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
);
1726 if (pane
.IsMaximized())
1727 has_maximized_pane
= true;
1730 int amount
= pane_pos
- offset
;
1733 if (dock
.IsVertical())
1734 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1736 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1738 part
.type
= wxAuiDockUIPart::typeBackground
;
1742 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1743 part
.cont_sizer
= dock_sizer
;
1744 part
.sizer_item
= sizer_item
;
1750 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1752 offset
+= pane_sizes
.Item(pane_i
);
1755 // at the end add a very small stretchable background area
1756 sizer_item
= dock_sizer
->Add(0,0, 1, wxEXPAND
);
1758 part
.type
= wxAuiDockUIPart::typeBackground
;
1762 part
.orientation
= orientation
;
1763 part
.cont_sizer
= dock_sizer
;
1764 part
.sizer_item
= sizer_item
;
1769 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1771 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1773 if(pane
.IsMaximized())
1774 has_maximized_pane
= true;
1776 // if this is not the first pane being added,
1777 // we need to add a pane sizer
1778 if (!m_has_maximized
&& pane_i
> 0)
1780 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1782 part
.type
= wxAuiDockUIPart::typePaneSizer
;
1784 part
.pane
= dock
.panes
.Item(pane_i
-1);
1786 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1787 part
.cont_sizer
= dock_sizer
;
1788 part
.sizer_item
= sizer_item
;
1792 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1796 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
|| has_maximized_pane
)
1797 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1799 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1801 part
.type
= wxAuiDockUIPart::typeDock
;
1805 part
.orientation
= orientation
;
1806 part
.cont_sizer
= cont
;
1807 part
.sizer_item
= sizer_item
;
1810 if (dock
.IsHorizontal())
1811 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1813 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1815 // top and left docks have a sash after them
1816 if (!m_has_maximized
&&
1818 (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1819 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1821 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1823 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1827 part
.orientation
= orientation
;
1828 part
.cont_sizer
= cont
;
1829 part
.sizer_item
= sizer_item
;
1834 wxSizer
* wxAuiManager::LayoutAll(wxAuiPaneInfoArray
& panes
,
1835 wxAuiDockInfoArray
& docks
,
1836 wxAuiDockUIPartArray
& uiparts
,
1839 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1841 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1842 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1843 wxSize cli_size
= m_frame
->GetClientSize();
1844 int i
, dock_count
, pane_count
;
1847 // empty all docks out
1848 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1849 docks
.Item(i
).panes
.Empty();
1852 // iterate through all known panes, filing each
1853 // of them into the appropriate dock. If the
1854 // pane does not exist in the dock, add it
1855 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1857 wxAuiPaneInfo
& p
= panes
.Item(i
);
1859 // find any docks with the same dock direction, dock layer, and
1860 // dock row as the pane we are working on
1861 wxAuiDockInfo
* dock
;
1862 wxAuiDockInfoPtrArray arr
;
1863 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1865 if (arr
.GetCount() > 0)
1867 // found the right dock
1872 // dock was not found, so we need to create a new one
1874 d
.dock_direction
= p
.dock_direction
;
1875 d
.dock_layer
= p
.dock_layer
;
1876 d
.dock_row
= p
.dock_row
;
1878 dock
= &docks
.Last();
1882 if (p
.IsDocked() && p
.IsShown())
1884 // remove the pane from any existing docks except this one
1885 RemovePaneFromDocks(docks
, p
, dock
);
1887 // pane needs to be added to the dock,
1888 // if it doesn't already exist
1889 if (!FindPaneInDock(*dock
, p
.window
))
1890 dock
->panes
.Add(&p
);
1894 // remove the pane from any existing docks
1895 RemovePaneFromDocks(docks
, p
);
1900 // remove any empty docks
1901 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1903 if (docks
.Item(i
).panes
.GetCount() == 0)
1907 // configure the docks further
1908 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1910 wxAuiDockInfo
& dock
= docks
.Item(i
);
1911 int j
, dock_pane_count
= dock
.panes
.GetCount();
1913 // sort the dock pane array by the pane's
1914 // dock position (dock_pos), in ascending order
1915 dock
.panes
.Sort(PaneSortFunc
);
1917 // for newly created docks, set up their initial size
1922 for (j
= 0; j
< dock_pane_count
; ++j
)
1924 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
1925 wxSize pane_size
= pane
.best_size
;
1926 if (pane_size
== wxDefaultSize
)
1927 pane_size
= pane
.min_size
;
1928 if (pane_size
== wxDefaultSize
)
1929 pane_size
= pane
.window
->GetSize();
1931 if (dock
.IsHorizontal())
1932 size
= wxMax(pane_size
.y
, size
);
1934 size
= wxMax(pane_size
.x
, size
);
1937 // add space for the border (two times), but only
1938 // if at least one pane inside the dock has a pane border
1939 for (j
= 0; j
< dock_pane_count
; ++j
)
1941 if (dock
.panes
.Item(j
)->HasBorder())
1943 size
+= (pane_border_size
*2);
1948 // if pane is on the top or bottom, add the caption height,
1949 // but only if at least one pane inside the dock has a caption
1950 if (dock
.IsHorizontal())
1952 for (j
= 0; j
< dock_pane_count
; ++j
)
1954 if (dock
.panes
.Item(j
)->HasCaption())
1956 size
+= caption_size
;
1962 if (!(m_flags
& wxAUI_MGR_NO_DOCK_SIZE_LIMIT
))
1964 // new dock's size may not be more than 1/3 of the frame size
1965 if (dock
.IsHorizontal())
1966 size
= wxMin(size
, cli_size
.y
/3);
1968 size
= wxMin(size
, cli_size
.x
/3);
1977 // determine the dock's minimum size
1978 bool plus_border
= false;
1979 bool plus_caption
= false;
1980 int dock_min_size
= 0;
1981 for (j
= 0; j
< dock_pane_count
; ++j
)
1983 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
1984 if (pane
.min_size
!= wxDefaultSize
)
1986 if (pane
.HasBorder())
1988 if (pane
.HasCaption())
1989 plus_caption
= true;
1990 if (dock
.IsHorizontal())
1992 if (pane
.min_size
.y
> dock_min_size
)
1993 dock_min_size
= pane
.min_size
.y
;
1997 if (pane
.min_size
.x
> dock_min_size
)
1998 dock_min_size
= pane
.min_size
.x
;
2004 dock_min_size
+= (pane_border_size
*2);
2005 if (plus_caption
&& dock
.IsHorizontal())
2006 dock_min_size
+= (caption_size
);
2008 dock
.min_size
= dock_min_size
;
2011 // if the pane's current size is less than it's
2012 // minimum, increase the dock's size to it's minimum
2013 if (dock
.size
< dock
.min_size
)
2014 dock
.size
= dock
.min_size
;
2017 // determine the dock's mode (fixed or proportional);
2018 // determine whether the dock has only toolbars
2019 bool action_pane_marked
= false;
2021 dock
.toolbar
= true;
2022 for (j
= 0; j
< dock_pane_count
; ++j
)
2024 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2025 if (!pane
.IsFixed())
2027 if (!pane
.IsToolbar())
2028 dock
.toolbar
= false;
2029 if (pane
.state
& wxAuiPaneInfo::actionPane
)
2030 action_pane_marked
= true;
2034 // if the dock mode is proportional and not fixed-pixel,
2035 // reassign the dock_pos to the sequential 0, 1, 2, 3;
2036 // e.g. remove gaps like 1, 2, 30, 500
2039 for (j
= 0; j
< dock_pane_count
; ++j
)
2041 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2046 // if the dock mode is fixed, and none of the panes
2047 // are being moved right now, make sure the panes
2048 // do not overlap each other. If they do, we will
2049 // adjust the positions of the panes
2050 if (dock
.fixed
&& !action_pane_marked
)
2052 wxArrayInt pane_positions
, pane_sizes
;
2053 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
2056 for (j
= 0; j
< dock_pane_count
; ++j
)
2058 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(j
));
2059 pane
.dock_pos
= pane_positions
[j
];
2061 int amount
= pane
.dock_pos
- offset
;
2065 pane
.dock_pos
+= -amount
;
2067 offset
+= pane_sizes
[j
];
2072 // discover the maximum dock layer
2074 for (i
= 0; i
< dock_count
; ++i
)
2075 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
2078 // clear out uiparts
2081 // create a bunch of box sizers,
2082 // from the innermost level outwards.
2083 wxSizer
* cont
= NULL
;
2084 wxSizer
* middle
= NULL
;
2088 for (layer
= 0; layer
<= max_layer
; ++layer
)
2090 wxAuiDockInfoPtrArray arr
;
2092 // find any docks in this layer
2093 FindDocks(docks
, -1, layer
, -1, arr
);
2095 // if there aren't any, skip to the next layer
2099 wxSizer
* old_cont
= cont
;
2101 // create a container which will hold this layer's
2102 // docks (top, bottom, left, right)
2103 cont
= new wxBoxSizer(wxVERTICAL
);
2106 // find any top docks in this layer
2107 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
2108 RenumberDockRows(arr
);
2111 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2112 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2116 // fill out the middle layer (which consists
2117 // of left docks, content area and right docks)
2119 middle
= new wxBoxSizer(wxHORIZONTAL
);
2121 // find any left docks in this layer
2122 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
2123 RenumberDockRows(arr
);
2126 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2127 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2130 // add content dock (or previous layer's sizer
2134 // find any center docks
2135 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
2138 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
2139 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2141 else if (!m_has_maximized
)
2143 // there are no center docks, add a background area
2144 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
2145 wxAuiDockUIPart part
;
2146 part
.type
= wxAuiDockUIPart::typeBackground
;
2150 part
.cont_sizer
= middle
;
2151 part
.sizer_item
= sizer_item
;
2157 middle
->Add(old_cont
, 1, wxEXPAND
);
2160 // find any right docks in this layer
2161 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
2162 RenumberDockRows(arr
);
2165 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2166 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2169 cont
->Add(middle
, 1, wxEXPAND
);
2173 // find any bottom docks in this layer
2174 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
2175 RenumberDockRows(arr
);
2178 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2179 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2186 // no sizer available, because there are no docks,
2187 // therefore we will create a simple background area
2188 cont
= new wxBoxSizer(wxVERTICAL
);
2189 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
2190 wxAuiDockUIPart part
;
2191 part
.type
= wxAuiDockUIPart::typeBackground
;
2195 part
.cont_sizer
= middle
;
2196 part
.sizer_item
= sizer_item
;
2200 container
->Add(cont
, 1, wxEXPAND
);
2205 // Update() updates the layout. Whenever changes are made to
2206 // one or more panes, this function should be called. It is the
2207 // external entry point for running the layout engine.
2209 void wxAuiManager::Update()
2212 int i
, pane_count
= m_panes
.GetCount();
2215 // destroy floating panes which have been
2216 // redocked or are becoming non-floating
2217 for (i
= 0; i
< pane_count
; ++i
)
2219 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2221 if (!p
.IsFloating() && p
.frame
)
2223 // because the pane is no longer in a floating, we need to
2224 // reparent it to m_frame and destroy the floating frame
2227 p
.window
->SetSize(1,1);
2230 // the following block is a workaround for bug #1531361
2231 // (see wxWidgets sourceforge page). On wxGTK (only), when
2232 // a frame is shown/hidden, a move event unfortunately
2233 // also gets fired. Because we may be dragging around
2234 // a pane, we need to cancel that action here to prevent
2235 // a spurious crash.
2236 if (m_action_window
== p
.frame
)
2238 if (wxWindow::GetCapture() == m_frame
)
2239 m_frame
->ReleaseMouse();
2240 m_action
= actionNone
;
2241 m_action_window
= NULL
;
2245 if (p
.frame
->IsShown())
2246 p
.frame
->Show(false);
2248 // reparent to m_frame and destroy the pane
2249 if(m_action_window
== p
.frame
)
2251 m_action_window
= NULL
;
2254 p
.window
->Reparent(m_frame
);
2255 p
.frame
->SetSizer(NULL
);
2262 // delete old sizer first
2263 m_frame
->SetSizer(NULL
);
2265 // create a layout for all of the panes
2266 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
2268 // hide or show panes as necessary,
2269 // and float panes as necessary
2270 for (i
= 0; i
< pane_count
; ++i
)
2272 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2276 if (p
.frame
== NULL
)
2278 // we need to create a frame for this
2279 // pane, which has recently been floated
2280 wxAuiFloatingFrame
* frame
= CreateFloatingFrame(m_frame
, p
);
2282 // on MSW and Mac, if the owner desires transparent dragging, and
2283 // the dragging is happening right now, then the floating
2284 // window should have this style by default
2285 if (m_action
== actionDragFloatingPane
&&
2286 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2287 frame
->SetTransparent(150);
2289 frame
->SetPaneWindow(p
);
2292 if (p
.IsShown() && !frame
->IsShown())
2297 // frame already exists, make sure it's position
2298 // and size reflect the information in wxAuiPaneInfo
2299 if (p
.frame
->GetPosition() != p
.floating_pos
)
2301 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2302 wxDefaultCoord
, wxDefaultCoord
,
2303 wxSIZE_USE_EXISTING
);
2304 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2307 if (p
.frame
->IsShown() != p
.IsShown())
2308 p
.frame
->Show(p
.IsShown());
2313 if (p
.window
->IsShown() != p
.IsShown())
2314 p
.window
->Show(p
.IsShown());
2317 // if "active panes" are no longer allowed, clear
2318 // any optionActive values from the pane states
2319 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2321 p
.state
&= ~wxAuiPaneInfo::optionActive
;
2326 // keep track of the old window rectangles so we can
2327 // refresh those windows whose rect has changed
2328 wxAuiRectArray old_pane_rects
;
2329 for (i
= 0; i
< pane_count
; ++i
)
2332 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2334 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2337 old_pane_rects
.Add(r
);
2343 // apply the new sizer
2344 m_frame
->SetSizer(sizer
);
2345 m_frame
->SetAutoLayout(false);
2350 // now that the frame layout is done, we need to check
2351 // the new pane rectangles against the old rectangles that
2352 // we saved a few lines above here. If the rectangles have
2353 // changed, the corresponding panes must also be updated
2354 for (i
= 0; i
< pane_count
; ++i
)
2356 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2357 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2359 if (p
.rect
!= old_pane_rects
[i
])
2361 p
.window
->Refresh();
2370 // set frame's minimum size
2373 // N.B. More work needs to be done on frame minimum sizes;
2374 // this is some intresting code that imposes the minimum size,
2375 // but we may want to include a more flexible mechanism or
2376 // options for multiple minimum-size modes, e.g. strict or lax
2377 wxSize min_size = sizer->GetMinSize();
2378 wxSize frame_size = m_frame->GetSize();
2379 wxSize client_size = m_frame->GetClientSize();
2381 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2382 min_size.y+frame_size.y-client_size.y );
2384 m_frame->SetMinSize(minframe_size);
2386 if (frame_size.x < minframe_size.x ||
2387 frame_size.y < minframe_size.y)
2388 sizer->Fit(m_frame);
2393 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2394 // on the frame's main sizer, then measures all the various UI items
2395 // and updates their internal rectangles. This should always be called
2396 // instead of calling m_frame->Layout() directly
2398 void wxAuiManager::DoFrameLayout()
2403 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2405 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2407 // get the rectangle of the UI part
2408 // originally, this code looked like this:
2409 // part.rect = wxRect(part.sizer_item->GetPosition(),
2410 // part.sizer_item->GetSize());
2411 // this worked quite well, with one exception: the mdi
2412 // client window had a "deferred" size variable
2413 // that returned the wrong size. It looks like
2414 // a bug in wx, because the former size of the window
2415 // was being returned. So, we will retrieve the part's
2416 // rectangle via other means
2419 part
.rect
= part
.sizer_item
->GetRect();
2420 int flag
= part
.sizer_item
->GetFlag();
2421 int border
= part
.sizer_item
->GetBorder();
2424 part
.rect
.y
-= border
;
2425 part
.rect
.height
+= border
;
2429 part
.rect
.x
-= border
;
2430 part
.rect
.width
+= border
;
2432 if (flag
& wxBOTTOM
)
2433 part
.rect
.height
+= border
;
2435 part
.rect
.width
+= border
;
2438 if (part
.type
== wxAuiDockUIPart::typeDock
)
2439 part
.dock
->rect
= part
.rect
;
2440 if (part
.type
== wxAuiDockUIPart::typePane
)
2441 part
.pane
->rect
= part
.rect
;
2445 // GetPanePart() looks up the pane the pane border UI part (or the regular
2446 // pane part if there is no border). This allows the caller to get the exact
2447 // rectangle of the pane in question, including decorations like
2448 // caption and border (if any).
2450 wxAuiDockUIPart
* wxAuiManager::GetPanePart(wxWindow
* wnd
)
2453 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2455 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2456 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
2457 part
.pane
&& part
.pane
->window
== wnd
)
2460 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2462 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2463 if (part
.type
== wxAuiDockUIPart::typePane
&&
2464 part
.pane
&& part
.pane
->window
== wnd
)
2472 // GetDockPixelOffset() is an internal function which returns
2473 // a dock's offset in pixels from the left side of the window
2474 // (for horizontal docks) or from the top of the window (for
2475 // vertical docks). This value is necessary for calculating
2476 // fixel-pane/toolbar offsets when they are dragged.
2478 int wxAuiManager::GetDockPixelOffset(wxAuiPaneInfo
& test
)
2480 // the only way to accurately calculate the dock's
2481 // offset is to actually run a theoretical layout
2483 int i
, part_count
, dock_count
;
2484 wxAuiDockInfoArray docks
;
2485 wxAuiPaneInfoArray panes
;
2486 wxAuiDockUIPartArray uiparts
;
2487 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2490 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2491 wxSize client_size
= m_frame
->GetClientSize();
2492 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2495 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2497 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
2498 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2499 part
.sizer_item
->GetSize());
2500 if (part
.type
== wxAuiDockUIPart::typeDock
)
2501 part
.dock
->rect
= part
.rect
;
2506 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2508 wxAuiDockInfo
& dock
= docks
.Item(i
);
2509 if (test
.dock_direction
== dock
.dock_direction
&&
2510 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2512 if (dock
.IsVertical())
2524 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2525 // if a dock operation is allowed, the new dock position is copied into
2526 // the target info. If the operation was allowed, the function returns true.
2528 bool wxAuiManager::ProcessDockResult(wxAuiPaneInfo
& target
,
2529 const wxAuiPaneInfo
& new_pos
)
2531 bool allowed
= false;
2532 switch (new_pos
.dock_direction
)
2534 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2535 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2536 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2537 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2547 // DoDrop() is an important function. It basically takes a mouse position,
2548 // and determines where the pane's new position would be. If the pane is to be
2549 // dropped, it performs the drop operation using the specified dock and pane
2550 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2551 // scenario can be performed, giving precise coordinates for drop hints.
2552 // If, however, wxAuiManager:m_docks and wxAuiManager::m_panes are specified
2553 // as parameters, the changes will be made to the main state arrays
2555 const int auiInsertRowPixels
= 10;
2556 const int auiNewRowPixels
= 40;
2557 const int auiLayerInsertPixels
= 40;
2558 const int auiLayerInsertOffset
= 5;
2560 bool wxAuiManager::DoDrop(wxAuiDockInfoArray
& docks
,
2561 wxAuiPaneInfoArray
& panes
,
2562 wxAuiPaneInfo
& target
,
2564 const wxPoint
& offset
)
2566 wxSize cli_size
= m_frame
->GetClientSize();
2568 wxAuiPaneInfo drop
= target
;
2571 // The result should always be shown
2575 // Check to see if the pane has been dragged outside of the window
2576 // (or near to the outside of the window), if so, dock it along the edge
2579 int layer_insert_offset
= auiLayerInsertOffset
;
2580 if (target
.IsToolbar())
2581 layer_insert_offset
= 0;
2583 if (pt
.x
< layer_insert_offset
&&
2584 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2586 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2587 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2588 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2592 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2593 return ProcessDockResult(target
, drop
);
2595 else if (pt
.y
< layer_insert_offset
&&
2596 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2598 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2599 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2600 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2604 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2605 return ProcessDockResult(target
, drop
);
2607 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2608 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2610 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2611 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2612 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2614 drop
.Dock().Right().
2617 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2618 return ProcessDockResult(target
, drop
);
2620 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2621 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2623 int new_layer
= wxMax( wxMax( GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2624 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2625 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2627 drop
.Dock().Bottom().
2630 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2631 return ProcessDockResult(target
, drop
);
2634 wxAuiDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2637 if (drop
.IsToolbar())
2639 if (!part
|| !part
->dock
)
2642 // calculate the offset from where the dock begins
2643 // to the point where the user dropped the pane
2644 int dock_drop_offset
= 0;
2645 if (part
->dock
->IsHorizontal())
2646 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2648 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2651 // toolbars may only be moved in and to fixed-pane docks,
2652 // otherwise we will try to float the pane. Also, the pane
2653 // should float if being dragged over center pane windows
2654 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2656 if (m_last_rect
.IsEmpty() || m_last_rect
.Contains(pt
.x
, pt
.y
))
2662 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2663 (drop
.IsFloatable() ||
2664 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2665 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2672 return ProcessDockResult(target
, drop
);
2675 drop
.Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2677 return ProcessDockResult(target
, drop
);
2686 m_last_rect
= part
->dock
->rect
;
2687 m_last_rect
.Inflate( 15, 15 );
2691 Direction(part
->dock
->dock_direction
).
2692 Layer(part
->dock
->dock_layer
).
2693 Row(part
->dock
->dock_row
).
2694 Position(dock_drop_offset
);
2697 ((pt
.y
< part
->dock
->rect
.y
+ 1) && part
->dock
->IsHorizontal()) ||
2698 ((pt
.x
< part
->dock
->rect
.x
+ 1) && part
->dock
->IsVertical())
2699 ) && part
->dock
->panes
.GetCount() > 1)
2701 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2702 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2704 int row
= drop
.dock_row
;
2705 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2706 part
->dock
->dock_layer
,
2707 part
->dock
->dock_row
);
2708 drop
.dock_row
= row
;
2712 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2713 part
->dock
->dock_layer
,
2714 part
->dock
->dock_row
+1);
2715 drop
.dock_row
= part
->dock
->dock_row
+1;
2720 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2721 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2722 ) && part
->dock
->panes
.GetCount() > 1)
2724 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2725 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2727 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2728 part
->dock
->dock_layer
,
2729 part
->dock
->dock_row
+1);
2730 drop
.dock_row
= part
->dock
->dock_row
+1;
2734 int row
= drop
.dock_row
;
2735 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2736 part
->dock
->dock_layer
,
2737 part
->dock
->dock_row
);
2738 drop
.dock_row
= row
;
2742 return ProcessDockResult(target
, drop
);
2751 if (part
->type
== wxAuiDockUIPart::typePaneBorder
||
2752 part
->type
== wxAuiDockUIPart::typeCaption
||
2753 part
->type
== wxAuiDockUIPart::typeGripper
||
2754 part
->type
== wxAuiDockUIPart::typePaneButton
||
2755 part
->type
== wxAuiDockUIPart::typePane
||
2756 part
->type
== wxAuiDockUIPart::typePaneSizer
||
2757 part
->type
== wxAuiDockUIPart::typeDockSizer
||
2758 part
->type
== wxAuiDockUIPart::typeBackground
)
2760 if (part
->type
== wxAuiDockUIPart::typeDockSizer
)
2762 if (part
->dock
->panes
.GetCount() != 1)
2764 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2771 // If a normal frame is being dragged over a toolbar, insert it
2772 // along the edge under the toolbar, but over all other panes.
2773 // (this could be done much better, but somehow factoring this
2774 // calculation with the one at the beginning of this function)
2775 if (part
->dock
&& part
->dock
->toolbar
)
2779 switch (part
->dock
->dock_direction
)
2781 case wxAUI_DOCK_LEFT
:
2782 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2783 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2784 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2786 case wxAUI_DOCK_TOP
:
2787 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2788 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2789 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2791 case wxAUI_DOCK_RIGHT
:
2792 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2793 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2794 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2796 case wxAUI_DOCK_BOTTOM
:
2797 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2798 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2799 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2803 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2806 Direction(part
->dock
->dock_direction
).
2807 Layer(layer
).Row(0).Position(0);
2808 return ProcessDockResult(target
, drop
);
2815 part
= GetPanePart(part
->pane
->window
);
2819 bool insert_dock_row
= false;
2820 int insert_row
= part
->pane
->dock_row
;
2821 int insert_dir
= part
->pane
->dock_direction
;
2822 int insert_layer
= part
->pane
->dock_layer
;
2824 switch (part
->pane
->dock_direction
)
2826 case wxAUI_DOCK_TOP
:
2827 if (pt
.y
>= part
->rect
.y
&&
2828 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2829 insert_dock_row
= true;
2831 case wxAUI_DOCK_BOTTOM
:
2832 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2833 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2834 insert_dock_row
= true;
2836 case wxAUI_DOCK_LEFT
:
2837 if (pt
.x
>= part
->rect
.x
&&
2838 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2839 insert_dock_row
= true;
2841 case wxAUI_DOCK_RIGHT
:
2842 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2843 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2844 insert_dock_row
= true;
2846 case wxAUI_DOCK_CENTER
:
2848 // "new row pixels" will be set to the default, but
2849 // must never exceed 20% of the window size
2850 int new_row_pixels_x
= auiNewRowPixels
;
2851 int new_row_pixels_y
= auiNewRowPixels
;
2853 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2854 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2856 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2857 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2860 // determine if the mouse pointer is in a location that
2861 // will cause a new row to be inserted. The hot spot positions
2862 // are along the borders of the center pane
2865 insert_dock_row
= true;
2866 if (pt
.x
>= part
->rect
.x
&&
2867 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2868 insert_dir
= wxAUI_DOCK_LEFT
;
2870 if (pt
.y
>= part
->rect
.y
&&
2871 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2872 insert_dir
= wxAUI_DOCK_TOP
;
2874 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2875 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2876 insert_dir
= wxAUI_DOCK_RIGHT
;
2878 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2879 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2880 insert_dir
= wxAUI_DOCK_BOTTOM
;
2884 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2888 if (insert_dock_row
)
2890 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2891 drop
.Dock().Direction(insert_dir
).
2892 Layer(insert_layer
).
2895 return ProcessDockResult(target
, drop
);
2898 // determine the mouse offset and the pane size, both in the
2899 // direction of the dock itself, and perpendicular to the dock
2903 if (part
->orientation
== wxVERTICAL
)
2905 offset
= pt
.y
- part
->rect
.y
;
2906 size
= part
->rect
.GetHeight();
2910 offset
= pt
.x
- part
->rect
.x
;
2911 size
= part
->rect
.GetWidth();
2914 int drop_position
= part
->pane
->dock_pos
;
2916 // if we are in the top/left part of the pane,
2917 // insert the pane before the pane being hovered over
2918 if (offset
<= size
/2)
2920 drop_position
= part
->pane
->dock_pos
;
2922 part
->pane
->dock_direction
,
2923 part
->pane
->dock_layer
,
2924 part
->pane
->dock_row
,
2925 part
->pane
->dock_pos
);
2928 // if we are in the bottom/right part of the pane,
2929 // insert the pane before the pane being hovered over
2930 if (offset
> size
/2)
2932 drop_position
= part
->pane
->dock_pos
+1;
2934 part
->pane
->dock_direction
,
2935 part
->pane
->dock_layer
,
2936 part
->pane
->dock_row
,
2937 part
->pane
->dock_pos
+1);
2941 Direction(part
->dock
->dock_direction
).
2942 Layer(part
->dock
->dock_layer
).
2943 Row(part
->dock
->dock_row
).
2944 Position(drop_position
);
2945 return ProcessDockResult(target
, drop
);
2952 void wxAuiManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2954 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
2956 m_hint_fadetimer
.Stop();
2960 m_hint_fadeamt
+= 4;
2961 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2964 void wxAuiManager::ShowHint(const wxRect
& rect
)
2968 // if the hint rect is the same as last time, don't do anything
2969 if (m_last_hint
== rect
)
2973 m_hint_fadeamt
= m_hint_fademax
;
2975 if ((m_flags
& wxAUI_MGR_HINT_FADE
)
2976 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2977 (m_flags
& wxAUI_MGR_NO_VENETIAN_BLINDS_FADE
))
2981 m_hint_wnd
->SetSize(rect
);
2983 if (!m_hint_wnd
->IsShown())
2986 // if we are dragging a floating pane, set the focus
2987 // back to that floating pane (otherwise it becomes unfocused)
2988 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2989 m_action_window
->SetFocus();
2991 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2992 m_hint_wnd
->Raise();
2995 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
2997 // start fade in timer
2998 m_hint_fadetimer
.SetOwner(this, 101);
2999 m_hint_fadetimer
.Start(5);
3002 else // Not using a transparent hint window...
3004 if (!(m_flags
& wxAUI_MGR_RECTANGLE_HINT
))
3007 if (m_last_hint
!= rect
)
3009 // remove the last hint rectangle
3015 wxScreenDC screendc
;
3016 wxRegion
clip(1, 1, 10000, 10000);
3018 // clip all floating windows, so we don't draw over them
3020 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
3022 wxAuiPaneInfo
& pane
= m_panes
.Item(i
);
3024 if (pane
.IsFloating() &&
3025 pane
.frame
->IsShown())
3027 wxRect rect
= pane
.frame
->GetRect();
3029 // wxGTK returns the client size, not the whole frame size
3035 clip
.Subtract(rect
);
3039 // As we can only hide the hint by redrawing the managed window, we
3040 // need to clip the region to the managed window too or we get
3041 // nasty redrawn problems.
3042 clip
.Intersect(m_frame
->GetRect());
3044 screendc
.SetClippingRegion(clip
);
3046 wxBitmap stipple
= wxPaneCreateStippleBitmap();
3047 wxBrush
brush(stipple
);
3048 screendc
.SetBrush(brush
);
3049 screendc
.SetPen(*wxTRANSPARENT_PEN
);
3051 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
3052 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
3053 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
3054 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
3058 void wxAuiManager::HideHint()
3060 // hides a transparent window hint, if there is one
3063 if (m_hint_wnd
->IsShown())
3064 m_hint_wnd
->Show(false);
3065 m_hint_wnd
->SetTransparent(0);
3066 m_hint_fadetimer
.Stop();
3067 m_last_hint
= wxRect();
3071 // hides a painted hint by redrawing the frame window
3072 if (!m_last_hint
.IsEmpty())
3076 m_last_hint
= wxRect();
3082 void wxAuiManager::StartPaneDrag(wxWindow
* pane_window
,
3083 const wxPoint
& offset
)
3085 wxAuiPaneInfo
& pane
= GetPane(pane_window
);
3089 if (pane
.IsToolbar())
3091 m_action
= actionDragToolbarPane
;
3095 m_action
= actionDragFloatingPane
;
3098 m_action_window
= pane_window
;
3099 m_action_offset
= offset
;
3100 m_frame
->CaptureMouse();
3104 // CalculateHintRect() calculates the drop hint rectangle. The method
3105 // first calls DoDrop() to determine the exact position the pane would
3106 // be at were if dropped. If the pane would indeed become docked at the
3107 // specified drop point, the the rectangle hint will be returned in
3108 // screen coordinates. Otherwise, an empty rectangle is returned.
3109 // |pane_window| is the window pointer of the pane being dragged, |pt| is
3110 // the mouse position, in client coordinates. |offset| describes the offset
3111 // that the mouse is from the upper-left corner of the item being dragged
3113 wxRect
wxAuiManager::CalculateHintRect(wxWindow
* pane_window
,
3115 const wxPoint
& offset
)
3119 // we need to paint a hint rectangle; to find out the exact hint rectangle,
3120 // we will create a new temporary layout and then measure the resulting
3121 // rectangle; we will create a copy of the docking structures (m_dock)
3122 // so that we don't modify the real thing on screen
3124 int i
, pane_count
, part_count
;
3125 wxAuiDockInfoArray docks
;
3126 wxAuiPaneInfoArray panes
;
3127 wxAuiDockUIPartArray uiparts
;
3128 wxAuiPaneInfo hint
= GetPane(pane_window
);
3129 hint
.name
= wxT("__HINT__");
3135 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3137 // remove any pane already there which bears the same window;
3138 // this happens when you are moving a pane around in a dock
3139 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
3141 if (panes
.Item(i
).window
== pane_window
)
3143 RemovePaneFromDocks(docks
, panes
.Item(i
));
3149 // find out where the new pane would be
3150 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
3157 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
3158 wxSize client_size
= m_frame
->GetClientSize();
3159 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
3162 for (i
= 0, part_count
= uiparts
.GetCount();
3163 i
< part_count
; ++i
)
3165 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
3167 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
3168 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
3170 rect
= wxRect(part
.sizer_item
->GetPosition(),
3171 part
.sizer_item
->GetSize());
3183 // actually show the hint rectangle on the screen
3184 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
3189 // DrawHintRect() calculates the hint rectangle by calling
3190 // CalculateHintRect(). If there is a rectangle, it shows it
3191 // by calling ShowHint(), otherwise it hides any hint
3192 // rectangle currently shown
3193 void wxAuiManager::DrawHintRect(wxWindow
* pane_window
,
3195 const wxPoint
& offset
)
3197 wxRect rect
= CalculateHintRect(pane_window
, pt
, offset
);
3209 void wxAuiManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
3211 // try to find the pane
3212 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3213 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3215 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3216 pane
.frame
->SetTransparent(150);
3219 void wxAuiManager::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
3221 // try to find the pane
3222 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3223 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3225 wxPoint pt
= ::wxGetMousePosition();
3228 // Adapt pt to direction
3231 // move to pane's upper border
3233 pos
= wnd
->ClientToScreen( pos
);
3235 // and some more pixels for the title bar
3240 // move to pane's left border
3242 pos
= wnd
->ClientToScreen( pos
);
3247 // move to pane's right border
3248 wxPoint
pos( wnd
->GetSize().x
, 0 );
3249 pos
= wnd
->ClientToScreen( pos
);
3254 // move to pane's bottom border
3255 wxPoint
pos( 0, wnd
->GetSize().y
);
3256 pos
= wnd
->ClientToScreen( pos
);
3263 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3265 // calculate the offset from the upper left-hand corner
3266 // of the frame to the mouse pointer
3267 wxPoint frame_pos
= pane
.frame
->GetPosition();
3268 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3270 // no hint for toolbar floating windows
3271 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
3273 if (m_action
== actionDragFloatingPane
)
3275 wxAuiDockInfoArray docks
;
3276 wxAuiPaneInfoArray panes
;
3277 wxAuiDockUIPartArray uiparts
;
3278 wxAuiPaneInfo hint
= pane
;
3280 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3282 // find out where the new pane would be
3283 if (!DoDrop(docks
, panes
, hint
, client_pt
))
3285 if (hint
.IsFloating())
3289 m_action
= actionDragToolbarPane
;
3290 m_action_window
= pane
.window
;
3299 // if a key modifier is pressed while dragging the frame,
3300 // don't dock the window
3301 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
3308 DrawHintRect(wnd
, client_pt
, action_offset
);
3311 // this cleans up some screen artifacts that are caused on GTK because
3312 // we aren't getting the exact size of the window (see comment
3322 void wxAuiManager::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
3324 // try to find the pane
3325 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3326 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3328 wxPoint pt
= ::wxGetMousePosition();
3331 // Adapt pt to direction
3334 // move to pane's upper border
3336 pos
= wnd
->ClientToScreen( pos
);
3338 // and some more pixels for the title bar
3343 // move to pane's left border
3345 pos
= wnd
->ClientToScreen( pos
);
3350 // move to pane's right border
3351 wxPoint
pos( wnd
->GetSize().x
, 0 );
3352 pos
= wnd
->ClientToScreen( pos
);
3357 // move to pane's bottom border
3358 wxPoint
pos( 0, wnd
->GetSize().y
);
3359 pos
= wnd
->ClientToScreen( pos
);
3366 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3368 // calculate the offset from the upper left-hand corner
3369 // of the frame to the mouse pointer
3370 wxPoint frame_pos
= pane
.frame
->GetPosition();
3371 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3374 // if a key modifier is pressed while dragging the frame,
3375 // don't dock the window
3376 if (!wxGetKeyState(WXK_CONTROL
) && !wxGetKeyState(WXK_ALT
))
3378 // do the drop calculation
3379 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3382 // if the pane is still floating, update it's floating
3383 // position (that we store)
3384 if (pane
.IsFloating())
3386 pane
.floating_pos
= pane
.frame
->GetPosition();
3388 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3389 pane
.frame
->SetTransparent(255);
3391 else if (m_has_maximized
)
3393 RestoreMaximizedPane();
3401 void wxAuiManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3403 // try to find the pane
3404 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3405 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3407 pane
.floating_size
= size
;
3411 void wxAuiManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3413 // try to find the pane
3414 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3415 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3418 // fire pane close event
3419 wxAuiManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3421 e
.SetCanVeto(evt
.CanVeto());
3437 void wxAuiManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3439 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3441 // try to find the pane
3442 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
3444 SetActivePane(m_panes
, wnd
);
3449 // OnRender() draws all of the pane captions, sashes,
3450 // backgrounds, captions, grippers, pane borders and buttons.
3451 // It renders the entire user interface.
3453 void wxAuiManager::OnRender(wxAuiManagerEvent
& evt
)
3455 wxDC
* dc
= evt
.GetDC();
3461 for (i
= 0, part_count
= m_uiparts
.GetCount();
3462 i
< part_count
; ++i
)
3464 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
3466 // don't draw hidden pane items
3467 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
3472 case wxAuiDockUIPart::typeDockSizer
:
3473 case wxAuiDockUIPart::typePaneSizer
:
3474 m_art
->DrawSash(*dc
, m_frame
, part
.orientation
, part
.rect
);
3476 case wxAuiDockUIPart::typeBackground
:
3477 m_art
->DrawBackground(*dc
, m_frame
, part
.orientation
, part
.rect
);
3479 case wxAuiDockUIPart::typeCaption
:
3480 m_art
->DrawCaption(*dc
, m_frame
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3482 case wxAuiDockUIPart::typeGripper
:
3483 m_art
->DrawGripper(*dc
, m_frame
, part
.rect
, *part
.pane
);
3485 case wxAuiDockUIPart::typePaneBorder
:
3486 m_art
->DrawBorder(*dc
, m_frame
, part
.rect
, *part
.pane
);
3488 case wxAuiDockUIPart::typePaneButton
:
3489 m_art
->DrawPaneButton(*dc
, m_frame
, part
.button
->button_id
,
3490 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3497 // Render() fire a render event, which is normally handled by
3498 // wxAuiManager::OnRender(). This allows the render function to
3499 // be overridden via the render event. This can be useful for paintin
3500 // custom graphics in the main window. Default behavior can be
3501 // invoked in the overridden function by calling OnRender()
3503 void wxAuiManager::Render(wxDC
* dc
)
3505 wxAuiManagerEvent
e(wxEVT_AUI_RENDER
);
3511 void wxAuiManager::Repaint(wxDC
* dc
)
3516 m_frame
->Refresh() ;
3522 m_frame
->GetClientSize(&w
, &h
);
3524 // figure out which dc to use; if one
3525 // has been specified, use it, otherwise
3527 wxClientDC
* client_dc
= NULL
;
3530 client_dc
= new wxClientDC(m_frame
);
3534 // if the frame has a toolbar, the client area
3535 // origin will not be (0,0).
3536 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3537 if (pt
.x
!= 0 || pt
.y
!= 0)
3538 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3540 // render all the items
3543 // if we created a client_dc, delete it
3548 void wxAuiManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3550 wxPaintDC
dc(m_frame
);
3554 void wxAuiManager::OnEraseBackground(wxEraseEvent
& event
)
3563 void wxAuiManager::OnSize(wxSizeEvent
& event
)
3571 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
3573 // for MDI parent frames, this event must not
3574 // be "skipped". In other words, the parent frame
3575 // must not be allowed to resize the client window
3576 // after we are finished processing sizing changes
3584 void wxAuiManager::OnFindManager(wxAuiManagerEvent
& evt
)
3586 // get the window we are managing, if none, return NULL
3587 wxWindow
* window
= GetManagedWindow();
3590 evt
.SetManager(NULL
);
3594 // if we are managing a child frame, get the 'real' manager
3595 if (window
->IsKindOf(CLASSINFO(wxAuiFloatingFrame
)))
3597 wxAuiFloatingFrame
* float_frame
= static_cast<wxAuiFloatingFrame
*>(window
);
3598 evt
.SetManager(float_frame
->GetOwnerManager());
3602 // return pointer to ourself
3603 evt
.SetManager(this);
3606 void wxAuiManager::OnSetCursor(wxSetCursorEvent
& event
)
3609 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3610 wxCursor cursor
= wxNullCursor
;
3614 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3615 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3617 // a dock may not be resized if it has a single
3618 // pane which is not resizable
3619 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3620 part
->dock
->panes
.GetCount() == 1 &&
3621 part
->dock
->panes
.Item(0)->IsFixed())
3624 // panes that may not be resized do not get a sizing cursor
3625 if (part
->pane
&& part
->pane
->IsFixed())
3628 if (part
->orientation
== wxVERTICAL
)
3629 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3631 cursor
= wxCursor(wxCURSOR_SIZENS
);
3633 else if (part
->type
== wxAuiDockUIPart::typeGripper
)
3635 cursor
= wxCursor(wxCURSOR_SIZING
);
3639 event
.SetCursor(cursor
);
3644 void wxAuiManager::UpdateButtonOnScreen(wxAuiDockUIPart
* button_ui_part
,
3645 const wxMouseEvent
& event
)
3647 wxAuiDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3648 if (!hit_test
|| !button_ui_part
)
3651 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3653 if (hit_test
== button_ui_part
)
3655 if (event
.LeftDown())
3656 state
= wxAUI_BUTTON_STATE_PRESSED
;
3658 state
= wxAUI_BUTTON_STATE_HOVER
;
3662 if (event
.LeftDown())
3663 state
= wxAUI_BUTTON_STATE_HOVER
;
3666 // now repaint the button with hover state
3667 wxClientDC
cdc(m_frame
);
3669 // if the frame has a toolbar, the client area
3670 // origin will not be (0,0).
3671 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3672 if (pt
.x
!= 0 || pt
.y
!= 0)
3673 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3677 m_art
->DrawPaneButton(cdc
, m_frame
,
3678 button_ui_part
->button
->button_id
,
3680 button_ui_part
->rect
,
3685 void wxAuiManager::OnLeftDown(wxMouseEvent
& event
)
3687 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3690 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3691 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3693 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3696 // a dock may not be resized if it has a single
3697 // pane which is not resizable
3698 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3699 part
->dock
->panes
.GetCount() == 1 &&
3700 part
->dock
->panes
.Item(0)->IsFixed())
3703 // panes that may not be resized should be ignored here
3704 if (part
->pane
&& part
->pane
->IsFixed())
3707 m_action
= actionResize
;
3708 m_action_part
= part
;
3709 m_action_hintrect
= wxRect();
3710 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3711 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3712 event
.m_y
- part
->rect
.y
);
3713 m_frame
->CaptureMouse();
3715 else if (part
->type
== wxAuiDockUIPart::typePaneButton
)
3717 m_action
= actionClickButton
;
3718 m_action_part
= part
;
3719 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3720 m_frame
->CaptureMouse();
3722 UpdateButtonOnScreen(part
, event
);
3724 else if (part
->type
== wxAuiDockUIPart::typeCaption
||
3725 part
->type
== wxAuiDockUIPart::typeGripper
)
3727 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3730 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3732 // set the caption as active
3733 SetActivePane(m_panes
, part
->pane
->window
);
3737 m_action
= actionClickCaption
;
3738 m_action_part
= part
;
3739 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3740 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3741 event
.m_y
- part
->rect
.y
);
3742 m_frame
->CaptureMouse();
3762 void wxAuiManager::OnLeftUp(wxMouseEvent
& event
)
3764 if (m_action
== actionResize
)
3766 m_frame
->ReleaseMouse();
3768 // get rid of the hint rectangle
3770 DrawResizeHint(dc
, m_action_hintrect
);
3772 // resize the dock or the pane
3773 if (m_action_part
&& m_action_part
->type
==wxAuiDockUIPart::typeDockSizer
)
3775 wxRect
& rect
= m_action_part
->dock
->rect
;
3777 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3778 event
.m_y
- m_action_offset
.y
);
3780 switch (m_action_part
->dock
->dock_direction
)
3782 case wxAUI_DOCK_LEFT
:
3783 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3785 case wxAUI_DOCK_TOP
:
3786 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3788 case wxAUI_DOCK_RIGHT
:
3789 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3790 new_pos
.x
- m_action_part
->rect
.GetWidth();
3792 case wxAUI_DOCK_BOTTOM
:
3793 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3794 new_pos
.y
- m_action_part
->rect
.GetHeight();
3801 else if (m_action_part
&&
3802 m_action_part
->type
== wxAuiDockUIPart::typePaneSizer
)
3804 wxAuiDockInfo
& dock
= *m_action_part
->dock
;
3805 wxAuiPaneInfo
& pane
= *m_action_part
->pane
;
3807 int total_proportion
= 0;
3808 int dock_pixels
= 0;
3809 int new_pixsize
= 0;
3811 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
3812 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
3813 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
3815 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3816 event
.m_y
- m_action_offset
.y
);
3818 // determine the pane rectangle by getting the pane part
3819 wxAuiDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3820 wxASSERT_MSG(pane_part
,
3821 wxT("Pane border part not found -- shouldn't happen"));
3823 // determine the new pixel size that the user wants;
3824 // this will help us recalculate the pane's proportion
3825 if (dock
.IsHorizontal())
3826 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3828 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3830 // determine the size of the dock, based on orientation
3831 if (dock
.IsHorizontal())
3832 dock_pixels
= dock
.rect
.GetWidth();
3834 dock_pixels
= dock
.rect
.GetHeight();
3836 // determine the total proportion of all resizable panes,
3837 // and the total size of the dock minus the size of all
3839 int i
, dock_pane_count
= dock
.panes
.GetCount();
3840 int pane_position
= -1;
3841 for (i
= 0; i
< dock_pane_count
; ++i
)
3843 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
3844 if (p
.window
== pane
.window
)
3847 // while we're at it, subtract the pane sash
3848 // width from the dock width, because this would
3849 // skew our proportion calculations
3851 dock_pixels
-= sash_size
;
3853 // also, the whole size (including decorations) of
3854 // all fixed panes must also be subtracted, because they
3855 // are not part of the proportion calculation
3858 if (dock
.IsHorizontal())
3859 dock_pixels
-= p
.best_size
.x
;
3861 dock_pixels
-= p
.best_size
.y
;
3865 total_proportion
+= p
.dock_proportion
;
3869 // find a pane in our dock to 'steal' space from or to 'give'
3870 // space to -- this is essentially what is done when a pane is
3871 // resized; the pane should usually be the first non-fixed pane
3872 // to the right of the action pane
3873 int borrow_pane
= -1;
3874 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3876 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
3885 // demand that the pane being resized is found in this dock
3886 // (this assert really never should be raised)
3887 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3889 // prevent division by zero
3890 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3892 m_action
= actionNone
;
3896 // calculate the new proportion of the pane
3897 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3899 // default minimum size
3902 // check against the pane's minimum size, if specified. please note
3903 // that this is not enough to ensure that the minimum size will
3904 // not be violated, because the whole frame might later be shrunk,
3905 // causing the size of the pane to violate it's minimum size
3906 if (pane
.min_size
.IsFullySpecified())
3910 if (pane
.HasBorder())
3911 min_size
+= (pane_border_size
*2);
3913 // calculate minimum size with decorations (border,caption)
3914 if (pane_part
->orientation
== wxVERTICAL
)
3916 min_size
+= pane
.min_size
.y
;
3917 if (pane
.HasCaption())
3918 min_size
+= caption_size
;
3922 min_size
+= pane
.min_size
.x
;
3927 // for some reason, an arithmatic error somewhere is causing
3928 // the proportion calculations to always be off by 1 pixel;
3929 // for now we will add the 1 pixel on, but we really should
3930 // determine what's causing this.
3933 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3935 if (new_proportion
< min_proportion
)
3936 new_proportion
= min_proportion
;
3940 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3942 // borrow the space from our neighbor pane to the
3943 // right or bottom (depending on orientation)
3944 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3945 pane
.dock_proportion
= new_proportion
;
3952 else if (m_action
== actionClickButton
)
3954 m_hover_button
= NULL
;
3955 m_frame
->ReleaseMouse();
3956 UpdateButtonOnScreen(m_action_part
, event
);
3958 // make sure we're still over the item that was originally clicked
3959 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3961 // fire button-click event
3962 wxAuiManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3964 e
.SetPane(m_action_part
->pane
);
3965 e
.SetButton(m_action_part
->button
->button_id
);
3969 else if (m_action
== actionClickCaption
)
3971 m_frame
->ReleaseMouse();
3973 else if (m_action
== actionDragFloatingPane
)
3975 m_frame
->ReleaseMouse();
3977 else if (m_action
== actionDragToolbarPane
)
3979 m_frame
->ReleaseMouse();
3981 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
3982 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3984 // save the new positions
3985 wxAuiDockInfoPtrArray docks
;
3986 FindDocks(m_docks
, pane
.dock_direction
,
3987 pane
.dock_layer
, pane
.dock_row
, docks
);
3988 if (docks
.GetCount() == 1)
3990 wxAuiDockInfo
& dock
= *docks
.Item(0);
3992 wxArrayInt pane_positions
, pane_sizes
;
3993 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3995 int i
, dock_pane_count
= dock
.panes
.GetCount();
3996 for (i
= 0; i
< dock_pane_count
; ++i
)
3997 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
4000 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
4008 m_action
= actionNone
;
4009 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
4013 void wxAuiManager::OnMotion(wxMouseEvent
& event
)
4015 // sometimes when Update() is called from inside this method,
4016 // a spurious mouse move event is generated; this check will make
4017 // sure that only real mouse moves will get anywhere in this method;
4018 // this appears to be a bug somewhere, and I don't know where the
4019 // mouse move event is being generated. only verified on MSW
4021 wxPoint mouse_pos
= event
.GetPosition();
4022 if (m_last_mouse_move
== mouse_pos
)
4024 m_last_mouse_move
= mouse_pos
;
4027 if (m_action
== actionResize
)
4029 wxPoint pos
= m_action_part
->rect
.GetPosition();
4030 if (m_action_part
->orientation
== wxHORIZONTAL
)
4031 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
4033 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
4035 wxRect
rect(m_frame
->ClientToScreen(pos
),
4036 m_action_part
->rect
.GetSize());
4039 if (!m_action_hintrect
.IsEmpty())
4040 DrawResizeHint(dc
, m_action_hintrect
);
4041 DrawResizeHint(dc
, rect
);
4042 m_action_hintrect
= rect
;
4044 else if (m_action
== actionClickCaption
)
4046 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
4047 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
4049 // caption has been clicked. we need to check if the mouse
4050 // is now being dragged. if it is, we need to change the
4051 // mouse action to 'drag'
4052 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
4053 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
4055 wxAuiPaneInfo
* pane_info
= m_action_part
->pane
;
4057 if (!pane_info
->IsToolbar())
4059 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
4060 pane_info
->IsFloatable())
4062 m_action
= actionDragFloatingPane
;
4064 // set initial float position
4065 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4066 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4067 pt
.y
- m_action_offset
.y
);
4070 if (pane_info
->IsMaximized())
4071 RestorePane(*pane_info
);
4075 m_action_window
= pane_info
->frame
;
4077 // action offset is used here to make it feel "natural" to the user
4078 // to drag a docked pane and suddenly have it become a floating frame.
4079 // Sometimes, however, the offset where the user clicked on the docked
4080 // caption is bigger than the width of the floating frame itself, so
4081 // in that case we need to set the action offset to a sensible value
4082 wxSize frame_size
= m_action_window
->GetSize();
4083 if (frame_size
.x
<= m_action_offset
.x
)
4084 m_action_offset
.x
= 30;
4089 m_action
= actionDragToolbarPane
;
4090 m_action_window
= pane_info
->window
;
4094 else if (m_action
== actionDragFloatingPane
)
4096 if(m_action_window
) {
4097 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4098 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
4099 pt
.y
- m_action_offset
.y
);
4102 else if (m_action
== actionDragToolbarPane
)
4104 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4105 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4107 pane
.state
|= wxAuiPaneInfo::actionPane
;
4109 wxPoint pt
= event
.GetPosition();
4110 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
4112 // if DoDrop() decided to float the pane, set up
4113 // the floating pane's initial position
4114 if (pane
.IsFloating())
4116 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4117 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4118 pt
.y
- m_action_offset
.y
);
4121 // this will do the actiual move operation;
4122 // in the case that the pane has been floated,
4123 // this call will create the floating pane
4124 // and do the reparenting
4127 // if the pane has been floated, change the mouse
4128 // action actionDragFloatingPane so that subsequent
4129 // EVT_MOTION() events will move the floating pane
4130 if (pane
.IsFloating())
4132 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
4133 m_action
= actionDragFloatingPane
;
4134 m_action_window
= pane
.frame
;
4139 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
4140 if (part
&& part
->type
== wxAuiDockUIPart::typePaneButton
)
4142 if (part
!= m_hover_button
)
4144 // make the old button normal
4147 UpdateButtonOnScreen(m_hover_button
, event
);
4151 // mouse is over a button, so repaint the
4152 // button in hover mode
4153 UpdateButtonOnScreen(part
, event
);
4154 m_hover_button
= part
;
4162 m_hover_button
= NULL
;
4173 void wxAuiManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
4177 m_hover_button
= NULL
;
4182 void wxAuiManager::OnChildFocus(wxChildFocusEvent
& event
)
4184 // when a child pane has it's focus set, we should change the
4185 // pane's active state to reflect this. (this is only true if
4186 // active panes are allowed by the owner)
4187 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
4189 if (GetPane(event
.GetWindow()).IsOk())
4191 SetActivePane(m_panes
, event
.GetWindow());
4200 // OnPaneButton() is an event handler that is called
4201 // when a pane button has been pressed.
4202 void wxAuiManager::OnPaneButton(wxAuiManagerEvent
& evt
)
4204 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxAuiManager::OnPaneButton must be non-null"));
4206 wxAuiPaneInfo
& pane
= *(evt
.pane
);
4208 if (evt
.button
== wxAUI_BUTTON_CLOSE
)
4210 // fire pane close event
4211 wxAuiManagerEvent
e(wxEVT_AUI_PANECLOSE
);
4213 e
.SetPane(evt
.pane
);
4222 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& !pane
.IsMaximized())
4224 // fire pane close event
4225 wxAuiManagerEvent
e(wxEVT_AUI_PANEMAXIMIZE
);
4227 e
.SetPane(evt
.pane
);
4236 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& pane
.IsMaximized())
4238 // fire pane close event
4239 wxAuiManagerEvent
e(wxEVT_AUI_PANERESTORE
);
4241 e
.SetPane(evt
.pane
);
4250 else if (evt
.button
== wxAUI_BUTTON_PIN
)
4252 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&