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
)
62 // a few defines to avoid nameclashes
63 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
65 #include "wx/mac/private.h"
68 IMPLEMENT_DYNAMIC_CLASS(wxAuiManagerEvent
, wxEvent
)
71 // private manager flags (not yet on the public API)
72 enum wxAuiPrivateManagerOption
74 wxAUI_MGR_NO_DOCK_SIZE_LIMIT
= 1 << 28
80 class wxPseudoTransparentFrame
: public wxFrame
83 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
84 wxWindowID id
= wxID_ANY
,
85 const wxString
& title
= wxEmptyString
,
86 const wxPoint
& pos
= wxDefaultPosition
,
87 const wxSize
& size
= wxDefaultSize
,
88 long style
= wxDEFAULT_FRAME_STYLE
,
89 const wxString
&name
= wxT("frame"))
90 : wxFrame(parent
, id
, title
, pos
, size
, style
| wxFRAME_SHAPED
, name
)
92 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
99 m_CanSetShape
= false; // have to wait for window create event on GTK
101 m_CanSetShape
= true;
103 m_Region
= wxRegion(0, 0, 0, 0);
107 virtual bool SetTransparent(wxByte alpha
)
111 int w
=100; // some defaults
113 GetClientSize(&w
, &h
);
119 // m_Region.Union(0, 0, 1, m_MaxWidth);
122 for (int y
=0; y
<m_MaxHeight
; y
++)
124 // Reverse the order of the bottom 4 bits
125 int j
=((y
&8)?1:0)|((y
&4)?2:0)|((y
&2)?4:0)|((y
&1)?8:0);
126 if ((j
*16+8)<m_Amount
)
127 m_Region
.Union(0, y
, m_MaxWidth
, 1);
136 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
140 if (m_Region
.IsEmpty())
144 dc
.SetBrush(wxColour(128, 192, 255));
146 dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
148 dc
.SetPen(*wxTRANSPARENT_PEN
);
150 wxRegionIterator
upd(GetUpdateRegion()); // get the update rect list
154 wxRect
rect(upd
.GetRect());
155 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
162 void OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
))
169 void OnSize(wxSizeEvent
& event
)
171 // We sometimes get surplus size events
172 if ((event
.GetSize().GetWidth() == m_lastWidth
) &&
173 (event
.GetSize().GetHeight() == m_lastHeight
))
178 m_lastWidth
= event
.GetSize().GetWidth();
179 m_lastHeight
= event
.GetSize().GetHeight();
181 SetTransparent(m_Amount
);
182 m_Region
.Intersect(0, 0, event
.GetSize().GetWidth(),
183 event
.GetSize().GetHeight());
194 int m_lastWidth
,m_lastHeight
;
198 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
199 DECLARE_EVENT_TABLE()
203 IMPLEMENT_DYNAMIC_CLASS(wxPseudoTransparentFrame
, wxFrame
)
205 BEGIN_EVENT_TABLE(wxPseudoTransparentFrame
, wxFrame
)
206 EVT_PAINT(wxPseudoTransparentFrame::OnPaint
)
207 EVT_SIZE(wxPseudoTransparentFrame::OnSize
)
209 EVT_WINDOW_CREATE(wxPseudoTransparentFrame::OnWindowCreate
)
214 // -- static utility functions --
216 static wxBitmap
wxPaneCreateStippleBitmap()
218 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
219 wxImage
img(2,2,data
,true);
220 return wxBitmap(img
);
223 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
225 wxBitmap stipple
= wxPaneCreateStippleBitmap();
226 wxBrush
brush(stipple
);
228 dc
.SetPen(*wxTRANSPARENT_PEN
);
230 dc
.SetLogicalFunction(wxXOR
);
231 dc
.DrawRectangle(rect
);
236 // CopyDocksAndPanes() - this utility function creates copies of
237 // the dock and pane info. wxAuiDockInfo's usually contain pointers
238 // to wxAuiPaneInfo classes, thus this function is necessary to reliably
239 // reconstruct that relationship in the new dock info and pane info arrays
241 static void CopyDocksAndPanes(wxAuiDockInfoArray
& dest_docks
,
242 wxAuiPaneInfoArray
& dest_panes
,
243 const wxAuiDockInfoArray
& src_docks
,
244 const wxAuiPaneInfoArray
& src_panes
)
246 dest_docks
= src_docks
;
247 dest_panes
= src_panes
;
248 int i
, j
, k
, dock_count
, pc1
, pc2
;
249 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
251 wxAuiDockInfo
& dock
= dest_docks
.Item(i
);
252 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
253 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
254 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
255 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
259 // GetMaxLayer() is an internal function which returns
260 // the highest layer inside the specified dock
261 static int GetMaxLayer(const wxAuiDockInfoArray
& docks
, int dock_direction
)
263 int i
, dock_count
, max_layer
= 0;
264 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
266 wxAuiDockInfo
& dock
= docks
.Item(i
);
267 if (dock
.dock_direction
== dock_direction
&&
268 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
269 max_layer
= dock
.dock_layer
;
275 // GetMaxRow() is an internal function which returns
276 // the highest layer inside the specified dock
277 static int GetMaxRow(const wxAuiPaneInfoArray
& panes
, int direction
, int layer
)
279 int i
, pane_count
, max_row
= 0;
280 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
282 wxAuiPaneInfo
& pane
= panes
.Item(i
);
283 if (pane
.dock_direction
== direction
&&
284 pane
.dock_layer
== layer
&&
285 pane
.dock_row
> max_row
)
286 max_row
= pane
.dock_row
;
293 // DoInsertDockLayer() is an internal function that inserts a new dock
294 // layer by incrementing all existing dock layer values by one
295 static void DoInsertDockLayer(wxAuiPaneInfoArray
& panes
,
300 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
302 wxAuiPaneInfo
& pane
= panes
.Item(i
);
303 if (!pane
.IsFloating() &&
304 pane
.dock_direction
== dock_direction
&&
305 pane
.dock_layer
>= dock_layer
)
310 // DoInsertDockLayer() is an internal function that inserts a new dock
311 // row by incrementing all existing dock row values by one
312 static void DoInsertDockRow(wxAuiPaneInfoArray
& panes
,
318 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
320 wxAuiPaneInfo
& pane
= panes
.Item(i
);
321 if (!pane
.IsFloating() &&
322 pane
.dock_direction
== dock_direction
&&
323 pane
.dock_layer
== dock_layer
&&
324 pane
.dock_row
>= dock_row
)
329 // DoInsertDockLayer() is an internal function that inserts a space for
330 // another dock pane by incrementing all existing dock row values by one
331 static void DoInsertPane(wxAuiPaneInfoArray
& panes
,
338 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
340 wxAuiPaneInfo
& pane
= panes
.Item(i
);
341 if (!pane
.IsFloating() &&
342 pane
.dock_direction
== dock_direction
&&
343 pane
.dock_layer
== dock_layer
&&
344 pane
.dock_row
== dock_row
&&
345 pane
.dock_pos
>= dock_pos
)
350 // FindDocks() is an internal function that returns a list of docks which meet
351 // the specified conditions in the parameters and returns a sorted array
352 // (sorted by layer and then row)
353 static void FindDocks(wxAuiDockInfoArray
& docks
,
357 wxAuiDockInfoPtrArray
& arr
)
359 int begin_layer
= dock_layer
;
360 int end_layer
= dock_layer
;
361 int begin_row
= dock_row
;
362 int end_row
= dock_row
;
363 int dock_count
= docks
.GetCount();
364 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
366 // discover the maximum dock layer and the max row
367 for (i
= 0; i
< dock_count
; ++i
)
369 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
370 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
373 // if no dock layer was specified, search all dock layers
374 if (dock_layer
== -1)
377 end_layer
= max_layer
;
380 // if no dock row was specified, search all dock row
389 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
390 for (row
= begin_row
; row
<= end_row
; ++row
)
391 for (i
= 0; i
< dock_count
; ++i
)
393 wxAuiDockInfo
& d
= docks
.Item(i
);
394 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
396 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
402 // FindPaneInDock() looks up a specified window pointer inside a dock.
403 // If found, the corresponding wxAuiPaneInfo pointer is returned, otherwise NULL.
404 static wxAuiPaneInfo
* FindPaneInDock(const wxAuiDockInfo
& dock
, wxWindow
* window
)
406 int i
, count
= dock
.panes
.GetCount();
407 for (i
= 0; i
< count
; ++i
)
409 wxAuiPaneInfo
* p
= dock
.panes
.Item(i
);
410 if (p
->window
== window
)
416 // RemovePaneFromDocks() removes a pane window from all docks
417 // with a possible exception specified by parameter "ex_cept"
418 static void RemovePaneFromDocks(wxAuiDockInfoArray
& docks
,
420 wxAuiDockInfo
* ex_cept
= NULL
)
423 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
425 wxAuiDockInfo
& d
= docks
.Item(i
);
428 wxAuiPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
434 // RenumberDockRows() takes a dock and assigns sequential numbers
435 // to existing rows. Basically it takes out the gaps; so if a
436 // dock has rows with numbers 0,2,5, they will become 0,1,2
437 static void RenumberDockRows(wxAuiDockInfoPtrArray
& docks
)
439 int i
, dock_count
, j
, pane_count
;
440 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
442 wxAuiDockInfo
& dock
= *docks
.Item(i
);
444 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
445 dock
.panes
.Item(j
)->dock_row
= i
;
450 // SetActivePane() sets the active pane, as well as cycles through
451 // every other pane and makes sure that all others' active flags
453 static void SetActivePane(wxAuiPaneInfoArray
& panes
, wxWindow
* active_pane
)
456 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
458 wxAuiPaneInfo
& pane
= panes
.Item(i
);
459 pane
.state
&= ~wxAuiPaneInfo::optionActive
;
460 if (pane
.window
== active_pane
)
461 pane
.state
|= wxAuiPaneInfo::optionActive
;
466 // this function is used to sort panes by dock position
467 static int PaneSortFunc(wxAuiPaneInfo
** p1
, wxAuiPaneInfo
** p2
)
469 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
473 // -- wxAuiManager class implementation --
476 BEGIN_EVENT_TABLE(wxAuiManager
, wxEvtHandler
)
477 EVT_AUI_PANEBUTTON(wxAuiManager::OnPaneButton
)
478 EVT_AUI_RENDER(wxAuiManager::OnRender
)
479 EVT_PAINT(wxAuiManager::OnPaint
)
480 EVT_ERASE_BACKGROUND(wxAuiManager::OnEraseBackground
)
481 EVT_SIZE(wxAuiManager::OnSize
)
482 EVT_SET_CURSOR(wxAuiManager::OnSetCursor
)
483 EVT_LEFT_DOWN(wxAuiManager::OnLeftDown
)
484 EVT_LEFT_UP(wxAuiManager::OnLeftUp
)
485 EVT_MOTION(wxAuiManager::OnMotion
)
486 EVT_LEAVE_WINDOW(wxAuiManager::OnLeaveWindow
)
487 EVT_CHILD_FOCUS(wxAuiManager::OnChildFocus
)
488 EVT_TIMER(101, wxAuiManager::OnHintFadeTimer
)
492 wxAuiManager::wxAuiManager(wxWindow
* managed_wnd
, unsigned int flags
)
494 m_action
= actionNone
;
495 m_last_mouse_move
= wxPoint();
496 m_hover_button
= NULL
;
497 m_art
= new wxAuiDefaultDockArt
;
501 m_has_maximized
= false;
506 SetManagedWindow(managed_wnd
);
510 wxAuiManager::~wxAuiManager()
515 // Creates a floating frame for the windows
516 wxAuiFloatingFrame
* wxAuiManager::CreateFloatingFrame(wxWindow
* parent
, const wxAuiPaneInfo
& p
)
518 return new wxAuiFloatingFrame(parent
, this, p
);
521 // GetPane() looks up a wxAuiPaneInfo structure based
522 // on the supplied window pointer. Upon failure, GetPane()
523 // returns an empty wxAuiPaneInfo, a condition which can be checked
524 // by calling wxAuiPaneInfo::IsOk().
526 // The pane info's structure may then be modified. Once a pane's
527 // info is modified, wxAuiManager::Update() must be called to
528 // realize the changes in the UI.
530 wxAuiPaneInfo
& wxAuiManager::GetPane(wxWindow
* window
)
533 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
535 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
536 if (p
.window
== window
)
539 return wxAuiNullPaneInfo
;
542 // this version of GetPane() looks up a pane based on a
543 // 'pane name', see above comment for more info
544 wxAuiPaneInfo
& wxAuiManager::GetPane(const wxString
& name
)
547 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
549 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
553 return wxAuiNullPaneInfo
;
556 // GetAllPanes() returns a reference to all the pane info structures
557 wxAuiPaneInfoArray
& wxAuiManager::GetAllPanes()
562 // HitTest() is an internal function which determines
563 // which UI item the specified coordinates are over
564 // (x,y) specify a position in client coordinates
565 wxAuiDockUIPart
* wxAuiManager::HitTest(int x
, int y
)
567 wxAuiDockUIPart
* result
= NULL
;
570 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
572 wxAuiDockUIPart
* item
= &m_uiparts
.Item(i
);
574 // we are not interested in typeDock, because this space
575 // isn't used to draw anything, just for measurements;
576 // besides, the entire dock area is covered with other
577 // rectangles, which we are interested in.
578 if (item
->type
== wxAuiDockUIPart::typeDock
)
581 // if we already have a hit on a more specific item, we are not
582 // interested in a pane hit. If, however, we don't already have
583 // a hit, returning a pane hit is necessary for some operations
584 if ((item
->type
== wxAuiDockUIPart::typePane
||
585 item
->type
== wxAuiDockUIPart::typePaneBorder
) && result
)
588 // if the point is inside the rectangle, we have a hit
589 if (item
->rect
.Contains(x
,y
))
597 // SetFlags() and GetFlags() allow the owner to set various
598 // options which are global to wxAuiManager
599 void wxAuiManager::SetFlags(unsigned int flags
)
601 // find out if we have to call UpdateHintWindowConfig()
602 bool update_hint_wnd
= false;
603 unsigned int hint_mask
= wxAUI_MGR_TRANSPARENT_HINT
|
604 wxAUI_MGR_VENETIAN_BLINDS_HINT
|
605 wxAUI_MGR_RECTANGLE_HINT
;
606 if ((flags
& hint_mask
) != (m_flags
& hint_mask
))
607 update_hint_wnd
= true;
615 UpdateHintWindowConfig();
619 unsigned int wxAuiManager::GetFlags() const
625 // don't use these anymore as they are deprecated
626 // use Set/GetManagedFrame() instead
627 void wxAuiManager::SetFrame(wxFrame
* frame
)
629 SetManagedWindow((wxWindow
*)frame
);
632 wxFrame
* wxAuiManager::GetFrame() const
634 return (wxFrame
*)m_frame
;
638 void wxAuiManager::UpdateHintWindowConfig()
640 // find out if the the system can do transparent frames
641 bool can_do_transparent
= false;
643 wxWindow
* w
= m_frame
;
646 if (w
->IsKindOf(CLASSINFO(wxFrame
)))
648 wxFrame
* f
= static_cast<wxFrame
*>(w
);
649 #if wxCHECK_VERSION(2,7,0)
650 can_do_transparent
= f
->CanSetTransparent();
658 // if there is an existing hint window, delete it
661 m_hint_wnd
->Destroy();
668 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) && can_do_transparent
)
670 // Make a window to use for a transparent hint
671 #if defined(__WXMSW__) || defined(__WXGTK__)
672 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
,
673 wxDefaultPosition
, wxSize(1,1),
674 wxFRAME_TOOL_WINDOW
|
675 wxFRAME_FLOAT_ON_PARENT
|
679 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
680 #elif defined(__WXMAC__)
681 // Using a miniframe with float and tool styles keeps the parent
682 // frame activated and highlighted as such...
683 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
,
684 wxDefaultPosition
, wxSize(1,1),
685 wxFRAME_FLOAT_ON_PARENT
686 | wxFRAME_TOOL_WINDOW
);
688 // Can't set the bg colour of a Frame in wxMac
689 wxPanel
* p
= new wxPanel(m_hint_wnd
);
691 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
692 // color that is really hard to see, especially transparent.
693 // Until a better system color is decided upon we'll just use
695 p
->SetBackgroundColour(*wxBLUE
);
701 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 ||
702 (m_flags
& wxAUI_MGR_VENETIAN_BLINDS_HINT
) != 0)
704 // system can't support transparent fade, or the venetian
705 // blinds effect was explicitly requested
706 m_hint_wnd
= new wxPseudoTransparentFrame(m_frame
,
711 wxFRAME_TOOL_WINDOW
|
712 wxFRAME_FLOAT_ON_PARENT
|
715 m_hint_fademax
= 128;
721 // SetManagedWindow() is usually called once when the frame
722 // manager class is being initialized. "frame" specifies
723 // the frame which should be managed by the frame mananger
724 void wxAuiManager::SetManagedWindow(wxWindow
* wnd
)
726 wxASSERT_MSG(wnd
, wxT("specified window must be non-NULL"));
729 m_frame
->PushEventHandler(this);
732 // if the owner is going to manage an MDI parent frame,
733 // we need to add the MDI client window as the default
736 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
738 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)m_frame
;
739 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
741 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
743 AddPane(client_window
,
744 wxAuiPaneInfo().Name(wxT("mdiclient")).
745 CenterPane().PaneBorder(false));
749 UpdateHintWindowConfig();
753 // UnInit() must be called, usually in the destructor
754 // of the frame class. If it is not called, usually this
755 // will result in a crash upon program exit
756 void wxAuiManager::UnInit()
760 m_frame
->RemoveEventHandler(this);
764 // GetManagedWindow() returns the window pointer being managed
765 wxWindow
* wxAuiManager::GetManagedWindow() const
770 wxAuiDockArt
* wxAuiManager::GetArtProvider() const
775 void wxAuiManager::ProcessMgrEvent(wxAuiManagerEvent
& event
)
777 // first, give the owner frame a chance to override
780 if (m_frame
->ProcessEvent(event
))
787 // SetArtProvider() instructs wxAuiManager to use the
788 // specified art provider for all drawing calls. This allows
789 // plugable look-and-feel features. The pointer that is
790 // passed to this method subsequently belongs to wxAuiManager,
791 // and is deleted in the frame manager destructor
792 void wxAuiManager::SetArtProvider(wxAuiDockArt
* art_provider
)
794 // delete the last art provider, if any
797 // assign the new art provider
798 m_art
= art_provider
;
802 bool wxAuiManager::AddPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
)
804 // check if the pane has a valid window
808 // check if the pane already exists
809 if (GetPane(pane_info
.window
).IsOk())
812 // if the new pane is docked then we should undo maximize
813 if(pane_info
.IsDocked())
814 RestoreMaximizedPane();
816 m_panes
.Add(pane_info
);
818 wxAuiPaneInfo
& pinfo
= m_panes
.Last();
820 // set the pane window
821 pinfo
.window
= window
;
823 // if the pane's name identifier is blank, create a random string
824 if (pinfo
.name
.empty())
826 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
827 ((unsigned long)pinfo
.window
) & 0xffffffff,
828 (unsigned int)time(NULL
),
830 (unsigned int)GetTickCount(),
832 (unsigned int)clock(),
834 (unsigned long)m_panes
.GetCount());
837 // set initial proportion (if not already set)
838 if (pinfo
.dock_proportion
== 0)
839 pinfo
.dock_proportion
= 100000;
841 if (pinfo
.HasMaximizeButton())
843 wxAuiPaneButton button
;
844 button
.button_id
= wxAUI_BUTTON_MAXIMIZE_RESTORE
;
845 pinfo
.buttons
.Add(button
);
848 if (pinfo
.HasPinButton())
850 wxAuiPaneButton button
;
851 button
.button_id
= wxAUI_BUTTON_PIN
;
852 pinfo
.buttons
.Add(button
);
855 if (pinfo
.HasCloseButton())
857 wxAuiPaneButton button
;
858 button
.button_id
= wxAUI_BUTTON_CLOSE
;
859 pinfo
.buttons
.Add(button
);
862 if (pinfo
.best_size
== wxDefaultSize
&&
865 pinfo
.best_size
= pinfo
.window
->GetClientSize();
867 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
869 // GetClientSize() doesn't get the best size for
870 // a toolbar under some newer versions of wxWidgets,
871 // so use GetBestSize()
872 pinfo
.best_size
= pinfo
.window
->GetBestSize();
874 // for some reason, wxToolBar::GetBestSize() is returning
875 // a size that is a pixel shy of the correct amount.
876 // I believe this to be the correct action, until
877 // wxToolBar::GetBestSize() is fixed. Is this assumption
882 if (pinfo
.min_size
!= wxDefaultSize
)
884 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
885 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
886 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
887 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
894 bool wxAuiManager::AddPane(wxWindow
* window
,
896 const wxString
& caption
)
899 pinfo
.Caption(caption
);
902 case wxTOP
: pinfo
.Top(); break;
903 case wxBOTTOM
: pinfo
.Bottom(); break;
904 case wxLEFT
: pinfo
.Left(); break;
905 case wxRIGHT
: pinfo
.Right(); break;
906 case wxCENTER
: pinfo
.CenterPane(); break;
908 return AddPane(window
, pinfo
);
911 bool wxAuiManager::AddPane(wxWindow
* window
,
912 const wxAuiPaneInfo
& pane_info
,
913 const wxPoint
& drop_pos
)
915 if (!AddPane(window
, pane_info
))
918 wxAuiPaneInfo
& pane
= GetPane(window
);
920 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
925 bool wxAuiManager::InsertPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
,
928 // shift the panes around, depending on the insert level
929 switch (insert_level
)
931 case wxAUI_INSERT_PANE
:
932 DoInsertPane(m_panes
,
933 pane_info
.dock_direction
,
934 pane_info
.dock_layer
,
938 case wxAUI_INSERT_ROW
:
939 DoInsertDockRow(m_panes
,
940 pane_info
.dock_direction
,
941 pane_info
.dock_layer
,
944 case wxAUI_INSERT_DOCK
:
945 DoInsertDockLayer(m_panes
,
946 pane_info
.dock_direction
,
947 pane_info
.dock_layer
);
951 // if the window already exists, we are basically just moving/inserting the
952 // existing window. If it doesn't exist, we need to add it and insert it
953 wxAuiPaneInfo
& existing_pane
= GetPane(window
);
954 if (!existing_pane
.IsOk())
956 return AddPane(window
, pane_info
);
960 if (pane_info
.IsFloating())
962 existing_pane
.Float();
963 if (pane_info
.floating_pos
!= wxDefaultPosition
)
964 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
965 if (pane_info
.floating_size
!= wxDefaultSize
)
966 existing_pane
.FloatingSize(pane_info
.floating_size
);
970 // if the new pane is docked then we should undo maximize
971 RestoreMaximizedPane();
973 existing_pane
.Direction(pane_info
.dock_direction
);
974 existing_pane
.Layer(pane_info
.dock_layer
);
975 existing_pane
.Row(pane_info
.dock_row
);
976 existing_pane
.Position(pane_info
.dock_pos
);
984 // DetachPane() removes a pane from the frame manager. This
985 // method will not destroy the window that is removed.
986 bool wxAuiManager::DetachPane(wxWindow
* window
)
989 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
991 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
992 if (p
.window
== window
)
996 // we have a floating frame which is being detached. We need to
997 // reparent it to m_frame and destroy the floating frame
1000 p
.window
->SetSize(1,1);
1002 if (p
.frame
->IsShown())
1003 p
.frame
->Show(false);
1005 // reparent to m_frame and destroy the pane
1006 if(m_action_window
== p
.frame
) {
1007 m_action_window
= NULL
;
1009 p
.window
->Reparent(m_frame
);
1010 p
.frame
->SetSizer(NULL
);
1015 // make sure there are no references to this pane in our uiparts,
1016 // just in case the caller doesn't call Update() immediately after
1017 // the DetachPane() call. This prevets obscure crashes which would
1018 // happen at window repaint if the caller forgets to call Update()
1020 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
1022 wxAuiDockUIPart
& part
= m_uiparts
.Item(pi
);
1023 if (part
.pane
== &p
)
1025 m_uiparts
.RemoveAt(pi
);
1032 m_panes
.RemoveAt(i
);
1039 // ClosePane() destroys or hides the pane depending on its
1041 void wxAuiManager::ClosePane(wxAuiPaneInfo
& pane_info
)
1043 // if we were maximized, restore
1044 if(pane_info
.IsMaximized()) {
1045 RestorePane(pane_info
);
1048 // first, hide the window
1049 if (pane_info
.window
&& pane_info
.window
->IsShown()) {
1050 pane_info
.window
->Show(false);
1053 // make sure that we are the parent of this window
1054 if(pane_info
.window
&& pane_info
.window
->GetParent() != m_frame
) {
1055 pane_info
.window
->Reparent(m_frame
);
1058 // if we have a frame, destroy it
1059 if(pane_info
.frame
) {
1060 pane_info
.frame
->Destroy();
1061 pane_info
.frame
= NULL
;
1064 // now we need to either destroy or hide the pane
1065 if(pane_info
.IsDestroyOnClose())
1067 wxWindow
* window
= pane_info
.window
;
1079 void wxAuiManager::MaximizePane(wxAuiPaneInfo
& pane_info
)
1083 // un-maximize and hide all other panes
1084 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1086 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1087 if(!p
.IsToolbar()) {
1094 // mark ourselves maximized
1095 pane_info
.Maximize();
1097 m_has_maximized
= true;
1099 // last, show the window
1100 if (pane_info
.window
&& !pane_info
.window
->IsShown()) {
1101 pane_info
.window
->Show(true);
1105 void wxAuiManager::RestorePane(wxAuiPaneInfo
& pane_info
)
1109 // restore all the panes
1110 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1112 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1113 if(!p
.IsToolbar()) {
1118 // mark ourselves non-maximized
1119 pane_info
.Restore();
1120 m_has_maximized
= false;
1122 // last, show the window
1123 if (pane_info
.window
&& !pane_info
.window
->IsShown()) {
1124 pane_info
.window
->Show(true);
1128 void wxAuiManager::RestoreMaximizedPane()
1132 // restore all the panes
1133 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1135 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1136 if(p
.IsMaximized()) {
1143 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
1144 // in the input string. This is an internal functions which is
1145 // used for saving perspectives
1146 static wxString
EscapeDelimiters(const wxString
& s
)
1149 result
.Alloc(s
.length());
1150 const wxChar
* ch
= s
.c_str();
1153 if (*ch
== wxT(';') || *ch
== wxT('|'))
1154 result
+= wxT('\\');
1161 wxString
wxAuiManager::SavePaneInfo(wxAuiPaneInfo
& pane
)
1163 wxString result
= wxT("name=");
1164 result
+= EscapeDelimiters(pane
.name
);
1167 result
+= wxT("caption=");
1168 result
+= EscapeDelimiters(pane
.caption
);
1171 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
1172 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
1173 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
1174 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
1175 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
1176 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
1177 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
1178 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
1179 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
1180 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
1181 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
1182 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
1183 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
1184 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
1185 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
1186 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
1191 // Load a "pane" with the pane infor settings in pane_part
1192 void wxAuiManager::LoadPaneInfo(wxString pane_part
, wxAuiPaneInfo
&pane
)
1194 // replace escaped characters so we can
1195 // split up the string easily
1196 pane_part
.Replace(wxT("\\|"), wxT("\a"));
1197 pane_part
.Replace(wxT("\\;"), wxT("\b"));
1201 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
1202 pane_part
= pane_part
.AfterFirst(wxT(';'));
1203 wxString val_name
= val_part
.BeforeFirst(wxT('='));
1204 wxString value
= val_part
.AfterFirst(wxT('='));
1205 val_name
.MakeLower();
1206 val_name
.Trim(true);
1207 val_name
.Trim(false);
1211 if (val_name
.empty())
1214 if (val_name
== wxT("name"))
1216 else if (val_name
== wxT("caption"))
1217 pane
.caption
= value
;
1218 else if (val_name
== wxT("state"))
1219 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1220 else if (val_name
== wxT("dir"))
1221 pane
.dock_direction
= wxAtoi(value
.c_str());
1222 else if (val_name
== wxT("layer"))
1223 pane
.dock_layer
= wxAtoi(value
.c_str());
1224 else if (val_name
== wxT("row"))
1225 pane
.dock_row
= wxAtoi(value
.c_str());
1226 else if (val_name
== wxT("pos"))
1227 pane
.dock_pos
= wxAtoi(value
.c_str());
1228 else if (val_name
== wxT("prop"))
1229 pane
.dock_proportion
= wxAtoi(value
.c_str());
1230 else if (val_name
== wxT("bestw"))
1231 pane
.best_size
.x
= wxAtoi(value
.c_str());
1232 else if (val_name
== wxT("besth"))
1233 pane
.best_size
.y
= wxAtoi(value
.c_str());
1234 else if (val_name
== wxT("minw"))
1235 pane
.min_size
.x
= wxAtoi(value
.c_str());
1236 else if (val_name
== wxT("minh"))
1237 pane
.min_size
.y
= wxAtoi(value
.c_str());
1238 else if (val_name
== wxT("maxw"))
1239 pane
.max_size
.x
= wxAtoi(value
.c_str());
1240 else if (val_name
== wxT("maxh"))
1241 pane
.max_size
.y
= wxAtoi(value
.c_str());
1242 else if (val_name
== wxT("floatx"))
1243 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1244 else if (val_name
== wxT("floaty"))
1245 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1246 else if (val_name
== wxT("floatw"))
1247 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1248 else if (val_name
== wxT("floath"))
1249 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1251 wxFAIL_MSG(wxT("Bad Perspective String"));
1255 // replace escaped characters so we can
1256 // split up the string easily
1257 pane
.name
.Replace(wxT("\a"), wxT("|"));
1258 pane
.name
.Replace(wxT("\b"), wxT(";"));
1259 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1260 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1261 pane_part
.Replace(wxT("\a"), wxT("|"));
1262 pane_part
.Replace(wxT("\b"), wxT(";"));
1268 // SavePerspective() saves all pane information as a single string.
1269 // This string may later be fed into LoadPerspective() to restore
1270 // all pane settings. This save and load mechanism allows an
1271 // exact pane configuration to be saved and restored at a later time
1273 wxString
wxAuiManager::SavePerspective()
1277 result
= wxT("layout1|");
1279 int pane_i
, pane_count
= m_panes
.GetCount();
1280 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1282 wxAuiPaneInfo
& pane
= m_panes
.Item(pane_i
);
1283 result
+= SavePaneInfo(pane
)+wxT("|");
1286 int dock_i
, dock_count
= m_docks
.GetCount();
1287 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1289 wxAuiDockInfo
& dock
= m_docks
.Item(dock_i
);
1291 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1292 dock
.dock_direction
, dock
.dock_layer
,
1293 dock
.dock_row
, dock
.size
);
1299 // LoadPerspective() loads a layout which was saved with SavePerspective()
1300 // If the "update" flag parameter is true, the GUI will immediately be updated
1302 bool wxAuiManager::LoadPerspective(const wxString
& layout
, bool update
)
1304 wxString input
= layout
;
1307 // check layout string version
1308 part
= input
.BeforeFirst(wxT('|'));
1309 input
= input
.AfterFirst(wxT('|'));
1312 if (part
!= wxT("layout1"))
1315 // mark all panes currently managed as docked and hidden
1316 int pane_i
, pane_count
= m_panes
.GetCount();
1317 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1318 m_panes
.Item(pane_i
).Dock().Hide();
1320 // clear out the dock array; this will be reconstructed
1323 // replace escaped characters so we can
1324 // split up the string easily
1325 input
.Replace(wxT("\\|"), wxT("\a"));
1326 input
.Replace(wxT("\\;"), wxT("\b"));
1332 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1333 input
= input
.AfterFirst(wxT('|'));
1334 pane_part
.Trim(true);
1336 // if the string is empty, we're done parsing
1337 if (pane_part
.empty())
1340 if (pane_part
.Left(9) == wxT("dock_size"))
1342 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1343 wxString value
= pane_part
.AfterFirst(wxT('='));
1345 long dir
, layer
, row
, size
;
1346 wxString piece
= val_name
.AfterFirst(wxT('('));
1347 piece
= piece
.BeforeLast(wxT(')'));
1348 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1349 piece
= piece
.AfterFirst(wxT(','));
1350 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1351 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1352 value
.ToLong(&size
);
1355 dock
.dock_direction
= dir
;
1356 dock
.dock_layer
= layer
;
1357 dock
.dock_row
= row
;
1363 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1364 // name so it can be called by external callers
1365 pane_part
.Replace(wxT("\a"), wxT("|"));
1366 pane_part
.Replace(wxT("\b"), wxT(";"));
1368 LoadPaneInfo(pane_part
, pane
);
1370 wxAuiPaneInfo
& p
= GetPane(pane
.name
);
1373 // the pane window couldn't be found
1374 // in the existing layout
1388 void wxAuiManager::GetPanePositionsAndSizes(wxAuiDockInfo
& dock
,
1389 wxArrayInt
& positions
,
1392 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1393 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1394 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1399 int offset
, action_pane
= -1;
1400 int pane_i
, pane_count
= dock
.panes
.GetCount();
1402 // find the pane marked as our action pane
1403 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1405 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1407 if (pane
.state
& wxAuiPaneInfo::actionPane
)
1409 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1410 action_pane
= pane_i
;
1414 // set up each panes default position, and
1415 // determine the size (width or height, depending
1416 // on the dock's orientation) of each pane
1417 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1419 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1420 positions
.Add(pane
.dock_pos
);
1423 if (pane
.HasBorder())
1424 size
+= (pane_border_size
*2);
1426 if (dock
.IsHorizontal())
1428 if (pane
.HasGripper() && !pane
.HasGripperTop())
1429 size
+= gripper_size
;
1430 size
+= pane
.best_size
.x
;
1434 if (pane
.HasGripper() && pane
.HasGripperTop())
1435 size
+= gripper_size
;
1437 if (pane
.HasCaption())
1438 size
+= caption_size
;
1439 size
+= pane
.best_size
.y
;
1445 // if there is no action pane, just return the default
1446 // positions (as specified in pane.pane_pos)
1447 if (action_pane
== -1)
1451 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1453 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1458 positions
[pane_i
] -= -amount
;
1460 offset
+= sizes
[pane_i
];
1463 // if the dock mode is fixed, make sure none of the panes
1464 // overlap; we will bump panes that overlap
1466 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1468 int amount
= positions
[pane_i
] - offset
;
1472 positions
[pane_i
] += -amount
;
1474 offset
+= sizes
[pane_i
];
1479 void wxAuiManager::LayoutAddPane(wxSizer
* cont
,
1480 wxAuiDockInfo
& dock
,
1481 wxAuiPaneInfo
& pane
,
1482 wxAuiDockUIPartArray
& uiparts
,
1485 wxAuiDockUIPart part
;
1486 wxSizerItem
* sizer_item
;
1488 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1489 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1490 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1491 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1493 // find out the orientation of the item (orientation for panes
1494 // is the same as the dock's orientation)
1496 if (dock
.IsHorizontal())
1497 orientation
= wxHORIZONTAL
;
1499 orientation
= wxVERTICAL
;
1501 // this variable will store the proportion
1502 // value that the pane will receive
1503 int pane_proportion
= pane
.dock_proportion
;
1505 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1506 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1508 if (pane
.HasGripper())
1510 if (pane
.HasGripperTop())
1511 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1513 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1515 part
.type
= wxAuiDockUIPart::typeGripper
;
1519 part
.orientation
= orientation
;
1520 part
.cont_sizer
= horz_pane_sizer
;
1521 part
.sizer_item
= sizer_item
;
1525 if (pane
.HasCaption())
1527 // create the caption sizer
1528 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1530 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1532 part
.type
= wxAuiDockUIPart::typeCaption
;
1536 part
.orientation
= orientation
;
1537 part
.cont_sizer
= vert_pane_sizer
;
1538 part
.sizer_item
= sizer_item
;
1539 int caption_part_idx
= uiparts
.GetCount();
1542 // add pane buttons to the caption
1543 int i
, button_count
;
1544 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1545 i
< button_count
; ++i
)
1547 wxAuiPaneButton
& button
= pane
.buttons
.Item(i
);
1549 sizer_item
= caption_sizer
->Add(pane_button_size
,
1553 part
.type
= wxAuiDockUIPart::typePaneButton
;
1556 part
.button
= &button
;
1557 part
.orientation
= orientation
;
1558 part
.cont_sizer
= caption_sizer
;
1559 part
.sizer_item
= sizer_item
;
1563 // if we have buttons, add a little space to the right
1564 // of them to ease visual crowding
1565 if (button_count
>= 1)
1567 caption_sizer
->Add(3,1);
1570 // add the caption sizer
1571 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1573 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1576 // add the pane window itself
1579 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1583 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1584 // Don't do this because it breaks the pane size in floating windows
1585 // BIW: Right now commenting this out is causing problems with
1586 // an mdi client window as the center pane.
1587 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1590 part
.type
= wxAuiDockUIPart::typePane
;
1594 part
.orientation
= orientation
;
1595 part
.cont_sizer
= vert_pane_sizer
;
1596 part
.sizer_item
= sizer_item
;
1600 // determine if the pane should have a minimum size; if the pane is
1601 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1602 // if the pane.min_size is set, we must use that value as well
1604 wxSize min_size
= pane
.min_size
;
1607 if (min_size
== wxDefaultSize
)
1609 min_size
= pane
.best_size
;
1610 pane_proportion
= 0;
1614 if (min_size
!= wxDefaultSize
)
1616 vert_pane_sizer
->SetItemMinSize(
1617 vert_pane_sizer
->GetChildren().GetCount()-1,
1618 min_size
.x
, min_size
.y
);
1622 // add the verticle sizer (caption, pane window) to the
1623 // horizontal sizer (gripper, verticle sizer)
1624 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1626 // finally, add the pane sizer to the dock sizer
1628 if (pane
.HasBorder())
1630 // allowing space for the pane's border
1631 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1632 wxEXPAND
| wxALL
, pane_border_size
);
1634 part
.type
= wxAuiDockUIPart::typePaneBorder
;
1638 part
.orientation
= orientation
;
1639 part
.cont_sizer
= cont
;
1640 part
.sizer_item
= sizer_item
;
1645 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1649 void wxAuiManager::LayoutAddDock(wxSizer
* cont
,
1650 wxAuiDockInfo
& dock
,
1651 wxAuiDockUIPartArray
& uiparts
,
1654 wxSizerItem
* sizer_item
;
1655 wxAuiDockUIPart part
;
1657 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1658 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1660 // resizable bottom and right docks have a sash before them
1661 if (!m_has_maximized
&& !dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1662 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1664 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1666 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1667 part
.orientation
= orientation
;
1671 part
.cont_sizer
= cont
;
1672 part
.sizer_item
= sizer_item
;
1676 // create the sizer for the dock
1677 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1679 // add each pane to the dock
1680 bool has_maximized_pane
= false;
1681 int pane_i
, pane_count
= dock
.panes
.GetCount();
1685 wxArrayInt pane_positions
, pane_sizes
;
1687 // figure out the real pane positions we will
1688 // use, without modifying the each pane's pane_pos member
1689 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1692 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1694 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1695 int pane_pos
= pane_positions
.Item(pane_i
);
1696 if(pane
.IsMaximized()) {
1697 has_maximized_pane
= true;
1700 int amount
= pane_pos
- offset
;
1703 if (dock
.IsVertical())
1704 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1706 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1708 part
.type
= wxAuiDockUIPart::typeBackground
;
1712 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1713 part
.cont_sizer
= dock_sizer
;
1714 part
.sizer_item
= sizer_item
;
1720 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1722 offset
+= pane_sizes
.Item(pane_i
);
1725 // at the end add a very small stretchable background area
1726 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1728 part
.type
= wxAuiDockUIPart::typeBackground
;
1732 part
.orientation
= orientation
;
1733 part
.cont_sizer
= dock_sizer
;
1734 part
.sizer_item
= sizer_item
;
1739 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1741 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1742 if(pane
.IsMaximized()) {
1743 has_maximized_pane
= true;
1746 // if this is not the first pane being added,
1747 // we need to add a pane sizer
1748 if (!m_has_maximized
&& pane_i
> 0)
1750 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1752 part
.type
= wxAuiDockUIPart::typePaneSizer
;
1754 part
.pane
= dock
.panes
.Item(pane_i
-1);
1756 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1757 part
.cont_sizer
= dock_sizer
;
1758 part
.sizer_item
= sizer_item
;
1762 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1766 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
|| has_maximized_pane
)
1767 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1769 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1771 part
.type
= wxAuiDockUIPart::typeDock
;
1775 part
.orientation
= orientation
;
1776 part
.cont_sizer
= cont
;
1777 part
.sizer_item
= sizer_item
;
1780 if (dock
.IsHorizontal())
1781 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1783 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1785 // top and left docks have a sash after them
1786 if (!m_has_maximized
&& !dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1787 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1789 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1791 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1795 part
.orientation
= orientation
;
1796 part
.cont_sizer
= cont
;
1797 part
.sizer_item
= sizer_item
;
1802 wxSizer
* wxAuiManager::LayoutAll(wxAuiPaneInfoArray
& panes
,
1803 wxAuiDockInfoArray
& docks
,
1804 wxAuiDockUIPartArray
& uiparts
,
1807 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1809 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1810 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1811 wxSize cli_size
= m_frame
->GetClientSize();
1812 int i
, dock_count
, pane_count
;
1815 // empty all docks out
1816 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1817 docks
.Item(i
).panes
.Empty();
1820 // iterate through all known panes, filing each
1821 // of them into the appropriate dock. If the
1822 // pane does not exist in the dock, add it
1823 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1825 wxAuiPaneInfo
& p
= panes
.Item(i
);
1827 // find any docks in this layer
1828 wxAuiDockInfo
* dock
;
1829 wxAuiDockInfoPtrArray arr
;
1830 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1832 if (arr
.GetCount() > 0)
1838 // dock was not found, so we need to create a new one
1840 d
.dock_direction
= p
.dock_direction
;
1841 d
.dock_layer
= p
.dock_layer
;
1842 d
.dock_row
= p
.dock_row
;
1844 dock
= &docks
.Last();
1848 if (p
.IsDocked() && p
.IsShown())
1850 // remove the pane from any existing docks except this one
1851 RemovePaneFromDocks(docks
, p
, dock
);
1853 // pane needs to be added to the dock,
1854 // if it doesn't already exist
1855 if (!FindPaneInDock(*dock
, p
.window
))
1856 dock
->panes
.Add(&p
);
1860 // remove the pane from any existing docks
1861 RemovePaneFromDocks(docks
, p
);
1866 // remove any empty docks
1867 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1869 if (docks
.Item(i
).panes
.GetCount() == 0)
1873 // configure the docks further
1874 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1876 wxAuiDockInfo
& dock
= docks
.Item(i
);
1877 int j
, dock_pane_count
= dock
.panes
.GetCount();
1879 // sort the dock pane array by the pane's
1880 // dock position (dock_pos), in ascending order
1881 dock
.panes
.Sort(PaneSortFunc
);
1883 // for newly created docks, set up their initial size
1888 for (j
= 0; j
< dock_pane_count
; ++j
)
1890 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
1891 wxSize pane_size
= pane
.best_size
;
1892 if (pane_size
== wxDefaultSize
)
1893 pane_size
= pane
.min_size
;
1894 if (pane_size
== wxDefaultSize
)
1895 pane_size
= pane
.window
->GetSize();
1897 if (dock
.IsHorizontal())
1898 size
= wxMax(pane_size
.y
, size
);
1900 size
= wxMax(pane_size
.x
, size
);
1903 // add space for the border (two times), but only
1904 // if at least one pane inside the dock has a pane border
1905 for (j
= 0; j
< dock_pane_count
; ++j
)
1907 if (dock
.panes
.Item(j
)->HasBorder())
1909 size
+= (pane_border_size
*2);
1914 // if pane is on the top or bottom, add the caption height,
1915 // but only if at least one pane inside the dock has a caption
1916 if (dock
.IsHorizontal())
1918 for (j
= 0; j
< dock_pane_count
; ++j
)
1920 if (dock
.panes
.Item(j
)->HasCaption())
1922 size
+= caption_size
;
1928 if (!(m_flags
& wxAUI_MGR_NO_DOCK_SIZE_LIMIT
))
1930 // new dock's size may not be more than 1/3 of the frame size
1931 if (dock
.IsHorizontal())
1932 size
= wxMin(size
, cli_size
.y
/3);
1934 size
= wxMin(size
, cli_size
.x
/3);
1943 // determine the dock's minimum size
1944 bool plus_border
= false;
1945 bool plus_caption
= false;
1946 int dock_min_size
= 0;
1947 for (j
= 0; j
< dock_pane_count
; ++j
)
1949 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
1950 if (pane
.min_size
!= wxDefaultSize
)
1952 if (pane
.HasBorder())
1954 if (pane
.HasCaption())
1955 plus_caption
= true;
1956 if (dock
.IsHorizontal())
1958 if (pane
.min_size
.y
> dock_min_size
)
1959 dock_min_size
= pane
.min_size
.y
;
1963 if (pane
.min_size
.x
> dock_min_size
)
1964 dock_min_size
= pane
.min_size
.x
;
1970 dock_min_size
+= (pane_border_size
*2);
1971 if (plus_caption
&& dock
.IsHorizontal())
1972 dock_min_size
+= (caption_size
);
1974 dock
.min_size
= dock_min_size
;
1977 // if the pane's current size is less than it's
1978 // minimum, increase the dock's size to it's minimum
1979 if (dock
.size
< dock
.min_size
)
1980 dock
.size
= dock
.min_size
;
1983 // determine the dock's mode (fixed or proportional);
1984 // determine whether the dock has only toolbars
1985 bool action_pane_marked
= false;
1987 dock
.toolbar
= true;
1988 for (j
= 0; j
< dock_pane_count
; ++j
)
1990 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
1991 if (!pane
.IsFixed())
1993 if (!pane
.IsToolbar())
1994 dock
.toolbar
= false;
1995 if (pane
.state
& wxAuiPaneInfo::actionPane
)
1996 action_pane_marked
= true;
2000 // if the dock mode is proportional and not fixed-pixel,
2001 // reassign the dock_pos to the sequential 0, 1, 2, 3;
2002 // e.g. remove gaps like 1, 2, 30, 500
2005 for (j
= 0; j
< dock_pane_count
; ++j
)
2007 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2012 // if the dock mode is fixed, and none of the panes
2013 // are being moved right now, make sure the panes
2014 // do not overlap each other. If they do, we will
2015 // adjust the panes' positions
2016 if (dock
.fixed
&& !action_pane_marked
)
2018 wxArrayInt pane_positions
, pane_sizes
;
2019 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
2022 for (j
= 0; j
< dock_pane_count
; ++j
)
2024 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(j
));
2025 pane
.dock_pos
= pane_positions
[j
];
2027 int amount
= pane
.dock_pos
- offset
;
2031 pane
.dock_pos
+= -amount
;
2033 offset
+= pane_sizes
[j
];
2038 // discover the maximum dock layer
2040 for (i
= 0; i
< dock_count
; ++i
)
2041 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
2044 // clear out uiparts
2047 // create a bunch of box sizers,
2048 // from the innermost level outwards.
2049 wxSizer
* cont
= NULL
;
2050 wxSizer
* middle
= NULL
;
2054 for (layer
= 0; layer
<= max_layer
; ++layer
)
2056 wxAuiDockInfoPtrArray arr
;
2058 // find any docks in this layer
2059 FindDocks(docks
, -1, layer
, -1, arr
);
2061 // if there aren't any, skip to the next layer
2065 wxSizer
* old_cont
= cont
;
2067 // create a container which will hold this layer's
2068 // docks (top, bottom, left, right)
2069 cont
= new wxBoxSizer(wxVERTICAL
);
2072 // find any top docks in this layer
2073 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
2074 RenumberDockRows(arr
);
2077 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2078 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2082 // fill out the middle layer (which consists
2083 // of left docks, content area and right docks)
2085 middle
= new wxBoxSizer(wxHORIZONTAL
);
2087 // find any left docks in this layer
2088 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
2089 RenumberDockRows(arr
);
2092 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2093 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2096 // add content dock (or previous layer's sizer
2100 // find any center docks
2101 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
2104 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
2105 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2107 else if (!m_has_maximized
)
2109 // there are no center docks, add a background area
2110 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
2111 wxAuiDockUIPart part
;
2112 part
.type
= wxAuiDockUIPart::typeBackground
;
2116 part
.cont_sizer
= middle
;
2117 part
.sizer_item
= sizer_item
;
2123 middle
->Add(old_cont
, 1, wxEXPAND
);
2126 // find any right docks in this layer
2127 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
2128 RenumberDockRows(arr
);
2131 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2132 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2135 cont
->Add(middle
, 1, wxEXPAND
);
2139 // find any bottom docks in this layer
2140 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
2141 RenumberDockRows(arr
);
2144 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2145 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2152 // no sizer available, because there are no docks,
2153 // therefore we will create a simple background area
2154 cont
= new wxBoxSizer(wxVERTICAL
);
2155 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
2156 wxAuiDockUIPart part
;
2157 part
.type
= wxAuiDockUIPart::typeBackground
;
2161 part
.cont_sizer
= middle
;
2162 part
.sizer_item
= sizer_item
;
2166 container
->Add(cont
, 1, wxEXPAND
);
2171 // Update() updates the layout. Whenever changes are made to
2172 // one or more panes, this function should be called. It is the
2173 // external entry point for running the layout engine.
2175 void wxAuiManager::Update()
2178 int i
, pane_count
= m_panes
.GetCount();
2181 // destroy floating panes which have been
2182 // redocked or are becoming non-floating
2183 for (i
= 0; i
< pane_count
; ++i
)
2185 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2187 if (!p
.IsFloating() && p
.frame
)
2189 // because the pane is no longer in a floating, we need to
2190 // reparent it to m_frame and destroy the floating frame
2193 p
.window
->SetSize(1,1);
2196 // the following block is a workaround for bug #1531361
2197 // (see wxWidgets sourceforge page). On wxGTK (only), when
2198 // a frame is shown/hidden, a move event unfortunately
2199 // also gets fired. Because we may be dragging around
2200 // a pane, we need to cancel that action here to prevent
2201 // a spurious crash.
2202 if (m_action_window
== p
.frame
)
2204 if (wxWindow::GetCapture() == m_frame
)
2205 m_frame
->ReleaseMouse();
2206 m_action
= actionNone
;
2207 m_action_window
= NULL
;
2211 if (p
.frame
->IsShown())
2212 p
.frame
->Show(false);
2214 // reparent to m_frame and destroy the pane
2215 if(m_action_window
== p
.frame
)
2217 m_action_window
= NULL
;
2220 p
.window
->Reparent(m_frame
);
2221 p
.frame
->SetSizer(NULL
);
2228 // delete old sizer first
2229 m_frame
->SetSizer(NULL
);
2231 // create a layout for all of the panes
2232 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
2234 // hide or show panes as necessary,
2235 // and float panes as necessary
2236 for (i
= 0; i
< pane_count
; ++i
)
2238 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2242 if (p
.frame
== NULL
)
2244 // we need to create a frame for this
2245 // pane, which has recently been floated
2246 wxAuiFloatingFrame
* frame
= CreateFloatingFrame(m_frame
, p
);
2248 #if wxCHECK_VERSION(2,7,0)
2249 // on MSW and Mac, if the owner desires transparent dragging, and
2250 // the dragging is happening right now, then the floating
2251 // window should have this style by default
2252 if (m_action
== actionDragFloatingPane
&&
2253 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2254 frame
->SetTransparent(150);
2257 frame
->SetPaneWindow(p
);
2260 if (p
.IsShown() && !frame
->IsShown())
2265 // frame already exists, make sure it's position
2266 // and size reflect the information in wxAuiPaneInfo
2267 if (p
.frame
->GetPosition() != p
.floating_pos
)
2269 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2270 wxDefaultCoord
, wxDefaultCoord
,
2271 wxSIZE_USE_EXISTING
);
2272 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2275 if (p
.frame
->IsShown() != p
.IsShown())
2276 p
.frame
->Show(p
.IsShown());
2281 if (p
.window
->IsShown() != p
.IsShown())
2282 p
.window
->Show(p
.IsShown());
2285 // if "active panes" are no longer allowed, clear
2286 // any optionActive values from the pane states
2287 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2289 p
.state
&= ~wxAuiPaneInfo::optionActive
;
2294 // keep track of the old window rectangles so we can
2295 // refresh those windows whose rect has changed
2296 wxAuiRectArray old_pane_rects
;
2297 for (i
= 0; i
< pane_count
; ++i
)
2300 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2302 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2305 old_pane_rects
.Add(r
);
2311 // apply the new sizer
2312 m_frame
->SetSizer(sizer
);
2313 m_frame
->SetAutoLayout(false);
2318 // now that the frame layout is done, we need to check
2319 // the new pane rectangles against the old rectangles that
2320 // we saved a few lines above here. If the rectangles have
2321 // changed, the corresponding panes must also be updated
2322 for (i
= 0; i
< pane_count
; ++i
)
2324 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2325 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2327 if (p
.rect
!= old_pane_rects
[i
])
2329 p
.window
->Refresh();
2338 // set frame's minimum size
2341 // N.B. More work needs to be done on frame minimum sizes;
2342 // this is some intresting code that imposes the minimum size,
2343 // but we may want to include a more flexible mechanism or
2344 // options for multiple minimum-size modes, e.g. strict or lax
2345 wxSize min_size = sizer->GetMinSize();
2346 wxSize frame_size = m_frame->GetSize();
2347 wxSize client_size = m_frame->GetClientSize();
2349 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2350 min_size.y+frame_size.y-client_size.y );
2352 m_frame->SetMinSize(minframe_size);
2354 if (frame_size.x < minframe_size.x ||
2355 frame_size.y < minframe_size.y)
2356 sizer->Fit(m_frame);
2361 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2362 // on the frame's main sizer, then measures all the various UI items
2363 // and updates their internal rectangles. This should always be called
2364 // instead of calling m_frame->Layout() directly
2366 void wxAuiManager::DoFrameLayout()
2371 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2373 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2375 // get the rectangle of the UI part
2376 // originally, this code looked like this:
2377 // part.rect = wxRect(part.sizer_item->GetPosition(),
2378 // part.sizer_item->GetSize());
2379 // this worked quite well, with one exception: the mdi
2380 // client window had a "deferred" size variable
2381 // that returned the wrong size. It looks like
2382 // a bug in wx, because the former size of the window
2383 // was being returned. So, we will retrieve the part's
2384 // rectangle via other means
2387 part
.rect
= part
.sizer_item
->GetRect();
2388 int flag
= part
.sizer_item
->GetFlag();
2389 int border
= part
.sizer_item
->GetBorder();
2392 part
.rect
.y
-= border
;
2393 part
.rect
.height
+= border
;
2397 part
.rect
.x
-= border
;
2398 part
.rect
.width
+= border
;
2400 if (flag
& wxBOTTOM
)
2401 part
.rect
.height
+= border
;
2403 part
.rect
.width
+= border
;
2406 if (part
.type
== wxAuiDockUIPart::typeDock
)
2407 part
.dock
->rect
= part
.rect
;
2408 if (part
.type
== wxAuiDockUIPart::typePane
)
2409 part
.pane
->rect
= part
.rect
;
2413 // GetPanePart() looks up the pane the pane border UI part (or the regular
2414 // pane part if there is no border). This allows the caller to get the exact
2415 // rectangle of the pane in question, including decorations like
2416 // caption and border (if any).
2418 wxAuiDockUIPart
* wxAuiManager::GetPanePart(wxWindow
* wnd
)
2421 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2423 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2424 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
2425 part
.pane
&& part
.pane
->window
== wnd
)
2428 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2430 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2431 if (part
.type
== wxAuiDockUIPart::typePane
&&
2432 part
.pane
&& part
.pane
->window
== wnd
)
2440 // GetDockPixelOffset() is an internal function which returns
2441 // a dock's offset in pixels from the left side of the window
2442 // (for horizontal docks) or from the top of the window (for
2443 // vertical docks). This value is necessary for calculating
2444 // fixel-pane/toolbar offsets when they are dragged.
2446 int wxAuiManager::GetDockPixelOffset(wxAuiPaneInfo
& test
)
2448 // the only way to accurately calculate the dock's
2449 // offset is to actually run a theoretical layout
2451 int i
, part_count
, dock_count
;
2452 wxAuiDockInfoArray docks
;
2453 wxAuiPaneInfoArray panes
;
2454 wxAuiDockUIPartArray uiparts
;
2455 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2458 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2459 wxSize client_size
= m_frame
->GetClientSize();
2460 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2463 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2465 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
2466 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2467 part
.sizer_item
->GetSize());
2468 if (part
.type
== wxAuiDockUIPart::typeDock
)
2469 part
.dock
->rect
= part
.rect
;
2474 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2476 wxAuiDockInfo
& dock
= docks
.Item(i
);
2477 if (test
.dock_direction
== dock
.dock_direction
&&
2478 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2480 if (dock
.IsVertical())
2492 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2493 // if a dock operation is allowed, the new dock position is copied into
2494 // the target info. If the operation was allowed, the function returns true.
2496 bool wxAuiManager::ProcessDockResult(wxAuiPaneInfo
& target
,
2497 const wxAuiPaneInfo
& new_pos
)
2499 bool allowed
= false;
2500 switch (new_pos
.dock_direction
)
2502 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2503 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2504 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2505 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2515 // DoDrop() is an important function. It basically takes a mouse position,
2516 // and determines where the pane's new position would be. If the pane is to be
2517 // dropped, it performs the drop operation using the specified dock and pane
2518 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2519 // scenario can be performed, giving precise coordinates for drop hints.
2520 // If, however, wxAuiManager:m_docks and wxAuiManager::m_panes are specified
2521 // as parameters, the changes will be made to the main state arrays
2523 const int auiInsertRowPixels
= 10;
2524 const int auiNewRowPixels
= 40;
2525 const int auiLayerInsertPixels
= 40;
2526 const int auiLayerInsertOffset
= 5;
2528 bool wxAuiManager::DoDrop(wxAuiDockInfoArray
& docks
,
2529 wxAuiPaneInfoArray
& panes
,
2530 wxAuiPaneInfo
& target
,
2532 const wxPoint
& offset
)
2534 wxSize cli_size
= m_frame
->GetClientSize();
2536 wxAuiPaneInfo drop
= target
;
2539 // The result should always be shown
2543 // Check to see if the pane has been dragged outside of the window
2544 // (or near to the outside of the window), if so, dock it along the edge
2547 int layer_insert_offset
= auiLayerInsertOffset
;
2548 if (target
.IsToolbar())
2549 layer_insert_offset
= 0;
2551 if (pt
.x
< layer_insert_offset
&&
2552 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2554 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2555 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2556 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2560 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2561 return ProcessDockResult(target
, drop
);
2563 else if (pt
.y
< layer_insert_offset
&&
2564 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2566 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2567 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2568 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2572 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2573 return ProcessDockResult(target
, drop
);
2575 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2576 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2578 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2579 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2580 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2582 drop
.Dock().Right().
2585 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2586 return ProcessDockResult(target
, drop
);
2588 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2589 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2591 int new_layer
= wxMax( wxMax( GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2592 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2593 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2595 drop
.Dock().Bottom().
2598 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2599 return ProcessDockResult(target
, drop
);
2602 wxAuiDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2605 if (drop
.IsToolbar())
2607 if (!part
|| !part
->dock
)
2610 // calculate the offset from where the dock begins
2611 // to the point where the user dropped the pane
2612 int dock_drop_offset
= 0;
2613 if (part
->dock
->IsHorizontal())
2614 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2616 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2619 // toolbars may only be moved in and to fixed-pane docks,
2620 // otherwise we will try to float the pane. Also, the pane
2621 // should float if being dragged over center pane windows
2622 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2624 if (m_last_rect
.IsEmpty() || m_last_rect
.Contains(pt
.x
, pt
.y
))
2630 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2631 (drop
.IsFloatable() ||
2632 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2633 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2640 return ProcessDockResult(target
, drop
);
2643 drop
.Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2645 return ProcessDockResult(target
, drop
);
2654 m_last_rect
= part
->dock
->rect
;
2655 m_last_rect
.Inflate( 15, 15 );
2659 Direction(part
->dock
->dock_direction
).
2660 Layer(part
->dock
->dock_layer
).
2661 Row(part
->dock
->dock_row
).
2662 Position(dock_drop_offset
);
2665 ((pt
.y
< part
->dock
->rect
.y
+ 1) && part
->dock
->IsHorizontal()) ||
2666 ((pt
.x
< part
->dock
->rect
.x
+ 1) && part
->dock
->IsVertical())
2667 ) && part
->dock
->panes
.GetCount() > 1)
2669 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2670 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2672 int row
= drop
.dock_row
;
2673 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2674 part
->dock
->dock_layer
,
2675 part
->dock
->dock_row
);
2676 drop
.dock_row
= row
;
2680 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2681 part
->dock
->dock_layer
,
2682 part
->dock
->dock_row
+1);
2683 drop
.dock_row
= part
->dock
->dock_row
+1;
2688 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2689 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2690 ) && part
->dock
->panes
.GetCount() > 1)
2692 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2693 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2695 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2696 part
->dock
->dock_layer
,
2697 part
->dock
->dock_row
+1);
2698 drop
.dock_row
= part
->dock
->dock_row
+1;
2702 int row
= drop
.dock_row
;
2703 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2704 part
->dock
->dock_layer
,
2705 part
->dock
->dock_row
);
2706 drop
.dock_row
= row
;
2710 return ProcessDockResult(target
, drop
);
2719 if (part
->type
== wxAuiDockUIPart::typePaneBorder
||
2720 part
->type
== wxAuiDockUIPart::typeCaption
||
2721 part
->type
== wxAuiDockUIPart::typeGripper
||
2722 part
->type
== wxAuiDockUIPart::typePaneButton
||
2723 part
->type
== wxAuiDockUIPart::typePane
||
2724 part
->type
== wxAuiDockUIPart::typePaneSizer
||
2725 part
->type
== wxAuiDockUIPart::typeDockSizer
||
2726 part
->type
== wxAuiDockUIPart::typeBackground
)
2728 if (part
->type
== wxAuiDockUIPart::typeDockSizer
)
2730 if (part
->dock
->panes
.GetCount() != 1)
2732 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2739 // If a normal frame is being dragged over a toolbar, insert it
2740 // along the edge under the toolbar, but over all other panes.
2741 // (this could be done much better, but somehow factoring this
2742 // calculation with the one at the beginning of this function)
2743 if (part
->dock
&& part
->dock
->toolbar
)
2747 switch (part
->dock
->dock_direction
)
2749 case wxAUI_DOCK_LEFT
:
2750 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2751 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2752 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2754 case wxAUI_DOCK_TOP
:
2755 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2756 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2757 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2759 case wxAUI_DOCK_RIGHT
:
2760 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2761 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2762 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2764 case wxAUI_DOCK_BOTTOM
:
2765 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2766 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2767 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2771 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2774 Direction(part
->dock
->dock_direction
).
2775 Layer(layer
).Row(0).Position(0);
2776 return ProcessDockResult(target
, drop
);
2783 part
= GetPanePart(part
->pane
->window
);
2787 bool insert_dock_row
= false;
2788 int insert_row
= part
->pane
->dock_row
;
2789 int insert_dir
= part
->pane
->dock_direction
;
2790 int insert_layer
= part
->pane
->dock_layer
;
2792 switch (part
->pane
->dock_direction
)
2794 case wxAUI_DOCK_TOP
:
2795 if (pt
.y
>= part
->rect
.y
&&
2796 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2797 insert_dock_row
= true;
2799 case wxAUI_DOCK_BOTTOM
:
2800 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2801 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2802 insert_dock_row
= true;
2804 case wxAUI_DOCK_LEFT
:
2805 if (pt
.x
>= part
->rect
.x
&&
2806 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2807 insert_dock_row
= true;
2809 case wxAUI_DOCK_RIGHT
:
2810 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2811 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2812 insert_dock_row
= true;
2814 case wxAUI_DOCK_CENTER
:
2816 // "new row pixels" will be set to the default, but
2817 // must never exceed 20% of the window size
2818 int new_row_pixels_x
= auiNewRowPixels
;
2819 int new_row_pixels_y
= auiNewRowPixels
;
2821 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2822 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2824 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2825 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2828 // determine if the mouse pointer is in a location that
2829 // will cause a new row to be inserted. The hot spot positions
2830 // are along the borders of the center pane
2833 insert_dock_row
= true;
2834 if (pt
.x
>= part
->rect
.x
&&
2835 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2836 insert_dir
= wxAUI_DOCK_LEFT
;
2838 if (pt
.y
>= part
->rect
.y
&&
2839 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2840 insert_dir
= wxAUI_DOCK_TOP
;
2842 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2843 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2844 insert_dir
= wxAUI_DOCK_RIGHT
;
2846 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2847 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2848 insert_dir
= wxAUI_DOCK_BOTTOM
;
2852 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2856 if (insert_dock_row
)
2858 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2859 drop
.Dock().Direction(insert_dir
).
2860 Layer(insert_layer
).
2863 return ProcessDockResult(target
, drop
);
2866 // determine the mouse offset and the pane size, both in the
2867 // direction of the dock itself, and perpendicular to the dock
2871 if (part
->orientation
== wxVERTICAL
)
2873 offset
= pt
.y
- part
->rect
.y
;
2874 size
= part
->rect
.GetHeight();
2878 offset
= pt
.x
- part
->rect
.x
;
2879 size
= part
->rect
.GetWidth();
2882 int drop_position
= part
->pane
->dock_pos
;
2884 // if we are in the top/left part of the pane,
2885 // insert the pane before the pane being hovered over
2886 if (offset
<= size
/2)
2888 drop_position
= part
->pane
->dock_pos
;
2890 part
->pane
->dock_direction
,
2891 part
->pane
->dock_layer
,
2892 part
->pane
->dock_row
,
2893 part
->pane
->dock_pos
);
2896 // if we are in the bottom/right part of the pane,
2897 // insert the pane before the pane being hovered over
2898 if (offset
> size
/2)
2900 drop_position
= part
->pane
->dock_pos
+1;
2902 part
->pane
->dock_direction
,
2903 part
->pane
->dock_layer
,
2904 part
->pane
->dock_row
,
2905 part
->pane
->dock_pos
+1);
2909 Direction(part
->dock
->dock_direction
).
2910 Layer(part
->dock
->dock_layer
).
2911 Row(part
->dock
->dock_row
).
2912 Position(drop_position
);
2913 return ProcessDockResult(target
, drop
);
2920 void wxAuiManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2922 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
2924 m_hint_fadetimer
.Stop();
2928 m_hint_fadeamt
+= 4;
2929 #if wxCHECK_VERSION(2,7,0)
2930 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2932 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2933 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2937 void wxAuiManager::ShowHint(const wxRect
& rect
)
2941 // if the hint rect is the same as last time, don't do anything
2942 if (m_last_hint
== rect
)
2946 m_hint_fadeamt
= m_hint_fademax
;
2948 if ((m_flags
& wxAUI_MGR_HINT_FADE
)
2949 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2950 (m_flags
& wxAUI_MGR_NO_VENETIAN_BLINDS_FADE
))
2954 m_hint_wnd
->SetSize(rect
);
2956 if (!m_hint_wnd
->IsShown())
2959 // if we are dragging a floating pane, set the focus
2960 // back to that floating pane (otherwise it becomes unfocused)
2961 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2962 m_action_window
->SetFocus();
2964 #if wxCHECK_VERSION(2,7,0)
2965 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2967 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2968 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2970 m_hint_wnd
->Raise();
2973 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
2975 // start fade in timer
2976 m_hint_fadetimer
.SetOwner(this, 101);
2977 m_hint_fadetimer
.Start(5);
2980 else // Not using a transparent hint window...
2982 if (!(m_flags
& wxAUI_MGR_RECTANGLE_HINT
))
2985 if (m_last_hint
!= rect
)
2987 // remove the last hint rectangle
2993 wxScreenDC screendc
;
2994 wxRegion
clip(1, 1, 10000, 10000);
2996 // clip all floating windows, so we don't draw over them
2998 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
3000 wxAuiPaneInfo
& pane
= m_panes
.Item(i
);
3002 if (pane
.IsFloating() &&
3003 pane
.frame
->IsShown())
3005 wxRect rect
= pane
.frame
->GetRect();
3007 // wxGTK returns the client size, not the whole frame size
3013 clip
.Subtract(rect
);
3017 // As we can only hide the hint by redrawing the managed window, we
3018 // need to clip the region to the managed window too or we get
3019 // nasty redrawn problems.
3020 clip
.Intersect(m_frame
->GetRect());
3022 screendc
.SetClippingRegion(clip
);
3024 wxBitmap stipple
= wxPaneCreateStippleBitmap();
3025 wxBrush
brush(stipple
);
3026 screendc
.SetBrush(brush
);
3027 screendc
.SetPen(*wxTRANSPARENT_PEN
);
3029 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
3030 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
3031 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
3032 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
3036 void wxAuiManager::HideHint()
3038 // hides a transparent window hint, if there is one
3041 if (m_hint_wnd
->IsShown())
3042 m_hint_wnd
->Show(false);
3043 #if wxCHECK_VERSION(2,7,0)
3044 m_hint_wnd
->SetTransparent(0);
3046 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
3047 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(0);
3049 m_hint_fadetimer
.Stop();
3050 m_last_hint
= wxRect();
3054 // hides a painted hint by redrawing the frame window
3055 if (!m_last_hint
.IsEmpty())
3059 m_last_hint
= wxRect();
3066 // CalculateHintRect() calculates the drop hint rectangle. The method
3067 // first calls DoDrop() to determine the exact position the pane would
3068 // be at were if dropped. If the pane would indeed become docked at the
3069 // specified drop point, the the rectangle hint will be returned in
3070 // screen coordinates. Otherwise, an empty rectangle is returned.
3071 // |pane_window| is the window pointer of the pane being dragged, |pt| is
3072 // the mouse position, in client coordinates. |offset| describes the offset
3073 // that the mouse is from the upper-left corner of the item being dragged
3075 wxRect
wxAuiManager::CalculateHintRect(wxWindow
* pane_window
,
3077 const wxPoint
& offset
)
3081 // we need to paint a hint rectangle; to find out the exact hint rectangle,
3082 // we will create a new temporary layout and then measure the resulting
3083 // rectangle; we will create a copy of the docking structures (m_dock)
3084 // so that we don't modify the real thing on screen
3086 int i
, pane_count
, part_count
;
3087 wxAuiDockInfoArray docks
;
3088 wxAuiPaneInfoArray panes
;
3089 wxAuiDockUIPartArray uiparts
;
3090 wxAuiPaneInfo hint
= GetPane(pane_window
);
3091 hint
.name
= wxT("__HINT__");
3097 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3099 // remove any pane already there which bears the same window;
3100 // this happens when you are moving a pane around in a dock
3101 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
3103 if (panes
.Item(i
).window
== pane_window
)
3105 RemovePaneFromDocks(docks
, panes
.Item(i
));
3111 // find out where the new pane would be
3112 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
3119 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
3120 wxSize client_size
= m_frame
->GetClientSize();
3121 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
3124 for (i
= 0, part_count
= uiparts
.GetCount();
3125 i
< part_count
; ++i
)
3127 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
3129 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
3130 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
3132 rect
= wxRect(part
.sizer_item
->GetPosition(),
3133 part
.sizer_item
->GetSize());
3145 // actually show the hint rectangle on the screen
3146 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
3151 // DrawHintRect() calculates the hint rectangle by calling
3152 // CalculateHintRect(). If there is a rectangle, it shows it
3153 // by calling ShowHint(), otherwise it hides any hint
3154 // rectangle currently shown
3155 void wxAuiManager::DrawHintRect(wxWindow
* pane_window
,
3157 const wxPoint
& offset
)
3159 wxRect rect
= CalculateHintRect(pane_window
, pt
, offset
);
3171 void wxAuiManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
3173 // try to find the pane
3174 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3175 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3177 #if wxCHECK_VERSION(2,7,0)
3178 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3179 pane
.frame
->SetTransparent(150);
3183 void wxAuiManager::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
3185 // try to find the pane
3186 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3187 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3189 wxPoint pt
= ::wxGetMousePosition();
3192 // Adapt pt to direction
3195 // move to pane's upper border
3197 pos
= wnd
->ClientToScreen( pos
);
3199 // and some more pixels for the title bar
3204 // move to pane's left border
3206 pos
= wnd
->ClientToScreen( pos
);
3211 // move to pane's right border
3212 wxPoint
pos( wnd
->GetSize().x
, 0 );
3213 pos
= wnd
->ClientToScreen( pos
);
3218 // move to pane's bottom border
3219 wxPoint
pos( 0, wnd
->GetSize().y
);
3220 pos
= wnd
->ClientToScreen( pos
);
3227 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3229 // calculate the offset from the upper left-hand corner
3230 // of the frame to the mouse pointer
3231 wxPoint frame_pos
= pane
.frame
->GetPosition();
3232 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3234 // no hint for toolbar floating windows
3235 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
3237 if (m_action
== actionDragFloatingPane
)
3239 wxAuiDockInfoArray docks
;
3240 wxAuiPaneInfoArray panes
;
3241 wxAuiDockUIPartArray uiparts
;
3242 wxAuiPaneInfo hint
= pane
;
3244 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3246 // find out where the new pane would be
3247 if (!DoDrop(docks
, panes
, hint
, client_pt
))
3249 if (hint
.IsFloating())
3253 m_action
= actionDragToolbarPane
;
3254 m_action_window
= pane
.window
;
3263 // if a key modifier is pressed while dragging the frame,
3264 // don't dock the window
3265 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
3272 DrawHintRect(wnd
, client_pt
, action_offset
);
3275 // this cleans up some screen artifacts that are caused on GTK because
3276 // we aren't getting the exact size of the window (see comment
3286 void wxAuiManager::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
3288 // try to find the pane
3289 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3290 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3292 wxPoint pt
= ::wxGetMousePosition();
3295 // Adapt pt to direction
3298 // move to pane's upper border
3300 pos
= wnd
->ClientToScreen( pos
);
3302 // and some more pixels for the title bar
3307 // move to pane's left border
3309 pos
= wnd
->ClientToScreen( pos
);
3314 // move to pane's right border
3315 wxPoint
pos( wnd
->GetSize().x
, 0 );
3316 pos
= wnd
->ClientToScreen( pos
);
3321 // move to pane's bottom border
3322 wxPoint
pos( 0, wnd
->GetSize().y
);
3323 pos
= wnd
->ClientToScreen( pos
);
3330 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3332 // calculate the offset from the upper left-hand corner
3333 // of the frame to the mouse pointer
3334 wxPoint frame_pos
= pane
.frame
->GetPosition();
3335 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3338 // if a key modifier is pressed while dragging the frame,
3339 // don't dock the window
3340 if (!wxGetKeyState(WXK_CONTROL
) && !wxGetKeyState(WXK_ALT
))
3342 // do the drop calculation
3343 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3346 // if the pane is still floating, update it's floating
3347 // position (that we store)
3348 if (pane
.IsFloating())
3350 pane
.floating_pos
= pane
.frame
->GetPosition();
3352 #if wxCHECK_VERSION(2,7,0)
3353 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3354 pane
.frame
->SetTransparent(255);
3356 } else if(m_has_maximized
) {
3357 RestoreMaximizedPane();
3365 void wxAuiManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3367 // try to find the pane
3368 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3369 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3371 pane
.floating_size
= size
;
3375 void wxAuiManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3377 // try to find the pane
3378 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3379 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3382 // fire pane close event
3383 wxAuiManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3385 e
.SetCanVeto(evt
.CanVeto());
3401 void wxAuiManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3403 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3405 // try to find the pane
3406 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
3408 SetActivePane(m_panes
, wnd
);
3413 // OnRender() draws all of the pane captions, sashes,
3414 // backgrounds, captions, grippers, pane borders and buttons.
3415 // It renders the entire user interface.
3417 void wxAuiManager::OnRender(wxAuiManagerEvent
& evt
)
3419 wxDC
* dc
= evt
.GetDC();
3425 for (i
= 0, part_count
= m_uiparts
.GetCount();
3426 i
< part_count
; ++i
)
3428 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
3430 // don't draw hidden pane items
3431 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
3436 case wxAuiDockUIPart::typeDockSizer
:
3437 case wxAuiDockUIPart::typePaneSizer
:
3438 m_art
->DrawSash(*dc
, m_frame
, part
.orientation
, part
.rect
);
3440 case wxAuiDockUIPart::typeBackground
:
3441 m_art
->DrawBackground(*dc
, m_frame
, part
.orientation
, part
.rect
);
3443 case wxAuiDockUIPart::typeCaption
:
3444 m_art
->DrawCaption(*dc
, m_frame
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3446 case wxAuiDockUIPart::typeGripper
:
3447 m_art
->DrawGripper(*dc
, m_frame
, part
.rect
, *part
.pane
);
3449 case wxAuiDockUIPart::typePaneBorder
:
3450 m_art
->DrawBorder(*dc
, m_frame
, part
.rect
, *part
.pane
);
3452 case wxAuiDockUIPart::typePaneButton
:
3453 m_art
->DrawPaneButton(*dc
, m_frame
, part
.button
->button_id
,
3454 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3461 // Render() fire a render event, which is normally handled by
3462 // wxAuiManager::OnRender(). This allows the render function to
3463 // be overridden via the render event. This can be useful for paintin
3464 // custom graphics in the main window. Default behavior can be
3465 // invoked in the overridden function by calling OnRender()
3467 void wxAuiManager::Render(wxDC
* dc
)
3469 wxAuiManagerEvent
e(wxEVT_AUI_RENDER
);
3474 void wxAuiManager::Repaint(wxDC
* dc
)
3479 m_frame
->Refresh() ;
3485 m_frame
->GetClientSize(&w
, &h
);
3487 // figure out which dc to use; if one
3488 // has been specified, use it, otherwise
3490 wxClientDC
* client_dc
= NULL
;
3493 client_dc
= new wxClientDC(m_frame
);
3497 // if the frame has a toolbar, the client area
3498 // origin will not be (0,0).
3499 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3500 if (pt
.x
!= 0 || pt
.y
!= 0)
3501 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3503 // render all the items
3506 // if we created a client_dc, delete it
3511 void wxAuiManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3513 wxPaintDC
dc(m_frame
);
3517 void wxAuiManager::OnEraseBackground(wxEraseEvent
& event
)
3526 void wxAuiManager::OnSize(wxSizeEvent
& event
)
3534 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
3536 // for MDI parent frames, this event must not
3537 // be "skipped". In other words, the parent frame
3538 // must not be allowed to resize the client window
3539 // after we are finished processing sizing changes
3548 void wxAuiManager::OnSetCursor(wxSetCursorEvent
& event
)
3551 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3552 wxCursor cursor
= wxNullCursor
;
3556 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3557 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3559 // a dock may not be resized if it has a single
3560 // pane which is not resizable
3561 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3562 part
->dock
->panes
.GetCount() == 1 &&
3563 part
->dock
->panes
.Item(0)->IsFixed())
3566 // panes that may not be resized do not get a sizing cursor
3567 if (part
->pane
&& part
->pane
->IsFixed())
3570 if (part
->orientation
== wxVERTICAL
)
3571 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3573 cursor
= wxCursor(wxCURSOR_SIZENS
);
3575 else if (part
->type
== wxAuiDockUIPart::typeGripper
)
3577 cursor
= wxCursor(wxCURSOR_SIZING
);
3581 event
.SetCursor(cursor
);
3586 void wxAuiManager::UpdateButtonOnScreen(wxAuiDockUIPart
* button_ui_part
,
3587 const wxMouseEvent
& event
)
3589 wxAuiDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3590 if (!hit_test
|| !button_ui_part
)
3593 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3595 if (hit_test
== button_ui_part
)
3597 if (event
.LeftDown())
3598 state
= wxAUI_BUTTON_STATE_PRESSED
;
3600 state
= wxAUI_BUTTON_STATE_HOVER
;
3604 if (event
.LeftDown())
3605 state
= wxAUI_BUTTON_STATE_HOVER
;
3608 // now repaint the button with hover state
3609 wxClientDC
cdc(m_frame
);
3611 // if the frame has a toolbar, the client area
3612 // origin will not be (0,0).
3613 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3614 if (pt
.x
!= 0 || pt
.y
!= 0)
3615 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3619 m_art
->DrawPaneButton(cdc
, m_frame
,
3620 button_ui_part
->button
->button_id
,
3622 button_ui_part
->rect
,
3627 void wxAuiManager::OnLeftDown(wxMouseEvent
& event
)
3629 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3632 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3633 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3635 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3638 // a dock may not be resized if it has a single
3639 // pane which is not resizable
3640 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3641 part
->dock
->panes
.GetCount() == 1 &&
3642 part
->dock
->panes
.Item(0)->IsFixed())
3645 // panes that may not be resized should be ignored here
3646 if (part
->pane
&& part
->pane
->IsFixed())
3649 m_action
= actionResize
;
3650 m_action_part
= part
;
3651 m_action_hintrect
= wxRect();
3652 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3653 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3654 event
.m_y
- part
->rect
.y
);
3655 m_frame
->CaptureMouse();
3657 else if (part
->type
== wxAuiDockUIPart::typePaneButton
)
3659 m_action
= actionClickButton
;
3660 m_action_part
= part
;
3661 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3662 m_frame
->CaptureMouse();
3664 UpdateButtonOnScreen(part
, event
);
3666 else if (part
->type
== wxAuiDockUIPart::typeCaption
||
3667 part
->type
== wxAuiDockUIPart::typeGripper
)
3669 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3672 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3674 // set the caption as active
3675 SetActivePane(m_panes
, part
->pane
->window
);
3679 m_action
= actionClickCaption
;
3680 m_action_part
= part
;
3681 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3682 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3683 event
.m_y
- part
->rect
.y
);
3684 m_frame
->CaptureMouse();
3704 void wxAuiManager::OnLeftUp(wxMouseEvent
& event
)
3706 if (m_action
== actionResize
)
3708 m_frame
->ReleaseMouse();
3710 // get rid of the hint rectangle
3712 DrawResizeHint(dc
, m_action_hintrect
);
3714 // resize the dock or the pane
3715 if (m_action_part
&& m_action_part
->type
==wxAuiDockUIPart::typeDockSizer
)
3717 wxRect
& rect
= m_action_part
->dock
->rect
;
3719 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3720 event
.m_y
- m_action_offset
.y
);
3722 switch (m_action_part
->dock
->dock_direction
)
3724 case wxAUI_DOCK_LEFT
:
3725 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3727 case wxAUI_DOCK_TOP
:
3728 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3730 case wxAUI_DOCK_RIGHT
:
3731 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3732 new_pos
.x
- m_action_part
->rect
.GetWidth();
3734 case wxAUI_DOCK_BOTTOM
:
3735 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3736 new_pos
.y
- m_action_part
->rect
.GetHeight();
3743 else if (m_action_part
&&
3744 m_action_part
->type
== wxAuiDockUIPart::typePaneSizer
)
3746 wxAuiDockInfo
& dock
= *m_action_part
->dock
;
3747 wxAuiPaneInfo
& pane
= *m_action_part
->pane
;
3749 int total_proportion
= 0;
3750 int dock_pixels
= 0;
3751 int new_pixsize
= 0;
3753 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3754 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3755 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3757 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3758 event
.m_y
- m_action_offset
.y
);
3760 // determine the pane rectangle by getting the pane part
3761 wxAuiDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3762 wxASSERT_MSG(pane_part
,
3763 wxT("Pane border part not found -- shouldn't happen"));
3765 // determine the new pixel size that the user wants;
3766 // this will help us recalculate the pane's proportion
3767 if (dock
.IsHorizontal())
3768 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3770 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3772 // determine the size of the dock, based on orientation
3773 if (dock
.IsHorizontal())
3774 dock_pixels
= dock
.rect
.GetWidth();
3776 dock_pixels
= dock
.rect
.GetHeight();
3778 // determine the total proportion of all resizable panes,
3779 // and the total size of the dock minus the size of all
3781 int i
, dock_pane_count
= dock
.panes
.GetCount();
3782 int pane_position
= -1;
3783 for (i
= 0; i
< dock_pane_count
; ++i
)
3785 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
3786 if (p
.window
== pane
.window
)
3789 // while we're at it, subtract the pane sash
3790 // width from the dock width, because this would
3791 // skew our proportion calculations
3793 dock_pixels
-= sash_size
;
3795 // also, the whole size (including decorations) of
3796 // all fixed panes must also be subtracted, because they
3797 // are not part of the proportion calculation
3800 if (dock
.IsHorizontal())
3801 dock_pixels
-= p
.best_size
.x
;
3803 dock_pixels
-= p
.best_size
.y
;
3807 total_proportion
+= p
.dock_proportion
;
3811 // find a pane in our dock to 'steal' space from or to 'give'
3812 // space to -- this is essentially what is done when a pane is
3813 // resized; the pane should usually be the first non-fixed pane
3814 // to the right of the action pane
3815 int borrow_pane
= -1;
3816 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3818 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
3827 // demand that the pane being resized is found in this dock
3828 // (this assert really never should be raised)
3829 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3831 // prevent division by zero
3832 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3834 m_action
= actionNone
;
3838 // calculate the new proportion of the pane
3839 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3841 // default minimum size
3844 // check against the pane's minimum size, if specified. please note
3845 // that this is not enough to ensure that the minimum size will
3846 // not be violated, because the whole frame might later be shrunk,
3847 // causing the size of the pane to violate it's minimum size
3848 if (pane
.min_size
.IsFullySpecified())
3852 if (pane
.HasBorder())
3853 min_size
+= (pane_border_size
*2);
3855 // calculate minimum size with decorations (border,caption)
3856 if (pane_part
->orientation
== wxVERTICAL
)
3858 min_size
+= pane
.min_size
.y
;
3859 if (pane
.HasCaption())
3860 min_size
+= caption_size
;
3864 min_size
+= pane
.min_size
.x
;
3869 // for some reason, an arithmatic error somewhere is causing
3870 // the proportion calculations to always be off by 1 pixel;
3871 // for now we will add the 1 pixel on, but we really should
3872 // determine what's causing this.
3875 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3877 if (new_proportion
< min_proportion
)
3878 new_proportion
= min_proportion
;
3882 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3884 // borrow the space from our neighbor pane to the
3885 // right or bottom (depending on orientation)
3886 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3887 pane
.dock_proportion
= new_proportion
;
3894 else if (m_action
== actionClickButton
)
3896 m_hover_button
= NULL
;
3897 m_frame
->ReleaseMouse();
3898 UpdateButtonOnScreen(m_action_part
, event
);
3900 // make sure we're still over the item that was originally clicked
3901 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3903 // fire button-click event
3904 wxAuiManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3905 e
.SetPane(m_action_part
->pane
);
3906 e
.SetButton(m_action_part
->button
->button_id
);
3910 else if (m_action
== actionClickCaption
)
3912 m_frame
->ReleaseMouse();
3914 else if (m_action
== actionDragFloatingPane
)
3916 m_frame
->ReleaseMouse();
3918 else if (m_action
== actionDragToolbarPane
)
3920 m_frame
->ReleaseMouse();
3922 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
3923 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3925 // save the new positions
3926 wxAuiDockInfoPtrArray docks
;
3927 FindDocks(m_docks
, pane
.dock_direction
,
3928 pane
.dock_layer
, pane
.dock_row
, docks
);
3929 if (docks
.GetCount() == 1)
3931 wxAuiDockInfo
& dock
= *docks
.Item(0);
3933 wxArrayInt pane_positions
, pane_sizes
;
3934 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3936 int i
, dock_pane_count
= dock
.panes
.GetCount();
3937 for (i
= 0; i
< dock_pane_count
; ++i
)
3938 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3941 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
3949 m_action
= actionNone
;
3950 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3954 void wxAuiManager::OnMotion(wxMouseEvent
& event
)
3956 // sometimes when Update() is called from inside this method,
3957 // a spurious mouse move event is generated; this check will make
3958 // sure that only real mouse moves will get anywhere in this method;
3959 // this appears to be a bug somewhere, and I don't know where the
3960 // mouse move event is being generated. only verified on MSW
3962 wxPoint mouse_pos
= event
.GetPosition();
3963 if (m_last_mouse_move
== mouse_pos
)
3965 m_last_mouse_move
= mouse_pos
;
3968 if (m_action
== actionResize
)
3970 wxPoint pos
= m_action_part
->rect
.GetPosition();
3971 if (m_action_part
->orientation
== wxHORIZONTAL
)
3972 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3974 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3976 wxRect
rect(m_frame
->ClientToScreen(pos
),
3977 m_action_part
->rect
.GetSize());
3980 if (!m_action_hintrect
.IsEmpty())
3981 DrawResizeHint(dc
, m_action_hintrect
);
3982 DrawResizeHint(dc
, rect
);
3983 m_action_hintrect
= rect
;
3985 else if (m_action
== actionClickCaption
)
3987 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3988 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3990 // caption has been clicked. we need to check if the mouse
3991 // is now being dragged. if it is, we need to change the
3992 // mouse action to 'drag'
3993 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3994 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3996 wxAuiPaneInfo
* pane_info
= m_action_part
->pane
;
3998 if (!pane_info
->IsToolbar())
4000 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
4001 pane_info
->IsFloatable())
4003 m_action
= actionDragFloatingPane
;
4005 // set initial float position
4006 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4007 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4008 pt
.y
- m_action_offset
.y
);
4011 if(pane_info
->IsMaximized()) {
4012 RestorePane(*pane_info
);
4017 m_action_window
= pane_info
->frame
;
4019 // action offset is used here to make it feel "natural" to the user
4020 // to drag a docked pane and suddenly have it become a floating frame.
4021 // Sometimes, however, the offset where the user clicked on the docked
4022 // caption is bigger than the width of the floating frame itself, so
4023 // in that case we need to set the action offset to a sensible value
4024 wxSize frame_size
= m_action_window
->GetSize();
4025 if (frame_size
.x
<= m_action_offset
.x
)
4026 m_action_offset
.x
= 30;
4031 m_action
= actionDragToolbarPane
;
4032 m_action_window
= pane_info
->window
;
4036 else if (m_action
== actionDragFloatingPane
)
4038 if(m_action_window
) {
4039 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4040 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
4041 pt
.y
- m_action_offset
.y
);
4044 else if (m_action
== actionDragToolbarPane
)
4046 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4047 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4049 pane
.state
|= wxAuiPaneInfo::actionPane
;
4051 wxPoint pt
= event
.GetPosition();
4052 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
4054 // if DoDrop() decided to float the pane, set up
4055 // the floating pane's initial position
4056 if (pane
.IsFloating())
4058 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4059 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4060 pt
.y
- m_action_offset
.y
);
4063 // this will do the actiual move operation;
4064 // in the case that the pane has been floated,
4065 // this call will create the floating pane
4066 // and do the reparenting
4069 // if the pane has been floated, change the mouse
4070 // action actionDragFloatingPane so that subsequent
4071 // EVT_MOTION() events will move the floating pane
4072 if (pane
.IsFloating())
4074 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
4075 m_action
= actionDragFloatingPane
;
4076 m_action_window
= pane
.frame
;
4081 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
4082 if (part
&& part
->type
== wxAuiDockUIPart::typePaneButton
)
4084 if (part
!= m_hover_button
)
4086 // make the old button normal
4089 UpdateButtonOnScreen(m_hover_button
, event
);
4093 // mouse is over a button, so repaint the
4094 // button in hover mode
4095 UpdateButtonOnScreen(part
, event
);
4096 m_hover_button
= part
;
4104 m_hover_button
= NULL
;
4115 void wxAuiManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
4119 m_hover_button
= NULL
;
4124 void wxAuiManager::OnChildFocus(wxChildFocusEvent
& event
)
4126 // when a child pane has it's focus set, we should change the
4127 // pane's active state to reflect this. (this is only true if
4128 // active panes are allowed by the owner)
4129 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
4131 if (GetPane(event
.GetWindow()).IsOk())
4133 SetActivePane(m_panes
, event
.GetWindow());
4142 // OnPaneButton() is an event handler that is called
4143 // when a pane button has been pressed.
4144 void wxAuiManager::OnPaneButton(wxAuiManagerEvent
& evt
)
4146 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxAuiManager::OnPaneButton must be non-null"));
4148 wxAuiPaneInfo
& pane
= *(evt
.pane
);
4150 if (evt
.button
== wxAUI_BUTTON_CLOSE
)
4152 // fire pane close event
4153 wxAuiManagerEvent
e(wxEVT_AUI_PANECLOSE
);
4154 e
.SetPane(evt
.pane
);
4163 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& !pane
.IsMaximized())
4165 // fire pane close event
4166 wxAuiManagerEvent
e(wxEVT_AUI_PANEMAXIMIZE
);
4167 e
.SetPane(evt
.pane
);
4176 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& pane
.IsMaximized())
4178 // fire pane close event
4179 wxAuiManagerEvent
e(wxEVT_AUI_PANERESTORE
);
4180 e
.SetPane(evt
.pane
);
4189 else if (evt
.button
== wxAUI_BUTTON_PIN
)
4191 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&