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