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