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