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