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(wxFrame
* frame
, unsigned int flags
)
396 m_action
= actionNone
;
397 m_last_mouse_move
= wxPoint();
398 m_hover_button
= NULL
;
399 m_art
= new wxDefaultDockArt
;
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 // SetFrame() is usually called once when the frame
504 // manager class is being initialized. "frame" specifies
505 // the frame which should be managed by the frame mananger
506 void wxFrameManager::SetFrame(wxWindow
* frame
)
508 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
511 m_frame
->PushEventHandler(this);
514 // if the owner is going to manage an MDI parent frame,
515 // we need to add the MDI client window as the default
518 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
520 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
521 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
523 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
525 AddPane(client_window
,
526 wxPaneInfo().Name(wxT("mdiclient")).
527 CenterPane().PaneBorder(false));
533 // UnInit() must be called, usually in the destructor
534 // of the frame class. If it is not called, usually this
535 // will result in a crash upon program exit
536 void wxFrameManager::UnInit()
538 m_frame
->RemoveEventHandler(this);
541 // GetFrame() returns the window pointer being managed by wxFrameManager
542 wxWindow
* wxFrameManager::GetFrame() const
547 wxDockArt
* wxFrameManager::GetArtProvider() const
552 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
554 // first, give the owner frame a chance to override
557 if (m_frame
->ProcessEvent(event
))
564 // SetArtProvider() instructs wxFrameManager to use the
565 // specified art provider for all drawing calls. This allows
566 // plugable look-and-feel features. The pointer that is
567 // passed to this method subsequently belongs to wxFrameManager,
568 // and is deleted in the frame manager destructor
569 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
571 // delete the last art provider, if any
574 // assign the new art provider
575 m_art
= art_provider
;
579 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
581 // check if the pane has a valid window
585 // check if the pane already exists
586 if (GetPane(pane_info
.window
).IsOk())
589 m_panes
.Add(pane_info
);
591 wxPaneInfo
& pinfo
= m_panes
.Last();
593 // set the pane window
594 pinfo
.window
= window
;
596 // if the pane's name identifier is blank, create a random string
597 if (pinfo
.name
.empty())
599 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
600 ((unsigned long)pinfo
.window
) & 0xffffffff,
601 (unsigned int)time(NULL
),
603 (unsigned int)GetTickCount(),
605 (unsigned int)clock(),
607 (unsigned long)m_panes
.GetCount());
610 // set initial proportion (if not already set)
611 if (pinfo
.dock_proportion
== 0)
612 pinfo
.dock_proportion
= 100000;
614 if (pinfo
.HasCloseButton() &&
615 pinfo
.buttons
.size() == 0)
618 button
.button_id
= wxPaneInfo::buttonClose
;
619 pinfo
.buttons
.Add(button
);
622 if (pinfo
.best_size
== wxDefaultSize
&&
625 pinfo
.best_size
= pinfo
.window
->GetClientSize();
627 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
629 // GetClientSize() doesn't get the best size for
630 // a toolbar under some newer versions of wxWidgets,
631 // so use GetBestSize()
632 pinfo
.best_size
= pinfo
.window
->GetBestSize();
634 // for some reason, wxToolBar::GetBestSize() is returning
635 // a size that is a pixel shy of the correct amount.
636 // I believe this to be the correct action, until
637 // wxToolBar::GetBestSize() is fixed. Is this assumption
642 if (pinfo
.min_size
!= wxDefaultSize
)
644 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
645 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
646 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
647 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
654 bool wxFrameManager::AddPane(wxWindow
* window
,
656 const wxString
& caption
)
659 pinfo
.Caption(caption
);
662 case wxTOP
: pinfo
.Top(); break;
663 case wxBOTTOM
: pinfo
.Bottom(); break;
664 case wxLEFT
: pinfo
.Left(); break;
665 case wxRIGHT
: pinfo
.Right(); break;
666 case wxCENTER
: pinfo
.CenterPane(); break;
668 return AddPane(window
, pinfo
);
671 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
674 // shift the panes around, depending on the insert level
675 switch (insert_level
)
677 case wxAUI_INSERT_PANE
:
678 DoInsertPane(m_panes
,
679 pane_info
.dock_direction
,
680 pane_info
.dock_layer
,
684 case wxAUI_INSERT_ROW
:
685 DoInsertDockRow(m_panes
,
686 pane_info
.dock_direction
,
687 pane_info
.dock_layer
,
690 case wxAUI_INSERT_DOCK
:
691 DoInsertDockLayer(m_panes
,
692 pane_info
.dock_direction
,
693 pane_info
.dock_layer
);
697 // if the window already exists, we are basically just moving/inserting the
698 // existing window. If it doesn't exist, we need to add it and insert it
699 wxPaneInfo
& existing_pane
= GetPane(window
);
700 if (!existing_pane
.IsOk())
702 return AddPane(window
, pane_info
);
706 if (pane_info
.IsFloating())
708 existing_pane
.Float();
709 if (pane_info
.floating_pos
!= wxDefaultPosition
)
710 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
711 if (pane_info
.floating_size
!= wxDefaultSize
)
712 existing_pane
.FloatingSize(pane_info
.floating_size
);
716 existing_pane
.Direction(pane_info
.dock_direction
);
717 existing_pane
.Layer(pane_info
.dock_layer
);
718 existing_pane
.Row(pane_info
.dock_row
);
719 existing_pane
.Position(pane_info
.dock_pos
);
727 // DetachPane() removes a pane from the frame manager. This
728 // method will not destroy the window that is removed.
729 bool wxFrameManager::DetachPane(wxWindow
* window
)
732 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
734 wxPaneInfo
& p
= m_panes
.Item(i
);
735 if (p
.window
== window
)
739 // we have a floating frame which is being detached. We need to
740 // reparent it to m_frame and destroy the floating frame
743 p
.window
->SetSize(1,1);
744 p
.frame
->Show(false);
746 // reparent to m_frame and destroy the pane
747 p
.window
->Reparent(m_frame
);
748 p
.frame
->SetSizer(NULL
);
760 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
761 // in the input string. This is an internal functions which is
762 // used for saving perspectives
763 static wxString
EscapeDelimiters(const wxString
& s
)
766 result
.Alloc(s
.length());
767 const wxChar
* ch
= s
.c_str();
770 if (*ch
== wxT(';') || *ch
== wxT('|'))
779 // SavePerspective() saves all pane information as a single string.
780 // This string may later be fed into LoadPerspective() to restore
781 // all pane settings. This save and load mechanism allows an
782 // exact pane configuration to be saved and restored at a later time
784 wxString
wxFrameManager::SavePerspective()
788 result
= wxT("layout1|");
790 int pane_i
, pane_count
= m_panes
.GetCount();
791 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
793 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
795 result
+= wxT("name=");
796 result
+= EscapeDelimiters(pane
.name
);
799 result
+= wxT("caption=");
800 result
+= EscapeDelimiters(pane
.caption
);
803 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
804 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
805 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
806 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
807 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
808 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
809 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
810 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
811 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
812 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
813 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
814 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
815 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
816 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
817 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
818 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
822 int dock_i
, dock_count
= m_docks
.GetCount();
823 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
825 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
827 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
828 dock
.dock_direction
, dock
.dock_layer
,
829 dock
.dock_row
, dock
.size
);
835 // LoadPerspective() loads a layout which was saved with SavePerspective()
836 // If the "update" flag parameter is true, the GUI will immediately be updated
838 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
840 wxString input
= layout
;
843 // check layout string version
844 part
= input
.BeforeFirst(wxT('|'));
845 input
= input
.AfterFirst(wxT('|'));
848 if (part
!= wxT("layout1"))
852 // mark all panes currently managed as docked and hidden
853 int pane_i
, pane_count
= m_panes
.GetCount();
854 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
855 m_panes
.Item(pane_i
).Dock().Hide();
857 // clear out the dock array; this will be reconstructed
860 // replace escaped characters so we can
861 // split up the string easily
862 input
.Replace(wxT("\\|"), wxT("\a"));
863 input
.Replace(wxT("\\;"), wxT("\b"));
869 wxString pane_part
= input
.BeforeFirst(wxT('|'));
870 input
= input
.AfterFirst(wxT('|'));
871 pane_part
.Trim(true);
873 // if the string is empty, we're done parsing
874 if (pane_part
.empty())
878 if (pane_part
.Left(9) == wxT("dock_size"))
880 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
881 wxString value
= pane_part
.AfterFirst(wxT('='));
883 long dir
, layer
, row
, size
;
884 wxString piece
= val_name
.AfterFirst(wxT('('));
885 piece
= piece
.BeforeLast(wxT(')'));
886 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
887 piece
= piece
.AfterFirst(wxT(','));
888 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
889 piece
.AfterFirst(wxT(',')).ToLong(&row
);
893 dock
.dock_direction
= dir
;
894 dock
.dock_layer
= layer
;
903 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
904 pane_part
= pane_part
.AfterFirst(wxT(';'));
905 wxString val_name
= val_part
.BeforeFirst(wxT('='));
906 wxString value
= val_part
.AfterFirst(wxT('='));
907 val_name
.MakeLower();
909 val_name
.Trim(false);
913 if (val_name
.empty())
916 if (val_name
== wxT("name"))
918 else if (val_name
== wxT("caption"))
919 pane
.caption
= value
;
920 else if (val_name
== wxT("state"))
921 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
922 else if (val_name
== wxT("dir"))
923 pane
.dock_direction
= wxAtoi(value
.c_str());
924 else if (val_name
== wxT("layer"))
925 pane
.dock_layer
= wxAtoi(value
.c_str());
926 else if (val_name
== wxT("row"))
927 pane
.dock_row
= wxAtoi(value
.c_str());
928 else if (val_name
== wxT("pos"))
929 pane
.dock_pos
= wxAtoi(value
.c_str());
930 else if (val_name
== wxT("prop"))
931 pane
.dock_proportion
= wxAtoi(value
.c_str());
932 else if (val_name
== wxT("bestw"))
933 pane
.best_size
.x
= wxAtoi(value
.c_str());
934 else if (val_name
== wxT("besth"))
935 pane
.best_size
.y
= wxAtoi(value
.c_str());
936 else if (val_name
== wxT("minw"))
937 pane
.min_size
.x
= wxAtoi(value
.c_str());
938 else if (val_name
== wxT("minh"))
939 pane
.min_size
.y
= wxAtoi(value
.c_str());
940 else if (val_name
== wxT("maxw"))
941 pane
.max_size
.x
= wxAtoi(value
.c_str());
942 else if (val_name
== wxT("maxh"))
943 pane
.max_size
.y
= wxAtoi(value
.c_str());
944 else if (val_name
== wxT("floatx"))
945 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
946 else if (val_name
== wxT("floaty"))
947 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
948 else if (val_name
== wxT("floatw"))
949 pane
.floating_size
.x
= wxAtoi(value
.c_str());
950 else if (val_name
== wxT("floath"))
951 pane
.floating_size
.y
= wxAtoi(value
.c_str());
953 wxFAIL_MSG(wxT("Bad Perspective String"));
957 // replace escaped characters so we can
958 // split up the string easily
959 pane
.name
.Replace(wxT("\a"), wxT("|"));
960 pane
.name
.Replace(wxT("\b"), wxT(";"));
961 pane
.caption
.Replace(wxT("\a"), wxT("|"));
962 pane
.caption
.Replace(wxT("\b"), wxT(";"));
964 wxPaneInfo
& p
= GetPane(pane
.name
);
967 // the pane window couldn't be found
968 // in the existing layout
972 pane
.window
= p
.window
;
973 pane
.frame
= p
.frame
;
974 pane
.buttons
= p
.buttons
;
985 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
986 wxArrayInt
& positions
,
989 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
990 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
991 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
996 int offset
, action_pane
= -1;
997 int pane_i
, pane_count
= dock
.panes
.GetCount();
999 // find the pane marked as our action pane
1000 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1002 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1004 if (pane
.state
& wxPaneInfo::actionPane
)
1006 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1007 action_pane
= pane_i
;
1011 // set up each panes default position, and
1012 // determine the size (width or height, depending
1013 // on the dock's orientation) of each pane
1014 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1016 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1017 positions
.Add(pane
.dock_pos
);
1020 if (pane
.HasBorder())
1021 size
+= (pane_border_size
*2);
1023 if (dock
.IsHorizontal())
1025 if (pane
.HasGripper() && !pane
.HasGripperTop())
1026 size
+= gripper_size
;
1027 size
+= pane
.best_size
.x
;
1031 if (pane
.HasGripper() && pane
.HasGripperTop())
1032 size
+= gripper_size
;
1034 if (pane
.HasCaption())
1035 size
+= caption_size
;
1036 size
+= pane
.best_size
.y
;
1042 // if there is no action pane, just return the default
1043 // positions (as specified in pane.pane_pos)
1044 if (action_pane
== -1)
1048 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1050 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1055 positions
[pane_i
] -= -amount
;
1057 offset
+= sizes
[pane_i
];
1060 // if the dock mode is fixed, make sure none of the panes
1061 // overlap; we will bump panes that overlap
1063 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1065 int amount
= positions
[pane_i
] - offset
;
1069 positions
[pane_i
] += -amount
;
1071 offset
+= sizes
[pane_i
];
1076 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1079 wxDockUIPartArray
& uiparts
,
1083 wxSizerItem
* sizer_item
;
1085 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1086 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1087 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1088 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1090 // find out the orientation of the item (orientation for panes
1091 // is the same as the dock's orientation)
1093 if (dock
.IsHorizontal())
1094 orientation
= wxHORIZONTAL
;
1096 orientation
= wxVERTICAL
;
1098 // this variable will store the proportion
1099 // value that the pane will receive
1100 int pane_proportion
= pane
.dock_proportion
;
1102 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1103 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1105 if (pane
.HasGripper())
1107 if (pane
.HasGripperTop())
1108 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1110 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1112 part
.type
= wxDockUIPart::typeGripper
;
1116 part
.orientation
= orientation
;
1117 part
.cont_sizer
= horz_pane_sizer
;
1118 part
.sizer_item
= sizer_item
;
1122 if (pane
.HasCaption())
1124 // create the caption sizer
1125 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1127 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1129 part
.type
= wxDockUIPart::typeCaption
;
1133 part
.orientation
= orientation
;
1134 part
.cont_sizer
= vert_pane_sizer
;
1135 part
.sizer_item
= sizer_item
;
1136 int caption_part_idx
= uiparts
.GetCount();
1139 // add pane buttons to the caption
1140 int i
, button_count
;
1141 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1142 i
< button_count
; ++i
)
1144 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1146 sizer_item
= caption_sizer
->Add(pane_button_size
,
1150 part
.type
= wxDockUIPart::typePaneButton
;
1153 part
.button
= &button
;
1154 part
.orientation
= orientation
;
1155 part
.cont_sizer
= caption_sizer
;
1156 part
.sizer_item
= sizer_item
;
1160 // add the caption sizer
1161 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1163 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1166 // add the pane window itself
1169 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1173 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1174 // Don't do this because it breaks the pane size in floating windows
1175 // BIW: Right now commenting this out is causing problems with
1176 // an mdi client window as the center pane.
1177 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1180 part
.type
= wxDockUIPart::typePane
;
1184 part
.orientation
= orientation
;
1185 part
.cont_sizer
= vert_pane_sizer
;
1186 part
.sizer_item
= sizer_item
;
1190 // determine if the pane should have a minimum size; if the pane is
1191 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1192 // if the pane.min_size is set, we must use that value as well
1194 wxSize min_size
= pane
.min_size
;
1197 if (min_size
== wxDefaultSize
)
1199 min_size
= pane
.best_size
;
1200 pane_proportion
= 0;
1204 if (min_size
!= wxDefaultSize
)
1206 vert_pane_sizer
->SetItemMinSize(
1207 vert_pane_sizer
->GetChildren().GetCount()-1,
1208 min_size
.x
, min_size
.y
);
1212 // add the verticle sizer (caption, pane window) to the
1213 // horizontal sizer (gripper, verticle sizer)
1214 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1216 // finally, add the pane sizer to the dock sizer
1218 if (pane
.HasBorder())
1220 // allowing space for the pane's border
1221 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1222 wxEXPAND
| wxALL
, pane_border_size
);
1224 part
.type
= wxDockUIPart::typePaneBorder
;
1228 part
.orientation
= orientation
;
1229 part
.cont_sizer
= cont
;
1230 part
.sizer_item
= sizer_item
;
1235 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1239 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1241 wxDockUIPartArray
& uiparts
,
1244 wxSizerItem
* sizer_item
;
1247 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1248 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1250 // resizable bottom and right docks have a sash before them
1251 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1252 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1254 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1256 part
.type
= wxDockUIPart::typeDockSizer
;
1257 part
.orientation
= orientation
;
1261 part
.cont_sizer
= cont
;
1262 part
.sizer_item
= sizer_item
;
1266 // create the sizer for the dock
1267 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1269 // add each pane to the dock
1270 int pane_i
, pane_count
= dock
.panes
.GetCount();
1274 wxArrayInt pane_positions
, pane_sizes
;
1276 // figure out the real pane positions we will
1277 // use, without modifying the each pane's pane_pos member
1278 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1281 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1283 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1284 int pane_pos
= pane_positions
.Item(pane_i
);
1286 int amount
= pane_pos
- offset
;
1289 if (dock
.IsVertical())
1290 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1292 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1294 part
.type
= wxDockUIPart::typeBackground
;
1298 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1299 part
.cont_sizer
= dock_sizer
;
1300 part
.sizer_item
= sizer_item
;
1306 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1308 offset
+= pane_sizes
.Item(pane_i
);
1311 // at the end add a very small stretchable background area
1312 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1314 part
.type
= wxDockUIPart::typeBackground
;
1318 part
.orientation
= orientation
;
1319 part
.cont_sizer
= dock_sizer
;
1320 part
.sizer_item
= sizer_item
;
1325 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1327 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1329 // if this is not the first pane being added,
1330 // we need to add a pane sizer
1333 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1335 part
.type
= wxDockUIPart::typePaneSizer
;
1337 part
.pane
= dock
.panes
.Item(pane_i
-1);
1339 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1340 part
.cont_sizer
= dock_sizer
;
1341 part
.sizer_item
= sizer_item
;
1345 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1349 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1350 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1352 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1354 part
.type
= wxDockUIPart::typeDock
;
1358 part
.orientation
= orientation
;
1359 part
.cont_sizer
= cont
;
1360 part
.sizer_item
= sizer_item
;
1363 if (dock
.IsHorizontal())
1364 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1366 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1368 // top and left docks have a sash after them
1369 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1370 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1372 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1374 part
.type
= wxDockUIPart::typeDockSizer
;
1378 part
.orientation
= orientation
;
1379 part
.cont_sizer
= cont
;
1380 part
.sizer_item
= sizer_item
;
1385 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1386 wxDockInfoArray
& docks
,
1387 wxDockUIPartArray
& uiparts
,
1390 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1392 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1393 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1394 wxSize cli_size
= m_frame
->GetClientSize();
1395 int i
, dock_count
, pane_count
;
1398 // empty all docks out
1399 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1400 docks
.Item(i
).panes
.Empty();
1402 // iterate through all known panes, filing each
1403 // of them into the appropriate dock. If the
1404 // pane does not exist in the dock, add it
1405 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1407 wxPaneInfo
& p
= panes
.Item(i
);
1409 // find any docks in this layer
1411 wxDockInfoPtrArray arr
;
1412 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1414 if (arr
.GetCount() > 0)
1420 // dock was not found, so we need to create a new one
1422 d
.dock_direction
= p
.dock_direction
;
1423 d
.dock_layer
= p
.dock_layer
;
1424 d
.dock_row
= p
.dock_row
;
1426 dock
= &docks
.Last();
1430 if (p
.IsDocked() && p
.IsShown())
1432 // remove the pane from any existing docks except this one
1433 RemovePaneFromDocks(docks
, p
, dock
);
1435 // pane needs to be added to the dock,
1436 // if it doesn't already exist
1437 if (!FindPaneInDock(*dock
, p
.window
))
1438 dock
->panes
.Add(&p
);
1442 // remove the pane from any existing docks
1443 RemovePaneFromDocks(docks
, p
);
1448 // remove any empty docks
1449 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1451 if (docks
.Item(i
).panes
.GetCount() == 0)
1455 // configure the docks further
1456 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1458 wxDockInfo
& dock
= docks
.Item(i
);
1459 int j
, dock_pane_count
= dock
.panes
.GetCount();
1461 // sort the dock pane array by the pane's
1462 // dock position (dock_pos), in ascending order
1463 dock
.panes
.Sort(PaneSortFunc
);
1465 // for newly created docks, set up their initial size
1470 for (j
= 0; j
< dock_pane_count
; ++j
)
1472 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1473 wxSize pane_size
= pane
.best_size
;
1474 if (pane_size
== wxDefaultSize
)
1475 pane_size
= pane
.min_size
;
1476 if (pane_size
== wxDefaultSize
)
1477 pane_size
= pane
.window
->GetSize();
1479 if (dock
.IsHorizontal())
1480 size
= wxMax(pane_size
.y
, size
);
1482 size
= wxMax(pane_size
.x
, size
);
1485 // add space for the border (two times), but only
1486 // if at least one pane inside the dock has a pane border
1487 for (j
= 0; j
< dock_pane_count
; ++j
)
1489 if (dock
.panes
.Item(j
)->HasBorder())
1491 size
+= (pane_border_size
*2);
1496 // if pane is on the top or bottom, add the caption height,
1497 // but only if at least one pane inside the dock has a caption
1498 if (dock
.IsHorizontal())
1500 for (j
= 0; j
< dock_pane_count
; ++j
)
1502 if (dock
.panes
.Item(j
)->HasCaption())
1504 size
+= caption_size
;
1510 // new dock's size may not be more than 1/3 of the frame size
1511 if (dock
.IsHorizontal())
1512 size
= wxMin(size
, cli_size
.y
/3);
1514 size
= wxMin(size
, cli_size
.x
/3);
1522 // determine the dock's minimum size
1523 bool plus_border
= false;
1524 bool plus_caption
= false;
1525 int dock_min_size
= 0;
1526 for (j
= 0; j
< dock_pane_count
; ++j
)
1528 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1529 if (pane
.min_size
!= wxDefaultSize
)
1531 if (pane
.HasBorder())
1533 if (pane
.HasCaption())
1534 plus_caption
= true;
1535 if (dock
.IsHorizontal())
1537 if (pane
.min_size
.y
> dock_min_size
)
1538 dock_min_size
= pane
.min_size
.y
;
1542 if (pane
.min_size
.x
> dock_min_size
)
1543 dock_min_size
= pane
.min_size
.x
;
1549 dock_min_size
+= (pane_border_size
*2);
1550 if (plus_caption
&& dock
.IsHorizontal())
1551 dock_min_size
+= (caption_size
);
1553 dock
.min_size
= dock_min_size
;
1556 // if the pane's current size is less than it's
1557 // minimum, increase the dock's size to it's minimum
1558 if (dock
.size
< dock
.min_size
)
1559 dock
.size
= dock
.min_size
;
1562 // determine the dock's mode (fixed or proportional);
1563 // determine whether the dock has only toolbars
1564 bool action_pane_marked
= false;
1566 dock
.toolbar
= true;
1567 for (j
= 0; j
< dock_pane_count
; ++j
)
1569 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1570 if (!pane
.IsFixed())
1572 if (!pane
.IsToolbar())
1573 dock
.toolbar
= false;
1574 if (pane
.state
& wxPaneInfo::actionPane
)
1575 action_pane_marked
= true;
1579 // if the dock mode is proportional and not fixed-pixel,
1580 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1581 // e.g. remove gaps like 1, 2, 30, 500
1584 for (j
= 0; j
< dock_pane_count
; ++j
)
1586 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1591 // if the dock mode is fixed, and none of the panes
1592 // are being moved right now, make sure the panes
1593 // do not overlap each other. If they do, we will
1594 // adjust the panes' positions
1595 if (dock
.fixed
&& !action_pane_marked
)
1597 wxArrayInt pane_positions
, pane_sizes
;
1598 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1601 for (j
= 0; j
< dock_pane_count
; ++j
)
1603 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1604 pane
.dock_pos
= pane_positions
[j
];
1606 int amount
= pane
.dock_pos
- offset
;
1610 pane
.dock_pos
+= -amount
;
1612 offset
+= pane_sizes
[j
];
1617 // discover the maximum dock layer
1619 for (i
= 0; i
< dock_count
; ++i
)
1620 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1623 // clear out uiparts
1626 // create a bunch of box sizers,
1627 // from the innermost level outwards.
1628 wxSizer
* cont
= NULL
;
1629 wxSizer
* middle
= NULL
;
1633 for (layer
= 0; layer
<= max_layer
; ++layer
)
1635 wxDockInfoPtrArray arr
;
1637 // find any docks in this layer
1638 FindDocks(docks
, -1, layer
, -1, arr
);
1640 // if there aren't any, skip to the next layer
1644 wxSizer
* old_cont
= cont
;
1646 // create a container which will hold this layer's
1647 // docks (top, bottom, left, right)
1648 cont
= new wxBoxSizer(wxVERTICAL
);
1651 // find any top docks in this layer
1652 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1653 RenumberDockRows(arr
);
1656 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1657 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1661 // fill out the middle layer (which consists
1662 // of left docks, content area and right docks)
1664 middle
= new wxBoxSizer(wxHORIZONTAL
);
1666 // find any left docks in this layer
1667 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1668 RenumberDockRows(arr
);
1671 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1672 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1675 // add content dock (or previous layer's sizer
1679 // find any center docks
1680 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1683 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1684 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1688 // there are no center docks, add a background area
1689 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1691 part
.type
= wxDockUIPart::typeBackground
;
1695 part
.cont_sizer
= middle
;
1696 part
.sizer_item
= sizer_item
;
1702 middle
->Add(old_cont
, 1, wxEXPAND
);
1705 // find any right docks in this layer
1706 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1707 RenumberDockRows(arr
);
1710 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1711 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1714 cont
->Add(middle
, 1, wxEXPAND
);
1718 // find any bottom docks in this layer
1719 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1720 RenumberDockRows(arr
);
1723 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1724 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1731 // no sizer available, because there are no docks,
1732 // therefore we will create a simple background area
1733 cont
= new wxBoxSizer(wxVERTICAL
);
1734 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1736 part
.type
= wxDockUIPart::typeBackground
;
1740 part
.cont_sizer
= middle
;
1741 part
.sizer_item
= sizer_item
;
1745 container
->Add(cont
, 1, wxEXPAND
);
1750 // Update() updates the layout. Whenever changes are made to
1751 // one or more panes, this function should be called. It is the
1752 // external entry point for running the layout engine.
1754 void wxFrameManager::Update()
1757 int i
, pane_count
= m_panes
.GetCount();
1759 // delete old sizer first
1760 m_frame
->SetSizer(NULL
);
1762 // destroy floating panes which have been
1763 // redocked or are becoming non-floating
1764 for (i
= 0; i
< pane_count
; ++i
)
1766 wxPaneInfo
& p
= m_panes
.Item(i
);
1768 if (!p
.IsFloating() && p
.frame
)
1770 // because the pane is no longer in a floating, we need to
1771 // reparent it to m_frame and destroy the floating frame
1774 p
.window
->SetSize(1,1);
1775 p
.frame
->Show(false);
1777 // reparent to m_frame and destroy the pane
1778 p
.window
->Reparent(m_frame
);
1779 p
.frame
->SetSizer(NULL
);
1786 // create a layout for all of the panes
1787 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
1789 // hide or show panes as necessary,
1790 // and float panes as necessary
1791 for (i
= 0; i
< pane_count
; ++i
)
1793 wxPaneInfo
& p
= m_panes
.Item(i
);
1797 if (p
.frame
== NULL
)
1799 // we need to create a frame for this
1800 // pane, which has recently been floated
1801 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
1805 // on MSW and Mac, if the owner desires transparent dragging, and
1806 // the dragging is happening right now, then the floating
1807 // window should have this style by default
1808 if (m_action
== actionDragFloatingPane
&&
1809 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
1810 MakeWindowTransparent(frame
, 150);
1812 frame
->SetPaneWindow(p
);
1822 // frame already exists, make sure it's position
1823 // and size reflect the information in wxPaneInfo
1824 if (p
.frame
->GetPosition() != p
.floating_pos
)
1826 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
1827 wxDefaultCoord
, wxDefaultCoord
,
1828 wxSIZE_USE_EXISTING
);
1829 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
1832 p
.frame
->Show(p
.IsShown());
1837 p
.window
->Show(p
.IsShown());
1840 // if "active panes" are no longer allowed, clear
1841 // any optionActive values from the pane states
1842 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
1844 p
.state
&= ~wxPaneInfo::optionActive
;
1849 // keep track of the old window rectangles so we can
1850 // refresh those windows whose rect has changed
1851 wxAuiRectArray old_pane_rects
;
1852 for (i
= 0; i
< pane_count
; ++i
)
1855 wxPaneInfo
& p
= m_panes
.Item(i
);
1857 if (p
.window
&& p
.IsShown() && p
.IsDocked())
1860 old_pane_rects
.Add(r
);
1866 // apply the new sizer
1867 m_frame
->SetSizer(sizer
);
1868 m_frame
->SetAutoLayout(false);
1873 // now that the frame layout is done, we need to check
1874 // the new pane rectangles against the old rectangles that
1875 // we saved a few lines above here. If the rectangles have
1876 // changed, the corresponding panes must also be updated
1877 for (i
= 0; i
< pane_count
; ++i
)
1879 wxPaneInfo
& p
= m_panes
.Item(i
);
1880 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
1882 if (p
.rect
!= old_pane_rects
[i
])
1884 p
.window
->Refresh();
1893 // set frame's minimum size
1896 // N.B. More work needs to be done on frame minimum sizes;
1897 // this is some intresting code that imposes the minimum size,
1898 // but we may want to include a more flexible mechanism or
1899 // options for multiple minimum-size modes, e.g. strict or lax
1900 wxSize min_size = sizer->GetMinSize();
1901 wxSize frame_size = m_frame->GetSize();
1902 wxSize client_size = m_frame->GetClientSize();
1904 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
1905 min_size.y+frame_size.y-client_size.y );
1907 m_frame->SetMinSize(minframe_size);
1909 if (frame_size.x < minframe_size.x ||
1910 frame_size.y < minframe_size.y)
1911 sizer->Fit(m_frame);
1916 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
1917 // on the frame's main sizer, then measures all the various UI items
1918 // and updates their internal rectangles. This should always be called
1919 // instead of calling m_frame->Layout() directly
1921 void wxFrameManager::DoFrameLayout()
1926 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1928 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1930 // get the rectangle of the UI part
1931 // originally, this code looked like this:
1932 // part.rect = wxRect(part.sizer_item->GetPosition(),
1933 // part.sizer_item->GetSize());
1934 // this worked quite well, with one exception: the mdi
1935 // client window had a "deferred" size variable
1936 // that returned the wrong size. It looks like
1937 // a bug in wx, because the former size of the window
1938 // was being returned. So, we will retrieve the part's
1939 // rectangle via other means
1942 part
.rect
= part
.sizer_item
->GetRect();
1943 int flag
= part
.sizer_item
->GetFlag();
1944 int border
= part
.sizer_item
->GetBorder();
1947 part
.rect
.y
-= border
;
1948 part
.rect
.height
+= border
;
1952 part
.rect
.x
-= border
;
1953 part
.rect
.width
+= border
;
1955 if (flag
& wxBOTTOM
)
1956 part
.rect
.height
+= border
;
1958 part
.rect
.width
+= border
;
1961 if (part
.type
== wxDockUIPart::typeDock
)
1962 part
.dock
->rect
= part
.rect
;
1963 if (part
.type
== wxDockUIPart::typePane
)
1964 part
.pane
->rect
= part
.rect
;
1968 // GetPanePart() looks up the pane the pane border UI part (or the regular
1969 // pane part if there is no border). This allows the caller to get the exact
1970 // rectangle of the pane in question, including decorations like
1971 // caption and border (if any).
1973 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
1976 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1978 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1979 if (part
.type
== wxDockUIPart::typePaneBorder
&&
1980 part
.pane
&& part
.pane
->window
== wnd
)
1983 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
1985 wxDockUIPart
& part
= m_uiparts
.Item(i
);
1986 if (part
.type
== wxDockUIPart::typePane
&&
1987 part
.pane
&& part
.pane
->window
== wnd
)
1995 // GetDockPixelOffset() is an internal function which returns
1996 // a dock's offset in pixels from the left side of the window
1997 // (for horizontal docks) or from the top of the window (for
1998 // vertical docks). This value is necessary for calculating
1999 // fixel-pane/toolbar offsets when they are dragged.
2001 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
2003 // the only way to accurately calculate the dock's
2004 // offset is to actually run a theoretical layout
2006 int i
, part_count
, dock_count
;
2007 wxDockInfoArray docks
;
2008 wxPaneInfoArray panes
;
2009 wxDockUIPartArray uiparts
;
2010 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2013 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2014 wxSize client_size
= m_frame
->GetClientSize();
2015 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2018 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2020 wxDockUIPart
& part
= uiparts
.Item(i
);
2021 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2022 part
.sizer_item
->GetSize());
2023 if (part
.type
== wxDockUIPart::typeDock
)
2024 part
.dock
->rect
= part
.rect
;
2029 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2031 wxDockInfo
& dock
= docks
.Item(i
);
2032 if (test
.dock_direction
== dock
.dock_direction
&&
2033 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2035 if (dock
.IsVertical())
2047 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2048 // if a dock operation is allowed, the new dock position is copied into
2049 // the target info. If the operation was allowed, the function returns true.
2051 static bool ProcessDockResult(wxPaneInfo
& target
,
2052 const wxPaneInfo
& new_pos
)
2054 bool allowed
= false;
2055 switch (new_pos
.dock_direction
)
2057 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2058 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2059 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2060 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2070 // DoDrop() is an important function. It basically takes a mouse position,
2071 // and determines where the pane's new position would be. If the pane is to be
2072 // dropped, it performs the drop operation using the specified dock and pane
2073 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2074 // scenario can be performed, giving precise coordinates for drop hints.
2075 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2076 // as parameters, the changes will be made to the main state arrays
2078 const int auiInsertRowPixels
= 10;
2079 const int auiNewRowPixels
= 40;
2080 const int auiLayerInsertPixels
= 40;
2081 const int auiLayerInsertOffset
= 5;
2083 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2084 wxPaneInfoArray
& panes
,
2087 const wxPoint
& offset
)
2089 wxSize cli_size
= m_frame
->GetClientSize();
2091 wxPaneInfo drop
= target
;
2094 // The result should always be shown
2098 // Check to see if the pane has been dragged outside of the window
2099 // (or near to the outside of the window), if so, dock it along the edge
2102 int layer_insert_offset
= auiLayerInsertOffset
;
2103 if (target
.IsToolbar())
2104 layer_insert_offset
= 0;
2106 if (pt
.x
< layer_insert_offset
&&
2107 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2109 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2110 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2111 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2115 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2116 return ProcessDockResult(target
, drop
);
2118 else if (pt
.y
< layer_insert_offset
&&
2119 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2121 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2122 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2123 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2127 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2128 return ProcessDockResult(target
, drop
);
2130 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2131 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2133 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2134 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2135 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2136 drop
.Dock().Right().
2139 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2140 return ProcessDockResult(target
, drop
);
2142 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2143 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2145 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2146 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2147 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2148 drop
.Dock().Bottom().
2151 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2152 return ProcessDockResult(target
, drop
);
2156 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2159 if (drop
.IsToolbar())
2161 if (!part
|| !part
->dock
)
2165 // calculate the offset from where the dock begins
2166 // to the point where the user dropped the pane
2167 int dock_drop_offset
= 0;
2168 if (part
->dock
->IsHorizontal())
2169 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2171 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2174 // toolbars may only be moved in and to fixed-pane docks,
2175 // otherwise we will try to float the pane. Also, the pane
2176 // should float if being dragged over center pane windows
2177 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2179 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2180 (drop
.IsFloatable() ||
2181 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2182 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2187 return ProcessDockResult(target
, drop
);
2191 Direction(part
->dock
->dock_direction
).
2192 Layer(part
->dock
->dock_layer
).
2193 Row(part
->dock
->dock_row
).
2194 Position(dock_drop_offset
);
2197 ((pt
.y
< part
->dock
->rect
.y
+ 2) && part
->dock
->IsHorizontal()) ||
2198 ((pt
.x
< part
->dock
->rect
.x
+ 2) && part
->dock
->IsVertical())
2199 ) && part
->dock
->panes
.GetCount() > 1)
2201 int row
= drop
.dock_row
;
2202 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2203 part
->dock
->dock_layer
,
2204 part
->dock
->dock_row
);
2205 drop
.dock_row
= row
;
2209 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2210 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2211 ) && part
->dock
->panes
.GetCount() > 1)
2213 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2214 part
->dock
->dock_layer
,
2215 part
->dock
->dock_row
+1);
2216 drop
.dock_row
= part
->dock
->dock_row
+1;
2219 return ProcessDockResult(target
, drop
);
2228 if (part
->type
== wxDockUIPart::typePaneBorder
||
2229 part
->type
== wxDockUIPart::typeCaption
||
2230 part
->type
== wxDockUIPart::typeGripper
||
2231 part
->type
== wxDockUIPart::typePaneButton
||
2232 part
->type
== wxDockUIPart::typePane
||
2233 part
->type
== wxDockUIPart::typePaneSizer
||
2234 part
->type
== wxDockUIPart::typeDockSizer
||
2235 part
->type
== wxDockUIPart::typeBackground
)
2237 if (part
->type
== wxDockUIPart::typeDockSizer
)
2239 if (part
->dock
->panes
.GetCount() != 1)
2241 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2248 // If a normal frame is being dragged over a toolbar, insert it
2249 // along the edge under the toolbar, but over all other panes.
2250 // (this could be done much better, but somehow factoring this
2251 // calculation with the one at the beginning of this function)
2252 if (part
->dock
&& part
->dock
->toolbar
)
2256 switch (part
->dock
->dock_direction
)
2258 case wxAUI_DOCK_LEFT
:
2259 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2260 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2261 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2263 case wxAUI_DOCK_TOP
:
2264 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2265 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2266 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2268 case wxAUI_DOCK_RIGHT
:
2269 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2270 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2271 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2273 case wxAUI_DOCK_BOTTOM
:
2274 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2275 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2276 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2280 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2283 Direction(part
->dock
->dock_direction
).
2284 Layer(layer
).Row(0).Position(0);
2285 return ProcessDockResult(target
, drop
);
2292 part
= GetPanePart(part
->pane
->window
);
2296 bool insert_dock_row
= false;
2297 int insert_row
= part
->pane
->dock_row
;
2298 int insert_dir
= part
->pane
->dock_direction
;
2299 int insert_layer
= part
->pane
->dock_layer
;
2301 switch (part
->pane
->dock_direction
)
2303 case wxAUI_DOCK_TOP
:
2304 if (pt
.y
>= part
->rect
.y
&&
2305 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2306 insert_dock_row
= true;
2308 case wxAUI_DOCK_BOTTOM
:
2309 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2310 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2311 insert_dock_row
= true;
2313 case wxAUI_DOCK_LEFT
:
2314 if (pt
.x
>= part
->rect
.x
&&
2315 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2316 insert_dock_row
= true;
2318 case wxAUI_DOCK_RIGHT
:
2319 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2320 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2321 insert_dock_row
= true;
2323 case wxAUI_DOCK_CENTER
:
2325 // "new row pixels" will be set to the default, but
2326 // must never exceed 20% of the window size
2327 int new_row_pixels_x
= auiNewRowPixels
;
2328 int new_row_pixels_y
= auiNewRowPixels
;
2330 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2331 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2333 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2334 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2337 // determine if the mouse pointer is in a location that
2338 // will cause a new row to be inserted. The hot spot positions
2339 // are along the borders of the center pane
2342 insert_dock_row
= true;
2343 if (pt
.x
>= part
->rect
.x
&&
2344 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2345 insert_dir
= wxAUI_DOCK_LEFT
;
2347 if (pt
.y
>= part
->rect
.y
&&
2348 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2349 insert_dir
= wxAUI_DOCK_TOP
;
2351 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2352 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2353 insert_dir
= wxAUI_DOCK_RIGHT
;
2355 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2356 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2357 insert_dir
= wxAUI_DOCK_BOTTOM
;
2361 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2365 if (insert_dock_row
)
2367 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2368 drop
.Dock().Direction(insert_dir
).
2369 Layer(insert_layer
).
2372 return ProcessDockResult(target
, drop
);
2375 // determine the mouse offset and the pane size, both in the
2376 // direction of the dock itself, and perpendicular to the dock
2380 if (part
->orientation
== wxVERTICAL
)
2382 offset
= pt
.y
- part
->rect
.y
;
2383 size
= part
->rect
.GetHeight();
2387 offset
= pt
.x
- part
->rect
.x
;
2388 size
= part
->rect
.GetWidth();
2391 int drop_position
= part
->pane
->dock_pos
;
2393 // if we are in the top/left part of the pane,
2394 // insert the pane before the pane being hovered over
2395 if (offset
<= size
/2)
2397 drop_position
= part
->pane
->dock_pos
;
2399 part
->pane
->dock_direction
,
2400 part
->pane
->dock_layer
,
2401 part
->pane
->dock_row
,
2402 part
->pane
->dock_pos
);
2405 // if we are in the bottom/right part of the pane,
2406 // insert the pane before the pane being hovered over
2407 if (offset
> size
/2)
2409 drop_position
= part
->pane
->dock_pos
+1;
2411 part
->pane
->dock_direction
,
2412 part
->pane
->dock_layer
,
2413 part
->pane
->dock_row
,
2414 part
->pane
->dock_pos
+1);
2418 Direction(part
->dock
->dock_direction
).
2419 Layer(part
->dock
->dock_layer
).
2420 Row(part
->dock
->dock_row
).
2421 Position(drop_position
);
2422 return ProcessDockResult(target
, drop
);
2429 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2431 if (!m_hint_wnd
|| m_hint_fadeamt
>= 50)
2433 m_hint_fadetimer
.Stop();
2437 m_hint_fadeamt
+= 5;
2438 MakeWindowTransparent(m_hint_wnd
, m_hint_fadeamt
);
2441 void wxFrameManager::ShowHint(const wxRect
& rect
)
2443 #if defined(__WXMSW__) || defined(__WXMAC__)
2444 // First, determine if the operating system can handle transparency.
2445 // Transparency is available on Win2000 and above
2447 static int os_type
= -1;
2448 static int ver_major
= -1;
2451 os_type
= ::wxGetOsVersion(&ver_major
);
2453 // If the transparent flag is set, and the OS supports it,
2454 // go ahead and use a transparent hint
2456 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0
2458 && os_type
== wxWINDOWS_NT
&& ver_major
>= 5
2462 if (m_last_hint
== rect
)
2466 int initial_fade
= 50;
2467 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2470 if (m_hint_wnd
== NULL
)
2472 wxPoint pt
= rect
.GetPosition();
2473 wxSize size
= rect
.GetSize();
2474 #if defined(__WXMSW__)
2475 m_hint_wnd
= new wxFrame(m_frame
, -1, wxEmptyString
, pt
, size
,
2476 wxFRAME_TOOL_WINDOW
|
2477 wxFRAME_FLOAT_ON_PARENT
|
2478 wxFRAME_NO_TASKBAR
|
2481 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2482 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
2483 #elif defined(__WXMAC__)
2484 // Using a miniframe with float and tool styles keeps the parent
2485 // frame activated and highlighted as such...
2486 m_hint_wnd
= new wxMiniFrame(m_frame
, -1, wxEmptyString
, pt
, size
,
2487 wxFRAME_FLOAT_ON_PARENT
2488 | wxFRAME_TOOL_WINDOW
2491 // Can't set the bg colour of a Frame in wxMac
2492 wxPanel
* p
= new wxPanel(m_hint_wnd
);
2494 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
2495 // color that is really hard to see, especially transparent.
2496 // Until a better system color is decided upon we'll just use
2498 p
->SetBackgroundColour(*wxBLUE
);
2502 // if we are dragging a floating pane, set the focus
2503 // back to that floating pane (otherwise it becomes unfocused)
2504 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2505 m_action_window
->SetFocus();
2510 MakeWindowTransparent(m_hint_wnd
, initial_fade
);
2511 m_hint_wnd
->SetSize(rect
);
2512 m_hint_wnd
->Raise();
2515 if (m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2517 // start fade in timer
2519 m_hint_fadetimer
.SetOwner(this, 101);
2520 m_hint_fadetimer
.Start(5);
2527 if (m_last_hint
!= rect
)
2529 // remove the last hint rectangle
2535 wxScreenDC screendc
;
2536 wxRegion
clip(1, 1, 10000, 10000);
2538 // clip all floating windows, so we don't draw over them
2540 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2542 wxPaneInfo
& pane
= m_panes
.Item(i
);
2544 if (pane
.IsFloating() &&
2545 pane
.frame
->IsShown())
2547 wxRect rect
= pane
.frame
->GetRect();
2549 // wxGTK returns the client size, not the whole frame size
2555 clip
.Subtract(rect
);
2559 screendc
.SetClippingRegion(clip
);
2561 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2562 wxBrush
brush(stipple
);
2563 screendc
.SetBrush(brush
);
2564 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2566 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2567 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2568 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2569 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2572 void wxFrameManager::HideHint()
2574 // hides a transparent window hint, if there is one
2577 MakeWindowTransparent(m_hint_wnd
, 0);
2578 m_hint_fadetimer
.Stop();
2579 m_last_hint
= wxRect();
2583 // hides a painted hint by redrawing the frame window
2584 if (!m_last_hint
.IsEmpty())
2588 m_last_hint
= wxRect();
2594 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2595 // determine the exact position the pane would be at were if dropped. If
2596 // the pame would indeed become docked at the specified drop point,
2597 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2598 // "pane_window" is the window pointer of the pane being dragged, pt is
2599 // the mouse position, in client coordinates
2600 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2602 const wxPoint
& offset
)
2606 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2607 // we will create a new temporary layout and then measure the resulting
2608 // rectangle; we will create a copy of the docking structures (m_dock)
2609 // so that we don't modify the real thing on screen
2611 int i
, pane_count
, part_count
;
2612 wxDockInfoArray docks
;
2613 wxPaneInfoArray panes
;
2614 wxDockUIPartArray uiparts
;
2615 wxPaneInfo hint
= GetPane(pane_window
);
2616 hint
.name
= wxT("__HINT__");
2621 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2623 // remove any pane already there which bears the same window;
2624 // this happens when you are moving a pane around in a dock
2625 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2627 if (panes
.Item(i
).window
== pane_window
)
2629 RemovePaneFromDocks(docks
, panes
.Item(i
));
2635 // find out where the new pane would be
2636 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2644 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2645 wxSize client_size
= m_frame
->GetClientSize();
2646 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2649 for (i
= 0, part_count
= uiparts
.GetCount();
2650 i
< part_count
; ++i
)
2652 wxDockUIPart
& part
= uiparts
.Item(i
);
2654 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2655 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2657 rect
= wxRect(part
.sizer_item
->GetPosition(),
2658 part
.sizer_item
->GetSize());
2671 // actually show the hint rectangle on the screen
2672 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2676 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2678 // try to find the pane
2679 wxPaneInfo
& pane
= GetPane(wnd
);
2680 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2682 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2683 MakeWindowTransparent(pane
.frame
, 150);
2686 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
)
2688 // try to find the pane
2689 wxPaneInfo
& pane
= GetPane(wnd
);
2690 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2692 wxPoint pt
= ::wxGetMousePosition();
2693 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2695 // calculate the offset from the upper left-hand corner
2696 // of the frame to the mouse pointer
2697 wxPoint frame_pos
= pane
.frame
->GetPosition();
2698 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2700 // no hint for toolbar floating windows
2701 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
2703 if (m_action
== actionDragFloatingPane
)
2705 wxDockInfoArray docks
;
2706 wxPaneInfoArray panes
;
2707 wxDockUIPartArray uiparts
;
2708 wxPaneInfo hint
= pane
;
2710 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2712 // find out where the new pane would be
2713 if (!DoDrop(docks
, panes
, hint
, client_pt
))
2715 if (hint
.IsFloating())
2719 m_action
= actionDragToolbarPane
;
2720 m_action_window
= pane
.window
;
2729 // if a key modifier is pressed while dragging the frame,
2730 // don't dock the window
2731 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2738 DrawHintRect(wnd
, client_pt
, action_offset
);
2741 // this cleans up some screen artifacts that are caused on GTK because
2742 // we aren't getting the exact size of the window (see comment
2752 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
)
2754 // try to find the pane
2755 wxPaneInfo
& pane
= GetPane(wnd
);
2756 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2758 wxPoint pt
= ::wxGetMousePosition();
2759 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2761 // calculate the offset from the upper left-hand corner
2762 // of the frame to the mouse pointer
2763 wxPoint frame_pos
= pane
.frame
->GetPosition();
2764 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2767 // if a key modifier is pressed while dragging the frame,
2768 // don't dock the window
2769 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2776 // do the drop calculation
2777 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
2779 // if the pane is still floating, update it's floating
2780 // position (that we store)
2781 if (pane
.IsFloating())
2783 pane
.floating_pos
= pane
.frame
->GetPosition();
2785 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2786 MakeWindowTransparent(pane
.frame
, 255);
2794 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
2796 // try to find the pane
2797 wxPaneInfo
& pane
= GetPane(wnd
);
2798 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2800 pane
.floating_size
= size
;
2804 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
2806 // try to find the pane
2807 wxPaneInfo
& pane
= GetPane(wnd
);
2808 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2811 // fire pane close event
2812 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
2814 e
.SetCanVeto(evt
.CanVeto());
2824 // reparent the pane window back to us and
2825 // prepare the frame window for destruction
2826 pane
.window
->Show(false);
2827 pane
.window
->Reparent(m_frame
);
2835 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
2837 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
2839 // try to find the pane
2840 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
2842 SetActivePane(m_panes
, wnd
);
2847 // OnRender() draws all of the pane captions, sashes,
2848 // backgrounds, captions, grippers, pane borders and buttons.
2849 // It renders the entire user interface.
2851 void wxFrameManager::OnRender(wxFrameManagerEvent
& evt
)
2853 wxDC
* dc
= evt
.GetDC();
2859 for (i
= 0, part_count
= m_uiparts
.GetCount();
2860 i
< part_count
; ++i
)
2862 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2864 // don't draw hidden pane items
2865 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
2870 case wxDockUIPart::typeDockSizer
:
2871 case wxDockUIPart::typePaneSizer
:
2872 m_art
->DrawSash(*dc
, part
.orientation
, part
.rect
);
2874 case wxDockUIPart::typeBackground
:
2875 m_art
->DrawBackground(*dc
, part
.orientation
, part
.rect
);
2877 case wxDockUIPart::typeCaption
:
2878 m_art
->DrawCaption(*dc
, part
.pane
->caption
, part
.rect
, *part
.pane
);
2880 case wxDockUIPart::typeGripper
:
2881 m_art
->DrawGripper(*dc
, part
.rect
, *part
.pane
);
2883 case wxDockUIPart::typePaneBorder
:
2884 m_art
->DrawBorder(*dc
, part
.rect
, *part
.pane
);
2886 case wxDockUIPart::typePaneButton
:
2887 m_art
->DrawPaneButton(*dc
, part
.button
->button_id
,
2888 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
2895 // Render() fire a render event, which is normally handled by
2896 // wxFrameManager::OnRender(). This allows the render function to
2897 // be overridden via the render event. This can be useful for paintin
2898 // custom graphics in the main window. Default behavior can be
2899 // invoked in the overridden function by calling OnRender()
2901 void wxFrameManager::Render(wxDC
* dc
)
2903 wxFrameManagerEvent
e(wxEVT_AUI_RENDER
);
2908 void wxFrameManager::Repaint(wxDC
* dc
)
2913 m_frame
->Refresh() ;
2919 m_frame
->GetClientSize(&w
, &h
);
2921 // figure out which dc to use; if one
2922 // has been specified, use it, otherwise
2924 wxClientDC
* client_dc
= NULL
;
2927 client_dc
= new wxClientDC(m_frame
);
2931 // if the frame has a toolbar, the client area
2932 // origin will not be (0,0).
2933 wxPoint pt
= m_frame
->GetClientAreaOrigin();
2934 if (pt
.x
!= 0 || pt
.y
!= 0)
2935 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
2937 // render all the items
2940 // if we created a client_dc, delete it
2945 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
2947 wxPaintDC
dc(m_frame
);
2951 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
2960 void wxFrameManager::OnSize(wxSizeEvent
& WXUNUSED(event
))
2970 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
2973 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
2974 wxCursor cursor
= wxNullCursor
;
2978 if (part
->type
== wxDockUIPart::typeDockSizer
||
2979 part
->type
== wxDockUIPart::typePaneSizer
)
2981 // a dock may not be resized if it has a single
2982 // pane which is not resizable
2983 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
2984 part
->dock
->panes
.GetCount() == 1 &&
2985 part
->dock
->panes
.Item(0)->IsFixed())
2988 // panes that may not be resized do not get a sizing cursor
2989 if (part
->pane
&& part
->pane
->IsFixed())
2992 if (part
->orientation
== wxVERTICAL
)
2993 cursor
= wxCursor(wxCURSOR_SIZEWE
);
2995 cursor
= wxCursor(wxCURSOR_SIZENS
);
2997 else if (part
->type
== wxDockUIPart::typeGripper
)
2999 cursor
= wxCursor(wxCURSOR_SIZING
);
3003 event
.SetCursor(cursor
);
3008 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
3009 const wxMouseEvent
& event
)
3011 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3013 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3015 if (hit_test
== button_ui_part
)
3017 if (event
.LeftDown())
3018 state
= wxAUI_BUTTON_STATE_PRESSED
;
3020 state
= wxAUI_BUTTON_STATE_HOVER
;
3024 if (event
.LeftDown())
3025 state
= wxAUI_BUTTON_STATE_HOVER
;
3028 // now repaint the button with hover state
3029 wxClientDC
cdc(m_frame
);
3031 // if the frame has a toolbar, the client area
3032 // origin will not be (0,0).
3033 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3034 if (pt
.x
!= 0 || pt
.y
!= 0)
3035 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3037 m_art
->DrawPaneButton(cdc
,
3038 button_ui_part
->button
->button_id
,
3040 button_ui_part
->rect
,
3044 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
3046 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3049 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3052 if (part
->type
== wxDockUIPart::typeDockSizer
||
3053 part
->type
== wxDockUIPart::typePaneSizer
)
3055 // a dock may not be resized if it has a single
3056 // pane which is not resizable
3057 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3058 part
->dock
->panes
.GetCount() == 1 &&
3059 part
->dock
->panes
.Item(0)->IsFixed())
3062 // panes that may not be resized should be ignored here
3063 if (part
->pane
&& part
->pane
->IsFixed())
3066 m_action
= actionResize
;
3067 m_action_part
= part
;
3068 m_action_hintrect
= wxRect();
3069 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3070 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3071 event
.m_y
- part
->rect
.y
);
3072 m_frame
->CaptureMouse();
3074 else if (part
->type
== wxDockUIPart::typePaneButton
)
3076 m_action
= actionClickButton
;
3077 m_action_part
= part
;
3078 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3079 m_frame
->CaptureMouse();
3081 UpdateButtonOnScreen(part
, event
);
3083 else if (part
->type
== wxDockUIPart::typeCaption
||
3084 part
->type
== wxDockUIPart::typeGripper
)
3086 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3088 // set the caption as active
3089 SetActivePane(m_panes
, part
->pane
->window
);
3093 m_action
= actionClickCaption
;
3094 m_action_part
= part
;
3095 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3096 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3097 event
.m_y
- part
->rect
.y
);
3098 m_frame
->CaptureMouse();
3118 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3120 if (m_action
== actionResize
)
3122 m_frame
->ReleaseMouse();
3124 // get rid of the hint rectangle
3126 DrawResizeHint(dc
, m_action_hintrect
);
3128 // resize the dock or the pane
3129 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3131 wxRect
& rect
= m_action_part
->dock
->rect
;
3133 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3134 event
.m_y
- m_action_offset
.y
);
3136 switch (m_action_part
->dock
->dock_direction
)
3138 case wxAUI_DOCK_LEFT
:
3139 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3141 case wxAUI_DOCK_TOP
:
3142 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3144 case wxAUI_DOCK_RIGHT
:
3145 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3146 new_pos
.x
- m_action_part
->rect
.GetWidth();
3148 case wxAUI_DOCK_BOTTOM
:
3149 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3150 new_pos
.y
- m_action_part
->rect
.GetHeight();
3157 else if (m_action_part
&&
3158 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3160 wxDockInfo
& dock
= *m_action_part
->dock
;
3161 wxPaneInfo
& pane
= *m_action_part
->pane
;
3163 int total_proportion
= 0;
3164 int dock_pixels
= 0;
3165 int new_pixsize
= 0;
3167 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3168 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3169 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3171 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3172 event
.m_y
- m_action_offset
.y
);
3174 // determine the pane rectangle by getting the pane part
3175 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3176 wxASSERT_MSG(pane_part
,
3177 wxT("Pane border part not found -- shouldn't happen"));
3179 // determine the new pixel size that the user wants;
3180 // this will help us recalculate the pane's proportion
3181 if (dock
.IsHorizontal())
3182 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3184 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3186 // determine the size of the dock, based on orientation
3187 if (dock
.IsHorizontal())
3188 dock_pixels
= dock
.rect
.GetWidth();
3190 dock_pixels
= dock
.rect
.GetHeight();
3192 // determine the total proportion of all resizable panes,
3193 // and the total size of the dock minus the size of all
3195 int i
, dock_pane_count
= dock
.panes
.GetCount();
3196 int pane_position
= -1;
3197 for (i
= 0; i
< dock_pane_count
; ++i
)
3199 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3200 if (p
.window
== pane
.window
)
3203 // while we're at it, subtract the pane sash
3204 // width from the dock width, because this would
3205 // skew our proportion calculations
3207 dock_pixels
-= sash_size
;
3209 // also, the whole size (including decorations) of
3210 // all fixed panes must also be subtracted, because they
3211 // are not part of the proportion calculation
3214 if (dock
.IsHorizontal())
3215 dock_pixels
-= p
.best_size
.x
;
3217 dock_pixels
-= p
.best_size
.y
;
3221 total_proportion
+= p
.dock_proportion
;
3225 // find a pane in our dock to 'steal' space from or to 'give'
3226 // space to -- this is essentially what is done when a pane is
3227 // resized; the pane should usually be the first non-fixed pane
3228 // to the right of the action pane
3229 int borrow_pane
= -1;
3230 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3232 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3241 // demand that the pane being resized is found in this dock
3242 // (this assert really never should be raised)
3243 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3245 // prevent division by zero
3246 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3248 m_action
= actionNone
;
3252 // calculate the new proportion of the pane
3253 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3255 // default minimum size
3258 // check against the pane's minimum size, if specified. please note
3259 // that this is not enough to ensure that the minimum size will
3260 // not be violated, because the whole frame might later be shrunk,
3261 // causing the size of the pane to violate it's minimum size
3262 if (pane
.min_size
.IsFullySpecified())
3266 if (pane
.HasBorder())
3267 min_size
+= (pane_border_size
*2);
3269 // calculate minimum size with decorations (border,caption)
3270 if (pane_part
->orientation
== wxVERTICAL
)
3272 min_size
+= pane
.min_size
.y
;
3273 if (pane
.HasCaption())
3274 min_size
+= caption_size
;
3278 min_size
+= pane
.min_size
.x
;
3283 // for some reason, an arithmatic error somewhere is causing
3284 // the proportion calculations to always be off by 1 pixel;
3285 // for now we will add the 1 pixel on, but we really should
3286 // determine what's causing this.
3289 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3291 if (new_proportion
< min_proportion
)
3292 new_proportion
= min_proportion
;
3296 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3298 // borrow the space from our neighbor pane to the
3299 // right or bottom (depending on orientation)
3300 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3301 pane
.dock_proportion
= new_proportion
;
3308 else if (m_action
== actionClickButton
)
3310 m_hover_button
= NULL
;
3311 m_frame
->ReleaseMouse();
3312 UpdateButtonOnScreen(m_action_part
, event
);
3314 // make sure we're still over the item that was originally clicked
3315 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3317 // fire button-click event
3318 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3319 e
.SetPane(m_action_part
->pane
);
3320 e
.SetButton(m_action_part
->button
->button_id
);
3324 else if (m_action
== actionClickCaption
)
3326 m_frame
->ReleaseMouse();
3328 else if (m_action
== actionDragFloatingPane
)
3330 m_frame
->ReleaseMouse();
3332 else if (m_action
== actionDragToolbarPane
)
3334 m_frame
->ReleaseMouse();
3336 wxPaneInfo
& pane
= GetPane(m_action_window
);
3337 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3339 // save the new positions
3340 wxDockInfoPtrArray docks
;
3341 FindDocks(m_docks
, pane
.dock_direction
,
3342 pane
.dock_layer
, pane
.dock_row
, docks
);
3343 if (docks
.GetCount() == 1)
3345 wxDockInfo
& dock
= *docks
.Item(0);
3347 wxArrayInt pane_positions
, pane_sizes
;
3348 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3350 int i
, dock_pane_count
= dock
.panes
.GetCount();
3351 for (i
= 0; i
< dock_pane_count
; ++i
)
3352 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3355 pane
.state
&= ~wxPaneInfo::actionPane
;
3363 m_action
= actionNone
;
3364 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3368 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3370 // sometimes when Update() is called from inside this method,
3371 // a spurious mouse move event is generated; this check will make
3372 // sure that only real mouse moves will get anywhere in this method;
3373 // this appears to be a bug somewhere, and I don't know where the
3374 // mouse move event is being generated. only verified on MSW
3376 wxPoint mouse_pos
= event
.GetPosition();
3377 if (m_last_mouse_move
== mouse_pos
)
3379 m_last_mouse_move
= mouse_pos
;
3382 if (m_action
== actionResize
)
3384 wxPoint pos
= m_action_part
->rect
.GetPosition();
3385 if (m_action_part
->orientation
== wxHORIZONTAL
)
3386 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3388 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3390 wxRect
rect(m_frame
->ClientToScreen(pos
),
3391 m_action_part
->rect
.GetSize());
3394 if (!m_action_hintrect
.IsEmpty())
3395 DrawResizeHint(dc
, m_action_hintrect
);
3396 DrawResizeHint(dc
, rect
);
3397 m_action_hintrect
= rect
;
3399 else if (m_action
== actionClickCaption
)
3401 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3402 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3404 // caption has been clicked. we need to check if the mouse
3405 // is now being dragged. if it is, we need to change the
3406 // mouse action to 'drag'
3407 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3408 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3410 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3412 if (!pane_info
->IsToolbar())
3414 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3415 pane_info
->IsFloatable())
3417 m_action
= actionDragFloatingPane
;
3419 // set initial float position
3420 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3421 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3422 pt
.y
- m_action_offset
.y
);
3427 m_action_window
= pane_info
->frame
;
3429 // action offset is used here to make it feel "natural" to the user
3430 // to drag a docked pane and suddenly have it become a floating frame.
3431 // Sometimes, however, the offset where the user clicked on the docked
3432 // caption is bigger than the width of the floating frame itself, so
3433 // in that case we need to set the action offset to a sensible value
3434 wxSize frame_size
= m_action_window
->GetSize();
3435 if (frame_size
.x
<= m_action_offset
.x
)
3436 m_action_offset
.x
= 30;
3441 m_action
= actionDragToolbarPane
;
3442 m_action_window
= pane_info
->window
;
3446 else if (m_action
== actionDragFloatingPane
)
3448 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3449 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3450 pt
.y
- m_action_offset
.y
);
3452 else if (m_action
== actionDragToolbarPane
)
3454 wxPaneInfo
& pane
= GetPane(m_action_window
);
3455 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3457 pane
.state
|= wxPaneInfo::actionPane
;
3459 wxPoint pt
= event
.GetPosition();
3460 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3462 // if DoDrop() decided to float the pane, set up
3463 // the floating pane's initial position
3464 if (pane
.IsFloating())
3466 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3467 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3468 pt
.y
- m_action_offset
.y
);
3471 // this will do the actiual move operation;
3472 // in the case that the pane has been floated,
3473 // this call will create the floating pane
3474 // and do the reparenting
3477 // if the pane has been floated, change the mouse
3478 // action actionDragFloatingPane so that subsequent
3479 // EVT_MOTION() events will move the floating pane
3480 if (pane
.IsFloating())
3482 pane
.state
&= ~wxPaneInfo::actionPane
;
3483 m_action
= actionDragFloatingPane
;
3484 m_action_window
= pane
.frame
;
3489 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3490 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3492 if (part
!= m_hover_button
)
3494 // make the old button normal
3496 UpdateButtonOnScreen(m_hover_button
, event
);
3498 // mouse is over a button, so repaint the
3499 // button in hover mode
3500 UpdateButtonOnScreen(part
, event
);
3501 m_hover_button
= part
;
3508 m_hover_button
= NULL
;
3519 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3523 m_hover_button
= NULL
;
3528 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3530 // when a child pane has it's focus set, we should change the
3531 // pane's active state to reflect this. (this is only true if
3532 // active panes are allowed by the owner)
3533 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3535 if (GetPane(event
.GetWindow()).IsOk())
3537 SetActivePane(m_panes
, event
.GetWindow());
3544 // OnPaneButton() is an event handler that is called
3545 // when a pane button has been pressed.
3546 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& evt
)
3548 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3550 wxPaneInfo
& pane
= *(evt
.pane
);
3552 if (evt
.button
== wxPaneInfo::buttonClose
)
3554 // fire pane close event
3555 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3556 e
.SetPane(evt
.pane
);
3565 else if (evt
.button
== wxPaneInfo::buttonPin
)
3567 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&