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(wxAuiDockUIPartArray
)
49 WX_DEFINE_OBJARRAY(wxAuiDockInfoArray
)
50 WX_DEFINE_OBJARRAY(wxAuiPaneButtonArray
)
51 WX_DEFINE_OBJARRAY(wxAuiPaneInfoArray
)
53 wxAuiPaneInfo wxAuiNullPaneInfo
;
54 wxAuiDockInfo wxAuiNullDockInfo
;
55 DEFINE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON
)
56 DEFINE_EVENT_TYPE(wxEVT_AUI_PANECLOSE
)
57 DEFINE_EVENT_TYPE(wxEVT_AUI_PANEMAXIMIZE
)
58 DEFINE_EVENT_TYPE(wxEVT_AUI_PANERESTORE
)
59 DEFINE_EVENT_TYPE(wxEVT_AUI_RENDER
)
60 DEFINE_EVENT_TYPE(wxEVT_AUI_FINDMANAGER
)
63 // a few defines to avoid nameclashes
64 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
66 #include "wx/mac/private.h"
69 IMPLEMENT_DYNAMIC_CLASS(wxAuiManagerEvent
, wxEvent
)
70 IMPLEMENT_CLASS(wxAuiManager
, wxEvtHandler
)
72 // private manager flags (not yet on the public API)
73 enum wxAuiPrivateManagerOption
75 wxAUI_MGR_NO_DOCK_SIZE_LIMIT
= 1 << 28
81 class wxPseudoTransparentFrame
: public wxFrame
84 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
85 wxWindowID id
= wxID_ANY
,
86 const wxString
& title
= wxEmptyString
,
87 const wxPoint
& pos
= wxDefaultPosition
,
88 const wxSize
& size
= wxDefaultSize
,
89 long style
= wxDEFAULT_FRAME_STYLE
,
90 const wxString
&name
= wxT("frame"))
91 : wxFrame(parent
, id
, title
, pos
, size
, style
| wxFRAME_SHAPED
, name
)
93 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
100 m_CanSetShape
= false; // have to wait for window create event on GTK
102 m_CanSetShape
= true;
104 m_Region
= wxRegion(0, 0, 0, 0);
108 virtual bool SetTransparent(wxByte alpha
)
112 int w
=100; // some defaults
114 GetClientSize(&w
, &h
);
120 // m_Region.Union(0, 0, 1, m_MaxWidth);
123 for (int y
=0; y
<m_MaxHeight
; y
++)
125 // Reverse the order of the bottom 4 bits
126 int j
=((y
&8)?1:0)|((y
&4)?2:0)|((y
&2)?4:0)|((y
&1)?8:0);
127 if ((j
*16+8)<m_Amount
)
128 m_Region
.Union(0, y
, m_MaxWidth
, 1);
137 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
141 if (m_Region
.IsEmpty())
145 dc
.SetBrush(wxColour(128, 192, 255));
147 dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
149 dc
.SetPen(*wxTRANSPARENT_PEN
);
151 wxRegionIterator
upd(GetUpdateRegion()); // get the update rect list
155 wxRect
rect(upd
.GetRect());
156 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
163 void OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
))
170 void OnSize(wxSizeEvent
& event
)
172 // We sometimes get surplus size events
173 if ((event
.GetSize().GetWidth() == m_lastWidth
) &&
174 (event
.GetSize().GetHeight() == m_lastHeight
))
179 m_lastWidth
= event
.GetSize().GetWidth();
180 m_lastHeight
= event
.GetSize().GetHeight();
182 SetTransparent(m_Amount
);
183 m_Region
.Intersect(0, 0, event
.GetSize().GetWidth(),
184 event
.GetSize().GetHeight());
195 int m_lastWidth
,m_lastHeight
;
199 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
200 DECLARE_EVENT_TABLE()
204 IMPLEMENT_DYNAMIC_CLASS(wxPseudoTransparentFrame
, wxFrame
)
206 BEGIN_EVENT_TABLE(wxPseudoTransparentFrame
, wxFrame
)
207 EVT_PAINT(wxPseudoTransparentFrame::OnPaint
)
208 EVT_SIZE(wxPseudoTransparentFrame::OnSize
)
210 EVT_WINDOW_CREATE(wxPseudoTransparentFrame::OnWindowCreate
)
215 // -- static utility functions --
217 static wxBitmap
wxPaneCreateStippleBitmap()
219 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
220 wxImage
img(2,2,data
,true);
221 return wxBitmap(img
);
224 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
226 wxBitmap stipple
= wxPaneCreateStippleBitmap();
227 wxBrush
brush(stipple
);
229 dc
.SetPen(*wxTRANSPARENT_PEN
);
231 dc
.SetLogicalFunction(wxXOR
);
232 dc
.DrawRectangle(rect
);
237 // CopyDocksAndPanes() - this utility function creates copies of
238 // the dock and pane info. wxAuiDockInfo's usually contain pointers
239 // to wxAuiPaneInfo classes, thus this function is necessary to reliably
240 // reconstruct that relationship in the new dock info and pane info arrays
242 static void CopyDocksAndPanes(wxAuiDockInfoArray
& dest_docks
,
243 wxAuiPaneInfoArray
& dest_panes
,
244 const wxAuiDockInfoArray
& src_docks
,
245 const wxAuiPaneInfoArray
& src_panes
)
247 dest_docks
= src_docks
;
248 dest_panes
= src_panes
;
249 int i
, j
, k
, dock_count
, pc1
, pc2
;
250 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
252 wxAuiDockInfo
& dock
= dest_docks
.Item(i
);
253 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
254 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
255 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
256 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
260 // GetMaxLayer() is an internal function which returns
261 // the highest layer inside the specified dock
262 static int GetMaxLayer(const wxAuiDockInfoArray
& docks
, int dock_direction
)
264 int i
, dock_count
, max_layer
= 0;
265 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
267 wxAuiDockInfo
& dock
= docks
.Item(i
);
268 if (dock
.dock_direction
== dock_direction
&&
269 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
270 max_layer
= dock
.dock_layer
;
276 // GetMaxRow() is an internal function which returns
277 // the highest layer inside the specified dock
278 static int GetMaxRow(const wxAuiPaneInfoArray
& panes
, int direction
, int layer
)
280 int i
, pane_count
, max_row
= 0;
281 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
283 wxAuiPaneInfo
& pane
= panes
.Item(i
);
284 if (pane
.dock_direction
== direction
&&
285 pane
.dock_layer
== layer
&&
286 pane
.dock_row
> max_row
)
287 max_row
= pane
.dock_row
;
294 // DoInsertDockLayer() is an internal function that inserts a new dock
295 // layer by incrementing all existing dock layer values by one
296 static void DoInsertDockLayer(wxAuiPaneInfoArray
& panes
,
301 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
303 wxAuiPaneInfo
& pane
= panes
.Item(i
);
304 if (!pane
.IsFloating() &&
305 pane
.dock_direction
== dock_direction
&&
306 pane
.dock_layer
>= dock_layer
)
311 // DoInsertDockLayer() is an internal function that inserts a new dock
312 // row by incrementing all existing dock row values by one
313 static void DoInsertDockRow(wxAuiPaneInfoArray
& panes
,
319 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
321 wxAuiPaneInfo
& pane
= panes
.Item(i
);
322 if (!pane
.IsFloating() &&
323 pane
.dock_direction
== dock_direction
&&
324 pane
.dock_layer
== dock_layer
&&
325 pane
.dock_row
>= dock_row
)
330 // DoInsertDockLayer() is an internal function that inserts a space for
331 // another dock pane by incrementing all existing dock row values by one
332 static void DoInsertPane(wxAuiPaneInfoArray
& panes
,
339 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
341 wxAuiPaneInfo
& pane
= panes
.Item(i
);
342 if (!pane
.IsFloating() &&
343 pane
.dock_direction
== dock_direction
&&
344 pane
.dock_layer
== dock_layer
&&
345 pane
.dock_row
== dock_row
&&
346 pane
.dock_pos
>= dock_pos
)
351 // FindDocks() is an internal function that returns a list of docks which meet
352 // the specified conditions in the parameters and returns a sorted array
353 // (sorted by layer and then row)
354 static void FindDocks(wxAuiDockInfoArray
& docks
,
358 wxAuiDockInfoPtrArray
& arr
)
360 int begin_layer
= dock_layer
;
361 int end_layer
= dock_layer
;
362 int begin_row
= dock_row
;
363 int end_row
= dock_row
;
364 int dock_count
= docks
.GetCount();
365 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
367 // discover the maximum dock layer and the max row
368 for (i
= 0; i
< dock_count
; ++i
)
370 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
371 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
374 // if no dock layer was specified, search all dock layers
375 if (dock_layer
== -1)
378 end_layer
= max_layer
;
381 // if no dock row was specified, search all dock row
390 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
391 for (row
= begin_row
; row
<= end_row
; ++row
)
392 for (i
= 0; i
< dock_count
; ++i
)
394 wxAuiDockInfo
& d
= docks
.Item(i
);
395 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
397 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
403 // FindPaneInDock() looks up a specified window pointer inside a dock.
404 // If found, the corresponding wxAuiPaneInfo pointer is returned, otherwise NULL.
405 static wxAuiPaneInfo
* FindPaneInDock(const wxAuiDockInfo
& dock
, wxWindow
* window
)
407 int i
, count
= dock
.panes
.GetCount();
408 for (i
= 0; i
< count
; ++i
)
410 wxAuiPaneInfo
* p
= dock
.panes
.Item(i
);
411 if (p
->window
== window
)
417 // RemovePaneFromDocks() removes a pane window from all docks
418 // with a possible exception specified by parameter "ex_cept"
419 static void RemovePaneFromDocks(wxAuiDockInfoArray
& docks
,
421 wxAuiDockInfo
* ex_cept
= NULL
)
424 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
426 wxAuiDockInfo
& d
= docks
.Item(i
);
429 wxAuiPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
435 // RenumberDockRows() takes a dock and assigns sequential numbers
436 // to existing rows. Basically it takes out the gaps; so if a
437 // dock has rows with numbers 0,2,5, they will become 0,1,2
438 static void RenumberDockRows(wxAuiDockInfoPtrArray
& docks
)
440 int i
, dock_count
, j
, pane_count
;
441 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
443 wxAuiDockInfo
& dock
= *docks
.Item(i
);
445 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
446 dock
.panes
.Item(j
)->dock_row
= i
;
451 // SetActivePane() sets the active pane, as well as cycles through
452 // every other pane and makes sure that all others' active flags
454 static void SetActivePane(wxAuiPaneInfoArray
& panes
, wxWindow
* active_pane
)
457 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
459 wxAuiPaneInfo
& pane
= panes
.Item(i
);
460 pane
.state
&= ~wxAuiPaneInfo::optionActive
;
461 if (pane
.window
== active_pane
)
462 pane
.state
|= wxAuiPaneInfo::optionActive
;
467 // this function is used to sort panes by dock position
468 static int PaneSortFunc(wxAuiPaneInfo
** p1
, wxAuiPaneInfo
** p2
)
470 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
474 // -- wxAuiManager class implementation --
477 BEGIN_EVENT_TABLE(wxAuiManager
, wxEvtHandler
)
478 EVT_AUI_PANEBUTTON(wxAuiManager::OnPaneButton
)
479 EVT_AUI_RENDER(wxAuiManager::OnRender
)
480 EVT_PAINT(wxAuiManager::OnPaint
)
481 EVT_ERASE_BACKGROUND(wxAuiManager::OnEraseBackground
)
482 EVT_SIZE(wxAuiManager::OnSize
)
483 EVT_SET_CURSOR(wxAuiManager::OnSetCursor
)
484 EVT_LEFT_DOWN(wxAuiManager::OnLeftDown
)
485 EVT_LEFT_UP(wxAuiManager::OnLeftUp
)
486 EVT_MOTION(wxAuiManager::OnMotion
)
487 EVT_LEAVE_WINDOW(wxAuiManager::OnLeaveWindow
)
488 EVT_CHILD_FOCUS(wxAuiManager::OnChildFocus
)
489 EVT_AUI_FINDMANAGER(wxAuiManager::OnFindManager
)
490 EVT_TIMER(101, wxAuiManager::OnHintFadeTimer
)
494 wxAuiManager::wxAuiManager(wxWindow
* managed_wnd
, unsigned int flags
)
496 m_action
= actionNone
;
497 m_last_mouse_move
= wxPoint();
498 m_hover_button
= NULL
;
499 m_art
= new wxAuiDefaultDockArt
;
503 m_has_maximized
= false;
508 SetManagedWindow(managed_wnd
);
512 wxAuiManager::~wxAuiManager()
517 // Creates a floating frame for the windows
518 wxAuiFloatingFrame
* wxAuiManager::CreateFloatingFrame(wxWindow
* parent
, const wxAuiPaneInfo
& p
)
520 return new wxAuiFloatingFrame(parent
, this, p
);
523 // GetPane() looks up a wxAuiPaneInfo structure based
524 // on the supplied window pointer. Upon failure, GetPane()
525 // returns an empty wxAuiPaneInfo, a condition which can be checked
526 // by calling wxAuiPaneInfo::IsOk().
528 // The pane info's structure may then be modified. Once a pane's
529 // info is modified, wxAuiManager::Update() must be called to
530 // realize the changes in the UI.
532 wxAuiPaneInfo
& wxAuiManager::GetPane(wxWindow
* window
)
535 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
537 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
538 if (p
.window
== window
)
541 return wxAuiNullPaneInfo
;
544 // this version of GetPane() looks up a pane based on a
545 // 'pane name', see above comment for more info
546 wxAuiPaneInfo
& wxAuiManager::GetPane(const wxString
& name
)
549 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
551 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
555 return wxAuiNullPaneInfo
;
558 // GetAllPanes() returns a reference to all the pane info structures
559 wxAuiPaneInfoArray
& wxAuiManager::GetAllPanes()
564 // HitTest() is an internal function which determines
565 // which UI item the specified coordinates are over
566 // (x,y) specify a position in client coordinates
567 wxAuiDockUIPart
* wxAuiManager::HitTest(int x
, int y
)
569 wxAuiDockUIPart
* result
= NULL
;
572 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
574 wxAuiDockUIPart
* item
= &m_uiparts
.Item(i
);
576 // we are not interested in typeDock, because this space
577 // isn't used to draw anything, just for measurements;
578 // besides, the entire dock area is covered with other
579 // rectangles, which we are interested in.
580 if (item
->type
== wxAuiDockUIPart::typeDock
)
583 // if we already have a hit on a more specific item, we are not
584 // interested in a pane hit. If, however, we don't already have
585 // a hit, returning a pane hit is necessary for some operations
586 if ((item
->type
== wxAuiDockUIPart::typePane
||
587 item
->type
== wxAuiDockUIPart::typePaneBorder
) && result
)
590 // if the point is inside the rectangle, we have a hit
591 if (item
->rect
.Contains(x
,y
))
599 // SetFlags() and GetFlags() allow the owner to set various
600 // options which are global to wxAuiManager
601 void wxAuiManager::SetFlags(unsigned int flags
)
603 // find out if we have to call UpdateHintWindowConfig()
604 bool update_hint_wnd
= false;
605 unsigned int hint_mask
= wxAUI_MGR_TRANSPARENT_HINT
|
606 wxAUI_MGR_VENETIAN_BLINDS_HINT
|
607 wxAUI_MGR_RECTANGLE_HINT
;
608 if ((flags
& hint_mask
) != (m_flags
& hint_mask
))
609 update_hint_wnd
= true;
617 UpdateHintWindowConfig();
621 unsigned int wxAuiManager::GetFlags() const
627 // don't use these anymore as they are deprecated
628 // use Set/GetManagedFrame() instead
629 void wxAuiManager::SetFrame(wxFrame
* frame
)
631 SetManagedWindow((wxWindow
*)frame
);
634 wxFrame
* wxAuiManager::GetFrame() const
636 return (wxFrame
*)m_frame
;
640 // this function will return the aui manager for a given
641 // window. The |window| parameter should be any child window
642 // or grand-child window (and so on) of the frame/window
643 // managed by wxAuiManager. The |window| parameter does not
644 // need to be managed by the manager itself.
645 wxAuiManager
* wxAuiManager::GetManager(wxWindow
* window
)
647 wxAuiManagerEvent
evt(wxEVT_AUI_FINDMANAGER
);
648 evt
.SetManager(NULL
);
649 evt
.ResumePropagation(wxEVENT_PROPAGATE_MAX
);
650 if (!window
->ProcessEvent(evt
))
653 return evt
.GetManager();
657 void wxAuiManager::UpdateHintWindowConfig()
659 // find out if the the system can do transparent frames
660 bool can_do_transparent
= false;
662 wxWindow
* w
= m_frame
;
665 if (w
->IsKindOf(CLASSINFO(wxFrame
)))
667 wxFrame
* f
= static_cast<wxFrame
*>(w
);
668 can_do_transparent
= f
->CanSetTransparent();
675 // if there is an existing hint window, delete it
678 m_hint_wnd
->Destroy();
685 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) && can_do_transparent
)
687 // Make a window to use for a transparent hint
688 #if defined(__WXMSW__) || defined(__WXGTK__)
689 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
,
690 wxDefaultPosition
, wxSize(1,1),
691 wxFRAME_TOOL_WINDOW
|
692 wxFRAME_FLOAT_ON_PARENT
|
696 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
697 #elif defined(__WXMAC__)
698 // Using a miniframe with float and tool styles keeps the parent
699 // frame activated and highlighted as such...
700 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
,
701 wxDefaultPosition
, wxSize(1,1),
702 wxFRAME_FLOAT_ON_PARENT
703 | wxFRAME_TOOL_WINDOW
);
705 // Can't set the bg colour of a Frame in wxMac
706 wxPanel
* p
= new wxPanel(m_hint_wnd
);
708 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
709 // color that is really hard to see, especially transparent.
710 // Until a better system color is decided upon we'll just use
712 p
->SetBackgroundColour(*wxBLUE
);
718 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 ||
719 (m_flags
& wxAUI_MGR_VENETIAN_BLINDS_HINT
) != 0)
721 // system can't support transparent fade, or the venetian
722 // blinds effect was explicitly requested
723 m_hint_wnd
= new wxPseudoTransparentFrame(m_frame
,
728 wxFRAME_TOOL_WINDOW
|
729 wxFRAME_FLOAT_ON_PARENT
|
732 m_hint_fademax
= 128;
738 // SetManagedWindow() is usually called once when the frame
739 // manager class is being initialized. "frame" specifies
740 // the frame which should be managed by the frame mananger
741 void wxAuiManager::SetManagedWindow(wxWindow
* wnd
)
743 wxASSERT_MSG(wnd
, wxT("specified window must be non-NULL"));
746 m_frame
->PushEventHandler(this);
749 // if the owner is going to manage an MDI parent frame,
750 // we need to add the MDI client window as the default
753 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
755 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)m_frame
;
756 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
758 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
760 AddPane(client_window
,
761 wxAuiPaneInfo().Name(wxT("mdiclient")).
762 CenterPane().PaneBorder(false));
766 UpdateHintWindowConfig();
770 // UnInit() must be called, usually in the destructor
771 // of the frame class. If it is not called, usually this
772 // will result in a crash upon program exit
773 void wxAuiManager::UnInit()
777 m_frame
->RemoveEventHandler(this);
781 // GetManagedWindow() returns the window pointer being managed
782 wxWindow
* wxAuiManager::GetManagedWindow() const
787 wxAuiDockArt
* wxAuiManager::GetArtProvider() const
792 void wxAuiManager::ProcessMgrEvent(wxAuiManagerEvent
& event
)
794 // first, give the owner frame a chance to override
797 if (m_frame
->ProcessEvent(event
))
804 // SetArtProvider() instructs wxAuiManager to use the
805 // specified art provider for all drawing calls. This allows
806 // plugable look-and-feel features. The pointer that is
807 // passed to this method subsequently belongs to wxAuiManager,
808 // and is deleted in the frame manager destructor
809 void wxAuiManager::SetArtProvider(wxAuiDockArt
* art_provider
)
811 // delete the last art provider, if any
814 // assign the new art provider
815 m_art
= art_provider
;
819 bool wxAuiManager::AddPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
)
821 // check if the pane has a valid window
825 // check if the pane already exists
826 if (GetPane(pane_info
.window
).IsOk())
829 // if the new pane is docked then we should undo maximize
830 if(pane_info
.IsDocked())
831 RestoreMaximizedPane();
833 m_panes
.Add(pane_info
);
835 wxAuiPaneInfo
& pinfo
= m_panes
.Last();
837 // set the pane window
838 pinfo
.window
= window
;
840 // if the pane's name identifier is blank, create a random string
841 if (pinfo
.name
.empty())
843 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
844 ((unsigned long)pinfo
.window
) & 0xffffffff,
845 (unsigned int)time(NULL
),
847 (unsigned int)GetTickCount(),
849 (unsigned int)clock(),
851 (unsigned long)m_panes
.GetCount());
854 // set initial proportion (if not already set)
855 if (pinfo
.dock_proportion
== 0)
856 pinfo
.dock_proportion
= 100000;
858 if (pinfo
.HasMaximizeButton())
860 wxAuiPaneButton button
;
861 button
.button_id
= wxAUI_BUTTON_MAXIMIZE_RESTORE
;
862 pinfo
.buttons
.Add(button
);
865 if (pinfo
.HasPinButton())
867 wxAuiPaneButton button
;
868 button
.button_id
= wxAUI_BUTTON_PIN
;
869 pinfo
.buttons
.Add(button
);
872 if (pinfo
.HasCloseButton())
874 wxAuiPaneButton button
;
875 button
.button_id
= wxAUI_BUTTON_CLOSE
;
876 pinfo
.buttons
.Add(button
);
879 if (pinfo
.best_size
== wxDefaultSize
&&
882 pinfo
.best_size
= pinfo
.window
->GetClientSize();
884 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
886 // GetClientSize() doesn't get the best size for
887 // a toolbar under some newer versions of wxWidgets,
888 // so use GetBestSize()
889 pinfo
.best_size
= pinfo
.window
->GetBestSize();
891 // for some reason, wxToolBar::GetBestSize() is returning
892 // a size that is a pixel shy of the correct amount.
893 // I believe this to be the correct action, until
894 // wxToolBar::GetBestSize() is fixed. Is this assumption
899 if (pinfo
.min_size
!= wxDefaultSize
)
901 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
902 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
903 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
904 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
911 bool wxAuiManager::AddPane(wxWindow
* window
,
913 const wxString
& caption
)
916 pinfo
.Caption(caption
);
919 case wxTOP
: pinfo
.Top(); break;
920 case wxBOTTOM
: pinfo
.Bottom(); break;
921 case wxLEFT
: pinfo
.Left(); break;
922 case wxRIGHT
: pinfo
.Right(); break;
923 case wxCENTER
: pinfo
.CenterPane(); break;
925 return AddPane(window
, pinfo
);
928 bool wxAuiManager::AddPane(wxWindow
* window
,
929 const wxAuiPaneInfo
& pane_info
,
930 const wxPoint
& drop_pos
)
932 if (!AddPane(window
, pane_info
))
935 wxAuiPaneInfo
& pane
= GetPane(window
);
937 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
942 bool wxAuiManager::InsertPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
,
945 // shift the panes around, depending on the insert level
946 switch (insert_level
)
948 case wxAUI_INSERT_PANE
:
949 DoInsertPane(m_panes
,
950 pane_info
.dock_direction
,
951 pane_info
.dock_layer
,
955 case wxAUI_INSERT_ROW
:
956 DoInsertDockRow(m_panes
,
957 pane_info
.dock_direction
,
958 pane_info
.dock_layer
,
961 case wxAUI_INSERT_DOCK
:
962 DoInsertDockLayer(m_panes
,
963 pane_info
.dock_direction
,
964 pane_info
.dock_layer
);
968 // if the window already exists, we are basically just moving/inserting the
969 // existing window. If it doesn't exist, we need to add it and insert it
970 wxAuiPaneInfo
& existing_pane
= GetPane(window
);
971 if (!existing_pane
.IsOk())
973 return AddPane(window
, pane_info
);
977 if (pane_info
.IsFloating())
979 existing_pane
.Float();
980 if (pane_info
.floating_pos
!= wxDefaultPosition
)
981 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
982 if (pane_info
.floating_size
!= wxDefaultSize
)
983 existing_pane
.FloatingSize(pane_info
.floating_size
);
987 // if the new pane is docked then we should undo maximize
988 RestoreMaximizedPane();
990 existing_pane
.Direction(pane_info
.dock_direction
);
991 existing_pane
.Layer(pane_info
.dock_layer
);
992 existing_pane
.Row(pane_info
.dock_row
);
993 existing_pane
.Position(pane_info
.dock_pos
);
1001 // DetachPane() removes a pane from the frame manager. This
1002 // method will not destroy the window that is removed.
1003 bool wxAuiManager::DetachPane(wxWindow
* window
)
1006 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
1008 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1009 if (p
.window
== window
)
1013 // we have a floating frame which is being detached. We need to
1014 // reparent it to m_frame and destroy the floating frame
1017 p
.window
->SetSize(1,1);
1019 if (p
.frame
->IsShown())
1020 p
.frame
->Show(false);
1022 // reparent to m_frame and destroy the pane
1023 if(m_action_window
== p
.frame
)
1025 m_action_window
= NULL
;
1028 p
.window
->Reparent(m_frame
);
1029 p
.frame
->SetSizer(NULL
);
1034 // make sure there are no references to this pane in our uiparts,
1035 // just in case the caller doesn't call Update() immediately after
1036 // the DetachPane() call. This prevets obscure crashes which would
1037 // happen at window repaint if the caller forgets to call Update()
1039 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
1041 wxAuiDockUIPart
& part
= m_uiparts
.Item(pi
);
1042 if (part
.pane
== &p
)
1044 m_uiparts
.RemoveAt(pi
);
1051 m_panes
.RemoveAt(i
);
1058 // ClosePane() destroys or hides the pane depending on its
1060 void wxAuiManager::ClosePane(wxAuiPaneInfo
& pane_info
)
1062 // if we were maximized, restore
1063 if (pane_info
.IsMaximized())
1065 RestorePane(pane_info
);
1068 // first, hide the window
1069 if (pane_info
.window
&& pane_info
.window
->IsShown())
1071 pane_info
.window
->Show(false);
1074 // make sure that we are the parent of this window
1075 if (pane_info
.window
&& pane_info
.window
->GetParent() != m_frame
)
1077 pane_info
.window
->Reparent(m_frame
);
1080 // if we have a frame, destroy it
1081 if (pane_info
.frame
)
1083 pane_info
.frame
->Destroy();
1084 pane_info
.frame
= NULL
;
1087 // now we need to either destroy or hide the pane
1088 if (pane_info
.IsDestroyOnClose())
1090 wxWindow
* window
= pane_info
.window
;
1103 void wxAuiManager::MaximizePane(wxAuiPaneInfo
& pane_info
)
1107 // un-maximize and hide all other panes
1108 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1110 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1119 // mark ourselves maximized
1120 pane_info
.Maximize();
1122 m_has_maximized
= true;
1124 // last, show the window
1125 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1127 pane_info
.window
->Show(true);
1131 void wxAuiManager::RestorePane(wxAuiPaneInfo
& pane_info
)
1135 // restore all the panes
1136 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1138 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1145 // mark ourselves non-maximized
1146 pane_info
.Restore();
1147 m_has_maximized
= false;
1149 // last, show the window
1150 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1152 pane_info
.window
->Show(true);
1156 void wxAuiManager::RestoreMaximizedPane()
1160 // restore all the panes
1161 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1163 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1172 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
1173 // in the input string. This is an internal functions which is
1174 // used for saving perspectives
1175 static wxString
EscapeDelimiters(const wxString
& s
)
1178 result
.Alloc(s
.length());
1179 const wxChar
* ch
= s
.c_str();
1182 if (*ch
== wxT(';') || *ch
== wxT('|'))
1183 result
+= wxT('\\');
1190 wxString
wxAuiManager::SavePaneInfo(wxAuiPaneInfo
& pane
)
1192 wxString result
= wxT("name=");
1193 result
+= EscapeDelimiters(pane
.name
);
1196 result
+= wxT("caption=");
1197 result
+= EscapeDelimiters(pane
.caption
);
1200 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
1201 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
1202 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
1203 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
1204 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
1205 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
1206 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
1207 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
1208 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
1209 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
1210 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
1211 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
1212 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
1213 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
1214 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
1215 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
1220 // Load a "pane" with the pane infor settings in pane_part
1221 void wxAuiManager::LoadPaneInfo(wxString pane_part
, wxAuiPaneInfo
&pane
)
1223 // replace escaped characters so we can
1224 // split up the string easily
1225 pane_part
.Replace(wxT("\\|"), wxT("\a"));
1226 pane_part
.Replace(wxT("\\;"), wxT("\b"));
1230 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
1231 pane_part
= pane_part
.AfterFirst(wxT(';'));
1232 wxString val_name
= val_part
.BeforeFirst(wxT('='));
1233 wxString value
= val_part
.AfterFirst(wxT('='));
1234 val_name
.MakeLower();
1235 val_name
.Trim(true);
1236 val_name
.Trim(false);
1240 if (val_name
.empty())
1243 if (val_name
== wxT("name"))
1245 else if (val_name
== wxT("caption"))
1246 pane
.caption
= value
;
1247 else if (val_name
== wxT("state"))
1248 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1249 else if (val_name
== wxT("dir"))
1250 pane
.dock_direction
= wxAtoi(value
.c_str());
1251 else if (val_name
== wxT("layer"))
1252 pane
.dock_layer
= wxAtoi(value
.c_str());
1253 else if (val_name
== wxT("row"))
1254 pane
.dock_row
= wxAtoi(value
.c_str());
1255 else if (val_name
== wxT("pos"))
1256 pane
.dock_pos
= wxAtoi(value
.c_str());
1257 else if (val_name
== wxT("prop"))
1258 pane
.dock_proportion
= wxAtoi(value
.c_str());
1259 else if (val_name
== wxT("bestw"))
1260 pane
.best_size
.x
= wxAtoi(value
.c_str());
1261 else if (val_name
== wxT("besth"))
1262 pane
.best_size
.y
= wxAtoi(value
.c_str());
1263 else if (val_name
== wxT("minw"))
1264 pane
.min_size
.x
= wxAtoi(value
.c_str());
1265 else if (val_name
== wxT("minh"))
1266 pane
.min_size
.y
= wxAtoi(value
.c_str());
1267 else if (val_name
== wxT("maxw"))
1268 pane
.max_size
.x
= wxAtoi(value
.c_str());
1269 else if (val_name
== wxT("maxh"))
1270 pane
.max_size
.y
= wxAtoi(value
.c_str());
1271 else if (val_name
== wxT("floatx"))
1272 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1273 else if (val_name
== wxT("floaty"))
1274 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1275 else if (val_name
== wxT("floatw"))
1276 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1277 else if (val_name
== wxT("floath"))
1278 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1280 wxFAIL_MSG(wxT("Bad Perspective String"));
1284 // replace escaped characters so we can
1285 // split up the string easily
1286 pane
.name
.Replace(wxT("\a"), wxT("|"));
1287 pane
.name
.Replace(wxT("\b"), wxT(";"));
1288 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1289 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1290 pane_part
.Replace(wxT("\a"), wxT("|"));
1291 pane_part
.Replace(wxT("\b"), wxT(";"));
1297 // SavePerspective() saves all pane information as a single string.
1298 // This string may later be fed into LoadPerspective() to restore
1299 // all pane settings. This save and load mechanism allows an
1300 // exact pane configuration to be saved and restored at a later time
1302 wxString
wxAuiManager::SavePerspective()
1306 result
= wxT("layout1|");
1308 int pane_i
, pane_count
= m_panes
.GetCount();
1309 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1311 wxAuiPaneInfo
& pane
= m_panes
.Item(pane_i
);
1312 result
+= SavePaneInfo(pane
)+wxT("|");
1315 int dock_i
, dock_count
= m_docks
.GetCount();
1316 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1318 wxAuiDockInfo
& dock
= m_docks
.Item(dock_i
);
1320 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1321 dock
.dock_direction
, dock
.dock_layer
,
1322 dock
.dock_row
, dock
.size
);
1328 // LoadPerspective() loads a layout which was saved with SavePerspective()
1329 // If the "update" flag parameter is true, the GUI will immediately be updated
1331 bool wxAuiManager::LoadPerspective(const wxString
& layout
, bool update
)
1333 wxString input
= layout
;
1336 // check layout string version
1337 part
= input
.BeforeFirst(wxT('|'));
1338 input
= input
.AfterFirst(wxT('|'));
1341 if (part
!= wxT("layout1"))
1344 // mark all panes currently managed as docked and hidden
1345 int pane_i
, pane_count
= m_panes
.GetCount();
1346 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1347 m_panes
.Item(pane_i
).Dock().Hide();
1349 // clear out the dock array; this will be reconstructed
1352 // replace escaped characters so we can
1353 // split up the string easily
1354 input
.Replace(wxT("\\|"), wxT("\a"));
1355 input
.Replace(wxT("\\;"), wxT("\b"));
1361 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1362 input
= input
.AfterFirst(wxT('|'));
1363 pane_part
.Trim(true);
1365 // if the string is empty, we're done parsing
1366 if (pane_part
.empty())
1369 if (pane_part
.Left(9) == wxT("dock_size"))
1371 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1372 wxString value
= pane_part
.AfterFirst(wxT('='));
1374 long dir
, layer
, row
, size
;
1375 wxString piece
= val_name
.AfterFirst(wxT('('));
1376 piece
= piece
.BeforeLast(wxT(')'));
1377 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1378 piece
= piece
.AfterFirst(wxT(','));
1379 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1380 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1381 value
.ToLong(&size
);
1384 dock
.dock_direction
= dir
;
1385 dock
.dock_layer
= layer
;
1386 dock
.dock_row
= row
;
1392 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1393 // name so it can be called by external callers
1394 pane_part
.Replace(wxT("\a"), wxT("|"));
1395 pane_part
.Replace(wxT("\b"), wxT(";"));
1397 LoadPaneInfo(pane_part
, pane
);
1399 wxAuiPaneInfo
& p
= GetPane(pane
.name
);
1402 // the pane window couldn't be found
1403 // in the existing layout
1417 void wxAuiManager::GetPanePositionsAndSizes(wxAuiDockInfo
& dock
,
1418 wxArrayInt
& positions
,
1421 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1422 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1423 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1428 int offset
, action_pane
= -1;
1429 int pane_i
, pane_count
= dock
.panes
.GetCount();
1431 // find the pane marked as our action pane
1432 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1434 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1436 if (pane
.state
& wxAuiPaneInfo::actionPane
)
1438 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1439 action_pane
= pane_i
;
1443 // set up each panes default position, and
1444 // determine the size (width or height, depending
1445 // on the dock's orientation) of each pane
1446 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1448 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1449 positions
.Add(pane
.dock_pos
);
1452 if (pane
.HasBorder())
1453 size
+= (pane_border_size
*2);
1455 if (dock
.IsHorizontal())
1457 if (pane
.HasGripper() && !pane
.HasGripperTop())
1458 size
+= gripper_size
;
1459 size
+= pane
.best_size
.x
;
1463 if (pane
.HasGripper() && pane
.HasGripperTop())
1464 size
+= gripper_size
;
1466 if (pane
.HasCaption())
1467 size
+= caption_size
;
1468 size
+= pane
.best_size
.y
;
1474 // if there is no action pane, just return the default
1475 // positions (as specified in pane.pane_pos)
1476 if (action_pane
== -1)
1480 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1482 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1487 positions
[pane_i
] -= -amount
;
1489 offset
+= sizes
[pane_i
];
1492 // if the dock mode is fixed, make sure none of the panes
1493 // overlap; we will bump panes that overlap
1495 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1497 int amount
= positions
[pane_i
] - offset
;
1501 positions
[pane_i
] += -amount
;
1503 offset
+= sizes
[pane_i
];
1508 void wxAuiManager::LayoutAddPane(wxSizer
* cont
,
1509 wxAuiDockInfo
& dock
,
1510 wxAuiPaneInfo
& pane
,
1511 wxAuiDockUIPartArray
& uiparts
,
1514 wxAuiDockUIPart part
;
1515 wxSizerItem
* sizer_item
;
1517 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1518 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1519 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1520 int pane_button_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BUTTON_SIZE
);
1522 // find out the orientation of the item (orientation for panes
1523 // is the same as the dock's orientation)
1525 if (dock
.IsHorizontal())
1526 orientation
= wxHORIZONTAL
;
1528 orientation
= wxVERTICAL
;
1530 // this variable will store the proportion
1531 // value that the pane will receive
1532 int pane_proportion
= pane
.dock_proportion
;
1534 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1535 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1537 if (pane
.HasGripper())
1539 if (pane
.HasGripperTop())
1540 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1542 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1544 part
.type
= wxAuiDockUIPart::typeGripper
;
1548 part
.orientation
= orientation
;
1549 part
.cont_sizer
= horz_pane_sizer
;
1550 part
.sizer_item
= sizer_item
;
1554 if (pane
.HasCaption())
1556 // create the caption sizer
1557 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1559 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1561 part
.type
= wxAuiDockUIPart::typeCaption
;
1565 part
.orientation
= orientation
;
1566 part
.cont_sizer
= vert_pane_sizer
;
1567 part
.sizer_item
= sizer_item
;
1568 int caption_part_idx
= uiparts
.GetCount();
1571 // add pane buttons to the caption
1572 int i
, button_count
;
1573 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1574 i
< button_count
; ++i
)
1576 wxAuiPaneButton
& button
= pane
.buttons
.Item(i
);
1578 sizer_item
= caption_sizer
->Add(pane_button_size
,
1582 part
.type
= wxAuiDockUIPart::typePaneButton
;
1585 part
.button
= &button
;
1586 part
.orientation
= orientation
;
1587 part
.cont_sizer
= caption_sizer
;
1588 part
.sizer_item
= sizer_item
;
1592 // if we have buttons, add a little space to the right
1593 // of them to ease visual crowding
1594 if (button_count
>= 1)
1596 caption_sizer
->Add(3,1);
1599 // add the caption sizer
1600 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1602 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1605 // add the pane window itself
1608 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1612 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1613 // Don't do this because it breaks the pane size in floating windows
1614 // BIW: Right now commenting this out is causing problems with
1615 // an mdi client window as the center pane.
1616 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1619 part
.type
= wxAuiDockUIPart::typePane
;
1623 part
.orientation
= orientation
;
1624 part
.cont_sizer
= vert_pane_sizer
;
1625 part
.sizer_item
= sizer_item
;
1629 // determine if the pane should have a minimum size; if the pane is
1630 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1631 // if the pane.min_size is set, we must use that value as well
1633 wxSize min_size
= pane
.min_size
;
1636 if (min_size
== wxDefaultSize
)
1638 min_size
= pane
.best_size
;
1639 pane_proportion
= 0;
1643 if (min_size
!= wxDefaultSize
)
1645 vert_pane_sizer
->SetItemMinSize(
1646 vert_pane_sizer
->GetChildren().GetCount()-1,
1647 min_size
.x
, min_size
.y
);
1651 // add the verticle sizer (caption, pane window) to the
1652 // horizontal sizer (gripper, verticle sizer)
1653 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1655 // finally, add the pane sizer to the dock sizer
1657 if (pane
.HasBorder())
1659 // allowing space for the pane's border
1660 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1661 wxEXPAND
| wxALL
, pane_border_size
);
1663 part
.type
= wxAuiDockUIPart::typePaneBorder
;
1667 part
.orientation
= orientation
;
1668 part
.cont_sizer
= cont
;
1669 part
.sizer_item
= sizer_item
;
1674 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1678 void wxAuiManager::LayoutAddDock(wxSizer
* cont
,
1679 wxAuiDockInfo
& dock
,
1680 wxAuiDockUIPartArray
& uiparts
,
1683 wxSizerItem
* sizer_item
;
1684 wxAuiDockUIPart part
;
1686 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
1687 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1689 // resizable bottom and right docks have a sash before them
1690 if (!m_has_maximized
&& !dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1691 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1693 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1695 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1696 part
.orientation
= orientation
;
1700 part
.cont_sizer
= cont
;
1701 part
.sizer_item
= sizer_item
;
1705 // create the sizer for the dock
1706 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1708 // add each pane to the dock
1709 bool has_maximized_pane
= false;
1710 int pane_i
, pane_count
= dock
.panes
.GetCount();
1714 wxArrayInt pane_positions
, pane_sizes
;
1716 // figure out the real pane positions we will
1717 // use, without modifying the each pane's pane_pos member
1718 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1721 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1723 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1724 int pane_pos
= pane_positions
.Item(pane_i
);
1725 if(pane
.IsMaximized()) {
1726 has_maximized_pane
= true;
1729 int amount
= pane_pos
- offset
;
1732 if (dock
.IsVertical())
1733 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1735 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1737 part
.type
= wxAuiDockUIPart::typeBackground
;
1741 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1742 part
.cont_sizer
= dock_sizer
;
1743 part
.sizer_item
= sizer_item
;
1749 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1751 offset
+= pane_sizes
.Item(pane_i
);
1754 // at the end add a very small stretchable background area
1755 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1757 part
.type
= wxAuiDockUIPart::typeBackground
;
1761 part
.orientation
= orientation
;
1762 part
.cont_sizer
= dock_sizer
;
1763 part
.sizer_item
= sizer_item
;
1768 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1770 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1771 if(pane
.IsMaximized()) {
1772 has_maximized_pane
= true;
1775 // if this is not the first pane being added,
1776 // we need to add a pane sizer
1777 if (!m_has_maximized
&& pane_i
> 0)
1779 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1781 part
.type
= wxAuiDockUIPart::typePaneSizer
;
1783 part
.pane
= dock
.panes
.Item(pane_i
-1);
1785 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1786 part
.cont_sizer
= dock_sizer
;
1787 part
.sizer_item
= sizer_item
;
1791 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1795 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
|| has_maximized_pane
)
1796 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1798 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1800 part
.type
= wxAuiDockUIPart::typeDock
;
1804 part
.orientation
= orientation
;
1805 part
.cont_sizer
= cont
;
1806 part
.sizer_item
= sizer_item
;
1809 if (dock
.IsHorizontal())
1810 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1812 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1814 // top and left docks have a sash after them
1815 if (!m_has_maximized
&& !dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1816 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1818 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1820 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1824 part
.orientation
= orientation
;
1825 part
.cont_sizer
= cont
;
1826 part
.sizer_item
= sizer_item
;
1831 wxSizer
* wxAuiManager::LayoutAll(wxAuiPaneInfoArray
& panes
,
1832 wxAuiDockInfoArray
& docks
,
1833 wxAuiDockUIPartArray
& uiparts
,
1836 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1838 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1839 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1840 wxSize cli_size
= m_frame
->GetClientSize();
1841 int i
, dock_count
, pane_count
;
1844 // empty all docks out
1845 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1846 docks
.Item(i
).panes
.Empty();
1849 // iterate through all known panes, filing each
1850 // of them into the appropriate dock. If the
1851 // pane does not exist in the dock, add it
1852 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1854 wxAuiPaneInfo
& p
= panes
.Item(i
);
1856 // find any docks in this layer
1857 wxAuiDockInfo
* dock
;
1858 wxAuiDockInfoPtrArray arr
;
1859 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1861 if (arr
.GetCount() > 0)
1867 // dock was not found, so we need to create a new one
1869 d
.dock_direction
= p
.dock_direction
;
1870 d
.dock_layer
= p
.dock_layer
;
1871 d
.dock_row
= p
.dock_row
;
1873 dock
= &docks
.Last();
1877 if (p
.IsDocked() && p
.IsShown())
1879 // remove the pane from any existing docks except this one
1880 RemovePaneFromDocks(docks
, p
, dock
);
1882 // pane needs to be added to the dock,
1883 // if it doesn't already exist
1884 if (!FindPaneInDock(*dock
, p
.window
))
1885 dock
->panes
.Add(&p
);
1889 // remove the pane from any existing docks
1890 RemovePaneFromDocks(docks
, p
);
1895 // remove any empty docks
1896 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1898 if (docks
.Item(i
).panes
.GetCount() == 0)
1902 // configure the docks further
1903 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1905 wxAuiDockInfo
& dock
= docks
.Item(i
);
1906 int j
, dock_pane_count
= dock
.panes
.GetCount();
1908 // sort the dock pane array by the pane's
1909 // dock position (dock_pos), in ascending order
1910 dock
.panes
.Sort(PaneSortFunc
);
1912 // for newly created docks, set up their initial size
1917 for (j
= 0; j
< dock_pane_count
; ++j
)
1919 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
1920 wxSize pane_size
= pane
.best_size
;
1921 if (pane_size
== wxDefaultSize
)
1922 pane_size
= pane
.min_size
;
1923 if (pane_size
== wxDefaultSize
)
1924 pane_size
= pane
.window
->GetSize();
1926 if (dock
.IsHorizontal())
1927 size
= wxMax(pane_size
.y
, size
);
1929 size
= wxMax(pane_size
.x
, size
);
1932 // add space for the border (two times), but only
1933 // if at least one pane inside the dock has a pane border
1934 for (j
= 0; j
< dock_pane_count
; ++j
)
1936 if (dock
.panes
.Item(j
)->HasBorder())
1938 size
+= (pane_border_size
*2);
1943 // if pane is on the top or bottom, add the caption height,
1944 // but only if at least one pane inside the dock has a caption
1945 if (dock
.IsHorizontal())
1947 for (j
= 0; j
< dock_pane_count
; ++j
)
1949 if (dock
.panes
.Item(j
)->HasCaption())
1951 size
+= caption_size
;
1957 if (!(m_flags
& wxAUI_MGR_NO_DOCK_SIZE_LIMIT
))
1959 // new dock's size may not be more than 1/3 of the frame size
1960 if (dock
.IsHorizontal())
1961 size
= wxMin(size
, cli_size
.y
/3);
1963 size
= wxMin(size
, cli_size
.x
/3);
1972 // determine the dock's minimum size
1973 bool plus_border
= false;
1974 bool plus_caption
= false;
1975 int dock_min_size
= 0;
1976 for (j
= 0; j
< dock_pane_count
; ++j
)
1978 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
1979 if (pane
.min_size
!= wxDefaultSize
)
1981 if (pane
.HasBorder())
1983 if (pane
.HasCaption())
1984 plus_caption
= true;
1985 if (dock
.IsHorizontal())
1987 if (pane
.min_size
.y
> dock_min_size
)
1988 dock_min_size
= pane
.min_size
.y
;
1992 if (pane
.min_size
.x
> dock_min_size
)
1993 dock_min_size
= pane
.min_size
.x
;
1999 dock_min_size
+= (pane_border_size
*2);
2000 if (plus_caption
&& dock
.IsHorizontal())
2001 dock_min_size
+= (caption_size
);
2003 dock
.min_size
= dock_min_size
;
2006 // if the pane's current size is less than it's
2007 // minimum, increase the dock's size to it's minimum
2008 if (dock
.size
< dock
.min_size
)
2009 dock
.size
= dock
.min_size
;
2012 // determine the dock's mode (fixed or proportional);
2013 // determine whether the dock has only toolbars
2014 bool action_pane_marked
= false;
2016 dock
.toolbar
= true;
2017 for (j
= 0; j
< dock_pane_count
; ++j
)
2019 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2020 if (!pane
.IsFixed())
2022 if (!pane
.IsToolbar())
2023 dock
.toolbar
= false;
2024 if (pane
.state
& wxAuiPaneInfo::actionPane
)
2025 action_pane_marked
= true;
2029 // if the dock mode is proportional and not fixed-pixel,
2030 // reassign the dock_pos to the sequential 0, 1, 2, 3;
2031 // e.g. remove gaps like 1, 2, 30, 500
2034 for (j
= 0; j
< dock_pane_count
; ++j
)
2036 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2041 // if the dock mode is fixed, and none of the panes
2042 // are being moved right now, make sure the panes
2043 // do not overlap each other. If they do, we will
2044 // adjust the panes' positions
2045 if (dock
.fixed
&& !action_pane_marked
)
2047 wxArrayInt pane_positions
, pane_sizes
;
2048 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
2051 for (j
= 0; j
< dock_pane_count
; ++j
)
2053 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(j
));
2054 pane
.dock_pos
= pane_positions
[j
];
2056 int amount
= pane
.dock_pos
- offset
;
2060 pane
.dock_pos
+= -amount
;
2062 offset
+= pane_sizes
[j
];
2067 // discover the maximum dock layer
2069 for (i
= 0; i
< dock_count
; ++i
)
2070 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
2073 // clear out uiparts
2076 // create a bunch of box sizers,
2077 // from the innermost level outwards.
2078 wxSizer
* cont
= NULL
;
2079 wxSizer
* middle
= NULL
;
2083 for (layer
= 0; layer
<= max_layer
; ++layer
)
2085 wxAuiDockInfoPtrArray arr
;
2087 // find any docks in this layer
2088 FindDocks(docks
, -1, layer
, -1, arr
);
2090 // if there aren't any, skip to the next layer
2094 wxSizer
* old_cont
= cont
;
2096 // create a container which will hold this layer's
2097 // docks (top, bottom, left, right)
2098 cont
= new wxBoxSizer(wxVERTICAL
);
2101 // find any top docks in this layer
2102 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
2103 RenumberDockRows(arr
);
2106 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2107 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2111 // fill out the middle layer (which consists
2112 // of left docks, content area and right docks)
2114 middle
= new wxBoxSizer(wxHORIZONTAL
);
2116 // find any left docks in this layer
2117 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
2118 RenumberDockRows(arr
);
2121 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2122 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2125 // add content dock (or previous layer's sizer
2129 // find any center docks
2130 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
2133 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
2134 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2136 else if (!m_has_maximized
)
2138 // there are no center docks, add a background area
2139 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
2140 wxAuiDockUIPart part
;
2141 part
.type
= wxAuiDockUIPart::typeBackground
;
2145 part
.cont_sizer
= middle
;
2146 part
.sizer_item
= sizer_item
;
2152 middle
->Add(old_cont
, 1, wxEXPAND
);
2155 // find any right docks in this layer
2156 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
2157 RenumberDockRows(arr
);
2160 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2161 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2164 cont
->Add(middle
, 1, wxEXPAND
);
2168 // find any bottom docks in this layer
2169 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
2170 RenumberDockRows(arr
);
2173 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2174 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2181 // no sizer available, because there are no docks,
2182 // therefore we will create a simple background area
2183 cont
= new wxBoxSizer(wxVERTICAL
);
2184 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
2185 wxAuiDockUIPart part
;
2186 part
.type
= wxAuiDockUIPart::typeBackground
;
2190 part
.cont_sizer
= middle
;
2191 part
.sizer_item
= sizer_item
;
2195 container
->Add(cont
, 1, wxEXPAND
);
2200 // Update() updates the layout. Whenever changes are made to
2201 // one or more panes, this function should be called. It is the
2202 // external entry point for running the layout engine.
2204 void wxAuiManager::Update()
2207 int i
, pane_count
= m_panes
.GetCount();
2210 // destroy floating panes which have been
2211 // redocked or are becoming non-floating
2212 for (i
= 0; i
< pane_count
; ++i
)
2214 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2216 if (!p
.IsFloating() && p
.frame
)
2218 // because the pane is no longer in a floating, we need to
2219 // reparent it to m_frame and destroy the floating frame
2222 p
.window
->SetSize(1,1);
2225 // the following block is a workaround for bug #1531361
2226 // (see wxWidgets sourceforge page). On wxGTK (only), when
2227 // a frame is shown/hidden, a move event unfortunately
2228 // also gets fired. Because we may be dragging around
2229 // a pane, we need to cancel that action here to prevent
2230 // a spurious crash.
2231 if (m_action_window
== p
.frame
)
2233 if (wxWindow::GetCapture() == m_frame
)
2234 m_frame
->ReleaseMouse();
2235 m_action
= actionNone
;
2236 m_action_window
= NULL
;
2240 if (p
.frame
->IsShown())
2241 p
.frame
->Show(false);
2243 // reparent to m_frame and destroy the pane
2244 if(m_action_window
== p
.frame
)
2246 m_action_window
= NULL
;
2249 p
.window
->Reparent(m_frame
);
2250 p
.frame
->SetSizer(NULL
);
2257 // delete old sizer first
2258 m_frame
->SetSizer(NULL
);
2260 // create a layout for all of the panes
2261 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
2263 // hide or show panes as necessary,
2264 // and float panes as necessary
2265 for (i
= 0; i
< pane_count
; ++i
)
2267 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2271 if (p
.frame
== NULL
)
2273 // we need to create a frame for this
2274 // pane, which has recently been floated
2275 wxAuiFloatingFrame
* frame
= CreateFloatingFrame(m_frame
, p
);
2277 // on MSW and Mac, if the owner desires transparent dragging, and
2278 // the dragging is happening right now, then the floating
2279 // window should have this style by default
2280 if (m_action
== actionDragFloatingPane
&&
2281 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2282 frame
->SetTransparent(150);
2284 frame
->SetPaneWindow(p
);
2287 if (p
.IsShown() && !frame
->IsShown())
2292 // frame already exists, make sure it's position
2293 // and size reflect the information in wxAuiPaneInfo
2294 if (p
.frame
->GetPosition() != p
.floating_pos
)
2296 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2297 wxDefaultCoord
, wxDefaultCoord
,
2298 wxSIZE_USE_EXISTING
);
2299 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2302 if (p
.frame
->IsShown() != p
.IsShown())
2303 p
.frame
->Show(p
.IsShown());
2308 if (p
.window
->IsShown() != p
.IsShown())
2309 p
.window
->Show(p
.IsShown());
2312 // if "active panes" are no longer allowed, clear
2313 // any optionActive values from the pane states
2314 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2316 p
.state
&= ~wxAuiPaneInfo::optionActive
;
2321 // keep track of the old window rectangles so we can
2322 // refresh those windows whose rect has changed
2323 wxAuiRectArray old_pane_rects
;
2324 for (i
= 0; i
< pane_count
; ++i
)
2327 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2329 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2332 old_pane_rects
.Add(r
);
2338 // apply the new sizer
2339 m_frame
->SetSizer(sizer
);
2340 m_frame
->SetAutoLayout(false);
2345 // now that the frame layout is done, we need to check
2346 // the new pane rectangles against the old rectangles that
2347 // we saved a few lines above here. If the rectangles have
2348 // changed, the corresponding panes must also be updated
2349 for (i
= 0; i
< pane_count
; ++i
)
2351 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2352 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2354 if (p
.rect
!= old_pane_rects
[i
])
2356 p
.window
->Refresh();
2365 // set frame's minimum size
2368 // N.B. More work needs to be done on frame minimum sizes;
2369 // this is some intresting code that imposes the minimum size,
2370 // but we may want to include a more flexible mechanism or
2371 // options for multiple minimum-size modes, e.g. strict or lax
2372 wxSize min_size = sizer->GetMinSize();
2373 wxSize frame_size = m_frame->GetSize();
2374 wxSize client_size = m_frame->GetClientSize();
2376 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2377 min_size.y+frame_size.y-client_size.y );
2379 m_frame->SetMinSize(minframe_size);
2381 if (frame_size.x < minframe_size.x ||
2382 frame_size.y < minframe_size.y)
2383 sizer->Fit(m_frame);
2388 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2389 // on the frame's main sizer, then measures all the various UI items
2390 // and updates their internal rectangles. This should always be called
2391 // instead of calling m_frame->Layout() directly
2393 void wxAuiManager::DoFrameLayout()
2398 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2400 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2402 // get the rectangle of the UI part
2403 // originally, this code looked like this:
2404 // part.rect = wxRect(part.sizer_item->GetPosition(),
2405 // part.sizer_item->GetSize());
2406 // this worked quite well, with one exception: the mdi
2407 // client window had a "deferred" size variable
2408 // that returned the wrong size. It looks like
2409 // a bug in wx, because the former size of the window
2410 // was being returned. So, we will retrieve the part's
2411 // rectangle via other means
2414 part
.rect
= part
.sizer_item
->GetRect();
2415 int flag
= part
.sizer_item
->GetFlag();
2416 int border
= part
.sizer_item
->GetBorder();
2419 part
.rect
.y
-= border
;
2420 part
.rect
.height
+= border
;
2424 part
.rect
.x
-= border
;
2425 part
.rect
.width
+= border
;
2427 if (flag
& wxBOTTOM
)
2428 part
.rect
.height
+= border
;
2430 part
.rect
.width
+= border
;
2433 if (part
.type
== wxAuiDockUIPart::typeDock
)
2434 part
.dock
->rect
= part
.rect
;
2435 if (part
.type
== wxAuiDockUIPart::typePane
)
2436 part
.pane
->rect
= part
.rect
;
2440 // GetPanePart() looks up the pane the pane border UI part (or the regular
2441 // pane part if there is no border). This allows the caller to get the exact
2442 // rectangle of the pane in question, including decorations like
2443 // caption and border (if any).
2445 wxAuiDockUIPart
* wxAuiManager::GetPanePart(wxWindow
* wnd
)
2448 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2450 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2451 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
2452 part
.pane
&& part
.pane
->window
== wnd
)
2455 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2457 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2458 if (part
.type
== wxAuiDockUIPart::typePane
&&
2459 part
.pane
&& part
.pane
->window
== wnd
)
2467 // GetDockPixelOffset() is an internal function which returns
2468 // a dock's offset in pixels from the left side of the window
2469 // (for horizontal docks) or from the top of the window (for
2470 // vertical docks). This value is necessary for calculating
2471 // fixel-pane/toolbar offsets when they are dragged.
2473 int wxAuiManager::GetDockPixelOffset(wxAuiPaneInfo
& test
)
2475 // the only way to accurately calculate the dock's
2476 // offset is to actually run a theoretical layout
2478 int i
, part_count
, dock_count
;
2479 wxAuiDockInfoArray docks
;
2480 wxAuiPaneInfoArray panes
;
2481 wxAuiDockUIPartArray uiparts
;
2482 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2485 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2486 wxSize client_size
= m_frame
->GetClientSize();
2487 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2490 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2492 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
2493 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2494 part
.sizer_item
->GetSize());
2495 if (part
.type
== wxAuiDockUIPart::typeDock
)
2496 part
.dock
->rect
= part
.rect
;
2501 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2503 wxAuiDockInfo
& dock
= docks
.Item(i
);
2504 if (test
.dock_direction
== dock
.dock_direction
&&
2505 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2507 if (dock
.IsVertical())
2519 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2520 // if a dock operation is allowed, the new dock position is copied into
2521 // the target info. If the operation was allowed, the function returns true.
2523 bool wxAuiManager::ProcessDockResult(wxAuiPaneInfo
& target
,
2524 const wxAuiPaneInfo
& new_pos
)
2526 bool allowed
= false;
2527 switch (new_pos
.dock_direction
)
2529 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2530 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2531 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2532 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2542 // DoDrop() is an important function. It basically takes a mouse position,
2543 // and determines where the pane's new position would be. If the pane is to be
2544 // dropped, it performs the drop operation using the specified dock and pane
2545 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2546 // scenario can be performed, giving precise coordinates for drop hints.
2547 // If, however, wxAuiManager:m_docks and wxAuiManager::m_panes are specified
2548 // as parameters, the changes will be made to the main state arrays
2550 const int auiInsertRowPixels
= 10;
2551 const int auiNewRowPixels
= 40;
2552 const int auiLayerInsertPixels
= 40;
2553 const int auiLayerInsertOffset
= 5;
2555 bool wxAuiManager::DoDrop(wxAuiDockInfoArray
& docks
,
2556 wxAuiPaneInfoArray
& panes
,
2557 wxAuiPaneInfo
& target
,
2559 const wxPoint
& offset
)
2561 wxSize cli_size
= m_frame
->GetClientSize();
2563 wxAuiPaneInfo drop
= target
;
2566 // The result should always be shown
2570 // Check to see if the pane has been dragged outside of the window
2571 // (or near to the outside of the window), if so, dock it along the edge
2574 int layer_insert_offset
= auiLayerInsertOffset
;
2575 if (target
.IsToolbar())
2576 layer_insert_offset
= 0;
2578 if (pt
.x
< layer_insert_offset
&&
2579 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2581 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2582 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2583 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2587 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2588 return ProcessDockResult(target
, drop
);
2590 else if (pt
.y
< layer_insert_offset
&&
2591 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2593 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2594 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2595 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2599 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2600 return ProcessDockResult(target
, drop
);
2602 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2603 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2605 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2606 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2607 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2609 drop
.Dock().Right().
2612 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2613 return ProcessDockResult(target
, drop
);
2615 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2616 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2618 int new_layer
= wxMax( wxMax( GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2619 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2620 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2622 drop
.Dock().Bottom().
2625 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2626 return ProcessDockResult(target
, drop
);
2629 wxAuiDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2632 if (drop
.IsToolbar())
2634 if (!part
|| !part
->dock
)
2637 // calculate the offset from where the dock begins
2638 // to the point where the user dropped the pane
2639 int dock_drop_offset
= 0;
2640 if (part
->dock
->IsHorizontal())
2641 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2643 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2646 // toolbars may only be moved in and to fixed-pane docks,
2647 // otherwise we will try to float the pane. Also, the pane
2648 // should float if being dragged over center pane windows
2649 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2651 if (m_last_rect
.IsEmpty() || m_last_rect
.Contains(pt
.x
, pt
.y
))
2657 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2658 (drop
.IsFloatable() ||
2659 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2660 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2667 return ProcessDockResult(target
, drop
);
2670 drop
.Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2672 return ProcessDockResult(target
, drop
);
2681 m_last_rect
= part
->dock
->rect
;
2682 m_last_rect
.Inflate( 15, 15 );
2686 Direction(part
->dock
->dock_direction
).
2687 Layer(part
->dock
->dock_layer
).
2688 Row(part
->dock
->dock_row
).
2689 Position(dock_drop_offset
);
2692 ((pt
.y
< part
->dock
->rect
.y
+ 1) && part
->dock
->IsHorizontal()) ||
2693 ((pt
.x
< part
->dock
->rect
.x
+ 1) && part
->dock
->IsVertical())
2694 ) && part
->dock
->panes
.GetCount() > 1)
2696 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2697 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2699 int row
= drop
.dock_row
;
2700 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2701 part
->dock
->dock_layer
,
2702 part
->dock
->dock_row
);
2703 drop
.dock_row
= row
;
2707 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2708 part
->dock
->dock_layer
,
2709 part
->dock
->dock_row
+1);
2710 drop
.dock_row
= part
->dock
->dock_row
+1;
2715 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2716 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2717 ) && part
->dock
->panes
.GetCount() > 1)
2719 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2720 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2722 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2723 part
->dock
->dock_layer
,
2724 part
->dock
->dock_row
+1);
2725 drop
.dock_row
= part
->dock
->dock_row
+1;
2729 int row
= drop
.dock_row
;
2730 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2731 part
->dock
->dock_layer
,
2732 part
->dock
->dock_row
);
2733 drop
.dock_row
= row
;
2737 return ProcessDockResult(target
, drop
);
2746 if (part
->type
== wxAuiDockUIPart::typePaneBorder
||
2747 part
->type
== wxAuiDockUIPart::typeCaption
||
2748 part
->type
== wxAuiDockUIPart::typeGripper
||
2749 part
->type
== wxAuiDockUIPart::typePaneButton
||
2750 part
->type
== wxAuiDockUIPart::typePane
||
2751 part
->type
== wxAuiDockUIPart::typePaneSizer
||
2752 part
->type
== wxAuiDockUIPart::typeDockSizer
||
2753 part
->type
== wxAuiDockUIPart::typeBackground
)
2755 if (part
->type
== wxAuiDockUIPart::typeDockSizer
)
2757 if (part
->dock
->panes
.GetCount() != 1)
2759 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2766 // If a normal frame is being dragged over a toolbar, insert it
2767 // along the edge under the toolbar, but over all other panes.
2768 // (this could be done much better, but somehow factoring this
2769 // calculation with the one at the beginning of this function)
2770 if (part
->dock
&& part
->dock
->toolbar
)
2774 switch (part
->dock
->dock_direction
)
2776 case wxAUI_DOCK_LEFT
:
2777 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2778 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2779 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2781 case wxAUI_DOCK_TOP
:
2782 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2783 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2784 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2786 case wxAUI_DOCK_RIGHT
:
2787 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2788 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2789 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2791 case wxAUI_DOCK_BOTTOM
:
2792 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2793 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2794 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2798 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2801 Direction(part
->dock
->dock_direction
).
2802 Layer(layer
).Row(0).Position(0);
2803 return ProcessDockResult(target
, drop
);
2810 part
= GetPanePart(part
->pane
->window
);
2814 bool insert_dock_row
= false;
2815 int insert_row
= part
->pane
->dock_row
;
2816 int insert_dir
= part
->pane
->dock_direction
;
2817 int insert_layer
= part
->pane
->dock_layer
;
2819 switch (part
->pane
->dock_direction
)
2821 case wxAUI_DOCK_TOP
:
2822 if (pt
.y
>= part
->rect
.y
&&
2823 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2824 insert_dock_row
= true;
2826 case wxAUI_DOCK_BOTTOM
:
2827 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2828 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2829 insert_dock_row
= true;
2831 case wxAUI_DOCK_LEFT
:
2832 if (pt
.x
>= part
->rect
.x
&&
2833 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2834 insert_dock_row
= true;
2836 case wxAUI_DOCK_RIGHT
:
2837 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2838 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2839 insert_dock_row
= true;
2841 case wxAUI_DOCK_CENTER
:
2843 // "new row pixels" will be set to the default, but
2844 // must never exceed 20% of the window size
2845 int new_row_pixels_x
= auiNewRowPixels
;
2846 int new_row_pixels_y
= auiNewRowPixels
;
2848 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2849 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2851 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2852 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2855 // determine if the mouse pointer is in a location that
2856 // will cause a new row to be inserted. The hot spot positions
2857 // are along the borders of the center pane
2860 insert_dock_row
= true;
2861 if (pt
.x
>= part
->rect
.x
&&
2862 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2863 insert_dir
= wxAUI_DOCK_LEFT
;
2865 if (pt
.y
>= part
->rect
.y
&&
2866 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2867 insert_dir
= wxAUI_DOCK_TOP
;
2869 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2870 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2871 insert_dir
= wxAUI_DOCK_RIGHT
;
2873 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2874 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2875 insert_dir
= wxAUI_DOCK_BOTTOM
;
2879 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2883 if (insert_dock_row
)
2885 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2886 drop
.Dock().Direction(insert_dir
).
2887 Layer(insert_layer
).
2890 return ProcessDockResult(target
, drop
);
2893 // determine the mouse offset and the pane size, both in the
2894 // direction of the dock itself, and perpendicular to the dock
2898 if (part
->orientation
== wxVERTICAL
)
2900 offset
= pt
.y
- part
->rect
.y
;
2901 size
= part
->rect
.GetHeight();
2905 offset
= pt
.x
- part
->rect
.x
;
2906 size
= part
->rect
.GetWidth();
2909 int drop_position
= part
->pane
->dock_pos
;
2911 // if we are in the top/left part of the pane,
2912 // insert the pane before the pane being hovered over
2913 if (offset
<= size
/2)
2915 drop_position
= part
->pane
->dock_pos
;
2917 part
->pane
->dock_direction
,
2918 part
->pane
->dock_layer
,
2919 part
->pane
->dock_row
,
2920 part
->pane
->dock_pos
);
2923 // if we are in the bottom/right part of the pane,
2924 // insert the pane before the pane being hovered over
2925 if (offset
> size
/2)
2927 drop_position
= part
->pane
->dock_pos
+1;
2929 part
->pane
->dock_direction
,
2930 part
->pane
->dock_layer
,
2931 part
->pane
->dock_row
,
2932 part
->pane
->dock_pos
+1);
2936 Direction(part
->dock
->dock_direction
).
2937 Layer(part
->dock
->dock_layer
).
2938 Row(part
->dock
->dock_row
).
2939 Position(drop_position
);
2940 return ProcessDockResult(target
, drop
);
2947 void wxAuiManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2949 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
2951 m_hint_fadetimer
.Stop();
2955 m_hint_fadeamt
+= 4;
2956 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2959 void wxAuiManager::ShowHint(const wxRect
& rect
)
2963 // if the hint rect is the same as last time, don't do anything
2964 if (m_last_hint
== rect
)
2968 m_hint_fadeamt
= m_hint_fademax
;
2970 if ((m_flags
& wxAUI_MGR_HINT_FADE
)
2971 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2972 (m_flags
& wxAUI_MGR_NO_VENETIAN_BLINDS_FADE
))
2976 m_hint_wnd
->SetSize(rect
);
2978 if (!m_hint_wnd
->IsShown())
2981 // if we are dragging a floating pane, set the focus
2982 // back to that floating pane (otherwise it becomes unfocused)
2983 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2984 m_action_window
->SetFocus();
2986 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2987 m_hint_wnd
->Raise();
2990 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
2992 // start fade in timer
2993 m_hint_fadetimer
.SetOwner(this, 101);
2994 m_hint_fadetimer
.Start(5);
2997 else // Not using a transparent hint window...
2999 if (!(m_flags
& wxAUI_MGR_RECTANGLE_HINT
))
3002 if (m_last_hint
!= rect
)
3004 // remove the last hint rectangle
3010 wxScreenDC screendc
;
3011 wxRegion
clip(1, 1, 10000, 10000);
3013 // clip all floating windows, so we don't draw over them
3015 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
3017 wxAuiPaneInfo
& pane
= m_panes
.Item(i
);
3019 if (pane
.IsFloating() &&
3020 pane
.frame
->IsShown())
3022 wxRect rect
= pane
.frame
->GetRect();
3024 // wxGTK returns the client size, not the whole frame size
3030 clip
.Subtract(rect
);
3034 // As we can only hide the hint by redrawing the managed window, we
3035 // need to clip the region to the managed window too or we get
3036 // nasty redrawn problems.
3037 clip
.Intersect(m_frame
->GetRect());
3039 screendc
.SetClippingRegion(clip
);
3041 wxBitmap stipple
= wxPaneCreateStippleBitmap();
3042 wxBrush
brush(stipple
);
3043 screendc
.SetBrush(brush
);
3044 screendc
.SetPen(*wxTRANSPARENT_PEN
);
3046 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
3047 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
3048 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
3049 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
3053 void wxAuiManager::HideHint()
3055 // hides a transparent window hint, if there is one
3058 if (m_hint_wnd
->IsShown())
3059 m_hint_wnd
->Show(false);
3060 m_hint_wnd
->SetTransparent(0);
3061 m_hint_fadetimer
.Stop();
3062 m_last_hint
= wxRect();
3066 // hides a painted hint by redrawing the frame window
3067 if (!m_last_hint
.IsEmpty())
3071 m_last_hint
= wxRect();
3078 // CalculateHintRect() calculates the drop hint rectangle. The method
3079 // first calls DoDrop() to determine the exact position the pane would
3080 // be at were if dropped. If the pane would indeed become docked at the
3081 // specified drop point, the the rectangle hint will be returned in
3082 // screen coordinates. Otherwise, an empty rectangle is returned.
3083 // |pane_window| is the window pointer of the pane being dragged, |pt| is
3084 // the mouse position, in client coordinates. |offset| describes the offset
3085 // that the mouse is from the upper-left corner of the item being dragged
3087 wxRect
wxAuiManager::CalculateHintRect(wxWindow
* pane_window
,
3089 const wxPoint
& offset
)
3093 // we need to paint a hint rectangle; to find out the exact hint rectangle,
3094 // we will create a new temporary layout and then measure the resulting
3095 // rectangle; we will create a copy of the docking structures (m_dock)
3096 // so that we don't modify the real thing on screen
3098 int i
, pane_count
, part_count
;
3099 wxAuiDockInfoArray docks
;
3100 wxAuiPaneInfoArray panes
;
3101 wxAuiDockUIPartArray uiparts
;
3102 wxAuiPaneInfo hint
= GetPane(pane_window
);
3103 hint
.name
= wxT("__HINT__");
3109 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3111 // remove any pane already there which bears the same window;
3112 // this happens when you are moving a pane around in a dock
3113 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
3115 if (panes
.Item(i
).window
== pane_window
)
3117 RemovePaneFromDocks(docks
, panes
.Item(i
));
3123 // find out where the new pane would be
3124 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
3131 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
3132 wxSize client_size
= m_frame
->GetClientSize();
3133 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
3136 for (i
= 0, part_count
= uiparts
.GetCount();
3137 i
< part_count
; ++i
)
3139 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
3141 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
3142 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
3144 rect
= wxRect(part
.sizer_item
->GetPosition(),
3145 part
.sizer_item
->GetSize());
3157 // actually show the hint rectangle on the screen
3158 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
3163 // DrawHintRect() calculates the hint rectangle by calling
3164 // CalculateHintRect(). If there is a rectangle, it shows it
3165 // by calling ShowHint(), otherwise it hides any hint
3166 // rectangle currently shown
3167 void wxAuiManager::DrawHintRect(wxWindow
* pane_window
,
3169 const wxPoint
& offset
)
3171 wxRect rect
= CalculateHintRect(pane_window
, pt
, offset
);
3183 void wxAuiManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
3185 // try to find the pane
3186 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3187 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3189 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3190 pane
.frame
->SetTransparent(150);
3193 void wxAuiManager::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
3195 // try to find the pane
3196 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3197 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3199 wxPoint pt
= ::wxGetMousePosition();
3202 // Adapt pt to direction
3205 // move to pane's upper border
3207 pos
= wnd
->ClientToScreen( pos
);
3209 // and some more pixels for the title bar
3214 // move to pane's left border
3216 pos
= wnd
->ClientToScreen( pos
);
3221 // move to pane's right border
3222 wxPoint
pos( wnd
->GetSize().x
, 0 );
3223 pos
= wnd
->ClientToScreen( pos
);
3228 // move to pane's bottom border
3229 wxPoint
pos( 0, wnd
->GetSize().y
);
3230 pos
= wnd
->ClientToScreen( pos
);
3237 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3239 // calculate the offset from the upper left-hand corner
3240 // of the frame to the mouse pointer
3241 wxPoint frame_pos
= pane
.frame
->GetPosition();
3242 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3244 // no hint for toolbar floating windows
3245 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
3247 if (m_action
== actionDragFloatingPane
)
3249 wxAuiDockInfoArray docks
;
3250 wxAuiPaneInfoArray panes
;
3251 wxAuiDockUIPartArray uiparts
;
3252 wxAuiPaneInfo hint
= pane
;
3254 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3256 // find out where the new pane would be
3257 if (!DoDrop(docks
, panes
, hint
, client_pt
))
3259 if (hint
.IsFloating())
3263 m_action
= actionDragToolbarPane
;
3264 m_action_window
= pane
.window
;
3273 // if a key modifier is pressed while dragging the frame,
3274 // don't dock the window
3275 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
3282 DrawHintRect(wnd
, client_pt
, action_offset
);
3285 // this cleans up some screen artifacts that are caused on GTK because
3286 // we aren't getting the exact size of the window (see comment
3296 void wxAuiManager::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
3298 // try to find the pane
3299 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3300 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3302 wxPoint pt
= ::wxGetMousePosition();
3305 // Adapt pt to direction
3308 // move to pane's upper border
3310 pos
= wnd
->ClientToScreen( pos
);
3312 // and some more pixels for the title bar
3317 // move to pane's left border
3319 pos
= wnd
->ClientToScreen( pos
);
3324 // move to pane's right border
3325 wxPoint
pos( wnd
->GetSize().x
, 0 );
3326 pos
= wnd
->ClientToScreen( pos
);
3331 // move to pane's bottom border
3332 wxPoint
pos( 0, wnd
->GetSize().y
);
3333 pos
= wnd
->ClientToScreen( pos
);
3340 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3342 // calculate the offset from the upper left-hand corner
3343 // of the frame to the mouse pointer
3344 wxPoint frame_pos
= pane
.frame
->GetPosition();
3345 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3348 // if a key modifier is pressed while dragging the frame,
3349 // don't dock the window
3350 if (!wxGetKeyState(WXK_CONTROL
) && !wxGetKeyState(WXK_ALT
))
3352 // do the drop calculation
3353 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3356 // if the pane is still floating, update it's floating
3357 // position (that we store)
3358 if (pane
.IsFloating())
3360 pane
.floating_pos
= pane
.frame
->GetPosition();
3362 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3363 pane
.frame
->SetTransparent(255);
3365 else if (m_has_maximized
)
3367 RestoreMaximizedPane();
3375 void wxAuiManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3377 // try to find the pane
3378 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3379 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3381 pane
.floating_size
= size
;
3385 void wxAuiManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3387 // try to find the pane
3388 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3389 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3392 // fire pane close event
3393 wxAuiManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3395 e
.SetCanVeto(evt
.CanVeto());
3411 void wxAuiManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3413 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3415 // try to find the pane
3416 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
3418 SetActivePane(m_panes
, wnd
);
3423 // OnRender() draws all of the pane captions, sashes,
3424 // backgrounds, captions, grippers, pane borders and buttons.
3425 // It renders the entire user interface.
3427 void wxAuiManager::OnRender(wxAuiManagerEvent
& evt
)
3429 wxDC
* dc
= evt
.GetDC();
3435 for (i
= 0, part_count
= m_uiparts
.GetCount();
3436 i
< part_count
; ++i
)
3438 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
3440 // don't draw hidden pane items
3441 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
3446 case wxAuiDockUIPart::typeDockSizer
:
3447 case wxAuiDockUIPart::typePaneSizer
:
3448 m_art
->DrawSash(*dc
, m_frame
, part
.orientation
, part
.rect
);
3450 case wxAuiDockUIPart::typeBackground
:
3451 m_art
->DrawBackground(*dc
, m_frame
, part
.orientation
, part
.rect
);
3453 case wxAuiDockUIPart::typeCaption
:
3454 m_art
->DrawCaption(*dc
, m_frame
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3456 case wxAuiDockUIPart::typeGripper
:
3457 m_art
->DrawGripper(*dc
, m_frame
, part
.rect
, *part
.pane
);
3459 case wxAuiDockUIPart::typePaneBorder
:
3460 m_art
->DrawBorder(*dc
, m_frame
, part
.rect
, *part
.pane
);
3462 case wxAuiDockUIPart::typePaneButton
:
3463 m_art
->DrawPaneButton(*dc
, m_frame
, part
.button
->button_id
,
3464 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3471 // Render() fire a render event, which is normally handled by
3472 // wxAuiManager::OnRender(). This allows the render function to
3473 // be overridden via the render event. This can be useful for paintin
3474 // custom graphics in the main window. Default behavior can be
3475 // invoked in the overridden function by calling OnRender()
3477 void wxAuiManager::Render(wxDC
* dc
)
3479 wxAuiManagerEvent
e(wxEVT_AUI_RENDER
);
3485 void wxAuiManager::Repaint(wxDC
* dc
)
3490 m_frame
->Refresh() ;
3496 m_frame
->GetClientSize(&w
, &h
);
3498 // figure out which dc to use; if one
3499 // has been specified, use it, otherwise
3501 wxClientDC
* client_dc
= NULL
;
3504 client_dc
= new wxClientDC(m_frame
);
3508 // if the frame has a toolbar, the client area
3509 // origin will not be (0,0).
3510 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3511 if (pt
.x
!= 0 || pt
.y
!= 0)
3512 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3514 // render all the items
3517 // if we created a client_dc, delete it
3522 void wxAuiManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3524 wxPaintDC
dc(m_frame
);
3528 void wxAuiManager::OnEraseBackground(wxEraseEvent
& event
)
3537 void wxAuiManager::OnSize(wxSizeEvent
& event
)
3545 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
3547 // for MDI parent frames, this event must not
3548 // be "skipped". In other words, the parent frame
3549 // must not be allowed to resize the client window
3550 // after we are finished processing sizing changes
3558 void wxAuiManager::OnFindManager(wxAuiManagerEvent
& evt
)
3560 // get the window we are managing, if none, return NULL
3561 wxWindow
* window
= GetManagedWindow();
3564 evt
.SetManager(NULL
);
3568 // if we are managing a child frame, get the 'real' manager
3569 if (window
->IsKindOf(CLASSINFO(wxAuiFloatingFrame
)))
3571 wxAuiFloatingFrame
* float_frame
= static_cast<wxAuiFloatingFrame
*>(window
);
3572 evt
.SetManager(float_frame
->GetOwnerManager());
3576 // return pointer to ourself
3577 evt
.SetManager(this);
3580 void wxAuiManager::OnSetCursor(wxSetCursorEvent
& event
)
3583 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3584 wxCursor cursor
= wxNullCursor
;
3588 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3589 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3591 // a dock may not be resized if it has a single
3592 // pane which is not resizable
3593 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3594 part
->dock
->panes
.GetCount() == 1 &&
3595 part
->dock
->panes
.Item(0)->IsFixed())
3598 // panes that may not be resized do not get a sizing cursor
3599 if (part
->pane
&& part
->pane
->IsFixed())
3602 if (part
->orientation
== wxVERTICAL
)
3603 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3605 cursor
= wxCursor(wxCURSOR_SIZENS
);
3607 else if (part
->type
== wxAuiDockUIPart::typeGripper
)
3609 cursor
= wxCursor(wxCURSOR_SIZING
);
3613 event
.SetCursor(cursor
);
3618 void wxAuiManager::UpdateButtonOnScreen(wxAuiDockUIPart
* button_ui_part
,
3619 const wxMouseEvent
& event
)
3621 wxAuiDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3622 if (!hit_test
|| !button_ui_part
)
3625 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3627 if (hit_test
== button_ui_part
)
3629 if (event
.LeftDown())
3630 state
= wxAUI_BUTTON_STATE_PRESSED
;
3632 state
= wxAUI_BUTTON_STATE_HOVER
;
3636 if (event
.LeftDown())
3637 state
= wxAUI_BUTTON_STATE_HOVER
;
3640 // now repaint the button with hover state
3641 wxClientDC
cdc(m_frame
);
3643 // if the frame has a toolbar, the client area
3644 // origin will not be (0,0).
3645 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3646 if (pt
.x
!= 0 || pt
.y
!= 0)
3647 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3651 m_art
->DrawPaneButton(cdc
, m_frame
,
3652 button_ui_part
->button
->button_id
,
3654 button_ui_part
->rect
,
3659 void wxAuiManager::OnLeftDown(wxMouseEvent
& event
)
3661 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3664 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3665 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3667 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3670 // a dock may not be resized if it has a single
3671 // pane which is not resizable
3672 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3673 part
->dock
->panes
.GetCount() == 1 &&
3674 part
->dock
->panes
.Item(0)->IsFixed())
3677 // panes that may not be resized should be ignored here
3678 if (part
->pane
&& part
->pane
->IsFixed())
3681 m_action
= actionResize
;
3682 m_action_part
= part
;
3683 m_action_hintrect
= wxRect();
3684 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3685 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3686 event
.m_y
- part
->rect
.y
);
3687 m_frame
->CaptureMouse();
3689 else if (part
->type
== wxAuiDockUIPart::typePaneButton
)
3691 m_action
= actionClickButton
;
3692 m_action_part
= part
;
3693 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3694 m_frame
->CaptureMouse();
3696 UpdateButtonOnScreen(part
, event
);
3698 else if (part
->type
== wxAuiDockUIPart::typeCaption
||
3699 part
->type
== wxAuiDockUIPart::typeGripper
)
3701 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3704 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3706 // set the caption as active
3707 SetActivePane(m_panes
, part
->pane
->window
);
3711 m_action
= actionClickCaption
;
3712 m_action_part
= part
;
3713 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3714 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3715 event
.m_y
- part
->rect
.y
);
3716 m_frame
->CaptureMouse();
3736 void wxAuiManager::OnLeftUp(wxMouseEvent
& event
)
3738 if (m_action
== actionResize
)
3740 m_frame
->ReleaseMouse();
3742 // get rid of the hint rectangle
3744 DrawResizeHint(dc
, m_action_hintrect
);
3746 // resize the dock or the pane
3747 if (m_action_part
&& m_action_part
->type
==wxAuiDockUIPart::typeDockSizer
)
3749 wxRect
& rect
= m_action_part
->dock
->rect
;
3751 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3752 event
.m_y
- m_action_offset
.y
);
3754 switch (m_action_part
->dock
->dock_direction
)
3756 case wxAUI_DOCK_LEFT
:
3757 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3759 case wxAUI_DOCK_TOP
:
3760 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3762 case wxAUI_DOCK_RIGHT
:
3763 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3764 new_pos
.x
- m_action_part
->rect
.GetWidth();
3766 case wxAUI_DOCK_BOTTOM
:
3767 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3768 new_pos
.y
- m_action_part
->rect
.GetHeight();
3775 else if (m_action_part
&&
3776 m_action_part
->type
== wxAuiDockUIPart::typePaneSizer
)
3778 wxAuiDockInfo
& dock
= *m_action_part
->dock
;
3779 wxAuiPaneInfo
& pane
= *m_action_part
->pane
;
3781 int total_proportion
= 0;
3782 int dock_pixels
= 0;
3783 int new_pixsize
= 0;
3785 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
3786 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
3787 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
3789 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3790 event
.m_y
- m_action_offset
.y
);
3792 // determine the pane rectangle by getting the pane part
3793 wxAuiDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3794 wxASSERT_MSG(pane_part
,
3795 wxT("Pane border part not found -- shouldn't happen"));
3797 // determine the new pixel size that the user wants;
3798 // this will help us recalculate the pane's proportion
3799 if (dock
.IsHorizontal())
3800 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3802 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3804 // determine the size of the dock, based on orientation
3805 if (dock
.IsHorizontal())
3806 dock_pixels
= dock
.rect
.GetWidth();
3808 dock_pixels
= dock
.rect
.GetHeight();
3810 // determine the total proportion of all resizable panes,
3811 // and the total size of the dock minus the size of all
3813 int i
, dock_pane_count
= dock
.panes
.GetCount();
3814 int pane_position
= -1;
3815 for (i
= 0; i
< dock_pane_count
; ++i
)
3817 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
3818 if (p
.window
== pane
.window
)
3821 // while we're at it, subtract the pane sash
3822 // width from the dock width, because this would
3823 // skew our proportion calculations
3825 dock_pixels
-= sash_size
;
3827 // also, the whole size (including decorations) of
3828 // all fixed panes must also be subtracted, because they
3829 // are not part of the proportion calculation
3832 if (dock
.IsHorizontal())
3833 dock_pixels
-= p
.best_size
.x
;
3835 dock_pixels
-= p
.best_size
.y
;
3839 total_proportion
+= p
.dock_proportion
;
3843 // find a pane in our dock to 'steal' space from or to 'give'
3844 // space to -- this is essentially what is done when a pane is
3845 // resized; the pane should usually be the first non-fixed pane
3846 // to the right of the action pane
3847 int borrow_pane
= -1;
3848 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3850 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
3859 // demand that the pane being resized is found in this dock
3860 // (this assert really never should be raised)
3861 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3863 // prevent division by zero
3864 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3866 m_action
= actionNone
;
3870 // calculate the new proportion of the pane
3871 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3873 // default minimum size
3876 // check against the pane's minimum size, if specified. please note
3877 // that this is not enough to ensure that the minimum size will
3878 // not be violated, because the whole frame might later be shrunk,
3879 // causing the size of the pane to violate it's minimum size
3880 if (pane
.min_size
.IsFullySpecified())
3884 if (pane
.HasBorder())
3885 min_size
+= (pane_border_size
*2);
3887 // calculate minimum size with decorations (border,caption)
3888 if (pane_part
->orientation
== wxVERTICAL
)
3890 min_size
+= pane
.min_size
.y
;
3891 if (pane
.HasCaption())
3892 min_size
+= caption_size
;
3896 min_size
+= pane
.min_size
.x
;
3901 // for some reason, an arithmatic error somewhere is causing
3902 // the proportion calculations to always be off by 1 pixel;
3903 // for now we will add the 1 pixel on, but we really should
3904 // determine what's causing this.
3907 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3909 if (new_proportion
< min_proportion
)
3910 new_proportion
= min_proportion
;
3914 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3916 // borrow the space from our neighbor pane to the
3917 // right or bottom (depending on orientation)
3918 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3919 pane
.dock_proportion
= new_proportion
;
3926 else if (m_action
== actionClickButton
)
3928 m_hover_button
= NULL
;
3929 m_frame
->ReleaseMouse();
3930 UpdateButtonOnScreen(m_action_part
, event
);
3932 // make sure we're still over the item that was originally clicked
3933 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3935 // fire button-click event
3936 wxAuiManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3938 e
.SetPane(m_action_part
->pane
);
3939 e
.SetButton(m_action_part
->button
->button_id
);
3943 else if (m_action
== actionClickCaption
)
3945 m_frame
->ReleaseMouse();
3947 else if (m_action
== actionDragFloatingPane
)
3949 m_frame
->ReleaseMouse();
3951 else if (m_action
== actionDragToolbarPane
)
3953 m_frame
->ReleaseMouse();
3955 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
3956 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3958 // save the new positions
3959 wxAuiDockInfoPtrArray docks
;
3960 FindDocks(m_docks
, pane
.dock_direction
,
3961 pane
.dock_layer
, pane
.dock_row
, docks
);
3962 if (docks
.GetCount() == 1)
3964 wxAuiDockInfo
& dock
= *docks
.Item(0);
3966 wxArrayInt pane_positions
, pane_sizes
;
3967 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3969 int i
, dock_pane_count
= dock
.panes
.GetCount();
3970 for (i
= 0; i
< dock_pane_count
; ++i
)
3971 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3974 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
3982 m_action
= actionNone
;
3983 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3987 void wxAuiManager::OnMotion(wxMouseEvent
& event
)
3989 // sometimes when Update() is called from inside this method,
3990 // a spurious mouse move event is generated; this check will make
3991 // sure that only real mouse moves will get anywhere in this method;
3992 // this appears to be a bug somewhere, and I don't know where the
3993 // mouse move event is being generated. only verified on MSW
3995 wxPoint mouse_pos
= event
.GetPosition();
3996 if (m_last_mouse_move
== mouse_pos
)
3998 m_last_mouse_move
= mouse_pos
;
4001 if (m_action
== actionResize
)
4003 wxPoint pos
= m_action_part
->rect
.GetPosition();
4004 if (m_action_part
->orientation
== wxHORIZONTAL
)
4005 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
4007 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
4009 wxRect
rect(m_frame
->ClientToScreen(pos
),
4010 m_action_part
->rect
.GetSize());
4013 if (!m_action_hintrect
.IsEmpty())
4014 DrawResizeHint(dc
, m_action_hintrect
);
4015 DrawResizeHint(dc
, rect
);
4016 m_action_hintrect
= rect
;
4018 else if (m_action
== actionClickCaption
)
4020 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
4021 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
4023 // caption has been clicked. we need to check if the mouse
4024 // is now being dragged. if it is, we need to change the
4025 // mouse action to 'drag'
4026 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
4027 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
4029 wxAuiPaneInfo
* pane_info
= m_action_part
->pane
;
4031 if (!pane_info
->IsToolbar())
4033 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
4034 pane_info
->IsFloatable())
4036 m_action
= actionDragFloatingPane
;
4038 // set initial float position
4039 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4040 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4041 pt
.y
- m_action_offset
.y
);
4044 if(pane_info
->IsMaximized()) {
4045 RestorePane(*pane_info
);
4050 m_action_window
= pane_info
->frame
;
4052 // action offset is used here to make it feel "natural" to the user
4053 // to drag a docked pane and suddenly have it become a floating frame.
4054 // Sometimes, however, the offset where the user clicked on the docked
4055 // caption is bigger than the width of the floating frame itself, so
4056 // in that case we need to set the action offset to a sensible value
4057 wxSize frame_size
= m_action_window
->GetSize();
4058 if (frame_size
.x
<= m_action_offset
.x
)
4059 m_action_offset
.x
= 30;
4064 m_action
= actionDragToolbarPane
;
4065 m_action_window
= pane_info
->window
;
4069 else if (m_action
== actionDragFloatingPane
)
4071 if(m_action_window
) {
4072 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4073 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
4074 pt
.y
- m_action_offset
.y
);
4077 else if (m_action
== actionDragToolbarPane
)
4079 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4080 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4082 pane
.state
|= wxAuiPaneInfo::actionPane
;
4084 wxPoint pt
= event
.GetPosition();
4085 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
4087 // if DoDrop() decided to float the pane, set up
4088 // the floating pane's initial position
4089 if (pane
.IsFloating())
4091 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4092 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4093 pt
.y
- m_action_offset
.y
);
4096 // this will do the actiual move operation;
4097 // in the case that the pane has been floated,
4098 // this call will create the floating pane
4099 // and do the reparenting
4102 // if the pane has been floated, change the mouse
4103 // action actionDragFloatingPane so that subsequent
4104 // EVT_MOTION() events will move the floating pane
4105 if (pane
.IsFloating())
4107 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
4108 m_action
= actionDragFloatingPane
;
4109 m_action_window
= pane
.frame
;
4114 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
4115 if (part
&& part
->type
== wxAuiDockUIPart::typePaneButton
)
4117 if (part
!= m_hover_button
)
4119 // make the old button normal
4122 UpdateButtonOnScreen(m_hover_button
, event
);
4126 // mouse is over a button, so repaint the
4127 // button in hover mode
4128 UpdateButtonOnScreen(part
, event
);
4129 m_hover_button
= part
;
4137 m_hover_button
= NULL
;
4148 void wxAuiManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
4152 m_hover_button
= NULL
;
4157 void wxAuiManager::OnChildFocus(wxChildFocusEvent
& event
)
4159 // when a child pane has it's focus set, we should change the
4160 // pane's active state to reflect this. (this is only true if
4161 // active panes are allowed by the owner)
4162 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
4164 if (GetPane(event
.GetWindow()).IsOk())
4166 SetActivePane(m_panes
, event
.GetWindow());
4175 // OnPaneButton() is an event handler that is called
4176 // when a pane button has been pressed.
4177 void wxAuiManager::OnPaneButton(wxAuiManagerEvent
& evt
)
4179 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxAuiManager::OnPaneButton must be non-null"));
4181 wxAuiPaneInfo
& pane
= *(evt
.pane
);
4183 if (evt
.button
== wxAUI_BUTTON_CLOSE
)
4185 // fire pane close event
4186 wxAuiManagerEvent
e(wxEVT_AUI_PANECLOSE
);
4188 e
.SetPane(evt
.pane
);
4197 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& !pane
.IsMaximized())
4199 // fire pane close event
4200 wxAuiManagerEvent
e(wxEVT_AUI_PANEMAXIMIZE
);
4202 e
.SetPane(evt
.pane
);
4211 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& pane
.IsMaximized())
4213 // fire pane close event
4214 wxAuiManagerEvent
e(wxEVT_AUI_PANERESTORE
);
4216 e
.SetPane(evt
.pane
);
4225 else if (evt
.button
== wxAUI_BUTTON_PIN
)
4227 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&