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