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