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