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