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