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
);
86 m_CanSetShape
= false; // have to wait for window create event on GTK
90 m_Region
= wxRegion(0, 0, 0, 0);
94 virtual bool SetTransparent(wxByte alpha
)
98 int w
=100; // some defaults
100 GetClientSize(&w
, &h
);
106 // m_Region.Union(0, 0, 1, m_MaxWidth);
109 for (int y
=0; y
<m_MaxHeight
; y
++)
111 // Reverse the order of the bottom 4 bits
112 int j
=((y
&8)?1:0)|((y
&4)?2:0)|((y
&2)?4:0)|((y
&1)?8:0);
113 if ((j
*16+8)<m_Amount
)
114 m_Region
.Union(0, y
, m_MaxWidth
, 1);
123 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
127 if (m_Region
.IsEmpty())
131 dc
.SetBrush(wxColour(128, 192, 255));
133 dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
135 dc
.SetPen(*wxTRANSPARENT_PEN
);
137 wxRegionIterator
upd(GetUpdateRegion()); // get the update rect list
141 wxRect
rect(upd
.GetRect());
142 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
149 void OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
)) {m_CanSetShape
=true; SetTransparent(0);}
152 void OnSize(wxSizeEvent
& event
)
154 // We sometimes get surplus size events
155 if ((event
.GetSize().GetWidth() == m_lastWidth
) &&
156 (event
.GetSize().GetHeight() == m_lastHeight
))
161 m_lastWidth
= event
.GetSize().GetWidth();
162 m_lastHeight
= event
.GetSize().GetHeight();
164 SetTransparent(m_Amount
);
165 m_Region
.Intersect(0, 0, event
.GetSize().GetWidth(),
166 event
.GetSize().GetHeight());
177 int m_lastWidth
,m_lastHeight
;
181 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
182 DECLARE_EVENT_TABLE()
186 IMPLEMENT_DYNAMIC_CLASS( wxPseudoTransparentFrame
, wxFrame
)
188 BEGIN_EVENT_TABLE(wxPseudoTransparentFrame
, wxFrame
)
189 EVT_PAINT(wxPseudoTransparentFrame::OnPaint
)
190 EVT_SIZE(wxPseudoTransparentFrame::OnSize
)
192 EVT_WINDOW_CREATE(wxPseudoTransparentFrame::OnWindowCreate
)
197 // -- static utility functions --
199 static wxBitmap
wxPaneCreateStippleBitmap()
201 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
202 wxImage
img(2,2,data
,true);
203 return wxBitmap(img
);
206 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
208 wxBitmap stipple
= wxPaneCreateStippleBitmap();
209 wxBrush
brush(stipple
);
211 dc
.SetPen(*wxTRANSPARENT_PEN
);
213 dc
.SetLogicalFunction(wxXOR
);
214 dc
.DrawRectangle(rect
);
219 // CopyDocksAndPanes() - this utility function creates copies of
220 // the dock and pane info. wxDockInfo's usually contain pointers
221 // to wxPaneInfo classes, thus this function is necessary to reliably
222 // reconstruct that relationship in the new dock info and pane info arrays
224 static void CopyDocksAndPanes(wxDockInfoArray
& dest_docks
,
225 wxPaneInfoArray
& dest_panes
,
226 const wxDockInfoArray
& src_docks
,
227 const wxPaneInfoArray
& src_panes
)
229 dest_docks
= src_docks
;
230 dest_panes
= src_panes
;
231 int i
, j
, k
, dock_count
, pc1
, pc2
;
232 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
234 wxDockInfo
& dock
= dest_docks
.Item(i
);
235 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
236 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
237 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
238 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
242 // GetMaxLayer() is an internal function which returns
243 // the highest layer inside the specified dock
244 static int GetMaxLayer(const wxDockInfoArray
& docks
, int dock_direction
)
246 int i
, dock_count
, max_layer
= 0;
247 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
249 wxDockInfo
& dock
= docks
.Item(i
);
250 if (dock
.dock_direction
== dock_direction
&&
251 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
252 max_layer
= dock
.dock_layer
;
258 // GetMaxRow() is an internal function which returns
259 // the highest layer inside the specified dock
260 static int GetMaxRow(const wxPaneInfoArray
& panes
, int direction
, int layer
)
262 int i
, pane_count
, max_row
= 0;
263 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
265 wxPaneInfo
& pane
= panes
.Item(i
);
266 if (pane
.dock_direction
== direction
&&
267 pane
.dock_layer
== layer
&&
268 pane
.dock_row
> max_row
)
269 max_row
= pane
.dock_row
;
276 // DoInsertDockLayer() is an internal function that inserts a new dock
277 // layer by incrementing all existing dock layer values by one
278 static void DoInsertDockLayer(wxPaneInfoArray
& panes
,
283 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
285 wxPaneInfo
& pane
= panes
.Item(i
);
286 if (!pane
.IsFloating() &&
287 pane
.dock_direction
== dock_direction
&&
288 pane
.dock_layer
>= dock_layer
)
293 // DoInsertDockLayer() is an internal function that inserts a new dock
294 // row by incrementing all existing dock row values by one
295 static void DoInsertDockRow(wxPaneInfoArray
& panes
,
301 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
303 wxPaneInfo
& pane
= panes
.Item(i
);
304 if (!pane
.IsFloating() &&
305 pane
.dock_direction
== dock_direction
&&
306 pane
.dock_layer
== dock_layer
&&
307 pane
.dock_row
>= dock_row
)
312 // DoInsertDockLayer() is an internal function that inserts a space for
313 // another dock pane by incrementing all existing dock row values by one
314 static void DoInsertPane(wxPaneInfoArray
& panes
,
321 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
323 wxPaneInfo
& pane
= panes
.Item(i
);
324 if (!pane
.IsFloating() &&
325 pane
.dock_direction
== dock_direction
&&
326 pane
.dock_layer
== dock_layer
&&
327 pane
.dock_row
== dock_row
&&
328 pane
.dock_pos
>= dock_pos
)
333 // FindDocks() is an internal function that returns a list of docks which meet
334 // the specified conditions in the parameters and returns a sorted array
335 // (sorted by layer and then row)
336 static void FindDocks(wxDockInfoArray
& docks
,
340 wxDockInfoPtrArray
& arr
)
342 int begin_layer
= dock_layer
;
343 int end_layer
= dock_layer
;
344 int begin_row
= dock_row
;
345 int end_row
= dock_row
;
346 int dock_count
= docks
.GetCount();
347 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
349 // discover the maximum dock layer and the max row
350 for (i
= 0; i
< dock_count
; ++i
)
352 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
353 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
356 // if no dock layer was specified, search all dock layers
357 if (dock_layer
== -1)
360 end_layer
= max_layer
;
363 // if no dock row was specified, search all dock row
372 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
373 for (row
= begin_row
; row
<= end_row
; ++row
)
374 for (i
= 0; i
< dock_count
; ++i
)
376 wxDockInfo
& d
= docks
.Item(i
);
377 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
379 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
385 // FindPaneInDock() looks up a specified window pointer inside a dock.
386 // If found, the corresponding wxPaneInfo pointer is returned, otherwise NULL.
387 static wxPaneInfo
* FindPaneInDock(const wxDockInfo
& dock
, wxWindow
* window
)
389 int i
, count
= dock
.panes
.GetCount();
390 for (i
= 0; i
< count
; ++i
)
392 wxPaneInfo
* p
= dock
.panes
.Item(i
);
393 if (p
->window
== window
)
399 // RemovePaneFromDocks() removes a pane window from all docks
400 // with a possible exception specified by parameter "ex_cept"
401 static void RemovePaneFromDocks(wxDockInfoArray
& docks
,
403 wxDockInfo
* ex_cept
= NULL
)
406 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
408 wxDockInfo
& d
= docks
.Item(i
);
411 wxPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
417 // RenumberDockRows() takes a dock and assigns sequential numbers
418 // to existing rows. Basically it takes out the gaps; so if a
419 // dock has rows with numbers 0,2,5, they will become 0,1,2
420 static void RenumberDockRows(wxDockInfoPtrArray
& docks
)
422 int i
, dock_count
, j
, pane_count
;
423 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
425 wxDockInfo
& dock
= *docks
.Item(i
);
427 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
428 dock
.panes
.Item(j
)->dock_row
= i
;
433 // SetActivePane() sets the active pane, as well as cycles through
434 // every other pane and makes sure that all others' active flags
436 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
439 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
441 wxPaneInfo
& pane
= panes
.Item(i
);
442 pane
.state
&= ~wxPaneInfo::optionActive
;
443 if (pane
.window
== active_pane
)
444 pane
.state
|= wxPaneInfo::optionActive
;
449 // this function is used to sort panes by dock position
450 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
452 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
456 // -- wxFrameManager class implementation --
459 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
460 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
461 EVT_AUI_RENDER(wxFrameManager::OnRender
)
462 EVT_PAINT(wxFrameManager::OnPaint
)
463 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
464 EVT_SIZE(wxFrameManager::OnSize
)
465 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
466 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
467 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
468 EVT_MOTION(wxFrameManager::OnMotion
)
469 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
470 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
471 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
475 wxFrameManager::wxFrameManager(wxWindow
* managed_wnd
, unsigned int flags
)
477 m_action
= actionNone
;
478 m_last_mouse_move
= wxPoint();
479 m_hover_button
= NULL
;
480 m_art
= new wxDefaultDockArt
;
487 SetManagedWindow(managed_wnd
);
491 wxFrameManager::~wxFrameManager()
496 // GetPane() looks up a wxPaneInfo structure based
497 // on the supplied window pointer. Upon failure, GetPane()
498 // returns an empty wxPaneInfo, a condition which can be checked
499 // by calling wxPaneInfo::IsOk().
501 // The pane info's structure may then be modified. Once a pane's
502 // info is modified, wxFrameManager::Update() must be called to
503 // realize the changes in the UI.
505 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
508 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
510 wxPaneInfo
& p
= m_panes
.Item(i
);
511 if (p
.window
== window
)
514 return wxNullPaneInfo
;
517 // this version of GetPane() looks up a pane based on a
518 // 'pane name', see above comment for more info
519 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
522 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
524 wxPaneInfo
& p
= m_panes
.Item(i
);
528 return wxNullPaneInfo
;
531 // GetAllPanes() returns a reference to all the pane info structures
532 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
537 // HitTest() is an internal function which determines
538 // which UI item the specified coordinates are over
539 // (x,y) specify a position in client coordinates
540 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
542 wxDockUIPart
* result
= NULL
;
545 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
547 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
549 // we are not interested in typeDock, because this space
550 // isn't used to draw anything, just for measurements;
551 // besides, the entire dock area is covered with other
552 // rectangles, which we are interested in.
553 if (item
->type
== wxDockUIPart::typeDock
)
556 // if we already have a hit on a more specific item, we are not
557 // interested in a pane hit. If, however, we don't already have
558 // a hit, returning a pane hit is necessary for some operations
559 if ((item
->type
== wxDockUIPart::typePane
||
560 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
563 // if the point is inside the rectangle, we have a hit
564 if (item
->rect
.Inside(x
,y
))
572 // SetFlags() and GetFlags() allow the owner to set various
573 // options which are global to wxFrameManager
574 void wxFrameManager::SetFlags(unsigned int flags
)
579 unsigned int wxFrameManager::GetFlags() const
585 // don't use these anymore as they are deprecated
586 // use Set/GetManagedFrame() instead
587 void wxFrameManager::SetFrame(wxFrame
* frame
)
589 SetManagedWindow((wxWindow
*)frame
);
592 wxFrame
* wxFrameManager::GetFrame() const
594 return (wxFrame
*)m_frame
;
600 // SetManagedWindow() is usually called once when the frame
601 // manager class is being initialized. "frame" specifies
602 // the frame which should be managed by the frame mananger
603 void wxFrameManager::SetManagedWindow(wxWindow
* frame
)
605 wxASSERT_MSG(frame
, wxT("specified frame must be non-NULL"));
608 m_frame
->PushEventHandler(this);
611 // if the owner is going to manage an MDI parent frame,
612 // we need to add the MDI client window as the default
615 if (frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
617 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)frame
;
618 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
620 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
622 AddPane(client_window
,
623 wxPaneInfo().Name(wxT("mdiclient")).
624 CenterPane().PaneBorder(false));
628 // Make a window to use for a transparent hint
629 #if defined(__WXMSW__) || defined(__WXGTK__)
630 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
631 wxFRAME_TOOL_WINDOW
|
632 wxFRAME_FLOAT_ON_PARENT
|
636 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
638 #elif defined(__WXMAC__)
639 // Using a miniframe with float and tool styles keeps the parent
640 // frame activated and highlighted as such...
641 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
642 wxFRAME_FLOAT_ON_PARENT
643 | wxFRAME_TOOL_WINDOW
);
645 // Can't set the bg colour of a Frame in wxMac
646 wxPanel
* p
= new wxPanel(m_hint_wnd
);
648 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
649 // color that is really hard to see, especially transparent.
650 // Until a better system color is decided upon we'll just use
652 p
->SetBackgroundColour(*wxBLUE
);
658 // CanSetTransparent is only present in the 2.7.0 ABI. To allow this file to be easily used
659 // in a backported environment, conditionally compile this in.
660 #if wxCHECK_VERSION(2,7,0)
661 && !m_hint_wnd
->CanSetTransparent()
667 m_hint_wnd
->Destroy();
670 // If we can convert it to a PseudoTransparent window, do so
671 m_hint_wnd
= new wxPseudoTransparentFrame (m_frame
, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxSize(1,1),
672 wxFRAME_TOOL_WINDOW
|
673 wxFRAME_FLOAT_ON_PARENT
|
677 m_hint_fademax
= 128;
682 // UnInit() must be called, usually in the destructor
683 // of the frame class. If it is not called, usually this
684 // will result in a crash upon program exit
685 void wxFrameManager::UnInit()
687 m_frame
->RemoveEventHandler(this);
690 // GetManagedWindow() returns the window pointer being managed
691 wxWindow
* wxFrameManager::GetManagedWindow() const
696 wxDockArt
* wxFrameManager::GetArtProvider() const
701 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
703 // first, give the owner frame a chance to override
706 if (m_frame
->ProcessEvent(event
))
713 // SetArtProvider() instructs wxFrameManager to use the
714 // specified art provider for all drawing calls. This allows
715 // plugable look-and-feel features. The pointer that is
716 // passed to this method subsequently belongs to wxFrameManager,
717 // and is deleted in the frame manager destructor
718 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
720 // delete the last art provider, if any
723 // assign the new art provider
724 m_art
= art_provider
;
728 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
730 // check if the pane has a valid window
734 // check if the pane already exists
735 if (GetPane(pane_info
.window
).IsOk())
738 m_panes
.Add(pane_info
);
740 wxPaneInfo
& pinfo
= m_panes
.Last();
742 // set the pane window
743 pinfo
.window
= window
;
745 // if the pane's name identifier is blank, create a random string
746 if (pinfo
.name
.empty())
748 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
749 ((unsigned long)pinfo
.window
) & 0xffffffff,
750 (unsigned int)time(NULL
),
752 (unsigned int)GetTickCount(),
754 (unsigned int)clock(),
756 (unsigned long)m_panes
.GetCount());
759 // set initial proportion (if not already set)
760 if (pinfo
.dock_proportion
== 0)
761 pinfo
.dock_proportion
= 100000;
763 if (pinfo
.HasCloseButton() &&
764 pinfo
.buttons
.size() == 0)
767 button
.button_id
= wxPaneInfo::buttonClose
;
768 pinfo
.buttons
.Add(button
);
771 if (pinfo
.best_size
== wxDefaultSize
&&
774 pinfo
.best_size
= pinfo
.window
->GetClientSize();
776 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
778 // GetClientSize() doesn't get the best size for
779 // a toolbar under some newer versions of wxWidgets,
780 // so use GetBestSize()
781 pinfo
.best_size
= pinfo
.window
->GetBestSize();
783 // for some reason, wxToolBar::GetBestSize() is returning
784 // a size that is a pixel shy of the correct amount.
785 // I believe this to be the correct action, until
786 // wxToolBar::GetBestSize() is fixed. Is this assumption
791 if (pinfo
.min_size
!= wxDefaultSize
)
793 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
794 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
795 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
796 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
803 bool wxFrameManager::AddPane(wxWindow
* window
,
805 const wxString
& caption
)
808 pinfo
.Caption(caption
);
811 case wxTOP
: pinfo
.Top(); break;
812 case wxBOTTOM
: pinfo
.Bottom(); break;
813 case wxLEFT
: pinfo
.Left(); break;
814 case wxRIGHT
: pinfo
.Right(); break;
815 case wxCENTER
: pinfo
.CenterPane(); break;
817 return AddPane(window
, pinfo
);
820 bool wxFrameManager::AddPane(wxWindow
* window
,
821 const wxPaneInfo
& pane_info
,
822 const wxPoint
& drop_pos
)
824 if (!AddPane(window
, pane_info
))
827 wxPaneInfo
& pane
= GetPane(window
);
829 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
834 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
837 // shift the panes around, depending on the insert level
838 switch (insert_level
)
840 case wxAUI_INSERT_PANE
:
841 DoInsertPane(m_panes
,
842 pane_info
.dock_direction
,
843 pane_info
.dock_layer
,
847 case wxAUI_INSERT_ROW
:
848 DoInsertDockRow(m_panes
,
849 pane_info
.dock_direction
,
850 pane_info
.dock_layer
,
853 case wxAUI_INSERT_DOCK
:
854 DoInsertDockLayer(m_panes
,
855 pane_info
.dock_direction
,
856 pane_info
.dock_layer
);
860 // if the window already exists, we are basically just moving/inserting the
861 // existing window. If it doesn't exist, we need to add it and insert it
862 wxPaneInfo
& existing_pane
= GetPane(window
);
863 if (!existing_pane
.IsOk())
865 return AddPane(window
, pane_info
);
869 if (pane_info
.IsFloating())
871 existing_pane
.Float();
872 if (pane_info
.floating_pos
!= wxDefaultPosition
)
873 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
874 if (pane_info
.floating_size
!= wxDefaultSize
)
875 existing_pane
.FloatingSize(pane_info
.floating_size
);
879 existing_pane
.Direction(pane_info
.dock_direction
);
880 existing_pane
.Layer(pane_info
.dock_layer
);
881 existing_pane
.Row(pane_info
.dock_row
);
882 existing_pane
.Position(pane_info
.dock_pos
);
890 // DetachPane() removes a pane from the frame manager. This
891 // method will not destroy the window that is removed.
892 bool wxFrameManager::DetachPane(wxWindow
* window
)
895 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
897 wxPaneInfo
& p
= m_panes
.Item(i
);
898 if (p
.window
== window
)
902 // we have a floating frame which is being detached. We need to
903 // reparent it to m_frame and destroy the floating frame
906 p
.window
->SetSize(1,1);
908 if (p
.frame
->IsShown())
909 p
.frame
->Show(false);
911 // reparent to m_frame and destroy the pane
912 p
.window
->Reparent(m_frame
);
913 p
.frame
->SetSizer(NULL
);
918 // make sure there are no references to this pane in our uiparts,
919 // just in case the caller doesn't call Update() immediately after
920 // the DetachPane() call. This prevets obscure crashes which would
921 // happen at window repaint if the caller forgets to call Update()
923 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
925 wxDockUIPart
& part
= m_uiparts
.Item(pi
);
928 m_uiparts
.RemoveAt(pi
);
943 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
944 // in the input string. This is an internal functions which is
945 // used for saving perspectives
946 static wxString
EscapeDelimiters(const wxString
& s
)
949 result
.Alloc(s
.length());
950 const wxChar
* ch
= s
.c_str();
953 if (*ch
== wxT(';') || *ch
== wxT('|'))
961 wxString
wxFrameManager::SavePaneInfo(wxPaneInfo
& pane
)
963 wxString result
= wxT("name=");
964 result
+= EscapeDelimiters(pane
.name
);
967 result
+= wxT("caption=");
968 result
+= EscapeDelimiters(pane
.caption
);
971 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
972 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
973 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
974 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
975 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
976 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
977 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
978 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
979 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
980 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
981 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
982 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
983 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
984 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
985 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
986 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
991 // Load a "pane" with the pane infor settings in pane_part
992 void wxFrameManager::LoadPaneInfo(wxString pane_part
, wxPaneInfo
&pane
)
994 // replace escaped characters so we can
995 // split up the string easily
996 pane_part
.Replace(wxT("\\|"), wxT("\a"));
997 pane_part
.Replace(wxT("\\;"), wxT("\b"));
1001 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
1002 pane_part
= pane_part
.AfterFirst(wxT(';'));
1003 wxString val_name
= val_part
.BeforeFirst(wxT('='));
1004 wxString value
= val_part
.AfterFirst(wxT('='));
1005 val_name
.MakeLower();
1006 val_name
.Trim(true);
1007 val_name
.Trim(false);
1011 if (val_name
.empty())
1014 if (val_name
== wxT("name"))
1016 else if (val_name
== wxT("caption"))
1017 pane
.caption
= value
;
1018 else if (val_name
== wxT("state"))
1019 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1020 else if (val_name
== wxT("dir"))
1021 pane
.dock_direction
= wxAtoi(value
.c_str());
1022 else if (val_name
== wxT("layer"))
1023 pane
.dock_layer
= wxAtoi(value
.c_str());
1024 else if (val_name
== wxT("row"))
1025 pane
.dock_row
= wxAtoi(value
.c_str());
1026 else if (val_name
== wxT("pos"))
1027 pane
.dock_pos
= wxAtoi(value
.c_str());
1028 else if (val_name
== wxT("prop"))
1029 pane
.dock_proportion
= wxAtoi(value
.c_str());
1030 else if (val_name
== wxT("bestw"))
1031 pane
.best_size
.x
= wxAtoi(value
.c_str());
1032 else if (val_name
== wxT("besth"))
1033 pane
.best_size
.y
= wxAtoi(value
.c_str());
1034 else if (val_name
== wxT("minw"))
1035 pane
.min_size
.x
= wxAtoi(value
.c_str());
1036 else if (val_name
== wxT("minh"))
1037 pane
.min_size
.y
= wxAtoi(value
.c_str());
1038 else if (val_name
== wxT("maxw"))
1039 pane
.max_size
.x
= wxAtoi(value
.c_str());
1040 else if (val_name
== wxT("maxh"))
1041 pane
.max_size
.y
= wxAtoi(value
.c_str());
1042 else if (val_name
== wxT("floatx"))
1043 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1044 else if (val_name
== wxT("floaty"))
1045 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1046 else if (val_name
== wxT("floatw"))
1047 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1048 else if (val_name
== wxT("floath"))
1049 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1051 wxFAIL_MSG(wxT("Bad Perspective String"));
1055 // replace escaped characters so we can
1056 // split up the string easily
1057 pane
.name
.Replace(wxT("\a"), wxT("|"));
1058 pane
.name
.Replace(wxT("\b"), wxT(";"));
1059 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1060 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1061 pane_part
.Replace(wxT("\a"), wxT("|"));
1062 pane_part
.Replace(wxT("\b"), wxT(";"));
1068 // SavePerspective() saves all pane information as a single string.
1069 // This string may later be fed into LoadPerspective() to restore
1070 // all pane settings. This save and load mechanism allows an
1071 // exact pane configuration to be saved and restored at a later time
1073 wxString
wxFrameManager::SavePerspective()
1077 result
= wxT("layout1|");
1079 int pane_i
, pane_count
= m_panes
.GetCount();
1080 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1082 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
1083 result
+= SavePaneInfo(pane
)+wxT("|");
1086 int dock_i
, dock_count
= m_docks
.GetCount();
1087 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1089 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
1091 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1092 dock
.dock_direction
, dock
.dock_layer
,
1093 dock
.dock_row
, dock
.size
);
1099 // LoadPerspective() loads a layout which was saved with SavePerspective()
1100 // If the "update" flag parameter is true, the GUI will immediately be updated
1102 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
1104 wxString input
= layout
;
1107 // check layout string version
1108 part
= input
.BeforeFirst(wxT('|'));
1109 input
= input
.AfterFirst(wxT('|'));
1112 if (part
!= wxT("layout1"))
1115 // mark all panes currently managed as docked and hidden
1116 int pane_i
, pane_count
= m_panes
.GetCount();
1117 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1118 m_panes
.Item(pane_i
).Dock().Hide();
1120 // clear out the dock array; this will be reconstructed
1123 // replace escaped characters so we can
1124 // split up the string easily
1125 input
.Replace(wxT("\\|"), wxT("\a"));
1126 input
.Replace(wxT("\\;"), wxT("\b"));
1132 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1133 input
= input
.AfterFirst(wxT('|'));
1134 pane_part
.Trim(true);
1136 // if the string is empty, we're done parsing
1137 if (pane_part
.empty())
1140 if (pane_part
.Left(9) == wxT("dock_size"))
1142 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1143 wxString value
= pane_part
.AfterFirst(wxT('='));
1145 long dir
, layer
, row
, size
;
1146 wxString piece
= val_name
.AfterFirst(wxT('('));
1147 piece
= piece
.BeforeLast(wxT(')'));
1148 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1149 piece
= piece
.AfterFirst(wxT(','));
1150 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1151 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1152 value
.ToLong(&size
);
1155 dock
.dock_direction
= dir
;
1156 dock
.dock_layer
= layer
;
1157 dock
.dock_row
= row
;
1163 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1164 // name so it can be called by external callers
1165 pane_part
.Replace(wxT("\a"), wxT("|"));
1166 pane_part
.Replace(wxT("\b"), wxT(";"));
1168 LoadPaneInfo(pane_part
, pane
);
1170 wxPaneInfo
& p
= GetPane(pane
.name
);
1173 // the pane window couldn't be found
1174 // in the existing layout
1188 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
1189 wxArrayInt
& positions
,
1192 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1193 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1194 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1199 int offset
, action_pane
= -1;
1200 int pane_i
, pane_count
= dock
.panes
.GetCount();
1202 // find the pane marked as our action pane
1203 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1205 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1207 if (pane
.state
& wxPaneInfo::actionPane
)
1209 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1210 action_pane
= pane_i
;
1214 // set up each panes default position, and
1215 // determine the size (width or height, depending
1216 // on the dock's orientation) of each pane
1217 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1219 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1220 positions
.Add(pane
.dock_pos
);
1223 if (pane
.HasBorder())
1224 size
+= (pane_border_size
*2);
1226 if (dock
.IsHorizontal())
1228 if (pane
.HasGripper() && !pane
.HasGripperTop())
1229 size
+= gripper_size
;
1230 size
+= pane
.best_size
.x
;
1234 if (pane
.HasGripper() && pane
.HasGripperTop())
1235 size
+= gripper_size
;
1237 if (pane
.HasCaption())
1238 size
+= caption_size
;
1239 size
+= pane
.best_size
.y
;
1245 // if there is no action pane, just return the default
1246 // positions (as specified in pane.pane_pos)
1247 if (action_pane
== -1)
1251 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1253 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1258 positions
[pane_i
] -= -amount
;
1260 offset
+= sizes
[pane_i
];
1263 // if the dock mode is fixed, make sure none of the panes
1264 // overlap; we will bump panes that overlap
1266 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1268 int amount
= positions
[pane_i
] - offset
;
1272 positions
[pane_i
] += -amount
;
1274 offset
+= sizes
[pane_i
];
1279 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1282 wxDockUIPartArray
& uiparts
,
1286 wxSizerItem
* sizer_item
;
1288 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1289 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1290 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1291 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1293 // find out the orientation of the item (orientation for panes
1294 // is the same as the dock's orientation)
1296 if (dock
.IsHorizontal())
1297 orientation
= wxHORIZONTAL
;
1299 orientation
= wxVERTICAL
;
1301 // this variable will store the proportion
1302 // value that the pane will receive
1303 int pane_proportion
= pane
.dock_proportion
;
1305 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1306 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1308 if (pane
.HasGripper())
1310 if (pane
.HasGripperTop())
1311 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1313 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1315 part
.type
= wxDockUIPart::typeGripper
;
1319 part
.orientation
= orientation
;
1320 part
.cont_sizer
= horz_pane_sizer
;
1321 part
.sizer_item
= sizer_item
;
1325 if (pane
.HasCaption())
1327 // create the caption sizer
1328 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1330 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1332 part
.type
= wxDockUIPart::typeCaption
;
1336 part
.orientation
= orientation
;
1337 part
.cont_sizer
= vert_pane_sizer
;
1338 part
.sizer_item
= sizer_item
;
1339 int caption_part_idx
= uiparts
.GetCount();
1342 // add pane buttons to the caption
1343 int i
, button_count
;
1344 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1345 i
< button_count
; ++i
)
1347 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1349 sizer_item
= caption_sizer
->Add(pane_button_size
,
1353 part
.type
= wxDockUIPart::typePaneButton
;
1356 part
.button
= &button
;
1357 part
.orientation
= orientation
;
1358 part
.cont_sizer
= caption_sizer
;
1359 part
.sizer_item
= sizer_item
;
1363 // add the caption sizer
1364 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1366 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1369 // add the pane window itself
1372 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1376 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1377 // Don't do this because it breaks the pane size in floating windows
1378 // BIW: Right now commenting this out is causing problems with
1379 // an mdi client window as the center pane.
1380 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1383 part
.type
= wxDockUIPart::typePane
;
1387 part
.orientation
= orientation
;
1388 part
.cont_sizer
= vert_pane_sizer
;
1389 part
.sizer_item
= sizer_item
;
1393 // determine if the pane should have a minimum size; if the pane is
1394 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1395 // if the pane.min_size is set, we must use that value as well
1397 wxSize min_size
= pane
.min_size
;
1400 if (min_size
== wxDefaultSize
)
1402 min_size
= pane
.best_size
;
1403 pane_proportion
= 0;
1407 if (min_size
!= wxDefaultSize
)
1409 vert_pane_sizer
->SetItemMinSize(
1410 vert_pane_sizer
->GetChildren().GetCount()-1,
1411 min_size
.x
, min_size
.y
);
1415 // add the verticle sizer (caption, pane window) to the
1416 // horizontal sizer (gripper, verticle sizer)
1417 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1419 // finally, add the pane sizer to the dock sizer
1421 if (pane
.HasBorder())
1423 // allowing space for the pane's border
1424 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1425 wxEXPAND
| wxALL
, pane_border_size
);
1427 part
.type
= wxDockUIPart::typePaneBorder
;
1431 part
.orientation
= orientation
;
1432 part
.cont_sizer
= cont
;
1433 part
.sizer_item
= sizer_item
;
1438 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1442 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1444 wxDockUIPartArray
& uiparts
,
1447 wxSizerItem
* sizer_item
;
1450 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1451 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1453 // resizable bottom and right docks have a sash before them
1454 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1455 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1457 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1459 part
.type
= wxDockUIPart::typeDockSizer
;
1460 part
.orientation
= orientation
;
1464 part
.cont_sizer
= cont
;
1465 part
.sizer_item
= sizer_item
;
1469 // create the sizer for the dock
1470 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1472 // add each pane to the dock
1473 int pane_i
, pane_count
= dock
.panes
.GetCount();
1477 wxArrayInt pane_positions
, pane_sizes
;
1479 // figure out the real pane positions we will
1480 // use, without modifying the each pane's pane_pos member
1481 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1484 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1486 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1487 int pane_pos
= pane_positions
.Item(pane_i
);
1489 int amount
= pane_pos
- offset
;
1492 if (dock
.IsVertical())
1493 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1495 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1497 part
.type
= wxDockUIPart::typeBackground
;
1501 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1502 part
.cont_sizer
= dock_sizer
;
1503 part
.sizer_item
= sizer_item
;
1509 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1511 offset
+= pane_sizes
.Item(pane_i
);
1514 // at the end add a very small stretchable background area
1515 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1517 part
.type
= wxDockUIPart::typeBackground
;
1521 part
.orientation
= orientation
;
1522 part
.cont_sizer
= dock_sizer
;
1523 part
.sizer_item
= sizer_item
;
1528 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1530 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1532 // if this is not the first pane being added,
1533 // we need to add a pane sizer
1536 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1538 part
.type
= wxDockUIPart::typePaneSizer
;
1540 part
.pane
= dock
.panes
.Item(pane_i
-1);
1542 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1543 part
.cont_sizer
= dock_sizer
;
1544 part
.sizer_item
= sizer_item
;
1548 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1552 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1553 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1555 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1557 part
.type
= wxDockUIPart::typeDock
;
1561 part
.orientation
= orientation
;
1562 part
.cont_sizer
= cont
;
1563 part
.sizer_item
= sizer_item
;
1566 if (dock
.IsHorizontal())
1567 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1569 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1571 // top and left docks have a sash after them
1572 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1573 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1575 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1577 part
.type
= wxDockUIPart::typeDockSizer
;
1581 part
.orientation
= orientation
;
1582 part
.cont_sizer
= cont
;
1583 part
.sizer_item
= sizer_item
;
1588 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1589 wxDockInfoArray
& docks
,
1590 wxDockUIPartArray
& uiparts
,
1593 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1595 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1596 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1597 wxSize cli_size
= m_frame
->GetClientSize();
1598 int i
, dock_count
, pane_count
;
1601 // empty all docks out
1602 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1603 docks
.Item(i
).panes
.Empty();
1605 // iterate through all known panes, filing each
1606 // of them into the appropriate dock. If the
1607 // pane does not exist in the dock, add it
1608 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1610 wxPaneInfo
& p
= panes
.Item(i
);
1612 // find any docks in this layer
1614 wxDockInfoPtrArray arr
;
1615 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1617 if (arr
.GetCount() > 0)
1623 // dock was not found, so we need to create a new one
1625 d
.dock_direction
= p
.dock_direction
;
1626 d
.dock_layer
= p
.dock_layer
;
1627 d
.dock_row
= p
.dock_row
;
1629 dock
= &docks
.Last();
1633 if (p
.IsDocked() && p
.IsShown())
1635 // remove the pane from any existing docks except this one
1636 RemovePaneFromDocks(docks
, p
, dock
);
1638 // pane needs to be added to the dock,
1639 // if it doesn't already exist
1640 if (!FindPaneInDock(*dock
, p
.window
))
1641 dock
->panes
.Add(&p
);
1645 // remove the pane from any existing docks
1646 RemovePaneFromDocks(docks
, p
);
1651 // remove any empty docks
1652 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1654 if (docks
.Item(i
).panes
.GetCount() == 0)
1658 // configure the docks further
1659 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1661 wxDockInfo
& dock
= docks
.Item(i
);
1662 int j
, dock_pane_count
= dock
.panes
.GetCount();
1664 // sort the dock pane array by the pane's
1665 // dock position (dock_pos), in ascending order
1666 dock
.panes
.Sort(PaneSortFunc
);
1668 // for newly created docks, set up their initial size
1673 for (j
= 0; j
< dock_pane_count
; ++j
)
1675 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1676 wxSize pane_size
= pane
.best_size
;
1677 if (pane_size
== wxDefaultSize
)
1678 pane_size
= pane
.min_size
;
1679 if (pane_size
== wxDefaultSize
)
1680 pane_size
= pane
.window
->GetSize();
1682 if (dock
.IsHorizontal())
1683 size
= wxMax(pane_size
.y
, size
);
1685 size
= wxMax(pane_size
.x
, size
);
1688 // add space for the border (two times), but only
1689 // if at least one pane inside the dock has a pane border
1690 for (j
= 0; j
< dock_pane_count
; ++j
)
1692 if (dock
.panes
.Item(j
)->HasBorder())
1694 size
+= (pane_border_size
*2);
1699 // if pane is on the top or bottom, add the caption height,
1700 // but only if at least one pane inside the dock has a caption
1701 if (dock
.IsHorizontal())
1703 for (j
= 0; j
< dock_pane_count
; ++j
)
1705 if (dock
.panes
.Item(j
)->HasCaption())
1707 size
+= caption_size
;
1713 // new dock's size may not be more than 1/3 of the frame size
1714 if (dock
.IsHorizontal())
1715 size
= wxMin(size
, cli_size
.y
/3);
1717 size
= wxMin(size
, cli_size
.x
/3);
1725 // determine the dock's minimum size
1726 bool plus_border
= false;
1727 bool plus_caption
= false;
1728 int dock_min_size
= 0;
1729 for (j
= 0; j
< dock_pane_count
; ++j
)
1731 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1732 if (pane
.min_size
!= wxDefaultSize
)
1734 if (pane
.HasBorder())
1736 if (pane
.HasCaption())
1737 plus_caption
= true;
1738 if (dock
.IsHorizontal())
1740 if (pane
.min_size
.y
> dock_min_size
)
1741 dock_min_size
= pane
.min_size
.y
;
1745 if (pane
.min_size
.x
> dock_min_size
)
1746 dock_min_size
= pane
.min_size
.x
;
1752 dock_min_size
+= (pane_border_size
*2);
1753 if (plus_caption
&& dock
.IsHorizontal())
1754 dock_min_size
+= (caption_size
);
1756 dock
.min_size
= dock_min_size
;
1759 // if the pane's current size is less than it's
1760 // minimum, increase the dock's size to it's minimum
1761 if (dock
.size
< dock
.min_size
)
1762 dock
.size
= dock
.min_size
;
1765 // determine the dock's mode (fixed or proportional);
1766 // determine whether the dock has only toolbars
1767 bool action_pane_marked
= false;
1769 dock
.toolbar
= true;
1770 for (j
= 0; j
< dock_pane_count
; ++j
)
1772 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1773 if (!pane
.IsFixed())
1775 if (!pane
.IsToolbar())
1776 dock
.toolbar
= false;
1777 if (pane
.state
& wxPaneInfo::actionPane
)
1778 action_pane_marked
= true;
1782 // if the dock mode is proportional and not fixed-pixel,
1783 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1784 // e.g. remove gaps like 1, 2, 30, 500
1787 for (j
= 0; j
< dock_pane_count
; ++j
)
1789 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1794 // if the dock mode is fixed, and none of the panes
1795 // are being moved right now, make sure the panes
1796 // do not overlap each other. If they do, we will
1797 // adjust the panes' positions
1798 if (dock
.fixed
&& !action_pane_marked
)
1800 wxArrayInt pane_positions
, pane_sizes
;
1801 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1804 for (j
= 0; j
< dock_pane_count
; ++j
)
1806 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1807 pane
.dock_pos
= pane_positions
[j
];
1809 int amount
= pane
.dock_pos
- offset
;
1813 pane
.dock_pos
+= -amount
;
1815 offset
+= pane_sizes
[j
];
1820 // discover the maximum dock layer
1822 for (i
= 0; i
< dock_count
; ++i
)
1823 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1826 // clear out uiparts
1829 // create a bunch of box sizers,
1830 // from the innermost level outwards.
1831 wxSizer
* cont
= NULL
;
1832 wxSizer
* middle
= NULL
;
1836 for (layer
= 0; layer
<= max_layer
; ++layer
)
1838 wxDockInfoPtrArray arr
;
1840 // find any docks in this layer
1841 FindDocks(docks
, -1, layer
, -1, arr
);
1843 // if there aren't any, skip to the next layer
1847 wxSizer
* old_cont
= cont
;
1849 // create a container which will hold this layer's
1850 // docks (top, bottom, left, right)
1851 cont
= new wxBoxSizer(wxVERTICAL
);
1854 // find any top docks in this layer
1855 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1856 RenumberDockRows(arr
);
1859 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1860 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1864 // fill out the middle layer (which consists
1865 // of left docks, content area and right docks)
1867 middle
= new wxBoxSizer(wxHORIZONTAL
);
1869 // find any left docks in this layer
1870 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1871 RenumberDockRows(arr
);
1874 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1875 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1878 // add content dock (or previous layer's sizer
1882 // find any center docks
1883 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1886 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1887 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1891 // there are no center docks, add a background area
1892 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1894 part
.type
= wxDockUIPart::typeBackground
;
1898 part
.cont_sizer
= middle
;
1899 part
.sizer_item
= sizer_item
;
1905 middle
->Add(old_cont
, 1, wxEXPAND
);
1908 // find any right docks in this layer
1909 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
1910 RenumberDockRows(arr
);
1913 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1914 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1917 cont
->Add(middle
, 1, wxEXPAND
);
1921 // find any bottom docks in this layer
1922 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
1923 RenumberDockRows(arr
);
1926 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
1927 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1934 // no sizer available, because there are no docks,
1935 // therefore we will create a simple background area
1936 cont
= new wxBoxSizer(wxVERTICAL
);
1937 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
1939 part
.type
= wxDockUIPart::typeBackground
;
1943 part
.cont_sizer
= middle
;
1944 part
.sizer_item
= sizer_item
;
1948 container
->Add(cont
, 1, wxEXPAND
);
1953 // Update() updates the layout. Whenever changes are made to
1954 // one or more panes, this function should be called. It is the
1955 // external entry point for running the layout engine.
1957 void wxFrameManager::Update()
1960 int i
, pane_count
= m_panes
.GetCount();
1962 // delete old sizer first
1963 m_frame
->SetSizer(NULL
);
1965 // destroy floating panes which have been
1966 // redocked or are becoming non-floating
1967 for (i
= 0; i
< pane_count
; ++i
)
1969 wxPaneInfo
& p
= m_panes
.Item(i
);
1971 if (!p
.IsFloating() && p
.frame
)
1973 // because the pane is no longer in a floating, we need to
1974 // reparent it to m_frame and destroy the floating frame
1977 p
.window
->SetSize(1,1);
1979 if (p
.frame
->IsShown())
1980 p
.frame
->Show(false);
1982 // reparent to m_frame and destroy the pane
1983 p
.window
->Reparent(m_frame
);
1984 p
.frame
->SetSizer(NULL
);
1991 // create a layout for all of the panes
1992 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
1994 // hide or show panes as necessary,
1995 // and float panes as necessary
1996 for (i
= 0; i
< pane_count
; ++i
)
1998 wxPaneInfo
& p
= m_panes
.Item(i
);
2002 if (p
.frame
== NULL
)
2004 // we need to create a frame for this
2005 // pane, which has recently been floated
2006 wxFloatingPane
* frame
= new wxFloatingPane(m_frame
,
2010 #if wxCHECK_VERSION(2,7,0)
2011 // on MSW and Mac, if the owner desires transparent dragging, and
2012 // the dragging is happening right now, then the floating
2013 // window should have this style by default
2014 if (m_action
== actionDragFloatingPane
&&
2015 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2016 frame
->SetTransparent(150);
2019 frame
->SetPaneWindow(p
);
2022 if (p
.IsShown() && !frame
->IsShown())
2027 // frame already exists, make sure it's position
2028 // and size reflect the information in wxPaneInfo
2029 if (p
.frame
->GetPosition() != p
.floating_pos
)
2031 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2032 wxDefaultCoord
, wxDefaultCoord
,
2033 wxSIZE_USE_EXISTING
);
2034 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2037 if (p
.frame
->IsShown() != p
.IsShown())
2038 p
.frame
->Show(p
.IsShown());
2043 if (p
.window
->IsShown() != p
.IsShown())
2044 p
.window
->Show(p
.IsShown());
2047 // if "active panes" are no longer allowed, clear
2048 // any optionActive values from the pane states
2049 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2051 p
.state
&= ~wxPaneInfo::optionActive
;
2056 // keep track of the old window rectangles so we can
2057 // refresh those windows whose rect has changed
2058 wxAuiRectArray old_pane_rects
;
2059 for (i
= 0; i
< pane_count
; ++i
)
2062 wxPaneInfo
& p
= m_panes
.Item(i
);
2064 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2067 old_pane_rects
.Add(r
);
2073 // apply the new sizer
2074 m_frame
->SetSizer(sizer
);
2075 m_frame
->SetAutoLayout(false);
2080 // now that the frame layout is done, we need to check
2081 // the new pane rectangles against the old rectangles that
2082 // we saved a few lines above here. If the rectangles have
2083 // changed, the corresponding panes must also be updated
2084 for (i
= 0; i
< pane_count
; ++i
)
2086 wxPaneInfo
& p
= m_panes
.Item(i
);
2087 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2089 if (p
.rect
!= old_pane_rects
[i
])
2091 p
.window
->Refresh();
2100 // set frame's minimum size
2103 // N.B. More work needs to be done on frame minimum sizes;
2104 // this is some intresting code that imposes the minimum size,
2105 // but we may want to include a more flexible mechanism or
2106 // options for multiple minimum-size modes, e.g. strict or lax
2107 wxSize min_size = sizer->GetMinSize();
2108 wxSize frame_size = m_frame->GetSize();
2109 wxSize client_size = m_frame->GetClientSize();
2111 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2112 min_size.y+frame_size.y-client_size.y );
2114 m_frame->SetMinSize(minframe_size);
2116 if (frame_size.x < minframe_size.x ||
2117 frame_size.y < minframe_size.y)
2118 sizer->Fit(m_frame);
2123 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2124 // on the frame's main sizer, then measures all the various UI items
2125 // and updates their internal rectangles. This should always be called
2126 // instead of calling m_frame->Layout() directly
2128 void wxFrameManager::DoFrameLayout()
2133 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2135 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2137 // get the rectangle of the UI part
2138 // originally, this code looked like this:
2139 // part.rect = wxRect(part.sizer_item->GetPosition(),
2140 // part.sizer_item->GetSize());
2141 // this worked quite well, with one exception: the mdi
2142 // client window had a "deferred" size variable
2143 // that returned the wrong size. It looks like
2144 // a bug in wx, because the former size of the window
2145 // was being returned. So, we will retrieve the part's
2146 // rectangle via other means
2149 part
.rect
= part
.sizer_item
->GetRect();
2150 int flag
= part
.sizer_item
->GetFlag();
2151 int border
= part
.sizer_item
->GetBorder();
2154 part
.rect
.y
-= border
;
2155 part
.rect
.height
+= border
;
2159 part
.rect
.x
-= border
;
2160 part
.rect
.width
+= border
;
2162 if (flag
& wxBOTTOM
)
2163 part
.rect
.height
+= border
;
2165 part
.rect
.width
+= border
;
2168 if (part
.type
== wxDockUIPart::typeDock
)
2169 part
.dock
->rect
= part
.rect
;
2170 if (part
.type
== wxDockUIPart::typePane
)
2171 part
.pane
->rect
= part
.rect
;
2175 // GetPanePart() looks up the pane the pane border UI part (or the regular
2176 // pane part if there is no border). This allows the caller to get the exact
2177 // rectangle of the pane in question, including decorations like
2178 // caption and border (if any).
2180 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
2183 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2185 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2186 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2187 part
.pane
&& part
.pane
->window
== wnd
)
2190 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2192 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2193 if (part
.type
== wxDockUIPart::typePane
&&
2194 part
.pane
&& part
.pane
->window
== wnd
)
2202 // GetDockPixelOffset() is an internal function which returns
2203 // a dock's offset in pixels from the left side of the window
2204 // (for horizontal docks) or from the top of the window (for
2205 // vertical docks). This value is necessary for calculating
2206 // fixel-pane/toolbar offsets when they are dragged.
2208 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
2210 // the only way to accurately calculate the dock's
2211 // offset is to actually run a theoretical layout
2213 int i
, part_count
, dock_count
;
2214 wxDockInfoArray docks
;
2215 wxPaneInfoArray panes
;
2216 wxDockUIPartArray uiparts
;
2217 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2220 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2221 wxSize client_size
= m_frame
->GetClientSize();
2222 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2225 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2227 wxDockUIPart
& part
= uiparts
.Item(i
);
2228 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2229 part
.sizer_item
->GetSize());
2230 if (part
.type
== wxDockUIPart::typeDock
)
2231 part
.dock
->rect
= part
.rect
;
2236 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2238 wxDockInfo
& dock
= docks
.Item(i
);
2239 if (test
.dock_direction
== dock
.dock_direction
&&
2240 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2242 if (dock
.IsVertical())
2254 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2255 // if a dock operation is allowed, the new dock position is copied into
2256 // the target info. If the operation was allowed, the function returns true.
2258 bool wxFrameManager::ProcessDockResult(wxPaneInfo
& target
,
2259 const wxPaneInfo
& new_pos
)
2261 bool allowed
= false;
2262 switch (new_pos
.dock_direction
)
2264 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2265 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2266 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2267 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2277 // DoDrop() is an important function. It basically takes a mouse position,
2278 // and determines where the pane's new position would be. If the pane is to be
2279 // dropped, it performs the drop operation using the specified dock and pane
2280 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2281 // scenario can be performed, giving precise coordinates for drop hints.
2282 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2283 // as parameters, the changes will be made to the main state arrays
2285 const int auiInsertRowPixels
= 10;
2286 const int auiNewRowPixels
= 40;
2287 const int auiLayerInsertPixels
= 40;
2288 const int auiLayerInsertOffset
= 5;
2290 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2291 wxPaneInfoArray
& panes
,
2294 const wxPoint
& offset
)
2296 wxSize cli_size
= m_frame
->GetClientSize();
2298 wxPaneInfo drop
= target
;
2301 // The result should always be shown
2305 // Check to see if the pane has been dragged outside of the window
2306 // (or near to the outside of the window), if so, dock it along the edge
2309 int layer_insert_offset
= auiLayerInsertOffset
;
2310 if (target
.IsToolbar())
2311 layer_insert_offset
= 0;
2313 if (pt
.x
< layer_insert_offset
&&
2314 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2318 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2319 return ProcessDockResult(target
, drop
);
2321 else if (pt
.y
< layer_insert_offset
&&
2322 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2326 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2327 return ProcessDockResult(target
, drop
);
2329 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2330 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2332 drop
.Dock().Right().
2334 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2335 return ProcessDockResult(target
, drop
);
2337 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2338 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2340 int new_layer
= wxMax( wxMax( GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2341 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2342 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2344 drop
.Dock().Bottom().
2347 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2348 return ProcessDockResult(target
, drop
);
2351 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2354 if (drop
.IsToolbar())
2356 if (!part
|| !part
->dock
)
2359 // calculate the offset from where the dock begins
2360 // to the point where the user dropped the pane
2361 int dock_drop_offset
= 0;
2362 if (part
->dock
->IsHorizontal())
2363 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2365 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2368 // toolbars may only be moved in and to fixed-pane docks,
2369 // otherwise we will try to float the pane. Also, the pane
2370 // should float if being dragged over center pane windows
2371 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2373 if (m_last_rect
.IsEmpty() || m_last_rect
.Inside(pt
.x
, pt
.y
))
2379 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2380 (drop
.IsFloatable() ||
2381 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2382 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2389 return ProcessDockResult(target
, drop
);
2392 drop
.Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2394 return ProcessDockResult(target
, drop
);
2403 m_last_rect
= part
->dock
->rect
;
2404 m_last_rect
.Inflate( 15, 15 );
2408 Direction(part
->dock
->dock_direction
).
2409 Layer(part
->dock
->dock_layer
).
2410 Row(part
->dock
->dock_row
).
2411 Position(dock_drop_offset
);
2414 ((pt
.y
< part
->dock
->rect
.y
+ 1) && part
->dock
->IsHorizontal()) ||
2415 ((pt
.x
< part
->dock
->rect
.x
+ 1) && part
->dock
->IsVertical())
2416 ) && part
->dock
->panes
.GetCount() > 1)
2418 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2419 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2421 int row
= drop
.dock_row
;
2422 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2423 part
->dock
->dock_layer
,
2424 part
->dock
->dock_row
);
2425 drop
.dock_row
= row
;
2429 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2430 part
->dock
->dock_layer
,
2431 part
->dock
->dock_row
+1);
2432 drop
.dock_row
= part
->dock
->dock_row
+1;
2437 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2438 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2439 ) && part
->dock
->panes
.GetCount() > 1)
2441 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2442 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2444 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2445 part
->dock
->dock_layer
,
2446 part
->dock
->dock_row
+1);
2447 drop
.dock_row
= part
->dock
->dock_row
+1;
2451 int row
= drop
.dock_row
;
2452 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2453 part
->dock
->dock_layer
,
2454 part
->dock
->dock_row
);
2455 drop
.dock_row
= row
;
2459 return ProcessDockResult(target
, drop
);
2468 if (part
->type
== wxDockUIPart::typePaneBorder
||
2469 part
->type
== wxDockUIPart::typeCaption
||
2470 part
->type
== wxDockUIPart::typeGripper
||
2471 part
->type
== wxDockUIPart::typePaneButton
||
2472 part
->type
== wxDockUIPart::typePane
||
2473 part
->type
== wxDockUIPart::typePaneSizer
||
2474 part
->type
== wxDockUIPart::typeDockSizer
||
2475 part
->type
== wxDockUIPart::typeBackground
)
2477 if (part
->type
== wxDockUIPart::typeDockSizer
)
2479 if (part
->dock
->panes
.GetCount() != 1)
2481 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2488 // If a normal frame is being dragged over a toolbar, insert it
2489 // along the edge under the toolbar, but over all other panes.
2490 // (this could be done much better, but somehow factoring this
2491 // calculation with the one at the beginning of this function)
2492 if (part
->dock
&& part
->dock
->toolbar
)
2496 switch (part
->dock
->dock_direction
)
2498 case wxAUI_DOCK_LEFT
:
2499 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2500 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2501 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2503 case wxAUI_DOCK_TOP
:
2504 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2505 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2506 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2508 case wxAUI_DOCK_RIGHT
:
2509 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2510 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2511 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2513 case wxAUI_DOCK_BOTTOM
:
2514 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2515 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2516 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2520 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2523 Direction(part
->dock
->dock_direction
).
2524 Layer(layer
).Row(0).Position(0);
2525 return ProcessDockResult(target
, drop
);
2532 part
= GetPanePart(part
->pane
->window
);
2536 bool insert_dock_row
= false;
2537 int insert_row
= part
->pane
->dock_row
;
2538 int insert_dir
= part
->pane
->dock_direction
;
2539 int insert_layer
= part
->pane
->dock_layer
;
2541 switch (part
->pane
->dock_direction
)
2543 case wxAUI_DOCK_TOP
:
2544 if (pt
.y
>= part
->rect
.y
&&
2545 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2546 insert_dock_row
= true;
2548 case wxAUI_DOCK_BOTTOM
:
2549 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2550 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2551 insert_dock_row
= true;
2553 case wxAUI_DOCK_LEFT
:
2554 if (pt
.x
>= part
->rect
.x
&&
2555 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2556 insert_dock_row
= true;
2558 case wxAUI_DOCK_RIGHT
:
2559 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2560 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2561 insert_dock_row
= true;
2563 case wxAUI_DOCK_CENTER
:
2565 // "new row pixels" will be set to the default, but
2566 // must never exceed 20% of the window size
2567 int new_row_pixels_x
= auiNewRowPixels
;
2568 int new_row_pixels_y
= auiNewRowPixels
;
2570 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2571 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2573 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2574 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2577 // determine if the mouse pointer is in a location that
2578 // will cause a new row to be inserted. The hot spot positions
2579 // are along the borders of the center pane
2582 insert_dock_row
= true;
2583 if (pt
.x
>= part
->rect
.x
&&
2584 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2585 insert_dir
= wxAUI_DOCK_LEFT
;
2587 if (pt
.y
>= part
->rect
.y
&&
2588 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2589 insert_dir
= wxAUI_DOCK_TOP
;
2591 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2592 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2593 insert_dir
= wxAUI_DOCK_RIGHT
;
2595 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2596 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2597 insert_dir
= wxAUI_DOCK_BOTTOM
;
2601 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2605 if (insert_dock_row
)
2607 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2608 drop
.Dock().Direction(insert_dir
).
2609 Layer(insert_layer
).
2612 return ProcessDockResult(target
, drop
);
2615 // determine the mouse offset and the pane size, both in the
2616 // direction of the dock itself, and perpendicular to the dock
2620 if (part
->orientation
== wxVERTICAL
)
2622 offset
= pt
.y
- part
->rect
.y
;
2623 size
= part
->rect
.GetHeight();
2627 offset
= pt
.x
- part
->rect
.x
;
2628 size
= part
->rect
.GetWidth();
2631 int drop_position
= part
->pane
->dock_pos
;
2633 // if we are in the top/left part of the pane,
2634 // insert the pane before the pane being hovered over
2635 if (offset
<= size
/2)
2637 drop_position
= part
->pane
->dock_pos
;
2639 part
->pane
->dock_direction
,
2640 part
->pane
->dock_layer
,
2641 part
->pane
->dock_row
,
2642 part
->pane
->dock_pos
);
2645 // if we are in the bottom/right part of the pane,
2646 // insert the pane before the pane being hovered over
2647 if (offset
> size
/2)
2649 drop_position
= part
->pane
->dock_pos
+1;
2651 part
->pane
->dock_direction
,
2652 part
->pane
->dock_layer
,
2653 part
->pane
->dock_row
,
2654 part
->pane
->dock_pos
+1);
2658 Direction(part
->dock
->dock_direction
).
2659 Layer(part
->dock
->dock_layer
).
2660 Row(part
->dock
->dock_row
).
2661 Position(drop_position
);
2662 return ProcessDockResult(target
, drop
);
2669 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2671 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
2673 m_hint_fadetimer
.Stop();
2677 m_hint_fadeamt
+= 4;
2678 #if wxCHECK_VERSION(2,7,0)
2679 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2681 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2682 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2686 void wxFrameManager::ShowHint(const wxRect
& rect
)
2688 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0
2690 // Finally, don't use a venetian blind effect if it's been specifically disabled
2691 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2692 (m_flags
& wxAUI_MGR_DISABLE_VENETIAN_BLINDS
))
2695 if (m_last_hint
== rect
)
2699 m_hint_fadeamt
= m_hint_fademax
;
2700 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT_FADE
)
2701 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2702 (m_flags
& wxAUI_MGR_DISABLE_VENETIAN_BLINDS_FADE
))
2706 m_hint_wnd
->SetSize(rect
);
2708 if (! m_hint_wnd
->IsShown())
2711 // if we are dragging a floating pane, set the focus
2712 // back to that floating pane (otherwise it becomes unfocused)
2713 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2714 m_action_window
->SetFocus();
2716 #if wxCHECK_VERSION(2,7,0)
2717 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2719 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2720 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2722 m_hint_wnd
->Raise();
2725 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
2727 // start fade in timer
2728 m_hint_fadetimer
.SetOwner(this, 101);
2729 m_hint_fadetimer
.Start(5);
2733 else // Not using a transparent hint window...
2736 if (m_last_hint
!= rect
)
2738 // remove the last hint rectangle
2744 wxScreenDC screendc
;
2745 wxRegion
clip(1, 1, 10000, 10000);
2747 // clip all floating windows, so we don't draw over them
2749 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2751 wxPaneInfo
& pane
= m_panes
.Item(i
);
2753 if (pane
.IsFloating() &&
2754 pane
.frame
->IsShown())
2756 wxRect rect
= pane
.frame
->GetRect();
2758 // wxGTK returns the client size, not the whole frame size
2764 clip
.Subtract(rect
);
2768 // As we can only hide the hint by redrawing the managed window, we
2769 // need to clip the region to the managed window too or we get
2770 // nasty redrawn problems.
2771 clip
.Intersect(m_frame
->GetRect());
2773 screendc
.SetClippingRegion(clip
);
2775 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2776 wxBrush
brush(stipple
);
2777 screendc
.SetBrush(brush
);
2778 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2780 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2781 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2782 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2783 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2787 void wxFrameManager::HideHint()
2789 // hides a transparent window hint, if there is one
2792 if (m_hint_wnd
->IsShown())
2793 m_hint_wnd
->Show(false);
2794 #if wxCHECK_VERSION(2,7,0)
2795 m_hint_wnd
->SetTransparent(0);
2797 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2798 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(0);
2800 m_hint_fadetimer
.Stop();
2801 m_last_hint
= wxRect();
2805 // hides a painted hint by redrawing the frame window
2806 if (!m_last_hint
.IsEmpty())
2810 m_last_hint
= wxRect();
2816 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2817 // determine the exact position the pane would be at were if dropped. If
2818 // the pame would indeed become docked at the specified drop point,
2819 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2820 // "pane_window" is the window pointer of the pane being dragged, pt is
2821 // the mouse position, in client coordinates
2822 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2824 const wxPoint
& offset
)
2828 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2829 // we will create a new temporary layout and then measure the resulting
2830 // rectangle; we will create a copy of the docking structures (m_dock)
2831 // so that we don't modify the real thing on screen
2833 int i
, pane_count
, part_count
;
2834 wxDockInfoArray docks
;
2835 wxPaneInfoArray panes
;
2836 wxDockUIPartArray uiparts
;
2837 wxPaneInfo hint
= GetPane(pane_window
);
2838 hint
.name
= wxT("__HINT__");
2844 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2846 // remove any pane already there which bears the same window;
2847 // this happens when you are moving a pane around in a dock
2848 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2850 if (panes
.Item(i
).window
== pane_window
)
2852 RemovePaneFromDocks(docks
, panes
.Item(i
));
2858 // find out where the new pane would be
2859 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2867 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2868 wxSize client_size
= m_frame
->GetClientSize();
2869 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2872 for (i
= 0, part_count
= uiparts
.GetCount();
2873 i
< part_count
; ++i
)
2875 wxDockUIPart
& part
= uiparts
.Item(i
);
2877 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2878 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2880 rect
= wxRect(part
.sizer_item
->GetPosition(),
2881 part
.sizer_item
->GetSize());
2894 // actually show the hint rectangle on the screen
2895 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
2899 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
2901 // try to find the pane
2902 wxPaneInfo
& pane
= GetPane(wnd
);
2903 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2905 #if wxCHECK_VERSION(2,7,0)
2906 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
2907 pane
.frame
->SetTransparent(150);
2911 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
2913 // try to find the pane
2914 wxPaneInfo
& pane
= GetPane(wnd
);
2915 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
2917 wxPoint pt
= ::wxGetMousePosition();
2920 // Adapt pt to direction
2923 // move to pane's upper border
2925 pos
= wnd
->ClientToScreen( pos
);
2927 // and some more pixels for the title bar
2932 // move to pane's left border
2934 pos
= wnd
->ClientToScreen( pos
);
2939 // move to pane's right border
2940 wxPoint
pos( wnd
->GetSize().x
, 0 );
2941 pos
= wnd
->ClientToScreen( pos
);
2946 // move to pane's bottom border
2947 wxPoint
pos( 0, wnd
->GetSize().y
);
2948 pos
= wnd
->ClientToScreen( pos
);
2953 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
2955 // calculate the offset from the upper left-hand corner
2956 // of the frame to the mouse pointer
2957 wxPoint frame_pos
= pane
.frame
->GetPosition();
2958 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
2960 // no hint for toolbar floating windows
2961 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
2963 if (m_action
== actionDragFloatingPane
)
2965 wxDockInfoArray docks
;
2966 wxPaneInfoArray panes
;
2967 wxDockUIPartArray uiparts
;
2968 wxPaneInfo hint
= pane
;
2970 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2972 // find out where the new pane would be
2973 if (!DoDrop(docks
, panes
, hint
, client_pt
))
2975 if (hint
.IsFloating())
2979 m_action
= actionDragToolbarPane
;
2980 m_action_window
= pane
.window
;
2989 // if a key modifier is pressed while dragging the frame,
2990 // don't dock the window
2991 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
2998 DrawHintRect(wnd
, client_pt
, action_offset
);
3001 // this cleans up some screen artifacts that are caused on GTK because
3002 // we aren't getting the exact size of the window (see comment
3012 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
3014 // try to find the pane
3015 wxPaneInfo
& pane
= GetPane(wnd
);
3016 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3018 wxPoint pt
= ::wxGetMousePosition();
3021 // Adapt pt to direction
3024 // move to pane's upper border
3026 pos
= wnd
->ClientToScreen( pos
);
3028 // and some more pixels for the title bar
3033 // move to pane's left border
3035 pos
= wnd
->ClientToScreen( pos
);
3040 // move to pane's right border
3041 wxPoint
pos( wnd
->GetSize().x
, 0 );
3042 pos
= wnd
->ClientToScreen( pos
);
3047 // move to pane's bottom border
3048 wxPoint
pos( 0, wnd
->GetSize().y
);
3049 pos
= wnd
->ClientToScreen( pos
);
3054 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3056 // calculate the offset from the upper left-hand corner
3057 // of the frame to the mouse pointer
3058 wxPoint frame_pos
= pane
.frame
->GetPosition();
3059 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3062 // if a key modifier is pressed while dragging the frame,
3063 // don't dock the window
3064 if (!wxGetKeyState(WXK_CONTROL
) && !wxGetKeyState(WXK_ALT
))
3066 // do the drop calculation
3067 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3070 // if the pane is still floating, update it's floating
3071 // position (that we store)
3072 if (pane
.IsFloating())
3074 pane
.floating_pos
= pane
.frame
->GetPosition();
3076 #if wxCHECK_VERSION(2,7,0)
3077 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3078 pane
.frame
->SetTransparent(255);
3087 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3089 // try to find the pane
3090 wxPaneInfo
& pane
= GetPane(wnd
);
3091 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3093 pane
.floating_size
= size
;
3097 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3099 // try to find the pane
3100 wxPaneInfo
& pane
= GetPane(wnd
);
3101 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3104 // fire pane close event
3105 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3107 e
.SetCanVeto(evt
.CanVeto());
3117 // reparent the pane window back to us and
3118 // prepare the frame window for destruction
3119 if (pane
.window
->IsShown())
3120 pane
.window
->Show(false);
3121 pane
.window
->Reparent(m_frame
);
3129 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3131 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3133 // try to find the pane
3134 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
3136 SetActivePane(m_panes
, wnd
);
3141 // OnRender() draws all of the pane captions, sashes,
3142 // backgrounds, captions, grippers, pane borders and buttons.
3143 // It renders the entire user interface.
3145 void wxFrameManager::OnRender(wxFrameManagerEvent
& evt
)
3147 wxDC
* dc
= evt
.GetDC();
3153 for (i
= 0, part_count
= m_uiparts
.GetCount();
3154 i
< part_count
; ++i
)
3156 wxDockUIPart
& part
= m_uiparts
.Item(i
);
3158 // don't draw hidden pane items
3159 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
3164 case wxDockUIPart::typeDockSizer
:
3165 case wxDockUIPart::typePaneSizer
:
3166 m_art
->DrawSash(*dc
, part
.orientation
, part
.rect
);
3168 case wxDockUIPart::typeBackground
:
3169 m_art
->DrawBackground(*dc
, part
.orientation
, part
.rect
);
3171 case wxDockUIPart::typeCaption
:
3172 m_art
->DrawCaption(*dc
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3174 case wxDockUIPart::typeGripper
:
3175 m_art
->DrawGripper(*dc
, part
.rect
, *part
.pane
);
3177 case wxDockUIPart::typePaneBorder
:
3178 m_art
->DrawBorder(*dc
, part
.rect
, *part
.pane
);
3180 case wxDockUIPart::typePaneButton
:
3181 m_art
->DrawPaneButton(*dc
, part
.button
->button_id
,
3182 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3189 // Render() fire a render event, which is normally handled by
3190 // wxFrameManager::OnRender(). This allows the render function to
3191 // be overridden via the render event. This can be useful for paintin
3192 // custom graphics in the main window. Default behavior can be
3193 // invoked in the overridden function by calling OnRender()
3195 void wxFrameManager::Render(wxDC
* dc
)
3197 wxFrameManagerEvent
e(wxEVT_AUI_RENDER
);
3202 void wxFrameManager::Repaint(wxDC
* dc
)
3207 m_frame
->Refresh() ;
3213 m_frame
->GetClientSize(&w
, &h
);
3215 // figure out which dc to use; if one
3216 // has been specified, use it, otherwise
3218 wxClientDC
* client_dc
= NULL
;
3221 client_dc
= new wxClientDC(m_frame
);
3225 // if the frame has a toolbar, the client area
3226 // origin will not be (0,0).
3227 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3228 if (pt
.x
!= 0 || pt
.y
!= 0)
3229 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3231 // render all the items
3234 // if we created a client_dc, delete it
3239 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3241 wxPaintDC
dc(m_frame
);
3245 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
3254 void wxFrameManager::OnSize(wxSizeEvent
& event
)
3265 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
3268 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3269 wxCursor cursor
= wxNullCursor
;
3273 if (part
->type
== wxDockUIPart::typeDockSizer
||
3274 part
->type
== wxDockUIPart::typePaneSizer
)
3276 // a dock may not be resized if it has a single
3277 // pane which is not resizable
3278 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3279 part
->dock
->panes
.GetCount() == 1 &&
3280 part
->dock
->panes
.Item(0)->IsFixed())
3283 // panes that may not be resized do not get a sizing cursor
3284 if (part
->pane
&& part
->pane
->IsFixed())
3287 if (part
->orientation
== wxVERTICAL
)
3288 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3290 cursor
= wxCursor(wxCURSOR_SIZENS
);
3292 else if (part
->type
== wxDockUIPart::typeGripper
)
3294 cursor
= wxCursor(wxCURSOR_SIZING
);
3298 event
.SetCursor(cursor
);
3303 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
3304 const wxMouseEvent
& event
)
3306 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3308 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3310 if (hit_test
== button_ui_part
)
3312 if (event
.LeftDown())
3313 state
= wxAUI_BUTTON_STATE_PRESSED
;
3315 state
= wxAUI_BUTTON_STATE_HOVER
;
3319 if (event
.LeftDown())
3320 state
= wxAUI_BUTTON_STATE_HOVER
;
3323 // now repaint the button with hover state
3324 wxClientDC
cdc(m_frame
);
3326 // if the frame has a toolbar, the client area
3327 // origin will not be (0,0).
3328 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3329 if (pt
.x
!= 0 || pt
.y
!= 0)
3330 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3332 m_art
->DrawPaneButton(cdc
,
3333 button_ui_part
->button
->button_id
,
3335 button_ui_part
->rect
,
3339 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
3341 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3344 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3347 if (part
->type
== wxDockUIPart::typeDockSizer
||
3348 part
->type
== wxDockUIPart::typePaneSizer
)
3350 // a dock may not be resized if it has a single
3351 // pane which is not resizable
3352 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3353 part
->dock
->panes
.GetCount() == 1 &&
3354 part
->dock
->panes
.Item(0)->IsFixed())
3357 // panes that may not be resized should be ignored here
3358 if (part
->pane
&& part
->pane
->IsFixed())
3361 m_action
= actionResize
;
3362 m_action_part
= part
;
3363 m_action_hintrect
= wxRect();
3364 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3365 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3366 event
.m_y
- part
->rect
.y
);
3367 m_frame
->CaptureMouse();
3369 else if (part
->type
== wxDockUIPart::typePaneButton
)
3371 m_action
= actionClickButton
;
3372 m_action_part
= part
;
3373 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3374 m_frame
->CaptureMouse();
3376 UpdateButtonOnScreen(part
, event
);
3378 else if (part
->type
== wxDockUIPart::typeCaption
||
3379 part
->type
== wxDockUIPart::typeGripper
)
3381 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3383 // set the caption as active
3384 SetActivePane(m_panes
, part
->pane
->window
);
3388 m_action
= actionClickCaption
;
3389 m_action_part
= part
;
3390 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3391 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3392 event
.m_y
- part
->rect
.y
);
3393 m_frame
->CaptureMouse();
3413 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3415 if (m_action
== actionResize
)
3417 m_frame
->ReleaseMouse();
3419 // get rid of the hint rectangle
3421 DrawResizeHint(dc
, m_action_hintrect
);
3423 // resize the dock or the pane
3424 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3426 wxRect
& rect
= m_action_part
->dock
->rect
;
3428 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3429 event
.m_y
- m_action_offset
.y
);
3431 switch (m_action_part
->dock
->dock_direction
)
3433 case wxAUI_DOCK_LEFT
:
3434 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3436 case wxAUI_DOCK_TOP
:
3437 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3439 case wxAUI_DOCK_RIGHT
:
3440 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3441 new_pos
.x
- m_action_part
->rect
.GetWidth();
3443 case wxAUI_DOCK_BOTTOM
:
3444 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3445 new_pos
.y
- m_action_part
->rect
.GetHeight();
3452 else if (m_action_part
&&
3453 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3455 wxDockInfo
& dock
= *m_action_part
->dock
;
3456 wxPaneInfo
& pane
= *m_action_part
->pane
;
3458 int total_proportion
= 0;
3459 int dock_pixels
= 0;
3460 int new_pixsize
= 0;
3462 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3463 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3464 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3466 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3467 event
.m_y
- m_action_offset
.y
);
3469 // determine the pane rectangle by getting the pane part
3470 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3471 wxASSERT_MSG(pane_part
,
3472 wxT("Pane border part not found -- shouldn't happen"));
3474 // determine the new pixel size that the user wants;
3475 // this will help us recalculate the pane's proportion
3476 if (dock
.IsHorizontal())
3477 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3479 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3481 // determine the size of the dock, based on orientation
3482 if (dock
.IsHorizontal())
3483 dock_pixels
= dock
.rect
.GetWidth();
3485 dock_pixels
= dock
.rect
.GetHeight();
3487 // determine the total proportion of all resizable panes,
3488 // and the total size of the dock minus the size of all
3490 int i
, dock_pane_count
= dock
.panes
.GetCount();
3491 int pane_position
= -1;
3492 for (i
= 0; i
< dock_pane_count
; ++i
)
3494 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3495 if (p
.window
== pane
.window
)
3498 // while we're at it, subtract the pane sash
3499 // width from the dock width, because this would
3500 // skew our proportion calculations
3502 dock_pixels
-= sash_size
;
3504 // also, the whole size (including decorations) of
3505 // all fixed panes must also be subtracted, because they
3506 // are not part of the proportion calculation
3509 if (dock
.IsHorizontal())
3510 dock_pixels
-= p
.best_size
.x
;
3512 dock_pixels
-= p
.best_size
.y
;
3516 total_proportion
+= p
.dock_proportion
;
3520 // find a pane in our dock to 'steal' space from or to 'give'
3521 // space to -- this is essentially what is done when a pane is
3522 // resized; the pane should usually be the first non-fixed pane
3523 // to the right of the action pane
3524 int borrow_pane
= -1;
3525 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3527 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3536 // demand that the pane being resized is found in this dock
3537 // (this assert really never should be raised)
3538 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3540 // prevent division by zero
3541 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3543 m_action
= actionNone
;
3547 // calculate the new proportion of the pane
3548 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3550 // default minimum size
3553 // check against the pane's minimum size, if specified. please note
3554 // that this is not enough to ensure that the minimum size will
3555 // not be violated, because the whole frame might later be shrunk,
3556 // causing the size of the pane to violate it's minimum size
3557 if (pane
.min_size
.IsFullySpecified())
3561 if (pane
.HasBorder())
3562 min_size
+= (pane_border_size
*2);
3564 // calculate minimum size with decorations (border,caption)
3565 if (pane_part
->orientation
== wxVERTICAL
)
3567 min_size
+= pane
.min_size
.y
;
3568 if (pane
.HasCaption())
3569 min_size
+= caption_size
;
3573 min_size
+= pane
.min_size
.x
;
3578 // for some reason, an arithmatic error somewhere is causing
3579 // the proportion calculations to always be off by 1 pixel;
3580 // for now we will add the 1 pixel on, but we really should
3581 // determine what's causing this.
3584 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3586 if (new_proportion
< min_proportion
)
3587 new_proportion
= min_proportion
;
3591 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3593 // borrow the space from our neighbor pane to the
3594 // right or bottom (depending on orientation)
3595 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3596 pane
.dock_proportion
= new_proportion
;
3603 else if (m_action
== actionClickButton
)
3605 m_hover_button
= NULL
;
3606 m_frame
->ReleaseMouse();
3607 UpdateButtonOnScreen(m_action_part
, event
);
3609 // make sure we're still over the item that was originally clicked
3610 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3612 // fire button-click event
3613 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3614 e
.SetPane(m_action_part
->pane
);
3615 e
.SetButton(m_action_part
->button
->button_id
);
3619 else if (m_action
== actionClickCaption
)
3621 m_frame
->ReleaseMouse();
3623 else if (m_action
== actionDragFloatingPane
)
3625 m_frame
->ReleaseMouse();
3627 else if (m_action
== actionDragToolbarPane
)
3629 m_frame
->ReleaseMouse();
3631 wxPaneInfo
& pane
= GetPane(m_action_window
);
3632 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3634 // save the new positions
3635 wxDockInfoPtrArray docks
;
3636 FindDocks(m_docks
, pane
.dock_direction
,
3637 pane
.dock_layer
, pane
.dock_row
, docks
);
3638 if (docks
.GetCount() == 1)
3640 wxDockInfo
& dock
= *docks
.Item(0);
3642 wxArrayInt pane_positions
, pane_sizes
;
3643 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3645 int i
, dock_pane_count
= dock
.panes
.GetCount();
3646 for (i
= 0; i
< dock_pane_count
; ++i
)
3647 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3650 pane
.state
&= ~wxPaneInfo::actionPane
;
3658 m_action
= actionNone
;
3659 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3663 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3665 // sometimes when Update() is called from inside this method,
3666 // a spurious mouse move event is generated; this check will make
3667 // sure that only real mouse moves will get anywhere in this method;
3668 // this appears to be a bug somewhere, and I don't know where the
3669 // mouse move event is being generated. only verified on MSW
3671 wxPoint mouse_pos
= event
.GetPosition();
3672 if (m_last_mouse_move
== mouse_pos
)
3674 m_last_mouse_move
= mouse_pos
;
3677 if (m_action
== actionResize
)
3679 wxPoint pos
= m_action_part
->rect
.GetPosition();
3680 if (m_action_part
->orientation
== wxHORIZONTAL
)
3681 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3683 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3685 wxRect
rect(m_frame
->ClientToScreen(pos
),
3686 m_action_part
->rect
.GetSize());
3689 if (!m_action_hintrect
.IsEmpty())
3690 DrawResizeHint(dc
, m_action_hintrect
);
3691 DrawResizeHint(dc
, rect
);
3692 m_action_hintrect
= rect
;
3694 else if (m_action
== actionClickCaption
)
3696 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3697 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3699 // caption has been clicked. we need to check if the mouse
3700 // is now being dragged. if it is, we need to change the
3701 // mouse action to 'drag'
3702 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3703 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3705 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3707 if (!pane_info
->IsToolbar())
3709 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3710 pane_info
->IsFloatable())
3712 m_action
= actionDragFloatingPane
;
3714 // set initial float position
3715 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3716 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3717 pt
.y
- m_action_offset
.y
);
3722 m_action_window
= pane_info
->frame
;
3724 // action offset is used here to make it feel "natural" to the user
3725 // to drag a docked pane and suddenly have it become a floating frame.
3726 // Sometimes, however, the offset where the user clicked on the docked
3727 // caption is bigger than the width of the floating frame itself, so
3728 // in that case we need to set the action offset to a sensible value
3729 wxSize frame_size
= m_action_window
->GetSize();
3730 if (frame_size
.x
<= m_action_offset
.x
)
3731 m_action_offset
.x
= 30;
3736 m_action
= actionDragToolbarPane
;
3737 m_action_window
= pane_info
->window
;
3741 else if (m_action
== actionDragFloatingPane
)
3743 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3744 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3745 pt
.y
- m_action_offset
.y
);
3747 else if (m_action
== actionDragToolbarPane
)
3749 wxPaneInfo
& pane
= GetPane(m_action_window
);
3750 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3752 pane
.state
|= wxPaneInfo::actionPane
;
3754 wxPoint pt
= event
.GetPosition();
3755 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3757 // if DoDrop() decided to float the pane, set up
3758 // the floating pane's initial position
3759 if (pane
.IsFloating())
3761 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3762 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3763 pt
.y
- m_action_offset
.y
);
3766 // this will do the actiual move operation;
3767 // in the case that the pane has been floated,
3768 // this call will create the floating pane
3769 // and do the reparenting
3772 // if the pane has been floated, change the mouse
3773 // action actionDragFloatingPane so that subsequent
3774 // EVT_MOTION() events will move the floating pane
3775 if (pane
.IsFloating())
3777 pane
.state
&= ~wxPaneInfo::actionPane
;
3778 m_action
= actionDragFloatingPane
;
3779 m_action_window
= pane
.frame
;
3784 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3785 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3787 if (part
!= m_hover_button
)
3789 // make the old button normal
3791 UpdateButtonOnScreen(m_hover_button
, event
);
3793 // mouse is over a button, so repaint the
3794 // button in hover mode
3795 UpdateButtonOnScreen(part
, event
);
3796 m_hover_button
= part
;
3803 m_hover_button
= NULL
;
3814 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3818 m_hover_button
= NULL
;
3823 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3825 // when a child pane has it's focus set, we should change the
3826 // pane's active state to reflect this. (this is only true if
3827 // active panes are allowed by the owner)
3828 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3830 if (GetPane(event
.GetWindow()).IsOk())
3832 SetActivePane(m_panes
, event
.GetWindow());
3841 // OnPaneButton() is an event handler that is called
3842 // when a pane button has been pressed.
3843 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& evt
)
3845 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3847 wxPaneInfo
& pane
= *(evt
.pane
);
3849 if (evt
.button
== wxPaneInfo::buttonClose
)
3851 // fire pane close event
3852 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3853 e
.SetPane(evt
.pane
);
3862 else if (evt
.button
== wxPaneInfo::buttonPin
)
3864 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&