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"
41 //#include "wx/dcbuffer.h"
45 WX_CHECK_BUILD_OPTIONS("wxAUI")
47 #include "wx/arrimpl.cpp"
48 WX_DECLARE_OBJARRAY(wxRect
, wxAuiRectArray
);
49 WX_DEFINE_OBJARRAY(wxAuiRectArray
)
50 WX_DEFINE_OBJARRAY(wxDockUIPartArray
)
51 WX_DEFINE_OBJARRAY(wxDockInfoArray
)
52 WX_DEFINE_OBJARRAY(wxPaneButtonArray
)
53 WX_DEFINE_OBJARRAY(wxPaneInfoArray
)
55 wxPaneInfo wxNullPaneInfo
;
56 wxDockInfo wxNullDockInfo
;
57 DEFINE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON
)
60 // a few defines to avoid nameclashes
61 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
63 #include "wx/mac/private.h"
67 // -- static utility functions --
69 static wxBitmap
wxPaneCreateStippleBitmap()
71 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
72 wxImage
img(2,2,data
,true);
76 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
78 wxBitmap stipple
= wxPaneCreateStippleBitmap();
79 wxBrush
brush(stipple
);
81 dc
.SetPen(*wxTRANSPARENT_PEN
);
83 dc
.SetLogicalFunction(wxXOR
);
84 dc
.DrawRectangle(rect
);
89 // on supported windows systems (Win2000 and greater), this function
90 // will make a frame window transparent by a certain amount
91 static void MakeWindowTransparent(wxWindow
* wnd
, int amount
)
93 // this API call is not in all SDKs, only the newer ones, so
94 // we will runtime bind this
95 typedef DWORD (WINAPI
*PSETLAYEREDWINDOWATTR
)(HWND
, DWORD
, BYTE
, DWORD
);
96 static PSETLAYEREDWINDOWATTR pSetLayeredWindowAttributes
= NULL
;
97 static HMODULE h
= NULL
;
98 HWND hwnd
= (HWND
)wnd
->GetHWND();
101 h
= LoadLibrary(_T("user32"));
103 if (!pSetLayeredWindowAttributes
)
105 pSetLayeredWindowAttributes
=
106 (PSETLAYEREDWINDOWATTR
)GetProcAddress(h
,"SetLayeredWindowAttributes");
109 if (pSetLayeredWindowAttributes
== NULL
)
112 LONG exstyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
113 if (0 == (exstyle
& 0x80000) /*WS_EX_LAYERED*/)
114 SetWindowLong(hwnd
, GWL_EXSTYLE
, exstyle
| 0x80000 /*WS_EX_LAYERED*/);
116 pSetLayeredWindowAttributes(hwnd
, 0, (BYTE
)amount
, 2 /*LWA_ALPHA*/);
122 // CopyDocksAndPanes() - this utility function creates copies of
123 // the dock and pane info. wxDockInfo's usually contain pointers
124 // to wxPaneInfo classes, thus this function is necessary to reliably
125 // reconstruct that relationship in the new dock info and pane info arrays
127 static void CopyDocksAndPanes(wxDockInfoArray
& dest_docks
,
128 wxPaneInfoArray
& dest_panes
,
129 const wxDockInfoArray
& src_docks
,
130 const wxPaneInfoArray
& src_panes
)
132 dest_docks
= src_docks
;
133 dest_panes
= src_panes
;
134 int i
, j
, k
, dock_count
, pc1
, pc2
;
135 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
137 wxDockInfo
& dock
= dest_docks
.Item(i
);
138 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
139 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
140 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
141 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
145 // GetMaxLayer() is an internal function which returns
146 // the highest layer inside the specified dock
147 static int GetMaxLayer(const wxDockInfoArray
& docks
, int dock_direction
)
149 int i
, dock_count
, max_layer
= 0;
150 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
152 wxDockInfo
& dock
= docks
.Item(i
);
153 if (dock
.dock_direction
== dock_direction
&&
154 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
155 max_layer
= dock
.dock_layer
;
161 // GetMaxRow() is an internal function which returns
162 // the highest layer inside the specified dock
163 static int GetMaxRow(const wxPaneInfoArray
& panes
, int direction
, int layer
)
165 int i
, pane_count
, max_row
= 0;
166 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
168 wxPaneInfo
& pane
= panes
.Item(i
);
169 if (pane
.dock_direction
== direction
&&
170 pane
.dock_layer
== layer
&&
171 pane
.dock_row
> max_row
)
172 max_row
= pane
.dock_row
;
179 // DoInsertDockLayer() is an internal function that inserts a new dock
180 // layer by incrementing all existing dock layer values by one
181 static void DoInsertDockLayer(wxPaneInfoArray
& panes
,
186 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
188 wxPaneInfo
& pane
= panes
.Item(i
);
189 if (!pane
.IsFloating() &&
190 pane
.dock_direction
== dock_direction
&&
191 pane
.dock_layer
>= dock_layer
)
196 // DoInsertDockLayer() is an internal function that inserts a new dock
197 // row by incrementing all existing dock row values by one
198 static void DoInsertDockRow(wxPaneInfoArray
& panes
,
204 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
206 wxPaneInfo
& pane
= panes
.Item(i
);
207 if (!pane
.IsFloating() &&
208 pane
.dock_direction
== dock_direction
&&
209 pane
.dock_layer
== dock_layer
&&
210 pane
.dock_row
>= dock_row
)
215 // DoInsertDockLayer() is an internal function that inserts a space for
216 // another dock pane by incrementing all existing dock row values by one
217 static void DoInsertPane(wxPaneInfoArray
& panes
,
224 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
226 wxPaneInfo
& pane
= panes
.Item(i
);
227 if (!pane
.IsFloating() &&
228 pane
.dock_direction
== dock_direction
&&
229 pane
.dock_layer
== dock_layer
&&
230 pane
.dock_row
== dock_row
&&
231 pane
.dock_pos
>= dock_pos
)
236 // FindDocks() is an internal function that returns a list of docks which meet
237 // the specified conditions in the parameters and returns a sorted array
238 // (sorted by layer and then row)
239 static void FindDocks(wxDockInfoArray
& docks
,
243 wxDockInfoPtrArray
& arr
)
245 int begin_layer
= dock_layer
;
246 int end_layer
= dock_layer
;
247 int begin_row
= dock_row
;
248 int end_row
= dock_row
;
249 int dock_count
= docks
.GetCount();
250 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
252 // discover the maximum dock layer and the max row
253 for (i
= 0; i
< dock_count
; ++i
)
255 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
256 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
259 // if no dock layer was specified, search all dock layers
260 if (dock_layer
== -1)
263 end_layer
= max_layer
;
266 // if no dock row was specified, search all dock row
275 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
276 for (row
= begin_row
; row
<= end_row
; ++row
)
277 for (i
= 0; i
< dock_count
; ++i
)
279 wxDockInfo
& d
= docks
.Item(i
);
280 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
282 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
288 // FindPaneInDock() looks up a specified window pointer inside a dock.
289 // If found, the corresponding wxPaneInfo pointer is returned, otherwise NULL.
290 static wxPaneInfo
* FindPaneInDock(const wxDockInfo
& dock
, wxWindow
* window
)
292 int i
, count
= dock
.panes
.GetCount();
293 for (i
= 0; i
< count
; ++i
)
295 wxPaneInfo
* p
= dock
.panes
.Item(i
);
296 if (p
->window
== window
)
302 // RemovePaneFromDocks() removes a pane window from all docks
303 // with a possible exception specified by parameter "except"
304 static void RemovePaneFromDocks(wxDockInfoArray
& docks
,
306 wxDockInfo
* except
= NULL
)
309 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
311 wxDockInfo
& d
= docks
.Item(i
);
314 wxPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
320 // RenumberDockRows() takes a dock and assigns sequential numbers
321 // to existing rows. Basically it takes out the gaps; so if a
322 // dock has rows with numbers 0,2,5, they will become 0,1,2
323 static void RenumberDockRows(wxDockInfoPtrArray
& docks
)
325 int i
, dock_count
, j
, pane_count
;
326 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
328 wxDockInfo
& dock
= *docks
.Item(i
);
330 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
331 dock
.panes
.Item(j
)->dock_row
= i
;
337 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
340 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
342 wxPaneInfo
& pane
= panes
.Item(i
);
343 pane
.state
&= ~wxPaneInfo::optionActive
;
344 if (pane
.window
== active_pane
)
345 pane
.state
|= wxPaneInfo::optionActive
;
350 // this function is used to sort panes by dock position
351 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
353 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
357 // -- wxFrameManager class implementation --
360 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
361 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
362 EVT_PAINT(wxFrameManager::OnPaint
)
363 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
364 EVT_SIZE(wxFrameManager::OnSize
)
365 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
366 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
367 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
368 EVT_MOTION(wxFrameManager::OnMotion
)
369 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
370 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
371 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
375 wxFrameManager::wxFrameManager(wxFrame
* frame
, unsigned int flags
)
377 m_action
= actionNone
;
378 m_last_mouse_move
= wxPoint();
379 m_hover_button
= NULL
;
380 m_art
= new wxDefaultDockArt
;
390 wxFrameManager::~wxFrameManager()
395 // GetPane() looks up a wxPaneInfo structure based
396 // on the supplied window pointer. Upon failure, GetPane()
397 // returns an empty wxPaneInfo, a condition which can be checked
398 // by calling wxPaneInfo::IsOk().
400 // The pane info's structure may then be modified. Once a pane's
401 // info is modified, wxFrameManager::Update() must be called to
402 // realize the changes in the UI.
404 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
407 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
409 wxPaneInfo
& p
= m_panes
.Item(i
);
410 if (p
.window
== window
)
413 return wxNullPaneInfo
;
416 // this version of GetPane() looks up a pane based on a
417 // 'pane name', see above comment for more info
418 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
421 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
423 wxPaneInfo
& p
= m_panes
.Item(i
);
427 return wxNullPaneInfo
;
430 // GetAllPanes() returns a reference to all the pane info structures
431 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
436 // HitTest() is an internal function which determines
437 // which UI item the specified coordinates are over
438 // (x,y) specify a position in client coordinates
439 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
441 wxDockUIPart
* result
= NULL
;
444 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
446 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
448 // we are not interested in typeDock, because this space
449 // isn't used to draw anything, just for measurements;
450 // besides, the entire dock area is covered with other
451 // rectangles, which we are interested in.
452 if (item
->type
== wxDockUIPart::typeDock
)
455 // if we already have a hit on a more specific item, we are not
456 // interested in a pane hit. If, however, we don't already have
457 // a hit, returning a pane hit is necessary for some operations
458 if ((item
->type
== wxDockUIPart::typePane
||
459 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
462 // if the point is inside the rectangle, we have a hit
463 if (item
->rect
.Inside(x
,y
))
471 // SetFlags() and GetFlags() allow the owner to set various
472 // options which are global to wxFrameManager
473 void wxFrameManager::SetFlags(unsigned int flags
)
478 unsigned int wxFrameManager::GetFlags() const
484 // SetFrame() is usually called once when the frame
485 // manager class is being initialized. "frame" specifies
486 // the frame which should be managed by the frame mananger
487 void wxFrameManager::SetFrame(wxFrame
* frame
)
489 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
492 m_frame
->PushEventHandler(this);
495 // if the owner is going to manage an MDI parent frame,
496 // we need to add the MDI client window as the default
499 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
501 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
502 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
504 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
506 AddPane(client_window
,
507 wxPaneInfo().Name(wxT("mdiclient")).
508 CenterPane().PaneBorder(false));
514 // UnInit() must be called, usually in the destructor
515 // of the frame class. If it is not called, usually this
516 // will result in a crash upon program exit
517 void wxFrameManager::UnInit()
519 m_frame
->RemoveEventHandler(this);
522 // GetFrame() returns the frame pointer being managed by wxFrameManager
523 wxFrame
* wxFrameManager::GetFrame() const
528 wxDockArt
* wxFrameManager::GetArtProvider() const
533 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
535 // first, give the owner frame a chance to override
538 if (m_frame
->ProcessEvent(event
))
545 // SetArtProvider() instructs wxFrameManager to use the
546 // specified art provider for all drawing calls. This allows
547 // plugable look-and-feel features
548 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
550 // delete the last art provider, if any
553 // assign the new art provider
554 m_art
= art_provider
;
557 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
559 // check if the pane has a valid window
563 // check if the pane already exists
564 if (GetPane(pane_info
.window
).IsOk())
567 m_panes
.Add(pane_info
);
569 wxPaneInfo
& pinfo
= m_panes
.Last();
571 // set the pane window
572 pinfo
.window
= window
;
574 // if the pane's name identifier is blank, create a random string
575 if (pinfo
.name
.empty())
577 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
578 ((unsigned long)pinfo
.window
) & 0xffffffff,
579 (unsigned int)time(NULL
),
580 (unsigned int)clock(),
581 (unsigned long)m_panes
.GetCount());
584 // set initial proportion (if not already set)
585 if (pinfo
.dock_proportion
== 0)
586 pinfo
.dock_proportion
= 100000;
588 if (pinfo
.HasCloseButton() &&
589 pinfo
.buttons
.size() == 0)
592 button
.button_id
= wxPaneInfo::buttonClose
;
593 pinfo
.buttons
.Add(button
);
596 if (pinfo
.best_size
== wxDefaultSize
&&
599 pinfo
.best_size
= pinfo
.window
->GetClientSize();
601 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
603 // GetClientSize() doesn't get the best size for
604 // a toolbar under some newer versions of wxWidgets,
605 // so use GetBestSize()
606 pinfo
.best_size
= pinfo
.window
->GetBestSize();
608 // for some reason, wxToolBar::GetBestSize() is returning
609 // a size that is a pixel shy of the correct amount.
610 // I believe this to be the correct action, until
611 // wxToolBar::GetBestSize() is fixed. Is this assumption
616 if (pinfo
.min_size
!= wxDefaultSize
)
618 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
619 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
620 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
621 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
628 bool wxFrameManager::AddPane(wxWindow
* window
,
630 const wxString
& caption
)
633 pinfo
.Caption(caption
);
636 case wxTOP
: pinfo
.Top(); break;
637 case wxBOTTOM
: pinfo
.Bottom(); break;
638 case wxLEFT
: pinfo
.Left(); break;
639 case wxRIGHT
: pinfo
.Right(); break;
640 case wxCENTER
: pinfo
.CenterPane(); break;
642 return AddPane(window
, pinfo
);
645 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
648 // shift the panes around, depending on the insert level
649 switch (insert_level
)
651 case wxAUI_INSERT_PANE
:
652 DoInsertPane(m_panes
,
653 pane_info
.dock_direction
,
654 pane_info
.dock_layer
,
658 case wxAUI_INSERT_ROW
:
659 DoInsertDockRow(m_panes
,
660 pane_info
.dock_direction
,
661 pane_info
.dock_layer
,
664 case wxAUI_INSERT_DOCK
:
665 DoInsertDockLayer(m_panes
,
666 pane_info
.dock_direction
,
667 pane_info
.dock_layer
);
671 // if the window already exists, we are basically just moving/inserting the
672 // existing window. If it doesn't exist, we need to add it and insert it
673 wxPaneInfo
& existing_pane
= GetPane(window
);
674 if (!existing_pane
.IsOk())
676 return AddPane(window
, pane_info
);
680 if (pane_info
.IsFloating())
682 existing_pane
.Float();
683 if (pane_info
.floating_pos
!= wxDefaultPosition
)
684 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
685 if (pane_info
.floating_size
!= wxDefaultSize
)
686 existing_pane
.FloatingSize(pane_info
.floating_size
);
690 existing_pane
.Direction(pane_info
.dock_direction
);
691 existing_pane
.Layer(pane_info
.dock_layer
);
692 existing_pane
.Row(pane_info
.dock_row
);
693 existing_pane
.Position(pane_info
.dock_pos
);
701 bool wxFrameManager::DetachPane(wxWindow
* window
)
704 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
706 wxPaneInfo
& p
= m_panes
.Item(i
);
707 if (p
.window
== window
)
711 // we have a floating frame which is being detached. We need to
712 // reparent it to m_frame and destroy the floating frame
715 p
.window
->SetSize(1,1);
716 p
.frame
->Show(false);
718 // reparent to m_frame and destroy the pane
719 p
.window
->Reparent(m_frame
);
720 p
.frame
->SetSizer(NULL
);
732 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
733 // in the input string. This is an internal functions which is
734 // used for saving perspectives
735 static wxString
EscapeDelimiters(const wxString
& s
)
738 result
.Alloc(s
.length());
739 const wxChar
* ch
= s
.c_str();
742 if (*ch
== wxT(';') || *ch
== wxT('|'))
751 // SavePerspective() saves all pane information as a single string.
752 // This string may later be fed into LoadPerspective() to restore
753 // all pane settings. This save and load mechanism allows an
754 // exact pane configuration to be saved and restored at a later time
756 wxString
wxFrameManager::SavePerspective()
760 result
= wxT("layout1|");
762 int pane_i
, pane_count
= m_panes
.GetCount();
763 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
765 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
767 result
+= wxT("name=");
768 result
+= EscapeDelimiters(pane
.name
);
771 result
+= wxT("caption=");
772 result
+= EscapeDelimiters(pane
.caption
);
775 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
776 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
777 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
778 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
779 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
780 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
781 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
782 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
783 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
784 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
785 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
786 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
787 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
788 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
789 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
790 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
794 int dock_i
, dock_count
= m_docks
.GetCount();
795 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
797 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
799 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
800 dock
.dock_direction
, dock
.dock_layer
,
801 dock
.dock_row
, dock
.size
);
807 // LoadPerspective() loads a layout which was saved with SavePerspective()
808 // If the "update" flag parameter is true, the GUI will immediately be updated
810 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
812 wxString input
= layout
;
815 // check layout string version
816 part
= input
.BeforeFirst(wxT('|'));
817 input
= input
.AfterFirst(wxT('|'));
820 if (part
!= wxT("layout1"))
824 // mark all panes currently managed as docked and hidden
825 int pane_i
, pane_count
= m_panes
.GetCount();
826 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
827 m_panes
.Item(pane_i
).Dock().Hide();
829 // clear out the dock array; this will be reconstructed
832 // replace escaped characters so we can
833 // split up the string easily
834 input
.Replace(wxT("\\|"), wxT("\a"));
835 input
.Replace(wxT("\\;"), wxT("\b"));
841 wxString pane_part
= input
.BeforeFirst(wxT('|'));
842 input
= input
.AfterFirst(wxT('|'));
843 pane_part
.Trim(true);
845 // if the string is empty, we're done parsing
846 if (pane_part
.empty())
850 if (pane_part
.Left(9) == wxT("dock_size"))
852 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
853 wxString value
= pane_part
.AfterFirst(wxT('='));
855 long dir
, layer
, row
, size
;
856 wxString piece
= val_name
.AfterFirst(wxT('('));
857 piece
= piece
.BeforeLast(wxT(')'));
858 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
859 piece
= piece
.AfterFirst(wxT(','));
860 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
861 piece
.AfterFirst(wxT(',')).ToLong(&row
);
865 dock
.dock_direction
= dir
;
866 dock
.dock_layer
= layer
;
875 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
876 pane_part
= pane_part
.AfterFirst(wxT(';'));
877 wxString val_name
= val_part
.BeforeFirst(wxT('='));
878 wxString value
= val_part
.AfterFirst(wxT('='));
879 val_name
.MakeLower();
881 val_name
.Trim(false);
885 if (val_name
.empty())
888 if (val_name
== wxT("name"))
890 else if (val_name
== wxT("caption"))
891 pane
.caption
= value
;
892 else if (val_name
== wxT("state"))
893 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
894 else if (val_name
== wxT("dir"))
895 pane
.dock_direction
= wxAtoi(value
.c_str());
896 else if (val_name
== wxT("layer"))
897 pane
.dock_layer
= wxAtoi(value
.c_str());
898 else if (val_name
== wxT("row"))
899 pane
.dock_row
= wxAtoi(value
.c_str());
900 else if (val_name
== wxT("pos"))
901 pane
.dock_pos
= wxAtoi(value
.c_str());
902 else if (val_name
== wxT("prop"))
903 pane
.dock_proportion
= wxAtoi(value
.c_str());
904 else if (val_name
== wxT("bestw"))
905 pane
.best_size
.x
= wxAtoi(value
.c_str());
906 else if (val_name
== wxT("besth"))
907 pane
.best_size
.y
= wxAtoi(value
.c_str());
908 else if (val_name
== wxT("minw"))
909 pane
.min_size
.x
= wxAtoi(value
.c_str());
910 else if (val_name
== wxT("minh"))
911 pane
.min_size
.y
= wxAtoi(value
.c_str());
912 else if (val_name
== wxT("maxw"))
913 pane
.max_size
.x
= wxAtoi(value
.c_str());
914 else if (val_name
== wxT("maxh"))
915 pane
.max_size
.y
= wxAtoi(value
.c_str());
916 else if (val_name
== wxT("floatx"))
917 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
918 else if (val_name
== wxT("floaty"))
919 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
920 else if (val_name
== wxT("floatw"))
921 pane
.floating_size
.x
= wxAtoi(value
.c_str());
922 else if (val_name
== wxT("floath"))
923 pane
.floating_size
.y
= wxAtoi(value
.c_str());
925 wxFAIL_MSG(wxT("Bad Perspective String"));
929 // replace escaped characters so we can
930 // split up the string easily
931 pane
.name
.Replace(wxT("\a"), wxT("|"));
932 pane
.name
.Replace(wxT("\b"), wxT(";"));
933 pane
.caption
.Replace(wxT("\a"), wxT("|"));
934 pane
.caption
.Replace(wxT("\b"), wxT(";"));
936 wxPaneInfo
& p
= GetPane(pane
.name
);
939 // the pane window couldn't be found
940 // in the existing layout
944 pane
.window
= p
.window
;
945 pane
.frame
= p
.frame
;
946 pane
.buttons
= p
.buttons
;
957 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
958 wxArrayInt
& positions
,
961 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
962 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
963 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
968 int offset
, action_pane
= -1;
969 int pane_i
, pane_count
= dock
.panes
.GetCount();
971 // find the pane marked as our action pane
972 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
974 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
976 if (pane
.state
& wxPaneInfo::actionPane
)
978 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
979 action_pane
= pane_i
;
983 // set up each panes default position, and
984 // determine the size (width or height, depending
985 // on the dock's orientation) of each pane
986 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
988 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
989 positions
.Add(pane
.dock_pos
);
992 if (pane
.HasBorder())
993 size
+= (pane_border_size
*2);
995 if (dock
.IsHorizontal())
997 if (pane
.HasGripper() && !pane
.HasGripperTop())
998 size
+= gripper_size
;
999 size
+= pane
.best_size
.x
;
1003 if (pane
.HasGripper() && pane
.HasGripperTop())
1004 size
+= gripper_size
;
1006 if (pane
.HasCaption())
1007 size
+= caption_size
;
1008 size
+= pane
.best_size
.y
;
1014 // if there is no action pane, just return the default
1015 // positions (as specified in pane.pane_pos)
1016 if (action_pane
== -1)
1020 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1022 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1027 positions
[pane_i
] -= -amount
;
1029 offset
+= sizes
[pane_i
];
1032 // if the dock mode is fixed, make sure none of the panes
1033 // overlap; we will bump panes that overlap
1035 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1037 int amount
= positions
[pane_i
] - offset
;
1041 positions
[pane_i
] += -amount
;
1043 offset
+= sizes
[pane_i
];
1048 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1051 wxDockUIPartArray
& uiparts
,
1055 wxSizerItem
* sizer_item
;
1057 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1058 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1059 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1060 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1062 // find out the orientation of the item (orientation for panes
1063 // is the same as the dock's orientation)
1065 if (dock
.IsHorizontal())
1066 orientation
= wxHORIZONTAL
;
1068 orientation
= wxVERTICAL
;
1070 // this variable will store the proportion
1071 // value that the pane will receive
1072 int pane_proportion
= pane
.dock_proportion
;
1074 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1075 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1077 if (pane
.HasGripper())
1079 if (pane
.HasGripperTop())
1080 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1082 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1084 part
.type
= wxDockUIPart::typeGripper
;
1088 part
.orientation
= orientation
;
1089 part
.cont_sizer
= horz_pane_sizer
;
1090 part
.sizer_item
= sizer_item
;
1094 if (pane
.HasCaption())
1096 // create the caption sizer
1097 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1099 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1101 part
.type
= wxDockUIPart::typeCaption
;
1105 part
.orientation
= orientation
;
1106 part
.cont_sizer
= vert_pane_sizer
;
1107 part
.sizer_item
= sizer_item
;
1108 int caption_part_idx
= uiparts
.GetCount();
1111 // add pane buttons to the caption
1112 int i
, button_count
;
1113 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1114 i
< button_count
; ++i
)
1116 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1118 sizer_item
= caption_sizer
->Add(pane_button_size
,
1122 part
.type
= wxDockUIPart::typePaneButton
;
1125 part
.button
= &button
;
1126 part
.orientation
= orientation
;
1127 part
.cont_sizer
= caption_sizer
;
1128 part
.sizer_item
= sizer_item
;
1132 // add the caption sizer
1133 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1135 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1138 // add the pane window itself
1141 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1145 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1146 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1149 part
.type
= wxDockUIPart::typePane
;
1153 part
.orientation
= orientation
;
1154 part
.cont_sizer
= vert_pane_sizer
;
1155 part
.sizer_item
= sizer_item
;
1159 // determine if the pane should have a minimum size; if the pane is
1160 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1161 // if the pane.min_size is set, we must use that value as well
1163 wxSize min_size
= pane
.min_size
;
1166 if (min_size
== wxDefaultSize
)
1168 min_size
= pane
.best_size
;
1169 pane_proportion
= 0;
1173 if (min_size
!= wxDefaultSize
)
1175 vert_pane_sizer
->SetItemMinSize(
1176 vert_pane_sizer
->GetChildren().GetCount()-1,
1177 min_size
.x
, min_size
.y
);
1181 // add the verticle sizer (caption, pane window) to the
1182 // horizontal sizer (gripper, verticle sizer)
1183 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1185 // finally, add the pane sizer to the dock sizer
1187 if (pane
.HasBorder())
1189 // allowing space for the pane's border
1190 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1191 wxEXPAND
| wxALL
, pane_border_size
);
1193 part
.type
= wxDockUIPart::typePaneBorder
;
1197 part
.orientation
= orientation
;
1198 part
.cont_sizer
= cont
;
1199 part
.sizer_item
= sizer_item
;
1204 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1208 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1210 wxDockUIPartArray
& uiparts
,
1213 wxSizerItem
* sizer_item
;
1216 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1217 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1219 // resizable bottom and right docks have a sash before them
1220 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1221 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1223 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1225 part
.type
= wxDockUIPart::typeDockSizer
;
1226 part
.orientation
= orientation
;
1230 part
.cont_sizer
= cont
;
1231 part
.sizer_item
= sizer_item
;
1235 // create the sizer for the dock
1236 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1238 // add each pane to the dock
1239 int pane_i
, pane_count
= dock
.panes
.GetCount();
1243 wxArrayInt pane_positions
, pane_sizes
;
1245 // figure out the real pane positions we will
1246 // use, without modifying the each pane's pane_pos member
1247 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1250 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1252 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1253 int pane_pos
= pane_positions
.Item(pane_i
);
1255 int amount
= pane_pos
- offset
;
1258 if (dock
.IsVertical())
1259 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1261 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1263 part
.type
= wxDockUIPart::typeBackground
;
1267 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1268 part
.cont_sizer
= dock_sizer
;
1269 part
.sizer_item
= sizer_item
;
1275 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1277 offset
+= pane_sizes
.Item(pane_i
);
1280 // at the end add a very small stretchable background area
1281 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1283 part
.type
= wxDockUIPart::typeBackground
;
1287 part
.orientation
= orientation
;
1288 part
.cont_sizer
= dock_sizer
;
1289 part
.sizer_item
= sizer_item
;
1294 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1296 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1298 // if this is not the first pane being added,
1299 // we need to add a pane sizer
1302 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1304 part
.type
= wxDockUIPart::typePaneSizer
;
1306 part
.pane
= dock
.panes
.Item(pane_i
-1);
1308 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1309 part
.cont_sizer
= dock_sizer
;
1310 part
.sizer_item
= sizer_item
;
1314 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1318 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1319 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1321 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1323 part
.type
= wxDockUIPart::typeDock
;
1327 part
.orientation
= orientation
;
1328 part
.cont_sizer
= cont
;
1329 part
.sizer_item
= sizer_item
;
1332 if (dock
.IsHorizontal())
1333 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1335 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1337 // top and left docks have a sash after them
1338 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1339 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1341 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1343 part
.type
= wxDockUIPart::typeDockSizer
;
1347 part
.orientation
= orientation
;
1348 part
.cont_sizer
= cont
;
1349 part
.sizer_item
= sizer_item
;
1354 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1355 wxDockInfoArray
& docks
,
1356 wxDockUIPartArray
& uiparts
,
1359 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1361 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1362 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1363 wxSize cli_size
= m_frame
->GetClientSize();
1364 int i
, dock_count
, pane_count
;
1367 // empty all docks out
1368 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1369 docks
.Item(i
).panes
.Empty();
1371 // iterate through all known panes, filing each
1372 // of them into the appropriate dock. If the
1373 // pane does not exist in the dock, add it
1374 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1376 wxPaneInfo
& p
= panes
.Item(i
);
1378 // find any docks in this layer
1380 wxDockInfoPtrArray arr
;
1381 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1383 if (arr
.GetCount() > 0)
1389 // dock was not found, so we need to create a new one
1391 d
.dock_direction
= p
.dock_direction
;
1392 d
.dock_layer
= p
.dock_layer
;
1393 d
.dock_row
= p
.dock_row
;
1395 dock
= &docks
.Last();
1399 if (p
.IsDocked() && p
.IsShown())
1401 // remove the pane from any existing docks except this one
1402 RemovePaneFromDocks(docks
, p
, dock
);
1404 // pane needs to be added to the dock,
1405 // if it doesn't already exist
1406 if (!FindPaneInDock(*dock
, p
.window
))
1407 dock
->panes
.Add(&p
);
1411 // remove the pane from any existing docks
1412 RemovePaneFromDocks(docks
, p
);
1417 // remove any empty docks
1418 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1420 if (docks
.Item(i
).panes
.GetCount() == 0)
1424 // configure the docks further
1425 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1427 wxDockInfo
& dock
= docks
.Item(i
);
1428 int j
, dock_pane_count
= dock
.panes
.GetCount();
1430 // sort the dock pane array by the pane's
1431 // dock position (dock_pos), in ascending order
1432 dock
.panes
.Sort(PaneSortFunc
);
1434 // for newly created docks, set up their initial size
1439 for (j
= 0; j
< dock_pane_count
; ++j
)
1441 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1442 wxSize pane_size
= pane
.best_size
;
1443 if (pane_size
== wxDefaultSize
)
1444 pane_size
= pane
.min_size
;
1445 if (pane_size
== wxDefaultSize
)
1446 pane_size
= pane
.window
->GetSize();
1448 if (dock
.IsHorizontal())
1449 size
= wxMax(pane_size
.y
, size
);
1451 size
= wxMax(pane_size
.x
, size
);
1454 // add space for the border (two times), but only
1455 // if at least one pane inside the dock has a pane border
1456 for (j
= 0; j
< dock_pane_count
; ++j
)
1458 if (dock
.panes
.Item(j
)->HasBorder())
1460 size
+= (pane_border_size
*2);
1465 // if pane is on the top or bottom, add the caption height,
1466 // but only if at least one pane inside the dock has a caption
1467 if (dock
.IsHorizontal())
1469 for (j
= 0; j
< dock_pane_count
; ++j
)
1471 if (dock
.panes
.Item(j
)->HasCaption())
1473 size
+= caption_size
;
1479 // new dock's size may not be more than 1/3 of the frame size
1480 if (dock
.IsHorizontal())
1481 size
= wxMin(size
, cli_size
.y
/3);
1483 size
= wxMin(size
, cli_size
.x
/3);
1491 // determine the dock's minimum size
1492 bool plus_border
= false;
1493 bool plus_caption
= false;
1494 int dock_min_size
= 0;
1495 for (j
= 0; j
< dock_pane_count
; ++j
)
1497 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1498 if (pane
.min_size
!= wxDefaultSize
)
1500 if (pane
.HasBorder())
1502 if (pane
.HasCaption())
1503 plus_caption
= true;
1504 if (dock
.IsHorizontal())
1506 if (pane
.min_size
.y
> dock_min_size
)
1507 dock_min_size
= pane
.min_size
.y
;
1511 if (pane
.min_size
.x
> dock_min_size
)
1512 dock_min_size
= pane
.min_size
.x
;
1518 dock_min_size
+= (pane_border_size
*2);
1519 if (plus_caption
&& dock
.IsHorizontal())
1520 dock_min_size
+= (caption_size
);
1522 dock
.min_size
= dock_min_size
;
1525 // if the pane's current size is less than it's
1526 // minimum, increase the dock's size to it's minimum
1527 if (dock
.size
< dock
.min_size
)
1528 dock
.size
= dock
.min_size
;
1531 // determine the dock's mode (fixed or proportional);
1532 // determine whether the dock has only toolbars
1533 bool action_pane_marked
= false;
1535 dock
.toolbar
= true;
1536 for (j
= 0; j
< dock_pane_count
; ++j
)
1538 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1539 if (!pane
.IsFixed())
1541 if (!pane
.IsToolbar())
1542 dock
.toolbar
= false;
1543 if (pane
.state
& wxPaneInfo::actionPane
)
1544 action_pane_marked
= true;
1548 // if the dock mode is proportional and not fixed-pixel,
1549 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1550 // e.g. remove gaps like 1, 2, 30, 500
1553 for (j
= 0; j
< dock_pane_count
; ++j
)
1555 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1560 // if the dock mode is fixed, and none of the panes
1561 // are being moved right now, make sure the panes
1562 // do not overlap each other. If they do, we will
1563 // adjust the panes' positions
1564 if (dock
.fixed
&& !action_pane_marked
)
1566 wxArrayInt pane_positions
, pane_sizes
;
1567 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1570 for (j
= 0; j
< dock_pane_count
; ++j
)
1572 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1573 pane
.dock_pos
= pane_positions
[j
];
1575 int amount
= pane
.dock_pos
- offset
;
1579 pane
.dock_pos
+= -amount
;
1581 offset
+= pane_sizes
[j
];
1586 // discover the maximum dock layer
1588 for (i
= 0; i
< dock_count
; ++i
)
1589 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1592 // clear out uiparts
1595 // create a bunch of box sizers,
1596 // from the innermost level outwards.
1597 wxSizer
* cont
= NULL
;
1598 wxSizer
* middle
= NULL
;
1602 for (layer
= 0; layer
<= max_layer
; ++layer
)
1604 wxDockInfoPtrArray arr
;
1606 // find any docks in this layer
1607 FindDocks(docks
, -1, layer
, -1, arr
);
1609 // if there aren't any, skip to the next layer
1613 wxSizer
* old_cont
= cont
;
1615 // create a container which will hold this layer's
1616 // docks (top, bottom, left, right)
1617 cont
= new wxBoxSizer(wxVERTICAL
);
1620 // find any top docks in this layer
1621 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1622 RenumberDockRows(arr
);
1625 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1626 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1630 // fill out the middle layer (which consists
1631 // of left docks, content area and right docks)
1633 middle
= new wxBoxSizer(wxHORIZONTAL
);
1635 // find any left docks in this layer
1636 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1637 RenumberDockRows(arr
);
1640 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1641 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1644 // add content dock (or previous layer's sizer
1648 // find any center docks
1649 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1652 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1653 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1657 // there are no center docks, add a background area
1658 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1660 part
.type
= wxDockUIPart::typeBackground
;
1664 part
.cont_sizer
= middle
;
1665 part
.sizer_item
= sizer_item
;
1671 middle
->Add(old_cont
, 1, wxEXPAND
);
1674 // find any right docks in this layer
1675 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1676 RenumberDockRows(arr
);
1679 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1680 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1683 cont
->Add(middle
, 1, wxEXPAND
);
1687 // find any bottom docks in this layer
1688 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1689 RenumberDockRows(arr
);
1692 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1693 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1700 // no sizer available, because there are no docks,
1701 // therefore we will create a simple background area
1702 cont
= new wxBoxSizer(wxVERTICAL
);
1703 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1705 part
.type
= wxDockUIPart::typeBackground
;
1709 part
.cont_sizer
= middle
;
1710 part
.sizer_item
= sizer_item
;
1714 container
->Add(cont
, 1, wxEXPAND
);
1719 // Update() updates the layout. Whenever changes are made to
1720 // one or more panes, this function should be called. It is the
1721 // external entry point for running the layout engine.
1723 void wxFrameManager::Update()
1726 int i
, pane_count
= m_panes
.GetCount();
1728 // delete old sizer first
1729 m_frame
->SetSizer(NULL
);
1731 // destroy floating panes which have been
1732 // redocked or are becoming non-floating
1733 for (i
= 0; i
< pane_count
; ++i
)
1735 wxPaneInfo
& p
= m_panes
.Item(i
);
1737 if (!p
.IsFloating() && p
.frame
)
1739 // because the pane is no longer in a floating, we need to
1740 // reparent it to m_frame and destroy the floating frame
1743 p
.window
->SetSize(1,1);
1744 p
.frame
->Show(false);
1746 // reparent to m_frame and destroy the pane
1747 p
.window
->Reparent(m_frame
);
1748 p
.frame
->SetSizer(NULL
);
1755 // create a layout for all of the panes
1756 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
1758 // hide or show panes as necessary,
1759 // and float panes as necessary
1760 for (i
= 0; i
< pane_count
; ++i
)
1762 wxPaneInfo
& p
= m_panes
.Item(i
);
1766 if (p
.frame
== NULL
)
1768 // we need to create a frame for this
1769 // pane, which has recently been floated
1770 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
1775 // on MSW, if the owner desires transparent dragging, and
1776 // the dragging is happening right now, then the floating
1777 // window should have this style by default
1779 if (m_action
== actionDragFloatingPane
&&
1780 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
1781 MakeWindowTransparent(frame
, 150);
1784 frame
->SetPaneWindow(p
);
1794 // frame already exists, make sure it's position
1795 // and size reflect the information in wxPaneInfo
1796 if (p
.frame
->GetPosition() != p
.floating_pos
)
1798 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
1799 -1, -1, wxSIZE_USE_EXISTING
);
1800 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
1803 p
.frame
->Show(p
.IsShown());
1808 p
.window
->Show(p
.IsShown());
1811 // if "active panes" are no longer allowed, clear
1812 // any optionActive values from the pane states
1813 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
1815 p
.state
&= ~wxPaneInfo::optionActive
;
1820 // keep track of the old window rectangles so we can
1821 // refresh those windows whose rect has changed
1822 wxAuiRectArray old_pane_rects
;
1823 for (i
= 0; i
< pane_count
; ++i
)
1826 wxPaneInfo
& p
= m_panes
.Item(i
);
1828 if (p
.window
&& p
.IsShown() && p
.IsDocked())
1831 old_pane_rects
.Add(r
);
1837 // apply the new sizer
1838 m_frame
->SetSizer(sizer
);
1839 m_frame
->SetAutoLayout(false);
1844 // now that the frame layout is done, we need to check
1845 // the new pane rectangles against the old rectangles that
1846 // we saved a few lines above here. If the rectangles have
1847 // changed, the corresponding panes must also be updated
1848 for (i
= 0; i
< pane_count
; ++i
)
1850 wxPaneInfo
& p
= m_panes
.Item(i
);
1851 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
1853 if (p
.rect
!= old_pane_rects
[i
])
1855 p
.window
->Refresh();
1864 // set frame's minimum size
1867 // N.B. More work needs to be done on frame minimum sizes;
1868 // this is some intresting code that imposes the minimum size,
1869 // but we may want to include a more flexible mechanism or
1870 // options for multiple minimum-size modes, e.g. strict or lax
1871 wxSize min_size = sizer->GetMinSize();
1872 wxSize frame_size = m_frame->GetSize();
1873 wxSize client_size = m_frame->GetClientSize();
1875 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
1876 min_size.y+frame_size.y-client_size.y );
1878 m_frame->SetMinSize(minframe_size);
1880 if (frame_size.x < minframe_size.x ||
1881 frame_size.y < minframe_size.y)
1882 sizer->Fit(m_frame);
1887 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
1888 // on the frame's main sizer, then measures all the various UI items
1889 // and updates their internal rectangles. This should always be called
1890 // instead of calling m_frame->Layout() directly
1892 void wxFrameManager::DoFrameLayout()
1897 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1899 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1901 // get the rectangle of the UI part
1902 // originally, this code looked like this:
1903 // part.rect = wxRect(part.sizer_item->GetPosition(),
1904 // part.sizer_item->GetSize());
1905 // this worked quite well, with one exception: the mdi
1906 // client window had a "deferred" size variable
1907 // that returned the wrong size. It looks like
1908 // a bug in wx, because the former size of the window
1909 // was being returned. So, we will retrieve the part's
1910 // rectangle via other means
1913 part
.rect
= part
.sizer_item
->GetRect();
1914 int flag
= part
.sizer_item
->GetFlag();
1915 int border
= part
.sizer_item
->GetBorder();
1918 part
.rect
.y
-= border
;
1919 part
.rect
.height
+= border
;
1923 part
.rect
.x
-= border
;
1924 part
.rect
.width
+= border
;
1926 if (flag
& wxBOTTOM
)
1927 part
.rect
.height
+= border
;
1929 part
.rect
.width
+= border
;
1932 if (part
.type
== wxDockUIPart::typeDock
)
1933 part
.dock
->rect
= part
.rect
;
1934 if (part
.type
== wxDockUIPart::typePane
)
1935 part
.pane
->rect
= part
.rect
;
1939 // GetPanePart() looks up the pane the pane border UI part (or the regular
1940 // pane part if there is no border). This allows the caller to get the exact
1941 // rectangle of the pane in question, including decorations like
1942 // caption and border (if any).
1944 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
1947 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1949 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1950 if (part
.type
== wxDockUIPart::typePaneBorder
&&
1951 part
.pane
&& part
.pane
->window
== wnd
)
1954 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1956 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1957 if (part
.type
== wxDockUIPart::typePane
&&
1958 part
.pane
&& part
.pane
->window
== wnd
)
1966 // GetDockPixelOffset() is an internal function which returns
1967 // a dock's offset in pixels from the left side of the window
1968 // (for horizontal docks) or from the top of the window (for
1969 // vertical docks). This value is necessary for calculating
1970 // fixel-pane/toolbar offsets when they are dragged.
1972 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
1974 // the only way to accurately calculate the dock's
1975 // offset is to actually run a theoretical layout
1977 int i
, part_count
, dock_count
;
1978 wxDockInfoArray docks
;
1979 wxPaneInfoArray panes
;
1980 wxDockUIPartArray uiparts
;
1981 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
1984 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
1985 wxSize client_size
= m_frame
->GetClientSize();
1986 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
1989 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
1991 wxDockUIPart
& part
= uiparts
.Item(i
);
1992 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
1993 part
.sizer_item
->GetSize());
1994 if (part
.type
== wxDockUIPart::typeDock
)
1995 part
.dock
->rect
= part
.rect
;
2000 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2002 wxDockInfo
& dock
= docks
.Item(i
);
2003 if (test
.dock_direction
== dock
.dock_direction
&&
2004 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2006 if (dock
.IsVertical())
2018 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2019 // if a dock operation is allowed, the new dock position is copied into
2020 // the target info. If the operation was allowed, the function returns true.
2022 static bool ProcessDockResult(wxPaneInfo
& target
,
2023 const wxPaneInfo
& new_pos
)
2025 bool allowed
= false;
2026 switch (new_pos
.dock_direction
)
2028 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2029 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2030 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2031 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2041 // DoDrop() is an important function. It basically takes a mouse position,
2042 // and determines where the pane's new position would be. If the pane is to be
2043 // dropped, it performs the drop operation using the specified dock and pane
2044 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2045 // scenario can be performed, giving precise coordinates for drop hints.
2046 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2047 // as parameters, the changes will be made to the main state arrays
2049 const int auiInsertRowPixels
= 10;
2050 const int auiNewRowPixels
= 40;
2051 const int auiLayerInsertPixels
= 40;
2052 const int auiLayerInsertOffset
= 5;
2054 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2055 wxPaneInfoArray
& panes
,
2058 const wxPoint
& offset
)
2060 wxSize cli_size
= m_frame
->GetClientSize();
2062 wxPaneInfo drop
= target
;
2065 // The result should always be shown
2069 // Check to see if the pane has been dragged outside of the window
2070 // (or near to the outside of the window), if so, dock it along the edge
2073 int layer_insert_offset
= auiLayerInsertOffset
;
2074 if (target
.IsToolbar())
2075 layer_insert_offset
= 0;
2077 if (pt
.x
< layer_insert_offset
&&
2078 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2080 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2081 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2082 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2086 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2087 return ProcessDockResult(target
, drop
);
2089 else if (pt
.y
< layer_insert_offset
&&
2090 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2092 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2093 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2094 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2098 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2099 return ProcessDockResult(target
, drop
);
2101 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2102 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2104 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2105 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2106 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2107 drop
.Dock().Right().
2110 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2111 return ProcessDockResult(target
, drop
);
2113 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2114 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2116 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2117 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2118 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2119 drop
.Dock().Bottom().
2122 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2123 return ProcessDockResult(target
, drop
);
2127 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2130 if (drop
.IsToolbar())
2132 if (!part
|| !part
->dock
)
2136 // calculate the offset from where the dock begins
2137 // to the point where the user dropped the pane
2138 int dock_drop_offset
= 0;
2139 if (part
->dock
->IsHorizontal())
2140 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2142 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2145 // toolbars may only be moved in and to fixed-pane docks,
2146 // otherwise we will try to float the pane. Also, the pane
2147 // should float if being dragged over center pane windows
2148 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2150 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2151 (drop
.IsFloatable() ||
2152 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2153 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2158 return ProcessDockResult(target
, drop
);
2162 Direction(part
->dock
->dock_direction
).
2163 Layer(part
->dock
->dock_layer
).
2164 Row(part
->dock
->dock_row
).
2165 Position(dock_drop_offset
);
2168 ((pt
.y
< part
->dock
->rect
.y
+ 2) && part
->dock
->IsHorizontal()) ||
2169 ((pt
.x
< part
->dock
->rect
.x
+ 2) && part
->dock
->IsVertical())
2170 ) && part
->dock
->panes
.GetCount() > 1)
2172 int row
= drop
.dock_row
;
2173 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2174 part
->dock
->dock_layer
,
2175 part
->dock
->dock_row
);
2176 drop
.dock_row
= row
;
2180 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2181 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2182 ) && part
->dock
->panes
.GetCount() > 1)
2184 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2185 part
->dock
->dock_layer
,
2186 part
->dock
->dock_row
+1);
2187 drop
.dock_row
= part
->dock
->dock_row
+1;
2190 return ProcessDockResult(target
, drop
);
2199 if (part
->type
== wxDockUIPart::typePaneBorder
||
2200 part
->type
== wxDockUIPart::typeCaption
||
2201 part
->type
== wxDockUIPart::typeGripper
||
2202 part
->type
== wxDockUIPart::typePaneButton
||
2203 part
->type
== wxDockUIPart::typePane
||
2204 part
->type
== wxDockUIPart::typePaneSizer
||
2205 part
->type
== wxDockUIPart::typeDockSizer
||
2206 part
->type
== wxDockUIPart::typeBackground
)
2208 if (part
->type
== wxDockUIPart::typeDockSizer
)
2210 if (part
->dock
->panes
.GetCount() != 1)
2212 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2219 // If a normal frame is being dragged over a toolbar, insert it
2220 // along the edge under the toolbar, but over all other panes.
2221 // (this could be done much better, but somehow factoring this
2222 // calculation with the one at the beginning of this function)
2223 if (part
->dock
&& part
->dock
->toolbar
)
2227 switch (part
->dock
->dock_direction
)
2229 case wxAUI_DOCK_LEFT
:
2230 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2231 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2232 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2234 case wxAUI_DOCK_TOP
:
2235 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2236 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2237 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2239 case wxAUI_DOCK_RIGHT
:
2240 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2241 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2242 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2244 case wxAUI_DOCK_BOTTOM
:
2245 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2246 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2247 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2251 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2254 Direction(part
->dock
->dock_direction
).
2255 Layer(layer
).Row(0).Position(0);
2256 return ProcessDockResult(target
, drop
);
2263 part
= GetPanePart(part
->pane
->window
);
2267 bool insert_dock_row
= false;
2268 int insert_row
= part
->pane
->dock_row
;
2269 int insert_dir
= part
->pane
->dock_direction
;
2270 int insert_layer
= part
->pane
->dock_layer
;
2272 switch (part
->pane
->dock_direction
)
2274 case wxAUI_DOCK_TOP
:
2275 if (pt
.y
>= part
->rect
.y
&&
2276 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2277 insert_dock_row
= true;
2279 case wxAUI_DOCK_BOTTOM
:
2280 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2281 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2282 insert_dock_row
= true;
2284 case wxAUI_DOCK_LEFT
:
2285 if (pt
.x
>= part
->rect
.x
&&
2286 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2287 insert_dock_row
= true;
2289 case wxAUI_DOCK_RIGHT
:
2290 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2291 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2292 insert_dock_row
= true;
2294 case wxAUI_DOCK_CENTER
:
2296 // "new row pixels" will be set to the default, but
2297 // must never exceed 20% of the window size
2298 int new_row_pixels_x
= auiNewRowPixels
;
2299 int new_row_pixels_y
= auiNewRowPixels
;
2301 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2302 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2304 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2305 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2308 // determine if the mouse pointer is in a location that
2309 // will cause a new row to be inserted. The hot spot positions
2310 // are along the borders of the center pane
2313 insert_dock_row
= true;
2314 if (pt
.x
>= part
->rect
.x
&&
2315 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2316 insert_dir
= wxAUI_DOCK_LEFT
;
2318 if (pt
.y
>= part
->rect
.y
&&
2319 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2320 insert_dir
= wxAUI_DOCK_TOP
;
2322 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2323 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2324 insert_dir
= wxAUI_DOCK_RIGHT
;
2326 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2327 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2328 insert_dir
= wxAUI_DOCK_BOTTOM
;
2332 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2336 if (insert_dock_row
)
2338 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2339 drop
.Dock().Direction(insert_dir
).
2340 Layer(insert_layer
).
2343 return ProcessDockResult(target
, drop
);
2346 // determine the mouse offset and the pane size, both in the
2347 // direction of the dock itself, and perpendicular to the dock
2351 if (part
->orientation
== wxVERTICAL
)
2353 offset
= pt
.y
- part
->rect
.y
;
2354 size
= part
->rect
.GetHeight();
2358 offset
= pt
.x
- part
->rect
.x
;
2359 size
= part
->rect
.GetWidth();
2362 int drop_position
= part
->pane
->dock_pos
;
2364 // if we are in the top/left part of the pane,
2365 // insert the pane before the pane being hovered over
2366 if (offset
<= size
/2)
2368 drop_position
= part
->pane
->dock_pos
;
2370 part
->pane
->dock_direction
,
2371 part
->pane
->dock_layer
,
2372 part
->pane
->dock_row
,
2373 part
->pane
->dock_pos
);
2376 // if we are in the bottom/right part of the pane,
2377 // insert the pane before the pane being hovered over
2378 if (offset
> size
/2)
2380 drop_position
= part
->pane
->dock_pos
+1;
2382 part
->pane
->dock_direction
,
2383 part
->pane
->dock_layer
,
2384 part
->pane
->dock_row
,
2385 part
->pane
->dock_pos
+1);
2389 Direction(part
->dock
->dock_direction
).
2390 Layer(part
->dock
->dock_layer
).
2391 Row(part
->dock
->dock_row
).
2392 Position(drop_position
);
2393 return ProcessDockResult(target
, drop
);
2400 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2403 if (!m_hint_wnd
|| m_hint_fadeamt
>= 50)
2405 m_hint_fadetimer
.Stop();
2409 m_hint_fadeamt
+= 5;
2410 MakeWindowTransparent(m_hint_wnd
, m_hint_fadeamt
);
2414 void wxFrameManager::ShowHint(const wxRect
& rect
)
2418 // First, determine if the operating system can handle transparency.
2419 // Transparency is available on Win2000 and above
2421 static int os_type
= -1;
2422 static int ver_major
= -1;
2425 os_type
= ::wxGetOsVersion(&ver_major
);
2427 // If the transparent flag is set, and the OS supports it,
2428 // go ahead and use a transparent hint
2430 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 &&
2431 os_type
== wxWINDOWS_NT
&& ver_major
>= 5)
2433 if (m_last_hint
== rect
)
2437 int initial_fade
= 50;
2438 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2441 if (m_hint_wnd
== NULL
)
2443 wxPoint pt
= rect
.GetPosition();
2444 wxSize size
= rect
.GetSize();
2445 m_hint_wnd
= new wxFrame(m_frame
, -1, wxEmptyString
, pt
, size
,
2446 wxFRAME_TOOL_WINDOW
|
2447 wxFRAME_FLOAT_ON_PARENT
|
2448 wxFRAME_NO_TASKBAR
|
2451 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2452 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
2455 // if we are dragging a floating pane, set the focus
2456 // back to that floating pane (otherwise it becomes unfocused)
2457 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2458 m_action_window
->SetFocus();
2463 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2464 m_hint_wnd
->SetSize(rect
);
2467 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2469 // start fade in timer
2471 m_hint_fadetimer
.SetOwner(this, 101);
2472 m_hint_fadetimer
.Start(5);
2479 if (m_last_hint
!= rect
)
2481 // remove the last hint rectangle
2487 wxScreenDC screendc
;
2488 wxRegion
clip(1, 1, 10000, 10000);
2490 // clip all floating windows, so we don't draw over them
2492 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2494 wxPaneInfo
& pane
= m_panes
.Item(i
);
2496 if (pane
.IsFloating() &&
2497 pane
.frame
->IsShown())
2499 wxRect rect
= pane
.frame
->GetRect();
2501 // wxGTK returns the client size, not the whole frame size
2507 clip
.Subtract(rect
);
2511 screendc
.SetClippingRegion(clip
);
2513 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2514 wxBrush
brush(stipple
);
2515 screendc
.SetBrush(brush
);
2516 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2518 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2519 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2520 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2521 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2524 void wxFrameManager::HideHint()
2526 // hides a transparent window hint (currently wxMSW only)
2530 MakeWindowTransparent(m_hint_wnd
, 0);
2531 m_hint_fadetimer
.Stop();
2532 m_last_hint
= wxRect();
2537 // hides a painted hint by redrawing the frame window
2538 if (!m_last_hint
.IsEmpty())
2542 m_last_hint
= wxRect();
2548 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2549 // determine the exact position the pane would be at were if dropped. If
2550 // the pame would indeed become docked at the specified drop point,
2551 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2552 // "pane_window" is the window pointer of the pane being dragged, pt is
2553 // the mouse position, in client coordinates
2554 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2556 const wxPoint
& offset
)
2560 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2561 // we will create a new temporary layout and then measure the resulting
2562 // rectangle; we will create a copy of the docking structures (m_dock)
2563 // so that we don't modify the real thing on screen
2565 int i
, pane_count
, part_count
;
2566 wxDockInfoArray docks
;
2567 wxPaneInfoArray panes
;
2568 wxDockUIPartArray uiparts
;
2569 wxPaneInfo hint
= GetPane(pane_window
);
2570 hint
.name
= wxT("__HINT__");
2575 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2577 // remove any pane already there which bears the same window;
2578 // this happens when you are moving a pane around in a dock
2579 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2581 if (panes
.Item(i
).window
== pane_window
)
2583 RemovePaneFromDocks(docks
, panes
.Item(i
));
2589 // find out where the new pane would be
2590 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2598 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2599 wxSize client_size
= m_frame
->GetClientSize();
2600 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2603 for (i
= 0, part_count
= uiparts
.GetCount();
2604 i
< part_count
; ++i
)
2606 wxDockUIPart
& part
= uiparts
.Item(i
);
2608 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2609 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2611 rect
= wxRect(part
.sizer_item
->GetPosition(),
2612 part
.sizer_item
->GetSize());
2625 // actually show the hint rectangle on the screen
2626 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2630 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2632 // try to find the pane
2633 wxPaneInfo
& pane
= GetPane(wnd
);
2634 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2637 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2638 MakeWindowTransparent(pane
.frame
, 150);
2642 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
)
2644 // try to find the pane
2645 wxPaneInfo
& pane
= GetPane(wnd
);
2646 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2648 wxPoint pt
= ::wxGetMousePosition();
2649 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2651 // calculate the offset from the upper left-hand corner
2652 // of the frame to the mouse pointer
2653 wxPoint frame_pos
= pane
.frame
->GetPosition();
2654 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2656 // no hint for toolbar floating windows
2657 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
2659 if (m_action
== actionDragFloatingPane
)
2661 wxDockInfoArray docks
;
2662 wxPaneInfoArray panes
;
2663 wxDockUIPartArray uiparts
;
2664 wxPaneInfo hint
= pane
;
2666 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2668 // find out where the new pane would be
2669 if (!DoDrop(docks
, panes
, hint
, client_pt
))
2671 if (hint
.IsFloating())
2675 m_action
= actionDragToolbarPane
;
2676 m_action_window
= pane
.window
;
2685 // if a key modifier is pressed while dragging the frame,
2686 // don't dock the window
2687 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2694 DrawHintRect(wnd
, client_pt
, action_offset
);
2697 // this cleans up some screen artifacts that are caused on GTK because
2698 // we aren't getting the exact size of the window (see comment
2708 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
)
2710 // try to find the pane
2711 wxPaneInfo
& pane
= GetPane(wnd
);
2712 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2714 wxPoint pt
= ::wxGetMousePosition();
2715 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2717 // calculate the offset from the upper left-hand corner
2718 // of the frame to the mouse pointer
2719 wxPoint frame_pos
= pane
.frame
->GetPosition();
2720 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2723 // if a key modifier is pressed while dragging the frame,
2724 // don't dock the window
2725 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2732 // do the drop calculation
2733 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
2735 // if the pane is still floating, update it's floating
2736 // position (that we store)
2737 if (pane
.IsFloating())
2739 pane
.floating_pos
= pane
.frame
->GetPosition();
2742 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2743 MakeWindowTransparent(pane
.frame
, 255);
2752 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
2754 // try to find the pane
2755 wxPaneInfo
& pane
= GetPane(wnd
);
2756 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2758 pane
.floating_size
= size
;
2761 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
)
2763 // try to find the pane
2764 wxPaneInfo
& pane
= GetPane(wnd
);
2765 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2767 // reparent the pane window back to us and
2768 // prepare the frame window for destruction
2769 pane
.window
->Show(false);
2770 pane
.window
->Reparent(m_frame
);
2775 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
2777 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
2779 // try to find the pane
2780 wxPaneInfo
& pane
= GetPane(wnd
);
2781 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2783 SetActivePane(m_panes
, wnd
);
2788 // Render() draws all of the pane captions, sashes,
2789 // backgrounds, captions, grippers, pane borders and buttons.
2790 // It renders the entire user interface.
2792 void wxFrameManager::Render(wxDC
* dc
)
2798 for (i
= 0, part_count
= m_uiparts
.GetCount();
2799 i
< part_count
; ++i
)
2801 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2803 // don't draw hidden pane items
2804 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
2809 case wxDockUIPart::typeDockSizer
:
2810 case wxDockUIPart::typePaneSizer
:
2811 m_art
->DrawSash(*dc
, part
.orientation
, part
.rect
);
2813 case wxDockUIPart::typeBackground
:
2814 m_art
->DrawBackground(*dc
, part
.orientation
, part
.rect
);
2816 case wxDockUIPart::typeCaption
:
2817 m_art
->DrawCaption(*dc
, part
.pane
->caption
, part
.rect
, *part
.pane
);
2819 case wxDockUIPart::typeGripper
:
2820 m_art
->DrawGripper(*dc
, part
.rect
, *part
.pane
);
2822 case wxDockUIPart::typePaneBorder
:
2823 m_art
->DrawBorder(*dc
, part
.rect
, *part
.pane
);
2825 case wxDockUIPart::typePaneButton
:
2826 m_art
->DrawPaneButton(*dc
, part
.button
->button_id
,
2827 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
2833 void wxFrameManager::Repaint(wxDC
* dc
)
2838 m_frame
->Refresh() ;
2844 m_frame
->GetClientSize(&w
, &h
);
2846 // figure out which dc to use; if one
2847 // has been specified, use it, otherwise
2849 wxClientDC
* client_dc
= NULL
;
2852 client_dc
= new wxClientDC(m_frame
);
2856 // if the frame has a toolbar, the client area
2857 // origin will not be (0,0).
2858 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2859 if (pt
.x
!= 0 || pt
.y
!= 0)
2860 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
2862 // render all the items
2865 // if we created a client_dc, delete it
2870 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2872 wxPaintDC
dc(m_frame
);
2876 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
2885 void wxFrameManager::OnSize(wxSizeEvent
& WXUNUSED(event
))
2895 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
2898 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2899 wxCursor cursor
= wxNullCursor
;
2903 if (part
->type
== wxDockUIPart::typeDockSizer
||
2904 part
->type
== wxDockUIPart::typePaneSizer
)
2906 // a dock may not be resized if it has a single
2907 // pane which is not resizable
2908 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
2909 part
->dock
->panes
.GetCount() == 1 &&
2910 part
->dock
->panes
.Item(0)->IsFixed())
2913 // panes that may not be resized do not get a sizing cursor
2914 if (part
->pane
&& part
->pane
->IsFixed())
2917 if (part
->orientation
== wxVERTICAL
)
2918 cursor
= wxCursor(wxCURSOR_SIZEWE
);
2920 cursor
= wxCursor(wxCURSOR_SIZENS
);
2922 else if (part
->type
== wxDockUIPart::typeGripper
)
2924 cursor
= wxCursor(wxCURSOR_SIZING
);
2928 event
.SetCursor(cursor
);
2933 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
2934 const wxMouseEvent
& event
)
2936 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
2938 int state
= wxAUI_BUTTON_STATE_NORMAL
;
2940 if (hit_test
== button_ui_part
)
2942 if (event
.LeftDown())
2943 state
= wxAUI_BUTTON_STATE_PRESSED
;
2945 state
= wxAUI_BUTTON_STATE_HOVER
;
2949 if (event
.LeftDown())
2950 state
= wxAUI_BUTTON_STATE_HOVER
;
2953 // now repaint the button with hover state
2954 wxClientDC
cdc(m_frame
);
2956 // if the frame has a toolbar, the client area
2957 // origin will not be (0,0).
2958 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2959 if (pt
.x
!= 0 || pt
.y
!= 0)
2960 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
2962 m_art
->DrawPaneButton(cdc
,
2963 button_ui_part
->button
->button_id
,
2965 button_ui_part
->rect
,
2969 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
2971 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2974 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2977 if (part
->type
== wxDockUIPart::typeDockSizer
||
2978 part
->type
== wxDockUIPart::typePaneSizer
)
2980 // a dock may not be resized if it has a single
2981 // pane which is not resizable
2982 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
2983 part
->dock
->panes
.GetCount() == 1 &&
2984 part
->dock
->panes
.Item(0)->IsFixed())
2987 // panes that may not be resized should be ignored here
2988 if (part
->pane
&& part
->pane
->IsFixed())
2991 m_action
= actionResize
;
2992 m_action_part
= part
;
2993 m_action_hintrect
= wxRect();
2994 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
2995 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
2996 event
.m_y
- part
->rect
.y
);
2997 m_frame
->CaptureMouse();
2999 else if (part
->type
== wxDockUIPart::typePaneButton
)
3001 m_action
= actionClickButton
;
3002 m_action_part
= part
;
3003 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3004 m_frame
->CaptureMouse();
3006 UpdateButtonOnScreen(part
, event
);
3008 else if (part
->type
== wxDockUIPart::typeCaption
||
3009 part
->type
== wxDockUIPart::typeGripper
)
3011 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3013 // set the caption as active
3014 SetActivePane(m_panes
, part
->pane
->window
);
3018 m_action
= actionClickCaption
;
3019 m_action_part
= part
;
3020 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3021 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3022 event
.m_y
- part
->rect
.y
);
3023 m_frame
->CaptureMouse();
3043 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3045 if (m_action
== actionResize
)
3047 m_frame
->ReleaseMouse();
3049 // get rid of the hint rectangle
3051 DrawResizeHint(dc
, m_action_hintrect
);
3053 // resize the dock or the pane
3054 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3056 wxRect
& rect
= m_action_part
->dock
->rect
;
3058 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3059 event
.m_y
- m_action_offset
.y
);
3061 switch (m_action_part
->dock
->dock_direction
)
3063 case wxAUI_DOCK_LEFT
:
3064 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3066 case wxAUI_DOCK_TOP
:
3067 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3069 case wxAUI_DOCK_RIGHT
:
3070 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3071 new_pos
.x
- m_action_part
->rect
.GetWidth();
3073 case wxAUI_DOCK_BOTTOM
:
3074 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3075 new_pos
.y
- m_action_part
->rect
.GetHeight();
3082 else if (m_action_part
&&
3083 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3085 wxDockInfo
& dock
= *m_action_part
->dock
;
3086 wxPaneInfo
& pane
= *m_action_part
->pane
;
3088 int total_proportion
= 0;
3089 int dock_pixels
= 0;
3090 int new_pixsize
= 0;
3092 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3093 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3094 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3096 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3097 event
.m_y
- m_action_offset
.y
);
3099 // determine the pane rectangle by getting the pane part
3100 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3101 wxASSERT_MSG(pane_part
,
3102 wxT("Pane border part not found -- shouldn't happen"));
3104 // determine the new pixel size that the user wants;
3105 // this will help us recalculate the pane's proportion
3106 if (dock
.IsHorizontal())
3107 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3109 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3111 // determine the size of the dock, based on orientation
3112 if (dock
.IsHorizontal())
3113 dock_pixels
= dock
.rect
.GetWidth();
3115 dock_pixels
= dock
.rect
.GetHeight();
3117 // determine the total proportion of all resizable panes,
3118 // and the total size of the dock minus the size of all
3120 int i
, dock_pane_count
= dock
.panes
.GetCount();
3121 int pane_position
= -1;
3122 for (i
= 0; i
< dock_pane_count
; ++i
)
3124 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3125 if (p
.window
== pane
.window
)
3128 // while we're at it, subtract the pane sash
3129 // width from the dock width, because this would
3130 // skew our proportion calculations
3132 dock_pixels
-= sash_size
;
3134 // also, the whole size (including decorations) of
3135 // all fixed panes must also be subtracted, because they
3136 // are not part of the proportion calculation
3139 if (dock
.IsHorizontal())
3140 dock_pixels
-= p
.best_size
.x
;
3142 dock_pixels
-= p
.best_size
.y
;
3146 total_proportion
+= p
.dock_proportion
;
3150 // find a pane in our dock to 'steal' space from or to 'give'
3151 // space to -- this is essentially what is done when a pane is
3152 // resized; the pane should usually be the first non-fixed pane
3153 // to the right of the action pane
3154 int borrow_pane
= -1;
3155 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3157 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3166 // demand that the pane being resized is found in this dock
3167 // (this assert really never should be raised)
3168 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3170 // prevent division by zero
3171 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3173 m_action
= actionNone
;
3177 // calculate the new proportion of the pane
3178 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3180 // default minimum size
3183 // check against the pane's minimum size, if specified. please note
3184 // that this is not enough to ensure that the minimum size will
3185 // not be violated, because the whole frame might later be shrunk,
3186 // causing the size of the pane to violate it's minimum size
3187 if (pane
.min_size
.IsFullySpecified())
3191 if (pane
.HasBorder())
3192 min_size
+= (pane_border_size
*2);
3194 // calculate minimum size with decorations (border,caption)
3195 if (pane_part
->orientation
== wxVERTICAL
)
3197 min_size
+= pane
.min_size
.y
;
3198 if (pane
.HasCaption())
3199 min_size
+= caption_size
;
3203 min_size
+= pane
.min_size
.x
;
3208 // for some reason, an arithmatic error somewhere is causing
3209 // the proportion calculations to always be off by 1 pixel;
3210 // for now we will add the 1 pixel on, but we really should
3211 // determine what's causing this.
3214 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3216 if (new_proportion
< min_proportion
)
3217 new_proportion
= min_proportion
;
3221 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3223 // borrow the space from our neighbor pane to the
3224 // right or bottom (depending on orientation)
3225 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3226 pane
.dock_proportion
= new_proportion
;
3233 else if (m_action
== actionClickButton
)
3235 m_hover_button
= NULL
;
3236 m_frame
->ReleaseMouse();
3237 UpdateButtonOnScreen(m_action_part
, event
);
3239 // make sure we're still over the item that was originally clicked
3240 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3242 // fire button-click event
3243 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3244 e
.SetPane(m_action_part
->pane
);
3245 e
.SetButton(m_action_part
->button
->button_id
);
3249 else if (m_action
== actionClickCaption
)
3251 m_frame
->ReleaseMouse();
3253 else if (m_action
== actionDragFloatingPane
)
3255 m_frame
->ReleaseMouse();
3257 else if (m_action
== actionDragToolbarPane
)
3259 m_frame
->ReleaseMouse();
3261 wxPaneInfo
& pane
= GetPane(m_action_window
);
3262 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3264 // save the new positions
3265 wxDockInfoPtrArray docks
;
3266 FindDocks(m_docks
, pane
.dock_direction
,
3267 pane
.dock_layer
, pane
.dock_row
, docks
);
3268 if (docks
.GetCount() == 1)
3270 wxDockInfo
& dock
= *docks
.Item(0);
3272 wxArrayInt pane_positions
, pane_sizes
;
3273 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3275 int i
, dock_pane_count
= dock
.panes
.GetCount();
3276 for (i
= 0; i
< dock_pane_count
; ++i
)
3277 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3280 pane
.state
&= ~wxPaneInfo::actionPane
;
3288 m_action
= actionNone
;
3289 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3293 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3295 // sometimes when Update() is called from inside this method,
3296 // a spurious mouse move event is generated; this check will make
3297 // sure that only real mouse moves will get anywhere in this method;
3298 // this appears to be a bug somewhere, and I don't know where the
3299 // mouse move event is being generated. only verified on MSW
3301 wxPoint mouse_pos
= event
.GetPosition();
3302 if (m_last_mouse_move
== mouse_pos
)
3304 m_last_mouse_move
= mouse_pos
;
3307 if (m_action
== actionResize
)
3309 wxPoint pos
= m_action_part
->rect
.GetPosition();
3310 if (m_action_part
->orientation
== wxHORIZONTAL
)
3311 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3313 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3315 wxRect
rect(m_frame
->ClientToScreen(pos
),
3316 m_action_part
->rect
.GetSize());
3319 if (!m_action_hintrect
.IsEmpty())
3320 DrawResizeHint(dc
, m_action_hintrect
);
3321 DrawResizeHint(dc
, rect
);
3322 m_action_hintrect
= rect
;
3324 else if (m_action
== actionClickCaption
)
3326 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3327 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3329 // caption has been clicked. we need to check if the mouse
3330 // is now being dragged. if it is, we need to change the
3331 // mouse action to 'drag'
3332 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3333 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3335 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3337 if (!pane_info
->IsToolbar())
3339 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3340 pane_info
->IsFloatable())
3342 m_action
= actionDragFloatingPane
;
3344 // set initial float position
3345 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3346 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3347 pt
.y
- m_action_offset
.y
);
3352 m_action_window
= pane_info
->frame
;
3354 // action offset is used here to make it feel "natural" to the user
3355 // to drag a docked pane and suddenly have it become a floating frame.
3356 // Sometimes, however, the offset where the user clicked on the docked
3357 // caption is bigger than the width of the floating frame itself, so
3358 // in that case we need to set the action offset to a sensible value
3359 wxSize frame_size
= m_action_window
->GetSize();
3360 if (frame_size
.x
<= m_action_offset
.x
)
3361 m_action_offset
.x
= 30;
3366 m_action
= actionDragToolbarPane
;
3367 m_action_window
= pane_info
->window
;
3371 else if (m_action
== actionDragFloatingPane
)
3373 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3374 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3375 pt
.y
- m_action_offset
.y
);
3377 else if (m_action
== actionDragToolbarPane
)
3379 wxPaneInfo
& pane
= GetPane(m_action_window
);
3380 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3382 pane
.state
|= wxPaneInfo::actionPane
;
3384 wxPoint pt
= event
.GetPosition();
3385 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3387 // if DoDrop() decided to float the pane, set up
3388 // the floating pane's initial position
3389 if (pane
.IsFloating())
3391 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3392 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3393 pt
.y
- m_action_offset
.y
);
3396 // this will do the actiual move operation;
3397 // in the case that the pane has been floated,
3398 // this call will create the floating pane
3399 // and do the reparenting
3402 // if the pane has been floated, change the mouse
3403 // action actionDragFloatingPane so that subsequent
3404 // EVT_MOTION() events will move the floating pane
3405 if (pane
.IsFloating())
3407 pane
.state
&= ~wxPaneInfo::actionPane
;
3408 m_action
= actionDragFloatingPane
;
3409 m_action_window
= pane
.frame
;
3414 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3415 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3417 if (part
!= m_hover_button
)
3419 // make the old button normal
3421 UpdateButtonOnScreen(m_hover_button
, event
);
3423 // mouse is over a button, so repaint the
3424 // button in hover mode
3425 UpdateButtonOnScreen(part
, event
);
3426 m_hover_button
= part
;
3433 m_hover_button
= NULL
;
3444 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3448 m_hover_button
= NULL
;
3453 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3455 // when a child pane has it's focus set, we should change the
3456 // pane's active state to reflect this. (this is only true if
3457 // active panes are allowed by the owner)
3458 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3460 if (GetPane(event
.GetWindow()).IsOk())
3462 SetActivePane(m_panes
, event
.GetWindow());
3469 // OnPaneButton() is an event handler that is called
3470 // when a pane button has been pressed.
3471 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& event
)
3473 wxPaneInfo
& pane
= *(event
.pane
);
3475 if (event
.button
== wxPaneInfo::buttonClose
)
3480 else if (event
.button
== wxPaneInfo::buttonPin
)
3482 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&