]> git.saurik.com Git - wxWidgets.git/blob - src/aui/framemanager.cpp
wxAUI: fixed pane saving design thinko
[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 p.frame->Show(false);
880
881 // reparent to m_frame and destroy the pane
882 p.window->Reparent(m_frame);
883 p.frame->SetSizer(NULL);
884 p.frame->Destroy();
885 p.frame = NULL;
886 }
887
888 // make sure there are no references to this pane in our uiparts,
889 // just in case the caller doesn't call Update() immediately after
890 // the DetachPane() call. This prevets obscure crashes which would
891 // happen at window repaint if the caller forgets to call Update()
892 int pi, part_count;
893 for (pi = 0, part_count = (int)m_uiparts.GetCount(); pi < part_count; ++pi)
894 {
895 wxDockUIPart& part = m_uiparts.Item(pi);
896 if (part.pane == &p)
897 {
898 m_uiparts.RemoveAt(pi);
899 part_count--;
900 pi--;
901 continue;
902 }
903 }
904
905 m_panes.RemoveAt(i);
906 return true;
907 }
908 }
909 return false;
910 }
911
912
913 // EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
914 // in the input string. This is an internal functions which is
915 // used for saving perspectives
916 static wxString EscapeDelimiters(const wxString& s)
917 {
918 wxString result;
919 result.Alloc(s.length());
920 const wxChar* ch = s.c_str();
921 while (*ch)
922 {
923 if (*ch == wxT(';') || *ch == wxT('|'))
924 result += wxT('\\');
925 result += *ch;
926 ++ch;
927 }
928 return result;
929 }
930
931 wxString wxFrameManager::SavePaneInfo(wxPaneInfo& pane)
932 {
933 wxString result = wxT("name=");
934 result += EscapeDelimiters(pane.name);
935 result += wxT(";");
936
937 result += wxT("caption=");
938 result += EscapeDelimiters(pane.caption);
939 result += wxT(";");
940
941 result += wxString::Format(wxT("state=%u;"), pane.state);
942 result += wxString::Format(wxT("dir=%d;"), pane.dock_direction);
943 result += wxString::Format(wxT("layer=%d;"), pane.dock_layer);
944 result += wxString::Format(wxT("row=%d;"), pane.dock_row);
945 result += wxString::Format(wxT("pos=%d;"), pane.dock_pos);
946 result += wxString::Format(wxT("prop=%d;"), pane.dock_proportion);
947 result += wxString::Format(wxT("bestw=%d;"), pane.best_size.x);
948 result += wxString::Format(wxT("besth=%d;"), pane.best_size.y);
949 result += wxString::Format(wxT("minw=%d;"), pane.min_size.x);
950 result += wxString::Format(wxT("minh=%d;"), pane.min_size.y);
951 result += wxString::Format(wxT("maxw=%d;"), pane.max_size.x);
952 result += wxString::Format(wxT("maxh=%d;"), pane.max_size.y);
953 result += wxString::Format(wxT("floatx=%d;"), pane.floating_pos.x);
954 result += wxString::Format(wxT("floaty=%d;"), pane.floating_pos.y);
955 result += wxString::Format(wxT("floatw=%d;"), pane.floating_size.x);
956 result += wxString::Format(wxT("floath=%d"), pane.floating_size.y);
957
958 return result;
959 }
960
961 // Load a "pane" with the pane infor settings in pane_part
962 void wxFrameManager::LoadPaneInfo(wxString pane_part, wxPaneInfo &pane)
963 {
964 // replace escaped characters so we can
965 // split up the string easily
966 pane_part.Replace(wxT("\\|"), wxT("\a"));
967 pane_part.Replace(wxT("\\;"), wxT("\b"));
968
969 while(1)
970 {
971 wxString val_part = pane_part.BeforeFirst(wxT(';'));
972 pane_part = pane_part.AfterFirst(wxT(';'));
973 wxString val_name = val_part.BeforeFirst(wxT('='));
974 wxString value = val_part.AfterFirst(wxT('='));
975 val_name.MakeLower();
976 val_name.Trim(true);
977 val_name.Trim(false);
978 value.Trim(true);
979 value.Trim(false);
980
981 if (val_name.empty())
982 break;
983
984 if (val_name == wxT("name"))
985 pane.name = value;
986 else if (val_name == wxT("caption"))
987 pane.caption = value;
988 else if (val_name == wxT("state"))
989 pane.state = (unsigned int)wxAtoi(value.c_str());
990 else if (val_name == wxT("dir"))
991 pane.dock_direction = wxAtoi(value.c_str());
992 else if (val_name == wxT("layer"))
993 pane.dock_layer = wxAtoi(value.c_str());
994 else if (val_name == wxT("row"))
995 pane.dock_row = wxAtoi(value.c_str());
996 else if (val_name == wxT("pos"))
997 pane.dock_pos = wxAtoi(value.c_str());
998 else if (val_name == wxT("prop"))
999 pane.dock_proportion = wxAtoi(value.c_str());
1000 else if (val_name == wxT("bestw"))
1001 pane.best_size.x = wxAtoi(value.c_str());
1002 else if (val_name == wxT("besth"))
1003 pane.best_size.y = wxAtoi(value.c_str());
1004 else if (val_name == wxT("minw"))
1005 pane.min_size.x = wxAtoi(value.c_str());
1006 else if (val_name == wxT("minh"))
1007 pane.min_size.y = wxAtoi(value.c_str());
1008 else if (val_name == wxT("maxw"))
1009 pane.max_size.x = wxAtoi(value.c_str());
1010 else if (val_name == wxT("maxh"))
1011 pane.max_size.y = wxAtoi(value.c_str());
1012 else if (val_name == wxT("floatx"))
1013 pane.floating_pos.x = wxAtoi(value.c_str());
1014 else if (val_name == wxT("floaty"))
1015 pane.floating_pos.y = wxAtoi(value.c_str());
1016 else if (val_name == wxT("floatw"))
1017 pane.floating_size.x = wxAtoi(value.c_str());
1018 else if (val_name == wxT("floath"))
1019 pane.floating_size.y = wxAtoi(value.c_str());
1020 else {
1021 wxFAIL_MSG(wxT("Bad Perspective String"));
1022 }
1023 }
1024
1025 // replace escaped characters so we can
1026 // split up the string easily
1027 pane.name.Replace(wxT("\a"), wxT("|"));
1028 pane.name.Replace(wxT("\b"), wxT(";"));
1029 pane.caption.Replace(wxT("\a"), wxT("|"));
1030 pane.caption.Replace(wxT("\b"), wxT(";"));
1031 pane_part.Replace(wxT("\a"), wxT("|"));
1032 pane_part.Replace(wxT("\b"), wxT(";"));
1033
1034 return;
1035 }
1036
1037
1038 // SavePerspective() saves all pane information as a single string.
1039 // This string may later be fed into LoadPerspective() to restore
1040 // all pane settings. This save and load mechanism allows an
1041 // exact pane configuration to be saved and restored at a later time
1042
1043 wxString wxFrameManager::SavePerspective()
1044 {
1045 wxString result;
1046 result.Alloc(500);
1047 result = wxT("layout1|");
1048
1049 int pane_i, pane_count = m_panes.GetCount();
1050 for (pane_i = 0; pane_i < pane_count; ++pane_i)
1051 {
1052 wxPaneInfo& pane = m_panes.Item(pane_i);
1053 result += SavePaneInfo(pane)+wxT("|");
1054 }
1055
1056 int dock_i, dock_count = m_docks.GetCount();
1057 for (dock_i = 0; dock_i < dock_count; ++dock_i)
1058 {
1059 wxDockInfo& dock = m_docks.Item(dock_i);
1060
1061 result += wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
1062 dock.dock_direction, dock.dock_layer,
1063 dock.dock_row, dock.size);
1064 }
1065
1066 return result;
1067 }
1068
1069 // LoadPerspective() loads a layout which was saved with SavePerspective()
1070 // If the "update" flag parameter is true, the GUI will immediately be updated
1071
1072 bool wxFrameManager::LoadPerspective(const wxString& layout, bool update)
1073 {
1074 wxString input = layout;
1075 wxString part;
1076
1077 // check layout string version
1078 part = input.BeforeFirst(wxT('|'));
1079 input = input.AfterFirst(wxT('|'));
1080 part.Trim(true);
1081 part.Trim(false);
1082 if (part != wxT("layout1"))
1083 return false;
1084
1085 // mark all panes currently managed as docked and hidden
1086 int pane_i, pane_count = m_panes.GetCount();
1087 for (pane_i = 0; pane_i < pane_count; ++pane_i)
1088 m_panes.Item(pane_i).Dock().Hide();
1089
1090 // clear out the dock array; this will be reconstructed
1091 m_docks.Clear();
1092
1093 // replace escaped characters so we can
1094 // split up the string easily
1095 input.Replace(wxT("\\|"), wxT("\a"));
1096 input.Replace(wxT("\\;"), wxT("\b"));
1097
1098 while (1)
1099 {
1100 wxPaneInfo pane;
1101
1102 wxString pane_part = input.BeforeFirst(wxT('|'));
1103 input = input.AfterFirst(wxT('|'));
1104 pane_part.Trim(true);
1105
1106 // if the string is empty, we're done parsing
1107 if (pane_part.empty())
1108 break;
1109
1110 if (pane_part.Left(9) == wxT("dock_size"))
1111 {
1112 wxString val_name = pane_part.BeforeFirst(wxT('='));
1113 wxString value = pane_part.AfterFirst(wxT('='));
1114
1115 long dir, layer, row, size;
1116 wxString piece = val_name.AfterFirst(wxT('('));
1117 piece = piece.BeforeLast(wxT(')'));
1118 piece.BeforeFirst(wxT(',')).ToLong(&dir);
1119 piece = piece.AfterFirst(wxT(','));
1120 piece.BeforeFirst(wxT(',')).ToLong(&layer);
1121 piece.AfterFirst(wxT(',')).ToLong(&row);
1122 value.ToLong(&size);
1123
1124 wxDockInfo dock;
1125 dock.dock_direction = dir;
1126 dock.dock_layer = layer;
1127 dock.dock_row = row;
1128 dock.size = size;
1129 m_docks.Add(dock);
1130 continue;
1131 }
1132
1133 // Undo our escaping as LoadPaneInfo needs to take an unescaped
1134 // name so it can be called by external callers
1135 pane_part.Replace(wxT("\a"), wxT("|"));
1136 pane_part.Replace(wxT("\b"), wxT(";"));
1137
1138 LoadPaneInfo(pane_part, pane);
1139
1140 wxPaneInfo& p = GetPane(pane.name);
1141 if (!p.IsOk())
1142 {
1143 // the pane window couldn't be found
1144 // in the existing layout
1145 return false;
1146 }
1147
1148 p.SafeSet(pane);
1149
1150 }
1151
1152 if (update)
1153 Update();
1154
1155 return true;
1156 }
1157
1158 void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo& dock,
1159 wxArrayInt& positions,
1160 wxArrayInt& sizes)
1161 {
1162 int caption_size = m_art->GetMetric(wxAUI_ART_CAPTION_SIZE);
1163 int pane_border_size = m_art->GetMetric(wxAUI_ART_PANE_BORDER_SIZE);
1164 int gripper_size = m_art->GetMetric(wxAUI_ART_GRIPPER_SIZE);
1165
1166 positions.Empty();
1167 sizes.Empty();
1168
1169 int offset, action_pane = -1;
1170 int pane_i, pane_count = dock.panes.GetCount();
1171
1172 // find the pane marked as our action pane
1173 for (pane_i = 0; pane_i < pane_count; ++pane_i)
1174 {
1175 wxPaneInfo& pane = *(dock.panes.Item(pane_i));
1176
1177 if (pane.state & wxPaneInfo::actionPane)
1178 {
1179 wxASSERT_MSG(action_pane==-1, wxT("Too many fixed action panes"));
1180 action_pane = pane_i;
1181 }
1182 }
1183
1184 // set up each panes default position, and
1185 // determine the size (width or height, depending
1186 // on the dock's orientation) of each pane
1187 for (pane_i = 0; pane_i < pane_count; ++pane_i)
1188 {
1189 wxPaneInfo& pane = *(dock.panes.Item(pane_i));
1190 positions.Add(pane.dock_pos);
1191 int size = 0;
1192
1193 if (pane.HasBorder())
1194 size += (pane_border_size*2);
1195
1196 if (dock.IsHorizontal())
1197 {
1198 if (pane.HasGripper() && !pane.HasGripperTop())
1199 size += gripper_size;
1200 size += pane.best_size.x;
1201 }
1202 else
1203 {
1204 if (pane.HasGripper() && pane.HasGripperTop())
1205 size += gripper_size;
1206
1207 if (pane.HasCaption())
1208 size += caption_size;
1209 size += pane.best_size.y;
1210 }
1211
1212 sizes.Add(size);
1213 }
1214
1215 // if there is no action pane, just return the default
1216 // positions (as specified in pane.pane_pos)
1217 if (action_pane == -1)
1218 return;
1219
1220 offset = 0;
1221 for (pane_i = action_pane-1; pane_i >= 0; --pane_i)
1222 {
1223 int amount = positions[pane_i+1] - (positions[pane_i] + sizes[pane_i]);
1224
1225 if (amount >= 0)
1226 offset += amount;
1227 else
1228 positions[pane_i] -= -amount;
1229
1230 offset += sizes[pane_i];
1231 }
1232
1233 // if the dock mode is fixed, make sure none of the panes
1234 // overlap; we will bump panes that overlap
1235 offset = 0;
1236 for (pane_i = action_pane; pane_i < pane_count; ++pane_i)
1237 {
1238 int amount = positions[pane_i] - offset;
1239 if (amount >= 0)
1240 offset += amount;
1241 else
1242 positions[pane_i] += -amount;
1243
1244 offset += sizes[pane_i];
1245 }
1246 }
1247
1248
1249 void wxFrameManager::LayoutAddPane(wxSizer* cont,
1250 wxDockInfo& dock,
1251 wxPaneInfo& pane,
1252 wxDockUIPartArray& uiparts,
1253 bool spacer_only)
1254 {
1255 wxDockUIPart part;
1256 wxSizerItem* sizer_item;
1257
1258 int caption_size = m_art->GetMetric(wxAUI_ART_CAPTION_SIZE);
1259 int gripper_size = m_art->GetMetric(wxAUI_ART_GRIPPER_SIZE);
1260 int pane_border_size = m_art->GetMetric(wxAUI_ART_PANE_BORDER_SIZE);
1261 int pane_button_size = m_art->GetMetric(wxAUI_ART_PANE_BUTTON_SIZE);
1262
1263 // find out the orientation of the item (orientation for panes
1264 // is the same as the dock's orientation)
1265 int orientation;
1266 if (dock.IsHorizontal())
1267 orientation = wxHORIZONTAL;
1268 else
1269 orientation = wxVERTICAL;
1270
1271 // this variable will store the proportion
1272 // value that the pane will receive
1273 int pane_proportion = pane.dock_proportion;
1274
1275 wxBoxSizer* horz_pane_sizer = new wxBoxSizer(wxHORIZONTAL);
1276 wxBoxSizer* vert_pane_sizer = new wxBoxSizer(wxVERTICAL);
1277
1278 if (pane.HasGripper())
1279 {
1280 if (pane.HasGripperTop())
1281 sizer_item = vert_pane_sizer ->Add(1, gripper_size, 0, wxEXPAND);
1282 else
1283 sizer_item = horz_pane_sizer ->Add(gripper_size, 1, 0, wxEXPAND);
1284
1285 part.type = wxDockUIPart::typeGripper;
1286 part.dock = &dock;
1287 part.pane = &pane;
1288 part.button = NULL;
1289 part.orientation = orientation;
1290 part.cont_sizer = horz_pane_sizer;
1291 part.sizer_item = sizer_item;
1292 uiparts.Add(part);
1293 }
1294
1295 if (pane.HasCaption())
1296 {
1297 // create the caption sizer
1298 wxBoxSizer* caption_sizer = new wxBoxSizer(wxHORIZONTAL);
1299
1300 sizer_item = caption_sizer->Add(1, caption_size, 1, wxEXPAND);
1301
1302 part.type = wxDockUIPart::typeCaption;
1303 part.dock = &dock;
1304 part.pane = &pane;
1305 part.button = NULL;
1306 part.orientation = orientation;
1307 part.cont_sizer = vert_pane_sizer;
1308 part.sizer_item = sizer_item;
1309 int caption_part_idx = uiparts.GetCount();
1310 uiparts.Add(part);
1311
1312 // add pane buttons to the caption
1313 int i, button_count;
1314 for (i = 0, button_count = pane.buttons.GetCount();
1315 i < button_count; ++i)
1316 {
1317 wxPaneButton& button = pane.buttons.Item(i);
1318
1319 sizer_item = caption_sizer->Add(pane_button_size,
1320 caption_size,
1321 0, wxEXPAND);
1322
1323 part.type = wxDockUIPart::typePaneButton;
1324 part.dock = &dock;
1325 part.pane = &pane;
1326 part.button = &button;
1327 part.orientation = orientation;
1328 part.cont_sizer = caption_sizer;
1329 part.sizer_item = sizer_item;
1330 uiparts.Add(part);
1331 }
1332
1333 // add the caption sizer
1334 sizer_item = vert_pane_sizer->Add(caption_sizer, 0, wxEXPAND);
1335
1336 uiparts.Item(caption_part_idx).sizer_item = sizer_item;
1337 }
1338
1339 // add the pane window itself
1340 if (spacer_only)
1341 {
1342 sizer_item = vert_pane_sizer->Add(1, 1, 1, wxEXPAND);
1343 }
1344 else
1345 {
1346 sizer_item = vert_pane_sizer->Add(pane.window, 1, wxEXPAND);
1347 // Don't do this because it breaks the pane size in floating windows
1348 // BIW: Right now commenting this out is causing problems with
1349 // an mdi client window as the center pane.
1350 vert_pane_sizer->SetItemMinSize(pane.window, 1, 1);
1351 }
1352
1353 part.type = wxDockUIPart::typePane;
1354 part.dock = &dock;
1355 part.pane = &pane;
1356 part.button = NULL;
1357 part.orientation = orientation;
1358 part.cont_sizer = vert_pane_sizer;
1359 part.sizer_item = sizer_item;
1360 uiparts.Add(part);
1361
1362
1363 // determine if the pane should have a minimum size; if the pane is
1364 // non-resizable (fixed) then we must set a minimum size. Alternitavely,
1365 // if the pane.min_size is set, we must use that value as well
1366
1367 wxSize min_size = pane.min_size;
1368 if (pane.IsFixed())
1369 {
1370 if (min_size == wxDefaultSize)
1371 {
1372 min_size = pane.best_size;
1373 pane_proportion = 0;
1374 }
1375 }
1376
1377 if (min_size != wxDefaultSize)
1378 {
1379 vert_pane_sizer->SetItemMinSize(
1380 vert_pane_sizer->GetChildren().GetCount()-1,
1381 min_size.x, min_size.y);
1382 }
1383
1384
1385 // add the verticle sizer (caption, pane window) to the
1386 // horizontal sizer (gripper, verticle sizer)
1387 horz_pane_sizer->Add(vert_pane_sizer, 1, wxEXPAND);
1388
1389 // finally, add the pane sizer to the dock sizer
1390
1391 if (pane.HasBorder())
1392 {
1393 // allowing space for the pane's border
1394 sizer_item = cont->Add(horz_pane_sizer, pane_proportion,
1395 wxEXPAND | wxALL, pane_border_size);
1396
1397 part.type = wxDockUIPart::typePaneBorder;
1398 part.dock = &dock;
1399 part.pane = &pane;
1400 part.button = NULL;
1401 part.orientation = orientation;
1402 part.cont_sizer = cont;
1403 part.sizer_item = sizer_item;
1404 uiparts.Add(part);
1405 }
1406 else
1407 {
1408 sizer_item = cont->Add(horz_pane_sizer, pane_proportion, wxEXPAND);
1409 }
1410 }
1411
1412 void wxFrameManager::LayoutAddDock(wxSizer* cont,
1413 wxDockInfo& dock,
1414 wxDockUIPartArray& uiparts,
1415 bool spacer_only)
1416 {
1417 wxSizerItem* sizer_item;
1418 wxDockUIPart part;
1419
1420 int sash_size = m_art->GetMetric(wxAUI_ART_SASH_SIZE);
1421 int orientation = dock.IsHorizontal() ? wxHORIZONTAL : wxVERTICAL;
1422
1423 // resizable bottom and right docks have a sash before them
1424 if (!dock.fixed && (dock.dock_direction == wxAUI_DOCK_BOTTOM ||
1425 dock.dock_direction == wxAUI_DOCK_RIGHT))
1426 {
1427 sizer_item = cont->Add(sash_size, sash_size, 0, wxEXPAND);
1428
1429 part.type = wxDockUIPart::typeDockSizer;
1430 part.orientation = orientation;
1431 part.dock = &dock;
1432 part.pane = NULL;
1433 part.button = NULL;
1434 part.cont_sizer = cont;
1435 part.sizer_item = sizer_item;
1436 uiparts.Add(part);
1437 }
1438
1439 // create the sizer for the dock
1440 wxSizer* dock_sizer = new wxBoxSizer(orientation);
1441
1442 // add each pane to the dock
1443 int pane_i, pane_count = dock.panes.GetCount();
1444
1445 if (dock.fixed)
1446 {
1447 wxArrayInt pane_positions, pane_sizes;
1448
1449 // figure out the real pane positions we will
1450 // use, without modifying the each pane's pane_pos member
1451 GetPanePositionsAndSizes(dock, pane_positions, pane_sizes);
1452
1453 int offset = 0;
1454 for (pane_i = 0; pane_i < pane_count; ++pane_i)
1455 {
1456 wxPaneInfo& pane = *(dock.panes.Item(pane_i));
1457 int pane_pos = pane_positions.Item(pane_i);
1458
1459 int amount = pane_pos - offset;
1460 if (amount > 0)
1461 {
1462 if (dock.IsVertical())
1463 sizer_item = dock_sizer->Add(1, amount, 0, wxEXPAND);
1464 else
1465 sizer_item = dock_sizer->Add(amount, 1, 0, wxEXPAND);
1466
1467 part.type = wxDockUIPart::typeBackground;
1468 part.dock = &dock;
1469 part.pane = NULL;
1470 part.button = NULL;
1471 part.orientation = (orientation==wxHORIZONTAL) ? wxVERTICAL:wxHORIZONTAL;
1472 part.cont_sizer = dock_sizer;
1473 part.sizer_item = sizer_item;
1474 uiparts.Add(part);
1475
1476 offset += amount;
1477 }
1478
1479 LayoutAddPane(dock_sizer, dock, pane, uiparts, spacer_only);
1480
1481 offset += pane_sizes.Item(pane_i);
1482 }
1483
1484 // at the end add a very small stretchable background area
1485 sizer_item = dock_sizer->Add(1,1, 1, wxEXPAND);
1486
1487 part.type = wxDockUIPart::typeBackground;
1488 part.dock = &dock;
1489 part.pane = NULL;
1490 part.button = NULL;
1491 part.orientation = orientation;
1492 part.cont_sizer = dock_sizer;
1493 part.sizer_item = sizer_item;
1494 uiparts.Add(part);
1495 }
1496 else
1497 {
1498 for (pane_i = 0; pane_i < pane_count; ++pane_i)
1499 {
1500 wxPaneInfo& pane = *(dock.panes.Item(pane_i));
1501
1502 // if this is not the first pane being added,
1503 // we need to add a pane sizer
1504 if (pane_i > 0)
1505 {
1506 sizer_item = dock_sizer->Add(sash_size, sash_size, 0, wxEXPAND);
1507
1508 part.type = wxDockUIPart::typePaneSizer;
1509 part.dock = &dock;
1510 part.pane = dock.panes.Item(pane_i-1);
1511 part.button = NULL;
1512 part.orientation = (orientation==wxHORIZONTAL) ? wxVERTICAL:wxHORIZONTAL;
1513 part.cont_sizer = dock_sizer;
1514 part.sizer_item = sizer_item;
1515 uiparts.Add(part);
1516 }
1517
1518 LayoutAddPane(dock_sizer, dock, pane, uiparts, spacer_only);
1519 }
1520 }
1521
1522 if (dock.dock_direction == wxAUI_DOCK_CENTER)
1523 sizer_item = cont->Add(dock_sizer, 1, wxEXPAND);
1524 else
1525 sizer_item = cont->Add(dock_sizer, 0, wxEXPAND);
1526
1527 part.type = wxDockUIPart::typeDock;
1528 part.dock = &dock;
1529 part.pane = NULL;
1530 part.button = NULL;
1531 part.orientation = orientation;
1532 part.cont_sizer = cont;
1533 part.sizer_item = sizer_item;
1534 uiparts.Add(part);
1535
1536 if (dock.IsHorizontal())
1537 cont->SetItemMinSize(dock_sizer, 0, dock.size);
1538 else
1539 cont->SetItemMinSize(dock_sizer, dock.size, 0);
1540
1541 // top and left docks have a sash after them
1542 if (!dock.fixed && (dock.dock_direction == wxAUI_DOCK_TOP ||
1543 dock.dock_direction == wxAUI_DOCK_LEFT))
1544 {
1545 sizer_item = cont->Add(sash_size, sash_size, 0, wxEXPAND);
1546
1547 part.type = wxDockUIPart::typeDockSizer;
1548 part.dock = &dock;
1549 part.pane = NULL;
1550 part.button = NULL;
1551 part.orientation = orientation;
1552 part.cont_sizer = cont;
1553 part.sizer_item = sizer_item;
1554 uiparts.Add(part);
1555 }
1556 }
1557
1558 wxSizer* wxFrameManager::LayoutAll(wxPaneInfoArray& panes,
1559 wxDockInfoArray& docks,
1560 wxDockUIPartArray& uiparts,
1561 bool spacer_only)
1562 {
1563 wxBoxSizer* container = new wxBoxSizer(wxVERTICAL);
1564
1565 int pane_border_size = m_art->GetMetric(wxAUI_ART_PANE_BORDER_SIZE);
1566 int caption_size = m_art->GetMetric(wxAUI_ART_CAPTION_SIZE);
1567 wxSize cli_size = m_frame->GetClientSize();
1568 int i, dock_count, pane_count;
1569
1570
1571 // empty all docks out
1572 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
1573 docks.Item(i).panes.Empty();
1574
1575 // iterate through all known panes, filing each
1576 // of them into the appropriate dock. If the
1577 // pane does not exist in the dock, add it
1578 for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
1579 {
1580 wxPaneInfo& p = panes.Item(i);
1581
1582 // find any docks in this layer
1583 wxDockInfo* dock;
1584 wxDockInfoPtrArray arr;
1585 FindDocks(docks, p.dock_direction, p.dock_layer, p.dock_row, arr);
1586
1587 if (arr.GetCount() > 0)
1588 {
1589 dock = arr.Item(0);
1590 }
1591 else
1592 {
1593 // dock was not found, so we need to create a new one
1594 wxDockInfo d;
1595 d.dock_direction = p.dock_direction;
1596 d.dock_layer = p.dock_layer;
1597 d.dock_row = p.dock_row;
1598 docks.Add(d);
1599 dock = &docks.Last();
1600 }
1601
1602
1603 if (p.IsDocked() && p.IsShown())
1604 {
1605 // remove the pane from any existing docks except this one
1606 RemovePaneFromDocks(docks, p, dock);
1607
1608 // pane needs to be added to the dock,
1609 // if it doesn't already exist
1610 if (!FindPaneInDock(*dock, p.window))
1611 dock->panes.Add(&p);
1612 }
1613 else
1614 {
1615 // remove the pane from any existing docks
1616 RemovePaneFromDocks(docks, p);
1617 }
1618
1619 }
1620
1621 // remove any empty docks
1622 for (i = docks.GetCount()-1; i >= 0; --i)
1623 {
1624 if (docks.Item(i).panes.GetCount() == 0)
1625 docks.RemoveAt(i);
1626 }
1627
1628 // configure the docks further
1629 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
1630 {
1631 wxDockInfo& dock = docks.Item(i);
1632 int j, dock_pane_count = dock.panes.GetCount();
1633
1634 // sort the dock pane array by the pane's
1635 // dock position (dock_pos), in ascending order
1636 dock.panes.Sort(PaneSortFunc);
1637
1638 // for newly created docks, set up their initial size
1639 if (dock.size == 0)
1640 {
1641 int size = 0;
1642
1643 for (j = 0; j < dock_pane_count; ++j)
1644 {
1645 wxPaneInfo& pane = *dock.panes.Item(j);
1646 wxSize pane_size = pane.best_size;
1647 if (pane_size == wxDefaultSize)
1648 pane_size = pane.min_size;
1649 if (pane_size == wxDefaultSize)
1650 pane_size = pane.window->GetSize();
1651
1652 if (dock.IsHorizontal())
1653 size = wxMax(pane_size.y, size);
1654 else
1655 size = wxMax(pane_size.x, size);
1656 }
1657
1658 // add space for the border (two times), but only
1659 // if at least one pane inside the dock has a pane border
1660 for (j = 0; j < dock_pane_count; ++j)
1661 {
1662 if (dock.panes.Item(j)->HasBorder())
1663 {
1664 size += (pane_border_size*2);
1665 break;
1666 }
1667 }
1668
1669 // if pane is on the top or bottom, add the caption height,
1670 // but only if at least one pane inside the dock has a caption
1671 if (dock.IsHorizontal())
1672 {
1673 for (j = 0; j < dock_pane_count; ++j)
1674 {
1675 if (dock.panes.Item(j)->HasCaption())
1676 {
1677 size += caption_size;
1678 break;
1679 }
1680 }
1681 }
1682
1683 // new dock's size may not be more than 1/3 of the frame size
1684 if (dock.IsHorizontal())
1685 size = wxMin(size, cli_size.y/3);
1686 else
1687 size = wxMin(size, cli_size.x/3);
1688
1689 if (size < 10)
1690 size = 10;
1691 dock.size = size;
1692 }
1693
1694
1695 // determine the dock's minimum size
1696 bool plus_border = false;
1697 bool plus_caption = false;
1698 int dock_min_size = 0;
1699 for (j = 0; j < dock_pane_count; ++j)
1700 {
1701 wxPaneInfo& pane = *dock.panes.Item(j);
1702 if (pane.min_size != wxDefaultSize)
1703 {
1704 if (pane.HasBorder())
1705 plus_border = true;
1706 if (pane.HasCaption())
1707 plus_caption = true;
1708 if (dock.IsHorizontal())
1709 {
1710 if (pane.min_size.y > dock_min_size)
1711 dock_min_size = pane.min_size.y;
1712 }
1713 else
1714 {
1715 if (pane.min_size.x > dock_min_size)
1716 dock_min_size = pane.min_size.x;
1717 }
1718 }
1719 }
1720
1721 if (plus_border)
1722 dock_min_size += (pane_border_size*2);
1723 if (plus_caption && dock.IsHorizontal())
1724 dock_min_size += (caption_size);
1725
1726 dock.min_size = dock_min_size;
1727
1728
1729 // if the pane's current size is less than it's
1730 // minimum, increase the dock's size to it's minimum
1731 if (dock.size < dock.min_size)
1732 dock.size = dock.min_size;
1733
1734
1735 // determine the dock's mode (fixed or proportional);
1736 // determine whether the dock has only toolbars
1737 bool action_pane_marked = false;
1738 dock.fixed = true;
1739 dock.toolbar = true;
1740 for (j = 0; j < dock_pane_count; ++j)
1741 {
1742 wxPaneInfo& pane = *dock.panes.Item(j);
1743 if (!pane.IsFixed())
1744 dock.fixed = false;
1745 if (!pane.IsToolbar())
1746 dock.toolbar = false;
1747 if (pane.state & wxPaneInfo::actionPane)
1748 action_pane_marked = true;
1749 }
1750
1751
1752 // if the dock mode is proportional and not fixed-pixel,
1753 // reassign the dock_pos to the sequential 0, 1, 2, 3;
1754 // e.g. remove gaps like 1, 2, 30, 500
1755 if (!dock.fixed)
1756 {
1757 for (j = 0; j < dock_pane_count; ++j)
1758 {
1759 wxPaneInfo& pane = *dock.panes.Item(j);
1760 pane.dock_pos = j;
1761 }
1762 }
1763
1764 // if the dock mode is fixed, and none of the panes
1765 // are being moved right now, make sure the panes
1766 // do not overlap each other. If they do, we will
1767 // adjust the panes' positions
1768 if (dock.fixed && !action_pane_marked)
1769 {
1770 wxArrayInt pane_positions, pane_sizes;
1771 GetPanePositionsAndSizes(dock, pane_positions, pane_sizes);
1772
1773 int offset = 0;
1774 for (j = 0; j < dock_pane_count; ++j)
1775 {
1776 wxPaneInfo& pane = *(dock.panes.Item(j));
1777 pane.dock_pos = pane_positions[j];
1778
1779 int amount = pane.dock_pos - offset;
1780 if (amount >= 0)
1781 offset += amount;
1782 else
1783 pane.dock_pos += -amount;
1784
1785 offset += pane_sizes[j];
1786 }
1787 }
1788 }
1789
1790 // discover the maximum dock layer
1791 int max_layer = 0;
1792 for (i = 0; i < dock_count; ++i)
1793 max_layer = wxMax(max_layer, docks.Item(i).dock_layer);
1794
1795
1796 // clear out uiparts
1797 uiparts.Empty();
1798
1799 // create a bunch of box sizers,
1800 // from the innermost level outwards.
1801 wxSizer* cont = NULL;
1802 wxSizer* middle = NULL;
1803 int layer = 0;
1804 int row, row_count;
1805
1806 for (layer = 0; layer <= max_layer; ++layer)
1807 {
1808 wxDockInfoPtrArray arr;
1809
1810 // find any docks in this layer
1811 FindDocks(docks, -1, layer, -1, arr);
1812
1813 // if there aren't any, skip to the next layer
1814 if (arr.IsEmpty())
1815 continue;
1816
1817 wxSizer* old_cont = cont;
1818
1819 // create a container which will hold this layer's
1820 // docks (top, bottom, left, right)
1821 cont = new wxBoxSizer(wxVERTICAL);
1822
1823
1824 // find any top docks in this layer
1825 FindDocks(docks, wxAUI_DOCK_TOP, layer, -1, arr);
1826 RenumberDockRows(arr);
1827 if (!arr.IsEmpty())
1828 {
1829 for (row = 0, row_count = arr.GetCount(); row < row_count; ++row)
1830 LayoutAddDock(cont, *arr.Item(row), uiparts, spacer_only);
1831 }
1832
1833
1834 // fill out the middle layer (which consists
1835 // of left docks, content area and right docks)
1836
1837 middle = new wxBoxSizer(wxHORIZONTAL);
1838
1839 // find any left docks in this layer
1840 FindDocks(docks, wxAUI_DOCK_LEFT, layer, -1, arr);
1841 RenumberDockRows(arr);
1842 if (!arr.IsEmpty())
1843 {
1844 for (row = 0, row_count = arr.GetCount(); row < row_count; ++row)
1845 LayoutAddDock(middle, *arr.Item(row), uiparts, spacer_only);
1846 }
1847
1848 // add content dock (or previous layer's sizer
1849 // to the middle
1850 if (!old_cont)
1851 {
1852 // find any center docks
1853 FindDocks(docks, wxAUI_DOCK_CENTER, -1, -1, arr);
1854 if (!arr.IsEmpty())
1855 {
1856 for (row = 0,row_count = arr.GetCount(); row<row_count; ++row)
1857 LayoutAddDock(middle, *arr.Item(row), uiparts, spacer_only);
1858 }
1859 else
1860 {
1861 // there are no center docks, add a background area
1862 wxSizerItem* sizer_item = middle->Add(1,1, 1, wxEXPAND);
1863 wxDockUIPart part;
1864 part.type = wxDockUIPart::typeBackground;
1865 part.pane = NULL;
1866 part.dock = NULL;
1867 part.button = NULL;
1868 part.cont_sizer = middle;
1869 part.sizer_item = sizer_item;
1870 uiparts.Add(part);
1871 }
1872 }
1873 else
1874 {
1875 middle->Add(old_cont, 1, wxEXPAND);
1876 }
1877
1878 // find any right docks in this layer
1879 FindDocks(docks, wxAUI_DOCK_RIGHT, layer, -1, arr);
1880 RenumberDockRows(arr);
1881 if (!arr.IsEmpty())
1882 {
1883 for (row = arr.GetCount()-1; row >= 0; --row)
1884 LayoutAddDock(middle, *arr.Item(row), uiparts, spacer_only);
1885 }
1886
1887 cont->Add(middle, 1, wxEXPAND);
1888
1889
1890
1891 // find any bottom docks in this layer
1892 FindDocks(docks, wxAUI_DOCK_BOTTOM, layer, -1, arr);
1893 RenumberDockRows(arr);
1894 if (!arr.IsEmpty())
1895 {
1896 for (row = arr.GetCount()-1; row >= 0; --row)
1897 LayoutAddDock(cont, *arr.Item(row), uiparts, spacer_only);
1898 }
1899
1900 }
1901
1902 if (!cont)
1903 {
1904 // no sizer available, because there are no docks,
1905 // therefore we will create a simple background area
1906 cont = new wxBoxSizer(wxVERTICAL);
1907 wxSizerItem* sizer_item = cont->Add(1,1, 1, wxEXPAND);
1908 wxDockUIPart part;
1909 part.type = wxDockUIPart::typeBackground;
1910 part.pane = NULL;
1911 part.dock = NULL;
1912 part.button = NULL;
1913 part.cont_sizer = middle;
1914 part.sizer_item = sizer_item;
1915 uiparts.Add(part);
1916 }
1917
1918 container->Add(cont, 1, wxEXPAND);
1919 return container;
1920 }
1921
1922
1923 // Update() updates the layout. Whenever changes are made to
1924 // one or more panes, this function should be called. It is the
1925 // external entry point for running the layout engine.
1926
1927 void wxFrameManager::Update()
1928 {
1929 wxSizer* sizer;
1930 int i, pane_count = m_panes.GetCount();
1931
1932 // delete old sizer first
1933 m_frame->SetSizer(NULL);
1934
1935 // destroy floating panes which have been
1936 // redocked or are becoming non-floating
1937 for (i = 0; i < pane_count; ++i)
1938 {
1939 wxPaneInfo& p = m_panes.Item(i);
1940
1941 if (!p.IsFloating() && p.frame)
1942 {
1943 // because the pane is no longer in a floating, we need to
1944 // reparent it to m_frame and destroy the floating frame
1945
1946 // reduce flicker
1947 p.window->SetSize(1,1);
1948 p.frame->Show(false);
1949
1950 // reparent to m_frame and destroy the pane
1951 p.window->Reparent(m_frame);
1952 p.frame->SetSizer(NULL);
1953 p.frame->Destroy();
1954 p.frame = NULL;
1955 }
1956 }
1957
1958
1959 // create a layout for all of the panes
1960 sizer = LayoutAll(m_panes, m_docks, m_uiparts, false);
1961
1962 // hide or show panes as necessary,
1963 // and float panes as necessary
1964 for (i = 0; i < pane_count; ++i)
1965 {
1966 wxPaneInfo& p = m_panes.Item(i);
1967
1968 if (p.IsFloating())
1969 {
1970 if (p.frame == NULL)
1971 {
1972 // we need to create a frame for this
1973 // pane, which has recently been floated
1974 wxFloatingPane* frame = new wxFloatingPane(m_frame,
1975 this,
1976 p);
1977
1978 #if wxCHECK_VERSION(2,7,0)
1979 // on MSW and Mac, if the owner desires transparent dragging, and
1980 // the dragging is happening right now, then the floating
1981 // window should have this style by default
1982 if (m_action == actionDragFloatingPane &&
1983 (m_flags & wxAUI_MGR_TRANSPARENT_DRAG))
1984 frame->SetTransparent(150);
1985 #endif
1986
1987 frame->SetPaneWindow(p);
1988 p.frame = frame;
1989
1990 if (p.IsShown())
1991 {
1992 frame->Show();
1993 }
1994 }
1995 else
1996 {
1997 // frame already exists, make sure it's position
1998 // and size reflect the information in wxPaneInfo
1999 if (p.frame->GetPosition() != p.floating_pos)
2000 {
2001 p.frame->SetSize(p.floating_pos.x, p.floating_pos.y,
2002 wxDefaultCoord, wxDefaultCoord,
2003 wxSIZE_USE_EXISTING);
2004 //p.frame->Move(p.floating_pos.x, p.floating_pos.y);
2005 }
2006
2007 p.frame->Show(p.IsShown());
2008 }
2009 }
2010 else
2011 {
2012 p.window->Show(p.IsShown());
2013 }
2014
2015 // if "active panes" are no longer allowed, clear
2016 // any optionActive values from the pane states
2017 if ((m_flags & wxAUI_MGR_ALLOW_ACTIVE_PANE) == 0)
2018 {
2019 p.state &= ~wxPaneInfo::optionActive;
2020 }
2021 }
2022
2023
2024 // keep track of the old window rectangles so we can
2025 // refresh those windows whose rect has changed
2026 wxAuiRectArray old_pane_rects;
2027 for (i = 0; i < pane_count; ++i)
2028 {
2029 wxRect r;
2030 wxPaneInfo& p = m_panes.Item(i);
2031
2032 if (p.window && p.IsShown() && p.IsDocked())
2033 r = p.rect;
2034
2035 old_pane_rects.Add(r);
2036 }
2037
2038
2039
2040
2041 // apply the new sizer
2042 m_frame->SetSizer(sizer);
2043 m_frame->SetAutoLayout(false);
2044 DoFrameLayout();
2045
2046
2047
2048 // now that the frame layout is done, we need to check
2049 // the new pane rectangles against the old rectangles that
2050 // we saved a few lines above here. If the rectangles have
2051 // changed, the corresponding panes must also be updated
2052 for (i = 0; i < pane_count; ++i)
2053 {
2054 wxPaneInfo& p = m_panes.Item(i);
2055 if (p.window && p.window->IsShown() && p.IsDocked())
2056 {
2057 if (p.rect != old_pane_rects[i])
2058 {
2059 p.window->Refresh();
2060 p.window->Update();
2061 }
2062 }
2063 }
2064
2065
2066 Repaint();
2067
2068 // set frame's minimum size
2069
2070 /*
2071 // N.B. More work needs to be done on frame minimum sizes;
2072 // this is some intresting code that imposes the minimum size,
2073 // but we may want to include a more flexible mechanism or
2074 // options for multiple minimum-size modes, e.g. strict or lax
2075 wxSize min_size = sizer->GetMinSize();
2076 wxSize frame_size = m_frame->GetSize();
2077 wxSize client_size = m_frame->GetClientSize();
2078
2079 wxSize minframe_size(min_size.x+frame_size.x-client_size.x,
2080 min_size.y+frame_size.y-client_size.y );
2081
2082 m_frame->SetMinSize(minframe_size);
2083
2084 if (frame_size.x < minframe_size.x ||
2085 frame_size.y < minframe_size.y)
2086 sizer->Fit(m_frame);
2087 */
2088 }
2089
2090
2091 // DoFrameLayout() is an internal function which invokes wxSizer::Layout
2092 // on the frame's main sizer, then measures all the various UI items
2093 // and updates their internal rectangles. This should always be called
2094 // instead of calling m_frame->Layout() directly
2095
2096 void wxFrameManager::DoFrameLayout()
2097 {
2098 m_frame->Layout();
2099
2100 int i, part_count;
2101 for (i = 0, part_count = m_uiparts.GetCount(); i < part_count; ++i)
2102 {
2103 wxDockUIPart& part = m_uiparts.Item(i);
2104
2105 // get the rectangle of the UI part
2106 // originally, this code looked like this:
2107 // part.rect = wxRect(part.sizer_item->GetPosition(),
2108 // part.sizer_item->GetSize());
2109 // this worked quite well, with one exception: the mdi
2110 // client window had a "deferred" size variable
2111 // that returned the wrong size. It looks like
2112 // a bug in wx, because the former size of the window
2113 // was being returned. So, we will retrieve the part's
2114 // rectangle via other means
2115
2116
2117 part.rect = part.sizer_item->GetRect();
2118 int flag = part.sizer_item->GetFlag();
2119 int border = part.sizer_item->GetBorder();
2120 if (flag & wxTOP)
2121 {
2122 part.rect.y -= border;
2123 part.rect.height += border;
2124 }
2125 if (flag & wxLEFT)
2126 {
2127 part.rect.x -= border;
2128 part.rect.width += border;
2129 }
2130 if (flag & wxBOTTOM)
2131 part.rect.height += border;
2132 if (flag & wxRIGHT)
2133 part.rect.width += border;
2134
2135
2136 if (part.type == wxDockUIPart::typeDock)
2137 part.dock->rect = part.rect;
2138 if (part.type == wxDockUIPart::typePane)
2139 part.pane->rect = part.rect;
2140 }
2141 }
2142
2143 // GetPanePart() looks up the pane the pane border UI part (or the regular
2144 // pane part if there is no border). This allows the caller to get the exact
2145 // rectangle of the pane in question, including decorations like
2146 // caption and border (if any).
2147
2148 wxDockUIPart* wxFrameManager::GetPanePart(wxWindow* wnd)
2149 {
2150 int i, part_count;
2151 for (i = 0, part_count = m_uiparts.GetCount(); i < part_count; ++i)
2152 {
2153 wxDockUIPart& part = m_uiparts.Item(i);
2154 if (part.type == wxDockUIPart::typePaneBorder &&
2155 part.pane && part.pane->window == wnd)
2156 return &part;
2157 }
2158 for (i = 0, part_count = m_uiparts.GetCount(); i < part_count; ++i)
2159 {
2160 wxDockUIPart& part = m_uiparts.Item(i);
2161 if (part.type == wxDockUIPart::typePane &&
2162 part.pane && part.pane->window == wnd)
2163 return &part;
2164 }
2165 return NULL;
2166 }
2167
2168
2169
2170 // GetDockPixelOffset() is an internal function which returns
2171 // a dock's offset in pixels from the left side of the window
2172 // (for horizontal docks) or from the top of the window (for
2173 // vertical docks). This value is necessary for calculating
2174 // fixel-pane/toolbar offsets when they are dragged.
2175
2176 int wxFrameManager::GetDockPixelOffset(wxPaneInfo& test)
2177 {
2178 // the only way to accurately calculate the dock's
2179 // offset is to actually run a theoretical layout
2180
2181 int i, part_count, dock_count;
2182 wxDockInfoArray docks;
2183 wxPaneInfoArray panes;
2184 wxDockUIPartArray uiparts;
2185 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
2186 panes.Add(test);
2187
2188 wxSizer* sizer = LayoutAll(panes, docks, uiparts, true);
2189 wxSize client_size = m_frame->GetClientSize();
2190 sizer->SetDimension(0, 0, client_size.x, client_size.y);
2191 sizer->Layout();
2192
2193 for (i = 0, part_count = uiparts.GetCount(); i < part_count; ++i)
2194 {
2195 wxDockUIPart& part = uiparts.Item(i);
2196 part.rect = wxRect(part.sizer_item->GetPosition(),
2197 part.sizer_item->GetSize());
2198 if (part.type == wxDockUIPart::typeDock)
2199 part.dock->rect = part.rect;
2200 }
2201
2202 delete sizer;
2203
2204 for (i = 0, dock_count = docks.GetCount(); i < dock_count; ++i)
2205 {
2206 wxDockInfo& dock = docks.Item(i);
2207 if (test.dock_direction == dock.dock_direction &&
2208 test.dock_layer==dock.dock_layer && test.dock_row==dock.dock_row)
2209 {
2210 if (dock.IsVertical())
2211 return dock.rect.y;
2212 else
2213 return dock.rect.x;
2214 }
2215 }
2216
2217 return 0;
2218 }
2219
2220
2221
2222 // ProcessDockResult() is a utility function used by DoDrop() - it checks
2223 // if a dock operation is allowed, the new dock position is copied into
2224 // the target info. If the operation was allowed, the function returns true.
2225
2226 bool wxFrameManager::ProcessDockResult(wxPaneInfo& target,
2227 const wxPaneInfo& new_pos)
2228 {
2229 bool allowed = false;
2230 switch (new_pos.dock_direction)
2231 {
2232 case wxAUI_DOCK_TOP: allowed = target.IsTopDockable(); break;
2233 case wxAUI_DOCK_BOTTOM: allowed = target.IsBottomDockable(); break;
2234 case wxAUI_DOCK_LEFT: allowed = target.IsLeftDockable(); break;
2235 case wxAUI_DOCK_RIGHT: allowed = target.IsRightDockable(); break;
2236 }
2237
2238 if (allowed)
2239 target = new_pos;
2240
2241 return allowed;
2242 }
2243
2244
2245 // DoDrop() is an important function. It basically takes a mouse position,
2246 // and determines where the pane's new position would be. If the pane is to be
2247 // dropped, it performs the drop operation using the specified dock and pane
2248 // arrays. By specifying copied dock and pane arrays when calling, a "what-if"
2249 // scenario can be performed, giving precise coordinates for drop hints.
2250 // If, however, wxFrameManager:m_docks and wxFrameManager::m_panes are specified
2251 // as parameters, the changes will be made to the main state arrays
2252
2253 const int auiInsertRowPixels = 10;
2254 const int auiNewRowPixels = 40;
2255 const int auiLayerInsertPixels = 40;
2256 const int auiLayerInsertOffset = 5;
2257
2258 bool wxFrameManager::DoDrop(wxDockInfoArray& docks,
2259 wxPaneInfoArray& panes,
2260 wxPaneInfo& target,
2261 const wxPoint& pt,
2262 const wxPoint& offset)
2263 {
2264 wxSize cli_size = m_frame->GetClientSize();
2265
2266 wxPaneInfo drop = target;
2267
2268
2269 // The result should always be shown
2270 drop.Show();
2271
2272
2273 // Check to see if the pane has been dragged outside of the window
2274 // (or near to the outside of the window), if so, dock it along the edge
2275
2276
2277 int layer_insert_offset = auiLayerInsertOffset;
2278 if (target.IsToolbar())
2279 layer_insert_offset = 0;
2280
2281 if (pt.x < layer_insert_offset &&
2282 pt.x > layer_insert_offset-auiLayerInsertPixels)
2283 {
2284 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_LEFT),
2285 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM)),
2286 GetMaxLayer(docks, wxAUI_DOCK_TOP)) + 1;
2287 drop.Dock().Left().
2288 Layer(new_layer).
2289 Row(0).
2290 Position(pt.y - GetDockPixelOffset(drop) - offset.y);
2291 return ProcessDockResult(target, drop);
2292 }
2293 else if (pt.y < layer_insert_offset &&
2294 pt.y > layer_insert_offset-auiLayerInsertPixels)
2295 {
2296 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_TOP),
2297 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2298 GetMaxLayer(docks, wxAUI_DOCK_RIGHT)) + 1;
2299 drop.Dock().Top().
2300 Layer(new_layer).
2301 Row(0).
2302 Position(pt.x - GetDockPixelOffset(drop) - offset.x);
2303 return ProcessDockResult(target, drop);
2304 }
2305 else if (pt.x >= cli_size.x - layer_insert_offset &&
2306 pt.x < cli_size.x - layer_insert_offset + auiLayerInsertPixels)
2307 {
2308 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_RIGHT),
2309 GetMaxLayer(docks, wxAUI_DOCK_TOP)),
2310 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM)) + 1;
2311 drop.Dock().Right().
2312 Layer(new_layer).
2313 Row(0).
2314 Position(pt.y - GetDockPixelOffset(drop) - offset.y);
2315 return ProcessDockResult(target, drop);
2316 }
2317 else if (pt.y >= cli_size.y - layer_insert_offset &&
2318 pt.y < cli_size.y - layer_insert_offset + auiLayerInsertPixels)
2319 {
2320 int new_layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_BOTTOM),
2321 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2322 GetMaxLayer(docks, wxAUI_DOCK_RIGHT)) + 1;
2323 drop.Dock().Bottom().
2324 Layer(new_layer).
2325 Row(0).
2326 Position(pt.x - GetDockPixelOffset(drop) - offset.x);
2327 return ProcessDockResult(target, drop);
2328 }
2329
2330
2331 wxDockUIPart* part = HitTest(pt.x, pt.y);
2332
2333
2334 if (drop.IsToolbar())
2335 {
2336 if (!part || !part->dock)
2337 return false;
2338
2339
2340 // calculate the offset from where the dock begins
2341 // to the point where the user dropped the pane
2342 int dock_drop_offset = 0;
2343 if (part->dock->IsHorizontal())
2344 dock_drop_offset = pt.x - part->dock->rect.x - offset.x;
2345 else
2346 dock_drop_offset = pt.y - part->dock->rect.y - offset.y;
2347
2348
2349 // toolbars may only be moved in and to fixed-pane docks,
2350 // otherwise we will try to float the pane. Also, the pane
2351 // should float if being dragged over center pane windows
2352 if (!part->dock->fixed || part->dock->dock_direction == wxAUI_DOCK_CENTER)
2353 {
2354 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
2355 (drop.IsFloatable() ||
2356 (part->dock->dock_direction != wxAUI_DOCK_CENTER &&
2357 part->dock->dock_direction != wxAUI_DOCK_NONE)))
2358 {
2359 drop.Float();
2360 }
2361
2362 return ProcessDockResult(target, drop);
2363 }
2364
2365 drop.Dock().
2366 Direction(part->dock->dock_direction).
2367 Layer(part->dock->dock_layer).
2368 Row(part->dock->dock_row).
2369 Position(dock_drop_offset);
2370
2371 if ((
2372 ((pt.y < part->dock->rect.y + 2) && part->dock->IsHorizontal()) ||
2373 ((pt.x < part->dock->rect.x + 2) && part->dock->IsVertical())
2374 ) && part->dock->panes.GetCount() > 1)
2375 {
2376 int row = drop.dock_row;
2377 DoInsertDockRow(panes, part->dock->dock_direction,
2378 part->dock->dock_layer,
2379 part->dock->dock_row);
2380 drop.dock_row = row;
2381 }
2382
2383 if ((
2384 ((pt.y > part->dock->rect.y + part->dock->rect.height - 2 ) && part->dock->IsHorizontal()) ||
2385 ((pt.x > part->dock->rect.x + part->dock->rect.width - 2 ) && part->dock->IsVertical())
2386 ) && part->dock->panes.GetCount() > 1)
2387 {
2388 DoInsertDockRow(panes, part->dock->dock_direction,
2389 part->dock->dock_layer,
2390 part->dock->dock_row+1);
2391 drop.dock_row = part->dock->dock_row+1;
2392 }
2393
2394 return ProcessDockResult(target, drop);
2395 }
2396
2397
2398
2399
2400 if (!part)
2401 return false;
2402
2403 if (part->type == wxDockUIPart::typePaneBorder ||
2404 part->type == wxDockUIPart::typeCaption ||
2405 part->type == wxDockUIPart::typeGripper ||
2406 part->type == wxDockUIPart::typePaneButton ||
2407 part->type == wxDockUIPart::typePane ||
2408 part->type == wxDockUIPart::typePaneSizer ||
2409 part->type == wxDockUIPart::typeDockSizer ||
2410 part->type == wxDockUIPart::typeBackground)
2411 {
2412 if (part->type == wxDockUIPart::typeDockSizer)
2413 {
2414 if (part->dock->panes.GetCount() != 1)
2415 return false;
2416 part = GetPanePart(part->dock->panes.Item(0)->window);
2417 if (!part)
2418 return false;
2419 }
2420
2421
2422
2423 // If a normal frame is being dragged over a toolbar, insert it
2424 // along the edge under the toolbar, but over all other panes.
2425 // (this could be done much better, but somehow factoring this
2426 // calculation with the one at the beginning of this function)
2427 if (part->dock && part->dock->toolbar)
2428 {
2429 int layer = 0;
2430
2431 switch (part->dock->dock_direction)
2432 {
2433 case wxAUI_DOCK_LEFT:
2434 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_LEFT),
2435 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM)),
2436 GetMaxLayer(docks, wxAUI_DOCK_TOP));
2437 break;
2438 case wxAUI_DOCK_TOP:
2439 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_TOP),
2440 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2441 GetMaxLayer(docks, wxAUI_DOCK_RIGHT));
2442 break;
2443 case wxAUI_DOCK_RIGHT:
2444 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_RIGHT),
2445 GetMaxLayer(docks, wxAUI_DOCK_TOP)),
2446 GetMaxLayer(docks, wxAUI_DOCK_BOTTOM));
2447 break;
2448 case wxAUI_DOCK_BOTTOM:
2449 layer = wxMax(wxMax(GetMaxLayer(docks, wxAUI_DOCK_BOTTOM),
2450 GetMaxLayer(docks, wxAUI_DOCK_LEFT)),
2451 GetMaxLayer(docks, wxAUI_DOCK_RIGHT));
2452 break;
2453 }
2454
2455 DoInsertDockRow(panes, part->dock->dock_direction,
2456 layer, 0);
2457 drop.Dock().
2458 Direction(part->dock->dock_direction).
2459 Layer(layer).Row(0).Position(0);
2460 return ProcessDockResult(target, drop);
2461 }
2462
2463
2464 if (!part->pane)
2465 return false;
2466
2467 part = GetPanePart(part->pane->window);
2468 if (!part)
2469 return false;
2470
2471 bool insert_dock_row = false;
2472 int insert_row = part->pane->dock_row;
2473 int insert_dir = part->pane->dock_direction;
2474 int insert_layer = part->pane->dock_layer;
2475
2476 switch (part->pane->dock_direction)
2477 {
2478 case wxAUI_DOCK_TOP:
2479 if (pt.y >= part->rect.y &&
2480 pt.y < part->rect.y+auiInsertRowPixels)
2481 insert_dock_row = true;
2482 break;
2483 case wxAUI_DOCK_BOTTOM:
2484 if (pt.y > part->rect.y+part->rect.height-auiInsertRowPixels &&
2485 pt.y <= part->rect.y + part->rect.height)
2486 insert_dock_row = true;
2487 break;
2488 case wxAUI_DOCK_LEFT:
2489 if (pt.x >= part->rect.x &&
2490 pt.x < part->rect.x+auiInsertRowPixels)
2491 insert_dock_row = true;
2492 break;
2493 case wxAUI_DOCK_RIGHT:
2494 if (pt.x > part->rect.x+part->rect.width-auiInsertRowPixels &&
2495 pt.x <= part->rect.x+part->rect.width)
2496 insert_dock_row = true;
2497 break;
2498 case wxAUI_DOCK_CENTER:
2499 {
2500 // "new row pixels" will be set to the default, but
2501 // must never exceed 20% of the window size
2502 int new_row_pixels_x = auiNewRowPixels;
2503 int new_row_pixels_y = auiNewRowPixels;
2504
2505 if (new_row_pixels_x > (part->rect.width*20)/100)
2506 new_row_pixels_x = (part->rect.width*20)/100;
2507
2508 if (new_row_pixels_y > (part->rect.height*20)/100)
2509 new_row_pixels_y = (part->rect.height*20)/100;
2510
2511
2512 // determine if the mouse pointer is in a location that
2513 // will cause a new row to be inserted. The hot spot positions
2514 // are along the borders of the center pane
2515
2516 insert_layer = 0;
2517 insert_dock_row = true;
2518 if (pt.x >= part->rect.x &&
2519 pt.x < part->rect.x+new_row_pixels_x)
2520 insert_dir = wxAUI_DOCK_LEFT;
2521 else
2522 if (pt.y >= part->rect.y &&
2523 pt.y < part->rect.y+new_row_pixels_y)
2524 insert_dir = wxAUI_DOCK_TOP;
2525 else
2526 if (pt.x >= part->rect.x + part->rect.width-new_row_pixels_x &&
2527 pt.x < part->rect.x + part->rect.width)
2528 insert_dir = wxAUI_DOCK_RIGHT;
2529 else
2530 if (pt.y >= part->rect.y+ part->rect.height-new_row_pixels_y &&
2531 pt.y < part->rect.y + part->rect.height)
2532 insert_dir = wxAUI_DOCK_BOTTOM;
2533 else
2534 return false;
2535
2536 insert_row = GetMaxRow(panes, insert_dir, insert_layer) + 1;
2537 }
2538 }
2539
2540 if (insert_dock_row)
2541 {
2542 DoInsertDockRow(panes, insert_dir, insert_layer, insert_row);
2543 drop.Dock().Direction(insert_dir).
2544 Layer(insert_layer).
2545 Row(insert_row).
2546 Position(0);
2547 return ProcessDockResult(target, drop);
2548 }
2549
2550 // determine the mouse offset and the pane size, both in the
2551 // direction of the dock itself, and perpendicular to the dock
2552
2553 int offset, size;
2554
2555 if (part->orientation == wxVERTICAL)
2556 {
2557 offset = pt.y - part->rect.y;
2558 size = part->rect.GetHeight();
2559 }
2560 else
2561 {
2562 offset = pt.x - part->rect.x;
2563 size = part->rect.GetWidth();
2564 }
2565
2566 int drop_position = part->pane->dock_pos;
2567
2568 // if we are in the top/left part of the pane,
2569 // insert the pane before the pane being hovered over
2570 if (offset <= size/2)
2571 {
2572 drop_position = part->pane->dock_pos;
2573 DoInsertPane(panes,
2574 part->pane->dock_direction,
2575 part->pane->dock_layer,
2576 part->pane->dock_row,
2577 part->pane->dock_pos);
2578 }
2579
2580 // if we are in the bottom/right part of the pane,
2581 // insert the pane before the pane being hovered over
2582 if (offset > size/2)
2583 {
2584 drop_position = part->pane->dock_pos+1;
2585 DoInsertPane(panes,
2586 part->pane->dock_direction,
2587 part->pane->dock_layer,
2588 part->pane->dock_row,
2589 part->pane->dock_pos+1);
2590 }
2591
2592 drop.Dock().
2593 Direction(part->dock->dock_direction).
2594 Layer(part->dock->dock_layer).
2595 Row(part->dock->dock_row).
2596 Position(drop_position);
2597 return ProcessDockResult(target, drop);
2598 }
2599
2600 return false;
2601 }
2602
2603
2604 void wxFrameManager::OnHintFadeTimer(wxTimerEvent& WXUNUSED(event))
2605 {
2606 if (!m_hint_wnd || m_hint_fadeamt >= m_hint_fademax)
2607 {
2608 m_hint_fadetimer.Stop();
2609 return;
2610 }
2611
2612 m_hint_fadeamt += 4;
2613 #if wxCHECK_VERSION(2,7,0)
2614 m_hint_wnd->SetTransparent(m_hint_fadeamt);
2615 #else
2616 if (m_hint_wnd->IsKindOf(CLASSINFO(wxPseudoTransparentFrame)))
2617 ((wxPseudoTransparentFrame *)m_hint_wnd)->SetTransparent(m_hint_fadeamt);
2618 #endif
2619 }
2620
2621 void wxFrameManager::ShowHint(const wxRect& rect)
2622 {
2623 if ((m_flags & wxAUI_MGR_TRANSPARENT_HINT) != 0
2624 && m_hint_wnd
2625 // Finally, don't use a venetian blind effect if it's been specifically disabled
2626 && !((m_hint_wnd->IsKindOf(CLASSINFO(wxPseudoTransparentFrame))) &&
2627 (m_flags & wxAUI_MGR_DISABLE_VENETIAN_BLINDS))
2628 )
2629 {
2630 if (m_last_hint == rect)
2631 return;
2632 m_last_hint = rect;
2633
2634 m_hint_fadeamt = m_hint_fademax;
2635 if ((m_flags & wxAUI_MGR_TRANSPARENT_HINT_FADE)
2636 && !((m_hint_wnd->IsKindOf(CLASSINFO(wxPseudoTransparentFrame))) &&
2637 (m_flags & wxAUI_MGR_DISABLE_VENETIAN_BLINDS_FADE))
2638 )
2639 m_hint_fadeamt = 0;
2640
2641 if (! m_hint_wnd->IsShown())
2642 m_hint_wnd->Show();
2643
2644 // if we are dragging a floating pane, set the focus
2645 // back to that floating pane (otherwise it becomes unfocused)
2646 if (m_action == actionDragFloatingPane && m_action_window)
2647 m_action_window->SetFocus();
2648
2649 #if wxCHECK_VERSION(2,7,0)
2650 m_hint_wnd->SetTransparent(m_hint_fadeamt);
2651 #else
2652 if (m_hint_wnd->IsKindOf(CLASSINFO(wxPseudoTransparentFrame)))
2653 ((wxPseudoTransparentFrame *)m_hint_wnd)->SetTransparent(m_hint_fadeamt);
2654 #endif
2655 m_hint_wnd->SetSize(rect);
2656 m_hint_wnd->Raise();
2657
2658
2659 if (m_hint_fadeamt != m_hint_fademax) // Only fade if we need to
2660 {
2661 // start fade in timer
2662 m_hint_fadetimer.SetOwner(this, 101);
2663 m_hint_fadetimer.Start(5);
2664 }
2665 }
2666
2667 else // Not using a transparent hint window...
2668 {
2669
2670 if (m_last_hint != rect)
2671 {
2672 // remove the last hint rectangle
2673 m_last_hint = rect;
2674 m_frame->Refresh();
2675 m_frame->Update();
2676 }
2677
2678 wxScreenDC screendc;
2679 wxRegion clip(1, 1, 10000, 10000);
2680
2681 // clip all floating windows, so we don't draw over them
2682 int i, pane_count;
2683 for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
2684 {
2685 wxPaneInfo& pane = m_panes.Item(i);
2686
2687 if (pane.IsFloating() &&
2688 pane.frame->IsShown())
2689 {
2690 wxRect rect = pane.frame->GetRect();
2691 #ifdef __WXGTK__
2692 // wxGTK returns the client size, not the whole frame size
2693 rect.width += 15;
2694 rect.height += 35;
2695 rect.Inflate(5);
2696 #endif
2697
2698 clip.Subtract(rect);
2699 }
2700 }
2701
2702 // As we can only hide the hint by redrawing the managed window, we
2703 // need to clip the region to the managed window too or we get
2704 // nasty redrawn problems.
2705 clip.Intersect(m_frame->GetRect());
2706
2707 screendc.SetClippingRegion(clip);
2708
2709 wxBitmap stipple = wxPaneCreateStippleBitmap();
2710 wxBrush brush(stipple);
2711 screendc.SetBrush(brush);
2712 screendc.SetPen(*wxTRANSPARENT_PEN);
2713
2714 screendc.DrawRectangle(rect.x, rect.y, 5, rect.height);
2715 screendc.DrawRectangle(rect.x+5, rect.y, rect.width-10, 5);
2716 screendc.DrawRectangle(rect.x+rect.width-5, rect.y, 5, rect.height);
2717 screendc.DrawRectangle(rect.x+5, rect.y+rect.height-5, rect.width-10, 5);
2718 }
2719 }
2720
2721 void wxFrameManager::HideHint()
2722 {
2723 // hides a transparent window hint, if there is one
2724 if (m_hint_wnd)
2725 {
2726 m_hint_wnd->Show(false);
2727 #if wxCHECK_VERSION(2,7,0)
2728 m_hint_wnd->SetTransparent(0);
2729 #else
2730 if (m_hint_wnd->IsKindOf(CLASSINFO(wxPseudoTransparentFrame)))
2731 ((wxPseudoTransparentFrame *)m_hint_wnd)->SetTransparent(0);
2732 #endif
2733 m_hint_fadetimer.Stop();
2734 m_last_hint = wxRect();
2735 return;
2736 }
2737
2738 // hides a painted hint by redrawing the frame window
2739 if (!m_last_hint.IsEmpty())
2740 {
2741 m_frame->Refresh();
2742 m_frame->Update();
2743 m_last_hint = wxRect();
2744 }
2745 }
2746
2747
2748
2749 // DrawHintRect() draws a drop hint rectangle. First calls DoDrop() to
2750 // determine the exact position the pane would be at were if dropped. If
2751 // the pame would indeed become docked at the specified drop point,
2752 // DrawHintRect() then calls ShowHint() to indicate this drop rectangle.
2753 // "pane_window" is the window pointer of the pane being dragged, pt is
2754 // the mouse position, in client coordinates
2755 void wxFrameManager::DrawHintRect(wxWindow* pane_window,
2756 const wxPoint& pt,
2757 const wxPoint& offset)
2758 {
2759 wxRect rect;
2760
2761 // we need to paint a hint rectangle; to find out the exact hint rectangle,
2762 // we will create a new temporary layout and then measure the resulting
2763 // rectangle; we will create a copy of the docking structures (m_dock)
2764 // so that we don't modify the real thing on screen
2765
2766 int i, pane_count, part_count;
2767 wxDockInfoArray docks;
2768 wxPaneInfoArray panes;
2769 wxDockUIPartArray uiparts;
2770 wxPaneInfo hint = GetPane(pane_window);
2771 hint.name = wxT("__HINT__");
2772 hint.Show();
2773
2774 if (!hint.IsOk())
2775 return;
2776
2777 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
2778
2779 // remove any pane already there which bears the same window;
2780 // this happens when you are moving a pane around in a dock
2781 for (i = 0, pane_count = panes.GetCount(); i < pane_count; ++i)
2782 {
2783 if (panes.Item(i).window == pane_window)
2784 {
2785 RemovePaneFromDocks(docks, panes.Item(i));
2786 panes.RemoveAt(i);
2787 break;
2788 }
2789 }
2790
2791 // find out where the new pane would be
2792 if (!DoDrop(docks, panes, hint, pt, offset))
2793 {
2794 HideHint();
2795 return;
2796 }
2797
2798 panes.Add(hint);
2799
2800 wxSizer* sizer = LayoutAll(panes, docks, uiparts, true);
2801 wxSize client_size = m_frame->GetClientSize();
2802 sizer->SetDimension(0, 0, client_size.x, client_size.y);
2803 sizer->Layout();
2804
2805 for (i = 0, part_count = uiparts.GetCount();
2806 i < part_count; ++i)
2807 {
2808 wxDockUIPart& part = uiparts.Item(i);
2809
2810 if (part.type == wxDockUIPart::typePaneBorder &&
2811 part.pane && part.pane->name == wxT("__HINT__"))
2812 {
2813 rect = wxRect(part.sizer_item->GetPosition(),
2814 part.sizer_item->GetSize());
2815 break;
2816 }
2817 }
2818
2819 delete sizer;
2820
2821 if (rect.IsEmpty())
2822 {
2823 HideHint();
2824 return;
2825 }
2826
2827 // actually show the hint rectangle on the screen
2828 m_frame->ClientToScreen(&rect.x, &rect.y);
2829 ShowHint(rect);
2830 }
2831
2832 void wxFrameManager::OnFloatingPaneMoveStart(wxWindow* wnd)
2833 {
2834 // try to find the pane
2835 wxPaneInfo& pane = GetPane(wnd);
2836 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
2837
2838 #if wxCHECK_VERSION(2,7,0)
2839 if (m_flags & wxAUI_MGR_TRANSPARENT_DRAG)
2840 pane.frame->SetTransparent(150);
2841 #endif
2842 }
2843
2844 void wxFrameManager::OnFloatingPaneMoving(wxWindow* wnd)
2845 {
2846 // try to find the pane
2847 wxPaneInfo& pane = GetPane(wnd);
2848 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
2849
2850 wxPoint pt = ::wxGetMousePosition();
2851 wxPoint client_pt = m_frame->ScreenToClient(pt);
2852
2853 // calculate the offset from the upper left-hand corner
2854 // of the frame to the mouse pointer
2855 wxPoint frame_pos = pane.frame->GetPosition();
2856 wxPoint action_offset(pt.x-frame_pos.x, pt.y-frame_pos.y);
2857
2858 // no hint for toolbar floating windows
2859 if (pane.IsToolbar() && m_action == actionDragFloatingPane)
2860 {
2861 if (m_action == actionDragFloatingPane)
2862 {
2863 wxDockInfoArray docks;
2864 wxPaneInfoArray panes;
2865 wxDockUIPartArray uiparts;
2866 wxPaneInfo hint = pane;
2867
2868 CopyDocksAndPanes(docks, panes, m_docks, m_panes);
2869
2870 // find out where the new pane would be
2871 if (!DoDrop(docks, panes, hint, client_pt))
2872 return;
2873 if (hint.IsFloating())
2874 return;
2875
2876 pane = hint;
2877 m_action = actionDragToolbarPane;
2878 m_action_window = pane.window;
2879
2880 Update();
2881 }
2882
2883 return;
2884 }
2885
2886
2887 // if a key modifier is pressed while dragging the frame,
2888 // don't dock the window
2889 if (wxGetKeyState(WXK_CONTROL) || wxGetKeyState(WXK_ALT))
2890 {
2891 HideHint();
2892 return;
2893 }
2894
2895
2896 DrawHintRect(wnd, client_pt, action_offset);
2897
2898 #ifdef __WXGTK__
2899 // this cleans up some screen artifacts that are caused on GTK because
2900 // we aren't getting the exact size of the window (see comment
2901 // in DrawHintRect)
2902 //Refresh();
2903 #endif
2904
2905
2906 // reduces flicker
2907 m_frame->Update();
2908 }
2909
2910 void wxFrameManager::OnFloatingPaneMoved(wxWindow* wnd)
2911 {
2912 // try to find the pane
2913 wxPaneInfo& pane = GetPane(wnd);
2914 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
2915
2916 wxPoint pt = ::wxGetMousePosition();
2917 wxPoint client_pt = m_frame->ScreenToClient(pt);
2918
2919 // calculate the offset from the upper left-hand corner
2920 // of the frame to the mouse pointer
2921 wxPoint frame_pos = pane.frame->GetPosition();
2922 wxPoint action_offset(pt.x-frame_pos.x, pt.y-frame_pos.y);
2923
2924
2925 // if a key modifier is pressed while dragging the frame,
2926 // don't dock the window
2927 if (!wxGetKeyState(WXK_CONTROL) && !wxGetKeyState(WXK_ALT))
2928 {
2929 // do the drop calculation
2930 DoDrop(m_docks, m_panes, pane, client_pt, action_offset);
2931 }
2932
2933 // if the pane is still floating, update it's floating
2934 // position (that we store)
2935 if (pane.IsFloating())
2936 {
2937 pane.floating_pos = pane.frame->GetPosition();
2938
2939 #if wxCHECK_VERSION(2,7,0)
2940 if (m_flags & wxAUI_MGR_TRANSPARENT_DRAG)
2941 pane.frame->SetTransparent(255);
2942 #endif
2943 }
2944
2945 Update();
2946
2947 HideHint();
2948 }
2949
2950 void wxFrameManager::OnFloatingPaneResized(wxWindow* wnd, const wxSize& size)
2951 {
2952 // try to find the pane
2953 wxPaneInfo& pane = GetPane(wnd);
2954 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
2955
2956 pane.floating_size = size;
2957 }
2958
2959
2960 void wxFrameManager::OnFloatingPaneClosed(wxWindow* wnd, wxCloseEvent& evt)
2961 {
2962 // try to find the pane
2963 wxPaneInfo& pane = GetPane(wnd);
2964 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
2965
2966
2967 // fire pane close event
2968 wxFrameManagerEvent e(wxEVT_AUI_PANECLOSE);
2969 e.SetPane(&pane);
2970 e.SetCanVeto(evt.CanVeto());
2971 ProcessMgrEvent(e);
2972
2973 if (e.GetVeto())
2974 {
2975 evt.Veto();
2976 return;
2977 }
2978 else
2979 {
2980 // reparent the pane window back to us and
2981 // prepare the frame window for destruction
2982 pane.window->Show(false);
2983 pane.window->Reparent(m_frame);
2984 pane.frame = NULL;
2985 pane.Hide();
2986 }
2987 }
2988
2989
2990
2991 void wxFrameManager::OnFloatingPaneActivated(wxWindow* wnd)
2992 {
2993 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
2994 {
2995 // try to find the pane
2996 wxASSERT_MSG(GetPane(wnd).IsOk(), wxT("Pane window not found"));
2997
2998 SetActivePane(m_panes, wnd);
2999 Repaint();
3000 }
3001 }
3002
3003 // OnRender() draws all of the pane captions, sashes,
3004 // backgrounds, captions, grippers, pane borders and buttons.
3005 // It renders the entire user interface.
3006
3007 void wxFrameManager::OnRender(wxFrameManagerEvent& evt)
3008 {
3009 wxDC* dc = evt.GetDC();
3010
3011 #ifdef __WXMAC__
3012 dc->Clear() ;
3013 #endif
3014 int i, part_count;
3015 for (i = 0, part_count = m_uiparts.GetCount();
3016 i < part_count; ++i)
3017 {
3018 wxDockUIPart& part = m_uiparts.Item(i);
3019
3020 // don't draw hidden pane items
3021 if (part.sizer_item && !part.sizer_item->IsShown())
3022 continue;
3023
3024 switch (part.type)
3025 {
3026 case wxDockUIPart::typeDockSizer:
3027 case wxDockUIPart::typePaneSizer:
3028 m_art->DrawSash(*dc, part.orientation, part.rect);
3029 break;
3030 case wxDockUIPart::typeBackground:
3031 m_art->DrawBackground(*dc, part.orientation, part.rect);
3032 break;
3033 case wxDockUIPart::typeCaption:
3034 m_art->DrawCaption(*dc, part.pane->caption, part.rect, *part.pane);
3035 break;
3036 case wxDockUIPart::typeGripper:
3037 m_art->DrawGripper(*dc, part.rect, *part.pane);
3038 break;
3039 case wxDockUIPart::typePaneBorder:
3040 m_art->DrawBorder(*dc, part.rect, *part.pane);
3041 break;
3042 case wxDockUIPart::typePaneButton:
3043 m_art->DrawPaneButton(*dc, part.button->button_id,
3044 wxAUI_BUTTON_STATE_NORMAL, part.rect, *part.pane);
3045 break;
3046 }
3047 }
3048 }
3049
3050
3051 // Render() fire a render event, which is normally handled by
3052 // wxFrameManager::OnRender(). This allows the render function to
3053 // be overridden via the render event. This can be useful for paintin
3054 // custom graphics in the main window. Default behavior can be
3055 // invoked in the overridden function by calling OnRender()
3056
3057 void wxFrameManager::Render(wxDC* dc)
3058 {
3059 wxFrameManagerEvent e(wxEVT_AUI_RENDER);
3060 e.SetDC(dc);
3061 ProcessMgrEvent(e);
3062 }
3063
3064 void wxFrameManager::Repaint(wxDC* dc)
3065 {
3066 #ifdef __WXMAC__
3067 if ( dc == NULL )
3068 {
3069 m_frame->Refresh() ;
3070 m_frame->Update() ;
3071 return ;
3072 }
3073 #endif
3074 int w, h;
3075 m_frame->GetClientSize(&w, &h);
3076
3077 // figure out which dc to use; if one
3078 // has been specified, use it, otherwise
3079 // make a client dc
3080 wxClientDC* client_dc = NULL;
3081 if (!dc)
3082 {
3083 client_dc = new wxClientDC(m_frame);
3084 dc = client_dc;
3085 }
3086
3087 // if the frame has a toolbar, the client area
3088 // origin will not be (0,0).
3089 wxPoint pt = m_frame->GetClientAreaOrigin();
3090 if (pt.x != 0 || pt.y != 0)
3091 dc->SetDeviceOrigin(pt.x, pt.y);
3092
3093 // render all the items
3094 Render(dc);
3095
3096 // if we created a client_dc, delete it
3097 if (client_dc)
3098 delete client_dc;
3099 }
3100
3101 void wxFrameManager::OnPaint(wxPaintEvent& WXUNUSED(event))
3102 {
3103 wxPaintDC dc(m_frame);
3104 Repaint(&dc);
3105 }
3106
3107 void wxFrameManager::OnEraseBackground(wxEraseEvent& event)
3108 {
3109 #ifdef __WXMAC__
3110 event.Skip() ;
3111 #else
3112 wxUnusedVar(event);
3113 #endif
3114 }
3115
3116 void wxFrameManager::OnSize(wxSizeEvent& WXUNUSED(event))
3117 {
3118 if (m_frame)
3119 {
3120 DoFrameLayout();
3121 Repaint();
3122 }
3123 }
3124
3125
3126 void wxFrameManager::OnSetCursor(wxSetCursorEvent& event)
3127 {
3128 // determine cursor
3129 wxDockUIPart* part = HitTest(event.GetX(), event.GetY());
3130 wxCursor cursor = wxNullCursor;
3131
3132 if (part)
3133 {
3134 if (part->type == wxDockUIPart::typeDockSizer ||
3135 part->type == wxDockUIPart::typePaneSizer)
3136 {
3137 // a dock may not be resized if it has a single
3138 // pane which is not resizable
3139 if (part->type == wxDockUIPart::typeDockSizer && part->dock &&
3140 part->dock->panes.GetCount() == 1 &&
3141 part->dock->panes.Item(0)->IsFixed())
3142 return;
3143
3144 // panes that may not be resized do not get a sizing cursor
3145 if (part->pane && part->pane->IsFixed())
3146 return;
3147
3148 if (part->orientation == wxVERTICAL)
3149 cursor = wxCursor(wxCURSOR_SIZEWE);
3150 else
3151 cursor = wxCursor(wxCURSOR_SIZENS);
3152 }
3153 else if (part->type == wxDockUIPart::typeGripper)
3154 {
3155 cursor = wxCursor(wxCURSOR_SIZING);
3156 }
3157 }
3158
3159 event.SetCursor(cursor);
3160 }
3161
3162
3163
3164 void wxFrameManager::UpdateButtonOnScreen(wxDockUIPart* button_ui_part,
3165 const wxMouseEvent& event)
3166 {
3167 wxDockUIPart* hit_test = HitTest(event.GetX(), event.GetY());
3168
3169 int state = wxAUI_BUTTON_STATE_NORMAL;
3170
3171 if (hit_test == button_ui_part)
3172 {
3173 if (event.LeftDown())
3174 state = wxAUI_BUTTON_STATE_PRESSED;
3175 else
3176 state = wxAUI_BUTTON_STATE_HOVER;
3177 }
3178 else
3179 {
3180 if (event.LeftDown())
3181 state = wxAUI_BUTTON_STATE_HOVER;
3182 }
3183
3184 // now repaint the button with hover state
3185 wxClientDC cdc(m_frame);
3186
3187 // if the frame has a toolbar, the client area
3188 // origin will not be (0,0).
3189 wxPoint pt = m_frame->GetClientAreaOrigin();
3190 if (pt.x != 0 || pt.y != 0)
3191 cdc.SetDeviceOrigin(pt.x, pt.y);
3192
3193 m_art->DrawPaneButton(cdc,
3194 button_ui_part->button->button_id,
3195 state,
3196 button_ui_part->rect,
3197 *hit_test->pane);
3198 }
3199
3200 void wxFrameManager::OnLeftDown(wxMouseEvent& event)
3201 {
3202 wxDockUIPart* part = HitTest(event.GetX(), event.GetY());
3203 if (part)
3204 {
3205 if (part->dock && part->dock->dock_direction == wxAUI_DOCK_CENTER)
3206 return;
3207
3208 if (part->type == wxDockUIPart::typeDockSizer ||
3209 part->type == wxDockUIPart::typePaneSizer)
3210 {
3211 // a dock may not be resized if it has a single
3212 // pane which is not resizable
3213 if (part->type == wxDockUIPart::typeDockSizer && part->dock &&
3214 part->dock->panes.GetCount() == 1 &&
3215 part->dock->panes.Item(0)->IsFixed())
3216 return;
3217
3218 // panes that may not be resized should be ignored here
3219 if (part->pane && part->pane->IsFixed())
3220 return;
3221
3222 m_action = actionResize;
3223 m_action_part = part;
3224 m_action_hintrect = wxRect();
3225 m_action_start = wxPoint(event.m_x, event.m_y);
3226 m_action_offset = wxPoint(event.m_x - part->rect.x,
3227 event.m_y - part->rect.y);
3228 m_frame->CaptureMouse();
3229 }
3230 else if (part->type == wxDockUIPart::typePaneButton)
3231 {
3232 m_action = actionClickButton;
3233 m_action_part = part;
3234 m_action_start = wxPoint(event.m_x, event.m_y);
3235 m_frame->CaptureMouse();
3236
3237 UpdateButtonOnScreen(part, event);
3238 }
3239 else if (part->type == wxDockUIPart::typeCaption ||
3240 part->type == wxDockUIPart::typeGripper)
3241 {
3242 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
3243 {
3244 // set the caption as active
3245 SetActivePane(m_panes, part->pane->window);
3246 Repaint();
3247 }
3248
3249 m_action = actionClickCaption;
3250 m_action_part = part;
3251 m_action_start = wxPoint(event.m_x, event.m_y);
3252 m_action_offset = wxPoint(event.m_x - part->rect.x,
3253 event.m_y - part->rect.y);
3254 m_frame->CaptureMouse();
3255 }
3256 #ifdef __WXMAC__
3257 else
3258 {
3259 event.Skip();
3260 }
3261 #endif
3262 }
3263 #ifdef __WXMAC__
3264 else
3265 {
3266 event.Skip();
3267 }
3268 #else
3269 event.Skip();
3270 #endif
3271 }
3272
3273
3274 void wxFrameManager::OnLeftUp(wxMouseEvent& event)
3275 {
3276 if (m_action == actionResize)
3277 {
3278 m_frame->ReleaseMouse();
3279
3280 // get rid of the hint rectangle
3281 wxScreenDC dc;
3282 DrawResizeHint(dc, m_action_hintrect);
3283
3284 // resize the dock or the pane
3285 if (m_action_part && m_action_part->type==wxDockUIPart::typeDockSizer)
3286 {
3287 wxRect& rect = m_action_part->dock->rect;
3288
3289 wxPoint new_pos(event.m_x - m_action_offset.x,
3290 event.m_y - m_action_offset.y);
3291
3292 switch (m_action_part->dock->dock_direction)
3293 {
3294 case wxAUI_DOCK_LEFT:
3295 m_action_part->dock->size = new_pos.x - rect.x;
3296 break;
3297 case wxAUI_DOCK_TOP:
3298 m_action_part->dock->size = new_pos.y - rect.y;
3299 break;
3300 case wxAUI_DOCK_RIGHT:
3301 m_action_part->dock->size = rect.x + rect.width -
3302 new_pos.x - m_action_part->rect.GetWidth();
3303 break;
3304 case wxAUI_DOCK_BOTTOM:
3305 m_action_part->dock->size = rect.y + rect.height -
3306 new_pos.y - m_action_part->rect.GetHeight();
3307 break;
3308 }
3309
3310 Update();
3311 Repaint(NULL);
3312 }
3313 else if (m_action_part &&
3314 m_action_part->type == wxDockUIPart::typePaneSizer)
3315 {
3316 wxDockInfo& dock = *m_action_part->dock;
3317 wxPaneInfo& pane = *m_action_part->pane;
3318
3319 int total_proportion = 0;
3320 int dock_pixels = 0;
3321 int new_pixsize = 0;
3322
3323 int caption_size = m_art->GetMetric(wxAUI_ART_CAPTION_SIZE);
3324 int pane_border_size = m_art->GetMetric(wxAUI_ART_PANE_BORDER_SIZE);
3325 int sash_size = m_art->GetMetric(wxAUI_ART_SASH_SIZE);
3326
3327 wxPoint new_pos(event.m_x - m_action_offset.x,
3328 event.m_y - m_action_offset.y);
3329
3330 // determine the pane rectangle by getting the pane part
3331 wxDockUIPart* pane_part = GetPanePart(pane.window);
3332 wxASSERT_MSG(pane_part,
3333 wxT("Pane border part not found -- shouldn't happen"));
3334
3335 // determine the new pixel size that the user wants;
3336 // this will help us recalculate the pane's proportion
3337 if (dock.IsHorizontal())
3338 new_pixsize = new_pos.x - pane_part->rect.x;
3339 else
3340 new_pixsize = new_pos.y - pane_part->rect.y;
3341
3342 // determine the size of the dock, based on orientation
3343 if (dock.IsHorizontal())
3344 dock_pixels = dock.rect.GetWidth();
3345 else
3346 dock_pixels = dock.rect.GetHeight();
3347
3348 // determine the total proportion of all resizable panes,
3349 // and the total size of the dock minus the size of all
3350 // the fixed panes
3351 int i, dock_pane_count = dock.panes.GetCount();
3352 int pane_position = -1;
3353 for (i = 0; i < dock_pane_count; ++i)
3354 {
3355 wxPaneInfo& p = *dock.panes.Item(i);
3356 if (p.window == pane.window)
3357 pane_position = i;
3358
3359 // while we're at it, subtract the pane sash
3360 // width from the dock width, because this would
3361 // skew our proportion calculations
3362 if (i > 0)
3363 dock_pixels -= sash_size;
3364
3365 // also, the whole size (including decorations) of
3366 // all fixed panes must also be subtracted, because they
3367 // are not part of the proportion calculation
3368 if (p.IsFixed())
3369 {
3370 if (dock.IsHorizontal())
3371 dock_pixels -= p.best_size.x;
3372 else
3373 dock_pixels -= p.best_size.y;
3374 }
3375 else
3376 {
3377 total_proportion += p.dock_proportion;
3378 }
3379 }
3380
3381 // find a pane in our dock to 'steal' space from or to 'give'
3382 // space to -- this is essentially what is done when a pane is
3383 // resized; the pane should usually be the first non-fixed pane
3384 // to the right of the action pane
3385 int borrow_pane = -1;
3386 for (i = pane_position+1; i < dock_pane_count; ++i)
3387 {
3388 wxPaneInfo& p = *dock.panes.Item(i);
3389 if (!p.IsFixed())
3390 {
3391 borrow_pane = i;
3392 break;
3393 }
3394 }
3395
3396
3397 // demand that the pane being resized is found in this dock
3398 // (this assert really never should be raised)
3399 wxASSERT_MSG(pane_position != -1, wxT("Pane not found in dock"));
3400
3401 // prevent division by zero
3402 if (dock_pixels == 0 || total_proportion == 0 || borrow_pane == -1)
3403 {
3404 m_action = actionNone;
3405 return;
3406 }
3407
3408 // calculate the new proportion of the pane
3409 int new_proportion = (new_pixsize*total_proportion)/dock_pixels;
3410
3411 // default minimum size
3412 int min_size = 0;
3413
3414 // check against the pane's minimum size, if specified. please note
3415 // that this is not enough to ensure that the minimum size will
3416 // not be violated, because the whole frame might later be shrunk,
3417 // causing the size of the pane to violate it's minimum size
3418 if (pane.min_size.IsFullySpecified())
3419 {
3420 min_size = 0;
3421
3422 if (pane.HasBorder())
3423 min_size += (pane_border_size*2);
3424
3425 // calculate minimum size with decorations (border,caption)
3426 if (pane_part->orientation == wxVERTICAL)
3427 {
3428 min_size += pane.min_size.y;
3429 if (pane.HasCaption())
3430 min_size += caption_size;
3431 }
3432 else
3433 {
3434 min_size += pane.min_size.x;
3435 }
3436 }
3437
3438
3439 // for some reason, an arithmatic error somewhere is causing
3440 // the proportion calculations to always be off by 1 pixel;
3441 // for now we will add the 1 pixel on, but we really should
3442 // determine what's causing this.
3443 min_size++;
3444
3445 int min_proportion = (min_size*total_proportion)/dock_pixels;
3446
3447 if (new_proportion < min_proportion)
3448 new_proportion = min_proportion;
3449
3450
3451
3452 int prop_diff = new_proportion - pane.dock_proportion;
3453
3454 // borrow the space from our neighbor pane to the
3455 // right or bottom (depending on orientation)
3456 dock.panes.Item(borrow_pane)->dock_proportion -= prop_diff;
3457 pane.dock_proportion = new_proportion;
3458
3459 // repaint
3460 Update();
3461 Repaint(NULL);
3462 }
3463 }
3464 else if (m_action == actionClickButton)
3465 {
3466 m_hover_button = NULL;
3467 m_frame->ReleaseMouse();
3468 UpdateButtonOnScreen(m_action_part, event);
3469
3470 // make sure we're still over the item that was originally clicked
3471 if (m_action_part == HitTest(event.GetX(), event.GetY()))
3472 {
3473 // fire button-click event
3474 wxFrameManagerEvent e(wxEVT_AUI_PANEBUTTON);
3475 e.SetPane(m_action_part->pane);
3476 e.SetButton(m_action_part->button->button_id);
3477 ProcessMgrEvent(e);
3478 }
3479 }
3480 else if (m_action == actionClickCaption)
3481 {
3482 m_frame->ReleaseMouse();
3483 }
3484 else if (m_action == actionDragFloatingPane)
3485 {
3486 m_frame->ReleaseMouse();
3487 }
3488 else if (m_action == actionDragToolbarPane)
3489 {
3490 m_frame->ReleaseMouse();
3491
3492 wxPaneInfo& pane = GetPane(m_action_window);
3493 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3494
3495 // save the new positions
3496 wxDockInfoPtrArray docks;
3497 FindDocks(m_docks, pane.dock_direction,
3498 pane.dock_layer, pane.dock_row, docks);
3499 if (docks.GetCount() == 1)
3500 {
3501 wxDockInfo& dock = *docks.Item(0);
3502
3503 wxArrayInt pane_positions, pane_sizes;
3504 GetPanePositionsAndSizes(dock, pane_positions, pane_sizes);
3505
3506 int i, dock_pane_count = dock.panes.GetCount();
3507 for (i = 0; i < dock_pane_count; ++i)
3508 dock.panes.Item(i)->dock_pos = pane_positions[i];
3509 }
3510
3511 pane.state &= ~wxPaneInfo::actionPane;
3512 Update();
3513 }
3514 else
3515 {
3516 event.Skip();
3517 }
3518
3519 m_action = actionNone;
3520 m_last_mouse_move = wxPoint(); // see comment in OnMotion()
3521 }
3522
3523
3524 void wxFrameManager::OnMotion(wxMouseEvent& event)
3525 {
3526 // sometimes when Update() is called from inside this method,
3527 // a spurious mouse move event is generated; this check will make
3528 // sure that only real mouse moves will get anywhere in this method;
3529 // this appears to be a bug somewhere, and I don't know where the
3530 // mouse move event is being generated. only verified on MSW
3531
3532 wxPoint mouse_pos = event.GetPosition();
3533 if (m_last_mouse_move == mouse_pos)
3534 return;
3535 m_last_mouse_move = mouse_pos;
3536
3537
3538 if (m_action == actionResize)
3539 {
3540 wxPoint pos = m_action_part->rect.GetPosition();
3541 if (m_action_part->orientation == wxHORIZONTAL)
3542 pos.y = wxMax(0, event.m_y - m_action_offset.y);
3543 else
3544 pos.x = wxMax(0, event.m_x - m_action_offset.x);
3545
3546 wxRect rect(m_frame->ClientToScreen(pos),
3547 m_action_part->rect.GetSize());
3548
3549 wxScreenDC dc;
3550 if (!m_action_hintrect.IsEmpty())
3551 DrawResizeHint(dc, m_action_hintrect);
3552 DrawResizeHint(dc, rect);
3553 m_action_hintrect = rect;
3554 }
3555 else if (m_action == actionClickCaption)
3556 {
3557 int drag_x_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_X);
3558 int drag_y_threshold = wxSystemSettings::GetMetric(wxSYS_DRAG_Y);
3559
3560 // caption has been clicked. we need to check if the mouse
3561 // is now being dragged. if it is, we need to change the
3562 // mouse action to 'drag'
3563 if (abs(event.m_x - m_action_start.x) > drag_x_threshold ||
3564 abs(event.m_y - m_action_start.y) > drag_y_threshold)
3565 {
3566 wxPaneInfo* pane_info = m_action_part->pane;
3567
3568 if (!pane_info->IsToolbar())
3569 {
3570 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
3571 pane_info->IsFloatable())
3572 {
3573 m_action = actionDragFloatingPane;
3574
3575 // set initial float position
3576 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
3577 pane_info->floating_pos = wxPoint(pt.x - m_action_offset.x,
3578 pt.y - m_action_offset.y);
3579 // float the window
3580 pane_info->Float();
3581 Update();
3582
3583 m_action_window = pane_info->frame;
3584
3585 // action offset is used here to make it feel "natural" to the user
3586 // to drag a docked pane and suddenly have it become a floating frame.
3587 // Sometimes, however, the offset where the user clicked on the docked
3588 // caption is bigger than the width of the floating frame itself, so
3589 // in that case we need to set the action offset to a sensible value
3590 wxSize frame_size = m_action_window->GetSize();
3591 if (frame_size.x <= m_action_offset.x)
3592 m_action_offset.x = 30;
3593 }
3594 }
3595 else
3596 {
3597 m_action = actionDragToolbarPane;
3598 m_action_window = pane_info->window;
3599 }
3600 }
3601 }
3602 else if (m_action == actionDragFloatingPane)
3603 {
3604 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
3605 m_action_window->Move(pt.x - m_action_offset.x,
3606 pt.y - m_action_offset.y);
3607 }
3608 else if (m_action == actionDragToolbarPane)
3609 {
3610 wxPaneInfo& pane = GetPane(m_action_window);
3611 wxASSERT_MSG(pane.IsOk(), wxT("Pane window not found"));
3612
3613 pane.state |= wxPaneInfo::actionPane;
3614
3615 wxPoint pt = event.GetPosition();
3616 DoDrop(m_docks, m_panes, pane, pt, m_action_offset);
3617
3618 // if DoDrop() decided to float the pane, set up
3619 // the floating pane's initial position
3620 if (pane.IsFloating())
3621 {
3622 wxPoint pt = m_frame->ClientToScreen(event.GetPosition());
3623 pane.floating_pos = wxPoint(pt.x - m_action_offset.x,
3624 pt.y - m_action_offset.y);
3625 }
3626
3627 // this will do the actiual move operation;
3628 // in the case that the pane has been floated,
3629 // this call will create the floating pane
3630 // and do the reparenting
3631 Update();
3632
3633 // if the pane has been floated, change the mouse
3634 // action actionDragFloatingPane so that subsequent
3635 // EVT_MOTION() events will move the floating pane
3636 if (pane.IsFloating())
3637 {
3638 pane.state &= ~wxPaneInfo::actionPane;
3639 m_action = actionDragFloatingPane;
3640 m_action_window = pane.frame;
3641 }
3642 }
3643 else
3644 {
3645 wxDockUIPart* part = HitTest(event.GetX(), event.GetY());
3646 if (part && part->type == wxDockUIPart::typePaneButton)
3647 {
3648 if (part != m_hover_button)
3649 {
3650 // make the old button normal
3651 if (m_hover_button)
3652 UpdateButtonOnScreen(m_hover_button, event);
3653
3654 // mouse is over a button, so repaint the
3655 // button in hover mode
3656 UpdateButtonOnScreen(part, event);
3657 m_hover_button = part;
3658 }
3659 }
3660 else
3661 {
3662 if (m_hover_button)
3663 {
3664 m_hover_button = NULL;
3665 Repaint();
3666 }
3667 else
3668 {
3669 event.Skip();
3670 }
3671 }
3672 }
3673 }
3674
3675 void wxFrameManager::OnLeaveWindow(wxMouseEvent& WXUNUSED(event))
3676 {
3677 if (m_hover_button)
3678 {
3679 m_hover_button = NULL;
3680 Repaint();
3681 }
3682 }
3683
3684 void wxFrameManager::OnChildFocus(wxChildFocusEvent& event)
3685 {
3686 // when a child pane has it's focus set, we should change the
3687 // pane's active state to reflect this. (this is only true if
3688 // active panes are allowed by the owner)
3689 if (GetFlags() & wxAUI_MGR_ALLOW_ACTIVE_PANE)
3690 {
3691 if (GetPane(event.GetWindow()).IsOk())
3692 {
3693 SetActivePane(m_panes, event.GetWindow());
3694 m_frame->Refresh();
3695 }
3696 }
3697
3698 event.Skip();
3699 }
3700
3701
3702 // OnPaneButton() is an event handler that is called
3703 // when a pane button has been pressed.
3704 void wxFrameManager::OnPaneButton(wxFrameManagerEvent& evt)
3705 {
3706 wxASSERT_MSG(evt.pane, wxT("Pane Info passed to wxFrameManager::OnPaneButton must be non-null"));
3707
3708 wxPaneInfo& pane = *(evt.pane);
3709
3710 if (evt.button == wxPaneInfo::buttonClose)
3711 {
3712 // fire pane close event
3713 wxFrameManagerEvent e(wxEVT_AUI_PANECLOSE);
3714 e.SetPane(evt.pane);
3715 ProcessMgrEvent(e);
3716
3717 if (!e.GetVeto())
3718 {
3719 pane.Hide();
3720 Update();
3721 }
3722 }
3723 else if (evt.button == wxPaneInfo::buttonPin)
3724 {
3725 if ((m_flags & wxAUI_MGR_ALLOW_FLOATING) &&
3726 pane.IsFloatable())
3727 pane.Float();
3728 Update();
3729 }
3730 }
3731
3732 #endif // wxUSE_AUI