1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/framemanager.cpp
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
8 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/aui/framemanager.h"
29 #include "wx/aui/dockart.h"
30 #include "wx/aui/floatpane.h"
33 #include "wx/settings.h"
35 #include "wx/dcclient.h"
36 #include "wx/dcscreen.h"
37 #include "wx/toolbar.h"
42 WX_CHECK_BUILD_OPTIONS("wxAUI")
44 #include "wx/arrimpl.cpp"
45 WX_DECLARE_OBJARRAY(wxRect
, wxAuiRectArray
);
46 WX_DEFINE_OBJARRAY(wxAuiRectArray
)
47 WX_DEFINE_OBJARRAY(wxDockUIPartArray
)
48 WX_DEFINE_OBJARRAY(wxDockInfoArray
)
49 WX_DEFINE_OBJARRAY(wxPaneButtonArray
)
50 WX_DEFINE_OBJARRAY(wxPaneInfoArray
)
52 wxPaneInfo wxNullPaneInfo
;
53 wxDockInfo wxNullDockInfo
;
54 DEFINE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON
)
55 DEFINE_EVENT_TYPE(wxEVT_AUI_PANECLOSE
)
58 // a few defines to avoid nameclashes
59 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
61 #include "wx/mac/private.h"
65 // -- static utility functions --
67 static wxBitmap
wxPaneCreateStippleBitmap()
69 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
70 wxImage
img(2,2,data
,true);
74 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
76 wxBitmap stipple
= wxPaneCreateStippleBitmap();
77 wxBrush
brush(stipple
);
79 dc
.SetPen(*wxTRANSPARENT_PEN
);
81 dc
.SetLogicalFunction(wxXOR
);
82 dc
.DrawRectangle(rect
);
86 // on supported windows systems (Win2000 and greater, Mac), this function
87 // will make a frame window transparent by a certain amount
88 static void MakeWindowTransparent(wxWindow
* wnd
, int amount
)
90 #if defined(__WXMSW__)
91 // this API call is not in all SDKs, only the newer ones, so
92 // we will runtime bind this
93 typedef DWORD (WINAPI
*PSETLAYEREDWINDOWATTR
)(HWND
, DWORD
, BYTE
, DWORD
);
94 static PSETLAYEREDWINDOWATTR pSetLayeredWindowAttributes
= NULL
;
95 static HMODULE h
= NULL
;
96 HWND hwnd
= (HWND
)wnd
->GetHWND();
99 h
= LoadLibrary(_T("user32"));
101 if (!pSetLayeredWindowAttributes
)
103 pSetLayeredWindowAttributes
=
104 (PSETLAYEREDWINDOWATTR
)GetProcAddress(h
,
106 wxT("SetLayeredWindowAttributes")
108 "SetLayeredWindowAttributes"
113 if (pSetLayeredWindowAttributes
== NULL
)
116 LONG exstyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
117 if (0 == (exstyle
& 0x80000) /*WS_EX_LAYERED*/)
118 SetWindowLong(hwnd
, GWL_EXSTYLE
, exstyle
| 0x80000 /*WS_EX_LAYERED*/);
120 pSetLayeredWindowAttributes(hwnd
, 0, (BYTE
)amount
, 2 /*LWA_ALPHA*/);
122 #elif defined(__WXMAC__)
124 WindowRef handle
= GetControlOwner((OpaqueControlRef
*)wnd
->GetHandle());
125 SetWindowAlpha(handle
, float(amount
)/ 255.0);
135 // CopyDocksAndPanes() - this utility function creates copies of
136 // the dock and pane info. wxDockInfo's usually contain pointers
137 // to wxPaneInfo classes, thus this function is necessary to reliably
138 // reconstruct that relationship in the new dock info and pane info arrays
140 static void CopyDocksAndPanes(wxDockInfoArray
& dest_docks
,
141 wxPaneInfoArray
& dest_panes
,
142 const wxDockInfoArray
& src_docks
,
143 const wxPaneInfoArray
& src_panes
)
145 dest_docks
= src_docks
;
146 dest_panes
= src_panes
;
147 int i
, j
, k
, dock_count
, pc1
, pc2
;
148 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
150 wxDockInfo
& dock
= dest_docks
.Item(i
);
151 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
152 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
153 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
154 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
158 // GetMaxLayer() is an internal function which returns
159 // the highest layer inside the specified dock
160 static int GetMaxLayer(const wxDockInfoArray
& docks
, int dock_direction
)
162 int i
, dock_count
, max_layer
= 0;
163 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
165 wxDockInfo
& dock
= docks
.Item(i
);
166 if (dock
.dock_direction
== dock_direction
&&
167 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
168 max_layer
= dock
.dock_layer
;
174 // GetMaxRow() is an internal function which returns
175 // the highest layer inside the specified dock
176 static int GetMaxRow(const wxPaneInfoArray
& panes
, int direction
, int layer
)
178 int i
, pane_count
, max_row
= 0;
179 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
181 wxPaneInfo
& pane
= panes
.Item(i
);
182 if (pane
.dock_direction
== direction
&&
183 pane
.dock_layer
== layer
&&
184 pane
.dock_row
> max_row
)
185 max_row
= pane
.dock_row
;
192 // DoInsertDockLayer() is an internal function that inserts a new dock
193 // layer by incrementing all existing dock layer values by one
194 static void DoInsertDockLayer(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
)
209 // DoInsertDockLayer() is an internal function that inserts a new dock
210 // row by incrementing all existing dock row values by one
211 static void DoInsertDockRow(wxPaneInfoArray
& panes
,
217 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
219 wxPaneInfo
& pane
= panes
.Item(i
);
220 if (!pane
.IsFloating() &&
221 pane
.dock_direction
== dock_direction
&&
222 pane
.dock_layer
== dock_layer
&&
223 pane
.dock_row
>= dock_row
)
228 // DoInsertDockLayer() is an internal function that inserts a space for
229 // another dock pane by incrementing all existing dock row values by one
230 static void DoInsertPane(wxPaneInfoArray
& panes
,
237 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
239 wxPaneInfo
& pane
= panes
.Item(i
);
240 if (!pane
.IsFloating() &&
241 pane
.dock_direction
== dock_direction
&&
242 pane
.dock_layer
== dock_layer
&&
243 pane
.dock_row
== dock_row
&&
244 pane
.dock_pos
>= dock_pos
)
249 // FindDocks() is an internal function that returns a list of docks which meet
250 // the specified conditions in the parameters and returns a sorted array
251 // (sorted by layer and then row)
252 static void FindDocks(wxDockInfoArray
& docks
,
256 wxDockInfoPtrArray
& arr
)
258 int begin_layer
= dock_layer
;
259 int end_layer
= dock_layer
;
260 int begin_row
= dock_row
;
261 int end_row
= dock_row
;
262 int dock_count
= docks
.GetCount();
263 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
265 // discover the maximum dock layer and the max row
266 for (i
= 0; i
< dock_count
; ++i
)
268 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
269 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
272 // if no dock layer was specified, search all dock layers
273 if (dock_layer
== -1)
276 end_layer
= max_layer
;
279 // if no dock row was specified, search all dock row
288 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
289 for (row
= begin_row
; row
<= end_row
; ++row
)
290 for (i
= 0; i
< dock_count
; ++i
)
292 wxDockInfo
& d
= docks
.Item(i
);
293 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
295 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
301 // FindPaneInDock() looks up a specified window pointer inside a dock.
302 // If found, the corresponding wxPaneInfo pointer is returned, otherwise NULL.
303 static wxPaneInfo
* FindPaneInDock(const wxDockInfo
& dock
, wxWindow
* window
)
305 int i
, count
= dock
.panes
.GetCount();
306 for (i
= 0; i
< count
; ++i
)
308 wxPaneInfo
* p
= dock
.panes
.Item(i
);
309 if (p
->window
== window
)
315 // RemovePaneFromDocks() removes a pane window from all docks
316 // with a possible exception specified by parameter "except"
317 static void RemovePaneFromDocks(wxDockInfoArray
& docks
,
319 wxDockInfo
* except
= NULL
)
322 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
324 wxDockInfo
& d
= docks
.Item(i
);
327 wxPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
333 // RenumberDockRows() takes a dock and assigns sequential numbers
334 // to existing rows. Basically it takes out the gaps; so if a
335 // dock has rows with numbers 0,2,5, they will become 0,1,2
336 static void RenumberDockRows(wxDockInfoPtrArray
& docks
)
338 int i
, dock_count
, j
, pane_count
;
339 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
341 wxDockInfo
& dock
= *docks
.Item(i
);
343 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
344 dock
.panes
.Item(j
)->dock_row
= i
;
349 // SetActivePane() sets the active pane, as well as cycles through
350 // every other pane and makes sure that all others' active flags
352 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
355 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
357 wxPaneInfo
& pane
= panes
.Item(i
);
358 pane
.state
&= ~wxPaneInfo::optionActive
;
359 if (pane
.window
== active_pane
)
360 pane
.state
|= wxPaneInfo::optionActive
;
365 // this function is used to sort panes by dock position
366 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
368 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
372 // -- wxFrameManager class implementation --
375 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
376 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
377 EVT_PAINT(wxFrameManager::OnPaint
)
378 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
379 EVT_SIZE(wxFrameManager::OnSize
)
380 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
381 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
382 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
383 EVT_MOTION(wxFrameManager::OnMotion
)
384 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
385 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
386 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
390 wxFrameManager::wxFrameManager(wxFrame
* frame
, unsigned int flags
)
392 m_action
= actionNone
;
393 m_last_mouse_move
= wxPoint();
394 m_hover_button
= NULL
;
395 m_art
= new wxDefaultDockArt
;
405 wxFrameManager::~wxFrameManager()
410 // GetPane() looks up a wxPaneInfo structure based
411 // on the supplied window pointer. Upon failure, GetPane()
412 // returns an empty wxPaneInfo, a condition which can be checked
413 // by calling wxPaneInfo::IsOk().
415 // The pane info's structure may then be modified. Once a pane's
416 // info is modified, wxFrameManager::Update() must be called to
417 // realize the changes in the UI.
419 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
422 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
424 wxPaneInfo
& p
= m_panes
.Item(i
);
425 if (p
.window
== window
)
428 return wxNullPaneInfo
;
431 // this version of GetPane() looks up a pane based on a
432 // 'pane name', see above comment for more info
433 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
436 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
438 wxPaneInfo
& p
= m_panes
.Item(i
);
442 return wxNullPaneInfo
;
445 // GetAllPanes() returns a reference to all the pane info structures
446 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
451 // HitTest() is an internal function which determines
452 // which UI item the specified coordinates are over
453 // (x,y) specify a position in client coordinates
454 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
456 wxDockUIPart
* result
= NULL
;
459 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
461 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
463 // we are not interested in typeDock, because this space
464 // isn't used to draw anything, just for measurements;
465 // besides, the entire dock area is covered with other
466 // rectangles, which we are interested in.
467 if (item
->type
== wxDockUIPart::typeDock
)
470 // if we already have a hit on a more specific item, we are not
471 // interested in a pane hit. If, however, we don't already have
472 // a hit, returning a pane hit is necessary for some operations
473 if ((item
->type
== wxDockUIPart::typePane
||
474 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
477 // if the point is inside the rectangle, we have a hit
478 if (item
->rect
.Inside(x
,y
))
486 // SetFlags() and GetFlags() allow the owner to set various
487 // options which are global to wxFrameManager
488 void wxFrameManager::SetFlags(unsigned int flags
)
493 unsigned int wxFrameManager::GetFlags() const
499 // SetFrame() is usually called once when the frame
500 // manager class is being initialized. "frame" specifies
501 // the frame which should be managed by the frame mananger
502 void wxFrameManager::SetFrame(wxFrame
* frame
)
504 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
507 m_frame
->PushEventHandler(this);
510 // if the owner is going to manage an MDI parent frame,
511 // we need to add the MDI client window as the default
514 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
516 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
517 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
519 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
521 AddPane(client_window
,
522 wxPaneInfo().Name(wxT("mdiclient")).
523 CenterPane().PaneBorder(false));
529 // UnInit() must be called, usually in the destructor
530 // of the frame class. If it is not called, usually this
531 // will result in a crash upon program exit
532 void wxFrameManager::UnInit()
534 m_frame
->RemoveEventHandler(this);
537 // GetFrame() returns the frame pointer being managed by wxFrameManager
538 wxFrame
* wxFrameManager::GetFrame() const
543 wxDockArt
* wxFrameManager::GetArtProvider() const
548 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
550 // first, give the owner frame a chance to override
553 if (m_frame
->ProcessEvent(event
))
560 // SetArtProvider() instructs wxFrameManager to use the
561 // specified art provider for all drawing calls. This allows
562 // plugable look-and-feel features. The pointer that is
563 // passed to this method subsequently belongs to wxFrameManager,
564 // and is deleted in the frame manager destructor
565 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
567 // delete the last art provider, if any
570 // assign the new art provider
571 m_art
= art_provider
;
575 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
577 // check if the pane has a valid window
581 // check if the pane already exists
582 if (GetPane(pane_info
.window
).IsOk())
585 m_panes
.Add(pane_info
);
587 wxPaneInfo
& pinfo
= m_panes
.Last();
589 // set the pane window
590 pinfo
.window
= window
;
592 // if the pane's name identifier is blank, create a random string
593 if (pinfo
.name
.empty())
595 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
596 ((unsigned long)pinfo
.window
) & 0xffffffff,
597 (unsigned int)time(NULL
),
599 (unsigned int)GetTickCount(),
601 (unsigned int)clock(),
603 (unsigned long)m_panes
.GetCount());
606 // set initial proportion (if not already set)
607 if (pinfo
.dock_proportion
== 0)
608 pinfo
.dock_proportion
= 100000;
610 if (pinfo
.HasCloseButton() &&
611 pinfo
.buttons
.size() == 0)
614 button
.button_id
= wxPaneInfo::buttonClose
;
615 pinfo
.buttons
.Add(button
);
618 if (pinfo
.best_size
== wxDefaultSize
&&
621 pinfo
.best_size
= pinfo
.window
->GetClientSize();
623 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
625 // GetClientSize() doesn't get the best size for
626 // a toolbar under some newer versions of wxWidgets,
627 // so use GetBestSize()
628 pinfo
.best_size
= pinfo
.window
->GetBestSize();
630 // for some reason, wxToolBar::GetBestSize() is returning
631 // a size that is a pixel shy of the correct amount.
632 // I believe this to be the correct action, until
633 // wxToolBar::GetBestSize() is fixed. Is this assumption
638 if (pinfo
.min_size
!= wxDefaultSize
)
640 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
641 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
642 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
643 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
650 bool wxFrameManager::AddPane(wxWindow
* window
,
652 const wxString
& caption
)
655 pinfo
.Caption(caption
);
658 case wxTOP
: pinfo
.Top(); break;
659 case wxBOTTOM
: pinfo
.Bottom(); break;
660 case wxLEFT
: pinfo
.Left(); break;
661 case wxRIGHT
: pinfo
.Right(); break;
662 case wxCENTER
: pinfo
.CenterPane(); break;
664 return AddPane(window
, pinfo
);
667 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
670 // shift the panes around, depending on the insert level
671 switch (insert_level
)
673 case wxAUI_INSERT_PANE
:
674 DoInsertPane(m_panes
,
675 pane_info
.dock_direction
,
676 pane_info
.dock_layer
,
680 case wxAUI_INSERT_ROW
:
681 DoInsertDockRow(m_panes
,
682 pane_info
.dock_direction
,
683 pane_info
.dock_layer
,
686 case wxAUI_INSERT_DOCK
:
687 DoInsertDockLayer(m_panes
,
688 pane_info
.dock_direction
,
689 pane_info
.dock_layer
);
693 // if the window already exists, we are basically just moving/inserting the
694 // existing window. If it doesn't exist, we need to add it and insert it
695 wxPaneInfo
& existing_pane
= GetPane(window
);
696 if (!existing_pane
.IsOk())
698 return AddPane(window
, pane_info
);
702 if (pane_info
.IsFloating())
704 existing_pane
.Float();
705 if (pane_info
.floating_pos
!= wxDefaultPosition
)
706 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
707 if (pane_info
.floating_size
!= wxDefaultSize
)
708 existing_pane
.FloatingSize(pane_info
.floating_size
);
712 existing_pane
.Direction(pane_info
.dock_direction
);
713 existing_pane
.Layer(pane_info
.dock_layer
);
714 existing_pane
.Row(pane_info
.dock_row
);
715 existing_pane
.Position(pane_info
.dock_pos
);
723 // DetachPane() removes a pane from the frame manager. This
724 // method will not destroy the window that is removed.
725 bool wxFrameManager::DetachPane(wxWindow
* window
)
728 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
730 wxPaneInfo
& p
= m_panes
.Item(i
);
731 if (p
.window
== window
)
735 // we have a floating frame which is being detached. We need to
736 // reparent it to m_frame and destroy the floating frame
739 p
.window
->SetSize(1,1);
740 p
.frame
->Show(false);
742 // reparent to m_frame and destroy the pane
743 p
.window
->Reparent(m_frame
);
744 p
.frame
->SetSizer(NULL
);
756 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
757 // in the input string. This is an internal functions which is
758 // used for saving perspectives
759 static wxString
EscapeDelimiters(const wxString
& s
)
762 result
.Alloc(s
.length());
763 const wxChar
* ch
= s
.c_str();
766 if (*ch
== wxT(';') || *ch
== wxT('|'))
775 // SavePerspective() saves all pane information as a single string.
776 // This string may later be fed into LoadPerspective() to restore
777 // all pane settings. This save and load mechanism allows an
778 // exact pane configuration to be saved and restored at a later time
780 wxString
wxFrameManager::SavePerspective()
784 result
= wxT("layout1|");
786 int pane_i
, pane_count
= m_panes
.GetCount();
787 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
789 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
791 result
+= wxT("name=");
792 result
+= EscapeDelimiters(pane
.name
);
795 result
+= wxT("caption=");
796 result
+= EscapeDelimiters(pane
.caption
);
799 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
800 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
801 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
802 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
803 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
804 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
805 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
806 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
807 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
808 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
809 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
810 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
811 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
812 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
813 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
814 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
818 int dock_i
, dock_count
= m_docks
.GetCount();
819 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
821 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
823 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
824 dock
.dock_direction
, dock
.dock_layer
,
825 dock
.dock_row
, dock
.size
);
831 // LoadPerspective() loads a layout which was saved with SavePerspective()
832 // If the "update" flag parameter is true, the GUI will immediately be updated
834 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
836 wxString input
= layout
;
839 // check layout string version
840 part
= input
.BeforeFirst(wxT('|'));
841 input
= input
.AfterFirst(wxT('|'));
844 if (part
!= wxT("layout1"))
848 // mark all panes currently managed as docked and hidden
849 int pane_i
, pane_count
= m_panes
.GetCount();
850 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
851 m_panes
.Item(pane_i
).Dock().Hide();
853 // clear out the dock array; this will be reconstructed
856 // replace escaped characters so we can
857 // split up the string easily
858 input
.Replace(wxT("\\|"), wxT("\a"));
859 input
.Replace(wxT("\\;"), wxT("\b"));
865 wxString pane_part
= input
.BeforeFirst(wxT('|'));
866 input
= input
.AfterFirst(wxT('|'));
867 pane_part
.Trim(true);
869 // if the string is empty, we're done parsing
870 if (pane_part
.empty())
874 if (pane_part
.Left(9) == wxT("dock_size"))
876 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
877 wxString value
= pane_part
.AfterFirst(wxT('='));
879 long dir
, layer
, row
, size
;
880 wxString piece
= val_name
.AfterFirst(wxT('('));
881 piece
= piece
.BeforeLast(wxT(')'));
882 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
883 piece
= piece
.AfterFirst(wxT(','));
884 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
885 piece
.AfterFirst(wxT(',')).ToLong(&row
);
889 dock
.dock_direction
= dir
;
890 dock
.dock_layer
= layer
;
899 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
900 pane_part
= pane_part
.AfterFirst(wxT(';'));
901 wxString val_name
= val_part
.BeforeFirst(wxT('='));
902 wxString value
= val_part
.AfterFirst(wxT('='));
903 val_name
.MakeLower();
905 val_name
.Trim(false);
909 if (val_name
.empty())
912 if (val_name
== wxT("name"))
914 else if (val_name
== wxT("caption"))
915 pane
.caption
= value
;
916 else if (val_name
== wxT("state"))
917 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
918 else if (val_name
== wxT("dir"))
919 pane
.dock_direction
= wxAtoi(value
.c_str());
920 else if (val_name
== wxT("layer"))
921 pane
.dock_layer
= wxAtoi(value
.c_str());
922 else if (val_name
== wxT("row"))
923 pane
.dock_row
= wxAtoi(value
.c_str());
924 else if (val_name
== wxT("pos"))
925 pane
.dock_pos
= wxAtoi(value
.c_str());
926 else if (val_name
== wxT("prop"))
927 pane
.dock_proportion
= wxAtoi(value
.c_str());
928 else if (val_name
== wxT("bestw"))
929 pane
.best_size
.x
= wxAtoi(value
.c_str());
930 else if (val_name
== wxT("besth"))
931 pane
.best_size
.y
= wxAtoi(value
.c_str());
932 else if (val_name
== wxT("minw"))
933 pane
.min_size
.x
= wxAtoi(value
.c_str());
934 else if (val_name
== wxT("minh"))
935 pane
.min_size
.y
= wxAtoi(value
.c_str());
936 else if (val_name
== wxT("maxw"))
937 pane
.max_size
.x
= wxAtoi(value
.c_str());
938 else if (val_name
== wxT("maxh"))
939 pane
.max_size
.y
= wxAtoi(value
.c_str());
940 else if (val_name
== wxT("floatx"))
941 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
942 else if (val_name
== wxT("floaty"))
943 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
944 else if (val_name
== wxT("floatw"))
945 pane
.floating_size
.x
= wxAtoi(value
.c_str());
946 else if (val_name
== wxT("floath"))
947 pane
.floating_size
.y
= wxAtoi(value
.c_str());
949 wxFAIL_MSG(wxT("Bad Perspective String"));
953 // replace escaped characters so we can
954 // split up the string easily
955 pane
.name
.Replace(wxT("\a"), wxT("|"));
956 pane
.name
.Replace(wxT("\b"), wxT(";"));
957 pane
.caption
.Replace(wxT("\a"), wxT("|"));
958 pane
.caption
.Replace(wxT("\b"), wxT(";"));
960 wxPaneInfo
& p
= GetPane(pane
.name
);
963 // the pane window couldn't be found
964 // in the existing layout
968 pane
.window
= p
.window
;
969 pane
.frame
= p
.frame
;
970 pane
.buttons
= p
.buttons
;
981 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
982 wxArrayInt
& positions
,
985 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
986 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
987 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
992 int offset
, action_pane
= -1;
993 int pane_i
, pane_count
= dock
.panes
.GetCount();
995 // find the pane marked as our action pane
996 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
998 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1000 if (pane
.state
& wxPaneInfo::actionPane
)
1002 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1003 action_pane
= pane_i
;
1007 // set up each panes default position, and
1008 // determine the size (width or height, depending
1009 // on the dock's orientation) of each pane
1010 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1012 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1013 positions
.Add(pane
.dock_pos
);
1016 if (pane
.HasBorder())
1017 size
+= (pane_border_size
*2);
1019 if (dock
.IsHorizontal())
1021 if (pane
.HasGripper() && !pane
.HasGripperTop())
1022 size
+= gripper_size
;
1023 size
+= pane
.best_size
.x
;
1027 if (pane
.HasGripper() && pane
.HasGripperTop())
1028 size
+= gripper_size
;
1030 if (pane
.HasCaption())
1031 size
+= caption_size
;
1032 size
+= pane
.best_size
.y
;
1038 // if there is no action pane, just return the default
1039 // positions (as specified in pane.pane_pos)
1040 if (action_pane
== -1)
1044 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1046 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1051 positions
[pane_i
] -= -amount
;
1053 offset
+= sizes
[pane_i
];
1056 // if the dock mode is fixed, make sure none of the panes
1057 // overlap; we will bump panes that overlap
1059 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1061 int amount
= positions
[pane_i
] - offset
;
1065 positions
[pane_i
] += -amount
;
1067 offset
+= sizes
[pane_i
];
1072 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1075 wxDockUIPartArray
& uiparts
,
1079 wxSizerItem
* sizer_item
;
1081 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1082 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1083 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1084 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1086 // find out the orientation of the item (orientation for panes
1087 // is the same as the dock's orientation)
1089 if (dock
.IsHorizontal())
1090 orientation
= wxHORIZONTAL
;
1092 orientation
= wxVERTICAL
;
1094 // this variable will store the proportion
1095 // value that the pane will receive
1096 int pane_proportion
= pane
.dock_proportion
;
1098 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1099 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1101 if (pane
.HasGripper())
1103 if (pane
.HasGripperTop())
1104 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1106 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1108 part
.type
= wxDockUIPart::typeGripper
;
1112 part
.orientation
= orientation
;
1113 part
.cont_sizer
= horz_pane_sizer
;
1114 part
.sizer_item
= sizer_item
;
1118 if (pane
.HasCaption())
1120 // create the caption sizer
1121 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1123 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1125 part
.type
= wxDockUIPart::typeCaption
;
1129 part
.orientation
= orientation
;
1130 part
.cont_sizer
= vert_pane_sizer
;
1131 part
.sizer_item
= sizer_item
;
1132 int caption_part_idx
= uiparts
.GetCount();
1135 // add pane buttons to the caption
1136 int i
, button_count
;
1137 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1138 i
< button_count
; ++i
)
1140 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1142 sizer_item
= caption_sizer
->Add(pane_button_size
,
1146 part
.type
= wxDockUIPart::typePaneButton
;
1149 part
.button
= &button
;
1150 part
.orientation
= orientation
;
1151 part
.cont_sizer
= caption_sizer
;
1152 part
.sizer_item
= sizer_item
;
1156 // add the caption sizer
1157 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1159 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1162 // add the pane window itself
1165 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1169 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1170 // Don't do this because it breaks the pane size in floating windows
1171 // vert_pane_sizer->SetItemMinSize(pane.window, 1, 1);
1174 part
.type
= wxDockUIPart::typePane
;
1178 part
.orientation
= orientation
;
1179 part
.cont_sizer
= vert_pane_sizer
;
1180 part
.sizer_item
= sizer_item
;
1184 // determine if the pane should have a minimum size; if the pane is
1185 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1186 // if the pane.min_size is set, we must use that value as well
1188 wxSize min_size
= pane
.min_size
;
1191 if (min_size
== wxDefaultSize
)
1193 min_size
= pane
.best_size
;
1194 pane_proportion
= 0;
1198 if (min_size
!= wxDefaultSize
)
1200 vert_pane_sizer
->SetItemMinSize(
1201 vert_pane_sizer
->GetChildren().GetCount()-1,
1202 min_size
.x
, min_size
.y
);
1206 // add the verticle sizer (caption, pane window) to the
1207 // horizontal sizer (gripper, verticle sizer)
1208 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1210 // finally, add the pane sizer to the dock sizer
1212 if (pane
.HasBorder())
1214 // allowing space for the pane's border
1215 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1216 wxEXPAND
| wxALL
, pane_border_size
);
1218 part
.type
= wxDockUIPart::typePaneBorder
;
1222 part
.orientation
= orientation
;
1223 part
.cont_sizer
= cont
;
1224 part
.sizer_item
= sizer_item
;
1229 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1233 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1235 wxDockUIPartArray
& uiparts
,
1238 wxSizerItem
* sizer_item
;
1241 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1242 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1244 // resizable bottom and right docks have a sash before them
1245 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1246 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1248 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1250 part
.type
= wxDockUIPart::typeDockSizer
;
1251 part
.orientation
= orientation
;
1255 part
.cont_sizer
= cont
;
1256 part
.sizer_item
= sizer_item
;
1260 // create the sizer for the dock
1261 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1263 // add each pane to the dock
1264 int pane_i
, pane_count
= dock
.panes
.GetCount();
1268 wxArrayInt pane_positions
, pane_sizes
;
1270 // figure out the real pane positions we will
1271 // use, without modifying the each pane's pane_pos member
1272 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1275 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1277 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1278 int pane_pos
= pane_positions
.Item(pane_i
);
1280 int amount
= pane_pos
- offset
;
1283 if (dock
.IsVertical())
1284 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1286 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1288 part
.type
= wxDockUIPart::typeBackground
;
1292 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1293 part
.cont_sizer
= dock_sizer
;
1294 part
.sizer_item
= sizer_item
;
1300 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1302 offset
+= pane_sizes
.Item(pane_i
);
1305 // at the end add a very small stretchable background area
1306 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1308 part
.type
= wxDockUIPart::typeBackground
;
1312 part
.orientation
= orientation
;
1313 part
.cont_sizer
= dock_sizer
;
1314 part
.sizer_item
= sizer_item
;
1319 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1321 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1323 // if this is not the first pane being added,
1324 // we need to add a pane sizer
1327 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1329 part
.type
= wxDockUIPart::typePaneSizer
;
1331 part
.pane
= dock
.panes
.Item(pane_i
-1);
1333 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1334 part
.cont_sizer
= dock_sizer
;
1335 part
.sizer_item
= sizer_item
;
1339 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1343 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1344 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1346 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1348 part
.type
= wxDockUIPart::typeDock
;
1352 part
.orientation
= orientation
;
1353 part
.cont_sizer
= cont
;
1354 part
.sizer_item
= sizer_item
;
1357 if (dock
.IsHorizontal())
1358 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1360 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1362 // top and left docks have a sash after them
1363 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1364 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1366 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1368 part
.type
= wxDockUIPart::typeDockSizer
;
1372 part
.orientation
= orientation
;
1373 part
.cont_sizer
= cont
;
1374 part
.sizer_item
= sizer_item
;
1379 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1380 wxDockInfoArray
& docks
,
1381 wxDockUIPartArray
& uiparts
,
1384 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1386 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1387 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1388 wxSize cli_size
= m_frame
->GetClientSize();
1389 int i
, dock_count
, pane_count
;
1392 // empty all docks out
1393 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1394 docks
.Item(i
).panes
.Empty();
1396 // iterate through all known panes, filing each
1397 // of them into the appropriate dock. If the
1398 // pane does not exist in the dock, add it
1399 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1401 wxPaneInfo
& p
= panes
.Item(i
);
1403 // find any docks in this layer
1405 wxDockInfoPtrArray arr
;
1406 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1408 if (arr
.GetCount() > 0)
1414 // dock was not found, so we need to create a new one
1416 d
.dock_direction
= p
.dock_direction
;
1417 d
.dock_layer
= p
.dock_layer
;
1418 d
.dock_row
= p
.dock_row
;
1420 dock
= &docks
.Last();
1424 if (p
.IsDocked() && p
.IsShown())
1426 // remove the pane from any existing docks except this one
1427 RemovePaneFromDocks(docks
, p
, dock
);
1429 // pane needs to be added to the dock,
1430 // if it doesn't already exist
1431 if (!FindPaneInDock(*dock
, p
.window
))
1432 dock
->panes
.Add(&p
);
1436 // remove the pane from any existing docks
1437 RemovePaneFromDocks(docks
, p
);
1442 // remove any empty docks
1443 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1445 if (docks
.Item(i
).panes
.GetCount() == 0)
1449 // configure the docks further
1450 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1452 wxDockInfo
& dock
= docks
.Item(i
);
1453 int j
, dock_pane_count
= dock
.panes
.GetCount();
1455 // sort the dock pane array by the pane's
1456 // dock position (dock_pos), in ascending order
1457 dock
.panes
.Sort(PaneSortFunc
);
1459 // for newly created docks, set up their initial size
1464 for (j
= 0; j
< dock_pane_count
; ++j
)
1466 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1467 wxSize pane_size
= pane
.best_size
;
1468 if (pane_size
== wxDefaultSize
)
1469 pane_size
= pane
.min_size
;
1470 if (pane_size
== wxDefaultSize
)
1471 pane_size
= pane
.window
->GetSize();
1473 if (dock
.IsHorizontal())
1474 size
= wxMax(pane_size
.y
, size
);
1476 size
= wxMax(pane_size
.x
, size
);
1479 // add space for the border (two times), but only
1480 // if at least one pane inside the dock has a pane border
1481 for (j
= 0; j
< dock_pane_count
; ++j
)
1483 if (dock
.panes
.Item(j
)->HasBorder())
1485 size
+= (pane_border_size
*2);
1490 // if pane is on the top or bottom, add the caption height,
1491 // but only if at least one pane inside the dock has a caption
1492 if (dock
.IsHorizontal())
1494 for (j
= 0; j
< dock_pane_count
; ++j
)
1496 if (dock
.panes
.Item(j
)->HasCaption())
1498 size
+= caption_size
;
1504 // new dock's size may not be more than 1/3 of the frame size
1505 if (dock
.IsHorizontal())
1506 size
= wxMin(size
, cli_size
.y
/3);
1508 size
= wxMin(size
, cli_size
.x
/3);
1516 // determine the dock's minimum size
1517 bool plus_border
= false;
1518 bool plus_caption
= false;
1519 int dock_min_size
= 0;
1520 for (j
= 0; j
< dock_pane_count
; ++j
)
1522 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1523 if (pane
.min_size
!= wxDefaultSize
)
1525 if (pane
.HasBorder())
1527 if (pane
.HasCaption())
1528 plus_caption
= true;
1529 if (dock
.IsHorizontal())
1531 if (pane
.min_size
.y
> dock_min_size
)
1532 dock_min_size
= pane
.min_size
.y
;
1536 if (pane
.min_size
.x
> dock_min_size
)
1537 dock_min_size
= pane
.min_size
.x
;
1543 dock_min_size
+= (pane_border_size
*2);
1544 if (plus_caption
&& dock
.IsHorizontal())
1545 dock_min_size
+= (caption_size
);
1547 dock
.min_size
= dock_min_size
;
1550 // if the pane's current size is less than it's
1551 // minimum, increase the dock's size to it's minimum
1552 if (dock
.size
< dock
.min_size
)
1553 dock
.size
= dock
.min_size
;
1556 // determine the dock's mode (fixed or proportional);
1557 // determine whether the dock has only toolbars
1558 bool action_pane_marked
= false;
1560 dock
.toolbar
= true;
1561 for (j
= 0; j
< dock_pane_count
; ++j
)
1563 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1564 if (!pane
.IsFixed())
1566 if (!pane
.IsToolbar())
1567 dock
.toolbar
= false;
1568 if (pane
.state
& wxPaneInfo::actionPane
)
1569 action_pane_marked
= true;
1573 // if the dock mode is proportional and not fixed-pixel,
1574 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1575 // e.g. remove gaps like 1, 2, 30, 500
1578 for (j
= 0; j
< dock_pane_count
; ++j
)
1580 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1585 // if the dock mode is fixed, and none of the panes
1586 // are being moved right now, make sure the panes
1587 // do not overlap each other. If they do, we will
1588 // adjust the panes' positions
1589 if (dock
.fixed
&& !action_pane_marked
)
1591 wxArrayInt pane_positions
, pane_sizes
;
1592 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1595 for (j
= 0; j
< dock_pane_count
; ++j
)
1597 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1598 pane
.dock_pos
= pane_positions
[j
];
1600 int amount
= pane
.dock_pos
- offset
;
1604 pane
.dock_pos
+= -amount
;
1606 offset
+= pane_sizes
[j
];
1611 // discover the maximum dock layer
1613 for (i
= 0; i
< dock_count
; ++i
)
1614 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1617 // clear out uiparts
1620 // create a bunch of box sizers,
1621 // from the innermost level outwards.
1622 wxSizer
* cont
= NULL
;
1623 wxSizer
* middle
= NULL
;
1627 for (layer
= 0; layer
<= max_layer
; ++layer
)
1629 wxDockInfoPtrArray arr
;
1631 // find any docks in this layer
1632 FindDocks(docks
, -1, layer
, -1, arr
);
1634 // if there aren't any, skip to the next layer
1638 wxSizer
* old_cont
= cont
;
1640 // create a container which will hold this layer's
1641 // docks (top, bottom, left, right)
1642 cont
= new wxBoxSizer(wxVERTICAL
);
1645 // find any top docks in this layer
1646 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1647 RenumberDockRows(arr
);
1650 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1651 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1655 // fill out the middle layer (which consists
1656 // of left docks, content area and right docks)
1658 middle
= new wxBoxSizer(wxHORIZONTAL
);
1660 // find any left docks in this layer
1661 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1662 RenumberDockRows(arr
);
1665 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1666 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1669 // add content dock (or previous layer's sizer
1673 // find any center docks
1674 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1677 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1678 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1682 // there are no center docks, add a background area
1683 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1685 part
.type
= wxDockUIPart::typeBackground
;
1689 part
.cont_sizer
= middle
;
1690 part
.sizer_item
= sizer_item
;
1696 middle
->Add(old_cont
, 1, wxEXPAND
);
1699 // find any right docks in this layer
1700 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1701 RenumberDockRows(arr
);
1704 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1705 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1708 cont
->Add(middle
, 1, wxEXPAND
);
1712 // find any bottom docks in this layer
1713 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1714 RenumberDockRows(arr
);
1717 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1718 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1725 // no sizer available, because there are no docks,
1726 // therefore we will create a simple background area
1727 cont
= new wxBoxSizer(wxVERTICAL
);
1728 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1730 part
.type
= wxDockUIPart::typeBackground
;
1734 part
.cont_sizer
= middle
;
1735 part
.sizer_item
= sizer_item
;
1739 container
->Add(cont
, 1, wxEXPAND
);
1744 // Update() updates the layout. Whenever changes are made to
1745 // one or more panes, this function should be called. It is the
1746 // external entry point for running the layout engine.
1748 void wxFrameManager::Update()
1751 int i
, pane_count
= m_panes
.GetCount();
1753 // delete old sizer first
1754 m_frame
->SetSizer(NULL
);
1756 // destroy floating panes which have been
1757 // redocked or are becoming non-floating
1758 for (i
= 0; i
< pane_count
; ++i
)
1760 wxPaneInfo
& p
= m_panes
.Item(i
);
1762 if (!p
.IsFloating() && p
.frame
)
1764 // because the pane is no longer in a floating, we need to
1765 // reparent it to m_frame and destroy the floating frame
1768 p
.window
->SetSize(1,1);
1769 p
.frame
->Show(false);
1771 // reparent to m_frame and destroy the pane
1772 p
.window
->Reparent(m_frame
);
1773 p
.frame
->SetSizer(NULL
);
1780 // create a layout for all of the panes
1781 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
1783 // hide or show panes as necessary,
1784 // and float panes as necessary
1785 for (i
= 0; i
< pane_count
; ++i
)
1787 wxPaneInfo
& p
= m_panes
.Item(i
);
1791 if (p
.frame
== NULL
)
1793 // we need to create a frame for this
1794 // pane, which has recently been floated
1795 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
1799 // on MSW and Mac, if the owner desires transparent dragging, and
1800 // the dragging is happening right now, then the floating
1801 // window should have this style by default
1802 if (m_action
== actionDragFloatingPane
&&
1803 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
1804 MakeWindowTransparent(frame
, 150);
1806 frame
->SetPaneWindow(p
);
1816 // frame already exists, make sure it's position
1817 // and size reflect the information in wxPaneInfo
1818 if (p
.frame
->GetPosition() != p
.floating_pos
)
1820 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
1821 wxDefaultCoord
, wxDefaultCoord
,
1822 wxSIZE_USE_EXISTING
);
1823 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
1826 p
.frame
->Show(p
.IsShown());
1831 p
.window
->Show(p
.IsShown());
1834 // if "active panes" are no longer allowed, clear
1835 // any optionActive values from the pane states
1836 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
1838 p
.state
&= ~wxPaneInfo::optionActive
;
1843 // keep track of the old window rectangles so we can
1844 // refresh those windows whose rect has changed
1845 wxAuiRectArray old_pane_rects
;
1846 for (i
= 0; i
< pane_count
; ++i
)
1849 wxPaneInfo
& p
= m_panes
.Item(i
);
1851 if (p
.window
&& p
.IsShown() && p
.IsDocked())
1854 old_pane_rects
.Add(r
);
1860 // apply the new sizer
1861 m_frame
->SetSizer(sizer
);
1862 m_frame
->SetAutoLayout(false);
1867 // now that the frame layout is done, we need to check
1868 // the new pane rectangles against the old rectangles that
1869 // we saved a few lines above here. If the rectangles have
1870 // changed, the corresponding panes must also be updated
1871 for (i
= 0; i
< pane_count
; ++i
)
1873 wxPaneInfo
& p
= m_panes
.Item(i
);
1874 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
1876 if (p
.rect
!= old_pane_rects
[i
])
1878 p
.window
->Refresh();
1887 // set frame's minimum size
1890 // N.B. More work needs to be done on frame minimum sizes;
1891 // this is some intresting code that imposes the minimum size,
1892 // but we may want to include a more flexible mechanism or
1893 // options for multiple minimum-size modes, e.g. strict or lax
1894 wxSize min_size = sizer->GetMinSize();
1895 wxSize frame_size = m_frame->GetSize();
1896 wxSize client_size = m_frame->GetClientSize();
1898 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
1899 min_size.y+frame_size.y-client_size.y );
1901 m_frame->SetMinSize(minframe_size);
1903 if (frame_size.x < minframe_size.x ||
1904 frame_size.y < minframe_size.y)
1905 sizer->Fit(m_frame);
1910 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
1911 // on the frame's main sizer, then measures all the various UI items
1912 // and updates their internal rectangles. This should always be called
1913 // instead of calling m_frame->Layout() directly
1915 void wxFrameManager::DoFrameLayout()
1920 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1922 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1924 // get the rectangle of the UI part
1925 // originally, this code looked like this:
1926 // part.rect = wxRect(part.sizer_item->GetPosition(),
1927 // part.sizer_item->GetSize());
1928 // this worked quite well, with one exception: the mdi
1929 // client window had a "deferred" size variable
1930 // that returned the wrong size. It looks like
1931 // a bug in wx, because the former size of the window
1932 // was being returned. So, we will retrieve the part's
1933 // rectangle via other means
1936 part
.rect
= part
.sizer_item
->GetRect();
1937 int flag
= part
.sizer_item
->GetFlag();
1938 int border
= part
.sizer_item
->GetBorder();
1941 part
.rect
.y
-= border
;
1942 part
.rect
.height
+= border
;
1946 part
.rect
.x
-= border
;
1947 part
.rect
.width
+= border
;
1949 if (flag
& wxBOTTOM
)
1950 part
.rect
.height
+= border
;
1952 part
.rect
.width
+= border
;
1955 if (part
.type
== wxDockUIPart::typeDock
)
1956 part
.dock
->rect
= part
.rect
;
1957 if (part
.type
== wxDockUIPart::typePane
)
1958 part
.pane
->rect
= part
.rect
;
1962 // GetPanePart() looks up the pane the pane border UI part (or the regular
1963 // pane part if there is no border). This allows the caller to get the exact
1964 // rectangle of the pane in question, including decorations like
1965 // caption and border (if any).
1967 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
1970 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1972 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1973 if (part
.type
== wxDockUIPart::typePaneBorder
&&
1974 part
.pane
&& part
.pane
->window
== wnd
)
1977 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1979 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1980 if (part
.type
== wxDockUIPart::typePane
&&
1981 part
.pane
&& part
.pane
->window
== wnd
)
1989 // GetDockPixelOffset() is an internal function which returns
1990 // a dock's offset in pixels from the left side of the window
1991 // (for horizontal docks) or from the top of the window (for
1992 // vertical docks). This value is necessary for calculating
1993 // fixel-pane/toolbar offsets when they are dragged.
1995 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
1997 // the only way to accurately calculate the dock's
1998 // offset is to actually run a theoretical layout
2000 int i
, part_count
, dock_count
;
2001 wxDockInfoArray docks
;
2002 wxPaneInfoArray panes
;
2003 wxDockUIPartArray uiparts
;
2004 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2007 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2008 wxSize client_size
= m_frame
->GetClientSize();
2009 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2012 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2014 wxDockUIPart
& part
= uiparts
.Item(i
);
2015 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2016 part
.sizer_item
->GetSize());
2017 if (part
.type
== wxDockUIPart::typeDock
)
2018 part
.dock
->rect
= part
.rect
;
2023 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2025 wxDockInfo
& dock
= docks
.Item(i
);
2026 if (test
.dock_direction
== dock
.dock_direction
&&
2027 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2029 if (dock
.IsVertical())
2041 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2042 // if a dock operation is allowed, the new dock position is copied into
2043 // the target info. If the operation was allowed, the function returns true.
2045 static bool ProcessDockResult(wxPaneInfo
& target
,
2046 const wxPaneInfo
& new_pos
)
2048 bool allowed
= false;
2049 switch (new_pos
.dock_direction
)
2051 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2052 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2053 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2054 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2064 // DoDrop() is an important function. It basically takes a mouse position,
2065 // and determines where the pane's new position would be. If the pane is to be
2066 // dropped, it performs the drop operation using the specified dock and pane
2067 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2068 // scenario can be performed, giving precise coordinates for drop hints.
2069 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2070 // as parameters, the changes will be made to the main state arrays
2072 const int auiInsertRowPixels
= 10;
2073 const int auiNewRowPixels
= 40;
2074 const int auiLayerInsertPixels
= 40;
2075 const int auiLayerInsertOffset
= 5;
2077 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2078 wxPaneInfoArray
& panes
,
2081 const wxPoint
& offset
)
2083 wxSize cli_size
= m_frame
->GetClientSize();
2085 wxPaneInfo drop
= target
;
2088 // The result should always be shown
2092 // Check to see if the pane has been dragged outside of the window
2093 // (or near to the outside of the window), if so, dock it along the edge
2096 int layer_insert_offset
= auiLayerInsertOffset
;
2097 if (target
.IsToolbar())
2098 layer_insert_offset
= 0;
2100 if (pt
.x
< layer_insert_offset
&&
2101 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2103 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2104 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2105 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2109 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2110 return ProcessDockResult(target
, drop
);
2112 else if (pt
.y
< layer_insert_offset
&&
2113 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2115 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2116 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2117 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2121 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2122 return ProcessDockResult(target
, drop
);
2124 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2125 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2127 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2128 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2129 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2130 drop
.Dock().Right().
2133 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2134 return ProcessDockResult(target
, drop
);
2136 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2137 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2139 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2140 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2141 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2142 drop
.Dock().Bottom().
2145 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2146 return ProcessDockResult(target
, drop
);
2150 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2153 if (drop
.IsToolbar())
2155 if (!part
|| !part
->dock
)
2159 // calculate the offset from where the dock begins
2160 // to the point where the user dropped the pane
2161 int dock_drop_offset
= 0;
2162 if (part
->dock
->IsHorizontal())
2163 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2165 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2168 // toolbars may only be moved in and to fixed-pane docks,
2169 // otherwise we will try to float the pane. Also, the pane
2170 // should float if being dragged over center pane windows
2171 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2173 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2174 (drop
.IsFloatable() ||
2175 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2176 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2181 return ProcessDockResult(target
, drop
);
2185 Direction(part
->dock
->dock_direction
).
2186 Layer(part
->dock
->dock_layer
).
2187 Row(part
->dock
->dock_row
).
2188 Position(dock_drop_offset
);
2191 ((pt
.y
< part
->dock
->rect
.y
+ 2) && part
->dock
->IsHorizontal()) ||
2192 ((pt
.x
< part
->dock
->rect
.x
+ 2) && part
->dock
->IsVertical())
2193 ) && part
->dock
->panes
.GetCount() > 1)
2195 int row
= drop
.dock_row
;
2196 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2197 part
->dock
->dock_layer
,
2198 part
->dock
->dock_row
);
2199 drop
.dock_row
= row
;
2203 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2204 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2205 ) && part
->dock
->panes
.GetCount() > 1)
2207 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2208 part
->dock
->dock_layer
,
2209 part
->dock
->dock_row
+1);
2210 drop
.dock_row
= part
->dock
->dock_row
+1;
2213 return ProcessDockResult(target
, drop
);
2222 if (part
->type
== wxDockUIPart::typePaneBorder
||
2223 part
->type
== wxDockUIPart::typeCaption
||
2224 part
->type
== wxDockUIPart::typeGripper
||
2225 part
->type
== wxDockUIPart::typePaneButton
||
2226 part
->type
== wxDockUIPart::typePane
||
2227 part
->type
== wxDockUIPart::typePaneSizer
||
2228 part
->type
== wxDockUIPart::typeDockSizer
||
2229 part
->type
== wxDockUIPart::typeBackground
)
2231 if (part
->type
== wxDockUIPart::typeDockSizer
)
2233 if (part
->dock
->panes
.GetCount() != 1)
2235 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2242 // If a normal frame is being dragged over a toolbar, insert it
2243 // along the edge under the toolbar, but over all other panes.
2244 // (this could be done much better, but somehow factoring this
2245 // calculation with the one at the beginning of this function)
2246 if (part
->dock
&& part
->dock
->toolbar
)
2250 switch (part
->dock
->dock_direction
)
2252 case wxAUI_DOCK_LEFT
:
2253 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2254 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2255 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2257 case wxAUI_DOCK_TOP
:
2258 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2259 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2260 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2262 case wxAUI_DOCK_RIGHT
:
2263 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2264 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2265 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2267 case wxAUI_DOCK_BOTTOM
:
2268 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2269 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2270 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2274 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2277 Direction(part
->dock
->dock_direction
).
2278 Layer(layer
).Row(0).Position(0);
2279 return ProcessDockResult(target
, drop
);
2286 part
= GetPanePart(part
->pane
->window
);
2290 bool insert_dock_row
= false;
2291 int insert_row
= part
->pane
->dock_row
;
2292 int insert_dir
= part
->pane
->dock_direction
;
2293 int insert_layer
= part
->pane
->dock_layer
;
2295 switch (part
->pane
->dock_direction
)
2297 case wxAUI_DOCK_TOP
:
2298 if (pt
.y
>= part
->rect
.y
&&
2299 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2300 insert_dock_row
= true;
2302 case wxAUI_DOCK_BOTTOM
:
2303 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2304 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2305 insert_dock_row
= true;
2307 case wxAUI_DOCK_LEFT
:
2308 if (pt
.x
>= part
->rect
.x
&&
2309 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2310 insert_dock_row
= true;
2312 case wxAUI_DOCK_RIGHT
:
2313 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2314 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2315 insert_dock_row
= true;
2317 case wxAUI_DOCK_CENTER
:
2319 // "new row pixels" will be set to the default, but
2320 // must never exceed 20% of the window size
2321 int new_row_pixels_x
= auiNewRowPixels
;
2322 int new_row_pixels_y
= auiNewRowPixels
;
2324 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2325 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2327 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2328 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2331 // determine if the mouse pointer is in a location that
2332 // will cause a new row to be inserted. The hot spot positions
2333 // are along the borders of the center pane
2336 insert_dock_row
= true;
2337 if (pt
.x
>= part
->rect
.x
&&
2338 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2339 insert_dir
= wxAUI_DOCK_LEFT
;
2341 if (pt
.y
>= part
->rect
.y
&&
2342 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2343 insert_dir
= wxAUI_DOCK_TOP
;
2345 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2346 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2347 insert_dir
= wxAUI_DOCK_RIGHT
;
2349 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2350 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2351 insert_dir
= wxAUI_DOCK_BOTTOM
;
2355 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2359 if (insert_dock_row
)
2361 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2362 drop
.Dock().Direction(insert_dir
).
2363 Layer(insert_layer
).
2366 return ProcessDockResult(target
, drop
);
2369 // determine the mouse offset and the pane size, both in the
2370 // direction of the dock itself, and perpendicular to the dock
2374 if (part
->orientation
== wxVERTICAL
)
2376 offset
= pt
.y
- part
->rect
.y
;
2377 size
= part
->rect
.GetHeight();
2381 offset
= pt
.x
- part
->rect
.x
;
2382 size
= part
->rect
.GetWidth();
2385 int drop_position
= part
->pane
->dock_pos
;
2387 // if we are in the top/left part of the pane,
2388 // insert the pane before the pane being hovered over
2389 if (offset
<= size
/2)
2391 drop_position
= part
->pane
->dock_pos
;
2393 part
->pane
->dock_direction
,
2394 part
->pane
->dock_layer
,
2395 part
->pane
->dock_row
,
2396 part
->pane
->dock_pos
);
2399 // if we are in the bottom/right part of the pane,
2400 // insert the pane before the pane being hovered over
2401 if (offset
> size
/2)
2403 drop_position
= part
->pane
->dock_pos
+1;
2405 part
->pane
->dock_direction
,
2406 part
->pane
->dock_layer
,
2407 part
->pane
->dock_row
,
2408 part
->pane
->dock_pos
+1);
2412 Direction(part
->dock
->dock_direction
).
2413 Layer(part
->dock
->dock_layer
).
2414 Row(part
->dock
->dock_row
).
2415 Position(drop_position
);
2416 return ProcessDockResult(target
, drop
);
2423 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2425 if (!m_hint_wnd
|| m_hint_fadeamt
>= 50)
2427 m_hint_fadetimer
.Stop();
2431 m_hint_fadeamt
+= 5;
2432 MakeWindowTransparent(m_hint_wnd
, m_hint_fadeamt
);
2435 void wxFrameManager::ShowHint(const wxRect
& rect
)
2437 // First, determine if the operating system can handle transparency.
2438 // Transparency is available on Win2000 and above
2440 static int os_type
= -1;
2441 static int ver_major
= -1;
2444 os_type
= ::wxGetOsVersion(&ver_major
);
2446 // If the transparent flag is set, and the OS supports it,
2447 // go ahead and use a transparent hint
2449 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0
2451 && os_type
== wxWINDOWS_NT
&& ver_major
>= 5
2455 if (m_last_hint
== rect
)
2459 int initial_fade
= 50;
2460 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2463 if (m_hint_wnd
== NULL
)
2465 wxPoint pt
= rect
.GetPosition();
2466 wxSize size
= rect
.GetSize();
2467 #if defined(__WXMSW__)
2468 m_hint_wnd
= new wxFrame(m_frame
, -1, wxEmptyString
, pt
, size
,
2469 wxFRAME_TOOL_WINDOW
|
2470 wxFRAME_FLOAT_ON_PARENT
|
2471 wxFRAME_NO_TASKBAR
|
2474 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2475 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
2476 #elif defined(__WXMAC__)
2477 // Using a miniframe with float and tool styles keeps the parent
2478 // frame activated and highlighted as such...
2479 m_hint_wnd
= new wxMiniFrame(m_frame
, -1, wxEmptyString
, pt
, size
,
2480 wxFRAME_FLOAT_ON_PARENT
2481 | wxFRAME_TOOL_WINDOW
2484 // Can't set the bg colour of a Frame in wxMac
2485 wxPanel
* p
= new wxPanel(m_hint_wnd
);
2487 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
2488 // color that is really hard to see, especially transparent.
2489 // Until a better system color is decided upon we'll just use
2491 p
->SetBackgroundColour(*wxBLUE
);
2498 // if we are dragging a floating pane, set the focus
2499 // back to that floating pane (otherwise it becomes unfocused)
2500 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2501 m_action_window
->SetFocus();
2506 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2507 m_hint_wnd
->SetSize(rect
);
2508 m_hint_wnd
->Raise();
2511 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2513 // start fade in timer
2515 m_hint_fadetimer
.SetOwner(this, 101);
2516 m_hint_fadetimer
.Start(5);
2522 if (m_last_hint
!= rect
)
2524 // remove the last hint rectangle
2530 wxScreenDC screendc
;
2531 wxRegion
clip(1, 1, 10000, 10000);
2533 // clip all floating windows, so we don't draw over them
2535 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2537 wxPaneInfo
& pane
= m_panes
.Item(i
);
2539 if (pane
.IsFloating() &&
2540 pane
.frame
->IsShown())
2542 wxRect rect
= pane
.frame
->GetRect();
2544 // wxGTK returns the client size, not the whole frame size
2550 clip
.Subtract(rect
);
2554 screendc
.SetClippingRegion(clip
);
2556 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2557 wxBrush
brush(stipple
);
2558 screendc
.SetBrush(brush
);
2559 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2561 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2562 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2563 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2564 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2567 void wxFrameManager::HideHint()
2569 // hides a transparent window hint, if there is one
2572 MakeWindowTransparent(m_hint_wnd
, 0);
2573 m_hint_fadetimer
.Stop();
2574 m_last_hint
= wxRect();
2578 // hides a painted hint by redrawing the frame window
2579 if (!m_last_hint
.IsEmpty())
2583 m_last_hint
= wxRect();
2589 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2590 // determine the exact position the pane would be at were if dropped. If
2591 // the pame would indeed become docked at the specified drop point,
2592 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2593 // "pane_window" is the window pointer of the pane being dragged, pt is
2594 // the mouse position, in client coordinates
2595 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2597 const wxPoint
& offset
)
2601 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2602 // we will create a new temporary layout and then measure the resulting
2603 // rectangle; we will create a copy of the docking structures (m_dock)
2604 // so that we don't modify the real thing on screen
2606 int i
, pane_count
, part_count
;
2607 wxDockInfoArray docks
;
2608 wxPaneInfoArray panes
;
2609 wxDockUIPartArray uiparts
;
2610 wxPaneInfo hint
= GetPane(pane_window
);
2611 hint
.name
= wxT("__HINT__");
2616 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2618 // remove any pane already there which bears the same window;
2619 // this happens when you are moving a pane around in a dock
2620 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2622 if (panes
.Item(i
).window
== pane_window
)
2624 RemovePaneFromDocks(docks
, panes
.Item(i
));
2630 // find out where the new pane would be
2631 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2639 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2640 wxSize client_size
= m_frame
->GetClientSize();
2641 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2644 for (i
= 0, part_count
= uiparts
.GetCount();
2645 i
< part_count
; ++i
)
2647 wxDockUIPart
& part
= uiparts
.Item(i
);
2649 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2650 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2652 rect
= wxRect(part
.sizer_item
->GetPosition(),
2653 part
.sizer_item
->GetSize());
2666 // actually show the hint rectangle on the screen
2667 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2671 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2673 // try to find the pane
2674 wxPaneInfo
& pane
= GetPane(wnd
);
2675 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2677 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2678 MakeWindowTransparent(pane
.frame
, 150);
2681 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
)
2683 // try to find the pane
2684 wxPaneInfo
& pane
= GetPane(wnd
);
2685 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2687 wxPoint pt
= ::wxGetMousePosition();
2688 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2690 // calculate the offset from the upper left-hand corner
2691 // of the frame to the mouse pointer
2692 wxPoint frame_pos
= pane
.frame
->GetPosition();
2693 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2695 // no hint for toolbar floating windows
2696 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
2698 if (m_action
== actionDragFloatingPane
)
2700 wxDockInfoArray docks
;
2701 wxPaneInfoArray panes
;
2702 wxDockUIPartArray uiparts
;
2703 wxPaneInfo hint
= pane
;
2705 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2707 // find out where the new pane would be
2708 if (!DoDrop(docks
, panes
, hint
, client_pt
))
2710 if (hint
.IsFloating())
2714 m_action
= actionDragToolbarPane
;
2715 m_action_window
= pane
.window
;
2724 // if a key modifier is pressed while dragging the frame,
2725 // don't dock the window
2726 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2733 DrawHintRect(wnd
, client_pt
, action_offset
);
2736 // this cleans up some screen artifacts that are caused on GTK because
2737 // we aren't getting the exact size of the window (see comment
2747 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
)
2749 // try to find the pane
2750 wxPaneInfo
& pane
= GetPane(wnd
);
2751 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2753 wxPoint pt
= ::wxGetMousePosition();
2754 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2756 // calculate the offset from the upper left-hand corner
2757 // of the frame to the mouse pointer
2758 wxPoint frame_pos
= pane
.frame
->GetPosition();
2759 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2762 // if a key modifier is pressed while dragging the frame,
2763 // don't dock the window
2764 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2771 // do the drop calculation
2772 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
2774 // if the pane is still floating, update it's floating
2775 // position (that we store)
2776 if (pane
.IsFloating())
2778 pane
.floating_pos
= pane
.frame
->GetPosition();
2780 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2781 MakeWindowTransparent(pane
.frame
, 255);
2789 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
2791 // try to find the pane
2792 wxPaneInfo
& pane
= GetPane(wnd
);
2793 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2795 pane
.floating_size
= size
;
2799 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
2801 // try to find the pane
2802 wxPaneInfo
& pane
= GetPane(wnd
);
2803 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2806 // fire pane close event
2807 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
2809 e
.SetCanVeto(evt
.CanVeto());
2819 // reparent the pane window back to us and
2820 // prepare the frame window for destruction
2821 pane
.window
->Show(false);
2822 pane
.window
->Reparent(m_frame
);
2830 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
2832 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
2834 // try to find the pane
2835 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
2837 SetActivePane(m_panes
, wnd
);
2842 // Render() draws all of the pane captions, sashes,
2843 // backgrounds, captions, grippers, pane borders and buttons.
2844 // It renders the entire user interface.
2846 void wxFrameManager::Render(wxDC
* dc
)
2852 for (i
= 0, part_count
= m_uiparts
.GetCount();
2853 i
< part_count
; ++i
)
2855 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2857 // don't draw hidden pane items
2858 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
2863 case wxDockUIPart::typeDockSizer
:
2864 case wxDockUIPart::typePaneSizer
:
2865 m_art
->DrawSash(*dc
, part
.orientation
, part
.rect
);
2867 case wxDockUIPart::typeBackground
:
2868 m_art
->DrawBackground(*dc
, part
.orientation
, part
.rect
);
2870 case wxDockUIPart::typeCaption
:
2871 m_art
->DrawCaption(*dc
, part
.pane
->caption
, part
.rect
, *part
.pane
);
2873 case wxDockUIPart::typeGripper
:
2874 m_art
->DrawGripper(*dc
, part
.rect
, *part
.pane
);
2876 case wxDockUIPart::typePaneBorder
:
2877 m_art
->DrawBorder(*dc
, part
.rect
, *part
.pane
);
2879 case wxDockUIPart::typePaneButton
:
2880 m_art
->DrawPaneButton(*dc
, part
.button
->button_id
,
2881 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
2887 void wxFrameManager::Repaint(wxDC
* dc
)
2892 m_frame
->Refresh() ;
2898 m_frame
->GetClientSize(&w
, &h
);
2900 // figure out which dc to use; if one
2901 // has been specified, use it, otherwise
2903 wxClientDC
* client_dc
= NULL
;
2906 client_dc
= new wxClientDC(m_frame
);
2910 // if the frame has a toolbar, the client area
2911 // origin will not be (0,0).
2912 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2913 if (pt
.x
!= 0 || pt
.y
!= 0)
2914 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
2916 // render all the items
2919 // if we created a client_dc, delete it
2924 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2926 wxPaintDC
dc(m_frame
);
2930 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
2939 void wxFrameManager::OnSize(wxSizeEvent
& WXUNUSED(event
))
2949 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
2952 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2953 wxCursor cursor
= wxNullCursor
;
2957 if (part
->type
== wxDockUIPart::typeDockSizer
||
2958 part
->type
== wxDockUIPart::typePaneSizer
)
2960 // a dock may not be resized if it has a single
2961 // pane which is not resizable
2962 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
2963 part
->dock
->panes
.GetCount() == 1 &&
2964 part
->dock
->panes
.Item(0)->IsFixed())
2967 // panes that may not be resized do not get a sizing cursor
2968 if (part
->pane
&& part
->pane
->IsFixed())
2971 if (part
->orientation
== wxVERTICAL
)
2972 cursor
= wxCursor(wxCURSOR_SIZEWE
);
2974 cursor
= wxCursor(wxCURSOR_SIZENS
);
2976 else if (part
->type
== wxDockUIPart::typeGripper
)
2978 cursor
= wxCursor(wxCURSOR_SIZING
);
2982 event
.SetCursor(cursor
);
2987 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
2988 const wxMouseEvent
& event
)
2990 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
2992 int state
= wxAUI_BUTTON_STATE_NORMAL
;
2994 if (hit_test
== button_ui_part
)
2996 if (event
.LeftDown())
2997 state
= wxAUI_BUTTON_STATE_PRESSED
;
2999 state
= wxAUI_BUTTON_STATE_HOVER
;
3003 if (event
.LeftDown())
3004 state
= wxAUI_BUTTON_STATE_HOVER
;
3007 // now repaint the button with hover state
3008 wxClientDC
cdc(m_frame
);
3010 // if the frame has a toolbar, the client area
3011 // origin will not be (0,0).
3012 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3013 if (pt
.x
!= 0 || pt
.y
!= 0)
3014 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3016 m_art
->DrawPaneButton(cdc
,
3017 button_ui_part
->button
->button_id
,
3019 button_ui_part
->rect
,
3023 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
3025 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3028 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3031 if (part
->type
== wxDockUIPart::typeDockSizer
||
3032 part
->type
== wxDockUIPart::typePaneSizer
)
3034 // a dock may not be resized if it has a single
3035 // pane which is not resizable
3036 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3037 part
->dock
->panes
.GetCount() == 1 &&
3038 part
->dock
->panes
.Item(0)->IsFixed())
3041 // panes that may not be resized should be ignored here
3042 if (part
->pane
&& part
->pane
->IsFixed())
3045 m_action
= actionResize
;
3046 m_action_part
= part
;
3047 m_action_hintrect
= wxRect();
3048 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3049 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3050 event
.m_y
- part
->rect
.y
);
3051 m_frame
->CaptureMouse();
3053 else if (part
->type
== wxDockUIPart::typePaneButton
)
3055 m_action
= actionClickButton
;
3056 m_action_part
= part
;
3057 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3058 m_frame
->CaptureMouse();
3060 UpdateButtonOnScreen(part
, event
);
3062 else if (part
->type
== wxDockUIPart::typeCaption
||
3063 part
->type
== wxDockUIPart::typeGripper
)
3065 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3067 // set the caption as active
3068 SetActivePane(m_panes
, part
->pane
->window
);
3072 m_action
= actionClickCaption
;
3073 m_action_part
= part
;
3074 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3075 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3076 event
.m_y
- part
->rect
.y
);
3077 m_frame
->CaptureMouse();
3097 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3099 if (m_action
== actionResize
)
3101 m_frame
->ReleaseMouse();
3103 // get rid of the hint rectangle
3105 DrawResizeHint(dc
, m_action_hintrect
);
3107 // resize the dock or the pane
3108 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3110 wxRect
& rect
= m_action_part
->dock
->rect
;
3112 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3113 event
.m_y
- m_action_offset
.y
);
3115 switch (m_action_part
->dock
->dock_direction
)
3117 case wxAUI_DOCK_LEFT
:
3118 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3120 case wxAUI_DOCK_TOP
:
3121 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3123 case wxAUI_DOCK_RIGHT
:
3124 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3125 new_pos
.x
- m_action_part
->rect
.GetWidth();
3127 case wxAUI_DOCK_BOTTOM
:
3128 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3129 new_pos
.y
- m_action_part
->rect
.GetHeight();
3136 else if (m_action_part
&&
3137 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3139 wxDockInfo
& dock
= *m_action_part
->dock
;
3140 wxPaneInfo
& pane
= *m_action_part
->pane
;
3142 int total_proportion
= 0;
3143 int dock_pixels
= 0;
3144 int new_pixsize
= 0;
3146 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3147 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3148 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3150 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3151 event
.m_y
- m_action_offset
.y
);
3153 // determine the pane rectangle by getting the pane part
3154 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3155 wxASSERT_MSG(pane_part
,
3156 wxT("Pane border part not found -- shouldn't happen"));
3158 // determine the new pixel size that the user wants;
3159 // this will help us recalculate the pane's proportion
3160 if (dock
.IsHorizontal())
3161 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3163 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3165 // determine the size of the dock, based on orientation
3166 if (dock
.IsHorizontal())
3167 dock_pixels
= dock
.rect
.GetWidth();
3169 dock_pixels
= dock
.rect
.GetHeight();
3171 // determine the total proportion of all resizable panes,
3172 // and the total size of the dock minus the size of all
3174 int i
, dock_pane_count
= dock
.panes
.GetCount();
3175 int pane_position
= -1;
3176 for (i
= 0; i
< dock_pane_count
; ++i
)
3178 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3179 if (p
.window
== pane
.window
)
3182 // while we're at it, subtract the pane sash
3183 // width from the dock width, because this would
3184 // skew our proportion calculations
3186 dock_pixels
-= sash_size
;
3188 // also, the whole size (including decorations) of
3189 // all fixed panes must also be subtracted, because they
3190 // are not part of the proportion calculation
3193 if (dock
.IsHorizontal())
3194 dock_pixels
-= p
.best_size
.x
;
3196 dock_pixels
-= p
.best_size
.y
;
3200 total_proportion
+= p
.dock_proportion
;
3204 // find a pane in our dock to 'steal' space from or to 'give'
3205 // space to -- this is essentially what is done when a pane is
3206 // resized; the pane should usually be the first non-fixed pane
3207 // to the right of the action pane
3208 int borrow_pane
= -1;
3209 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3211 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3220 // demand that the pane being resized is found in this dock
3221 // (this assert really never should be raised)
3222 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3224 // prevent division by zero
3225 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3227 m_action
= actionNone
;
3231 // calculate the new proportion of the pane
3232 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3234 // default minimum size
3237 // check against the pane's minimum size, if specified. please note
3238 // that this is not enough to ensure that the minimum size will
3239 // not be violated, because the whole frame might later be shrunk,
3240 // causing the size of the pane to violate it's minimum size
3241 if (pane
.min_size
.IsFullySpecified())
3245 if (pane
.HasBorder())
3246 min_size
+= (pane_border_size
*2);
3248 // calculate minimum size with decorations (border,caption)
3249 if (pane_part
->orientation
== wxVERTICAL
)
3251 min_size
+= pane
.min_size
.y
;
3252 if (pane
.HasCaption())
3253 min_size
+= caption_size
;
3257 min_size
+= pane
.min_size
.x
;
3262 // for some reason, an arithmatic error somewhere is causing
3263 // the proportion calculations to always be off by 1 pixel;
3264 // for now we will add the 1 pixel on, but we really should
3265 // determine what's causing this.
3268 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3270 if (new_proportion
< min_proportion
)
3271 new_proportion
= min_proportion
;
3275 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3277 // borrow the space from our neighbor pane to the
3278 // right or bottom (depending on orientation)
3279 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3280 pane
.dock_proportion
= new_proportion
;
3287 else if (m_action
== actionClickButton
)
3289 m_hover_button
= NULL
;
3290 m_frame
->ReleaseMouse();
3291 UpdateButtonOnScreen(m_action_part
, event
);
3293 // make sure we're still over the item that was originally clicked
3294 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3296 // fire button-click event
3297 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3298 e
.SetPane(m_action_part
->pane
);
3299 e
.SetButton(m_action_part
->button
->button_id
);
3303 else if (m_action
== actionClickCaption
)
3305 m_frame
->ReleaseMouse();
3307 else if (m_action
== actionDragFloatingPane
)
3309 m_frame
->ReleaseMouse();
3311 else if (m_action
== actionDragToolbarPane
)
3313 m_frame
->ReleaseMouse();
3315 wxPaneInfo
& pane
= GetPane(m_action_window
);
3316 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3318 // save the new positions
3319 wxDockInfoPtrArray docks
;
3320 FindDocks(m_docks
, pane
.dock_direction
,
3321 pane
.dock_layer
, pane
.dock_row
, docks
);
3322 if (docks
.GetCount() == 1)
3324 wxDockInfo
& dock
= *docks
.Item(0);
3326 wxArrayInt pane_positions
, pane_sizes
;
3327 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3329 int i
, dock_pane_count
= dock
.panes
.GetCount();
3330 for (i
= 0; i
< dock_pane_count
; ++i
)
3331 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3334 pane
.state
&= ~wxPaneInfo::actionPane
;
3342 m_action
= actionNone
;
3343 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3347 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3349 // sometimes when Update() is called from inside this method,
3350 // a spurious mouse move event is generated; this check will make
3351 // sure that only real mouse moves will get anywhere in this method;
3352 // this appears to be a bug somewhere, and I don't know where the
3353 // mouse move event is being generated. only verified on MSW
3355 wxPoint mouse_pos
= event
.GetPosition();
3356 if (m_last_mouse_move
== mouse_pos
)
3358 m_last_mouse_move
= mouse_pos
;
3361 if (m_action
== actionResize
)
3363 wxPoint pos
= m_action_part
->rect
.GetPosition();
3364 if (m_action_part
->orientation
== wxHORIZONTAL
)
3365 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3367 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3369 wxRect
rect(m_frame
->ClientToScreen(pos
),
3370 m_action_part
->rect
.GetSize());
3373 if (!m_action_hintrect
.IsEmpty())
3374 DrawResizeHint(dc
, m_action_hintrect
);
3375 DrawResizeHint(dc
, rect
);
3376 m_action_hintrect
= rect
;
3378 else if (m_action
== actionClickCaption
)
3380 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3381 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3383 // caption has been clicked. we need to check if the mouse
3384 // is now being dragged. if it is, we need to change the
3385 // mouse action to 'drag'
3386 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3387 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3389 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3391 if (!pane_info
->IsToolbar())
3393 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3394 pane_info
->IsFloatable())
3396 m_action
= actionDragFloatingPane
;
3398 // set initial float position
3399 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3400 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3401 pt
.y
- m_action_offset
.y
);
3406 m_action_window
= pane_info
->frame
;
3408 // action offset is used here to make it feel "natural" to the user
3409 // to drag a docked pane and suddenly have it become a floating frame.
3410 // Sometimes, however, the offset where the user clicked on the docked
3411 // caption is bigger than the width of the floating frame itself, so
3412 // in that case we need to set the action offset to a sensible value
3413 wxSize frame_size
= m_action_window
->GetSize();
3414 if (frame_size
.x
<= m_action_offset
.x
)
3415 m_action_offset
.x
= 30;
3420 m_action
= actionDragToolbarPane
;
3421 m_action_window
= pane_info
->window
;
3425 else if (m_action
== actionDragFloatingPane
)
3427 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3428 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3429 pt
.y
- m_action_offset
.y
);
3431 else if (m_action
== actionDragToolbarPane
)
3433 wxPaneInfo
& pane
= GetPane(m_action_window
);
3434 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3436 pane
.state
|= wxPaneInfo::actionPane
;
3438 wxPoint pt
= event
.GetPosition();
3439 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3441 // if DoDrop() decided to float the pane, set up
3442 // the floating pane's initial position
3443 if (pane
.IsFloating())
3445 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3446 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3447 pt
.y
- m_action_offset
.y
);
3450 // this will do the actiual move operation;
3451 // in the case that the pane has been floated,
3452 // this call will create the floating pane
3453 // and do the reparenting
3456 // if the pane has been floated, change the mouse
3457 // action actionDragFloatingPane so that subsequent
3458 // EVT_MOTION() events will move the floating pane
3459 if (pane
.IsFloating())
3461 pane
.state
&= ~wxPaneInfo::actionPane
;
3462 m_action
= actionDragFloatingPane
;
3463 m_action_window
= pane
.frame
;
3468 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3469 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3471 if (part
!= m_hover_button
)
3473 // make the old button normal
3475 UpdateButtonOnScreen(m_hover_button
, event
);
3477 // mouse is over a button, so repaint the
3478 // button in hover mode
3479 UpdateButtonOnScreen(part
, event
);
3480 m_hover_button
= part
;
3487 m_hover_button
= NULL
;
3498 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3502 m_hover_button
= NULL
;
3507 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3509 // when a child pane has it's focus set, we should change the
3510 // pane's active state to reflect this. (this is only true if
3511 // active panes are allowed by the owner)
3512 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3514 if (GetPane(event
.GetWindow()).IsOk())
3516 SetActivePane(m_panes
, event
.GetWindow());
3523 // OnPaneButton() is an event handler that is called
3524 // when a pane button has been pressed.
3525 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& evt
)
3527 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3529 wxPaneInfo
& pane
= *(evt
.pane
);
3531 if (evt
.button
== wxPaneInfo::buttonClose
)
3533 // fire pane close event
3534 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3535 e
.SetPane(evt
.pane
);
3544 else if (evt
.button
== wxPaneInfo::buttonPin
)
3546 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&