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