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