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