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"
39 //#include "wx/dcbuffer.h"
42 #include "wx/toolbar.h"
48 WX_CHECK_BUILD_OPTIONS("wxAUI")
50 #include "wx/arrimpl.cpp"
51 WX_DECLARE_OBJARRAY(wxRect
, wxAuiRectArray
);
52 WX_DEFINE_OBJARRAY(wxAuiRectArray
)
53 WX_DEFINE_OBJARRAY(wxDockUIPartArray
)
54 WX_DEFINE_OBJARRAY(wxDockInfoArray
)
55 WX_DEFINE_OBJARRAY(wxPaneButtonArray
)
56 WX_DEFINE_OBJARRAY(wxPaneInfoArray
)
58 wxPaneInfo wxNullPaneInfo
;
59 wxDockInfo wxNullDockInfo
;
60 DEFINE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON
)
63 // a few defines to avoid nameclashes
64 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
66 #include "wx/mac/private.h"
70 // -- static utility functions --
72 static wxBitmap
wxPaneCreateStippleBitmap()
74 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
75 wxImage
img(2,2,data
,true);
79 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
81 wxBitmap stipple
= wxPaneCreateStippleBitmap();
82 wxBrush
brush(stipple
);
84 dc
.SetPen(*wxTRANSPARENT_PEN
);
86 dc
.SetLogicalFunction(wxXOR
);
87 dc
.DrawRectangle(rect
);
92 // on supported windows systems (Win2000 and greater), this function
93 // will make a frame window transparent by a certain amount
94 static void MakeWindowTransparent(wxWindow
* wnd
, int amount
)
96 // this API call is not in all SDKs, only the newer ones, so
97 // we will runtime bind this
98 typedef DWORD (WINAPI
*PSETLAYEREDWINDOWATTR
)(HWND
, DWORD
, BYTE
, DWORD
);
99 static PSETLAYEREDWINDOWATTR pSetLayeredWindowAttributes
= NULL
;
100 static HMODULE h
= NULL
;
101 HWND hwnd
= (HWND
)wnd
->GetHWND();
104 h
= LoadLibrary(_T("user32"));
106 if (!pSetLayeredWindowAttributes
)
108 pSetLayeredWindowAttributes
=
109 (PSETLAYEREDWINDOWATTR
)GetProcAddress(h
,"SetLayeredWindowAttributes");
112 if (pSetLayeredWindowAttributes
== NULL
)
115 LONG exstyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
116 if (0 == (exstyle
& 0x80000) /*WS_EX_LAYERED*/)
117 SetWindowLong(hwnd
, GWL_EXSTYLE
, exstyle
| 0x80000 /*WS_EX_LAYERED*/);
119 pSetLayeredWindowAttributes(hwnd
, 0, (BYTE
)amount
, 2 /*LWA_ALPHA*/);
125 // CopyDocksAndPanes() - this utility function creates copies of
126 // the dock and pane info. wxDockInfo's usually contain pointers
127 // to wxPaneInfo classes, thus this function is necessary to reliably
128 // reconstruct that relationship in the new dock info and pane info arrays
130 static void CopyDocksAndPanes(wxDockInfoArray
& dest_docks
,
131 wxPaneInfoArray
& dest_panes
,
132 const wxDockInfoArray
& src_docks
,
133 const wxPaneInfoArray
& src_panes
)
135 dest_docks
= src_docks
;
136 dest_panes
= src_panes
;
137 int i
, j
, k
, dock_count
, pc1
, pc2
;
138 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
140 wxDockInfo
& dock
= dest_docks
.Item(i
);
141 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
142 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
143 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
144 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
148 // GetMaxLayer() is an internal function which returns
149 // the highest layer inside the specified dock
150 static int GetMaxLayer(const wxDockInfoArray
& docks
, int dock_direction
)
152 int i
, dock_count
, max_layer
= 0;
153 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
155 wxDockInfo
& dock
= docks
.Item(i
);
156 if (dock
.dock_direction
== dock_direction
&&
157 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
158 max_layer
= dock
.dock_layer
;
164 // GetMaxRow() is an internal function which returns
165 // the highest layer inside the specified dock
166 static int GetMaxRow(const wxPaneInfoArray
& panes
, int direction
, int layer
)
168 int i
, pane_count
, max_row
= 0;
169 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
171 wxPaneInfo
& pane
= panes
.Item(i
);
172 if (pane
.dock_direction
== direction
&&
173 pane
.dock_layer
== layer
&&
174 pane
.dock_row
> max_row
)
175 max_row
= pane
.dock_row
;
182 // DoInsertDockLayer() is an internal function that inserts a new dock
183 // layer by incrementing all existing dock layer values by one
184 static void DoInsertDockLayer(wxPaneInfoArray
& panes
,
189 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
191 wxPaneInfo
& pane
= panes
.Item(i
);
192 if (!pane
.IsFloating() &&
193 pane
.dock_direction
== dock_direction
&&
194 pane
.dock_layer
>= dock_layer
)
199 // DoInsertDockLayer() is an internal function that inserts a new dock
200 // row by incrementing all existing dock row values by one
201 static void DoInsertDockRow(wxPaneInfoArray
& panes
,
207 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
209 wxPaneInfo
& pane
= panes
.Item(i
);
210 if (!pane
.IsFloating() &&
211 pane
.dock_direction
== dock_direction
&&
212 pane
.dock_layer
== dock_layer
&&
213 pane
.dock_row
>= dock_row
)
218 // DoInsertDockLayer() is an internal function that inserts a space for
219 // another dock pane by incrementing all existing dock row values by one
220 static void DoInsertPane(wxPaneInfoArray
& panes
,
227 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
229 wxPaneInfo
& pane
= panes
.Item(i
);
230 if (!pane
.IsFloating() &&
231 pane
.dock_direction
== dock_direction
&&
232 pane
.dock_layer
== dock_layer
&&
233 pane
.dock_row
== dock_row
&&
234 pane
.dock_pos
>= dock_pos
)
239 // FindDocks() is an internal function that returns a list of docks which meet
240 // the specified conditions in the parameters and returns a sorted array
241 // (sorted by layer and then row)
242 static void FindDocks(wxDockInfoArray
& docks
,
246 wxDockInfoPtrArray
& arr
)
248 int begin_layer
= dock_layer
;
249 int end_layer
= dock_layer
;
250 int begin_row
= dock_row
;
251 int end_row
= dock_row
;
252 int dock_count
= docks
.GetCount();
253 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
255 // discover the maximum dock layer and the max row
256 for (i
= 0; i
< dock_count
; ++i
)
258 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
259 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
262 // if no dock layer was specified, search all dock layers
263 if (dock_layer
== -1)
266 end_layer
= max_layer
;
269 // if no dock row was specified, search all dock row
278 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
279 for (row
= begin_row
; row
<= end_row
; ++row
)
280 for (i
= 0; i
< dock_count
; ++i
)
282 wxDockInfo
& d
= docks
.Item(i
);
283 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
285 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
291 // FindPaneInDock() looks up a specified window pointer inside a dock.
292 // If found, the corresponding wxPaneInfo pointer is returned, otherwise NULL.
293 static wxPaneInfo
* FindPaneInDock(const wxDockInfo
& dock
, wxWindow
* window
)
295 int i
, count
= dock
.panes
.GetCount();
296 for (i
= 0; i
< count
; ++i
)
298 wxPaneInfo
* p
= dock
.panes
.Item(i
);
299 if (p
->window
== window
)
305 // RemovePaneFromDocks() removes a pane window from all docks
306 // with a possible exception specified by parameter "except"
307 static void RemovePaneFromDocks(wxDockInfoArray
& docks
,
309 wxDockInfo
* except
= NULL
)
312 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
314 wxDockInfo
& d
= docks
.Item(i
);
317 wxPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
323 // RenumberDockRows() takes a dock and assigns sequential numbers
324 // to existing rows. Basically it takes out the gaps; so if a
325 // dock has rows with numbers 0,2,5, they will become 0,1,2
326 static void RenumberDockRows(wxDockInfoPtrArray
& docks
)
328 int i
, dock_count
, j
, pane_count
;
329 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
331 wxDockInfo
& dock
= *docks
.Item(i
);
333 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
334 dock
.panes
.Item(j
)->dock_row
= i
;
340 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
343 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
345 wxPaneInfo
& pane
= panes
.Item(i
);
346 pane
.state
&= ~wxPaneInfo::optionActive
;
347 if (pane
.window
== active_pane
)
348 pane
.state
|= wxPaneInfo::optionActive
;
353 // this function is used to sort panes by dock position
354 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
356 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
360 // -- wxFrameManager class implementation --
363 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
364 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
365 EVT_PAINT(wxFrameManager::OnPaint
)
366 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
367 EVT_SIZE(wxFrameManager::OnSize
)
368 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
369 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
370 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
371 EVT_MOTION(wxFrameManager::OnMotion
)
372 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
373 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
374 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
378 wxFrameManager::wxFrameManager(wxFrame
* frame
, unsigned int flags
)
380 m_action
= actionNone
;
381 m_last_mouse_move
= wxPoint();
382 m_hover_button
= NULL
;
383 m_art
= new wxDefaultDockArt
;
393 wxFrameManager::~wxFrameManager()
398 // GetPane() looks up a wxPaneInfo structure based
399 // on the supplied window pointer. Upon failure, GetPane()
400 // returns an empty wxPaneInfo, a condition which can be checked
401 // by calling wxPaneInfo::IsOk().
403 // The pane info's structure may then be modified. Once a pane's
404 // info is modified, wxFrameManager::Update() must be called to
405 // realize the changes in the UI.
407 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
410 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
412 wxPaneInfo
& p
= m_panes
.Item(i
);
413 if (p
.window
== window
)
416 return wxNullPaneInfo
;
419 // this version of GetPane() looks up a pane based on a
420 // 'pane name', see above comment for more info
421 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
424 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
426 wxPaneInfo
& p
= m_panes
.Item(i
);
430 return wxNullPaneInfo
;
433 // GetAllPanes() returns a reference to all the pane info structures
434 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
439 // HitTest() is an internal function which determines
440 // which UI item the specified coordinates are over
441 // (x,y) specify a position in client coordinates
442 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
444 wxDockUIPart
* result
= NULL
;
447 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
449 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
451 // we are not interested in typeDock, because this space
452 // isn't used to draw anything, just for measurements;
453 // besides, the entire dock area is covered with other
454 // rectangles, which we are interested in.
455 if (item
->type
== wxDockUIPart::typeDock
)
458 // if we already have a hit on a more specific item, we are not
459 // interested in a pane hit. If, however, we don't already have
460 // a hit, returning a pane hit is necessary for some operations
461 if ((item
->type
== wxDockUIPart::typePane
||
462 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
465 // if the point is inside the rectangle, we have a hit
466 if (item
->rect
.Inside(x
,y
))
474 // SetFlags() and GetFlags() allow the owner to set various
475 // options which are global to wxFrameManager
476 void wxFrameManager::SetFlags(unsigned int flags
)
481 unsigned int wxFrameManager::GetFlags() const
487 // SetFrame() is usually called once when the frame
488 // manager class is being initialized. "frame" specifies
489 // the frame which should be managed by the frame mananger
490 void wxFrameManager::SetFrame(wxFrame
* frame
)
492 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
495 m_frame
->PushEventHandler(this);
498 // if the owner is going to manage an MDI parent frame,
499 // we need to add the MDI client window as the default
502 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
504 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
505 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
507 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
509 AddPane(client_window
,
510 wxPaneInfo().Name(wxT("mdiclient")).
511 CenterPane().PaneBorder(false));
517 // UnInit() must be called, usually in the destructor
518 // of the frame class. If it is not called, usually this
519 // will result in a crash upon program exit
520 void wxFrameManager::UnInit()
522 m_frame
->RemoveEventHandler(this);
525 // GetFrame() returns the frame pointer being managed by wxFrameManager
526 wxFrame
* wxFrameManager::GetFrame() const
531 wxDockArt
* wxFrameManager::GetArtProvider() const
536 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
538 // first, give the owner frame a chance to override
541 if (m_frame
->ProcessEvent(event
))
548 // SetArtProvider() instructs wxFrameManager to use the
549 // specified art provider for all drawing calls. This allows
550 // plugable look-and-feel features
551 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
553 // delete the last art provider, if any
556 // assign the new art provider
557 m_art
= art_provider
;
560 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
562 // check if the pane has a valid window
566 // check if the pane already exists
567 if (GetPane(pane_info
.window
).IsOk())
570 m_panes
.Add(pane_info
);
572 wxPaneInfo
& pinfo
= m_panes
.Last();
574 // set the pane window
575 pinfo
.window
= window
;
577 // if the pane's name identifier is blank, create a random string
578 if (pinfo
.name
.empty())
580 pinfo
.name
.Printf(wxT("%08x%08x%08x%08x"),
581 ((unsigned long)pinfo
.window
) & 0xffffffff,
582 (unsigned int)time(NULL
),
583 (unsigned int)clock(), m_panes
.GetCount());
586 // set initial proportion (if not already set)
587 if (pinfo
.dock_proportion
== 0)
588 pinfo
.dock_proportion
= 100000;
590 if (pinfo
.HasCloseButton() &&
591 pinfo
.buttons
.size() == 0)
594 button
.button_id
= wxPaneInfo::buttonClose
;
595 pinfo
.buttons
.Add(button
);
598 if (pinfo
.best_size
== wxDefaultSize
&&
601 pinfo
.best_size
= pinfo
.window
->GetClientSize();
603 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
605 // GetClientSize() doesn't get the best size for
606 // a toolbar under some newer versions of wxWidgets,
607 // so use GetBestSize()
608 pinfo
.best_size
= pinfo
.window
->GetBestSize();
610 // for some reason, wxToolBar::GetBestSize() is returning
611 // a size that is a pixel shy of the correct amount.
612 // I believe this to be the correct action, until
613 // wxToolBar::GetBestSize() is fixed. Is this assumption
618 if (pinfo
.min_size
!= wxDefaultSize
)
620 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
621 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
622 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
623 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
630 bool wxFrameManager::AddPane(wxWindow
* window
,
632 const wxString
& caption
)
635 pinfo
.Caption(caption
);
638 case wxTOP
: pinfo
.Top(); break;
639 case wxBOTTOM
: pinfo
.Bottom(); break;
640 case wxLEFT
: pinfo
.Left(); break;
641 case wxRIGHT
: pinfo
.Right(); break;
642 case wxCENTER
: pinfo
.CenterPane(); break;
644 return AddPane(window
, pinfo
);
647 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
650 // shift the panes around, depending on the insert level
651 switch (insert_level
)
653 case wxAUI_INSERT_PANE
:
654 DoInsertPane(m_panes
,
655 pane_info
.dock_direction
,
656 pane_info
.dock_layer
,
660 case wxAUI_INSERT_ROW
:
661 DoInsertDockRow(m_panes
,
662 pane_info
.dock_direction
,
663 pane_info
.dock_layer
,
666 case wxAUI_INSERT_DOCK
:
667 DoInsertDockLayer(m_panes
,
668 pane_info
.dock_direction
,
669 pane_info
.dock_layer
);
673 // if the window already exists, we are basically just moving/inserting the
674 // existing window. If it doesn't exist, we need to add it and insert it
675 wxPaneInfo
& existing_pane
= GetPane(window
);
676 if (!existing_pane
.IsOk())
678 return AddPane(window
, pane_info
);
682 if (pane_info
.IsFloating())
684 existing_pane
.Float();
685 if (pane_info
.floating_pos
!= wxDefaultPosition
)
686 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
687 if (pane_info
.floating_size
!= wxDefaultSize
)
688 existing_pane
.FloatingSize(pane_info
.floating_size
);
692 existing_pane
.Direction(pane_info
.dock_direction
);
693 existing_pane
.Layer(pane_info
.dock_layer
);
694 existing_pane
.Row(pane_info
.dock_row
);
695 existing_pane
.Position(pane_info
.dock_pos
);
703 bool wxFrameManager::DetachPane(wxWindow
* window
)
706 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
708 wxPaneInfo
& p
= m_panes
.Item(i
);
709 if (p
.window
== window
)
713 // we have a floating frame which is being detached. We need to
714 // reparent it to m_frame and destroy the floating frame
717 p
.window
->SetSize(1,1);
718 p
.frame
->Show(false);
720 // reparent to m_frame and destroy the pane
721 p
.window
->Reparent(m_frame
);
722 p
.frame
->SetSizer(NULL
);
734 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
735 // in the input string. This is an internal functions which is
736 // used for saving perspectives
737 static wxString
EscapeDelimiters(const wxString
& s
)
740 result
.Alloc(s
.length());
741 const wxChar
* ch
= s
.c_str();
744 if (*ch
== wxT(';') || *ch
== wxT('|'))
753 // SavePerspective() saves all pane information as a single string.
754 // This string may later be fed into LoadPerspective() to restore
755 // all pane settings. This save and load mechanism allows an
756 // exact pane configuration to be saved and restored at a later time
758 wxString
wxFrameManager::SavePerspective()
762 result
= wxT("layout1|");
764 int pane_i
, pane_count
= m_panes
.GetCount();
765 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
767 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
769 result
+= wxT("name=");
770 result
+= EscapeDelimiters(pane
.name
);
773 result
+= wxT("caption=");
774 result
+= EscapeDelimiters(pane
.caption
);
777 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
778 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
779 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
780 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
781 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
782 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
783 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
784 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
785 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
786 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
787 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
788 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
789 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
790 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
791 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
792 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
796 int dock_i
, dock_count
= m_docks
.GetCount();
797 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
799 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
801 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
802 dock
.dock_direction
, dock
.dock_layer
,
803 dock
.dock_row
, dock
.size
);
809 // LoadPerspective() loads a layout which was saved with SavePerspective()
810 // If the "update" flag parameter is true, the GUI will immediately be updated
812 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
814 wxString input
= layout
;
817 // check layout string version
818 part
= input
.BeforeFirst(wxT('|'));
819 input
= input
.AfterFirst(wxT('|'));
822 if (part
!= wxT("layout1"))
826 // mark all panes currently managed as docked and hidden
827 int pane_i
, pane_count
= m_panes
.GetCount();
828 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
829 m_panes
.Item(pane_i
).Dock().Hide();
831 // clear out the dock array; this will be reconstructed
834 // replace escaped characters so we can
835 // split up the string easily
836 input
.Replace(wxT("\\|"), wxT("\a"));
837 input
.Replace(wxT("\\;"), wxT("\b"));
843 wxString pane_part
= input
.BeforeFirst(wxT('|'));
844 input
= input
.AfterFirst(wxT('|'));
845 pane_part
.Trim(true);
847 // if the string is empty, we're done parsing
848 if (pane_part
.empty())
852 if (pane_part
.Left(9) == wxT("dock_size"))
854 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
855 wxString value
= pane_part
.AfterFirst(wxT('='));
857 long dir
, layer
, row
, size
;
858 wxString piece
= val_name
.AfterFirst(wxT('('));
859 piece
= piece
.BeforeLast(wxT(')'));
860 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
861 piece
= piece
.AfterFirst(wxT(','));
862 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
863 piece
.AfterFirst(wxT(',')).ToLong(&row
);
867 dock
.dock_direction
= dir
;
868 dock
.dock_layer
= layer
;
877 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
878 pane_part
= pane_part
.AfterFirst(wxT(';'));
879 wxString val_name
= val_part
.BeforeFirst(wxT('='));
880 wxString value
= val_part
.AfterFirst(wxT('='));
881 val_name
.MakeLower();
883 val_name
.Trim(false);
887 if (val_name
.empty())
890 if (val_name
== wxT("name"))
892 else if (val_name
== wxT("caption"))
893 pane
.caption
= value
;
894 else if (val_name
== wxT("state"))
895 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
896 else if (val_name
== wxT("dir"))
897 pane
.dock_direction
= wxAtoi(value
.c_str());
898 else if (val_name
== wxT("layer"))
899 pane
.dock_layer
= wxAtoi(value
.c_str());
900 else if (val_name
== wxT("row"))
901 pane
.dock_row
= wxAtoi(value
.c_str());
902 else if (val_name
== wxT("pos"))
903 pane
.dock_pos
= wxAtoi(value
.c_str());
904 else if (val_name
== wxT("prop"))
905 pane
.dock_proportion
= wxAtoi(value
.c_str());
906 else if (val_name
== wxT("bestw"))
907 pane
.best_size
.x
= wxAtoi(value
.c_str());
908 else if (val_name
== wxT("besth"))
909 pane
.best_size
.y
= wxAtoi(value
.c_str());
910 else if (val_name
== wxT("minw"))
911 pane
.min_size
.x
= wxAtoi(value
.c_str());
912 else if (val_name
== wxT("minh"))
913 pane
.min_size
.y
= wxAtoi(value
.c_str());
914 else if (val_name
== wxT("maxw"))
915 pane
.max_size
.x
= wxAtoi(value
.c_str());
916 else if (val_name
== wxT("maxh"))
917 pane
.max_size
.y
= wxAtoi(value
.c_str());
918 else if (val_name
== wxT("floatx"))
919 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
920 else if (val_name
== wxT("floaty"))
921 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
922 else if (val_name
== wxT("floatw"))
923 pane
.floating_size
.x
= wxAtoi(value
.c_str());
924 else if (val_name
== wxT("floath"))
925 pane
.floating_size
.y
= wxAtoi(value
.c_str());
927 wxFAIL_MSG(wxT("Bad Perspective String"));
931 // replace escaped characters so we can
932 // split up the string easily
933 pane
.name
.Replace(wxT("\a"), wxT("|"));
934 pane
.name
.Replace(wxT("\b"), wxT(";"));
935 pane
.caption
.Replace(wxT("\a"), wxT("|"));
936 pane
.caption
.Replace(wxT("\b"), wxT(";"));
938 wxPaneInfo
& p
= GetPane(pane
.name
);
941 // the pane window couldn't be found
942 // in the existing layout
946 pane
.window
= p
.window
;
947 pane
.frame
= p
.frame
;
948 pane
.buttons
= p
.buttons
;
959 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
960 wxArrayInt
& positions
,
963 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
964 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
965 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
970 int offset
, action_pane
= -1;
971 int pane_i
, pane_count
= dock
.panes
.GetCount();
973 // find the pane marked as our action pane
974 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
976 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
978 if (pane
.state
& wxPaneInfo::actionPane
)
980 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
981 action_pane
= pane_i
;
985 // set up each panes default position, and
986 // determine the size (width or height, depending
987 // on the dock's orientation) of each pane
988 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
990 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
991 positions
.Add(pane
.dock_pos
);
994 if (pane
.HasBorder())
995 size
+= (pane_border_size
*2);
997 if (dock
.IsHorizontal())
999 if (pane
.HasGripper() && !pane
.HasGripperTop())
1000 size
+= gripper_size
;
1001 size
+= pane
.best_size
.x
;
1005 if (pane
.HasGripper() && pane
.HasGripperTop())
1006 size
+= gripper_size
;
1008 if (pane
.HasCaption())
1009 size
+= caption_size
;
1010 size
+= pane
.best_size
.y
;
1016 // if there is no action pane, just return the default
1017 // positions (as specified in pane.pane_pos)
1018 if (action_pane
== -1)
1022 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1024 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1029 positions
[pane_i
] -= -amount
;
1031 offset
+= sizes
[pane_i
];
1034 // if the dock mode is fixed, make sure none of the panes
1035 // overlap; we will bump panes that overlap
1037 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1039 int amount
= positions
[pane_i
] - offset
;
1043 positions
[pane_i
] += -amount
;
1045 offset
+= sizes
[pane_i
];
1050 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1053 wxDockUIPartArray
& uiparts
,
1057 wxSizerItem
* sizer_item
;
1059 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1060 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1061 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1062 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1064 // find out the orientation of the item (orientation for panes
1065 // is the same as the dock's orientation)
1067 if (dock
.IsHorizontal())
1068 orientation
= wxHORIZONTAL
;
1070 orientation
= wxVERTICAL
;
1072 // this variable will store the proportion
1073 // value that the pane will receive
1074 int pane_proportion
= pane
.dock_proportion
;
1076 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1077 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1079 if (pane
.HasGripper())
1081 if (pane
.HasGripperTop())
1082 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1084 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1086 part
.type
= wxDockUIPart::typeGripper
;
1090 part
.orientation
= orientation
;
1091 part
.cont_sizer
= horz_pane_sizer
;
1092 part
.sizer_item
= sizer_item
;
1096 if (pane
.HasCaption())
1098 // create the caption sizer
1099 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1101 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1103 part
.type
= wxDockUIPart::typeCaption
;
1107 part
.orientation
= orientation
;
1108 part
.cont_sizer
= vert_pane_sizer
;
1109 part
.sizer_item
= sizer_item
;
1110 int caption_part_idx
= uiparts
.GetCount();
1113 // add pane buttons to the caption
1114 int i
, button_count
;
1115 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1116 i
< button_count
; ++i
)
1118 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1120 sizer_item
= caption_sizer
->Add(pane_button_size
,
1124 part
.type
= wxDockUIPart::typePaneButton
;
1127 part
.button
= &button
;
1128 part
.orientation
= orientation
;
1129 part
.cont_sizer
= caption_sizer
;
1130 part
.sizer_item
= sizer_item
;
1134 // add the caption sizer
1135 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1137 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1140 // add the pane window itself
1143 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1147 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1148 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1151 part
.type
= wxDockUIPart::typePane
;
1155 part
.orientation
= orientation
;
1156 part
.cont_sizer
= vert_pane_sizer
;
1157 part
.sizer_item
= sizer_item
;
1161 // determine if the pane should have a minimum size; if the pane is
1162 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1163 // if the pane.min_size is set, we must use that value as well
1165 wxSize min_size
= pane
.min_size
;
1168 if (min_size
== wxDefaultSize
)
1170 min_size
= pane
.best_size
;
1171 pane_proportion
= 0;
1175 if (min_size
!= wxDefaultSize
)
1177 vert_pane_sizer
->SetItemMinSize(
1178 vert_pane_sizer
->GetChildren().GetCount()-1,
1179 min_size
.x
, min_size
.y
);
1183 // add the verticle sizer (caption, pane window) to the
1184 // horizontal sizer (gripper, verticle sizer)
1185 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1187 // finally, add the pane sizer to the dock sizer
1189 if (pane
.HasBorder())
1191 // allowing space for the pane's border
1192 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1193 wxEXPAND
| wxALL
, pane_border_size
);
1195 part
.type
= wxDockUIPart::typePaneBorder
;
1199 part
.orientation
= orientation
;
1200 part
.cont_sizer
= cont
;
1201 part
.sizer_item
= sizer_item
;
1206 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1210 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1212 wxDockUIPartArray
& uiparts
,
1215 wxSizerItem
* sizer_item
;
1218 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1219 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1221 // resizable bottom and right docks have a sash before them
1222 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1223 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1225 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1227 part
.type
= wxDockUIPart::typeDockSizer
;
1228 part
.orientation
= orientation
;
1232 part
.cont_sizer
= cont
;
1233 part
.sizer_item
= sizer_item
;
1237 // create the sizer for the dock
1238 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1240 // add each pane to the dock
1241 int pane_i
, pane_count
= dock
.panes
.GetCount();
1245 wxArrayInt pane_positions
, pane_sizes
;
1247 // figure out the real pane positions we will
1248 // use, without modifying the each pane's pane_pos member
1249 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1252 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1254 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1255 int pane_pos
= pane_positions
.Item(pane_i
);
1257 int amount
= pane_pos
- offset
;
1260 if (dock
.IsVertical())
1261 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1263 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1265 part
.type
= wxDockUIPart::typeBackground
;
1269 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1270 part
.cont_sizer
= dock_sizer
;
1271 part
.sizer_item
= sizer_item
;
1277 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1279 offset
+= pane_sizes
.Item(pane_i
);
1282 // at the end add a very small stretchable background area
1283 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1285 part
.type
= wxDockUIPart::typeBackground
;
1289 part
.orientation
= orientation
;
1290 part
.cont_sizer
= dock_sizer
;
1291 part
.sizer_item
= sizer_item
;
1296 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1298 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1300 // if this is not the first pane being added,
1301 // we need to add a pane sizer
1304 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1306 part
.type
= wxDockUIPart::typePaneSizer
;
1308 part
.pane
= dock
.panes
.Item(pane_i
-1);
1310 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1311 part
.cont_sizer
= dock_sizer
;
1312 part
.sizer_item
= sizer_item
;
1316 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1320 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1321 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1323 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1325 part
.type
= wxDockUIPart::typeDock
;
1329 part
.orientation
= orientation
;
1330 part
.cont_sizer
= cont
;
1331 part
.sizer_item
= sizer_item
;
1334 if (dock
.IsHorizontal())
1335 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1337 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1339 // top and left docks have a sash after them
1340 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1341 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1343 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1345 part
.type
= wxDockUIPart::typeDockSizer
;
1349 part
.orientation
= orientation
;
1350 part
.cont_sizer
= cont
;
1351 part
.sizer_item
= sizer_item
;
1356 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1357 wxDockInfoArray
& docks
,
1358 wxDockUIPartArray
& uiparts
,
1361 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1363 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1364 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1365 wxSize cli_size
= m_frame
->GetClientSize();
1366 int i
, dock_count
, pane_count
;
1369 // empty all docks out
1370 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1371 docks
.Item(i
).panes
.Empty();
1373 // iterate through all known panes, filing each
1374 // of them into the appropriate dock. If the
1375 // pane does not exist in the dock, add it
1376 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1378 wxPaneInfo
& p
= panes
.Item(i
);
1380 // find any docks in this layer
1382 wxDockInfoPtrArray arr
;
1383 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1385 if (arr
.GetCount() > 0)
1391 // dock was not found, so we need to create a new one
1393 d
.dock_direction
= p
.dock_direction
;
1394 d
.dock_layer
= p
.dock_layer
;
1395 d
.dock_row
= p
.dock_row
;
1397 dock
= &docks
.Last();
1401 if (p
.IsDocked() && p
.IsShown())
1403 // remove the pane from any existing docks except this one
1404 RemovePaneFromDocks(docks
, p
, dock
);
1406 // pane needs to be added to the dock,
1407 // if it doesn't already exist
1408 if (!FindPaneInDock(*dock
, p
.window
))
1409 dock
->panes
.Add(&p
);
1413 // remove the pane from any existing docks
1414 RemovePaneFromDocks(docks
, p
);
1419 // remove any empty docks
1420 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1422 if (docks
.Item(i
).panes
.GetCount() == 0)
1426 // configure the docks further
1427 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1429 wxDockInfo
& dock
= docks
.Item(i
);
1430 int j
, dock_pane_count
= dock
.panes
.GetCount();
1432 // sort the dock pane array by the pane's
1433 // dock position (dock_pos), in ascending order
1434 dock
.panes
.Sort(PaneSortFunc
);
1436 // for newly created docks, set up their initial size
1441 for (j
= 0; j
< dock_pane_count
; ++j
)
1443 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1444 wxSize pane_size
= pane
.best_size
;
1445 if (pane_size
== wxDefaultSize
)
1446 pane_size
= pane
.min_size
;
1447 if (pane_size
== wxDefaultSize
)
1448 pane_size
= pane
.window
->GetSize();
1450 if (dock
.IsHorizontal())
1451 size
= wxMax(pane_size
.y
, size
);
1453 size
= wxMax(pane_size
.x
, size
);
1456 // add space for the border (two times), but only
1457 // if at least one pane inside the dock has a pane border
1458 for (j
= 0; j
< dock_pane_count
; ++j
)
1460 if (dock
.panes
.Item(j
)->HasBorder())
1462 size
+= (pane_border_size
*2);
1467 // if pane is on the top or bottom, add the caption height,
1468 // but only if at least one pane inside the dock has a caption
1469 if (dock
.IsHorizontal())
1471 for (j
= 0; j
< dock_pane_count
; ++j
)
1473 if (dock
.panes
.Item(j
)->HasCaption())
1475 size
+= caption_size
;
1481 // new dock's size may not be more than 1/3 of the frame size
1482 if (dock
.IsHorizontal())
1483 size
= wxMin(size
, cli_size
.y
/3);
1485 size
= wxMin(size
, cli_size
.x
/3);
1493 // determine the dock's minimum size
1494 bool plus_border
= false;
1495 bool plus_caption
= false;
1496 int dock_min_size
= 0;
1497 for (j
= 0; j
< dock_pane_count
; ++j
)
1499 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1500 if (pane
.min_size
!= wxDefaultSize
)
1502 if (pane
.HasBorder())
1504 if (pane
.HasCaption())
1505 plus_caption
= true;
1506 if (dock
.IsHorizontal())
1508 if (pane
.min_size
.y
> dock_min_size
)
1509 dock_min_size
= pane
.min_size
.y
;
1513 if (pane
.min_size
.x
> dock_min_size
)
1514 dock_min_size
= pane
.min_size
.x
;
1520 dock_min_size
+= (pane_border_size
*2);
1521 if (plus_caption
&& dock
.IsHorizontal())
1522 dock_min_size
+= (caption_size
);
1524 dock
.min_size
= dock_min_size
;
1527 // if the pane's current size is less than it's
1528 // minimum, increase the dock's size to it's minimum
1529 if (dock
.size
< dock
.min_size
)
1530 dock
.size
= dock
.min_size
;
1533 // determine the dock's mode (fixed or proportional);
1534 // determine whether the dock has only toolbars
1535 bool action_pane_marked
= false;
1537 dock
.toolbar
= true;
1538 for (j
= 0; j
< dock_pane_count
; ++j
)
1540 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1541 if (!pane
.IsFixed())
1543 if (!pane
.IsToolbar())
1544 dock
.toolbar
= false;
1545 if (pane
.state
& wxPaneInfo::actionPane
)
1546 action_pane_marked
= true;
1550 // if the dock mode is proportional and not fixed-pixel,
1551 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1552 // e.g. remove gaps like 1, 2, 30, 500
1555 for (j
= 0; j
< dock_pane_count
; ++j
)
1557 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1562 // if the dock mode is fixed, and none of the panes
1563 // are being moved right now, make sure the panes
1564 // do not overlap each other. If they do, we will
1565 // adjust the panes' positions
1566 if (dock
.fixed
&& !action_pane_marked
)
1568 wxArrayInt pane_positions
, pane_sizes
;
1569 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1572 for (j
= 0; j
< dock_pane_count
; ++j
)
1574 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1575 pane
.dock_pos
= pane_positions
[j
];
1577 int amount
= pane
.dock_pos
- offset
;
1581 pane
.dock_pos
+= -amount
;
1583 offset
+= pane_sizes
[j
];
1588 // discover the maximum dock layer
1590 for (i
= 0; i
< dock_count
; ++i
)
1591 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1594 // clear out uiparts
1597 // create a bunch of box sizers,
1598 // from the innermost level outwards.
1599 wxSizer
* cont
= NULL
;
1600 wxSizer
* middle
= NULL
;
1604 for (layer
= 0; layer
<= max_layer
; ++layer
)
1606 wxDockInfoPtrArray arr
;
1608 // find any docks in this layer
1609 FindDocks(docks
, -1, layer
, -1, arr
);
1611 // if there aren't any, skip to the next layer
1615 wxSizer
* old_cont
= cont
;
1617 // create a container which will hold this layer's
1618 // docks (top, bottom, left, right)
1619 cont
= new wxBoxSizer(wxVERTICAL
);
1622 // find any top docks in this layer
1623 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1624 RenumberDockRows(arr
);
1627 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1628 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1632 // fill out the middle layer (which consists
1633 // of left docks, content area and right docks)
1635 middle
= new wxBoxSizer(wxHORIZONTAL
);
1637 // find any left docks in this layer
1638 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1639 RenumberDockRows(arr
);
1642 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1643 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1646 // add content dock (or previous layer's sizer
1650 // find any center docks
1651 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1654 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1655 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1659 // there are no center docks, add a background area
1660 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1662 part
.type
= wxDockUIPart::typeBackground
;
1666 part
.cont_sizer
= middle
;
1667 part
.sizer_item
= sizer_item
;
1673 middle
->Add(old_cont
, 1, wxEXPAND
);
1676 // find any right docks in this layer
1677 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1678 RenumberDockRows(arr
);
1681 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1682 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1685 cont
->Add(middle
, 1, wxEXPAND
);
1689 // find any bottom docks in this layer
1690 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1691 RenumberDockRows(arr
);
1694 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1695 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1702 // no sizer available, because there are no docks,
1703 // therefore we will create a simple background area
1704 cont
= new wxBoxSizer(wxVERTICAL
);
1705 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1707 part
.type
= wxDockUIPart::typeBackground
;
1711 part
.cont_sizer
= middle
;
1712 part
.sizer_item
= sizer_item
;
1716 container
->Add(cont
, 1, wxEXPAND
);
1721 // Update() updates the layout. Whenever changes are made to
1722 // one or more panes, this function should be called. It is the
1723 // external entry point for running the layout engine.
1725 void wxFrameManager::Update()
1728 int i
, pane_count
= m_panes
.GetCount();
1730 // delete old sizer first
1731 m_frame
->SetSizer(NULL
);
1733 // destroy floating panes which have been
1734 // redocked or are becoming non-floating
1735 for (i
= 0; i
< pane_count
; ++i
)
1737 wxPaneInfo
& p
= m_panes
.Item(i
);
1739 if (!p
.IsFloating() && p
.frame
)
1741 // because the pane is no longer in a floating, we need to
1742 // reparent it to m_frame and destroy the floating frame
1745 p
.window
->SetSize(1,1);
1746 p
.frame
->Show(false);
1748 // reparent to m_frame and destroy the pane
1749 p
.window
->Reparent(m_frame
);
1750 p
.frame
->SetSizer(NULL
);
1757 // create a layout for all of the panes
1758 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
1760 // hide or show panes as necessary,
1761 // and float panes as necessary
1762 for (i
= 0; i
< pane_count
; ++i
)
1764 wxPaneInfo
& p
= m_panes
.Item(i
);
1768 if (p
.frame
== NULL
)
1770 // we need to create a frame for this
1771 // pane, which has recently been floated
1772 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
1777 // on MSW, if the owner desires transparent dragging, and
1778 // the dragging is happening right now, then the floating
1779 // window should have this style by default
1781 if (m_action
== actionDragFloatingPane
&&
1782 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
1783 MakeWindowTransparent(frame
, 150);
1786 frame
->SetPaneWindow(p
);
1796 // frame already exists, make sure it's position
1797 // and size reflect the information in wxPaneInfo
1798 if (p
.frame
->GetPosition() != p
.floating_pos
)
1800 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
1801 -1, -1, wxSIZE_USE_EXISTING
);
1802 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
1805 p
.frame
->Show(p
.IsShown());
1810 p
.window
->Show(p
.IsShown());
1813 // if "active panes" are no longer allowed, clear
1814 // any optionActive values from the pane states
1815 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
1817 p
.state
&= ~wxPaneInfo::optionActive
;
1822 // keep track of the old window rectangles so we can
1823 // refresh those windows whose rect has changed
1824 wxAuiRectArray old_pane_rects
;
1825 for (i
= 0; i
< pane_count
; ++i
)
1828 wxPaneInfo
& p
= m_panes
.Item(i
);
1830 if (p
.window
&& p
.IsShown() && p
.IsDocked())
1833 old_pane_rects
.Add(r
);
1839 // apply the new sizer
1840 m_frame
->SetSizer(sizer
);
1841 m_frame
->SetAutoLayout(false);
1846 // now that the frame layout is done, we need to check
1847 // the new pane rectangles against the old rectangles that
1848 // we saved a few lines above here. If the rectangles have
1849 // changed, the corresponding panes must also be updated
1850 for (i
= 0; i
< pane_count
; ++i
)
1852 wxPaneInfo
& p
= m_panes
.Item(i
);
1853 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
1855 if (p
.rect
!= old_pane_rects
[i
])
1857 p
.window
->Refresh();
1866 // set frame's minimum size
1869 // N.B. More work needs to be done on frame minimum sizes;
1870 // this is some intresting code that imposes the minimum size,
1871 // but we may want to include a more flexible mechanism or
1872 // options for multiple minimum-size modes, e.g. strict or lax
1873 wxSize min_size = sizer->GetMinSize();
1874 wxSize frame_size = m_frame->GetSize();
1875 wxSize client_size = m_frame->GetClientSize();
1877 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
1878 min_size.y+frame_size.y-client_size.y );
1880 m_frame->SetMinSize(minframe_size);
1882 if (frame_size.x < minframe_size.x ||
1883 frame_size.y < minframe_size.y)
1884 sizer->Fit(m_frame);
1889 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
1890 // on the frame's main sizer, then measures all the various UI items
1891 // and updates their internal rectangles. This should always be called
1892 // instead of calling m_frame->Layout() directly
1894 void wxFrameManager::DoFrameLayout()
1899 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1901 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1903 // get the rectangle of the UI part
1904 // originally, this code looked like this:
1905 // part.rect = wxRect(part.sizer_item->GetPosition(),
1906 // part.sizer_item->GetSize());
1907 // this worked quite well, with one exception: the mdi
1908 // client window had a "deferred" size variable
1909 // that returned the wrong size. It looks like
1910 // a bug in wx, because the former size of the window
1911 // was being returned. So, we will retrieve the part's
1912 // rectangle via other means
1915 part
.rect
= part
.sizer_item
->GetRect();
1916 int flag
= part
.sizer_item
->GetFlag();
1917 int border
= part
.sizer_item
->GetBorder();
1920 part
.rect
.y
-= border
;
1921 part
.rect
.height
+= border
;
1925 part
.rect
.x
-= border
;
1926 part
.rect
.width
+= border
;
1928 if (flag
& wxBOTTOM
)
1929 part
.rect
.height
+= border
;
1931 part
.rect
.width
+= border
;
1934 if (part
.type
== wxDockUIPart::typeDock
)
1935 part
.dock
->rect
= part
.rect
;
1936 if (part
.type
== wxDockUIPart::typePane
)
1937 part
.pane
->rect
= part
.rect
;
1941 // GetPanePart() looks up the pane the pane border UI part (or the regular
1942 // pane part if there is no border). This allows the caller to get the exact
1943 // rectangle of the pane in question, including decorations like
1944 // caption and border (if any).
1946 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
1949 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1951 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1952 if (part
.type
== wxDockUIPart::typePaneBorder
&&
1953 part
.pane
&& part
.pane
->window
== wnd
)
1956 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1958 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1959 if (part
.type
== wxDockUIPart::typePane
&&
1960 part
.pane
&& part
.pane
->window
== wnd
)
1968 // GetDockPixelOffset() is an internal function which returns
1969 // a dock's offset in pixels from the left side of the window
1970 // (for horizontal docks) or from the top of the window (for
1971 // vertical docks). This value is necessary for calculating
1972 // fixel-pane/toolbar offsets when they are dragged.
1974 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
1976 // the only way to accurately calculate the dock's
1977 // offset is to actually run a theoretical layout
1979 int i
, part_count
, dock_count
;
1980 wxDockInfoArray docks
;
1981 wxPaneInfoArray panes
;
1982 wxDockUIPartArray uiparts
;
1983 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
1986 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
1987 wxSize client_size
= m_frame
->GetClientSize();
1988 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
1991 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
1993 wxDockUIPart
& part
= uiparts
.Item(i
);
1994 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
1995 part
.sizer_item
->GetSize());
1996 if (part
.type
== wxDockUIPart::typeDock
)
1997 part
.dock
->rect
= part
.rect
;
2002 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2004 wxDockInfo
& dock
= docks
.Item(i
);
2005 if (test
.dock_direction
== dock
.dock_direction
&&
2006 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2008 if (dock
.IsVertical())
2020 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2021 // if a dock operation is allowed, the new dock position is copied into
2022 // the target info. If the operation was allowed, the function returns true.
2024 static bool ProcessDockResult(wxPaneInfo
& target
,
2025 const wxPaneInfo
& new_pos
)
2027 bool allowed
= false;
2028 switch (new_pos
.dock_direction
)
2030 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2031 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2032 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2033 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2043 // DoDrop() is an important function. It basically takes a mouse position,
2044 // and determines where the pane's new position would be. If the pane is to be
2045 // dropped, it performs the drop operation using the specified dock and pane
2046 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2047 // scenario can be performed, giving precise coordinates for drop hints.
2048 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2049 // as parameters, the changes will be made to the main state arrays
2051 const int auiInsertRowPixels
= 10;
2052 const int auiNewRowPixels
= 40;
2053 const int auiLayerInsertPixels
= 40;
2054 const int auiLayerInsertOffset
= 5;
2056 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2057 wxPaneInfoArray
& panes
,
2060 const wxPoint
& offset
)
2062 wxSize cli_size
= m_frame
->GetClientSize();
2064 wxPaneInfo drop
= target
;
2067 // The result should always be shown
2071 // Check to see if the pane has been dragged outside of the window
2072 // (or near to the outside of the window), if so, dock it along the edge
2075 int layer_insert_offset
= auiLayerInsertOffset
;
2076 if (target
.IsToolbar())
2077 layer_insert_offset
= 0;
2079 if (pt
.x
< layer_insert_offset
&&
2080 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2082 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2083 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2084 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2088 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2089 return ProcessDockResult(target
, drop
);
2091 else if (pt
.y
< layer_insert_offset
&&
2092 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2094 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2095 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2096 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2100 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2101 return ProcessDockResult(target
, drop
);
2103 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2104 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2106 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2107 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2108 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2109 drop
.Dock().Right().
2112 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2113 return ProcessDockResult(target
, drop
);
2115 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2116 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2118 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2119 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2120 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2121 drop
.Dock().Bottom().
2124 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2125 return ProcessDockResult(target
, drop
);
2129 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2132 if (drop
.IsToolbar())
2134 if (!part
|| !part
->dock
)
2138 // calculate the offset from where the dock begins
2139 // to the point where the user dropped the pane
2140 int dock_drop_offset
= 0;
2141 if (part
->dock
->IsHorizontal())
2142 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2144 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2147 // toolbars may only be moved in and to fixed-pane docks,
2148 // otherwise we will try to float the pane. Also, the pane
2149 // should float if being dragged over center pane windows
2150 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2152 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2153 (drop
.IsFloatable() ||
2154 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2155 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2160 return ProcessDockResult(target
, drop
);
2164 Direction(part
->dock
->dock_direction
).
2165 Layer(part
->dock
->dock_layer
).
2166 Row(part
->dock
->dock_row
).
2167 Position(dock_drop_offset
);
2170 ((pt
.y
< part
->dock
->rect
.y
+ 2) && part
->dock
->IsHorizontal()) ||
2171 ((pt
.x
< part
->dock
->rect
.x
+ 2) && part
->dock
->IsVertical())
2172 ) && part
->dock
->panes
.GetCount() > 1)
2174 int row
= drop
.dock_row
;
2175 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2176 part
->dock
->dock_layer
,
2177 part
->dock
->dock_row
);
2178 drop
.dock_row
= row
;
2182 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2183 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2184 ) && part
->dock
->panes
.GetCount() > 1)
2186 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2187 part
->dock
->dock_layer
,
2188 part
->dock
->dock_row
+1);
2189 drop
.dock_row
= part
->dock
->dock_row
+1;
2192 return ProcessDockResult(target
, drop
);
2201 if (part
->type
== wxDockUIPart::typePaneBorder
||
2202 part
->type
== wxDockUIPart::typeCaption
||
2203 part
->type
== wxDockUIPart::typeGripper
||
2204 part
->type
== wxDockUIPart::typePaneButton
||
2205 part
->type
== wxDockUIPart::typePane
||
2206 part
->type
== wxDockUIPart::typePaneSizer
||
2207 part
->type
== wxDockUIPart::typeDockSizer
||
2208 part
->type
== wxDockUIPart::typeBackground
)
2210 if (part
->type
== wxDockUIPart::typeDockSizer
)
2212 if (part
->dock
->panes
.GetCount() != 1)
2214 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2221 // If a normal frame is being dragged over a toolbar, insert it
2222 // along the edge under the toolbar, but over all other panes.
2223 // (this could be done much better, but somehow factoring this
2224 // calculation with the one at the beginning of this function)
2225 if (part
->dock
&& part
->dock
->toolbar
)
2229 switch (part
->dock
->dock_direction
)
2231 case wxAUI_DOCK_LEFT
:
2232 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2233 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2234 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2236 case wxAUI_DOCK_TOP
:
2237 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2238 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2239 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2241 case wxAUI_DOCK_RIGHT
:
2242 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2243 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2244 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2246 case wxAUI_DOCK_BOTTOM
:
2247 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2248 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2249 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2253 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2256 Direction(part
->dock
->dock_direction
).
2257 Layer(layer
).Row(0).Position(0);
2258 return ProcessDockResult(target
, drop
);
2265 part
= GetPanePart(part
->pane
->window
);
2269 bool insert_dock_row
= false;
2270 int insert_row
= part
->pane
->dock_row
;
2271 int insert_dir
= part
->pane
->dock_direction
;
2272 int insert_layer
= part
->pane
->dock_layer
;
2274 switch (part
->pane
->dock_direction
)
2276 case wxAUI_DOCK_TOP
:
2277 if (pt
.y
>= part
->rect
.y
&&
2278 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2279 insert_dock_row
= true;
2281 case wxAUI_DOCK_BOTTOM
:
2282 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2283 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2284 insert_dock_row
= true;
2286 case wxAUI_DOCK_LEFT
:
2287 if (pt
.x
>= part
->rect
.x
&&
2288 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2289 insert_dock_row
= true;
2291 case wxAUI_DOCK_RIGHT
:
2292 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2293 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2294 insert_dock_row
= true;
2296 case wxAUI_DOCK_CENTER
:
2298 // "new row pixels" will be set to the default, but
2299 // must never exceed 20% of the window size
2300 int new_row_pixels_x
= auiNewRowPixels
;
2301 int new_row_pixels_y
= auiNewRowPixels
;
2303 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2304 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2306 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2307 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2310 // determine if the mouse pointer is in a location that
2311 // will cause a new row to be inserted. The hot spot positions
2312 // are along the borders of the center pane
2315 insert_dock_row
= true;
2316 if (pt
.x
>= part
->rect
.x
&&
2317 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2318 insert_dir
= wxAUI_DOCK_LEFT
;
2320 if (pt
.y
>= part
->rect
.y
&&
2321 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2322 insert_dir
= wxAUI_DOCK_TOP
;
2324 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2325 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2326 insert_dir
= wxAUI_DOCK_RIGHT
;
2328 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2329 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2330 insert_dir
= wxAUI_DOCK_BOTTOM
;
2334 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2338 if (insert_dock_row
)
2340 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2341 drop
.Dock().Direction(insert_dir
).
2342 Layer(insert_layer
).
2345 return ProcessDockResult(target
, drop
);
2348 // determine the mouse offset and the pane size, both in the
2349 // direction of the dock itself, and perpendicular to the dock
2353 if (part
->orientation
== wxVERTICAL
)
2355 offset
= pt
.y
- part
->rect
.y
;
2356 size
= part
->rect
.GetHeight();
2360 offset
= pt
.x
- part
->rect
.x
;
2361 size
= part
->rect
.GetWidth();
2364 int drop_position
= part
->pane
->dock_pos
;
2366 // if we are in the top/left part of the pane,
2367 // insert the pane before the pane being hovered over
2368 if (offset
<= size
/2)
2370 drop_position
= part
->pane
->dock_pos
;
2372 part
->pane
->dock_direction
,
2373 part
->pane
->dock_layer
,
2374 part
->pane
->dock_row
,
2375 part
->pane
->dock_pos
);
2378 // if we are in the bottom/right part of the pane,
2379 // insert the pane before the pane being hovered over
2380 if (offset
> size
/2)
2382 drop_position
= part
->pane
->dock_pos
+1;
2384 part
->pane
->dock_direction
,
2385 part
->pane
->dock_layer
,
2386 part
->pane
->dock_row
,
2387 part
->pane
->dock_pos
+1);
2391 Direction(part
->dock
->dock_direction
).
2392 Layer(part
->dock
->dock_layer
).
2393 Row(part
->dock
->dock_row
).
2394 Position(drop_position
);
2395 return ProcessDockResult(target
, drop
);
2402 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2405 if (!m_hint_wnd
|| m_hint_fadeamt
>= 50)
2407 m_hint_fadetimer
.Stop();
2411 m_hint_fadeamt
+= 5;
2412 MakeWindowTransparent(m_hint_wnd
, m_hint_fadeamt
);
2416 void wxFrameManager::ShowHint(const wxRect
& rect
)
2420 // First, determine if the operating system can handle transparency.
2421 // Transparency is available on Win2000 and above
2423 static int os_type
= -1;
2424 static int ver_major
= -1;
2427 os_type
= ::wxGetOsVersion(&ver_major
);
2429 // If the transparent flag is set, and the OS supports it,
2430 // go ahead and use a transparent hint
2432 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 &&
2433 os_type
== wxWINDOWS_NT
&& ver_major
>= 5)
2435 if (m_last_hint
== rect
)
2439 int initial_fade
= 50;
2440 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2443 if (m_hint_wnd
== NULL
)
2445 wxPoint pt
= rect
.GetPosition();
2446 wxSize size
= rect
.GetSize();
2447 m_hint_wnd
= new wxFrame(m_frame
, -1, wxEmptyString
, pt
, size
,
2448 wxFRAME_TOOL_WINDOW
|
2449 wxFRAME_FLOAT_ON_PARENT
|
2450 wxFRAME_NO_TASKBAR
|
2453 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2454 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
2457 // if we are dragging a floating pane, set the focus
2458 // back to that floating pane (otherwise it becomes unfocused)
2459 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2460 m_action_window
->SetFocus();
2465 wxPoint pt
= rect
.GetPosition();
2466 wxSize size
= rect
.GetSize();
2467 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2468 m_hint_wnd
->SetSize(pt
.x
, pt
.y
, rect
.width
, rect
.height
);
2471 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2473 // start fade in timer
2475 m_hint_fadetimer
.SetOwner(this, 101);
2476 m_hint_fadetimer
.Start(5);
2483 if (m_last_hint
!= rect
)
2485 // remove the last hint rectangle
2491 wxScreenDC screendc
;
2492 wxRegion
clip(1, 1, 10000, 10000);
2494 // clip all floating windows, so we don't draw over them
2496 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2498 wxPaneInfo
& pane
= m_panes
.Item(i
);
2500 if (pane
.IsFloating() &&
2501 pane
.frame
->IsShown())
2503 wxRect rect
= pane
.frame
->GetRect();
2505 // wxGTK returns the client size, not the whole frame size
2511 clip
.Subtract(rect
);
2515 screendc
.SetClippingRegion(clip
);
2517 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2518 wxBrush
brush(stipple
);
2519 screendc
.SetBrush(brush
);
2520 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2522 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2523 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2524 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2525 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2528 void wxFrameManager::HideHint()
2530 // hides a transparent window hint (currently wxMSW only)
2534 MakeWindowTransparent(m_hint_wnd
, 0);
2535 m_hint_fadetimer
.Stop();
2536 m_last_hint
= wxRect();
2541 // hides a painted hint by redrawing the frame window
2542 if (!m_last_hint
.IsEmpty())
2546 m_last_hint
= wxRect();
2552 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2553 // determine the exact position the pane would be at were if dropped. If
2554 // the pame would indeed become docked at the specified drop point,
2555 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2556 // "pane_window" is the window pointer of the pane being dragged, pt is
2557 // the mouse position, in client coordinates
2558 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2560 const wxPoint
& offset
)
2564 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2565 // we will create a new temporary layout and then measure the resulting
2566 // rectangle; we will create a copy of the docking structures (m_dock)
2567 // so that we don't modify the real thing on screen
2569 int i
, pane_count
, part_count
;
2570 wxDockInfoArray docks
;
2571 wxPaneInfoArray panes
;
2572 wxDockUIPartArray uiparts
;
2573 wxPaneInfo hint
= GetPane(pane_window
);
2574 hint
.name
= wxT("__HINT__");
2579 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2581 // remove any pane already there which bears the same window;
2582 // this happens when you are moving a pane around in a dock
2583 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2585 if (panes
.Item(i
).window
== pane_window
)
2587 RemovePaneFromDocks(docks
, panes
.Item(i
));
2593 // find out where the new pane would be
2594 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2602 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2603 wxSize client_size
= m_frame
->GetClientSize();
2604 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2607 for (i
= 0, part_count
= uiparts
.GetCount();
2608 i
< part_count
; ++i
)
2610 wxDockUIPart
& part
= uiparts
.Item(i
);
2612 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2613 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2615 rect
= wxRect(part
.sizer_item
->GetPosition(),
2616 part
.sizer_item
->GetSize());
2629 // actually show the hint rectangle on the screen
2630 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2634 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2636 // try to find the pane
2637 wxPaneInfo
& pane
= GetPane(wnd
);
2638 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2641 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2642 MakeWindowTransparent(pane
.frame
, 150);
2646 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
)
2648 // try to find the pane
2649 wxPaneInfo
& pane
= GetPane(wnd
);
2650 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2652 wxPoint pt
= ::wxGetMousePosition();
2653 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2655 // calculate the offset from the upper left-hand corner
2656 // of the frame to the mouse pointer
2657 wxPoint frame_pos
= pane
.frame
->GetPosition();
2658 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2660 // no hint for toolbar floating windows
2661 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
2663 if (m_action
== actionDragFloatingPane
)
2665 wxDockInfoArray docks
;
2666 wxPaneInfoArray panes
;
2667 wxDockUIPartArray uiparts
;
2668 wxPaneInfo hint
= pane
;
2670 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2672 // find out where the new pane would be
2673 if (!DoDrop(docks
, panes
, hint
, client_pt
))
2675 if (hint
.IsFloating())
2679 m_action
= actionDragToolbarPane
;
2680 m_action_window
= pane
.window
;
2689 // if a key modifier is pressed while dragging the frame,
2690 // don't dock the window
2691 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2698 DrawHintRect(wnd
, client_pt
, action_offset
);
2701 // this cleans up some screen artifacts that are caused on GTK because
2702 // we aren't getting the exact size of the window (see comment
2712 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
)
2714 // try to find the pane
2715 wxPaneInfo
& pane
= GetPane(wnd
);
2716 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2718 wxPoint pt
= ::wxGetMousePosition();
2719 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2721 // calculate the offset from the upper left-hand corner
2722 // of the frame to the mouse pointer
2723 wxPoint frame_pos
= pane
.frame
->GetPosition();
2724 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2727 // if a key modifier is pressed while dragging the frame,
2728 // don't dock the window
2729 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2736 // do the drop calculation
2737 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
2739 // if the pane is still floating, update it's floating
2740 // position (that we store)
2741 if (pane
.IsFloating())
2743 pane
.floating_pos
= pane
.frame
->GetPosition();
2746 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2747 MakeWindowTransparent(pane
.frame
, 255);
2756 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
2758 // try to find the pane
2759 wxPaneInfo
& pane
= GetPane(wnd
);
2760 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2762 pane
.floating_size
= size
;
2765 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
)
2767 // try to find the pane
2768 wxPaneInfo
& pane
= GetPane(wnd
);
2769 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2771 // reparent the pane window back to us and
2772 // prepare the frame window for destruction
2773 pane
.window
->Show(false);
2774 pane
.window
->Reparent(m_frame
);
2779 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
2781 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
2783 // try to find the pane
2784 wxPaneInfo
& pane
= GetPane(wnd
);
2785 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2787 SetActivePane(m_panes
, wnd
);
2792 // Render() draws all of the pane captions, sashes,
2793 // backgrounds, captions, grippers, pane borders and buttons.
2794 // It renders the entire user interface.
2796 void wxFrameManager::Render(wxDC
* dc
)
2802 for (i
= 0, part_count
= m_uiparts
.GetCount();
2803 i
< part_count
; ++i
)
2805 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2807 // don't draw hidden pane items
2808 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
2813 case wxDockUIPart::typeDockSizer
:
2814 case wxDockUIPart::typePaneSizer
:
2815 m_art
->DrawSash(*dc
, part
.orientation
, part
.rect
);
2817 case wxDockUIPart::typeBackground
:
2818 m_art
->DrawBackground(*dc
, part
.orientation
, part
.rect
);
2820 case wxDockUIPart::typeCaption
:
2821 m_art
->DrawCaption(*dc
, part
.pane
->caption
, part
.rect
, *part
.pane
);
2823 case wxDockUIPart::typeGripper
:
2824 m_art
->DrawGripper(*dc
, part
.rect
, *part
.pane
);
2826 case wxDockUIPart::typePaneBorder
:
2827 m_art
->DrawBorder(*dc
, part
.rect
, *part
.pane
);
2829 case wxDockUIPart::typePaneButton
:
2830 m_art
->DrawPaneButton(*dc
, part
.button
->button_id
,
2831 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
2837 void wxFrameManager::Repaint(wxDC
* dc
)
2842 m_frame
->Refresh() ;
2848 m_frame
->GetClientSize(&w
, &h
);
2850 // figure out which dc to use; if one
2851 // has been specified, use it, otherwise
2853 wxClientDC
* client_dc
= NULL
;
2856 client_dc
= new wxClientDC(m_frame
);
2860 // if the frame has a toolbar, the client area
2861 // origin will not be (0,0).
2862 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2863 if (pt
.x
!= 0 || pt
.y
!= 0)
2864 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
2866 // render all the items
2869 // if we created a client_dc, delete it
2874 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2876 wxPaintDC
dc(m_frame
);
2880 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
2889 void wxFrameManager::OnSize(wxSizeEvent
& WXUNUSED(event
))
2899 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
2902 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2903 wxCursor cursor
= wxNullCursor
;
2907 if (part
->type
== wxDockUIPart::typeDockSizer
||
2908 part
->type
== wxDockUIPart::typePaneSizer
)
2910 // a dock may not be resized if it has a single
2911 // pane which is not resizable
2912 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
2913 part
->dock
->panes
.GetCount() == 1 &&
2914 part
->dock
->panes
.Item(0)->IsFixed())
2917 // panes that may not be resized do not get a sizing cursor
2918 if (part
->pane
&& part
->pane
->IsFixed())
2921 if (part
->orientation
== wxVERTICAL
)
2922 cursor
= wxCursor(wxCURSOR_SIZEWE
);
2924 cursor
= wxCursor(wxCURSOR_SIZENS
);
2926 else if (part
->type
== wxDockUIPart::typeGripper
)
2928 cursor
= wxCursor(wxCURSOR_SIZING
);
2932 event
.SetCursor(cursor
);
2937 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
2938 const wxMouseEvent
& event
)
2940 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
2942 int state
= wxAUI_BUTTON_STATE_NORMAL
;
2944 if (hit_test
== button_ui_part
)
2946 if (event
.LeftDown())
2947 state
= wxAUI_BUTTON_STATE_PRESSED
;
2949 state
= wxAUI_BUTTON_STATE_HOVER
;
2953 if (event
.LeftDown())
2954 state
= wxAUI_BUTTON_STATE_HOVER
;
2957 // now repaint the button with hover state
2958 wxClientDC
cdc(m_frame
);
2960 // if the frame has a toolbar, the client area
2961 // origin will not be (0,0).
2962 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2963 if (pt
.x
!= 0 || pt
.y
!= 0)
2964 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
2966 m_art
->DrawPaneButton(cdc
,
2967 button_ui_part
->button
->button_id
,
2969 button_ui_part
->rect
,
2973 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
2975 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2978 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2981 if (part
->type
== wxDockUIPart::typeDockSizer
||
2982 part
->type
== wxDockUIPart::typePaneSizer
)
2984 // a dock may not be resized if it has a single
2985 // pane which is not resizable
2986 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
2987 part
->dock
->panes
.GetCount() == 1 &&
2988 part
->dock
->panes
.Item(0)->IsFixed())
2991 // panes that may not be resized should be ignored here
2992 if (part
->pane
&& part
->pane
->IsFixed())
2995 m_action
= actionResize
;
2996 m_action_part
= part
;
2997 m_action_hintrect
= wxRect();
2998 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
2999 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3000 event
.m_y
- part
->rect
.y
);
3001 m_frame
->CaptureMouse();
3003 else if (part
->type
== wxDockUIPart::typePaneButton
)
3005 m_action
= actionClickButton
;
3006 m_action_part
= part
;
3007 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3008 m_frame
->CaptureMouse();
3010 UpdateButtonOnScreen(part
, event
);
3012 else if (part
->type
== wxDockUIPart::typeCaption
||
3013 part
->type
== wxDockUIPart::typeGripper
)
3015 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3017 // set the caption as active
3018 SetActivePane(m_panes
, part
->pane
->window
);
3022 m_action
= actionClickCaption
;
3023 m_action_part
= part
;
3024 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3025 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3026 event
.m_y
- part
->rect
.y
);
3027 m_frame
->CaptureMouse();
3047 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3049 if (m_action
== actionResize
)
3051 m_frame
->ReleaseMouse();
3053 // get rid of the hint rectangle
3055 DrawResizeHint(dc
, m_action_hintrect
);
3057 // resize the dock or the pane
3058 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3060 wxRect
& rect
= m_action_part
->dock
->rect
;
3062 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3063 event
.m_y
- m_action_offset
.y
);
3065 switch (m_action_part
->dock
->dock_direction
)
3067 case wxAUI_DOCK_LEFT
:
3068 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3070 case wxAUI_DOCK_TOP
:
3071 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3073 case wxAUI_DOCK_RIGHT
:
3074 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3075 new_pos
.x
- m_action_part
->rect
.GetWidth();
3077 case wxAUI_DOCK_BOTTOM
:
3078 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3079 new_pos
.y
- m_action_part
->rect
.GetHeight();
3086 else if (m_action_part
&&
3087 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3089 wxDockInfo
& dock
= *m_action_part
->dock
;
3090 wxPaneInfo
& pane
= *m_action_part
->pane
;
3092 int total_proportion
= 0;
3093 int dock_pixels
= 0;
3094 int new_pixsize
= 0;
3096 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3097 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3098 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3100 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3101 event
.m_y
- m_action_offset
.y
);
3103 // determine the pane rectangle by getting the pane part
3104 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3105 wxASSERT_MSG(pane_part
,
3106 wxT("Pane border part not found -- shouldn't happen"));
3108 // determine the new pixel size that the user wants;
3109 // this will help us recalculate the pane's proportion
3110 if (dock
.IsHorizontal())
3111 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3113 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3115 // determine the size of the dock, based on orientation
3116 if (dock
.IsHorizontal())
3117 dock_pixels
= dock
.rect
.GetWidth();
3119 dock_pixels
= dock
.rect
.GetHeight();
3121 // determine the total proportion of all resizable panes,
3122 // and the total size of the dock minus the size of all
3124 int i
, dock_pane_count
= dock
.panes
.GetCount();
3125 int pane_position
= -1;
3126 for (i
= 0; i
< dock_pane_count
; ++i
)
3128 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3129 if (p
.window
== pane
.window
)
3132 // while we're at it, subtract the pane sash
3133 // width from the dock width, because this would
3134 // skew our proportion calculations
3136 dock_pixels
-= sash_size
;
3138 // also, the whole size (including decorations) of
3139 // all fixed panes must also be subtracted, because they
3140 // are not part of the proportion calculation
3143 if (dock
.IsHorizontal())
3144 dock_pixels
-= p
.best_size
.x
;
3146 dock_pixels
-= p
.best_size
.y
;
3150 total_proportion
+= p
.dock_proportion
;
3154 // find a pane in our dock to 'steal' space from or to 'give'
3155 // space to -- this is essentially what is done when a pane is
3156 // resized; the pane should usually be the first non-fixed pane
3157 // to the right of the action pane
3158 int borrow_pane
= -1;
3159 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3161 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3170 // demand that the pane being resized is found in this dock
3171 // (this assert really never should be raised)
3172 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3174 // prevent division by zero
3175 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3177 m_action
= actionNone
;
3181 // calculate the new proportion of the pane
3182 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3184 // default minimum size
3187 // check against the pane's minimum size, if specified. please note
3188 // that this is not enough to ensure that the minimum size will
3189 // not be violated, because the whole frame might later be shrunk,
3190 // causing the size of the pane to violate it's minimum size
3191 if (pane
.min_size
.IsFullySpecified())
3195 if (pane
.HasBorder())
3196 min_size
+= (pane_border_size
*2);
3198 // calculate minimum size with decorations (border,caption)
3199 if (pane_part
->orientation
== wxVERTICAL
)
3201 min_size
+= pane
.min_size
.y
;
3202 if (pane
.HasCaption())
3203 min_size
+= caption_size
;
3207 min_size
+= pane
.min_size
.x
;
3212 // for some reason, an arithmatic error somewhere is causing
3213 // the proportion calculations to always be off by 1 pixel;
3214 // for now we will add the 1 pixel on, but we really should
3215 // determine what's causing this.
3218 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3220 if (new_proportion
< min_proportion
)
3221 new_proportion
= min_proportion
;
3225 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3227 // borrow the space from our neighbor pane to the
3228 // right or bottom (depending on orientation)
3229 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3230 pane
.dock_proportion
= new_proportion
;
3237 else if (m_action
== actionClickButton
)
3239 m_hover_button
= NULL
;
3240 m_frame
->ReleaseMouse();
3241 UpdateButtonOnScreen(m_action_part
, event
);
3243 // make sure we're still over the item that was originally clicked
3244 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3246 // fire button-click event
3247 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3248 e
.SetPane(m_action_part
->pane
);
3249 e
.SetButton(m_action_part
->button
->button_id
);
3253 else if (m_action
== actionClickCaption
)
3255 m_frame
->ReleaseMouse();
3257 else if (m_action
== actionDragFloatingPane
)
3259 m_frame
->ReleaseMouse();
3261 else if (m_action
== actionDragToolbarPane
)
3263 m_frame
->ReleaseMouse();
3265 wxPaneInfo
& pane
= GetPane(m_action_window
);
3266 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3268 // save the new positions
3269 wxDockInfoPtrArray docks
;
3270 FindDocks(m_docks
, pane
.dock_direction
,
3271 pane
.dock_layer
, pane
.dock_row
, docks
);
3272 if (docks
.GetCount() == 1)
3274 wxDockInfo
& dock
= *docks
.Item(0);
3276 wxArrayInt pane_positions
, pane_sizes
;
3277 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3279 int i
, dock_pane_count
= dock
.panes
.GetCount();
3280 for (i
= 0; i
< dock_pane_count
; ++i
)
3281 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3284 pane
.state
&= ~wxPaneInfo::actionPane
;
3292 m_action
= actionNone
;
3293 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3297 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3299 // sometimes when Update() is called from inside this method,
3300 // a spurious mouse move event is generated; this check will make
3301 // sure that only real mouse moves will get anywhere in this method;
3302 // this appears to be a bug somewhere, and I don't know where the
3303 // mouse move event is being generated. only verified on MSW
3305 wxPoint mouse_pos
= event
.GetPosition();
3306 if (m_last_mouse_move
== mouse_pos
)
3308 m_last_mouse_move
= mouse_pos
;
3311 if (m_action
== actionResize
)
3313 wxPoint pos
= m_action_part
->rect
.GetPosition();
3314 if (m_action_part
->orientation
== wxHORIZONTAL
)
3315 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3317 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3319 wxRect
rect(m_frame
->ClientToScreen(pos
),
3320 m_action_part
->rect
.GetSize());
3323 if (!m_action_hintrect
.IsEmpty())
3324 DrawResizeHint(dc
, m_action_hintrect
);
3325 DrawResizeHint(dc
, rect
);
3326 m_action_hintrect
= rect
;
3328 else if (m_action
== actionClickCaption
)
3330 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3331 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3333 // caption has been clicked. we need to check if the mouse
3334 // is now being dragged. if it is, we need to change the
3335 // mouse action to 'drag'
3336 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3337 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3339 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3341 if (!pane_info
->IsToolbar())
3343 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3344 pane_info
->IsFloatable())
3346 m_action
= actionDragFloatingPane
;
3348 // set initial float position
3349 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3350 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3351 pt
.y
- m_action_offset
.y
);
3356 m_action_window
= pane_info
->frame
;
3358 // action offset is used here to make it feel "natural" to the user
3359 // to drag a docked pane and suddenly have it become a floating frame.
3360 // Sometimes, however, the offset where the user clicked on the docked
3361 // caption is bigger than the width of the floating frame itself, so
3362 // in that case we need to set the action offset to a sensible value
3363 wxSize frame_size
= m_action_window
->GetSize();
3364 if (frame_size
.x
<= m_action_offset
.x
)
3365 m_action_offset
.x
= 30;
3370 m_action
= actionDragToolbarPane
;
3371 m_action_window
= pane_info
->window
;
3375 else if (m_action
== actionDragFloatingPane
)
3377 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3378 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3379 pt
.y
- m_action_offset
.y
);
3381 else if (m_action
== actionDragToolbarPane
)
3383 wxPaneInfo
& pane
= GetPane(m_action_window
);
3384 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3386 pane
.state
|= wxPaneInfo::actionPane
;
3388 wxPoint pt
= event
.GetPosition();
3389 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3391 // if DoDrop() decided to float the pane, set up
3392 // the floating pane's initial position
3393 if (pane
.IsFloating())
3395 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3396 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3397 pt
.y
- m_action_offset
.y
);
3400 // this will do the actiual move operation;
3401 // in the case that the pane has been floated,
3402 // this call will create the floating pane
3403 // and do the reparenting
3406 // if the pane has been floated, change the mouse
3407 // action actionDragFloatingPane so that subsequent
3408 // EVT_MOTION() events will move the floating pane
3409 if (pane
.IsFloating())
3411 pane
.state
&= ~wxPaneInfo::actionPane
;
3412 m_action
= actionDragFloatingPane
;
3413 m_action_window
= pane
.frame
;
3418 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3419 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3421 if (part
!= m_hover_button
)
3423 // make the old button normal
3425 UpdateButtonOnScreen(m_hover_button
, event
);
3427 // mouse is over a button, so repaint the
3428 // button in hover mode
3429 UpdateButtonOnScreen(part
, event
);
3430 m_hover_button
= part
;
3437 m_hover_button
= NULL
;
3448 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3452 m_hover_button
= NULL
;
3457 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3459 // when a child pane has it's focus set, we should change the
3460 // pane's active state to reflect this. (this is only true if
3461 // active panes are allowed by the owner)
3462 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3464 if (GetPane(event
.GetWindow()).IsOk())
3466 SetActivePane(m_panes
, event
.GetWindow());
3473 // OnPaneButton() is an event handler that is called
3474 // when a pane button has been pressed.
3475 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& event
)
3477 wxPaneInfo
& pane
= *(event
.pane
);
3479 if (event
.button
== wxPaneInfo::buttonClose
)
3484 else if (event
.button
== wxPaneInfo::buttonPin
)
3486 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&