]>
Commit | Line | Data |
---|---|---|
7ec1983b | 1 | ///////////////////////////////////////////////////////////////////////////// |
7ec69821 | 2 | // Name: src/common/window.cpp |
7ec1983b VZ |
3 | // Purpose: common (to all ports) wxWindow functions |
4 | // Author: Julian Smart, Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 13/07/98 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
7ec1983b VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
f03fc89f VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
f701d7ab | 19 | |
341287bf JS |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
f701d7ab | 23 | #ifdef __BORLANDC__ |
f03fc89f | 24 | #pragma hdrstop |
f701d7ab JS |
25 | #endif |
26 | ||
f03fc89f VZ |
27 | #ifndef WX_PRECOMP |
28 | #include "wx/string.h" | |
29 | #include "wx/log.h" | |
30 | #include "wx/intl.h" | |
31 | #include "wx/frame.h" | |
f03fc89f | 32 | #include "wx/window.h" |
1e6feb95 | 33 | #include "wx/control.h" |
f03fc89f VZ |
34 | #include "wx/checkbox.h" |
35 | #include "wx/radiobut.h" | |
106844da | 36 | #include "wx/statbox.h" |
26bf1ce0 | 37 | #include "wx/textctrl.h" |
f03fc89f VZ |
38 | #include "wx/settings.h" |
39 | #include "wx/dialog.h" | |
a02dc3e3 | 40 | #include "wx/msgdlg.h" |
1b942d5f | 41 | #include "wx/msgout.h" |
a37a5a73 | 42 | #include "wx/statusbr.h" |
e0cf3745 | 43 | #include "wx/toolbar.h" |
ed39ff57 | 44 | #include "wx/dcclient.h" |
7d59475e | 45 | #include "wx/scrolbar.h" |
f03fc89f | 46 | #include "wx/layout.h" |
ed2fbeb8 | 47 | #include "wx/sizer.h" |
8515098c | 48 | #include "wx/menu.h" |
ed2fbeb8 | 49 | #endif //WX_PRECOMP |
461e93f9 | 50 | |
f03fc89f VZ |
51 | #if wxUSE_DRAG_AND_DROP |
52 | #include "wx/dnd.h" | |
53 | #endif // wxUSE_DRAG_AND_DROP | |
54 | ||
ed5317e5 | 55 | #if wxUSE_ACCESSIBILITY |
7de59551 | 56 | #include "wx/access.h" |
ed5317e5 JS |
57 | #endif |
58 | ||
bd83cb56 VZ |
59 | #if wxUSE_HELP |
60 | #include "wx/cshelp.h" | |
61 | #endif // wxUSE_HELP | |
62 | ||
f03fc89f VZ |
63 | #if wxUSE_TOOLTIPS |
64 | #include "wx/tooltip.h" | |
65 | #endif // wxUSE_TOOLTIPS | |
66 | ||
789295bf VZ |
67 | #if wxUSE_CARET |
68 | #include "wx/caret.h" | |
69 | #endif // wxUSE_CARET | |
70 | ||
ff9f7a12 | 71 | #if wxUSE_SYSTEM_OPTIONS |
cab1a605 | 72 | #include "wx/sysopt.h" |
ff9f7a12 SC |
73 | #endif |
74 | ||
8bb6b2c0 | 75 | #include "wx/platinfo.h" |
5c3c1372 VS |
76 | #include "wx/private/window.h" |
77 | ||
78 | #ifdef __WXMSW__ | |
79 | #include "wx/msw/wrapwin.h" | |
80 | #endif | |
8bb6b2c0 | 81 | |
e7445ff8 PC |
82 | // Windows List |
83 | WXDLLIMPEXP_DATA_CORE(wxWindowList) wxTopLevelWindows; | |
84 | ||
eeb0bee1 | 85 | // globals |
8bb08801 | 86 | #if wxUSE_MENUS |
eeb0bee1 | 87 | wxMenu *wxCurrentPopupMenu = NULL; |
8bb08801 | 88 | #endif // wxUSE_MENUS |
eeb0bee1 | 89 | |
f03fc89f VZ |
90 | // ---------------------------------------------------------------------------- |
91 | // static data | |
92 | // ---------------------------------------------------------------------------- | |
93 | ||
f03fc89f VZ |
94 | |
95 | IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler) | |
96 | ||
97 | // ---------------------------------------------------------------------------- | |
98 | // event table | |
99 | // ---------------------------------------------------------------------------- | |
100 | ||
101 | BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler) | |
102 | EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged) | |
103 | EVT_INIT_DIALOG(wxWindowBase::OnInitDialog) | |
a02dc3e3 | 104 | EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick) |
bd83cb56 VZ |
105 | |
106 | #if wxUSE_HELP | |
e11f4636 | 107 | EVT_HELP(wxID_ANY, wxWindowBase::OnHelp) |
bd83cb56 VZ |
108 | #endif // wxUSE_HELP |
109 | ||
6528a7f1 | 110 | EVT_SIZE(wxWindowBase::InternalOnSize) |
f03fc89f VZ |
111 | END_EVENT_TABLE() |
112 | ||
113 | // ============================================================================ | |
114 | // implementation of the common functionality of the wxWindow class | |
115 | // ============================================================================ | |
116 | ||
28953245 SC |
117 | // ---------------------------------------------------------------------------- |
118 | // XTI | |
119 | // ---------------------------------------------------------------------------- | |
120 | ||
121 | #if wxUSE_EXTENDED_RTTI | |
122 | ||
123 | // windows that are created from a parent window during its Create method, | |
124 | // eg. spin controls in a calendar controls must never been streamed out | |
125 | // separately otherwise chaos occurs. Right now easiest is to test for negative ids, | |
126 | // as windows with negative ids never can be recreated anyway | |
127 | ||
128 | bool wxWindowStreamingCallback( const wxObject *object, wxObjectWriter *, | |
129 | wxObjectReaderCallback *, wxVariantBaseArray & ) | |
130 | { | |
131 | const wxWindow * win = wx_dynamic_cast(const wxWindow*, object); | |
132 | if ( win && win->GetId() < 0 ) | |
133 | return false; | |
134 | return true; | |
135 | } | |
136 | ||
137 | wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow, wxWindowBase, "wx/window.h", \ | |
138 | wxWindowStreamingCallback) | |
139 | ||
140 | // make wxWindowList known before the property is used | |
141 | ||
142 | wxCOLLECTION_TYPE_INFO( wxWindow*, wxWindowList ); | |
143 | ||
144 | template<> void wxCollectionToVariantArray( wxWindowList const &theList, | |
145 | wxVariantBaseArray &value) | |
146 | { | |
147 | wxListCollectionToVariantArray<wxWindowList::compatibility_iterator>( theList, value ); | |
148 | } | |
149 | ||
150 | wxDEFINE_FLAGS( wxWindowStyle ) | |
151 | ||
152 | wxBEGIN_FLAGS( wxWindowStyle ) | |
153 | // new style border flags, we put them first to | |
154 | // use them for streaming out | |
155 | ||
156 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) | |
157 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
158 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
159 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
160 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
161 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
162 | ||
163 | // old style border flags | |
164 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) | |
165 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
166 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
167 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
168 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
169 | wxFLAGS_MEMBER(wxBORDER) | |
170 | ||
171 | // standard window styles | |
172 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) | |
173 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
174 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
175 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
176 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) | |
177 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) | |
178 | wxFLAGS_MEMBER(wxVSCROLL) | |
179 | wxFLAGS_MEMBER(wxHSCROLL) | |
180 | ||
181 | wxEND_FLAGS( wxWindowStyle ) | |
182 | ||
183 | wxBEGIN_PROPERTIES_TABLE(wxWindow) | |
184 | wxEVENT_PROPERTY( Close, wxEVT_CLOSE_WINDOW, wxCloseEvent) | |
185 | wxEVENT_PROPERTY( Create, wxEVT_CREATE, wxWindowCreateEvent ) | |
186 | wxEVENT_PROPERTY( Destroy, wxEVT_DESTROY, wxWindowDestroyEvent ) | |
187 | // Always constructor Properties first | |
188 | ||
189 | wxREADONLY_PROPERTY( Parent,wxWindow*, GetParent, wxEMPTY_PARAMETER_VALUE, \ | |
190 | 0 /*flags*/, wxT("Helpstring"), wxT("group")) | |
191 | wxPROPERTY( Id,wxWindowID, SetId, GetId, -1 /*wxID_ANY*/, 0 /*flags*/, \ | |
192 | wxT("Helpstring"), wxT("group") ) | |
193 | wxPROPERTY( Position,wxPoint, SetPosition, GetPosition, wxDefaultPosition, \ | |
194 | 0 /*flags*/, wxT("Helpstring"), wxT("group")) // pos | |
195 | wxPROPERTY( Size,wxSize, SetSize, GetSize, wxDefaultSize, 0 /*flags*/, \ | |
196 | wxT("Helpstring"), wxT("group")) // size | |
197 | wxPROPERTY( WindowStyle, long, SetWindowStyleFlag, GetWindowStyleFlag, \ | |
198 | wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // style | |
199 | wxPROPERTY( Name,wxString, SetName, GetName, wxEmptyString, 0 /*flags*/, \ | |
200 | wxT("Helpstring"), wxT("group") ) | |
201 | ||
202 | // Then all relations of the object graph | |
203 | ||
204 | wxREADONLY_PROPERTY_COLLECTION( Children, wxWindowList, wxWindowBase*, \ | |
205 | GetWindowChildren, wxPROP_OBJECT_GRAPH /*flags*/, \ | |
206 | wxT("Helpstring"), wxT("group")) | |
207 | ||
208 | // and finally all other properties | |
209 | ||
210 | wxPROPERTY( ExtraStyle, long, SetExtraStyle, GetExtraStyle, wxEMPTY_PARAMETER_VALUE, \ | |
211 | 0 /*flags*/, wxT("Helpstring"), wxT("group")) // extstyle | |
212 | wxPROPERTY( BackgroundColour, wxColour, SetBackgroundColour, GetBackgroundColour, \ | |
213 | wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // bg | |
214 | wxPROPERTY( ForegroundColour, wxColour, SetForegroundColour, GetForegroundColour, \ | |
215 | wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // fg | |
216 | wxPROPERTY( Enabled, bool, Enable, IsEnabled, wxVariantBase((bool)true), 0 /*flags*/, \ | |
217 | wxT("Helpstring"), wxT("group")) | |
218 | wxPROPERTY( Shown, bool, Show, IsShown, wxVariantBase((bool)true), 0 /*flags*/, \ | |
219 | wxT("Helpstring"), wxT("group")) | |
220 | ||
221 | #if 0 | |
222 | // possible property candidates (not in xrc) or not valid in all subclasses | |
223 | wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxEmptyString ) | |
224 | wxPROPERTY( Font, wxFont, SetFont, GetWindowFont , ) | |
225 | wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxEmptyString ) | |
226 | // MaxHeight, Width, MinHeight, Width | |
227 | // TODO switch label to control and title to toplevels | |
228 | ||
229 | wxPROPERTY( ThemeEnabled, bool, SetThemeEnabled, GetThemeEnabled, ) | |
230 | //wxPROPERTY( Cursor, wxCursor, SetCursor, GetCursor, ) | |
231 | // wxPROPERTY( ToolTip, wxString, SetToolTip, GetToolTipText, ) | |
232 | wxPROPERTY( AutoLayout, bool, SetAutoLayout, GetAutoLayout, ) | |
233 | #endif | |
234 | wxEND_PROPERTIES_TABLE() | |
235 | ||
236 | wxEMPTY_HANDLERS_TABLE(wxWindow) | |
237 | ||
238 | wxCONSTRUCTOR_DUMMY(wxWindow) | |
239 | ||
240 | #else | |
241 | ||
242 | #ifndef __WXUNIVERSAL__ | |
243 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) | |
244 | #endif | |
245 | ||
246 | #endif | |
247 | ||
f03fc89f VZ |
248 | // ---------------------------------------------------------------------------- |
249 | // initialization | |
250 | // ---------------------------------------------------------------------------- | |
251 | ||
252 | // the default initialization | |
72795335 | 253 | wxWindowBase::wxWindowBase() |
f03fc89f VZ |
254 | { |
255 | // no window yet, no parent nor children | |
d3b9f782 | 256 | m_parent = NULL; |
e11f4636 | 257 | m_windowId = wxID_ANY; |
f03fc89f VZ |
258 | |
259 | // no constraints on the minimal window size | |
260 | m_minWidth = | |
422d0ff0 | 261 | m_maxWidth = wxDefaultCoord; |
f03fc89f | 262 | m_minHeight = |
422d0ff0 | 263 | m_maxHeight = wxDefaultCoord; |
f03fc89f | 264 | |
9f884528 RD |
265 | // invalidiated cache value |
266 | m_bestSizeCache = wxDefaultSize; | |
267 | ||
eefe6d4b VZ |
268 | // window are created enabled and visible by default |
269 | m_isShown = | |
e11f4636 | 270 | m_isEnabled = true; |
f03fc89f | 271 | |
f03fc89f VZ |
272 | // the default event handler is just this window |
273 | m_eventHandler = this; | |
274 | ||
88ac883a | 275 | #if wxUSE_VALIDATORS |
f03fc89f | 276 | // no validator |
d3b9f782 | 277 | m_windowValidator = NULL; |
88ac883a | 278 | #endif // wxUSE_VALIDATORS |
f03fc89f | 279 | |
1b69c815 VZ |
280 | // the colours/fonts are default for now, so leave m_font, |
281 | // m_backgroundColour and m_foregroundColour uninitialized and set those | |
08df3e44 VZ |
282 | m_hasBgCol = |
283 | m_hasFgCol = | |
e11f4636 | 284 | m_hasFont = false; |
f8ff87ed VS |
285 | m_inheritBgCol = |
286 | m_inheritFgCol = | |
287 | m_inheritFont = false; | |
e11f4636 | 288 | |
f03fc89f | 289 | // no style bits |
d80cd92a | 290 | m_exStyle = |
f03fc89f | 291 | m_windowStyle = 0; |
cab1a605 | 292 | |
9c61c5b0 | 293 | m_backgroundStyle = wxBG_STYLE_ERASE; |
f03fc89f | 294 | |
f03fc89f VZ |
295 | #if wxUSE_CONSTRAINTS |
296 | // no constraints whatsoever | |
d3b9f782 VZ |
297 | m_constraints = NULL; |
298 | m_constraintsInvolvedIn = NULL; | |
461e93f9 JS |
299 | #endif // wxUSE_CONSTRAINTS |
300 | ||
d3b9f782 VZ |
301 | m_windowSizer = NULL; |
302 | m_containingSizer = NULL; | |
e11f4636 | 303 | m_autoLayout = false; |
f03fc89f VZ |
304 | |
305 | #if wxUSE_DRAG_AND_DROP | |
d3b9f782 | 306 | m_dropTarget = NULL; |
f03fc89f VZ |
307 | #endif // wxUSE_DRAG_AND_DROP |
308 | ||
309 | #if wxUSE_TOOLTIPS | |
d3b9f782 | 310 | m_tooltip = NULL; |
f03fc89f | 311 | #endif // wxUSE_TOOLTIPS |
789295bf VZ |
312 | |
313 | #if wxUSE_CARET | |
d3b9f782 | 314 | m_caret = NULL; |
789295bf | 315 | #endif // wxUSE_CARET |
a2d93e73 | 316 | |
574c939e | 317 | #if wxUSE_PALETTE |
e11f4636 | 318 | m_hasCustomPalette = false; |
574c939e KB |
319 | #endif // wxUSE_PALETTE |
320 | ||
ed5317e5 JS |
321 | #if wxUSE_ACCESSIBILITY |
322 | m_accessible = NULL; | |
323 | #endif | |
324 | ||
566d84a7 | 325 | m_virtualSize = wxDefaultSize; |
1b69c815 | 326 | |
d3b9f782 | 327 | m_scrollHelper = NULL; |
f4fe2f20 | 328 | |
1b69c815 | 329 | m_windowVariant = wxWINDOW_VARIANT_NORMAL; |
ff9f7a12 SC |
330 | #if wxUSE_SYSTEM_OPTIONS |
331 | if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT) ) | |
332 | { | |
333 | m_windowVariant = (wxWindowVariant) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT ) ; | |
334 | } | |
335 | #endif | |
69d90995 | 336 | |
a2d93e73 | 337 | // Whether we're using the current theme for this window (wxGTK only for now) |
e11f4636 | 338 | m_themeEnabled = false; |
1b69c815 | 339 | |
c6212a0c VZ |
340 | // This is set to true by SendDestroyEvent() which should be called by the |
341 | // most derived class to ensure that the destruction event is sent as soon | |
342 | // as possible to allow its handlers to still see the undestroyed window | |
1b69c815 | 343 | m_isBeingDeleted = false; |
17808a75 VZ |
344 | |
345 | m_freezeCount = 0; | |
f03fc89f VZ |
346 | } |
347 | ||
348 | // common part of window creation process | |
349 | bool wxWindowBase::CreateBase(wxWindowBase *parent, | |
350 | wxWindowID id, | |
74e3313b | 351 | const wxPoint& WXUNUSED(pos), |
032e024c | 352 | const wxSize& size, |
f03fc89f VZ |
353 | long style, |
354 | const wxString& name) | |
355 | { | |
925f154d VZ |
356 | // ids are limited to 16 bits under MSW so if you care about portability, |
357 | // it's not a good idea to use ids out of this range (and negative ids are | |
77ffb593 | 358 | // reserved for wxWidgets own usage) |
f35fdf7e VZ |
359 | wxASSERT_MSG( id == wxID_ANY || (id >= 0 && id < 32767) || |
360 | (id >= wxID_AUTO_LOWEST && id <= wxID_AUTO_HIGHEST), | |
9a83f860 | 361 | wxT("invalid id value") ); |
925f154d | 362 | |
f03fc89f | 363 | // generate a new id if the user doesn't care about it |
f35fdf7e VZ |
364 | if ( id == wxID_ANY ) |
365 | { | |
366 | m_windowId = NewControlId(); | |
f35fdf7e VZ |
367 | } |
368 | else // valid id specified | |
369 | { | |
370 | m_windowId = id; | |
371 | } | |
f03fc89f | 372 | |
e96248c4 VZ |
373 | // don't use SetWindowStyleFlag() here, this function should only be called |
374 | // to change the flag after creation as it tries to reflect the changes in | |
375 | // flags by updating the window dynamically and we don't need this here | |
376 | m_windowStyle = style; | |
377 | ||
032e024c VZ |
378 | // assume the user doesn't want this window to shrink beneath its initial |
379 | // size, this worked like this in wxWidgets 2.8 and before and generally | |
62354609 VZ |
380 | // often makes sense for child windows (for top level ones it definitely |
381 | // does not as the user should be able to resize the window) | |
54a3120e VZ |
382 | // |
383 | // note that we can't use IsTopLevel() from ctor | |
653351d1 | 384 | if ( size != wxDefaultSize && !wxTopLevelWindows.Find((wxWindow *)this) ) |
62354609 | 385 | SetMinSize(size); |
032e024c | 386 | |
f03fc89f | 387 | SetName(name); |
f03fc89f | 388 | SetParent(parent); |
674ac8b9 | 389 | |
2973301f VZ |
390 | return true; |
391 | } | |
392 | ||
393 | bool wxWindowBase::CreateBase(wxWindowBase *parent, | |
394 | wxWindowID id, | |
395 | const wxPoint& pos, | |
396 | const wxSize& size, | |
397 | long style, | |
398 | const wxValidator& wxVALIDATOR_PARAM(validator), | |
399 | const wxString& name) | |
400 | { | |
401 | if ( !CreateBase(parent, id, pos, size, style, name) ) | |
402 | return false; | |
403 | ||
674ac8b9 | 404 | #if wxUSE_VALIDATORS |
8d99be5f | 405 | SetValidator(validator); |
674ac8b9 | 406 | #endif // wxUSE_VALIDATORS |
f03fc89f | 407 | |
8ae6ce07 VZ |
408 | // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to |
409 | // have it too - like this it's possible to set it only in the top level | |
410 | // dialog/frame and all children will inherit it by defult | |
411 | if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) ) | |
412 | { | |
9cb98d89 | 413 | SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY); |
8ae6ce07 VZ |
414 | } |
415 | ||
e11f4636 | 416 | return true; |
f03fc89f VZ |
417 | } |
418 | ||
d63312a9 VZ |
419 | bool wxWindowBase::ToggleWindowStyle(int flag) |
420 | { | |
9a83f860 | 421 | wxASSERT_MSG( flag, wxT("flags with 0 value can't be toggled") ); |
d63312a9 VZ |
422 | |
423 | bool rc; | |
424 | long style = GetWindowStyleFlag(); | |
425 | if ( style & flag ) | |
426 | { | |
427 | style &= ~flag; | |
428 | rc = false; | |
429 | } | |
430 | else // currently off | |
431 | { | |
432 | style |= flag; | |
433 | rc = true; | |
434 | } | |
435 | ||
436 | SetWindowStyleFlag(style); | |
437 | ||
438 | return rc; | |
439 | } | |
440 | ||
f03fc89f VZ |
441 | // ---------------------------------------------------------------------------- |
442 | // destruction | |
443 | // ---------------------------------------------------------------------------- | |
444 | ||
445 | // common clean up | |
446 | wxWindowBase::~wxWindowBase() | |
447 | { | |
349d1942 VS |
448 | wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") ); |
449 | ||
f03fc89f VZ |
450 | // FIXME if these 2 cases result from programming errors in the user code |
451 | // we should probably assert here instead of silently fixing them | |
452 | ||
453 | // Just in case the window has been Closed, but we're then deleting | |
454 | // immediately: don't leave dangling pointers. | |
455 | wxPendingDelete.DeleteObject(this); | |
456 | ||
457 | // Just in case we've loaded a top-level window via LoadNativeDialog but | |
458 | // we weren't a dialog class | |
222ed1d6 | 459 | wxTopLevelWindows.DeleteObject((wxWindow*)this); |
a23fd0e1 | 460 | |
4b621e4c VZ |
461 | // Any additional event handlers should be popped before the window is |
462 | // deleted as otherwise the last handler will be left with a dangling | |
463 | // pointer to this window result in a difficult to diagnose crash later on. | |
464 | wxASSERT_MSG( GetEventHandler() == this, | |
465 | wxT("any pushed event handlers must have been removed") ); | |
466 | ||
3bc9aac0 | 467 | #if wxUSE_MENUS |
eeb0bee1 VZ |
468 | // The associated popup menu can still be alive, disassociate from it in |
469 | // this case | |
470 | if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetInvokingWindow() == this ) | |
471 | wxCurrentPopupMenu->SetInvokingWindow(NULL); | |
3bc9aac0 | 472 | #endif // wxUSE_MENUS |
eeb0bee1 | 473 | |
223d09f6 | 474 | wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") ); |
f03fc89f | 475 | |
f8ab85ae | 476 | // notify the parent about this window destruction |
f09df8b2 | 477 | if ( m_parent ) |
8e35ab96 | 478 | m_parent->RemoveChild(this); |
8e35ab96 | 479 | |
789295bf | 480 | #if wxUSE_CARET |
a2b436fb | 481 | delete m_caret; |
789295bf VZ |
482 | #endif // wxUSE_CARET |
483 | ||
88ac883a | 484 | #if wxUSE_VALIDATORS |
a2b436fb | 485 | delete m_windowValidator; |
88ac883a | 486 | #endif // wxUSE_VALIDATORS |
f03fc89f | 487 | |
f03fc89f VZ |
488 | #if wxUSE_CONSTRAINTS |
489 | // Have to delete constraints/sizer FIRST otherwise sizers may try to look | |
490 | // at deleted windows as they delete themselves. | |
491 | DeleteRelatedConstraints(); | |
492 | ||
493 | if ( m_constraints ) | |
494 | { | |
495 | // This removes any dangling pointers to this window in other windows' | |
496 | // constraintsInvolvedIn lists. | |
497 | UnsetConstraints(m_constraints); | |
5276b0a5 | 498 | wxDELETE(m_constraints); |
f03fc89f | 499 | } |
461e93f9 JS |
500 | #endif // wxUSE_CONSTRAINTS |
501 | ||
be90c029 | 502 | if ( m_containingSizer ) |
12a3f227 | 503 | m_containingSizer->Detach( (wxWindow*)this ); |
be90c029 | 504 | |
a2b436fb | 505 | delete m_windowSizer; |
f03fc89f | 506 | |
f03fc89f | 507 | #if wxUSE_DRAG_AND_DROP |
a2b436fb | 508 | delete m_dropTarget; |
f03fc89f VZ |
509 | #endif // wxUSE_DRAG_AND_DROP |
510 | ||
511 | #if wxUSE_TOOLTIPS | |
a2b436fb | 512 | delete m_tooltip; |
f03fc89f | 513 | #endif // wxUSE_TOOLTIPS |
b0ee47ff | 514 | |
ed5317e5 | 515 | #if wxUSE_ACCESSIBILITY |
a2b436fb | 516 | delete m_accessible; |
ed5317e5 | 517 | #endif |
d18d8bda VS |
518 | |
519 | #if wxUSE_HELP | |
520 | // NB: this has to be called unconditionally, because we don't know | |
521 | // whether this window has associated help text or not | |
522 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
523 | if ( helpProvider ) | |
524 | helpProvider->RemoveHelp(this); | |
525 | #endif | |
f03fc89f VZ |
526 | } |
527 | ||
a3ac93e3 VZ |
528 | bool wxWindowBase::IsBeingDeleted() const |
529 | { | |
530 | return m_isBeingDeleted || | |
531 | (!IsTopLevel() && m_parent && m_parent->IsBeingDeleted()); | |
532 | } | |
533 | ||
602a2e02 VZ |
534 | void wxWindowBase::SendDestroyEvent() |
535 | { | |
c6212a0c VZ |
536 | if ( m_isBeingDeleted ) |
537 | { | |
538 | // we could have been already called from a more derived class dtor, | |
539 | // e.g. ~wxTLW calls us and so does ~wxWindow and the latter call | |
540 | // should be simply ignored | |
541 | return; | |
542 | } | |
543 | ||
544 | m_isBeingDeleted = true; | |
545 | ||
602a2e02 VZ |
546 | wxWindowDestroyEvent event; |
547 | event.SetEventObject(this); | |
548 | event.SetId(GetId()); | |
549 | GetEventHandler()->ProcessEvent(event); | |
550 | } | |
551 | ||
f03fc89f VZ |
552 | bool wxWindowBase::Destroy() |
553 | { | |
a79a6671 VZ |
554 | SendDestroyEvent(); |
555 | ||
f03fc89f VZ |
556 | delete this; |
557 | ||
e11f4636 | 558 | return true; |
f03fc89f VZ |
559 | } |
560 | ||
561 | bool wxWindowBase::Close(bool force) | |
562 | { | |
563 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); | |
564 | event.SetEventObject(this); | |
f03fc89f VZ |
565 | event.SetCanVeto(!force); |
566 | ||
e11f4636 | 567 | // return false if window wasn't closed because the application vetoed the |
f03fc89f | 568 | // close event |
a50c5fcc | 569 | return HandleWindowEvent(event) && !event.GetVeto(); |
f03fc89f VZ |
570 | } |
571 | ||
572 | bool wxWindowBase::DestroyChildren() | |
573 | { | |
222ed1d6 | 574 | wxWindowList::compatibility_iterator node; |
a23fd0e1 | 575 | for ( ;; ) |
f03fc89f | 576 | { |
a23fd0e1 VZ |
577 | // we iterate until the list becomes empty |
578 | node = GetChildren().GetFirst(); | |
579 | if ( !node ) | |
580 | break; | |
581 | ||
f03fc89f | 582 | wxWindow *child = node->GetData(); |
a23fd0e1 | 583 | |
a79a6671 VZ |
584 | // note that we really want to delete it immediately so don't call the |
585 | // possible overridden Destroy() version which might not delete the | |
586 | // child immediately resulting in problems with our (top level) child | |
587 | // outliving its parent | |
588 | child->wxWindowBase::Destroy(); | |
a23fd0e1 VZ |
589 | |
590 | wxASSERT_MSG( !GetChildren().Find(child), | |
223d09f6 | 591 | wxT("child didn't remove itself using RemoveChild()") ); |
f03fc89f VZ |
592 | } |
593 | ||
e11f4636 | 594 | return true; |
f03fc89f VZ |
595 | } |
596 | ||
597 | // ---------------------------------------------------------------------------- | |
f68586e5 | 598 | // size/position related methods |
f03fc89f VZ |
599 | // ---------------------------------------------------------------------------- |
600 | ||
601 | // centre the window with respect to its parent in either (or both) directions | |
1f464296 | 602 | void wxWindowBase::DoCentre(int dir) |
f03fc89f | 603 | { |
1f464296 | 604 | wxCHECK_RET( !(dir & wxCENTRE_ON_SCREEN) && GetParent(), |
9a83f860 | 605 | wxT("this method only implements centering child windows") ); |
ef397583 | 606 | |
1f464296 | 607 | SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir)); |
7631a292 RD |
608 | } |
609 | ||
f03fc89f VZ |
610 | // fits the window around the children |
611 | void wxWindowBase::Fit() | |
612 | { | |
74205969 | 613 | if ( !GetChildren().empty() ) |
f68586e5 | 614 | { |
1736f021 | 615 | SetSize(GetBestSize()); |
f68586e5 VZ |
616 | } |
617 | //else: do nothing if we have no children | |
618 | } | |
f03fc89f | 619 | |
2b5f62a0 VZ |
620 | // fits virtual size (ie. scrolled area etc.) around children |
621 | void wxWindowBase::FitInside() | |
622 | { | |
623 | if ( GetChildren().GetCount() > 0 ) | |
624 | { | |
625 | SetVirtualSize( GetBestVirtualSize() ); | |
626 | } | |
627 | } | |
628 | ||
7d59475e | 629 | // On Mac, scrollbars are explicitly children. |
d7928233 | 630 | #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) |
7d59475e JS |
631 | static bool wxHasRealChildren(const wxWindowBase* win) |
632 | { | |
633 | int realChildCount = 0; | |
cab1a605 | 634 | |
7d59475e JS |
635 | for ( wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst(); |
636 | node; | |
637 | node = node->GetNext() ) | |
638 | { | |
639 | wxWindow *win = node->GetData(); | |
c5cc7fbd | 640 | if ( !win->IsTopLevel() && win->IsShown() |
9504069e SC |
641 | #if wxUSE_SCROLLBAR |
642 | && !win->IsKindOf(CLASSINFO(wxScrollBar)) | |
643 | #endif | |
644 | ) | |
7d59475e JS |
645 | realChildCount ++; |
646 | } | |
647 | return (realChildCount > 0); | |
648 | } | |
649 | #endif | |
ba889513 | 650 | |
992b2ec4 VS |
651 | void wxWindowBase::InvalidateBestSize() |
652 | { | |
653 | m_bestSizeCache = wxDefaultSize; | |
654 | ||
655 | // parent's best size calculation may depend on its children's | |
5b7df27e WS |
656 | // as long as child window we are in is not top level window itself |
657 | // (because the TLW size is never resized automatically) | |
658 | // so let's invalidate it as well to be safe: | |
5ff84587 | 659 | if (m_parent && !IsTopLevel()) |
992b2ec4 VS |
660 | m_parent->InvalidateBestSize(); |
661 | } | |
7d59475e | 662 | |
f68586e5 VZ |
663 | // return the size best suited for the current window |
664 | wxSize wxWindowBase::DoGetBestSize() const | |
665 | { | |
08a19f64 | 666 | wxSize best; |
2997ca30 | 667 | |
ec5bb70d VZ |
668 | if ( m_windowSizer ) |
669 | { | |
7e0f7539 | 670 | best = m_windowSizer->GetMinSize(); |
ec5bb70d VZ |
671 | } |
672 | #if wxUSE_CONSTRAINTS | |
673 | else if ( m_constraints ) | |
674 | { | |
675 | wxConstCast(this, wxWindowBase)->SatisfyConstraints(); | |
676 | ||
677 | // our minimal acceptable size is such that all our windows fit inside | |
678 | int maxX = 0, | |
679 | maxY = 0; | |
680 | ||
222ed1d6 | 681 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
ec5bb70d VZ |
682 | node; |
683 | node = node->GetNext() ) | |
684 | { | |
685 | wxLayoutConstraints *c = node->GetData()->GetConstraints(); | |
686 | if ( !c ) | |
687 | { | |
688 | // it's not normal that we have an unconstrained child, but | |
689 | // what can we do about it? | |
690 | continue; | |
691 | } | |
692 | ||
693 | int x = c->right.GetValue(), | |
694 | y = c->bottom.GetValue(); | |
695 | ||
696 | if ( x > maxX ) | |
697 | maxX = x; | |
698 | ||
699 | if ( y > maxY ) | |
700 | maxY = y; | |
701 | ||
702 | // TODO: we must calculate the overlaps somehow, otherwise we | |
703 | // will never return a size bigger than the current one :-( | |
704 | } | |
705 | ||
08a19f64 | 706 | best = wxSize(maxX, maxY); |
ec5bb70d VZ |
707 | } |
708 | #endif // wxUSE_CONSTRAINTS | |
7d59475e | 709 | else if ( !GetChildren().empty() |
d7928233 | 710 | #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) |
7d59475e JS |
711 | && wxHasRealChildren(this) |
712 | #endif | |
713 | ) | |
f03fc89f | 714 | { |
54af2461 VZ |
715 | // our minimal acceptable size is such that all our visible child |
716 | // windows fit inside | |
f68586e5 VZ |
717 | int maxX = 0, |
718 | maxY = 0; | |
719 | ||
222ed1d6 | 720 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
f68586e5 VZ |
721 | node; |
722 | node = node->GetNext() ) | |
42e69d6b | 723 | { |
f68586e5 | 724 | wxWindow *win = node->GetData(); |
54af2461 VZ |
725 | if ( win->IsTopLevel() |
726 | || !win->IsShown() | |
1e6feb95 | 727 | #if wxUSE_STATUSBAR |
54af2461 | 728 | || wxDynamicCast(win, wxStatusBar) |
1e6feb95 VZ |
729 | #endif // wxUSE_STATUSBAR |
730 | ) | |
f68586e5 VZ |
731 | { |
732 | // dialogs and frames lie in different top level windows - | |
7d9fd004 VZ |
733 | // don't deal with them here; as for the status bars, they |
734 | // don't lie in the client area at all | |
f68586e5 VZ |
735 | continue; |
736 | } | |
737 | ||
738 | int wx, wy, ww, wh; | |
739 | win->GetPosition(&wx, &wy); | |
3f5513f5 VZ |
740 | |
741 | // if the window hadn't been positioned yet, assume that it is in | |
742 | // the origin | |
422d0ff0 | 743 | if ( wx == wxDefaultCoord ) |
3f5513f5 | 744 | wx = 0; |
422d0ff0 | 745 | if ( wy == wxDefaultCoord ) |
3f5513f5 VZ |
746 | wy = 0; |
747 | ||
f68586e5 VZ |
748 | win->GetSize(&ww, &wh); |
749 | if ( wx + ww > maxX ) | |
750 | maxX = wx + ww; | |
751 | if ( wy + wh > maxY ) | |
752 | maxY = wy + wh; | |
42e69d6b VZ |
753 | } |
754 | ||
08a19f64 | 755 | best = wxSize(maxX, maxY); |
f68586e5 | 756 | } |
997c7280 | 757 | else // ! has children |
f68586e5 | 758 | { |
9240613a VZ |
759 | wxSize size = GetMinSize(); |
760 | if ( !size.IsFullySpecified() ) | |
761 | { | |
7ccc497b VZ |
762 | // if the window doesn't define its best size we assume that it can |
763 | // be arbitrarily small -- usually this is not the case, of course, | |
764 | // but we have no way to know what the limit is, it should really | |
765 | // override DoGetBestClientSize() itself to tell us | |
766 | size.SetDefaults(wxSize(1, 1)); | |
9240613a | 767 | } |
c0bb586f VZ |
768 | |
769 | // return as-is, unadjusted by the client size difference. | |
9240613a | 770 | return size; |
f03fc89f | 771 | } |
08a19f64 RD |
772 | |
773 | // Add any difference between size and client size | |
774 | wxSize diff = GetSize() - GetClientSize(); | |
775 | best.x += wxMax(0, diff.x); | |
776 | best.y += wxMax(0, diff.y); | |
777 | ||
778 | return best; | |
f03fc89f VZ |
779 | } |
780 | ||
333d7052 VZ |
781 | // helper of GetWindowBorderSize(): as many ports don't implement support for |
782 | // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded | |
783 | // fallbacks in this case | |
d45a01e0 | 784 | static int wxGetMetricOrDefault(wxSystemMetric what, const wxWindowBase* win) |
333d7052 | 785 | { |
d45a01e0 PC |
786 | int rc = wxSystemSettings::GetMetric( |
787 | what, static_cast<wxWindow*>(const_cast<wxWindowBase*>(win))); | |
333d7052 VZ |
788 | if ( rc == -1 ) |
789 | { | |
790 | switch ( what ) | |
791 | { | |
792 | case wxSYS_BORDER_X: | |
793 | case wxSYS_BORDER_Y: | |
794 | // 2D border is by default 1 pixel wide | |
795 | rc = 1; | |
796 | break; | |
797 | ||
798 | case wxSYS_EDGE_X: | |
799 | case wxSYS_EDGE_Y: | |
800 | // 3D borders are by default 2 pixels | |
801 | rc = 2; | |
802 | break; | |
803 | ||
804 | default: | |
9a83f860 | 805 | wxFAIL_MSG( wxT("unexpected wxGetMetricOrDefault() argument") ); |
333d7052 VZ |
806 | rc = 0; |
807 | } | |
808 | } | |
809 | ||
810 | return rc; | |
811 | } | |
812 | ||
813 | wxSize wxWindowBase::GetWindowBorderSize() const | |
814 | { | |
815 | wxSize size; | |
816 | ||
817 | switch ( GetBorder() ) | |
818 | { | |
819 | case wxBORDER_NONE: | |
820 | // nothing to do, size is already (0, 0) | |
821 | break; | |
822 | ||
823 | case wxBORDER_SIMPLE: | |
824 | case wxBORDER_STATIC: | |
d45a01e0 PC |
825 | size.x = wxGetMetricOrDefault(wxSYS_BORDER_X, this); |
826 | size.y = wxGetMetricOrDefault(wxSYS_BORDER_Y, this); | |
333d7052 VZ |
827 | break; |
828 | ||
829 | case wxBORDER_SUNKEN: | |
830 | case wxBORDER_RAISED: | |
d45a01e0 PC |
831 | size.x = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X, this), |
832 | wxGetMetricOrDefault(wxSYS_BORDER_X, this)); | |
833 | size.y = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y, this), | |
834 | wxGetMetricOrDefault(wxSYS_BORDER_Y, this)); | |
333d7052 VZ |
835 | break; |
836 | ||
837 | case wxBORDER_DOUBLE: | |
d45a01e0 PC |
838 | size.x = wxGetMetricOrDefault(wxSYS_EDGE_X, this) + |
839 | wxGetMetricOrDefault(wxSYS_BORDER_X, this); | |
840 | size.y = wxGetMetricOrDefault(wxSYS_EDGE_Y, this) + | |
841 | wxGetMetricOrDefault(wxSYS_BORDER_Y, this); | |
333d7052 VZ |
842 | break; |
843 | ||
844 | default: | |
9a83f860 | 845 | wxFAIL_MSG(wxT("Unknown border style.")); |
333d7052 VZ |
846 | break; |
847 | } | |
848 | ||
849 | // we have borders on both sides | |
850 | return size*2; | |
851 | } | |
9f884528 | 852 | |
170acdc9 | 853 | wxSize wxWindowBase::GetEffectiveMinSize() const |
400a9e41 | 854 | { |
9f884528 RD |
855 | // merge the best size with the min size, giving priority to the min size |
856 | wxSize min = GetMinSize(); | |
1b942d5f | 857 | |
9f884528 | 858 | if (min.x == wxDefaultCoord || min.y == wxDefaultCoord) |
400a9e41 | 859 | { |
9f884528 RD |
860 | wxSize best = GetBestSize(); |
861 | if (min.x == wxDefaultCoord) min.x = best.x; | |
862 | if (min.y == wxDefaultCoord) min.y = best.y; | |
17c48da8 | 863 | } |
1b942d5f | 864 | |
9f884528 RD |
865 | return min; |
866 | } | |
17c48da8 | 867 | |
d7d943a7 VZ |
868 | wxSize wxWindowBase::DoGetBorderSize() const |
869 | { | |
b3554952 | 870 | // there is one case in which we can implement it for all ports easily |
d7d943a7 VZ |
871 | if ( GetBorder() == wxBORDER_NONE ) |
872 | return wxSize(0, 0); | |
873 | ||
b3554952 VZ |
874 | // otherwise use the difference between the real size and the client size |
875 | // as a fallback: notice that this is incorrect in general as client size | |
876 | // also doesn't take the scrollbars into account | |
877 | return GetSize() - GetClientSize(); | |
d7d943a7 VZ |
878 | } |
879 | ||
26f7724c RR |
880 | wxSize wxWindowBase::GetBestSize() const |
881 | { | |
743b4266 | 882 | if ( !m_windowSizer && m_bestSizeCache.IsFullySpecified() ) |
26f7724c | 883 | return m_bestSizeCache; |
1b942d5f | 884 | |
743b4266 VZ |
885 | // call DoGetBestClientSize() first, if a derived class overrides it wants |
886 | // it to be used | |
887 | wxSize size = DoGetBestClientSize(); | |
888 | if ( size != wxDefaultSize ) | |
889 | { | |
890 | size += DoGetBorderSize(); | |
891 | ||
892 | CacheBestSize(size); | |
893 | return size; | |
894 | } | |
895 | ||
26f7724c RR |
896 | return DoGetBestSize(); |
897 | } | |
42cfa184 | 898 | |
e81c7155 | 899 | void wxWindowBase::SetMinSize(const wxSize& minSize) |
1b942d5f FM |
900 | { |
901 | m_minWidth = minSize.x; | |
902 | m_minHeight = minSize.y; | |
e81c7155 RR |
903 | } |
904 | ||
905 | void wxWindowBase::SetMaxSize(const wxSize& maxSize) | |
1b942d5f FM |
906 | { |
907 | m_maxWidth = maxSize.x; | |
e81c7155 RR |
908 | m_maxHeight = maxSize.y; |
909 | } | |
910 | ||
170acdc9 | 911 | void wxWindowBase::SetInitialSize(const wxSize& size) |
9f884528 RD |
912 | { |
913 | // Set the min size to the size passed in. This will usually either be | |
914 | // wxDefaultSize or the size passed to this window's ctor/Create function. | |
915 | SetMinSize(size); | |
916 | ||
917 | // Merge the size with the best size if needed | |
170acdc9 | 918 | wxSize best = GetEffectiveMinSize(); |
cab1a605 | 919 | |
9f884528 RD |
920 | // If the current size doesn't match then change it |
921 | if (GetSize() != best) | |
922 | SetSize(best); | |
400a9e41 VZ |
923 | } |
924 | ||
9f884528 | 925 | |
1e6feb95 VZ |
926 | // by default the origin is not shifted |
927 | wxPoint wxWindowBase::GetClientAreaOrigin() const | |
928 | { | |
c47addef | 929 | return wxPoint(0,0); |
1e6feb95 VZ |
930 | } |
931 | ||
301d7a0d VS |
932 | wxSize wxWindowBase::ClientToWindowSize(const wxSize& size) const |
933 | { | |
934 | const wxSize diff(GetSize() - GetClientSize()); | |
935 | ||
936 | return wxSize(size.x == -1 ? -1 : size.x + diff.x, | |
937 | size.y == -1 ? -1 : size.y + diff.y); | |
938 | } | |
939 | ||
940 | wxSize wxWindowBase::WindowToClientSize(const wxSize& size) const | |
941 | { | |
942 | const wxSize diff(GetSize() - GetClientSize()); | |
943 | ||
944 | return wxSize(size.x == -1 ? -1 : size.x - diff.x, | |
945 | size.y == -1 ? -1 : size.y - diff.y); | |
946 | } | |
947 | ||
69d90995 SC |
948 | void wxWindowBase::SetWindowVariant( wxWindowVariant variant ) |
949 | { | |
1b69c815 VZ |
950 | if ( m_windowVariant != variant ) |
951 | { | |
952 | m_windowVariant = variant; | |
69d90995 | 953 | |
1b69c815 VZ |
954 | DoSetWindowVariant(variant); |
955 | } | |
69d90995 SC |
956 | } |
957 | ||
958 | void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant ) | |
959 | { | |
1b69c815 VZ |
960 | // adjust the font height to correspond to our new variant (notice that |
961 | // we're only called if something really changed) | |
962 | wxFont font = GetFont(); | |
963 | int size = font.GetPointSize(); | |
69d90995 SC |
964 | switch ( variant ) |
965 | { | |
1b69c815 VZ |
966 | case wxWINDOW_VARIANT_NORMAL: |
967 | break; | |
968 | ||
969 | case wxWINDOW_VARIANT_SMALL: | |
c063e450 | 970 | size = wxRound(size * 3.0 / 4.0); |
1b69c815 VZ |
971 | break; |
972 | ||
973 | case wxWINDOW_VARIANT_MINI: | |
c063e450 | 974 | size = wxRound(size * 2.0 / 3.0); |
1b69c815 VZ |
975 | break; |
976 | ||
977 | case wxWINDOW_VARIANT_LARGE: | |
c063e450 | 978 | size = wxRound(size * 5.0 / 4.0); |
1b69c815 VZ |
979 | break; |
980 | ||
69d90995 | 981 | default: |
9a83f860 | 982 | wxFAIL_MSG(wxT("unexpected window variant")); |
1b69c815 | 983 | break; |
69d90995 | 984 | } |
1b69c815 VZ |
985 | |
986 | font.SetPointSize(size); | |
987 | SetFont(font); | |
69d90995 SC |
988 | } |
989 | ||
b21f4960 RR |
990 | void wxWindowBase::DoSetSizeHints( int minW, int minH, |
991 | int maxW, int maxH, | |
f36978ba | 992 | int WXUNUSED(incW), int WXUNUSED(incH) ) |
b21f4960 RR |
993 | { |
994 | wxCHECK_RET( (minW == wxDefaultCoord || maxW == wxDefaultCoord || minW <= maxW) && | |
995 | (minH == wxDefaultCoord || maxH == wxDefaultCoord || minH <= maxH), | |
9a83f860 | 996 | wxT("min width/height must be less than max width/height!") ); |
b21f4960 RR |
997 | |
998 | m_minWidth = minW; | |
999 | m_maxWidth = maxW; | |
1000 | m_minHeight = minH; | |
1001 | m_maxHeight = maxH; | |
1002 | } | |
1003 | ||
1004 | ||
f944aec0 VS |
1005 | #if WXWIN_COMPATIBILITY_2_8 |
1006 | void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW), int WXUNUSED(minH), | |
1007 | int WXUNUSED(maxW), int WXUNUSED(maxH)) | |
566d84a7 | 1008 | { |
566d84a7 RL |
1009 | } |
1010 | ||
f944aec0 VS |
1011 | void wxWindowBase::SetVirtualSizeHints(const wxSize& WXUNUSED(minsize), |
1012 | const wxSize& WXUNUSED(maxsize)) | |
566d84a7 | 1013 | { |
f944aec0 VS |
1014 | } |
1015 | #endif // WXWIN_COMPATIBILITY_2_8 | |
1e2a653b | 1016 | |
f944aec0 VS |
1017 | void wxWindowBase::DoSetVirtualSize( int x, int y ) |
1018 | { | |
1e2a653b | 1019 | m_virtualSize = wxSize(x, y); |
566d84a7 RL |
1020 | } |
1021 | ||
1022 | wxSize wxWindowBase::DoGetVirtualSize() const | |
1023 | { | |
143e2719 VZ |
1024 | // we should use the entire client area so if it is greater than our |
1025 | // virtual size, expand it to fit (otherwise if the window is big enough we | |
1026 | // wouldn't be using parts of it) | |
c20ab85b | 1027 | wxSize size = GetClientSize(); |
143e2719 | 1028 | if ( m_virtualSize.x > size.x ) |
c20ab85b VZ |
1029 | size.x = m_virtualSize.x; |
1030 | ||
143e2719 | 1031 | if ( m_virtualSize.y >= size.y ) |
c20ab85b VZ |
1032 | size.y = m_virtualSize.y; |
1033 | ||
1034 | return size; | |
566d84a7 RL |
1035 | } |
1036 | ||
3c81c9aa VZ |
1037 | void wxWindowBase::DoGetScreenPosition(int *x, int *y) const |
1038 | { | |
1039 | // screen position is the same as (0, 0) in client coords for non TLWs (and | |
1040 | // TLWs override this method) | |
1041 | if ( x ) | |
1042 | *x = 0; | |
1043 | if ( y ) | |
1044 | *y = 0; | |
1045 | ||
aa738eb8 | 1046 | ClientToScreen(x, y); |
3c81c9aa VZ |
1047 | } |
1048 | ||
ecdc1183 | 1049 | void wxWindowBase::SendSizeEvent(int flags) |
0dba08dd VZ |
1050 | { |
1051 | wxSizeEvent event(GetSize(), GetId()); | |
1052 | event.SetEventObject(this); | |
ecdc1183 VZ |
1053 | if ( flags & wxSEND_EVENT_POST ) |
1054 | wxPostEvent(this, event); | |
1055 | else | |
1056 | HandleWindowEvent(event); | |
0dba08dd VZ |
1057 | } |
1058 | ||
ecdc1183 | 1059 | void wxWindowBase::SendSizeEventToParent(int flags) |
0dba08dd VZ |
1060 | { |
1061 | wxWindow * const parent = GetParent(); | |
1062 | if ( parent && !parent->IsBeingDeleted() ) | |
ecdc1183 | 1063 | parent->SendSizeEvent(flags); |
0dba08dd VZ |
1064 | } |
1065 | ||
c5cc7fbd VZ |
1066 | bool wxWindowBase::HasScrollbar(int orient) const |
1067 | { | |
1068 | // if scrolling in the given direction is disabled, we can't have the | |
1069 | // corresponding scrollbar no matter what | |
1070 | if ( !CanScroll(orient) ) | |
1071 | return false; | |
1072 | ||
1073 | const wxSize sizeVirt = GetVirtualSize(); | |
1074 | const wxSize sizeClient = GetClientSize(); | |
1075 | ||
1076 | return orient == wxHORIZONTAL ? sizeVirt.x > sizeClient.x | |
1077 | : sizeVirt.y > sizeClient.y; | |
1078 | } | |
1079 | ||
f03fc89f VZ |
1080 | // ---------------------------------------------------------------------------- |
1081 | // show/hide/enable/disable the window | |
1082 | // ---------------------------------------------------------------------------- | |
1083 | ||
1084 | bool wxWindowBase::Show(bool show) | |
1085 | { | |
1086 | if ( show != m_isShown ) | |
1087 | { | |
1088 | m_isShown = show; | |
1089 | ||
e11f4636 | 1090 | return true; |
f03fc89f VZ |
1091 | } |
1092 | else | |
1093 | { | |
e11f4636 | 1094 | return false; |
f03fc89f VZ |
1095 | } |
1096 | } | |
1097 | ||
47a8a4d5 | 1098 | bool wxWindowBase::IsEnabled() const |
f03fc89f | 1099 | { |
47a8a4d5 VZ |
1100 | return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled()); |
1101 | } | |
f03fc89f | 1102 | |
47a8a4d5 VZ |
1103 | void wxWindowBase::NotifyWindowOnEnableChange(bool enabled) |
1104 | { | |
a0fe7703 VZ |
1105 | // Under some platforms there is no need to update the window state |
1106 | // explicitly, it will become disabled when its parent is. On other ones we | |
1107 | // do need to disable all windows recursively though. | |
47a8a4d5 VZ |
1108 | #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT |
1109 | DoEnable(enabled); | |
1110 | #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT) | |
1111 | ||
1112 | OnEnabled(enabled); | |
1113 | ||
a0fe7703 VZ |
1114 | // Disabling a top level window is typically done when showing a modal |
1115 | // dialog and we don't need to disable its children in this case, they will | |
1116 | // be logically disabled anyhow (i.e. their IsEnabled() will return false) | |
1117 | // and the TLW won't accept any input for them. Moreover, explicitly | |
1118 | // disabling them would look ugly as the entire TLW would be greyed out | |
1119 | // whenever a modal dialog is shown and no native applications under any | |
1120 | // platform behave like this. | |
1121 | if ( IsTopLevel() && !enabled ) | |
47a8a4d5 VZ |
1122 | return; |
1123 | ||
a0fe7703 VZ |
1124 | // When disabling (or enabling back) a non-TLW window we need to |
1125 | // recursively propagate the change of the state to its children, otherwise | |
1126 | // they would still show as enabled even though they wouldn't actually | |
1127 | // accept any input (at least under MSW where children don't accept input | |
1128 | // if any of the windows in their parent chain is enabled). | |
1129 | // | |
1130 | // Notice that we must do this even for wxHAS_NATIVE_ENABLED_MANAGEMENT | |
1131 | // platforms as we still need to call the children OnEnabled() recursively. | |
47a8a4d5 VZ |
1132 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
1133 | node; | |
1134 | node = node->GetNext() ) | |
f03fc89f | 1135 | { |
47a8a4d5 VZ |
1136 | wxWindowBase * const child = node->GetData(); |
1137 | if ( !child->IsTopLevel() && child->IsThisEnabled() ) | |
1138 | child->NotifyWindowOnEnableChange(enabled); | |
1139 | } | |
1140 | } | |
1141 | ||
1142 | bool wxWindowBase::Enable(bool enable) | |
1143 | { | |
1144 | if ( enable == IsThisEnabled() ) | |
e11f4636 | 1145 | return false; |
47a8a4d5 VZ |
1146 | |
1147 | m_isEnabled = enable; | |
1148 | ||
a0fe7703 VZ |
1149 | // If we call DoEnable() from NotifyWindowOnEnableChange(), we don't need |
1150 | // to do it from here. | |
47a8a4d5 VZ |
1151 | #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT |
1152 | DoEnable(enable); | |
47a8a4d5 VZ |
1153 | #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT) |
1154 | ||
1155 | NotifyWindowOnEnableChange(enable); | |
1156 | ||
1157 | return true; | |
f03fc89f | 1158 | } |
9c72cf76 | 1159 | |
865a74c7 | 1160 | bool wxWindowBase::IsShownOnScreen() const |
9c72cf76 | 1161 | { |
8a6a997f VS |
1162 | // A window is shown on screen if it itself is shown and so are all its |
1163 | // parents. But if a window is toplevel one, then its always visible on | |
1164 | // screen if IsShown() returns true, even if it has a hidden parent. | |
865a74c7 | 1165 | return IsShown() && |
8a6a997f | 1166 | (IsTopLevel() || GetParent() == NULL || GetParent()->IsShownOnScreen()); |
9c72cf76 VS |
1167 | } |
1168 | ||
34636400 VZ |
1169 | // ---------------------------------------------------------------------------- |
1170 | // RTTI | |
1171 | // ---------------------------------------------------------------------------- | |
1172 | ||
1173 | bool wxWindowBase::IsTopLevel() const | |
1174 | { | |
e11f4636 | 1175 | return false; |
34636400 | 1176 | } |
f03fc89f | 1177 | |
1c8e5c51 VS |
1178 | // ---------------------------------------------------------------------------- |
1179 | // Freeze/Thaw | |
1180 | // ---------------------------------------------------------------------------- | |
1181 | ||
1182 | void wxWindowBase::Freeze() | |
1183 | { | |
1184 | if ( !m_freezeCount++ ) | |
1185 | { | |
1186 | // physically freeze this window: | |
1187 | DoFreeze(); | |
1188 | ||
1189 | // and recursively freeze all children: | |
1190 | for ( wxWindowList::iterator i = GetChildren().begin(); | |
1191 | i != GetChildren().end(); ++i ) | |
1192 | { | |
1193 | wxWindow *child = *i; | |
1194 | if ( child->IsTopLevel() ) | |
1195 | continue; | |
1196 | ||
1197 | child->Freeze(); | |
1198 | } | |
1199 | } | |
1200 | } | |
1201 | ||
1202 | void wxWindowBase::Thaw() | |
1203 | { | |
1204 | wxASSERT_MSG( m_freezeCount, "Thaw() without matching Freeze()" ); | |
1205 | ||
1206 | if ( !--m_freezeCount ) | |
1207 | { | |
1208 | // recursively thaw all children: | |
1209 | for ( wxWindowList::iterator i = GetChildren().begin(); | |
1210 | i != GetChildren().end(); ++i ) | |
1211 | { | |
1212 | wxWindow *child = *i; | |
1213 | if ( child->IsTopLevel() ) | |
1214 | continue; | |
1215 | ||
1216 | child->Thaw(); | |
1217 | } | |
1218 | ||
1219 | // physically thaw this window: | |
1220 | DoThaw(); | |
1221 | } | |
1222 | } | |
1223 | ||
f03fc89f VZ |
1224 | // ---------------------------------------------------------------------------- |
1225 | // reparenting the window | |
1226 | // ---------------------------------------------------------------------------- | |
1227 | ||
1228 | void wxWindowBase::AddChild(wxWindowBase *child) | |
1229 | { | |
223d09f6 | 1230 | wxCHECK_RET( child, wxT("can't add a NULL child") ); |
f03fc89f | 1231 | |
f6bcfd97 BP |
1232 | // this should never happen and it will lead to a crash later if it does |
1233 | // because RemoveChild() will remove only one node from the children list | |
1234 | // and the other(s) one(s) will be left with dangling pointers in them | |
9a83f860 | 1235 | wxASSERT_MSG( !GetChildren().Find((wxWindow*)child), wxT("AddChild() called twice") ); |
f6bcfd97 | 1236 | |
222ed1d6 | 1237 | GetChildren().Append((wxWindow*)child); |
f03fc89f | 1238 | child->SetParent(this); |
1c8e5c51 | 1239 | |
76be36e4 | 1240 | // adding a child while frozen will assert when thawed, so freeze it as if |
1c8e5c51 VS |
1241 | // it had been already present when we were frozen |
1242 | if ( IsFrozen() && !child->IsTopLevel() ) | |
1243 | child->Freeze(); | |
f03fc89f VZ |
1244 | } |
1245 | ||
1246 | void wxWindowBase::RemoveChild(wxWindowBase *child) | |
1247 | { | |
223d09f6 | 1248 | wxCHECK_RET( child, wxT("can't remove a NULL child") ); |
f03fc89f | 1249 | |
1c8e5c51 VS |
1250 | // removing a child while frozen may result in permanently frozen window |
1251 | // if used e.g. from Reparent(), so thaw it | |
76be36e4 VZ |
1252 | // |
1253 | // NB: IsTopLevel() doesn't return true any more when a TLW child is being | |
1254 | // removed from its ~wxWindowBase, so check for IsBeingDeleted() too | |
1255 | if ( IsFrozen() && !child->IsBeingDeleted() && !child->IsTopLevel() ) | |
1c8e5c51 VS |
1256 | child->Thaw(); |
1257 | ||
222ed1d6 MB |
1258 | GetChildren().DeleteObject((wxWindow *)child); |
1259 | child->SetParent(NULL); | |
f03fc89f | 1260 | } |
439b3bf1 | 1261 | |
f03fc89f VZ |
1262 | bool wxWindowBase::Reparent(wxWindowBase *newParent) |
1263 | { | |
1264 | wxWindow *oldParent = GetParent(); | |
1265 | if ( newParent == oldParent ) | |
1266 | { | |
1267 | // nothing done | |
e11f4636 | 1268 | return false; |
f03fc89f VZ |
1269 | } |
1270 | ||
47a8a4d5 VZ |
1271 | const bool oldEnabledState = IsEnabled(); |
1272 | ||
f03fc89f VZ |
1273 | // unlink this window from the existing parent. |
1274 | if ( oldParent ) | |
1275 | { | |
1276 | oldParent->RemoveChild(this); | |
1277 | } | |
1278 | else | |
1279 | { | |
222ed1d6 | 1280 | wxTopLevelWindows.DeleteObject((wxWindow *)this); |
f03fc89f VZ |
1281 | } |
1282 | ||
1283 | // add it to the new one | |
1284 | if ( newParent ) | |
1285 | { | |
1286 | newParent->AddChild(this); | |
1287 | } | |
1288 | else | |
1289 | { | |
222ed1d6 | 1290 | wxTopLevelWindows.Append((wxWindow *)this); |
f03fc89f VZ |
1291 | } |
1292 | ||
47a8a4d5 VZ |
1293 | // We need to notify window (and its subwindows) if by changing the parent |
1294 | // we also change our enabled/disabled status. | |
1295 | const bool newEnabledState = IsEnabled(); | |
1296 | if ( newEnabledState != oldEnabledState ) | |
1297 | { | |
1298 | NotifyWindowOnEnableChange(newEnabledState); | |
1299 | } | |
1300 | ||
e11f4636 | 1301 | return true; |
f03fc89f VZ |
1302 | } |
1303 | ||
1304 | // ---------------------------------------------------------------------------- | |
1305 | // event handler stuff | |
1306 | // ---------------------------------------------------------------------------- | |
1307 | ||
7f853dd0 | 1308 | void wxWindowBase::SetEventHandler(wxEvtHandler *handler) |
f03fc89f | 1309 | { |
7f853dd0 FM |
1310 | wxCHECK_RET(handler != NULL, "SetEventHandler(NULL) called"); |
1311 | ||
1312 | m_eventHandler = handler; | |
1313 | } | |
1314 | ||
1315 | void wxWindowBase::SetNextHandler(wxEvtHandler *WXUNUSED(handler)) | |
1316 | { | |
1317 | // disable wxEvtHandler chain mechanism for wxWindows: | |
1318 | // wxWindow uses its own stack mechanism which doesn't mix well with wxEvtHandler's one | |
1319 | ||
1320 | wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain"); | |
1321 | } | |
1322 | void wxWindowBase::SetPreviousHandler(wxEvtHandler *WXUNUSED(handler)) | |
1323 | { | |
1324 | // we can't simply wxFAIL here as in SetNextHandler: in fact the last | |
1325 | // handler of our stack when is destroyed will be Unlink()ed and thus | |
1326 | // will call this function to update the pointer of this window... | |
1327 | ||
1328 | //wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain"); | |
1329 | } | |
1330 | ||
1331 | void wxWindowBase::PushEventHandler(wxEvtHandler *handlerToPush) | |
1332 | { | |
1333 | wxCHECK_RET( handlerToPush != NULL, "PushEventHandler(NULL) called" ); | |
1334 | ||
1335 | // the new handler is going to be part of the wxWindow stack of event handlers: | |
1336 | // it can't be part also of an event handler double-linked chain: | |
1337 | wxASSERT_MSG(handlerToPush->IsUnlinked(), | |
1338 | "The handler being pushed in the wxWindow stack shouldn't be part of " | |
1339 | "a wxEvtHandler chain; call Unlink() on it first"); | |
1340 | ||
3a074ba8 | 1341 | wxEvtHandler *handlerOld = GetEventHandler(); |
7f853dd0 FM |
1342 | wxCHECK_RET( handlerOld, "an old event handler is NULL?" ); |
1343 | ||
1344 | // now use wxEvtHandler double-linked list to implement a stack: | |
1345 | handlerToPush->SetNextHandler(handlerOld); | |
3a074ba8 | 1346 | |
7f853dd0 FM |
1347 | if (handlerOld != this) |
1348 | handlerOld->SetPreviousHandler(handlerToPush); | |
3a074ba8 | 1349 | |
7f853dd0 | 1350 | SetEventHandler(handlerToPush); |
3a074ba8 | 1351 | |
4b6a582b | 1352 | #if wxDEBUG_LEVEL |
7f853dd0 FM |
1353 | // final checks of the operations done above: |
1354 | wxASSERT_MSG( handlerToPush->GetPreviousHandler() == NULL, | |
4b6a582b VZ |
1355 | "the first handler of the wxWindow stack should " |
1356 | "have no previous handlers set" ); | |
7f853dd0 | 1357 | wxASSERT_MSG( handlerToPush->GetNextHandler() != NULL, |
4b6a582b VZ |
1358 | "the first handler of the wxWindow stack should " |
1359 | "have non-NULL next handler" ); | |
7f853dd0 FM |
1360 | |
1361 | wxEvtHandler* pLast = handlerToPush; | |
4b6a582b | 1362 | while ( pLast && pLast != this ) |
7f853dd0 FM |
1363 | pLast = pLast->GetNextHandler(); |
1364 | wxASSERT_MSG( pLast->GetNextHandler() == NULL, | |
4b6a582b VZ |
1365 | "the last handler of the wxWindow stack should " |
1366 | "have this window as next handler" ); | |
1367 | #endif // wxDEBUG_LEVEL | |
f03fc89f VZ |
1368 | } |
1369 | ||
1370 | wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler) | |
1371 | { | |
7f853dd0 | 1372 | // we need to pop the wxWindow stack, i.e. we need to remove the first handler |
3a074ba8 | 1373 | |
7f853dd0 FM |
1374 | wxEvtHandler *firstHandler = GetEventHandler(); |
1375 | wxCHECK_MSG( firstHandler != NULL, NULL, "wxWindow cannot have a NULL event handler" ); | |
1376 | wxCHECK_MSG( firstHandler != this, NULL, "cannot pop the wxWindow itself" ); | |
1377 | wxCHECK_MSG( firstHandler->GetPreviousHandler() == NULL, NULL, | |
1378 | "the first handler of the wxWindow stack should have no previous handlers set" ); | |
3a074ba8 | 1379 | |
7f853dd0 FM |
1380 | wxEvtHandler *secondHandler = firstHandler->GetNextHandler(); |
1381 | wxCHECK_MSG( secondHandler != NULL, NULL, | |
1382 | "the first handler of the wxWindow stack should have non-NULL next handler" ); | |
1383 | ||
1384 | firstHandler->SetNextHandler(NULL); | |
1385 | secondHandler->SetPreviousHandler(NULL); | |
1386 | ||
1387 | // now firstHandler is completely unlinked; set secondHandler as the new window event handler | |
1388 | SetEventHandler(secondHandler); | |
1389 | ||
1390 | if ( deleteHandler ) | |
1391 | { | |
5276b0a5 | 1392 | wxDELETE(firstHandler); |
f03fc89f VZ |
1393 | } |
1394 | ||
7f853dd0 | 1395 | return firstHandler; |
f03fc89f VZ |
1396 | } |
1397 | ||
7f853dd0 | 1398 | bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handlerToRemove) |
2e36d5cf | 1399 | { |
7f853dd0 FM |
1400 | wxCHECK_MSG( handlerToRemove != NULL, false, "RemoveEventHandler(NULL) called" ); |
1401 | wxCHECK_MSG( handlerToRemove != this, false, "Cannot remove the window itself" ); | |
1402 | ||
1403 | if (handlerToRemove == GetEventHandler()) | |
1404 | { | |
1405 | // removing the first event handler is equivalent to "popping" the stack | |
1406 | PopEventHandler(false); | |
1407 | return true; | |
1408 | } | |
2e36d5cf | 1409 | |
7f853dd0 FM |
1410 | // NOTE: the wxWindow event handler list is always terminated with "this" handler |
1411 | wxEvtHandler *handlerCur = GetEventHandler()->GetNextHandler(); | |
9e96e16f | 1412 | while ( handlerCur != this && handlerCur ) |
2e36d5cf VZ |
1413 | { |
1414 | wxEvtHandler *handlerNext = handlerCur->GetNextHandler(); | |
1415 | ||
7f853dd0 | 1416 | if ( handlerCur == handlerToRemove ) |
2e36d5cf | 1417 | { |
7f853dd0 | 1418 | handlerCur->Unlink(); |
2e36d5cf | 1419 | |
7f853dd0 FM |
1420 | wxASSERT_MSG( handlerCur != GetEventHandler(), |
1421 | "the case Remove == Pop should was already handled" ); | |
e11f4636 | 1422 | return true; |
2e36d5cf VZ |
1423 | } |
1424 | ||
2e36d5cf VZ |
1425 | handlerCur = handlerNext; |
1426 | } | |
1427 | ||
9a83f860 | 1428 | wxFAIL_MSG( wxT("where has the event handler gone?") ); |
2e36d5cf | 1429 | |
e11f4636 | 1430 | return false; |
2e36d5cf VZ |
1431 | } |
1432 | ||
937013e0 VS |
1433 | bool wxWindowBase::HandleWindowEvent(wxEvent& event) const |
1434 | { | |
7f853dd0 | 1435 | // SafelyProcessEvent() will handle exceptions nicely |
937013e0 VS |
1436 | return GetEventHandler()->SafelyProcessEvent(event); |
1437 | } | |
1438 | ||
f03fc89f | 1439 | // ---------------------------------------------------------------------------- |
1b69c815 | 1440 | // colours, fonts &c |
f03fc89f VZ |
1441 | // ---------------------------------------------------------------------------- |
1442 | ||
b8e7b673 VZ |
1443 | void wxWindowBase::InheritAttributes() |
1444 | { | |
8afef133 | 1445 | const wxWindowBase * const parent = GetParent(); |
b8e7b673 VZ |
1446 | if ( !parent ) |
1447 | return; | |
1448 | ||
1449 | // we only inherit attributes which had been explicitly set for the parent | |
1450 | // which ensures that this only happens if the user really wants it and | |
1451 | // not by default which wouldn't make any sense in modern GUIs where the | |
1452 | // controls don't all use the same fonts (nor colours) | |
f8ff87ed | 1453 | if ( parent->m_inheritFont && !m_hasFont ) |
b8e7b673 VZ |
1454 | SetFont(parent->GetFont()); |
1455 | ||
1456 | // in addition, there is a possibility to explicitly forbid inheriting | |
1457 | // colours at each class level by overriding ShouldInheritColours() | |
1458 | if ( ShouldInheritColours() ) | |
1459 | { | |
f8ff87ed | 1460 | if ( parent->m_inheritFgCol && !m_hasFgCol ) |
b8e7b673 VZ |
1461 | SetForegroundColour(parent->GetForegroundColour()); |
1462 | ||
eb96212b VZ |
1463 | // inheriting (solid) background colour is wrong as it totally breaks |
1464 | // any kind of themed backgrounds | |
1465 | // | |
1466 | // instead, the controls should use the same background as their parent | |
1467 | // (ideally by not drawing it at all) | |
1468 | #if 0 | |
f8ff87ed | 1469 | if ( parent->m_inheritBgCol && !m_hasBgCol ) |
b8e7b673 | 1470 | SetBackgroundColour(parent->GetBackgroundColour()); |
eb96212b | 1471 | #endif // 0 |
b8e7b673 VZ |
1472 | } |
1473 | } | |
1474 | ||
1b69c815 VZ |
1475 | /* static */ wxVisualAttributes |
1476 | wxWindowBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
1477 | { | |
1478 | // it is important to return valid values for all attributes from here, | |
1479 | // GetXXX() below rely on this | |
1480 | wxVisualAttributes attrs; | |
1481 | attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
1482 | attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); | |
1b69c815 | 1483 | |
0477a857 JS |
1484 | // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of |
1485 | // the usual background colour than wxSYS_COLOUR_BTNFACE. | |
1486 | // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background | |
1487 | // colour on other platforms. | |
1488 | ||
1489 | #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__)) | |
1490 | attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); | |
1491 | #else | |
1492 | attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); | |
1493 | #endif | |
1b69c815 VZ |
1494 | return attrs; |
1495 | } | |
1496 | ||
1497 | wxColour wxWindowBase::GetBackgroundColour() const | |
1498 | { | |
1117d56f | 1499 | if ( !m_backgroundColour.IsOk() ) |
1b69c815 | 1500 | { |
9a83f860 | 1501 | wxASSERT_MSG( !m_hasBgCol, wxT("we have invalid explicit bg colour?") ); |
1b69c815 VZ |
1502 | |
1503 | // get our default background colour | |
1504 | wxColour colBg = GetDefaultAttributes().colBg; | |
1505 | ||
1506 | // we must return some valid colour to avoid redoing this every time | |
cbab1556 | 1507 | // and also to avoid surprising the applications written for older |
77ffb593 | 1508 | // wxWidgets versions where GetBackgroundColour() always returned |
1b69c815 VZ |
1509 | // something -- so give them something even if it doesn't make sense |
1510 | // for this window (e.g. it has a themed background) | |
1511 | if ( !colBg.Ok() ) | |
1512 | colBg = GetClassDefaultAttributes().colBg; | |
1513 | ||
f604c658 | 1514 | return colBg; |
1b69c815 | 1515 | } |
f604c658 VS |
1516 | else |
1517 | return m_backgroundColour; | |
1b69c815 VZ |
1518 | } |
1519 | ||
1520 | wxColour wxWindowBase::GetForegroundColour() const | |
1521 | { | |
1522 | // logic is the same as above | |
1523 | if ( !m_hasFgCol && !m_foregroundColour.Ok() ) | |
1524 | { | |
1b69c815 VZ |
1525 | wxColour colFg = GetDefaultAttributes().colFg; |
1526 | ||
1117d56f | 1527 | if ( !colFg.IsOk() ) |
1b69c815 VZ |
1528 | colFg = GetClassDefaultAttributes().colFg; |
1529 | ||
f604c658 | 1530 | return colFg; |
1b69c815 | 1531 | } |
f604c658 VS |
1532 | else |
1533 | return m_foregroundColour; | |
1b69c815 VZ |
1534 | } |
1535 | ||
f03fc89f VZ |
1536 | bool wxWindowBase::SetBackgroundColour( const wxColour &colour ) |
1537 | { | |
cab1a605 | 1538 | if ( colour == m_backgroundColour ) |
e11f4636 | 1539 | return false; |
f03fc89f | 1540 | |
1117d56f | 1541 | m_hasBgCol = colour.IsOk(); |
17bcd9a6 | 1542 | |
f8ff87ed | 1543 | m_inheritBgCol = m_hasBgCol; |
f03fc89f | 1544 | m_backgroundColour = colour; |
44dfb5ce | 1545 | SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.Ok() ); |
e11f4636 | 1546 | return true; |
f03fc89f VZ |
1547 | } |
1548 | ||
1549 | bool wxWindowBase::SetForegroundColour( const wxColour &colour ) | |
1550 | { | |
44dfb5ce | 1551 | if (colour == m_foregroundColour ) |
e11f4636 | 1552 | return false; |
f03fc89f | 1553 | |
1117d56f | 1554 | m_hasFgCol = colour.IsOk(); |
f8ff87ed | 1555 | m_inheritFgCol = m_hasFgCol; |
f03fc89f | 1556 | m_foregroundColour = colour; |
44dfb5ce | 1557 | SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() ); |
e11f4636 | 1558 | return true; |
f03fc89f VZ |
1559 | } |
1560 | ||
1561 | bool wxWindowBase::SetCursor(const wxCursor& cursor) | |
1562 | { | |
8a9c2246 VZ |
1563 | // setting an invalid cursor is ok, it means that we don't have any special |
1564 | // cursor | |
a3ab1c18 | 1565 | if ( m_cursor.IsSameAs(cursor) ) |
f03fc89f VZ |
1566 | { |
1567 | // no change | |
e11f4636 | 1568 | return false; |
f03fc89f VZ |
1569 | } |
1570 | ||
8a9c2246 | 1571 | m_cursor = cursor; |
f03fc89f | 1572 | |
e11f4636 | 1573 | return true; |
f03fc89f VZ |
1574 | } |
1575 | ||
f604c658 | 1576 | wxFont wxWindowBase::GetFont() const |
1b69c815 VZ |
1577 | { |
1578 | // logic is the same as in GetBackgroundColour() | |
1117d56f | 1579 | if ( !m_font.IsOk() ) |
1b69c815 | 1580 | { |
9a83f860 | 1581 | wxASSERT_MSG( !m_hasFont, wxT("we have invalid explicit font?") ); |
1b69c815 VZ |
1582 | |
1583 | wxFont font = GetDefaultAttributes().font; | |
1117d56f | 1584 | if ( !font.IsOk() ) |
1b69c815 VZ |
1585 | font = GetClassDefaultAttributes().font; |
1586 | ||
f604c658 | 1587 | return font; |
1b69c815 | 1588 | } |
f604c658 VS |
1589 | else |
1590 | return m_font; | |
1b69c815 VZ |
1591 | } |
1592 | ||
f03fc89f VZ |
1593 | bool wxWindowBase::SetFont(const wxFont& font) |
1594 | { | |
1b69c815 | 1595 | if ( font == m_font ) |
f03fc89f VZ |
1596 | { |
1597 | // no change | |
e11f4636 | 1598 | return false; |
f03fc89f VZ |
1599 | } |
1600 | ||
1b69c815 | 1601 | m_font = font; |
1117d56f | 1602 | m_hasFont = font.IsOk(); |
f8ff87ed | 1603 | m_inheritFont = m_hasFont; |
23895080 | 1604 | |
583d7e55 VS |
1605 | InvalidateBestSize(); |
1606 | ||
e11f4636 | 1607 | return true; |
f03fc89f VZ |
1608 | } |
1609 | ||
b95edd47 VZ |
1610 | #if wxUSE_PALETTE |
1611 | ||
1612 | void wxWindowBase::SetPalette(const wxPalette& pal) | |
1613 | { | |
e11f4636 | 1614 | m_hasCustomPalette = true; |
b95edd47 VZ |
1615 | m_palette = pal; |
1616 | ||
1617 | // VZ: can anyone explain me what do we do here? | |
1618 | wxWindowDC d((wxWindow *) this); | |
1619 | d.SetPalette(pal); | |
1620 | } | |
1621 | ||
1622 | wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const | |
1623 | { | |
1624 | wxWindow *win = (wxWindow *)this; | |
1625 | while ( win && !win->HasCustomPalette() ) | |
1626 | { | |
1627 | win = win->GetParent(); | |
1628 | } | |
1629 | ||
1630 | return win; | |
1631 | } | |
1632 | ||
1633 | #endif // wxUSE_PALETTE | |
1634 | ||
789295bf VZ |
1635 | #if wxUSE_CARET |
1636 | void wxWindowBase::SetCaret(wxCaret *caret) | |
1637 | { | |
1638 | if ( m_caret ) | |
1639 | { | |
1640 | delete m_caret; | |
1641 | } | |
1642 | ||
1643 | m_caret = caret; | |
1644 | ||
1645 | if ( m_caret ) | |
1646 | { | |
1647 | wxASSERT_MSG( m_caret->GetWindow() == this, | |
223d09f6 | 1648 | wxT("caret should be created associated to this window") ); |
789295bf VZ |
1649 | } |
1650 | } | |
1651 | #endif // wxUSE_CARET | |
1652 | ||
88ac883a | 1653 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
1654 | // ---------------------------------------------------------------------------- |
1655 | // validators | |
1656 | // ---------------------------------------------------------------------------- | |
1657 | ||
1658 | void wxWindowBase::SetValidator(const wxValidator& validator) | |
1659 | { | |
1660 | if ( m_windowValidator ) | |
1661 | delete m_windowValidator; | |
1662 | ||
1663 | m_windowValidator = (wxValidator *)validator.Clone(); | |
1664 | ||
1665 | if ( m_windowValidator ) | |
1b69c815 | 1666 | m_windowValidator->SetWindow(this); |
f03fc89f | 1667 | } |
88ac883a | 1668 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
1669 | |
1670 | // ---------------------------------------------------------------------------- | |
1e6feb95 | 1671 | // update region stuff |
f03fc89f VZ |
1672 | // ---------------------------------------------------------------------------- |
1673 | ||
1e6feb95 VZ |
1674 | wxRect wxWindowBase::GetUpdateClientRect() const |
1675 | { | |
1676 | wxRegion rgnUpdate = GetUpdateRegion(); | |
1677 | rgnUpdate.Intersect(GetClientRect()); | |
1678 | wxRect rectUpdate = rgnUpdate.GetBox(); | |
1679 | wxPoint ptOrigin = GetClientAreaOrigin(); | |
1680 | rectUpdate.x -= ptOrigin.x; | |
1681 | rectUpdate.y -= ptOrigin.y; | |
1682 | ||
1683 | return rectUpdate; | |
1684 | } | |
1685 | ||
657b4fd4 | 1686 | bool wxWindowBase::DoIsExposed(int x, int y) const |
f03fc89f VZ |
1687 | { |
1688 | return m_updateRegion.Contains(x, y) != wxOutRegion; | |
1689 | } | |
1690 | ||
657b4fd4 | 1691 | bool wxWindowBase::DoIsExposed(int x, int y, int w, int h) const |
f03fc89f VZ |
1692 | { |
1693 | return m_updateRegion.Contains(x, y, w, h) != wxOutRegion; | |
1694 | } | |
1695 | ||
5da0803c VZ |
1696 | void wxWindowBase::ClearBackground() |
1697 | { | |
1698 | // wxGTK uses its own version, no need to add never used code | |
1699 | #ifndef __WXGTK__ | |
1700 | wxClientDC dc((wxWindow *)this); | |
cb129171 | 1701 | wxBrush brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID); |
5da0803c VZ |
1702 | dc.SetBackground(brush); |
1703 | dc.Clear(); | |
1704 | #endif // __WXGTK__ | |
1705 | } | |
1706 | ||
f03fc89f | 1707 | // ---------------------------------------------------------------------------- |
146ba0fe | 1708 | // find child window by id or name |
f03fc89f VZ |
1709 | // ---------------------------------------------------------------------------- |
1710 | ||
6b73af79 | 1711 | wxWindow *wxWindowBase::FindWindow(long id) const |
f03fc89f VZ |
1712 | { |
1713 | if ( id == m_windowId ) | |
1714 | return (wxWindow *)this; | |
1715 | ||
d3b9f782 | 1716 | wxWindowBase *res = NULL; |
222ed1d6 | 1717 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1718 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) |
1719 | { | |
1720 | wxWindowBase *child = node->GetData(); | |
1721 | res = child->FindWindow( id ); | |
1722 | } | |
1723 | ||
1724 | return (wxWindow *)res; | |
1725 | } | |
1726 | ||
6b73af79 | 1727 | wxWindow *wxWindowBase::FindWindow(const wxString& name) const |
f03fc89f VZ |
1728 | { |
1729 | if ( name == m_windowName ) | |
1730 | return (wxWindow *)this; | |
1731 | ||
d3b9f782 | 1732 | wxWindowBase *res = NULL; |
222ed1d6 | 1733 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1734 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) |
1735 | { | |
1736 | wxWindow *child = node->GetData(); | |
1737 | res = child->FindWindow(name); | |
1738 | } | |
1739 | ||
1740 | return (wxWindow *)res; | |
1741 | } | |
1742 | ||
146ba0fe VZ |
1743 | |
1744 | // find any window by id or name or label: If parent is non-NULL, look through | |
1745 | // children for a label or title matching the specified string. If NULL, look | |
1746 | // through all top-level windows. | |
1747 | // | |
1748 | // to avoid duplicating code we reuse the same helper function but with | |
1749 | // different comparators | |
1750 | ||
1751 | typedef bool (*wxFindWindowCmp)(const wxWindow *win, | |
1752 | const wxString& label, long id); | |
1753 | ||
1754 | static | |
1755 | bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label, | |
1756 | long WXUNUSED(id)) | |
1757 | { | |
1758 | return win->GetLabel() == label; | |
1759 | } | |
1760 | ||
1761 | static | |
1762 | bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label, | |
1763 | long WXUNUSED(id)) | |
1764 | { | |
1765 | return win->GetName() == label; | |
1766 | } | |
1767 | ||
1768 | static | |
1769 | bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label), | |
1770 | long id) | |
1771 | { | |
1772 | return win->GetId() == id; | |
1773 | } | |
1774 | ||
1775 | // recursive helper for the FindWindowByXXX() functions | |
1776 | static | |
1777 | wxWindow *wxFindWindowRecursively(const wxWindow *parent, | |
1778 | const wxString& label, | |
1779 | long id, | |
1780 | wxFindWindowCmp cmp) | |
1781 | { | |
1782 | if ( parent ) | |
1783 | { | |
1784 | // see if this is the one we're looking for | |
1785 | if ( (*cmp)(parent, label, id) ) | |
1786 | return (wxWindow *)parent; | |
1787 | ||
1788 | // It wasn't, so check all its children | |
222ed1d6 | 1789 | for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst(); |
146ba0fe VZ |
1790 | node; |
1791 | node = node->GetNext() ) | |
1792 | { | |
1793 | // recursively check each child | |
1794 | wxWindow *win = (wxWindow *)node->GetData(); | |
1795 | wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp); | |
1796 | if (retwin) | |
1797 | return retwin; | |
1798 | } | |
1799 | } | |
1800 | ||
1801 | // Not found | |
1802 | return NULL; | |
1803 | } | |
1804 | ||
1805 | // helper for FindWindowByXXX() | |
1806 | static | |
1807 | wxWindow *wxFindWindowHelper(const wxWindow *parent, | |
1808 | const wxString& label, | |
1809 | long id, | |
1810 | wxFindWindowCmp cmp) | |
1811 | { | |
1812 | if ( parent ) | |
1813 | { | |
1814 | // just check parent and all its children | |
1815 | return wxFindWindowRecursively(parent, label, id, cmp); | |
1816 | } | |
1817 | ||
1818 | // start at very top of wx's windows | |
222ed1d6 | 1819 | for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); |
146ba0fe VZ |
1820 | node; |
1821 | node = node->GetNext() ) | |
1822 | { | |
1823 | // recursively check each window & its children | |
1824 | wxWindow *win = node->GetData(); | |
1825 | wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp); | |
1826 | if (retwin) | |
1827 | return retwin; | |
1828 | } | |
1829 | ||
1830 | return NULL; | |
1831 | } | |
1832 | ||
1833 | /* static */ | |
1834 | wxWindow * | |
1835 | wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent) | |
1836 | { | |
1837 | return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels); | |
1838 | } | |
1839 | ||
1840 | /* static */ | |
1841 | wxWindow * | |
1842 | wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent) | |
1843 | { | |
1844 | wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames); | |
1845 | ||
1846 | if ( !win ) | |
1847 | { | |
1848 | // fall back to the label | |
1849 | win = FindWindowByLabel(title, parent); | |
1850 | } | |
1851 | ||
1852 | return win; | |
1853 | } | |
1854 | ||
1855 | /* static */ | |
1856 | wxWindow * | |
1857 | wxWindowBase::FindWindowById( long id, const wxWindow* parent ) | |
1858 | { | |
525d8583 | 1859 | return wxFindWindowHelper(parent, wxEmptyString, id, wxFindWindowCmpIds); |
146ba0fe VZ |
1860 | } |
1861 | ||
f03fc89f VZ |
1862 | // ---------------------------------------------------------------------------- |
1863 | // dialog oriented functions | |
1864 | // ---------------------------------------------------------------------------- | |
1865 | ||
34636400 | 1866 | void wxWindowBase::MakeModal(bool modal) |
f03fc89f | 1867 | { |
34636400 VZ |
1868 | // Disable all other windows |
1869 | if ( IsTopLevel() ) | |
1870 | { | |
222ed1d6 | 1871 | wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); |
34636400 VZ |
1872 | while (node) |
1873 | { | |
1874 | wxWindow *win = node->GetData(); | |
1875 | if (win != this) | |
1876 | win->Enable(!modal); | |
1877 | ||
1878 | node = node->GetNext(); | |
1879 | } | |
1880 | } | |
f03fc89f VZ |
1881 | } |
1882 | ||
1883 | bool wxWindowBase::Validate() | |
1884 | { | |
88ac883a | 1885 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1886 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1887 | ||
222ed1d6 | 1888 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1889 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) |
1890 | { | |
1891 | wxWindowBase *child = node->GetData(); | |
1892 | wxValidator *validator = child->GetValidator(); | |
dcd6b914 | 1893 | if ( validator && !validator->Validate((wxWindow *)this) ) |
f03fc89f | 1894 | { |
e11f4636 | 1895 | return false; |
f03fc89f | 1896 | } |
d80cd92a VZ |
1897 | |
1898 | if ( recurse && !child->Validate() ) | |
1899 | { | |
e11f4636 | 1900 | return false; |
d80cd92a | 1901 | } |
f03fc89f | 1902 | } |
88ac883a | 1903 | #endif // wxUSE_VALIDATORS |
f03fc89f | 1904 | |
e11f4636 | 1905 | return true; |
f03fc89f VZ |
1906 | } |
1907 | ||
1908 | bool wxWindowBase::TransferDataToWindow() | |
1909 | { | |
88ac883a | 1910 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1911 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1912 | ||
222ed1d6 | 1913 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1914 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) |
1915 | { | |
1916 | wxWindowBase *child = node->GetData(); | |
1917 | wxValidator *validator = child->GetValidator(); | |
1918 | if ( validator && !validator->TransferToWindow() ) | |
1919 | { | |
d80cd92a | 1920 | wxLogWarning(_("Could not transfer data to window")); |
e30285ab | 1921 | #if wxUSE_LOG |
d80cd92a | 1922 | wxLog::FlushActive(); |
e30285ab | 1923 | #endif // wxUSE_LOG |
f03fc89f | 1924 | |
e11f4636 | 1925 | return false; |
f03fc89f | 1926 | } |
d80cd92a VZ |
1927 | |
1928 | if ( recurse ) | |
1929 | { | |
a58a12e9 | 1930 | if ( !child->TransferDataToWindow() ) |
d80cd92a VZ |
1931 | { |
1932 | // warning already given | |
e11f4636 | 1933 | return false; |
d80cd92a VZ |
1934 | } |
1935 | } | |
f03fc89f | 1936 | } |
88ac883a | 1937 | #endif // wxUSE_VALIDATORS |
f03fc89f | 1938 | |
e11f4636 | 1939 | return true; |
f03fc89f VZ |
1940 | } |
1941 | ||
1942 | bool wxWindowBase::TransferDataFromWindow() | |
1943 | { | |
88ac883a | 1944 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1945 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1946 | ||
222ed1d6 | 1947 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1948 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) |
1949 | { | |
1950 | wxWindow *child = node->GetData(); | |
d80cd92a VZ |
1951 | wxValidator *validator = child->GetValidator(); |
1952 | if ( validator && !validator->TransferFromWindow() ) | |
f03fc89f | 1953 | { |
d80cd92a VZ |
1954 | // nop warning here because the application is supposed to give |
1955 | // one itself - we don't know here what might have gone wrongly | |
1956 | ||
e11f4636 | 1957 | return false; |
f03fc89f | 1958 | } |
d80cd92a VZ |
1959 | |
1960 | if ( recurse ) | |
1961 | { | |
a58a12e9 | 1962 | if ( !child->TransferDataFromWindow() ) |
d80cd92a VZ |
1963 | { |
1964 | // warning already given | |
e11f4636 | 1965 | return false; |
d80cd92a VZ |
1966 | } |
1967 | } | |
f03fc89f | 1968 | } |
88ac883a | 1969 | #endif // wxUSE_VALIDATORS |
f03fc89f | 1970 | |
e11f4636 | 1971 | return true; |
f03fc89f VZ |
1972 | } |
1973 | ||
1974 | void wxWindowBase::InitDialog() | |
1975 | { | |
1976 | wxInitDialogEvent event(GetId()); | |
1977 | event.SetEventObject( this ); | |
1978 | GetEventHandler()->ProcessEvent(event); | |
1979 | } | |
1980 | ||
1981 | // ---------------------------------------------------------------------------- | |
bd83cb56 VZ |
1982 | // context-sensitive help support |
1983 | // ---------------------------------------------------------------------------- | |
1984 | ||
1985 | #if wxUSE_HELP | |
1986 | ||
1987 | // associate this help text with this window | |
1988 | void wxWindowBase::SetHelpText(const wxString& text) | |
1989 | { | |
1990 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1991 | if ( helpProvider ) | |
1992 | { | |
1993 | helpProvider->AddHelp(this, text); | |
1994 | } | |
1995 | } | |
1996 | ||
520746ac | 1997 | #if WXWIN_COMPATIBILITY_2_8 |
bd83cb56 VZ |
1998 | // associate this help text with all windows with the same id as this |
1999 | // one | |
2000 | void wxWindowBase::SetHelpTextForId(const wxString& text) | |
2001 | { | |
2002 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
2003 | if ( helpProvider ) | |
2004 | { | |
2005 | helpProvider->AddHelp(GetId(), text); | |
2006 | } | |
2007 | } | |
520746ac | 2008 | #endif // WXWIN_COMPATIBILITY_2_8 |
bd83cb56 VZ |
2009 | |
2010 | // get the help string associated with this window (may be empty) | |
dc6588e7 VZ |
2011 | // default implementation forwards calls to the help provider |
2012 | wxString | |
2013 | wxWindowBase::GetHelpTextAtPoint(const wxPoint & WXUNUSED(pt), | |
2014 | wxHelpEvent::Origin WXUNUSED(origin)) const | |
bd83cb56 VZ |
2015 | { |
2016 | wxString text; | |
2017 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
2018 | if ( helpProvider ) | |
2019 | { | |
2020 | text = helpProvider->GetHelp(this); | |
2021 | } | |
2022 | ||
2023 | return text; | |
2024 | } | |
2025 | ||
2026 | // show help for this window | |
2027 | void wxWindowBase::OnHelp(wxHelpEvent& event) | |
2028 | { | |
2029 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
2030 | if ( helpProvider ) | |
2031 | { | |
95d3881f VZ |
2032 | wxPoint pos = event.GetPosition(); |
2033 | const wxHelpEvent::Origin origin = event.GetOrigin(); | |
2034 | if ( origin == wxHelpEvent::Origin_Keyboard ) | |
2035 | { | |
2036 | // if the help event was generated from keyboard it shouldn't | |
2037 | // appear at the mouse position (which is still the only position | |
2038 | // associated with help event) if the mouse is far away, although | |
2039 | // we still do use the mouse position if it's over the window | |
2040 | // because we suppose the user looks approximately at the mouse | |
2041 | // already and so it would be more convenient than showing tooltip | |
2042 | // at some arbitrary position which can be quite far from it | |
2043 | const wxRect rectClient = GetClientRect(); | |
2044 | if ( !rectClient.Contains(ScreenToClient(pos)) ) | |
2045 | { | |
2046 | // position help slightly under and to the right of this window | |
2047 | pos = ClientToScreen(wxPoint( | |
2048 | 2*GetCharWidth(), | |
2049 | rectClient.height + GetCharHeight() | |
2050 | )); | |
2051 | } | |
2052 | } | |
2053 | ||
2054 | if ( helpProvider->ShowHelpAtPoint(this, pos, origin) ) | |
bd83cb56 VZ |
2055 | { |
2056 | // skip the event.Skip() below | |
2057 | return; | |
2058 | } | |
2059 | } | |
2060 | ||
2061 | event.Skip(); | |
2062 | } | |
2063 | ||
2064 | #endif // wxUSE_HELP | |
2065 | ||
2066 | // ---------------------------------------------------------------------------- | |
602a2e02 | 2067 | // tooltips |
f03fc89f VZ |
2068 | // ---------------------------------------------------------------------------- |
2069 | ||
2070 | #if wxUSE_TOOLTIPS | |
2071 | ||
a16a2338 VZ |
2072 | wxString wxWindowBase::GetToolTipText() const |
2073 | { | |
2074 | return m_tooltip ? m_tooltip->GetTip() : wxString(); | |
2075 | } | |
2076 | ||
f03fc89f VZ |
2077 | void wxWindowBase::SetToolTip( const wxString &tip ) |
2078 | { | |
2079 | // don't create the new tooltip if we already have one | |
2080 | if ( m_tooltip ) | |
2081 | { | |
2082 | m_tooltip->SetTip( tip ); | |
2083 | } | |
2084 | else | |
2085 | { | |
2086 | SetToolTip( new wxToolTip( tip ) ); | |
2087 | } | |
2088 | ||
2089 | // setting empty tooltip text does not remove the tooltip any more - use | |
d3b9f782 | 2090 | // SetToolTip(NULL) for this |
f03fc89f VZ |
2091 | } |
2092 | ||
2093 | void wxWindowBase::DoSetToolTip(wxToolTip *tooltip) | |
2094 | { | |
0cb57187 VZ |
2095 | if ( m_tooltip != tooltip ) |
2096 | { | |
2097 | if ( m_tooltip ) | |
2098 | delete m_tooltip; | |
f03fc89f | 2099 | |
0cb57187 VZ |
2100 | m_tooltip = tooltip; |
2101 | } | |
f03fc89f VZ |
2102 | } |
2103 | ||
2104 | #endif // wxUSE_TOOLTIPS | |
2105 | ||
2106 | // ---------------------------------------------------------------------------- | |
2107 | // constraints and sizers | |
2108 | // ---------------------------------------------------------------------------- | |
2109 | ||
2110 | #if wxUSE_CONSTRAINTS | |
2111 | ||
2112 | void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints ) | |
2113 | { | |
2114 | if ( m_constraints ) | |
2115 | { | |
2116 | UnsetConstraints(m_constraints); | |
2117 | delete m_constraints; | |
2118 | } | |
2119 | m_constraints = constraints; | |
2120 | if ( m_constraints ) | |
2121 | { | |
2122 | // Make sure other windows know they're part of a 'meaningful relationship' | |
2123 | if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) ) | |
2124 | m_constraints->left.GetOtherWindow()->AddConstraintReference(this); | |
2125 | if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) ) | |
2126 | m_constraints->top.GetOtherWindow()->AddConstraintReference(this); | |
2127 | if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) ) | |
2128 | m_constraints->right.GetOtherWindow()->AddConstraintReference(this); | |
2129 | if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) ) | |
2130 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this); | |
2131 | if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) ) | |
2132 | m_constraints->width.GetOtherWindow()->AddConstraintReference(this); | |
2133 | if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) ) | |
2134 | m_constraints->height.GetOtherWindow()->AddConstraintReference(this); | |
2135 | if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) ) | |
2136 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this); | |
2137 | if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) ) | |
2138 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this); | |
2139 | } | |
2140 | } | |
2141 | ||
2142 | // This removes any dangling pointers to this window in other windows' | |
2143 | // constraintsInvolvedIn lists. | |
2144 | void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c) | |
2145 | { | |
2146 | if ( c ) | |
2147 | { | |
2148 | if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
2149 | c->left.GetOtherWindow()->RemoveConstraintReference(this); | |
2150 | if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
2151 | c->top.GetOtherWindow()->RemoveConstraintReference(this); | |
2152 | if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) ) | |
2153 | c->right.GetOtherWindow()->RemoveConstraintReference(this); | |
2154 | if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) ) | |
2155 | c->bottom.GetOtherWindow()->RemoveConstraintReference(this); | |
2156 | if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) ) | |
2157 | c->width.GetOtherWindow()->RemoveConstraintReference(this); | |
2158 | if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) ) | |
2159 | c->height.GetOtherWindow()->RemoveConstraintReference(this); | |
2160 | if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) ) | |
2161 | c->centreX.GetOtherWindow()->RemoveConstraintReference(this); | |
2162 | if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) ) | |
2163 | c->centreY.GetOtherWindow()->RemoveConstraintReference(this); | |
2164 | } | |
2165 | } | |
2166 | ||
2167 | // Back-pointer to other windows we're involved with, so if we delete this | |
2168 | // window, we must delete any constraints we're involved with. | |
2169 | void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin) | |
2170 | { | |
2171 | if ( !m_constraintsInvolvedIn ) | |
2172 | m_constraintsInvolvedIn = new wxWindowList; | |
222ed1d6 MB |
2173 | if ( !m_constraintsInvolvedIn->Find((wxWindow *)otherWin) ) |
2174 | m_constraintsInvolvedIn->Append((wxWindow *)otherWin); | |
f03fc89f VZ |
2175 | } |
2176 | ||
2177 | // REMOVE back-pointer to other windows we're involved with. | |
2178 | void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin) | |
2179 | { | |
2180 | if ( m_constraintsInvolvedIn ) | |
222ed1d6 | 2181 | m_constraintsInvolvedIn->DeleteObject((wxWindow *)otherWin); |
f03fc89f VZ |
2182 | } |
2183 | ||
2184 | // Reset any constraints that mention this window | |
2185 | void wxWindowBase::DeleteRelatedConstraints() | |
2186 | { | |
2187 | if ( m_constraintsInvolvedIn ) | |
2188 | { | |
222ed1d6 | 2189 | wxWindowList::compatibility_iterator node = m_constraintsInvolvedIn->GetFirst(); |
f03fc89f VZ |
2190 | while (node) |
2191 | { | |
2192 | wxWindow *win = node->GetData(); | |
2193 | wxLayoutConstraints *constr = win->GetConstraints(); | |
2194 | ||
2195 | // Reset any constraints involving this window | |
2196 | if ( constr ) | |
2197 | { | |
2198 | constr->left.ResetIfWin(this); | |
2199 | constr->top.ResetIfWin(this); | |
2200 | constr->right.ResetIfWin(this); | |
2201 | constr->bottom.ResetIfWin(this); | |
2202 | constr->width.ResetIfWin(this); | |
2203 | constr->height.ResetIfWin(this); | |
2204 | constr->centreX.ResetIfWin(this); | |
2205 | constr->centreY.ResetIfWin(this); | |
2206 | } | |
2207 | ||
222ed1d6 MB |
2208 | wxWindowList::compatibility_iterator next = node->GetNext(); |
2209 | m_constraintsInvolvedIn->Erase(node); | |
f03fc89f VZ |
2210 | node = next; |
2211 | } | |
2212 | ||
5276b0a5 | 2213 | wxDELETE(m_constraintsInvolvedIn); |
f03fc89f VZ |
2214 | } |
2215 | } | |
ec5bb70d VZ |
2216 | |
2217 | #endif // wxUSE_CONSTRAINTS | |
f03fc89f | 2218 | |
3aa5d532 | 2219 | void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld) |
f03fc89f | 2220 | { |
fb89cfc5 RD |
2221 | if ( sizer == m_windowSizer) |
2222 | return; | |
1b69c815 | 2223 | |
e8cfff87 VZ |
2224 | if ( m_windowSizer ) |
2225 | { | |
2226 | m_windowSizer->SetContainingWindow(NULL); | |
2227 | ||
2228 | if ( deleteOld ) | |
2229 | delete m_windowSizer; | |
2230 | } | |
3417c2cd | 2231 | |
f03fc89f | 2232 | m_windowSizer = sizer; |
e8cfff87 VZ |
2233 | if ( m_windowSizer ) |
2234 | { | |
2235 | m_windowSizer->SetContainingWindow((wxWindow *)this); | |
2236 | } | |
566d84a7 | 2237 | |
e8cfff87 | 2238 | SetAutoLayout(m_windowSizer != NULL); |
566d84a7 RL |
2239 | } |
2240 | ||
2241 | void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld) | |
2242 | { | |
2243 | SetSizer( sizer, deleteOld ); | |
2244 | sizer->SetSizeHints( (wxWindow*) this ); | |
f03fc89f VZ |
2245 | } |
2246 | ||
400a9e41 | 2247 | |
1ebfafde RD |
2248 | void wxWindowBase::SetContainingSizer(wxSizer* sizer) |
2249 | { | |
2250 | // adding a window to a sizer twice is going to result in fatal and | |
2251 | // hard to debug problems later because when deleting the second | |
2252 | // associated wxSizerItem we're going to dereference a dangling | |
2253 | // pointer; so try to detect this as early as possible | |
2254 | wxASSERT_MSG( !sizer || m_containingSizer != sizer, | |
9a83f860 | 2255 | wxT("Adding a window to the same sizer twice?") ); |
1ebfafde | 2256 | |
400a9e41 | 2257 | m_containingSizer = sizer; |
1ebfafde | 2258 | } |
400a9e41 | 2259 | |
ec5bb70d VZ |
2260 | #if wxUSE_CONSTRAINTS |
2261 | ||
2262 | void wxWindowBase::SatisfyConstraints() | |
2263 | { | |
2264 | wxLayoutConstraints *constr = GetConstraints(); | |
2265 | bool wasOk = constr && constr->AreSatisfied(); | |
2266 | ||
2267 | ResetConstraints(); // Mark all constraints as unevaluated | |
2268 | ||
2269 | int noChanges = 1; | |
2270 | ||
2271 | // if we're a top level panel (i.e. our parent is frame/dialog), our | |
2272 | // own constraints will never be satisfied any more unless we do it | |
2273 | // here | |
2274 | if ( wasOk ) | |
2275 | { | |
2276 | while ( noChanges > 0 ) | |
2277 | { | |
2278 | LayoutPhase1(&noChanges); | |
2279 | } | |
2280 | } | |
2281 | ||
2282 | LayoutPhase2(&noChanges); | |
2283 | } | |
2284 | ||
2285 | #endif // wxUSE_CONSTRAINTS | |
2286 | ||
f03fc89f VZ |
2287 | bool wxWindowBase::Layout() |
2288 | { | |
3417c2cd | 2289 | // If there is a sizer, use it instead of the constraints |
f03fc89f VZ |
2290 | if ( GetSizer() ) |
2291 | { | |
8d7eaf91 | 2292 | int w = 0, h = 0; |
566d84a7 | 2293 | GetVirtualSize(&w, &h); |
3417c2cd | 2294 | GetSizer()->SetDimension( 0, 0, w, h ); |
f03fc89f | 2295 | } |
461e93f9 | 2296 | #if wxUSE_CONSTRAINTS |
f1df0927 | 2297 | else |
f03fc89f | 2298 | { |
ec5bb70d | 2299 | SatisfyConstraints(); // Find the right constraints values |
f1df0927 | 2300 | SetConstraintSizes(); // Recursively set the real window sizes |
f03fc89f | 2301 | } |
461e93f9 | 2302 | #endif |
5d4b632b | 2303 | |
e11f4636 | 2304 | return true; |
f03fc89f VZ |
2305 | } |
2306 | ||
6528a7f1 VZ |
2307 | void wxWindowBase::InternalOnSize(wxSizeEvent& event) |
2308 | { | |
2309 | if ( GetAutoLayout() ) | |
2310 | Layout(); | |
2311 | ||
2312 | event.Skip(); | |
2313 | } | |
2314 | ||
461e93f9 | 2315 | #if wxUSE_CONSTRAINTS |
ec5bb70d VZ |
2316 | |
2317 | // first phase of the constraints evaluation: set our own constraints | |
f03fc89f VZ |
2318 | bool wxWindowBase::LayoutPhase1(int *noChanges) |
2319 | { | |
2320 | wxLayoutConstraints *constr = GetConstraints(); | |
ec5bb70d VZ |
2321 | |
2322 | return !constr || constr->SatisfyConstraints(this, noChanges); | |
f03fc89f VZ |
2323 | } |
2324 | ||
ec5bb70d | 2325 | // second phase: set the constraints for our children |
f03fc89f VZ |
2326 | bool wxWindowBase::LayoutPhase2(int *noChanges) |
2327 | { | |
2328 | *noChanges = 0; | |
2329 | ||
2330 | // Layout children | |
2331 | DoPhase(1); | |
ec5bb70d VZ |
2332 | |
2333 | // Layout grand children | |
f03fc89f | 2334 | DoPhase(2); |
ec5bb70d | 2335 | |
e11f4636 | 2336 | return true; |
f03fc89f VZ |
2337 | } |
2338 | ||
2339 | // Do a phase of evaluating child constraints | |
2340 | bool wxWindowBase::DoPhase(int phase) | |
2341 | { | |
ec5bb70d VZ |
2342 | // the list containing the children for which the constraints are already |
2343 | // set correctly | |
f03fc89f | 2344 | wxWindowList succeeded; |
ec5bb70d VZ |
2345 | |
2346 | // the max number of iterations we loop before concluding that we can't set | |
2347 | // the constraints | |
2348 | static const int maxIterations = 500; | |
2349 | ||
2350 | for ( int noIterations = 0; noIterations < maxIterations; noIterations++ ) | |
f03fc89f | 2351 | { |
ec5bb70d VZ |
2352 | int noChanges = 0; |
2353 | ||
2354 | // loop over all children setting their constraints | |
222ed1d6 | 2355 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
ec5bb70d VZ |
2356 | node; |
2357 | node = node->GetNext() ) | |
f03fc89f VZ |
2358 | { |
2359 | wxWindow *child = node->GetData(); | |
ec5bb70d | 2360 | if ( child->IsTopLevel() ) |
f03fc89f | 2361 | { |
ec5bb70d VZ |
2362 | // top level children are not inside our client area |
2363 | continue; | |
2364 | } | |
2365 | ||
2366 | if ( !child->GetConstraints() || succeeded.Find(child) ) | |
2367 | { | |
2368 | // this one is either already ok or nothing we can do about it | |
2369 | continue; | |
2370 | } | |
2371 | ||
2372 | int tempNoChanges = 0; | |
2373 | bool success = phase == 1 ? child->LayoutPhase1(&tempNoChanges) | |
2374 | : child->LayoutPhase2(&tempNoChanges); | |
2375 | noChanges += tempNoChanges; | |
2376 | ||
2377 | if ( success ) | |
2378 | { | |
2379 | succeeded.Append(child); | |
f03fc89f | 2380 | } |
f03fc89f VZ |
2381 | } |
2382 | ||
ec5bb70d VZ |
2383 | if ( !noChanges ) |
2384 | { | |
2385 | // constraints are set | |
2386 | break; | |
2387 | } | |
f03fc89f VZ |
2388 | } |
2389 | ||
e11f4636 | 2390 | return true; |
f03fc89f VZ |
2391 | } |
2392 | ||
2393 | void wxWindowBase::ResetConstraints() | |
2394 | { | |
2395 | wxLayoutConstraints *constr = GetConstraints(); | |
2396 | if ( constr ) | |
2397 | { | |
e11f4636 DS |
2398 | constr->left.SetDone(false); |
2399 | constr->top.SetDone(false); | |
2400 | constr->right.SetDone(false); | |
2401 | constr->bottom.SetDone(false); | |
2402 | constr->width.SetDone(false); | |
2403 | constr->height.SetDone(false); | |
2404 | constr->centreX.SetDone(false); | |
2405 | constr->centreY.SetDone(false); | |
f03fc89f | 2406 | } |
f1df0927 | 2407 | |
222ed1d6 | 2408 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
f03fc89f VZ |
2409 | while (node) |
2410 | { | |
2411 | wxWindow *win = node->GetData(); | |
34636400 | 2412 | if ( !win->IsTopLevel() ) |
f03fc89f VZ |
2413 | win->ResetConstraints(); |
2414 | node = node->GetNext(); | |
2415 | } | |
2416 | } | |
2417 | ||
2418 | // Need to distinguish between setting the 'fake' size for windows and sizers, | |
2419 | // and setting the real values. | |
2420 | void wxWindowBase::SetConstraintSizes(bool recurse) | |
2421 | { | |
2422 | wxLayoutConstraints *constr = GetConstraints(); | |
4b7f2165 | 2423 | if ( constr && constr->AreSatisfied() ) |
f03fc89f VZ |
2424 | { |
2425 | int x = constr->left.GetValue(); | |
2426 | int y = constr->top.GetValue(); | |
2427 | int w = constr->width.GetValue(); | |
2428 | int h = constr->height.GetValue(); | |
2429 | ||
f03fc89f | 2430 | if ( (constr->width.GetRelationship() != wxAsIs ) || |
3417c2cd | 2431 | (constr->height.GetRelationship() != wxAsIs) ) |
f03fc89f | 2432 | { |
7e843c0e VZ |
2433 | // We really shouldn't set negative sizes for the windows so make |
2434 | // them at least of 1*1 size | |
2435 | SetSize(x, y, w > 0 ? w : 1, h > 0 ? h : 1); | |
f03fc89f VZ |
2436 | } |
2437 | else | |
2438 | { | |
3417c2cd RR |
2439 | // If we don't want to resize this window, just move it... |
2440 | Move(x, y); | |
f03fc89f VZ |
2441 | } |
2442 | } | |
2443 | else if ( constr ) | |
2444 | { | |
4b7f2165 | 2445 | wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."), |
f1df0927 | 2446 | GetClassInfo()->GetClassName(), |
4b7f2165 | 2447 | GetName().c_str()); |
f03fc89f VZ |
2448 | } |
2449 | ||
2450 | if ( recurse ) | |
2451 | { | |
222ed1d6 | 2452 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
f03fc89f VZ |
2453 | while (node) |
2454 | { | |
2455 | wxWindow *win = node->GetData(); | |
e2f9212c | 2456 | if ( !win->IsTopLevel() && win->GetConstraints() ) |
f03fc89f VZ |
2457 | win->SetConstraintSizes(); |
2458 | node = node->GetNext(); | |
2459 | } | |
2460 | } | |
2461 | } | |
2462 | ||
f03fc89f VZ |
2463 | // Only set the size/position of the constraint (if any) |
2464 | void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h) | |
2465 | { | |
2466 | wxLayoutConstraints *constr = GetConstraints(); | |
2467 | if ( constr ) | |
2468 | { | |
422d0ff0 | 2469 | if ( x != wxDefaultCoord ) |
f03fc89f VZ |
2470 | { |
2471 | constr->left.SetValue(x); | |
e11f4636 | 2472 | constr->left.SetDone(true); |
f03fc89f | 2473 | } |
422d0ff0 | 2474 | if ( y != wxDefaultCoord ) |
f03fc89f VZ |
2475 | { |
2476 | constr->top.SetValue(y); | |
e11f4636 | 2477 | constr->top.SetDone(true); |
f03fc89f | 2478 | } |
422d0ff0 | 2479 | if ( w != wxDefaultCoord ) |
f03fc89f VZ |
2480 | { |
2481 | constr->width.SetValue(w); | |
e11f4636 | 2482 | constr->width.SetDone(true); |
f03fc89f | 2483 | } |
422d0ff0 | 2484 | if ( h != wxDefaultCoord ) |
f03fc89f VZ |
2485 | { |
2486 | constr->height.SetValue(h); | |
e11f4636 | 2487 | constr->height.SetDone(true); |
f03fc89f VZ |
2488 | } |
2489 | } | |
2490 | } | |
2491 | ||
2492 | void wxWindowBase::MoveConstraint(int x, int y) | |
2493 | { | |
2494 | wxLayoutConstraints *constr = GetConstraints(); | |
2495 | if ( constr ) | |
2496 | { | |
422d0ff0 | 2497 | if ( x != wxDefaultCoord ) |
f03fc89f VZ |
2498 | { |
2499 | constr->left.SetValue(x); | |
e11f4636 | 2500 | constr->left.SetDone(true); |
f03fc89f | 2501 | } |
422d0ff0 | 2502 | if ( y != wxDefaultCoord ) |
f03fc89f VZ |
2503 | { |
2504 | constr->top.SetValue(y); | |
e11f4636 | 2505 | constr->top.SetDone(true); |
f03fc89f VZ |
2506 | } |
2507 | } | |
2508 | } | |
2509 | ||
2510 | void wxWindowBase::GetSizeConstraint(int *w, int *h) const | |
2511 | { | |
2512 | wxLayoutConstraints *constr = GetConstraints(); | |
2513 | if ( constr ) | |
2514 | { | |
2515 | *w = constr->width.GetValue(); | |
2516 | *h = constr->height.GetValue(); | |
2517 | } | |
2518 | else | |
2519 | GetSize(w, h); | |
2520 | } | |
2521 | ||
2522 | void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const | |
2523 | { | |
2524 | wxLayoutConstraints *constr = GetConstraints(); | |
2525 | if ( constr ) | |
2526 | { | |
2527 | *w = constr->width.GetValue(); | |
2528 | *h = constr->height.GetValue(); | |
2529 | } | |
2530 | else | |
2531 | GetClientSize(w, h); | |
2532 | } | |
2533 | ||
461e93f9 JS |
2534 | void wxWindowBase::GetPositionConstraint(int *x, int *y) const |
2535 | { | |
2536 | wxLayoutConstraints *constr = GetConstraints(); | |
2537 | if ( constr ) | |
2538 | { | |
2539 | *x = constr->left.GetValue(); | |
2540 | *y = constr->top.GetValue(); | |
2541 | } | |
2542 | else | |
2543 | GetPosition(x, y); | |
2544 | } | |
2545 | ||
2546 | #endif // wxUSE_CONSTRAINTS | |
2547 | ||
20a1eea1 | 2548 | void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const |
a200c35e VS |
2549 | { |
2550 | // don't do it for the dialogs/frames - they float independently of their | |
2551 | // parent | |
2552 | if ( !IsTopLevel() ) | |
2553 | { | |
2554 | wxWindow *parent = GetParent(); | |
2555 | if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent ) | |
2556 | { | |
2557 | wxPoint pt(parent->GetClientAreaOrigin()); | |
2558 | x += pt.x; | |
2559 | y += pt.y; | |
2560 | } | |
2561 | } | |
2562 | } | |
2563 | ||
f03fc89f | 2564 | // ---------------------------------------------------------------------------- |
602a2e02 | 2565 | // Update UI processing |
f03fc89f | 2566 | // ---------------------------------------------------------------------------- |
7ec1983b | 2567 | |
e39af974 | 2568 | void wxWindowBase::UpdateWindowUI(long flags) |
7ec1983b | 2569 | { |
26bf1ce0 | 2570 | wxUpdateUIEvent event(GetId()); |
687706f5 | 2571 | event.SetEventObject(this); |
26bf1ce0 VZ |
2572 | |
2573 | if ( GetEventHandler()->ProcessEvent(event) ) | |
7ec1983b | 2574 | { |
e39af974 JS |
2575 | DoUpdateWindowUI(event); |
2576 | } | |
7ec1983b | 2577 | |
e39af974 JS |
2578 | if (flags & wxUPDATE_UI_RECURSE) |
2579 | { | |
222ed1d6 | 2580 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
e39af974 | 2581 | while (node) |
f03fc89f | 2582 | { |
e39af974 JS |
2583 | wxWindow* child = (wxWindow*) node->GetData(); |
2584 | child->UpdateWindowUI(flags); | |
2585 | node = node->GetNext(); | |
26bf1ce0 | 2586 | } |
e39af974 JS |
2587 | } |
2588 | } | |
f03fc89f | 2589 | |
e39af974 | 2590 | // do the window-specific processing after processing the update event |
e39af974 JS |
2591 | void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event) |
2592 | { | |
2593 | if ( event.GetSetEnabled() ) | |
2594 | Enable(event.GetEnabled()); | |
e11f4636 | 2595 | |
a3a4105d VZ |
2596 | if ( event.GetSetShown() ) |
2597 | Show(event.GetShown()); | |
e39af974 JS |
2598 | } |
2599 | ||
f03fc89f VZ |
2600 | // ---------------------------------------------------------------------------- |
2601 | // dialog units translations | |
2602 | // ---------------------------------------------------------------------------- | |
2603 | ||
5c3c1372 VS |
2604 | // Windows' computes dialog units using average character width over upper- |
2605 | // and lower-case ASCII alphabet and not using the average character width | |
2606 | // metadata stored in the font; see | |
2607 | // http://support.microsoft.com/default.aspx/kb/145994 for detailed discussion. | |
2608 | // It's important that we perform the conversion in identical way, because | |
2609 | // dialog units natively exist only on Windows and Windows HIG is expressed | |
2610 | // using them. | |
2611 | wxSize wxWindowBase::GetDlgUnitBase() const | |
2612 | { | |
2d4dcfe1 | 2613 | const wxWindowBase * const parent = wxGetTopLevelParent((wxWindow*)this); |
5c3c1372 VS |
2614 | |
2615 | if ( !parent->m_font.IsOk() ) | |
2616 | { | |
2617 | // Default GUI font is used. This is the most common case, so | |
2618 | // cache the results. | |
2619 | static wxSize s_defFontSize; | |
2620 | if ( s_defFontSize.x == 0 ) | |
2621 | s_defFontSize = wxPrivate::GetAverageASCIILetterSize(*parent); | |
2622 | return s_defFontSize; | |
2623 | } | |
2624 | else | |
2625 | { | |
2626 | // Custom font, we always need to compute the result | |
2627 | return wxPrivate::GetAverageASCIILetterSize(*parent); | |
2628 | } | |
2629 | } | |
2630 | ||
0e7f59ab | 2631 | wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt) const |
fd71308f | 2632 | { |
5c3c1372 VS |
2633 | const wxSize base = GetDlgUnitBase(); |
2634 | ||
2635 | // NB: wxMulDivInt32() is used, because it correctly rounds the result | |
2636 | ||
cab1a605 WS |
2637 | wxPoint pt2 = wxDefaultPosition; |
2638 | if (pt.x != wxDefaultCoord) | |
5c3c1372 | 2639 | pt2.x = wxMulDivInt32(pt.x, 4, base.x); |
cab1a605 | 2640 | if (pt.y != wxDefaultCoord) |
5c3c1372 | 2641 | pt2.y = wxMulDivInt32(pt.y, 8, base.y); |
fd71308f JS |
2642 | |
2643 | return pt2; | |
2644 | } | |
2645 | ||
0e7f59ab | 2646 | wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt) const |
fd71308f | 2647 | { |
5c3c1372 VS |
2648 | const wxSize base = GetDlgUnitBase(); |
2649 | ||
cab1a605 WS |
2650 | wxPoint pt2 = wxDefaultPosition; |
2651 | if (pt.x != wxDefaultCoord) | |
5c3c1372 | 2652 | pt2.x = wxMulDivInt32(pt.x, base.x, 4); |
cab1a605 | 2653 | if (pt.y != wxDefaultCoord) |
5c3c1372 | 2654 | pt2.y = wxMulDivInt32(pt.y, base.y, 8); |
fd71308f JS |
2655 | |
2656 | return pt2; | |
2657 | } | |
2658 | ||
f03fc89f VZ |
2659 | // ---------------------------------------------------------------------------- |
2660 | // event handlers | |
2661 | // ---------------------------------------------------------------------------- | |
2662 | ||
2663 | // propagate the colour change event to the subwindows | |
efc88372 | 2664 | void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) |
f03fc89f | 2665 | { |
222ed1d6 | 2666 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
f03fc89f VZ |
2667 | while ( node ) |
2668 | { | |
2669 | // Only propagate to non-top-level windows | |
2670 | wxWindow *win = node->GetData(); | |
2671 | if ( !win->IsTopLevel() ) | |
2672 | { | |
2673 | wxSysColourChangedEvent event2; | |
6f34fcb3 | 2674 | event2.SetEventObject(win); |
f03fc89f VZ |
2675 | win->GetEventHandler()->ProcessEvent(event2); |
2676 | } | |
2677 | ||
2678 | node = node->GetNext(); | |
2679 | } | |
9a8477e1 VS |
2680 | |
2681 | Refresh(); | |
f03fc89f VZ |
2682 | } |
2683 | ||
e39af974 JS |
2684 | // the default action is to populate dialog with data when it's created, |
2685 | // and nudge the UI into displaying itself correctly in case | |
2686 | // we've turned the wxUpdateUIEvents frequency down low. | |
f03fc89f VZ |
2687 | void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) ) |
2688 | { | |
2689 | TransferDataToWindow(); | |
e11f4636 | 2690 | |
e39af974 JS |
2691 | // Update the UI at this point |
2692 | UpdateWindowUI(wxUPDATE_UI_RECURSE); | |
f03fc89f VZ |
2693 | } |
2694 | ||
00a77b7c VZ |
2695 | // ---------------------------------------------------------------------------- |
2696 | // menu-related functions | |
2697 | // ---------------------------------------------------------------------------- | |
2698 | ||
2699 | #if wxUSE_MENUS | |
2700 | ||
eeb0bee1 VZ |
2701 | bool wxWindowBase::PopupMenu(wxMenu *menu, int x, int y) |
2702 | { | |
2703 | wxCHECK_MSG( menu, false, "can't popup NULL menu" ); | |
2704 | ||
c59aa14a VZ |
2705 | wxMenuInvokingWindowSetter |
2706 | setInvokingWin(*menu, static_cast<wxWindow *>(this)); | |
2707 | ||
eeb0bee1 VZ |
2708 | wxCurrentPopupMenu = menu; |
2709 | const bool rc = DoPopupMenu(menu, x, y); | |
2710 | wxCurrentPopupMenu = NULL; | |
2711 | ||
2712 | return rc; | |
2713 | } | |
2714 | ||
00a77b7c VZ |
2715 | // this is used to pass the id of the selected item from the menu event handler |
2716 | // to the main function itself | |
2717 | // | |
2718 | // it's ok to use a global here as there can be at most one popup menu shown at | |
2719 | // any time | |
2720 | static int gs_popupMenuSelection = wxID_NONE; | |
2721 | ||
2722 | void wxWindowBase::InternalOnPopupMenu(wxCommandEvent& event) | |
2723 | { | |
2724 | // store the id in a global variable where we'll retrieve it from later | |
2725 | gs_popupMenuSelection = event.GetId(); | |
2726 | } | |
2727 | ||
565382de VZ |
2728 | void wxWindowBase::InternalOnPopupMenuUpdate(wxUpdateUIEvent& WXUNUSED(event)) |
2729 | { | |
2730 | // nothing to do but do not skip it | |
2731 | } | |
2732 | ||
00a77b7c VZ |
2733 | int |
2734 | wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu& menu, int x, int y) | |
2735 | { | |
2736 | gs_popupMenuSelection = wxID_NONE; | |
2737 | ||
2738 | Connect(wxEVT_COMMAND_MENU_SELECTED, | |
2739 | wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu), | |
2740 | NULL, | |
2741 | this); | |
2742 | ||
565382de VZ |
2743 | // it is common to construct the menu passed to this function dynamically |
2744 | // using some fixed range of ids which could clash with the ids used | |
2745 | // elsewhere in the program, which could result in some menu items being | |
2746 | // unintentionally disabled or otherwise modified by update UI handlers | |
2747 | // elsewhere in the program code and this is difficult to avoid in the | |
2748 | // program itself, so instead we just temporarily suspend UI updating while | |
2749 | // this menu is shown | |
2750 | Connect(wxEVT_UPDATE_UI, | |
2751 | wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate), | |
2752 | NULL, | |
2753 | this); | |
2754 | ||
00a77b7c VZ |
2755 | PopupMenu(&menu, x, y); |
2756 | ||
565382de VZ |
2757 | Disconnect(wxEVT_UPDATE_UI, |
2758 | wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate), | |
2759 | NULL, | |
2760 | this); | |
00a77b7c VZ |
2761 | Disconnect(wxEVT_COMMAND_MENU_SELECTED, |
2762 | wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu), | |
2763 | NULL, | |
2764 | this); | |
2765 | ||
2766 | return gs_popupMenuSelection; | |
2767 | } | |
2768 | ||
2769 | #endif // wxUSE_MENUS | |
2770 | ||
32be10a4 VZ |
2771 | // methods for drawing the sizers in a visible way: this is currently only |
2772 | // enabled for "full debug" builds with wxDEBUG_LEVEL==2 as it doesn't work | |
2773 | // that well and also because we don't want to leave it enabled in default | |
2774 | // builds used for production | |
2775 | #if wxDEBUG_LEVEL > 1 | |
dddd1f21 VZ |
2776 | |
2777 | static void DrawSizers(wxWindowBase *win); | |
2778 | ||
a721fd82 | 2779 | static void DrawBorder(wxWindowBase *win, const wxRect& rect, bool fill, const wxPen* pen) |
dddd1f21 VZ |
2780 | { |
2781 | wxClientDC dc((wxWindow *)win); | |
a721fd82 | 2782 | dc.SetPen(*pen); |
1b942d5f | 2783 | dc.SetBrush(fill ? wxBrush(pen->GetColour(), wxBRUSHSTYLE_CROSSDIAG_HATCH) : |
a721fd82 | 2784 | *wxTRANSPARENT_BRUSH); |
dddd1f21 VZ |
2785 | dc.DrawRectangle(rect.Deflate(1, 1)); |
2786 | } | |
2787 | ||
2788 | static void DrawSizer(wxWindowBase *win, wxSizer *sizer) | |
2789 | { | |
2790 | const wxSizerItemList& items = sizer->GetChildren(); | |
2791 | for ( wxSizerItemList::const_iterator i = items.begin(), | |
2792 | end = items.end(); | |
2793 | i != end; | |
2794 | ++i ) | |
2795 | { | |
2796 | wxSizerItem *item = *i; | |
2797 | if ( item->IsSizer() ) | |
2798 | { | |
a721fd82 | 2799 | DrawBorder(win, item->GetRect().Deflate(2), false, wxRED_PEN); |
dddd1f21 VZ |
2800 | DrawSizer(win, item->GetSizer()); |
2801 | } | |
2802 | else if ( item->IsSpacer() ) | |
2803 | { | |
a721fd82 | 2804 | DrawBorder(win, item->GetRect().Deflate(2), true, wxBLUE_PEN); |
dddd1f21 VZ |
2805 | } |
2806 | else if ( item->IsWindow() ) | |
2807 | { | |
2808 | DrawSizers(item->GetWindow()); | |
2809 | } | |
1b942d5f FM |
2810 | else |
2811 | wxFAIL_MSG("inconsistent wxSizerItem status!"); | |
dddd1f21 VZ |
2812 | } |
2813 | } | |
2814 | ||
2815 | static void DrawSizers(wxWindowBase *win) | |
2816 | { | |
a721fd82 FM |
2817 | DrawBorder(win, win->GetClientSize(), false, wxGREEN_PEN); |
2818 | ||
dddd1f21 VZ |
2819 | wxSizer *sizer = win->GetSizer(); |
2820 | if ( sizer ) | |
2821 | { | |
dddd1f21 VZ |
2822 | DrawSizer(win, sizer); |
2823 | } | |
2824 | else // no sizer, still recurse into the children | |
2825 | { | |
2826 | const wxWindowList& children = win->GetChildren(); | |
2827 | for ( wxWindowList::const_iterator i = children.begin(), | |
2828 | end = children.end(); | |
2829 | i != end; | |
2830 | ++i ) | |
2831 | { | |
2832 | DrawSizers(*i); | |
2833 | } | |
1b942d5f FM |
2834 | |
2835 | // show all kind of sizes of this window; see the "window sizing" topic | |
2836 | // overview for more info about the various differences: | |
2837 | wxSize fullSz = win->GetSize(); | |
2838 | wxSize clientSz = win->GetClientSize(); | |
2839 | wxSize bestSz = win->GetBestSize(); | |
2840 | wxSize minSz = win->GetMinSize(); | |
2841 | wxSize maxSz = win->GetMaxSize(); | |
2842 | wxSize virtualSz = win->GetVirtualSize(); | |
2843 | ||
2844 | wxMessageOutputDebug dbgout; | |
2845 | dbgout.Printf( | |
2846 | "%-10s => fullsz=%4d;%-4d clientsz=%4d;%-4d bestsz=%4d;%-4d minsz=%4d;%-4d maxsz=%4d;%-4d virtualsz=%4d;%-4d\n", | |
79cb759d | 2847 | win->GetName(), |
1b942d5f FM |
2848 | fullSz.x, fullSz.y, |
2849 | clientSz.x, clientSz.y, | |
2850 | bestSz.x, bestSz.y, | |
2851 | minSz.x, minSz.y, | |
2852 | maxSz.x, maxSz.y, | |
2853 | virtualSz.x, virtualSz.y); | |
dddd1f21 VZ |
2854 | } |
2855 | } | |
2856 | ||
32be10a4 | 2857 | #endif // wxDEBUG_LEVEL |
dddd1f21 VZ |
2858 | |
2859 | // process special middle clicks | |
a02dc3e3 VZ |
2860 | void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) |
2861 | { | |
2862 | if ( event.ControlDown() && event.AltDown() ) | |
2863 | { | |
32be10a4 | 2864 | #if wxDEBUG_LEVEL > 1 |
dddd1f21 VZ |
2865 | // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds |
2866 | if ( event.ShiftDown() ) | |
2867 | { | |
2868 | DrawSizers(this); | |
dddd1f21 | 2869 | } |
32be10a4 | 2870 | else |
dddd1f21 | 2871 | #endif // __WXDEBUG__ |
32be10a4 | 2872 | { |
7822ffb1 | 2873 | #if wxUSE_MSGDLG |
32be10a4 VZ |
2874 | // just Ctrl-Alt-middle click shows information about wx version |
2875 | ::wxInfoMessageBox((wxWindow*)this); | |
7822ffb1 | 2876 | #endif // wxUSE_MSGDLG |
32be10a4 | 2877 | } |
a02dc3e3 VZ |
2878 | } |
2879 | else | |
2880 | { | |
2881 | event.Skip(); | |
2882 | } | |
2883 | } | |
2884 | ||
ed5317e5 JS |
2885 | // ---------------------------------------------------------------------------- |
2886 | // accessibility | |
2887 | // ---------------------------------------------------------------------------- | |
2888 | ||
2889 | #if wxUSE_ACCESSIBILITY | |
2890 | void wxWindowBase::SetAccessible(wxAccessible* accessible) | |
2891 | { | |
2aefc528 | 2892 | if (m_accessible && (accessible != m_accessible)) |
ed5317e5 JS |
2893 | delete m_accessible; |
2894 | m_accessible = accessible; | |
2895 | if (m_accessible) | |
2896 | m_accessible->SetWindow((wxWindow*) this); | |
2897 | } | |
2898 | ||
2899 | // Returns the accessible object, creating if necessary. | |
2900 | wxAccessible* wxWindowBase::GetOrCreateAccessible() | |
2901 | { | |
2902 | if (!m_accessible) | |
2903 | m_accessible = CreateAccessible(); | |
2904 | return m_accessible; | |
2905 | } | |
2906 | ||
2907 | // Override to create a specific accessible object. | |
2908 | wxAccessible* wxWindowBase::CreateAccessible() | |
2909 | { | |
2910 | return new wxWindowAccessible((wxWindow*) this); | |
2911 | } | |
2912 | ||
2913 | #endif | |
2914 | ||
f03fc89f VZ |
2915 | // ---------------------------------------------------------------------------- |
2916 | // list classes implementation | |
2917 | // ---------------------------------------------------------------------------- | |
2918 | ||
ed1288c1 VZ |
2919 | #if wxUSE_STL |
2920 | ||
7ec69821 | 2921 | #include "wx/listimpl.cpp" |
412e0d47 | 2922 | WX_DEFINE_LIST(wxWindowList) |
ed1288c1 | 2923 | |
602a2e02 | 2924 | #else // !wxUSE_STL |
ed1288c1 | 2925 | |
f03fc89f VZ |
2926 | void wxWindowListNode::DeleteData() |
2927 | { | |
2928 | delete (wxWindow *)GetData(); | |
2929 | } | |
ed1288c1 | 2930 | |
602a2e02 | 2931 | #endif // wxUSE_STL/!wxUSE_STL |
f03fc89f | 2932 | |
1e6feb95 VZ |
2933 | // ---------------------------------------------------------------------------- |
2934 | // borders | |
2935 | // ---------------------------------------------------------------------------- | |
2936 | ||
aede4ebb | 2937 | wxBorder wxWindowBase::GetBorder(long flags) const |
1e6feb95 | 2938 | { |
aede4ebb | 2939 | wxBorder border = (wxBorder)(flags & wxBORDER_MASK); |
1e6feb95 VZ |
2940 | if ( border == wxBORDER_DEFAULT ) |
2941 | { | |
2942 | border = GetDefaultBorder(); | |
2943 | } | |
78cd9c69 JS |
2944 | else if ( border == wxBORDER_THEME ) |
2945 | { | |
2946 | border = GetDefaultBorderForControl(); | |
2947 | } | |
1e6feb95 VZ |
2948 | |
2949 | return border; | |
2950 | } | |
2951 | ||
2952 | wxBorder wxWindowBase::GetDefaultBorder() const | |
2953 | { | |
2954 | return wxBORDER_NONE; | |
2955 | } | |
2956 | ||
2957 | // ---------------------------------------------------------------------------- | |
2958 | // hit testing | |
2959 | // ---------------------------------------------------------------------------- | |
2960 | ||
2961 | wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const | |
2962 | { | |
2963 | // here we just check if the point is inside the window or not | |
2964 | ||
2965 | // check the top and left border first | |
2966 | bool outside = x < 0 || y < 0; | |
2967 | if ( !outside ) | |
2968 | { | |
2969 | // check the right and bottom borders too | |
2970 | wxSize size = GetSize(); | |
2971 | outside = x >= size.x || y >= size.y; | |
2972 | } | |
2973 | ||
2974 | return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE; | |
2975 | } | |
2976 | ||
94633ad9 VZ |
2977 | // ---------------------------------------------------------------------------- |
2978 | // mouse capture | |
2979 | // ---------------------------------------------------------------------------- | |
2980 | ||
2981 | struct WXDLLEXPORT wxWindowNext | |
2982 | { | |
2983 | wxWindow *win; | |
2984 | wxWindowNext *next; | |
786646f3 | 2985 | } *wxWindowBase::ms_winCaptureNext = NULL; |
63e819f2 VS |
2986 | wxWindow *wxWindowBase::ms_winCaptureCurrent = NULL; |
2987 | bool wxWindowBase::ms_winCaptureChanging = false; | |
94633ad9 | 2988 | |
a83e1475 | 2989 | void wxWindowBase::CaptureMouse() |
94633ad9 | 2990 | { |
9a83f860 | 2991 | wxLogTrace(wxT("mousecapture"), wxT("CaptureMouse(%p)"), static_cast<void*>(this)); |
45e0dc94 | 2992 | |
9a83f860 | 2993 | wxASSERT_MSG( !ms_winCaptureChanging, wxT("recursive CaptureMouse call?") ); |
63e819f2 VS |
2994 | |
2995 | ms_winCaptureChanging = true; | |
2996 | ||
94633ad9 VZ |
2997 | wxWindow *winOld = GetCapture(); |
2998 | if ( winOld ) | |
2999 | { | |
df2f507b | 3000 | ((wxWindowBase*) winOld)->DoReleaseMouse(); |
edd802c6 | 3001 | |
94633ad9 VZ |
3002 | // save it on stack |
3003 | wxWindowNext *item = new wxWindowNext; | |
3004 | item->win = winOld; | |
3005 | item->next = ms_winCaptureNext; | |
3006 | ms_winCaptureNext = item; | |
3007 | } | |
3008 | //else: no mouse capture to save | |
3009 | ||
3010 | DoCaptureMouse(); | |
63e819f2 VS |
3011 | ms_winCaptureCurrent = (wxWindow*)this; |
3012 | ||
3013 | ms_winCaptureChanging = false; | |
94633ad9 VZ |
3014 | } |
3015 | ||
a83e1475 | 3016 | void wxWindowBase::ReleaseMouse() |
94633ad9 | 3017 | { |
9a83f860 | 3018 | wxLogTrace(wxT("mousecapture"), wxT("ReleaseMouse(%p)"), static_cast<void*>(this)); |
349d1942 | 3019 | |
9a83f860 | 3020 | wxASSERT_MSG( !ms_winCaptureChanging, wxT("recursive ReleaseMouse call?") ); |
63e819f2 | 3021 | |
31b9d29f VS |
3022 | wxASSERT_MSG( GetCapture() == this, |
3023 | "attempt to release mouse, but this window hasn't captured it" ); | |
3024 | wxASSERT_MSG( ms_winCaptureCurrent == this, | |
3025 | "attempt to release mouse, but this window hasn't captured it" ); | |
a7b09001 | 3026 | |
63e819f2 VS |
3027 | ms_winCaptureChanging = true; |
3028 | ||
94633ad9 | 3029 | DoReleaseMouse(); |
63e819f2 | 3030 | ms_winCaptureCurrent = NULL; |
94633ad9 VZ |
3031 | |
3032 | if ( ms_winCaptureNext ) | |
3033 | { | |
44f8caa7 | 3034 | ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse(); |
63e819f2 | 3035 | ms_winCaptureCurrent = ms_winCaptureNext->win; |
edd802c6 | 3036 | |
94633ad9 VZ |
3037 | wxWindowNext *item = ms_winCaptureNext; |
3038 | ms_winCaptureNext = item->next; | |
3039 | delete item; | |
3040 | } | |
3041 | //else: stack is empty, no previous capture | |
3042 | ||
63e819f2 VS |
3043 | ms_winCaptureChanging = false; |
3044 | ||
9a83f860 VZ |
3045 | wxLogTrace(wxT("mousecapture"), |
3046 | (const wxChar *) wxT("After ReleaseMouse() mouse is captured by %p"), | |
5c33522f | 3047 | static_cast<void*>(GetCapture())); |
94633ad9 VZ |
3048 | } |
3049 | ||
63e819f2 VS |
3050 | static void DoNotifyWindowAboutCaptureLost(wxWindow *win) |
3051 | { | |
3052 | wxMouseCaptureLostEvent event(win->GetId()); | |
3053 | event.SetEventObject(win); | |
40bdc5d6 VZ |
3054 | if ( !win->GetEventHandler()->ProcessEvent(event) ) |
3055 | { | |
44038f9a VS |
3056 | // windows must handle this event, otherwise the app wouldn't behave |
3057 | // correctly if it loses capture unexpectedly; see the discussion here: | |
3058 | // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863 | |
3059 | // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376 | |
9a83f860 | 3060 | wxFAIL_MSG( wxT("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") ); |
40bdc5d6 | 3061 | } |
63e819f2 VS |
3062 | } |
3063 | ||
3064 | /* static */ | |
72f8c792 | 3065 | void wxWindowBase::NotifyCaptureLost() |
63e819f2 VS |
3066 | { |
3067 | // don't do anything if capture lost was expected, i.e. resulted from | |
3068 | // a wx call to ReleaseMouse or CaptureMouse: | |
3069 | if ( ms_winCaptureChanging ) | |
3070 | return; | |
3071 | ||
3072 | // if the capture was lost unexpectedly, notify every window that has | |
3073 | // capture (on stack or current) about it and clear the stack: | |
3074 | ||
3075 | if ( ms_winCaptureCurrent ) | |
3076 | { | |
3077 | DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent); | |
3078 | ms_winCaptureCurrent = NULL; | |
3079 | } | |
3080 | ||
3081 | while ( ms_winCaptureNext ) | |
3082 | { | |
3083 | wxWindowNext *item = ms_winCaptureNext; | |
3084 | ms_winCaptureNext = item->next; | |
3085 | ||
3086 | DoNotifyWindowAboutCaptureLost(item->win); | |
3087 | ||
3088 | delete item; | |
3089 | } | |
3090 | } | |
3091 | ||
5048c832 | 3092 | #if wxUSE_HOTKEY |
540b6b09 VZ |
3093 | |
3094 | bool | |
3095 | wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId), | |
3096 | int WXUNUSED(modifiers), | |
3097 | int WXUNUSED(keycode)) | |
5048c832 JS |
3098 | { |
3099 | // not implemented | |
3100 | return false; | |
3101 | } | |
3102 | ||
540b6b09 | 3103 | bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId)) |
5048c832 JS |
3104 | { |
3105 | // not implemented | |
3106 | return false; | |
3107 | } | |
540b6b09 VZ |
3108 | |
3109 | #endif // wxUSE_HOTKEY | |
7de59551 | 3110 | |
4caf847c VZ |
3111 | // ---------------------------------------------------------------------------- |
3112 | // event processing | |
3113 | // ---------------------------------------------------------------------------- | |
3114 | ||
8cc208e3 | 3115 | bool wxWindowBase::TryBefore(wxEvent& event) |
4caf847c | 3116 | { |
6eabf58c | 3117 | #if wxUSE_VALIDATORS |
4caf847c VZ |
3118 | // Can only use the validator of the window which |
3119 | // is receiving the event | |
3120 | if ( event.GetEventObject() == this ) | |
3121 | { | |
92089d00 | 3122 | wxValidator * const validator = GetValidator(); |
512220b6 | 3123 | if ( validator && validator->ProcessEventLocally(event) ) |
4caf847c | 3124 | { |
6eabf58c | 3125 | return true; |
4caf847c VZ |
3126 | } |
3127 | } | |
6eabf58c | 3128 | #endif // wxUSE_VALIDATORS |
4caf847c | 3129 | |
8cc208e3 | 3130 | return wxEvtHandler::TryBefore(event); |
4caf847c VZ |
3131 | } |
3132 | ||
8cc208e3 | 3133 | bool wxWindowBase::TryAfter(wxEvent& event) |
4caf847c | 3134 | { |
90e572f1 | 3135 | // carry on up the parent-child hierarchy if the propagation count hasn't |
040e234d VZ |
3136 | // reached zero yet |
3137 | if ( event.ShouldPropagate() ) | |
4caf847c VZ |
3138 | { |
3139 | // honour the requests to stop propagation at this window: this is | |
3140 | // used by the dialogs, for example, to prevent processing the events | |
3141 | // from the dialog controls in the parent frame which rarely, if ever, | |
3142 | // makes sense | |
3143 | if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) ) | |
3144 | { | |
3145 | wxWindow *parent = GetParent(); | |
3146 | if ( parent && !parent->IsBeingDeleted() ) | |
040e234d VZ |
3147 | { |
3148 | wxPropagateOnce propagateOnce(event); | |
3149 | ||
4caf847c | 3150 | return parent->GetEventHandler()->ProcessEvent(event); |
040e234d | 3151 | } |
4caf847c VZ |
3152 | } |
3153 | } | |
3154 | ||
8cc208e3 | 3155 | return wxEvtHandler::TryAfter(event); |
4caf847c VZ |
3156 | } |
3157 | ||
c944775f VZ |
3158 | // ---------------------------------------------------------------------------- |
3159 | // window relationships | |
3160 | // ---------------------------------------------------------------------------- | |
3161 | ||
3162 | wxWindow *wxWindowBase::DoGetSibling(WindowOrder order) const | |
3163 | { | |
3164 | wxCHECK_MSG( GetParent(), NULL, | |
9a83f860 | 3165 | wxT("GetPrev/NextSibling() don't work for TLWs!") ); |
c944775f VZ |
3166 | |
3167 | wxWindowList& siblings = GetParent()->GetChildren(); | |
c52b9635 | 3168 | wxWindowList::compatibility_iterator i = siblings.Find((wxWindow *)this); |
9a83f860 | 3169 | wxCHECK_MSG( i, NULL, wxT("window not a child of its parent?") ); |
c944775f VZ |
3170 | |
3171 | if ( order == OrderBefore ) | |
3172 | i = i->GetPrevious(); | |
3173 | else // OrderAfter | |
3174 | i = i->GetNext(); | |
3175 | ||
3176 | return i ? i->GetData() : NULL; | |
3177 | } | |
3178 | ||
5f6cfda7 | 3179 | // ---------------------------------------------------------------------------- |
a24de76b | 3180 | // keyboard navigation |
5f6cfda7 JS |
3181 | // ---------------------------------------------------------------------------- |
3182 | ||
5644933f | 3183 | // Navigates in the specified direction inside this window |
553d2d7d | 3184 | bool wxWindowBase::DoNavigateIn(int flags) |
5f6cfda7 | 3185 | { |
5644933f VZ |
3186 | #ifdef wxHAS_NATIVE_TAB_TRAVERSAL |
3187 | // native code doesn't process our wxNavigationKeyEvents anyhow | |
553d2d7d | 3188 | wxUnusedVar(flags); |
5644933f VZ |
3189 | return false; |
3190 | #else // !wxHAS_NATIVE_TAB_TRAVERSAL | |
5f6cfda7 | 3191 | wxNavigationKeyEvent eventNav; |
f029f1d1 VS |
3192 | wxWindow *focused = FindFocus(); |
3193 | eventNav.SetCurrentFocus(focused); | |
3194 | eventNav.SetEventObject(focused); | |
eedc82f4 | 3195 | eventNav.SetFlags(flags); |
5644933f VZ |
3196 | return GetEventHandler()->ProcessEvent(eventNav); |
3197 | #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL | |
5f6cfda7 JS |
3198 | } |
3199 | ||
f029f1d1 VS |
3200 | bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent& event) |
3201 | { | |
3202 | if ( event.GetKeyCode() != WXK_TAB ) | |
3203 | return false; | |
3204 | ||
3205 | int flags = wxNavigationKeyEvent::FromTab; | |
3206 | ||
3207 | if ( event.ShiftDown() ) | |
3208 | flags |= wxNavigationKeyEvent::IsBackward; | |
3209 | else | |
3210 | flags |= wxNavigationKeyEvent::IsForward; | |
3211 | ||
3212 | if ( event.ControlDown() ) | |
3213 | flags |= wxNavigationKeyEvent::WinChange; | |
3214 | ||
3215 | Navigate(flags); | |
3216 | return true; | |
3217 | } | |
3218 | ||
c944775f | 3219 | void wxWindowBase::DoMoveInTabOrder(wxWindow *win, WindowOrder move) |
a24de76b VZ |
3220 | { |
3221 | // check that we're not a top level window | |
3222 | wxCHECK_RET( GetParent(), | |
9a83f860 | 3223 | wxT("MoveBefore/AfterInTabOrder() don't work for TLWs!") ); |
a24de76b | 3224 | |
ef6816ef VZ |
3225 | // detect the special case when we have nothing to do anyhow and when the |
3226 | // code below wouldn't work | |
3227 | if ( win == this ) | |
3228 | return; | |
3229 | ||
a24de76b VZ |
3230 | // find the target window in the siblings list |
3231 | wxWindowList& siblings = GetParent()->GetChildren(); | |
3232 | wxWindowList::compatibility_iterator i = siblings.Find(win); | |
9a83f860 | 3233 | wxCHECK_RET( i, wxT("MoveBefore/AfterInTabOrder(): win is not a sibling") ); |
a24de76b VZ |
3234 | |
3235 | // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we | |
3236 | // can't just move the node around | |
feef1ecf VZ |
3237 | wxWindow *self = (wxWindow *)this; |
3238 | siblings.DeleteObject(self); | |
c944775f | 3239 | if ( move == OrderAfter ) |
9e9300c4 VZ |
3240 | { |
3241 | i = i->GetNext(); | |
3242 | } | |
3243 | ||
3244 | if ( i ) | |
a24de76b | 3245 | { |
feef1ecf | 3246 | siblings.Insert(i, self); |
a24de76b | 3247 | } |
c944775f | 3248 | else // OrderAfter and win was the last sibling |
a24de76b | 3249 | { |
feef1ecf | 3250 | siblings.Append(self); |
a24de76b VZ |
3251 | } |
3252 | } | |
3253 | ||
0fe02759 VS |
3254 | // ---------------------------------------------------------------------------- |
3255 | // focus handling | |
3256 | // ---------------------------------------------------------------------------- | |
3257 | ||
3258 | /*static*/ wxWindow* wxWindowBase::FindFocus() | |
3259 | { | |
9c52a429 | 3260 | wxWindowBase *win = DoFindFocus(); |
0fe02759 VS |
3261 | return win ? win->GetMainWindowOfCompositeControl() : NULL; |
3262 | } | |
3263 | ||
3358af0f VS |
3264 | bool wxWindowBase::HasFocus() const |
3265 | { | |
3266 | wxWindowBase *win = DoFindFocus(); | |
3267 | return win == this || | |
3268 | win == wxConstCast(this, wxWindowBase)->GetMainWindowOfCompositeControl(); | |
3269 | } | |
3270 | ||
4f24cbbd VS |
3271 | // ---------------------------------------------------------------------------- |
3272 | // drag and drop | |
3273 | // ---------------------------------------------------------------------------- | |
3274 | ||
3275 | #if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__) | |
3276 | ||
3277 | namespace | |
3278 | { | |
3279 | ||
3280 | class DragAcceptFilesTarget : public wxFileDropTarget | |
3281 | { | |
3282 | public: | |
3283 | DragAcceptFilesTarget(wxWindowBase *win) : m_win(win) {} | |
3284 | ||
3285 | virtual bool OnDropFiles(wxCoord x, wxCoord y, | |
3286 | const wxArrayString& filenames) | |
3287 | { | |
3288 | wxDropFilesEvent event(wxEVT_DROP_FILES, | |
3289 | filenames.size(), | |
3290 | wxCArrayString(filenames).Release()); | |
3291 | event.SetEventObject(m_win); | |
3292 | event.m_pos.x = x; | |
3293 | event.m_pos.y = y; | |
3294 | ||
3295 | return m_win->HandleWindowEvent(event); | |
3296 | } | |
3297 | ||
3298 | private: | |
3299 | wxWindowBase * const m_win; | |
3300 | ||
c0c133e1 | 3301 | wxDECLARE_NO_COPY_CLASS(DragAcceptFilesTarget); |
4f24cbbd VS |
3302 | }; |
3303 | ||
3304 | ||
3305 | } // anonymous namespace | |
3306 | ||
3307 | // Generic version of DragAcceptFiles(). It works by installing a simple | |
3308 | // wxFileDropTarget-to-EVT_DROP_FILES adaptor and therefore cannot be used | |
3309 | // together with explicit SetDropTarget() calls. | |
3310 | void wxWindowBase::DragAcceptFiles(bool accept) | |
3311 | { | |
3312 | if ( accept ) | |
3313 | { | |
3314 | wxASSERT_MSG( !GetDropTarget(), | |
3315 | "cannot use DragAcceptFiles() and SetDropTarget() together" ); | |
3316 | SetDropTarget(new DragAcceptFilesTarget(this)); | |
3317 | } | |
3318 | else | |
3319 | { | |
3320 | SetDropTarget(NULL); | |
3321 | } | |
3322 | } | |
3323 | ||
3324 | #endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__) | |
3325 | ||
33b494d6 VZ |
3326 | // ---------------------------------------------------------------------------- |
3327 | // global functions | |
3328 | // ---------------------------------------------------------------------------- | |
3329 | ||
3330 | wxWindow* wxGetTopLevelParent(wxWindow *win) | |
3331 | { | |
3332 | while ( win && !win->IsTopLevel() ) | |
3333 | win = win->GetParent(); | |
3334 | ||
3335 | return win; | |
3336 | } | |
3337 | ||
ed5317e5 JS |
3338 | #if wxUSE_ACCESSIBILITY |
3339 | // ---------------------------------------------------------------------------- | |
3340 | // accessible object for windows | |
3341 | // ---------------------------------------------------------------------------- | |
3342 | ||
3343 | // Can return either a child object, or an integer | |
3344 | // representing the child element, starting from 1. | |
66b9ec3d | 3345 | wxAccStatus wxWindowAccessible::HitTest(const wxPoint& WXUNUSED(pt), int* WXUNUSED(childId), wxAccessible** WXUNUSED(childObject)) |
ed5317e5 JS |
3346 | { |
3347 | wxASSERT( GetWindow() != NULL ); | |
3348 | if (!GetWindow()) | |
3349 | return wxACC_FAIL; | |
3350 | ||
3351 | return wxACC_NOT_IMPLEMENTED; | |
3352 | } | |
3353 | ||
3354 | // Returns the rectangle for this object (id = 0) or a child element (id > 0). | |
3355 | wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId) | |
3356 | { | |
3357 | wxASSERT( GetWindow() != NULL ); | |
3358 | if (!GetWindow()) | |
3359 | return wxACC_FAIL; | |
3360 | ||
c6e2af45 JS |
3361 | wxWindow* win = NULL; |
3362 | if (elementId == 0) | |
3363 | { | |
3364 | win = GetWindow(); | |
3365 | } | |
3366 | else | |
3367 | { | |
3368 | if (elementId <= (int) GetWindow()->GetChildren().GetCount()) | |
3369 | { | |
ee6eb8d8 | 3370 | win = GetWindow()->GetChildren().Item(elementId-1)->GetData(); |
c6e2af45 JS |
3371 | } |
3372 | else | |
3373 | return wxACC_FAIL; | |
3374 | } | |
3375 | if (win) | |
3376 | { | |
3377 | rect = win->GetRect(); | |
3378 | if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow))) | |
3379 | rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition())); | |
3380 | return wxACC_OK; | |
3381 | } | |
3382 | ||
ed5317e5 JS |
3383 | return wxACC_NOT_IMPLEMENTED; |
3384 | } | |
3385 | ||
3386 | // Navigates from fromId to toId/toObject. | |
3387 | wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId, | |
66b9ec3d | 3388 | int* WXUNUSED(toId), wxAccessible** toObject) |
ed5317e5 JS |
3389 | { |
3390 | wxASSERT( GetWindow() != NULL ); | |
3391 | if (!GetWindow()) | |
3392 | return wxACC_FAIL; | |
3393 | ||
c6e2af45 JS |
3394 | switch (navDir) |
3395 | { | |
3396 | case wxNAVDIR_FIRSTCHILD: | |
3397 | { | |
3398 | if (GetWindow()->GetChildren().GetCount() == 0) | |
3399 | return wxACC_FALSE; | |
3400 | wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData(); | |
3401 | *toObject = childWindow->GetOrCreateAccessible(); | |
3402 | ||
3403 | return wxACC_OK; | |
3404 | } | |
3405 | case wxNAVDIR_LASTCHILD: | |
3406 | { | |
3407 | if (GetWindow()->GetChildren().GetCount() == 0) | |
3408 | return wxACC_FALSE; | |
3409 | wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData(); | |
3410 | *toObject = childWindow->GetOrCreateAccessible(); | |
3411 | ||
3412 | return wxACC_OK; | |
3413 | } | |
3414 | case wxNAVDIR_RIGHT: | |
3415 | case wxNAVDIR_DOWN: | |
3416 | case wxNAVDIR_NEXT: | |
3417 | { | |
ee6eb8d8 MB |
3418 | wxWindowList::compatibility_iterator node = |
3419 | wxWindowList::compatibility_iterator(); | |
c6e2af45 JS |
3420 | if (fromId == 0) |
3421 | { | |
3422 | // Can't navigate to sibling of this window | |
3423 | // if we're a top-level window. | |
3424 | if (!GetWindow()->GetParent()) | |
3425 | return wxACC_NOT_IMPLEMENTED; | |
3426 | ||
3427 | node = GetWindow()->GetParent()->GetChildren().Find(GetWindow()); | |
3428 | } | |
3429 | else | |
3430 | { | |
3431 | if (fromId <= (int) GetWindow()->GetChildren().GetCount()) | |
33b3f7c3 | 3432 | node = GetWindow()->GetChildren().Item(fromId-1); |
c6e2af45 JS |
3433 | } |
3434 | ||
3435 | if (node && node->GetNext()) | |
3436 | { | |
ee6eb8d8 | 3437 | wxWindow* nextWindow = node->GetNext()->GetData(); |
c6e2af45 JS |
3438 | *toObject = nextWindow->GetOrCreateAccessible(); |
3439 | return wxACC_OK; | |
3440 | } | |
3441 | else | |
3442 | return wxACC_FALSE; | |
3443 | } | |
3444 | case wxNAVDIR_LEFT: | |
3445 | case wxNAVDIR_UP: | |
3446 | case wxNAVDIR_PREVIOUS: | |
3447 | { | |
ee6eb8d8 MB |
3448 | wxWindowList::compatibility_iterator node = |
3449 | wxWindowList::compatibility_iterator(); | |
c6e2af45 JS |
3450 | if (fromId == 0) |
3451 | { | |
3452 | // Can't navigate to sibling of this window | |
3453 | // if we're a top-level window. | |
3454 | if (!GetWindow()->GetParent()) | |
3455 | return wxACC_NOT_IMPLEMENTED; | |
3456 | ||
3457 | node = GetWindow()->GetParent()->GetChildren().Find(GetWindow()); | |
3458 | } | |
3459 | else | |
3460 | { | |
3461 | if (fromId <= (int) GetWindow()->GetChildren().GetCount()) | |
33b3f7c3 | 3462 | node = GetWindow()->GetChildren().Item(fromId-1); |
c6e2af45 JS |
3463 | } |
3464 | ||
3465 | if (node && node->GetPrevious()) | |
3466 | { | |
ee6eb8d8 | 3467 | wxWindow* previousWindow = node->GetPrevious()->GetData(); |
c6e2af45 JS |
3468 | *toObject = previousWindow->GetOrCreateAccessible(); |
3469 | return wxACC_OK; | |
3470 | } | |
3471 | else | |
3472 | return wxACC_FALSE; | |
3473 | } | |
3474 | } | |
3475 | ||
ed5317e5 JS |
3476 | return wxACC_NOT_IMPLEMENTED; |
3477 | } | |
3478 | ||
3479 | // Gets the name of the specified object. | |
3480 | wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name) | |
3481 | { | |
3482 | wxASSERT( GetWindow() != NULL ); | |
3483 | if (!GetWindow()) | |
3484 | return wxACC_FAIL; | |
3485 | ||
2aefc528 JS |
3486 | wxString title; |
3487 | ||
77ffb593 | 3488 | // If a child, leave wxWidgets to call the function on the actual |
2aefc528 JS |
3489 | // child object. |
3490 | if (childId > 0) | |
3491 | return wxACC_NOT_IMPLEMENTED; | |
3492 | ||
3493 | // This will eventually be replaced by specialised | |
77ffb593 | 3494 | // accessible classes, one for each kind of wxWidgets |
2aefc528 | 3495 | // control or window. |
0b4f47a3 | 3496 | #if wxUSE_BUTTON |
2aefc528 JS |
3497 | if (GetWindow()->IsKindOf(CLASSINFO(wxButton))) |
3498 | title = ((wxButton*) GetWindow())->GetLabel(); | |
3499 | else | |
0b4f47a3 | 3500 | #endif |
2aefc528 | 3501 | title = GetWindow()->GetName(); |
e11f4636 | 3502 | |
ba889513 | 3503 | if (!title.empty()) |
ed5317e5 JS |
3504 | { |
3505 | *name = title; | |
3506 | return wxACC_OK; | |
3507 | } | |
3508 | else | |
3509 | return wxACC_NOT_IMPLEMENTED; | |
3510 | } | |
3511 | ||
3512 | // Gets the number of children. | |
3513 | wxAccStatus wxWindowAccessible::GetChildCount(int* childId) | |
3514 | { | |
3515 | wxASSERT( GetWindow() != NULL ); | |
3516 | if (!GetWindow()) | |
3517 | return wxACC_FAIL; | |
3518 | ||
3519 | *childId = (int) GetWindow()->GetChildren().GetCount(); | |
3520 | return wxACC_OK; | |
3521 | } | |
3522 | ||
3523 | // Gets the specified child (starting from 1). | |
3524 | // If *child is NULL and return value is wxACC_OK, | |
3525 | // this means that the child is a simple element and | |
3526 | // not an accessible object. | |
3527 | wxAccStatus wxWindowAccessible::GetChild(int childId, wxAccessible** child) | |
3528 | { | |
3529 | wxASSERT( GetWindow() != NULL ); | |
3530 | if (!GetWindow()) | |
3531 | return wxACC_FAIL; | |
3532 | ||
3533 | if (childId == 0) | |
3534 | { | |
3535 | *child = this; | |
3536 | return wxACC_OK; | |
3537 | } | |
3538 | ||
3539 | if (childId > (int) GetWindow()->GetChildren().GetCount()) | |
3540 | return wxACC_FAIL; | |
3541 | ||
ee6eb8d8 | 3542 | wxWindow* childWindow = GetWindow()->GetChildren().Item(childId-1)->GetData(); |
ed5317e5 JS |
3543 | *child = childWindow->GetOrCreateAccessible(); |
3544 | if (*child) | |
3545 | return wxACC_OK; | |
3546 | else | |
3547 | return wxACC_FAIL; | |
3548 | } | |
3549 | ||
3550 | // Gets the parent, or NULL. | |
3551 | wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent) | |
3552 | { | |
3553 | wxASSERT( GetWindow() != NULL ); | |
3554 | if (!GetWindow()) | |
3555 | return wxACC_FAIL; | |
3556 | ||
3557 | wxWindow* parentWindow = GetWindow()->GetParent(); | |
c6e2af45 | 3558 | if (!parentWindow) |
ed5317e5 JS |
3559 | { |
3560 | *parent = NULL; | |
3561 | return wxACC_OK; | |
3562 | } | |
3563 | else | |
3564 | { | |
3565 | *parent = parentWindow->GetOrCreateAccessible(); | |
3566 | if (*parent) | |
3567 | return wxACC_OK; | |
3568 | else | |
3569 | return wxACC_FAIL; | |
3570 | } | |
3571 | } | |
3572 | ||
3573 | // Performs the default action. childId is 0 (the action for this object) | |
3574 | // or > 0 (the action for a child). | |
3575 | // Return wxACC_NOT_SUPPORTED if there is no default action for this | |
3576 | // window (e.g. an edit control). | |
66b9ec3d | 3577 | wxAccStatus wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId)) |
ed5317e5 JS |
3578 | { |
3579 | wxASSERT( GetWindow() != NULL ); | |
3580 | if (!GetWindow()) | |
3581 | return wxACC_FAIL; | |
3582 | ||
3583 | return wxACC_NOT_IMPLEMENTED; | |
3584 | } | |
3585 | ||
3586 | // Gets the default action for this object (0) or > 0 (the action for a child). | |
3587 | // Return wxACC_OK even if there is no action. actionName is the action, or the empty | |
3588 | // string if there is no action. | |
3589 | // The retrieved string describes the action that is performed on an object, | |
3590 | // not what the object does as a result. For example, a toolbar button that prints | |
3591 | // a document has a default action of "Press" rather than "Prints the current document." | |
66b9ec3d | 3592 | wxAccStatus wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId), wxString* WXUNUSED(actionName)) |
ed5317e5 JS |
3593 | { |
3594 | wxASSERT( GetWindow() != NULL ); | |
3595 | if (!GetWindow()) | |
3596 | return wxACC_FAIL; | |
3597 | ||
3598 | return wxACC_NOT_IMPLEMENTED; | |
3599 | } | |
3600 | ||
3601 | // Returns the description for this object or a child. | |
66b9ec3d | 3602 | wxAccStatus wxWindowAccessible::GetDescription(int WXUNUSED(childId), wxString* description) |
ed5317e5 JS |
3603 | { |
3604 | wxASSERT( GetWindow() != NULL ); | |
3605 | if (!GetWindow()) | |
3606 | return wxACC_FAIL; | |
3607 | ||
dc6588e7 | 3608 | wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard)); |
ba889513 | 3609 | if (!ht.empty()) |
2aefc528 JS |
3610 | { |
3611 | *description = ht; | |
3612 | return wxACC_OK; | |
3613 | } | |
ed5317e5 JS |
3614 | return wxACC_NOT_IMPLEMENTED; |
3615 | } | |
3616 | ||
3617 | // Returns help text for this object or a child, similar to tooltip text. | |
66b9ec3d | 3618 | wxAccStatus wxWindowAccessible::GetHelpText(int WXUNUSED(childId), wxString* helpText) |
ed5317e5 JS |
3619 | { |
3620 | wxASSERT( GetWindow() != NULL ); | |
3621 | if (!GetWindow()) | |
3622 | return wxACC_FAIL; | |
3623 | ||
dc6588e7 | 3624 | wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard)); |
ba889513 | 3625 | if (!ht.empty()) |
ed5317e5 JS |
3626 | { |
3627 | *helpText = ht; | |
3628 | return wxACC_OK; | |
3629 | } | |
3630 | return wxACC_NOT_IMPLEMENTED; | |
3631 | } | |
3632 | ||
3633 | // Returns the keyboard shortcut for this object or child. | |
3634 | // Return e.g. ALT+K | |
66b9ec3d | 3635 | wxAccStatus wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId), wxString* WXUNUSED(shortcut)) |
ed5317e5 JS |
3636 | { |
3637 | wxASSERT( GetWindow() != NULL ); | |
3638 | if (!GetWindow()) | |
3639 | return wxACC_FAIL; | |
3640 | ||
3641 | return wxACC_NOT_IMPLEMENTED; | |
3642 | } | |
3643 | ||
3644 | // Returns a role constant. | |
3645 | wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role) | |
3646 | { | |
3647 | wxASSERT( GetWindow() != NULL ); | |
3648 | if (!GetWindow()) | |
3649 | return wxACC_FAIL; | |
3650 | ||
77ffb593 | 3651 | // If a child, leave wxWidgets to call the function on the actual |
2aefc528 JS |
3652 | // child object. |
3653 | if (childId > 0) | |
3654 | return wxACC_NOT_IMPLEMENTED; | |
3655 | ||
3656 | if (GetWindow()->IsKindOf(CLASSINFO(wxControl))) | |
3657 | return wxACC_NOT_IMPLEMENTED; | |
3658 | #if wxUSE_STATUSBAR | |
3659 | if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar))) | |
3660 | return wxACC_NOT_IMPLEMENTED; | |
3661 | #endif | |
3662 | #if wxUSE_TOOLBAR | |
3663 | if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar))) | |
3664 | return wxACC_NOT_IMPLEMENTED; | |
3665 | #endif | |
3666 | ||
3667 | //*role = wxROLE_SYSTEM_CLIENT; | |
3668 | *role = wxROLE_SYSTEM_CLIENT; | |
3669 | return wxACC_OK; | |
3670 | ||
66b9ec3d | 3671 | #if 0 |
ed5317e5 | 3672 | return wxACC_NOT_IMPLEMENTED; |
66b9ec3d | 3673 | #endif |
ed5317e5 JS |
3674 | } |
3675 | ||
3676 | // Returns a state constant. | |
3677 | wxAccStatus wxWindowAccessible::GetState(int childId, long* state) | |
3678 | { | |
3679 | wxASSERT( GetWindow() != NULL ); | |
3680 | if (!GetWindow()) | |
3681 | return wxACC_FAIL; | |
3682 | ||
77ffb593 | 3683 | // If a child, leave wxWidgets to call the function on the actual |
2aefc528 JS |
3684 | // child object. |
3685 | if (childId > 0) | |
3686 | return wxACC_NOT_IMPLEMENTED; | |
3687 | ||
3688 | if (GetWindow()->IsKindOf(CLASSINFO(wxControl))) | |
3689 | return wxACC_NOT_IMPLEMENTED; | |
3690 | ||
3691 | #if wxUSE_STATUSBAR | |
3692 | if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar))) | |
3693 | return wxACC_NOT_IMPLEMENTED; | |
3694 | #endif | |
3695 | #if wxUSE_TOOLBAR | |
3696 | if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar))) | |
3697 | return wxACC_NOT_IMPLEMENTED; | |
3698 | #endif | |
3699 | ||
3700 | *state = 0; | |
3701 | return wxACC_OK; | |
3702 | ||
66b9ec3d | 3703 | #if 0 |
ed5317e5 | 3704 | return wxACC_NOT_IMPLEMENTED; |
66b9ec3d | 3705 | #endif |
ed5317e5 JS |
3706 | } |
3707 | ||
3708 | // Returns a localized string representing the value for the object | |
3709 | // or child. | |
66b9ec3d | 3710 | wxAccStatus wxWindowAccessible::GetValue(int WXUNUSED(childId), wxString* WXUNUSED(strValue)) |
ed5317e5 JS |
3711 | { |
3712 | wxASSERT( GetWindow() != NULL ); | |
3713 | if (!GetWindow()) | |
3714 | return wxACC_FAIL; | |
3715 | ||
3716 | return wxACC_NOT_IMPLEMENTED; | |
3717 | } | |
3718 | ||
3719 | // Selects the object or child. | |
66b9ec3d | 3720 | wxAccStatus wxWindowAccessible::Select(int WXUNUSED(childId), wxAccSelectionFlags WXUNUSED(selectFlags)) |
ed5317e5 JS |
3721 | { |
3722 | wxASSERT( GetWindow() != NULL ); | |
3723 | if (!GetWindow()) | |
3724 | return wxACC_FAIL; | |
3725 | ||
3726 | return wxACC_NOT_IMPLEMENTED; | |
3727 | } | |
3728 | ||
3729 | // Gets the window with the keyboard focus. | |
3730 | // If childId is 0 and child is NULL, no object in | |
3731 | // this subhierarchy has the focus. | |
3732 | // If this object has the focus, child should be 'this'. | |
66b9ec3d | 3733 | wxAccStatus wxWindowAccessible::GetFocus(int* WXUNUSED(childId), wxAccessible** WXUNUSED(child)) |
ed5317e5 JS |
3734 | { |
3735 | wxASSERT( GetWindow() != NULL ); | |
3736 | if (!GetWindow()) | |
3737 | return wxACC_FAIL; | |
3738 | ||
3739 | return wxACC_NOT_IMPLEMENTED; | |
3740 | } | |
3741 | ||
ca5c6ac3 | 3742 | #if wxUSE_VARIANT |
ed5317e5 JS |
3743 | // Gets a variant representing the selected children |
3744 | // of this object. | |
3745 | // Acceptable values: | |
cab1a605 | 3746 | // - a null variant (IsNull() returns true) |
ed5317e5 JS |
3747 | // - a list variant (GetType() == wxT("list") |
3748 | // - an integer representing the selected child element, | |
3749 | // or 0 if this object is selected (GetType() == wxT("long") | |
3750 | // - a "void*" pointer to a wxAccessible child object | |
66b9ec3d | 3751 | wxAccStatus wxWindowAccessible::GetSelections(wxVariant* WXUNUSED(selections)) |
ed5317e5 JS |
3752 | { |
3753 | wxASSERT( GetWindow() != NULL ); | |
3754 | if (!GetWindow()) | |
3755 | return wxACC_FAIL; | |
3756 | ||
3757 | return wxACC_NOT_IMPLEMENTED; | |
3758 | } | |
ca5c6ac3 | 3759 | #endif // wxUSE_VARIANT |
ed5317e5 JS |
3760 | |
3761 | #endif // wxUSE_ACCESSIBILITY | |
978af864 VZ |
3762 | |
3763 | // ---------------------------------------------------------------------------- | |
3764 | // RTL support | |
3765 | // ---------------------------------------------------------------------------- | |
3766 | ||
3767 | wxCoord | |
3768 | wxWindowBase::AdjustForLayoutDirection(wxCoord x, | |
3769 | wxCoord width, | |
3770 | wxCoord widthTotal) const | |
3771 | { | |
3772 | if ( GetLayoutDirection() == wxLayout_RightToLeft ) | |
3773 | { | |
3774 | x = widthTotal - x - width; | |
3775 | } | |
3776 | ||
3777 | return x; | |
3778 | } | |
3779 | ||
f35fdf7e | 3780 |