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