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