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