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
);
260 g_object_ref(m_widget
);
262 if (parent
) parent
->AddChild(this);
264 g_signal_connect( m_widget
, "realize",
265 G_CALLBACK (gtk_pseudo_window_realized_callback
), this );
269 col
.green
= 192 * 256;
270 col
.blue
= 255 * 256;
271 gtk_widget_modify_bg( m_widget
, GTK_STATE_NORMAL
, &col
);
274 bool SetTransparent(wxByte
WXUNUSED(alpha
))
280 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
283 IMPLEMENT_DYNAMIC_CLASS(wxPseudoTransparentFrame
, wxFrame
)
290 // -- static utility functions --
292 static wxBitmap
wxPaneCreateStippleBitmap()
294 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
295 wxImage
img(2,2,data
,true);
296 return wxBitmap(img
);
299 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
301 wxBitmap stipple
= wxPaneCreateStippleBitmap();
302 wxBrush
brush(stipple
);
305 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
306 PatBlt(GetHdcOf(*impl
), rect
.GetX(), rect
.GetY(), rect
.GetWidth(), rect
.GetHeight(), PATINVERT
);
308 dc
.SetPen(*wxTRANSPARENT_PEN
);
310 dc
.SetLogicalFunction(wxXOR
);
311 dc
.DrawRectangle(rect
);
317 // CopyDocksAndPanes() - this utility function creates copies of
318 // the dock and pane info. wxAuiDockInfo's usually contain pointers
319 // to wxAuiPaneInfo classes, thus this function is necessary to reliably
320 // reconstruct that relationship in the new dock info and pane info arrays
322 static void CopyDocksAndPanes(wxAuiDockInfoArray
& dest_docks
,
323 wxAuiPaneInfoArray
& dest_panes
,
324 const wxAuiDockInfoArray
& src_docks
,
325 const wxAuiPaneInfoArray
& src_panes
)
327 dest_docks
= src_docks
;
328 dest_panes
= src_panes
;
329 int i
, j
, k
, dock_count
, pc1
, pc2
;
330 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
332 wxAuiDockInfo
& dock
= dest_docks
.Item(i
);
333 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
334 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
335 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
336 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
340 // GetMaxLayer() is an internal function which returns
341 // the highest layer inside the specified dock
342 static int GetMaxLayer(const wxAuiDockInfoArray
& docks
,
345 int i
, dock_count
, max_layer
= 0;
346 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
348 wxAuiDockInfo
& dock
= docks
.Item(i
);
349 if (dock
.dock_direction
== dock_direction
&&
350 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
351 max_layer
= dock
.dock_layer
;
357 // GetMaxRow() is an internal function which returns
358 // the highest layer inside the specified dock
359 static int GetMaxRow(const wxAuiPaneInfoArray
& panes
, int direction
, int layer
)
361 int i
, pane_count
, max_row
= 0;
362 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
364 wxAuiPaneInfo
& pane
= panes
.Item(i
);
365 if (pane
.dock_direction
== direction
&&
366 pane
.dock_layer
== layer
&&
367 pane
.dock_row
> max_row
)
368 max_row
= pane
.dock_row
;
375 // DoInsertDockLayer() is an internal function that inserts a new dock
376 // layer by incrementing all existing dock layer values by one
377 static void DoInsertDockLayer(wxAuiPaneInfoArray
& panes
,
382 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
384 wxAuiPaneInfo
& pane
= panes
.Item(i
);
385 if (!pane
.IsFloating() &&
386 pane
.dock_direction
== dock_direction
&&
387 pane
.dock_layer
>= dock_layer
)
392 // DoInsertDockLayer() is an internal function that inserts a new dock
393 // row by incrementing all existing dock row values by one
394 static void DoInsertDockRow(wxAuiPaneInfoArray
& panes
,
400 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
402 wxAuiPaneInfo
& pane
= panes
.Item(i
);
403 if (!pane
.IsFloating() &&
404 pane
.dock_direction
== dock_direction
&&
405 pane
.dock_layer
== dock_layer
&&
406 pane
.dock_row
>= dock_row
)
411 // DoInsertDockLayer() is an internal function that inserts a space for
412 // another dock pane by incrementing all existing dock row values by one
413 static void DoInsertPane(wxAuiPaneInfoArray
& panes
,
420 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
422 wxAuiPaneInfo
& pane
= panes
.Item(i
);
423 if (!pane
.IsFloating() &&
424 pane
.dock_direction
== dock_direction
&&
425 pane
.dock_layer
== dock_layer
&&
426 pane
.dock_row
== dock_row
&&
427 pane
.dock_pos
>= dock_pos
)
432 // FindDocks() is an internal function that returns a list of docks which meet
433 // the specified conditions in the parameters and returns a sorted array
434 // (sorted by layer and then row)
435 static void FindDocks(wxAuiDockInfoArray
& docks
,
439 wxAuiDockInfoPtrArray
& arr
)
441 int begin_layer
= dock_layer
;
442 int end_layer
= dock_layer
;
443 int begin_row
= dock_row
;
444 int end_row
= dock_row
;
445 int dock_count
= docks
.GetCount();
446 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
448 // discover the maximum dock layer and the max row
449 for (i
= 0; i
< dock_count
; ++i
)
451 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
452 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
455 // if no dock layer was specified, search all dock layers
456 if (dock_layer
== -1)
459 end_layer
= max_layer
;
462 // if no dock row was specified, search all dock row
471 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
472 for (row
= begin_row
; row
<= end_row
; ++row
)
473 for (i
= 0; i
< dock_count
; ++i
)
475 wxAuiDockInfo
& d
= docks
.Item(i
);
476 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
478 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
484 // FindPaneInDock() looks up a specified window pointer inside a dock.
485 // If found, the corresponding wxAuiPaneInfo pointer is returned, otherwise NULL.
486 static wxAuiPaneInfo
* FindPaneInDock(const wxAuiDockInfo
& dock
, wxWindow
* window
)
488 int i
, count
= dock
.panes
.GetCount();
489 for (i
= 0; i
< count
; ++i
)
491 wxAuiPaneInfo
* p
= dock
.panes
.Item(i
);
492 if (p
->window
== window
)
498 // RemovePaneFromDocks() removes a pane window from all docks
499 // with a possible exception specified by parameter "ex_cept"
500 static void RemovePaneFromDocks(wxAuiDockInfoArray
& docks
,
502 wxAuiDockInfo
* ex_cept
= NULL
)
505 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
507 wxAuiDockInfo
& d
= docks
.Item(i
);
510 wxAuiPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
517 // This function works fine, and may be used in the future
519 // RenumberDockRows() takes a dock and assigns sequential numbers
520 // to existing rows. Basically it takes out the gaps; so if a
521 // dock has rows with numbers 0,2,5, they will become 0,1,2
522 static void RenumberDockRows(wxAuiDockInfoPtrArray& docks)
525 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
527 wxAuiDockInfo& dock = *docks.Item(i);
531 for (j = 0, pane_count = dock.panes.GetCount(); j < pane_count; ++j)
532 dock.panes.Item(j)->dock_row = i;
538 // SetActivePane() sets the active pane, as well as cycles through
539 // every other pane and makes sure that all others' active flags
541 static void SetActivePane(wxAuiPaneInfoArray
& panes
, wxWindow
* active_pane
)
544 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
546 wxAuiPaneInfo
& pane
= panes
.Item(i
);
547 pane
.state
&= ~wxAuiPaneInfo::optionActive
;
548 if (pane
.window
== active_pane
)
549 pane
.state
|= wxAuiPaneInfo::optionActive
;
554 // this function is used to sort panes by dock position
555 static int PaneSortFunc(wxAuiPaneInfo
** p1
, wxAuiPaneInfo
** p2
)
557 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
561 // -- wxAuiManager class implementation --
564 BEGIN_EVENT_TABLE(wxAuiManager
, wxEvtHandler
)
565 EVT_AUI_PANE_BUTTON(wxAuiManager::OnPaneButton
)
566 EVT_AUI_RENDER(wxAuiManager::OnRender
)
567 EVT_PAINT(wxAuiManager::OnPaint
)
568 EVT_ERASE_BACKGROUND(wxAuiManager::OnEraseBackground
)
569 EVT_SIZE(wxAuiManager::OnSize
)
570 EVT_SET_CURSOR(wxAuiManager::OnSetCursor
)
571 EVT_LEFT_DOWN(wxAuiManager::OnLeftDown
)
572 EVT_LEFT_UP(wxAuiManager::OnLeftUp
)
573 EVT_MOTION(wxAuiManager::OnMotion
)
574 EVT_LEAVE_WINDOW(wxAuiManager::OnLeaveWindow
)
575 EVT_CHILD_FOCUS(wxAuiManager::OnChildFocus
)
576 EVT_AUI_FIND_MANAGER(wxAuiManager::OnFindManager
)
577 EVT_TIMER(101, wxAuiManager::OnHintFadeTimer
)
581 wxAuiManager::wxAuiManager(wxWindow
* managed_wnd
, unsigned int flags
)
583 m_action
= actionNone
;
584 m_last_mouse_move
= wxPoint();
585 m_hover_button
= NULL
;
586 m_art
= new wxAuiDefaultDockArt
;
590 m_has_maximized
= false;
592 m_dock_constraint_x
= 0.3;
593 m_dock_constraint_y
= 0.3;
598 SetManagedWindow(managed_wnd
);
602 wxAuiManager::~wxAuiManager()
604 // NOTE: It's possible that the windows have already been destroyed by the
605 // time this dtor is called, so this loop can result in memory access via
606 // invalid pointers, resulting in a crash. So it will be disabled while
607 // waiting for a better solution.
609 for ( size_t i
= 0; i
< m_panes
.size(); i
++ )
611 wxAuiPaneInfo
& pinfo
= m_panes
[i
];
612 if (pinfo
.window
&& !pinfo
.window
->GetParent())
620 // creates a floating frame for the windows
621 wxAuiFloatingFrame
* wxAuiManager::CreateFloatingFrame(wxWindow
* parent
,
622 const wxAuiPaneInfo
& pane_info
)
624 return new wxAuiFloatingFrame(parent
, this, pane_info
);
627 bool wxAuiManager::CanDockPanel(const wxAuiPaneInfo
& WXUNUSED(p
))
629 // if a key modifier is pressed while dragging the frame,
630 // don't dock the window
631 return !(wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
));
634 // GetPane() looks up a wxAuiPaneInfo structure based
635 // on the supplied window pointer. Upon failure, GetPane()
636 // returns an empty wxAuiPaneInfo, a condition which can be checked
637 // by calling wxAuiPaneInfo::IsOk().
639 // The pane info's structure may then be modified. Once a pane's
640 // info is modified, wxAuiManager::Update() must be called to
641 // realize the changes in the UI.
643 wxAuiPaneInfo
& wxAuiManager::GetPane(wxWindow
* window
)
646 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
648 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
649 if (p
.window
== window
)
652 return wxAuiNullPaneInfo
;
655 // this version of GetPane() looks up a pane based on a
656 // 'pane name', see above comment for more info
657 wxAuiPaneInfo
& wxAuiManager::GetPane(const wxString
& name
)
660 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
662 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
666 return wxAuiNullPaneInfo
;
669 // GetAllPanes() returns a reference to all the pane info structures
670 wxAuiPaneInfoArray
& wxAuiManager::GetAllPanes()
675 // HitTest() is an internal function which determines
676 // which UI item the specified coordinates are over
677 // (x,y) specify a position in client coordinates
678 wxAuiDockUIPart
* wxAuiManager::HitTest(int x
, int y
)
680 wxAuiDockUIPart
* result
= NULL
;
683 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
685 wxAuiDockUIPart
* item
= &m_uiparts
.Item(i
);
687 // we are not interested in typeDock, because this space
688 // isn't used to draw anything, just for measurements;
689 // besides, the entire dock area is covered with other
690 // rectangles, which we are interested in.
691 if (item
->type
== wxAuiDockUIPart::typeDock
)
694 // if we already have a hit on a more specific item, we are not
695 // interested in a pane hit. If, however, we don't already have
696 // a hit, returning a pane hit is necessary for some operations
697 if ((item
->type
== wxAuiDockUIPart::typePane
||
698 item
->type
== wxAuiDockUIPart::typePaneBorder
) && result
)
701 // if the point is inside the rectangle, we have a hit
702 if (item
->rect
.Contains(x
,y
))
710 // SetFlags() and GetFlags() allow the owner to set various
711 // options which are global to wxAuiManager
712 void wxAuiManager::SetFlags(unsigned int flags
)
714 // find out if we have to call UpdateHintWindowConfig()
715 bool update_hint_wnd
= false;
716 unsigned int hint_mask
= wxAUI_MGR_TRANSPARENT_HINT
|
717 wxAUI_MGR_VENETIAN_BLINDS_HINT
|
718 wxAUI_MGR_RECTANGLE_HINT
;
719 if ((flags
& hint_mask
) != (m_flags
& hint_mask
))
720 update_hint_wnd
= true;
728 UpdateHintWindowConfig();
732 unsigned int wxAuiManager::GetFlags() const
738 // don't use these anymore as they are deprecated
739 // use Set/GetManagedFrame() instead
740 void wxAuiManager::SetFrame(wxFrame
* frame
)
742 SetManagedWindow((wxWindow
*)frame
);
745 wxFrame
* wxAuiManager::GetFrame() const
747 return (wxFrame
*)m_frame
;
751 // this function will return the aui manager for a given
752 // window. The |window| parameter should be any child window
753 // or grand-child window (and so on) of the frame/window
754 // managed by wxAuiManager. The |window| parameter does not
755 // need to be managed by the manager itself.
756 wxAuiManager
* wxAuiManager::GetManager(wxWindow
* window
)
758 wxAuiManagerEvent
evt(wxEVT_AUI_FIND_MANAGER
);
759 evt
.SetManager(NULL
);
760 evt
.ResumePropagation(wxEVENT_PROPAGATE_MAX
);
761 if (!window
->ProcessEvent(evt
))
764 return evt
.GetManager();
768 void wxAuiManager::UpdateHintWindowConfig()
770 // find out if the the system can do transparent frames
771 bool can_do_transparent
= false;
773 wxWindow
* w
= m_frame
;
776 if (w
->IsKindOf(CLASSINFO(wxFrame
)))
778 wxFrame
* f
= static_cast<wxFrame
*>(w
);
779 can_do_transparent
= f
->CanSetTransparent();
787 // if there is an existing hint window, delete it
790 m_hint_wnd
->Destroy();
797 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) && can_do_transparent
)
799 // Make a window to use for a transparent hint
800 #if defined(__WXMSW__) || defined(__WXGTK__)
801 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
,
802 wxDefaultPosition
, wxSize(1,1),
803 wxFRAME_TOOL_WINDOW
|
804 wxFRAME_FLOAT_ON_PARENT
|
808 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
809 #elif defined(__WXMAC__)
810 // Using a miniframe with float and tool styles keeps the parent
811 // frame activated and highlighted as such...
812 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
,
813 wxDefaultPosition
, wxSize(1,1),
814 wxFRAME_FLOAT_ON_PARENT
815 | wxFRAME_TOOL_WINDOW
);
817 // Can't set the bg colour of a Frame in wxMac
818 wxPanel
* p
= new wxPanel(m_hint_wnd
);
820 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
821 // color that is really hard to see, especially transparent.
822 // Until a better system color is decided upon we'll just use
824 p
->SetBackgroundColour(*wxBLUE
);
830 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 ||
831 (m_flags
& wxAUI_MGR_VENETIAN_BLINDS_HINT
) != 0)
833 // system can't support transparent fade, or the venetian
834 // blinds effect was explicitly requested
835 m_hint_wnd
= new wxPseudoTransparentFrame(m_frame
,
840 wxFRAME_TOOL_WINDOW
|
841 wxFRAME_FLOAT_ON_PARENT
|
844 m_hint_fademax
= 128;
850 // SetManagedWindow() is usually called once when the frame
851 // manager class is being initialized. "frame" specifies
852 // the frame which should be managed by the frame mananger
853 void wxAuiManager::SetManagedWindow(wxWindow
* wnd
)
855 wxASSERT_MSG(wnd
, wxT("specified window must be non-NULL"));
858 m_frame
->PushEventHandler(this);
861 // if the owner is going to manage an MDI parent frame,
862 // we need to add the MDI client window as the default
865 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
867 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)m_frame
;
868 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
870 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
872 AddPane(client_window
,
873 wxAuiPaneInfo().Name(wxT("mdiclient")).
874 CenterPane().PaneBorder(false));
876 else if (m_frame
->IsKindOf(CLASSINFO(wxAuiMDIParentFrame
)))
878 wxAuiMDIParentFrame
* mdi_frame
= (wxAuiMDIParentFrame
*)m_frame
;
879 wxAuiMDIClientWindow
* client_window
= mdi_frame
->GetClientWindow();
880 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
882 AddPane(client_window
,
883 wxAuiPaneInfo().Name(wxT("mdiclient")).
884 CenterPane().PaneBorder(false));
889 UpdateHintWindowConfig();
893 // UnInit() must be called, usually in the destructor
894 // of the frame class. If it is not called, usually this
895 // will result in a crash upon program exit
896 void wxAuiManager::UnInit()
900 m_frame
->RemoveEventHandler(this);
904 // GetManagedWindow() returns the window pointer being managed
905 wxWindow
* wxAuiManager::GetManagedWindow() const
910 wxAuiDockArt
* wxAuiManager::GetArtProvider() const
915 void wxAuiManager::ProcessMgrEvent(wxAuiManagerEvent
& event
)
917 // first, give the owner frame a chance to override
920 if (m_frame
->ProcessEvent(event
))
927 // SetArtProvider() instructs wxAuiManager to use the
928 // specified art provider for all drawing calls. This allows
929 // plugable look-and-feel features. The pointer that is
930 // passed to this method subsequently belongs to wxAuiManager,
931 // and is deleted in the frame manager destructor
932 void wxAuiManager::SetArtProvider(wxAuiDockArt
* art_provider
)
934 // delete the last art provider, if any
937 // assign the new art provider
938 m_art
= art_provider
;
942 bool wxAuiManager::AddPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
)
944 wxASSERT_MSG(window
, wxT("NULL window ptrs are not allowed"));
946 // check if the pane has a valid window
950 // check if the window is already managed by us
951 if (GetPane(pane_info
.window
).IsOk())
954 // check if the pane name already exists, this could reveal a
955 // bug in the library user's application
956 bool already_exists
= false;
957 if (!pane_info
.name
.empty() && GetPane(pane_info
.name
).IsOk())
959 wxFAIL_MSG(wxT("A pane with that name already exists in the manager!"));
960 already_exists
= true;
963 // if the new pane is docked then we should undo maximize
964 if (pane_info
.IsDocked())
965 RestoreMaximizedPane();
967 m_panes
.Add(pane_info
);
969 wxAuiPaneInfo
& pinfo
= m_panes
.Last();
971 // set the pane window
972 pinfo
.window
= window
;
975 // if the pane's name identifier is blank, create a random string
976 if (pinfo
.name
.empty() || already_exists
)
978 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
979 wxPtrToUInt(pinfo
.window
) & 0xffffffff,
980 (unsigned int)time(NULL
),
982 (unsigned int)GetTickCount(),
984 (unsigned int)clock(),
986 (unsigned long)m_panes
.GetCount());
989 // set initial proportion (if not already set)
990 if (pinfo
.dock_proportion
== 0)
991 pinfo
.dock_proportion
= 100000;
993 if (pinfo
.HasMaximizeButton())
995 wxAuiPaneButton button
;
996 button
.button_id
= wxAUI_BUTTON_MAXIMIZE_RESTORE
;
997 pinfo
.buttons
.Add(button
);
1000 if (pinfo
.HasPinButton())
1002 wxAuiPaneButton button
;
1003 button
.button_id
= wxAUI_BUTTON_PIN
;
1004 pinfo
.buttons
.Add(button
);
1007 if (pinfo
.HasCloseButton())
1009 wxAuiPaneButton button
;
1010 button
.button_id
= wxAUI_BUTTON_CLOSE
;
1011 pinfo
.buttons
.Add(button
);
1014 if (pinfo
.HasGripper())
1016 if (pinfo
.window
->IsKindOf(CLASSINFO(wxAuiToolBar
)))
1018 // prevent duplicate gripper -- both wxAuiManager and wxAuiToolBar
1019 // have a gripper control. The toolbar's built-in gripper
1020 // meshes better with the look and feel of the control than ours,
1021 // so turn wxAuiManager's gripper off, and the toolbar's on.
1023 wxAuiToolBar
* tb
= static_cast<wxAuiToolBar
*>(pinfo
.window
);
1024 pinfo
.SetFlag(wxAuiPaneInfo::optionGripper
, false);
1025 tb
->SetGripperVisible(true);
1030 if (pinfo
.best_size
== wxDefaultSize
&&
1033 pinfo
.best_size
= pinfo
.window
->GetClientSize();
1035 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
1037 // GetClientSize() doesn't get the best size for
1038 // a toolbar under some newer versions of wxWidgets,
1039 // so use GetBestSize()
1040 pinfo
.best_size
= pinfo
.window
->GetBestSize();
1042 // for some reason, wxToolBar::GetBestSize() is returning
1043 // a size that is a pixel shy of the correct amount.
1044 // I believe this to be the correct action, until
1045 // wxToolBar::GetBestSize() is fixed. Is this assumption
1047 // commented out by JACS 2007-9-08 after having added a pixel in wxMSW's wxToolBar::DoGetBestSize()
1048 // pinfo.best_size.y++;
1051 if (pinfo
.min_size
!= wxDefaultSize
)
1053 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
1054 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
1055 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
1056 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
1065 bool wxAuiManager::AddPane(wxWindow
* window
,
1067 const wxString
& caption
)
1069 wxAuiPaneInfo pinfo
;
1070 pinfo
.Caption(caption
);
1073 case wxTOP
: pinfo
.Top(); break;
1074 case wxBOTTOM
: pinfo
.Bottom(); break;
1075 case wxLEFT
: pinfo
.Left(); break;
1076 case wxRIGHT
: pinfo
.Right(); break;
1077 case wxCENTER
: pinfo
.CenterPane(); break;
1079 return AddPane(window
, pinfo
);
1082 bool wxAuiManager::AddPane(wxWindow
* window
,
1083 const wxAuiPaneInfo
& pane_info
,
1084 const wxPoint
& drop_pos
)
1086 if (!AddPane(window
, pane_info
))
1089 wxAuiPaneInfo
& pane
= GetPane(window
);
1091 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
1096 bool wxAuiManager::InsertPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
,
1099 wxASSERT_MSG(window
, wxT("NULL window ptrs are not allowed"));
1101 // shift the panes around, depending on the insert level
1102 switch (insert_level
)
1104 case wxAUI_INSERT_PANE
:
1105 DoInsertPane(m_panes
,
1106 pane_info
.dock_direction
,
1107 pane_info
.dock_layer
,
1109 pane_info
.dock_pos
);
1111 case wxAUI_INSERT_ROW
:
1112 DoInsertDockRow(m_panes
,
1113 pane_info
.dock_direction
,
1114 pane_info
.dock_layer
,
1115 pane_info
.dock_row
);
1117 case wxAUI_INSERT_DOCK
:
1118 DoInsertDockLayer(m_panes
,
1119 pane_info
.dock_direction
,
1120 pane_info
.dock_layer
);
1124 // if the window already exists, we are basically just moving/inserting the
1125 // existing window. If it doesn't exist, we need to add it and insert it
1126 wxAuiPaneInfo
& existing_pane
= GetPane(window
);
1127 if (!existing_pane
.IsOk())
1129 return AddPane(window
, pane_info
);
1133 if (pane_info
.IsFloating())
1135 existing_pane
.Float();
1136 if (pane_info
.floating_pos
!= wxDefaultPosition
)
1137 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
1138 if (pane_info
.floating_size
!= wxDefaultSize
)
1139 existing_pane
.FloatingSize(pane_info
.floating_size
);
1143 // if the new pane is docked then we should undo maximize
1144 RestoreMaximizedPane();
1146 existing_pane
.Direction(pane_info
.dock_direction
);
1147 existing_pane
.Layer(pane_info
.dock_layer
);
1148 existing_pane
.Row(pane_info
.dock_row
);
1149 existing_pane
.Position(pane_info
.dock_pos
);
1157 // DetachPane() removes a pane from the frame manager. This
1158 // method will not destroy the window that is removed.
1159 bool wxAuiManager::DetachPane(wxWindow
* window
)
1161 wxASSERT_MSG(window
, wxT("NULL window ptrs are not allowed"));
1164 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
1166 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1167 if (p
.window
== window
)
1171 // we have a floating frame which is being detached. We need to
1172 // reparent it to m_frame and destroy the floating frame
1175 p
.window
->SetSize(1,1);
1177 if (p
.frame
->IsShown())
1178 p
.frame
->Show(false);
1180 // reparent to m_frame and destroy the pane
1181 if (m_action_window
== p
.frame
)
1183 m_action_window
= NULL
;
1186 p
.window
->Reparent(m_frame
);
1187 p
.frame
->SetSizer(NULL
);
1192 // make sure there are no references to this pane in our uiparts,
1193 // just in case the caller doesn't call Update() immediately after
1194 // the DetachPane() call. This prevets obscure crashes which would
1195 // happen at window repaint if the caller forgets to call Update()
1197 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
1199 wxAuiDockUIPart
& part
= m_uiparts
.Item(pi
);
1200 if (part
.pane
== &p
)
1202 m_uiparts
.RemoveAt(pi
);
1209 m_panes
.RemoveAt(i
);
1216 // ClosePane() destroys or hides the pane depending on its flags
1217 void wxAuiManager::ClosePane(wxAuiPaneInfo
& pane_info
)
1219 // if we were maximized, restore
1220 if (pane_info
.IsMaximized())
1222 RestorePane(pane_info
);
1225 // first, hide the window
1226 if (pane_info
.window
&& pane_info
.window
->IsShown())
1228 pane_info
.window
->Show(false);
1231 // make sure that we are the parent of this window
1232 if (pane_info
.window
&& pane_info
.window
->GetParent() != m_frame
)
1234 pane_info
.window
->Reparent(m_frame
);
1237 // if we have a frame, destroy it
1238 if (pane_info
.frame
)
1240 pane_info
.frame
->Destroy();
1241 pane_info
.frame
= NULL
;
1244 // now we need to either destroy or hide the pane
1245 if (pane_info
.IsDestroyOnClose())
1247 wxWindow
* window
= pane_info
.window
;
1260 void wxAuiManager::MaximizePane(wxAuiPaneInfo
& pane_info
)
1264 // un-maximize and hide all other panes
1265 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1267 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1272 // save hidden state
1273 p
.SetFlag(wxAuiPaneInfo::savedHiddenState
,
1274 p
.HasFlag(wxAuiPaneInfo::optionHidden
));
1276 // hide the pane, because only the newly
1277 // maximized pane should show
1282 // mark ourselves maximized
1283 pane_info
.Maximize();
1285 m_has_maximized
= true;
1287 // last, show the window
1288 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1290 pane_info
.window
->Show(true);
1294 void wxAuiManager::RestorePane(wxAuiPaneInfo
& pane_info
)
1298 // restore all the panes
1299 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1301 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1304 p
.SetFlag(wxAuiPaneInfo::optionHidden
,
1305 p
.HasFlag(wxAuiPaneInfo::savedHiddenState
));
1309 // mark ourselves non-maximized
1310 pane_info
.Restore();
1311 m_has_maximized
= false;
1313 // last, show the window
1314 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1316 pane_info
.window
->Show(true);
1320 void wxAuiManager::RestoreMaximizedPane()
1324 // restore all the panes
1325 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1327 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1328 if (p
.IsMaximized())
1336 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
1337 // in the input string. This is an internal functions which is
1338 // used for saving perspectives
1339 static wxString
EscapeDelimiters(const wxString
& s
)
1342 result
.Alloc(s
.length());
1343 const wxChar
* ch
= s
.c_str();
1346 if (*ch
== wxT(';') || *ch
== wxT('|'))
1347 result
+= wxT('\\');
1354 wxString
wxAuiManager::SavePaneInfo(wxAuiPaneInfo
& pane
)
1356 wxString result
= wxT("name=");
1357 result
+= EscapeDelimiters(pane
.name
);
1360 result
+= wxT("caption=");
1361 result
+= EscapeDelimiters(pane
.caption
);
1364 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
1365 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
1366 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
1367 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
1368 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
1369 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
1370 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
1371 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
1372 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
1373 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
1374 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
1375 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
1376 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
1377 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
1378 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
1379 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
1384 // Load a "pane" with the pane infor settings in pane_part
1385 void wxAuiManager::LoadPaneInfo(wxString pane_part
, wxAuiPaneInfo
&pane
)
1387 // replace escaped characters so we can
1388 // split up the string easily
1389 pane_part
.Replace(wxT("\\|"), wxT("\a"));
1390 pane_part
.Replace(wxT("\\;"), wxT("\b"));
1394 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
1395 pane_part
= pane_part
.AfterFirst(wxT(';'));
1396 wxString val_name
= val_part
.BeforeFirst(wxT('='));
1397 wxString value
= val_part
.AfterFirst(wxT('='));
1398 val_name
.MakeLower();
1399 val_name
.Trim(true);
1400 val_name
.Trim(false);
1404 if (val_name
.empty())
1407 if (val_name
== wxT("name"))
1409 else if (val_name
== wxT("caption"))
1410 pane
.caption
= value
;
1411 else if (val_name
== wxT("state"))
1412 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1413 else if (val_name
== wxT("dir"))
1414 pane
.dock_direction
= wxAtoi(value
.c_str());
1415 else if (val_name
== wxT("layer"))
1416 pane
.dock_layer
= wxAtoi(value
.c_str());
1417 else if (val_name
== wxT("row"))
1418 pane
.dock_row
= wxAtoi(value
.c_str());
1419 else if (val_name
== wxT("pos"))
1420 pane
.dock_pos
= wxAtoi(value
.c_str());
1421 else if (val_name
== wxT("prop"))
1422 pane
.dock_proportion
= wxAtoi(value
.c_str());
1423 else if (val_name
== wxT("bestw"))
1424 pane
.best_size
.x
= wxAtoi(value
.c_str());
1425 else if (val_name
== wxT("besth"))
1426 pane
.best_size
.y
= wxAtoi(value
.c_str());
1427 else if (val_name
== wxT("minw"))
1428 pane
.min_size
.x
= wxAtoi(value
.c_str());
1429 else if (val_name
== wxT("minh"))
1430 pane
.min_size
.y
= wxAtoi(value
.c_str());
1431 else if (val_name
== wxT("maxw"))
1432 pane
.max_size
.x
= wxAtoi(value
.c_str());
1433 else if (val_name
== wxT("maxh"))
1434 pane
.max_size
.y
= wxAtoi(value
.c_str());
1435 else if (val_name
== wxT("floatx"))
1436 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1437 else if (val_name
== wxT("floaty"))
1438 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1439 else if (val_name
== wxT("floatw"))
1440 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1441 else if (val_name
== wxT("floath"))
1442 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1444 wxFAIL_MSG(wxT("Bad Perspective String"));
1448 // replace escaped characters so we can
1449 // split up the string easily
1450 pane
.name
.Replace(wxT("\a"), wxT("|"));
1451 pane
.name
.Replace(wxT("\b"), wxT(";"));
1452 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1453 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1454 pane_part
.Replace(wxT("\a"), wxT("|"));
1455 pane_part
.Replace(wxT("\b"), wxT(";"));
1461 // SavePerspective() saves all pane information as a single string.
1462 // This string may later be fed into LoadPerspective() to restore
1463 // all pane settings. This save and load mechanism allows an
1464 // exact pane configuration to be saved and restored at a later time
1466 wxString
wxAuiManager::SavePerspective()
1470 result
= wxT("layout2|");
1472 int pane_i
, pane_count
= m_panes
.GetCount();
1473 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1475 wxAuiPaneInfo
& pane
= m_panes
.Item(pane_i
);
1476 result
+= SavePaneInfo(pane
)+wxT("|");
1479 int dock_i
, dock_count
= m_docks
.GetCount();
1480 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1482 wxAuiDockInfo
& dock
= m_docks
.Item(dock_i
);
1484 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1485 dock
.dock_direction
, dock
.dock_layer
,
1486 dock
.dock_row
, dock
.size
);
1492 // LoadPerspective() loads a layout which was saved with SavePerspective()
1493 // If the "update" flag parameter is true, the GUI will immediately be updated
1495 bool wxAuiManager::LoadPerspective(const wxString
& layout
, bool update
)
1497 wxString input
= layout
;
1500 // check layout string version
1501 // 'layout1' = wxAUI 0.9.0 - wxAUI 0.9.2
1502 // 'layout2' = wxAUI 0.9.2 (wxWidgets 2.8)
1503 part
= input
.BeforeFirst(wxT('|'));
1504 input
= input
.AfterFirst(wxT('|'));
1507 if (part
!= wxT("layout2"))
1510 // mark all panes currently managed as docked and hidden
1511 int pane_i
, pane_count
= m_panes
.GetCount();
1512 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1513 m_panes
.Item(pane_i
).Dock().Hide();
1515 // clear out the dock array; this will be reconstructed
1518 // replace escaped characters so we can
1519 // split up the string easily
1520 input
.Replace(wxT("\\|"), wxT("\a"));
1521 input
.Replace(wxT("\\;"), wxT("\b"));
1527 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1528 input
= input
.AfterFirst(wxT('|'));
1529 pane_part
.Trim(true);
1531 // if the string is empty, we're done parsing
1532 if (pane_part
.empty())
1535 if (pane_part
.Left(9) == wxT("dock_size"))
1537 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1538 wxString value
= pane_part
.AfterFirst(wxT('='));
1540 long dir
, layer
, row
, size
;
1541 wxString piece
= val_name
.AfterFirst(wxT('('));
1542 piece
= piece
.BeforeLast(wxT(')'));
1543 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1544 piece
= piece
.AfterFirst(wxT(','));
1545 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1546 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1547 value
.ToLong(&size
);
1550 dock
.dock_direction
= dir
;
1551 dock
.dock_layer
= layer
;
1552 dock
.dock_row
= row
;
1558 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1559 // name so it can be called by external callers
1560 pane_part
.Replace(wxT("\a"), wxT("|"));
1561 pane_part
.Replace(wxT("\b"), wxT(";"));
1563 LoadPaneInfo(pane_part
, pane
);
1565 wxAuiPaneInfo
& p
= GetPane(pane
.name
);
1568 // the pane window couldn't be found
1569 // in the existing layout -- skip it
1582 void wxAuiManager::GetPanePositionsAndSizes(wxAuiDockInfo
& dock
,
1583 wxArrayInt
& positions
,
1586 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1587 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1588 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1593 int offset
, action_pane
= -1;
1594 int pane_i
, pane_count
= dock
.panes
.GetCount();
1596 // find the pane marked as our action pane
1597 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1599 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1601 if (pane
.state
& wxAuiPaneInfo::actionPane
)
1603 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1604 action_pane
= pane_i
;
1608 // set up each panes default position, and
1609 // determine the size (width or height, depending
1610 // on the dock's orientation) of each pane
1611 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1613 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1614 positions
.Add(pane
.dock_pos
);
1617 if (pane
.HasBorder())
1618 size
+= (pane_border_size
*2);
1620 if (dock
.IsHorizontal())
1622 if (pane
.HasGripper() && !pane
.HasGripperTop())
1623 size
+= gripper_size
;
1624 size
+= pane
.best_size
.x
;
1628 if (pane
.HasGripper() && pane
.HasGripperTop())
1629 size
+= gripper_size
;
1631 if (pane
.HasCaption())
1632 size
+= caption_size
;
1633 size
+= pane
.best_size
.y
;
1639 // if there is no action pane, just return the default
1640 // positions (as specified in pane.pane_pos)
1641 if (action_pane
== -1)
1645 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1647 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1652 positions
[pane_i
] -= -amount
;
1654 offset
+= sizes
[pane_i
];
1657 // if the dock mode is fixed, make sure none of the panes
1658 // overlap; we will bump panes that overlap
1660 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1662 int amount
= positions
[pane_i
] - offset
;
1666 positions
[pane_i
] += -amount
;
1668 offset
+= sizes
[pane_i
];
1673 void wxAuiManager::LayoutAddPane(wxSizer
* cont
,
1674 wxAuiDockInfo
& dock
,
1675 wxAuiPaneInfo
& pane
,
1676 wxAuiDockUIPartArray
& uiparts
,
1679 wxAuiDockUIPart part
;
1680 wxSizerItem
* sizer_item
;
1682 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1683 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1684 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1685 int pane_button_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BUTTON_SIZE
);
1687 // find out the orientation of the item (orientation for panes
1688 // is the same as the dock's orientation)
1690 if (dock
.IsHorizontal())
1691 orientation
= wxHORIZONTAL
;
1693 orientation
= wxVERTICAL
;
1695 // this variable will store the proportion
1696 // value that the pane will receive
1697 int pane_proportion
= pane
.dock_proportion
;
1699 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1700 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1702 if (pane
.HasGripper())
1704 if (pane
.HasGripperTop())
1705 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1707 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1709 part
.type
= wxAuiDockUIPart::typeGripper
;
1713 part
.orientation
= orientation
;
1714 part
.cont_sizer
= horz_pane_sizer
;
1715 part
.sizer_item
= sizer_item
;
1719 if (pane
.HasCaption())
1721 // create the caption sizer
1722 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1724 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1726 part
.type
= wxAuiDockUIPart::typeCaption
;
1730 part
.orientation
= orientation
;
1731 part
.cont_sizer
= vert_pane_sizer
;
1732 part
.sizer_item
= sizer_item
;
1733 int caption_part_idx
= uiparts
.GetCount();
1736 // add pane buttons to the caption
1737 int i
, button_count
;
1738 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1739 i
< button_count
; ++i
)
1741 wxAuiPaneButton
& button
= pane
.buttons
.Item(i
);
1743 sizer_item
= caption_sizer
->Add(pane_button_size
,
1747 part
.type
= wxAuiDockUIPart::typePaneButton
;
1750 part
.button
= &button
;
1751 part
.orientation
= orientation
;
1752 part
.cont_sizer
= caption_sizer
;
1753 part
.sizer_item
= sizer_item
;
1757 // if we have buttons, add a little space to the right
1758 // of them to ease visual crowding
1759 if (button_count
>= 1)
1761 caption_sizer
->Add(3,1);
1764 // add the caption sizer
1765 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1767 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1770 // add the pane window itself
1773 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1777 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1778 // Don't do this because it breaks the pane size in floating windows
1779 // BIW: Right now commenting this out is causing problems with
1780 // an mdi client window as the center pane.
1781 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1784 part
.type
= wxAuiDockUIPart::typePane
;
1788 part
.orientation
= orientation
;
1789 part
.cont_sizer
= vert_pane_sizer
;
1790 part
.sizer_item
= sizer_item
;
1794 // determine if the pane should have a minimum size; if the pane is
1795 // non-resizable (fixed) then we must set a minimum size. Alternatively,
1796 // if the pane.min_size is set, we must use that value as well
1798 wxSize min_size
= pane
.min_size
;
1801 if (min_size
== wxDefaultSize
)
1803 min_size
= pane
.best_size
;
1804 pane_proportion
= 0;
1808 if (min_size
!= wxDefaultSize
)
1810 vert_pane_sizer
->SetItemMinSize(
1811 vert_pane_sizer
->GetChildren().GetCount()-1,
1812 min_size
.x
, min_size
.y
);
1816 // add the verticle sizer (caption, pane window) to the
1817 // horizontal sizer (gripper, verticle sizer)
1818 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1820 // finally, add the pane sizer to the dock sizer
1822 if (pane
.HasBorder())
1824 // allowing space for the pane's border
1825 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1826 wxEXPAND
| wxALL
, pane_border_size
);
1828 part
.type
= wxAuiDockUIPart::typePaneBorder
;
1832 part
.orientation
= orientation
;
1833 part
.cont_sizer
= cont
;
1834 part
.sizer_item
= sizer_item
;
1839 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1843 void wxAuiManager::LayoutAddDock(wxSizer
* cont
,
1844 wxAuiDockInfo
& dock
,
1845 wxAuiDockUIPartArray
& uiparts
,
1848 wxSizerItem
* sizer_item
;
1849 wxAuiDockUIPart part
;
1851 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
1852 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1854 // resizable bottom and right docks have a sash before them
1855 if (!m_has_maximized
&& !dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1856 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1858 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1860 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1861 part
.orientation
= orientation
;
1865 part
.cont_sizer
= cont
;
1866 part
.sizer_item
= sizer_item
;
1870 // create the sizer for the dock
1871 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1873 // add each pane to the dock
1874 bool has_maximized_pane
= false;
1875 int pane_i
, pane_count
= dock
.panes
.GetCount();
1879 wxArrayInt pane_positions
, pane_sizes
;
1881 // figure out the real pane positions we will
1882 // use, without modifying the each pane's pane_pos member
1883 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1886 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1888 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1889 int pane_pos
= pane_positions
.Item(pane_i
);
1891 if (pane
.IsMaximized())
1892 has_maximized_pane
= true;
1895 int amount
= pane_pos
- offset
;
1898 if (dock
.IsVertical())
1899 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1901 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1903 part
.type
= wxAuiDockUIPart::typeBackground
;
1907 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1908 part
.cont_sizer
= dock_sizer
;
1909 part
.sizer_item
= sizer_item
;
1915 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1917 offset
+= pane_sizes
.Item(pane_i
);
1920 // at the end add a very small stretchable background area
1921 sizer_item
= dock_sizer
->Add(0,0, 1, wxEXPAND
);
1923 part
.type
= wxAuiDockUIPart::typeBackground
;
1927 part
.orientation
= orientation
;
1928 part
.cont_sizer
= dock_sizer
;
1929 part
.sizer_item
= sizer_item
;
1934 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1936 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1938 if (pane
.IsMaximized())
1939 has_maximized_pane
= true;
1941 // if this is not the first pane being added,
1942 // we need to add a pane sizer
1943 if (!m_has_maximized
&& pane_i
> 0)
1945 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1947 part
.type
= wxAuiDockUIPart::typePaneSizer
;
1949 part
.pane
= dock
.panes
.Item(pane_i
-1);
1951 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1952 part
.cont_sizer
= dock_sizer
;
1953 part
.sizer_item
= sizer_item
;
1957 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1961 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
|| has_maximized_pane
)
1962 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1964 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1966 part
.type
= wxAuiDockUIPart::typeDock
;
1970 part
.orientation
= orientation
;
1971 part
.cont_sizer
= cont
;
1972 part
.sizer_item
= sizer_item
;
1975 if (dock
.IsHorizontal())
1976 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1978 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1980 // top and left docks have a sash after them
1981 if (!m_has_maximized
&&
1983 (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1984 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1986 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1988 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1992 part
.orientation
= orientation
;
1993 part
.cont_sizer
= cont
;
1994 part
.sizer_item
= sizer_item
;
1999 wxSizer
* wxAuiManager::LayoutAll(wxAuiPaneInfoArray
& panes
,
2000 wxAuiDockInfoArray
& docks
,
2001 wxAuiDockUIPartArray
& uiparts
,
2004 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
2006 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
2007 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
2008 wxSize cli_size
= m_frame
->GetClientSize();
2009 int i
, dock_count
, pane_count
;
2012 // empty all docks out
2013 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2015 wxAuiDockInfo
& dock
= docks
.Item(i
);
2017 // empty out all panes, as they will be readded below
2022 // always reset fixed docks' sizes, because
2023 // the contained windows may have been resized
2029 // iterate through all known panes, filing each
2030 // of them into the appropriate dock. If the
2031 // pane does not exist in the dock, add it
2032 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2034 wxAuiPaneInfo
& p
= panes
.Item(i
);
2036 // find any docks with the same dock direction, dock layer, and
2037 // dock row as the pane we are working on
2038 wxAuiDockInfo
* dock
;
2039 wxAuiDockInfoPtrArray arr
;
2040 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
2042 if (arr
.GetCount() > 0)
2044 // found the right dock
2049 // dock was not found, so we need to create a new one
2051 d
.dock_direction
= p
.dock_direction
;
2052 d
.dock_layer
= p
.dock_layer
;
2053 d
.dock_row
= p
.dock_row
;
2055 dock
= &docks
.Last();
2059 if (p
.IsDocked() && p
.IsShown())
2061 // remove the pane from any existing docks except this one
2062 RemovePaneFromDocks(docks
, p
, dock
);
2064 // pane needs to be added to the dock,
2065 // if it doesn't already exist
2066 if (!FindPaneInDock(*dock
, p
.window
))
2067 dock
->panes
.Add(&p
);
2071 // remove the pane from any existing docks
2072 RemovePaneFromDocks(docks
, p
);
2077 // remove any empty docks
2078 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
2080 if (docks
.Item(i
).panes
.GetCount() == 0)
2084 // configure the docks further
2085 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2087 wxAuiDockInfo
& dock
= docks
.Item(i
);
2088 int j
, dock_pane_count
= dock
.panes
.GetCount();
2090 // sort the dock pane array by the pane's
2091 // dock position (dock_pos), in ascending order
2092 dock
.panes
.Sort(PaneSortFunc
);
2094 // for newly created docks, set up their initial size
2099 for (j
= 0; j
< dock_pane_count
; ++j
)
2101 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2102 wxSize pane_size
= pane
.best_size
;
2103 if (pane_size
== wxDefaultSize
)
2104 pane_size
= pane
.min_size
;
2105 if (pane_size
== wxDefaultSize
)
2106 pane_size
= pane
.window
->GetSize();
2108 if (dock
.IsHorizontal())
2109 size
= wxMax(pane_size
.y
, size
);
2111 size
= wxMax(pane_size
.x
, size
);
2114 // add space for the border (two times), but only
2115 // if at least one pane inside the dock has a pane border
2116 for (j
= 0; j
< dock_pane_count
; ++j
)
2118 if (dock
.panes
.Item(j
)->HasBorder())
2120 size
+= (pane_border_size
*2);
2125 // if pane is on the top or bottom, add the caption height,
2126 // but only if at least one pane inside the dock has a caption
2127 if (dock
.IsHorizontal())
2129 for (j
= 0; j
< dock_pane_count
; ++j
)
2131 if (dock
.panes
.Item(j
)->HasCaption())
2133 size
+= caption_size
;
2140 // new dock's size may not be more than the dock constraint
2141 // parameter specifies. See SetDockSizeConstraint()
2143 int max_dock_x_size
= (int)(m_dock_constraint_x
* ((double)cli_size
.x
));
2144 int max_dock_y_size
= (int)(m_dock_constraint_y
* ((double)cli_size
.y
));
2146 if (dock
.IsHorizontal())
2147 size
= wxMin(size
, max_dock_y_size
);
2149 size
= wxMin(size
, max_dock_x_size
);
2151 // absolute minimum size for a dock is 10 pixels
2159 // determine the dock's minimum size
2160 bool plus_border
= false;
2161 bool plus_caption
= false;
2162 int dock_min_size
= 0;
2163 for (j
= 0; j
< dock_pane_count
; ++j
)
2165 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2166 if (pane
.min_size
!= wxDefaultSize
)
2168 if (pane
.HasBorder())
2170 if (pane
.HasCaption())
2171 plus_caption
= true;
2172 if (dock
.IsHorizontal())
2174 if (pane
.min_size
.y
> dock_min_size
)
2175 dock_min_size
= pane
.min_size
.y
;
2179 if (pane
.min_size
.x
> dock_min_size
)
2180 dock_min_size
= pane
.min_size
.x
;
2186 dock_min_size
+= (pane_border_size
*2);
2187 if (plus_caption
&& dock
.IsHorizontal())
2188 dock_min_size
+= (caption_size
);
2190 dock
.min_size
= dock_min_size
;
2193 // if the pane's current size is less than it's
2194 // minimum, increase the dock's size to it's minimum
2195 if (dock
.size
< dock
.min_size
)
2196 dock
.size
= dock
.min_size
;
2199 // determine the dock's mode (fixed or proportional);
2200 // determine whether the dock has only toolbars
2201 bool action_pane_marked
= false;
2203 dock
.toolbar
= true;
2204 for (j
= 0; j
< dock_pane_count
; ++j
)
2206 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2207 if (!pane
.IsFixed())
2209 if (!pane
.IsToolbar())
2210 dock
.toolbar
= false;
2211 if (pane
.HasFlag(wxAuiPaneInfo::optionDockFixed
))
2213 if (pane
.state
& wxAuiPaneInfo::actionPane
)
2214 action_pane_marked
= true;
2218 // if the dock mode is proportional and not fixed-pixel,
2219 // reassign the dock_pos to the sequential 0, 1, 2, 3;
2220 // e.g. remove gaps like 1, 2, 30, 500
2223 for (j
= 0; j
< dock_pane_count
; ++j
)
2225 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2230 // if the dock mode is fixed, and none of the panes
2231 // are being moved right now, make sure the panes
2232 // do not overlap each other. If they do, we will
2233 // adjust the positions of the panes
2234 if (dock
.fixed
&& !action_pane_marked
)
2236 wxArrayInt pane_positions
, pane_sizes
;
2237 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
2240 for (j
= 0; j
< dock_pane_count
; ++j
)
2242 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(j
));
2243 pane
.dock_pos
= pane_positions
[j
];
2245 int amount
= pane
.dock_pos
- offset
;
2249 pane
.dock_pos
+= -amount
;
2251 offset
+= pane_sizes
[j
];
2256 // discover the maximum dock layer
2258 for (i
= 0; i
< dock_count
; ++i
)
2259 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
2262 // clear out uiparts
2265 // create a bunch of box sizers,
2266 // from the innermost level outwards.
2267 wxSizer
* cont
= NULL
;
2268 wxSizer
* middle
= NULL
;
2272 for (layer
= 0; layer
<= max_layer
; ++layer
)
2274 wxAuiDockInfoPtrArray arr
;
2276 // find any docks in this layer
2277 FindDocks(docks
, -1, layer
, -1, arr
);
2279 // if there aren't any, skip to the next layer
2283 wxSizer
* old_cont
= cont
;
2285 // create a container which will hold this layer's
2286 // docks (top, bottom, left, right)
2287 cont
= new wxBoxSizer(wxVERTICAL
);
2290 // find any top docks in this layer
2291 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
2294 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2295 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2299 // fill out the middle layer (which consists
2300 // of left docks, content area and right docks)
2302 middle
= new wxBoxSizer(wxHORIZONTAL
);
2304 // find any left docks in this layer
2305 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
2308 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2309 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2312 // add content dock (or previous layer's sizer
2316 // find any center docks
2317 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
2320 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
2321 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2323 else if (!m_has_maximized
)
2325 // there are no center docks, add a background area
2326 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
2327 wxAuiDockUIPart part
;
2328 part
.type
= wxAuiDockUIPart::typeBackground
;
2332 part
.cont_sizer
= middle
;
2333 part
.sizer_item
= sizer_item
;
2339 middle
->Add(old_cont
, 1, wxEXPAND
);
2342 // find any right docks in this layer
2343 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
2346 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2347 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2350 if (middle
->GetChildren().GetCount() > 0)
2351 cont
->Add(middle
, 1, wxEXPAND
);
2357 // find any bottom docks in this layer
2358 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
2361 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2362 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2369 // no sizer available, because there are no docks,
2370 // therefore we will create a simple background area
2371 cont
= new wxBoxSizer(wxVERTICAL
);
2372 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
2373 wxAuiDockUIPart part
;
2374 part
.type
= wxAuiDockUIPart::typeBackground
;
2378 part
.cont_sizer
= middle
;
2379 part
.sizer_item
= sizer_item
;
2383 container
->Add(cont
, 1, wxEXPAND
);
2388 // SetDockSizeConstraint() allows the dock constraints to be set. For example,
2389 // specifying values of 0.5, 0.5 will mean that upon dock creation, a dock may
2390 // not be larger than half of the window's size
2392 void wxAuiManager::SetDockSizeConstraint(double width_pct
, double height_pct
)
2394 m_dock_constraint_x
= wxMax(0.0, wxMin(1.0, width_pct
));
2395 m_dock_constraint_y
= wxMax(0.0, wxMin(1.0, height_pct
));
2398 void wxAuiManager::GetDockSizeConstraint(double* width_pct
, double* height_pct
) const
2401 *width_pct
= m_dock_constraint_x
;
2404 *height_pct
= m_dock_constraint_y
;
2409 // Update() updates the layout. Whenever changes are made to
2410 // one or more panes, this function should be called. It is the
2411 // external entry point for running the layout engine.
2413 void wxAuiManager::Update()
2415 m_hover_button
= NULL
;
2416 m_action_part
= NULL
;
2419 int i
, pane_count
= m_panes
.GetCount();
2422 // destroy floating panes which have been
2423 // redocked or are becoming non-floating
2424 for (i
= 0; i
< pane_count
; ++i
)
2426 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2428 if (!p
.IsFloating() && p
.frame
)
2430 // because the pane is no longer in a floating, we need to
2431 // reparent it to m_frame and destroy the floating frame
2434 p
.window
->SetSize(1,1);
2437 // the following block is a workaround for bug #1531361
2438 // (see wxWidgets sourceforge page). On wxGTK (only), when
2439 // a frame is shown/hidden, a move event unfortunately
2440 // also gets fired. Because we may be dragging around
2441 // a pane, we need to cancel that action here to prevent
2442 // a spurious crash.
2443 if (m_action_window
== p
.frame
)
2445 if (wxWindow::GetCapture() == m_frame
)
2446 m_frame
->ReleaseMouse();
2447 m_action
= actionNone
;
2448 m_action_window
= NULL
;
2452 if (p
.frame
->IsShown())
2453 p
.frame
->Show(false);
2455 // reparent to m_frame and destroy the pane
2456 if (m_action_window
== p
.frame
)
2458 m_action_window
= NULL
;
2461 p
.window
->Reparent(m_frame
);
2462 p
.frame
->SetSizer(NULL
);
2469 // delete old sizer first
2470 m_frame
->SetSizer(NULL
);
2472 // create a layout for all of the panes
2473 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
2475 // hide or show panes as necessary,
2476 // and float panes as necessary
2477 for (i
= 0; i
< pane_count
; ++i
)
2479 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2483 if (p
.frame
== NULL
)
2485 // we need to create a frame for this
2486 // pane, which has recently been floated
2487 wxAuiFloatingFrame
* frame
= CreateFloatingFrame(m_frame
, p
);
2489 // on MSW and Mac, if the owner desires transparent dragging, and
2490 // the dragging is happening right now, then the floating
2491 // window should have this style by default
2492 if (m_action
== actionDragFloatingPane
&&
2493 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2494 frame
->SetTransparent(150);
2496 frame
->SetPaneWindow(p
);
2499 if (p
.IsShown() && !frame
->IsShown())
2504 // frame already exists, make sure it's position
2505 // and size reflect the information in wxAuiPaneInfo
2506 if ((p
.frame
->GetPosition() != p
.floating_pos
) || (p
.frame
->GetSize() != p
.floating_size
))
2508 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2509 p
.floating_size
.x
, p
.floating_size
.y
,
2510 wxSIZE_USE_EXISTING
);
2512 p.frame->SetSize(p.floating_pos.x, p.floating_pos.y,
2513 wxDefaultCoord, wxDefaultCoord,
2514 wxSIZE_USE_EXISTING);
2515 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2519 if (p
.frame
->IsShown() != p
.IsShown())
2520 p
.frame
->Show(p
.IsShown());
2525 if (p
.window
->IsShown() != p
.IsShown())
2526 p
.window
->Show(p
.IsShown());
2529 // if "active panes" are no longer allowed, clear
2530 // any optionActive values from the pane states
2531 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2533 p
.state
&= ~wxAuiPaneInfo::optionActive
;
2538 // keep track of the old window rectangles so we can
2539 // refresh those windows whose rect has changed
2540 wxAuiRectArray old_pane_rects
;
2541 for (i
= 0; i
< pane_count
; ++i
)
2544 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2546 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2549 old_pane_rects
.Add(r
);
2555 // apply the new sizer
2556 m_frame
->SetSizer(sizer
);
2557 m_frame
->SetAutoLayout(false);
2562 // now that the frame layout is done, we need to check
2563 // the new pane rectangles against the old rectangles that
2564 // we saved a few lines above here. If the rectangles have
2565 // changed, the corresponding panes must also be updated
2566 for (i
= 0; i
< pane_count
; ++i
)
2568 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2569 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2571 if (p
.rect
!= old_pane_rects
[i
])
2573 p
.window
->Refresh();
2582 // set frame's minimum size
2585 // N.B. More work needs to be done on frame minimum sizes;
2586 // this is some intresting code that imposes the minimum size,
2587 // but we may want to include a more flexible mechanism or
2588 // options for multiple minimum-size modes, e.g. strict or lax
2589 wxSize min_size = sizer->GetMinSize();
2590 wxSize frame_size = m_frame->GetSize();
2591 wxSize client_size = m_frame->GetClientSize();
2593 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2594 min_size.y+frame_size.y-client_size.y );
2596 m_frame->SetMinSize(minframe_size);
2598 if (frame_size.x < minframe_size.x ||
2599 frame_size.y < minframe_size.y)
2600 sizer->Fit(m_frame);
2605 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2606 // on the frame's main sizer, then measures all the various UI items
2607 // and updates their internal rectangles. This should always be called
2608 // instead of calling m_frame->Layout() directly
2610 void wxAuiManager::DoFrameLayout()
2615 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2617 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2619 // get the rectangle of the UI part
2620 // originally, this code looked like this:
2621 // part.rect = wxRect(part.sizer_item->GetPosition(),
2622 // part.sizer_item->GetSize());
2623 // this worked quite well, with one exception: the mdi
2624 // client window had a "deferred" size variable
2625 // that returned the wrong size. It looks like
2626 // a bug in wx, because the former size of the window
2627 // was being returned. So, we will retrieve the part's
2628 // rectangle via other means
2631 part
.rect
= part
.sizer_item
->GetRect();
2632 int flag
= part
.sizer_item
->GetFlag();
2633 int border
= part
.sizer_item
->GetBorder();
2636 part
.rect
.y
-= border
;
2637 part
.rect
.height
+= border
;
2641 part
.rect
.x
-= border
;
2642 part
.rect
.width
+= border
;
2644 if (flag
& wxBOTTOM
)
2645 part
.rect
.height
+= border
;
2647 part
.rect
.width
+= border
;
2650 if (part
.type
== wxAuiDockUIPart::typeDock
)
2651 part
.dock
->rect
= part
.rect
;
2652 if (part
.type
== wxAuiDockUIPart::typePane
)
2653 part
.pane
->rect
= part
.rect
;
2657 // GetPanePart() looks up the pane the pane border UI part (or the regular
2658 // pane part if there is no border). This allows the caller to get the exact
2659 // rectangle of the pane in question, including decorations like
2660 // caption and border (if any).
2662 wxAuiDockUIPart
* wxAuiManager::GetPanePart(wxWindow
* wnd
)
2665 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2667 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2668 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
2669 part
.pane
&& part
.pane
->window
== wnd
)
2672 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2674 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2675 if (part
.type
== wxAuiDockUIPart::typePane
&&
2676 part
.pane
&& part
.pane
->window
== wnd
)
2684 // GetDockPixelOffset() is an internal function which returns
2685 // a dock's offset in pixels from the left side of the window
2686 // (for horizontal docks) or from the top of the window (for
2687 // vertical docks). This value is necessary for calculating
2688 // fixel-pane/toolbar offsets when they are dragged.
2690 int wxAuiManager::GetDockPixelOffset(wxAuiPaneInfo
& test
)
2692 // the only way to accurately calculate the dock's
2693 // offset is to actually run a theoretical layout
2695 int i
, part_count
, dock_count
;
2696 wxAuiDockInfoArray docks
;
2697 wxAuiPaneInfoArray panes
;
2698 wxAuiDockUIPartArray uiparts
;
2699 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2702 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2703 wxSize client_size
= m_frame
->GetClientSize();
2704 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2707 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2709 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
2710 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2711 part
.sizer_item
->GetSize());
2712 if (part
.type
== wxAuiDockUIPart::typeDock
)
2713 part
.dock
->rect
= part
.rect
;
2718 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2720 wxAuiDockInfo
& dock
= docks
.Item(i
);
2721 if (test
.dock_direction
== dock
.dock_direction
&&
2722 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2724 if (dock
.IsVertical())
2736 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2737 // if a dock operation is allowed, the new dock position is copied into
2738 // the target info. If the operation was allowed, the function returns true.
2740 bool wxAuiManager::ProcessDockResult(wxAuiPaneInfo
& target
,
2741 const wxAuiPaneInfo
& new_pos
)
2743 bool allowed
= false;
2744 switch (new_pos
.dock_direction
)
2746 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2747 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2748 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2749 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2759 // DoDrop() is an important function. It basically takes a mouse position,
2760 // and determines where the pane's new position would be. If the pane is to be
2761 // dropped, it performs the drop operation using the specified dock and pane
2762 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2763 // scenario can be performed, giving precise coordinates for drop hints.
2764 // If, however, wxAuiManager:m_docks and wxAuiManager::m_panes are specified
2765 // as parameters, the changes will be made to the main state arrays
2767 const int auiInsertRowPixels
= 10;
2768 const int auiNewRowPixels
= 40;
2769 const int auiLayerInsertPixels
= 40;
2770 const int auiLayerInsertOffset
= 5;
2772 bool wxAuiManager::DoDrop(wxAuiDockInfoArray
& docks
,
2773 wxAuiPaneInfoArray
& panes
,
2774 wxAuiPaneInfo
& target
,
2776 const wxPoint
& offset
)
2778 wxSize cli_size
= m_frame
->GetClientSize();
2780 wxAuiPaneInfo drop
= target
;
2783 // The result should always be shown
2787 // Check to see if the pane has been dragged outside of the window
2788 // (or near to the outside of the window), if so, dock it along the edge
2791 int layer_insert_offset
= auiLayerInsertOffset
;
2792 if (drop
.IsToolbar())
2793 layer_insert_offset
= 0;
2796 if (pt
.x
< layer_insert_offset
&&
2797 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2799 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2800 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2801 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2803 if (drop
.IsToolbar())
2804 new_layer
= auiToolBarLayer
;
2809 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2810 return ProcessDockResult(target
, drop
);
2812 else if (pt
.y
< layer_insert_offset
&&
2813 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2815 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2816 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2817 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2819 if (drop
.IsToolbar())
2820 new_layer
= auiToolBarLayer
;
2825 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2826 return ProcessDockResult(target
, drop
);
2828 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2829 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2831 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2832 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2833 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2835 if (drop
.IsToolbar())
2836 new_layer
= auiToolBarLayer
;
2838 drop
.Dock().Right().
2841 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2842 return ProcessDockResult(target
, drop
);
2844 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2845 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2847 int new_layer
= wxMax( wxMax( GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2848 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2849 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2851 if (drop
.IsToolbar())
2852 new_layer
= auiToolBarLayer
;
2854 drop
.Dock().Bottom().
2857 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2858 return ProcessDockResult(target
, drop
);
2862 wxAuiDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2865 if (drop
.IsToolbar())
2867 if (!part
|| !part
->dock
)
2870 // calculate the offset from where the dock begins
2871 // to the point where the user dropped the pane
2872 int dock_drop_offset
= 0;
2873 if (part
->dock
->IsHorizontal())
2874 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2876 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2879 // toolbars may only be moved in and to fixed-pane docks,
2880 // otherwise we will try to float the pane. Also, the pane
2881 // should float if being dragged over center pane windows
2882 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2884 if (m_last_rect
.IsEmpty() || m_last_rect
.Contains(pt
.x
, pt
.y
))
2890 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2891 (drop
.IsFloatable() ||
2892 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2893 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2895 if (drop
.IsFloatable())
2901 return ProcessDockResult(target
, drop
);
2904 drop
.Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2906 return ProcessDockResult(target
, drop
);
2911 m_last_rect
= part
->dock
->rect
;
2912 m_last_rect
.Inflate( 15, 15 );
2915 Direction(part
->dock
->dock_direction
).
2916 Layer(part
->dock
->dock_layer
).
2917 Row(part
->dock
->dock_row
).
2918 Position(dock_drop_offset
);
2921 ((pt
.y
< part
->dock
->rect
.y
+ 1) && part
->dock
->IsHorizontal()) ||
2922 ((pt
.x
< part
->dock
->rect
.x
+ 1) && part
->dock
->IsVertical())
2923 ) && part
->dock
->panes
.GetCount() > 1)
2925 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2926 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2928 int row
= drop
.dock_row
;
2929 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2930 part
->dock
->dock_layer
,
2931 part
->dock
->dock_row
);
2932 drop
.dock_row
= row
;
2936 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2937 part
->dock
->dock_layer
,
2938 part
->dock
->dock_row
+1);
2939 drop
.dock_row
= part
->dock
->dock_row
+1;
2944 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2945 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2946 ) && part
->dock
->panes
.GetCount() > 1)
2948 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2949 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2951 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2952 part
->dock
->dock_layer
,
2953 part
->dock
->dock_row
+1);
2954 drop
.dock_row
= part
->dock
->dock_row
+1;
2958 int row
= drop
.dock_row
;
2959 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2960 part
->dock
->dock_layer
,
2961 part
->dock
->dock_row
);
2962 drop
.dock_row
= row
;
2966 return ProcessDockResult(target
, drop
);
2975 if (part
->type
== wxAuiDockUIPart::typePaneBorder
||
2976 part
->type
== wxAuiDockUIPart::typeCaption
||
2977 part
->type
== wxAuiDockUIPart::typeGripper
||
2978 part
->type
== wxAuiDockUIPart::typePaneButton
||
2979 part
->type
== wxAuiDockUIPart::typePane
||
2980 part
->type
== wxAuiDockUIPart::typePaneSizer
||
2981 part
->type
== wxAuiDockUIPart::typeDockSizer
||
2982 part
->type
== wxAuiDockUIPart::typeBackground
)
2984 if (part
->type
== wxAuiDockUIPart::typeDockSizer
)
2986 if (part
->dock
->panes
.GetCount() != 1)
2988 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2995 // If a normal frame is being dragged over a toolbar, insert it
2996 // along the edge under the toolbar, but over all other panes.
2997 // (this could be done much better, but somehow factoring this
2998 // calculation with the one at the beginning of this function)
2999 if (part
->dock
&& part
->dock
->toolbar
)
3003 switch (part
->dock
->dock_direction
)
3005 case wxAUI_DOCK_LEFT
:
3006 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
3007 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
3008 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
3010 case wxAUI_DOCK_TOP
:
3011 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
3012 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
3013 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
3015 case wxAUI_DOCK_RIGHT
:
3016 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
3017 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
3018 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
3020 case wxAUI_DOCK_BOTTOM
:
3021 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
3022 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
3023 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
3027 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
3030 Direction(part
->dock
->dock_direction
).
3031 Layer(layer
).Row(0).Position(0);
3032 return ProcessDockResult(target
, drop
);
3039 part
= GetPanePart(part
->pane
->window
);
3043 bool insert_dock_row
= false;
3044 int insert_row
= part
->pane
->dock_row
;
3045 int insert_dir
= part
->pane
->dock_direction
;
3046 int insert_layer
= part
->pane
->dock_layer
;
3048 switch (part
->pane
->dock_direction
)
3050 case wxAUI_DOCK_TOP
:
3051 if (pt
.y
>= part
->rect
.y
&&
3052 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
3053 insert_dock_row
= true;
3055 case wxAUI_DOCK_BOTTOM
:
3056 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
3057 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
3058 insert_dock_row
= true;
3060 case wxAUI_DOCK_LEFT
:
3061 if (pt
.x
>= part
->rect
.x
&&
3062 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
3063 insert_dock_row
= true;
3065 case wxAUI_DOCK_RIGHT
:
3066 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
3067 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
3068 insert_dock_row
= true;
3070 case wxAUI_DOCK_CENTER
:
3072 // "new row pixels" will be set to the default, but
3073 // must never exceed 20% of the window size
3074 int new_row_pixels_x
= auiNewRowPixels
;
3075 int new_row_pixels_y
= auiNewRowPixels
;
3077 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
3078 new_row_pixels_x
= (part
->rect
.width
*20)/100;
3080 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
3081 new_row_pixels_y
= (part
->rect
.height
*20)/100;
3084 // determine if the mouse pointer is in a location that
3085 // will cause a new row to be inserted. The hot spot positions
3086 // are along the borders of the center pane
3089 insert_dock_row
= true;
3090 const wxRect
& pr
= part
->rect
;
3091 if (pt
.x
>= pr
.x
&& pt
.x
< pr
.x
+ new_row_pixels_x
)
3092 insert_dir
= wxAUI_DOCK_LEFT
;
3093 else if (pt
.y
>= pr
.y
&& pt
.y
< pr
.y
+ new_row_pixels_y
)
3094 insert_dir
= wxAUI_DOCK_TOP
;
3095 else if (pt
.x
>= pr
.x
+ pr
.width
- new_row_pixels_x
&&
3096 pt
.x
< pr
.x
+ pr
.width
)
3097 insert_dir
= wxAUI_DOCK_RIGHT
;
3098 else if (pt
.y
>= pr
.y
+ pr
.height
- new_row_pixels_y
&&
3099 pt
.y
< pr
.y
+ pr
.height
)
3100 insert_dir
= wxAUI_DOCK_BOTTOM
;
3104 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
3108 if (insert_dock_row
)
3110 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
3111 drop
.Dock().Direction(insert_dir
).
3112 Layer(insert_layer
).
3115 return ProcessDockResult(target
, drop
);
3118 // determine the mouse offset and the pane size, both in the
3119 // direction of the dock itself, and perpendicular to the dock
3123 if (part
->orientation
== wxVERTICAL
)
3125 offset
= pt
.y
- part
->rect
.y
;
3126 size
= part
->rect
.GetHeight();
3130 offset
= pt
.x
- part
->rect
.x
;
3131 size
= part
->rect
.GetWidth();
3134 int drop_position
= part
->pane
->dock_pos
;
3136 // if we are in the top/left part of the pane,
3137 // insert the pane before the pane being hovered over
3138 if (offset
<= size
/2)
3140 drop_position
= part
->pane
->dock_pos
;
3142 part
->pane
->dock_direction
,
3143 part
->pane
->dock_layer
,
3144 part
->pane
->dock_row
,
3145 part
->pane
->dock_pos
);
3148 // if we are in the bottom/right part of the pane,
3149 // insert the pane before the pane being hovered over
3150 if (offset
> size
/2)
3152 drop_position
= part
->pane
->dock_pos
+1;
3154 part
->pane
->dock_direction
,
3155 part
->pane
->dock_layer
,
3156 part
->pane
->dock_row
,
3157 part
->pane
->dock_pos
+1);
3161 Direction(part
->dock
->dock_direction
).
3162 Layer(part
->dock
->dock_layer
).
3163 Row(part
->dock
->dock_row
).
3164 Position(drop_position
);
3165 return ProcessDockResult(target
, drop
);
3172 void wxAuiManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
3174 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
3176 m_hint_fadetimer
.Stop();
3180 m_hint_fadeamt
+= 4;
3181 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
3184 void wxAuiManager::ShowHint(const wxRect
& rect
)
3188 // if the hint rect is the same as last time, don't do anything
3189 if (m_last_hint
== rect
)
3193 m_hint_fadeamt
= m_hint_fademax
;
3195 if ((m_flags
& wxAUI_MGR_HINT_FADE
)
3196 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
3197 (m_flags
& wxAUI_MGR_NO_VENETIAN_BLINDS_FADE
))
3201 m_hint_wnd
->SetSize(rect
);
3202 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
3204 if (!m_hint_wnd
->IsShown())
3207 // if we are dragging a floating pane, set the focus
3208 // back to that floating pane (otherwise it becomes unfocused)
3209 if (m_action
== actionDragFloatingPane
&& m_action_window
)
3210 m_action_window
->SetFocus();
3212 m_hint_wnd
->Raise();
3215 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
3217 // start fade in timer
3218 m_hint_fadetimer
.SetOwner(this, 101);
3219 m_hint_fadetimer
.Start(5);
3222 else // Not using a transparent hint window...
3224 if (!(m_flags
& wxAUI_MGR_RECTANGLE_HINT
))
3227 if (m_last_hint
!= rect
)
3229 // remove the last hint rectangle
3235 wxScreenDC screendc
;
3236 wxRegion
clip(1, 1, 10000, 10000);
3238 // clip all floating windows, so we don't draw over them
3240 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
3242 wxAuiPaneInfo
& pane
= m_panes
.Item(i
);
3244 if (pane
.IsFloating() &&
3245 pane
.frame
->IsShown())
3247 wxRect rect
= pane
.frame
->GetRect();
3249 // wxGTK returns the client size, not the whole frame size
3255 clip
.Subtract(rect
);
3259 // As we can only hide the hint by redrawing the managed window, we
3260 // need to clip the region to the managed window too or we get
3261 // nasty redrawn problems.
3262 clip
.Intersect(m_frame
->GetRect());
3264 screendc
.SetDeviceClippingRegion(clip
);
3266 wxBitmap stipple
= wxPaneCreateStippleBitmap();
3267 wxBrush
brush(stipple
);
3268 screendc
.SetBrush(brush
);
3269 screendc
.SetPen(*wxTRANSPARENT_PEN
);
3271 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
3272 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
3273 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
3274 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
3278 void wxAuiManager::HideHint()
3280 // hides a transparent window hint, if there is one
3283 if (m_hint_wnd
->IsShown())
3284 m_hint_wnd
->Show(false);
3285 m_hint_wnd
->SetTransparent(0);
3286 m_hint_fadetimer
.Stop();
3287 m_last_hint
= wxRect();
3291 // hides a painted hint by redrawing the frame window
3292 if (!m_last_hint
.IsEmpty())
3296 m_last_hint
= wxRect();
3302 void wxAuiManager::StartPaneDrag(wxWindow
* pane_window
,
3303 const wxPoint
& offset
)
3305 wxAuiPaneInfo
& pane
= GetPane(pane_window
);
3309 if (pane
.IsToolbar())
3311 m_action
= actionDragToolbarPane
;
3315 m_action
= actionDragFloatingPane
;
3318 m_action_window
= pane_window
;
3319 m_action_offset
= offset
;
3320 m_frame
->CaptureMouse();
3324 // CalculateHintRect() calculates the drop hint rectangle. The method
3325 // first calls DoDrop() to determine the exact position the pane would
3326 // be at were if dropped. If the pane would indeed become docked at the
3327 // specified drop point, the the rectangle hint will be returned in
3328 // screen coordinates. Otherwise, an empty rectangle is returned.
3329 // |pane_window| is the window pointer of the pane being dragged, |pt| is
3330 // the mouse position, in client coordinates. |offset| describes the offset
3331 // that the mouse is from the upper-left corner of the item being dragged
3333 wxRect
wxAuiManager::CalculateHintRect(wxWindow
* pane_window
,
3335 const wxPoint
& offset
)
3339 // we need to paint a hint rectangle; to find out the exact hint rectangle,
3340 // we will create a new temporary layout and then measure the resulting
3341 // rectangle; we will create a copy of the docking structures (m_dock)
3342 // so that we don't modify the real thing on screen
3344 int i
, pane_count
, part_count
;
3345 wxAuiDockInfoArray docks
;
3346 wxAuiPaneInfoArray panes
;
3347 wxAuiDockUIPartArray uiparts
;
3348 wxAuiPaneInfo hint
= GetPane(pane_window
);
3349 hint
.name
= wxT("__HINT__");
3350 hint
.PaneBorder(true);
3356 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3358 // remove any pane already there which bears the same window;
3359 // this happens when you are moving a pane around in a dock
3360 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
3362 if (panes
.Item(i
).window
== pane_window
)
3364 RemovePaneFromDocks(docks
, panes
.Item(i
));
3370 // find out where the new pane would be
3371 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
3378 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
3379 wxSize client_size
= m_frame
->GetClientSize();
3380 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
3383 for (i
= 0, part_count
= uiparts
.GetCount();
3384 i
< part_count
; ++i
)
3386 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
3388 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
3389 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
3391 rect
= wxRect(part
.sizer_item
->GetPosition(),
3392 part
.sizer_item
->GetSize());
3404 // actually show the hint rectangle on the screen
3405 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
3407 if ( m_frame
->GetLayoutDirection() == wxLayout_RightToLeft
)
3409 // Mirror rectangle in RTL mode
3410 rect
.x
-= rect
.GetWidth();
3416 // DrawHintRect() calculates the hint rectangle by calling
3417 // CalculateHintRect(). If there is a rectangle, it shows it
3418 // by calling ShowHint(), otherwise it hides any hint
3419 // rectangle currently shown
3420 void wxAuiManager::DrawHintRect(wxWindow
* pane_window
,
3422 const wxPoint
& offset
)
3424 wxRect rect
= CalculateHintRect(pane_window
, pt
, offset
);
3436 void wxAuiManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
3438 // try to find the pane
3439 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3440 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3442 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3443 pane
.frame
->SetTransparent(150);
3446 void wxAuiManager::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
3448 // try to find the pane
3449 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3450 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3452 wxPoint pt
= ::wxGetMousePosition();
3455 // Adapt pt to direction
3458 // move to pane's upper border
3460 pos
= wnd
->ClientToScreen( pos
);
3462 // and some more pixels for the title bar
3465 else if (dir
== wxWEST
)
3467 // move to pane's left border
3469 pos
= wnd
->ClientToScreen( pos
);
3472 else if (dir
== wxEAST
)
3474 // move to pane's right border
3475 wxPoint
pos( wnd
->GetSize().x
, 0 );
3476 pos
= wnd
->ClientToScreen( pos
);
3479 else if (dir
== wxSOUTH
)
3481 // move to pane's bottom border
3482 wxPoint
pos( 0, wnd
->GetSize().y
);
3483 pos
= wnd
->ClientToScreen( pos
);
3490 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3492 // calculate the offset from the upper left-hand corner
3493 // of the frame to the mouse pointer
3494 wxPoint frame_pos
= pane
.frame
->GetPosition();
3495 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3497 // no hint for toolbar floating windows
3498 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
3500 wxAuiDockInfoArray docks
;
3501 wxAuiPaneInfoArray panes
;
3502 wxAuiDockUIPartArray uiparts
;
3503 wxAuiPaneInfo hint
= pane
;
3505 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3507 // find out where the new pane would be
3508 if (!DoDrop(docks
, panes
, hint
, client_pt
))
3510 if (hint
.IsFloating())
3514 m_action
= actionDragToolbarPane
;
3515 m_action_window
= pane
.window
;
3523 // if a key modifier is pressed while dragging the frame,
3524 // don't dock the window
3525 if (!CanDockPanel(pane
))
3532 DrawHintRect(wnd
, client_pt
, action_offset
);
3535 // this cleans up some screen artifacts that are caused on GTK because
3536 // we aren't getting the exact size of the window (see comment
3546 void wxAuiManager::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
3548 // try to find the pane
3549 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3550 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3552 wxPoint pt
= ::wxGetMousePosition();
3555 // Adapt pt to direction
3558 // move to pane's upper border
3560 pos
= wnd
->ClientToScreen( pos
);
3562 // and some more pixels for the title bar
3565 else if (dir
== wxWEST
)
3567 // move to pane's left border
3569 pos
= wnd
->ClientToScreen( pos
);
3572 else if (dir
== wxEAST
)
3574 // move to pane's right border
3575 wxPoint
pos( wnd
->GetSize().x
, 0 );
3576 pos
= wnd
->ClientToScreen( pos
);
3579 else if (dir
== wxSOUTH
)
3581 // move to pane's bottom border
3582 wxPoint
pos( 0, wnd
->GetSize().y
);
3583 pos
= wnd
->ClientToScreen( pos
);
3590 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3592 // calculate the offset from the upper left-hand corner
3593 // of the frame to the mouse pointer
3594 wxPoint frame_pos
= pane
.frame
->GetPosition();
3595 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3597 // if a key modifier is pressed while dragging the frame,
3598 // don't dock the window
3599 if (CanDockPanel(pane
))
3601 // do the drop calculation
3602 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3605 // if the pane is still floating, update it's floating
3606 // position (that we store)
3607 if (pane
.IsFloating())
3609 pane
.floating_pos
= pane
.frame
->GetPosition();
3611 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3612 pane
.frame
->SetTransparent(255);
3614 else if (m_has_maximized
)
3616 RestoreMaximizedPane();
3624 void wxAuiManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3626 // try to find the pane
3627 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3628 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3630 pane
.floating_size
= size
;
3634 void wxAuiManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3636 // try to find the pane
3637 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3638 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3641 // fire pane close event
3642 wxAuiManagerEvent
e(wxEVT_AUI_PANE_CLOSE
);
3644 e
.SetCanVeto(evt
.CanVeto());
3654 // close the pane, but check that it
3655 // still exists in our pane array first
3656 // (the event handler above might have removed it)
3658 wxAuiPaneInfo
& check
= GetPane(wnd
);
3668 void wxAuiManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3670 if ((GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
) && GetPane(wnd
).IsOk())
3672 SetActivePane(m_panes
, wnd
);
3677 // OnRender() draws all of the pane captions, sashes,
3678 // backgrounds, captions, grippers, pane borders and buttons.
3679 // It renders the entire user interface.
3681 void wxAuiManager::OnRender(wxAuiManagerEvent
& evt
)
3683 // if the frame is about to be deleted, don't bother
3684 if (!m_frame
|| wxPendingDelete
.Member(m_frame
))
3687 wxDC
* dc
= evt
.GetDC();
3693 for (i
= 0, part_count
= m_uiparts
.GetCount();
3694 i
< part_count
; ++i
)
3696 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
3698 // don't draw hidden pane items or items that aren't windows
3699 if (part
.sizer_item
&& ((!part
.sizer_item
->IsWindow() && !part
.sizer_item
->IsSpacer() && !part
.sizer_item
->IsSizer()) || !part
.sizer_item
->IsShown()))
3704 case wxAuiDockUIPart::typeDockSizer
:
3705 case wxAuiDockUIPart::typePaneSizer
:
3706 m_art
->DrawSash(*dc
, m_frame
, part
.orientation
, part
.rect
);
3708 case wxAuiDockUIPart::typeBackground
:
3709 m_art
->DrawBackground(*dc
, m_frame
, part
.orientation
, part
.rect
);
3711 case wxAuiDockUIPart::typeCaption
:
3712 m_art
->DrawCaption(*dc
, m_frame
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3714 case wxAuiDockUIPart::typeGripper
:
3715 m_art
->DrawGripper(*dc
, m_frame
, part
.rect
, *part
.pane
);
3717 case wxAuiDockUIPart::typePaneBorder
:
3718 m_art
->DrawBorder(*dc
, m_frame
, part
.rect
, *part
.pane
);
3720 case wxAuiDockUIPart::typePaneButton
:
3721 m_art
->DrawPaneButton(*dc
, m_frame
, part
.button
->button_id
,
3722 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3729 // Render() fire a render event, which is normally handled by
3730 // wxAuiManager::OnRender(). This allows the render function to
3731 // be overridden via the render event. This can be useful for paintin
3732 // custom graphics in the main window. Default behavior can be
3733 // invoked in the overridden function by calling OnRender()
3735 void wxAuiManager::Render(wxDC
* dc
)
3737 wxAuiManagerEvent
e(wxEVT_AUI_RENDER
);
3743 void wxAuiManager::Repaint(wxDC
* dc
)
3748 m_frame
->Refresh() ;
3754 m_frame
->GetClientSize(&w
, &h
);
3756 // figure out which dc to use; if one
3757 // has been specified, use it, otherwise
3759 wxClientDC
* client_dc
= NULL
;
3762 client_dc
= new wxClientDC(m_frame
);
3766 // if the frame has a toolbar, the client area
3767 // origin will not be (0,0).
3768 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3769 if (pt
.x
!= 0 || pt
.y
!= 0)
3770 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3772 // render all the items
3775 // if we created a client_dc, delete it
3780 void wxAuiManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3782 wxPaintDC
dc(m_frame
);
3786 void wxAuiManager::OnEraseBackground(wxEraseEvent
& event
)
3795 void wxAuiManager::OnSize(wxSizeEvent
& event
)
3803 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
3805 // for MDI parent frames, this event must not
3806 // be "skipped". In other words, the parent frame
3807 // must not be allowed to resize the client window
3808 // after we are finished processing sizing changes
3816 void wxAuiManager::OnFindManager(wxAuiManagerEvent
& evt
)
3818 // get the window we are managing, if none, return NULL
3819 wxWindow
* window
= GetManagedWindow();
3822 evt
.SetManager(NULL
);
3826 // if we are managing a child frame, get the 'real' manager
3827 if (window
->IsKindOf(CLASSINFO(wxAuiFloatingFrame
)))
3829 wxAuiFloatingFrame
* float_frame
= static_cast<wxAuiFloatingFrame
*>(window
);
3830 evt
.SetManager(float_frame
->GetOwnerManager());
3834 // return pointer to ourself
3835 evt
.SetManager(this);
3838 void wxAuiManager::OnSetCursor(wxSetCursorEvent
& event
)
3841 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3842 wxCursor cursor
= wxNullCursor
;
3846 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3847 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3849 // a dock may not be resized if it has a single
3850 // pane which is not resizable
3851 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3852 part
->dock
->panes
.GetCount() == 1 &&
3853 part
->dock
->panes
.Item(0)->IsFixed())
3856 // panes that may not be resized do not get a sizing cursor
3857 if (part
->pane
&& part
->pane
->IsFixed())
3860 if (part
->orientation
== wxVERTICAL
)
3861 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3863 cursor
= wxCursor(wxCURSOR_SIZENS
);
3865 else if (part
->type
== wxAuiDockUIPart::typeGripper
)
3867 cursor
= wxCursor(wxCURSOR_SIZING
);
3871 event
.SetCursor(cursor
);
3876 void wxAuiManager::UpdateButtonOnScreen(wxAuiDockUIPart
* button_ui_part
,
3877 const wxMouseEvent
& event
)
3879 wxAuiDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3880 if (!hit_test
|| !button_ui_part
)
3883 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3885 if (hit_test
== button_ui_part
)
3887 if (event
.LeftDown())
3888 state
= wxAUI_BUTTON_STATE_PRESSED
;
3890 state
= wxAUI_BUTTON_STATE_HOVER
;
3894 if (event
.LeftDown())
3895 state
= wxAUI_BUTTON_STATE_HOVER
;
3898 // now repaint the button with hover state
3899 wxClientDC
cdc(m_frame
);
3901 // if the frame has a toolbar, the client area
3902 // origin will not be (0,0).
3903 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3904 if (pt
.x
!= 0 || pt
.y
!= 0)
3905 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3909 m_art
->DrawPaneButton(cdc
, m_frame
,
3910 button_ui_part
->button
->button_id
,
3912 button_ui_part
->rect
,
3917 void wxAuiManager::OnLeftDown(wxMouseEvent
& event
)
3919 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3922 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3923 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3925 // Removing this restriction so that a centre pane can be resized
3926 //if (part->dock && part->dock->dock_direction == wxAUI_DOCK_CENTER)
3929 // a dock may not be resized if it has a single
3930 // pane which is not resizable
3931 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3932 part
->dock
->panes
.GetCount() == 1 &&
3933 part
->dock
->panes
.Item(0)->IsFixed())
3936 // panes that may not be resized should be ignored here
3937 if (part
->pane
&& part
->pane
->IsFixed())
3940 m_action
= actionResize
;
3941 m_action_part
= part
;
3942 m_action_hintrect
= wxRect();
3943 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3944 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3945 event
.m_y
- part
->rect
.y
);
3946 m_frame
->CaptureMouse();
3948 else if (part
->type
== wxAuiDockUIPart::typePaneButton
)
3950 m_action
= actionClickButton
;
3951 m_action_part
= part
;
3952 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3953 m_frame
->CaptureMouse();
3955 UpdateButtonOnScreen(part
, event
);
3957 else if (part
->type
== wxAuiDockUIPart::typeCaption
||
3958 part
->type
== wxAuiDockUIPart::typeGripper
)
3960 // if we are managing a wxAuiFloatingFrame window, then
3961 // we are an embedded wxAuiManager inside the wxAuiFloatingFrame.
3962 // We want to initiate a toolbar drag in our owner manager
3963 wxWindow
* managed_wnd
= GetManagedWindow();
3966 part
->pane
->window
&&
3968 managed_wnd
->IsKindOf(CLASSINFO(wxAuiFloatingFrame
)))
3970 wxAuiFloatingFrame
* floating_frame
= (wxAuiFloatingFrame
*)managed_wnd
;
3971 wxAuiManager
* owner_mgr
= floating_frame
->GetOwnerManager();
3972 owner_mgr
->StartPaneDrag(part
->pane
->window
,
3973 wxPoint(event
.m_x
- part
->rect
.x
,
3974 event
.m_y
- part
->rect
.y
));
3980 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3982 // set the caption as active
3983 SetActivePane(m_panes
, part
->pane
->window
);
3987 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3990 m_action
= actionClickCaption
;
3991 m_action_part
= part
;
3992 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3993 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3994 event
.m_y
- part
->rect
.y
);
3995 m_frame
->CaptureMouse();
4015 void wxAuiManager::OnLeftUp(wxMouseEvent
& event
)
4017 if (m_action
== actionResize
)
4019 m_frame
->ReleaseMouse();
4021 // get rid of the hint rectangle
4023 DrawResizeHint(dc
, m_action_hintrect
);
4025 // resize the dock or the pane
4026 if (m_action_part
&& m_action_part
->type
==wxAuiDockUIPart::typeDockSizer
)
4028 wxRect
& rect
= m_action_part
->dock
->rect
;
4030 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
4031 event
.m_y
- m_action_offset
.y
);
4033 switch (m_action_part
->dock
->dock_direction
)
4035 case wxAUI_DOCK_LEFT
:
4036 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
4038 case wxAUI_DOCK_TOP
:
4039 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
4041 case wxAUI_DOCK_RIGHT
:
4042 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
4043 new_pos
.x
- m_action_part
->rect
.GetWidth();
4045 case wxAUI_DOCK_BOTTOM
:
4046 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
4047 new_pos
.y
- m_action_part
->rect
.GetHeight();
4054 else if (m_action_part
&&
4055 m_action_part
->type
== wxAuiDockUIPart::typePaneSizer
)
4057 wxAuiDockInfo
& dock
= *m_action_part
->dock
;
4058 wxAuiPaneInfo
& pane
= *m_action_part
->pane
;
4060 int total_proportion
= 0;
4061 int dock_pixels
= 0;
4062 int new_pixsize
= 0;
4064 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
4065 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
4066 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
4068 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
4069 event
.m_y
- m_action_offset
.y
);
4071 // determine the pane rectangle by getting the pane part
4072 wxAuiDockUIPart
* pane_part
= GetPanePart(pane
.window
);
4073 wxASSERT_MSG(pane_part
,
4074 wxT("Pane border part not found -- shouldn't happen"));
4076 // determine the new pixel size that the user wants;
4077 // this will help us recalculate the pane's proportion
4078 if (dock
.IsHorizontal())
4079 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
4081 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
4083 // determine the size of the dock, based on orientation
4084 if (dock
.IsHorizontal())
4085 dock_pixels
= dock
.rect
.GetWidth();
4087 dock_pixels
= dock
.rect
.GetHeight();
4089 // determine the total proportion of all resizable panes,
4090 // and the total size of the dock minus the size of all
4092 int i
, dock_pane_count
= dock
.panes
.GetCount();
4093 int pane_position
= -1;
4094 for (i
= 0; i
< dock_pane_count
; ++i
)
4096 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
4097 if (p
.window
== pane
.window
)
4100 // while we're at it, subtract the pane sash
4101 // width from the dock width, because this would
4102 // skew our proportion calculations
4104 dock_pixels
-= sash_size
;
4106 // also, the whole size (including decorations) of
4107 // all fixed panes must also be subtracted, because they
4108 // are not part of the proportion calculation
4111 if (dock
.IsHorizontal())
4112 dock_pixels
-= p
.best_size
.x
;
4114 dock_pixels
-= p
.best_size
.y
;
4118 total_proportion
+= p
.dock_proportion
;
4122 // find a pane in our dock to 'steal' space from or to 'give'
4123 // space to -- this is essentially what is done when a pane is
4124 // resized; the pane should usually be the first non-fixed pane
4125 // to the right of the action pane
4126 int borrow_pane
= -1;
4127 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
4129 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
4138 // demand that the pane being resized is found in this dock
4139 // (this assert really never should be raised)
4140 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
4142 // prevent division by zero
4143 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
4145 m_action
= actionNone
;
4149 // calculate the new proportion of the pane
4150 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
4152 // default minimum size
4155 // check against the pane's minimum size, if specified. please note
4156 // that this is not enough to ensure that the minimum size will
4157 // not be violated, because the whole frame might later be shrunk,
4158 // causing the size of the pane to violate it's minimum size
4159 if (pane
.min_size
.IsFullySpecified())
4163 if (pane
.HasBorder())
4164 min_size
+= (pane_border_size
*2);
4166 // calculate minimum size with decorations (border,caption)
4167 if (pane_part
->orientation
== wxVERTICAL
)
4169 min_size
+= pane
.min_size
.y
;
4170 if (pane
.HasCaption())
4171 min_size
+= caption_size
;
4175 min_size
+= pane
.min_size
.x
;
4180 // for some reason, an arithmatic error somewhere is causing
4181 // the proportion calculations to always be off by 1 pixel;
4182 // for now we will add the 1 pixel on, but we really should
4183 // determine what's causing this.
4186 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
4188 if (new_proportion
< min_proportion
)
4189 new_proportion
= min_proportion
;
4193 int prop_diff
= new_proportion
- pane
.dock_proportion
;
4195 // borrow the space from our neighbor pane to the
4196 // right or bottom (depending on orientation)
4197 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
4198 pane
.dock_proportion
= new_proportion
;
4205 else if (m_action
== actionClickButton
)
4207 m_hover_button
= NULL
;
4208 m_frame
->ReleaseMouse();
4212 UpdateButtonOnScreen(m_action_part
, event
);
4214 // make sure we're still over the item that was originally clicked
4215 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
4217 // fire button-click event
4218 wxAuiManagerEvent
e(wxEVT_AUI_PANE_BUTTON
);
4220 e
.SetPane(m_action_part
->pane
);
4221 e
.SetButton(m_action_part
->button
->button_id
);
4226 else if (m_action
== actionClickCaption
)
4228 m_frame
->ReleaseMouse();
4230 else if (m_action
== actionDragFloatingPane
)
4232 m_frame
->ReleaseMouse();
4234 else if (m_action
== actionDragToolbarPane
)
4236 m_frame
->ReleaseMouse();
4238 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4239 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4241 // save the new positions
4242 wxAuiDockInfoPtrArray docks
;
4243 FindDocks(m_docks
, pane
.dock_direction
,
4244 pane
.dock_layer
, pane
.dock_row
, docks
);
4245 if (docks
.GetCount() == 1)
4247 wxAuiDockInfo
& dock
= *docks
.Item(0);
4249 wxArrayInt pane_positions
, pane_sizes
;
4250 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
4252 int i
, dock_pane_count
= dock
.panes
.GetCount();
4253 for (i
= 0; i
< dock_pane_count
; ++i
)
4254 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
4257 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
4265 m_action
= actionNone
;
4266 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
4270 void wxAuiManager::OnMotion(wxMouseEvent
& event
)
4272 // sometimes when Update() is called from inside this method,
4273 // a spurious mouse move event is generated; this check will make
4274 // sure that only real mouse moves will get anywhere in this method;
4275 // this appears to be a bug somewhere, and I don't know where the
4276 // mouse move event is being generated. only verified on MSW
4278 wxPoint mouse_pos
= event
.GetPosition();
4279 if (m_last_mouse_move
== mouse_pos
)
4281 m_last_mouse_move
= mouse_pos
;
4284 if (m_action
== actionResize
)
4288 wxPoint pos
= m_action_part
->rect
.GetPosition();
4289 if (m_action_part
->orientation
== wxHORIZONTAL
)
4290 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
4292 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
4294 wxRect
rect(m_frame
->ClientToScreen(pos
),
4295 m_action_part
->rect
.GetSize());
4298 if (!m_action_hintrect
.IsEmpty())
4299 DrawResizeHint(dc
, m_action_hintrect
);
4300 DrawResizeHint(dc
, rect
);
4301 m_action_hintrect
= rect
;
4304 else if (m_action
== actionClickCaption
)
4306 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
4307 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
4309 // caption has been clicked. we need to check if the mouse
4310 // is now being dragged. if it is, we need to change the
4311 // mouse action to 'drag'
4312 if (m_action_part
&&
4313 (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
4314 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
))
4316 wxAuiPaneInfo
* pane_info
= m_action_part
->pane
;
4318 if (!pane_info
->IsToolbar())
4320 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
4321 pane_info
->IsFloatable())
4323 m_action
= actionDragFloatingPane
;
4325 // set initial float position
4326 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4327 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4328 pt
.y
- m_action_offset
.y
);
4331 if (pane_info
->IsMaximized())
4332 RestorePane(*pane_info
);
4336 m_action_window
= pane_info
->frame
;
4338 // action offset is used here to make it feel "natural" to the user
4339 // to drag a docked pane and suddenly have it become a floating frame.
4340 // Sometimes, however, the offset where the user clicked on the docked
4341 // caption is bigger than the width of the floating frame itself, so
4342 // in that case we need to set the action offset to a sensible value
4343 wxSize frame_size
= m_action_window
->GetSize();
4344 if (frame_size
.x
<= m_action_offset
.x
)
4345 m_action_offset
.x
= 30;
4350 m_action
= actionDragToolbarPane
;
4351 m_action_window
= pane_info
->window
;
4355 else if (m_action
== actionDragFloatingPane
)
4357 if (m_action_window
)
4359 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4360 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
4361 pt
.y
- m_action_offset
.y
);
4364 else if (m_action
== actionDragToolbarPane
)
4366 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4367 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4369 pane
.state
|= wxAuiPaneInfo::actionPane
;
4371 wxPoint pt
= event
.GetPosition();
4372 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
4374 // if DoDrop() decided to float the pane, set up
4375 // the floating pane's initial position
4376 if (pane
.IsFloating())
4378 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4379 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4380 pt
.y
- m_action_offset
.y
);
4383 // this will do the actiual move operation;
4384 // in the case that the pane has been floated,
4385 // this call will create the floating pane
4386 // and do the reparenting
4389 // if the pane has been floated, change the mouse
4390 // action actionDragFloatingPane so that subsequent
4391 // EVT_MOTION() events will move the floating pane
4392 if (pane
.IsFloating())
4394 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
4395 m_action
= actionDragFloatingPane
;
4396 m_action_window
= pane
.frame
;
4401 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
4402 if (part
&& part
->type
== wxAuiDockUIPart::typePaneButton
)
4404 if (part
!= m_hover_button
)
4406 // make the old button normal
4409 UpdateButtonOnScreen(m_hover_button
, event
);
4413 // mouse is over a button, so repaint the
4414 // button in hover mode
4415 UpdateButtonOnScreen(part
, event
);
4416 m_hover_button
= part
;
4424 m_hover_button
= NULL
;
4435 void wxAuiManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
4439 m_hover_button
= NULL
;
4444 void wxAuiManager::OnChildFocus(wxChildFocusEvent
& event
)
4446 // when a child pane has it's focus set, we should change the
4447 // pane's active state to reflect this. (this is only true if
4448 // active panes are allowed by the owner)
4449 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
4451 wxAuiPaneInfo
& pane
= GetPane(event
.GetWindow());
4452 if (pane
.IsOk() && (pane
.state
& wxAuiPaneInfo::optionActive
) == 0)
4454 SetActivePane(m_panes
, event
.GetWindow());
4463 // OnPaneButton() is an event handler that is called
4464 // when a pane button has been pressed.
4465 void wxAuiManager::OnPaneButton(wxAuiManagerEvent
& evt
)
4467 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxAuiManager::OnPaneButton must be non-null"));
4469 wxAuiPaneInfo
& pane
= *(evt
.pane
);
4471 if (evt
.button
== wxAUI_BUTTON_CLOSE
)
4473 // fire pane close event
4474 wxAuiManagerEvent
e(wxEVT_AUI_PANE_CLOSE
);
4476 e
.SetPane(evt
.pane
);
4481 // close the pane, but check that it
4482 // still exists in our pane array first
4483 // (the event handler above might have removed it)
4485 wxAuiPaneInfo
& check
= GetPane(pane
.window
);
4494 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& !pane
.IsMaximized())
4496 // fire pane close event
4497 wxAuiManagerEvent
e(wxEVT_AUI_PANE_MAXIMIZE
);
4499 e
.SetPane(evt
.pane
);
4508 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& pane
.IsMaximized())
4510 // fire pane close event
4511 wxAuiManagerEvent
e(wxEVT_AUI_PANE_RESTORE
);
4513 e
.SetPane(evt
.pane
);
4522 else if (evt
.button
== wxAUI_BUTTON_PIN
)
4524 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&