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