1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/framemanager.cpp
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
8 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/aui/framemanager.h"
29 #include "wx/aui/dockart.h"
30 #include "wx/aui/floatpane.h"
34 #include "wx/settings.h"
36 #include "wx/dcclient.h"
37 #include "wx/dcscreen.h"
38 #include "wx/toolbar.h"
43 WX_CHECK_BUILD_OPTIONS("wxAUI")
45 #include "wx/arrimpl.cpp"
46 WX_DECLARE_OBJARRAY(wxRect
, wxAuiRectArray
);
47 WX_DEFINE_OBJARRAY(wxAuiRectArray
)
48 WX_DEFINE_OBJARRAY(wxDockUIPartArray
)
49 WX_DEFINE_OBJARRAY(wxDockInfoArray
)
50 WX_DEFINE_OBJARRAY(wxPaneButtonArray
)
51 WX_DEFINE_OBJARRAY(wxPaneInfoArray
)
53 wxPaneInfo wxNullPaneInfo
;
54 wxDockInfo wxNullDockInfo
;
55 DEFINE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON
)
56 DEFINE_EVENT_TYPE(wxEVT_AUI_PANECLOSE
)
57 DEFINE_EVENT_TYPE(wxEVT_AUI_RENDER
)
60 // a few defines to avoid nameclashes
61 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
63 #include "wx/mac/private.h"
66 IMPLEMENT_DYNAMIC_CLASS(wxFrameManagerEvent
, wxEvent
)
68 class wxPseudoTransparentFrame
: public wxFrame
71 wxPseudoTransparentFrame(wxWindow
* parent
= NULL
,
72 wxWindowID id
= wxID_ANY
,
73 const wxString
& title
= wxEmptyString
,
74 const wxPoint
& pos
= wxDefaultPosition
,
75 const wxSize
& size
= wxDefaultSize
,
76 long style
= wxDEFAULT_FRAME_STYLE
,
77 const wxString
&name
= wxT("frame"))
78 : wxFrame(parent
, id
, title
, pos
, size
, style
| wxFRAME_SHAPED
, name
)
80 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
87 m_CanSetShape
= false; // have to wait for window create event on GTK
91 m_Region
= wxRegion(0, 0, 0, 0);
95 virtual bool SetTransparent(wxByte alpha
)
99 int w
=100; // some defaults
101 GetClientSize(&w
, &h
);
107 // m_Region.Union(0, 0, 1, m_MaxWidth);
110 for (int y
=0; y
<m_MaxHeight
; y
++)
112 // Reverse the order of the bottom 4 bits
113 int j
=((y
&8)?1:0)|((y
&4)?2:0)|((y
&2)?4:0)|((y
&1)?8:0);
114 if ((j
*16+8)<m_Amount
)
115 m_Region
.Union(0, y
, m_MaxWidth
, 1);
124 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
128 if (m_Region
.IsEmpty())
132 dc
.SetBrush(wxColour(128, 192, 255));
134 dc
.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
136 dc
.SetPen(*wxTRANSPARENT_PEN
);
138 wxRegionIterator
upd(GetUpdateRegion()); // get the update rect list
142 wxRect
rect(upd
.GetRect());
143 dc
.DrawRectangle(rect
.x
, rect
.y
, rect
.width
, rect
.height
);
150 void OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
))
157 void OnSize(wxSizeEvent
& event
)
159 // We sometimes get surplus size events
160 if ((event
.GetSize().GetWidth() == m_lastWidth
) &&
161 (event
.GetSize().GetHeight() == m_lastHeight
))
166 m_lastWidth
= event
.GetSize().GetWidth();
167 m_lastHeight
= event
.GetSize().GetHeight();
169 SetTransparent(m_Amount
);
170 m_Region
.Intersect(0, 0, event
.GetSize().GetWidth(),
171 event
.GetSize().GetHeight());
182 int m_lastWidth
,m_lastHeight
;
186 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame
)
187 DECLARE_EVENT_TABLE()
191 IMPLEMENT_DYNAMIC_CLASS(wxPseudoTransparentFrame
, wxFrame
)
193 BEGIN_EVENT_TABLE(wxPseudoTransparentFrame
, wxFrame
)
194 EVT_PAINT(wxPseudoTransparentFrame::OnPaint
)
195 EVT_SIZE(wxPseudoTransparentFrame::OnSize
)
197 EVT_WINDOW_CREATE(wxPseudoTransparentFrame::OnWindowCreate
)
202 // -- static utility functions --
204 static wxBitmap
wxPaneCreateStippleBitmap()
206 unsigned char data
[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
207 wxImage
img(2,2,data
,true);
208 return wxBitmap(img
);
211 static void DrawResizeHint(wxDC
& dc
, const wxRect
& rect
)
213 wxBitmap stipple
= wxPaneCreateStippleBitmap();
214 wxBrush
brush(stipple
);
216 dc
.SetPen(*wxTRANSPARENT_PEN
);
218 dc
.SetLogicalFunction(wxXOR
);
219 dc
.DrawRectangle(rect
);
224 // CopyDocksAndPanes() - this utility function creates copies of
225 // the dock and pane info. wxDockInfo's usually contain pointers
226 // to wxPaneInfo classes, thus this function is necessary to reliably
227 // reconstruct that relationship in the new dock info and pane info arrays
229 static void CopyDocksAndPanes(wxDockInfoArray
& dest_docks
,
230 wxPaneInfoArray
& dest_panes
,
231 const wxDockInfoArray
& src_docks
,
232 const wxPaneInfoArray
& src_panes
)
234 dest_docks
= src_docks
;
235 dest_panes
= src_panes
;
236 int i
, j
, k
, dock_count
, pc1
, pc2
;
237 for (i
= 0, dock_count
= dest_docks
.GetCount(); i
< dock_count
; ++i
)
239 wxDockInfo
& dock
= dest_docks
.Item(i
);
240 for (j
= 0, pc1
= dock
.panes
.GetCount(); j
< pc1
; ++j
)
241 for (k
= 0, pc2
= src_panes
.GetCount(); k
< pc2
; ++k
)
242 if (dock
.panes
.Item(j
) == &src_panes
.Item(k
))
243 dock
.panes
.Item(j
) = &dest_panes
.Item(k
);
247 // GetMaxLayer() is an internal function which returns
248 // the highest layer inside the specified dock
249 static int GetMaxLayer(const wxDockInfoArray
& docks
, int dock_direction
)
251 int i
, dock_count
, max_layer
= 0;
252 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
254 wxDockInfo
& dock
= docks
.Item(i
);
255 if (dock
.dock_direction
== dock_direction
&&
256 dock
.dock_layer
> max_layer
&& !dock
.fixed
)
257 max_layer
= dock
.dock_layer
;
263 // GetMaxRow() is an internal function which returns
264 // the highest layer inside the specified dock
265 static int GetMaxRow(const wxPaneInfoArray
& panes
, int direction
, int layer
)
267 int i
, pane_count
, max_row
= 0;
268 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
270 wxPaneInfo
& pane
= panes
.Item(i
);
271 if (pane
.dock_direction
== direction
&&
272 pane
.dock_layer
== layer
&&
273 pane
.dock_row
> max_row
)
274 max_row
= pane
.dock_row
;
281 // DoInsertDockLayer() is an internal function that inserts a new dock
282 // layer by incrementing all existing dock layer values by one
283 static void DoInsertDockLayer(wxPaneInfoArray
& panes
,
288 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
290 wxPaneInfo
& pane
= panes
.Item(i
);
291 if (!pane
.IsFloating() &&
292 pane
.dock_direction
== dock_direction
&&
293 pane
.dock_layer
>= dock_layer
)
298 // DoInsertDockLayer() is an internal function that inserts a new dock
299 // row by incrementing all existing dock row values by one
300 static void DoInsertDockRow(wxPaneInfoArray
& panes
,
306 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
308 wxPaneInfo
& pane
= panes
.Item(i
);
309 if (!pane
.IsFloating() &&
310 pane
.dock_direction
== dock_direction
&&
311 pane
.dock_layer
== dock_layer
&&
312 pane
.dock_row
>= dock_row
)
317 // DoInsertDockLayer() is an internal function that inserts a space for
318 // another dock pane by incrementing all existing dock row values by one
319 static void DoInsertPane(wxPaneInfoArray
& panes
,
326 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
328 wxPaneInfo
& pane
= panes
.Item(i
);
329 if (!pane
.IsFloating() &&
330 pane
.dock_direction
== dock_direction
&&
331 pane
.dock_layer
== dock_layer
&&
332 pane
.dock_row
== dock_row
&&
333 pane
.dock_pos
>= dock_pos
)
338 // FindDocks() is an internal function that returns a list of docks which meet
339 // the specified conditions in the parameters and returns a sorted array
340 // (sorted by layer and then row)
341 static void FindDocks(wxDockInfoArray
& docks
,
345 wxDockInfoPtrArray
& arr
)
347 int begin_layer
= dock_layer
;
348 int end_layer
= dock_layer
;
349 int begin_row
= dock_row
;
350 int end_row
= dock_row
;
351 int dock_count
= docks
.GetCount();
352 int layer
, row
, i
, max_row
= 0, max_layer
= 0;
354 // discover the maximum dock layer and the max row
355 for (i
= 0; i
< dock_count
; ++i
)
357 max_row
= wxMax(max_row
, docks
.Item(i
).dock_row
);
358 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
361 // if no dock layer was specified, search all dock layers
362 if (dock_layer
== -1)
365 end_layer
= max_layer
;
368 // if no dock row was specified, search all dock row
377 for (layer
= begin_layer
; layer
<= end_layer
; ++layer
)
378 for (row
= begin_row
; row
<= end_row
; ++row
)
379 for (i
= 0; i
< dock_count
; ++i
)
381 wxDockInfo
& d
= docks
.Item(i
);
382 if (dock_direction
== -1 || dock_direction
== d
.dock_direction
)
384 if (d
.dock_layer
== layer
&& d
.dock_row
== row
)
390 // FindPaneInDock() looks up a specified window pointer inside a dock.
391 // If found, the corresponding wxPaneInfo pointer is returned, otherwise NULL.
392 static wxPaneInfo
* FindPaneInDock(const wxDockInfo
& dock
, wxWindow
* window
)
394 int i
, count
= dock
.panes
.GetCount();
395 for (i
= 0; i
< count
; ++i
)
397 wxPaneInfo
* p
= dock
.panes
.Item(i
);
398 if (p
->window
== window
)
404 // RemovePaneFromDocks() removes a pane window from all docks
405 // with a possible exception specified by parameter "ex_cept"
406 static void RemovePaneFromDocks(wxDockInfoArray
& docks
,
408 wxDockInfo
* ex_cept
= NULL
)
411 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
413 wxDockInfo
& d
= docks
.Item(i
);
416 wxPaneInfo
* pi
= FindPaneInDock(d
, pane
.window
);
422 // RenumberDockRows() takes a dock and assigns sequential numbers
423 // to existing rows. Basically it takes out the gaps; so if a
424 // dock has rows with numbers 0,2,5, they will become 0,1,2
425 static void RenumberDockRows(wxDockInfoPtrArray
& docks
)
427 int i
, dock_count
, j
, pane_count
;
428 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
430 wxDockInfo
& dock
= *docks
.Item(i
);
432 for (j
= 0, pane_count
= dock
.panes
.GetCount(); j
< pane_count
; ++j
)
433 dock
.panes
.Item(j
)->dock_row
= i
;
438 // SetActivePane() sets the active pane, as well as cycles through
439 // every other pane and makes sure that all others' active flags
441 static void SetActivePane(wxPaneInfoArray
& panes
, wxWindow
* active_pane
)
444 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
446 wxPaneInfo
& pane
= panes
.Item(i
);
447 pane
.state
&= ~wxPaneInfo::optionActive
;
448 if (pane
.window
== active_pane
)
449 pane
.state
|= wxPaneInfo::optionActive
;
454 // this function is used to sort panes by dock position
455 static int PaneSortFunc(wxPaneInfo
** p1
, wxPaneInfo
** p2
)
457 return ((*p1
)->dock_pos
< (*p2
)->dock_pos
) ? -1 : 1;
461 // -- wxFrameManager class implementation --
464 BEGIN_EVENT_TABLE(wxFrameManager
, wxEvtHandler
)
465 EVT_AUI_PANEBUTTON(wxFrameManager::OnPaneButton
)
466 EVT_AUI_RENDER(wxFrameManager::OnRender
)
467 EVT_PAINT(wxFrameManager::OnPaint
)
468 EVT_ERASE_BACKGROUND(wxFrameManager::OnEraseBackground
)
469 EVT_SIZE(wxFrameManager::OnSize
)
470 EVT_SET_CURSOR(wxFrameManager::OnSetCursor
)
471 EVT_LEFT_DOWN(wxFrameManager::OnLeftDown
)
472 EVT_LEFT_UP(wxFrameManager::OnLeftUp
)
473 EVT_MOTION(wxFrameManager::OnMotion
)
474 EVT_LEAVE_WINDOW(wxFrameManager::OnLeaveWindow
)
475 EVT_CHILD_FOCUS(wxFrameManager::OnChildFocus
)
476 EVT_TIMER(101, wxFrameManager::OnHintFadeTimer
)
480 wxFrameManager::wxFrameManager(wxWindow
* managed_wnd
, unsigned int flags
)
482 m_action
= actionNone
;
483 m_last_mouse_move
= wxPoint();
484 m_hover_button
= NULL
;
485 m_art
= new wxDefaultDockArt
;
493 SetManagedWindow(managed_wnd
);
497 wxFrameManager::~wxFrameManager()
502 // Creates a floating frame for the windows
503 wxFloatingPane
* wxFrameManager::CreateFloatingFrame(wxWindow
* parent
, const wxPaneInfo
& p
)
505 return new wxFloatingPane(parent
, this, p
);
508 // GetPane() looks up a wxPaneInfo structure based
509 // on the supplied window pointer. Upon failure, GetPane()
510 // returns an empty wxPaneInfo, a condition which can be checked
511 // by calling wxPaneInfo::IsOk().
513 // The pane info's structure may then be modified. Once a pane's
514 // info is modified, wxFrameManager::Update() must be called to
515 // realize the changes in the UI.
517 wxPaneInfo
& wxFrameManager::GetPane(wxWindow
* window
)
520 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
522 wxPaneInfo
& p
= m_panes
.Item(i
);
523 if (p
.window
== window
)
526 return wxNullPaneInfo
;
529 // this version of GetPane() looks up a pane based on a
530 // 'pane name', see above comment for more info
531 wxPaneInfo
& wxFrameManager::GetPane(const wxString
& name
)
534 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
536 wxPaneInfo
& p
= m_panes
.Item(i
);
540 return wxNullPaneInfo
;
543 // GetAllPanes() returns a reference to all the pane info structures
544 wxPaneInfoArray
& wxFrameManager::GetAllPanes()
549 // HitTest() is an internal function which determines
550 // which UI item the specified coordinates are over
551 // (x,y) specify a position in client coordinates
552 wxDockUIPart
* wxFrameManager::HitTest(int x
, int y
)
554 wxDockUIPart
* result
= NULL
;
557 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
559 wxDockUIPart
* item
= &m_uiparts
.Item(i
);
561 // we are not interested in typeDock, because this space
562 // isn't used to draw anything, just for measurements;
563 // besides, the entire dock area is covered with other
564 // rectangles, which we are interested in.
565 if (item
->type
== wxDockUIPart::typeDock
)
568 // if we already have a hit on a more specific item, we are not
569 // interested in a pane hit. If, however, we don't already have
570 // a hit, returning a pane hit is necessary for some operations
571 if ((item
->type
== wxDockUIPart::typePane
||
572 item
->type
== wxDockUIPart::typePaneBorder
) && result
)
575 // if the point is inside the rectangle, we have a hit
576 if (item
->rect
.Contains(x
,y
))
584 // SetFlags() and GetFlags() allow the owner to set various
585 // options which are global to wxFrameManager
586 void wxFrameManager::SetFlags(unsigned int flags
)
588 // find out if we have to call UpdateHintWindowConfig()
589 bool update_hint_wnd
= false;
590 unsigned int hint_mask
= wxAUI_MGR_TRANSPARENT_HINT
|
591 wxAUI_MGR_VENETIAN_BLINDS_HINT
|
592 wxAUI_MGR_RECTANGLE_HINT
;
593 if ((flags
& hint_mask
) != (m_flags
& hint_mask
))
594 update_hint_wnd
= true;
602 UpdateHintWindowConfig();
606 unsigned int wxFrameManager::GetFlags() const
612 // don't use these anymore as they are deprecated
613 // use Set/GetManagedFrame() instead
614 void wxFrameManager::SetFrame(wxFrame
* frame
)
616 SetManagedWindow((wxWindow
*)frame
);
619 wxFrame
* wxFrameManager::GetFrame() const
621 return (wxFrame
*)m_frame
;
625 void wxFrameManager::UpdateHintWindowConfig()
627 // find out if the the system can do transparent frames
628 bool can_do_transparent
= false;
630 wxWindow
* w
= m_frame
;
633 if (w
->IsKindOf(CLASSINFO(wxFrame
)))
635 wxFrame
* f
= static_cast<wxFrame
*>(w
);
636 #if wxCHECK_VERSION(2,7,0)
637 can_do_transparent
= f
->CanSetTransparent();
645 // if there is an existing hint window, delete it
648 m_hint_wnd
->Destroy();
655 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) && can_do_transparent
)
657 // Make a window to use for a transparent hint
658 #if defined(__WXMSW__) || defined(__WXGTK__)
659 m_hint_wnd
= new wxFrame(m_frame
, wxID_ANY
, wxEmptyString
,
660 wxDefaultPosition
, wxSize(1,1),
661 wxFRAME_TOOL_WINDOW
|
662 wxFRAME_FLOAT_ON_PARENT
|
666 m_hint_wnd
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION
));
667 #elif defined(__WXMAC__)
668 // Using a miniframe with float and tool styles keeps the parent
669 // frame activated and highlighted as such...
670 m_hint_wnd
= new wxMiniFrame(m_frame
, wxID_ANY
, wxEmptyString
,
671 wxDefaultPosition
, wxSize(1,1),
672 wxFRAME_FLOAT_ON_PARENT
673 | wxFRAME_TOOL_WINDOW
);
675 // Can't set the bg colour of a Frame in wxMac
676 wxPanel
* p
= new wxPanel(m_hint_wnd
);
678 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
679 // color that is really hard to see, especially transparent.
680 // Until a better system color is decided upon we'll just use
682 p
->SetBackgroundColour(*wxBLUE
);
688 if ((m_flags
& wxAUI_MGR_TRANSPARENT_HINT
) != 0 ||
689 (m_flags
& wxAUI_MGR_VENETIAN_BLINDS_HINT
) != 0)
691 // system can't support transparent fade, or the venetian
692 // blinds effect was explicitly requested
693 m_hint_wnd
= new wxPseudoTransparentFrame(m_frame
,
698 wxFRAME_TOOL_WINDOW
|
699 wxFRAME_FLOAT_ON_PARENT
|
702 m_hint_fademax
= 128;
708 // SetManagedWindow() is usually called once when the frame
709 // manager class is being initialized. "frame" specifies
710 // the frame which should be managed by the frame mananger
711 void wxFrameManager::SetManagedWindow(wxWindow
* wnd
)
713 wxASSERT_MSG(wnd
, wxT("specified window must be non-NULL"));
716 m_frame
->PushEventHandler(this);
719 // if the owner is going to manage an MDI parent frame,
720 // we need to add the MDI client window as the default
723 if (m_frame
->IsKindOf(CLASSINFO(wxMDIParentFrame
)))
725 wxMDIParentFrame
* mdi_frame
= (wxMDIParentFrame
*)m_frame
;
726 wxWindow
* client_window
= mdi_frame
->GetClientWindow();
728 wxASSERT_MSG(client_window
, wxT("Client window is NULL!"));
730 AddPane(client_window
,
731 wxPaneInfo().Name(wxT("mdiclient")).
732 CenterPane().PaneBorder(false));
736 UpdateHintWindowConfig();
740 // UnInit() must be called, usually in the destructor
741 // of the frame class. If it is not called, usually this
742 // will result in a crash upon program exit
743 void wxFrameManager::UnInit()
747 m_frame
->RemoveEventHandler(this);
751 // GetManagedWindow() returns the window pointer being managed
752 wxWindow
* wxFrameManager::GetManagedWindow() const
757 wxDockArt
* wxFrameManager::GetArtProvider() const
762 void wxFrameManager::ProcessMgrEvent(wxFrameManagerEvent
& event
)
764 // first, give the owner frame a chance to override
767 if (m_frame
->ProcessEvent(event
))
774 // SetArtProvider() instructs wxFrameManager to use the
775 // specified art provider for all drawing calls. This allows
776 // plugable look-and-feel features. The pointer that is
777 // passed to this method subsequently belongs to wxFrameManager,
778 // and is deleted in the frame manager destructor
779 void wxFrameManager::SetArtProvider(wxDockArt
* art_provider
)
781 // delete the last art provider, if any
784 // assign the new art provider
785 m_art
= art_provider
;
789 bool wxFrameManager::AddPane(wxWindow
* window
, const wxPaneInfo
& pane_info
)
791 // check if the pane has a valid window
795 // check if the pane already exists
796 if (GetPane(pane_info
.window
).IsOk())
799 m_panes
.Add(pane_info
);
801 wxPaneInfo
& pinfo
= m_panes
.Last();
803 // set the pane window
804 pinfo
.window
= window
;
806 // if the pane's name identifier is blank, create a random string
807 if (pinfo
.name
.empty())
809 pinfo
.name
.Printf(wxT("%08lx%08x%08x%08lx"),
810 ((unsigned long)pinfo
.window
) & 0xffffffff,
811 (unsigned int)time(NULL
),
813 (unsigned int)GetTickCount(),
815 (unsigned int)clock(),
817 (unsigned long)m_panes
.GetCount());
820 // set initial proportion (if not already set)
821 if (pinfo
.dock_proportion
== 0)
822 pinfo
.dock_proportion
= 100000;
824 if (pinfo
.HasCloseButton() &&
825 pinfo
.buttons
.size() == 0)
828 button
.button_id
= wxAUI_BUTTON_CLOSE
;
829 pinfo
.buttons
.Add(button
);
832 if (pinfo
.best_size
== wxDefaultSize
&&
835 pinfo
.best_size
= pinfo
.window
->GetClientSize();
837 if (pinfo
.window
->IsKindOf(CLASSINFO(wxToolBar
)))
839 // GetClientSize() doesn't get the best size for
840 // a toolbar under some newer versions of wxWidgets,
841 // so use GetBestSize()
842 pinfo
.best_size
= pinfo
.window
->GetBestSize();
844 // for some reason, wxToolBar::GetBestSize() is returning
845 // a size that is a pixel shy of the correct amount.
846 // I believe this to be the correct action, until
847 // wxToolBar::GetBestSize() is fixed. Is this assumption
852 if (pinfo
.min_size
!= wxDefaultSize
)
854 if (pinfo
.best_size
.x
< pinfo
.min_size
.x
)
855 pinfo
.best_size
.x
= pinfo
.min_size
.x
;
856 if (pinfo
.best_size
.y
< pinfo
.min_size
.y
)
857 pinfo
.best_size
.y
= pinfo
.min_size
.y
;
864 bool wxFrameManager::AddPane(wxWindow
* window
,
866 const wxString
& caption
)
869 pinfo
.Caption(caption
);
872 case wxTOP
: pinfo
.Top(); break;
873 case wxBOTTOM
: pinfo
.Bottom(); break;
874 case wxLEFT
: pinfo
.Left(); break;
875 case wxRIGHT
: pinfo
.Right(); break;
876 case wxCENTER
: pinfo
.CenterPane(); break;
878 return AddPane(window
, pinfo
);
881 bool wxFrameManager::AddPane(wxWindow
* window
,
882 const wxPaneInfo
& pane_info
,
883 const wxPoint
& drop_pos
)
885 if (!AddPane(window
, pane_info
))
888 wxPaneInfo
& pane
= GetPane(window
);
890 DoDrop(m_docks
, m_panes
, pane
, drop_pos
, wxPoint(0,0));
895 bool wxFrameManager::InsertPane(wxWindow
* window
, const wxPaneInfo
& pane_info
,
898 // shift the panes around, depending on the insert level
899 switch (insert_level
)
901 case wxAUI_INSERT_PANE
:
902 DoInsertPane(m_panes
,
903 pane_info
.dock_direction
,
904 pane_info
.dock_layer
,
908 case wxAUI_INSERT_ROW
:
909 DoInsertDockRow(m_panes
,
910 pane_info
.dock_direction
,
911 pane_info
.dock_layer
,
914 case wxAUI_INSERT_DOCK
:
915 DoInsertDockLayer(m_panes
,
916 pane_info
.dock_direction
,
917 pane_info
.dock_layer
);
921 // if the window already exists, we are basically just moving/inserting the
922 // existing window. If it doesn't exist, we need to add it and insert it
923 wxPaneInfo
& existing_pane
= GetPane(window
);
924 if (!existing_pane
.IsOk())
926 return AddPane(window
, pane_info
);
930 if (pane_info
.IsFloating())
932 existing_pane
.Float();
933 if (pane_info
.floating_pos
!= wxDefaultPosition
)
934 existing_pane
.FloatingPosition(pane_info
.floating_pos
);
935 if (pane_info
.floating_size
!= wxDefaultSize
)
936 existing_pane
.FloatingSize(pane_info
.floating_size
);
940 existing_pane
.Direction(pane_info
.dock_direction
);
941 existing_pane
.Layer(pane_info
.dock_layer
);
942 existing_pane
.Row(pane_info
.dock_row
);
943 existing_pane
.Position(pane_info
.dock_pos
);
951 // DetachPane() removes a pane from the frame manager. This
952 // method will not destroy the window that is removed.
953 bool wxFrameManager::DetachPane(wxWindow
* window
)
956 for (i
= 0, count
= m_panes
.GetCount(); i
< count
; ++i
)
958 wxPaneInfo
& p
= m_panes
.Item(i
);
959 if (p
.window
== window
)
963 // we have a floating frame which is being detached. We need to
964 // reparent it to m_frame and destroy the floating frame
967 p
.window
->SetSize(1,1);
969 if (p
.frame
->IsShown())
970 p
.frame
->Show(false);
972 // reparent to m_frame and destroy the pane
973 p
.window
->Reparent(m_frame
);
974 p
.frame
->SetSizer(NULL
);
979 // make sure there are no references to this pane in our uiparts,
980 // just in case the caller doesn't call Update() immediately after
981 // the DetachPane() call. This prevets obscure crashes which would
982 // happen at window repaint if the caller forgets to call Update()
984 for (pi
= 0, part_count
= (int)m_uiparts
.GetCount(); pi
< part_count
; ++pi
)
986 wxDockUIPart
& part
= m_uiparts
.Item(pi
);
989 m_uiparts
.RemoveAt(pi
);
1003 // ClosePane() destroys or hides the pane depending on its
1005 void wxFrameManager::ClosePane(wxPaneInfo
& pane_info
)
1007 // first, hide the window
1008 if (pane_info
.window
&& pane_info
.window
->IsShown()) {
1009 pane_info
.window
->Show(false);
1012 // make sure that we are the parent of this window
1013 if(pane_info
.window
&& pane_info
.window
->GetParent() != m_frame
) {
1014 pane_info
.window
->Reparent(m_frame
);
1017 // if we have a frame, destroy it
1018 if(pane_info
.frame
) {
1019 pane_info
.frame
->Destroy();
1020 pane_info
.frame
= NULL
;
1023 // now we need to either destroy or hide the pane
1024 if(pane_info
.IsDestroyOnClose())
1026 wxWindow
* window
= pane_info
.window
;
1038 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
1039 // in the input string. This is an internal functions which is
1040 // used for saving perspectives
1041 static wxString
EscapeDelimiters(const wxString
& s
)
1044 result
.Alloc(s
.length());
1045 const wxChar
* ch
= s
.c_str();
1048 if (*ch
== wxT(';') || *ch
== wxT('|'))
1049 result
+= wxT('\\');
1056 wxString
wxFrameManager::SavePaneInfo(wxPaneInfo
& pane
)
1058 wxString result
= wxT("name=");
1059 result
+= EscapeDelimiters(pane
.name
);
1062 result
+= wxT("caption=");
1063 result
+= EscapeDelimiters(pane
.caption
);
1066 result
+= wxString::Format(wxT("state=%u;"), pane
.state
);
1067 result
+= wxString::Format(wxT("dir=%d;"), pane
.dock_direction
);
1068 result
+= wxString::Format(wxT("layer=%d;"), pane
.dock_layer
);
1069 result
+= wxString::Format(wxT("row=%d;"), pane
.dock_row
);
1070 result
+= wxString::Format(wxT("pos=%d;"), pane
.dock_pos
);
1071 result
+= wxString::Format(wxT("prop=%d;"), pane
.dock_proportion
);
1072 result
+= wxString::Format(wxT("bestw=%d;"), pane
.best_size
.x
);
1073 result
+= wxString::Format(wxT("besth=%d;"), pane
.best_size
.y
);
1074 result
+= wxString::Format(wxT("minw=%d;"), pane
.min_size
.x
);
1075 result
+= wxString::Format(wxT("minh=%d;"), pane
.min_size
.y
);
1076 result
+= wxString::Format(wxT("maxw=%d;"), pane
.max_size
.x
);
1077 result
+= wxString::Format(wxT("maxh=%d;"), pane
.max_size
.y
);
1078 result
+= wxString::Format(wxT("floatx=%d;"), pane
.floating_pos
.x
);
1079 result
+= wxString::Format(wxT("floaty=%d;"), pane
.floating_pos
.y
);
1080 result
+= wxString::Format(wxT("floatw=%d;"), pane
.floating_size
.x
);
1081 result
+= wxString::Format(wxT("floath=%d"), pane
.floating_size
.y
);
1086 // Load a "pane" with the pane infor settings in pane_part
1087 void wxFrameManager::LoadPaneInfo(wxString pane_part
, wxPaneInfo
&pane
)
1089 // replace escaped characters so we can
1090 // split up the string easily
1091 pane_part
.Replace(wxT("\\|"), wxT("\a"));
1092 pane_part
.Replace(wxT("\\;"), wxT("\b"));
1096 wxString val_part
= pane_part
.BeforeFirst(wxT(';'));
1097 pane_part
= pane_part
.AfterFirst(wxT(';'));
1098 wxString val_name
= val_part
.BeforeFirst(wxT('='));
1099 wxString value
= val_part
.AfterFirst(wxT('='));
1100 val_name
.MakeLower();
1101 val_name
.Trim(true);
1102 val_name
.Trim(false);
1106 if (val_name
.empty())
1109 if (val_name
== wxT("name"))
1111 else if (val_name
== wxT("caption"))
1112 pane
.caption
= value
;
1113 else if (val_name
== wxT("state"))
1114 pane
.state
= (unsigned int)wxAtoi(value
.c_str());
1115 else if (val_name
== wxT("dir"))
1116 pane
.dock_direction
= wxAtoi(value
.c_str());
1117 else if (val_name
== wxT("layer"))
1118 pane
.dock_layer
= wxAtoi(value
.c_str());
1119 else if (val_name
== wxT("row"))
1120 pane
.dock_row
= wxAtoi(value
.c_str());
1121 else if (val_name
== wxT("pos"))
1122 pane
.dock_pos
= wxAtoi(value
.c_str());
1123 else if (val_name
== wxT("prop"))
1124 pane
.dock_proportion
= wxAtoi(value
.c_str());
1125 else if (val_name
== wxT("bestw"))
1126 pane
.best_size
.x
= wxAtoi(value
.c_str());
1127 else if (val_name
== wxT("besth"))
1128 pane
.best_size
.y
= wxAtoi(value
.c_str());
1129 else if (val_name
== wxT("minw"))
1130 pane
.min_size
.x
= wxAtoi(value
.c_str());
1131 else if (val_name
== wxT("minh"))
1132 pane
.min_size
.y
= wxAtoi(value
.c_str());
1133 else if (val_name
== wxT("maxw"))
1134 pane
.max_size
.x
= wxAtoi(value
.c_str());
1135 else if (val_name
== wxT("maxh"))
1136 pane
.max_size
.y
= wxAtoi(value
.c_str());
1137 else if (val_name
== wxT("floatx"))
1138 pane
.floating_pos
.x
= wxAtoi(value
.c_str());
1139 else if (val_name
== wxT("floaty"))
1140 pane
.floating_pos
.y
= wxAtoi(value
.c_str());
1141 else if (val_name
== wxT("floatw"))
1142 pane
.floating_size
.x
= wxAtoi(value
.c_str());
1143 else if (val_name
== wxT("floath"))
1144 pane
.floating_size
.y
= wxAtoi(value
.c_str());
1146 wxFAIL_MSG(wxT("Bad Perspective String"));
1150 // replace escaped characters so we can
1151 // split up the string easily
1152 pane
.name
.Replace(wxT("\a"), wxT("|"));
1153 pane
.name
.Replace(wxT("\b"), wxT(";"));
1154 pane
.caption
.Replace(wxT("\a"), wxT("|"));
1155 pane
.caption
.Replace(wxT("\b"), wxT(";"));
1156 pane_part
.Replace(wxT("\a"), wxT("|"));
1157 pane_part
.Replace(wxT("\b"), wxT(";"));
1163 // SavePerspective() saves all pane information as a single string.
1164 // This string may later be fed into LoadPerspective() to restore
1165 // all pane settings. This save and load mechanism allows an
1166 // exact pane configuration to be saved and restored at a later time
1168 wxString
wxFrameManager::SavePerspective()
1172 result
= wxT("layout1|");
1174 int pane_i
, pane_count
= m_panes
.GetCount();
1175 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1177 wxPaneInfo
& pane
= m_panes
.Item(pane_i
);
1178 result
+= SavePaneInfo(pane
)+wxT("|");
1181 int dock_i
, dock_count
= m_docks
.GetCount();
1182 for (dock_i
= 0; dock_i
< dock_count
; ++dock_i
)
1184 wxDockInfo
& dock
= m_docks
.Item(dock_i
);
1186 result
+= wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1187 dock
.dock_direction
, dock
.dock_layer
,
1188 dock
.dock_row
, dock
.size
);
1194 // LoadPerspective() loads a layout which was saved with SavePerspective()
1195 // If the "update" flag parameter is true, the GUI will immediately be updated
1197 bool wxFrameManager::LoadPerspective(const wxString
& layout
, bool update
)
1199 wxString input
= layout
;
1202 // check layout string version
1203 part
= input
.BeforeFirst(wxT('|'));
1204 input
= input
.AfterFirst(wxT('|'));
1207 if (part
!= wxT("layout1"))
1210 // mark all panes currently managed as docked and hidden
1211 int pane_i
, pane_count
= m_panes
.GetCount();
1212 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1213 m_panes
.Item(pane_i
).Dock().Hide();
1215 // clear out the dock array; this will be reconstructed
1218 // replace escaped characters so we can
1219 // split up the string easily
1220 input
.Replace(wxT("\\|"), wxT("\a"));
1221 input
.Replace(wxT("\\;"), wxT("\b"));
1227 wxString pane_part
= input
.BeforeFirst(wxT('|'));
1228 input
= input
.AfterFirst(wxT('|'));
1229 pane_part
.Trim(true);
1231 // if the string is empty, we're done parsing
1232 if (pane_part
.empty())
1235 if (pane_part
.Left(9) == wxT("dock_size"))
1237 wxString val_name
= pane_part
.BeforeFirst(wxT('='));
1238 wxString value
= pane_part
.AfterFirst(wxT('='));
1240 long dir
, layer
, row
, size
;
1241 wxString piece
= val_name
.AfterFirst(wxT('('));
1242 piece
= piece
.BeforeLast(wxT(')'));
1243 piece
.BeforeFirst(wxT(',')).ToLong(&dir
);
1244 piece
= piece
.AfterFirst(wxT(','));
1245 piece
.BeforeFirst(wxT(',')).ToLong(&layer
);
1246 piece
.AfterFirst(wxT(',')).ToLong(&row
);
1247 value
.ToLong(&size
);
1250 dock
.dock_direction
= dir
;
1251 dock
.dock_layer
= layer
;
1252 dock
.dock_row
= row
;
1258 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1259 // name so it can be called by external callers
1260 pane_part
.Replace(wxT("\a"), wxT("|"));
1261 pane_part
.Replace(wxT("\b"), wxT(";"));
1263 LoadPaneInfo(pane_part
, pane
);
1265 wxPaneInfo
& p
= GetPane(pane
.name
);
1268 // the pane window couldn't be found
1269 // in the existing layout
1283 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo
& dock
,
1284 wxArrayInt
& positions
,
1287 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1288 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1289 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1294 int offset
, action_pane
= -1;
1295 int pane_i
, pane_count
= dock
.panes
.GetCount();
1297 // find the pane marked as our action pane
1298 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1300 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1302 if (pane
.state
& wxPaneInfo::actionPane
)
1304 wxASSERT_MSG(action_pane
==-1, wxT("Too many fixed action panes"));
1305 action_pane
= pane_i
;
1309 // set up each panes default position, and
1310 // determine the size (width or height, depending
1311 // on the dock's orientation) of each pane
1312 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1314 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1315 positions
.Add(pane
.dock_pos
);
1318 if (pane
.HasBorder())
1319 size
+= (pane_border_size
*2);
1321 if (dock
.IsHorizontal())
1323 if (pane
.HasGripper() && !pane
.HasGripperTop())
1324 size
+= gripper_size
;
1325 size
+= pane
.best_size
.x
;
1329 if (pane
.HasGripper() && pane
.HasGripperTop())
1330 size
+= gripper_size
;
1332 if (pane
.HasCaption())
1333 size
+= caption_size
;
1334 size
+= pane
.best_size
.y
;
1340 // if there is no action pane, just return the default
1341 // positions (as specified in pane.pane_pos)
1342 if (action_pane
== -1)
1346 for (pane_i
= action_pane
-1; pane_i
>= 0; --pane_i
)
1348 int amount
= positions
[pane_i
+1] - (positions
[pane_i
] + sizes
[pane_i
]);
1353 positions
[pane_i
] -= -amount
;
1355 offset
+= sizes
[pane_i
];
1358 // if the dock mode is fixed, make sure none of the panes
1359 // overlap; we will bump panes that overlap
1361 for (pane_i
= action_pane
; pane_i
< pane_count
; ++pane_i
)
1363 int amount
= positions
[pane_i
] - offset
;
1367 positions
[pane_i
] += -amount
;
1369 offset
+= sizes
[pane_i
];
1374 void wxFrameManager::LayoutAddPane(wxSizer
* cont
,
1377 wxDockUIPartArray
& uiparts
,
1381 wxSizerItem
* sizer_item
;
1383 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1384 int gripper_size
= m_art
->GetMetric(wxAUI_ART_GRIPPER_SIZE
);
1385 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1386 int pane_button_size
= m_art
->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE
);
1388 // find out the orientation of the item (orientation for panes
1389 // is the same as the dock's orientation)
1391 if (dock
.IsHorizontal())
1392 orientation
= wxHORIZONTAL
;
1394 orientation
= wxVERTICAL
;
1396 // this variable will store the proportion
1397 // value that the pane will receive
1398 int pane_proportion
= pane
.dock_proportion
;
1400 wxBoxSizer
* horz_pane_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1401 wxBoxSizer
* vert_pane_sizer
= new wxBoxSizer(wxVERTICAL
);
1403 if (pane
.HasGripper())
1405 if (pane
.HasGripperTop())
1406 sizer_item
= vert_pane_sizer
->Add(1, gripper_size
, 0, wxEXPAND
);
1408 sizer_item
= horz_pane_sizer
->Add(gripper_size
, 1, 0, wxEXPAND
);
1410 part
.type
= wxDockUIPart::typeGripper
;
1414 part
.orientation
= orientation
;
1415 part
.cont_sizer
= horz_pane_sizer
;
1416 part
.sizer_item
= sizer_item
;
1420 if (pane
.HasCaption())
1422 // create the caption sizer
1423 wxBoxSizer
* caption_sizer
= new wxBoxSizer(wxHORIZONTAL
);
1425 sizer_item
= caption_sizer
->Add(1, caption_size
, 1, wxEXPAND
);
1427 part
.type
= wxDockUIPart::typeCaption
;
1431 part
.orientation
= orientation
;
1432 part
.cont_sizer
= vert_pane_sizer
;
1433 part
.sizer_item
= sizer_item
;
1434 int caption_part_idx
= uiparts
.GetCount();
1437 // add pane buttons to the caption
1438 int i
, button_count
;
1439 for (i
= 0, button_count
= pane
.buttons
.GetCount();
1440 i
< button_count
; ++i
)
1442 wxPaneButton
& button
= pane
.buttons
.Item(i
);
1444 sizer_item
= caption_sizer
->Add(pane_button_size
,
1448 part
.type
= wxDockUIPart::typePaneButton
;
1451 part
.button
= &button
;
1452 part
.orientation
= orientation
;
1453 part
.cont_sizer
= caption_sizer
;
1454 part
.sizer_item
= sizer_item
;
1458 // add the caption sizer
1459 sizer_item
= vert_pane_sizer
->Add(caption_sizer
, 0, wxEXPAND
);
1461 uiparts
.Item(caption_part_idx
).sizer_item
= sizer_item
;
1464 // add the pane window itself
1467 sizer_item
= vert_pane_sizer
->Add(1, 1, 1, wxEXPAND
);
1471 sizer_item
= vert_pane_sizer
->Add(pane
.window
, 1, wxEXPAND
);
1472 // Don't do this because it breaks the pane size in floating windows
1473 // BIW: Right now commenting this out is causing problems with
1474 // an mdi client window as the center pane.
1475 vert_pane_sizer
->SetItemMinSize(pane
.window
, 1, 1);
1478 part
.type
= wxDockUIPart::typePane
;
1482 part
.orientation
= orientation
;
1483 part
.cont_sizer
= vert_pane_sizer
;
1484 part
.sizer_item
= sizer_item
;
1488 // determine if the pane should have a minimum size; if the pane is
1489 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1490 // if the pane.min_size is set, we must use that value as well
1492 wxSize min_size
= pane
.min_size
;
1495 if (min_size
== wxDefaultSize
)
1497 min_size
= pane
.best_size
;
1498 pane_proportion
= 0;
1502 if (min_size
!= wxDefaultSize
)
1504 vert_pane_sizer
->SetItemMinSize(
1505 vert_pane_sizer
->GetChildren().GetCount()-1,
1506 min_size
.x
, min_size
.y
);
1510 // add the verticle sizer (caption, pane window) to the
1511 // horizontal sizer (gripper, verticle sizer)
1512 horz_pane_sizer
->Add(vert_pane_sizer
, 1, wxEXPAND
);
1514 // finally, add the pane sizer to the dock sizer
1516 if (pane
.HasBorder())
1518 // allowing space for the pane's border
1519 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
,
1520 wxEXPAND
| wxALL
, pane_border_size
);
1522 part
.type
= wxDockUIPart::typePaneBorder
;
1526 part
.orientation
= orientation
;
1527 part
.cont_sizer
= cont
;
1528 part
.sizer_item
= sizer_item
;
1533 sizer_item
= cont
->Add(horz_pane_sizer
, pane_proportion
, wxEXPAND
);
1537 void wxFrameManager::LayoutAddDock(wxSizer
* cont
,
1539 wxDockUIPartArray
& uiparts
,
1542 wxSizerItem
* sizer_item
;
1545 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
1546 int orientation
= dock
.IsHorizontal() ? wxHORIZONTAL
: wxVERTICAL
;
1548 // resizable bottom and right docks have a sash before them
1549 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_BOTTOM
||
1550 dock
.dock_direction
== wxAUI_DOCK_RIGHT
))
1552 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1554 part
.type
= wxDockUIPart::typeDockSizer
;
1555 part
.orientation
= orientation
;
1559 part
.cont_sizer
= cont
;
1560 part
.sizer_item
= sizer_item
;
1564 // create the sizer for the dock
1565 wxSizer
* dock_sizer
= new wxBoxSizer(orientation
);
1567 // add each pane to the dock
1568 int pane_i
, pane_count
= dock
.panes
.GetCount();
1572 wxArrayInt pane_positions
, pane_sizes
;
1574 // figure out the real pane positions we will
1575 // use, without modifying the each pane's pane_pos member
1576 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1579 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1581 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1582 int pane_pos
= pane_positions
.Item(pane_i
);
1584 int amount
= pane_pos
- offset
;
1587 if (dock
.IsVertical())
1588 sizer_item
= dock_sizer
->Add(1, amount
, 0, wxEXPAND
);
1590 sizer_item
= dock_sizer
->Add(amount
, 1, 0, wxEXPAND
);
1592 part
.type
= wxDockUIPart::typeBackground
;
1596 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1597 part
.cont_sizer
= dock_sizer
;
1598 part
.sizer_item
= sizer_item
;
1604 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1606 offset
+= pane_sizes
.Item(pane_i
);
1609 // at the end add a very small stretchable background area
1610 sizer_item
= dock_sizer
->Add(1,1, 1, wxEXPAND
);
1612 part
.type
= wxDockUIPart::typeBackground
;
1616 part
.orientation
= orientation
;
1617 part
.cont_sizer
= dock_sizer
;
1618 part
.sizer_item
= sizer_item
;
1623 for (pane_i
= 0; pane_i
< pane_count
; ++pane_i
)
1625 wxPaneInfo
& pane
= *(dock
.panes
.Item(pane_i
));
1627 // if this is not the first pane being added,
1628 // we need to add a pane sizer
1631 sizer_item
= dock_sizer
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1633 part
.type
= wxDockUIPart::typePaneSizer
;
1635 part
.pane
= dock
.panes
.Item(pane_i
-1);
1637 part
.orientation
= (orientation
==wxHORIZONTAL
) ? wxVERTICAL
:wxHORIZONTAL
;
1638 part
.cont_sizer
= dock_sizer
;
1639 part
.sizer_item
= sizer_item
;
1643 LayoutAddPane(dock_sizer
, dock
, pane
, uiparts
, spacer_only
);
1647 if (dock
.dock_direction
== wxAUI_DOCK_CENTER
)
1648 sizer_item
= cont
->Add(dock_sizer
, 1, wxEXPAND
);
1650 sizer_item
= cont
->Add(dock_sizer
, 0, wxEXPAND
);
1652 part
.type
= wxDockUIPart::typeDock
;
1656 part
.orientation
= orientation
;
1657 part
.cont_sizer
= cont
;
1658 part
.sizer_item
= sizer_item
;
1661 if (dock
.IsHorizontal())
1662 cont
->SetItemMinSize(dock_sizer
, 0, dock
.size
);
1664 cont
->SetItemMinSize(dock_sizer
, dock
.size
, 0);
1666 // top and left docks have a sash after them
1667 if (!dock
.fixed
&& (dock
.dock_direction
== wxAUI_DOCK_TOP
||
1668 dock
.dock_direction
== wxAUI_DOCK_LEFT
))
1670 sizer_item
= cont
->Add(sash_size
, sash_size
, 0, wxEXPAND
);
1672 part
.type
= wxDockUIPart::typeDockSizer
;
1676 part
.orientation
= orientation
;
1677 part
.cont_sizer
= cont
;
1678 part
.sizer_item
= sizer_item
;
1683 wxSizer
* wxFrameManager::LayoutAll(wxPaneInfoArray
& panes
,
1684 wxDockInfoArray
& docks
,
1685 wxDockUIPartArray
& uiparts
,
1688 wxBoxSizer
* container
= new wxBoxSizer(wxVERTICAL
);
1690 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
1691 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
1692 wxSize cli_size
= m_frame
->GetClientSize();
1693 int i
, dock_count
, pane_count
;
1696 // empty all docks out
1697 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1698 docks
.Item(i
).panes
.Empty();
1700 // iterate through all known panes, filing each
1701 // of them into the appropriate dock. If the
1702 // pane does not exist in the dock, add it
1703 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
1705 wxPaneInfo
& p
= panes
.Item(i
);
1707 // find any docks in this layer
1709 wxDockInfoPtrArray arr
;
1710 FindDocks(docks
, p
.dock_direction
, p
.dock_layer
, p
.dock_row
, arr
);
1712 if (arr
.GetCount() > 0)
1718 // dock was not found, so we need to create a new one
1720 d
.dock_direction
= p
.dock_direction
;
1721 d
.dock_layer
= p
.dock_layer
;
1722 d
.dock_row
= p
.dock_row
;
1724 dock
= &docks
.Last();
1728 if (p
.IsDocked() && p
.IsShown())
1730 // remove the pane from any existing docks except this one
1731 RemovePaneFromDocks(docks
, p
, dock
);
1733 // pane needs to be added to the dock,
1734 // if it doesn't already exist
1735 if (!FindPaneInDock(*dock
, p
.window
))
1736 dock
->panes
.Add(&p
);
1740 // remove the pane from any existing docks
1741 RemovePaneFromDocks(docks
, p
);
1746 // remove any empty docks
1747 for (i
= docks
.GetCount()-1; i
>= 0; --i
)
1749 if (docks
.Item(i
).panes
.GetCount() == 0)
1753 // configure the docks further
1754 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
1756 wxDockInfo
& dock
= docks
.Item(i
);
1757 int j
, dock_pane_count
= dock
.panes
.GetCount();
1759 // sort the dock pane array by the pane's
1760 // dock position (dock_pos), in ascending order
1761 dock
.panes
.Sort(PaneSortFunc
);
1763 // for newly created docks, set up their initial size
1768 for (j
= 0; j
< dock_pane_count
; ++j
)
1770 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1771 wxSize pane_size
= pane
.best_size
;
1772 if (pane_size
== wxDefaultSize
)
1773 pane_size
= pane
.min_size
;
1774 if (pane_size
== wxDefaultSize
)
1775 pane_size
= pane
.window
->GetSize();
1777 if (dock
.IsHorizontal())
1778 size
= wxMax(pane_size
.y
, size
);
1780 size
= wxMax(pane_size
.x
, size
);
1783 // add space for the border (two times), but only
1784 // if at least one pane inside the dock has a pane border
1785 for (j
= 0; j
< dock_pane_count
; ++j
)
1787 if (dock
.panes
.Item(j
)->HasBorder())
1789 size
+= (pane_border_size
*2);
1794 // if pane is on the top or bottom, add the caption height,
1795 // but only if at least one pane inside the dock has a caption
1796 if (dock
.IsHorizontal())
1798 for (j
= 0; j
< dock_pane_count
; ++j
)
1800 if (dock
.panes
.Item(j
)->HasCaption())
1802 size
+= caption_size
;
1808 // new dock's size may not be more than 1/3 of the frame size
1809 if (dock
.IsHorizontal())
1810 size
= wxMin(size
, cli_size
.y
/3);
1812 size
= wxMin(size
, cli_size
.x
/3);
1820 // determine the dock's minimum size
1821 bool plus_border
= false;
1822 bool plus_caption
= false;
1823 int dock_min_size
= 0;
1824 for (j
= 0; j
< dock_pane_count
; ++j
)
1826 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1827 if (pane
.min_size
!= wxDefaultSize
)
1829 if (pane
.HasBorder())
1831 if (pane
.HasCaption())
1832 plus_caption
= true;
1833 if (dock
.IsHorizontal())
1835 if (pane
.min_size
.y
> dock_min_size
)
1836 dock_min_size
= pane
.min_size
.y
;
1840 if (pane
.min_size
.x
> dock_min_size
)
1841 dock_min_size
= pane
.min_size
.x
;
1847 dock_min_size
+= (pane_border_size
*2);
1848 if (plus_caption
&& dock
.IsHorizontal())
1849 dock_min_size
+= (caption_size
);
1851 dock
.min_size
= dock_min_size
;
1854 // if the pane's current size is less than it's
1855 // minimum, increase the dock's size to it's minimum
1856 if (dock
.size
< dock
.min_size
)
1857 dock
.size
= dock
.min_size
;
1860 // determine the dock's mode (fixed or proportional);
1861 // determine whether the dock has only toolbars
1862 bool action_pane_marked
= false;
1864 dock
.toolbar
= true;
1865 for (j
= 0; j
< dock_pane_count
; ++j
)
1867 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1868 if (!pane
.IsFixed())
1870 if (!pane
.IsToolbar())
1871 dock
.toolbar
= false;
1872 if (pane
.state
& wxPaneInfo::actionPane
)
1873 action_pane_marked
= true;
1877 // if the dock mode is proportional and not fixed-pixel,
1878 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1879 // e.g. remove gaps like 1, 2, 30, 500
1882 for (j
= 0; j
< dock_pane_count
; ++j
)
1884 wxPaneInfo
& pane
= *dock
.panes
.Item(j
);
1889 // if the dock mode is fixed, and none of the panes
1890 // are being moved right now, make sure the panes
1891 // do not overlap each other. If they do, we will
1892 // adjust the panes' positions
1893 if (dock
.fixed
&& !action_pane_marked
)
1895 wxArrayInt pane_positions
, pane_sizes
;
1896 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
1899 for (j
= 0; j
< dock_pane_count
; ++j
)
1901 wxPaneInfo
& pane
= *(dock
.panes
.Item(j
));
1902 pane
.dock_pos
= pane_positions
[j
];
1904 int amount
= pane
.dock_pos
- offset
;
1908 pane
.dock_pos
+= -amount
;
1910 offset
+= pane_sizes
[j
];
1915 // discover the maximum dock layer
1917 for (i
= 0; i
< dock_count
; ++i
)
1918 max_layer
= wxMax(max_layer
, docks
.Item(i
).dock_layer
);
1921 // clear out uiparts
1924 // create a bunch of box sizers,
1925 // from the innermost level outwards.
1926 wxSizer
* cont
= NULL
;
1927 wxSizer
* middle
= NULL
;
1931 for (layer
= 0; layer
<= max_layer
; ++layer
)
1933 wxDockInfoPtrArray arr
;
1935 // find any docks in this layer
1936 FindDocks(docks
, -1, layer
, -1, arr
);
1938 // if there aren't any, skip to the next layer
1942 wxSizer
* old_cont
= cont
;
1944 // create a container which will hold this layer's
1945 // docks (top, bottom, left, right)
1946 cont
= new wxBoxSizer(wxVERTICAL
);
1949 // find any top docks in this layer
1950 FindDocks(docks
, wxAUI_DOCK_TOP
, layer
, -1, arr
);
1951 RenumberDockRows(arr
);
1954 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1955 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
1959 // fill out the middle layer (which consists
1960 // of left docks, content area and right docks)
1962 middle
= new wxBoxSizer(wxHORIZONTAL
);
1964 // find any left docks in this layer
1965 FindDocks(docks
, wxAUI_DOCK_LEFT
, layer
, -1, arr
);
1966 RenumberDockRows(arr
);
1969 for (row
= 0, row_count
= arr
.GetCount(); row
< row_count
; ++row
)
1970 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1973 // add content dock (or previous layer's sizer
1977 // find any center docks
1978 FindDocks(docks
, wxAUI_DOCK_CENTER
, -1, -1, arr
);
1981 for (row
= 0,row_count
= arr
.GetCount(); row
<row_count
; ++row
)
1982 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
1986 // there are no center docks, add a background area
1987 wxSizerItem
* sizer_item
= middle
->Add(1,1, 1, wxEXPAND
);
1989 part
.type
= wxDockUIPart::typeBackground
;
1993 part
.cont_sizer
= middle
;
1994 part
.sizer_item
= sizer_item
;
2000 middle
->Add(old_cont
, 1, wxEXPAND
);
2003 // find any right docks in this layer
2004 FindDocks(docks
, wxAUI_DOCK_RIGHT
, layer
, -1, arr
);
2005 RenumberDockRows(arr
);
2008 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2009 LayoutAddDock(middle
, *arr
.Item(row
), uiparts
, spacer_only
);
2012 cont
->Add(middle
, 1, wxEXPAND
);
2016 // find any bottom docks in this layer
2017 FindDocks(docks
, wxAUI_DOCK_BOTTOM
, layer
, -1, arr
);
2018 RenumberDockRows(arr
);
2021 for (row
= arr
.GetCount()-1; row
>= 0; --row
)
2022 LayoutAddDock(cont
, *arr
.Item(row
), uiparts
, spacer_only
);
2029 // no sizer available, because there are no docks,
2030 // therefore we will create a simple background area
2031 cont
= new wxBoxSizer(wxVERTICAL
);
2032 wxSizerItem
* sizer_item
= cont
->Add(1,1, 1, wxEXPAND
);
2034 part
.type
= wxDockUIPart::typeBackground
;
2038 part
.cont_sizer
= middle
;
2039 part
.sizer_item
= sizer_item
;
2043 container
->Add(cont
, 1, wxEXPAND
);
2048 // Update() updates the layout. Whenever changes are made to
2049 // one or more panes, this function should be called. It is the
2050 // external entry point for running the layout engine.
2052 void wxFrameManager::Update()
2055 int i
, pane_count
= m_panes
.GetCount();
2057 // delete old sizer first
2058 m_frame
->SetSizer(NULL
);
2060 // destroy floating panes which have been
2061 // redocked or are becoming non-floating
2062 for (i
= 0; i
< pane_count
; ++i
)
2064 wxPaneInfo
& p
= m_panes
.Item(i
);
2066 if (!p
.IsFloating() && p
.frame
)
2068 // because the pane is no longer in a floating, we need to
2069 // reparent it to m_frame and destroy the floating frame
2072 p
.window
->SetSize(1,1);
2075 // the following block is a workaround for bug #1531361
2076 // (see wxWidgets sourceforge page). On wxGTK (only), when
2077 // a frame is shown/hidden, a move event unfortunately
2078 // also gets fired. Because we may be dragging around
2079 // a pane, we need to cancel that action here to prevent
2080 // a spurious crash.
2081 if (m_action_window
== p
.frame
)
2083 if (wxWindow::GetCapture() == m_frame
)
2084 m_frame
->ReleaseMouse();
2085 m_action
= actionNone
;
2086 m_action_window
= NULL
;
2090 if (p
.frame
->IsShown())
2091 p
.frame
->Show(false);
2093 // reparent to m_frame and destroy the pane
2094 p
.window
->Reparent(m_frame
);
2095 p
.frame
->SetSizer(NULL
);
2102 // create a layout for all of the panes
2103 sizer
= LayoutAll(m_panes
, m_docks
, m_uiparts
, false);
2105 // hide or show panes as necessary,
2106 // and float panes as necessary
2107 for (i
= 0; i
< pane_count
; ++i
)
2109 wxPaneInfo
& p
= m_panes
.Item(i
);
2113 if (p
.frame
== NULL
)
2115 // we need to create a frame for this
2116 // pane, which has recently been floated
2117 wxFloatingPane
* frame
= CreateFloatingFrame(m_frame
, p
);
2119 #if wxCHECK_VERSION(2,7,0)
2120 // on MSW and Mac, if the owner desires transparent dragging, and
2121 // the dragging is happening right now, then the floating
2122 // window should have this style by default
2123 if (m_action
== actionDragFloatingPane
&&
2124 (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
))
2125 frame
->SetTransparent(150);
2128 frame
->SetPaneWindow(p
);
2131 if (p
.IsShown() && !frame
->IsShown())
2136 // frame already exists, make sure it's position
2137 // and size reflect the information in wxPaneInfo
2138 if (p
.frame
->GetPosition() != p
.floating_pos
)
2140 p
.frame
->SetSize(p
.floating_pos
.x
, p
.floating_pos
.y
,
2141 wxDefaultCoord
, wxDefaultCoord
,
2142 wxSIZE_USE_EXISTING
);
2143 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2146 if (p
.frame
->IsShown() != p
.IsShown())
2147 p
.frame
->Show(p
.IsShown());
2152 if (p
.window
->IsShown() != p
.IsShown())
2153 p
.window
->Show(p
.IsShown());
2156 // if "active panes" are no longer allowed, clear
2157 // any optionActive values from the pane states
2158 if ((m_flags
& wxAUI_MGR_ALLOW_ACTIVE_PANE
) == 0)
2160 p
.state
&= ~wxPaneInfo::optionActive
;
2165 // keep track of the old window rectangles so we can
2166 // refresh those windows whose rect has changed
2167 wxAuiRectArray old_pane_rects
;
2168 for (i
= 0; i
< pane_count
; ++i
)
2171 wxPaneInfo
& p
= m_panes
.Item(i
);
2173 if (p
.window
&& p
.IsShown() && p
.IsDocked())
2176 old_pane_rects
.Add(r
);
2182 // apply the new sizer
2183 m_frame
->SetSizer(sizer
);
2184 m_frame
->SetAutoLayout(false);
2189 // now that the frame layout is done, we need to check
2190 // the new pane rectangles against the old rectangles that
2191 // we saved a few lines above here. If the rectangles have
2192 // changed, the corresponding panes must also be updated
2193 for (i
= 0; i
< pane_count
; ++i
)
2195 wxPaneInfo
& p
= m_panes
.Item(i
);
2196 if (p
.window
&& p
.window
->IsShown() && p
.IsDocked())
2198 if (p
.rect
!= old_pane_rects
[i
])
2200 p
.window
->Refresh();
2209 // set frame's minimum size
2212 // N.B. More work needs to be done on frame minimum sizes;
2213 // this is some intresting code that imposes the minimum size,
2214 // but we may want to include a more flexible mechanism or
2215 // options for multiple minimum-size modes, e.g. strict or lax
2216 wxSize min_size = sizer->GetMinSize();
2217 wxSize frame_size = m_frame->GetSize();
2218 wxSize client_size = m_frame->GetClientSize();
2220 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2221 min_size.y+frame_size.y-client_size.y );
2223 m_frame->SetMinSize(minframe_size);
2225 if (frame_size.x < minframe_size.x ||
2226 frame_size.y < minframe_size.y)
2227 sizer->Fit(m_frame);
2232 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2233 // on the frame's main sizer, then measures all the various UI items
2234 // and updates their internal rectangles. This should always be called
2235 // instead of calling m_frame->Layout() directly
2237 void wxFrameManager::DoFrameLayout()
2242 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2244 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2246 // get the rectangle of the UI part
2247 // originally, this code looked like this:
2248 // part.rect = wxRect(part.sizer_item->GetPosition(),
2249 // part.sizer_item->GetSize());
2250 // this worked quite well, with one exception: the mdi
2251 // client window had a "deferred" size variable
2252 // that returned the wrong size. It looks like
2253 // a bug in wx, because the former size of the window
2254 // was being returned. So, we will retrieve the part's
2255 // rectangle via other means
2258 part
.rect
= part
.sizer_item
->GetRect();
2259 int flag
= part
.sizer_item
->GetFlag();
2260 int border
= part
.sizer_item
->GetBorder();
2263 part
.rect
.y
-= border
;
2264 part
.rect
.height
+= border
;
2268 part
.rect
.x
-= border
;
2269 part
.rect
.width
+= border
;
2271 if (flag
& wxBOTTOM
)
2272 part
.rect
.height
+= border
;
2274 part
.rect
.width
+= border
;
2277 if (part
.type
== wxDockUIPart::typeDock
)
2278 part
.dock
->rect
= part
.rect
;
2279 if (part
.type
== wxDockUIPart::typePane
)
2280 part
.pane
->rect
= part
.rect
;
2284 // GetPanePart() looks up the pane the pane border UI part (or the regular
2285 // pane part if there is no border). This allows the caller to get the exact
2286 // rectangle of the pane in question, including decorations like
2287 // caption and border (if any).
2289 wxDockUIPart
* wxFrameManager::GetPanePart(wxWindow
* wnd
)
2292 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2294 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2295 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2296 part
.pane
&& part
.pane
->window
== wnd
)
2299 for (i
= 0, part_count
= m_uiparts
.GetCount(); i
< part_count
; ++i
)
2301 wxDockUIPart
& part
= m_uiparts
.Item(i
);
2302 if (part
.type
== wxDockUIPart::typePane
&&
2303 part
.pane
&& part
.pane
->window
== wnd
)
2311 // GetDockPixelOffset() is an internal function which returns
2312 // a dock's offset in pixels from the left side of the window
2313 // (for horizontal docks) or from the top of the window (for
2314 // vertical docks). This value is necessary for calculating
2315 // fixel-pane/toolbar offsets when they are dragged.
2317 int wxFrameManager::GetDockPixelOffset(wxPaneInfo
& test
)
2319 // the only way to accurately calculate the dock's
2320 // offset is to actually run a theoretical layout
2322 int i
, part_count
, dock_count
;
2323 wxDockInfoArray docks
;
2324 wxPaneInfoArray panes
;
2325 wxDockUIPartArray uiparts
;
2326 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2329 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2330 wxSize client_size
= m_frame
->GetClientSize();
2331 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2334 for (i
= 0, part_count
= uiparts
.GetCount(); i
< part_count
; ++i
)
2336 wxDockUIPart
& part
= uiparts
.Item(i
);
2337 part
.rect
= wxRect(part
.sizer_item
->GetPosition(),
2338 part
.sizer_item
->GetSize());
2339 if (part
.type
== wxDockUIPart::typeDock
)
2340 part
.dock
->rect
= part
.rect
;
2345 for (i
= 0, dock_count
= docks
.GetCount(); i
< dock_count
; ++i
)
2347 wxDockInfo
& dock
= docks
.Item(i
);
2348 if (test
.dock_direction
== dock
.dock_direction
&&
2349 test
.dock_layer
==dock
.dock_layer
&& test
.dock_row
==dock
.dock_row
)
2351 if (dock
.IsVertical())
2363 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2364 // if a dock operation is allowed, the new dock position is copied into
2365 // the target info. If the operation was allowed, the function returns true.
2367 bool wxFrameManager::ProcessDockResult(wxPaneInfo
& target
,
2368 const wxPaneInfo
& new_pos
)
2370 bool allowed
= false;
2371 switch (new_pos
.dock_direction
)
2373 case wxAUI_DOCK_TOP
: allowed
= target
.IsTopDockable(); break;
2374 case wxAUI_DOCK_BOTTOM
: allowed
= target
.IsBottomDockable(); break;
2375 case wxAUI_DOCK_LEFT
: allowed
= target
.IsLeftDockable(); break;
2376 case wxAUI_DOCK_RIGHT
: allowed
= target
.IsRightDockable(); break;
2386 // DoDrop() is an important function. It basically takes a mouse position,
2387 // and determines where the pane's new position would be. If the pane is to be
2388 // dropped, it performs the drop operation using the specified dock and pane
2389 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2390 // scenario can be performed, giving precise coordinates for drop hints.
2391 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2392 // as parameters, the changes will be made to the main state arrays
2394 const int auiInsertRowPixels
= 10;
2395 const int auiNewRowPixels
= 40;
2396 const int auiLayerInsertPixels
= 40;
2397 const int auiLayerInsertOffset
= 5;
2399 bool wxFrameManager::DoDrop(wxDockInfoArray
& docks
,
2400 wxPaneInfoArray
& panes
,
2403 const wxPoint
& offset
)
2405 wxSize cli_size
= m_frame
->GetClientSize();
2407 wxPaneInfo drop
= target
;
2410 // The result should always be shown
2414 // Check to see if the pane has been dragged outside of the window
2415 // (or near to the outside of the window), if so, dock it along the edge
2418 int layer_insert_offset
= auiLayerInsertOffset
;
2419 if (target
.IsToolbar())
2420 layer_insert_offset
= 0;
2422 if (pt
.x
< layer_insert_offset
&&
2423 pt
.x
> layer_insert_offset
-auiLayerInsertPixels
)
2427 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2428 return ProcessDockResult(target
, drop
);
2430 else if (pt
.y
< layer_insert_offset
&&
2431 pt
.y
> layer_insert_offset
-auiLayerInsertPixels
)
2435 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2436 return ProcessDockResult(target
, drop
);
2438 else if (pt
.x
>= cli_size
.x
- layer_insert_offset
&&
2439 pt
.x
< cli_size
.x
- layer_insert_offset
+ auiLayerInsertPixels
)
2441 drop
.Dock().Right().
2443 Position(pt
.y
- GetDockPixelOffset(drop
) - offset
.y
);
2444 return ProcessDockResult(target
, drop
);
2446 else if (pt
.y
>= cli_size
.y
- layer_insert_offset
&&
2447 pt
.y
< cli_size
.y
- layer_insert_offset
+ auiLayerInsertPixels
)
2449 int new_layer
= wxMax( wxMax( GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2450 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2451 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
)) + 1;
2453 drop
.Dock().Bottom().
2456 Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2457 return ProcessDockResult(target
, drop
);
2460 wxDockUIPart
* part
= HitTest(pt
.x
, pt
.y
);
2463 if (drop
.IsToolbar())
2465 if (!part
|| !part
->dock
)
2468 // calculate the offset from where the dock begins
2469 // to the point where the user dropped the pane
2470 int dock_drop_offset
= 0;
2471 if (part
->dock
->IsHorizontal())
2472 dock_drop_offset
= pt
.x
- part
->dock
->rect
.x
- offset
.x
;
2474 dock_drop_offset
= pt
.y
- part
->dock
->rect
.y
- offset
.y
;
2477 // toolbars may only be moved in and to fixed-pane docks,
2478 // otherwise we will try to float the pane. Also, the pane
2479 // should float if being dragged over center pane windows
2480 if (!part
->dock
->fixed
|| part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
2482 if (m_last_rect
.IsEmpty() || m_last_rect
.Contains(pt
.x
, pt
.y
))
2488 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
2489 (drop
.IsFloatable() ||
2490 (part
->dock
->dock_direction
!= wxAUI_DOCK_CENTER
&&
2491 part
->dock
->dock_direction
!= wxAUI_DOCK_NONE
)))
2498 return ProcessDockResult(target
, drop
);
2501 drop
.Position(pt
.x
- GetDockPixelOffset(drop
) - offset
.x
);
2503 return ProcessDockResult(target
, drop
);
2512 m_last_rect
= part
->dock
->rect
;
2513 m_last_rect
.Inflate( 15, 15 );
2517 Direction(part
->dock
->dock_direction
).
2518 Layer(part
->dock
->dock_layer
).
2519 Row(part
->dock
->dock_row
).
2520 Position(dock_drop_offset
);
2523 ((pt
.y
< part
->dock
->rect
.y
+ 1) && part
->dock
->IsHorizontal()) ||
2524 ((pt
.x
< part
->dock
->rect
.x
+ 1) && part
->dock
->IsVertical())
2525 ) && part
->dock
->panes
.GetCount() > 1)
2527 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2528 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2530 int row
= drop
.dock_row
;
2531 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2532 part
->dock
->dock_layer
,
2533 part
->dock
->dock_row
);
2534 drop
.dock_row
= row
;
2538 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2539 part
->dock
->dock_layer
,
2540 part
->dock
->dock_row
+1);
2541 drop
.dock_row
= part
->dock
->dock_row
+1;
2546 ((pt
.y
> part
->dock
->rect
.y
+ part
->dock
->rect
.height
- 2 ) && part
->dock
->IsHorizontal()) ||
2547 ((pt
.x
> part
->dock
->rect
.x
+ part
->dock
->rect
.width
- 2 ) && part
->dock
->IsVertical())
2548 ) && part
->dock
->panes
.GetCount() > 1)
2550 if ((part
->dock
->dock_direction
== wxAUI_DOCK_TOP
) ||
2551 (part
->dock
->dock_direction
== wxAUI_DOCK_LEFT
))
2553 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2554 part
->dock
->dock_layer
,
2555 part
->dock
->dock_row
+1);
2556 drop
.dock_row
= part
->dock
->dock_row
+1;
2560 int row
= drop
.dock_row
;
2561 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2562 part
->dock
->dock_layer
,
2563 part
->dock
->dock_row
);
2564 drop
.dock_row
= row
;
2568 return ProcessDockResult(target
, drop
);
2577 if (part
->type
== wxDockUIPart::typePaneBorder
||
2578 part
->type
== wxDockUIPart::typeCaption
||
2579 part
->type
== wxDockUIPart::typeGripper
||
2580 part
->type
== wxDockUIPart::typePaneButton
||
2581 part
->type
== wxDockUIPart::typePane
||
2582 part
->type
== wxDockUIPart::typePaneSizer
||
2583 part
->type
== wxDockUIPart::typeDockSizer
||
2584 part
->type
== wxDockUIPart::typeBackground
)
2586 if (part
->type
== wxDockUIPart::typeDockSizer
)
2588 if (part
->dock
->panes
.GetCount() != 1)
2590 part
= GetPanePart(part
->dock
->panes
.Item(0)->window
);
2597 // If a normal frame is being dragged over a toolbar, insert it
2598 // along the edge under the toolbar, but over all other panes.
2599 // (this could be done much better, but somehow factoring this
2600 // calculation with the one at the beginning of this function)
2601 if (part
->dock
&& part
->dock
->toolbar
)
2605 switch (part
->dock
->dock_direction
)
2607 case wxAUI_DOCK_LEFT
:
2608 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_LEFT
),
2609 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
)),
2610 GetMaxLayer(docks
, wxAUI_DOCK_TOP
));
2612 case wxAUI_DOCK_TOP
:
2613 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_TOP
),
2614 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2615 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2617 case wxAUI_DOCK_RIGHT
:
2618 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
),
2619 GetMaxLayer(docks
, wxAUI_DOCK_TOP
)),
2620 GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
));
2622 case wxAUI_DOCK_BOTTOM
:
2623 layer
= wxMax(wxMax(GetMaxLayer(docks
, wxAUI_DOCK_BOTTOM
),
2624 GetMaxLayer(docks
, wxAUI_DOCK_LEFT
)),
2625 GetMaxLayer(docks
, wxAUI_DOCK_RIGHT
));
2629 DoInsertDockRow(panes
, part
->dock
->dock_direction
,
2632 Direction(part
->dock
->dock_direction
).
2633 Layer(layer
).Row(0).Position(0);
2634 return ProcessDockResult(target
, drop
);
2641 part
= GetPanePart(part
->pane
->window
);
2645 bool insert_dock_row
= false;
2646 int insert_row
= part
->pane
->dock_row
;
2647 int insert_dir
= part
->pane
->dock_direction
;
2648 int insert_layer
= part
->pane
->dock_layer
;
2650 switch (part
->pane
->dock_direction
)
2652 case wxAUI_DOCK_TOP
:
2653 if (pt
.y
>= part
->rect
.y
&&
2654 pt
.y
< part
->rect
.y
+auiInsertRowPixels
)
2655 insert_dock_row
= true;
2657 case wxAUI_DOCK_BOTTOM
:
2658 if (pt
.y
> part
->rect
.y
+part
->rect
.height
-auiInsertRowPixels
&&
2659 pt
.y
<= part
->rect
.y
+ part
->rect
.height
)
2660 insert_dock_row
= true;
2662 case wxAUI_DOCK_LEFT
:
2663 if (pt
.x
>= part
->rect
.x
&&
2664 pt
.x
< part
->rect
.x
+auiInsertRowPixels
)
2665 insert_dock_row
= true;
2667 case wxAUI_DOCK_RIGHT
:
2668 if (pt
.x
> part
->rect
.x
+part
->rect
.width
-auiInsertRowPixels
&&
2669 pt
.x
<= part
->rect
.x
+part
->rect
.width
)
2670 insert_dock_row
= true;
2672 case wxAUI_DOCK_CENTER
:
2674 // "new row pixels" will be set to the default, but
2675 // must never exceed 20% of the window size
2676 int new_row_pixels_x
= auiNewRowPixels
;
2677 int new_row_pixels_y
= auiNewRowPixels
;
2679 if (new_row_pixels_x
> (part
->rect
.width
*20)/100)
2680 new_row_pixels_x
= (part
->rect
.width
*20)/100;
2682 if (new_row_pixels_y
> (part
->rect
.height
*20)/100)
2683 new_row_pixels_y
= (part
->rect
.height
*20)/100;
2686 // determine if the mouse pointer is in a location that
2687 // will cause a new row to be inserted. The hot spot positions
2688 // are along the borders of the center pane
2691 insert_dock_row
= true;
2692 if (pt
.x
>= part
->rect
.x
&&
2693 pt
.x
< part
->rect
.x
+new_row_pixels_x
)
2694 insert_dir
= wxAUI_DOCK_LEFT
;
2696 if (pt
.y
>= part
->rect
.y
&&
2697 pt
.y
< part
->rect
.y
+new_row_pixels_y
)
2698 insert_dir
= wxAUI_DOCK_TOP
;
2700 if (pt
.x
>= part
->rect
.x
+ part
->rect
.width
-new_row_pixels_x
&&
2701 pt
.x
< part
->rect
.x
+ part
->rect
.width
)
2702 insert_dir
= wxAUI_DOCK_RIGHT
;
2704 if (pt
.y
>= part
->rect
.y
+ part
->rect
.height
-new_row_pixels_y
&&
2705 pt
.y
< part
->rect
.y
+ part
->rect
.height
)
2706 insert_dir
= wxAUI_DOCK_BOTTOM
;
2710 insert_row
= GetMaxRow(panes
, insert_dir
, insert_layer
) + 1;
2714 if (insert_dock_row
)
2716 DoInsertDockRow(panes
, insert_dir
, insert_layer
, insert_row
);
2717 drop
.Dock().Direction(insert_dir
).
2718 Layer(insert_layer
).
2721 return ProcessDockResult(target
, drop
);
2724 // determine the mouse offset and the pane size, both in the
2725 // direction of the dock itself, and perpendicular to the dock
2729 if (part
->orientation
== wxVERTICAL
)
2731 offset
= pt
.y
- part
->rect
.y
;
2732 size
= part
->rect
.GetHeight();
2736 offset
= pt
.x
- part
->rect
.x
;
2737 size
= part
->rect
.GetWidth();
2740 int drop_position
= part
->pane
->dock_pos
;
2742 // if we are in the top/left part of the pane,
2743 // insert the pane before the pane being hovered over
2744 if (offset
<= size
/2)
2746 drop_position
= part
->pane
->dock_pos
;
2748 part
->pane
->dock_direction
,
2749 part
->pane
->dock_layer
,
2750 part
->pane
->dock_row
,
2751 part
->pane
->dock_pos
);
2754 // if we are in the bottom/right part of the pane,
2755 // insert the pane before the pane being hovered over
2756 if (offset
> size
/2)
2758 drop_position
= part
->pane
->dock_pos
+1;
2760 part
->pane
->dock_direction
,
2761 part
->pane
->dock_layer
,
2762 part
->pane
->dock_row
,
2763 part
->pane
->dock_pos
+1);
2767 Direction(part
->dock
->dock_direction
).
2768 Layer(part
->dock
->dock_layer
).
2769 Row(part
->dock
->dock_row
).
2770 Position(drop_position
);
2771 return ProcessDockResult(target
, drop
);
2778 void wxFrameManager::OnHintFadeTimer(wxTimerEvent
& WXUNUSED(event
))
2780 if (!m_hint_wnd
|| m_hint_fadeamt
>= m_hint_fademax
)
2782 m_hint_fadetimer
.Stop();
2786 m_hint_fadeamt
+= 4;
2787 #if wxCHECK_VERSION(2,7,0)
2788 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2790 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2791 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2795 void wxFrameManager::ShowHint(const wxRect
& rect
)
2799 // if the hint rect is the same as last time, don't do anything
2800 if (m_last_hint
== rect
)
2804 m_hint_fadeamt
= m_hint_fademax
;
2806 if ((m_flags
& wxAUI_MGR_HINT_FADE
)
2807 && !((m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
))) &&
2808 (m_flags
& wxAUI_MGR_NO_VENETIAN_BLINDS_FADE
))
2812 m_hint_wnd
->SetSize(rect
);
2814 if (!m_hint_wnd
->IsShown())
2817 // if we are dragging a floating pane, set the focus
2818 // back to that floating pane (otherwise it becomes unfocused)
2819 if (m_action
== actionDragFloatingPane
&& m_action_window
)
2820 m_action_window
->SetFocus();
2822 #if wxCHECK_VERSION(2,7,0)
2823 m_hint_wnd
->SetTransparent(m_hint_fadeamt
);
2825 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2826 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(m_hint_fadeamt
);
2828 m_hint_wnd
->Raise();
2831 if (m_hint_fadeamt
!= m_hint_fademax
) // Only fade if we need to
2833 // start fade in timer
2834 m_hint_fadetimer
.SetOwner(this, 101);
2835 m_hint_fadetimer
.Start(5);
2838 else // Not using a transparent hint window...
2840 if (!(m_flags
& wxAUI_MGR_RECTANGLE_HINT
))
2843 if (m_last_hint
!= rect
)
2845 // remove the last hint rectangle
2851 wxScreenDC screendc
;
2852 wxRegion
clip(1, 1, 10000, 10000);
2854 // clip all floating windows, so we don't draw over them
2856 for (i
= 0, pane_count
= m_panes
.GetCount(); i
< pane_count
; ++i
)
2858 wxPaneInfo
& pane
= m_panes
.Item(i
);
2860 if (pane
.IsFloating() &&
2861 pane
.frame
->IsShown())
2863 wxRect rect
= pane
.frame
->GetRect();
2865 // wxGTK returns the client size, not the whole frame size
2871 clip
.Subtract(rect
);
2875 // As we can only hide the hint by redrawing the managed window, we
2876 // need to clip the region to the managed window too or we get
2877 // nasty redrawn problems.
2878 clip
.Intersect(m_frame
->GetRect());
2880 screendc
.SetClippingRegion(clip
);
2882 wxBitmap stipple
= wxPaneCreateStippleBitmap();
2883 wxBrush
brush(stipple
);
2884 screendc
.SetBrush(brush
);
2885 screendc
.SetPen(*wxTRANSPARENT_PEN
);
2887 screendc
.DrawRectangle(rect
.x
, rect
.y
, 5, rect
.height
);
2888 screendc
.DrawRectangle(rect
.x
+5, rect
.y
, rect
.width
-10, 5);
2889 screendc
.DrawRectangle(rect
.x
+rect
.width
-5, rect
.y
, 5, rect
.height
);
2890 screendc
.DrawRectangle(rect
.x
+5, rect
.y
+rect
.height
-5, rect
.width
-10, 5);
2894 void wxFrameManager::HideHint()
2896 // hides a transparent window hint, if there is one
2899 if (m_hint_wnd
->IsShown())
2900 m_hint_wnd
->Show(false);
2901 #if wxCHECK_VERSION(2,7,0)
2902 m_hint_wnd
->SetTransparent(0);
2904 if (m_hint_wnd
->IsKindOf(CLASSINFO(wxPseudoTransparentFrame
)))
2905 ((wxPseudoTransparentFrame
*)m_hint_wnd
)->SetTransparent(0);
2907 m_hint_fadetimer
.Stop();
2908 m_last_hint
= wxRect();
2912 // hides a painted hint by redrawing the frame window
2913 if (!m_last_hint
.IsEmpty())
2917 m_last_hint
= wxRect();
2923 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2924 // determine the exact position the pane would be at were if dropped. If
2925 // the pame would indeed become docked at the specified drop point,
2926 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2927 // "pane_window" is the window pointer of the pane being dragged, pt is
2928 // the mouse position, in client coordinates
2929 void wxFrameManager::DrawHintRect(wxWindow
* pane_window
,
2931 const wxPoint
& offset
)
2935 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2936 // we will create a new temporary layout and then measure the resulting
2937 // rectangle; we will create a copy of the docking structures (m_dock)
2938 // so that we don't modify the real thing on screen
2940 int i
, pane_count
, part_count
;
2941 wxDockInfoArray docks
;
2942 wxPaneInfoArray panes
;
2943 wxDockUIPartArray uiparts
;
2944 wxPaneInfo hint
= GetPane(pane_window
);
2945 hint
.name
= wxT("__HINT__");
2951 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
2953 // remove any pane already there which bears the same window;
2954 // this happens when you are moving a pane around in a dock
2955 for (i
= 0, pane_count
= panes
.GetCount(); i
< pane_count
; ++i
)
2957 if (panes
.Item(i
).window
== pane_window
)
2959 RemovePaneFromDocks(docks
, panes
.Item(i
));
2965 // find out where the new pane would be
2966 if (!DoDrop(docks
, panes
, hint
, pt
, offset
))
2974 wxSizer
* sizer
= LayoutAll(panes
, docks
, uiparts
, true);
2975 wxSize client_size
= m_frame
->GetClientSize();
2976 sizer
->SetDimension(0, 0, client_size
.x
, client_size
.y
);
2979 for (i
= 0, part_count
= uiparts
.GetCount();
2980 i
< part_count
; ++i
)
2982 wxDockUIPart
& part
= uiparts
.Item(i
);
2984 if (part
.type
== wxDockUIPart::typePaneBorder
&&
2985 part
.pane
&& part
.pane
->name
== wxT("__HINT__"))
2987 rect
= wxRect(part
.sizer_item
->GetPosition(),
2988 part
.sizer_item
->GetSize());
3001 // actually show the hint rectangle on the screen
3002 m_frame
->ClientToScreen(&rect
.x
, &rect
.y
);
3006 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow
* wnd
)
3008 // try to find the pane
3009 wxPaneInfo
& pane
= GetPane(wnd
);
3010 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3012 #if wxCHECK_VERSION(2,7,0)
3013 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3014 pane
.frame
->SetTransparent(150);
3018 void wxFrameManager::OnFloatingPaneMoving(wxWindow
* wnd
, wxDirection dir
)
3020 // try to find the pane
3021 wxPaneInfo
& pane
= GetPane(wnd
);
3022 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3024 wxPoint pt
= ::wxGetMousePosition();
3027 // Adapt pt to direction
3030 // move to pane's upper border
3032 pos
= wnd
->ClientToScreen( pos
);
3034 // and some more pixels for the title bar
3039 // move to pane's left border
3041 pos
= wnd
->ClientToScreen( pos
);
3046 // move to pane's right border
3047 wxPoint
pos( wnd
->GetSize().x
, 0 );
3048 pos
= wnd
->ClientToScreen( pos
);
3053 // move to pane's bottom border
3054 wxPoint
pos( 0, wnd
->GetSize().y
);
3055 pos
= wnd
->ClientToScreen( pos
);
3062 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3064 // calculate the offset from the upper left-hand corner
3065 // of the frame to the mouse pointer
3066 wxPoint frame_pos
= pane
.frame
->GetPosition();
3067 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3069 // no hint for toolbar floating windows
3070 if (pane
.IsToolbar() && m_action
== actionDragFloatingPane
)
3072 if (m_action
== actionDragFloatingPane
)
3074 wxDockInfoArray docks
;
3075 wxPaneInfoArray panes
;
3076 wxDockUIPartArray uiparts
;
3077 wxPaneInfo hint
= pane
;
3079 CopyDocksAndPanes(docks
, panes
, m_docks
, m_panes
);
3081 // find out where the new pane would be
3082 if (!DoDrop(docks
, panes
, hint
, client_pt
))
3084 if (hint
.IsFloating())
3088 m_action
= actionDragToolbarPane
;
3089 m_action_window
= pane
.window
;
3098 // if a key modifier is pressed while dragging the frame,
3099 // don't dock the window
3100 if (wxGetKeyState(WXK_CONTROL
) || wxGetKeyState(WXK_ALT
))
3107 DrawHintRect(wnd
, client_pt
, action_offset
);
3110 // this cleans up some screen artifacts that are caused on GTK because
3111 // we aren't getting the exact size of the window (see comment
3121 void wxFrameManager::OnFloatingPaneMoved(wxWindow
* wnd
, wxDirection dir
)
3123 // try to find the pane
3124 wxPaneInfo
& pane
= GetPane(wnd
);
3125 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3127 wxPoint pt
= ::wxGetMousePosition();
3130 // Adapt pt to direction
3133 // move to pane's upper border
3135 pos
= wnd
->ClientToScreen( pos
);
3137 // and some more pixels for the title bar
3142 // move to pane's left border
3144 pos
= wnd
->ClientToScreen( pos
);
3149 // move to pane's right border
3150 wxPoint
pos( wnd
->GetSize().x
, 0 );
3151 pos
= wnd
->ClientToScreen( pos
);
3156 // move to pane's bottom border
3157 wxPoint
pos( 0, wnd
->GetSize().y
);
3158 pos
= wnd
->ClientToScreen( pos
);
3165 wxPoint client_pt
= m_frame
->ScreenToClient(pt
);
3167 // calculate the offset from the upper left-hand corner
3168 // of the frame to the mouse pointer
3169 wxPoint frame_pos
= pane
.frame
->GetPosition();
3170 wxPoint
action_offset(pt
.x
-frame_pos
.x
, pt
.y
-frame_pos
.y
);
3173 // if a key modifier is pressed while dragging the frame,
3174 // don't dock the window
3175 if (!wxGetKeyState(WXK_CONTROL
) && !wxGetKeyState(WXK_ALT
))
3177 // do the drop calculation
3178 DoDrop(m_docks
, m_panes
, pane
, client_pt
, action_offset
);
3181 // if the pane is still floating, update it's floating
3182 // position (that we store)
3183 if (pane
.IsFloating())
3185 pane
.floating_pos
= pane
.frame
->GetPosition();
3187 #if wxCHECK_VERSION(2,7,0)
3188 if (m_flags
& wxAUI_MGR_TRANSPARENT_DRAG
)
3189 pane
.frame
->SetTransparent(255);
3198 void wxFrameManager::OnFloatingPaneResized(wxWindow
* wnd
, const wxSize
& size
)
3200 // try to find the pane
3201 wxPaneInfo
& pane
= GetPane(wnd
);
3202 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3204 pane
.floating_size
= size
;
3208 void wxFrameManager::OnFloatingPaneClosed(wxWindow
* wnd
, wxCloseEvent
& evt
)
3210 // try to find the pane
3211 wxPaneInfo
& pane
= GetPane(wnd
);
3212 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3215 // fire pane close event
3216 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3218 e
.SetCanVeto(evt
.CanVeto());
3234 void wxFrameManager::OnFloatingPaneActivated(wxWindow
* wnd
)
3236 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3238 // try to find the pane
3239 wxASSERT_MSG(GetPane(wnd
).IsOk(), wxT("Pane window not found"));
3241 SetActivePane(m_panes
, wnd
);
3246 // OnRender() draws all of the pane captions, sashes,
3247 // backgrounds, captions, grippers, pane borders and buttons.
3248 // It renders the entire user interface.
3250 void wxFrameManager::OnRender(wxFrameManagerEvent
& evt
)
3252 wxDC
* dc
= evt
.GetDC();
3258 for (i
= 0, part_count
= m_uiparts
.GetCount();
3259 i
< part_count
; ++i
)
3261 wxDockUIPart
& part
= m_uiparts
.Item(i
);
3263 // don't draw hidden pane items
3264 if (part
.sizer_item
&& !part
.sizer_item
->IsShown())
3269 case wxDockUIPart::typeDockSizer
:
3270 case wxDockUIPart::typePaneSizer
:
3271 m_art
->DrawSash(*dc
, m_frame
, part
.orientation
, part
.rect
);
3273 case wxDockUIPart::typeBackground
:
3274 m_art
->DrawBackground(*dc
, m_frame
, part
.orientation
, part
.rect
);
3276 case wxDockUIPart::typeCaption
:
3277 m_art
->DrawCaption(*dc
, m_frame
, part
.pane
->caption
, part
.rect
, *part
.pane
);
3279 case wxDockUIPart::typeGripper
:
3280 m_art
->DrawGripper(*dc
, m_frame
, part
.rect
, *part
.pane
);
3282 case wxDockUIPart::typePaneBorder
:
3283 m_art
->DrawBorder(*dc
, m_frame
, part
.rect
, *part
.pane
);
3285 case wxDockUIPart::typePaneButton
:
3286 m_art
->DrawPaneButton(*dc
, m_frame
, part
.button
->button_id
,
3287 wxAUI_BUTTON_STATE_NORMAL
, part
.rect
, *part
.pane
);
3294 // Render() fire a render event, which is normally handled by
3295 // wxFrameManager::OnRender(). This allows the render function to
3296 // be overridden via the render event. This can be useful for paintin
3297 // custom graphics in the main window. Default behavior can be
3298 // invoked in the overridden function by calling OnRender()
3300 void wxFrameManager::Render(wxDC
* dc
)
3302 wxFrameManagerEvent
e(wxEVT_AUI_RENDER
);
3307 void wxFrameManager::Repaint(wxDC
* dc
)
3312 m_frame
->Refresh() ;
3318 m_frame
->GetClientSize(&w
, &h
);
3320 // figure out which dc to use; if one
3321 // has been specified, use it, otherwise
3323 wxClientDC
* client_dc
= NULL
;
3326 client_dc
= new wxClientDC(m_frame
);
3330 // if the frame has a toolbar, the client area
3331 // origin will not be (0,0).
3332 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3333 if (pt
.x
!= 0 || pt
.y
!= 0)
3334 dc
->SetDeviceOrigin(pt
.x
, pt
.y
);
3336 // render all the items
3339 // if we created a client_dc, delete it
3344 void wxFrameManager::OnPaint(wxPaintEvent
& WXUNUSED(event
))
3346 wxPaintDC
dc(m_frame
);
3350 void wxFrameManager::OnEraseBackground(wxEraseEvent
& event
)
3359 void wxFrameManager::OnSize(wxSizeEvent
& event
)
3370 void wxFrameManager::OnSetCursor(wxSetCursorEvent
& event
)
3373 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3374 wxCursor cursor
= wxNullCursor
;
3378 if (part
->type
== wxDockUIPart::typeDockSizer
||
3379 part
->type
== wxDockUIPart::typePaneSizer
)
3381 // a dock may not be resized if it has a single
3382 // pane which is not resizable
3383 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3384 part
->dock
->panes
.GetCount() == 1 &&
3385 part
->dock
->panes
.Item(0)->IsFixed())
3388 // panes that may not be resized do not get a sizing cursor
3389 if (part
->pane
&& part
->pane
->IsFixed())
3392 if (part
->orientation
== wxVERTICAL
)
3393 cursor
= wxCursor(wxCURSOR_SIZEWE
);
3395 cursor
= wxCursor(wxCURSOR_SIZENS
);
3397 else if (part
->type
== wxDockUIPart::typeGripper
)
3399 cursor
= wxCursor(wxCURSOR_SIZING
);
3403 event
.SetCursor(cursor
);
3408 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart
* button_ui_part
,
3409 const wxMouseEvent
& event
)
3411 wxDockUIPart
* hit_test
= HitTest(event
.GetX(), event
.GetY());
3413 int state
= wxAUI_BUTTON_STATE_NORMAL
;
3415 if (hit_test
== button_ui_part
)
3417 if (event
.LeftDown())
3418 state
= wxAUI_BUTTON_STATE_PRESSED
;
3420 state
= wxAUI_BUTTON_STATE_HOVER
;
3424 if (event
.LeftDown())
3425 state
= wxAUI_BUTTON_STATE_HOVER
;
3428 // now repaint the button with hover state
3429 wxClientDC
cdc(m_frame
);
3431 // if the frame has a toolbar, the client area
3432 // origin will not be (0,0).
3433 wxPoint pt
= m_frame
->GetClientAreaOrigin();
3434 if (pt
.x
!= 0 || pt
.y
!= 0)
3435 cdc
.SetDeviceOrigin(pt
.x
, pt
.y
);
3437 m_art
->DrawPaneButton(cdc
, m_frame
,
3438 button_ui_part
->button
->button_id
,
3440 button_ui_part
->rect
,
3444 void wxFrameManager::OnLeftDown(wxMouseEvent
& event
)
3446 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3449 if (part
->dock
&& part
->dock
->dock_direction
== wxAUI_DOCK_CENTER
)
3452 if (part
->type
== wxDockUIPart::typeDockSizer
||
3453 part
->type
== wxDockUIPart::typePaneSizer
)
3455 // a dock may not be resized if it has a single
3456 // pane which is not resizable
3457 if (part
->type
== wxDockUIPart::typeDockSizer
&& part
->dock
&&
3458 part
->dock
->panes
.GetCount() == 1 &&
3459 part
->dock
->panes
.Item(0)->IsFixed())
3462 // panes that may not be resized should be ignored here
3463 if (part
->pane
&& part
->pane
->IsFixed())
3466 m_action
= actionResize
;
3467 m_action_part
= part
;
3468 m_action_hintrect
= wxRect();
3469 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3470 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3471 event
.m_y
- part
->rect
.y
);
3472 m_frame
->CaptureMouse();
3474 else if (part
->type
== wxDockUIPart::typePaneButton
)
3476 m_action
= actionClickButton
;
3477 m_action_part
= part
;
3478 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3479 m_frame
->CaptureMouse();
3481 UpdateButtonOnScreen(part
, event
);
3483 else if (part
->type
== wxDockUIPart::typeCaption
||
3484 part
->type
== wxDockUIPart::typeGripper
)
3486 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3488 // set the caption as active
3489 SetActivePane(m_panes
, part
->pane
->window
);
3493 m_action
= actionClickCaption
;
3494 m_action_part
= part
;
3495 m_action_start
= wxPoint(event
.m_x
, event
.m_y
);
3496 m_action_offset
= wxPoint(event
.m_x
- part
->rect
.x
,
3497 event
.m_y
- part
->rect
.y
);
3498 m_frame
->CaptureMouse();
3518 void wxFrameManager::OnLeftUp(wxMouseEvent
& event
)
3520 if (m_action
== actionResize
)
3522 m_frame
->ReleaseMouse();
3524 // get rid of the hint rectangle
3526 DrawResizeHint(dc
, m_action_hintrect
);
3528 // resize the dock or the pane
3529 if (m_action_part
&& m_action_part
->type
==wxDockUIPart::typeDockSizer
)
3531 wxRect
& rect
= m_action_part
->dock
->rect
;
3533 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3534 event
.m_y
- m_action_offset
.y
);
3536 switch (m_action_part
->dock
->dock_direction
)
3538 case wxAUI_DOCK_LEFT
:
3539 m_action_part
->dock
->size
= new_pos
.x
- rect
.x
;
3541 case wxAUI_DOCK_TOP
:
3542 m_action_part
->dock
->size
= new_pos
.y
- rect
.y
;
3544 case wxAUI_DOCK_RIGHT
:
3545 m_action_part
->dock
->size
= rect
.x
+ rect
.width
-
3546 new_pos
.x
- m_action_part
->rect
.GetWidth();
3548 case wxAUI_DOCK_BOTTOM
:
3549 m_action_part
->dock
->size
= rect
.y
+ rect
.height
-
3550 new_pos
.y
- m_action_part
->rect
.GetHeight();
3557 else if (m_action_part
&&
3558 m_action_part
->type
== wxDockUIPart::typePaneSizer
)
3560 wxDockInfo
& dock
= *m_action_part
->dock
;
3561 wxPaneInfo
& pane
= *m_action_part
->pane
;
3563 int total_proportion
= 0;
3564 int dock_pixels
= 0;
3565 int new_pixsize
= 0;
3567 int caption_size
= m_art
->GetMetric(wxAUI_ART_CAPTION_SIZE
);
3568 int pane_border_size
= m_art
->GetMetric(wxAUI_ART_PANE_BORDER_SIZE
);
3569 int sash_size
= m_art
->GetMetric(wxAUI_ART_SASH_SIZE
);
3571 wxPoint
new_pos(event
.m_x
- m_action_offset
.x
,
3572 event
.m_y
- m_action_offset
.y
);
3574 // determine the pane rectangle by getting the pane part
3575 wxDockUIPart
* pane_part
= GetPanePart(pane
.window
);
3576 wxASSERT_MSG(pane_part
,
3577 wxT("Pane border part not found -- shouldn't happen"));
3579 // determine the new pixel size that the user wants;
3580 // this will help us recalculate the pane's proportion
3581 if (dock
.IsHorizontal())
3582 new_pixsize
= new_pos
.x
- pane_part
->rect
.x
;
3584 new_pixsize
= new_pos
.y
- pane_part
->rect
.y
;
3586 // determine the size of the dock, based on orientation
3587 if (dock
.IsHorizontal())
3588 dock_pixels
= dock
.rect
.GetWidth();
3590 dock_pixels
= dock
.rect
.GetHeight();
3592 // determine the total proportion of all resizable panes,
3593 // and the total size of the dock minus the size of all
3595 int i
, dock_pane_count
= dock
.panes
.GetCount();
3596 int pane_position
= -1;
3597 for (i
= 0; i
< dock_pane_count
; ++i
)
3599 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3600 if (p
.window
== pane
.window
)
3603 // while we're at it, subtract the pane sash
3604 // width from the dock width, because this would
3605 // skew our proportion calculations
3607 dock_pixels
-= sash_size
;
3609 // also, the whole size (including decorations) of
3610 // all fixed panes must also be subtracted, because they
3611 // are not part of the proportion calculation
3614 if (dock
.IsHorizontal())
3615 dock_pixels
-= p
.best_size
.x
;
3617 dock_pixels
-= p
.best_size
.y
;
3621 total_proportion
+= p
.dock_proportion
;
3625 // find a pane in our dock to 'steal' space from or to 'give'
3626 // space to -- this is essentially what is done when a pane is
3627 // resized; the pane should usually be the first non-fixed pane
3628 // to the right of the action pane
3629 int borrow_pane
= -1;
3630 for (i
= pane_position
+1; i
< dock_pane_count
; ++i
)
3632 wxPaneInfo
& p
= *dock
.panes
.Item(i
);
3641 // demand that the pane being resized is found in this dock
3642 // (this assert really never should be raised)
3643 wxASSERT_MSG(pane_position
!= -1, wxT("Pane not found in dock"));
3645 // prevent division by zero
3646 if (dock_pixels
== 0 || total_proportion
== 0 || borrow_pane
== -1)
3648 m_action
= actionNone
;
3652 // calculate the new proportion of the pane
3653 int new_proportion
= (new_pixsize
*total_proportion
)/dock_pixels
;
3655 // default minimum size
3658 // check against the pane's minimum size, if specified. please note
3659 // that this is not enough to ensure that the minimum size will
3660 // not be violated, because the whole frame might later be shrunk,
3661 // causing the size of the pane to violate it's minimum size
3662 if (pane
.min_size
.IsFullySpecified())
3666 if (pane
.HasBorder())
3667 min_size
+= (pane_border_size
*2);
3669 // calculate minimum size with decorations (border,caption)
3670 if (pane_part
->orientation
== wxVERTICAL
)
3672 min_size
+= pane
.min_size
.y
;
3673 if (pane
.HasCaption())
3674 min_size
+= caption_size
;
3678 min_size
+= pane
.min_size
.x
;
3683 // for some reason, an arithmatic error somewhere is causing
3684 // the proportion calculations to always be off by 1 pixel;
3685 // for now we will add the 1 pixel on, but we really should
3686 // determine what's causing this.
3689 int min_proportion
= (min_size
*total_proportion
)/dock_pixels
;
3691 if (new_proportion
< min_proportion
)
3692 new_proportion
= min_proportion
;
3696 int prop_diff
= new_proportion
- pane
.dock_proportion
;
3698 // borrow the space from our neighbor pane to the
3699 // right or bottom (depending on orientation)
3700 dock
.panes
.Item(borrow_pane
)->dock_proportion
-= prop_diff
;
3701 pane
.dock_proportion
= new_proportion
;
3708 else if (m_action
== actionClickButton
)
3710 m_hover_button
= NULL
;
3711 m_frame
->ReleaseMouse();
3712 UpdateButtonOnScreen(m_action_part
, event
);
3714 // make sure we're still over the item that was originally clicked
3715 if (m_action_part
== HitTest(event
.GetX(), event
.GetY()))
3717 // fire button-click event
3718 wxFrameManagerEvent
e(wxEVT_AUI_PANEBUTTON
);
3719 e
.SetPane(m_action_part
->pane
);
3720 e
.SetButton(m_action_part
->button
->button_id
);
3724 else if (m_action
== actionClickCaption
)
3726 m_frame
->ReleaseMouse();
3728 else if (m_action
== actionDragFloatingPane
)
3730 m_frame
->ReleaseMouse();
3732 else if (m_action
== actionDragToolbarPane
)
3734 m_frame
->ReleaseMouse();
3736 wxPaneInfo
& pane
= GetPane(m_action_window
);
3737 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3739 // save the new positions
3740 wxDockInfoPtrArray docks
;
3741 FindDocks(m_docks
, pane
.dock_direction
,
3742 pane
.dock_layer
, pane
.dock_row
, docks
);
3743 if (docks
.GetCount() == 1)
3745 wxDockInfo
& dock
= *docks
.Item(0);
3747 wxArrayInt pane_positions
, pane_sizes
;
3748 GetPanePositionsAndSizes(dock
, pane_positions
, pane_sizes
);
3750 int i
, dock_pane_count
= dock
.panes
.GetCount();
3751 for (i
= 0; i
< dock_pane_count
; ++i
)
3752 dock
.panes
.Item(i
)->dock_pos
= pane_positions
[i
];
3755 pane
.state
&= ~wxPaneInfo::actionPane
;
3763 m_action
= actionNone
;
3764 m_last_mouse_move
= wxPoint(); // see comment in OnMotion()
3768 void wxFrameManager::OnMotion(wxMouseEvent
& event
)
3770 // sometimes when Update() is called from inside this method,
3771 // a spurious mouse move event is generated; this check will make
3772 // sure that only real mouse moves will get anywhere in this method;
3773 // this appears to be a bug somewhere, and I don't know where the
3774 // mouse move event is being generated. only verified on MSW
3776 wxPoint mouse_pos
= event
.GetPosition();
3777 if (m_last_mouse_move
== mouse_pos
)
3779 m_last_mouse_move
= mouse_pos
;
3782 if (m_action
== actionResize
)
3784 wxPoint pos
= m_action_part
->rect
.GetPosition();
3785 if (m_action_part
->orientation
== wxHORIZONTAL
)
3786 pos
.y
= wxMax(0, event
.m_y
- m_action_offset
.y
);
3788 pos
.x
= wxMax(0, event
.m_x
- m_action_offset
.x
);
3790 wxRect
rect(m_frame
->ClientToScreen(pos
),
3791 m_action_part
->rect
.GetSize());
3794 if (!m_action_hintrect
.IsEmpty())
3795 DrawResizeHint(dc
, m_action_hintrect
);
3796 DrawResizeHint(dc
, rect
);
3797 m_action_hintrect
= rect
;
3799 else if (m_action
== actionClickCaption
)
3801 int drag_x_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
3802 int drag_y_threshold
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
3804 // caption has been clicked. we need to check if the mouse
3805 // is now being dragged. if it is, we need to change the
3806 // mouse action to 'drag'
3807 if (abs(event
.m_x
- m_action_start
.x
) > drag_x_threshold
||
3808 abs(event
.m_y
- m_action_start
.y
) > drag_y_threshold
)
3810 wxPaneInfo
* pane_info
= m_action_part
->pane
;
3812 if (!pane_info
->IsToolbar())
3814 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&
3815 pane_info
->IsFloatable())
3817 m_action
= actionDragFloatingPane
;
3819 // set initial float position
3820 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3821 pane_info
->floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3822 pt
.y
- m_action_offset
.y
);
3827 m_action_window
= pane_info
->frame
;
3829 // action offset is used here to make it feel "natural" to the user
3830 // to drag a docked pane and suddenly have it become a floating frame.
3831 // Sometimes, however, the offset where the user clicked on the docked
3832 // caption is bigger than the width of the floating frame itself, so
3833 // in that case we need to set the action offset to a sensible value
3834 wxSize frame_size
= m_action_window
->GetSize();
3835 if (frame_size
.x
<= m_action_offset
.x
)
3836 m_action_offset
.x
= 30;
3841 m_action
= actionDragToolbarPane
;
3842 m_action_window
= pane_info
->window
;
3846 else if (m_action
== actionDragFloatingPane
)
3848 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3849 m_action_window
->Move(pt
.x
- m_action_offset
.x
,
3850 pt
.y
- m_action_offset
.y
);
3852 else if (m_action
== actionDragToolbarPane
)
3854 wxPaneInfo
& pane
= GetPane(m_action_window
);
3855 wxASSERT_MSG(pane
.IsOk(), wxT("Pane window not found"));
3857 pane
.state
|= wxPaneInfo::actionPane
;
3859 wxPoint pt
= event
.GetPosition();
3860 DoDrop(m_docks
, m_panes
, pane
, pt
, m_action_offset
);
3862 // if DoDrop() decided to float the pane, set up
3863 // the floating pane's initial position
3864 if (pane
.IsFloating())
3866 wxPoint pt
= m_frame
->ClientToScreen(event
.GetPosition());
3867 pane
.floating_pos
= wxPoint(pt
.x
- m_action_offset
.x
,
3868 pt
.y
- m_action_offset
.y
);
3871 // this will do the actiual move operation;
3872 // in the case that the pane has been floated,
3873 // this call will create the floating pane
3874 // and do the reparenting
3877 // if the pane has been floated, change the mouse
3878 // action actionDragFloatingPane so that subsequent
3879 // EVT_MOTION() events will move the floating pane
3880 if (pane
.IsFloating())
3882 pane
.state
&= ~wxPaneInfo::actionPane
;
3883 m_action
= actionDragFloatingPane
;
3884 m_action_window
= pane
.frame
;
3889 wxDockUIPart
* part
= HitTest(event
.GetX(), event
.GetY());
3890 if (part
&& part
->type
== wxDockUIPart::typePaneButton
)
3892 if (part
!= m_hover_button
)
3894 // make the old button normal
3896 UpdateButtonOnScreen(m_hover_button
, event
);
3898 // mouse is over a button, so repaint the
3899 // button in hover mode
3900 UpdateButtonOnScreen(part
, event
);
3901 m_hover_button
= part
;
3908 m_hover_button
= NULL
;
3919 void wxFrameManager::OnLeaveWindow(wxMouseEvent
& WXUNUSED(event
))
3923 m_hover_button
= NULL
;
3928 void wxFrameManager::OnChildFocus(wxChildFocusEvent
& event
)
3930 // when a child pane has it's focus set, we should change the
3931 // pane's active state to reflect this. (this is only true if
3932 // active panes are allowed by the owner)
3933 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE
)
3935 if (GetPane(event
.GetWindow()).IsOk())
3937 SetActivePane(m_panes
, event
.GetWindow());
3946 // OnPaneButton() is an event handler that is called
3947 // when a pane button has been pressed.
3948 void wxFrameManager::OnPaneButton(wxFrameManagerEvent
& evt
)
3950 wxASSERT_MSG(evt
.pane
, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3952 wxPaneInfo
& pane
= *(evt
.pane
);
3954 if (evt
.button
== wxAUI_BUTTON_CLOSE
)
3956 // fire pane close event
3957 wxFrameManagerEvent
e(wxEVT_AUI_PANECLOSE
);
3958 e
.SetPane(evt
.pane
);
3967 else if (evt
.button
== wxAUI_BUTTON_PIN
)
3969 if ((m_flags
& wxAUI_MGR_ALLOW_FLOATING
) &&