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