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