]> git.saurik.com Git - wxWidgets.git/blame - src/aui/framemanager.cpp
cache the item text size to optimize tree layout/painting (#9956)
[wxWidgets.git] / src / aui / framemanager.cpp
CommitLineData
50acee04 1///////////////////////////////////////////////////////////////////////////////
be66f18e 2// Name: src/aui/framemanager.cpp
50acee04
JS
3// Purpose: wxaui: wx advanced user interface - docking window manager
4// Author: Benjamin I. Williams
5// Modified by:
6// Created: 2005-05-17
be66f18e 7// RCS-ID: $Id$
50acee04
JS
8// Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9// Licence: wxWindows Library Licence, Version 3.1
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#if wxUSE_AUI
27
28#include "wx/aui/framemanager.h"
29#include "wx/aui/dockart.h"
30#include "wx/aui/floatpane.h"
f244aef2 31#include "wx/aui/tabmdi.h"
1154f91b 32#include "wx/aui/auibar.h"
50acee04
JS
33
34#ifndef WX_PRECOMP
5ff14574 35 #include "wx/panel.h"
be66f18e
WS
36 #include "wx/settings.h"
37 #include "wx/app.h"
38 #include "wx/dcclient.h"
39 #include "wx/dcscreen.h"
4e3e485b 40 #include "wx/toolbar.h"
59cf2e49 41 #include "wx/mdi.h"
155ecd4c 42 #include "wx/image.h"
50acee04
JS
43#endif
44
50acee04
JS
45WX_CHECK_BUILD_OPTIONS("wxAUI")
46
47#include "wx/arrimpl.cpp"
48WX_DECLARE_OBJARRAY(wxRect, wxAuiRectArray);
49WX_DEFINE_OBJARRAY(wxAuiRectArray)
a3a5df9d
BW
50WX_DEFINE_OBJARRAY(wxAuiDockUIPartArray)
51WX_DEFINE_OBJARRAY(wxAuiDockInfoArray)
52WX_DEFINE_OBJARRAY(wxAuiPaneButtonArray)
53WX_DEFINE_OBJARRAY(wxAuiPaneInfoArray)
50acee04 54
a3a5df9d
BW
55wxAuiPaneInfo wxAuiNullPaneInfo;
56wxAuiDockInfo wxAuiNullDockInfo;
bc07ab17
RD
57DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_BUTTON)
58DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_CLOSE)
59DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_MAXIMIZE)
60DEFINE_EVENT_TYPE(wxEVT_AUI_PANE_RESTORE)
673727f3 61DEFINE_EVENT_TYPE(wxEVT_AUI_RENDER)
bc07ab17 62DEFINE_EVENT_TYPE(wxEVT_AUI_FIND_MANAGER)
50acee04
JS
63
64#ifdef __WXMAC__
65 // a few defines to avoid nameclashes
66 #define __MAC_OS_X_MEMORY_MANAGER_CLEAN__ 1
67 #define __AIFF__
d20db501 68 #include "wx/osx/private.h"
50acee04
JS
69#endif
70
be794d62
JS
71#ifdef __WXMSW__
72 #include "wx/msw/wrapwin.h"
73 #include "wx/msw/private.h"
888dde65 74 #include "wx/msw/dc.h"
be794d62
JS
75#endif
76
a3a5df9d 77IMPLEMENT_DYNAMIC_CLASS(wxAuiManagerEvent, wxEvent)
4dc79cfb 78IMPLEMENT_CLASS(wxAuiManager, wxEvtHandler)
f71d596e 79
f71d596e
BW
80
81
32e4b03c 82const int auiToolBarLayer = 10;
f71d596e 83
952a3bd4
RR
84#ifndef __WXGTK20__
85
f71d596e 86
7a5b04a6
AB
87class wxPseudoTransparentFrame : public wxFrame
88{
89public:
90 wxPseudoTransparentFrame(wxWindow* parent = NULL,
c08ee034
WS
91 wxWindowID id = wxID_ANY,
92 const wxString& title = wxEmptyString,
7a5b04a6
AB
93 const wxPoint& pos = wxDefaultPosition,
94 const wxSize& size = wxDefaultSize,
95 long style = wxDEFAULT_FRAME_STYLE,
96 const wxString &name = wxT("frame"))
97 : wxFrame(parent, id, title, pos, size, style | wxFRAME_SHAPED, name)
98 {
99 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
100 m_Amount=0;
101 m_MaxWidth=0;
102 m_MaxHeight=0;
0ae3bace
RR
103 m_lastWidth=0;
104 m_lastHeight=0;
7a5b04a6
AB
105#ifdef __WXGTK__
106 m_CanSetShape = false; // have to wait for window create event on GTK
107#else
108 m_CanSetShape = true;
109#endif
8d361e83 110 m_Region = wxRegion(0, 0, 0, 0);
7a5b04a6
AB
111 SetTransparent(0);
112 }
113
114 virtual bool SetTransparent(wxByte alpha)
115 {
116 if (m_CanSetShape)
117 {
118 int w=100; // some defaults
119 int h=100;
120 GetClientSize(&w, &h);
8d361e83 121
b4ea182b 122 m_MaxWidth = w;
8d361e83
RR
123 m_MaxHeight = h;
124 m_Amount = alpha;
125 m_Region.Clear();
126// m_Region.Union(0, 0, 1, m_MaxWidth);
127 if (m_Amount)
7a5b04a6 128 {
8d361e83 129 for (int y=0; y<m_MaxHeight; y++)
7a5b04a6 130 {
8d361e83
RR
131 // Reverse the order of the bottom 4 bits
132 int j=((y&8)?1:0)|((y&4)?2:0)|((y&2)?4:0)|((y&1)?8:0);
133 if ((j*16+8)<m_Amount)
134 m_Region.Union(0, y, m_MaxWidth, 1);
7a5b04a6 135 }
7a5b04a6 136 }
8d361e83
RR
137 SetShape(m_Region);
138 Refresh();
7a5b04a6
AB
139 }
140 return true;
141 }
142
c08ee034 143 void OnPaint(wxPaintEvent& WXUNUSED(event))
7a5b04a6
AB
144 {
145 wxPaintDC dc(this);
c08ee034 146
8d361e83
RR
147 if (m_Region.IsEmpty())
148 return;
149
150#ifdef __WXMAC__
151 dc.SetBrush(wxColour(128, 192, 255));
152#else
7a5b04a6 153 dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION));
8d361e83 154#endif
7a5b04a6 155 dc.SetPen(*wxTRANSPARENT_PEN);
c08ee034 156
7a5b04a6 157 wxRegionIterator upd(GetUpdateRegion()); // get the update rect list
c08ee034 158
7a5b04a6
AB
159 while (upd)
160 {
161 wxRect rect(upd.GetRect());
162 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
163
cedd7b22 164 ++upd;
7a5b04a6
AB
165 }
166 }
167
168#ifdef __WXGTK__
cf6fec73
BW
169 void OnWindowCreate(wxWindowCreateEvent& WXUNUSED(event))
170 {
171 m_CanSetShape=true;
172 SetTransparent(0);
173 }
7a5b04a6
AB
174#endif
175
8d361e83
RR
176 void OnSize(wxSizeEvent& event)
177 {
0ae3bace
RR
178 // We sometimes get surplus size events
179 if ((event.GetSize().GetWidth() == m_lastWidth) &&
180 (event.GetSize().GetHeight() == m_lastHeight))
181 {
182 event.Skip();
183 return;
184 }
185 m_lastWidth = event.GetSize().GetWidth();
186 m_lastHeight = event.GetSize().GetHeight();
b4ea182b 187
8d361e83
RR
188 SetTransparent(m_Amount);
189 m_Region.Intersect(0, 0, event.GetSize().GetWidth(),
190 event.GetSize().GetHeight());
191 SetShape(m_Region);
192 Refresh();
193 event.Skip();
194 }
195
7a5b04a6 196private:
b4ea182b 197 wxByte m_Amount;
7a5b04a6
AB
198 int m_MaxWidth;
199 int m_MaxHeight;
200 bool m_CanSetShape;
0ae3bace 201 int m_lastWidth,m_lastHeight;
7a5b04a6
AB
202
203 wxRegion m_Region;
204
f89f6b74
AB
205 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame)
206 DECLARE_EVENT_TABLE()
7a5b04a6
AB
207};
208
209
cf6fec73 210IMPLEMENT_DYNAMIC_CLASS(wxPseudoTransparentFrame, wxFrame)
7a5b04a6
AB
211
212BEGIN_EVENT_TABLE(wxPseudoTransparentFrame, wxFrame)
213 EVT_PAINT(wxPseudoTransparentFrame::OnPaint)
8d361e83 214 EVT_SIZE(wxPseudoTransparentFrame::OnSize)
7a5b04a6
AB
215#ifdef __WXGTK__
216 EVT_WINDOW_CREATE(wxPseudoTransparentFrame::OnWindowCreate)
217#endif
218END_EVENT_TABLE()
219
50acee04 220
952a3bd4
RR
221#else
222 // __WXGTK20__
223
19abd352 224#include <gtk/gtk.h>
952a3bd4
RR
225
226static void
227gtk_pseudo_window_realized_callback( GtkWidget *m_widget, void *WXUNUSED(win) )
228{
229 wxSize disp = wxGetDisplaySize();
230 int amount = 128;
231 wxRegion region;
232 for (int y=0; y<disp.y; y++)
233 {
234 // Reverse the order of the bottom 4 bits
235 int j=((y&8)?1:0)|((y&4)?2:0)|((y&2)?4:0)|((y&1)?8:0);
236 if ((j*16+8)<amount)
237 region.Union(0, y, disp.x, 1);
238 }
239 gdk_window_shape_combine_region(m_widget->window, region.GetRegion(), 0, 0);
240}
241
242
243class wxPseudoTransparentFrame: public wxFrame
244{
245public:
246 wxPseudoTransparentFrame(wxWindow* parent = NULL,
247 wxWindowID id = wxID_ANY,
248 const wxString& title = wxEmptyString,
249 const wxPoint& pos = wxDefaultPosition,
250 const wxSize& size = wxDefaultSize,
251 long style = wxDEFAULT_FRAME_STYLE,
252 const wxString &name = wxT("frame"))
253 {
254 if (!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
255 return;
256
257 m_title = title;
be794d62 258
952a3bd4 259 m_widget = gtk_window_new( GTK_WINDOW_POPUP );
173d02a8
PC
260 g_object_ref(m_widget);
261
262 if (parent) parent->AddChild(this);
952a3bd4
RR
263
264 g_signal_connect( m_widget, "realize",
265 G_CALLBACK (gtk_pseudo_window_realized_callback), this );
be794d62 266
952a3bd4
RR
267 GdkColor col;
268 col.red = 128 * 256;
269 col.green = 192 * 256;
270 col.blue = 255 * 256;
271 gtk_widget_modify_bg( m_widget, GTK_STATE_NORMAL, &col );
272 }
273
274 bool SetTransparent(wxByte WXUNUSED(alpha))
275 {
276 return true;
277 }
be794d62 278
952a3bd4
RR
279private:
280 DECLARE_DYNAMIC_CLASS(wxPseudoTransparentFrame)
281};
282
283IMPLEMENT_DYNAMIC_CLASS(wxPseudoTransparentFrame, wxFrame)
284
285#endif
286 // __WXGTK20__
287
288
289
50acee04
JS
290// -- static utility functions --
291
292static wxBitmap wxPaneCreateStippleBitmap()
293{
294 unsigned char data[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };
295 wxImage img(2,2,data,true);
296 return wxBitmap(img);
297}
298
299static void DrawResizeHint(wxDC& dc, const wxRect& rect)
300{
301 wxBitmap stipple = wxPaneCreateStippleBitmap();
302 wxBrush brush(stipple);
be66f18e 303 dc.SetBrush(brush);
be794d62 304#ifdef __WXMSW__
888dde65
RR
305 wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
306 PatBlt(GetHdcOf(*impl), rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight(), PATINVERT);
be794d62 307#else
50acee04
JS
308 dc.SetPen(*wxTRANSPARENT_PEN);
309
310 dc.SetLogicalFunction(wxXOR);
311 dc.DrawRectangle(rect);
be794d62 312#endif
50acee04
JS
313}
314
50acee04 315
50acee04
JS
316
317// CopyDocksAndPanes() - this utility function creates copies of
a3a5df9d
BW
318// the dock and pane info. wxAuiDockInfo's usually contain pointers
319// to wxAuiPaneInfo classes, thus this function is necessary to reliably
50acee04
JS
320// reconstruct that relationship in the new dock info and pane info arrays
321
a3a5df9d
BW
322static void CopyDocksAndPanes(wxAuiDockInfoArray& dest_docks,
323 wxAuiPaneInfoArray& dest_panes,
324 const wxAuiDockInfoArray& src_docks,
325 const wxAuiPaneInfoArray& src_panes)
50acee04
JS
326{
327 dest_docks = src_docks;
328 dest_panes = src_panes;
329 int i, j, k, dock_count, pc1, pc2;
330 for (i = 0, dock_count = dest_docks.GetCount(); i < dock_count; ++i)
331 {
a3a5df9d 332 wxAuiDockInfo& dock = dest_docks.Item(i);
50acee04
JS
333 for (j = 0, pc1 = dock.panes.GetCount(); j < pc1; ++j)
334 for (k = 0, pc2 = src_panes.GetCount(); k < pc2; ++k)
335 if (dock.panes.Item(j) == &src_panes.Item(k))
336 dock.panes.Item(j) = &dest_panes.Item(k);
337 }
338}
339
340// GetMaxLayer() is an internal function which returns
341// the highest layer inside the specified dock
32e4b03c
BW
342static int GetMaxLayer(const wxAuiDockInfoArray& docks,
343 int dock_direction)
50acee04
JS
344{
345 int i, dock_count, max_layer = 0;
346 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
347 {
a3a5df9d 348 wxAuiDockInfo& dock = docks.Item(i);
50acee04
JS
349 if (dock.dock_direction == dock_direction &&
350 dock.dock_layer > max_layer && !dock.fixed)
351 max_layer = dock.dock_layer;
352 }
353 return max_layer;
354}
355
356
357// GetMaxRow() is an internal function which returns
358// the highest layer inside the specified dock
a3a5df9d 359static int GetMaxRow(const wxAuiPaneInfoArray& panes, int direction, int layer)
50acee04
JS
360{
361 int i, pane_count, max_row = 0;
362 for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
363 {
a3a5df9d 364 wxAuiPaneInfo& pane = panes.Item(i);
50acee04 365 if (pane.dock_direction == direction &&
be66f18e 366 pane.dock_layer == layer &&
50acee04
JS
367 pane.dock_row > max_row)
368 max_row = pane.dock_row;
369 }
370 return max_row;
371}
372
373
374
375// DoInsertDockLayer() is an internal function that inserts a new dock
376// layer by incrementing all existing dock layer values by one
a3a5df9d 377static void DoInsertDockLayer(wxAuiPaneInfoArray& panes,
50acee04
JS
378 int dock_direction,
379 int dock_layer)
380{
381 int i, pane_count;
382 for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
383 {
a3a5df9d 384 wxAuiPaneInfo& pane = panes.Item(i);
50acee04
JS
385 if (!pane.IsFloating() &&
386 pane.dock_direction == dock_direction &&
387 pane.dock_layer >= dock_layer)
388 pane.dock_layer++;
389 }
390}
391
392// DoInsertDockLayer() is an internal function that inserts a new dock
393// row by incrementing all existing dock row values by one
a3a5df9d 394static void DoInsertDockRow(wxAuiPaneInfoArray& panes,
50acee04
JS
395 int dock_direction,
396 int dock_layer,
397 int dock_row)
398{
399 int i, pane_count;
400 for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
401 {
a3a5df9d 402 wxAuiPaneInfo& pane = panes.Item(i);
50acee04
JS
403 if (!pane.IsFloating() &&
404 pane.dock_direction == dock_direction &&
405 pane.dock_layer == dock_layer &&
406 pane.dock_row >= dock_row)
407 pane.dock_row++;
408 }
409}
410
be66f18e 411// DoInsertDockLayer() is an internal function that inserts a space for
50acee04 412// another dock pane by incrementing all existing dock row values by one
a3a5df9d 413static void DoInsertPane(wxAuiPaneInfoArray& panes,
50acee04
JS
414 int dock_direction,
415 int dock_layer,
416 int dock_row,
417 int dock_pos)
418{
419 int i, pane_count;
420 for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
421 {
a3a5df9d 422 wxAuiPaneInfo& pane = panes.Item(i);
50acee04
JS
423 if (!pane.IsFloating() &&
424 pane.dock_direction == dock_direction &&
425 pane.dock_layer == dock_layer &&
426 pane.dock_row == dock_row &&
427 pane.dock_pos >= dock_pos)
428 pane.dock_pos++;
429 }
430}
431
432// FindDocks() is an internal function that returns a list of docks which meet
433// the specified conditions in the parameters and returns a sorted array
434// (sorted by layer and then row)
a3a5df9d 435static void FindDocks(wxAuiDockInfoArray& docks,
50acee04
JS
436 int dock_direction,
437 int dock_layer,
438 int dock_row,
a3a5df9d 439 wxAuiDockInfoPtrArray& arr)
50acee04
JS
440{
441 int begin_layer = dock_layer;
442 int end_layer = dock_layer;
443 int begin_row = dock_row;
444 int end_row = dock_row;
445 int dock_count = docks.GetCount();
446 int layer, row, i, max_row = 0, max_layer = 0;
447
448 // discover the maximum dock layer and the max row
449 for (i = 0; i < dock_count; ++i)
450 {
451 max_row = wxMax(max_row, docks.Item(i).dock_row);
452 max_layer = wxMax(max_layer, docks.Item(i).dock_layer);
453 }
be66f18e 454
50acee04
JS
455 // if no dock layer was specified, search all dock layers
456 if (dock_layer == -1)
457 {
458 begin_layer = 0;
459 end_layer = max_layer;
460 }
be66f18e 461
50acee04
JS
462 // if no dock row was specified, search all dock row
463 if (dock_row == -1)
464 {
465 begin_row = 0;
466 end_row = max_row;
467 }
468
469 arr.Clear();
470
471 for (layer = begin_layer; layer <= end_layer; ++layer)
472 for (row = begin_row; row <= end_row; ++row)
473 for (i = 0; i < dock_count; ++i)
474 {
a3a5df9d 475 wxAuiDockInfo& d = docks.Item(i);
50acee04
JS
476 if (dock_direction == -1 || dock_direction == d.dock_direction)
477 {
478 if (d.dock_layer == layer && d.dock_row == row)
479 arr.Add(&d);
480 }
481 }
482}
483
484// FindPaneInDock() looks up a specified window pointer inside a dock.
a3a5df9d
BW
485// If found, the corresponding wxAuiPaneInfo pointer is returned, otherwise NULL.
486static wxAuiPaneInfo* FindPaneInDock(const wxAuiDockInfo& dock, wxWindow* window)
50acee04
JS
487{
488 int i, count = dock.panes.GetCount();
489 for (i = 0; i < count; ++i)
490 {
a3a5df9d 491 wxAuiPaneInfo* p = dock.panes.Item(i);
50acee04
JS
492 if (p->window == window)
493 return p;
494 }
495 return NULL;
496}
497
498// RemovePaneFromDocks() removes a pane window from all docks
9259ed34 499// with a possible exception specified by parameter "ex_cept"
a3a5df9d
BW
500static void RemovePaneFromDocks(wxAuiDockInfoArray& docks,
501 wxAuiPaneInfo& pane,
502 wxAuiDockInfo* ex_cept = NULL )
50acee04
JS
503{
504 int i, dock_count;
505 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
506 {
a3a5df9d 507 wxAuiDockInfo& d = docks.Item(i);
9259ed34 508 if (&d == ex_cept)
50acee04 509 continue;
a3a5df9d 510 wxAuiPaneInfo* pi = FindPaneInDock(d, pane.window);
50acee04
JS
511 if (pi)
512 d.panes.Remove(pi);
513 }
514}
515
1ca1b2b8
BW
516/*
517// This function works fine, and may be used in the future
518
50acee04
JS
519// RenumberDockRows() takes a dock and assigns sequential numbers
520// to existing rows. Basically it takes out the gaps; so if a
521// dock has rows with numbers 0,2,5, they will become 0,1,2
a3a5df9d 522static void RenumberDockRows(wxAuiDockInfoPtrArray& docks)
50acee04 523{
7afb5814 524 int i, dock_count;
50acee04
JS
525 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
526 {
a3a5df9d 527 wxAuiDockInfo& dock = *docks.Item(i);
50acee04 528 dock.dock_row = i;
be794d62 529
1ca1b2b8
BW
530 int j, pane_count;
531 for (j = 0, pane_count = dock.panes.GetCount(); j < pane_count; ++j)
532 dock.panes.Item(j)->dock_row = i;
50acee04
JS
533 }
534}
1ca1b2b8 535*/
50acee04
JS
536
537
cc0196c7
BW
538// SetActivePane() sets the active pane, as well as cycles through
539// every other pane and makes sure that all others' active flags
540// are turned off
a3a5df9d 541static void SetActivePane(wxAuiPaneInfoArray& panes, wxWindow* active_pane)
50acee04
JS
542{
543 int i, pane_count;
544 for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
545 {
a3a5df9d
BW
546 wxAuiPaneInfo& pane = panes.Item(i);
547 pane.state &= ~wxAuiPaneInfo::optionActive;
50acee04 548 if (pane.window == active_pane)
a3a5df9d 549 pane.state |= wxAuiPaneInfo::optionActive;
50acee04
JS
550 }
551}
552
553
554// this function is used to sort panes by dock position
a3a5df9d 555static int PaneSortFunc(wxAuiPaneInfo** p1, wxAuiPaneInfo** p2)
50acee04
JS
556{
557 return ((*p1)->dock_pos < (*p2)->dock_pos) ? -1 : 1;
558}
559
560
a3a5df9d 561// -- wxAuiManager class implementation --
50acee04
JS
562
563
a3a5df9d 564BEGIN_EVENT_TABLE(wxAuiManager, wxEvtHandler)
bc07ab17 565 EVT_AUI_PANE_BUTTON(wxAuiManager::OnPaneButton)
a3a5df9d
BW
566 EVT_AUI_RENDER(wxAuiManager::OnRender)
567 EVT_PAINT(wxAuiManager::OnPaint)
568 EVT_ERASE_BACKGROUND(wxAuiManager::OnEraseBackground)
569 EVT_SIZE(wxAuiManager::OnSize)
570 EVT_SET_CURSOR(wxAuiManager::OnSetCursor)
571 EVT_LEFT_DOWN(wxAuiManager::OnLeftDown)
572 EVT_LEFT_UP(wxAuiManager::OnLeftUp)
573 EVT_MOTION(wxAuiManager::OnMotion)
574 EVT_LEAVE_WINDOW(wxAuiManager::OnLeaveWindow)
575 EVT_CHILD_FOCUS(wxAuiManager::OnChildFocus)
bc07ab17 576 EVT_AUI_FIND_MANAGER(wxAuiManager::OnFindManager)
a3a5df9d 577 EVT_TIMER(101, wxAuiManager::OnHintFadeTimer)
50acee04
JS
578END_EVENT_TABLE()
579
580
a3a5df9d 581wxAuiManager::wxAuiManager(wxWindow* managed_wnd, unsigned int flags)
50acee04
JS
582{
583 m_action = actionNone;
584 m_last_mouse_move = wxPoint();
585 m_hover_button = NULL;
a3a5df9d 586 m_art = new wxAuiDefaultDockArt;
50acee04
JS
587 m_hint_wnd = NULL;
588 m_flags = flags;
c3008402 589 m_skipping = false;
37106ab2 590 m_has_maximized = false;
26da5e4f 591 m_frame = NULL;
a6b7a521
VZ
592 m_dock_constraint_x = 0.3;
593 m_dock_constraint_y = 0.3;
1dc6ec2c 594 m_reserved = NULL;
7608fd01 595
461125ea 596 if (managed_wnd)
50acee04 597 {
461125ea 598 SetManagedWindow(managed_wnd);
50acee04
JS
599 }
600}
601
a3a5df9d 602wxAuiManager::~wxAuiManager()
50acee04 603{
46eac9e4
JS
604 // NOTE: It's possible that the windows have already been destroyed by the
605 // time this dtor is called, so this loop can result in memory access via
606 // invalid pointers, resulting in a crash. So it will be disabled while
607 // waiting for a better solution.
608#if 0
fb48a5f8 609 for ( size_t i = 0; i < m_panes.size(); i++ )
7608fd01 610 {
fb48a5f8
VZ
611 wxAuiPaneInfo& pinfo = m_panes[i];
612 if (pinfo.window && !pinfo.window->GetParent())
7608fd01
VZ
613 delete pinfo.window;
614 }
46eac9e4 615#endif
7608fd01 616
50acee04
JS
617 delete m_art;
618}
619
9e1fc0e4
BW
620// creates a floating frame for the windows
621wxAuiFloatingFrame* wxAuiManager::CreateFloatingFrame(wxWindow* parent,
622 const wxAuiPaneInfo& pane_info)
bc429ce0 623{
1afad0ac 624 return new wxAuiFloatingFrame(parent, this, pane_info);
bc429ce0
RR
625}
626
858a3a7a
JS
627bool wxAuiManager::CanDockPanel(const wxAuiPaneInfo & WXUNUSED(p))
628{
629 // if a key modifier is pressed while dragging the frame,
630 // don't dock the window
631 return !(wxGetKeyState(WXK_CONTROL) || wxGetKeyState(WXK_ALT));
632}
633
a3a5df9d 634// GetPane() looks up a wxAuiPaneInfo structure based
50acee04 635// on the supplied window pointer. Upon failure, GetPane()
a3a5df9d
BW
636// returns an empty wxAuiPaneInfo, a condition which can be checked
637// by calling wxAuiPaneInfo::IsOk().
50acee04
JS
638//
639// The pane info's structure may then be modified. Once a pane's
a3a5df9d 640// info is modified, wxAuiManager::Update() must be called to
50acee04
JS
641// realize the changes in the UI.
642
a3a5df9d 643wxAuiPaneInfo& wxAuiManager::GetPane(wxWindow* window)
50acee04
JS
644{
645 int i, pane_count;
646 for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
647 {
a3a5df9d 648 wxAuiPaneInfo& p = m_panes.Item(i);
50acee04
JS
649 if (p.window == window)
650 return p;
651 }
a3a5df9d 652 return wxAuiNullPaneInfo;
50acee04
JS
653}
654
655// this version of GetPane() looks up a pane based on a
656// 'pane name', see above comment for more info
a3a5df9d 657wxAuiPaneInfo& wxAuiManager::GetPane(const wxString& name)
50acee04
JS
658{
659 int i, pane_count;
660 for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
661 {
a3a5df9d 662 wxAuiPaneInfo& p = m_panes.Item(i);
50acee04
JS
663 if (p.name == name)
664 return p;
665 }
a3a5df9d 666 return wxAuiNullPaneInfo;
50acee04
JS
667}
668
669// GetAllPanes() returns a reference to all the pane info structures
a3a5df9d 670wxAuiPaneInfoArray& wxAuiManager::GetAllPanes()
50acee04
JS
671{
672 return m_panes;
673}
674
675// HitTest() is an internal function which determines
676// which UI item the specified coordinates are over
677// (x,y) specify a position in client coordinates
a3a5df9d 678wxAuiDockUIPart* wxAuiManager::HitTest(int x, int y)
50acee04 679{
a3a5df9d 680 wxAuiDockUIPart* result = NULL;
50acee04
JS
681
682 int i, part_count;
683 for (i = 0, part_count = m_uiparts.GetCount(); i < part_count; ++i)
684 {
a3a5df9d 685 wxAuiDockUIPart* item = &m_uiparts.Item(i);
be66f18e
WS
686
687 // we are not interested in typeDock, because this space
50acee04
JS
688 // isn't used to draw anything, just for measurements;
689 // besides, the entire dock area is covered with other
690 // rectangles, which we are interested in.
a3a5df9d 691 if (item->type == wxAuiDockUIPart::typeDock)
50acee04 692 continue;
be66f18e 693
50acee04
JS
694 // if we already have a hit on a more specific item, we are not
695 // interested in a pane hit. If, however, we don't already have
696 // a hit, returning a pane hit is necessary for some operations
a3a5df9d
BW
697 if ((item->type == wxAuiDockUIPart::typePane ||
698 item->type == wxAuiDockUIPart::typePaneBorder) && result)
50acee04 699 continue;
be66f18e 700
50acee04 701 // if the point is inside the rectangle, we have a hit
22a35096 702 if (item->rect.Contains(x,y))
50acee04
JS
703 result = item;
704 }
be66f18e 705
50acee04
JS
706 return result;
707}
708
709
710// SetFlags() and GetFlags() allow the owner to set various
a3a5df9d
BW
711// options which are global to wxAuiManager
712void wxAuiManager::SetFlags(unsigned int flags)
50acee04 713{
cf6fec73
BW
714 // find out if we have to call UpdateHintWindowConfig()
715 bool update_hint_wnd = false;
716 unsigned int hint_mask = wxAUI_MGR_TRANSPARENT_HINT |
717 wxAUI_MGR_VENETIAN_BLINDS_HINT |
718 wxAUI_MGR_RECTANGLE_HINT;
719 if ((flags & hint_mask) != (m_flags & hint_mask))
720 update_hint_wnd = true;
721
722
723 // set the new flags
50acee04 724 m_flags = flags;
7608fd01 725
cf6fec73
BW
726 if (update_hint_wnd)
727 {
728 UpdateHintWindowConfig();
729 }
50acee04
JS
730}
731
a3a5df9d 732unsigned int wxAuiManager::GetFlags() const
50acee04
JS
733{
734 return m_flags;
735}
736
737
461125ea
BW
738// don't use these anymore as they are deprecated
739// use Set/GetManagedFrame() instead
a3a5df9d 740void wxAuiManager::SetFrame(wxFrame* frame)
461125ea
BW
741{
742 SetManagedWindow((wxWindow*)frame);
743}
744
a3a5df9d 745wxFrame* wxAuiManager::GetFrame() const
461125ea
BW
746{
747 return (wxFrame*)m_frame;
748}
749
750
4dc79cfb
BW
751// this function will return the aui manager for a given
752// window. The |window| parameter should be any child window
753// or grand-child window (and so on) of the frame/window
754// managed by wxAuiManager. The |window| parameter does not
755// need to be managed by the manager itself.
756wxAuiManager* wxAuiManager::GetManager(wxWindow* window)
757{
bc07ab17 758 wxAuiManagerEvent evt(wxEVT_AUI_FIND_MANAGER);
bc9e3321 759 evt.SetManager(NULL);
4dc79cfb
BW
760 evt.ResumePropagation(wxEVENT_PROPAGATE_MAX);
761 if (!window->ProcessEvent(evt))
762 return NULL;
7608fd01 763
4dc79cfb
BW
764 return evt.GetManager();
765}
766
767
a3a5df9d 768void wxAuiManager::UpdateHintWindowConfig()
cf6fec73
BW
769{
770 // find out if the the system can do transparent frames
771 bool can_do_transparent = false;
7608fd01 772
cf6fec73
BW
773 wxWindow* w = m_frame;
774 while (w)
775 {
776 if (w->IsKindOf(CLASSINFO(wxFrame)))
777 {
778 wxFrame* f = static_cast<wxFrame*>(w);
cf6fec73 779 can_do_transparent = f->CanSetTransparent();
888dde65 780
cf6fec73
BW
781 break;
782 }
7608fd01 783
cf6fec73
BW
784 w = w->GetParent();
785 }
7608fd01 786
cf6fec73
BW
787 // if there is an existing hint window, delete it
788 if (m_hint_wnd)
789 {
790 m_hint_wnd->Destroy();
791 m_hint_wnd = NULL;
792 }
793
794 m_hint_fademax = 50;
795 m_hint_wnd = NULL;
7608fd01 796
cf6fec73 797 if ((m_flags & wxAUI_MGR_TRANSPARENT_HINT) && can_do_transparent)
7608fd01 798 {
cf6fec73
BW
799 // Make a window to use for a transparent hint
800 #if defined(__WXMSW__) || defined(__WXGTK__)
801 m_hint_wnd = new wxFrame(m_frame, wxID_ANY, wxEmptyString,
802 wxDefaultPosition, wxSize(1,1),
803 wxFRAME_TOOL_WINDOW |
804 wxFRAME_FLOAT_ON_PARENT |
805 wxFRAME_NO_TASKBAR |
806 wxNO_BORDER);
807
808 m_hint_wnd->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION));
809 #elif defined(__WXMAC__)
810 // Using a miniframe with float and tool styles keeps the parent
811 // frame activated and highlighted as such...
812 m_hint_wnd = new wxMiniFrame(m_frame, wxID_ANY, wxEmptyString,
813 wxDefaultPosition, wxSize(1,1),
814 wxFRAME_FLOAT_ON_PARENT
815 | wxFRAME_TOOL_WINDOW );
816
817 // Can't set the bg colour of a Frame in wxMac
818 wxPanel* p = new wxPanel(m_hint_wnd);
819
820 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
821 // color that is really hard to see, especially transparent.
822 // Until a better system color is decided upon we'll just use
823 // blue.
824 p->SetBackgroundColour(*wxBLUE);
825 #endif
7608fd01 826
cf6fec73 827 }
7608fd01 828 else
cf6fec73
BW
829 {
830 if ((m_flags & wxAUI_MGR_TRANSPARENT_HINT) != 0 ||
831 (m_flags & wxAUI_MGR_VENETIAN_BLINDS_HINT) != 0)
832 {
833 // system can't support transparent fade, or the venetian
834 // blinds effect was explicitly requested
835 m_hint_wnd = new wxPseudoTransparentFrame(m_frame,
836 wxID_ANY,
837 wxEmptyString,
838 wxDefaultPosition,
839 wxSize(1,1),
840 wxFRAME_TOOL_WINDOW |
841 wxFRAME_FLOAT_ON_PARENT |
842 wxFRAME_NO_TASKBAR |
843 wxNO_BORDER);
844 m_hint_fademax = 128;
845 }
846 }
847}
461125ea
BW
848
849
850// SetManagedWindow() is usually called once when the frame
50acee04
JS
851// manager class is being initialized. "frame" specifies
852// the frame which should be managed by the frame mananger
a3a5df9d 853void wxAuiManager::SetManagedWindow(wxWindow* wnd)
50acee04 854{
cf6fec73 855 wxASSERT_MSG(wnd, wxT("specified window must be non-NULL"));
50acee04 856
cf6fec73 857 m_frame = wnd;
50acee04
JS
858 m_frame->PushEventHandler(this);
859
860#if wxUSE_MDI
861 // if the owner is going to manage an MDI parent frame,
862 // we need to add the MDI client window as the default
863 // center pane
864
cf6fec73 865 if (m_frame->IsKindOf(CLASSINFO(wxMDIParentFrame)))
50acee04 866 {
cf6fec73 867 wxMDIParentFrame* mdi_frame = (wxMDIParentFrame*)m_frame;
9db1b540 868 wxWindow* client_window = mdi_frame->GetClientWindow();
50acee04
JS
869
870 wxASSERT_MSG(client_window, wxT("Client window is NULL!"));
871
872 AddPane(client_window,
a3a5df9d 873 wxAuiPaneInfo().Name(wxT("mdiclient")).
50acee04
JS
874 CenterPane().PaneBorder(false));
875 }
cedd7b22 876 else if (m_frame->IsKindOf(CLASSINFO(wxAuiMDIParentFrame)))
f244aef2
BW
877 {
878 wxAuiMDIParentFrame* mdi_frame = (wxAuiMDIParentFrame*)m_frame;
879 wxAuiMDIClientWindow* client_window = mdi_frame->GetClientWindow();
880 wxASSERT_MSG(client_window, wxT("Client window is NULL!"));
881
882 AddPane(client_window,
883 wxAuiPaneInfo().Name(wxT("mdiclient")).
884 CenterPane().PaneBorder(false));
885 }
886
50acee04 887#endif
50f3c41d 888
cf6fec73 889 UpdateHintWindowConfig();
50acee04
JS
890}
891
892
893// UnInit() must be called, usually in the destructor
894// of the frame class. If it is not called, usually this
895// will result in a crash upon program exit
a3a5df9d 896void wxAuiManager::UnInit()
50acee04 897{
26da5e4f
BW
898 if (m_frame)
899 {
900 m_frame->RemoveEventHandler(this);
901 }
50acee04
JS
902}
903
461125ea 904// GetManagedWindow() returns the window pointer being managed
a3a5df9d 905wxWindow* wxAuiManager::GetManagedWindow() const
50acee04
JS
906{
907 return m_frame;
908}
909
a3a5df9d 910wxAuiDockArt* wxAuiManager::GetArtProvider() const
50acee04
JS
911{
912 return m_art;
913}
914
a3a5df9d 915void wxAuiManager::ProcessMgrEvent(wxAuiManagerEvent& event)
50acee04
JS
916{
917 // first, give the owner frame a chance to override
918 if (m_frame)
919 {
920 if (m_frame->ProcessEvent(event))
921 return;
922 }
923
924 ProcessEvent(event);
925}
926
a3a5df9d 927// SetArtProvider() instructs wxAuiManager to use the
50acee04 928// specified art provider for all drawing calls. This allows
cc0196c7 929// plugable look-and-feel features. The pointer that is
a3a5df9d 930// passed to this method subsequently belongs to wxAuiManager,
cc0196c7 931// and is deleted in the frame manager destructor
a3a5df9d 932void wxAuiManager::SetArtProvider(wxAuiDockArt* art_provider)
50acee04
JS
933{
934 // delete the last art provider, if any
935 delete m_art;
be66f18e 936
50acee04
JS
937 // assign the new art provider
938 m_art = art_provider;
939}
940
cc0196c7 941
a3a5df9d 942bool wxAuiManager::AddPane(wxWindow* window, const wxAuiPaneInfo& pane_info)
50acee04 943{
4b7d829b
BW
944 wxASSERT_MSG(window, wxT("NULL window ptrs are not allowed"));
945
50acee04
JS
946 // check if the pane has a valid window
947 if (!window)
948 return false;
949
dc4334d7
BW
950 // check if the window is already managed by us
951 if (GetPane(pane_info.window).IsOk())
952 return false;
953
954 // check if the pane name already exists, this could reveal a
955 // bug in the library user's application
2a8f8889 956 bool already_exists = false;
2a8f8889
BW
957 if (!pane_info.name.empty() && GetPane(pane_info.name).IsOk())
958 {
959 wxFAIL_MSG(wxT("A pane with that name already exists in the manager!"));
960 already_exists = true;
961 }
50acee04 962
46067c35 963 // if the new pane is docked then we should undo maximize
32e4b03c 964 if (pane_info.IsDocked())
46067c35
BW
965 RestoreMaximizedPane();
966
50acee04
JS
967 m_panes.Add(pane_info);
968
a3a5df9d 969 wxAuiPaneInfo& pinfo = m_panes.Last();
50acee04
JS
970
971 // set the pane window
972 pinfo.window = window;
be66f18e 973
2a8f8889 974
50acee04 975 // if the pane's name identifier is blank, create a random string
2a8f8889 976 if (pinfo.name.empty() || already_exists)
50acee04 977 {
0e9c9923 978 pinfo.name.Printf(wxT("%08lx%08x%08x%08lx"),
140d4f0f 979 wxPtrToUInt(pinfo.window) & 0xffffffff,
50acee04 980 (unsigned int)time(NULL),
99ae6124
WS
981#ifdef __WXWINCE__
982 (unsigned int)GetTickCount(),
983#else
0e9c9923 984 (unsigned int)clock(),
99ae6124 985#endif
0e9c9923 986 (unsigned long)m_panes.GetCount());
50acee04 987 }
be66f18e 988
50acee04
JS
989 // set initial proportion (if not already set)
990 if (pinfo.dock_proportion == 0)
991 pinfo.dock_proportion = 100000;
992
37106ab2
BW
993 if (pinfo.HasMaximizeButton())
994 {
a3a5df9d 995 wxAuiPaneButton button;
37106ab2
BW
996 button.button_id = wxAUI_BUTTON_MAXIMIZE_RESTORE;
997 pinfo.buttons.Add(button);
998 }
7608fd01 999
50d5ad7d
BW
1000 if (pinfo.HasPinButton())
1001 {
1002 wxAuiPaneButton button;
1003 button.button_id = wxAUI_BUTTON_PIN;
1004 pinfo.buttons.Add(button);
1005 }
7608fd01 1006
37106ab2 1007 if (pinfo.HasCloseButton())
50acee04 1008 {
a3a5df9d 1009 wxAuiPaneButton button;
4953f8cf 1010 button.button_id = wxAUI_BUTTON_CLOSE;
50acee04
JS
1011 pinfo.buttons.Add(button);
1012 }
1154f91b
BW
1013
1014 if (pinfo.HasGripper())
1015 {
1016 if (pinfo.window->IsKindOf(CLASSINFO(wxAuiToolBar)))
1017 {
1018 // prevent duplicate gripper -- both wxAuiManager and wxAuiToolBar
1019 // have a gripper control. The toolbar's built-in gripper
1020 // meshes better with the look and feel of the control than ours,
1021 // so turn wxAuiManager's gripper off, and the toolbar's on.
1022
1023 wxAuiToolBar* tb = static_cast<wxAuiToolBar*>(pinfo.window);
1024 pinfo.SetFlag(wxAuiPaneInfo::optionGripper, false);
1025 tb->SetGripperVisible(true);
1026 }
1027 }
1028
be66f18e 1029
50acee04
JS
1030 if (pinfo.best_size == wxDefaultSize &&
1031 pinfo.window)
1032 {
1033 pinfo.best_size = pinfo.window->GetClientSize();
1034
1035 if (pinfo.window->IsKindOf(CLASSINFO(wxToolBar)))
1036 {
1037 // GetClientSize() doesn't get the best size for
1038 // a toolbar under some newer versions of wxWidgets,
1039 // so use GetBestSize()
1040 pinfo.best_size = pinfo.window->GetBestSize();
be66f18e 1041
50acee04
JS
1042 // for some reason, wxToolBar::GetBestSize() is returning
1043 // a size that is a pixel shy of the correct amount.
1044 // I believe this to be the correct action, until
1045 // wxToolBar::GetBestSize() is fixed. Is this assumption
1046 // correct?
c118d8b0
JS
1047 // commented out by JACS 2007-9-08 after having added a pixel in wxMSW's wxToolBar::DoGetBestSize()
1048 // pinfo.best_size.y++;
50acee04 1049 }
be66f18e 1050
50acee04
JS
1051 if (pinfo.min_size != wxDefaultSize)
1052 {
1053 if (pinfo.best_size.x < pinfo.min_size.x)
1054 pinfo.best_size.x = pinfo.min_size.x;
1055 if (pinfo.best_size.y < pinfo.min_size.y)
1056 pinfo.best_size.y = pinfo.min_size.y;
1057 }
1058 }
1059
1154f91b
BW
1060
1061
50acee04
JS
1062 return true;
1063}
1064
a3a5df9d 1065bool wxAuiManager::AddPane(wxWindow* window,
1dc6ec2c
BW
1066 int direction,
1067 const wxString& caption)
50acee04 1068{
a3a5df9d 1069 wxAuiPaneInfo pinfo;
50acee04
JS
1070 pinfo.Caption(caption);
1071 switch (direction)
1072 {
1073 case wxTOP: pinfo.Top(); break;
1074 case wxBOTTOM: pinfo.Bottom(); break;
1075 case wxLEFT: pinfo.Left(); break;
1076 case wxRIGHT: pinfo.Right(); break;
1077 case wxCENTER: pinfo.CenterPane(); break;
1078 }
1079 return AddPane(window, pinfo);
1080}
1081
a3a5df9d 1082bool wxAuiManager::AddPane(wxWindow* window,
1dc6ec2c
BW
1083 const wxAuiPaneInfo& pane_info,
1084 const wxPoint& drop_pos)
0603bb28
BW
1085{
1086 if (!AddPane(window, pane_info))
1087 return false;
c08ee034 1088
a3a5df9d 1089 wxAuiPaneInfo& pane = GetPane(window);
c08ee034 1090
0603bb28 1091 DoDrop(m_docks, m_panes, pane, drop_pos, wxPoint(0,0));
c08ee034 1092
0603bb28
BW
1093 return true;
1094}
1095
a3a5df9d 1096bool wxAuiManager::InsertPane(wxWindow* window, const wxAuiPaneInfo& pane_info,
50acee04
JS
1097 int insert_level)
1098{
4b7d829b
BW
1099 wxASSERT_MSG(window, wxT("NULL window ptrs are not allowed"));
1100
50acee04
JS
1101 // shift the panes around, depending on the insert level
1102 switch (insert_level)
1103 {
1104 case wxAUI_INSERT_PANE:
1105 DoInsertPane(m_panes,
1106 pane_info.dock_direction,
1107 pane_info.dock_layer,
1108 pane_info.dock_row,
1109 pane_info.dock_pos);
1110 break;
1111 case wxAUI_INSERT_ROW:
1112 DoInsertDockRow(m_panes,
1113 pane_info.dock_direction,
1114 pane_info.dock_layer,
1115 pane_info.dock_row);
1116 break;
1117 case wxAUI_INSERT_DOCK:
1118 DoInsertDockLayer(m_panes,
1119 pane_info.dock_direction,
1120 pane_info.dock_layer);
1121 break;
1122 }
be66f18e 1123
50acee04
JS
1124 // if the window already exists, we are basically just moving/inserting the
1125 // existing window. If it doesn't exist, we need to add it and insert it
a3a5df9d 1126 wxAuiPaneInfo& existing_pane = GetPane(window);
50acee04
JS
1127 if (!existing_pane.IsOk())
1128 {
1129 return AddPane(window, pane_info);
1130 }
7608fd01 1131 else
50acee04
JS
1132 {
1133 if (pane_info.IsFloating())
1134 {
1135 existing_pane.Float();
1136 if (pane_info.floating_pos != wxDefaultPosition)
1137 existing_pane.FloatingPosition(pane_info.floating_pos);
1138 if (pane_info.floating_size != wxDefaultSize)
1139 existing_pane.FloatingSize(pane_info.floating_size);
1140 }
7608fd01 1141 else
50acee04 1142 {
46067c35
BW
1143 // if the new pane is docked then we should undo maximize
1144 RestoreMaximizedPane();
1145
50acee04
JS
1146 existing_pane.Direction(pane_info.dock_direction);
1147 existing_pane.Layer(pane_info.dock_layer);
1148 existing_pane.Row(pane_info.dock_row);
1149 existing_pane.Position(pane_info.dock_pos);
1150 }
1151 }
1152
1153 return true;
1154}
1155
be66f18e 1156
cc0196c7
BW
1157// DetachPane() removes a pane from the frame manager. This
1158// method will not destroy the window that is removed.
a3a5df9d 1159bool wxAuiManager::DetachPane(wxWindow* window)
50acee04 1160{
4b7d829b
BW
1161 wxASSERT_MSG(window, wxT("NULL window ptrs are not allowed"));
1162
50acee04
JS
1163 int i, count;
1164 for (i = 0, count = m_panes.GetCount(); i < count; ++i)
1165 {
a3a5df9d 1166 wxAuiPaneInfo& p = m_panes.Item(i);
50acee04
JS
1167 if (p.window == window)
1168 {
1169 if (p.frame)
1170 {
1171 // we have a floating frame which is being detached. We need to
1172 // reparent it to m_frame and destroy the floating frame
1173
1174 // reduce flicker
1175 p.window->SetSize(1,1);
26178b5d
BW
1176
1177 if (p.frame->IsShown())
1178 p.frame->Show(false);
50acee04
JS
1179
1180 // reparent to m_frame and destroy the pane
32e4b03c 1181 if (m_action_window == p.frame)
7453065a 1182 {
49fa1dbb
RR
1183 m_action_window = NULL;
1184 }
7608fd01 1185
50acee04
JS
1186 p.window->Reparent(m_frame);
1187 p.frame->SetSizer(NULL);
1188 p.frame->Destroy();
1189 p.frame = NULL;
1190 }
c08ee034 1191
2f68106f
BW
1192 // make sure there are no references to this pane in our uiparts,
1193 // just in case the caller doesn't call Update() immediately after
1194 // the DetachPane() call. This prevets obscure crashes which would
1195 // happen at window repaint if the caller forgets to call Update()
1196 int pi, part_count;
1197 for (pi = 0, part_count = (int)m_uiparts.GetCount(); pi < part_count; ++pi)
1198 {
a3a5df9d 1199 wxAuiDockUIPart& part = m_uiparts.Item(pi);
2f68106f
BW
1200 if (part.pane == &p)
1201 {
1202 m_uiparts.RemoveAt(pi);
1203 part_count--;
1204 pi--;
1205 continue;
1206 }
1207 }
c08ee034 1208
50acee04
JS
1209 m_panes.RemoveAt(i);
1210 return true;
1211 }
1212 }
1213 return false;
1214}
1215
7da1b21e 1216// ClosePane() destroys or hides the pane depending on its flags
a3a5df9d 1217void wxAuiManager::ClosePane(wxAuiPaneInfo& pane_info)
fa96a36e 1218{
37106ab2 1219 // if we were maximized, restore
7453065a
BW
1220 if (pane_info.IsMaximized())
1221 {
37106ab2
BW
1222 RestorePane(pane_info);
1223 }
1224
fa96a36e 1225 // first, hide the window
7453065a
BW
1226 if (pane_info.window && pane_info.window->IsShown())
1227 {
fa96a36e
RR
1228 pane_info.window->Show(false);
1229 }
1230
1231 // make sure that we are the parent of this window
7453065a
BW
1232 if (pane_info.window && pane_info.window->GetParent() != m_frame)
1233 {
fa96a36e
RR
1234 pane_info.window->Reparent(m_frame);
1235 }
1236
1237 // if we have a frame, destroy it
7453065a
BW
1238 if (pane_info.frame)
1239 {
fa96a36e
RR
1240 pane_info.frame->Destroy();
1241 pane_info.frame = NULL;
1242 }
1243
1244 // now we need to either destroy or hide the pane
7608fd01 1245 if (pane_info.IsDestroyOnClose())
fa96a36e
RR
1246 {
1247 wxWindow * window = pane_info.window;
1248 DetachPane(window);
32e4b03c 1249 if (window)
7453065a 1250 {
fa96a36e
RR
1251 window->Destroy();
1252 }
7608fd01
VZ
1253 }
1254 else
fa96a36e
RR
1255 {
1256 pane_info.Hide();
1257 }
1258}
50acee04 1259
a3a5df9d 1260void wxAuiManager::MaximizePane(wxAuiPaneInfo& pane_info)
37106ab2
BW
1261{
1262 int i, pane_count;
1263
1264 // un-maximize and hide all other panes
1265 for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
1266 {
a3a5df9d 1267 wxAuiPaneInfo& p = m_panes.Item(i);
7453065a
BW
1268 if (!p.IsToolbar())
1269 {
37106ab2 1270 p.Restore();
7608fd01 1271
8d0634ab 1272 // save hidden state
1dc6ec2c
BW
1273 p.SetFlag(wxAuiPaneInfo::savedHiddenState,
1274 p.HasFlag(wxAuiPaneInfo::optionHidden));
8d0634ab
BW
1275
1276 // hide the pane, because only the newly
1277 // maximized pane should show
37106ab2
BW
1278 p.Hide();
1279 }
1280 }
1281
1282 // mark ourselves maximized
1283 pane_info.Maximize();
1284 pane_info.Show();
1285 m_has_maximized = true;
1286
1287 // last, show the window
7453065a
BW
1288 if (pane_info.window && !pane_info.window->IsShown())
1289 {
37106ab2
BW
1290 pane_info.window->Show(true);
1291 }
1292}
1293
a3a5df9d 1294void wxAuiManager::RestorePane(wxAuiPaneInfo& pane_info)
37106ab2
BW
1295{
1296 int i, pane_count;
1297
1298 // restore all the panes
1299 for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
1300 {
a3a5df9d 1301 wxAuiPaneInfo& p = m_panes.Item(i);
7453065a
BW
1302 if (!p.IsToolbar())
1303 {
1dc6ec2c
BW
1304 p.SetFlag(wxAuiPaneInfo::optionHidden,
1305 p.HasFlag(wxAuiPaneInfo::savedHiddenState));
37106ab2
BW
1306 }
1307 }
1308
1309 // mark ourselves non-maximized
1310 pane_info.Restore();
1311 m_has_maximized = false;
1312
1313 // last, show the window
7453065a
BW
1314 if (pane_info.window && !pane_info.window->IsShown())
1315 {
37106ab2
BW
1316 pane_info.window->Show(true);
1317 }
1318}
1319
a3a5df9d 1320void wxAuiManager::RestoreMaximizedPane()
37106ab2
BW
1321{
1322 int i, pane_count;
1323
1324 // restore all the panes
1325 for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
1326 {
a3a5df9d 1327 wxAuiPaneInfo& p = m_panes.Item(i);
32e4b03c 1328 if (p.IsMaximized())
7453065a 1329 {
37106ab2
BW
1330 RestorePane(p);
1331 break;
1332 }
1333 }
1334}
1335
50acee04
JS
1336// EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
1337// in the input string. This is an internal functions which is
1338// used for saving perspectives
1339static wxString EscapeDelimiters(const wxString& s)
1340{
1341 wxString result;
be66f18e 1342 result.Alloc(s.length());
50acee04
JS
1343 const wxChar* ch = s.c_str();
1344 while (*ch)
1345 {
1346 if (*ch == wxT(';') || *ch == wxT('|'))
1347 result += wxT('\\');
1348 result += *ch;
1349 ++ch;
1350 }
1351 return result;
1352}
1353
a3a5df9d 1354wxString wxAuiManager::SavePaneInfo(wxAuiPaneInfo& pane)
75c8d68f
AB
1355{
1356 wxString result = wxT("name=");
1357 result += EscapeDelimiters(pane.name);
1358 result += wxT(";");
1359
1360 result += wxT("caption=");
1361 result += EscapeDelimiters(pane.caption);
1362 result += wxT(";");
1363
1364 result += wxString::Format(wxT("state=%u;"), pane.state);
1365 result += wxString::Format(wxT("dir=%d;"), pane.dock_direction);
1366 result += wxString::Format(wxT("layer=%d;"), pane.dock_layer);
1367 result += wxString::Format(wxT("row=%d;"), pane.dock_row);
1368 result += wxString::Format(wxT("pos=%d;"), pane.dock_pos);
1369 result += wxString::Format(wxT("prop=%d;"), pane.dock_proportion);
1370 result += wxString::Format(wxT("bestw=%d;"), pane.best_size.x);
1371 result += wxString::Format(wxT("besth=%d;"), pane.best_size.y);
1372 result += wxString::Format(wxT("minw=%d;"), pane.min_size.x);
1373 result += wxString::Format(wxT("minh=%d;"), pane.min_size.y);
1374 result += wxString::Format(wxT("maxw=%d;"), pane.max_size.x);
1375 result += wxString::Format(wxT("maxh=%d;"), pane.max_size.y);
1376 result += wxString::Format(wxT("floatx=%d;"), pane.floating_pos.x);
1377 result += wxString::Format(wxT("floaty=%d;"), pane.floating_pos.y);
1378 result += wxString::Format(wxT("floatw=%d;"), pane.floating_size.x);
1379 result += wxString::Format(wxT("floath=%d"), pane.floating_size.y);
1380
1381 return result;
1382}
1383
13201165 1384// Load a "pane" with the pane infor settings in pane_part
a3a5df9d 1385void wxAuiManager::LoadPaneInfo(wxString pane_part, wxAuiPaneInfo &pane)
75c8d68f
AB
1386{
1387 // replace escaped characters so we can
1388 // split up the string easily
1389 pane_part.Replace(wxT("\\|"), wxT("\a"));
1390 pane_part.Replace(wxT("\\;"), wxT("\b"));
1391
13201165
AB
1392 while(1)
1393 {
1394 wxString val_part = pane_part.BeforeFirst(wxT(';'));
1395 pane_part = pane_part.AfterFirst(wxT(';'));
1396 wxString val_name = val_part.BeforeFirst(wxT('='));
1397 wxString value = val_part.AfterFirst(wxT('='));
1398 val_name.MakeLower();
1399 val_name.Trim(true);
1400 val_name.Trim(false);
1401 value.Trim(true);
1402 value.Trim(false);
b4ea182b 1403
13201165
AB
1404 if (val_name.empty())
1405 break;
b4ea182b 1406
13201165
AB
1407 if (val_name == wxT("name"))
1408 pane.name = value;
1409 else if (val_name == wxT("caption"))
1410 pane.caption = value;
1411 else if (val_name == wxT("state"))
1412 pane.state = (unsigned int)wxAtoi(value.c_str());
1413 else if (val_name == wxT("dir"))
1414 pane.dock_direction = wxAtoi(value.c_str());
1415 else if (val_name == wxT("layer"))
1416 pane.dock_layer = wxAtoi(value.c_str());
1417 else if (val_name == wxT("row"))
1418 pane.dock_row = wxAtoi(value.c_str());
1419 else if (val_name == wxT("pos"))
1420 pane.dock_pos = wxAtoi(value.c_str());
1421 else if (val_name == wxT("prop"))
1422 pane.dock_proportion = wxAtoi(value.c_str());
1423 else if (val_name == wxT("bestw"))
1424 pane.best_size.x = wxAtoi(value.c_str());
1425 else if (val_name == wxT("besth"))
1426 pane.best_size.y = wxAtoi(value.c_str());
1427 else if (val_name == wxT("minw"))
1428 pane.min_size.x = wxAtoi(value.c_str());
1429 else if (val_name == wxT("minh"))
1430 pane.min_size.y = wxAtoi(value.c_str());
1431 else if (val_name == wxT("maxw"))
1432 pane.max_size.x = wxAtoi(value.c_str());
1433 else if (val_name == wxT("maxh"))
1434 pane.max_size.y = wxAtoi(value.c_str());
1435 else if (val_name == wxT("floatx"))
1436 pane.floating_pos.x = wxAtoi(value.c_str());
1437 else if (val_name == wxT("floaty"))
1438 pane.floating_pos.y = wxAtoi(value.c_str());
1439 else if (val_name == wxT("floatw"))
1440 pane.floating_size.x = wxAtoi(value.c_str());
1441 else if (val_name == wxT("floath"))
1442 pane.floating_size.y = wxAtoi(value.c_str());
1443 else {
1444 wxFAIL_MSG(wxT("Bad Perspective String"));
1445 }
75c8d68f
AB
1446 }
1447
1448 // replace escaped characters so we can
1449 // split up the string easily
1450 pane.name.Replace(wxT("\a"), wxT("|"));
1451 pane.name.Replace(wxT("\b"), wxT(";"));
1452 pane.caption.Replace(wxT("\a"), wxT("|"));
1453 pane.caption.Replace(wxT("\b"), wxT(";"));
1454 pane_part.Replace(wxT("\a"), wxT("|"));
1455 pane_part.Replace(wxT("\b"), wxT(";"));
1456
13201165 1457 return;
75c8d68f
AB
1458}
1459
50acee04
JS
1460
1461// SavePerspective() saves all pane information as a single string.
1462// This string may later be fed into LoadPerspective() to restore
1463// all pane settings. This save and load mechanism allows an
1464// exact pane configuration to be saved and restored at a later time
1465
a3a5df9d 1466wxString wxAuiManager::SavePerspective()
50acee04
JS
1467{
1468 wxString result;
1469 result.Alloc(500);
1dc6ec2c 1470 result = wxT("layout2|");
50acee04
JS
1471
1472 int pane_i, pane_count = m_panes.GetCount();
1473 for (pane_i = 0; pane_i < pane_count; ++pane_i)
1474 {
a3a5df9d 1475 wxAuiPaneInfo& pane = m_panes.Item(pane_i);
75c8d68f 1476 result += SavePaneInfo(pane)+wxT("|");
50acee04 1477 }
be66f18e 1478
50acee04
JS
1479 int dock_i, dock_count = m_docks.GetCount();
1480 for (dock_i = 0; dock_i < dock_count; ++dock_i)
1481 {
a3a5df9d 1482 wxAuiDockInfo& dock = m_docks.Item(dock_i);
be66f18e 1483
50acee04
JS
1484 result += wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1485 dock.dock_direction, dock.dock_layer,
1486 dock.dock_row, dock.size);
1487 }
be66f18e 1488
50acee04
JS
1489 return result;
1490}
1491
1492// LoadPerspective() loads a layout which was saved with SavePerspective()
1493// If the "update" flag parameter is true, the GUI will immediately be updated
1494
a3a5df9d 1495bool wxAuiManager::LoadPerspective(const wxString& layout, bool update)
50acee04
JS
1496{
1497 wxString input = layout;
1498 wxString part;
be66f18e 1499
50acee04 1500 // check layout string version
1dc6ec2c
BW
1501 // 'layout1' = wxAUI 0.9.0 - wxAUI 0.9.2
1502 // 'layout2' = wxAUI 0.9.2 (wxWidgets 2.8)
50acee04
JS
1503 part = input.BeforeFirst(wxT('|'));
1504 input = input.AfterFirst(wxT('|'));
1505 part.Trim(true);
1506 part.Trim(false);
1dc6ec2c 1507 if (part != wxT("layout2"))
50acee04 1508 return false;
be66f18e 1509
50acee04
JS
1510 // mark all panes currently managed as docked and hidden
1511 int pane_i, pane_count = m_panes.GetCount();
1512 for (pane_i = 0; pane_i < pane_count; ++pane_i)
1513 m_panes.Item(pane_i).Dock().Hide();
1514
1515 // clear out the dock array; this will be reconstructed
1516 m_docks.Clear();
be66f18e 1517
50acee04
JS
1518 // replace escaped characters so we can
1519 // split up the string easily
1520 input.Replace(wxT("\\|"), wxT("\a"));
1521 input.Replace(wxT("\\;"), wxT("\b"));
be66f18e 1522
50acee04
JS
1523 while (1)
1524 {
a3a5df9d 1525 wxAuiPaneInfo pane;
50acee04
JS
1526
1527 wxString pane_part = input.BeforeFirst(wxT('|'));
1528 input = input.AfterFirst(wxT('|'));
1529 pane_part.Trim(true);
1530
1531 // if the string is empty, we're done parsing
be66f18e 1532 if (pane_part.empty())
50acee04
JS
1533 break;
1534
50acee04
JS
1535 if (pane_part.Left(9) == wxT("dock_size"))
1536 {
1537 wxString val_name = pane_part.BeforeFirst(wxT('='));
1538 wxString value = pane_part.AfterFirst(wxT('='));
be66f18e 1539
50acee04
JS
1540 long dir, layer, row, size;
1541 wxString piece = val_name.AfterFirst(wxT('('));
1542 piece = piece.BeforeLast(wxT(')'));
1543 piece.BeforeFirst(wxT(',')).ToLong(&dir);
1544 piece = piece.AfterFirst(wxT(','));
1545 piece.BeforeFirst(wxT(',')).ToLong(&layer);
1546 piece.AfterFirst(wxT(',')).ToLong(&row);
1547 value.ToLong(&size);
be66f18e 1548
a3a5df9d 1549 wxAuiDockInfo dock;
50acee04
JS
1550 dock.dock_direction = dir;
1551 dock.dock_layer = layer;
1552 dock.dock_row = row;
1553 dock.size = size;
1554 m_docks.Add(dock);
1555 continue;
1556 }
1557
75c8d68f
AB
1558 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1559 // name so it can be called by external callers
1560 pane_part.Replace(wxT("\a"), wxT("|"));
1561 pane_part.Replace(wxT("\b"), wxT(";"));
1562
13201165 1563 LoadPaneInfo(pane_part, pane);
be66f18e 1564
a3a5df9d 1565 wxAuiPaneInfo& p = GetPane(pane.name);
50acee04
JS
1566 if (!p.IsOk())
1567 {
1568 // the pane window couldn't be found
88664cda
BW
1569 // in the existing layout -- skip it
1570 continue;
50acee04 1571 }
be66f18e 1572
75c8d68f 1573 p.SafeSet(pane);
50acee04 1574 }
be66f18e 1575
50acee04
JS
1576 if (update)
1577 Update();
1578
1579 return true;
1580}
1581
a3a5df9d 1582void wxAuiManager::GetPanePositionsAndSizes(wxAuiDockInfo& dock,
bb38f6c8
BW
1583 wxArrayInt& positions,
1584 wxArrayInt& sizes)
50acee04 1585{
254a3429
BW
1586 int caption_size = m_art->GetMetric(wxAUI_DOCKART_CAPTION_SIZE);
1587 int pane_border_size = m_art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE);
1588 int gripper_size = m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE);
50acee04
JS
1589
1590 positions.Empty();
1591 sizes.Empty();
1592
1593 int offset, action_pane = -1;
1594 int pane_i, pane_count = dock.panes.GetCount();
1595
1596 // find the pane marked as our action pane
1597 for (pane_i = 0; pane_i < pane_count; ++pane_i)
1598 {
a3a5df9d 1599 wxAuiPaneInfo& pane = *(dock.panes.Item(pane_i));
50acee04 1600
a3a5df9d 1601 if (pane.state & wxAuiPaneInfo::actionPane)
50acee04
JS
1602 {
1603 wxASSERT_MSG(action_pane==-1, wxT("Too many fixed action panes"));
1604 action_pane = pane_i;
1605 }
1606 }
be66f18e 1607
50acee04
JS
1608 // set up each panes default position, and
1609 // determine the size (width or height, depending
1610 // on the dock's orientation) of each pane
1611 for (pane_i = 0; pane_i < pane_count; ++pane_i)
1612 {
a3a5df9d 1613 wxAuiPaneInfo& pane = *(dock.panes.Item(pane_i));
50acee04
JS
1614 positions.Add(pane.dock_pos);
1615 int size = 0;
be66f18e 1616
50acee04
JS
1617 if (pane.HasBorder())
1618 size += (pane_border_size*2);
be66f18e 1619
50acee04
JS
1620 if (dock.IsHorizontal())
1621 {
1622 if (pane.HasGripper() && !pane.HasGripperTop())
1623 size += gripper_size;
1624 size += pane.best_size.x;
1625 }
7608fd01 1626 else
50acee04
JS
1627 {
1628 if (pane.HasGripper() && pane.HasGripperTop())
1629 size += gripper_size;
1630
1631 if (pane.HasCaption())
be66f18e 1632 size += caption_size;
50acee04
JS
1633 size += pane.best_size.y;
1634 }
be66f18e 1635
50acee04
JS
1636 sizes.Add(size);
1637 }
1638
1639 // if there is no action pane, just return the default
1640 // positions (as specified in pane.pane_pos)
1641 if (action_pane == -1)
1642 return;
1643
1644 offset = 0;
1645 for (pane_i = action_pane-1; pane_i >= 0; --pane_i)
1646 {
1647 int amount = positions[pane_i+1] - (positions[pane_i] + sizes[pane_i]);
1648
1649 if (amount >= 0)
1650 offset += amount;
7608fd01 1651 else
50acee04
JS
1652 positions[pane_i] -= -amount;
1653
1654 offset += sizes[pane_i];
1655 }
be66f18e 1656
50acee04
JS
1657 // if the dock mode is fixed, make sure none of the panes
1658 // overlap; we will bump panes that overlap
1659 offset = 0;
1660 for (pane_i = action_pane; pane_i < pane_count; ++pane_i)
1661 {
1662 int amount = positions[pane_i] - offset;
1663 if (amount >= 0)
1664 offset += amount;
7608fd01 1665 else
50acee04
JS
1666 positions[pane_i] += -amount;
1667
1668 offset += sizes[pane_i];
1669 }
1670}
1671
1672
a3a5df9d 1673void wxAuiManager::LayoutAddPane(wxSizer* cont,
1dc6ec2c
BW
1674 wxAuiDockInfo& dock,
1675 wxAuiPaneInfo& pane,
1676 wxAuiDockUIPartArray& uiparts,
1677 bool spacer_only)
be66f18e 1678{
a3a5df9d 1679 wxAuiDockUIPart part;
50acee04
JS
1680 wxSizerItem* sizer_item;
1681
254a3429
BW
1682 int caption_size = m_art->GetMetric(wxAUI_DOCKART_CAPTION_SIZE);
1683 int gripper_size = m_art->GetMetric(wxAUI_DOCKART_GRIPPER_SIZE);
1684 int pane_border_size = m_art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE);
1685 int pane_button_size = m_art->GetMetric(wxAUI_DOCKART_PANE_BUTTON_SIZE);
50acee04
JS
1686
1687 // find out the orientation of the item (orientation for panes
1688 // is the same as the dock's orientation)
1689 int orientation;
1690 if (dock.IsHorizontal())
1691 orientation = wxHORIZONTAL;
7608fd01 1692 else
50acee04
JS
1693 orientation = wxVERTICAL;
1694
1695 // this variable will store the proportion
1696 // value that the pane will receive
1697 int pane_proportion = pane.dock_proportion;
1698
1699 wxBoxSizer* horz_pane_sizer = new wxBoxSizer(wxHORIZONTAL);
1700 wxBoxSizer* vert_pane_sizer = new wxBoxSizer(wxVERTICAL);
1701
1702 if (pane.HasGripper())
1703 {
1704 if (pane.HasGripperTop())
1705 sizer_item = vert_pane_sizer ->Add(1, gripper_size, 0, wxEXPAND);
be66f18e 1706 else
50acee04
JS
1707 sizer_item = horz_pane_sizer ->Add(gripper_size, 1, 0, wxEXPAND);
1708
a3a5df9d 1709 part.type = wxAuiDockUIPart::typeGripper;
50acee04
JS
1710 part.dock = &dock;
1711 part.pane = &pane;
1712 part.button = NULL;
1713 part.orientation = orientation;
1714 part.cont_sizer = horz_pane_sizer;
1715 part.sizer_item = sizer_item;
1716 uiparts.Add(part);
1717 }
1718
1719 if (pane.HasCaption())
1720 {
1721 // create the caption sizer
1722 wxBoxSizer* caption_sizer = new wxBoxSizer(wxHORIZONTAL);
1723
1724 sizer_item = caption_sizer->Add(1, caption_size, 1, wxEXPAND);
1725
a3a5df9d 1726 part.type = wxAuiDockUIPart::typeCaption;
50acee04
JS
1727 part.dock = &dock;
1728 part.pane = &pane;
1729 part.button = NULL;
1730 part.orientation = orientation;
1731 part.cont_sizer = vert_pane_sizer;
1732 part.sizer_item = sizer_item;
1733 int caption_part_idx = uiparts.GetCount();
1734 uiparts.Add(part);
1735
1736 // add pane buttons to the caption
1737 int i, button_count;
1738 for (i = 0, button_count = pane.buttons.GetCount();
1739 i < button_count; ++i)
1740 {
a3a5df9d 1741 wxAuiPaneButton& button = pane.buttons.Item(i);
50acee04
JS
1742
1743 sizer_item = caption_sizer->Add(pane_button_size,
1744 caption_size,
1745 0, wxEXPAND);
1746
a3a5df9d 1747 part.type = wxAuiDockUIPart::typePaneButton;
50acee04
JS
1748 part.dock = &dock;
1749 part.pane = &pane;
1750 part.button = &button;
1751 part.orientation = orientation;
1752 part.cont_sizer = caption_sizer;
1753 part.sizer_item = sizer_item;
1754 uiparts.Add(part);
1755 }
7608fd01 1756
8896cb72
BW
1757 // if we have buttons, add a little space to the right
1758 // of them to ease visual crowding
1759 if (button_count >= 1)
1760 {
1761 caption_sizer->Add(3,1);
1762 }
50acee04
JS
1763
1764 // add the caption sizer
1765 sizer_item = vert_pane_sizer->Add(caption_sizer, 0, wxEXPAND);
1766
1767 uiparts.Item(caption_part_idx).sizer_item = sizer_item;
1768 }
1769
1770 // add the pane window itself
1771 if (spacer_only)
1772 {
1773 sizer_item = vert_pane_sizer->Add(1, 1, 1, wxEXPAND);
1774 }
696978ee 1775 else
50acee04
JS
1776 {
1777 sizer_item = vert_pane_sizer->Add(pane.window, 1, wxEXPAND);
5c62cb6c 1778 // Don't do this because it breaks the pane size in floating windows
dec588bd
BW
1779 // BIW: Right now commenting this out is causing problems with
1780 // an mdi client window as the center pane.
1781 vert_pane_sizer->SetItemMinSize(pane.window, 1, 1);
50acee04
JS
1782 }
1783
a3a5df9d 1784 part.type = wxAuiDockUIPart::typePane;
50acee04
JS
1785 part.dock = &dock;
1786 part.pane = &pane;
1787 part.button = NULL;
1788 part.orientation = orientation;
1789 part.cont_sizer = vert_pane_sizer;
1790 part.sizer_item = sizer_item;
1791 uiparts.Add(part);
1792
1793
1794 // determine if the pane should have a minimum size; if the pane is
1dc6ec2c 1795 // non-resizable (fixed) then we must set a minimum size. Alternatively,
50acee04 1796 // if the pane.min_size is set, we must use that value as well
be66f18e 1797
50acee04
JS
1798 wxSize min_size = pane.min_size;
1799 if (pane.IsFixed())
1800 {
1801 if (min_size == wxDefaultSize)
1802 {
1803 min_size = pane.best_size;
1804 pane_proportion = 0;
1805 }
1806 }
be66f18e 1807
50acee04
JS
1808 if (min_size != wxDefaultSize)
1809 {
1810 vert_pane_sizer->SetItemMinSize(
1811 vert_pane_sizer->GetChildren().GetCount()-1,
1812 min_size.x, min_size.y);
1813 }
1814
1815
1816 // add the verticle sizer (caption, pane window) to the
1817 // horizontal sizer (gripper, verticle sizer)
1818 horz_pane_sizer->Add(vert_pane_sizer, 1, wxEXPAND);
1819
1820 // finally, add the pane sizer to the dock sizer
1821
1822 if (pane.HasBorder())
1823 {
1824 // allowing space for the pane's border
1825 sizer_item = cont->Add(horz_pane_sizer, pane_proportion,
1826 wxEXPAND | wxALL, pane_border_size);
1827
a3a5df9d 1828 part.type = wxAuiDockUIPart::typePaneBorder;
50acee04
JS
1829 part.dock = &dock;
1830 part.pane = &pane;
1831 part.button = NULL;
1832 part.orientation = orientation;
1833 part.cont_sizer = cont;
1834 part.sizer_item = sizer_item;
1835 uiparts.Add(part);
1836 }
7608fd01 1837 else
50acee04
JS
1838 {
1839 sizer_item = cont->Add(horz_pane_sizer, pane_proportion, wxEXPAND);
1840 }
1841}
1842
a3a5df9d 1843void wxAuiManager::LayoutAddDock(wxSizer* cont,
bb38f6c8
BW
1844 wxAuiDockInfo& dock,
1845 wxAuiDockUIPartArray& uiparts,
1846 bool spacer_only)
50acee04
JS
1847{
1848 wxSizerItem* sizer_item;
a3a5df9d 1849 wxAuiDockUIPart part;
50acee04 1850
254a3429 1851 int sash_size = m_art->GetMetric(wxAUI_DOCKART_SASH_SIZE);
50acee04
JS
1852 int orientation = dock.IsHorizontal() ? wxHORIZONTAL : wxVERTICAL;
1853
1854 // resizable bottom and right docks have a sash before them
37106ab2 1855 if (!m_has_maximized && !dock.fixed && (dock.dock_direction == wxAUI_DOCK_BOTTOM ||
50acee04
JS
1856 dock.dock_direction == wxAUI_DOCK_RIGHT))
1857 {
1858 sizer_item = cont->Add(sash_size, sash_size, 0, wxEXPAND);
1859
a3a5df9d 1860 part.type = wxAuiDockUIPart::typeDockSizer;
50acee04
JS
1861 part.orientation = orientation;
1862 part.dock = &dock;
1863 part.pane = NULL;
1864 part.button = NULL;
1865 part.cont_sizer = cont;
1866 part.sizer_item = sizer_item;
1867 uiparts.Add(part);
1868 }
1869
1870 // create the sizer for the dock
1871 wxSizer* dock_sizer = new wxBoxSizer(orientation);
1872
1873 // add each pane to the dock
37106ab2 1874 bool has_maximized_pane = false;
50acee04
JS
1875 int pane_i, pane_count = dock.panes.GetCount();
1876
1877 if (dock.fixed)
1878 {
1879 wxArrayInt pane_positions, pane_sizes;
be66f18e 1880
50acee04
JS
1881 // figure out the real pane positions we will
1882 // use, without modifying the each pane's pane_pos member
1883 GetPanePositionsAndSizes(dock, pane_positions, pane_sizes);
1884
1885 int offset = 0;
1886 for (pane_i = 0; pane_i < pane_count; ++pane_i)
1887 {
a3a5df9d 1888 wxAuiPaneInfo& pane = *(dock.panes.Item(pane_i));
50acee04 1889 int pane_pos = pane_positions.Item(pane_i);
7608fd01 1890
bb38f6c8 1891 if (pane.IsMaximized())
37106ab2 1892 has_maximized_pane = true;
bb38f6c8 1893
50acee04
JS
1894
1895 int amount = pane_pos - offset;
1896 if (amount > 0)
1897 {
1898 if (dock.IsVertical())
1899 sizer_item = dock_sizer->Add(1, amount, 0, wxEXPAND);
7608fd01 1900 else
50acee04
JS
1901 sizer_item = dock_sizer->Add(amount, 1, 0, wxEXPAND);
1902
a3a5df9d 1903 part.type = wxAuiDockUIPart::typeBackground;
50acee04
JS
1904 part.dock = &dock;
1905 part.pane = NULL;
1906 part.button = NULL;
1907 part.orientation = (orientation==wxHORIZONTAL) ? wxVERTICAL:wxHORIZONTAL;
1908 part.cont_sizer = dock_sizer;
1909 part.sizer_item = sizer_item;
1910 uiparts.Add(part);
1911
1912 offset += amount;
1913 }
1914
1915 LayoutAddPane(dock_sizer, dock, pane, uiparts, spacer_only);
1916
1917 offset += pane_sizes.Item(pane_i);
1918 }
1919
1920 // at the end add a very small stretchable background area
bb38f6c8 1921 sizer_item = dock_sizer->Add(0,0, 1, wxEXPAND);
50acee04 1922
a3a5df9d 1923 part.type = wxAuiDockUIPart::typeBackground;
50acee04
JS
1924 part.dock = &dock;
1925 part.pane = NULL;
1926 part.button = NULL;
1927 part.orientation = orientation;
1928 part.cont_sizer = dock_sizer;
1929 part.sizer_item = sizer_item;
1930 uiparts.Add(part);
1931 }
696978ee 1932 else
50acee04
JS
1933 {
1934 for (pane_i = 0; pane_i < pane_count; ++pane_i)
1935 {
a3a5df9d 1936 wxAuiPaneInfo& pane = *(dock.panes.Item(pane_i));
7608fd01 1937
32e4b03c 1938 if (pane.IsMaximized())
37106ab2 1939 has_maximized_pane = true;
50acee04
JS
1940
1941 // if this is not the first pane being added,
1942 // we need to add a pane sizer
37106ab2 1943 if (!m_has_maximized && pane_i > 0)
50acee04
JS
1944 {
1945 sizer_item = dock_sizer->Add(sash_size, sash_size, 0, wxEXPAND);
1946
a3a5df9d 1947 part.type = wxAuiDockUIPart::typePaneSizer;
50acee04
JS
1948 part.dock = &dock;
1949 part.pane = dock.panes.Item(pane_i-1);
1950 part.button = NULL;
1951 part.orientation = (orientation==wxHORIZONTAL) ? wxVERTICAL:wxHORIZONTAL;
1952 part.cont_sizer = dock_sizer;
1953 part.sizer_item = sizer_item;
1954 uiparts.Add(part);
1955 }
1956
1957 LayoutAddPane(dock_sizer, dock, pane, uiparts, spacer_only);
1958 }
1959 }
1960
37106ab2 1961 if (dock.dock_direction == wxAUI_DOCK_CENTER || has_maximized_pane)
50acee04 1962 sizer_item = cont->Add(dock_sizer, 1, wxEXPAND);
7608fd01 1963 else
50acee04
JS
1964 sizer_item = cont->Add(dock_sizer, 0, wxEXPAND);
1965
a3a5df9d 1966 part.type = wxAuiDockUIPart::typeDock;
50acee04
JS
1967 part.dock = &dock;
1968 part.pane = NULL;
1969 part.button = NULL;
1970 part.orientation = orientation;
1971 part.cont_sizer = cont;
1972 part.sizer_item = sizer_item;
1973 uiparts.Add(part);
1974
1975 if (dock.IsHorizontal())
1976 cont->SetItemMinSize(dock_sizer, 0, dock.size);
7608fd01 1977 else
50acee04
JS
1978 cont->SetItemMinSize(dock_sizer, dock.size, 0);
1979
1980 // top and left docks have a sash after them
bb38f6c8
BW
1981 if (!m_has_maximized &&
1982 !dock.fixed &&
1983 (dock.dock_direction == wxAUI_DOCK_TOP ||
1984 dock.dock_direction == wxAUI_DOCK_LEFT))
50acee04
JS
1985 {
1986 sizer_item = cont->Add(sash_size, sash_size, 0, wxEXPAND);
1987
a3a5df9d 1988 part.type = wxAuiDockUIPart::typeDockSizer;
50acee04
JS
1989 part.dock = &dock;
1990 part.pane = NULL;
1991 part.button = NULL;
1992 part.orientation = orientation;
1993 part.cont_sizer = cont;
1994 part.sizer_item = sizer_item;
1995 uiparts.Add(part);
1996 }
1997}
1998
a3a5df9d 1999wxSizer* wxAuiManager::LayoutAll(wxAuiPaneInfoArray& panes,
8d0634ab
BW
2000 wxAuiDockInfoArray& docks,
2001 wxAuiDockUIPartArray& uiparts,
2002 bool spacer_only)
50acee04
JS
2003{
2004 wxBoxSizer* container = new wxBoxSizer(wxVERTICAL);
2005
254a3429
BW
2006 int pane_border_size = m_art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE);
2007 int caption_size = m_art->GetMetric(wxAUI_DOCKART_CAPTION_SIZE);
50acee04
JS
2008 wxSize cli_size = m_frame->GetClientSize();
2009 int i, dock_count, pane_count;
be66f18e 2010
50acee04
JS
2011
2012 // empty all docks out
2013 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
03dc5fad
BW
2014 {
2015 wxAuiDockInfo& dock = docks.Item(i);
7608fd01 2016
03dc5fad
BW
2017 // empty out all panes, as they will be readded below
2018 dock.panes.Empty();
7608fd01 2019
03dc5fad
BW
2020 if (dock.fixed)
2021 {
2022 // always reset fixed docks' sizes, because
2023 // the contained windows may have been resized
2024 dock.size = 0;
2025 }
2026 }
be66f18e 2027
37106ab2 2028
50acee04
JS
2029 // iterate through all known panes, filing each
2030 // of them into the appropriate dock. If the
2031 // pane does not exist in the dock, add it
2032 for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
2033 {
a3a5df9d 2034 wxAuiPaneInfo& p = panes.Item(i);
50acee04 2035
bb38f6c8
BW
2036 // find any docks with the same dock direction, dock layer, and
2037 // dock row as the pane we are working on
a3a5df9d
BW
2038 wxAuiDockInfo* dock;
2039 wxAuiDockInfoPtrArray arr;
50acee04
JS
2040 FindDocks(docks, p.dock_direction, p.dock_layer, p.dock_row, arr);
2041
2042 if (arr.GetCount() > 0)
2043 {
bb38f6c8 2044 // found the right dock
50acee04
JS
2045 dock = arr.Item(0);
2046 }
7608fd01 2047 else
50acee04
JS
2048 {
2049 // dock was not found, so we need to create a new one
a3a5df9d 2050 wxAuiDockInfo d;
50acee04
JS
2051 d.dock_direction = p.dock_direction;
2052 d.dock_layer = p.dock_layer;
2053 d.dock_row = p.dock_row;
2054 docks.Add(d);
2055 dock = &docks.Last();
2056 }
2057
2058
2059 if (p.IsDocked() && p.IsShown())
2060 {
2061 // remove the pane from any existing docks except this one
2062 RemovePaneFromDocks(docks, p, dock);
2063
2064 // pane needs to be added to the dock,
be66f18e 2065 // if it doesn't already exist
50acee04
JS
2066 if (!FindPaneInDock(*dock, p.window))
2067 dock->panes.Add(&p);
2068 }
7608fd01 2069 else
50acee04
JS
2070 {
2071 // remove the pane from any existing docks
2072 RemovePaneFromDocks(docks, p);
2073 }
2074
2075 }
2076
2077 // remove any empty docks
2078 for (i = docks.GetCount()-1; i >= 0; --i)
2079 {
2080 if (docks.Item(i).panes.GetCount() == 0)
2081 docks.RemoveAt(i);
2082 }
2083
2084 // configure the docks further
2085 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
2086 {
a3a5df9d 2087 wxAuiDockInfo& dock = docks.Item(i);
50acee04 2088 int j, dock_pane_count = dock.panes.GetCount();
be66f18e 2089
50acee04
JS
2090 // sort the dock pane array by the pane's
2091 // dock position (dock_pos), in ascending order
2092 dock.panes.Sort(PaneSortFunc);
2093
2094 // for newly created docks, set up their initial size
2095 if (dock.size == 0)
2096 {
2097 int size = 0;
2098
2099 for (j = 0; j < dock_pane_count; ++j)
2100 {
a3a5df9d 2101 wxAuiPaneInfo& pane = *dock.panes.Item(j);
50acee04
JS
2102 wxSize pane_size = pane.best_size;
2103 if (pane_size == wxDefaultSize)
2104 pane_size = pane.min_size;
2105 if (pane_size == wxDefaultSize)
2106 pane_size = pane.window->GetSize();
be66f18e 2107
50acee04
JS
2108 if (dock.IsHorizontal())
2109 size = wxMax(pane_size.y, size);
7608fd01 2110 else
50acee04
JS
2111 size = wxMax(pane_size.x, size);
2112 }
be66f18e 2113
50acee04
JS
2114 // add space for the border (two times), but only
2115 // if at least one pane inside the dock has a pane border
2116 for (j = 0; j < dock_pane_count; ++j)
2117 {
2118 if (dock.panes.Item(j)->HasBorder())
2119 {
2120 size += (pane_border_size*2);
2121 break;
2122 }
2123 }
2124
2125 // if pane is on the top or bottom, add the caption height,
2126 // but only if at least one pane inside the dock has a caption
2127 if (dock.IsHorizontal())
2128 {
2129 for (j = 0; j < dock_pane_count; ++j)
2130 {
2131 if (dock.panes.Item(j)->HasCaption())
2132 {
2133 size += caption_size;
2134 break;
2135 }
2136 }
2137 }
2138
a6b7a521
VZ
2139
2140 // new dock's size may not be more than the dock constraint
2141 // parameter specifies. See SetDockSizeConstraint()
7608fd01 2142
a6b7a521
VZ
2143 int max_dock_x_size = (int)(m_dock_constraint_x * ((double)cli_size.x));
2144 int max_dock_y_size = (int)(m_dock_constraint_y * ((double)cli_size.y));
7608fd01 2145
a6b7a521
VZ
2146 if (dock.IsHorizontal())
2147 size = wxMin(size, max_dock_y_size);
7608fd01 2148 else
a6b7a521
VZ
2149 size = wxMin(size, max_dock_x_size);
2150
2151 // absolute minimum size for a dock is 10 pixels
50acee04
JS
2152 if (size < 10)
2153 size = 10;
7608fd01 2154
50acee04
JS
2155 dock.size = size;
2156 }
2157
2158
2159 // determine the dock's minimum size
2160 bool plus_border = false;
2161 bool plus_caption = false;
2162 int dock_min_size = 0;
2163 for (j = 0; j < dock_pane_count; ++j)
2164 {
a3a5df9d 2165 wxAuiPaneInfo& pane = *dock.panes.Item(j);
50acee04
JS
2166 if (pane.min_size != wxDefaultSize)
2167 {
2168 if (pane.HasBorder())
2169 plus_border = true;
2170 if (pane.HasCaption())
2171 plus_caption = true;
2172 if (dock.IsHorizontal())
2173 {
2174 if (pane.min_size.y > dock_min_size)
2175 dock_min_size = pane.min_size.y;
2176 }
7608fd01 2177 else
50acee04
JS
2178 {
2179 if (pane.min_size.x > dock_min_size)
2180 dock_min_size = pane.min_size.x;
2181 }
2182 }
2183 }
be66f18e 2184
50acee04
JS
2185 if (plus_border)
2186 dock_min_size += (pane_border_size*2);
2187 if (plus_caption && dock.IsHorizontal())
2188 dock_min_size += (caption_size);
be66f18e 2189
50acee04 2190 dock.min_size = dock_min_size;
be66f18e
WS
2191
2192
50acee04
JS
2193 // if the pane's current size is less than it's
2194 // minimum, increase the dock's size to it's minimum
2195 if (dock.size < dock.min_size)
2196 dock.size = dock.min_size;
2197
2198
2199 // determine the dock's mode (fixed or proportional);
2200 // determine whether the dock has only toolbars
2201 bool action_pane_marked = false;
2202 dock.fixed = true;
2203 dock.toolbar = true;
2204 for (j = 0; j < dock_pane_count; ++j)
2205 {
a3a5df9d 2206 wxAuiPaneInfo& pane = *dock.panes.Item(j);
50acee04
JS
2207 if (!pane.IsFixed())
2208 dock.fixed = false;
2209 if (!pane.IsToolbar())
2210 dock.toolbar = false;
c89e16e4
BW
2211 if (pane.HasFlag(wxAuiPaneInfo::optionDockFixed))
2212 dock.fixed = true;
a3a5df9d 2213 if (pane.state & wxAuiPaneInfo::actionPane)
50acee04
JS
2214 action_pane_marked = true;
2215 }
2216
2217
2218 // if the dock mode is proportional and not fixed-pixel,
2219 // reassign the dock_pos to the sequential 0, 1, 2, 3;
2220 // e.g. remove gaps like 1, 2, 30, 500
2221 if (!dock.fixed)
2222 {
2223 for (j = 0; j < dock_pane_count; ++j)
2224 {
a3a5df9d 2225 wxAuiPaneInfo& pane = *dock.panes.Item(j);
50acee04
JS
2226 pane.dock_pos = j;
2227 }
2228 }
2229
2230 // if the dock mode is fixed, and none of the panes
2231 // are being moved right now, make sure the panes
2232 // do not overlap each other. If they do, we will
bb38f6c8 2233 // adjust the positions of the panes
50acee04
JS
2234 if (dock.fixed && !action_pane_marked)
2235 {
2236 wxArrayInt pane_positions, pane_sizes;
2237 GetPanePositionsAndSizes(dock, pane_positions, pane_sizes);
be66f18e 2238
50acee04
JS
2239 int offset = 0;
2240 for (j = 0; j < dock_pane_count; ++j)
2241 {
a3a5df9d 2242 wxAuiPaneInfo& pane = *(dock.panes.Item(j));
50acee04
JS
2243 pane.dock_pos = pane_positions[j];
2244
2245 int amount = pane.dock_pos - offset;
2246 if (amount >= 0)
2247 offset += amount;
7608fd01 2248 else
50acee04
JS
2249 pane.dock_pos += -amount;
2250
2251 offset += pane_sizes[j];
2252 }
2253 }
2254 }
be66f18e 2255
50acee04
JS
2256 // discover the maximum dock layer
2257 int max_layer = 0;
2258 for (i = 0; i < dock_count; ++i)
2259 max_layer = wxMax(max_layer, docks.Item(i).dock_layer);
be66f18e 2260
50acee04
JS
2261
2262 // clear out uiparts
2263 uiparts.Empty();
2264
2265 // create a bunch of box sizers,
2266 // from the innermost level outwards.
2267 wxSizer* cont = NULL;
2268 wxSizer* middle = NULL;
2269 int layer = 0;
2270 int row, row_count;
2271
2272 for (layer = 0; layer <= max_layer; ++layer)
2273 {
a3a5df9d 2274 wxAuiDockInfoPtrArray arr;
50acee04
JS
2275
2276 // find any docks in this layer
2277 FindDocks(docks, -1, layer, -1, arr);
2278
2279 // if there aren't any, skip to the next layer
2280 if (arr.IsEmpty())
2281 continue;
2282
2283 wxSizer* old_cont = cont;
2284
2285 // create a container which will hold this layer's
2286 // docks (top, bottom, left, right)
2287 cont = new wxBoxSizer(wxVERTICAL);
2288
2289
2290 // find any top docks in this layer
2291 FindDocks(docks, wxAUI_DOCK_TOP, layer, -1, arr);
50acee04
JS
2292 if (!arr.IsEmpty())
2293 {
2294 for (row = 0, row_count = arr.GetCount(); row < row_count; ++row)
2295 LayoutAddDock(cont, *arr.Item(row), uiparts, spacer_only);
2296 }
2297
be66f18e 2298
50acee04
JS
2299 // fill out the middle layer (which consists
2300 // of left docks, content area and right docks)
be66f18e 2301
50acee04
JS
2302 middle = new wxBoxSizer(wxHORIZONTAL);
2303
2304 // find any left docks in this layer
2305 FindDocks(docks, wxAUI_DOCK_LEFT, layer, -1, arr);
50acee04
JS
2306 if (!arr.IsEmpty())
2307 {
2308 for (row = 0, row_count = arr.GetCount(); row < row_count; ++row)
2309 LayoutAddDock(middle, *arr.Item(row), uiparts, spacer_only);
2310 }
2311
2312 // add content dock (or previous layer's sizer
2313 // to the middle
2314 if (!old_cont)
2315 {
2316 // find any center docks
2317 FindDocks(docks, wxAUI_DOCK_CENTER, -1, -1, arr);
2318 if (!arr.IsEmpty())
2319 {
2320 for (row = 0,row_count = arr.GetCount(); row<row_count; ++row)
2321 LayoutAddDock(middle, *arr.Item(row), uiparts, spacer_only);
2322 }
7608fd01 2323 else if (!m_has_maximized)
50acee04
JS
2324 {
2325 // there are no center docks, add a background area
2326 wxSizerItem* sizer_item = middle->Add(1,1, 1, wxEXPAND);
a3a5df9d
BW
2327 wxAuiDockUIPart part;
2328 part.type = wxAuiDockUIPart::typeBackground;
50acee04
JS
2329 part.pane = NULL;
2330 part.dock = NULL;
2331 part.button = NULL;
2332 part.cont_sizer = middle;
2333 part.sizer_item = sizer_item;
2334 uiparts.Add(part);
2335 }
2336 }
7608fd01 2337 else
50acee04
JS
2338 {
2339 middle->Add(old_cont, 1, wxEXPAND);
2340 }
2341
2342 // find any right docks in this layer
2343 FindDocks(docks, wxAUI_DOCK_RIGHT, layer, -1, arr);
50acee04
JS
2344 if (!arr.IsEmpty())
2345 {
2346 for (row = arr.GetCount()-1; row >= 0; --row)
2347 LayoutAddDock(middle, *arr.Item(row), uiparts, spacer_only);
2348 }
2349
3b58a205
BW
2350 if (middle->GetChildren().GetCount() > 0)
2351 cont->Add(middle, 1, wxEXPAND);
a25484eb
BW
2352 else
2353 delete middle;
2354
50acee04
JS
2355
2356
2357 // find any bottom docks in this layer
2358 FindDocks(docks, wxAUI_DOCK_BOTTOM, layer, -1, arr);
50acee04
JS
2359 if (!arr.IsEmpty())
2360 {
2361 for (row = arr.GetCount()-1; row >= 0; --row)
2362 LayoutAddDock(cont, *arr.Item(row), uiparts, spacer_only);
2363 }
2364
2365 }
2366
2367 if (!cont)
2368 {
2369 // no sizer available, because there are no docks,
2370 // therefore we will create a simple background area
2371 cont = new wxBoxSizer(wxVERTICAL);
2372 wxSizerItem* sizer_item = cont->Add(1,1, 1, wxEXPAND);
a3a5df9d
BW
2373 wxAuiDockUIPart part;
2374 part.type = wxAuiDockUIPart::typeBackground;
50acee04
JS
2375 part.pane = NULL;
2376 part.dock = NULL;
2377 part.button = NULL;
2378 part.cont_sizer = middle;
2379 part.sizer_item = sizer_item;
2380 uiparts.Add(part);
2381 }
2382
2383 container->Add(cont, 1, wxEXPAND);
2384 return container;
2385}
2386
2387
a6b7a521
VZ
2388// SetDockSizeConstraint() allows the dock constraints to be set. For example,
2389// specifying values of 0.5, 0.5 will mean that upon dock creation, a dock may
2390// not be larger than half of the window's size
2391
2392void wxAuiManager::SetDockSizeConstraint(double width_pct, double height_pct)
2393{
2394 m_dock_constraint_x = wxMax(0.0, wxMin(1.0, width_pct));
2395 m_dock_constraint_y = wxMax(0.0, wxMin(1.0, height_pct));
2396}
2397
2398void wxAuiManager::GetDockSizeConstraint(double* width_pct, double* height_pct) const
2399{
2400 if (width_pct)
2401 *width_pct = m_dock_constraint_x;
7608fd01 2402
a6b7a521
VZ
2403 if (height_pct)
2404 *height_pct = m_dock_constraint_y;
2405}
2406
2407
2408
50acee04
JS
2409// Update() updates the layout. Whenever changes are made to
2410// one or more panes, this function should be called. It is the
2411// external entry point for running the layout engine.
2412
a3a5df9d 2413void wxAuiManager::Update()
50acee04 2414{
987bb1c6 2415 m_hover_button = NULL;
d1939071 2416 m_action_part = NULL;
987bb1c6 2417
50acee04
JS
2418 wxSizer* sizer;
2419 int i, pane_count = m_panes.GetCount();
2420
50acee04
JS
2421
2422 // destroy floating panes which have been
2423 // redocked or are becoming non-floating
2424 for (i = 0; i < pane_count; ++i)
2425 {
a3a5df9d 2426 wxAuiPaneInfo& p = m_panes.Item(i);
50acee04
JS
2427
2428 if (!p.IsFloating() && p.frame)
2429 {
2430 // because the pane is no longer in a floating, we need to
2431 // reparent it to m_frame and destroy the floating frame
be66f18e 2432
50acee04
JS
2433 // reduce flicker
2434 p.window->SetSize(1,1);
26178b5d 2435
533bedbf 2436
cedd7b22
PC
2437 // the following block is a workaround for bug #1531361
2438 // (see wxWidgets sourceforge page). On wxGTK (only), when
2439 // a frame is shown/hidden, a move event unfortunately
2440 // also gets fired. Because we may be dragging around
2441 // a pane, we need to cancel that action here to prevent
2442 // a spurious crash.
2443 if (m_action_window == p.frame)
2444 {
2445 if (wxWindow::GetCapture() == m_frame)
533bedbf
BW
2446 m_frame->ReleaseMouse();
2447 m_action = actionNone;
cedd7b22
PC
2448 m_action_window = NULL;
2449 }
533bedbf 2450
cedd7b22 2451 // hide the frame
26178b5d
BW
2452 if (p.frame->IsShown())
2453 p.frame->Show(false);
be66f18e 2454
50acee04 2455 // reparent to m_frame and destroy the pane
32e4b03c 2456 if (m_action_window == p.frame)
528a5e8f 2457 {
49fa1dbb
RR
2458 m_action_window = NULL;
2459 }
7608fd01 2460
50acee04
JS
2461 p.window->Reparent(m_frame);
2462 p.frame->SetSizer(NULL);
2463 p.frame->Destroy();
2464 p.frame = NULL;
2465 }
2466 }
2467
2468
852a7df6
BW
2469 // delete old sizer first
2470 m_frame->SetSizer(NULL);
2471
50acee04
JS
2472 // create a layout for all of the panes
2473 sizer = LayoutAll(m_panes, m_docks, m_uiparts, false);
2474
2475 // hide or show panes as necessary,
2476 // and float panes as necessary
2477 for (i = 0; i < pane_count; ++i)
2478 {
a3a5df9d 2479 wxAuiPaneInfo& p = m_panes.Item(i);
50acee04
JS
2480
2481 if (p.IsFloating())
2482 {
2483 if (p.frame == NULL)
2484 {
2485 // we need to create a frame for this
2486 // pane, which has recently been floated
00c1c94c 2487 wxAuiFloatingFrame* frame = CreateFloatingFrame(m_frame, p);
be66f18e 2488
81cc4eb2 2489 // on MSW and Mac, if the owner desires transparent dragging, and
50acee04 2490 // the dragging is happening right now, then the floating
be66f18e 2491 // window should have this style by default
50acee04
JS
2492 if (m_action == actionDragFloatingPane &&
2493 (m_flags & wxAUI_MGR_TRANSPARENT_DRAG))
07880314 2494 frame->SetTransparent(150);
be66f18e 2495
50acee04
JS
2496 frame->SetPaneWindow(p);
2497 p.frame = frame;
2498
26178b5d 2499 if (p.IsShown() && !frame->IsShown())
50acee04 2500 frame->Show();
50acee04 2501 }
7608fd01 2502 else
50acee04
JS
2503 {
2504 // frame already exists, make sure it's position
a3a5df9d 2505 // and size reflect the information in wxAuiPaneInfo
ab620250 2506 if ((p.frame->GetPosition() != p.floating_pos) || (p.frame->GetSize() != p.floating_size))
50acee04 2507 {
9e1fc0e4
BW
2508 p.frame->SetSize(p.floating_pos.x, p.floating_pos.y,
2509 p.floating_size.x, p.floating_size.y,
2510 wxSIZE_USE_EXISTING);
2511 /*
50acee04 2512 p.frame->SetSize(p.floating_pos.x, p.floating_pos.y,
a1b3b608
WS
2513 wxDefaultCoord, wxDefaultCoord,
2514 wxSIZE_USE_EXISTING);
50acee04 2515 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
9e1fc0e4 2516 */
50acee04
JS
2517 }
2518
f88d1716
BW
2519 if (p.frame->IsShown() != p.IsShown())
2520 p.frame->Show(p.IsShown());
50acee04
JS
2521 }
2522 }
7608fd01 2523 else
50acee04 2524 {
26178b5d
BW
2525 if (p.window->IsShown() != p.IsShown())
2526 p.window->Show(p.IsShown());
50acee04
JS
2527 }
2528
2529 // if "active panes" are no longer allowed, clear
2530 // any optionActive values from the pane states
2531 if ((m_flags & wxAUI_MGR_ALLOW_ACTIVE_PANE) == 0)
2532 {
a3a5df9d 2533 p.state &= ~wxAuiPaneInfo::optionActive;
50acee04
JS
2534 }
2535 }
2536
2537
2538 // keep track of the old window rectangles so we can
2539 // refresh those windows whose rect has changed
2540 wxAuiRectArray old_pane_rects;
2541 for (i = 0; i < pane_count; ++i)
2542 {
2543 wxRect r;
a3a5df9d 2544 wxAuiPaneInfo& p = m_panes.Item(i);
50acee04
JS
2545
2546 if (p.window && p.IsShown() && p.IsDocked())
2547 r = p.rect;
2548
2549 old_pane_rects.Add(r);
2550 }
2551
2552
2553
2554
2555 // apply the new sizer
2556 m_frame->SetSizer(sizer);
2557 m_frame->SetAutoLayout(false);
2558 DoFrameLayout();
2559
2560
2561
2562 // now that the frame layout is done, we need to check
2563 // the new pane rectangles against the old rectangles that
2564 // we saved a few lines above here. If the rectangles have
2565 // changed, the corresponding panes must also be updated
2566 for (i = 0; i < pane_count; ++i)
2567 {
a3a5df9d 2568 wxAuiPaneInfo& p = m_panes.Item(i);
50acee04
JS
2569 if (p.window && p.window->IsShown() && p.IsDocked())
2570 {
2571 if (p.rect != old_pane_rects[i])
2572 {
2573 p.window->Refresh();
2574 p.window->Update();
2575 }
2576 }
2577 }
2578
2579
2580 Repaint();
be66f18e 2581
50acee04 2582 // set frame's minimum size
be66f18e 2583
50acee04
JS
2584/*
2585 // N.B. More work needs to be done on frame minimum sizes;
2586 // this is some intresting code that imposes the minimum size,
2587 // but we may want to include a more flexible mechanism or
2588 // options for multiple minimum-size modes, e.g. strict or lax
2589 wxSize min_size = sizer->GetMinSize();
2590 wxSize frame_size = m_frame->GetSize();
2591 wxSize client_size = m_frame->GetClientSize();
2592
2593 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2594 min_size.y+frame_size.y-client_size.y );
be66f18e 2595
50acee04 2596 m_frame->SetMinSize(minframe_size);
be66f18e 2597
50acee04
JS
2598 if (frame_size.x < minframe_size.x ||
2599 frame_size.y < minframe_size.y)
2600 sizer->Fit(m_frame);
2601*/
2602}
2603
2604
2605// DoFrameLayout() is an internal function which invokes wxSizer::Layout
2606// on the frame's main sizer, then measures all the various UI items
2607// and updates their internal rectangles. This should always be called
2608// instead of calling m_frame->Layout() directly
2609
a3a5df9d 2610void wxAuiManager::DoFrameLayout()
50acee04
JS
2611{
2612 m_frame->Layout();
be66f18e 2613
50acee04
JS
2614 int i, part_count;
2615 for (i = 0, part_count = m_uiparts.GetCount(); i < part_count; ++i)
2616 {
a3a5df9d 2617 wxAuiDockUIPart& part = m_uiparts.Item(i);
50acee04
JS
2618
2619 // get the rectangle of the UI part
2620 // originally, this code looked like this:
2621 // part.rect = wxRect(part.sizer_item->GetPosition(),
2622 // part.sizer_item->GetSize());
2623 // this worked quite well, with one exception: the mdi
be66f18e 2624 // client window had a "deferred" size variable
50acee04
JS
2625 // that returned the wrong size. It looks like
2626 // a bug in wx, because the former size of the window
2627 // was being returned. So, we will retrieve the part's
2628 // rectangle via other means
2629
2630
2631 part.rect = part.sizer_item->GetRect();
2632 int flag = part.sizer_item->GetFlag();
2633 int border = part.sizer_item->GetBorder();
2634 if (flag & wxTOP)
2635 {
2636 part.rect.y -= border;
2637 part.rect.height += border;
2638 }
2639 if (flag & wxLEFT)
2640 {
2641 part.rect.x -= border;
2642 part.rect.width += border;
2643 }
2644 if (flag & wxBOTTOM)
2645 part.rect.height += border;
2646 if (flag & wxRIGHT)
2647 part.rect.width += border;
2648
2649
a3a5df9d 2650 if (part.type == wxAuiDockUIPart::typeDock)
50acee04 2651 part.dock->rect = part.rect;
a3a5df9d 2652 if (part.type == wxAuiDockUIPart::typePane)
50acee04
JS
2653 part.pane->rect = part.rect;
2654 }
2655}
2656
2657// GetPanePart() looks up the pane the pane border UI part (or the regular
2658// pane part if there is no border). This allows the caller to get the exact
2659// rectangle of the pane in question, including decorations like
2660// caption and border (if any).
2661
a3a5df9d 2662wxAuiDockUIPart* wxAuiManager::GetPanePart(wxWindow* wnd)
50acee04
JS
2663{
2664 int i, part_count;
2665 for (i = 0, part_count = m_uiparts.GetCount(); i < part_count; ++i)
2666 {
a3a5df9d
BW
2667 wxAuiDockUIPart& part = m_uiparts.Item(i);
2668 if (part.type == wxAuiDockUIPart::typePaneBorder &&
50acee04
JS
2669 part.pane && part.pane->window == wnd)
2670 return &part;
2671 }
2672 for (i = 0, part_count = m_uiparts.GetCount(); i < part_count; ++i)
2673 {
a3a5df9d
BW
2674 wxAuiDockUIPart& part = m_uiparts.Item(i);
2675 if (part.type == wxAuiDockUIPart::typePane &&
50acee04
JS
2676 part.pane && part.pane->window == wnd)
2677 return &part;
2678 }
2679 return NULL;
2680}
2681
2682
2683
2684// GetDockPixelOffset() is an internal function which returns
2685// a dock's offset in pixels from the left side of the window
2686// (for horizontal docks) or from the top of the window (for
2687// vertical docks). This value is necessary for calculating
2688// fixel-pane/toolbar offsets when they are dragged.
2689
a3a5df9d 2690int wxAuiManager::GetDockPixelOffset(wxAuiPaneInfo& test)
50acee04
JS
2691{
2692 // the only way to accurately calculate the dock's
2693 // offset is to actually run a theoretical layout
be66f18e 2694
50acee04 2695 int i, part_count, dock_count;
a3a5df9d
BW
2696 wxAuiDockInfoArray docks;
2697 wxAuiPaneInfoArray panes;
2698 wxAuiDockUIPartArray uiparts;
50acee04
JS
2699 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
2700 panes.Add(test);
2701
2702 wxSizer* sizer = LayoutAll(panes, docks, uiparts, true);
2703 wxSize client_size = m_frame->GetClientSize();
2704 sizer->SetDimension(0, 0, client_size.x, client_size.y);
2705 sizer->Layout();
2706
2707 for (i = 0, part_count = uiparts.GetCount(); i < part_count; ++i)
2708 {
a3a5df9d 2709 wxAuiDockUIPart& part = uiparts.Item(i);
50acee04
JS
2710 part.rect = wxRect(part.sizer_item->GetPosition(),
2711 part.sizer_item->GetSize());
a3a5df9d 2712 if (part.type == wxAuiDockUIPart::typeDock)
50acee04
JS
2713 part.dock->rect = part.rect;
2714 }
be66f18e 2715
50acee04 2716 delete sizer;
be66f18e 2717
50acee04
JS
2718 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
2719 {
a3a5df9d 2720 wxAuiDockInfo& dock = docks.Item(i);
50acee04
JS
2721 if (test.dock_direction == dock.dock_direction &&
2722 test.dock_layer==dock.dock_layer && test.dock_row==dock.dock_row)
2723 {
2724 if (dock.IsVertical())
2725 return dock.rect.y;
7608fd01 2726 else
50acee04
JS
2727 return dock.rect.x;
2728 }
2729 }
2730
2731 return 0;
2732}
2733
2734
2735
2736// ProcessDockResult() is a utility function used by DoDrop() - it checks
2737// if a dock operation is allowed, the new dock position is copied into
2738// the target info. If the operation was allowed, the function returns true.
2739
a3a5df9d 2740bool wxAuiManager::ProcessDockResult(wxAuiPaneInfo& target,
1dc6ec2c 2741 const wxAuiPaneInfo& new_pos)
50acee04
JS
2742{
2743 bool allowed = false;
2744 switch (new_pos.dock_direction)
2745 {
2746 case wxAUI_DOCK_TOP: allowed = target.IsTopDockable(); break;
2747 case wxAUI_DOCK_BOTTOM: allowed = target.IsBottomDockable(); break;
2748 case wxAUI_DOCK_LEFT: allowed = target.IsLeftDockable(); break;
2749 case wxAUI_DOCK_RIGHT: allowed = target.IsRightDockable(); break;
2750 }
2751
2752 if (allowed)
2753 target = new_pos;
2754
2755 return allowed;
2756}
2757
2758
2759// DoDrop() is an important function. It basically takes a mouse position,
2760// and determines where the pane's new position would be. If the pane is to be
2761// dropped, it performs the drop operation using the specified dock and pane
2762// arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2763// scenario can be performed, giving precise coordinates for drop hints.
a3a5df9d 2764// If, however, wxAuiManager:m_docks and wxAuiManager::m_panes are specified
50acee04
JS
2765// as parameters, the changes will be made to the main state arrays
2766
2767const int auiInsertRowPixels = 10;
2768const int auiNewRowPixels = 40;
2769const int auiLayerInsertPixels = 40;
2770const int auiLayerInsertOffset = 5;
2771
a3a5df9d 2772bool wxAuiManager::DoDrop(wxAuiDockInfoArray& docks,
32e4b03c
BW
2773 wxAuiPaneInfoArray& panes,
2774 wxAuiPaneInfo& target,
2775 const wxPoint& pt,
2776 const wxPoint& offset)
50acee04
JS
2777{
2778 wxSize cli_size = m_frame->GetClientSize();
2779
a3a5df9d 2780 wxAuiPaneInfo drop = target;
50acee04
JS
2781
2782
2783 // The result should always be shown
2784 drop.Show();
be66f18e 2785
50acee04
JS
2786
2787 // Check to see if the pane has been dragged outside of the window
2788 // (or near to the outside of the window), if so, dock it along the edge
2789
2790
2791 int layer_insert_offset = auiLayerInsertOffset;
32e4b03c 2792 if (drop.IsToolbar())
50acee04 2793 layer_insert_offset = 0;
be66f18e 2794
32e4b03c 2795
50acee04
JS
2796 if (pt.x < layer_insert_offset &&
2797 pt.x > layer_insert_offset-auiLayerInsertPixels)
2798 {
613a0c4c
BW
2799 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_LEFT),
2800 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM)),
32e4b03c 2801 GetMaxLayer(docks, wxAUI_DOCK_TOP)) + 1;
7608fd01 2802
32e4b03c
BW
2803 if (drop.IsToolbar())
2804 new_layer = auiToolBarLayer;
7608fd01 2805
50acee04 2806 drop.Dock().Left().
613a0c4c 2807 Layer(new_layer).
50acee04
JS
2808 Row(0).
2809 Position(pt.y - GetDockPixelOffset(drop) - offset.y);
2810 return ProcessDockResult(target, drop);
2811 }
696978ee
WS
2812 else if (pt.y < layer_insert_offset &&
2813 pt.y > layer_insert_offset-auiLayerInsertPixels)
50acee04 2814 {
613a0c4c
BW
2815 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_TOP),
2816 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2817 GetMaxLayer(docks, wxAUI_DOCK_RIGHT)) + 1;
7608fd01 2818
32e4b03c
BW
2819 if (drop.IsToolbar())
2820 new_layer = auiToolBarLayer;
7608fd01 2821
50acee04 2822 drop.Dock().Top().
613a0c4c 2823 Layer(new_layer).
50acee04
JS
2824 Row(0).
2825 Position(pt.x - GetDockPixelOffset(drop) - offset.x);
2826 return ProcessDockResult(target, drop);
2827 }
696978ee
WS
2828 else if (pt.x >= cli_size.x - layer_insert_offset &&
2829 pt.x < cli_size.x - layer_insert_offset + auiLayerInsertPixels)
50acee04 2830 {
613a0c4c
BW
2831 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_RIGHT),
2832 GetMaxLayer(docks, wxAUI_DOCK_TOP)),
7608fd01
VZ
2833 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM)) + 1;
2834
32e4b03c
BW
2835 if (drop.IsToolbar())
2836 new_layer = auiToolBarLayer;
7608fd01 2837
50acee04 2838 drop.Dock().Right().
613a0c4c 2839 Layer(new_layer).
50acee04
JS
2840 Row(0).
2841 Position(pt.y - GetDockPixelOffset(drop) - offset.y);
2842 return ProcessDockResult(target, drop);
2843 }
696978ee
WS
2844 else if (pt.y >= cli_size.y - layer_insert_offset &&
2845 pt.y < cli_size.y - layer_insert_offset + auiLayerInsertPixels)
50acee04 2846 {
26d18378
RR
2847 int new_layer = wxMax( wxMax( GetMaxLayer(docks, wxAUI_DOCK_BOTTOM),
2848 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2849 GetMaxLayer(docks, wxAUI_DOCK_RIGHT)) + 1;
7608fd01 2850
32e4b03c
BW
2851 if (drop.IsToolbar())
2852 new_layer = auiToolBarLayer;
7608fd01 2853
50acee04 2854 drop.Dock().Bottom().
26d18378 2855 Layer(new_layer).
50acee04
JS
2856 Row(0).
2857 Position(pt.x - GetDockPixelOffset(drop) - offset.x);
2858 return ProcessDockResult(target, drop);
2859 }
2860
32e4b03c 2861
a3a5df9d 2862 wxAuiDockUIPart* part = HitTest(pt.x, pt.y);
50acee04
JS
2863
2864
2865 if (drop.IsToolbar())
2866 {
2867 if (!part || !part->dock)
2868 return false;
93b9de86 2869
50acee04
JS
2870 // calculate the offset from where the dock begins
2871 // to the point where the user dropped the pane
2872 int dock_drop_offset = 0;
2873 if (part->dock->IsHorizontal())
2874 dock_drop_offset = pt.x - part->dock->rect.x - offset.x;
7608fd01 2875 else
50acee04
JS
2876 dock_drop_offset = pt.y - part->dock->rect.y - offset.y;
2877
2878
2879 // toolbars may only be moved in and to fixed-pane docks,
2880 // otherwise we will try to float the pane. Also, the pane
2881 // should float if being dragged over center pane windows
2882 if (!part->dock->fixed || part->dock->dock_direction == wxAUI_DOCK_CENTER)
2883 {
22a35096 2884 if (m_last_rect.IsEmpty() || m_last_rect.Contains(pt.x, pt.y ))
c3008402
RR
2885 {
2886 m_skipping = true;
2887 }
2888 else
2889 {
2890 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
50acee04
JS
2891 (drop.IsFloatable() ||
2892 (part->dock->dock_direction != wxAUI_DOCK_CENTER &&
2893 part->dock->dock_direction != wxAUI_DOCK_NONE)))
c3008402 2894 {
c015463a
BW
2895 if (drop.IsFloatable())
2896 drop.Float();
c3008402 2897 }
93b9de86 2898
c3008402 2899 m_skipping = false;
93b9de86 2900
c3008402 2901 return ProcessDockResult(target, drop);
50acee04 2902 }
93b9de86 2903
c3008402 2904 drop.Position(pt.x - GetDockPixelOffset(drop) - offset.x);
be66f18e 2905
50acee04
JS
2906 return ProcessDockResult(target, drop);
2907 }
93b9de86 2908
cedd7b22
PC
2909 m_skipping = false;
2910
2911 m_last_rect = part->dock->rect;
2912 m_last_rect.Inflate( 15, 15 );
be66f18e 2913
50acee04
JS
2914 drop.Dock().
2915 Direction(part->dock->dock_direction).
2916 Layer(part->dock->dock_layer).
2917 Row(part->dock->dock_row).
2918 Position(dock_drop_offset);
2919
2920 if ((
12125a1e
RR
2921 ((pt.y < part->dock->rect.y + 1) && part->dock->IsHorizontal()) ||
2922 ((pt.x < part->dock->rect.x + 1) && part->dock->IsVertical())
50acee04
JS
2923 ) && part->dock->panes.GetCount() > 1)
2924 {
26d18378
RR
2925 if ((part->dock->dock_direction == wxAUI_DOCK_TOP) ||
2926 (part->dock->dock_direction == wxAUI_DOCK_LEFT))
2927 {
2928 int row = drop.dock_row;
2929 DoInsertDockRow(panes, part->dock->dock_direction,
2930 part->dock->dock_layer,
2931 part->dock->dock_row);
2932 drop.dock_row = row;
2933 }
2934 else
2935 {
2936 DoInsertDockRow(panes, part->dock->dock_direction,
2937 part->dock->dock_layer,
2938 part->dock->dock_row+1);
2939 drop.dock_row = part->dock->dock_row+1;
2940 }
50acee04 2941 }
be66f18e 2942
50acee04
JS
2943 if ((
2944 ((pt.y > part->dock->rect.y + part->dock->rect.height - 2 ) && part->dock->IsHorizontal()) ||
2945 ((pt.x > part->dock->rect.x + part->dock->rect.width - 2 ) && part->dock->IsVertical())
2946 ) && part->dock->panes.GetCount() > 1)
2947 {
26d18378
RR
2948 if ((part->dock->dock_direction == wxAUI_DOCK_TOP) ||
2949 (part->dock->dock_direction == wxAUI_DOCK_LEFT))
2950 {
2951 DoInsertDockRow(panes, part->dock->dock_direction,
2952 part->dock->dock_layer,
2953 part->dock->dock_row+1);
2954 drop.dock_row = part->dock->dock_row+1;
2955 }
2956 else
2957 {
2958 int row = drop.dock_row;
2959 DoInsertDockRow(panes, part->dock->dock_direction,
2960 part->dock->dock_layer,
2961 part->dock->dock_row);
2962 drop.dock_row = row;
2963 }
50acee04
JS
2964 }
2965
2966 return ProcessDockResult(target, drop);
2967 }
2968
2969
2970
be66f18e 2971
50acee04
JS
2972 if (!part)
2973 return false;
2974
a3a5df9d
BW
2975 if (part->type == wxAuiDockUIPart::typePaneBorder ||
2976 part->type == wxAuiDockUIPart::typeCaption ||
2977 part->type == wxAuiDockUIPart::typeGripper ||
2978 part->type == wxAuiDockUIPart::typePaneButton ||
2979 part->type == wxAuiDockUIPart::typePane ||
2980 part->type == wxAuiDockUIPart::typePaneSizer ||
2981 part->type == wxAuiDockUIPart::typeDockSizer ||
2982 part->type == wxAuiDockUIPart::typeBackground)
50acee04 2983 {
a3a5df9d 2984 if (part->type == wxAuiDockUIPart::typeDockSizer)
50acee04
JS
2985 {
2986 if (part->dock->panes.GetCount() != 1)
2987 return false;
2988 part = GetPanePart(part->dock->panes.Item(0)->window);
2989 if (!part)
2990 return false;
2991 }
2992
2993
2994
2995 // If a normal frame is being dragged over a toolbar, insert it
2996 // along the edge under the toolbar, but over all other panes.
2997 // (this could be done much better, but somehow factoring this
2998 // calculation with the one at the beginning of this function)
2999 if (part->dock && part->dock->toolbar)
3000 {
3001 int layer = 0;
3002
3003 switch (part->dock->dock_direction)
3004 {
3005 case wxAUI_DOCK_LEFT:
3006 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_LEFT),
3007 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM)),
3008 GetMaxLayer(docks, wxAUI_DOCK_TOP));
3009 break;
3010 case wxAUI_DOCK_TOP:
3011 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_TOP),
3012 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
3013 GetMaxLayer(docks, wxAUI_DOCK_RIGHT));
3014 break;
3015 case wxAUI_DOCK_RIGHT:
3016 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_RIGHT),
3017 GetMaxLayer(docks, wxAUI_DOCK_TOP)),
3018 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM));
3019 break;
3020 case wxAUI_DOCK_BOTTOM:
3021 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_BOTTOM),
3022 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
3023 GetMaxLayer(docks, wxAUI_DOCK_RIGHT));
3024 break;
3025 }
3026
3027 DoInsertDockRow(panes, part->dock->dock_direction,
3028 layer, 0);
3029 drop.Dock().
3030 Direction(part->dock->dock_direction).
3031 Layer(layer).Row(0).Position(0);
3032 return ProcessDockResult(target, drop);
3033 }
3034
3035
3036 if (!part->pane)
3037 return false;
3038
3039 part = GetPanePart(part->pane->window);
3040 if (!part)
3041 return false;
be66f18e 3042
50acee04
JS
3043 bool insert_dock_row = false;
3044 int insert_row = part->pane->dock_row;
3045 int insert_dir = part->pane->dock_direction;
3046 int insert_layer = part->pane->dock_layer;
be66f18e 3047
50acee04
JS
3048 switch (part->pane->dock_direction)
3049 {
3050 case wxAUI_DOCK_TOP:
3051 if (pt.y >= part->rect.y &&
3052 pt.y < part->rect.y+auiInsertRowPixels)
3053 insert_dock_row = true;
3054 break;
3055 case wxAUI_DOCK_BOTTOM:
3056 if (pt.y > part->rect.y+part->rect.height-auiInsertRowPixels &&
3057 pt.y <= part->rect.y + part->rect.height)
3058 insert_dock_row = true;
3059 break;
3060 case wxAUI_DOCK_LEFT:
3061 if (pt.x >= part->rect.x &&
3062 pt.x < part->rect.x+auiInsertRowPixels)
3063 insert_dock_row = true;
3064 break;
3065 case wxAUI_DOCK_RIGHT:
3066 if (pt.x > part->rect.x+part->rect.width-auiInsertRowPixels &&
3067 pt.x <= part->rect.x+part->rect.width)
3068 insert_dock_row = true;
3069 break;
3070 case wxAUI_DOCK_CENTER:
3071 {
3072 // "new row pixels" will be set to the default, but
3073 // must never exceed 20% of the window size
3074 int new_row_pixels_x = auiNewRowPixels;
3075 int new_row_pixels_y = auiNewRowPixels;
3076
3077 if (new_row_pixels_x > (part->rect.width*20)/100)
3078 new_row_pixels_x = (part->rect.width*20)/100;
3079
3080 if (new_row_pixels_y > (part->rect.height*20)/100)
3081 new_row_pixels_y = (part->rect.height*20)/100;
3082
be66f18e 3083
50acee04
JS
3084 // determine if the mouse pointer is in a location that
3085 // will cause a new row to be inserted. The hot spot positions
3086 // are along the borders of the center pane
3087
3088 insert_layer = 0;
3089 insert_dock_row = true;
7608fd01
VZ
3090 const wxRect& pr = part->rect;
3091 if (pt.x >= pr.x && pt.x < pr.x + new_row_pixels_x)
3092 insert_dir = wxAUI_DOCK_LEFT;
3093 else if (pt.y >= pr.y && pt.y < pr.y + new_row_pixels_y)
3094 insert_dir = wxAUI_DOCK_TOP;
3095 else if (pt.x >= pr.x + pr.width - new_row_pixels_x &&
3096 pt.x < pr.x + pr.width)
3097 insert_dir = wxAUI_DOCK_RIGHT;
3098 else if (pt.y >= pr.y+ pr.height - new_row_pixels_y &&
3099 pt.y < pr.y + pr.height)
3100 insert_dir = wxAUI_DOCK_BOTTOM;
3101 else
3102 return false;
50acee04
JS
3103
3104 insert_row = GetMaxRow(panes, insert_dir, insert_layer) + 1;
3105 }
3106 }
3107
3108 if (insert_dock_row)
be66f18e 3109 {
50acee04
JS
3110 DoInsertDockRow(panes, insert_dir, insert_layer, insert_row);
3111 drop.Dock().Direction(insert_dir).
3112 Layer(insert_layer).
3113 Row(insert_row).
3114 Position(0);
3115 return ProcessDockResult(target, drop);
3116 }
be66f18e 3117
50acee04
JS
3118 // determine the mouse offset and the pane size, both in the
3119 // direction of the dock itself, and perpendicular to the dock
be66f18e 3120
50acee04 3121 int offset, size;
be66f18e 3122
50acee04
JS
3123 if (part->orientation == wxVERTICAL)
3124 {
3125 offset = pt.y - part->rect.y;
be66f18e 3126 size = part->rect.GetHeight();
50acee04 3127 }
7608fd01 3128 else
50acee04
JS
3129 {
3130 offset = pt.x - part->rect.x;
3131 size = part->rect.GetWidth();
3132 }
be66f18e 3133
50acee04 3134 int drop_position = part->pane->dock_pos;
be66f18e 3135
50acee04
JS
3136 // if we are in the top/left part of the pane,
3137 // insert the pane before the pane being hovered over
3138 if (offset <= size/2)
3139 {
3140 drop_position = part->pane->dock_pos;
3141 DoInsertPane(panes,
3142 part->pane->dock_direction,
3143 part->pane->dock_layer,
3144 part->pane->dock_row,
3145 part->pane->dock_pos);
3146 }
3147
3148 // if we are in the bottom/right part of the pane,
3149 // insert the pane before the pane being hovered over
3150 if (offset > size/2)
3151 {
3152 drop_position = part->pane->dock_pos+1;
3153 DoInsertPane(panes,
3154 part->pane->dock_direction,
3155 part->pane->dock_layer,
3156 part->pane->dock_row,
3157 part->pane->dock_pos+1);
3158 }
3159
3160 drop.Dock().
3161 Direction(part->dock->dock_direction).
3162 Layer(part->dock->dock_layer).
3163 Row(part->dock->dock_row).
3164 Position(drop_position);
3165 return ProcessDockResult(target, drop);
3166 }
3167
3168 return false;
3169}
3170
3171
a3a5df9d 3172void wxAuiManager::OnHintFadeTimer(wxTimerEvent& WXUNUSED(event))
50acee04 3173{
7a5b04a6 3174 if (!m_hint_wnd || m_hint_fadeamt >= m_hint_fademax)
50acee04
JS
3175 {
3176 m_hint_fadetimer.Stop();
3177 return;
3178 }
be66f18e 3179
7a5b04a6 3180 m_hint_fadeamt += 4;
07880314 3181 m_hint_wnd->SetTransparent(m_hint_fadeamt);
50acee04
JS
3182}
3183
a3a5df9d 3184void wxAuiManager::ShowHint(const wxRect& rect)
50acee04 3185{
cf6fec73 3186 if (m_hint_wnd)
50acee04 3187 {
cf6fec73 3188 // if the hint rect is the same as last time, don't do anything
50acee04
JS
3189 if (m_last_hint == rect)
3190 return;
3191 m_last_hint = rect;
be66f18e 3192
5826659c 3193 m_hint_fadeamt = m_hint_fademax;
7608fd01 3194
cf6fec73 3195 if ((m_flags & wxAUI_MGR_HINT_FADE)
5826659c 3196 && !((m_hint_wnd->IsKindOf(CLASSINFO(wxPseudoTransparentFrame))) &&
cf6fec73 3197 (m_flags & wxAUI_MGR_NO_VENETIAN_BLINDS_FADE))
5826659c
AB
3198 )
3199 m_hint_fadeamt = 0;
be66f18e 3200
e65fbef6 3201 m_hint_wnd->SetSize(rect);
c2291b1f 3202 m_hint_wnd->SetTransparent(m_hint_fadeamt);
b4ea182b 3203
cf6fec73 3204 if (!m_hint_wnd->IsShown())
50acee04
JS
3205 m_hint_wnd->Show();
3206
50f3c41d
RD
3207 // if we are dragging a floating pane, set the focus
3208 // back to that floating pane (otherwise it becomes unfocused)
3209 if (m_action == actionDragFloatingPane && m_action_window)
3210 m_action_window->SetFocus();
50acee04 3211
50f3c41d 3212 m_hint_wnd->Raise();
c08ee034 3213
be66f18e 3214
5826659c 3215 if (m_hint_fadeamt != m_hint_fademax) // Only fade if we need to
50acee04
JS
3216 {
3217 // start fade in timer
50acee04
JS
3218 m_hint_fadetimer.SetOwner(this, 101);
3219 m_hint_fadetimer.Start(5);
3220 }
50acee04 3221 }
7608fd01 3222 else // Not using a transparent hint window...
50acee04 3223 {
cf6fec73
BW
3224 if (!(m_flags & wxAUI_MGR_RECTANGLE_HINT))
3225 return;
7608fd01 3226
50f3c41d
RD
3227 if (m_last_hint != rect)
3228 {
3229 // remove the last hint rectangle
3230 m_last_hint = rect;
3231 m_frame->Refresh();
3232 m_frame->Update();
3233 }
50acee04 3234
50f3c41d
RD
3235 wxScreenDC screendc;
3236 wxRegion clip(1, 1, 10000, 10000);
3237
3238 // clip all floating windows, so we don't draw over them
3239 int i, pane_count;
3240 for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
50acee04 3241 {
a3a5df9d 3242 wxAuiPaneInfo& pane = m_panes.Item(i);
50f3c41d
RD
3243
3244 if (pane.IsFloating() &&
3245 pane.frame->IsShown())
3246 {
3247 wxRect rect = pane.frame->GetRect();
3248#ifdef __WXGTK__
3249 // wxGTK returns the client size, not the whole frame size
3250 rect.width += 15;
3251 rect.height += 35;
3252 rect.Inflate(5);
3253#endif
3254
3255 clip.Subtract(rect);
3256 }
50acee04 3257 }
50acee04 3258
8b001346
AB
3259 // As we can only hide the hint by redrawing the managed window, we
3260 // need to clip the region to the managed window too or we get
3261 // nasty redrawn problems.
3262 clip.Intersect(m_frame->GetRect());
3263
c1bc8d9f 3264 screendc.SetDeviceClippingRegion(clip);
50acee04 3265
50f3c41d
RD
3266 wxBitmap stipple = wxPaneCreateStippleBitmap();
3267 wxBrush brush(stipple);
3268 screendc.SetBrush(brush);
3269 screendc.SetPen(*wxTRANSPARENT_PEN);
50acee04 3270
50f3c41d
RD
3271 screendc.DrawRectangle(rect.x, rect.y, 5, rect.height);
3272 screendc.DrawRectangle(rect.x+5, rect.y, rect.width-10, 5);
3273 screendc.DrawRectangle(rect.x+rect.width-5, rect.y, 5, rect.height);
3274 screendc.DrawRectangle(rect.x+5, rect.y+rect.height-5, rect.width-10, 5);
3275 }
50acee04
JS
3276}
3277
a3a5df9d 3278void wxAuiManager::HideHint()
be66f18e 3279{
81cc4eb2 3280 // hides a transparent window hint, if there is one
50acee04
JS
3281 if (m_hint_wnd)
3282 {
26178b5d
BW
3283 if (m_hint_wnd->IsShown())
3284 m_hint_wnd->Show(false);
07880314 3285 m_hint_wnd->SetTransparent(0);
50acee04
JS
3286 m_hint_fadetimer.Stop();
3287 m_last_hint = wxRect();
3288 return;
3289 }
be66f18e 3290
50acee04
JS
3291 // hides a painted hint by redrawing the frame window
3292 if (!m_last_hint.IsEmpty())
3293 {
3294 m_frame->Refresh();
3295 m_frame->Update();
3296 m_last_hint = wxRect();
3297 }
3298}
3299
3300
3301
cf37c9a9
BW
3302void wxAuiManager::StartPaneDrag(wxWindow* pane_window,
3303 const wxPoint& offset)
3304{
3305 wxAuiPaneInfo& pane = GetPane(pane_window);
3306 if (!pane.IsOk())
3307 return;
7608fd01 3308
cf37c9a9
BW
3309 if (pane.IsToolbar())
3310 {
3311 m_action = actionDragToolbarPane;
3312 }
7608fd01 3313 else
cf37c9a9
BW
3314 {
3315 m_action = actionDragFloatingPane;
3316 }
7608fd01 3317
cf37c9a9
BW
3318 m_action_window = pane_window;
3319 m_action_offset = offset;
3320 m_frame->CaptureMouse();
3321}
3322
ce15b45f
BW
3323
3324// CalculateHintRect() calculates the drop hint rectangle. The method
3325// first calls DoDrop() to determine the exact position the pane would
3326// be at were if dropped. If the pane would indeed become docked at the
3327// specified drop point, the the rectangle hint will be returned in
3328// screen coordinates. Otherwise, an empty rectangle is returned.
3329// |pane_window| is the window pointer of the pane being dragged, |pt| is
3330// the mouse position, in client coordinates. |offset| describes the offset
3331// that the mouse is from the upper-left corner of the item being dragged
3332
3333wxRect wxAuiManager::CalculateHintRect(wxWindow* pane_window,
3334 const wxPoint& pt,
3335 const wxPoint& offset)
50acee04
JS
3336{
3337 wxRect rect;
3338
3339 // we need to paint a hint rectangle; to find out the exact hint rectangle,
3340 // we will create a new temporary layout and then measure the resulting
3341 // rectangle; we will create a copy of the docking structures (m_dock)
3342 // so that we don't modify the real thing on screen
3343
3344 int i, pane_count, part_count;
a3a5df9d
BW
3345 wxAuiDockInfoArray docks;
3346 wxAuiPaneInfoArray panes;
3347 wxAuiDockUIPartArray uiparts;
3348 wxAuiPaneInfo hint = GetPane(pane_window);
50acee04 3349 hint.name = wxT("__HINT__");
479574aa 3350 hint.PaneBorder(true);
483c90c2 3351 hint.Show();
50acee04
JS
3352
3353 if (!hint.IsOk())
ce15b45f 3354 return rect;
50acee04
JS
3355
3356 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
3357
3358 // remove any pane already there which bears the same window;
3359 // this happens when you are moving a pane around in a dock
3360 for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
3361 {
3362 if (panes.Item(i).window == pane_window)
3363 {
3364 RemovePaneFromDocks(docks, panes.Item(i));
3365 panes.RemoveAt(i);
3366 break;
3367 }
3368 }
3369
3370 // find out where the new pane would be
3371 if (!DoDrop(docks, panes, hint, pt, offset))
3372 {
ce15b45f 3373 return rect;
50acee04
JS
3374 }
3375
3376 panes.Add(hint);
3377
3378 wxSizer* sizer = LayoutAll(panes, docks, uiparts, true);
3379 wxSize client_size = m_frame->GetClientSize();
3380 sizer->SetDimension(0, 0, client_size.x, client_size.y);
3381 sizer->Layout();
3382
3383 for (i = 0, part_count = uiparts.GetCount();
3384 i < part_count; ++i)
3385 {
a3a5df9d 3386 wxAuiDockUIPart& part = uiparts.Item(i);
50acee04 3387
a3a5df9d 3388 if (part.type == wxAuiDockUIPart::typePaneBorder &&
50acee04
JS
3389 part.pane && part.pane->name == wxT("__HINT__"))
3390 {
3391 rect = wxRect(part.sizer_item->GetPosition(),
3392 part.sizer_item->GetSize());
3393 break;
3394 }
3395 }
be66f18e 3396
50acee04
JS
3397 delete sizer;
3398
3399 if (rect.IsEmpty())
3400 {
ce15b45f 3401 return rect;
50acee04
JS
3402 }
3403
3404 // actually show the hint rectangle on the screen
3405 m_frame->ClientToScreen(&rect.x, &rect.y);
ce15b45f 3406
f928b1ab
VZ
3407 if ( m_frame->GetLayoutDirection() == wxLayout_RightToLeft )
3408 {
3409 // Mirror rectangle in RTL mode
3410 rect.x -= rect.GetWidth();
3411 }
3412
ce15b45f
BW
3413 return rect;
3414}
3415
3416// DrawHintRect() calculates the hint rectangle by calling
3417// CalculateHintRect(). If there is a rectangle, it shows it
3418// by calling ShowHint(), otherwise it hides any hint
3419// rectangle currently shown
3420void wxAuiManager::DrawHintRect(wxWindow* pane_window,
3421 const wxPoint& pt,
3422 const wxPoint& offset)
3423{
3424 wxRect rect = CalculateHintRect(pane_window, pt, offset);
7608fd01 3425
ce15b45f
BW
3426 if (rect.IsEmpty())
3427 {
3428 HideHint();
3429 }
7608fd01 3430 else
ce15b45f
BW
3431 {
3432 ShowHint(rect);
3433 }
50acee04
JS
3434}
3435
a3a5df9d 3436void wxAuiManager::OnFloatingPaneMoveStart(wxWindow* wnd)
50acee04
JS
3437{
3438 // try to find the pane
a3a5df9d 3439 wxAuiPaneInfo& pane = GetPane(wnd);
50acee04 3440 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
be66f18e 3441
50acee04 3442 if (m_flags & wxAUI_MGR_TRANSPARENT_DRAG)
07880314 3443 pane.frame->SetTransparent(150);
50acee04
JS
3444}
3445
a3a5df9d 3446void wxAuiManager::OnFloatingPaneMoving(wxWindow* wnd, wxDirection dir)
50acee04
JS
3447{
3448 // try to find the pane
a3a5df9d 3449 wxAuiPaneInfo& pane = GetPane(wnd);
50acee04 3450 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
be66f18e 3451
50acee04 3452 wxPoint pt = ::wxGetMousePosition();
322c5ec4 3453
f8a13949 3454#if 0
b4ea182b 3455 // Adapt pt to direction
322c5ec4
RR
3456 if (dir == wxNORTH)
3457 {
3458 // move to pane's upper border
3459 wxPoint pos( 0,0 );
3460 pos = wnd->ClientToScreen( pos );
3461 pt.y = pos.y;
3462 // and some more pixels for the title bar
3463 pt.y -= 5;
7608fd01
VZ
3464 }
3465 else if (dir == wxWEST)
322c5ec4
RR
3466 {
3467 // move to pane's left border
3468 wxPoint pos( 0,0 );
3469 pos = wnd->ClientToScreen( pos );
3470 pt.x = pos.x;
7608fd01
VZ
3471 }
3472 else if (dir == wxEAST)
322c5ec4
RR
3473 {
3474 // move to pane's right border
3475 wxPoint pos( wnd->GetSize().x, 0 );
3476 pos = wnd->ClientToScreen( pos );
3477 pt.x = pos.x;
7608fd01
VZ
3478 }
3479 else if (dir == wxSOUTH)
322c5ec4
RR
3480 {
3481 // move to pane's bottom border
3482 wxPoint pos( 0, wnd->GetSize().y );
3483 pos = wnd->ClientToScreen( pos );
3484 pt.y = pos.y;
3485 }
93b9de86
WS
3486#else
3487 wxUnusedVar(dir);
322c5ec4
RR
3488#endif
3489
50acee04 3490 wxPoint client_pt = m_frame->ScreenToClient(pt);
be66f18e 3491
50acee04
JS
3492 // calculate the offset from the upper left-hand corner
3493 // of the frame to the mouse pointer
3494 wxPoint frame_pos = pane.frame->GetPosition();
3495 wxPoint action_offset(pt.x-frame_pos.x, pt.y-frame_pos.y);
3496
3497 // no hint for toolbar floating windows
3498 if (pane.IsToolbar() && m_action == actionDragFloatingPane)
3499 {
cedd7b22
PC
3500 wxAuiDockInfoArray docks;
3501 wxAuiPaneInfoArray panes;
3502 wxAuiDockUIPartArray uiparts;
3503 wxAuiPaneInfo hint = pane;
be66f18e 3504
cedd7b22 3505 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
50acee04 3506
cedd7b22
PC
3507 // find out where the new pane would be
3508 if (!DoDrop(docks, panes, hint, client_pt))
3509 return;
3510 if (hint.IsFloating())
3511 return;
be66f18e 3512
cedd7b22
PC
3513 pane = hint;
3514 m_action = actionDragToolbarPane;
3515 m_action_window = pane.window;
be66f18e 3516
cedd7b22 3517 Update();
be66f18e 3518
50acee04
JS
3519 return;
3520 }
3521
3522
3523 // if a key modifier is pressed while dragging the frame,
3524 // don't dock the window
858a3a7a 3525 if (!CanDockPanel(pane))
50acee04
JS
3526 {
3527 HideHint();
3528 return;
3529 }
3530
3531
3532 DrawHintRect(wnd, client_pt, action_offset);
3533
be66f18e 3534#ifdef __WXGTK__
50acee04
JS
3535 // this cleans up some screen artifacts that are caused on GTK because
3536 // we aren't getting the exact size of the window (see comment
3537 // in DrawHintRect)
3538 //Refresh();
be66f18e
WS
3539#endif
3540
3541
50acee04
JS
3542 // reduces flicker
3543 m_frame->Update();
3544}
3545
a3a5df9d 3546void wxAuiManager::OnFloatingPaneMoved(wxWindow* wnd, wxDirection dir)
50acee04
JS
3547{
3548 // try to find the pane
a3a5df9d 3549 wxAuiPaneInfo& pane = GetPane(wnd);
50acee04 3550 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
be66f18e 3551
50acee04 3552 wxPoint pt = ::wxGetMousePosition();
322c5ec4 3553
f8a13949 3554#if 0
b4ea182b 3555 // Adapt pt to direction
322c5ec4
RR
3556 if (dir == wxNORTH)
3557 {
3558 // move to pane's upper border
3559 wxPoint pos( 0,0 );
3560 pos = wnd->ClientToScreen( pos );
3561 pt.y = pos.y;
3562 // and some more pixels for the title bar
3563 pt.y -= 10;
7608fd01
VZ
3564 }
3565 else if (dir == wxWEST)
322c5ec4
RR
3566 {
3567 // move to pane's left border
3568 wxPoint pos( 0,0 );
3569 pos = wnd->ClientToScreen( pos );
3570 pt.x = pos.x;
7608fd01
VZ
3571 }
3572 else if (dir == wxEAST)
322c5ec4
RR
3573 {
3574 // move to pane's right border
3575 wxPoint pos( wnd->GetSize().x, 0 );
3576 pos = wnd->ClientToScreen( pos );
3577 pt.x = pos.x;
7608fd01
VZ
3578 }
3579 else if (dir == wxSOUTH)
322c5ec4
RR
3580 {
3581 // move to pane's bottom border
3582 wxPoint pos( 0, wnd->GetSize().y );
3583 pos = wnd->ClientToScreen( pos );
3584 pt.y = pos.y;
3585 }
93b9de86
WS
3586#else
3587 wxUnusedVar(dir);
322c5ec4
RR
3588#endif
3589
50acee04 3590 wxPoint client_pt = m_frame->ScreenToClient(pt);
be66f18e 3591
50acee04
JS
3592 // calculate the offset from the upper left-hand corner
3593 // of the frame to the mouse pointer
3594 wxPoint frame_pos = pane.frame->GetPosition();
3595 wxPoint action_offset(pt.x-frame_pos.x, pt.y-frame_pos.y);
be66f18e 3596
50acee04
JS
3597 // if a key modifier is pressed while dragging the frame,
3598 // don't dock the window
858a3a7a 3599 if (CanDockPanel(pane))
50acee04 3600 {
50f3c41d
RD
3601 // do the drop calculation
3602 DoDrop(m_docks, m_panes, pane, client_pt, action_offset);
50acee04 3603 }
c08ee034 3604
50acee04
JS
3605 // if the pane is still floating, update it's floating
3606 // position (that we store)
3607 if (pane.IsFloating())
3608 {
3609 pane.floating_pos = pane.frame->GetPosition();
be66f18e 3610
50acee04 3611 if (m_flags & wxAUI_MGR_TRANSPARENT_DRAG)
07880314 3612 pane.frame->SetTransparent(255);
7453065a 3613 }
7608fd01 3614 else if (m_has_maximized)
7453065a 3615 {
37106ab2 3616 RestoreMaximizedPane();
50acee04 3617 }
be66f18e 3618
50acee04 3619 Update();
be66f18e 3620
50acee04
JS
3621 HideHint();
3622}
3623
a3a5df9d 3624void wxAuiManager::OnFloatingPaneResized(wxWindow* wnd, const wxSize& size)
50acee04
JS
3625{
3626 // try to find the pane
a3a5df9d 3627 wxAuiPaneInfo& pane = GetPane(wnd);
50acee04 3628 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
be66f18e 3629
50acee04
JS
3630 pane.floating_size = size;
3631}
3632
58754643 3633
a3a5df9d 3634void wxAuiManager::OnFloatingPaneClosed(wxWindow* wnd, wxCloseEvent& evt)
50acee04
JS
3635{
3636 // try to find the pane
a3a5df9d 3637 wxAuiPaneInfo& pane = GetPane(wnd);
50acee04
JS
3638 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3639
58754643
BW
3640
3641 // fire pane close event
bc07ab17 3642 wxAuiManagerEvent e(wxEVT_AUI_PANE_CLOSE);
58754643
BW
3643 e.SetPane(&pane);
3644 e.SetCanVeto(evt.CanVeto());
3645 ProcessMgrEvent(e);
a1b3b608 3646
58754643
BW
3647 if (e.GetVeto())
3648 {
3649 evt.Veto();
3650 return;
3651 }
7608fd01 3652 else
58754643 3653 {
7da1b21e
BW
3654 // close the pane, but check that it
3655 // still exists in our pane array first
3656 // (the event handler above might have removed it)
3657
3658 wxAuiPaneInfo& check = GetPane(wnd);
3659 if (check.IsOk())
3660 {
3661 ClosePane(pane);
3662 }
58754643 3663 }
50acee04
JS
3664}
3665
58754643
BW
3666
3667
a3a5df9d 3668void wxAuiManager::OnFloatingPaneActivated(wxWindow* wnd)
50acee04 3669{
4d83610e 3670 if ((GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE) && GetPane(wnd).IsOk())
50acee04 3671 {
50acee04
JS
3672 SetActivePane(m_panes, wnd);
3673 Repaint();
3674 }
3675}
3676
673727f3 3677// OnRender() draws all of the pane captions, sashes,
50acee04
JS
3678// backgrounds, captions, grippers, pane borders and buttons.
3679// It renders the entire user interface.
3680
a3a5df9d 3681void wxAuiManager::OnRender(wxAuiManagerEvent& evt)
50acee04 3682{
befda040
RR
3683 // if the frame is about to be deleted, don't bother
3684 if (!m_frame || wxPendingDelete.Member(m_frame))
cedd7b22
PC
3685 return;
3686
673727f3 3687 wxDC* dc = evt.GetDC();
c08ee034 3688
50acee04
JS
3689#ifdef __WXMAC__
3690 dc->Clear() ;
3691#endif
3692 int i, part_count;
3693 for (i = 0, part_count = m_uiparts.GetCount();
3694 i < part_count; ++i)
3695 {
a3a5df9d 3696 wxAuiDockUIPart& part = m_uiparts.Item(i);
50acee04 3697
4d83610e
JS
3698 // don't draw hidden pane items or items that aren't windows
3699 if (part.sizer_item && ((!part.sizer_item->IsWindow() && !part.sizer_item->IsSpacer() && !part.sizer_item->IsSizer()) || !part.sizer_item->IsShown()))
50acee04 3700 continue;
be66f18e 3701
50acee04
JS
3702 switch (part.type)
3703 {
a3a5df9d
BW
3704 case wxAuiDockUIPart::typeDockSizer:
3705 case wxAuiDockUIPart::typePaneSizer:
32205ebb 3706 m_art->DrawSash(*dc, m_frame, part.orientation, part.rect);
50acee04 3707 break;
a3a5df9d 3708 case wxAuiDockUIPart::typeBackground:
32205ebb 3709 m_art->DrawBackground(*dc, m_frame, part.orientation, part.rect);
50acee04 3710 break;
a3a5df9d 3711 case wxAuiDockUIPart::typeCaption:
32205ebb 3712 m_art->DrawCaption(*dc, m_frame, part.pane->caption, part.rect, *part.pane);
50acee04 3713 break;
a3a5df9d 3714 case wxAuiDockUIPart::typeGripper:
32205ebb 3715 m_art->DrawGripper(*dc, m_frame, part.rect, *part.pane);
be66f18e 3716 break;
a3a5df9d 3717 case wxAuiDockUIPart::typePaneBorder:
32205ebb 3718 m_art->DrawBorder(*dc, m_frame, part.rect, *part.pane);
50acee04 3719 break;
a3a5df9d 3720 case wxAuiDockUIPart::typePaneButton:
32205ebb 3721 m_art->DrawPaneButton(*dc, m_frame, part.button->button_id,
50acee04
JS
3722 wxAUI_BUTTON_STATE_NORMAL, part.rect, *part.pane);
3723 break;
3724 }
3725 }
3726}
3727
673727f3
BW
3728
3729// Render() fire a render event, which is normally handled by
a3a5df9d 3730// wxAuiManager::OnRender(). This allows the render function to
673727f3
BW
3731// be overridden via the render event. This can be useful for paintin
3732// custom graphics in the main window. Default behavior can be
3733// invoked in the overridden function by calling OnRender()
3734
a3a5df9d 3735void wxAuiManager::Render(wxDC* dc)
673727f3 3736{
a3a5df9d 3737 wxAuiManagerEvent e(wxEVT_AUI_RENDER);
bc9e3321 3738 e.SetManager(this);
673727f3
BW
3739 e.SetDC(dc);
3740 ProcessMgrEvent(e);
3741}
3742
a3a5df9d 3743void wxAuiManager::Repaint(wxDC* dc)
50acee04
JS
3744{
3745#ifdef __WXMAC__
3746 if ( dc == NULL )
3747 {
3748 m_frame->Refresh() ;
3749 m_frame->Update() ;
3750 return ;
3751 }
3752#endif
3753 int w, h;
3754 m_frame->GetClientSize(&w, &h);
3755
3756 // figure out which dc to use; if one
3757 // has been specified, use it, otherwise
3758 // make a client dc
3759 wxClientDC* client_dc = NULL;
3760 if (!dc)
3761 {
3762 client_dc = new wxClientDC(m_frame);
3763 dc = client_dc;
3764 }
3765
3766 // if the frame has a toolbar, the client area
3767 // origin will not be (0,0).
3768 wxPoint pt = m_frame->GetClientAreaOrigin();
3769 if (pt.x != 0 || pt.y != 0)
3770 dc->SetDeviceOrigin(pt.x, pt.y);
3771
3772 // render all the items
3773 Render(dc);
3774
3775 // if we created a client_dc, delete it
3776 if (client_dc)
3777 delete client_dc;
3778}
3779
a3a5df9d 3780void wxAuiManager::OnPaint(wxPaintEvent& WXUNUSED(event))
50acee04
JS
3781{
3782 wxPaintDC dc(m_frame);
3783 Repaint(&dc);
3784}
3785
a3a5df9d 3786void wxAuiManager::OnEraseBackground(wxEraseEvent& event)
50acee04
JS
3787{
3788#ifdef __WXMAC__
3789 event.Skip() ;
3790#else
3791 wxUnusedVar(event);
3792#endif
3793}
3794
a3a5df9d 3795void wxAuiManager::OnSize(wxSizeEvent& event)
50acee04
JS
3796{
3797 if (m_frame)
3798 {
3799 DoFrameLayout();
3800 Repaint();
7608fd01 3801
473016d6
BW
3802#if wxUSE_MDI
3803 if (m_frame->IsKindOf(CLASSINFO(wxMDIParentFrame)))
3804 {
3805 // for MDI parent frames, this event must not
3806 // be "skipped". In other words, the parent frame
3807 // must not be allowed to resize the client window
3808 // after we are finished processing sizing changes
3809 return;
3810 }
3811#endif
50acee04 3812 }
8d361e83 3813 event.Skip();
50acee04
JS
3814}
3815
4dc79cfb
BW
3816void wxAuiManager::OnFindManager(wxAuiManagerEvent& evt)
3817{
3818 // get the window we are managing, if none, return NULL
3819 wxWindow* window = GetManagedWindow();
3820 if (!window)
3821 {
3822 evt.SetManager(NULL);
3823 return;
3824 }
7608fd01 3825
4dc79cfb
BW
3826 // if we are managing a child frame, get the 'real' manager
3827 if (window->IsKindOf(CLASSINFO(wxAuiFloatingFrame)))
3828 {
3829 wxAuiFloatingFrame* float_frame = static_cast<wxAuiFloatingFrame*>(window);
3830 evt.SetManager(float_frame->GetOwnerManager());
3831 return;
3832 }
7608fd01 3833
4dc79cfb
BW
3834 // return pointer to ourself
3835 evt.SetManager(this);
3836}
50acee04 3837
a3a5df9d 3838void wxAuiManager::OnSetCursor(wxSetCursorEvent& event)
50acee04
JS
3839{
3840 // determine cursor
a3a5df9d 3841 wxAuiDockUIPart* part = HitTest(event.GetX(), event.GetY());
50acee04
JS
3842 wxCursor cursor = wxNullCursor;
3843
3844 if (part)
3845 {
a3a5df9d
BW
3846 if (part->type == wxAuiDockUIPart::typeDockSizer ||
3847 part->type == wxAuiDockUIPart::typePaneSizer)
50acee04
JS
3848 {
3849 // a dock may not be resized if it has a single
3850 // pane which is not resizable
a3a5df9d 3851 if (part->type == wxAuiDockUIPart::typeDockSizer && part->dock &&
50acee04
JS
3852 part->dock->panes.GetCount() == 1 &&
3853 part->dock->panes.Item(0)->IsFixed())
3854 return;
3855
3856 // panes that may not be resized do not get a sizing cursor
3857 if (part->pane && part->pane->IsFixed())
3858 return;
3859
3860 if (part->orientation == wxVERTICAL)
3861 cursor = wxCursor(wxCURSOR_SIZEWE);
7608fd01 3862 else
50acee04
JS
3863 cursor = wxCursor(wxCURSOR_SIZENS);
3864 }
7608fd01 3865 else if (part->type == wxAuiDockUIPart::typeGripper)
50acee04
JS
3866 {
3867 cursor = wxCursor(wxCURSOR_SIZING);
3868 }
3869 }
be66f18e 3870
50acee04
JS
3871 event.SetCursor(cursor);
3872}
3873
3874
3875
a3a5df9d 3876void wxAuiManager::UpdateButtonOnScreen(wxAuiDockUIPart* button_ui_part,
28169517 3877 const wxMouseEvent& event)
50acee04 3878{
a3a5df9d 3879 wxAuiDockUIPart* hit_test = HitTest(event.GetX(), event.GetY());
a93d5af8 3880 if (!hit_test || !button_ui_part)
28169517 3881 return;
7608fd01 3882
50acee04 3883 int state = wxAUI_BUTTON_STATE_NORMAL;
be66f18e 3884
50acee04
JS
3885 if (hit_test == button_ui_part)
3886 {
3887 if (event.LeftDown())
3888 state = wxAUI_BUTTON_STATE_PRESSED;
7608fd01 3889 else
50acee04
JS
3890 state = wxAUI_BUTTON_STATE_HOVER;
3891 }
7608fd01 3892 else
50acee04
JS
3893 {
3894 if (event.LeftDown())
3895 state = wxAUI_BUTTON_STATE_HOVER;
3896 }
3897
3898 // now repaint the button with hover state
3899 wxClientDC cdc(m_frame);
3900
3901 // if the frame has a toolbar, the client area
3902 // origin will not be (0,0).
3903 wxPoint pt = m_frame->GetClientAreaOrigin();
3904 if (pt.x != 0 || pt.y != 0)
3905 cdc.SetDeviceOrigin(pt.x, pt.y);
3906
37106ab2
BW
3907 if (hit_test->pane)
3908 {
3909 m_art->DrawPaneButton(cdc, m_frame,
3910 button_ui_part->button->button_id,
3911 state,
3912 button_ui_part->rect,
3913 *hit_test->pane);
3914 }
50acee04
JS
3915}
3916
a3a5df9d 3917void wxAuiManager::OnLeftDown(wxMouseEvent& event)
50acee04 3918{
a3a5df9d 3919 wxAuiDockUIPart* part = HitTest(event.GetX(), event.GetY());
50acee04
JS
3920 if (part)
3921 {
a3a5df9d
BW
3922 if (part->type == wxAuiDockUIPart::typeDockSizer ||
3923 part->type == wxAuiDockUIPart::typePaneSizer)
50acee04 3924 {
f5dc1b7e
JS
3925 // Removing this restriction so that a centre pane can be resized
3926 //if (part->dock && part->dock->dock_direction == wxAUI_DOCK_CENTER)
3927 // return;
7608fd01 3928
50acee04
JS
3929 // a dock may not be resized if it has a single
3930 // pane which is not resizable
a3a5df9d 3931 if (part->type == wxAuiDockUIPart::typeDockSizer && part->dock &&
50acee04
JS
3932 part->dock->panes.GetCount() == 1 &&
3933 part->dock->panes.Item(0)->IsFixed())
3934 return;
3935
3936 // panes that may not be resized should be ignored here
3937 if (part->pane && part->pane->IsFixed())
3938 return;
3939
3940 m_action = actionResize;
3941 m_action_part = part;
3942 m_action_hintrect = wxRect();
3943 m_action_start = wxPoint(event.m_x, event.m_y);
3944 m_action_offset = wxPoint(event.m_x - part->rect.x,
3945 event.m_y - part->rect.y);
3946 m_frame->CaptureMouse();
3947 }
7608fd01 3948 else if (part->type == wxAuiDockUIPart::typePaneButton)
50acee04
JS
3949 {
3950 m_action = actionClickButton;
3951 m_action_part = part;
3952 m_action_start = wxPoint(event.m_x, event.m_y);
3953 m_frame->CaptureMouse();
3954
3955 UpdateButtonOnScreen(part, event);
3956 }
7608fd01 3957 else if (part->type == wxAuiDockUIPart::typeCaption ||
a3a5df9d 3958 part->type == wxAuiDockUIPart::typeGripper)
50acee04 3959 {
79bcf6f4
RD
3960 // if we are managing a wxAuiFloatingFrame window, then
3961 // we are an embedded wxAuiManager inside the wxAuiFloatingFrame.
3962 // We want to initiate a toolbar drag in our owner manager
3963 wxWindow* managed_wnd = GetManagedWindow();
7608fd01
VZ
3964
3965 if (part->pane &&
79bcf6f4
RD
3966 part->pane->window &&
3967 managed_wnd &&
3968 managed_wnd->IsKindOf(CLASSINFO(wxAuiFloatingFrame)))
3969 {
3970 wxAuiFloatingFrame* floating_frame = (wxAuiFloatingFrame*)managed_wnd;
3971 wxAuiManager* owner_mgr = floating_frame->GetOwnerManager();
3972 owner_mgr->StartPaneDrag(part->pane->window,
3973 wxPoint(event.m_x - part->rect.x,
3974 event.m_y - part->rect.y));
3975 return;
3976 }
7608fd01
VZ
3977
3978
3979
50acee04
JS
3980 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
3981 {
3982 // set the caption as active
3983 SetActivePane(m_panes, part->pane->window);
3984 Repaint();
3985 }
a4c721ee
JS
3986
3987 if (part->dock && part->dock->dock_direction == wxAUI_DOCK_CENTER)
3988 return;
50acee04
JS
3989
3990 m_action = actionClickCaption;
3991 m_action_part = part;
3992 m_action_start = wxPoint(event.m_x, event.m_y);
3993 m_action_offset = wxPoint(event.m_x - part->rect.x,
3994 event.m_y - part->rect.y);
3995 m_frame->CaptureMouse();
3996 }
3997#ifdef __WXMAC__
3998 else
3999 {
4000 event.Skip();
4001 }
4002#endif
4003 }
4004#ifdef __WXMAC__
4005 else
4006 {
4007 event.Skip();
4008 }
4009#else
4010 event.Skip();
4011#endif
4012}
4013
4014
a3a5df9d 4015void wxAuiManager::OnLeftUp(wxMouseEvent& event)
50acee04
JS
4016{
4017 if (m_action == actionResize)
4018 {
4019 m_frame->ReleaseMouse();
4020
4021 // get rid of the hint rectangle
4022 wxScreenDC dc;
4023 DrawResizeHint(dc, m_action_hintrect);
4024
4025 // resize the dock or the pane
a3a5df9d 4026 if (m_action_part && m_action_part->type==wxAuiDockUIPart::typeDockSizer)
50acee04
JS
4027 {
4028 wxRect& rect = m_action_part->dock->rect;
4029
4030 wxPoint new_pos(event.m_x - m_action_offset.x,
4031 event.m_y - m_action_offset.y);
4032
4033 switch (m_action_part->dock->dock_direction)
4034 {
4035 case wxAUI_DOCK_LEFT:
4036 m_action_part->dock->size = new_pos.x - rect.x;
4037 break;
4038 case wxAUI_DOCK_TOP:
4039 m_action_part->dock->size = new_pos.y - rect.y;
4040 break;
4041 case wxAUI_DOCK_RIGHT:
4042 m_action_part->dock->size = rect.x + rect.width -
4043 new_pos.x - m_action_part->rect.GetWidth();
4044 break;
4045 case wxAUI_DOCK_BOTTOM:
4046 m_action_part->dock->size = rect.y + rect.height -
4047 new_pos.y - m_action_part->rect.GetHeight();
4048 break;
4049 }
4050
4051 Update();
4052 Repaint(NULL);
4053 }
7608fd01
VZ
4054 else if (m_action_part &&
4055 m_action_part->type == wxAuiDockUIPart::typePaneSizer)
50acee04 4056 {
a3a5df9d
BW
4057 wxAuiDockInfo& dock = *m_action_part->dock;
4058 wxAuiPaneInfo& pane = *m_action_part->pane;
50acee04
JS
4059
4060 int total_proportion = 0;
4061 int dock_pixels = 0;
4062 int new_pixsize = 0;
4063
254a3429
BW
4064 int caption_size = m_art->GetMetric(wxAUI_DOCKART_CAPTION_SIZE);
4065 int pane_border_size = m_art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE);
4066 int sash_size = m_art->GetMetric(wxAUI_DOCKART_SASH_SIZE);
50acee04
JS
4067
4068 wxPoint new_pos(event.m_x - m_action_offset.x,
4069 event.m_y - m_action_offset.y);
4070
4071 // determine the pane rectangle by getting the pane part
a3a5df9d 4072 wxAuiDockUIPart* pane_part = GetPanePart(pane.window);
50acee04
JS
4073 wxASSERT_MSG(pane_part,
4074 wxT("Pane border part not found -- shouldn't happen"));
4075
4076 // determine the new pixel size that the user wants;
4077 // this will help us recalculate the pane's proportion
4078 if (dock.IsHorizontal())
4079 new_pixsize = new_pos.x - pane_part->rect.x;
7608fd01 4080 else
50acee04
JS
4081 new_pixsize = new_pos.y - pane_part->rect.y;
4082
4083 // determine the size of the dock, based on orientation
4084 if (dock.IsHorizontal())
4085 dock_pixels = dock.rect.GetWidth();
7608fd01 4086 else
50acee04
JS
4087 dock_pixels = dock.rect.GetHeight();
4088
4089 // determine the total proportion of all resizable panes,
4090 // and the total size of the dock minus the size of all
4091 // the fixed panes
4092 int i, dock_pane_count = dock.panes.GetCount();
4093 int pane_position = -1;
4094 for (i = 0; i < dock_pane_count; ++i)
4095 {
a3a5df9d 4096 wxAuiPaneInfo& p = *dock.panes.Item(i);
50acee04
JS
4097 if (p.window == pane.window)
4098 pane_position = i;
be66f18e 4099
50acee04
JS
4100 // while we're at it, subtract the pane sash
4101 // width from the dock width, because this would
4102 // skew our proportion calculations
4103 if (i > 0)
4104 dock_pixels -= sash_size;
be66f18e 4105
50acee04
JS
4106 // also, the whole size (including decorations) of
4107 // all fixed panes must also be subtracted, because they
4108 // are not part of the proportion calculation
4109 if (p.IsFixed())
4110 {
4111 if (dock.IsHorizontal())
4112 dock_pixels -= p.best_size.x;
7608fd01 4113 else
50acee04
JS
4114 dock_pixels -= p.best_size.y;
4115 }
7608fd01 4116 else
50acee04
JS
4117 {
4118 total_proportion += p.dock_proportion;
4119 }
4120 }
be66f18e 4121
50acee04
JS
4122 // find a pane in our dock to 'steal' space from or to 'give'
4123 // space to -- this is essentially what is done when a pane is
4124 // resized; the pane should usually be the first non-fixed pane
4125 // to the right of the action pane
4126 int borrow_pane = -1;
4127 for (i = pane_position+1; i < dock_pane_count; ++i)
4128 {
a3a5df9d 4129 wxAuiPaneInfo& p = *dock.panes.Item(i);
50acee04
JS
4130 if (!p.IsFixed())
4131 {
4132 borrow_pane = i;
4133 break;
4134 }
4135 }
be66f18e
WS
4136
4137
50acee04
JS
4138 // demand that the pane being resized is found in this dock
4139 // (this assert really never should be raised)
4140 wxASSERT_MSG(pane_position != -1, wxT("Pane not found in dock"));
be66f18e 4141
50acee04
JS
4142 // prevent division by zero
4143 if (dock_pixels == 0 || total_proportion == 0 || borrow_pane == -1)
4144 {
4145 m_action = actionNone;
4146 return;
4147 }
4148
4149 // calculate the new proportion of the pane
4150 int new_proportion = (new_pixsize*total_proportion)/dock_pixels;
be66f18e 4151
50acee04
JS
4152 // default minimum size
4153 int min_size = 0;
be66f18e 4154
50acee04
JS
4155 // check against the pane's minimum size, if specified. please note
4156 // that this is not enough to ensure that the minimum size will
4157 // not be violated, because the whole frame might later be shrunk,
4158 // causing the size of the pane to violate it's minimum size
4159 if (pane.min_size.IsFullySpecified())
4160 {
4161 min_size = 0;
be66f18e 4162
50acee04
JS
4163 if (pane.HasBorder())
4164 min_size += (pane_border_size*2);
4165
4166 // calculate minimum size with decorations (border,caption)
4167 if (pane_part->orientation == wxVERTICAL)
4168 {
4169 min_size += pane.min_size.y;
4170 if (pane.HasCaption())
4171 min_size += caption_size;
4172 }
7608fd01 4173 else
50acee04
JS
4174 {
4175 min_size += pane.min_size.x;
4176 }
4177 }
be66f18e
WS
4178
4179
50acee04
JS
4180 // for some reason, an arithmatic error somewhere is causing
4181 // the proportion calculations to always be off by 1 pixel;
4182 // for now we will add the 1 pixel on, but we really should
4183 // determine what's causing this.
4184 min_size++;
4185
4186 int min_proportion = (min_size*total_proportion)/dock_pixels;
be66f18e 4187
50acee04
JS
4188 if (new_proportion < min_proportion)
4189 new_proportion = min_proportion;
be66f18e
WS
4190
4191
4192
50acee04
JS
4193 int prop_diff = new_proportion - pane.dock_proportion;
4194
4195 // borrow the space from our neighbor pane to the
4196 // right or bottom (depending on orientation)
4197 dock.panes.Item(borrow_pane)->dock_proportion -= prop_diff;
4198 pane.dock_proportion = new_proportion;
be66f18e 4199
50acee04
JS
4200 // repaint
4201 Update();
4202 Repaint(NULL);
4203 }
4204 }
696978ee 4205 else if (m_action == actionClickButton)
50acee04
JS
4206 {
4207 m_hover_button = NULL;
be66f18e 4208 m_frame->ReleaseMouse();
d1939071
BW
4209
4210 if (m_action_part)
be66f18e 4211 {
d1939071
BW
4212 UpdateButtonOnScreen(m_action_part, event);
4213
4214 // make sure we're still over the item that was originally clicked
4215 if (m_action_part == HitTest(event.GetX(), event.GetY()))
4216 {
4217 // fire button-click event
4218 wxAuiManagerEvent e(wxEVT_AUI_PANE_BUTTON);
4219 e.SetManager(this);
4220 e.SetPane(m_action_part->pane);
4221 e.SetButton(m_action_part->button->button_id);
4222 ProcessMgrEvent(e);
4223 }
50acee04
JS
4224 }
4225 }
696978ee 4226 else if (m_action == actionClickCaption)
50acee04
JS
4227 {
4228 m_frame->ReleaseMouse();
4229 }
696978ee 4230 else if (m_action == actionDragFloatingPane)
50acee04
JS
4231 {
4232 m_frame->ReleaseMouse();
4233 }
696978ee 4234 else if (m_action == actionDragToolbarPane)
50acee04
JS
4235 {
4236 m_frame->ReleaseMouse();
4237
a3a5df9d 4238 wxAuiPaneInfo& pane = GetPane(m_action_window);
50acee04 4239 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
be66f18e 4240
50acee04 4241 // save the new positions
a3a5df9d 4242 wxAuiDockInfoPtrArray docks;
50acee04
JS
4243 FindDocks(m_docks, pane.dock_direction,
4244 pane.dock_layer, pane.dock_row, docks);
4245 if (docks.GetCount() == 1)
4246 {
a3a5df9d 4247 wxAuiDockInfo& dock = *docks.Item(0);
be66f18e 4248
50acee04
JS
4249 wxArrayInt pane_positions, pane_sizes;
4250 GetPanePositionsAndSizes(dock, pane_positions, pane_sizes);
be66f18e 4251
50acee04
JS
4252 int i, dock_pane_count = dock.panes.GetCount();
4253 for (i = 0; i < dock_pane_count; ++i)
4254 dock.panes.Item(i)->dock_pos = pane_positions[i];
4255 }
be66f18e 4256
a3a5df9d 4257 pane.state &= ~wxAuiPaneInfo::actionPane;
50acee04
JS
4258 Update();
4259 }
696978ee 4260 else
50acee04
JS
4261 {
4262 event.Skip();
4263 }
4264
4265 m_action = actionNone;
4266 m_last_mouse_move = wxPoint(); // see comment in OnMotion()
4267}
4268
4269
a3a5df9d 4270void wxAuiManager::OnMotion(wxMouseEvent& event)
50acee04
JS
4271{
4272 // sometimes when Update() is called from inside this method,
4273 // a spurious mouse move event is generated; this check will make
4274 // sure that only real mouse moves will get anywhere in this method;
4275 // this appears to be a bug somewhere, and I don't know where the
4276 // mouse move event is being generated. only verified on MSW
be66f18e 4277
50acee04
JS
4278 wxPoint mouse_pos = event.GetPosition();
4279 if (m_last_mouse_move == mouse_pos)
4280 return;
4281 m_last_mouse_move = mouse_pos;
4282
be66f18e 4283
50acee04
JS
4284 if (m_action == actionResize)
4285 {
d1939071
BW
4286 if (m_action_part)
4287 {
4288 wxPoint pos = m_action_part->rect.GetPosition();
4289 if (m_action_part->orientation == wxHORIZONTAL)
4290 pos.y = wxMax(0, event.m_y - m_action_offset.y);
4291 else
4292 pos.x = wxMax(0, event.m_x - m_action_offset.x);
50acee04 4293
d1939071
BW
4294 wxRect rect(m_frame->ClientToScreen(pos),
4295 m_action_part->rect.GetSize());
50acee04 4296
d1939071
BW
4297 wxScreenDC dc;
4298 if (!m_action_hintrect.IsEmpty())
4299 DrawResizeHint(dc, m_action_hintrect);
4300 DrawResizeHint(dc, rect);
4301 m_action_hintrect = rect;
4302 }
50acee04 4303 }
696978ee 4304 else if (m_action == actionClickCaption)
50acee04
JS
4305 {
4306 int drag_x_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_X);
4307 int drag_y_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_Y);
be66f18e 4308
50acee04
JS
4309 // caption has been clicked. we need to check if the mouse
4310 // is now being dragged. if it is, we need to change the
4311 // mouse action to 'drag'
d1939071
BW
4312 if (m_action_part &&
4313 (abs(event.m_x - m_action_start.x) > drag_x_threshold ||
4314 abs(event.m_y - m_action_start.y) > drag_y_threshold))
50acee04 4315 {
a3a5df9d 4316 wxAuiPaneInfo* pane_info = m_action_part->pane;
50acee04
JS
4317
4318 if (!pane_info->IsToolbar())
4319 {
4320 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
be66f18e 4321 pane_info->IsFloatable())
50acee04
JS
4322 {
4323 m_action = actionDragFloatingPane;
4324
4325 // set initial float position
4326 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
4327 pane_info->floating_pos = wxPoint(pt.x - m_action_offset.x,
4328 pt.y - m_action_offset.y);
49fa1dbb 4329
50acee04 4330 // float the window
cf37c9a9 4331 if (pane_info->IsMaximized())
37106ab2 4332 RestorePane(*pane_info);
50acee04
JS
4333 pane_info->Float();
4334 Update();
4335
4336 m_action_window = pane_info->frame;
be66f18e 4337
50acee04
JS
4338 // action offset is used here to make it feel "natural" to the user
4339 // to drag a docked pane and suddenly have it become a floating frame.
4340 // Sometimes, however, the offset where the user clicked on the docked
4341 // caption is bigger than the width of the floating frame itself, so
4342 // in that case we need to set the action offset to a sensible value
4343 wxSize frame_size = m_action_window->GetSize();
4344 if (frame_size.x <= m_action_offset.x)
4345 m_action_offset.x = 30;
4346 }
4347 }
7608fd01 4348 else
50acee04
JS
4349 {
4350 m_action = actionDragToolbarPane;
4351 m_action_window = pane_info->window;
4352 }
4353 }
4354 }
696978ee 4355 else if (m_action == actionDragFloatingPane)
50acee04 4356 {
32e4b03c
BW
4357 if (m_action_window)
4358 {
49fa1dbb
RR
4359 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
4360 m_action_window->Move(pt.x - m_action_offset.x,
4361 pt.y - m_action_offset.y);
4362 }
50acee04 4363 }
696978ee 4364 else if (m_action == actionDragToolbarPane)
50acee04 4365 {
a3a5df9d 4366 wxAuiPaneInfo& pane = GetPane(m_action_window);
50acee04
JS
4367 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
4368
a3a5df9d 4369 pane.state |= wxAuiPaneInfo::actionPane;
50acee04
JS
4370
4371 wxPoint pt = event.GetPosition();
4372 DoDrop(m_docks, m_panes, pane, pt, m_action_offset);
be66f18e 4373
50acee04
JS
4374 // if DoDrop() decided to float the pane, set up
4375 // the floating pane's initial position
4376 if (pane.IsFloating())
4377 {
4378 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
4379 pane.floating_pos = wxPoint(pt.x - m_action_offset.x,
4380 pt.y - m_action_offset.y);
4381 }
be66f18e 4382
50acee04
JS
4383 // this will do the actiual move operation;
4384 // in the case that the pane has been floated,
4385 // this call will create the floating pane
4386 // and do the reparenting
4387 Update();
be66f18e 4388
50acee04
JS
4389 // if the pane has been floated, change the mouse
4390 // action actionDragFloatingPane so that subsequent
4391 // EVT_MOTION() events will move the floating pane
4392 if (pane.IsFloating())
4393 {
a3a5df9d 4394 pane.state &= ~wxAuiPaneInfo::actionPane;
50acee04
JS
4395 m_action = actionDragFloatingPane;
4396 m_action_window = pane.frame;
4397 }
be66f18e
WS
4398 }
4399 else
50acee04 4400 {
a3a5df9d
BW
4401 wxAuiDockUIPart* part = HitTest(event.GetX(), event.GetY());
4402 if (part && part->type == wxAuiDockUIPart::typePaneButton)
50acee04
JS
4403 {
4404 if (part != m_hover_button)
4405 {
4406 // make the old button normal
4407 if (m_hover_button)
37106ab2 4408 {
50acee04 4409 UpdateButtonOnScreen(m_hover_button, event);
37106ab2
BW
4410 Repaint();
4411 }
7608fd01 4412
50acee04
JS
4413 // mouse is over a button, so repaint the
4414 // button in hover mode
4415 UpdateButtonOnScreen(part, event);
4416 m_hover_button = part;
7608fd01 4417
50acee04
JS
4418 }
4419 }
7608fd01 4420 else
50acee04
JS
4421 {
4422 if (m_hover_button)
4423 {
4424 m_hover_button = NULL;
4425 Repaint();
4426 }
7608fd01 4427 else
50acee04
JS
4428 {
4429 event.Skip();
4430 }
4431 }
4432 }
4433}
4434
a3a5df9d 4435void wxAuiManager::OnLeaveWindow(wxMouseEvent& WXUNUSED(event))
50acee04
JS
4436{
4437 if (m_hover_button)
4438 {
4439 m_hover_button = NULL;
4440 Repaint();
4441 }
4442}
4443
a3a5df9d 4444void wxAuiManager::OnChildFocus(wxChildFocusEvent& event)
50acee04 4445{
be66f18e
WS
4446 // when a child pane has it's focus set, we should change the
4447 // pane's active state to reflect this. (this is only true if
50acee04
JS
4448 // active panes are allowed by the owner)
4449 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
4450 {
d7ad415c
BW
4451 wxAuiPaneInfo& pane = GetPane(event.GetWindow());
4452 if (pane.IsOk() && (pane.state & wxAuiPaneInfo::optionActive) == 0)
50acee04
JS
4453 {
4454 SetActivePane(m_panes, event.GetWindow());
4455 m_frame->Refresh();
4456 }
4457 }
c08ee034 4458
16541a4e 4459 event.Skip();
50acee04
JS
4460}
4461
4462
4463// OnPaneButton() is an event handler that is called
4464// when a pane button has been pressed.
a3a5df9d 4465void wxAuiManager::OnPaneButton(wxAuiManagerEvent& evt)
50acee04 4466{
a3a5df9d 4467 wxASSERT_MSG(evt.pane, wxT("Pane Info passed to wxAuiManager::OnPaneButton must be non-null"));
a1b3b608 4468
a3a5df9d 4469 wxAuiPaneInfo& pane = *(evt.pane);
be66f18e 4470
4953f8cf 4471 if (evt.button == wxAUI_BUTTON_CLOSE)
50acee04 4472 {
e092fb2e 4473 // fire pane close event
bc07ab17 4474 wxAuiManagerEvent e(wxEVT_AUI_PANE_CLOSE);
bc9e3321 4475 e.SetManager(this);
58754643
BW
4476 e.SetPane(evt.pane);
4477 ProcessMgrEvent(e);
a1b3b608 4478
58754643 4479 if (!e.GetVeto())
cf08f19a 4480 {
7da1b21e
BW
4481 // close the pane, but check that it
4482 // still exists in our pane array first
4483 // (the event handler above might have removed it)
4484
4485 wxAuiPaneInfo& check = GetPane(pane.window);
4486 if (check.IsOk())
4487 {
4488 ClosePane(pane);
4489 }
be794d62 4490
58754643 4491 Update();
cf08f19a 4492 }
37106ab2
BW
4493 }
4494 else if (evt.button == wxAUI_BUTTON_MAXIMIZE_RESTORE && !pane.IsMaximized())
4495 {
4496 // fire pane close event
bc07ab17 4497 wxAuiManagerEvent e(wxEVT_AUI_PANE_MAXIMIZE);
bc9e3321 4498 e.SetManager(this);
37106ab2
BW
4499 e.SetPane(evt.pane);
4500 ProcessMgrEvent(e);
4501
4502 if (!e.GetVeto())
4503 {
4504 MaximizePane(pane);
4505 Update();
4506 }
4507 }
4508 else if (evt.button == wxAUI_BUTTON_MAXIMIZE_RESTORE && pane.IsMaximized())
4509 {
4510 // fire pane close event
bc07ab17 4511 wxAuiManagerEvent e(wxEVT_AUI_PANE_RESTORE);
bc9e3321 4512 e.SetManager(this);
37106ab2
BW
4513 e.SetPane(evt.pane);
4514 ProcessMgrEvent(e);
4515
4516 if (!e.GetVeto())
4517 {
4518 RestorePane(pane);
4519 Update();
4520 }
50acee04 4521 }
7608fd01 4522 else if (evt.button == wxAUI_BUTTON_PIN)
50acee04
JS
4523 {
4524 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
4525 pane.IsFloatable())
4526 pane.Float();
4527 Update();
4528 }
4529}
4530
4531#endif // wxUSE_AUI