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