]> git.saurik.com Git - wxWidgets.git/blob - src/aui/framemanager.cpp
Made toolbars sticky, i.e. you need to drag them
[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 drop.Dock().Bottom().
2341 Row(0).
2342 Position(pt.x - GetDockPixelOffset(drop) - offset.x);
2343 return ProcessDockResult(target, drop);
2344 }
2345
2346 wxDockUIPart* part = HitTest(pt.x, pt.y);
2347
2348
2349 if (drop.IsToolbar())
2350 {
2351 if (!part || !part->dock)
2352 return false;
2353
2354 // calculate the offset from where the dock begins
2355 // to the point where the user dropped the pane
2356 int dock_drop_offset = 0;
2357 if (part->dock->IsHorizontal())
2358 dock_drop_offset = pt.x - part->dock->rect.x - offset.x;
2359 else
2360 dock_drop_offset = pt.y - part->dock->rect.y - offset.y;
2361
2362
2363 // toolbars may only be moved in and to fixed-pane docks,
2364 // otherwise we will try to float the pane. Also, the pane
2365 // should float if being dragged over center pane windows
2366 if (!part->dock->fixed || part->dock->dock_direction == wxAUI_DOCK_CENTER)
2367 {
2368 if (m_last_rect.IsEmpty() || m_last_rect.Inside(pt.x, pt.y ))
2369 {
2370 m_skipping = true;
2371 }
2372 else
2373 {
2374 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
2375 (drop.IsFloatable() ||
2376 (part->dock->dock_direction != wxAUI_DOCK_CENTER &&
2377 part->dock->dock_direction != wxAUI_DOCK_NONE)))
2378 {
2379 drop.Float();
2380 }
2381
2382 m_skipping = false;
2383
2384 return ProcessDockResult(target, drop);
2385 }
2386
2387 drop.Position(pt.x - GetDockPixelOffset(drop) - offset.x);
2388
2389 return ProcessDockResult(target, drop);
2390 }
2391 else
2392 {
2393 m_skipping = false;
2394 }
2395
2396 if (!m_skipping)
2397 {
2398 m_last_rect = part->dock->rect;
2399 m_last_rect.Offset( -10, -10 );
2400 m_last_rect.Inflate( 20, 20 );
2401 }
2402
2403 drop.Dock().
2404 Direction(part->dock->dock_direction).
2405 Layer(part->dock->dock_layer).
2406 Row(part->dock->dock_row).
2407 Position(dock_drop_offset);
2408
2409 if ((
2410 ((pt.y < part->dock->rect.y + 2) && part->dock->IsHorizontal()) ||
2411 ((pt.x < part->dock->rect.x + 2) && part->dock->IsVertical())
2412 ) && part->dock->panes.GetCount() > 1)
2413 {
2414 int row = drop.dock_row;
2415 DoInsertDockRow(panes, part->dock->dock_direction,
2416 part->dock->dock_layer,
2417 part->dock->dock_row);
2418 drop.dock_row = row;
2419 }
2420
2421 if ((
2422 ((pt.y > part->dock->rect.y + part->dock->rect.height - 2 ) && part->dock->IsHorizontal()) ||
2423 ((pt.x > part->dock->rect.x + part->dock->rect.width - 2 ) && part->dock->IsVertical())
2424 ) && part->dock->panes.GetCount() > 1)
2425 {
2426 DoInsertDockRow(panes, part->dock->dock_direction,
2427 part->dock->dock_layer,
2428 part->dock->dock_row+1);
2429 drop.dock_row = part->dock->dock_row+1;
2430 }
2431
2432 return ProcessDockResult(target, drop);
2433 }
2434
2435
2436
2437
2438 if (!part)
2439 return false;
2440
2441 if (part->type == wxDockUIPart::typePaneBorder ||
2442 part->type == wxDockUIPart::typeCaption ||
2443 part->type == wxDockUIPart::typeGripper ||
2444 part->type == wxDockUIPart::typePaneButton ||
2445 part->type == wxDockUIPart::typePane ||
2446 part->type == wxDockUIPart::typePaneSizer ||
2447 part->type == wxDockUIPart::typeDockSizer ||
2448 part->type == wxDockUIPart::typeBackground)
2449 {
2450 if (part->type == wxDockUIPart::typeDockSizer)
2451 {
2452 if (part->dock->panes.GetCount() != 1)
2453 return false;
2454 part = GetPanePart(part->dock->panes.Item(0)->window);
2455 if (!part)
2456 return false;
2457 }
2458
2459
2460
2461 // If a normal frame is being dragged over a toolbar, insert it
2462 // along the edge under the toolbar, but over all other panes.
2463 // (this could be done much better, but somehow factoring this
2464 // calculation with the one at the beginning of this function)
2465 if (part->dock && part->dock->toolbar)
2466 {
2467 int layer = 0;
2468
2469 switch (part->dock->dock_direction)
2470 {
2471 case wxAUI_DOCK_LEFT:
2472 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_LEFT),
2473 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM)),
2474 GetMaxLayer(docks, wxAUI_DOCK_TOP));
2475 break;
2476 case wxAUI_DOCK_TOP:
2477 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_TOP),
2478 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2479 GetMaxLayer(docks, wxAUI_DOCK_RIGHT));
2480 break;
2481 case wxAUI_DOCK_RIGHT:
2482 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_RIGHT),
2483 GetMaxLayer(docks, wxAUI_DOCK_TOP)),
2484 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM));
2485 break;
2486 case wxAUI_DOCK_BOTTOM:
2487 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_BOTTOM),
2488 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2489 GetMaxLayer(docks, wxAUI_DOCK_RIGHT));
2490 break;
2491 }
2492
2493 DoInsertDockRow(panes, part->dock->dock_direction,
2494 layer, 0);
2495 drop.Dock().
2496 Direction(part->dock->dock_direction).
2497 Layer(layer).Row(0).Position(0);
2498 return ProcessDockResult(target, drop);
2499 }
2500
2501
2502 if (!part->pane)
2503 return false;
2504
2505 part = GetPanePart(part->pane->window);
2506 if (!part)
2507 return false;
2508
2509 bool insert_dock_row = false;
2510 int insert_row = part->pane->dock_row;
2511 int insert_dir = part->pane->dock_direction;
2512 int insert_layer = part->pane->dock_layer;
2513
2514 switch (part->pane->dock_direction)
2515 {
2516 case wxAUI_DOCK_TOP:
2517 if (pt.y >= part->rect.y &&
2518 pt.y < part->rect.y+auiInsertRowPixels)
2519 insert_dock_row = true;
2520 break;
2521 case wxAUI_DOCK_BOTTOM:
2522 if (pt.y > part->rect.y+part->rect.height-auiInsertRowPixels &&
2523 pt.y <= part->rect.y + part->rect.height)
2524 insert_dock_row = true;
2525 break;
2526 case wxAUI_DOCK_LEFT:
2527 if (pt.x >= part->rect.x &&
2528 pt.x < part->rect.x+auiInsertRowPixels)
2529 insert_dock_row = true;
2530 break;
2531 case wxAUI_DOCK_RIGHT:
2532 if (pt.x > part->rect.x+part->rect.width-auiInsertRowPixels &&
2533 pt.x <= part->rect.x+part->rect.width)
2534 insert_dock_row = true;
2535 break;
2536 case wxAUI_DOCK_CENTER:
2537 {
2538 // "new row pixels" will be set to the default, but
2539 // must never exceed 20% of the window size
2540 int new_row_pixels_x = auiNewRowPixels;
2541 int new_row_pixels_y = auiNewRowPixels;
2542
2543 if (new_row_pixels_x > (part->rect.width*20)/100)
2544 new_row_pixels_x = (part->rect.width*20)/100;
2545
2546 if (new_row_pixels_y > (part->rect.height*20)/100)
2547 new_row_pixels_y = (part->rect.height*20)/100;
2548
2549
2550 // determine if the mouse pointer is in a location that
2551 // will cause a new row to be inserted. The hot spot positions
2552 // are along the borders of the center pane
2553
2554 insert_layer = 0;
2555 insert_dock_row = true;
2556 if (pt.x >= part->rect.x &&
2557 pt.x < part->rect.x+new_row_pixels_x)
2558 insert_dir = wxAUI_DOCK_LEFT;
2559 else
2560 if (pt.y >= part->rect.y &&
2561 pt.y < part->rect.y+new_row_pixels_y)
2562 insert_dir = wxAUI_DOCK_TOP;
2563 else
2564 if (pt.x >= part->rect.x + part->rect.width-new_row_pixels_x &&
2565 pt.x < part->rect.x + part->rect.width)
2566 insert_dir = wxAUI_DOCK_RIGHT;
2567 else
2568 if (pt.y >= part->rect.y+ part->rect.height-new_row_pixels_y &&
2569 pt.y < part->rect.y + part->rect.height)
2570 insert_dir = wxAUI_DOCK_BOTTOM;
2571 else
2572 return false;
2573
2574 insert_row = GetMaxRow(panes, insert_dir, insert_layer) + 1;
2575 }
2576 }
2577
2578 if (insert_dock_row)
2579 {
2580 DoInsertDockRow(panes, insert_dir, insert_layer, insert_row);
2581 drop.Dock().Direction(insert_dir).
2582 Layer(insert_layer).
2583 Row(insert_row).
2584 Position(0);
2585 return ProcessDockResult(target, drop);
2586 }
2587
2588 // determine the mouse offset and the pane size, both in the
2589 // direction of the dock itself, and perpendicular to the dock
2590
2591 int offset, size;
2592
2593 if (part->orientation == wxVERTICAL)
2594 {
2595 offset = pt.y - part->rect.y;
2596 size = part->rect.GetHeight();
2597 }
2598 else
2599 {
2600 offset = pt.x - part->rect.x;
2601 size = part->rect.GetWidth();
2602 }
2603
2604 int drop_position = part->pane->dock_pos;
2605
2606 // if we are in the top/left part of the pane,
2607 // insert the pane before the pane being hovered over
2608 if (offset <= size/2)
2609 {
2610 drop_position = part->pane->dock_pos;
2611 DoInsertPane(panes,
2612 part->pane->dock_direction,
2613 part->pane->dock_layer,
2614 part->pane->dock_row,
2615 part->pane->dock_pos);
2616 }
2617
2618 // if we are in the bottom/right part of the pane,
2619 // insert the pane before the pane being hovered over
2620 if (offset > size/2)
2621 {
2622 drop_position = part->pane->dock_pos+1;
2623 DoInsertPane(panes,
2624 part->pane->dock_direction,
2625 part->pane->dock_layer,
2626 part->pane->dock_row,
2627 part->pane->dock_pos+1);
2628 }
2629
2630 drop.Dock().
2631 Direction(part->dock->dock_direction).
2632 Layer(part->dock->dock_layer).
2633 Row(part->dock->dock_row).
2634 Position(drop_position);
2635 return ProcessDockResult(target, drop);
2636 }
2637
2638 return false;
2639 }
2640
2641
2642 void wxFrameManager::OnHintFadeTimer(wxTimerEvent& WXUNUSED(event))
2643 {
2644 if (!m_hint_wnd || m_hint_fadeamt >= m_hint_fademax)
2645 {
2646 m_hint_fadetimer.Stop();
2647 return;
2648 }
2649
2650 m_hint_fadeamt += 4;
2651 #if wxCHECK_VERSION(2,7,0)
2652 m_hint_wnd->SetTransparent(m_hint_fadeamt);
2653 #else
2654 if (m_hint_wnd->IsKindOf(CLASSINFO(wxPseudoTransparentFrame)))
2655 ((wxPseudoTransparentFrame *)m_hint_wnd)->SetTransparent(m_hint_fadeamt);
2656 #endif
2657 }
2658
2659 void wxFrameManager::ShowHint(const wxRect& rect)
2660 {
2661 if ((m_flags & wxAUI_MGR_TRANSPARENT_HINT) != 0
2662 && m_hint_wnd
2663 // Finally, don't use a venetian blind effect if it's been specifically disabled
2664 && !((m_hint_wnd->IsKindOf(CLASSINFO(wxPseudoTransparentFrame))) &&
2665 (m_flags & wxAUI_MGR_DISABLE_VENETIAN_BLINDS))
2666 )
2667 {
2668 if (m_last_hint == rect)
2669 return;
2670 m_last_hint = rect;
2671
2672 m_hint_fadeamt = m_hint_fademax;
2673 if ((m_flags & wxAUI_MGR_TRANSPARENT_HINT_FADE)
2674 && !((m_hint_wnd->IsKindOf(CLASSINFO(wxPseudoTransparentFrame))) &&
2675 (m_flags & wxAUI_MGR_DISABLE_VENETIAN_BLINDS_FADE))
2676 )
2677 m_hint_fadeamt = 0;
2678
2679 m_hint_wnd->SetSize(rect);
2680
2681 if (! m_hint_wnd->IsShown())
2682 m_hint_wnd->Show();
2683
2684 // if we are dragging a floating pane, set the focus
2685 // back to that floating pane (otherwise it becomes unfocused)
2686 if (m_action == actionDragFloatingPane && m_action_window)
2687 m_action_window->SetFocus();
2688
2689 #if wxCHECK_VERSION(2,7,0)
2690 m_hint_wnd->SetTransparent(m_hint_fadeamt);
2691 #else
2692 if (m_hint_wnd->IsKindOf(CLASSINFO(wxPseudoTransparentFrame)))
2693 ((wxPseudoTransparentFrame *)m_hint_wnd)->SetTransparent(m_hint_fadeamt);
2694 #endif
2695 m_hint_wnd->Raise();
2696
2697
2698 if (m_hint_fadeamt != m_hint_fademax) // Only fade if we need to
2699 {
2700 // start fade in timer
2701 m_hint_fadetimer.SetOwner(this, 101);
2702 m_hint_fadetimer.Start(5);
2703 }
2704 }
2705
2706 else // Not using a transparent hint window...
2707 {
2708
2709 if (m_last_hint != rect)
2710 {
2711 // remove the last hint rectangle
2712 m_last_hint = rect;
2713 m_frame->Refresh();
2714 m_frame->Update();
2715 }
2716
2717 wxScreenDC screendc;
2718 wxRegion clip(1, 1, 10000, 10000);
2719
2720 // clip all floating windows, so we don't draw over them
2721 int i, pane_count;
2722 for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
2723 {
2724 wxPaneInfo& pane = m_panes.Item(i);
2725
2726 if (pane.IsFloating() &&
2727 pane.frame->IsShown())
2728 {
2729 wxRect rect = pane.frame->GetRect();
2730 #ifdef __WXGTK__
2731 // wxGTK returns the client size, not the whole frame size
2732 rect.width += 15;
2733 rect.height += 35;
2734 rect.Inflate(5);
2735 #endif
2736
2737 clip.Subtract(rect);
2738 }
2739 }
2740
2741 // As we can only hide the hint by redrawing the managed window, we
2742 // need to clip the region to the managed window too or we get
2743 // nasty redrawn problems.
2744 clip.Intersect(m_frame->GetRect());
2745
2746 screendc.SetClippingRegion(clip);
2747
2748 wxBitmap stipple = wxPaneCreateStippleBitmap();
2749 wxBrush brush(stipple);
2750 screendc.SetBrush(brush);
2751 screendc.SetPen(*wxTRANSPARENT_PEN);
2752
2753 screendc.DrawRectangle(rect.x, rect.y, 5, rect.height);
2754 screendc.DrawRectangle(rect.x+5, rect.y, rect.width-10, 5);
2755 screendc.DrawRectangle(rect.x+rect.width-5, rect.y, 5, rect.height);
2756 screendc.DrawRectangle(rect.x+5, rect.y+rect.height-5, rect.width-10, 5);
2757 }
2758 }
2759
2760 void wxFrameManager::HideHint()
2761 {
2762 // hides a transparent window hint, if there is one
2763 if (m_hint_wnd)
2764 {
2765 if (m_hint_wnd->IsShown())
2766 m_hint_wnd->Show(false);
2767 #if wxCHECK_VERSION(2,7,0)
2768 m_hint_wnd->SetTransparent(0);
2769 #else
2770 if (m_hint_wnd->IsKindOf(CLASSINFO(wxPseudoTransparentFrame)))
2771 ((wxPseudoTransparentFrame *)m_hint_wnd)->SetTransparent(0);
2772 #endif
2773 m_hint_fadetimer.Stop();
2774 m_last_hint = wxRect();
2775 return;
2776 }
2777
2778 // hides a painted hint by redrawing the frame window
2779 if (!m_last_hint.IsEmpty())
2780 {
2781 m_frame->Refresh();
2782 m_frame->Update();
2783 m_last_hint = wxRect();
2784 }
2785 }
2786
2787
2788
2789 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2790 // determine the exact position the pane would be at were if dropped. If
2791 // the pame would indeed become docked at the specified drop point,
2792 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2793 // "pane_window" is the window pointer of the pane being dragged, pt is
2794 // the mouse position, in client coordinates
2795 void wxFrameManager::DrawHintRect(wxWindow* pane_window,
2796 const wxPoint& pt,
2797 const wxPoint& offset)
2798 {
2799 wxRect rect;
2800
2801 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2802 // we will create a new temporary layout and then measure the resulting
2803 // rectangle; we will create a copy of the docking structures (m_dock)
2804 // so that we don't modify the real thing on screen
2805
2806 int i, pane_count, part_count;
2807 wxDockInfoArray docks;
2808 wxPaneInfoArray panes;
2809 wxDockUIPartArray uiparts;
2810 wxPaneInfo hint = GetPane(pane_window);
2811 hint.name = wxT("__HINT__");
2812 hint.Show();
2813
2814 if (!hint.IsOk())
2815 return;
2816
2817 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
2818
2819 // remove any pane already there which bears the same window;
2820 // this happens when you are moving a pane around in a dock
2821 for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
2822 {
2823 if (panes.Item(i).window == pane_window)
2824 {
2825 RemovePaneFromDocks(docks, panes.Item(i));
2826 panes.RemoveAt(i);
2827 break;
2828 }
2829 }
2830
2831 // find out where the new pane would be
2832 if (!DoDrop(docks, panes, hint, pt, offset))
2833 {
2834 HideHint();
2835 return;
2836 }
2837
2838 panes.Add(hint);
2839
2840 wxSizer* sizer = LayoutAll(panes, docks, uiparts, true);
2841 wxSize client_size = m_frame->GetClientSize();
2842 sizer->SetDimension(0, 0, client_size.x, client_size.y);
2843 sizer->Layout();
2844
2845 for (i = 0, part_count = uiparts.GetCount();
2846 i < part_count; ++i)
2847 {
2848 wxDockUIPart& part = uiparts.Item(i);
2849
2850 if (part.type == wxDockUIPart::typePaneBorder &&
2851 part.pane && part.pane->name == wxT("__HINT__"))
2852 {
2853 rect = wxRect(part.sizer_item->GetPosition(),
2854 part.sizer_item->GetSize());
2855 break;
2856 }
2857 }
2858
2859 delete sizer;
2860
2861 if (rect.IsEmpty())
2862 {
2863 HideHint();
2864 return;
2865 }
2866
2867 // actually show the hint rectangle on the screen
2868 m_frame->ClientToScreen(&rect.x, &rect.y);
2869 ShowHint(rect);
2870 }
2871
2872 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow* wnd)
2873 {
2874 // try to find the pane
2875 wxPaneInfo& pane = GetPane(wnd);
2876 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
2877
2878 #if wxCHECK_VERSION(2,7,0)
2879 if (m_flags & wxAUI_MGR_TRANSPARENT_DRAG)
2880 pane.frame->SetTransparent(150);
2881 #endif
2882 }
2883
2884 void wxFrameManager::OnFloatingPaneMoving(wxWindow* wnd, wxDirection dir)
2885 {
2886 // try to find the pane
2887 wxPaneInfo& pane = GetPane(wnd);
2888 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
2889
2890 wxPoint pt = ::wxGetMousePosition();
2891
2892 #if 0
2893 // Adapt pt to direction
2894 if (dir == wxNORTH)
2895 {
2896 // move to pane's upper border
2897 wxPoint pos( 0,0 );
2898 pos = wnd->ClientToScreen( pos );
2899 pt.y = pos.y;
2900 // and some more pixels for the title bar
2901 pt.y -= 5;
2902 } else
2903 if (dir == wxWEST)
2904 {
2905 // move to pane's left border
2906 wxPoint pos( 0,0 );
2907 pos = wnd->ClientToScreen( pos );
2908 pt.x = pos.x;
2909 } else
2910 if (dir == wxEAST)
2911 {
2912 // move to pane's right border
2913 wxPoint pos( wnd->GetSize().x, 0 );
2914 pos = wnd->ClientToScreen( pos );
2915 pt.x = pos.x;
2916 } else
2917 if (dir == wxSOUTH)
2918 {
2919 // move to pane's bottom border
2920 wxPoint pos( 0, wnd->GetSize().y );
2921 pos = wnd->ClientToScreen( pos );
2922 pt.y = pos.y;
2923 }
2924 #endif
2925
2926 wxPoint client_pt = m_frame->ScreenToClient(pt);
2927
2928 // calculate the offset from the upper left-hand corner
2929 // of the frame to the mouse pointer
2930 wxPoint frame_pos = pane.frame->GetPosition();
2931 wxPoint action_offset(pt.x-frame_pos.x, pt.y-frame_pos.y);
2932
2933 // no hint for toolbar floating windows
2934 if (pane.IsToolbar() && m_action == actionDragFloatingPane)
2935 {
2936 if (m_action == actionDragFloatingPane)
2937 {
2938 wxDockInfoArray docks;
2939 wxPaneInfoArray panes;
2940 wxDockUIPartArray uiparts;
2941 wxPaneInfo hint = pane;
2942
2943 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
2944
2945 // find out where the new pane would be
2946 if (!DoDrop(docks, panes, hint, client_pt))
2947 return;
2948 if (hint.IsFloating())
2949 return;
2950
2951 pane = hint;
2952 m_action = actionDragToolbarPane;
2953 m_action_window = pane.window;
2954
2955 Update();
2956 }
2957
2958 return;
2959 }
2960
2961
2962 // if a key modifier is pressed while dragging the frame,
2963 // don't dock the window
2964 if (wxGetKeyState(WXK_CONTROL) || wxGetKeyState(WXK_ALT))
2965 {
2966 HideHint();
2967 return;
2968 }
2969
2970
2971 DrawHintRect(wnd, client_pt, action_offset);
2972
2973 #ifdef __WXGTK__
2974 // this cleans up some screen artifacts that are caused on GTK because
2975 // we aren't getting the exact size of the window (see comment
2976 // in DrawHintRect)
2977 //Refresh();
2978 #endif
2979
2980
2981 // reduces flicker
2982 m_frame->Update();
2983 }
2984
2985 void wxFrameManager::OnFloatingPaneMoved(wxWindow* wnd, wxDirection dir)
2986 {
2987 // try to find the pane
2988 wxPaneInfo& pane = GetPane(wnd);
2989 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
2990
2991 wxPoint pt = ::wxGetMousePosition();
2992
2993 #if 0
2994 // Adapt pt to direction
2995 if (dir == wxNORTH)
2996 {
2997 // move to pane's upper border
2998 wxPoint pos( 0,0 );
2999 pos = wnd->ClientToScreen( pos );
3000 pt.y = pos.y;
3001 // and some more pixels for the title bar
3002 pt.y -= 10;
3003 } else
3004 if (dir == wxWEST)
3005 {
3006 // move to pane's left border
3007 wxPoint pos( 0,0 );
3008 pos = wnd->ClientToScreen( pos );
3009 pt.x = pos.x;
3010 } else
3011 if (dir == wxEAST)
3012 {
3013 // move to pane's right border
3014 wxPoint pos( wnd->GetSize().x, 0 );
3015 pos = wnd->ClientToScreen( pos );
3016 pt.x = pos.x;
3017 } else
3018 if (dir == wxSOUTH)
3019 {
3020 // move to pane's bottom border
3021 wxPoint pos( 0, wnd->GetSize().y );
3022 pos = wnd->ClientToScreen( pos );
3023 pt.y = pos.y;
3024 }
3025 #endif
3026
3027 wxPoint client_pt = m_frame->ScreenToClient(pt);
3028
3029 // calculate the offset from the upper left-hand corner
3030 // of the frame to the mouse pointer
3031 wxPoint frame_pos = pane.frame->GetPosition();
3032 wxPoint action_offset(pt.x-frame_pos.x, pt.y-frame_pos.y);
3033
3034
3035 // if a key modifier is pressed while dragging the frame,
3036 // don't dock the window
3037 if (!wxGetKeyState(WXK_CONTROL) && !wxGetKeyState(WXK_ALT))
3038 {
3039 // do the drop calculation
3040 DoDrop(m_docks, m_panes, pane, client_pt, action_offset);
3041 }
3042
3043 // if the pane is still floating, update it's floating
3044 // position (that we store)
3045 if (pane.IsFloating())
3046 {
3047 pane.floating_pos = pane.frame->GetPosition();
3048
3049 #if wxCHECK_VERSION(2,7,0)
3050 if (m_flags & wxAUI_MGR_TRANSPARENT_DRAG)
3051 pane.frame->SetTransparent(255);
3052 #endif
3053 }
3054
3055 Update();
3056
3057 HideHint();
3058 }
3059
3060 void wxFrameManager::OnFloatingPaneResized(wxWindow* wnd, const wxSize& size)
3061 {
3062 // try to find the pane
3063 wxPaneInfo& pane = GetPane(wnd);
3064 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3065
3066 pane.floating_size = size;
3067 }
3068
3069
3070 void wxFrameManager::OnFloatingPaneClosed(wxWindow* wnd, wxCloseEvent& evt)
3071 {
3072 // try to find the pane
3073 wxPaneInfo& pane = GetPane(wnd);
3074 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3075
3076
3077 // fire pane close event
3078 wxFrameManagerEvent e(wxEVT_AUI_PANECLOSE);
3079 e.SetPane(&pane);
3080 e.SetCanVeto(evt.CanVeto());
3081 ProcessMgrEvent(e);
3082
3083 if (e.GetVeto())
3084 {
3085 evt.Veto();
3086 return;
3087 }
3088 else
3089 {
3090 // reparent the pane window back to us and
3091 // prepare the frame window for destruction
3092 if (pane.window->IsShown())
3093 pane.window->Show(false);
3094 pane.window->Reparent(m_frame);
3095 pane.frame = NULL;
3096 pane.Hide();
3097 }
3098 }
3099
3100
3101
3102 void wxFrameManager::OnFloatingPaneActivated(wxWindow* wnd)
3103 {
3104 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
3105 {
3106 // try to find the pane
3107 wxASSERT_MSG(GetPane(wnd).IsOk(), wxT("Pane window not found"));
3108
3109 SetActivePane(m_panes, wnd);
3110 Repaint();
3111 }
3112 }
3113
3114 // OnRender() draws all of the pane captions, sashes,
3115 // backgrounds, captions, grippers, pane borders and buttons.
3116 // It renders the entire user interface.
3117
3118 void wxFrameManager::OnRender(wxFrameManagerEvent& evt)
3119 {
3120 wxDC* dc = evt.GetDC();
3121
3122 #ifdef __WXMAC__
3123 dc->Clear() ;
3124 #endif
3125 int i, part_count;
3126 for (i = 0, part_count = m_uiparts.GetCount();
3127 i < part_count; ++i)
3128 {
3129 wxDockUIPart& part = m_uiparts.Item(i);
3130
3131 // don't draw hidden pane items
3132 if (part.sizer_item && !part.sizer_item->IsShown())
3133 continue;
3134
3135 switch (part.type)
3136 {
3137 case wxDockUIPart::typeDockSizer:
3138 case wxDockUIPart::typePaneSizer:
3139 m_art->DrawSash(*dc, part.orientation, part.rect);
3140 break;
3141 case wxDockUIPart::typeBackground:
3142 m_art->DrawBackground(*dc, part.orientation, part.rect);
3143 break;
3144 case wxDockUIPart::typeCaption:
3145 m_art->DrawCaption(*dc, part.pane->caption, part.rect, *part.pane);
3146 break;
3147 case wxDockUIPart::typeGripper:
3148 m_art->DrawGripper(*dc, part.rect, *part.pane);
3149 break;
3150 case wxDockUIPart::typePaneBorder:
3151 m_art->DrawBorder(*dc, part.rect, *part.pane);
3152 break;
3153 case wxDockUIPart::typePaneButton:
3154 m_art->DrawPaneButton(*dc, part.button->button_id,
3155 wxAUI_BUTTON_STATE_NORMAL, part.rect, *part.pane);
3156 break;
3157 }
3158 }
3159 }
3160
3161
3162 // Render() fire a render event, which is normally handled by
3163 // wxFrameManager::OnRender(). This allows the render function to
3164 // be overridden via the render event. This can be useful for paintin
3165 // custom graphics in the main window. Default behavior can be
3166 // invoked in the overridden function by calling OnRender()
3167
3168 void wxFrameManager::Render(wxDC* dc)
3169 {
3170 wxFrameManagerEvent e(wxEVT_AUI_RENDER);
3171 e.SetDC(dc);
3172 ProcessMgrEvent(e);
3173 }
3174
3175 void wxFrameManager::Repaint(wxDC* dc)
3176 {
3177 #ifdef __WXMAC__
3178 if ( dc == NULL )
3179 {
3180 m_frame->Refresh() ;
3181 m_frame->Update() ;
3182 return ;
3183 }
3184 #endif
3185 int w, h;
3186 m_frame->GetClientSize(&w, &h);
3187
3188 // figure out which dc to use; if one
3189 // has been specified, use it, otherwise
3190 // make a client dc
3191 wxClientDC* client_dc = NULL;
3192 if (!dc)
3193 {
3194 client_dc = new wxClientDC(m_frame);
3195 dc = client_dc;
3196 }
3197
3198 // if the frame has a toolbar, the client area
3199 // origin will not be (0,0).
3200 wxPoint pt = m_frame->GetClientAreaOrigin();
3201 if (pt.x != 0 || pt.y != 0)
3202 dc->SetDeviceOrigin(pt.x, pt.y);
3203
3204 // render all the items
3205 Render(dc);
3206
3207 // if we created a client_dc, delete it
3208 if (client_dc)
3209 delete client_dc;
3210 }
3211
3212 void wxFrameManager::OnPaint(wxPaintEvent& WXUNUSED(event))
3213 {
3214 wxPaintDC dc(m_frame);
3215 Repaint(&dc);
3216 }
3217
3218 void wxFrameManager::OnEraseBackground(wxEraseEvent& event)
3219 {
3220 #ifdef __WXMAC__
3221 event.Skip() ;
3222 #else
3223 wxUnusedVar(event);
3224 #endif
3225 }
3226
3227 void wxFrameManager::OnSize(wxSizeEvent& event)
3228 {
3229 if (m_frame)
3230 {
3231 DoFrameLayout();
3232 Repaint();
3233 }
3234 event.Skip();
3235 }
3236
3237
3238 void wxFrameManager::OnSetCursor(wxSetCursorEvent& event)
3239 {
3240 // determine cursor
3241 wxDockUIPart* part = HitTest(event.GetX(), event.GetY());
3242 wxCursor cursor = wxNullCursor;
3243
3244 if (part)
3245 {
3246 if (part->type == wxDockUIPart::typeDockSizer ||
3247 part->type == wxDockUIPart::typePaneSizer)
3248 {
3249 // a dock may not be resized if it has a single
3250 // pane which is not resizable
3251 if (part->type == wxDockUIPart::typeDockSizer && part->dock &&
3252 part->dock->panes.GetCount() == 1 &&
3253 part->dock->panes.Item(0)->IsFixed())
3254 return;
3255
3256 // panes that may not be resized do not get a sizing cursor
3257 if (part->pane && part->pane->IsFixed())
3258 return;
3259
3260 if (part->orientation == wxVERTICAL)
3261 cursor = wxCursor(wxCURSOR_SIZEWE);
3262 else
3263 cursor = wxCursor(wxCURSOR_SIZENS);
3264 }
3265 else if (part->type == wxDockUIPart::typeGripper)
3266 {
3267 cursor = wxCursor(wxCURSOR_SIZING);
3268 }
3269 }
3270
3271 event.SetCursor(cursor);
3272 }
3273
3274
3275
3276 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart* button_ui_part,
3277 const wxMouseEvent& event)
3278 {
3279 wxDockUIPart* hit_test = HitTest(event.GetX(), event.GetY());
3280
3281 int state = wxAUI_BUTTON_STATE_NORMAL;
3282
3283 if (hit_test == button_ui_part)
3284 {
3285 if (event.LeftDown())
3286 state = wxAUI_BUTTON_STATE_PRESSED;
3287 else
3288 state = wxAUI_BUTTON_STATE_HOVER;
3289 }
3290 else
3291 {
3292 if (event.LeftDown())
3293 state = wxAUI_BUTTON_STATE_HOVER;
3294 }
3295
3296 // now repaint the button with hover state
3297 wxClientDC cdc(m_frame);
3298
3299 // if the frame has a toolbar, the client area
3300 // origin will not be (0,0).
3301 wxPoint pt = m_frame->GetClientAreaOrigin();
3302 if (pt.x != 0 || pt.y != 0)
3303 cdc.SetDeviceOrigin(pt.x, pt.y);
3304
3305 m_art->DrawPaneButton(cdc,
3306 button_ui_part->button->button_id,
3307 state,
3308 button_ui_part->rect,
3309 *hit_test->pane);
3310 }
3311
3312 void wxFrameManager::OnLeftDown(wxMouseEvent& event)
3313 {
3314 wxDockUIPart* part = HitTest(event.GetX(), event.GetY());
3315 if (part)
3316 {
3317 if (part->dock && part->dock->dock_direction == wxAUI_DOCK_CENTER)
3318 return;
3319
3320 if (part->type == wxDockUIPart::typeDockSizer ||
3321 part->type == wxDockUIPart::typePaneSizer)
3322 {
3323 // a dock may not be resized if it has a single
3324 // pane which is not resizable
3325 if (part->type == wxDockUIPart::typeDockSizer && part->dock &&
3326 part->dock->panes.GetCount() == 1 &&
3327 part->dock->panes.Item(0)->IsFixed())
3328 return;
3329
3330 // panes that may not be resized should be ignored here
3331 if (part->pane && part->pane->IsFixed())
3332 return;
3333
3334 m_action = actionResize;
3335 m_action_part = part;
3336 m_action_hintrect = wxRect();
3337 m_action_start = wxPoint(event.m_x, event.m_y);
3338 m_action_offset = wxPoint(event.m_x - part->rect.x,
3339 event.m_y - part->rect.y);
3340 m_frame->CaptureMouse();
3341 }
3342 else if (part->type == wxDockUIPart::typePaneButton)
3343 {
3344 m_action = actionClickButton;
3345 m_action_part = part;
3346 m_action_start = wxPoint(event.m_x, event.m_y);
3347 m_frame->CaptureMouse();
3348
3349 UpdateButtonOnScreen(part, event);
3350 }
3351 else if (part->type == wxDockUIPart::typeCaption ||
3352 part->type == wxDockUIPart::typeGripper)
3353 {
3354 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
3355 {
3356 // set the caption as active
3357 SetActivePane(m_panes, part->pane->window);
3358 Repaint();
3359 }
3360
3361 m_action = actionClickCaption;
3362 m_action_part = part;
3363 m_action_start = wxPoint(event.m_x, event.m_y);
3364 m_action_offset = wxPoint(event.m_x - part->rect.x,
3365 event.m_y - part->rect.y);
3366 m_frame->CaptureMouse();
3367 }
3368 #ifdef __WXMAC__
3369 else
3370 {
3371 event.Skip();
3372 }
3373 #endif
3374 }
3375 #ifdef __WXMAC__
3376 else
3377 {
3378 event.Skip();
3379 }
3380 #else
3381 event.Skip();
3382 #endif
3383 }
3384
3385
3386 void wxFrameManager::OnLeftUp(wxMouseEvent& event)
3387 {
3388 if (m_action == actionResize)
3389 {
3390 m_frame->ReleaseMouse();
3391
3392 // get rid of the hint rectangle
3393 wxScreenDC dc;
3394 DrawResizeHint(dc, m_action_hintrect);
3395
3396 // resize the dock or the pane
3397 if (m_action_part && m_action_part->type==wxDockUIPart::typeDockSizer)
3398 {
3399 wxRect& rect = m_action_part->dock->rect;
3400
3401 wxPoint new_pos(event.m_x - m_action_offset.x,
3402 event.m_y - m_action_offset.y);
3403
3404 switch (m_action_part->dock->dock_direction)
3405 {
3406 case wxAUI_DOCK_LEFT:
3407 m_action_part->dock->size = new_pos.x - rect.x;
3408 break;
3409 case wxAUI_DOCK_TOP:
3410 m_action_part->dock->size = new_pos.y - rect.y;
3411 break;
3412 case wxAUI_DOCK_RIGHT:
3413 m_action_part->dock->size = rect.x + rect.width -
3414 new_pos.x - m_action_part->rect.GetWidth();
3415 break;
3416 case wxAUI_DOCK_BOTTOM:
3417 m_action_part->dock->size = rect.y + rect.height -
3418 new_pos.y - m_action_part->rect.GetHeight();
3419 break;
3420 }
3421
3422 Update();
3423 Repaint(NULL);
3424 }
3425 else if (m_action_part &&
3426 m_action_part->type == wxDockUIPart::typePaneSizer)
3427 {
3428 wxDockInfo& dock = *m_action_part->dock;
3429 wxPaneInfo& pane = *m_action_part->pane;
3430
3431 int total_proportion = 0;
3432 int dock_pixels = 0;
3433 int new_pixsize = 0;
3434
3435 int caption_size = m_art->GetMetric(wxAUI_ART_CAPTION_SIZE);
3436 int pane_border_size = m_art->GetMetric(wxAUI_ART_PANE_BORDER_SIZE);
3437 int sash_size = m_art->GetMetric(wxAUI_ART_SASH_SIZE);
3438
3439 wxPoint new_pos(event.m_x - m_action_offset.x,
3440 event.m_y - m_action_offset.y);
3441
3442 // determine the pane rectangle by getting the pane part
3443 wxDockUIPart* pane_part = GetPanePart(pane.window);
3444 wxASSERT_MSG(pane_part,
3445 wxT("Pane border part not found -- shouldn't happen"));
3446
3447 // determine the new pixel size that the user wants;
3448 // this will help us recalculate the pane's proportion
3449 if (dock.IsHorizontal())
3450 new_pixsize = new_pos.x - pane_part->rect.x;
3451 else
3452 new_pixsize = new_pos.y - pane_part->rect.y;
3453
3454 // determine the size of the dock, based on orientation
3455 if (dock.IsHorizontal())
3456 dock_pixels = dock.rect.GetWidth();
3457 else
3458 dock_pixels = dock.rect.GetHeight();
3459
3460 // determine the total proportion of all resizable panes,
3461 // and the total size of the dock minus the size of all
3462 // the fixed panes
3463 int i, dock_pane_count = dock.panes.GetCount();
3464 int pane_position = -1;
3465 for (i = 0; i < dock_pane_count; ++i)
3466 {
3467 wxPaneInfo& p = *dock.panes.Item(i);
3468 if (p.window == pane.window)
3469 pane_position = i;
3470
3471 // while we're at it, subtract the pane sash
3472 // width from the dock width, because this would
3473 // skew our proportion calculations
3474 if (i > 0)
3475 dock_pixels -= sash_size;
3476
3477 // also, the whole size (including decorations) of
3478 // all fixed panes must also be subtracted, because they
3479 // are not part of the proportion calculation
3480 if (p.IsFixed())
3481 {
3482 if (dock.IsHorizontal())
3483 dock_pixels -= p.best_size.x;
3484 else
3485 dock_pixels -= p.best_size.y;
3486 }
3487 else
3488 {
3489 total_proportion += p.dock_proportion;
3490 }
3491 }
3492
3493 // find a pane in our dock to 'steal' space from or to 'give'
3494 // space to -- this is essentially what is done when a pane is
3495 // resized; the pane should usually be the first non-fixed pane
3496 // to the right of the action pane
3497 int borrow_pane = -1;
3498 for (i = pane_position+1; i < dock_pane_count; ++i)
3499 {
3500 wxPaneInfo& p = *dock.panes.Item(i);
3501 if (!p.IsFixed())
3502 {
3503 borrow_pane = i;
3504 break;
3505 }
3506 }
3507
3508
3509 // demand that the pane being resized is found in this dock
3510 // (this assert really never should be raised)
3511 wxASSERT_MSG(pane_position != -1, wxT("Pane not found in dock"));
3512
3513 // prevent division by zero
3514 if (dock_pixels == 0 || total_proportion == 0 || borrow_pane == -1)
3515 {
3516 m_action = actionNone;
3517 return;
3518 }
3519
3520 // calculate the new proportion of the pane
3521 int new_proportion = (new_pixsize*total_proportion)/dock_pixels;
3522
3523 // default minimum size
3524 int min_size = 0;
3525
3526 // check against the pane's minimum size, if specified. please note
3527 // that this is not enough to ensure that the minimum size will
3528 // not be violated, because the whole frame might later be shrunk,
3529 // causing the size of the pane to violate it's minimum size
3530 if (pane.min_size.IsFullySpecified())
3531 {
3532 min_size = 0;
3533
3534 if (pane.HasBorder())
3535 min_size += (pane_border_size*2);
3536
3537 // calculate minimum size with decorations (border,caption)
3538 if (pane_part->orientation == wxVERTICAL)
3539 {
3540 min_size += pane.min_size.y;
3541 if (pane.HasCaption())
3542 min_size += caption_size;
3543 }
3544 else
3545 {
3546 min_size += pane.min_size.x;
3547 }
3548 }
3549
3550
3551 // for some reason, an arithmatic error somewhere is causing
3552 // the proportion calculations to always be off by 1 pixel;
3553 // for now we will add the 1 pixel on, but we really should
3554 // determine what's causing this.
3555 min_size++;
3556
3557 int min_proportion = (min_size*total_proportion)/dock_pixels;
3558
3559 if (new_proportion < min_proportion)
3560 new_proportion = min_proportion;
3561
3562
3563
3564 int prop_diff = new_proportion - pane.dock_proportion;
3565
3566 // borrow the space from our neighbor pane to the
3567 // right or bottom (depending on orientation)
3568 dock.panes.Item(borrow_pane)->dock_proportion -= prop_diff;
3569 pane.dock_proportion = new_proportion;
3570
3571 // repaint
3572 Update();
3573 Repaint(NULL);
3574 }
3575 }
3576 else if (m_action == actionClickButton)
3577 {
3578 m_hover_button = NULL;
3579 m_frame->ReleaseMouse();
3580 UpdateButtonOnScreen(m_action_part, event);
3581
3582 // make sure we're still over the item that was originally clicked
3583 if (m_action_part == HitTest(event.GetX(), event.GetY()))
3584 {
3585 // fire button-click event
3586 wxFrameManagerEvent e(wxEVT_AUI_PANEBUTTON);
3587 e.SetPane(m_action_part->pane);
3588 e.SetButton(m_action_part->button->button_id);
3589 ProcessMgrEvent(e);
3590 }
3591 }
3592 else if (m_action == actionClickCaption)
3593 {
3594 m_frame->ReleaseMouse();
3595 }
3596 else if (m_action == actionDragFloatingPane)
3597 {
3598 m_frame->ReleaseMouse();
3599 }
3600 else if (m_action == actionDragToolbarPane)
3601 {
3602 m_frame->ReleaseMouse();
3603
3604 wxPaneInfo& pane = GetPane(m_action_window);
3605 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3606
3607 // save the new positions
3608 wxDockInfoPtrArray docks;
3609 FindDocks(m_docks, pane.dock_direction,
3610 pane.dock_layer, pane.dock_row, docks);
3611 if (docks.GetCount() == 1)
3612 {
3613 wxDockInfo& dock = *docks.Item(0);
3614
3615 wxArrayInt pane_positions, pane_sizes;
3616 GetPanePositionsAndSizes(dock, pane_positions, pane_sizes);
3617
3618 int i, dock_pane_count = dock.panes.GetCount();
3619 for (i = 0; i < dock_pane_count; ++i)
3620 dock.panes.Item(i)->dock_pos = pane_positions[i];
3621 }
3622
3623 pane.state &= ~wxPaneInfo::actionPane;
3624 Update();
3625 }
3626 else
3627 {
3628 event.Skip();
3629 }
3630
3631 m_action = actionNone;
3632 m_last_mouse_move = wxPoint(); // see comment in OnMotion()
3633 }
3634
3635
3636 void wxFrameManager::OnMotion(wxMouseEvent& event)
3637 {
3638 // sometimes when Update() is called from inside this method,
3639 // a spurious mouse move event is generated; this check will make
3640 // sure that only real mouse moves will get anywhere in this method;
3641 // this appears to be a bug somewhere, and I don't know where the
3642 // mouse move event is being generated. only verified on MSW
3643
3644 wxPoint mouse_pos = event.GetPosition();
3645 if (m_last_mouse_move == mouse_pos)
3646 return;
3647 m_last_mouse_move = mouse_pos;
3648
3649
3650 if (m_action == actionResize)
3651 {
3652 wxPoint pos = m_action_part->rect.GetPosition();
3653 if (m_action_part->orientation == wxHORIZONTAL)
3654 pos.y = wxMax(0, event.m_y - m_action_offset.y);
3655 else
3656 pos.x = wxMax(0, event.m_x - m_action_offset.x);
3657
3658 wxRect rect(m_frame->ClientToScreen(pos),
3659 m_action_part->rect.GetSize());
3660
3661 wxScreenDC dc;
3662 if (!m_action_hintrect.IsEmpty())
3663 DrawResizeHint(dc, m_action_hintrect);
3664 DrawResizeHint(dc, rect);
3665 m_action_hintrect = rect;
3666 }
3667 else if (m_action == actionClickCaption)
3668 {
3669 int drag_x_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_X);
3670 int drag_y_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_Y);
3671
3672 // caption has been clicked. we need to check if the mouse
3673 // is now being dragged. if it is, we need to change the
3674 // mouse action to 'drag'
3675 if (abs(event.m_x - m_action_start.x) > drag_x_threshold ||
3676 abs(event.m_y - m_action_start.y) > drag_y_threshold)
3677 {
3678 wxPaneInfo* pane_info = m_action_part->pane;
3679
3680 if (!pane_info->IsToolbar())
3681 {
3682 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
3683 pane_info->IsFloatable())
3684 {
3685 m_action = actionDragFloatingPane;
3686
3687 // set initial float position
3688 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
3689 pane_info->floating_pos = wxPoint(pt.x - m_action_offset.x,
3690 pt.y - m_action_offset.y);
3691 // float the window
3692 pane_info->Float();
3693 Update();
3694
3695 m_action_window = pane_info->frame;
3696
3697 // action offset is used here to make it feel "natural" to the user
3698 // to drag a docked pane and suddenly have it become a floating frame.
3699 // Sometimes, however, the offset where the user clicked on the docked
3700 // caption is bigger than the width of the floating frame itself, so
3701 // in that case we need to set the action offset to a sensible value
3702 wxSize frame_size = m_action_window->GetSize();
3703 if (frame_size.x <= m_action_offset.x)
3704 m_action_offset.x = 30;
3705 }
3706 }
3707 else
3708 {
3709 m_action = actionDragToolbarPane;
3710 m_action_window = pane_info->window;
3711 }
3712 }
3713 }
3714 else if (m_action == actionDragFloatingPane)
3715 {
3716 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
3717 m_action_window->Move(pt.x - m_action_offset.x,
3718 pt.y - m_action_offset.y);
3719 }
3720 else if (m_action == actionDragToolbarPane)
3721 {
3722 wxPaneInfo& pane = GetPane(m_action_window);
3723 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3724
3725 pane.state |= wxPaneInfo::actionPane;
3726
3727 wxPoint pt = event.GetPosition();
3728 DoDrop(m_docks, m_panes, pane, pt, m_action_offset);
3729
3730 // if DoDrop() decided to float the pane, set up
3731 // the floating pane's initial position
3732 if (pane.IsFloating())
3733 {
3734 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
3735 pane.floating_pos = wxPoint(pt.x - m_action_offset.x,
3736 pt.y - m_action_offset.y);
3737 }
3738
3739 // this will do the actiual move operation;
3740 // in the case that the pane has been floated,
3741 // this call will create the floating pane
3742 // and do the reparenting
3743 Update();
3744
3745 // if the pane has been floated, change the mouse
3746 // action actionDragFloatingPane so that subsequent
3747 // EVT_MOTION() events will move the floating pane
3748 if (pane.IsFloating())
3749 {
3750 pane.state &= ~wxPaneInfo::actionPane;
3751 m_action = actionDragFloatingPane;
3752 m_action_window = pane.frame;
3753 }
3754 }
3755 else
3756 {
3757 wxDockUIPart* part = HitTest(event.GetX(), event.GetY());
3758 if (part && part->type == wxDockUIPart::typePaneButton)
3759 {
3760 if (part != m_hover_button)
3761 {
3762 // make the old button normal
3763 if (m_hover_button)
3764 UpdateButtonOnScreen(m_hover_button, event);
3765
3766 // mouse is over a button, so repaint the
3767 // button in hover mode
3768 UpdateButtonOnScreen(part, event);
3769 m_hover_button = part;
3770 }
3771 }
3772 else
3773 {
3774 if (m_hover_button)
3775 {
3776 m_hover_button = NULL;
3777 Repaint();
3778 }
3779 else
3780 {
3781 event.Skip();
3782 }
3783 }
3784 }
3785 }
3786
3787 void wxFrameManager::OnLeaveWindow(wxMouseEvent& WXUNUSED(event))
3788 {
3789 if (m_hover_button)
3790 {
3791 m_hover_button = NULL;
3792 Repaint();
3793 }
3794 }
3795
3796 void wxFrameManager::OnChildFocus(wxChildFocusEvent& event)
3797 {
3798 // when a child pane has it's focus set, we should change the
3799 // pane's active state to reflect this. (this is only true if
3800 // active panes are allowed by the owner)
3801 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
3802 {
3803 if (GetPane(event.GetWindow()).IsOk())
3804 {
3805 SetActivePane(m_panes, event.GetWindow());
3806 m_frame->Refresh();
3807 }
3808 }
3809
3810 event.Skip();
3811 }
3812
3813
3814 // OnPaneButton() is an event handler that is called
3815 // when a pane button has been pressed.
3816 void wxFrameManager::OnPaneButton(wxFrameManagerEvent& evt)
3817 {
3818 wxASSERT_MSG(evt.pane, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3819
3820 wxPaneInfo& pane = *(evt.pane);
3821
3822 if (evt.button == wxPaneInfo::buttonClose)
3823 {
3824 // fire pane close event
3825 wxFrameManagerEvent e(wxEVT_AUI_PANECLOSE);
3826 e.SetPane(evt.pane);
3827 ProcessMgrEvent(e);
3828
3829 if (!e.GetVeto())
3830 {
3831 pane.Hide();
3832 Update();
3833 }
3834 }
3835 else if (evt.button == wxPaneInfo::buttonPin)
3836 {
3837 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
3838 pane.IsFloatable())
3839 pane.Float();
3840 Update();
3841 }
3842 }
3843
3844 #endif // wxUSE_AUI