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