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