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