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
)
67 class wxPseudoTransparentFrame
: public wxFrame
70 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
71 wxWindowID id
= wxID_ANY
,
72 const wxString
& title
= wxEmptyString
,
73 const wxPoint
& pos
= wxDefaultPosition
,
74 const wxSize
& size
= wxDefaultSize
,
75 long style
= wxDEFAULT_FRAME_STYLE
,
76 const wxString
&name
= wxT("frame"))
77 : wxFrame(parent
, id
, title
, pos
, size
, style
| wxFRAME_SHAPED
, name
)
79 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
84 m_CanSetShape
= false; // have to wait for window create event on GTK
88 m_Region
= wxRegion(0, 0, 0, 0);
92 virtual bool SetTransparent(wxByte alpha
)
96 int w
=100; // some defaults
98 GetClientSize(&w
, &h
);
104 // m_Region.Union(0, 0, 1, m_MaxWidth);
107 for (int y
=0; y
<m_MaxHeight
; y
++)
109 // Reverse the order of the bottom 4 bits
110 int j
=((y
&8)?1:0)|((y
&4)?2:0)|((y
&2)?4:0)|((y
&1)?8:0);
111 if ((j
*16+8)<m_Amount
)
112 m_Region
.Union(0, y
, m_MaxWidth
, 1);
121 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
125 if (m_Region
.IsEmpty())
129 dc
.SetBrush(wxColour(128, 192, 255));
131 dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
133 dc
.SetPen(*wxTRANSPARENT_PEN
);
135 wxRegionIterator
upd(GetUpdateRegion()); // get the update rect list
139 wxRect
rect(upd
.GetRect());
140 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
147 void OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
)) {m_CanSetShape
=true; SetTransparent(0);}
150 void OnSize(wxSizeEvent
& event
)
152 SetTransparent(m_Amount
);
153 m_Region
.Intersect(0, 0, event
.GetSize().GetWidth(),
154 event
.GetSize().GetHeight());
168 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
169 DECLARE_EVENT_TABLE()
173 IMPLEMENT_DYNAMIC_CLASS( wxPseudoTransparentFrame
, wxFrame
)
175 BEGIN_EVENT_TABLE(wxPseudoTransparentFrame
, wxFrame
)
176 EVT_PAINT(wxPseudoTransparentFrame::OnPaint
)
177 EVT_SIZE(wxPseudoTransparentFrame::OnSize
)
179 EVT_WINDOW_CREATE(wxPseudoTransparentFrame::OnWindowCreate
)
184 // -- static utility functions --
186 static wxBitmap
wxPaneCreateStippleBitmap()
188 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
189 wxImage
img(2,2,data
,true);
190 return wxBitmap(img
);
193 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
195 wxBitmap stipple
= wxPaneCreateStippleBitmap();
196 wxBrush
brush(stipple
);
198 dc
.SetPen(*wxTRANSPARENT_PEN
);
200 dc
.SetLogicalFunction(wxXOR
);
201 dc
.DrawRectangle(rect
);
206 // CopyDocksAndPanes() - this utility function creates copies of
207 // the dock and pane info. wxDockInfo's usually contain pointers
208 // to wxPaneInfo classes, thus this function is necessary to reliably
209 // reconstruct that relationship in the new dock info and pane info arrays
211 static void CopyDocksAndPanes(wxDockInfoArray
& dest_docks
,
212 wxPaneInfoArray
& dest_panes
,
213 const wxDockInfoArray
& src_docks
,
214 const wxPaneInfoArray
& src_panes
)
216 dest_docks
= src_docks
;
217 dest_panes
= src_panes
;
218 int i
, j
, k
, dock_count
, pc1
, pc2
;
219 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
221 wxDockInfo
& dock
= dest_docks
.Item(i
);
222 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
223 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
224 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
225 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
229 // GetMaxLayer() is an internal function which returns
230 // the highest layer inside the specified dock
231 static int GetMaxLayer(const wxDockInfoArray
& docks
, int dock_direction
)
233 int i
, dock_count
, max_layer
= 0;
234 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
236 wxDockInfo
& dock
= docks
.Item(i
);
237 if (dock
.dock_direction
== dock_direction
&&
238 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
239 max_layer
= dock
.dock_layer
;
245 // GetMaxRow() is an internal function which returns
246 // the highest layer inside the specified dock
247 static int GetMaxRow(const wxPaneInfoArray
& panes
, int direction
, int layer
)
249 int i
, pane_count
, max_row
= 0;
250 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
252 wxPaneInfo
& pane
= panes
.Item(i
);
253 if (pane
.dock_direction
== direction
&&
254 pane
.dock_layer
== layer
&&
255 pane
.dock_row
> max_row
)
256 max_row
= pane
.dock_row
;
263 // DoInsertDockLayer() is an internal function that inserts a new dock
264 // layer by incrementing all existing dock layer values by one
265 static void DoInsertDockLayer(wxPaneInfoArray
& panes
,
270 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
272 wxPaneInfo
& pane
= panes
.Item(i
);
273 if (!pane
.IsFloating() &&
274 pane
.dock_direction
== dock_direction
&&
275 pane
.dock_layer
>= dock_layer
)
280 // DoInsertDockLayer() is an internal function that inserts a new dock
281 // row by incrementing all existing dock row values by one
282 static void DoInsertDockRow(wxPaneInfoArray
& panes
,
288 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
290 wxPaneInfo
& pane
= panes
.Item(i
);
291 if (!pane
.IsFloating() &&
292 pane
.dock_direction
== dock_direction
&&
293 pane
.dock_layer
== dock_layer
&&
294 pane
.dock_row
>= dock_row
)
299 // DoInsertDockLayer() is an internal function that inserts a space for
300 // another dock pane by incrementing all existing dock row values by one
301 static void DoInsertPane(wxPaneInfoArray
& panes
,
308 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
310 wxPaneInfo
& pane
= panes
.Item(i
);
311 if (!pane
.IsFloating() &&
312 pane
.dock_direction
== dock_direction
&&
313 pane
.dock_layer
== dock_layer
&&
314 pane
.dock_row
== dock_row
&&
315 pane
.dock_pos
>= dock_pos
)
320 // FindDocks() is an internal function that returns a list of docks which meet
321 // the specified conditions in the parameters and returns a sorted array
322 // (sorted by layer and then row)
323 static void FindDocks(wxDockInfoArray
& docks
,
327 wxDockInfoPtrArray
& arr
)
329 int begin_layer
= dock_layer
;
330 int end_layer
= dock_layer
;
331 int begin_row
= dock_row
;
332 int end_row
= dock_row
;
333 int dock_count
= docks
.GetCount();
334 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
336 // discover the maximum dock layer and the max row
337 for (i
= 0; i
< dock_count
; ++i
)
339 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
340 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
343 // if no dock layer was specified, search all dock layers
344 if (dock_layer
== -1)
347 end_layer
= max_layer
;
350 // if no dock row was specified, search all dock row
359 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
360 for (row
= begin_row
; row
<= end_row
; ++row
)
361 for (i
= 0; i
< dock_count
; ++i
)
363 wxDockInfo
& d
= docks
.Item(i
);
364 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
366 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
372 // FindPaneInDock() looks up a specified window pointer inside a dock.
373 // If found, the corresponding wxPaneInfo pointer is returned, otherwise NULL.
374 static wxPaneInfo
* FindPaneInDock(const wxDockInfo
& dock
, wxWindow
* window
)
376 int i
, count
= dock
.panes
.GetCount();
377 for (i
= 0; i
< count
; ++i
)
379 wxPaneInfo
* p
= dock
.panes
.Item(i
);
380 if (p
->window
== window
)
386 // RemovePaneFromDocks() removes a pane window from all docks
387 // with a possible exception specified by parameter "ex_cept"
388 static void RemovePaneFromDocks(wxDockInfoArray
& docks
,
390 wxDockInfo
* ex_cept
= NULL
)
393 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
395 wxDockInfo
& d
= docks
.Item(i
);
398 wxPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
404 // RenumberDockRows() takes a dock and assigns sequential numbers
405 // to existing rows. Basically it takes out the gaps; so if a
406 // dock has rows with numbers 0,2,5, they will become 0,1,2
407 static void RenumberDockRows(wxDockInfoPtrArray
& docks
)
409 int i
, dock_count
, j
, pane_count
;
410 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
412 wxDockInfo
& dock
= *docks
.Item(i
);
414 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
415 dock
.panes
.Item(j
)->dock_row
= i
;
420 // SetActivePane() sets the active pane, as well as cycles through
421 // every other pane and makes sure that all others' active flags
423 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
426 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
428 wxPaneInfo
& pane
= panes
.Item(i
);
429 pane
.state
&= ~wxPaneInfo::optionActive
;
430 if (pane
.window
== active_pane
)
431 pane
.state
|= wxPaneInfo::optionActive
;
436 // this function is used to sort panes by dock position
437 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
439 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
443 // -- wxFrameManager class implementation --
446 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
447 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
448 EVT_AUI_RENDER(wxFrameManager::OnRender
)
449 EVT_PAINT(wxFrameManager::OnPaint
)
450 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
451 EVT_SIZE(wxFrameManager::OnSize
)
452 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
453 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
454 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
455 EVT_MOTION(wxFrameManager::OnMotion
)
456 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
457 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
458 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
462 wxFrameManager::wxFrameManager(wxWindow
* managed_wnd
, unsigned int flags
)
464 m_action
= actionNone
;
465 m_last_mouse_move
= wxPoint();
466 m_hover_button
= NULL
;
467 m_art
= new wxDefaultDockArt
;
473 SetManagedWindow(managed_wnd
);
477 wxFrameManager::~wxFrameManager()
482 // GetPane() looks up a wxPaneInfo structure based
483 // on the supplied window pointer. Upon failure, GetPane()
484 // returns an empty wxPaneInfo, a condition which can be checked
485 // by calling wxPaneInfo::IsOk().
487 // The pane info's structure may then be modified. Once a pane's
488 // info is modified, wxFrameManager::Update() must be called to
489 // realize the changes in the UI.
491 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
494 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
496 wxPaneInfo
& p
= m_panes
.Item(i
);
497 if (p
.window
== window
)
500 return wxNullPaneInfo
;
503 // this version of GetPane() looks up a pane based on a
504 // 'pane name', see above comment for more info
505 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
508 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
510 wxPaneInfo
& p
= m_panes
.Item(i
);
514 return wxNullPaneInfo
;
517 // GetAllPanes() returns a reference to all the pane info structures
518 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
523 // HitTest() is an internal function which determines
524 // which UI item the specified coordinates are over
525 // (x,y) specify a position in client coordinates
526 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
528 wxDockUIPart
* result
= NULL
;
531 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
533 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
535 // we are not interested in typeDock, because this space
536 // isn't used to draw anything, just for measurements;
537 // besides, the entire dock area is covered with other
538 // rectangles, which we are interested in.
539 if (item
->type
== wxDockUIPart::typeDock
)
542 // if we already have a hit on a more specific item, we are not
543 // interested in a pane hit. If, however, we don't already have
544 // a hit, returning a pane hit is necessary for some operations
545 if ((item
->type
== wxDockUIPart::typePane
||
546 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
549 // if the point is inside the rectangle, we have a hit
550 if (item
->rect
.Inside(x
,y
))
558 // SetFlags() and GetFlags() allow the owner to set various
559 // options which are global to wxFrameManager
560 void wxFrameManager::SetFlags(unsigned int flags
)
565 unsigned int wxFrameManager::GetFlags() const
571 // don't use these anymore as they are deprecated
572 // use Set/GetManagedFrame() instead
573 void wxFrameManager::SetFrame(wxFrame
* frame
)
575 SetManagedWindow((wxWindow
*)frame
);
578 wxFrame
* wxFrameManager::GetFrame() const
580 return (wxFrame
*)m_frame
;
586 // SetManagedWindow() is usually called once when the frame
587 // manager class is being initialized. "frame" specifies
588 // the frame which should be managed by the frame mananger
589 void wxFrameManager::SetManagedWindow(wxWindow
* frame
)
591 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
594 m_frame
->PushEventHandler(this);
597 // if the owner is going to manage an MDI parent frame,
598 // we need to add the MDI client window as the default
601 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
603 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
604 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
606 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
608 AddPane(client_window
,
609 wxPaneInfo().Name(wxT("mdiclient")).
610 CenterPane().PaneBorder(false));
614 // Make a window to use for a transparent hint
615 #if defined(__WXMSW__) || defined(__WXGTK__)
616 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
617 wxFRAME_TOOL_WINDOW
|
618 wxFRAME_FLOAT_ON_PARENT
|
622 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
624 #elif defined(__WXMAC__)
625 // Using a miniframe with float and tool styles keeps the parent
626 // frame activated and highlighted as such...
627 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
628 wxFRAME_FLOAT_ON_PARENT
629 | wxFRAME_TOOL_WINDOW
);
631 // Can't set the bg colour of a Frame in wxMac
632 wxPanel
* p
= new wxPanel(m_hint_wnd
);
634 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
635 // color that is really hard to see, especially transparent.
636 // Until a better system color is decided upon we'll just use
638 p
->SetBackgroundColour(*wxBLUE
);
644 // CanSetTransparent is only present in the 2.7.0 ABI. To allow this file to be easily used
645 // in a backported environment, conditionally compile this in.
646 #if wxCHECK_VERSION(2,7,0)
647 && !m_hint_wnd
->CanSetTransparent()
653 m_hint_wnd
->Destroy();
656 // If we can convert it to a PseudoTransparent window, do so
657 m_hint_wnd
= new wxPseudoTransparentFrame (m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
658 wxFRAME_TOOL_WINDOW
|
659 wxFRAME_FLOAT_ON_PARENT
|
663 m_hint_fademax
= 128;
668 // UnInit() must be called, usually in the destructor
669 // of the frame class. If it is not called, usually this
670 // will result in a crash upon program exit
671 void wxFrameManager::UnInit()
673 m_frame
->RemoveEventHandler(this);
676 // GetManagedWindow() returns the window pointer being managed
677 wxWindow
* wxFrameManager::GetManagedWindow() const
682 wxDockArt
* wxFrameManager::GetArtProvider() const
687 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
689 // first, give the owner frame a chance to override
692 if (m_frame
->ProcessEvent(event
))
699 // SetArtProvider() instructs wxFrameManager to use the
700 // specified art provider for all drawing calls. This allows
701 // plugable look-and-feel features. The pointer that is
702 // passed to this method subsequently belongs to wxFrameManager,
703 // and is deleted in the frame manager destructor
704 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
706 // delete the last art provider, if any
709 // assign the new art provider
710 m_art
= art_provider
;
714 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
716 // check if the pane has a valid window
720 // check if the pane already exists
721 if (GetPane(pane_info
.window
).IsOk())
724 m_panes
.Add(pane_info
);
726 wxPaneInfo
& pinfo
= m_panes
.Last();
728 // set the pane window
729 pinfo
.window
= window
;
731 // if the pane's name identifier is blank, create a random string
732 if (pinfo
.name
.empty())
734 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
735 ((unsigned long)pinfo
.window
) & 0xffffffff,
736 (unsigned int)time(NULL
),
738 (unsigned int)GetTickCount(),
740 (unsigned int)clock(),
742 (unsigned long)m_panes
.GetCount());
745 // set initial proportion (if not already set)
746 if (pinfo
.dock_proportion
== 0)
747 pinfo
.dock_proportion
= 100000;
749 if (pinfo
.HasCloseButton() &&
750 pinfo
.buttons
.size() == 0)
753 button
.button_id
= wxPaneInfo::buttonClose
;
754 pinfo
.buttons
.Add(button
);
757 if (pinfo
.best_size
== wxDefaultSize
&&
760 pinfo
.best_size
= pinfo
.window
->GetClientSize();
762 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
764 // GetClientSize() doesn't get the best size for
765 // a toolbar under some newer versions of wxWidgets,
766 // so use GetBestSize()
767 pinfo
.best_size
= pinfo
.window
->GetBestSize();
769 // for some reason, wxToolBar::GetBestSize() is returning
770 // a size that is a pixel shy of the correct amount.
771 // I believe this to be the correct action, until
772 // wxToolBar::GetBestSize() is fixed. Is this assumption
777 if (pinfo
.min_size
!= wxDefaultSize
)
779 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
780 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
781 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
782 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
789 bool wxFrameManager::AddPane(wxWindow
* window
,
791 const wxString
& caption
)
794 pinfo
.Caption(caption
);
797 case wxTOP
: pinfo
.Top(); break;
798 case wxBOTTOM
: pinfo
.Bottom(); break;
799 case wxLEFT
: pinfo
.Left(); break;
800 case wxRIGHT
: pinfo
.Right(); break;
801 case wxCENTER
: pinfo
.CenterPane(); break;
803 return AddPane(window
, pinfo
);
806 bool wxFrameManager::AddPane(wxWindow
* window
,
807 const wxPaneInfo
& pane_info
,
808 const wxPoint
& drop_pos
)
810 if (!AddPane(window
, pane_info
))
813 wxPaneInfo
& pane
= GetPane(window
);
815 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
820 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
823 // shift the panes around, depending on the insert level
824 switch (insert_level
)
826 case wxAUI_INSERT_PANE
:
827 DoInsertPane(m_panes
,
828 pane_info
.dock_direction
,
829 pane_info
.dock_layer
,
833 case wxAUI_INSERT_ROW
:
834 DoInsertDockRow(m_panes
,
835 pane_info
.dock_direction
,
836 pane_info
.dock_layer
,
839 case wxAUI_INSERT_DOCK
:
840 DoInsertDockLayer(m_panes
,
841 pane_info
.dock_direction
,
842 pane_info
.dock_layer
);
846 // if the window already exists, we are basically just moving/inserting the
847 // existing window. If it doesn't exist, we need to add it and insert it
848 wxPaneInfo
& existing_pane
= GetPane(window
);
849 if (!existing_pane
.IsOk())
851 return AddPane(window
, pane_info
);
855 if (pane_info
.IsFloating())
857 existing_pane
.Float();
858 if (pane_info
.floating_pos
!= wxDefaultPosition
)
859 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
860 if (pane_info
.floating_size
!= wxDefaultSize
)
861 existing_pane
.FloatingSize(pane_info
.floating_size
);
865 existing_pane
.Direction(pane_info
.dock_direction
);
866 existing_pane
.Layer(pane_info
.dock_layer
);
867 existing_pane
.Row(pane_info
.dock_row
);
868 existing_pane
.Position(pane_info
.dock_pos
);
876 // DetachPane() removes a pane from the frame manager. This
877 // method will not destroy the window that is removed.
878 bool wxFrameManager::DetachPane(wxWindow
* window
)
881 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
883 wxPaneInfo
& p
= m_panes
.Item(i
);
884 if (p
.window
== window
)
888 // we have a floating frame which is being detached. We need to
889 // reparent it to m_frame and destroy the floating frame
892 p
.window
->SetSize(1,1);
894 if (p
.frame
->IsShown())
895 p
.frame
->Show(false);
897 // reparent to m_frame and destroy the pane
898 p
.window
->Reparent(m_frame
);
899 p
.frame
->SetSizer(NULL
);
904 // make sure there are no references to this pane in our uiparts,
905 // just in case the caller doesn't call Update() immediately after
906 // the DetachPane() call. This prevets obscure crashes which would
907 // happen at window repaint if the caller forgets to call Update()
909 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
911 wxDockUIPart
& part
= m_uiparts
.Item(pi
);
914 m_uiparts
.RemoveAt(pi
);
929 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
930 // in the input string. This is an internal functions which is
931 // used for saving perspectives
932 static wxString
EscapeDelimiters(const wxString
& s
)
935 result
.Alloc(s
.length());
936 const wxChar
* ch
= s
.c_str();
939 if (*ch
== wxT(';') || *ch
== wxT('|'))
947 wxString
wxFrameManager::SavePaneInfo(wxPaneInfo
& pane
)
949 wxString result
= wxT("name=");
950 result
+= EscapeDelimiters(pane
.name
);
953 result
+= wxT("caption=");
954 result
+= EscapeDelimiters(pane
.caption
);
957 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
958 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
959 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
960 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
961 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
962 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
963 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
964 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
965 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
966 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
967 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
968 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
969 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
970 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
971 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
972 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
977 // Load a "pane" with the pane infor settings in pane_part
978 void wxFrameManager::LoadPaneInfo(wxString pane_part
, wxPaneInfo
&pane
)
980 // replace escaped characters so we can
981 // split up the string easily
982 pane_part
.Replace(wxT("\\|"), wxT("\a"));
983 pane_part
.Replace(wxT("\\;"), wxT("\b"));
987 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
988 pane_part
= pane_part
.AfterFirst(wxT(';'));
989 wxString val_name
= val_part
.BeforeFirst(wxT('='));
990 wxString value
= val_part
.AfterFirst(wxT('='));
991 val_name
.MakeLower();
993 val_name
.Trim(false);
997 if (val_name
.empty())
1000 if (val_name
== wxT("name"))
1002 else if (val_name
== wxT("caption"))
1003 pane
.caption
= value
;
1004 else if (val_name
== wxT("state"))
1005 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1006 else if (val_name
== wxT("dir"))
1007 pane
.dock_direction
= wxAtoi(value
.c_str());
1008 else if (val_name
== wxT("layer"))
1009 pane
.dock_layer
= wxAtoi(value
.c_str());
1010 else if (val_name
== wxT("row"))
1011 pane
.dock_row
= wxAtoi(value
.c_str());
1012 else if (val_name
== wxT("pos"))
1013 pane
.dock_pos
= wxAtoi(value
.c_str());
1014 else if (val_name
== wxT("prop"))
1015 pane
.dock_proportion
= wxAtoi(value
.c_str());
1016 else if (val_name
== wxT("bestw"))
1017 pane
.best_size
.x
= wxAtoi(value
.c_str());
1018 else if (val_name
== wxT("besth"))
1019 pane
.best_size
.y
= wxAtoi(value
.c_str());
1020 else if (val_name
== wxT("minw"))
1021 pane
.min_size
.x
= wxAtoi(value
.c_str());
1022 else if (val_name
== wxT("minh"))
1023 pane
.min_size
.y
= wxAtoi(value
.c_str());
1024 else if (val_name
== wxT("maxw"))
1025 pane
.max_size
.x
= wxAtoi(value
.c_str());
1026 else if (val_name
== wxT("maxh"))
1027 pane
.max_size
.y
= wxAtoi(value
.c_str());
1028 else if (val_name
== wxT("floatx"))
1029 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1030 else if (val_name
== wxT("floaty"))
1031 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1032 else if (val_name
== wxT("floatw"))
1033 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1034 else if (val_name
== wxT("floath"))
1035 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1037 wxFAIL_MSG(wxT("Bad Perspective String"));
1041 // replace escaped characters so we can
1042 // split up the string easily
1043 pane
.name
.Replace(wxT("\a"), wxT("|"));
1044 pane
.name
.Replace(wxT("\b"), wxT(";"));
1045 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1046 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1047 pane_part
.Replace(wxT("\a"), wxT("|"));
1048 pane_part
.Replace(wxT("\b"), wxT(";"));
1054 // SavePerspective() saves all pane information as a single string.
1055 // This string may later be fed into LoadPerspective() to restore
1056 // all pane settings. This save and load mechanism allows an
1057 // exact pane configuration to be saved and restored at a later time
1059 wxString
wxFrameManager::SavePerspective()
1063 result
= wxT("layout1|");
1065 int pane_i
, pane_count
= m_panes
.GetCount();
1066 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1068 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
1069 result
+= SavePaneInfo(pane
)+wxT("|");
1072 int dock_i
, dock_count
= m_docks
.GetCount();
1073 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1075 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
1077 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1078 dock
.dock_direction
, dock
.dock_layer
,
1079 dock
.dock_row
, dock
.size
);
1085 // LoadPerspective() loads a layout which was saved with SavePerspective()
1086 // If the "update" flag parameter is true, the GUI will immediately be updated
1088 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
1090 wxString input
= layout
;
1093 // check layout string version
1094 part
= input
.BeforeFirst(wxT('|'));
1095 input
= input
.AfterFirst(wxT('|'));
1098 if (part
!= wxT("layout1"))
1101 // mark all panes currently managed as docked and hidden
1102 int pane_i
, pane_count
= m_panes
.GetCount();
1103 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1104 m_panes
.Item(pane_i
).Dock().Hide();
1106 // clear out the dock array; this will be reconstructed
1109 // replace escaped characters so we can
1110 // split up the string easily
1111 input
.Replace(wxT("\\|"), wxT("\a"));
1112 input
.Replace(wxT("\\;"), wxT("\b"));
1118 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1119 input
= input
.AfterFirst(wxT('|'));
1120 pane_part
.Trim(true);
1122 // if the string is empty, we're done parsing
1123 if (pane_part
.empty())
1126 if (pane_part
.Left(9) == wxT("dock_size"))
1128 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1129 wxString value
= pane_part
.AfterFirst(wxT('='));
1131 long dir
, layer
, row
, size
;
1132 wxString piece
= val_name
.AfterFirst(wxT('('));
1133 piece
= piece
.BeforeLast(wxT(')'));
1134 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1135 piece
= piece
.AfterFirst(wxT(','));
1136 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1137 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1138 value
.ToLong(&size
);
1141 dock
.dock_direction
= dir
;
1142 dock
.dock_layer
= layer
;
1143 dock
.dock_row
= row
;
1149 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1150 // name so it can be called by external callers
1151 pane_part
.Replace(wxT("\a"), wxT("|"));
1152 pane_part
.Replace(wxT("\b"), wxT(";"));
1154 LoadPaneInfo(pane_part
, pane
);
1156 wxPaneInfo
& p
= GetPane(pane
.name
);
1159 // the pane window couldn't be found
1160 // in the existing layout
1174 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
1175 wxArrayInt
& positions
,
1178 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1179 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1180 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1185 int offset
, action_pane
= -1;
1186 int pane_i
, pane_count
= dock
.panes
.GetCount();
1188 // find the pane marked as our action pane
1189 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1191 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1193 if (pane
.state
& wxPaneInfo::actionPane
)
1195 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1196 action_pane
= pane_i
;
1200 // set up each panes default position, and
1201 // determine the size (width or height, depending
1202 // on the dock's orientation) of each pane
1203 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1205 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1206 positions
.Add(pane
.dock_pos
);
1209 if (pane
.HasBorder())
1210 size
+= (pane_border_size
*2);
1212 if (dock
.IsHorizontal())
1214 if (pane
.HasGripper() && !pane
.HasGripperTop())
1215 size
+= gripper_size
;
1216 size
+= pane
.best_size
.x
;
1220 if (pane
.HasGripper() && pane
.HasGripperTop())
1221 size
+= gripper_size
;
1223 if (pane
.HasCaption())
1224 size
+= caption_size
;
1225 size
+= pane
.best_size
.y
;
1231 // if there is no action pane, just return the default
1232 // positions (as specified in pane.pane_pos)
1233 if (action_pane
== -1)
1237 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1239 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1244 positions
[pane_i
] -= -amount
;
1246 offset
+= sizes
[pane_i
];
1249 // if the dock mode is fixed, make sure none of the panes
1250 // overlap; we will bump panes that overlap
1252 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1254 int amount
= positions
[pane_i
] - offset
;
1258 positions
[pane_i
] += -amount
;
1260 offset
+= sizes
[pane_i
];
1265 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1268 wxDockUIPartArray
& uiparts
,
1272 wxSizerItem
* sizer_item
;
1274 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1275 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1276 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1277 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1279 // find out the orientation of the item (orientation for panes
1280 // is the same as the dock's orientation)
1282 if (dock
.IsHorizontal())
1283 orientation
= wxHORIZONTAL
;
1285 orientation
= wxVERTICAL
;
1287 // this variable will store the proportion
1288 // value that the pane will receive
1289 int pane_proportion
= pane
.dock_proportion
;
1291 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1292 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1294 if (pane
.HasGripper())
1296 if (pane
.HasGripperTop())
1297 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1299 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1301 part
.type
= wxDockUIPart::typeGripper
;
1305 part
.orientation
= orientation
;
1306 part
.cont_sizer
= horz_pane_sizer
;
1307 part
.sizer_item
= sizer_item
;
1311 if (pane
.HasCaption())
1313 // create the caption sizer
1314 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1316 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1318 part
.type
= wxDockUIPart::typeCaption
;
1322 part
.orientation
= orientation
;
1323 part
.cont_sizer
= vert_pane_sizer
;
1324 part
.sizer_item
= sizer_item
;
1325 int caption_part_idx
= uiparts
.GetCount();
1328 // add pane buttons to the caption
1329 int i
, button_count
;
1330 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1331 i
< button_count
; ++i
)
1333 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1335 sizer_item
= caption_sizer
->Add(pane_button_size
,
1339 part
.type
= wxDockUIPart::typePaneButton
;
1342 part
.button
= &button
;
1343 part
.orientation
= orientation
;
1344 part
.cont_sizer
= caption_sizer
;
1345 part
.sizer_item
= sizer_item
;
1349 // add the caption sizer
1350 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1352 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1355 // add the pane window itself
1358 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1362 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1363 // Don't do this because it breaks the pane size in floating windows
1364 // BIW: Right now commenting this out is causing problems with
1365 // an mdi client window as the center pane.
1366 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1369 part
.type
= wxDockUIPart::typePane
;
1373 part
.orientation
= orientation
;
1374 part
.cont_sizer
= vert_pane_sizer
;
1375 part
.sizer_item
= sizer_item
;
1379 // determine if the pane should have a minimum size; if the pane is
1380 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1381 // if the pane.min_size is set, we must use that value as well
1383 wxSize min_size
= pane
.min_size
;
1386 if (min_size
== wxDefaultSize
)
1388 min_size
= pane
.best_size
;
1389 pane_proportion
= 0;
1393 if (min_size
!= wxDefaultSize
)
1395 vert_pane_sizer
->SetItemMinSize(
1396 vert_pane_sizer
->GetChildren().GetCount()-1,
1397 min_size
.x
, min_size
.y
);
1401 // add the verticle sizer (caption, pane window) to the
1402 // horizontal sizer (gripper, verticle sizer)
1403 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1405 // finally, add the pane sizer to the dock sizer
1407 if (pane
.HasBorder())
1409 // allowing space for the pane's border
1410 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1411 wxEXPAND
| wxALL
, pane_border_size
);
1413 part
.type
= wxDockUIPart::typePaneBorder
;
1417 part
.orientation
= orientation
;
1418 part
.cont_sizer
= cont
;
1419 part
.sizer_item
= sizer_item
;
1424 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1428 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1430 wxDockUIPartArray
& uiparts
,
1433 wxSizerItem
* sizer_item
;
1436 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1437 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1439 // resizable bottom and right docks have a sash before them
1440 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1441 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1443 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1445 part
.type
= wxDockUIPart::typeDockSizer
;
1446 part
.orientation
= orientation
;
1450 part
.cont_sizer
= cont
;
1451 part
.sizer_item
= sizer_item
;
1455 // create the sizer for the dock
1456 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1458 // add each pane to the dock
1459 int pane_i
, pane_count
= dock
.panes
.GetCount();
1463 wxArrayInt pane_positions
, pane_sizes
;
1465 // figure out the real pane positions we will
1466 // use, without modifying the each pane's pane_pos member
1467 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1470 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1472 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1473 int pane_pos
= pane_positions
.Item(pane_i
);
1475 int amount
= pane_pos
- offset
;
1478 if (dock
.IsVertical())
1479 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1481 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1483 part
.type
= wxDockUIPart::typeBackground
;
1487 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1488 part
.cont_sizer
= dock_sizer
;
1489 part
.sizer_item
= sizer_item
;
1495 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1497 offset
+= pane_sizes
.Item(pane_i
);
1500 // at the end add a very small stretchable background area
1501 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1503 part
.type
= wxDockUIPart::typeBackground
;
1507 part
.orientation
= orientation
;
1508 part
.cont_sizer
= dock_sizer
;
1509 part
.sizer_item
= sizer_item
;
1514 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1516 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1518 // if this is not the first pane being added,
1519 // we need to add a pane sizer
1522 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1524 part
.type
= wxDockUIPart::typePaneSizer
;
1526 part
.pane
= dock
.panes
.Item(pane_i
-1);
1528 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1529 part
.cont_sizer
= dock_sizer
;
1530 part
.sizer_item
= sizer_item
;
1534 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1538 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1539 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1541 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1543 part
.type
= wxDockUIPart::typeDock
;
1547 part
.orientation
= orientation
;
1548 part
.cont_sizer
= cont
;
1549 part
.sizer_item
= sizer_item
;
1552 if (dock
.IsHorizontal())
1553 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1555 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1557 // top and left docks have a sash after them
1558 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1559 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1561 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1563 part
.type
= wxDockUIPart::typeDockSizer
;
1567 part
.orientation
= orientation
;
1568 part
.cont_sizer
= cont
;
1569 part
.sizer_item
= sizer_item
;
1574 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1575 wxDockInfoArray
& docks
,
1576 wxDockUIPartArray
& uiparts
,
1579 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1581 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1582 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1583 wxSize cli_size
= m_frame
->GetClientSize();
1584 int i
, dock_count
, pane_count
;
1587 // empty all docks out
1588 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1589 docks
.Item(i
).panes
.Empty();
1591 // iterate through all known panes, filing each
1592 // of them into the appropriate dock. If the
1593 // pane does not exist in the dock, add it
1594 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1596 wxPaneInfo
& p
= panes
.Item(i
);
1598 // find any docks in this layer
1600 wxDockInfoPtrArray arr
;
1601 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1603 if (arr
.GetCount() > 0)
1609 // dock was not found, so we need to create a new one
1611 d
.dock_direction
= p
.dock_direction
;
1612 d
.dock_layer
= p
.dock_layer
;
1613 d
.dock_row
= p
.dock_row
;
1615 dock
= &docks
.Last();
1619 if (p
.IsDocked() && p
.IsShown())
1621 // remove the pane from any existing docks except this one
1622 RemovePaneFromDocks(docks
, p
, dock
);
1624 // pane needs to be added to the dock,
1625 // if it doesn't already exist
1626 if (!FindPaneInDock(*dock
, p
.window
))
1627 dock
->panes
.Add(&p
);
1631 // remove the pane from any existing docks
1632 RemovePaneFromDocks(docks
, p
);
1637 // remove any empty docks
1638 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1640 if (docks
.Item(i
).panes
.GetCount() == 0)
1644 // configure the docks further
1645 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1647 wxDockInfo
& dock
= docks
.Item(i
);
1648 int j
, dock_pane_count
= dock
.panes
.GetCount();
1650 // sort the dock pane array by the pane's
1651 // dock position (dock_pos), in ascending order
1652 dock
.panes
.Sort(PaneSortFunc
);
1654 // for newly created docks, set up their initial size
1659 for (j
= 0; j
< dock_pane_count
; ++j
)
1661 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1662 wxSize pane_size
= pane
.best_size
;
1663 if (pane_size
== wxDefaultSize
)
1664 pane_size
= pane
.min_size
;
1665 if (pane_size
== wxDefaultSize
)
1666 pane_size
= pane
.window
->GetSize();
1668 if (dock
.IsHorizontal())
1669 size
= wxMax(pane_size
.y
, size
);
1671 size
= wxMax(pane_size
.x
, size
);
1674 // add space for the border (two times), but only
1675 // if at least one pane inside the dock has a pane border
1676 for (j
= 0; j
< dock_pane_count
; ++j
)
1678 if (dock
.panes
.Item(j
)->HasBorder())
1680 size
+= (pane_border_size
*2);
1685 // if pane is on the top or bottom, add the caption height,
1686 // but only if at least one pane inside the dock has a caption
1687 if (dock
.IsHorizontal())
1689 for (j
= 0; j
< dock_pane_count
; ++j
)
1691 if (dock
.panes
.Item(j
)->HasCaption())
1693 size
+= caption_size
;
1699 // new dock's size may not be more than 1/3 of the frame size
1700 if (dock
.IsHorizontal())
1701 size
= wxMin(size
, cli_size
.y
/3);
1703 size
= wxMin(size
, cli_size
.x
/3);
1711 // determine the dock's minimum size
1712 bool plus_border
= false;
1713 bool plus_caption
= false;
1714 int dock_min_size
= 0;
1715 for (j
= 0; j
< dock_pane_count
; ++j
)
1717 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1718 if (pane
.min_size
!= wxDefaultSize
)
1720 if (pane
.HasBorder())
1722 if (pane
.HasCaption())
1723 plus_caption
= true;
1724 if (dock
.IsHorizontal())
1726 if (pane
.min_size
.y
> dock_min_size
)
1727 dock_min_size
= pane
.min_size
.y
;
1731 if (pane
.min_size
.x
> dock_min_size
)
1732 dock_min_size
= pane
.min_size
.x
;
1738 dock_min_size
+= (pane_border_size
*2);
1739 if (plus_caption
&& dock
.IsHorizontal())
1740 dock_min_size
+= (caption_size
);
1742 dock
.min_size
= dock_min_size
;
1745 // if the pane's current size is less than it's
1746 // minimum, increase the dock's size to it's minimum
1747 if (dock
.size
< dock
.min_size
)
1748 dock
.size
= dock
.min_size
;
1751 // determine the dock's mode (fixed or proportional);
1752 // determine whether the dock has only toolbars
1753 bool action_pane_marked
= false;
1755 dock
.toolbar
= true;
1756 for (j
= 0; j
< dock_pane_count
; ++j
)
1758 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1759 if (!pane
.IsFixed())
1761 if (!pane
.IsToolbar())
1762 dock
.toolbar
= false;
1763 if (pane
.state
& wxPaneInfo::actionPane
)
1764 action_pane_marked
= true;
1768 // if the dock mode is proportional and not fixed-pixel,
1769 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1770 // e.g. remove gaps like 1, 2, 30, 500
1773 for (j
= 0; j
< dock_pane_count
; ++j
)
1775 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1780 // if the dock mode is fixed, and none of the panes
1781 // are being moved right now, make sure the panes
1782 // do not overlap each other. If they do, we will
1783 // adjust the panes' positions
1784 if (dock
.fixed
&& !action_pane_marked
)
1786 wxArrayInt pane_positions
, pane_sizes
;
1787 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1790 for (j
= 0; j
< dock_pane_count
; ++j
)
1792 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1793 pane
.dock_pos
= pane_positions
[j
];
1795 int amount
= pane
.dock_pos
- offset
;
1799 pane
.dock_pos
+= -amount
;
1801 offset
+= pane_sizes
[j
];
1806 // discover the maximum dock layer
1808 for (i
= 0; i
< dock_count
; ++i
)
1809 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1812 // clear out uiparts
1815 // create a bunch of box sizers,
1816 // from the innermost level outwards.
1817 wxSizer
* cont
= NULL
;
1818 wxSizer
* middle
= NULL
;
1822 for (layer
= 0; layer
<= max_layer
; ++layer
)
1824 wxDockInfoPtrArray arr
;
1826 // find any docks in this layer
1827 FindDocks(docks
, -1, layer
, -1, arr
);
1829 // if there aren't any, skip to the next layer
1833 wxSizer
* old_cont
= cont
;
1835 // create a container which will hold this layer's
1836 // docks (top, bottom, left, right)
1837 cont
= new wxBoxSizer(wxVERTICAL
);
1840 // find any top docks in this layer
1841 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1842 RenumberDockRows(arr
);
1845 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1846 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1850 // fill out the middle layer (which consists
1851 // of left docks, content area and right docks)
1853 middle
= new wxBoxSizer(wxHORIZONTAL
);
1855 // find any left docks in this layer
1856 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1857 RenumberDockRows(arr
);
1860 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1861 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1864 // add content dock (or previous layer's sizer
1868 // find any center docks
1869 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1872 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1873 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1877 // there are no center docks, add a background area
1878 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1880 part
.type
= wxDockUIPart::typeBackground
;
1884 part
.cont_sizer
= middle
;
1885 part
.sizer_item
= sizer_item
;
1891 middle
->Add(old_cont
, 1, wxEXPAND
);
1894 // find any right docks in this layer
1895 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1896 RenumberDockRows(arr
);
1899 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1900 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1903 cont
->Add(middle
, 1, wxEXPAND
);
1907 // find any bottom docks in this layer
1908 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1909 RenumberDockRows(arr
);
1912 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1913 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1920 // no sizer available, because there are no docks,
1921 // therefore we will create a simple background area
1922 cont
= new wxBoxSizer(wxVERTICAL
);
1923 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1925 part
.type
= wxDockUIPart::typeBackground
;
1929 part
.cont_sizer
= middle
;
1930 part
.sizer_item
= sizer_item
;
1934 container
->Add(cont
, 1, wxEXPAND
);
1939 // Update() updates the layout. Whenever changes are made to
1940 // one or more panes, this function should be called. It is the
1941 // external entry point for running the layout engine.
1943 void wxFrameManager::Update()
1946 int i
, pane_count
= m_panes
.GetCount();
1948 // delete old sizer first
1949 m_frame
->SetSizer(NULL
);
1951 // destroy floating panes which have been
1952 // redocked or are becoming non-floating
1953 for (i
= 0; i
< pane_count
; ++i
)
1955 wxPaneInfo
& p
= m_panes
.Item(i
);
1957 if (!p
.IsFloating() && p
.frame
)
1959 // because the pane is no longer in a floating, we need to
1960 // reparent it to m_frame and destroy the floating frame
1963 p
.window
->SetSize(1,1);
1965 if (p
.frame
->IsShown())
1966 p
.frame
->Show(false);
1968 // reparent to m_frame and destroy the pane
1969 p
.window
->Reparent(m_frame
);
1970 p
.frame
->SetSizer(NULL
);
1977 // create a layout for all of the panes
1978 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
1980 // hide or show panes as necessary,
1981 // and float panes as necessary
1982 for (i
= 0; i
< pane_count
; ++i
)
1984 wxPaneInfo
& p
= m_panes
.Item(i
);
1988 if (p
.frame
== NULL
)
1990 // we need to create a frame for this
1991 // pane, which has recently been floated
1992 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
1996 #if wxCHECK_VERSION(2,7,0)
1997 // on MSW and Mac, if the owner desires transparent dragging, and
1998 // the dragging is happening right now, then the floating
1999 // window should have this style by default
2000 if (m_action
== actionDragFloatingPane
&&
2001 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2002 frame
->SetTransparent(150);
2005 frame
->SetPaneWindow(p
);
2008 if (p
.IsShown() && !frame
->IsShown())
2013 // frame already exists, make sure it's position
2014 // and size reflect the information in wxPaneInfo
2015 if (p
.frame
->GetPosition() != p
.floating_pos
)
2017 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2018 wxDefaultCoord
, wxDefaultCoord
,
2019 wxSIZE_USE_EXISTING
);
2020 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2023 if (p
.frame
->IsShown() != p
.IsShown())
2024 p
.frame
->Show(p
.IsShown());
2029 if (p
.window
->IsShown() != p
.IsShown())
2030 p
.window
->Show(p
.IsShown());
2033 // if "active panes" are no longer allowed, clear
2034 // any optionActive values from the pane states
2035 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2037 p
.state
&= ~wxPaneInfo::optionActive
;
2042 // keep track of the old window rectangles so we can
2043 // refresh those windows whose rect has changed
2044 wxAuiRectArray old_pane_rects
;
2045 for (i
= 0; i
< pane_count
; ++i
)
2048 wxPaneInfo
& p
= m_panes
.Item(i
);
2050 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2053 old_pane_rects
.Add(r
);
2059 // apply the new sizer
2060 m_frame
->SetSizer(sizer
);
2061 m_frame
->SetAutoLayout(false);
2066 // now that the frame layout is done, we need to check
2067 // the new pane rectangles against the old rectangles that
2068 // we saved a few lines above here. If the rectangles have
2069 // changed, the corresponding panes must also be updated
2070 for (i
= 0; i
< pane_count
; ++i
)
2072 wxPaneInfo
& p
= m_panes
.Item(i
);
2073 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2075 if (p
.rect
!= old_pane_rects
[i
])
2077 p
.window
->Refresh();
2086 // set frame's minimum size
2089 // N.B. More work needs to be done on frame minimum sizes;
2090 // this is some intresting code that imposes the minimum size,
2091 // but we may want to include a more flexible mechanism or
2092 // options for multiple minimum-size modes, e.g. strict or lax
2093 wxSize min_size = sizer->GetMinSize();
2094 wxSize frame_size = m_frame->GetSize();
2095 wxSize client_size = m_frame->GetClientSize();
2097 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2098 min_size.y+frame_size.y-client_size.y );
2100 m_frame->SetMinSize(minframe_size);
2102 if (frame_size.x < minframe_size.x ||
2103 frame_size.y < minframe_size.y)
2104 sizer->Fit(m_frame);
2109 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2110 // on the frame's main sizer, then measures all the various UI items
2111 // and updates their internal rectangles. This should always be called
2112 // instead of calling m_frame->Layout() directly
2114 void wxFrameManager::DoFrameLayout()
2119 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2121 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2123 // get the rectangle of the UI part
2124 // originally, this code looked like this:
2125 // part.rect = wxRect(part.sizer_item->GetPosition(),
2126 // part.sizer_item->GetSize());
2127 // this worked quite well, with one exception: the mdi
2128 // client window had a "deferred" size variable
2129 // that returned the wrong size. It looks like
2130 // a bug in wx, because the former size of the window
2131 // was being returned. So, we will retrieve the part's
2132 // rectangle via other means
2135 part
.rect
= part
.sizer_item
->GetRect();
2136 int flag
= part
.sizer_item
->GetFlag();
2137 int border
= part
.sizer_item
->GetBorder();
2140 part
.rect
.y
-= border
;
2141 part
.rect
.height
+= border
;
2145 part
.rect
.x
-= border
;
2146 part
.rect
.width
+= border
;
2148 if (flag
& wxBOTTOM
)
2149 part
.rect
.height
+= border
;
2151 part
.rect
.width
+= border
;
2154 if (part
.type
== wxDockUIPart::typeDock
)
2155 part
.dock
->rect
= part
.rect
;
2156 if (part
.type
== wxDockUIPart::typePane
)
2157 part
.pane
->rect
= part
.rect
;
2161 // GetPanePart() looks up the pane the pane border UI part (or the regular
2162 // pane part if there is no border). This allows the caller to get the exact
2163 // rectangle of the pane in question, including decorations like
2164 // caption and border (if any).
2166 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
2169 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2171 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2172 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2173 part
.pane
&& part
.pane
->window
== wnd
)
2176 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2178 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2179 if (part
.type
== wxDockUIPart::typePane
&&
2180 part
.pane
&& part
.pane
->window
== wnd
)
2188 // GetDockPixelOffset() is an internal function which returns
2189 // a dock's offset in pixels from the left side of the window
2190 // (for horizontal docks) or from the top of the window (for
2191 // vertical docks). This value is necessary for calculating
2192 // fixel-pane/toolbar offsets when they are dragged.
2194 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
2196 // the only way to accurately calculate the dock's
2197 // offset is to actually run a theoretical layout
2199 int i
, part_count
, dock_count
;
2200 wxDockInfoArray docks
;
2201 wxPaneInfoArray panes
;
2202 wxDockUIPartArray uiparts
;
2203 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2206 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2207 wxSize client_size
= m_frame
->GetClientSize();
2208 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2211 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2213 wxDockUIPart
& part
= uiparts
.Item(i
);
2214 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2215 part
.sizer_item
->GetSize());
2216 if (part
.type
== wxDockUIPart::typeDock
)
2217 part
.dock
->rect
= part
.rect
;
2222 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2224 wxDockInfo
& dock
= docks
.Item(i
);
2225 if (test
.dock_direction
== dock
.dock_direction
&&
2226 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2228 if (dock
.IsVertical())
2240 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2241 // if a dock operation is allowed, the new dock position is copied into
2242 // the target info. If the operation was allowed, the function returns true.
2244 bool wxFrameManager::ProcessDockResult(wxPaneInfo
& target
,
2245 const wxPaneInfo
& new_pos
)
2247 bool allowed
= false;
2248 switch (new_pos
.dock_direction
)
2250 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2251 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2252 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2253 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2263 // DoDrop() is an important function. It basically takes a mouse position,
2264 // and determines where the pane's new position would be. If the pane is to be
2265 // dropped, it performs the drop operation using the specified dock and pane
2266 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2267 // scenario can be performed, giving precise coordinates for drop hints.
2268 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2269 // as parameters, the changes will be made to the main state arrays
2271 const int auiInsertRowPixels
= 10;
2272 const int auiNewRowPixels
= 40;
2273 const int auiLayerInsertPixels
= 40;
2274 const int auiLayerInsertOffset
= 5;
2276 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2277 wxPaneInfoArray
& panes
,
2280 const wxPoint
& offset
)
2282 wxSize cli_size
= m_frame
->GetClientSize();
2284 wxPaneInfo drop
= target
;
2287 // The result should always be shown
2291 // Check to see if the pane has been dragged outside of the window
2292 // (or near to the outside of the window), if so, dock it along the edge
2295 int layer_insert_offset
= auiLayerInsertOffset
;
2296 if (target
.IsToolbar())
2297 layer_insert_offset
= 0;
2299 if (pt
.x
< layer_insert_offset
&&
2300 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2302 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2303 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2304 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2308 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2309 return ProcessDockResult(target
, drop
);
2311 else if (pt
.y
< layer_insert_offset
&&
2312 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2314 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2315 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2316 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2320 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2321 return ProcessDockResult(target
, drop
);
2323 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2324 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2326 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2327 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2328 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2329 drop
.Dock().Right().
2332 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2333 return ProcessDockResult(target
, drop
);
2335 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2336 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2338 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2339 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2340 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2341 drop
.Dock().Bottom().
2344 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2345 return ProcessDockResult(target
, drop
);
2349 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2352 if (drop
.IsToolbar())
2354 if (!part
|| !part
->dock
)
2358 // calculate the offset from where the dock begins
2359 // to the point where the user dropped the pane
2360 int dock_drop_offset
= 0;
2361 if (part
->dock
->IsHorizontal())
2362 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2364 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2367 // toolbars may only be moved in and to fixed-pane docks,
2368 // otherwise we will try to float the pane. Also, the pane
2369 // should float if being dragged over center pane windows
2370 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2372 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2373 (drop
.IsFloatable() ||
2374 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2375 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2380 return ProcessDockResult(target
, drop
);
2384 Direction(part
->dock
->dock_direction
).
2385 Layer(part
->dock
->dock_layer
).
2386 Row(part
->dock
->dock_row
).
2387 Position(dock_drop_offset
);
2390 ((pt
.y
< part
->dock
->rect
.y
+ 2) && part
->dock
->IsHorizontal()) ||
2391 ((pt
.x
< part
->dock
->rect
.x
+ 2) && part
->dock
->IsVertical())
2392 ) && part
->dock
->panes
.GetCount() > 1)
2394 int row
= drop
.dock_row
;
2395 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2396 part
->dock
->dock_layer
,
2397 part
->dock
->dock_row
);
2398 drop
.dock_row
= row
;
2402 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2403 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2404 ) && part
->dock
->panes
.GetCount() > 1)
2406 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2407 part
->dock
->dock_layer
,
2408 part
->dock
->dock_row
+1);
2409 drop
.dock_row
= part
->dock
->dock_row
+1;
2412 return ProcessDockResult(target
, drop
);
2421 if (part
->type
== wxDockUIPart::typePaneBorder
||
2422 part
->type
== wxDockUIPart::typeCaption
||
2423 part
->type
== wxDockUIPart::typeGripper
||
2424 part
->type
== wxDockUIPart::typePaneButton
||
2425 part
->type
== wxDockUIPart::typePane
||
2426 part
->type
== wxDockUIPart::typePaneSizer
||
2427 part
->type
== wxDockUIPart::typeDockSizer
||
2428 part
->type
== wxDockUIPart::typeBackground
)
2430 if (part
->type
== wxDockUIPart::typeDockSizer
)
2432 if (part
->dock
->panes
.GetCount() != 1)
2434 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2441 // If a normal frame is being dragged over a toolbar, insert it
2442 // along the edge under the toolbar, but over all other panes.
2443 // (this could be done much better, but somehow factoring this
2444 // calculation with the one at the beginning of this function)
2445 if (part
->dock
&& part
->dock
->toolbar
)
2449 switch (part
->dock
->dock_direction
)
2451 case wxAUI_DOCK_LEFT
:
2452 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2453 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2454 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2456 case wxAUI_DOCK_TOP
:
2457 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2458 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2459 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2461 case wxAUI_DOCK_RIGHT
:
2462 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2463 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2464 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2466 case wxAUI_DOCK_BOTTOM
:
2467 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2468 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2469 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2473 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2476 Direction(part
->dock
->dock_direction
).
2477 Layer(layer
).Row(0).Position(0);
2478 return ProcessDockResult(target
, drop
);
2485 part
= GetPanePart(part
->pane
->window
);
2489 bool insert_dock_row
= false;
2490 int insert_row
= part
->pane
->dock_row
;
2491 int insert_dir
= part
->pane
->dock_direction
;
2492 int insert_layer
= part
->pane
->dock_layer
;
2494 switch (part
->pane
->dock_direction
)
2496 case wxAUI_DOCK_TOP
:
2497 if (pt
.y
>= part
->rect
.y
&&
2498 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2499 insert_dock_row
= true;
2501 case wxAUI_DOCK_BOTTOM
:
2502 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2503 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2504 insert_dock_row
= true;
2506 case wxAUI_DOCK_LEFT
:
2507 if (pt
.x
>= part
->rect
.x
&&
2508 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2509 insert_dock_row
= true;
2511 case wxAUI_DOCK_RIGHT
:
2512 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2513 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2514 insert_dock_row
= true;
2516 case wxAUI_DOCK_CENTER
:
2518 // "new row pixels" will be set to the default, but
2519 // must never exceed 20% of the window size
2520 int new_row_pixels_x
= auiNewRowPixels
;
2521 int new_row_pixels_y
= auiNewRowPixels
;
2523 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2524 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2526 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2527 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2530 // determine if the mouse pointer is in a location that
2531 // will cause a new row to be inserted. The hot spot positions
2532 // are along the borders of the center pane
2535 insert_dock_row
= true;
2536 if (pt
.x
>= part
->rect
.x
&&
2537 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2538 insert_dir
= wxAUI_DOCK_LEFT
;
2540 if (pt
.y
>= part
->rect
.y
&&
2541 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2542 insert_dir
= wxAUI_DOCK_TOP
;
2544 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2545 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2546 insert_dir
= wxAUI_DOCK_RIGHT
;
2548 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2549 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2550 insert_dir
= wxAUI_DOCK_BOTTOM
;
2554 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2558 if (insert_dock_row
)
2560 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2561 drop
.Dock().Direction(insert_dir
).
2562 Layer(insert_layer
).
2565 return ProcessDockResult(target
, drop
);
2568 // determine the mouse offset and the pane size, both in the
2569 // direction of the dock itself, and perpendicular to the dock
2573 if (part
->orientation
== wxVERTICAL
)
2575 offset
= pt
.y
- part
->rect
.y
;
2576 size
= part
->rect
.GetHeight();
2580 offset
= pt
.x
- part
->rect
.x
;
2581 size
= part
->rect
.GetWidth();
2584 int drop_position
= part
->pane
->dock_pos
;
2586 // if we are in the top/left part of the pane,
2587 // insert the pane before the pane being hovered over
2588 if (offset
<= size
/2)
2590 drop_position
= part
->pane
->dock_pos
;
2592 part
->pane
->dock_direction
,
2593 part
->pane
->dock_layer
,
2594 part
->pane
->dock_row
,
2595 part
->pane
->dock_pos
);
2598 // if we are in the bottom/right part of the pane,
2599 // insert the pane before the pane being hovered over
2600 if (offset
> size
/2)
2602 drop_position
= part
->pane
->dock_pos
+1;
2604 part
->pane
->dock_direction
,
2605 part
->pane
->dock_layer
,
2606 part
->pane
->dock_row
,
2607 part
->pane
->dock_pos
+1);
2611 Direction(part
->dock
->dock_direction
).
2612 Layer(part
->dock
->dock_layer
).
2613 Row(part
->dock
->dock_row
).
2614 Position(drop_position
);
2615 return ProcessDockResult(target
, drop
);
2622 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2624 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
2626 m_hint_fadetimer
.Stop();
2630 m_hint_fadeamt
+= 4;
2631 #if wxCHECK_VERSION(2,7,0)
2632 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2634 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2635 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2639 void wxFrameManager::ShowHint(const wxRect
& rect
)
2641 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0
2643 // Finally, don't use a venetian blind effect if it's been specifically disabled
2644 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2645 (m_flags
& wxAUI_MGR_DISABLE_VENETIAN_BLINDS
))
2648 if (m_last_hint
== rect
)
2652 m_hint_fadeamt
= m_hint_fademax
;
2653 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2654 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2655 (m_flags
& wxAUI_MGR_DISABLE_VENETIAN_BLINDS_FADE
))
2659 if (! m_hint_wnd
->IsShown())
2662 // if we are dragging a floating pane, set the focus
2663 // back to that floating pane (otherwise it becomes unfocused)
2664 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2665 m_action_window
->SetFocus();
2667 #if wxCHECK_VERSION(2,7,0)
2668 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2670 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2671 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2673 m_hint_wnd
->SetSize(rect
);
2674 m_hint_wnd
->Raise();
2677 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
2679 // start fade in timer
2680 m_hint_fadetimer
.SetOwner(this, 101);
2681 m_hint_fadetimer
.Start(5);
2685 else // Not using a transparent hint window...
2688 if (m_last_hint
!= rect
)
2690 // remove the last hint rectangle
2696 wxScreenDC screendc
;
2697 wxRegion
clip(1, 1, 10000, 10000);
2699 // clip all floating windows, so we don't draw over them
2701 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2703 wxPaneInfo
& pane
= m_panes
.Item(i
);
2705 if (pane
.IsFloating() &&
2706 pane
.frame
->IsShown())
2708 wxRect rect
= pane
.frame
->GetRect();
2710 // wxGTK returns the client size, not the whole frame size
2716 clip
.Subtract(rect
);
2720 // As we can only hide the hint by redrawing the managed window, we
2721 // need to clip the region to the managed window too or we get
2722 // nasty redrawn problems.
2723 clip
.Intersect(m_frame
->GetRect());
2725 screendc
.SetClippingRegion(clip
);
2727 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2728 wxBrush
brush(stipple
);
2729 screendc
.SetBrush(brush
);
2730 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2732 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2733 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2734 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2735 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2739 void wxFrameManager::HideHint()
2741 // hides a transparent window hint, if there is one
2744 if (m_hint_wnd
->IsShown())
2745 m_hint_wnd
->Show(false);
2746 #if wxCHECK_VERSION(2,7,0)
2747 m_hint_wnd
->SetTransparent(0);
2749 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2750 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(0);
2752 m_hint_fadetimer
.Stop();
2753 m_last_hint
= wxRect();
2757 // hides a painted hint by redrawing the frame window
2758 if (!m_last_hint
.IsEmpty())
2762 m_last_hint
= wxRect();
2768 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2769 // determine the exact position the pane would be at were if dropped. If
2770 // the pame would indeed become docked at the specified drop point,
2771 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2772 // "pane_window" is the window pointer of the pane being dragged, pt is
2773 // the mouse position, in client coordinates
2774 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2776 const wxPoint
& offset
)
2780 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2781 // we will create a new temporary layout and then measure the resulting
2782 // rectangle; we will create a copy of the docking structures (m_dock)
2783 // so that we don't modify the real thing on screen
2785 int i
, pane_count
, part_count
;
2786 wxDockInfoArray docks
;
2787 wxPaneInfoArray panes
;
2788 wxDockUIPartArray uiparts
;
2789 wxPaneInfo hint
= GetPane(pane_window
);
2790 hint
.name
= wxT("__HINT__");
2796 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2798 // remove any pane already there which bears the same window;
2799 // this happens when you are moving a pane around in a dock
2800 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2802 if (panes
.Item(i
).window
== pane_window
)
2804 RemovePaneFromDocks(docks
, panes
.Item(i
));
2810 // find out where the new pane would be
2811 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2819 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2820 wxSize client_size
= m_frame
->GetClientSize();
2821 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2824 for (i
= 0, part_count
= uiparts
.GetCount();
2825 i
< part_count
; ++i
)
2827 wxDockUIPart
& part
= uiparts
.Item(i
);
2829 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2830 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2832 rect
= wxRect(part
.sizer_item
->GetPosition(),
2833 part
.sizer_item
->GetSize());
2846 // actually show the hint rectangle on the screen
2847 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2851 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2853 // try to find the pane
2854 wxPaneInfo
& pane
= GetPane(wnd
);
2855 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2857 #if wxCHECK_VERSION(2,7,0)
2858 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2859 pane
.frame
->SetTransparent(150);
2863 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
)
2865 // try to find the pane
2866 wxPaneInfo
& pane
= GetPane(wnd
);
2867 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2869 wxPoint pt
= ::wxGetMousePosition();
2870 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2872 // calculate the offset from the upper left-hand corner
2873 // of the frame to the mouse pointer
2874 wxPoint frame_pos
= pane
.frame
->GetPosition();
2875 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2877 // no hint for toolbar floating windows
2878 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
2880 if (m_action
== actionDragFloatingPane
)
2882 wxDockInfoArray docks
;
2883 wxPaneInfoArray panes
;
2884 wxDockUIPartArray uiparts
;
2885 wxPaneInfo hint
= pane
;
2887 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2889 // find out where the new pane would be
2890 if (!DoDrop(docks
, panes
, hint
, client_pt
))
2892 if (hint
.IsFloating())
2896 m_action
= actionDragToolbarPane
;
2897 m_action_window
= pane
.window
;
2906 // if a key modifier is pressed while dragging the frame,
2907 // don't dock the window
2908 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2915 DrawHintRect(wnd
, client_pt
, action_offset
);
2918 // this cleans up some screen artifacts that are caused on GTK because
2919 // we aren't getting the exact size of the window (see comment
2929 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
)
2931 // try to find the pane
2932 wxPaneInfo
& pane
= GetPane(wnd
);
2933 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2935 wxPoint pt
= ::wxGetMousePosition();
2936 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2938 // calculate the offset from the upper left-hand corner
2939 // of the frame to the mouse pointer
2940 wxPoint frame_pos
= pane
.frame
->GetPosition();
2941 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2944 // if a key modifier is pressed while dragging the frame,
2945 // don't dock the window
2946 if (!wxGetKeyState(WXK_CONTROL
) && !wxGetKeyState(WXK_ALT
))
2948 // do the drop calculation
2949 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
2952 // if the pane is still floating, update it's floating
2953 // position (that we store)
2954 if (pane
.IsFloating())
2956 pane
.floating_pos
= pane
.frame
->GetPosition();
2958 #if wxCHECK_VERSION(2,7,0)
2959 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2960 pane
.frame
->SetTransparent(255);
2969 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
2971 // try to find the pane
2972 wxPaneInfo
& pane
= GetPane(wnd
);
2973 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2975 pane
.floating_size
= size
;
2979 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
2981 // try to find the pane
2982 wxPaneInfo
& pane
= GetPane(wnd
);
2983 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2986 // fire pane close event
2987 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
2989 e
.SetCanVeto(evt
.CanVeto());
2999 // reparent the pane window back to us and
3000 // prepare the frame window for destruction
3001 if (pane
.window
->IsShown())
3002 pane
.window
->Show(false);
3003 pane
.window
->Reparent(m_frame
);
3011 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3013 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3015 // try to find the pane
3016 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
3018 SetActivePane(m_panes
, wnd
);
3023 // OnRender() draws all of the pane captions, sashes,
3024 // backgrounds, captions, grippers, pane borders and buttons.
3025 // It renders the entire user interface.
3027 void wxFrameManager::OnRender(wxFrameManagerEvent
& evt
)
3029 wxDC
* dc
= evt
.GetDC();
3035 for (i
= 0, part_count
= m_uiparts
.GetCount();
3036 i
< part_count
; ++i
)
3038 wxDockUIPart
& part
= m_uiparts
.Item(i
);
3040 // don't draw hidden pane items
3041 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
3046 case wxDockUIPart::typeDockSizer
:
3047 case wxDockUIPart::typePaneSizer
:
3048 m_art
->DrawSash(*dc
, part
.orientation
, part
.rect
);
3050 case wxDockUIPart::typeBackground
:
3051 m_art
->DrawBackground(*dc
, part
.orientation
, part
.rect
);
3053 case wxDockUIPart::typeCaption
:
3054 m_art
->DrawCaption(*dc
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3056 case wxDockUIPart::typeGripper
:
3057 m_art
->DrawGripper(*dc
, part
.rect
, *part
.pane
);
3059 case wxDockUIPart::typePaneBorder
:
3060 m_art
->DrawBorder(*dc
, part
.rect
, *part
.pane
);
3062 case wxDockUIPart::typePaneButton
:
3063 m_art
->DrawPaneButton(*dc
, part
.button
->button_id
,
3064 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3071 // Render() fire a render event, which is normally handled by
3072 // wxFrameManager::OnRender(). This allows the render function to
3073 // be overridden via the render event. This can be useful for paintin
3074 // custom graphics in the main window. Default behavior can be
3075 // invoked in the overridden function by calling OnRender()
3077 void wxFrameManager::Render(wxDC
* dc
)
3079 wxFrameManagerEvent
e(wxEVT_AUI_RENDER
);
3084 void wxFrameManager::Repaint(wxDC
* dc
)
3089 m_frame
->Refresh() ;
3095 m_frame
->GetClientSize(&w
, &h
);
3097 // figure out which dc to use; if one
3098 // has been specified, use it, otherwise
3100 wxClientDC
* client_dc
= NULL
;
3103 client_dc
= new wxClientDC(m_frame
);
3107 // if the frame has a toolbar, the client area
3108 // origin will not be (0,0).
3109 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3110 if (pt
.x
!= 0 || pt
.y
!= 0)
3111 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3113 // render all the items
3116 // if we created a client_dc, delete it
3121 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3123 wxPaintDC
dc(m_frame
);
3127 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
3136 void wxFrameManager::OnSize(wxSizeEvent
& event
)
3147 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
3150 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3151 wxCursor cursor
= wxNullCursor
;
3155 if (part
->type
== wxDockUIPart::typeDockSizer
||
3156 part
->type
== wxDockUIPart::typePaneSizer
)
3158 // a dock may not be resized if it has a single
3159 // pane which is not resizable
3160 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3161 part
->dock
->panes
.GetCount() == 1 &&
3162 part
->dock
->panes
.Item(0)->IsFixed())
3165 // panes that may not be resized do not get a sizing cursor
3166 if (part
->pane
&& part
->pane
->IsFixed())
3169 if (part
->orientation
== wxVERTICAL
)
3170 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3172 cursor
= wxCursor(wxCURSOR_SIZENS
);
3174 else if (part
->type
== wxDockUIPart::typeGripper
)
3176 cursor
= wxCursor(wxCURSOR_SIZING
);
3180 event
.SetCursor(cursor
);
3185 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
3186 const wxMouseEvent
& event
)
3188 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3190 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3192 if (hit_test
== button_ui_part
)
3194 if (event
.LeftDown())
3195 state
= wxAUI_BUTTON_STATE_PRESSED
;
3197 state
= wxAUI_BUTTON_STATE_HOVER
;
3201 if (event
.LeftDown())
3202 state
= wxAUI_BUTTON_STATE_HOVER
;
3205 // now repaint the button with hover state
3206 wxClientDC
cdc(m_frame
);
3208 // if the frame has a toolbar, the client area
3209 // origin will not be (0,0).
3210 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3211 if (pt
.x
!= 0 || pt
.y
!= 0)
3212 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3214 m_art
->DrawPaneButton(cdc
,
3215 button_ui_part
->button
->button_id
,
3217 button_ui_part
->rect
,
3221 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
3223 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3226 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3229 if (part
->type
== wxDockUIPart::typeDockSizer
||
3230 part
->type
== wxDockUIPart::typePaneSizer
)
3232 // a dock may not be resized if it has a single
3233 // pane which is not resizable
3234 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3235 part
->dock
->panes
.GetCount() == 1 &&
3236 part
->dock
->panes
.Item(0)->IsFixed())
3239 // panes that may not be resized should be ignored here
3240 if (part
->pane
&& part
->pane
->IsFixed())
3243 m_action
= actionResize
;
3244 m_action_part
= part
;
3245 m_action_hintrect
= wxRect();
3246 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3247 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3248 event
.m_y
- part
->rect
.y
);
3249 m_frame
->CaptureMouse();
3251 else if (part
->type
== wxDockUIPart::typePaneButton
)
3253 m_action
= actionClickButton
;
3254 m_action_part
= part
;
3255 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3256 m_frame
->CaptureMouse();
3258 UpdateButtonOnScreen(part
, event
);
3260 else if (part
->type
== wxDockUIPart::typeCaption
||
3261 part
->type
== wxDockUIPart::typeGripper
)
3263 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3265 // set the caption as active
3266 SetActivePane(m_panes
, part
->pane
->window
);
3270 m_action
= actionClickCaption
;
3271 m_action_part
= part
;
3272 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3273 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3274 event
.m_y
- part
->rect
.y
);
3275 m_frame
->CaptureMouse();
3295 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3297 if (m_action
== actionResize
)
3299 m_frame
->ReleaseMouse();
3301 // get rid of the hint rectangle
3303 DrawResizeHint(dc
, m_action_hintrect
);
3305 // resize the dock or the pane
3306 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3308 wxRect
& rect
= m_action_part
->dock
->rect
;
3310 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3311 event
.m_y
- m_action_offset
.y
);
3313 switch (m_action_part
->dock
->dock_direction
)
3315 case wxAUI_DOCK_LEFT
:
3316 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3318 case wxAUI_DOCK_TOP
:
3319 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3321 case wxAUI_DOCK_RIGHT
:
3322 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3323 new_pos
.x
- m_action_part
->rect
.GetWidth();
3325 case wxAUI_DOCK_BOTTOM
:
3326 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3327 new_pos
.y
- m_action_part
->rect
.GetHeight();
3334 else if (m_action_part
&&
3335 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3337 wxDockInfo
& dock
= *m_action_part
->dock
;
3338 wxPaneInfo
& pane
= *m_action_part
->pane
;
3340 int total_proportion
= 0;
3341 int dock_pixels
= 0;
3342 int new_pixsize
= 0;
3344 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3345 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3346 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3348 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3349 event
.m_y
- m_action_offset
.y
);
3351 // determine the pane rectangle by getting the pane part
3352 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3353 wxASSERT_MSG(pane_part
,
3354 wxT("Pane border part not found -- shouldn't happen"));
3356 // determine the new pixel size that the user wants;
3357 // this will help us recalculate the pane's proportion
3358 if (dock
.IsHorizontal())
3359 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3361 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3363 // determine the size of the dock, based on orientation
3364 if (dock
.IsHorizontal())
3365 dock_pixels
= dock
.rect
.GetWidth();
3367 dock_pixels
= dock
.rect
.GetHeight();
3369 // determine the total proportion of all resizable panes,
3370 // and the total size of the dock minus the size of all
3372 int i
, dock_pane_count
= dock
.panes
.GetCount();
3373 int pane_position
= -1;
3374 for (i
= 0; i
< dock_pane_count
; ++i
)
3376 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3377 if (p
.window
== pane
.window
)
3380 // while we're at it, subtract the pane sash
3381 // width from the dock width, because this would
3382 // skew our proportion calculations
3384 dock_pixels
-= sash_size
;
3386 // also, the whole size (including decorations) of
3387 // all fixed panes must also be subtracted, because they
3388 // are not part of the proportion calculation
3391 if (dock
.IsHorizontal())
3392 dock_pixels
-= p
.best_size
.x
;
3394 dock_pixels
-= p
.best_size
.y
;
3398 total_proportion
+= p
.dock_proportion
;
3402 // find a pane in our dock to 'steal' space from or to 'give'
3403 // space to -- this is essentially what is done when a pane is
3404 // resized; the pane should usually be the first non-fixed pane
3405 // to the right of the action pane
3406 int borrow_pane
= -1;
3407 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3409 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3418 // demand that the pane being resized is found in this dock
3419 // (this assert really never should be raised)
3420 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3422 // prevent division by zero
3423 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3425 m_action
= actionNone
;
3429 // calculate the new proportion of the pane
3430 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3432 // default minimum size
3435 // check against the pane's minimum size, if specified. please note
3436 // that this is not enough to ensure that the minimum size will
3437 // not be violated, because the whole frame might later be shrunk,
3438 // causing the size of the pane to violate it's minimum size
3439 if (pane
.min_size
.IsFullySpecified())
3443 if (pane
.HasBorder())
3444 min_size
+= (pane_border_size
*2);
3446 // calculate minimum size with decorations (border,caption)
3447 if (pane_part
->orientation
== wxVERTICAL
)
3449 min_size
+= pane
.min_size
.y
;
3450 if (pane
.HasCaption())
3451 min_size
+= caption_size
;
3455 min_size
+= pane
.min_size
.x
;
3460 // for some reason, an arithmatic error somewhere is causing
3461 // the proportion calculations to always be off by 1 pixel;
3462 // for now we will add the 1 pixel on, but we really should
3463 // determine what's causing this.
3466 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3468 if (new_proportion
< min_proportion
)
3469 new_proportion
= min_proportion
;
3473 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3475 // borrow the space from our neighbor pane to the
3476 // right or bottom (depending on orientation)
3477 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3478 pane
.dock_proportion
= new_proportion
;
3485 else if (m_action
== actionClickButton
)
3487 m_hover_button
= NULL
;
3488 m_frame
->ReleaseMouse();
3489 UpdateButtonOnScreen(m_action_part
, event
);
3491 // make sure we're still over the item that was originally clicked
3492 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3494 // fire button-click event
3495 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3496 e
.SetPane(m_action_part
->pane
);
3497 e
.SetButton(m_action_part
->button
->button_id
);
3501 else if (m_action
== actionClickCaption
)
3503 m_frame
->ReleaseMouse();
3505 else if (m_action
== actionDragFloatingPane
)
3507 m_frame
->ReleaseMouse();
3509 else if (m_action
== actionDragToolbarPane
)
3511 m_frame
->ReleaseMouse();
3513 wxPaneInfo
& pane
= GetPane(m_action_window
);
3514 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3516 // save the new positions
3517 wxDockInfoPtrArray docks
;
3518 FindDocks(m_docks
, pane
.dock_direction
,
3519 pane
.dock_layer
, pane
.dock_row
, docks
);
3520 if (docks
.GetCount() == 1)
3522 wxDockInfo
& dock
= *docks
.Item(0);
3524 wxArrayInt pane_positions
, pane_sizes
;
3525 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3527 int i
, dock_pane_count
= dock
.panes
.GetCount();
3528 for (i
= 0; i
< dock_pane_count
; ++i
)
3529 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3532 pane
.state
&= ~wxPaneInfo::actionPane
;
3540 m_action
= actionNone
;
3541 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3545 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3547 // sometimes when Update() is called from inside this method,
3548 // a spurious mouse move event is generated; this check will make
3549 // sure that only real mouse moves will get anywhere in this method;
3550 // this appears to be a bug somewhere, and I don't know where the
3551 // mouse move event is being generated. only verified on MSW
3553 wxPoint mouse_pos
= event
.GetPosition();
3554 if (m_last_mouse_move
== mouse_pos
)
3556 m_last_mouse_move
= mouse_pos
;
3559 if (m_action
== actionResize
)
3561 wxPoint pos
= m_action_part
->rect
.GetPosition();
3562 if (m_action_part
->orientation
== wxHORIZONTAL
)
3563 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3565 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3567 wxRect
rect(m_frame
->ClientToScreen(pos
),
3568 m_action_part
->rect
.GetSize());
3571 if (!m_action_hintrect
.IsEmpty())
3572 DrawResizeHint(dc
, m_action_hintrect
);
3573 DrawResizeHint(dc
, rect
);
3574 m_action_hintrect
= rect
;
3576 else if (m_action
== actionClickCaption
)
3578 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3579 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3581 // caption has been clicked. we need to check if the mouse
3582 // is now being dragged. if it is, we need to change the
3583 // mouse action to 'drag'
3584 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3585 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3587 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3589 if (!pane_info
->IsToolbar())
3591 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3592 pane_info
->IsFloatable())
3594 m_action
= actionDragFloatingPane
;
3596 // set initial float position
3597 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3598 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3599 pt
.y
- m_action_offset
.y
);
3604 m_action_window
= pane_info
->frame
;
3606 // action offset is used here to make it feel "natural" to the user
3607 // to drag a docked pane and suddenly have it become a floating frame.
3608 // Sometimes, however, the offset where the user clicked on the docked
3609 // caption is bigger than the width of the floating frame itself, so
3610 // in that case we need to set the action offset to a sensible value
3611 wxSize frame_size
= m_action_window
->GetSize();
3612 if (frame_size
.x
<= m_action_offset
.x
)
3613 m_action_offset
.x
= 30;
3618 m_action
= actionDragToolbarPane
;
3619 m_action_window
= pane_info
->window
;
3623 else if (m_action
== actionDragFloatingPane
)
3625 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3626 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3627 pt
.y
- m_action_offset
.y
);
3629 else if (m_action
== actionDragToolbarPane
)
3631 wxPaneInfo
& pane
= GetPane(m_action_window
);
3632 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3634 pane
.state
|= wxPaneInfo::actionPane
;
3636 wxPoint pt
= event
.GetPosition();
3637 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3639 // if DoDrop() decided to float the pane, set up
3640 // the floating pane's initial position
3641 if (pane
.IsFloating())
3643 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3644 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3645 pt
.y
- m_action_offset
.y
);
3648 // this will do the actiual move operation;
3649 // in the case that the pane has been floated,
3650 // this call will create the floating pane
3651 // and do the reparenting
3654 // if the pane has been floated, change the mouse
3655 // action actionDragFloatingPane so that subsequent
3656 // EVT_MOTION() events will move the floating pane
3657 if (pane
.IsFloating())
3659 pane
.state
&= ~wxPaneInfo::actionPane
;
3660 m_action
= actionDragFloatingPane
;
3661 m_action_window
= pane
.frame
;
3666 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3667 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3669 if (part
!= m_hover_button
)
3671 // make the old button normal
3673 UpdateButtonOnScreen(m_hover_button
, event
);
3675 // mouse is over a button, so repaint the
3676 // button in hover mode
3677 UpdateButtonOnScreen(part
, event
);
3678 m_hover_button
= part
;
3685 m_hover_button
= NULL
;
3696 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3700 m_hover_button
= NULL
;
3705 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3707 // when a child pane has it's focus set, we should change the
3708 // pane's active state to reflect this. (this is only true if
3709 // active panes are allowed by the owner)
3710 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3712 if (GetPane(event
.GetWindow()).IsOk())
3714 SetActivePane(m_panes
, event
.GetWindow());
3723 // OnPaneButton() is an event handler that is called
3724 // when a pane button has been pressed.
3725 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& evt
)
3727 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3729 wxPaneInfo
& pane
= *(evt
.pane
);
3731 if (evt
.button
== wxPaneInfo::buttonClose
)
3733 // fire pane close event
3734 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3735 e
.SetPane(evt
.pane
);
3744 else if (evt
.button
== wxPaneInfo::buttonPin
)
3746 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&