]> git.saurik.com Git - wxWidgets.git/blob - src/aui/framemanager.cpp
Tinderbox warning fix.
[wxWidgets.git] / src / aui / framemanager.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/framemanager.cpp
3 // Purpose: wxaui: wx advanced user interface - docking window manager
4 // Author: Benjamin I. Williams
5 // Modified by:
6 // Created: 2005-05-17
7 // RCS-ID: $Id$
8 // Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9 // Licence: wxWindows Library Licence, Version 3.1
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_AUI
27
28 #include "wx/aui/framemanager.h"
29 #include "wx/aui/dockart.h"
30 #include "wx/aui/floatpane.h"
31
32 #ifndef WX_PRECOMP
33 #include "wx/settings.h"
34 #include "wx/app.h"
35 #include "wx/dcclient.h"
36 #include "wx/dcscreen.h"
37 #include "wx/toolbar.h"
38 #include "wx/mdi.h"
39 #include "wx/image.h"
40 #endif
41
42 WX_CHECK_BUILD_OPTIONS("wxAUI")
43
44 #include "wx/arrimpl.cpp"
45 WX_DECLARE_OBJARRAY(wxRect, wxAuiRectArray);
46 WX_DEFINE_OBJARRAY(wxAuiRectArray)
47 WX_DEFINE_OBJARRAY(wxDockUIPartArray)
48 WX_DEFINE_OBJARRAY(wxDockInfoArray)
49 WX_DEFINE_OBJARRAY(wxPaneButtonArray)
50 WX_DEFINE_OBJARRAY(wxPaneInfoArray)
51
52 wxPaneInfo wxNullPaneInfo;
53 wxDockInfo wxNullDockInfo;
54 DEFINE_EVENT_TYPE(wxEVT_AUI_PANEBUTTON)
55 DEFINE_EVENT_TYPE(wxEVT_AUI_PANECLOSE)
56
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 wxDefaultCoord, wxDefaultCoord,
1822 wxSIZE_USE_EXISTING);
1823 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
1824 }
1825
1826 p.frame->Show(p.IsShown());
1827 }
1828 }
1829 else
1830 {
1831 p.window->Show(p.IsShown());
1832 }
1833
1834 // if "active panes" are no longer allowed, clear
1835 // any optionActive values from the pane states
1836 if ((m_flags & wxAUI_MGR_ALLOW_ACTIVE_PANE) == 0)
1837 {
1838 p.state &= ~wxPaneInfo::optionActive;
1839 }
1840 }
1841
1842
1843 // keep track of the old window rectangles so we can
1844 // refresh those windows whose rect has changed
1845 wxAuiRectArray old_pane_rects;
1846 for (i = 0; i < pane_count; ++i)
1847 {
1848 wxRect r;
1849 wxPaneInfo& p = m_panes.Item(i);
1850
1851 if (p.window && p.IsShown() && p.IsDocked())
1852 r = p.rect;
1853
1854 old_pane_rects.Add(r);
1855 }
1856
1857
1858
1859
1860 // apply the new sizer
1861 m_frame->SetSizer(sizer);
1862 m_frame->SetAutoLayout(false);
1863 DoFrameLayout();
1864
1865
1866
1867 // now that the frame layout is done, we need to check
1868 // the new pane rectangles against the old rectangles that
1869 // we saved a few lines above here. If the rectangles have
1870 // changed, the corresponding panes must also be updated
1871 for (i = 0; i < pane_count; ++i)
1872 {
1873 wxPaneInfo& p = m_panes.Item(i);
1874 if (p.window && p.window->IsShown() && p.IsDocked())
1875 {
1876 if (p.rect != old_pane_rects[i])
1877 {
1878 p.window->Refresh();
1879 p.window->Update();
1880 }
1881 }
1882 }
1883
1884
1885 Repaint();
1886
1887 // set frame's minimum size
1888
1889 /*
1890 // N.B. More work needs to be done on frame minimum sizes;
1891 // this is some intresting code that imposes the minimum size,
1892 // but we may want to include a more flexible mechanism or
1893 // options for multiple minimum-size modes, e.g. strict or lax
1894 wxSize min_size = sizer->GetMinSize();
1895 wxSize frame_size = m_frame->GetSize();
1896 wxSize client_size = m_frame->GetClientSize();
1897
1898 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
1899 min_size.y+frame_size.y-client_size.y );
1900
1901 m_frame->SetMinSize(minframe_size);
1902
1903 if (frame_size.x < minframe_size.x ||
1904 frame_size.y < minframe_size.y)
1905 sizer->Fit(m_frame);
1906 */
1907 }
1908
1909
1910 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
1911 // on the frame's main sizer, then measures all the various UI items
1912 // and updates their internal rectangles. This should always be called
1913 // instead of calling m_frame->Layout() directly
1914
1915 void wxFrameManager::DoFrameLayout()
1916 {
1917 m_frame->Layout();
1918
1919 int i, part_count;
1920 for (i = 0, part_count = m_uiparts.GetCount(); i < part_count; ++i)
1921 {
1922 wxDockUIPart& part = m_uiparts.Item(i);
1923
1924 // get the rectangle of the UI part
1925 // originally, this code looked like this:
1926 // part.rect = wxRect(part.sizer_item->GetPosition(),
1927 // part.sizer_item->GetSize());
1928 // this worked quite well, with one exception: the mdi
1929 // client window had a "deferred" size variable
1930 // that returned the wrong size. It looks like
1931 // a bug in wx, because the former size of the window
1932 // was being returned. So, we will retrieve the part's
1933 // rectangle via other means
1934
1935
1936 part.rect = part.sizer_item->GetRect();
1937 int flag = part.sizer_item->GetFlag();
1938 int border = part.sizer_item->GetBorder();
1939 if (flag & wxTOP)
1940 {
1941 part.rect.y -= border;
1942 part.rect.height += border;
1943 }
1944 if (flag & wxLEFT)
1945 {
1946 part.rect.x -= border;
1947 part.rect.width += border;
1948 }
1949 if (flag & wxBOTTOM)
1950 part.rect.height += border;
1951 if (flag & wxRIGHT)
1952 part.rect.width += border;
1953
1954
1955 if (part.type == wxDockUIPart::typeDock)
1956 part.dock->rect = part.rect;
1957 if (part.type == wxDockUIPart::typePane)
1958 part.pane->rect = part.rect;
1959 }
1960 }
1961
1962 // GetPanePart() looks up the pane the pane border UI part (or the regular
1963 // pane part if there is no border). This allows the caller to get the exact
1964 // rectangle of the pane in question, including decorations like
1965 // caption and border (if any).
1966
1967 wxDockUIPart* wxFrameManager::GetPanePart(wxWindow* wnd)
1968 {
1969 int i, part_count;
1970 for (i = 0, part_count = m_uiparts.GetCount(); i < part_count; ++i)
1971 {
1972 wxDockUIPart& part = m_uiparts.Item(i);
1973 if (part.type == wxDockUIPart::typePaneBorder &&
1974 part.pane && part.pane->window == wnd)
1975 return &part;
1976 }
1977 for (i = 0, part_count = m_uiparts.GetCount(); i < part_count; ++i)
1978 {
1979 wxDockUIPart& part = m_uiparts.Item(i);
1980 if (part.type == wxDockUIPart::typePane &&
1981 part.pane && part.pane->window == wnd)
1982 return &part;
1983 }
1984 return NULL;
1985 }
1986
1987
1988
1989 // GetDockPixelOffset() is an internal function which returns
1990 // a dock's offset in pixels from the left side of the window
1991 // (for horizontal docks) or from the top of the window (for
1992 // vertical docks). This value is necessary for calculating
1993 // fixel-pane/toolbar offsets when they are dragged.
1994
1995 int wxFrameManager::GetDockPixelOffset(wxPaneInfo& test)
1996 {
1997 // the only way to accurately calculate the dock's
1998 // offset is to actually run a theoretical layout
1999
2000 int i, part_count, dock_count;
2001 wxDockInfoArray docks;
2002 wxPaneInfoArray panes;
2003 wxDockUIPartArray uiparts;
2004 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
2005 panes.Add(test);
2006
2007 wxSizer* sizer = LayoutAll(panes, docks, uiparts, true);
2008 wxSize client_size = m_frame->GetClientSize();
2009 sizer->SetDimension(0, 0, client_size.x, client_size.y);
2010 sizer->Layout();
2011
2012 for (i = 0, part_count = uiparts.GetCount(); i < part_count; ++i)
2013 {
2014 wxDockUIPart& part = uiparts.Item(i);
2015 part.rect = wxRect(part.sizer_item->GetPosition(),
2016 part.sizer_item->GetSize());
2017 if (part.type == wxDockUIPart::typeDock)
2018 part.dock->rect = part.rect;
2019 }
2020
2021 delete sizer;
2022
2023 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
2024 {
2025 wxDockInfo& dock = docks.Item(i);
2026 if (test.dock_direction == dock.dock_direction &&
2027 test.dock_layer==dock.dock_layer && test.dock_row==dock.dock_row)
2028 {
2029 if (dock.IsVertical())
2030 return dock.rect.y;
2031 else
2032 return dock.rect.x;
2033 }
2034 }
2035
2036 return 0;
2037 }
2038
2039
2040
2041 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2042 // if a dock operation is allowed, the new dock position is copied into
2043 // the target info. If the operation was allowed, the function returns true.
2044
2045 static bool ProcessDockResult(wxPaneInfo& target,
2046 const wxPaneInfo& new_pos)
2047 {
2048 bool allowed = false;
2049 switch (new_pos.dock_direction)
2050 {
2051 case wxAUI_DOCK_TOP: allowed = target.IsTopDockable(); break;
2052 case wxAUI_DOCK_BOTTOM: allowed = target.IsBottomDockable(); break;
2053 case wxAUI_DOCK_LEFT: allowed = target.IsLeftDockable(); break;
2054 case wxAUI_DOCK_RIGHT: allowed = target.IsRightDockable(); break;
2055 }
2056
2057 if (allowed)
2058 target = new_pos;
2059
2060 return allowed;
2061 }
2062
2063
2064 // DoDrop() is an important function. It basically takes a mouse position,
2065 // and determines where the pane's new position would be. If the pane is to be
2066 // dropped, it performs the drop operation using the specified dock and pane
2067 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2068 // scenario can be performed, giving precise coordinates for drop hints.
2069 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2070 // as parameters, the changes will be made to the main state arrays
2071
2072 const int auiInsertRowPixels = 10;
2073 const int auiNewRowPixels = 40;
2074 const int auiLayerInsertPixels = 40;
2075 const int auiLayerInsertOffset = 5;
2076
2077 bool wxFrameManager::DoDrop(wxDockInfoArray& docks,
2078 wxPaneInfoArray& panes,
2079 wxPaneInfo& target,
2080 const wxPoint& pt,
2081 const wxPoint& offset)
2082 {
2083 wxSize cli_size = m_frame->GetClientSize();
2084
2085 wxPaneInfo drop = target;
2086
2087
2088 // The result should always be shown
2089 drop.Show();
2090
2091
2092 // Check to see if the pane has been dragged outside of the window
2093 // (or near to the outside of the window), if so, dock it along the edge
2094
2095
2096 int layer_insert_offset = auiLayerInsertOffset;
2097 if (target.IsToolbar())
2098 layer_insert_offset = 0;
2099
2100 if (pt.x < layer_insert_offset &&
2101 pt.x > layer_insert_offset-auiLayerInsertPixels)
2102 {
2103 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_LEFT),
2104 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM)),
2105 GetMaxLayer(docks, wxAUI_DOCK_TOP)) + 1;
2106 drop.Dock().Left().
2107 Layer(new_layer).
2108 Row(0).
2109 Position(pt.y - GetDockPixelOffset(drop) - offset.y);
2110 return ProcessDockResult(target, drop);
2111 }
2112 else if (pt.y < layer_insert_offset &&
2113 pt.y > layer_insert_offset-auiLayerInsertPixels)
2114 {
2115 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_TOP),
2116 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2117 GetMaxLayer(docks, wxAUI_DOCK_RIGHT)) + 1;
2118 drop.Dock().Top().
2119 Layer(new_layer).
2120 Row(0).
2121 Position(pt.x - GetDockPixelOffset(drop) - offset.x);
2122 return ProcessDockResult(target, drop);
2123 }
2124 else if (pt.x >= cli_size.x - layer_insert_offset &&
2125 pt.x < cli_size.x - layer_insert_offset + auiLayerInsertPixels)
2126 {
2127 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_RIGHT),
2128 GetMaxLayer(docks, wxAUI_DOCK_TOP)),
2129 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM)) + 1;
2130 drop.Dock().Right().
2131 Layer(new_layer).
2132 Row(0).
2133 Position(pt.y - GetDockPixelOffset(drop) - offset.y);
2134 return ProcessDockResult(target, drop);
2135 }
2136 else if (pt.y >= cli_size.y - layer_insert_offset &&
2137 pt.y < cli_size.y - layer_insert_offset + auiLayerInsertPixels)
2138 {
2139 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_BOTTOM),
2140 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2141 GetMaxLayer(docks, wxAUI_DOCK_RIGHT)) + 1;
2142 drop.Dock().Bottom().
2143 Layer(new_layer).
2144 Row(0).
2145 Position(pt.x - GetDockPixelOffset(drop) - offset.x);
2146 return ProcessDockResult(target, drop);
2147 }
2148
2149
2150 wxDockUIPart* part = HitTest(pt.x, pt.y);
2151
2152
2153 if (drop.IsToolbar())
2154 {
2155 if (!part || !part->dock)
2156 return false;
2157
2158
2159 // calculate the offset from where the dock begins
2160 // to the point where the user dropped the pane
2161 int dock_drop_offset = 0;
2162 if (part->dock->IsHorizontal())
2163 dock_drop_offset = pt.x - part->dock->rect.x - offset.x;
2164 else
2165 dock_drop_offset = pt.y - part->dock->rect.y - offset.y;
2166
2167
2168 // toolbars may only be moved in and to fixed-pane docks,
2169 // otherwise we will try to float the pane. Also, the pane
2170 // should float if being dragged over center pane windows
2171 if (!part->dock->fixed || part->dock->dock_direction == wxAUI_DOCK_CENTER)
2172 {
2173 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
2174 (drop.IsFloatable() ||
2175 (part->dock->dock_direction != wxAUI_DOCK_CENTER &&
2176 part->dock->dock_direction != wxAUI_DOCK_NONE)))
2177 {
2178 drop.Float();
2179 }
2180
2181 return ProcessDockResult(target, drop);
2182 }
2183
2184 drop.Dock().
2185 Direction(part->dock->dock_direction).
2186 Layer(part->dock->dock_layer).
2187 Row(part->dock->dock_row).
2188 Position(dock_drop_offset);
2189
2190 if ((
2191 ((pt.y < part->dock->rect.y + 2) && part->dock->IsHorizontal()) ||
2192 ((pt.x < part->dock->rect.x + 2) && part->dock->IsVertical())
2193 ) && part->dock->panes.GetCount() > 1)
2194 {
2195 int row = drop.dock_row;
2196 DoInsertDockRow(panes, part->dock->dock_direction,
2197 part->dock->dock_layer,
2198 part->dock->dock_row);
2199 drop.dock_row = row;
2200 }
2201
2202 if ((
2203 ((pt.y > part->dock->rect.y + part->dock->rect.height - 2 ) && part->dock->IsHorizontal()) ||
2204 ((pt.x > part->dock->rect.x + part->dock->rect.width - 2 ) && part->dock->IsVertical())
2205 ) && part->dock->panes.GetCount() > 1)
2206 {
2207 DoInsertDockRow(panes, part->dock->dock_direction,
2208 part->dock->dock_layer,
2209 part->dock->dock_row+1);
2210 drop.dock_row = part->dock->dock_row+1;
2211 }
2212
2213 return ProcessDockResult(target, drop);
2214 }
2215
2216
2217
2218
2219 if (!part)
2220 return false;
2221
2222 if (part->type == wxDockUIPart::typePaneBorder ||
2223 part->type == wxDockUIPart::typeCaption ||
2224 part->type == wxDockUIPart::typeGripper ||
2225 part->type == wxDockUIPart::typePaneButton ||
2226 part->type == wxDockUIPart::typePane ||
2227 part->type == wxDockUIPart::typePaneSizer ||
2228 part->type == wxDockUIPart::typeDockSizer ||
2229 part->type == wxDockUIPart::typeBackground)
2230 {
2231 if (part->type == wxDockUIPart::typeDockSizer)
2232 {
2233 if (part->dock->panes.GetCount() != 1)
2234 return false;
2235 part = GetPanePart(part->dock->panes.Item(0)->window);
2236 if (!part)
2237 return false;
2238 }
2239
2240
2241
2242 // If a normal frame is being dragged over a toolbar, insert it
2243 // along the edge under the toolbar, but over all other panes.
2244 // (this could be done much better, but somehow factoring this
2245 // calculation with the one at the beginning of this function)
2246 if (part->dock && part->dock->toolbar)
2247 {
2248 int layer = 0;
2249
2250 switch (part->dock->dock_direction)
2251 {
2252 case wxAUI_DOCK_LEFT:
2253 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_LEFT),
2254 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM)),
2255 GetMaxLayer(docks, wxAUI_DOCK_TOP));
2256 break;
2257 case wxAUI_DOCK_TOP:
2258 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_TOP),
2259 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2260 GetMaxLayer(docks, wxAUI_DOCK_RIGHT));
2261 break;
2262 case wxAUI_DOCK_RIGHT:
2263 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_RIGHT),
2264 GetMaxLayer(docks, wxAUI_DOCK_TOP)),
2265 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM));
2266 break;
2267 case wxAUI_DOCK_BOTTOM:
2268 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_BOTTOM),
2269 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2270 GetMaxLayer(docks, wxAUI_DOCK_RIGHT));
2271 break;
2272 }
2273
2274 DoInsertDockRow(panes, part->dock->dock_direction,
2275 layer, 0);
2276 drop.Dock().
2277 Direction(part->dock->dock_direction).
2278 Layer(layer).Row(0).Position(0);
2279 return ProcessDockResult(target, drop);
2280 }
2281
2282
2283 if (!part->pane)
2284 return false;
2285
2286 part = GetPanePart(part->pane->window);
2287 if (!part)
2288 return false;
2289
2290 bool insert_dock_row = false;
2291 int insert_row = part->pane->dock_row;
2292 int insert_dir = part->pane->dock_direction;
2293 int insert_layer = part->pane->dock_layer;
2294
2295 switch (part->pane->dock_direction)
2296 {
2297 case wxAUI_DOCK_TOP:
2298 if (pt.y >= part->rect.y &&
2299 pt.y < part->rect.y+auiInsertRowPixels)
2300 insert_dock_row = true;
2301 break;
2302 case wxAUI_DOCK_BOTTOM:
2303 if (pt.y > part->rect.y+part->rect.height-auiInsertRowPixels &&
2304 pt.y <= part->rect.y + part->rect.height)
2305 insert_dock_row = true;
2306 break;
2307 case wxAUI_DOCK_LEFT:
2308 if (pt.x >= part->rect.x &&
2309 pt.x < part->rect.x+auiInsertRowPixels)
2310 insert_dock_row = true;
2311 break;
2312 case wxAUI_DOCK_RIGHT:
2313 if (pt.x > part->rect.x+part->rect.width-auiInsertRowPixels &&
2314 pt.x <= part->rect.x+part->rect.width)
2315 insert_dock_row = true;
2316 break;
2317 case wxAUI_DOCK_CENTER:
2318 {
2319 // "new row pixels" will be set to the default, but
2320 // must never exceed 20% of the window size
2321 int new_row_pixels_x = auiNewRowPixels;
2322 int new_row_pixels_y = auiNewRowPixels;
2323
2324 if (new_row_pixels_x > (part->rect.width*20)/100)
2325 new_row_pixels_x = (part->rect.width*20)/100;
2326
2327 if (new_row_pixels_y > (part->rect.height*20)/100)
2328 new_row_pixels_y = (part->rect.height*20)/100;
2329
2330
2331 // determine if the mouse pointer is in a location that
2332 // will cause a new row to be inserted. The hot spot positions
2333 // are along the borders of the center pane
2334
2335 insert_layer = 0;
2336 insert_dock_row = true;
2337 if (pt.x >= part->rect.x &&
2338 pt.x < part->rect.x+new_row_pixels_x)
2339 insert_dir = wxAUI_DOCK_LEFT;
2340 else
2341 if (pt.y >= part->rect.y &&
2342 pt.y < part->rect.y+new_row_pixels_y)
2343 insert_dir = wxAUI_DOCK_TOP;
2344 else
2345 if (pt.x >= part->rect.x + part->rect.width-new_row_pixels_x &&
2346 pt.x < part->rect.x + part->rect.width)
2347 insert_dir = wxAUI_DOCK_RIGHT;
2348 else
2349 if (pt.y >= part->rect.y+ part->rect.height-new_row_pixels_y &&
2350 pt.y < part->rect.y + part->rect.height)
2351 insert_dir = wxAUI_DOCK_BOTTOM;
2352 else
2353 return false;
2354
2355 insert_row = GetMaxRow(panes, insert_dir, insert_layer) + 1;
2356 }
2357 }
2358
2359 if (insert_dock_row)
2360 {
2361 DoInsertDockRow(panes, insert_dir, insert_layer, insert_row);
2362 drop.Dock().Direction(insert_dir).
2363 Layer(insert_layer).
2364 Row(insert_row).
2365 Position(0);
2366 return ProcessDockResult(target, drop);
2367 }
2368
2369 // determine the mouse offset and the pane size, both in the
2370 // direction of the dock itself, and perpendicular to the dock
2371
2372 int offset, size;
2373
2374 if (part->orientation == wxVERTICAL)
2375 {
2376 offset = pt.y - part->rect.y;
2377 size = part->rect.GetHeight();
2378 }
2379 else
2380 {
2381 offset = pt.x - part->rect.x;
2382 size = part->rect.GetWidth();
2383 }
2384
2385 int drop_position = part->pane->dock_pos;
2386
2387 // if we are in the top/left part of the pane,
2388 // insert the pane before the pane being hovered over
2389 if (offset <= size/2)
2390 {
2391 drop_position = part->pane->dock_pos;
2392 DoInsertPane(panes,
2393 part->pane->dock_direction,
2394 part->pane->dock_layer,
2395 part->pane->dock_row,
2396 part->pane->dock_pos);
2397 }
2398
2399 // if we are in the bottom/right part of the pane,
2400 // insert the pane before the pane being hovered over
2401 if (offset > size/2)
2402 {
2403 drop_position = part->pane->dock_pos+1;
2404 DoInsertPane(panes,
2405 part->pane->dock_direction,
2406 part->pane->dock_layer,
2407 part->pane->dock_row,
2408 part->pane->dock_pos+1);
2409 }
2410
2411 drop.Dock().
2412 Direction(part->dock->dock_direction).
2413 Layer(part->dock->dock_layer).
2414 Row(part->dock->dock_row).
2415 Position(drop_position);
2416 return ProcessDockResult(target, drop);
2417 }
2418
2419 return false;
2420 }
2421
2422
2423 void wxFrameManager::OnHintFadeTimer(wxTimerEvent& WXUNUSED(event))
2424 {
2425 if (!m_hint_wnd || m_hint_fadeamt >= 50)
2426 {
2427 m_hint_fadetimer.Stop();
2428 return;
2429 }
2430
2431 m_hint_fadeamt += 5;
2432 MakeWindowTransparent(m_hint_wnd, m_hint_fadeamt);
2433 }
2434
2435 void wxFrameManager::ShowHint(const wxRect& rect)
2436 {
2437 // First, determine if the operating system can handle transparency.
2438 // Transparency is available on Win2000 and above
2439
2440 static int os_type = -1;
2441 static int ver_major = -1;
2442
2443 if (os_type == -1)
2444 os_type = ::wxGetOsVersion(&ver_major);
2445
2446 // If the transparent flag is set, and the OS supports it,
2447 // go ahead and use a transparent hint
2448
2449 if ((m_flags & wxAUI_MGR_TRANSPARENT_HINT) != 0
2450 #ifdef __WXMSW__
2451 && os_type == wxWINDOWS_NT && ver_major >= 5
2452 #endif
2453 )
2454 {
2455 if (m_last_hint == rect)
2456 return;
2457 m_last_hint = rect;
2458
2459 int initial_fade = 50;
2460 if (m_flags & wxAUI_MGR_TRANSPARENT_HINT_FADE)
2461 initial_fade = 0;
2462
2463 if (m_hint_wnd == NULL)
2464 {
2465 wxPoint pt = rect.GetPosition();
2466 wxSize size = rect.GetSize();
2467 #if defined(__WXMSW__)
2468 m_hint_wnd = new wxFrame(m_frame, -1, wxEmptyString, pt, size,
2469 wxFRAME_TOOL_WINDOW |
2470 wxFRAME_FLOAT_ON_PARENT |
2471 wxFRAME_NO_TASKBAR |
2472 wxNO_BORDER);
2473
2474 MakeWindowTransparent(m_hint_wnd, initial_fade);
2475 m_hint_wnd->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION));
2476 #elif defined(__WXMAC__)
2477 // Using a miniframe with float and tool styles keeps the parent
2478 // frame activated and highlighted as such...
2479 m_hint_wnd = new wxMiniFrame(m_frame, -1, wxEmptyString, pt, size,
2480 wxFRAME_FLOAT_ON_PARENT
2481 | wxFRAME_TOOL_WINDOW
2482 | wxCAPTION );
2483
2484 // Can't set the bg colour of a Frame in wxMac
2485 wxPanel* p = new wxPanel(m_hint_wnd);
2486
2487 // The default wxSYS_COLOUR_ACTIVECAPTION colour is a light silver
2488 // color that is really hard to see, especially transparent.
2489 // Until a better system color is decided upon we'll just use
2490 // blue.
2491 p->SetBackgroundColour(*wxBLUE);
2492 #else
2493 wxUnusedVar(pt);
2494 wxUnusedVar(size);
2495 #endif
2496 m_hint_wnd->Show();
2497
2498 // if we are dragging a floating pane, set the focus
2499 // back to that floating pane (otherwise it becomes unfocused)
2500 if (m_action == actionDragFloatingPane && m_action_window)
2501 m_action_window->SetFocus();
2502
2503 }
2504 else
2505 {
2506 MakeWindowTransparent(m_hint_wnd, initial_fade);
2507 m_hint_wnd->SetSize(rect);
2508 m_hint_wnd->Raise();
2509 }
2510
2511 if (m_flags & wxAUI_MGR_TRANSPARENT_HINT_FADE)
2512 {
2513 // start fade in timer
2514 m_hint_fadeamt = 0;
2515 m_hint_fadetimer.SetOwner(this, 101);
2516 m_hint_fadetimer.Start(5);
2517 }
2518
2519 return;
2520 }
2521
2522 if (m_last_hint != rect)
2523 {
2524 // remove the last hint rectangle
2525 m_last_hint = rect;
2526 m_frame->Refresh();
2527 m_frame->Update();
2528 }
2529
2530 wxScreenDC screendc;
2531 wxRegion clip(1, 1, 10000, 10000);
2532
2533 // clip all floating windows, so we don't draw over them
2534 int i, pane_count;
2535 for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
2536 {
2537 wxPaneInfo& pane = m_panes.Item(i);
2538
2539 if (pane.IsFloating() &&
2540 pane.frame->IsShown())
2541 {
2542 wxRect rect = pane.frame->GetRect();
2543 #ifdef __WXGTK__
2544 // wxGTK returns the client size, not the whole frame size
2545 rect.width += 15;
2546 rect.height += 35;
2547 rect.Inflate(5);
2548 #endif
2549
2550 clip.Subtract(rect);
2551 }
2552 }
2553
2554 screendc.SetClippingRegion(clip);
2555
2556 wxBitmap stipple = wxPaneCreateStippleBitmap();
2557 wxBrush brush(stipple);
2558 screendc.SetBrush(brush);
2559 screendc.SetPen(*wxTRANSPARENT_PEN);
2560
2561 screendc.DrawRectangle(rect.x, rect.y, 5, rect.height);
2562 screendc.DrawRectangle(rect.x+5, rect.y, rect.width-10, 5);
2563 screendc.DrawRectangle(rect.x+rect.width-5, rect.y, 5, rect.height);
2564 screendc.DrawRectangle(rect.x+5, rect.y+rect.height-5, rect.width-10, 5);
2565 }
2566
2567 void wxFrameManager::HideHint()
2568 {
2569 // hides a transparent window hint, if there is one
2570 if (m_hint_wnd)
2571 {
2572 MakeWindowTransparent(m_hint_wnd, 0);
2573 m_hint_fadetimer.Stop();
2574 m_last_hint = wxRect();
2575 return;
2576 }
2577
2578 // hides a painted hint by redrawing the frame window
2579 if (!m_last_hint.IsEmpty())
2580 {
2581 m_frame->Refresh();
2582 m_frame->Update();
2583 m_last_hint = wxRect();
2584 }
2585 }
2586
2587
2588
2589 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2590 // determine the exact position the pane would be at were if dropped. If
2591 // the pame would indeed become docked at the specified drop point,
2592 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2593 // "pane_window" is the window pointer of the pane being dragged, pt is
2594 // the mouse position, in client coordinates
2595 void wxFrameManager::DrawHintRect(wxWindow* pane_window,
2596 const wxPoint& pt,
2597 const wxPoint& offset)
2598 {
2599 wxRect rect;
2600
2601 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2602 // we will create a new temporary layout and then measure the resulting
2603 // rectangle; we will create a copy of the docking structures (m_dock)
2604 // so that we don't modify the real thing on screen
2605
2606 int i, pane_count, part_count;
2607 wxDockInfoArray docks;
2608 wxPaneInfoArray panes;
2609 wxDockUIPartArray uiparts;
2610 wxPaneInfo hint = GetPane(pane_window);
2611 hint.name = wxT("__HINT__");
2612
2613 if (!hint.IsOk())
2614 return;
2615
2616 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
2617
2618 // remove any pane already there which bears the same window;
2619 // this happens when you are moving a pane around in a dock
2620 for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
2621 {
2622 if (panes.Item(i).window == pane_window)
2623 {
2624 RemovePaneFromDocks(docks, panes.Item(i));
2625 panes.RemoveAt(i);
2626 break;
2627 }
2628 }
2629
2630 // find out where the new pane would be
2631 if (!DoDrop(docks, panes, hint, pt, offset))
2632 {
2633 HideHint();
2634 return;
2635 }
2636
2637 panes.Add(hint);
2638
2639 wxSizer* sizer = LayoutAll(panes, docks, uiparts, true);
2640 wxSize client_size = m_frame->GetClientSize();
2641 sizer->SetDimension(0, 0, client_size.x, client_size.y);
2642 sizer->Layout();
2643
2644 for (i = 0, part_count = uiparts.GetCount();
2645 i < part_count; ++i)
2646 {
2647 wxDockUIPart& part = uiparts.Item(i);
2648
2649 if (part.type == wxDockUIPart::typePaneBorder &&
2650 part.pane && part.pane->name == wxT("__HINT__"))
2651 {
2652 rect = wxRect(part.sizer_item->GetPosition(),
2653 part.sizer_item->GetSize());
2654 break;
2655 }
2656 }
2657
2658 delete sizer;
2659
2660 if (rect.IsEmpty())
2661 {
2662 HideHint();
2663 return;
2664 }
2665
2666 // actually show the hint rectangle on the screen
2667 m_frame->ClientToScreen(&rect.x, &rect.y);
2668 ShowHint(rect);
2669 }
2670
2671 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow* wnd)
2672 {
2673 // try to find the pane
2674 wxPaneInfo& pane = GetPane(wnd);
2675 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
2676
2677 if (m_flags & wxAUI_MGR_TRANSPARENT_DRAG)
2678 MakeWindowTransparent(pane.frame, 150);
2679 }
2680
2681 void wxFrameManager::OnFloatingPaneMoving(wxWindow* wnd)
2682 {
2683 // try to find the pane
2684 wxPaneInfo& pane = GetPane(wnd);
2685 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
2686
2687 wxPoint pt = ::wxGetMousePosition();
2688 wxPoint client_pt = m_frame->ScreenToClient(pt);
2689
2690 // calculate the offset from the upper left-hand corner
2691 // of the frame to the mouse pointer
2692 wxPoint frame_pos = pane.frame->GetPosition();
2693 wxPoint action_offset(pt.x-frame_pos.x, pt.y-frame_pos.y);
2694
2695 // no hint for toolbar floating windows
2696 if (pane.IsToolbar() && m_action == actionDragFloatingPane)
2697 {
2698 if (m_action == actionDragFloatingPane)
2699 {
2700 wxDockInfoArray docks;
2701 wxPaneInfoArray panes;
2702 wxDockUIPartArray uiparts;
2703 wxPaneInfo hint = pane;
2704
2705 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
2706
2707 // find out where the new pane would be
2708 if (!DoDrop(docks, panes, hint, client_pt))
2709 return;
2710 if (hint.IsFloating())
2711 return;
2712
2713 pane = hint;
2714 m_action = actionDragToolbarPane;
2715 m_action_window = pane.window;
2716
2717 Update();
2718 }
2719
2720 return;
2721 }
2722
2723
2724 // if a key modifier is pressed while dragging the frame,
2725 // don't dock the window
2726 if (wxGetKeyState(WXK_CONTROL) || wxGetKeyState(WXK_ALT))
2727 {
2728 HideHint();
2729 return;
2730 }
2731
2732
2733 DrawHintRect(wnd, client_pt, action_offset);
2734
2735 #ifdef __WXGTK__
2736 // this cleans up some screen artifacts that are caused on GTK because
2737 // we aren't getting the exact size of the window (see comment
2738 // in DrawHintRect)
2739 //Refresh();
2740 #endif
2741
2742
2743 // reduces flicker
2744 m_frame->Update();
2745 }
2746
2747 void wxFrameManager::OnFloatingPaneMoved(wxWindow* wnd)
2748 {
2749 // try to find the pane
2750 wxPaneInfo& pane = GetPane(wnd);
2751 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
2752
2753 wxPoint pt = ::wxGetMousePosition();
2754 wxPoint client_pt = m_frame->ScreenToClient(pt);
2755
2756 // calculate the offset from the upper left-hand corner
2757 // of the frame to the mouse pointer
2758 wxPoint frame_pos = pane.frame->GetPosition();
2759 wxPoint action_offset(pt.x-frame_pos.x, pt.y-frame_pos.y);
2760
2761
2762 // if a key modifier is pressed while dragging the frame,
2763 // don't dock the window
2764 if (wxGetKeyState(WXK_CONTROL) || wxGetKeyState(WXK_ALT))
2765 {
2766 HideHint();
2767 return;
2768 }
2769
2770
2771 // do the drop calculation
2772 DoDrop(m_docks, m_panes, pane, client_pt, action_offset);
2773
2774 // if the pane is still floating, update it's floating
2775 // position (that we store)
2776 if (pane.IsFloating())
2777 {
2778 pane.floating_pos = pane.frame->GetPosition();
2779
2780 if (m_flags & wxAUI_MGR_TRANSPARENT_DRAG)
2781 MakeWindowTransparent(pane.frame, 255);
2782 }
2783
2784 Update();
2785
2786 HideHint();
2787 }
2788
2789 void wxFrameManager::OnFloatingPaneResized(wxWindow* wnd, const wxSize& size)
2790 {
2791 // try to find the pane
2792 wxPaneInfo& pane = GetPane(wnd);
2793 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
2794
2795 pane.floating_size = size;
2796 }
2797
2798
2799 void wxFrameManager::OnFloatingPaneClosed(wxWindow* wnd, wxCloseEvent& evt)
2800 {
2801 // try to find the pane
2802 wxPaneInfo& pane = GetPane(wnd);
2803 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
2804
2805
2806 // fire pane close event
2807 wxFrameManagerEvent e(wxEVT_AUI_PANECLOSE);
2808 e.SetPane(&pane);
2809 e.SetCanVeto(evt.CanVeto());
2810 ProcessMgrEvent(e);
2811
2812 if (e.GetVeto())
2813 {
2814 evt.Veto();
2815 return;
2816 }
2817 else
2818 {
2819 // reparent the pane window back to us and
2820 // prepare the frame window for destruction
2821 pane.window->Show(false);
2822 pane.window->Reparent(m_frame);
2823 pane.frame = NULL;
2824 pane.Hide();
2825 }
2826 }
2827
2828
2829
2830 void wxFrameManager::OnFloatingPaneActivated(wxWindow* wnd)
2831 {
2832 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
2833 {
2834 // try to find the pane
2835 wxASSERT_MSG(GetPane(wnd).IsOk(), wxT("Pane window not found"));
2836
2837 SetActivePane(m_panes, wnd);
2838 Repaint();
2839 }
2840 }
2841
2842 // Render() draws all of the pane captions, sashes,
2843 // backgrounds, captions, grippers, pane borders and buttons.
2844 // It renders the entire user interface.
2845
2846 void wxFrameManager::Render(wxDC* dc)
2847 {
2848 #ifdef __WXMAC__
2849 dc->Clear() ;
2850 #endif
2851 int i, part_count;
2852 for (i = 0, part_count = m_uiparts.GetCount();
2853 i < part_count; ++i)
2854 {
2855 wxDockUIPart& part = m_uiparts.Item(i);
2856
2857 // don't draw hidden pane items
2858 if (part.sizer_item && !part.sizer_item->IsShown())
2859 continue;
2860
2861 switch (part.type)
2862 {
2863 case wxDockUIPart::typeDockSizer:
2864 case wxDockUIPart::typePaneSizer:
2865 m_art->DrawSash(*dc, part.orientation, part.rect);
2866 break;
2867 case wxDockUIPart::typeBackground:
2868 m_art->DrawBackground(*dc, part.orientation, part.rect);
2869 break;
2870 case wxDockUIPart::typeCaption:
2871 m_art->DrawCaption(*dc, part.pane->caption, part.rect, *part.pane);
2872 break;
2873 case wxDockUIPart::typeGripper:
2874 m_art->DrawGripper(*dc, part.rect, *part.pane);
2875 break;
2876 case wxDockUIPart::typePaneBorder:
2877 m_art->DrawBorder(*dc, part.rect, *part.pane);
2878 break;
2879 case wxDockUIPart::typePaneButton:
2880 m_art->DrawPaneButton(*dc, part.button->button_id,
2881 wxAUI_BUTTON_STATE_NORMAL, part.rect, *part.pane);
2882 break;
2883 }
2884 }
2885 }
2886
2887 void wxFrameManager::Repaint(wxDC* dc)
2888 {
2889 #ifdef __WXMAC__
2890 if ( dc == NULL )
2891 {
2892 m_frame->Refresh() ;
2893 m_frame->Update() ;
2894 return ;
2895 }
2896 #endif
2897 int w, h;
2898 m_frame->GetClientSize(&w, &h);
2899
2900 // figure out which dc to use; if one
2901 // has been specified, use it, otherwise
2902 // make a client dc
2903 wxClientDC* client_dc = NULL;
2904 if (!dc)
2905 {
2906 client_dc = new wxClientDC(m_frame);
2907 dc = client_dc;
2908 }
2909
2910 // if the frame has a toolbar, the client area
2911 // origin will not be (0,0).
2912 wxPoint pt = m_frame->GetClientAreaOrigin();
2913 if (pt.x != 0 || pt.y != 0)
2914 dc->SetDeviceOrigin(pt.x, pt.y);
2915
2916 // render all the items
2917 Render(dc);
2918
2919 // if we created a client_dc, delete it
2920 if (client_dc)
2921 delete client_dc;
2922 }
2923
2924 void wxFrameManager::OnPaint(wxPaintEvent& WXUNUSED(event))
2925 {
2926 wxPaintDC dc(m_frame);
2927 Repaint(&dc);
2928 }
2929
2930 void wxFrameManager::OnEraseBackground(wxEraseEvent& event)
2931 {
2932 #ifdef __WXMAC__
2933 event.Skip() ;
2934 #else
2935 wxUnusedVar(event);
2936 #endif
2937 }
2938
2939 void wxFrameManager::OnSize(wxSizeEvent& WXUNUSED(event))
2940 {
2941 if (m_frame)
2942 {
2943 DoFrameLayout();
2944 Repaint();
2945 }
2946 }
2947
2948
2949 void wxFrameManager::OnSetCursor(wxSetCursorEvent& event)
2950 {
2951 // determine cursor
2952 wxDockUIPart* part = HitTest(event.GetX(), event.GetY());
2953 wxCursor cursor = wxNullCursor;
2954
2955 if (part)
2956 {
2957 if (part->type == wxDockUIPart::typeDockSizer ||
2958 part->type == wxDockUIPart::typePaneSizer)
2959 {
2960 // a dock may not be resized if it has a single
2961 // pane which is not resizable
2962 if (part->type == wxDockUIPart::typeDockSizer && part->dock &&
2963 part->dock->panes.GetCount() == 1 &&
2964 part->dock->panes.Item(0)->IsFixed())
2965 return;
2966
2967 // panes that may not be resized do not get a sizing cursor
2968 if (part->pane && part->pane->IsFixed())
2969 return;
2970
2971 if (part->orientation == wxVERTICAL)
2972 cursor = wxCursor(wxCURSOR_SIZEWE);
2973 else
2974 cursor = wxCursor(wxCURSOR_SIZENS);
2975 }
2976 else if (part->type == wxDockUIPart::typeGripper)
2977 {
2978 cursor = wxCursor(wxCURSOR_SIZING);
2979 }
2980 }
2981
2982 event.SetCursor(cursor);
2983 }
2984
2985
2986
2987 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart* button_ui_part,
2988 const wxMouseEvent& event)
2989 {
2990 wxDockUIPart* hit_test = HitTest(event.GetX(), event.GetY());
2991
2992 int state = wxAUI_BUTTON_STATE_NORMAL;
2993
2994 if (hit_test == button_ui_part)
2995 {
2996 if (event.LeftDown())
2997 state = wxAUI_BUTTON_STATE_PRESSED;
2998 else
2999 state = wxAUI_BUTTON_STATE_HOVER;
3000 }
3001 else
3002 {
3003 if (event.LeftDown())
3004 state = wxAUI_BUTTON_STATE_HOVER;
3005 }
3006
3007 // now repaint the button with hover state
3008 wxClientDC cdc(m_frame);
3009
3010 // if the frame has a toolbar, the client area
3011 // origin will not be (0,0).
3012 wxPoint pt = m_frame->GetClientAreaOrigin();
3013 if (pt.x != 0 || pt.y != 0)
3014 cdc.SetDeviceOrigin(pt.x, pt.y);
3015
3016 m_art->DrawPaneButton(cdc,
3017 button_ui_part->button->button_id,
3018 state,
3019 button_ui_part->rect,
3020 *hit_test->pane);
3021 }
3022
3023 void wxFrameManager::OnLeftDown(wxMouseEvent& event)
3024 {
3025 wxDockUIPart* part = HitTest(event.GetX(), event.GetY());
3026 if (part)
3027 {
3028 if (part->dock && part->dock->dock_direction == wxAUI_DOCK_CENTER)
3029 return;
3030
3031 if (part->type == wxDockUIPart::typeDockSizer ||
3032 part->type == wxDockUIPart::typePaneSizer)
3033 {
3034 // a dock may not be resized if it has a single
3035 // pane which is not resizable
3036 if (part->type == wxDockUIPart::typeDockSizer && part->dock &&
3037 part->dock->panes.GetCount() == 1 &&
3038 part->dock->panes.Item(0)->IsFixed())
3039 return;
3040
3041 // panes that may not be resized should be ignored here
3042 if (part->pane && part->pane->IsFixed())
3043 return;
3044
3045 m_action = actionResize;
3046 m_action_part = part;
3047 m_action_hintrect = wxRect();
3048 m_action_start = wxPoint(event.m_x, event.m_y);
3049 m_action_offset = wxPoint(event.m_x - part->rect.x,
3050 event.m_y - part->rect.y);
3051 m_frame->CaptureMouse();
3052 }
3053 else if (part->type == wxDockUIPart::typePaneButton)
3054 {
3055 m_action = actionClickButton;
3056 m_action_part = part;
3057 m_action_start = wxPoint(event.m_x, event.m_y);
3058 m_frame->CaptureMouse();
3059
3060 UpdateButtonOnScreen(part, event);
3061 }
3062 else if (part->type == wxDockUIPart::typeCaption ||
3063 part->type == wxDockUIPart::typeGripper)
3064 {
3065 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
3066 {
3067 // set the caption as active
3068 SetActivePane(m_panes, part->pane->window);
3069 Repaint();
3070 }
3071
3072 m_action = actionClickCaption;
3073 m_action_part = part;
3074 m_action_start = wxPoint(event.m_x, event.m_y);
3075 m_action_offset = wxPoint(event.m_x - part->rect.x,
3076 event.m_y - part->rect.y);
3077 m_frame->CaptureMouse();
3078 }
3079 #ifdef __WXMAC__
3080 else
3081 {
3082 event.Skip();
3083 }
3084 #endif
3085 }
3086 #ifdef __WXMAC__
3087 else
3088 {
3089 event.Skip();
3090 }
3091 #else
3092 event.Skip();
3093 #endif
3094 }
3095
3096
3097 void wxFrameManager::OnLeftUp(wxMouseEvent& event)
3098 {
3099 if (m_action == actionResize)
3100 {
3101 m_frame->ReleaseMouse();
3102
3103 // get rid of the hint rectangle
3104 wxScreenDC dc;
3105 DrawResizeHint(dc, m_action_hintrect);
3106
3107 // resize the dock or the pane
3108 if (m_action_part && m_action_part->type==wxDockUIPart::typeDockSizer)
3109 {
3110 wxRect& rect = m_action_part->dock->rect;
3111
3112 wxPoint new_pos(event.m_x - m_action_offset.x,
3113 event.m_y - m_action_offset.y);
3114
3115 switch (m_action_part->dock->dock_direction)
3116 {
3117 case wxAUI_DOCK_LEFT:
3118 m_action_part->dock->size = new_pos.x - rect.x;
3119 break;
3120 case wxAUI_DOCK_TOP:
3121 m_action_part->dock->size = new_pos.y - rect.y;
3122 break;
3123 case wxAUI_DOCK_RIGHT:
3124 m_action_part->dock->size = rect.x + rect.width -
3125 new_pos.x - m_action_part->rect.GetWidth();
3126 break;
3127 case wxAUI_DOCK_BOTTOM:
3128 m_action_part->dock->size = rect.y + rect.height -
3129 new_pos.y - m_action_part->rect.GetHeight();
3130 break;
3131 }
3132
3133 Update();
3134 Repaint(NULL);
3135 }
3136 else if (m_action_part &&
3137 m_action_part->type == wxDockUIPart::typePaneSizer)
3138 {
3139 wxDockInfo& dock = *m_action_part->dock;
3140 wxPaneInfo& pane = *m_action_part->pane;
3141
3142 int total_proportion = 0;
3143 int dock_pixels = 0;
3144 int new_pixsize = 0;
3145
3146 int caption_size = m_art->GetMetric(wxAUI_ART_CAPTION_SIZE);
3147 int pane_border_size = m_art->GetMetric(wxAUI_ART_PANE_BORDER_SIZE);
3148 int sash_size = m_art->GetMetric(wxAUI_ART_SASH_SIZE);
3149
3150 wxPoint new_pos(event.m_x - m_action_offset.x,
3151 event.m_y - m_action_offset.y);
3152
3153 // determine the pane rectangle by getting the pane part
3154 wxDockUIPart* pane_part = GetPanePart(pane.window);
3155 wxASSERT_MSG(pane_part,
3156 wxT("Pane border part not found -- shouldn't happen"));
3157
3158 // determine the new pixel size that the user wants;
3159 // this will help us recalculate the pane's proportion
3160 if (dock.IsHorizontal())
3161 new_pixsize = new_pos.x - pane_part->rect.x;
3162 else
3163 new_pixsize = new_pos.y - pane_part->rect.y;
3164
3165 // determine the size of the dock, based on orientation
3166 if (dock.IsHorizontal())
3167 dock_pixels = dock.rect.GetWidth();
3168 else
3169 dock_pixels = dock.rect.GetHeight();
3170
3171 // determine the total proportion of all resizable panes,
3172 // and the total size of the dock minus the size of all
3173 // the fixed panes
3174 int i, dock_pane_count = dock.panes.GetCount();
3175 int pane_position = -1;
3176 for (i = 0; i < dock_pane_count; ++i)
3177 {
3178 wxPaneInfo& p = *dock.panes.Item(i);
3179 if (p.window == pane.window)
3180 pane_position = i;
3181
3182 // while we're at it, subtract the pane sash
3183 // width from the dock width, because this would
3184 // skew our proportion calculations
3185 if (i > 0)
3186 dock_pixels -= sash_size;
3187
3188 // also, the whole size (including decorations) of
3189 // all fixed panes must also be subtracted, because they
3190 // are not part of the proportion calculation
3191 if (p.IsFixed())
3192 {
3193 if (dock.IsHorizontal())
3194 dock_pixels -= p.best_size.x;
3195 else
3196 dock_pixels -= p.best_size.y;
3197 }
3198 else
3199 {
3200 total_proportion += p.dock_proportion;
3201 }
3202 }
3203
3204 // find a pane in our dock to 'steal' space from or to 'give'
3205 // space to -- this is essentially what is done when a pane is
3206 // resized; the pane should usually be the first non-fixed pane
3207 // to the right of the action pane
3208 int borrow_pane = -1;
3209 for (i = pane_position+1; i < dock_pane_count; ++i)
3210 {
3211 wxPaneInfo& p = *dock.panes.Item(i);
3212 if (!p.IsFixed())
3213 {
3214 borrow_pane = i;
3215 break;
3216 }
3217 }
3218
3219
3220 // demand that the pane being resized is found in this dock
3221 // (this assert really never should be raised)
3222 wxASSERT_MSG(pane_position != -1, wxT("Pane not found in dock"));
3223
3224 // prevent division by zero
3225 if (dock_pixels == 0 || total_proportion == 0 || borrow_pane == -1)
3226 {
3227 m_action = actionNone;
3228 return;
3229 }
3230
3231 // calculate the new proportion of the pane
3232 int new_proportion = (new_pixsize*total_proportion)/dock_pixels;
3233
3234 // default minimum size
3235 int min_size = 0;
3236
3237 // check against the pane's minimum size, if specified. please note
3238 // that this is not enough to ensure that the minimum size will
3239 // not be violated, because the whole frame might later be shrunk,
3240 // causing the size of the pane to violate it's minimum size
3241 if (pane.min_size.IsFullySpecified())
3242 {
3243 min_size = 0;
3244
3245 if (pane.HasBorder())
3246 min_size += (pane_border_size*2);
3247
3248 // calculate minimum size with decorations (border,caption)
3249 if (pane_part->orientation == wxVERTICAL)
3250 {
3251 min_size += pane.min_size.y;
3252 if (pane.HasCaption())
3253 min_size += caption_size;
3254 }
3255 else
3256 {
3257 min_size += pane.min_size.x;
3258 }
3259 }
3260
3261
3262 // for some reason, an arithmatic error somewhere is causing
3263 // the proportion calculations to always be off by 1 pixel;
3264 // for now we will add the 1 pixel on, but we really should
3265 // determine what's causing this.
3266 min_size++;
3267
3268 int min_proportion = (min_size*total_proportion)/dock_pixels;
3269
3270 if (new_proportion < min_proportion)
3271 new_proportion = min_proportion;
3272
3273
3274
3275 int prop_diff = new_proportion - pane.dock_proportion;
3276
3277 // borrow the space from our neighbor pane to the
3278 // right or bottom (depending on orientation)
3279 dock.panes.Item(borrow_pane)->dock_proportion -= prop_diff;
3280 pane.dock_proportion = new_proportion;
3281
3282 // repaint
3283 Update();
3284 Repaint(NULL);
3285 }
3286 }
3287 else if (m_action == actionClickButton)
3288 {
3289 m_hover_button = NULL;
3290 m_frame->ReleaseMouse();
3291 UpdateButtonOnScreen(m_action_part, event);
3292
3293 // make sure we're still over the item that was originally clicked
3294 if (m_action_part == HitTest(event.GetX(), event.GetY()))
3295 {
3296 // fire button-click event
3297 wxFrameManagerEvent e(wxEVT_AUI_PANEBUTTON);
3298 e.SetPane(m_action_part->pane);
3299 e.SetButton(m_action_part->button->button_id);
3300 ProcessMgrEvent(e);
3301 }
3302 }
3303 else if (m_action == actionClickCaption)
3304 {
3305 m_frame->ReleaseMouse();
3306 }
3307 else if (m_action == actionDragFloatingPane)
3308 {
3309 m_frame->ReleaseMouse();
3310 }
3311 else if (m_action == actionDragToolbarPane)
3312 {
3313 m_frame->ReleaseMouse();
3314
3315 wxPaneInfo& pane = GetPane(m_action_window);
3316 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3317
3318 // save the new positions
3319 wxDockInfoPtrArray docks;
3320 FindDocks(m_docks, pane.dock_direction,
3321 pane.dock_layer, pane.dock_row, docks);
3322 if (docks.GetCount() == 1)
3323 {
3324 wxDockInfo& dock = *docks.Item(0);
3325
3326 wxArrayInt pane_positions, pane_sizes;
3327 GetPanePositionsAndSizes(dock, pane_positions, pane_sizes);
3328
3329 int i, dock_pane_count = dock.panes.GetCount();
3330 for (i = 0; i < dock_pane_count; ++i)
3331 dock.panes.Item(i)->dock_pos = pane_positions[i];
3332 }
3333
3334 pane.state &= ~wxPaneInfo::actionPane;
3335 Update();
3336 }
3337 else
3338 {
3339 event.Skip();
3340 }
3341
3342 m_action = actionNone;
3343 m_last_mouse_move = wxPoint(); // see comment in OnMotion()
3344 }
3345
3346
3347 void wxFrameManager::OnMotion(wxMouseEvent& event)
3348 {
3349 // sometimes when Update() is called from inside this method,
3350 // a spurious mouse move event is generated; this check will make
3351 // sure that only real mouse moves will get anywhere in this method;
3352 // this appears to be a bug somewhere, and I don't know where the
3353 // mouse move event is being generated. only verified on MSW
3354
3355 wxPoint mouse_pos = event.GetPosition();
3356 if (m_last_mouse_move == mouse_pos)
3357 return;
3358 m_last_mouse_move = mouse_pos;
3359
3360
3361 if (m_action == actionResize)
3362 {
3363 wxPoint pos = m_action_part->rect.GetPosition();
3364 if (m_action_part->orientation == wxHORIZONTAL)
3365 pos.y = wxMax(0, event.m_y - m_action_offset.y);
3366 else
3367 pos.x = wxMax(0, event.m_x - m_action_offset.x);
3368
3369 wxRect rect(m_frame->ClientToScreen(pos),
3370 m_action_part->rect.GetSize());
3371
3372 wxScreenDC dc;
3373 if (!m_action_hintrect.IsEmpty())
3374 DrawResizeHint(dc, m_action_hintrect);
3375 DrawResizeHint(dc, rect);
3376 m_action_hintrect = rect;
3377 }
3378 else if (m_action == actionClickCaption)
3379 {
3380 int drag_x_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_X);
3381 int drag_y_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_Y);
3382
3383 // caption has been clicked. we need to check if the mouse
3384 // is now being dragged. if it is, we need to change the
3385 // mouse action to 'drag'
3386 if (abs(event.m_x - m_action_start.x) > drag_x_threshold ||
3387 abs(event.m_y - m_action_start.y) > drag_y_threshold)
3388 {
3389 wxPaneInfo* pane_info = m_action_part->pane;
3390
3391 if (!pane_info->IsToolbar())
3392 {
3393 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
3394 pane_info->IsFloatable())
3395 {
3396 m_action = actionDragFloatingPane;
3397
3398 // set initial float position
3399 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
3400 pane_info->floating_pos = wxPoint(pt.x - m_action_offset.x,
3401 pt.y - m_action_offset.y);
3402 // float the window
3403 pane_info->Float();
3404 Update();
3405
3406 m_action_window = pane_info->frame;
3407
3408 // action offset is used here to make it feel "natural" to the user
3409 // to drag a docked pane and suddenly have it become a floating frame.
3410 // Sometimes, however, the offset where the user clicked on the docked
3411 // caption is bigger than the width of the floating frame itself, so
3412 // in that case we need to set the action offset to a sensible value
3413 wxSize frame_size = m_action_window->GetSize();
3414 if (frame_size.x <= m_action_offset.x)
3415 m_action_offset.x = 30;
3416 }
3417 }
3418 else
3419 {
3420 m_action = actionDragToolbarPane;
3421 m_action_window = pane_info->window;
3422 }
3423 }
3424 }
3425 else if (m_action == actionDragFloatingPane)
3426 {
3427 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
3428 m_action_window->Move(pt.x - m_action_offset.x,
3429 pt.y - m_action_offset.y);
3430 }
3431 else if (m_action == actionDragToolbarPane)
3432 {
3433 wxPaneInfo& pane = GetPane(m_action_window);
3434 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3435
3436 pane.state |= wxPaneInfo::actionPane;
3437
3438 wxPoint pt = event.GetPosition();
3439 DoDrop(m_docks, m_panes, pane, pt, m_action_offset);
3440
3441 // if DoDrop() decided to float the pane, set up
3442 // the floating pane's initial position
3443 if (pane.IsFloating())
3444 {
3445 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
3446 pane.floating_pos = wxPoint(pt.x - m_action_offset.x,
3447 pt.y - m_action_offset.y);
3448 }
3449
3450 // this will do the actiual move operation;
3451 // in the case that the pane has been floated,
3452 // this call will create the floating pane
3453 // and do the reparenting
3454 Update();
3455
3456 // if the pane has been floated, change the mouse
3457 // action actionDragFloatingPane so that subsequent
3458 // EVT_MOTION() events will move the floating pane
3459 if (pane.IsFloating())
3460 {
3461 pane.state &= ~wxPaneInfo::actionPane;
3462 m_action = actionDragFloatingPane;
3463 m_action_window = pane.frame;
3464 }
3465 }
3466 else
3467 {
3468 wxDockUIPart* part = HitTest(event.GetX(), event.GetY());
3469 if (part && part->type == wxDockUIPart::typePaneButton)
3470 {
3471 if (part != m_hover_button)
3472 {
3473 // make the old button normal
3474 if (m_hover_button)
3475 UpdateButtonOnScreen(m_hover_button, event);
3476
3477 // mouse is over a button, so repaint the
3478 // button in hover mode
3479 UpdateButtonOnScreen(part, event);
3480 m_hover_button = part;
3481 }
3482 }
3483 else
3484 {
3485 if (m_hover_button)
3486 {
3487 m_hover_button = NULL;
3488 Repaint();
3489 }
3490 else
3491 {
3492 event.Skip();
3493 }
3494 }
3495 }
3496 }
3497
3498 void wxFrameManager::OnLeaveWindow(wxMouseEvent& WXUNUSED(event))
3499 {
3500 if (m_hover_button)
3501 {
3502 m_hover_button = NULL;
3503 Repaint();
3504 }
3505 }
3506
3507 void wxFrameManager::OnChildFocus(wxChildFocusEvent& event)
3508 {
3509 // when a child pane has it's focus set, we should change the
3510 // pane's active state to reflect this. (this is only true if
3511 // active panes are allowed by the owner)
3512 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
3513 {
3514 if (GetPane(event.GetWindow()).IsOk())
3515 {
3516 SetActivePane(m_panes, event.GetWindow());
3517 m_frame->Refresh();
3518 }
3519 }
3520 }
3521
3522
3523 // OnPaneButton() is an event handler that is called
3524 // when a pane button has been pressed.
3525 void wxFrameManager::OnPaneButton(wxFrameManagerEvent& evt)
3526 {
3527 wxASSERT_MSG(evt.pane, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3528
3529 wxPaneInfo& pane = *(evt.pane);
3530
3531 if (evt.button == wxPaneInfo::buttonClose)
3532 {
3533 // fire pane close event
3534 wxFrameManagerEvent e(wxEVT_AUI_PANECLOSE);
3535 e.SetPane(evt.pane);
3536 ProcessMgrEvent(e);
3537
3538 if (!e.GetVeto())
3539 {
3540 pane.Hide();
3541 Update();
3542 }
3543 }
3544 else if (evt.button == wxPaneInfo::buttonPin)
3545 {
3546 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
3547 pane.IsFloatable())
3548 pane.Float();
3549 Update();
3550 }
3551 }
3552
3553 #endif // wxUSE_AUI