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
);
86 m_CanSetShape
= false; // have to wait for window create event on GTK
90 m_Region
= wxRegion(0, 0, 0, 0);
94 virtual bool SetTransparent(wxByte alpha
)
98 int w
=100; // some defaults
100 GetClientSize(&w
, &h
);
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);
123 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
127 if (m_Region
.IsEmpty())
131 dc
.SetBrush(wxColour(128, 192, 255));
133 dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
135 dc
.SetPen(*wxTRANSPARENT_PEN
);
137 wxRegionIterator
upd(GetUpdateRegion()); // get the update rect list
141 wxRect
rect(upd
.GetRect());
142 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
149 void OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
)) {m_CanSetShape
=true; SetTransparent(0);}
152 void OnSize(wxSizeEvent
& event
)
154 // We sometimes get surplus size events
155 if ((event
.GetSize().GetWidth() == m_lastWidth
) &&
156 (event
.GetSize().GetHeight() == m_lastHeight
))
161 m_lastWidth
= event
.GetSize().GetWidth();
162 m_lastHeight
= event
.GetSize().GetHeight();
164 SetTransparent(m_Amount
);
165 m_Region
.Intersect(0, 0, event
.GetSize().GetWidth(),
166 event
.GetSize().GetHeight());
177 int m_lastWidth
,m_lastHeight
;
181 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
182 DECLARE_EVENT_TABLE()
186 IMPLEMENT_DYNAMIC_CLASS( wxPseudoTransparentFrame
, wxFrame
)
188 BEGIN_EVENT_TABLE(wxPseudoTransparentFrame
, wxFrame
)
189 EVT_PAINT(wxPseudoTransparentFrame::OnPaint
)
190 EVT_SIZE(wxPseudoTransparentFrame::OnSize
)
192 EVT_WINDOW_CREATE(wxPseudoTransparentFrame::OnWindowCreate
)
197 // -- static utility functions --
199 static wxBitmap
wxPaneCreateStippleBitmap()
201 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
202 wxImage
img(2,2,data
,true);
203 return wxBitmap(img
);
206 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
208 wxBitmap stipple
= wxPaneCreateStippleBitmap();
209 wxBrush
brush(stipple
);
211 dc
.SetPen(*wxTRANSPARENT_PEN
);
213 dc
.SetLogicalFunction(wxXOR
);
214 dc
.DrawRectangle(rect
);
219 // CopyDocksAndPanes() - this utility function creates copies of
220 // the dock and pane info. wxDockInfo's usually contain pointers
221 // to wxPaneInfo classes, thus this function is necessary to reliably
222 // reconstruct that relationship in the new dock info and pane info arrays
224 static void CopyDocksAndPanes(wxDockInfoArray
& dest_docks
,
225 wxPaneInfoArray
& dest_panes
,
226 const wxDockInfoArray
& src_docks
,
227 const wxPaneInfoArray
& src_panes
)
229 dest_docks
= src_docks
;
230 dest_panes
= src_panes
;
231 int i
, j
, k
, dock_count
, pc1
, pc2
;
232 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
234 wxDockInfo
& dock
= dest_docks
.Item(i
);
235 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
236 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
237 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
238 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
242 // GetMaxLayer() is an internal function which returns
243 // the highest layer inside the specified dock
244 static int GetMaxLayer(const wxDockInfoArray
& docks
, int dock_direction
)
246 int i
, dock_count
, max_layer
= 0;
247 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
249 wxDockInfo
& dock
= docks
.Item(i
);
250 if (dock
.dock_direction
== dock_direction
&&
251 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
252 max_layer
= dock
.dock_layer
;
258 // GetMaxRow() is an internal function which returns
259 // the highest layer inside the specified dock
260 static int GetMaxRow(const wxPaneInfoArray
& panes
, int direction
, int layer
)
262 int i
, pane_count
, max_row
= 0;
263 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
265 wxPaneInfo
& pane
= panes
.Item(i
);
266 if (pane
.dock_direction
== direction
&&
267 pane
.dock_layer
== layer
&&
268 pane
.dock_row
> max_row
)
269 max_row
= pane
.dock_row
;
276 // DoInsertDockLayer() is an internal function that inserts a new dock
277 // layer by incrementing all existing dock layer values by one
278 static void DoInsertDockLayer(wxPaneInfoArray
& panes
,
283 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
285 wxPaneInfo
& pane
= panes
.Item(i
);
286 if (!pane
.IsFloating() &&
287 pane
.dock_direction
== dock_direction
&&
288 pane
.dock_layer
>= dock_layer
)
293 // DoInsertDockLayer() is an internal function that inserts a new dock
294 // row by incrementing all existing dock row values by one
295 static void DoInsertDockRow(wxPaneInfoArray
& panes
,
301 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
303 wxPaneInfo
& pane
= panes
.Item(i
);
304 if (!pane
.IsFloating() &&
305 pane
.dock_direction
== dock_direction
&&
306 pane
.dock_layer
== dock_layer
&&
307 pane
.dock_row
>= dock_row
)
312 // DoInsertDockLayer() is an internal function that inserts a space for
313 // another dock pane by incrementing all existing dock row values by one
314 static void DoInsertPane(wxPaneInfoArray
& panes
,
321 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
323 wxPaneInfo
& pane
= panes
.Item(i
);
324 if (!pane
.IsFloating() &&
325 pane
.dock_direction
== dock_direction
&&
326 pane
.dock_layer
== dock_layer
&&
327 pane
.dock_row
== dock_row
&&
328 pane
.dock_pos
>= dock_pos
)
333 // FindDocks() is an internal function that returns a list of docks which meet
334 // the specified conditions in the parameters and returns a sorted array
335 // (sorted by layer and then row)
336 static void FindDocks(wxDockInfoArray
& docks
,
340 wxDockInfoPtrArray
& arr
)
342 int begin_layer
= dock_layer
;
343 int end_layer
= dock_layer
;
344 int begin_row
= dock_row
;
345 int end_row
= dock_row
;
346 int dock_count
= docks
.GetCount();
347 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
349 // discover the maximum dock layer and the max row
350 for (i
= 0; i
< dock_count
; ++i
)
352 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
353 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
356 // if no dock layer was specified, search all dock layers
357 if (dock_layer
== -1)
360 end_layer
= max_layer
;
363 // if no dock row was specified, search all dock row
372 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
373 for (row
= begin_row
; row
<= end_row
; ++row
)
374 for (i
= 0; i
< dock_count
; ++i
)
376 wxDockInfo
& d
= docks
.Item(i
);
377 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
379 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
385 // FindPaneInDock() looks up a specified window pointer inside a dock.
386 // If found, the corresponding wxPaneInfo pointer is returned, otherwise NULL.
387 static wxPaneInfo
* FindPaneInDock(const wxDockInfo
& dock
, wxWindow
* window
)
389 int i
, count
= dock
.panes
.GetCount();
390 for (i
= 0; i
< count
; ++i
)
392 wxPaneInfo
* p
= dock
.panes
.Item(i
);
393 if (p
->window
== window
)
399 // RemovePaneFromDocks() removes a pane window from all docks
400 // with a possible exception specified by parameter "ex_cept"
401 static void RemovePaneFromDocks(wxDockInfoArray
& docks
,
403 wxDockInfo
* ex_cept
= NULL
)
406 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
408 wxDockInfo
& d
= docks
.Item(i
);
411 wxPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
417 // RenumberDockRows() takes a dock and assigns sequential numbers
418 // to existing rows. Basically it takes out the gaps; so if a
419 // dock has rows with numbers 0,2,5, they will become 0,1,2
420 static void RenumberDockRows(wxDockInfoPtrArray
& docks
)
422 int i
, dock_count
, j
, pane_count
;
423 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
425 wxDockInfo
& dock
= *docks
.Item(i
);
427 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
428 dock
.panes
.Item(j
)->dock_row
= i
;
433 // SetActivePane() sets the active pane, as well as cycles through
434 // every other pane and makes sure that all others' active flags
436 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
439 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
441 wxPaneInfo
& pane
= panes
.Item(i
);
442 pane
.state
&= ~wxPaneInfo::optionActive
;
443 if (pane
.window
== active_pane
)
444 pane
.state
|= wxPaneInfo::optionActive
;
449 // this function is used to sort panes by dock position
450 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
452 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
456 // -- wxFrameManager class implementation --
459 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
460 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
461 EVT_AUI_RENDER(wxFrameManager::OnRender
)
462 EVT_PAINT(wxFrameManager::OnPaint
)
463 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
464 EVT_SIZE(wxFrameManager::OnSize
)
465 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
466 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
467 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
468 EVT_MOTION(wxFrameManager::OnMotion
)
469 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
470 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
471 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
475 wxFrameManager::wxFrameManager(wxWindow
* managed_wnd
, unsigned int flags
)
477 m_action
= actionNone
;
478 m_last_mouse_move
= wxPoint();
479 m_hover_button
= NULL
;
480 m_art
= new wxDefaultDockArt
;
486 SetManagedWindow(managed_wnd
);
490 wxFrameManager::~wxFrameManager()
495 // GetPane() looks up a wxPaneInfo structure based
496 // on the supplied window pointer. Upon failure, GetPane()
497 // returns an empty wxPaneInfo, a condition which can be checked
498 // by calling wxPaneInfo::IsOk().
500 // The pane info's structure may then be modified. Once a pane's
501 // info is modified, wxFrameManager::Update() must be called to
502 // realize the changes in the UI.
504 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
507 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
509 wxPaneInfo
& p
= m_panes
.Item(i
);
510 if (p
.window
== window
)
513 return wxNullPaneInfo
;
516 // this version of GetPane() looks up a pane based on a
517 // 'pane name', see above comment for more info
518 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
521 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
523 wxPaneInfo
& p
= m_panes
.Item(i
);
527 return wxNullPaneInfo
;
530 // GetAllPanes() returns a reference to all the pane info structures
531 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
536 // HitTest() is an internal function which determines
537 // which UI item the specified coordinates are over
538 // (x,y) specify a position in client coordinates
539 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
541 wxDockUIPart
* result
= NULL
;
544 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
546 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
548 // we are not interested in typeDock, because this space
549 // isn't used to draw anything, just for measurements;
550 // besides, the entire dock area is covered with other
551 // rectangles, which we are interested in.
552 if (item
->type
== wxDockUIPart::typeDock
)
555 // if we already have a hit on a more specific item, we are not
556 // interested in a pane hit. If, however, we don't already have
557 // a hit, returning a pane hit is necessary for some operations
558 if ((item
->type
== wxDockUIPart::typePane
||
559 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
562 // if the point is inside the rectangle, we have a hit
563 if (item
->rect
.Inside(x
,y
))
571 // SetFlags() and GetFlags() allow the owner to set various
572 // options which are global to wxFrameManager
573 void wxFrameManager::SetFlags(unsigned int flags
)
578 unsigned int wxFrameManager::GetFlags() const
584 // don't use these anymore as they are deprecated
585 // use Set/GetManagedFrame() instead
586 void wxFrameManager::SetFrame(wxFrame
* frame
)
588 SetManagedWindow((wxWindow
*)frame
);
591 wxFrame
* wxFrameManager::GetFrame() const
593 return (wxFrame
*)m_frame
;
599 // SetManagedWindow() is usually called once when the frame
600 // manager class is being initialized. "frame" specifies
601 // the frame which should be managed by the frame mananger
602 void wxFrameManager::SetManagedWindow(wxWindow
* frame
)
604 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
607 m_frame
->PushEventHandler(this);
610 // if the owner is going to manage an MDI parent frame,
611 // we need to add the MDI client window as the default
614 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
616 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
617 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
619 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
621 AddPane(client_window
,
622 wxPaneInfo().Name(wxT("mdiclient")).
623 CenterPane().PaneBorder(false));
627 // Make a window to use for a transparent hint
628 #if defined(__WXMSW__) || defined(__WXGTK__)
629 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
630 wxFRAME_TOOL_WINDOW
|
631 wxFRAME_FLOAT_ON_PARENT
|
635 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
637 #elif defined(__WXMAC__)
638 // Using a miniframe with float and tool styles keeps the parent
639 // frame activated and highlighted as such...
640 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
641 wxFRAME_FLOAT_ON_PARENT
642 | wxFRAME_TOOL_WINDOW
);
644 // Can't set the bg colour of a Frame in wxMac
645 wxPanel
* p
= new wxPanel(m_hint_wnd
);
647 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
648 // color that is really hard to see, especially transparent.
649 // Until a better system color is decided upon we'll just use
651 p
->SetBackgroundColour(*wxBLUE
);
657 // CanSetTransparent is only present in the 2.7.0 ABI. To allow this file to be easily used
658 // in a backported environment, conditionally compile this in.
659 #if wxCHECK_VERSION(2,7,0)
660 && !m_hint_wnd
->CanSetTransparent()
666 m_hint_wnd
->Destroy();
669 // If we can convert it to a PseudoTransparent window, do so
670 m_hint_wnd
= new wxPseudoTransparentFrame (m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
671 wxFRAME_TOOL_WINDOW
|
672 wxFRAME_FLOAT_ON_PARENT
|
676 m_hint_fademax
= 128;
681 // UnInit() must be called, usually in the destructor
682 // of the frame class. If it is not called, usually this
683 // will result in a crash upon program exit
684 void wxFrameManager::UnInit()
686 m_frame
->RemoveEventHandler(this);
689 // GetManagedWindow() returns the window pointer being managed
690 wxWindow
* wxFrameManager::GetManagedWindow() const
695 wxDockArt
* wxFrameManager::GetArtProvider() const
700 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
702 // first, give the owner frame a chance to override
705 if (m_frame
->ProcessEvent(event
))
712 // SetArtProvider() instructs wxFrameManager to use the
713 // specified art provider for all drawing calls. This allows
714 // plugable look-and-feel features. The pointer that is
715 // passed to this method subsequently belongs to wxFrameManager,
716 // and is deleted in the frame manager destructor
717 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
719 // delete the last art provider, if any
722 // assign the new art provider
723 m_art
= art_provider
;
727 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
729 // check if the pane has a valid window
733 // check if the pane already exists
734 if (GetPane(pane_info
.window
).IsOk())
737 m_panes
.Add(pane_info
);
739 wxPaneInfo
& pinfo
= m_panes
.Last();
741 // set the pane window
742 pinfo
.window
= window
;
744 // if the pane's name identifier is blank, create a random string
745 if (pinfo
.name
.empty())
747 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
748 ((unsigned long)pinfo
.window
) & 0xffffffff,
749 (unsigned int)time(NULL
),
751 (unsigned int)GetTickCount(),
753 (unsigned int)clock(),
755 (unsigned long)m_panes
.GetCount());
758 // set initial proportion (if not already set)
759 if (pinfo
.dock_proportion
== 0)
760 pinfo
.dock_proportion
= 100000;
762 if (pinfo
.HasCloseButton() &&
763 pinfo
.buttons
.size() == 0)
766 button
.button_id
= wxPaneInfo::buttonClose
;
767 pinfo
.buttons
.Add(button
);
770 if (pinfo
.best_size
== wxDefaultSize
&&
773 pinfo
.best_size
= pinfo
.window
->GetClientSize();
775 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
777 // GetClientSize() doesn't get the best size for
778 // a toolbar under some newer versions of wxWidgets,
779 // so use GetBestSize()
780 pinfo
.best_size
= pinfo
.window
->GetBestSize();
782 // for some reason, wxToolBar::GetBestSize() is returning
783 // a size that is a pixel shy of the correct amount.
784 // I believe this to be the correct action, until
785 // wxToolBar::GetBestSize() is fixed. Is this assumption
790 if (pinfo
.min_size
!= wxDefaultSize
)
792 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
793 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
794 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
795 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
802 bool wxFrameManager::AddPane(wxWindow
* window
,
804 const wxString
& caption
)
807 pinfo
.Caption(caption
);
810 case wxTOP
: pinfo
.Top(); break;
811 case wxBOTTOM
: pinfo
.Bottom(); break;
812 case wxLEFT
: pinfo
.Left(); break;
813 case wxRIGHT
: pinfo
.Right(); break;
814 case wxCENTER
: pinfo
.CenterPane(); break;
816 return AddPane(window
, pinfo
);
819 bool wxFrameManager::AddPane(wxWindow
* window
,
820 const wxPaneInfo
& pane_info
,
821 const wxPoint
& drop_pos
)
823 if (!AddPane(window
, pane_info
))
826 wxPaneInfo
& pane
= GetPane(window
);
828 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
833 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
836 // shift the panes around, depending on the insert level
837 switch (insert_level
)
839 case wxAUI_INSERT_PANE
:
840 DoInsertPane(m_panes
,
841 pane_info
.dock_direction
,
842 pane_info
.dock_layer
,
846 case wxAUI_INSERT_ROW
:
847 DoInsertDockRow(m_panes
,
848 pane_info
.dock_direction
,
849 pane_info
.dock_layer
,
852 case wxAUI_INSERT_DOCK
:
853 DoInsertDockLayer(m_panes
,
854 pane_info
.dock_direction
,
855 pane_info
.dock_layer
);
859 // if the window already exists, we are basically just moving/inserting the
860 // existing window. If it doesn't exist, we need to add it and insert it
861 wxPaneInfo
& existing_pane
= GetPane(window
);
862 if (!existing_pane
.IsOk())
864 return AddPane(window
, pane_info
);
868 if (pane_info
.IsFloating())
870 existing_pane
.Float();
871 if (pane_info
.floating_pos
!= wxDefaultPosition
)
872 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
873 if (pane_info
.floating_size
!= wxDefaultSize
)
874 existing_pane
.FloatingSize(pane_info
.floating_size
);
878 existing_pane
.Direction(pane_info
.dock_direction
);
879 existing_pane
.Layer(pane_info
.dock_layer
);
880 existing_pane
.Row(pane_info
.dock_row
);
881 existing_pane
.Position(pane_info
.dock_pos
);
889 // DetachPane() removes a pane from the frame manager. This
890 // method will not destroy the window that is removed.
891 bool wxFrameManager::DetachPane(wxWindow
* window
)
894 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
896 wxPaneInfo
& p
= m_panes
.Item(i
);
897 if (p
.window
== window
)
901 // we have a floating frame which is being detached. We need to
902 // reparent it to m_frame and destroy the floating frame
905 p
.window
->SetSize(1,1);
907 if (p
.frame
->IsShown())
908 p
.frame
->Show(false);
910 // reparent to m_frame and destroy the pane
911 p
.window
->Reparent(m_frame
);
912 p
.frame
->SetSizer(NULL
);
917 // make sure there are no references to this pane in our uiparts,
918 // just in case the caller doesn't call Update() immediately after
919 // the DetachPane() call. This prevets obscure crashes which would
920 // happen at window repaint if the caller forgets to call Update()
922 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
924 wxDockUIPart
& part
= m_uiparts
.Item(pi
);
927 m_uiparts
.RemoveAt(pi
);
942 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
943 // in the input string. This is an internal functions which is
944 // used for saving perspectives
945 static wxString
EscapeDelimiters(const wxString
& s
)
948 result
.Alloc(s
.length());
949 const wxChar
* ch
= s
.c_str();
952 if (*ch
== wxT(';') || *ch
== wxT('|'))
960 wxString
wxFrameManager::SavePaneInfo(wxPaneInfo
& pane
)
962 wxString result
= wxT("name=");
963 result
+= EscapeDelimiters(pane
.name
);
966 result
+= wxT("caption=");
967 result
+= EscapeDelimiters(pane
.caption
);
970 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
971 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
972 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
973 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
974 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
975 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
976 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
977 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
978 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
979 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
980 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
981 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
982 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
983 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
984 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
985 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
990 // Load a "pane" with the pane infor settings in pane_part
991 void wxFrameManager::LoadPaneInfo(wxString pane_part
, wxPaneInfo
&pane
)
993 // replace escaped characters so we can
994 // split up the string easily
995 pane_part
.Replace(wxT("\\|"), wxT("\a"));
996 pane_part
.Replace(wxT("\\;"), wxT("\b"));
1000 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
1001 pane_part
= pane_part
.AfterFirst(wxT(';'));
1002 wxString val_name
= val_part
.BeforeFirst(wxT('='));
1003 wxString value
= val_part
.AfterFirst(wxT('='));
1004 val_name
.MakeLower();
1005 val_name
.Trim(true);
1006 val_name
.Trim(false);
1010 if (val_name
.empty())
1013 if (val_name
== wxT("name"))
1015 else if (val_name
== wxT("caption"))
1016 pane
.caption
= value
;
1017 else if (val_name
== wxT("state"))
1018 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1019 else if (val_name
== wxT("dir"))
1020 pane
.dock_direction
= wxAtoi(value
.c_str());
1021 else if (val_name
== wxT("layer"))
1022 pane
.dock_layer
= wxAtoi(value
.c_str());
1023 else if (val_name
== wxT("row"))
1024 pane
.dock_row
= wxAtoi(value
.c_str());
1025 else if (val_name
== wxT("pos"))
1026 pane
.dock_pos
= wxAtoi(value
.c_str());
1027 else if (val_name
== wxT("prop"))
1028 pane
.dock_proportion
= wxAtoi(value
.c_str());
1029 else if (val_name
== wxT("bestw"))
1030 pane
.best_size
.x
= wxAtoi(value
.c_str());
1031 else if (val_name
== wxT("besth"))
1032 pane
.best_size
.y
= wxAtoi(value
.c_str());
1033 else if (val_name
== wxT("minw"))
1034 pane
.min_size
.x
= wxAtoi(value
.c_str());
1035 else if (val_name
== wxT("minh"))
1036 pane
.min_size
.y
= wxAtoi(value
.c_str());
1037 else if (val_name
== wxT("maxw"))
1038 pane
.max_size
.x
= wxAtoi(value
.c_str());
1039 else if (val_name
== wxT("maxh"))
1040 pane
.max_size
.y
= wxAtoi(value
.c_str());
1041 else if (val_name
== wxT("floatx"))
1042 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1043 else if (val_name
== wxT("floaty"))
1044 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1045 else if (val_name
== wxT("floatw"))
1046 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1047 else if (val_name
== wxT("floath"))
1048 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1050 wxFAIL_MSG(wxT("Bad Perspective String"));
1054 // replace escaped characters so we can
1055 // split up the string easily
1056 pane
.name
.Replace(wxT("\a"), wxT("|"));
1057 pane
.name
.Replace(wxT("\b"), wxT(";"));
1058 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1059 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1060 pane_part
.Replace(wxT("\a"), wxT("|"));
1061 pane_part
.Replace(wxT("\b"), wxT(";"));
1067 // SavePerspective() saves all pane information as a single string.
1068 // This string may later be fed into LoadPerspective() to restore
1069 // all pane settings. This save and load mechanism allows an
1070 // exact pane configuration to be saved and restored at a later time
1072 wxString
wxFrameManager::SavePerspective()
1076 result
= wxT("layout1|");
1078 int pane_i
, pane_count
= m_panes
.GetCount();
1079 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1081 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
1082 result
+= SavePaneInfo(pane
)+wxT("|");
1085 int dock_i
, dock_count
= m_docks
.GetCount();
1086 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1088 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
1090 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1091 dock
.dock_direction
, dock
.dock_layer
,
1092 dock
.dock_row
, dock
.size
);
1098 // LoadPerspective() loads a layout which was saved with SavePerspective()
1099 // If the "update" flag parameter is true, the GUI will immediately be updated
1101 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
1103 wxString input
= layout
;
1106 // check layout string version
1107 part
= input
.BeforeFirst(wxT('|'));
1108 input
= input
.AfterFirst(wxT('|'));
1111 if (part
!= wxT("layout1"))
1114 // mark all panes currently managed as docked and hidden
1115 int pane_i
, pane_count
= m_panes
.GetCount();
1116 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1117 m_panes
.Item(pane_i
).Dock().Hide();
1119 // clear out the dock array; this will be reconstructed
1122 // replace escaped characters so we can
1123 // split up the string easily
1124 input
.Replace(wxT("\\|"), wxT("\a"));
1125 input
.Replace(wxT("\\;"), wxT("\b"));
1131 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1132 input
= input
.AfterFirst(wxT('|'));
1133 pane_part
.Trim(true);
1135 // if the string is empty, we're done parsing
1136 if (pane_part
.empty())
1139 if (pane_part
.Left(9) == wxT("dock_size"))
1141 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1142 wxString value
= pane_part
.AfterFirst(wxT('='));
1144 long dir
, layer
, row
, size
;
1145 wxString piece
= val_name
.AfterFirst(wxT('('));
1146 piece
= piece
.BeforeLast(wxT(')'));
1147 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1148 piece
= piece
.AfterFirst(wxT(','));
1149 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1150 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1151 value
.ToLong(&size
);
1154 dock
.dock_direction
= dir
;
1155 dock
.dock_layer
= layer
;
1156 dock
.dock_row
= row
;
1162 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1163 // name so it can be called by external callers
1164 pane_part
.Replace(wxT("\a"), wxT("|"));
1165 pane_part
.Replace(wxT("\b"), wxT(";"));
1167 LoadPaneInfo(pane_part
, pane
);
1169 wxPaneInfo
& p
= GetPane(pane
.name
);
1172 // the pane window couldn't be found
1173 // in the existing layout
1187 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
1188 wxArrayInt
& positions
,
1191 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1192 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1193 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1198 int offset
, action_pane
= -1;
1199 int pane_i
, pane_count
= dock
.panes
.GetCount();
1201 // find the pane marked as our action pane
1202 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1204 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1206 if (pane
.state
& wxPaneInfo::actionPane
)
1208 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1209 action_pane
= pane_i
;
1213 // set up each panes default position, and
1214 // determine the size (width or height, depending
1215 // on the dock's orientation) of each pane
1216 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1218 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1219 positions
.Add(pane
.dock_pos
);
1222 if (pane
.HasBorder())
1223 size
+= (pane_border_size
*2);
1225 if (dock
.IsHorizontal())
1227 if (pane
.HasGripper() && !pane
.HasGripperTop())
1228 size
+= gripper_size
;
1229 size
+= pane
.best_size
.x
;
1233 if (pane
.HasGripper() && pane
.HasGripperTop())
1234 size
+= gripper_size
;
1236 if (pane
.HasCaption())
1237 size
+= caption_size
;
1238 size
+= pane
.best_size
.y
;
1244 // if there is no action pane, just return the default
1245 // positions (as specified in pane.pane_pos)
1246 if (action_pane
== -1)
1250 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1252 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1257 positions
[pane_i
] -= -amount
;
1259 offset
+= sizes
[pane_i
];
1262 // if the dock mode is fixed, make sure none of the panes
1263 // overlap; we will bump panes that overlap
1265 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1267 int amount
= positions
[pane_i
] - offset
;
1271 positions
[pane_i
] += -amount
;
1273 offset
+= sizes
[pane_i
];
1278 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1281 wxDockUIPartArray
& uiparts
,
1285 wxSizerItem
* sizer_item
;
1287 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1288 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1289 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1290 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1292 // find out the orientation of the item (orientation for panes
1293 // is the same as the dock's orientation)
1295 if (dock
.IsHorizontal())
1296 orientation
= wxHORIZONTAL
;
1298 orientation
= wxVERTICAL
;
1300 // this variable will store the proportion
1301 // value that the pane will receive
1302 int pane_proportion
= pane
.dock_proportion
;
1304 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1305 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1307 if (pane
.HasGripper())
1309 if (pane
.HasGripperTop())
1310 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1312 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1314 part
.type
= wxDockUIPart::typeGripper
;
1318 part
.orientation
= orientation
;
1319 part
.cont_sizer
= horz_pane_sizer
;
1320 part
.sizer_item
= sizer_item
;
1324 if (pane
.HasCaption())
1326 // create the caption sizer
1327 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1329 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1331 part
.type
= wxDockUIPart::typeCaption
;
1335 part
.orientation
= orientation
;
1336 part
.cont_sizer
= vert_pane_sizer
;
1337 part
.sizer_item
= sizer_item
;
1338 int caption_part_idx
= uiparts
.GetCount();
1341 // add pane buttons to the caption
1342 int i
, button_count
;
1343 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1344 i
< button_count
; ++i
)
1346 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1348 sizer_item
= caption_sizer
->Add(pane_button_size
,
1352 part
.type
= wxDockUIPart::typePaneButton
;
1355 part
.button
= &button
;
1356 part
.orientation
= orientation
;
1357 part
.cont_sizer
= caption_sizer
;
1358 part
.sizer_item
= sizer_item
;
1362 // add the caption sizer
1363 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1365 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1368 // add the pane window itself
1371 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1375 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1376 // Don't do this because it breaks the pane size in floating windows
1377 // BIW: Right now commenting this out is causing problems with
1378 // an mdi client window as the center pane.
1379 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1382 part
.type
= wxDockUIPart::typePane
;
1386 part
.orientation
= orientation
;
1387 part
.cont_sizer
= vert_pane_sizer
;
1388 part
.sizer_item
= sizer_item
;
1392 // determine if the pane should have a minimum size; if the pane is
1393 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1394 // if the pane.min_size is set, we must use that value as well
1396 wxSize min_size
= pane
.min_size
;
1399 if (min_size
== wxDefaultSize
)
1401 min_size
= pane
.best_size
;
1402 pane_proportion
= 0;
1406 if (min_size
!= wxDefaultSize
)
1408 vert_pane_sizer
->SetItemMinSize(
1409 vert_pane_sizer
->GetChildren().GetCount()-1,
1410 min_size
.x
, min_size
.y
);
1414 // add the verticle sizer (caption, pane window) to the
1415 // horizontal sizer (gripper, verticle sizer)
1416 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1418 // finally, add the pane sizer to the dock sizer
1420 if (pane
.HasBorder())
1422 // allowing space for the pane's border
1423 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1424 wxEXPAND
| wxALL
, pane_border_size
);
1426 part
.type
= wxDockUIPart::typePaneBorder
;
1430 part
.orientation
= orientation
;
1431 part
.cont_sizer
= cont
;
1432 part
.sizer_item
= sizer_item
;
1437 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1441 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1443 wxDockUIPartArray
& uiparts
,
1446 wxSizerItem
* sizer_item
;
1449 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1450 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1452 // resizable bottom and right docks have a sash before them
1453 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1454 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1456 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1458 part
.type
= wxDockUIPart::typeDockSizer
;
1459 part
.orientation
= orientation
;
1463 part
.cont_sizer
= cont
;
1464 part
.sizer_item
= sizer_item
;
1468 // create the sizer for the dock
1469 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1471 // add each pane to the dock
1472 int pane_i
, pane_count
= dock
.panes
.GetCount();
1476 wxArrayInt pane_positions
, pane_sizes
;
1478 // figure out the real pane positions we will
1479 // use, without modifying the each pane's pane_pos member
1480 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1483 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1485 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1486 int pane_pos
= pane_positions
.Item(pane_i
);
1488 int amount
= pane_pos
- offset
;
1491 if (dock
.IsVertical())
1492 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1494 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1496 part
.type
= wxDockUIPart::typeBackground
;
1500 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1501 part
.cont_sizer
= dock_sizer
;
1502 part
.sizer_item
= sizer_item
;
1508 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1510 offset
+= pane_sizes
.Item(pane_i
);
1513 // at the end add a very small stretchable background area
1514 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1516 part
.type
= wxDockUIPart::typeBackground
;
1520 part
.orientation
= orientation
;
1521 part
.cont_sizer
= dock_sizer
;
1522 part
.sizer_item
= sizer_item
;
1527 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1529 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1531 // if this is not the first pane being added,
1532 // we need to add a pane sizer
1535 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1537 part
.type
= wxDockUIPart::typePaneSizer
;
1539 part
.pane
= dock
.panes
.Item(pane_i
-1);
1541 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1542 part
.cont_sizer
= dock_sizer
;
1543 part
.sizer_item
= sizer_item
;
1547 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1551 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1552 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1554 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1556 part
.type
= wxDockUIPart::typeDock
;
1560 part
.orientation
= orientation
;
1561 part
.cont_sizer
= cont
;
1562 part
.sizer_item
= sizer_item
;
1565 if (dock
.IsHorizontal())
1566 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1568 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1570 // top and left docks have a sash after them
1571 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1572 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1574 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1576 part
.type
= wxDockUIPart::typeDockSizer
;
1580 part
.orientation
= orientation
;
1581 part
.cont_sizer
= cont
;
1582 part
.sizer_item
= sizer_item
;
1587 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1588 wxDockInfoArray
& docks
,
1589 wxDockUIPartArray
& uiparts
,
1592 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1594 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1595 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1596 wxSize cli_size
= m_frame
->GetClientSize();
1597 int i
, dock_count
, pane_count
;
1600 // empty all docks out
1601 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1602 docks
.Item(i
).panes
.Empty();
1604 // iterate through all known panes, filing each
1605 // of them into the appropriate dock. If the
1606 // pane does not exist in the dock, add it
1607 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1609 wxPaneInfo
& p
= panes
.Item(i
);
1611 // find any docks in this layer
1613 wxDockInfoPtrArray arr
;
1614 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1616 if (arr
.GetCount() > 0)
1622 // dock was not found, so we need to create a new one
1624 d
.dock_direction
= p
.dock_direction
;
1625 d
.dock_layer
= p
.dock_layer
;
1626 d
.dock_row
= p
.dock_row
;
1628 dock
= &docks
.Last();
1632 if (p
.IsDocked() && p
.IsShown())
1634 // remove the pane from any existing docks except this one
1635 RemovePaneFromDocks(docks
, p
, dock
);
1637 // pane needs to be added to the dock,
1638 // if it doesn't already exist
1639 if (!FindPaneInDock(*dock
, p
.window
))
1640 dock
->panes
.Add(&p
);
1644 // remove the pane from any existing docks
1645 RemovePaneFromDocks(docks
, p
);
1650 // remove any empty docks
1651 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1653 if (docks
.Item(i
).panes
.GetCount() == 0)
1657 // configure the docks further
1658 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1660 wxDockInfo
& dock
= docks
.Item(i
);
1661 int j
, dock_pane_count
= dock
.panes
.GetCount();
1663 // sort the dock pane array by the pane's
1664 // dock position (dock_pos), in ascending order
1665 dock
.panes
.Sort(PaneSortFunc
);
1667 // for newly created docks, set up their initial size
1672 for (j
= 0; j
< dock_pane_count
; ++j
)
1674 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1675 wxSize pane_size
= pane
.best_size
;
1676 if (pane_size
== wxDefaultSize
)
1677 pane_size
= pane
.min_size
;
1678 if (pane_size
== wxDefaultSize
)
1679 pane_size
= pane
.window
->GetSize();
1681 if (dock
.IsHorizontal())
1682 size
= wxMax(pane_size
.y
, size
);
1684 size
= wxMax(pane_size
.x
, size
);
1687 // add space for the border (two times), but only
1688 // if at least one pane inside the dock has a pane border
1689 for (j
= 0; j
< dock_pane_count
; ++j
)
1691 if (dock
.panes
.Item(j
)->HasBorder())
1693 size
+= (pane_border_size
*2);
1698 // if pane is on the top or bottom, add the caption height,
1699 // but only if at least one pane inside the dock has a caption
1700 if (dock
.IsHorizontal())
1702 for (j
= 0; j
< dock_pane_count
; ++j
)
1704 if (dock
.panes
.Item(j
)->HasCaption())
1706 size
+= caption_size
;
1712 // new dock's size may not be more than 1/3 of the frame size
1713 if (dock
.IsHorizontal())
1714 size
= wxMin(size
, cli_size
.y
/3);
1716 size
= wxMin(size
, cli_size
.x
/3);
1724 // determine the dock's minimum size
1725 bool plus_border
= false;
1726 bool plus_caption
= false;
1727 int dock_min_size
= 0;
1728 for (j
= 0; j
< dock_pane_count
; ++j
)
1730 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1731 if (pane
.min_size
!= wxDefaultSize
)
1733 if (pane
.HasBorder())
1735 if (pane
.HasCaption())
1736 plus_caption
= true;
1737 if (dock
.IsHorizontal())
1739 if (pane
.min_size
.y
> dock_min_size
)
1740 dock_min_size
= pane
.min_size
.y
;
1744 if (pane
.min_size
.x
> dock_min_size
)
1745 dock_min_size
= pane
.min_size
.x
;
1751 dock_min_size
+= (pane_border_size
*2);
1752 if (plus_caption
&& dock
.IsHorizontal())
1753 dock_min_size
+= (caption_size
);
1755 dock
.min_size
= dock_min_size
;
1758 // if the pane's current size is less than it's
1759 // minimum, increase the dock's size to it's minimum
1760 if (dock
.size
< dock
.min_size
)
1761 dock
.size
= dock
.min_size
;
1764 // determine the dock's mode (fixed or proportional);
1765 // determine whether the dock has only toolbars
1766 bool action_pane_marked
= false;
1768 dock
.toolbar
= true;
1769 for (j
= 0; j
< dock_pane_count
; ++j
)
1771 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1772 if (!pane
.IsFixed())
1774 if (!pane
.IsToolbar())
1775 dock
.toolbar
= false;
1776 if (pane
.state
& wxPaneInfo::actionPane
)
1777 action_pane_marked
= true;
1781 // if the dock mode is proportional and not fixed-pixel,
1782 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1783 // e.g. remove gaps like 1, 2, 30, 500
1786 for (j
= 0; j
< dock_pane_count
; ++j
)
1788 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1793 // if the dock mode is fixed, and none of the panes
1794 // are being moved right now, make sure the panes
1795 // do not overlap each other. If they do, we will
1796 // adjust the panes' positions
1797 if (dock
.fixed
&& !action_pane_marked
)
1799 wxArrayInt pane_positions
, pane_sizes
;
1800 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1803 for (j
= 0; j
< dock_pane_count
; ++j
)
1805 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1806 pane
.dock_pos
= pane_positions
[j
];
1808 int amount
= pane
.dock_pos
- offset
;
1812 pane
.dock_pos
+= -amount
;
1814 offset
+= pane_sizes
[j
];
1819 // discover the maximum dock layer
1821 for (i
= 0; i
< dock_count
; ++i
)
1822 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1825 // clear out uiparts
1828 // create a bunch of box sizers,
1829 // from the innermost level outwards.
1830 wxSizer
* cont
= NULL
;
1831 wxSizer
* middle
= NULL
;
1835 for (layer
= 0; layer
<= max_layer
; ++layer
)
1837 wxDockInfoPtrArray arr
;
1839 // find any docks in this layer
1840 FindDocks(docks
, -1, layer
, -1, arr
);
1842 // if there aren't any, skip to the next layer
1846 wxSizer
* old_cont
= cont
;
1848 // create a container which will hold this layer's
1849 // docks (top, bottom, left, right)
1850 cont
= new wxBoxSizer(wxVERTICAL
);
1853 // find any top docks in this layer
1854 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1855 RenumberDockRows(arr
);
1858 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1859 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1863 // fill out the middle layer (which consists
1864 // of left docks, content area and right docks)
1866 middle
= new wxBoxSizer(wxHORIZONTAL
);
1868 // find any left docks in this layer
1869 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1870 RenumberDockRows(arr
);
1873 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1874 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1877 // add content dock (or previous layer's sizer
1881 // find any center docks
1882 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1885 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1886 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1890 // there are no center docks, add a background area
1891 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1893 part
.type
= wxDockUIPart::typeBackground
;
1897 part
.cont_sizer
= middle
;
1898 part
.sizer_item
= sizer_item
;
1904 middle
->Add(old_cont
, 1, wxEXPAND
);
1907 // find any right docks in this layer
1908 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1909 RenumberDockRows(arr
);
1912 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1913 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1916 cont
->Add(middle
, 1, wxEXPAND
);
1920 // find any bottom docks in this layer
1921 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1922 RenumberDockRows(arr
);
1925 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1926 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1933 // no sizer available, because there are no docks,
1934 // therefore we will create a simple background area
1935 cont
= new wxBoxSizer(wxVERTICAL
);
1936 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1938 part
.type
= wxDockUIPart::typeBackground
;
1942 part
.cont_sizer
= middle
;
1943 part
.sizer_item
= sizer_item
;
1947 container
->Add(cont
, 1, wxEXPAND
);
1952 // Update() updates the layout. Whenever changes are made to
1953 // one or more panes, this function should be called. It is the
1954 // external entry point for running the layout engine.
1956 void wxFrameManager::Update()
1959 int i
, pane_count
= m_panes
.GetCount();
1961 // delete old sizer first
1962 m_frame
->SetSizer(NULL
);
1964 // destroy floating panes which have been
1965 // redocked or are becoming non-floating
1966 for (i
= 0; i
< pane_count
; ++i
)
1968 wxPaneInfo
& p
= m_panes
.Item(i
);
1970 if (!p
.IsFloating() && p
.frame
)
1972 // because the pane is no longer in a floating, we need to
1973 // reparent it to m_frame and destroy the floating frame
1976 p
.window
->SetSize(1,1);
1978 if (p
.frame
->IsShown())
1979 p
.frame
->Show(false);
1981 // reparent to m_frame and destroy the pane
1982 p
.window
->Reparent(m_frame
);
1983 p
.frame
->SetSizer(NULL
);
1990 // create a layout for all of the panes
1991 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
1993 // hide or show panes as necessary,
1994 // and float panes as necessary
1995 for (i
= 0; i
< pane_count
; ++i
)
1997 wxPaneInfo
& p
= m_panes
.Item(i
);
2001 if (p
.frame
== NULL
)
2003 // we need to create a frame for this
2004 // pane, which has recently been floated
2005 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
2009 #if wxCHECK_VERSION(2,7,0)
2010 // on MSW and Mac, if the owner desires transparent dragging, and
2011 // the dragging is happening right now, then the floating
2012 // window should have this style by default
2013 if (m_action
== actionDragFloatingPane
&&
2014 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2015 frame
->SetTransparent(150);
2018 frame
->SetPaneWindow(p
);
2021 if (p
.IsShown() && !frame
->IsShown())
2026 // frame already exists, make sure it's position
2027 // and size reflect the information in wxPaneInfo
2028 if (p
.frame
->GetPosition() != p
.floating_pos
)
2030 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2031 wxDefaultCoord
, wxDefaultCoord
,
2032 wxSIZE_USE_EXISTING
);
2033 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2036 if (p
.frame
->IsShown() != p
.IsShown())
2037 p
.frame
->Show(p
.IsShown());
2042 if (p
.window
->IsShown() != p
.IsShown())
2043 p
.window
->Show(p
.IsShown());
2046 // if "active panes" are no longer allowed, clear
2047 // any optionActive values from the pane states
2048 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2050 p
.state
&= ~wxPaneInfo::optionActive
;
2055 // keep track of the old window rectangles so we can
2056 // refresh those windows whose rect has changed
2057 wxAuiRectArray old_pane_rects
;
2058 for (i
= 0; i
< pane_count
; ++i
)
2061 wxPaneInfo
& p
= m_panes
.Item(i
);
2063 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2066 old_pane_rects
.Add(r
);
2072 // apply the new sizer
2073 m_frame
->SetSizer(sizer
);
2074 m_frame
->SetAutoLayout(false);
2079 // now that the frame layout is done, we need to check
2080 // the new pane rectangles against the old rectangles that
2081 // we saved a few lines above here. If the rectangles have
2082 // changed, the corresponding panes must also be updated
2083 for (i
= 0; i
< pane_count
; ++i
)
2085 wxPaneInfo
& p
= m_panes
.Item(i
);
2086 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2088 if (p
.rect
!= old_pane_rects
[i
])
2090 p
.window
->Refresh();
2099 // set frame's minimum size
2102 // N.B. More work needs to be done on frame minimum sizes;
2103 // this is some intresting code that imposes the minimum size,
2104 // but we may want to include a more flexible mechanism or
2105 // options for multiple minimum-size modes, e.g. strict or lax
2106 wxSize min_size = sizer->GetMinSize();
2107 wxSize frame_size = m_frame->GetSize();
2108 wxSize client_size = m_frame->GetClientSize();
2110 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2111 min_size.y+frame_size.y-client_size.y );
2113 m_frame->SetMinSize(minframe_size);
2115 if (frame_size.x < minframe_size.x ||
2116 frame_size.y < minframe_size.y)
2117 sizer->Fit(m_frame);
2122 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2123 // on the frame's main sizer, then measures all the various UI items
2124 // and updates their internal rectangles. This should always be called
2125 // instead of calling m_frame->Layout() directly
2127 void wxFrameManager::DoFrameLayout()
2132 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2134 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2136 // get the rectangle of the UI part
2137 // originally, this code looked like this:
2138 // part.rect = wxRect(part.sizer_item->GetPosition(),
2139 // part.sizer_item->GetSize());
2140 // this worked quite well, with one exception: the mdi
2141 // client window had a "deferred" size variable
2142 // that returned the wrong size. It looks like
2143 // a bug in wx, because the former size of the window
2144 // was being returned. So, we will retrieve the part's
2145 // rectangle via other means
2148 part
.rect
= part
.sizer_item
->GetRect();
2149 int flag
= part
.sizer_item
->GetFlag();
2150 int border
= part
.sizer_item
->GetBorder();
2153 part
.rect
.y
-= border
;
2154 part
.rect
.height
+= border
;
2158 part
.rect
.x
-= border
;
2159 part
.rect
.width
+= border
;
2161 if (flag
& wxBOTTOM
)
2162 part
.rect
.height
+= border
;
2164 part
.rect
.width
+= border
;
2167 if (part
.type
== wxDockUIPart::typeDock
)
2168 part
.dock
->rect
= part
.rect
;
2169 if (part
.type
== wxDockUIPart::typePane
)
2170 part
.pane
->rect
= part
.rect
;
2174 // GetPanePart() looks up the pane the pane border UI part (or the regular
2175 // pane part if there is no border). This allows the caller to get the exact
2176 // rectangle of the pane in question, including decorations like
2177 // caption and border (if any).
2179 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
2182 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2184 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2185 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2186 part
.pane
&& part
.pane
->window
== wnd
)
2189 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2191 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2192 if (part
.type
== wxDockUIPart::typePane
&&
2193 part
.pane
&& part
.pane
->window
== wnd
)
2201 // GetDockPixelOffset() is an internal function which returns
2202 // a dock's offset in pixels from the left side of the window
2203 // (for horizontal docks) or from the top of the window (for
2204 // vertical docks). This value is necessary for calculating
2205 // fixel-pane/toolbar offsets when they are dragged.
2207 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
2209 // the only way to accurately calculate the dock's
2210 // offset is to actually run a theoretical layout
2212 int i
, part_count
, dock_count
;
2213 wxDockInfoArray docks
;
2214 wxPaneInfoArray panes
;
2215 wxDockUIPartArray uiparts
;
2216 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2219 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2220 wxSize client_size
= m_frame
->GetClientSize();
2221 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2224 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2226 wxDockUIPart
& part
= uiparts
.Item(i
);
2227 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2228 part
.sizer_item
->GetSize());
2229 if (part
.type
== wxDockUIPart::typeDock
)
2230 part
.dock
->rect
= part
.rect
;
2235 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2237 wxDockInfo
& dock
= docks
.Item(i
);
2238 if (test
.dock_direction
== dock
.dock_direction
&&
2239 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2241 if (dock
.IsVertical())
2253 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2254 // if a dock operation is allowed, the new dock position is copied into
2255 // the target info. If the operation was allowed, the function returns true.
2257 bool wxFrameManager::ProcessDockResult(wxPaneInfo
& target
,
2258 const wxPaneInfo
& new_pos
)
2260 bool allowed
= false;
2261 switch (new_pos
.dock_direction
)
2263 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2264 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2265 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2266 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2276 // DoDrop() is an important function. It basically takes a mouse position,
2277 // and determines where the pane's new position would be. If the pane is to be
2278 // dropped, it performs the drop operation using the specified dock and pane
2279 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2280 // scenario can be performed, giving precise coordinates for drop hints.
2281 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2282 // as parameters, the changes will be made to the main state arrays
2284 const int auiInsertRowPixels
= 10;
2285 const int auiNewRowPixels
= 40;
2286 const int auiLayerInsertPixels
= 40;
2287 const int auiLayerInsertOffset
= 5;
2289 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2290 wxPaneInfoArray
& panes
,
2293 const wxPoint
& offset
)
2295 wxSize cli_size
= m_frame
->GetClientSize();
2297 wxPaneInfo drop
= target
;
2300 // The result should always be shown
2304 // Check to see if the pane has been dragged outside of the window
2305 // (or near to the outside of the window), if so, dock it along the edge
2308 int layer_insert_offset
= auiLayerInsertOffset
;
2309 if (target
.IsToolbar())
2310 layer_insert_offset
= 0;
2312 if (pt
.x
< layer_insert_offset
&&
2313 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2317 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2318 return ProcessDockResult(target
, drop
);
2320 else if (pt
.y
< layer_insert_offset
&&
2321 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2325 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2326 return ProcessDockResult(target
, drop
);
2328 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2329 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2331 drop
.Dock().Right().
2333 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2334 return ProcessDockResult(target
, drop
);
2336 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2337 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2339 drop
.Dock().Bottom().
2341 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2342 return ProcessDockResult(target
, drop
);
2345 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2348 if (drop
.IsToolbar())
2350 if (!part
|| !part
->dock
)
2354 // calculate the offset from where the dock begins
2355 // to the point where the user dropped the pane
2356 int dock_drop_offset
= 0;
2357 if (part
->dock
->IsHorizontal())
2358 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2360 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2363 // toolbars may only be moved in and to fixed-pane docks,
2364 // otherwise we will try to float the pane. Also, the pane
2365 // should float if being dragged over center pane windows
2366 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2368 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2369 (drop
.IsFloatable() ||
2370 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2371 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2376 return ProcessDockResult(target
, drop
);
2380 Direction(part
->dock
->dock_direction
).
2381 Layer(part
->dock
->dock_layer
).
2382 Row(part
->dock
->dock_row
).
2383 Position(dock_drop_offset
);
2386 ((pt
.y
< part
->dock
->rect
.y
+ 2) && part
->dock
->IsHorizontal()) ||
2387 ((pt
.x
< part
->dock
->rect
.x
+ 2) && part
->dock
->IsVertical())
2388 ) && part
->dock
->panes
.GetCount() > 1)
2390 int row
= drop
.dock_row
;
2391 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2392 part
->dock
->dock_layer
,
2393 part
->dock
->dock_row
);
2394 drop
.dock_row
= row
;
2398 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2399 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2400 ) && part
->dock
->panes
.GetCount() > 1)
2402 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2403 part
->dock
->dock_layer
,
2404 part
->dock
->dock_row
+1);
2405 drop
.dock_row
= part
->dock
->dock_row
+1;
2408 return ProcessDockResult(target
, drop
);
2417 if (part
->type
== wxDockUIPart::typePaneBorder
||
2418 part
->type
== wxDockUIPart::typeCaption
||
2419 part
->type
== wxDockUIPart::typeGripper
||
2420 part
->type
== wxDockUIPart::typePaneButton
||
2421 part
->type
== wxDockUIPart::typePane
||
2422 part
->type
== wxDockUIPart::typePaneSizer
||
2423 part
->type
== wxDockUIPart::typeDockSizer
||
2424 part
->type
== wxDockUIPart::typeBackground
)
2426 if (part
->type
== wxDockUIPart::typeDockSizer
)
2428 if (part
->dock
->panes
.GetCount() != 1)
2430 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2437 // If a normal frame is being dragged over a toolbar, insert it
2438 // along the edge under the toolbar, but over all other panes.
2439 // (this could be done much better, but somehow factoring this
2440 // calculation with the one at the beginning of this function)
2441 if (part
->dock
&& part
->dock
->toolbar
)
2445 switch (part
->dock
->dock_direction
)
2447 case wxAUI_DOCK_LEFT
:
2448 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2449 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2450 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2452 case wxAUI_DOCK_TOP
:
2453 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2454 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2455 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2457 case wxAUI_DOCK_RIGHT
:
2458 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2459 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2460 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2462 case wxAUI_DOCK_BOTTOM
:
2463 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2464 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2465 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2469 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2472 Direction(part
->dock
->dock_direction
).
2473 Layer(layer
).Row(0).Position(0);
2474 return ProcessDockResult(target
, drop
);
2481 part
= GetPanePart(part
->pane
->window
);
2485 bool insert_dock_row
= false;
2486 int insert_row
= part
->pane
->dock_row
;
2487 int insert_dir
= part
->pane
->dock_direction
;
2488 int insert_layer
= part
->pane
->dock_layer
;
2490 switch (part
->pane
->dock_direction
)
2492 case wxAUI_DOCK_TOP
:
2493 if (pt
.y
>= part
->rect
.y
&&
2494 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2495 insert_dock_row
= true;
2497 case wxAUI_DOCK_BOTTOM
:
2498 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2499 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2500 insert_dock_row
= true;
2502 case wxAUI_DOCK_LEFT
:
2503 if (pt
.x
>= part
->rect
.x
&&
2504 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2505 insert_dock_row
= true;
2507 case wxAUI_DOCK_RIGHT
:
2508 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2509 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2510 insert_dock_row
= true;
2512 case wxAUI_DOCK_CENTER
:
2514 // "new row pixels" will be set to the default, but
2515 // must never exceed 20% of the window size
2516 int new_row_pixels_x
= auiNewRowPixels
;
2517 int new_row_pixels_y
= auiNewRowPixels
;
2519 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2520 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2522 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2523 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2526 // determine if the mouse pointer is in a location that
2527 // will cause a new row to be inserted. The hot spot positions
2528 // are along the borders of the center pane
2531 insert_dock_row
= true;
2532 if (pt
.x
>= part
->rect
.x
&&
2533 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2534 insert_dir
= wxAUI_DOCK_LEFT
;
2536 if (pt
.y
>= part
->rect
.y
&&
2537 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2538 insert_dir
= wxAUI_DOCK_TOP
;
2540 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2541 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2542 insert_dir
= wxAUI_DOCK_RIGHT
;
2544 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2545 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2546 insert_dir
= wxAUI_DOCK_BOTTOM
;
2550 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2554 if (insert_dock_row
)
2556 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2557 drop
.Dock().Direction(insert_dir
).
2558 Layer(insert_layer
).
2561 return ProcessDockResult(target
, drop
);
2564 // determine the mouse offset and the pane size, both in the
2565 // direction of the dock itself, and perpendicular to the dock
2569 if (part
->orientation
== wxVERTICAL
)
2571 offset
= pt
.y
- part
->rect
.y
;
2572 size
= part
->rect
.GetHeight();
2576 offset
= pt
.x
- part
->rect
.x
;
2577 size
= part
->rect
.GetWidth();
2580 int drop_position
= part
->pane
->dock_pos
;
2582 // if we are in the top/left part of the pane,
2583 // insert the pane before the pane being hovered over
2584 if (offset
<= size
/2)
2586 drop_position
= part
->pane
->dock_pos
;
2588 part
->pane
->dock_direction
,
2589 part
->pane
->dock_layer
,
2590 part
->pane
->dock_row
,
2591 part
->pane
->dock_pos
);
2594 // if we are in the bottom/right part of the pane,
2595 // insert the pane before the pane being hovered over
2596 if (offset
> size
/2)
2598 drop_position
= part
->pane
->dock_pos
+1;
2600 part
->pane
->dock_direction
,
2601 part
->pane
->dock_layer
,
2602 part
->pane
->dock_row
,
2603 part
->pane
->dock_pos
+1);
2607 Direction(part
->dock
->dock_direction
).
2608 Layer(part
->dock
->dock_layer
).
2609 Row(part
->dock
->dock_row
).
2610 Position(drop_position
);
2611 return ProcessDockResult(target
, drop
);
2618 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2620 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
2622 m_hint_fadetimer
.Stop();
2626 m_hint_fadeamt
+= 4;
2627 #if wxCHECK_VERSION(2,7,0)
2628 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2630 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2631 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2635 void wxFrameManager::ShowHint(const wxRect
& rect
)
2637 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0
2639 // Finally, don't use a venetian blind effect if it's been specifically disabled
2640 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2641 (m_flags
& wxAUI_MGR_DISABLE_VENETIAN_BLINDS
))
2644 if (m_last_hint
== rect
)
2648 m_hint_fadeamt
= m_hint_fademax
;
2649 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2650 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2651 (m_flags
& wxAUI_MGR_DISABLE_VENETIAN_BLINDS_FADE
))
2655 m_hint_wnd
->SetSize(rect
);
2657 if (! m_hint_wnd
->IsShown())
2660 // if we are dragging a floating pane, set the focus
2661 // back to that floating pane (otherwise it becomes unfocused)
2662 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2663 m_action_window
->SetFocus();
2665 #if wxCHECK_VERSION(2,7,0)
2666 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2668 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2669 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2671 m_hint_wnd
->Raise();
2674 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
2676 // start fade in timer
2677 m_hint_fadetimer
.SetOwner(this, 101);
2678 m_hint_fadetimer
.Start(5);
2682 else // Not using a transparent hint window...
2685 if (m_last_hint
!= rect
)
2687 // remove the last hint rectangle
2693 wxScreenDC screendc
;
2694 wxRegion
clip(1, 1, 10000, 10000);
2696 // clip all floating windows, so we don't draw over them
2698 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2700 wxPaneInfo
& pane
= m_panes
.Item(i
);
2702 if (pane
.IsFloating() &&
2703 pane
.frame
->IsShown())
2705 wxRect rect
= pane
.frame
->GetRect();
2707 // wxGTK returns the client size, not the whole frame size
2713 clip
.Subtract(rect
);
2717 // As we can only hide the hint by redrawing the managed window, we
2718 // need to clip the region to the managed window too or we get
2719 // nasty redrawn problems.
2720 clip
.Intersect(m_frame
->GetRect());
2722 screendc
.SetClippingRegion(clip
);
2724 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2725 wxBrush
brush(stipple
);
2726 screendc
.SetBrush(brush
);
2727 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2729 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2730 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2731 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2732 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2736 void wxFrameManager::HideHint()
2738 // hides a transparent window hint, if there is one
2741 if (m_hint_wnd
->IsShown())
2742 m_hint_wnd
->Show(false);
2743 #if wxCHECK_VERSION(2,7,0)
2744 m_hint_wnd
->SetTransparent(0);
2746 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2747 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(0);
2749 m_hint_fadetimer
.Stop();
2750 m_last_hint
= wxRect();
2754 // hides a painted hint by redrawing the frame window
2755 if (!m_last_hint
.IsEmpty())
2759 m_last_hint
= wxRect();
2765 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2766 // determine the exact position the pane would be at were if dropped. If
2767 // the pame would indeed become docked at the specified drop point,
2768 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2769 // "pane_window" is the window pointer of the pane being dragged, pt is
2770 // the mouse position, in client coordinates
2771 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2773 const wxPoint
& offset
)
2777 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2778 // we will create a new temporary layout and then measure the resulting
2779 // rectangle; we will create a copy of the docking structures (m_dock)
2780 // so that we don't modify the real thing on screen
2782 int i
, pane_count
, part_count
;
2783 wxDockInfoArray docks
;
2784 wxPaneInfoArray panes
;
2785 wxDockUIPartArray uiparts
;
2786 wxPaneInfo hint
= GetPane(pane_window
);
2787 hint
.name
= wxT("__HINT__");
2793 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2795 // remove any pane already there which bears the same window;
2796 // this happens when you are moving a pane around in a dock
2797 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2799 if (panes
.Item(i
).window
== pane_window
)
2801 RemovePaneFromDocks(docks
, panes
.Item(i
));
2807 // find out where the new pane would be
2808 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2816 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2817 wxSize client_size
= m_frame
->GetClientSize();
2818 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2821 for (i
= 0, part_count
= uiparts
.GetCount();
2822 i
< part_count
; ++i
)
2824 wxDockUIPart
& part
= uiparts
.Item(i
);
2826 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2827 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2829 rect
= wxRect(part
.sizer_item
->GetPosition(),
2830 part
.sizer_item
->GetSize());
2843 // actually show the hint rectangle on the screen
2844 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2848 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2850 // try to find the pane
2851 wxPaneInfo
& pane
= GetPane(wnd
);
2852 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2854 #if wxCHECK_VERSION(2,7,0)
2855 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2856 pane
.frame
->SetTransparent(150);
2860 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
2862 // try to find the pane
2863 wxPaneInfo
& pane
= GetPane(wnd
);
2864 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2866 wxPoint pt
= ::wxGetMousePosition();
2869 // Adapt pt to direction
2872 // move to pane's upper border
2874 pos
= wnd
->ClientToScreen( pos
);
2876 // and some more pixels for the title bar
2881 // move to pane's left border
2883 pos
= wnd
->ClientToScreen( pos
);
2888 // move to pane's right border
2889 wxPoint
pos( wnd
->GetSize().x
, 0 );
2890 pos
= wnd
->ClientToScreen( pos
);
2895 // move to pane's bottom border
2896 wxPoint
pos( 0, wnd
->GetSize().y
);
2897 pos
= wnd
->ClientToScreen( pos
);
2902 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2904 // calculate the offset from the upper left-hand corner
2905 // of the frame to the mouse pointer
2906 wxPoint frame_pos
= pane
.frame
->GetPosition();
2907 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2909 // no hint for toolbar floating windows
2910 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
2912 if (m_action
== actionDragFloatingPane
)
2914 wxDockInfoArray docks
;
2915 wxPaneInfoArray panes
;
2916 wxDockUIPartArray uiparts
;
2917 wxPaneInfo hint
= pane
;
2919 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2921 // find out where the new pane would be
2922 if (!DoDrop(docks
, panes
, hint
, client_pt
))
2924 if (hint
.IsFloating())
2928 m_action
= actionDragToolbarPane
;
2929 m_action_window
= pane
.window
;
2938 // if a key modifier is pressed while dragging the frame,
2939 // don't dock the window
2940 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2947 DrawHintRect(wnd
, client_pt
, action_offset
);
2950 // this cleans up some screen artifacts that are caused on GTK because
2951 // we aren't getting the exact size of the window (see comment
2961 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
2963 // try to find the pane
2964 wxPaneInfo
& pane
= GetPane(wnd
);
2965 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2967 wxPoint pt
= ::wxGetMousePosition();
2970 // Adapt pt to direction
2973 // move to pane's upper border
2975 pos
= wnd
->ClientToScreen( pos
);
2977 // and some more pixels for the title bar
2982 // move to pane's left border
2984 pos
= wnd
->ClientToScreen( pos
);
2989 // move to pane's right border
2990 wxPoint
pos( wnd
->GetSize().x
, 0 );
2991 pos
= wnd
->ClientToScreen( pos
);
2996 // move to pane's bottom border
2997 wxPoint
pos( 0, wnd
->GetSize().y
);
2998 pos
= wnd
->ClientToScreen( pos
);
3003 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3005 // calculate the offset from the upper left-hand corner
3006 // of the frame to the mouse pointer
3007 wxPoint frame_pos
= pane
.frame
->GetPosition();
3008 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3011 // if a key modifier is pressed while dragging the frame,
3012 // don't dock the window
3013 if (!wxGetKeyState(WXK_CONTROL
) && !wxGetKeyState(WXK_ALT
))
3015 // do the drop calculation
3016 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3019 // if the pane is still floating, update it's floating
3020 // position (that we store)
3021 if (pane
.IsFloating())
3023 pane
.floating_pos
= pane
.frame
->GetPosition();
3025 #if wxCHECK_VERSION(2,7,0)
3026 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3027 pane
.frame
->SetTransparent(255);
3036 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3038 // try to find the pane
3039 wxPaneInfo
& pane
= GetPane(wnd
);
3040 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3042 pane
.floating_size
= size
;
3046 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3048 // try to find the pane
3049 wxPaneInfo
& pane
= GetPane(wnd
);
3050 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3053 // fire pane close event
3054 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3056 e
.SetCanVeto(evt
.CanVeto());
3066 // reparent the pane window back to us and
3067 // prepare the frame window for destruction
3068 if (pane
.window
->IsShown())
3069 pane
.window
->Show(false);
3070 pane
.window
->Reparent(m_frame
);
3078 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3080 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3082 // try to find the pane
3083 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
3085 SetActivePane(m_panes
, wnd
);
3090 // OnRender() draws all of the pane captions, sashes,
3091 // backgrounds, captions, grippers, pane borders and buttons.
3092 // It renders the entire user interface.
3094 void wxFrameManager::OnRender(wxFrameManagerEvent
& evt
)
3096 wxDC
* dc
= evt
.GetDC();
3102 for (i
= 0, part_count
= m_uiparts
.GetCount();
3103 i
< part_count
; ++i
)
3105 wxDockUIPart
& part
= m_uiparts
.Item(i
);
3107 // don't draw hidden pane items
3108 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
3113 case wxDockUIPart::typeDockSizer
:
3114 case wxDockUIPart::typePaneSizer
:
3115 m_art
->DrawSash(*dc
, part
.orientation
, part
.rect
);
3117 case wxDockUIPart::typeBackground
:
3118 m_art
->DrawBackground(*dc
, part
.orientation
, part
.rect
);
3120 case wxDockUIPart::typeCaption
:
3121 m_art
->DrawCaption(*dc
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3123 case wxDockUIPart::typeGripper
:
3124 m_art
->DrawGripper(*dc
, part
.rect
, *part
.pane
);
3126 case wxDockUIPart::typePaneBorder
:
3127 m_art
->DrawBorder(*dc
, part
.rect
, *part
.pane
);
3129 case wxDockUIPart::typePaneButton
:
3130 m_art
->DrawPaneButton(*dc
, part
.button
->button_id
,
3131 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3138 // Render() fire a render event, which is normally handled by
3139 // wxFrameManager::OnRender(). This allows the render function to
3140 // be overridden via the render event. This can be useful for paintin
3141 // custom graphics in the main window. Default behavior can be
3142 // invoked in the overridden function by calling OnRender()
3144 void wxFrameManager::Render(wxDC
* dc
)
3146 wxFrameManagerEvent
e(wxEVT_AUI_RENDER
);
3151 void wxFrameManager::Repaint(wxDC
* dc
)
3156 m_frame
->Refresh() ;
3162 m_frame
->GetClientSize(&w
, &h
);
3164 // figure out which dc to use; if one
3165 // has been specified, use it, otherwise
3167 wxClientDC
* client_dc
= NULL
;
3170 client_dc
= new wxClientDC(m_frame
);
3174 // if the frame has a toolbar, the client area
3175 // origin will not be (0,0).
3176 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3177 if (pt
.x
!= 0 || pt
.y
!= 0)
3178 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3180 // render all the items
3183 // if we created a client_dc, delete it
3188 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3190 wxPaintDC
dc(m_frame
);
3194 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
3203 void wxFrameManager::OnSize(wxSizeEvent
& event
)
3214 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
3217 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3218 wxCursor cursor
= wxNullCursor
;
3222 if (part
->type
== wxDockUIPart::typeDockSizer
||
3223 part
->type
== wxDockUIPart::typePaneSizer
)
3225 // a dock may not be resized if it has a single
3226 // pane which is not resizable
3227 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3228 part
->dock
->panes
.GetCount() == 1 &&
3229 part
->dock
->panes
.Item(0)->IsFixed())
3232 // panes that may not be resized do not get a sizing cursor
3233 if (part
->pane
&& part
->pane
->IsFixed())
3236 if (part
->orientation
== wxVERTICAL
)
3237 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3239 cursor
= wxCursor(wxCURSOR_SIZENS
);
3241 else if (part
->type
== wxDockUIPart::typeGripper
)
3243 cursor
= wxCursor(wxCURSOR_SIZING
);
3247 event
.SetCursor(cursor
);
3252 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
3253 const wxMouseEvent
& event
)
3255 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3257 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3259 if (hit_test
== button_ui_part
)
3261 if (event
.LeftDown())
3262 state
= wxAUI_BUTTON_STATE_PRESSED
;
3264 state
= wxAUI_BUTTON_STATE_HOVER
;
3268 if (event
.LeftDown())
3269 state
= wxAUI_BUTTON_STATE_HOVER
;
3272 // now repaint the button with hover state
3273 wxClientDC
cdc(m_frame
);
3275 // if the frame has a toolbar, the client area
3276 // origin will not be (0,0).
3277 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3278 if (pt
.x
!= 0 || pt
.y
!= 0)
3279 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3281 m_art
->DrawPaneButton(cdc
,
3282 button_ui_part
->button
->button_id
,
3284 button_ui_part
->rect
,
3288 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
3290 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3293 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3296 if (part
->type
== wxDockUIPart::typeDockSizer
||
3297 part
->type
== wxDockUIPart::typePaneSizer
)
3299 // a dock may not be resized if it has a single
3300 // pane which is not resizable
3301 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3302 part
->dock
->panes
.GetCount() == 1 &&
3303 part
->dock
->panes
.Item(0)->IsFixed())
3306 // panes that may not be resized should be ignored here
3307 if (part
->pane
&& part
->pane
->IsFixed())
3310 m_action
= actionResize
;
3311 m_action_part
= part
;
3312 m_action_hintrect
= wxRect();
3313 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3314 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3315 event
.m_y
- part
->rect
.y
);
3316 m_frame
->CaptureMouse();
3318 else if (part
->type
== wxDockUIPart::typePaneButton
)
3320 m_action
= actionClickButton
;
3321 m_action_part
= part
;
3322 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3323 m_frame
->CaptureMouse();
3325 UpdateButtonOnScreen(part
, event
);
3327 else if (part
->type
== wxDockUIPart::typeCaption
||
3328 part
->type
== wxDockUIPart::typeGripper
)
3330 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3332 // set the caption as active
3333 SetActivePane(m_panes
, part
->pane
->window
);
3337 m_action
= actionClickCaption
;
3338 m_action_part
= part
;
3339 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3340 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3341 event
.m_y
- part
->rect
.y
);
3342 m_frame
->CaptureMouse();
3362 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3364 if (m_action
== actionResize
)
3366 m_frame
->ReleaseMouse();
3368 // get rid of the hint rectangle
3370 DrawResizeHint(dc
, m_action_hintrect
);
3372 // resize the dock or the pane
3373 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3375 wxRect
& rect
= m_action_part
->dock
->rect
;
3377 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3378 event
.m_y
- m_action_offset
.y
);
3380 switch (m_action_part
->dock
->dock_direction
)
3382 case wxAUI_DOCK_LEFT
:
3383 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3385 case wxAUI_DOCK_TOP
:
3386 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3388 case wxAUI_DOCK_RIGHT
:
3389 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3390 new_pos
.x
- m_action_part
->rect
.GetWidth();
3392 case wxAUI_DOCK_BOTTOM
:
3393 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3394 new_pos
.y
- m_action_part
->rect
.GetHeight();
3401 else if (m_action_part
&&
3402 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3404 wxDockInfo
& dock
= *m_action_part
->dock
;
3405 wxPaneInfo
& pane
= *m_action_part
->pane
;
3407 int total_proportion
= 0;
3408 int dock_pixels
= 0;
3409 int new_pixsize
= 0;
3411 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3412 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3413 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3415 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3416 event
.m_y
- m_action_offset
.y
);
3418 // determine the pane rectangle by getting the pane part
3419 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3420 wxASSERT_MSG(pane_part
,
3421 wxT("Pane border part not found -- shouldn't happen"));
3423 // determine the new pixel size that the user wants;
3424 // this will help us recalculate the pane's proportion
3425 if (dock
.IsHorizontal())
3426 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3428 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3430 // determine the size of the dock, based on orientation
3431 if (dock
.IsHorizontal())
3432 dock_pixels
= dock
.rect
.GetWidth();
3434 dock_pixels
= dock
.rect
.GetHeight();
3436 // determine the total proportion of all resizable panes,
3437 // and the total size of the dock minus the size of all
3439 int i
, dock_pane_count
= dock
.panes
.GetCount();
3440 int pane_position
= -1;
3441 for (i
= 0; i
< dock_pane_count
; ++i
)
3443 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3444 if (p
.window
== pane
.window
)
3447 // while we're at it, subtract the pane sash
3448 // width from the dock width, because this would
3449 // skew our proportion calculations
3451 dock_pixels
-= sash_size
;
3453 // also, the whole size (including decorations) of
3454 // all fixed panes must also be subtracted, because they
3455 // are not part of the proportion calculation
3458 if (dock
.IsHorizontal())
3459 dock_pixels
-= p
.best_size
.x
;
3461 dock_pixels
-= p
.best_size
.y
;
3465 total_proportion
+= p
.dock_proportion
;
3469 // find a pane in our dock to 'steal' space from or to 'give'
3470 // space to -- this is essentially what is done when a pane is
3471 // resized; the pane should usually be the first non-fixed pane
3472 // to the right of the action pane
3473 int borrow_pane
= -1;
3474 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3476 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3485 // demand that the pane being resized is found in this dock
3486 // (this assert really never should be raised)
3487 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3489 // prevent division by zero
3490 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3492 m_action
= actionNone
;
3496 // calculate the new proportion of the pane
3497 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3499 // default minimum size
3502 // check against the pane's minimum size, if specified. please note
3503 // that this is not enough to ensure that the minimum size will
3504 // not be violated, because the whole frame might later be shrunk,
3505 // causing the size of the pane to violate it's minimum size
3506 if (pane
.min_size
.IsFullySpecified())
3510 if (pane
.HasBorder())
3511 min_size
+= (pane_border_size
*2);
3513 // calculate minimum size with decorations (border,caption)
3514 if (pane_part
->orientation
== wxVERTICAL
)
3516 min_size
+= pane
.min_size
.y
;
3517 if (pane
.HasCaption())
3518 min_size
+= caption_size
;
3522 min_size
+= pane
.min_size
.x
;
3527 // for some reason, an arithmatic error somewhere is causing
3528 // the proportion calculations to always be off by 1 pixel;
3529 // for now we will add the 1 pixel on, but we really should
3530 // determine what's causing this.
3533 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3535 if (new_proportion
< min_proportion
)
3536 new_proportion
= min_proportion
;
3540 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3542 // borrow the space from our neighbor pane to the
3543 // right or bottom (depending on orientation)
3544 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3545 pane
.dock_proportion
= new_proportion
;
3552 else if (m_action
== actionClickButton
)
3554 m_hover_button
= NULL
;
3555 m_frame
->ReleaseMouse();
3556 UpdateButtonOnScreen(m_action_part
, event
);
3558 // make sure we're still over the item that was originally clicked
3559 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3561 // fire button-click event
3562 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3563 e
.SetPane(m_action_part
->pane
);
3564 e
.SetButton(m_action_part
->button
->button_id
);
3568 else if (m_action
== actionClickCaption
)
3570 m_frame
->ReleaseMouse();
3572 else if (m_action
== actionDragFloatingPane
)
3574 m_frame
->ReleaseMouse();
3576 else if (m_action
== actionDragToolbarPane
)
3578 m_frame
->ReleaseMouse();
3580 wxPaneInfo
& pane
= GetPane(m_action_window
);
3581 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3583 // save the new positions
3584 wxDockInfoPtrArray docks
;
3585 FindDocks(m_docks
, pane
.dock_direction
,
3586 pane
.dock_layer
, pane
.dock_row
, docks
);
3587 if (docks
.GetCount() == 1)
3589 wxDockInfo
& dock
= *docks
.Item(0);
3591 wxArrayInt pane_positions
, pane_sizes
;
3592 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3594 int i
, dock_pane_count
= dock
.panes
.GetCount();
3595 for (i
= 0; i
< dock_pane_count
; ++i
)
3596 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3599 pane
.state
&= ~wxPaneInfo::actionPane
;
3607 m_action
= actionNone
;
3608 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3612 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3614 // sometimes when Update() is called from inside this method,
3615 // a spurious mouse move event is generated; this check will make
3616 // sure that only real mouse moves will get anywhere in this method;
3617 // this appears to be a bug somewhere, and I don't know where the
3618 // mouse move event is being generated. only verified on MSW
3620 wxPoint mouse_pos
= event
.GetPosition();
3621 if (m_last_mouse_move
== mouse_pos
)
3623 m_last_mouse_move
= mouse_pos
;
3626 if (m_action
== actionResize
)
3628 wxPoint pos
= m_action_part
->rect
.GetPosition();
3629 if (m_action_part
->orientation
== wxHORIZONTAL
)
3630 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3632 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3634 wxRect
rect(m_frame
->ClientToScreen(pos
),
3635 m_action_part
->rect
.GetSize());
3638 if (!m_action_hintrect
.IsEmpty())
3639 DrawResizeHint(dc
, m_action_hintrect
);
3640 DrawResizeHint(dc
, rect
);
3641 m_action_hintrect
= rect
;
3643 else if (m_action
== actionClickCaption
)
3645 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3646 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3648 // caption has been clicked. we need to check if the mouse
3649 // is now being dragged. if it is, we need to change the
3650 // mouse action to 'drag'
3651 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3652 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3654 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3656 if (!pane_info
->IsToolbar())
3658 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3659 pane_info
->IsFloatable())
3661 m_action
= actionDragFloatingPane
;
3663 // set initial float position
3664 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3665 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3666 pt
.y
- m_action_offset
.y
);
3671 m_action_window
= pane_info
->frame
;
3673 // action offset is used here to make it feel "natural" to the user
3674 // to drag a docked pane and suddenly have it become a floating frame.
3675 // Sometimes, however, the offset where the user clicked on the docked
3676 // caption is bigger than the width of the floating frame itself, so
3677 // in that case we need to set the action offset to a sensible value
3678 wxSize frame_size
= m_action_window
->GetSize();
3679 if (frame_size
.x
<= m_action_offset
.x
)
3680 m_action_offset
.x
= 30;
3685 m_action
= actionDragToolbarPane
;
3686 m_action_window
= pane_info
->window
;
3690 else if (m_action
== actionDragFloatingPane
)
3692 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3693 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3694 pt
.y
- m_action_offset
.y
);
3696 else if (m_action
== actionDragToolbarPane
)
3698 wxPaneInfo
& pane
= GetPane(m_action_window
);
3699 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3701 pane
.state
|= wxPaneInfo::actionPane
;
3703 wxPoint pt
= event
.GetPosition();
3704 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3706 // if DoDrop() decided to float the pane, set up
3707 // the floating pane's initial position
3708 if (pane
.IsFloating())
3710 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3711 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3712 pt
.y
- m_action_offset
.y
);
3715 // this will do the actiual move operation;
3716 // in the case that the pane has been floated,
3717 // this call will create the floating pane
3718 // and do the reparenting
3721 // if the pane has been floated, change the mouse
3722 // action actionDragFloatingPane so that subsequent
3723 // EVT_MOTION() events will move the floating pane
3724 if (pane
.IsFloating())
3726 pane
.state
&= ~wxPaneInfo::actionPane
;
3727 m_action
= actionDragFloatingPane
;
3728 m_action_window
= pane
.frame
;
3733 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3734 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3736 if (part
!= m_hover_button
)
3738 // make the old button normal
3740 UpdateButtonOnScreen(m_hover_button
, event
);
3742 // mouse is over a button, so repaint the
3743 // button in hover mode
3744 UpdateButtonOnScreen(part
, event
);
3745 m_hover_button
= part
;
3752 m_hover_button
= NULL
;
3763 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3767 m_hover_button
= NULL
;
3772 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3774 // when a child pane has it's focus set, we should change the
3775 // pane's active state to reflect this. (this is only true if
3776 // active panes are allowed by the owner)
3777 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3779 if (GetPane(event
.GetWindow()).IsOk())
3781 SetActivePane(m_panes
, event
.GetWindow());
3790 // OnPaneButton() is an event handler that is called
3791 // when a pane button has been pressed.
3792 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& evt
)
3794 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3796 wxPaneInfo
& pane
= *(evt
.pane
);
3798 if (evt
.button
== wxPaneInfo::buttonClose
)
3800 // fire pane close event
3801 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3802 e
.SetPane(evt
.pane
);
3811 else if (evt
.button
== wxPaneInfo::buttonPin
)
3813 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&