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