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