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