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