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