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