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("%08x%08x%08x%08x"),
578 ((unsigned long)pinfo
.window
) & 0xffffffff,
579 (unsigned int)time(NULL
),
580 (unsigned int)clock(), m_panes
.GetCount());
583 // set initial proportion (if not already set)
584 if (pinfo
.dock_proportion
== 0)
585 pinfo
.dock_proportion
= 100000;
587 if (pinfo
.HasCloseButton() &&
588 pinfo
.buttons
.size() == 0)
591 button
.button_id
= wxPaneInfo::buttonClose
;
592 pinfo
.buttons
.Add(button
);
595 if (pinfo
.best_size
== wxDefaultSize
&&
598 pinfo
.best_size
= pinfo
.window
->GetClientSize();
600 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
602 // GetClientSize() doesn't get the best size for
603 // a toolbar under some newer versions of wxWidgets,
604 // so use GetBestSize()
605 pinfo
.best_size
= pinfo
.window
->GetBestSize();
607 // for some reason, wxToolBar::GetBestSize() is returning
608 // a size that is a pixel shy of the correct amount.
609 // I believe this to be the correct action, until
610 // wxToolBar::GetBestSize() is fixed. Is this assumption
615 if (pinfo
.min_size
!= wxDefaultSize
)
617 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
618 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
619 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
620 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
627 bool wxFrameManager::AddPane(wxWindow
* window
,
629 const wxString
& caption
)
632 pinfo
.Caption(caption
);
635 case wxTOP
: pinfo
.Top(); break;
636 case wxBOTTOM
: pinfo
.Bottom(); break;
637 case wxLEFT
: pinfo
.Left(); break;
638 case wxRIGHT
: pinfo
.Right(); break;
639 case wxCENTER
: pinfo
.CenterPane(); break;
641 return AddPane(window
, pinfo
);
644 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
647 // shift the panes around, depending on the insert level
648 switch (insert_level
)
650 case wxAUI_INSERT_PANE
:
651 DoInsertPane(m_panes
,
652 pane_info
.dock_direction
,
653 pane_info
.dock_layer
,
657 case wxAUI_INSERT_ROW
:
658 DoInsertDockRow(m_panes
,
659 pane_info
.dock_direction
,
660 pane_info
.dock_layer
,
663 case wxAUI_INSERT_DOCK
:
664 DoInsertDockLayer(m_panes
,
665 pane_info
.dock_direction
,
666 pane_info
.dock_layer
);
670 // if the window already exists, we are basically just moving/inserting the
671 // existing window. If it doesn't exist, we need to add it and insert it
672 wxPaneInfo
& existing_pane
= GetPane(window
);
673 if (!existing_pane
.IsOk())
675 return AddPane(window
, pane_info
);
679 if (pane_info
.IsFloating())
681 existing_pane
.Float();
682 if (pane_info
.floating_pos
!= wxDefaultPosition
)
683 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
684 if (pane_info
.floating_size
!= wxDefaultSize
)
685 existing_pane
.FloatingSize(pane_info
.floating_size
);
689 existing_pane
.Direction(pane_info
.dock_direction
);
690 existing_pane
.Layer(pane_info
.dock_layer
);
691 existing_pane
.Row(pane_info
.dock_row
);
692 existing_pane
.Position(pane_info
.dock_pos
);
700 bool wxFrameManager::DetachPane(wxWindow
* window
)
703 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
705 wxPaneInfo
& p
= m_panes
.Item(i
);
706 if (p
.window
== window
)
710 // we have a floating frame which is being detached. We need to
711 // reparent it to m_frame and destroy the floating frame
714 p
.window
->SetSize(1,1);
715 p
.frame
->Show(false);
717 // reparent to m_frame and destroy the pane
718 p
.window
->Reparent(m_frame
);
719 p
.frame
->SetSizer(NULL
);
731 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
732 // in the input string. This is an internal functions which is
733 // used for saving perspectives
734 static wxString
EscapeDelimiters(const wxString
& s
)
737 result
.Alloc(s
.length());
738 const wxChar
* ch
= s
.c_str();
741 if (*ch
== wxT(';') || *ch
== wxT('|'))
750 // SavePerspective() saves all pane information as a single string.
751 // This string may later be fed into LoadPerspective() to restore
752 // all pane settings. This save and load mechanism allows an
753 // exact pane configuration to be saved and restored at a later time
755 wxString
wxFrameManager::SavePerspective()
759 result
= wxT("layout1|");
761 int pane_i
, pane_count
= m_panes
.GetCount();
762 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
764 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
766 result
+= wxT("name=");
767 result
+= EscapeDelimiters(pane
.name
);
770 result
+= wxT("caption=");
771 result
+= EscapeDelimiters(pane
.caption
);
774 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
775 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
776 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
777 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
778 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
779 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
780 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
781 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
782 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
783 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
784 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
785 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
786 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
787 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
788 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
789 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
793 int dock_i
, dock_count
= m_docks
.GetCount();
794 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
796 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
798 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
799 dock
.dock_direction
, dock
.dock_layer
,
800 dock
.dock_row
, dock
.size
);
806 // LoadPerspective() loads a layout which was saved with SavePerspective()
807 // If the "update" flag parameter is true, the GUI will immediately be updated
809 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
811 wxString input
= layout
;
814 // check layout string version
815 part
= input
.BeforeFirst(wxT('|'));
816 input
= input
.AfterFirst(wxT('|'));
819 if (part
!= wxT("layout1"))
823 // mark all panes currently managed as docked and hidden
824 int pane_i
, pane_count
= m_panes
.GetCount();
825 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
826 m_panes
.Item(pane_i
).Dock().Hide();
828 // clear out the dock array; this will be reconstructed
831 // replace escaped characters so we can
832 // split up the string easily
833 input
.Replace(wxT("\\|"), wxT("\a"));
834 input
.Replace(wxT("\\;"), wxT("\b"));
840 wxString pane_part
= input
.BeforeFirst(wxT('|'));
841 input
= input
.AfterFirst(wxT('|'));
842 pane_part
.Trim(true);
844 // if the string is empty, we're done parsing
845 if (pane_part
.empty())
849 if (pane_part
.Left(9) == wxT("dock_size"))
851 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
852 wxString value
= pane_part
.AfterFirst(wxT('='));
854 long dir
, layer
, row
, size
;
855 wxString piece
= val_name
.AfterFirst(wxT('('));
856 piece
= piece
.BeforeLast(wxT(')'));
857 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
858 piece
= piece
.AfterFirst(wxT(','));
859 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
860 piece
.AfterFirst(wxT(',')).ToLong(&row
);
864 dock
.dock_direction
= dir
;
865 dock
.dock_layer
= layer
;
874 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
875 pane_part
= pane_part
.AfterFirst(wxT(';'));
876 wxString val_name
= val_part
.BeforeFirst(wxT('='));
877 wxString value
= val_part
.AfterFirst(wxT('='));
878 val_name
.MakeLower();
880 val_name
.Trim(false);
884 if (val_name
.empty())
887 if (val_name
== wxT("name"))
889 else if (val_name
== wxT("caption"))
890 pane
.caption
= value
;
891 else if (val_name
== wxT("state"))
892 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
893 else if (val_name
== wxT("dir"))
894 pane
.dock_direction
= wxAtoi(value
.c_str());
895 else if (val_name
== wxT("layer"))
896 pane
.dock_layer
= wxAtoi(value
.c_str());
897 else if (val_name
== wxT("row"))
898 pane
.dock_row
= wxAtoi(value
.c_str());
899 else if (val_name
== wxT("pos"))
900 pane
.dock_pos
= wxAtoi(value
.c_str());
901 else if (val_name
== wxT("prop"))
902 pane
.dock_proportion
= wxAtoi(value
.c_str());
903 else if (val_name
== wxT("bestw"))
904 pane
.best_size
.x
= wxAtoi(value
.c_str());
905 else if (val_name
== wxT("besth"))
906 pane
.best_size
.y
= wxAtoi(value
.c_str());
907 else if (val_name
== wxT("minw"))
908 pane
.min_size
.x
= wxAtoi(value
.c_str());
909 else if (val_name
== wxT("minh"))
910 pane
.min_size
.y
= wxAtoi(value
.c_str());
911 else if (val_name
== wxT("maxw"))
912 pane
.max_size
.x
= wxAtoi(value
.c_str());
913 else if (val_name
== wxT("maxh"))
914 pane
.max_size
.y
= wxAtoi(value
.c_str());
915 else if (val_name
== wxT("floatx"))
916 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
917 else if (val_name
== wxT("floaty"))
918 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
919 else if (val_name
== wxT("floatw"))
920 pane
.floating_size
.x
= wxAtoi(value
.c_str());
921 else if (val_name
== wxT("floath"))
922 pane
.floating_size
.y
= wxAtoi(value
.c_str());
924 wxFAIL_MSG(wxT("Bad Perspective String"));
928 // replace escaped characters so we can
929 // split up the string easily
930 pane
.name
.Replace(wxT("\a"), wxT("|"));
931 pane
.name
.Replace(wxT("\b"), wxT(";"));
932 pane
.caption
.Replace(wxT("\a"), wxT("|"));
933 pane
.caption
.Replace(wxT("\b"), wxT(";"));
935 wxPaneInfo
& p
= GetPane(pane
.name
);
938 // the pane window couldn't be found
939 // in the existing layout
943 pane
.window
= p
.window
;
944 pane
.frame
= p
.frame
;
945 pane
.buttons
= p
.buttons
;
956 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
957 wxArrayInt
& positions
,
960 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
961 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
962 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
967 int offset
, action_pane
= -1;
968 int pane_i
, pane_count
= dock
.panes
.GetCount();
970 // find the pane marked as our action pane
971 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
973 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
975 if (pane
.state
& wxPaneInfo::actionPane
)
977 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
978 action_pane
= pane_i
;
982 // set up each panes default position, and
983 // determine the size (width or height, depending
984 // on the dock's orientation) of each pane
985 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
987 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
988 positions
.Add(pane
.dock_pos
);
991 if (pane
.HasBorder())
992 size
+= (pane_border_size
*2);
994 if (dock
.IsHorizontal())
996 if (pane
.HasGripper() && !pane
.HasGripperTop())
997 size
+= gripper_size
;
998 size
+= pane
.best_size
.x
;
1002 if (pane
.HasGripper() && pane
.HasGripperTop())
1003 size
+= gripper_size
;
1005 if (pane
.HasCaption())
1006 size
+= caption_size
;
1007 size
+= pane
.best_size
.y
;
1013 // if there is no action pane, just return the default
1014 // positions (as specified in pane.pane_pos)
1015 if (action_pane
== -1)
1019 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1021 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1026 positions
[pane_i
] -= -amount
;
1028 offset
+= sizes
[pane_i
];
1031 // if the dock mode is fixed, make sure none of the panes
1032 // overlap; we will bump panes that overlap
1034 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1036 int amount
= positions
[pane_i
] - offset
;
1040 positions
[pane_i
] += -amount
;
1042 offset
+= sizes
[pane_i
];
1047 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1050 wxDockUIPartArray
& uiparts
,
1054 wxSizerItem
* sizer_item
;
1056 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1057 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1058 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1059 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1061 // find out the orientation of the item (orientation for panes
1062 // is the same as the dock's orientation)
1064 if (dock
.IsHorizontal())
1065 orientation
= wxHORIZONTAL
;
1067 orientation
= wxVERTICAL
;
1069 // this variable will store the proportion
1070 // value that the pane will receive
1071 int pane_proportion
= pane
.dock_proportion
;
1073 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1074 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1076 if (pane
.HasGripper())
1078 if (pane
.HasGripperTop())
1079 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1081 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1083 part
.type
= wxDockUIPart::typeGripper
;
1087 part
.orientation
= orientation
;
1088 part
.cont_sizer
= horz_pane_sizer
;
1089 part
.sizer_item
= sizer_item
;
1093 if (pane
.HasCaption())
1095 // create the caption sizer
1096 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1098 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1100 part
.type
= wxDockUIPart::typeCaption
;
1104 part
.orientation
= orientation
;
1105 part
.cont_sizer
= vert_pane_sizer
;
1106 part
.sizer_item
= sizer_item
;
1107 int caption_part_idx
= uiparts
.GetCount();
1110 // add pane buttons to the caption
1111 int i
, button_count
;
1112 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1113 i
< button_count
; ++i
)
1115 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1117 sizer_item
= caption_sizer
->Add(pane_button_size
,
1121 part
.type
= wxDockUIPart::typePaneButton
;
1124 part
.button
= &button
;
1125 part
.orientation
= orientation
;
1126 part
.cont_sizer
= caption_sizer
;
1127 part
.sizer_item
= sizer_item
;
1131 // add the caption sizer
1132 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1134 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1137 // add the pane window itself
1140 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1144 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1145 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1148 part
.type
= wxDockUIPart::typePane
;
1152 part
.orientation
= orientation
;
1153 part
.cont_sizer
= vert_pane_sizer
;
1154 part
.sizer_item
= sizer_item
;
1158 // determine if the pane should have a minimum size; if the pane is
1159 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1160 // if the pane.min_size is set, we must use that value as well
1162 wxSize min_size
= pane
.min_size
;
1165 if (min_size
== wxDefaultSize
)
1167 min_size
= pane
.best_size
;
1168 pane_proportion
= 0;
1172 if (min_size
!= wxDefaultSize
)
1174 vert_pane_sizer
->SetItemMinSize(
1175 vert_pane_sizer
->GetChildren().GetCount()-1,
1176 min_size
.x
, min_size
.y
);
1180 // add the verticle sizer (caption, pane window) to the
1181 // horizontal sizer (gripper, verticle sizer)
1182 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1184 // finally, add the pane sizer to the dock sizer
1186 if (pane
.HasBorder())
1188 // allowing space for the pane's border
1189 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1190 wxEXPAND
| wxALL
, pane_border_size
);
1192 part
.type
= wxDockUIPart::typePaneBorder
;
1196 part
.orientation
= orientation
;
1197 part
.cont_sizer
= cont
;
1198 part
.sizer_item
= sizer_item
;
1203 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1207 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1209 wxDockUIPartArray
& uiparts
,
1212 wxSizerItem
* sizer_item
;
1215 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1216 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1218 // resizable bottom and right docks have a sash before them
1219 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1220 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1222 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1224 part
.type
= wxDockUIPart::typeDockSizer
;
1225 part
.orientation
= orientation
;
1229 part
.cont_sizer
= cont
;
1230 part
.sizer_item
= sizer_item
;
1234 // create the sizer for the dock
1235 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1237 // add each pane to the dock
1238 int pane_i
, pane_count
= dock
.panes
.GetCount();
1242 wxArrayInt pane_positions
, pane_sizes
;
1244 // figure out the real pane positions we will
1245 // use, without modifying the each pane's pane_pos member
1246 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1249 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1251 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1252 int pane_pos
= pane_positions
.Item(pane_i
);
1254 int amount
= pane_pos
- offset
;
1257 if (dock
.IsVertical())
1258 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1260 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1262 part
.type
= wxDockUIPart::typeBackground
;
1266 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1267 part
.cont_sizer
= dock_sizer
;
1268 part
.sizer_item
= sizer_item
;
1274 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1276 offset
+= pane_sizes
.Item(pane_i
);
1279 // at the end add a very small stretchable background area
1280 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1282 part
.type
= wxDockUIPart::typeBackground
;
1286 part
.orientation
= orientation
;
1287 part
.cont_sizer
= dock_sizer
;
1288 part
.sizer_item
= sizer_item
;
1293 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1295 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1297 // if this is not the first pane being added,
1298 // we need to add a pane sizer
1301 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1303 part
.type
= wxDockUIPart::typePaneSizer
;
1305 part
.pane
= dock
.panes
.Item(pane_i
-1);
1307 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1308 part
.cont_sizer
= dock_sizer
;
1309 part
.sizer_item
= sizer_item
;
1313 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1317 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1318 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1320 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1322 part
.type
= wxDockUIPart::typeDock
;
1326 part
.orientation
= orientation
;
1327 part
.cont_sizer
= cont
;
1328 part
.sizer_item
= sizer_item
;
1331 if (dock
.IsHorizontal())
1332 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1334 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1336 // top and left docks have a sash after them
1337 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1338 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1340 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1342 part
.type
= wxDockUIPart::typeDockSizer
;
1346 part
.orientation
= orientation
;
1347 part
.cont_sizer
= cont
;
1348 part
.sizer_item
= sizer_item
;
1353 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1354 wxDockInfoArray
& docks
,
1355 wxDockUIPartArray
& uiparts
,
1358 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1360 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1361 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1362 wxSize cli_size
= m_frame
->GetClientSize();
1363 int i
, dock_count
, pane_count
;
1366 // empty all docks out
1367 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1368 docks
.Item(i
).panes
.Empty();
1370 // iterate through all known panes, filing each
1371 // of them into the appropriate dock. If the
1372 // pane does not exist in the dock, add it
1373 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1375 wxPaneInfo
& p
= panes
.Item(i
);
1377 // find any docks in this layer
1379 wxDockInfoPtrArray arr
;
1380 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1382 if (arr
.GetCount() > 0)
1388 // dock was not found, so we need to create a new one
1390 d
.dock_direction
= p
.dock_direction
;
1391 d
.dock_layer
= p
.dock_layer
;
1392 d
.dock_row
= p
.dock_row
;
1394 dock
= &docks
.Last();
1398 if (p
.IsDocked() && p
.IsShown())
1400 // remove the pane from any existing docks except this one
1401 RemovePaneFromDocks(docks
, p
, dock
);
1403 // pane needs to be added to the dock,
1404 // if it doesn't already exist
1405 if (!FindPaneInDock(*dock
, p
.window
))
1406 dock
->panes
.Add(&p
);
1410 // remove the pane from any existing docks
1411 RemovePaneFromDocks(docks
, p
);
1416 // remove any empty docks
1417 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1419 if (docks
.Item(i
).panes
.GetCount() == 0)
1423 // configure the docks further
1424 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1426 wxDockInfo
& dock
= docks
.Item(i
);
1427 int j
, dock_pane_count
= dock
.panes
.GetCount();
1429 // sort the dock pane array by the pane's
1430 // dock position (dock_pos), in ascending order
1431 dock
.panes
.Sort(PaneSortFunc
);
1433 // for newly created docks, set up their initial size
1438 for (j
= 0; j
< dock_pane_count
; ++j
)
1440 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1441 wxSize pane_size
= pane
.best_size
;
1442 if (pane_size
== wxDefaultSize
)
1443 pane_size
= pane
.min_size
;
1444 if (pane_size
== wxDefaultSize
)
1445 pane_size
= pane
.window
->GetSize();
1447 if (dock
.IsHorizontal())
1448 size
= wxMax(pane_size
.y
, size
);
1450 size
= wxMax(pane_size
.x
, size
);
1453 // add space for the border (two times), but only
1454 // if at least one pane inside the dock has a pane border
1455 for (j
= 0; j
< dock_pane_count
; ++j
)
1457 if (dock
.panes
.Item(j
)->HasBorder())
1459 size
+= (pane_border_size
*2);
1464 // if pane is on the top or bottom, add the caption height,
1465 // but only if at least one pane inside the dock has a caption
1466 if (dock
.IsHorizontal())
1468 for (j
= 0; j
< dock_pane_count
; ++j
)
1470 if (dock
.panes
.Item(j
)->HasCaption())
1472 size
+= caption_size
;
1478 // new dock's size may not be more than 1/3 of the frame size
1479 if (dock
.IsHorizontal())
1480 size
= wxMin(size
, cli_size
.y
/3);
1482 size
= wxMin(size
, cli_size
.x
/3);
1490 // determine the dock's minimum size
1491 bool plus_border
= false;
1492 bool plus_caption
= false;
1493 int dock_min_size
= 0;
1494 for (j
= 0; j
< dock_pane_count
; ++j
)
1496 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1497 if (pane
.min_size
!= wxDefaultSize
)
1499 if (pane
.HasBorder())
1501 if (pane
.HasCaption())
1502 plus_caption
= true;
1503 if (dock
.IsHorizontal())
1505 if (pane
.min_size
.y
> dock_min_size
)
1506 dock_min_size
= pane
.min_size
.y
;
1510 if (pane
.min_size
.x
> dock_min_size
)
1511 dock_min_size
= pane
.min_size
.x
;
1517 dock_min_size
+= (pane_border_size
*2);
1518 if (plus_caption
&& dock
.IsHorizontal())
1519 dock_min_size
+= (caption_size
);
1521 dock
.min_size
= dock_min_size
;
1524 // if the pane's current size is less than it's
1525 // minimum, increase the dock's size to it's minimum
1526 if (dock
.size
< dock
.min_size
)
1527 dock
.size
= dock
.min_size
;
1530 // determine the dock's mode (fixed or proportional);
1531 // determine whether the dock has only toolbars
1532 bool action_pane_marked
= false;
1534 dock
.toolbar
= true;
1535 for (j
= 0; j
< dock_pane_count
; ++j
)
1537 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1538 if (!pane
.IsFixed())
1540 if (!pane
.IsToolbar())
1541 dock
.toolbar
= false;
1542 if (pane
.state
& wxPaneInfo::actionPane
)
1543 action_pane_marked
= true;
1547 // if the dock mode is proportional and not fixed-pixel,
1548 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1549 // e.g. remove gaps like 1, 2, 30, 500
1552 for (j
= 0; j
< dock_pane_count
; ++j
)
1554 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1559 // if the dock mode is fixed, and none of the panes
1560 // are being moved right now, make sure the panes
1561 // do not overlap each other. If they do, we will
1562 // adjust the panes' positions
1563 if (dock
.fixed
&& !action_pane_marked
)
1565 wxArrayInt pane_positions
, pane_sizes
;
1566 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1569 for (j
= 0; j
< dock_pane_count
; ++j
)
1571 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1572 pane
.dock_pos
= pane_positions
[j
];
1574 int amount
= pane
.dock_pos
- offset
;
1578 pane
.dock_pos
+= -amount
;
1580 offset
+= pane_sizes
[j
];
1585 // discover the maximum dock layer
1587 for (i
= 0; i
< dock_count
; ++i
)
1588 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1591 // clear out uiparts
1594 // create a bunch of box sizers,
1595 // from the innermost level outwards.
1596 wxSizer
* cont
= NULL
;
1597 wxSizer
* middle
= NULL
;
1601 for (layer
= 0; layer
<= max_layer
; ++layer
)
1603 wxDockInfoPtrArray arr
;
1605 // find any docks in this layer
1606 FindDocks(docks
, -1, layer
, -1, arr
);
1608 // if there aren't any, skip to the next layer
1612 wxSizer
* old_cont
= cont
;
1614 // create a container which will hold this layer's
1615 // docks (top, bottom, left, right)
1616 cont
= new wxBoxSizer(wxVERTICAL
);
1619 // find any top docks in this layer
1620 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1621 RenumberDockRows(arr
);
1624 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1625 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1629 // fill out the middle layer (which consists
1630 // of left docks, content area and right docks)
1632 middle
= new wxBoxSizer(wxHORIZONTAL
);
1634 // find any left docks in this layer
1635 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1636 RenumberDockRows(arr
);
1639 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1640 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1643 // add content dock (or previous layer's sizer
1647 // find any center docks
1648 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1651 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1652 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1656 // there are no center docks, add a background area
1657 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1659 part
.type
= wxDockUIPart::typeBackground
;
1663 part
.cont_sizer
= middle
;
1664 part
.sizer_item
= sizer_item
;
1670 middle
->Add(old_cont
, 1, wxEXPAND
);
1673 // find any right docks in this layer
1674 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1675 RenumberDockRows(arr
);
1678 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1679 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1682 cont
->Add(middle
, 1, wxEXPAND
);
1686 // find any bottom docks in this layer
1687 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1688 RenumberDockRows(arr
);
1691 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1692 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1699 // no sizer available, because there are no docks,
1700 // therefore we will create a simple background area
1701 cont
= new wxBoxSizer(wxVERTICAL
);
1702 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1704 part
.type
= wxDockUIPart::typeBackground
;
1708 part
.cont_sizer
= middle
;
1709 part
.sizer_item
= sizer_item
;
1713 container
->Add(cont
, 1, wxEXPAND
);
1718 // Update() updates the layout. Whenever changes are made to
1719 // one or more panes, this function should be called. It is the
1720 // external entry point for running the layout engine.
1722 void wxFrameManager::Update()
1725 int i
, pane_count
= m_panes
.GetCount();
1727 // delete old sizer first
1728 m_frame
->SetSizer(NULL
);
1730 // destroy floating panes which have been
1731 // redocked or are becoming non-floating
1732 for (i
= 0; i
< pane_count
; ++i
)
1734 wxPaneInfo
& p
= m_panes
.Item(i
);
1736 if (!p
.IsFloating() && p
.frame
)
1738 // because the pane is no longer in a floating, we need to
1739 // reparent it to m_frame and destroy the floating frame
1742 p
.window
->SetSize(1,1);
1743 p
.frame
->Show(false);
1745 // reparent to m_frame and destroy the pane
1746 p
.window
->Reparent(m_frame
);
1747 p
.frame
->SetSizer(NULL
);
1754 // create a layout for all of the panes
1755 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
1757 // hide or show panes as necessary,
1758 // and float panes as necessary
1759 for (i
= 0; i
< pane_count
; ++i
)
1761 wxPaneInfo
& p
= m_panes
.Item(i
);
1765 if (p
.frame
== NULL
)
1767 // we need to create a frame for this
1768 // pane, which has recently been floated
1769 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
1774 // on MSW, if the owner desires transparent dragging, and
1775 // the dragging is happening right now, then the floating
1776 // window should have this style by default
1778 if (m_action
== actionDragFloatingPane
&&
1779 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
1780 MakeWindowTransparent(frame
, 150);
1783 frame
->SetPaneWindow(p
);
1793 // frame already exists, make sure it's position
1794 // and size reflect the information in wxPaneInfo
1795 if (p
.frame
->GetPosition() != p
.floating_pos
)
1797 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
1798 -1, -1, wxSIZE_USE_EXISTING
);
1799 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
1802 p
.frame
->Show(p
.IsShown());
1807 p
.window
->Show(p
.IsShown());
1810 // if "active panes" are no longer allowed, clear
1811 // any optionActive values from the pane states
1812 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
1814 p
.state
&= ~wxPaneInfo::optionActive
;
1819 // keep track of the old window rectangles so we can
1820 // refresh those windows whose rect has changed
1821 wxAuiRectArray old_pane_rects
;
1822 for (i
= 0; i
< pane_count
; ++i
)
1825 wxPaneInfo
& p
= m_panes
.Item(i
);
1827 if (p
.window
&& p
.IsShown() && p
.IsDocked())
1830 old_pane_rects
.Add(r
);
1836 // apply the new sizer
1837 m_frame
->SetSizer(sizer
);
1838 m_frame
->SetAutoLayout(false);
1843 // now that the frame layout is done, we need to check
1844 // the new pane rectangles against the old rectangles that
1845 // we saved a few lines above here. If the rectangles have
1846 // changed, the corresponding panes must also be updated
1847 for (i
= 0; i
< pane_count
; ++i
)
1849 wxPaneInfo
& p
= m_panes
.Item(i
);
1850 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
1852 if (p
.rect
!= old_pane_rects
[i
])
1854 p
.window
->Refresh();
1863 // set frame's minimum size
1866 // N.B. More work needs to be done on frame minimum sizes;
1867 // this is some intresting code that imposes the minimum size,
1868 // but we may want to include a more flexible mechanism or
1869 // options for multiple minimum-size modes, e.g. strict or lax
1870 wxSize min_size = sizer->GetMinSize();
1871 wxSize frame_size = m_frame->GetSize();
1872 wxSize client_size = m_frame->GetClientSize();
1874 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
1875 min_size.y+frame_size.y-client_size.y );
1877 m_frame->SetMinSize(minframe_size);
1879 if (frame_size.x < minframe_size.x ||
1880 frame_size.y < minframe_size.y)
1881 sizer->Fit(m_frame);
1886 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
1887 // on the frame's main sizer, then measures all the various UI items
1888 // and updates their internal rectangles. This should always be called
1889 // instead of calling m_frame->Layout() directly
1891 void wxFrameManager::DoFrameLayout()
1896 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1898 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1900 // get the rectangle of the UI part
1901 // originally, this code looked like this:
1902 // part.rect = wxRect(part.sizer_item->GetPosition(),
1903 // part.sizer_item->GetSize());
1904 // this worked quite well, with one exception: the mdi
1905 // client window had a "deferred" size variable
1906 // that returned the wrong size. It looks like
1907 // a bug in wx, because the former size of the window
1908 // was being returned. So, we will retrieve the part's
1909 // rectangle via other means
1912 part
.rect
= part
.sizer_item
->GetRect();
1913 int flag
= part
.sizer_item
->GetFlag();
1914 int border
= part
.sizer_item
->GetBorder();
1917 part
.rect
.y
-= border
;
1918 part
.rect
.height
+= border
;
1922 part
.rect
.x
-= border
;
1923 part
.rect
.width
+= border
;
1925 if (flag
& wxBOTTOM
)
1926 part
.rect
.height
+= border
;
1928 part
.rect
.width
+= border
;
1931 if (part
.type
== wxDockUIPart::typeDock
)
1932 part
.dock
->rect
= part
.rect
;
1933 if (part
.type
== wxDockUIPart::typePane
)
1934 part
.pane
->rect
= part
.rect
;
1938 // GetPanePart() looks up the pane the pane border UI part (or the regular
1939 // pane part if there is no border). This allows the caller to get the exact
1940 // rectangle of the pane in question, including decorations like
1941 // caption and border (if any).
1943 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
1946 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1948 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1949 if (part
.type
== wxDockUIPart::typePaneBorder
&&
1950 part
.pane
&& part
.pane
->window
== wnd
)
1953 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1955 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1956 if (part
.type
== wxDockUIPart::typePane
&&
1957 part
.pane
&& part
.pane
->window
== wnd
)
1965 // GetDockPixelOffset() is an internal function which returns
1966 // a dock's offset in pixels from the left side of the window
1967 // (for horizontal docks) or from the top of the window (for
1968 // vertical docks). This value is necessary for calculating
1969 // fixel-pane/toolbar offsets when they are dragged.
1971 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
1973 // the only way to accurately calculate the dock's
1974 // offset is to actually run a theoretical layout
1976 int i
, part_count
, dock_count
;
1977 wxDockInfoArray docks
;
1978 wxPaneInfoArray panes
;
1979 wxDockUIPartArray uiparts
;
1980 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
1983 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
1984 wxSize client_size
= m_frame
->GetClientSize();
1985 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
1988 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
1990 wxDockUIPart
& part
= uiparts
.Item(i
);
1991 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
1992 part
.sizer_item
->GetSize());
1993 if (part
.type
== wxDockUIPart::typeDock
)
1994 part
.dock
->rect
= part
.rect
;
1999 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2001 wxDockInfo
& dock
= docks
.Item(i
);
2002 if (test
.dock_direction
== dock
.dock_direction
&&
2003 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2005 if (dock
.IsVertical())
2017 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2018 // if a dock operation is allowed, the new dock position is copied into
2019 // the target info. If the operation was allowed, the function returns true.
2021 static bool ProcessDockResult(wxPaneInfo
& target
,
2022 const wxPaneInfo
& new_pos
)
2024 bool allowed
= false;
2025 switch (new_pos
.dock_direction
)
2027 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2028 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2029 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2030 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2040 // DoDrop() is an important function. It basically takes a mouse position,
2041 // and determines where the pane's new position would be. If the pane is to be
2042 // dropped, it performs the drop operation using the specified dock and pane
2043 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2044 // scenario can be performed, giving precise coordinates for drop hints.
2045 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2046 // as parameters, the changes will be made to the main state arrays
2048 const int auiInsertRowPixels
= 10;
2049 const int auiNewRowPixels
= 40;
2050 const int auiLayerInsertPixels
= 40;
2051 const int auiLayerInsertOffset
= 5;
2053 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2054 wxPaneInfoArray
& panes
,
2057 const wxPoint
& offset
)
2059 wxSize cli_size
= m_frame
->GetClientSize();
2061 wxPaneInfo drop
= target
;
2064 // The result should always be shown
2068 // Check to see if the pane has been dragged outside of the window
2069 // (or near to the outside of the window), if so, dock it along the edge
2072 int layer_insert_offset
= auiLayerInsertOffset
;
2073 if (target
.IsToolbar())
2074 layer_insert_offset
= 0;
2076 if (pt
.x
< layer_insert_offset
&&
2077 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2079 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2080 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2081 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2085 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2086 return ProcessDockResult(target
, drop
);
2088 else if (pt
.y
< layer_insert_offset
&&
2089 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2091 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2092 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2093 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2097 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2098 return ProcessDockResult(target
, drop
);
2100 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2101 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2103 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2104 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2105 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2106 drop
.Dock().Right().
2109 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2110 return ProcessDockResult(target
, drop
);
2112 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2113 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2115 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2116 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2117 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2118 drop
.Dock().Bottom().
2121 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2122 return ProcessDockResult(target
, drop
);
2126 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2129 if (drop
.IsToolbar())
2131 if (!part
|| !part
->dock
)
2135 // calculate the offset from where the dock begins
2136 // to the point where the user dropped the pane
2137 int dock_drop_offset
= 0;
2138 if (part
->dock
->IsHorizontal())
2139 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2141 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2144 // toolbars may only be moved in and to fixed-pane docks,
2145 // otherwise we will try to float the pane. Also, the pane
2146 // should float if being dragged over center pane windows
2147 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2149 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2150 (drop
.IsFloatable() ||
2151 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2152 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2157 return ProcessDockResult(target
, drop
);
2161 Direction(part
->dock
->dock_direction
).
2162 Layer(part
->dock
->dock_layer
).
2163 Row(part
->dock
->dock_row
).
2164 Position(dock_drop_offset
);
2167 ((pt
.y
< part
->dock
->rect
.y
+ 2) && part
->dock
->IsHorizontal()) ||
2168 ((pt
.x
< part
->dock
->rect
.x
+ 2) && part
->dock
->IsVertical())
2169 ) && part
->dock
->panes
.GetCount() > 1)
2171 int row
= drop
.dock_row
;
2172 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2173 part
->dock
->dock_layer
,
2174 part
->dock
->dock_row
);
2175 drop
.dock_row
= row
;
2179 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2180 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2181 ) && part
->dock
->panes
.GetCount() > 1)
2183 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2184 part
->dock
->dock_layer
,
2185 part
->dock
->dock_row
+1);
2186 drop
.dock_row
= part
->dock
->dock_row
+1;
2189 return ProcessDockResult(target
, drop
);
2198 if (part
->type
== wxDockUIPart::typePaneBorder
||
2199 part
->type
== wxDockUIPart::typeCaption
||
2200 part
->type
== wxDockUIPart::typeGripper
||
2201 part
->type
== wxDockUIPart::typePaneButton
||
2202 part
->type
== wxDockUIPart::typePane
||
2203 part
->type
== wxDockUIPart::typePaneSizer
||
2204 part
->type
== wxDockUIPart::typeDockSizer
||
2205 part
->type
== wxDockUIPart::typeBackground
)
2207 if (part
->type
== wxDockUIPart::typeDockSizer
)
2209 if (part
->dock
->panes
.GetCount() != 1)
2211 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2218 // If a normal frame is being dragged over a toolbar, insert it
2219 // along the edge under the toolbar, but over all other panes.
2220 // (this could be done much better, but somehow factoring this
2221 // calculation with the one at the beginning of this function)
2222 if (part
->dock
&& part
->dock
->toolbar
)
2226 switch (part
->dock
->dock_direction
)
2228 case wxAUI_DOCK_LEFT
:
2229 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2230 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2231 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2233 case wxAUI_DOCK_TOP
:
2234 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2235 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2236 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2238 case wxAUI_DOCK_RIGHT
:
2239 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2240 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2241 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2243 case wxAUI_DOCK_BOTTOM
:
2244 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2245 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2246 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2250 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2253 Direction(part
->dock
->dock_direction
).
2254 Layer(layer
).Row(0).Position(0);
2255 return ProcessDockResult(target
, drop
);
2262 part
= GetPanePart(part
->pane
->window
);
2266 bool insert_dock_row
= false;
2267 int insert_row
= part
->pane
->dock_row
;
2268 int insert_dir
= part
->pane
->dock_direction
;
2269 int insert_layer
= part
->pane
->dock_layer
;
2271 switch (part
->pane
->dock_direction
)
2273 case wxAUI_DOCK_TOP
:
2274 if (pt
.y
>= part
->rect
.y
&&
2275 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2276 insert_dock_row
= true;
2278 case wxAUI_DOCK_BOTTOM
:
2279 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2280 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2281 insert_dock_row
= true;
2283 case wxAUI_DOCK_LEFT
:
2284 if (pt
.x
>= part
->rect
.x
&&
2285 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2286 insert_dock_row
= true;
2288 case wxAUI_DOCK_RIGHT
:
2289 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2290 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2291 insert_dock_row
= true;
2293 case wxAUI_DOCK_CENTER
:
2295 // "new row pixels" will be set to the default, but
2296 // must never exceed 20% of the window size
2297 int new_row_pixels_x
= auiNewRowPixels
;
2298 int new_row_pixels_y
= auiNewRowPixels
;
2300 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2301 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2303 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2304 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2307 // determine if the mouse pointer is in a location that
2308 // will cause a new row to be inserted. The hot spot positions
2309 // are along the borders of the center pane
2312 insert_dock_row
= true;
2313 if (pt
.x
>= part
->rect
.x
&&
2314 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2315 insert_dir
= wxAUI_DOCK_LEFT
;
2317 if (pt
.y
>= part
->rect
.y
&&
2318 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2319 insert_dir
= wxAUI_DOCK_TOP
;
2321 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2322 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2323 insert_dir
= wxAUI_DOCK_RIGHT
;
2325 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2326 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2327 insert_dir
= wxAUI_DOCK_BOTTOM
;
2331 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2335 if (insert_dock_row
)
2337 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2338 drop
.Dock().Direction(insert_dir
).
2339 Layer(insert_layer
).
2342 return ProcessDockResult(target
, drop
);
2345 // determine the mouse offset and the pane size, both in the
2346 // direction of the dock itself, and perpendicular to the dock
2350 if (part
->orientation
== wxVERTICAL
)
2352 offset
= pt
.y
- part
->rect
.y
;
2353 size
= part
->rect
.GetHeight();
2357 offset
= pt
.x
- part
->rect
.x
;
2358 size
= part
->rect
.GetWidth();
2361 int drop_position
= part
->pane
->dock_pos
;
2363 // if we are in the top/left part of the pane,
2364 // insert the pane before the pane being hovered over
2365 if (offset
<= size
/2)
2367 drop_position
= part
->pane
->dock_pos
;
2369 part
->pane
->dock_direction
,
2370 part
->pane
->dock_layer
,
2371 part
->pane
->dock_row
,
2372 part
->pane
->dock_pos
);
2375 // if we are in the bottom/right part of the pane,
2376 // insert the pane before the pane being hovered over
2377 if (offset
> size
/2)
2379 drop_position
= part
->pane
->dock_pos
+1;
2381 part
->pane
->dock_direction
,
2382 part
->pane
->dock_layer
,
2383 part
->pane
->dock_row
,
2384 part
->pane
->dock_pos
+1);
2388 Direction(part
->dock
->dock_direction
).
2389 Layer(part
->dock
->dock_layer
).
2390 Row(part
->dock
->dock_row
).
2391 Position(drop_position
);
2392 return ProcessDockResult(target
, drop
);
2399 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2402 if (!m_hint_wnd
|| m_hint_fadeamt
>= 50)
2404 m_hint_fadetimer
.Stop();
2408 m_hint_fadeamt
+= 5;
2409 MakeWindowTransparent(m_hint_wnd
, m_hint_fadeamt
);
2413 void wxFrameManager::ShowHint(const wxRect
& rect
)
2417 // First, determine if the operating system can handle transparency.
2418 // Transparency is available on Win2000 and above
2420 static int os_type
= -1;
2421 static int ver_major
= -1;
2424 os_type
= ::wxGetOsVersion(&ver_major
);
2426 // If the transparent flag is set, and the OS supports it,
2427 // go ahead and use a transparent hint
2429 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 &&
2430 os_type
== wxWINDOWS_NT
&& ver_major
>= 5)
2432 if (m_last_hint
== rect
)
2436 int initial_fade
= 50;
2437 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2440 if (m_hint_wnd
== NULL
)
2442 wxPoint pt
= rect
.GetPosition();
2443 wxSize size
= rect
.GetSize();
2444 m_hint_wnd
= new wxFrame(m_frame
, -1, wxEmptyString
, pt
, size
,
2445 wxFRAME_TOOL_WINDOW
|
2446 wxFRAME_FLOAT_ON_PARENT
|
2447 wxFRAME_NO_TASKBAR
|
2450 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2451 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
2454 // if we are dragging a floating pane, set the focus
2455 // back to that floating pane (otherwise it becomes unfocused)
2456 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2457 m_action_window
->SetFocus();
2462 wxPoint pt
= rect
.GetPosition();
2463 wxSize size
= rect
.GetSize();
2464 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2465 m_hint_wnd
->SetSize(pt
.x
, pt
.y
, rect
.width
, rect
.height
);
2468 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2470 // start fade in timer
2472 m_hint_fadetimer
.SetOwner(this, 101);
2473 m_hint_fadetimer
.Start(5);
2480 if (m_last_hint
!= rect
)
2482 // remove the last hint rectangle
2488 wxScreenDC screendc
;
2489 wxRegion
clip(1, 1, 10000, 10000);
2491 // clip all floating windows, so we don't draw over them
2493 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2495 wxPaneInfo
& pane
= m_panes
.Item(i
);
2497 if (pane
.IsFloating() &&
2498 pane
.frame
->IsShown())
2500 wxRect rect
= pane
.frame
->GetRect();
2502 // wxGTK returns the client size, not the whole frame size
2508 clip
.Subtract(rect
);
2512 screendc
.SetClippingRegion(clip
);
2514 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2515 wxBrush
brush(stipple
);
2516 screendc
.SetBrush(brush
);
2517 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2519 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2520 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2521 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2522 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2525 void wxFrameManager::HideHint()
2527 // hides a transparent window hint (currently wxMSW only)
2531 MakeWindowTransparent(m_hint_wnd
, 0);
2532 m_hint_fadetimer
.Stop();
2533 m_last_hint
= wxRect();
2538 // hides a painted hint by redrawing the frame window
2539 if (!m_last_hint
.IsEmpty())
2543 m_last_hint
= wxRect();
2549 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2550 // determine the exact position the pane would be at were if dropped. If
2551 // the pame would indeed become docked at the specified drop point,
2552 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2553 // "pane_window" is the window pointer of the pane being dragged, pt is
2554 // the mouse position, in client coordinates
2555 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2557 const wxPoint
& offset
)
2561 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2562 // we will create a new temporary layout and then measure the resulting
2563 // rectangle; we will create a copy of the docking structures (m_dock)
2564 // so that we don't modify the real thing on screen
2566 int i
, pane_count
, part_count
;
2567 wxDockInfoArray docks
;
2568 wxPaneInfoArray panes
;
2569 wxDockUIPartArray uiparts
;
2570 wxPaneInfo hint
= GetPane(pane_window
);
2571 hint
.name
= wxT("__HINT__");
2576 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2578 // remove any pane already there which bears the same window;
2579 // this happens when you are moving a pane around in a dock
2580 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2582 if (panes
.Item(i
).window
== pane_window
)
2584 RemovePaneFromDocks(docks
, panes
.Item(i
));
2590 // find out where the new pane would be
2591 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2599 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2600 wxSize client_size
= m_frame
->GetClientSize();
2601 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2604 for (i
= 0, part_count
= uiparts
.GetCount();
2605 i
< part_count
; ++i
)
2607 wxDockUIPart
& part
= uiparts
.Item(i
);
2609 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2610 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2612 rect
= wxRect(part
.sizer_item
->GetPosition(),
2613 part
.sizer_item
->GetSize());
2626 // actually show the hint rectangle on the screen
2627 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2631 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2633 // try to find the pane
2634 wxPaneInfo
& pane
= GetPane(wnd
);
2635 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2638 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2639 MakeWindowTransparent(pane
.frame
, 150);
2643 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
)
2645 // try to find the pane
2646 wxPaneInfo
& pane
= GetPane(wnd
);
2647 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2649 wxPoint pt
= ::wxGetMousePosition();
2650 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2652 // calculate the offset from the upper left-hand corner
2653 // of the frame to the mouse pointer
2654 wxPoint frame_pos
= pane
.frame
->GetPosition();
2655 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2657 // no hint for toolbar floating windows
2658 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
2660 if (m_action
== actionDragFloatingPane
)
2662 wxDockInfoArray docks
;
2663 wxPaneInfoArray panes
;
2664 wxDockUIPartArray uiparts
;
2665 wxPaneInfo hint
= pane
;
2667 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2669 // find out where the new pane would be
2670 if (!DoDrop(docks
, panes
, hint
, client_pt
))
2672 if (hint
.IsFloating())
2676 m_action
= actionDragToolbarPane
;
2677 m_action_window
= pane
.window
;
2686 // if a key modifier is pressed while dragging the frame,
2687 // don't dock the window
2688 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2695 DrawHintRect(wnd
, client_pt
, action_offset
);
2698 // this cleans up some screen artifacts that are caused on GTK because
2699 // we aren't getting the exact size of the window (see comment
2709 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
)
2711 // try to find the pane
2712 wxPaneInfo
& pane
= GetPane(wnd
);
2713 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2715 wxPoint pt
= ::wxGetMousePosition();
2716 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2718 // calculate the offset from the upper left-hand corner
2719 // of the frame to the mouse pointer
2720 wxPoint frame_pos
= pane
.frame
->GetPosition();
2721 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2724 // if a key modifier is pressed while dragging the frame,
2725 // don't dock the window
2726 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2733 // do the drop calculation
2734 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
2736 // if the pane is still floating, update it's floating
2737 // position (that we store)
2738 if (pane
.IsFloating())
2740 pane
.floating_pos
= pane
.frame
->GetPosition();
2743 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2744 MakeWindowTransparent(pane
.frame
, 255);
2753 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
2755 // try to find the pane
2756 wxPaneInfo
& pane
= GetPane(wnd
);
2757 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2759 pane
.floating_size
= size
;
2762 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
)
2764 // try to find the pane
2765 wxPaneInfo
& pane
= GetPane(wnd
);
2766 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2768 // reparent the pane window back to us and
2769 // prepare the frame window for destruction
2770 pane
.window
->Show(false);
2771 pane
.window
->Reparent(m_frame
);
2776 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
2778 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
2780 // try to find the pane
2781 wxPaneInfo
& pane
= GetPane(wnd
);
2782 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2784 SetActivePane(m_panes
, wnd
);
2789 // Render() draws all of the pane captions, sashes,
2790 // backgrounds, captions, grippers, pane borders and buttons.
2791 // It renders the entire user interface.
2793 void wxFrameManager::Render(wxDC
* dc
)
2799 for (i
= 0, part_count
= m_uiparts
.GetCount();
2800 i
< part_count
; ++i
)
2802 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2804 // don't draw hidden pane items
2805 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
2810 case wxDockUIPart::typeDockSizer
:
2811 case wxDockUIPart::typePaneSizer
:
2812 m_art
->DrawSash(*dc
, part
.orientation
, part
.rect
);
2814 case wxDockUIPart::typeBackground
:
2815 m_art
->DrawBackground(*dc
, part
.orientation
, part
.rect
);
2817 case wxDockUIPart::typeCaption
:
2818 m_art
->DrawCaption(*dc
, part
.pane
->caption
, part
.rect
, *part
.pane
);
2820 case wxDockUIPart::typeGripper
:
2821 m_art
->DrawGripper(*dc
, part
.rect
, *part
.pane
);
2823 case wxDockUIPart::typePaneBorder
:
2824 m_art
->DrawBorder(*dc
, part
.rect
, *part
.pane
);
2826 case wxDockUIPart::typePaneButton
:
2827 m_art
->DrawPaneButton(*dc
, part
.button
->button_id
,
2828 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
2834 void wxFrameManager::Repaint(wxDC
* dc
)
2839 m_frame
->Refresh() ;
2845 m_frame
->GetClientSize(&w
, &h
);
2847 // figure out which dc to use; if one
2848 // has been specified, use it, otherwise
2850 wxClientDC
* client_dc
= NULL
;
2853 client_dc
= new wxClientDC(m_frame
);
2857 // if the frame has a toolbar, the client area
2858 // origin will not be (0,0).
2859 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2860 if (pt
.x
!= 0 || pt
.y
!= 0)
2861 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
2863 // render all the items
2866 // if we created a client_dc, delete it
2871 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2873 wxPaintDC
dc(m_frame
);
2877 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
2886 void wxFrameManager::OnSize(wxSizeEvent
& WXUNUSED(event
))
2896 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
2899 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2900 wxCursor cursor
= wxNullCursor
;
2904 if (part
->type
== wxDockUIPart::typeDockSizer
||
2905 part
->type
== wxDockUIPart::typePaneSizer
)
2907 // a dock may not be resized if it has a single
2908 // pane which is not resizable
2909 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
2910 part
->dock
->panes
.GetCount() == 1 &&
2911 part
->dock
->panes
.Item(0)->IsFixed())
2914 // panes that may not be resized do not get a sizing cursor
2915 if (part
->pane
&& part
->pane
->IsFixed())
2918 if (part
->orientation
== wxVERTICAL
)
2919 cursor
= wxCursor(wxCURSOR_SIZEWE
);
2921 cursor
= wxCursor(wxCURSOR_SIZENS
);
2923 else if (part
->type
== wxDockUIPart::typeGripper
)
2925 cursor
= wxCursor(wxCURSOR_SIZING
);
2929 event
.SetCursor(cursor
);
2934 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
2935 const wxMouseEvent
& event
)
2937 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
2939 int state
= wxAUI_BUTTON_STATE_NORMAL
;
2941 if (hit_test
== button_ui_part
)
2943 if (event
.LeftDown())
2944 state
= wxAUI_BUTTON_STATE_PRESSED
;
2946 state
= wxAUI_BUTTON_STATE_HOVER
;
2950 if (event
.LeftDown())
2951 state
= wxAUI_BUTTON_STATE_HOVER
;
2954 // now repaint the button with hover state
2955 wxClientDC
cdc(m_frame
);
2957 // if the frame has a toolbar, the client area
2958 // origin will not be (0,0).
2959 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2960 if (pt
.x
!= 0 || pt
.y
!= 0)
2961 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
2963 m_art
->DrawPaneButton(cdc
,
2964 button_ui_part
->button
->button_id
,
2966 button_ui_part
->rect
,
2970 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
2972 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2975 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2978 if (part
->type
== wxDockUIPart::typeDockSizer
||
2979 part
->type
== wxDockUIPart::typePaneSizer
)
2981 // a dock may not be resized if it has a single
2982 // pane which is not resizable
2983 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
2984 part
->dock
->panes
.GetCount() == 1 &&
2985 part
->dock
->panes
.Item(0)->IsFixed())
2988 // panes that may not be resized should be ignored here
2989 if (part
->pane
&& part
->pane
->IsFixed())
2992 m_action
= actionResize
;
2993 m_action_part
= part
;
2994 m_action_hintrect
= wxRect();
2995 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
2996 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
2997 event
.m_y
- part
->rect
.y
);
2998 m_frame
->CaptureMouse();
3000 else if (part
->type
== wxDockUIPart::typePaneButton
)
3002 m_action
= actionClickButton
;
3003 m_action_part
= part
;
3004 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3005 m_frame
->CaptureMouse();
3007 UpdateButtonOnScreen(part
, event
);
3009 else if (part
->type
== wxDockUIPart::typeCaption
||
3010 part
->type
== wxDockUIPart::typeGripper
)
3012 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3014 // set the caption as active
3015 SetActivePane(m_panes
, part
->pane
->window
);
3019 m_action
= actionClickCaption
;
3020 m_action_part
= part
;
3021 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3022 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3023 event
.m_y
- part
->rect
.y
);
3024 m_frame
->CaptureMouse();
3044 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3046 if (m_action
== actionResize
)
3048 m_frame
->ReleaseMouse();
3050 // get rid of the hint rectangle
3052 DrawResizeHint(dc
, m_action_hintrect
);
3054 // resize the dock or the pane
3055 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3057 wxRect
& rect
= m_action_part
->dock
->rect
;
3059 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3060 event
.m_y
- m_action_offset
.y
);
3062 switch (m_action_part
->dock
->dock_direction
)
3064 case wxAUI_DOCK_LEFT
:
3065 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3067 case wxAUI_DOCK_TOP
:
3068 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3070 case wxAUI_DOCK_RIGHT
:
3071 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3072 new_pos
.x
- m_action_part
->rect
.GetWidth();
3074 case wxAUI_DOCK_BOTTOM
:
3075 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3076 new_pos
.y
- m_action_part
->rect
.GetHeight();
3083 else if (m_action_part
&&
3084 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3086 wxDockInfo
& dock
= *m_action_part
->dock
;
3087 wxPaneInfo
& pane
= *m_action_part
->pane
;
3089 int total_proportion
= 0;
3090 int dock_pixels
= 0;
3091 int new_pixsize
= 0;
3093 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3094 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3095 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3097 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3098 event
.m_y
- m_action_offset
.y
);
3100 // determine the pane rectangle by getting the pane part
3101 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3102 wxASSERT_MSG(pane_part
,
3103 wxT("Pane border part not found -- shouldn't happen"));
3105 // determine the new pixel size that the user wants;
3106 // this will help us recalculate the pane's proportion
3107 if (dock
.IsHorizontal())
3108 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3110 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3112 // determine the size of the dock, based on orientation
3113 if (dock
.IsHorizontal())
3114 dock_pixels
= dock
.rect
.GetWidth();
3116 dock_pixels
= dock
.rect
.GetHeight();
3118 // determine the total proportion of all resizable panes,
3119 // and the total size of the dock minus the size of all
3121 int i
, dock_pane_count
= dock
.panes
.GetCount();
3122 int pane_position
= -1;
3123 for (i
= 0; i
< dock_pane_count
; ++i
)
3125 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3126 if (p
.window
== pane
.window
)
3129 // while we're at it, subtract the pane sash
3130 // width from the dock width, because this would
3131 // skew our proportion calculations
3133 dock_pixels
-= sash_size
;
3135 // also, the whole size (including decorations) of
3136 // all fixed panes must also be subtracted, because they
3137 // are not part of the proportion calculation
3140 if (dock
.IsHorizontal())
3141 dock_pixels
-= p
.best_size
.x
;
3143 dock_pixels
-= p
.best_size
.y
;
3147 total_proportion
+= p
.dock_proportion
;
3151 // find a pane in our dock to 'steal' space from or to 'give'
3152 // space to -- this is essentially what is done when a pane is
3153 // resized; the pane should usually be the first non-fixed pane
3154 // to the right of the action pane
3155 int borrow_pane
= -1;
3156 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3158 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3167 // demand that the pane being resized is found in this dock
3168 // (this assert really never should be raised)
3169 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3171 // prevent division by zero
3172 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3174 m_action
= actionNone
;
3178 // calculate the new proportion of the pane
3179 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3181 // default minimum size
3184 // check against the pane's minimum size, if specified. please note
3185 // that this is not enough to ensure that the minimum size will
3186 // not be violated, because the whole frame might later be shrunk,
3187 // causing the size of the pane to violate it's minimum size
3188 if (pane
.min_size
.IsFullySpecified())
3192 if (pane
.HasBorder())
3193 min_size
+= (pane_border_size
*2);
3195 // calculate minimum size with decorations (border,caption)
3196 if (pane_part
->orientation
== wxVERTICAL
)
3198 min_size
+= pane
.min_size
.y
;
3199 if (pane
.HasCaption())
3200 min_size
+= caption_size
;
3204 min_size
+= pane
.min_size
.x
;
3209 // for some reason, an arithmatic error somewhere is causing
3210 // the proportion calculations to always be off by 1 pixel;
3211 // for now we will add the 1 pixel on, but we really should
3212 // determine what's causing this.
3215 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3217 if (new_proportion
< min_proportion
)
3218 new_proportion
= min_proportion
;
3222 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3224 // borrow the space from our neighbor pane to the
3225 // right or bottom (depending on orientation)
3226 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3227 pane
.dock_proportion
= new_proportion
;
3234 else if (m_action
== actionClickButton
)
3236 m_hover_button
= NULL
;
3237 m_frame
->ReleaseMouse();
3238 UpdateButtonOnScreen(m_action_part
, event
);
3240 // make sure we're still over the item that was originally clicked
3241 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3243 // fire button-click event
3244 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3245 e
.SetPane(m_action_part
->pane
);
3246 e
.SetButton(m_action_part
->button
->button_id
);
3250 else if (m_action
== actionClickCaption
)
3252 m_frame
->ReleaseMouse();
3254 else if (m_action
== actionDragFloatingPane
)
3256 m_frame
->ReleaseMouse();
3258 else if (m_action
== actionDragToolbarPane
)
3260 m_frame
->ReleaseMouse();
3262 wxPaneInfo
& pane
= GetPane(m_action_window
);
3263 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3265 // save the new positions
3266 wxDockInfoPtrArray docks
;
3267 FindDocks(m_docks
, pane
.dock_direction
,
3268 pane
.dock_layer
, pane
.dock_row
, docks
);
3269 if (docks
.GetCount() == 1)
3271 wxDockInfo
& dock
= *docks
.Item(0);
3273 wxArrayInt pane_positions
, pane_sizes
;
3274 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3276 int i
, dock_pane_count
= dock
.panes
.GetCount();
3277 for (i
= 0; i
< dock_pane_count
; ++i
)
3278 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3281 pane
.state
&= ~wxPaneInfo::actionPane
;
3289 m_action
= actionNone
;
3290 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3294 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3296 // sometimes when Update() is called from inside this method,
3297 // a spurious mouse move event is generated; this check will make
3298 // sure that only real mouse moves will get anywhere in this method;
3299 // this appears to be a bug somewhere, and I don't know where the
3300 // mouse move event is being generated. only verified on MSW
3302 wxPoint mouse_pos
= event
.GetPosition();
3303 if (m_last_mouse_move
== mouse_pos
)
3305 m_last_mouse_move
= mouse_pos
;
3308 if (m_action
== actionResize
)
3310 wxPoint pos
= m_action_part
->rect
.GetPosition();
3311 if (m_action_part
->orientation
== wxHORIZONTAL
)
3312 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3314 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3316 wxRect
rect(m_frame
->ClientToScreen(pos
),
3317 m_action_part
->rect
.GetSize());
3320 if (!m_action_hintrect
.IsEmpty())
3321 DrawResizeHint(dc
, m_action_hintrect
);
3322 DrawResizeHint(dc
, rect
);
3323 m_action_hintrect
= rect
;
3325 else if (m_action
== actionClickCaption
)
3327 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3328 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3330 // caption has been clicked. we need to check if the mouse
3331 // is now being dragged. if it is, we need to change the
3332 // mouse action to 'drag'
3333 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3334 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3336 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3338 if (!pane_info
->IsToolbar())
3340 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3341 pane_info
->IsFloatable())
3343 m_action
= actionDragFloatingPane
;
3345 // set initial float position
3346 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3347 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3348 pt
.y
- m_action_offset
.y
);
3353 m_action_window
= pane_info
->frame
;
3355 // action offset is used here to make it feel "natural" to the user
3356 // to drag a docked pane and suddenly have it become a floating frame.
3357 // Sometimes, however, the offset where the user clicked on the docked
3358 // caption is bigger than the width of the floating frame itself, so
3359 // in that case we need to set the action offset to a sensible value
3360 wxSize frame_size
= m_action_window
->GetSize();
3361 if (frame_size
.x
<= m_action_offset
.x
)
3362 m_action_offset
.x
= 30;
3367 m_action
= actionDragToolbarPane
;
3368 m_action_window
= pane_info
->window
;
3372 else if (m_action
== actionDragFloatingPane
)
3374 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3375 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3376 pt
.y
- m_action_offset
.y
);
3378 else if (m_action
== actionDragToolbarPane
)
3380 wxPaneInfo
& pane
= GetPane(m_action_window
);
3381 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3383 pane
.state
|= wxPaneInfo::actionPane
;
3385 wxPoint pt
= event
.GetPosition();
3386 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3388 // if DoDrop() decided to float the pane, set up
3389 // the floating pane's initial position
3390 if (pane
.IsFloating())
3392 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3393 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3394 pt
.y
- m_action_offset
.y
);
3397 // this will do the actiual move operation;
3398 // in the case that the pane has been floated,
3399 // this call will create the floating pane
3400 // and do the reparenting
3403 // if the pane has been floated, change the mouse
3404 // action actionDragFloatingPane so that subsequent
3405 // EVT_MOTION() events will move the floating pane
3406 if (pane
.IsFloating())
3408 pane
.state
&= ~wxPaneInfo::actionPane
;
3409 m_action
= actionDragFloatingPane
;
3410 m_action_window
= pane
.frame
;
3415 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3416 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3418 if (part
!= m_hover_button
)
3420 // make the old button normal
3422 UpdateButtonOnScreen(m_hover_button
, event
);
3424 // mouse is over a button, so repaint the
3425 // button in hover mode
3426 UpdateButtonOnScreen(part
, event
);
3427 m_hover_button
= part
;
3434 m_hover_button
= NULL
;
3445 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3449 m_hover_button
= NULL
;
3454 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3456 // when a child pane has it's focus set, we should change the
3457 // pane's active state to reflect this. (this is only true if
3458 // active panes are allowed by the owner)
3459 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3461 if (GetPane(event
.GetWindow()).IsOk())
3463 SetActivePane(m_panes
, event
.GetWindow());
3470 // OnPaneButton() is an event handler that is called
3471 // when a pane button has been pressed.
3472 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& event
)
3474 wxPaneInfo
& pane
= *(event
.pane
);
3476 if (event
.button
== wxPaneInfo::buttonClose
)
3481 else if (event
.button
== wxPaneInfo::buttonPin
)
3483 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&