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