]> git.saurik.com Git - wxWidgets.git/blob - src/aui/framemanager.cpp
allow programmatic access to start pane dragging
[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 if(pane.IsMaximized()) {
1726 has_maximized_pane = true;
1727 }
1728
1729 int amount = pane_pos - offset;
1730 if (amount > 0)
1731 {
1732 if (dock.IsVertical())
1733 sizer_item = dock_sizer->Add(1, amount, 0, wxEXPAND);
1734 else
1735 sizer_item = dock_sizer->Add(amount, 1, 0, wxEXPAND);
1736
1737 part.type = wxAuiDockUIPart::typeBackground;
1738 part.dock = &dock;
1739 part.pane = NULL;
1740 part.button = NULL;
1741 part.orientation = (orientation==wxHORIZONTAL) ? wxVERTICAL:wxHORIZONTAL;
1742 part.cont_sizer = dock_sizer;
1743 part.sizer_item = sizer_item;
1744 uiparts.Add(part);
1745
1746 offset += amount;
1747 }
1748
1749 LayoutAddPane(dock_sizer, dock, pane, uiparts, spacer_only);
1750
1751 offset += pane_sizes.Item(pane_i);
1752 }
1753
1754 // at the end add a very small stretchable background area
1755 sizer_item = dock_sizer->Add(1,1, 1, wxEXPAND);
1756
1757 part.type = wxAuiDockUIPart::typeBackground;
1758 part.dock = &dock;
1759 part.pane = NULL;
1760 part.button = NULL;
1761 part.orientation = orientation;
1762 part.cont_sizer = dock_sizer;
1763 part.sizer_item = sizer_item;
1764 uiparts.Add(part);
1765 }
1766 else
1767 {
1768 for (pane_i = 0; pane_i < pane_count; ++pane_i)
1769 {
1770 wxAuiPaneInfo& pane = *(dock.panes.Item(pane_i));
1771 if(pane.IsMaximized()) {
1772 has_maximized_pane = true;
1773 }
1774
1775 // if this is not the first pane being added,
1776 // we need to add a pane sizer
1777 if (!m_has_maximized && pane_i > 0)
1778 {
1779 sizer_item = dock_sizer->Add(sash_size, sash_size, 0, wxEXPAND);
1780
1781 part.type = wxAuiDockUIPart::typePaneSizer;
1782 part.dock = &dock;
1783 part.pane = dock.panes.Item(pane_i-1);
1784 part.button = NULL;
1785 part.orientation = (orientation==wxHORIZONTAL) ? wxVERTICAL:wxHORIZONTAL;
1786 part.cont_sizer = dock_sizer;
1787 part.sizer_item = sizer_item;
1788 uiparts.Add(part);
1789 }
1790
1791 LayoutAddPane(dock_sizer, dock, pane, uiparts, spacer_only);
1792 }
1793 }
1794
1795 if (dock.dock_direction == wxAUI_DOCK_CENTER || has_maximized_pane)
1796 sizer_item = cont->Add(dock_sizer, 1, wxEXPAND);
1797 else
1798 sizer_item = cont->Add(dock_sizer, 0, wxEXPAND);
1799
1800 part.type = wxAuiDockUIPart::typeDock;
1801 part.dock = &dock;
1802 part.pane = NULL;
1803 part.button = NULL;
1804 part.orientation = orientation;
1805 part.cont_sizer = cont;
1806 part.sizer_item = sizer_item;
1807 uiparts.Add(part);
1808
1809 if (dock.IsHorizontal())
1810 cont->SetItemMinSize(dock_sizer, 0, dock.size);
1811 else
1812 cont->SetItemMinSize(dock_sizer, dock.size, 0);
1813
1814 // top and left docks have a sash after them
1815 if (!m_has_maximized && !dock.fixed && (dock.dock_direction == wxAUI_DOCK_TOP ||
1816 dock.dock_direction == wxAUI_DOCK_LEFT))
1817 {
1818 sizer_item = cont->Add(sash_size, sash_size, 0, wxEXPAND);
1819
1820 part.type = wxAuiDockUIPart::typeDockSizer;
1821 part.dock = &dock;
1822 part.pane = NULL;
1823 part.button = NULL;
1824 part.orientation = orientation;
1825 part.cont_sizer = cont;
1826 part.sizer_item = sizer_item;
1827 uiparts.Add(part);
1828 }
1829 }
1830
1831 wxSizer* wxAuiManager::LayoutAll(wxAuiPaneInfoArray& panes,
1832 wxAuiDockInfoArray& docks,
1833 wxAuiDockUIPartArray& uiparts,
1834 bool spacer_only)
1835 {
1836 wxBoxSizer* container = new wxBoxSizer(wxVERTICAL);
1837
1838 int pane_border_size = m_art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE);
1839 int caption_size = m_art->GetMetric(wxAUI_DOCKART_CAPTION_SIZE);
1840 wxSize cli_size = m_frame->GetClientSize();
1841 int i, dock_count, pane_count;
1842
1843
1844 // empty all docks out
1845 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
1846 docks.Item(i).panes.Empty();
1847
1848
1849 // iterate through all known panes, filing each
1850 // of them into the appropriate dock. If the
1851 // pane does not exist in the dock, add it
1852 for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
1853 {
1854 wxAuiPaneInfo& p = panes.Item(i);
1855
1856 // find any docks in this layer
1857 wxAuiDockInfo* dock;
1858 wxAuiDockInfoPtrArray arr;
1859 FindDocks(docks, p.dock_direction, p.dock_layer, p.dock_row, arr);
1860
1861 if (arr.GetCount() > 0)
1862 {
1863 dock = arr.Item(0);
1864 }
1865 else
1866 {
1867 // dock was not found, so we need to create a new one
1868 wxAuiDockInfo d;
1869 d.dock_direction = p.dock_direction;
1870 d.dock_layer = p.dock_layer;
1871 d.dock_row = p.dock_row;
1872 docks.Add(d);
1873 dock = &docks.Last();
1874 }
1875
1876
1877 if (p.IsDocked() && p.IsShown())
1878 {
1879 // remove the pane from any existing docks except this one
1880 RemovePaneFromDocks(docks, p, dock);
1881
1882 // pane needs to be added to the dock,
1883 // if it doesn't already exist
1884 if (!FindPaneInDock(*dock, p.window))
1885 dock->panes.Add(&p);
1886 }
1887 else
1888 {
1889 // remove the pane from any existing docks
1890 RemovePaneFromDocks(docks, p);
1891 }
1892
1893 }
1894
1895 // remove any empty docks
1896 for (i = docks.GetCount()-1; i >= 0; --i)
1897 {
1898 if (docks.Item(i).panes.GetCount() == 0)
1899 docks.RemoveAt(i);
1900 }
1901
1902 // configure the docks further
1903 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
1904 {
1905 wxAuiDockInfo& dock = docks.Item(i);
1906 int j, dock_pane_count = dock.panes.GetCount();
1907
1908 // sort the dock pane array by the pane's
1909 // dock position (dock_pos), in ascending order
1910 dock.panes.Sort(PaneSortFunc);
1911
1912 // for newly created docks, set up their initial size
1913 if (dock.size == 0)
1914 {
1915 int size = 0;
1916
1917 for (j = 0; j < dock_pane_count; ++j)
1918 {
1919 wxAuiPaneInfo& pane = *dock.panes.Item(j);
1920 wxSize pane_size = pane.best_size;
1921 if (pane_size == wxDefaultSize)
1922 pane_size = pane.min_size;
1923 if (pane_size == wxDefaultSize)
1924 pane_size = pane.window->GetSize();
1925
1926 if (dock.IsHorizontal())
1927 size = wxMax(pane_size.y, size);
1928 else
1929 size = wxMax(pane_size.x, size);
1930 }
1931
1932 // add space for the border (two times), but only
1933 // if at least one pane inside the dock has a pane border
1934 for (j = 0; j < dock_pane_count; ++j)
1935 {
1936 if (dock.panes.Item(j)->HasBorder())
1937 {
1938 size += (pane_border_size*2);
1939 break;
1940 }
1941 }
1942
1943 // if pane is on the top or bottom, add the caption height,
1944 // but only if at least one pane inside the dock has a caption
1945 if (dock.IsHorizontal())
1946 {
1947 for (j = 0; j < dock_pane_count; ++j)
1948 {
1949 if (dock.panes.Item(j)->HasCaption())
1950 {
1951 size += caption_size;
1952 break;
1953 }
1954 }
1955 }
1956
1957 if (!(m_flags & wxAUI_MGR_NO_DOCK_SIZE_LIMIT))
1958 {
1959 // new dock's size may not be more than 1/3 of the frame size
1960 if (dock.IsHorizontal())
1961 size = wxMin(size, cli_size.y/3);
1962 else
1963 size = wxMin(size, cli_size.x/3);
1964 }
1965
1966 if (size < 10)
1967 size = 10;
1968 dock.size = size;
1969 }
1970
1971
1972 // determine the dock's minimum size
1973 bool plus_border = false;
1974 bool plus_caption = false;
1975 int dock_min_size = 0;
1976 for (j = 0; j < dock_pane_count; ++j)
1977 {
1978 wxAuiPaneInfo& pane = *dock.panes.Item(j);
1979 if (pane.min_size != wxDefaultSize)
1980 {
1981 if (pane.HasBorder())
1982 plus_border = true;
1983 if (pane.HasCaption())
1984 plus_caption = true;
1985 if (dock.IsHorizontal())
1986 {
1987 if (pane.min_size.y > dock_min_size)
1988 dock_min_size = pane.min_size.y;
1989 }
1990 else
1991 {
1992 if (pane.min_size.x > dock_min_size)
1993 dock_min_size = pane.min_size.x;
1994 }
1995 }
1996 }
1997
1998 if (plus_border)
1999 dock_min_size += (pane_border_size*2);
2000 if (plus_caption && dock.IsHorizontal())
2001 dock_min_size += (caption_size);
2002
2003 dock.min_size = dock_min_size;
2004
2005
2006 // if the pane's current size is less than it's
2007 // minimum, increase the dock's size to it's minimum
2008 if (dock.size < dock.min_size)
2009 dock.size = dock.min_size;
2010
2011
2012 // determine the dock's mode (fixed or proportional);
2013 // determine whether the dock has only toolbars
2014 bool action_pane_marked = false;
2015 dock.fixed = true;
2016 dock.toolbar = true;
2017 for (j = 0; j < dock_pane_count; ++j)
2018 {
2019 wxAuiPaneInfo& pane = *dock.panes.Item(j);
2020 if (!pane.IsFixed())
2021 dock.fixed = false;
2022 if (!pane.IsToolbar())
2023 dock.toolbar = false;
2024 if (pane.state & wxAuiPaneInfo::actionPane)
2025 action_pane_marked = true;
2026 }
2027
2028
2029 // if the dock mode is proportional and not fixed-pixel,
2030 // reassign the dock_pos to the sequential 0, 1, 2, 3;
2031 // e.g. remove gaps like 1, 2, 30, 500
2032 if (!dock.fixed)
2033 {
2034 for (j = 0; j < dock_pane_count; ++j)
2035 {
2036 wxAuiPaneInfo& pane = *dock.panes.Item(j);
2037 pane.dock_pos = j;
2038 }
2039 }
2040
2041 // if the dock mode is fixed, and none of the panes
2042 // are being moved right now, make sure the panes
2043 // do not overlap each other. If they do, we will
2044 // adjust the panes' positions
2045 if (dock.fixed && !action_pane_marked)
2046 {
2047 wxArrayInt pane_positions, pane_sizes;
2048 GetPanePositionsAndSizes(dock, pane_positions, pane_sizes);
2049
2050 int offset = 0;
2051 for (j = 0; j < dock_pane_count; ++j)
2052 {
2053 wxAuiPaneInfo& pane = *(dock.panes.Item(j));
2054 pane.dock_pos = pane_positions[j];
2055
2056 int amount = pane.dock_pos - offset;
2057 if (amount >= 0)
2058 offset += amount;
2059 else
2060 pane.dock_pos += -amount;
2061
2062 offset += pane_sizes[j];
2063 }
2064 }
2065 }
2066
2067 // discover the maximum dock layer
2068 int max_layer = 0;
2069 for (i = 0; i < dock_count; ++i)
2070 max_layer = wxMax(max_layer, docks.Item(i).dock_layer);
2071
2072
2073 // clear out uiparts
2074 uiparts.Empty();
2075
2076 // create a bunch of box sizers,
2077 // from the innermost level outwards.
2078 wxSizer* cont = NULL;
2079 wxSizer* middle = NULL;
2080 int layer = 0;
2081 int row, row_count;
2082
2083 for (layer = 0; layer <= max_layer; ++layer)
2084 {
2085 wxAuiDockInfoPtrArray arr;
2086
2087 // find any docks in this layer
2088 FindDocks(docks, -1, layer, -1, arr);
2089
2090 // if there aren't any, skip to the next layer
2091 if (arr.IsEmpty())
2092 continue;
2093
2094 wxSizer* old_cont = cont;
2095
2096 // create a container which will hold this layer's
2097 // docks (top, bottom, left, right)
2098 cont = new wxBoxSizer(wxVERTICAL);
2099
2100
2101 // find any top docks in this layer
2102 FindDocks(docks, wxAUI_DOCK_TOP, layer, -1, arr);
2103 RenumberDockRows(arr);
2104 if (!arr.IsEmpty())
2105 {
2106 for (row = 0, row_count = arr.GetCount(); row < row_count; ++row)
2107 LayoutAddDock(cont, *arr.Item(row), uiparts, spacer_only);
2108 }
2109
2110
2111 // fill out the middle layer (which consists
2112 // of left docks, content area and right docks)
2113
2114 middle = new wxBoxSizer(wxHORIZONTAL);
2115
2116 // find any left docks in this layer
2117 FindDocks(docks, wxAUI_DOCK_LEFT, layer, -1, arr);
2118 RenumberDockRows(arr);
2119 if (!arr.IsEmpty())
2120 {
2121 for (row = 0, row_count = arr.GetCount(); row < row_count; ++row)
2122 LayoutAddDock(middle, *arr.Item(row), uiparts, spacer_only);
2123 }
2124
2125 // add content dock (or previous layer's sizer
2126 // to the middle
2127 if (!old_cont)
2128 {
2129 // find any center docks
2130 FindDocks(docks, wxAUI_DOCK_CENTER, -1, -1, arr);
2131 if (!arr.IsEmpty())
2132 {
2133 for (row = 0,row_count = arr.GetCount(); row<row_count; ++row)
2134 LayoutAddDock(middle, *arr.Item(row), uiparts, spacer_only);
2135 }
2136 else if (!m_has_maximized)
2137 {
2138 // there are no center docks, add a background area
2139 wxSizerItem* sizer_item = middle->Add(1,1, 1, wxEXPAND);
2140 wxAuiDockUIPart part;
2141 part.type = wxAuiDockUIPart::typeBackground;
2142 part.pane = NULL;
2143 part.dock = NULL;
2144 part.button = NULL;
2145 part.cont_sizer = middle;
2146 part.sizer_item = sizer_item;
2147 uiparts.Add(part);
2148 }
2149 }
2150 else
2151 {
2152 middle->Add(old_cont, 1, wxEXPAND);
2153 }
2154
2155 // find any right docks in this layer
2156 FindDocks(docks, wxAUI_DOCK_RIGHT, layer, -1, arr);
2157 RenumberDockRows(arr);
2158 if (!arr.IsEmpty())
2159 {
2160 for (row = arr.GetCount()-1; row >= 0; --row)
2161 LayoutAddDock(middle, *arr.Item(row), uiparts, spacer_only);
2162 }
2163
2164 cont->Add(middle, 1, wxEXPAND);
2165
2166
2167
2168 // find any bottom docks in this layer
2169 FindDocks(docks, wxAUI_DOCK_BOTTOM, layer, -1, arr);
2170 RenumberDockRows(arr);
2171 if (!arr.IsEmpty())
2172 {
2173 for (row = arr.GetCount()-1; row >= 0; --row)
2174 LayoutAddDock(cont, *arr.Item(row), uiparts, spacer_only);
2175 }
2176
2177 }
2178
2179 if (!cont)
2180 {
2181 // no sizer available, because there are no docks,
2182 // therefore we will create a simple background area
2183 cont = new wxBoxSizer(wxVERTICAL);
2184 wxSizerItem* sizer_item = cont->Add(1,1, 1, wxEXPAND);
2185 wxAuiDockUIPart part;
2186 part.type = wxAuiDockUIPart::typeBackground;
2187 part.pane = NULL;
2188 part.dock = NULL;
2189 part.button = NULL;
2190 part.cont_sizer = middle;
2191 part.sizer_item = sizer_item;
2192 uiparts.Add(part);
2193 }
2194
2195 container->Add(cont, 1, wxEXPAND);
2196 return container;
2197 }
2198
2199
2200 // Update() updates the layout. Whenever changes are made to
2201 // one or more panes, this function should be called. It is the
2202 // external entry point for running the layout engine.
2203
2204 void wxAuiManager::Update()
2205 {
2206 wxSizer* sizer;
2207 int i, pane_count = m_panes.GetCount();
2208
2209
2210 // destroy floating panes which have been
2211 // redocked or are becoming non-floating
2212 for (i = 0; i < pane_count; ++i)
2213 {
2214 wxAuiPaneInfo& p = m_panes.Item(i);
2215
2216 if (!p.IsFloating() && p.frame)
2217 {
2218 // because the pane is no longer in a floating, we need to
2219 // reparent it to m_frame and destroy the floating frame
2220
2221 // reduce flicker
2222 p.window->SetSize(1,1);
2223
2224
2225 // the following block is a workaround for bug #1531361
2226 // (see wxWidgets sourceforge page). On wxGTK (only), when
2227 // a frame is shown/hidden, a move event unfortunately
2228 // also gets fired. Because we may be dragging around
2229 // a pane, we need to cancel that action here to prevent
2230 // a spurious crash.
2231 if (m_action_window == p.frame)
2232 {
2233 if (wxWindow::GetCapture() == m_frame)
2234 m_frame->ReleaseMouse();
2235 m_action = actionNone;
2236 m_action_window = NULL;
2237 }
2238
2239 // hide the frame
2240 if (p.frame->IsShown())
2241 p.frame->Show(false);
2242
2243 // reparent to m_frame and destroy the pane
2244 if(m_action_window == p.frame)
2245 {
2246 m_action_window = NULL;
2247 }
2248
2249 p.window->Reparent(m_frame);
2250 p.frame->SetSizer(NULL);
2251 p.frame->Destroy();
2252 p.frame = NULL;
2253 }
2254 }
2255
2256
2257 // delete old sizer first
2258 m_frame->SetSizer(NULL);
2259
2260 // create a layout for all of the panes
2261 sizer = LayoutAll(m_panes, m_docks, m_uiparts, false);
2262
2263 // hide or show panes as necessary,
2264 // and float panes as necessary
2265 for (i = 0; i < pane_count; ++i)
2266 {
2267 wxAuiPaneInfo& p = m_panes.Item(i);
2268
2269 if (p.IsFloating())
2270 {
2271 if (p.frame == NULL)
2272 {
2273 // we need to create a frame for this
2274 // pane, which has recently been floated
2275 wxAuiFloatingFrame* frame = CreateFloatingFrame(m_frame, p);
2276
2277 // on MSW and Mac, if the owner desires transparent dragging, and
2278 // the dragging is happening right now, then the floating
2279 // window should have this style by default
2280 if (m_action == actionDragFloatingPane &&
2281 (m_flags & wxAUI_MGR_TRANSPARENT_DRAG))
2282 frame->SetTransparent(150);
2283
2284 frame->SetPaneWindow(p);
2285 p.frame = frame;
2286
2287 if (p.IsShown() && !frame->IsShown())
2288 frame->Show();
2289 }
2290 else
2291 {
2292 // frame already exists, make sure it's position
2293 // and size reflect the information in wxAuiPaneInfo
2294 if (p.frame->GetPosition() != p.floating_pos)
2295 {
2296 p.frame->SetSize(p.floating_pos.x, p.floating_pos.y,
2297 wxDefaultCoord, wxDefaultCoord,
2298 wxSIZE_USE_EXISTING);
2299 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2300 }
2301
2302 if (p.frame->IsShown() != p.IsShown())
2303 p.frame->Show(p.IsShown());
2304 }
2305 }
2306 else
2307 {
2308 if (p.window->IsShown() != p.IsShown())
2309 p.window->Show(p.IsShown());
2310 }
2311
2312 // if "active panes" are no longer allowed, clear
2313 // any optionActive values from the pane states
2314 if ((m_flags & wxAUI_MGR_ALLOW_ACTIVE_PANE) == 0)
2315 {
2316 p.state &= ~wxAuiPaneInfo::optionActive;
2317 }
2318 }
2319
2320
2321 // keep track of the old window rectangles so we can
2322 // refresh those windows whose rect has changed
2323 wxAuiRectArray old_pane_rects;
2324 for (i = 0; i < pane_count; ++i)
2325 {
2326 wxRect r;
2327 wxAuiPaneInfo& p = m_panes.Item(i);
2328
2329 if (p.window && p.IsShown() && p.IsDocked())
2330 r = p.rect;
2331
2332 old_pane_rects.Add(r);
2333 }
2334
2335
2336
2337
2338 // apply the new sizer
2339 m_frame->SetSizer(sizer);
2340 m_frame->SetAutoLayout(false);
2341 DoFrameLayout();
2342
2343
2344
2345 // now that the frame layout is done, we need to check
2346 // the new pane rectangles against the old rectangles that
2347 // we saved a few lines above here. If the rectangles have
2348 // changed, the corresponding panes must also be updated
2349 for (i = 0; i < pane_count; ++i)
2350 {
2351 wxAuiPaneInfo& p = m_panes.Item(i);
2352 if (p.window && p.window->IsShown() && p.IsDocked())
2353 {
2354 if (p.rect != old_pane_rects[i])
2355 {
2356 p.window->Refresh();
2357 p.window->Update();
2358 }
2359 }
2360 }
2361
2362
2363 Repaint();
2364
2365 // set frame's minimum size
2366
2367 /*
2368 // N.B. More work needs to be done on frame minimum sizes;
2369 // this is some intresting code that imposes the minimum size,
2370 // but we may want to include a more flexible mechanism or
2371 // options for multiple minimum-size modes, e.g. strict or lax
2372 wxSize min_size = sizer->GetMinSize();
2373 wxSize frame_size = m_frame->GetSize();
2374 wxSize client_size = m_frame->GetClientSize();
2375
2376 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2377 min_size.y+frame_size.y-client_size.y );
2378
2379 m_frame->SetMinSize(minframe_size);
2380
2381 if (frame_size.x < minframe_size.x ||
2382 frame_size.y < minframe_size.y)
2383 sizer->Fit(m_frame);
2384 */
2385 }
2386
2387
2388 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2389 // on the frame's main sizer, then measures all the various UI items
2390 // and updates their internal rectangles. This should always be called
2391 // instead of calling m_frame->Layout() directly
2392
2393 void wxAuiManager::DoFrameLayout()
2394 {
2395 m_frame->Layout();
2396
2397 int i, part_count;
2398 for (i = 0, part_count = m_uiparts.GetCount(); i < part_count; ++i)
2399 {
2400 wxAuiDockUIPart& part = m_uiparts.Item(i);
2401
2402 // get the rectangle of the UI part
2403 // originally, this code looked like this:
2404 // part.rect = wxRect(part.sizer_item->GetPosition(),
2405 // part.sizer_item->GetSize());
2406 // this worked quite well, with one exception: the mdi
2407 // client window had a "deferred" size variable
2408 // that returned the wrong size. It looks like
2409 // a bug in wx, because the former size of the window
2410 // was being returned. So, we will retrieve the part's
2411 // rectangle via other means
2412
2413
2414 part.rect = part.sizer_item->GetRect();
2415 int flag = part.sizer_item->GetFlag();
2416 int border = part.sizer_item->GetBorder();
2417 if (flag & wxTOP)
2418 {
2419 part.rect.y -= border;
2420 part.rect.height += border;
2421 }
2422 if (flag & wxLEFT)
2423 {
2424 part.rect.x -= border;
2425 part.rect.width += border;
2426 }
2427 if (flag & wxBOTTOM)
2428 part.rect.height += border;
2429 if (flag & wxRIGHT)
2430 part.rect.width += border;
2431
2432
2433 if (part.type == wxAuiDockUIPart::typeDock)
2434 part.dock->rect = part.rect;
2435 if (part.type == wxAuiDockUIPart::typePane)
2436 part.pane->rect = part.rect;
2437 }
2438 }
2439
2440 // GetPanePart() looks up the pane the pane border UI part (or the regular
2441 // pane part if there is no border). This allows the caller to get the exact
2442 // rectangle of the pane in question, including decorations like
2443 // caption and border (if any).
2444
2445 wxAuiDockUIPart* wxAuiManager::GetPanePart(wxWindow* wnd)
2446 {
2447 int i, part_count;
2448 for (i = 0, part_count = m_uiparts.GetCount(); i < part_count; ++i)
2449 {
2450 wxAuiDockUIPart& part = m_uiparts.Item(i);
2451 if (part.type == wxAuiDockUIPart::typePaneBorder &&
2452 part.pane && part.pane->window == wnd)
2453 return &part;
2454 }
2455 for (i = 0, part_count = m_uiparts.GetCount(); i < part_count; ++i)
2456 {
2457 wxAuiDockUIPart& part = m_uiparts.Item(i);
2458 if (part.type == wxAuiDockUIPart::typePane &&
2459 part.pane && part.pane->window == wnd)
2460 return &part;
2461 }
2462 return NULL;
2463 }
2464
2465
2466
2467 // GetDockPixelOffset() is an internal function which returns
2468 // a dock's offset in pixels from the left side of the window
2469 // (for horizontal docks) or from the top of the window (for
2470 // vertical docks). This value is necessary for calculating
2471 // fixel-pane/toolbar offsets when they are dragged.
2472
2473 int wxAuiManager::GetDockPixelOffset(wxAuiPaneInfo& test)
2474 {
2475 // the only way to accurately calculate the dock's
2476 // offset is to actually run a theoretical layout
2477
2478 int i, part_count, dock_count;
2479 wxAuiDockInfoArray docks;
2480 wxAuiPaneInfoArray panes;
2481 wxAuiDockUIPartArray uiparts;
2482 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
2483 panes.Add(test);
2484
2485 wxSizer* sizer = LayoutAll(panes, docks, uiparts, true);
2486 wxSize client_size = m_frame->GetClientSize();
2487 sizer->SetDimension(0, 0, client_size.x, client_size.y);
2488 sizer->Layout();
2489
2490 for (i = 0, part_count = uiparts.GetCount(); i < part_count; ++i)
2491 {
2492 wxAuiDockUIPart& part = uiparts.Item(i);
2493 part.rect = wxRect(part.sizer_item->GetPosition(),
2494 part.sizer_item->GetSize());
2495 if (part.type == wxAuiDockUIPart::typeDock)
2496 part.dock->rect = part.rect;
2497 }
2498
2499 delete sizer;
2500
2501 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
2502 {
2503 wxAuiDockInfo& dock = docks.Item(i);
2504 if (test.dock_direction == dock.dock_direction &&
2505 test.dock_layer==dock.dock_layer && test.dock_row==dock.dock_row)
2506 {
2507 if (dock.IsVertical())
2508 return dock.rect.y;
2509 else
2510 return dock.rect.x;
2511 }
2512 }
2513
2514 return 0;
2515 }
2516
2517
2518
2519 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2520 // if a dock operation is allowed, the new dock position is copied into
2521 // the target info. If the operation was allowed, the function returns true.
2522
2523 bool wxAuiManager::ProcessDockResult(wxAuiPaneInfo& target,
2524 const wxAuiPaneInfo& new_pos)
2525 {
2526 bool allowed = false;
2527 switch (new_pos.dock_direction)
2528 {
2529 case wxAUI_DOCK_TOP: allowed = target.IsTopDockable(); break;
2530 case wxAUI_DOCK_BOTTOM: allowed = target.IsBottomDockable(); break;
2531 case wxAUI_DOCK_LEFT: allowed = target.IsLeftDockable(); break;
2532 case wxAUI_DOCK_RIGHT: allowed = target.IsRightDockable(); break;
2533 }
2534
2535 if (allowed)
2536 target = new_pos;
2537
2538 return allowed;
2539 }
2540
2541
2542 // DoDrop() is an important function. It basically takes a mouse position,
2543 // and determines where the pane's new position would be. If the pane is to be
2544 // dropped, it performs the drop operation using the specified dock and pane
2545 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2546 // scenario can be performed, giving precise coordinates for drop hints.
2547 // If, however, wxAuiManager:m_docks and wxAuiManager::m_panes are specified
2548 // as parameters, the changes will be made to the main state arrays
2549
2550 const int auiInsertRowPixels = 10;
2551 const int auiNewRowPixels = 40;
2552 const int auiLayerInsertPixels = 40;
2553 const int auiLayerInsertOffset = 5;
2554
2555 bool wxAuiManager::DoDrop(wxAuiDockInfoArray& docks,
2556 wxAuiPaneInfoArray& panes,
2557 wxAuiPaneInfo& target,
2558 const wxPoint& pt,
2559 const wxPoint& offset)
2560 {
2561 wxSize cli_size = m_frame->GetClientSize();
2562
2563 wxAuiPaneInfo drop = target;
2564
2565
2566 // The result should always be shown
2567 drop.Show();
2568
2569
2570 // Check to see if the pane has been dragged outside of the window
2571 // (or near to the outside of the window), if so, dock it along the edge
2572
2573
2574 int layer_insert_offset = auiLayerInsertOffset;
2575 if (target.IsToolbar())
2576 layer_insert_offset = 0;
2577
2578 if (pt.x < layer_insert_offset &&
2579 pt.x > layer_insert_offset-auiLayerInsertPixels)
2580 {
2581 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_LEFT),
2582 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM)),
2583 GetMaxLayer(docks, wxAUI_DOCK_TOP)) + 1;
2584 drop.Dock().Left().
2585 Layer(new_layer).
2586 Row(0).
2587 Position(pt.y - GetDockPixelOffset(drop) - offset.y);
2588 return ProcessDockResult(target, drop);
2589 }
2590 else if (pt.y < layer_insert_offset &&
2591 pt.y > layer_insert_offset-auiLayerInsertPixels)
2592 {
2593 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_TOP),
2594 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2595 GetMaxLayer(docks, wxAUI_DOCK_RIGHT)) + 1;
2596 drop.Dock().Top().
2597 Layer(new_layer).
2598 Row(0).
2599 Position(pt.x - GetDockPixelOffset(drop) - offset.x);
2600 return ProcessDockResult(target, drop);
2601 }
2602 else if (pt.x >= cli_size.x - layer_insert_offset &&
2603 pt.x < cli_size.x - layer_insert_offset + auiLayerInsertPixels)
2604 {
2605 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_RIGHT),
2606 GetMaxLayer(docks, wxAUI_DOCK_TOP)),
2607 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM)) + 1;
2608
2609 drop.Dock().Right().
2610 Layer(new_layer).
2611 Row(0).
2612 Position(pt.y - GetDockPixelOffset(drop) - offset.y);
2613 return ProcessDockResult(target, drop);
2614 }
2615 else if (pt.y >= cli_size.y - layer_insert_offset &&
2616 pt.y < cli_size.y - layer_insert_offset + auiLayerInsertPixels)
2617 {
2618 int new_layer = wxMax( wxMax( GetMaxLayer(docks, wxAUI_DOCK_BOTTOM),
2619 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2620 GetMaxLayer(docks, wxAUI_DOCK_RIGHT)) + 1;
2621
2622 drop.Dock().Bottom().
2623 Layer(new_layer).
2624 Row(0).
2625 Position(pt.x - GetDockPixelOffset(drop) - offset.x);
2626 return ProcessDockResult(target, drop);
2627 }
2628
2629 wxAuiDockUIPart* part = HitTest(pt.x, pt.y);
2630
2631
2632 if (drop.IsToolbar())
2633 {
2634 if (!part || !part->dock)
2635 return false;
2636
2637 // calculate the offset from where the dock begins
2638 // to the point where the user dropped the pane
2639 int dock_drop_offset = 0;
2640 if (part->dock->IsHorizontal())
2641 dock_drop_offset = pt.x - part->dock->rect.x - offset.x;
2642 else
2643 dock_drop_offset = pt.y - part->dock->rect.y - offset.y;
2644
2645
2646 // toolbars may only be moved in and to fixed-pane docks,
2647 // otherwise we will try to float the pane. Also, the pane
2648 // should float if being dragged over center pane windows
2649 if (!part->dock->fixed || part->dock->dock_direction == wxAUI_DOCK_CENTER)
2650 {
2651 if (m_last_rect.IsEmpty() || m_last_rect.Contains(pt.x, pt.y ))
2652 {
2653 m_skipping = true;
2654 }
2655 else
2656 {
2657 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
2658 (drop.IsFloatable() ||
2659 (part->dock->dock_direction != wxAUI_DOCK_CENTER &&
2660 part->dock->dock_direction != wxAUI_DOCK_NONE)))
2661 {
2662 drop.Float();
2663 }
2664
2665 m_skipping = false;
2666
2667 return ProcessDockResult(target, drop);
2668 }
2669
2670 drop.Position(pt.x - GetDockPixelOffset(drop) - offset.x);
2671
2672 return ProcessDockResult(target, drop);
2673 }
2674 else
2675 {
2676 m_skipping = false;
2677 }
2678
2679 if (!m_skipping)
2680 {
2681 m_last_rect = part->dock->rect;
2682 m_last_rect.Inflate( 15, 15 );
2683 }
2684
2685 drop.Dock().
2686 Direction(part->dock->dock_direction).
2687 Layer(part->dock->dock_layer).
2688 Row(part->dock->dock_row).
2689 Position(dock_drop_offset);
2690
2691 if ((
2692 ((pt.y < part->dock->rect.y + 1) && part->dock->IsHorizontal()) ||
2693 ((pt.x < part->dock->rect.x + 1) && part->dock->IsVertical())
2694 ) && part->dock->panes.GetCount() > 1)
2695 {
2696 if ((part->dock->dock_direction == wxAUI_DOCK_TOP) ||
2697 (part->dock->dock_direction == wxAUI_DOCK_LEFT))
2698 {
2699 int row = drop.dock_row;
2700 DoInsertDockRow(panes, part->dock->dock_direction,
2701 part->dock->dock_layer,
2702 part->dock->dock_row);
2703 drop.dock_row = row;
2704 }
2705 else
2706 {
2707 DoInsertDockRow(panes, part->dock->dock_direction,
2708 part->dock->dock_layer,
2709 part->dock->dock_row+1);
2710 drop.dock_row = part->dock->dock_row+1;
2711 }
2712 }
2713
2714 if ((
2715 ((pt.y > part->dock->rect.y + part->dock->rect.height - 2 ) && part->dock->IsHorizontal()) ||
2716 ((pt.x > part->dock->rect.x + part->dock->rect.width - 2 ) && part->dock->IsVertical())
2717 ) && part->dock->panes.GetCount() > 1)
2718 {
2719 if ((part->dock->dock_direction == wxAUI_DOCK_TOP) ||
2720 (part->dock->dock_direction == wxAUI_DOCK_LEFT))
2721 {
2722 DoInsertDockRow(panes, part->dock->dock_direction,
2723 part->dock->dock_layer,
2724 part->dock->dock_row+1);
2725 drop.dock_row = part->dock->dock_row+1;
2726 }
2727 else
2728 {
2729 int row = drop.dock_row;
2730 DoInsertDockRow(panes, part->dock->dock_direction,
2731 part->dock->dock_layer,
2732 part->dock->dock_row);
2733 drop.dock_row = row;
2734 }
2735 }
2736
2737 return ProcessDockResult(target, drop);
2738 }
2739
2740
2741
2742
2743 if (!part)
2744 return false;
2745
2746 if (part->type == wxAuiDockUIPart::typePaneBorder ||
2747 part->type == wxAuiDockUIPart::typeCaption ||
2748 part->type == wxAuiDockUIPart::typeGripper ||
2749 part->type == wxAuiDockUIPart::typePaneButton ||
2750 part->type == wxAuiDockUIPart::typePane ||
2751 part->type == wxAuiDockUIPart::typePaneSizer ||
2752 part->type == wxAuiDockUIPart::typeDockSizer ||
2753 part->type == wxAuiDockUIPart::typeBackground)
2754 {
2755 if (part->type == wxAuiDockUIPart::typeDockSizer)
2756 {
2757 if (part->dock->panes.GetCount() != 1)
2758 return false;
2759 part = GetPanePart(part->dock->panes.Item(0)->window);
2760 if (!part)
2761 return false;
2762 }
2763
2764
2765
2766 // If a normal frame is being dragged over a toolbar, insert it
2767 // along the edge under the toolbar, but over all other panes.
2768 // (this could be done much better, but somehow factoring this
2769 // calculation with the one at the beginning of this function)
2770 if (part->dock && part->dock->toolbar)
2771 {
2772 int layer = 0;
2773
2774 switch (part->dock->dock_direction)
2775 {
2776 case wxAUI_DOCK_LEFT:
2777 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_LEFT),
2778 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM)),
2779 GetMaxLayer(docks, wxAUI_DOCK_TOP));
2780 break;
2781 case wxAUI_DOCK_TOP:
2782 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_TOP),
2783 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2784 GetMaxLayer(docks, wxAUI_DOCK_RIGHT));
2785 break;
2786 case wxAUI_DOCK_RIGHT:
2787 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_RIGHT),
2788 GetMaxLayer(docks, wxAUI_DOCK_TOP)),
2789 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM));
2790 break;
2791 case wxAUI_DOCK_BOTTOM:
2792 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_BOTTOM),
2793 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2794 GetMaxLayer(docks, wxAUI_DOCK_RIGHT));
2795 break;
2796 }
2797
2798 DoInsertDockRow(panes, part->dock->dock_direction,
2799 layer, 0);
2800 drop.Dock().
2801 Direction(part->dock->dock_direction).
2802 Layer(layer).Row(0).Position(0);
2803 return ProcessDockResult(target, drop);
2804 }
2805
2806
2807 if (!part->pane)
2808 return false;
2809
2810 part = GetPanePart(part->pane->window);
2811 if (!part)
2812 return false;
2813
2814 bool insert_dock_row = false;
2815 int insert_row = part->pane->dock_row;
2816 int insert_dir = part->pane->dock_direction;
2817 int insert_layer = part->pane->dock_layer;
2818
2819 switch (part->pane->dock_direction)
2820 {
2821 case wxAUI_DOCK_TOP:
2822 if (pt.y >= part->rect.y &&
2823 pt.y < part->rect.y+auiInsertRowPixels)
2824 insert_dock_row = true;
2825 break;
2826 case wxAUI_DOCK_BOTTOM:
2827 if (pt.y > part->rect.y+part->rect.height-auiInsertRowPixels &&
2828 pt.y <= part->rect.y + part->rect.height)
2829 insert_dock_row = true;
2830 break;
2831 case wxAUI_DOCK_LEFT:
2832 if (pt.x >= part->rect.x &&
2833 pt.x < part->rect.x+auiInsertRowPixels)
2834 insert_dock_row = true;
2835 break;
2836 case wxAUI_DOCK_RIGHT:
2837 if (pt.x > part->rect.x+part->rect.width-auiInsertRowPixels &&
2838 pt.x <= part->rect.x+part->rect.width)
2839 insert_dock_row = true;
2840 break;
2841 case wxAUI_DOCK_CENTER:
2842 {
2843 // "new row pixels" will be set to the default, but
2844 // must never exceed 20% of the window size
2845 int new_row_pixels_x = auiNewRowPixels;
2846 int new_row_pixels_y = auiNewRowPixels;
2847
2848 if (new_row_pixels_x > (part->rect.width*20)/100)
2849 new_row_pixels_x = (part->rect.width*20)/100;
2850
2851 if (new_row_pixels_y > (part->rect.height*20)/100)
2852 new_row_pixels_y = (part->rect.height*20)/100;
2853
2854
2855 // determine if the mouse pointer is in a location that
2856 // will cause a new row to be inserted. The hot spot positions
2857 // are along the borders of the center pane
2858
2859 insert_layer = 0;
2860 insert_dock_row = true;
2861 if (pt.x >= part->rect.x &&
2862 pt.x < part->rect.x+new_row_pixels_x)
2863 insert_dir = wxAUI_DOCK_LEFT;
2864 else
2865 if (pt.y >= part->rect.y &&
2866 pt.y < part->rect.y+new_row_pixels_y)
2867 insert_dir = wxAUI_DOCK_TOP;
2868 else
2869 if (pt.x >= part->rect.x + part->rect.width-new_row_pixels_x &&
2870 pt.x < part->rect.x + part->rect.width)
2871 insert_dir = wxAUI_DOCK_RIGHT;
2872 else
2873 if (pt.y >= part->rect.y+ part->rect.height-new_row_pixels_y &&
2874 pt.y < part->rect.y + part->rect.height)
2875 insert_dir = wxAUI_DOCK_BOTTOM;
2876 else
2877 return false;
2878
2879 insert_row = GetMaxRow(panes, insert_dir, insert_layer) + 1;
2880 }
2881 }
2882
2883 if (insert_dock_row)
2884 {
2885 DoInsertDockRow(panes, insert_dir, insert_layer, insert_row);
2886 drop.Dock().Direction(insert_dir).
2887 Layer(insert_layer).
2888 Row(insert_row).
2889 Position(0);
2890 return ProcessDockResult(target, drop);
2891 }
2892
2893 // determine the mouse offset and the pane size, both in the
2894 // direction of the dock itself, and perpendicular to the dock
2895
2896 int offset, size;
2897
2898 if (part->orientation == wxVERTICAL)
2899 {
2900 offset = pt.y - part->rect.y;
2901 size = part->rect.GetHeight();
2902 }
2903 else
2904 {
2905 offset = pt.x - part->rect.x;
2906 size = part->rect.GetWidth();
2907 }
2908
2909 int drop_position = part->pane->dock_pos;
2910
2911 // if we are in the top/left part of the pane,
2912 // insert the pane before the pane being hovered over
2913 if (offset <= size/2)
2914 {
2915 drop_position = part->pane->dock_pos;
2916 DoInsertPane(panes,
2917 part->pane->dock_direction,
2918 part->pane->dock_layer,
2919 part->pane->dock_row,
2920 part->pane->dock_pos);
2921 }
2922
2923 // if we are in the bottom/right part of the pane,
2924 // insert the pane before the pane being hovered over
2925 if (offset > size/2)
2926 {
2927 drop_position = part->pane->dock_pos+1;
2928 DoInsertPane(panes,
2929 part->pane->dock_direction,
2930 part->pane->dock_layer,
2931 part->pane->dock_row,
2932 part->pane->dock_pos+1);
2933 }
2934
2935 drop.Dock().
2936 Direction(part->dock->dock_direction).
2937 Layer(part->dock->dock_layer).
2938 Row(part->dock->dock_row).
2939 Position(drop_position);
2940 return ProcessDockResult(target, drop);
2941 }
2942
2943 return false;
2944 }
2945
2946
2947 void wxAuiManager::OnHintFadeTimer(wxTimerEvent& WXUNUSED(event))
2948 {
2949 if (!m_hint_wnd || m_hint_fadeamt >= m_hint_fademax)
2950 {
2951 m_hint_fadetimer.Stop();
2952 return;
2953 }
2954
2955 m_hint_fadeamt += 4;
2956 m_hint_wnd->SetTransparent(m_hint_fadeamt);
2957 }
2958
2959 void wxAuiManager::ShowHint(const wxRect& rect)
2960 {
2961 if (m_hint_wnd)
2962 {
2963 // if the hint rect is the same as last time, don't do anything
2964 if (m_last_hint == rect)
2965 return;
2966 m_last_hint = rect;
2967
2968 m_hint_fadeamt = m_hint_fademax;
2969
2970 if ((m_flags & wxAUI_MGR_HINT_FADE)
2971 && !((m_hint_wnd->IsKindOf(CLASSINFO(wxPseudoTransparentFrame))) &&
2972 (m_flags & wxAUI_MGR_NO_VENETIAN_BLINDS_FADE))
2973 )
2974 m_hint_fadeamt = 0;
2975
2976 m_hint_wnd->SetSize(rect);
2977
2978 if (!m_hint_wnd->IsShown())
2979 m_hint_wnd->Show();
2980
2981 // if we are dragging a floating pane, set the focus
2982 // back to that floating pane (otherwise it becomes unfocused)
2983 if (m_action == actionDragFloatingPane && m_action_window)
2984 m_action_window->SetFocus();
2985
2986 m_hint_wnd->SetTransparent(m_hint_fadeamt);
2987 m_hint_wnd->Raise();
2988
2989
2990 if (m_hint_fadeamt != m_hint_fademax) // Only fade if we need to
2991 {
2992 // start fade in timer
2993 m_hint_fadetimer.SetOwner(this, 101);
2994 m_hint_fadetimer.Start(5);
2995 }
2996 }
2997 else // Not using a transparent hint window...
2998 {
2999 if (!(m_flags & wxAUI_MGR_RECTANGLE_HINT))
3000 return;
3001
3002 if (m_last_hint != rect)
3003 {
3004 // remove the last hint rectangle
3005 m_last_hint = rect;
3006 m_frame->Refresh();
3007 m_frame->Update();
3008 }
3009
3010 wxScreenDC screendc;
3011 wxRegion clip(1, 1, 10000, 10000);
3012
3013 // clip all floating windows, so we don't draw over them
3014 int i, pane_count;
3015 for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
3016 {
3017 wxAuiPaneInfo& pane = m_panes.Item(i);
3018
3019 if (pane.IsFloating() &&
3020 pane.frame->IsShown())
3021 {
3022 wxRect rect = pane.frame->GetRect();
3023 #ifdef __WXGTK__
3024 // wxGTK returns the client size, not the whole frame size
3025 rect.width += 15;
3026 rect.height += 35;
3027 rect.Inflate(5);
3028 #endif
3029
3030 clip.Subtract(rect);
3031 }
3032 }
3033
3034 // As we can only hide the hint by redrawing the managed window, we
3035 // need to clip the region to the managed window too or we get
3036 // nasty redrawn problems.
3037 clip.Intersect(m_frame->GetRect());
3038
3039 screendc.SetClippingRegion(clip);
3040
3041 wxBitmap stipple = wxPaneCreateStippleBitmap();
3042 wxBrush brush(stipple);
3043 screendc.SetBrush(brush);
3044 screendc.SetPen(*wxTRANSPARENT_PEN);
3045
3046 screendc.DrawRectangle(rect.x, rect.y, 5, rect.height);
3047 screendc.DrawRectangle(rect.x+5, rect.y, rect.width-10, 5);
3048 screendc.DrawRectangle(rect.x+rect.width-5, rect.y, 5, rect.height);
3049 screendc.DrawRectangle(rect.x+5, rect.y+rect.height-5, rect.width-10, 5);
3050 }
3051 }
3052
3053 void wxAuiManager::HideHint()
3054 {
3055 // hides a transparent window hint, if there is one
3056 if (m_hint_wnd)
3057 {
3058 if (m_hint_wnd->IsShown())
3059 m_hint_wnd->Show(false);
3060 m_hint_wnd->SetTransparent(0);
3061 m_hint_fadetimer.Stop();
3062 m_last_hint = wxRect();
3063 return;
3064 }
3065
3066 // hides a painted hint by redrawing the frame window
3067 if (!m_last_hint.IsEmpty())
3068 {
3069 m_frame->Refresh();
3070 m_frame->Update();
3071 m_last_hint = wxRect();
3072 }
3073 }
3074
3075
3076
3077 void wxAuiManager::StartPaneDrag(wxWindow* pane_window,
3078 const wxPoint& offset)
3079 {
3080 wxAuiPaneInfo& pane = GetPane(pane_window);
3081 if (!pane.IsOk())
3082 return;
3083
3084 if (pane.IsToolbar())
3085 {
3086 m_action = actionDragToolbarPane;
3087 }
3088 else
3089 {
3090 m_action = actionDragFloatingPane;
3091 }
3092
3093 m_action_window = pane_window;
3094 m_action_offset = offset;
3095 m_frame->CaptureMouse();
3096 }
3097
3098
3099 // CalculateHintRect() calculates the drop hint rectangle. The method
3100 // first calls DoDrop() to determine the exact position the pane would
3101 // be at were if dropped. If the pane would indeed become docked at the
3102 // specified drop point, the the rectangle hint will be returned in
3103 // screen coordinates. Otherwise, an empty rectangle is returned.
3104 // |pane_window| is the window pointer of the pane being dragged, |pt| is
3105 // the mouse position, in client coordinates. |offset| describes the offset
3106 // that the mouse is from the upper-left corner of the item being dragged
3107
3108 wxRect wxAuiManager::CalculateHintRect(wxWindow* pane_window,
3109 const wxPoint& pt,
3110 const wxPoint& offset)
3111 {
3112 wxRect rect;
3113
3114 // we need to paint a hint rectangle; to find out the exact hint rectangle,
3115 // we will create a new temporary layout and then measure the resulting
3116 // rectangle; we will create a copy of the docking structures (m_dock)
3117 // so that we don't modify the real thing on screen
3118
3119 int i, pane_count, part_count;
3120 wxAuiDockInfoArray docks;
3121 wxAuiPaneInfoArray panes;
3122 wxAuiDockUIPartArray uiparts;
3123 wxAuiPaneInfo hint = GetPane(pane_window);
3124 hint.name = wxT("__HINT__");
3125 hint.Show();
3126
3127 if (!hint.IsOk())
3128 return rect;
3129
3130 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
3131
3132 // remove any pane already there which bears the same window;
3133 // this happens when you are moving a pane around in a dock
3134 for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
3135 {
3136 if (panes.Item(i).window == pane_window)
3137 {
3138 RemovePaneFromDocks(docks, panes.Item(i));
3139 panes.RemoveAt(i);
3140 break;
3141 }
3142 }
3143
3144 // find out where the new pane would be
3145 if (!DoDrop(docks, panes, hint, pt, offset))
3146 {
3147 return rect;
3148 }
3149
3150 panes.Add(hint);
3151
3152 wxSizer* sizer = LayoutAll(panes, docks, uiparts, true);
3153 wxSize client_size = m_frame->GetClientSize();
3154 sizer->SetDimension(0, 0, client_size.x, client_size.y);
3155 sizer->Layout();
3156
3157 for (i = 0, part_count = uiparts.GetCount();
3158 i < part_count; ++i)
3159 {
3160 wxAuiDockUIPart& part = uiparts.Item(i);
3161
3162 if (part.type == wxAuiDockUIPart::typePaneBorder &&
3163 part.pane && part.pane->name == wxT("__HINT__"))
3164 {
3165 rect = wxRect(part.sizer_item->GetPosition(),
3166 part.sizer_item->GetSize());
3167 break;
3168 }
3169 }
3170
3171 delete sizer;
3172
3173 if (rect.IsEmpty())
3174 {
3175 return rect;
3176 }
3177
3178 // actually show the hint rectangle on the screen
3179 m_frame->ClientToScreen(&rect.x, &rect.y);
3180
3181 return rect;
3182 }
3183
3184 // DrawHintRect() calculates the hint rectangle by calling
3185 // CalculateHintRect(). If there is a rectangle, it shows it
3186 // by calling ShowHint(), otherwise it hides any hint
3187 // rectangle currently shown
3188 void wxAuiManager::DrawHintRect(wxWindow* pane_window,
3189 const wxPoint& pt,
3190 const wxPoint& offset)
3191 {
3192 wxRect rect = CalculateHintRect(pane_window, pt, offset);
3193
3194 if (rect.IsEmpty())
3195 {
3196 HideHint();
3197 }
3198 else
3199 {
3200 ShowHint(rect);
3201 }
3202 }
3203
3204 void wxAuiManager::OnFloatingPaneMoveStart(wxWindow* wnd)
3205 {
3206 // try to find the pane
3207 wxAuiPaneInfo& pane = GetPane(wnd);
3208 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3209
3210 if (m_flags & wxAUI_MGR_TRANSPARENT_DRAG)
3211 pane.frame->SetTransparent(150);
3212 }
3213
3214 void wxAuiManager::OnFloatingPaneMoving(wxWindow* wnd, wxDirection dir)
3215 {
3216 // try to find the pane
3217 wxAuiPaneInfo& pane = GetPane(wnd);
3218 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3219
3220 wxPoint pt = ::wxGetMousePosition();
3221
3222 #if 0
3223 // Adapt pt to direction
3224 if (dir == wxNORTH)
3225 {
3226 // move to pane's upper border
3227 wxPoint pos( 0,0 );
3228 pos = wnd->ClientToScreen( pos );
3229 pt.y = pos.y;
3230 // and some more pixels for the title bar
3231 pt.y -= 5;
3232 } else
3233 if (dir == wxWEST)
3234 {
3235 // move to pane's left border
3236 wxPoint pos( 0,0 );
3237 pos = wnd->ClientToScreen( pos );
3238 pt.x = pos.x;
3239 } else
3240 if (dir == wxEAST)
3241 {
3242 // move to pane's right border
3243 wxPoint pos( wnd->GetSize().x, 0 );
3244 pos = wnd->ClientToScreen( pos );
3245 pt.x = pos.x;
3246 } else
3247 if (dir == wxSOUTH)
3248 {
3249 // move to pane's bottom border
3250 wxPoint pos( 0, wnd->GetSize().y );
3251 pos = wnd->ClientToScreen( pos );
3252 pt.y = pos.y;
3253 }
3254 #else
3255 wxUnusedVar(dir);
3256 #endif
3257
3258 wxPoint client_pt = m_frame->ScreenToClient(pt);
3259
3260 // calculate the offset from the upper left-hand corner
3261 // of the frame to the mouse pointer
3262 wxPoint frame_pos = pane.frame->GetPosition();
3263 wxPoint action_offset(pt.x-frame_pos.x, pt.y-frame_pos.y);
3264
3265 // no hint for toolbar floating windows
3266 if (pane.IsToolbar() && m_action == actionDragFloatingPane)
3267 {
3268 if (m_action == actionDragFloatingPane)
3269 {
3270 wxAuiDockInfoArray docks;
3271 wxAuiPaneInfoArray panes;
3272 wxAuiDockUIPartArray uiparts;
3273 wxAuiPaneInfo hint = pane;
3274
3275 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
3276
3277 // find out where the new pane would be
3278 if (!DoDrop(docks, panes, hint, client_pt))
3279 return;
3280 if (hint.IsFloating())
3281 return;
3282
3283 pane = hint;
3284 m_action = actionDragToolbarPane;
3285 m_action_window = pane.window;
3286
3287 Update();
3288 }
3289
3290 return;
3291 }
3292
3293
3294 // if a key modifier is pressed while dragging the frame,
3295 // don't dock the window
3296 if (wxGetKeyState(WXK_CONTROL) || wxGetKeyState(WXK_ALT))
3297 {
3298 HideHint();
3299 return;
3300 }
3301
3302
3303 DrawHintRect(wnd, client_pt, action_offset);
3304
3305 #ifdef __WXGTK__
3306 // this cleans up some screen artifacts that are caused on GTK because
3307 // we aren't getting the exact size of the window (see comment
3308 // in DrawHintRect)
3309 //Refresh();
3310 #endif
3311
3312
3313 // reduces flicker
3314 m_frame->Update();
3315 }
3316
3317 void wxAuiManager::OnFloatingPaneMoved(wxWindow* wnd, wxDirection dir)
3318 {
3319 // try to find the pane
3320 wxAuiPaneInfo& pane = GetPane(wnd);
3321 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3322
3323 wxPoint pt = ::wxGetMousePosition();
3324
3325 #if 0
3326 // Adapt pt to direction
3327 if (dir == wxNORTH)
3328 {
3329 // move to pane's upper border
3330 wxPoint pos( 0,0 );
3331 pos = wnd->ClientToScreen( pos );
3332 pt.y = pos.y;
3333 // and some more pixels for the title bar
3334 pt.y -= 10;
3335 } else
3336 if (dir == wxWEST)
3337 {
3338 // move to pane's left border
3339 wxPoint pos( 0,0 );
3340 pos = wnd->ClientToScreen( pos );
3341 pt.x = pos.x;
3342 } else
3343 if (dir == wxEAST)
3344 {
3345 // move to pane's right border
3346 wxPoint pos( wnd->GetSize().x, 0 );
3347 pos = wnd->ClientToScreen( pos );
3348 pt.x = pos.x;
3349 } else
3350 if (dir == wxSOUTH)
3351 {
3352 // move to pane's bottom border
3353 wxPoint pos( 0, wnd->GetSize().y );
3354 pos = wnd->ClientToScreen( pos );
3355 pt.y = pos.y;
3356 }
3357 #else
3358 wxUnusedVar(dir);
3359 #endif
3360
3361 wxPoint client_pt = m_frame->ScreenToClient(pt);
3362
3363 // calculate the offset from the upper left-hand corner
3364 // of the frame to the mouse pointer
3365 wxPoint frame_pos = pane.frame->GetPosition();
3366 wxPoint action_offset(pt.x-frame_pos.x, pt.y-frame_pos.y);
3367
3368
3369 // if a key modifier is pressed while dragging the frame,
3370 // don't dock the window
3371 if (!wxGetKeyState(WXK_CONTROL) && !wxGetKeyState(WXK_ALT))
3372 {
3373 // do the drop calculation
3374 DoDrop(m_docks, m_panes, pane, client_pt, action_offset);
3375 }
3376
3377 // if the pane is still floating, update it's floating
3378 // position (that we store)
3379 if (pane.IsFloating())
3380 {
3381 pane.floating_pos = pane.frame->GetPosition();
3382
3383 if (m_flags & wxAUI_MGR_TRANSPARENT_DRAG)
3384 pane.frame->SetTransparent(255);
3385 }
3386 else if (m_has_maximized)
3387 {
3388 RestoreMaximizedPane();
3389 }
3390
3391 Update();
3392
3393 HideHint();
3394 }
3395
3396 void wxAuiManager::OnFloatingPaneResized(wxWindow* wnd, const wxSize& size)
3397 {
3398 // try to find the pane
3399 wxAuiPaneInfo& pane = GetPane(wnd);
3400 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3401
3402 pane.floating_size = size;
3403 }
3404
3405
3406 void wxAuiManager::OnFloatingPaneClosed(wxWindow* wnd, wxCloseEvent& evt)
3407 {
3408 // try to find the pane
3409 wxAuiPaneInfo& pane = GetPane(wnd);
3410 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3411
3412
3413 // fire pane close event
3414 wxAuiManagerEvent e(wxEVT_AUI_PANECLOSE);
3415 e.SetPane(&pane);
3416 e.SetCanVeto(evt.CanVeto());
3417 ProcessMgrEvent(e);
3418
3419 if (e.GetVeto())
3420 {
3421 evt.Veto();
3422 return;
3423 }
3424 else
3425 {
3426 ClosePane(pane);
3427 }
3428 }
3429
3430
3431
3432 void wxAuiManager::OnFloatingPaneActivated(wxWindow* wnd)
3433 {
3434 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
3435 {
3436 // try to find the pane
3437 wxASSERT_MSG(GetPane(wnd).IsOk(), wxT("Pane window not found"));
3438
3439 SetActivePane(m_panes, wnd);
3440 Repaint();
3441 }
3442 }
3443
3444 // OnRender() draws all of the pane captions, sashes,
3445 // backgrounds, captions, grippers, pane borders and buttons.
3446 // It renders the entire user interface.
3447
3448 void wxAuiManager::OnRender(wxAuiManagerEvent& evt)
3449 {
3450 wxDC* dc = evt.GetDC();
3451
3452 #ifdef __WXMAC__
3453 dc->Clear() ;
3454 #endif
3455 int i, part_count;
3456 for (i = 0, part_count = m_uiparts.GetCount();
3457 i < part_count; ++i)
3458 {
3459 wxAuiDockUIPart& part = m_uiparts.Item(i);
3460
3461 // don't draw hidden pane items
3462 if (part.sizer_item && !part.sizer_item->IsShown())
3463 continue;
3464
3465 switch (part.type)
3466 {
3467 case wxAuiDockUIPart::typeDockSizer:
3468 case wxAuiDockUIPart::typePaneSizer:
3469 m_art->DrawSash(*dc, m_frame, part.orientation, part.rect);
3470 break;
3471 case wxAuiDockUIPart::typeBackground:
3472 m_art->DrawBackground(*dc, m_frame, part.orientation, part.rect);
3473 break;
3474 case wxAuiDockUIPart::typeCaption:
3475 m_art->DrawCaption(*dc, m_frame, part.pane->caption, part.rect, *part.pane);
3476 break;
3477 case wxAuiDockUIPart::typeGripper:
3478 m_art->DrawGripper(*dc, m_frame, part.rect, *part.pane);
3479 break;
3480 case wxAuiDockUIPart::typePaneBorder:
3481 m_art->DrawBorder(*dc, m_frame, part.rect, *part.pane);
3482 break;
3483 case wxAuiDockUIPart::typePaneButton:
3484 m_art->DrawPaneButton(*dc, m_frame, part.button->button_id,
3485 wxAUI_BUTTON_STATE_NORMAL, part.rect, *part.pane);
3486 break;
3487 }
3488 }
3489 }
3490
3491
3492 // Render() fire a render event, which is normally handled by
3493 // wxAuiManager::OnRender(). This allows the render function to
3494 // be overridden via the render event. This can be useful for paintin
3495 // custom graphics in the main window. Default behavior can be
3496 // invoked in the overridden function by calling OnRender()
3497
3498 void wxAuiManager::Render(wxDC* dc)
3499 {
3500 wxAuiManagerEvent e(wxEVT_AUI_RENDER);
3501 e.SetManager(this);
3502 e.SetDC(dc);
3503 ProcessMgrEvent(e);
3504 }
3505
3506 void wxAuiManager::Repaint(wxDC* dc)
3507 {
3508 #ifdef __WXMAC__
3509 if ( dc == NULL )
3510 {
3511 m_frame->Refresh() ;
3512 m_frame->Update() ;
3513 return ;
3514 }
3515 #endif
3516 int w, h;
3517 m_frame->GetClientSize(&w, &h);
3518
3519 // figure out which dc to use; if one
3520 // has been specified, use it, otherwise
3521 // make a client dc
3522 wxClientDC* client_dc = NULL;
3523 if (!dc)
3524 {
3525 client_dc = new wxClientDC(m_frame);
3526 dc = client_dc;
3527 }
3528
3529 // if the frame has a toolbar, the client area
3530 // origin will not be (0,0).
3531 wxPoint pt = m_frame->GetClientAreaOrigin();
3532 if (pt.x != 0 || pt.y != 0)
3533 dc->SetDeviceOrigin(pt.x, pt.y);
3534
3535 // render all the items
3536 Render(dc);
3537
3538 // if we created a client_dc, delete it
3539 if (client_dc)
3540 delete client_dc;
3541 }
3542
3543 void wxAuiManager::OnPaint(wxPaintEvent& WXUNUSED(event))
3544 {
3545 wxPaintDC dc(m_frame);
3546 Repaint(&dc);
3547 }
3548
3549 void wxAuiManager::OnEraseBackground(wxEraseEvent& event)
3550 {
3551 #ifdef __WXMAC__
3552 event.Skip() ;
3553 #else
3554 wxUnusedVar(event);
3555 #endif
3556 }
3557
3558 void wxAuiManager::OnSize(wxSizeEvent& event)
3559 {
3560 if (m_frame)
3561 {
3562 DoFrameLayout();
3563 Repaint();
3564
3565 #if wxUSE_MDI
3566 if (m_frame->IsKindOf(CLASSINFO(wxMDIParentFrame)))
3567 {
3568 // for MDI parent frames, this event must not
3569 // be "skipped". In other words, the parent frame
3570 // must not be allowed to resize the client window
3571 // after we are finished processing sizing changes
3572 return;
3573 }
3574 #endif
3575 }
3576 event.Skip();
3577 }
3578
3579 void wxAuiManager::OnFindManager(wxAuiManagerEvent& evt)
3580 {
3581 // get the window we are managing, if none, return NULL
3582 wxWindow* window = GetManagedWindow();
3583 if (!window)
3584 {
3585 evt.SetManager(NULL);
3586 return;
3587 }
3588
3589 // if we are managing a child frame, get the 'real' manager
3590 if (window->IsKindOf(CLASSINFO(wxAuiFloatingFrame)))
3591 {
3592 wxAuiFloatingFrame* float_frame = static_cast<wxAuiFloatingFrame*>(window);
3593 evt.SetManager(float_frame->GetOwnerManager());
3594 return;
3595 }
3596
3597 // return pointer to ourself
3598 evt.SetManager(this);
3599 }
3600
3601 void wxAuiManager::OnSetCursor(wxSetCursorEvent& event)
3602 {
3603 // determine cursor
3604 wxAuiDockUIPart* part = HitTest(event.GetX(), event.GetY());
3605 wxCursor cursor = wxNullCursor;
3606
3607 if (part)
3608 {
3609 if (part->type == wxAuiDockUIPart::typeDockSizer ||
3610 part->type == wxAuiDockUIPart::typePaneSizer)
3611 {
3612 // a dock may not be resized if it has a single
3613 // pane which is not resizable
3614 if (part->type == wxAuiDockUIPart::typeDockSizer && part->dock &&
3615 part->dock->panes.GetCount() == 1 &&
3616 part->dock->panes.Item(0)->IsFixed())
3617 return;
3618
3619 // panes that may not be resized do not get a sizing cursor
3620 if (part->pane && part->pane->IsFixed())
3621 return;
3622
3623 if (part->orientation == wxVERTICAL)
3624 cursor = wxCursor(wxCURSOR_SIZEWE);
3625 else
3626 cursor = wxCursor(wxCURSOR_SIZENS);
3627 }
3628 else if (part->type == wxAuiDockUIPart::typeGripper)
3629 {
3630 cursor = wxCursor(wxCURSOR_SIZING);
3631 }
3632 }
3633
3634 event.SetCursor(cursor);
3635 }
3636
3637
3638
3639 void wxAuiManager::UpdateButtonOnScreen(wxAuiDockUIPart* button_ui_part,
3640 const wxMouseEvent& event)
3641 {
3642 wxAuiDockUIPart* hit_test = HitTest(event.GetX(), event.GetY());
3643 if (!hit_test || !button_ui_part)
3644 return;
3645
3646 int state = wxAUI_BUTTON_STATE_NORMAL;
3647
3648 if (hit_test == button_ui_part)
3649 {
3650 if (event.LeftDown())
3651 state = wxAUI_BUTTON_STATE_PRESSED;
3652 else
3653 state = wxAUI_BUTTON_STATE_HOVER;
3654 }
3655 else
3656 {
3657 if (event.LeftDown())
3658 state = wxAUI_BUTTON_STATE_HOVER;
3659 }
3660
3661 // now repaint the button with hover state
3662 wxClientDC cdc(m_frame);
3663
3664 // if the frame has a toolbar, the client area
3665 // origin will not be (0,0).
3666 wxPoint pt = m_frame->GetClientAreaOrigin();
3667 if (pt.x != 0 || pt.y != 0)
3668 cdc.SetDeviceOrigin(pt.x, pt.y);
3669
3670 if (hit_test->pane)
3671 {
3672 m_art->DrawPaneButton(cdc, m_frame,
3673 button_ui_part->button->button_id,
3674 state,
3675 button_ui_part->rect,
3676 *hit_test->pane);
3677 }
3678 }
3679
3680 void wxAuiManager::OnLeftDown(wxMouseEvent& event)
3681 {
3682 wxAuiDockUIPart* part = HitTest(event.GetX(), event.GetY());
3683 if (part)
3684 {
3685 if (part->type == wxAuiDockUIPart::typeDockSizer ||
3686 part->type == wxAuiDockUIPart::typePaneSizer)
3687 {
3688 if (part->dock && part->dock->dock_direction == wxAUI_DOCK_CENTER)
3689 return;
3690
3691 // a dock may not be resized if it has a single
3692 // pane which is not resizable
3693 if (part->type == wxAuiDockUIPart::typeDockSizer && part->dock &&
3694 part->dock->panes.GetCount() == 1 &&
3695 part->dock->panes.Item(0)->IsFixed())
3696 return;
3697
3698 // panes that may not be resized should be ignored here
3699 if (part->pane && part->pane->IsFixed())
3700 return;
3701
3702 m_action = actionResize;
3703 m_action_part = part;
3704 m_action_hintrect = wxRect();
3705 m_action_start = wxPoint(event.m_x, event.m_y);
3706 m_action_offset = wxPoint(event.m_x - part->rect.x,
3707 event.m_y - part->rect.y);
3708 m_frame->CaptureMouse();
3709 }
3710 else if (part->type == wxAuiDockUIPart::typePaneButton)
3711 {
3712 m_action = actionClickButton;
3713 m_action_part = part;
3714 m_action_start = wxPoint(event.m_x, event.m_y);
3715 m_frame->CaptureMouse();
3716
3717 UpdateButtonOnScreen(part, event);
3718 }
3719 else if (part->type == wxAuiDockUIPart::typeCaption ||
3720 part->type == wxAuiDockUIPart::typeGripper)
3721 {
3722 if (part->dock && part->dock->dock_direction == wxAUI_DOCK_CENTER)
3723 return;
3724
3725 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
3726 {
3727 // set the caption as active
3728 SetActivePane(m_panes, part->pane->window);
3729 Repaint();
3730 }
3731
3732 m_action = actionClickCaption;
3733 m_action_part = part;
3734 m_action_start = wxPoint(event.m_x, event.m_y);
3735 m_action_offset = wxPoint(event.m_x - part->rect.x,
3736 event.m_y - part->rect.y);
3737 m_frame->CaptureMouse();
3738 }
3739 #ifdef __WXMAC__
3740 else
3741 {
3742 event.Skip();
3743 }
3744 #endif
3745 }
3746 #ifdef __WXMAC__
3747 else
3748 {
3749 event.Skip();
3750 }
3751 #else
3752 event.Skip();
3753 #endif
3754 }
3755
3756
3757 void wxAuiManager::OnLeftUp(wxMouseEvent& event)
3758 {
3759 if (m_action == actionResize)
3760 {
3761 m_frame->ReleaseMouse();
3762
3763 // get rid of the hint rectangle
3764 wxScreenDC dc;
3765 DrawResizeHint(dc, m_action_hintrect);
3766
3767 // resize the dock or the pane
3768 if (m_action_part && m_action_part->type==wxAuiDockUIPart::typeDockSizer)
3769 {
3770 wxRect& rect = m_action_part->dock->rect;
3771
3772 wxPoint new_pos(event.m_x - m_action_offset.x,
3773 event.m_y - m_action_offset.y);
3774
3775 switch (m_action_part->dock->dock_direction)
3776 {
3777 case wxAUI_DOCK_LEFT:
3778 m_action_part->dock->size = new_pos.x - rect.x;
3779 break;
3780 case wxAUI_DOCK_TOP:
3781 m_action_part->dock->size = new_pos.y - rect.y;
3782 break;
3783 case wxAUI_DOCK_RIGHT:
3784 m_action_part->dock->size = rect.x + rect.width -
3785 new_pos.x - m_action_part->rect.GetWidth();
3786 break;
3787 case wxAUI_DOCK_BOTTOM:
3788 m_action_part->dock->size = rect.y + rect.height -
3789 new_pos.y - m_action_part->rect.GetHeight();
3790 break;
3791 }
3792
3793 Update();
3794 Repaint(NULL);
3795 }
3796 else if (m_action_part &&
3797 m_action_part->type == wxAuiDockUIPart::typePaneSizer)
3798 {
3799 wxAuiDockInfo& dock = *m_action_part->dock;
3800 wxAuiPaneInfo& pane = *m_action_part->pane;
3801
3802 int total_proportion = 0;
3803 int dock_pixels = 0;
3804 int new_pixsize = 0;
3805
3806 int caption_size = m_art->GetMetric(wxAUI_DOCKART_CAPTION_SIZE);
3807 int pane_border_size = m_art->GetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE);
3808 int sash_size = m_art->GetMetric(wxAUI_DOCKART_SASH_SIZE);
3809
3810 wxPoint new_pos(event.m_x - m_action_offset.x,
3811 event.m_y - m_action_offset.y);
3812
3813 // determine the pane rectangle by getting the pane part
3814 wxAuiDockUIPart* pane_part = GetPanePart(pane.window);
3815 wxASSERT_MSG(pane_part,
3816 wxT("Pane border part not found -- shouldn't happen"));
3817
3818 // determine the new pixel size that the user wants;
3819 // this will help us recalculate the pane's proportion
3820 if (dock.IsHorizontal())
3821 new_pixsize = new_pos.x - pane_part->rect.x;
3822 else
3823 new_pixsize = new_pos.y - pane_part->rect.y;
3824
3825 // determine the size of the dock, based on orientation
3826 if (dock.IsHorizontal())
3827 dock_pixels = dock.rect.GetWidth();
3828 else
3829 dock_pixels = dock.rect.GetHeight();
3830
3831 // determine the total proportion of all resizable panes,
3832 // and the total size of the dock minus the size of all
3833 // the fixed panes
3834 int i, dock_pane_count = dock.panes.GetCount();
3835 int pane_position = -1;
3836 for (i = 0; i < dock_pane_count; ++i)
3837 {
3838 wxAuiPaneInfo& p = *dock.panes.Item(i);
3839 if (p.window == pane.window)
3840 pane_position = i;
3841
3842 // while we're at it, subtract the pane sash
3843 // width from the dock width, because this would
3844 // skew our proportion calculations
3845 if (i > 0)
3846 dock_pixels -= sash_size;
3847
3848 // also, the whole size (including decorations) of
3849 // all fixed panes must also be subtracted, because they
3850 // are not part of the proportion calculation
3851 if (p.IsFixed())
3852 {
3853 if (dock.IsHorizontal())
3854 dock_pixels -= p.best_size.x;
3855 else
3856 dock_pixels -= p.best_size.y;
3857 }
3858 else
3859 {
3860 total_proportion += p.dock_proportion;
3861 }
3862 }
3863
3864 // find a pane in our dock to 'steal' space from or to 'give'
3865 // space to -- this is essentially what is done when a pane is
3866 // resized; the pane should usually be the first non-fixed pane
3867 // to the right of the action pane
3868 int borrow_pane = -1;
3869 for (i = pane_position+1; i < dock_pane_count; ++i)
3870 {
3871 wxAuiPaneInfo& p = *dock.panes.Item(i);
3872 if (!p.IsFixed())
3873 {
3874 borrow_pane = i;
3875 break;
3876 }
3877 }
3878
3879
3880 // demand that the pane being resized is found in this dock
3881 // (this assert really never should be raised)
3882 wxASSERT_MSG(pane_position != -1, wxT("Pane not found in dock"));
3883
3884 // prevent division by zero
3885 if (dock_pixels == 0 || total_proportion == 0 || borrow_pane == -1)
3886 {
3887 m_action = actionNone;
3888 return;
3889 }
3890
3891 // calculate the new proportion of the pane
3892 int new_proportion = (new_pixsize*total_proportion)/dock_pixels;
3893
3894 // default minimum size
3895 int min_size = 0;
3896
3897 // check against the pane's minimum size, if specified. please note
3898 // that this is not enough to ensure that the minimum size will
3899 // not be violated, because the whole frame might later be shrunk,
3900 // causing the size of the pane to violate it's minimum size
3901 if (pane.min_size.IsFullySpecified())
3902 {
3903 min_size = 0;
3904
3905 if (pane.HasBorder())
3906 min_size += (pane_border_size*2);
3907
3908 // calculate minimum size with decorations (border,caption)
3909 if (pane_part->orientation == wxVERTICAL)
3910 {
3911 min_size += pane.min_size.y;
3912 if (pane.HasCaption())
3913 min_size += caption_size;
3914 }
3915 else
3916 {
3917 min_size += pane.min_size.x;
3918 }
3919 }
3920
3921
3922 // for some reason, an arithmatic error somewhere is causing
3923 // the proportion calculations to always be off by 1 pixel;
3924 // for now we will add the 1 pixel on, but we really should
3925 // determine what's causing this.
3926 min_size++;
3927
3928 int min_proportion = (min_size*total_proportion)/dock_pixels;
3929
3930 if (new_proportion < min_proportion)
3931 new_proportion = min_proportion;
3932
3933
3934
3935 int prop_diff = new_proportion - pane.dock_proportion;
3936
3937 // borrow the space from our neighbor pane to the
3938 // right or bottom (depending on orientation)
3939 dock.panes.Item(borrow_pane)->dock_proportion -= prop_diff;
3940 pane.dock_proportion = new_proportion;
3941
3942 // repaint
3943 Update();
3944 Repaint(NULL);
3945 }
3946 }
3947 else if (m_action == actionClickButton)
3948 {
3949 m_hover_button = NULL;
3950 m_frame->ReleaseMouse();
3951 UpdateButtonOnScreen(m_action_part, event);
3952
3953 // make sure we're still over the item that was originally clicked
3954 if (m_action_part == HitTest(event.GetX(), event.GetY()))
3955 {
3956 // fire button-click event
3957 wxAuiManagerEvent e(wxEVT_AUI_PANEBUTTON);
3958 e.SetManager(this);
3959 e.SetPane(m_action_part->pane);
3960 e.SetButton(m_action_part->button->button_id);
3961 ProcessMgrEvent(e);
3962 }
3963 }
3964 else if (m_action == actionClickCaption)
3965 {
3966 m_frame->ReleaseMouse();
3967 }
3968 else if (m_action == actionDragFloatingPane)
3969 {
3970 m_frame->ReleaseMouse();
3971 }
3972 else if (m_action == actionDragToolbarPane)
3973 {
3974 m_frame->ReleaseMouse();
3975
3976 wxAuiPaneInfo& pane = GetPane(m_action_window);
3977 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3978
3979 // save the new positions
3980 wxAuiDockInfoPtrArray docks;
3981 FindDocks(m_docks, pane.dock_direction,
3982 pane.dock_layer, pane.dock_row, docks);
3983 if (docks.GetCount() == 1)
3984 {
3985 wxAuiDockInfo& dock = *docks.Item(0);
3986
3987 wxArrayInt pane_positions, pane_sizes;
3988 GetPanePositionsAndSizes(dock, pane_positions, pane_sizes);
3989
3990 int i, dock_pane_count = dock.panes.GetCount();
3991 for (i = 0; i < dock_pane_count; ++i)
3992 dock.panes.Item(i)->dock_pos = pane_positions[i];
3993 }
3994
3995 pane.state &= ~wxAuiPaneInfo::actionPane;
3996 Update();
3997 }
3998 else
3999 {
4000 event.Skip();
4001 }
4002
4003 m_action = actionNone;
4004 m_last_mouse_move = wxPoint(); // see comment in OnMotion()
4005 }
4006
4007
4008 void wxAuiManager::OnMotion(wxMouseEvent& event)
4009 {
4010 // sometimes when Update() is called from inside this method,
4011 // a spurious mouse move event is generated; this check will make
4012 // sure that only real mouse moves will get anywhere in this method;
4013 // this appears to be a bug somewhere, and I don't know where the
4014 // mouse move event is being generated. only verified on MSW
4015
4016 wxPoint mouse_pos = event.GetPosition();
4017 if (m_last_mouse_move == mouse_pos)
4018 return;
4019 m_last_mouse_move = mouse_pos;
4020
4021
4022 if (m_action == actionResize)
4023 {
4024 wxPoint pos = m_action_part->rect.GetPosition();
4025 if (m_action_part->orientation == wxHORIZONTAL)
4026 pos.y = wxMax(0, event.m_y - m_action_offset.y);
4027 else
4028 pos.x = wxMax(0, event.m_x - m_action_offset.x);
4029
4030 wxRect rect(m_frame->ClientToScreen(pos),
4031 m_action_part->rect.GetSize());
4032
4033 wxScreenDC dc;
4034 if (!m_action_hintrect.IsEmpty())
4035 DrawResizeHint(dc, m_action_hintrect);
4036 DrawResizeHint(dc, rect);
4037 m_action_hintrect = rect;
4038 }
4039 else if (m_action == actionClickCaption)
4040 {
4041 int drag_x_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_X);
4042 int drag_y_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_Y);
4043
4044 // caption has been clicked. we need to check if the mouse
4045 // is now being dragged. if it is, we need to change the
4046 // mouse action to 'drag'
4047 if (abs(event.m_x - m_action_start.x) > drag_x_threshold ||
4048 abs(event.m_y - m_action_start.y) > drag_y_threshold)
4049 {
4050 wxAuiPaneInfo* pane_info = m_action_part->pane;
4051
4052 if (!pane_info->IsToolbar())
4053 {
4054 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
4055 pane_info->IsFloatable())
4056 {
4057 m_action = actionDragFloatingPane;
4058
4059 // set initial float position
4060 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
4061 pane_info->floating_pos = wxPoint(pt.x - m_action_offset.x,
4062 pt.y - m_action_offset.y);
4063
4064 // float the window
4065 if (pane_info->IsMaximized())
4066 RestorePane(*pane_info);
4067 pane_info->Float();
4068 Update();
4069
4070 m_action_window = pane_info->frame;
4071
4072 // action offset is used here to make it feel "natural" to the user
4073 // to drag a docked pane and suddenly have it become a floating frame.
4074 // Sometimes, however, the offset where the user clicked on the docked
4075 // caption is bigger than the width of the floating frame itself, so
4076 // in that case we need to set the action offset to a sensible value
4077 wxSize frame_size = m_action_window->GetSize();
4078 if (frame_size.x <= m_action_offset.x)
4079 m_action_offset.x = 30;
4080 }
4081 }
4082 else
4083 {
4084 m_action = actionDragToolbarPane;
4085 m_action_window = pane_info->window;
4086 }
4087 }
4088 }
4089 else if (m_action == actionDragFloatingPane)
4090 {
4091 if(m_action_window) {
4092 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
4093 m_action_window->Move(pt.x - m_action_offset.x,
4094 pt.y - m_action_offset.y);
4095 }
4096 }
4097 else if (m_action == actionDragToolbarPane)
4098 {
4099 wxAuiPaneInfo& pane = GetPane(m_action_window);
4100 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
4101
4102 pane.state |= wxAuiPaneInfo::actionPane;
4103
4104 wxPoint pt = event.GetPosition();
4105 DoDrop(m_docks, m_panes, pane, pt, m_action_offset);
4106
4107 // if DoDrop() decided to float the pane, set up
4108 // the floating pane's initial position
4109 if (pane.IsFloating())
4110 {
4111 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
4112 pane.floating_pos = wxPoint(pt.x - m_action_offset.x,
4113 pt.y - m_action_offset.y);
4114 }
4115
4116 // this will do the actiual move operation;
4117 // in the case that the pane has been floated,
4118 // this call will create the floating pane
4119 // and do the reparenting
4120 Update();
4121
4122 // if the pane has been floated, change the mouse
4123 // action actionDragFloatingPane so that subsequent
4124 // EVT_MOTION() events will move the floating pane
4125 if (pane.IsFloating())
4126 {
4127 pane.state &= ~wxAuiPaneInfo::actionPane;
4128 m_action = actionDragFloatingPane;
4129 m_action_window = pane.frame;
4130 }
4131 }
4132 else
4133 {
4134 wxAuiDockUIPart* part = HitTest(event.GetX(), event.GetY());
4135 if (part && part->type == wxAuiDockUIPart::typePaneButton)
4136 {
4137 if (part != m_hover_button)
4138 {
4139 // make the old button normal
4140 if (m_hover_button)
4141 {
4142 UpdateButtonOnScreen(m_hover_button, event);
4143 Repaint();
4144 }
4145
4146 // mouse is over a button, so repaint the
4147 // button in hover mode
4148 UpdateButtonOnScreen(part, event);
4149 m_hover_button = part;
4150
4151 }
4152 }
4153 else
4154 {
4155 if (m_hover_button)
4156 {
4157 m_hover_button = NULL;
4158 Repaint();
4159 }
4160 else
4161 {
4162 event.Skip();
4163 }
4164 }
4165 }
4166 }
4167
4168 void wxAuiManager::OnLeaveWindow(wxMouseEvent& WXUNUSED(event))
4169 {
4170 if (m_hover_button)
4171 {
4172 m_hover_button = NULL;
4173 Repaint();
4174 }
4175 }
4176
4177 void wxAuiManager::OnChildFocus(wxChildFocusEvent& event)
4178 {
4179 // when a child pane has it's focus set, we should change the
4180 // pane's active state to reflect this. (this is only true if
4181 // active panes are allowed by the owner)
4182 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
4183 {
4184 if (GetPane(event.GetWindow()).IsOk())
4185 {
4186 SetActivePane(m_panes, event.GetWindow());
4187 m_frame->Refresh();
4188 }
4189 }
4190
4191 event.Skip();
4192 }
4193
4194
4195 // OnPaneButton() is an event handler that is called
4196 // when a pane button has been pressed.
4197 void wxAuiManager::OnPaneButton(wxAuiManagerEvent& evt)
4198 {
4199 wxASSERT_MSG(evt.pane, wxT("Pane Info passed to wxAuiManager::OnPaneButton must be non-null"));
4200
4201 wxAuiPaneInfo& pane = *(evt.pane);
4202
4203 if (evt.button == wxAUI_BUTTON_CLOSE)
4204 {
4205 // fire pane close event
4206 wxAuiManagerEvent e(wxEVT_AUI_PANECLOSE);
4207 e.SetManager(this);
4208 e.SetPane(evt.pane);
4209 ProcessMgrEvent(e);
4210
4211 if (!e.GetVeto())
4212 {
4213 ClosePane(pane);
4214 Update();
4215 }
4216 }
4217 else if (evt.button == wxAUI_BUTTON_MAXIMIZE_RESTORE && !pane.IsMaximized())
4218 {
4219 // fire pane close event
4220 wxAuiManagerEvent e(wxEVT_AUI_PANEMAXIMIZE);
4221 e.SetManager(this);
4222 e.SetPane(evt.pane);
4223 ProcessMgrEvent(e);
4224
4225 if (!e.GetVeto())
4226 {
4227 MaximizePane(pane);
4228 Update();
4229 }
4230 }
4231 else if (evt.button == wxAUI_BUTTON_MAXIMIZE_RESTORE && pane.IsMaximized())
4232 {
4233 // fire pane close event
4234 wxAuiManagerEvent e(wxEVT_AUI_PANERESTORE);
4235 e.SetManager(this);
4236 e.SetPane(evt.pane);
4237 ProcessMgrEvent(e);
4238
4239 if (!e.GetVeto())
4240 {
4241 RestorePane(pane);
4242 Update();
4243 }
4244 }
4245 else if (evt.button == wxAUI_BUTTON_PIN)
4246 {
4247 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
4248 pane.IsFloatable())
4249 pane.Float();
4250 Update();
4251 }
4252 }
4253
4254 #endif // wxUSE_AUI