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