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"
33 #include "wx/settings.h"
35 #include "wx/dcclient.h"
36 #include "wx/dcscreen.h"
37 #include "wx/toolbar.h"
42 WX_CHECK_BUILD_OPTIONS("wxAUI")
44 #include "wx/arrimpl.cpp"
45 WX_DECLARE_OBJARRAY(wxRect
, wxAuiRectArray
);
46 WX_DEFINE_OBJARRAY(wxAuiRectArray
)
47 WX_DEFINE_OBJARRAY(wxDockUIPartArray
)
48 WX_DEFINE_OBJARRAY(wxDockInfoArray
)
49 WX_DEFINE_OBJARRAY(wxPaneButtonArray
)
50 WX_DEFINE_OBJARRAY(wxPaneInfoArray
)
52 wxPaneInfo wxNullPaneInfo
;
53 wxDockInfo wxNullDockInfo
;
54 DEFINE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON
)
55 DEFINE_EVENT_TYPE(wxEVT_AUI_PANECLOSE
)
56 DEFINE_EVENT_TYPE(wxEVT_AUI_RENDER
)
59 // a few defines to avoid nameclashes
60 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
62 #include "wx/mac/private.h"
65 IMPLEMENT_DYNAMIC_CLASS(wxFrameManagerEvent
, wxEvent
)
67 class wxPseudoTransparentFrame
: public wxFrame
70 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
71 wxWindowID id
= wxID_ANY
,
72 const wxString
& title
= wxEmptyString
,
73 const wxPoint
& pos
= wxDefaultPosition
,
74 const wxSize
& size
= wxDefaultSize
,
75 long style
= wxDEFAULT_FRAME_STYLE
,
76 const wxString
&name
= wxT("frame"))
77 : wxFrame(parent
, id
, title
, pos
, size
, style
| wxFRAME_SHAPED
, name
)
79 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
84 m_CanSetShape
= false; // have to wait for window create event on GTK
91 virtual bool SetTransparent(wxByte alpha
)
95 int w
=100; // some defaults
97 GetClientSize(&w
, &h
);
98 if ((alpha
!= m_Amount
) || (m_MaxWidth
<w
) | (m_MaxHeight
<h
))
100 // Make the region at least double the height and width so we don't have
101 // to rebuild if the size changes.
106 // m_Region.Union(0, 0, 1, m_MaxWidth);
109 for (int y
=0; y
<m_MaxHeight
; y
++)
111 // Reverse the order of the bottom 4 bits
112 int j
=((y
&8)?1:0)|((y
&4)?2:0)|((y
&2)?4:0)|((y
&1)?8:0);
113 if ((j
*16+8)<m_Amount
)
114 m_Region
.Union(0, y
, m_MaxWidth
, 1);
124 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
128 dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
129 dc
.SetPen(*wxTRANSPARENT_PEN
);
131 wxRegionIterator
upd(GetUpdateRegion()); // get the update rect list
135 wxRect
rect(upd
.GetRect());
136 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
143 void OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
)) {m_CanSetShape
=true; SetTransparent(0);}
154 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
155 DECLARE_EVENT_TABLE()
159 IMPLEMENT_DYNAMIC_CLASS( wxPseudoTransparentFrame
, wxFrame
)
161 BEGIN_EVENT_TABLE(wxPseudoTransparentFrame
, wxFrame
)
162 EVT_PAINT(wxPseudoTransparentFrame::OnPaint
)
164 EVT_WINDOW_CREATE(wxPseudoTransparentFrame::OnWindowCreate
)
169 // -- static utility functions --
171 static wxBitmap
wxPaneCreateStippleBitmap()
173 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
174 wxImage
img(2,2,data
,true);
175 return wxBitmap(img
);
178 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
180 wxBitmap stipple
= wxPaneCreateStippleBitmap();
181 wxBrush
brush(stipple
);
183 dc
.SetPen(*wxTRANSPARENT_PEN
);
185 dc
.SetLogicalFunction(wxXOR
);
186 dc
.DrawRectangle(rect
);
191 // CopyDocksAndPanes() - this utility function creates copies of
192 // the dock and pane info. wxDockInfo's usually contain pointers
193 // to wxPaneInfo classes, thus this function is necessary to reliably
194 // reconstruct that relationship in the new dock info and pane info arrays
196 static void CopyDocksAndPanes(wxDockInfoArray
& dest_docks
,
197 wxPaneInfoArray
& dest_panes
,
198 const wxDockInfoArray
& src_docks
,
199 const wxPaneInfoArray
& src_panes
)
201 dest_docks
= src_docks
;
202 dest_panes
= src_panes
;
203 int i
, j
, k
, dock_count
, pc1
, pc2
;
204 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
206 wxDockInfo
& dock
= dest_docks
.Item(i
);
207 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
208 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
209 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
210 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
214 // GetMaxLayer() is an internal function which returns
215 // the highest layer inside the specified dock
216 static int GetMaxLayer(const wxDockInfoArray
& docks
, int dock_direction
)
218 int i
, dock_count
, max_layer
= 0;
219 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
221 wxDockInfo
& dock
= docks
.Item(i
);
222 if (dock
.dock_direction
== dock_direction
&&
223 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
224 max_layer
= dock
.dock_layer
;
230 // GetMaxRow() is an internal function which returns
231 // the highest layer inside the specified dock
232 static int GetMaxRow(const wxPaneInfoArray
& panes
, int direction
, int layer
)
234 int i
, pane_count
, max_row
= 0;
235 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
237 wxPaneInfo
& pane
= panes
.Item(i
);
238 if (pane
.dock_direction
== direction
&&
239 pane
.dock_layer
== layer
&&
240 pane
.dock_row
> max_row
)
241 max_row
= pane
.dock_row
;
248 // DoInsertDockLayer() is an internal function that inserts a new dock
249 // layer by incrementing all existing dock layer values by one
250 static void DoInsertDockLayer(wxPaneInfoArray
& panes
,
255 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
257 wxPaneInfo
& pane
= panes
.Item(i
);
258 if (!pane
.IsFloating() &&
259 pane
.dock_direction
== dock_direction
&&
260 pane
.dock_layer
>= dock_layer
)
265 // DoInsertDockLayer() is an internal function that inserts a new dock
266 // row by incrementing all existing dock row values by one
267 static void DoInsertDockRow(wxPaneInfoArray
& panes
,
273 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
275 wxPaneInfo
& pane
= panes
.Item(i
);
276 if (!pane
.IsFloating() &&
277 pane
.dock_direction
== dock_direction
&&
278 pane
.dock_layer
== dock_layer
&&
279 pane
.dock_row
>= dock_row
)
284 // DoInsertDockLayer() is an internal function that inserts a space for
285 // another dock pane by incrementing all existing dock row values by one
286 static void DoInsertPane(wxPaneInfoArray
& panes
,
293 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
295 wxPaneInfo
& pane
= panes
.Item(i
);
296 if (!pane
.IsFloating() &&
297 pane
.dock_direction
== dock_direction
&&
298 pane
.dock_layer
== dock_layer
&&
299 pane
.dock_row
== dock_row
&&
300 pane
.dock_pos
>= dock_pos
)
305 // FindDocks() is an internal function that returns a list of docks which meet
306 // the specified conditions in the parameters and returns a sorted array
307 // (sorted by layer and then row)
308 static void FindDocks(wxDockInfoArray
& docks
,
312 wxDockInfoPtrArray
& arr
)
314 int begin_layer
= dock_layer
;
315 int end_layer
= dock_layer
;
316 int begin_row
= dock_row
;
317 int end_row
= dock_row
;
318 int dock_count
= docks
.GetCount();
319 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
321 // discover the maximum dock layer and the max row
322 for (i
= 0; i
< dock_count
; ++i
)
324 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
325 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
328 // if no dock layer was specified, search all dock layers
329 if (dock_layer
== -1)
332 end_layer
= max_layer
;
335 // if no dock row was specified, search all dock row
344 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
345 for (row
= begin_row
; row
<= end_row
; ++row
)
346 for (i
= 0; i
< dock_count
; ++i
)
348 wxDockInfo
& d
= docks
.Item(i
);
349 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
351 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
357 // FindPaneInDock() looks up a specified window pointer inside a dock.
358 // If found, the corresponding wxPaneInfo pointer is returned, otherwise NULL.
359 static wxPaneInfo
* FindPaneInDock(const wxDockInfo
& dock
, wxWindow
* window
)
361 int i
, count
= dock
.panes
.GetCount();
362 for (i
= 0; i
< count
; ++i
)
364 wxPaneInfo
* p
= dock
.panes
.Item(i
);
365 if (p
->window
== window
)
371 // RemovePaneFromDocks() removes a pane window from all docks
372 // with a possible exception specified by parameter "except"
373 static void RemovePaneFromDocks(wxDockInfoArray
& docks
,
375 wxDockInfo
* except
= NULL
)
378 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
380 wxDockInfo
& d
= docks
.Item(i
);
383 wxPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
389 // RenumberDockRows() takes a dock and assigns sequential numbers
390 // to existing rows. Basically it takes out the gaps; so if a
391 // dock has rows with numbers 0,2,5, they will become 0,1,2
392 static void RenumberDockRows(wxDockInfoPtrArray
& docks
)
394 int i
, dock_count
, j
, pane_count
;
395 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
397 wxDockInfo
& dock
= *docks
.Item(i
);
399 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
400 dock
.panes
.Item(j
)->dock_row
= i
;
405 // SetActivePane() sets the active pane, as well as cycles through
406 // every other pane and makes sure that all others' active flags
408 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
411 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
413 wxPaneInfo
& pane
= panes
.Item(i
);
414 pane
.state
&= ~wxPaneInfo::optionActive
;
415 if (pane
.window
== active_pane
)
416 pane
.state
|= wxPaneInfo::optionActive
;
421 // this function is used to sort panes by dock position
422 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
424 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
428 // -- wxFrameManager class implementation --
431 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
432 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
433 EVT_AUI_RENDER(wxFrameManager::OnRender
)
434 EVT_PAINT(wxFrameManager::OnPaint
)
435 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
436 EVT_SIZE(wxFrameManager::OnSize
)
437 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
438 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
439 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
440 EVT_MOTION(wxFrameManager::OnMotion
)
441 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
442 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
443 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
447 wxFrameManager::wxFrameManager(wxWindow
* managed_wnd
, unsigned int flags
)
449 m_action
= actionNone
;
450 m_last_mouse_move
= wxPoint();
451 m_hover_button
= NULL
;
452 m_art
= new wxDefaultDockArt
;
458 SetManagedWindow(managed_wnd
);
462 wxFrameManager::~wxFrameManager()
467 // GetPane() looks up a wxPaneInfo structure based
468 // on the supplied window pointer. Upon failure, GetPane()
469 // returns an empty wxPaneInfo, a condition which can be checked
470 // by calling wxPaneInfo::IsOk().
472 // The pane info's structure may then be modified. Once a pane's
473 // info is modified, wxFrameManager::Update() must be called to
474 // realize the changes in the UI.
476 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
479 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
481 wxPaneInfo
& p
= m_panes
.Item(i
);
482 if (p
.window
== window
)
485 return wxNullPaneInfo
;
488 // this version of GetPane() looks up a pane based on a
489 // 'pane name', see above comment for more info
490 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
493 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
495 wxPaneInfo
& p
= m_panes
.Item(i
);
499 return wxNullPaneInfo
;
502 // GetAllPanes() returns a reference to all the pane info structures
503 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
508 // HitTest() is an internal function which determines
509 // which UI item the specified coordinates are over
510 // (x,y) specify a position in client coordinates
511 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
513 wxDockUIPart
* result
= NULL
;
516 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
518 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
520 // we are not interested in typeDock, because this space
521 // isn't used to draw anything, just for measurements;
522 // besides, the entire dock area is covered with other
523 // rectangles, which we are interested in.
524 if (item
->type
== wxDockUIPart::typeDock
)
527 // if we already have a hit on a more specific item, we are not
528 // interested in a pane hit. If, however, we don't already have
529 // a hit, returning a pane hit is necessary for some operations
530 if ((item
->type
== wxDockUIPart::typePane
||
531 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
534 // if the point is inside the rectangle, we have a hit
535 if (item
->rect
.Inside(x
,y
))
543 // SetFlags() and GetFlags() allow the owner to set various
544 // options which are global to wxFrameManager
545 void wxFrameManager::SetFlags(unsigned int flags
)
550 unsigned int wxFrameManager::GetFlags() const
556 // don't use these anymore as they are deprecated
557 // use Set/GetManagedFrame() instead
558 void wxFrameManager::SetFrame(wxFrame
* frame
)
560 SetManagedWindow((wxWindow
*)frame
);
563 wxFrame
* wxFrameManager::GetFrame() const
565 return (wxFrame
*)m_frame
;
571 // SetManagedWindow() is usually called once when the frame
572 // manager class is being initialized. "frame" specifies
573 // the frame which should be managed by the frame mananger
574 void wxFrameManager::SetManagedWindow(wxWindow
* frame
)
576 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
579 m_frame
->PushEventHandler(this);
582 // if the owner is going to manage an MDI parent frame,
583 // we need to add the MDI client window as the default
586 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
588 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
589 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
591 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
593 AddPane(client_window
,
594 wxPaneInfo().Name(wxT("mdiclient")).
595 CenterPane().PaneBorder(false));
599 // Make a window to use for a transparent hint
600 #if defined(__WXMSW__) || defined(__WXGTK__)
601 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
602 wxFRAME_TOOL_WINDOW
|
603 wxFRAME_FLOAT_ON_PARENT
|
607 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
609 #elif defined(__WXMAC__)
610 // Using a miniframe with float and tool styles keeps the parent
611 // frame activated and highlighted as such...
612 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
613 wxFRAME_FLOAT_ON_PARENT
614 | wxFRAME_TOOL_WINDOW
617 // Can't set the bg colour of a Frame in wxMac
618 wxPanel
* p
= new wxPanel(m_hint_wnd
);
620 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
621 // color that is really hard to see, especially transparent.
622 // Until a better system color is decided upon we'll just use
624 p
->SetBackgroundColour(*wxBLUE
);
630 // CanSetTransparent is only present in the 2.7.0 ABI. To allow this file to be easily used
631 // in a backported environment, conditionally compile this in.
632 #if wxCHECK_VERSION(2,7,0)
633 && !m_hint_wnd
->CanSetTransparent()
639 m_hint_wnd
->Destroy();
642 // If we can convert it to a PseudoTransparent window, do so
643 m_hint_wnd
= new wxPseudoTransparentFrame (m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
644 wxFRAME_TOOL_WINDOW
|
645 wxFRAME_FLOAT_ON_PARENT
|
649 m_hint_fademax
= 128;
654 // UnInit() must be called, usually in the destructor
655 // of the frame class. If it is not called, usually this
656 // will result in a crash upon program exit
657 void wxFrameManager::UnInit()
659 m_frame
->RemoveEventHandler(this);
662 // GetManagedWindow() returns the window pointer being managed
663 wxWindow
* wxFrameManager::GetManagedWindow() const
668 wxDockArt
* wxFrameManager::GetArtProvider() const
673 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
675 // first, give the owner frame a chance to override
678 if (m_frame
->ProcessEvent(event
))
685 // SetArtProvider() instructs wxFrameManager to use the
686 // specified art provider for all drawing calls. This allows
687 // plugable look-and-feel features. The pointer that is
688 // passed to this method subsequently belongs to wxFrameManager,
689 // and is deleted in the frame manager destructor
690 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
692 // delete the last art provider, if any
695 // assign the new art provider
696 m_art
= art_provider
;
700 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
702 // check if the pane has a valid window
706 // check if the pane already exists
707 if (GetPane(pane_info
.window
).IsOk())
710 m_panes
.Add(pane_info
);
712 wxPaneInfo
& pinfo
= m_panes
.Last();
714 // set the pane window
715 pinfo
.window
= window
;
717 // if the pane's name identifier is blank, create a random string
718 if (pinfo
.name
.empty())
720 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
721 ((unsigned long)pinfo
.window
) & 0xffffffff,
722 (unsigned int)time(NULL
),
724 (unsigned int)GetTickCount(),
726 (unsigned int)clock(),
728 (unsigned long)m_panes
.GetCount());
731 // set initial proportion (if not already set)
732 if (pinfo
.dock_proportion
== 0)
733 pinfo
.dock_proportion
= 100000;
735 if (pinfo
.HasCloseButton() &&
736 pinfo
.buttons
.size() == 0)
739 button
.button_id
= wxPaneInfo::buttonClose
;
740 pinfo
.buttons
.Add(button
);
743 if (pinfo
.best_size
== wxDefaultSize
&&
746 pinfo
.best_size
= pinfo
.window
->GetClientSize();
748 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
750 // GetClientSize() doesn't get the best size for
751 // a toolbar under some newer versions of wxWidgets,
752 // so use GetBestSize()
753 pinfo
.best_size
= pinfo
.window
->GetBestSize();
755 // for some reason, wxToolBar::GetBestSize() is returning
756 // a size that is a pixel shy of the correct amount.
757 // I believe this to be the correct action, until
758 // wxToolBar::GetBestSize() is fixed. Is this assumption
763 if (pinfo
.min_size
!= wxDefaultSize
)
765 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
766 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
767 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
768 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
775 bool wxFrameManager::AddPane(wxWindow
* window
,
777 const wxString
& caption
)
780 pinfo
.Caption(caption
);
783 case wxTOP
: pinfo
.Top(); break;
784 case wxBOTTOM
: pinfo
.Bottom(); break;
785 case wxLEFT
: pinfo
.Left(); break;
786 case wxRIGHT
: pinfo
.Right(); break;
787 case wxCENTER
: pinfo
.CenterPane(); break;
789 return AddPane(window
, pinfo
);
792 bool wxFrameManager::AddPane(wxWindow
* window
,
793 const wxPaneInfo
& pane_info
,
794 const wxPoint
& drop_pos
)
796 if (!AddPane(window
, pane_info
))
799 wxPaneInfo
& pane
= GetPane(window
);
801 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
806 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
809 // shift the panes around, depending on the insert level
810 switch (insert_level
)
812 case wxAUI_INSERT_PANE
:
813 DoInsertPane(m_panes
,
814 pane_info
.dock_direction
,
815 pane_info
.dock_layer
,
819 case wxAUI_INSERT_ROW
:
820 DoInsertDockRow(m_panes
,
821 pane_info
.dock_direction
,
822 pane_info
.dock_layer
,
825 case wxAUI_INSERT_DOCK
:
826 DoInsertDockLayer(m_panes
,
827 pane_info
.dock_direction
,
828 pane_info
.dock_layer
);
832 // if the window already exists, we are basically just moving/inserting the
833 // existing window. If it doesn't exist, we need to add it and insert it
834 wxPaneInfo
& existing_pane
= GetPane(window
);
835 if (!existing_pane
.IsOk())
837 return AddPane(window
, pane_info
);
841 if (pane_info
.IsFloating())
843 existing_pane
.Float();
844 if (pane_info
.floating_pos
!= wxDefaultPosition
)
845 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
846 if (pane_info
.floating_size
!= wxDefaultSize
)
847 existing_pane
.FloatingSize(pane_info
.floating_size
);
851 existing_pane
.Direction(pane_info
.dock_direction
);
852 existing_pane
.Layer(pane_info
.dock_layer
);
853 existing_pane
.Row(pane_info
.dock_row
);
854 existing_pane
.Position(pane_info
.dock_pos
);
862 // DetachPane() removes a pane from the frame manager. This
863 // method will not destroy the window that is removed.
864 bool wxFrameManager::DetachPane(wxWindow
* window
)
867 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
869 wxPaneInfo
& p
= m_panes
.Item(i
);
870 if (p
.window
== window
)
874 // we have a floating frame which is being detached. We need to
875 // reparent it to m_frame and destroy the floating frame
878 p
.window
->SetSize(1,1);
879 p
.frame
->Show(false);
881 // reparent to m_frame and destroy the pane
882 p
.window
->Reparent(m_frame
);
883 p
.frame
->SetSizer(NULL
);
888 // make sure there are no references to this pane in our uiparts,
889 // just in case the caller doesn't call Update() immediately after
890 // the DetachPane() call. This prevets obscure crashes which would
891 // happen at window repaint if the caller forgets to call Update()
893 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
895 wxDockUIPart
& part
= m_uiparts
.Item(pi
);
898 m_uiparts
.RemoveAt(pi
);
913 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
914 // in the input string. This is an internal functions which is
915 // used for saving perspectives
916 static wxString
EscapeDelimiters(const wxString
& s
)
919 result
.Alloc(s
.length());
920 const wxChar
* ch
= s
.c_str();
923 if (*ch
== wxT(';') || *ch
== wxT('|'))
931 wxString
wxFrameManager::SavePaneInfo(wxPaneInfo
& pane
)
933 wxString result
= wxT("name=");
934 result
+= EscapeDelimiters(pane
.name
);
937 result
+= wxT("caption=");
938 result
+= EscapeDelimiters(pane
.caption
);
941 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
942 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
943 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
944 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
945 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
946 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
947 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
948 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
949 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
950 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
951 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
952 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
953 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
954 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
955 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
956 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
961 // Load a "pane" with the pane infor settings in pane_part; return the remainder of the
963 wxString
wxFrameManager::LoadPaneInfo(wxString pane_part
, wxPaneInfo
&pane
)
965 // replace escaped characters so we can
966 // split up the string easily
967 pane_part
.Replace(wxT("\\|"), wxT("\a"));
968 pane_part
.Replace(wxT("\\;"), wxT("\b"));
970 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
971 pane_part
= pane_part
.AfterFirst(wxT(';'));
972 wxString val_name
= val_part
.BeforeFirst(wxT('='));
973 wxString value
= val_part
.AfterFirst(wxT('='));
974 val_name
.MakeLower();
976 val_name
.Trim(false);
980 if (val_name
.empty())
981 return wxEmptyString
;
983 if (val_name
== wxT("name"))
985 else if (val_name
== wxT("caption"))
986 pane
.caption
= value
;
987 else if (val_name
== wxT("state"))
988 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
989 else if (val_name
== wxT("dir"))
990 pane
.dock_direction
= wxAtoi(value
.c_str());
991 else if (val_name
== wxT("layer"))
992 pane
.dock_layer
= wxAtoi(value
.c_str());
993 else if (val_name
== wxT("row"))
994 pane
.dock_row
= wxAtoi(value
.c_str());
995 else if (val_name
== wxT("pos"))
996 pane
.dock_pos
= wxAtoi(value
.c_str());
997 else if (val_name
== wxT("prop"))
998 pane
.dock_proportion
= wxAtoi(value
.c_str());
999 else if (val_name
== wxT("bestw"))
1000 pane
.best_size
.x
= wxAtoi(value
.c_str());
1001 else if (val_name
== wxT("besth"))
1002 pane
.best_size
.y
= wxAtoi(value
.c_str());
1003 else if (val_name
== wxT("minw"))
1004 pane
.min_size
.x
= wxAtoi(value
.c_str());
1005 else if (val_name
== wxT("minh"))
1006 pane
.min_size
.y
= wxAtoi(value
.c_str());
1007 else if (val_name
== wxT("maxw"))
1008 pane
.max_size
.x
= wxAtoi(value
.c_str());
1009 else if (val_name
== wxT("maxh"))
1010 pane
.max_size
.y
= wxAtoi(value
.c_str());
1011 else if (val_name
== wxT("floatx"))
1012 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1013 else if (val_name
== wxT("floaty"))
1014 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1015 else if (val_name
== wxT("floatw"))
1016 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1017 else if (val_name
== wxT("floath"))
1018 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1020 wxFAIL_MSG(wxT("Bad Perspective String"));
1023 // replace escaped characters so we can
1024 // split up the string easily
1025 pane
.name
.Replace(wxT("\a"), wxT("|"));
1026 pane
.name
.Replace(wxT("\b"), wxT(";"));
1027 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1028 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1029 pane_part
.Replace(wxT("\a"), wxT("|"));
1030 pane_part
.Replace(wxT("\b"), wxT(";"));
1036 // SavePerspective() saves all pane information as a single string.
1037 // This string may later be fed into LoadPerspective() to restore
1038 // all pane settings. This save and load mechanism allows an
1039 // exact pane configuration to be saved and restored at a later time
1041 wxString
wxFrameManager::SavePerspective()
1045 result
= wxT("layout1|");
1047 int pane_i
, pane_count
= m_panes
.GetCount();
1048 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1050 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
1051 result
+= SavePaneInfo(pane
)+wxT("|");
1054 int dock_i
, dock_count
= m_docks
.GetCount();
1055 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1057 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
1059 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1060 dock
.dock_direction
, dock
.dock_layer
,
1061 dock
.dock_row
, dock
.size
);
1067 // LoadPerspective() loads a layout which was saved with SavePerspective()
1068 // If the "update" flag parameter is true, the GUI will immediately be updated
1070 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
1072 wxString input
= layout
;
1075 // check layout string version
1076 part
= input
.BeforeFirst(wxT('|'));
1077 input
= input
.AfterFirst(wxT('|'));
1080 if (part
!= wxT("layout1"))
1083 // mark all panes currently managed as docked and hidden
1084 int pane_i
, pane_count
= m_panes
.GetCount();
1085 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1086 m_panes
.Item(pane_i
).Dock().Hide();
1088 // clear out the dock array; this will be reconstructed
1091 // replace escaped characters so we can
1092 // split up the string easily
1093 input
.Replace(wxT("\\|"), wxT("\a"));
1094 input
.Replace(wxT("\\;"), wxT("\b"));
1100 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1101 input
= input
.AfterFirst(wxT('|'));
1102 pane_part
.Trim(true);
1104 // if the string is empty, we're done parsing
1105 if (pane_part
.empty())
1108 if (pane_part
.Left(9) == wxT("dock_size"))
1110 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1111 wxString value
= pane_part
.AfterFirst(wxT('='));
1113 long dir
, layer
, row
, size
;
1114 wxString piece
= val_name
.AfterFirst(wxT('('));
1115 piece
= piece
.BeforeLast(wxT(')'));
1116 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1117 piece
= piece
.AfterFirst(wxT(','));
1118 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1119 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1120 value
.ToLong(&size
);
1123 dock
.dock_direction
= dir
;
1124 dock
.dock_layer
= layer
;
1125 dock
.dock_row
= row
;
1131 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1132 // name so it can be called by external callers
1133 pane_part
.Replace(wxT("\a"), wxT("|"));
1134 pane_part
.Replace(wxT("\b"), wxT(";"));
1136 while (!pane_part
.empty())
1138 pane_part
= LoadPaneInfo(pane_part
, pane
);
1141 wxPaneInfo
& p
= GetPane(pane
.name
);
1144 // the pane window couldn't be found
1145 // in the existing layout
1159 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
1160 wxArrayInt
& positions
,
1163 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1164 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1165 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1170 int offset
, action_pane
= -1;
1171 int pane_i
, pane_count
= dock
.panes
.GetCount();
1173 // find the pane marked as our action pane
1174 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1176 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1178 if (pane
.state
& wxPaneInfo::actionPane
)
1180 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1181 action_pane
= pane_i
;
1185 // set up each panes default position, and
1186 // determine the size (width or height, depending
1187 // on the dock's orientation) of each pane
1188 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1190 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1191 positions
.Add(pane
.dock_pos
);
1194 if (pane
.HasBorder())
1195 size
+= (pane_border_size
*2);
1197 if (dock
.IsHorizontal())
1199 if (pane
.HasGripper() && !pane
.HasGripperTop())
1200 size
+= gripper_size
;
1201 size
+= pane
.best_size
.x
;
1205 if (pane
.HasGripper() && pane
.HasGripperTop())
1206 size
+= gripper_size
;
1208 if (pane
.HasCaption())
1209 size
+= caption_size
;
1210 size
+= pane
.best_size
.y
;
1216 // if there is no action pane, just return the default
1217 // positions (as specified in pane.pane_pos)
1218 if (action_pane
== -1)
1222 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1224 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1229 positions
[pane_i
] -= -amount
;
1231 offset
+= sizes
[pane_i
];
1234 // if the dock mode is fixed, make sure none of the panes
1235 // overlap; we will bump panes that overlap
1237 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1239 int amount
= positions
[pane_i
] - offset
;
1243 positions
[pane_i
] += -amount
;
1245 offset
+= sizes
[pane_i
];
1250 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1253 wxDockUIPartArray
& uiparts
,
1257 wxSizerItem
* sizer_item
;
1259 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1260 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1261 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1262 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1264 // find out the orientation of the item (orientation for panes
1265 // is the same as the dock's orientation)
1267 if (dock
.IsHorizontal())
1268 orientation
= wxHORIZONTAL
;
1270 orientation
= wxVERTICAL
;
1272 // this variable will store the proportion
1273 // value that the pane will receive
1274 int pane_proportion
= pane
.dock_proportion
;
1276 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1277 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1279 if (pane
.HasGripper())
1281 if (pane
.HasGripperTop())
1282 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1284 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1286 part
.type
= wxDockUIPart::typeGripper
;
1290 part
.orientation
= orientation
;
1291 part
.cont_sizer
= horz_pane_sizer
;
1292 part
.sizer_item
= sizer_item
;
1296 if (pane
.HasCaption())
1298 // create the caption sizer
1299 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1301 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1303 part
.type
= wxDockUIPart::typeCaption
;
1307 part
.orientation
= orientation
;
1308 part
.cont_sizer
= vert_pane_sizer
;
1309 part
.sizer_item
= sizer_item
;
1310 int caption_part_idx
= uiparts
.GetCount();
1313 // add pane buttons to the caption
1314 int i
, button_count
;
1315 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1316 i
< button_count
; ++i
)
1318 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1320 sizer_item
= caption_sizer
->Add(pane_button_size
,
1324 part
.type
= wxDockUIPart::typePaneButton
;
1327 part
.button
= &button
;
1328 part
.orientation
= orientation
;
1329 part
.cont_sizer
= caption_sizer
;
1330 part
.sizer_item
= sizer_item
;
1334 // add the caption sizer
1335 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1337 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1340 // add the pane window itself
1343 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1347 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1348 // Don't do this because it breaks the pane size in floating windows
1349 // BIW: Right now commenting this out is causing problems with
1350 // an mdi client window as the center pane.
1351 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1354 part
.type
= wxDockUIPart::typePane
;
1358 part
.orientation
= orientation
;
1359 part
.cont_sizer
= vert_pane_sizer
;
1360 part
.sizer_item
= sizer_item
;
1364 // determine if the pane should have a minimum size; if the pane is
1365 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1366 // if the pane.min_size is set, we must use that value as well
1368 wxSize min_size
= pane
.min_size
;
1371 if (min_size
== wxDefaultSize
)
1373 min_size
= pane
.best_size
;
1374 pane_proportion
= 0;
1378 if (min_size
!= wxDefaultSize
)
1380 vert_pane_sizer
->SetItemMinSize(
1381 vert_pane_sizer
->GetChildren().GetCount()-1,
1382 min_size
.x
, min_size
.y
);
1386 // add the verticle sizer (caption, pane window) to the
1387 // horizontal sizer (gripper, verticle sizer)
1388 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1390 // finally, add the pane sizer to the dock sizer
1392 if (pane
.HasBorder())
1394 // allowing space for the pane's border
1395 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1396 wxEXPAND
| wxALL
, pane_border_size
);
1398 part
.type
= wxDockUIPart::typePaneBorder
;
1402 part
.orientation
= orientation
;
1403 part
.cont_sizer
= cont
;
1404 part
.sizer_item
= sizer_item
;
1409 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1413 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1415 wxDockUIPartArray
& uiparts
,
1418 wxSizerItem
* sizer_item
;
1421 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1422 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1424 // resizable bottom and right docks have a sash before them
1425 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1426 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1428 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1430 part
.type
= wxDockUIPart::typeDockSizer
;
1431 part
.orientation
= orientation
;
1435 part
.cont_sizer
= cont
;
1436 part
.sizer_item
= sizer_item
;
1440 // create the sizer for the dock
1441 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1443 // add each pane to the dock
1444 int pane_i
, pane_count
= dock
.panes
.GetCount();
1448 wxArrayInt pane_positions
, pane_sizes
;
1450 // figure out the real pane positions we will
1451 // use, without modifying the each pane's pane_pos member
1452 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1455 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1457 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1458 int pane_pos
= pane_positions
.Item(pane_i
);
1460 int amount
= pane_pos
- offset
;
1463 if (dock
.IsVertical())
1464 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1466 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1468 part
.type
= wxDockUIPart::typeBackground
;
1472 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1473 part
.cont_sizer
= dock_sizer
;
1474 part
.sizer_item
= sizer_item
;
1480 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1482 offset
+= pane_sizes
.Item(pane_i
);
1485 // at the end add a very small stretchable background area
1486 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1488 part
.type
= wxDockUIPart::typeBackground
;
1492 part
.orientation
= orientation
;
1493 part
.cont_sizer
= dock_sizer
;
1494 part
.sizer_item
= sizer_item
;
1499 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1501 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1503 // if this is not the first pane being added,
1504 // we need to add a pane sizer
1507 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1509 part
.type
= wxDockUIPart::typePaneSizer
;
1511 part
.pane
= dock
.panes
.Item(pane_i
-1);
1513 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1514 part
.cont_sizer
= dock_sizer
;
1515 part
.sizer_item
= sizer_item
;
1519 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1523 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1524 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1526 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1528 part
.type
= wxDockUIPart::typeDock
;
1532 part
.orientation
= orientation
;
1533 part
.cont_sizer
= cont
;
1534 part
.sizer_item
= sizer_item
;
1537 if (dock
.IsHorizontal())
1538 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1540 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1542 // top and left docks have a sash after them
1543 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1544 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1546 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1548 part
.type
= wxDockUIPart::typeDockSizer
;
1552 part
.orientation
= orientation
;
1553 part
.cont_sizer
= cont
;
1554 part
.sizer_item
= sizer_item
;
1559 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1560 wxDockInfoArray
& docks
,
1561 wxDockUIPartArray
& uiparts
,
1564 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1566 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1567 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1568 wxSize cli_size
= m_frame
->GetClientSize();
1569 int i
, dock_count
, pane_count
;
1572 // empty all docks out
1573 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1574 docks
.Item(i
).panes
.Empty();
1576 // iterate through all known panes, filing each
1577 // of them into the appropriate dock. If the
1578 // pane does not exist in the dock, add it
1579 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1581 wxPaneInfo
& p
= panes
.Item(i
);
1583 // find any docks in this layer
1585 wxDockInfoPtrArray arr
;
1586 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1588 if (arr
.GetCount() > 0)
1594 // dock was not found, so we need to create a new one
1596 d
.dock_direction
= p
.dock_direction
;
1597 d
.dock_layer
= p
.dock_layer
;
1598 d
.dock_row
= p
.dock_row
;
1600 dock
= &docks
.Last();
1604 if (p
.IsDocked() && p
.IsShown())
1606 // remove the pane from any existing docks except this one
1607 RemovePaneFromDocks(docks
, p
, dock
);
1609 // pane needs to be added to the dock,
1610 // if it doesn't already exist
1611 if (!FindPaneInDock(*dock
, p
.window
))
1612 dock
->panes
.Add(&p
);
1616 // remove the pane from any existing docks
1617 RemovePaneFromDocks(docks
, p
);
1622 // remove any empty docks
1623 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1625 if (docks
.Item(i
).panes
.GetCount() == 0)
1629 // configure the docks further
1630 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1632 wxDockInfo
& dock
= docks
.Item(i
);
1633 int j
, dock_pane_count
= dock
.panes
.GetCount();
1635 // sort the dock pane array by the pane's
1636 // dock position (dock_pos), in ascending order
1637 dock
.panes
.Sort(PaneSortFunc
);
1639 // for newly created docks, set up their initial size
1644 for (j
= 0; j
< dock_pane_count
; ++j
)
1646 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1647 wxSize pane_size
= pane
.best_size
;
1648 if (pane_size
== wxDefaultSize
)
1649 pane_size
= pane
.min_size
;
1650 if (pane_size
== wxDefaultSize
)
1651 pane_size
= pane
.window
->GetSize();
1653 if (dock
.IsHorizontal())
1654 size
= wxMax(pane_size
.y
, size
);
1656 size
= wxMax(pane_size
.x
, size
);
1659 // add space for the border (two times), but only
1660 // if at least one pane inside the dock has a pane border
1661 for (j
= 0; j
< dock_pane_count
; ++j
)
1663 if (dock
.panes
.Item(j
)->HasBorder())
1665 size
+= (pane_border_size
*2);
1670 // if pane is on the top or bottom, add the caption height,
1671 // but only if at least one pane inside the dock has a caption
1672 if (dock
.IsHorizontal())
1674 for (j
= 0; j
< dock_pane_count
; ++j
)
1676 if (dock
.panes
.Item(j
)->HasCaption())
1678 size
+= caption_size
;
1684 // new dock's size may not be more than 1/3 of the frame size
1685 if (dock
.IsHorizontal())
1686 size
= wxMin(size
, cli_size
.y
/3);
1688 size
= wxMin(size
, cli_size
.x
/3);
1696 // determine the dock's minimum size
1697 bool plus_border
= false;
1698 bool plus_caption
= false;
1699 int dock_min_size
= 0;
1700 for (j
= 0; j
< dock_pane_count
; ++j
)
1702 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1703 if (pane
.min_size
!= wxDefaultSize
)
1705 if (pane
.HasBorder())
1707 if (pane
.HasCaption())
1708 plus_caption
= true;
1709 if (dock
.IsHorizontal())
1711 if (pane
.min_size
.y
> dock_min_size
)
1712 dock_min_size
= pane
.min_size
.y
;
1716 if (pane
.min_size
.x
> dock_min_size
)
1717 dock_min_size
= pane
.min_size
.x
;
1723 dock_min_size
+= (pane_border_size
*2);
1724 if (plus_caption
&& dock
.IsHorizontal())
1725 dock_min_size
+= (caption_size
);
1727 dock
.min_size
= dock_min_size
;
1730 // if the pane's current size is less than it's
1731 // minimum, increase the dock's size to it's minimum
1732 if (dock
.size
< dock
.min_size
)
1733 dock
.size
= dock
.min_size
;
1736 // determine the dock's mode (fixed or proportional);
1737 // determine whether the dock has only toolbars
1738 bool action_pane_marked
= false;
1740 dock
.toolbar
= true;
1741 for (j
= 0; j
< dock_pane_count
; ++j
)
1743 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1744 if (!pane
.IsFixed())
1746 if (!pane
.IsToolbar())
1747 dock
.toolbar
= false;
1748 if (pane
.state
& wxPaneInfo::actionPane
)
1749 action_pane_marked
= true;
1753 // if the dock mode is proportional and not fixed-pixel,
1754 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1755 // e.g. remove gaps like 1, 2, 30, 500
1758 for (j
= 0; j
< dock_pane_count
; ++j
)
1760 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1765 // if the dock mode is fixed, and none of the panes
1766 // are being moved right now, make sure the panes
1767 // do not overlap each other. If they do, we will
1768 // adjust the panes' positions
1769 if (dock
.fixed
&& !action_pane_marked
)
1771 wxArrayInt pane_positions
, pane_sizes
;
1772 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1775 for (j
= 0; j
< dock_pane_count
; ++j
)
1777 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1778 pane
.dock_pos
= pane_positions
[j
];
1780 int amount
= pane
.dock_pos
- offset
;
1784 pane
.dock_pos
+= -amount
;
1786 offset
+= pane_sizes
[j
];
1791 // discover the maximum dock layer
1793 for (i
= 0; i
< dock_count
; ++i
)
1794 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1797 // clear out uiparts
1800 // create a bunch of box sizers,
1801 // from the innermost level outwards.
1802 wxSizer
* cont
= NULL
;
1803 wxSizer
* middle
= NULL
;
1807 for (layer
= 0; layer
<= max_layer
; ++layer
)
1809 wxDockInfoPtrArray arr
;
1811 // find any docks in this layer
1812 FindDocks(docks
, -1, layer
, -1, arr
);
1814 // if there aren't any, skip to the next layer
1818 wxSizer
* old_cont
= cont
;
1820 // create a container which will hold this layer's
1821 // docks (top, bottom, left, right)
1822 cont
= new wxBoxSizer(wxVERTICAL
);
1825 // find any top docks in this layer
1826 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1827 RenumberDockRows(arr
);
1830 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1831 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1835 // fill out the middle layer (which consists
1836 // of left docks, content area and right docks)
1838 middle
= new wxBoxSizer(wxHORIZONTAL
);
1840 // find any left docks in this layer
1841 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1842 RenumberDockRows(arr
);
1845 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1846 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1849 // add content dock (or previous layer's sizer
1853 // find any center docks
1854 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1857 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1858 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1862 // there are no center docks, add a background area
1863 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1865 part
.type
= wxDockUIPart::typeBackground
;
1869 part
.cont_sizer
= middle
;
1870 part
.sizer_item
= sizer_item
;
1876 middle
->Add(old_cont
, 1, wxEXPAND
);
1879 // find any right docks in this layer
1880 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1881 RenumberDockRows(arr
);
1884 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1885 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1888 cont
->Add(middle
, 1, wxEXPAND
);
1892 // find any bottom docks in this layer
1893 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1894 RenumberDockRows(arr
);
1897 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1898 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1905 // no sizer available, because there are no docks,
1906 // therefore we will create a simple background area
1907 cont
= new wxBoxSizer(wxVERTICAL
);
1908 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1910 part
.type
= wxDockUIPart::typeBackground
;
1914 part
.cont_sizer
= middle
;
1915 part
.sizer_item
= sizer_item
;
1919 container
->Add(cont
, 1, wxEXPAND
);
1924 // Update() updates the layout. Whenever changes are made to
1925 // one or more panes, this function should be called. It is the
1926 // external entry point for running the layout engine.
1928 void wxFrameManager::Update()
1931 int i
, pane_count
= m_panes
.GetCount();
1933 // delete old sizer first
1934 m_frame
->SetSizer(NULL
);
1936 // destroy floating panes which have been
1937 // redocked or are becoming non-floating
1938 for (i
= 0; i
< pane_count
; ++i
)
1940 wxPaneInfo
& p
= m_panes
.Item(i
);
1942 if (!p
.IsFloating() && p
.frame
)
1944 // because the pane is no longer in a floating, we need to
1945 // reparent it to m_frame and destroy the floating frame
1948 p
.window
->SetSize(1,1);
1949 p
.frame
->Show(false);
1951 // reparent to m_frame and destroy the pane
1952 p
.window
->Reparent(m_frame
);
1953 p
.frame
->SetSizer(NULL
);
1960 // create a layout for all of the panes
1961 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
1963 // hide or show panes as necessary,
1964 // and float panes as necessary
1965 for (i
= 0; i
< pane_count
; ++i
)
1967 wxPaneInfo
& p
= m_panes
.Item(i
);
1971 if (p
.frame
== NULL
)
1973 // we need to create a frame for this
1974 // pane, which has recently been floated
1975 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
1979 #if wxCHECK_VERSION(2,7,0)
1980 // on MSW and Mac, if the owner desires transparent dragging, and
1981 // the dragging is happening right now, then the floating
1982 // window should have this style by default
1983 if (m_action
== actionDragFloatingPane
&&
1984 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
1985 frame
->SetTransparent(150);
1988 frame
->SetPaneWindow(p
);
1998 // frame already exists, make sure it's position
1999 // and size reflect the information in wxPaneInfo
2000 if (p
.frame
->GetPosition() != p
.floating_pos
)
2002 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2003 wxDefaultCoord
, wxDefaultCoord
,
2004 wxSIZE_USE_EXISTING
);
2005 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2008 p
.frame
->Show(p
.IsShown());
2013 p
.window
->Show(p
.IsShown());
2016 // if "active panes" are no longer allowed, clear
2017 // any optionActive values from the pane states
2018 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2020 p
.state
&= ~wxPaneInfo::optionActive
;
2025 // keep track of the old window rectangles so we can
2026 // refresh those windows whose rect has changed
2027 wxAuiRectArray old_pane_rects
;
2028 for (i
= 0; i
< pane_count
; ++i
)
2031 wxPaneInfo
& p
= m_panes
.Item(i
);
2033 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2036 old_pane_rects
.Add(r
);
2042 // apply the new sizer
2043 m_frame
->SetSizer(sizer
);
2044 m_frame
->SetAutoLayout(false);
2049 // now that the frame layout is done, we need to check
2050 // the new pane rectangles against the old rectangles that
2051 // we saved a few lines above here. If the rectangles have
2052 // changed, the corresponding panes must also be updated
2053 for (i
= 0; i
< pane_count
; ++i
)
2055 wxPaneInfo
& p
= m_panes
.Item(i
);
2056 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2058 if (p
.rect
!= old_pane_rects
[i
])
2060 p
.window
->Refresh();
2069 // set frame's minimum size
2072 // N.B. More work needs to be done on frame minimum sizes;
2073 // this is some intresting code that imposes the minimum size,
2074 // but we may want to include a more flexible mechanism or
2075 // options for multiple minimum-size modes, e.g. strict or lax
2076 wxSize min_size = sizer->GetMinSize();
2077 wxSize frame_size = m_frame->GetSize();
2078 wxSize client_size = m_frame->GetClientSize();
2080 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2081 min_size.y+frame_size.y-client_size.y );
2083 m_frame->SetMinSize(minframe_size);
2085 if (frame_size.x < minframe_size.x ||
2086 frame_size.y < minframe_size.y)
2087 sizer->Fit(m_frame);
2092 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2093 // on the frame's main sizer, then measures all the various UI items
2094 // and updates their internal rectangles. This should always be called
2095 // instead of calling m_frame->Layout() directly
2097 void wxFrameManager::DoFrameLayout()
2102 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2104 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2106 // get the rectangle of the UI part
2107 // originally, this code looked like this:
2108 // part.rect = wxRect(part.sizer_item->GetPosition(),
2109 // part.sizer_item->GetSize());
2110 // this worked quite well, with one exception: the mdi
2111 // client window had a "deferred" size variable
2112 // that returned the wrong size. It looks like
2113 // a bug in wx, because the former size of the window
2114 // was being returned. So, we will retrieve the part's
2115 // rectangle via other means
2118 part
.rect
= part
.sizer_item
->GetRect();
2119 int flag
= part
.sizer_item
->GetFlag();
2120 int border
= part
.sizer_item
->GetBorder();
2123 part
.rect
.y
-= border
;
2124 part
.rect
.height
+= border
;
2128 part
.rect
.x
-= border
;
2129 part
.rect
.width
+= border
;
2131 if (flag
& wxBOTTOM
)
2132 part
.rect
.height
+= border
;
2134 part
.rect
.width
+= border
;
2137 if (part
.type
== wxDockUIPart::typeDock
)
2138 part
.dock
->rect
= part
.rect
;
2139 if (part
.type
== wxDockUIPart::typePane
)
2140 part
.pane
->rect
= part
.rect
;
2144 // GetPanePart() looks up the pane the pane border UI part (or the regular
2145 // pane part if there is no border). This allows the caller to get the exact
2146 // rectangle of the pane in question, including decorations like
2147 // caption and border (if any).
2149 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
2152 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2154 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2155 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2156 part
.pane
&& part
.pane
->window
== wnd
)
2159 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2161 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2162 if (part
.type
== wxDockUIPart::typePane
&&
2163 part
.pane
&& part
.pane
->window
== wnd
)
2171 // GetDockPixelOffset() is an internal function which returns
2172 // a dock's offset in pixels from the left side of the window
2173 // (for horizontal docks) or from the top of the window (for
2174 // vertical docks). This value is necessary for calculating
2175 // fixel-pane/toolbar offsets when they are dragged.
2177 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
2179 // the only way to accurately calculate the dock's
2180 // offset is to actually run a theoretical layout
2182 int i
, part_count
, dock_count
;
2183 wxDockInfoArray docks
;
2184 wxPaneInfoArray panes
;
2185 wxDockUIPartArray uiparts
;
2186 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2189 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2190 wxSize client_size
= m_frame
->GetClientSize();
2191 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2194 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2196 wxDockUIPart
& part
= uiparts
.Item(i
);
2197 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2198 part
.sizer_item
->GetSize());
2199 if (part
.type
== wxDockUIPart::typeDock
)
2200 part
.dock
->rect
= part
.rect
;
2205 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2207 wxDockInfo
& dock
= docks
.Item(i
);
2208 if (test
.dock_direction
== dock
.dock_direction
&&
2209 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2211 if (dock
.IsVertical())
2223 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2224 // if a dock operation is allowed, the new dock position is copied into
2225 // the target info. If the operation was allowed, the function returns true.
2227 bool wxFrameManager::ProcessDockResult(wxPaneInfo
& target
,
2228 const wxPaneInfo
& new_pos
)
2230 bool allowed
= false;
2231 switch (new_pos
.dock_direction
)
2233 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2234 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2235 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2236 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2246 // DoDrop() is an important function. It basically takes a mouse position,
2247 // and determines where the pane's new position would be. If the pane is to be
2248 // dropped, it performs the drop operation using the specified dock and pane
2249 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2250 // scenario can be performed, giving precise coordinates for drop hints.
2251 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2252 // as parameters, the changes will be made to the main state arrays
2254 const int auiInsertRowPixels
= 10;
2255 const int auiNewRowPixels
= 40;
2256 const int auiLayerInsertPixels
= 40;
2257 const int auiLayerInsertOffset
= 5;
2259 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2260 wxPaneInfoArray
& panes
,
2263 const wxPoint
& offset
)
2265 wxSize cli_size
= m_frame
->GetClientSize();
2267 wxPaneInfo drop
= target
;
2270 // The result should always be shown
2274 // Check to see if the pane has been dragged outside of the window
2275 // (or near to the outside of the window), if so, dock it along the edge
2278 int layer_insert_offset
= auiLayerInsertOffset
;
2279 if (target
.IsToolbar())
2280 layer_insert_offset
= 0;
2282 if (pt
.x
< layer_insert_offset
&&
2283 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2285 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2286 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2287 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2291 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2292 return ProcessDockResult(target
, drop
);
2294 else if (pt
.y
< layer_insert_offset
&&
2295 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2297 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2298 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2299 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2303 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2304 return ProcessDockResult(target
, drop
);
2306 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2307 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2309 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2310 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2311 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2312 drop
.Dock().Right().
2315 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2316 return ProcessDockResult(target
, drop
);
2318 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2319 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2321 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2322 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2323 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2324 drop
.Dock().Bottom().
2327 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2328 return ProcessDockResult(target
, drop
);
2332 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2335 if (drop
.IsToolbar())
2337 if (!part
|| !part
->dock
)
2341 // calculate the offset from where the dock begins
2342 // to the point where the user dropped the pane
2343 int dock_drop_offset
= 0;
2344 if (part
->dock
->IsHorizontal())
2345 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2347 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2350 // toolbars may only be moved in and to fixed-pane docks,
2351 // otherwise we will try to float the pane. Also, the pane
2352 // should float if being dragged over center pane windows
2353 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2355 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2356 (drop
.IsFloatable() ||
2357 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2358 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2363 return ProcessDockResult(target
, drop
);
2367 Direction(part
->dock
->dock_direction
).
2368 Layer(part
->dock
->dock_layer
).
2369 Row(part
->dock
->dock_row
).
2370 Position(dock_drop_offset
);
2373 ((pt
.y
< part
->dock
->rect
.y
+ 2) && part
->dock
->IsHorizontal()) ||
2374 ((pt
.x
< part
->dock
->rect
.x
+ 2) && part
->dock
->IsVertical())
2375 ) && part
->dock
->panes
.GetCount() > 1)
2377 int row
= drop
.dock_row
;
2378 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2379 part
->dock
->dock_layer
,
2380 part
->dock
->dock_row
);
2381 drop
.dock_row
= row
;
2385 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2386 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2387 ) && part
->dock
->panes
.GetCount() > 1)
2389 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2390 part
->dock
->dock_layer
,
2391 part
->dock
->dock_row
+1);
2392 drop
.dock_row
= part
->dock
->dock_row
+1;
2395 return ProcessDockResult(target
, drop
);
2404 if (part
->type
== wxDockUIPart::typePaneBorder
||
2405 part
->type
== wxDockUIPart::typeCaption
||
2406 part
->type
== wxDockUIPart::typeGripper
||
2407 part
->type
== wxDockUIPart::typePaneButton
||
2408 part
->type
== wxDockUIPart::typePane
||
2409 part
->type
== wxDockUIPart::typePaneSizer
||
2410 part
->type
== wxDockUIPart::typeDockSizer
||
2411 part
->type
== wxDockUIPart::typeBackground
)
2413 if (part
->type
== wxDockUIPart::typeDockSizer
)
2415 if (part
->dock
->panes
.GetCount() != 1)
2417 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2424 // If a normal frame is being dragged over a toolbar, insert it
2425 // along the edge under the toolbar, but over all other panes.
2426 // (this could be done much better, but somehow factoring this
2427 // calculation with the one at the beginning of this function)
2428 if (part
->dock
&& part
->dock
->toolbar
)
2432 switch (part
->dock
->dock_direction
)
2434 case wxAUI_DOCK_LEFT
:
2435 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2436 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2437 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2439 case wxAUI_DOCK_TOP
:
2440 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2441 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2442 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2444 case wxAUI_DOCK_RIGHT
:
2445 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2446 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2447 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2449 case wxAUI_DOCK_BOTTOM
:
2450 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2451 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2452 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2456 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2459 Direction(part
->dock
->dock_direction
).
2460 Layer(layer
).Row(0).Position(0);
2461 return ProcessDockResult(target
, drop
);
2468 part
= GetPanePart(part
->pane
->window
);
2472 bool insert_dock_row
= false;
2473 int insert_row
= part
->pane
->dock_row
;
2474 int insert_dir
= part
->pane
->dock_direction
;
2475 int insert_layer
= part
->pane
->dock_layer
;
2477 switch (part
->pane
->dock_direction
)
2479 case wxAUI_DOCK_TOP
:
2480 if (pt
.y
>= part
->rect
.y
&&
2481 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2482 insert_dock_row
= true;
2484 case wxAUI_DOCK_BOTTOM
:
2485 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2486 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2487 insert_dock_row
= true;
2489 case wxAUI_DOCK_LEFT
:
2490 if (pt
.x
>= part
->rect
.x
&&
2491 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2492 insert_dock_row
= true;
2494 case wxAUI_DOCK_RIGHT
:
2495 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2496 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2497 insert_dock_row
= true;
2499 case wxAUI_DOCK_CENTER
:
2501 // "new row pixels" will be set to the default, but
2502 // must never exceed 20% of the window size
2503 int new_row_pixels_x
= auiNewRowPixels
;
2504 int new_row_pixels_y
= auiNewRowPixels
;
2506 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2507 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2509 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2510 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2513 // determine if the mouse pointer is in a location that
2514 // will cause a new row to be inserted. The hot spot positions
2515 // are along the borders of the center pane
2518 insert_dock_row
= true;
2519 if (pt
.x
>= part
->rect
.x
&&
2520 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2521 insert_dir
= wxAUI_DOCK_LEFT
;
2523 if (pt
.y
>= part
->rect
.y
&&
2524 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2525 insert_dir
= wxAUI_DOCK_TOP
;
2527 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2528 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2529 insert_dir
= wxAUI_DOCK_RIGHT
;
2531 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2532 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2533 insert_dir
= wxAUI_DOCK_BOTTOM
;
2537 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2541 if (insert_dock_row
)
2543 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2544 drop
.Dock().Direction(insert_dir
).
2545 Layer(insert_layer
).
2548 return ProcessDockResult(target
, drop
);
2551 // determine the mouse offset and the pane size, both in the
2552 // direction of the dock itself, and perpendicular to the dock
2556 if (part
->orientation
== wxVERTICAL
)
2558 offset
= pt
.y
- part
->rect
.y
;
2559 size
= part
->rect
.GetHeight();
2563 offset
= pt
.x
- part
->rect
.x
;
2564 size
= part
->rect
.GetWidth();
2567 int drop_position
= part
->pane
->dock_pos
;
2569 // if we are in the top/left part of the pane,
2570 // insert the pane before the pane being hovered over
2571 if (offset
<= size
/2)
2573 drop_position
= part
->pane
->dock_pos
;
2575 part
->pane
->dock_direction
,
2576 part
->pane
->dock_layer
,
2577 part
->pane
->dock_row
,
2578 part
->pane
->dock_pos
);
2581 // if we are in the bottom/right part of the pane,
2582 // insert the pane before the pane being hovered over
2583 if (offset
> size
/2)
2585 drop_position
= part
->pane
->dock_pos
+1;
2587 part
->pane
->dock_direction
,
2588 part
->pane
->dock_layer
,
2589 part
->pane
->dock_row
,
2590 part
->pane
->dock_pos
+1);
2594 Direction(part
->dock
->dock_direction
).
2595 Layer(part
->dock
->dock_layer
).
2596 Row(part
->dock
->dock_row
).
2597 Position(drop_position
);
2598 return ProcessDockResult(target
, drop
);
2605 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2607 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
2609 m_hint_fadetimer
.Stop();
2613 m_hint_fadeamt
+= 4;
2614 #if wxCHECK_VERSION(2,7,0)
2615 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2617 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2618 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2622 void wxFrameManager::ShowHint(const wxRect
& rect
)
2624 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0
2626 // Finally, don't use a venetian blind effect if it's been specifically disabled
2627 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2628 (m_flags
& wxAUI_MGR_DISABLE_VENETIAN_BLINDS
))
2631 if (m_last_hint
== rect
)
2635 m_hint_fadeamt
= m_hint_fademax
;
2636 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2637 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2638 (m_flags
& wxAUI_MGR_DISABLE_VENETIAN_BLINDS_FADE
))
2642 if (! m_hint_wnd
->IsShown())
2645 // if we are dragging a floating pane, set the focus
2646 // back to that floating pane (otherwise it becomes unfocused)
2647 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2648 m_action_window
->SetFocus();
2650 #if wxCHECK_VERSION(2,7,0)
2651 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2653 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2654 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2656 m_hint_wnd
->SetSize(rect
);
2657 m_hint_wnd
->Raise();
2660 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
2662 // start fade in timer
2663 m_hint_fadetimer
.SetOwner(this, 101);
2664 m_hint_fadetimer
.Start(5);
2668 else // Not using a transparent hint window...
2671 if (m_last_hint
!= rect
)
2673 // remove the last hint rectangle
2679 wxScreenDC screendc
;
2680 wxRegion
clip(1, 1, 10000, 10000);
2682 // clip all floating windows, so we don't draw over them
2684 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2686 wxPaneInfo
& pane
= m_panes
.Item(i
);
2688 if (pane
.IsFloating() &&
2689 pane
.frame
->IsShown())
2691 wxRect rect
= pane
.frame
->GetRect();
2693 // wxGTK returns the client size, not the whole frame size
2699 clip
.Subtract(rect
);
2703 // As we can only hide the hint by redrawing the managed window, we
2704 // need to clip the region to the managed window too or we get
2705 // nasty redrawn problems.
2706 clip
.Intersect(m_frame
->GetRect());
2708 screendc
.SetClippingRegion(clip
);
2710 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2711 wxBrush
brush(stipple
);
2712 screendc
.SetBrush(brush
);
2713 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2715 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2716 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2717 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2718 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2722 void wxFrameManager::HideHint()
2724 // hides a transparent window hint, if there is one
2727 m_hint_wnd
->Show(false);
2728 #if wxCHECK_VERSION(2,7,0)
2729 m_hint_wnd
->SetTransparent(0);
2731 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2732 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(0);
2734 m_hint_fadetimer
.Stop();
2735 m_last_hint
= wxRect();
2739 // hides a painted hint by redrawing the frame window
2740 if (!m_last_hint
.IsEmpty())
2744 m_last_hint
= wxRect();
2750 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2751 // determine the exact position the pane would be at were if dropped. If
2752 // the pame would indeed become docked at the specified drop point,
2753 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2754 // "pane_window" is the window pointer of the pane being dragged, pt is
2755 // the mouse position, in client coordinates
2756 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2758 const wxPoint
& offset
)
2762 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2763 // we will create a new temporary layout and then measure the resulting
2764 // rectangle; we will create a copy of the docking structures (m_dock)
2765 // so that we don't modify the real thing on screen
2767 int i
, pane_count
, part_count
;
2768 wxDockInfoArray docks
;
2769 wxPaneInfoArray panes
;
2770 wxDockUIPartArray uiparts
;
2771 wxPaneInfo hint
= GetPane(pane_window
);
2772 hint
.name
= wxT("__HINT__");
2778 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2780 // remove any pane already there which bears the same window;
2781 // this happens when you are moving a pane around in a dock
2782 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2784 if (panes
.Item(i
).window
== pane_window
)
2786 RemovePaneFromDocks(docks
, panes
.Item(i
));
2792 // find out where the new pane would be
2793 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2801 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2802 wxSize client_size
= m_frame
->GetClientSize();
2803 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2806 for (i
= 0, part_count
= uiparts
.GetCount();
2807 i
< part_count
; ++i
)
2809 wxDockUIPart
& part
= uiparts
.Item(i
);
2811 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2812 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2814 rect
= wxRect(part
.sizer_item
->GetPosition(),
2815 part
.sizer_item
->GetSize());
2828 // actually show the hint rectangle on the screen
2829 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2833 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2835 // try to find the pane
2836 wxPaneInfo
& pane
= GetPane(wnd
);
2837 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2839 #if wxCHECK_VERSION(2,7,0)
2840 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2841 pane
.frame
->SetTransparent(150);
2845 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
)
2847 // try to find the pane
2848 wxPaneInfo
& pane
= GetPane(wnd
);
2849 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2851 wxPoint pt
= ::wxGetMousePosition();
2852 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2854 // calculate the offset from the upper left-hand corner
2855 // of the frame to the mouse pointer
2856 wxPoint frame_pos
= pane
.frame
->GetPosition();
2857 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2859 // no hint for toolbar floating windows
2860 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
2862 if (m_action
== actionDragFloatingPane
)
2864 wxDockInfoArray docks
;
2865 wxPaneInfoArray panes
;
2866 wxDockUIPartArray uiparts
;
2867 wxPaneInfo hint
= pane
;
2869 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2871 // find out where the new pane would be
2872 if (!DoDrop(docks
, panes
, hint
, client_pt
))
2874 if (hint
.IsFloating())
2878 m_action
= actionDragToolbarPane
;
2879 m_action_window
= pane
.window
;
2888 // if a key modifier is pressed while dragging the frame,
2889 // don't dock the window
2890 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2897 DrawHintRect(wnd
, client_pt
, action_offset
);
2900 // this cleans up some screen artifacts that are caused on GTK because
2901 // we aren't getting the exact size of the window (see comment
2911 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
)
2913 // try to find the pane
2914 wxPaneInfo
& pane
= GetPane(wnd
);
2915 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2917 wxPoint pt
= ::wxGetMousePosition();
2918 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2920 // calculate the offset from the upper left-hand corner
2921 // of the frame to the mouse pointer
2922 wxPoint frame_pos
= pane
.frame
->GetPosition();
2923 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2926 // if a key modifier is pressed while dragging the frame,
2927 // don't dock the window
2928 if (!wxGetKeyState(WXK_CONTROL
) && !wxGetKeyState(WXK_ALT
))
2930 // do the drop calculation
2931 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
2934 // if the pane is still floating, update it's floating
2935 // position (that we store)
2936 if (pane
.IsFloating())
2938 pane
.floating_pos
= pane
.frame
->GetPosition();
2940 #if wxCHECK_VERSION(2,7,0)
2941 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2942 pane
.frame
->SetTransparent(255);
2951 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
2953 // try to find the pane
2954 wxPaneInfo
& pane
= GetPane(wnd
);
2955 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2957 pane
.floating_size
= size
;
2961 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
2963 // try to find the pane
2964 wxPaneInfo
& pane
= GetPane(wnd
);
2965 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2968 // fire pane close event
2969 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
2971 e
.SetCanVeto(evt
.CanVeto());
2981 // reparent the pane window back to us and
2982 // prepare the frame window for destruction
2983 pane
.window
->Show(false);
2984 pane
.window
->Reparent(m_frame
);
2992 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
2994 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
2996 // try to find the pane
2997 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
2999 SetActivePane(m_panes
, wnd
);
3004 // OnRender() draws all of the pane captions, sashes,
3005 // backgrounds, captions, grippers, pane borders and buttons.
3006 // It renders the entire user interface.
3008 void wxFrameManager::OnRender(wxFrameManagerEvent
& evt
)
3010 wxDC
* dc
= evt
.GetDC();
3016 for (i
= 0, part_count
= m_uiparts
.GetCount();
3017 i
< part_count
; ++i
)
3019 wxDockUIPart
& part
= m_uiparts
.Item(i
);
3021 // don't draw hidden pane items
3022 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
3027 case wxDockUIPart::typeDockSizer
:
3028 case wxDockUIPart::typePaneSizer
:
3029 m_art
->DrawSash(*dc
, part
.orientation
, part
.rect
);
3031 case wxDockUIPart::typeBackground
:
3032 m_art
->DrawBackground(*dc
, part
.orientation
, part
.rect
);
3034 case wxDockUIPart::typeCaption
:
3035 m_art
->DrawCaption(*dc
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3037 case wxDockUIPart::typeGripper
:
3038 m_art
->DrawGripper(*dc
, part
.rect
, *part
.pane
);
3040 case wxDockUIPart::typePaneBorder
:
3041 m_art
->DrawBorder(*dc
, part
.rect
, *part
.pane
);
3043 case wxDockUIPart::typePaneButton
:
3044 m_art
->DrawPaneButton(*dc
, part
.button
->button_id
,
3045 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3052 // Render() fire a render event, which is normally handled by
3053 // wxFrameManager::OnRender(). This allows the render function to
3054 // be overridden via the render event. This can be useful for paintin
3055 // custom graphics in the main window. Default behavior can be
3056 // invoked in the overridden function by calling OnRender()
3058 void wxFrameManager::Render(wxDC
* dc
)
3060 wxFrameManagerEvent
e(wxEVT_AUI_RENDER
);
3065 void wxFrameManager::Repaint(wxDC
* dc
)
3070 m_frame
->Refresh() ;
3076 m_frame
->GetClientSize(&w
, &h
);
3078 // figure out which dc to use; if one
3079 // has been specified, use it, otherwise
3081 wxClientDC
* client_dc
= NULL
;
3084 client_dc
= new wxClientDC(m_frame
);
3088 // if the frame has a toolbar, the client area
3089 // origin will not be (0,0).
3090 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3091 if (pt
.x
!= 0 || pt
.y
!= 0)
3092 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3094 // render all the items
3097 // if we created a client_dc, delete it
3102 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3104 wxPaintDC
dc(m_frame
);
3108 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
3117 void wxFrameManager::OnSize(wxSizeEvent
& WXUNUSED(event
))
3127 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
3130 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3131 wxCursor cursor
= wxNullCursor
;
3135 if (part
->type
== wxDockUIPart::typeDockSizer
||
3136 part
->type
== wxDockUIPart::typePaneSizer
)
3138 // a dock may not be resized if it has a single
3139 // pane which is not resizable
3140 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3141 part
->dock
->panes
.GetCount() == 1 &&
3142 part
->dock
->panes
.Item(0)->IsFixed())
3145 // panes that may not be resized do not get a sizing cursor
3146 if (part
->pane
&& part
->pane
->IsFixed())
3149 if (part
->orientation
== wxVERTICAL
)
3150 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3152 cursor
= wxCursor(wxCURSOR_SIZENS
);
3154 else if (part
->type
== wxDockUIPart::typeGripper
)
3156 cursor
= wxCursor(wxCURSOR_SIZING
);
3160 event
.SetCursor(cursor
);
3165 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
3166 const wxMouseEvent
& event
)
3168 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3170 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3172 if (hit_test
== button_ui_part
)
3174 if (event
.LeftDown())
3175 state
= wxAUI_BUTTON_STATE_PRESSED
;
3177 state
= wxAUI_BUTTON_STATE_HOVER
;
3181 if (event
.LeftDown())
3182 state
= wxAUI_BUTTON_STATE_HOVER
;
3185 // now repaint the button with hover state
3186 wxClientDC
cdc(m_frame
);
3188 // if the frame has a toolbar, the client area
3189 // origin will not be (0,0).
3190 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3191 if (pt
.x
!= 0 || pt
.y
!= 0)
3192 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3194 m_art
->DrawPaneButton(cdc
,
3195 button_ui_part
->button
->button_id
,
3197 button_ui_part
->rect
,
3201 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
3203 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3206 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3209 if (part
->type
== wxDockUIPart::typeDockSizer
||
3210 part
->type
== wxDockUIPart::typePaneSizer
)
3212 // a dock may not be resized if it has a single
3213 // pane which is not resizable
3214 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3215 part
->dock
->panes
.GetCount() == 1 &&
3216 part
->dock
->panes
.Item(0)->IsFixed())
3219 // panes that may not be resized should be ignored here
3220 if (part
->pane
&& part
->pane
->IsFixed())
3223 m_action
= actionResize
;
3224 m_action_part
= part
;
3225 m_action_hintrect
= wxRect();
3226 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3227 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3228 event
.m_y
- part
->rect
.y
);
3229 m_frame
->CaptureMouse();
3231 else if (part
->type
== wxDockUIPart::typePaneButton
)
3233 m_action
= actionClickButton
;
3234 m_action_part
= part
;
3235 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3236 m_frame
->CaptureMouse();
3238 UpdateButtonOnScreen(part
, event
);
3240 else if (part
->type
== wxDockUIPart::typeCaption
||
3241 part
->type
== wxDockUIPart::typeGripper
)
3243 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3245 // set the caption as active
3246 SetActivePane(m_panes
, part
->pane
->window
);
3250 m_action
= actionClickCaption
;
3251 m_action_part
= part
;
3252 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3253 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3254 event
.m_y
- part
->rect
.y
);
3255 m_frame
->CaptureMouse();
3275 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3277 if (m_action
== actionResize
)
3279 m_frame
->ReleaseMouse();
3281 // get rid of the hint rectangle
3283 DrawResizeHint(dc
, m_action_hintrect
);
3285 // resize the dock or the pane
3286 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3288 wxRect
& rect
= m_action_part
->dock
->rect
;
3290 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3291 event
.m_y
- m_action_offset
.y
);
3293 switch (m_action_part
->dock
->dock_direction
)
3295 case wxAUI_DOCK_LEFT
:
3296 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3298 case wxAUI_DOCK_TOP
:
3299 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3301 case wxAUI_DOCK_RIGHT
:
3302 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3303 new_pos
.x
- m_action_part
->rect
.GetWidth();
3305 case wxAUI_DOCK_BOTTOM
:
3306 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3307 new_pos
.y
- m_action_part
->rect
.GetHeight();
3314 else if (m_action_part
&&
3315 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3317 wxDockInfo
& dock
= *m_action_part
->dock
;
3318 wxPaneInfo
& pane
= *m_action_part
->pane
;
3320 int total_proportion
= 0;
3321 int dock_pixels
= 0;
3322 int new_pixsize
= 0;
3324 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3325 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3326 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3328 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3329 event
.m_y
- m_action_offset
.y
);
3331 // determine the pane rectangle by getting the pane part
3332 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3333 wxASSERT_MSG(pane_part
,
3334 wxT("Pane border part not found -- shouldn't happen"));
3336 // determine the new pixel size that the user wants;
3337 // this will help us recalculate the pane's proportion
3338 if (dock
.IsHorizontal())
3339 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3341 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3343 // determine the size of the dock, based on orientation
3344 if (dock
.IsHorizontal())
3345 dock_pixels
= dock
.rect
.GetWidth();
3347 dock_pixels
= dock
.rect
.GetHeight();
3349 // determine the total proportion of all resizable panes,
3350 // and the total size of the dock minus the size of all
3352 int i
, dock_pane_count
= dock
.panes
.GetCount();
3353 int pane_position
= -1;
3354 for (i
= 0; i
< dock_pane_count
; ++i
)
3356 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3357 if (p
.window
== pane
.window
)
3360 // while we're at it, subtract the pane sash
3361 // width from the dock width, because this would
3362 // skew our proportion calculations
3364 dock_pixels
-= sash_size
;
3366 // also, the whole size (including decorations) of
3367 // all fixed panes must also be subtracted, because they
3368 // are not part of the proportion calculation
3371 if (dock
.IsHorizontal())
3372 dock_pixels
-= p
.best_size
.x
;
3374 dock_pixels
-= p
.best_size
.y
;
3378 total_proportion
+= p
.dock_proportion
;
3382 // find a pane in our dock to 'steal' space from or to 'give'
3383 // space to -- this is essentially what is done when a pane is
3384 // resized; the pane should usually be the first non-fixed pane
3385 // to the right of the action pane
3386 int borrow_pane
= -1;
3387 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3389 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3398 // demand that the pane being resized is found in this dock
3399 // (this assert really never should be raised)
3400 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3402 // prevent division by zero
3403 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3405 m_action
= actionNone
;
3409 // calculate the new proportion of the pane
3410 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3412 // default minimum size
3415 // check against the pane's minimum size, if specified. please note
3416 // that this is not enough to ensure that the minimum size will
3417 // not be violated, because the whole frame might later be shrunk,
3418 // causing the size of the pane to violate it's minimum size
3419 if (pane
.min_size
.IsFullySpecified())
3423 if (pane
.HasBorder())
3424 min_size
+= (pane_border_size
*2);
3426 // calculate minimum size with decorations (border,caption)
3427 if (pane_part
->orientation
== wxVERTICAL
)
3429 min_size
+= pane
.min_size
.y
;
3430 if (pane
.HasCaption())
3431 min_size
+= caption_size
;
3435 min_size
+= pane
.min_size
.x
;
3440 // for some reason, an arithmatic error somewhere is causing
3441 // the proportion calculations to always be off by 1 pixel;
3442 // for now we will add the 1 pixel on, but we really should
3443 // determine what's causing this.
3446 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3448 if (new_proportion
< min_proportion
)
3449 new_proportion
= min_proportion
;
3453 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3455 // borrow the space from our neighbor pane to the
3456 // right or bottom (depending on orientation)
3457 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3458 pane
.dock_proportion
= new_proportion
;
3465 else if (m_action
== actionClickButton
)
3467 m_hover_button
= NULL
;
3468 m_frame
->ReleaseMouse();
3469 UpdateButtonOnScreen(m_action_part
, event
);
3471 // make sure we're still over the item that was originally clicked
3472 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3474 // fire button-click event
3475 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3476 e
.SetPane(m_action_part
->pane
);
3477 e
.SetButton(m_action_part
->button
->button_id
);
3481 else if (m_action
== actionClickCaption
)
3483 m_frame
->ReleaseMouse();
3485 else if (m_action
== actionDragFloatingPane
)
3487 m_frame
->ReleaseMouse();
3489 else if (m_action
== actionDragToolbarPane
)
3491 m_frame
->ReleaseMouse();
3493 wxPaneInfo
& pane
= GetPane(m_action_window
);
3494 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3496 // save the new positions
3497 wxDockInfoPtrArray docks
;
3498 FindDocks(m_docks
, pane
.dock_direction
,
3499 pane
.dock_layer
, pane
.dock_row
, docks
);
3500 if (docks
.GetCount() == 1)
3502 wxDockInfo
& dock
= *docks
.Item(0);
3504 wxArrayInt pane_positions
, pane_sizes
;
3505 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3507 int i
, dock_pane_count
= dock
.panes
.GetCount();
3508 for (i
= 0; i
< dock_pane_count
; ++i
)
3509 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3512 pane
.state
&= ~wxPaneInfo::actionPane
;
3520 m_action
= actionNone
;
3521 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3525 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3527 // sometimes when Update() is called from inside this method,
3528 // a spurious mouse move event is generated; this check will make
3529 // sure that only real mouse moves will get anywhere in this method;
3530 // this appears to be a bug somewhere, and I don't know where the
3531 // mouse move event is being generated. only verified on MSW
3533 wxPoint mouse_pos
= event
.GetPosition();
3534 if (m_last_mouse_move
== mouse_pos
)
3536 m_last_mouse_move
= mouse_pos
;
3539 if (m_action
== actionResize
)
3541 wxPoint pos
= m_action_part
->rect
.GetPosition();
3542 if (m_action_part
->orientation
== wxHORIZONTAL
)
3543 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3545 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3547 wxRect
rect(m_frame
->ClientToScreen(pos
),
3548 m_action_part
->rect
.GetSize());
3551 if (!m_action_hintrect
.IsEmpty())
3552 DrawResizeHint(dc
, m_action_hintrect
);
3553 DrawResizeHint(dc
, rect
);
3554 m_action_hintrect
= rect
;
3556 else if (m_action
== actionClickCaption
)
3558 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3559 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3561 // caption has been clicked. we need to check if the mouse
3562 // is now being dragged. if it is, we need to change the
3563 // mouse action to 'drag'
3564 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3565 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3567 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3569 if (!pane_info
->IsToolbar())
3571 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3572 pane_info
->IsFloatable())
3574 m_action
= actionDragFloatingPane
;
3576 // set initial float position
3577 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3578 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3579 pt
.y
- m_action_offset
.y
);
3584 m_action_window
= pane_info
->frame
;
3586 // action offset is used here to make it feel "natural" to the user
3587 // to drag a docked pane and suddenly have it become a floating frame.
3588 // Sometimes, however, the offset where the user clicked on the docked
3589 // caption is bigger than the width of the floating frame itself, so
3590 // in that case we need to set the action offset to a sensible value
3591 wxSize frame_size
= m_action_window
->GetSize();
3592 if (frame_size
.x
<= m_action_offset
.x
)
3593 m_action_offset
.x
= 30;
3598 m_action
= actionDragToolbarPane
;
3599 m_action_window
= pane_info
->window
;
3603 else if (m_action
== actionDragFloatingPane
)
3605 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3606 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3607 pt
.y
- m_action_offset
.y
);
3609 else if (m_action
== actionDragToolbarPane
)
3611 wxPaneInfo
& pane
= GetPane(m_action_window
);
3612 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3614 pane
.state
|= wxPaneInfo::actionPane
;
3616 wxPoint pt
= event
.GetPosition();
3617 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3619 // if DoDrop() decided to float the pane, set up
3620 // the floating pane's initial position
3621 if (pane
.IsFloating())
3623 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3624 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3625 pt
.y
- m_action_offset
.y
);
3628 // this will do the actiual move operation;
3629 // in the case that the pane has been floated,
3630 // this call will create the floating pane
3631 // and do the reparenting
3634 // if the pane has been floated, change the mouse
3635 // action actionDragFloatingPane so that subsequent
3636 // EVT_MOTION() events will move the floating pane
3637 if (pane
.IsFloating())
3639 pane
.state
&= ~wxPaneInfo::actionPane
;
3640 m_action
= actionDragFloatingPane
;
3641 m_action_window
= pane
.frame
;
3646 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3647 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3649 if (part
!= m_hover_button
)
3651 // make the old button normal
3653 UpdateButtonOnScreen(m_hover_button
, event
);
3655 // mouse is over a button, so repaint the
3656 // button in hover mode
3657 UpdateButtonOnScreen(part
, event
);
3658 m_hover_button
= part
;
3665 m_hover_button
= NULL
;
3676 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3680 m_hover_button
= NULL
;
3685 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3687 // when a child pane has it's focus set, we should change the
3688 // pane's active state to reflect this. (this is only true if
3689 // active panes are allowed by the owner)
3690 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3692 if (GetPane(event
.GetWindow()).IsOk())
3694 SetActivePane(m_panes
, event
.GetWindow());
3703 // OnPaneButton() is an event handler that is called
3704 // when a pane button has been pressed.
3705 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& evt
)
3707 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3709 wxPaneInfo
& pane
= *(evt
.pane
);
3711 if (evt
.button
== wxPaneInfo::buttonClose
)
3713 // fire pane close event
3714 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3715 e
.SetPane(evt
.pane
);
3724 else if (evt
.button
== wxPaneInfo::buttonPin
)
3726 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&