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