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