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