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
)
56 DEFINE_EVENT_TYPE(wxEVT_AUI_RENDER
)
59 // a few defines to avoid nameclashes
60 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
62 #include "wx/mac/private.h"
65 IMPLEMENT_DYNAMIC_CLASS(wxFrameManagerEvent
, wxEvent
)
68 // -- static utility functions --
70 static wxBitmap
wxPaneCreateStippleBitmap()
72 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
73 wxImage
img(2,2,data
,true);
77 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
79 wxBitmap stipple
= wxPaneCreateStippleBitmap();
80 wxBrush
brush(stipple
);
82 dc
.SetPen(*wxTRANSPARENT_PEN
);
84 dc
.SetLogicalFunction(wxXOR
);
85 dc
.DrawRectangle(rect
);
89 // on supported windows systems (Win2000 and greater, Mac), this function
90 // will make a frame window transparent by a certain amount
91 static void MakeWindowTransparent(wxWindow
* wnd
, int amount
)
93 #if defined(__WXMSW__)
94 // this API call is not in all SDKs, only the newer ones, so
95 // we will runtime bind this
96 typedef DWORD (WINAPI
*PSETLAYEREDWINDOWATTR
)(HWND
, DWORD
, BYTE
, DWORD
);
97 static PSETLAYEREDWINDOWATTR pSetLayeredWindowAttributes
= NULL
;
98 static HMODULE h
= NULL
;
99 HWND hwnd
= (HWND
)wnd
->GetHWND();
102 h
= LoadLibrary(_T("user32"));
104 if (!pSetLayeredWindowAttributes
)
106 pSetLayeredWindowAttributes
=
107 (PSETLAYEREDWINDOWATTR
)GetProcAddress(h
,
109 wxT("SetLayeredWindowAttributes")
111 "SetLayeredWindowAttributes"
116 if (pSetLayeredWindowAttributes
== NULL
)
119 LONG exstyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
120 if (0 == (exstyle
& 0x80000) /*WS_EX_LAYERED*/)
121 SetWindowLong(hwnd
, GWL_EXSTYLE
, exstyle
| 0x80000 /*WS_EX_LAYERED*/);
123 pSetLayeredWindowAttributes(hwnd
, 0, (BYTE
)amount
, 2 /*LWA_ALPHA*/);
125 #elif defined(__WXMAC__)
127 WindowRef handle
= GetControlOwner((OpaqueControlRef
*)wnd
->GetHandle());
128 SetWindowAlpha(handle
, float(amount
)/ 255.0);
138 // CopyDocksAndPanes() - this utility function creates copies of
139 // the dock and pane info. wxDockInfo's usually contain pointers
140 // to wxPaneInfo classes, thus this function is necessary to reliably
141 // reconstruct that relationship in the new dock info and pane info arrays
143 static void CopyDocksAndPanes(wxDockInfoArray
& dest_docks
,
144 wxPaneInfoArray
& dest_panes
,
145 const wxDockInfoArray
& src_docks
,
146 const wxPaneInfoArray
& src_panes
)
148 dest_docks
= src_docks
;
149 dest_panes
= src_panes
;
150 int i
, j
, k
, dock_count
, pc1
, pc2
;
151 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
153 wxDockInfo
& dock
= dest_docks
.Item(i
);
154 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
155 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
156 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
157 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
161 // GetMaxLayer() is an internal function which returns
162 // the highest layer inside the specified dock
163 static int GetMaxLayer(const wxDockInfoArray
& docks
, int dock_direction
)
165 int i
, dock_count
, max_layer
= 0;
166 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
168 wxDockInfo
& dock
= docks
.Item(i
);
169 if (dock
.dock_direction
== dock_direction
&&
170 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
171 max_layer
= dock
.dock_layer
;
177 // GetMaxRow() is an internal function which returns
178 // the highest layer inside the specified dock
179 static int GetMaxRow(const wxPaneInfoArray
& panes
, int direction
, int layer
)
181 int i
, pane_count
, max_row
= 0;
182 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
184 wxPaneInfo
& pane
= panes
.Item(i
);
185 if (pane
.dock_direction
== direction
&&
186 pane
.dock_layer
== layer
&&
187 pane
.dock_row
> max_row
)
188 max_row
= pane
.dock_row
;
195 // DoInsertDockLayer() is an internal function that inserts a new dock
196 // layer by incrementing all existing dock layer values by one
197 static void DoInsertDockLayer(wxPaneInfoArray
& panes
,
202 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
204 wxPaneInfo
& pane
= panes
.Item(i
);
205 if (!pane
.IsFloating() &&
206 pane
.dock_direction
== dock_direction
&&
207 pane
.dock_layer
>= dock_layer
)
212 // DoInsertDockLayer() is an internal function that inserts a new dock
213 // row by incrementing all existing dock row values by one
214 static void DoInsertDockRow(wxPaneInfoArray
& panes
,
220 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
222 wxPaneInfo
& pane
= panes
.Item(i
);
223 if (!pane
.IsFloating() &&
224 pane
.dock_direction
== dock_direction
&&
225 pane
.dock_layer
== dock_layer
&&
226 pane
.dock_row
>= dock_row
)
231 // DoInsertDockLayer() is an internal function that inserts a space for
232 // another dock pane by incrementing all existing dock row values by one
233 static void DoInsertPane(wxPaneInfoArray
& panes
,
240 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
242 wxPaneInfo
& pane
= panes
.Item(i
);
243 if (!pane
.IsFloating() &&
244 pane
.dock_direction
== dock_direction
&&
245 pane
.dock_layer
== dock_layer
&&
246 pane
.dock_row
== dock_row
&&
247 pane
.dock_pos
>= dock_pos
)
252 // FindDocks() is an internal function that returns a list of docks which meet
253 // the specified conditions in the parameters and returns a sorted array
254 // (sorted by layer and then row)
255 static void FindDocks(wxDockInfoArray
& docks
,
259 wxDockInfoPtrArray
& arr
)
261 int begin_layer
= dock_layer
;
262 int end_layer
= dock_layer
;
263 int begin_row
= dock_row
;
264 int end_row
= dock_row
;
265 int dock_count
= docks
.GetCount();
266 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
268 // discover the maximum dock layer and the max row
269 for (i
= 0; i
< dock_count
; ++i
)
271 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
272 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
275 // if no dock layer was specified, search all dock layers
276 if (dock_layer
== -1)
279 end_layer
= max_layer
;
282 // if no dock row was specified, search all dock row
291 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
292 for (row
= begin_row
; row
<= end_row
; ++row
)
293 for (i
= 0; i
< dock_count
; ++i
)
295 wxDockInfo
& d
= docks
.Item(i
);
296 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
298 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
304 // FindPaneInDock() looks up a specified window pointer inside a dock.
305 // If found, the corresponding wxPaneInfo pointer is returned, otherwise NULL.
306 static wxPaneInfo
* FindPaneInDock(const wxDockInfo
& dock
, wxWindow
* window
)
308 int i
, count
= dock
.panes
.GetCount();
309 for (i
= 0; i
< count
; ++i
)
311 wxPaneInfo
* p
= dock
.panes
.Item(i
);
312 if (p
->window
== window
)
318 // RemovePaneFromDocks() removes a pane window from all docks
319 // with a possible exception specified by parameter "except"
320 static void RemovePaneFromDocks(wxDockInfoArray
& docks
,
322 wxDockInfo
* except
= NULL
)
325 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
327 wxDockInfo
& d
= docks
.Item(i
);
330 wxPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
336 // RenumberDockRows() takes a dock and assigns sequential numbers
337 // to existing rows. Basically it takes out the gaps; so if a
338 // dock has rows with numbers 0,2,5, they will become 0,1,2
339 static void RenumberDockRows(wxDockInfoPtrArray
& docks
)
341 int i
, dock_count
, j
, pane_count
;
342 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
344 wxDockInfo
& dock
= *docks
.Item(i
);
346 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
347 dock
.panes
.Item(j
)->dock_row
= i
;
352 // SetActivePane() sets the active pane, as well as cycles through
353 // every other pane and makes sure that all others' active flags
355 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
358 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
360 wxPaneInfo
& pane
= panes
.Item(i
);
361 pane
.state
&= ~wxPaneInfo::optionActive
;
362 if (pane
.window
== active_pane
)
363 pane
.state
|= wxPaneInfo::optionActive
;
368 // this function is used to sort panes by dock position
369 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
371 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
375 // -- wxFrameManager class implementation --
378 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
379 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
380 EVT_AUI_RENDER(wxFrameManager::OnRender
)
381 EVT_PAINT(wxFrameManager::OnPaint
)
382 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
383 EVT_SIZE(wxFrameManager::OnSize
)
384 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
385 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
386 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
387 EVT_MOTION(wxFrameManager::OnMotion
)
388 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
389 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
390 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
394 wxFrameManager::wxFrameManager(wxWindow
* managed_wnd
, unsigned int flags
)
396 m_action
= actionNone
;
397 m_last_mouse_move
= wxPoint();
398 m_hover_button
= NULL
;
399 m_art
= new wxDefaultDockArt
;
405 SetManagedWindow(managed_wnd
);
409 wxFrameManager::~wxFrameManager()
414 // GetPane() looks up a wxPaneInfo structure based
415 // on the supplied window pointer. Upon failure, GetPane()
416 // returns an empty wxPaneInfo, a condition which can be checked
417 // by calling wxPaneInfo::IsOk().
419 // The pane info's structure may then be modified. Once a pane's
420 // info is modified, wxFrameManager::Update() must be called to
421 // realize the changes in the UI.
423 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
426 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
428 wxPaneInfo
& p
= m_panes
.Item(i
);
429 if (p
.window
== window
)
432 return wxNullPaneInfo
;
435 // this version of GetPane() looks up a pane based on a
436 // 'pane name', see above comment for more info
437 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
440 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
442 wxPaneInfo
& p
= m_panes
.Item(i
);
446 return wxNullPaneInfo
;
449 // GetAllPanes() returns a reference to all the pane info structures
450 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
455 // HitTest() is an internal function which determines
456 // which UI item the specified coordinates are over
457 // (x,y) specify a position in client coordinates
458 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
460 wxDockUIPart
* result
= NULL
;
463 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
465 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
467 // we are not interested in typeDock, because this space
468 // isn't used to draw anything, just for measurements;
469 // besides, the entire dock area is covered with other
470 // rectangles, which we are interested in.
471 if (item
->type
== wxDockUIPart::typeDock
)
474 // if we already have a hit on a more specific item, we are not
475 // interested in a pane hit. If, however, we don't already have
476 // a hit, returning a pane hit is necessary for some operations
477 if ((item
->type
== wxDockUIPart::typePane
||
478 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
481 // if the point is inside the rectangle, we have a hit
482 if (item
->rect
.Inside(x
,y
))
490 // SetFlags() and GetFlags() allow the owner to set various
491 // options which are global to wxFrameManager
492 void wxFrameManager::SetFlags(unsigned int flags
)
497 unsigned int wxFrameManager::GetFlags() const
503 // don't use these anymore as they are deprecated
504 // use Set/GetManagedFrame() instead
505 void wxFrameManager::SetFrame(wxFrame
* frame
)
507 SetManagedWindow((wxWindow
*)frame
);
510 wxFrame
* wxFrameManager::GetFrame() const
512 return (wxFrame
*)m_frame
;
518 // SetManagedWindow() is usually called once when the frame
519 // manager class is being initialized. "frame" specifies
520 // the frame which should be managed by the frame mananger
521 void wxFrameManager::SetManagedWindow(wxWindow
* frame
)
523 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
526 m_frame
->PushEventHandler(this);
529 // if the owner is going to manage an MDI parent frame,
530 // we need to add the MDI client window as the default
533 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
535 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
536 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
538 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
540 AddPane(client_window
,
541 wxPaneInfo().Name(wxT("mdiclient")).
542 CenterPane().PaneBorder(false));
548 // UnInit() must be called, usually in the destructor
549 // of the frame class. If it is not called, usually this
550 // will result in a crash upon program exit
551 void wxFrameManager::UnInit()
553 m_frame
->RemoveEventHandler(this);
556 // GetManagedWindow() returns the window pointer being managed
557 wxWindow
* wxFrameManager::GetManagedWindow() const
562 wxDockArt
* wxFrameManager::GetArtProvider() const
567 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
569 // first, give the owner frame a chance to override
572 if (m_frame
->ProcessEvent(event
))
579 // SetArtProvider() instructs wxFrameManager to use the
580 // specified art provider for all drawing calls. This allows
581 // plugable look-and-feel features. The pointer that is
582 // passed to this method subsequently belongs to wxFrameManager,
583 // and is deleted in the frame manager destructor
584 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
586 // delete the last art provider, if any
589 // assign the new art provider
590 m_art
= art_provider
;
594 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
596 // check if the pane has a valid window
600 // check if the pane already exists
601 if (GetPane(pane_info
.window
).IsOk())
604 m_panes
.Add(pane_info
);
606 wxPaneInfo
& pinfo
= m_panes
.Last();
608 // set the pane window
609 pinfo
.window
= window
;
611 // if the pane's name identifier is blank, create a random string
612 if (pinfo
.name
.empty())
614 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
615 ((unsigned long)pinfo
.window
) & 0xffffffff,
616 (unsigned int)time(NULL
),
618 (unsigned int)GetTickCount(),
620 (unsigned int)clock(),
622 (unsigned long)m_panes
.GetCount());
625 // set initial proportion (if not already set)
626 if (pinfo
.dock_proportion
== 0)
627 pinfo
.dock_proportion
= 100000;
629 if (pinfo
.HasCloseButton() &&
630 pinfo
.buttons
.size() == 0)
633 button
.button_id
= wxPaneInfo::buttonClose
;
634 pinfo
.buttons
.Add(button
);
637 if (pinfo
.best_size
== wxDefaultSize
&&
640 pinfo
.best_size
= pinfo
.window
->GetClientSize();
642 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
644 // GetClientSize() doesn't get the best size for
645 // a toolbar under some newer versions of wxWidgets,
646 // so use GetBestSize()
647 pinfo
.best_size
= pinfo
.window
->GetBestSize();
649 // for some reason, wxToolBar::GetBestSize() is returning
650 // a size that is a pixel shy of the correct amount.
651 // I believe this to be the correct action, until
652 // wxToolBar::GetBestSize() is fixed. Is this assumption
657 if (pinfo
.min_size
!= wxDefaultSize
)
659 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
660 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
661 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
662 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
669 bool wxFrameManager::AddPane(wxWindow
* window
,
671 const wxString
& caption
)
674 pinfo
.Caption(caption
);
677 case wxTOP
: pinfo
.Top(); break;
678 case wxBOTTOM
: pinfo
.Bottom(); break;
679 case wxLEFT
: pinfo
.Left(); break;
680 case wxRIGHT
: pinfo
.Right(); break;
681 case wxCENTER
: pinfo
.CenterPane(); break;
683 return AddPane(window
, pinfo
);
686 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
689 // shift the panes around, depending on the insert level
690 switch (insert_level
)
692 case wxAUI_INSERT_PANE
:
693 DoInsertPane(m_panes
,
694 pane_info
.dock_direction
,
695 pane_info
.dock_layer
,
699 case wxAUI_INSERT_ROW
:
700 DoInsertDockRow(m_panes
,
701 pane_info
.dock_direction
,
702 pane_info
.dock_layer
,
705 case wxAUI_INSERT_DOCK
:
706 DoInsertDockLayer(m_panes
,
707 pane_info
.dock_direction
,
708 pane_info
.dock_layer
);
712 // if the window already exists, we are basically just moving/inserting the
713 // existing window. If it doesn't exist, we need to add it and insert it
714 wxPaneInfo
& existing_pane
= GetPane(window
);
715 if (!existing_pane
.IsOk())
717 return AddPane(window
, pane_info
);
721 if (pane_info
.IsFloating())
723 existing_pane
.Float();
724 if (pane_info
.floating_pos
!= wxDefaultPosition
)
725 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
726 if (pane_info
.floating_size
!= wxDefaultSize
)
727 existing_pane
.FloatingSize(pane_info
.floating_size
);
731 existing_pane
.Direction(pane_info
.dock_direction
);
732 existing_pane
.Layer(pane_info
.dock_layer
);
733 existing_pane
.Row(pane_info
.dock_row
);
734 existing_pane
.Position(pane_info
.dock_pos
);
742 // DetachPane() removes a pane from the frame manager. This
743 // method will not destroy the window that is removed.
744 bool wxFrameManager::DetachPane(wxWindow
* window
)
747 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
749 wxPaneInfo
& p
= m_panes
.Item(i
);
750 if (p
.window
== window
)
754 // we have a floating frame which is being detached. We need to
755 // reparent it to m_frame and destroy the floating frame
758 p
.window
->SetSize(1,1);
759 p
.frame
->Show(false);
761 // reparent to m_frame and destroy the pane
762 p
.window
->Reparent(m_frame
);
763 p
.frame
->SetSizer(NULL
);
775 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
776 // in the input string. This is an internal functions which is
777 // used for saving perspectives
778 static wxString
EscapeDelimiters(const wxString
& s
)
781 result
.Alloc(s
.length());
782 const wxChar
* ch
= s
.c_str();
785 if (*ch
== wxT(';') || *ch
== wxT('|'))
794 // SavePerspective() saves all pane information as a single string.
795 // This string may later be fed into LoadPerspective() to restore
796 // all pane settings. This save and load mechanism allows an
797 // exact pane configuration to be saved and restored at a later time
799 wxString
wxFrameManager::SavePerspective()
803 result
= wxT("layout1|");
805 int pane_i
, pane_count
= m_panes
.GetCount();
806 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
808 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
810 result
+= wxT("name=");
811 result
+= EscapeDelimiters(pane
.name
);
814 result
+= wxT("caption=");
815 result
+= EscapeDelimiters(pane
.caption
);
818 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
819 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
820 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
821 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
822 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
823 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
824 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
825 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
826 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
827 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
828 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
829 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
830 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
831 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
832 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
833 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
837 int dock_i
, dock_count
= m_docks
.GetCount();
838 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
840 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
842 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
843 dock
.dock_direction
, dock
.dock_layer
,
844 dock
.dock_row
, dock
.size
);
850 // LoadPerspective() loads a layout which was saved with SavePerspective()
851 // If the "update" flag parameter is true, the GUI will immediately be updated
853 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
855 wxString input
= layout
;
858 // check layout string version
859 part
= input
.BeforeFirst(wxT('|'));
860 input
= input
.AfterFirst(wxT('|'));
863 if (part
!= wxT("layout1"))
867 // mark all panes currently managed as docked and hidden
868 int pane_i
, pane_count
= m_panes
.GetCount();
869 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
870 m_panes
.Item(pane_i
).Dock().Hide();
872 // clear out the dock array; this will be reconstructed
875 // replace escaped characters so we can
876 // split up the string easily
877 input
.Replace(wxT("\\|"), wxT("\a"));
878 input
.Replace(wxT("\\;"), wxT("\b"));
884 wxString pane_part
= input
.BeforeFirst(wxT('|'));
885 input
= input
.AfterFirst(wxT('|'));
886 pane_part
.Trim(true);
888 // if the string is empty, we're done parsing
889 if (pane_part
.empty())
893 if (pane_part
.Left(9) == wxT("dock_size"))
895 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
896 wxString value
= pane_part
.AfterFirst(wxT('='));
898 long dir
, layer
, row
, size
;
899 wxString piece
= val_name
.AfterFirst(wxT('('));
900 piece
= piece
.BeforeLast(wxT(')'));
901 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
902 piece
= piece
.AfterFirst(wxT(','));
903 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
904 piece
.AfterFirst(wxT(',')).ToLong(&row
);
908 dock
.dock_direction
= dir
;
909 dock
.dock_layer
= layer
;
918 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
919 pane_part
= pane_part
.AfterFirst(wxT(';'));
920 wxString val_name
= val_part
.BeforeFirst(wxT('='));
921 wxString value
= val_part
.AfterFirst(wxT('='));
922 val_name
.MakeLower();
924 val_name
.Trim(false);
928 if (val_name
.empty())
931 if (val_name
== wxT("name"))
933 else if (val_name
== wxT("caption"))
934 pane
.caption
= value
;
935 else if (val_name
== wxT("state"))
936 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
937 else if (val_name
== wxT("dir"))
938 pane
.dock_direction
= wxAtoi(value
.c_str());
939 else if (val_name
== wxT("layer"))
940 pane
.dock_layer
= wxAtoi(value
.c_str());
941 else if (val_name
== wxT("row"))
942 pane
.dock_row
= wxAtoi(value
.c_str());
943 else if (val_name
== wxT("pos"))
944 pane
.dock_pos
= wxAtoi(value
.c_str());
945 else if (val_name
== wxT("prop"))
946 pane
.dock_proportion
= wxAtoi(value
.c_str());
947 else if (val_name
== wxT("bestw"))
948 pane
.best_size
.x
= wxAtoi(value
.c_str());
949 else if (val_name
== wxT("besth"))
950 pane
.best_size
.y
= wxAtoi(value
.c_str());
951 else if (val_name
== wxT("minw"))
952 pane
.min_size
.x
= wxAtoi(value
.c_str());
953 else if (val_name
== wxT("minh"))
954 pane
.min_size
.y
= wxAtoi(value
.c_str());
955 else if (val_name
== wxT("maxw"))
956 pane
.max_size
.x
= wxAtoi(value
.c_str());
957 else if (val_name
== wxT("maxh"))
958 pane
.max_size
.y
= wxAtoi(value
.c_str());
959 else if (val_name
== wxT("floatx"))
960 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
961 else if (val_name
== wxT("floaty"))
962 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
963 else if (val_name
== wxT("floatw"))
964 pane
.floating_size
.x
= wxAtoi(value
.c_str());
965 else if (val_name
== wxT("floath"))
966 pane
.floating_size
.y
= wxAtoi(value
.c_str());
968 wxFAIL_MSG(wxT("Bad Perspective String"));
972 // replace escaped characters so we can
973 // split up the string easily
974 pane
.name
.Replace(wxT("\a"), wxT("|"));
975 pane
.name
.Replace(wxT("\b"), wxT(";"));
976 pane
.caption
.Replace(wxT("\a"), wxT("|"));
977 pane
.caption
.Replace(wxT("\b"), wxT(";"));
979 wxPaneInfo
& p
= GetPane(pane
.name
);
982 // the pane window couldn't be found
983 // in the existing layout
987 pane
.window
= p
.window
;
988 pane
.frame
= p
.frame
;
989 pane
.buttons
= p
.buttons
;
1000 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
1001 wxArrayInt
& positions
,
1004 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1005 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1006 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1011 int offset
, action_pane
= -1;
1012 int pane_i
, pane_count
= dock
.panes
.GetCount();
1014 // find the pane marked as our action pane
1015 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1017 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1019 if (pane
.state
& wxPaneInfo::actionPane
)
1021 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1022 action_pane
= pane_i
;
1026 // set up each panes default position, and
1027 // determine the size (width or height, depending
1028 // on the dock's orientation) of each pane
1029 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1031 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1032 positions
.Add(pane
.dock_pos
);
1035 if (pane
.HasBorder())
1036 size
+= (pane_border_size
*2);
1038 if (dock
.IsHorizontal())
1040 if (pane
.HasGripper() && !pane
.HasGripperTop())
1041 size
+= gripper_size
;
1042 size
+= pane
.best_size
.x
;
1046 if (pane
.HasGripper() && pane
.HasGripperTop())
1047 size
+= gripper_size
;
1049 if (pane
.HasCaption())
1050 size
+= caption_size
;
1051 size
+= pane
.best_size
.y
;
1057 // if there is no action pane, just return the default
1058 // positions (as specified in pane.pane_pos)
1059 if (action_pane
== -1)
1063 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1065 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1070 positions
[pane_i
] -= -amount
;
1072 offset
+= sizes
[pane_i
];
1075 // if the dock mode is fixed, make sure none of the panes
1076 // overlap; we will bump panes that overlap
1078 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1080 int amount
= positions
[pane_i
] - offset
;
1084 positions
[pane_i
] += -amount
;
1086 offset
+= sizes
[pane_i
];
1091 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1094 wxDockUIPartArray
& uiparts
,
1098 wxSizerItem
* sizer_item
;
1100 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1101 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1102 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1103 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1105 // find out the orientation of the item (orientation for panes
1106 // is the same as the dock's orientation)
1108 if (dock
.IsHorizontal())
1109 orientation
= wxHORIZONTAL
;
1111 orientation
= wxVERTICAL
;
1113 // this variable will store the proportion
1114 // value that the pane will receive
1115 int pane_proportion
= pane
.dock_proportion
;
1117 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1118 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1120 if (pane
.HasGripper())
1122 if (pane
.HasGripperTop())
1123 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1125 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1127 part
.type
= wxDockUIPart::typeGripper
;
1131 part
.orientation
= orientation
;
1132 part
.cont_sizer
= horz_pane_sizer
;
1133 part
.sizer_item
= sizer_item
;
1137 if (pane
.HasCaption())
1139 // create the caption sizer
1140 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1142 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1144 part
.type
= wxDockUIPart::typeCaption
;
1148 part
.orientation
= orientation
;
1149 part
.cont_sizer
= vert_pane_sizer
;
1150 part
.sizer_item
= sizer_item
;
1151 int caption_part_idx
= uiparts
.GetCount();
1154 // add pane buttons to the caption
1155 int i
, button_count
;
1156 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1157 i
< button_count
; ++i
)
1159 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1161 sizer_item
= caption_sizer
->Add(pane_button_size
,
1165 part
.type
= wxDockUIPart::typePaneButton
;
1168 part
.button
= &button
;
1169 part
.orientation
= orientation
;
1170 part
.cont_sizer
= caption_sizer
;
1171 part
.sizer_item
= sizer_item
;
1175 // add the caption sizer
1176 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1178 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1181 // add the pane window itself
1184 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1188 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1189 // Don't do this because it breaks the pane size in floating windows
1190 // BIW: Right now commenting this out is causing problems with
1191 // an mdi client window as the center pane.
1192 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1195 part
.type
= wxDockUIPart::typePane
;
1199 part
.orientation
= orientation
;
1200 part
.cont_sizer
= vert_pane_sizer
;
1201 part
.sizer_item
= sizer_item
;
1205 // determine if the pane should have a minimum size; if the pane is
1206 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1207 // if the pane.min_size is set, we must use that value as well
1209 wxSize min_size
= pane
.min_size
;
1212 if (min_size
== wxDefaultSize
)
1214 min_size
= pane
.best_size
;
1215 pane_proportion
= 0;
1219 if (min_size
!= wxDefaultSize
)
1221 vert_pane_sizer
->SetItemMinSize(
1222 vert_pane_sizer
->GetChildren().GetCount()-1,
1223 min_size
.x
, min_size
.y
);
1227 // add the verticle sizer (caption, pane window) to the
1228 // horizontal sizer (gripper, verticle sizer)
1229 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1231 // finally, add the pane sizer to the dock sizer
1233 if (pane
.HasBorder())
1235 // allowing space for the pane's border
1236 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1237 wxEXPAND
| wxALL
, pane_border_size
);
1239 part
.type
= wxDockUIPart::typePaneBorder
;
1243 part
.orientation
= orientation
;
1244 part
.cont_sizer
= cont
;
1245 part
.sizer_item
= sizer_item
;
1250 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1254 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1256 wxDockUIPartArray
& uiparts
,
1259 wxSizerItem
* sizer_item
;
1262 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1263 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1265 // resizable bottom and right docks have a sash before them
1266 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1267 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1269 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1271 part
.type
= wxDockUIPart::typeDockSizer
;
1272 part
.orientation
= orientation
;
1276 part
.cont_sizer
= cont
;
1277 part
.sizer_item
= sizer_item
;
1281 // create the sizer for the dock
1282 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1284 // add each pane to the dock
1285 int pane_i
, pane_count
= dock
.panes
.GetCount();
1289 wxArrayInt pane_positions
, pane_sizes
;
1291 // figure out the real pane positions we will
1292 // use, without modifying the each pane's pane_pos member
1293 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1296 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1298 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1299 int pane_pos
= pane_positions
.Item(pane_i
);
1301 int amount
= pane_pos
- offset
;
1304 if (dock
.IsVertical())
1305 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1307 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1309 part
.type
= wxDockUIPart::typeBackground
;
1313 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1314 part
.cont_sizer
= dock_sizer
;
1315 part
.sizer_item
= sizer_item
;
1321 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1323 offset
+= pane_sizes
.Item(pane_i
);
1326 // at the end add a very small stretchable background area
1327 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1329 part
.type
= wxDockUIPart::typeBackground
;
1333 part
.orientation
= orientation
;
1334 part
.cont_sizer
= dock_sizer
;
1335 part
.sizer_item
= sizer_item
;
1340 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1342 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1344 // if this is not the first pane being added,
1345 // we need to add a pane sizer
1348 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1350 part
.type
= wxDockUIPart::typePaneSizer
;
1352 part
.pane
= dock
.panes
.Item(pane_i
-1);
1354 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1355 part
.cont_sizer
= dock_sizer
;
1356 part
.sizer_item
= sizer_item
;
1360 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1364 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1365 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1367 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1369 part
.type
= wxDockUIPart::typeDock
;
1373 part
.orientation
= orientation
;
1374 part
.cont_sizer
= cont
;
1375 part
.sizer_item
= sizer_item
;
1378 if (dock
.IsHorizontal())
1379 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1381 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1383 // top and left docks have a sash after them
1384 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1385 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1387 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1389 part
.type
= wxDockUIPart::typeDockSizer
;
1393 part
.orientation
= orientation
;
1394 part
.cont_sizer
= cont
;
1395 part
.sizer_item
= sizer_item
;
1400 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1401 wxDockInfoArray
& docks
,
1402 wxDockUIPartArray
& uiparts
,
1405 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1407 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1408 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1409 wxSize cli_size
= m_frame
->GetClientSize();
1410 int i
, dock_count
, pane_count
;
1413 // empty all docks out
1414 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1415 docks
.Item(i
).panes
.Empty();
1417 // iterate through all known panes, filing each
1418 // of them into the appropriate dock. If the
1419 // pane does not exist in the dock, add it
1420 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1422 wxPaneInfo
& p
= panes
.Item(i
);
1424 // find any docks in this layer
1426 wxDockInfoPtrArray arr
;
1427 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1429 if (arr
.GetCount() > 0)
1435 // dock was not found, so we need to create a new one
1437 d
.dock_direction
= p
.dock_direction
;
1438 d
.dock_layer
= p
.dock_layer
;
1439 d
.dock_row
= p
.dock_row
;
1441 dock
= &docks
.Last();
1445 if (p
.IsDocked() && p
.IsShown())
1447 // remove the pane from any existing docks except this one
1448 RemovePaneFromDocks(docks
, p
, dock
);
1450 // pane needs to be added to the dock,
1451 // if it doesn't already exist
1452 if (!FindPaneInDock(*dock
, p
.window
))
1453 dock
->panes
.Add(&p
);
1457 // remove the pane from any existing docks
1458 RemovePaneFromDocks(docks
, p
);
1463 // remove any empty docks
1464 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1466 if (docks
.Item(i
).panes
.GetCount() == 0)
1470 // configure the docks further
1471 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1473 wxDockInfo
& dock
= docks
.Item(i
);
1474 int j
, dock_pane_count
= dock
.panes
.GetCount();
1476 // sort the dock pane array by the pane's
1477 // dock position (dock_pos), in ascending order
1478 dock
.panes
.Sort(PaneSortFunc
);
1480 // for newly created docks, set up their initial size
1485 for (j
= 0; j
< dock_pane_count
; ++j
)
1487 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1488 wxSize pane_size
= pane
.best_size
;
1489 if (pane_size
== wxDefaultSize
)
1490 pane_size
= pane
.min_size
;
1491 if (pane_size
== wxDefaultSize
)
1492 pane_size
= pane
.window
->GetSize();
1494 if (dock
.IsHorizontal())
1495 size
= wxMax(pane_size
.y
, size
);
1497 size
= wxMax(pane_size
.x
, size
);
1500 // add space for the border (two times), but only
1501 // if at least one pane inside the dock has a pane border
1502 for (j
= 0; j
< dock_pane_count
; ++j
)
1504 if (dock
.panes
.Item(j
)->HasBorder())
1506 size
+= (pane_border_size
*2);
1511 // if pane is on the top or bottom, add the caption height,
1512 // but only if at least one pane inside the dock has a caption
1513 if (dock
.IsHorizontal())
1515 for (j
= 0; j
< dock_pane_count
; ++j
)
1517 if (dock
.panes
.Item(j
)->HasCaption())
1519 size
+= caption_size
;
1525 // new dock's size may not be more than 1/3 of the frame size
1526 if (dock
.IsHorizontal())
1527 size
= wxMin(size
, cli_size
.y
/3);
1529 size
= wxMin(size
, cli_size
.x
/3);
1537 // determine the dock's minimum size
1538 bool plus_border
= false;
1539 bool plus_caption
= false;
1540 int dock_min_size
= 0;
1541 for (j
= 0; j
< dock_pane_count
; ++j
)
1543 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1544 if (pane
.min_size
!= wxDefaultSize
)
1546 if (pane
.HasBorder())
1548 if (pane
.HasCaption())
1549 plus_caption
= true;
1550 if (dock
.IsHorizontal())
1552 if (pane
.min_size
.y
> dock_min_size
)
1553 dock_min_size
= pane
.min_size
.y
;
1557 if (pane
.min_size
.x
> dock_min_size
)
1558 dock_min_size
= pane
.min_size
.x
;
1564 dock_min_size
+= (pane_border_size
*2);
1565 if (plus_caption
&& dock
.IsHorizontal())
1566 dock_min_size
+= (caption_size
);
1568 dock
.min_size
= dock_min_size
;
1571 // if the pane's current size is less than it's
1572 // minimum, increase the dock's size to it's minimum
1573 if (dock
.size
< dock
.min_size
)
1574 dock
.size
= dock
.min_size
;
1577 // determine the dock's mode (fixed or proportional);
1578 // determine whether the dock has only toolbars
1579 bool action_pane_marked
= false;
1581 dock
.toolbar
= true;
1582 for (j
= 0; j
< dock_pane_count
; ++j
)
1584 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1585 if (!pane
.IsFixed())
1587 if (!pane
.IsToolbar())
1588 dock
.toolbar
= false;
1589 if (pane
.state
& wxPaneInfo::actionPane
)
1590 action_pane_marked
= true;
1594 // if the dock mode is proportional and not fixed-pixel,
1595 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1596 // e.g. remove gaps like 1, 2, 30, 500
1599 for (j
= 0; j
< dock_pane_count
; ++j
)
1601 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1606 // if the dock mode is fixed, and none of the panes
1607 // are being moved right now, make sure the panes
1608 // do not overlap each other. If they do, we will
1609 // adjust the panes' positions
1610 if (dock
.fixed
&& !action_pane_marked
)
1612 wxArrayInt pane_positions
, pane_sizes
;
1613 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1616 for (j
= 0; j
< dock_pane_count
; ++j
)
1618 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1619 pane
.dock_pos
= pane_positions
[j
];
1621 int amount
= pane
.dock_pos
- offset
;
1625 pane
.dock_pos
+= -amount
;
1627 offset
+= pane_sizes
[j
];
1632 // discover the maximum dock layer
1634 for (i
= 0; i
< dock_count
; ++i
)
1635 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1638 // clear out uiparts
1641 // create a bunch of box sizers,
1642 // from the innermost level outwards.
1643 wxSizer
* cont
= NULL
;
1644 wxSizer
* middle
= NULL
;
1648 for (layer
= 0; layer
<= max_layer
; ++layer
)
1650 wxDockInfoPtrArray arr
;
1652 // find any docks in this layer
1653 FindDocks(docks
, -1, layer
, -1, arr
);
1655 // if there aren't any, skip to the next layer
1659 wxSizer
* old_cont
= cont
;
1661 // create a container which will hold this layer's
1662 // docks (top, bottom, left, right)
1663 cont
= new wxBoxSizer(wxVERTICAL
);
1666 // find any top docks in this layer
1667 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1668 RenumberDockRows(arr
);
1671 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1672 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1676 // fill out the middle layer (which consists
1677 // of left docks, content area and right docks)
1679 middle
= new wxBoxSizer(wxHORIZONTAL
);
1681 // find any left docks in this layer
1682 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1683 RenumberDockRows(arr
);
1686 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1687 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1690 // add content dock (or previous layer's sizer
1694 // find any center docks
1695 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1698 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1699 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1703 // there are no center docks, add a background area
1704 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1706 part
.type
= wxDockUIPart::typeBackground
;
1710 part
.cont_sizer
= middle
;
1711 part
.sizer_item
= sizer_item
;
1717 middle
->Add(old_cont
, 1, wxEXPAND
);
1720 // find any right docks in this layer
1721 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1722 RenumberDockRows(arr
);
1725 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1726 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1729 cont
->Add(middle
, 1, wxEXPAND
);
1733 // find any bottom docks in this layer
1734 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1735 RenumberDockRows(arr
);
1738 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1739 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1746 // no sizer available, because there are no docks,
1747 // therefore we will create a simple background area
1748 cont
= new wxBoxSizer(wxVERTICAL
);
1749 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1751 part
.type
= wxDockUIPart::typeBackground
;
1755 part
.cont_sizer
= middle
;
1756 part
.sizer_item
= sizer_item
;
1760 container
->Add(cont
, 1, wxEXPAND
);
1765 // Update() updates the layout. Whenever changes are made to
1766 // one or more panes, this function should be called. It is the
1767 // external entry point for running the layout engine.
1769 void wxFrameManager::Update()
1772 int i
, pane_count
= m_panes
.GetCount();
1774 // delete old sizer first
1775 m_frame
->SetSizer(NULL
);
1777 // destroy floating panes which have been
1778 // redocked or are becoming non-floating
1779 for (i
= 0; i
< pane_count
; ++i
)
1781 wxPaneInfo
& p
= m_panes
.Item(i
);
1783 if (!p
.IsFloating() && p
.frame
)
1785 // because the pane is no longer in a floating, we need to
1786 // reparent it to m_frame and destroy the floating frame
1789 p
.window
->SetSize(1,1);
1790 p
.frame
->Show(false);
1792 // reparent to m_frame and destroy the pane
1793 p
.window
->Reparent(m_frame
);
1794 p
.frame
->SetSizer(NULL
);
1801 // create a layout for all of the panes
1802 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
1804 // hide or show panes as necessary,
1805 // and float panes as necessary
1806 for (i
= 0; i
< pane_count
; ++i
)
1808 wxPaneInfo
& p
= m_panes
.Item(i
);
1812 if (p
.frame
== NULL
)
1814 // we need to create a frame for this
1815 // pane, which has recently been floated
1816 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
1820 // on MSW and Mac, if the owner desires transparent dragging, and
1821 // the dragging is happening right now, then the floating
1822 // window should have this style by default
1823 if (m_action
== actionDragFloatingPane
&&
1824 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
1825 MakeWindowTransparent(frame
, 150);
1827 frame
->SetPaneWindow(p
);
1837 // frame already exists, make sure it's position
1838 // and size reflect the information in wxPaneInfo
1839 if (p
.frame
->GetPosition() != p
.floating_pos
)
1841 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
1842 wxDefaultCoord
, wxDefaultCoord
,
1843 wxSIZE_USE_EXISTING
);
1844 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
1847 p
.frame
->Show(p
.IsShown());
1852 p
.window
->Show(p
.IsShown());
1855 // if "active panes" are no longer allowed, clear
1856 // any optionActive values from the pane states
1857 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
1859 p
.state
&= ~wxPaneInfo::optionActive
;
1864 // keep track of the old window rectangles so we can
1865 // refresh those windows whose rect has changed
1866 wxAuiRectArray old_pane_rects
;
1867 for (i
= 0; i
< pane_count
; ++i
)
1870 wxPaneInfo
& p
= m_panes
.Item(i
);
1872 if (p
.window
&& p
.IsShown() && p
.IsDocked())
1875 old_pane_rects
.Add(r
);
1881 // apply the new sizer
1882 m_frame
->SetSizer(sizer
);
1883 m_frame
->SetAutoLayout(false);
1888 // now that the frame layout is done, we need to check
1889 // the new pane rectangles against the old rectangles that
1890 // we saved a few lines above here. If the rectangles have
1891 // changed, the corresponding panes must also be updated
1892 for (i
= 0; i
< pane_count
; ++i
)
1894 wxPaneInfo
& p
= m_panes
.Item(i
);
1895 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
1897 if (p
.rect
!= old_pane_rects
[i
])
1899 p
.window
->Refresh();
1908 // set frame's minimum size
1911 // N.B. More work needs to be done on frame minimum sizes;
1912 // this is some intresting code that imposes the minimum size,
1913 // but we may want to include a more flexible mechanism or
1914 // options for multiple minimum-size modes, e.g. strict or lax
1915 wxSize min_size = sizer->GetMinSize();
1916 wxSize frame_size = m_frame->GetSize();
1917 wxSize client_size = m_frame->GetClientSize();
1919 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
1920 min_size.y+frame_size.y-client_size.y );
1922 m_frame->SetMinSize(minframe_size);
1924 if (frame_size.x < minframe_size.x ||
1925 frame_size.y < minframe_size.y)
1926 sizer->Fit(m_frame);
1931 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
1932 // on the frame's main sizer, then measures all the various UI items
1933 // and updates their internal rectangles. This should always be called
1934 // instead of calling m_frame->Layout() directly
1936 void wxFrameManager::DoFrameLayout()
1941 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1943 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1945 // get the rectangle of the UI part
1946 // originally, this code looked like this:
1947 // part.rect = wxRect(part.sizer_item->GetPosition(),
1948 // part.sizer_item->GetSize());
1949 // this worked quite well, with one exception: the mdi
1950 // client window had a "deferred" size variable
1951 // that returned the wrong size. It looks like
1952 // a bug in wx, because the former size of the window
1953 // was being returned. So, we will retrieve the part's
1954 // rectangle via other means
1957 part
.rect
= part
.sizer_item
->GetRect();
1958 int flag
= part
.sizer_item
->GetFlag();
1959 int border
= part
.sizer_item
->GetBorder();
1962 part
.rect
.y
-= border
;
1963 part
.rect
.height
+= border
;
1967 part
.rect
.x
-= border
;
1968 part
.rect
.width
+= border
;
1970 if (flag
& wxBOTTOM
)
1971 part
.rect
.height
+= border
;
1973 part
.rect
.width
+= border
;
1976 if (part
.type
== wxDockUIPart::typeDock
)
1977 part
.dock
->rect
= part
.rect
;
1978 if (part
.type
== wxDockUIPart::typePane
)
1979 part
.pane
->rect
= part
.rect
;
1983 // GetPanePart() looks up the pane the pane border UI part (or the regular
1984 // pane part if there is no border). This allows the caller to get the exact
1985 // rectangle of the pane in question, including decorations like
1986 // caption and border (if any).
1988 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
1991 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1993 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1994 if (part
.type
== wxDockUIPart::typePaneBorder
&&
1995 part
.pane
&& part
.pane
->window
== wnd
)
1998 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2000 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2001 if (part
.type
== wxDockUIPart::typePane
&&
2002 part
.pane
&& part
.pane
->window
== wnd
)
2010 // GetDockPixelOffset() is an internal function which returns
2011 // a dock's offset in pixels from the left side of the window
2012 // (for horizontal docks) or from the top of the window (for
2013 // vertical docks). This value is necessary for calculating
2014 // fixel-pane/toolbar offsets when they are dragged.
2016 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
2018 // the only way to accurately calculate the dock's
2019 // offset is to actually run a theoretical layout
2021 int i
, part_count
, dock_count
;
2022 wxDockInfoArray docks
;
2023 wxPaneInfoArray panes
;
2024 wxDockUIPartArray uiparts
;
2025 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2028 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2029 wxSize client_size
= m_frame
->GetClientSize();
2030 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2033 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2035 wxDockUIPart
& part
= uiparts
.Item(i
);
2036 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2037 part
.sizer_item
->GetSize());
2038 if (part
.type
== wxDockUIPart::typeDock
)
2039 part
.dock
->rect
= part
.rect
;
2044 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2046 wxDockInfo
& dock
= docks
.Item(i
);
2047 if (test
.dock_direction
== dock
.dock_direction
&&
2048 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2050 if (dock
.IsVertical())
2062 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2063 // if a dock operation is allowed, the new dock position is copied into
2064 // the target info. If the operation was allowed, the function returns true.
2066 bool wxFrameManager::ProcessDockResult(wxPaneInfo
& target
,
2067 const wxPaneInfo
& new_pos
)
2069 bool allowed
= false;
2070 switch (new_pos
.dock_direction
)
2072 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2073 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2074 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2075 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2085 // DoDrop() is an important function. It basically takes a mouse position,
2086 // and determines where the pane's new position would be. If the pane is to be
2087 // dropped, it performs the drop operation using the specified dock and pane
2088 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2089 // scenario can be performed, giving precise coordinates for drop hints.
2090 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2091 // as parameters, the changes will be made to the main state arrays
2093 const int auiInsertRowPixels
= 10;
2094 const int auiNewRowPixels
= 40;
2095 const int auiLayerInsertPixels
= 40;
2096 const int auiLayerInsertOffset
= 5;
2098 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2099 wxPaneInfoArray
& panes
,
2102 const wxPoint
& offset
)
2104 wxSize cli_size
= m_frame
->GetClientSize();
2106 wxPaneInfo drop
= target
;
2109 // The result should always be shown
2113 // Check to see if the pane has been dragged outside of the window
2114 // (or near to the outside of the window), if so, dock it along the edge
2117 int layer_insert_offset
= auiLayerInsertOffset
;
2118 if (target
.IsToolbar())
2119 layer_insert_offset
= 0;
2121 if (pt
.x
< layer_insert_offset
&&
2122 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2124 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2125 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2126 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2130 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2131 return ProcessDockResult(target
, drop
);
2133 else if (pt
.y
< layer_insert_offset
&&
2134 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2136 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2137 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2138 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2142 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2143 return ProcessDockResult(target
, drop
);
2145 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2146 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2148 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2149 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2150 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2151 drop
.Dock().Right().
2154 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2155 return ProcessDockResult(target
, drop
);
2157 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2158 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2160 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2161 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2162 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2163 drop
.Dock().Bottom().
2166 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2167 return ProcessDockResult(target
, drop
);
2171 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2174 if (drop
.IsToolbar())
2176 if (!part
|| !part
->dock
)
2180 // calculate the offset from where the dock begins
2181 // to the point where the user dropped the pane
2182 int dock_drop_offset
= 0;
2183 if (part
->dock
->IsHorizontal())
2184 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2186 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2189 // toolbars may only be moved in and to fixed-pane docks,
2190 // otherwise we will try to float the pane. Also, the pane
2191 // should float if being dragged over center pane windows
2192 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2194 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2195 (drop
.IsFloatable() ||
2196 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2197 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2202 return ProcessDockResult(target
, drop
);
2206 Direction(part
->dock
->dock_direction
).
2207 Layer(part
->dock
->dock_layer
).
2208 Row(part
->dock
->dock_row
).
2209 Position(dock_drop_offset
);
2212 ((pt
.y
< part
->dock
->rect
.y
+ 2) && part
->dock
->IsHorizontal()) ||
2213 ((pt
.x
< part
->dock
->rect
.x
+ 2) && part
->dock
->IsVertical())
2214 ) && part
->dock
->panes
.GetCount() > 1)
2216 int row
= drop
.dock_row
;
2217 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2218 part
->dock
->dock_layer
,
2219 part
->dock
->dock_row
);
2220 drop
.dock_row
= row
;
2224 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2225 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2226 ) && part
->dock
->panes
.GetCount() > 1)
2228 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2229 part
->dock
->dock_layer
,
2230 part
->dock
->dock_row
+1);
2231 drop
.dock_row
= part
->dock
->dock_row
+1;
2234 return ProcessDockResult(target
, drop
);
2243 if (part
->type
== wxDockUIPart::typePaneBorder
||
2244 part
->type
== wxDockUIPart::typeCaption
||
2245 part
->type
== wxDockUIPart::typeGripper
||
2246 part
->type
== wxDockUIPart::typePaneButton
||
2247 part
->type
== wxDockUIPart::typePane
||
2248 part
->type
== wxDockUIPart::typePaneSizer
||
2249 part
->type
== wxDockUIPart::typeDockSizer
||
2250 part
->type
== wxDockUIPart::typeBackground
)
2252 if (part
->type
== wxDockUIPart::typeDockSizer
)
2254 if (part
->dock
->panes
.GetCount() != 1)
2256 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2263 // If a normal frame is being dragged over a toolbar, insert it
2264 // along the edge under the toolbar, but over all other panes.
2265 // (this could be done much better, but somehow factoring this
2266 // calculation with the one at the beginning of this function)
2267 if (part
->dock
&& part
->dock
->toolbar
)
2271 switch (part
->dock
->dock_direction
)
2273 case wxAUI_DOCK_LEFT
:
2274 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2275 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2276 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2278 case wxAUI_DOCK_TOP
:
2279 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2280 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2281 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2283 case wxAUI_DOCK_RIGHT
:
2284 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2285 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2286 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2288 case wxAUI_DOCK_BOTTOM
:
2289 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2290 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2291 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2295 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2298 Direction(part
->dock
->dock_direction
).
2299 Layer(layer
).Row(0).Position(0);
2300 return ProcessDockResult(target
, drop
);
2307 part
= GetPanePart(part
->pane
->window
);
2311 bool insert_dock_row
= false;
2312 int insert_row
= part
->pane
->dock_row
;
2313 int insert_dir
= part
->pane
->dock_direction
;
2314 int insert_layer
= part
->pane
->dock_layer
;
2316 switch (part
->pane
->dock_direction
)
2318 case wxAUI_DOCK_TOP
:
2319 if (pt
.y
>= part
->rect
.y
&&
2320 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2321 insert_dock_row
= true;
2323 case wxAUI_DOCK_BOTTOM
:
2324 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2325 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2326 insert_dock_row
= true;
2328 case wxAUI_DOCK_LEFT
:
2329 if (pt
.x
>= part
->rect
.x
&&
2330 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2331 insert_dock_row
= true;
2333 case wxAUI_DOCK_RIGHT
:
2334 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2335 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2336 insert_dock_row
= true;
2338 case wxAUI_DOCK_CENTER
:
2340 // "new row pixels" will be set to the default, but
2341 // must never exceed 20% of the window size
2342 int new_row_pixels_x
= auiNewRowPixels
;
2343 int new_row_pixels_y
= auiNewRowPixels
;
2345 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2346 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2348 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2349 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2352 // determine if the mouse pointer is in a location that
2353 // will cause a new row to be inserted. The hot spot positions
2354 // are along the borders of the center pane
2357 insert_dock_row
= true;
2358 if (pt
.x
>= part
->rect
.x
&&
2359 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2360 insert_dir
= wxAUI_DOCK_LEFT
;
2362 if (pt
.y
>= part
->rect
.y
&&
2363 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2364 insert_dir
= wxAUI_DOCK_TOP
;
2366 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2367 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2368 insert_dir
= wxAUI_DOCK_RIGHT
;
2370 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2371 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2372 insert_dir
= wxAUI_DOCK_BOTTOM
;
2376 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2380 if (insert_dock_row
)
2382 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2383 drop
.Dock().Direction(insert_dir
).
2384 Layer(insert_layer
).
2387 return ProcessDockResult(target
, drop
);
2390 // determine the mouse offset and the pane size, both in the
2391 // direction of the dock itself, and perpendicular to the dock
2395 if (part
->orientation
== wxVERTICAL
)
2397 offset
= pt
.y
- part
->rect
.y
;
2398 size
= part
->rect
.GetHeight();
2402 offset
= pt
.x
- part
->rect
.x
;
2403 size
= part
->rect
.GetWidth();
2406 int drop_position
= part
->pane
->dock_pos
;
2408 // if we are in the top/left part of the pane,
2409 // insert the pane before the pane being hovered over
2410 if (offset
<= size
/2)
2412 drop_position
= part
->pane
->dock_pos
;
2414 part
->pane
->dock_direction
,
2415 part
->pane
->dock_layer
,
2416 part
->pane
->dock_row
,
2417 part
->pane
->dock_pos
);
2420 // if we are in the bottom/right part of the pane,
2421 // insert the pane before the pane being hovered over
2422 if (offset
> size
/2)
2424 drop_position
= part
->pane
->dock_pos
+1;
2426 part
->pane
->dock_direction
,
2427 part
->pane
->dock_layer
,
2428 part
->pane
->dock_row
,
2429 part
->pane
->dock_pos
+1);
2433 Direction(part
->dock
->dock_direction
).
2434 Layer(part
->dock
->dock_layer
).
2435 Row(part
->dock
->dock_row
).
2436 Position(drop_position
);
2437 return ProcessDockResult(target
, drop
);
2444 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2446 if (!m_hint_wnd
|| m_hint_fadeamt
>= 50)
2448 m_hint_fadetimer
.Stop();
2452 m_hint_fadeamt
+= 5;
2453 MakeWindowTransparent(m_hint_wnd
, m_hint_fadeamt
);
2456 void wxFrameManager::ShowHint(const wxRect
& rect
)
2458 #if defined(__WXMSW__) || defined(__WXMAC__)
2459 // First, determine if the operating system can handle transparency.
2460 // Transparency is available on Win2000 and above
2462 static int os_type
= -1;
2463 static int ver_major
= -1;
2466 os_type
= ::wxGetOsVersion(&ver_major
);
2468 // If the transparent flag is set, and the OS supports it,
2469 // go ahead and use a transparent hint
2471 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0
2473 && os_type
== wxWINDOWS_NT
&& ver_major
>= 5
2477 if (m_last_hint
== rect
)
2481 int initial_fade
= 50;
2482 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2485 if (m_hint_wnd
== NULL
)
2487 wxPoint pt
= rect
.GetPosition();
2488 wxSize size
= rect
.GetSize();
2489 #if defined(__WXMSW__)
2490 m_hint_wnd
= new wxFrame(m_frame
, -1, wxEmptyString
, pt
, size
,
2491 wxFRAME_TOOL_WINDOW
|
2492 wxFRAME_FLOAT_ON_PARENT
|
2493 wxFRAME_NO_TASKBAR
|
2496 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2497 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
2498 #elif defined(__WXMAC__)
2499 // Using a miniframe with float and tool styles keeps the parent
2500 // frame activated and highlighted as such...
2501 m_hint_wnd
= new wxMiniFrame(m_frame
, -1, wxEmptyString
, pt
, size
,
2502 wxFRAME_FLOAT_ON_PARENT
2503 | wxFRAME_TOOL_WINDOW
2506 // Can't set the bg colour of a Frame in wxMac
2507 wxPanel
* p
= new wxPanel(m_hint_wnd
);
2509 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
2510 // color that is really hard to see, especially transparent.
2511 // Until a better system color is decided upon we'll just use
2513 p
->SetBackgroundColour(*wxBLUE
);
2517 // if we are dragging a floating pane, set the focus
2518 // back to that floating pane (otherwise it becomes unfocused)
2519 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2520 m_action_window
->SetFocus();
2525 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2526 m_hint_wnd
->SetSize(rect
);
2527 m_hint_wnd
->Raise();
2530 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2532 // start fade in timer
2534 m_hint_fadetimer
.SetOwner(this, 101);
2535 m_hint_fadetimer
.Start(5);
2542 if (m_last_hint
!= rect
)
2544 // remove the last hint rectangle
2550 wxScreenDC screendc
;
2551 wxRegion
clip(1, 1, 10000, 10000);
2553 // clip all floating windows, so we don't draw over them
2555 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2557 wxPaneInfo
& pane
= m_panes
.Item(i
);
2559 if (pane
.IsFloating() &&
2560 pane
.frame
->IsShown())
2562 wxRect rect
= pane
.frame
->GetRect();
2564 // wxGTK returns the client size, not the whole frame size
2570 clip
.Subtract(rect
);
2574 screendc
.SetClippingRegion(clip
);
2576 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2577 wxBrush
brush(stipple
);
2578 screendc
.SetBrush(brush
);
2579 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2581 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2582 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2583 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2584 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2587 void wxFrameManager::HideHint()
2589 // hides a transparent window hint, if there is one
2592 MakeWindowTransparent(m_hint_wnd
, 0);
2593 m_hint_fadetimer
.Stop();
2594 m_last_hint
= wxRect();
2598 // hides a painted hint by redrawing the frame window
2599 if (!m_last_hint
.IsEmpty())
2603 m_last_hint
= wxRect();
2609 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2610 // determine the exact position the pane would be at were if dropped. If
2611 // the pame would indeed become docked at the specified drop point,
2612 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2613 // "pane_window" is the window pointer of the pane being dragged, pt is
2614 // the mouse position, in client coordinates
2615 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2617 const wxPoint
& offset
)
2621 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2622 // we will create a new temporary layout and then measure the resulting
2623 // rectangle; we will create a copy of the docking structures (m_dock)
2624 // so that we don't modify the real thing on screen
2626 int i
, pane_count
, part_count
;
2627 wxDockInfoArray docks
;
2628 wxPaneInfoArray panes
;
2629 wxDockUIPartArray uiparts
;
2630 wxPaneInfo hint
= GetPane(pane_window
);
2631 hint
.name
= wxT("__HINT__");
2637 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2639 // remove any pane already there which bears the same window;
2640 // this happens when you are moving a pane around in a dock
2641 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2643 if (panes
.Item(i
).window
== pane_window
)
2645 RemovePaneFromDocks(docks
, panes
.Item(i
));
2651 // find out where the new pane would be
2652 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2660 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2661 wxSize client_size
= m_frame
->GetClientSize();
2662 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2665 for (i
= 0, part_count
= uiparts
.GetCount();
2666 i
< part_count
; ++i
)
2668 wxDockUIPart
& part
= uiparts
.Item(i
);
2670 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2671 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2673 rect
= wxRect(part
.sizer_item
->GetPosition(),
2674 part
.sizer_item
->GetSize());
2687 // actually show the hint rectangle on the screen
2688 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2692 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2694 // try to find the pane
2695 wxPaneInfo
& pane
= GetPane(wnd
);
2696 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2698 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2699 MakeWindowTransparent(pane
.frame
, 150);
2702 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
)
2704 // try to find the pane
2705 wxPaneInfo
& pane
= GetPane(wnd
);
2706 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2708 wxPoint pt
= ::wxGetMousePosition();
2709 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2711 // calculate the offset from the upper left-hand corner
2712 // of the frame to the mouse pointer
2713 wxPoint frame_pos
= pane
.frame
->GetPosition();
2714 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2716 // no hint for toolbar floating windows
2717 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
2719 if (m_action
== actionDragFloatingPane
)
2721 wxDockInfoArray docks
;
2722 wxPaneInfoArray panes
;
2723 wxDockUIPartArray uiparts
;
2724 wxPaneInfo hint
= pane
;
2726 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2728 // find out where the new pane would be
2729 if (!DoDrop(docks
, panes
, hint
, client_pt
))
2731 if (hint
.IsFloating())
2735 m_action
= actionDragToolbarPane
;
2736 m_action_window
= pane
.window
;
2745 // if a key modifier is pressed while dragging the frame,
2746 // don't dock the window
2747 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2754 DrawHintRect(wnd
, client_pt
, action_offset
);
2757 // this cleans up some screen artifacts that are caused on GTK because
2758 // we aren't getting the exact size of the window (see comment
2768 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
)
2770 // try to find the pane
2771 wxPaneInfo
& pane
= GetPane(wnd
);
2772 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2774 wxPoint pt
= ::wxGetMousePosition();
2775 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2777 // calculate the offset from the upper left-hand corner
2778 // of the frame to the mouse pointer
2779 wxPoint frame_pos
= pane
.frame
->GetPosition();
2780 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2783 // if a key modifier is pressed while dragging the frame,
2784 // don't dock the window
2785 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2792 // do the drop calculation
2793 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
2795 // if the pane is still floating, update it's floating
2796 // position (that we store)
2797 if (pane
.IsFloating())
2799 pane
.floating_pos
= pane
.frame
->GetPosition();
2801 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2802 MakeWindowTransparent(pane
.frame
, 255);
2810 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
2812 // try to find the pane
2813 wxPaneInfo
& pane
= GetPane(wnd
);
2814 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2816 pane
.floating_size
= size
;
2820 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
2822 // try to find the pane
2823 wxPaneInfo
& pane
= GetPane(wnd
);
2824 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2827 // fire pane close event
2828 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
2830 e
.SetCanVeto(evt
.CanVeto());
2840 // reparent the pane window back to us and
2841 // prepare the frame window for destruction
2842 pane
.window
->Show(false);
2843 pane
.window
->Reparent(m_frame
);
2851 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
2853 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
2855 // try to find the pane
2856 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
2858 SetActivePane(m_panes
, wnd
);
2863 // OnRender() draws all of the pane captions, sashes,
2864 // backgrounds, captions, grippers, pane borders and buttons.
2865 // It renders the entire user interface.
2867 void wxFrameManager::OnRender(wxFrameManagerEvent
& evt
)
2869 wxDC
* dc
= evt
.GetDC();
2875 for (i
= 0, part_count
= m_uiparts
.GetCount();
2876 i
< part_count
; ++i
)
2878 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2880 // don't draw hidden pane items
2881 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
2886 case wxDockUIPart::typeDockSizer
:
2887 case wxDockUIPart::typePaneSizer
:
2888 m_art
->DrawSash(*dc
, part
.orientation
, part
.rect
);
2890 case wxDockUIPart::typeBackground
:
2891 m_art
->DrawBackground(*dc
, part
.orientation
, part
.rect
);
2893 case wxDockUIPart::typeCaption
:
2894 m_art
->DrawCaption(*dc
, part
.pane
->caption
, part
.rect
, *part
.pane
);
2896 case wxDockUIPart::typeGripper
:
2897 m_art
->DrawGripper(*dc
, part
.rect
, *part
.pane
);
2899 case wxDockUIPart::typePaneBorder
:
2900 m_art
->DrawBorder(*dc
, part
.rect
, *part
.pane
);
2902 case wxDockUIPart::typePaneButton
:
2903 m_art
->DrawPaneButton(*dc
, part
.button
->button_id
,
2904 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
2911 // Render() fire a render event, which is normally handled by
2912 // wxFrameManager::OnRender(). This allows the render function to
2913 // be overridden via the render event. This can be useful for paintin
2914 // custom graphics in the main window. Default behavior can be
2915 // invoked in the overridden function by calling OnRender()
2917 void wxFrameManager::Render(wxDC
* dc
)
2919 wxFrameManagerEvent
e(wxEVT_AUI_RENDER
);
2924 void wxFrameManager::Repaint(wxDC
* dc
)
2929 m_frame
->Refresh() ;
2935 m_frame
->GetClientSize(&w
, &h
);
2937 // figure out which dc to use; if one
2938 // has been specified, use it, otherwise
2940 wxClientDC
* client_dc
= NULL
;
2943 client_dc
= new wxClientDC(m_frame
);
2947 // if the frame has a toolbar, the client area
2948 // origin will not be (0,0).
2949 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2950 if (pt
.x
!= 0 || pt
.y
!= 0)
2951 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
2953 // render all the items
2956 // if we created a client_dc, delete it
2961 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2963 wxPaintDC
dc(m_frame
);
2967 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
2976 void wxFrameManager::OnSize(wxSizeEvent
& WXUNUSED(event
))
2986 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
2989 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2990 wxCursor cursor
= wxNullCursor
;
2994 if (part
->type
== wxDockUIPart::typeDockSizer
||
2995 part
->type
== wxDockUIPart::typePaneSizer
)
2997 // a dock may not be resized if it has a single
2998 // pane which is not resizable
2999 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3000 part
->dock
->panes
.GetCount() == 1 &&
3001 part
->dock
->panes
.Item(0)->IsFixed())
3004 // panes that may not be resized do not get a sizing cursor
3005 if (part
->pane
&& part
->pane
->IsFixed())
3008 if (part
->orientation
== wxVERTICAL
)
3009 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3011 cursor
= wxCursor(wxCURSOR_SIZENS
);
3013 else if (part
->type
== wxDockUIPart::typeGripper
)
3015 cursor
= wxCursor(wxCURSOR_SIZING
);
3019 event
.SetCursor(cursor
);
3024 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
3025 const wxMouseEvent
& event
)
3027 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3029 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3031 if (hit_test
== button_ui_part
)
3033 if (event
.LeftDown())
3034 state
= wxAUI_BUTTON_STATE_PRESSED
;
3036 state
= wxAUI_BUTTON_STATE_HOVER
;
3040 if (event
.LeftDown())
3041 state
= wxAUI_BUTTON_STATE_HOVER
;
3044 // now repaint the button with hover state
3045 wxClientDC
cdc(m_frame
);
3047 // if the frame has a toolbar, the client area
3048 // origin will not be (0,0).
3049 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3050 if (pt
.x
!= 0 || pt
.y
!= 0)
3051 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3053 m_art
->DrawPaneButton(cdc
,
3054 button_ui_part
->button
->button_id
,
3056 button_ui_part
->rect
,
3060 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
3062 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3065 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3068 if (part
->type
== wxDockUIPart::typeDockSizer
||
3069 part
->type
== wxDockUIPart::typePaneSizer
)
3071 // a dock may not be resized if it has a single
3072 // pane which is not resizable
3073 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3074 part
->dock
->panes
.GetCount() == 1 &&
3075 part
->dock
->panes
.Item(0)->IsFixed())
3078 // panes that may not be resized should be ignored here
3079 if (part
->pane
&& part
->pane
->IsFixed())
3082 m_action
= actionResize
;
3083 m_action_part
= part
;
3084 m_action_hintrect
= wxRect();
3085 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3086 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3087 event
.m_y
- part
->rect
.y
);
3088 m_frame
->CaptureMouse();
3090 else if (part
->type
== wxDockUIPart::typePaneButton
)
3092 m_action
= actionClickButton
;
3093 m_action_part
= part
;
3094 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3095 m_frame
->CaptureMouse();
3097 UpdateButtonOnScreen(part
, event
);
3099 else if (part
->type
== wxDockUIPart::typeCaption
||
3100 part
->type
== wxDockUIPart::typeGripper
)
3102 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3104 // set the caption as active
3105 SetActivePane(m_panes
, part
->pane
->window
);
3109 m_action
= actionClickCaption
;
3110 m_action_part
= part
;
3111 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3112 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3113 event
.m_y
- part
->rect
.y
);
3114 m_frame
->CaptureMouse();
3134 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3136 if (m_action
== actionResize
)
3138 m_frame
->ReleaseMouse();
3140 // get rid of the hint rectangle
3142 DrawResizeHint(dc
, m_action_hintrect
);
3144 // resize the dock or the pane
3145 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3147 wxRect
& rect
= m_action_part
->dock
->rect
;
3149 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3150 event
.m_y
- m_action_offset
.y
);
3152 switch (m_action_part
->dock
->dock_direction
)
3154 case wxAUI_DOCK_LEFT
:
3155 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3157 case wxAUI_DOCK_TOP
:
3158 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3160 case wxAUI_DOCK_RIGHT
:
3161 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3162 new_pos
.x
- m_action_part
->rect
.GetWidth();
3164 case wxAUI_DOCK_BOTTOM
:
3165 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3166 new_pos
.y
- m_action_part
->rect
.GetHeight();
3173 else if (m_action_part
&&
3174 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3176 wxDockInfo
& dock
= *m_action_part
->dock
;
3177 wxPaneInfo
& pane
= *m_action_part
->pane
;
3179 int total_proportion
= 0;
3180 int dock_pixels
= 0;
3181 int new_pixsize
= 0;
3183 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3184 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3185 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3187 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3188 event
.m_y
- m_action_offset
.y
);
3190 // determine the pane rectangle by getting the pane part
3191 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3192 wxASSERT_MSG(pane_part
,
3193 wxT("Pane border part not found -- shouldn't happen"));
3195 // determine the new pixel size that the user wants;
3196 // this will help us recalculate the pane's proportion
3197 if (dock
.IsHorizontal())
3198 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3200 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3202 // determine the size of the dock, based on orientation
3203 if (dock
.IsHorizontal())
3204 dock_pixels
= dock
.rect
.GetWidth();
3206 dock_pixels
= dock
.rect
.GetHeight();
3208 // determine the total proportion of all resizable panes,
3209 // and the total size of the dock minus the size of all
3211 int i
, dock_pane_count
= dock
.panes
.GetCount();
3212 int pane_position
= -1;
3213 for (i
= 0; i
< dock_pane_count
; ++i
)
3215 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3216 if (p
.window
== pane
.window
)
3219 // while we're at it, subtract the pane sash
3220 // width from the dock width, because this would
3221 // skew our proportion calculations
3223 dock_pixels
-= sash_size
;
3225 // also, the whole size (including decorations) of
3226 // all fixed panes must also be subtracted, because they
3227 // are not part of the proportion calculation
3230 if (dock
.IsHorizontal())
3231 dock_pixels
-= p
.best_size
.x
;
3233 dock_pixels
-= p
.best_size
.y
;
3237 total_proportion
+= p
.dock_proportion
;
3241 // find a pane in our dock to 'steal' space from or to 'give'
3242 // space to -- this is essentially what is done when a pane is
3243 // resized; the pane should usually be the first non-fixed pane
3244 // to the right of the action pane
3245 int borrow_pane
= -1;
3246 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3248 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3257 // demand that the pane being resized is found in this dock
3258 // (this assert really never should be raised)
3259 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3261 // prevent division by zero
3262 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3264 m_action
= actionNone
;
3268 // calculate the new proportion of the pane
3269 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3271 // default minimum size
3274 // check against the pane's minimum size, if specified. please note
3275 // that this is not enough to ensure that the minimum size will
3276 // not be violated, because the whole frame might later be shrunk,
3277 // causing the size of the pane to violate it's minimum size
3278 if (pane
.min_size
.IsFullySpecified())
3282 if (pane
.HasBorder())
3283 min_size
+= (pane_border_size
*2);
3285 // calculate minimum size with decorations (border,caption)
3286 if (pane_part
->orientation
== wxVERTICAL
)
3288 min_size
+= pane
.min_size
.y
;
3289 if (pane
.HasCaption())
3290 min_size
+= caption_size
;
3294 min_size
+= pane
.min_size
.x
;
3299 // for some reason, an arithmatic error somewhere is causing
3300 // the proportion calculations to always be off by 1 pixel;
3301 // for now we will add the 1 pixel on, but we really should
3302 // determine what's causing this.
3305 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3307 if (new_proportion
< min_proportion
)
3308 new_proportion
= min_proportion
;
3312 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3314 // borrow the space from our neighbor pane to the
3315 // right or bottom (depending on orientation)
3316 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3317 pane
.dock_proportion
= new_proportion
;
3324 else if (m_action
== actionClickButton
)
3326 m_hover_button
= NULL
;
3327 m_frame
->ReleaseMouse();
3328 UpdateButtonOnScreen(m_action_part
, event
);
3330 // make sure we're still over the item that was originally clicked
3331 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3333 // fire button-click event
3334 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3335 e
.SetPane(m_action_part
->pane
);
3336 e
.SetButton(m_action_part
->button
->button_id
);
3340 else if (m_action
== actionClickCaption
)
3342 m_frame
->ReleaseMouse();
3344 else if (m_action
== actionDragFloatingPane
)
3346 m_frame
->ReleaseMouse();
3348 else if (m_action
== actionDragToolbarPane
)
3350 m_frame
->ReleaseMouse();
3352 wxPaneInfo
& pane
= GetPane(m_action_window
);
3353 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3355 // save the new positions
3356 wxDockInfoPtrArray docks
;
3357 FindDocks(m_docks
, pane
.dock_direction
,
3358 pane
.dock_layer
, pane
.dock_row
, docks
);
3359 if (docks
.GetCount() == 1)
3361 wxDockInfo
& dock
= *docks
.Item(0);
3363 wxArrayInt pane_positions
, pane_sizes
;
3364 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3366 int i
, dock_pane_count
= dock
.panes
.GetCount();
3367 for (i
= 0; i
< dock_pane_count
; ++i
)
3368 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3371 pane
.state
&= ~wxPaneInfo::actionPane
;
3379 m_action
= actionNone
;
3380 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3384 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3386 // sometimes when Update() is called from inside this method,
3387 // a spurious mouse move event is generated; this check will make
3388 // sure that only real mouse moves will get anywhere in this method;
3389 // this appears to be a bug somewhere, and I don't know where the
3390 // mouse move event is being generated. only verified on MSW
3392 wxPoint mouse_pos
= event
.GetPosition();
3393 if (m_last_mouse_move
== mouse_pos
)
3395 m_last_mouse_move
= mouse_pos
;
3398 if (m_action
== actionResize
)
3400 wxPoint pos
= m_action_part
->rect
.GetPosition();
3401 if (m_action_part
->orientation
== wxHORIZONTAL
)
3402 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3404 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3406 wxRect
rect(m_frame
->ClientToScreen(pos
),
3407 m_action_part
->rect
.GetSize());
3410 if (!m_action_hintrect
.IsEmpty())
3411 DrawResizeHint(dc
, m_action_hintrect
);
3412 DrawResizeHint(dc
, rect
);
3413 m_action_hintrect
= rect
;
3415 else if (m_action
== actionClickCaption
)
3417 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3418 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3420 // caption has been clicked. we need to check if the mouse
3421 // is now being dragged. if it is, we need to change the
3422 // mouse action to 'drag'
3423 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3424 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3426 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3428 if (!pane_info
->IsToolbar())
3430 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3431 pane_info
->IsFloatable())
3433 m_action
= actionDragFloatingPane
;
3435 // set initial float position
3436 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3437 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3438 pt
.y
- m_action_offset
.y
);
3443 m_action_window
= pane_info
->frame
;
3445 // action offset is used here to make it feel "natural" to the user
3446 // to drag a docked pane and suddenly have it become a floating frame.
3447 // Sometimes, however, the offset where the user clicked on the docked
3448 // caption is bigger than the width of the floating frame itself, so
3449 // in that case we need to set the action offset to a sensible value
3450 wxSize frame_size
= m_action_window
->GetSize();
3451 if (frame_size
.x
<= m_action_offset
.x
)
3452 m_action_offset
.x
= 30;
3457 m_action
= actionDragToolbarPane
;
3458 m_action_window
= pane_info
->window
;
3462 else if (m_action
== actionDragFloatingPane
)
3464 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3465 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3466 pt
.y
- m_action_offset
.y
);
3468 else if (m_action
== actionDragToolbarPane
)
3470 wxPaneInfo
& pane
= GetPane(m_action_window
);
3471 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3473 pane
.state
|= wxPaneInfo::actionPane
;
3475 wxPoint pt
= event
.GetPosition();
3476 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3478 // if DoDrop() decided to float the pane, set up
3479 // the floating pane's initial position
3480 if (pane
.IsFloating())
3482 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3483 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3484 pt
.y
- m_action_offset
.y
);
3487 // this will do the actiual move operation;
3488 // in the case that the pane has been floated,
3489 // this call will create the floating pane
3490 // and do the reparenting
3493 // if the pane has been floated, change the mouse
3494 // action actionDragFloatingPane so that subsequent
3495 // EVT_MOTION() events will move the floating pane
3496 if (pane
.IsFloating())
3498 pane
.state
&= ~wxPaneInfo::actionPane
;
3499 m_action
= actionDragFloatingPane
;
3500 m_action_window
= pane
.frame
;
3505 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3506 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3508 if (part
!= m_hover_button
)
3510 // make the old button normal
3512 UpdateButtonOnScreen(m_hover_button
, event
);
3514 // mouse is over a button, so repaint the
3515 // button in hover mode
3516 UpdateButtonOnScreen(part
, event
);
3517 m_hover_button
= part
;
3524 m_hover_button
= NULL
;
3535 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3539 m_hover_button
= NULL
;
3544 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3546 // when a child pane has it's focus set, we should change the
3547 // pane's active state to reflect this. (this is only true if
3548 // active panes are allowed by the owner)
3549 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3551 if (GetPane(event
.GetWindow()).IsOk())
3553 SetActivePane(m_panes
, event
.GetWindow());
3560 // OnPaneButton() is an event handler that is called
3561 // when a pane button has been pressed.
3562 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& evt
)
3564 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3566 wxPaneInfo
& pane
= *(evt
.pane
);
3568 if (evt
.button
== wxPaneInfo::buttonClose
)
3570 // fire pane close event
3571 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3572 e
.SetPane(evt
.pane
);
3581 else if (evt
.button
== wxPaneInfo::buttonPin
)
3583 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&