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