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