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