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
)
58 // a few defines to avoid nameclashes
59 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
61 #include "wx/mac/private.h"
65 // -- static utility functions --
67 static wxBitmap
wxPaneCreateStippleBitmap()
69 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
70 wxImage
img(2,2,data
,true);
74 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
76 wxBitmap stipple
= wxPaneCreateStippleBitmap();
77 wxBrush
brush(stipple
);
79 dc
.SetPen(*wxTRANSPARENT_PEN
);
81 dc
.SetLogicalFunction(wxXOR
);
82 dc
.DrawRectangle(rect
);
87 // on supported windows systems (Win2000 and greater), this function
88 // will make a frame window transparent by a certain amount
89 static void MakeWindowTransparent(wxWindow
* wnd
, int amount
)
91 // this API call is not in all SDKs, only the newer ones, so
92 // we will runtime bind this
93 typedef DWORD (WINAPI
*PSETLAYEREDWINDOWATTR
)(HWND
, DWORD
, BYTE
, DWORD
);
94 static PSETLAYEREDWINDOWATTR pSetLayeredWindowAttributes
= NULL
;
95 static HMODULE h
= NULL
;
96 HWND hwnd
= (HWND
)wnd
->GetHWND();
99 h
= LoadLibrary(_T("user32"));
101 if (!pSetLayeredWindowAttributes
)
103 pSetLayeredWindowAttributes
=
104 (PSETLAYEREDWINDOWATTR
)GetProcAddress(h
,
106 wxT("SetLayeredWindowAttributes")
108 "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, (BYTE
)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
;
340 // SetActivePane() sets the active pane, as well as cycles through
341 // every other pane and makes sure that all others' active flags
343 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
346 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
348 wxPaneInfo
& pane
= panes
.Item(i
);
349 pane
.state
&= ~wxPaneInfo::optionActive
;
350 if (pane
.window
== active_pane
)
351 pane
.state
|= wxPaneInfo::optionActive
;
356 // this function is used to sort panes by dock position
357 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
359 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
363 // -- wxFrameManager class implementation --
366 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
367 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
368 EVT_PAINT(wxFrameManager::OnPaint
)
369 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
370 EVT_SIZE(wxFrameManager::OnSize
)
371 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
372 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
373 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
374 EVT_MOTION(wxFrameManager::OnMotion
)
375 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
376 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
377 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
381 wxFrameManager::wxFrameManager(wxFrame
* frame
, unsigned int flags
)
383 m_action
= actionNone
;
384 m_last_mouse_move
= wxPoint();
385 m_hover_button
= NULL
;
386 m_art
= new wxDefaultDockArt
;
396 wxFrameManager::~wxFrameManager()
401 // GetPane() looks up a wxPaneInfo structure based
402 // on the supplied window pointer. Upon failure, GetPane()
403 // returns an empty wxPaneInfo, a condition which can be checked
404 // by calling wxPaneInfo::IsOk().
406 // The pane info's structure may then be modified. Once a pane's
407 // info is modified, wxFrameManager::Update() must be called to
408 // realize the changes in the UI.
410 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
413 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
415 wxPaneInfo
& p
= m_panes
.Item(i
);
416 if (p
.window
== window
)
419 return wxNullPaneInfo
;
422 // this version of GetPane() looks up a pane based on a
423 // 'pane name', see above comment for more info
424 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
427 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
429 wxPaneInfo
& p
= m_panes
.Item(i
);
433 return wxNullPaneInfo
;
436 // GetAllPanes() returns a reference to all the pane info structures
437 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
442 // HitTest() is an internal function which determines
443 // which UI item the specified coordinates are over
444 // (x,y) specify a position in client coordinates
445 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
447 wxDockUIPart
* result
= NULL
;
450 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
452 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
454 // we are not interested in typeDock, because this space
455 // isn't used to draw anything, just for measurements;
456 // besides, the entire dock area is covered with other
457 // rectangles, which we are interested in.
458 if (item
->type
== wxDockUIPart::typeDock
)
461 // if we already have a hit on a more specific item, we are not
462 // interested in a pane hit. If, however, we don't already have
463 // a hit, returning a pane hit is necessary for some operations
464 if ((item
->type
== wxDockUIPart::typePane
||
465 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
468 // if the point is inside the rectangle, we have a hit
469 if (item
->rect
.Inside(x
,y
))
477 // SetFlags() and GetFlags() allow the owner to set various
478 // options which are global to wxFrameManager
479 void wxFrameManager::SetFlags(unsigned int flags
)
484 unsigned int wxFrameManager::GetFlags() const
490 // SetFrame() is usually called once when the frame
491 // manager class is being initialized. "frame" specifies
492 // the frame which should be managed by the frame mananger
493 void wxFrameManager::SetFrame(wxFrame
* frame
)
495 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
498 m_frame
->PushEventHandler(this);
501 // if the owner is going to manage an MDI parent frame,
502 // we need to add the MDI client window as the default
505 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
507 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
508 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
510 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
512 AddPane(client_window
,
513 wxPaneInfo().Name(wxT("mdiclient")).
514 CenterPane().PaneBorder(false));
520 // UnInit() must be called, usually in the destructor
521 // of the frame class. If it is not called, usually this
522 // will result in a crash upon program exit
523 void wxFrameManager::UnInit()
525 m_frame
->RemoveEventHandler(this);
528 // GetFrame() returns the frame pointer being managed by wxFrameManager
529 wxFrame
* wxFrameManager::GetFrame() const
534 wxDockArt
* wxFrameManager::GetArtProvider() const
539 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
541 // first, give the owner frame a chance to override
544 if (m_frame
->ProcessEvent(event
))
551 // SetArtProvider() instructs wxFrameManager to use the
552 // specified art provider for all drawing calls. This allows
553 // plugable look-and-feel features. The pointer that is
554 // passed to this method subsequently belongs to wxFrameManager,
555 // and is deleted in the frame manager destructor
556 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
558 // delete the last art provider, if any
561 // assign the new art provider
562 m_art
= art_provider
;
566 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
568 // check if the pane has a valid window
572 // check if the pane already exists
573 if (GetPane(pane_info
.window
).IsOk())
576 m_panes
.Add(pane_info
);
578 wxPaneInfo
& pinfo
= m_panes
.Last();
580 // set the pane window
581 pinfo
.window
= window
;
583 // if the pane's name identifier is blank, create a random string
584 if (pinfo
.name
.empty())
586 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
587 ((unsigned long)pinfo
.window
) & 0xffffffff,
588 (unsigned int)time(NULL
),
590 (unsigned int)GetTickCount(),
592 (unsigned int)clock(),
594 (unsigned long)m_panes
.GetCount());
597 // set initial proportion (if not already set)
598 if (pinfo
.dock_proportion
== 0)
599 pinfo
.dock_proportion
= 100000;
601 if (pinfo
.HasCloseButton() &&
602 pinfo
.buttons
.size() == 0)
605 button
.button_id
= wxPaneInfo::buttonClose
;
606 pinfo
.buttons
.Add(button
);
609 if (pinfo
.best_size
== wxDefaultSize
&&
612 pinfo
.best_size
= pinfo
.window
->GetClientSize();
614 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
616 // GetClientSize() doesn't get the best size for
617 // a toolbar under some newer versions of wxWidgets,
618 // so use GetBestSize()
619 pinfo
.best_size
= pinfo
.window
->GetBestSize();
621 // for some reason, wxToolBar::GetBestSize() is returning
622 // a size that is a pixel shy of the correct amount.
623 // I believe this to be the correct action, until
624 // wxToolBar::GetBestSize() is fixed. Is this assumption
629 if (pinfo
.min_size
!= wxDefaultSize
)
631 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
632 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
633 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
634 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
641 bool wxFrameManager::AddPane(wxWindow
* window
,
643 const wxString
& caption
)
646 pinfo
.Caption(caption
);
649 case wxTOP
: pinfo
.Top(); break;
650 case wxBOTTOM
: pinfo
.Bottom(); break;
651 case wxLEFT
: pinfo
.Left(); break;
652 case wxRIGHT
: pinfo
.Right(); break;
653 case wxCENTER
: pinfo
.CenterPane(); break;
655 return AddPane(window
, pinfo
);
658 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
661 // shift the panes around, depending on the insert level
662 switch (insert_level
)
664 case wxAUI_INSERT_PANE
:
665 DoInsertPane(m_panes
,
666 pane_info
.dock_direction
,
667 pane_info
.dock_layer
,
671 case wxAUI_INSERT_ROW
:
672 DoInsertDockRow(m_panes
,
673 pane_info
.dock_direction
,
674 pane_info
.dock_layer
,
677 case wxAUI_INSERT_DOCK
:
678 DoInsertDockLayer(m_panes
,
679 pane_info
.dock_direction
,
680 pane_info
.dock_layer
);
684 // if the window already exists, we are basically just moving/inserting the
685 // existing window. If it doesn't exist, we need to add it and insert it
686 wxPaneInfo
& existing_pane
= GetPane(window
);
687 if (!existing_pane
.IsOk())
689 return AddPane(window
, pane_info
);
693 if (pane_info
.IsFloating())
695 existing_pane
.Float();
696 if (pane_info
.floating_pos
!= wxDefaultPosition
)
697 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
698 if (pane_info
.floating_size
!= wxDefaultSize
)
699 existing_pane
.FloatingSize(pane_info
.floating_size
);
703 existing_pane
.Direction(pane_info
.dock_direction
);
704 existing_pane
.Layer(pane_info
.dock_layer
);
705 existing_pane
.Row(pane_info
.dock_row
);
706 existing_pane
.Position(pane_info
.dock_pos
);
714 // DetachPane() removes a pane from the frame manager. This
715 // method will not destroy the window that is removed.
716 bool wxFrameManager::DetachPane(wxWindow
* window
)
719 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
721 wxPaneInfo
& p
= m_panes
.Item(i
);
722 if (p
.window
== window
)
726 // we have a floating frame which is being detached. We need to
727 // reparent it to m_frame and destroy the floating frame
730 p
.window
->SetSize(1,1);
731 p
.frame
->Show(false);
733 // reparent to m_frame and destroy the pane
734 p
.window
->Reparent(m_frame
);
735 p
.frame
->SetSizer(NULL
);
747 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
748 // in the input string. This is an internal functions which is
749 // used for saving perspectives
750 static wxString
EscapeDelimiters(const wxString
& s
)
753 result
.Alloc(s
.length());
754 const wxChar
* ch
= s
.c_str();
757 if (*ch
== wxT(';') || *ch
== wxT('|'))
766 // SavePerspective() saves all pane information as a single string.
767 // This string may later be fed into LoadPerspective() to restore
768 // all pane settings. This save and load mechanism allows an
769 // exact pane configuration to be saved and restored at a later time
771 wxString
wxFrameManager::SavePerspective()
775 result
= wxT("layout1|");
777 int pane_i
, pane_count
= m_panes
.GetCount();
778 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
780 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
782 result
+= wxT("name=");
783 result
+= EscapeDelimiters(pane
.name
);
786 result
+= wxT("caption=");
787 result
+= EscapeDelimiters(pane
.caption
);
790 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
791 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
792 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
793 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
794 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
795 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
796 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
797 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
798 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
799 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
800 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
801 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
802 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
803 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
804 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
805 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
809 int dock_i
, dock_count
= m_docks
.GetCount();
810 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
812 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
814 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
815 dock
.dock_direction
, dock
.dock_layer
,
816 dock
.dock_row
, dock
.size
);
822 // LoadPerspective() loads a layout which was saved with SavePerspective()
823 // If the "update" flag parameter is true, the GUI will immediately be updated
825 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
827 wxString input
= layout
;
830 // check layout string version
831 part
= input
.BeforeFirst(wxT('|'));
832 input
= input
.AfterFirst(wxT('|'));
835 if (part
!= wxT("layout1"))
839 // mark all panes currently managed as docked and hidden
840 int pane_i
, pane_count
= m_panes
.GetCount();
841 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
842 m_panes
.Item(pane_i
).Dock().Hide();
844 // clear out the dock array; this will be reconstructed
847 // replace escaped characters so we can
848 // split up the string easily
849 input
.Replace(wxT("\\|"), wxT("\a"));
850 input
.Replace(wxT("\\;"), wxT("\b"));
856 wxString pane_part
= input
.BeforeFirst(wxT('|'));
857 input
= input
.AfterFirst(wxT('|'));
858 pane_part
.Trim(true);
860 // if the string is empty, we're done parsing
861 if (pane_part
.empty())
865 if (pane_part
.Left(9) == wxT("dock_size"))
867 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
868 wxString value
= pane_part
.AfterFirst(wxT('='));
870 long dir
, layer
, row
, size
;
871 wxString piece
= val_name
.AfterFirst(wxT('('));
872 piece
= piece
.BeforeLast(wxT(')'));
873 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
874 piece
= piece
.AfterFirst(wxT(','));
875 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
876 piece
.AfterFirst(wxT(',')).ToLong(&row
);
880 dock
.dock_direction
= dir
;
881 dock
.dock_layer
= layer
;
890 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
891 pane_part
= pane_part
.AfterFirst(wxT(';'));
892 wxString val_name
= val_part
.BeforeFirst(wxT('='));
893 wxString value
= val_part
.AfterFirst(wxT('='));
894 val_name
.MakeLower();
896 val_name
.Trim(false);
900 if (val_name
.empty())
903 if (val_name
== wxT("name"))
905 else if (val_name
== wxT("caption"))
906 pane
.caption
= value
;
907 else if (val_name
== wxT("state"))
908 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
909 else if (val_name
== wxT("dir"))
910 pane
.dock_direction
= wxAtoi(value
.c_str());
911 else if (val_name
== wxT("layer"))
912 pane
.dock_layer
= wxAtoi(value
.c_str());
913 else if (val_name
== wxT("row"))
914 pane
.dock_row
= wxAtoi(value
.c_str());
915 else if (val_name
== wxT("pos"))
916 pane
.dock_pos
= wxAtoi(value
.c_str());
917 else if (val_name
== wxT("prop"))
918 pane
.dock_proportion
= wxAtoi(value
.c_str());
919 else if (val_name
== wxT("bestw"))
920 pane
.best_size
.x
= wxAtoi(value
.c_str());
921 else if (val_name
== wxT("besth"))
922 pane
.best_size
.y
= wxAtoi(value
.c_str());
923 else if (val_name
== wxT("minw"))
924 pane
.min_size
.x
= wxAtoi(value
.c_str());
925 else if (val_name
== wxT("minh"))
926 pane
.min_size
.y
= wxAtoi(value
.c_str());
927 else if (val_name
== wxT("maxw"))
928 pane
.max_size
.x
= wxAtoi(value
.c_str());
929 else if (val_name
== wxT("maxh"))
930 pane
.max_size
.y
= wxAtoi(value
.c_str());
931 else if (val_name
== wxT("floatx"))
932 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
933 else if (val_name
== wxT("floaty"))
934 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
935 else if (val_name
== wxT("floatw"))
936 pane
.floating_size
.x
= wxAtoi(value
.c_str());
937 else if (val_name
== wxT("floath"))
938 pane
.floating_size
.y
= wxAtoi(value
.c_str());
940 wxFAIL_MSG(wxT("Bad Perspective String"));
944 // replace escaped characters so we can
945 // split up the string easily
946 pane
.name
.Replace(wxT("\a"), wxT("|"));
947 pane
.name
.Replace(wxT("\b"), wxT(";"));
948 pane
.caption
.Replace(wxT("\a"), wxT("|"));
949 pane
.caption
.Replace(wxT("\b"), wxT(";"));
951 wxPaneInfo
& p
= GetPane(pane
.name
);
954 // the pane window couldn't be found
955 // in the existing layout
959 pane
.window
= p
.window
;
960 pane
.frame
= p
.frame
;
961 pane
.buttons
= p
.buttons
;
972 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
973 wxArrayInt
& positions
,
976 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
977 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
978 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
983 int offset
, action_pane
= -1;
984 int pane_i
, pane_count
= dock
.panes
.GetCount();
986 // find the pane marked as our action pane
987 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
989 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
991 if (pane
.state
& wxPaneInfo::actionPane
)
993 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
994 action_pane
= pane_i
;
998 // set up each panes default position, and
999 // determine the size (width or height, depending
1000 // on the dock's orientation) of each pane
1001 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1003 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1004 positions
.Add(pane
.dock_pos
);
1007 if (pane
.HasBorder())
1008 size
+= (pane_border_size
*2);
1010 if (dock
.IsHorizontal())
1012 if (pane
.HasGripper() && !pane
.HasGripperTop())
1013 size
+= gripper_size
;
1014 size
+= pane
.best_size
.x
;
1018 if (pane
.HasGripper() && pane
.HasGripperTop())
1019 size
+= gripper_size
;
1021 if (pane
.HasCaption())
1022 size
+= caption_size
;
1023 size
+= pane
.best_size
.y
;
1029 // if there is no action pane, just return the default
1030 // positions (as specified in pane.pane_pos)
1031 if (action_pane
== -1)
1035 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1037 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1042 positions
[pane_i
] -= -amount
;
1044 offset
+= sizes
[pane_i
];
1047 // if the dock mode is fixed, make sure none of the panes
1048 // overlap; we will bump panes that overlap
1050 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1052 int amount
= positions
[pane_i
] - offset
;
1056 positions
[pane_i
] += -amount
;
1058 offset
+= sizes
[pane_i
];
1063 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1066 wxDockUIPartArray
& uiparts
,
1070 wxSizerItem
* sizer_item
;
1072 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1073 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1074 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1075 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1077 // find out the orientation of the item (orientation for panes
1078 // is the same as the dock's orientation)
1080 if (dock
.IsHorizontal())
1081 orientation
= wxHORIZONTAL
;
1083 orientation
= wxVERTICAL
;
1085 // this variable will store the proportion
1086 // value that the pane will receive
1087 int pane_proportion
= pane
.dock_proportion
;
1089 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1090 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1092 if (pane
.HasGripper())
1094 if (pane
.HasGripperTop())
1095 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1097 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1099 part
.type
= wxDockUIPart::typeGripper
;
1103 part
.orientation
= orientation
;
1104 part
.cont_sizer
= horz_pane_sizer
;
1105 part
.sizer_item
= sizer_item
;
1109 if (pane
.HasCaption())
1111 // create the caption sizer
1112 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1114 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1116 part
.type
= wxDockUIPart::typeCaption
;
1120 part
.orientation
= orientation
;
1121 part
.cont_sizer
= vert_pane_sizer
;
1122 part
.sizer_item
= sizer_item
;
1123 int caption_part_idx
= uiparts
.GetCount();
1126 // add pane buttons to the caption
1127 int i
, button_count
;
1128 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1129 i
< button_count
; ++i
)
1131 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1133 sizer_item
= caption_sizer
->Add(pane_button_size
,
1137 part
.type
= wxDockUIPart::typePaneButton
;
1140 part
.button
= &button
;
1141 part
.orientation
= orientation
;
1142 part
.cont_sizer
= caption_sizer
;
1143 part
.sizer_item
= sizer_item
;
1147 // add the caption sizer
1148 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1150 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1153 // add the pane window itself
1156 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1160 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1161 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1164 part
.type
= wxDockUIPart::typePane
;
1168 part
.orientation
= orientation
;
1169 part
.cont_sizer
= vert_pane_sizer
;
1170 part
.sizer_item
= sizer_item
;
1174 // determine if the pane should have a minimum size; if the pane is
1175 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1176 // if the pane.min_size is set, we must use that value as well
1178 wxSize min_size
= pane
.min_size
;
1181 if (min_size
== wxDefaultSize
)
1183 min_size
= pane
.best_size
;
1184 pane_proportion
= 0;
1188 if (min_size
!= wxDefaultSize
)
1190 vert_pane_sizer
->SetItemMinSize(
1191 vert_pane_sizer
->GetChildren().GetCount()-1,
1192 min_size
.x
, min_size
.y
);
1196 // add the verticle sizer (caption, pane window) to the
1197 // horizontal sizer (gripper, verticle sizer)
1198 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1200 // finally, add the pane sizer to the dock sizer
1202 if (pane
.HasBorder())
1204 // allowing space for the pane's border
1205 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1206 wxEXPAND
| wxALL
, pane_border_size
);
1208 part
.type
= wxDockUIPart::typePaneBorder
;
1212 part
.orientation
= orientation
;
1213 part
.cont_sizer
= cont
;
1214 part
.sizer_item
= sizer_item
;
1219 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1223 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1225 wxDockUIPartArray
& uiparts
,
1228 wxSizerItem
* sizer_item
;
1231 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1232 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1234 // resizable bottom and right docks have a sash before them
1235 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1236 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1238 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1240 part
.type
= wxDockUIPart::typeDockSizer
;
1241 part
.orientation
= orientation
;
1245 part
.cont_sizer
= cont
;
1246 part
.sizer_item
= sizer_item
;
1250 // create the sizer for the dock
1251 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1253 // add each pane to the dock
1254 int pane_i
, pane_count
= dock
.panes
.GetCount();
1258 wxArrayInt pane_positions
, pane_sizes
;
1260 // figure out the real pane positions we will
1261 // use, without modifying the each pane's pane_pos member
1262 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1265 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1267 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1268 int pane_pos
= pane_positions
.Item(pane_i
);
1270 int amount
= pane_pos
- offset
;
1273 if (dock
.IsVertical())
1274 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1276 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1278 part
.type
= wxDockUIPart::typeBackground
;
1282 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1283 part
.cont_sizer
= dock_sizer
;
1284 part
.sizer_item
= sizer_item
;
1290 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1292 offset
+= pane_sizes
.Item(pane_i
);
1295 // at the end add a very small stretchable background area
1296 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1298 part
.type
= wxDockUIPart::typeBackground
;
1302 part
.orientation
= orientation
;
1303 part
.cont_sizer
= dock_sizer
;
1304 part
.sizer_item
= sizer_item
;
1309 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1311 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1313 // if this is not the first pane being added,
1314 // we need to add a pane sizer
1317 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1319 part
.type
= wxDockUIPart::typePaneSizer
;
1321 part
.pane
= dock
.panes
.Item(pane_i
-1);
1323 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1324 part
.cont_sizer
= dock_sizer
;
1325 part
.sizer_item
= sizer_item
;
1329 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1333 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1334 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1336 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1338 part
.type
= wxDockUIPart::typeDock
;
1342 part
.orientation
= orientation
;
1343 part
.cont_sizer
= cont
;
1344 part
.sizer_item
= sizer_item
;
1347 if (dock
.IsHorizontal())
1348 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1350 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1352 // top and left docks have a sash after them
1353 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1354 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1356 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1358 part
.type
= wxDockUIPart::typeDockSizer
;
1362 part
.orientation
= orientation
;
1363 part
.cont_sizer
= cont
;
1364 part
.sizer_item
= sizer_item
;
1369 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1370 wxDockInfoArray
& docks
,
1371 wxDockUIPartArray
& uiparts
,
1374 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1376 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1377 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1378 wxSize cli_size
= m_frame
->GetClientSize();
1379 int i
, dock_count
, pane_count
;
1382 // empty all docks out
1383 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1384 docks
.Item(i
).panes
.Empty();
1386 // iterate through all known panes, filing each
1387 // of them into the appropriate dock. If the
1388 // pane does not exist in the dock, add it
1389 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1391 wxPaneInfo
& p
= panes
.Item(i
);
1393 // find any docks in this layer
1395 wxDockInfoPtrArray arr
;
1396 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1398 if (arr
.GetCount() > 0)
1404 // dock was not found, so we need to create a new one
1406 d
.dock_direction
= p
.dock_direction
;
1407 d
.dock_layer
= p
.dock_layer
;
1408 d
.dock_row
= p
.dock_row
;
1410 dock
= &docks
.Last();
1414 if (p
.IsDocked() && p
.IsShown())
1416 // remove the pane from any existing docks except this one
1417 RemovePaneFromDocks(docks
, p
, dock
);
1419 // pane needs to be added to the dock,
1420 // if it doesn't already exist
1421 if (!FindPaneInDock(*dock
, p
.window
))
1422 dock
->panes
.Add(&p
);
1426 // remove the pane from any existing docks
1427 RemovePaneFromDocks(docks
, p
);
1432 // remove any empty docks
1433 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1435 if (docks
.Item(i
).panes
.GetCount() == 0)
1439 // configure the docks further
1440 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1442 wxDockInfo
& dock
= docks
.Item(i
);
1443 int j
, dock_pane_count
= dock
.panes
.GetCount();
1445 // sort the dock pane array by the pane's
1446 // dock position (dock_pos), in ascending order
1447 dock
.panes
.Sort(PaneSortFunc
);
1449 // for newly created docks, set up their initial size
1454 for (j
= 0; j
< dock_pane_count
; ++j
)
1456 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1457 wxSize pane_size
= pane
.best_size
;
1458 if (pane_size
== wxDefaultSize
)
1459 pane_size
= pane
.min_size
;
1460 if (pane_size
== wxDefaultSize
)
1461 pane_size
= pane
.window
->GetSize();
1463 if (dock
.IsHorizontal())
1464 size
= wxMax(pane_size
.y
, size
);
1466 size
= wxMax(pane_size
.x
, size
);
1469 // add space for the border (two times), but only
1470 // if at least one pane inside the dock has a pane border
1471 for (j
= 0; j
< dock_pane_count
; ++j
)
1473 if (dock
.panes
.Item(j
)->HasBorder())
1475 size
+= (pane_border_size
*2);
1480 // if pane is on the top or bottom, add the caption height,
1481 // but only if at least one pane inside the dock has a caption
1482 if (dock
.IsHorizontal())
1484 for (j
= 0; j
< dock_pane_count
; ++j
)
1486 if (dock
.panes
.Item(j
)->HasCaption())
1488 size
+= caption_size
;
1494 // new dock's size may not be more than 1/3 of the frame size
1495 if (dock
.IsHorizontal())
1496 size
= wxMin(size
, cli_size
.y
/3);
1498 size
= wxMin(size
, cli_size
.x
/3);
1506 // determine the dock's minimum size
1507 bool plus_border
= false;
1508 bool plus_caption
= false;
1509 int dock_min_size
= 0;
1510 for (j
= 0; j
< dock_pane_count
; ++j
)
1512 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1513 if (pane
.min_size
!= wxDefaultSize
)
1515 if (pane
.HasBorder())
1517 if (pane
.HasCaption())
1518 plus_caption
= true;
1519 if (dock
.IsHorizontal())
1521 if (pane
.min_size
.y
> dock_min_size
)
1522 dock_min_size
= pane
.min_size
.y
;
1526 if (pane
.min_size
.x
> dock_min_size
)
1527 dock_min_size
= pane
.min_size
.x
;
1533 dock_min_size
+= (pane_border_size
*2);
1534 if (plus_caption
&& dock
.IsHorizontal())
1535 dock_min_size
+= (caption_size
);
1537 dock
.min_size
= dock_min_size
;
1540 // if the pane's current size is less than it's
1541 // minimum, increase the dock's size to it's minimum
1542 if (dock
.size
< dock
.min_size
)
1543 dock
.size
= dock
.min_size
;
1546 // determine the dock's mode (fixed or proportional);
1547 // determine whether the dock has only toolbars
1548 bool action_pane_marked
= false;
1550 dock
.toolbar
= true;
1551 for (j
= 0; j
< dock_pane_count
; ++j
)
1553 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1554 if (!pane
.IsFixed())
1556 if (!pane
.IsToolbar())
1557 dock
.toolbar
= false;
1558 if (pane
.state
& wxPaneInfo::actionPane
)
1559 action_pane_marked
= true;
1563 // if the dock mode is proportional and not fixed-pixel,
1564 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1565 // e.g. remove gaps like 1, 2, 30, 500
1568 for (j
= 0; j
< dock_pane_count
; ++j
)
1570 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1575 // if the dock mode is fixed, and none of the panes
1576 // are being moved right now, make sure the panes
1577 // do not overlap each other. If they do, we will
1578 // adjust the panes' positions
1579 if (dock
.fixed
&& !action_pane_marked
)
1581 wxArrayInt pane_positions
, pane_sizes
;
1582 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1585 for (j
= 0; j
< dock_pane_count
; ++j
)
1587 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1588 pane
.dock_pos
= pane_positions
[j
];
1590 int amount
= pane
.dock_pos
- offset
;
1594 pane
.dock_pos
+= -amount
;
1596 offset
+= pane_sizes
[j
];
1601 // discover the maximum dock layer
1603 for (i
= 0; i
< dock_count
; ++i
)
1604 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1607 // clear out uiparts
1610 // create a bunch of box sizers,
1611 // from the innermost level outwards.
1612 wxSizer
* cont
= NULL
;
1613 wxSizer
* middle
= NULL
;
1617 for (layer
= 0; layer
<= max_layer
; ++layer
)
1619 wxDockInfoPtrArray arr
;
1621 // find any docks in this layer
1622 FindDocks(docks
, -1, layer
, -1, arr
);
1624 // if there aren't any, skip to the next layer
1628 wxSizer
* old_cont
= cont
;
1630 // create a container which will hold this layer's
1631 // docks (top, bottom, left, right)
1632 cont
= new wxBoxSizer(wxVERTICAL
);
1635 // find any top docks in this layer
1636 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1637 RenumberDockRows(arr
);
1640 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1641 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1645 // fill out the middle layer (which consists
1646 // of left docks, content area and right docks)
1648 middle
= new wxBoxSizer(wxHORIZONTAL
);
1650 // find any left docks in this layer
1651 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1652 RenumberDockRows(arr
);
1655 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1656 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1659 // add content dock (or previous layer's sizer
1663 // find any center docks
1664 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1667 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1668 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1672 // there are no center docks, add a background area
1673 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1675 part
.type
= wxDockUIPart::typeBackground
;
1679 part
.cont_sizer
= middle
;
1680 part
.sizer_item
= sizer_item
;
1686 middle
->Add(old_cont
, 1, wxEXPAND
);
1689 // find any right docks in this layer
1690 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1691 RenumberDockRows(arr
);
1694 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1695 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1698 cont
->Add(middle
, 1, wxEXPAND
);
1702 // find any bottom docks in this layer
1703 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1704 RenumberDockRows(arr
);
1707 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1708 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1715 // no sizer available, because there are no docks,
1716 // therefore we will create a simple background area
1717 cont
= new wxBoxSizer(wxVERTICAL
);
1718 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1720 part
.type
= wxDockUIPart::typeBackground
;
1724 part
.cont_sizer
= middle
;
1725 part
.sizer_item
= sizer_item
;
1729 container
->Add(cont
, 1, wxEXPAND
);
1734 // Update() updates the layout. Whenever changes are made to
1735 // one or more panes, this function should be called. It is the
1736 // external entry point for running the layout engine.
1738 void wxFrameManager::Update()
1741 int i
, pane_count
= m_panes
.GetCount();
1743 // delete old sizer first
1744 m_frame
->SetSizer(NULL
);
1746 // destroy floating panes which have been
1747 // redocked or are becoming non-floating
1748 for (i
= 0; i
< pane_count
; ++i
)
1750 wxPaneInfo
& p
= m_panes
.Item(i
);
1752 if (!p
.IsFloating() && p
.frame
)
1754 // because the pane is no longer in a floating, we need to
1755 // reparent it to m_frame and destroy the floating frame
1758 p
.window
->SetSize(1,1);
1759 p
.frame
->Show(false);
1761 // reparent to m_frame and destroy the pane
1762 p
.window
->Reparent(m_frame
);
1763 p
.frame
->SetSizer(NULL
);
1770 // create a layout for all of the panes
1771 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
1773 // hide or show panes as necessary,
1774 // and float panes as necessary
1775 for (i
= 0; i
< pane_count
; ++i
)
1777 wxPaneInfo
& p
= m_panes
.Item(i
);
1781 if (p
.frame
== NULL
)
1783 // we need to create a frame for this
1784 // pane, which has recently been floated
1785 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
1789 // on MSW, if the owner desires transparent dragging, and
1790 // the dragging is happening right now, then the floating
1791 // window should have this style by default
1793 if (m_action
== actionDragFloatingPane
&&
1794 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
1795 MakeWindowTransparent(frame
, 150);
1798 frame
->SetPaneWindow(p
);
1808 // frame already exists, make sure it's position
1809 // and size reflect the information in wxPaneInfo
1810 if (p
.frame
->GetPosition() != p
.floating_pos
)
1812 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
1813 -1, -1, wxSIZE_USE_EXISTING
);
1814 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
1817 p
.frame
->Show(p
.IsShown());
1822 p
.window
->Show(p
.IsShown());
1825 // if "active panes" are no longer allowed, clear
1826 // any optionActive values from the pane states
1827 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
1829 p
.state
&= ~wxPaneInfo::optionActive
;
1834 // keep track of the old window rectangles so we can
1835 // refresh those windows whose rect has changed
1836 wxAuiRectArray old_pane_rects
;
1837 for (i
= 0; i
< pane_count
; ++i
)
1840 wxPaneInfo
& p
= m_panes
.Item(i
);
1842 if (p
.window
&& p
.IsShown() && p
.IsDocked())
1845 old_pane_rects
.Add(r
);
1851 // apply the new sizer
1852 m_frame
->SetSizer(sizer
);
1853 m_frame
->SetAutoLayout(false);
1858 // now that the frame layout is done, we need to check
1859 // the new pane rectangles against the old rectangles that
1860 // we saved a few lines above here. If the rectangles have
1861 // changed, the corresponding panes must also be updated
1862 for (i
= 0; i
< pane_count
; ++i
)
1864 wxPaneInfo
& p
= m_panes
.Item(i
);
1865 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
1867 if (p
.rect
!= old_pane_rects
[i
])
1869 p
.window
->Refresh();
1878 // set frame's minimum size
1881 // N.B. More work needs to be done on frame minimum sizes;
1882 // this is some intresting code that imposes the minimum size,
1883 // but we may want to include a more flexible mechanism or
1884 // options for multiple minimum-size modes, e.g. strict or lax
1885 wxSize min_size = sizer->GetMinSize();
1886 wxSize frame_size = m_frame->GetSize();
1887 wxSize client_size = m_frame->GetClientSize();
1889 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
1890 min_size.y+frame_size.y-client_size.y );
1892 m_frame->SetMinSize(minframe_size);
1894 if (frame_size.x < minframe_size.x ||
1895 frame_size.y < minframe_size.y)
1896 sizer->Fit(m_frame);
1901 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
1902 // on the frame's main sizer, then measures all the various UI items
1903 // and updates their internal rectangles. This should always be called
1904 // instead of calling m_frame->Layout() directly
1906 void wxFrameManager::DoFrameLayout()
1911 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1913 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1915 // get the rectangle of the UI part
1916 // originally, this code looked like this:
1917 // part.rect = wxRect(part.sizer_item->GetPosition(),
1918 // part.sizer_item->GetSize());
1919 // this worked quite well, with one exception: the mdi
1920 // client window had a "deferred" size variable
1921 // that returned the wrong size. It looks like
1922 // a bug in wx, because the former size of the window
1923 // was being returned. So, we will retrieve the part's
1924 // rectangle via other means
1927 part
.rect
= part
.sizer_item
->GetRect();
1928 int flag
= part
.sizer_item
->GetFlag();
1929 int border
= part
.sizer_item
->GetBorder();
1932 part
.rect
.y
-= border
;
1933 part
.rect
.height
+= border
;
1937 part
.rect
.x
-= border
;
1938 part
.rect
.width
+= border
;
1940 if (flag
& wxBOTTOM
)
1941 part
.rect
.height
+= border
;
1943 part
.rect
.width
+= border
;
1946 if (part
.type
== wxDockUIPart::typeDock
)
1947 part
.dock
->rect
= part
.rect
;
1948 if (part
.type
== wxDockUIPart::typePane
)
1949 part
.pane
->rect
= part
.rect
;
1953 // GetPanePart() looks up the pane the pane border UI part (or the regular
1954 // pane part if there is no border). This allows the caller to get the exact
1955 // rectangle of the pane in question, including decorations like
1956 // caption and border (if any).
1958 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
1961 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1963 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1964 if (part
.type
== wxDockUIPart::typePaneBorder
&&
1965 part
.pane
&& part
.pane
->window
== wnd
)
1968 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1970 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1971 if (part
.type
== wxDockUIPart::typePane
&&
1972 part
.pane
&& part
.pane
->window
== wnd
)
1980 // GetDockPixelOffset() is an internal function which returns
1981 // a dock's offset in pixels from the left side of the window
1982 // (for horizontal docks) or from the top of the window (for
1983 // vertical docks). This value is necessary for calculating
1984 // fixel-pane/toolbar offsets when they are dragged.
1986 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
1988 // the only way to accurately calculate the dock's
1989 // offset is to actually run a theoretical layout
1991 int i
, part_count
, dock_count
;
1992 wxDockInfoArray docks
;
1993 wxPaneInfoArray panes
;
1994 wxDockUIPartArray uiparts
;
1995 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
1998 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
1999 wxSize client_size
= m_frame
->GetClientSize();
2000 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2003 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2005 wxDockUIPart
& part
= uiparts
.Item(i
);
2006 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2007 part
.sizer_item
->GetSize());
2008 if (part
.type
== wxDockUIPart::typeDock
)
2009 part
.dock
->rect
= part
.rect
;
2014 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2016 wxDockInfo
& dock
= docks
.Item(i
);
2017 if (test
.dock_direction
== dock
.dock_direction
&&
2018 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2020 if (dock
.IsVertical())
2032 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2033 // if a dock operation is allowed, the new dock position is copied into
2034 // the target info. If the operation was allowed, the function returns true.
2036 static bool ProcessDockResult(wxPaneInfo
& target
,
2037 const wxPaneInfo
& new_pos
)
2039 bool allowed
= false;
2040 switch (new_pos
.dock_direction
)
2042 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2043 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2044 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2045 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2055 // DoDrop() is an important function. It basically takes a mouse position,
2056 // and determines where the pane's new position would be. If the pane is to be
2057 // dropped, it performs the drop operation using the specified dock and pane
2058 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2059 // scenario can be performed, giving precise coordinates for drop hints.
2060 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2061 // as parameters, the changes will be made to the main state arrays
2063 const int auiInsertRowPixels
= 10;
2064 const int auiNewRowPixels
= 40;
2065 const int auiLayerInsertPixels
= 40;
2066 const int auiLayerInsertOffset
= 5;
2068 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2069 wxPaneInfoArray
& panes
,
2072 const wxPoint
& offset
)
2074 wxSize cli_size
= m_frame
->GetClientSize();
2076 wxPaneInfo drop
= target
;
2079 // The result should always be shown
2083 // Check to see if the pane has been dragged outside of the window
2084 // (or near to the outside of the window), if so, dock it along the edge
2087 int layer_insert_offset
= auiLayerInsertOffset
;
2088 if (target
.IsToolbar())
2089 layer_insert_offset
= 0;
2091 if (pt
.x
< layer_insert_offset
&&
2092 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2094 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2095 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2096 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2100 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2101 return ProcessDockResult(target
, drop
);
2103 else if (pt
.y
< layer_insert_offset
&&
2104 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2106 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2107 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2108 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2112 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2113 return ProcessDockResult(target
, drop
);
2115 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2116 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2118 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2119 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2120 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2121 drop
.Dock().Right().
2124 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2125 return ProcessDockResult(target
, drop
);
2127 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2128 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2130 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2131 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2132 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2133 drop
.Dock().Bottom().
2136 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2137 return ProcessDockResult(target
, drop
);
2141 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2144 if (drop
.IsToolbar())
2146 if (!part
|| !part
->dock
)
2150 // calculate the offset from where the dock begins
2151 // to the point where the user dropped the pane
2152 int dock_drop_offset
= 0;
2153 if (part
->dock
->IsHorizontal())
2154 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2156 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2159 // toolbars may only be moved in and to fixed-pane docks,
2160 // otherwise we will try to float the pane. Also, the pane
2161 // should float if being dragged over center pane windows
2162 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2164 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2165 (drop
.IsFloatable() ||
2166 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2167 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2172 return ProcessDockResult(target
, drop
);
2176 Direction(part
->dock
->dock_direction
).
2177 Layer(part
->dock
->dock_layer
).
2178 Row(part
->dock
->dock_row
).
2179 Position(dock_drop_offset
);
2182 ((pt
.y
< part
->dock
->rect
.y
+ 2) && part
->dock
->IsHorizontal()) ||
2183 ((pt
.x
< part
->dock
->rect
.x
+ 2) && part
->dock
->IsVertical())
2184 ) && part
->dock
->panes
.GetCount() > 1)
2186 int row
= drop
.dock_row
;
2187 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2188 part
->dock
->dock_layer
,
2189 part
->dock
->dock_row
);
2190 drop
.dock_row
= row
;
2194 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2195 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2196 ) && part
->dock
->panes
.GetCount() > 1)
2198 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2199 part
->dock
->dock_layer
,
2200 part
->dock
->dock_row
+1);
2201 drop
.dock_row
= part
->dock
->dock_row
+1;
2204 return ProcessDockResult(target
, drop
);
2213 if (part
->type
== wxDockUIPart::typePaneBorder
||
2214 part
->type
== wxDockUIPart::typeCaption
||
2215 part
->type
== wxDockUIPart::typeGripper
||
2216 part
->type
== wxDockUIPart::typePaneButton
||
2217 part
->type
== wxDockUIPart::typePane
||
2218 part
->type
== wxDockUIPart::typePaneSizer
||
2219 part
->type
== wxDockUIPart::typeDockSizer
||
2220 part
->type
== wxDockUIPart::typeBackground
)
2222 if (part
->type
== wxDockUIPart::typeDockSizer
)
2224 if (part
->dock
->panes
.GetCount() != 1)
2226 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2233 // If a normal frame is being dragged over a toolbar, insert it
2234 // along the edge under the toolbar, but over all other panes.
2235 // (this could be done much better, but somehow factoring this
2236 // calculation with the one at the beginning of this function)
2237 if (part
->dock
&& part
->dock
->toolbar
)
2241 switch (part
->dock
->dock_direction
)
2243 case wxAUI_DOCK_LEFT
:
2244 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2245 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2246 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2248 case wxAUI_DOCK_TOP
:
2249 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2250 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2251 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2253 case wxAUI_DOCK_RIGHT
:
2254 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2255 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2256 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2258 case wxAUI_DOCK_BOTTOM
:
2259 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2260 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2261 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2265 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2268 Direction(part
->dock
->dock_direction
).
2269 Layer(layer
).Row(0).Position(0);
2270 return ProcessDockResult(target
, drop
);
2277 part
= GetPanePart(part
->pane
->window
);
2281 bool insert_dock_row
= false;
2282 int insert_row
= part
->pane
->dock_row
;
2283 int insert_dir
= part
->pane
->dock_direction
;
2284 int insert_layer
= part
->pane
->dock_layer
;
2286 switch (part
->pane
->dock_direction
)
2288 case wxAUI_DOCK_TOP
:
2289 if (pt
.y
>= part
->rect
.y
&&
2290 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2291 insert_dock_row
= true;
2293 case wxAUI_DOCK_BOTTOM
:
2294 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2295 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2296 insert_dock_row
= true;
2298 case wxAUI_DOCK_LEFT
:
2299 if (pt
.x
>= part
->rect
.x
&&
2300 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2301 insert_dock_row
= true;
2303 case wxAUI_DOCK_RIGHT
:
2304 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2305 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2306 insert_dock_row
= true;
2308 case wxAUI_DOCK_CENTER
:
2310 // "new row pixels" will be set to the default, but
2311 // must never exceed 20% of the window size
2312 int new_row_pixels_x
= auiNewRowPixels
;
2313 int new_row_pixels_y
= auiNewRowPixels
;
2315 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2316 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2318 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2319 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2322 // determine if the mouse pointer is in a location that
2323 // will cause a new row to be inserted. The hot spot positions
2324 // are along the borders of the center pane
2327 insert_dock_row
= true;
2328 if (pt
.x
>= part
->rect
.x
&&
2329 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2330 insert_dir
= wxAUI_DOCK_LEFT
;
2332 if (pt
.y
>= part
->rect
.y
&&
2333 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2334 insert_dir
= wxAUI_DOCK_TOP
;
2336 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2337 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2338 insert_dir
= wxAUI_DOCK_RIGHT
;
2340 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2341 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2342 insert_dir
= wxAUI_DOCK_BOTTOM
;
2346 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2350 if (insert_dock_row
)
2352 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2353 drop
.Dock().Direction(insert_dir
).
2354 Layer(insert_layer
).
2357 return ProcessDockResult(target
, drop
);
2360 // determine the mouse offset and the pane size, both in the
2361 // direction of the dock itself, and perpendicular to the dock
2365 if (part
->orientation
== wxVERTICAL
)
2367 offset
= pt
.y
- part
->rect
.y
;
2368 size
= part
->rect
.GetHeight();
2372 offset
= pt
.x
- part
->rect
.x
;
2373 size
= part
->rect
.GetWidth();
2376 int drop_position
= part
->pane
->dock_pos
;
2378 // if we are in the top/left part of the pane,
2379 // insert the pane before the pane being hovered over
2380 if (offset
<= size
/2)
2382 drop_position
= part
->pane
->dock_pos
;
2384 part
->pane
->dock_direction
,
2385 part
->pane
->dock_layer
,
2386 part
->pane
->dock_row
,
2387 part
->pane
->dock_pos
);
2390 // if we are in the bottom/right part of the pane,
2391 // insert the pane before the pane being hovered over
2392 if (offset
> size
/2)
2394 drop_position
= part
->pane
->dock_pos
+1;
2396 part
->pane
->dock_direction
,
2397 part
->pane
->dock_layer
,
2398 part
->pane
->dock_row
,
2399 part
->pane
->dock_pos
+1);
2403 Direction(part
->dock
->dock_direction
).
2404 Layer(part
->dock
->dock_layer
).
2405 Row(part
->dock
->dock_row
).
2406 Position(drop_position
);
2407 return ProcessDockResult(target
, drop
);
2414 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2417 if (!m_hint_wnd
|| m_hint_fadeamt
>= 50)
2419 m_hint_fadetimer
.Stop();
2423 m_hint_fadeamt
+= 5;
2424 MakeWindowTransparent(m_hint_wnd
, m_hint_fadeamt
);
2428 void wxFrameManager::ShowHint(const wxRect
& rect
)
2432 // First, determine if the operating system can handle transparency.
2433 // Transparency is available on Win2000 and above
2435 static int os_type
= -1;
2436 static int ver_major
= -1;
2439 os_type
= ::wxGetOsVersion(&ver_major
);
2441 // If the transparent flag is set, and the OS supports it,
2442 // go ahead and use a transparent hint
2444 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 &&
2445 os_type
== wxWINDOWS_NT
&& ver_major
>= 5)
2447 if (m_last_hint
== rect
)
2451 int initial_fade
= 50;
2452 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2455 if (m_hint_wnd
== NULL
)
2457 wxPoint pt
= rect
.GetPosition();
2458 wxSize size
= rect
.GetSize();
2459 m_hint_wnd
= new wxFrame(m_frame
, -1, wxEmptyString
, pt
, size
,
2460 wxFRAME_TOOL_WINDOW
|
2461 wxFRAME_FLOAT_ON_PARENT
|
2462 wxFRAME_NO_TASKBAR
|
2465 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2466 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
2469 // if we are dragging a floating pane, set the focus
2470 // back to that floating pane (otherwise it becomes unfocused)
2471 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2472 m_action_window
->SetFocus();
2477 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2478 m_hint_wnd
->SetSize(rect
);
2481 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2483 // start fade in timer
2485 m_hint_fadetimer
.SetOwner(this, 101);
2486 m_hint_fadetimer
.Start(5);
2493 if (m_last_hint
!= rect
)
2495 // remove the last hint rectangle
2501 wxScreenDC screendc
;
2502 wxRegion
clip(1, 1, 10000, 10000);
2504 // clip all floating windows, so we don't draw over them
2506 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2508 wxPaneInfo
& pane
= m_panes
.Item(i
);
2510 if (pane
.IsFloating() &&
2511 pane
.frame
->IsShown())
2513 wxRect rect
= pane
.frame
->GetRect();
2515 // wxGTK returns the client size, not the whole frame size
2521 clip
.Subtract(rect
);
2525 screendc
.SetClippingRegion(clip
);
2527 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2528 wxBrush
brush(stipple
);
2529 screendc
.SetBrush(brush
);
2530 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2532 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2533 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2534 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2535 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2538 void wxFrameManager::HideHint()
2540 // hides a transparent window hint (currently wxMSW only)
2544 MakeWindowTransparent(m_hint_wnd
, 0);
2545 m_hint_fadetimer
.Stop();
2546 m_last_hint
= wxRect();
2551 // hides a painted hint by redrawing the frame window
2552 if (!m_last_hint
.IsEmpty())
2556 m_last_hint
= wxRect();
2562 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2563 // determine the exact position the pane would be at were if dropped. If
2564 // the pame would indeed become docked at the specified drop point,
2565 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2566 // "pane_window" is the window pointer of the pane being dragged, pt is
2567 // the mouse position, in client coordinates
2568 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2570 const wxPoint
& offset
)
2574 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2575 // we will create a new temporary layout and then measure the resulting
2576 // rectangle; we will create a copy of the docking structures (m_dock)
2577 // so that we don't modify the real thing on screen
2579 int i
, pane_count
, part_count
;
2580 wxDockInfoArray docks
;
2581 wxPaneInfoArray panes
;
2582 wxDockUIPartArray uiparts
;
2583 wxPaneInfo hint
= GetPane(pane_window
);
2584 hint
.name
= wxT("__HINT__");
2589 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2591 // remove any pane already there which bears the same window;
2592 // this happens when you are moving a pane around in a dock
2593 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2595 if (panes
.Item(i
).window
== pane_window
)
2597 RemovePaneFromDocks(docks
, panes
.Item(i
));
2603 // find out where the new pane would be
2604 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2612 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2613 wxSize client_size
= m_frame
->GetClientSize();
2614 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2617 for (i
= 0, part_count
= uiparts
.GetCount();
2618 i
< part_count
; ++i
)
2620 wxDockUIPart
& part
= uiparts
.Item(i
);
2622 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2623 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2625 rect
= wxRect(part
.sizer_item
->GetPosition(),
2626 part
.sizer_item
->GetSize());
2639 // actually show the hint rectangle on the screen
2640 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2644 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2646 // try to find the pane
2647 wxPaneInfo
& pane
= GetPane(wnd
);
2648 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2651 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2652 MakeWindowTransparent(pane
.frame
, 150);
2656 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
)
2658 // try to find the pane
2659 wxPaneInfo
& pane
= GetPane(wnd
);
2660 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2662 wxPoint pt
= ::wxGetMousePosition();
2663 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2665 // calculate the offset from the upper left-hand corner
2666 // of the frame to the mouse pointer
2667 wxPoint frame_pos
= pane
.frame
->GetPosition();
2668 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2670 // no hint for toolbar floating windows
2671 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
2673 if (m_action
== actionDragFloatingPane
)
2675 wxDockInfoArray docks
;
2676 wxPaneInfoArray panes
;
2677 wxDockUIPartArray uiparts
;
2678 wxPaneInfo hint
= pane
;
2680 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2682 // find out where the new pane would be
2683 if (!DoDrop(docks
, panes
, hint
, client_pt
))
2685 if (hint
.IsFloating())
2689 m_action
= actionDragToolbarPane
;
2690 m_action_window
= pane
.window
;
2699 // if a key modifier is pressed while dragging the frame,
2700 // don't dock the window
2701 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2708 DrawHintRect(wnd
, client_pt
, action_offset
);
2711 // this cleans up some screen artifacts that are caused on GTK because
2712 // we aren't getting the exact size of the window (see comment
2722 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
)
2724 // try to find the pane
2725 wxPaneInfo
& pane
= GetPane(wnd
);
2726 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2728 wxPoint pt
= ::wxGetMousePosition();
2729 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2731 // calculate the offset from the upper left-hand corner
2732 // of the frame to the mouse pointer
2733 wxPoint frame_pos
= pane
.frame
->GetPosition();
2734 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2737 // if a key modifier is pressed while dragging the frame,
2738 // don't dock the window
2739 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2746 // do the drop calculation
2747 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
2749 // if the pane is still floating, update it's floating
2750 // position (that we store)
2751 if (pane
.IsFloating())
2753 pane
.floating_pos
= pane
.frame
->GetPosition();
2756 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2757 MakeWindowTransparent(pane
.frame
, 255);
2766 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
2768 // try to find the pane
2769 wxPaneInfo
& pane
= GetPane(wnd
);
2770 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2772 pane
.floating_size
= size
;
2776 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
2778 // try to find the pane
2779 wxPaneInfo
& pane
= GetPane(wnd
);
2780 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2783 // fire pane close event
2784 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
2786 e
.SetCanVeto(evt
.CanVeto());
2796 // reparent the pane window back to us and
2797 // prepare the frame window for destruction
2798 pane
.window
->Show(false);
2799 pane
.window
->Reparent(m_frame
);
2807 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
2809 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
2811 // try to find the pane
2812 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
2814 SetActivePane(m_panes
, wnd
);
2819 // Render() draws all of the pane captions, sashes,
2820 // backgrounds, captions, grippers, pane borders and buttons.
2821 // It renders the entire user interface.
2823 void wxFrameManager::Render(wxDC
* dc
)
2829 for (i
= 0, part_count
= m_uiparts
.GetCount();
2830 i
< part_count
; ++i
)
2832 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2834 // don't draw hidden pane items
2835 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
2840 case wxDockUIPart::typeDockSizer
:
2841 case wxDockUIPart::typePaneSizer
:
2842 m_art
->DrawSash(*dc
, part
.orientation
, part
.rect
);
2844 case wxDockUIPart::typeBackground
:
2845 m_art
->DrawBackground(*dc
, part
.orientation
, part
.rect
);
2847 case wxDockUIPart::typeCaption
:
2848 m_art
->DrawCaption(*dc
, part
.pane
->caption
, part
.rect
, *part
.pane
);
2850 case wxDockUIPart::typeGripper
:
2851 m_art
->DrawGripper(*dc
, part
.rect
, *part
.pane
);
2853 case wxDockUIPart::typePaneBorder
:
2854 m_art
->DrawBorder(*dc
, part
.rect
, *part
.pane
);
2856 case wxDockUIPart::typePaneButton
:
2857 m_art
->DrawPaneButton(*dc
, part
.button
->button_id
,
2858 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
2864 void wxFrameManager::Repaint(wxDC
* dc
)
2869 m_frame
->Refresh() ;
2875 m_frame
->GetClientSize(&w
, &h
);
2877 // figure out which dc to use; if one
2878 // has been specified, use it, otherwise
2880 wxClientDC
* client_dc
= NULL
;
2883 client_dc
= new wxClientDC(m_frame
);
2887 // if the frame has a toolbar, the client area
2888 // origin will not be (0,0).
2889 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2890 if (pt
.x
!= 0 || pt
.y
!= 0)
2891 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
2893 // render all the items
2896 // if we created a client_dc, delete it
2901 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2903 wxPaintDC
dc(m_frame
);
2907 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
2916 void wxFrameManager::OnSize(wxSizeEvent
& WXUNUSED(event
))
2926 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
2929 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2930 wxCursor cursor
= wxNullCursor
;
2934 if (part
->type
== wxDockUIPart::typeDockSizer
||
2935 part
->type
== wxDockUIPart::typePaneSizer
)
2937 // a dock may not be resized if it has a single
2938 // pane which is not resizable
2939 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
2940 part
->dock
->panes
.GetCount() == 1 &&
2941 part
->dock
->panes
.Item(0)->IsFixed())
2944 // panes that may not be resized do not get a sizing cursor
2945 if (part
->pane
&& part
->pane
->IsFixed())
2948 if (part
->orientation
== wxVERTICAL
)
2949 cursor
= wxCursor(wxCURSOR_SIZEWE
);
2951 cursor
= wxCursor(wxCURSOR_SIZENS
);
2953 else if (part
->type
== wxDockUIPart::typeGripper
)
2955 cursor
= wxCursor(wxCURSOR_SIZING
);
2959 event
.SetCursor(cursor
);
2964 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
2965 const wxMouseEvent
& event
)
2967 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
2969 int state
= wxAUI_BUTTON_STATE_NORMAL
;
2971 if (hit_test
== button_ui_part
)
2973 if (event
.LeftDown())
2974 state
= wxAUI_BUTTON_STATE_PRESSED
;
2976 state
= wxAUI_BUTTON_STATE_HOVER
;
2980 if (event
.LeftDown())
2981 state
= wxAUI_BUTTON_STATE_HOVER
;
2984 // now repaint the button with hover state
2985 wxClientDC
cdc(m_frame
);
2987 // if the frame has a toolbar, the client area
2988 // origin will not be (0,0).
2989 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2990 if (pt
.x
!= 0 || pt
.y
!= 0)
2991 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
2993 m_art
->DrawPaneButton(cdc
,
2994 button_ui_part
->button
->button_id
,
2996 button_ui_part
->rect
,
3000 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
3002 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3005 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3008 if (part
->type
== wxDockUIPart::typeDockSizer
||
3009 part
->type
== wxDockUIPart::typePaneSizer
)
3011 // a dock may not be resized if it has a single
3012 // pane which is not resizable
3013 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3014 part
->dock
->panes
.GetCount() == 1 &&
3015 part
->dock
->panes
.Item(0)->IsFixed())
3018 // panes that may not be resized should be ignored here
3019 if (part
->pane
&& part
->pane
->IsFixed())
3022 m_action
= actionResize
;
3023 m_action_part
= part
;
3024 m_action_hintrect
= wxRect();
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();
3030 else if (part
->type
== wxDockUIPart::typePaneButton
)
3032 m_action
= actionClickButton
;
3033 m_action_part
= part
;
3034 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3035 m_frame
->CaptureMouse();
3037 UpdateButtonOnScreen(part
, event
);
3039 else if (part
->type
== wxDockUIPart::typeCaption
||
3040 part
->type
== wxDockUIPart::typeGripper
)
3042 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3044 // set the caption as active
3045 SetActivePane(m_panes
, part
->pane
->window
);
3049 m_action
= actionClickCaption
;
3050 m_action_part
= part
;
3051 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3052 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3053 event
.m_y
- part
->rect
.y
);
3054 m_frame
->CaptureMouse();
3074 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3076 if (m_action
== actionResize
)
3078 m_frame
->ReleaseMouse();
3080 // get rid of the hint rectangle
3082 DrawResizeHint(dc
, m_action_hintrect
);
3084 // resize the dock or the pane
3085 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3087 wxRect
& rect
= m_action_part
->dock
->rect
;
3089 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3090 event
.m_y
- m_action_offset
.y
);
3092 switch (m_action_part
->dock
->dock_direction
)
3094 case wxAUI_DOCK_LEFT
:
3095 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3097 case wxAUI_DOCK_TOP
:
3098 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3100 case wxAUI_DOCK_RIGHT
:
3101 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3102 new_pos
.x
- m_action_part
->rect
.GetWidth();
3104 case wxAUI_DOCK_BOTTOM
:
3105 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3106 new_pos
.y
- m_action_part
->rect
.GetHeight();
3113 else if (m_action_part
&&
3114 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3116 wxDockInfo
& dock
= *m_action_part
->dock
;
3117 wxPaneInfo
& pane
= *m_action_part
->pane
;
3119 int total_proportion
= 0;
3120 int dock_pixels
= 0;
3121 int new_pixsize
= 0;
3123 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3124 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3125 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3127 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3128 event
.m_y
- m_action_offset
.y
);
3130 // determine the pane rectangle by getting the pane part
3131 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3132 wxASSERT_MSG(pane_part
,
3133 wxT("Pane border part not found -- shouldn't happen"));
3135 // determine the new pixel size that the user wants;
3136 // this will help us recalculate the pane's proportion
3137 if (dock
.IsHorizontal())
3138 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3140 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3142 // determine the size of the dock, based on orientation
3143 if (dock
.IsHorizontal())
3144 dock_pixels
= dock
.rect
.GetWidth();
3146 dock_pixels
= dock
.rect
.GetHeight();
3148 // determine the total proportion of all resizable panes,
3149 // and the total size of the dock minus the size of all
3151 int i
, dock_pane_count
= dock
.panes
.GetCount();
3152 int pane_position
= -1;
3153 for (i
= 0; i
< dock_pane_count
; ++i
)
3155 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3156 if (p
.window
== pane
.window
)
3159 // while we're at it, subtract the pane sash
3160 // width from the dock width, because this would
3161 // skew our proportion calculations
3163 dock_pixels
-= sash_size
;
3165 // also, the whole size (including decorations) of
3166 // all fixed panes must also be subtracted, because they
3167 // are not part of the proportion calculation
3170 if (dock
.IsHorizontal())
3171 dock_pixels
-= p
.best_size
.x
;
3173 dock_pixels
-= p
.best_size
.y
;
3177 total_proportion
+= p
.dock_proportion
;
3181 // find a pane in our dock to 'steal' space from or to 'give'
3182 // space to -- this is essentially what is done when a pane is
3183 // resized; the pane should usually be the first non-fixed pane
3184 // to the right of the action pane
3185 int borrow_pane
= -1;
3186 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3188 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3197 // demand that the pane being resized is found in this dock
3198 // (this assert really never should be raised)
3199 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3201 // prevent division by zero
3202 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3204 m_action
= actionNone
;
3208 // calculate the new proportion of the pane
3209 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3211 // default minimum size
3214 // check against the pane's minimum size, if specified. please note
3215 // that this is not enough to ensure that the minimum size will
3216 // not be violated, because the whole frame might later be shrunk,
3217 // causing the size of the pane to violate it's minimum size
3218 if (pane
.min_size
.IsFullySpecified())
3222 if (pane
.HasBorder())
3223 min_size
+= (pane_border_size
*2);
3225 // calculate minimum size with decorations (border,caption)
3226 if (pane_part
->orientation
== wxVERTICAL
)
3228 min_size
+= pane
.min_size
.y
;
3229 if (pane
.HasCaption())
3230 min_size
+= caption_size
;
3234 min_size
+= pane
.min_size
.x
;
3239 // for some reason, an arithmatic error somewhere is causing
3240 // the proportion calculations to always be off by 1 pixel;
3241 // for now we will add the 1 pixel on, but we really should
3242 // determine what's causing this.
3245 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3247 if (new_proportion
< min_proportion
)
3248 new_proportion
= min_proportion
;
3252 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3254 // borrow the space from our neighbor pane to the
3255 // right or bottom (depending on orientation)
3256 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3257 pane
.dock_proportion
= new_proportion
;
3264 else if (m_action
== actionClickButton
)
3266 m_hover_button
= NULL
;
3267 m_frame
->ReleaseMouse();
3268 UpdateButtonOnScreen(m_action_part
, event
);
3270 // make sure we're still over the item that was originally clicked
3271 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3273 // fire button-click event
3274 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3275 e
.SetPane(m_action_part
->pane
);
3276 e
.SetButton(m_action_part
->button
->button_id
);
3280 else if (m_action
== actionClickCaption
)
3282 m_frame
->ReleaseMouse();
3284 else if (m_action
== actionDragFloatingPane
)
3286 m_frame
->ReleaseMouse();
3288 else if (m_action
== actionDragToolbarPane
)
3290 m_frame
->ReleaseMouse();
3292 wxPaneInfo
& pane
= GetPane(m_action_window
);
3293 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3295 // save the new positions
3296 wxDockInfoPtrArray docks
;
3297 FindDocks(m_docks
, pane
.dock_direction
,
3298 pane
.dock_layer
, pane
.dock_row
, docks
);
3299 if (docks
.GetCount() == 1)
3301 wxDockInfo
& dock
= *docks
.Item(0);
3303 wxArrayInt pane_positions
, pane_sizes
;
3304 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3306 int i
, dock_pane_count
= dock
.panes
.GetCount();
3307 for (i
= 0; i
< dock_pane_count
; ++i
)
3308 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3311 pane
.state
&= ~wxPaneInfo::actionPane
;
3319 m_action
= actionNone
;
3320 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3324 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3326 // sometimes when Update() is called from inside this method,
3327 // a spurious mouse move event is generated; this check will make
3328 // sure that only real mouse moves will get anywhere in this method;
3329 // this appears to be a bug somewhere, and I don't know where the
3330 // mouse move event is being generated. only verified on MSW
3332 wxPoint mouse_pos
= event
.GetPosition();
3333 if (m_last_mouse_move
== mouse_pos
)
3335 m_last_mouse_move
= mouse_pos
;
3338 if (m_action
== actionResize
)
3340 wxPoint pos
= m_action_part
->rect
.GetPosition();
3341 if (m_action_part
->orientation
== wxHORIZONTAL
)
3342 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3344 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3346 wxRect
rect(m_frame
->ClientToScreen(pos
),
3347 m_action_part
->rect
.GetSize());
3350 if (!m_action_hintrect
.IsEmpty())
3351 DrawResizeHint(dc
, m_action_hintrect
);
3352 DrawResizeHint(dc
, rect
);
3353 m_action_hintrect
= rect
;
3355 else if (m_action
== actionClickCaption
)
3357 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3358 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3360 // caption has been clicked. we need to check if the mouse
3361 // is now being dragged. if it is, we need to change the
3362 // mouse action to 'drag'
3363 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3364 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3366 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3368 if (!pane_info
->IsToolbar())
3370 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3371 pane_info
->IsFloatable())
3373 m_action
= actionDragFloatingPane
;
3375 // set initial float position
3376 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3377 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3378 pt
.y
- m_action_offset
.y
);
3383 m_action_window
= pane_info
->frame
;
3385 // action offset is used here to make it feel "natural" to the user
3386 // to drag a docked pane and suddenly have it become a floating frame.
3387 // Sometimes, however, the offset where the user clicked on the docked
3388 // caption is bigger than the width of the floating frame itself, so
3389 // in that case we need to set the action offset to a sensible value
3390 wxSize frame_size
= m_action_window
->GetSize();
3391 if (frame_size
.x
<= m_action_offset
.x
)
3392 m_action_offset
.x
= 30;
3397 m_action
= actionDragToolbarPane
;
3398 m_action_window
= pane_info
->window
;
3402 else if (m_action
== actionDragFloatingPane
)
3404 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3405 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3406 pt
.y
- m_action_offset
.y
);
3408 else if (m_action
== actionDragToolbarPane
)
3410 wxPaneInfo
& pane
= GetPane(m_action_window
);
3411 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3413 pane
.state
|= wxPaneInfo::actionPane
;
3415 wxPoint pt
= event
.GetPosition();
3416 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3418 // if DoDrop() decided to float the pane, set up
3419 // the floating pane's initial position
3420 if (pane
.IsFloating())
3422 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3423 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3424 pt
.y
- m_action_offset
.y
);
3427 // this will do the actiual move operation;
3428 // in the case that the pane has been floated,
3429 // this call will create the floating pane
3430 // and do the reparenting
3433 // if the pane has been floated, change the mouse
3434 // action actionDragFloatingPane so that subsequent
3435 // EVT_MOTION() events will move the floating pane
3436 if (pane
.IsFloating())
3438 pane
.state
&= ~wxPaneInfo::actionPane
;
3439 m_action
= actionDragFloatingPane
;
3440 m_action_window
= pane
.frame
;
3445 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3446 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3448 if (part
!= m_hover_button
)
3450 // make the old button normal
3452 UpdateButtonOnScreen(m_hover_button
, event
);
3454 // mouse is over a button, so repaint the
3455 // button in hover mode
3456 UpdateButtonOnScreen(part
, event
);
3457 m_hover_button
= part
;
3464 m_hover_button
= NULL
;
3475 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3479 m_hover_button
= NULL
;
3484 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3486 // when a child pane has it's focus set, we should change the
3487 // pane's active state to reflect this. (this is only true if
3488 // active panes are allowed by the owner)
3489 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3491 if (GetPane(event
.GetWindow()).IsOk())
3493 SetActivePane(m_panes
, event
.GetWindow());
3500 // OnPaneButton() is an event handler that is called
3501 // when a pane button has been pressed.
3502 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& evt
)
3504 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3506 wxPaneInfo
& pane
= *(evt
.pane
);
3508 if (evt
.button
== wxPaneInfo::buttonClose
)
3510 // fire pane close event
3511 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3512 e
.SetPane(evt
.pane
);
3521 else if (evt
.button
== wxPaneInfo::buttonPin
)
3523 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&