]> git.saurik.com Git - wxWidgets.git/blame - src/aui/floatpane.cpp
Fixes for semicolons, commas and wxSTRING_MAXLEN from Wlodek Szafran.
[wxWidgets.git] / src / aui / floatpane.cpp
CommitLineData
50acee04 1///////////////////////////////////////////////////////////////////////////////
be66f18e 2// Name: src/aui/floatpane.cpp
50acee04
JS
3// Purpose: wxaui: wx advanced user interface - docking window manager
4// Author: Benjamin I. Williams
5// Modified by:
6// Created: 2005-05-17
be66f18e 7// RCS-ID: $Id$
50acee04
JS
8// Copyright: (C) Copyright 2005-2006, Kirix Corporation, All Rights Reserved
9// Licence: wxWindows Library Licence, Version 3.1
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#if wxUSE_AUI
27
28#include "wx/aui/framemanager.h"
29#include "wx/aui/floatpane.h"
30#include "wx/aui/dockart.h"
31
32#ifndef WX_PRECOMP
50acee04
JS
33#endif
34
e5ab82d3
AB
35IMPLEMENT_CLASS( wxFloatingPane, wxFloatingPaneBaseClass )
36
50acee04
JS
37wxFloatingPane::wxFloatingPane(wxWindow* parent,
38 wxFrameManager* owner_mgr,
e5ab82d3 39 const wxPaneInfo& pane,
bc429ce0
RR
40 wxWindowID id /*= wxID_ANY*/,
41 long style /*=wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION |
42 wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT |
43 wxCLIP_CHILDREN
44 */)
e5ab82d3
AB
45 : wxFloatingPaneBaseClass(parent, id, wxEmptyString,
46 pane.floating_pos, pane.floating_size,
bc429ce0 47 style |
96743140 48 (pane.HasCloseButton()?wxCLOSE_BOX:0) |
e5ab82d3
AB
49 (pane.IsFixed()?0:wxRESIZE_BORDER)
50 )
50acee04
JS
51{
52 m_owner_mgr = owner_mgr;
53 m_moving = false;
461125ea 54 m_mgr.SetManagedWindow(this);
322c5ec4 55 SetExtraStyle(wxWS_EX_PROCESS_IDLE);
50acee04
JS
56}
57
58wxFloatingPane::~wxFloatingPane()
59{
60 m_mgr.UnInit();
61}
62
63void wxFloatingPane::SetPaneWindow(const wxPaneInfo& pane)
64{
65 m_pane_window = pane.window;
66 m_pane_window->Reparent(this);
be66f18e 67
50acee04
JS
68 wxPaneInfo contained_pane = pane;
69 contained_pane.Dock().Center().Show().
70 CaptionVisible(false).
71 PaneBorder(false).
72 Layer(0).Row(0).Position(0);
be66f18e 73
5c62cb6c
AB
74 // Carry over the minimum size
75 SetMinSize(pane.window->GetMinSize());
76
50acee04 77 m_mgr.AddPane(m_pane_window, contained_pane);
be66f18e 78 m_mgr.Update();
50acee04
JS
79
80 if (pane.min_size.IsFullySpecified())
81 {
82 // because SetSizeHints() calls Fit() too (which sets the window
83 // size to its minimum allowed), we keep the size before calling
84 // SetSizeHints() and reset it afterwards...
85 wxSize tmp = GetSize();
86 GetSizer()->SetSizeHints(this);
87 SetSize(tmp);
88 }
be66f18e 89
50acee04
JS
90 SetTitle(pane.caption);
91
50acee04
JS
92 if (pane.floating_size != wxDefaultSize)
93 {
94 SetSize(pane.floating_size);
95 }
96 else
97 {
98 wxSize size = pane.best_size;
99 if (size == wxDefaultSize)
100 size = pane.min_size;
101 if (size == wxDefaultSize)
102 size = m_pane_window->GetSize();
103 if (pane.HasGripper())
104 {
105 if (pane.HasGripperTop())
106 size.y += m_owner_mgr->m_art->GetMetric(wxAUI_ART_GRIPPER_SIZE);
107 else
108 size.x += m_owner_mgr->m_art->GetMetric(wxAUI_ART_GRIPPER_SIZE);
109 }
be66f18e 110
50acee04
JS
111 SetClientSize(size);
112 }
113}
114
115void wxFloatingPane::OnSize(wxSizeEvent& event)
116{
117 m_owner_mgr->OnFloatingPaneResized(m_pane_window, event.GetSize());
118}
119
58754643 120void wxFloatingPane::OnClose(wxCloseEvent& evt)
50acee04 121{
58754643
BW
122 m_owner_mgr->OnFloatingPaneClosed(m_pane_window, evt);
123 if (!evt.GetVeto())
c68038f3 124 Destroy();
50acee04
JS
125}
126
127void wxFloatingPane::OnMoveEvent(wxMoveEvent& event)
128{
129 wxRect win_rect = GetRect();
130
322c5ec4
RR
131 if (win_rect == m_last_rect)
132 return;
133
50acee04
JS
134 // skip the first move event
135 if (m_last_rect.IsEmpty())
136 {
137 m_last_rect = win_rect;
138 return;
139 }
140
322c5ec4
RR
141 // skip if moving too fast to avoid massive redraws and
142 // jumping hint windows
143 if ((abs(win_rect.x - m_last_rect.x) > 3) ||
144 (abs(win_rect.y - m_last_rect.y) > 3))
0ae3bace 145 {
322c5ec4
RR
146 m_last3_rect = m_last2_rect;
147 m_last2_rect = m_last_rect;
0ae3bace
RR
148 m_last_rect = win_rect;
149 return;
150 }
151
50acee04
JS
152 // prevent frame redocking during resize
153 if (m_last_rect.GetSize() != win_rect.GetSize())
154 {
322c5ec4
RR
155 m_last3_rect = m_last2_rect;
156 m_last2_rect = m_last_rect;
50acee04
JS
157 m_last_rect = win_rect;
158 return;
159 }
160
322c5ec4
RR
161 wxDirection dir = wxALL;
162
163 int horiz_dist = abs(win_rect.x - m_last3_rect.x);
164 int vert_dist = abs(win_rect.y - m_last3_rect.y);
165
166 if (vert_dist >= horiz_dist)
167 {
168 if (win_rect.y < m_last3_rect.y)
169 dir = wxNORTH;
170 else
171 dir = wxSOUTH;
172 }
173 else
174 {
175 if (win_rect.x < m_last3_rect.x)
176 dir = wxWEST;
177 else
178 dir = wxEAST;
179 }
180
181 m_last3_rect = m_last2_rect;
182 m_last2_rect = m_last_rect;
50acee04 183 m_last_rect = win_rect;
be66f18e 184
50acee04
JS
185 if (!isMouseDown())
186 return;
187
188 if (!m_moving)
189 {
190 OnMoveStart();
191 m_moving = true;
192 }
193
322c5ec4
RR
194 if (m_last3_rect.IsEmpty())
195 return;
196
197 OnMoving(event.GetRect(), dir );
50acee04
JS
198}
199
200void wxFloatingPane::OnIdle(wxIdleEvent& event)
201{
202 if (m_moving)
203 {
204 if (!isMouseDown())
205 {
206 m_moving = false;
207 OnMoveFinished();
208 }
209 else
210 {
211 event.RequestMore();
212 }
213 }
214}
215
216void wxFloatingPane::OnMoveStart()
217{
218 // notify the owner manager that the pane has started to move
219 m_owner_mgr->OnFloatingPaneMoveStart(m_pane_window);
220}
221
322c5ec4 222void wxFloatingPane::OnMoving(const wxRect& WXUNUSED(window_rect), wxDirection dir)
50acee04
JS
223{
224 // notify the owner manager that the pane is moving
322c5ec4
RR
225 m_owner_mgr->OnFloatingPaneMoving(m_pane_window, dir);
226 m_lastDirection = dir;
50acee04
JS
227}
228
229void wxFloatingPane::OnMoveFinished()
230{
231 // notify the owner manager that the pane has finished moving
322c5ec4 232 m_owner_mgr->OnFloatingPaneMoved(m_pane_window, m_lastDirection);
50acee04
JS
233}
234
235void wxFloatingPane::OnActivate(wxActivateEvent& event)
236{
237 if (event.GetActive())
238 {
239 m_owner_mgr->OnFloatingPaneActivated(m_pane_window);
240 }
241}
242
243// utility function which determines the state of the mouse button
244// (independant of having a wxMouseEvent handy) - utimately a better
245// mechanism for this should be found (possibly by adding the
246// functionality to wxWidgets itself)
247bool wxFloatingPane::isMouseDown()
248{
249 return wxGetMouseState().LeftDown();
250}
251
252
253BEGIN_EVENT_TABLE(wxFloatingPane, wxFloatingPaneBaseClass)
254 EVT_SIZE(wxFloatingPane::OnSize)
255 EVT_MOVE(wxFloatingPane::OnMoveEvent)
256 EVT_MOVING(wxFloatingPane::OnMoveEvent)
257 EVT_CLOSE(wxFloatingPane::OnClose)
258 EVT_IDLE(wxFloatingPane::OnIdle)
259 EVT_ACTIVATE(wxFloatingPane::OnActivate)
260END_EVENT_TABLE()
261
262
263#endif // wxUSE_AUI