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