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"
34 #include "wx/settings.h"
36 #include "wx/dcclient.h"
37 #include "wx/dcscreen.h"
38 #include "wx/toolbar.h"
43 WX_CHECK_BUILD_OPTIONS("wxAUI")
45 #include "wx/arrimpl.cpp"
46 WX_DECLARE_OBJARRAY(wxRect
, wxAuiRectArray
);
47 WX_DEFINE_OBJARRAY(wxAuiRectArray
)
48 WX_DEFINE_OBJARRAY(wxAuiDockUIPartArray
)
49 WX_DEFINE_OBJARRAY(wxAuiDockInfoArray
)
50 WX_DEFINE_OBJARRAY(wxAuiPaneButtonArray
)
51 WX_DEFINE_OBJARRAY(wxAuiPaneInfoArray
)
53 wxAuiPaneInfo wxAuiNullPaneInfo
;
54 wxAuiDockInfo wxAuiNullDockInfo
;
55 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_BUTTON
)
56 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_CLOSE
)
57 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_MAXIMIZE
)
58 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_RESTORE
)
59 DEFINE_EVENT_TYPE(wxEVT_AUI_RENDER
)
60 DEFINE_EVENT_TYPE(wxEVT_AUI_FIND_MANAGER
)
63 // a few defines to avoid nameclashes
64 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
66 #include "wx/mac/private.h"
69 IMPLEMENT_DYNAMIC_CLASS(wxAuiManagerEvent
, wxEvent
)
70 IMPLEMENT_CLASS(wxAuiManager
, wxEvtHandler
)
74 const int auiToolBarLayer
= 10;
77 class wxPseudoTransparentFrame
: public wxFrame
80 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
81 wxWindowID id
= wxID_ANY
,
82 const wxString
& title
= wxEmptyString
,
83 const wxPoint
& pos
= wxDefaultPosition
,
84 const wxSize
& size
= wxDefaultSize
,
85 long style
= wxDEFAULT_FRAME_STYLE
,
86 const wxString
&name
= wxT("frame"))
87 : wxFrame(parent
, id
, title
, pos
, size
, style
| wxFRAME_SHAPED
, name
)
89 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
96 m_CanSetShape
= false; // have to wait for window create event on GTK
100 m_Region
= wxRegion(0, 0, 0, 0);
104 virtual bool SetTransparent(wxByte alpha
)
108 int w
=100; // some defaults
110 GetClientSize(&w
, &h
);
116 // m_Region.Union(0, 0, 1, m_MaxWidth);
119 for (int y
=0; y
<m_MaxHeight
; y
++)
121 // Reverse the order of the bottom 4 bits
122 int j
=((y
&8)?1:0)|((y
&4)?2:0)|((y
&2)?4:0)|((y
&1)?8:0);
123 if ((j
*16+8)<m_Amount
)
124 m_Region
.Union(0, y
, m_MaxWidth
, 1);
133 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
137 if (m_Region
.IsEmpty())
141 dc
.SetBrush(wxColour(128, 192, 255));
143 dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
145 dc
.SetPen(*wxTRANSPARENT_PEN
);
147 wxRegionIterator
upd(GetUpdateRegion()); // get the update rect list
151 wxRect
rect(upd
.GetRect());
152 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
159 void OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
))
166 void OnSize(wxSizeEvent
& event
)
168 // We sometimes get surplus size events
169 if ((event
.GetSize().GetWidth() == m_lastWidth
) &&
170 (event
.GetSize().GetHeight() == m_lastHeight
))
175 m_lastWidth
= event
.GetSize().GetWidth();
176 m_lastHeight
= event
.GetSize().GetHeight();
178 SetTransparent(m_Amount
);
179 m_Region
.Intersect(0, 0, event
.GetSize().GetWidth(),
180 event
.GetSize().GetHeight());
191 int m_lastWidth
,m_lastHeight
;
195 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
196 DECLARE_EVENT_TABLE()
200 IMPLEMENT_DYNAMIC_CLASS(wxPseudoTransparentFrame
, wxFrame
)
202 BEGIN_EVENT_TABLE(wxPseudoTransparentFrame
, wxFrame
)
203 EVT_PAINT(wxPseudoTransparentFrame::OnPaint
)
204 EVT_SIZE(wxPseudoTransparentFrame::OnSize
)
206 EVT_WINDOW_CREATE(wxPseudoTransparentFrame::OnWindowCreate
)
211 // -- static utility functions --
213 static wxBitmap
wxPaneCreateStippleBitmap()
215 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
216 wxImage
img(2,2,data
,true);
217 return wxBitmap(img
);
220 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
222 wxBitmap stipple
= wxPaneCreateStippleBitmap();
223 wxBrush
brush(stipple
);
225 dc
.SetPen(*wxTRANSPARENT_PEN
);
227 dc
.SetLogicalFunction(wxXOR
);
228 dc
.DrawRectangle(rect
);
233 // CopyDocksAndPanes() - this utility function creates copies of
234 // the dock and pane info. wxAuiDockInfo's usually contain pointers
235 // to wxAuiPaneInfo classes, thus this function is necessary to reliably
236 // reconstruct that relationship in the new dock info and pane info arrays
238 static void CopyDocksAndPanes(wxAuiDockInfoArray
& dest_docks
,
239 wxAuiPaneInfoArray
& dest_panes
,
240 const wxAuiDockInfoArray
& src_docks
,
241 const wxAuiPaneInfoArray
& src_panes
)
243 dest_docks
= src_docks
;
244 dest_panes
= src_panes
;
245 int i
, j
, k
, dock_count
, pc1
, pc2
;
246 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
248 wxAuiDockInfo
& dock
= dest_docks
.Item(i
);
249 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
250 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
251 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
252 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
256 // GetMaxLayer() is an internal function which returns
257 // the highest layer inside the specified dock
258 static int GetMaxLayer(const wxAuiDockInfoArray
& docks
,
261 int i
, dock_count
, max_layer
= 0;
262 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
264 wxAuiDockInfo
& dock
= docks
.Item(i
);
265 if (dock
.dock_direction
== dock_direction
&&
266 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
267 max_layer
= dock
.dock_layer
;
273 // GetMaxRow() is an internal function which returns
274 // the highest layer inside the specified dock
275 static int GetMaxRow(const wxAuiPaneInfoArray
& panes
, int direction
, int layer
)
277 int i
, pane_count
, max_row
= 0;
278 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
280 wxAuiPaneInfo
& pane
= panes
.Item(i
);
281 if (pane
.dock_direction
== direction
&&
282 pane
.dock_layer
== layer
&&
283 pane
.dock_row
> max_row
)
284 max_row
= pane
.dock_row
;
291 // DoInsertDockLayer() is an internal function that inserts a new dock
292 // layer by incrementing all existing dock layer values by one
293 static void DoInsertDockLayer(wxAuiPaneInfoArray
& panes
,
298 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
300 wxAuiPaneInfo
& pane
= panes
.Item(i
);
301 if (!pane
.IsFloating() &&
302 pane
.dock_direction
== dock_direction
&&
303 pane
.dock_layer
>= dock_layer
)
308 // DoInsertDockLayer() is an internal function that inserts a new dock
309 // row by incrementing all existing dock row values by one
310 static void DoInsertDockRow(wxAuiPaneInfoArray
& panes
,
316 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
318 wxAuiPaneInfo
& pane
= panes
.Item(i
);
319 if (!pane
.IsFloating() &&
320 pane
.dock_direction
== dock_direction
&&
321 pane
.dock_layer
== dock_layer
&&
322 pane
.dock_row
>= dock_row
)
327 // DoInsertDockLayer() is an internal function that inserts a space for
328 // another dock pane by incrementing all existing dock row values by one
329 static void DoInsertPane(wxAuiPaneInfoArray
& panes
,
336 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
338 wxAuiPaneInfo
& pane
= panes
.Item(i
);
339 if (!pane
.IsFloating() &&
340 pane
.dock_direction
== dock_direction
&&
341 pane
.dock_layer
== dock_layer
&&
342 pane
.dock_row
== dock_row
&&
343 pane
.dock_pos
>= dock_pos
)
348 // FindDocks() is an internal function that returns a list of docks which meet
349 // the specified conditions in the parameters and returns a sorted array
350 // (sorted by layer and then row)
351 static void FindDocks(wxAuiDockInfoArray
& docks
,
355 wxAuiDockInfoPtrArray
& arr
)
357 int begin_layer
= dock_layer
;
358 int end_layer
= dock_layer
;
359 int begin_row
= dock_row
;
360 int end_row
= dock_row
;
361 int dock_count
= docks
.GetCount();
362 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
364 // discover the maximum dock layer and the max row
365 for (i
= 0; i
< dock_count
; ++i
)
367 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
368 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
371 // if no dock layer was specified, search all dock layers
372 if (dock_layer
== -1)
375 end_layer
= max_layer
;
378 // if no dock row was specified, search all dock row
387 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
388 for (row
= begin_row
; row
<= end_row
; ++row
)
389 for (i
= 0; i
< dock_count
; ++i
)
391 wxAuiDockInfo
& d
= docks
.Item(i
);
392 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
394 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
400 // FindPaneInDock() looks up a specified window pointer inside a dock.
401 // If found, the corresponding wxAuiPaneInfo pointer is returned, otherwise NULL.
402 static wxAuiPaneInfo
* FindPaneInDock(const wxAuiDockInfo
& dock
, wxWindow
* window
)
404 int i
, count
= dock
.panes
.GetCount();
405 for (i
= 0; i
< count
; ++i
)
407 wxAuiPaneInfo
* p
= dock
.panes
.Item(i
);
408 if (p
->window
== window
)
414 // RemovePaneFromDocks() removes a pane window from all docks
415 // with a possible exception specified by parameter "ex_cept"
416 static void RemovePaneFromDocks(wxAuiDockInfoArray
& docks
,
418 wxAuiDockInfo
* ex_cept
= NULL
)
421 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
423 wxAuiDockInfo
& d
= docks
.Item(i
);
426 wxAuiPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
432 // RenumberDockRows() takes a dock and assigns sequential numbers
433 // to existing rows. Basically it takes out the gaps; so if a
434 // dock has rows with numbers 0,2,5, they will become 0,1,2
435 static void RenumberDockRows(wxAuiDockInfoPtrArray
& docks
)
437 int i
, dock_count
, j
, pane_count
;
438 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
440 wxAuiDockInfo
& dock
= *docks
.Item(i
);
442 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
443 dock
.panes
.Item(j
)->dock_row
= i
;
448 // SetActivePane() sets the active pane, as well as cycles through
449 // every other pane and makes sure that all others' active flags
451 static void SetActivePane(wxAuiPaneInfoArray
& panes
, wxWindow
* active_pane
)
454 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
456 wxAuiPaneInfo
& pane
= panes
.Item(i
);
457 pane
.state
&= ~wxAuiPaneInfo::optionActive
;
458 if (pane
.window
== active_pane
)
459 pane
.state
|= wxAuiPaneInfo::optionActive
;
464 // this function is used to sort panes by dock position
465 static int PaneSortFunc(wxAuiPaneInfo
** p1
, wxAuiPaneInfo
** p2
)
467 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
471 // -- wxAuiManager class implementation --
474 BEGIN_EVENT_TABLE(wxAuiManager
, wxEvtHandler
)
475 EVT_AUI_PANE_BUTTON(wxAuiManager::OnPaneButton
)
476 EVT_AUI_RENDER(wxAuiManager::OnRender
)
477 EVT_PAINT(wxAuiManager::OnPaint
)
478 EVT_ERASE_BACKGROUND(wxAuiManager::OnEraseBackground
)
479 EVT_SIZE(wxAuiManager::OnSize
)
480 EVT_SET_CURSOR(wxAuiManager::OnSetCursor
)
481 EVT_LEFT_DOWN(wxAuiManager::OnLeftDown
)
482 EVT_LEFT_UP(wxAuiManager::OnLeftUp
)
483 EVT_MOTION(wxAuiManager::OnMotion
)
484 EVT_LEAVE_WINDOW(wxAuiManager::OnLeaveWindow
)
485 EVT_CHILD_FOCUS(wxAuiManager::OnChildFocus
)
486 EVT_AUI_FIND_MANAGER(wxAuiManager::OnFindManager
)
487 EVT_TIMER(101, wxAuiManager::OnHintFadeTimer
)
491 wxAuiManager::wxAuiManager(wxWindow
* managed_wnd
, unsigned int flags
)
493 m_action
= actionNone
;
494 m_last_mouse_move
= wxPoint();
495 m_hover_button
= NULL
;
496 m_art
= new wxAuiDefaultDockArt
;
500 m_has_maximized
= false;
502 m_dock_constraint_x
= 0.3;
503 m_dock_constraint_y
= 0.3;
508 SetManagedWindow(managed_wnd
);
512 wxAuiManager::~wxAuiManager()
517 // creates a floating frame for the windows
518 wxAuiFloatingFrame
* wxAuiManager::CreateFloatingFrame(wxWindow
* parent
,
519 const wxAuiPaneInfo
& pane_info
)
521 return new wxAuiFloatingFrame(parent
, this, pane_info
);
524 // GetPane() looks up a wxAuiPaneInfo structure based
525 // on the supplied window pointer. Upon failure, GetPane()
526 // returns an empty wxAuiPaneInfo, a condition which can be checked
527 // by calling wxAuiPaneInfo::IsOk().
529 // The pane info's structure may then be modified. Once a pane's
530 // info is modified, wxAuiManager::Update() must be called to
531 // realize the changes in the UI.
533 wxAuiPaneInfo
& wxAuiManager::GetPane(wxWindow
* window
)
536 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
538 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
539 if (p
.window
== window
)
542 return wxAuiNullPaneInfo
;
545 // this version of GetPane() looks up a pane based on a
546 // 'pane name', see above comment for more info
547 wxAuiPaneInfo
& wxAuiManager::GetPane(const wxString
& name
)
550 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
552 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
556 return wxAuiNullPaneInfo
;
559 // GetAllPanes() returns a reference to all the pane info structures
560 wxAuiPaneInfoArray
& wxAuiManager::GetAllPanes()
565 // HitTest() is an internal function which determines
566 // which UI item the specified coordinates are over
567 // (x,y) specify a position in client coordinates
568 wxAuiDockUIPart
* wxAuiManager::HitTest(int x
, int y
)
570 wxAuiDockUIPart
* result
= NULL
;
573 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
575 wxAuiDockUIPart
* item
= &m_uiparts
.Item(i
);
577 // we are not interested in typeDock, because this space
578 // isn't used to draw anything, just for measurements;
579 // besides, the entire dock area is covered with other
580 // rectangles, which we are interested in.
581 if (item
->type
== wxAuiDockUIPart::typeDock
)
584 // if we already have a hit on a more specific item, we are not
585 // interested in a pane hit. If, however, we don't already have
586 // a hit, returning a pane hit is necessary for some operations
587 if ((item
->type
== wxAuiDockUIPart::typePane
||
588 item
->type
== wxAuiDockUIPart::typePaneBorder
) && result
)
591 // if the point is inside the rectangle, we have a hit
592 if (item
->rect
.Contains(x
,y
))
600 // SetFlags() and GetFlags() allow the owner to set various
601 // options which are global to wxAuiManager
602 void wxAuiManager::SetFlags(unsigned int flags
)
604 // find out if we have to call UpdateHintWindowConfig()
605 bool update_hint_wnd
= false;
606 unsigned int hint_mask
= wxAUI_MGR_TRANSPARENT_HINT
|
607 wxAUI_MGR_VENETIAN_BLINDS_HINT
|
608 wxAUI_MGR_RECTANGLE_HINT
;
609 if ((flags
& hint_mask
) != (m_flags
& hint_mask
))
610 update_hint_wnd
= true;
618 UpdateHintWindowConfig();
622 unsigned int wxAuiManager::GetFlags() const
628 // don't use these anymore as they are deprecated
629 // use Set/GetManagedFrame() instead
630 void wxAuiManager::SetFrame(wxFrame
* frame
)
632 SetManagedWindow((wxWindow
*)frame
);
635 wxFrame
* wxAuiManager::GetFrame() const
637 return (wxFrame
*)m_frame
;
641 // this function will return the aui manager for a given
642 // window. The |window| parameter should be any child window
643 // or grand-child window (and so on) of the frame/window
644 // managed by wxAuiManager. The |window| parameter does not
645 // need to be managed by the manager itself.
646 wxAuiManager
* wxAuiManager::GetManager(wxWindow
* window
)
648 wxAuiManagerEvent
evt(wxEVT_AUI_FIND_MANAGER
);
649 evt
.SetManager(NULL
);
650 evt
.ResumePropagation(wxEVENT_PROPAGATE_MAX
);
651 if (!window
->ProcessEvent(evt
))
654 return evt
.GetManager();
658 void wxAuiManager::UpdateHintWindowConfig()
660 // find out if the the system can do transparent frames
661 bool can_do_transparent
= false;
663 wxWindow
* w
= m_frame
;
666 if (w
->IsKindOf(CLASSINFO(wxFrame
)))
668 wxFrame
* f
= static_cast<wxFrame
*>(w
);
669 can_do_transparent
= f
->CanSetTransparent();
676 // if there is an existing hint window, delete it
679 m_hint_wnd
->Destroy();
686 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) && can_do_transparent
)
688 // Make a window to use for a transparent hint
689 #if defined(__WXMSW__) || defined(__WXGTK__)
690 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
,
691 wxDefaultPosition
, wxSize(1,1),
692 wxFRAME_TOOL_WINDOW
|
693 wxFRAME_FLOAT_ON_PARENT
|
697 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
698 #elif defined(__WXMAC__)
699 // Using a miniframe with float and tool styles keeps the parent
700 // frame activated and highlighted as such...
701 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
,
702 wxDefaultPosition
, wxSize(1,1),
703 wxFRAME_FLOAT_ON_PARENT
704 | wxFRAME_TOOL_WINDOW
);
706 // Can't set the bg colour of a Frame in wxMac
707 wxPanel
* p
= new wxPanel(m_hint_wnd
);
709 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
710 // color that is really hard to see, especially transparent.
711 // Until a better system color is decided upon we'll just use
713 p
->SetBackgroundColour(*wxBLUE
);
719 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 ||
720 (m_flags
& wxAUI_MGR_VENETIAN_BLINDS_HINT
) != 0)
722 // system can't support transparent fade, or the venetian
723 // blinds effect was explicitly requested
724 m_hint_wnd
= new wxPseudoTransparentFrame(m_frame
,
729 wxFRAME_TOOL_WINDOW
|
730 wxFRAME_FLOAT_ON_PARENT
|
733 m_hint_fademax
= 128;
739 // SetManagedWindow() is usually called once when the frame
740 // manager class is being initialized. "frame" specifies
741 // the frame which should be managed by the frame mananger
742 void wxAuiManager::SetManagedWindow(wxWindow
* wnd
)
744 wxASSERT_MSG(wnd
, wxT("specified window must be non-NULL"));
747 m_frame
->PushEventHandler(this);
750 // if the owner is going to manage an MDI parent frame,
751 // we need to add the MDI client window as the default
754 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
756 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)m_frame
;
757 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
759 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
761 AddPane(client_window
,
762 wxAuiPaneInfo().Name(wxT("mdiclient")).
763 CenterPane().PaneBorder(false));
767 UpdateHintWindowConfig();
771 // UnInit() must be called, usually in the destructor
772 // of the frame class. If it is not called, usually this
773 // will result in a crash upon program exit
774 void wxAuiManager::UnInit()
778 m_frame
->RemoveEventHandler(this);
782 // GetManagedWindow() returns the window pointer being managed
783 wxWindow
* wxAuiManager::GetManagedWindow() const
788 wxAuiDockArt
* wxAuiManager::GetArtProvider() const
793 void wxAuiManager::ProcessMgrEvent(wxAuiManagerEvent
& event
)
795 // first, give the owner frame a chance to override
798 if (m_frame
->ProcessEvent(event
))
805 // SetArtProvider() instructs wxAuiManager to use the
806 // specified art provider for all drawing calls. This allows
807 // plugable look-and-feel features. The pointer that is
808 // passed to this method subsequently belongs to wxAuiManager,
809 // and is deleted in the frame manager destructor
810 void wxAuiManager::SetArtProvider(wxAuiDockArt
* art_provider
)
812 // delete the last art provider, if any
815 // assign the new art provider
816 m_art
= art_provider
;
820 bool wxAuiManager::AddPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
)
822 // check if the pane has a valid window
826 // check if the window is already managed by us
827 if (GetPane(pane_info
.window
).IsOk())
830 // check if the pane name already exists, this could reveal a
831 // bug in the library user's application
832 bool already_exists
= false;
833 if (!pane_info
.name
.empty() && GetPane(pane_info
.name
).IsOk())
835 wxFAIL_MSG(wxT("A pane with that name already exists in the manager!"));
836 already_exists
= true;
839 // if the new pane is docked then we should undo maximize
840 if (pane_info
.IsDocked())
841 RestoreMaximizedPane();
843 m_panes
.Add(pane_info
);
845 wxAuiPaneInfo
& pinfo
= m_panes
.Last();
847 // set the pane window
848 pinfo
.window
= window
;
851 // if the pane's name identifier is blank, create a random string
852 if (pinfo
.name
.empty() || already_exists
)
854 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
855 ((unsigned long)pinfo
.window
) & 0xffffffff,
856 (unsigned int)time(NULL
),
858 (unsigned int)GetTickCount(),
860 (unsigned int)clock(),
862 (unsigned long)m_panes
.GetCount());
865 // set initial proportion (if not already set)
866 if (pinfo
.dock_proportion
== 0)
867 pinfo
.dock_proportion
= 100000;
869 if (pinfo
.HasMaximizeButton())
871 wxAuiPaneButton button
;
872 button
.button_id
= wxAUI_BUTTON_MAXIMIZE_RESTORE
;
873 pinfo
.buttons
.Add(button
);
876 if (pinfo
.HasPinButton())
878 wxAuiPaneButton button
;
879 button
.button_id
= wxAUI_BUTTON_PIN
;
880 pinfo
.buttons
.Add(button
);
883 if (pinfo
.HasCloseButton())
885 wxAuiPaneButton button
;
886 button
.button_id
= wxAUI_BUTTON_CLOSE
;
887 pinfo
.buttons
.Add(button
);
890 if (pinfo
.best_size
== wxDefaultSize
&&
893 pinfo
.best_size
= pinfo
.window
->GetClientSize();
895 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
897 // GetClientSize() doesn't get the best size for
898 // a toolbar under some newer versions of wxWidgets,
899 // so use GetBestSize()
900 pinfo
.best_size
= pinfo
.window
->GetBestSize();
902 // for some reason, wxToolBar::GetBestSize() is returning
903 // a size that is a pixel shy of the correct amount.
904 // I believe this to be the correct action, until
905 // wxToolBar::GetBestSize() is fixed. Is this assumption
910 if (pinfo
.min_size
!= wxDefaultSize
)
912 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
913 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
914 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
915 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
922 bool wxAuiManager::AddPane(wxWindow
* window
,
924 const wxString
& caption
)
927 pinfo
.Caption(caption
);
930 case wxTOP
: pinfo
.Top(); break;
931 case wxBOTTOM
: pinfo
.Bottom(); break;
932 case wxLEFT
: pinfo
.Left(); break;
933 case wxRIGHT
: pinfo
.Right(); break;
934 case wxCENTER
: pinfo
.CenterPane(); break;
936 return AddPane(window
, pinfo
);
939 bool wxAuiManager::AddPane(wxWindow
* window
,
940 const wxAuiPaneInfo
& pane_info
,
941 const wxPoint
& drop_pos
)
943 if (!AddPane(window
, pane_info
))
946 wxAuiPaneInfo
& pane
= GetPane(window
);
948 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
953 bool wxAuiManager::InsertPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
,
956 // shift the panes around, depending on the insert level
957 switch (insert_level
)
959 case wxAUI_INSERT_PANE
:
960 DoInsertPane(m_panes
,
961 pane_info
.dock_direction
,
962 pane_info
.dock_layer
,
966 case wxAUI_INSERT_ROW
:
967 DoInsertDockRow(m_panes
,
968 pane_info
.dock_direction
,
969 pane_info
.dock_layer
,
972 case wxAUI_INSERT_DOCK
:
973 DoInsertDockLayer(m_panes
,
974 pane_info
.dock_direction
,
975 pane_info
.dock_layer
);
979 // if the window already exists, we are basically just moving/inserting the
980 // existing window. If it doesn't exist, we need to add it and insert it
981 wxAuiPaneInfo
& existing_pane
= GetPane(window
);
982 if (!existing_pane
.IsOk())
984 return AddPane(window
, pane_info
);
988 if (pane_info
.IsFloating())
990 existing_pane
.Float();
991 if (pane_info
.floating_pos
!= wxDefaultPosition
)
992 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
993 if (pane_info
.floating_size
!= wxDefaultSize
)
994 existing_pane
.FloatingSize(pane_info
.floating_size
);
998 // if the new pane is docked then we should undo maximize
999 RestoreMaximizedPane();
1001 existing_pane
.Direction(pane_info
.dock_direction
);
1002 existing_pane
.Layer(pane_info
.dock_layer
);
1003 existing_pane
.Row(pane_info
.dock_row
);
1004 existing_pane
.Position(pane_info
.dock_pos
);
1012 // DetachPane() removes a pane from the frame manager. This
1013 // method will not destroy the window that is removed.
1014 bool wxAuiManager::DetachPane(wxWindow
* window
)
1017 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
1019 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1020 if (p
.window
== window
)
1024 // we have a floating frame which is being detached. We need to
1025 // reparent it to m_frame and destroy the floating frame
1028 p
.window
->SetSize(1,1);
1030 if (p
.frame
->IsShown())
1031 p
.frame
->Show(false);
1033 // reparent to m_frame and destroy the pane
1034 if (m_action_window
== p
.frame
)
1036 m_action_window
= NULL
;
1039 p
.window
->Reparent(m_frame
);
1040 p
.frame
->SetSizer(NULL
);
1045 // make sure there are no references to this pane in our uiparts,
1046 // just in case the caller doesn't call Update() immediately after
1047 // the DetachPane() call. This prevets obscure crashes which would
1048 // happen at window repaint if the caller forgets to call Update()
1050 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
1052 wxAuiDockUIPart
& part
= m_uiparts
.Item(pi
);
1053 if (part
.pane
== &p
)
1055 m_uiparts
.RemoveAt(pi
);
1062 m_panes
.RemoveAt(i
);
1069 // ClosePane() destroys or hides the pane depending on its
1071 void wxAuiManager::ClosePane(wxAuiPaneInfo
& pane_info
)
1073 // if we were maximized, restore
1074 if (pane_info
.IsMaximized())
1076 RestorePane(pane_info
);
1079 // first, hide the window
1080 if (pane_info
.window
&& pane_info
.window
->IsShown())
1082 pane_info
.window
->Show(false);
1085 // make sure that we are the parent of this window
1086 if (pane_info
.window
&& pane_info
.window
->GetParent() != m_frame
)
1088 pane_info
.window
->Reparent(m_frame
);
1091 // if we have a frame, destroy it
1092 if (pane_info
.frame
)
1094 pane_info
.frame
->Destroy();
1095 pane_info
.frame
= NULL
;
1098 // now we need to either destroy or hide the pane
1099 if (pane_info
.IsDestroyOnClose())
1101 wxWindow
* window
= pane_info
.window
;
1114 void wxAuiManager::MaximizePane(wxAuiPaneInfo
& pane_info
)
1118 // un-maximize and hide all other panes
1119 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1121 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1126 // save hidden state
1127 p
.SetFlag(wxAuiPaneInfo::savedHiddenState
,
1128 p
.HasFlag(wxAuiPaneInfo::optionHidden
));
1130 // hide the pane, because only the newly
1131 // maximized pane should show
1136 // mark ourselves maximized
1137 pane_info
.Maximize();
1139 m_has_maximized
= true;
1141 // last, show the window
1142 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1144 pane_info
.window
->Show(true);
1148 void wxAuiManager::RestorePane(wxAuiPaneInfo
& pane_info
)
1152 // restore all the panes
1153 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1155 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1158 p
.SetFlag(wxAuiPaneInfo::optionHidden
,
1159 p
.HasFlag(wxAuiPaneInfo::savedHiddenState
));
1163 // mark ourselves non-maximized
1164 pane_info
.Restore();
1165 m_has_maximized
= false;
1167 // last, show the window
1168 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1170 pane_info
.window
->Show(true);
1174 void wxAuiManager::RestoreMaximizedPane()
1178 // restore all the panes
1179 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1181 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1182 if (p
.IsMaximized())
1190 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
1191 // in the input string. This is an internal functions which is
1192 // used for saving perspectives
1193 static wxString
EscapeDelimiters(const wxString
& s
)
1196 result
.Alloc(s
.length());
1197 const wxChar
* ch
= s
.c_str();
1200 if (*ch
== wxT(';') || *ch
== wxT('|'))
1201 result
+= wxT('\\');
1208 wxString
wxAuiManager::SavePaneInfo(wxAuiPaneInfo
& pane
)
1210 wxString result
= wxT("name=");
1211 result
+= EscapeDelimiters(pane
.name
);
1214 result
+= wxT("caption=");
1215 result
+= EscapeDelimiters(pane
.caption
);
1218 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
1219 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
1220 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
1221 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
1222 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
1223 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
1224 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
1225 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
1226 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
1227 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
1228 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
1229 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
1230 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
1231 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
1232 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
1233 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
1238 // Load a "pane" with the pane infor settings in pane_part
1239 void wxAuiManager::LoadPaneInfo(wxString pane_part
, wxAuiPaneInfo
&pane
)
1241 // replace escaped characters so we can
1242 // split up the string easily
1243 pane_part
.Replace(wxT("\\|"), wxT("\a"));
1244 pane_part
.Replace(wxT("\\;"), wxT("\b"));
1248 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
1249 pane_part
= pane_part
.AfterFirst(wxT(';'));
1250 wxString val_name
= val_part
.BeforeFirst(wxT('='));
1251 wxString value
= val_part
.AfterFirst(wxT('='));
1252 val_name
.MakeLower();
1253 val_name
.Trim(true);
1254 val_name
.Trim(false);
1258 if (val_name
.empty())
1261 if (val_name
== wxT("name"))
1263 else if (val_name
== wxT("caption"))
1264 pane
.caption
= value
;
1265 else if (val_name
== wxT("state"))
1266 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1267 else if (val_name
== wxT("dir"))
1268 pane
.dock_direction
= wxAtoi(value
.c_str());
1269 else if (val_name
== wxT("layer"))
1270 pane
.dock_layer
= wxAtoi(value
.c_str());
1271 else if (val_name
== wxT("row"))
1272 pane
.dock_row
= wxAtoi(value
.c_str());
1273 else if (val_name
== wxT("pos"))
1274 pane
.dock_pos
= wxAtoi(value
.c_str());
1275 else if (val_name
== wxT("prop"))
1276 pane
.dock_proportion
= wxAtoi(value
.c_str());
1277 else if (val_name
== wxT("bestw"))
1278 pane
.best_size
.x
= wxAtoi(value
.c_str());
1279 else if (val_name
== wxT("besth"))
1280 pane
.best_size
.y
= wxAtoi(value
.c_str());
1281 else if (val_name
== wxT("minw"))
1282 pane
.min_size
.x
= wxAtoi(value
.c_str());
1283 else if (val_name
== wxT("minh"))
1284 pane
.min_size
.y
= wxAtoi(value
.c_str());
1285 else if (val_name
== wxT("maxw"))
1286 pane
.max_size
.x
= wxAtoi(value
.c_str());
1287 else if (val_name
== wxT("maxh"))
1288 pane
.max_size
.y
= wxAtoi(value
.c_str());
1289 else if (val_name
== wxT("floatx"))
1290 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1291 else if (val_name
== wxT("floaty"))
1292 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1293 else if (val_name
== wxT("floatw"))
1294 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1295 else if (val_name
== wxT("floath"))
1296 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1298 wxFAIL_MSG(wxT("Bad Perspective String"));
1302 // replace escaped characters so we can
1303 // split up the string easily
1304 pane
.name
.Replace(wxT("\a"), wxT("|"));
1305 pane
.name
.Replace(wxT("\b"), wxT(";"));
1306 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1307 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1308 pane_part
.Replace(wxT("\a"), wxT("|"));
1309 pane_part
.Replace(wxT("\b"), wxT(";"));
1315 // SavePerspective() saves all pane information as a single string.
1316 // This string may later be fed into LoadPerspective() to restore
1317 // all pane settings. This save and load mechanism allows an
1318 // exact pane configuration to be saved and restored at a later time
1320 wxString
wxAuiManager::SavePerspective()
1324 result
= wxT("layout2|");
1326 int pane_i
, pane_count
= m_panes
.GetCount();
1327 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1329 wxAuiPaneInfo
& pane
= m_panes
.Item(pane_i
);
1330 result
+= SavePaneInfo(pane
)+wxT("|");
1333 int dock_i
, dock_count
= m_docks
.GetCount();
1334 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1336 wxAuiDockInfo
& dock
= m_docks
.Item(dock_i
);
1338 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1339 dock
.dock_direction
, dock
.dock_layer
,
1340 dock
.dock_row
, dock
.size
);
1346 // LoadPerspective() loads a layout which was saved with SavePerspective()
1347 // If the "update" flag parameter is true, the GUI will immediately be updated
1349 bool wxAuiManager::LoadPerspective(const wxString
& layout
, bool update
)
1351 wxString input
= layout
;
1354 // check layout string version
1355 // 'layout1' = wxAUI 0.9.0 - wxAUI 0.9.2
1356 // 'layout2' = wxAUI 0.9.2 (wxWidgets 2.8)
1357 part
= input
.BeforeFirst(wxT('|'));
1358 input
= input
.AfterFirst(wxT('|'));
1361 if (part
!= wxT("layout2"))
1364 // mark all panes currently managed as docked and hidden
1365 int pane_i
, pane_count
= m_panes
.GetCount();
1366 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1367 m_panes
.Item(pane_i
).Dock().Hide();
1369 // clear out the dock array; this will be reconstructed
1372 // replace escaped characters so we can
1373 // split up the string easily
1374 input
.Replace(wxT("\\|"), wxT("\a"));
1375 input
.Replace(wxT("\\;"), wxT("\b"));
1381 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1382 input
= input
.AfterFirst(wxT('|'));
1383 pane_part
.Trim(true);
1385 // if the string is empty, we're done parsing
1386 if (pane_part
.empty())
1389 if (pane_part
.Left(9) == wxT("dock_size"))
1391 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1392 wxString value
= pane_part
.AfterFirst(wxT('='));
1394 long dir
, layer
, row
, size
;
1395 wxString piece
= val_name
.AfterFirst(wxT('('));
1396 piece
= piece
.BeforeLast(wxT(')'));
1397 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1398 piece
= piece
.AfterFirst(wxT(','));
1399 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1400 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1401 value
.ToLong(&size
);
1404 dock
.dock_direction
= dir
;
1405 dock
.dock_layer
= layer
;
1406 dock
.dock_row
= row
;
1412 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1413 // name so it can be called by external callers
1414 pane_part
.Replace(wxT("\a"), wxT("|"));
1415 pane_part
.Replace(wxT("\b"), wxT(";"));
1417 LoadPaneInfo(pane_part
, pane
);
1419 wxAuiPaneInfo
& p
= GetPane(pane
.name
);
1422 // the pane window couldn't be found
1423 // in the existing layout
1437 void wxAuiManager::GetPanePositionsAndSizes(wxAuiDockInfo
& dock
,
1438 wxArrayInt
& positions
,
1441 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1442 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1443 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1448 int offset
, action_pane
= -1;
1449 int pane_i
, pane_count
= dock
.panes
.GetCount();
1451 // find the pane marked as our action pane
1452 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1454 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1456 if (pane
.state
& wxAuiPaneInfo::actionPane
)
1458 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1459 action_pane
= pane_i
;
1463 // set up each panes default position, and
1464 // determine the size (width or height, depending
1465 // on the dock's orientation) of each pane
1466 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1468 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1469 positions
.Add(pane
.dock_pos
);
1472 if (pane
.HasBorder())
1473 size
+= (pane_border_size
*2);
1475 if (dock
.IsHorizontal())
1477 if (pane
.HasGripper() && !pane
.HasGripperTop())
1478 size
+= gripper_size
;
1479 size
+= pane
.best_size
.x
;
1483 if (pane
.HasGripper() && pane
.HasGripperTop())
1484 size
+= gripper_size
;
1486 if (pane
.HasCaption())
1487 size
+= caption_size
;
1488 size
+= pane
.best_size
.y
;
1494 // if there is no action pane, just return the default
1495 // positions (as specified in pane.pane_pos)
1496 if (action_pane
== -1)
1500 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1502 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1507 positions
[pane_i
] -= -amount
;
1509 offset
+= sizes
[pane_i
];
1512 // if the dock mode is fixed, make sure none of the panes
1513 // overlap; we will bump panes that overlap
1515 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1517 int amount
= positions
[pane_i
] - offset
;
1521 positions
[pane_i
] += -amount
;
1523 offset
+= sizes
[pane_i
];
1528 void wxAuiManager::LayoutAddPane(wxSizer
* cont
,
1529 wxAuiDockInfo
& dock
,
1530 wxAuiPaneInfo
& pane
,
1531 wxAuiDockUIPartArray
& uiparts
,
1534 wxAuiDockUIPart part
;
1535 wxSizerItem
* sizer_item
;
1537 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1538 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1539 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1540 int pane_button_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BUTTON_SIZE
);
1542 // find out the orientation of the item (orientation for panes
1543 // is the same as the dock's orientation)
1545 if (dock
.IsHorizontal())
1546 orientation
= wxHORIZONTAL
;
1548 orientation
= wxVERTICAL
;
1550 // this variable will store the proportion
1551 // value that the pane will receive
1552 int pane_proportion
= pane
.dock_proportion
;
1554 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1555 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1557 if (pane
.HasGripper())
1559 if (pane
.HasGripperTop())
1560 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1562 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1564 part
.type
= wxAuiDockUIPart::typeGripper
;
1568 part
.orientation
= orientation
;
1569 part
.cont_sizer
= horz_pane_sizer
;
1570 part
.sizer_item
= sizer_item
;
1574 if (pane
.HasCaption())
1576 // create the caption sizer
1577 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1579 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1581 part
.type
= wxAuiDockUIPart::typeCaption
;
1585 part
.orientation
= orientation
;
1586 part
.cont_sizer
= vert_pane_sizer
;
1587 part
.sizer_item
= sizer_item
;
1588 int caption_part_idx
= uiparts
.GetCount();
1591 // add pane buttons to the caption
1592 int i
, button_count
;
1593 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1594 i
< button_count
; ++i
)
1596 wxAuiPaneButton
& button
= pane
.buttons
.Item(i
);
1598 sizer_item
= caption_sizer
->Add(pane_button_size
,
1602 part
.type
= wxAuiDockUIPart::typePaneButton
;
1605 part
.button
= &button
;
1606 part
.orientation
= orientation
;
1607 part
.cont_sizer
= caption_sizer
;
1608 part
.sizer_item
= sizer_item
;
1612 // if we have buttons, add a little space to the right
1613 // of them to ease visual crowding
1614 if (button_count
>= 1)
1616 caption_sizer
->Add(3,1);
1619 // add the caption sizer
1620 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1622 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1625 // add the pane window itself
1628 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1632 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1633 // Don't do this because it breaks the pane size in floating windows
1634 // BIW: Right now commenting this out is causing problems with
1635 // an mdi client window as the center pane.
1636 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1639 part
.type
= wxAuiDockUIPart::typePane
;
1643 part
.orientation
= orientation
;
1644 part
.cont_sizer
= vert_pane_sizer
;
1645 part
.sizer_item
= sizer_item
;
1649 // determine if the pane should have a minimum size; if the pane is
1650 // non-resizable (fixed) then we must set a minimum size. Alternatively,
1651 // if the pane.min_size is set, we must use that value as well
1653 wxSize min_size
= pane
.min_size
;
1656 if (min_size
== wxDefaultSize
)
1658 min_size
= pane
.best_size
;
1659 pane_proportion
= 0;
1663 if (min_size
!= wxDefaultSize
)
1665 vert_pane_sizer
->SetItemMinSize(
1666 vert_pane_sizer
->GetChildren().GetCount()-1,
1667 min_size
.x
, min_size
.y
);
1671 // add the verticle sizer (caption, pane window) to the
1672 // horizontal sizer (gripper, verticle sizer)
1673 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1675 // finally, add the pane sizer to the dock sizer
1677 if (pane
.HasBorder())
1679 // allowing space for the pane's border
1680 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1681 wxEXPAND
| wxALL
, pane_border_size
);
1683 part
.type
= wxAuiDockUIPart::typePaneBorder
;
1687 part
.orientation
= orientation
;
1688 part
.cont_sizer
= cont
;
1689 part
.sizer_item
= sizer_item
;
1694 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1698 void wxAuiManager::LayoutAddDock(wxSizer
* cont
,
1699 wxAuiDockInfo
& dock
,
1700 wxAuiDockUIPartArray
& uiparts
,
1703 wxSizerItem
* sizer_item
;
1704 wxAuiDockUIPart part
;
1706 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
1707 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1709 // resizable bottom and right docks have a sash before them
1710 if (!m_has_maximized
&& !dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1711 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1713 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1715 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1716 part
.orientation
= orientation
;
1720 part
.cont_sizer
= cont
;
1721 part
.sizer_item
= sizer_item
;
1725 // create the sizer for the dock
1726 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1728 // add each pane to the dock
1729 bool has_maximized_pane
= false;
1730 int pane_i
, pane_count
= dock
.panes
.GetCount();
1734 wxArrayInt pane_positions
, pane_sizes
;
1736 // figure out the real pane positions we will
1737 // use, without modifying the each pane's pane_pos member
1738 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1741 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1743 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1744 int pane_pos
= pane_positions
.Item(pane_i
);
1746 if (pane
.IsMaximized())
1747 has_maximized_pane
= true;
1750 int amount
= pane_pos
- offset
;
1753 if (dock
.IsVertical())
1754 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1756 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1758 part
.type
= wxAuiDockUIPart::typeBackground
;
1762 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1763 part
.cont_sizer
= dock_sizer
;
1764 part
.sizer_item
= sizer_item
;
1770 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1772 offset
+= pane_sizes
.Item(pane_i
);
1775 // at the end add a very small stretchable background area
1776 sizer_item
= dock_sizer
->Add(0,0, 1, wxEXPAND
);
1778 part
.type
= wxAuiDockUIPart::typeBackground
;
1782 part
.orientation
= orientation
;
1783 part
.cont_sizer
= dock_sizer
;
1784 part
.sizer_item
= sizer_item
;
1789 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1791 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1793 if (pane
.IsMaximized())
1794 has_maximized_pane
= true;
1796 // if this is not the first pane being added,
1797 // we need to add a pane sizer
1798 if (!m_has_maximized
&& pane_i
> 0)
1800 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1802 part
.type
= wxAuiDockUIPart::typePaneSizer
;
1804 part
.pane
= dock
.panes
.Item(pane_i
-1);
1806 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1807 part
.cont_sizer
= dock_sizer
;
1808 part
.sizer_item
= sizer_item
;
1812 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1816 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
|| has_maximized_pane
)
1817 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1819 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1821 part
.type
= wxAuiDockUIPart::typeDock
;
1825 part
.orientation
= orientation
;
1826 part
.cont_sizer
= cont
;
1827 part
.sizer_item
= sizer_item
;
1830 if (dock
.IsHorizontal())
1831 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1833 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1835 // top and left docks have a sash after them
1836 if (!m_has_maximized
&&
1838 (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1839 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1841 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1843 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1847 part
.orientation
= orientation
;
1848 part
.cont_sizer
= cont
;
1849 part
.sizer_item
= sizer_item
;
1854 wxSizer
* wxAuiManager::LayoutAll(wxAuiPaneInfoArray
& panes
,
1855 wxAuiDockInfoArray
& docks
,
1856 wxAuiDockUIPartArray
& uiparts
,
1859 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1861 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1862 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1863 wxSize cli_size
= m_frame
->GetClientSize();
1864 int i
, dock_count
, pane_count
;
1867 // empty all docks out
1868 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1870 wxAuiDockInfo
& dock
= docks
.Item(i
);
1872 // empty out all panes, as they will be readded below
1877 // always reset fixed docks' sizes, because
1878 // the contained windows may have been resized
1884 // iterate through all known panes, filing each
1885 // of them into the appropriate dock. If the
1886 // pane does not exist in the dock, add it
1887 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1889 wxAuiPaneInfo
& p
= panes
.Item(i
);
1891 // find any docks with the same dock direction, dock layer, and
1892 // dock row as the pane we are working on
1893 wxAuiDockInfo
* dock
;
1894 wxAuiDockInfoPtrArray arr
;
1895 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1897 if (arr
.GetCount() > 0)
1899 // found the right dock
1904 // dock was not found, so we need to create a new one
1906 d
.dock_direction
= p
.dock_direction
;
1907 d
.dock_layer
= p
.dock_layer
;
1908 d
.dock_row
= p
.dock_row
;
1910 dock
= &docks
.Last();
1914 if (p
.IsDocked() && p
.IsShown())
1916 // remove the pane from any existing docks except this one
1917 RemovePaneFromDocks(docks
, p
, dock
);
1919 // pane needs to be added to the dock,
1920 // if it doesn't already exist
1921 if (!FindPaneInDock(*dock
, p
.window
))
1922 dock
->panes
.Add(&p
);
1926 // remove the pane from any existing docks
1927 RemovePaneFromDocks(docks
, p
);
1932 // remove any empty docks
1933 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1935 if (docks
.Item(i
).panes
.GetCount() == 0)
1939 // configure the docks further
1940 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1942 wxAuiDockInfo
& dock
= docks
.Item(i
);
1943 int j
, dock_pane_count
= dock
.panes
.GetCount();
1945 // sort the dock pane array by the pane's
1946 // dock position (dock_pos), in ascending order
1947 dock
.panes
.Sort(PaneSortFunc
);
1949 // for newly created docks, set up their initial size
1954 for (j
= 0; j
< dock_pane_count
; ++j
)
1956 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
1957 wxSize pane_size
= pane
.best_size
;
1958 if (pane_size
== wxDefaultSize
)
1959 pane_size
= pane
.min_size
;
1960 if (pane_size
== wxDefaultSize
)
1961 pane_size
= pane
.window
->GetSize();
1963 if (dock
.IsHorizontal())
1964 size
= wxMax(pane_size
.y
, size
);
1966 size
= wxMax(pane_size
.x
, size
);
1969 // add space for the border (two times), but only
1970 // if at least one pane inside the dock has a pane border
1971 for (j
= 0; j
< dock_pane_count
; ++j
)
1973 if (dock
.panes
.Item(j
)->HasBorder())
1975 size
+= (pane_border_size
*2);
1980 // if pane is on the top or bottom, add the caption height,
1981 // but only if at least one pane inside the dock has a caption
1982 if (dock
.IsHorizontal())
1984 for (j
= 0; j
< dock_pane_count
; ++j
)
1986 if (dock
.panes
.Item(j
)->HasCaption())
1988 size
+= caption_size
;
1995 // new dock's size may not be more than the dock constraint
1996 // parameter specifies. See SetDockSizeConstraint()
1998 int max_dock_x_size
= (int)(m_dock_constraint_x
* ((double)cli_size
.x
));
1999 int max_dock_y_size
= (int)(m_dock_constraint_y
* ((double)cli_size
.y
));
2001 if (dock
.IsHorizontal())
2002 size
= wxMin(size
, max_dock_y_size
);
2004 size
= wxMin(size
, max_dock_x_size
);
2006 // absolute minimum size for a dock is 10 pixels
2014 // determine the dock's minimum size
2015 bool plus_border
= false;
2016 bool plus_caption
= false;
2017 int dock_min_size
= 0;
2018 for (j
= 0; j
< dock_pane_count
; ++j
)
2020 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2021 if (pane
.min_size
!= wxDefaultSize
)
2023 if (pane
.HasBorder())
2025 if (pane
.HasCaption())
2026 plus_caption
= true;
2027 if (dock
.IsHorizontal())
2029 if (pane
.min_size
.y
> dock_min_size
)
2030 dock_min_size
= pane
.min_size
.y
;
2034 if (pane
.min_size
.x
> dock_min_size
)
2035 dock_min_size
= pane
.min_size
.x
;
2041 dock_min_size
+= (pane_border_size
*2);
2042 if (plus_caption
&& dock
.IsHorizontal())
2043 dock_min_size
+= (caption_size
);
2045 dock
.min_size
= dock_min_size
;
2048 // if the pane's current size is less than it's
2049 // minimum, increase the dock's size to it's minimum
2050 if (dock
.size
< dock
.min_size
)
2051 dock
.size
= dock
.min_size
;
2054 // determine the dock's mode (fixed or proportional);
2055 // determine whether the dock has only toolbars
2056 bool action_pane_marked
= false;
2058 dock
.toolbar
= true;
2059 for (j
= 0; j
< dock_pane_count
; ++j
)
2061 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2062 if (!pane
.IsFixed())
2064 if (!pane
.IsToolbar())
2065 dock
.toolbar
= false;
2066 if (pane
.state
& wxAuiPaneInfo::actionPane
)
2067 action_pane_marked
= true;
2071 // if the dock mode is proportional and not fixed-pixel,
2072 // reassign the dock_pos to the sequential 0, 1, 2, 3;
2073 // e.g. remove gaps like 1, 2, 30, 500
2076 for (j
= 0; j
< dock_pane_count
; ++j
)
2078 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2083 // if the dock mode is fixed, and none of the panes
2084 // are being moved right now, make sure the panes
2085 // do not overlap each other. If they do, we will
2086 // adjust the positions of the panes
2087 if (dock
.fixed
&& !action_pane_marked
)
2089 wxArrayInt pane_positions
, pane_sizes
;
2090 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
2093 for (j
= 0; j
< dock_pane_count
; ++j
)
2095 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(j
));
2096 pane
.dock_pos
= pane_positions
[j
];
2098 int amount
= pane
.dock_pos
- offset
;
2102 pane
.dock_pos
+= -amount
;
2104 offset
+= pane_sizes
[j
];
2109 // discover the maximum dock layer
2111 for (i
= 0; i
< dock_count
; ++i
)
2112 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
2115 // clear out uiparts
2118 // create a bunch of box sizers,
2119 // from the innermost level outwards.
2120 wxSizer
* cont
= NULL
;
2121 wxSizer
* middle
= NULL
;
2125 for (layer
= 0; layer
<= max_layer
; ++layer
)
2127 wxAuiDockInfoPtrArray arr
;
2129 // find any docks in this layer
2130 FindDocks(docks
, -1, layer
, -1, arr
);
2132 // if there aren't any, skip to the next layer
2136 wxSizer
* old_cont
= cont
;
2138 // create a container which will hold this layer's
2139 // docks (top, bottom, left, right)
2140 cont
= new wxBoxSizer(wxVERTICAL
);
2143 // find any top docks in this layer
2144 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
2145 RenumberDockRows(arr
);
2148 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2149 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2153 // fill out the middle layer (which consists
2154 // of left docks, content area and right docks)
2156 middle
= new wxBoxSizer(wxHORIZONTAL
);
2158 // find any left docks in this layer
2159 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
2160 RenumberDockRows(arr
);
2163 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2164 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2167 // add content dock (or previous layer's sizer
2171 // find any center docks
2172 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
2175 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
2176 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2178 else if (!m_has_maximized
)
2180 // there are no center docks, add a background area
2181 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
2182 wxAuiDockUIPart part
;
2183 part
.type
= wxAuiDockUIPart::typeBackground
;
2187 part
.cont_sizer
= middle
;
2188 part
.sizer_item
= sizer_item
;
2194 middle
->Add(old_cont
, 1, wxEXPAND
);
2197 // find any right docks in this layer
2198 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
2199 RenumberDockRows(arr
);
2202 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2203 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2206 cont
->Add(middle
, 1, wxEXPAND
);
2210 // find any bottom docks in this layer
2211 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
2212 RenumberDockRows(arr
);
2215 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2216 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2223 // no sizer available, because there are no docks,
2224 // therefore we will create a simple background area
2225 cont
= new wxBoxSizer(wxVERTICAL
);
2226 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
2227 wxAuiDockUIPart part
;
2228 part
.type
= wxAuiDockUIPart::typeBackground
;
2232 part
.cont_sizer
= middle
;
2233 part
.sizer_item
= sizer_item
;
2237 container
->Add(cont
, 1, wxEXPAND
);
2242 // SetDockSizeConstraint() allows the dock constraints to be set. For example,
2243 // specifying values of 0.5, 0.5 will mean that upon dock creation, a dock may
2244 // not be larger than half of the window's size
2246 void wxAuiManager::SetDockSizeConstraint(double width_pct
, double height_pct
)
2248 m_dock_constraint_x
= wxMax(0.0, wxMin(1.0, width_pct
));
2249 m_dock_constraint_y
= wxMax(0.0, wxMin(1.0, height_pct
));
2252 void wxAuiManager::GetDockSizeConstraint(double* width_pct
, double* height_pct
) const
2255 *width_pct
= m_dock_constraint_x
;
2258 *height_pct
= m_dock_constraint_y
;
2263 // Update() updates the layout. Whenever changes are made to
2264 // one or more panes, this function should be called. It is the
2265 // external entry point for running the layout engine.
2267 void wxAuiManager::Update()
2270 int i
, pane_count
= m_panes
.GetCount();
2273 // destroy floating panes which have been
2274 // redocked or are becoming non-floating
2275 for (i
= 0; i
< pane_count
; ++i
)
2277 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2279 if (!p
.IsFloating() && p
.frame
)
2281 // because the pane is no longer in a floating, we need to
2282 // reparent it to m_frame and destroy the floating frame
2285 p
.window
->SetSize(1,1);
2288 // the following block is a workaround for bug #1531361
2289 // (see wxWidgets sourceforge page). On wxGTK (only), when
2290 // a frame is shown/hidden, a move event unfortunately
2291 // also gets fired. Because we may be dragging around
2292 // a pane, we need to cancel that action here to prevent
2293 // a spurious crash.
2294 if (m_action_window
== p
.frame
)
2296 if (wxWindow::GetCapture() == m_frame
)
2297 m_frame
->ReleaseMouse();
2298 m_action
= actionNone
;
2299 m_action_window
= NULL
;
2303 if (p
.frame
->IsShown())
2304 p
.frame
->Show(false);
2306 // reparent to m_frame and destroy the pane
2307 if (m_action_window
== p
.frame
)
2309 m_action_window
= NULL
;
2312 p
.window
->Reparent(m_frame
);
2313 p
.frame
->SetSizer(NULL
);
2320 // delete old sizer first
2321 m_frame
->SetSizer(NULL
);
2323 // create a layout for all of the panes
2324 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
2326 // hide or show panes as necessary,
2327 // and float panes as necessary
2328 for (i
= 0; i
< pane_count
; ++i
)
2330 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2334 if (p
.frame
== NULL
)
2336 // we need to create a frame for this
2337 // pane, which has recently been floated
2338 wxAuiFloatingFrame
* frame
= CreateFloatingFrame(m_frame
, p
);
2340 // on MSW and Mac, if the owner desires transparent dragging, and
2341 // the dragging is happening right now, then the floating
2342 // window should have this style by default
2343 if (m_action
== actionDragFloatingPane
&&
2344 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2345 frame
->SetTransparent(150);
2347 frame
->SetPaneWindow(p
);
2350 if (p
.IsShown() && !frame
->IsShown())
2355 // frame already exists, make sure it's position
2356 // and size reflect the information in wxAuiPaneInfo
2357 if (p
.frame
->GetPosition() != p
.floating_pos
)
2359 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2360 p
.floating_size
.x
, p
.floating_size
.y
,
2361 wxSIZE_USE_EXISTING
);
2363 p.frame->SetSize(p.floating_pos.x, p.floating_pos.y,
2364 wxDefaultCoord, wxDefaultCoord,
2365 wxSIZE_USE_EXISTING);
2366 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2370 if (p
.frame
->IsShown() != p
.IsShown())
2371 p
.frame
->Show(p
.IsShown());
2376 if (p
.window
->IsShown() != p
.IsShown())
2377 p
.window
->Show(p
.IsShown());
2380 // if "active panes" are no longer allowed, clear
2381 // any optionActive values from the pane states
2382 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2384 p
.state
&= ~wxAuiPaneInfo::optionActive
;
2389 // keep track of the old window rectangles so we can
2390 // refresh those windows whose rect has changed
2391 wxAuiRectArray old_pane_rects
;
2392 for (i
= 0; i
< pane_count
; ++i
)
2395 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2397 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2400 old_pane_rects
.Add(r
);
2406 // apply the new sizer
2407 m_frame
->SetSizer(sizer
);
2408 m_frame
->SetAutoLayout(false);
2413 // now that the frame layout is done, we need to check
2414 // the new pane rectangles against the old rectangles that
2415 // we saved a few lines above here. If the rectangles have
2416 // changed, the corresponding panes must also be updated
2417 for (i
= 0; i
< pane_count
; ++i
)
2419 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2420 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2422 if (p
.rect
!= old_pane_rects
[i
])
2424 p
.window
->Refresh();
2433 // set frame's minimum size
2436 // N.B. More work needs to be done on frame minimum sizes;
2437 // this is some intresting code that imposes the minimum size,
2438 // but we may want to include a more flexible mechanism or
2439 // options for multiple minimum-size modes, e.g. strict or lax
2440 wxSize min_size = sizer->GetMinSize();
2441 wxSize frame_size = m_frame->GetSize();
2442 wxSize client_size = m_frame->GetClientSize();
2444 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2445 min_size.y+frame_size.y-client_size.y );
2447 m_frame->SetMinSize(minframe_size);
2449 if (frame_size.x < minframe_size.x ||
2450 frame_size.y < minframe_size.y)
2451 sizer->Fit(m_frame);
2456 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2457 // on the frame's main sizer, then measures all the various UI items
2458 // and updates their internal rectangles. This should always be called
2459 // instead of calling m_frame->Layout() directly
2461 void wxAuiManager::DoFrameLayout()
2466 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2468 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2470 // get the rectangle of the UI part
2471 // originally, this code looked like this:
2472 // part.rect = wxRect(part.sizer_item->GetPosition(),
2473 // part.sizer_item->GetSize());
2474 // this worked quite well, with one exception: the mdi
2475 // client window had a "deferred" size variable
2476 // that returned the wrong size. It looks like
2477 // a bug in wx, because the former size of the window
2478 // was being returned. So, we will retrieve the part's
2479 // rectangle via other means
2482 part
.rect
= part
.sizer_item
->GetRect();
2483 int flag
= part
.sizer_item
->GetFlag();
2484 int border
= part
.sizer_item
->GetBorder();
2487 part
.rect
.y
-= border
;
2488 part
.rect
.height
+= border
;
2492 part
.rect
.x
-= border
;
2493 part
.rect
.width
+= border
;
2495 if (flag
& wxBOTTOM
)
2496 part
.rect
.height
+= border
;
2498 part
.rect
.width
+= border
;
2501 if (part
.type
== wxAuiDockUIPart::typeDock
)
2502 part
.dock
->rect
= part
.rect
;
2503 if (part
.type
== wxAuiDockUIPart::typePane
)
2504 part
.pane
->rect
= part
.rect
;
2508 // GetPanePart() looks up the pane the pane border UI part (or the regular
2509 // pane part if there is no border). This allows the caller to get the exact
2510 // rectangle of the pane in question, including decorations like
2511 // caption and border (if any).
2513 wxAuiDockUIPart
* wxAuiManager::GetPanePart(wxWindow
* wnd
)
2516 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2518 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2519 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
2520 part
.pane
&& part
.pane
->window
== wnd
)
2523 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2525 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2526 if (part
.type
== wxAuiDockUIPart::typePane
&&
2527 part
.pane
&& part
.pane
->window
== wnd
)
2535 // GetDockPixelOffset() is an internal function which returns
2536 // a dock's offset in pixels from the left side of the window
2537 // (for horizontal docks) or from the top of the window (for
2538 // vertical docks). This value is necessary for calculating
2539 // fixel-pane/toolbar offsets when they are dragged.
2541 int wxAuiManager::GetDockPixelOffset(wxAuiPaneInfo
& test
)
2543 // the only way to accurately calculate the dock's
2544 // offset is to actually run a theoretical layout
2546 int i
, part_count
, dock_count
;
2547 wxAuiDockInfoArray docks
;
2548 wxAuiPaneInfoArray panes
;
2549 wxAuiDockUIPartArray uiparts
;
2550 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2553 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2554 wxSize client_size
= m_frame
->GetClientSize();
2555 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2558 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2560 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
2561 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2562 part
.sizer_item
->GetSize());
2563 if (part
.type
== wxAuiDockUIPart::typeDock
)
2564 part
.dock
->rect
= part
.rect
;
2569 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2571 wxAuiDockInfo
& dock
= docks
.Item(i
);
2572 if (test
.dock_direction
== dock
.dock_direction
&&
2573 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2575 if (dock
.IsVertical())
2587 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2588 // if a dock operation is allowed, the new dock position is copied into
2589 // the target info. If the operation was allowed, the function returns true.
2591 bool wxAuiManager::ProcessDockResult(wxAuiPaneInfo
& target
,
2592 const wxAuiPaneInfo
& new_pos
)
2594 bool allowed
= false;
2595 switch (new_pos
.dock_direction
)
2597 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2598 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2599 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2600 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2610 // DoDrop() is an important function. It basically takes a mouse position,
2611 // and determines where the pane's new position would be. If the pane is to be
2612 // dropped, it performs the drop operation using the specified dock and pane
2613 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2614 // scenario can be performed, giving precise coordinates for drop hints.
2615 // If, however, wxAuiManager:m_docks and wxAuiManager::m_panes are specified
2616 // as parameters, the changes will be made to the main state arrays
2618 const int auiInsertRowPixels
= 10;
2619 const int auiNewRowPixels
= 40;
2620 const int auiLayerInsertPixels
= 40;
2621 const int auiLayerInsertOffset
= 5;
2623 bool wxAuiManager::DoDrop(wxAuiDockInfoArray
& docks
,
2624 wxAuiPaneInfoArray
& panes
,
2625 wxAuiPaneInfo
& target
,
2627 const wxPoint
& offset
)
2629 wxSize cli_size
= m_frame
->GetClientSize();
2631 wxAuiPaneInfo drop
= target
;
2634 // The result should always be shown
2638 // Check to see if the pane has been dragged outside of the window
2639 // (or near to the outside of the window), if so, dock it along the edge
2642 int layer_insert_offset
= auiLayerInsertOffset
;
2643 if (drop
.IsToolbar())
2644 layer_insert_offset
= 0;
2647 if (pt
.x
< layer_insert_offset
&&
2648 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2650 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2651 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2652 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2654 if (drop
.IsToolbar())
2655 new_layer
= auiToolBarLayer
;
2660 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2661 return ProcessDockResult(target
, drop
);
2663 else if (pt
.y
< layer_insert_offset
&&
2664 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2666 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2667 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2668 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2670 if (drop
.IsToolbar())
2671 new_layer
= auiToolBarLayer
;
2676 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2677 return ProcessDockResult(target
, drop
);
2679 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2680 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2682 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2683 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2684 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2686 if (drop
.IsToolbar())
2687 new_layer
= auiToolBarLayer
;
2689 drop
.Dock().Right().
2692 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2693 return ProcessDockResult(target
, drop
);
2695 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2696 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2698 int new_layer
= wxMax( wxMax( GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2699 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2700 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2702 if (drop
.IsToolbar())
2703 new_layer
= auiToolBarLayer
;
2705 drop
.Dock().Bottom().
2708 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2709 return ProcessDockResult(target
, drop
);
2713 wxAuiDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2716 if (drop
.IsToolbar())
2718 if (!part
|| !part
->dock
)
2721 // calculate the offset from where the dock begins
2722 // to the point where the user dropped the pane
2723 int dock_drop_offset
= 0;
2724 if (part
->dock
->IsHorizontal())
2725 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2727 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2730 // toolbars may only be moved in and to fixed-pane docks,
2731 // otherwise we will try to float the pane. Also, the pane
2732 // should float if being dragged over center pane windows
2733 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2735 if (m_last_rect
.IsEmpty() || m_last_rect
.Contains(pt
.x
, pt
.y
))
2741 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2742 (drop
.IsFloatable() ||
2743 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2744 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2751 return ProcessDockResult(target
, drop
);
2754 drop
.Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2756 return ProcessDockResult(target
, drop
);
2765 m_last_rect
= part
->dock
->rect
;
2766 m_last_rect
.Inflate( 15, 15 );
2770 Direction(part
->dock
->dock_direction
).
2771 Layer(part
->dock
->dock_layer
).
2772 Row(part
->dock
->dock_row
).
2773 Position(dock_drop_offset
);
2776 ((pt
.y
< part
->dock
->rect
.y
+ 1) && part
->dock
->IsHorizontal()) ||
2777 ((pt
.x
< part
->dock
->rect
.x
+ 1) && part
->dock
->IsVertical())
2778 ) && part
->dock
->panes
.GetCount() > 1)
2780 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2781 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2783 int row
= drop
.dock_row
;
2784 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2785 part
->dock
->dock_layer
,
2786 part
->dock
->dock_row
);
2787 drop
.dock_row
= row
;
2791 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2792 part
->dock
->dock_layer
,
2793 part
->dock
->dock_row
+1);
2794 drop
.dock_row
= part
->dock
->dock_row
+1;
2799 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2800 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2801 ) && part
->dock
->panes
.GetCount() > 1)
2803 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2804 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2806 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2807 part
->dock
->dock_layer
,
2808 part
->dock
->dock_row
+1);
2809 drop
.dock_row
= part
->dock
->dock_row
+1;
2813 int row
= drop
.dock_row
;
2814 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2815 part
->dock
->dock_layer
,
2816 part
->dock
->dock_row
);
2817 drop
.dock_row
= row
;
2821 return ProcessDockResult(target
, drop
);
2830 if (part
->type
== wxAuiDockUIPart::typePaneBorder
||
2831 part
->type
== wxAuiDockUIPart::typeCaption
||
2832 part
->type
== wxAuiDockUIPart::typeGripper
||
2833 part
->type
== wxAuiDockUIPart::typePaneButton
||
2834 part
->type
== wxAuiDockUIPart::typePane
||
2835 part
->type
== wxAuiDockUIPart::typePaneSizer
||
2836 part
->type
== wxAuiDockUIPart::typeDockSizer
||
2837 part
->type
== wxAuiDockUIPart::typeBackground
)
2839 if (part
->type
== wxAuiDockUIPart::typeDockSizer
)
2841 if (part
->dock
->panes
.GetCount() != 1)
2843 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2850 // If a normal frame is being dragged over a toolbar, insert it
2851 // along the edge under the toolbar, but over all other panes.
2852 // (this could be done much better, but somehow factoring this
2853 // calculation with the one at the beginning of this function)
2854 if (part
->dock
&& part
->dock
->toolbar
)
2858 switch (part
->dock
->dock_direction
)
2860 case wxAUI_DOCK_LEFT
:
2861 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2862 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2863 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2865 case wxAUI_DOCK_TOP
:
2866 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2867 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2868 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2870 case wxAUI_DOCK_RIGHT
:
2871 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2872 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2873 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2875 case wxAUI_DOCK_BOTTOM
:
2876 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2877 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2878 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2882 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2885 Direction(part
->dock
->dock_direction
).
2886 Layer(layer
).Row(0).Position(0);
2887 return ProcessDockResult(target
, drop
);
2894 part
= GetPanePart(part
->pane
->window
);
2898 bool insert_dock_row
= false;
2899 int insert_row
= part
->pane
->dock_row
;
2900 int insert_dir
= part
->pane
->dock_direction
;
2901 int insert_layer
= part
->pane
->dock_layer
;
2903 switch (part
->pane
->dock_direction
)
2905 case wxAUI_DOCK_TOP
:
2906 if (pt
.y
>= part
->rect
.y
&&
2907 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2908 insert_dock_row
= true;
2910 case wxAUI_DOCK_BOTTOM
:
2911 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2912 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2913 insert_dock_row
= true;
2915 case wxAUI_DOCK_LEFT
:
2916 if (pt
.x
>= part
->rect
.x
&&
2917 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2918 insert_dock_row
= true;
2920 case wxAUI_DOCK_RIGHT
:
2921 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2922 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2923 insert_dock_row
= true;
2925 case wxAUI_DOCK_CENTER
:
2927 // "new row pixels" will be set to the default, but
2928 // must never exceed 20% of the window size
2929 int new_row_pixels_x
= auiNewRowPixels
;
2930 int new_row_pixels_y
= auiNewRowPixels
;
2932 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2933 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2935 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2936 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2939 // determine if the mouse pointer is in a location that
2940 // will cause a new row to be inserted. The hot spot positions
2941 // are along the borders of the center pane
2944 insert_dock_row
= true;
2945 if (pt
.x
>= part
->rect
.x
&&
2946 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2947 insert_dir
= wxAUI_DOCK_LEFT
;
2949 if (pt
.y
>= part
->rect
.y
&&
2950 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2951 insert_dir
= wxAUI_DOCK_TOP
;
2953 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2954 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2955 insert_dir
= wxAUI_DOCK_RIGHT
;
2957 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2958 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2959 insert_dir
= wxAUI_DOCK_BOTTOM
;
2963 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2967 if (insert_dock_row
)
2969 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2970 drop
.Dock().Direction(insert_dir
).
2971 Layer(insert_layer
).
2974 return ProcessDockResult(target
, drop
);
2977 // determine the mouse offset and the pane size, both in the
2978 // direction of the dock itself, and perpendicular to the dock
2982 if (part
->orientation
== wxVERTICAL
)
2984 offset
= pt
.y
- part
->rect
.y
;
2985 size
= part
->rect
.GetHeight();
2989 offset
= pt
.x
- part
->rect
.x
;
2990 size
= part
->rect
.GetWidth();
2993 int drop_position
= part
->pane
->dock_pos
;
2995 // if we are in the top/left part of the pane,
2996 // insert the pane before the pane being hovered over
2997 if (offset
<= size
/2)
2999 drop_position
= part
->pane
->dock_pos
;
3001 part
->pane
->dock_direction
,
3002 part
->pane
->dock_layer
,
3003 part
->pane
->dock_row
,
3004 part
->pane
->dock_pos
);
3007 // if we are in the bottom/right part of the pane,
3008 // insert the pane before the pane being hovered over
3009 if (offset
> size
/2)
3011 drop_position
= part
->pane
->dock_pos
+1;
3013 part
->pane
->dock_direction
,
3014 part
->pane
->dock_layer
,
3015 part
->pane
->dock_row
,
3016 part
->pane
->dock_pos
+1);
3020 Direction(part
->dock
->dock_direction
).
3021 Layer(part
->dock
->dock_layer
).
3022 Row(part
->dock
->dock_row
).
3023 Position(drop_position
);
3024 return ProcessDockResult(target
, drop
);
3031 void wxAuiManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
3033 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
3035 m_hint_fadetimer
.Stop();
3039 m_hint_fadeamt
+= 4;
3040 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
3043 void wxAuiManager::ShowHint(const wxRect
& rect
)
3047 // if the hint rect is the same as last time, don't do anything
3048 if (m_last_hint
== rect
)
3052 m_hint_fadeamt
= m_hint_fademax
;
3054 if ((m_flags
& wxAUI_MGR_HINT_FADE
)
3055 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
3056 (m_flags
& wxAUI_MGR_NO_VENETIAN_BLINDS_FADE
))
3060 m_hint_wnd
->SetSize(rect
);
3062 if (!m_hint_wnd
->IsShown())
3065 // if we are dragging a floating pane, set the focus
3066 // back to that floating pane (otherwise it becomes unfocused)
3067 if (m_action
== actionDragFloatingPane
&& m_action_window
)
3068 m_action_window
->SetFocus();
3070 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
3071 m_hint_wnd
->Raise();
3074 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
3076 // start fade in timer
3077 m_hint_fadetimer
.SetOwner(this, 101);
3078 m_hint_fadetimer
.Start(5);
3081 else // Not using a transparent hint window...
3083 if (!(m_flags
& wxAUI_MGR_RECTANGLE_HINT
))
3086 if (m_last_hint
!= rect
)
3088 // remove the last hint rectangle
3094 wxScreenDC screendc
;
3095 wxRegion
clip(1, 1, 10000, 10000);
3097 // clip all floating windows, so we don't draw over them
3099 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
3101 wxAuiPaneInfo
& pane
= m_panes
.Item(i
);
3103 if (pane
.IsFloating() &&
3104 pane
.frame
->IsShown())
3106 wxRect rect
= pane
.frame
->GetRect();
3108 // wxGTK returns the client size, not the whole frame size
3114 clip
.Subtract(rect
);
3118 // As we can only hide the hint by redrawing the managed window, we
3119 // need to clip the region to the managed window too or we get
3120 // nasty redrawn problems.
3121 clip
.Intersect(m_frame
->GetRect());
3123 screendc
.SetClippingRegion(clip
);
3125 wxBitmap stipple
= wxPaneCreateStippleBitmap();
3126 wxBrush
brush(stipple
);
3127 screendc
.SetBrush(brush
);
3128 screendc
.SetPen(*wxTRANSPARENT_PEN
);
3130 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
3131 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
3132 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
3133 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
3137 void wxAuiManager::HideHint()
3139 // hides a transparent window hint, if there is one
3142 if (m_hint_wnd
->IsShown())
3143 m_hint_wnd
->Show(false);
3144 m_hint_wnd
->SetTransparent(0);
3145 m_hint_fadetimer
.Stop();
3146 m_last_hint
= wxRect();
3150 // hides a painted hint by redrawing the frame window
3151 if (!m_last_hint
.IsEmpty())
3155 m_last_hint
= wxRect();
3161 void wxAuiManager::StartPaneDrag(wxWindow
* pane_window
,
3162 const wxPoint
& offset
)
3164 wxAuiPaneInfo
& pane
= GetPane(pane_window
);
3168 if (pane
.IsToolbar())
3170 m_action
= actionDragToolbarPane
;
3174 m_action
= actionDragFloatingPane
;
3177 m_action_window
= pane_window
;
3178 m_action_offset
= offset
;
3179 m_frame
->CaptureMouse();
3183 // CalculateHintRect() calculates the drop hint rectangle. The method
3184 // first calls DoDrop() to determine the exact position the pane would
3185 // be at were if dropped. If the pane would indeed become docked at the
3186 // specified drop point, the the rectangle hint will be returned in
3187 // screen coordinates. Otherwise, an empty rectangle is returned.
3188 // |pane_window| is the window pointer of the pane being dragged, |pt| is
3189 // the mouse position, in client coordinates. |offset| describes the offset
3190 // that the mouse is from the upper-left corner of the item being dragged
3192 wxRect
wxAuiManager::CalculateHintRect(wxWindow
* pane_window
,
3194 const wxPoint
& offset
)
3198 // we need to paint a hint rectangle; to find out the exact hint rectangle,
3199 // we will create a new temporary layout and then measure the resulting
3200 // rectangle; we will create a copy of the docking structures (m_dock)
3201 // so that we don't modify the real thing on screen
3203 int i
, pane_count
, part_count
;
3204 wxAuiDockInfoArray docks
;
3205 wxAuiPaneInfoArray panes
;
3206 wxAuiDockUIPartArray uiparts
;
3207 wxAuiPaneInfo hint
= GetPane(pane_window
);
3208 hint
.name
= wxT("__HINT__");
3214 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3216 // remove any pane already there which bears the same window;
3217 // this happens when you are moving a pane around in a dock
3218 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
3220 if (panes
.Item(i
).window
== pane_window
)
3222 RemovePaneFromDocks(docks
, panes
.Item(i
));
3228 // find out where the new pane would be
3229 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
3236 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
3237 wxSize client_size
= m_frame
->GetClientSize();
3238 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
3241 for (i
= 0, part_count
= uiparts
.GetCount();
3242 i
< part_count
; ++i
)
3244 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
3246 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
3247 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
3249 rect
= wxRect(part
.sizer_item
->GetPosition(),
3250 part
.sizer_item
->GetSize());
3262 // actually show the hint rectangle on the screen
3263 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
3265 if ( m_frame
->GetLayoutDirection() == wxLayout_RightToLeft
)
3267 // Mirror rectangle in RTL mode
3268 rect
.x
-= rect
.GetWidth();
3274 // DrawHintRect() calculates the hint rectangle by calling
3275 // CalculateHintRect(). If there is a rectangle, it shows it
3276 // by calling ShowHint(), otherwise it hides any hint
3277 // rectangle currently shown
3278 void wxAuiManager::DrawHintRect(wxWindow
* pane_window
,
3280 const wxPoint
& offset
)
3282 wxRect rect
= CalculateHintRect(pane_window
, pt
, offset
);
3294 void wxAuiManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
3296 // try to find the pane
3297 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3298 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3300 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3301 pane
.frame
->SetTransparent(150);
3304 void wxAuiManager::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
3306 // try to find the pane
3307 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3308 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3310 wxPoint pt
= ::wxGetMousePosition();
3313 // Adapt pt to direction
3316 // move to pane's upper border
3318 pos
= wnd
->ClientToScreen( pos
);
3320 // and some more pixels for the title bar
3325 // move to pane's left border
3327 pos
= wnd
->ClientToScreen( pos
);
3332 // move to pane's right border
3333 wxPoint
pos( wnd
->GetSize().x
, 0 );
3334 pos
= wnd
->ClientToScreen( pos
);
3339 // move to pane's bottom border
3340 wxPoint
pos( 0, wnd
->GetSize().y
);
3341 pos
= wnd
->ClientToScreen( pos
);
3348 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3350 // calculate the offset from the upper left-hand corner
3351 // of the frame to the mouse pointer
3352 wxPoint frame_pos
= pane
.frame
->GetPosition();
3353 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3355 // no hint for toolbar floating windows
3356 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
3358 if (m_action
== actionDragFloatingPane
)
3360 wxAuiDockInfoArray docks
;
3361 wxAuiPaneInfoArray panes
;
3362 wxAuiDockUIPartArray uiparts
;
3363 wxAuiPaneInfo hint
= pane
;
3365 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3367 // find out where the new pane would be
3368 if (!DoDrop(docks
, panes
, hint
, client_pt
))
3370 if (hint
.IsFloating())
3374 m_action
= actionDragToolbarPane
;
3375 m_action_window
= pane
.window
;
3384 // if a key modifier is pressed while dragging the frame,
3385 // don't dock the window
3386 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
3393 DrawHintRect(wnd
, client_pt
, action_offset
);
3396 // this cleans up some screen artifacts that are caused on GTK because
3397 // we aren't getting the exact size of the window (see comment
3407 void wxAuiManager::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
3409 // try to find the pane
3410 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3411 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3413 wxPoint pt
= ::wxGetMousePosition();
3416 // Adapt pt to direction
3419 // move to pane's upper border
3421 pos
= wnd
->ClientToScreen( pos
);
3423 // and some more pixels for the title bar
3428 // move to pane's left border
3430 pos
= wnd
->ClientToScreen( pos
);
3435 // move to pane's right border
3436 wxPoint
pos( wnd
->GetSize().x
, 0 );
3437 pos
= wnd
->ClientToScreen( pos
);
3442 // move to pane's bottom border
3443 wxPoint
pos( 0, wnd
->GetSize().y
);
3444 pos
= wnd
->ClientToScreen( pos
);
3451 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3453 // calculate the offset from the upper left-hand corner
3454 // of the frame to the mouse pointer
3455 wxPoint frame_pos
= pane
.frame
->GetPosition();
3456 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3459 // if a key modifier is pressed while dragging the frame,
3460 // don't dock the window
3461 if (!wxGetKeyState(WXK_CONTROL
) && !wxGetKeyState(WXK_ALT
))
3463 // do the drop calculation
3464 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3467 // if the pane is still floating, update it's floating
3468 // position (that we store)
3469 if (pane
.IsFloating())
3471 pane
.floating_pos
= pane
.frame
->GetPosition();
3473 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3474 pane
.frame
->SetTransparent(255);
3476 else if (m_has_maximized
)
3478 RestoreMaximizedPane();
3486 void wxAuiManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3488 // try to find the pane
3489 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3490 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3492 pane
.floating_size
= size
;
3496 void wxAuiManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3498 // try to find the pane
3499 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3500 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3503 // fire pane close event
3504 wxAuiManagerEvent
e(wxEVT_AUI_PANE_CLOSE
);
3506 e
.SetCanVeto(evt
.CanVeto());
3522 void wxAuiManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3524 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3526 // try to find the pane
3527 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
3529 SetActivePane(m_panes
, wnd
);
3534 // OnRender() draws all of the pane captions, sashes,
3535 // backgrounds, captions, grippers, pane borders and buttons.
3536 // It renders the entire user interface.
3538 void wxAuiManager::OnRender(wxAuiManagerEvent
& evt
)
3540 wxDC
* dc
= evt
.GetDC();
3546 for (i
= 0, part_count
= m_uiparts
.GetCount();
3547 i
< part_count
; ++i
)
3549 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
3551 // don't draw hidden pane items
3552 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
3557 case wxAuiDockUIPart::typeDockSizer
:
3558 case wxAuiDockUIPart::typePaneSizer
:
3559 m_art
->DrawSash(*dc
, m_frame
, part
.orientation
, part
.rect
);
3561 case wxAuiDockUIPart::typeBackground
:
3562 m_art
->DrawBackground(*dc
, m_frame
, part
.orientation
, part
.rect
);
3564 case wxAuiDockUIPart::typeCaption
:
3565 m_art
->DrawCaption(*dc
, m_frame
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3567 case wxAuiDockUIPart::typeGripper
:
3568 m_art
->DrawGripper(*dc
, m_frame
, part
.rect
, *part
.pane
);
3570 case wxAuiDockUIPart::typePaneBorder
:
3571 m_art
->DrawBorder(*dc
, m_frame
, part
.rect
, *part
.pane
);
3573 case wxAuiDockUIPart::typePaneButton
:
3574 m_art
->DrawPaneButton(*dc
, m_frame
, part
.button
->button_id
,
3575 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3582 // Render() fire a render event, which is normally handled by
3583 // wxAuiManager::OnRender(). This allows the render function to
3584 // be overridden via the render event. This can be useful for paintin
3585 // custom graphics in the main window. Default behavior can be
3586 // invoked in the overridden function by calling OnRender()
3588 void wxAuiManager::Render(wxDC
* dc
)
3590 wxAuiManagerEvent
e(wxEVT_AUI_RENDER
);
3596 void wxAuiManager::Repaint(wxDC
* dc
)
3601 m_frame
->Refresh() ;
3607 m_frame
->GetClientSize(&w
, &h
);
3609 // figure out which dc to use; if one
3610 // has been specified, use it, otherwise
3612 wxClientDC
* client_dc
= NULL
;
3615 client_dc
= new wxClientDC(m_frame
);
3619 // if the frame has a toolbar, the client area
3620 // origin will not be (0,0).
3621 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3622 if (pt
.x
!= 0 || pt
.y
!= 0)
3623 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3625 // render all the items
3628 // if we created a client_dc, delete it
3633 void wxAuiManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3635 wxPaintDC
dc(m_frame
);
3639 void wxAuiManager::OnEraseBackground(wxEraseEvent
& event
)
3648 void wxAuiManager::OnSize(wxSizeEvent
& event
)
3656 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
3658 // for MDI parent frames, this event must not
3659 // be "skipped". In other words, the parent frame
3660 // must not be allowed to resize the client window
3661 // after we are finished processing sizing changes
3669 void wxAuiManager::OnFindManager(wxAuiManagerEvent
& evt
)
3671 // get the window we are managing, if none, return NULL
3672 wxWindow
* window
= GetManagedWindow();
3675 evt
.SetManager(NULL
);
3679 // if we are managing a child frame, get the 'real' manager
3680 if (window
->IsKindOf(CLASSINFO(wxAuiFloatingFrame
)))
3682 wxAuiFloatingFrame
* float_frame
= static_cast<wxAuiFloatingFrame
*>(window
);
3683 evt
.SetManager(float_frame
->GetOwnerManager());
3687 // return pointer to ourself
3688 evt
.SetManager(this);
3691 void wxAuiManager::OnSetCursor(wxSetCursorEvent
& event
)
3694 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3695 wxCursor cursor
= wxNullCursor
;
3699 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3700 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3702 // a dock may not be resized if it has a single
3703 // pane which is not resizable
3704 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3705 part
->dock
->panes
.GetCount() == 1 &&
3706 part
->dock
->panes
.Item(0)->IsFixed())
3709 // panes that may not be resized do not get a sizing cursor
3710 if (part
->pane
&& part
->pane
->IsFixed())
3713 if (part
->orientation
== wxVERTICAL
)
3714 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3716 cursor
= wxCursor(wxCURSOR_SIZENS
);
3718 else if (part
->type
== wxAuiDockUIPart::typeGripper
)
3720 cursor
= wxCursor(wxCURSOR_SIZING
);
3724 event
.SetCursor(cursor
);
3729 void wxAuiManager::UpdateButtonOnScreen(wxAuiDockUIPart
* button_ui_part
,
3730 const wxMouseEvent
& event
)
3732 wxAuiDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3733 if (!hit_test
|| !button_ui_part
)
3736 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3738 if (hit_test
== button_ui_part
)
3740 if (event
.LeftDown())
3741 state
= wxAUI_BUTTON_STATE_PRESSED
;
3743 state
= wxAUI_BUTTON_STATE_HOVER
;
3747 if (event
.LeftDown())
3748 state
= wxAUI_BUTTON_STATE_HOVER
;
3751 // now repaint the button with hover state
3752 wxClientDC
cdc(m_frame
);
3754 // if the frame has a toolbar, the client area
3755 // origin will not be (0,0).
3756 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3757 if (pt
.x
!= 0 || pt
.y
!= 0)
3758 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3762 m_art
->DrawPaneButton(cdc
, m_frame
,
3763 button_ui_part
->button
->button_id
,
3765 button_ui_part
->rect
,
3770 void wxAuiManager::OnLeftDown(wxMouseEvent
& event
)
3772 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3775 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3776 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3778 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3781 // a dock may not be resized if it has a single
3782 // pane which is not resizable
3783 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3784 part
->dock
->panes
.GetCount() == 1 &&
3785 part
->dock
->panes
.Item(0)->IsFixed())
3788 // panes that may not be resized should be ignored here
3789 if (part
->pane
&& part
->pane
->IsFixed())
3792 m_action
= actionResize
;
3793 m_action_part
= part
;
3794 m_action_hintrect
= wxRect();
3795 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3796 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3797 event
.m_y
- part
->rect
.y
);
3798 m_frame
->CaptureMouse();
3800 else if (part
->type
== wxAuiDockUIPart::typePaneButton
)
3802 m_action
= actionClickButton
;
3803 m_action_part
= part
;
3804 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3805 m_frame
->CaptureMouse();
3807 UpdateButtonOnScreen(part
, event
);
3809 else if (part
->type
== wxAuiDockUIPart::typeCaption
||
3810 part
->type
== wxAuiDockUIPart::typeGripper
)
3812 // if we are managing a wxAuiFloatingFrame window, then
3813 // we are an embedded wxAuiManager inside the wxAuiFloatingFrame.
3814 // We want to initiate a toolbar drag in our owner manager
3815 wxWindow
* managed_wnd
= GetManagedWindow();
3818 part
->pane
->window
&&
3820 managed_wnd
->IsKindOf(CLASSINFO(wxAuiFloatingFrame
)))
3822 wxAuiFloatingFrame
* floating_frame
= (wxAuiFloatingFrame
*)managed_wnd
;
3823 wxAuiManager
* owner_mgr
= floating_frame
->GetOwnerManager();
3824 owner_mgr
->StartPaneDrag(part
->pane
->window
,
3825 wxPoint(event
.m_x
- part
->rect
.x
,
3826 event
.m_y
- part
->rect
.y
));
3832 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3835 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3837 // set the caption as active
3838 SetActivePane(m_panes
, part
->pane
->window
);
3842 m_action
= actionClickCaption
;
3843 m_action_part
= part
;
3844 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3845 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3846 event
.m_y
- part
->rect
.y
);
3847 m_frame
->CaptureMouse();
3867 void wxAuiManager::OnLeftUp(wxMouseEvent
& event
)
3869 if (m_action
== actionResize
)
3871 m_frame
->ReleaseMouse();
3873 // get rid of the hint rectangle
3875 DrawResizeHint(dc
, m_action_hintrect
);
3877 // resize the dock or the pane
3878 if (m_action_part
&& m_action_part
->type
==wxAuiDockUIPart::typeDockSizer
)
3880 wxRect
& rect
= m_action_part
->dock
->rect
;
3882 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3883 event
.m_y
- m_action_offset
.y
);
3885 switch (m_action_part
->dock
->dock_direction
)
3887 case wxAUI_DOCK_LEFT
:
3888 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3890 case wxAUI_DOCK_TOP
:
3891 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3893 case wxAUI_DOCK_RIGHT
:
3894 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3895 new_pos
.x
- m_action_part
->rect
.GetWidth();
3897 case wxAUI_DOCK_BOTTOM
:
3898 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3899 new_pos
.y
- m_action_part
->rect
.GetHeight();
3906 else if (m_action_part
&&
3907 m_action_part
->type
== wxAuiDockUIPart::typePaneSizer
)
3909 wxAuiDockInfo
& dock
= *m_action_part
->dock
;
3910 wxAuiPaneInfo
& pane
= *m_action_part
->pane
;
3912 int total_proportion
= 0;
3913 int dock_pixels
= 0;
3914 int new_pixsize
= 0;
3916 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
3917 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
3918 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
3920 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3921 event
.m_y
- m_action_offset
.y
);
3923 // determine the pane rectangle by getting the pane part
3924 wxAuiDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3925 wxASSERT_MSG(pane_part
,
3926 wxT("Pane border part not found -- shouldn't happen"));
3928 // determine the new pixel size that the user wants;
3929 // this will help us recalculate the pane's proportion
3930 if (dock
.IsHorizontal())
3931 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3933 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3935 // determine the size of the dock, based on orientation
3936 if (dock
.IsHorizontal())
3937 dock_pixels
= dock
.rect
.GetWidth();
3939 dock_pixels
= dock
.rect
.GetHeight();
3941 // determine the total proportion of all resizable panes,
3942 // and the total size of the dock minus the size of all
3944 int i
, dock_pane_count
= dock
.panes
.GetCount();
3945 int pane_position
= -1;
3946 for (i
= 0; i
< dock_pane_count
; ++i
)
3948 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
3949 if (p
.window
== pane
.window
)
3952 // while we're at it, subtract the pane sash
3953 // width from the dock width, because this would
3954 // skew our proportion calculations
3956 dock_pixels
-= sash_size
;
3958 // also, the whole size (including decorations) of
3959 // all fixed panes must also be subtracted, because they
3960 // are not part of the proportion calculation
3963 if (dock
.IsHorizontal())
3964 dock_pixels
-= p
.best_size
.x
;
3966 dock_pixels
-= p
.best_size
.y
;
3970 total_proportion
+= p
.dock_proportion
;
3974 // find a pane in our dock to 'steal' space from or to 'give'
3975 // space to -- this is essentially what is done when a pane is
3976 // resized; the pane should usually be the first non-fixed pane
3977 // to the right of the action pane
3978 int borrow_pane
= -1;
3979 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3981 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
3990 // demand that the pane being resized is found in this dock
3991 // (this assert really never should be raised)
3992 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3994 // prevent division by zero
3995 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3997 m_action
= actionNone
;
4001 // calculate the new proportion of the pane
4002 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
4004 // default minimum size
4007 // check against the pane's minimum size, if specified. please note
4008 // that this is not enough to ensure that the minimum size will
4009 // not be violated, because the whole frame might later be shrunk,
4010 // causing the size of the pane to violate it's minimum size
4011 if (pane
.min_size
.IsFullySpecified())
4015 if (pane
.HasBorder())
4016 min_size
+= (pane_border_size
*2);
4018 // calculate minimum size with decorations (border,caption)
4019 if (pane_part
->orientation
== wxVERTICAL
)
4021 min_size
+= pane
.min_size
.y
;
4022 if (pane
.HasCaption())
4023 min_size
+= caption_size
;
4027 min_size
+= pane
.min_size
.x
;
4032 // for some reason, an arithmatic error somewhere is causing
4033 // the proportion calculations to always be off by 1 pixel;
4034 // for now we will add the 1 pixel on, but we really should
4035 // determine what's causing this.
4038 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
4040 if (new_proportion
< min_proportion
)
4041 new_proportion
= min_proportion
;
4045 int prop_diff
= new_proportion
- pane
.dock_proportion
;
4047 // borrow the space from our neighbor pane to the
4048 // right or bottom (depending on orientation)
4049 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
4050 pane
.dock_proportion
= new_proportion
;
4057 else if (m_action
== actionClickButton
)
4059 m_hover_button
= NULL
;
4060 m_frame
->ReleaseMouse();
4061 UpdateButtonOnScreen(m_action_part
, event
);
4063 // make sure we're still over the item that was originally clicked
4064 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
4066 // fire button-click event
4067 wxAuiManagerEvent
e(wxEVT_AUI_PANE_BUTTON
);
4069 e
.SetPane(m_action_part
->pane
);
4070 e
.SetButton(m_action_part
->button
->button_id
);
4074 else if (m_action
== actionClickCaption
)
4076 m_frame
->ReleaseMouse();
4078 else if (m_action
== actionDragFloatingPane
)
4080 m_frame
->ReleaseMouse();
4082 else if (m_action
== actionDragToolbarPane
)
4084 m_frame
->ReleaseMouse();
4086 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4087 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4089 // save the new positions
4090 wxAuiDockInfoPtrArray docks
;
4091 FindDocks(m_docks
, pane
.dock_direction
,
4092 pane
.dock_layer
, pane
.dock_row
, docks
);
4093 if (docks
.GetCount() == 1)
4095 wxAuiDockInfo
& dock
= *docks
.Item(0);
4097 wxArrayInt pane_positions
, pane_sizes
;
4098 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
4100 int i
, dock_pane_count
= dock
.panes
.GetCount();
4101 for (i
= 0; i
< dock_pane_count
; ++i
)
4102 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
4105 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
4113 m_action
= actionNone
;
4114 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
4118 void wxAuiManager::OnMotion(wxMouseEvent
& event
)
4120 // sometimes when Update() is called from inside this method,
4121 // a spurious mouse move event is generated; this check will make
4122 // sure that only real mouse moves will get anywhere in this method;
4123 // this appears to be a bug somewhere, and I don't know where the
4124 // mouse move event is being generated. only verified on MSW
4126 wxPoint mouse_pos
= event
.GetPosition();
4127 if (m_last_mouse_move
== mouse_pos
)
4129 m_last_mouse_move
= mouse_pos
;
4132 if (m_action
== actionResize
)
4134 wxPoint pos
= m_action_part
->rect
.GetPosition();
4135 if (m_action_part
->orientation
== wxHORIZONTAL
)
4136 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
4138 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
4140 wxRect
rect(m_frame
->ClientToScreen(pos
),
4141 m_action_part
->rect
.GetSize());
4144 if (!m_action_hintrect
.IsEmpty())
4145 DrawResizeHint(dc
, m_action_hintrect
);
4146 DrawResizeHint(dc
, rect
);
4147 m_action_hintrect
= rect
;
4149 else if (m_action
== actionClickCaption
)
4151 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
4152 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
4154 // caption has been clicked. we need to check if the mouse
4155 // is now being dragged. if it is, we need to change the
4156 // mouse action to 'drag'
4157 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
4158 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
4160 wxAuiPaneInfo
* pane_info
= m_action_part
->pane
;
4162 if (!pane_info
->IsToolbar())
4164 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
4165 pane_info
->IsFloatable())
4167 m_action
= actionDragFloatingPane
;
4169 // set initial float position
4170 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4171 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4172 pt
.y
- m_action_offset
.y
);
4175 if (pane_info
->IsMaximized())
4176 RestorePane(*pane_info
);
4180 m_action_window
= pane_info
->frame
;
4182 // action offset is used here to make it feel "natural" to the user
4183 // to drag a docked pane and suddenly have it become a floating frame.
4184 // Sometimes, however, the offset where the user clicked on the docked
4185 // caption is bigger than the width of the floating frame itself, so
4186 // in that case we need to set the action offset to a sensible value
4187 wxSize frame_size
= m_action_window
->GetSize();
4188 if (frame_size
.x
<= m_action_offset
.x
)
4189 m_action_offset
.x
= 30;
4194 m_action
= actionDragToolbarPane
;
4195 m_action_window
= pane_info
->window
;
4199 else if (m_action
== actionDragFloatingPane
)
4201 if (m_action_window
)
4203 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4204 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
4205 pt
.y
- m_action_offset
.y
);
4208 else if (m_action
== actionDragToolbarPane
)
4210 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4211 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4213 pane
.state
|= wxAuiPaneInfo::actionPane
;
4215 wxPoint pt
= event
.GetPosition();
4216 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
4218 // if DoDrop() decided to float the pane, set up
4219 // the floating pane's initial position
4220 if (pane
.IsFloating())
4222 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4223 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4224 pt
.y
- m_action_offset
.y
);
4227 // this will do the actiual move operation;
4228 // in the case that the pane has been floated,
4229 // this call will create the floating pane
4230 // and do the reparenting
4233 // if the pane has been floated, change the mouse
4234 // action actionDragFloatingPane so that subsequent
4235 // EVT_MOTION() events will move the floating pane
4236 if (pane
.IsFloating())
4238 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
4239 m_action
= actionDragFloatingPane
;
4240 m_action_window
= pane
.frame
;
4245 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
4246 if (part
&& part
->type
== wxAuiDockUIPart::typePaneButton
)
4248 if (part
!= m_hover_button
)
4250 // make the old button normal
4253 UpdateButtonOnScreen(m_hover_button
, event
);
4257 // mouse is over a button, so repaint the
4258 // button in hover mode
4259 UpdateButtonOnScreen(part
, event
);
4260 m_hover_button
= part
;
4268 m_hover_button
= NULL
;
4279 void wxAuiManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
4283 m_hover_button
= NULL
;
4288 void wxAuiManager::OnChildFocus(wxChildFocusEvent
& event
)
4290 // when a child pane has it's focus set, we should change the
4291 // pane's active state to reflect this. (this is only true if
4292 // active panes are allowed by the owner)
4293 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
4295 if (GetPane(event
.GetWindow()).IsOk())
4297 SetActivePane(m_panes
, event
.GetWindow());
4306 // OnPaneButton() is an event handler that is called
4307 // when a pane button has been pressed.
4308 void wxAuiManager::OnPaneButton(wxAuiManagerEvent
& evt
)
4310 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxAuiManager::OnPaneButton must be non-null"));
4312 wxAuiPaneInfo
& pane
= *(evt
.pane
);
4314 if (evt
.button
== wxAUI_BUTTON_CLOSE
)
4316 // fire pane close event
4317 wxAuiManagerEvent
e(wxEVT_AUI_PANE_CLOSE
);
4319 e
.SetPane(evt
.pane
);
4328 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& !pane
.IsMaximized())
4330 // fire pane close event
4331 wxAuiManagerEvent
e(wxEVT_AUI_PANE_MAXIMIZE
);
4333 e
.SetPane(evt
.pane
);
4342 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& pane
.IsMaximized())
4344 // fire pane close event
4345 wxAuiManagerEvent
e(wxEVT_AUI_PANE_RESTORE
);
4347 e
.SetPane(evt
.pane
);
4356 else if (evt
.button
== wxAUI_BUTTON_PIN
)
4358 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&