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