1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/framemanager.cpp
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
8 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/aui/framemanager.h"
29 #include "wx/aui/dockart.h"
30 #include "wx/aui/floatpane.h"
34 #include "wx/settings.h"
36 #include "wx/dcclient.h"
37 #include "wx/dcscreen.h"
38 #include "wx/toolbar.h"
43 WX_CHECK_BUILD_OPTIONS("wxAUI")
45 #include "wx/arrimpl.cpp"
46 WX_DECLARE_OBJARRAY(wxRect
, wxAuiRectArray
);
47 WX_DEFINE_OBJARRAY(wxAuiRectArray
)
48 WX_DEFINE_OBJARRAY(wxDockUIPartArray
)
49 WX_DEFINE_OBJARRAY(wxDockInfoArray
)
50 WX_DEFINE_OBJARRAY(wxPaneButtonArray
)
51 WX_DEFINE_OBJARRAY(wxPaneInfoArray
)
53 wxPaneInfo wxNullPaneInfo
;
54 wxDockInfo wxNullDockInfo
;
55 DEFINE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON
)
56 DEFINE_EVENT_TYPE(wxEVT_AUI_PANECLOSE
)
57 DEFINE_EVENT_TYPE(wxEVT_AUI_RENDER
)
60 // a few defines to avoid nameclashes
61 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
63 #include "wx/mac/private.h"
66 IMPLEMENT_DYNAMIC_CLASS(wxFrameManagerEvent
, wxEvent
)
68 class wxPseudoTransparentFrame
: public wxFrame
71 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
72 wxWindowID id
= wxID_ANY
,
73 const wxString
& title
= wxEmptyString
,
74 const wxPoint
& pos
= wxDefaultPosition
,
75 const wxSize
& size
= wxDefaultSize
,
76 long style
= wxDEFAULT_FRAME_STYLE
,
77 const wxString
&name
= wxT("frame"))
78 : wxFrame(parent
, id
, title
, pos
, size
, style
| wxFRAME_SHAPED
, name
)
80 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
87 m_CanSetShape
= false; // have to wait for window create event on GTK
91 m_Region
= wxRegion(0, 0, 0, 0);
95 virtual bool SetTransparent(wxByte alpha
)
99 int w
=100; // some defaults
101 GetClientSize(&w
, &h
);
107 // m_Region.Union(0, 0, 1, m_MaxWidth);
110 for (int y
=0; y
<m_MaxHeight
; y
++)
112 // Reverse the order of the bottom 4 bits
113 int j
=((y
&8)?1:0)|((y
&4)?2:0)|((y
&2)?4:0)|((y
&1)?8:0);
114 if ((j
*16+8)<m_Amount
)
115 m_Region
.Union(0, y
, m_MaxWidth
, 1);
124 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
128 if (m_Region
.IsEmpty())
132 dc
.SetBrush(wxColour(128, 192, 255));
134 dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
136 dc
.SetPen(*wxTRANSPARENT_PEN
);
138 wxRegionIterator
upd(GetUpdateRegion()); // get the update rect list
142 wxRect
rect(upd
.GetRect());
143 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
150 void OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
)) {m_CanSetShape
=true; SetTransparent(0);}
153 void OnSize(wxSizeEvent
& event
)
155 // We sometimes get surplus size events
156 if ((event
.GetSize().GetWidth() == m_lastWidth
) &&
157 (event
.GetSize().GetHeight() == m_lastHeight
))
162 m_lastWidth
= event
.GetSize().GetWidth();
163 m_lastHeight
= event
.GetSize().GetHeight();
165 SetTransparent(m_Amount
);
166 m_Region
.Intersect(0, 0, event
.GetSize().GetWidth(),
167 event
.GetSize().GetHeight());
178 int m_lastWidth
,m_lastHeight
;
182 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
183 DECLARE_EVENT_TABLE()
187 IMPLEMENT_DYNAMIC_CLASS( wxPseudoTransparentFrame
, wxFrame
)
189 BEGIN_EVENT_TABLE(wxPseudoTransparentFrame
, wxFrame
)
190 EVT_PAINT(wxPseudoTransparentFrame::OnPaint
)
191 EVT_SIZE(wxPseudoTransparentFrame::OnSize
)
193 EVT_WINDOW_CREATE(wxPseudoTransparentFrame::OnWindowCreate
)
198 // -- static utility functions --
200 static wxBitmap
wxPaneCreateStippleBitmap()
202 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
203 wxImage
img(2,2,data
,true);
204 return wxBitmap(img
);
207 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
209 wxBitmap stipple
= wxPaneCreateStippleBitmap();
210 wxBrush
brush(stipple
);
212 dc
.SetPen(*wxTRANSPARENT_PEN
);
214 dc
.SetLogicalFunction(wxXOR
);
215 dc
.DrawRectangle(rect
);
220 // CopyDocksAndPanes() - this utility function creates copies of
221 // the dock and pane info. wxDockInfo's usually contain pointers
222 // to wxPaneInfo classes, thus this function is necessary to reliably
223 // reconstruct that relationship in the new dock info and pane info arrays
225 static void CopyDocksAndPanes(wxDockInfoArray
& dest_docks
,
226 wxPaneInfoArray
& dest_panes
,
227 const wxDockInfoArray
& src_docks
,
228 const wxPaneInfoArray
& src_panes
)
230 dest_docks
= src_docks
;
231 dest_panes
= src_panes
;
232 int i
, j
, k
, dock_count
, pc1
, pc2
;
233 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
235 wxDockInfo
& dock
= dest_docks
.Item(i
);
236 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
237 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
238 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
239 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
243 // GetMaxLayer() is an internal function which returns
244 // the highest layer inside the specified dock
245 static int GetMaxLayer(const wxDockInfoArray
& docks
, int dock_direction
)
247 int i
, dock_count
, max_layer
= 0;
248 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
250 wxDockInfo
& dock
= docks
.Item(i
);
251 if (dock
.dock_direction
== dock_direction
&&
252 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
253 max_layer
= dock
.dock_layer
;
259 // GetMaxRow() is an internal function which returns
260 // the highest layer inside the specified dock
261 static int GetMaxRow(const wxPaneInfoArray
& panes
, int direction
, int layer
)
263 int i
, pane_count
, max_row
= 0;
264 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
266 wxPaneInfo
& pane
= panes
.Item(i
);
267 if (pane
.dock_direction
== direction
&&
268 pane
.dock_layer
== layer
&&
269 pane
.dock_row
> max_row
)
270 max_row
= pane
.dock_row
;
277 // DoInsertDockLayer() is an internal function that inserts a new dock
278 // layer by incrementing all existing dock layer values by one
279 static void DoInsertDockLayer(wxPaneInfoArray
& panes
,
284 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
286 wxPaneInfo
& pane
= panes
.Item(i
);
287 if (!pane
.IsFloating() &&
288 pane
.dock_direction
== dock_direction
&&
289 pane
.dock_layer
>= dock_layer
)
294 // DoInsertDockLayer() is an internal function that inserts a new dock
295 // row by incrementing all existing dock row values by one
296 static void DoInsertDockRow(wxPaneInfoArray
& panes
,
302 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
304 wxPaneInfo
& pane
= panes
.Item(i
);
305 if (!pane
.IsFloating() &&
306 pane
.dock_direction
== dock_direction
&&
307 pane
.dock_layer
== dock_layer
&&
308 pane
.dock_row
>= dock_row
)
313 // DoInsertDockLayer() is an internal function that inserts a space for
314 // another dock pane by incrementing all existing dock row values by one
315 static void DoInsertPane(wxPaneInfoArray
& panes
,
322 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
324 wxPaneInfo
& pane
= panes
.Item(i
);
325 if (!pane
.IsFloating() &&
326 pane
.dock_direction
== dock_direction
&&
327 pane
.dock_layer
== dock_layer
&&
328 pane
.dock_row
== dock_row
&&
329 pane
.dock_pos
>= dock_pos
)
334 // FindDocks() is an internal function that returns a list of docks which meet
335 // the specified conditions in the parameters and returns a sorted array
336 // (sorted by layer and then row)
337 static void FindDocks(wxDockInfoArray
& docks
,
341 wxDockInfoPtrArray
& arr
)
343 int begin_layer
= dock_layer
;
344 int end_layer
= dock_layer
;
345 int begin_row
= dock_row
;
346 int end_row
= dock_row
;
347 int dock_count
= docks
.GetCount();
348 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
350 // discover the maximum dock layer and the max row
351 for (i
= 0; i
< dock_count
; ++i
)
353 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
354 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
357 // if no dock layer was specified, search all dock layers
358 if (dock_layer
== -1)
361 end_layer
= max_layer
;
364 // if no dock row was specified, search all dock row
373 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
374 for (row
= begin_row
; row
<= end_row
; ++row
)
375 for (i
= 0; i
< dock_count
; ++i
)
377 wxDockInfo
& d
= docks
.Item(i
);
378 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
380 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
386 // FindPaneInDock() looks up a specified window pointer inside a dock.
387 // If found, the corresponding wxPaneInfo pointer is returned, otherwise NULL.
388 static wxPaneInfo
* FindPaneInDock(const wxDockInfo
& dock
, wxWindow
* window
)
390 int i
, count
= dock
.panes
.GetCount();
391 for (i
= 0; i
< count
; ++i
)
393 wxPaneInfo
* p
= dock
.panes
.Item(i
);
394 if (p
->window
== window
)
400 // RemovePaneFromDocks() removes a pane window from all docks
401 // with a possible exception specified by parameter "ex_cept"
402 static void RemovePaneFromDocks(wxDockInfoArray
& docks
,
404 wxDockInfo
* ex_cept
= NULL
)
407 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
409 wxDockInfo
& d
= docks
.Item(i
);
412 wxPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
418 // RenumberDockRows() takes a dock and assigns sequential numbers
419 // to existing rows. Basically it takes out the gaps; so if a
420 // dock has rows with numbers 0,2,5, they will become 0,1,2
421 static void RenumberDockRows(wxDockInfoPtrArray
& docks
)
423 int i
, dock_count
, j
, pane_count
;
424 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
426 wxDockInfo
& dock
= *docks
.Item(i
);
428 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
429 dock
.panes
.Item(j
)->dock_row
= i
;
434 // SetActivePane() sets the active pane, as well as cycles through
435 // every other pane and makes sure that all others' active flags
437 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
440 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
442 wxPaneInfo
& pane
= panes
.Item(i
);
443 pane
.state
&= ~wxPaneInfo::optionActive
;
444 if (pane
.window
== active_pane
)
445 pane
.state
|= wxPaneInfo::optionActive
;
450 // this function is used to sort panes by dock position
451 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
453 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
457 // -- wxFrameManager class implementation --
460 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
461 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
462 EVT_AUI_RENDER(wxFrameManager::OnRender
)
463 EVT_PAINT(wxFrameManager::OnPaint
)
464 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
465 EVT_SIZE(wxFrameManager::OnSize
)
466 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
467 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
468 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
469 EVT_MOTION(wxFrameManager::OnMotion
)
470 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
471 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
472 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
476 wxFrameManager::wxFrameManager(wxWindow
* managed_wnd
, unsigned int flags
)
478 m_action
= actionNone
;
479 m_last_mouse_move
= wxPoint();
480 m_hover_button
= NULL
;
481 m_art
= new wxDefaultDockArt
;
488 SetManagedWindow(managed_wnd
);
492 wxFrameManager::~wxFrameManager()
497 // Creates a floating frame for the windows
498 wxFloatingPane
* wxFrameManager::CreateFloatingFrame(wxWindow
* parent
, const wxPaneInfo
& p
)
500 return new wxFloatingPane(parent
, this, p
);
503 // GetPane() looks up a wxPaneInfo structure based
504 // on the supplied window pointer. Upon failure, GetPane()
505 // returns an empty wxPaneInfo, a condition which can be checked
506 // by calling wxPaneInfo::IsOk().
508 // The pane info's structure may then be modified. Once a pane's
509 // info is modified, wxFrameManager::Update() must be called to
510 // realize the changes in the UI.
512 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
515 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
517 wxPaneInfo
& p
= m_panes
.Item(i
);
518 if (p
.window
== window
)
521 return wxNullPaneInfo
;
524 // this version of GetPane() looks up a pane based on a
525 // 'pane name', see above comment for more info
526 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
529 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
531 wxPaneInfo
& p
= m_panes
.Item(i
);
535 return wxNullPaneInfo
;
538 // GetAllPanes() returns a reference to all the pane info structures
539 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
544 // HitTest() is an internal function which determines
545 // which UI item the specified coordinates are over
546 // (x,y) specify a position in client coordinates
547 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
549 wxDockUIPart
* result
= NULL
;
552 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
554 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
556 // we are not interested in typeDock, because this space
557 // isn't used to draw anything, just for measurements;
558 // besides, the entire dock area is covered with other
559 // rectangles, which we are interested in.
560 if (item
->type
== wxDockUIPart::typeDock
)
563 // if we already have a hit on a more specific item, we are not
564 // interested in a pane hit. If, however, we don't already have
565 // a hit, returning a pane hit is necessary for some operations
566 if ((item
->type
== wxDockUIPart::typePane
||
567 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
570 // if the point is inside the rectangle, we have a hit
571 if (item
->rect
.Contains(x
,y
))
579 // SetFlags() and GetFlags() allow the owner to set various
580 // options which are global to wxFrameManager
581 void wxFrameManager::SetFlags(unsigned int flags
)
586 unsigned int wxFrameManager::GetFlags() const
592 // don't use these anymore as they are deprecated
593 // use Set/GetManagedFrame() instead
594 void wxFrameManager::SetFrame(wxFrame
* frame
)
596 SetManagedWindow((wxWindow
*)frame
);
599 wxFrame
* wxFrameManager::GetFrame() const
601 return (wxFrame
*)m_frame
;
607 // SetManagedWindow() is usually called once when the frame
608 // manager class is being initialized. "frame" specifies
609 // the frame which should be managed by the frame mananger
610 void wxFrameManager::SetManagedWindow(wxWindow
* frame
)
612 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
615 m_frame
->PushEventHandler(this);
618 // if the owner is going to manage an MDI parent frame,
619 // we need to add the MDI client window as the default
622 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
624 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
625 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
627 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
629 AddPane(client_window
,
630 wxPaneInfo().Name(wxT("mdiclient")).
631 CenterPane().PaneBorder(false));
635 // Make a window to use for a transparent hint
636 #if defined(__WXMSW__) || defined(__WXGTK__)
637 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
638 wxFRAME_TOOL_WINDOW
|
639 wxFRAME_FLOAT_ON_PARENT
|
643 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
645 #elif defined(__WXMAC__)
646 // Using a miniframe with float and tool styles keeps the parent
647 // frame activated and highlighted as such...
648 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
649 wxFRAME_FLOAT_ON_PARENT
650 | wxFRAME_TOOL_WINDOW
);
652 // Can't set the bg colour of a Frame in wxMac
653 wxPanel
* p
= new wxPanel(m_hint_wnd
);
655 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
656 // color that is really hard to see, especially transparent.
657 // Until a better system color is decided upon we'll just use
659 p
->SetBackgroundColour(*wxBLUE
);
665 // CanSetTransparent is only present in the 2.7.0 ABI. To allow this file to be easily used
666 // in a backported environment, conditionally compile this in.
667 #if wxCHECK_VERSION(2,7,0)
668 && !m_hint_wnd
->CanSetTransparent()
674 m_hint_wnd
->Destroy();
677 // If we can convert it to a PseudoTransparent window, do so
678 m_hint_wnd
= new wxPseudoTransparentFrame (m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
679 wxFRAME_TOOL_WINDOW
|
680 wxFRAME_FLOAT_ON_PARENT
|
684 m_hint_fademax
= 128;
689 // UnInit() must be called, usually in the destructor
690 // of the frame class. If it is not called, usually this
691 // will result in a crash upon program exit
692 void wxFrameManager::UnInit()
694 m_frame
->RemoveEventHandler(this);
697 // GetManagedWindow() returns the window pointer being managed
698 wxWindow
* wxFrameManager::GetManagedWindow() const
703 wxDockArt
* wxFrameManager::GetArtProvider() const
708 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
710 // first, give the owner frame a chance to override
713 if (m_frame
->ProcessEvent(event
))
720 // SetArtProvider() instructs wxFrameManager to use the
721 // specified art provider for all drawing calls. This allows
722 // plugable look-and-feel features. The pointer that is
723 // passed to this method subsequently belongs to wxFrameManager,
724 // and is deleted in the frame manager destructor
725 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
727 // delete the last art provider, if any
730 // assign the new art provider
731 m_art
= art_provider
;
735 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
737 // check if the pane has a valid window
741 // check if the pane already exists
742 if (GetPane(pane_info
.window
).IsOk())
745 m_panes
.Add(pane_info
);
747 wxPaneInfo
& pinfo
= m_panes
.Last();
749 // set the pane window
750 pinfo
.window
= window
;
752 // if the pane's name identifier is blank, create a random string
753 if (pinfo
.name
.empty())
755 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
756 ((unsigned long)pinfo
.window
) & 0xffffffff,
757 (unsigned int)time(NULL
),
759 (unsigned int)GetTickCount(),
761 (unsigned int)clock(),
763 (unsigned long)m_panes
.GetCount());
766 // set initial proportion (if not already set)
767 if (pinfo
.dock_proportion
== 0)
768 pinfo
.dock_proportion
= 100000;
770 if (pinfo
.HasCloseButton() &&
771 pinfo
.buttons
.size() == 0)
774 button
.button_id
= wxPaneInfo::buttonClose
;
775 pinfo
.buttons
.Add(button
);
778 if (pinfo
.best_size
== wxDefaultSize
&&
781 pinfo
.best_size
= pinfo
.window
->GetClientSize();
783 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
785 // GetClientSize() doesn't get the best size for
786 // a toolbar under some newer versions of wxWidgets,
787 // so use GetBestSize()
788 pinfo
.best_size
= pinfo
.window
->GetBestSize();
790 // for some reason, wxToolBar::GetBestSize() is returning
791 // a size that is a pixel shy of the correct amount.
792 // I believe this to be the correct action, until
793 // wxToolBar::GetBestSize() is fixed. Is this assumption
798 if (pinfo
.min_size
!= wxDefaultSize
)
800 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
801 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
802 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
803 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
810 bool wxFrameManager::AddPane(wxWindow
* window
,
812 const wxString
& caption
)
815 pinfo
.Caption(caption
);
818 case wxTOP
: pinfo
.Top(); break;
819 case wxBOTTOM
: pinfo
.Bottom(); break;
820 case wxLEFT
: pinfo
.Left(); break;
821 case wxRIGHT
: pinfo
.Right(); break;
822 case wxCENTER
: pinfo
.CenterPane(); break;
824 return AddPane(window
, pinfo
);
827 bool wxFrameManager::AddPane(wxWindow
* window
,
828 const wxPaneInfo
& pane_info
,
829 const wxPoint
& drop_pos
)
831 if (!AddPane(window
, pane_info
))
834 wxPaneInfo
& pane
= GetPane(window
);
836 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
841 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
844 // shift the panes around, depending on the insert level
845 switch (insert_level
)
847 case wxAUI_INSERT_PANE
:
848 DoInsertPane(m_panes
,
849 pane_info
.dock_direction
,
850 pane_info
.dock_layer
,
854 case wxAUI_INSERT_ROW
:
855 DoInsertDockRow(m_panes
,
856 pane_info
.dock_direction
,
857 pane_info
.dock_layer
,
860 case wxAUI_INSERT_DOCK
:
861 DoInsertDockLayer(m_panes
,
862 pane_info
.dock_direction
,
863 pane_info
.dock_layer
);
867 // if the window already exists, we are basically just moving/inserting the
868 // existing window. If it doesn't exist, we need to add it and insert it
869 wxPaneInfo
& existing_pane
= GetPane(window
);
870 if (!existing_pane
.IsOk())
872 return AddPane(window
, pane_info
);
876 if (pane_info
.IsFloating())
878 existing_pane
.Float();
879 if (pane_info
.floating_pos
!= wxDefaultPosition
)
880 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
881 if (pane_info
.floating_size
!= wxDefaultSize
)
882 existing_pane
.FloatingSize(pane_info
.floating_size
);
886 existing_pane
.Direction(pane_info
.dock_direction
);
887 existing_pane
.Layer(pane_info
.dock_layer
);
888 existing_pane
.Row(pane_info
.dock_row
);
889 existing_pane
.Position(pane_info
.dock_pos
);
897 // DetachPane() removes a pane from the frame manager. This
898 // method will not destroy the window that is removed.
899 bool wxFrameManager::DetachPane(wxWindow
* window
)
902 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
904 wxPaneInfo
& p
= m_panes
.Item(i
);
905 if (p
.window
== window
)
909 // we have a floating frame which is being detached. We need to
910 // reparent it to m_frame and destroy the floating frame
913 p
.window
->SetSize(1,1);
915 if (p
.frame
->IsShown())
916 p
.frame
->Show(false);
918 // reparent to m_frame and destroy the pane
919 p
.window
->Reparent(m_frame
);
920 p
.frame
->SetSizer(NULL
);
925 // make sure there are no references to this pane in our uiparts,
926 // just in case the caller doesn't call Update() immediately after
927 // the DetachPane() call. This prevets obscure crashes which would
928 // happen at window repaint if the caller forgets to call Update()
930 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
932 wxDockUIPart
& part
= m_uiparts
.Item(pi
);
935 m_uiparts
.RemoveAt(pi
);
949 // ClosePane() destroys or hides the pane depending on its
951 void wxFrameManager::ClosePane(wxPaneInfo
& pane_info
)
953 // first, hide the window
954 if (pane_info
.window
&& pane_info
.window
->IsShown()) {
955 pane_info
.window
->Show(false);
958 // make sure that we are the parent of this window
959 if(pane_info
.window
&& pane_info
.window
->GetParent() != m_frame
) {
960 pane_info
.window
->Reparent(m_frame
);
963 // if we have a frame, destroy it
964 if(pane_info
.frame
) {
965 pane_info
.frame
->Destroy();
966 pane_info
.frame
= NULL
;
969 // now we need to either destroy or hide the pane
970 if(pane_info
.IsDestroyOnClose())
972 wxWindow
* window
= pane_info
.window
;
984 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
985 // in the input string. This is an internal functions which is
986 // used for saving perspectives
987 static wxString
EscapeDelimiters(const wxString
& s
)
990 result
.Alloc(s
.length());
991 const wxChar
* ch
= s
.c_str();
994 if (*ch
== wxT(';') || *ch
== wxT('|'))
1002 wxString
wxFrameManager::SavePaneInfo(wxPaneInfo
& pane
)
1004 wxString result
= wxT("name=");
1005 result
+= EscapeDelimiters(pane
.name
);
1008 result
+= wxT("caption=");
1009 result
+= EscapeDelimiters(pane
.caption
);
1012 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
1013 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
1014 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
1015 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
1016 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
1017 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
1018 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
1019 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
1020 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
1021 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
1022 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
1023 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
1024 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
1025 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
1026 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
1027 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
1032 // Load a "pane" with the pane infor settings in pane_part
1033 void wxFrameManager::LoadPaneInfo(wxString pane_part
, wxPaneInfo
&pane
)
1035 // replace escaped characters so we can
1036 // split up the string easily
1037 pane_part
.Replace(wxT("\\|"), wxT("\a"));
1038 pane_part
.Replace(wxT("\\;"), wxT("\b"));
1042 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
1043 pane_part
= pane_part
.AfterFirst(wxT(';'));
1044 wxString val_name
= val_part
.BeforeFirst(wxT('='));
1045 wxString value
= val_part
.AfterFirst(wxT('='));
1046 val_name
.MakeLower();
1047 val_name
.Trim(true);
1048 val_name
.Trim(false);
1052 if (val_name
.empty())
1055 if (val_name
== wxT("name"))
1057 else if (val_name
== wxT("caption"))
1058 pane
.caption
= value
;
1059 else if (val_name
== wxT("state"))
1060 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1061 else if (val_name
== wxT("dir"))
1062 pane
.dock_direction
= wxAtoi(value
.c_str());
1063 else if (val_name
== wxT("layer"))
1064 pane
.dock_layer
= wxAtoi(value
.c_str());
1065 else if (val_name
== wxT("row"))
1066 pane
.dock_row
= wxAtoi(value
.c_str());
1067 else if (val_name
== wxT("pos"))
1068 pane
.dock_pos
= wxAtoi(value
.c_str());
1069 else if (val_name
== wxT("prop"))
1070 pane
.dock_proportion
= wxAtoi(value
.c_str());
1071 else if (val_name
== wxT("bestw"))
1072 pane
.best_size
.x
= wxAtoi(value
.c_str());
1073 else if (val_name
== wxT("besth"))
1074 pane
.best_size
.y
= wxAtoi(value
.c_str());
1075 else if (val_name
== wxT("minw"))
1076 pane
.min_size
.x
= wxAtoi(value
.c_str());
1077 else if (val_name
== wxT("minh"))
1078 pane
.min_size
.y
= wxAtoi(value
.c_str());
1079 else if (val_name
== wxT("maxw"))
1080 pane
.max_size
.x
= wxAtoi(value
.c_str());
1081 else if (val_name
== wxT("maxh"))
1082 pane
.max_size
.y
= wxAtoi(value
.c_str());
1083 else if (val_name
== wxT("floatx"))
1084 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1085 else if (val_name
== wxT("floaty"))
1086 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1087 else if (val_name
== wxT("floatw"))
1088 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1089 else if (val_name
== wxT("floath"))
1090 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1092 wxFAIL_MSG(wxT("Bad Perspective String"));
1096 // replace escaped characters so we can
1097 // split up the string easily
1098 pane
.name
.Replace(wxT("\a"), wxT("|"));
1099 pane
.name
.Replace(wxT("\b"), wxT(";"));
1100 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1101 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1102 pane_part
.Replace(wxT("\a"), wxT("|"));
1103 pane_part
.Replace(wxT("\b"), wxT(";"));
1109 // SavePerspective() saves all pane information as a single string.
1110 // This string may later be fed into LoadPerspective() to restore
1111 // all pane settings. This save and load mechanism allows an
1112 // exact pane configuration to be saved and restored at a later time
1114 wxString
wxFrameManager::SavePerspective()
1118 result
= wxT("layout1|");
1120 int pane_i
, pane_count
= m_panes
.GetCount();
1121 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1123 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
1124 result
+= SavePaneInfo(pane
)+wxT("|");
1127 int dock_i
, dock_count
= m_docks
.GetCount();
1128 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1130 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
1132 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1133 dock
.dock_direction
, dock
.dock_layer
,
1134 dock
.dock_row
, dock
.size
);
1140 // LoadPerspective() loads a layout which was saved with SavePerspective()
1141 // If the "update" flag parameter is true, the GUI will immediately be updated
1143 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
1145 wxString input
= layout
;
1148 // check layout string version
1149 part
= input
.BeforeFirst(wxT('|'));
1150 input
= input
.AfterFirst(wxT('|'));
1153 if (part
!= wxT("layout1"))
1156 // mark all panes currently managed as docked and hidden
1157 int pane_i
, pane_count
= m_panes
.GetCount();
1158 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1159 m_panes
.Item(pane_i
).Dock().Hide();
1161 // clear out the dock array; this will be reconstructed
1164 // replace escaped characters so we can
1165 // split up the string easily
1166 input
.Replace(wxT("\\|"), wxT("\a"));
1167 input
.Replace(wxT("\\;"), wxT("\b"));
1173 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1174 input
= input
.AfterFirst(wxT('|'));
1175 pane_part
.Trim(true);
1177 // if the string is empty, we're done parsing
1178 if (pane_part
.empty())
1181 if (pane_part
.Left(9) == wxT("dock_size"))
1183 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1184 wxString value
= pane_part
.AfterFirst(wxT('='));
1186 long dir
, layer
, row
, size
;
1187 wxString piece
= val_name
.AfterFirst(wxT('('));
1188 piece
= piece
.BeforeLast(wxT(')'));
1189 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1190 piece
= piece
.AfterFirst(wxT(','));
1191 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1192 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1193 value
.ToLong(&size
);
1196 dock
.dock_direction
= dir
;
1197 dock
.dock_layer
= layer
;
1198 dock
.dock_row
= row
;
1204 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1205 // name so it can be called by external callers
1206 pane_part
.Replace(wxT("\a"), wxT("|"));
1207 pane_part
.Replace(wxT("\b"), wxT(";"));
1209 LoadPaneInfo(pane_part
, pane
);
1211 wxPaneInfo
& p
= GetPane(pane
.name
);
1214 // the pane window couldn't be found
1215 // in the existing layout
1229 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
1230 wxArrayInt
& positions
,
1233 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1234 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1235 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1240 int offset
, action_pane
= -1;
1241 int pane_i
, pane_count
= dock
.panes
.GetCount();
1243 // find the pane marked as our action pane
1244 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1246 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1248 if (pane
.state
& wxPaneInfo::actionPane
)
1250 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1251 action_pane
= pane_i
;
1255 // set up each panes default position, and
1256 // determine the size (width or height, depending
1257 // on the dock's orientation) of each pane
1258 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1260 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1261 positions
.Add(pane
.dock_pos
);
1264 if (pane
.HasBorder())
1265 size
+= (pane_border_size
*2);
1267 if (dock
.IsHorizontal())
1269 if (pane
.HasGripper() && !pane
.HasGripperTop())
1270 size
+= gripper_size
;
1271 size
+= pane
.best_size
.x
;
1275 if (pane
.HasGripper() && pane
.HasGripperTop())
1276 size
+= gripper_size
;
1278 if (pane
.HasCaption())
1279 size
+= caption_size
;
1280 size
+= pane
.best_size
.y
;
1286 // if there is no action pane, just return the default
1287 // positions (as specified in pane.pane_pos)
1288 if (action_pane
== -1)
1292 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1294 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1299 positions
[pane_i
] -= -amount
;
1301 offset
+= sizes
[pane_i
];
1304 // if the dock mode is fixed, make sure none of the panes
1305 // overlap; we will bump panes that overlap
1307 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1309 int amount
= positions
[pane_i
] - offset
;
1313 positions
[pane_i
] += -amount
;
1315 offset
+= sizes
[pane_i
];
1320 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1323 wxDockUIPartArray
& uiparts
,
1327 wxSizerItem
* sizer_item
;
1329 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1330 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1331 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1332 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1334 // find out the orientation of the item (orientation for panes
1335 // is the same as the dock's orientation)
1337 if (dock
.IsHorizontal())
1338 orientation
= wxHORIZONTAL
;
1340 orientation
= wxVERTICAL
;
1342 // this variable will store the proportion
1343 // value that the pane will receive
1344 int pane_proportion
= pane
.dock_proportion
;
1346 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1347 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1349 if (pane
.HasGripper())
1351 if (pane
.HasGripperTop())
1352 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1354 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1356 part
.type
= wxDockUIPart::typeGripper
;
1360 part
.orientation
= orientation
;
1361 part
.cont_sizer
= horz_pane_sizer
;
1362 part
.sizer_item
= sizer_item
;
1366 if (pane
.HasCaption())
1368 // create the caption sizer
1369 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1371 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1373 part
.type
= wxDockUIPart::typeCaption
;
1377 part
.orientation
= orientation
;
1378 part
.cont_sizer
= vert_pane_sizer
;
1379 part
.sizer_item
= sizer_item
;
1380 int caption_part_idx
= uiparts
.GetCount();
1383 // add pane buttons to the caption
1384 int i
, button_count
;
1385 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1386 i
< button_count
; ++i
)
1388 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1390 sizer_item
= caption_sizer
->Add(pane_button_size
,
1394 part
.type
= wxDockUIPart::typePaneButton
;
1397 part
.button
= &button
;
1398 part
.orientation
= orientation
;
1399 part
.cont_sizer
= caption_sizer
;
1400 part
.sizer_item
= sizer_item
;
1404 // add the caption sizer
1405 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1407 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1410 // add the pane window itself
1413 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1417 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1418 // Don't do this because it breaks the pane size in floating windows
1419 // BIW: Right now commenting this out is causing problems with
1420 // an mdi client window as the center pane.
1421 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1424 part
.type
= wxDockUIPart::typePane
;
1428 part
.orientation
= orientation
;
1429 part
.cont_sizer
= vert_pane_sizer
;
1430 part
.sizer_item
= sizer_item
;
1434 // determine if the pane should have a minimum size; if the pane is
1435 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1436 // if the pane.min_size is set, we must use that value as well
1438 wxSize min_size
= pane
.min_size
;
1441 if (min_size
== wxDefaultSize
)
1443 min_size
= pane
.best_size
;
1444 pane_proportion
= 0;
1448 if (min_size
!= wxDefaultSize
)
1450 vert_pane_sizer
->SetItemMinSize(
1451 vert_pane_sizer
->GetChildren().GetCount()-1,
1452 min_size
.x
, min_size
.y
);
1456 // add the verticle sizer (caption, pane window) to the
1457 // horizontal sizer (gripper, verticle sizer)
1458 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1460 // finally, add the pane sizer to the dock sizer
1462 if (pane
.HasBorder())
1464 // allowing space for the pane's border
1465 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1466 wxEXPAND
| wxALL
, pane_border_size
);
1468 part
.type
= wxDockUIPart::typePaneBorder
;
1472 part
.orientation
= orientation
;
1473 part
.cont_sizer
= cont
;
1474 part
.sizer_item
= sizer_item
;
1479 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1483 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1485 wxDockUIPartArray
& uiparts
,
1488 wxSizerItem
* sizer_item
;
1491 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1492 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1494 // resizable bottom and right docks have a sash before them
1495 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1496 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1498 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1500 part
.type
= wxDockUIPart::typeDockSizer
;
1501 part
.orientation
= orientation
;
1505 part
.cont_sizer
= cont
;
1506 part
.sizer_item
= sizer_item
;
1510 // create the sizer for the dock
1511 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1513 // add each pane to the dock
1514 int pane_i
, pane_count
= dock
.panes
.GetCount();
1518 wxArrayInt pane_positions
, pane_sizes
;
1520 // figure out the real pane positions we will
1521 // use, without modifying the each pane's pane_pos member
1522 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1525 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1527 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1528 int pane_pos
= pane_positions
.Item(pane_i
);
1530 int amount
= pane_pos
- offset
;
1533 if (dock
.IsVertical())
1534 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1536 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1538 part
.type
= wxDockUIPart::typeBackground
;
1542 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1543 part
.cont_sizer
= dock_sizer
;
1544 part
.sizer_item
= sizer_item
;
1550 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1552 offset
+= pane_sizes
.Item(pane_i
);
1555 // at the end add a very small stretchable background area
1556 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1558 part
.type
= wxDockUIPart::typeBackground
;
1562 part
.orientation
= orientation
;
1563 part
.cont_sizer
= dock_sizer
;
1564 part
.sizer_item
= sizer_item
;
1569 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1571 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1573 // if this is not the first pane being added,
1574 // we need to add a pane sizer
1577 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1579 part
.type
= wxDockUIPart::typePaneSizer
;
1581 part
.pane
= dock
.panes
.Item(pane_i
-1);
1583 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1584 part
.cont_sizer
= dock_sizer
;
1585 part
.sizer_item
= sizer_item
;
1589 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1593 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1594 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1596 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1598 part
.type
= wxDockUIPart::typeDock
;
1602 part
.orientation
= orientation
;
1603 part
.cont_sizer
= cont
;
1604 part
.sizer_item
= sizer_item
;
1607 if (dock
.IsHorizontal())
1608 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1610 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1612 // top and left docks have a sash after them
1613 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1614 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1616 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1618 part
.type
= wxDockUIPart::typeDockSizer
;
1622 part
.orientation
= orientation
;
1623 part
.cont_sizer
= cont
;
1624 part
.sizer_item
= sizer_item
;
1629 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1630 wxDockInfoArray
& docks
,
1631 wxDockUIPartArray
& uiparts
,
1634 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1636 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1637 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1638 wxSize cli_size
= m_frame
->GetClientSize();
1639 int i
, dock_count
, pane_count
;
1642 // empty all docks out
1643 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1644 docks
.Item(i
).panes
.Empty();
1646 // iterate through all known panes, filing each
1647 // of them into the appropriate dock. If the
1648 // pane does not exist in the dock, add it
1649 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1651 wxPaneInfo
& p
= panes
.Item(i
);
1653 // find any docks in this layer
1655 wxDockInfoPtrArray arr
;
1656 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1658 if (arr
.GetCount() > 0)
1664 // dock was not found, so we need to create a new one
1666 d
.dock_direction
= p
.dock_direction
;
1667 d
.dock_layer
= p
.dock_layer
;
1668 d
.dock_row
= p
.dock_row
;
1670 dock
= &docks
.Last();
1674 if (p
.IsDocked() && p
.IsShown())
1676 // remove the pane from any existing docks except this one
1677 RemovePaneFromDocks(docks
, p
, dock
);
1679 // pane needs to be added to the dock,
1680 // if it doesn't already exist
1681 if (!FindPaneInDock(*dock
, p
.window
))
1682 dock
->panes
.Add(&p
);
1686 // remove the pane from any existing docks
1687 RemovePaneFromDocks(docks
, p
);
1692 // remove any empty docks
1693 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1695 if (docks
.Item(i
).panes
.GetCount() == 0)
1699 // configure the docks further
1700 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1702 wxDockInfo
& dock
= docks
.Item(i
);
1703 int j
, dock_pane_count
= dock
.panes
.GetCount();
1705 // sort the dock pane array by the pane's
1706 // dock position (dock_pos), in ascending order
1707 dock
.panes
.Sort(PaneSortFunc
);
1709 // for newly created docks, set up their initial size
1714 for (j
= 0; j
< dock_pane_count
; ++j
)
1716 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1717 wxSize pane_size
= pane
.best_size
;
1718 if (pane_size
== wxDefaultSize
)
1719 pane_size
= pane
.min_size
;
1720 if (pane_size
== wxDefaultSize
)
1721 pane_size
= pane
.window
->GetSize();
1723 if (dock
.IsHorizontal())
1724 size
= wxMax(pane_size
.y
, size
);
1726 size
= wxMax(pane_size
.x
, size
);
1729 // add space for the border (two times), but only
1730 // if at least one pane inside the dock has a pane border
1731 for (j
= 0; j
< dock_pane_count
; ++j
)
1733 if (dock
.panes
.Item(j
)->HasBorder())
1735 size
+= (pane_border_size
*2);
1740 // if pane is on the top or bottom, add the caption height,
1741 // but only if at least one pane inside the dock has a caption
1742 if (dock
.IsHorizontal())
1744 for (j
= 0; j
< dock_pane_count
; ++j
)
1746 if (dock
.panes
.Item(j
)->HasCaption())
1748 size
+= caption_size
;
1754 // new dock's size may not be more than 1/3 of the frame size
1755 if (dock
.IsHorizontal())
1756 size
= wxMin(size
, cli_size
.y
/3);
1758 size
= wxMin(size
, cli_size
.x
/3);
1766 // determine the dock's minimum size
1767 bool plus_border
= false;
1768 bool plus_caption
= false;
1769 int dock_min_size
= 0;
1770 for (j
= 0; j
< dock_pane_count
; ++j
)
1772 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1773 if (pane
.min_size
!= wxDefaultSize
)
1775 if (pane
.HasBorder())
1777 if (pane
.HasCaption())
1778 plus_caption
= true;
1779 if (dock
.IsHorizontal())
1781 if (pane
.min_size
.y
> dock_min_size
)
1782 dock_min_size
= pane
.min_size
.y
;
1786 if (pane
.min_size
.x
> dock_min_size
)
1787 dock_min_size
= pane
.min_size
.x
;
1793 dock_min_size
+= (pane_border_size
*2);
1794 if (plus_caption
&& dock
.IsHorizontal())
1795 dock_min_size
+= (caption_size
);
1797 dock
.min_size
= dock_min_size
;
1800 // if the pane's current size is less than it's
1801 // minimum, increase the dock's size to it's minimum
1802 if (dock
.size
< dock
.min_size
)
1803 dock
.size
= dock
.min_size
;
1806 // determine the dock's mode (fixed or proportional);
1807 // determine whether the dock has only toolbars
1808 bool action_pane_marked
= false;
1810 dock
.toolbar
= true;
1811 for (j
= 0; j
< dock_pane_count
; ++j
)
1813 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1814 if (!pane
.IsFixed())
1816 if (!pane
.IsToolbar())
1817 dock
.toolbar
= false;
1818 if (pane
.state
& wxPaneInfo::actionPane
)
1819 action_pane_marked
= true;
1823 // if the dock mode is proportional and not fixed-pixel,
1824 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1825 // e.g. remove gaps like 1, 2, 30, 500
1828 for (j
= 0; j
< dock_pane_count
; ++j
)
1830 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1835 // if the dock mode is fixed, and none of the panes
1836 // are being moved right now, make sure the panes
1837 // do not overlap each other. If they do, we will
1838 // adjust the panes' positions
1839 if (dock
.fixed
&& !action_pane_marked
)
1841 wxArrayInt pane_positions
, pane_sizes
;
1842 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1845 for (j
= 0; j
< dock_pane_count
; ++j
)
1847 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1848 pane
.dock_pos
= pane_positions
[j
];
1850 int amount
= pane
.dock_pos
- offset
;
1854 pane
.dock_pos
+= -amount
;
1856 offset
+= pane_sizes
[j
];
1861 // discover the maximum dock layer
1863 for (i
= 0; i
< dock_count
; ++i
)
1864 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1867 // clear out uiparts
1870 // create a bunch of box sizers,
1871 // from the innermost level outwards.
1872 wxSizer
* cont
= NULL
;
1873 wxSizer
* middle
= NULL
;
1877 for (layer
= 0; layer
<= max_layer
; ++layer
)
1879 wxDockInfoPtrArray arr
;
1881 // find any docks in this layer
1882 FindDocks(docks
, -1, layer
, -1, arr
);
1884 // if there aren't any, skip to the next layer
1888 wxSizer
* old_cont
= cont
;
1890 // create a container which will hold this layer's
1891 // docks (top, bottom, left, right)
1892 cont
= new wxBoxSizer(wxVERTICAL
);
1895 // find any top docks in this layer
1896 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1897 RenumberDockRows(arr
);
1900 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1901 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1905 // fill out the middle layer (which consists
1906 // of left docks, content area and right docks)
1908 middle
= new wxBoxSizer(wxHORIZONTAL
);
1910 // find any left docks in this layer
1911 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1912 RenumberDockRows(arr
);
1915 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1916 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1919 // add content dock (or previous layer's sizer
1923 // find any center docks
1924 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1927 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1928 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1932 // there are no center docks, add a background area
1933 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1935 part
.type
= wxDockUIPart::typeBackground
;
1939 part
.cont_sizer
= middle
;
1940 part
.sizer_item
= sizer_item
;
1946 middle
->Add(old_cont
, 1, wxEXPAND
);
1949 // find any right docks in this layer
1950 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1951 RenumberDockRows(arr
);
1954 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1955 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1958 cont
->Add(middle
, 1, wxEXPAND
);
1962 // find any bottom docks in this layer
1963 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1964 RenumberDockRows(arr
);
1967 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1968 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1975 // no sizer available, because there are no docks,
1976 // therefore we will create a simple background area
1977 cont
= new wxBoxSizer(wxVERTICAL
);
1978 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1980 part
.type
= wxDockUIPart::typeBackground
;
1984 part
.cont_sizer
= middle
;
1985 part
.sizer_item
= sizer_item
;
1989 container
->Add(cont
, 1, wxEXPAND
);
1994 // Update() updates the layout. Whenever changes are made to
1995 // one or more panes, this function should be called. It is the
1996 // external entry point for running the layout engine.
1998 void wxFrameManager::Update()
2001 int i
, pane_count
= m_panes
.GetCount();
2003 // delete old sizer first
2004 m_frame
->SetSizer(NULL
);
2006 // destroy floating panes which have been
2007 // redocked or are becoming non-floating
2008 for (i
= 0; i
< pane_count
; ++i
)
2010 wxPaneInfo
& p
= m_panes
.Item(i
);
2012 if (!p
.IsFloating() && p
.frame
)
2014 // because the pane is no longer in a floating, we need to
2015 // reparent it to m_frame and destroy the floating frame
2018 p
.window
->SetSize(1,1);
2020 if (p
.frame
->IsShown())
2021 p
.frame
->Show(false);
2023 // reparent to m_frame and destroy the pane
2024 p
.window
->Reparent(m_frame
);
2025 p
.frame
->SetSizer(NULL
);
2032 // create a layout for all of the panes
2033 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
2035 // hide or show panes as necessary,
2036 // and float panes as necessary
2037 for (i
= 0; i
< pane_count
; ++i
)
2039 wxPaneInfo
& p
= m_panes
.Item(i
);
2043 if (p
.frame
== NULL
)
2045 // we need to create a frame for this
2046 // pane, which has recently been floated
2047 wxFloatingPane
* frame
= CreateFloatingFrame(m_frame
, p
);
2049 #if wxCHECK_VERSION(2,7,0)
2050 // on MSW and Mac, if the owner desires transparent dragging, and
2051 // the dragging is happening right now, then the floating
2052 // window should have this style by default
2053 if (m_action
== actionDragFloatingPane
&&
2054 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2055 frame
->SetTransparent(150);
2058 frame
->SetPaneWindow(p
);
2061 if (p
.IsShown() && !frame
->IsShown())
2066 // frame already exists, make sure it's position
2067 // and size reflect the information in wxPaneInfo
2068 if (p
.frame
->GetPosition() != p
.floating_pos
)
2070 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2071 wxDefaultCoord
, wxDefaultCoord
,
2072 wxSIZE_USE_EXISTING
);
2073 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2076 if (p
.frame
->IsShown() != p
.IsShown())
2077 p
.frame
->Show(p
.IsShown());
2082 if (p
.window
->IsShown() != p
.IsShown())
2083 p
.window
->Show(p
.IsShown());
2086 // if "active panes" are no longer allowed, clear
2087 // any optionActive values from the pane states
2088 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2090 p
.state
&= ~wxPaneInfo::optionActive
;
2095 // keep track of the old window rectangles so we can
2096 // refresh those windows whose rect has changed
2097 wxAuiRectArray old_pane_rects
;
2098 for (i
= 0; i
< pane_count
; ++i
)
2101 wxPaneInfo
& p
= m_panes
.Item(i
);
2103 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2106 old_pane_rects
.Add(r
);
2112 // apply the new sizer
2113 m_frame
->SetSizer(sizer
);
2114 m_frame
->SetAutoLayout(false);
2119 // now that the frame layout is done, we need to check
2120 // the new pane rectangles against the old rectangles that
2121 // we saved a few lines above here. If the rectangles have
2122 // changed, the corresponding panes must also be updated
2123 for (i
= 0; i
< pane_count
; ++i
)
2125 wxPaneInfo
& p
= m_panes
.Item(i
);
2126 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2128 if (p
.rect
!= old_pane_rects
[i
])
2130 p
.window
->Refresh();
2139 // set frame's minimum size
2142 // N.B. More work needs to be done on frame minimum sizes;
2143 // this is some intresting code that imposes the minimum size,
2144 // but we may want to include a more flexible mechanism or
2145 // options for multiple minimum-size modes, e.g. strict or lax
2146 wxSize min_size = sizer->GetMinSize();
2147 wxSize frame_size = m_frame->GetSize();
2148 wxSize client_size = m_frame->GetClientSize();
2150 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2151 min_size.y+frame_size.y-client_size.y );
2153 m_frame->SetMinSize(minframe_size);
2155 if (frame_size.x < minframe_size.x ||
2156 frame_size.y < minframe_size.y)
2157 sizer->Fit(m_frame);
2162 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2163 // on the frame's main sizer, then measures all the various UI items
2164 // and updates their internal rectangles. This should always be called
2165 // instead of calling m_frame->Layout() directly
2167 void wxFrameManager::DoFrameLayout()
2172 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2174 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2176 // get the rectangle of the UI part
2177 // originally, this code looked like this:
2178 // part.rect = wxRect(part.sizer_item->GetPosition(),
2179 // part.sizer_item->GetSize());
2180 // this worked quite well, with one exception: the mdi
2181 // client window had a "deferred" size variable
2182 // that returned the wrong size. It looks like
2183 // a bug in wx, because the former size of the window
2184 // was being returned. So, we will retrieve the part's
2185 // rectangle via other means
2188 part
.rect
= part
.sizer_item
->GetRect();
2189 int flag
= part
.sizer_item
->GetFlag();
2190 int border
= part
.sizer_item
->GetBorder();
2193 part
.rect
.y
-= border
;
2194 part
.rect
.height
+= border
;
2198 part
.rect
.x
-= border
;
2199 part
.rect
.width
+= border
;
2201 if (flag
& wxBOTTOM
)
2202 part
.rect
.height
+= border
;
2204 part
.rect
.width
+= border
;
2207 if (part
.type
== wxDockUIPart::typeDock
)
2208 part
.dock
->rect
= part
.rect
;
2209 if (part
.type
== wxDockUIPart::typePane
)
2210 part
.pane
->rect
= part
.rect
;
2214 // GetPanePart() looks up the pane the pane border UI part (or the regular
2215 // pane part if there is no border). This allows the caller to get the exact
2216 // rectangle of the pane in question, including decorations like
2217 // caption and border (if any).
2219 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
2222 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2224 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2225 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2226 part
.pane
&& part
.pane
->window
== wnd
)
2229 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2231 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2232 if (part
.type
== wxDockUIPart::typePane
&&
2233 part
.pane
&& part
.pane
->window
== wnd
)
2241 // GetDockPixelOffset() is an internal function which returns
2242 // a dock's offset in pixels from the left side of the window
2243 // (for horizontal docks) or from the top of the window (for
2244 // vertical docks). This value is necessary for calculating
2245 // fixel-pane/toolbar offsets when they are dragged.
2247 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
2249 // the only way to accurately calculate the dock's
2250 // offset is to actually run a theoretical layout
2252 int i
, part_count
, dock_count
;
2253 wxDockInfoArray docks
;
2254 wxPaneInfoArray panes
;
2255 wxDockUIPartArray uiparts
;
2256 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2259 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2260 wxSize client_size
= m_frame
->GetClientSize();
2261 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2264 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2266 wxDockUIPart
& part
= uiparts
.Item(i
);
2267 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2268 part
.sizer_item
->GetSize());
2269 if (part
.type
== wxDockUIPart::typeDock
)
2270 part
.dock
->rect
= part
.rect
;
2275 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2277 wxDockInfo
& dock
= docks
.Item(i
);
2278 if (test
.dock_direction
== dock
.dock_direction
&&
2279 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2281 if (dock
.IsVertical())
2293 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2294 // if a dock operation is allowed, the new dock position is copied into
2295 // the target info. If the operation was allowed, the function returns true.
2297 bool wxFrameManager::ProcessDockResult(wxPaneInfo
& target
,
2298 const wxPaneInfo
& new_pos
)
2300 bool allowed
= false;
2301 switch (new_pos
.dock_direction
)
2303 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2304 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2305 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2306 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2316 // DoDrop() is an important function. It basically takes a mouse position,
2317 // and determines where the pane's new position would be. If the pane is to be
2318 // dropped, it performs the drop operation using the specified dock and pane
2319 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2320 // scenario can be performed, giving precise coordinates for drop hints.
2321 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2322 // as parameters, the changes will be made to the main state arrays
2324 const int auiInsertRowPixels
= 10;
2325 const int auiNewRowPixels
= 40;
2326 const int auiLayerInsertPixels
= 40;
2327 const int auiLayerInsertOffset
= 5;
2329 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2330 wxPaneInfoArray
& panes
,
2333 const wxPoint
& offset
)
2335 wxSize cli_size
= m_frame
->GetClientSize();
2337 wxPaneInfo drop
= target
;
2340 // The result should always be shown
2344 // Check to see if the pane has been dragged outside of the window
2345 // (or near to the outside of the window), if so, dock it along the edge
2348 int layer_insert_offset
= auiLayerInsertOffset
;
2349 if (target
.IsToolbar())
2350 layer_insert_offset
= 0;
2352 if (pt
.x
< layer_insert_offset
&&
2353 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2357 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2358 return ProcessDockResult(target
, drop
);
2360 else if (pt
.y
< layer_insert_offset
&&
2361 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2365 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2366 return ProcessDockResult(target
, drop
);
2368 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2369 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2371 drop
.Dock().Right().
2373 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2374 return ProcessDockResult(target
, drop
);
2376 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2377 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2379 int new_layer
= wxMax( wxMax( GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2380 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2381 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2383 drop
.Dock().Bottom().
2386 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2387 return ProcessDockResult(target
, drop
);
2390 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2393 if (drop
.IsToolbar())
2395 if (!part
|| !part
->dock
)
2398 // calculate the offset from where the dock begins
2399 // to the point where the user dropped the pane
2400 int dock_drop_offset
= 0;
2401 if (part
->dock
->IsHorizontal())
2402 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2404 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2407 // toolbars may only be moved in and to fixed-pane docks,
2408 // otherwise we will try to float the pane. Also, the pane
2409 // should float if being dragged over center pane windows
2410 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2412 if (m_last_rect
.IsEmpty() || m_last_rect
.Contains(pt
.x
, pt
.y
))
2418 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2419 (drop
.IsFloatable() ||
2420 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2421 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2428 return ProcessDockResult(target
, drop
);
2431 drop
.Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2433 return ProcessDockResult(target
, drop
);
2442 m_last_rect
= part
->dock
->rect
;
2443 m_last_rect
.Inflate( 15, 15 );
2447 Direction(part
->dock
->dock_direction
).
2448 Layer(part
->dock
->dock_layer
).
2449 Row(part
->dock
->dock_row
).
2450 Position(dock_drop_offset
);
2453 ((pt
.y
< part
->dock
->rect
.y
+ 1) && part
->dock
->IsHorizontal()) ||
2454 ((pt
.x
< part
->dock
->rect
.x
+ 1) && part
->dock
->IsVertical())
2455 ) && part
->dock
->panes
.GetCount() > 1)
2457 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2458 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2460 int row
= drop
.dock_row
;
2461 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2462 part
->dock
->dock_layer
,
2463 part
->dock
->dock_row
);
2464 drop
.dock_row
= row
;
2468 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2469 part
->dock
->dock_layer
,
2470 part
->dock
->dock_row
+1);
2471 drop
.dock_row
= part
->dock
->dock_row
+1;
2476 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2477 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2478 ) && part
->dock
->panes
.GetCount() > 1)
2480 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2481 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2483 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2484 part
->dock
->dock_layer
,
2485 part
->dock
->dock_row
+1);
2486 drop
.dock_row
= part
->dock
->dock_row
+1;
2490 int row
= drop
.dock_row
;
2491 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2492 part
->dock
->dock_layer
,
2493 part
->dock
->dock_row
);
2494 drop
.dock_row
= row
;
2498 return ProcessDockResult(target
, drop
);
2507 if (part
->type
== wxDockUIPart::typePaneBorder
||
2508 part
->type
== wxDockUIPart::typeCaption
||
2509 part
->type
== wxDockUIPart::typeGripper
||
2510 part
->type
== wxDockUIPart::typePaneButton
||
2511 part
->type
== wxDockUIPart::typePane
||
2512 part
->type
== wxDockUIPart::typePaneSizer
||
2513 part
->type
== wxDockUIPart::typeDockSizer
||
2514 part
->type
== wxDockUIPart::typeBackground
)
2516 if (part
->type
== wxDockUIPart::typeDockSizer
)
2518 if (part
->dock
->panes
.GetCount() != 1)
2520 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2527 // If a normal frame is being dragged over a toolbar, insert it
2528 // along the edge under the toolbar, but over all other panes.
2529 // (this could be done much better, but somehow factoring this
2530 // calculation with the one at the beginning of this function)
2531 if (part
->dock
&& part
->dock
->toolbar
)
2535 switch (part
->dock
->dock_direction
)
2537 case wxAUI_DOCK_LEFT
:
2538 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2539 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2540 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2542 case wxAUI_DOCK_TOP
:
2543 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2544 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2545 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2547 case wxAUI_DOCK_RIGHT
:
2548 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2549 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2550 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2552 case wxAUI_DOCK_BOTTOM
:
2553 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2554 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2555 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2559 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2562 Direction(part
->dock
->dock_direction
).
2563 Layer(layer
).Row(0).Position(0);
2564 return ProcessDockResult(target
, drop
);
2571 part
= GetPanePart(part
->pane
->window
);
2575 bool insert_dock_row
= false;
2576 int insert_row
= part
->pane
->dock_row
;
2577 int insert_dir
= part
->pane
->dock_direction
;
2578 int insert_layer
= part
->pane
->dock_layer
;
2580 switch (part
->pane
->dock_direction
)
2582 case wxAUI_DOCK_TOP
:
2583 if (pt
.y
>= part
->rect
.y
&&
2584 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2585 insert_dock_row
= true;
2587 case wxAUI_DOCK_BOTTOM
:
2588 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2589 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2590 insert_dock_row
= true;
2592 case wxAUI_DOCK_LEFT
:
2593 if (pt
.x
>= part
->rect
.x
&&
2594 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2595 insert_dock_row
= true;
2597 case wxAUI_DOCK_RIGHT
:
2598 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2599 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2600 insert_dock_row
= true;
2602 case wxAUI_DOCK_CENTER
:
2604 // "new row pixels" will be set to the default, but
2605 // must never exceed 20% of the window size
2606 int new_row_pixels_x
= auiNewRowPixels
;
2607 int new_row_pixels_y
= auiNewRowPixels
;
2609 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2610 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2612 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2613 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2616 // determine if the mouse pointer is in a location that
2617 // will cause a new row to be inserted. The hot spot positions
2618 // are along the borders of the center pane
2621 insert_dock_row
= true;
2622 if (pt
.x
>= part
->rect
.x
&&
2623 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2624 insert_dir
= wxAUI_DOCK_LEFT
;
2626 if (pt
.y
>= part
->rect
.y
&&
2627 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2628 insert_dir
= wxAUI_DOCK_TOP
;
2630 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2631 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2632 insert_dir
= wxAUI_DOCK_RIGHT
;
2634 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2635 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2636 insert_dir
= wxAUI_DOCK_BOTTOM
;
2640 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2644 if (insert_dock_row
)
2646 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2647 drop
.Dock().Direction(insert_dir
).
2648 Layer(insert_layer
).
2651 return ProcessDockResult(target
, drop
);
2654 // determine the mouse offset and the pane size, both in the
2655 // direction of the dock itself, and perpendicular to the dock
2659 if (part
->orientation
== wxVERTICAL
)
2661 offset
= pt
.y
- part
->rect
.y
;
2662 size
= part
->rect
.GetHeight();
2666 offset
= pt
.x
- part
->rect
.x
;
2667 size
= part
->rect
.GetWidth();
2670 int drop_position
= part
->pane
->dock_pos
;
2672 // if we are in the top/left part of the pane,
2673 // insert the pane before the pane being hovered over
2674 if (offset
<= size
/2)
2676 drop_position
= part
->pane
->dock_pos
;
2678 part
->pane
->dock_direction
,
2679 part
->pane
->dock_layer
,
2680 part
->pane
->dock_row
,
2681 part
->pane
->dock_pos
);
2684 // if we are in the bottom/right part of the pane,
2685 // insert the pane before the pane being hovered over
2686 if (offset
> size
/2)
2688 drop_position
= part
->pane
->dock_pos
+1;
2690 part
->pane
->dock_direction
,
2691 part
->pane
->dock_layer
,
2692 part
->pane
->dock_row
,
2693 part
->pane
->dock_pos
+1);
2697 Direction(part
->dock
->dock_direction
).
2698 Layer(part
->dock
->dock_layer
).
2699 Row(part
->dock
->dock_row
).
2700 Position(drop_position
);
2701 return ProcessDockResult(target
, drop
);
2708 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2710 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
2712 m_hint_fadetimer
.Stop();
2716 m_hint_fadeamt
+= 4;
2717 #if wxCHECK_VERSION(2,7,0)
2718 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2720 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2721 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2725 void wxFrameManager::ShowHint(const wxRect
& rect
)
2727 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0
2729 // Finally, don't use a venetian blind effect if it's been specifically disabled
2730 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2731 (m_flags
& wxAUI_MGR_DISABLE_VENETIAN_BLINDS
))
2734 if (m_last_hint
== rect
)
2738 m_hint_fadeamt
= m_hint_fademax
;
2739 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2740 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2741 (m_flags
& wxAUI_MGR_DISABLE_VENETIAN_BLINDS_FADE
))
2745 m_hint_wnd
->SetSize(rect
);
2747 if (! m_hint_wnd
->IsShown())
2750 // if we are dragging a floating pane, set the focus
2751 // back to that floating pane (otherwise it becomes unfocused)
2752 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2753 m_action_window
->SetFocus();
2755 #if wxCHECK_VERSION(2,7,0)
2756 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2758 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2759 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2761 m_hint_wnd
->Raise();
2764 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
2766 // start fade in timer
2767 m_hint_fadetimer
.SetOwner(this, 101);
2768 m_hint_fadetimer
.Start(5);
2772 else // Not using a transparent hint window...
2775 if (m_last_hint
!= rect
)
2777 // remove the last hint rectangle
2783 wxScreenDC screendc
;
2784 wxRegion
clip(1, 1, 10000, 10000);
2786 // clip all floating windows, so we don't draw over them
2788 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2790 wxPaneInfo
& pane
= m_panes
.Item(i
);
2792 if (pane
.IsFloating() &&
2793 pane
.frame
->IsShown())
2795 wxRect rect
= pane
.frame
->GetRect();
2797 // wxGTK returns the client size, not the whole frame size
2803 clip
.Subtract(rect
);
2807 // As we can only hide the hint by redrawing the managed window, we
2808 // need to clip the region to the managed window too or we get
2809 // nasty redrawn problems.
2810 clip
.Intersect(m_frame
->GetRect());
2812 screendc
.SetClippingRegion(clip
);
2814 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2815 wxBrush
brush(stipple
);
2816 screendc
.SetBrush(brush
);
2817 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2819 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2820 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2821 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2822 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2826 void wxFrameManager::HideHint()
2828 // hides a transparent window hint, if there is one
2831 if (m_hint_wnd
->IsShown())
2832 m_hint_wnd
->Show(false);
2833 #if wxCHECK_VERSION(2,7,0)
2834 m_hint_wnd
->SetTransparent(0);
2836 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2837 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(0);
2839 m_hint_fadetimer
.Stop();
2840 m_last_hint
= wxRect();
2844 // hides a painted hint by redrawing the frame window
2845 if (!m_last_hint
.IsEmpty())
2849 m_last_hint
= wxRect();
2855 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2856 // determine the exact position the pane would be at were if dropped. If
2857 // the pame would indeed become docked at the specified drop point,
2858 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2859 // "pane_window" is the window pointer of the pane being dragged, pt is
2860 // the mouse position, in client coordinates
2861 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2863 const wxPoint
& offset
)
2867 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2868 // we will create a new temporary layout and then measure the resulting
2869 // rectangle; we will create a copy of the docking structures (m_dock)
2870 // so that we don't modify the real thing on screen
2872 int i
, pane_count
, part_count
;
2873 wxDockInfoArray docks
;
2874 wxPaneInfoArray panes
;
2875 wxDockUIPartArray uiparts
;
2876 wxPaneInfo hint
= GetPane(pane_window
);
2877 hint
.name
= wxT("__HINT__");
2883 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2885 // remove any pane already there which bears the same window;
2886 // this happens when you are moving a pane around in a dock
2887 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2889 if (panes
.Item(i
).window
== pane_window
)
2891 RemovePaneFromDocks(docks
, panes
.Item(i
));
2897 // find out where the new pane would be
2898 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2906 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2907 wxSize client_size
= m_frame
->GetClientSize();
2908 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2911 for (i
= 0, part_count
= uiparts
.GetCount();
2912 i
< part_count
; ++i
)
2914 wxDockUIPart
& part
= uiparts
.Item(i
);
2916 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2917 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2919 rect
= wxRect(part
.sizer_item
->GetPosition(),
2920 part
.sizer_item
->GetSize());
2933 // actually show the hint rectangle on the screen
2934 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2938 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2940 // try to find the pane
2941 wxPaneInfo
& pane
= GetPane(wnd
);
2942 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2944 #if wxCHECK_VERSION(2,7,0)
2945 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2946 pane
.frame
->SetTransparent(150);
2950 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
2952 // try to find the pane
2953 wxPaneInfo
& pane
= GetPane(wnd
);
2954 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2956 wxPoint pt
= ::wxGetMousePosition();
2959 // Adapt pt to direction
2962 // move to pane's upper border
2964 pos
= wnd
->ClientToScreen( pos
);
2966 // and some more pixels for the title bar
2971 // move to pane's left border
2973 pos
= wnd
->ClientToScreen( pos
);
2978 // move to pane's right border
2979 wxPoint
pos( wnd
->GetSize().x
, 0 );
2980 pos
= wnd
->ClientToScreen( pos
);
2985 // move to pane's bottom border
2986 wxPoint
pos( 0, wnd
->GetSize().y
);
2987 pos
= wnd
->ClientToScreen( pos
);
2994 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2996 // calculate the offset from the upper left-hand corner
2997 // of the frame to the mouse pointer
2998 wxPoint frame_pos
= pane
.frame
->GetPosition();
2999 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3001 // no hint for toolbar floating windows
3002 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
3004 if (m_action
== actionDragFloatingPane
)
3006 wxDockInfoArray docks
;
3007 wxPaneInfoArray panes
;
3008 wxDockUIPartArray uiparts
;
3009 wxPaneInfo hint
= pane
;
3011 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3013 // find out where the new pane would be
3014 if (!DoDrop(docks
, panes
, hint
, client_pt
))
3016 if (hint
.IsFloating())
3020 m_action
= actionDragToolbarPane
;
3021 m_action_window
= pane
.window
;
3030 // if a key modifier is pressed while dragging the frame,
3031 // don't dock the window
3032 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
3039 DrawHintRect(wnd
, client_pt
, action_offset
);
3042 // this cleans up some screen artifacts that are caused on GTK because
3043 // we aren't getting the exact size of the window (see comment
3053 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
3055 // try to find the pane
3056 wxPaneInfo
& pane
= GetPane(wnd
);
3057 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3059 wxPoint pt
= ::wxGetMousePosition();
3062 // Adapt pt to direction
3065 // move to pane's upper border
3067 pos
= wnd
->ClientToScreen( pos
);
3069 // and some more pixels for the title bar
3074 // move to pane's left border
3076 pos
= wnd
->ClientToScreen( pos
);
3081 // move to pane's right border
3082 wxPoint
pos( wnd
->GetSize().x
, 0 );
3083 pos
= wnd
->ClientToScreen( pos
);
3088 // move to pane's bottom border
3089 wxPoint
pos( 0, wnd
->GetSize().y
);
3090 pos
= wnd
->ClientToScreen( pos
);
3097 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3099 // calculate the offset from the upper left-hand corner
3100 // of the frame to the mouse pointer
3101 wxPoint frame_pos
= pane
.frame
->GetPosition();
3102 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3105 // if a key modifier is pressed while dragging the frame,
3106 // don't dock the window
3107 if (!wxGetKeyState(WXK_CONTROL
) && !wxGetKeyState(WXK_ALT
))
3109 // do the drop calculation
3110 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3113 // if the pane is still floating, update it's floating
3114 // position (that we store)
3115 if (pane
.IsFloating())
3117 pane
.floating_pos
= pane
.frame
->GetPosition();
3119 #if wxCHECK_VERSION(2,7,0)
3120 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3121 pane
.frame
->SetTransparent(255);
3130 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3132 // try to find the pane
3133 wxPaneInfo
& pane
= GetPane(wnd
);
3134 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3136 pane
.floating_size
= size
;
3140 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3142 // try to find the pane
3143 wxPaneInfo
& pane
= GetPane(wnd
);
3144 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3147 // fire pane close event
3148 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3150 e
.SetCanVeto(evt
.CanVeto());
3166 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3168 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3170 // try to find the pane
3171 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
3173 SetActivePane(m_panes
, wnd
);
3178 // OnRender() draws all of the pane captions, sashes,
3179 // backgrounds, captions, grippers, pane borders and buttons.
3180 // It renders the entire user interface.
3182 void wxFrameManager::OnRender(wxFrameManagerEvent
& evt
)
3184 wxDC
* dc
= evt
.GetDC();
3190 for (i
= 0, part_count
= m_uiparts
.GetCount();
3191 i
< part_count
; ++i
)
3193 wxDockUIPart
& part
= m_uiparts
.Item(i
);
3195 // don't draw hidden pane items
3196 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
3201 case wxDockUIPart::typeDockSizer
:
3202 case wxDockUIPart::typePaneSizer
:
3203 m_art
->DrawSash(*dc
, m_frame
, part
.orientation
, part
.rect
);
3205 case wxDockUIPart::typeBackground
:
3206 m_art
->DrawBackground(*dc
, m_frame
, part
.orientation
, part
.rect
);
3208 case wxDockUIPart::typeCaption
:
3209 m_art
->DrawCaption(*dc
, m_frame
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3211 case wxDockUIPart::typeGripper
:
3212 m_art
->DrawGripper(*dc
, m_frame
, part
.rect
, *part
.pane
);
3214 case wxDockUIPart::typePaneBorder
:
3215 m_art
->DrawBorder(*dc
, m_frame
, part
.rect
, *part
.pane
);
3217 case wxDockUIPart::typePaneButton
:
3218 m_art
->DrawPaneButton(*dc
, m_frame
, part
.button
->button_id
,
3219 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3226 // Render() fire a render event, which is normally handled by
3227 // wxFrameManager::OnRender(). This allows the render function to
3228 // be overridden via the render event. This can be useful for paintin
3229 // custom graphics in the main window. Default behavior can be
3230 // invoked in the overridden function by calling OnRender()
3232 void wxFrameManager::Render(wxDC
* dc
)
3234 wxFrameManagerEvent
e(wxEVT_AUI_RENDER
);
3239 void wxFrameManager::Repaint(wxDC
* dc
)
3244 m_frame
->Refresh() ;
3250 m_frame
->GetClientSize(&w
, &h
);
3252 // figure out which dc to use; if one
3253 // has been specified, use it, otherwise
3255 wxClientDC
* client_dc
= NULL
;
3258 client_dc
= new wxClientDC(m_frame
);
3262 // if the frame has a toolbar, the client area
3263 // origin will not be (0,0).
3264 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3265 if (pt
.x
!= 0 || pt
.y
!= 0)
3266 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3268 // render all the items
3271 // if we created a client_dc, delete it
3276 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3278 wxPaintDC
dc(m_frame
);
3282 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
3291 void wxFrameManager::OnSize(wxSizeEvent
& event
)
3302 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
3305 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3306 wxCursor cursor
= wxNullCursor
;
3310 if (part
->type
== wxDockUIPart::typeDockSizer
||
3311 part
->type
== wxDockUIPart::typePaneSizer
)
3313 // a dock may not be resized if it has a single
3314 // pane which is not resizable
3315 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3316 part
->dock
->panes
.GetCount() == 1 &&
3317 part
->dock
->panes
.Item(0)->IsFixed())
3320 // panes that may not be resized do not get a sizing cursor
3321 if (part
->pane
&& part
->pane
->IsFixed())
3324 if (part
->orientation
== wxVERTICAL
)
3325 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3327 cursor
= wxCursor(wxCURSOR_SIZENS
);
3329 else if (part
->type
== wxDockUIPart::typeGripper
)
3331 cursor
= wxCursor(wxCURSOR_SIZING
);
3335 event
.SetCursor(cursor
);
3340 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
3341 const wxMouseEvent
& event
)
3343 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3345 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3347 if (hit_test
== button_ui_part
)
3349 if (event
.LeftDown())
3350 state
= wxAUI_BUTTON_STATE_PRESSED
;
3352 state
= wxAUI_BUTTON_STATE_HOVER
;
3356 if (event
.LeftDown())
3357 state
= wxAUI_BUTTON_STATE_HOVER
;
3360 // now repaint the button with hover state
3361 wxClientDC
cdc(m_frame
);
3363 // if the frame has a toolbar, the client area
3364 // origin will not be (0,0).
3365 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3366 if (pt
.x
!= 0 || pt
.y
!= 0)
3367 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3369 m_art
->DrawPaneButton(cdc
, m_frame
,
3370 button_ui_part
->button
->button_id
,
3372 button_ui_part
->rect
,
3376 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
3378 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3381 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3384 if (part
->type
== wxDockUIPart::typeDockSizer
||
3385 part
->type
== wxDockUIPart::typePaneSizer
)
3387 // a dock may not be resized if it has a single
3388 // pane which is not resizable
3389 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3390 part
->dock
->panes
.GetCount() == 1 &&
3391 part
->dock
->panes
.Item(0)->IsFixed())
3394 // panes that may not be resized should be ignored here
3395 if (part
->pane
&& part
->pane
->IsFixed())
3398 m_action
= actionResize
;
3399 m_action_part
= part
;
3400 m_action_hintrect
= wxRect();
3401 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3402 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3403 event
.m_y
- part
->rect
.y
);
3404 m_frame
->CaptureMouse();
3406 else if (part
->type
== wxDockUIPart::typePaneButton
)
3408 m_action
= actionClickButton
;
3409 m_action_part
= part
;
3410 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3411 m_frame
->CaptureMouse();
3413 UpdateButtonOnScreen(part
, event
);
3415 else if (part
->type
== wxDockUIPart::typeCaption
||
3416 part
->type
== wxDockUIPart::typeGripper
)
3418 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3420 // set the caption as active
3421 SetActivePane(m_panes
, part
->pane
->window
);
3425 m_action
= actionClickCaption
;
3426 m_action_part
= part
;
3427 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3428 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3429 event
.m_y
- part
->rect
.y
);
3430 m_frame
->CaptureMouse();
3450 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3452 if (m_action
== actionResize
)
3454 m_frame
->ReleaseMouse();
3456 // get rid of the hint rectangle
3458 DrawResizeHint(dc
, m_action_hintrect
);
3460 // resize the dock or the pane
3461 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3463 wxRect
& rect
= m_action_part
->dock
->rect
;
3465 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3466 event
.m_y
- m_action_offset
.y
);
3468 switch (m_action_part
->dock
->dock_direction
)
3470 case wxAUI_DOCK_LEFT
:
3471 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3473 case wxAUI_DOCK_TOP
:
3474 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3476 case wxAUI_DOCK_RIGHT
:
3477 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3478 new_pos
.x
- m_action_part
->rect
.GetWidth();
3480 case wxAUI_DOCK_BOTTOM
:
3481 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3482 new_pos
.y
- m_action_part
->rect
.GetHeight();
3489 else if (m_action_part
&&
3490 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3492 wxDockInfo
& dock
= *m_action_part
->dock
;
3493 wxPaneInfo
& pane
= *m_action_part
->pane
;
3495 int total_proportion
= 0;
3496 int dock_pixels
= 0;
3497 int new_pixsize
= 0;
3499 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3500 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3501 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3503 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3504 event
.m_y
- m_action_offset
.y
);
3506 // determine the pane rectangle by getting the pane part
3507 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3508 wxASSERT_MSG(pane_part
,
3509 wxT("Pane border part not found -- shouldn't happen"));
3511 // determine the new pixel size that the user wants;
3512 // this will help us recalculate the pane's proportion
3513 if (dock
.IsHorizontal())
3514 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3516 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3518 // determine the size of the dock, based on orientation
3519 if (dock
.IsHorizontal())
3520 dock_pixels
= dock
.rect
.GetWidth();
3522 dock_pixels
= dock
.rect
.GetHeight();
3524 // determine the total proportion of all resizable panes,
3525 // and the total size of the dock minus the size of all
3527 int i
, dock_pane_count
= dock
.panes
.GetCount();
3528 int pane_position
= -1;
3529 for (i
= 0; i
< dock_pane_count
; ++i
)
3531 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3532 if (p
.window
== pane
.window
)
3535 // while we're at it, subtract the pane sash
3536 // width from the dock width, because this would
3537 // skew our proportion calculations
3539 dock_pixels
-= sash_size
;
3541 // also, the whole size (including decorations) of
3542 // all fixed panes must also be subtracted, because they
3543 // are not part of the proportion calculation
3546 if (dock
.IsHorizontal())
3547 dock_pixels
-= p
.best_size
.x
;
3549 dock_pixels
-= p
.best_size
.y
;
3553 total_proportion
+= p
.dock_proportion
;
3557 // find a pane in our dock to 'steal' space from or to 'give'
3558 // space to -- this is essentially what is done when a pane is
3559 // resized; the pane should usually be the first non-fixed pane
3560 // to the right of the action pane
3561 int borrow_pane
= -1;
3562 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3564 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3573 // demand that the pane being resized is found in this dock
3574 // (this assert really never should be raised)
3575 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3577 // prevent division by zero
3578 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3580 m_action
= actionNone
;
3584 // calculate the new proportion of the pane
3585 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3587 // default minimum size
3590 // check against the pane's minimum size, if specified. please note
3591 // that this is not enough to ensure that the minimum size will
3592 // not be violated, because the whole frame might later be shrunk,
3593 // causing the size of the pane to violate it's minimum size
3594 if (pane
.min_size
.IsFullySpecified())
3598 if (pane
.HasBorder())
3599 min_size
+= (pane_border_size
*2);
3601 // calculate minimum size with decorations (border,caption)
3602 if (pane_part
->orientation
== wxVERTICAL
)
3604 min_size
+= pane
.min_size
.y
;
3605 if (pane
.HasCaption())
3606 min_size
+= caption_size
;
3610 min_size
+= pane
.min_size
.x
;
3615 // for some reason, an arithmatic error somewhere is causing
3616 // the proportion calculations to always be off by 1 pixel;
3617 // for now we will add the 1 pixel on, but we really should
3618 // determine what's causing this.
3621 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3623 if (new_proportion
< min_proportion
)
3624 new_proportion
= min_proportion
;
3628 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3630 // borrow the space from our neighbor pane to the
3631 // right or bottom (depending on orientation)
3632 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3633 pane
.dock_proportion
= new_proportion
;
3640 else if (m_action
== actionClickButton
)
3642 m_hover_button
= NULL
;
3643 m_frame
->ReleaseMouse();
3644 UpdateButtonOnScreen(m_action_part
, event
);
3646 // make sure we're still over the item that was originally clicked
3647 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3649 // fire button-click event
3650 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3651 e
.SetPane(m_action_part
->pane
);
3652 e
.SetButton(m_action_part
->button
->button_id
);
3656 else if (m_action
== actionClickCaption
)
3658 m_frame
->ReleaseMouse();
3660 else if (m_action
== actionDragFloatingPane
)
3662 m_frame
->ReleaseMouse();
3664 else if (m_action
== actionDragToolbarPane
)
3666 m_frame
->ReleaseMouse();
3668 wxPaneInfo
& pane
= GetPane(m_action_window
);
3669 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3671 // save the new positions
3672 wxDockInfoPtrArray docks
;
3673 FindDocks(m_docks
, pane
.dock_direction
,
3674 pane
.dock_layer
, pane
.dock_row
, docks
);
3675 if (docks
.GetCount() == 1)
3677 wxDockInfo
& dock
= *docks
.Item(0);
3679 wxArrayInt pane_positions
, pane_sizes
;
3680 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3682 int i
, dock_pane_count
= dock
.panes
.GetCount();
3683 for (i
= 0; i
< dock_pane_count
; ++i
)
3684 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3687 pane
.state
&= ~wxPaneInfo::actionPane
;
3695 m_action
= actionNone
;
3696 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3700 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3702 // sometimes when Update() is called from inside this method,
3703 // a spurious mouse move event is generated; this check will make
3704 // sure that only real mouse moves will get anywhere in this method;
3705 // this appears to be a bug somewhere, and I don't know where the
3706 // mouse move event is being generated. only verified on MSW
3708 wxPoint mouse_pos
= event
.GetPosition();
3709 if (m_last_mouse_move
== mouse_pos
)
3711 m_last_mouse_move
= mouse_pos
;
3714 if (m_action
== actionResize
)
3716 wxPoint pos
= m_action_part
->rect
.GetPosition();
3717 if (m_action_part
->orientation
== wxHORIZONTAL
)
3718 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3720 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3722 wxRect
rect(m_frame
->ClientToScreen(pos
),
3723 m_action_part
->rect
.GetSize());
3726 if (!m_action_hintrect
.IsEmpty())
3727 DrawResizeHint(dc
, m_action_hintrect
);
3728 DrawResizeHint(dc
, rect
);
3729 m_action_hintrect
= rect
;
3731 else if (m_action
== actionClickCaption
)
3733 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3734 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3736 // caption has been clicked. we need to check if the mouse
3737 // is now being dragged. if it is, we need to change the
3738 // mouse action to 'drag'
3739 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3740 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3742 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3744 if (!pane_info
->IsToolbar())
3746 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3747 pane_info
->IsFloatable())
3749 m_action
= actionDragFloatingPane
;
3751 // set initial float position
3752 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3753 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3754 pt
.y
- m_action_offset
.y
);
3759 m_action_window
= pane_info
->frame
;
3761 // action offset is used here to make it feel "natural" to the user
3762 // to drag a docked pane and suddenly have it become a floating frame.
3763 // Sometimes, however, the offset where the user clicked on the docked
3764 // caption is bigger than the width of the floating frame itself, so
3765 // in that case we need to set the action offset to a sensible value
3766 wxSize frame_size
= m_action_window
->GetSize();
3767 if (frame_size
.x
<= m_action_offset
.x
)
3768 m_action_offset
.x
= 30;
3773 m_action
= actionDragToolbarPane
;
3774 m_action_window
= pane_info
->window
;
3778 else if (m_action
== actionDragFloatingPane
)
3780 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3781 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3782 pt
.y
- m_action_offset
.y
);
3784 else if (m_action
== actionDragToolbarPane
)
3786 wxPaneInfo
& pane
= GetPane(m_action_window
);
3787 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3789 pane
.state
|= wxPaneInfo::actionPane
;
3791 wxPoint pt
= event
.GetPosition();
3792 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3794 // if DoDrop() decided to float the pane, set up
3795 // the floating pane's initial position
3796 if (pane
.IsFloating())
3798 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3799 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3800 pt
.y
- m_action_offset
.y
);
3803 // this will do the actiual move operation;
3804 // in the case that the pane has been floated,
3805 // this call will create the floating pane
3806 // and do the reparenting
3809 // if the pane has been floated, change the mouse
3810 // action actionDragFloatingPane so that subsequent
3811 // EVT_MOTION() events will move the floating pane
3812 if (pane
.IsFloating())
3814 pane
.state
&= ~wxPaneInfo::actionPane
;
3815 m_action
= actionDragFloatingPane
;
3816 m_action_window
= pane
.frame
;
3821 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3822 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3824 if (part
!= m_hover_button
)
3826 // make the old button normal
3828 UpdateButtonOnScreen(m_hover_button
, event
);
3830 // mouse is over a button, so repaint the
3831 // button in hover mode
3832 UpdateButtonOnScreen(part
, event
);
3833 m_hover_button
= part
;
3840 m_hover_button
= NULL
;
3851 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3855 m_hover_button
= NULL
;
3860 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3862 // when a child pane has it's focus set, we should change the
3863 // pane's active state to reflect this. (this is only true if
3864 // active panes are allowed by the owner)
3865 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3867 if (GetPane(event
.GetWindow()).IsOk())
3869 SetActivePane(m_panes
, event
.GetWindow());
3878 // OnPaneButton() is an event handler that is called
3879 // when a pane button has been pressed.
3880 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& evt
)
3882 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3884 wxPaneInfo
& pane
= *(evt
.pane
);
3886 if (evt
.button
== wxPaneInfo::buttonClose
)
3888 // fire pane close event
3889 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3890 e
.SetPane(evt
.pane
);
3899 else if (evt
.button
== wxPaneInfo::buttonPin
)
3901 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&