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