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