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