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