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
.ResumePropagation(wxEVENT_PROPAGATE_MAX
);
649 if (!window
->ProcessEvent(evt
))
652 return evt
.GetManager();
656 void wxAuiManager::UpdateHintWindowConfig()
658 // find out if the the system can do transparent frames
659 bool can_do_transparent
= false;
661 wxWindow
* w
= m_frame
;
664 if (w
->IsKindOf(CLASSINFO(wxFrame
)))
666 wxFrame
* f
= static_cast<wxFrame
*>(w
);
667 can_do_transparent
= f
->CanSetTransparent();
674 // if there is an existing hint window, delete it
677 m_hint_wnd
->Destroy();
684 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) && can_do_transparent
)
686 // Make a window to use for a transparent hint
687 #if defined(__WXMSW__) || defined(__WXGTK__)
688 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
,
689 wxDefaultPosition
, wxSize(1,1),
690 wxFRAME_TOOL_WINDOW
|
691 wxFRAME_FLOAT_ON_PARENT
|
695 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
696 #elif defined(__WXMAC__)
697 // Using a miniframe with float and tool styles keeps the parent
698 // frame activated and highlighted as such...
699 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
,
700 wxDefaultPosition
, wxSize(1,1),
701 wxFRAME_FLOAT_ON_PARENT
702 | wxFRAME_TOOL_WINDOW
);
704 // Can't set the bg colour of a Frame in wxMac
705 wxPanel
* p
= new wxPanel(m_hint_wnd
);
707 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
708 // color that is really hard to see, especially transparent.
709 // Until a better system color is decided upon we'll just use
711 p
->SetBackgroundColour(*wxBLUE
);
717 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 ||
718 (m_flags
& wxAUI_MGR_VENETIAN_BLINDS_HINT
) != 0)
720 // system can't support transparent fade, or the venetian
721 // blinds effect was explicitly requested
722 m_hint_wnd
= new wxPseudoTransparentFrame(m_frame
,
727 wxFRAME_TOOL_WINDOW
|
728 wxFRAME_FLOAT_ON_PARENT
|
731 m_hint_fademax
= 128;
737 // SetManagedWindow() is usually called once when the frame
738 // manager class is being initialized. "frame" specifies
739 // the frame which should be managed by the frame mananger
740 void wxAuiManager::SetManagedWindow(wxWindow
* wnd
)
742 wxASSERT_MSG(wnd
, wxT("specified window must be non-NULL"));
745 m_frame
->PushEventHandler(this);
748 // if the owner is going to manage an MDI parent frame,
749 // we need to add the MDI client window as the default
752 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
754 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)m_frame
;
755 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
757 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
759 AddPane(client_window
,
760 wxAuiPaneInfo().Name(wxT("mdiclient")).
761 CenterPane().PaneBorder(false));
765 UpdateHintWindowConfig();
769 // UnInit() must be called, usually in the destructor
770 // of the frame class. If it is not called, usually this
771 // will result in a crash upon program exit
772 void wxAuiManager::UnInit()
776 m_frame
->RemoveEventHandler(this);
780 // GetManagedWindow() returns the window pointer being managed
781 wxWindow
* wxAuiManager::GetManagedWindow() const
786 wxAuiDockArt
* wxAuiManager::GetArtProvider() const
791 void wxAuiManager::ProcessMgrEvent(wxAuiManagerEvent
& event
)
793 // first, give the owner frame a chance to override
796 if (m_frame
->ProcessEvent(event
))
803 // SetArtProvider() instructs wxAuiManager to use the
804 // specified art provider for all drawing calls. This allows
805 // plugable look-and-feel features. The pointer that is
806 // passed to this method subsequently belongs to wxAuiManager,
807 // and is deleted in the frame manager destructor
808 void wxAuiManager::SetArtProvider(wxAuiDockArt
* art_provider
)
810 // delete the last art provider, if any
813 // assign the new art provider
814 m_art
= art_provider
;
818 bool wxAuiManager::AddPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
)
820 // check if the pane has a valid window
824 // check if the pane already exists
825 if (GetPane(pane_info
.window
).IsOk())
828 // if the new pane is docked then we should undo maximize
829 if(pane_info
.IsDocked())
830 RestoreMaximizedPane();
832 m_panes
.Add(pane_info
);
834 wxAuiPaneInfo
& pinfo
= m_panes
.Last();
836 // set the pane window
837 pinfo
.window
= window
;
839 // if the pane's name identifier is blank, create a random string
840 if (pinfo
.name
.empty())
842 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
843 ((unsigned long)pinfo
.window
) & 0xffffffff,
844 (unsigned int)time(NULL
),
846 (unsigned int)GetTickCount(),
848 (unsigned int)clock(),
850 (unsigned long)m_panes
.GetCount());
853 // set initial proportion (if not already set)
854 if (pinfo
.dock_proportion
== 0)
855 pinfo
.dock_proportion
= 100000;
857 if (pinfo
.HasMaximizeButton())
859 wxAuiPaneButton button
;
860 button
.button_id
= wxAUI_BUTTON_MAXIMIZE_RESTORE
;
861 pinfo
.buttons
.Add(button
);
864 if (pinfo
.HasPinButton())
866 wxAuiPaneButton button
;
867 button
.button_id
= wxAUI_BUTTON_PIN
;
868 pinfo
.buttons
.Add(button
);
871 if (pinfo
.HasCloseButton())
873 wxAuiPaneButton button
;
874 button
.button_id
= wxAUI_BUTTON_CLOSE
;
875 pinfo
.buttons
.Add(button
);
878 if (pinfo
.best_size
== wxDefaultSize
&&
881 pinfo
.best_size
= pinfo
.window
->GetClientSize();
883 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
885 // GetClientSize() doesn't get the best size for
886 // a toolbar under some newer versions of wxWidgets,
887 // so use GetBestSize()
888 pinfo
.best_size
= pinfo
.window
->GetBestSize();
890 // for some reason, wxToolBar::GetBestSize() is returning
891 // a size that is a pixel shy of the correct amount.
892 // I believe this to be the correct action, until
893 // wxToolBar::GetBestSize() is fixed. Is this assumption
898 if (pinfo
.min_size
!= wxDefaultSize
)
900 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
901 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
902 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
903 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
910 bool wxAuiManager::AddPane(wxWindow
* window
,
912 const wxString
& caption
)
915 pinfo
.Caption(caption
);
918 case wxTOP
: pinfo
.Top(); break;
919 case wxBOTTOM
: pinfo
.Bottom(); break;
920 case wxLEFT
: pinfo
.Left(); break;
921 case wxRIGHT
: pinfo
.Right(); break;
922 case wxCENTER
: pinfo
.CenterPane(); break;
924 return AddPane(window
, pinfo
);
927 bool wxAuiManager::AddPane(wxWindow
* window
,
928 const wxAuiPaneInfo
& pane_info
,
929 const wxPoint
& drop_pos
)
931 if (!AddPane(window
, pane_info
))
934 wxAuiPaneInfo
& pane
= GetPane(window
);
936 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
941 bool wxAuiManager::InsertPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
,
944 // shift the panes around, depending on the insert level
945 switch (insert_level
)
947 case wxAUI_INSERT_PANE
:
948 DoInsertPane(m_panes
,
949 pane_info
.dock_direction
,
950 pane_info
.dock_layer
,
954 case wxAUI_INSERT_ROW
:
955 DoInsertDockRow(m_panes
,
956 pane_info
.dock_direction
,
957 pane_info
.dock_layer
,
960 case wxAUI_INSERT_DOCK
:
961 DoInsertDockLayer(m_panes
,
962 pane_info
.dock_direction
,
963 pane_info
.dock_layer
);
967 // if the window already exists, we are basically just moving/inserting the
968 // existing window. If it doesn't exist, we need to add it and insert it
969 wxAuiPaneInfo
& existing_pane
= GetPane(window
);
970 if (!existing_pane
.IsOk())
972 return AddPane(window
, pane_info
);
976 if (pane_info
.IsFloating())
978 existing_pane
.Float();
979 if (pane_info
.floating_pos
!= wxDefaultPosition
)
980 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
981 if (pane_info
.floating_size
!= wxDefaultSize
)
982 existing_pane
.FloatingSize(pane_info
.floating_size
);
986 // if the new pane is docked then we should undo maximize
987 RestoreMaximizedPane();
989 existing_pane
.Direction(pane_info
.dock_direction
);
990 existing_pane
.Layer(pane_info
.dock_layer
);
991 existing_pane
.Row(pane_info
.dock_row
);
992 existing_pane
.Position(pane_info
.dock_pos
);
1000 // DetachPane() removes a pane from the frame manager. This
1001 // method will not destroy the window that is removed.
1002 bool wxAuiManager::DetachPane(wxWindow
* window
)
1005 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
1007 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1008 if (p
.window
== window
)
1012 // we have a floating frame which is being detached. We need to
1013 // reparent it to m_frame and destroy the floating frame
1016 p
.window
->SetSize(1,1);
1018 if (p
.frame
->IsShown())
1019 p
.frame
->Show(false);
1021 // reparent to m_frame and destroy the pane
1022 if(m_action_window
== p
.frame
)
1024 m_action_window
= NULL
;
1027 p
.window
->Reparent(m_frame
);
1028 p
.frame
->SetSizer(NULL
);
1033 // make sure there are no references to this pane in our uiparts,
1034 // just in case the caller doesn't call Update() immediately after
1035 // the DetachPane() call. This prevets obscure crashes which would
1036 // happen at window repaint if the caller forgets to call Update()
1038 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
1040 wxAuiDockUIPart
& part
= m_uiparts
.Item(pi
);
1041 if (part
.pane
== &p
)
1043 m_uiparts
.RemoveAt(pi
);
1050 m_panes
.RemoveAt(i
);
1057 // ClosePane() destroys or hides the pane depending on its
1059 void wxAuiManager::ClosePane(wxAuiPaneInfo
& pane_info
)
1061 // if we were maximized, restore
1062 if (pane_info
.IsMaximized())
1064 RestorePane(pane_info
);
1067 // first, hide the window
1068 if (pane_info
.window
&& pane_info
.window
->IsShown())
1070 pane_info
.window
->Show(false);
1073 // make sure that we are the parent of this window
1074 if (pane_info
.window
&& pane_info
.window
->GetParent() != m_frame
)
1076 pane_info
.window
->Reparent(m_frame
);
1079 // if we have a frame, destroy it
1080 if (pane_info
.frame
)
1082 pane_info
.frame
->Destroy();
1083 pane_info
.frame
= NULL
;
1086 // now we need to either destroy or hide the pane
1087 if (pane_info
.IsDestroyOnClose())
1089 wxWindow
* window
= pane_info
.window
;
1102 void wxAuiManager::MaximizePane(wxAuiPaneInfo
& pane_info
)
1106 // un-maximize and hide all other panes
1107 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1109 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1118 // mark ourselves maximized
1119 pane_info
.Maximize();
1121 m_has_maximized
= true;
1123 // last, show the window
1124 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1126 pane_info
.window
->Show(true);
1130 void wxAuiManager::RestorePane(wxAuiPaneInfo
& pane_info
)
1134 // restore all the panes
1135 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1137 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1144 // mark ourselves non-maximized
1145 pane_info
.Restore();
1146 m_has_maximized
= false;
1148 // last, show the window
1149 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1151 pane_info
.window
->Show(true);
1155 void wxAuiManager::RestoreMaximizedPane()
1159 // restore all the panes
1160 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1162 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1171 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
1172 // in the input string. This is an internal functions which is
1173 // used for saving perspectives
1174 static wxString
EscapeDelimiters(const wxString
& s
)
1177 result
.Alloc(s
.length());
1178 const wxChar
* ch
= s
.c_str();
1181 if (*ch
== wxT(';') || *ch
== wxT('|'))
1182 result
+= wxT('\\');
1189 wxString
wxAuiManager::SavePaneInfo(wxAuiPaneInfo
& pane
)
1191 wxString result
= wxT("name=");
1192 result
+= EscapeDelimiters(pane
.name
);
1195 result
+= wxT("caption=");
1196 result
+= EscapeDelimiters(pane
.caption
);
1199 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
1200 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
1201 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
1202 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
1203 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
1204 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
1205 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
1206 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
1207 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
1208 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
1209 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
1210 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
1211 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
1212 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
1213 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
1214 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
1219 // Load a "pane" with the pane infor settings in pane_part
1220 void wxAuiManager::LoadPaneInfo(wxString pane_part
, wxAuiPaneInfo
&pane
)
1222 // replace escaped characters so we can
1223 // split up the string easily
1224 pane_part
.Replace(wxT("\\|"), wxT("\a"));
1225 pane_part
.Replace(wxT("\\;"), wxT("\b"));
1229 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
1230 pane_part
= pane_part
.AfterFirst(wxT(';'));
1231 wxString val_name
= val_part
.BeforeFirst(wxT('='));
1232 wxString value
= val_part
.AfterFirst(wxT('='));
1233 val_name
.MakeLower();
1234 val_name
.Trim(true);
1235 val_name
.Trim(false);
1239 if (val_name
.empty())
1242 if (val_name
== wxT("name"))
1244 else if (val_name
== wxT("caption"))
1245 pane
.caption
= value
;
1246 else if (val_name
== wxT("state"))
1247 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1248 else if (val_name
== wxT("dir"))
1249 pane
.dock_direction
= wxAtoi(value
.c_str());
1250 else if (val_name
== wxT("layer"))
1251 pane
.dock_layer
= wxAtoi(value
.c_str());
1252 else if (val_name
== wxT("row"))
1253 pane
.dock_row
= wxAtoi(value
.c_str());
1254 else if (val_name
== wxT("pos"))
1255 pane
.dock_pos
= wxAtoi(value
.c_str());
1256 else if (val_name
== wxT("prop"))
1257 pane
.dock_proportion
= wxAtoi(value
.c_str());
1258 else if (val_name
== wxT("bestw"))
1259 pane
.best_size
.x
= wxAtoi(value
.c_str());
1260 else if (val_name
== wxT("besth"))
1261 pane
.best_size
.y
= wxAtoi(value
.c_str());
1262 else if (val_name
== wxT("minw"))
1263 pane
.min_size
.x
= wxAtoi(value
.c_str());
1264 else if (val_name
== wxT("minh"))
1265 pane
.min_size
.y
= wxAtoi(value
.c_str());
1266 else if (val_name
== wxT("maxw"))
1267 pane
.max_size
.x
= wxAtoi(value
.c_str());
1268 else if (val_name
== wxT("maxh"))
1269 pane
.max_size
.y
= wxAtoi(value
.c_str());
1270 else if (val_name
== wxT("floatx"))
1271 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1272 else if (val_name
== wxT("floaty"))
1273 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1274 else if (val_name
== wxT("floatw"))
1275 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1276 else if (val_name
== wxT("floath"))
1277 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1279 wxFAIL_MSG(wxT("Bad Perspective String"));
1283 // replace escaped characters so we can
1284 // split up the string easily
1285 pane
.name
.Replace(wxT("\a"), wxT("|"));
1286 pane
.name
.Replace(wxT("\b"), wxT(";"));
1287 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1288 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1289 pane_part
.Replace(wxT("\a"), wxT("|"));
1290 pane_part
.Replace(wxT("\b"), wxT(";"));
1296 // SavePerspective() saves all pane information as a single string.
1297 // This string may later be fed into LoadPerspective() to restore
1298 // all pane settings. This save and load mechanism allows an
1299 // exact pane configuration to be saved and restored at a later time
1301 wxString
wxAuiManager::SavePerspective()
1305 result
= wxT("layout1|");
1307 int pane_i
, pane_count
= m_panes
.GetCount();
1308 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1310 wxAuiPaneInfo
& pane
= m_panes
.Item(pane_i
);
1311 result
+= SavePaneInfo(pane
)+wxT("|");
1314 int dock_i
, dock_count
= m_docks
.GetCount();
1315 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1317 wxAuiDockInfo
& dock
= m_docks
.Item(dock_i
);
1319 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1320 dock
.dock_direction
, dock
.dock_layer
,
1321 dock
.dock_row
, dock
.size
);
1327 // LoadPerspective() loads a layout which was saved with SavePerspective()
1328 // If the "update" flag parameter is true, the GUI will immediately be updated
1330 bool wxAuiManager::LoadPerspective(const wxString
& layout
, bool update
)
1332 wxString input
= layout
;
1335 // check layout string version
1336 part
= input
.BeforeFirst(wxT('|'));
1337 input
= input
.AfterFirst(wxT('|'));
1340 if (part
!= wxT("layout1"))
1343 // mark all panes currently managed as docked and hidden
1344 int pane_i
, pane_count
= m_panes
.GetCount();
1345 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1346 m_panes
.Item(pane_i
).Dock().Hide();
1348 // clear out the dock array; this will be reconstructed
1351 // replace escaped characters so we can
1352 // split up the string easily
1353 input
.Replace(wxT("\\|"), wxT("\a"));
1354 input
.Replace(wxT("\\;"), wxT("\b"));
1360 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1361 input
= input
.AfterFirst(wxT('|'));
1362 pane_part
.Trim(true);
1364 // if the string is empty, we're done parsing
1365 if (pane_part
.empty())
1368 if (pane_part
.Left(9) == wxT("dock_size"))
1370 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1371 wxString value
= pane_part
.AfterFirst(wxT('='));
1373 long dir
, layer
, row
, size
;
1374 wxString piece
= val_name
.AfterFirst(wxT('('));
1375 piece
= piece
.BeforeLast(wxT(')'));
1376 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1377 piece
= piece
.AfterFirst(wxT(','));
1378 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1379 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1380 value
.ToLong(&size
);
1383 dock
.dock_direction
= dir
;
1384 dock
.dock_layer
= layer
;
1385 dock
.dock_row
= row
;
1391 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1392 // name so it can be called by external callers
1393 pane_part
.Replace(wxT("\a"), wxT("|"));
1394 pane_part
.Replace(wxT("\b"), wxT(";"));
1396 LoadPaneInfo(pane_part
, pane
);
1398 wxAuiPaneInfo
& p
= GetPane(pane
.name
);
1401 // the pane window couldn't be found
1402 // in the existing layout
1416 void wxAuiManager::GetPanePositionsAndSizes(wxAuiDockInfo
& dock
,
1417 wxArrayInt
& positions
,
1420 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1421 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1422 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1427 int offset
, action_pane
= -1;
1428 int pane_i
, pane_count
= dock
.panes
.GetCount();
1430 // find the pane marked as our action pane
1431 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1433 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1435 if (pane
.state
& wxAuiPaneInfo::actionPane
)
1437 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1438 action_pane
= pane_i
;
1442 // set up each panes default position, and
1443 // determine the size (width or height, depending
1444 // on the dock's orientation) of each pane
1445 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1447 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1448 positions
.Add(pane
.dock_pos
);
1451 if (pane
.HasBorder())
1452 size
+= (pane_border_size
*2);
1454 if (dock
.IsHorizontal())
1456 if (pane
.HasGripper() && !pane
.HasGripperTop())
1457 size
+= gripper_size
;
1458 size
+= pane
.best_size
.x
;
1462 if (pane
.HasGripper() && pane
.HasGripperTop())
1463 size
+= gripper_size
;
1465 if (pane
.HasCaption())
1466 size
+= caption_size
;
1467 size
+= pane
.best_size
.y
;
1473 // if there is no action pane, just return the default
1474 // positions (as specified in pane.pane_pos)
1475 if (action_pane
== -1)
1479 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1481 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1486 positions
[pane_i
] -= -amount
;
1488 offset
+= sizes
[pane_i
];
1491 // if the dock mode is fixed, make sure none of the panes
1492 // overlap; we will bump panes that overlap
1494 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1496 int amount
= positions
[pane_i
] - offset
;
1500 positions
[pane_i
] += -amount
;
1502 offset
+= sizes
[pane_i
];
1507 void wxAuiManager::LayoutAddPane(wxSizer
* cont
,
1508 wxAuiDockInfo
& dock
,
1509 wxAuiPaneInfo
& pane
,
1510 wxAuiDockUIPartArray
& uiparts
,
1513 wxAuiDockUIPart part
;
1514 wxSizerItem
* sizer_item
;
1516 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1517 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1518 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1519 int pane_button_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BUTTON_SIZE
);
1521 // find out the orientation of the item (orientation for panes
1522 // is the same as the dock's orientation)
1524 if (dock
.IsHorizontal())
1525 orientation
= wxHORIZONTAL
;
1527 orientation
= wxVERTICAL
;
1529 // this variable will store the proportion
1530 // value that the pane will receive
1531 int pane_proportion
= pane
.dock_proportion
;
1533 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1534 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1536 if (pane
.HasGripper())
1538 if (pane
.HasGripperTop())
1539 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1541 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1543 part
.type
= wxAuiDockUIPart::typeGripper
;
1547 part
.orientation
= orientation
;
1548 part
.cont_sizer
= horz_pane_sizer
;
1549 part
.sizer_item
= sizer_item
;
1553 if (pane
.HasCaption())
1555 // create the caption sizer
1556 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1558 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1560 part
.type
= wxAuiDockUIPart::typeCaption
;
1564 part
.orientation
= orientation
;
1565 part
.cont_sizer
= vert_pane_sizer
;
1566 part
.sizer_item
= sizer_item
;
1567 int caption_part_idx
= uiparts
.GetCount();
1570 // add pane buttons to the caption
1571 int i
, button_count
;
1572 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1573 i
< button_count
; ++i
)
1575 wxAuiPaneButton
& button
= pane
.buttons
.Item(i
);
1577 sizer_item
= caption_sizer
->Add(pane_button_size
,
1581 part
.type
= wxAuiDockUIPart::typePaneButton
;
1584 part
.button
= &button
;
1585 part
.orientation
= orientation
;
1586 part
.cont_sizer
= caption_sizer
;
1587 part
.sizer_item
= sizer_item
;
1591 // if we have buttons, add a little space to the right
1592 // of them to ease visual crowding
1593 if (button_count
>= 1)
1595 caption_sizer
->Add(3,1);
1598 // add the caption sizer
1599 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1601 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1604 // add the pane window itself
1607 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1611 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1612 // Don't do this because it breaks the pane size in floating windows
1613 // BIW: Right now commenting this out is causing problems with
1614 // an mdi client window as the center pane.
1615 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1618 part
.type
= wxAuiDockUIPart::typePane
;
1622 part
.orientation
= orientation
;
1623 part
.cont_sizer
= vert_pane_sizer
;
1624 part
.sizer_item
= sizer_item
;
1628 // determine if the pane should have a minimum size; if the pane is
1629 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1630 // if the pane.min_size is set, we must use that value as well
1632 wxSize min_size
= pane
.min_size
;
1635 if (min_size
== wxDefaultSize
)
1637 min_size
= pane
.best_size
;
1638 pane_proportion
= 0;
1642 if (min_size
!= wxDefaultSize
)
1644 vert_pane_sizer
->SetItemMinSize(
1645 vert_pane_sizer
->GetChildren().GetCount()-1,
1646 min_size
.x
, min_size
.y
);
1650 // add the verticle sizer (caption, pane window) to the
1651 // horizontal sizer (gripper, verticle sizer)
1652 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1654 // finally, add the pane sizer to the dock sizer
1656 if (pane
.HasBorder())
1658 // allowing space for the pane's border
1659 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1660 wxEXPAND
| wxALL
, pane_border_size
);
1662 part
.type
= wxAuiDockUIPart::typePaneBorder
;
1666 part
.orientation
= orientation
;
1667 part
.cont_sizer
= cont
;
1668 part
.sizer_item
= sizer_item
;
1673 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1677 void wxAuiManager::LayoutAddDock(wxSizer
* cont
,
1678 wxAuiDockInfo
& dock
,
1679 wxAuiDockUIPartArray
& uiparts
,
1682 wxSizerItem
* sizer_item
;
1683 wxAuiDockUIPart part
;
1685 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
1686 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1688 // resizable bottom and right docks have a sash before them
1689 if (!m_has_maximized
&& !dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1690 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1692 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1694 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1695 part
.orientation
= orientation
;
1699 part
.cont_sizer
= cont
;
1700 part
.sizer_item
= sizer_item
;
1704 // create the sizer for the dock
1705 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1707 // add each pane to the dock
1708 bool has_maximized_pane
= false;
1709 int pane_i
, pane_count
= dock
.panes
.GetCount();
1713 wxArrayInt pane_positions
, pane_sizes
;
1715 // figure out the real pane positions we will
1716 // use, without modifying the each pane's pane_pos member
1717 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1720 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1722 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1723 int pane_pos
= pane_positions
.Item(pane_i
);
1724 if(pane
.IsMaximized()) {
1725 has_maximized_pane
= true;
1728 int amount
= pane_pos
- offset
;
1731 if (dock
.IsVertical())
1732 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1734 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1736 part
.type
= wxAuiDockUIPart::typeBackground
;
1740 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1741 part
.cont_sizer
= dock_sizer
;
1742 part
.sizer_item
= sizer_item
;
1748 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1750 offset
+= pane_sizes
.Item(pane_i
);
1753 // at the end add a very small stretchable background area
1754 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1756 part
.type
= wxAuiDockUIPart::typeBackground
;
1760 part
.orientation
= orientation
;
1761 part
.cont_sizer
= dock_sizer
;
1762 part
.sizer_item
= sizer_item
;
1767 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1769 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1770 if(pane
.IsMaximized()) {
1771 has_maximized_pane
= true;
1774 // if this is not the first pane being added,
1775 // we need to add a pane sizer
1776 if (!m_has_maximized
&& pane_i
> 0)
1778 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1780 part
.type
= wxAuiDockUIPart::typePaneSizer
;
1782 part
.pane
= dock
.panes
.Item(pane_i
-1);
1784 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1785 part
.cont_sizer
= dock_sizer
;
1786 part
.sizer_item
= sizer_item
;
1790 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1794 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
|| has_maximized_pane
)
1795 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1797 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1799 part
.type
= wxAuiDockUIPart::typeDock
;
1803 part
.orientation
= orientation
;
1804 part
.cont_sizer
= cont
;
1805 part
.sizer_item
= sizer_item
;
1808 if (dock
.IsHorizontal())
1809 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1811 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1813 // top and left docks have a sash after them
1814 if (!m_has_maximized
&& !dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1815 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1817 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1819 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1823 part
.orientation
= orientation
;
1824 part
.cont_sizer
= cont
;
1825 part
.sizer_item
= sizer_item
;
1830 wxSizer
* wxAuiManager::LayoutAll(wxAuiPaneInfoArray
& panes
,
1831 wxAuiDockInfoArray
& docks
,
1832 wxAuiDockUIPartArray
& uiparts
,
1835 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1837 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1838 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1839 wxSize cli_size
= m_frame
->GetClientSize();
1840 int i
, dock_count
, pane_count
;
1843 // empty all docks out
1844 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1845 docks
.Item(i
).panes
.Empty();
1848 // iterate through all known panes, filing each
1849 // of them into the appropriate dock. If the
1850 // pane does not exist in the dock, add it
1851 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1853 wxAuiPaneInfo
& p
= panes
.Item(i
);
1855 // find any docks in this layer
1856 wxAuiDockInfo
* dock
;
1857 wxAuiDockInfoPtrArray arr
;
1858 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1860 if (arr
.GetCount() > 0)
1866 // dock was not found, so we need to create a new one
1868 d
.dock_direction
= p
.dock_direction
;
1869 d
.dock_layer
= p
.dock_layer
;
1870 d
.dock_row
= p
.dock_row
;
1872 dock
= &docks
.Last();
1876 if (p
.IsDocked() && p
.IsShown())
1878 // remove the pane from any existing docks except this one
1879 RemovePaneFromDocks(docks
, p
, dock
);
1881 // pane needs to be added to the dock,
1882 // if it doesn't already exist
1883 if (!FindPaneInDock(*dock
, p
.window
))
1884 dock
->panes
.Add(&p
);
1888 // remove the pane from any existing docks
1889 RemovePaneFromDocks(docks
, p
);
1894 // remove any empty docks
1895 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1897 if (docks
.Item(i
).panes
.GetCount() == 0)
1901 // configure the docks further
1902 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1904 wxAuiDockInfo
& dock
= docks
.Item(i
);
1905 int j
, dock_pane_count
= dock
.panes
.GetCount();
1907 // sort the dock pane array by the pane's
1908 // dock position (dock_pos), in ascending order
1909 dock
.panes
.Sort(PaneSortFunc
);
1911 // for newly created docks, set up their initial size
1916 for (j
= 0; j
< dock_pane_count
; ++j
)
1918 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
1919 wxSize pane_size
= pane
.best_size
;
1920 if (pane_size
== wxDefaultSize
)
1921 pane_size
= pane
.min_size
;
1922 if (pane_size
== wxDefaultSize
)
1923 pane_size
= pane
.window
->GetSize();
1925 if (dock
.IsHorizontal())
1926 size
= wxMax(pane_size
.y
, size
);
1928 size
= wxMax(pane_size
.x
, size
);
1931 // add space for the border (two times), but only
1932 // if at least one pane inside the dock has a pane border
1933 for (j
= 0; j
< dock_pane_count
; ++j
)
1935 if (dock
.panes
.Item(j
)->HasBorder())
1937 size
+= (pane_border_size
*2);
1942 // if pane is on the top or bottom, add the caption height,
1943 // but only if at least one pane inside the dock has a caption
1944 if (dock
.IsHorizontal())
1946 for (j
= 0; j
< dock_pane_count
; ++j
)
1948 if (dock
.panes
.Item(j
)->HasCaption())
1950 size
+= caption_size
;
1956 if (!(m_flags
& wxAUI_MGR_NO_DOCK_SIZE_LIMIT
))
1958 // new dock's size may not be more than 1/3 of the frame size
1959 if (dock
.IsHorizontal())
1960 size
= wxMin(size
, cli_size
.y
/3);
1962 size
= wxMin(size
, cli_size
.x
/3);
1971 // determine the dock's minimum size
1972 bool plus_border
= false;
1973 bool plus_caption
= false;
1974 int dock_min_size
= 0;
1975 for (j
= 0; j
< dock_pane_count
; ++j
)
1977 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
1978 if (pane
.min_size
!= wxDefaultSize
)
1980 if (pane
.HasBorder())
1982 if (pane
.HasCaption())
1983 plus_caption
= true;
1984 if (dock
.IsHorizontal())
1986 if (pane
.min_size
.y
> dock_min_size
)
1987 dock_min_size
= pane
.min_size
.y
;
1991 if (pane
.min_size
.x
> dock_min_size
)
1992 dock_min_size
= pane
.min_size
.x
;
1998 dock_min_size
+= (pane_border_size
*2);
1999 if (plus_caption
&& dock
.IsHorizontal())
2000 dock_min_size
+= (caption_size
);
2002 dock
.min_size
= dock_min_size
;
2005 // if the pane's current size is less than it's
2006 // minimum, increase the dock's size to it's minimum
2007 if (dock
.size
< dock
.min_size
)
2008 dock
.size
= dock
.min_size
;
2011 // determine the dock's mode (fixed or proportional);
2012 // determine whether the dock has only toolbars
2013 bool action_pane_marked
= false;
2015 dock
.toolbar
= true;
2016 for (j
= 0; j
< dock_pane_count
; ++j
)
2018 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2019 if (!pane
.IsFixed())
2021 if (!pane
.IsToolbar())
2022 dock
.toolbar
= false;
2023 if (pane
.state
& wxAuiPaneInfo::actionPane
)
2024 action_pane_marked
= true;
2028 // if the dock mode is proportional and not fixed-pixel,
2029 // reassign the dock_pos to the sequential 0, 1, 2, 3;
2030 // e.g. remove gaps like 1, 2, 30, 500
2033 for (j
= 0; j
< dock_pane_count
; ++j
)
2035 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2040 // if the dock mode is fixed, and none of the panes
2041 // are being moved right now, make sure the panes
2042 // do not overlap each other. If they do, we will
2043 // adjust the panes' positions
2044 if (dock
.fixed
&& !action_pane_marked
)
2046 wxArrayInt pane_positions
, pane_sizes
;
2047 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
2050 for (j
= 0; j
< dock_pane_count
; ++j
)
2052 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(j
));
2053 pane
.dock_pos
= pane_positions
[j
];
2055 int amount
= pane
.dock_pos
- offset
;
2059 pane
.dock_pos
+= -amount
;
2061 offset
+= pane_sizes
[j
];
2066 // discover the maximum dock layer
2068 for (i
= 0; i
< dock_count
; ++i
)
2069 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
2072 // clear out uiparts
2075 // create a bunch of box sizers,
2076 // from the innermost level outwards.
2077 wxSizer
* cont
= NULL
;
2078 wxSizer
* middle
= NULL
;
2082 for (layer
= 0; layer
<= max_layer
; ++layer
)
2084 wxAuiDockInfoPtrArray arr
;
2086 // find any docks in this layer
2087 FindDocks(docks
, -1, layer
, -1, arr
);
2089 // if there aren't any, skip to the next layer
2093 wxSizer
* old_cont
= cont
;
2095 // create a container which will hold this layer's
2096 // docks (top, bottom, left, right)
2097 cont
= new wxBoxSizer(wxVERTICAL
);
2100 // find any top docks in this layer
2101 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
2102 RenumberDockRows(arr
);
2105 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2106 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2110 // fill out the middle layer (which consists
2111 // of left docks, content area and right docks)
2113 middle
= new wxBoxSizer(wxHORIZONTAL
);
2115 // find any left docks in this layer
2116 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
2117 RenumberDockRows(arr
);
2120 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2121 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2124 // add content dock (or previous layer's sizer
2128 // find any center docks
2129 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
2132 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
2133 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2135 else if (!m_has_maximized
)
2137 // there are no center docks, add a background area
2138 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
2139 wxAuiDockUIPart part
;
2140 part
.type
= wxAuiDockUIPart::typeBackground
;
2144 part
.cont_sizer
= middle
;
2145 part
.sizer_item
= sizer_item
;
2151 middle
->Add(old_cont
, 1, wxEXPAND
);
2154 // find any right docks in this layer
2155 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
2156 RenumberDockRows(arr
);
2159 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2160 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2163 cont
->Add(middle
, 1, wxEXPAND
);
2167 // find any bottom docks in this layer
2168 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
2169 RenumberDockRows(arr
);
2172 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2173 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2180 // no sizer available, because there are no docks,
2181 // therefore we will create a simple background area
2182 cont
= new wxBoxSizer(wxVERTICAL
);
2183 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
2184 wxAuiDockUIPart part
;
2185 part
.type
= wxAuiDockUIPart::typeBackground
;
2189 part
.cont_sizer
= middle
;
2190 part
.sizer_item
= sizer_item
;
2194 container
->Add(cont
, 1, wxEXPAND
);
2199 // Update() updates the layout. Whenever changes are made to
2200 // one or more panes, this function should be called. It is the
2201 // external entry point for running the layout engine.
2203 void wxAuiManager::Update()
2206 int i
, pane_count
= m_panes
.GetCount();
2209 // destroy floating panes which have been
2210 // redocked or are becoming non-floating
2211 for (i
= 0; i
< pane_count
; ++i
)
2213 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2215 if (!p
.IsFloating() && p
.frame
)
2217 // because the pane is no longer in a floating, we need to
2218 // reparent it to m_frame and destroy the floating frame
2221 p
.window
->SetSize(1,1);
2224 // the following block is a workaround for bug #1531361
2225 // (see wxWidgets sourceforge page). On wxGTK (only), when
2226 // a frame is shown/hidden, a move event unfortunately
2227 // also gets fired. Because we may be dragging around
2228 // a pane, we need to cancel that action here to prevent
2229 // a spurious crash.
2230 if (m_action_window
== p
.frame
)
2232 if (wxWindow::GetCapture() == m_frame
)
2233 m_frame
->ReleaseMouse();
2234 m_action
= actionNone
;
2235 m_action_window
= NULL
;
2239 if (p
.frame
->IsShown())
2240 p
.frame
->Show(false);
2242 // reparent to m_frame and destroy the pane
2243 if(m_action_window
== p
.frame
)
2245 m_action_window
= NULL
;
2248 p
.window
->Reparent(m_frame
);
2249 p
.frame
->SetSizer(NULL
);
2256 // delete old sizer first
2257 m_frame
->SetSizer(NULL
);
2259 // create a layout for all of the panes
2260 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
2262 // hide or show panes as necessary,
2263 // and float panes as necessary
2264 for (i
= 0; i
< pane_count
; ++i
)
2266 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2270 if (p
.frame
== NULL
)
2272 // we need to create a frame for this
2273 // pane, which has recently been floated
2274 wxAuiFloatingFrame
* frame
= CreateFloatingFrame(m_frame
, p
);
2276 // on MSW and Mac, if the owner desires transparent dragging, and
2277 // the dragging is happening right now, then the floating
2278 // window should have this style by default
2279 if (m_action
== actionDragFloatingPane
&&
2280 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2281 frame
->SetTransparent(150);
2283 frame
->SetPaneWindow(p
);
2286 if (p
.IsShown() && !frame
->IsShown())
2291 // frame already exists, make sure it's position
2292 // and size reflect the information in wxAuiPaneInfo
2293 if (p
.frame
->GetPosition() != p
.floating_pos
)
2295 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2296 wxDefaultCoord
, wxDefaultCoord
,
2297 wxSIZE_USE_EXISTING
);
2298 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2301 if (p
.frame
->IsShown() != p
.IsShown())
2302 p
.frame
->Show(p
.IsShown());
2307 if (p
.window
->IsShown() != p
.IsShown())
2308 p
.window
->Show(p
.IsShown());
2311 // if "active panes" are no longer allowed, clear
2312 // any optionActive values from the pane states
2313 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2315 p
.state
&= ~wxAuiPaneInfo::optionActive
;
2320 // keep track of the old window rectangles so we can
2321 // refresh those windows whose rect has changed
2322 wxAuiRectArray old_pane_rects
;
2323 for (i
= 0; i
< pane_count
; ++i
)
2326 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2328 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2331 old_pane_rects
.Add(r
);
2337 // apply the new sizer
2338 m_frame
->SetSizer(sizer
);
2339 m_frame
->SetAutoLayout(false);
2344 // now that the frame layout is done, we need to check
2345 // the new pane rectangles against the old rectangles that
2346 // we saved a few lines above here. If the rectangles have
2347 // changed, the corresponding panes must also be updated
2348 for (i
= 0; i
< pane_count
; ++i
)
2350 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2351 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2353 if (p
.rect
!= old_pane_rects
[i
])
2355 p
.window
->Refresh();
2364 // set frame's minimum size
2367 // N.B. More work needs to be done on frame minimum sizes;
2368 // this is some intresting code that imposes the minimum size,
2369 // but we may want to include a more flexible mechanism or
2370 // options for multiple minimum-size modes, e.g. strict or lax
2371 wxSize min_size = sizer->GetMinSize();
2372 wxSize frame_size = m_frame->GetSize();
2373 wxSize client_size = m_frame->GetClientSize();
2375 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2376 min_size.y+frame_size.y-client_size.y );
2378 m_frame->SetMinSize(minframe_size);
2380 if (frame_size.x < minframe_size.x ||
2381 frame_size.y < minframe_size.y)
2382 sizer->Fit(m_frame);
2387 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2388 // on the frame's main sizer, then measures all the various UI items
2389 // and updates their internal rectangles. This should always be called
2390 // instead of calling m_frame->Layout() directly
2392 void wxAuiManager::DoFrameLayout()
2397 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2399 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2401 // get the rectangle of the UI part
2402 // originally, this code looked like this:
2403 // part.rect = wxRect(part.sizer_item->GetPosition(),
2404 // part.sizer_item->GetSize());
2405 // this worked quite well, with one exception: the mdi
2406 // client window had a "deferred" size variable
2407 // that returned the wrong size. It looks like
2408 // a bug in wx, because the former size of the window
2409 // was being returned. So, we will retrieve the part's
2410 // rectangle via other means
2413 part
.rect
= part
.sizer_item
->GetRect();
2414 int flag
= part
.sizer_item
->GetFlag();
2415 int border
= part
.sizer_item
->GetBorder();
2418 part
.rect
.y
-= border
;
2419 part
.rect
.height
+= border
;
2423 part
.rect
.x
-= border
;
2424 part
.rect
.width
+= border
;
2426 if (flag
& wxBOTTOM
)
2427 part
.rect
.height
+= border
;
2429 part
.rect
.width
+= border
;
2432 if (part
.type
== wxAuiDockUIPart::typeDock
)
2433 part
.dock
->rect
= part
.rect
;
2434 if (part
.type
== wxAuiDockUIPart::typePane
)
2435 part
.pane
->rect
= part
.rect
;
2439 // GetPanePart() looks up the pane the pane border UI part (or the regular
2440 // pane part if there is no border). This allows the caller to get the exact
2441 // rectangle of the pane in question, including decorations like
2442 // caption and border (if any).
2444 wxAuiDockUIPart
* wxAuiManager::GetPanePart(wxWindow
* wnd
)
2447 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2449 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2450 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
2451 part
.pane
&& part
.pane
->window
== wnd
)
2454 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2456 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2457 if (part
.type
== wxAuiDockUIPart::typePane
&&
2458 part
.pane
&& part
.pane
->window
== wnd
)
2466 // GetDockPixelOffset() is an internal function which returns
2467 // a dock's offset in pixels from the left side of the window
2468 // (for horizontal docks) or from the top of the window (for
2469 // vertical docks). This value is necessary for calculating
2470 // fixel-pane/toolbar offsets when they are dragged.
2472 int wxAuiManager::GetDockPixelOffset(wxAuiPaneInfo
& test
)
2474 // the only way to accurately calculate the dock's
2475 // offset is to actually run a theoretical layout
2477 int i
, part_count
, dock_count
;
2478 wxAuiDockInfoArray docks
;
2479 wxAuiPaneInfoArray panes
;
2480 wxAuiDockUIPartArray uiparts
;
2481 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2484 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2485 wxSize client_size
= m_frame
->GetClientSize();
2486 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2489 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2491 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
2492 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2493 part
.sizer_item
->GetSize());
2494 if (part
.type
== wxAuiDockUIPart::typeDock
)
2495 part
.dock
->rect
= part
.rect
;
2500 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2502 wxAuiDockInfo
& dock
= docks
.Item(i
);
2503 if (test
.dock_direction
== dock
.dock_direction
&&
2504 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2506 if (dock
.IsVertical())
2518 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2519 // if a dock operation is allowed, the new dock position is copied into
2520 // the target info. If the operation was allowed, the function returns true.
2522 bool wxAuiManager::ProcessDockResult(wxAuiPaneInfo
& target
,
2523 const wxAuiPaneInfo
& new_pos
)
2525 bool allowed
= false;
2526 switch (new_pos
.dock_direction
)
2528 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2529 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2530 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2531 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2541 // DoDrop() is an important function. It basically takes a mouse position,
2542 // and determines where the pane's new position would be. If the pane is to be
2543 // dropped, it performs the drop operation using the specified dock and pane
2544 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2545 // scenario can be performed, giving precise coordinates for drop hints.
2546 // If, however, wxAuiManager:m_docks and wxAuiManager::m_panes are specified
2547 // as parameters, the changes will be made to the main state arrays
2549 const int auiInsertRowPixels
= 10;
2550 const int auiNewRowPixels
= 40;
2551 const int auiLayerInsertPixels
= 40;
2552 const int auiLayerInsertOffset
= 5;
2554 bool wxAuiManager::DoDrop(wxAuiDockInfoArray
& docks
,
2555 wxAuiPaneInfoArray
& panes
,
2556 wxAuiPaneInfo
& target
,
2558 const wxPoint
& offset
)
2560 wxSize cli_size
= m_frame
->GetClientSize();
2562 wxAuiPaneInfo drop
= target
;
2565 // The result should always be shown
2569 // Check to see if the pane has been dragged outside of the window
2570 // (or near to the outside of the window), if so, dock it along the edge
2573 int layer_insert_offset
= auiLayerInsertOffset
;
2574 if (target
.IsToolbar())
2575 layer_insert_offset
= 0;
2577 if (pt
.x
< layer_insert_offset
&&
2578 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2580 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2581 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2582 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2586 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2587 return ProcessDockResult(target
, drop
);
2589 else if (pt
.y
< layer_insert_offset
&&
2590 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2592 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2593 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2594 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2598 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2599 return ProcessDockResult(target
, drop
);
2601 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2602 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2604 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2605 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2606 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2608 drop
.Dock().Right().
2611 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2612 return ProcessDockResult(target
, drop
);
2614 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2615 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2617 int new_layer
= wxMax( wxMax( GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2618 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2619 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2621 drop
.Dock().Bottom().
2624 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2625 return ProcessDockResult(target
, drop
);
2628 wxAuiDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2631 if (drop
.IsToolbar())
2633 if (!part
|| !part
->dock
)
2636 // calculate the offset from where the dock begins
2637 // to the point where the user dropped the pane
2638 int dock_drop_offset
= 0;
2639 if (part
->dock
->IsHorizontal())
2640 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2642 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2645 // toolbars may only be moved in and to fixed-pane docks,
2646 // otherwise we will try to float the pane. Also, the pane
2647 // should float if being dragged over center pane windows
2648 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2650 if (m_last_rect
.IsEmpty() || m_last_rect
.Contains(pt
.x
, pt
.y
))
2656 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2657 (drop
.IsFloatable() ||
2658 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2659 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2666 return ProcessDockResult(target
, drop
);
2669 drop
.Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2671 return ProcessDockResult(target
, drop
);
2680 m_last_rect
= part
->dock
->rect
;
2681 m_last_rect
.Inflate( 15, 15 );
2685 Direction(part
->dock
->dock_direction
).
2686 Layer(part
->dock
->dock_layer
).
2687 Row(part
->dock
->dock_row
).
2688 Position(dock_drop_offset
);
2691 ((pt
.y
< part
->dock
->rect
.y
+ 1) && part
->dock
->IsHorizontal()) ||
2692 ((pt
.x
< part
->dock
->rect
.x
+ 1) && part
->dock
->IsVertical())
2693 ) && part
->dock
->panes
.GetCount() > 1)
2695 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2696 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2698 int row
= drop
.dock_row
;
2699 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2700 part
->dock
->dock_layer
,
2701 part
->dock
->dock_row
);
2702 drop
.dock_row
= row
;
2706 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2707 part
->dock
->dock_layer
,
2708 part
->dock
->dock_row
+1);
2709 drop
.dock_row
= part
->dock
->dock_row
+1;
2714 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2715 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2716 ) && part
->dock
->panes
.GetCount() > 1)
2718 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2719 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2721 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2722 part
->dock
->dock_layer
,
2723 part
->dock
->dock_row
+1);
2724 drop
.dock_row
= part
->dock
->dock_row
+1;
2728 int row
= drop
.dock_row
;
2729 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2730 part
->dock
->dock_layer
,
2731 part
->dock
->dock_row
);
2732 drop
.dock_row
= row
;
2736 return ProcessDockResult(target
, drop
);
2745 if (part
->type
== wxAuiDockUIPart::typePaneBorder
||
2746 part
->type
== wxAuiDockUIPart::typeCaption
||
2747 part
->type
== wxAuiDockUIPart::typeGripper
||
2748 part
->type
== wxAuiDockUIPart::typePaneButton
||
2749 part
->type
== wxAuiDockUIPart::typePane
||
2750 part
->type
== wxAuiDockUIPart::typePaneSizer
||
2751 part
->type
== wxAuiDockUIPart::typeDockSizer
||
2752 part
->type
== wxAuiDockUIPart::typeBackground
)
2754 if (part
->type
== wxAuiDockUIPart::typeDockSizer
)
2756 if (part
->dock
->panes
.GetCount() != 1)
2758 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2765 // If a normal frame is being dragged over a toolbar, insert it
2766 // along the edge under the toolbar, but over all other panes.
2767 // (this could be done much better, but somehow factoring this
2768 // calculation with the one at the beginning of this function)
2769 if (part
->dock
&& part
->dock
->toolbar
)
2773 switch (part
->dock
->dock_direction
)
2775 case wxAUI_DOCK_LEFT
:
2776 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2777 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2778 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2780 case wxAUI_DOCK_TOP
:
2781 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2782 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2783 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2785 case wxAUI_DOCK_RIGHT
:
2786 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2787 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2788 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2790 case wxAUI_DOCK_BOTTOM
:
2791 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2792 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2793 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2797 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2800 Direction(part
->dock
->dock_direction
).
2801 Layer(layer
).Row(0).Position(0);
2802 return ProcessDockResult(target
, drop
);
2809 part
= GetPanePart(part
->pane
->window
);
2813 bool insert_dock_row
= false;
2814 int insert_row
= part
->pane
->dock_row
;
2815 int insert_dir
= part
->pane
->dock_direction
;
2816 int insert_layer
= part
->pane
->dock_layer
;
2818 switch (part
->pane
->dock_direction
)
2820 case wxAUI_DOCK_TOP
:
2821 if (pt
.y
>= part
->rect
.y
&&
2822 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2823 insert_dock_row
= true;
2825 case wxAUI_DOCK_BOTTOM
:
2826 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2827 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2828 insert_dock_row
= true;
2830 case wxAUI_DOCK_LEFT
:
2831 if (pt
.x
>= part
->rect
.x
&&
2832 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2833 insert_dock_row
= true;
2835 case wxAUI_DOCK_RIGHT
:
2836 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2837 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2838 insert_dock_row
= true;
2840 case wxAUI_DOCK_CENTER
:
2842 // "new row pixels" will be set to the default, but
2843 // must never exceed 20% of the window size
2844 int new_row_pixels_x
= auiNewRowPixels
;
2845 int new_row_pixels_y
= auiNewRowPixels
;
2847 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2848 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2850 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2851 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2854 // determine if the mouse pointer is in a location that
2855 // will cause a new row to be inserted. The hot spot positions
2856 // are along the borders of the center pane
2859 insert_dock_row
= true;
2860 if (pt
.x
>= part
->rect
.x
&&
2861 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2862 insert_dir
= wxAUI_DOCK_LEFT
;
2864 if (pt
.y
>= part
->rect
.y
&&
2865 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2866 insert_dir
= wxAUI_DOCK_TOP
;
2868 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2869 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2870 insert_dir
= wxAUI_DOCK_RIGHT
;
2872 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2873 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2874 insert_dir
= wxAUI_DOCK_BOTTOM
;
2878 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2882 if (insert_dock_row
)
2884 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2885 drop
.Dock().Direction(insert_dir
).
2886 Layer(insert_layer
).
2889 return ProcessDockResult(target
, drop
);
2892 // determine the mouse offset and the pane size, both in the
2893 // direction of the dock itself, and perpendicular to the dock
2897 if (part
->orientation
== wxVERTICAL
)
2899 offset
= pt
.y
- part
->rect
.y
;
2900 size
= part
->rect
.GetHeight();
2904 offset
= pt
.x
- part
->rect
.x
;
2905 size
= part
->rect
.GetWidth();
2908 int drop_position
= part
->pane
->dock_pos
;
2910 // if we are in the top/left part of the pane,
2911 // insert the pane before the pane being hovered over
2912 if (offset
<= size
/2)
2914 drop_position
= part
->pane
->dock_pos
;
2916 part
->pane
->dock_direction
,
2917 part
->pane
->dock_layer
,
2918 part
->pane
->dock_row
,
2919 part
->pane
->dock_pos
);
2922 // if we are in the bottom/right part of the pane,
2923 // insert the pane before the pane being hovered over
2924 if (offset
> size
/2)
2926 drop_position
= part
->pane
->dock_pos
+1;
2928 part
->pane
->dock_direction
,
2929 part
->pane
->dock_layer
,
2930 part
->pane
->dock_row
,
2931 part
->pane
->dock_pos
+1);
2935 Direction(part
->dock
->dock_direction
).
2936 Layer(part
->dock
->dock_layer
).
2937 Row(part
->dock
->dock_row
).
2938 Position(drop_position
);
2939 return ProcessDockResult(target
, drop
);
2946 void wxAuiManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2948 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
2950 m_hint_fadetimer
.Stop();
2954 m_hint_fadeamt
+= 4;
2955 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2958 void wxAuiManager::ShowHint(const wxRect
& rect
)
2962 // if the hint rect is the same as last time, don't do anything
2963 if (m_last_hint
== rect
)
2967 m_hint_fadeamt
= m_hint_fademax
;
2969 if ((m_flags
& wxAUI_MGR_HINT_FADE
)
2970 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2971 (m_flags
& wxAUI_MGR_NO_VENETIAN_BLINDS_FADE
))
2975 m_hint_wnd
->SetSize(rect
);
2977 if (!m_hint_wnd
->IsShown())
2980 // if we are dragging a floating pane, set the focus
2981 // back to that floating pane (otherwise it becomes unfocused)
2982 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2983 m_action_window
->SetFocus();
2985 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2986 m_hint_wnd
->Raise();
2989 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
2991 // start fade in timer
2992 m_hint_fadetimer
.SetOwner(this, 101);
2993 m_hint_fadetimer
.Start(5);
2996 else // Not using a transparent hint window...
2998 if (!(m_flags
& wxAUI_MGR_RECTANGLE_HINT
))
3001 if (m_last_hint
!= rect
)
3003 // remove the last hint rectangle
3009 wxScreenDC screendc
;
3010 wxRegion
clip(1, 1, 10000, 10000);
3012 // clip all floating windows, so we don't draw over them
3014 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
3016 wxAuiPaneInfo
& pane
= m_panes
.Item(i
);
3018 if (pane
.IsFloating() &&
3019 pane
.frame
->IsShown())
3021 wxRect rect
= pane
.frame
->GetRect();
3023 // wxGTK returns the client size, not the whole frame size
3029 clip
.Subtract(rect
);
3033 // As we can only hide the hint by redrawing the managed window, we
3034 // need to clip the region to the managed window too or we get
3035 // nasty redrawn problems.
3036 clip
.Intersect(m_frame
->GetRect());
3038 screendc
.SetClippingRegion(clip
);
3040 wxBitmap stipple
= wxPaneCreateStippleBitmap();
3041 wxBrush
brush(stipple
);
3042 screendc
.SetBrush(brush
);
3043 screendc
.SetPen(*wxTRANSPARENT_PEN
);
3045 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
3046 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
3047 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
3048 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
3052 void wxAuiManager::HideHint()
3054 // hides a transparent window hint, if there is one
3057 if (m_hint_wnd
->IsShown())
3058 m_hint_wnd
->Show(false);
3059 m_hint_wnd
->SetTransparent(0);
3060 m_hint_fadetimer
.Stop();
3061 m_last_hint
= wxRect();
3065 // hides a painted hint by redrawing the frame window
3066 if (!m_last_hint
.IsEmpty())
3070 m_last_hint
= wxRect();
3077 // CalculateHintRect() calculates the drop hint rectangle. The method
3078 // first calls DoDrop() to determine the exact position the pane would
3079 // be at were if dropped. If the pane would indeed become docked at the
3080 // specified drop point, the the rectangle hint will be returned in
3081 // screen coordinates. Otherwise, an empty rectangle is returned.
3082 // |pane_window| is the window pointer of the pane being dragged, |pt| is
3083 // the mouse position, in client coordinates. |offset| describes the offset
3084 // that the mouse is from the upper-left corner of the item being dragged
3086 wxRect
wxAuiManager::CalculateHintRect(wxWindow
* pane_window
,
3088 const wxPoint
& offset
)
3092 // we need to paint a hint rectangle; to find out the exact hint rectangle,
3093 // we will create a new temporary layout and then measure the resulting
3094 // rectangle; we will create a copy of the docking structures (m_dock)
3095 // so that we don't modify the real thing on screen
3097 int i
, pane_count
, part_count
;
3098 wxAuiDockInfoArray docks
;
3099 wxAuiPaneInfoArray panes
;
3100 wxAuiDockUIPartArray uiparts
;
3101 wxAuiPaneInfo hint
= GetPane(pane_window
);
3102 hint
.name
= wxT("__HINT__");
3108 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3110 // remove any pane already there which bears the same window;
3111 // this happens when you are moving a pane around in a dock
3112 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
3114 if (panes
.Item(i
).window
== pane_window
)
3116 RemovePaneFromDocks(docks
, panes
.Item(i
));
3122 // find out where the new pane would be
3123 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
3130 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
3131 wxSize client_size
= m_frame
->GetClientSize();
3132 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
3135 for (i
= 0, part_count
= uiparts
.GetCount();
3136 i
< part_count
; ++i
)
3138 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
3140 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
3141 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
3143 rect
= wxRect(part
.sizer_item
->GetPosition(),
3144 part
.sizer_item
->GetSize());
3156 // actually show the hint rectangle on the screen
3157 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
3162 // DrawHintRect() calculates the hint rectangle by calling
3163 // CalculateHintRect(). If there is a rectangle, it shows it
3164 // by calling ShowHint(), otherwise it hides any hint
3165 // rectangle currently shown
3166 void wxAuiManager::DrawHintRect(wxWindow
* pane_window
,
3168 const wxPoint
& offset
)
3170 wxRect rect
= CalculateHintRect(pane_window
, pt
, offset
);
3182 void wxAuiManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
3184 // try to find the pane
3185 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3186 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3188 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3189 pane
.frame
->SetTransparent(150);
3192 void wxAuiManager::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
3194 // try to find the pane
3195 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3196 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3198 wxPoint pt
= ::wxGetMousePosition();
3201 // Adapt pt to direction
3204 // move to pane's upper border
3206 pos
= wnd
->ClientToScreen( pos
);
3208 // and some more pixels for the title bar
3213 // move to pane's left border
3215 pos
= wnd
->ClientToScreen( pos
);
3220 // move to pane's right border
3221 wxPoint
pos( wnd
->GetSize().x
, 0 );
3222 pos
= wnd
->ClientToScreen( pos
);
3227 // move to pane's bottom border
3228 wxPoint
pos( 0, wnd
->GetSize().y
);
3229 pos
= wnd
->ClientToScreen( pos
);
3236 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3238 // calculate the offset from the upper left-hand corner
3239 // of the frame to the mouse pointer
3240 wxPoint frame_pos
= pane
.frame
->GetPosition();
3241 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3243 // no hint for toolbar floating windows
3244 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
3246 if (m_action
== actionDragFloatingPane
)
3248 wxAuiDockInfoArray docks
;
3249 wxAuiPaneInfoArray panes
;
3250 wxAuiDockUIPartArray uiparts
;
3251 wxAuiPaneInfo hint
= pane
;
3253 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3255 // find out where the new pane would be
3256 if (!DoDrop(docks
, panes
, hint
, client_pt
))
3258 if (hint
.IsFloating())
3262 m_action
= actionDragToolbarPane
;
3263 m_action_window
= pane
.window
;
3272 // if a key modifier is pressed while dragging the frame,
3273 // don't dock the window
3274 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
3281 DrawHintRect(wnd
, client_pt
, action_offset
);
3284 // this cleans up some screen artifacts that are caused on GTK because
3285 // we aren't getting the exact size of the window (see comment
3295 void wxAuiManager::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
3297 // try to find the pane
3298 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3299 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3301 wxPoint pt
= ::wxGetMousePosition();
3304 // Adapt pt to direction
3307 // move to pane's upper border
3309 pos
= wnd
->ClientToScreen( pos
);
3311 // and some more pixels for the title bar
3316 // move to pane's left border
3318 pos
= wnd
->ClientToScreen( pos
);
3323 // move to pane's right border
3324 wxPoint
pos( wnd
->GetSize().x
, 0 );
3325 pos
= wnd
->ClientToScreen( pos
);
3330 // move to pane's bottom border
3331 wxPoint
pos( 0, wnd
->GetSize().y
);
3332 pos
= wnd
->ClientToScreen( pos
);
3339 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3341 // calculate the offset from the upper left-hand corner
3342 // of the frame to the mouse pointer
3343 wxPoint frame_pos
= pane
.frame
->GetPosition();
3344 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3347 // if a key modifier is pressed while dragging the frame,
3348 // don't dock the window
3349 if (!wxGetKeyState(WXK_CONTROL
) && !wxGetKeyState(WXK_ALT
))
3351 // do the drop calculation
3352 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3355 // if the pane is still floating, update it's floating
3356 // position (that we store)
3357 if (pane
.IsFloating())
3359 pane
.floating_pos
= pane
.frame
->GetPosition();
3361 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3362 pane
.frame
->SetTransparent(255);
3364 else if (m_has_maximized
)
3366 RestoreMaximizedPane();
3374 void wxAuiManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3376 // try to find the pane
3377 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3378 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3380 pane
.floating_size
= size
;
3384 void wxAuiManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3386 // try to find the pane
3387 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3388 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3391 // fire pane close event
3392 wxAuiManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3394 e
.SetCanVeto(evt
.CanVeto());
3410 void wxAuiManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3412 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3414 // try to find the pane
3415 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
3417 SetActivePane(m_panes
, wnd
);
3422 // OnRender() draws all of the pane captions, sashes,
3423 // backgrounds, captions, grippers, pane borders and buttons.
3424 // It renders the entire user interface.
3426 void wxAuiManager::OnRender(wxAuiManagerEvent
& evt
)
3428 wxDC
* dc
= evt
.GetDC();
3434 for (i
= 0, part_count
= m_uiparts
.GetCount();
3435 i
< part_count
; ++i
)
3437 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
3439 // don't draw hidden pane items
3440 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
3445 case wxAuiDockUIPart::typeDockSizer
:
3446 case wxAuiDockUIPart::typePaneSizer
:
3447 m_art
->DrawSash(*dc
, m_frame
, part
.orientation
, part
.rect
);
3449 case wxAuiDockUIPart::typeBackground
:
3450 m_art
->DrawBackground(*dc
, m_frame
, part
.orientation
, part
.rect
);
3452 case wxAuiDockUIPart::typeCaption
:
3453 m_art
->DrawCaption(*dc
, m_frame
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3455 case wxAuiDockUIPart::typeGripper
:
3456 m_art
->DrawGripper(*dc
, m_frame
, part
.rect
, *part
.pane
);
3458 case wxAuiDockUIPart::typePaneBorder
:
3459 m_art
->DrawBorder(*dc
, m_frame
, part
.rect
, *part
.pane
);
3461 case wxAuiDockUIPart::typePaneButton
:
3462 m_art
->DrawPaneButton(*dc
, m_frame
, part
.button
->button_id
,
3463 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3470 // Render() fire a render event, which is normally handled by
3471 // wxAuiManager::OnRender(). This allows the render function to
3472 // be overridden via the render event. This can be useful for paintin
3473 // custom graphics in the main window. Default behavior can be
3474 // invoked in the overridden function by calling OnRender()
3476 void wxAuiManager::Render(wxDC
* dc
)
3478 wxAuiManagerEvent
e(wxEVT_AUI_RENDER
);
3483 void wxAuiManager::Repaint(wxDC
* dc
)
3488 m_frame
->Refresh() ;
3494 m_frame
->GetClientSize(&w
, &h
);
3496 // figure out which dc to use; if one
3497 // has been specified, use it, otherwise
3499 wxClientDC
* client_dc
= NULL
;
3502 client_dc
= new wxClientDC(m_frame
);
3506 // if the frame has a toolbar, the client area
3507 // origin will not be (0,0).
3508 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3509 if (pt
.x
!= 0 || pt
.y
!= 0)
3510 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3512 // render all the items
3515 // if we created a client_dc, delete it
3520 void wxAuiManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3522 wxPaintDC
dc(m_frame
);
3526 void wxAuiManager::OnEraseBackground(wxEraseEvent
& event
)
3535 void wxAuiManager::OnSize(wxSizeEvent
& event
)
3543 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
3545 // for MDI parent frames, this event must not
3546 // be "skipped". In other words, the parent frame
3547 // must not be allowed to resize the client window
3548 // after we are finished processing sizing changes
3556 void wxAuiManager::OnFindManager(wxAuiManagerEvent
& evt
)
3558 // get the window we are managing, if none, return NULL
3559 wxWindow
* window
= GetManagedWindow();
3562 evt
.SetManager(NULL
);
3566 // if we are managing a child frame, get the 'real' manager
3567 if (window
->IsKindOf(CLASSINFO(wxAuiFloatingFrame
)))
3569 wxAuiFloatingFrame
* float_frame
= static_cast<wxAuiFloatingFrame
*>(window
);
3570 evt
.SetManager(float_frame
->GetOwnerManager());
3574 // return pointer to ourself
3575 evt
.SetManager(this);
3578 void wxAuiManager::OnSetCursor(wxSetCursorEvent
& event
)
3581 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3582 wxCursor cursor
= wxNullCursor
;
3586 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3587 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3589 // a dock may not be resized if it has a single
3590 // pane which is not resizable
3591 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3592 part
->dock
->panes
.GetCount() == 1 &&
3593 part
->dock
->panes
.Item(0)->IsFixed())
3596 // panes that may not be resized do not get a sizing cursor
3597 if (part
->pane
&& part
->pane
->IsFixed())
3600 if (part
->orientation
== wxVERTICAL
)
3601 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3603 cursor
= wxCursor(wxCURSOR_SIZENS
);
3605 else if (part
->type
== wxAuiDockUIPart::typeGripper
)
3607 cursor
= wxCursor(wxCURSOR_SIZING
);
3611 event
.SetCursor(cursor
);
3616 void wxAuiManager::UpdateButtonOnScreen(wxAuiDockUIPart
* button_ui_part
,
3617 const wxMouseEvent
& event
)
3619 wxAuiDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3620 if (!hit_test
|| !button_ui_part
)
3623 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3625 if (hit_test
== button_ui_part
)
3627 if (event
.LeftDown())
3628 state
= wxAUI_BUTTON_STATE_PRESSED
;
3630 state
= wxAUI_BUTTON_STATE_HOVER
;
3634 if (event
.LeftDown())
3635 state
= wxAUI_BUTTON_STATE_HOVER
;
3638 // now repaint the button with hover state
3639 wxClientDC
cdc(m_frame
);
3641 // if the frame has a toolbar, the client area
3642 // origin will not be (0,0).
3643 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3644 if (pt
.x
!= 0 || pt
.y
!= 0)
3645 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3649 m_art
->DrawPaneButton(cdc
, m_frame
,
3650 button_ui_part
->button
->button_id
,
3652 button_ui_part
->rect
,
3657 void wxAuiManager::OnLeftDown(wxMouseEvent
& event
)
3659 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3662 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3663 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3665 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3668 // a dock may not be resized if it has a single
3669 // pane which is not resizable
3670 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3671 part
->dock
->panes
.GetCount() == 1 &&
3672 part
->dock
->panes
.Item(0)->IsFixed())
3675 // panes that may not be resized should be ignored here
3676 if (part
->pane
&& part
->pane
->IsFixed())
3679 m_action
= actionResize
;
3680 m_action_part
= part
;
3681 m_action_hintrect
= wxRect();
3682 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3683 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3684 event
.m_y
- part
->rect
.y
);
3685 m_frame
->CaptureMouse();
3687 else if (part
->type
== wxAuiDockUIPart::typePaneButton
)
3689 m_action
= actionClickButton
;
3690 m_action_part
= part
;
3691 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3692 m_frame
->CaptureMouse();
3694 UpdateButtonOnScreen(part
, event
);
3696 else if (part
->type
== wxAuiDockUIPart::typeCaption
||
3697 part
->type
== wxAuiDockUIPart::typeGripper
)
3699 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3702 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3704 // set the caption as active
3705 SetActivePane(m_panes
, part
->pane
->window
);
3709 m_action
= actionClickCaption
;
3710 m_action_part
= part
;
3711 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3712 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3713 event
.m_y
- part
->rect
.y
);
3714 m_frame
->CaptureMouse();
3734 void wxAuiManager::OnLeftUp(wxMouseEvent
& event
)
3736 if (m_action
== actionResize
)
3738 m_frame
->ReleaseMouse();
3740 // get rid of the hint rectangle
3742 DrawResizeHint(dc
, m_action_hintrect
);
3744 // resize the dock or the pane
3745 if (m_action_part
&& m_action_part
->type
==wxAuiDockUIPart::typeDockSizer
)
3747 wxRect
& rect
= m_action_part
->dock
->rect
;
3749 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3750 event
.m_y
- m_action_offset
.y
);
3752 switch (m_action_part
->dock
->dock_direction
)
3754 case wxAUI_DOCK_LEFT
:
3755 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3757 case wxAUI_DOCK_TOP
:
3758 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3760 case wxAUI_DOCK_RIGHT
:
3761 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3762 new_pos
.x
- m_action_part
->rect
.GetWidth();
3764 case wxAUI_DOCK_BOTTOM
:
3765 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3766 new_pos
.y
- m_action_part
->rect
.GetHeight();
3773 else if (m_action_part
&&
3774 m_action_part
->type
== wxAuiDockUIPart::typePaneSizer
)
3776 wxAuiDockInfo
& dock
= *m_action_part
->dock
;
3777 wxAuiPaneInfo
& pane
= *m_action_part
->pane
;
3779 int total_proportion
= 0;
3780 int dock_pixels
= 0;
3781 int new_pixsize
= 0;
3783 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
3784 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
3785 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
3787 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3788 event
.m_y
- m_action_offset
.y
);
3790 // determine the pane rectangle by getting the pane part
3791 wxAuiDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3792 wxASSERT_MSG(pane_part
,
3793 wxT("Pane border part not found -- shouldn't happen"));
3795 // determine the new pixel size that the user wants;
3796 // this will help us recalculate the pane's proportion
3797 if (dock
.IsHorizontal())
3798 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3800 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3802 // determine the size of the dock, based on orientation
3803 if (dock
.IsHorizontal())
3804 dock_pixels
= dock
.rect
.GetWidth();
3806 dock_pixels
= dock
.rect
.GetHeight();
3808 // determine the total proportion of all resizable panes,
3809 // and the total size of the dock minus the size of all
3811 int i
, dock_pane_count
= dock
.panes
.GetCount();
3812 int pane_position
= -1;
3813 for (i
= 0; i
< dock_pane_count
; ++i
)
3815 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
3816 if (p
.window
== pane
.window
)
3819 // while we're at it, subtract the pane sash
3820 // width from the dock width, because this would
3821 // skew our proportion calculations
3823 dock_pixels
-= sash_size
;
3825 // also, the whole size (including decorations) of
3826 // all fixed panes must also be subtracted, because they
3827 // are not part of the proportion calculation
3830 if (dock
.IsHorizontal())
3831 dock_pixels
-= p
.best_size
.x
;
3833 dock_pixels
-= p
.best_size
.y
;
3837 total_proportion
+= p
.dock_proportion
;
3841 // find a pane in our dock to 'steal' space from or to 'give'
3842 // space to -- this is essentially what is done when a pane is
3843 // resized; the pane should usually be the first non-fixed pane
3844 // to the right of the action pane
3845 int borrow_pane
= -1;
3846 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3848 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
3857 // demand that the pane being resized is found in this dock
3858 // (this assert really never should be raised)
3859 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3861 // prevent division by zero
3862 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3864 m_action
= actionNone
;
3868 // calculate the new proportion of the pane
3869 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3871 // default minimum size
3874 // check against the pane's minimum size, if specified. please note
3875 // that this is not enough to ensure that the minimum size will
3876 // not be violated, because the whole frame might later be shrunk,
3877 // causing the size of the pane to violate it's minimum size
3878 if (pane
.min_size
.IsFullySpecified())
3882 if (pane
.HasBorder())
3883 min_size
+= (pane_border_size
*2);
3885 // calculate minimum size with decorations (border,caption)
3886 if (pane_part
->orientation
== wxVERTICAL
)
3888 min_size
+= pane
.min_size
.y
;
3889 if (pane
.HasCaption())
3890 min_size
+= caption_size
;
3894 min_size
+= pane
.min_size
.x
;
3899 // for some reason, an arithmatic error somewhere is causing
3900 // the proportion calculations to always be off by 1 pixel;
3901 // for now we will add the 1 pixel on, but we really should
3902 // determine what's causing this.
3905 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3907 if (new_proportion
< min_proportion
)
3908 new_proportion
= min_proportion
;
3912 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3914 // borrow the space from our neighbor pane to the
3915 // right or bottom (depending on orientation)
3916 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3917 pane
.dock_proportion
= new_proportion
;
3924 else if (m_action
== actionClickButton
)
3926 m_hover_button
= NULL
;
3927 m_frame
->ReleaseMouse();
3928 UpdateButtonOnScreen(m_action_part
, event
);
3930 // make sure we're still over the item that was originally clicked
3931 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3933 // fire button-click event
3934 wxAuiManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3935 e
.SetPane(m_action_part
->pane
);
3936 e
.SetButton(m_action_part
->button
->button_id
);
3940 else if (m_action
== actionClickCaption
)
3942 m_frame
->ReleaseMouse();
3944 else if (m_action
== actionDragFloatingPane
)
3946 m_frame
->ReleaseMouse();
3948 else if (m_action
== actionDragToolbarPane
)
3950 m_frame
->ReleaseMouse();
3952 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
3953 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3955 // save the new positions
3956 wxAuiDockInfoPtrArray docks
;
3957 FindDocks(m_docks
, pane
.dock_direction
,
3958 pane
.dock_layer
, pane
.dock_row
, docks
);
3959 if (docks
.GetCount() == 1)
3961 wxAuiDockInfo
& dock
= *docks
.Item(0);
3963 wxArrayInt pane_positions
, pane_sizes
;
3964 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3966 int i
, dock_pane_count
= dock
.panes
.GetCount();
3967 for (i
= 0; i
< dock_pane_count
; ++i
)
3968 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3971 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
3979 m_action
= actionNone
;
3980 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3984 void wxAuiManager::OnMotion(wxMouseEvent
& event
)
3986 // sometimes when Update() is called from inside this method,
3987 // a spurious mouse move event is generated; this check will make
3988 // sure that only real mouse moves will get anywhere in this method;
3989 // this appears to be a bug somewhere, and I don't know where the
3990 // mouse move event is being generated. only verified on MSW
3992 wxPoint mouse_pos
= event
.GetPosition();
3993 if (m_last_mouse_move
== mouse_pos
)
3995 m_last_mouse_move
= mouse_pos
;
3998 if (m_action
== actionResize
)
4000 wxPoint pos
= m_action_part
->rect
.GetPosition();
4001 if (m_action_part
->orientation
== wxHORIZONTAL
)
4002 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
4004 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
4006 wxRect
rect(m_frame
->ClientToScreen(pos
),
4007 m_action_part
->rect
.GetSize());
4010 if (!m_action_hintrect
.IsEmpty())
4011 DrawResizeHint(dc
, m_action_hintrect
);
4012 DrawResizeHint(dc
, rect
);
4013 m_action_hintrect
= rect
;
4015 else if (m_action
== actionClickCaption
)
4017 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
4018 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
4020 // caption has been clicked. we need to check if the mouse
4021 // is now being dragged. if it is, we need to change the
4022 // mouse action to 'drag'
4023 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
4024 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
4026 wxAuiPaneInfo
* pane_info
= m_action_part
->pane
;
4028 if (!pane_info
->IsToolbar())
4030 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
4031 pane_info
->IsFloatable())
4033 m_action
= actionDragFloatingPane
;
4035 // set initial float position
4036 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4037 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4038 pt
.y
- m_action_offset
.y
);
4041 if(pane_info
->IsMaximized()) {
4042 RestorePane(*pane_info
);
4047 m_action_window
= pane_info
->frame
;
4049 // action offset is used here to make it feel "natural" to the user
4050 // to drag a docked pane and suddenly have it become a floating frame.
4051 // Sometimes, however, the offset where the user clicked on the docked
4052 // caption is bigger than the width of the floating frame itself, so
4053 // in that case we need to set the action offset to a sensible value
4054 wxSize frame_size
= m_action_window
->GetSize();
4055 if (frame_size
.x
<= m_action_offset
.x
)
4056 m_action_offset
.x
= 30;
4061 m_action
= actionDragToolbarPane
;
4062 m_action_window
= pane_info
->window
;
4066 else if (m_action
== actionDragFloatingPane
)
4068 if(m_action_window
) {
4069 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4070 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
4071 pt
.y
- m_action_offset
.y
);
4074 else if (m_action
== actionDragToolbarPane
)
4076 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4077 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4079 pane
.state
|= wxAuiPaneInfo::actionPane
;
4081 wxPoint pt
= event
.GetPosition();
4082 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
4084 // if DoDrop() decided to float the pane, set up
4085 // the floating pane's initial position
4086 if (pane
.IsFloating())
4088 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4089 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4090 pt
.y
- m_action_offset
.y
);
4093 // this will do the actiual move operation;
4094 // in the case that the pane has been floated,
4095 // this call will create the floating pane
4096 // and do the reparenting
4099 // if the pane has been floated, change the mouse
4100 // action actionDragFloatingPane so that subsequent
4101 // EVT_MOTION() events will move the floating pane
4102 if (pane
.IsFloating())
4104 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
4105 m_action
= actionDragFloatingPane
;
4106 m_action_window
= pane
.frame
;
4111 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
4112 if (part
&& part
->type
== wxAuiDockUIPart::typePaneButton
)
4114 if (part
!= m_hover_button
)
4116 // make the old button normal
4119 UpdateButtonOnScreen(m_hover_button
, event
);
4123 // mouse is over a button, so repaint the
4124 // button in hover mode
4125 UpdateButtonOnScreen(part
, event
);
4126 m_hover_button
= part
;
4134 m_hover_button
= NULL
;
4145 void wxAuiManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
4149 m_hover_button
= NULL
;
4154 void wxAuiManager::OnChildFocus(wxChildFocusEvent
& event
)
4156 // when a child pane has it's focus set, we should change the
4157 // pane's active state to reflect this. (this is only true if
4158 // active panes are allowed by the owner)
4159 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
4161 if (GetPane(event
.GetWindow()).IsOk())
4163 SetActivePane(m_panes
, event
.GetWindow());
4172 // OnPaneButton() is an event handler that is called
4173 // when a pane button has been pressed.
4174 void wxAuiManager::OnPaneButton(wxAuiManagerEvent
& evt
)
4176 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxAuiManager::OnPaneButton must be non-null"));
4178 wxAuiPaneInfo
& pane
= *(evt
.pane
);
4180 if (evt
.button
== wxAUI_BUTTON_CLOSE
)
4182 // fire pane close event
4183 wxAuiManagerEvent
e(wxEVT_AUI_PANECLOSE
);
4184 e
.SetPane(evt
.pane
);
4193 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& !pane
.IsMaximized())
4195 // fire pane close event
4196 wxAuiManagerEvent
e(wxEVT_AUI_PANEMAXIMIZE
);
4197 e
.SetPane(evt
.pane
);
4206 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& pane
.IsMaximized())
4208 // fire pane close event
4209 wxAuiManagerEvent
e(wxEVT_AUI_PANERESTORE
);
4210 e
.SetPane(evt
.pane
);
4219 else if (evt
.button
== wxAUI_BUTTON_PIN
)
4221 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&