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