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"
31 #include "wx/aui/tabmdi.h"
35 #include "wx/settings.h"
37 #include "wx/dcclient.h"
38 #include "wx/dcscreen.h"
39 #include "wx/toolbar.h"
44 WX_CHECK_BUILD_OPTIONS("wxAUI")
46 #include "wx/arrimpl.cpp"
47 WX_DECLARE_OBJARRAY(wxRect
, wxAuiRectArray
);
48 WX_DEFINE_OBJARRAY(wxAuiRectArray
)
49 WX_DEFINE_OBJARRAY(wxAuiDockUIPartArray
)
50 WX_DEFINE_OBJARRAY(wxAuiDockInfoArray
)
51 WX_DEFINE_OBJARRAY(wxAuiPaneButtonArray
)
52 WX_DEFINE_OBJARRAY(wxAuiPaneInfoArray
)
54 wxAuiPaneInfo wxAuiNullPaneInfo
;
55 wxAuiDockInfo wxAuiNullDockInfo
;
56 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_BUTTON
)
57 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_CLOSE
)
58 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_MAXIMIZE
)
59 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_RESTORE
)
60 DEFINE_EVENT_TYPE(wxEVT_AUI_RENDER
)
61 DEFINE_EVENT_TYPE(wxEVT_AUI_FIND_MANAGER
)
64 // a few defines to avoid nameclashes
65 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
67 #include "wx/mac/private.h"
70 IMPLEMENT_DYNAMIC_CLASS(wxAuiManagerEvent
, wxEvent
)
71 IMPLEMENT_CLASS(wxAuiManager
, wxEvtHandler
)
75 const int auiToolBarLayer
= 10;
80 class wxPseudoTransparentFrame
: public wxFrame
83 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
84 wxWindowID id
= wxID_ANY
,
85 const wxString
& title
= wxEmptyString
,
86 const wxPoint
& pos
= wxDefaultPosition
,
87 const wxSize
& size
= wxDefaultSize
,
88 long style
= wxDEFAULT_FRAME_STYLE
,
89 const wxString
&name
= wxT("frame"))
90 : wxFrame(parent
, id
, title
, pos
, size
, style
| wxFRAME_SHAPED
, name
)
92 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
99 m_CanSetShape
= false; // have to wait for window create event on GTK
101 m_CanSetShape
= true;
103 m_Region
= wxRegion(0, 0, 0, 0);
107 virtual bool SetTransparent(wxByte alpha
)
111 int w
=100; // some defaults
113 GetClientSize(&w
, &h
);
119 // m_Region.Union(0, 0, 1, m_MaxWidth);
122 for (int y
=0; y
<m_MaxHeight
; y
++)
124 // Reverse the order of the bottom 4 bits
125 int j
=((y
&8)?
1:0)|((y
&4)?
2:0)|((y
&2)?
4:0)|((y
&1)?
8:0);
126 if ((j
*16+8)<m_Amount
)
127 m_Region
.Union(0, y
, m_MaxWidth
, 1);
136 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
140 if (m_Region
.IsEmpty())
144 dc
.SetBrush(wxColour(128, 192, 255));
146 dc
.SetBrush(wxSystemSettings
::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
148 dc
.SetPen(*wxTRANSPARENT_PEN
);
150 wxRegionIterator
upd(GetUpdateRegion()); // get the update rect list
154 wxRect
rect(upd
.GetRect());
155 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
162 void OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
))
169 void OnSize(wxSizeEvent
& event
)
171 // We sometimes get surplus size events
172 if ((event
.GetSize().GetWidth() == m_lastWidth
) &&
173 (event
.GetSize().GetHeight() == m_lastHeight
))
178 m_lastWidth
= event
.GetSize().GetWidth();
179 m_lastHeight
= event
.GetSize().GetHeight();
181 SetTransparent(m_Amount
);
182 m_Region
.Intersect(0, 0, event
.GetSize().GetWidth(),
183 event
.GetSize().GetHeight());
194 int m_lastWidth
,m_lastHeight
;
198 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
199 DECLARE_EVENT_TABLE()
203 IMPLEMENT_DYNAMIC_CLASS(wxPseudoTransparentFrame
, wxFrame
)
205 BEGIN_EVENT_TABLE(wxPseudoTransparentFrame
, wxFrame
)
206 EVT_PAINT(wxPseudoTransparentFrame
::OnPaint
)
207 EVT_SIZE(wxPseudoTransparentFrame
::OnSize
)
209 EVT_WINDOW_CREATE(wxPseudoTransparentFrame
::OnWindowCreate
)
217 #include "wx/gtk/private.h"
220 gtk_pseudo_window_realized_callback( GtkWidget
*m_widget
, void *WXUNUSED(win
) )
222 wxSize disp
= wxGetDisplaySize();
225 for (int y
=0; y
<disp
.y
; y
++)
227 // Reverse the order of the bottom 4 bits
228 int j
=((y
&8)?
1:0)|((y
&4)?
2:0)|((y
&2)?
4:0)|((y
&1)?
8:0);
230 region
.Union(0, y
, disp
.x
, 1);
232 gdk_window_shape_combine_region(m_widget
->window
, region
.GetRegion(), 0, 0);
236 class wxPseudoTransparentFrame
: public wxFrame
239 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
240 wxWindowID id
= wxID_ANY
,
241 const wxString
& title
= wxEmptyString
,
242 const wxPoint
& pos
= wxDefaultPosition
,
243 const wxSize
& size
= wxDefaultSize
,
244 long style
= wxDEFAULT_FRAME_STYLE
,
245 const wxString
&name
= wxT("frame"))
247 if (!CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
252 m_widget
= gtk_window_new( GTK_WINDOW_POPUP
);
254 g_signal_connect( m_widget
, "realize",
255 G_CALLBACK (gtk_pseudo_window_realized_callback
), this );
259 col
.green
= 192 * 256;
260 col
.blue
= 255 * 256;
261 gtk_widget_modify_bg( m_widget
, GTK_STATE_NORMAL
, &col
);
264 bool SetTransparent(wxByte
WXUNUSED(alpha
))
270 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
273 IMPLEMENT_DYNAMIC_CLASS(wxPseudoTransparentFrame
, wxFrame
)
280 // -- static utility functions --
282 static wxBitmap
wxPaneCreateStippleBitmap()
284 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
285 wxImage
img(2,2,data
,true);
286 return wxBitmap(img
);
289 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
291 wxBitmap stipple
= wxPaneCreateStippleBitmap();
292 wxBrush
brush(stipple
);
294 dc
.SetPen(*wxTRANSPARENT_PEN
);
296 dc
.SetLogicalFunction(wxXOR
);
297 dc
.DrawRectangle(rect
);
302 // CopyDocksAndPanes() - this utility function creates copies of
303 // the dock and pane info. wxAuiDockInfo's usually contain pointers
304 // to wxAuiPaneInfo classes, thus this function is necessary to reliably
305 // reconstruct that relationship in the new dock info and pane info arrays
307 static void CopyDocksAndPanes(wxAuiDockInfoArray
& dest_docks
,
308 wxAuiPaneInfoArray
& dest_panes
,
309 const wxAuiDockInfoArray
& src_docks
,
310 const wxAuiPaneInfoArray
& src_panes
)
312 dest_docks
= src_docks
;
313 dest_panes
= src_panes
;
314 int i
, j
, k
, dock_count
, pc1
, pc2
;
315 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
317 wxAuiDockInfo
& dock
= dest_docks
.Item(i
);
318 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
319 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
320 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
321 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
325 // GetMaxLayer() is an internal function which returns
326 // the highest layer inside the specified dock
327 static int GetMaxLayer(const wxAuiDockInfoArray
& docks
,
330 int i
, dock_count
, max_layer
= 0;
331 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
333 wxAuiDockInfo
& dock
= docks
.Item(i
);
334 if (dock
.dock_direction
== dock_direction
&&
335 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
336 max_layer
= dock
.dock_layer
;
342 // GetMaxRow() is an internal function which returns
343 // the highest layer inside the specified dock
344 static int GetMaxRow(const wxAuiPaneInfoArray
& panes
, int direction
, int layer
)
346 int i
, pane_count
, max_row
= 0;
347 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
349 wxAuiPaneInfo
& pane
= panes
.Item(i
);
350 if (pane
.dock_direction
== direction
&&
351 pane
.dock_layer
== layer
&&
352 pane
.dock_row
> max_row
)
353 max_row
= pane
.dock_row
;
360 // DoInsertDockLayer() is an internal function that inserts a new dock
361 // layer by incrementing all existing dock layer values by one
362 static void DoInsertDockLayer(wxAuiPaneInfoArray
& panes
,
367 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
369 wxAuiPaneInfo
& pane
= panes
.Item(i
);
370 if (!pane
.IsFloating() &&
371 pane
.dock_direction
== dock_direction
&&
372 pane
.dock_layer
>= dock_layer
)
377 // DoInsertDockLayer() is an internal function that inserts a new dock
378 // row by incrementing all existing dock row values by one
379 static void DoInsertDockRow(wxAuiPaneInfoArray
& panes
,
385 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
387 wxAuiPaneInfo
& pane
= panes
.Item(i
);
388 if (!pane
.IsFloating() &&
389 pane
.dock_direction
== dock_direction
&&
390 pane
.dock_layer
== dock_layer
&&
391 pane
.dock_row
>= dock_row
)
396 // DoInsertDockLayer() is an internal function that inserts a space for
397 // another dock pane by incrementing all existing dock row values by one
398 static void DoInsertPane(wxAuiPaneInfoArray
& panes
,
405 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
407 wxAuiPaneInfo
& pane
= panes
.Item(i
);
408 if (!pane
.IsFloating() &&
409 pane
.dock_direction
== dock_direction
&&
410 pane
.dock_layer
== dock_layer
&&
411 pane
.dock_row
== dock_row
&&
412 pane
.dock_pos
>= dock_pos
)
417 // FindDocks() is an internal function that returns a list of docks which meet
418 // the specified conditions in the parameters and returns a sorted array
419 // (sorted by layer and then row)
420 static void FindDocks(wxAuiDockInfoArray
& docks
,
424 wxAuiDockInfoPtrArray
& arr
)
426 int begin_layer
= dock_layer
;
427 int end_layer
= dock_layer
;
428 int begin_row
= dock_row
;
429 int end_row
= dock_row
;
430 int dock_count
= docks
.GetCount();
431 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
433 // discover the maximum dock layer and the max row
434 for (i
= 0; i
< dock_count
; ++i
)
436 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
437 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
440 // if no dock layer was specified, search all dock layers
441 if (dock_layer
== -1)
444 end_layer
= max_layer
;
447 // if no dock row was specified, search all dock row
456 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
457 for (row
= begin_row
; row
<= end_row
; ++row
)
458 for (i
= 0; i
< dock_count
; ++i
)
460 wxAuiDockInfo
& d
= docks
.Item(i
);
461 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
463 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
469 // FindPaneInDock() looks up a specified window pointer inside a dock.
470 // If found, the corresponding wxAuiPaneInfo pointer is returned, otherwise NULL.
471 static wxAuiPaneInfo
* FindPaneInDock(const wxAuiDockInfo
& dock
, wxWindow
* window
)
473 int i
, count
= dock
.panes
.GetCount();
474 for (i
= 0; i
< count
; ++i
)
476 wxAuiPaneInfo
* p
= dock
.panes
.Item(i
);
477 if (p
->window
== window
)
483 // RemovePaneFromDocks() removes a pane window from all docks
484 // with a possible exception specified by parameter "ex_cept"
485 static void RemovePaneFromDocks(wxAuiDockInfoArray
& docks
,
487 wxAuiDockInfo
* ex_cept
= NULL
)
490 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
492 wxAuiDockInfo
& d
= docks
.Item(i
);
495 wxAuiPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
502 // This function works fine, and may be used in the future
504 // RenumberDockRows() takes a dock and assigns sequential numbers
505 // to existing rows. Basically it takes out the gaps; so if a
506 // dock has rows with numbers 0,2,5, they will become 0,1,2
507 static void RenumberDockRows(wxAuiDockInfoPtrArray& docks)
510 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
512 wxAuiDockInfo& dock = *docks.Item(i);
516 for (j = 0, pane_count = dock.panes.GetCount(); j < pane_count; ++j)
517 dock.panes.Item(j)->dock_row = i;
523 // SetActivePane() sets the active pane, as well as cycles through
524 // every other pane and makes sure that all others' active flags
526 static void SetActivePane(wxAuiPaneInfoArray
& panes
, wxWindow
* active_pane
)
529 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
531 wxAuiPaneInfo
& pane
= panes
.Item(i
);
532 pane
.state
&= ~wxAuiPaneInfo
::optionActive
;
533 if (pane
.window
== active_pane
)
534 pane
.state
|= wxAuiPaneInfo
::optionActive
;
539 // this function is used to sort panes by dock position
540 static int PaneSortFunc(wxAuiPaneInfo
** p1
, wxAuiPaneInfo
** p2
)
542 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ?
-1 : 1;
546 // -- wxAuiManager class implementation --
549 BEGIN_EVENT_TABLE(wxAuiManager
, wxEvtHandler
)
550 EVT_AUI_PANE_BUTTON(wxAuiManager
::OnPaneButton
)
551 EVT_AUI_RENDER(wxAuiManager
::OnRender
)
552 EVT_PAINT(wxAuiManager
::OnPaint
)
553 EVT_ERASE_BACKGROUND(wxAuiManager
::OnEraseBackground
)
554 EVT_SIZE(wxAuiManager
::OnSize
)
555 EVT_SET_CURSOR(wxAuiManager
::OnSetCursor
)
556 EVT_LEFT_DOWN(wxAuiManager
::OnLeftDown
)
557 EVT_LEFT_UP(wxAuiManager
::OnLeftUp
)
558 EVT_MOTION(wxAuiManager
::OnMotion
)
559 EVT_LEAVE_WINDOW(wxAuiManager
::OnLeaveWindow
)
560 EVT_CHILD_FOCUS(wxAuiManager
::OnChildFocus
)
561 EVT_AUI_FIND_MANAGER(wxAuiManager
::OnFindManager
)
562 EVT_TIMER(101, wxAuiManager
::OnHintFadeTimer
)
566 wxAuiManager
::wxAuiManager(wxWindow
* managed_wnd
, unsigned int flags
)
568 m_action
= actionNone
;
569 m_last_mouse_move
= wxPoint();
570 m_hover_button
= NULL
;
571 m_art
= new wxAuiDefaultDockArt
;
575 m_has_maximized
= false;
577 m_dock_constraint_x
= 0.3;
578 m_dock_constraint_y
= 0.3;
583 SetManagedWindow(managed_wnd
);
587 wxAuiManager
::~wxAuiManager()
589 for ( size_t i
= 0; i
< m_panes
.size(); i
++ )
591 wxAuiPaneInfo
& pinfo
= m_panes
[i
];
592 if (pinfo
.window
&& !pinfo
.window
->GetParent())
599 // creates a floating frame for the windows
600 wxAuiFloatingFrame
* wxAuiManager
::CreateFloatingFrame(wxWindow
* parent
,
601 const wxAuiPaneInfo
& pane_info
)
603 return new wxAuiFloatingFrame(parent
, this, pane_info
);
606 bool wxAuiManager
::CanDockPanel(const wxAuiPaneInfo
& WXUNUSED(p
))
608 // if a key modifier is pressed while dragging the frame,
609 // don't dock the window
610 return !(wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
));
613 // GetPane() looks up a wxAuiPaneInfo structure based
614 // on the supplied window pointer. Upon failure, GetPane()
615 // returns an empty wxAuiPaneInfo, a condition which can be checked
616 // by calling wxAuiPaneInfo::IsOk().
618 // The pane info's structure may then be modified. Once a pane's
619 // info is modified, wxAuiManager::Update() must be called to
620 // realize the changes in the UI.
622 wxAuiPaneInfo
& wxAuiManager
::GetPane(wxWindow
* window
)
625 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
627 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
628 if (p
.window
== window
)
631 return wxAuiNullPaneInfo
;
634 // this version of GetPane() looks up a pane based on a
635 // 'pane name', see above comment for more info
636 wxAuiPaneInfo
& wxAuiManager
::GetPane(const wxString
& name
)
639 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
641 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
645 return wxAuiNullPaneInfo
;
648 // GetAllPanes() returns a reference to all the pane info structures
649 wxAuiPaneInfoArray
& wxAuiManager
::GetAllPanes()
654 // HitTest() is an internal function which determines
655 // which UI item the specified coordinates are over
656 // (x,y) specify a position in client coordinates
657 wxAuiDockUIPart
* wxAuiManager
::HitTest(int x
, int y
)
659 wxAuiDockUIPart
* result
= NULL
;
662 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
664 wxAuiDockUIPart
* item
= &m_uiparts
.Item(i
);
666 // we are not interested in typeDock, because this space
667 // isn't used to draw anything, just for measurements;
668 // besides, the entire dock area is covered with other
669 // rectangles, which we are interested in.
670 if (item
->type
== wxAuiDockUIPart
::typeDock
)
673 // if we already have a hit on a more specific item, we are not
674 // interested in a pane hit. If, however, we don't already have
675 // a hit, returning a pane hit is necessary for some operations
676 if ((item
->type
== wxAuiDockUIPart
::typePane
||
677 item
->type
== wxAuiDockUIPart
::typePaneBorder
) && result
)
680 // if the point is inside the rectangle, we have a hit
681 if (item
->rect
.Contains(x
,y
))
689 // SetFlags() and GetFlags() allow the owner to set various
690 // options which are global to wxAuiManager
691 void wxAuiManager
::SetFlags(unsigned int flags
)
693 // find out if we have to call UpdateHintWindowConfig()
694 bool update_hint_wnd
= false;
695 unsigned int hint_mask
= wxAUI_MGR_TRANSPARENT_HINT
|
696 wxAUI_MGR_VENETIAN_BLINDS_HINT
|
697 wxAUI_MGR_RECTANGLE_HINT
;
698 if ((flags
& hint_mask
) != (m_flags
& hint_mask
))
699 update_hint_wnd
= true;
707 UpdateHintWindowConfig();
711 unsigned int wxAuiManager
::GetFlags() const
717 // don't use these anymore as they are deprecated
718 // use Set/GetManagedFrame() instead
719 void wxAuiManager
::SetFrame(wxFrame
* frame
)
721 SetManagedWindow((wxWindow
*)frame
);
724 wxFrame
* wxAuiManager
::GetFrame() const
726 return (wxFrame
*)m_frame
;
730 // this function will return the aui manager for a given
731 // window. The |window| parameter should be any child window
732 // or grand-child window (and so on) of the frame/window
733 // managed by wxAuiManager. The |window| parameter does not
734 // need to be managed by the manager itself.
735 wxAuiManager
* wxAuiManager
::GetManager(wxWindow
* window
)
737 wxAuiManagerEvent
evt(wxEVT_AUI_FIND_MANAGER
);
738 evt
.SetManager(NULL
);
739 evt
.ResumePropagation(wxEVENT_PROPAGATE_MAX
);
740 if (!window
->ProcessEvent(evt
))
743 return evt
.GetManager();
747 void wxAuiManager
::UpdateHintWindowConfig()
749 // find out if the the system can do transparent frames
750 bool can_do_transparent
= false;
752 wxWindow
* w
= m_frame
;
755 if (w
->IsKindOf(CLASSINFO(wxFrame
)))
757 wxFrame
* f
= static_cast<wxFrame
*>(w
);
758 can_do_transparent
= f
->CanSetTransparent();
765 // if there is an existing hint window, delete it
768 m_hint_wnd
->Destroy();
775 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) && can_do_transparent
)
777 // Make a window to use for a transparent hint
778 #if defined(__WXMSW__) || defined(__WXGTK__)
779 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
,
780 wxDefaultPosition
, wxSize(1,1),
781 wxFRAME_TOOL_WINDOW
|
782 wxFRAME_FLOAT_ON_PARENT
|
786 m_hint_wnd
->SetBackgroundColour(wxSystemSettings
::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
787 #elif defined(__WXMAC__)
788 // Using a miniframe with float and tool styles keeps the parent
789 // frame activated and highlighted as such...
790 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
,
791 wxDefaultPosition
, wxSize(1,1),
792 wxFRAME_FLOAT_ON_PARENT
793 | wxFRAME_TOOL_WINDOW
);
795 // Can't set the bg colour of a Frame in wxMac
796 wxPanel
* p
= new wxPanel(m_hint_wnd
);
798 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
799 // color that is really hard to see, especially transparent.
800 // Until a better system color is decided upon we'll just use
802 p
->SetBackgroundColour(*wxBLUE
);
808 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 ||
809 (m_flags
& wxAUI_MGR_VENETIAN_BLINDS_HINT
) != 0)
811 // system can't support transparent fade, or the venetian
812 // blinds effect was explicitly requested
813 m_hint_wnd
= new wxPseudoTransparentFrame(m_frame
,
818 wxFRAME_TOOL_WINDOW
|
819 wxFRAME_FLOAT_ON_PARENT
|
822 m_hint_fademax
= 128;
828 // SetManagedWindow() is usually called once when the frame
829 // manager class is being initialized. "frame" specifies
830 // the frame which should be managed by the frame mananger
831 void wxAuiManager
::SetManagedWindow(wxWindow
* wnd
)
833 wxASSERT_MSG(wnd
, wxT("specified window must be non-NULL"));
836 m_frame
->PushEventHandler(this);
839 // if the owner is going to manage an MDI parent frame,
840 // we need to add the MDI client window as the default
843 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
845 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)m_frame
;
846 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
848 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
850 AddPane(client_window
,
851 wxAuiPaneInfo().Name(wxT("mdiclient")).
852 CenterPane().PaneBorder(false));
854 else if (m_frame
->IsKindOf(CLASSINFO(wxAuiMDIParentFrame
)))
856 wxAuiMDIParentFrame
* mdi_frame
= (wxAuiMDIParentFrame
*)m_frame
;
857 wxAuiMDIClientWindow
* client_window
= mdi_frame
->GetClientWindow();
858 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
860 AddPane(client_window
,
861 wxAuiPaneInfo().Name(wxT("mdiclient")).
862 CenterPane().PaneBorder(false));
867 UpdateHintWindowConfig();
871 // UnInit() must be called, usually in the destructor
872 // of the frame class. If it is not called, usually this
873 // will result in a crash upon program exit
874 void wxAuiManager
::UnInit()
878 m_frame
->RemoveEventHandler(this);
882 // GetManagedWindow() returns the window pointer being managed
883 wxWindow
* wxAuiManager
::GetManagedWindow() const
888 wxAuiDockArt
* wxAuiManager
::GetArtProvider() const
893 void wxAuiManager
::ProcessMgrEvent(wxAuiManagerEvent
& event
)
895 // first, give the owner frame a chance to override
898 if (m_frame
->ProcessEvent(event
))
905 // SetArtProvider() instructs wxAuiManager to use the
906 // specified art provider for all drawing calls. This allows
907 // plugable look-and-feel features. The pointer that is
908 // passed to this method subsequently belongs to wxAuiManager,
909 // and is deleted in the frame manager destructor
910 void wxAuiManager
::SetArtProvider(wxAuiDockArt
* art_provider
)
912 // delete the last art provider, if any
915 // assign the new art provider
916 m_art
= art_provider
;
920 bool wxAuiManager
::AddPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
)
922 // check if the pane has a valid window
926 // check if the window is already managed by us
927 if (GetPane(pane_info
.window
).IsOk())
930 // check if the pane name already exists, this could reveal a
931 // bug in the library user's application
932 bool already_exists
= false;
933 if (!pane_info
.name
.empty() && GetPane(pane_info
.name
).IsOk())
935 wxFAIL_MSG(wxT("A pane with that name already exists in the manager!"));
936 already_exists
= true;
939 // if the new pane is docked then we should undo maximize
940 if (pane_info
.IsDocked())
941 RestoreMaximizedPane();
943 m_panes
.Add(pane_info
);
945 wxAuiPaneInfo
& pinfo
= m_panes
.Last();
947 // set the pane window
948 pinfo
.window
= window
;
951 // if the pane's name identifier is blank, create a random string
952 if (pinfo
.name
.empty() || already_exists
)
954 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
955 ((unsigned long)pinfo
.window
) & 0xffffffff,
956 (unsigned int)time(NULL
),
958 (unsigned int)GetTickCount(),
960 (unsigned int)clock(),
962 (unsigned long)m_panes
.GetCount());
965 // set initial proportion (if not already set)
966 if (pinfo
.dock_proportion
== 0)
967 pinfo
.dock_proportion
= 100000;
969 if (pinfo
.HasMaximizeButton())
971 wxAuiPaneButton button
;
972 button
.button_id
= wxAUI_BUTTON_MAXIMIZE_RESTORE
;
973 pinfo
.buttons
.Add(button
);
976 if (pinfo
.HasPinButton())
978 wxAuiPaneButton button
;
979 button
.button_id
= wxAUI_BUTTON_PIN
;
980 pinfo
.buttons
.Add(button
);
983 if (pinfo
.HasCloseButton())
985 wxAuiPaneButton button
;
986 button
.button_id
= wxAUI_BUTTON_CLOSE
;
987 pinfo
.buttons
.Add(button
);
990 if (pinfo
.best_size
== wxDefaultSize
&&
993 pinfo
.best_size
= pinfo
.window
->GetClientSize();
995 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
997 // GetClientSize() doesn't get the best size for
998 // a toolbar under some newer versions of wxWidgets,
999 // so use GetBestSize()
1000 pinfo
.best_size
= pinfo
.window
->GetBestSize();
1002 // for some reason, wxToolBar::GetBestSize() is returning
1003 // a size that is a pixel shy of the correct amount.
1004 // I believe this to be the correct action, until
1005 // wxToolBar::GetBestSize() is fixed. Is this assumption
1007 // commented out by JACS 2007-9-08 after having added a pixel in wxMSW's wxToolBar::DoGetBestSize()
1008 // pinfo.best_size.y++;
1011 if (pinfo
.min_size
!= wxDefaultSize
)
1013 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
1014 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
1015 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
1016 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
1023 bool wxAuiManager
::AddPane(wxWindow
* window
,
1025 const wxString
& caption
)
1027 wxAuiPaneInfo pinfo
;
1028 pinfo
.Caption(caption
);
1031 case wxTOP
: pinfo
.Top(); break;
1032 case wxBOTTOM
: pinfo
.Bottom(); break;
1033 case wxLEFT
: pinfo
.Left(); break;
1034 case wxRIGHT
: pinfo
.Right(); break;
1035 case wxCENTER
: pinfo
.CenterPane(); break;
1037 return AddPane(window
, pinfo
);
1040 bool wxAuiManager
::AddPane(wxWindow
* window
,
1041 const wxAuiPaneInfo
& pane_info
,
1042 const wxPoint
& drop_pos
)
1044 if (!AddPane(window
, pane_info
))
1047 wxAuiPaneInfo
& pane
= GetPane(window
);
1049 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
1054 bool wxAuiManager
::InsertPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
,
1057 // shift the panes around, depending on the insert level
1058 switch (insert_level
)
1060 case wxAUI_INSERT_PANE
:
1061 DoInsertPane(m_panes
,
1062 pane_info
.dock_direction
,
1063 pane_info
.dock_layer
,
1065 pane_info
.dock_pos
);
1067 case wxAUI_INSERT_ROW
:
1068 DoInsertDockRow(m_panes
,
1069 pane_info
.dock_direction
,
1070 pane_info
.dock_layer
,
1071 pane_info
.dock_row
);
1073 case wxAUI_INSERT_DOCK
:
1074 DoInsertDockLayer(m_panes
,
1075 pane_info
.dock_direction
,
1076 pane_info
.dock_layer
);
1080 // if the window already exists, we are basically just moving/inserting the
1081 // existing window. If it doesn't exist, we need to add it and insert it
1082 wxAuiPaneInfo
& existing_pane
= GetPane(window
);
1083 if (!existing_pane
.IsOk())
1085 return AddPane(window
, pane_info
);
1089 if (pane_info
.IsFloating())
1091 existing_pane
.Float();
1092 if (pane_info
.floating_pos
!= wxDefaultPosition
)
1093 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
1094 if (pane_info
.floating_size
!= wxDefaultSize
)
1095 existing_pane
.FloatingSize(pane_info
.floating_size
);
1099 // if the new pane is docked then we should undo maximize
1100 RestoreMaximizedPane();
1102 existing_pane
.Direction(pane_info
.dock_direction
);
1103 existing_pane
.Layer(pane_info
.dock_layer
);
1104 existing_pane
.Row(pane_info
.dock_row
);
1105 existing_pane
.Position(pane_info
.dock_pos
);
1113 // DetachPane() removes a pane from the frame manager. This
1114 // method will not destroy the window that is removed.
1115 bool wxAuiManager
::DetachPane(wxWindow
* window
)
1118 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
1120 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1121 if (p
.window
== window
)
1125 // we have a floating frame which is being detached. We need to
1126 // reparent it to m_frame and destroy the floating frame
1129 p
.window
->SetSize(1,1);
1131 if (p
.frame
->IsShown())
1132 p
.frame
->Show(false);
1134 // reparent to m_frame and destroy the pane
1135 if (m_action_window
== p
.frame
)
1137 m_action_window
= NULL
;
1140 p
.window
->Reparent(m_frame
);
1141 p
.frame
->SetSizer(NULL
);
1146 // make sure there are no references to this pane in our uiparts,
1147 // just in case the caller doesn't call Update() immediately after
1148 // the DetachPane() call. This prevets obscure crashes which would
1149 // happen at window repaint if the caller forgets to call Update()
1151 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
1153 wxAuiDockUIPart
& part
= m_uiparts
.Item(pi
);
1154 if (part
.pane
== &p
)
1156 m_uiparts
.RemoveAt(pi
);
1163 m_panes
.RemoveAt(i
);
1170 // ClosePane() destroys or hides the pane depending on its flags
1171 void wxAuiManager
::ClosePane(wxAuiPaneInfo
& pane_info
)
1173 // if we were maximized, restore
1174 if (pane_info
.IsMaximized())
1176 RestorePane(pane_info
);
1179 // first, hide the window
1180 if (pane_info
.window
&& pane_info
.window
->IsShown())
1182 pane_info
.window
->Show(false);
1185 // make sure that we are the parent of this window
1186 if (pane_info
.window
&& pane_info
.window
->GetParent() != m_frame
)
1188 pane_info
.window
->Reparent(m_frame
);
1191 // if we have a frame, destroy it
1192 if (pane_info
.frame
)
1194 pane_info
.frame
->Destroy();
1195 pane_info
.frame
= NULL
;
1198 // now we need to either destroy or hide the pane
1199 if (pane_info
.IsDestroyOnClose())
1201 wxWindow
* window
= pane_info
.window
;
1214 void wxAuiManager
::MaximizePane(wxAuiPaneInfo
& pane_info
)
1218 // un-maximize and hide all other panes
1219 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1221 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1226 // save hidden state
1227 p
.SetFlag(wxAuiPaneInfo
::savedHiddenState
,
1228 p
.HasFlag(wxAuiPaneInfo
::optionHidden
));
1230 // hide the pane, because only the newly
1231 // maximized pane should show
1236 // mark ourselves maximized
1237 pane_info
.Maximize();
1239 m_has_maximized
= true;
1241 // last, show the window
1242 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1244 pane_info
.window
->Show(true);
1248 void wxAuiManager
::RestorePane(wxAuiPaneInfo
& pane_info
)
1252 // restore all the panes
1253 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1255 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1258 p
.SetFlag(wxAuiPaneInfo
::optionHidden
,
1259 p
.HasFlag(wxAuiPaneInfo
::savedHiddenState
));
1263 // mark ourselves non-maximized
1264 pane_info
.Restore();
1265 m_has_maximized
= false;
1267 // last, show the window
1268 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1270 pane_info
.window
->Show(true);
1274 void wxAuiManager
::RestoreMaximizedPane()
1278 // restore all the panes
1279 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1281 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1282 if (p
.IsMaximized())
1290 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
1291 // in the input string. This is an internal functions which is
1292 // used for saving perspectives
1293 static wxString
EscapeDelimiters(const wxString
& s
)
1296 result
.Alloc(s
.length());
1297 const wxChar
* ch
= s
.c_str();
1300 if (*ch
== wxT(';') || *ch
== wxT('|'))
1301 result
+= wxT('\\');
1308 wxString wxAuiManager
::SavePaneInfo(wxAuiPaneInfo
& pane
)
1310 wxString result
= wxT("name=");
1311 result
+= EscapeDelimiters(pane
.name
);
1314 result
+= wxT("caption=");
1315 result
+= EscapeDelimiters(pane
.caption
);
1318 result
+= wxString
::Format(wxT("state=%u;"), pane
.state
);
1319 result
+= wxString
::Format(wxT("dir=%d;"), pane
.dock_direction
);
1320 result
+= wxString
::Format(wxT("layer=%d;"), pane
.dock_layer
);
1321 result
+= wxString
::Format(wxT("row=%d;"), pane
.dock_row
);
1322 result
+= wxString
::Format(wxT("pos=%d;"), pane
.dock_pos
);
1323 result
+= wxString
::Format(wxT("prop=%d;"), pane
.dock_proportion
);
1324 result
+= wxString
::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
1325 result
+= wxString
::Format(wxT("besth=%d;"), pane
.best_size
.y
);
1326 result
+= wxString
::Format(wxT("minw=%d;"), pane
.min_size
.x
);
1327 result
+= wxString
::Format(wxT("minh=%d;"), pane
.min_size
.y
);
1328 result
+= wxString
::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
1329 result
+= wxString
::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
1330 result
+= wxString
::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
1331 result
+= wxString
::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
1332 result
+= wxString
::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
1333 result
+= wxString
::Format(wxT("floath=%d"), pane
.floating_size
.y
);
1338 // Load a "pane" with the pane infor settings in pane_part
1339 void wxAuiManager
::LoadPaneInfo(wxString pane_part
, wxAuiPaneInfo
&pane
)
1341 // replace escaped characters so we can
1342 // split up the string easily
1343 pane_part
.Replace(wxT("\\|"), wxT("\a"));
1344 pane_part
.Replace(wxT("\\;"), wxT("\b"));
1348 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
1349 pane_part
= pane_part
.AfterFirst(wxT(';'));
1350 wxString val_name
= val_part
.BeforeFirst(wxT('='));
1351 wxString value
= val_part
.AfterFirst(wxT('='));
1352 val_name
.MakeLower();
1353 val_name
.Trim(true);
1354 val_name
.Trim(false);
1358 if (val_name
.empty())
1361 if (val_name
== wxT("name"))
1363 else if (val_name
== wxT("caption"))
1364 pane
.caption
= value
;
1365 else if (val_name
== wxT("state"))
1366 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1367 else if (val_name
== wxT("dir"))
1368 pane
.dock_direction
= wxAtoi(value
.c_str());
1369 else if (val_name
== wxT("layer"))
1370 pane
.dock_layer
= wxAtoi(value
.c_str());
1371 else if (val_name
== wxT("row"))
1372 pane
.dock_row
= wxAtoi(value
.c_str());
1373 else if (val_name
== wxT("pos"))
1374 pane
.dock_pos
= wxAtoi(value
.c_str());
1375 else if (val_name
== wxT("prop"))
1376 pane
.dock_proportion
= wxAtoi(value
.c_str());
1377 else if (val_name
== wxT("bestw"))
1378 pane
.best_size
.x
= wxAtoi(value
.c_str());
1379 else if (val_name
== wxT("besth"))
1380 pane
.best_size
.y
= wxAtoi(value
.c_str());
1381 else if (val_name
== wxT("minw"))
1382 pane
.min_size
.x
= wxAtoi(value
.c_str());
1383 else if (val_name
== wxT("minh"))
1384 pane
.min_size
.y
= wxAtoi(value
.c_str());
1385 else if (val_name
== wxT("maxw"))
1386 pane
.max_size
.x
= wxAtoi(value
.c_str());
1387 else if (val_name
== wxT("maxh"))
1388 pane
.max_size
.y
= wxAtoi(value
.c_str());
1389 else if (val_name
== wxT("floatx"))
1390 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1391 else if (val_name
== wxT("floaty"))
1392 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1393 else if (val_name
== wxT("floatw"))
1394 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1395 else if (val_name
== wxT("floath"))
1396 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1398 wxFAIL_MSG(wxT("Bad Perspective String"));
1402 // replace escaped characters so we can
1403 // split up the string easily
1404 pane
.name
.Replace(wxT("\a"), wxT("|"));
1405 pane
.name
.Replace(wxT("\b"), wxT(";"));
1406 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1407 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1408 pane_part
.Replace(wxT("\a"), wxT("|"));
1409 pane_part
.Replace(wxT("\b"), wxT(";"));
1415 // SavePerspective() saves all pane information as a single string.
1416 // This string may later be fed into LoadPerspective() to restore
1417 // all pane settings. This save and load mechanism allows an
1418 // exact pane configuration to be saved and restored at a later time
1420 wxString wxAuiManager
::SavePerspective()
1424 result
= wxT("layout2|");
1426 int pane_i
, pane_count
= m_panes
.GetCount();
1427 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1429 wxAuiPaneInfo
& pane
= m_panes
.Item(pane_i
);
1430 result
+= SavePaneInfo(pane
)+wxT("|");
1433 int dock_i
, dock_count
= m_docks
.GetCount();
1434 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1436 wxAuiDockInfo
& dock
= m_docks
.Item(dock_i
);
1438 result
+= wxString
::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1439 dock
.dock_direction
, dock
.dock_layer
,
1440 dock
.dock_row
, dock
.size
);
1446 // LoadPerspective() loads a layout which was saved with SavePerspective()
1447 // If the "update" flag parameter is true, the GUI will immediately be updated
1449 bool wxAuiManager
::LoadPerspective(const wxString
& layout
, bool update
)
1451 wxString input
= layout
;
1454 // check layout string version
1455 // 'layout1' = wxAUI 0.9.0 - wxAUI 0.9.2
1456 // 'layout2' = wxAUI 0.9.2 (wxWidgets 2.8)
1457 part
= input
.BeforeFirst(wxT('|'));
1458 input
= input
.AfterFirst(wxT('|'));
1461 if (part
!= wxT("layout2"))
1464 // mark all panes currently managed as docked and hidden
1465 int pane_i
, pane_count
= m_panes
.GetCount();
1466 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1467 m_panes
.Item(pane_i
).Dock().Hide();
1469 // clear out the dock array; this will be reconstructed
1472 // replace escaped characters so we can
1473 // split up the string easily
1474 input
.Replace(wxT("\\|"), wxT("\a"));
1475 input
.Replace(wxT("\\;"), wxT("\b"));
1481 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1482 input
= input
.AfterFirst(wxT('|'));
1483 pane_part
.Trim(true);
1485 // if the string is empty, we're done parsing
1486 if (pane_part
.empty())
1489 if (pane_part
.Left(9) == wxT("dock_size"))
1491 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1492 wxString value
= pane_part
.AfterFirst(wxT('='));
1494 long dir
, layer
, row
, size
;
1495 wxString piece
= val_name
.AfterFirst(wxT('('));
1496 piece
= piece
.BeforeLast(wxT(')'));
1497 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1498 piece
= piece
.AfterFirst(wxT(','));
1499 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1500 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1501 value
.ToLong(&size
);
1504 dock
.dock_direction
= dir
;
1505 dock
.dock_layer
= layer
;
1506 dock
.dock_row
= row
;
1512 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1513 // name so it can be called by external callers
1514 pane_part
.Replace(wxT("\a"), wxT("|"));
1515 pane_part
.Replace(wxT("\b"), wxT(";"));
1517 LoadPaneInfo(pane_part
, pane
);
1519 wxAuiPaneInfo
& p
= GetPane(pane
.name
);
1522 // the pane window couldn't be found
1523 // in the existing layout -- skip it
1536 void wxAuiManager
::GetPanePositionsAndSizes(wxAuiDockInfo
& dock
,
1537 wxArrayInt
& positions
,
1540 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1541 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1542 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1547 int offset
, action_pane
= -1;
1548 int pane_i
, pane_count
= dock
.panes
.GetCount();
1550 // find the pane marked as our action pane
1551 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1553 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1555 if (pane
.state
& wxAuiPaneInfo
::actionPane
)
1557 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1558 action_pane
= pane_i
;
1562 // set up each panes default position, and
1563 // determine the size (width or height, depending
1564 // on the dock's orientation) of each pane
1565 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1567 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1568 positions
.Add(pane
.dock_pos
);
1571 if (pane
.HasBorder())
1572 size
+= (pane_border_size
*2);
1574 if (dock
.IsHorizontal())
1576 if (pane
.HasGripper() && !pane
.HasGripperTop())
1577 size
+= gripper_size
;
1578 size
+= pane
.best_size
.x
;
1582 if (pane
.HasGripper() && pane
.HasGripperTop())
1583 size
+= gripper_size
;
1585 if (pane
.HasCaption())
1586 size
+= caption_size
;
1587 size
+= pane
.best_size
.y
;
1593 // if there is no action pane, just return the default
1594 // positions (as specified in pane.pane_pos)
1595 if (action_pane
== -1)
1599 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1601 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1606 positions
[pane_i
] -= -amount
;
1608 offset
+= sizes
[pane_i
];
1611 // if the dock mode is fixed, make sure none of the panes
1612 // overlap; we will bump panes that overlap
1614 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1616 int amount
= positions
[pane_i
] - offset
;
1620 positions
[pane_i
] += -amount
;
1622 offset
+= sizes
[pane_i
];
1627 void wxAuiManager
::LayoutAddPane(wxSizer
* cont
,
1628 wxAuiDockInfo
& dock
,
1629 wxAuiPaneInfo
& pane
,
1630 wxAuiDockUIPartArray
& uiparts
,
1633 wxAuiDockUIPart part
;
1634 wxSizerItem
* sizer_item
;
1636 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1637 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1638 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1639 int pane_button_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BUTTON_SIZE
);
1641 // find out the orientation of the item (orientation for panes
1642 // is the same as the dock's orientation)
1644 if (dock
.IsHorizontal())
1645 orientation
= wxHORIZONTAL
;
1647 orientation
= wxVERTICAL
;
1649 // this variable will store the proportion
1650 // value that the pane will receive
1651 int pane_proportion
= pane
.dock_proportion
;
1653 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1654 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1656 if (pane
.HasGripper())
1658 if (pane
.HasGripperTop())
1659 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1661 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1663 part
.type
= wxAuiDockUIPart
::typeGripper
;
1667 part
.orientation
= orientation
;
1668 part
.cont_sizer
= horz_pane_sizer
;
1669 part
.sizer_item
= sizer_item
;
1673 if (pane
.HasCaption())
1675 // create the caption sizer
1676 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1678 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1680 part
.type
= wxAuiDockUIPart
::typeCaption
;
1684 part
.orientation
= orientation
;
1685 part
.cont_sizer
= vert_pane_sizer
;
1686 part
.sizer_item
= sizer_item
;
1687 int caption_part_idx
= uiparts
.GetCount();
1690 // add pane buttons to the caption
1691 int i
, button_count
;
1692 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1693 i
< button_count
; ++i
)
1695 wxAuiPaneButton
& button
= pane
.buttons
.Item(i
);
1697 sizer_item
= caption_sizer
->Add(pane_button_size
,
1701 part
.type
= wxAuiDockUIPart
::typePaneButton
;
1704 part
.button
= &button
;
1705 part
.orientation
= orientation
;
1706 part
.cont_sizer
= caption_sizer
;
1707 part
.sizer_item
= sizer_item
;
1711 // if we have buttons, add a little space to the right
1712 // of them to ease visual crowding
1713 if (button_count
>= 1)
1715 caption_sizer
->Add(3,1);
1718 // add the caption sizer
1719 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1721 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1724 // add the pane window itself
1727 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1731 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1732 // Don't do this because it breaks the pane size in floating windows
1733 // BIW: Right now commenting this out is causing problems with
1734 // an mdi client window as the center pane.
1735 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1738 part
.type
= wxAuiDockUIPart
::typePane
;
1742 part
.orientation
= orientation
;
1743 part
.cont_sizer
= vert_pane_sizer
;
1744 part
.sizer_item
= sizer_item
;
1748 // determine if the pane should have a minimum size; if the pane is
1749 // non-resizable (fixed) then we must set a minimum size. Alternatively,
1750 // if the pane.min_size is set, we must use that value as well
1752 wxSize min_size
= pane
.min_size
;
1755 if (min_size
== wxDefaultSize
)
1757 min_size
= pane
.best_size
;
1758 pane_proportion
= 0;
1762 if (min_size
!= wxDefaultSize
)
1764 vert_pane_sizer
->SetItemMinSize(
1765 vert_pane_sizer
->GetChildren().GetCount()-1,
1766 min_size
.x
, min_size
.y
);
1770 // add the verticle sizer (caption, pane window) to the
1771 // horizontal sizer (gripper, verticle sizer)
1772 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1774 // finally, add the pane sizer to the dock sizer
1776 if (pane
.HasBorder())
1778 // allowing space for the pane's border
1779 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1780 wxEXPAND
| wxALL
, pane_border_size
);
1782 part
.type
= wxAuiDockUIPart
::typePaneBorder
;
1786 part
.orientation
= orientation
;
1787 part
.cont_sizer
= cont
;
1788 part
.sizer_item
= sizer_item
;
1793 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1797 void wxAuiManager
::LayoutAddDock(wxSizer
* cont
,
1798 wxAuiDockInfo
& dock
,
1799 wxAuiDockUIPartArray
& uiparts
,
1802 wxSizerItem
* sizer_item
;
1803 wxAuiDockUIPart part
;
1805 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
1806 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1808 // resizable bottom and right docks have a sash before them
1809 if (!m_has_maximized
&& !dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1810 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1812 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1814 part
.type
= wxAuiDockUIPart
::typeDockSizer
;
1815 part
.orientation
= orientation
;
1819 part
.cont_sizer
= cont
;
1820 part
.sizer_item
= sizer_item
;
1824 // create the sizer for the dock
1825 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1827 // add each pane to the dock
1828 bool has_maximized_pane
= false;
1829 int pane_i
, pane_count
= dock
.panes
.GetCount();
1833 wxArrayInt pane_positions
, pane_sizes
;
1835 // figure out the real pane positions we will
1836 // use, without modifying the each pane's pane_pos member
1837 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1840 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1842 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1843 int pane_pos
= pane_positions
.Item(pane_i
);
1845 if (pane
.IsMaximized())
1846 has_maximized_pane
= true;
1849 int amount
= pane_pos
- offset
;
1852 if (dock
.IsVertical())
1853 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1855 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1857 part
.type
= wxAuiDockUIPart
::typeBackground
;
1861 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1862 part
.cont_sizer
= dock_sizer
;
1863 part
.sizer_item
= sizer_item
;
1869 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1871 offset
+= pane_sizes
.Item(pane_i
);
1874 // at the end add a very small stretchable background area
1875 sizer_item
= dock_sizer
->Add(0,0, 1, wxEXPAND
);
1877 part
.type
= wxAuiDockUIPart
::typeBackground
;
1881 part
.orientation
= orientation
;
1882 part
.cont_sizer
= dock_sizer
;
1883 part
.sizer_item
= sizer_item
;
1888 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1890 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1892 if (pane
.IsMaximized())
1893 has_maximized_pane
= true;
1895 // if this is not the first pane being added,
1896 // we need to add a pane sizer
1897 if (!m_has_maximized
&& pane_i
> 0)
1899 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1901 part
.type
= wxAuiDockUIPart
::typePaneSizer
;
1903 part
.pane
= dock
.panes
.Item(pane_i
-1);
1905 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1906 part
.cont_sizer
= dock_sizer
;
1907 part
.sizer_item
= sizer_item
;
1911 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1915 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
|| has_maximized_pane
)
1916 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1918 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1920 part
.type
= wxAuiDockUIPart
::typeDock
;
1924 part
.orientation
= orientation
;
1925 part
.cont_sizer
= cont
;
1926 part
.sizer_item
= sizer_item
;
1929 if (dock
.IsHorizontal())
1930 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1932 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1934 // top and left docks have a sash after them
1935 if (!m_has_maximized
&&
1937 (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1938 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1940 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1942 part
.type
= wxAuiDockUIPart
::typeDockSizer
;
1946 part
.orientation
= orientation
;
1947 part
.cont_sizer
= cont
;
1948 part
.sizer_item
= sizer_item
;
1953 wxSizer
* wxAuiManager
::LayoutAll(wxAuiPaneInfoArray
& panes
,
1954 wxAuiDockInfoArray
& docks
,
1955 wxAuiDockUIPartArray
& uiparts
,
1958 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1960 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1961 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1962 wxSize cli_size
= m_frame
->GetClientSize();
1963 int i
, dock_count
, pane_count
;
1966 // empty all docks out
1967 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1969 wxAuiDockInfo
& dock
= docks
.Item(i
);
1971 // empty out all panes, as they will be readded below
1976 // always reset fixed docks' sizes, because
1977 // the contained windows may have been resized
1983 // iterate through all known panes, filing each
1984 // of them into the appropriate dock. If the
1985 // pane does not exist in the dock, add it
1986 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1988 wxAuiPaneInfo
& p
= panes
.Item(i
);
1990 // find any docks with the same dock direction, dock layer, and
1991 // dock row as the pane we are working on
1992 wxAuiDockInfo
* dock
;
1993 wxAuiDockInfoPtrArray arr
;
1994 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1996 if (arr
.GetCount() > 0)
1998 // found the right dock
2003 // dock was not found, so we need to create a new one
2005 d
.dock_direction
= p
.dock_direction
;
2006 d
.dock_layer
= p
.dock_layer
;
2007 d
.dock_row
= p
.dock_row
;
2009 dock
= &docks
.Last();
2013 if (p
.IsDocked() && p
.IsShown())
2015 // remove the pane from any existing docks except this one
2016 RemovePaneFromDocks(docks
, p
, dock
);
2018 // pane needs to be added to the dock,
2019 // if it doesn't already exist
2020 if (!FindPaneInDock(*dock
, p
.window
))
2021 dock
->panes
.Add(&p
);
2025 // remove the pane from any existing docks
2026 RemovePaneFromDocks(docks
, p
);
2031 // remove any empty docks
2032 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
2034 if (docks
.Item(i
).panes
.GetCount() == 0)
2038 // configure the docks further
2039 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2041 wxAuiDockInfo
& dock
= docks
.Item(i
);
2042 int j
, dock_pane_count
= dock
.panes
.GetCount();
2044 // sort the dock pane array by the pane's
2045 // dock position (dock_pos), in ascending order
2046 dock
.panes
.Sort(PaneSortFunc
);
2048 // for newly created docks, set up their initial size
2053 for (j
= 0; j
< dock_pane_count
; ++j
)
2055 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2056 wxSize pane_size
= pane
.best_size
;
2057 if (pane_size
== wxDefaultSize
)
2058 pane_size
= pane
.min_size
;
2059 if (pane_size
== wxDefaultSize
)
2060 pane_size
= pane
.window
->GetSize();
2062 if (dock
.IsHorizontal())
2063 size
= wxMax(pane_size
.y
, size
);
2065 size
= wxMax(pane_size
.x
, size
);
2068 // add space for the border (two times), but only
2069 // if at least one pane inside the dock has a pane border
2070 for (j
= 0; j
< dock_pane_count
; ++j
)
2072 if (dock
.panes
.Item(j
)->HasBorder())
2074 size
+= (pane_border_size
*2);
2079 // if pane is on the top or bottom, add the caption height,
2080 // but only if at least one pane inside the dock has a caption
2081 if (dock
.IsHorizontal())
2083 for (j
= 0; j
< dock_pane_count
; ++j
)
2085 if (dock
.panes
.Item(j
)->HasCaption())
2087 size
+= caption_size
;
2094 // new dock's size may not be more than the dock constraint
2095 // parameter specifies. See SetDockSizeConstraint()
2097 int max_dock_x_size
= (int)(m_dock_constraint_x
* ((double)cli_size
.x
));
2098 int max_dock_y_size
= (int)(m_dock_constraint_y
* ((double)cli_size
.y
));
2100 if (dock
.IsHorizontal())
2101 size
= wxMin(size
, max_dock_y_size
);
2103 size
= wxMin(size
, max_dock_x_size
);
2105 // absolute minimum size for a dock is 10 pixels
2113 // determine the dock's minimum size
2114 bool plus_border
= false;
2115 bool plus_caption
= false;
2116 int dock_min_size
= 0;
2117 for (j
= 0; j
< dock_pane_count
; ++j
)
2119 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2120 if (pane
.min_size
!= wxDefaultSize
)
2122 if (pane
.HasBorder())
2124 if (pane
.HasCaption())
2125 plus_caption
= true;
2126 if (dock
.IsHorizontal())
2128 if (pane
.min_size
.y
> dock_min_size
)
2129 dock_min_size
= pane
.min_size
.y
;
2133 if (pane
.min_size
.x
> dock_min_size
)
2134 dock_min_size
= pane
.min_size
.x
;
2140 dock_min_size
+= (pane_border_size
*2);
2141 if (plus_caption
&& dock
.IsHorizontal())
2142 dock_min_size
+= (caption_size
);
2144 dock
.min_size
= dock_min_size
;
2147 // if the pane's current size is less than it's
2148 // minimum, increase the dock's size to it's minimum
2149 if (dock
.size
< dock
.min_size
)
2150 dock
.size
= dock
.min_size
;
2153 // determine the dock's mode (fixed or proportional);
2154 // determine whether the dock has only toolbars
2155 bool action_pane_marked
= false;
2157 dock
.toolbar
= true;
2158 for (j
= 0; j
< dock_pane_count
; ++j
)
2160 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2161 if (!pane
.IsFixed())
2163 if (!pane
.IsToolbar())
2164 dock
.toolbar
= false;
2165 if (pane
.HasFlag(wxAuiPaneInfo
::optionDockFixed
))
2167 if (pane
.state
& wxAuiPaneInfo
::actionPane
)
2168 action_pane_marked
= true;
2172 // if the dock mode is proportional and not fixed-pixel,
2173 // reassign the dock_pos to the sequential 0, 1, 2, 3;
2174 // e.g. remove gaps like 1, 2, 30, 500
2177 for (j
= 0; j
< dock_pane_count
; ++j
)
2179 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2184 // if the dock mode is fixed, and none of the panes
2185 // are being moved right now, make sure the panes
2186 // do not overlap each other. If they do, we will
2187 // adjust the positions of the panes
2188 if (dock
.fixed
&& !action_pane_marked
)
2190 wxArrayInt pane_positions
, pane_sizes
;
2191 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
2194 for (j
= 0; j
< dock_pane_count
; ++j
)
2196 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(j
));
2197 pane
.dock_pos
= pane_positions
[j
];
2199 int amount
= pane
.dock_pos
- offset
;
2203 pane
.dock_pos
+= -amount
;
2205 offset
+= pane_sizes
[j
];
2210 // discover the maximum dock layer
2212 for (i
= 0; i
< dock_count
; ++i
)
2213 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
2216 // clear out uiparts
2219 // create a bunch of box sizers,
2220 // from the innermost level outwards.
2221 wxSizer
* cont
= NULL
;
2222 wxSizer
* middle
= NULL
;
2226 for (layer
= 0; layer
<= max_layer
; ++layer
)
2228 wxAuiDockInfoPtrArray arr
;
2230 // find any docks in this layer
2231 FindDocks(docks
, -1, layer
, -1, arr
);
2233 // if there aren't any, skip to the next layer
2237 wxSizer
* old_cont
= cont
;
2239 // create a container which will hold this layer's
2240 // docks (top, bottom, left, right)
2241 cont
= new wxBoxSizer(wxVERTICAL
);
2244 // find any top docks in this layer
2245 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
2248 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2249 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2253 // fill out the middle layer (which consists
2254 // of left docks, content area and right docks)
2256 middle
= new wxBoxSizer(wxHORIZONTAL
);
2258 // find any left docks in this layer
2259 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
2262 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2263 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2266 // add content dock (or previous layer's sizer
2270 // find any center docks
2271 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
2274 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
2275 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2277 else if (!m_has_maximized
)
2279 // there are no center docks, add a background area
2280 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
2281 wxAuiDockUIPart part
;
2282 part
.type
= wxAuiDockUIPart
::typeBackground
;
2286 part
.cont_sizer
= middle
;
2287 part
.sizer_item
= sizer_item
;
2293 middle
->Add(old_cont
, 1, wxEXPAND
);
2296 // find any right docks in this layer
2297 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
2300 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2301 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2304 cont
->Add(middle
, 1, wxEXPAND
);
2308 // find any bottom docks in this layer
2309 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
2312 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2313 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2320 // no sizer available, because there are no docks,
2321 // therefore we will create a simple background area
2322 cont
= new wxBoxSizer(wxVERTICAL
);
2323 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
2324 wxAuiDockUIPart part
;
2325 part
.type
= wxAuiDockUIPart
::typeBackground
;
2329 part
.cont_sizer
= middle
;
2330 part
.sizer_item
= sizer_item
;
2334 container
->Add(cont
, 1, wxEXPAND
);
2339 // SetDockSizeConstraint() allows the dock constraints to be set. For example,
2340 // specifying values of 0.5, 0.5 will mean that upon dock creation, a dock may
2341 // not be larger than half of the window's size
2343 void wxAuiManager
::SetDockSizeConstraint(double width_pct
, double height_pct
)
2345 m_dock_constraint_x
= wxMax(0.0, wxMin(1.0, width_pct
));
2346 m_dock_constraint_y
= wxMax(0.0, wxMin(1.0, height_pct
));
2349 void wxAuiManager
::GetDockSizeConstraint(double* width_pct
, double* height_pct
) const
2352 *width_pct
= m_dock_constraint_x
;
2355 *height_pct
= m_dock_constraint_y
;
2360 // Update() updates the layout. Whenever changes are made to
2361 // one or more panes, this function should be called. It is the
2362 // external entry point for running the layout engine.
2364 void wxAuiManager
::Update()
2366 m_hover_button
= NULL
;
2369 int i
, pane_count
= m_panes
.GetCount();
2372 // destroy floating panes which have been
2373 // redocked or are becoming non-floating
2374 for (i
= 0; i
< pane_count
; ++i
)
2376 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2378 if (!p
.IsFloating() && p
.frame
)
2380 // because the pane is no longer in a floating, we need to
2381 // reparent it to m_frame and destroy the floating frame
2384 p
.window
->SetSize(1,1);
2387 // the following block is a workaround for bug #1531361
2388 // (see wxWidgets sourceforge page). On wxGTK (only), when
2389 // a frame is shown/hidden, a move event unfortunately
2390 // also gets fired. Because we may be dragging around
2391 // a pane, we need to cancel that action here to prevent
2392 // a spurious crash.
2393 if (m_action_window
== p
.frame
)
2395 if (wxWindow
::GetCapture() == m_frame
)
2396 m_frame
->ReleaseMouse();
2397 m_action
= actionNone
;
2398 m_action_window
= NULL
;
2402 if (p
.frame
->IsShown())
2403 p
.frame
->Show(false);
2405 // reparent to m_frame and destroy the pane
2406 if (m_action_window
== p
.frame
)
2408 m_action_window
= NULL
;
2411 p
.window
->Reparent(m_frame
);
2412 p
.frame
->SetSizer(NULL
);
2419 // delete old sizer first
2420 m_frame
->SetSizer(NULL
);
2422 // create a layout for all of the panes
2423 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
2425 // hide or show panes as necessary,
2426 // and float panes as necessary
2427 for (i
= 0; i
< pane_count
; ++i
)
2429 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2433 if (p
.frame
== NULL
)
2435 // we need to create a frame for this
2436 // pane, which has recently been floated
2437 wxAuiFloatingFrame
* frame
= CreateFloatingFrame(m_frame
, p
);
2439 // on MSW and Mac, if the owner desires transparent dragging, and
2440 // the dragging is happening right now, then the floating
2441 // window should have this style by default
2442 if (m_action
== actionDragFloatingPane
&&
2443 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2444 frame
->SetTransparent(150);
2446 frame
->SetPaneWindow(p
);
2449 if (p
.IsShown() && !frame
->IsShown())
2454 // frame already exists, make sure it's position
2455 // and size reflect the information in wxAuiPaneInfo
2456 if ((p
.frame
->GetPosition() != p
.floating_pos
) || (p
.frame
->GetSize() != p
.floating_size
))
2458 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2459 p
.floating_size
.x
, p
.floating_size
.y
,
2460 wxSIZE_USE_EXISTING
);
2462 p.frame->SetSize(p.floating_pos.x, p.floating_pos.y,
2463 wxDefaultCoord, wxDefaultCoord,
2464 wxSIZE_USE_EXISTING);
2465 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2469 if (p
.frame
->IsShown() != p
.IsShown())
2470 p
.frame
->Show(p
.IsShown());
2475 if (p
.window
->IsShown() != p
.IsShown())
2476 p
.window
->Show(p
.IsShown());
2479 // if "active panes" are no longer allowed, clear
2480 // any optionActive values from the pane states
2481 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2483 p
.state
&= ~wxAuiPaneInfo
::optionActive
;
2488 // keep track of the old window rectangles so we can
2489 // refresh those windows whose rect has changed
2490 wxAuiRectArray old_pane_rects
;
2491 for (i
= 0; i
< pane_count
; ++i
)
2494 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2496 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2499 old_pane_rects
.Add(r
);
2505 // apply the new sizer
2506 m_frame
->SetSizer(sizer
);
2507 m_frame
->SetAutoLayout(false);
2512 // now that the frame layout is done, we need to check
2513 // the new pane rectangles against the old rectangles that
2514 // we saved a few lines above here. If the rectangles have
2515 // changed, the corresponding panes must also be updated
2516 for (i
= 0; i
< pane_count
; ++i
)
2518 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2519 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2521 if (p
.rect
!= old_pane_rects
[i
])
2523 p
.window
->Refresh();
2532 // set frame's minimum size
2535 // N.B. More work needs to be done on frame minimum sizes;
2536 // this is some intresting code that imposes the minimum size,
2537 // but we may want to include a more flexible mechanism or
2538 // options for multiple minimum-size modes, e.g. strict or lax
2539 wxSize min_size = sizer->GetMinSize();
2540 wxSize frame_size = m_frame->GetSize();
2541 wxSize client_size = m_frame->GetClientSize();
2543 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2544 min_size.y+frame_size.y-client_size.y );
2546 m_frame->SetMinSize(minframe_size);
2548 if (frame_size.x < minframe_size.x ||
2549 frame_size.y < minframe_size.y)
2550 sizer->Fit(m_frame);
2555 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2556 // on the frame's main sizer, then measures all the various UI items
2557 // and updates their internal rectangles. This should always be called
2558 // instead of calling m_frame->Layout() directly
2560 void wxAuiManager
::DoFrameLayout()
2565 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2567 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2569 // get the rectangle of the UI part
2570 // originally, this code looked like this:
2571 // part.rect = wxRect(part.sizer_item->GetPosition(),
2572 // part.sizer_item->GetSize());
2573 // this worked quite well, with one exception: the mdi
2574 // client window had a "deferred" size variable
2575 // that returned the wrong size. It looks like
2576 // a bug in wx, because the former size of the window
2577 // was being returned. So, we will retrieve the part's
2578 // rectangle via other means
2581 part
.rect
= part
.sizer_item
->GetRect();
2582 int flag
= part
.sizer_item
->GetFlag();
2583 int border
= part
.sizer_item
->GetBorder();
2586 part
.rect
.y
-= border
;
2587 part
.rect
.height
+= border
;
2591 part
.rect
.x
-= border
;
2592 part
.rect
.width
+= border
;
2594 if (flag
& wxBOTTOM
)
2595 part
.rect
.height
+= border
;
2597 part
.rect
.width
+= border
;
2600 if (part
.type
== wxAuiDockUIPart
::typeDock
)
2601 part
.dock
->rect
= part
.rect
;
2602 if (part
.type
== wxAuiDockUIPart
::typePane
)
2603 part
.pane
->rect
= part
.rect
;
2607 // GetPanePart() looks up the pane the pane border UI part (or the regular
2608 // pane part if there is no border). This allows the caller to get the exact
2609 // rectangle of the pane in question, including decorations like
2610 // caption and border (if any).
2612 wxAuiDockUIPart
* wxAuiManager
::GetPanePart(wxWindow
* wnd
)
2615 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2617 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2618 if (part
.type
== wxAuiDockUIPart
::typePaneBorder
&&
2619 part
.pane
&& part
.pane
->window
== wnd
)
2622 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2624 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2625 if (part
.type
== wxAuiDockUIPart
::typePane
&&
2626 part
.pane
&& part
.pane
->window
== wnd
)
2634 // GetDockPixelOffset() is an internal function which returns
2635 // a dock's offset in pixels from the left side of the window
2636 // (for horizontal docks) or from the top of the window (for
2637 // vertical docks). This value is necessary for calculating
2638 // fixel-pane/toolbar offsets when they are dragged.
2640 int wxAuiManager
::GetDockPixelOffset(wxAuiPaneInfo
& test
)
2642 // the only way to accurately calculate the dock's
2643 // offset is to actually run a theoretical layout
2645 int i
, part_count
, dock_count
;
2646 wxAuiDockInfoArray docks
;
2647 wxAuiPaneInfoArray panes
;
2648 wxAuiDockUIPartArray uiparts
;
2649 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2652 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2653 wxSize client_size
= m_frame
->GetClientSize();
2654 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2657 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2659 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
2660 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2661 part
.sizer_item
->GetSize());
2662 if (part
.type
== wxAuiDockUIPart
::typeDock
)
2663 part
.dock
->rect
= part
.rect
;
2668 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2670 wxAuiDockInfo
& dock
= docks
.Item(i
);
2671 if (test
.dock_direction
== dock
.dock_direction
&&
2672 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2674 if (dock
.IsVertical())
2686 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2687 // if a dock operation is allowed, the new dock position is copied into
2688 // the target info. If the operation was allowed, the function returns true.
2690 bool wxAuiManager
::ProcessDockResult(wxAuiPaneInfo
& target
,
2691 const wxAuiPaneInfo
& new_pos
)
2693 bool allowed
= false;
2694 switch (new_pos
.dock_direction
)
2696 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2697 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2698 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2699 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2709 // DoDrop() is an important function. It basically takes a mouse position,
2710 // and determines where the pane's new position would be. If the pane is to be
2711 // dropped, it performs the drop operation using the specified dock and pane
2712 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2713 // scenario can be performed, giving precise coordinates for drop hints.
2714 // If, however, wxAuiManager:m_docks and wxAuiManager::m_panes are specified
2715 // as parameters, the changes will be made to the main state arrays
2717 const int auiInsertRowPixels
= 10;
2718 const int auiNewRowPixels
= 40;
2719 const int auiLayerInsertPixels
= 40;
2720 const int auiLayerInsertOffset
= 5;
2722 bool wxAuiManager
::DoDrop(wxAuiDockInfoArray
& docks
,
2723 wxAuiPaneInfoArray
& panes
,
2724 wxAuiPaneInfo
& target
,
2726 const wxPoint
& offset
)
2728 wxSize cli_size
= m_frame
->GetClientSize();
2730 wxAuiPaneInfo drop
= target
;
2733 // The result should always be shown
2737 // Check to see if the pane has been dragged outside of the window
2738 // (or near to the outside of the window), if so, dock it along the edge
2741 int layer_insert_offset
= auiLayerInsertOffset
;
2742 if (drop
.IsToolbar())
2743 layer_insert_offset
= 0;
2746 if (pt
.x
< layer_insert_offset
&&
2747 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2749 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2750 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2751 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2753 if (drop
.IsToolbar())
2754 new_layer
= auiToolBarLayer
;
2759 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2760 return ProcessDockResult(target
, drop
);
2762 else if (pt
.y
< layer_insert_offset
&&
2763 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2765 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2766 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2767 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2769 if (drop
.IsToolbar())
2770 new_layer
= auiToolBarLayer
;
2775 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2776 return ProcessDockResult(target
, drop
);
2778 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2779 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2781 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2782 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2783 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2785 if (drop
.IsToolbar())
2786 new_layer
= auiToolBarLayer
;
2788 drop
.Dock().Right().
2791 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2792 return ProcessDockResult(target
, drop
);
2794 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2795 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2797 int new_layer
= wxMax( wxMax( GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2798 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2799 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2801 if (drop
.IsToolbar())
2802 new_layer
= auiToolBarLayer
;
2804 drop
.Dock().Bottom().
2807 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2808 return ProcessDockResult(target
, drop
);
2812 wxAuiDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2815 if (drop
.IsToolbar())
2817 if (!part
|| !part
->dock
)
2820 // calculate the offset from where the dock begins
2821 // to the point where the user dropped the pane
2822 int dock_drop_offset
= 0;
2823 if (part
->dock
->IsHorizontal())
2824 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2826 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2829 // toolbars may only be moved in and to fixed-pane docks,
2830 // otherwise we will try to float the pane. Also, the pane
2831 // should float if being dragged over center pane windows
2832 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2834 if (m_last_rect
.IsEmpty() || m_last_rect
.Contains(pt
.x
, pt
.y
))
2840 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2841 (drop
.IsFloatable() ||
2842 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2843 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2850 return ProcessDockResult(target
, drop
);
2853 drop
.Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2855 return ProcessDockResult(target
, drop
);
2860 m_last_rect
= part
->dock
->rect
;
2861 m_last_rect
.Inflate( 15, 15 );
2864 Direction(part
->dock
->dock_direction
).
2865 Layer(part
->dock
->dock_layer
).
2866 Row(part
->dock
->dock_row
).
2867 Position(dock_drop_offset
);
2870 ((pt
.y
< part
->dock
->rect
.y
+ 1) && part
->dock
->IsHorizontal()) ||
2871 ((pt
.x
< part
->dock
->rect
.x
+ 1) && part
->dock
->IsVertical())
2872 ) && part
->dock
->panes
.GetCount() > 1)
2874 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2875 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2877 int row
= drop
.dock_row
;
2878 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2879 part
->dock
->dock_layer
,
2880 part
->dock
->dock_row
);
2881 drop
.dock_row
= row
;
2885 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2886 part
->dock
->dock_layer
,
2887 part
->dock
->dock_row
+1);
2888 drop
.dock_row
= part
->dock
->dock_row
+1;
2893 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2894 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2895 ) && part
->dock
->panes
.GetCount() > 1)
2897 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2898 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2900 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2901 part
->dock
->dock_layer
,
2902 part
->dock
->dock_row
+1);
2903 drop
.dock_row
= part
->dock
->dock_row
+1;
2907 int row
= drop
.dock_row
;
2908 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2909 part
->dock
->dock_layer
,
2910 part
->dock
->dock_row
);
2911 drop
.dock_row
= row
;
2915 return ProcessDockResult(target
, drop
);
2924 if (part
->type
== wxAuiDockUIPart
::typePaneBorder
||
2925 part
->type
== wxAuiDockUIPart
::typeCaption
||
2926 part
->type
== wxAuiDockUIPart
::typeGripper
||
2927 part
->type
== wxAuiDockUIPart
::typePaneButton
||
2928 part
->type
== wxAuiDockUIPart
::typePane
||
2929 part
->type
== wxAuiDockUIPart
::typePaneSizer
||
2930 part
->type
== wxAuiDockUIPart
::typeDockSizer
||
2931 part
->type
== wxAuiDockUIPart
::typeBackground
)
2933 if (part
->type
== wxAuiDockUIPart
::typeDockSizer
)
2935 if (part
->dock
->panes
.GetCount() != 1)
2937 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2944 // If a normal frame is being dragged over a toolbar, insert it
2945 // along the edge under the toolbar, but over all other panes.
2946 // (this could be done much better, but somehow factoring this
2947 // calculation with the one at the beginning of this function)
2948 if (part
->dock
&& part
->dock
->toolbar
)
2952 switch (part
->dock
->dock_direction
)
2954 case wxAUI_DOCK_LEFT
:
2955 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2956 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2957 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2959 case wxAUI_DOCK_TOP
:
2960 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2961 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2962 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2964 case wxAUI_DOCK_RIGHT
:
2965 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2966 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2967 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2969 case wxAUI_DOCK_BOTTOM
:
2970 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2971 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2972 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2976 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2979 Direction(part
->dock
->dock_direction
).
2980 Layer(layer
).Row(0).Position(0);
2981 return ProcessDockResult(target
, drop
);
2988 part
= GetPanePart(part
->pane
->window
);
2992 bool insert_dock_row
= false;
2993 int insert_row
= part
->pane
->dock_row
;
2994 int insert_dir
= part
->pane
->dock_direction
;
2995 int insert_layer
= part
->pane
->dock_layer
;
2997 switch (part
->pane
->dock_direction
)
2999 case wxAUI_DOCK_TOP
:
3000 if (pt
.y
>= part
->rect
.y
&&
3001 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
3002 insert_dock_row
= true;
3004 case wxAUI_DOCK_BOTTOM
:
3005 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
3006 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
3007 insert_dock_row
= true;
3009 case wxAUI_DOCK_LEFT
:
3010 if (pt
.x
>= part
->rect
.x
&&
3011 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
3012 insert_dock_row
= true;
3014 case wxAUI_DOCK_RIGHT
:
3015 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
3016 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
3017 insert_dock_row
= true;
3019 case wxAUI_DOCK_CENTER
:
3021 // "new row pixels" will be set to the default, but
3022 // must never exceed 20% of the window size
3023 int new_row_pixels_x
= auiNewRowPixels
;
3024 int new_row_pixels_y
= auiNewRowPixels
;
3026 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
3027 new_row_pixels_x
= (part
->rect
.width
*20)/100;
3029 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
3030 new_row_pixels_y
= (part
->rect
.height
*20)/100;
3033 // determine if the mouse pointer is in a location that
3034 // will cause a new row to be inserted. The hot spot positions
3035 // are along the borders of the center pane
3038 insert_dock_row
= true;
3039 const wxRect
& pr
= part
->rect
;
3040 if (pt
.x
>= pr
.x
&& pt
.x
< pr
.x
+ new_row_pixels_x
)
3041 insert_dir
= wxAUI_DOCK_LEFT
;
3042 else if (pt
.y
>= pr
.y
&& pt
.y
< pr
.y
+ new_row_pixels_y
)
3043 insert_dir
= wxAUI_DOCK_TOP
;
3044 else if (pt
.x
>= pr
.x
+ pr
.width
- new_row_pixels_x
&&
3045 pt
.x
< pr
.x
+ pr
.width
)
3046 insert_dir
= wxAUI_DOCK_RIGHT
;
3047 else if (pt
.y
>= pr
.y
+ pr
.height
- new_row_pixels_y
&&
3048 pt
.y
< pr
.y
+ pr
.height
)
3049 insert_dir
= wxAUI_DOCK_BOTTOM
;
3053 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
3057 if (insert_dock_row
)
3059 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
3060 drop
.Dock().Direction(insert_dir
).
3061 Layer(insert_layer
).
3064 return ProcessDockResult(target
, drop
);
3067 // determine the mouse offset and the pane size, both in the
3068 // direction of the dock itself, and perpendicular to the dock
3072 if (part
->orientation
== wxVERTICAL
)
3074 offset
= pt
.y
- part
->rect
.y
;
3075 size
= part
->rect
.GetHeight();
3079 offset
= pt
.x
- part
->rect
.x
;
3080 size
= part
->rect
.GetWidth();
3083 int drop_position
= part
->pane
->dock_pos
;
3085 // if we are in the top/left part of the pane,
3086 // insert the pane before the pane being hovered over
3087 if (offset
<= size
/2)
3089 drop_position
= part
->pane
->dock_pos
;
3091 part
->pane
->dock_direction
,
3092 part
->pane
->dock_layer
,
3093 part
->pane
->dock_row
,
3094 part
->pane
->dock_pos
);
3097 // if we are in the bottom/right part of the pane,
3098 // insert the pane before the pane being hovered over
3099 if (offset
> size
/2)
3101 drop_position
= part
->pane
->dock_pos
+1;
3103 part
->pane
->dock_direction
,
3104 part
->pane
->dock_layer
,
3105 part
->pane
->dock_row
,
3106 part
->pane
->dock_pos
+1);
3110 Direction(part
->dock
->dock_direction
).
3111 Layer(part
->dock
->dock_layer
).
3112 Row(part
->dock
->dock_row
).
3113 Position(drop_position
);
3114 return ProcessDockResult(target
, drop
);
3121 void wxAuiManager
::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
3123 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
3125 m_hint_fadetimer
.Stop();
3129 m_hint_fadeamt
+= 4;
3130 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
3133 void wxAuiManager
::ShowHint(const wxRect
& rect
)
3137 // if the hint rect is the same as last time, don't do anything
3138 if (m_last_hint
== rect
)
3142 m_hint_fadeamt
= m_hint_fademax
;
3144 if ((m_flags
& wxAUI_MGR_HINT_FADE
)
3145 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
3146 (m_flags
& wxAUI_MGR_NO_VENETIAN_BLINDS_FADE
))
3150 m_hint_wnd
->SetSize(rect
);
3151 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
3153 if (!m_hint_wnd
->IsShown())
3156 // if we are dragging a floating pane, set the focus
3157 // back to that floating pane (otherwise it becomes unfocused)
3158 if (m_action
== actionDragFloatingPane
&& m_action_window
)
3159 m_action_window
->SetFocus();
3161 m_hint_wnd
->Raise();
3164 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
3166 // start fade in timer
3167 m_hint_fadetimer
.SetOwner(this, 101);
3168 m_hint_fadetimer
.Start(5);
3171 else // Not using a transparent hint window...
3173 if (!(m_flags
& wxAUI_MGR_RECTANGLE_HINT
))
3176 if (m_last_hint
!= rect
)
3178 // remove the last hint rectangle
3184 wxScreenDC screendc
;
3185 wxRegion
clip(1, 1, 10000, 10000);
3187 // clip all floating windows, so we don't draw over them
3189 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
3191 wxAuiPaneInfo
& pane
= m_panes
.Item(i
);
3193 if (pane
.IsFloating() &&
3194 pane
.frame
->IsShown())
3196 wxRect rect
= pane
.frame
->GetRect();
3198 // wxGTK returns the client size, not the whole frame size
3204 clip
.Subtract(rect
);
3208 // As we can only hide the hint by redrawing the managed window, we
3209 // need to clip the region to the managed window too or we get
3210 // nasty redrawn problems.
3211 clip
.Intersect(m_frame
->GetRect());
3213 screendc
.SetClippingRegion(clip
);
3215 wxBitmap stipple
= wxPaneCreateStippleBitmap();
3216 wxBrush
brush(stipple
);
3217 screendc
.SetBrush(brush
);
3218 screendc
.SetPen(*wxTRANSPARENT_PEN
);
3220 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
3221 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
3222 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
3223 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
3227 void wxAuiManager
::HideHint()
3229 // hides a transparent window hint, if there is one
3232 if (m_hint_wnd
->IsShown())
3233 m_hint_wnd
->Show(false);
3234 m_hint_wnd
->SetTransparent(0);
3235 m_hint_fadetimer
.Stop();
3236 m_last_hint
= wxRect();
3240 // hides a painted hint by redrawing the frame window
3241 if (!m_last_hint
.IsEmpty())
3245 m_last_hint
= wxRect();
3251 void wxAuiManager
::StartPaneDrag(wxWindow
* pane_window
,
3252 const wxPoint
& offset
)
3254 wxAuiPaneInfo
& pane
= GetPane(pane_window
);
3258 if (pane
.IsToolbar())
3260 m_action
= actionDragToolbarPane
;
3264 m_action
= actionDragFloatingPane
;
3267 m_action_window
= pane_window
;
3268 m_action_offset
= offset
;
3269 m_frame
->CaptureMouse();
3273 // CalculateHintRect() calculates the drop hint rectangle. The method
3274 // first calls DoDrop() to determine the exact position the pane would
3275 // be at were if dropped. If the pane would indeed become docked at the
3276 // specified drop point, the the rectangle hint will be returned in
3277 // screen coordinates. Otherwise, an empty rectangle is returned.
3278 // |pane_window| is the window pointer of the pane being dragged, |pt| is
3279 // the mouse position, in client coordinates. |offset| describes the offset
3280 // that the mouse is from the upper-left corner of the item being dragged
3282 wxRect wxAuiManager
::CalculateHintRect(wxWindow
* pane_window
,
3284 const wxPoint
& offset
)
3288 // we need to paint a hint rectangle; to find out the exact hint rectangle,
3289 // we will create a new temporary layout and then measure the resulting
3290 // rectangle; we will create a copy of the docking structures (m_dock)
3291 // so that we don't modify the real thing on screen
3293 int i
, pane_count
, part_count
;
3294 wxAuiDockInfoArray docks
;
3295 wxAuiPaneInfoArray panes
;
3296 wxAuiDockUIPartArray uiparts
;
3297 wxAuiPaneInfo hint
= GetPane(pane_window
);
3298 hint
.name
= wxT("__HINT__");
3299 hint
.PaneBorder(true);
3305 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3307 // remove any pane already there which bears the same window;
3308 // this happens when you are moving a pane around in a dock
3309 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
3311 if (panes
.Item(i
).window
== pane_window
)
3313 RemovePaneFromDocks(docks
, panes
.Item(i
));
3319 // find out where the new pane would be
3320 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
3327 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
3328 wxSize client_size
= m_frame
->GetClientSize();
3329 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
3332 for (i
= 0, part_count
= uiparts
.GetCount();
3333 i
< part_count
; ++i
)
3335 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
3337 if (part
.type
== wxAuiDockUIPart
::typePaneBorder
&&
3338 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
3340 rect
= wxRect(part
.sizer_item
->GetPosition(),
3341 part
.sizer_item
->GetSize());
3353 // actually show the hint rectangle on the screen
3354 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
3356 if ( m_frame
->GetLayoutDirection() == wxLayout_RightToLeft
)
3358 // Mirror rectangle in RTL mode
3359 rect
.x
-= rect
.GetWidth();
3365 // DrawHintRect() calculates the hint rectangle by calling
3366 // CalculateHintRect(). If there is a rectangle, it shows it
3367 // by calling ShowHint(), otherwise it hides any hint
3368 // rectangle currently shown
3369 void wxAuiManager
::DrawHintRect(wxWindow
* pane_window
,
3371 const wxPoint
& offset
)
3373 wxRect rect
= CalculateHintRect(pane_window
, pt
, offset
);
3385 void wxAuiManager
::OnFloatingPaneMoveStart(wxWindow
* wnd
)
3387 // try to find the pane
3388 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3389 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3391 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3392 pane
.frame
->SetTransparent(150);
3395 void wxAuiManager
::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
3397 // try to find the pane
3398 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3399 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3401 wxPoint pt
= ::wxGetMousePosition();
3404 // Adapt pt to direction
3407 // move to pane's upper border
3409 pos
= wnd
->ClientToScreen( pos
);
3411 // and some more pixels for the title bar
3414 else if (dir
== wxWEST
)
3416 // move to pane's left border
3418 pos
= wnd
->ClientToScreen( pos
);
3421 else if (dir
== wxEAST
)
3423 // move to pane's right border
3424 wxPoint
pos( wnd
->GetSize().x
, 0 );
3425 pos
= wnd
->ClientToScreen( pos
);
3428 else if (dir
== wxSOUTH
)
3430 // move to pane's bottom border
3431 wxPoint
pos( 0, wnd
->GetSize().y
);
3432 pos
= wnd
->ClientToScreen( pos
);
3439 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3441 // calculate the offset from the upper left-hand corner
3442 // of the frame to the mouse pointer
3443 wxPoint frame_pos
= pane
.frame
->GetPosition();
3444 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3446 // no hint for toolbar floating windows
3447 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
3449 wxAuiDockInfoArray docks
;
3450 wxAuiPaneInfoArray panes
;
3451 wxAuiDockUIPartArray uiparts
;
3452 wxAuiPaneInfo hint
= pane
;
3454 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3456 // find out where the new pane would be
3457 if (!DoDrop(docks
, panes
, hint
, client_pt
))
3459 if (hint
.IsFloating())
3463 m_action
= actionDragToolbarPane
;
3464 m_action_window
= pane
.window
;
3472 // if a key modifier is pressed while dragging the frame,
3473 // don't dock the window
3474 if (!CanDockPanel(pane
))
3481 DrawHintRect(wnd
, client_pt
, action_offset
);
3484 // this cleans up some screen artifacts that are caused on GTK because
3485 // we aren't getting the exact size of the window (see comment
3495 void wxAuiManager
::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
3497 // try to find the pane
3498 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3499 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3501 wxPoint pt
= ::wxGetMousePosition();
3504 // Adapt pt to direction
3507 // move to pane's upper border
3509 pos
= wnd
->ClientToScreen( pos
);
3511 // and some more pixels for the title bar
3514 else if (dir
== wxWEST
)
3516 // move to pane's left border
3518 pos
= wnd
->ClientToScreen( pos
);
3521 else if (dir
== wxEAST
)
3523 // move to pane's right border
3524 wxPoint
pos( wnd
->GetSize().x
, 0 );
3525 pos
= wnd
->ClientToScreen( pos
);
3528 else if (dir
== wxSOUTH
)
3530 // move to pane's bottom border
3531 wxPoint
pos( 0, wnd
->GetSize().y
);
3532 pos
= wnd
->ClientToScreen( pos
);
3539 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3541 // calculate the offset from the upper left-hand corner
3542 // of the frame to the mouse pointer
3543 wxPoint frame_pos
= pane
.frame
->GetPosition();
3544 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3547 // if a key modifier is pressed while dragging the frame,
3548 // don't dock the window
3549 if (CanDockPanel(pane
))
3551 // do the drop calculation
3552 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3555 // if the pane is still floating, update it's floating
3556 // position (that we store)
3557 if (pane
.IsFloating())
3559 pane
.floating_pos
= pane
.frame
->GetPosition();
3561 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3562 pane
.frame
->SetTransparent(255);
3564 else if (m_has_maximized
)
3566 RestoreMaximizedPane();
3574 void wxAuiManager
::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3576 // try to find the pane
3577 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3578 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3580 pane
.floating_size
= size
;
3584 void wxAuiManager
::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3586 // try to find the pane
3587 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3588 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3591 // fire pane close event
3592 wxAuiManagerEvent
e(wxEVT_AUI_PANE_CLOSE
);
3594 e
.SetCanVeto(evt
.CanVeto());
3604 // close the pane, but check that it
3605 // still exists in our pane array first
3606 // (the event handler above might have removed it)
3608 wxAuiPaneInfo
& check
= GetPane(wnd
);
3618 void wxAuiManager
::OnFloatingPaneActivated(wxWindow
* wnd
)
3620 if ((GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
) && GetPane(wnd
).IsOk())
3622 SetActivePane(m_panes
, wnd
);
3627 // OnRender() draws all of the pane captions, sashes,
3628 // backgrounds, captions, grippers, pane borders and buttons.
3629 // It renders the entire user interface.
3631 void wxAuiManager
::OnRender(wxAuiManagerEvent
& evt
)
3633 // if the frame is about to be deleted, don't bother
3634 if (!m_frame
|| wxPendingDelete
.Member(m_frame
))
3637 wxDC
* dc
= evt
.GetDC();
3643 for (i
= 0, part_count
= m_uiparts
.GetCount();
3644 i
< part_count
; ++i
)
3646 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
3648 // don't draw hidden pane items or items that aren't windows
3649 if (part
.sizer_item
&& ((!part
.sizer_item
->IsWindow() && !part
.sizer_item
->IsSpacer() && !part
.sizer_item
->IsSizer()) || !part
.sizer_item
->IsShown()))
3654 case wxAuiDockUIPart
::typeDockSizer
:
3655 case wxAuiDockUIPart
::typePaneSizer
:
3656 m_art
->DrawSash(*dc
, m_frame
, part
.orientation
, part
.rect
);
3658 case wxAuiDockUIPart
::typeBackground
:
3659 m_art
->DrawBackground(*dc
, m_frame
, part
.orientation
, part
.rect
);
3661 case wxAuiDockUIPart
::typeCaption
:
3662 m_art
->DrawCaption(*dc
, m_frame
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3664 case wxAuiDockUIPart
::typeGripper
:
3665 m_art
->DrawGripper(*dc
, m_frame
, part
.rect
, *part
.pane
);
3667 case wxAuiDockUIPart
::typePaneBorder
:
3668 m_art
->DrawBorder(*dc
, m_frame
, part
.rect
, *part
.pane
);
3670 case wxAuiDockUIPart
::typePaneButton
:
3671 m_art
->DrawPaneButton(*dc
, m_frame
, part
.button
->button_id
,
3672 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3679 // Render() fire a render event, which is normally handled by
3680 // wxAuiManager::OnRender(). This allows the render function to
3681 // be overridden via the render event. This can be useful for paintin
3682 // custom graphics in the main window. Default behavior can be
3683 // invoked in the overridden function by calling OnRender()
3685 void wxAuiManager
::Render(wxDC
* dc
)
3687 wxAuiManagerEvent
e(wxEVT_AUI_RENDER
);
3693 void wxAuiManager
::Repaint(wxDC
* dc
)
3698 m_frame
->Refresh() ;
3704 m_frame
->GetClientSize(&w
, &h
);
3706 // figure out which dc to use; if one
3707 // has been specified, use it, otherwise
3709 wxClientDC
* client_dc
= NULL
;
3712 client_dc
= new wxClientDC(m_frame
);
3716 // if the frame has a toolbar, the client area
3717 // origin will not be (0,0).
3718 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3719 if (pt
.x
!= 0 || pt
.y
!= 0)
3720 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3722 // render all the items
3725 // if we created a client_dc, delete it
3730 void wxAuiManager
::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3732 wxPaintDC
dc(m_frame
);
3736 void wxAuiManager
::OnEraseBackground(wxEraseEvent
& event
)
3745 void wxAuiManager
::OnSize(wxSizeEvent
& event
)
3753 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
3755 // for MDI parent frames, this event must not
3756 // be "skipped". In other words, the parent frame
3757 // must not be allowed to resize the client window
3758 // after we are finished processing sizing changes
3766 void wxAuiManager
::OnFindManager(wxAuiManagerEvent
& evt
)
3768 // get the window we are managing, if none, return NULL
3769 wxWindow
* window
= GetManagedWindow();
3772 evt
.SetManager(NULL
);
3776 // if we are managing a child frame, get the 'real' manager
3777 if (window
->IsKindOf(CLASSINFO(wxAuiFloatingFrame
)))
3779 wxAuiFloatingFrame
* float_frame
= static_cast<wxAuiFloatingFrame
*>(window
);
3780 evt
.SetManager(float_frame
->GetOwnerManager());
3784 // return pointer to ourself
3785 evt
.SetManager(this);
3788 void wxAuiManager
::OnSetCursor(wxSetCursorEvent
& event
)
3791 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3792 wxCursor cursor
= wxNullCursor
;
3796 if (part
->type
== wxAuiDockUIPart
::typeDockSizer
||
3797 part
->type
== wxAuiDockUIPart
::typePaneSizer
)
3799 // a dock may not be resized if it has a single
3800 // pane which is not resizable
3801 if (part
->type
== wxAuiDockUIPart
::typeDockSizer
&& part
->dock
&&
3802 part
->dock
->panes
.GetCount() == 1 &&
3803 part
->dock
->panes
.Item(0)->IsFixed())
3806 // panes that may not be resized do not get a sizing cursor
3807 if (part
->pane
&& part
->pane
->IsFixed())
3810 if (part
->orientation
== wxVERTICAL
)
3811 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3813 cursor
= wxCursor(wxCURSOR_SIZENS
);
3815 else if (part
->type
== wxAuiDockUIPart
::typeGripper
)
3817 cursor
= wxCursor(wxCURSOR_SIZING
);
3821 event
.SetCursor(cursor
);
3826 void wxAuiManager
::UpdateButtonOnScreen(wxAuiDockUIPart
* button_ui_part
,
3827 const wxMouseEvent
& event
)
3829 wxAuiDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3830 if (!hit_test
|| !button_ui_part
)
3833 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3835 if (hit_test
== button_ui_part
)
3837 if (event
.LeftDown())
3838 state
= wxAUI_BUTTON_STATE_PRESSED
;
3840 state
= wxAUI_BUTTON_STATE_HOVER
;
3844 if (event
.LeftDown())
3845 state
= wxAUI_BUTTON_STATE_HOVER
;
3848 // now repaint the button with hover state
3849 wxClientDC
cdc(m_frame
);
3851 // if the frame has a toolbar, the client area
3852 // origin will not be (0,0).
3853 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3854 if (pt
.x
!= 0 || pt
.y
!= 0)
3855 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3859 m_art
->DrawPaneButton(cdc
, m_frame
,
3860 button_ui_part
->button
->button_id
,
3862 button_ui_part
->rect
,
3867 void wxAuiManager
::OnLeftDown(wxMouseEvent
& event
)
3869 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3872 if (part
->type
== wxAuiDockUIPart
::typeDockSizer
||
3873 part
->type
== wxAuiDockUIPart
::typePaneSizer
)
3875 // Removing this restriction so that a centre pane can be resized
3876 //if (part->dock && part->dock->dock_direction == wxAUI_DOCK_CENTER)
3879 // a dock may not be resized if it has a single
3880 // pane which is not resizable
3881 if (part
->type
== wxAuiDockUIPart
::typeDockSizer
&& part
->dock
&&
3882 part
->dock
->panes
.GetCount() == 1 &&
3883 part
->dock
->panes
.Item(0)->IsFixed())
3886 // panes that may not be resized should be ignored here
3887 if (part
->pane
&& part
->pane
->IsFixed())
3890 m_action
= actionResize
;
3891 m_action_part
= part
;
3892 m_action_hintrect
= wxRect();
3893 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3894 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3895 event
.m_y
- part
->rect
.y
);
3896 m_frame
->CaptureMouse();
3898 else if (part
->type
== wxAuiDockUIPart
::typePaneButton
)
3900 m_action
= actionClickButton
;
3901 m_action_part
= part
;
3902 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3903 m_frame
->CaptureMouse();
3905 UpdateButtonOnScreen(part
, event
);
3907 else if (part
->type
== wxAuiDockUIPart
::typeCaption
||
3908 part
->type
== wxAuiDockUIPart
::typeGripper
)
3910 // if we are managing a wxAuiFloatingFrame window, then
3911 // we are an embedded wxAuiManager inside the wxAuiFloatingFrame.
3912 // We want to initiate a toolbar drag in our owner manager
3913 wxWindow
* managed_wnd
= GetManagedWindow();
3916 part
->pane
->window
&&
3918 managed_wnd
->IsKindOf(CLASSINFO(wxAuiFloatingFrame
)))
3920 wxAuiFloatingFrame
* floating_frame
= (wxAuiFloatingFrame
*)managed_wnd
;
3921 wxAuiManager
* owner_mgr
= floating_frame
->GetOwnerManager();
3922 owner_mgr
->StartPaneDrag(part
->pane
->window
,
3923 wxPoint(event
.m_x
- part
->rect
.x
,
3924 event
.m_y
- part
->rect
.y
));
3930 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3932 // set the caption as active
3933 SetActivePane(m_panes
, part
->pane
->window
);
3937 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3940 m_action
= actionClickCaption
;
3941 m_action_part
= part
;
3942 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3943 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3944 event
.m_y
- part
->rect
.y
);
3945 m_frame
->CaptureMouse();
3965 void wxAuiManager
::OnLeftUp(wxMouseEvent
& event
)
3967 if (m_action
== actionResize
)
3969 m_frame
->ReleaseMouse();
3971 // get rid of the hint rectangle
3973 DrawResizeHint(dc
, m_action_hintrect
);
3975 // resize the dock or the pane
3976 if (m_action_part
&& m_action_part
->type
==wxAuiDockUIPart
::typeDockSizer
)
3978 wxRect
& rect
= m_action_part
->dock
->rect
;
3980 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3981 event
.m_y
- m_action_offset
.y
);
3983 switch (m_action_part
->dock
->dock_direction
)
3985 case wxAUI_DOCK_LEFT
:
3986 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3988 case wxAUI_DOCK_TOP
:
3989 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3991 case wxAUI_DOCK_RIGHT
:
3992 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3993 new_pos
.x
- m_action_part
->rect
.GetWidth();
3995 case wxAUI_DOCK_BOTTOM
:
3996 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3997 new_pos
.y
- m_action_part
->rect
.GetHeight();
4004 else if (m_action_part
&&
4005 m_action_part
->type
== wxAuiDockUIPart
::typePaneSizer
)
4007 wxAuiDockInfo
& dock
= *m_action_part
->dock
;
4008 wxAuiPaneInfo
& pane
= *m_action_part
->pane
;
4010 int total_proportion
= 0;
4011 int dock_pixels
= 0;
4012 int new_pixsize
= 0;
4014 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
4015 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
4016 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
4018 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
4019 event
.m_y
- m_action_offset
.y
);
4021 // determine the pane rectangle by getting the pane part
4022 wxAuiDockUIPart
* pane_part
= GetPanePart(pane
.window
);
4023 wxASSERT_MSG(pane_part
,
4024 wxT("Pane border part not found -- shouldn't happen"));
4026 // determine the new pixel size that the user wants;
4027 // this will help us recalculate the pane's proportion
4028 if (dock
.IsHorizontal())
4029 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
4031 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
4033 // determine the size of the dock, based on orientation
4034 if (dock
.IsHorizontal())
4035 dock_pixels
= dock
.rect
.GetWidth();
4037 dock_pixels
= dock
.rect
.GetHeight();
4039 // determine the total proportion of all resizable panes,
4040 // and the total size of the dock minus the size of all
4042 int i
, dock_pane_count
= dock
.panes
.GetCount();
4043 int pane_position
= -1;
4044 for (i
= 0; i
< dock_pane_count
; ++i
)
4046 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
4047 if (p
.window
== pane
.window
)
4050 // while we're at it, subtract the pane sash
4051 // width from the dock width, because this would
4052 // skew our proportion calculations
4054 dock_pixels
-= sash_size
;
4056 // also, the whole size (including decorations) of
4057 // all fixed panes must also be subtracted, because they
4058 // are not part of the proportion calculation
4061 if (dock
.IsHorizontal())
4062 dock_pixels
-= p
.best_size
.x
;
4064 dock_pixels
-= p
.best_size
.y
;
4068 total_proportion
+= p
.dock_proportion
;
4072 // find a pane in our dock to 'steal' space from or to 'give'
4073 // space to -- this is essentially what is done when a pane is
4074 // resized; the pane should usually be the first non-fixed pane
4075 // to the right of the action pane
4076 int borrow_pane
= -1;
4077 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
4079 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
4088 // demand that the pane being resized is found in this dock
4089 // (this assert really never should be raised)
4090 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
4092 // prevent division by zero
4093 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
4095 m_action
= actionNone
;
4099 // calculate the new proportion of the pane
4100 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
4102 // default minimum size
4105 // check against the pane's minimum size, if specified. please note
4106 // that this is not enough to ensure that the minimum size will
4107 // not be violated, because the whole frame might later be shrunk,
4108 // causing the size of the pane to violate it's minimum size
4109 if (pane
.min_size
.IsFullySpecified())
4113 if (pane
.HasBorder())
4114 min_size
+= (pane_border_size
*2);
4116 // calculate minimum size with decorations (border,caption)
4117 if (pane_part
->orientation
== wxVERTICAL
)
4119 min_size
+= pane
.min_size
.y
;
4120 if (pane
.HasCaption())
4121 min_size
+= caption_size
;
4125 min_size
+= pane
.min_size
.x
;
4130 // for some reason, an arithmatic error somewhere is causing
4131 // the proportion calculations to always be off by 1 pixel;
4132 // for now we will add the 1 pixel on, but we really should
4133 // determine what's causing this.
4136 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
4138 if (new_proportion
< min_proportion
)
4139 new_proportion
= min_proportion
;
4143 int prop_diff
= new_proportion
- pane
.dock_proportion
;
4145 // borrow the space from our neighbor pane to the
4146 // right or bottom (depending on orientation)
4147 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
4148 pane
.dock_proportion
= new_proportion
;
4155 else if (m_action
== actionClickButton
)
4157 m_hover_button
= NULL
;
4158 m_frame
->ReleaseMouse();
4159 UpdateButtonOnScreen(m_action_part
, event
);
4161 // make sure we're still over the item that was originally clicked
4162 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
4164 // fire button-click event
4165 wxAuiManagerEvent
e(wxEVT_AUI_PANE_BUTTON
);
4167 e
.SetPane(m_action_part
->pane
);
4168 e
.SetButton(m_action_part
->button
->button_id
);
4172 else if (m_action
== actionClickCaption
)
4174 m_frame
->ReleaseMouse();
4176 else if (m_action
== actionDragFloatingPane
)
4178 m_frame
->ReleaseMouse();
4180 else if (m_action
== actionDragToolbarPane
)
4182 m_frame
->ReleaseMouse();
4184 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4185 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4187 // save the new positions
4188 wxAuiDockInfoPtrArray docks
;
4189 FindDocks(m_docks
, pane
.dock_direction
,
4190 pane
.dock_layer
, pane
.dock_row
, docks
);
4191 if (docks
.GetCount() == 1)
4193 wxAuiDockInfo
& dock
= *docks
.Item(0);
4195 wxArrayInt pane_positions
, pane_sizes
;
4196 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
4198 int i
, dock_pane_count
= dock
.panes
.GetCount();
4199 for (i
= 0; i
< dock_pane_count
; ++i
)
4200 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
4203 pane
.state
&= ~wxAuiPaneInfo
::actionPane
;
4211 m_action
= actionNone
;
4212 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
4216 void wxAuiManager
::OnMotion(wxMouseEvent
& event
)
4218 // sometimes when Update() is called from inside this method,
4219 // a spurious mouse move event is generated; this check will make
4220 // sure that only real mouse moves will get anywhere in this method;
4221 // this appears to be a bug somewhere, and I don't know where the
4222 // mouse move event is being generated. only verified on MSW
4224 wxPoint mouse_pos
= event
.GetPosition();
4225 if (m_last_mouse_move
== mouse_pos
)
4227 m_last_mouse_move
= mouse_pos
;
4230 if (m_action
== actionResize
)
4232 wxPoint pos
= m_action_part
->rect
.GetPosition();
4233 if (m_action_part
->orientation
== wxHORIZONTAL
)
4234 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
4236 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
4238 wxRect
rect(m_frame
->ClientToScreen(pos
),
4239 m_action_part
->rect
.GetSize());
4242 if (!m_action_hintrect
.IsEmpty())
4243 DrawResizeHint(dc
, m_action_hintrect
);
4244 DrawResizeHint(dc
, rect
);
4245 m_action_hintrect
= rect
;
4247 else if (m_action
== actionClickCaption
)
4249 int drag_x_threshold
= wxSystemSettings
::GetMetric(wxSYS_DRAG_X
);
4250 int drag_y_threshold
= wxSystemSettings
::GetMetric(wxSYS_DRAG_Y
);
4252 // caption has been clicked. we need to check if the mouse
4253 // is now being dragged. if it is, we need to change the
4254 // mouse action to 'drag'
4255 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
4256 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
4258 wxAuiPaneInfo
* pane_info
= m_action_part
->pane
;
4260 if (!pane_info
->IsToolbar())
4262 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
4263 pane_info
->IsFloatable())
4265 m_action
= actionDragFloatingPane
;
4267 // set initial float position
4268 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4269 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4270 pt
.y
- m_action_offset
.y
);
4273 if (pane_info
->IsMaximized())
4274 RestorePane(*pane_info
);
4278 m_action_window
= pane_info
->frame
;
4280 // action offset is used here to make it feel "natural" to the user
4281 // to drag a docked pane and suddenly have it become a floating frame.
4282 // Sometimes, however, the offset where the user clicked on the docked
4283 // caption is bigger than the width of the floating frame itself, so
4284 // in that case we need to set the action offset to a sensible value
4285 wxSize frame_size
= m_action_window
->GetSize();
4286 if (frame_size
.x
<= m_action_offset
.x
)
4287 m_action_offset
.x
= 30;
4292 m_action
= actionDragToolbarPane
;
4293 m_action_window
= pane_info
->window
;
4297 else if (m_action
== actionDragFloatingPane
)
4299 if (m_action_window
)
4301 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4302 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
4303 pt
.y
- m_action_offset
.y
);
4306 else if (m_action
== actionDragToolbarPane
)
4308 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4309 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4311 pane
.state
|= wxAuiPaneInfo
::actionPane
;
4313 wxPoint pt
= event
.GetPosition();
4314 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
4316 // if DoDrop() decided to float the pane, set up
4317 // the floating pane's initial position
4318 if (pane
.IsFloating())
4320 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4321 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4322 pt
.y
- m_action_offset
.y
);
4325 // this will do the actiual move operation;
4326 // in the case that the pane has been floated,
4327 // this call will create the floating pane
4328 // and do the reparenting
4331 // if the pane has been floated, change the mouse
4332 // action actionDragFloatingPane so that subsequent
4333 // EVT_MOTION() events will move the floating pane
4334 if (pane
.IsFloating())
4336 pane
.state
&= ~wxAuiPaneInfo
::actionPane
;
4337 m_action
= actionDragFloatingPane
;
4338 m_action_window
= pane
.frame
;
4343 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
4344 if (part
&& part
->type
== wxAuiDockUIPart
::typePaneButton
)
4346 if (part
!= m_hover_button
)
4348 // make the old button normal
4351 UpdateButtonOnScreen(m_hover_button
, event
);
4355 // mouse is over a button, so repaint the
4356 // button in hover mode
4357 UpdateButtonOnScreen(part
, event
);
4358 m_hover_button
= part
;
4366 m_hover_button
= NULL
;
4377 void wxAuiManager
::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
4381 m_hover_button
= NULL
;
4386 void wxAuiManager
::OnChildFocus(wxChildFocusEvent
& event
)
4388 // when a child pane has it's focus set, we should change the
4389 // pane's active state to reflect this. (this is only true if
4390 // active panes are allowed by the owner)
4391 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
4393 wxAuiPaneInfo
& pane
= GetPane(event
.GetWindow());
4394 if (pane
.IsOk() && (pane
.state
& wxAuiPaneInfo
::optionActive
) == 0)
4396 SetActivePane(m_panes
, event
.GetWindow());
4405 // OnPaneButton() is an event handler that is called
4406 // when a pane button has been pressed.
4407 void wxAuiManager
::OnPaneButton(wxAuiManagerEvent
& evt
)
4409 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxAuiManager::OnPaneButton must be non-null"));
4411 wxAuiPaneInfo
& pane
= *(evt
.pane
);
4413 if (evt
.button
== wxAUI_BUTTON_CLOSE
)
4415 // fire pane close event
4416 wxAuiManagerEvent
e(wxEVT_AUI_PANE_CLOSE
);
4418 e
.SetPane(evt
.pane
);
4423 // close the pane, but check that it
4424 // still exists in our pane array first
4425 // (the event handler above might have removed it)
4427 wxAuiPaneInfo
& check
= GetPane(pane
.window
);
4436 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& !pane
.IsMaximized())
4438 // fire pane close event
4439 wxAuiManagerEvent
e(wxEVT_AUI_PANE_MAXIMIZE
);
4441 e
.SetPane(evt
.pane
);
4450 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& pane
.IsMaximized())
4452 // fire pane close event
4453 wxAuiManagerEvent
e(wxEVT_AUI_PANE_RESTORE
);
4455 e
.SetPane(evt
.pane
);
4464 else if (evt
.button
== wxAUI_BUTTON_PIN
)
4466 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&