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