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