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