1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/framemanager.cpp
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
8 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/aui/framemanager.h"
29 #include "wx/aui/dockart.h"
30 #include "wx/aui/floatpane.h"
31 #include "wx/aui/tabmdi.h"
35 #include "wx/settings.h"
37 #include "wx/dcclient.h"
38 #include "wx/dcscreen.h"
39 #include "wx/toolbar.h"
44 WX_CHECK_BUILD_OPTIONS("wxAUI")
46 #include "wx/arrimpl.cpp"
47 WX_DECLARE_OBJARRAY(wxRect
, wxAuiRectArray
);
48 WX_DEFINE_OBJARRAY(wxAuiRectArray
)
49 WX_DEFINE_OBJARRAY(wxAuiDockUIPartArray
)
50 WX_DEFINE_OBJARRAY(wxAuiDockInfoArray
)
51 WX_DEFINE_OBJARRAY(wxAuiPaneButtonArray
)
52 WX_DEFINE_OBJARRAY(wxAuiPaneInfoArray
)
54 wxAuiPaneInfo wxAuiNullPaneInfo
;
55 wxAuiDockInfo wxAuiNullDockInfo
;
56 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_BUTTON
)
57 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_CLOSE
)
58 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_MAXIMIZE
)
59 DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_RESTORE
)
60 DEFINE_EVENT_TYPE(wxEVT_AUI_RENDER
)
61 DEFINE_EVENT_TYPE(wxEVT_AUI_FIND_MANAGER
)
64 // a few defines to avoid nameclashes
65 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
67 #include "wx/mac/private.h"
71 #include "wx/msw/wrapwin.h"
72 #include "wx/msw/private.h"
75 IMPLEMENT_DYNAMIC_CLASS(wxAuiManagerEvent
, wxEvent
)
76 IMPLEMENT_CLASS(wxAuiManager
, wxEvtHandler
)
80 const int auiToolBarLayer
= 10;
85 class wxPseudoTransparentFrame
: public wxFrame
88 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
89 wxWindowID id
= wxID_ANY
,
90 const wxString
& title
= wxEmptyString
,
91 const wxPoint
& pos
= wxDefaultPosition
,
92 const wxSize
& size
= wxDefaultSize
,
93 long style
= wxDEFAULT_FRAME_STYLE
,
94 const wxString
&name
= wxT("frame"))
95 : wxFrame(parent
, id
, title
, pos
, size
, style
| wxFRAME_SHAPED
, name
)
97 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
104 m_CanSetShape
= false; // have to wait for window create event on GTK
106 m_CanSetShape
= true;
108 m_Region
= wxRegion(0, 0, 0, 0);
112 virtual bool SetTransparent(wxByte alpha
)
116 int w
=100; // some defaults
118 GetClientSize(&w
, &h
);
124 // m_Region.Union(0, 0, 1, m_MaxWidth);
127 for (int y
=0; y
<m_MaxHeight
; y
++)
129 // Reverse the order of the bottom 4 bits
130 int j
=((y
&8)?1:0)|((y
&4)?2:0)|((y
&2)?4:0)|((y
&1)?8:0);
131 if ((j
*16+8)<m_Amount
)
132 m_Region
.Union(0, y
, m_MaxWidth
, 1);
141 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
145 if (m_Region
.IsEmpty())
149 dc
.SetBrush(wxColour(128, 192, 255));
151 dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
153 dc
.SetPen(*wxTRANSPARENT_PEN
);
155 wxRegionIterator
upd(GetUpdateRegion()); // get the update rect list
159 wxRect
rect(upd
.GetRect());
160 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
167 void OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
))
174 void OnSize(wxSizeEvent
& event
)
176 // We sometimes get surplus size events
177 if ((event
.GetSize().GetWidth() == m_lastWidth
) &&
178 (event
.GetSize().GetHeight() == m_lastHeight
))
183 m_lastWidth
= event
.GetSize().GetWidth();
184 m_lastHeight
= event
.GetSize().GetHeight();
186 SetTransparent(m_Amount
);
187 m_Region
.Intersect(0, 0, event
.GetSize().GetWidth(),
188 event
.GetSize().GetHeight());
199 int m_lastWidth
,m_lastHeight
;
203 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
204 DECLARE_EVENT_TABLE()
208 IMPLEMENT_DYNAMIC_CLASS(wxPseudoTransparentFrame
, wxFrame
)
210 BEGIN_EVENT_TABLE(wxPseudoTransparentFrame
, wxFrame
)
211 EVT_PAINT(wxPseudoTransparentFrame::OnPaint
)
212 EVT_SIZE(wxPseudoTransparentFrame::OnSize
)
214 EVT_WINDOW_CREATE(wxPseudoTransparentFrame::OnWindowCreate
)
222 #include "wx/gtk/private.h"
225 gtk_pseudo_window_realized_callback( GtkWidget
*m_widget
, void *WXUNUSED(win
) )
227 wxSize disp
= wxGetDisplaySize();
230 for (int y
=0; y
<disp
.y
; y
++)
232 // Reverse the order of the bottom 4 bits
233 int j
=((y
&8)?1:0)|((y
&4)?2:0)|((y
&2)?4:0)|((y
&1)?8:0);
235 region
.Union(0, y
, disp
.x
, 1);
237 gdk_window_shape_combine_region(m_widget
->window
, region
.GetRegion(), 0, 0);
241 class wxPseudoTransparentFrame
: public wxFrame
244 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
245 wxWindowID id
= wxID_ANY
,
246 const wxString
& title
= wxEmptyString
,
247 const wxPoint
& pos
= wxDefaultPosition
,
248 const wxSize
& size
= wxDefaultSize
,
249 long style
= wxDEFAULT_FRAME_STYLE
,
250 const wxString
&name
= wxT("frame"))
252 if (!CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
257 m_widget
= gtk_window_new( GTK_WINDOW_POPUP
);
259 g_signal_connect( m_widget
, "realize",
260 G_CALLBACK (gtk_pseudo_window_realized_callback
), this );
264 col
.green
= 192 * 256;
265 col
.blue
= 255 * 256;
266 gtk_widget_modify_bg( m_widget
, GTK_STATE_NORMAL
, &col
);
269 bool SetTransparent(wxByte
WXUNUSED(alpha
))
275 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
278 IMPLEMENT_DYNAMIC_CLASS(wxPseudoTransparentFrame
, wxFrame
)
285 // -- static utility functions --
287 static wxBitmap
wxPaneCreateStippleBitmap()
289 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
290 wxImage
img(2,2,data
,true);
291 return wxBitmap(img
);
294 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
296 wxBitmap stipple
= wxPaneCreateStippleBitmap();
297 wxBrush
brush(stipple
);
300 PatBlt(GetHdcOf(dc
), rect
.GetX(), rect
.GetY(), rect
.GetWidth(), rect
.GetHeight(), PATINVERT
);
302 dc
.SetPen(*wxTRANSPARENT_PEN
);
304 dc
.SetLogicalFunction(wxXOR
);
305 dc
.DrawRectangle(rect
);
311 // CopyDocksAndPanes() - this utility function creates copies of
312 // the dock and pane info. wxAuiDockInfo's usually contain pointers
313 // to wxAuiPaneInfo classes, thus this function is necessary to reliably
314 // reconstruct that relationship in the new dock info and pane info arrays
316 static void CopyDocksAndPanes(wxAuiDockInfoArray
& dest_docks
,
317 wxAuiPaneInfoArray
& dest_panes
,
318 const wxAuiDockInfoArray
& src_docks
,
319 const wxAuiPaneInfoArray
& src_panes
)
321 dest_docks
= src_docks
;
322 dest_panes
= src_panes
;
323 int i
, j
, k
, dock_count
, pc1
, pc2
;
324 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
326 wxAuiDockInfo
& dock
= dest_docks
.Item(i
);
327 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
328 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
329 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
330 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
334 // GetMaxLayer() is an internal function which returns
335 // the highest layer inside the specified dock
336 static int GetMaxLayer(const wxAuiDockInfoArray
& docks
,
339 int i
, dock_count
, max_layer
= 0;
340 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
342 wxAuiDockInfo
& dock
= docks
.Item(i
);
343 if (dock
.dock_direction
== dock_direction
&&
344 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
345 max_layer
= dock
.dock_layer
;
351 // GetMaxRow() is an internal function which returns
352 // the highest layer inside the specified dock
353 static int GetMaxRow(const wxAuiPaneInfoArray
& panes
, int direction
, int layer
)
355 int i
, pane_count
, max_row
= 0;
356 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
358 wxAuiPaneInfo
& pane
= panes
.Item(i
);
359 if (pane
.dock_direction
== direction
&&
360 pane
.dock_layer
== layer
&&
361 pane
.dock_row
> max_row
)
362 max_row
= pane
.dock_row
;
369 // DoInsertDockLayer() is an internal function that inserts a new dock
370 // layer by incrementing all existing dock layer values by one
371 static void DoInsertDockLayer(wxAuiPaneInfoArray
& panes
,
376 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
378 wxAuiPaneInfo
& pane
= panes
.Item(i
);
379 if (!pane
.IsFloating() &&
380 pane
.dock_direction
== dock_direction
&&
381 pane
.dock_layer
>= dock_layer
)
386 // DoInsertDockLayer() is an internal function that inserts a new dock
387 // row by incrementing all existing dock row values by one
388 static void DoInsertDockRow(wxAuiPaneInfoArray
& panes
,
394 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
396 wxAuiPaneInfo
& pane
= panes
.Item(i
);
397 if (!pane
.IsFloating() &&
398 pane
.dock_direction
== dock_direction
&&
399 pane
.dock_layer
== dock_layer
&&
400 pane
.dock_row
>= dock_row
)
405 // DoInsertDockLayer() is an internal function that inserts a space for
406 // another dock pane by incrementing all existing dock row values by one
407 static void DoInsertPane(wxAuiPaneInfoArray
& panes
,
414 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
416 wxAuiPaneInfo
& pane
= panes
.Item(i
);
417 if (!pane
.IsFloating() &&
418 pane
.dock_direction
== dock_direction
&&
419 pane
.dock_layer
== dock_layer
&&
420 pane
.dock_row
== dock_row
&&
421 pane
.dock_pos
>= dock_pos
)
426 // FindDocks() is an internal function that returns a list of docks which meet
427 // the specified conditions in the parameters and returns a sorted array
428 // (sorted by layer and then row)
429 static void FindDocks(wxAuiDockInfoArray
& docks
,
433 wxAuiDockInfoPtrArray
& arr
)
435 int begin_layer
= dock_layer
;
436 int end_layer
= dock_layer
;
437 int begin_row
= dock_row
;
438 int end_row
= dock_row
;
439 int dock_count
= docks
.GetCount();
440 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
442 // discover the maximum dock layer and the max row
443 for (i
= 0; i
< dock_count
; ++i
)
445 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
446 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
449 // if no dock layer was specified, search all dock layers
450 if (dock_layer
== -1)
453 end_layer
= max_layer
;
456 // if no dock row was specified, search all dock row
465 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
466 for (row
= begin_row
; row
<= end_row
; ++row
)
467 for (i
= 0; i
< dock_count
; ++i
)
469 wxAuiDockInfo
& d
= docks
.Item(i
);
470 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
472 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
478 // FindPaneInDock() looks up a specified window pointer inside a dock.
479 // If found, the corresponding wxAuiPaneInfo pointer is returned, otherwise NULL.
480 static wxAuiPaneInfo
* FindPaneInDock(const wxAuiDockInfo
& dock
, wxWindow
* window
)
482 int i
, count
= dock
.panes
.GetCount();
483 for (i
= 0; i
< count
; ++i
)
485 wxAuiPaneInfo
* p
= dock
.panes
.Item(i
);
486 if (p
->window
== window
)
492 // RemovePaneFromDocks() removes a pane window from all docks
493 // with a possible exception specified by parameter "ex_cept"
494 static void RemovePaneFromDocks(wxAuiDockInfoArray
& docks
,
496 wxAuiDockInfo
* ex_cept
= NULL
)
499 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
501 wxAuiDockInfo
& d
= docks
.Item(i
);
504 wxAuiPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
511 // This function works fine, and may be used in the future
513 // RenumberDockRows() takes a dock and assigns sequential numbers
514 // to existing rows. Basically it takes out the gaps; so if a
515 // dock has rows with numbers 0,2,5, they will become 0,1,2
516 static void RenumberDockRows(wxAuiDockInfoPtrArray& docks)
519 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
521 wxAuiDockInfo& dock = *docks.Item(i);
525 for (j = 0, pane_count = dock.panes.GetCount(); j < pane_count; ++j)
526 dock.panes.Item(j)->dock_row = i;
532 // SetActivePane() sets the active pane, as well as cycles through
533 // every other pane and makes sure that all others' active flags
535 static void SetActivePane(wxAuiPaneInfoArray
& panes
, wxWindow
* active_pane
)
538 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
540 wxAuiPaneInfo
& pane
= panes
.Item(i
);
541 pane
.state
&= ~wxAuiPaneInfo::optionActive
;
542 if (pane
.window
== active_pane
)
543 pane
.state
|= wxAuiPaneInfo::optionActive
;
548 // this function is used to sort panes by dock position
549 static int PaneSortFunc(wxAuiPaneInfo
** p1
, wxAuiPaneInfo
** p2
)
551 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
555 // -- wxAuiManager class implementation --
558 BEGIN_EVENT_TABLE(wxAuiManager
, wxEvtHandler
)
559 EVT_AUI_PANE_BUTTON(wxAuiManager::OnPaneButton
)
560 EVT_AUI_RENDER(wxAuiManager::OnRender
)
561 EVT_PAINT(wxAuiManager::OnPaint
)
562 EVT_ERASE_BACKGROUND(wxAuiManager::OnEraseBackground
)
563 EVT_SIZE(wxAuiManager::OnSize
)
564 EVT_SET_CURSOR(wxAuiManager::OnSetCursor
)
565 EVT_LEFT_DOWN(wxAuiManager::OnLeftDown
)
566 EVT_LEFT_UP(wxAuiManager::OnLeftUp
)
567 EVT_MOTION(wxAuiManager::OnMotion
)
568 EVT_LEAVE_WINDOW(wxAuiManager::OnLeaveWindow
)
569 EVT_CHILD_FOCUS(wxAuiManager::OnChildFocus
)
570 EVT_AUI_FIND_MANAGER(wxAuiManager::OnFindManager
)
571 EVT_TIMER(101, wxAuiManager::OnHintFadeTimer
)
575 wxAuiManager::wxAuiManager(wxWindow
* managed_wnd
, unsigned int flags
)
577 m_action
= actionNone
;
578 m_last_mouse_move
= wxPoint();
579 m_hover_button
= NULL
;
580 m_art
= new wxAuiDefaultDockArt
;
584 m_has_maximized
= false;
586 m_dock_constraint_x
= 0.3;
587 m_dock_constraint_y
= 0.3;
592 SetManagedWindow(managed_wnd
);
596 wxAuiManager::~wxAuiManager()
598 // NOTE: It's possible that the windows have already been destroyed by the
599 // time this dtor is called, so this loop can result in memory access via
600 // invalid pointers, resulting in a crash. So it will be disabled while
601 // waiting for a better solution.
603 for ( size_t i
= 0; i
< m_panes
.size(); i
++ )
605 wxAuiPaneInfo
& pinfo
= m_panes
[i
];
606 if (pinfo
.window
&& !pinfo
.window
->GetParent())
614 // creates a floating frame for the windows
615 wxAuiFloatingFrame
* wxAuiManager::CreateFloatingFrame(wxWindow
* parent
,
616 const wxAuiPaneInfo
& pane_info
)
618 return new wxAuiFloatingFrame(parent
, this, pane_info
);
621 bool wxAuiManager::CanDockPanel(const wxAuiPaneInfo
& WXUNUSED(p
))
623 // if a key modifier is pressed while dragging the frame,
624 // don't dock the window
625 return !(wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
));
628 // GetPane() looks up a wxAuiPaneInfo structure based
629 // on the supplied window pointer. Upon failure, GetPane()
630 // returns an empty wxAuiPaneInfo, a condition which can be checked
631 // by calling wxAuiPaneInfo::IsOk().
633 // The pane info's structure may then be modified. Once a pane's
634 // info is modified, wxAuiManager::Update() must be called to
635 // realize the changes in the UI.
637 wxAuiPaneInfo
& wxAuiManager::GetPane(wxWindow
* window
)
640 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
642 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
643 if (p
.window
== window
)
646 return wxAuiNullPaneInfo
;
649 // this version of GetPane() looks up a pane based on a
650 // 'pane name', see above comment for more info
651 wxAuiPaneInfo
& wxAuiManager::GetPane(const wxString
& name
)
654 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
656 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
660 return wxAuiNullPaneInfo
;
663 // GetAllPanes() returns a reference to all the pane info structures
664 wxAuiPaneInfoArray
& wxAuiManager::GetAllPanes()
669 // HitTest() is an internal function which determines
670 // which UI item the specified coordinates are over
671 // (x,y) specify a position in client coordinates
672 wxAuiDockUIPart
* wxAuiManager::HitTest(int x
, int y
)
674 wxAuiDockUIPart
* result
= NULL
;
677 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
679 wxAuiDockUIPart
* item
= &m_uiparts
.Item(i
);
681 // we are not interested in typeDock, because this space
682 // isn't used to draw anything, just for measurements;
683 // besides, the entire dock area is covered with other
684 // rectangles, which we are interested in.
685 if (item
->type
== wxAuiDockUIPart::typeDock
)
688 // if we already have a hit on a more specific item, we are not
689 // interested in a pane hit. If, however, we don't already have
690 // a hit, returning a pane hit is necessary for some operations
691 if ((item
->type
== wxAuiDockUIPart::typePane
||
692 item
->type
== wxAuiDockUIPart::typePaneBorder
) && result
)
695 // if the point is inside the rectangle, we have a hit
696 if (item
->rect
.Contains(x
,y
))
704 // SetFlags() and GetFlags() allow the owner to set various
705 // options which are global to wxAuiManager
706 void wxAuiManager::SetFlags(unsigned int flags
)
708 // find out if we have to call UpdateHintWindowConfig()
709 bool update_hint_wnd
= false;
710 unsigned int hint_mask
= wxAUI_MGR_TRANSPARENT_HINT
|
711 wxAUI_MGR_VENETIAN_BLINDS_HINT
|
712 wxAUI_MGR_RECTANGLE_HINT
;
713 if ((flags
& hint_mask
) != (m_flags
& hint_mask
))
714 update_hint_wnd
= true;
722 UpdateHintWindowConfig();
726 unsigned int wxAuiManager::GetFlags() const
732 // don't use these anymore as they are deprecated
733 // use Set/GetManagedFrame() instead
734 void wxAuiManager::SetFrame(wxFrame
* frame
)
736 SetManagedWindow((wxWindow
*)frame
);
739 wxFrame
* wxAuiManager::GetFrame() const
741 return (wxFrame
*)m_frame
;
745 // this function will return the aui manager for a given
746 // window. The |window| parameter should be any child window
747 // or grand-child window (and so on) of the frame/window
748 // managed by wxAuiManager. The |window| parameter does not
749 // need to be managed by the manager itself.
750 wxAuiManager
* wxAuiManager::GetManager(wxWindow
* window
)
752 wxAuiManagerEvent
evt(wxEVT_AUI_FIND_MANAGER
);
753 evt
.SetManager(NULL
);
754 evt
.ResumePropagation(wxEVENT_PROPAGATE_MAX
);
755 if (!window
->ProcessEvent(evt
))
758 return evt
.GetManager();
762 void wxAuiManager::UpdateHintWindowConfig()
764 // find out if the the system can do transparent frames
765 bool can_do_transparent
= false;
767 wxWindow
* w
= m_frame
;
770 if (w
->IsKindOf(CLASSINFO(wxFrame
)))
772 wxFrame
* f
= static_cast<wxFrame
*>(w
);
773 can_do_transparent
= f
->CanSetTransparent();
780 // if there is an existing hint window, delete it
783 m_hint_wnd
->Destroy();
790 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) && can_do_transparent
)
792 // Make a window to use for a transparent hint
793 #if defined(__WXMSW__) || defined(__WXGTK__)
794 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
,
795 wxDefaultPosition
, wxSize(1,1),
796 wxFRAME_TOOL_WINDOW
|
797 wxFRAME_FLOAT_ON_PARENT
|
801 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
802 #elif defined(__WXMAC__)
803 // Using a miniframe with float and tool styles keeps the parent
804 // frame activated and highlighted as such...
805 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
,
806 wxDefaultPosition
, wxSize(1,1),
807 wxFRAME_FLOAT_ON_PARENT
808 | wxFRAME_TOOL_WINDOW
);
810 // Can't set the bg colour of a Frame in wxMac
811 wxPanel
* p
= new wxPanel(m_hint_wnd
);
813 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
814 // color that is really hard to see, especially transparent.
815 // Until a better system color is decided upon we'll just use
817 p
->SetBackgroundColour(*wxBLUE
);
823 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 ||
824 (m_flags
& wxAUI_MGR_VENETIAN_BLINDS_HINT
) != 0)
826 // system can't support transparent fade, or the venetian
827 // blinds effect was explicitly requested
828 m_hint_wnd
= new wxPseudoTransparentFrame(m_frame
,
833 wxFRAME_TOOL_WINDOW
|
834 wxFRAME_FLOAT_ON_PARENT
|
837 m_hint_fademax
= 128;
843 // SetManagedWindow() is usually called once when the frame
844 // manager class is being initialized. "frame" specifies
845 // the frame which should be managed by the frame mananger
846 void wxAuiManager::SetManagedWindow(wxWindow
* wnd
)
848 wxASSERT_MSG(wnd
, wxT("specified window must be non-NULL"));
851 m_frame
->PushEventHandler(this);
854 // if the owner is going to manage an MDI parent frame,
855 // we need to add the MDI client window as the default
858 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
860 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)m_frame
;
861 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
863 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
865 AddPane(client_window
,
866 wxAuiPaneInfo().Name(wxT("mdiclient")).
867 CenterPane().PaneBorder(false));
869 else if (m_frame
->IsKindOf(CLASSINFO(wxAuiMDIParentFrame
)))
871 wxAuiMDIParentFrame
* mdi_frame
= (wxAuiMDIParentFrame
*)m_frame
;
872 wxAuiMDIClientWindow
* client_window
= mdi_frame
->GetClientWindow();
873 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
875 AddPane(client_window
,
876 wxAuiPaneInfo().Name(wxT("mdiclient")).
877 CenterPane().PaneBorder(false));
882 UpdateHintWindowConfig();
886 // UnInit() must be called, usually in the destructor
887 // of the frame class. If it is not called, usually this
888 // will result in a crash upon program exit
889 void wxAuiManager::UnInit()
893 m_frame
->RemoveEventHandler(this);
897 // GetManagedWindow() returns the window pointer being managed
898 wxWindow
* wxAuiManager::GetManagedWindow() const
903 wxAuiDockArt
* wxAuiManager::GetArtProvider() const
908 void wxAuiManager::ProcessMgrEvent(wxAuiManagerEvent
& event
)
910 // first, give the owner frame a chance to override
913 if (m_frame
->ProcessEvent(event
))
920 // SetArtProvider() instructs wxAuiManager to use the
921 // specified art provider for all drawing calls. This allows
922 // plugable look-and-feel features. The pointer that is
923 // passed to this method subsequently belongs to wxAuiManager,
924 // and is deleted in the frame manager destructor
925 void wxAuiManager::SetArtProvider(wxAuiDockArt
* art_provider
)
927 // delete the last art provider, if any
930 // assign the new art provider
931 m_art
= art_provider
;
935 bool wxAuiManager::AddPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
)
937 // check if the pane has a valid window
941 // check if the window is already managed by us
942 if (GetPane(pane_info
.window
).IsOk())
945 // check if the pane name already exists, this could reveal a
946 // bug in the library user's application
947 bool already_exists
= false;
948 if (!pane_info
.name
.empty() && GetPane(pane_info
.name
).IsOk())
950 wxFAIL_MSG(wxT("A pane with that name already exists in the manager!"));
951 already_exists
= true;
954 // if the new pane is docked then we should undo maximize
955 if (pane_info
.IsDocked())
956 RestoreMaximizedPane();
958 m_panes
.Add(pane_info
);
960 wxAuiPaneInfo
& pinfo
= m_panes
.Last();
962 // set the pane window
963 pinfo
.window
= window
;
966 // if the pane's name identifier is blank, create a random string
967 if (pinfo
.name
.empty() || already_exists
)
969 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
970 ((unsigned long)pinfo
.window
) & 0xffffffff,
971 (unsigned int)time(NULL
),
973 (unsigned int)GetTickCount(),
975 (unsigned int)clock(),
977 (unsigned long)m_panes
.GetCount());
980 // set initial proportion (if not already set)
981 if (pinfo
.dock_proportion
== 0)
982 pinfo
.dock_proportion
= 100000;
984 if (pinfo
.HasMaximizeButton())
986 wxAuiPaneButton button
;
987 button
.button_id
= wxAUI_BUTTON_MAXIMIZE_RESTORE
;
988 pinfo
.buttons
.Add(button
);
991 if (pinfo
.HasPinButton())
993 wxAuiPaneButton button
;
994 button
.button_id
= wxAUI_BUTTON_PIN
;
995 pinfo
.buttons
.Add(button
);
998 if (pinfo
.HasCloseButton())
1000 wxAuiPaneButton button
;
1001 button
.button_id
= wxAUI_BUTTON_CLOSE
;
1002 pinfo
.buttons
.Add(button
);
1005 if (pinfo
.best_size
== wxDefaultSize
&&
1008 pinfo
.best_size
= pinfo
.window
->GetClientSize();
1010 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
1012 // GetClientSize() doesn't get the best size for
1013 // a toolbar under some newer versions of wxWidgets,
1014 // so use GetBestSize()
1015 pinfo
.best_size
= pinfo
.window
->GetBestSize();
1017 // for some reason, wxToolBar::GetBestSize() is returning
1018 // a size that is a pixel shy of the correct amount.
1019 // I believe this to be the correct action, until
1020 // wxToolBar::GetBestSize() is fixed. Is this assumption
1022 // commented out by JACS 2007-9-08 after having added a pixel in wxMSW's wxToolBar::DoGetBestSize()
1023 // pinfo.best_size.y++;
1026 if (pinfo
.min_size
!= wxDefaultSize
)
1028 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
1029 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
1030 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
1031 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
1038 bool wxAuiManager::AddPane(wxWindow
* window
,
1040 const wxString
& caption
)
1042 wxAuiPaneInfo pinfo
;
1043 pinfo
.Caption(caption
);
1046 case wxTOP
: pinfo
.Top(); break;
1047 case wxBOTTOM
: pinfo
.Bottom(); break;
1048 case wxLEFT
: pinfo
.Left(); break;
1049 case wxRIGHT
: pinfo
.Right(); break;
1050 case wxCENTER
: pinfo
.CenterPane(); break;
1052 return AddPane(window
, pinfo
);
1055 bool wxAuiManager::AddPane(wxWindow
* window
,
1056 const wxAuiPaneInfo
& pane_info
,
1057 const wxPoint
& drop_pos
)
1059 if (!AddPane(window
, pane_info
))
1062 wxAuiPaneInfo
& pane
= GetPane(window
);
1064 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
1069 bool wxAuiManager::InsertPane(wxWindow
* window
, const wxAuiPaneInfo
& pane_info
,
1072 // shift the panes around, depending on the insert level
1073 switch (insert_level
)
1075 case wxAUI_INSERT_PANE
:
1076 DoInsertPane(m_panes
,
1077 pane_info
.dock_direction
,
1078 pane_info
.dock_layer
,
1080 pane_info
.dock_pos
);
1082 case wxAUI_INSERT_ROW
:
1083 DoInsertDockRow(m_panes
,
1084 pane_info
.dock_direction
,
1085 pane_info
.dock_layer
,
1086 pane_info
.dock_row
);
1088 case wxAUI_INSERT_DOCK
:
1089 DoInsertDockLayer(m_panes
,
1090 pane_info
.dock_direction
,
1091 pane_info
.dock_layer
);
1095 // if the window already exists, we are basically just moving/inserting the
1096 // existing window. If it doesn't exist, we need to add it and insert it
1097 wxAuiPaneInfo
& existing_pane
= GetPane(window
);
1098 if (!existing_pane
.IsOk())
1100 return AddPane(window
, pane_info
);
1104 if (pane_info
.IsFloating())
1106 existing_pane
.Float();
1107 if (pane_info
.floating_pos
!= wxDefaultPosition
)
1108 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
1109 if (pane_info
.floating_size
!= wxDefaultSize
)
1110 existing_pane
.FloatingSize(pane_info
.floating_size
);
1114 // if the new pane is docked then we should undo maximize
1115 RestoreMaximizedPane();
1117 existing_pane
.Direction(pane_info
.dock_direction
);
1118 existing_pane
.Layer(pane_info
.dock_layer
);
1119 existing_pane
.Row(pane_info
.dock_row
);
1120 existing_pane
.Position(pane_info
.dock_pos
);
1128 // DetachPane() removes a pane from the frame manager. This
1129 // method will not destroy the window that is removed.
1130 bool wxAuiManager::DetachPane(wxWindow
* window
)
1133 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
1135 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1136 if (p
.window
== window
)
1140 // we have a floating frame which is being detached. We need to
1141 // reparent it to m_frame and destroy the floating frame
1144 p
.window
->SetSize(1,1);
1146 if (p
.frame
->IsShown())
1147 p
.frame
->Show(false);
1149 // reparent to m_frame and destroy the pane
1150 if (m_action_window
== p
.frame
)
1152 m_action_window
= NULL
;
1155 p
.window
->Reparent(m_frame
);
1156 p
.frame
->SetSizer(NULL
);
1161 // make sure there are no references to this pane in our uiparts,
1162 // just in case the caller doesn't call Update() immediately after
1163 // the DetachPane() call. This prevets obscure crashes which would
1164 // happen at window repaint if the caller forgets to call Update()
1166 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
1168 wxAuiDockUIPart
& part
= m_uiparts
.Item(pi
);
1169 if (part
.pane
== &p
)
1171 m_uiparts
.RemoveAt(pi
);
1178 m_panes
.RemoveAt(i
);
1185 // ClosePane() destroys or hides the pane depending on its flags
1186 void wxAuiManager::ClosePane(wxAuiPaneInfo
& pane_info
)
1188 // if we were maximized, restore
1189 if (pane_info
.IsMaximized())
1191 RestorePane(pane_info
);
1194 // first, hide the window
1195 if (pane_info
.window
&& pane_info
.window
->IsShown())
1197 pane_info
.window
->Show(false);
1200 // make sure that we are the parent of this window
1201 if (pane_info
.window
&& pane_info
.window
->GetParent() != m_frame
)
1203 pane_info
.window
->Reparent(m_frame
);
1206 // if we have a frame, destroy it
1207 if (pane_info
.frame
)
1209 pane_info
.frame
->Destroy();
1210 pane_info
.frame
= NULL
;
1213 // now we need to either destroy or hide the pane
1214 if (pane_info
.IsDestroyOnClose())
1216 wxWindow
* window
= pane_info
.window
;
1229 void wxAuiManager::MaximizePane(wxAuiPaneInfo
& pane_info
)
1233 // un-maximize and hide all other panes
1234 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1236 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1241 // save hidden state
1242 p
.SetFlag(wxAuiPaneInfo::savedHiddenState
,
1243 p
.HasFlag(wxAuiPaneInfo::optionHidden
));
1245 // hide the pane, because only the newly
1246 // maximized pane should show
1251 // mark ourselves maximized
1252 pane_info
.Maximize();
1254 m_has_maximized
= true;
1256 // last, show the window
1257 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1259 pane_info
.window
->Show(true);
1263 void wxAuiManager::RestorePane(wxAuiPaneInfo
& pane_info
)
1267 // restore all the panes
1268 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1270 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1273 p
.SetFlag(wxAuiPaneInfo::optionHidden
,
1274 p
.HasFlag(wxAuiPaneInfo::savedHiddenState
));
1278 // mark ourselves non-maximized
1279 pane_info
.Restore();
1280 m_has_maximized
= false;
1282 // last, show the window
1283 if (pane_info
.window
&& !pane_info
.window
->IsShown())
1285 pane_info
.window
->Show(true);
1289 void wxAuiManager::RestoreMaximizedPane()
1293 // restore all the panes
1294 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
1296 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
1297 if (p
.IsMaximized())
1305 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
1306 // in the input string. This is an internal functions which is
1307 // used for saving perspectives
1308 static wxString
EscapeDelimiters(const wxString
& s
)
1311 result
.Alloc(s
.length());
1312 const wxChar
* ch
= s
.c_str();
1315 if (*ch
== wxT(';') || *ch
== wxT('|'))
1316 result
+= wxT('\\');
1323 wxString
wxAuiManager::SavePaneInfo(wxAuiPaneInfo
& pane
)
1325 wxString result
= wxT("name=");
1326 result
+= EscapeDelimiters(pane
.name
);
1329 result
+= wxT("caption=");
1330 result
+= EscapeDelimiters(pane
.caption
);
1333 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
1334 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
1335 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
1336 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
1337 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
1338 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
1339 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
1340 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
1341 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
1342 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
1343 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
1344 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
1345 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
1346 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
1347 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
1348 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
1353 // Load a "pane" with the pane infor settings in pane_part
1354 void wxAuiManager::LoadPaneInfo(wxString pane_part
, wxAuiPaneInfo
&pane
)
1356 // replace escaped characters so we can
1357 // split up the string easily
1358 pane_part
.Replace(wxT("\\|"), wxT("\a"));
1359 pane_part
.Replace(wxT("\\;"), wxT("\b"));
1363 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
1364 pane_part
= pane_part
.AfterFirst(wxT(';'));
1365 wxString val_name
= val_part
.BeforeFirst(wxT('='));
1366 wxString value
= val_part
.AfterFirst(wxT('='));
1367 val_name
.MakeLower();
1368 val_name
.Trim(true);
1369 val_name
.Trim(false);
1373 if (val_name
.empty())
1376 if (val_name
== wxT("name"))
1378 else if (val_name
== wxT("caption"))
1379 pane
.caption
= value
;
1380 else if (val_name
== wxT("state"))
1381 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1382 else if (val_name
== wxT("dir"))
1383 pane
.dock_direction
= wxAtoi(value
.c_str());
1384 else if (val_name
== wxT("layer"))
1385 pane
.dock_layer
= wxAtoi(value
.c_str());
1386 else if (val_name
== wxT("row"))
1387 pane
.dock_row
= wxAtoi(value
.c_str());
1388 else if (val_name
== wxT("pos"))
1389 pane
.dock_pos
= wxAtoi(value
.c_str());
1390 else if (val_name
== wxT("prop"))
1391 pane
.dock_proportion
= wxAtoi(value
.c_str());
1392 else if (val_name
== wxT("bestw"))
1393 pane
.best_size
.x
= wxAtoi(value
.c_str());
1394 else if (val_name
== wxT("besth"))
1395 pane
.best_size
.y
= wxAtoi(value
.c_str());
1396 else if (val_name
== wxT("minw"))
1397 pane
.min_size
.x
= wxAtoi(value
.c_str());
1398 else if (val_name
== wxT("minh"))
1399 pane
.min_size
.y
= wxAtoi(value
.c_str());
1400 else if (val_name
== wxT("maxw"))
1401 pane
.max_size
.x
= wxAtoi(value
.c_str());
1402 else if (val_name
== wxT("maxh"))
1403 pane
.max_size
.y
= wxAtoi(value
.c_str());
1404 else if (val_name
== wxT("floatx"))
1405 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1406 else if (val_name
== wxT("floaty"))
1407 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1408 else if (val_name
== wxT("floatw"))
1409 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1410 else if (val_name
== wxT("floath"))
1411 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1413 wxFAIL_MSG(wxT("Bad Perspective String"));
1417 // replace escaped characters so we can
1418 // split up the string easily
1419 pane
.name
.Replace(wxT("\a"), wxT("|"));
1420 pane
.name
.Replace(wxT("\b"), wxT(";"));
1421 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1422 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1423 pane_part
.Replace(wxT("\a"), wxT("|"));
1424 pane_part
.Replace(wxT("\b"), wxT(";"));
1430 // SavePerspective() saves all pane information as a single string.
1431 // This string may later be fed into LoadPerspective() to restore
1432 // all pane settings. This save and load mechanism allows an
1433 // exact pane configuration to be saved and restored at a later time
1435 wxString
wxAuiManager::SavePerspective()
1439 result
= wxT("layout2|");
1441 int pane_i
, pane_count
= m_panes
.GetCount();
1442 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1444 wxAuiPaneInfo
& pane
= m_panes
.Item(pane_i
);
1445 result
+= SavePaneInfo(pane
)+wxT("|");
1448 int dock_i
, dock_count
= m_docks
.GetCount();
1449 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1451 wxAuiDockInfo
& dock
= m_docks
.Item(dock_i
);
1453 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1454 dock
.dock_direction
, dock
.dock_layer
,
1455 dock
.dock_row
, dock
.size
);
1461 // LoadPerspective() loads a layout which was saved with SavePerspective()
1462 // If the "update" flag parameter is true, the GUI will immediately be updated
1464 bool wxAuiManager::LoadPerspective(const wxString
& layout
, bool update
)
1466 wxString input
= layout
;
1469 // check layout string version
1470 // 'layout1' = wxAUI 0.9.0 - wxAUI 0.9.2
1471 // 'layout2' = wxAUI 0.9.2 (wxWidgets 2.8)
1472 part
= input
.BeforeFirst(wxT('|'));
1473 input
= input
.AfterFirst(wxT('|'));
1476 if (part
!= wxT("layout2"))
1479 // mark all panes currently managed as docked and hidden
1480 int pane_i
, pane_count
= m_panes
.GetCount();
1481 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1482 m_panes
.Item(pane_i
).Dock().Hide();
1484 // clear out the dock array; this will be reconstructed
1487 // replace escaped characters so we can
1488 // split up the string easily
1489 input
.Replace(wxT("\\|"), wxT("\a"));
1490 input
.Replace(wxT("\\;"), wxT("\b"));
1496 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1497 input
= input
.AfterFirst(wxT('|'));
1498 pane_part
.Trim(true);
1500 // if the string is empty, we're done parsing
1501 if (pane_part
.empty())
1504 if (pane_part
.Left(9) == wxT("dock_size"))
1506 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1507 wxString value
= pane_part
.AfterFirst(wxT('='));
1509 long dir
, layer
, row
, size
;
1510 wxString piece
= val_name
.AfterFirst(wxT('('));
1511 piece
= piece
.BeforeLast(wxT(')'));
1512 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1513 piece
= piece
.AfterFirst(wxT(','));
1514 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1515 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1516 value
.ToLong(&size
);
1519 dock
.dock_direction
= dir
;
1520 dock
.dock_layer
= layer
;
1521 dock
.dock_row
= row
;
1527 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1528 // name so it can be called by external callers
1529 pane_part
.Replace(wxT("\a"), wxT("|"));
1530 pane_part
.Replace(wxT("\b"), wxT(";"));
1532 LoadPaneInfo(pane_part
, pane
);
1534 wxAuiPaneInfo
& p
= GetPane(pane
.name
);
1537 // the pane window couldn't be found
1538 // in the existing layout -- skip it
1551 void wxAuiManager::GetPanePositionsAndSizes(wxAuiDockInfo
& dock
,
1552 wxArrayInt
& positions
,
1555 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1556 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1557 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1562 int offset
, action_pane
= -1;
1563 int pane_i
, pane_count
= dock
.panes
.GetCount();
1565 // find the pane marked as our action pane
1566 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1568 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1570 if (pane
.state
& wxAuiPaneInfo::actionPane
)
1572 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1573 action_pane
= pane_i
;
1577 // set up each panes default position, and
1578 // determine the size (width or height, depending
1579 // on the dock's orientation) of each pane
1580 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1582 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1583 positions
.Add(pane
.dock_pos
);
1586 if (pane
.HasBorder())
1587 size
+= (pane_border_size
*2);
1589 if (dock
.IsHorizontal())
1591 if (pane
.HasGripper() && !pane
.HasGripperTop())
1592 size
+= gripper_size
;
1593 size
+= pane
.best_size
.x
;
1597 if (pane
.HasGripper() && pane
.HasGripperTop())
1598 size
+= gripper_size
;
1600 if (pane
.HasCaption())
1601 size
+= caption_size
;
1602 size
+= pane
.best_size
.y
;
1608 // if there is no action pane, just return the default
1609 // positions (as specified in pane.pane_pos)
1610 if (action_pane
== -1)
1614 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1616 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1621 positions
[pane_i
] -= -amount
;
1623 offset
+= sizes
[pane_i
];
1626 // if the dock mode is fixed, make sure none of the panes
1627 // overlap; we will bump panes that overlap
1629 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1631 int amount
= positions
[pane_i
] - offset
;
1635 positions
[pane_i
] += -amount
;
1637 offset
+= sizes
[pane_i
];
1642 void wxAuiManager::LayoutAddPane(wxSizer
* cont
,
1643 wxAuiDockInfo
& dock
,
1644 wxAuiPaneInfo
& pane
,
1645 wxAuiDockUIPartArray
& uiparts
,
1648 wxAuiDockUIPart part
;
1649 wxSizerItem
* sizer_item
;
1651 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1652 int gripper_size
= m_art
->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE
);
1653 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1654 int pane_button_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BUTTON_SIZE
);
1656 // find out the orientation of the item (orientation for panes
1657 // is the same as the dock's orientation)
1659 if (dock
.IsHorizontal())
1660 orientation
= wxHORIZONTAL
;
1662 orientation
= wxVERTICAL
;
1664 // this variable will store the proportion
1665 // value that the pane will receive
1666 int pane_proportion
= pane
.dock_proportion
;
1668 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1669 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1671 if (pane
.HasGripper())
1673 if (pane
.HasGripperTop())
1674 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1676 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1678 part
.type
= wxAuiDockUIPart::typeGripper
;
1682 part
.orientation
= orientation
;
1683 part
.cont_sizer
= horz_pane_sizer
;
1684 part
.sizer_item
= sizer_item
;
1688 if (pane
.HasCaption())
1690 // create the caption sizer
1691 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1693 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1695 part
.type
= wxAuiDockUIPart::typeCaption
;
1699 part
.orientation
= orientation
;
1700 part
.cont_sizer
= vert_pane_sizer
;
1701 part
.sizer_item
= sizer_item
;
1702 int caption_part_idx
= uiparts
.GetCount();
1705 // add pane buttons to the caption
1706 int i
, button_count
;
1707 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1708 i
< button_count
; ++i
)
1710 wxAuiPaneButton
& button
= pane
.buttons
.Item(i
);
1712 sizer_item
= caption_sizer
->Add(pane_button_size
,
1716 part
.type
= wxAuiDockUIPart::typePaneButton
;
1719 part
.button
= &button
;
1720 part
.orientation
= orientation
;
1721 part
.cont_sizer
= caption_sizer
;
1722 part
.sizer_item
= sizer_item
;
1726 // if we have buttons, add a little space to the right
1727 // of them to ease visual crowding
1728 if (button_count
>= 1)
1730 caption_sizer
->Add(3,1);
1733 // add the caption sizer
1734 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1736 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1739 // add the pane window itself
1742 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1746 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1747 // Don't do this because it breaks the pane size in floating windows
1748 // BIW: Right now commenting this out is causing problems with
1749 // an mdi client window as the center pane.
1750 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1753 part
.type
= wxAuiDockUIPart::typePane
;
1757 part
.orientation
= orientation
;
1758 part
.cont_sizer
= vert_pane_sizer
;
1759 part
.sizer_item
= sizer_item
;
1763 // determine if the pane should have a minimum size; if the pane is
1764 // non-resizable (fixed) then we must set a minimum size. Alternatively,
1765 // if the pane.min_size is set, we must use that value as well
1767 wxSize min_size
= pane
.min_size
;
1770 if (min_size
== wxDefaultSize
)
1772 min_size
= pane
.best_size
;
1773 pane_proportion
= 0;
1777 if (min_size
!= wxDefaultSize
)
1779 vert_pane_sizer
->SetItemMinSize(
1780 vert_pane_sizer
->GetChildren().GetCount()-1,
1781 min_size
.x
, min_size
.y
);
1785 // add the verticle sizer (caption, pane window) to the
1786 // horizontal sizer (gripper, verticle sizer)
1787 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1789 // finally, add the pane sizer to the dock sizer
1791 if (pane
.HasBorder())
1793 // allowing space for the pane's border
1794 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1795 wxEXPAND
| wxALL
, pane_border_size
);
1797 part
.type
= wxAuiDockUIPart::typePaneBorder
;
1801 part
.orientation
= orientation
;
1802 part
.cont_sizer
= cont
;
1803 part
.sizer_item
= sizer_item
;
1808 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1812 void wxAuiManager::LayoutAddDock(wxSizer
* cont
,
1813 wxAuiDockInfo
& dock
,
1814 wxAuiDockUIPartArray
& uiparts
,
1817 wxSizerItem
* sizer_item
;
1818 wxAuiDockUIPart part
;
1820 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
1821 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1823 // resizable bottom and right docks have a sash before them
1824 if (!m_has_maximized
&& !dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1825 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1827 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1829 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1830 part
.orientation
= orientation
;
1834 part
.cont_sizer
= cont
;
1835 part
.sizer_item
= sizer_item
;
1839 // create the sizer for the dock
1840 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1842 // add each pane to the dock
1843 bool has_maximized_pane
= false;
1844 int pane_i
, pane_count
= dock
.panes
.GetCount();
1848 wxArrayInt pane_positions
, pane_sizes
;
1850 // figure out the real pane positions we will
1851 // use, without modifying the each pane's pane_pos member
1852 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1855 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1857 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1858 int pane_pos
= pane_positions
.Item(pane_i
);
1860 if (pane
.IsMaximized())
1861 has_maximized_pane
= true;
1864 int amount
= pane_pos
- offset
;
1867 if (dock
.IsVertical())
1868 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1870 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1872 part
.type
= wxAuiDockUIPart::typeBackground
;
1876 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1877 part
.cont_sizer
= dock_sizer
;
1878 part
.sizer_item
= sizer_item
;
1884 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1886 offset
+= pane_sizes
.Item(pane_i
);
1889 // at the end add a very small stretchable background area
1890 sizer_item
= dock_sizer
->Add(0,0, 1, wxEXPAND
);
1892 part
.type
= wxAuiDockUIPart::typeBackground
;
1896 part
.orientation
= orientation
;
1897 part
.cont_sizer
= dock_sizer
;
1898 part
.sizer_item
= sizer_item
;
1903 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1905 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1907 if (pane
.IsMaximized())
1908 has_maximized_pane
= true;
1910 // if this is not the first pane being added,
1911 // we need to add a pane sizer
1912 if (!m_has_maximized
&& pane_i
> 0)
1914 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1916 part
.type
= wxAuiDockUIPart::typePaneSizer
;
1918 part
.pane
= dock
.panes
.Item(pane_i
-1);
1920 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1921 part
.cont_sizer
= dock_sizer
;
1922 part
.sizer_item
= sizer_item
;
1926 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1930 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
|| has_maximized_pane
)
1931 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1933 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1935 part
.type
= wxAuiDockUIPart::typeDock
;
1939 part
.orientation
= orientation
;
1940 part
.cont_sizer
= cont
;
1941 part
.sizer_item
= sizer_item
;
1944 if (dock
.IsHorizontal())
1945 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1947 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1949 // top and left docks have a sash after them
1950 if (!m_has_maximized
&&
1952 (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1953 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1955 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1957 part
.type
= wxAuiDockUIPart::typeDockSizer
;
1961 part
.orientation
= orientation
;
1962 part
.cont_sizer
= cont
;
1963 part
.sizer_item
= sizer_item
;
1968 wxSizer
* wxAuiManager::LayoutAll(wxAuiPaneInfoArray
& panes
,
1969 wxAuiDockInfoArray
& docks
,
1970 wxAuiDockUIPartArray
& uiparts
,
1973 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1975 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
1976 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
1977 wxSize cli_size
= m_frame
->GetClientSize();
1978 int i
, dock_count
, pane_count
;
1981 // empty all docks out
1982 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1984 wxAuiDockInfo
& dock
= docks
.Item(i
);
1986 // empty out all panes, as they will be readded below
1991 // always reset fixed docks' sizes, because
1992 // the contained windows may have been resized
1998 // iterate through all known panes, filing each
1999 // of them into the appropriate dock. If the
2000 // pane does not exist in the dock, add it
2001 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2003 wxAuiPaneInfo
& p
= panes
.Item(i
);
2005 // find any docks with the same dock direction, dock layer, and
2006 // dock row as the pane we are working on
2007 wxAuiDockInfo
* dock
;
2008 wxAuiDockInfoPtrArray arr
;
2009 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
2011 if (arr
.GetCount() > 0)
2013 // found the right dock
2018 // dock was not found, so we need to create a new one
2020 d
.dock_direction
= p
.dock_direction
;
2021 d
.dock_layer
= p
.dock_layer
;
2022 d
.dock_row
= p
.dock_row
;
2024 dock
= &docks
.Last();
2028 if (p
.IsDocked() && p
.IsShown())
2030 // remove the pane from any existing docks except this one
2031 RemovePaneFromDocks(docks
, p
, dock
);
2033 // pane needs to be added to the dock,
2034 // if it doesn't already exist
2035 if (!FindPaneInDock(*dock
, p
.window
))
2036 dock
->panes
.Add(&p
);
2040 // remove the pane from any existing docks
2041 RemovePaneFromDocks(docks
, p
);
2046 // remove any empty docks
2047 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
2049 if (docks
.Item(i
).panes
.GetCount() == 0)
2053 // configure the docks further
2054 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2056 wxAuiDockInfo
& dock
= docks
.Item(i
);
2057 int j
, dock_pane_count
= dock
.panes
.GetCount();
2059 // sort the dock pane array by the pane's
2060 // dock position (dock_pos), in ascending order
2061 dock
.panes
.Sort(PaneSortFunc
);
2063 // for newly created docks, set up their initial size
2068 for (j
= 0; j
< dock_pane_count
; ++j
)
2070 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2071 wxSize pane_size
= pane
.best_size
;
2072 if (pane_size
== wxDefaultSize
)
2073 pane_size
= pane
.min_size
;
2074 if (pane_size
== wxDefaultSize
)
2075 pane_size
= pane
.window
->GetSize();
2077 if (dock
.IsHorizontal())
2078 size
= wxMax(pane_size
.y
, size
);
2080 size
= wxMax(pane_size
.x
, size
);
2083 // add space for the border (two times), but only
2084 // if at least one pane inside the dock has a pane border
2085 for (j
= 0; j
< dock_pane_count
; ++j
)
2087 if (dock
.panes
.Item(j
)->HasBorder())
2089 size
+= (pane_border_size
*2);
2094 // if pane is on the top or bottom, add the caption height,
2095 // but only if at least one pane inside the dock has a caption
2096 if (dock
.IsHorizontal())
2098 for (j
= 0; j
< dock_pane_count
; ++j
)
2100 if (dock
.panes
.Item(j
)->HasCaption())
2102 size
+= caption_size
;
2109 // new dock's size may not be more than the dock constraint
2110 // parameter specifies. See SetDockSizeConstraint()
2112 int max_dock_x_size
= (int)(m_dock_constraint_x
* ((double)cli_size
.x
));
2113 int max_dock_y_size
= (int)(m_dock_constraint_y
* ((double)cli_size
.y
));
2115 if (dock
.IsHorizontal())
2116 size
= wxMin(size
, max_dock_y_size
);
2118 size
= wxMin(size
, max_dock_x_size
);
2120 // absolute minimum size for a dock is 10 pixels
2128 // determine the dock's minimum size
2129 bool plus_border
= false;
2130 bool plus_caption
= false;
2131 int dock_min_size
= 0;
2132 for (j
= 0; j
< dock_pane_count
; ++j
)
2134 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2135 if (pane
.min_size
!= wxDefaultSize
)
2137 if (pane
.HasBorder())
2139 if (pane
.HasCaption())
2140 plus_caption
= true;
2141 if (dock
.IsHorizontal())
2143 if (pane
.min_size
.y
> dock_min_size
)
2144 dock_min_size
= pane
.min_size
.y
;
2148 if (pane
.min_size
.x
> dock_min_size
)
2149 dock_min_size
= pane
.min_size
.x
;
2155 dock_min_size
+= (pane_border_size
*2);
2156 if (plus_caption
&& dock
.IsHorizontal())
2157 dock_min_size
+= (caption_size
);
2159 dock
.min_size
= dock_min_size
;
2162 // if the pane's current size is less than it's
2163 // minimum, increase the dock's size to it's minimum
2164 if (dock
.size
< dock
.min_size
)
2165 dock
.size
= dock
.min_size
;
2168 // determine the dock's mode (fixed or proportional);
2169 // determine whether the dock has only toolbars
2170 bool action_pane_marked
= false;
2172 dock
.toolbar
= true;
2173 for (j
= 0; j
< dock_pane_count
; ++j
)
2175 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2176 if (!pane
.IsFixed())
2178 if (!pane
.IsToolbar())
2179 dock
.toolbar
= false;
2180 if (pane
.HasFlag(wxAuiPaneInfo::optionDockFixed
))
2182 if (pane
.state
& wxAuiPaneInfo::actionPane
)
2183 action_pane_marked
= true;
2187 // if the dock mode is proportional and not fixed-pixel,
2188 // reassign the dock_pos to the sequential 0, 1, 2, 3;
2189 // e.g. remove gaps like 1, 2, 30, 500
2192 for (j
= 0; j
< dock_pane_count
; ++j
)
2194 wxAuiPaneInfo
& pane
= *dock
.panes
.Item(j
);
2199 // if the dock mode is fixed, and none of the panes
2200 // are being moved right now, make sure the panes
2201 // do not overlap each other. If they do, we will
2202 // adjust the positions of the panes
2203 if (dock
.fixed
&& !action_pane_marked
)
2205 wxArrayInt pane_positions
, pane_sizes
;
2206 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
2209 for (j
= 0; j
< dock_pane_count
; ++j
)
2211 wxAuiPaneInfo
& pane
= *(dock
.panes
.Item(j
));
2212 pane
.dock_pos
= pane_positions
[j
];
2214 int amount
= pane
.dock_pos
- offset
;
2218 pane
.dock_pos
+= -amount
;
2220 offset
+= pane_sizes
[j
];
2225 // discover the maximum dock layer
2227 for (i
= 0; i
< dock_count
; ++i
)
2228 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
2231 // clear out uiparts
2234 // create a bunch of box sizers,
2235 // from the innermost level outwards.
2236 wxSizer
* cont
= NULL
;
2237 wxSizer
* middle
= NULL
;
2241 for (layer
= 0; layer
<= max_layer
; ++layer
)
2243 wxAuiDockInfoPtrArray arr
;
2245 // find any docks in this layer
2246 FindDocks(docks
, -1, layer
, -1, arr
);
2248 // if there aren't any, skip to the next layer
2252 wxSizer
* old_cont
= cont
;
2254 // create a container which will hold this layer's
2255 // docks (top, bottom, left, right)
2256 cont
= new wxBoxSizer(wxVERTICAL
);
2259 // find any top docks in this layer
2260 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
2263 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2264 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2268 // fill out the middle layer (which consists
2269 // of left docks, content area and right docks)
2271 middle
= new wxBoxSizer(wxHORIZONTAL
);
2273 // find any left docks in this layer
2274 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
2277 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
2278 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2281 // add content dock (or previous layer's sizer
2285 // find any center docks
2286 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
2289 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
2290 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2292 else if (!m_has_maximized
)
2294 // there are no center docks, add a background area
2295 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
2296 wxAuiDockUIPart part
;
2297 part
.type
= wxAuiDockUIPart::typeBackground
;
2301 part
.cont_sizer
= middle
;
2302 part
.sizer_item
= sizer_item
;
2308 middle
->Add(old_cont
, 1, wxEXPAND
);
2311 // find any right docks in this layer
2312 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
2315 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2316 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2319 cont
->Add(middle
, 1, wxEXPAND
);
2323 // find any bottom docks in this layer
2324 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
2327 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2328 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2335 // no sizer available, because there are no docks,
2336 // therefore we will create a simple background area
2337 cont
= new wxBoxSizer(wxVERTICAL
);
2338 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
2339 wxAuiDockUIPart part
;
2340 part
.type
= wxAuiDockUIPart::typeBackground
;
2344 part
.cont_sizer
= middle
;
2345 part
.sizer_item
= sizer_item
;
2349 container
->Add(cont
, 1, wxEXPAND
);
2354 // SetDockSizeConstraint() allows the dock constraints to be set. For example,
2355 // specifying values of 0.5, 0.5 will mean that upon dock creation, a dock may
2356 // not be larger than half of the window's size
2358 void wxAuiManager::SetDockSizeConstraint(double width_pct
, double height_pct
)
2360 m_dock_constraint_x
= wxMax(0.0, wxMin(1.0, width_pct
));
2361 m_dock_constraint_y
= wxMax(0.0, wxMin(1.0, height_pct
));
2364 void wxAuiManager::GetDockSizeConstraint(double* width_pct
, double* height_pct
) const
2367 *width_pct
= m_dock_constraint_x
;
2370 *height_pct
= m_dock_constraint_y
;
2375 // Update() updates the layout. Whenever changes are made to
2376 // one or more panes, this function should be called. It is the
2377 // external entry point for running the layout engine.
2379 void wxAuiManager::Update()
2381 m_hover_button
= NULL
;
2384 int i
, pane_count
= m_panes
.GetCount();
2387 // destroy floating panes which have been
2388 // redocked or are becoming non-floating
2389 for (i
= 0; i
< pane_count
; ++i
)
2391 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2393 if (!p
.IsFloating() && p
.frame
)
2395 // because the pane is no longer in a floating, we need to
2396 // reparent it to m_frame and destroy the floating frame
2399 p
.window
->SetSize(1,1);
2402 // the following block is a workaround for bug #1531361
2403 // (see wxWidgets sourceforge page). On wxGTK (only), when
2404 // a frame is shown/hidden, a move event unfortunately
2405 // also gets fired. Because we may be dragging around
2406 // a pane, we need to cancel that action here to prevent
2407 // a spurious crash.
2408 if (m_action_window
== p
.frame
)
2410 if (wxWindow::GetCapture() == m_frame
)
2411 m_frame
->ReleaseMouse();
2412 m_action
= actionNone
;
2413 m_action_window
= NULL
;
2417 if (p
.frame
->IsShown())
2418 p
.frame
->Show(false);
2420 // reparent to m_frame and destroy the pane
2421 if (m_action_window
== p
.frame
)
2423 m_action_window
= NULL
;
2426 p
.window
->Reparent(m_frame
);
2427 p
.frame
->SetSizer(NULL
);
2434 // delete old sizer first
2435 m_frame
->SetSizer(NULL
);
2437 // create a layout for all of the panes
2438 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
2440 // hide or show panes as necessary,
2441 // and float panes as necessary
2442 for (i
= 0; i
< pane_count
; ++i
)
2444 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2448 if (p
.frame
== NULL
)
2450 // we need to create a frame for this
2451 // pane, which has recently been floated
2452 wxAuiFloatingFrame
* frame
= CreateFloatingFrame(m_frame
, p
);
2454 // on MSW and Mac, if the owner desires transparent dragging, and
2455 // the dragging is happening right now, then the floating
2456 // window should have this style by default
2457 if (m_action
== actionDragFloatingPane
&&
2458 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2459 frame
->SetTransparent(150);
2461 frame
->SetPaneWindow(p
);
2464 if (p
.IsShown() && !frame
->IsShown())
2469 // frame already exists, make sure it's position
2470 // and size reflect the information in wxAuiPaneInfo
2471 if ((p
.frame
->GetPosition() != p
.floating_pos
) || (p
.frame
->GetSize() != p
.floating_size
))
2473 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2474 p
.floating_size
.x
, p
.floating_size
.y
,
2475 wxSIZE_USE_EXISTING
);
2477 p.frame->SetSize(p.floating_pos.x, p.floating_pos.y,
2478 wxDefaultCoord, wxDefaultCoord,
2479 wxSIZE_USE_EXISTING);
2480 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2484 if (p
.frame
->IsShown() != p
.IsShown())
2485 p
.frame
->Show(p
.IsShown());
2490 if (p
.window
->IsShown() != p
.IsShown())
2491 p
.window
->Show(p
.IsShown());
2494 // if "active panes" are no longer allowed, clear
2495 // any optionActive values from the pane states
2496 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2498 p
.state
&= ~wxAuiPaneInfo::optionActive
;
2503 // keep track of the old window rectangles so we can
2504 // refresh those windows whose rect has changed
2505 wxAuiRectArray old_pane_rects
;
2506 for (i
= 0; i
< pane_count
; ++i
)
2509 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2511 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2514 old_pane_rects
.Add(r
);
2520 // apply the new sizer
2521 m_frame
->SetSizer(sizer
);
2522 m_frame
->SetAutoLayout(false);
2527 // now that the frame layout is done, we need to check
2528 // the new pane rectangles against the old rectangles that
2529 // we saved a few lines above here. If the rectangles have
2530 // changed, the corresponding panes must also be updated
2531 for (i
= 0; i
< pane_count
; ++i
)
2533 wxAuiPaneInfo
& p
= m_panes
.Item(i
);
2534 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2536 if (p
.rect
!= old_pane_rects
[i
])
2538 p
.window
->Refresh();
2547 // set frame's minimum size
2550 // N.B. More work needs to be done on frame minimum sizes;
2551 // this is some intresting code that imposes the minimum size,
2552 // but we may want to include a more flexible mechanism or
2553 // options for multiple minimum-size modes, e.g. strict or lax
2554 wxSize min_size = sizer->GetMinSize();
2555 wxSize frame_size = m_frame->GetSize();
2556 wxSize client_size = m_frame->GetClientSize();
2558 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2559 min_size.y+frame_size.y-client_size.y );
2561 m_frame->SetMinSize(minframe_size);
2563 if (frame_size.x < minframe_size.x ||
2564 frame_size.y < minframe_size.y)
2565 sizer->Fit(m_frame);
2570 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2571 // on the frame's main sizer, then measures all the various UI items
2572 // and updates their internal rectangles. This should always be called
2573 // instead of calling m_frame->Layout() directly
2575 void wxAuiManager::DoFrameLayout()
2580 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2582 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2584 // get the rectangle of the UI part
2585 // originally, this code looked like this:
2586 // part.rect = wxRect(part.sizer_item->GetPosition(),
2587 // part.sizer_item->GetSize());
2588 // this worked quite well, with one exception: the mdi
2589 // client window had a "deferred" size variable
2590 // that returned the wrong size. It looks like
2591 // a bug in wx, because the former size of the window
2592 // was being returned. So, we will retrieve the part's
2593 // rectangle via other means
2596 part
.rect
= part
.sizer_item
->GetRect();
2597 int flag
= part
.sizer_item
->GetFlag();
2598 int border
= part
.sizer_item
->GetBorder();
2601 part
.rect
.y
-= border
;
2602 part
.rect
.height
+= border
;
2606 part
.rect
.x
-= border
;
2607 part
.rect
.width
+= border
;
2609 if (flag
& wxBOTTOM
)
2610 part
.rect
.height
+= border
;
2612 part
.rect
.width
+= border
;
2615 if (part
.type
== wxAuiDockUIPart::typeDock
)
2616 part
.dock
->rect
= part
.rect
;
2617 if (part
.type
== wxAuiDockUIPart::typePane
)
2618 part
.pane
->rect
= part
.rect
;
2622 // GetPanePart() looks up the pane the pane border UI part (or the regular
2623 // pane part if there is no border). This allows the caller to get the exact
2624 // rectangle of the pane in question, including decorations like
2625 // caption and border (if any).
2627 wxAuiDockUIPart
* wxAuiManager::GetPanePart(wxWindow
* wnd
)
2630 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2632 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2633 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
2634 part
.pane
&& part
.pane
->window
== wnd
)
2637 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2639 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
2640 if (part
.type
== wxAuiDockUIPart::typePane
&&
2641 part
.pane
&& part
.pane
->window
== wnd
)
2649 // GetDockPixelOffset() is an internal function which returns
2650 // a dock's offset in pixels from the left side of the window
2651 // (for horizontal docks) or from the top of the window (for
2652 // vertical docks). This value is necessary for calculating
2653 // fixel-pane/toolbar offsets when they are dragged.
2655 int wxAuiManager::GetDockPixelOffset(wxAuiPaneInfo
& test
)
2657 // the only way to accurately calculate the dock's
2658 // offset is to actually run a theoretical layout
2660 int i
, part_count
, dock_count
;
2661 wxAuiDockInfoArray docks
;
2662 wxAuiPaneInfoArray panes
;
2663 wxAuiDockUIPartArray uiparts
;
2664 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2667 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2668 wxSize client_size
= m_frame
->GetClientSize();
2669 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2672 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2674 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
2675 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2676 part
.sizer_item
->GetSize());
2677 if (part
.type
== wxAuiDockUIPart::typeDock
)
2678 part
.dock
->rect
= part
.rect
;
2683 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2685 wxAuiDockInfo
& dock
= docks
.Item(i
);
2686 if (test
.dock_direction
== dock
.dock_direction
&&
2687 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2689 if (dock
.IsVertical())
2701 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2702 // if a dock operation is allowed, the new dock position is copied into
2703 // the target info. If the operation was allowed, the function returns true.
2705 bool wxAuiManager::ProcessDockResult(wxAuiPaneInfo
& target
,
2706 const wxAuiPaneInfo
& new_pos
)
2708 bool allowed
= false;
2709 switch (new_pos
.dock_direction
)
2711 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2712 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2713 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2714 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2724 // DoDrop() is an important function. It basically takes a mouse position,
2725 // and determines where the pane's new position would be. If the pane is to be
2726 // dropped, it performs the drop operation using the specified dock and pane
2727 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2728 // scenario can be performed, giving precise coordinates for drop hints.
2729 // If, however, wxAuiManager:m_docks and wxAuiManager::m_panes are specified
2730 // as parameters, the changes will be made to the main state arrays
2732 const int auiInsertRowPixels
= 10;
2733 const int auiNewRowPixels
= 40;
2734 const int auiLayerInsertPixels
= 40;
2735 const int auiLayerInsertOffset
= 5;
2737 bool wxAuiManager::DoDrop(wxAuiDockInfoArray
& docks
,
2738 wxAuiPaneInfoArray
& panes
,
2739 wxAuiPaneInfo
& target
,
2741 const wxPoint
& offset
)
2743 wxSize cli_size
= m_frame
->GetClientSize();
2745 wxAuiPaneInfo drop
= target
;
2748 // The result should always be shown
2752 // Check to see if the pane has been dragged outside of the window
2753 // (or near to the outside of the window), if so, dock it along the edge
2756 int layer_insert_offset
= auiLayerInsertOffset
;
2757 if (drop
.IsToolbar())
2758 layer_insert_offset
= 0;
2761 if (pt
.x
< layer_insert_offset
&&
2762 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2764 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2765 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2766 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)) + 1;
2768 if (drop
.IsToolbar())
2769 new_layer
= auiToolBarLayer
;
2774 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2775 return ProcessDockResult(target
, drop
);
2777 else if (pt
.y
< layer_insert_offset
&&
2778 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2780 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2781 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2782 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2784 if (drop
.IsToolbar())
2785 new_layer
= auiToolBarLayer
;
2790 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2791 return ProcessDockResult(target
, drop
);
2793 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2794 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2796 int new_layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2797 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2798 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)) + 1;
2800 if (drop
.IsToolbar())
2801 new_layer
= auiToolBarLayer
;
2803 drop
.Dock().Right().
2806 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2807 return ProcessDockResult(target
, drop
);
2809 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2810 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2812 int new_layer
= wxMax( wxMax( GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2813 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2814 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2816 if (drop
.IsToolbar())
2817 new_layer
= auiToolBarLayer
;
2819 drop
.Dock().Bottom().
2822 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2823 return ProcessDockResult(target
, drop
);
2827 wxAuiDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2830 if (drop
.IsToolbar())
2832 if (!part
|| !part
->dock
)
2835 // calculate the offset from where the dock begins
2836 // to the point where the user dropped the pane
2837 int dock_drop_offset
= 0;
2838 if (part
->dock
->IsHorizontal())
2839 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2841 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2844 // toolbars may only be moved in and to fixed-pane docks,
2845 // otherwise we will try to float the pane. Also, the pane
2846 // should float if being dragged over center pane windows
2847 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2849 if (m_last_rect
.IsEmpty() || m_last_rect
.Contains(pt
.x
, pt
.y
))
2855 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2856 (drop
.IsFloatable() ||
2857 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2858 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2865 return ProcessDockResult(target
, drop
);
2868 drop
.Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2870 return ProcessDockResult(target
, drop
);
2875 m_last_rect
= part
->dock
->rect
;
2876 m_last_rect
.Inflate( 15, 15 );
2879 Direction(part
->dock
->dock_direction
).
2880 Layer(part
->dock
->dock_layer
).
2881 Row(part
->dock
->dock_row
).
2882 Position(dock_drop_offset
);
2885 ((pt
.y
< part
->dock
->rect
.y
+ 1) && part
->dock
->IsHorizontal()) ||
2886 ((pt
.x
< part
->dock
->rect
.x
+ 1) && part
->dock
->IsVertical())
2887 ) && part
->dock
->panes
.GetCount() > 1)
2889 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2890 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2892 int row
= drop
.dock_row
;
2893 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2894 part
->dock
->dock_layer
,
2895 part
->dock
->dock_row
);
2896 drop
.dock_row
= row
;
2900 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2901 part
->dock
->dock_layer
,
2902 part
->dock
->dock_row
+1);
2903 drop
.dock_row
= part
->dock
->dock_row
+1;
2908 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2909 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2910 ) && part
->dock
->panes
.GetCount() > 1)
2912 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2913 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2915 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2916 part
->dock
->dock_layer
,
2917 part
->dock
->dock_row
+1);
2918 drop
.dock_row
= part
->dock
->dock_row
+1;
2922 int row
= drop
.dock_row
;
2923 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2924 part
->dock
->dock_layer
,
2925 part
->dock
->dock_row
);
2926 drop
.dock_row
= row
;
2930 return ProcessDockResult(target
, drop
);
2939 if (part
->type
== wxAuiDockUIPart::typePaneBorder
||
2940 part
->type
== wxAuiDockUIPart::typeCaption
||
2941 part
->type
== wxAuiDockUIPart::typeGripper
||
2942 part
->type
== wxAuiDockUIPart::typePaneButton
||
2943 part
->type
== wxAuiDockUIPart::typePane
||
2944 part
->type
== wxAuiDockUIPart::typePaneSizer
||
2945 part
->type
== wxAuiDockUIPart::typeDockSizer
||
2946 part
->type
== wxAuiDockUIPart::typeBackground
)
2948 if (part
->type
== wxAuiDockUIPart::typeDockSizer
)
2950 if (part
->dock
->panes
.GetCount() != 1)
2952 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2959 // If a normal frame is being dragged over a toolbar, insert it
2960 // along the edge under the toolbar, but over all other panes.
2961 // (this could be done much better, but somehow factoring this
2962 // calculation with the one at the beginning of this function)
2963 if (part
->dock
&& part
->dock
->toolbar
)
2967 switch (part
->dock
->dock_direction
)
2969 case wxAUI_DOCK_LEFT
:
2970 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2971 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2972 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2974 case wxAUI_DOCK_TOP
:
2975 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2976 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2977 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2979 case wxAUI_DOCK_RIGHT
:
2980 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2981 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2982 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2984 case wxAUI_DOCK_BOTTOM
:
2985 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2986 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2987 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2991 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2994 Direction(part
->dock
->dock_direction
).
2995 Layer(layer
).Row(0).Position(0);
2996 return ProcessDockResult(target
, drop
);
3003 part
= GetPanePart(part
->pane
->window
);
3007 bool insert_dock_row
= false;
3008 int insert_row
= part
->pane
->dock_row
;
3009 int insert_dir
= part
->pane
->dock_direction
;
3010 int insert_layer
= part
->pane
->dock_layer
;
3012 switch (part
->pane
->dock_direction
)
3014 case wxAUI_DOCK_TOP
:
3015 if (pt
.y
>= part
->rect
.y
&&
3016 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
3017 insert_dock_row
= true;
3019 case wxAUI_DOCK_BOTTOM
:
3020 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
3021 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
3022 insert_dock_row
= true;
3024 case wxAUI_DOCK_LEFT
:
3025 if (pt
.x
>= part
->rect
.x
&&
3026 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
3027 insert_dock_row
= true;
3029 case wxAUI_DOCK_RIGHT
:
3030 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
3031 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
3032 insert_dock_row
= true;
3034 case wxAUI_DOCK_CENTER
:
3036 // "new row pixels" will be set to the default, but
3037 // must never exceed 20% of the window size
3038 int new_row_pixels_x
= auiNewRowPixels
;
3039 int new_row_pixels_y
= auiNewRowPixels
;
3041 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
3042 new_row_pixels_x
= (part
->rect
.width
*20)/100;
3044 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
3045 new_row_pixels_y
= (part
->rect
.height
*20)/100;
3048 // determine if the mouse pointer is in a location that
3049 // will cause a new row to be inserted. The hot spot positions
3050 // are along the borders of the center pane
3053 insert_dock_row
= true;
3054 const wxRect
& pr
= part
->rect
;
3055 if (pt
.x
>= pr
.x
&& pt
.x
< pr
.x
+ new_row_pixels_x
)
3056 insert_dir
= wxAUI_DOCK_LEFT
;
3057 else if (pt
.y
>= pr
.y
&& pt
.y
< pr
.y
+ new_row_pixels_y
)
3058 insert_dir
= wxAUI_DOCK_TOP
;
3059 else if (pt
.x
>= pr
.x
+ pr
.width
- new_row_pixels_x
&&
3060 pt
.x
< pr
.x
+ pr
.width
)
3061 insert_dir
= wxAUI_DOCK_RIGHT
;
3062 else if (pt
.y
>= pr
.y
+ pr
.height
- new_row_pixels_y
&&
3063 pt
.y
< pr
.y
+ pr
.height
)
3064 insert_dir
= wxAUI_DOCK_BOTTOM
;
3068 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
3072 if (insert_dock_row
)
3074 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
3075 drop
.Dock().Direction(insert_dir
).
3076 Layer(insert_layer
).
3079 return ProcessDockResult(target
, drop
);
3082 // determine the mouse offset and the pane size, both in the
3083 // direction of the dock itself, and perpendicular to the dock
3087 if (part
->orientation
== wxVERTICAL
)
3089 offset
= pt
.y
- part
->rect
.y
;
3090 size
= part
->rect
.GetHeight();
3094 offset
= pt
.x
- part
->rect
.x
;
3095 size
= part
->rect
.GetWidth();
3098 int drop_position
= part
->pane
->dock_pos
;
3100 // if we are in the top/left part of the pane,
3101 // insert the pane before the pane being hovered over
3102 if (offset
<= size
/2)
3104 drop_position
= part
->pane
->dock_pos
;
3106 part
->pane
->dock_direction
,
3107 part
->pane
->dock_layer
,
3108 part
->pane
->dock_row
,
3109 part
->pane
->dock_pos
);
3112 // if we are in the bottom/right part of the pane,
3113 // insert the pane before the pane being hovered over
3114 if (offset
> size
/2)
3116 drop_position
= part
->pane
->dock_pos
+1;
3118 part
->pane
->dock_direction
,
3119 part
->pane
->dock_layer
,
3120 part
->pane
->dock_row
,
3121 part
->pane
->dock_pos
+1);
3125 Direction(part
->dock
->dock_direction
).
3126 Layer(part
->dock
->dock_layer
).
3127 Row(part
->dock
->dock_row
).
3128 Position(drop_position
);
3129 return ProcessDockResult(target
, drop
);
3136 void wxAuiManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
3138 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
3140 m_hint_fadetimer
.Stop();
3144 m_hint_fadeamt
+= 4;
3145 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
3148 void wxAuiManager::ShowHint(const wxRect
& rect
)
3152 // if the hint rect is the same as last time, don't do anything
3153 if (m_last_hint
== rect
)
3157 m_hint_fadeamt
= m_hint_fademax
;
3159 if ((m_flags
& wxAUI_MGR_HINT_FADE
)
3160 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
3161 (m_flags
& wxAUI_MGR_NO_VENETIAN_BLINDS_FADE
))
3165 m_hint_wnd
->SetSize(rect
);
3166 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
3168 if (!m_hint_wnd
->IsShown())
3171 // if we are dragging a floating pane, set the focus
3172 // back to that floating pane (otherwise it becomes unfocused)
3173 if (m_action
== actionDragFloatingPane
&& m_action_window
)
3174 m_action_window
->SetFocus();
3176 m_hint_wnd
->Raise();
3179 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
3181 // start fade in timer
3182 m_hint_fadetimer
.SetOwner(this, 101);
3183 m_hint_fadetimer
.Start(5);
3186 else // Not using a transparent hint window...
3188 if (!(m_flags
& wxAUI_MGR_RECTANGLE_HINT
))
3191 if (m_last_hint
!= rect
)
3193 // remove the last hint rectangle
3199 wxScreenDC screendc
;
3200 wxRegion
clip(1, 1, 10000, 10000);
3202 // clip all floating windows, so we don't draw over them
3204 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
3206 wxAuiPaneInfo
& pane
= m_panes
.Item(i
);
3208 if (pane
.IsFloating() &&
3209 pane
.frame
->IsShown())
3211 wxRect rect
= pane
.frame
->GetRect();
3213 // wxGTK returns the client size, not the whole frame size
3219 clip
.Subtract(rect
);
3223 // As we can only hide the hint by redrawing the managed window, we
3224 // need to clip the region to the managed window too or we get
3225 // nasty redrawn problems.
3226 clip
.Intersect(m_frame
->GetRect());
3228 screendc
.SetClippingRegion(clip
);
3230 wxBitmap stipple
= wxPaneCreateStippleBitmap();
3231 wxBrush
brush(stipple
);
3232 screendc
.SetBrush(brush
);
3233 screendc
.SetPen(*wxTRANSPARENT_PEN
);
3235 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
3236 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
3237 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
3238 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
3242 void wxAuiManager::HideHint()
3244 // hides a transparent window hint, if there is one
3247 if (m_hint_wnd
->IsShown())
3248 m_hint_wnd
->Show(false);
3249 m_hint_wnd
->SetTransparent(0);
3250 m_hint_fadetimer
.Stop();
3251 m_last_hint
= wxRect();
3255 // hides a painted hint by redrawing the frame window
3256 if (!m_last_hint
.IsEmpty())
3260 m_last_hint
= wxRect();
3266 void wxAuiManager::StartPaneDrag(wxWindow
* pane_window
,
3267 const wxPoint
& offset
)
3269 wxAuiPaneInfo
& pane
= GetPane(pane_window
);
3273 if (pane
.IsToolbar())
3275 m_action
= actionDragToolbarPane
;
3279 m_action
= actionDragFloatingPane
;
3282 m_action_window
= pane_window
;
3283 m_action_offset
= offset
;
3284 m_frame
->CaptureMouse();
3288 // CalculateHintRect() calculates the drop hint rectangle. The method
3289 // first calls DoDrop() to determine the exact position the pane would
3290 // be at were if dropped. If the pane would indeed become docked at the
3291 // specified drop point, the the rectangle hint will be returned in
3292 // screen coordinates. Otherwise, an empty rectangle is returned.
3293 // |pane_window| is the window pointer of the pane being dragged, |pt| is
3294 // the mouse position, in client coordinates. |offset| describes the offset
3295 // that the mouse is from the upper-left corner of the item being dragged
3297 wxRect
wxAuiManager::CalculateHintRect(wxWindow
* pane_window
,
3299 const wxPoint
& offset
)
3303 // we need to paint a hint rectangle; to find out the exact hint rectangle,
3304 // we will create a new temporary layout and then measure the resulting
3305 // rectangle; we will create a copy of the docking structures (m_dock)
3306 // so that we don't modify the real thing on screen
3308 int i
, pane_count
, part_count
;
3309 wxAuiDockInfoArray docks
;
3310 wxAuiPaneInfoArray panes
;
3311 wxAuiDockUIPartArray uiparts
;
3312 wxAuiPaneInfo hint
= GetPane(pane_window
);
3313 hint
.name
= wxT("__HINT__");
3314 hint
.PaneBorder(true);
3320 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3322 // remove any pane already there which bears the same window;
3323 // this happens when you are moving a pane around in a dock
3324 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
3326 if (panes
.Item(i
).window
== pane_window
)
3328 RemovePaneFromDocks(docks
, panes
.Item(i
));
3334 // find out where the new pane would be
3335 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
3342 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
3343 wxSize client_size
= m_frame
->GetClientSize();
3344 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
3347 for (i
= 0, part_count
= uiparts
.GetCount();
3348 i
< part_count
; ++i
)
3350 wxAuiDockUIPart
& part
= uiparts
.Item(i
);
3352 if (part
.type
== wxAuiDockUIPart::typePaneBorder
&&
3353 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
3355 rect
= wxRect(part
.sizer_item
->GetPosition(),
3356 part
.sizer_item
->GetSize());
3368 // actually show the hint rectangle on the screen
3369 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
3371 if ( m_frame
->GetLayoutDirection() == wxLayout_RightToLeft
)
3373 // Mirror rectangle in RTL mode
3374 rect
.x
-= rect
.GetWidth();
3380 // DrawHintRect() calculates the hint rectangle by calling
3381 // CalculateHintRect(). If there is a rectangle, it shows it
3382 // by calling ShowHint(), otherwise it hides any hint
3383 // rectangle currently shown
3384 void wxAuiManager::DrawHintRect(wxWindow
* pane_window
,
3386 const wxPoint
& offset
)
3388 wxRect rect
= CalculateHintRect(pane_window
, pt
, offset
);
3400 void wxAuiManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
3402 // try to find the pane
3403 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3404 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3406 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3407 pane
.frame
->SetTransparent(150);
3410 void wxAuiManager::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
3412 // try to find the pane
3413 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3414 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3416 wxPoint pt
= ::wxGetMousePosition();
3419 // Adapt pt to direction
3422 // move to pane's upper border
3424 pos
= wnd
->ClientToScreen( pos
);
3426 // and some more pixels for the title bar
3429 else if (dir
== wxWEST
)
3431 // move to pane's left border
3433 pos
= wnd
->ClientToScreen( pos
);
3436 else if (dir
== wxEAST
)
3438 // move to pane's right border
3439 wxPoint
pos( wnd
->GetSize().x
, 0 );
3440 pos
= wnd
->ClientToScreen( pos
);
3443 else if (dir
== wxSOUTH
)
3445 // move to pane's bottom border
3446 wxPoint
pos( 0, wnd
->GetSize().y
);
3447 pos
= wnd
->ClientToScreen( pos
);
3454 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3456 // calculate the offset from the upper left-hand corner
3457 // of the frame to the mouse pointer
3458 wxPoint frame_pos
= pane
.frame
->GetPosition();
3459 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3461 // no hint for toolbar floating windows
3462 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
3464 wxAuiDockInfoArray docks
;
3465 wxAuiPaneInfoArray panes
;
3466 wxAuiDockUIPartArray uiparts
;
3467 wxAuiPaneInfo hint
= pane
;
3469 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3471 // find out where the new pane would be
3472 if (!DoDrop(docks
, panes
, hint
, client_pt
))
3474 if (hint
.IsFloating())
3478 m_action
= actionDragToolbarPane
;
3479 m_action_window
= pane
.window
;
3487 // if a key modifier is pressed while dragging the frame,
3488 // don't dock the window
3489 if (!CanDockPanel(pane
))
3496 DrawHintRect(wnd
, client_pt
, action_offset
);
3499 // this cleans up some screen artifacts that are caused on GTK because
3500 // we aren't getting the exact size of the window (see comment
3510 void wxAuiManager::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
3512 // try to find the pane
3513 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3514 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3516 wxPoint pt
= ::wxGetMousePosition();
3519 // Adapt pt to direction
3522 // move to pane's upper border
3524 pos
= wnd
->ClientToScreen( pos
);
3526 // and some more pixels for the title bar
3529 else if (dir
== wxWEST
)
3531 // move to pane's left border
3533 pos
= wnd
->ClientToScreen( pos
);
3536 else if (dir
== wxEAST
)
3538 // move to pane's right border
3539 wxPoint
pos( wnd
->GetSize().x
, 0 );
3540 pos
= wnd
->ClientToScreen( pos
);
3543 else if (dir
== wxSOUTH
)
3545 // move to pane's bottom border
3546 wxPoint
pos( 0, wnd
->GetSize().y
);
3547 pos
= wnd
->ClientToScreen( pos
);
3554 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3556 // calculate the offset from the upper left-hand corner
3557 // of the frame to the mouse pointer
3558 wxPoint frame_pos
= pane
.frame
->GetPosition();
3559 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3562 // if a key modifier is pressed while dragging the frame,
3563 // don't dock the window
3564 if (CanDockPanel(pane
))
3566 // do the drop calculation
3567 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3570 // if the pane is still floating, update it's floating
3571 // position (that we store)
3572 if (pane
.IsFloating())
3574 pane
.floating_pos
= pane
.frame
->GetPosition();
3576 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3577 pane
.frame
->SetTransparent(255);
3579 else if (m_has_maximized
)
3581 RestoreMaximizedPane();
3589 void wxAuiManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3591 // try to find the pane
3592 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3593 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3595 pane
.floating_size
= size
;
3599 void wxAuiManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3601 // try to find the pane
3602 wxAuiPaneInfo
& pane
= GetPane(wnd
);
3603 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3606 // fire pane close event
3607 wxAuiManagerEvent
e(wxEVT_AUI_PANE_CLOSE
);
3609 e
.SetCanVeto(evt
.CanVeto());
3619 // close the pane, but check that it
3620 // still exists in our pane array first
3621 // (the event handler above might have removed it)
3623 wxAuiPaneInfo
& check
= GetPane(wnd
);
3633 void wxAuiManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3635 if ((GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
) && GetPane(wnd
).IsOk())
3637 SetActivePane(m_panes
, wnd
);
3642 // OnRender() draws all of the pane captions, sashes,
3643 // backgrounds, captions, grippers, pane borders and buttons.
3644 // It renders the entire user interface.
3646 void wxAuiManager::OnRender(wxAuiManagerEvent
& evt
)
3648 // if the frame is about to be deleted, don't bother
3649 if (!m_frame
|| wxPendingDelete
.Member(m_frame
))
3652 wxDC
* dc
= evt
.GetDC();
3658 for (i
= 0, part_count
= m_uiparts
.GetCount();
3659 i
< part_count
; ++i
)
3661 wxAuiDockUIPart
& part
= m_uiparts
.Item(i
);
3663 // don't draw hidden pane items or items that aren't windows
3664 if (part
.sizer_item
&& ((!part
.sizer_item
->IsWindow() && !part
.sizer_item
->IsSpacer() && !part
.sizer_item
->IsSizer()) || !part
.sizer_item
->IsShown()))
3669 case wxAuiDockUIPart::typeDockSizer
:
3670 case wxAuiDockUIPart::typePaneSizer
:
3671 m_art
->DrawSash(*dc
, m_frame
, part
.orientation
, part
.rect
);
3673 case wxAuiDockUIPart::typeBackground
:
3674 m_art
->DrawBackground(*dc
, m_frame
, part
.orientation
, part
.rect
);
3676 case wxAuiDockUIPart::typeCaption
:
3677 m_art
->DrawCaption(*dc
, m_frame
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3679 case wxAuiDockUIPart::typeGripper
:
3680 m_art
->DrawGripper(*dc
, m_frame
, part
.rect
, *part
.pane
);
3682 case wxAuiDockUIPart::typePaneBorder
:
3683 m_art
->DrawBorder(*dc
, m_frame
, part
.rect
, *part
.pane
);
3685 case wxAuiDockUIPart::typePaneButton
:
3686 m_art
->DrawPaneButton(*dc
, m_frame
, part
.button
->button_id
,
3687 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3694 // Render() fire a render event, which is normally handled by
3695 // wxAuiManager::OnRender(). This allows the render function to
3696 // be overridden via the render event. This can be useful for paintin
3697 // custom graphics in the main window. Default behavior can be
3698 // invoked in the overridden function by calling OnRender()
3700 void wxAuiManager::Render(wxDC
* dc
)
3702 wxAuiManagerEvent
e(wxEVT_AUI_RENDER
);
3708 void wxAuiManager::Repaint(wxDC
* dc
)
3713 m_frame
->Refresh() ;
3719 m_frame
->GetClientSize(&w
, &h
);
3721 // figure out which dc to use; if one
3722 // has been specified, use it, otherwise
3724 wxClientDC
* client_dc
= NULL
;
3727 client_dc
= new wxClientDC(m_frame
);
3731 // if the frame has a toolbar, the client area
3732 // origin will not be (0,0).
3733 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3734 if (pt
.x
!= 0 || pt
.y
!= 0)
3735 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3737 // render all the items
3740 // if we created a client_dc, delete it
3745 void wxAuiManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3747 wxPaintDC
dc(m_frame
);
3751 void wxAuiManager::OnEraseBackground(wxEraseEvent
& event
)
3760 void wxAuiManager::OnSize(wxSizeEvent
& event
)
3768 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
3770 // for MDI parent frames, this event must not
3771 // be "skipped". In other words, the parent frame
3772 // must not be allowed to resize the client window
3773 // after we are finished processing sizing changes
3781 void wxAuiManager::OnFindManager(wxAuiManagerEvent
& evt
)
3783 // get the window we are managing, if none, return NULL
3784 wxWindow
* window
= GetManagedWindow();
3787 evt
.SetManager(NULL
);
3791 // if we are managing a child frame, get the 'real' manager
3792 if (window
->IsKindOf(CLASSINFO(wxAuiFloatingFrame
)))
3794 wxAuiFloatingFrame
* float_frame
= static_cast<wxAuiFloatingFrame
*>(window
);
3795 evt
.SetManager(float_frame
->GetOwnerManager());
3799 // return pointer to ourself
3800 evt
.SetManager(this);
3803 void wxAuiManager::OnSetCursor(wxSetCursorEvent
& event
)
3806 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3807 wxCursor cursor
= wxNullCursor
;
3811 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3812 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3814 // a dock may not be resized if it has a single
3815 // pane which is not resizable
3816 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3817 part
->dock
->panes
.GetCount() == 1 &&
3818 part
->dock
->panes
.Item(0)->IsFixed())
3821 // panes that may not be resized do not get a sizing cursor
3822 if (part
->pane
&& part
->pane
->IsFixed())
3825 if (part
->orientation
== wxVERTICAL
)
3826 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3828 cursor
= wxCursor(wxCURSOR_SIZENS
);
3830 else if (part
->type
== wxAuiDockUIPart::typeGripper
)
3832 cursor
= wxCursor(wxCURSOR_SIZING
);
3836 event
.SetCursor(cursor
);
3841 void wxAuiManager::UpdateButtonOnScreen(wxAuiDockUIPart
* button_ui_part
,
3842 const wxMouseEvent
& event
)
3844 wxAuiDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3845 if (!hit_test
|| !button_ui_part
)
3848 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3850 if (hit_test
== button_ui_part
)
3852 if (event
.LeftDown())
3853 state
= wxAUI_BUTTON_STATE_PRESSED
;
3855 state
= wxAUI_BUTTON_STATE_HOVER
;
3859 if (event
.LeftDown())
3860 state
= wxAUI_BUTTON_STATE_HOVER
;
3863 // now repaint the button with hover state
3864 wxClientDC
cdc(m_frame
);
3866 // if the frame has a toolbar, the client area
3867 // origin will not be (0,0).
3868 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3869 if (pt
.x
!= 0 || pt
.y
!= 0)
3870 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3874 m_art
->DrawPaneButton(cdc
, m_frame
,
3875 button_ui_part
->button
->button_id
,
3877 button_ui_part
->rect
,
3882 void wxAuiManager::OnLeftDown(wxMouseEvent
& event
)
3884 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3887 if (part
->type
== wxAuiDockUIPart::typeDockSizer
||
3888 part
->type
== wxAuiDockUIPart::typePaneSizer
)
3890 // Removing this restriction so that a centre pane can be resized
3891 //if (part->dock && part->dock->dock_direction == wxAUI_DOCK_CENTER)
3894 // a dock may not be resized if it has a single
3895 // pane which is not resizable
3896 if (part
->type
== wxAuiDockUIPart::typeDockSizer
&& part
->dock
&&
3897 part
->dock
->panes
.GetCount() == 1 &&
3898 part
->dock
->panes
.Item(0)->IsFixed())
3901 // panes that may not be resized should be ignored here
3902 if (part
->pane
&& part
->pane
->IsFixed())
3905 m_action
= actionResize
;
3906 m_action_part
= part
;
3907 m_action_hintrect
= wxRect();
3908 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3909 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3910 event
.m_y
- part
->rect
.y
);
3911 m_frame
->CaptureMouse();
3913 else if (part
->type
== wxAuiDockUIPart::typePaneButton
)
3915 m_action
= actionClickButton
;
3916 m_action_part
= part
;
3917 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3918 m_frame
->CaptureMouse();
3920 UpdateButtonOnScreen(part
, event
);
3922 else if (part
->type
== wxAuiDockUIPart::typeCaption
||
3923 part
->type
== wxAuiDockUIPart::typeGripper
)
3925 // if we are managing a wxAuiFloatingFrame window, then
3926 // we are an embedded wxAuiManager inside the wxAuiFloatingFrame.
3927 // We want to initiate a toolbar drag in our owner manager
3928 wxWindow
* managed_wnd
= GetManagedWindow();
3931 part
->pane
->window
&&
3933 managed_wnd
->IsKindOf(CLASSINFO(wxAuiFloatingFrame
)))
3935 wxAuiFloatingFrame
* floating_frame
= (wxAuiFloatingFrame
*)managed_wnd
;
3936 wxAuiManager
* owner_mgr
= floating_frame
->GetOwnerManager();
3937 owner_mgr
->StartPaneDrag(part
->pane
->window
,
3938 wxPoint(event
.m_x
- part
->rect
.x
,
3939 event
.m_y
- part
->rect
.y
));
3945 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3947 // set the caption as active
3948 SetActivePane(m_panes
, part
->pane
->window
);
3952 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3955 m_action
= actionClickCaption
;
3956 m_action_part
= part
;
3957 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3958 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3959 event
.m_y
- part
->rect
.y
);
3960 m_frame
->CaptureMouse();
3980 void wxAuiManager::OnLeftUp(wxMouseEvent
& event
)
3982 if (m_action
== actionResize
)
3984 m_frame
->ReleaseMouse();
3986 // get rid of the hint rectangle
3988 DrawResizeHint(dc
, m_action_hintrect
);
3990 // resize the dock or the pane
3991 if (m_action_part
&& m_action_part
->type
==wxAuiDockUIPart::typeDockSizer
)
3993 wxRect
& rect
= m_action_part
->dock
->rect
;
3995 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3996 event
.m_y
- m_action_offset
.y
);
3998 switch (m_action_part
->dock
->dock_direction
)
4000 case wxAUI_DOCK_LEFT
:
4001 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
4003 case wxAUI_DOCK_TOP
:
4004 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
4006 case wxAUI_DOCK_RIGHT
:
4007 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
4008 new_pos
.x
- m_action_part
->rect
.GetWidth();
4010 case wxAUI_DOCK_BOTTOM
:
4011 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
4012 new_pos
.y
- m_action_part
->rect
.GetHeight();
4019 else if (m_action_part
&&
4020 m_action_part
->type
== wxAuiDockUIPart::typePaneSizer
)
4022 wxAuiDockInfo
& dock
= *m_action_part
->dock
;
4023 wxAuiPaneInfo
& pane
= *m_action_part
->pane
;
4025 int total_proportion
= 0;
4026 int dock_pixels
= 0;
4027 int new_pixsize
= 0;
4029 int caption_size
= m_art
->GetMetric(wxAUI_DOCKART_CAPTION_SIZE
);
4030 int pane_border_size
= m_art
->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE
);
4031 int sash_size
= m_art
->GetMetric(wxAUI_DOCKART_SASH_SIZE
);
4033 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
4034 event
.m_y
- m_action_offset
.y
);
4036 // determine the pane rectangle by getting the pane part
4037 wxAuiDockUIPart
* pane_part
= GetPanePart(pane
.window
);
4038 wxASSERT_MSG(pane_part
,
4039 wxT("Pane border part not found -- shouldn't happen"));
4041 // determine the new pixel size that the user wants;
4042 // this will help us recalculate the pane's proportion
4043 if (dock
.IsHorizontal())
4044 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
4046 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
4048 // determine the size of the dock, based on orientation
4049 if (dock
.IsHorizontal())
4050 dock_pixels
= dock
.rect
.GetWidth();
4052 dock_pixels
= dock
.rect
.GetHeight();
4054 // determine the total proportion of all resizable panes,
4055 // and the total size of the dock minus the size of all
4057 int i
, dock_pane_count
= dock
.panes
.GetCount();
4058 int pane_position
= -1;
4059 for (i
= 0; i
< dock_pane_count
; ++i
)
4061 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
4062 if (p
.window
== pane
.window
)
4065 // while we're at it, subtract the pane sash
4066 // width from the dock width, because this would
4067 // skew our proportion calculations
4069 dock_pixels
-= sash_size
;
4071 // also, the whole size (including decorations) of
4072 // all fixed panes must also be subtracted, because they
4073 // are not part of the proportion calculation
4076 if (dock
.IsHorizontal())
4077 dock_pixels
-= p
.best_size
.x
;
4079 dock_pixels
-= p
.best_size
.y
;
4083 total_proportion
+= p
.dock_proportion
;
4087 // find a pane in our dock to 'steal' space from or to 'give'
4088 // space to -- this is essentially what is done when a pane is
4089 // resized; the pane should usually be the first non-fixed pane
4090 // to the right of the action pane
4091 int borrow_pane
= -1;
4092 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
4094 wxAuiPaneInfo
& p
= *dock
.panes
.Item(i
);
4103 // demand that the pane being resized is found in this dock
4104 // (this assert really never should be raised)
4105 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
4107 // prevent division by zero
4108 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
4110 m_action
= actionNone
;
4114 // calculate the new proportion of the pane
4115 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
4117 // default minimum size
4120 // check against the pane's minimum size, if specified. please note
4121 // that this is not enough to ensure that the minimum size will
4122 // not be violated, because the whole frame might later be shrunk,
4123 // causing the size of the pane to violate it's minimum size
4124 if (pane
.min_size
.IsFullySpecified())
4128 if (pane
.HasBorder())
4129 min_size
+= (pane_border_size
*2);
4131 // calculate minimum size with decorations (border,caption)
4132 if (pane_part
->orientation
== wxVERTICAL
)
4134 min_size
+= pane
.min_size
.y
;
4135 if (pane
.HasCaption())
4136 min_size
+= caption_size
;
4140 min_size
+= pane
.min_size
.x
;
4145 // for some reason, an arithmatic error somewhere is causing
4146 // the proportion calculations to always be off by 1 pixel;
4147 // for now we will add the 1 pixel on, but we really should
4148 // determine what's causing this.
4151 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
4153 if (new_proportion
< min_proportion
)
4154 new_proportion
= min_proportion
;
4158 int prop_diff
= new_proportion
- pane
.dock_proportion
;
4160 // borrow the space from our neighbor pane to the
4161 // right or bottom (depending on orientation)
4162 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
4163 pane
.dock_proportion
= new_proportion
;
4170 else if (m_action
== actionClickButton
)
4172 m_hover_button
= NULL
;
4173 m_frame
->ReleaseMouse();
4174 UpdateButtonOnScreen(m_action_part
, event
);
4176 // make sure we're still over the item that was originally clicked
4177 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
4179 // fire button-click event
4180 wxAuiManagerEvent
e(wxEVT_AUI_PANE_BUTTON
);
4182 e
.SetPane(m_action_part
->pane
);
4183 e
.SetButton(m_action_part
->button
->button_id
);
4187 else if (m_action
== actionClickCaption
)
4189 m_frame
->ReleaseMouse();
4191 else if (m_action
== actionDragFloatingPane
)
4193 m_frame
->ReleaseMouse();
4195 else if (m_action
== actionDragToolbarPane
)
4197 m_frame
->ReleaseMouse();
4199 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4200 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4202 // save the new positions
4203 wxAuiDockInfoPtrArray docks
;
4204 FindDocks(m_docks
, pane
.dock_direction
,
4205 pane
.dock_layer
, pane
.dock_row
, docks
);
4206 if (docks
.GetCount() == 1)
4208 wxAuiDockInfo
& dock
= *docks
.Item(0);
4210 wxArrayInt pane_positions
, pane_sizes
;
4211 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
4213 int i
, dock_pane_count
= dock
.panes
.GetCount();
4214 for (i
= 0; i
< dock_pane_count
; ++i
)
4215 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
4218 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
4226 m_action
= actionNone
;
4227 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
4231 void wxAuiManager::OnMotion(wxMouseEvent
& event
)
4233 // sometimes when Update() is called from inside this method,
4234 // a spurious mouse move event is generated; this check will make
4235 // sure that only real mouse moves will get anywhere in this method;
4236 // this appears to be a bug somewhere, and I don't know where the
4237 // mouse move event is being generated. only verified on MSW
4239 wxPoint mouse_pos
= event
.GetPosition();
4240 if (m_last_mouse_move
== mouse_pos
)
4242 m_last_mouse_move
= mouse_pos
;
4245 if (m_action
== actionResize
)
4247 wxPoint pos
= m_action_part
->rect
.GetPosition();
4248 if (m_action_part
->orientation
== wxHORIZONTAL
)
4249 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
4251 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
4253 wxRect
rect(m_frame
->ClientToScreen(pos
),
4254 m_action_part
->rect
.GetSize());
4257 if (!m_action_hintrect
.IsEmpty())
4258 DrawResizeHint(dc
, m_action_hintrect
);
4259 DrawResizeHint(dc
, rect
);
4260 m_action_hintrect
= rect
;
4262 else if (m_action
== actionClickCaption
)
4264 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
4265 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
4267 // caption has been clicked. we need to check if the mouse
4268 // is now being dragged. if it is, we need to change the
4269 // mouse action to 'drag'
4270 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
4271 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
4273 wxAuiPaneInfo
* pane_info
= m_action_part
->pane
;
4275 if (!pane_info
->IsToolbar())
4277 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
4278 pane_info
->IsFloatable())
4280 m_action
= actionDragFloatingPane
;
4282 // set initial float position
4283 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4284 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4285 pt
.y
- m_action_offset
.y
);
4288 if (pane_info
->IsMaximized())
4289 RestorePane(*pane_info
);
4293 m_action_window
= pane_info
->frame
;
4295 // action offset is used here to make it feel "natural" to the user
4296 // to drag a docked pane and suddenly have it become a floating frame.
4297 // Sometimes, however, the offset where the user clicked on the docked
4298 // caption is bigger than the width of the floating frame itself, so
4299 // in that case we need to set the action offset to a sensible value
4300 wxSize frame_size
= m_action_window
->GetSize();
4301 if (frame_size
.x
<= m_action_offset
.x
)
4302 m_action_offset
.x
= 30;
4307 m_action
= actionDragToolbarPane
;
4308 m_action_window
= pane_info
->window
;
4312 else if (m_action
== actionDragFloatingPane
)
4314 if (m_action_window
)
4316 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4317 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
4318 pt
.y
- m_action_offset
.y
);
4321 else if (m_action
== actionDragToolbarPane
)
4323 wxAuiPaneInfo
& pane
= GetPane(m_action_window
);
4324 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
4326 pane
.state
|= wxAuiPaneInfo::actionPane
;
4328 wxPoint pt
= event
.GetPosition();
4329 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
4331 // if DoDrop() decided to float the pane, set up
4332 // the floating pane's initial position
4333 if (pane
.IsFloating())
4335 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
4336 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
4337 pt
.y
- m_action_offset
.y
);
4340 // this will do the actiual move operation;
4341 // in the case that the pane has been floated,
4342 // this call will create the floating pane
4343 // and do the reparenting
4346 // if the pane has been floated, change the mouse
4347 // action actionDragFloatingPane so that subsequent
4348 // EVT_MOTION() events will move the floating pane
4349 if (pane
.IsFloating())
4351 pane
.state
&= ~wxAuiPaneInfo::actionPane
;
4352 m_action
= actionDragFloatingPane
;
4353 m_action_window
= pane
.frame
;
4358 wxAuiDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
4359 if (part
&& part
->type
== wxAuiDockUIPart::typePaneButton
)
4361 if (part
!= m_hover_button
)
4363 // make the old button normal
4366 UpdateButtonOnScreen(m_hover_button
, event
);
4370 // mouse is over a button, so repaint the
4371 // button in hover mode
4372 UpdateButtonOnScreen(part
, event
);
4373 m_hover_button
= part
;
4381 m_hover_button
= NULL
;
4392 void wxAuiManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
4396 m_hover_button
= NULL
;
4401 void wxAuiManager::OnChildFocus(wxChildFocusEvent
& event
)
4403 // when a child pane has it's focus set, we should change the
4404 // pane's active state to reflect this. (this is only true if
4405 // active panes are allowed by the owner)
4406 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
4408 wxAuiPaneInfo
& pane
= GetPane(event
.GetWindow());
4409 if (pane
.IsOk() && (pane
.state
& wxAuiPaneInfo::optionActive
) == 0)
4411 SetActivePane(m_panes
, event
.GetWindow());
4420 // OnPaneButton() is an event handler that is called
4421 // when a pane button has been pressed.
4422 void wxAuiManager::OnPaneButton(wxAuiManagerEvent
& evt
)
4424 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxAuiManager::OnPaneButton must be non-null"));
4426 wxAuiPaneInfo
& pane
= *(evt
.pane
);
4428 if (evt
.button
== wxAUI_BUTTON_CLOSE
)
4430 // fire pane close event
4431 wxAuiManagerEvent
e(wxEVT_AUI_PANE_CLOSE
);
4433 e
.SetPane(evt
.pane
);
4438 // close the pane, but check that it
4439 // still exists in our pane array first
4440 // (the event handler above might have removed it)
4442 wxAuiPaneInfo
& check
= GetPane(pane
.window
);
4451 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& !pane
.IsMaximized())
4453 // fire pane close event
4454 wxAuiManagerEvent
e(wxEVT_AUI_PANE_MAXIMIZE
);
4456 e
.SetPane(evt
.pane
);
4465 else if (evt
.button
== wxAUI_BUTTON_MAXIMIZE_RESTORE
&& pane
.IsMaximized())
4467 // fire pane close event
4468 wxAuiManagerEvent
e(wxEVT_AUI_PANE_RESTORE
);
4470 e
.SetPane(evt
.pane
);
4479 else if (evt
.button
== wxAUI_BUTTON_PIN
)
4481 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&