1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/framemanager.cpp
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
8 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/aui/framemanager.h"
29 #include "wx/aui/dockart.h"
30 #include "wx/aui/floatpane.h"
34 #include "wx/settings.h"
36 #include "wx/dcclient.h"
37 #include "wx/dcscreen.h"
38 #include "wx/toolbar.h"
43 WX_CHECK_BUILD_OPTIONS("wxAUI")
45 #include "wx/arrimpl.cpp"
46 WX_DECLARE_OBJARRAY(wxRect
, wxAuiRectArray
);
47 WX_DEFINE_OBJARRAY(wxAuiRectArray
)
48 WX_DEFINE_OBJARRAY(wxDockUIPartArray
)
49 WX_DEFINE_OBJARRAY(wxDockInfoArray
)
50 WX_DEFINE_OBJARRAY(wxPaneButtonArray
)
51 WX_DEFINE_OBJARRAY(wxPaneInfoArray
)
53 wxPaneInfo wxNullPaneInfo
;
54 wxDockInfo wxNullDockInfo
;
55 DEFINE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON
)
56 DEFINE_EVENT_TYPE(wxEVT_AUI_PANECLOSE
)
57 DEFINE_EVENT_TYPE(wxEVT_AUI_RENDER
)
60 // a few defines to avoid nameclashes
61 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
63 #include "wx/mac/private.h"
66 IMPLEMENT_DYNAMIC_CLASS(wxFrameManagerEvent
, wxEvent
)
68 class wxPseudoTransparentFrame
: public wxFrame
71 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
72 wxWindowID id
= wxID_ANY
,
73 const wxString
& title
= wxEmptyString
,
74 const wxPoint
& pos
= wxDefaultPosition
,
75 const wxSize
& size
= wxDefaultSize
,
76 long style
= wxDEFAULT_FRAME_STYLE
,
77 const wxString
&name
= wxT("frame"))
78 : wxFrame(parent
, id
, title
, pos
, size
, style
| wxFRAME_SHAPED
, name
)
80 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
87 m_CanSetShape
= false; // have to wait for window create event on GTK
91 m_Region
= wxRegion(0, 0, 0, 0);
95 virtual bool SetTransparent(wxByte alpha
)
99 int w
=100; // some defaults
101 GetClientSize(&w
, &h
);
107 // m_Region.Union(0, 0, 1, m_MaxWidth);
110 for (int y
=0; y
<m_MaxHeight
; y
++)
112 // Reverse the order of the bottom 4 bits
113 int j
=((y
&8)?1:0)|((y
&4)?2:0)|((y
&2)?4:0)|((y
&1)?8:0);
114 if ((j
*16+8)<m_Amount
)
115 m_Region
.Union(0, y
, m_MaxWidth
, 1);
124 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
128 if (m_Region
.IsEmpty())
132 dc
.SetBrush(wxColour(128, 192, 255));
134 dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
136 dc
.SetPen(*wxTRANSPARENT_PEN
);
138 wxRegionIterator
upd(GetUpdateRegion()); // get the update rect list
142 wxRect
rect(upd
.GetRect());
143 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
150 void OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
)) {m_CanSetShape
=true; SetTransparent(0);}
153 void OnSize(wxSizeEvent
& event
)
155 // We sometimes get surplus size events
156 if ((event
.GetSize().GetWidth() == m_lastWidth
) &&
157 (event
.GetSize().GetHeight() == m_lastHeight
))
162 m_lastWidth
= event
.GetSize().GetWidth();
163 m_lastHeight
= event
.GetSize().GetHeight();
165 SetTransparent(m_Amount
);
166 m_Region
.Intersect(0, 0, event
.GetSize().GetWidth(),
167 event
.GetSize().GetHeight());
178 int m_lastWidth
,m_lastHeight
;
182 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
183 DECLARE_EVENT_TABLE()
187 IMPLEMENT_DYNAMIC_CLASS( wxPseudoTransparentFrame
, wxFrame
)
189 BEGIN_EVENT_TABLE(wxPseudoTransparentFrame
, wxFrame
)
190 EVT_PAINT(wxPseudoTransparentFrame::OnPaint
)
191 EVT_SIZE(wxPseudoTransparentFrame::OnSize
)
193 EVT_WINDOW_CREATE(wxPseudoTransparentFrame::OnWindowCreate
)
198 // -- static utility functions --
200 static wxBitmap
wxPaneCreateStippleBitmap()
202 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
203 wxImage
img(2,2,data
,true);
204 return wxBitmap(img
);
207 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
209 wxBitmap stipple
= wxPaneCreateStippleBitmap();
210 wxBrush
brush(stipple
);
212 dc
.SetPen(*wxTRANSPARENT_PEN
);
214 dc
.SetLogicalFunction(wxXOR
);
215 dc
.DrawRectangle(rect
);
220 // CopyDocksAndPanes() - this utility function creates copies of
221 // the dock and pane info. wxDockInfo's usually contain pointers
222 // to wxPaneInfo classes, thus this function is necessary to reliably
223 // reconstruct that relationship in the new dock info and pane info arrays
225 static void CopyDocksAndPanes(wxDockInfoArray
& dest_docks
,
226 wxPaneInfoArray
& dest_panes
,
227 const wxDockInfoArray
& src_docks
,
228 const wxPaneInfoArray
& src_panes
)
230 dest_docks
= src_docks
;
231 dest_panes
= src_panes
;
232 int i
, j
, k
, dock_count
, pc1
, pc2
;
233 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
235 wxDockInfo
& dock
= dest_docks
.Item(i
);
236 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
237 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
238 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
239 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
243 // GetMaxLayer() is an internal function which returns
244 // the highest layer inside the specified dock
245 static int GetMaxLayer(const wxDockInfoArray
& docks
, int dock_direction
)
247 int i
, dock_count
, max_layer
= 0;
248 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
250 wxDockInfo
& dock
= docks
.Item(i
);
251 if (dock
.dock_direction
== dock_direction
&&
252 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
253 max_layer
= dock
.dock_layer
;
259 // GetMaxRow() is an internal function which returns
260 // the highest layer inside the specified dock
261 static int GetMaxRow(const wxPaneInfoArray
& panes
, int direction
, int layer
)
263 int i
, pane_count
, max_row
= 0;
264 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
266 wxPaneInfo
& pane
= panes
.Item(i
);
267 if (pane
.dock_direction
== direction
&&
268 pane
.dock_layer
== layer
&&
269 pane
.dock_row
> max_row
)
270 max_row
= pane
.dock_row
;
277 // DoInsertDockLayer() is an internal function that inserts a new dock
278 // layer by incrementing all existing dock layer values by one
279 static void DoInsertDockLayer(wxPaneInfoArray
& panes
,
284 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
286 wxPaneInfo
& pane
= panes
.Item(i
);
287 if (!pane
.IsFloating() &&
288 pane
.dock_direction
== dock_direction
&&
289 pane
.dock_layer
>= dock_layer
)
294 // DoInsertDockLayer() is an internal function that inserts a new dock
295 // row by incrementing all existing dock row values by one
296 static void DoInsertDockRow(wxPaneInfoArray
& panes
,
302 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
304 wxPaneInfo
& pane
= panes
.Item(i
);
305 if (!pane
.IsFloating() &&
306 pane
.dock_direction
== dock_direction
&&
307 pane
.dock_layer
== dock_layer
&&
308 pane
.dock_row
>= dock_row
)
313 // DoInsertDockLayer() is an internal function that inserts a space for
314 // another dock pane by incrementing all existing dock row values by one
315 static void DoInsertPane(wxPaneInfoArray
& panes
,
322 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
324 wxPaneInfo
& pane
= panes
.Item(i
);
325 if (!pane
.IsFloating() &&
326 pane
.dock_direction
== dock_direction
&&
327 pane
.dock_layer
== dock_layer
&&
328 pane
.dock_row
== dock_row
&&
329 pane
.dock_pos
>= dock_pos
)
334 // FindDocks() is an internal function that returns a list of docks which meet
335 // the specified conditions in the parameters and returns a sorted array
336 // (sorted by layer and then row)
337 static void FindDocks(wxDockInfoArray
& docks
,
341 wxDockInfoPtrArray
& arr
)
343 int begin_layer
= dock_layer
;
344 int end_layer
= dock_layer
;
345 int begin_row
= dock_row
;
346 int end_row
= dock_row
;
347 int dock_count
= docks
.GetCount();
348 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
350 // discover the maximum dock layer and the max row
351 for (i
= 0; i
< dock_count
; ++i
)
353 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
354 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
357 // if no dock layer was specified, search all dock layers
358 if (dock_layer
== -1)
361 end_layer
= max_layer
;
364 // if no dock row was specified, search all dock row
373 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
374 for (row
= begin_row
; row
<= end_row
; ++row
)
375 for (i
= 0; i
< dock_count
; ++i
)
377 wxDockInfo
& d
= docks
.Item(i
);
378 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
380 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
386 // FindPaneInDock() looks up a specified window pointer inside a dock.
387 // If found, the corresponding wxPaneInfo pointer is returned, otherwise NULL.
388 static wxPaneInfo
* FindPaneInDock(const wxDockInfo
& dock
, wxWindow
* window
)
390 int i
, count
= dock
.panes
.GetCount();
391 for (i
= 0; i
< count
; ++i
)
393 wxPaneInfo
* p
= dock
.panes
.Item(i
);
394 if (p
->window
== window
)
400 // RemovePaneFromDocks() removes a pane window from all docks
401 // with a possible exception specified by parameter "ex_cept"
402 static void RemovePaneFromDocks(wxDockInfoArray
& docks
,
404 wxDockInfo
* ex_cept
= NULL
)
407 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
409 wxDockInfo
& d
= docks
.Item(i
);
412 wxPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
418 // RenumberDockRows() takes a dock and assigns sequential numbers
419 // to existing rows. Basically it takes out the gaps; so if a
420 // dock has rows with numbers 0,2,5, they will become 0,1,2
421 static void RenumberDockRows(wxDockInfoPtrArray
& docks
)
423 int i
, dock_count
, j
, pane_count
;
424 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
426 wxDockInfo
& dock
= *docks
.Item(i
);
428 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
429 dock
.panes
.Item(j
)->dock_row
= i
;
434 // SetActivePane() sets the active pane, as well as cycles through
435 // every other pane and makes sure that all others' active flags
437 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
440 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
442 wxPaneInfo
& pane
= panes
.Item(i
);
443 pane
.state
&= ~wxPaneInfo::optionActive
;
444 if (pane
.window
== active_pane
)
445 pane
.state
|= wxPaneInfo::optionActive
;
450 // this function is used to sort panes by dock position
451 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
453 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
457 // -- wxFrameManager class implementation --
460 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
461 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
462 EVT_AUI_RENDER(wxFrameManager::OnRender
)
463 EVT_PAINT(wxFrameManager::OnPaint
)
464 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
465 EVT_SIZE(wxFrameManager::OnSize
)
466 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
467 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
468 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
469 EVT_MOTION(wxFrameManager::OnMotion
)
470 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
471 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
472 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
476 wxFrameManager::wxFrameManager(wxWindow
* managed_wnd
, unsigned int flags
)
478 m_action
= actionNone
;
479 m_last_mouse_move
= wxPoint();
480 m_hover_button
= NULL
;
481 m_art
= new wxDefaultDockArt
;
488 SetManagedWindow(managed_wnd
);
492 wxFrameManager::~wxFrameManager()
497 // GetPane() looks up a wxPaneInfo structure based
498 // on the supplied window pointer. Upon failure, GetPane()
499 // returns an empty wxPaneInfo, a condition which can be checked
500 // by calling wxPaneInfo::IsOk().
502 // The pane info's structure may then be modified. Once a pane's
503 // info is modified, wxFrameManager::Update() must be called to
504 // realize the changes in the UI.
506 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
509 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
511 wxPaneInfo
& p
= m_panes
.Item(i
);
512 if (p
.window
== window
)
515 return wxNullPaneInfo
;
518 // this version of GetPane() looks up a pane based on a
519 // 'pane name', see above comment for more info
520 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
523 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
525 wxPaneInfo
& p
= m_panes
.Item(i
);
529 return wxNullPaneInfo
;
532 // GetAllPanes() returns a reference to all the pane info structures
533 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
538 // HitTest() is an internal function which determines
539 // which UI item the specified coordinates are over
540 // (x,y) specify a position in client coordinates
541 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
543 wxDockUIPart
* result
= NULL
;
546 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
548 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
550 // we are not interested in typeDock, because this space
551 // isn't used to draw anything, just for measurements;
552 // besides, the entire dock area is covered with other
553 // rectangles, which we are interested in.
554 if (item
->type
== wxDockUIPart::typeDock
)
557 // if we already have a hit on a more specific item, we are not
558 // interested in a pane hit. If, however, we don't already have
559 // a hit, returning a pane hit is necessary for some operations
560 if ((item
->type
== wxDockUIPart::typePane
||
561 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
564 // if the point is inside the rectangle, we have a hit
565 if (item
->rect
.Contains(x
,y
))
573 // SetFlags() and GetFlags() allow the owner to set various
574 // options which are global to wxFrameManager
575 void wxFrameManager::SetFlags(unsigned int flags
)
580 unsigned int wxFrameManager::GetFlags() const
586 // don't use these anymore as they are deprecated
587 // use Set/GetManagedFrame() instead
588 void wxFrameManager::SetFrame(wxFrame
* frame
)
590 SetManagedWindow((wxWindow
*)frame
);
593 wxFrame
* wxFrameManager::GetFrame() const
595 return (wxFrame
*)m_frame
;
601 // SetManagedWindow() is usually called once when the frame
602 // manager class is being initialized. "frame" specifies
603 // the frame which should be managed by the frame mananger
604 void wxFrameManager::SetManagedWindow(wxWindow
* frame
)
606 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
609 m_frame
->PushEventHandler(this);
612 // if the owner is going to manage an MDI parent frame,
613 // we need to add the MDI client window as the default
616 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
618 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
619 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
621 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
623 AddPane(client_window
,
624 wxPaneInfo().Name(wxT("mdiclient")).
625 CenterPane().PaneBorder(false));
629 // Make a window to use for a transparent hint
630 #if defined(__WXMSW__) || defined(__WXGTK__)
631 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
632 wxFRAME_TOOL_WINDOW
|
633 wxFRAME_FLOAT_ON_PARENT
|
637 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
639 #elif defined(__WXMAC__)
640 // Using a miniframe with float and tool styles keeps the parent
641 // frame activated and highlighted as such...
642 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
643 wxFRAME_FLOAT_ON_PARENT
644 | wxFRAME_TOOL_WINDOW
);
646 // Can't set the bg colour of a Frame in wxMac
647 wxPanel
* p
= new wxPanel(m_hint_wnd
);
649 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
650 // color that is really hard to see, especially transparent.
651 // Until a better system color is decided upon we'll just use
653 p
->SetBackgroundColour(*wxBLUE
);
659 // CanSetTransparent is only present in the 2.7.0 ABI. To allow this file to be easily used
660 // in a backported environment, conditionally compile this in.
661 #if wxCHECK_VERSION(2,7,0)
662 && !m_hint_wnd
->CanSetTransparent()
668 m_hint_wnd
->Destroy();
671 // If we can convert it to a PseudoTransparent window, do so
672 m_hint_wnd
= new wxPseudoTransparentFrame (m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
673 wxFRAME_TOOL_WINDOW
|
674 wxFRAME_FLOAT_ON_PARENT
|
678 m_hint_fademax
= 128;
683 // UnInit() must be called, usually in the destructor
684 // of the frame class. If it is not called, usually this
685 // will result in a crash upon program exit
686 void wxFrameManager::UnInit()
688 m_frame
->RemoveEventHandler(this);
691 // GetManagedWindow() returns the window pointer being managed
692 wxWindow
* wxFrameManager::GetManagedWindow() const
697 wxDockArt
* wxFrameManager::GetArtProvider() const
702 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
704 // first, give the owner frame a chance to override
707 if (m_frame
->ProcessEvent(event
))
714 // SetArtProvider() instructs wxFrameManager to use the
715 // specified art provider for all drawing calls. This allows
716 // plugable look-and-feel features. The pointer that is
717 // passed to this method subsequently belongs to wxFrameManager,
718 // and is deleted in the frame manager destructor
719 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
721 // delete the last art provider, if any
724 // assign the new art provider
725 m_art
= art_provider
;
729 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
731 // check if the pane has a valid window
735 // check if the pane already exists
736 if (GetPane(pane_info
.window
).IsOk())
739 m_panes
.Add(pane_info
);
741 wxPaneInfo
& pinfo
= m_panes
.Last();
743 // set the pane window
744 pinfo
.window
= window
;
746 // if the pane's name identifier is blank, create a random string
747 if (pinfo
.name
.empty())
749 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
750 ((unsigned long)pinfo
.window
) & 0xffffffff,
751 (unsigned int)time(NULL
),
753 (unsigned int)GetTickCount(),
755 (unsigned int)clock(),
757 (unsigned long)m_panes
.GetCount());
760 // set initial proportion (if not already set)
761 if (pinfo
.dock_proportion
== 0)
762 pinfo
.dock_proportion
= 100000;
764 if (pinfo
.HasCloseButton() &&
765 pinfo
.buttons
.size() == 0)
768 button
.button_id
= wxPaneInfo::buttonClose
;
769 pinfo
.buttons
.Add(button
);
772 if (pinfo
.best_size
== wxDefaultSize
&&
775 pinfo
.best_size
= pinfo
.window
->GetClientSize();
777 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
779 // GetClientSize() doesn't get the best size for
780 // a toolbar under some newer versions of wxWidgets,
781 // so use GetBestSize()
782 pinfo
.best_size
= pinfo
.window
->GetBestSize();
784 // for some reason, wxToolBar::GetBestSize() is returning
785 // a size that is a pixel shy of the correct amount.
786 // I believe this to be the correct action, until
787 // wxToolBar::GetBestSize() is fixed. Is this assumption
792 if (pinfo
.min_size
!= wxDefaultSize
)
794 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
795 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
796 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
797 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
804 bool wxFrameManager::AddPane(wxWindow
* window
,
806 const wxString
& caption
)
809 pinfo
.Caption(caption
);
812 case wxTOP
: pinfo
.Top(); break;
813 case wxBOTTOM
: pinfo
.Bottom(); break;
814 case wxLEFT
: pinfo
.Left(); break;
815 case wxRIGHT
: pinfo
.Right(); break;
816 case wxCENTER
: pinfo
.CenterPane(); break;
818 return AddPane(window
, pinfo
);
821 bool wxFrameManager::AddPane(wxWindow
* window
,
822 const wxPaneInfo
& pane_info
,
823 const wxPoint
& drop_pos
)
825 if (!AddPane(window
, pane_info
))
828 wxPaneInfo
& pane
= GetPane(window
);
830 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
835 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
838 // shift the panes around, depending on the insert level
839 switch (insert_level
)
841 case wxAUI_INSERT_PANE
:
842 DoInsertPane(m_panes
,
843 pane_info
.dock_direction
,
844 pane_info
.dock_layer
,
848 case wxAUI_INSERT_ROW
:
849 DoInsertDockRow(m_panes
,
850 pane_info
.dock_direction
,
851 pane_info
.dock_layer
,
854 case wxAUI_INSERT_DOCK
:
855 DoInsertDockLayer(m_panes
,
856 pane_info
.dock_direction
,
857 pane_info
.dock_layer
);
861 // if the window already exists, we are basically just moving/inserting the
862 // existing window. If it doesn't exist, we need to add it and insert it
863 wxPaneInfo
& existing_pane
= GetPane(window
);
864 if (!existing_pane
.IsOk())
866 return AddPane(window
, pane_info
);
870 if (pane_info
.IsFloating())
872 existing_pane
.Float();
873 if (pane_info
.floating_pos
!= wxDefaultPosition
)
874 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
875 if (pane_info
.floating_size
!= wxDefaultSize
)
876 existing_pane
.FloatingSize(pane_info
.floating_size
);
880 existing_pane
.Direction(pane_info
.dock_direction
);
881 existing_pane
.Layer(pane_info
.dock_layer
);
882 existing_pane
.Row(pane_info
.dock_row
);
883 existing_pane
.Position(pane_info
.dock_pos
);
891 // DetachPane() removes a pane from the frame manager. This
892 // method will not destroy the window that is removed.
893 bool wxFrameManager::DetachPane(wxWindow
* window
)
896 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
898 wxPaneInfo
& p
= m_panes
.Item(i
);
899 if (p
.window
== window
)
903 // we have a floating frame which is being detached. We need to
904 // reparent it to m_frame and destroy the floating frame
907 p
.window
->SetSize(1,1);
909 if (p
.frame
->IsShown())
910 p
.frame
->Show(false);
912 // reparent to m_frame and destroy the pane
913 p
.window
->Reparent(m_frame
);
914 p
.frame
->SetSizer(NULL
);
919 // make sure there are no references to this pane in our uiparts,
920 // just in case the caller doesn't call Update() immediately after
921 // the DetachPane() call. This prevets obscure crashes which would
922 // happen at window repaint if the caller forgets to call Update()
924 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
926 wxDockUIPart
& part
= m_uiparts
.Item(pi
);
929 m_uiparts
.RemoveAt(pi
);
943 // ClosePane() destroys or hides the pane depending on its
945 void wxFrameManager::ClosePane(wxPaneInfo
& pane_info
)
947 // first, hide the window
948 if (pane_info
.window
&& pane_info
.window
->IsShown()) {
949 pane_info
.window
->Show(false);
952 // make sure that we are the parent of this window
953 if(pane_info
.window
&& pane_info
.window
->GetParent() != m_frame
) {
954 pane_info
.window
->Reparent(m_frame
);
957 // if we have a frame, destroy it
958 if(pane_info
.frame
) {
959 pane_info
.frame
->Destroy();
960 pane_info
.frame
= NULL
;
963 // now we need to either destroy or hide the pane
964 if(pane_info
.IsDestroyOnClose())
966 wxWindow
* window
= pane_info
.window
;
978 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
979 // in the input string. This is an internal functions which is
980 // used for saving perspectives
981 static wxString
EscapeDelimiters(const wxString
& s
)
984 result
.Alloc(s
.length());
985 const wxChar
* ch
= s
.c_str();
988 if (*ch
== wxT(';') || *ch
== wxT('|'))
996 wxString
wxFrameManager::SavePaneInfo(wxPaneInfo
& pane
)
998 wxString result
= wxT("name=");
999 result
+= EscapeDelimiters(pane
.name
);
1002 result
+= wxT("caption=");
1003 result
+= EscapeDelimiters(pane
.caption
);
1006 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
1007 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
1008 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
1009 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
1010 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
1011 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
1012 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
1013 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
1014 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
1015 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
1016 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
1017 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
1018 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
1019 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
1020 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
1021 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
1026 // Load a "pane" with the pane infor settings in pane_part
1027 void wxFrameManager::LoadPaneInfo(wxString pane_part
, wxPaneInfo
&pane
)
1029 // replace escaped characters so we can
1030 // split up the string easily
1031 pane_part
.Replace(wxT("\\|"), wxT("\a"));
1032 pane_part
.Replace(wxT("\\;"), wxT("\b"));
1036 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
1037 pane_part
= pane_part
.AfterFirst(wxT(';'));
1038 wxString val_name
= val_part
.BeforeFirst(wxT('='));
1039 wxString value
= val_part
.AfterFirst(wxT('='));
1040 val_name
.MakeLower();
1041 val_name
.Trim(true);
1042 val_name
.Trim(false);
1046 if (val_name
.empty())
1049 if (val_name
== wxT("name"))
1051 else if (val_name
== wxT("caption"))
1052 pane
.caption
= value
;
1053 else if (val_name
== wxT("state"))
1054 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1055 else if (val_name
== wxT("dir"))
1056 pane
.dock_direction
= wxAtoi(value
.c_str());
1057 else if (val_name
== wxT("layer"))
1058 pane
.dock_layer
= wxAtoi(value
.c_str());
1059 else if (val_name
== wxT("row"))
1060 pane
.dock_row
= wxAtoi(value
.c_str());
1061 else if (val_name
== wxT("pos"))
1062 pane
.dock_pos
= wxAtoi(value
.c_str());
1063 else if (val_name
== wxT("prop"))
1064 pane
.dock_proportion
= wxAtoi(value
.c_str());
1065 else if (val_name
== wxT("bestw"))
1066 pane
.best_size
.x
= wxAtoi(value
.c_str());
1067 else if (val_name
== wxT("besth"))
1068 pane
.best_size
.y
= wxAtoi(value
.c_str());
1069 else if (val_name
== wxT("minw"))
1070 pane
.min_size
.x
= wxAtoi(value
.c_str());
1071 else if (val_name
== wxT("minh"))
1072 pane
.min_size
.y
= wxAtoi(value
.c_str());
1073 else if (val_name
== wxT("maxw"))
1074 pane
.max_size
.x
= wxAtoi(value
.c_str());
1075 else if (val_name
== wxT("maxh"))
1076 pane
.max_size
.y
= wxAtoi(value
.c_str());
1077 else if (val_name
== wxT("floatx"))
1078 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1079 else if (val_name
== wxT("floaty"))
1080 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1081 else if (val_name
== wxT("floatw"))
1082 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1083 else if (val_name
== wxT("floath"))
1084 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1086 wxFAIL_MSG(wxT("Bad Perspective String"));
1090 // replace escaped characters so we can
1091 // split up the string easily
1092 pane
.name
.Replace(wxT("\a"), wxT("|"));
1093 pane
.name
.Replace(wxT("\b"), wxT(";"));
1094 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1095 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1096 pane_part
.Replace(wxT("\a"), wxT("|"));
1097 pane_part
.Replace(wxT("\b"), wxT(";"));
1103 // SavePerspective() saves all pane information as a single string.
1104 // This string may later be fed into LoadPerspective() to restore
1105 // all pane settings. This save and load mechanism allows an
1106 // exact pane configuration to be saved and restored at a later time
1108 wxString
wxFrameManager::SavePerspective()
1112 result
= wxT("layout1|");
1114 int pane_i
, pane_count
= m_panes
.GetCount();
1115 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1117 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
1118 result
+= SavePaneInfo(pane
)+wxT("|");
1121 int dock_i
, dock_count
= m_docks
.GetCount();
1122 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1124 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
1126 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1127 dock
.dock_direction
, dock
.dock_layer
,
1128 dock
.dock_row
, dock
.size
);
1134 // LoadPerspective() loads a layout which was saved with SavePerspective()
1135 // If the "update" flag parameter is true, the GUI will immediately be updated
1137 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
1139 wxString input
= layout
;
1142 // check layout string version
1143 part
= input
.BeforeFirst(wxT('|'));
1144 input
= input
.AfterFirst(wxT('|'));
1147 if (part
!= wxT("layout1"))
1150 // mark all panes currently managed as docked and hidden
1151 int pane_i
, pane_count
= m_panes
.GetCount();
1152 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1153 m_panes
.Item(pane_i
).Dock().Hide();
1155 // clear out the dock array; this will be reconstructed
1158 // replace escaped characters so we can
1159 // split up the string easily
1160 input
.Replace(wxT("\\|"), wxT("\a"));
1161 input
.Replace(wxT("\\;"), wxT("\b"));
1167 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1168 input
= input
.AfterFirst(wxT('|'));
1169 pane_part
.Trim(true);
1171 // if the string is empty, we're done parsing
1172 if (pane_part
.empty())
1175 if (pane_part
.Left(9) == wxT("dock_size"))
1177 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1178 wxString value
= pane_part
.AfterFirst(wxT('='));
1180 long dir
, layer
, row
, size
;
1181 wxString piece
= val_name
.AfterFirst(wxT('('));
1182 piece
= piece
.BeforeLast(wxT(')'));
1183 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1184 piece
= piece
.AfterFirst(wxT(','));
1185 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1186 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1187 value
.ToLong(&size
);
1190 dock
.dock_direction
= dir
;
1191 dock
.dock_layer
= layer
;
1192 dock
.dock_row
= row
;
1198 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1199 // name so it can be called by external callers
1200 pane_part
.Replace(wxT("\a"), wxT("|"));
1201 pane_part
.Replace(wxT("\b"), wxT(";"));
1203 LoadPaneInfo(pane_part
, pane
);
1205 wxPaneInfo
& p
= GetPane(pane
.name
);
1208 // the pane window couldn't be found
1209 // in the existing layout
1223 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
1224 wxArrayInt
& positions
,
1227 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1228 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1229 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1234 int offset
, action_pane
= -1;
1235 int pane_i
, pane_count
= dock
.panes
.GetCount();
1237 // find the pane marked as our action pane
1238 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1240 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1242 if (pane
.state
& wxPaneInfo::actionPane
)
1244 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1245 action_pane
= pane_i
;
1249 // set up each panes default position, and
1250 // determine the size (width or height, depending
1251 // on the dock's orientation) of each pane
1252 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1254 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1255 positions
.Add(pane
.dock_pos
);
1258 if (pane
.HasBorder())
1259 size
+= (pane_border_size
*2);
1261 if (dock
.IsHorizontal())
1263 if (pane
.HasGripper() && !pane
.HasGripperTop())
1264 size
+= gripper_size
;
1265 size
+= pane
.best_size
.x
;
1269 if (pane
.HasGripper() && pane
.HasGripperTop())
1270 size
+= gripper_size
;
1272 if (pane
.HasCaption())
1273 size
+= caption_size
;
1274 size
+= pane
.best_size
.y
;
1280 // if there is no action pane, just return the default
1281 // positions (as specified in pane.pane_pos)
1282 if (action_pane
== -1)
1286 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1288 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1293 positions
[pane_i
] -= -amount
;
1295 offset
+= sizes
[pane_i
];
1298 // if the dock mode is fixed, make sure none of the panes
1299 // overlap; we will bump panes that overlap
1301 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1303 int amount
= positions
[pane_i
] - offset
;
1307 positions
[pane_i
] += -amount
;
1309 offset
+= sizes
[pane_i
];
1314 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1317 wxDockUIPartArray
& uiparts
,
1321 wxSizerItem
* sizer_item
;
1323 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1324 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1325 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1326 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1328 // find out the orientation of the item (orientation for panes
1329 // is the same as the dock's orientation)
1331 if (dock
.IsHorizontal())
1332 orientation
= wxHORIZONTAL
;
1334 orientation
= wxVERTICAL
;
1336 // this variable will store the proportion
1337 // value that the pane will receive
1338 int pane_proportion
= pane
.dock_proportion
;
1340 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1341 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1343 if (pane
.HasGripper())
1345 if (pane
.HasGripperTop())
1346 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1348 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1350 part
.type
= wxDockUIPart::typeGripper
;
1354 part
.orientation
= orientation
;
1355 part
.cont_sizer
= horz_pane_sizer
;
1356 part
.sizer_item
= sizer_item
;
1360 if (pane
.HasCaption())
1362 // create the caption sizer
1363 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1365 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1367 part
.type
= wxDockUIPart::typeCaption
;
1371 part
.orientation
= orientation
;
1372 part
.cont_sizer
= vert_pane_sizer
;
1373 part
.sizer_item
= sizer_item
;
1374 int caption_part_idx
= uiparts
.GetCount();
1377 // add pane buttons to the caption
1378 int i
, button_count
;
1379 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1380 i
< button_count
; ++i
)
1382 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1384 sizer_item
= caption_sizer
->Add(pane_button_size
,
1388 part
.type
= wxDockUIPart::typePaneButton
;
1391 part
.button
= &button
;
1392 part
.orientation
= orientation
;
1393 part
.cont_sizer
= caption_sizer
;
1394 part
.sizer_item
= sizer_item
;
1398 // add the caption sizer
1399 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1401 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1404 // add the pane window itself
1407 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1411 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1412 // Don't do this because it breaks the pane size in floating windows
1413 // BIW: Right now commenting this out is causing problems with
1414 // an mdi client window as the center pane.
1415 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1418 part
.type
= wxDockUIPart::typePane
;
1422 part
.orientation
= orientation
;
1423 part
.cont_sizer
= vert_pane_sizer
;
1424 part
.sizer_item
= sizer_item
;
1428 // determine if the pane should have a minimum size; if the pane is
1429 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1430 // if the pane.min_size is set, we must use that value as well
1432 wxSize min_size
= pane
.min_size
;
1435 if (min_size
== wxDefaultSize
)
1437 min_size
= pane
.best_size
;
1438 pane_proportion
= 0;
1442 if (min_size
!= wxDefaultSize
)
1444 vert_pane_sizer
->SetItemMinSize(
1445 vert_pane_sizer
->GetChildren().GetCount()-1,
1446 min_size
.x
, min_size
.y
);
1450 // add the verticle sizer (caption, pane window) to the
1451 // horizontal sizer (gripper, verticle sizer)
1452 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1454 // finally, add the pane sizer to the dock sizer
1456 if (pane
.HasBorder())
1458 // allowing space for the pane's border
1459 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1460 wxEXPAND
| wxALL
, pane_border_size
);
1462 part
.type
= wxDockUIPart::typePaneBorder
;
1466 part
.orientation
= orientation
;
1467 part
.cont_sizer
= cont
;
1468 part
.sizer_item
= sizer_item
;
1473 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1477 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1479 wxDockUIPartArray
& uiparts
,
1482 wxSizerItem
* sizer_item
;
1485 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1486 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1488 // resizable bottom and right docks have a sash before them
1489 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1490 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1492 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1494 part
.type
= wxDockUIPart::typeDockSizer
;
1495 part
.orientation
= orientation
;
1499 part
.cont_sizer
= cont
;
1500 part
.sizer_item
= sizer_item
;
1504 // create the sizer for the dock
1505 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1507 // add each pane to the dock
1508 int pane_i
, pane_count
= dock
.panes
.GetCount();
1512 wxArrayInt pane_positions
, pane_sizes
;
1514 // figure out the real pane positions we will
1515 // use, without modifying the each pane's pane_pos member
1516 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1519 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1521 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1522 int pane_pos
= pane_positions
.Item(pane_i
);
1524 int amount
= pane_pos
- offset
;
1527 if (dock
.IsVertical())
1528 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1530 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1532 part
.type
= wxDockUIPart::typeBackground
;
1536 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1537 part
.cont_sizer
= dock_sizer
;
1538 part
.sizer_item
= sizer_item
;
1544 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1546 offset
+= pane_sizes
.Item(pane_i
);
1549 // at the end add a very small stretchable background area
1550 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1552 part
.type
= wxDockUIPart::typeBackground
;
1556 part
.orientation
= orientation
;
1557 part
.cont_sizer
= dock_sizer
;
1558 part
.sizer_item
= sizer_item
;
1563 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1565 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1567 // if this is not the first pane being added,
1568 // we need to add a pane sizer
1571 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1573 part
.type
= wxDockUIPart::typePaneSizer
;
1575 part
.pane
= dock
.panes
.Item(pane_i
-1);
1577 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1578 part
.cont_sizer
= dock_sizer
;
1579 part
.sizer_item
= sizer_item
;
1583 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1587 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1588 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1590 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1592 part
.type
= wxDockUIPart::typeDock
;
1596 part
.orientation
= orientation
;
1597 part
.cont_sizer
= cont
;
1598 part
.sizer_item
= sizer_item
;
1601 if (dock
.IsHorizontal())
1602 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1604 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1606 // top and left docks have a sash after them
1607 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1608 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1610 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1612 part
.type
= wxDockUIPart::typeDockSizer
;
1616 part
.orientation
= orientation
;
1617 part
.cont_sizer
= cont
;
1618 part
.sizer_item
= sizer_item
;
1623 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1624 wxDockInfoArray
& docks
,
1625 wxDockUIPartArray
& uiparts
,
1628 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1630 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1631 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1632 wxSize cli_size
= m_frame
->GetClientSize();
1633 int i
, dock_count
, pane_count
;
1636 // empty all docks out
1637 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1638 docks
.Item(i
).panes
.Empty();
1640 // iterate through all known panes, filing each
1641 // of them into the appropriate dock. If the
1642 // pane does not exist in the dock, add it
1643 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1645 wxPaneInfo
& p
= panes
.Item(i
);
1647 // find any docks in this layer
1649 wxDockInfoPtrArray arr
;
1650 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1652 if (arr
.GetCount() > 0)
1658 // dock was not found, so we need to create a new one
1660 d
.dock_direction
= p
.dock_direction
;
1661 d
.dock_layer
= p
.dock_layer
;
1662 d
.dock_row
= p
.dock_row
;
1664 dock
= &docks
.Last();
1668 if (p
.IsDocked() && p
.IsShown())
1670 // remove the pane from any existing docks except this one
1671 RemovePaneFromDocks(docks
, p
, dock
);
1673 // pane needs to be added to the dock,
1674 // if it doesn't already exist
1675 if (!FindPaneInDock(*dock
, p
.window
))
1676 dock
->panes
.Add(&p
);
1680 // remove the pane from any existing docks
1681 RemovePaneFromDocks(docks
, p
);
1686 // remove any empty docks
1687 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1689 if (docks
.Item(i
).panes
.GetCount() == 0)
1693 // configure the docks further
1694 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1696 wxDockInfo
& dock
= docks
.Item(i
);
1697 int j
, dock_pane_count
= dock
.panes
.GetCount();
1699 // sort the dock pane array by the pane's
1700 // dock position (dock_pos), in ascending order
1701 dock
.panes
.Sort(PaneSortFunc
);
1703 // for newly created docks, set up their initial size
1708 for (j
= 0; j
< dock_pane_count
; ++j
)
1710 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1711 wxSize pane_size
= pane
.best_size
;
1712 if (pane_size
== wxDefaultSize
)
1713 pane_size
= pane
.min_size
;
1714 if (pane_size
== wxDefaultSize
)
1715 pane_size
= pane
.window
->GetSize();
1717 if (dock
.IsHorizontal())
1718 size
= wxMax(pane_size
.y
, size
);
1720 size
= wxMax(pane_size
.x
, size
);
1723 // add space for the border (two times), but only
1724 // if at least one pane inside the dock has a pane border
1725 for (j
= 0; j
< dock_pane_count
; ++j
)
1727 if (dock
.panes
.Item(j
)->HasBorder())
1729 size
+= (pane_border_size
*2);
1734 // if pane is on the top or bottom, add the caption height,
1735 // but only if at least one pane inside the dock has a caption
1736 if (dock
.IsHorizontal())
1738 for (j
= 0; j
< dock_pane_count
; ++j
)
1740 if (dock
.panes
.Item(j
)->HasCaption())
1742 size
+= caption_size
;
1748 // new dock's size may not be more than 1/3 of the frame size
1749 if (dock
.IsHorizontal())
1750 size
= wxMin(size
, cli_size
.y
/3);
1752 size
= wxMin(size
, cli_size
.x
/3);
1760 // determine the dock's minimum size
1761 bool plus_border
= false;
1762 bool plus_caption
= false;
1763 int dock_min_size
= 0;
1764 for (j
= 0; j
< dock_pane_count
; ++j
)
1766 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1767 if (pane
.min_size
!= wxDefaultSize
)
1769 if (pane
.HasBorder())
1771 if (pane
.HasCaption())
1772 plus_caption
= true;
1773 if (dock
.IsHorizontal())
1775 if (pane
.min_size
.y
> dock_min_size
)
1776 dock_min_size
= pane
.min_size
.y
;
1780 if (pane
.min_size
.x
> dock_min_size
)
1781 dock_min_size
= pane
.min_size
.x
;
1787 dock_min_size
+= (pane_border_size
*2);
1788 if (plus_caption
&& dock
.IsHorizontal())
1789 dock_min_size
+= (caption_size
);
1791 dock
.min_size
= dock_min_size
;
1794 // if the pane's current size is less than it's
1795 // minimum, increase the dock's size to it's minimum
1796 if (dock
.size
< dock
.min_size
)
1797 dock
.size
= dock
.min_size
;
1800 // determine the dock's mode (fixed or proportional);
1801 // determine whether the dock has only toolbars
1802 bool action_pane_marked
= false;
1804 dock
.toolbar
= true;
1805 for (j
= 0; j
< dock_pane_count
; ++j
)
1807 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1808 if (!pane
.IsFixed())
1810 if (!pane
.IsToolbar())
1811 dock
.toolbar
= false;
1812 if (pane
.state
& wxPaneInfo::actionPane
)
1813 action_pane_marked
= true;
1817 // if the dock mode is proportional and not fixed-pixel,
1818 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1819 // e.g. remove gaps like 1, 2, 30, 500
1822 for (j
= 0; j
< dock_pane_count
; ++j
)
1824 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1829 // if the dock mode is fixed, and none of the panes
1830 // are being moved right now, make sure the panes
1831 // do not overlap each other. If they do, we will
1832 // adjust the panes' positions
1833 if (dock
.fixed
&& !action_pane_marked
)
1835 wxArrayInt pane_positions
, pane_sizes
;
1836 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1839 for (j
= 0; j
< dock_pane_count
; ++j
)
1841 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1842 pane
.dock_pos
= pane_positions
[j
];
1844 int amount
= pane
.dock_pos
- offset
;
1848 pane
.dock_pos
+= -amount
;
1850 offset
+= pane_sizes
[j
];
1855 // discover the maximum dock layer
1857 for (i
= 0; i
< dock_count
; ++i
)
1858 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1861 // clear out uiparts
1864 // create a bunch of box sizers,
1865 // from the innermost level outwards.
1866 wxSizer
* cont
= NULL
;
1867 wxSizer
* middle
= NULL
;
1871 for (layer
= 0; layer
<= max_layer
; ++layer
)
1873 wxDockInfoPtrArray arr
;
1875 // find any docks in this layer
1876 FindDocks(docks
, -1, layer
, -1, arr
);
1878 // if there aren't any, skip to the next layer
1882 wxSizer
* old_cont
= cont
;
1884 // create a container which will hold this layer's
1885 // docks (top, bottom, left, right)
1886 cont
= new wxBoxSizer(wxVERTICAL
);
1889 // find any top docks in this layer
1890 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1891 RenumberDockRows(arr
);
1894 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1895 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1899 // fill out the middle layer (which consists
1900 // of left docks, content area and right docks)
1902 middle
= new wxBoxSizer(wxHORIZONTAL
);
1904 // find any left docks in this layer
1905 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1906 RenumberDockRows(arr
);
1909 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1910 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1913 // add content dock (or previous layer's sizer
1917 // find any center docks
1918 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1921 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1922 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1926 // there are no center docks, add a background area
1927 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1929 part
.type
= wxDockUIPart::typeBackground
;
1933 part
.cont_sizer
= middle
;
1934 part
.sizer_item
= sizer_item
;
1940 middle
->Add(old_cont
, 1, wxEXPAND
);
1943 // find any right docks in this layer
1944 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1945 RenumberDockRows(arr
);
1948 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1949 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1952 cont
->Add(middle
, 1, wxEXPAND
);
1956 // find any bottom docks in this layer
1957 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1958 RenumberDockRows(arr
);
1961 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1962 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1969 // no sizer available, because there are no docks,
1970 // therefore we will create a simple background area
1971 cont
= new wxBoxSizer(wxVERTICAL
);
1972 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1974 part
.type
= wxDockUIPart::typeBackground
;
1978 part
.cont_sizer
= middle
;
1979 part
.sizer_item
= sizer_item
;
1983 container
->Add(cont
, 1, wxEXPAND
);
1988 // Update() updates the layout. Whenever changes are made to
1989 // one or more panes, this function should be called. It is the
1990 // external entry point for running the layout engine.
1992 void wxFrameManager::Update()
1995 int i
, pane_count
= m_panes
.GetCount();
1997 // delete old sizer first
1998 m_frame
->SetSizer(NULL
);
2000 // destroy floating panes which have been
2001 // redocked or are becoming non-floating
2002 for (i
= 0; i
< pane_count
; ++i
)
2004 wxPaneInfo
& p
= m_panes
.Item(i
);
2006 if (!p
.IsFloating() && p
.frame
)
2008 // because the pane is no longer in a floating, we need to
2009 // reparent it to m_frame and destroy the floating frame
2012 p
.window
->SetSize(1,1);
2014 if (p
.frame
->IsShown())
2015 p
.frame
->Show(false);
2017 // reparent to m_frame and destroy the pane
2018 p
.window
->Reparent(m_frame
);
2019 p
.frame
->SetSizer(NULL
);
2026 // create a layout for all of the panes
2027 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
2029 // hide or show panes as necessary,
2030 // and float panes as necessary
2031 for (i
= 0; i
< pane_count
; ++i
)
2033 wxPaneInfo
& p
= m_panes
.Item(i
);
2037 if (p
.frame
== NULL
)
2039 // we need to create a frame for this
2040 // pane, which has recently been floated
2041 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
2045 #if wxCHECK_VERSION(2,7,0)
2046 // on MSW and Mac, if the owner desires transparent dragging, and
2047 // the dragging is happening right now, then the floating
2048 // window should have this style by default
2049 if (m_action
== actionDragFloatingPane
&&
2050 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2051 frame
->SetTransparent(150);
2054 frame
->SetPaneWindow(p
);
2057 if (p
.IsShown() && !frame
->IsShown())
2062 // frame already exists, make sure it's position
2063 // and size reflect the information in wxPaneInfo
2064 if (p
.frame
->GetPosition() != p
.floating_pos
)
2066 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2067 wxDefaultCoord
, wxDefaultCoord
,
2068 wxSIZE_USE_EXISTING
);
2069 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2072 if (p
.frame
->IsShown() != p
.IsShown())
2073 p
.frame
->Show(p
.IsShown());
2078 if (p
.window
->IsShown() != p
.IsShown())
2079 p
.window
->Show(p
.IsShown());
2082 // if "active panes" are no longer allowed, clear
2083 // any optionActive values from the pane states
2084 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2086 p
.state
&= ~wxPaneInfo::optionActive
;
2091 // keep track of the old window rectangles so we can
2092 // refresh those windows whose rect has changed
2093 wxAuiRectArray old_pane_rects
;
2094 for (i
= 0; i
< pane_count
; ++i
)
2097 wxPaneInfo
& p
= m_panes
.Item(i
);
2099 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2102 old_pane_rects
.Add(r
);
2108 // apply the new sizer
2109 m_frame
->SetSizer(sizer
);
2110 m_frame
->SetAutoLayout(false);
2115 // now that the frame layout is done, we need to check
2116 // the new pane rectangles against the old rectangles that
2117 // we saved a few lines above here. If the rectangles have
2118 // changed, the corresponding panes must also be updated
2119 for (i
= 0; i
< pane_count
; ++i
)
2121 wxPaneInfo
& p
= m_panes
.Item(i
);
2122 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2124 if (p
.rect
!= old_pane_rects
[i
])
2126 p
.window
->Refresh();
2135 // set frame's minimum size
2138 // N.B. More work needs to be done on frame minimum sizes;
2139 // this is some intresting code that imposes the minimum size,
2140 // but we may want to include a more flexible mechanism or
2141 // options for multiple minimum-size modes, e.g. strict or lax
2142 wxSize min_size = sizer->GetMinSize();
2143 wxSize frame_size = m_frame->GetSize();
2144 wxSize client_size = m_frame->GetClientSize();
2146 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2147 min_size.y+frame_size.y-client_size.y );
2149 m_frame->SetMinSize(minframe_size);
2151 if (frame_size.x < minframe_size.x ||
2152 frame_size.y < minframe_size.y)
2153 sizer->Fit(m_frame);
2158 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2159 // on the frame's main sizer, then measures all the various UI items
2160 // and updates their internal rectangles. This should always be called
2161 // instead of calling m_frame->Layout() directly
2163 void wxFrameManager::DoFrameLayout()
2168 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2170 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2172 // get the rectangle of the UI part
2173 // originally, this code looked like this:
2174 // part.rect = wxRect(part.sizer_item->GetPosition(),
2175 // part.sizer_item->GetSize());
2176 // this worked quite well, with one exception: the mdi
2177 // client window had a "deferred" size variable
2178 // that returned the wrong size. It looks like
2179 // a bug in wx, because the former size of the window
2180 // was being returned. So, we will retrieve the part's
2181 // rectangle via other means
2184 part
.rect
= part
.sizer_item
->GetRect();
2185 int flag
= part
.sizer_item
->GetFlag();
2186 int border
= part
.sizer_item
->GetBorder();
2189 part
.rect
.y
-= border
;
2190 part
.rect
.height
+= border
;
2194 part
.rect
.x
-= border
;
2195 part
.rect
.width
+= border
;
2197 if (flag
& wxBOTTOM
)
2198 part
.rect
.height
+= border
;
2200 part
.rect
.width
+= border
;
2203 if (part
.type
== wxDockUIPart::typeDock
)
2204 part
.dock
->rect
= part
.rect
;
2205 if (part
.type
== wxDockUIPart::typePane
)
2206 part
.pane
->rect
= part
.rect
;
2210 // GetPanePart() looks up the pane the pane border UI part (or the regular
2211 // pane part if there is no border). This allows the caller to get the exact
2212 // rectangle of the pane in question, including decorations like
2213 // caption and border (if any).
2215 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
2218 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2220 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2221 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2222 part
.pane
&& part
.pane
->window
== wnd
)
2225 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2227 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2228 if (part
.type
== wxDockUIPart::typePane
&&
2229 part
.pane
&& part
.pane
->window
== wnd
)
2237 // GetDockPixelOffset() is an internal function which returns
2238 // a dock's offset in pixels from the left side of the window
2239 // (for horizontal docks) or from the top of the window (for
2240 // vertical docks). This value is necessary for calculating
2241 // fixel-pane/toolbar offsets when they are dragged.
2243 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
2245 // the only way to accurately calculate the dock's
2246 // offset is to actually run a theoretical layout
2248 int i
, part_count
, dock_count
;
2249 wxDockInfoArray docks
;
2250 wxPaneInfoArray panes
;
2251 wxDockUIPartArray uiparts
;
2252 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2255 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2256 wxSize client_size
= m_frame
->GetClientSize();
2257 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2260 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2262 wxDockUIPart
& part
= uiparts
.Item(i
);
2263 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2264 part
.sizer_item
->GetSize());
2265 if (part
.type
== wxDockUIPart::typeDock
)
2266 part
.dock
->rect
= part
.rect
;
2271 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2273 wxDockInfo
& dock
= docks
.Item(i
);
2274 if (test
.dock_direction
== dock
.dock_direction
&&
2275 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2277 if (dock
.IsVertical())
2289 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2290 // if a dock operation is allowed, the new dock position is copied into
2291 // the target info. If the operation was allowed, the function returns true.
2293 bool wxFrameManager::ProcessDockResult(wxPaneInfo
& target
,
2294 const wxPaneInfo
& new_pos
)
2296 bool allowed
= false;
2297 switch (new_pos
.dock_direction
)
2299 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2300 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2301 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2302 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2312 // DoDrop() is an important function. It basically takes a mouse position,
2313 // and determines where the pane's new position would be. If the pane is to be
2314 // dropped, it performs the drop operation using the specified dock and pane
2315 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2316 // scenario can be performed, giving precise coordinates for drop hints.
2317 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2318 // as parameters, the changes will be made to the main state arrays
2320 const int auiInsertRowPixels
= 10;
2321 const int auiNewRowPixels
= 40;
2322 const int auiLayerInsertPixels
= 40;
2323 const int auiLayerInsertOffset
= 5;
2325 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2326 wxPaneInfoArray
& panes
,
2329 const wxPoint
& offset
)
2331 wxSize cli_size
= m_frame
->GetClientSize();
2333 wxPaneInfo drop
= target
;
2336 // The result should always be shown
2340 // Check to see if the pane has been dragged outside of the window
2341 // (or near to the outside of the window), if so, dock it along the edge
2344 int layer_insert_offset
= auiLayerInsertOffset
;
2345 if (target
.IsToolbar())
2346 layer_insert_offset
= 0;
2348 if (pt
.x
< layer_insert_offset
&&
2349 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2353 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2354 return ProcessDockResult(target
, drop
);
2356 else if (pt
.y
< layer_insert_offset
&&
2357 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2361 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2362 return ProcessDockResult(target
, drop
);
2364 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2365 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2367 drop
.Dock().Right().
2369 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2370 return ProcessDockResult(target
, drop
);
2372 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2373 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2375 int new_layer
= wxMax( wxMax( GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2376 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2377 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2379 drop
.Dock().Bottom().
2382 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2383 return ProcessDockResult(target
, drop
);
2386 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2389 if (drop
.IsToolbar())
2391 if (!part
|| !part
->dock
)
2394 // calculate the offset from where the dock begins
2395 // to the point where the user dropped the pane
2396 int dock_drop_offset
= 0;
2397 if (part
->dock
->IsHorizontal())
2398 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2400 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2403 // toolbars may only be moved in and to fixed-pane docks,
2404 // otherwise we will try to float the pane. Also, the pane
2405 // should float if being dragged over center pane windows
2406 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2408 if (m_last_rect
.IsEmpty() || m_last_rect
.Contains(pt
.x
, pt
.y
))
2414 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2415 (drop
.IsFloatable() ||
2416 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2417 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2424 return ProcessDockResult(target
, drop
);
2427 drop
.Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2429 return ProcessDockResult(target
, drop
);
2438 m_last_rect
= part
->dock
->rect
;
2439 m_last_rect
.Inflate( 15, 15 );
2443 Direction(part
->dock
->dock_direction
).
2444 Layer(part
->dock
->dock_layer
).
2445 Row(part
->dock
->dock_row
).
2446 Position(dock_drop_offset
);
2449 ((pt
.y
< part
->dock
->rect
.y
+ 1) && part
->dock
->IsHorizontal()) ||
2450 ((pt
.x
< part
->dock
->rect
.x
+ 1) && part
->dock
->IsVertical())
2451 ) && part
->dock
->panes
.GetCount() > 1)
2453 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2454 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2456 int row
= drop
.dock_row
;
2457 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2458 part
->dock
->dock_layer
,
2459 part
->dock
->dock_row
);
2460 drop
.dock_row
= row
;
2464 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2465 part
->dock
->dock_layer
,
2466 part
->dock
->dock_row
+1);
2467 drop
.dock_row
= part
->dock
->dock_row
+1;
2472 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2473 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2474 ) && part
->dock
->panes
.GetCount() > 1)
2476 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2477 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2479 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2480 part
->dock
->dock_layer
,
2481 part
->dock
->dock_row
+1);
2482 drop
.dock_row
= part
->dock
->dock_row
+1;
2486 int row
= drop
.dock_row
;
2487 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2488 part
->dock
->dock_layer
,
2489 part
->dock
->dock_row
);
2490 drop
.dock_row
= row
;
2494 return ProcessDockResult(target
, drop
);
2503 if (part
->type
== wxDockUIPart::typePaneBorder
||
2504 part
->type
== wxDockUIPart::typeCaption
||
2505 part
->type
== wxDockUIPart::typeGripper
||
2506 part
->type
== wxDockUIPart::typePaneButton
||
2507 part
->type
== wxDockUIPart::typePane
||
2508 part
->type
== wxDockUIPart::typePaneSizer
||
2509 part
->type
== wxDockUIPart::typeDockSizer
||
2510 part
->type
== wxDockUIPart::typeBackground
)
2512 if (part
->type
== wxDockUIPart::typeDockSizer
)
2514 if (part
->dock
->panes
.GetCount() != 1)
2516 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2523 // If a normal frame is being dragged over a toolbar, insert it
2524 // along the edge under the toolbar, but over all other panes.
2525 // (this could be done much better, but somehow factoring this
2526 // calculation with the one at the beginning of this function)
2527 if (part
->dock
&& part
->dock
->toolbar
)
2531 switch (part
->dock
->dock_direction
)
2533 case wxAUI_DOCK_LEFT
:
2534 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2535 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2536 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2538 case wxAUI_DOCK_TOP
:
2539 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2540 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2541 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2543 case wxAUI_DOCK_RIGHT
:
2544 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2545 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2546 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2548 case wxAUI_DOCK_BOTTOM
:
2549 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2550 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2551 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2555 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2558 Direction(part
->dock
->dock_direction
).
2559 Layer(layer
).Row(0).Position(0);
2560 return ProcessDockResult(target
, drop
);
2567 part
= GetPanePart(part
->pane
->window
);
2571 bool insert_dock_row
= false;
2572 int insert_row
= part
->pane
->dock_row
;
2573 int insert_dir
= part
->pane
->dock_direction
;
2574 int insert_layer
= part
->pane
->dock_layer
;
2576 switch (part
->pane
->dock_direction
)
2578 case wxAUI_DOCK_TOP
:
2579 if (pt
.y
>= part
->rect
.y
&&
2580 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2581 insert_dock_row
= true;
2583 case wxAUI_DOCK_BOTTOM
:
2584 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2585 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2586 insert_dock_row
= true;
2588 case wxAUI_DOCK_LEFT
:
2589 if (pt
.x
>= part
->rect
.x
&&
2590 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2591 insert_dock_row
= true;
2593 case wxAUI_DOCK_RIGHT
:
2594 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2595 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2596 insert_dock_row
= true;
2598 case wxAUI_DOCK_CENTER
:
2600 // "new row pixels" will be set to the default, but
2601 // must never exceed 20% of the window size
2602 int new_row_pixels_x
= auiNewRowPixels
;
2603 int new_row_pixels_y
= auiNewRowPixels
;
2605 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2606 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2608 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2609 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2612 // determine if the mouse pointer is in a location that
2613 // will cause a new row to be inserted. The hot spot positions
2614 // are along the borders of the center pane
2617 insert_dock_row
= true;
2618 if (pt
.x
>= part
->rect
.x
&&
2619 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2620 insert_dir
= wxAUI_DOCK_LEFT
;
2622 if (pt
.y
>= part
->rect
.y
&&
2623 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2624 insert_dir
= wxAUI_DOCK_TOP
;
2626 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2627 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2628 insert_dir
= wxAUI_DOCK_RIGHT
;
2630 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2631 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2632 insert_dir
= wxAUI_DOCK_BOTTOM
;
2636 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2640 if (insert_dock_row
)
2642 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2643 drop
.Dock().Direction(insert_dir
).
2644 Layer(insert_layer
).
2647 return ProcessDockResult(target
, drop
);
2650 // determine the mouse offset and the pane size, both in the
2651 // direction of the dock itself, and perpendicular to the dock
2655 if (part
->orientation
== wxVERTICAL
)
2657 offset
= pt
.y
- part
->rect
.y
;
2658 size
= part
->rect
.GetHeight();
2662 offset
= pt
.x
- part
->rect
.x
;
2663 size
= part
->rect
.GetWidth();
2666 int drop_position
= part
->pane
->dock_pos
;
2668 // if we are in the top/left part of the pane,
2669 // insert the pane before the pane being hovered over
2670 if (offset
<= size
/2)
2672 drop_position
= part
->pane
->dock_pos
;
2674 part
->pane
->dock_direction
,
2675 part
->pane
->dock_layer
,
2676 part
->pane
->dock_row
,
2677 part
->pane
->dock_pos
);
2680 // if we are in the bottom/right part of the pane,
2681 // insert the pane before the pane being hovered over
2682 if (offset
> size
/2)
2684 drop_position
= part
->pane
->dock_pos
+1;
2686 part
->pane
->dock_direction
,
2687 part
->pane
->dock_layer
,
2688 part
->pane
->dock_row
,
2689 part
->pane
->dock_pos
+1);
2693 Direction(part
->dock
->dock_direction
).
2694 Layer(part
->dock
->dock_layer
).
2695 Row(part
->dock
->dock_row
).
2696 Position(drop_position
);
2697 return ProcessDockResult(target
, drop
);
2704 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2706 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
2708 m_hint_fadetimer
.Stop();
2712 m_hint_fadeamt
+= 4;
2713 #if wxCHECK_VERSION(2,7,0)
2714 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2716 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2717 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2721 void wxFrameManager::ShowHint(const wxRect
& rect
)
2723 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0
2725 // Finally, don't use a venetian blind effect if it's been specifically disabled
2726 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2727 (m_flags
& wxAUI_MGR_DISABLE_VENETIAN_BLINDS
))
2730 if (m_last_hint
== rect
)
2734 m_hint_fadeamt
= m_hint_fademax
;
2735 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2736 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2737 (m_flags
& wxAUI_MGR_DISABLE_VENETIAN_BLINDS_FADE
))
2741 m_hint_wnd
->SetSize(rect
);
2743 if (! m_hint_wnd
->IsShown())
2746 // if we are dragging a floating pane, set the focus
2747 // back to that floating pane (otherwise it becomes unfocused)
2748 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2749 m_action_window
->SetFocus();
2751 #if wxCHECK_VERSION(2,7,0)
2752 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2754 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2755 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2757 m_hint_wnd
->Raise();
2760 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
2762 // start fade in timer
2763 m_hint_fadetimer
.SetOwner(this, 101);
2764 m_hint_fadetimer
.Start(5);
2768 else // Not using a transparent hint window...
2771 if (m_last_hint
!= rect
)
2773 // remove the last hint rectangle
2779 wxScreenDC screendc
;
2780 wxRegion
clip(1, 1, 10000, 10000);
2782 // clip all floating windows, so we don't draw over them
2784 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2786 wxPaneInfo
& pane
= m_panes
.Item(i
);
2788 if (pane
.IsFloating() &&
2789 pane
.frame
->IsShown())
2791 wxRect rect
= pane
.frame
->GetRect();
2793 // wxGTK returns the client size, not the whole frame size
2799 clip
.Subtract(rect
);
2803 // As we can only hide the hint by redrawing the managed window, we
2804 // need to clip the region to the managed window too or we get
2805 // nasty redrawn problems.
2806 clip
.Intersect(m_frame
->GetRect());
2808 screendc
.SetClippingRegion(clip
);
2810 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2811 wxBrush
brush(stipple
);
2812 screendc
.SetBrush(brush
);
2813 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2815 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2816 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2817 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2818 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2822 void wxFrameManager::HideHint()
2824 // hides a transparent window hint, if there is one
2827 if (m_hint_wnd
->IsShown())
2828 m_hint_wnd
->Show(false);
2829 #if wxCHECK_VERSION(2,7,0)
2830 m_hint_wnd
->SetTransparent(0);
2832 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2833 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(0);
2835 m_hint_fadetimer
.Stop();
2836 m_last_hint
= wxRect();
2840 // hides a painted hint by redrawing the frame window
2841 if (!m_last_hint
.IsEmpty())
2845 m_last_hint
= wxRect();
2851 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2852 // determine the exact position the pane would be at were if dropped. If
2853 // the pame would indeed become docked at the specified drop point,
2854 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2855 // "pane_window" is the window pointer of the pane being dragged, pt is
2856 // the mouse position, in client coordinates
2857 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2859 const wxPoint
& offset
)
2863 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2864 // we will create a new temporary layout and then measure the resulting
2865 // rectangle; we will create a copy of the docking structures (m_dock)
2866 // so that we don't modify the real thing on screen
2868 int i
, pane_count
, part_count
;
2869 wxDockInfoArray docks
;
2870 wxPaneInfoArray panes
;
2871 wxDockUIPartArray uiparts
;
2872 wxPaneInfo hint
= GetPane(pane_window
);
2873 hint
.name
= wxT("__HINT__");
2879 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2881 // remove any pane already there which bears the same window;
2882 // this happens when you are moving a pane around in a dock
2883 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2885 if (panes
.Item(i
).window
== pane_window
)
2887 RemovePaneFromDocks(docks
, panes
.Item(i
));
2893 // find out where the new pane would be
2894 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2902 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2903 wxSize client_size
= m_frame
->GetClientSize();
2904 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2907 for (i
= 0, part_count
= uiparts
.GetCount();
2908 i
< part_count
; ++i
)
2910 wxDockUIPart
& part
= uiparts
.Item(i
);
2912 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2913 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2915 rect
= wxRect(part
.sizer_item
->GetPosition(),
2916 part
.sizer_item
->GetSize());
2929 // actually show the hint rectangle on the screen
2930 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2934 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2936 // try to find the pane
2937 wxPaneInfo
& pane
= GetPane(wnd
);
2938 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2940 #if wxCHECK_VERSION(2,7,0)
2941 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2942 pane
.frame
->SetTransparent(150);
2946 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
2948 // try to find the pane
2949 wxPaneInfo
& pane
= GetPane(wnd
);
2950 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2952 wxPoint pt
= ::wxGetMousePosition();
2955 // Adapt pt to direction
2958 // move to pane's upper border
2960 pos
= wnd
->ClientToScreen( pos
);
2962 // and some more pixels for the title bar
2967 // move to pane's left border
2969 pos
= wnd
->ClientToScreen( pos
);
2974 // move to pane's right border
2975 wxPoint
pos( wnd
->GetSize().x
, 0 );
2976 pos
= wnd
->ClientToScreen( pos
);
2981 // move to pane's bottom border
2982 wxPoint
pos( 0, wnd
->GetSize().y
);
2983 pos
= wnd
->ClientToScreen( pos
);
2990 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2992 // calculate the offset from the upper left-hand corner
2993 // of the frame to the mouse pointer
2994 wxPoint frame_pos
= pane
.frame
->GetPosition();
2995 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2997 // no hint for toolbar floating windows
2998 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
3000 if (m_action
== actionDragFloatingPane
)
3002 wxDockInfoArray docks
;
3003 wxPaneInfoArray panes
;
3004 wxDockUIPartArray uiparts
;
3005 wxPaneInfo hint
= pane
;
3007 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3009 // find out where the new pane would be
3010 if (!DoDrop(docks
, panes
, hint
, client_pt
))
3012 if (hint
.IsFloating())
3016 m_action
= actionDragToolbarPane
;
3017 m_action_window
= pane
.window
;
3026 // if a key modifier is pressed while dragging the frame,
3027 // don't dock the window
3028 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
3035 DrawHintRect(wnd
, client_pt
, action_offset
);
3038 // this cleans up some screen artifacts that are caused on GTK because
3039 // we aren't getting the exact size of the window (see comment
3049 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
3051 // try to find the pane
3052 wxPaneInfo
& pane
= GetPane(wnd
);
3053 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3055 wxPoint pt
= ::wxGetMousePosition();
3058 // Adapt pt to direction
3061 // move to pane's upper border
3063 pos
= wnd
->ClientToScreen( pos
);
3065 // and some more pixels for the title bar
3070 // move to pane's left border
3072 pos
= wnd
->ClientToScreen( pos
);
3077 // move to pane's right border
3078 wxPoint
pos( wnd
->GetSize().x
, 0 );
3079 pos
= wnd
->ClientToScreen( pos
);
3084 // move to pane's bottom border
3085 wxPoint
pos( 0, wnd
->GetSize().y
);
3086 pos
= wnd
->ClientToScreen( pos
);
3093 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3095 // calculate the offset from the upper left-hand corner
3096 // of the frame to the mouse pointer
3097 wxPoint frame_pos
= pane
.frame
->GetPosition();
3098 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3101 // if a key modifier is pressed while dragging the frame,
3102 // don't dock the window
3103 if (!wxGetKeyState(WXK_CONTROL
) && !wxGetKeyState(WXK_ALT
))
3105 // do the drop calculation
3106 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3109 // if the pane is still floating, update it's floating
3110 // position (that we store)
3111 if (pane
.IsFloating())
3113 pane
.floating_pos
= pane
.frame
->GetPosition();
3115 #if wxCHECK_VERSION(2,7,0)
3116 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3117 pane
.frame
->SetTransparent(255);
3126 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3128 // try to find the pane
3129 wxPaneInfo
& pane
= GetPane(wnd
);
3130 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3132 pane
.floating_size
= size
;
3136 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3138 // try to find the pane
3139 wxPaneInfo
& pane
= GetPane(wnd
);
3140 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3143 // fire pane close event
3144 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3146 e
.SetCanVeto(evt
.CanVeto());
3162 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3164 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3166 // try to find the pane
3167 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
3169 SetActivePane(m_panes
, wnd
);
3174 // OnRender() draws all of the pane captions, sashes,
3175 // backgrounds, captions, grippers, pane borders and buttons.
3176 // It renders the entire user interface.
3178 void wxFrameManager::OnRender(wxFrameManagerEvent
& evt
)
3180 wxDC
* dc
= evt
.GetDC();
3186 for (i
= 0, part_count
= m_uiparts
.GetCount();
3187 i
< part_count
; ++i
)
3189 wxDockUIPart
& part
= m_uiparts
.Item(i
);
3191 // don't draw hidden pane items
3192 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
3197 case wxDockUIPart::typeDockSizer
:
3198 case wxDockUIPart::typePaneSizer
:
3199 m_art
->DrawSash(*dc
, m_frame
, part
.orientation
, part
.rect
);
3201 case wxDockUIPart::typeBackground
:
3202 m_art
->DrawBackground(*dc
, m_frame
, part
.orientation
, part
.rect
);
3204 case wxDockUIPart::typeCaption
:
3205 m_art
->DrawCaption(*dc
, m_frame
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3207 case wxDockUIPart::typeGripper
:
3208 m_art
->DrawGripper(*dc
, m_frame
, part
.rect
, *part
.pane
);
3210 case wxDockUIPart::typePaneBorder
:
3211 m_art
->DrawBorder(*dc
, m_frame
, part
.rect
, *part
.pane
);
3213 case wxDockUIPart::typePaneButton
:
3214 m_art
->DrawPaneButton(*dc
, m_frame
, part
.button
->button_id
,
3215 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3222 // Render() fire a render event, which is normally handled by
3223 // wxFrameManager::OnRender(). This allows the render function to
3224 // be overridden via the render event. This can be useful for paintin
3225 // custom graphics in the main window. Default behavior can be
3226 // invoked in the overridden function by calling OnRender()
3228 void wxFrameManager::Render(wxDC
* dc
)
3230 wxFrameManagerEvent
e(wxEVT_AUI_RENDER
);
3235 void wxFrameManager::Repaint(wxDC
* dc
)
3240 m_frame
->Refresh() ;
3246 m_frame
->GetClientSize(&w
, &h
);
3248 // figure out which dc to use; if one
3249 // has been specified, use it, otherwise
3251 wxClientDC
* client_dc
= NULL
;
3254 client_dc
= new wxClientDC(m_frame
);
3258 // if the frame has a toolbar, the client area
3259 // origin will not be (0,0).
3260 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3261 if (pt
.x
!= 0 || pt
.y
!= 0)
3262 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3264 // render all the items
3267 // if we created a client_dc, delete it
3272 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3274 wxPaintDC
dc(m_frame
);
3278 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
3287 void wxFrameManager::OnSize(wxSizeEvent
& event
)
3298 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
3301 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3302 wxCursor cursor
= wxNullCursor
;
3306 if (part
->type
== wxDockUIPart::typeDockSizer
||
3307 part
->type
== wxDockUIPart::typePaneSizer
)
3309 // a dock may not be resized if it has a single
3310 // pane which is not resizable
3311 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3312 part
->dock
->panes
.GetCount() == 1 &&
3313 part
->dock
->panes
.Item(0)->IsFixed())
3316 // panes that may not be resized do not get a sizing cursor
3317 if (part
->pane
&& part
->pane
->IsFixed())
3320 if (part
->orientation
== wxVERTICAL
)
3321 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3323 cursor
= wxCursor(wxCURSOR_SIZENS
);
3325 else if (part
->type
== wxDockUIPart::typeGripper
)
3327 cursor
= wxCursor(wxCURSOR_SIZING
);
3331 event
.SetCursor(cursor
);
3336 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
3337 const wxMouseEvent
& event
)
3339 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3341 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3343 if (hit_test
== button_ui_part
)
3345 if (event
.LeftDown())
3346 state
= wxAUI_BUTTON_STATE_PRESSED
;
3348 state
= wxAUI_BUTTON_STATE_HOVER
;
3352 if (event
.LeftDown())
3353 state
= wxAUI_BUTTON_STATE_HOVER
;
3356 // now repaint the button with hover state
3357 wxClientDC
cdc(m_frame
);
3359 // if the frame has a toolbar, the client area
3360 // origin will not be (0,0).
3361 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3362 if (pt
.x
!= 0 || pt
.y
!= 0)
3363 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3365 m_art
->DrawPaneButton(cdc
, m_frame
,
3366 button_ui_part
->button
->button_id
,
3368 button_ui_part
->rect
,
3372 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
3374 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3377 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3380 if (part
->type
== wxDockUIPart::typeDockSizer
||
3381 part
->type
== wxDockUIPart::typePaneSizer
)
3383 // a dock may not be resized if it has a single
3384 // pane which is not resizable
3385 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3386 part
->dock
->panes
.GetCount() == 1 &&
3387 part
->dock
->panes
.Item(0)->IsFixed())
3390 // panes that may not be resized should be ignored here
3391 if (part
->pane
&& part
->pane
->IsFixed())
3394 m_action
= actionResize
;
3395 m_action_part
= part
;
3396 m_action_hintrect
= wxRect();
3397 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3398 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3399 event
.m_y
- part
->rect
.y
);
3400 m_frame
->CaptureMouse();
3402 else if (part
->type
== wxDockUIPart::typePaneButton
)
3404 m_action
= actionClickButton
;
3405 m_action_part
= part
;
3406 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3407 m_frame
->CaptureMouse();
3409 UpdateButtonOnScreen(part
, event
);
3411 else if (part
->type
== wxDockUIPart::typeCaption
||
3412 part
->type
== wxDockUIPart::typeGripper
)
3414 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3416 // set the caption as active
3417 SetActivePane(m_panes
, part
->pane
->window
);
3421 m_action
= actionClickCaption
;
3422 m_action_part
= part
;
3423 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3424 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3425 event
.m_y
- part
->rect
.y
);
3426 m_frame
->CaptureMouse();
3446 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3448 if (m_action
== actionResize
)
3450 m_frame
->ReleaseMouse();
3452 // get rid of the hint rectangle
3454 DrawResizeHint(dc
, m_action_hintrect
);
3456 // resize the dock or the pane
3457 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3459 wxRect
& rect
= m_action_part
->dock
->rect
;
3461 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3462 event
.m_y
- m_action_offset
.y
);
3464 switch (m_action_part
->dock
->dock_direction
)
3466 case wxAUI_DOCK_LEFT
:
3467 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3469 case wxAUI_DOCK_TOP
:
3470 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3472 case wxAUI_DOCK_RIGHT
:
3473 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3474 new_pos
.x
- m_action_part
->rect
.GetWidth();
3476 case wxAUI_DOCK_BOTTOM
:
3477 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3478 new_pos
.y
- m_action_part
->rect
.GetHeight();
3485 else if (m_action_part
&&
3486 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3488 wxDockInfo
& dock
= *m_action_part
->dock
;
3489 wxPaneInfo
& pane
= *m_action_part
->pane
;
3491 int total_proportion
= 0;
3492 int dock_pixels
= 0;
3493 int new_pixsize
= 0;
3495 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3496 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3497 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3499 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3500 event
.m_y
- m_action_offset
.y
);
3502 // determine the pane rectangle by getting the pane part
3503 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3504 wxASSERT_MSG(pane_part
,
3505 wxT("Pane border part not found -- shouldn't happen"));
3507 // determine the new pixel size that the user wants;
3508 // this will help us recalculate the pane's proportion
3509 if (dock
.IsHorizontal())
3510 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3512 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3514 // determine the size of the dock, based on orientation
3515 if (dock
.IsHorizontal())
3516 dock_pixels
= dock
.rect
.GetWidth();
3518 dock_pixels
= dock
.rect
.GetHeight();
3520 // determine the total proportion of all resizable panes,
3521 // and the total size of the dock minus the size of all
3523 int i
, dock_pane_count
= dock
.panes
.GetCount();
3524 int pane_position
= -1;
3525 for (i
= 0; i
< dock_pane_count
; ++i
)
3527 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3528 if (p
.window
== pane
.window
)
3531 // while we're at it, subtract the pane sash
3532 // width from the dock width, because this would
3533 // skew our proportion calculations
3535 dock_pixels
-= sash_size
;
3537 // also, the whole size (including decorations) of
3538 // all fixed panes must also be subtracted, because they
3539 // are not part of the proportion calculation
3542 if (dock
.IsHorizontal())
3543 dock_pixels
-= p
.best_size
.x
;
3545 dock_pixels
-= p
.best_size
.y
;
3549 total_proportion
+= p
.dock_proportion
;
3553 // find a pane in our dock to 'steal' space from or to 'give'
3554 // space to -- this is essentially what is done when a pane is
3555 // resized; the pane should usually be the first non-fixed pane
3556 // to the right of the action pane
3557 int borrow_pane
= -1;
3558 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3560 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3569 // demand that the pane being resized is found in this dock
3570 // (this assert really never should be raised)
3571 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3573 // prevent division by zero
3574 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3576 m_action
= actionNone
;
3580 // calculate the new proportion of the pane
3581 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3583 // default minimum size
3586 // check against the pane's minimum size, if specified. please note
3587 // that this is not enough to ensure that the minimum size will
3588 // not be violated, because the whole frame might later be shrunk,
3589 // causing the size of the pane to violate it's minimum size
3590 if (pane
.min_size
.IsFullySpecified())
3594 if (pane
.HasBorder())
3595 min_size
+= (pane_border_size
*2);
3597 // calculate minimum size with decorations (border,caption)
3598 if (pane_part
->orientation
== wxVERTICAL
)
3600 min_size
+= pane
.min_size
.y
;
3601 if (pane
.HasCaption())
3602 min_size
+= caption_size
;
3606 min_size
+= pane
.min_size
.x
;
3611 // for some reason, an arithmatic error somewhere is causing
3612 // the proportion calculations to always be off by 1 pixel;
3613 // for now we will add the 1 pixel on, but we really should
3614 // determine what's causing this.
3617 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3619 if (new_proportion
< min_proportion
)
3620 new_proportion
= min_proportion
;
3624 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3626 // borrow the space from our neighbor pane to the
3627 // right or bottom (depending on orientation)
3628 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3629 pane
.dock_proportion
= new_proportion
;
3636 else if (m_action
== actionClickButton
)
3638 m_hover_button
= NULL
;
3639 m_frame
->ReleaseMouse();
3640 UpdateButtonOnScreen(m_action_part
, event
);
3642 // make sure we're still over the item that was originally clicked
3643 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3645 // fire button-click event
3646 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3647 e
.SetPane(m_action_part
->pane
);
3648 e
.SetButton(m_action_part
->button
->button_id
);
3652 else if (m_action
== actionClickCaption
)
3654 m_frame
->ReleaseMouse();
3656 else if (m_action
== actionDragFloatingPane
)
3658 m_frame
->ReleaseMouse();
3660 else if (m_action
== actionDragToolbarPane
)
3662 m_frame
->ReleaseMouse();
3664 wxPaneInfo
& pane
= GetPane(m_action_window
);
3665 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3667 // save the new positions
3668 wxDockInfoPtrArray docks
;
3669 FindDocks(m_docks
, pane
.dock_direction
,
3670 pane
.dock_layer
, pane
.dock_row
, docks
);
3671 if (docks
.GetCount() == 1)
3673 wxDockInfo
& dock
= *docks
.Item(0);
3675 wxArrayInt pane_positions
, pane_sizes
;
3676 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3678 int i
, dock_pane_count
= dock
.panes
.GetCount();
3679 for (i
= 0; i
< dock_pane_count
; ++i
)
3680 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3683 pane
.state
&= ~wxPaneInfo::actionPane
;
3691 m_action
= actionNone
;
3692 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3696 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3698 // sometimes when Update() is called from inside this method,
3699 // a spurious mouse move event is generated; this check will make
3700 // sure that only real mouse moves will get anywhere in this method;
3701 // this appears to be a bug somewhere, and I don't know where the
3702 // mouse move event is being generated. only verified on MSW
3704 wxPoint mouse_pos
= event
.GetPosition();
3705 if (m_last_mouse_move
== mouse_pos
)
3707 m_last_mouse_move
= mouse_pos
;
3710 if (m_action
== actionResize
)
3712 wxPoint pos
= m_action_part
->rect
.GetPosition();
3713 if (m_action_part
->orientation
== wxHORIZONTAL
)
3714 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3716 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3718 wxRect
rect(m_frame
->ClientToScreen(pos
),
3719 m_action_part
->rect
.GetSize());
3722 if (!m_action_hintrect
.IsEmpty())
3723 DrawResizeHint(dc
, m_action_hintrect
);
3724 DrawResizeHint(dc
, rect
);
3725 m_action_hintrect
= rect
;
3727 else if (m_action
== actionClickCaption
)
3729 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3730 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3732 // caption has been clicked. we need to check if the mouse
3733 // is now being dragged. if it is, we need to change the
3734 // mouse action to 'drag'
3735 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3736 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3738 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3740 if (!pane_info
->IsToolbar())
3742 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3743 pane_info
->IsFloatable())
3745 m_action
= actionDragFloatingPane
;
3747 // set initial float position
3748 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3749 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3750 pt
.y
- m_action_offset
.y
);
3755 m_action_window
= pane_info
->frame
;
3757 // action offset is used here to make it feel "natural" to the user
3758 // to drag a docked pane and suddenly have it become a floating frame.
3759 // Sometimes, however, the offset where the user clicked on the docked
3760 // caption is bigger than the width of the floating frame itself, so
3761 // in that case we need to set the action offset to a sensible value
3762 wxSize frame_size
= m_action_window
->GetSize();
3763 if (frame_size
.x
<= m_action_offset
.x
)
3764 m_action_offset
.x
= 30;
3769 m_action
= actionDragToolbarPane
;
3770 m_action_window
= pane_info
->window
;
3774 else if (m_action
== actionDragFloatingPane
)
3776 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3777 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3778 pt
.y
- m_action_offset
.y
);
3780 else if (m_action
== actionDragToolbarPane
)
3782 wxPaneInfo
& pane
= GetPane(m_action_window
);
3783 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3785 pane
.state
|= wxPaneInfo::actionPane
;
3787 wxPoint pt
= event
.GetPosition();
3788 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3790 // if DoDrop() decided to float the pane, set up
3791 // the floating pane's initial position
3792 if (pane
.IsFloating())
3794 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3795 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3796 pt
.y
- m_action_offset
.y
);
3799 // this will do the actiual move operation;
3800 // in the case that the pane has been floated,
3801 // this call will create the floating pane
3802 // and do the reparenting
3805 // if the pane has been floated, change the mouse
3806 // action actionDragFloatingPane so that subsequent
3807 // EVT_MOTION() events will move the floating pane
3808 if (pane
.IsFloating())
3810 pane
.state
&= ~wxPaneInfo::actionPane
;
3811 m_action
= actionDragFloatingPane
;
3812 m_action_window
= pane
.frame
;
3817 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3818 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3820 if (part
!= m_hover_button
)
3822 // make the old button normal
3824 UpdateButtonOnScreen(m_hover_button
, event
);
3826 // mouse is over a button, so repaint the
3827 // button in hover mode
3828 UpdateButtonOnScreen(part
, event
);
3829 m_hover_button
= part
;
3836 m_hover_button
= NULL
;
3847 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3851 m_hover_button
= NULL
;
3856 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3858 // when a child pane has it's focus set, we should change the
3859 // pane's active state to reflect this. (this is only true if
3860 // active panes are allowed by the owner)
3861 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3863 if (GetPane(event
.GetWindow()).IsOk())
3865 SetActivePane(m_panes
, event
.GetWindow());
3874 // OnPaneButton() is an event handler that is called
3875 // when a pane button has been pressed.
3876 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& evt
)
3878 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3880 wxPaneInfo
& pane
= *(evt
.pane
);
3882 if (evt
.button
== wxPaneInfo::buttonClose
)
3884 // fire pane close event
3885 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3886 e
.SetPane(evt
.pane
);
3895 else if (evt
.button
== wxPaneInfo::buttonPin
)
3897 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&