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"
32 #include "wx/aui/auibar.h"
36 #include "wx/settings.h"
38 #include "wx/dcclient.h"
39 #include "wx/dcscreen.h"
40 #include "wx/toolbar.h"
45 WX_CHECK_BUILD_OPTIONS("wxAUI")
47 #include "wx/arrimpl.cpp"
48 WX_DECLARE_OBJARRAY(wxRect
, wxAuiRectArray
);
49 WX_DEFINE_OBJARRAY(wxAuiRectArray
)
50 WX_DEFINE_OBJARRAY(wxAuiDockUIPartArray
)
51 WX_DEFINE_OBJARRAY(wxAuiDockInfoArray
)
52 WX_DEFINE_OBJARRAY(wxAuiPaneButtonArray
)
53 WX_DEFINE_OBJARRAY(wxAuiPaneInfoArray
)
55 wxAuiPaneInfo wxAuiNullPaneInfo
;
56 wxAuiDockInfo wxAuiNullDockInfo
;
57 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_BUTTON
)
58 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_CLOSE
)
59 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_MAXIMIZE
)
60 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_RESTORE
)
61 DEFINE_EVENT_TYPE(wxEVT_AUI_RENDER
)
62 DEFINE_EVENT_TYPE(wxEVT_AUI_FIND_MANAGER
)
65 // a few defines to avoid nameclashes
66 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
68 #include "wx/osx/private.h"
72 #include "wx/msw/wrapwin.h"
73 #include "wx/msw/private.h"
74 #include "wx/msw/dc.h"
77 IMPLEMENT_DYNAMIC_CLASS(wxAuiManagerEvent
, wxEvent
)
78 IMPLEMENT_CLASS(wxAuiManager
, wxEvtHandler
)
82 const int auiToolBarLayer
= 10;
87 class wxPseudoTransparentFrame
: public wxFrame
90 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
91 wxWindowID id
= wxID_ANY
,
92 const wxString
& title
= wxEmptyString
,
93 const wxPoint
& pos
= wxDefaultPosition
,
94 const wxSize
& size
= wxDefaultSize
,
95 long style
= wxDEFAULT_FRAME_STYLE
,
96 const wxString
&name
= wxT("frame"))
97 : wxFrame(parent
, id
, title
, pos
, size
, style
| wxFRAME_SHAPED
, name
)
99 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
106 m_CanSetShape
= false; // have to wait for window create event on GTK
108 m_CanSetShape
= true;
110 m_Region
= wxRegion(0, 0, 0, 0);
114 virtual bool SetTransparent(wxByte alpha
)
118 int w
=100; // some defaults
120 GetClientSize(&w
, &h
);
126 // m_Region.Union(0, 0, 1, m_MaxWidth);
129 for (int y
=0; y
<m_MaxHeight
; y
++)
131 // Reverse the order of the bottom 4 bits
132 int j
=((y
&8)?1:0)|((y
&4)?2:0)|((y
&2)?4:0)|((y
&1)?8:0);
133 if ((j
*16+8)<m_Amount
)
134 m_Region
.Union(0, y
, m_MaxWidth
, 1);
143 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
147 if (m_Region
.IsEmpty())
151 dc
.SetBrush(wxColour(128, 192, 255));
153 dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
155 dc
.SetPen(*wxTRANSPARENT_PEN
);
157 wxRegionIterator
upd(GetUpdateRegion()); // get the update rect list
161 wxRect
rect(upd
.GetRect());
162 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
169 void OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
))
176 void OnSize(wxSizeEvent
& event
)
178 // We sometimes get surplus size events
179 if ((event
.GetSize().GetWidth() == m_lastWidth
) &&
180 (event
.GetSize().GetHeight() == m_lastHeight
))
185 m_lastWidth
= event
.GetSize().GetWidth();
186 m_lastHeight
= event
.GetSize().GetHeight();
188 SetTransparent(m_Amount
);
189 m_Region
.Intersect(0, 0, event
.GetSize().GetWidth(),
190 event
.GetSize().GetHeight());
201 int m_lastWidth
,m_lastHeight
;
205 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
206 DECLARE_EVENT_TABLE()
210 IMPLEMENT_DYNAMIC_CLASS(wxPseudoTransparentFrame
, wxFrame
)
212 BEGIN_EVENT_TABLE(wxPseudoTransparentFrame
, wxFrame
)
213 EVT_PAINT(wxPseudoTransparentFrame::OnPaint
)
214 EVT_SIZE(wxPseudoTransparentFrame::OnSize
)
216 EVT_WINDOW_CREATE(wxPseudoTransparentFrame::OnWindowCreate
)
227 gtk_pseudo_window_realized_callback( GtkWidget
*m_widget
, void *WXUNUSED(win
) )
229 wxSize disp
= wxGetDisplaySize();
232 for (int y
=0; y
<disp
.y
; y
++)
234 // Reverse the order of the bottom 4 bits
235 int j
=((y
&8)?1:0)|((y
&4)?2:0)|((y
&2)?4:0)|((y
&1)?8:0);
237 region
.Union(0, y
, disp
.x
, 1);
239 gdk_window_shape_combine_region(m_widget
->window
, region
.GetRegion(), 0, 0);
243 class wxPseudoTransparentFrame
: public wxFrame
246 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
247 wxWindowID id
= wxID_ANY
,
248 const wxString
& title
= wxEmptyString
,
249 const wxPoint
& pos
= wxDefaultPosition
,
250 const wxSize
& size
= wxDefaultSize
,
251 long style
= wxDEFAULT_FRAME_STYLE
,
252 const wxString
&name
= wxT("frame"))
254 if (!CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
259 m_widget
= gtk_window_new( GTK_WINDOW_POPUP
);
261 g_signal_connect( m_widget
, "realize",
262 G_CALLBACK (gtk_pseudo_window_realized_callback
), this );
266 col
.green
= 192 * 256;
267 col
.blue
= 255 * 256;
268 gtk_widget_modify_bg( m_widget
, GTK_STATE_NORMAL
, &col
);
271 bool SetTransparent(wxByte
WXUNUSED(alpha
))
277 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
280 IMPLEMENT_DYNAMIC_CLASS(wxPseudoTransparentFrame
, wxFrame
)
287 // -- static utility functions --
289 static wxBitmap
wxPaneCreateStippleBitmap()
291 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
292 wxImage
img(2,2,data
,true);
293 return wxBitmap(img
);
296 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
298 wxBitmap stipple
= wxPaneCreateStippleBitmap();
299 wxBrush
brush(stipple
);
302 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
303 PatBlt(GetHdcOf(*impl
), rect
.GetX(), rect
.GetY(), rect
.GetWidth(), rect
.GetHeight(), PATINVERT
);
305 dc
.SetPen(*wxTRANSPARENT_PEN
);
307 dc
.SetLogicalFunction(wxXOR
);
308 dc
.DrawRectangle(rect
);
314 // CopyDocksAndPanes() - this utility function creates copies of
315 // the dock and pane info. wxAuiDockInfo's usually contain pointers
316 // to wxAuiPaneInfo classes, thus this function is necessary to reliably
317 // reconstruct that relationship in the new dock info and pane info arrays
319 static void CopyDocksAndPanes(wxAuiDockInfoArray
& dest_docks
,
320 wxAuiPaneInfoArray
& dest_panes
,
321 const wxAuiDockInfoArray
& src_docks
,
322 const wxAuiPaneInfoArray
& src_panes
)
324 dest_docks
= src_docks
;
325 dest_panes
= src_panes
;
326 int i
, j
, k
, dock_count
, pc1
, pc2
;
327 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
329 wxAuiDockInfo
& dock
= dest_docks
.Item(i
);
330 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
331 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
332 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
333 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
337 // GetMaxLayer() is an internal function which returns
338 // the highest layer inside the specified dock
339 static int GetMaxLayer(const wxAuiDockInfoArray
& docks
,
342 int i
, dock_count
, max_layer
= 0;
343 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
345 wxAuiDockInfo
& dock
= docks
.Item(i
);
346 if (dock
.dock_direction
== dock_direction
&&
347 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
348 max_layer
= dock
.dock_layer
;
354 // GetMaxRow() is an internal function which returns
355 // the highest layer inside the specified dock
356 static int GetMaxRow(const wxAuiPaneInfoArray
& panes
, int direction
, int layer
)
358 int i
, pane_count
, max_row
= 0;
359 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
361 wxAuiPaneInfo
& pane
= panes
.Item(i
);
362 if (pane
.dock_direction
== direction
&&
363 pane
.dock_layer
== layer
&&
364 pane
.dock_row
> max_row
)
365 max_row
= pane
.dock_row
;
372 // DoInsertDockLayer() is an internal function that inserts a new dock
373 // layer by incrementing all existing dock layer values by one
374 static void DoInsertDockLayer(wxAuiPaneInfoArray
& panes
,
379 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
381 wxAuiPaneInfo
& pane
= panes
.Item(i
);
382 if (!pane
.IsFloating() &&
383 pane
.dock_direction
== dock_direction
&&
384 pane
.dock_layer
>= dock_layer
)
389 // DoInsertDockLayer() is an internal function that inserts a new dock
390 // row by incrementing all existing dock row values by one
391 static void DoInsertDockRow(wxAuiPaneInfoArray
& panes
,
397 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
399 wxAuiPaneInfo
& pane
= panes
.Item(i
);
400 if (!pane
.IsFloating() &&
401 pane
.dock_direction
== dock_direction
&&
402 pane
.dock_layer
== dock_layer
&&
403 pane
.dock_row
>= dock_row
)
408 // DoInsertDockLayer() is an internal function that inserts a space for
409 // another dock pane by incrementing all existing dock row values by one
410 static void DoInsertPane(wxAuiPaneInfoArray
& panes
,
417 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
419 wxAuiPaneInfo
& pane
= panes
.Item(i
);
420 if (!pane
.IsFloating() &&
421 pane
.dock_direction
== dock_direction
&&
422 pane
.dock_layer
== dock_layer
&&
423 pane
.dock_row
== dock_row
&&
424 pane
.dock_pos
>= dock_pos
)
429 // FindDocks() is an internal function that returns a list of docks which meet
430 // the specified conditions in the parameters and returns a sorted array
431 // (sorted by layer and then row)
432 static void FindDocks(wxAuiDockInfoArray
& docks
,
436 wxAuiDockInfoPtrArray
& arr
)
438 int begin_layer
= dock_layer
;
439 int end_layer
= dock_layer
;
440 int begin_row
= dock_row
;
441 int end_row
= dock_row
;
442 int dock_count
= docks
.GetCount();
443 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
445 // discover the maximum dock layer and the max row
446 for (i
= 0; i
< dock_count
; ++i
)
448 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
449 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
452 // if no dock layer was specified, search all dock layers
453 if (dock_layer
== -1)
456 end_layer
= max_layer
;
459 // if no dock row was specified, search all dock row
468 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
469 for (row
= begin_row
; row
<= end_row
; ++row
)
470 for (i
= 0; i
< dock_count
; ++i
)
472 wxAuiDockInfo
& d
= docks
.Item(i
);
473 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
475 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
481 // FindPaneInDock() looks up a specified window pointer inside a dock.
482 // If found, the corresponding wxAuiPaneInfo pointer is returned, otherwise NULL.
483 static wxAuiPaneInfo
* FindPaneInDock(const wxAuiDockInfo
& dock
, wxWindow
* window
)
485 int i
, count
= dock
.panes
.GetCount();
486 for (i
= 0; i
< count
; ++i
)
488 wxAuiPaneInfo
* p
= dock
.panes
.Item(i
);
489 if (p
->window
== window
)
495 // RemovePaneFromDocks() removes a pane window from all docks
496 // with a possible exception specified by parameter "ex_cept"
497 static void RemovePaneFromDocks(wxAuiDockInfoArray
& docks
,
499 wxAuiDockInfo
* ex_cept
= NULL
)
502 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
504 wxAuiDockInfo
& d
= docks
.Item(i
);
507 wxAuiPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
514 // This function works fine, and may be used in the future
516 // RenumberDockRows() takes a dock and assigns sequential numbers
517 // to existing rows. Basically it takes out the gaps; so if a
518 // dock has rows with numbers 0,2,5, they will become 0,1,2
519 static void RenumberDockRows(wxAuiDockInfoPtrArray& docks)
522 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
524 wxAuiDockInfo& dock = *docks.Item(i);
528 for (j = 0, pane_count = dock.panes.GetCount(); j < pane_count; ++j)
529 dock.panes.Item(j)->dock_row = i;
535 // SetActivePane() sets the active pane, as well as cycles through
536 // every other pane and makes sure that all others' active flags
538 static void SetActivePane(wxAuiPaneInfoArray
& panes
, wxWindow
* active_pane
)
541 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
543 wxAuiPaneInfo
& pane
= panes
.Item(i
);
544 pane
.state
&= ~wxAuiPaneInfo::optionActive
;
545 if (pane
.window
== active_pane
)
546 pane
.state
|= wxAuiPaneInfo::optionActive
;
551 // this function is used to sort panes by dock position
552 static int PaneSortFunc(wxAuiPaneInfo
** p1
, wxAuiPaneInfo
** p2
)
554 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
558 // -- wxAuiManager class implementation --
561 BEGIN_EVENT_TABLE(wxAuiManager
, wxEvtHandler
)
562 EVT_AUI_PANE_BUTTON(wxAuiManager::OnPaneButton
)
563 EVT_AUI_RENDER(wxAuiManager::OnRender
)
564 EVT_PAINT(wxAuiManager::OnPaint
)
565 EVT_ERASE_BACKGROUND(wxAuiManager::OnEraseBackground
)
566 EVT_SIZE(wxAuiManager::OnSize
)
567 EVT_SET_CURSOR(wxAuiManager::OnSetCursor
)
568 EVT_LEFT_DOWN(wxAuiManager::OnLeftDown
)
569 EVT_LEFT_UP(wxAuiManager::OnLeftUp
)
570 EVT_MOTION(wxAuiManager::OnMotion
)
571 EVT_LEAVE_WINDOW(wxAuiManager::OnLeaveWindow
)
572 EVT_CHILD_FOCUS(wxAuiManager::OnChildFocus
)
573 EVT_AUI_FIND_MANAGER(wxAuiManager::OnFindManager
)
574 EVT_TIMER(101, wxAuiManager::OnHintFadeTimer
)
578 wxAuiManager::wxAuiManager(wxWindow
* managed_wnd
, unsigned int flags
)
580 m_action
= actionNone
;
581 m_last_mouse_move
= wxPoint();
582 m_hover_button
= NULL
;
583 m_art
= new wxAuiDefaultDockArt
;
587 m_has_maximized
= false;
589 m_dock_constraint_x
= 0.3;
590 m_dock_constraint_y
= 0.3;
595 SetManagedWindow(managed_wnd
);
599 wxAuiManager::~wxAuiManager()
601 // NOTE: It's possible that the windows have already been destroyed by the
602 // time this dtor is called, so this loop can result in memory access via
603 // invalid pointers, resulting in a crash. So it will be disabled while
604 // waiting for a better solution.
606 for ( size_t i
= 0; i
< m_panes
.size(); i
++ )
608 wxAuiPaneInfo
& pinfo
= m_panes
[i
];
609 if (pinfo
.window
&& !pinfo
.window
->GetParent())
617 // creates a floating frame for the windows
618 wxAuiFloatingFrame
* wxAuiManager::CreateFloatingFrame(wxWindow
* parent
,
619 const wxAuiPaneInfo
& pane_info
)
621 return new wxAuiFloatingFrame(parent
, this, pane_info
);
624 bool wxAuiManager::CanDockPanel(const wxAuiPaneInfo
& WXUNUSED(p
))
626 // if a key modifier is pressed while dragging the frame,
627 // don't dock the window
628 return !(wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
));
631 // GetPane() looks up a wxAuiPaneInfo structure based
632 // on the supplied window pointer. Upon failure, GetPane()
633 // returns an empty wxAuiPaneInfo, a condition which can be checked
634 // by calling wxAuiPaneInfo::IsOk().
636 // The pane info's structure may then be modified. Once a pane's
637 // info is modified, wxAuiManager::Update() must be called to
638 // realize the changes in the UI.
640 wxAuiPaneInfo
& wxAuiManager::GetPane(wxWindow
* window
)
643 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
645 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
646 if (p
.window
== window
)
649 return wxAuiNullPaneInfo
;
652 // this version of GetPane() looks up a pane based on a
653 // 'pane name', see above comment for more info
654 wxAuiPaneInfo
& wxAuiManager::GetPane(const wxString
& name
)
657 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
659 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
663 return wxAuiNullPaneInfo
;
666 // GetAllPanes() returns a reference to all the pane info structures
667 wxAuiPaneInfoArray
& wxAuiManager::GetAllPanes()
672 // HitTest() is an internal function which determines
673 // which UI item the specified coordinates are over
674 // (x,y) specify a position in client coordinates
675 wxAuiDockUIPart
* wxAuiManager::HitTest(int x
, int y
)
677 wxAuiDockUIPart
* result
= NULL
;
680 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
682 wxAuiDockUIPart
* item
= &m_uiparts
.Item(i
);
684 // we are not interested in typeDock, because this space
685 // isn't used to draw anything, just for measurements;
686 // besides, the entire dock area is covered with other
687 // rectangles, which we are interested in.
688 if (item
->type
== wxAuiDockUIPart::typeDock
)
691 // if we already have a hit on a more specific item, we are not
692 // interested in a pane hit. If, however, we don't already have
693 // a hit, returning a pane hit is necessary for some operations
694 if ((item
->type
== wxAuiDockUIPart::typePane
||
695 item
->type
== wxAuiDockUIPart::typePaneBorder
) && result
)
698 // if the point is inside the rectangle, we have a hit
699 if (item
->rect
.Contains(x
,y
))
707 // SetFlags() and GetFlags() allow the owner to set various
708 // options which are global to wxAuiManager
709 void wxAuiManager::SetFlags(unsigned int flags
)
711 // find out if we have to call UpdateHintWindowConfig()
712 bool update_hint_wnd
= false;
713 unsigned int hint_mask
= wxAUI_MGR_TRANSPARENT_HINT
|
714 wxAUI_MGR_VENETIAN_BLINDS_HINT
|
715 wxAUI_MGR_RECTANGLE_HINT
;
716 if ((flags
& hint_mask
) != (m_flags
& hint_mask
))
717 update_hint_wnd
= true;
725 UpdateHintWindowConfig();
729 unsigned int wxAuiManager::GetFlags() const
735 // don't use these anymore as they are deprecated
736 // use Set/GetManagedFrame() instead
737 void wxAuiManager::SetFrame(wxFrame
* frame
)
739 SetManagedWindow((wxWindow
*)frame
);
742 wxFrame
* wxAuiManager::GetFrame() const
744 return (wxFrame
*)m_frame
;
748 // this function will return the aui manager for a given
749 // window. The |window| parameter should be any child window
750 // or grand-child window (and so on) of the frame/window
751 // managed by wxAuiManager. The |window| parameter does not
752 // need to be managed by the manager itself.
753 wxAuiManager
* wxAuiManager::GetManager(wxWindow
* window
)
755 wxAuiManagerEvent
evt(wxEVT_AUI_FIND_MANAGER
);
756 evt
.SetManager(NULL
);
757 evt
.ResumePropagation(wxEVENT_PROPAGATE_MAX
);
758 if (!window
->ProcessEvent(evt
))
761 return evt
.GetManager();
765 void wxAuiManager::UpdateHintWindowConfig()
767 // find out if the the system can do transparent frames
768 bool can_do_transparent
= false;
770 wxWindow
* w
= m_frame
;
773 if (w
->IsKindOf(CLASSINFO(wxFrame
)))
775 wxFrame
* f
= static_cast<wxFrame
*>(w
);
776 can_do_transparent
= f
->CanSetTransparent();
784 // if there is an existing hint window, delete it
787 m_hint_wnd
->Destroy();
794 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) && can_do_transparent
)
796 // Make a window to use for a transparent hint
797 #if defined(__WXMSW__) || defined(__WXGTK__)
798 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
,
799 wxDefaultPosition
, wxSize(1,1),
800 wxFRAME_TOOL_WINDOW
|
801 wxFRAME_FLOAT_ON_PARENT
|
805 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
806 #elif defined(__WXMAC__)
807 // Using a miniframe with float and tool styles keeps the parent
808 // frame activated and highlighted as such...
809 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
,
810 wxDefaultPosition
, wxSize(1,1),
811 wxFRAME_FLOAT_ON_PARENT
812 | wxFRAME_TOOL_WINDOW
);
814 // Can't set the bg colour of a Frame in wxMac
815 wxPanel
* p
= new wxPanel(m_hint_wnd
);
817 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
818 // color that is really hard to see, especially transparent.
819 // Until a better system color is decided upon we'll just use
821 p
->SetBackgroundColour(*wxBLUE
);
827 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 ||
828 (m_flags
& wxAUI_MGR_VENETIAN_BLINDS_HINT
) != 0)
830 // system can't support transparent fade, or the venetian
831 // blinds effect was explicitly requested
832 m_hint_wnd
= new wxPseudoTransparentFrame(m_frame
,
837 wxFRAME_TOOL_WINDOW
|
838 wxFRAME_FLOAT_ON_PARENT
|
841 m_hint_fademax
= 128;
847 // SetManagedWindow() is usually called once when the frame
848 // manager class is being initialized. "frame" specifies
849 // the frame which should be managed by the frame mananger
850 void wxAuiManager::SetManagedWindow(wxWindow
* wnd
)
852 wxASSERT_MSG(wnd
, wxT("specified window must be non-NULL"));
855 m_frame
->PushEventHandler(this);
858 // if the owner is going to manage an MDI parent frame,
859 // we need to add the MDI client window as the default
862 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
864 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)m_frame
;
865 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
867 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
869 AddPane(client_window
,
870 wxAuiPaneInfo().Name(wxT("mdiclient")).
871 CenterPane().PaneBorder(false));
873 else if (m_frame
->IsKindOf(CLASSINFO(wxAuiMDIParentFrame
)))
875 wxAuiMDIParentFrame
* mdi_frame
= (wxAuiMDIParentFrame
*)m_frame
;
876 wxAuiMDIClientWindow
* client_window
= mdi_frame
->GetClientWindow();
877 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
879 AddPane(client_window
,
880 wxAuiPaneInfo().Name(wxT("mdiclient")).
881 CenterPane().PaneBorder(false));
886 UpdateHintWindowConfig();
890 // UnInit() must be called, usually in the destructor
891 // of the frame class. If it is not called, usually this
892 // will result in a crash upon program exit
893 void wxAuiManager::UnInit()
897 m_frame
->RemoveEventHandler(this);
901 // GetManagedWindow() returns the window pointer being managed
902 wxWindow
* wxAuiManager::GetManagedWindow() const
907 wxAuiDockArt
* wxAuiManager::GetArtProvider() const
912 void wxAuiManager::ProcessMgrEvent(wxAuiManagerEvent
& event
)
914 // first, give the owner frame a chance to override
917 if (m_frame
->ProcessEvent(event
))
924 // SetArtProvider() instructs wxAuiManager to use the
925 // specified art provider for all drawing calls. This allows
926 // plugable look-and-feel features. The pointer that is
927 // passed to this method subsequently belongs to wxAuiManager,
928 // and is deleted in the frame manager destructor
929 void wxAuiManager::SetArtProvider(wxAuiDockArt
* art_provider
)
931 // delete the last art provider, if any
934 // assign the new art provider
935 m_art
= art_provider
;
939 bool wxAuiManager::AddPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
)
941 wxASSERT_MSG(window
, wxT("NULL window ptrs are not allowed"));
943 // check if the pane has a valid window
947 // check if the window is already managed by us
948 if (GetPane(pane_info
.window
).IsOk())
951 // check if the pane name already exists, this could reveal a
952 // bug in the library user's application
953 bool already_exists
= false;
954 if (!pane_info
.name
.empty() && GetPane(pane_info
.name
).IsOk())
956 wxFAIL_MSG(wxT("A pane with that name already exists in the manager!"));
957 already_exists
= true;
960 // if the new pane is docked then we should undo maximize
961 if (pane_info
.IsDocked())
962 RestoreMaximizedPane();
964 m_panes
.Add(pane_info
);
966 wxAuiPaneInfo
& pinfo
= m_panes
.Last();
968 // set the pane window
969 pinfo
.window
= window
;
972 // if the pane's name identifier is blank, create a random string
973 if (pinfo
.name
.empty() || already_exists
)
975 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
976 wxPtrToUInt(pinfo
.window
) & 0xffffffff,
977 (unsigned int)time(NULL
),
979 (unsigned int)GetTickCount(),
981 (unsigned int)clock(),
983 (unsigned long)m_panes
.GetCount());
986 // set initial proportion (if not already set)
987 if (pinfo
.dock_proportion
== 0)
988 pinfo
.dock_proportion
= 100000;
990 if (pinfo
.HasMaximizeButton())
992 wxAuiPaneButton button
;
993 button
.button_id
= wxAUI_BUTTON_MAXIMIZE_RESTORE
;
994 pinfo
.buttons
.Add(button
);
997 if (pinfo
.HasPinButton())
999 wxAuiPaneButton button
;
1000 button
.button_id
= wxAUI_BUTTON_PIN
;
1001 pinfo
.buttons
.Add(button
);
1004 if (pinfo
.HasCloseButton())
1006 wxAuiPaneButton button
;
1007 button
.button_id
= wxAUI_BUTTON_CLOSE
;
1008 pinfo
.buttons
.Add(button
);
1011 if (pinfo
.HasGripper())
1013 if (pinfo
.window
->IsKindOf(CLASSINFO(wxAuiToolBar
)))
1015 // prevent duplicate gripper -- both wxAuiManager and wxAuiToolBar
1016 // have a gripper control. The toolbar's built-in gripper
1017 // meshes better with the look and feel of the control than ours,
1018 // so turn wxAuiManager's gripper off, and the toolbar's on.
1020 wxAuiToolBar
* tb
= static_cast<wxAuiToolBar
*>(pinfo
.window
);
1021 pinfo
.SetFlag(wxAuiPaneInfo::optionGripper
, false);
1022 tb
->SetGripperVisible(true);
1027 if (pinfo
.best_size
== wxDefaultSize
&&
1030 pinfo
.best_size
= pinfo
.window
->GetClientSize();
1032 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
1034 // GetClientSize() doesn't get the best size for
1035 // a toolbar under some newer versions of wxWidgets,
1036 // so use GetBestSize()
1037 pinfo
.best_size
= pinfo
.window
->GetBestSize();
1039 // for some reason, wxToolBar::GetBestSize() is returning
1040 // a size that is a pixel shy of the correct amount.
1041 // I believe this to be the correct action, until
1042 // wxToolBar::GetBestSize() is fixed. Is this assumption
1044 // commented out by JACS 2007-9-08 after having added a pixel in wxMSW's wxToolBar::DoGetBestSize()
1045 // pinfo.best_size.y++;
1048 if (pinfo
.min_size
!= wxDefaultSize
)
1050 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
1051 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
1052 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
1053 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
1062 bool wxAuiManager::AddPane(wxWindow
* window
,
1064 const wxString
& caption
)
1066 wxAuiPaneInfo pinfo
;
1067 pinfo
.Caption(caption
);
1070 case wxTOP
: pinfo
.Top(); break;
1071 case wxBOTTOM
: pinfo
.Bottom(); break;
1072 case wxLEFT
: pinfo
.Left(); break;
1073 case wxRIGHT
: pinfo
.Right(); break;
1074 case wxCENTER
: pinfo
.CenterPane(); break;
1076 return AddPane(window
, pinfo
);
1079 bool wxAuiManager::AddPane(wxWindow
* window
,
1080 const wxAuiPaneInfo
& pane_info
,
1081 const wxPoint
& drop_pos
)
1083 if (!AddPane(window
, pane_info
))
1086 wxAuiPaneInfo
& pane
= GetPane(window
);
1088 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
1093 bool wxAuiManager::InsertPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
,
1096 wxASSERT_MSG(window
, wxT("NULL window ptrs are not allowed"));
1098 // shift the panes around, depending on the insert level
1099 switch (insert_level
)
1101 case wxAUI_INSERT_PANE
:
1102 DoInsertPane(m_panes
,
1103 pane_info
.dock_direction
,
1104 pane_info
.dock_layer
,
1106 pane_info
.dock_pos
);
1108 case wxAUI_INSERT_ROW
:
1109 DoInsertDockRow(m_panes
,
1110 pane_info
.dock_direction
,
1111 pane_info
.dock_layer
,
1112 pane_info
.dock_row
);
1114 case wxAUI_INSERT_DOCK
:
1115 DoInsertDockLayer(m_panes
,
1116 pane_info
.dock_direction
,
1117 pane_info
.dock_layer
);
1121 // if the window already exists, we are basically just moving/inserting the
1122 // existing window. If it doesn't exist, we need to add it and insert it
1123 wxAuiPaneInfo
& existing_pane
= GetPane(window
);
1124 if (!existing_pane
.IsOk())
1126 return AddPane(window
, pane_info
);
1130 if (pane_info
.IsFloating())
1132 existing_pane
.Float();
1133 if (pane_info
.floating_pos
!= wxDefaultPosition
)
1134 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
1135 if (pane_info
.floating_size
!= wxDefaultSize
)
1136 existing_pane
.FloatingSize(pane_info
.floating_size
);
1140 // if the new pane is docked then we should undo maximize
1141 RestoreMaximizedPane();
1143 existing_pane
.Direction(pane_info
.dock_direction
);
1144 existing_pane
.Layer(pane_info
.dock_layer
);
1145 existing_pane
.Row(pane_info
.dock_row
);
1146 existing_pane
.Position(pane_info
.dock_pos
);
1154 // DetachPane() removes a pane from the frame manager. This
1155 // method will not destroy the window that is removed.
1156 bool wxAuiManager::DetachPane(wxWindow
* window
)
1158 wxASSERT_MSG(window
, wxT("NULL window ptrs are not allowed"));
1161 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
1163 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1164 if (p
.window
== window
)
1168 // we have a floating frame which is being detached. We need to
1169 // reparent it to m_frame and destroy the floating frame
1172 p
.window
->SetSize(1,1);
1174 if (p
.frame
->IsShown())
1175 p
.frame
->Show(false);
1177 // reparent to m_frame and destroy the pane
1178 if (m_action_window
== p
.frame
)
1180 m_action_window
= NULL
;
1183 p
.window
->Reparent(m_frame
);
1184 p
.frame
->SetSizer(NULL
);
1189 // make sure there are no references to this pane in our uiparts,
1190 // just in case the caller doesn't call Update() immediately after
1191 // the DetachPane() call. This prevets obscure crashes which would
1192 // happen at window repaint if the caller forgets to call Update()
1194 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
1196 wxAuiDockUIPart
& part
= m_uiparts
.Item(pi
);
1197 if (part
.pane
== &p
)
1199 m_uiparts
.RemoveAt(pi
);
1206 m_panes
.RemoveAt(i
);
1213 // ClosePane() destroys or hides the pane depending on its flags
1214 void wxAuiManager::ClosePane(wxAuiPaneInfo
& pane_info
)
1216 // if we were maximized, restore
1217 if (pane_info
.IsMaximized())
1219 RestorePane(pane_info
);
1222 // first, hide the window
1223 if (pane_info
.window
&& pane_info
.window
->IsShown())
1225 pane_info
.window
->Show(false);
1228 // make sure that we are the parent of this window
1229 if (pane_info
.window
&& pane_info
.window
->GetParent() != m_frame
)
1231 pane_info
.window
->Reparent(m_frame
);
1234 // if we have a frame, destroy it
1235 if (pane_info
.frame
)
1237 pane_info
.frame
->Destroy();
1238 pane_info
.frame
= NULL
;
1241 // now we need to either destroy or hide the pane
1242 if (pane_info
.IsDestroyOnClose())
1244 wxWindow
* window
= pane_info
.window
;
1257 void wxAuiManager::MaximizePane(wxAuiPaneInfo
& pane_info
)
1261 // un-maximize and hide all other panes
1262 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1264 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1269 // save hidden state
1270 p
.SetFlag(wxAuiPaneInfo::savedHiddenState
,
1271 p
.HasFlag(wxAuiPaneInfo::optionHidden
));
1273 // hide the pane, because only the newly
1274 // maximized pane should show
1279 // mark ourselves maximized
1280 pane_info
.Maximize();
1282 m_has_maximized
= true;
1284 // last, show the window
1285 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1287 pane_info
.window
->Show(true);
1291 void wxAuiManager::RestorePane(wxAuiPaneInfo
& pane_info
)
1295 // restore all the panes
1296 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1298 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1301 p
.SetFlag(wxAuiPaneInfo::optionHidden
,
1302 p
.HasFlag(wxAuiPaneInfo::savedHiddenState
));
1306 // mark ourselves non-maximized
1307 pane_info
.Restore();
1308 m_has_maximized
= false;
1310 // last, show the window
1311 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1313 pane_info
.window
->Show(true);
1317 void wxAuiManager::RestoreMaximizedPane()
1321 // restore all the panes
1322 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1324 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1325 if (p
.IsMaximized())
1333 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
1334 // in the input string. This is an internal functions which is
1335 // used for saving perspectives
1336 static wxString
EscapeDelimiters(const wxString
& s
)
1339 result
.Alloc(s
.length());
1340 const wxChar
* ch
= s
.c_str();
1343 if (*ch
== wxT(';') || *ch
== wxT('|'))
1344 result
+= wxT('\\');
1351 wxString
wxAuiManager::SavePaneInfo(wxAuiPaneInfo
& pane
)
1353 wxString result
= wxT("name=");
1354 result
+= EscapeDelimiters(pane
.name
);
1357 result
+= wxT("caption=");
1358 result
+= EscapeDelimiters(pane
.caption
);
1361 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
1362 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
1363 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
1364 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
1365 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
1366 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
1367 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
1368 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
1369 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
1370 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
1371 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
1372 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
1373 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
1374 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
1375 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
1376 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
1381 // Load a "pane" with the pane infor settings in pane_part
1382 void wxAuiManager::LoadPaneInfo(wxString pane_part
, wxAuiPaneInfo
&pane
)
1384 // replace escaped characters so we can
1385 // split up the string easily
1386 pane_part
.Replace(wxT("\\|"), wxT("\a"));
1387 pane_part
.Replace(wxT("\\;"), wxT("\b"));
1391 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
1392 pane_part
= pane_part
.AfterFirst(wxT(';'));
1393 wxString val_name
= val_part
.BeforeFirst(wxT('='));
1394 wxString value
= val_part
.AfterFirst(wxT('='));
1395 val_name
.MakeLower();
1396 val_name
.Trim(true);
1397 val_name
.Trim(false);
1401 if (val_name
.empty())
1404 if (val_name
== wxT("name"))
1406 else if (val_name
== wxT("caption"))
1407 pane
.caption
= value
;
1408 else if (val_name
== wxT("state"))
1409 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1410 else if (val_name
== wxT("dir"))
1411 pane
.dock_direction
= wxAtoi(value
.c_str());
1412 else if (val_name
== wxT("layer"))
1413 pane
.dock_layer
= wxAtoi(value
.c_str());
1414 else if (val_name
== wxT("row"))
1415 pane
.dock_row
= wxAtoi(value
.c_str());
1416 else if (val_name
== wxT("pos"))
1417 pane
.dock_pos
= wxAtoi(value
.c_str());
1418 else if (val_name
== wxT("prop"))
1419 pane
.dock_proportion
= wxAtoi(value
.c_str());
1420 else if (val_name
== wxT("bestw"))
1421 pane
.best_size
.x
= wxAtoi(value
.c_str());
1422 else if (val_name
== wxT("besth"))
1423 pane
.best_size
.y
= wxAtoi(value
.c_str());
1424 else if (val_name
== wxT("minw"))
1425 pane
.min_size
.x
= wxAtoi(value
.c_str());
1426 else if (val_name
== wxT("minh"))
1427 pane
.min_size
.y
= wxAtoi(value
.c_str());
1428 else if (val_name
== wxT("maxw"))
1429 pane
.max_size
.x
= wxAtoi(value
.c_str());
1430 else if (val_name
== wxT("maxh"))
1431 pane
.max_size
.y
= wxAtoi(value
.c_str());
1432 else if (val_name
== wxT("floatx"))
1433 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1434 else if (val_name
== wxT("floaty"))
1435 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1436 else if (val_name
== wxT("floatw"))
1437 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1438 else if (val_name
== wxT("floath"))
1439 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1441 wxFAIL_MSG(wxT("Bad Perspective String"));
1445 // replace escaped characters so we can
1446 // split up the string easily
1447 pane
.name
.Replace(wxT("\a"), wxT("|"));
1448 pane
.name
.Replace(wxT("\b"), wxT(";"));
1449 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1450 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1451 pane_part
.Replace(wxT("\a"), wxT("|"));
1452 pane_part
.Replace(wxT("\b"), wxT(";"));
1458 // SavePerspective() saves all pane information as a single string.
1459 // This string may later be fed into LoadPerspective() to restore
1460 // all pane settings. This save and load mechanism allows an
1461 // exact pane configuration to be saved and restored at a later time
1463 wxString
wxAuiManager::SavePerspective()
1467 result
= wxT("layout2|");
1469 int pane_i
, pane_count
= m_panes
.GetCount();
1470 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1472 wxAuiPaneInfo
& pane
= m_panes
.Item(pane_i
);
1473 result
+= SavePaneInfo(pane
)+wxT("|");
1476 int dock_i
, dock_count
= m_docks
.GetCount();
1477 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1479 wxAuiDockInfo
& dock
= m_docks
.Item(dock_i
);
1481 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1482 dock
.dock_direction
, dock
.dock_layer
,
1483 dock
.dock_row
, dock
.size
);
1489 // LoadPerspective() loads a layout which was saved with SavePerspective()
1490 // If the "update" flag parameter is true, the GUI will immediately be updated
1492 bool wxAuiManager::LoadPerspective(const wxString
& layout
, bool update
)
1494 wxString input
= layout
;
1497 // check layout string version
1498 // 'layout1' = wxAUI 0.9.0 - wxAUI 0.9.2
1499 // 'layout2' = wxAUI 0.9.2 (wxWidgets 2.8)
1500 part
= input
.BeforeFirst(wxT('|'));
1501 input
= input
.AfterFirst(wxT('|'));
1504 if (part
!= wxT("layout2"))
1507 // mark all panes currently managed as docked and hidden
1508 int pane_i
, pane_count
= m_panes
.GetCount();
1509 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1510 m_panes
.Item(pane_i
).Dock().Hide();
1512 // clear out the dock array; this will be reconstructed
1515 // replace escaped characters so we can
1516 // split up the string easily
1517 input
.Replace(wxT("\\|"), wxT("\a"));
1518 input
.Replace(wxT("\\;"), wxT("\b"));
1524 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1525 input
= input
.AfterFirst(wxT('|'));
1526 pane_part
.Trim(true);
1528 // if the string is empty, we're done parsing
1529 if (pane_part
.empty())
1532 if (pane_part
.Left(9) == wxT("dock_size"))
1534 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1535 wxString value
= pane_part
.AfterFirst(wxT('='));
1537 long dir
, layer
, row
, size
;
1538 wxString piece
= val_name
.AfterFirst(wxT('('));
1539 piece
= piece
.BeforeLast(wxT(')'));
1540 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1541 piece
= piece
.AfterFirst(wxT(','));
1542 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1543 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1544 value
.ToLong(&size
);
1547 dock
.dock_direction
= dir
;
1548 dock
.dock_layer
= layer
;
1549 dock
.dock_row
= row
;
1555 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1556 // name so it can be called by external callers
1557 pane_part
.Replace(wxT("\a"), wxT("|"));
1558 pane_part
.Replace(wxT("\b"), wxT(";"));
1560 LoadPaneInfo(pane_part
, pane
);
1562 wxAuiPaneInfo
& p
= GetPane(pane
.name
);
1565 // the pane window couldn't be found
1566 // in the existing layout -- skip it
1579 void wxAuiManager::GetPanePositionsAndSizes(wxAuiDockInfo
& dock
,
1580 wxArrayInt
& positions
,
1583 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1584 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1585 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1590 int offset
, action_pane
= -1;
1591 int pane_i
, pane_count
= dock
.panes
.GetCount();
1593 // find the pane marked as our action pane
1594 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1596 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1598 if (pane
.state
& wxAuiPaneInfo::actionPane
)
1600 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1601 action_pane
= pane_i
;
1605 // set up each panes default position, and
1606 // determine the size (width or height, depending
1607 // on the dock's orientation) of each pane
1608 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1610 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1611 positions
.Add(pane
.dock_pos
);
1614 if (pane
.HasBorder())
1615 size
+= (pane_border_size
*2);
1617 if (dock
.IsHorizontal())
1619 if (pane
.HasGripper() && !pane
.HasGripperTop())
1620 size
+= gripper_size
;
1621 size
+= pane
.best_size
.x
;
1625 if (pane
.HasGripper() && pane
.HasGripperTop())
1626 size
+= gripper_size
;
1628 if (pane
.HasCaption())
1629 size
+= caption_size
;
1630 size
+= pane
.best_size
.y
;
1636 // if there is no action pane, just return the default
1637 // positions (as specified in pane.pane_pos)
1638 if (action_pane
== -1)
1642 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1644 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1649 positions
[pane_i
] -= -amount
;
1651 offset
+= sizes
[pane_i
];
1654 // if the dock mode is fixed, make sure none of the panes
1655 // overlap; we will bump panes that overlap
1657 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1659 int amount
= positions
[pane_i
] - offset
;
1663 positions
[pane_i
] += -amount
;
1665 offset
+= sizes
[pane_i
];
1670 void wxAuiManager::LayoutAddPane(wxSizer
* cont
,
1671 wxAuiDockInfo
& dock
,
1672 wxAuiPaneInfo
& pane
,
1673 wxAuiDockUIPartArray
& uiparts
,
1676 wxAuiDockUIPart part
;
1677 wxSizerItem
* sizer_item
;
1679 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1680 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1681 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1682 int pane_button_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BUTTON_SIZE
);
1684 // find out the orientation of the item (orientation for panes
1685 // is the same as the dock's orientation)
1687 if (dock
.IsHorizontal())
1688 orientation
= wxHORIZONTAL
;
1690 orientation
= wxVERTICAL
;
1692 // this variable will store the proportion
1693 // value that the pane will receive
1694 int pane_proportion
= pane
.dock_proportion
;
1696 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1697 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1699 if (pane
.HasGripper())
1701 if (pane
.HasGripperTop())
1702 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1704 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1706 part
.type
= wxAuiDockUIPart::typeGripper
;
1710 part
.orientation
= orientation
;
1711 part
.cont_sizer
= horz_pane_sizer
;
1712 part
.sizer_item
= sizer_item
;
1716 if (pane
.HasCaption())
1718 // create the caption sizer
1719 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1721 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1723 part
.type
= wxAuiDockUIPart::typeCaption
;
1727 part
.orientation
= orientation
;
1728 part
.cont_sizer
= vert_pane_sizer
;
1729 part
.sizer_item
= sizer_item
;
1730 int caption_part_idx
= uiparts
.GetCount();
1733 // add pane buttons to the caption
1734 int i
, button_count
;
1735 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1736 i
< button_count
; ++i
)
1738 wxAuiPaneButton
& button
= pane
.buttons
.Item(i
);
1740 sizer_item
= caption_sizer
->Add(pane_button_size
,
1744 part
.type
= wxAuiDockUIPart::typePaneButton
;
1747 part
.button
= &button
;
1748 part
.orientation
= orientation
;
1749 part
.cont_sizer
= caption_sizer
;
1750 part
.sizer_item
= sizer_item
;
1754 // if we have buttons, add a little space to the right
1755 // of them to ease visual crowding
1756 if (button_count
>= 1)
1758 caption_sizer
->Add(3,1);
1761 // add the caption sizer
1762 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1764 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1767 // add the pane window itself
1770 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1774 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1775 // Don't do this because it breaks the pane size in floating windows
1776 // BIW: Right now commenting this out is causing problems with
1777 // an mdi client window as the center pane.
1778 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1781 part
.type
= wxAuiDockUIPart::typePane
;
1785 part
.orientation
= orientation
;
1786 part
.cont_sizer
= vert_pane_sizer
;
1787 part
.sizer_item
= sizer_item
;
1791 // determine if the pane should have a minimum size; if the pane is
1792 // non-resizable (fixed) then we must set a minimum size. Alternatively,
1793 // if the pane.min_size is set, we must use that value as well
1795 wxSize min_size
= pane
.min_size
;
1798 if (min_size
== wxDefaultSize
)
1800 min_size
= pane
.best_size
;
1801 pane_proportion
= 0;
1805 if (min_size
!= wxDefaultSize
)
1807 vert_pane_sizer
->SetItemMinSize(
1808 vert_pane_sizer
->GetChildren().GetCount()-1,
1809 min_size
.x
, min_size
.y
);
1813 // add the verticle sizer (caption, pane window) to the
1814 // horizontal sizer (gripper, verticle sizer)
1815 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1817 // finally, add the pane sizer to the dock sizer
1819 if (pane
.HasBorder())
1821 // allowing space for the pane's border
1822 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1823 wxEXPAND
| wxALL
, pane_border_size
);
1825 part
.type
= wxAuiDockUIPart::typePaneBorder
;
1829 part
.orientation
= orientation
;
1830 part
.cont_sizer
= cont
;
1831 part
.sizer_item
= sizer_item
;
1836 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1840 void wxAuiManager::LayoutAddDock(wxSizer
* cont
,
1841 wxAuiDockInfo
& dock
,
1842 wxAuiDockUIPartArray
& uiparts
,
1845 wxSizerItem
* sizer_item
;
1846 wxAuiDockUIPart part
;
1848 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
1849 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1851 // resizable bottom and right docks have a sash before them
1852 if (!m_has_maximized
&& !dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1853 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1855 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1857 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1858 part
.orientation
= orientation
;
1862 part
.cont_sizer
= cont
;
1863 part
.sizer_item
= sizer_item
;
1867 // create the sizer for the dock
1868 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1870 // add each pane to the dock
1871 bool has_maximized_pane
= false;
1872 int pane_i
, pane_count
= dock
.panes
.GetCount();
1876 wxArrayInt pane_positions
, pane_sizes
;
1878 // figure out the real pane positions we will
1879 // use, without modifying the each pane's pane_pos member
1880 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1883 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1885 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1886 int pane_pos
= pane_positions
.Item(pane_i
);
1888 if (pane
.IsMaximized())
1889 has_maximized_pane
= true;
1892 int amount
= pane_pos
- offset
;
1895 if (dock
.IsVertical())
1896 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1898 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1900 part
.type
= wxAuiDockUIPart::typeBackground
;
1904 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1905 part
.cont_sizer
= dock_sizer
;
1906 part
.sizer_item
= sizer_item
;
1912 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1914 offset
+= pane_sizes
.Item(pane_i
);
1917 // at the end add a very small stretchable background area
1918 sizer_item
= dock_sizer
->Add(0,0, 1, wxEXPAND
);
1920 part
.type
= wxAuiDockUIPart::typeBackground
;
1924 part
.orientation
= orientation
;
1925 part
.cont_sizer
= dock_sizer
;
1926 part
.sizer_item
= sizer_item
;
1931 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1933 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1935 if (pane
.IsMaximized())
1936 has_maximized_pane
= true;
1938 // if this is not the first pane being added,
1939 // we need to add a pane sizer
1940 if (!m_has_maximized
&& pane_i
> 0)
1942 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1944 part
.type
= wxAuiDockUIPart::typePaneSizer
;
1946 part
.pane
= dock
.panes
.Item(pane_i
-1);
1948 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1949 part
.cont_sizer
= dock_sizer
;
1950 part
.sizer_item
= sizer_item
;
1954 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1958 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
|| has_maximized_pane
)
1959 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1961 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1963 part
.type
= wxAuiDockUIPart::typeDock
;
1967 part
.orientation
= orientation
;
1968 part
.cont_sizer
= cont
;
1969 part
.sizer_item
= sizer_item
;
1972 if (dock
.IsHorizontal())
1973 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1975 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1977 // top and left docks have a sash after them
1978 if (!m_has_maximized
&&
1980 (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1981 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1983 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1985 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1989 part
.orientation
= orientation
;
1990 part
.cont_sizer
= cont
;
1991 part
.sizer_item
= sizer_item
;
1996 wxSizer
* wxAuiManager::LayoutAll(wxAuiPaneInfoArray
& panes
,
1997 wxAuiDockInfoArray
& docks
,
1998 wxAuiDockUIPartArray
& uiparts
,
2001 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
2003 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
2004 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
2005 wxSize cli_size
= m_frame
->GetClientSize();
2006 int i
, dock_count
, pane_count
;
2009 // empty all docks out
2010 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2012 wxAuiDockInfo
& dock
= docks
.Item(i
);
2014 // empty out all panes, as they will be readded below
2019 // always reset fixed docks' sizes, because
2020 // the contained windows may have been resized
2026 // iterate through all known panes, filing each
2027 // of them into the appropriate dock. If the
2028 // pane does not exist in the dock, add it
2029 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2031 wxAuiPaneInfo
& p
= panes
.Item(i
);
2033 // find any docks with the same dock direction, dock layer, and
2034 // dock row as the pane we are working on
2035 wxAuiDockInfo
* dock
;
2036 wxAuiDockInfoPtrArray arr
;
2037 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
2039 if (arr
.GetCount() > 0)
2041 // found the right dock
2046 // dock was not found, so we need to create a new one
2048 d
.dock_direction
= p
.dock_direction
;
2049 d
.dock_layer
= p
.dock_layer
;
2050 d
.dock_row
= p
.dock_row
;
2052 dock
= &docks
.Last();
2056 if (p
.IsDocked() && p
.IsShown())
2058 // remove the pane from any existing docks except this one
2059 RemovePaneFromDocks(docks
, p
, dock
);
2061 // pane needs to be added to the dock,
2062 // if it doesn't already exist
2063 if (!FindPaneInDock(*dock
, p
.window
))
2064 dock
->panes
.Add(&p
);
2068 // remove the pane from any existing docks
2069 RemovePaneFromDocks(docks
, p
);
2074 // remove any empty docks
2075 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
2077 if (docks
.Item(i
).panes
.GetCount() == 0)
2081 // configure the docks further
2082 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2084 wxAuiDockInfo
& dock
= docks
.Item(i
);
2085 int j
, dock_pane_count
= dock
.panes
.GetCount();
2087 // sort the dock pane array by the pane's
2088 // dock position (dock_pos), in ascending order
2089 dock
.panes
.Sort(PaneSortFunc
);
2091 // for newly created docks, set up their initial size
2096 for (j
= 0; j
< dock_pane_count
; ++j
)
2098 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2099 wxSize pane_size
= pane
.best_size
;
2100 if (pane_size
== wxDefaultSize
)
2101 pane_size
= pane
.min_size
;
2102 if (pane_size
== wxDefaultSize
)
2103 pane_size
= pane
.window
->GetSize();
2105 if (dock
.IsHorizontal())
2106 size
= wxMax(pane_size
.y
, size
);
2108 size
= wxMax(pane_size
.x
, size
);
2111 // add space for the border (two times), but only
2112 // if at least one pane inside the dock has a pane border
2113 for (j
= 0; j
< dock_pane_count
; ++j
)
2115 if (dock
.panes
.Item(j
)->HasBorder())
2117 size
+= (pane_border_size
*2);
2122 // if pane is on the top or bottom, add the caption height,
2123 // but only if at least one pane inside the dock has a caption
2124 if (dock
.IsHorizontal())
2126 for (j
= 0; j
< dock_pane_count
; ++j
)
2128 if (dock
.panes
.Item(j
)->HasCaption())
2130 size
+= caption_size
;
2137 // new dock's size may not be more than the dock constraint
2138 // parameter specifies. See SetDockSizeConstraint()
2140 int max_dock_x_size
= (int)(m_dock_constraint_x
* ((double)cli_size
.x
));
2141 int max_dock_y_size
= (int)(m_dock_constraint_y
* ((double)cli_size
.y
));
2143 if (dock
.IsHorizontal())
2144 size
= wxMin(size
, max_dock_y_size
);
2146 size
= wxMin(size
, max_dock_x_size
);
2148 // absolute minimum size for a dock is 10 pixels
2156 // determine the dock's minimum size
2157 bool plus_border
= false;
2158 bool plus_caption
= false;
2159 int dock_min_size
= 0;
2160 for (j
= 0; j
< dock_pane_count
; ++j
)
2162 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2163 if (pane
.min_size
!= wxDefaultSize
)
2165 if (pane
.HasBorder())
2167 if (pane
.HasCaption())
2168 plus_caption
= true;
2169 if (dock
.IsHorizontal())
2171 if (pane
.min_size
.y
> dock_min_size
)
2172 dock_min_size
= pane
.min_size
.y
;
2176 if (pane
.min_size
.x
> dock_min_size
)
2177 dock_min_size
= pane
.min_size
.x
;
2183 dock_min_size
+= (pane_border_size
*2);
2184 if (plus_caption
&& dock
.IsHorizontal())
2185 dock_min_size
+= (caption_size
);
2187 dock
.min_size
= dock_min_size
;
2190 // if the pane's current size is less than it's
2191 // minimum, increase the dock's size to it's minimum
2192 if (dock
.size
< dock
.min_size
)
2193 dock
.size
= dock
.min_size
;
2196 // determine the dock's mode (fixed or proportional);
2197 // determine whether the dock has only toolbars
2198 bool action_pane_marked
= false;
2200 dock
.toolbar
= true;
2201 for (j
= 0; j
< dock_pane_count
; ++j
)
2203 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2204 if (!pane
.IsFixed())
2206 if (!pane
.IsToolbar())
2207 dock
.toolbar
= false;
2208 if (pane
.HasFlag(wxAuiPaneInfo::optionDockFixed
))
2210 if (pane
.state
& wxAuiPaneInfo::actionPane
)
2211 action_pane_marked
= true;
2215 // if the dock mode is proportional and not fixed-pixel,
2216 // reassign the dock_pos to the sequential 0, 1, 2, 3;
2217 // e.g. remove gaps like 1, 2, 30, 500
2220 for (j
= 0; j
< dock_pane_count
; ++j
)
2222 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2227 // if the dock mode is fixed, and none of the panes
2228 // are being moved right now, make sure the panes
2229 // do not overlap each other. If they do, we will
2230 // adjust the positions of the panes
2231 if (dock
.fixed
&& !action_pane_marked
)
2233 wxArrayInt pane_positions
, pane_sizes
;
2234 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
2237 for (j
= 0; j
< dock_pane_count
; ++j
)
2239 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(j
));
2240 pane
.dock_pos
= pane_positions
[j
];
2242 int amount
= pane
.dock_pos
- offset
;
2246 pane
.dock_pos
+= -amount
;
2248 offset
+= pane_sizes
[j
];
2253 // discover the maximum dock layer
2255 for (i
= 0; i
< dock_count
; ++i
)
2256 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
2259 // clear out uiparts
2262 // create a bunch of box sizers,
2263 // from the innermost level outwards.
2264 wxSizer
* cont
= NULL
;
2265 wxSizer
* middle
= NULL
;
2269 for (layer
= 0; layer
<= max_layer
; ++layer
)
2271 wxAuiDockInfoPtrArray arr
;
2273 // find any docks in this layer
2274 FindDocks(docks
, -1, layer
, -1, arr
);
2276 // if there aren't any, skip to the next layer
2280 wxSizer
* old_cont
= cont
;
2282 // create a container which will hold this layer's
2283 // docks (top, bottom, left, right)
2284 cont
= new wxBoxSizer(wxVERTICAL
);
2287 // find any top docks in this layer
2288 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
2291 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2292 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2296 // fill out the middle layer (which consists
2297 // of left docks, content area and right docks)
2299 middle
= new wxBoxSizer(wxHORIZONTAL
);
2301 // find any left docks in this layer
2302 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
2305 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2306 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2309 // add content dock (or previous layer's sizer
2313 // find any center docks
2314 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
2317 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
2318 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2320 else if (!m_has_maximized
)
2322 // there are no center docks, add a background area
2323 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
2324 wxAuiDockUIPart part
;
2325 part
.type
= wxAuiDockUIPart::typeBackground
;
2329 part
.cont_sizer
= middle
;
2330 part
.sizer_item
= sizer_item
;
2336 middle
->Add(old_cont
, 1, wxEXPAND
);
2339 // find any right docks in this layer
2340 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
2343 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2344 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2347 if (middle
->GetChildren().GetCount() > 0)
2348 cont
->Add(middle
, 1, wxEXPAND
);
2354 // find any bottom docks in this layer
2355 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
2358 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2359 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2366 // no sizer available, because there are no docks,
2367 // therefore we will create a simple background area
2368 cont
= new wxBoxSizer(wxVERTICAL
);
2369 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
2370 wxAuiDockUIPart part
;
2371 part
.type
= wxAuiDockUIPart::typeBackground
;
2375 part
.cont_sizer
= middle
;
2376 part
.sizer_item
= sizer_item
;
2380 container
->Add(cont
, 1, wxEXPAND
);
2385 // SetDockSizeConstraint() allows the dock constraints to be set. For example,
2386 // specifying values of 0.5, 0.5 will mean that upon dock creation, a dock may
2387 // not be larger than half of the window's size
2389 void wxAuiManager::SetDockSizeConstraint(double width_pct
, double height_pct
)
2391 m_dock_constraint_x
= wxMax(0.0, wxMin(1.0, width_pct
));
2392 m_dock_constraint_y
= wxMax(0.0, wxMin(1.0, height_pct
));
2395 void wxAuiManager::GetDockSizeConstraint(double* width_pct
, double* height_pct
) const
2398 *width_pct
= m_dock_constraint_x
;
2401 *height_pct
= m_dock_constraint_y
;
2406 // Update() updates the layout. Whenever changes are made to
2407 // one or more panes, this function should be called. It is the
2408 // external entry point for running the layout engine.
2410 void wxAuiManager::Update()
2412 m_hover_button
= NULL
;
2413 m_action_part
= NULL
;
2416 int i
, pane_count
= m_panes
.GetCount();
2419 // destroy floating panes which have been
2420 // redocked or are becoming non-floating
2421 for (i
= 0; i
< pane_count
; ++i
)
2423 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2425 if (!p
.IsFloating() && p
.frame
)
2427 // because the pane is no longer in a floating, we need to
2428 // reparent it to m_frame and destroy the floating frame
2431 p
.window
->SetSize(1,1);
2434 // the following block is a workaround for bug #1531361
2435 // (see wxWidgets sourceforge page). On wxGTK (only), when
2436 // a frame is shown/hidden, a move event unfortunately
2437 // also gets fired. Because we may be dragging around
2438 // a pane, we need to cancel that action here to prevent
2439 // a spurious crash.
2440 if (m_action_window
== p
.frame
)
2442 if (wxWindow::GetCapture() == m_frame
)
2443 m_frame
->ReleaseMouse();
2444 m_action
= actionNone
;
2445 m_action_window
= NULL
;
2449 if (p
.frame
->IsShown())
2450 p
.frame
->Show(false);
2452 // reparent to m_frame and destroy the pane
2453 if (m_action_window
== p
.frame
)
2455 m_action_window
= NULL
;
2458 p
.window
->Reparent(m_frame
);
2459 p
.frame
->SetSizer(NULL
);
2466 // delete old sizer first
2467 m_frame
->SetSizer(NULL
);
2469 // create a layout for all of the panes
2470 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
2472 // hide or show panes as necessary,
2473 // and float panes as necessary
2474 for (i
= 0; i
< pane_count
; ++i
)
2476 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2480 if (p
.frame
== NULL
)
2482 // we need to create a frame for this
2483 // pane, which has recently been floated
2484 wxAuiFloatingFrame
* frame
= CreateFloatingFrame(m_frame
, p
);
2486 // on MSW and Mac, if the owner desires transparent dragging, and
2487 // the dragging is happening right now, then the floating
2488 // window should have this style by default
2489 if (m_action
== actionDragFloatingPane
&&
2490 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2491 frame
->SetTransparent(150);
2493 frame
->SetPaneWindow(p
);
2496 if (p
.IsShown() && !frame
->IsShown())
2501 // frame already exists, make sure it's position
2502 // and size reflect the information in wxAuiPaneInfo
2503 if ((p
.frame
->GetPosition() != p
.floating_pos
) || (p
.frame
->GetSize() != p
.floating_size
))
2505 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2506 p
.floating_size
.x
, p
.floating_size
.y
,
2507 wxSIZE_USE_EXISTING
);
2509 p.frame->SetSize(p.floating_pos.x, p.floating_pos.y,
2510 wxDefaultCoord, wxDefaultCoord,
2511 wxSIZE_USE_EXISTING);
2512 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2516 if (p
.frame
->IsShown() != p
.IsShown())
2517 p
.frame
->Show(p
.IsShown());
2522 if (p
.window
->IsShown() != p
.IsShown())
2523 p
.window
->Show(p
.IsShown());
2526 // if "active panes" are no longer allowed, clear
2527 // any optionActive values from the pane states
2528 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2530 p
.state
&= ~wxAuiPaneInfo::optionActive
;
2535 // keep track of the old window rectangles so we can
2536 // refresh those windows whose rect has changed
2537 wxAuiRectArray old_pane_rects
;
2538 for (i
= 0; i
< pane_count
; ++i
)
2541 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2543 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2546 old_pane_rects
.Add(r
);
2552 // apply the new sizer
2553 m_frame
->SetSizer(sizer
);
2554 m_frame
->SetAutoLayout(false);
2559 // now that the frame layout is done, we need to check
2560 // the new pane rectangles against the old rectangles that
2561 // we saved a few lines above here. If the rectangles have
2562 // changed, the corresponding panes must also be updated
2563 for (i
= 0; i
< pane_count
; ++i
)
2565 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2566 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2568 if (p
.rect
!= old_pane_rects
[i
])
2570 p
.window
->Refresh();
2579 // set frame's minimum size
2582 // N.B. More work needs to be done on frame minimum sizes;
2583 // this is some intresting code that imposes the minimum size,
2584 // but we may want to include a more flexible mechanism or
2585 // options for multiple minimum-size modes, e.g. strict or lax
2586 wxSize min_size = sizer->GetMinSize();
2587 wxSize frame_size = m_frame->GetSize();
2588 wxSize client_size = m_frame->GetClientSize();
2590 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2591 min_size.y+frame_size.y-client_size.y );
2593 m_frame->SetMinSize(minframe_size);
2595 if (frame_size.x < minframe_size.x ||
2596 frame_size.y < minframe_size.y)
2597 sizer->Fit(m_frame);
2602 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2603 // on the frame's main sizer, then measures all the various UI items
2604 // and updates their internal rectangles. This should always be called
2605 // instead of calling m_frame->Layout() directly
2607 void wxAuiManager::DoFrameLayout()
2612 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2614 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2616 // get the rectangle of the UI part
2617 // originally, this code looked like this:
2618 // part.rect = wxRect(part.sizer_item->GetPosition(),
2619 // part.sizer_item->GetSize());
2620 // this worked quite well, with one exception: the mdi
2621 // client window had a "deferred" size variable
2622 // that returned the wrong size. It looks like
2623 // a bug in wx, because the former size of the window
2624 // was being returned. So, we will retrieve the part's
2625 // rectangle via other means
2628 part
.rect
= part
.sizer_item
->GetRect();
2629 int flag
= part
.sizer_item
->GetFlag();
2630 int border
= part
.sizer_item
->GetBorder();
2633 part
.rect
.y
-= border
;
2634 part
.rect
.height
+= border
;
2638 part
.rect
.x
-= border
;
2639 part
.rect
.width
+= border
;
2641 if (flag
& wxBOTTOM
)
2642 part
.rect
.height
+= border
;
2644 part
.rect
.width
+= border
;
2647 if (part
.type
== wxAuiDockUIPart::typeDock
)
2648 part
.dock
->rect
= part
.rect
;
2649 if (part
.type
== wxAuiDockUIPart::typePane
)
2650 part
.pane
->rect
= part
.rect
;
2654 // GetPanePart() looks up the pane the pane border UI part (or the regular
2655 // pane part if there is no border). This allows the caller to get the exact
2656 // rectangle of the pane in question, including decorations like
2657 // caption and border (if any).
2659 wxAuiDockUIPart
* wxAuiManager::GetPanePart(wxWindow
* wnd
)
2662 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2664 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2665 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
2666 part
.pane
&& part
.pane
->window
== wnd
)
2669 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2671 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2672 if (part
.type
== wxAuiDockUIPart::typePane
&&
2673 part
.pane
&& part
.pane
->window
== wnd
)
2681 // GetDockPixelOffset() is an internal function which returns
2682 // a dock's offset in pixels from the left side of the window
2683 // (for horizontal docks) or from the top of the window (for
2684 // vertical docks). This value is necessary for calculating
2685 // fixel-pane/toolbar offsets when they are dragged.
2687 int wxAuiManager::GetDockPixelOffset(wxAuiPaneInfo
& test
)
2689 // the only way to accurately calculate the dock's
2690 // offset is to actually run a theoretical layout
2692 int i
, part_count
, dock_count
;
2693 wxAuiDockInfoArray docks
;
2694 wxAuiPaneInfoArray panes
;
2695 wxAuiDockUIPartArray uiparts
;
2696 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2699 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2700 wxSize client_size
= m_frame
->GetClientSize();
2701 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2704 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2706 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
2707 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2708 part
.sizer_item
->GetSize());
2709 if (part
.type
== wxAuiDockUIPart::typeDock
)
2710 part
.dock
->rect
= part
.rect
;
2715 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2717 wxAuiDockInfo
& dock
= docks
.Item(i
);
2718 if (test
.dock_direction
== dock
.dock_direction
&&
2719 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2721 if (dock
.IsVertical())
2733 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2734 // if a dock operation is allowed, the new dock position is copied into
2735 // the target info. If the operation was allowed, the function returns true.
2737 bool wxAuiManager::ProcessDockResult(wxAuiPaneInfo
& target
,
2738 const wxAuiPaneInfo
& new_pos
)
2740 bool allowed
= false;
2741 switch (new_pos
.dock_direction
)
2743 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2744 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2745 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2746 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2756 // DoDrop() is an important function. It basically takes a mouse position,
2757 // and determines where the pane's new position would be. If the pane is to be
2758 // dropped, it performs the drop operation using the specified dock and pane
2759 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2760 // scenario can be performed, giving precise coordinates for drop hints.
2761 // If, however, wxAuiManager:m_docks and wxAuiManager::m_panes are specified
2762 // as parameters, the changes will be made to the main state arrays
2764 const int auiInsertRowPixels
= 10;
2765 const int auiNewRowPixels
= 40;
2766 const int auiLayerInsertPixels
= 40;
2767 const int auiLayerInsertOffset
= 5;
2769 bool wxAuiManager::DoDrop(wxAuiDockInfoArray
& docks
,
2770 wxAuiPaneInfoArray
& panes
,
2771 wxAuiPaneInfo
& target
,
2773 const wxPoint
& offset
)
2775 wxSize cli_size
= m_frame
->GetClientSize();
2777 wxAuiPaneInfo drop
= target
;
2780 // The result should always be shown
2784 // Check to see if the pane has been dragged outside of the window
2785 // (or near to the outside of the window), if so, dock it along the edge
2788 int layer_insert_offset
= auiLayerInsertOffset
;
2789 if (drop
.IsToolbar())
2790 layer_insert_offset
= 0;
2793 if (pt
.x
< layer_insert_offset
&&
2794 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2796 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2797 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2798 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2800 if (drop
.IsToolbar())
2801 new_layer
= auiToolBarLayer
;
2806 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2807 return ProcessDockResult(target
, drop
);
2809 else if (pt
.y
< layer_insert_offset
&&
2810 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2812 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2813 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2814 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2816 if (drop
.IsToolbar())
2817 new_layer
= auiToolBarLayer
;
2822 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2823 return ProcessDockResult(target
, drop
);
2825 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2826 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2828 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2829 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2830 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2832 if (drop
.IsToolbar())
2833 new_layer
= auiToolBarLayer
;
2835 drop
.Dock().Right().
2838 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2839 return ProcessDockResult(target
, drop
);
2841 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2842 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2844 int new_layer
= wxMax( wxMax( GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2845 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2846 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2848 if (drop
.IsToolbar())
2849 new_layer
= auiToolBarLayer
;
2851 drop
.Dock().Bottom().
2854 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2855 return ProcessDockResult(target
, drop
);
2859 wxAuiDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2862 if (drop
.IsToolbar())
2864 if (!part
|| !part
->dock
)
2867 // calculate the offset from where the dock begins
2868 // to the point where the user dropped the pane
2869 int dock_drop_offset
= 0;
2870 if (part
->dock
->IsHorizontal())
2871 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2873 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2876 // toolbars may only be moved in and to fixed-pane docks,
2877 // otherwise we will try to float the pane. Also, the pane
2878 // should float if being dragged over center pane windows
2879 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2881 if (m_last_rect
.IsEmpty() || m_last_rect
.Contains(pt
.x
, pt
.y
))
2887 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2888 (drop
.IsFloatable() ||
2889 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2890 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2892 if (drop
.IsFloatable())
2898 return ProcessDockResult(target
, drop
);
2901 drop
.Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2903 return ProcessDockResult(target
, drop
);
2908 m_last_rect
= part
->dock
->rect
;
2909 m_last_rect
.Inflate( 15, 15 );
2912 Direction(part
->dock
->dock_direction
).
2913 Layer(part
->dock
->dock_layer
).
2914 Row(part
->dock
->dock_row
).
2915 Position(dock_drop_offset
);
2918 ((pt
.y
< part
->dock
->rect
.y
+ 1) && part
->dock
->IsHorizontal()) ||
2919 ((pt
.x
< part
->dock
->rect
.x
+ 1) && part
->dock
->IsVertical())
2920 ) && part
->dock
->panes
.GetCount() > 1)
2922 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2923 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2925 int row
= drop
.dock_row
;
2926 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2927 part
->dock
->dock_layer
,
2928 part
->dock
->dock_row
);
2929 drop
.dock_row
= row
;
2933 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2934 part
->dock
->dock_layer
,
2935 part
->dock
->dock_row
+1);
2936 drop
.dock_row
= part
->dock
->dock_row
+1;
2941 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2942 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2943 ) && part
->dock
->panes
.GetCount() > 1)
2945 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2946 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2948 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2949 part
->dock
->dock_layer
,
2950 part
->dock
->dock_row
+1);
2951 drop
.dock_row
= part
->dock
->dock_row
+1;
2955 int row
= drop
.dock_row
;
2956 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2957 part
->dock
->dock_layer
,
2958 part
->dock
->dock_row
);
2959 drop
.dock_row
= row
;
2963 return ProcessDockResult(target
, drop
);
2972 if (part
->type
== wxAuiDockUIPart::typePaneBorder
||
2973 part
->type
== wxAuiDockUIPart::typeCaption
||
2974 part
->type
== wxAuiDockUIPart::typeGripper
||
2975 part
->type
== wxAuiDockUIPart::typePaneButton
||
2976 part
->type
== wxAuiDockUIPart::typePane
||
2977 part
->type
== wxAuiDockUIPart::typePaneSizer
||
2978 part
->type
== wxAuiDockUIPart::typeDockSizer
||
2979 part
->type
== wxAuiDockUIPart::typeBackground
)
2981 if (part
->type
== wxAuiDockUIPart::typeDockSizer
)
2983 if (part
->dock
->panes
.GetCount() != 1)
2985 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2992 // If a normal frame is being dragged over a toolbar, insert it
2993 // along the edge under the toolbar, but over all other panes.
2994 // (this could be done much better, but somehow factoring this
2995 // calculation with the one at the beginning of this function)
2996 if (part
->dock
&& part
->dock
->toolbar
)
3000 switch (part
->dock
->dock_direction
)
3002 case wxAUI_DOCK_LEFT
:
3003 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
3004 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
3005 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
3007 case wxAUI_DOCK_TOP
:
3008 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
3009 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
3010 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
3012 case wxAUI_DOCK_RIGHT
:
3013 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
3014 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
3015 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
3017 case wxAUI_DOCK_BOTTOM
:
3018 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
3019 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
3020 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
3024 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
3027 Direction(part
->dock
->dock_direction
).
3028 Layer(layer
).Row(0).Position(0);
3029 return ProcessDockResult(target
, drop
);
3036 part
= GetPanePart(part
->pane
->window
);
3040 bool insert_dock_row
= false;
3041 int insert_row
= part
->pane
->dock_row
;
3042 int insert_dir
= part
->pane
->dock_direction
;
3043 int insert_layer
= part
->pane
->dock_layer
;
3045 switch (part
->pane
->dock_direction
)
3047 case wxAUI_DOCK_TOP
:
3048 if (pt
.y
>= part
->rect
.y
&&
3049 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
3050 insert_dock_row
= true;
3052 case wxAUI_DOCK_BOTTOM
:
3053 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
3054 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
3055 insert_dock_row
= true;
3057 case wxAUI_DOCK_LEFT
:
3058 if (pt
.x
>= part
->rect
.x
&&
3059 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
3060 insert_dock_row
= true;
3062 case wxAUI_DOCK_RIGHT
:
3063 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
3064 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
3065 insert_dock_row
= true;
3067 case wxAUI_DOCK_CENTER
:
3069 // "new row pixels" will be set to the default, but
3070 // must never exceed 20% of the window size
3071 int new_row_pixels_x
= auiNewRowPixels
;
3072 int new_row_pixels_y
= auiNewRowPixels
;
3074 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
3075 new_row_pixels_x
= (part
->rect
.width
*20)/100;
3077 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
3078 new_row_pixels_y
= (part
->rect
.height
*20)/100;
3081 // determine if the mouse pointer is in a location that
3082 // will cause a new row to be inserted. The hot spot positions
3083 // are along the borders of the center pane
3086 insert_dock_row
= true;
3087 const wxRect
& pr
= part
->rect
;
3088 if (pt
.x
>= pr
.x
&& pt
.x
< pr
.x
+ new_row_pixels_x
)
3089 insert_dir
= wxAUI_DOCK_LEFT
;
3090 else if (pt
.y
>= pr
.y
&& pt
.y
< pr
.y
+ new_row_pixels_y
)
3091 insert_dir
= wxAUI_DOCK_TOP
;
3092 else if (pt
.x
>= pr
.x
+ pr
.width
- new_row_pixels_x
&&
3093 pt
.x
< pr
.x
+ pr
.width
)
3094 insert_dir
= wxAUI_DOCK_RIGHT
;
3095 else if (pt
.y
>= pr
.y
+ pr
.height
- new_row_pixels_y
&&
3096 pt
.y
< pr
.y
+ pr
.height
)
3097 insert_dir
= wxAUI_DOCK_BOTTOM
;
3101 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
3105 if (insert_dock_row
)
3107 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
3108 drop
.Dock().Direction(insert_dir
).
3109 Layer(insert_layer
).
3112 return ProcessDockResult(target
, drop
);
3115 // determine the mouse offset and the pane size, both in the
3116 // direction of the dock itself, and perpendicular to the dock
3120 if (part
->orientation
== wxVERTICAL
)
3122 offset
= pt
.y
- part
->rect
.y
;
3123 size
= part
->rect
.GetHeight();
3127 offset
= pt
.x
- part
->rect
.x
;
3128 size
= part
->rect
.GetWidth();
3131 int drop_position
= part
->pane
->dock_pos
;
3133 // if we are in the top/left part of the pane,
3134 // insert the pane before the pane being hovered over
3135 if (offset
<= size
/2)
3137 drop_position
= part
->pane
->dock_pos
;
3139 part
->pane
->dock_direction
,
3140 part
->pane
->dock_layer
,
3141 part
->pane
->dock_row
,
3142 part
->pane
->dock_pos
);
3145 // if we are in the bottom/right part of the pane,
3146 // insert the pane before the pane being hovered over
3147 if (offset
> size
/2)
3149 drop_position
= part
->pane
->dock_pos
+1;
3151 part
->pane
->dock_direction
,
3152 part
->pane
->dock_layer
,
3153 part
->pane
->dock_row
,
3154 part
->pane
->dock_pos
+1);
3158 Direction(part
->dock
->dock_direction
).
3159 Layer(part
->dock
->dock_layer
).
3160 Row(part
->dock
->dock_row
).
3161 Position(drop_position
);
3162 return ProcessDockResult(target
, drop
);
3169 void wxAuiManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
3171 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
3173 m_hint_fadetimer
.Stop();
3177 m_hint_fadeamt
+= 4;
3178 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
3181 void wxAuiManager::ShowHint(const wxRect
& rect
)
3185 // if the hint rect is the same as last time, don't do anything
3186 if (m_last_hint
== rect
)
3190 m_hint_fadeamt
= m_hint_fademax
;
3192 if ((m_flags
& wxAUI_MGR_HINT_FADE
)
3193 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
3194 (m_flags
& wxAUI_MGR_NO_VENETIAN_BLINDS_FADE
))
3198 m_hint_wnd
->SetSize(rect
);
3199 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
3201 if (!m_hint_wnd
->IsShown())
3204 // if we are dragging a floating pane, set the focus
3205 // back to that floating pane (otherwise it becomes unfocused)
3206 if (m_action
== actionDragFloatingPane
&& m_action_window
)
3207 m_action_window
->SetFocus();
3209 m_hint_wnd
->Raise();
3212 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
3214 // start fade in timer
3215 m_hint_fadetimer
.SetOwner(this, 101);
3216 m_hint_fadetimer
.Start(5);
3219 else // Not using a transparent hint window...
3221 if (!(m_flags
& wxAUI_MGR_RECTANGLE_HINT
))
3224 if (m_last_hint
!= rect
)
3226 // remove the last hint rectangle
3232 wxScreenDC screendc
;
3233 wxRegion
clip(1, 1, 10000, 10000);
3235 // clip all floating windows, so we don't draw over them
3237 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
3239 wxAuiPaneInfo
& pane
= m_panes
.Item(i
);
3241 if (pane
.IsFloating() &&
3242 pane
.frame
->IsShown())
3244 wxRect rect
= pane
.frame
->GetRect();
3246 // wxGTK returns the client size, not the whole frame size
3252 clip
.Subtract(rect
);
3256 // As we can only hide the hint by redrawing the managed window, we
3257 // need to clip the region to the managed window too or we get
3258 // nasty redrawn problems.
3259 clip
.Intersect(m_frame
->GetRect());
3261 screendc
.SetDeviceClippingRegion(clip
);
3263 wxBitmap stipple
= wxPaneCreateStippleBitmap();
3264 wxBrush
brush(stipple
);
3265 screendc
.SetBrush(brush
);
3266 screendc
.SetPen(*wxTRANSPARENT_PEN
);
3268 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
3269 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
3270 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
3271 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
3275 void wxAuiManager::HideHint()
3277 // hides a transparent window hint, if there is one
3280 if (m_hint_wnd
->IsShown())
3281 m_hint_wnd
->Show(false);
3282 m_hint_wnd
->SetTransparent(0);
3283 m_hint_fadetimer
.Stop();
3284 m_last_hint
= wxRect();
3288 // hides a painted hint by redrawing the frame window
3289 if (!m_last_hint
.IsEmpty())
3293 m_last_hint
= wxRect();
3299 void wxAuiManager::StartPaneDrag(wxWindow
* pane_window
,
3300 const wxPoint
& offset
)
3302 wxAuiPaneInfo
& pane
= GetPane(pane_window
);
3306 if (pane
.IsToolbar())
3308 m_action
= actionDragToolbarPane
;
3312 m_action
= actionDragFloatingPane
;
3315 m_action_window
= pane_window
;
3316 m_action_offset
= offset
;
3317 m_frame
->CaptureMouse();
3321 // CalculateHintRect() calculates the drop hint rectangle. The method
3322 // first calls DoDrop() to determine the exact position the pane would
3323 // be at were if dropped. If the pane would indeed become docked at the
3324 // specified drop point, the the rectangle hint will be returned in
3325 // screen coordinates. Otherwise, an empty rectangle is returned.
3326 // |pane_window| is the window pointer of the pane being dragged, |pt| is
3327 // the mouse position, in client coordinates. |offset| describes the offset
3328 // that the mouse is from the upper-left corner of the item being dragged
3330 wxRect
wxAuiManager::CalculateHintRect(wxWindow
* pane_window
,
3332 const wxPoint
& offset
)
3336 // we need to paint a hint rectangle; to find out the exact hint rectangle,
3337 // we will create a new temporary layout and then measure the resulting
3338 // rectangle; we will create a copy of the docking structures (m_dock)
3339 // so that we don't modify the real thing on screen
3341 int i
, pane_count
, part_count
;
3342 wxAuiDockInfoArray docks
;
3343 wxAuiPaneInfoArray panes
;
3344 wxAuiDockUIPartArray uiparts
;
3345 wxAuiPaneInfo hint
= GetPane(pane_window
);
3346 hint
.name
= wxT("__HINT__");
3347 hint
.PaneBorder(true);
3353 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3355 // remove any pane already there which bears the same window;
3356 // this happens when you are moving a pane around in a dock
3357 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
3359 if (panes
.Item(i
).window
== pane_window
)
3361 RemovePaneFromDocks(docks
, panes
.Item(i
));
3367 // find out where the new pane would be
3368 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
3375 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
3376 wxSize client_size
= m_frame
->GetClientSize();
3377 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
3380 for (i
= 0, part_count
= uiparts
.GetCount();
3381 i
< part_count
; ++i
)
3383 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
3385 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
3386 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
3388 rect
= wxRect(part
.sizer_item
->GetPosition(),
3389 part
.sizer_item
->GetSize());
3401 // actually show the hint rectangle on the screen
3402 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
3404 if ( m_frame
->GetLayoutDirection() == wxLayout_RightToLeft
)
3406 // Mirror rectangle in RTL mode
3407 rect
.x
-= rect
.GetWidth();
3413 // DrawHintRect() calculates the hint rectangle by calling
3414 // CalculateHintRect(). If there is a rectangle, it shows it
3415 // by calling ShowHint(), otherwise it hides any hint
3416 // rectangle currently shown
3417 void wxAuiManager::DrawHintRect(wxWindow
* pane_window
,
3419 const wxPoint
& offset
)
3421 wxRect rect
= CalculateHintRect(pane_window
, pt
, offset
);
3433 void wxAuiManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
3435 // try to find the pane
3436 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3437 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3439 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3440 pane
.frame
->SetTransparent(150);
3443 void wxAuiManager::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
3445 // try to find the pane
3446 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3447 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3449 wxPoint pt
= ::wxGetMousePosition();
3452 // Adapt pt to direction
3455 // move to pane's upper border
3457 pos
= wnd
->ClientToScreen( pos
);
3459 // and some more pixels for the title bar
3462 else if (dir
== wxWEST
)
3464 // move to pane's left border
3466 pos
= wnd
->ClientToScreen( pos
);
3469 else if (dir
== wxEAST
)
3471 // move to pane's right border
3472 wxPoint
pos( wnd
->GetSize().x
, 0 );
3473 pos
= wnd
->ClientToScreen( pos
);
3476 else if (dir
== wxSOUTH
)
3478 // move to pane's bottom border
3479 wxPoint
pos( 0, wnd
->GetSize().y
);
3480 pos
= wnd
->ClientToScreen( pos
);
3487 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3489 // calculate the offset from the upper left-hand corner
3490 // of the frame to the mouse pointer
3491 wxPoint frame_pos
= pane
.frame
->GetPosition();
3492 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3494 // no hint for toolbar floating windows
3495 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
3497 wxAuiDockInfoArray docks
;
3498 wxAuiPaneInfoArray panes
;
3499 wxAuiDockUIPartArray uiparts
;
3500 wxAuiPaneInfo hint
= pane
;
3502 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3504 // find out where the new pane would be
3505 if (!DoDrop(docks
, panes
, hint
, client_pt
))
3507 if (hint
.IsFloating())
3511 m_action
= actionDragToolbarPane
;
3512 m_action_window
= pane
.window
;
3520 // if a key modifier is pressed while dragging the frame,
3521 // don't dock the window
3522 if (!CanDockPanel(pane
))
3529 DrawHintRect(wnd
, client_pt
, action_offset
);
3532 // this cleans up some screen artifacts that are caused on GTK because
3533 // we aren't getting the exact size of the window (see comment
3543 void wxAuiManager::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
3545 // try to find the pane
3546 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3547 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3549 wxPoint pt
= ::wxGetMousePosition();
3552 // Adapt pt to direction
3555 // move to pane's upper border
3557 pos
= wnd
->ClientToScreen( pos
);
3559 // and some more pixels for the title bar
3562 else if (dir
== wxWEST
)
3564 // move to pane's left border
3566 pos
= wnd
->ClientToScreen( pos
);
3569 else if (dir
== wxEAST
)
3571 // move to pane's right border
3572 wxPoint
pos( wnd
->GetSize().x
, 0 );
3573 pos
= wnd
->ClientToScreen( pos
);
3576 else if (dir
== wxSOUTH
)
3578 // move to pane's bottom border
3579 wxPoint
pos( 0, wnd
->GetSize().y
);
3580 pos
= wnd
->ClientToScreen( pos
);
3587 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3589 // calculate the offset from the upper left-hand corner
3590 // of the frame to the mouse pointer
3591 wxPoint frame_pos
= pane
.frame
->GetPosition();
3592 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3594 // if a key modifier is pressed while dragging the frame,
3595 // don't dock the window
3596 if (CanDockPanel(pane
))
3598 // do the drop calculation
3599 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3602 // if the pane is still floating, update it's floating
3603 // position (that we store)
3604 if (pane
.IsFloating())
3606 pane
.floating_pos
= pane
.frame
->GetPosition();
3608 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3609 pane
.frame
->SetTransparent(255);
3611 else if (m_has_maximized
)
3613 RestoreMaximizedPane();
3621 void wxAuiManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3623 // try to find the pane
3624 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3625 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3627 pane
.floating_size
= size
;
3631 void wxAuiManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3633 // try to find the pane
3634 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3635 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3638 // fire pane close event
3639 wxAuiManagerEvent
e(wxEVT_AUI_PANE_CLOSE
);
3641 e
.SetCanVeto(evt
.CanVeto());
3651 // close the pane, but check that it
3652 // still exists in our pane array first
3653 // (the event handler above might have removed it)
3655 wxAuiPaneInfo
& check
= GetPane(wnd
);
3665 void wxAuiManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3667 if ((GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
) && GetPane(wnd
).IsOk())
3669 SetActivePane(m_panes
, wnd
);
3674 // OnRender() draws all of the pane captions, sashes,
3675 // backgrounds, captions, grippers, pane borders and buttons.
3676 // It renders the entire user interface.
3678 void wxAuiManager::OnRender(wxAuiManagerEvent
& evt
)
3680 // if the frame is about to be deleted, don't bother
3681 if (!m_frame
|| wxPendingDelete
.Member(m_frame
))
3684 wxDC
* dc
= evt
.GetDC();
3690 for (i
= 0, part_count
= m_uiparts
.GetCount();
3691 i
< part_count
; ++i
)
3693 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
3695 // don't draw hidden pane items or items that aren't windows
3696 if (part
.sizer_item
&& ((!part
.sizer_item
->IsWindow() && !part
.sizer_item
->IsSpacer() && !part
.sizer_item
->IsSizer()) || !part
.sizer_item
->IsShown()))
3701 case wxAuiDockUIPart::typeDockSizer
:
3702 case wxAuiDockUIPart::typePaneSizer
:
3703 m_art
->DrawSash(*dc
, m_frame
, part
.orientation
, part
.rect
);
3705 case wxAuiDockUIPart::typeBackground
:
3706 m_art
->DrawBackground(*dc
, m_frame
, part
.orientation
, part
.rect
);
3708 case wxAuiDockUIPart::typeCaption
:
3709 m_art
->DrawCaption(*dc
, m_frame
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3711 case wxAuiDockUIPart::typeGripper
:
3712 m_art
->DrawGripper(*dc
, m_frame
, part
.rect
, *part
.pane
);
3714 case wxAuiDockUIPart::typePaneBorder
:
3715 m_art
->DrawBorder(*dc
, m_frame
, part
.rect
, *part
.pane
);
3717 case wxAuiDockUIPart::typePaneButton
:
3718 m_art
->DrawPaneButton(*dc
, m_frame
, part
.button
->button_id
,
3719 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3726 // Render() fire a render event, which is normally handled by
3727 // wxAuiManager::OnRender(). This allows the render function to
3728 // be overridden via the render event. This can be useful for paintin
3729 // custom graphics in the main window. Default behavior can be
3730 // invoked in the overridden function by calling OnRender()
3732 void wxAuiManager::Render(wxDC
* dc
)
3734 wxAuiManagerEvent
e(wxEVT_AUI_RENDER
);
3740 void wxAuiManager::Repaint(wxDC
* dc
)
3745 m_frame
->Refresh() ;
3751 m_frame
->GetClientSize(&w
, &h
);
3753 // figure out which dc to use; if one
3754 // has been specified, use it, otherwise
3756 wxClientDC
* client_dc
= NULL
;
3759 client_dc
= new wxClientDC(m_frame
);
3763 // if the frame has a toolbar, the client area
3764 // origin will not be (0,0).
3765 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3766 if (pt
.x
!= 0 || pt
.y
!= 0)
3767 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3769 // render all the items
3772 // if we created a client_dc, delete it
3777 void wxAuiManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3779 wxPaintDC
dc(m_frame
);
3783 void wxAuiManager::OnEraseBackground(wxEraseEvent
& event
)
3792 void wxAuiManager::OnSize(wxSizeEvent
& event
)
3800 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
3802 // for MDI parent frames, this event must not
3803 // be "skipped". In other words, the parent frame
3804 // must not be allowed to resize the client window
3805 // after we are finished processing sizing changes
3813 void wxAuiManager::OnFindManager(wxAuiManagerEvent
& evt
)
3815 // get the window we are managing, if none, return NULL
3816 wxWindow
* window
= GetManagedWindow();
3819 evt
.SetManager(NULL
);
3823 // if we are managing a child frame, get the 'real' manager
3824 if (window
->IsKindOf(CLASSINFO(wxAuiFloatingFrame
)))
3826 wxAuiFloatingFrame
* float_frame
= static_cast<wxAuiFloatingFrame
*>(window
);
3827 evt
.SetManager(float_frame
->GetOwnerManager());
3831 // return pointer to ourself
3832 evt
.SetManager(this);
3835 void wxAuiManager::OnSetCursor(wxSetCursorEvent
& event
)
3838 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3839 wxCursor cursor
= wxNullCursor
;
3843 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3844 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3846 // a dock may not be resized if it has a single
3847 // pane which is not resizable
3848 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3849 part
->dock
->panes
.GetCount() == 1 &&
3850 part
->dock
->panes
.Item(0)->IsFixed())
3853 // panes that may not be resized do not get a sizing cursor
3854 if (part
->pane
&& part
->pane
->IsFixed())
3857 if (part
->orientation
== wxVERTICAL
)
3858 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3860 cursor
= wxCursor(wxCURSOR_SIZENS
);
3862 else if (part
->type
== wxAuiDockUIPart::typeGripper
)
3864 cursor
= wxCursor(wxCURSOR_SIZING
);
3868 event
.SetCursor(cursor
);
3873 void wxAuiManager::UpdateButtonOnScreen(wxAuiDockUIPart
* button_ui_part
,
3874 const wxMouseEvent
& event
)
3876 wxAuiDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3877 if (!hit_test
|| !button_ui_part
)
3880 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3882 if (hit_test
== button_ui_part
)
3884 if (event
.LeftDown())
3885 state
= wxAUI_BUTTON_STATE_PRESSED
;
3887 state
= wxAUI_BUTTON_STATE_HOVER
;
3891 if (event
.LeftDown())
3892 state
= wxAUI_BUTTON_STATE_HOVER
;
3895 // now repaint the button with hover state
3896 wxClientDC
cdc(m_frame
);
3898 // if the frame has a toolbar, the client area
3899 // origin will not be (0,0).
3900 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3901 if (pt
.x
!= 0 || pt
.y
!= 0)
3902 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3906 m_art
->DrawPaneButton(cdc
, m_frame
,
3907 button_ui_part
->button
->button_id
,
3909 button_ui_part
->rect
,
3914 void wxAuiManager::OnLeftDown(wxMouseEvent
& event
)
3916 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3919 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3920 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3922 // Removing this restriction so that a centre pane can be resized
3923 //if (part->dock && part->dock->dock_direction == wxAUI_DOCK_CENTER)
3926 // a dock may not be resized if it has a single
3927 // pane which is not resizable
3928 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3929 part
->dock
->panes
.GetCount() == 1 &&
3930 part
->dock
->panes
.Item(0)->IsFixed())
3933 // panes that may not be resized should be ignored here
3934 if (part
->pane
&& part
->pane
->IsFixed())
3937 m_action
= actionResize
;
3938 m_action_part
= part
;
3939 m_action_hintrect
= wxRect();
3940 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3941 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3942 event
.m_y
- part
->rect
.y
);
3943 m_frame
->CaptureMouse();
3945 else if (part
->type
== wxAuiDockUIPart::typePaneButton
)
3947 m_action
= actionClickButton
;
3948 m_action_part
= part
;
3949 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3950 m_frame
->CaptureMouse();
3952 UpdateButtonOnScreen(part
, event
);
3954 else if (part
->type
== wxAuiDockUIPart::typeCaption
||
3955 part
->type
== wxAuiDockUIPart::typeGripper
)
3957 // if we are managing a wxAuiFloatingFrame window, then
3958 // we are an embedded wxAuiManager inside the wxAuiFloatingFrame.
3959 // We want to initiate a toolbar drag in our owner manager
3960 wxWindow
* managed_wnd
= GetManagedWindow();
3963 part
->pane
->window
&&
3965 managed_wnd
->IsKindOf(CLASSINFO(wxAuiFloatingFrame
)))
3967 wxAuiFloatingFrame
* floating_frame
= (wxAuiFloatingFrame
*)managed_wnd
;
3968 wxAuiManager
* owner_mgr
= floating_frame
->GetOwnerManager();
3969 owner_mgr
->StartPaneDrag(part
->pane
->window
,
3970 wxPoint(event
.m_x
- part
->rect
.x
,
3971 event
.m_y
- part
->rect
.y
));
3977 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3979 // set the caption as active
3980 SetActivePane(m_panes
, part
->pane
->window
);
3984 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3987 m_action
= actionClickCaption
;
3988 m_action_part
= part
;
3989 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3990 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3991 event
.m_y
- part
->rect
.y
);
3992 m_frame
->CaptureMouse();
4012 void wxAuiManager::OnLeftUp(wxMouseEvent
& event
)
4014 if (m_action
== actionResize
)
4016 m_frame
->ReleaseMouse();
4018 // get rid of the hint rectangle
4020 DrawResizeHint(dc
, m_action_hintrect
);
4022 // resize the dock or the pane
4023 if (m_action_part
&& m_action_part
->type
==wxAuiDockUIPart::typeDockSizer
)
4025 wxRect
& rect
= m_action_part
->dock
->rect
;
4027 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
4028 event
.m_y
- m_action_offset
.y
);
4030 switch (m_action_part
->dock
->dock_direction
)
4032 case wxAUI_DOCK_LEFT
:
4033 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
4035 case wxAUI_DOCK_TOP
:
4036 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
4038 case wxAUI_DOCK_RIGHT
:
4039 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
4040 new_pos
.x
- m_action_part
->rect
.GetWidth();
4042 case wxAUI_DOCK_BOTTOM
:
4043 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
4044 new_pos
.y
- m_action_part
->rect
.GetHeight();
4051 else if (m_action_part
&&
4052 m_action_part
->type
== wxAuiDockUIPart::typePaneSizer
)
4054 wxAuiDockInfo
& dock
= *m_action_part
->dock
;
4055 wxAuiPaneInfo
& pane
= *m_action_part
->pane
;
4057 int total_proportion
= 0;
4058 int dock_pixels
= 0;
4059 int new_pixsize
= 0;
4061 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
4062 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
4063 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
4065 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
4066 event
.m_y
- m_action_offset
.y
);
4068 // determine the pane rectangle by getting the pane part
4069 wxAuiDockUIPart
* pane_part
= GetPanePart(pane
.window
);
4070 wxASSERT_MSG(pane_part
,
4071 wxT("Pane border part not found -- shouldn't happen"));
4073 // determine the new pixel size that the user wants;
4074 // this will help us recalculate the pane's proportion
4075 if (dock
.IsHorizontal())
4076 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
4078 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
4080 // determine the size of the dock, based on orientation
4081 if (dock
.IsHorizontal())
4082 dock_pixels
= dock
.rect
.GetWidth();
4084 dock_pixels
= dock
.rect
.GetHeight();
4086 // determine the total proportion of all resizable panes,
4087 // and the total size of the dock minus the size of all
4089 int i
, dock_pane_count
= dock
.panes
.GetCount();
4090 int pane_position
= -1;
4091 for (i
= 0; i
< dock_pane_count
; ++i
)
4093 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
4094 if (p
.window
== pane
.window
)
4097 // while we're at it, subtract the pane sash
4098 // width from the dock width, because this would
4099 // skew our proportion calculations
4101 dock_pixels
-= sash_size
;
4103 // also, the whole size (including decorations) of
4104 // all fixed panes must also be subtracted, because they
4105 // are not part of the proportion calculation
4108 if (dock
.IsHorizontal())
4109 dock_pixels
-= p
.best_size
.x
;
4111 dock_pixels
-= p
.best_size
.y
;
4115 total_proportion
+= p
.dock_proportion
;
4119 // find a pane in our dock to 'steal' space from or to 'give'
4120 // space to -- this is essentially what is done when a pane is
4121 // resized; the pane should usually be the first non-fixed pane
4122 // to the right of the action pane
4123 int borrow_pane
= -1;
4124 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
4126 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
4135 // demand that the pane being resized is found in this dock
4136 // (this assert really never should be raised)
4137 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
4139 // prevent division by zero
4140 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
4142 m_action
= actionNone
;
4146 // calculate the new proportion of the pane
4147 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
4149 // default minimum size
4152 // check against the pane's minimum size, if specified. please note
4153 // that this is not enough to ensure that the minimum size will
4154 // not be violated, because the whole frame might later be shrunk,
4155 // causing the size of the pane to violate it's minimum size
4156 if (pane
.min_size
.IsFullySpecified())
4160 if (pane
.HasBorder())
4161 min_size
+= (pane_border_size
*2);
4163 // calculate minimum size with decorations (border,caption)
4164 if (pane_part
->orientation
== wxVERTICAL
)
4166 min_size
+= pane
.min_size
.y
;
4167 if (pane
.HasCaption())
4168 min_size
+= caption_size
;
4172 min_size
+= pane
.min_size
.x
;
4177 // for some reason, an arithmatic error somewhere is causing
4178 // the proportion calculations to always be off by 1 pixel;
4179 // for now we will add the 1 pixel on, but we really should
4180 // determine what's causing this.
4183 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
4185 if (new_proportion
< min_proportion
)
4186 new_proportion
= min_proportion
;
4190 int prop_diff
= new_proportion
- pane
.dock_proportion
;
4192 // borrow the space from our neighbor pane to the
4193 // right or bottom (depending on orientation)
4194 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
4195 pane
.dock_proportion
= new_proportion
;
4202 else if (m_action
== actionClickButton
)
4204 m_hover_button
= NULL
;
4205 m_frame
->ReleaseMouse();
4209 UpdateButtonOnScreen(m_action_part
, event
);
4211 // make sure we're still over the item that was originally clicked
4212 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
4214 // fire button-click event
4215 wxAuiManagerEvent
e(wxEVT_AUI_PANE_BUTTON
);
4217 e
.SetPane(m_action_part
->pane
);
4218 e
.SetButton(m_action_part
->button
->button_id
);
4223 else if (m_action
== actionClickCaption
)
4225 m_frame
->ReleaseMouse();
4227 else if (m_action
== actionDragFloatingPane
)
4229 m_frame
->ReleaseMouse();
4231 else if (m_action
== actionDragToolbarPane
)
4233 m_frame
->ReleaseMouse();
4235 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4236 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4238 // save the new positions
4239 wxAuiDockInfoPtrArray docks
;
4240 FindDocks(m_docks
, pane
.dock_direction
,
4241 pane
.dock_layer
, pane
.dock_row
, docks
);
4242 if (docks
.GetCount() == 1)
4244 wxAuiDockInfo
& dock
= *docks
.Item(0);
4246 wxArrayInt pane_positions
, pane_sizes
;
4247 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
4249 int i
, dock_pane_count
= dock
.panes
.GetCount();
4250 for (i
= 0; i
< dock_pane_count
; ++i
)
4251 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
4254 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
4262 m_action
= actionNone
;
4263 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
4267 void wxAuiManager::OnMotion(wxMouseEvent
& event
)
4269 // sometimes when Update() is called from inside this method,
4270 // a spurious mouse move event is generated; this check will make
4271 // sure that only real mouse moves will get anywhere in this method;
4272 // this appears to be a bug somewhere, and I don't know where the
4273 // mouse move event is being generated. only verified on MSW
4275 wxPoint mouse_pos
= event
.GetPosition();
4276 if (m_last_mouse_move
== mouse_pos
)
4278 m_last_mouse_move
= mouse_pos
;
4281 if (m_action
== actionResize
)
4285 wxPoint pos
= m_action_part
->rect
.GetPosition();
4286 if (m_action_part
->orientation
== wxHORIZONTAL
)
4287 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
4289 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
4291 wxRect
rect(m_frame
->ClientToScreen(pos
),
4292 m_action_part
->rect
.GetSize());
4295 if (!m_action_hintrect
.IsEmpty())
4296 DrawResizeHint(dc
, m_action_hintrect
);
4297 DrawResizeHint(dc
, rect
);
4298 m_action_hintrect
= rect
;
4301 else if (m_action
== actionClickCaption
)
4303 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
4304 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
4306 // caption has been clicked. we need to check if the mouse
4307 // is now being dragged. if it is, we need to change the
4308 // mouse action to 'drag'
4309 if (m_action_part
&&
4310 (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
4311 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
))
4313 wxAuiPaneInfo
* pane_info
= m_action_part
->pane
;
4315 if (!pane_info
->IsToolbar())
4317 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
4318 pane_info
->IsFloatable())
4320 m_action
= actionDragFloatingPane
;
4322 // set initial float position
4323 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4324 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4325 pt
.y
- m_action_offset
.y
);
4328 if (pane_info
->IsMaximized())
4329 RestorePane(*pane_info
);
4333 m_action_window
= pane_info
->frame
;
4335 // action offset is used here to make it feel "natural" to the user
4336 // to drag a docked pane and suddenly have it become a floating frame.
4337 // Sometimes, however, the offset where the user clicked on the docked
4338 // caption is bigger than the width of the floating frame itself, so
4339 // in that case we need to set the action offset to a sensible value
4340 wxSize frame_size
= m_action_window
->GetSize();
4341 if (frame_size
.x
<= m_action_offset
.x
)
4342 m_action_offset
.x
= 30;
4347 m_action
= actionDragToolbarPane
;
4348 m_action_window
= pane_info
->window
;
4352 else if (m_action
== actionDragFloatingPane
)
4354 if (m_action_window
)
4356 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4357 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
4358 pt
.y
- m_action_offset
.y
);
4361 else if (m_action
== actionDragToolbarPane
)
4363 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4364 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4366 pane
.state
|= wxAuiPaneInfo::actionPane
;
4368 wxPoint pt
= event
.GetPosition();
4369 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
4371 // if DoDrop() decided to float the pane, set up
4372 // the floating pane's initial position
4373 if (pane
.IsFloating())
4375 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4376 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4377 pt
.y
- m_action_offset
.y
);
4380 // this will do the actiual move operation;
4381 // in the case that the pane has been floated,
4382 // this call will create the floating pane
4383 // and do the reparenting
4386 // if the pane has been floated, change the mouse
4387 // action actionDragFloatingPane so that subsequent
4388 // EVT_MOTION() events will move the floating pane
4389 if (pane
.IsFloating())
4391 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
4392 m_action
= actionDragFloatingPane
;
4393 m_action_window
= pane
.frame
;
4398 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
4399 if (part
&& part
->type
== wxAuiDockUIPart::typePaneButton
)
4401 if (part
!= m_hover_button
)
4403 // make the old button normal
4406 UpdateButtonOnScreen(m_hover_button
, event
);
4410 // mouse is over a button, so repaint the
4411 // button in hover mode
4412 UpdateButtonOnScreen(part
, event
);
4413 m_hover_button
= part
;
4421 m_hover_button
= NULL
;
4432 void wxAuiManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
4436 m_hover_button
= NULL
;
4441 void wxAuiManager::OnChildFocus(wxChildFocusEvent
& event
)
4443 // when a child pane has it's focus set, we should change the
4444 // pane's active state to reflect this. (this is only true if
4445 // active panes are allowed by the owner)
4446 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
4448 wxAuiPaneInfo
& pane
= GetPane(event
.GetWindow());
4449 if (pane
.IsOk() && (pane
.state
& wxAuiPaneInfo::optionActive
) == 0)
4451 SetActivePane(m_panes
, event
.GetWindow());
4460 // OnPaneButton() is an event handler that is called
4461 // when a pane button has been pressed.
4462 void wxAuiManager::OnPaneButton(wxAuiManagerEvent
& evt
)
4464 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxAuiManager::OnPaneButton must be non-null"));
4466 wxAuiPaneInfo
& pane
= *(evt
.pane
);
4468 if (evt
.button
== wxAUI_BUTTON_CLOSE
)
4470 // fire pane close event
4471 wxAuiManagerEvent
e(wxEVT_AUI_PANE_CLOSE
);
4473 e
.SetPane(evt
.pane
);
4478 // close the pane, but check that it
4479 // still exists in our pane array first
4480 // (the event handler above might have removed it)
4482 wxAuiPaneInfo
& check
= GetPane(pane
.window
);
4491 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& !pane
.IsMaximized())
4493 // fire pane close event
4494 wxAuiManagerEvent
e(wxEVT_AUI_PANE_MAXIMIZE
);
4496 e
.SetPane(evt
.pane
);
4505 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& pane
.IsMaximized())
4507 // fire pane close event
4508 wxAuiManagerEvent
e(wxEVT_AUI_PANE_RESTORE
);
4510 e
.SetPane(evt
.pane
);
4519 else if (evt
.button
== wxAUI_BUTTON_PIN
)
4521 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&