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