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