1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: framemanager.cpp
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
8 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/aui/framemanager.h"
29 #include "wx/aui/dockart.h"
30 #include "wx/aui/floatpane.h"
33 // #include "wx/log.h"
36 //#include "wx/dcbuffer.h"
40 WX_CHECK_BUILD_OPTIONS("wxAUI")
42 #include "wx/arrimpl.cpp"
43 WX_DECLARE_OBJARRAY(wxRect
, wxAuiRectArray
);
44 WX_DEFINE_OBJARRAY(wxAuiRectArray
)
45 WX_DEFINE_OBJARRAY(wxDockUIPartArray
)
46 WX_DEFINE_OBJARRAY(wxDockInfoArray
)
47 WX_DEFINE_OBJARRAY(wxPaneButtonArray
)
48 WX_DEFINE_OBJARRAY(wxPaneInfoArray
)
50 wxPaneInfo wxNullPaneInfo
;
51 wxDockInfo wxNullDockInfo
;
52 DEFINE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON
)
55 // a few defines to avoid nameclashes
56 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
58 #include "wx/mac/private.h"
62 // -- static utility functions --
64 static wxBitmap
wxPaneCreateStippleBitmap()
66 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
67 wxImage
img(2,2,data
,true);
71 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
73 wxBitmap stipple
= wxPaneCreateStippleBitmap();
74 wxBrush
brush(stipple
);
76 dc
.SetPen(*wxTRANSPARENT_PEN
);
78 dc
.SetLogicalFunction(wxXOR
);
79 dc
.DrawRectangle(rect
);
84 // on supported windows systems (Win2000 and greater), this function
85 // will make a frame window transparent by a certain amount
86 static void MakeWindowTransparent(wxWindow
* wnd
, int amount
)
88 // this API call is not in all SDKs, only the newer ones, so
89 // we will runtime bind this
90 typedef DWORD (WINAPI
*PSETLAYEREDWINDOWATTR
)(HWND
, DWORD
, BYTE
, DWORD
);
91 static PSETLAYEREDWINDOWATTR pSetLayeredWindowAttributes
= NULL
;
92 static HMODULE h
= NULL
;
93 HWND hwnd
= (HWND
)wnd
->GetHWND();
96 h
= LoadLibrary(_T("user32"));
98 if (!pSetLayeredWindowAttributes
)
100 pSetLayeredWindowAttributes
=
101 (PSETLAYEREDWINDOWATTR
)GetProcAddress(h
,"SetLayeredWindowAttributes");
104 if (pSetLayeredWindowAttributes
== NULL
)
107 LONG exstyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
108 if (0 == (exstyle
& 0x80000) /*WS_EX_LAYERED*/)
109 SetWindowLong(hwnd
, GWL_EXSTYLE
, exstyle
| 0x80000 /*WS_EX_LAYERED*/);
111 pSetLayeredWindowAttributes(hwnd
, 0, amount
, 2 /*LWA_ALPHA*/);
117 // CopyDocksAndPanes() - this utility function creates copies of
118 // the dock and pane info. wxDockInfo's usually contain pointers
119 // to wxPaneInfo classes, thus this function is necessary to reliably
120 // reconstruct that relationship in the new dock info and pane info arrays
122 static void CopyDocksAndPanes(wxDockInfoArray
& dest_docks
,
123 wxPaneInfoArray
& dest_panes
,
124 const wxDockInfoArray
& src_docks
,
125 const wxPaneInfoArray
& src_panes
)
127 dest_docks
= src_docks
;
128 dest_panes
= src_panes
;
129 int i
, j
, k
, dock_count
, pc1
, pc2
;
130 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
132 wxDockInfo
& dock
= dest_docks
.Item(i
);
133 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
134 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
135 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
136 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
140 // GetMaxLayer() is an internal function which returns
141 // the highest layer inside the specified dock
142 static int GetMaxLayer(const wxDockInfoArray
& docks
, int dock_direction
)
144 int i
, dock_count
, max_layer
= 0;
145 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
147 wxDockInfo
& dock
= docks
.Item(i
);
148 if (dock
.dock_direction
== dock_direction
&&
149 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
150 max_layer
= dock
.dock_layer
;
156 // GetMaxRow() is an internal function which returns
157 // the highest layer inside the specified dock
158 static int GetMaxRow(const wxPaneInfoArray
& panes
, int direction
, int layer
)
160 int i
, pane_count
, max_row
= 0;
161 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
163 wxPaneInfo
& pane
= panes
.Item(i
);
164 if (pane
.dock_direction
== direction
&&
165 pane
.dock_layer
== layer
&&
166 pane
.dock_row
> max_row
)
167 max_row
= pane
.dock_row
;
174 // DoInsertDockLayer() is an internal function that inserts a new dock
175 // layer by incrementing all existing dock layer values by one
176 static void DoInsertDockLayer(wxPaneInfoArray
& panes
,
181 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
183 wxPaneInfo
& pane
= panes
.Item(i
);
184 if (!pane
.IsFloating() &&
185 pane
.dock_direction
== dock_direction
&&
186 pane
.dock_layer
>= dock_layer
)
191 // DoInsertDockLayer() is an internal function that inserts a new dock
192 // row by incrementing all existing dock row values by one
193 static void DoInsertDockRow(wxPaneInfoArray
& panes
,
199 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
201 wxPaneInfo
& pane
= panes
.Item(i
);
202 if (!pane
.IsFloating() &&
203 pane
.dock_direction
== dock_direction
&&
204 pane
.dock_layer
== dock_layer
&&
205 pane
.dock_row
>= dock_row
)
210 // DoInsertDockLayer() is an internal function that inserts a space for
211 // another dock pane by incrementing all existing dock row values by one
212 static void DoInsertPane(wxPaneInfoArray
& panes
,
219 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
221 wxPaneInfo
& pane
= panes
.Item(i
);
222 if (!pane
.IsFloating() &&
223 pane
.dock_direction
== dock_direction
&&
224 pane
.dock_layer
== dock_layer
&&
225 pane
.dock_row
== dock_row
&&
226 pane
.dock_pos
>= dock_pos
)
231 // FindDocks() is an internal function that returns a list of docks which meet
232 // the specified conditions in the parameters and returns a sorted array
233 // (sorted by layer and then row)
234 static void FindDocks(wxDockInfoArray
& docks
,
238 wxDockInfoPtrArray
& arr
)
240 int begin_layer
= dock_layer
;
241 int end_layer
= dock_layer
;
242 int begin_row
= dock_row
;
243 int end_row
= dock_row
;
244 int dock_count
= docks
.GetCount();
245 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
247 // discover the maximum dock layer and the max row
248 for (i
= 0; i
< dock_count
; ++i
)
250 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
251 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
254 // if no dock layer was specified, search all dock layers
255 if (dock_layer
== -1)
258 end_layer
= max_layer
;
261 // if no dock row was specified, search all dock row
270 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
271 for (row
= begin_row
; row
<= end_row
; ++row
)
272 for (i
= 0; i
< dock_count
; ++i
)
274 wxDockInfo
& d
= docks
.Item(i
);
275 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
277 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
283 // FindPaneInDock() looks up a specified window pointer inside a dock.
284 // If found, the corresponding wxPaneInfo pointer is returned, otherwise NULL.
285 static wxPaneInfo
* FindPaneInDock(const wxDockInfo
& dock
, wxWindow
* window
)
287 int i
, count
= dock
.panes
.GetCount();
288 for (i
= 0; i
< count
; ++i
)
290 wxPaneInfo
* p
= dock
.panes
.Item(i
);
291 if (p
->window
== window
)
297 // RemovePaneFromDocks() removes a pane window from all docks
298 // with a possible exception specified by parameter "except"
299 static void RemovePaneFromDocks(wxDockInfoArray
& docks
,
301 wxDockInfo
* except
= NULL
)
304 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
306 wxDockInfo
& d
= docks
.Item(i
);
309 wxPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
315 // RenumberDockRows() takes a dock and assigns sequential numbers
316 // to existing rows. Basically it takes out the gaps; so if a
317 // dock has rows with numbers 0,2,5, they will become 0,1,2
318 static void RenumberDockRows(wxDockInfoPtrArray
& docks
)
320 int i
, dock_count
, j
, pane_count
;
321 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
323 wxDockInfo
& dock
= *docks
.Item(i
);
325 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
326 dock
.panes
.Item(j
)->dock_row
= i
;
332 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
335 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
337 wxPaneInfo
& pane
= panes
.Item(i
);
338 pane
.state
&= ~wxPaneInfo::optionActive
;
339 if (pane
.window
== active_pane
)
340 pane
.state
|= wxPaneInfo::optionActive
;
345 // this function is used to sort panes by dock position
346 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
348 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
352 // -- wxFrameManager class implementation --
355 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
356 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
357 EVT_PAINT(wxFrameManager::OnPaint
)
358 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
359 EVT_SIZE(wxFrameManager::OnSize
)
360 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
361 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
362 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
363 EVT_MOTION(wxFrameManager::OnMotion
)
364 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
365 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
366 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
370 wxFrameManager::wxFrameManager(wxFrame
* frame
, unsigned int flags
)
372 m_action
= actionNone
;
373 m_last_mouse_move
= wxPoint();
374 m_hover_button
= NULL
;
375 m_art
= new wxDefaultDockArt
;
385 wxFrameManager::~wxFrameManager()
390 // GetPane() looks up a wxPaneInfo structure based
391 // on the supplied window pointer. Upon failure, GetPane()
392 // returns an empty wxPaneInfo, a condition which can be checked
393 // by calling wxPaneInfo::IsOk().
395 // The pane info's structure may then be modified. Once a pane's
396 // info is modified, wxFrameManager::Update() must be called to
397 // realize the changes in the UI.
399 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
402 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
404 wxPaneInfo
& p
= m_panes
.Item(i
);
405 if (p
.window
== window
)
408 return wxNullPaneInfo
;
411 // this version of GetPane() looks up a pane based on a
412 // 'pane name', see above comment for more info
413 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
416 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
418 wxPaneInfo
& p
= m_panes
.Item(i
);
422 return wxNullPaneInfo
;
425 // GetAllPanes() returns a reference to all the pane info structures
426 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
431 // HitTest() is an internal function which determines
432 // which UI item the specified coordinates are over
433 // (x,y) specify a position in client coordinates
434 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
436 wxDockUIPart
* result
= NULL
;
439 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
441 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
443 // we are not interested in typeDock, because this space
444 // isn't used to draw anything, just for measurements;
445 // besides, the entire dock area is covered with other
446 // rectangles, which we are interested in.
447 if (item
->type
== wxDockUIPart::typeDock
)
450 // if we already have a hit on a more specific item, we are not
451 // interested in a pane hit. If, however, we don't already have
452 // a hit, returning a pane hit is necessary for some operations
453 if ((item
->type
== wxDockUIPart::typePane
||
454 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
457 // if the point is inside the rectangle, we have a hit
458 if (item
->rect
.Inside(x
,y
))
466 // SetFlags() and GetFlags() allow the owner to set various
467 // options which are global to wxFrameManager
468 void wxFrameManager::SetFlags(unsigned int flags
)
473 unsigned int wxFrameManager::GetFlags() const
479 // SetFrame() is usually called once when the frame
480 // manager class is being initialized. "frame" specifies
481 // the frame which should be managed by the frame mananger
482 void wxFrameManager::SetFrame(wxFrame
* frame
)
484 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
487 m_frame
->PushEventHandler(this);
490 // if the owner is going to manage an MDI parent frame,
491 // we need to add the MDI client window as the default
494 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
496 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
497 wxMDIClientWindow
* client_window
= mdi_frame
->GetClientWindow();
499 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
501 AddPane(client_window
,
502 wxPaneInfo().Name(wxT("mdiclient")).
503 CenterPane().PaneBorder(false));
509 // UnInit() must be called, usually in the destructor
510 // of the frame class. If it is not called, usually this
511 // will result in a crash upon program exit
512 void wxFrameManager::UnInit()
514 m_frame
->RemoveEventHandler(this);
517 // GetFrame() returns the frame pointer being managed by wxFrameManager
518 wxFrame
* wxFrameManager::GetFrame() const
523 wxDockArt
* wxFrameManager::GetArtProvider() const
528 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
530 // first, give the owner frame a chance to override
533 if (m_frame
->ProcessEvent(event
))
540 // SetArtProvider() instructs wxFrameManager to use the
541 // specified art provider for all drawing calls. This allows
542 // plugable look-and-feel features
543 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
545 // delete the last art provider, if any
548 // assign the new art provider
549 m_art
= art_provider
;
552 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
554 // check if the pane has a valid window
558 // check if the pane already exists
559 if (GetPane(pane_info
.window
).IsOk())
562 m_panes
.Add(pane_info
);
564 wxPaneInfo
& pinfo
= m_panes
.Last();
566 // set the pane window
567 pinfo
.window
= window
;
569 // if the pane's name identifier is blank, create a random string
570 if (pinfo
.name
.IsEmpty())
572 pinfo
.name
.Printf(wxT("%08x%08x%08x%08x"),
573 ((unsigned long)pinfo
.window
) & 0xffffffff,
574 (unsigned int)time(NULL
),
575 (unsigned int)clock(), m_panes
.GetCount());
578 // set initial proportion (if not already set)
579 if (pinfo
.dock_proportion
== 0)
580 pinfo
.dock_proportion
= 100000;
582 if (pinfo
.HasCloseButton() &&
583 pinfo
.buttons
.size() == 0)
586 button
.button_id
= wxPaneInfo::buttonClose
;
587 pinfo
.buttons
.Add(button
);
590 if (pinfo
.best_size
== wxDefaultSize
&&
593 pinfo
.best_size
= pinfo
.window
->GetClientSize();
595 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
597 // GetClientSize() doesn't get the best size for
598 // a toolbar under some newer versions of wxWidgets,
599 // so use GetBestSize()
600 pinfo
.best_size
= pinfo
.window
->GetBestSize();
602 // for some reason, wxToolBar::GetBestSize() is returning
603 // a size that is a pixel shy of the correct amount.
604 // I believe this to be the correct action, until
605 // wxToolBar::GetBestSize() is fixed. Is this assumption
610 if (pinfo
.min_size
!= wxDefaultSize
)
612 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
613 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
614 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
615 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
622 bool wxFrameManager::AddPane(wxWindow
* window
,
624 const wxString
& caption
)
627 pinfo
.Caption(caption
);
630 case wxTOP
: pinfo
.Top(); break;
631 case wxBOTTOM
: pinfo
.Bottom(); break;
632 case wxLEFT
: pinfo
.Left(); break;
633 case wxRIGHT
: pinfo
.Right(); break;
634 case wxCENTER
: pinfo
.CenterPane(); break;
636 return AddPane(window
, pinfo
);
639 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
642 // shift the panes around, depending on the insert level
643 switch (insert_level
)
645 case wxAUI_INSERT_PANE
:
646 DoInsertPane(m_panes
,
647 pane_info
.dock_direction
,
648 pane_info
.dock_layer
,
652 case wxAUI_INSERT_ROW
:
653 DoInsertDockRow(m_panes
,
654 pane_info
.dock_direction
,
655 pane_info
.dock_layer
,
658 case wxAUI_INSERT_DOCK
:
659 DoInsertDockLayer(m_panes
,
660 pane_info
.dock_direction
,
661 pane_info
.dock_layer
);
665 // if the window already exists, we are basically just moving/inserting the
666 // existing window. If it doesn't exist, we need to add it and insert it
667 wxPaneInfo
& existing_pane
= GetPane(window
);
668 if (!existing_pane
.IsOk())
670 return AddPane(window
, pane_info
);
674 if (pane_info
.IsFloating())
676 existing_pane
.Float();
677 if (pane_info
.floating_pos
!= wxDefaultPosition
)
678 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
679 if (pane_info
.floating_size
!= wxDefaultSize
)
680 existing_pane
.FloatingSize(pane_info
.floating_size
);
684 existing_pane
.Direction(pane_info
.dock_direction
);
685 existing_pane
.Layer(pane_info
.dock_layer
);
686 existing_pane
.Row(pane_info
.dock_row
);
687 existing_pane
.Position(pane_info
.dock_pos
);
695 bool wxFrameManager::DetachPane(wxWindow
* window
)
698 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
700 wxPaneInfo
& p
= m_panes
.Item(i
);
701 if (p
.window
== window
)
705 // we have a floating frame which is being detached. We need to
706 // reparent it to m_frame and destroy the floating frame
709 p
.window
->SetSize(1,1);
710 p
.frame
->Show(false);
712 // reparent to m_frame and destroy the pane
713 p
.window
->Reparent(m_frame
);
714 p
.frame
->SetSizer(NULL
);
726 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
727 // in the input string. This is an internal functions which is
728 // used for saving perspectives
729 static wxString
EscapeDelimiters(const wxString
& s
)
732 result
.Alloc(s
.Length());
733 const wxChar
* ch
= s
.c_str();
736 if (*ch
== wxT(';') || *ch
== wxT('|'))
745 // SavePerspective() saves all pane information as a single string.
746 // This string may later be fed into LoadPerspective() to restore
747 // all pane settings. This save and load mechanism allows an
748 // exact pane configuration to be saved and restored at a later time
750 wxString
wxFrameManager::SavePerspective()
754 result
= wxT("layout1|");
756 int pane_i
, pane_count
= m_panes
.GetCount();
757 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
759 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
761 result
+= wxT("name=");
762 result
+= EscapeDelimiters(pane
.name
);
765 result
+= wxT("caption=");
766 result
+= EscapeDelimiters(pane
.caption
);
769 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
770 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
771 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
772 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
773 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
774 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
775 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
776 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
777 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
778 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
779 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
780 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
781 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
782 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
783 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
784 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
788 int dock_i
, dock_count
= m_docks
.GetCount();
789 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
791 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
793 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
794 dock
.dock_direction
, dock
.dock_layer
,
795 dock
.dock_row
, dock
.size
);
801 // LoadPerspective() loads a layout which was saved with SavePerspective()
802 // If the "update" flag parameter is true, the GUI will immediately be updated
804 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
806 wxString input
= layout
;
809 // check layout string version
810 part
= input
.BeforeFirst(wxT('|'));
811 input
= input
.AfterFirst(wxT('|'));
814 if (part
!= wxT("layout1"))
818 // mark all panes currently managed as docked and hidden
819 int pane_i
, pane_count
= m_panes
.GetCount();
820 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
821 m_panes
.Item(pane_i
).Dock().Hide();
823 // clear out the dock array; this will be reconstructed
826 // replace escaped characters so we can
827 // split up the string easily
828 input
.Replace(wxT("\\|"), wxT("\a"));
829 input
.Replace(wxT("\\;"), wxT("\b"));
835 wxString pane_part
= input
.BeforeFirst(wxT('|'));
836 input
= input
.AfterFirst(wxT('|'));
837 pane_part
.Trim(true);
839 // if the string is empty, we're done parsing
840 if (pane_part
.IsEmpty())
844 if (pane_part
.Left(9) == wxT("dock_size"))
846 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
847 wxString value
= pane_part
.AfterFirst(wxT('='));
849 long dir
, layer
, row
, size
;
850 wxString piece
= val_name
.AfterFirst(wxT('('));
851 piece
= piece
.BeforeLast(wxT(')'));
852 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
853 piece
= piece
.AfterFirst(wxT(','));
854 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
855 piece
.AfterFirst(wxT(',')).ToLong(&row
);
859 dock
.dock_direction
= dir
;
860 dock
.dock_layer
= layer
;
869 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
870 pane_part
= pane_part
.AfterFirst(wxT(';'));
871 wxString val_name
= val_part
.BeforeFirst(wxT('='));
872 wxString value
= val_part
.AfterFirst(wxT('='));
873 val_name
.MakeLower();
875 val_name
.Trim(false);
879 if (val_name
.IsEmpty())
882 if (val_name
== wxT("name"))
884 else if (val_name
== wxT("caption"))
885 pane
.caption
= value
;
886 else if (val_name
== wxT("state"))
887 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
888 else if (val_name
== wxT("dir"))
889 pane
.dock_direction
= wxAtoi(value
.c_str());
890 else if (val_name
== wxT("layer"))
891 pane
.dock_layer
= wxAtoi(value
.c_str());
892 else if (val_name
== wxT("row"))
893 pane
.dock_row
= wxAtoi(value
.c_str());
894 else if (val_name
== wxT("pos"))
895 pane
.dock_pos
= wxAtoi(value
.c_str());
896 else if (val_name
== wxT("prop"))
897 pane
.dock_proportion
= wxAtoi(value
.c_str());
898 else if (val_name
== wxT("bestw"))
899 pane
.best_size
.x
= wxAtoi(value
.c_str());
900 else if (val_name
== wxT("besth"))
901 pane
.best_size
.y
= wxAtoi(value
.c_str());
902 else if (val_name
== wxT("minw"))
903 pane
.min_size
.x
= wxAtoi(value
.c_str());
904 else if (val_name
== wxT("minh"))
905 pane
.min_size
.y
= wxAtoi(value
.c_str());
906 else if (val_name
== wxT("maxw"))
907 pane
.max_size
.x
= wxAtoi(value
.c_str());
908 else if (val_name
== wxT("maxh"))
909 pane
.max_size
.y
= wxAtoi(value
.c_str());
910 else if (val_name
== wxT("floatx"))
911 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
912 else if (val_name
== wxT("floaty"))
913 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
914 else if (val_name
== wxT("floatw"))
915 pane
.floating_size
.x
= wxAtoi(value
.c_str());
916 else if (val_name
== wxT("floath"))
917 pane
.floating_size
.y
= wxAtoi(value
.c_str());
919 wxFAIL_MSG(wxT("Bad Perspective String"));
923 // replace escaped characters so we can
924 // split up the string easily
925 pane
.name
.Replace(wxT("\a"), wxT("|"));
926 pane
.name
.Replace(wxT("\b"), wxT(";"));
927 pane
.caption
.Replace(wxT("\a"), wxT("|"));
928 pane
.caption
.Replace(wxT("\b"), wxT(";"));
930 wxPaneInfo
& p
= GetPane(pane
.name
);
933 // the pane window couldn't be found
934 // in the existing layout
938 pane
.window
= p
.window
;
939 pane
.frame
= p
.frame
;
940 pane
.buttons
= p
.buttons
;
951 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
952 wxArrayInt
& positions
,
955 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
956 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
957 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
962 int offset
, action_pane
= -1;
963 int pane_i
, pane_count
= dock
.panes
.GetCount();
965 // find the pane marked as our action pane
966 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
968 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
970 if (pane
.state
& wxPaneInfo::actionPane
)
972 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
973 action_pane
= pane_i
;
977 // set up each panes default position, and
978 // determine the size (width or height, depending
979 // on the dock's orientation) of each pane
980 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
982 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
983 positions
.Add(pane
.dock_pos
);
986 if (pane
.HasBorder())
987 size
+= (pane_border_size
*2);
989 if (dock
.IsHorizontal())
991 if (pane
.HasGripper() && !pane
.HasGripperTop())
992 size
+= gripper_size
;
993 size
+= pane
.best_size
.x
;
997 if (pane
.HasGripper() && pane
.HasGripperTop())
998 size
+= gripper_size
;
1000 if (pane
.HasCaption())
1001 size
+= caption_size
;
1002 size
+= pane
.best_size
.y
;
1008 // if there is no action pane, just return the default
1009 // positions (as specified in pane.pane_pos)
1010 if (action_pane
== -1)
1014 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1016 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1021 positions
[pane_i
] -= -amount
;
1023 offset
+= sizes
[pane_i
];
1026 // if the dock mode is fixed, make sure none of the panes
1027 // overlap; we will bump panes that overlap
1029 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1031 int amount
= positions
[pane_i
] - offset
;
1035 positions
[pane_i
] += -amount
;
1037 offset
+= sizes
[pane_i
];
1042 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1045 wxDockUIPartArray
& uiparts
,
1049 wxSizerItem
* sizer_item
;
1051 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1052 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1053 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1054 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1056 // find out the orientation of the item (orientation for panes
1057 // is the same as the dock's orientation)
1059 if (dock
.IsHorizontal())
1060 orientation
= wxHORIZONTAL
;
1062 orientation
= wxVERTICAL
;
1064 // this variable will store the proportion
1065 // value that the pane will receive
1066 int pane_proportion
= pane
.dock_proportion
;
1068 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1069 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1071 if (pane
.HasGripper())
1073 if (pane
.HasGripperTop())
1074 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1076 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1078 part
.type
= wxDockUIPart::typeGripper
;
1082 part
.orientation
= orientation
;
1083 part
.cont_sizer
= horz_pane_sizer
;
1084 part
.sizer_item
= sizer_item
;
1088 if (pane
.HasCaption())
1090 // create the caption sizer
1091 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1093 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1095 part
.type
= wxDockUIPart::typeCaption
;
1099 part
.orientation
= orientation
;
1100 part
.cont_sizer
= vert_pane_sizer
;
1101 part
.sizer_item
= sizer_item
;
1102 int caption_part_idx
= uiparts
.GetCount();
1105 // add pane buttons to the caption
1106 int i
, button_count
;
1107 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1108 i
< button_count
; ++i
)
1110 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1112 sizer_item
= caption_sizer
->Add(pane_button_size
,
1116 part
.type
= wxDockUIPart::typePaneButton
;
1119 part
.button
= &button
;
1120 part
.orientation
= orientation
;
1121 part
.cont_sizer
= caption_sizer
;
1122 part
.sizer_item
= sizer_item
;
1126 // add the caption sizer
1127 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1129 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1132 // add the pane window itself
1135 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1139 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1140 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1143 part
.type
= wxDockUIPart::typePane
;
1147 part
.orientation
= orientation
;
1148 part
.cont_sizer
= vert_pane_sizer
;
1149 part
.sizer_item
= sizer_item
;
1153 // determine if the pane should have a minimum size; if the pane is
1154 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1155 // if the pane.min_size is set, we must use that value as well
1157 wxSize min_size
= pane
.min_size
;
1160 if (min_size
== wxDefaultSize
)
1162 min_size
= pane
.best_size
;
1163 pane_proportion
= 0;
1167 if (min_size
!= wxDefaultSize
)
1169 vert_pane_sizer
->SetItemMinSize(
1170 vert_pane_sizer
->GetChildren().GetCount()-1,
1171 min_size
.x
, min_size
.y
);
1175 // add the verticle sizer (caption, pane window) to the
1176 // horizontal sizer (gripper, verticle sizer)
1177 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1179 // finally, add the pane sizer to the dock sizer
1181 if (pane
.HasBorder())
1183 // allowing space for the pane's border
1184 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1185 wxEXPAND
| wxALL
, pane_border_size
);
1187 part
.type
= wxDockUIPart::typePaneBorder
;
1191 part
.orientation
= orientation
;
1192 part
.cont_sizer
= cont
;
1193 part
.sizer_item
= sizer_item
;
1198 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1202 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1204 wxDockUIPartArray
& uiparts
,
1207 wxSizerItem
* sizer_item
;
1210 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1211 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1213 // resizable bottom and right docks have a sash before them
1214 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1215 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1217 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1219 part
.type
= wxDockUIPart::typeDockSizer
;
1220 part
.orientation
= orientation
;
1224 part
.cont_sizer
= cont
;
1225 part
.sizer_item
= sizer_item
;
1229 // create the sizer for the dock
1230 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1232 // add each pane to the dock
1233 int pane_i
, pane_count
= dock
.panes
.GetCount();
1237 wxArrayInt pane_positions
, pane_sizes
;
1239 // figure out the real pane positions we will
1240 // use, without modifying the each pane's pane_pos member
1241 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1244 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1246 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1247 int pane_pos
= pane_positions
.Item(pane_i
);
1249 int amount
= pane_pos
- offset
;
1252 if (dock
.IsVertical())
1253 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1255 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1257 part
.type
= wxDockUIPart::typeBackground
;
1261 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1262 part
.cont_sizer
= dock_sizer
;
1263 part
.sizer_item
= sizer_item
;
1269 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1271 offset
+= pane_sizes
.Item(pane_i
);
1274 // at the end add a very small stretchable background area
1275 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1277 part
.type
= wxDockUIPart::typeBackground
;
1281 part
.orientation
= orientation
;
1282 part
.cont_sizer
= dock_sizer
;
1283 part
.sizer_item
= sizer_item
;
1288 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1290 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1292 // if this is not the first pane being added,
1293 // we need to add a pane sizer
1296 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1298 part
.type
= wxDockUIPart::typePaneSizer
;
1300 part
.pane
= dock
.panes
.Item(pane_i
-1);
1302 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1303 part
.cont_sizer
= dock_sizer
;
1304 part
.sizer_item
= sizer_item
;
1308 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1312 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1313 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1315 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1317 part
.type
= wxDockUIPart::typeDock
;
1321 part
.orientation
= orientation
;
1322 part
.cont_sizer
= cont
;
1323 part
.sizer_item
= sizer_item
;
1326 if (dock
.IsHorizontal())
1327 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1329 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1331 // top and left docks have a sash after them
1332 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1333 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1335 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1337 part
.type
= wxDockUIPart::typeDockSizer
;
1341 part
.orientation
= orientation
;
1342 part
.cont_sizer
= cont
;
1343 part
.sizer_item
= sizer_item
;
1348 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1349 wxDockInfoArray
& docks
,
1350 wxDockUIPartArray
& uiparts
,
1353 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1355 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1356 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1357 wxSize cli_size
= m_frame
->GetClientSize();
1358 int i
, dock_count
, pane_count
;
1361 // empty all docks out
1362 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1363 docks
.Item(i
).panes
.Empty();
1365 // iterate through all known panes, filing each
1366 // of them into the appropriate dock. If the
1367 // pane does not exist in the dock, add it
1368 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1370 wxPaneInfo
& p
= panes
.Item(i
);
1372 // find any docks in this layer
1374 wxDockInfoPtrArray arr
;
1375 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1377 if (arr
.GetCount() > 0)
1383 // dock was not found, so we need to create a new one
1385 d
.dock_direction
= p
.dock_direction
;
1386 d
.dock_layer
= p
.dock_layer
;
1387 d
.dock_row
= p
.dock_row
;
1389 dock
= &docks
.Last();
1393 if (p
.IsDocked() && p
.IsShown())
1395 // remove the pane from any existing docks except this one
1396 RemovePaneFromDocks(docks
, p
, dock
);
1398 // pane needs to be added to the dock,
1399 // if it doesn't already exist
1400 if (!FindPaneInDock(*dock
, p
.window
))
1401 dock
->panes
.Add(&p
);
1405 // remove the pane from any existing docks
1406 RemovePaneFromDocks(docks
, p
);
1411 // remove any empty docks
1412 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1414 if (docks
.Item(i
).panes
.GetCount() == 0)
1418 // configure the docks further
1419 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1421 wxDockInfo
& dock
= docks
.Item(i
);
1422 int j
, dock_pane_count
= dock
.panes
.GetCount();
1424 // sort the dock pane array by the pane's
1425 // dock position (dock_pos), in ascending order
1426 dock
.panes
.Sort(PaneSortFunc
);
1428 // for newly created docks, set up their initial size
1433 for (j
= 0; j
< dock_pane_count
; ++j
)
1435 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1436 wxSize pane_size
= pane
.best_size
;
1437 if (pane_size
== wxDefaultSize
)
1438 pane_size
= pane
.min_size
;
1439 if (pane_size
== wxDefaultSize
)
1440 pane_size
= pane
.window
->GetSize();
1442 if (dock
.IsHorizontal())
1443 size
= wxMax(pane_size
.y
, size
);
1445 size
= wxMax(pane_size
.x
, size
);
1448 // add space for the border (two times), but only
1449 // if at least one pane inside the dock has a pane border
1450 for (j
= 0; j
< dock_pane_count
; ++j
)
1452 if (dock
.panes
.Item(j
)->HasBorder())
1454 size
+= (pane_border_size
*2);
1459 // if pane is on the top or bottom, add the caption height,
1460 // but only if at least one pane inside the dock has a caption
1461 if (dock
.IsHorizontal())
1463 for (j
= 0; j
< dock_pane_count
; ++j
)
1465 if (dock
.panes
.Item(j
)->HasCaption())
1467 size
+= caption_size
;
1473 // new dock's size may not be more than 1/3 of the frame size
1474 if (dock
.IsHorizontal())
1475 size
= wxMin(size
, cli_size
.y
/3);
1477 size
= wxMin(size
, cli_size
.x
/3);
1485 // determine the dock's minimum size
1486 bool plus_border
= false;
1487 bool plus_caption
= false;
1488 int dock_min_size
= 0;
1489 for (j
= 0; j
< dock_pane_count
; ++j
)
1491 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1492 if (pane
.min_size
!= wxDefaultSize
)
1494 if (pane
.HasBorder())
1496 if (pane
.HasCaption())
1497 plus_caption
= true;
1498 if (dock
.IsHorizontal())
1500 if (pane
.min_size
.y
> dock_min_size
)
1501 dock_min_size
= pane
.min_size
.y
;
1505 if (pane
.min_size
.x
> dock_min_size
)
1506 dock_min_size
= pane
.min_size
.x
;
1512 dock_min_size
+= (pane_border_size
*2);
1513 if (plus_caption
&& dock
.IsHorizontal())
1514 dock_min_size
+= (caption_size
);
1516 dock
.min_size
= dock_min_size
;
1519 // if the pane's current size is less than it's
1520 // minimum, increase the dock's size to it's minimum
1521 if (dock
.size
< dock
.min_size
)
1522 dock
.size
= dock
.min_size
;
1525 // determine the dock's mode (fixed or proportional);
1526 // determine whether the dock has only toolbars
1527 bool action_pane_marked
= false;
1529 dock
.toolbar
= true;
1530 for (j
= 0; j
< dock_pane_count
; ++j
)
1532 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1533 if (!pane
.IsFixed())
1535 if (!pane
.IsToolbar())
1536 dock
.toolbar
= false;
1537 if (pane
.state
& wxPaneInfo::actionPane
)
1538 action_pane_marked
= true;
1542 // if the dock mode is proportional and not fixed-pixel,
1543 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1544 // e.g. remove gaps like 1, 2, 30, 500
1547 for (j
= 0; j
< dock_pane_count
; ++j
)
1549 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1554 // if the dock mode is fixed, and none of the panes
1555 // are being moved right now, make sure the panes
1556 // do not overlap each other. If they do, we will
1557 // adjust the panes' positions
1558 if (dock
.fixed
&& !action_pane_marked
)
1560 wxArrayInt pane_positions
, pane_sizes
;
1561 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1564 for (j
= 0; j
< dock_pane_count
; ++j
)
1566 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1567 pane
.dock_pos
= pane_positions
[j
];
1569 int amount
= pane
.dock_pos
- offset
;
1573 pane
.dock_pos
+= -amount
;
1575 offset
+= pane_sizes
[j
];
1580 // discover the maximum dock layer
1582 for (i
= 0; i
< dock_count
; ++i
)
1583 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1586 // clear out uiparts
1589 // create a bunch of box sizers,
1590 // from the innermost level outwards.
1591 wxSizer
* cont
= NULL
;
1592 wxSizer
* middle
= NULL
;
1596 for (layer
= 0; layer
<= max_layer
; ++layer
)
1598 wxDockInfoPtrArray arr
;
1600 // find any docks in this layer
1601 FindDocks(docks
, -1, layer
, -1, arr
);
1603 // if there aren't any, skip to the next layer
1607 wxSizer
* old_cont
= cont
;
1609 // create a container which will hold this layer's
1610 // docks (top, bottom, left, right)
1611 cont
= new wxBoxSizer(wxVERTICAL
);
1614 // find any top docks in this layer
1615 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1616 RenumberDockRows(arr
);
1619 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1620 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1624 // fill out the middle layer (which consists
1625 // of left docks, content area and right docks)
1627 middle
= new wxBoxSizer(wxHORIZONTAL
);
1629 // find any left docks in this layer
1630 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1631 RenumberDockRows(arr
);
1634 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1635 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1638 // add content dock (or previous layer's sizer
1642 // find any center docks
1643 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1646 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1647 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1651 // there are no center docks, add a background area
1652 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1654 part
.type
= wxDockUIPart::typeBackground
;
1658 part
.cont_sizer
= middle
;
1659 part
.sizer_item
= sizer_item
;
1665 middle
->Add(old_cont
, 1, wxEXPAND
);
1668 // find any right docks in this layer
1669 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1670 RenumberDockRows(arr
);
1673 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1674 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1677 cont
->Add(middle
, 1, wxEXPAND
);
1681 // find any bottom docks in this layer
1682 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1683 RenumberDockRows(arr
);
1686 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1687 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1694 // no sizer available, because there are no docks,
1695 // therefore we will create a simple background area
1696 cont
= new wxBoxSizer(wxVERTICAL
);
1697 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1699 part
.type
= wxDockUIPart::typeBackground
;
1703 part
.cont_sizer
= middle
;
1704 part
.sizer_item
= sizer_item
;
1708 container
->Add(cont
, 1, wxEXPAND
);
1713 // Update() updates the layout. Whenever changes are made to
1714 // one or more panes, this function should be called. It is the
1715 // external entry point for running the layout engine.
1717 void wxFrameManager::Update()
1720 int i
, pane_count
= m_panes
.GetCount();
1722 // delete old sizer first
1723 m_frame
->SetSizer(NULL
);
1725 // destroy floating panes which have been
1726 // redocked or are becoming non-floating
1727 for (i
= 0; i
< pane_count
; ++i
)
1729 wxPaneInfo
& p
= m_panes
.Item(i
);
1731 if (!p
.IsFloating() && p
.frame
)
1733 // because the pane is no longer in a floating, we need to
1734 // reparent it to m_frame and destroy the floating frame
1737 p
.window
->SetSize(1,1);
1738 p
.frame
->Show(false);
1740 // reparent to m_frame and destroy the pane
1741 p
.window
->Reparent(m_frame
);
1742 p
.frame
->SetSizer(NULL
);
1749 // create a layout for all of the panes
1750 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
1752 // hide or show panes as necessary,
1753 // and float panes as necessary
1754 for (i
= 0; i
< pane_count
; ++i
)
1756 wxPaneInfo
& p
= m_panes
.Item(i
);
1760 if (p
.frame
== NULL
)
1762 // we need to create a frame for this
1763 // pane, which has recently been floated
1764 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
1769 // on MSW, if the owner desires transparent dragging, and
1770 // the dragging is happening right now, then the floating
1771 // window should have this style by default
1773 if (m_action
== actionDragFloatingPane
&&
1774 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
1775 MakeWindowTransparent(frame
, 150);
1778 frame
->SetPaneWindow(p
);
1788 // frame already exists, make sure it's position
1789 // and size reflect the information in wxPaneInfo
1790 if (p
.frame
->GetPosition() != p
.floating_pos
)
1792 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
1793 -1, -1, wxSIZE_USE_EXISTING
);
1794 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
1797 p
.frame
->Show(p
.IsShown());
1802 p
.window
->Show(p
.IsShown());
1805 // if "active panes" are no longer allowed, clear
1806 // any optionActive values from the pane states
1807 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
1809 p
.state
&= ~wxPaneInfo::optionActive
;
1814 // keep track of the old window rectangles so we can
1815 // refresh those windows whose rect has changed
1816 wxAuiRectArray old_pane_rects
;
1817 for (i
= 0; i
< pane_count
; ++i
)
1820 wxPaneInfo
& p
= m_panes
.Item(i
);
1822 if (p
.window
&& p
.IsShown() && p
.IsDocked())
1825 old_pane_rects
.Add(r
);
1831 // apply the new sizer
1832 m_frame
->SetSizer(sizer
);
1833 m_frame
->SetAutoLayout(false);
1838 // now that the frame layout is done, we need to check
1839 // the new pane rectangles against the old rectangles that
1840 // we saved a few lines above here. If the rectangles have
1841 // changed, the corresponding panes must also be updated
1842 for (i
= 0; i
< pane_count
; ++i
)
1844 wxPaneInfo
& p
= m_panes
.Item(i
);
1845 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
1847 if (p
.rect
!= old_pane_rects
[i
])
1849 p
.window
->Refresh();
1858 // set frame's minimum size
1861 // N.B. More work needs to be done on frame minimum sizes;
1862 // this is some intresting code that imposes the minimum size,
1863 // but we may want to include a more flexible mechanism or
1864 // options for multiple minimum-size modes, e.g. strict or lax
1865 wxSize min_size = sizer->GetMinSize();
1866 wxSize frame_size = m_frame->GetSize();
1867 wxSize client_size = m_frame->GetClientSize();
1869 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
1870 min_size.y+frame_size.y-client_size.y );
1872 m_frame->SetMinSize(minframe_size);
1874 if (frame_size.x < minframe_size.x ||
1875 frame_size.y < minframe_size.y)
1876 sizer->Fit(m_frame);
1881 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
1882 // on the frame's main sizer, then measures all the various UI items
1883 // and updates their internal rectangles. This should always be called
1884 // instead of calling m_frame->Layout() directly
1886 void wxFrameManager::DoFrameLayout()
1891 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1893 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1895 // get the rectangle of the UI part
1896 // originally, this code looked like this:
1897 // part.rect = wxRect(part.sizer_item->GetPosition(),
1898 // part.sizer_item->GetSize());
1899 // this worked quite well, with one exception: the mdi
1900 // client window had a "deferred" size variable
1901 // that returned the wrong size. It looks like
1902 // a bug in wx, because the former size of the window
1903 // was being returned. So, we will retrieve the part's
1904 // rectangle via other means
1907 part
.rect
= part
.sizer_item
->GetRect();
1908 int flag
= part
.sizer_item
->GetFlag();
1909 int border
= part
.sizer_item
->GetBorder();
1912 part
.rect
.y
-= border
;
1913 part
.rect
.height
+= border
;
1917 part
.rect
.x
-= border
;
1918 part
.rect
.width
+= border
;
1920 if (flag
& wxBOTTOM
)
1921 part
.rect
.height
+= border
;
1923 part
.rect
.width
+= border
;
1926 if (part
.type
== wxDockUIPart::typeDock
)
1927 part
.dock
->rect
= part
.rect
;
1928 if (part
.type
== wxDockUIPart::typePane
)
1929 part
.pane
->rect
= part
.rect
;
1933 // GetPanePart() looks up the pane the pane border UI part (or the regular
1934 // pane part if there is no border). This allows the caller to get the exact
1935 // rectangle of the pane in question, including decorations like
1936 // caption and border (if any).
1938 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
1941 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1943 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1944 if (part
.type
== wxDockUIPart::typePaneBorder
&&
1945 part
.pane
&& part
.pane
->window
== wnd
)
1948 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1950 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1951 if (part
.type
== wxDockUIPart::typePane
&&
1952 part
.pane
&& part
.pane
->window
== wnd
)
1960 // GetDockPixelOffset() is an internal function which returns
1961 // a dock's offset in pixels from the left side of the window
1962 // (for horizontal docks) or from the top of the window (for
1963 // vertical docks). This value is necessary for calculating
1964 // fixel-pane/toolbar offsets when they are dragged.
1966 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
1968 // the only way to accurately calculate the dock's
1969 // offset is to actually run a theoretical layout
1971 int i
, part_count
, dock_count
;
1972 wxDockInfoArray docks
;
1973 wxPaneInfoArray panes
;
1974 wxDockUIPartArray uiparts
;
1975 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
1978 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
1979 wxSize client_size
= m_frame
->GetClientSize();
1980 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
1983 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
1985 wxDockUIPart
& part
= uiparts
.Item(i
);
1986 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
1987 part
.sizer_item
->GetSize());
1988 if (part
.type
== wxDockUIPart::typeDock
)
1989 part
.dock
->rect
= part
.rect
;
1994 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1996 wxDockInfo
& dock
= docks
.Item(i
);
1997 if (test
.dock_direction
== dock
.dock_direction
&&
1998 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2000 if (dock
.IsVertical())
2012 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2013 // if a dock operation is allowed, the new dock position is copied into
2014 // the target info. If the operation was allowed, the function returns true.
2016 static bool ProcessDockResult(wxPaneInfo
& target
,
2017 const wxPaneInfo
& new_pos
)
2019 bool allowed
= false;
2020 switch (new_pos
.dock_direction
)
2022 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2023 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2024 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2025 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2035 // DoDrop() is an important function. It basically takes a mouse position,
2036 // and determines where the pane's new position would be. If the pane is to be
2037 // dropped, it performs the drop operation using the specified dock and pane
2038 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2039 // scenario can be performed, giving precise coordinates for drop hints.
2040 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2041 // as parameters, the changes will be made to the main state arrays
2043 const int auiInsertRowPixels
= 10;
2044 const int auiNewRowPixels
= 40;
2045 const int auiLayerInsertPixels
= 40;
2046 const int auiLayerInsertOffset
= 5;
2048 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2049 wxPaneInfoArray
& panes
,
2052 const wxPoint
& offset
)
2054 wxSize cli_size
= m_frame
->GetClientSize();
2056 wxPaneInfo drop
= target
;
2059 // The result should always be shown
2063 // Check to see if the pane has been dragged outside of the window
2064 // (or near to the outside of the window), if so, dock it along the edge
2067 int layer_insert_offset
= auiLayerInsertOffset
;
2068 if (target
.IsToolbar())
2069 layer_insert_offset
= 0;
2071 if (pt
.x
< layer_insert_offset
&&
2072 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2074 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2075 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2076 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2080 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2081 return ProcessDockResult(target
, drop
);
2083 else if (pt
.y
< layer_insert_offset
&&
2084 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2086 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2087 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2088 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2092 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2093 return ProcessDockResult(target
, drop
);
2095 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2096 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2098 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2099 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2100 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2101 drop
.Dock().Right().
2104 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2105 return ProcessDockResult(target
, drop
);
2107 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2108 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2110 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2111 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2112 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2113 drop
.Dock().Bottom().
2116 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2117 return ProcessDockResult(target
, drop
);
2121 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2124 if (drop
.IsToolbar())
2126 if (!part
|| !part
->dock
)
2130 // calculate the offset from where the dock begins
2131 // to the point where the user dropped the pane
2132 int dock_drop_offset
= 0;
2133 if (part
->dock
->IsHorizontal())
2134 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2136 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2139 // toolbars may only be moved in and to fixed-pane docks,
2140 // otherwise we will try to float the pane. Also, the pane
2141 // should float if being dragged over center pane windows
2142 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2144 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2145 (drop
.IsFloatable() ||
2146 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2147 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2152 return ProcessDockResult(target
, drop
);
2156 Direction(part
->dock
->dock_direction
).
2157 Layer(part
->dock
->dock_layer
).
2158 Row(part
->dock
->dock_row
).
2159 Position(dock_drop_offset
);
2162 ((pt
.y
< part
->dock
->rect
.y
+ 2) && part
->dock
->IsHorizontal()) ||
2163 ((pt
.x
< part
->dock
->rect
.x
+ 2) && part
->dock
->IsVertical())
2164 ) && part
->dock
->panes
.GetCount() > 1)
2166 int row
= drop
.dock_row
;
2167 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2168 part
->dock
->dock_layer
,
2169 part
->dock
->dock_row
);
2170 drop
.dock_row
= row
;
2174 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2175 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2176 ) && part
->dock
->panes
.GetCount() > 1)
2178 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2179 part
->dock
->dock_layer
,
2180 part
->dock
->dock_row
+1);
2181 drop
.dock_row
= part
->dock
->dock_row
+1;
2184 return ProcessDockResult(target
, drop
);
2193 if (part
->type
== wxDockUIPart::typePaneBorder
||
2194 part
->type
== wxDockUIPart::typeCaption
||
2195 part
->type
== wxDockUIPart::typeGripper
||
2196 part
->type
== wxDockUIPart::typePaneButton
||
2197 part
->type
== wxDockUIPart::typePane
||
2198 part
->type
== wxDockUIPart::typePaneSizer
||
2199 part
->type
== wxDockUIPart::typeDockSizer
||
2200 part
->type
== wxDockUIPart::typeBackground
)
2202 if (part
->type
== wxDockUIPart::typeDockSizer
)
2204 if (part
->dock
->panes
.GetCount() != 1)
2206 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2213 // If a normal frame is being dragged over a toolbar, insert it
2214 // along the edge under the toolbar, but over all other panes.
2215 // (this could be done much better, but somehow factoring this
2216 // calculation with the one at the beginning of this function)
2217 if (part
->dock
&& part
->dock
->toolbar
)
2221 switch (part
->dock
->dock_direction
)
2223 case wxAUI_DOCK_LEFT
:
2224 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2225 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2226 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2228 case wxAUI_DOCK_TOP
:
2229 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2230 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2231 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2233 case wxAUI_DOCK_RIGHT
:
2234 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2235 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2236 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2238 case wxAUI_DOCK_BOTTOM
:
2239 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2240 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2241 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2245 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2248 Direction(part
->dock
->dock_direction
).
2249 Layer(layer
).Row(0).Position(0);
2250 return ProcessDockResult(target
, drop
);
2257 part
= GetPanePart(part
->pane
->window
);
2261 bool insert_dock_row
= false;
2262 int insert_row
= part
->pane
->dock_row
;
2263 int insert_dir
= part
->pane
->dock_direction
;
2264 int insert_layer
= part
->pane
->dock_layer
;
2266 switch (part
->pane
->dock_direction
)
2268 case wxAUI_DOCK_TOP
:
2269 if (pt
.y
>= part
->rect
.y
&&
2270 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2271 insert_dock_row
= true;
2273 case wxAUI_DOCK_BOTTOM
:
2274 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2275 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2276 insert_dock_row
= true;
2278 case wxAUI_DOCK_LEFT
:
2279 if (pt
.x
>= part
->rect
.x
&&
2280 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2281 insert_dock_row
= true;
2283 case wxAUI_DOCK_RIGHT
:
2284 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2285 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2286 insert_dock_row
= true;
2288 case wxAUI_DOCK_CENTER
:
2290 // "new row pixels" will be set to the default, but
2291 // must never exceed 20% of the window size
2292 int new_row_pixels_x
= auiNewRowPixels
;
2293 int new_row_pixels_y
= auiNewRowPixels
;
2295 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2296 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2298 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2299 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2302 // determine if the mouse pointer is in a location that
2303 // will cause a new row to be inserted. The hot spot positions
2304 // are along the borders of the center pane
2307 insert_dock_row
= true;
2308 if (pt
.x
>= part
->rect
.x
&&
2309 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2310 insert_dir
= wxAUI_DOCK_LEFT
;
2312 if (pt
.y
>= part
->rect
.y
&&
2313 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2314 insert_dir
= wxAUI_DOCK_TOP
;
2316 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2317 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2318 insert_dir
= wxAUI_DOCK_RIGHT
;
2320 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2321 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2322 insert_dir
= wxAUI_DOCK_BOTTOM
;
2326 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2330 if (insert_dock_row
)
2332 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2333 drop
.Dock().Direction(insert_dir
).
2334 Layer(insert_layer
).
2337 return ProcessDockResult(target
, drop
);
2340 // determine the mouse offset and the pane size, both in the
2341 // direction of the dock itself, and perpendicular to the dock
2345 if (part
->orientation
== wxVERTICAL
)
2347 offset
= pt
.y
- part
->rect
.y
;
2348 size
= part
->rect
.GetHeight();
2352 offset
= pt
.x
- part
->rect
.x
;
2353 size
= part
->rect
.GetWidth();
2356 int drop_position
= part
->pane
->dock_pos
;
2358 // if we are in the top/left part of the pane,
2359 // insert the pane before the pane being hovered over
2360 if (offset
<= size
/2)
2362 drop_position
= part
->pane
->dock_pos
;
2364 part
->pane
->dock_direction
,
2365 part
->pane
->dock_layer
,
2366 part
->pane
->dock_row
,
2367 part
->pane
->dock_pos
);
2370 // if we are in the bottom/right part of the pane,
2371 // insert the pane before the pane being hovered over
2372 if (offset
> size
/2)
2374 drop_position
= part
->pane
->dock_pos
+1;
2376 part
->pane
->dock_direction
,
2377 part
->pane
->dock_layer
,
2378 part
->pane
->dock_row
,
2379 part
->pane
->dock_pos
+1);
2383 Direction(part
->dock
->dock_direction
).
2384 Layer(part
->dock
->dock_layer
).
2385 Row(part
->dock
->dock_row
).
2386 Position(drop_position
);
2387 return ProcessDockResult(target
, drop
);
2394 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2397 if (!m_hint_wnd
|| m_hint_fadeamt
>= 50)
2399 m_hint_fadetimer
.Stop();
2403 m_hint_fadeamt
+= 5;
2404 MakeWindowTransparent(m_hint_wnd
, m_hint_fadeamt
);
2408 void wxFrameManager::ShowHint(const wxRect
& rect
)
2412 // First, determine if the operating system can handle transparency.
2413 // Transparency is available on Win2000 and above
2415 static int os_type
= -1;
2416 static int ver_major
= -1;
2419 os_type
= ::wxGetOsVersion(&ver_major
);
2421 // If the transparent flag is set, and the OS supports it,
2422 // go ahead and use a transparent hint
2424 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 &&
2425 os_type
== wxWINDOWS_NT
&& ver_major
>= 5)
2427 if (m_last_hint
== rect
)
2431 int initial_fade
= 50;
2432 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2435 if (m_hint_wnd
== NULL
)
2437 wxPoint pt
= rect
.GetPosition();
2438 wxSize size
= rect
.GetSize();
2439 m_hint_wnd
= new wxFrame(m_frame
, -1, wxEmptyString
, pt
, size
,
2440 wxFRAME_TOOL_WINDOW
|
2441 wxFRAME_FLOAT_ON_PARENT
|
2442 wxFRAME_NO_TASKBAR
|
2445 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2446 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
2449 // if we are dragging a floating pane, set the focus
2450 // back to that floating pane (otherwise it becomes unfocused)
2451 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2452 m_action_window
->SetFocus();
2457 wxPoint pt
= rect
.GetPosition();
2458 wxSize size
= rect
.GetSize();
2459 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2460 m_hint_wnd
->SetSize(pt
.x
, pt
.y
, rect
.width
, rect
.height
);
2463 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2465 // start fade in timer
2467 m_hint_fadetimer
.SetOwner(this, 101);
2468 m_hint_fadetimer
.Start(5);
2475 if (m_last_hint
!= rect
)
2477 // remove the last hint rectangle
2483 wxScreenDC screendc
;
2484 wxRegion
clip(1, 1, 10000, 10000);
2486 // clip all floating windows, so we don't draw over them
2488 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2490 wxPaneInfo
& pane
= m_panes
.Item(i
);
2492 if (pane
.IsFloating() &&
2493 pane
.frame
->IsShown())
2495 wxRect rect
= pane
.frame
->GetRect();
2497 // wxGTK returns the client size, not the whole frame size
2503 clip
.Subtract(rect
);
2507 screendc
.SetClippingRegion(clip
);
2509 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2510 wxBrush
brush(stipple
);
2511 screendc
.SetBrush(brush
);
2512 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2514 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2515 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2516 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2517 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2520 void wxFrameManager::HideHint()
2522 // hides a transparent window hint (currently wxMSW only)
2526 MakeWindowTransparent(m_hint_wnd
, 0);
2527 m_hint_fadetimer
.Stop();
2528 m_last_hint
= wxRect();
2533 // hides a painted hint by redrawing the frame window
2534 if (!m_last_hint
.IsEmpty())
2538 m_last_hint
= wxRect();
2544 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2545 // determine the exact position the pane would be at were if dropped. If
2546 // the pame would indeed become docked at the specified drop point,
2547 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2548 // "pane_window" is the window pointer of the pane being dragged, pt is
2549 // the mouse position, in client coordinates
2550 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2552 const wxPoint
& offset
)
2556 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2557 // we will create a new temporary layout and then measure the resulting
2558 // rectangle; we will create a copy of the docking structures (m_dock)
2559 // so that we don't modify the real thing on screen
2561 int i
, pane_count
, part_count
;
2562 wxDockInfoArray docks
;
2563 wxPaneInfoArray panes
;
2564 wxDockUIPartArray uiparts
;
2565 wxPaneInfo hint
= GetPane(pane_window
);
2566 hint
.name
= wxT("__HINT__");
2571 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2573 // remove any pane already there which bears the same window;
2574 // this happens when you are moving a pane around in a dock
2575 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2577 if (panes
.Item(i
).window
== pane_window
)
2579 RemovePaneFromDocks(docks
, panes
.Item(i
));
2585 // find out where the new pane would be
2586 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2594 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2595 wxSize client_size
= m_frame
->GetClientSize();
2596 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2599 for (i
= 0, part_count
= uiparts
.GetCount();
2600 i
< part_count
; ++i
)
2602 wxDockUIPart
& part
= uiparts
.Item(i
);
2604 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2605 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2607 rect
= wxRect(part
.sizer_item
->GetPosition(),
2608 part
.sizer_item
->GetSize());
2621 // actually show the hint rectangle on the screen
2622 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2626 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2628 // try to find the pane
2629 wxPaneInfo
& pane
= GetPane(wnd
);
2630 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2633 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2634 MakeWindowTransparent(pane
.frame
, 150);
2638 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
)
2640 // try to find the pane
2641 wxPaneInfo
& pane
= GetPane(wnd
);
2642 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2644 wxPoint pt
= ::wxGetMousePosition();
2645 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2647 // calculate the offset from the upper left-hand corner
2648 // of the frame to the mouse pointer
2649 wxPoint frame_pos
= pane
.frame
->GetPosition();
2650 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2652 // no hint for toolbar floating windows
2653 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
2655 if (m_action
== actionDragFloatingPane
)
2657 wxDockInfoArray docks
;
2658 wxPaneInfoArray panes
;
2659 wxDockUIPartArray uiparts
;
2660 wxPaneInfo hint
= pane
;
2662 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2664 // find out where the new pane would be
2665 if (!DoDrop(docks
, panes
, hint
, client_pt
))
2667 if (hint
.IsFloating())
2671 m_action
= actionDragToolbarPane
;
2672 m_action_window
= pane
.window
;
2681 // if a key modifier is pressed while dragging the frame,
2682 // don't dock the window
2683 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2690 DrawHintRect(wnd
, client_pt
, action_offset
);
2693 // this cleans up some screen artifacts that are caused on GTK because
2694 // we aren't getting the exact size of the window (see comment
2704 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
)
2706 // try to find the pane
2707 wxPaneInfo
& pane
= GetPane(wnd
);
2708 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2710 wxPoint pt
= ::wxGetMousePosition();
2711 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2713 // calculate the offset from the upper left-hand corner
2714 // of the frame to the mouse pointer
2715 wxPoint frame_pos
= pane
.frame
->GetPosition();
2716 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2719 // if a key modifier is pressed while dragging the frame,
2720 // don't dock the window
2721 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2728 // do the drop calculation
2729 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
2731 // if the pane is still floating, update it's floating
2732 // position (that we store)
2733 if (pane
.IsFloating())
2735 pane
.floating_pos
= pane
.frame
->GetPosition();
2738 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2739 MakeWindowTransparent(pane
.frame
, 255);
2748 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
2750 // try to find the pane
2751 wxPaneInfo
& pane
= GetPane(wnd
);
2752 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2754 pane
.floating_size
= size
;
2757 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
)
2759 // try to find the pane
2760 wxPaneInfo
& pane
= GetPane(wnd
);
2761 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2763 // reparent the pane window back to us and
2764 // prepare the frame window for destruction
2765 pane
.window
->Show(false);
2766 pane
.window
->Reparent(m_frame
);
2771 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
2773 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
2775 // try to find the pane
2776 wxPaneInfo
& pane
= GetPane(wnd
);
2777 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2779 SetActivePane(m_panes
, wnd
);
2784 // Render() draws all of the pane captions, sashes,
2785 // backgrounds, captions, grippers, pane borders and buttons.
2786 // It renders the entire user interface.
2788 void wxFrameManager::Render(wxDC
* dc
)
2794 for (i
= 0, part_count
= m_uiparts
.GetCount();
2795 i
< part_count
; ++i
)
2797 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2799 // don't draw hidden pane items
2800 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
2805 case wxDockUIPart::typeDockSizer
:
2806 case wxDockUIPart::typePaneSizer
:
2807 m_art
->DrawSash(*dc
, part
.orientation
, part
.rect
);
2809 case wxDockUIPart::typeBackground
:
2810 m_art
->DrawBackground(*dc
, part
.orientation
, part
.rect
);
2812 case wxDockUIPart::typeCaption
:
2813 m_art
->DrawCaption(*dc
, part
.pane
->caption
, part
.rect
, *part
.pane
);
2815 case wxDockUIPart::typeGripper
:
2816 m_art
->DrawGripper(*dc
, part
.rect
, *part
.pane
);
2818 case wxDockUIPart::typePaneBorder
:
2819 m_art
->DrawBorder(*dc
, part
.rect
, *part
.pane
);
2821 case wxDockUIPart::typePaneButton
:
2822 m_art
->DrawPaneButton(*dc
, part
.button
->button_id
,
2823 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
2829 void wxFrameManager::Repaint(wxDC
* dc
)
2834 m_frame
->Refresh() ;
2840 m_frame
->GetClientSize(&w
, &h
);
2842 // figure out which dc to use; if one
2843 // has been specified, use it, otherwise
2845 wxClientDC
* client_dc
= NULL
;
2848 client_dc
= new wxClientDC(m_frame
);
2852 // if the frame has a toolbar, the client area
2853 // origin will not be (0,0).
2854 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2855 if (pt
.x
!= 0 || pt
.y
!= 0)
2856 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
2858 // render all the items
2861 // if we created a client_dc, delete it
2866 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2868 wxPaintDC
dc(m_frame
);
2872 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
2881 void wxFrameManager::OnSize(wxSizeEvent
& WXUNUSED(event
))
2891 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
2894 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2895 wxCursor cursor
= wxNullCursor
;
2899 if (part
->type
== wxDockUIPart::typeDockSizer
||
2900 part
->type
== wxDockUIPart::typePaneSizer
)
2902 // a dock may not be resized if it has a single
2903 // pane which is not resizable
2904 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
2905 part
->dock
->panes
.GetCount() == 1 &&
2906 part
->dock
->panes
.Item(0)->IsFixed())
2909 // panes that may not be resized do not get a sizing cursor
2910 if (part
->pane
&& part
->pane
->IsFixed())
2913 if (part
->orientation
== wxVERTICAL
)
2914 cursor
= wxCursor(wxCURSOR_SIZEWE
);
2916 cursor
= wxCursor(wxCURSOR_SIZENS
);
2918 else if (part
->type
== wxDockUIPart::typeGripper
)
2920 cursor
= wxCursor(wxCURSOR_SIZING
);
2924 event
.SetCursor(cursor
);
2929 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
2930 const wxMouseEvent
& event
)
2932 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
2934 int state
= wxAUI_BUTTON_STATE_NORMAL
;
2936 if (hit_test
== button_ui_part
)
2938 if (event
.LeftDown())
2939 state
= wxAUI_BUTTON_STATE_PRESSED
;
2941 state
= wxAUI_BUTTON_STATE_HOVER
;
2945 if (event
.LeftDown())
2946 state
= wxAUI_BUTTON_STATE_HOVER
;
2949 // now repaint the button with hover state
2950 wxClientDC
cdc(m_frame
);
2952 // if the frame has a toolbar, the client area
2953 // origin will not be (0,0).
2954 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2955 if (pt
.x
!= 0 || pt
.y
!= 0)
2956 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
2958 m_art
->DrawPaneButton(cdc
,
2959 button_ui_part
->button
->button_id
,
2961 button_ui_part
->rect
,
2965 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
2967 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2970 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2973 if (part
->type
== wxDockUIPart::typeDockSizer
||
2974 part
->type
== wxDockUIPart::typePaneSizer
)
2976 // a dock may not be resized if it has a single
2977 // pane which is not resizable
2978 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
2979 part
->dock
->panes
.GetCount() == 1 &&
2980 part
->dock
->panes
.Item(0)->IsFixed())
2983 // panes that may not be resized should be ignored here
2984 if (part
->pane
&& part
->pane
->IsFixed())
2987 m_action
= actionResize
;
2988 m_action_part
= part
;
2989 m_action_hintrect
= wxRect();
2990 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
2991 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
2992 event
.m_y
- part
->rect
.y
);
2993 m_frame
->CaptureMouse();
2995 else if (part
->type
== wxDockUIPart::typePaneButton
)
2997 m_action
= actionClickButton
;
2998 m_action_part
= part
;
2999 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3000 m_frame
->CaptureMouse();
3002 UpdateButtonOnScreen(part
, event
);
3004 else if (part
->type
== wxDockUIPart::typeCaption
||
3005 part
->type
== wxDockUIPart::typeGripper
)
3007 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3009 // set the caption as active
3010 SetActivePane(m_panes
, part
->pane
->window
);
3014 m_action
= actionClickCaption
;
3015 m_action_part
= part
;
3016 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3017 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3018 event
.m_y
- part
->rect
.y
);
3019 m_frame
->CaptureMouse();
3039 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3041 if (m_action
== actionResize
)
3043 m_frame
->ReleaseMouse();
3045 // get rid of the hint rectangle
3047 DrawResizeHint(dc
, m_action_hintrect
);
3049 // resize the dock or the pane
3050 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3052 wxRect
& rect
= m_action_part
->dock
->rect
;
3054 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3055 event
.m_y
- m_action_offset
.y
);
3057 switch (m_action_part
->dock
->dock_direction
)
3059 case wxAUI_DOCK_LEFT
:
3060 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3062 case wxAUI_DOCK_TOP
:
3063 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3065 case wxAUI_DOCK_RIGHT
:
3066 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3067 new_pos
.x
- m_action_part
->rect
.GetWidth();
3069 case wxAUI_DOCK_BOTTOM
:
3070 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3071 new_pos
.y
- m_action_part
->rect
.GetHeight();
3078 else if (m_action_part
&&
3079 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3081 wxDockInfo
& dock
= *m_action_part
->dock
;
3082 wxPaneInfo
& pane
= *m_action_part
->pane
;
3084 int total_proportion
= 0;
3085 int dock_pixels
= 0;
3086 int new_pixsize
= 0;
3088 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3089 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3090 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3092 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3093 event
.m_y
- m_action_offset
.y
);
3095 // determine the pane rectangle by getting the pane part
3096 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3097 wxASSERT_MSG(pane_part
,
3098 wxT("Pane border part not found -- shouldn't happen"));
3100 // determine the new pixel size that the user wants;
3101 // this will help us recalculate the pane's proportion
3102 if (dock
.IsHorizontal())
3103 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3105 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3107 // determine the size of the dock, based on orientation
3108 if (dock
.IsHorizontal())
3109 dock_pixels
= dock
.rect
.GetWidth();
3111 dock_pixels
= dock
.rect
.GetHeight();
3113 // determine the total proportion of all resizable panes,
3114 // and the total size of the dock minus the size of all
3116 int i
, dock_pane_count
= dock
.panes
.GetCount();
3117 int pane_position
= -1;
3118 for (i
= 0; i
< dock_pane_count
; ++i
)
3120 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3121 if (p
.window
== pane
.window
)
3124 // while we're at it, subtract the pane sash
3125 // width from the dock width, because this would
3126 // skew our proportion calculations
3128 dock_pixels
-= sash_size
;
3130 // also, the whole size (including decorations) of
3131 // all fixed panes must also be subtracted, because they
3132 // are not part of the proportion calculation
3135 if (dock
.IsHorizontal())
3136 dock_pixels
-= p
.best_size
.x
;
3138 dock_pixels
-= p
.best_size
.y
;
3142 total_proportion
+= p
.dock_proportion
;
3146 // find a pane in our dock to 'steal' space from or to 'give'
3147 // space to -- this is essentially what is done when a pane is
3148 // resized; the pane should usually be the first non-fixed pane
3149 // to the right of the action pane
3150 int borrow_pane
= -1;
3151 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3153 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3162 // demand that the pane being resized is found in this dock
3163 // (this assert really never should be raised)
3164 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3166 // prevent division by zero
3167 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3169 m_action
= actionNone
;
3173 // calculate the new proportion of the pane
3174 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3176 // default minimum size
3179 // check against the pane's minimum size, if specified. please note
3180 // that this is not enough to ensure that the minimum size will
3181 // not be violated, because the whole frame might later be shrunk,
3182 // causing the size of the pane to violate it's minimum size
3183 if (pane
.min_size
.IsFullySpecified())
3187 if (pane
.HasBorder())
3188 min_size
+= (pane_border_size
*2);
3190 // calculate minimum size with decorations (border,caption)
3191 if (pane_part
->orientation
== wxVERTICAL
)
3193 min_size
+= pane
.min_size
.y
;
3194 if (pane
.HasCaption())
3195 min_size
+= caption_size
;
3199 min_size
+= pane
.min_size
.x
;
3204 // for some reason, an arithmatic error somewhere is causing
3205 // the proportion calculations to always be off by 1 pixel;
3206 // for now we will add the 1 pixel on, but we really should
3207 // determine what's causing this.
3210 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3212 if (new_proportion
< min_proportion
)
3213 new_proportion
= min_proportion
;
3217 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3219 // borrow the space from our neighbor pane to the
3220 // right or bottom (depending on orientation)
3221 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3222 pane
.dock_proportion
= new_proportion
;
3229 else if (m_action
== actionClickButton
)
3231 m_hover_button
= NULL
;
3232 m_frame
->ReleaseMouse();
3233 UpdateButtonOnScreen(m_action_part
, event
);
3235 // make sure we're still over the item that was originally clicked
3236 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3238 // fire button-click event
3239 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3240 e
.SetPane(m_action_part
->pane
);
3241 e
.SetButton(m_action_part
->button
->button_id
);
3245 else if (m_action
== actionClickCaption
)
3247 m_frame
->ReleaseMouse();
3249 else if (m_action
== actionDragFloatingPane
)
3251 m_frame
->ReleaseMouse();
3253 else if (m_action
== actionDragToolbarPane
)
3255 m_frame
->ReleaseMouse();
3257 wxPaneInfo
& pane
= GetPane(m_action_window
);
3258 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3260 // save the new positions
3261 wxDockInfoPtrArray docks
;
3262 FindDocks(m_docks
, pane
.dock_direction
,
3263 pane
.dock_layer
, pane
.dock_row
, docks
);
3264 if (docks
.GetCount() == 1)
3266 wxDockInfo
& dock
= *docks
.Item(0);
3268 wxArrayInt pane_positions
, pane_sizes
;
3269 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3271 int i
, dock_pane_count
= dock
.panes
.GetCount();
3272 for (i
= 0; i
< dock_pane_count
; ++i
)
3273 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3276 pane
.state
&= ~wxPaneInfo::actionPane
;
3284 m_action
= actionNone
;
3285 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3289 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3291 // sometimes when Update() is called from inside this method,
3292 // a spurious mouse move event is generated; this check will make
3293 // sure that only real mouse moves will get anywhere in this method;
3294 // this appears to be a bug somewhere, and I don't know where the
3295 // mouse move event is being generated. only verified on MSW
3297 wxPoint mouse_pos
= event
.GetPosition();
3298 if (m_last_mouse_move
== mouse_pos
)
3300 m_last_mouse_move
= mouse_pos
;
3303 if (m_action
== actionResize
)
3305 wxPoint pos
= m_action_part
->rect
.GetPosition();
3306 if (m_action_part
->orientation
== wxHORIZONTAL
)
3307 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3309 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3311 wxRect
rect(m_frame
->ClientToScreen(pos
),
3312 m_action_part
->rect
.GetSize());
3315 if (!m_action_hintrect
.IsEmpty())
3316 DrawResizeHint(dc
, m_action_hintrect
);
3317 DrawResizeHint(dc
, rect
);
3318 m_action_hintrect
= rect
;
3320 else if (m_action
== actionClickCaption
)
3322 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3323 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3325 // caption has been clicked. we need to check if the mouse
3326 // is now being dragged. if it is, we need to change the
3327 // mouse action to 'drag'
3328 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3329 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3331 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3333 if (!pane_info
->IsToolbar())
3335 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3336 pane_info
->IsFloatable())
3338 m_action
= actionDragFloatingPane
;
3340 // set initial float position
3341 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3342 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3343 pt
.y
- m_action_offset
.y
);
3348 m_action_window
= pane_info
->frame
;
3350 // action offset is used here to make it feel "natural" to the user
3351 // to drag a docked pane and suddenly have it become a floating frame.
3352 // Sometimes, however, the offset where the user clicked on the docked
3353 // caption is bigger than the width of the floating frame itself, so
3354 // in that case we need to set the action offset to a sensible value
3355 wxSize frame_size
= m_action_window
->GetSize();
3356 if (frame_size
.x
<= m_action_offset
.x
)
3357 m_action_offset
.x
= 30;
3362 m_action
= actionDragToolbarPane
;
3363 m_action_window
= pane_info
->window
;
3367 else if (m_action
== actionDragFloatingPane
)
3369 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3370 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3371 pt
.y
- m_action_offset
.y
);
3373 else if (m_action
== actionDragToolbarPane
)
3375 wxPaneInfo
& pane
= GetPane(m_action_window
);
3376 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3378 pane
.state
|= wxPaneInfo::actionPane
;
3380 wxPoint pt
= event
.GetPosition();
3381 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3383 // if DoDrop() decided to float the pane, set up
3384 // the floating pane's initial position
3385 if (pane
.IsFloating())
3387 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3388 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3389 pt
.y
- m_action_offset
.y
);
3392 // this will do the actiual move operation;
3393 // in the case that the pane has been floated,
3394 // this call will create the floating pane
3395 // and do the reparenting
3398 // if the pane has been floated, change the mouse
3399 // action actionDragFloatingPane so that subsequent
3400 // EVT_MOTION() events will move the floating pane
3401 if (pane
.IsFloating())
3403 pane
.state
&= ~wxPaneInfo::actionPane
;
3404 m_action
= actionDragFloatingPane
;
3405 m_action_window
= pane
.frame
;
3410 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3411 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3413 if (part
!= m_hover_button
)
3415 // make the old button normal
3417 UpdateButtonOnScreen(m_hover_button
, event
);
3419 // mouse is over a button, so repaint the
3420 // button in hover mode
3421 UpdateButtonOnScreen(part
, event
);
3422 m_hover_button
= part
;
3429 m_hover_button
= NULL
;
3440 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3444 m_hover_button
= NULL
;
3449 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3451 // when a child pane has it's focus set, we should change the
3452 // pane's active state to reflect this. (this is only true if
3453 // active panes are allowed by the owner)
3454 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3456 if (GetPane(event
.GetWindow()).IsOk())
3458 SetActivePane(m_panes
, event
.GetWindow());
3465 // OnPaneButton() is an event handler that is called
3466 // when a pane button has been pressed.
3467 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& event
)
3469 wxPaneInfo
& pane
= *(event
.pane
);
3471 if (event
.button
== wxPaneInfo::buttonClose
)
3476 else if (event
.button
== wxPaneInfo::buttonPin
)
3478 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&