1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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/log.h"
36 //#include "wx/dcbuffer.h"
38 #include "wx/dcclient.h"
39 #include "wx/dcscreen.h"
42 #include "wx/settings.h"
43 #include "wx/toolbar.h"
49 WX_CHECK_BUILD_OPTIONS("wxAUI")
51 #include "wx/arrimpl.cpp"
52 WX_DECLARE_OBJARRAY(wxRect
, wxAuiRectArray
);
53 WX_DEFINE_OBJARRAY(wxAuiRectArray
)
54 WX_DEFINE_OBJARRAY(wxDockUIPartArray
)
55 WX_DEFINE_OBJARRAY(wxDockInfoArray
)
56 WX_DEFINE_OBJARRAY(wxPaneButtonArray
)
57 WX_DEFINE_OBJARRAY(wxPaneInfoArray
)
59 wxPaneInfo wxNullPaneInfo
;
60 wxDockInfo wxNullDockInfo
;
61 DEFINE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON
)
64 // a few defines to avoid nameclashes
65 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
67 #include "wx/mac/private.h"
71 // -- static utility functions --
73 static wxBitmap
wxPaneCreateStippleBitmap()
75 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
76 wxImage
img(2,2,data
,true);
80 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
82 wxBitmap stipple
= wxPaneCreateStippleBitmap();
83 wxBrush
brush(stipple
);
85 dc
.SetPen(*wxTRANSPARENT_PEN
);
87 dc
.SetLogicalFunction(wxXOR
);
88 dc
.DrawRectangle(rect
);
93 // on supported windows systems (Win2000 and greater), this function
94 // will make a frame window transparent by a certain amount
95 static void MakeWindowTransparent(wxWindow
* wnd
, int amount
)
97 // this API call is not in all SDKs, only the newer ones, so
98 // we will runtime bind this
99 typedef DWORD (WINAPI
*PSETLAYEREDWINDOWATTR
)(HWND
, DWORD
, BYTE
, DWORD
);
100 static PSETLAYEREDWINDOWATTR pSetLayeredWindowAttributes
= NULL
;
101 static HMODULE h
= NULL
;
102 HWND hwnd
= (HWND
)wnd
->GetHWND();
105 h
= LoadLibrary(_T("user32"));
107 if (!pSetLayeredWindowAttributes
)
109 pSetLayeredWindowAttributes
=
110 (PSETLAYEREDWINDOWATTR
)GetProcAddress(h
,"SetLayeredWindowAttributes");
113 if (pSetLayeredWindowAttributes
== NULL
)
116 LONG exstyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
117 if (0 == (exstyle
& 0x80000) /*WS_EX_LAYERED*/)
118 SetWindowLong(hwnd
, GWL_EXSTYLE
, exstyle
| 0x80000 /*WS_EX_LAYERED*/);
120 pSetLayeredWindowAttributes(hwnd
, 0, amount
, 2 /*LWA_ALPHA*/);
126 // CopyDocksAndPanes() - this utility function creates copies of
127 // the dock and pane info. wxDockInfo's usually contain pointers
128 // to wxPaneInfo classes, thus this function is necessary to reliably
129 // reconstruct that relationship in the new dock info and pane info arrays
131 static void CopyDocksAndPanes(wxDockInfoArray
& dest_docks
,
132 wxPaneInfoArray
& dest_panes
,
133 const wxDockInfoArray
& src_docks
,
134 const wxPaneInfoArray
& src_panes
)
136 dest_docks
= src_docks
;
137 dest_panes
= src_panes
;
138 int i
, j
, k
, dock_count
, pc1
, pc2
;
139 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
141 wxDockInfo
& dock
= dest_docks
.Item(i
);
142 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
143 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
144 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
145 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
149 // GetMaxLayer() is an internal function which returns
150 // the highest layer inside the specified dock
151 static int GetMaxLayer(const wxDockInfoArray
& docks
, int dock_direction
)
153 int i
, dock_count
, max_layer
= 0;
154 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
156 wxDockInfo
& dock
= docks
.Item(i
);
157 if (dock
.dock_direction
== dock_direction
&&
158 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
159 max_layer
= dock
.dock_layer
;
165 // GetMaxRow() is an internal function which returns
166 // the highest layer inside the specified dock
167 static int GetMaxRow(const wxPaneInfoArray
& panes
, int direction
, int layer
)
169 int i
, pane_count
, max_row
= 0;
170 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
172 wxPaneInfo
& pane
= panes
.Item(i
);
173 if (pane
.dock_direction
== direction
&&
174 pane
.dock_layer
== layer
&&
175 pane
.dock_row
> max_row
)
176 max_row
= pane
.dock_row
;
183 // DoInsertDockLayer() is an internal function that inserts a new dock
184 // layer by incrementing all existing dock layer values by one
185 static void DoInsertDockLayer(wxPaneInfoArray
& panes
,
190 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
192 wxPaneInfo
& pane
= panes
.Item(i
);
193 if (!pane
.IsFloating() &&
194 pane
.dock_direction
== dock_direction
&&
195 pane
.dock_layer
>= dock_layer
)
200 // DoInsertDockLayer() is an internal function that inserts a new dock
201 // row by incrementing all existing dock row values by one
202 static void DoInsertDockRow(wxPaneInfoArray
& panes
,
208 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
210 wxPaneInfo
& pane
= panes
.Item(i
);
211 if (!pane
.IsFloating() &&
212 pane
.dock_direction
== dock_direction
&&
213 pane
.dock_layer
== dock_layer
&&
214 pane
.dock_row
>= dock_row
)
219 // DoInsertDockLayer() is an internal function that inserts a space for
220 // another dock pane by incrementing all existing dock row values by one
221 static void DoInsertPane(wxPaneInfoArray
& panes
,
228 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
230 wxPaneInfo
& pane
= panes
.Item(i
);
231 if (!pane
.IsFloating() &&
232 pane
.dock_direction
== dock_direction
&&
233 pane
.dock_layer
== dock_layer
&&
234 pane
.dock_row
== dock_row
&&
235 pane
.dock_pos
>= dock_pos
)
240 // FindDocks() is an internal function that returns a list of docks which meet
241 // the specified conditions in the parameters and returns a sorted array
242 // (sorted by layer and then row)
243 static void FindDocks(wxDockInfoArray
& docks
,
247 wxDockInfoPtrArray
& arr
)
249 int begin_layer
= dock_layer
;
250 int end_layer
= dock_layer
;
251 int begin_row
= dock_row
;
252 int end_row
= dock_row
;
253 int dock_count
= docks
.GetCount();
254 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
256 // discover the maximum dock layer and the max row
257 for (i
= 0; i
< dock_count
; ++i
)
259 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
260 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
263 // if no dock layer was specified, search all dock layers
264 if (dock_layer
== -1)
267 end_layer
= max_layer
;
270 // if no dock row was specified, search all dock row
279 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
280 for (row
= begin_row
; row
<= end_row
; ++row
)
281 for (i
= 0; i
< dock_count
; ++i
)
283 wxDockInfo
& d
= docks
.Item(i
);
284 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
286 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
292 // FindPaneInDock() looks up a specified window pointer inside a dock.
293 // If found, the corresponding wxPaneInfo pointer is returned, otherwise NULL.
294 static wxPaneInfo
* FindPaneInDock(const wxDockInfo
& dock
, wxWindow
* window
)
296 int i
, count
= dock
.panes
.GetCount();
297 for (i
= 0; i
< count
; ++i
)
299 wxPaneInfo
* p
= dock
.panes
.Item(i
);
300 if (p
->window
== window
)
306 // RemovePaneFromDocks() removes a pane window from all docks
307 // with a possible exception specified by parameter "except"
308 static void RemovePaneFromDocks(wxDockInfoArray
& docks
,
310 wxDockInfo
* except
= NULL
)
313 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
315 wxDockInfo
& d
= docks
.Item(i
);
318 wxPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
324 // RenumberDockRows() takes a dock and assigns sequential numbers
325 // to existing rows. Basically it takes out the gaps; so if a
326 // dock has rows with numbers 0,2,5, they will become 0,1,2
327 static void RenumberDockRows(wxDockInfoPtrArray
& docks
)
329 int i
, dock_count
, j
, pane_count
;
330 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
332 wxDockInfo
& dock
= *docks
.Item(i
);
334 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
335 dock
.panes
.Item(j
)->dock_row
= i
;
341 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
344 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
346 wxPaneInfo
& pane
= panes
.Item(i
);
347 pane
.state
&= ~wxPaneInfo::optionActive
;
348 if (pane
.window
== active_pane
)
349 pane
.state
|= wxPaneInfo::optionActive
;
354 // this function is used to sort panes by dock position
355 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
357 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
361 // -- wxFrameManager class implementation --
364 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
365 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
366 EVT_PAINT(wxFrameManager::OnPaint
)
367 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
368 EVT_SIZE(wxFrameManager::OnSize
)
369 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
370 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
371 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
372 EVT_MOTION(wxFrameManager::OnMotion
)
373 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
374 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
375 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
379 wxFrameManager::wxFrameManager(wxFrame
* frame
, unsigned int flags
)
381 m_action
= actionNone
;
382 m_last_mouse_move
= wxPoint();
383 m_hover_button
= NULL
;
384 m_art
= new wxDefaultDockArt
;
394 wxFrameManager::~wxFrameManager()
399 // GetPane() looks up a wxPaneInfo structure based
400 // on the supplied window pointer. Upon failure, GetPane()
401 // returns an empty wxPaneInfo, a condition which can be checked
402 // by calling wxPaneInfo::IsOk().
404 // The pane info's structure may then be modified. Once a pane's
405 // info is modified, wxFrameManager::Update() must be called to
406 // realize the changes in the UI.
408 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
411 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
413 wxPaneInfo
& p
= m_panes
.Item(i
);
414 if (p
.window
== window
)
417 return wxNullPaneInfo
;
420 // this version of GetPane() looks up a pane based on a
421 // 'pane name', see above comment for more info
422 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
425 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
427 wxPaneInfo
& p
= m_panes
.Item(i
);
431 return wxNullPaneInfo
;
434 // GetAllPanes() returns a reference to all the pane info structures
435 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
440 // HitTest() is an internal function which determines
441 // which UI item the specified coordinates are over
442 // (x,y) specify a position in client coordinates
443 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
445 wxDockUIPart
* result
= NULL
;
448 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
450 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
452 // we are not interested in typeDock, because this space
453 // isn't used to draw anything, just for measurements;
454 // besides, the entire dock area is covered with other
455 // rectangles, which we are interested in.
456 if (item
->type
== wxDockUIPart::typeDock
)
459 // if we already have a hit on a more specific item, we are not
460 // interested in a pane hit. If, however, we don't already have
461 // a hit, returning a pane hit is necessary for some operations
462 if ((item
->type
== wxDockUIPart::typePane
||
463 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
466 // if the point is inside the rectangle, we have a hit
467 if (item
->rect
.Inside(x
,y
))
475 // SetFlags() and GetFlags() allow the owner to set various
476 // options which are global to wxFrameManager
477 void wxFrameManager::SetFlags(unsigned int flags
)
482 unsigned int wxFrameManager::GetFlags() const
488 // SetFrame() is usually called once when the frame
489 // manager class is being initialized. "frame" specifies
490 // the frame which should be managed by the frame mananger
491 void wxFrameManager::SetFrame(wxFrame
* frame
)
493 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
496 m_frame
->PushEventHandler(this);
499 // if the owner is going to manage an MDI parent frame,
500 // we need to add the MDI client window as the default
503 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
505 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
506 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
508 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
510 AddPane(client_window
,
511 wxPaneInfo().Name(wxT("mdiclient")).
512 CenterPane().PaneBorder(false));
518 // UnInit() must be called, usually in the destructor
519 // of the frame class. If it is not called, usually this
520 // will result in a crash upon program exit
521 void wxFrameManager::UnInit()
523 m_frame
->RemoveEventHandler(this);
526 // GetFrame() returns the frame pointer being managed by wxFrameManager
527 wxFrame
* wxFrameManager::GetFrame() const
532 wxDockArt
* wxFrameManager::GetArtProvider() const
537 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
539 // first, give the owner frame a chance to override
542 if (m_frame
->ProcessEvent(event
))
549 // SetArtProvider() instructs wxFrameManager to use the
550 // specified art provider for all drawing calls. This allows
551 // plugable look-and-feel features
552 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
554 // delete the last art provider, if any
557 // assign the new art provider
558 m_art
= art_provider
;
561 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
563 // check if the pane has a valid window
567 // check if the pane already exists
568 if (GetPane(pane_info
.window
).IsOk())
571 m_panes
.Add(pane_info
);
573 wxPaneInfo
& pinfo
= m_panes
.Last();
575 // set the pane window
576 pinfo
.window
= window
;
578 // if the pane's name identifier is blank, create a random string
579 if (pinfo
.name
.IsEmpty())
581 pinfo
.name
.Printf(wxT("%08x%08x%08x%08x"),
582 ((unsigned long)pinfo
.window
) & 0xffffffff,
583 (unsigned int)time(NULL
),
584 (unsigned int)clock(), m_panes
.GetCount());
587 // set initial proportion (if not already set)
588 if (pinfo
.dock_proportion
== 0)
589 pinfo
.dock_proportion
= 100000;
591 if (pinfo
.HasCloseButton() &&
592 pinfo
.buttons
.size() == 0)
595 button
.button_id
= wxPaneInfo::buttonClose
;
596 pinfo
.buttons
.Add(button
);
599 if (pinfo
.best_size
== wxDefaultSize
&&
602 pinfo
.best_size
= pinfo
.window
->GetClientSize();
604 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
606 // GetClientSize() doesn't get the best size for
607 // a toolbar under some newer versions of wxWidgets,
608 // so use GetBestSize()
609 pinfo
.best_size
= pinfo
.window
->GetBestSize();
611 // for some reason, wxToolBar::GetBestSize() is returning
612 // a size that is a pixel shy of the correct amount.
613 // I believe this to be the correct action, until
614 // wxToolBar::GetBestSize() is fixed. Is this assumption
619 if (pinfo
.min_size
!= wxDefaultSize
)
621 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
622 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
623 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
624 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
631 bool wxFrameManager::AddPane(wxWindow
* window
,
633 const wxString
& caption
)
636 pinfo
.Caption(caption
);
639 case wxTOP
: pinfo
.Top(); break;
640 case wxBOTTOM
: pinfo
.Bottom(); break;
641 case wxLEFT
: pinfo
.Left(); break;
642 case wxRIGHT
: pinfo
.Right(); break;
643 case wxCENTER
: pinfo
.CenterPane(); break;
645 return AddPane(window
, pinfo
);
648 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
651 // shift the panes around, depending on the insert level
652 switch (insert_level
)
654 case wxAUI_INSERT_PANE
:
655 DoInsertPane(m_panes
,
656 pane_info
.dock_direction
,
657 pane_info
.dock_layer
,
661 case wxAUI_INSERT_ROW
:
662 DoInsertDockRow(m_panes
,
663 pane_info
.dock_direction
,
664 pane_info
.dock_layer
,
667 case wxAUI_INSERT_DOCK
:
668 DoInsertDockLayer(m_panes
,
669 pane_info
.dock_direction
,
670 pane_info
.dock_layer
);
674 // if the window already exists, we are basically just moving/inserting the
675 // existing window. If it doesn't exist, we need to add it and insert it
676 wxPaneInfo
& existing_pane
= GetPane(window
);
677 if (!existing_pane
.IsOk())
679 return AddPane(window
, pane_info
);
683 if (pane_info
.IsFloating())
685 existing_pane
.Float();
686 if (pane_info
.floating_pos
!= wxDefaultPosition
)
687 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
688 if (pane_info
.floating_size
!= wxDefaultSize
)
689 existing_pane
.FloatingSize(pane_info
.floating_size
);
693 existing_pane
.Direction(pane_info
.dock_direction
);
694 existing_pane
.Layer(pane_info
.dock_layer
);
695 existing_pane
.Row(pane_info
.dock_row
);
696 existing_pane
.Position(pane_info
.dock_pos
);
704 bool wxFrameManager::DetachPane(wxWindow
* window
)
707 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
709 wxPaneInfo
& p
= m_panes
.Item(i
);
710 if (p
.window
== window
)
714 // we have a floating frame which is being detached. We need to
715 // reparent it to m_frame and destroy the floating frame
718 p
.window
->SetSize(1,1);
719 p
.frame
->Show(false);
721 // reparent to m_frame and destroy the pane
722 p
.window
->Reparent(m_frame
);
723 p
.frame
->SetSizer(NULL
);
735 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
736 // in the input string. This is an internal functions which is
737 // used for saving perspectives
738 static wxString
EscapeDelimiters(const wxString
& s
)
741 result
.Alloc(s
.Length());
742 const wxChar
* ch
= s
.c_str();
745 if (*ch
== wxT(';') || *ch
== wxT('|'))
754 // SavePerspective() saves all pane information as a single string.
755 // This string may later be fed into LoadPerspective() to restore
756 // all pane settings. This save and load mechanism allows an
757 // exact pane configuration to be saved and restored at a later time
759 wxString
wxFrameManager::SavePerspective()
763 result
= wxT("layout1|");
765 int pane_i
, pane_count
= m_panes
.GetCount();
766 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
768 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
770 result
+= wxT("name=");
771 result
+= EscapeDelimiters(pane
.name
);
774 result
+= wxT("caption=");
775 result
+= EscapeDelimiters(pane
.caption
);
778 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
779 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
780 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
781 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
782 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
783 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
784 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
785 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
786 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
787 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
788 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
789 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
790 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
791 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
792 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
793 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
797 int dock_i
, dock_count
= m_docks
.GetCount();
798 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
800 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
802 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
803 dock
.dock_direction
, dock
.dock_layer
,
804 dock
.dock_row
, dock
.size
);
810 // LoadPerspective() loads a layout which was saved with SavePerspective()
811 // If the "update" flag parameter is true, the GUI will immediately be updated
813 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
815 wxString input
= layout
;
818 // check layout string version
819 part
= input
.BeforeFirst(wxT('|'));
820 input
= input
.AfterFirst(wxT('|'));
823 if (part
!= wxT("layout1"))
827 // mark all panes currently managed as docked and hidden
828 int pane_i
, pane_count
= m_panes
.GetCount();
829 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
830 m_panes
.Item(pane_i
).Dock().Hide();
832 // clear out the dock array; this will be reconstructed
835 // replace escaped characters so we can
836 // split up the string easily
837 input
.Replace(wxT("\\|"), wxT("\a"));
838 input
.Replace(wxT("\\;"), wxT("\b"));
844 wxString pane_part
= input
.BeforeFirst(wxT('|'));
845 input
= input
.AfterFirst(wxT('|'));
846 pane_part
.Trim(true);
848 // if the string is empty, we're done parsing
849 if (pane_part
.IsEmpty())
853 if (pane_part
.Left(9) == wxT("dock_size"))
855 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
856 wxString value
= pane_part
.AfterFirst(wxT('='));
858 long dir
, layer
, row
, size
;
859 wxString piece
= val_name
.AfterFirst(wxT('('));
860 piece
= piece
.BeforeLast(wxT(')'));
861 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
862 piece
= piece
.AfterFirst(wxT(','));
863 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
864 piece
.AfterFirst(wxT(',')).ToLong(&row
);
868 dock
.dock_direction
= dir
;
869 dock
.dock_layer
= layer
;
878 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
879 pane_part
= pane_part
.AfterFirst(wxT(';'));
880 wxString val_name
= val_part
.BeforeFirst(wxT('='));
881 wxString value
= val_part
.AfterFirst(wxT('='));
882 val_name
.MakeLower();
884 val_name
.Trim(false);
888 if (val_name
.IsEmpty())
891 if (val_name
== wxT("name"))
893 else if (val_name
== wxT("caption"))
894 pane
.caption
= value
;
895 else if (val_name
== wxT("state"))
896 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
897 else if (val_name
== wxT("dir"))
898 pane
.dock_direction
= wxAtoi(value
.c_str());
899 else if (val_name
== wxT("layer"))
900 pane
.dock_layer
= wxAtoi(value
.c_str());
901 else if (val_name
== wxT("row"))
902 pane
.dock_row
= wxAtoi(value
.c_str());
903 else if (val_name
== wxT("pos"))
904 pane
.dock_pos
= wxAtoi(value
.c_str());
905 else if (val_name
== wxT("prop"))
906 pane
.dock_proportion
= wxAtoi(value
.c_str());
907 else if (val_name
== wxT("bestw"))
908 pane
.best_size
.x
= wxAtoi(value
.c_str());
909 else if (val_name
== wxT("besth"))
910 pane
.best_size
.y
= wxAtoi(value
.c_str());
911 else if (val_name
== wxT("minw"))
912 pane
.min_size
.x
= wxAtoi(value
.c_str());
913 else if (val_name
== wxT("minh"))
914 pane
.min_size
.y
= wxAtoi(value
.c_str());
915 else if (val_name
== wxT("maxw"))
916 pane
.max_size
.x
= wxAtoi(value
.c_str());
917 else if (val_name
== wxT("maxh"))
918 pane
.max_size
.y
= wxAtoi(value
.c_str());
919 else if (val_name
== wxT("floatx"))
920 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
921 else if (val_name
== wxT("floaty"))
922 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
923 else if (val_name
== wxT("floatw"))
924 pane
.floating_size
.x
= wxAtoi(value
.c_str());
925 else if (val_name
== wxT("floath"))
926 pane
.floating_size
.y
= wxAtoi(value
.c_str());
928 wxFAIL_MSG(wxT("Bad Perspective String"));
932 // replace escaped characters so we can
933 // split up the string easily
934 pane
.name
.Replace(wxT("\a"), wxT("|"));
935 pane
.name
.Replace(wxT("\b"), wxT(";"));
936 pane
.caption
.Replace(wxT("\a"), wxT("|"));
937 pane
.caption
.Replace(wxT("\b"), wxT(";"));
939 wxPaneInfo
& p
= GetPane(pane
.name
);
942 // the pane window couldn't be found
943 // in the existing layout
947 pane
.window
= p
.window
;
948 pane
.frame
= p
.frame
;
949 pane
.buttons
= p
.buttons
;
960 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
961 wxArrayInt
& positions
,
964 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
965 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
966 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
971 int offset
, action_pane
= -1;
972 int pane_i
, pane_count
= dock
.panes
.GetCount();
974 // find the pane marked as our action pane
975 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
977 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
979 if (pane
.state
& wxPaneInfo::actionPane
)
981 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
982 action_pane
= pane_i
;
986 // set up each panes default position, and
987 // determine the size (width or height, depending
988 // on the dock's orientation) of each pane
989 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
991 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
992 positions
.Add(pane
.dock_pos
);
995 if (pane
.HasBorder())
996 size
+= (pane_border_size
*2);
998 if (dock
.IsHorizontal())
1000 if (pane
.HasGripper() && !pane
.HasGripperTop())
1001 size
+= gripper_size
;
1002 size
+= pane
.best_size
.x
;
1006 if (pane
.HasGripper() && pane
.HasGripperTop())
1007 size
+= gripper_size
;
1009 if (pane
.HasCaption())
1010 size
+= caption_size
;
1011 size
+= pane
.best_size
.y
;
1017 // if there is no action pane, just return the default
1018 // positions (as specified in pane.pane_pos)
1019 if (action_pane
== -1)
1023 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1025 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1030 positions
[pane_i
] -= -amount
;
1032 offset
+= sizes
[pane_i
];
1035 // if the dock mode is fixed, make sure none of the panes
1036 // overlap; we will bump panes that overlap
1038 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1040 int amount
= positions
[pane_i
] - offset
;
1044 positions
[pane_i
] += -amount
;
1046 offset
+= sizes
[pane_i
];
1051 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1054 wxDockUIPartArray
& uiparts
,
1058 wxSizerItem
* sizer_item
;
1060 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1061 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1062 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1063 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1065 // find out the orientation of the item (orientation for panes
1066 // is the same as the dock's orientation)
1068 if (dock
.IsHorizontal())
1069 orientation
= wxHORIZONTAL
;
1071 orientation
= wxVERTICAL
;
1073 // this variable will store the proportion
1074 // value that the pane will receive
1075 int pane_proportion
= pane
.dock_proportion
;
1077 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1078 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1080 if (pane
.HasGripper())
1082 if (pane
.HasGripperTop())
1083 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1085 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1087 part
.type
= wxDockUIPart::typeGripper
;
1091 part
.orientation
= orientation
;
1092 part
.cont_sizer
= horz_pane_sizer
;
1093 part
.sizer_item
= sizer_item
;
1097 if (pane
.HasCaption())
1099 // create the caption sizer
1100 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1102 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1104 part
.type
= wxDockUIPart::typeCaption
;
1108 part
.orientation
= orientation
;
1109 part
.cont_sizer
= vert_pane_sizer
;
1110 part
.sizer_item
= sizer_item
;
1111 int caption_part_idx
= uiparts
.GetCount();
1114 // add pane buttons to the caption
1115 int i
, button_count
;
1116 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1117 i
< button_count
; ++i
)
1119 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1121 sizer_item
= caption_sizer
->Add(pane_button_size
,
1125 part
.type
= wxDockUIPart::typePaneButton
;
1128 part
.button
= &button
;
1129 part
.orientation
= orientation
;
1130 part
.cont_sizer
= caption_sizer
;
1131 part
.sizer_item
= sizer_item
;
1135 // add the caption sizer
1136 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1138 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1141 // add the pane window itself
1144 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1148 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1149 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1152 part
.type
= wxDockUIPart::typePane
;
1156 part
.orientation
= orientation
;
1157 part
.cont_sizer
= vert_pane_sizer
;
1158 part
.sizer_item
= sizer_item
;
1162 // determine if the pane should have a minimum size; if the pane is
1163 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1164 // if the pane.min_size is set, we must use that value as well
1166 wxSize min_size
= pane
.min_size
;
1169 if (min_size
== wxDefaultSize
)
1171 min_size
= pane
.best_size
;
1172 pane_proportion
= 0;
1176 if (min_size
!= wxDefaultSize
)
1178 vert_pane_sizer
->SetItemMinSize(
1179 vert_pane_sizer
->GetChildren().GetCount()-1,
1180 min_size
.x
, min_size
.y
);
1184 // add the verticle sizer (caption, pane window) to the
1185 // horizontal sizer (gripper, verticle sizer)
1186 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1188 // finally, add the pane sizer to the dock sizer
1190 if (pane
.HasBorder())
1192 // allowing space for the pane's border
1193 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1194 wxEXPAND
| wxALL
, pane_border_size
);
1196 part
.type
= wxDockUIPart::typePaneBorder
;
1200 part
.orientation
= orientation
;
1201 part
.cont_sizer
= cont
;
1202 part
.sizer_item
= sizer_item
;
1207 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1211 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1213 wxDockUIPartArray
& uiparts
,
1216 wxSizerItem
* sizer_item
;
1219 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1220 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1222 // resizable bottom and right docks have a sash before them
1223 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1224 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1226 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1228 part
.type
= wxDockUIPart::typeDockSizer
;
1229 part
.orientation
= orientation
;
1233 part
.cont_sizer
= cont
;
1234 part
.sizer_item
= sizer_item
;
1238 // create the sizer for the dock
1239 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1241 // add each pane to the dock
1242 int pane_i
, pane_count
= dock
.panes
.GetCount();
1246 wxArrayInt pane_positions
, pane_sizes
;
1248 // figure out the real pane positions we will
1249 // use, without modifying the each pane's pane_pos member
1250 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1253 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1255 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1256 int pane_pos
= pane_positions
.Item(pane_i
);
1258 int amount
= pane_pos
- offset
;
1261 if (dock
.IsVertical())
1262 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1264 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1266 part
.type
= wxDockUIPart::typeBackground
;
1270 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1271 part
.cont_sizer
= dock_sizer
;
1272 part
.sizer_item
= sizer_item
;
1278 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1280 offset
+= pane_sizes
.Item(pane_i
);
1283 // at the end add a very small stretchable background area
1284 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1286 part
.type
= wxDockUIPart::typeBackground
;
1290 part
.orientation
= orientation
;
1291 part
.cont_sizer
= dock_sizer
;
1292 part
.sizer_item
= sizer_item
;
1297 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1299 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1301 // if this is not the first pane being added,
1302 // we need to add a pane sizer
1305 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1307 part
.type
= wxDockUIPart::typePaneSizer
;
1309 part
.pane
= dock
.panes
.Item(pane_i
-1);
1311 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1312 part
.cont_sizer
= dock_sizer
;
1313 part
.sizer_item
= sizer_item
;
1317 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1321 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1322 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1324 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1326 part
.type
= wxDockUIPart::typeDock
;
1330 part
.orientation
= orientation
;
1331 part
.cont_sizer
= cont
;
1332 part
.sizer_item
= sizer_item
;
1335 if (dock
.IsHorizontal())
1336 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1338 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1340 // top and left docks have a sash after them
1341 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1342 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1344 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1346 part
.type
= wxDockUIPart::typeDockSizer
;
1350 part
.orientation
= orientation
;
1351 part
.cont_sizer
= cont
;
1352 part
.sizer_item
= sizer_item
;
1357 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1358 wxDockInfoArray
& docks
,
1359 wxDockUIPartArray
& uiparts
,
1362 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1364 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1365 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1366 wxSize cli_size
= m_frame
->GetClientSize();
1367 int i
, dock_count
, pane_count
;
1370 // empty all docks out
1371 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1372 docks
.Item(i
).panes
.Empty();
1374 // iterate through all known panes, filing each
1375 // of them into the appropriate dock. If the
1376 // pane does not exist in the dock, add it
1377 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1379 wxPaneInfo
& p
= panes
.Item(i
);
1381 // find any docks in this layer
1383 wxDockInfoPtrArray arr
;
1384 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1386 if (arr
.GetCount() > 0)
1392 // dock was not found, so we need to create a new one
1394 d
.dock_direction
= p
.dock_direction
;
1395 d
.dock_layer
= p
.dock_layer
;
1396 d
.dock_row
= p
.dock_row
;
1398 dock
= &docks
.Last();
1402 if (p
.IsDocked() && p
.IsShown())
1404 // remove the pane from any existing docks except this one
1405 RemovePaneFromDocks(docks
, p
, dock
);
1407 // pane needs to be added to the dock,
1408 // if it doesn't already exist
1409 if (!FindPaneInDock(*dock
, p
.window
))
1410 dock
->panes
.Add(&p
);
1414 // remove the pane from any existing docks
1415 RemovePaneFromDocks(docks
, p
);
1420 // remove any empty docks
1421 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1423 if (docks
.Item(i
).panes
.GetCount() == 0)
1427 // configure the docks further
1428 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1430 wxDockInfo
& dock
= docks
.Item(i
);
1431 int j
, dock_pane_count
= dock
.panes
.GetCount();
1433 // sort the dock pane array by the pane's
1434 // dock position (dock_pos), in ascending order
1435 dock
.panes
.Sort(PaneSortFunc
);
1437 // for newly created docks, set up their initial size
1442 for (j
= 0; j
< dock_pane_count
; ++j
)
1444 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1445 wxSize pane_size
= pane
.best_size
;
1446 if (pane_size
== wxDefaultSize
)
1447 pane_size
= pane
.min_size
;
1448 if (pane_size
== wxDefaultSize
)
1449 pane_size
= pane
.window
->GetSize();
1451 if (dock
.IsHorizontal())
1452 size
= wxMax(pane_size
.y
, size
);
1454 size
= wxMax(pane_size
.x
, size
);
1457 // add space for the border (two times), but only
1458 // if at least one pane inside the dock has a pane border
1459 for (j
= 0; j
< dock_pane_count
; ++j
)
1461 if (dock
.panes
.Item(j
)->HasBorder())
1463 size
+= (pane_border_size
*2);
1468 // if pane is on the top or bottom, add the caption height,
1469 // but only if at least one pane inside the dock has a caption
1470 if (dock
.IsHorizontal())
1472 for (j
= 0; j
< dock_pane_count
; ++j
)
1474 if (dock
.panes
.Item(j
)->HasCaption())
1476 size
+= caption_size
;
1482 // new dock's size may not be more than 1/3 of the frame size
1483 if (dock
.IsHorizontal())
1484 size
= wxMin(size
, cli_size
.y
/3);
1486 size
= wxMin(size
, cli_size
.x
/3);
1494 // determine the dock's minimum size
1495 bool plus_border
= false;
1496 bool plus_caption
= false;
1497 int dock_min_size
= 0;
1498 for (j
= 0; j
< dock_pane_count
; ++j
)
1500 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1501 if (pane
.min_size
!= wxDefaultSize
)
1503 if (pane
.HasBorder())
1505 if (pane
.HasCaption())
1506 plus_caption
= true;
1507 if (dock
.IsHorizontal())
1509 if (pane
.min_size
.y
> dock_min_size
)
1510 dock_min_size
= pane
.min_size
.y
;
1514 if (pane
.min_size
.x
> dock_min_size
)
1515 dock_min_size
= pane
.min_size
.x
;
1521 dock_min_size
+= (pane_border_size
*2);
1522 if (plus_caption
&& dock
.IsHorizontal())
1523 dock_min_size
+= (caption_size
);
1525 dock
.min_size
= dock_min_size
;
1528 // if the pane's current size is less than it's
1529 // minimum, increase the dock's size to it's minimum
1530 if (dock
.size
< dock
.min_size
)
1531 dock
.size
= dock
.min_size
;
1534 // determine the dock's mode (fixed or proportional);
1535 // determine whether the dock has only toolbars
1536 bool action_pane_marked
= false;
1538 dock
.toolbar
= true;
1539 for (j
= 0; j
< dock_pane_count
; ++j
)
1541 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1542 if (!pane
.IsFixed())
1544 if (!pane
.IsToolbar())
1545 dock
.toolbar
= false;
1546 if (pane
.state
& wxPaneInfo::actionPane
)
1547 action_pane_marked
= true;
1551 // if the dock mode is proportional and not fixed-pixel,
1552 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1553 // e.g. remove gaps like 1, 2, 30, 500
1556 for (j
= 0; j
< dock_pane_count
; ++j
)
1558 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1563 // if the dock mode is fixed, and none of the panes
1564 // are being moved right now, make sure the panes
1565 // do not overlap each other. If they do, we will
1566 // adjust the panes' positions
1567 if (dock
.fixed
&& !action_pane_marked
)
1569 wxArrayInt pane_positions
, pane_sizes
;
1570 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1573 for (j
= 0; j
< dock_pane_count
; ++j
)
1575 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1576 pane
.dock_pos
= pane_positions
[j
];
1578 int amount
= pane
.dock_pos
- offset
;
1582 pane
.dock_pos
+= -amount
;
1584 offset
+= pane_sizes
[j
];
1589 // discover the maximum dock layer
1591 for (i
= 0; i
< dock_count
; ++i
)
1592 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1595 // clear out uiparts
1598 // create a bunch of box sizers,
1599 // from the innermost level outwards.
1600 wxSizer
* cont
= NULL
;
1601 wxSizer
* middle
= NULL
;
1605 for (layer
= 0; layer
<= max_layer
; ++layer
)
1607 wxDockInfoPtrArray arr
;
1609 // find any docks in this layer
1610 FindDocks(docks
, -1, layer
, -1, arr
);
1612 // if there aren't any, skip to the next layer
1616 wxSizer
* old_cont
= cont
;
1618 // create a container which will hold this layer's
1619 // docks (top, bottom, left, right)
1620 cont
= new wxBoxSizer(wxVERTICAL
);
1623 // find any top docks in this layer
1624 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1625 RenumberDockRows(arr
);
1628 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1629 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1633 // fill out the middle layer (which consists
1634 // of left docks, content area and right docks)
1636 middle
= new wxBoxSizer(wxHORIZONTAL
);
1638 // find any left docks in this layer
1639 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1640 RenumberDockRows(arr
);
1643 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1644 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1647 // add content dock (or previous layer's sizer
1651 // find any center docks
1652 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1655 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1656 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1660 // there are no center docks, add a background area
1661 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1663 part
.type
= wxDockUIPart::typeBackground
;
1667 part
.cont_sizer
= middle
;
1668 part
.sizer_item
= sizer_item
;
1674 middle
->Add(old_cont
, 1, wxEXPAND
);
1677 // find any right docks in this layer
1678 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1679 RenumberDockRows(arr
);
1682 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1683 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1686 cont
->Add(middle
, 1, wxEXPAND
);
1690 // find any bottom docks in this layer
1691 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1692 RenumberDockRows(arr
);
1695 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1696 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1703 // no sizer available, because there are no docks,
1704 // therefore we will create a simple background area
1705 cont
= new wxBoxSizer(wxVERTICAL
);
1706 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1708 part
.type
= wxDockUIPart::typeBackground
;
1712 part
.cont_sizer
= middle
;
1713 part
.sizer_item
= sizer_item
;
1717 container
->Add(cont
, 1, wxEXPAND
);
1722 // Update() updates the layout. Whenever changes are made to
1723 // one or more panes, this function should be called. It is the
1724 // external entry point for running the layout engine.
1726 void wxFrameManager::Update()
1729 int i
, pane_count
= m_panes
.GetCount();
1731 // delete old sizer first
1732 m_frame
->SetSizer(NULL
);
1734 // destroy floating panes which have been
1735 // redocked or are becoming non-floating
1736 for (i
= 0; i
< pane_count
; ++i
)
1738 wxPaneInfo
& p
= m_panes
.Item(i
);
1740 if (!p
.IsFloating() && p
.frame
)
1742 // because the pane is no longer in a floating, we need to
1743 // reparent it to m_frame and destroy the floating frame
1746 p
.window
->SetSize(1,1);
1747 p
.frame
->Show(false);
1749 // reparent to m_frame and destroy the pane
1750 p
.window
->Reparent(m_frame
);
1751 p
.frame
->SetSizer(NULL
);
1758 // create a layout for all of the panes
1759 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
1761 // hide or show panes as necessary,
1762 // and float panes as necessary
1763 for (i
= 0; i
< pane_count
; ++i
)
1765 wxPaneInfo
& p
= m_panes
.Item(i
);
1769 if (p
.frame
== NULL
)
1771 // we need to create a frame for this
1772 // pane, which has recently been floated
1773 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
1778 // on MSW, if the owner desires transparent dragging, and
1779 // the dragging is happening right now, then the floating
1780 // window should have this style by default
1782 if (m_action
== actionDragFloatingPane
&&
1783 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
1784 MakeWindowTransparent(frame
, 150);
1787 frame
->SetPaneWindow(p
);
1797 // frame already exists, make sure it's position
1798 // and size reflect the information in wxPaneInfo
1799 if (p
.frame
->GetPosition() != p
.floating_pos
)
1801 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
1802 -1, -1, wxSIZE_USE_EXISTING
);
1803 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
1806 p
.frame
->Show(p
.IsShown());
1811 p
.window
->Show(p
.IsShown());
1814 // if "active panes" are no longer allowed, clear
1815 // any optionActive values from the pane states
1816 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
1818 p
.state
&= ~wxPaneInfo::optionActive
;
1823 // keep track of the old window rectangles so we can
1824 // refresh those windows whose rect has changed
1825 wxAuiRectArray old_pane_rects
;
1826 for (i
= 0; i
< pane_count
; ++i
)
1829 wxPaneInfo
& p
= m_panes
.Item(i
);
1831 if (p
.window
&& p
.IsShown() && p
.IsDocked())
1834 old_pane_rects
.Add(r
);
1840 // apply the new sizer
1841 m_frame
->SetSizer(sizer
);
1842 m_frame
->SetAutoLayout(false);
1847 // now that the frame layout is done, we need to check
1848 // the new pane rectangles against the old rectangles that
1849 // we saved a few lines above here. If the rectangles have
1850 // changed, the corresponding panes must also be updated
1851 for (i
= 0; i
< pane_count
; ++i
)
1853 wxPaneInfo
& p
= m_panes
.Item(i
);
1854 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
1856 if (p
.rect
!= old_pane_rects
[i
])
1858 p
.window
->Refresh();
1867 // set frame's minimum size
1870 // N.B. More work needs to be done on frame minimum sizes;
1871 // this is some intresting code that imposes the minimum size,
1872 // but we may want to include a more flexible mechanism or
1873 // options for multiple minimum-size modes, e.g. strict or lax
1874 wxSize min_size = sizer->GetMinSize();
1875 wxSize frame_size = m_frame->GetSize();
1876 wxSize client_size = m_frame->GetClientSize();
1878 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
1879 min_size.y+frame_size.y-client_size.y );
1881 m_frame->SetMinSize(minframe_size);
1883 if (frame_size.x < minframe_size.x ||
1884 frame_size.y < minframe_size.y)
1885 sizer->Fit(m_frame);
1890 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
1891 // on the frame's main sizer, then measures all the various UI items
1892 // and updates their internal rectangles. This should always be called
1893 // instead of calling m_frame->Layout() directly
1895 void wxFrameManager::DoFrameLayout()
1900 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1902 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1904 // get the rectangle of the UI part
1905 // originally, this code looked like this:
1906 // part.rect = wxRect(part.sizer_item->GetPosition(),
1907 // part.sizer_item->GetSize());
1908 // this worked quite well, with one exception: the mdi
1909 // client window had a "deferred" size variable
1910 // that returned the wrong size. It looks like
1911 // a bug in wx, because the former size of the window
1912 // was being returned. So, we will retrieve the part's
1913 // rectangle via other means
1916 part
.rect
= part
.sizer_item
->GetRect();
1917 int flag
= part
.sizer_item
->GetFlag();
1918 int border
= part
.sizer_item
->GetBorder();
1921 part
.rect
.y
-= border
;
1922 part
.rect
.height
+= border
;
1926 part
.rect
.x
-= border
;
1927 part
.rect
.width
+= border
;
1929 if (flag
& wxBOTTOM
)
1930 part
.rect
.height
+= border
;
1932 part
.rect
.width
+= border
;
1935 if (part
.type
== wxDockUIPart::typeDock
)
1936 part
.dock
->rect
= part
.rect
;
1937 if (part
.type
== wxDockUIPart::typePane
)
1938 part
.pane
->rect
= part
.rect
;
1942 // GetPanePart() looks up the pane the pane border UI part (or the regular
1943 // pane part if there is no border). This allows the caller to get the exact
1944 // rectangle of the pane in question, including decorations like
1945 // caption and border (if any).
1947 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
1950 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1952 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1953 if (part
.type
== wxDockUIPart::typePaneBorder
&&
1954 part
.pane
&& part
.pane
->window
== wnd
)
1957 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1959 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1960 if (part
.type
== wxDockUIPart::typePane
&&
1961 part
.pane
&& part
.pane
->window
== wnd
)
1969 // GetDockPixelOffset() is an internal function which returns
1970 // a dock's offset in pixels from the left side of the window
1971 // (for horizontal docks) or from the top of the window (for
1972 // vertical docks). This value is necessary for calculating
1973 // fixel-pane/toolbar offsets when they are dragged.
1975 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
1977 // the only way to accurately calculate the dock's
1978 // offset is to actually run a theoretical layout
1980 int i
, part_count
, dock_count
;
1981 wxDockInfoArray docks
;
1982 wxPaneInfoArray panes
;
1983 wxDockUIPartArray uiparts
;
1984 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
1987 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
1988 wxSize client_size
= m_frame
->GetClientSize();
1989 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
1992 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
1994 wxDockUIPart
& part
= uiparts
.Item(i
);
1995 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
1996 part
.sizer_item
->GetSize());
1997 if (part
.type
== wxDockUIPart::typeDock
)
1998 part
.dock
->rect
= part
.rect
;
2003 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2005 wxDockInfo
& dock
= docks
.Item(i
);
2006 if (test
.dock_direction
== dock
.dock_direction
&&
2007 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2009 if (dock
.IsVertical())
2021 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2022 // if a dock operation is allowed, the new dock position is copied into
2023 // the target info. If the operation was allowed, the function returns true.
2025 static bool ProcessDockResult(wxPaneInfo
& target
,
2026 const wxPaneInfo
& new_pos
)
2028 bool allowed
= false;
2029 switch (new_pos
.dock_direction
)
2031 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2032 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2033 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2034 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2044 // DoDrop() is an important function. It basically takes a mouse position,
2045 // and determines where the pane's new position would be. If the pane is to be
2046 // dropped, it performs the drop operation using the specified dock and pane
2047 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2048 // scenario can be performed, giving precise coordinates for drop hints.
2049 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2050 // as parameters, the changes will be made to the main state arrays
2052 const int auiInsertRowPixels
= 10;
2053 const int auiNewRowPixels
= 40;
2054 const int auiLayerInsertPixels
= 40;
2055 const int auiLayerInsertOffset
= 5;
2057 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2058 wxPaneInfoArray
& panes
,
2061 const wxPoint
& offset
)
2063 wxSize cli_size
= m_frame
->GetClientSize();
2065 wxPaneInfo drop
= target
;
2068 // The result should always be shown
2072 // Check to see if the pane has been dragged outside of the window
2073 // (or near to the outside of the window), if so, dock it along the edge
2076 int layer_insert_offset
= auiLayerInsertOffset
;
2077 if (target
.IsToolbar())
2078 layer_insert_offset
= 0;
2080 if (pt
.x
< layer_insert_offset
&&
2081 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2083 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2084 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2085 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2089 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2090 return ProcessDockResult(target
, drop
);
2092 else if (pt
.y
< layer_insert_offset
&&
2093 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2095 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2096 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2097 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2101 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2102 return ProcessDockResult(target
, drop
);
2104 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2105 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2107 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2108 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2109 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2110 drop
.Dock().Right().
2113 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2114 return ProcessDockResult(target
, drop
);
2116 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2117 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2119 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2120 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2121 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2122 drop
.Dock().Bottom().
2125 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2126 return ProcessDockResult(target
, drop
);
2130 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2133 if (drop
.IsToolbar())
2135 if (!part
|| !part
->dock
)
2139 // calculate the offset from where the dock begins
2140 // to the point where the user dropped the pane
2141 int dock_drop_offset
= 0;
2142 if (part
->dock
->IsHorizontal())
2143 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2145 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2148 // toolbars may only be moved in and to fixed-pane docks,
2149 // otherwise we will try to float the pane. Also, the pane
2150 // should float if being dragged over center pane windows
2151 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2153 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2154 (drop
.IsFloatable() ||
2155 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2156 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2161 return ProcessDockResult(target
, drop
);
2165 Direction(part
->dock
->dock_direction
).
2166 Layer(part
->dock
->dock_layer
).
2167 Row(part
->dock
->dock_row
).
2168 Position(dock_drop_offset
);
2171 ((pt
.y
< part
->dock
->rect
.y
+ 2) && part
->dock
->IsHorizontal()) ||
2172 ((pt
.x
< part
->dock
->rect
.x
+ 2) && part
->dock
->IsVertical())
2173 ) && part
->dock
->panes
.GetCount() > 1)
2175 int row
= drop
.dock_row
;
2176 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2177 part
->dock
->dock_layer
,
2178 part
->dock
->dock_row
);
2179 drop
.dock_row
= row
;
2183 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2184 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2185 ) && part
->dock
->panes
.GetCount() > 1)
2187 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2188 part
->dock
->dock_layer
,
2189 part
->dock
->dock_row
+1);
2190 drop
.dock_row
= part
->dock
->dock_row
+1;
2193 return ProcessDockResult(target
, drop
);
2202 if (part
->type
== wxDockUIPart::typePaneBorder
||
2203 part
->type
== wxDockUIPart::typeCaption
||
2204 part
->type
== wxDockUIPart::typeGripper
||
2205 part
->type
== wxDockUIPart::typePaneButton
||
2206 part
->type
== wxDockUIPart::typePane
||
2207 part
->type
== wxDockUIPart::typePaneSizer
||
2208 part
->type
== wxDockUIPart::typeDockSizer
||
2209 part
->type
== wxDockUIPart::typeBackground
)
2211 if (part
->type
== wxDockUIPart::typeDockSizer
)
2213 if (part
->dock
->panes
.GetCount() != 1)
2215 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2222 // If a normal frame is being dragged over a toolbar, insert it
2223 // along the edge under the toolbar, but over all other panes.
2224 // (this could be done much better, but somehow factoring this
2225 // calculation with the one at the beginning of this function)
2226 if (part
->dock
&& part
->dock
->toolbar
)
2230 switch (part
->dock
->dock_direction
)
2232 case wxAUI_DOCK_LEFT
:
2233 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2234 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2235 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2237 case wxAUI_DOCK_TOP
:
2238 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2239 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2240 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2242 case wxAUI_DOCK_RIGHT
:
2243 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2244 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2245 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2247 case wxAUI_DOCK_BOTTOM
:
2248 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2249 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2250 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2254 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2257 Direction(part
->dock
->dock_direction
).
2258 Layer(layer
).Row(0).Position(0);
2259 return ProcessDockResult(target
, drop
);
2266 part
= GetPanePart(part
->pane
->window
);
2270 bool insert_dock_row
= false;
2271 int insert_row
= part
->pane
->dock_row
;
2272 int insert_dir
= part
->pane
->dock_direction
;
2273 int insert_layer
= part
->pane
->dock_layer
;
2275 switch (part
->pane
->dock_direction
)
2277 case wxAUI_DOCK_TOP
:
2278 if (pt
.y
>= part
->rect
.y
&&
2279 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2280 insert_dock_row
= true;
2282 case wxAUI_DOCK_BOTTOM
:
2283 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2284 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2285 insert_dock_row
= true;
2287 case wxAUI_DOCK_LEFT
:
2288 if (pt
.x
>= part
->rect
.x
&&
2289 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2290 insert_dock_row
= true;
2292 case wxAUI_DOCK_RIGHT
:
2293 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2294 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2295 insert_dock_row
= true;
2297 case wxAUI_DOCK_CENTER
:
2299 // "new row pixels" will be set to the default, but
2300 // must never exceed 20% of the window size
2301 int new_row_pixels_x
= auiNewRowPixels
;
2302 int new_row_pixels_y
= auiNewRowPixels
;
2304 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2305 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2307 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2308 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2311 // determine if the mouse pointer is in a location that
2312 // will cause a new row to be inserted. The hot spot positions
2313 // are along the borders of the center pane
2316 insert_dock_row
= true;
2317 if (pt
.x
>= part
->rect
.x
&&
2318 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2319 insert_dir
= wxAUI_DOCK_LEFT
;
2321 if (pt
.y
>= part
->rect
.y
&&
2322 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2323 insert_dir
= wxAUI_DOCK_TOP
;
2325 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2326 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2327 insert_dir
= wxAUI_DOCK_RIGHT
;
2329 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2330 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2331 insert_dir
= wxAUI_DOCK_BOTTOM
;
2335 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2339 if (insert_dock_row
)
2341 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2342 drop
.Dock().Direction(insert_dir
).
2343 Layer(insert_layer
).
2346 return ProcessDockResult(target
, drop
);
2349 // determine the mouse offset and the pane size, both in the
2350 // direction of the dock itself, and perpendicular to the dock
2354 if (part
->orientation
== wxVERTICAL
)
2356 offset
= pt
.y
- part
->rect
.y
;
2357 size
= part
->rect
.GetHeight();
2361 offset
= pt
.x
- part
->rect
.x
;
2362 size
= part
->rect
.GetWidth();
2365 int drop_position
= part
->pane
->dock_pos
;
2367 // if we are in the top/left part of the pane,
2368 // insert the pane before the pane being hovered over
2369 if (offset
<= size
/2)
2371 drop_position
= part
->pane
->dock_pos
;
2373 part
->pane
->dock_direction
,
2374 part
->pane
->dock_layer
,
2375 part
->pane
->dock_row
,
2376 part
->pane
->dock_pos
);
2379 // if we are in the bottom/right part of the pane,
2380 // insert the pane before the pane being hovered over
2381 if (offset
> size
/2)
2383 drop_position
= part
->pane
->dock_pos
+1;
2385 part
->pane
->dock_direction
,
2386 part
->pane
->dock_layer
,
2387 part
->pane
->dock_row
,
2388 part
->pane
->dock_pos
+1);
2392 Direction(part
->dock
->dock_direction
).
2393 Layer(part
->dock
->dock_layer
).
2394 Row(part
->dock
->dock_row
).
2395 Position(drop_position
);
2396 return ProcessDockResult(target
, drop
);
2403 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2406 if (!m_hint_wnd
|| m_hint_fadeamt
>= 50)
2408 m_hint_fadetimer
.Stop();
2412 m_hint_fadeamt
+= 5;
2413 MakeWindowTransparent(m_hint_wnd
, m_hint_fadeamt
);
2417 void wxFrameManager::ShowHint(const wxRect
& rect
)
2421 // First, determine if the operating system can handle transparency.
2422 // Transparency is available on Win2000 and above
2424 static int os_type
= -1;
2425 static int ver_major
= -1;
2428 os_type
= ::wxGetOsVersion(&ver_major
);
2430 // If the transparent flag is set, and the OS supports it,
2431 // go ahead and use a transparent hint
2433 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 &&
2434 os_type
== wxWINDOWS_NT
&& ver_major
>= 5)
2436 if (m_last_hint
== rect
)
2440 int initial_fade
= 50;
2441 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2444 if (m_hint_wnd
== NULL
)
2446 wxPoint pt
= rect
.GetPosition();
2447 wxSize size
= rect
.GetSize();
2448 m_hint_wnd
= new wxFrame(m_frame
, -1, wxEmptyString
, pt
, size
,
2449 wxFRAME_TOOL_WINDOW
|
2450 wxFRAME_FLOAT_ON_PARENT
|
2451 wxFRAME_NO_TASKBAR
|
2454 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2455 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
2458 // if we are dragging a floating pane, set the focus
2459 // back to that floating pane (otherwise it becomes unfocused)
2460 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2461 m_action_window
->SetFocus();
2466 wxPoint pt
= rect
.GetPosition();
2467 wxSize size
= rect
.GetSize();
2468 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2469 m_hint_wnd
->SetSize(pt
.x
, pt
.y
, rect
.width
, rect
.height
);
2472 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2474 // start fade in timer
2476 m_hint_fadetimer
.SetOwner(this, 101);
2477 m_hint_fadetimer
.Start(5);
2484 if (m_last_hint
!= rect
)
2486 // remove the last hint rectangle
2492 wxScreenDC screendc
;
2493 wxRegion
clip(1, 1, 10000, 10000);
2495 // clip all floating windows, so we don't draw over them
2497 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2499 wxPaneInfo
& pane
= m_panes
.Item(i
);
2501 if (pane
.IsFloating() &&
2502 pane
.frame
->IsShown())
2504 wxRect rect
= pane
.frame
->GetRect();
2506 // wxGTK returns the client size, not the whole frame size
2512 clip
.Subtract(rect
);
2516 screendc
.SetClippingRegion(clip
);
2518 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2519 wxBrush
brush(stipple
);
2520 screendc
.SetBrush(brush
);
2521 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2523 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2524 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2525 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2526 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2529 void wxFrameManager::HideHint()
2531 // hides a transparent window hint (currently wxMSW only)
2535 MakeWindowTransparent(m_hint_wnd
, 0);
2536 m_hint_fadetimer
.Stop();
2537 m_last_hint
= wxRect();
2542 // hides a painted hint by redrawing the frame window
2543 if (!m_last_hint
.IsEmpty())
2547 m_last_hint
= wxRect();
2553 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2554 // determine the exact position the pane would be at were if dropped. If
2555 // the pame would indeed become docked at the specified drop point,
2556 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2557 // "pane_window" is the window pointer of the pane being dragged, pt is
2558 // the mouse position, in client coordinates
2559 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2561 const wxPoint
& offset
)
2565 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2566 // we will create a new temporary layout and then measure the resulting
2567 // rectangle; we will create a copy of the docking structures (m_dock)
2568 // so that we don't modify the real thing on screen
2570 int i
, pane_count
, part_count
;
2571 wxDockInfoArray docks
;
2572 wxPaneInfoArray panes
;
2573 wxDockUIPartArray uiparts
;
2574 wxPaneInfo hint
= GetPane(pane_window
);
2575 hint
.name
= wxT("__HINT__");
2580 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2582 // remove any pane already there which bears the same window;
2583 // this happens when you are moving a pane around in a dock
2584 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2586 if (panes
.Item(i
).window
== pane_window
)
2588 RemovePaneFromDocks(docks
, panes
.Item(i
));
2594 // find out where the new pane would be
2595 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2603 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2604 wxSize client_size
= m_frame
->GetClientSize();
2605 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2608 for (i
= 0, part_count
= uiparts
.GetCount();
2609 i
< part_count
; ++i
)
2611 wxDockUIPart
& part
= uiparts
.Item(i
);
2613 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2614 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2616 rect
= wxRect(part
.sizer_item
->GetPosition(),
2617 part
.sizer_item
->GetSize());
2630 // actually show the hint rectangle on the screen
2631 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2635 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2637 // try to find the pane
2638 wxPaneInfo
& pane
= GetPane(wnd
);
2639 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2642 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2643 MakeWindowTransparent(pane
.frame
, 150);
2647 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
)
2649 // try to find the pane
2650 wxPaneInfo
& pane
= GetPane(wnd
);
2651 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2653 wxPoint pt
= ::wxGetMousePosition();
2654 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2656 // calculate the offset from the upper left-hand corner
2657 // of the frame to the mouse pointer
2658 wxPoint frame_pos
= pane
.frame
->GetPosition();
2659 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2661 // no hint for toolbar floating windows
2662 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
2664 if (m_action
== actionDragFloatingPane
)
2666 wxDockInfoArray docks
;
2667 wxPaneInfoArray panes
;
2668 wxDockUIPartArray uiparts
;
2669 wxPaneInfo hint
= pane
;
2671 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2673 // find out where the new pane would be
2674 if (!DoDrop(docks
, panes
, hint
, client_pt
))
2676 if (hint
.IsFloating())
2680 m_action
= actionDragToolbarPane
;
2681 m_action_window
= pane
.window
;
2690 // if a key modifier is pressed while dragging the frame,
2691 // don't dock the window
2692 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2699 DrawHintRect(wnd
, client_pt
, action_offset
);
2702 // this cleans up some screen artifacts that are caused on GTK because
2703 // we aren't getting the exact size of the window (see comment
2713 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
)
2715 // try to find the pane
2716 wxPaneInfo
& pane
= GetPane(wnd
);
2717 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2719 wxPoint pt
= ::wxGetMousePosition();
2720 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2722 // calculate the offset from the upper left-hand corner
2723 // of the frame to the mouse pointer
2724 wxPoint frame_pos
= pane
.frame
->GetPosition();
2725 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2728 // if a key modifier is pressed while dragging the frame,
2729 // don't dock the window
2730 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2737 // do the drop calculation
2738 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
2740 // if the pane is still floating, update it's floating
2741 // position (that we store)
2742 if (pane
.IsFloating())
2744 pane
.floating_pos
= pane
.frame
->GetPosition();
2747 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2748 MakeWindowTransparent(pane
.frame
, 255);
2757 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
2759 // try to find the pane
2760 wxPaneInfo
& pane
= GetPane(wnd
);
2761 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2763 pane
.floating_size
= size
;
2766 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
)
2768 // try to find the pane
2769 wxPaneInfo
& pane
= GetPane(wnd
);
2770 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2772 // reparent the pane window back to us and
2773 // prepare the frame window for destruction
2774 pane
.window
->Show(false);
2775 pane
.window
->Reparent(m_frame
);
2780 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
2782 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
2784 // try to find the pane
2785 wxPaneInfo
& pane
= GetPane(wnd
);
2786 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2788 SetActivePane(m_panes
, wnd
);
2793 // Render() draws all of the pane captions, sashes,
2794 // backgrounds, captions, grippers, pane borders and buttons.
2795 // It renders the entire user interface.
2797 void wxFrameManager::Render(wxDC
* dc
)
2803 for (i
= 0, part_count
= m_uiparts
.GetCount();
2804 i
< part_count
; ++i
)
2806 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2808 // don't draw hidden pane items
2809 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
2814 case wxDockUIPart::typeDockSizer
:
2815 case wxDockUIPart::typePaneSizer
:
2816 m_art
->DrawSash(*dc
, part
.orientation
, part
.rect
);
2818 case wxDockUIPart::typeBackground
:
2819 m_art
->DrawBackground(*dc
, part
.orientation
, part
.rect
);
2821 case wxDockUIPart::typeCaption
:
2822 m_art
->DrawCaption(*dc
, part
.pane
->caption
, part
.rect
, *part
.pane
);
2824 case wxDockUIPart::typeGripper
:
2825 m_art
->DrawGripper(*dc
, part
.rect
, *part
.pane
);
2827 case wxDockUIPart::typePaneBorder
:
2828 m_art
->DrawBorder(*dc
, part
.rect
, *part
.pane
);
2830 case wxDockUIPart::typePaneButton
:
2831 m_art
->DrawPaneButton(*dc
, part
.button
->button_id
,
2832 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
2838 void wxFrameManager::Repaint(wxDC
* dc
)
2843 m_frame
->Refresh() ;
2849 m_frame
->GetClientSize(&w
, &h
);
2851 // figure out which dc to use; if one
2852 // has been specified, use it, otherwise
2854 wxClientDC
* client_dc
= NULL
;
2857 client_dc
= new wxClientDC(m_frame
);
2861 // if the frame has a toolbar, the client area
2862 // origin will not be (0,0).
2863 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2864 if (pt
.x
!= 0 || pt
.y
!= 0)
2865 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
2867 // render all the items
2870 // if we created a client_dc, delete it
2875 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2877 wxPaintDC
dc(m_frame
);
2881 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
2890 void wxFrameManager::OnSize(wxSizeEvent
& WXUNUSED(event
))
2900 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
2903 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2904 wxCursor cursor
= wxNullCursor
;
2908 if (part
->type
== wxDockUIPart::typeDockSizer
||
2909 part
->type
== wxDockUIPart::typePaneSizer
)
2911 // a dock may not be resized if it has a single
2912 // pane which is not resizable
2913 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
2914 part
->dock
->panes
.GetCount() == 1 &&
2915 part
->dock
->panes
.Item(0)->IsFixed())
2918 // panes that may not be resized do not get a sizing cursor
2919 if (part
->pane
&& part
->pane
->IsFixed())
2922 if (part
->orientation
== wxVERTICAL
)
2923 cursor
= wxCursor(wxCURSOR_SIZEWE
);
2925 cursor
= wxCursor(wxCURSOR_SIZENS
);
2927 else if (part
->type
== wxDockUIPart::typeGripper
)
2929 cursor
= wxCursor(wxCURSOR_SIZING
);
2933 event
.SetCursor(cursor
);
2938 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
2939 const wxMouseEvent
& event
)
2941 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
2943 int state
= wxAUI_BUTTON_STATE_NORMAL
;
2945 if (hit_test
== button_ui_part
)
2947 if (event
.LeftDown())
2948 state
= wxAUI_BUTTON_STATE_PRESSED
;
2950 state
= wxAUI_BUTTON_STATE_HOVER
;
2954 if (event
.LeftDown())
2955 state
= wxAUI_BUTTON_STATE_HOVER
;
2958 // now repaint the button with hover state
2959 wxClientDC
cdc(m_frame
);
2961 // if the frame has a toolbar, the client area
2962 // origin will not be (0,0).
2963 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2964 if (pt
.x
!= 0 || pt
.y
!= 0)
2965 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
2967 m_art
->DrawPaneButton(cdc
,
2968 button_ui_part
->button
->button_id
,
2970 button_ui_part
->rect
,
2974 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
2976 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2979 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2982 if (part
->type
== wxDockUIPart::typeDockSizer
||
2983 part
->type
== wxDockUIPart::typePaneSizer
)
2985 // a dock may not be resized if it has a single
2986 // pane which is not resizable
2987 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
2988 part
->dock
->panes
.GetCount() == 1 &&
2989 part
->dock
->panes
.Item(0)->IsFixed())
2992 // panes that may not be resized should be ignored here
2993 if (part
->pane
&& part
->pane
->IsFixed())
2996 m_action
= actionResize
;
2997 m_action_part
= part
;
2998 m_action_hintrect
= wxRect();
2999 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3000 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3001 event
.m_y
- part
->rect
.y
);
3002 m_frame
->CaptureMouse();
3004 else if (part
->type
== wxDockUIPart::typePaneButton
)
3006 m_action
= actionClickButton
;
3007 m_action_part
= part
;
3008 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3009 m_frame
->CaptureMouse();
3011 UpdateButtonOnScreen(part
, event
);
3013 else if (part
->type
== wxDockUIPart::typeCaption
||
3014 part
->type
== wxDockUIPart::typeGripper
)
3016 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3018 // set the caption as active
3019 SetActivePane(m_panes
, part
->pane
->window
);
3023 m_action
= actionClickCaption
;
3024 m_action_part
= part
;
3025 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3026 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3027 event
.m_y
- part
->rect
.y
);
3028 m_frame
->CaptureMouse();
3048 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3050 if (m_action
== actionResize
)
3052 m_frame
->ReleaseMouse();
3054 // get rid of the hint rectangle
3056 DrawResizeHint(dc
, m_action_hintrect
);
3058 // resize the dock or the pane
3059 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3061 wxRect
& rect
= m_action_part
->dock
->rect
;
3063 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3064 event
.m_y
- m_action_offset
.y
);
3066 switch (m_action_part
->dock
->dock_direction
)
3068 case wxAUI_DOCK_LEFT
:
3069 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3071 case wxAUI_DOCK_TOP
:
3072 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3074 case wxAUI_DOCK_RIGHT
:
3075 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3076 new_pos
.x
- m_action_part
->rect
.GetWidth();
3078 case wxAUI_DOCK_BOTTOM
:
3079 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3080 new_pos
.y
- m_action_part
->rect
.GetHeight();
3087 else if (m_action_part
&&
3088 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3090 wxDockInfo
& dock
= *m_action_part
->dock
;
3091 wxPaneInfo
& pane
= *m_action_part
->pane
;
3093 int total_proportion
= 0;
3094 int dock_pixels
= 0;
3095 int new_pixsize
= 0;
3097 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3098 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3099 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3101 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3102 event
.m_y
- m_action_offset
.y
);
3104 // determine the pane rectangle by getting the pane part
3105 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3106 wxASSERT_MSG(pane_part
,
3107 wxT("Pane border part not found -- shouldn't happen"));
3109 // determine the new pixel size that the user wants;
3110 // this will help us recalculate the pane's proportion
3111 if (dock
.IsHorizontal())
3112 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3114 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3116 // determine the size of the dock, based on orientation
3117 if (dock
.IsHorizontal())
3118 dock_pixels
= dock
.rect
.GetWidth();
3120 dock_pixels
= dock
.rect
.GetHeight();
3122 // determine the total proportion of all resizable panes,
3123 // and the total size of the dock minus the size of all
3125 int i
, dock_pane_count
= dock
.panes
.GetCount();
3126 int pane_position
= -1;
3127 for (i
= 0; i
< dock_pane_count
; ++i
)
3129 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3130 if (p
.window
== pane
.window
)
3133 // while we're at it, subtract the pane sash
3134 // width from the dock width, because this would
3135 // skew our proportion calculations
3137 dock_pixels
-= sash_size
;
3139 // also, the whole size (including decorations) of
3140 // all fixed panes must also be subtracted, because they
3141 // are not part of the proportion calculation
3144 if (dock
.IsHorizontal())
3145 dock_pixels
-= p
.best_size
.x
;
3147 dock_pixels
-= p
.best_size
.y
;
3151 total_proportion
+= p
.dock_proportion
;
3155 // find a pane in our dock to 'steal' space from or to 'give'
3156 // space to -- this is essentially what is done when a pane is
3157 // resized; the pane should usually be the first non-fixed pane
3158 // to the right of the action pane
3159 int borrow_pane
= -1;
3160 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3162 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3171 // demand that the pane being resized is found in this dock
3172 // (this assert really never should be raised)
3173 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3175 // prevent division by zero
3176 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3178 m_action
= actionNone
;
3182 // calculate the new proportion of the pane
3183 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3185 // default minimum size
3188 // check against the pane's minimum size, if specified. please note
3189 // that this is not enough to ensure that the minimum size will
3190 // not be violated, because the whole frame might later be shrunk,
3191 // causing the size of the pane to violate it's minimum size
3192 if (pane
.min_size
.IsFullySpecified())
3196 if (pane
.HasBorder())
3197 min_size
+= (pane_border_size
*2);
3199 // calculate minimum size with decorations (border,caption)
3200 if (pane_part
->orientation
== wxVERTICAL
)
3202 min_size
+= pane
.min_size
.y
;
3203 if (pane
.HasCaption())
3204 min_size
+= caption_size
;
3208 min_size
+= pane
.min_size
.x
;
3213 // for some reason, an arithmatic error somewhere is causing
3214 // the proportion calculations to always be off by 1 pixel;
3215 // for now we will add the 1 pixel on, but we really should
3216 // determine what's causing this.
3219 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3221 if (new_proportion
< min_proportion
)
3222 new_proportion
= min_proportion
;
3226 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3228 // borrow the space from our neighbor pane to the
3229 // right or bottom (depending on orientation)
3230 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3231 pane
.dock_proportion
= new_proportion
;
3238 else if (m_action
== actionClickButton
)
3240 m_hover_button
= NULL
;
3241 m_frame
->ReleaseMouse();
3242 UpdateButtonOnScreen(m_action_part
, event
);
3244 // make sure we're still over the item that was originally clicked
3245 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3247 // fire button-click event
3248 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3249 e
.SetPane(m_action_part
->pane
);
3250 e
.SetButton(m_action_part
->button
->button_id
);
3254 else if (m_action
== actionClickCaption
)
3256 m_frame
->ReleaseMouse();
3258 else if (m_action
== actionDragFloatingPane
)
3260 m_frame
->ReleaseMouse();
3262 else if (m_action
== actionDragToolbarPane
)
3264 m_frame
->ReleaseMouse();
3266 wxPaneInfo
& pane
= GetPane(m_action_window
);
3267 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3269 // save the new positions
3270 wxDockInfoPtrArray docks
;
3271 FindDocks(m_docks
, pane
.dock_direction
,
3272 pane
.dock_layer
, pane
.dock_row
, docks
);
3273 if (docks
.GetCount() == 1)
3275 wxDockInfo
& dock
= *docks
.Item(0);
3277 wxArrayInt pane_positions
, pane_sizes
;
3278 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3280 int i
, dock_pane_count
= dock
.panes
.GetCount();
3281 for (i
= 0; i
< dock_pane_count
; ++i
)
3282 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3285 pane
.state
&= ~wxPaneInfo::actionPane
;
3293 m_action
= actionNone
;
3294 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3298 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3300 // sometimes when Update() is called from inside this method,
3301 // a spurious mouse move event is generated; this check will make
3302 // sure that only real mouse moves will get anywhere in this method;
3303 // this appears to be a bug somewhere, and I don't know where the
3304 // mouse move event is being generated. only verified on MSW
3306 wxPoint mouse_pos
= event
.GetPosition();
3307 if (m_last_mouse_move
== mouse_pos
)
3309 m_last_mouse_move
= mouse_pos
;
3312 if (m_action
== actionResize
)
3314 wxPoint pos
= m_action_part
->rect
.GetPosition();
3315 if (m_action_part
->orientation
== wxHORIZONTAL
)
3316 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3318 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3320 wxRect
rect(m_frame
->ClientToScreen(pos
),
3321 m_action_part
->rect
.GetSize());
3324 if (!m_action_hintrect
.IsEmpty())
3325 DrawResizeHint(dc
, m_action_hintrect
);
3326 DrawResizeHint(dc
, rect
);
3327 m_action_hintrect
= rect
;
3329 else if (m_action
== actionClickCaption
)
3331 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3332 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3334 // caption has been clicked. we need to check if the mouse
3335 // is now being dragged. if it is, we need to change the
3336 // mouse action to 'drag'
3337 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3338 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3340 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3342 if (!pane_info
->IsToolbar())
3344 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3345 pane_info
->IsFloatable())
3347 m_action
= actionDragFloatingPane
;
3349 // set initial float position
3350 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3351 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3352 pt
.y
- m_action_offset
.y
);
3357 m_action_window
= pane_info
->frame
;
3359 // action offset is used here to make it feel "natural" to the user
3360 // to drag a docked pane and suddenly have it become a floating frame.
3361 // Sometimes, however, the offset where the user clicked on the docked
3362 // caption is bigger than the width of the floating frame itself, so
3363 // in that case we need to set the action offset to a sensible value
3364 wxSize frame_size
= m_action_window
->GetSize();
3365 if (frame_size
.x
<= m_action_offset
.x
)
3366 m_action_offset
.x
= 30;
3371 m_action
= actionDragToolbarPane
;
3372 m_action_window
= pane_info
->window
;
3376 else if (m_action
== actionDragFloatingPane
)
3378 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3379 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3380 pt
.y
- m_action_offset
.y
);
3382 else if (m_action
== actionDragToolbarPane
)
3384 wxPaneInfo
& pane
= GetPane(m_action_window
);
3385 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3387 pane
.state
|= wxPaneInfo::actionPane
;
3389 wxPoint pt
= event
.GetPosition();
3390 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3392 // if DoDrop() decided to float the pane, set up
3393 // the floating pane's initial position
3394 if (pane
.IsFloating())
3396 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3397 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3398 pt
.y
- m_action_offset
.y
);
3401 // this will do the actiual move operation;
3402 // in the case that the pane has been floated,
3403 // this call will create the floating pane
3404 // and do the reparenting
3407 // if the pane has been floated, change the mouse
3408 // action actionDragFloatingPane so that subsequent
3409 // EVT_MOTION() events will move the floating pane
3410 if (pane
.IsFloating())
3412 pane
.state
&= ~wxPaneInfo::actionPane
;
3413 m_action
= actionDragFloatingPane
;
3414 m_action_window
= pane
.frame
;
3419 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3420 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3422 if (part
!= m_hover_button
)
3424 // make the old button normal
3426 UpdateButtonOnScreen(m_hover_button
, event
);
3428 // mouse is over a button, so repaint the
3429 // button in hover mode
3430 UpdateButtonOnScreen(part
, event
);
3431 m_hover_button
= part
;
3438 m_hover_button
= NULL
;
3449 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3453 m_hover_button
= NULL
;
3458 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3460 // when a child pane has it's focus set, we should change the
3461 // pane's active state to reflect this. (this is only true if
3462 // active panes are allowed by the owner)
3463 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3465 if (GetPane(event
.GetWindow()).IsOk())
3467 SetActivePane(m_panes
, event
.GetWindow());
3474 // OnPaneButton() is an event handler that is called
3475 // when a pane button has been pressed.
3476 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& event
)
3478 wxPaneInfo
& pane
= *(event
.pane
);
3480 if (event
.button
== wxPaneInfo::buttonClose
)
3485 else if (event
.button
== wxPaneInfo::buttonPin
)
3487 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&