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