]>
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" |
a37a5a73 | 41 | #include "wx/statusbr.h" |
e0cf3745 | 42 | #include "wx/toolbar.h" |
ed39ff57 | 43 | #include "wx/dcclient.h" |
7d59475e | 44 | #include "wx/scrolbar.h" |
f03fc89f | 45 | #include "wx/layout.h" |
ed2fbeb8 WS |
46 | #include "wx/sizer.h" |
47 | #endif //WX_PRECOMP | |
461e93f9 | 48 | |
f03fc89f VZ |
49 | #if wxUSE_DRAG_AND_DROP |
50 | #include "wx/dnd.h" | |
51 | #endif // wxUSE_DRAG_AND_DROP | |
52 | ||
ed5317e5 | 53 | #if wxUSE_ACCESSIBILITY |
7de59551 | 54 | #include "wx/access.h" |
ed5317e5 JS |
55 | #endif |
56 | ||
bd83cb56 VZ |
57 | #if wxUSE_HELP |
58 | #include "wx/cshelp.h" | |
59 | #endif // wxUSE_HELP | |
60 | ||
f03fc89f VZ |
61 | #if wxUSE_TOOLTIPS |
62 | #include "wx/tooltip.h" | |
63 | #endif // wxUSE_TOOLTIPS | |
64 | ||
789295bf VZ |
65 | #if wxUSE_CARET |
66 | #include "wx/caret.h" | |
67 | #endif // wxUSE_CARET | |
68 | ||
ff9f7a12 | 69 | #if wxUSE_SYSTEM_OPTIONS |
cab1a605 | 70 | #include "wx/sysopt.h" |
ff9f7a12 SC |
71 | #endif |
72 | ||
0118b60b | 73 | // For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog. |
c1da5058 | 74 | // The gtk includes don't pull any other headers in, at least not on my system - MR |
0118b60b | 75 | #ifdef __WXGTK__ |
6ef708cd PC |
76 | #ifdef __WXGTK20__ |
77 | #include <gtk/gtkversion.h> | |
78 | #else | |
79 | #include <gtk/gtkfeatures.h> | |
80 | #endif | |
0118b60b MR |
81 | extern const unsigned int gtk_major_version; |
82 | extern const unsigned int gtk_minor_version; | |
83 | extern const unsigned int gtk_micro_version; | |
84 | #endif | |
85 | ||
8bb6b2c0 VZ |
86 | #include "wx/platinfo.h" |
87 | ||
e7445ff8 PC |
88 | // Windows List |
89 | WXDLLIMPEXP_DATA_CORE(wxWindowList) wxTopLevelWindows; | |
90 | ||
f03fc89f VZ |
91 | // ---------------------------------------------------------------------------- |
92 | // static data | |
93 | // ---------------------------------------------------------------------------- | |
94 | ||
ba889513 | 95 | #if defined(__WXPALMOS__) |
a152561c | 96 | int wxWindowBase::ms_lastControlId = 32767; |
ba889513 | 97 | #elif defined(__WXPM__) |
edd802c6 DW |
98 | int wxWindowBase::ms_lastControlId = 2000; |
99 | #else | |
42e69d6b | 100 | int wxWindowBase::ms_lastControlId = -200; |
edd802c6 | 101 | #endif |
f03fc89f VZ |
102 | |
103 | IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler) | |
104 | ||
105 | // ---------------------------------------------------------------------------- | |
106 | // event table | |
107 | // ---------------------------------------------------------------------------- | |
108 | ||
109 | BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler) | |
110 | EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged) | |
111 | EVT_INIT_DIALOG(wxWindowBase::OnInitDialog) | |
a02dc3e3 | 112 | EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick) |
bd83cb56 VZ |
113 | |
114 | #if wxUSE_HELP | |
e11f4636 | 115 | EVT_HELP(wxID_ANY, wxWindowBase::OnHelp) |
bd83cb56 VZ |
116 | #endif // wxUSE_HELP |
117 | ||
f03fc89f VZ |
118 | END_EVENT_TABLE() |
119 | ||
120 | // ============================================================================ | |
121 | // implementation of the common functionality of the wxWindow class | |
122 | // ============================================================================ | |
123 | ||
124 | // ---------------------------------------------------------------------------- | |
125 | // initialization | |
126 | // ---------------------------------------------------------------------------- | |
127 | ||
128 | // the default initialization | |
72795335 | 129 | wxWindowBase::wxWindowBase() |
f03fc89f VZ |
130 | { |
131 | // no window yet, no parent nor children | |
f03fc89f | 132 | m_parent = (wxWindow *)NULL; |
e11f4636 | 133 | m_windowId = wxID_ANY; |
f03fc89f VZ |
134 | |
135 | // no constraints on the minimal window size | |
136 | m_minWidth = | |
422d0ff0 | 137 | m_maxWidth = wxDefaultCoord; |
f03fc89f | 138 | m_minHeight = |
422d0ff0 | 139 | m_maxHeight = wxDefaultCoord; |
f03fc89f | 140 | |
9f884528 RD |
141 | // invalidiated cache value |
142 | m_bestSizeCache = wxDefaultSize; | |
143 | ||
eefe6d4b VZ |
144 | // window are created enabled and visible by default |
145 | m_isShown = | |
e11f4636 | 146 | m_isEnabled = true; |
f03fc89f | 147 | |
f03fc89f VZ |
148 | // the default event handler is just this window |
149 | m_eventHandler = this; | |
150 | ||
88ac883a | 151 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
152 | // no validator |
153 | m_windowValidator = (wxValidator *) NULL; | |
88ac883a | 154 | #endif // wxUSE_VALIDATORS |
f03fc89f | 155 | |
1b69c815 VZ |
156 | // the colours/fonts are default for now, so leave m_font, |
157 | // m_backgroundColour and m_foregroundColour uninitialized and set those | |
08df3e44 VZ |
158 | m_hasBgCol = |
159 | m_hasFgCol = | |
e11f4636 | 160 | m_hasFont = false; |
f8ff87ed VS |
161 | m_inheritBgCol = |
162 | m_inheritFgCol = | |
163 | m_inheritFont = false; | |
e11f4636 | 164 | |
f03fc89f | 165 | // no style bits |
d80cd92a | 166 | m_exStyle = |
f03fc89f | 167 | m_windowStyle = 0; |
cab1a605 | 168 | |
50c53860 | 169 | m_backgroundStyle = wxBG_STYLE_SYSTEM; |
f03fc89f | 170 | |
f03fc89f VZ |
171 | #if wxUSE_CONSTRAINTS |
172 | // no constraints whatsoever | |
173 | m_constraints = (wxLayoutConstraints *) NULL; | |
174 | m_constraintsInvolvedIn = (wxWindowList *) NULL; | |
461e93f9 JS |
175 | #endif // wxUSE_CONSTRAINTS |
176 | ||
f03fc89f | 177 | m_windowSizer = (wxSizer *) NULL; |
be90c029 | 178 | m_containingSizer = (wxSizer *) NULL; |
e11f4636 | 179 | m_autoLayout = false; |
f03fc89f VZ |
180 | |
181 | #if wxUSE_DRAG_AND_DROP | |
182 | m_dropTarget = (wxDropTarget *)NULL; | |
183 | #endif // wxUSE_DRAG_AND_DROP | |
184 | ||
185 | #if wxUSE_TOOLTIPS | |
186 | m_tooltip = (wxToolTip *)NULL; | |
187 | #endif // wxUSE_TOOLTIPS | |
789295bf VZ |
188 | |
189 | #if wxUSE_CARET | |
190 | m_caret = (wxCaret *)NULL; | |
191 | #endif // wxUSE_CARET | |
a2d93e73 | 192 | |
574c939e | 193 | #if wxUSE_PALETTE |
e11f4636 | 194 | m_hasCustomPalette = false; |
574c939e KB |
195 | #endif // wxUSE_PALETTE |
196 | ||
ed5317e5 JS |
197 | #if wxUSE_ACCESSIBILITY |
198 | m_accessible = NULL; | |
199 | #endif | |
200 | ||
566d84a7 | 201 | m_virtualSize = wxDefaultSize; |
1b69c815 | 202 | |
f4fe2f20 RR |
203 | m_scrollHelper = (wxScrollHelper *) NULL; |
204 | ||
1e2a653b | 205 | m_minVirtualWidth = |
422d0ff0 | 206 | m_maxVirtualWidth = wxDefaultCoord; |
1e2a653b | 207 | m_minVirtualHeight = |
422d0ff0 | 208 | m_maxVirtualHeight = wxDefaultCoord; |
566d84a7 | 209 | |
1b69c815 | 210 | m_windowVariant = wxWINDOW_VARIANT_NORMAL; |
ff9f7a12 SC |
211 | #if wxUSE_SYSTEM_OPTIONS |
212 | if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT) ) | |
213 | { | |
214 | m_windowVariant = (wxWindowVariant) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT ) ; | |
215 | } | |
216 | #endif | |
69d90995 | 217 | |
a2d93e73 | 218 | // Whether we're using the current theme for this window (wxGTK only for now) |
e11f4636 | 219 | m_themeEnabled = false; |
1b69c815 VZ |
220 | |
221 | // VZ: this one shouldn't exist... | |
222 | m_isBeingDeleted = false; | |
f03fc89f VZ |
223 | } |
224 | ||
225 | // common part of window creation process | |
226 | bool wxWindowBase::CreateBase(wxWindowBase *parent, | |
227 | wxWindowID id, | |
74e3313b | 228 | const wxPoint& WXUNUSED(pos), |
400a9e41 | 229 | const wxSize& WXUNUSED(size), |
f03fc89f | 230 | long style, |
ac8d0c11 | 231 | const wxValidator& wxVALIDATOR_PARAM(validator), |
f03fc89f VZ |
232 | const wxString& name) |
233 | { | |
106844da VZ |
234 | #if wxUSE_STATBOX |
235 | // wxGTK doesn't allow to create controls with static box as the parent so | |
236 | // this will result in a crash when the program is ported to wxGTK so warn | |
237 | // the user about it | |
238 | ||
239 | // if you get this assert, the correct solution is to create the controls | |
240 | // as siblings of the static box | |
241 | wxASSERT_MSG( !parent || !wxDynamicCast(parent, wxStaticBox), | |
242 | _T("wxStaticBox can't be used as a window parent!") ); | |
243 | #endif // wxUSE_STATBOX | |
244 | ||
925f154d VZ |
245 | // ids are limited to 16 bits under MSW so if you care about portability, |
246 | // it's not a good idea to use ids out of this range (and negative ids are | |
77ffb593 | 247 | // reserved for wxWidgets own usage) |
925f154d VZ |
248 | wxASSERT_MSG( id == wxID_ANY || (id >= 0 && id < 32767), |
249 | _T("invalid id value") ); | |
250 | ||
f03fc89f | 251 | // generate a new id if the user doesn't care about it |
925f154d | 252 | m_windowId = id == wxID_ANY ? NewControlId() : id; |
f03fc89f | 253 | |
e96248c4 VZ |
254 | // don't use SetWindowStyleFlag() here, this function should only be called |
255 | // to change the flag after creation as it tries to reflect the changes in | |
256 | // flags by updating the window dynamically and we don't need this here | |
257 | m_windowStyle = style; | |
258 | ||
f03fc89f | 259 | SetName(name); |
f03fc89f | 260 | SetParent(parent); |
674ac8b9 VZ |
261 | |
262 | #if wxUSE_VALIDATORS | |
8d99be5f | 263 | SetValidator(validator); |
674ac8b9 | 264 | #endif // wxUSE_VALIDATORS |
f03fc89f | 265 | |
8ae6ce07 VZ |
266 | // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to |
267 | // have it too - like this it's possible to set it only in the top level | |
268 | // dialog/frame and all children will inherit it by defult | |
269 | if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) ) | |
270 | { | |
9cb98d89 | 271 | SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY); |
8ae6ce07 VZ |
272 | } |
273 | ||
e11f4636 | 274 | return true; |
f03fc89f VZ |
275 | } |
276 | ||
d63312a9 VZ |
277 | bool wxWindowBase::ToggleWindowStyle(int flag) |
278 | { | |
279 | wxASSERT_MSG( flag, _T("flags with 0 value can't be toggled") ); | |
280 | ||
281 | bool rc; | |
282 | long style = GetWindowStyleFlag(); | |
283 | if ( style & flag ) | |
284 | { | |
285 | style &= ~flag; | |
286 | rc = false; | |
287 | } | |
288 | else // currently off | |
289 | { | |
290 | style |= flag; | |
291 | rc = true; | |
292 | } | |
293 | ||
294 | SetWindowStyleFlag(style); | |
295 | ||
296 | return rc; | |
297 | } | |
298 | ||
f03fc89f VZ |
299 | // ---------------------------------------------------------------------------- |
300 | // destruction | |
301 | // ---------------------------------------------------------------------------- | |
302 | ||
303 | // common clean up | |
304 | wxWindowBase::~wxWindowBase() | |
305 | { | |
349d1942 VS |
306 | wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") ); |
307 | ||
f03fc89f VZ |
308 | // FIXME if these 2 cases result from programming errors in the user code |
309 | // we should probably assert here instead of silently fixing them | |
310 | ||
311 | // Just in case the window has been Closed, but we're then deleting | |
312 | // immediately: don't leave dangling pointers. | |
313 | wxPendingDelete.DeleteObject(this); | |
314 | ||
315 | // Just in case we've loaded a top-level window via LoadNativeDialog but | |
316 | // we weren't a dialog class | |
222ed1d6 | 317 | wxTopLevelWindows.DeleteObject((wxWindow*)this); |
a23fd0e1 | 318 | |
223d09f6 | 319 | wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") ); |
f03fc89f | 320 | |
f09df8b2 RD |
321 | // reset the top-level parent's default item if it is this widget |
322 | if ( m_parent ) | |
323 | { | |
324 | wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent((wxWindow*)this), | |
325 | wxTopLevelWindow); | |
d63312a9 | 326 | |
f09df8b2 RD |
327 | if ( tlw && tlw->GetDefaultItem() == this ) |
328 | tlw->SetDefaultItem(NULL); | |
329 | if ( tlw && tlw->GetTmpDefaultItem() == this ) | |
330 | tlw->SetTmpDefaultItem(NULL); | |
331 | } | |
332 | ||
8e35ab96 VZ |
333 | // reset the dangling pointer our parent window may keep to us |
334 | if ( m_parent ) | |
335 | { | |
8e35ab96 VZ |
336 | m_parent->RemoveChild(this); |
337 | } | |
338 | ||
789295bf | 339 | #if wxUSE_CARET |
a2b436fb | 340 | delete m_caret; |
789295bf VZ |
341 | #endif // wxUSE_CARET |
342 | ||
88ac883a | 343 | #if wxUSE_VALIDATORS |
a2b436fb | 344 | delete m_windowValidator; |
88ac883a | 345 | #endif // wxUSE_VALIDATORS |
f03fc89f | 346 | |
f03fc89f VZ |
347 | #if wxUSE_CONSTRAINTS |
348 | // Have to delete constraints/sizer FIRST otherwise sizers may try to look | |
349 | // at deleted windows as they delete themselves. | |
350 | DeleteRelatedConstraints(); | |
351 | ||
352 | if ( m_constraints ) | |
353 | { | |
354 | // This removes any dangling pointers to this window in other windows' | |
355 | // constraintsInvolvedIn lists. | |
356 | UnsetConstraints(m_constraints); | |
357 | delete m_constraints; | |
358 | m_constraints = NULL; | |
359 | } | |
461e93f9 JS |
360 | #endif // wxUSE_CONSTRAINTS |
361 | ||
be90c029 | 362 | if ( m_containingSizer ) |
12a3f227 | 363 | m_containingSizer->Detach( (wxWindow*)this ); |
be90c029 | 364 | |
a2b436fb | 365 | delete m_windowSizer; |
f03fc89f | 366 | |
f03fc89f | 367 | #if wxUSE_DRAG_AND_DROP |
a2b436fb | 368 | delete m_dropTarget; |
f03fc89f VZ |
369 | #endif // wxUSE_DRAG_AND_DROP |
370 | ||
371 | #if wxUSE_TOOLTIPS | |
a2b436fb | 372 | delete m_tooltip; |
f03fc89f | 373 | #endif // wxUSE_TOOLTIPS |
b0ee47ff | 374 | |
ed5317e5 | 375 | #if wxUSE_ACCESSIBILITY |
a2b436fb | 376 | delete m_accessible; |
ed5317e5 | 377 | #endif |
f03fc89f VZ |
378 | } |
379 | ||
602a2e02 VZ |
380 | void wxWindowBase::SendDestroyEvent() |
381 | { | |
382 | wxWindowDestroyEvent event; | |
383 | event.SetEventObject(this); | |
384 | event.SetId(GetId()); | |
385 | GetEventHandler()->ProcessEvent(event); | |
386 | } | |
387 | ||
f03fc89f VZ |
388 | bool wxWindowBase::Destroy() |
389 | { | |
390 | delete this; | |
391 | ||
e11f4636 | 392 | return true; |
f03fc89f VZ |
393 | } |
394 | ||
395 | bool wxWindowBase::Close(bool force) | |
396 | { | |
397 | wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); | |
398 | event.SetEventObject(this); | |
f03fc89f VZ |
399 | event.SetCanVeto(!force); |
400 | ||
e11f4636 | 401 | // return false if window wasn't closed because the application vetoed the |
f03fc89f VZ |
402 | // close event |
403 | return GetEventHandler()->ProcessEvent(event) && !event.GetVeto(); | |
404 | } | |
405 | ||
406 | bool wxWindowBase::DestroyChildren() | |
407 | { | |
222ed1d6 | 408 | wxWindowList::compatibility_iterator node; |
a23fd0e1 | 409 | for ( ;; ) |
f03fc89f | 410 | { |
a23fd0e1 VZ |
411 | // we iterate until the list becomes empty |
412 | node = GetChildren().GetFirst(); | |
413 | if ( !node ) | |
414 | break; | |
415 | ||
f03fc89f | 416 | wxWindow *child = node->GetData(); |
a23fd0e1 | 417 | |
f303564d VZ |
418 | // note that we really want to call delete and not ->Destroy() here |
419 | // because we want to delete the child immediately, before we are | |
420 | // deleted, and delayed deletion would result in problems as our (top | |
421 | // level) child could outlive its parent | |
422 | delete child; | |
a23fd0e1 VZ |
423 | |
424 | wxASSERT_MSG( !GetChildren().Find(child), | |
223d09f6 | 425 | wxT("child didn't remove itself using RemoveChild()") ); |
f03fc89f VZ |
426 | } |
427 | ||
e11f4636 | 428 | return true; |
f03fc89f VZ |
429 | } |
430 | ||
431 | // ---------------------------------------------------------------------------- | |
f68586e5 | 432 | // size/position related methods |
f03fc89f VZ |
433 | // ---------------------------------------------------------------------------- |
434 | ||
435 | // centre the window with respect to its parent in either (or both) directions | |
1f464296 | 436 | void wxWindowBase::DoCentre(int dir) |
f03fc89f | 437 | { |
1f464296 VZ |
438 | wxCHECK_RET( !(dir & wxCENTRE_ON_SCREEN) && GetParent(), |
439 | _T("this method only implements centering child windows") ); | |
ef397583 | 440 | |
1f464296 | 441 | SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir)); |
7631a292 RD |
442 | } |
443 | ||
f03fc89f VZ |
444 | // fits the window around the children |
445 | void wxWindowBase::Fit() | |
446 | { | |
74205969 | 447 | if ( !GetChildren().empty() ) |
f68586e5 | 448 | { |
1736f021 | 449 | SetSize(GetBestSize()); |
f68586e5 VZ |
450 | } |
451 | //else: do nothing if we have no children | |
452 | } | |
f03fc89f | 453 | |
2b5f62a0 VZ |
454 | // fits virtual size (ie. scrolled area etc.) around children |
455 | void wxWindowBase::FitInside() | |
456 | { | |
457 | if ( GetChildren().GetCount() > 0 ) | |
458 | { | |
459 | SetVirtualSize( GetBestVirtualSize() ); | |
460 | } | |
461 | } | |
462 | ||
7d59475e JS |
463 | // On Mac, scrollbars are explicitly children. |
464 | #ifdef __WXMAC__ | |
465 | static bool wxHasRealChildren(const wxWindowBase* win) | |
466 | { | |
467 | int realChildCount = 0; | |
cab1a605 | 468 | |
7d59475e JS |
469 | for ( wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst(); |
470 | node; | |
471 | node = node->GetNext() ) | |
472 | { | |
473 | wxWindow *win = node->GetData(); | |
474 | if ( !win->IsTopLevel() && win->IsShown() && !win->IsKindOf(CLASSINFO(wxScrollBar))) | |
475 | realChildCount ++; | |
476 | } | |
477 | return (realChildCount > 0); | |
478 | } | |
479 | #endif | |
ba889513 | 480 | |
992b2ec4 VS |
481 | void wxWindowBase::InvalidateBestSize() |
482 | { | |
483 | m_bestSizeCache = wxDefaultSize; | |
484 | ||
485 | // parent's best size calculation may depend on its children's | |
5b7df27e WS |
486 | // as long as child window we are in is not top level window itself |
487 | // (because the TLW size is never resized automatically) | |
488 | // so let's invalidate it as well to be safe: | |
5ff84587 | 489 | if (m_parent && !IsTopLevel()) |
992b2ec4 VS |
490 | m_parent->InvalidateBestSize(); |
491 | } | |
7d59475e | 492 | |
f68586e5 VZ |
493 | // return the size best suited for the current window |
494 | wxSize wxWindowBase::DoGetBestSize() const | |
495 | { | |
08a19f64 | 496 | wxSize best; |
2997ca30 | 497 | |
ec5bb70d VZ |
498 | if ( m_windowSizer ) |
499 | { | |
ee146bca | 500 | best = GetWindowSizeForVirtualSize(m_windowSizer->GetMinSize()); |
ec5bb70d VZ |
501 | } |
502 | #if wxUSE_CONSTRAINTS | |
503 | else if ( m_constraints ) | |
504 | { | |
505 | wxConstCast(this, wxWindowBase)->SatisfyConstraints(); | |
506 | ||
507 | // our minimal acceptable size is such that all our windows fit inside | |
508 | int maxX = 0, | |
509 | maxY = 0; | |
510 | ||
222ed1d6 | 511 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
ec5bb70d VZ |
512 | node; |
513 | node = node->GetNext() ) | |
514 | { | |
515 | wxLayoutConstraints *c = node->GetData()->GetConstraints(); | |
516 | if ( !c ) | |
517 | { | |
518 | // it's not normal that we have an unconstrained child, but | |
519 | // what can we do about it? | |
520 | continue; | |
521 | } | |
522 | ||
523 | int x = c->right.GetValue(), | |
524 | y = c->bottom.GetValue(); | |
525 | ||
526 | if ( x > maxX ) | |
527 | maxX = x; | |
528 | ||
529 | if ( y > maxY ) | |
530 | maxY = y; | |
531 | ||
532 | // TODO: we must calculate the overlaps somehow, otherwise we | |
533 | // will never return a size bigger than the current one :-( | |
534 | } | |
535 | ||
08a19f64 | 536 | best = wxSize(maxX, maxY); |
ec5bb70d VZ |
537 | } |
538 | #endif // wxUSE_CONSTRAINTS | |
7d59475e JS |
539 | else if ( !GetChildren().empty() |
540 | #ifdef __WXMAC__ | |
541 | && wxHasRealChildren(this) | |
542 | #endif | |
543 | ) | |
f03fc89f | 544 | { |
54af2461 VZ |
545 | // our minimal acceptable size is such that all our visible child |
546 | // windows fit inside | |
f68586e5 VZ |
547 | int maxX = 0, |
548 | maxY = 0; | |
549 | ||
222ed1d6 | 550 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
f68586e5 VZ |
551 | node; |
552 | node = node->GetNext() ) | |
42e69d6b | 553 | { |
f68586e5 | 554 | wxWindow *win = node->GetData(); |
54af2461 VZ |
555 | if ( win->IsTopLevel() |
556 | || !win->IsShown() | |
1e6feb95 | 557 | #if wxUSE_STATUSBAR |
54af2461 | 558 | || wxDynamicCast(win, wxStatusBar) |
1e6feb95 VZ |
559 | #endif // wxUSE_STATUSBAR |
560 | ) | |
f68586e5 VZ |
561 | { |
562 | // dialogs and frames lie in different top level windows - | |
7d9fd004 VZ |
563 | // don't deal with them here; as for the status bars, they |
564 | // don't lie in the client area at all | |
f68586e5 VZ |
565 | continue; |
566 | } | |
567 | ||
568 | int wx, wy, ww, wh; | |
569 | win->GetPosition(&wx, &wy); | |
3f5513f5 VZ |
570 | |
571 | // if the window hadn't been positioned yet, assume that it is in | |
572 | // the origin | |
422d0ff0 | 573 | if ( wx == wxDefaultCoord ) |
3f5513f5 | 574 | wx = 0; |
422d0ff0 | 575 | if ( wy == wxDefaultCoord ) |
3f5513f5 VZ |
576 | wy = 0; |
577 | ||
f68586e5 VZ |
578 | win->GetSize(&ww, &wh); |
579 | if ( wx + ww > maxX ) | |
580 | maxX = wx + ww; | |
581 | if ( wy + wh > maxY ) | |
582 | maxY = wy + wh; | |
42e69d6b VZ |
583 | } |
584 | ||
08a19f64 | 585 | best = wxSize(maxX, maxY); |
f68586e5 | 586 | } |
997c7280 | 587 | else // ! has children |
f68586e5 | 588 | { |
c0bb586f VZ |
589 | // for a generic window there is no natural best size so, if the |
590 | // minimal size is not set, use the current size but take care to | |
591 | // remember it as minimal size for the next time because our best size | |
592 | // should be constant: otherwise we could get into a situation when the | |
593 | // window is initially at some size, then expanded to a larger size and | |
594 | // then, when the containing window is shrunk back (because our initial | |
595 | // best size had been used for computing the parent min size), we can't | |
596 | // be shrunk back any more because our best size is now bigger | |
9240613a VZ |
597 | wxSize size = GetMinSize(); |
598 | if ( !size.IsFullySpecified() ) | |
599 | { | |
600 | size.SetDefaults(GetSize()); | |
601 | wxConstCast(this, wxWindowBase)->SetMinSize(size); | |
602 | } | |
c0bb586f VZ |
603 | |
604 | // return as-is, unadjusted by the client size difference. | |
9240613a | 605 | return size; |
f03fc89f | 606 | } |
08a19f64 RD |
607 | |
608 | // Add any difference between size and client size | |
609 | wxSize diff = GetSize() - GetClientSize(); | |
610 | best.x += wxMax(0, diff.x); | |
611 | best.y += wxMax(0, diff.y); | |
612 | ||
613 | return best; | |
f03fc89f VZ |
614 | } |
615 | ||
333d7052 VZ |
616 | // helper of GetWindowBorderSize(): as many ports don't implement support for |
617 | // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded | |
618 | // fallbacks in this case | |
ce6fbc83 | 619 | static int wxGetMetricOrDefault(wxSystemMetric what) |
333d7052 VZ |
620 | { |
621 | int rc = wxSystemSettings::GetMetric(what); | |
622 | if ( rc == -1 ) | |
623 | { | |
624 | switch ( what ) | |
625 | { | |
626 | case wxSYS_BORDER_X: | |
627 | case wxSYS_BORDER_Y: | |
628 | // 2D border is by default 1 pixel wide | |
629 | rc = 1; | |
630 | break; | |
631 | ||
632 | case wxSYS_EDGE_X: | |
633 | case wxSYS_EDGE_Y: | |
634 | // 3D borders are by default 2 pixels | |
635 | rc = 2; | |
636 | break; | |
637 | ||
638 | default: | |
639 | wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") ); | |
640 | rc = 0; | |
641 | } | |
642 | } | |
643 | ||
644 | return rc; | |
645 | } | |
646 | ||
647 | wxSize wxWindowBase::GetWindowBorderSize() const | |
648 | { | |
649 | wxSize size; | |
650 | ||
651 | switch ( GetBorder() ) | |
652 | { | |
653 | case wxBORDER_NONE: | |
654 | // nothing to do, size is already (0, 0) | |
655 | break; | |
656 | ||
657 | case wxBORDER_SIMPLE: | |
658 | case wxBORDER_STATIC: | |
659 | size.x = wxGetMetricOrDefault(wxSYS_BORDER_X); | |
660 | size.y = wxGetMetricOrDefault(wxSYS_BORDER_Y); | |
661 | break; | |
662 | ||
663 | case wxBORDER_SUNKEN: | |
664 | case wxBORDER_RAISED: | |
665 | size.x = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X), | |
666 | wxGetMetricOrDefault(wxSYS_BORDER_X)); | |
667 | size.y = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y), | |
668 | wxGetMetricOrDefault(wxSYS_BORDER_Y)); | |
669 | break; | |
670 | ||
671 | case wxBORDER_DOUBLE: | |
672 | size.x = wxGetMetricOrDefault(wxSYS_EDGE_X) + | |
673 | wxGetMetricOrDefault(wxSYS_BORDER_X); | |
674 | size.y = wxGetMetricOrDefault(wxSYS_EDGE_Y) + | |
675 | wxGetMetricOrDefault(wxSYS_BORDER_Y); | |
676 | break; | |
677 | ||
678 | default: | |
679 | wxFAIL_MSG(_T("Unknown border style.")); | |
680 | break; | |
681 | } | |
682 | ||
683 | // we have borders on both sides | |
684 | return size*2; | |
685 | } | |
9f884528 | 686 | |
170acdc9 | 687 | wxSize wxWindowBase::GetEffectiveMinSize() const |
400a9e41 | 688 | { |
9f884528 RD |
689 | // merge the best size with the min size, giving priority to the min size |
690 | wxSize min = GetMinSize(); | |
691 | if (min.x == wxDefaultCoord || min.y == wxDefaultCoord) | |
400a9e41 | 692 | { |
9f884528 RD |
693 | wxSize best = GetBestSize(); |
694 | if (min.x == wxDefaultCoord) min.x = best.x; | |
695 | if (min.y == wxDefaultCoord) min.y = best.y; | |
17c48da8 | 696 | } |
9f884528 RD |
697 | return min; |
698 | } | |
17c48da8 | 699 | |
42cfa184 | 700 | |
170acdc9 | 701 | void wxWindowBase::SetInitialSize(const wxSize& size) |
9f884528 RD |
702 | { |
703 | // Set the min size to the size passed in. This will usually either be | |
704 | // wxDefaultSize or the size passed to this window's ctor/Create function. | |
705 | SetMinSize(size); | |
706 | ||
707 | // Merge the size with the best size if needed | |
170acdc9 | 708 | wxSize best = GetEffectiveMinSize(); |
cab1a605 | 709 | |
9f884528 RD |
710 | // If the current size doesn't match then change it |
711 | if (GetSize() != best) | |
712 | SetSize(best); | |
400a9e41 VZ |
713 | } |
714 | ||
9f884528 | 715 | |
1e6feb95 VZ |
716 | // by default the origin is not shifted |
717 | wxPoint wxWindowBase::GetClientAreaOrigin() const | |
718 | { | |
c47addef | 719 | return wxPoint(0,0); |
1e6feb95 VZ |
720 | } |
721 | ||
69d90995 SC |
722 | void wxWindowBase::SetWindowVariant( wxWindowVariant variant ) |
723 | { | |
1b69c815 VZ |
724 | if ( m_windowVariant != variant ) |
725 | { | |
726 | m_windowVariant = variant; | |
69d90995 | 727 | |
1b69c815 VZ |
728 | DoSetWindowVariant(variant); |
729 | } | |
69d90995 SC |
730 | } |
731 | ||
732 | void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant ) | |
733 | { | |
1b69c815 VZ |
734 | // adjust the font height to correspond to our new variant (notice that |
735 | // we're only called if something really changed) | |
736 | wxFont font = GetFont(); | |
737 | int size = font.GetPointSize(); | |
69d90995 SC |
738 | switch ( variant ) |
739 | { | |
1b69c815 VZ |
740 | case wxWINDOW_VARIANT_NORMAL: |
741 | break; | |
742 | ||
743 | case wxWINDOW_VARIANT_SMALL: | |
744 | size *= 3; | |
745 | size /= 4; | |
746 | break; | |
747 | ||
748 | case wxWINDOW_VARIANT_MINI: | |
749 | size *= 2; | |
750 | size /= 3; | |
751 | break; | |
752 | ||
753 | case wxWINDOW_VARIANT_LARGE: | |
754 | size *= 5; | |
755 | size /= 4; | |
756 | break; | |
757 | ||
69d90995 SC |
758 | default: |
759 | wxFAIL_MSG(_T("unexpected window variant")); | |
1b69c815 | 760 | break; |
69d90995 | 761 | } |
1b69c815 VZ |
762 | |
763 | font.SetPointSize(size); | |
764 | SetFont(font); | |
69d90995 SC |
765 | } |
766 | ||
b21f4960 RR |
767 | void wxWindowBase::DoSetSizeHints( int minW, int minH, |
768 | int maxW, int maxH, | |
f36978ba | 769 | int WXUNUSED(incW), int WXUNUSED(incH) ) |
b21f4960 RR |
770 | { |
771 | wxCHECK_RET( (minW == wxDefaultCoord || maxW == wxDefaultCoord || minW <= maxW) && | |
772 | (minH == wxDefaultCoord || maxH == wxDefaultCoord || minH <= maxH), | |
773 | _T("min width/height must be less than max width/height!") ); | |
774 | ||
775 | m_minWidth = minW; | |
776 | m_maxWidth = maxW; | |
777 | m_minHeight = minH; | |
778 | m_maxHeight = maxH; | |
779 | } | |
780 | ||
781 | ||
566d84a7 RL |
782 | void wxWindowBase::SetVirtualSizeHints( int minW, int minH, |
783 | int maxW, int maxH ) | |
784 | { | |
785 | m_minVirtualWidth = minW; | |
786 | m_maxVirtualWidth = maxW; | |
787 | m_minVirtualHeight = minH; | |
788 | m_maxVirtualHeight = maxH; | |
566d84a7 RL |
789 | } |
790 | ||
791 | void wxWindowBase::DoSetVirtualSize( int x, int y ) | |
792 | { | |
422d0ff0 | 793 | if ( m_minVirtualWidth != wxDefaultCoord && m_minVirtualWidth > x ) |
1e2a653b | 794 | x = m_minVirtualWidth; |
422d0ff0 | 795 | if ( m_maxVirtualWidth != wxDefaultCoord && m_maxVirtualWidth < x ) |
1e2a653b | 796 | x = m_maxVirtualWidth; |
422d0ff0 | 797 | if ( m_minVirtualHeight != wxDefaultCoord && m_minVirtualHeight > y ) |
1e2a653b | 798 | y = m_minVirtualHeight; |
422d0ff0 | 799 | if ( m_maxVirtualHeight != wxDefaultCoord && m_maxVirtualHeight < y ) |
1e2a653b VZ |
800 | y = m_maxVirtualHeight; |
801 | ||
802 | m_virtualSize = wxSize(x, y); | |
566d84a7 RL |
803 | } |
804 | ||
805 | wxSize wxWindowBase::DoGetVirtualSize() const | |
806 | { | |
143e2719 VZ |
807 | // we should use the entire client area so if it is greater than our |
808 | // virtual size, expand it to fit (otherwise if the window is big enough we | |
809 | // wouldn't be using parts of it) | |
c20ab85b | 810 | wxSize size = GetClientSize(); |
143e2719 | 811 | if ( m_virtualSize.x > size.x ) |
c20ab85b VZ |
812 | size.x = m_virtualSize.x; |
813 | ||
143e2719 | 814 | if ( m_virtualSize.y >= size.y ) |
c20ab85b VZ |
815 | size.y = m_virtualSize.y; |
816 | ||
817 | return size; | |
566d84a7 RL |
818 | } |
819 | ||
3c81c9aa VZ |
820 | void wxWindowBase::DoGetScreenPosition(int *x, int *y) const |
821 | { | |
822 | // screen position is the same as (0, 0) in client coords for non TLWs (and | |
823 | // TLWs override this method) | |
824 | if ( x ) | |
825 | *x = 0; | |
826 | if ( y ) | |
827 | *y = 0; | |
828 | ||
aa738eb8 | 829 | ClientToScreen(x, y); |
3c81c9aa VZ |
830 | } |
831 | ||
f03fc89f VZ |
832 | // ---------------------------------------------------------------------------- |
833 | // show/hide/enable/disable the window | |
834 | // ---------------------------------------------------------------------------- | |
835 | ||
836 | bool wxWindowBase::Show(bool show) | |
837 | { | |
838 | if ( show != m_isShown ) | |
839 | { | |
840 | m_isShown = show; | |
841 | ||
e11f4636 | 842 | return true; |
f03fc89f VZ |
843 | } |
844 | else | |
845 | { | |
e11f4636 | 846 | return false; |
f03fc89f VZ |
847 | } |
848 | } | |
849 | ||
850 | bool wxWindowBase::Enable(bool enable) | |
851 | { | |
852 | if ( enable != m_isEnabled ) | |
853 | { | |
854 | m_isEnabled = enable; | |
855 | ||
e11f4636 | 856 | return true; |
f03fc89f VZ |
857 | } |
858 | else | |
859 | { | |
e11f4636 | 860 | return false; |
f03fc89f VZ |
861 | } |
862 | } | |
9c72cf76 | 863 | |
865a74c7 | 864 | bool wxWindowBase::IsShownOnScreen() const |
9c72cf76 | 865 | { |
865a74c7 VS |
866 | return IsShown() && |
867 | (GetParent() == NULL || GetParent()->IsShownOnScreen()); | |
9c72cf76 VS |
868 | } |
869 | ||
34636400 VZ |
870 | // ---------------------------------------------------------------------------- |
871 | // RTTI | |
872 | // ---------------------------------------------------------------------------- | |
873 | ||
874 | bool wxWindowBase::IsTopLevel() const | |
875 | { | |
e11f4636 | 876 | return false; |
34636400 | 877 | } |
f03fc89f VZ |
878 | |
879 | // ---------------------------------------------------------------------------- | |
880 | // reparenting the window | |
881 | // ---------------------------------------------------------------------------- | |
882 | ||
883 | void wxWindowBase::AddChild(wxWindowBase *child) | |
884 | { | |
223d09f6 | 885 | wxCHECK_RET( child, wxT("can't add a NULL child") ); |
f03fc89f | 886 | |
f6bcfd97 BP |
887 | // this should never happen and it will lead to a crash later if it does |
888 | // because RemoveChild() will remove only one node from the children list | |
889 | // and the other(s) one(s) will be left with dangling pointers in them | |
222ed1d6 | 890 | wxASSERT_MSG( !GetChildren().Find((wxWindow*)child), _T("AddChild() called twice") ); |
f6bcfd97 | 891 | |
222ed1d6 | 892 | GetChildren().Append((wxWindow*)child); |
f03fc89f VZ |
893 | child->SetParent(this); |
894 | } | |
895 | ||
896 | void wxWindowBase::RemoveChild(wxWindowBase *child) | |
897 | { | |
223d09f6 | 898 | wxCHECK_RET( child, wxT("can't remove a NULL child") ); |
f03fc89f | 899 | |
222ed1d6 MB |
900 | GetChildren().DeleteObject((wxWindow *)child); |
901 | child->SetParent(NULL); | |
f03fc89f | 902 | } |
439b3bf1 | 903 | |
f03fc89f VZ |
904 | bool wxWindowBase::Reparent(wxWindowBase *newParent) |
905 | { | |
906 | wxWindow *oldParent = GetParent(); | |
907 | if ( newParent == oldParent ) | |
908 | { | |
909 | // nothing done | |
e11f4636 | 910 | return false; |
f03fc89f VZ |
911 | } |
912 | ||
913 | // unlink this window from the existing parent. | |
914 | if ( oldParent ) | |
915 | { | |
916 | oldParent->RemoveChild(this); | |
917 | } | |
918 | else | |
919 | { | |
222ed1d6 | 920 | wxTopLevelWindows.DeleteObject((wxWindow *)this); |
f03fc89f VZ |
921 | } |
922 | ||
923 | // add it to the new one | |
924 | if ( newParent ) | |
925 | { | |
926 | newParent->AddChild(this); | |
927 | } | |
928 | else | |
929 | { | |
222ed1d6 | 930 | wxTopLevelWindows.Append((wxWindow *)this); |
f03fc89f VZ |
931 | } |
932 | ||
e11f4636 | 933 | return true; |
f03fc89f VZ |
934 | } |
935 | ||
936 | // ---------------------------------------------------------------------------- | |
937 | // event handler stuff | |
938 | // ---------------------------------------------------------------------------- | |
939 | ||
940 | void wxWindowBase::PushEventHandler(wxEvtHandler *handler) | |
941 | { | |
3a074ba8 VZ |
942 | wxEvtHandler *handlerOld = GetEventHandler(); |
943 | ||
944 | handler->SetNextHandler(handlerOld); | |
945 | ||
946 | if ( handlerOld ) | |
947 | GetEventHandler()->SetPreviousHandler(handler); | |
948 | ||
f03fc89f VZ |
949 | SetEventHandler(handler); |
950 | } | |
951 | ||
952 | wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler) | |
953 | { | |
954 | wxEvtHandler *handlerA = GetEventHandler(); | |
955 | if ( handlerA ) | |
956 | { | |
957 | wxEvtHandler *handlerB = handlerA->GetNextHandler(); | |
958 | handlerA->SetNextHandler((wxEvtHandler *)NULL); | |
3a074ba8 VZ |
959 | |
960 | if ( handlerB ) | |
961 | handlerB->SetPreviousHandler((wxEvtHandler *)NULL); | |
f03fc89f | 962 | SetEventHandler(handlerB); |
3a074ba8 | 963 | |
f03fc89f VZ |
964 | if ( deleteHandler ) |
965 | { | |
966 | delete handlerA; | |
967 | handlerA = (wxEvtHandler *)NULL; | |
968 | } | |
969 | } | |
970 | ||
971 | return handlerA; | |
972 | } | |
973 | ||
2e36d5cf VZ |
974 | bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler) |
975 | { | |
e11f4636 | 976 | wxCHECK_MSG( handler, false, _T("RemoveEventHandler(NULL) called") ); |
2e36d5cf VZ |
977 | |
978 | wxEvtHandler *handlerPrev = NULL, | |
979 | *handlerCur = GetEventHandler(); | |
980 | while ( handlerCur ) | |
981 | { | |
982 | wxEvtHandler *handlerNext = handlerCur->GetNextHandler(); | |
983 | ||
984 | if ( handlerCur == handler ) | |
985 | { | |
986 | if ( handlerPrev ) | |
987 | { | |
988 | handlerPrev->SetNextHandler(handlerNext); | |
989 | } | |
990 | else | |
991 | { | |
992 | SetEventHandler(handlerNext); | |
993 | } | |
994 | ||
7a9c8d74 JS |
995 | if ( handlerNext ) |
996 | { | |
997 | handlerNext->SetPreviousHandler ( handlerPrev ); | |
998 | } | |
489bbac9 | 999 | |
2e36d5cf | 1000 | handler->SetNextHandler(NULL); |
489bbac9 | 1001 | handler->SetPreviousHandler(NULL); |
2e36d5cf | 1002 | |
e11f4636 | 1003 | return true; |
2e36d5cf VZ |
1004 | } |
1005 | ||
1006 | handlerPrev = handlerCur; | |
1007 | handlerCur = handlerNext; | |
1008 | } | |
1009 | ||
1010 | wxFAIL_MSG( _T("where has the event handler gone?") ); | |
1011 | ||
e11f4636 | 1012 | return false; |
2e36d5cf VZ |
1013 | } |
1014 | ||
f03fc89f | 1015 | // ---------------------------------------------------------------------------- |
1b69c815 | 1016 | // colours, fonts &c |
f03fc89f VZ |
1017 | // ---------------------------------------------------------------------------- |
1018 | ||
b8e7b673 VZ |
1019 | void wxWindowBase::InheritAttributes() |
1020 | { | |
8afef133 | 1021 | const wxWindowBase * const parent = GetParent(); |
b8e7b673 VZ |
1022 | if ( !parent ) |
1023 | return; | |
1024 | ||
1025 | // we only inherit attributes which had been explicitly set for the parent | |
1026 | // which ensures that this only happens if the user really wants it and | |
1027 | // not by default which wouldn't make any sense in modern GUIs where the | |
1028 | // controls don't all use the same fonts (nor colours) | |
f8ff87ed | 1029 | if ( parent->m_inheritFont && !m_hasFont ) |
b8e7b673 VZ |
1030 | SetFont(parent->GetFont()); |
1031 | ||
1032 | // in addition, there is a possibility to explicitly forbid inheriting | |
1033 | // colours at each class level by overriding ShouldInheritColours() | |
1034 | if ( ShouldInheritColours() ) | |
1035 | { | |
f8ff87ed | 1036 | if ( parent->m_inheritFgCol && !m_hasFgCol ) |
b8e7b673 VZ |
1037 | SetForegroundColour(parent->GetForegroundColour()); |
1038 | ||
eb96212b VZ |
1039 | // inheriting (solid) background colour is wrong as it totally breaks |
1040 | // any kind of themed backgrounds | |
1041 | // | |
1042 | // instead, the controls should use the same background as their parent | |
1043 | // (ideally by not drawing it at all) | |
1044 | #if 0 | |
f8ff87ed | 1045 | if ( parent->m_inheritBgCol && !m_hasBgCol ) |
b8e7b673 | 1046 | SetBackgroundColour(parent->GetBackgroundColour()); |
eb96212b | 1047 | #endif // 0 |
b8e7b673 VZ |
1048 | } |
1049 | } | |
1050 | ||
1b69c815 VZ |
1051 | /* static */ wxVisualAttributes |
1052 | wxWindowBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) | |
1053 | { | |
1054 | // it is important to return valid values for all attributes from here, | |
1055 | // GetXXX() below rely on this | |
1056 | wxVisualAttributes attrs; | |
1057 | attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
1058 | attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); | |
1b69c815 | 1059 | |
0477a857 JS |
1060 | // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of |
1061 | // the usual background colour than wxSYS_COLOUR_BTNFACE. | |
1062 | // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background | |
1063 | // colour on other platforms. | |
1064 | ||
1065 | #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__)) | |
1066 | attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); | |
1067 | #else | |
1068 | attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); | |
1069 | #endif | |
1b69c815 VZ |
1070 | return attrs; |
1071 | } | |
1072 | ||
1073 | wxColour wxWindowBase::GetBackgroundColour() const | |
1074 | { | |
1075 | if ( !m_backgroundColour.Ok() ) | |
1076 | { | |
1077 | wxASSERT_MSG( !m_hasBgCol, _T("we have invalid explicit bg colour?") ); | |
1078 | ||
1079 | // get our default background colour | |
1080 | wxColour colBg = GetDefaultAttributes().colBg; | |
1081 | ||
1082 | // we must return some valid colour to avoid redoing this every time | |
1083 | // and also to avoid surprizing the applications written for older | |
77ffb593 | 1084 | // wxWidgets versions where GetBackgroundColour() always returned |
1b69c815 VZ |
1085 | // something -- so give them something even if it doesn't make sense |
1086 | // for this window (e.g. it has a themed background) | |
1087 | if ( !colBg.Ok() ) | |
1088 | colBg = GetClassDefaultAttributes().colBg; | |
1089 | ||
f604c658 | 1090 | return colBg; |
1b69c815 | 1091 | } |
f604c658 VS |
1092 | else |
1093 | return m_backgroundColour; | |
1b69c815 VZ |
1094 | } |
1095 | ||
1096 | wxColour wxWindowBase::GetForegroundColour() const | |
1097 | { | |
1098 | // logic is the same as above | |
1099 | if ( !m_hasFgCol && !m_foregroundColour.Ok() ) | |
1100 | { | |
1101 | wxASSERT_MSG( !m_hasFgCol, _T("we have invalid explicit fg colour?") ); | |
1102 | ||
1103 | wxColour colFg = GetDefaultAttributes().colFg; | |
1104 | ||
1105 | if ( !colFg.Ok() ) | |
1106 | colFg = GetClassDefaultAttributes().colFg; | |
1107 | ||
f604c658 | 1108 | return colFg; |
1b69c815 | 1109 | } |
f604c658 VS |
1110 | else |
1111 | return m_foregroundColour; | |
1b69c815 VZ |
1112 | } |
1113 | ||
f03fc89f VZ |
1114 | bool wxWindowBase::SetBackgroundColour( const wxColour &colour ) |
1115 | { | |
cab1a605 | 1116 | if ( colour == m_backgroundColour ) |
e11f4636 | 1117 | return false; |
f03fc89f | 1118 | |
44dfb5ce | 1119 | m_hasBgCol = colour.Ok(); |
17bcd9a6 VZ |
1120 | if ( m_backgroundStyle != wxBG_STYLE_CUSTOM ) |
1121 | m_backgroundStyle = m_hasBgCol ? wxBG_STYLE_COLOUR : wxBG_STYLE_SYSTEM; | |
1122 | ||
f8ff87ed | 1123 | m_inheritBgCol = m_hasBgCol; |
f03fc89f | 1124 | m_backgroundColour = colour; |
44dfb5ce | 1125 | SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.Ok() ); |
e11f4636 | 1126 | return true; |
f03fc89f VZ |
1127 | } |
1128 | ||
1129 | bool wxWindowBase::SetForegroundColour( const wxColour &colour ) | |
1130 | { | |
44dfb5ce | 1131 | if (colour == m_foregroundColour ) |
e11f4636 | 1132 | return false; |
f03fc89f | 1133 | |
44dfb5ce | 1134 | m_hasFgCol = colour.Ok(); |
f8ff87ed | 1135 | m_inheritFgCol = m_hasFgCol; |
f03fc89f | 1136 | m_foregroundColour = colour; |
44dfb5ce | 1137 | SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() ); |
e11f4636 | 1138 | return true; |
f03fc89f VZ |
1139 | } |
1140 | ||
1141 | bool wxWindowBase::SetCursor(const wxCursor& cursor) | |
1142 | { | |
8a9c2246 VZ |
1143 | // setting an invalid cursor is ok, it means that we don't have any special |
1144 | // cursor | |
a3ab1c18 | 1145 | if ( m_cursor.IsSameAs(cursor) ) |
f03fc89f VZ |
1146 | { |
1147 | // no change | |
e11f4636 | 1148 | return false; |
f03fc89f VZ |
1149 | } |
1150 | ||
8a9c2246 | 1151 | m_cursor = cursor; |
f03fc89f | 1152 | |
e11f4636 | 1153 | return true; |
f03fc89f VZ |
1154 | } |
1155 | ||
f604c658 | 1156 | wxFont wxWindowBase::GetFont() const |
1b69c815 VZ |
1157 | { |
1158 | // logic is the same as in GetBackgroundColour() | |
1159 | if ( !m_font.Ok() ) | |
1160 | { | |
1161 | wxASSERT_MSG( !m_hasFont, _T("we have invalid explicit font?") ); | |
1162 | ||
1163 | wxFont font = GetDefaultAttributes().font; | |
1164 | if ( !font.Ok() ) | |
1165 | font = GetClassDefaultAttributes().font; | |
1166 | ||
f604c658 | 1167 | return font; |
1b69c815 | 1168 | } |
f604c658 VS |
1169 | else |
1170 | return m_font; | |
1b69c815 VZ |
1171 | } |
1172 | ||
f03fc89f VZ |
1173 | bool wxWindowBase::SetFont(const wxFont& font) |
1174 | { | |
1b69c815 | 1175 | if ( font == m_font ) |
f03fc89f VZ |
1176 | { |
1177 | // no change | |
e11f4636 | 1178 | return false; |
f03fc89f VZ |
1179 | } |
1180 | ||
1b69c815 | 1181 | m_font = font; |
72bbf76a | 1182 | m_hasFont = font.Ok(); |
f8ff87ed | 1183 | m_inheritFont = m_hasFont; |
23895080 | 1184 | |
583d7e55 VS |
1185 | InvalidateBestSize(); |
1186 | ||
e11f4636 | 1187 | return true; |
f03fc89f VZ |
1188 | } |
1189 | ||
b95edd47 VZ |
1190 | #if wxUSE_PALETTE |
1191 | ||
1192 | void wxWindowBase::SetPalette(const wxPalette& pal) | |
1193 | { | |
e11f4636 | 1194 | m_hasCustomPalette = true; |
b95edd47 VZ |
1195 | m_palette = pal; |
1196 | ||
1197 | // VZ: can anyone explain me what do we do here? | |
1198 | wxWindowDC d((wxWindow *) this); | |
1199 | d.SetPalette(pal); | |
1200 | } | |
1201 | ||
1202 | wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const | |
1203 | { | |
1204 | wxWindow *win = (wxWindow *)this; | |
1205 | while ( win && !win->HasCustomPalette() ) | |
1206 | { | |
1207 | win = win->GetParent(); | |
1208 | } | |
1209 | ||
1210 | return win; | |
1211 | } | |
1212 | ||
1213 | #endif // wxUSE_PALETTE | |
1214 | ||
789295bf VZ |
1215 | #if wxUSE_CARET |
1216 | void wxWindowBase::SetCaret(wxCaret *caret) | |
1217 | { | |
1218 | if ( m_caret ) | |
1219 | { | |
1220 | delete m_caret; | |
1221 | } | |
1222 | ||
1223 | m_caret = caret; | |
1224 | ||
1225 | if ( m_caret ) | |
1226 | { | |
1227 | wxASSERT_MSG( m_caret->GetWindow() == this, | |
223d09f6 | 1228 | wxT("caret should be created associated to this window") ); |
789295bf VZ |
1229 | } |
1230 | } | |
1231 | #endif // wxUSE_CARET | |
1232 | ||
88ac883a | 1233 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
1234 | // ---------------------------------------------------------------------------- |
1235 | // validators | |
1236 | // ---------------------------------------------------------------------------- | |
1237 | ||
1238 | void wxWindowBase::SetValidator(const wxValidator& validator) | |
1239 | { | |
1240 | if ( m_windowValidator ) | |
1241 | delete m_windowValidator; | |
1242 | ||
1243 | m_windowValidator = (wxValidator *)validator.Clone(); | |
1244 | ||
1245 | if ( m_windowValidator ) | |
1b69c815 | 1246 | m_windowValidator->SetWindow(this); |
f03fc89f | 1247 | } |
88ac883a | 1248 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
1249 | |
1250 | // ---------------------------------------------------------------------------- | |
1e6feb95 | 1251 | // update region stuff |
f03fc89f VZ |
1252 | // ---------------------------------------------------------------------------- |
1253 | ||
1e6feb95 VZ |
1254 | wxRect wxWindowBase::GetUpdateClientRect() const |
1255 | { | |
1256 | wxRegion rgnUpdate = GetUpdateRegion(); | |
1257 | rgnUpdate.Intersect(GetClientRect()); | |
1258 | wxRect rectUpdate = rgnUpdate.GetBox(); | |
1259 | wxPoint ptOrigin = GetClientAreaOrigin(); | |
1260 | rectUpdate.x -= ptOrigin.x; | |
1261 | rectUpdate.y -= ptOrigin.y; | |
1262 | ||
1263 | return rectUpdate; | |
1264 | } | |
1265 | ||
657b4fd4 | 1266 | bool wxWindowBase::DoIsExposed(int x, int y) const |
f03fc89f VZ |
1267 | { |
1268 | return m_updateRegion.Contains(x, y) != wxOutRegion; | |
1269 | } | |
1270 | ||
657b4fd4 | 1271 | bool wxWindowBase::DoIsExposed(int x, int y, int w, int h) const |
f03fc89f VZ |
1272 | { |
1273 | return m_updateRegion.Contains(x, y, w, h) != wxOutRegion; | |
1274 | } | |
1275 | ||
5da0803c VZ |
1276 | void wxWindowBase::ClearBackground() |
1277 | { | |
1278 | // wxGTK uses its own version, no need to add never used code | |
1279 | #ifndef __WXGTK__ | |
1280 | wxClientDC dc((wxWindow *)this); | |
1281 | wxBrush brush(GetBackgroundColour(), wxSOLID); | |
1282 | dc.SetBackground(brush); | |
1283 | dc.Clear(); | |
1284 | #endif // __WXGTK__ | |
1285 | } | |
1286 | ||
f03fc89f | 1287 | // ---------------------------------------------------------------------------- |
146ba0fe | 1288 | // find child window by id or name |
f03fc89f VZ |
1289 | // ---------------------------------------------------------------------------- |
1290 | ||
6b73af79 | 1291 | wxWindow *wxWindowBase::FindWindow(long id) const |
f03fc89f VZ |
1292 | { |
1293 | if ( id == m_windowId ) | |
1294 | return (wxWindow *)this; | |
1295 | ||
1296 | wxWindowBase *res = (wxWindow *)NULL; | |
222ed1d6 | 1297 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1298 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) |
1299 | { | |
1300 | wxWindowBase *child = node->GetData(); | |
1301 | res = child->FindWindow( id ); | |
1302 | } | |
1303 | ||
1304 | return (wxWindow *)res; | |
1305 | } | |
1306 | ||
6b73af79 | 1307 | wxWindow *wxWindowBase::FindWindow(const wxString& name) const |
f03fc89f VZ |
1308 | { |
1309 | if ( name == m_windowName ) | |
1310 | return (wxWindow *)this; | |
1311 | ||
1312 | wxWindowBase *res = (wxWindow *)NULL; | |
222ed1d6 | 1313 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1314 | for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() ) |
1315 | { | |
1316 | wxWindow *child = node->GetData(); | |
1317 | res = child->FindWindow(name); | |
1318 | } | |
1319 | ||
1320 | return (wxWindow *)res; | |
1321 | } | |
1322 | ||
146ba0fe VZ |
1323 | |
1324 | // find any window by id or name or label: If parent is non-NULL, look through | |
1325 | // children for a label or title matching the specified string. If NULL, look | |
1326 | // through all top-level windows. | |
1327 | // | |
1328 | // to avoid duplicating code we reuse the same helper function but with | |
1329 | // different comparators | |
1330 | ||
1331 | typedef bool (*wxFindWindowCmp)(const wxWindow *win, | |
1332 | const wxString& label, long id); | |
1333 | ||
1334 | static | |
1335 | bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label, | |
1336 | long WXUNUSED(id)) | |
1337 | { | |
1338 | return win->GetLabel() == label; | |
1339 | } | |
1340 | ||
1341 | static | |
1342 | bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label, | |
1343 | long WXUNUSED(id)) | |
1344 | { | |
1345 | return win->GetName() == label; | |
1346 | } | |
1347 | ||
1348 | static | |
1349 | bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label), | |
1350 | long id) | |
1351 | { | |
1352 | return win->GetId() == id; | |
1353 | } | |
1354 | ||
1355 | // recursive helper for the FindWindowByXXX() functions | |
1356 | static | |
1357 | wxWindow *wxFindWindowRecursively(const wxWindow *parent, | |
1358 | const wxString& label, | |
1359 | long id, | |
1360 | wxFindWindowCmp cmp) | |
1361 | { | |
1362 | if ( parent ) | |
1363 | { | |
1364 | // see if this is the one we're looking for | |
1365 | if ( (*cmp)(parent, label, id) ) | |
1366 | return (wxWindow *)parent; | |
1367 | ||
1368 | // It wasn't, so check all its children | |
222ed1d6 | 1369 | for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst(); |
146ba0fe VZ |
1370 | node; |
1371 | node = node->GetNext() ) | |
1372 | { | |
1373 | // recursively check each child | |
1374 | wxWindow *win = (wxWindow *)node->GetData(); | |
1375 | wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp); | |
1376 | if (retwin) | |
1377 | return retwin; | |
1378 | } | |
1379 | } | |
1380 | ||
1381 | // Not found | |
1382 | return NULL; | |
1383 | } | |
1384 | ||
1385 | // helper for FindWindowByXXX() | |
1386 | static | |
1387 | wxWindow *wxFindWindowHelper(const wxWindow *parent, | |
1388 | const wxString& label, | |
1389 | long id, | |
1390 | wxFindWindowCmp cmp) | |
1391 | { | |
1392 | if ( parent ) | |
1393 | { | |
1394 | // just check parent and all its children | |
1395 | return wxFindWindowRecursively(parent, label, id, cmp); | |
1396 | } | |
1397 | ||
1398 | // start at very top of wx's windows | |
222ed1d6 | 1399 | for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); |
146ba0fe VZ |
1400 | node; |
1401 | node = node->GetNext() ) | |
1402 | { | |
1403 | // recursively check each window & its children | |
1404 | wxWindow *win = node->GetData(); | |
1405 | wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp); | |
1406 | if (retwin) | |
1407 | return retwin; | |
1408 | } | |
1409 | ||
1410 | return NULL; | |
1411 | } | |
1412 | ||
1413 | /* static */ | |
1414 | wxWindow * | |
1415 | wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent) | |
1416 | { | |
1417 | return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels); | |
1418 | } | |
1419 | ||
1420 | /* static */ | |
1421 | wxWindow * | |
1422 | wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent) | |
1423 | { | |
1424 | wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames); | |
1425 | ||
1426 | if ( !win ) | |
1427 | { | |
1428 | // fall back to the label | |
1429 | win = FindWindowByLabel(title, parent); | |
1430 | } | |
1431 | ||
1432 | return win; | |
1433 | } | |
1434 | ||
1435 | /* static */ | |
1436 | wxWindow * | |
1437 | wxWindowBase::FindWindowById( long id, const wxWindow* parent ) | |
1438 | { | |
525d8583 | 1439 | return wxFindWindowHelper(parent, wxEmptyString, id, wxFindWindowCmpIds); |
146ba0fe VZ |
1440 | } |
1441 | ||
f03fc89f VZ |
1442 | // ---------------------------------------------------------------------------- |
1443 | // dialog oriented functions | |
1444 | // ---------------------------------------------------------------------------- | |
1445 | ||
34636400 | 1446 | void wxWindowBase::MakeModal(bool modal) |
f03fc89f | 1447 | { |
34636400 VZ |
1448 | // Disable all other windows |
1449 | if ( IsTopLevel() ) | |
1450 | { | |
222ed1d6 | 1451 | wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); |
34636400 VZ |
1452 | while (node) |
1453 | { | |
1454 | wxWindow *win = node->GetData(); | |
1455 | if (win != this) | |
1456 | win->Enable(!modal); | |
1457 | ||
1458 | node = node->GetNext(); | |
1459 | } | |
1460 | } | |
f03fc89f VZ |
1461 | } |
1462 | ||
1463 | bool wxWindowBase::Validate() | |
1464 | { | |
88ac883a | 1465 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1466 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1467 | ||
222ed1d6 | 1468 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1469 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) |
1470 | { | |
1471 | wxWindowBase *child = node->GetData(); | |
1472 | wxValidator *validator = child->GetValidator(); | |
dcd6b914 | 1473 | if ( validator && !validator->Validate((wxWindow *)this) ) |
f03fc89f | 1474 | { |
e11f4636 | 1475 | return false; |
f03fc89f | 1476 | } |
d80cd92a VZ |
1477 | |
1478 | if ( recurse && !child->Validate() ) | |
1479 | { | |
e11f4636 | 1480 | return false; |
d80cd92a | 1481 | } |
f03fc89f | 1482 | } |
88ac883a | 1483 | #endif // wxUSE_VALIDATORS |
f03fc89f | 1484 | |
e11f4636 | 1485 | return true; |
f03fc89f VZ |
1486 | } |
1487 | ||
1488 | bool wxWindowBase::TransferDataToWindow() | |
1489 | { | |
88ac883a | 1490 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1491 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1492 | ||
222ed1d6 | 1493 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1494 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) |
1495 | { | |
1496 | wxWindowBase *child = node->GetData(); | |
1497 | wxValidator *validator = child->GetValidator(); | |
1498 | if ( validator && !validator->TransferToWindow() ) | |
1499 | { | |
d80cd92a | 1500 | wxLogWarning(_("Could not transfer data to window")); |
e30285ab | 1501 | #if wxUSE_LOG |
d80cd92a | 1502 | wxLog::FlushActive(); |
e30285ab | 1503 | #endif // wxUSE_LOG |
f03fc89f | 1504 | |
e11f4636 | 1505 | return false; |
f03fc89f | 1506 | } |
d80cd92a VZ |
1507 | |
1508 | if ( recurse ) | |
1509 | { | |
a58a12e9 | 1510 | if ( !child->TransferDataToWindow() ) |
d80cd92a VZ |
1511 | { |
1512 | // warning already given | |
e11f4636 | 1513 | return false; |
d80cd92a VZ |
1514 | } |
1515 | } | |
f03fc89f | 1516 | } |
88ac883a | 1517 | #endif // wxUSE_VALIDATORS |
f03fc89f | 1518 | |
e11f4636 | 1519 | return true; |
f03fc89f VZ |
1520 | } |
1521 | ||
1522 | bool wxWindowBase::TransferDataFromWindow() | |
1523 | { | |
88ac883a | 1524 | #if wxUSE_VALIDATORS |
d80cd92a VZ |
1525 | bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0; |
1526 | ||
222ed1d6 | 1527 | wxWindowList::compatibility_iterator node; |
f03fc89f VZ |
1528 | for ( node = m_children.GetFirst(); node; node = node->GetNext() ) |
1529 | { | |
1530 | wxWindow *child = node->GetData(); | |
d80cd92a VZ |
1531 | wxValidator *validator = child->GetValidator(); |
1532 | if ( validator && !validator->TransferFromWindow() ) | |
f03fc89f | 1533 | { |
d80cd92a VZ |
1534 | // nop warning here because the application is supposed to give |
1535 | // one itself - we don't know here what might have gone wrongly | |
1536 | ||
e11f4636 | 1537 | return false; |
f03fc89f | 1538 | } |
d80cd92a VZ |
1539 | |
1540 | if ( recurse ) | |
1541 | { | |
a58a12e9 | 1542 | if ( !child->TransferDataFromWindow() ) |
d80cd92a VZ |
1543 | { |
1544 | // warning already given | |
e11f4636 | 1545 | return false; |
d80cd92a VZ |
1546 | } |
1547 | } | |
f03fc89f | 1548 | } |
88ac883a | 1549 | #endif // wxUSE_VALIDATORS |
f03fc89f | 1550 | |
e11f4636 | 1551 | return true; |
f03fc89f VZ |
1552 | } |
1553 | ||
1554 | void wxWindowBase::InitDialog() | |
1555 | { | |
1556 | wxInitDialogEvent event(GetId()); | |
1557 | event.SetEventObject( this ); | |
1558 | GetEventHandler()->ProcessEvent(event); | |
1559 | } | |
1560 | ||
1561 | // ---------------------------------------------------------------------------- | |
bd83cb56 VZ |
1562 | // context-sensitive help support |
1563 | // ---------------------------------------------------------------------------- | |
1564 | ||
1565 | #if wxUSE_HELP | |
1566 | ||
1567 | // associate this help text with this window | |
1568 | void wxWindowBase::SetHelpText(const wxString& text) | |
1569 | { | |
1570 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1571 | if ( helpProvider ) | |
1572 | { | |
1573 | helpProvider->AddHelp(this, text); | |
1574 | } | |
1575 | } | |
1576 | ||
1577 | // associate this help text with all windows with the same id as this | |
1578 | // one | |
1579 | void wxWindowBase::SetHelpTextForId(const wxString& text) | |
1580 | { | |
1581 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1582 | if ( helpProvider ) | |
1583 | { | |
1584 | helpProvider->AddHelp(GetId(), text); | |
1585 | } | |
1586 | } | |
1587 | ||
1588 | // get the help string associated with this window (may be empty) | |
dc6588e7 VZ |
1589 | // default implementation forwards calls to the help provider |
1590 | wxString | |
1591 | wxWindowBase::GetHelpTextAtPoint(const wxPoint & WXUNUSED(pt), | |
1592 | wxHelpEvent::Origin WXUNUSED(origin)) const | |
bd83cb56 VZ |
1593 | { |
1594 | wxString text; | |
1595 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1596 | if ( helpProvider ) | |
1597 | { | |
1598 | text = helpProvider->GetHelp(this); | |
1599 | } | |
1600 | ||
1601 | return text; | |
1602 | } | |
1603 | ||
1604 | // show help for this window | |
1605 | void wxWindowBase::OnHelp(wxHelpEvent& event) | |
1606 | { | |
1607 | wxHelpProvider *helpProvider = wxHelpProvider::Get(); | |
1608 | if ( helpProvider ) | |
1609 | { | |
dc6588e7 | 1610 | if ( helpProvider->ShowHelpAtPoint(this, event.GetPosition(), event.GetOrigin()) ) |
bd83cb56 VZ |
1611 | { |
1612 | // skip the event.Skip() below | |
1613 | return; | |
1614 | } | |
1615 | } | |
1616 | ||
1617 | event.Skip(); | |
1618 | } | |
1619 | ||
1620 | #endif // wxUSE_HELP | |
1621 | ||
1622 | // ---------------------------------------------------------------------------- | |
602a2e02 | 1623 | // tooltips |
f03fc89f VZ |
1624 | // ---------------------------------------------------------------------------- |
1625 | ||
1626 | #if wxUSE_TOOLTIPS | |
1627 | ||
1628 | void wxWindowBase::SetToolTip( const wxString &tip ) | |
1629 | { | |
1630 | // don't create the new tooltip if we already have one | |
1631 | if ( m_tooltip ) | |
1632 | { | |
1633 | m_tooltip->SetTip( tip ); | |
1634 | } | |
1635 | else | |
1636 | { | |
1637 | SetToolTip( new wxToolTip( tip ) ); | |
1638 | } | |
1639 | ||
1640 | // setting empty tooltip text does not remove the tooltip any more - use | |
1641 | // SetToolTip((wxToolTip *)NULL) for this | |
1642 | } | |
1643 | ||
1644 | void wxWindowBase::DoSetToolTip(wxToolTip *tooltip) | |
1645 | { | |
0cb57187 VZ |
1646 | if ( m_tooltip != tooltip ) |
1647 | { | |
1648 | if ( m_tooltip ) | |
1649 | delete m_tooltip; | |
f03fc89f | 1650 | |
0cb57187 VZ |
1651 | m_tooltip = tooltip; |
1652 | } | |
f03fc89f VZ |
1653 | } |
1654 | ||
1655 | #endif // wxUSE_TOOLTIPS | |
1656 | ||
1657 | // ---------------------------------------------------------------------------- | |
1658 | // constraints and sizers | |
1659 | // ---------------------------------------------------------------------------- | |
1660 | ||
1661 | #if wxUSE_CONSTRAINTS | |
1662 | ||
1663 | void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints ) | |
1664 | { | |
1665 | if ( m_constraints ) | |
1666 | { | |
1667 | UnsetConstraints(m_constraints); | |
1668 | delete m_constraints; | |
1669 | } | |
1670 | m_constraints = constraints; | |
1671 | if ( m_constraints ) | |
1672 | { | |
1673 | // Make sure other windows know they're part of a 'meaningful relationship' | |
1674 | if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) ) | |
1675 | m_constraints->left.GetOtherWindow()->AddConstraintReference(this); | |
1676 | if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) ) | |
1677 | m_constraints->top.GetOtherWindow()->AddConstraintReference(this); | |
1678 | if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) ) | |
1679 | m_constraints->right.GetOtherWindow()->AddConstraintReference(this); | |
1680 | if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) ) | |
1681 | m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this); | |
1682 | if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) ) | |
1683 | m_constraints->width.GetOtherWindow()->AddConstraintReference(this); | |
1684 | if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) ) | |
1685 | m_constraints->height.GetOtherWindow()->AddConstraintReference(this); | |
1686 | if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) ) | |
1687 | m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this); | |
1688 | if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) ) | |
1689 | m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this); | |
1690 | } | |
1691 | } | |
1692 | ||
1693 | // This removes any dangling pointers to this window in other windows' | |
1694 | // constraintsInvolvedIn lists. | |
1695 | void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c) | |
1696 | { | |
1697 | if ( c ) | |
1698 | { | |
1699 | if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1700 | c->left.GetOtherWindow()->RemoveConstraintReference(this); | |
1701 | if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) ) | |
1702 | c->top.GetOtherWindow()->RemoveConstraintReference(this); | |
1703 | if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) ) | |
1704 | c->right.GetOtherWindow()->RemoveConstraintReference(this); | |
1705 | if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) ) | |
1706 | c->bottom.GetOtherWindow()->RemoveConstraintReference(this); | |
1707 | if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) ) | |
1708 | c->width.GetOtherWindow()->RemoveConstraintReference(this); | |
1709 | if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) ) | |
1710 | c->height.GetOtherWindow()->RemoveConstraintReference(this); | |
1711 | if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) ) | |
1712 | c->centreX.GetOtherWindow()->RemoveConstraintReference(this); | |
1713 | if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) ) | |
1714 | c->centreY.GetOtherWindow()->RemoveConstraintReference(this); | |
1715 | } | |
1716 | } | |
1717 | ||
1718 | // Back-pointer to other windows we're involved with, so if we delete this | |
1719 | // window, we must delete any constraints we're involved with. | |
1720 | void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin) | |
1721 | { | |
1722 | if ( !m_constraintsInvolvedIn ) | |
1723 | m_constraintsInvolvedIn = new wxWindowList; | |
222ed1d6 MB |
1724 | if ( !m_constraintsInvolvedIn->Find((wxWindow *)otherWin) ) |
1725 | m_constraintsInvolvedIn->Append((wxWindow *)otherWin); | |
f03fc89f VZ |
1726 | } |
1727 | ||
1728 | // REMOVE back-pointer to other windows we're involved with. | |
1729 | void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin) | |
1730 | { | |
1731 | if ( m_constraintsInvolvedIn ) | |
222ed1d6 | 1732 | m_constraintsInvolvedIn->DeleteObject((wxWindow *)otherWin); |
f03fc89f VZ |
1733 | } |
1734 | ||
1735 | // Reset any constraints that mention this window | |
1736 | void wxWindowBase::DeleteRelatedConstraints() | |
1737 | { | |
1738 | if ( m_constraintsInvolvedIn ) | |
1739 | { | |
222ed1d6 | 1740 | wxWindowList::compatibility_iterator node = m_constraintsInvolvedIn->GetFirst(); |
f03fc89f VZ |
1741 | while (node) |
1742 | { | |
1743 | wxWindow *win = node->GetData(); | |
1744 | wxLayoutConstraints *constr = win->GetConstraints(); | |
1745 | ||
1746 | // Reset any constraints involving this window | |
1747 | if ( constr ) | |
1748 | { | |
1749 | constr->left.ResetIfWin(this); | |
1750 | constr->top.ResetIfWin(this); | |
1751 | constr->right.ResetIfWin(this); | |
1752 | constr->bottom.ResetIfWin(this); | |
1753 | constr->width.ResetIfWin(this); | |
1754 | constr->height.ResetIfWin(this); | |
1755 | constr->centreX.ResetIfWin(this); | |
1756 | constr->centreY.ResetIfWin(this); | |
1757 | } | |
1758 | ||
222ed1d6 MB |
1759 | wxWindowList::compatibility_iterator next = node->GetNext(); |
1760 | m_constraintsInvolvedIn->Erase(node); | |
f03fc89f VZ |
1761 | node = next; |
1762 | } | |
1763 | ||
1764 | delete m_constraintsInvolvedIn; | |
1765 | m_constraintsInvolvedIn = (wxWindowList *) NULL; | |
1766 | } | |
1767 | } | |
ec5bb70d VZ |
1768 | |
1769 | #endif // wxUSE_CONSTRAINTS | |
f03fc89f | 1770 | |
3aa5d532 | 1771 | void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld) |
f03fc89f | 1772 | { |
fb89cfc5 RD |
1773 | if ( sizer == m_windowSizer) |
1774 | return; | |
1b69c815 | 1775 | |
e8cfff87 VZ |
1776 | if ( m_windowSizer ) |
1777 | { | |
1778 | m_windowSizer->SetContainingWindow(NULL); | |
1779 | ||
1780 | if ( deleteOld ) | |
1781 | delete m_windowSizer; | |
1782 | } | |
3417c2cd | 1783 | |
f03fc89f | 1784 | m_windowSizer = sizer; |
e8cfff87 VZ |
1785 | if ( m_windowSizer ) |
1786 | { | |
1787 | m_windowSizer->SetContainingWindow((wxWindow *)this); | |
1788 | } | |
566d84a7 | 1789 | |
e8cfff87 | 1790 | SetAutoLayout(m_windowSizer != NULL); |
566d84a7 RL |
1791 | } |
1792 | ||
1793 | void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld) | |
1794 | { | |
1795 | SetSizer( sizer, deleteOld ); | |
1796 | sizer->SetSizeHints( (wxWindow*) this ); | |
f03fc89f VZ |
1797 | } |
1798 | ||
400a9e41 | 1799 | |
1ebfafde RD |
1800 | void wxWindowBase::SetContainingSizer(wxSizer* sizer) |
1801 | { | |
1802 | // adding a window to a sizer twice is going to result in fatal and | |
1803 | // hard to debug problems later because when deleting the second | |
1804 | // associated wxSizerItem we're going to dereference a dangling | |
1805 | // pointer; so try to detect this as early as possible | |
1806 | wxASSERT_MSG( !sizer || m_containingSizer != sizer, | |
1807 | _T("Adding a window to the same sizer twice?") ); | |
1ebfafde | 1808 | |
400a9e41 | 1809 | m_containingSizer = sizer; |
1ebfafde | 1810 | } |
400a9e41 | 1811 | |
ec5bb70d VZ |
1812 | #if wxUSE_CONSTRAINTS |
1813 | ||
1814 | void wxWindowBase::SatisfyConstraints() | |
1815 | { | |
1816 | wxLayoutConstraints *constr = GetConstraints(); | |
1817 | bool wasOk = constr && constr->AreSatisfied(); | |
1818 | ||
1819 | ResetConstraints(); // Mark all constraints as unevaluated | |
1820 | ||
1821 | int noChanges = 1; | |
1822 | ||
1823 | // if we're a top level panel (i.e. our parent is frame/dialog), our | |
1824 | // own constraints will never be satisfied any more unless we do it | |
1825 | // here | |
1826 | if ( wasOk ) | |
1827 | { | |
1828 | while ( noChanges > 0 ) | |
1829 | { | |
1830 | LayoutPhase1(&noChanges); | |
1831 | } | |
1832 | } | |
1833 | ||
1834 | LayoutPhase2(&noChanges); | |
1835 | } | |
1836 | ||
1837 | #endif // wxUSE_CONSTRAINTS | |
1838 | ||
f03fc89f VZ |
1839 | bool wxWindowBase::Layout() |
1840 | { | |
3417c2cd | 1841 | // If there is a sizer, use it instead of the constraints |
f03fc89f VZ |
1842 | if ( GetSizer() ) |
1843 | { | |
8d7eaf91 | 1844 | int w = 0, h = 0; |
566d84a7 | 1845 | GetVirtualSize(&w, &h); |
3417c2cd | 1846 | GetSizer()->SetDimension( 0, 0, w, h ); |
f03fc89f | 1847 | } |
461e93f9 | 1848 | #if wxUSE_CONSTRAINTS |
f1df0927 | 1849 | else |
f03fc89f | 1850 | { |
ec5bb70d | 1851 | SatisfyConstraints(); // Find the right constraints values |
f1df0927 | 1852 | SetConstraintSizes(); // Recursively set the real window sizes |
f03fc89f | 1853 | } |
461e93f9 | 1854 | #endif |
5d4b632b | 1855 | |
e11f4636 | 1856 | return true; |
f03fc89f VZ |
1857 | } |
1858 | ||
461e93f9 | 1859 | #if wxUSE_CONSTRAINTS |
ec5bb70d VZ |
1860 | |
1861 | // first phase of the constraints evaluation: set our own constraints | |
f03fc89f VZ |
1862 | bool wxWindowBase::LayoutPhase1(int *noChanges) |
1863 | { | |
1864 | wxLayoutConstraints *constr = GetConstraints(); | |
ec5bb70d VZ |
1865 | |
1866 | return !constr || constr->SatisfyConstraints(this, noChanges); | |
f03fc89f VZ |
1867 | } |
1868 | ||
ec5bb70d | 1869 | // second phase: set the constraints for our children |
f03fc89f VZ |
1870 | bool wxWindowBase::LayoutPhase2(int *noChanges) |
1871 | { | |
1872 | *noChanges = 0; | |
1873 | ||
1874 | // Layout children | |
1875 | DoPhase(1); | |
ec5bb70d VZ |
1876 | |
1877 | // Layout grand children | |
f03fc89f | 1878 | DoPhase(2); |
ec5bb70d | 1879 | |
e11f4636 | 1880 | return true; |
f03fc89f VZ |
1881 | } |
1882 | ||
1883 | // Do a phase of evaluating child constraints | |
1884 | bool wxWindowBase::DoPhase(int phase) | |
1885 | { | |
ec5bb70d VZ |
1886 | // the list containing the children for which the constraints are already |
1887 | // set correctly | |
f03fc89f | 1888 | wxWindowList succeeded; |
ec5bb70d VZ |
1889 | |
1890 | // the max number of iterations we loop before concluding that we can't set | |
1891 | // the constraints | |
1892 | static const int maxIterations = 500; | |
1893 | ||
1894 | for ( int noIterations = 0; noIterations < maxIterations; noIterations++ ) | |
f03fc89f | 1895 | { |
ec5bb70d VZ |
1896 | int noChanges = 0; |
1897 | ||
1898 | // loop over all children setting their constraints | |
222ed1d6 | 1899 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
ec5bb70d VZ |
1900 | node; |
1901 | node = node->GetNext() ) | |
f03fc89f VZ |
1902 | { |
1903 | wxWindow *child = node->GetData(); | |
ec5bb70d | 1904 | if ( child->IsTopLevel() ) |
f03fc89f | 1905 | { |
ec5bb70d VZ |
1906 | // top level children are not inside our client area |
1907 | continue; | |
1908 | } | |
1909 | ||
1910 | if ( !child->GetConstraints() || succeeded.Find(child) ) | |
1911 | { | |
1912 | // this one is either already ok or nothing we can do about it | |
1913 | continue; | |
1914 | } | |
1915 | ||
1916 | int tempNoChanges = 0; | |
1917 | bool success = phase == 1 ? child->LayoutPhase1(&tempNoChanges) | |
1918 | : child->LayoutPhase2(&tempNoChanges); | |
1919 | noChanges += tempNoChanges; | |
1920 | ||
1921 | if ( success ) | |
1922 | { | |
1923 | succeeded.Append(child); | |
f03fc89f | 1924 | } |
f03fc89f VZ |
1925 | } |
1926 | ||
ec5bb70d VZ |
1927 | if ( !noChanges ) |
1928 | { | |
1929 | // constraints are set | |
1930 | break; | |
1931 | } | |
f03fc89f VZ |
1932 | } |
1933 | ||
e11f4636 | 1934 | return true; |
f03fc89f VZ |
1935 | } |
1936 | ||
1937 | void wxWindowBase::ResetConstraints() | |
1938 | { | |
1939 | wxLayoutConstraints *constr = GetConstraints(); | |
1940 | if ( constr ) | |
1941 | { | |
e11f4636 DS |
1942 | constr->left.SetDone(false); |
1943 | constr->top.SetDone(false); | |
1944 | constr->right.SetDone(false); | |
1945 | constr->bottom.SetDone(false); | |
1946 | constr->width.SetDone(false); | |
1947 | constr->height.SetDone(false); | |
1948 | constr->centreX.SetDone(false); | |
1949 | constr->centreY.SetDone(false); | |
f03fc89f | 1950 | } |
f1df0927 | 1951 | |
222ed1d6 | 1952 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
f03fc89f VZ |
1953 | while (node) |
1954 | { | |
1955 | wxWindow *win = node->GetData(); | |
34636400 | 1956 | if ( !win->IsTopLevel() ) |
f03fc89f VZ |
1957 | win->ResetConstraints(); |
1958 | node = node->GetNext(); | |
1959 | } | |
1960 | } | |
1961 | ||
1962 | // Need to distinguish between setting the 'fake' size for windows and sizers, | |
1963 | // and setting the real values. | |
1964 | void wxWindowBase::SetConstraintSizes(bool recurse) | |
1965 | { | |
1966 | wxLayoutConstraints *constr = GetConstraints(); | |
4b7f2165 | 1967 | if ( constr && constr->AreSatisfied() ) |
f03fc89f VZ |
1968 | { |
1969 | int x = constr->left.GetValue(); | |
1970 | int y = constr->top.GetValue(); | |
1971 | int w = constr->width.GetValue(); | |
1972 | int h = constr->height.GetValue(); | |
1973 | ||
f03fc89f | 1974 | if ( (constr->width.GetRelationship() != wxAsIs ) || |
3417c2cd | 1975 | (constr->height.GetRelationship() != wxAsIs) ) |
f03fc89f | 1976 | { |
3417c2cd | 1977 | SetSize(x, y, w, h); |
f03fc89f VZ |
1978 | } |
1979 | else | |
1980 | { | |
3417c2cd RR |
1981 | // If we don't want to resize this window, just move it... |
1982 | Move(x, y); | |
f03fc89f VZ |
1983 | } |
1984 | } | |
1985 | else if ( constr ) | |
1986 | { | |
4b7f2165 | 1987 | wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."), |
f1df0927 | 1988 | GetClassInfo()->GetClassName(), |
4b7f2165 | 1989 | GetName().c_str()); |
f03fc89f VZ |
1990 | } |
1991 | ||
1992 | if ( recurse ) | |
1993 | { | |
222ed1d6 | 1994 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
f03fc89f VZ |
1995 | while (node) |
1996 | { | |
1997 | wxWindow *win = node->GetData(); | |
e2f9212c | 1998 | if ( !win->IsTopLevel() && win->GetConstraints() ) |
f03fc89f VZ |
1999 | win->SetConstraintSizes(); |
2000 | node = node->GetNext(); | |
2001 | } | |
2002 | } | |
2003 | } | |
2004 | ||
f03fc89f VZ |
2005 | // Only set the size/position of the constraint (if any) |
2006 | void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h) | |
2007 | { | |
2008 | wxLayoutConstraints *constr = GetConstraints(); | |
2009 | if ( constr ) | |
2010 | { | |
422d0ff0 | 2011 | if ( x != wxDefaultCoord ) |
f03fc89f VZ |
2012 | { |
2013 | constr->left.SetValue(x); | |
e11f4636 | 2014 | constr->left.SetDone(true); |
f03fc89f | 2015 | } |
422d0ff0 | 2016 | if ( y != wxDefaultCoord ) |
f03fc89f VZ |
2017 | { |
2018 | constr->top.SetValue(y); | |
e11f4636 | 2019 | constr->top.SetDone(true); |
f03fc89f | 2020 | } |
422d0ff0 | 2021 | if ( w != wxDefaultCoord ) |
f03fc89f VZ |
2022 | { |
2023 | constr->width.SetValue(w); | |
e11f4636 | 2024 | constr->width.SetDone(true); |
f03fc89f | 2025 | } |
422d0ff0 | 2026 | if ( h != wxDefaultCoord ) |
f03fc89f VZ |
2027 | { |
2028 | constr->height.SetValue(h); | |
e11f4636 | 2029 | constr->height.SetDone(true); |
f03fc89f VZ |
2030 | } |
2031 | } | |
2032 | } | |
2033 | ||
2034 | void wxWindowBase::MoveConstraint(int x, int y) | |
2035 | { | |
2036 | wxLayoutConstraints *constr = GetConstraints(); | |
2037 | if ( constr ) | |
2038 | { | |
422d0ff0 | 2039 | if ( x != wxDefaultCoord ) |
f03fc89f VZ |
2040 | { |
2041 | constr->left.SetValue(x); | |
e11f4636 | 2042 | constr->left.SetDone(true); |
f03fc89f | 2043 | } |
422d0ff0 | 2044 | if ( y != wxDefaultCoord ) |
f03fc89f VZ |
2045 | { |
2046 | constr->top.SetValue(y); | |
e11f4636 | 2047 | constr->top.SetDone(true); |
f03fc89f VZ |
2048 | } |
2049 | } | |
2050 | } | |
2051 | ||
2052 | void wxWindowBase::GetSizeConstraint(int *w, int *h) const | |
2053 | { | |
2054 | wxLayoutConstraints *constr = GetConstraints(); | |
2055 | if ( constr ) | |
2056 | { | |
2057 | *w = constr->width.GetValue(); | |
2058 | *h = constr->height.GetValue(); | |
2059 | } | |
2060 | else | |
2061 | GetSize(w, h); | |
2062 | } | |
2063 | ||
2064 | void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const | |
2065 | { | |
2066 | wxLayoutConstraints *constr = GetConstraints(); | |
2067 | if ( constr ) | |
2068 | { | |
2069 | *w = constr->width.GetValue(); | |
2070 | *h = constr->height.GetValue(); | |
2071 | } | |
2072 | else | |
2073 | GetClientSize(w, h); | |
2074 | } | |
2075 | ||
461e93f9 JS |
2076 | void wxWindowBase::GetPositionConstraint(int *x, int *y) const |
2077 | { | |
2078 | wxLayoutConstraints *constr = GetConstraints(); | |
2079 | if ( constr ) | |
2080 | { | |
2081 | *x = constr->left.GetValue(); | |
2082 | *y = constr->top.GetValue(); | |
2083 | } | |
2084 | else | |
2085 | GetPosition(x, y); | |
2086 | } | |
2087 | ||
2088 | #endif // wxUSE_CONSTRAINTS | |
2089 | ||
20a1eea1 | 2090 | void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const |
a200c35e VS |
2091 | { |
2092 | // don't do it for the dialogs/frames - they float independently of their | |
2093 | // parent | |
2094 | if ( !IsTopLevel() ) | |
2095 | { | |
2096 | wxWindow *parent = GetParent(); | |
2097 | if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent ) | |
2098 | { | |
2099 | wxPoint pt(parent->GetClientAreaOrigin()); | |
2100 | x += pt.x; | |
2101 | y += pt.y; | |
2102 | } | |
2103 | } | |
2104 | } | |
2105 | ||
f03fc89f | 2106 | // ---------------------------------------------------------------------------- |
602a2e02 | 2107 | // Update UI processing |
f03fc89f | 2108 | // ---------------------------------------------------------------------------- |
7ec1983b | 2109 | |
e39af974 | 2110 | void wxWindowBase::UpdateWindowUI(long flags) |
7ec1983b | 2111 | { |
26bf1ce0 | 2112 | wxUpdateUIEvent event(GetId()); |
687706f5 | 2113 | event.SetEventObject(this); |
26bf1ce0 VZ |
2114 | |
2115 | if ( GetEventHandler()->ProcessEvent(event) ) | |
7ec1983b | 2116 | { |
e39af974 JS |
2117 | DoUpdateWindowUI(event); |
2118 | } | |
7ec1983b | 2119 | |
e39af974 JS |
2120 | if (flags & wxUPDATE_UI_RECURSE) |
2121 | { | |
222ed1d6 | 2122 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
e39af974 | 2123 | while (node) |
f03fc89f | 2124 | { |
e39af974 JS |
2125 | wxWindow* child = (wxWindow*) node->GetData(); |
2126 | child->UpdateWindowUI(flags); | |
2127 | node = node->GetNext(); | |
26bf1ce0 | 2128 | } |
e39af974 JS |
2129 | } |
2130 | } | |
f03fc89f | 2131 | |
e39af974 | 2132 | // do the window-specific processing after processing the update event |
e39af974 JS |
2133 | void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event) |
2134 | { | |
2135 | if ( event.GetSetEnabled() ) | |
2136 | Enable(event.GetEnabled()); | |
e11f4636 | 2137 | |
a3a4105d VZ |
2138 | if ( event.GetSetShown() ) |
2139 | Show(event.GetShown()); | |
e39af974 JS |
2140 | } |
2141 | ||
f03fc89f VZ |
2142 | // ---------------------------------------------------------------------------- |
2143 | // dialog units translations | |
2144 | // ---------------------------------------------------------------------------- | |
2145 | ||
2146 | wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt) | |
fd71308f JS |
2147 | { |
2148 | int charWidth = GetCharWidth(); | |
2149 | int charHeight = GetCharHeight(); | |
cab1a605 WS |
2150 | wxPoint pt2 = wxDefaultPosition; |
2151 | if (pt.x != wxDefaultCoord) | |
1b69c815 | 2152 | pt2.x = (int) ((pt.x * 4) / charWidth); |
cab1a605 | 2153 | if (pt.y != wxDefaultCoord) |
1b69c815 | 2154 | pt2.y = (int) ((pt.y * 8) / charHeight); |
fd71308f JS |
2155 | |
2156 | return pt2; | |
2157 | } | |
2158 | ||
f03fc89f | 2159 | wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt) |
fd71308f JS |
2160 | { |
2161 | int charWidth = GetCharWidth(); | |
2162 | int charHeight = GetCharHeight(); | |
cab1a605 WS |
2163 | wxPoint pt2 = wxDefaultPosition; |
2164 | if (pt.x != wxDefaultCoord) | |
1b69c815 | 2165 | pt2.x = (int) ((pt.x * charWidth) / 4); |
cab1a605 | 2166 | if (pt.y != wxDefaultCoord) |
1b69c815 | 2167 | pt2.y = (int) ((pt.y * charHeight) / 8); |
fd71308f JS |
2168 | |
2169 | return pt2; | |
2170 | } | |
2171 | ||
f03fc89f VZ |
2172 | // ---------------------------------------------------------------------------- |
2173 | // event handlers | |
2174 | // ---------------------------------------------------------------------------- | |
2175 | ||
2176 | // propagate the colour change event to the subwindows | |
2177 | void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event) | |
2178 | { | |
222ed1d6 | 2179 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
f03fc89f VZ |
2180 | while ( node ) |
2181 | { | |
2182 | // Only propagate to non-top-level windows | |
2183 | wxWindow *win = node->GetData(); | |
2184 | if ( !win->IsTopLevel() ) | |
2185 | { | |
2186 | wxSysColourChangedEvent event2; | |
687706f5 | 2187 | event.SetEventObject(win); |
f03fc89f VZ |
2188 | win->GetEventHandler()->ProcessEvent(event2); |
2189 | } | |
2190 | ||
2191 | node = node->GetNext(); | |
2192 | } | |
9a8477e1 VS |
2193 | |
2194 | Refresh(); | |
f03fc89f VZ |
2195 | } |
2196 | ||
e39af974 JS |
2197 | // the default action is to populate dialog with data when it's created, |
2198 | // and nudge the UI into displaying itself correctly in case | |
2199 | // we've turned the wxUpdateUIEvents frequency down low. | |
f03fc89f VZ |
2200 | void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) ) |
2201 | { | |
2202 | TransferDataToWindow(); | |
e11f4636 | 2203 | |
e39af974 JS |
2204 | // Update the UI at this point |
2205 | UpdateWindowUI(wxUPDATE_UI_RECURSE); | |
f03fc89f VZ |
2206 | } |
2207 | ||
dddd1f21 VZ |
2208 | // methods for drawing the sizers in a visible way |
2209 | #ifdef __WXDEBUG__ | |
2210 | ||
2211 | static void DrawSizers(wxWindowBase *win); | |
2212 | ||
2213 | static void DrawBorder(wxWindowBase *win, const wxRect& rect, bool fill = false) | |
2214 | { | |
2215 | wxClientDC dc((wxWindow *)win); | |
2216 | dc.SetPen(*wxRED_PEN); | |
2217 | dc.SetBrush(fill ? wxBrush(*wxRED, wxCROSSDIAG_HATCH): *wxTRANSPARENT_BRUSH); | |
2218 | dc.DrawRectangle(rect.Deflate(1, 1)); | |
2219 | } | |
2220 | ||
2221 | static void DrawSizer(wxWindowBase *win, wxSizer *sizer) | |
2222 | { | |
2223 | const wxSizerItemList& items = sizer->GetChildren(); | |
2224 | for ( wxSizerItemList::const_iterator i = items.begin(), | |
2225 | end = items.end(); | |
2226 | i != end; | |
2227 | ++i ) | |
2228 | { | |
2229 | wxSizerItem *item = *i; | |
2230 | if ( item->IsSizer() ) | |
2231 | { | |
2232 | DrawBorder(win, item->GetRect().Deflate(2)); | |
2233 | DrawSizer(win, item->GetSizer()); | |
2234 | } | |
2235 | else if ( item->IsSpacer() ) | |
2236 | { | |
2237 | DrawBorder(win, item->GetRect().Deflate(2), true); | |
2238 | } | |
2239 | else if ( item->IsWindow() ) | |
2240 | { | |
2241 | DrawSizers(item->GetWindow()); | |
2242 | } | |
2243 | } | |
2244 | } | |
2245 | ||
2246 | static void DrawSizers(wxWindowBase *win) | |
2247 | { | |
2248 | wxSizer *sizer = win->GetSizer(); | |
2249 | if ( sizer ) | |
2250 | { | |
2251 | DrawBorder(win, win->GetClientSize()); | |
2252 | DrawSizer(win, sizer); | |
2253 | } | |
2254 | else // no sizer, still recurse into the children | |
2255 | { | |
2256 | const wxWindowList& children = win->GetChildren(); | |
2257 | for ( wxWindowList::const_iterator i = children.begin(), | |
2258 | end = children.end(); | |
2259 | i != end; | |
2260 | ++i ) | |
2261 | { | |
2262 | DrawSizers(*i); | |
2263 | } | |
2264 | } | |
2265 | } | |
2266 | ||
2267 | #endif // __WXDEBUG__ | |
2268 | ||
2269 | // process special middle clicks | |
a02dc3e3 VZ |
2270 | void wxWindowBase::OnMiddleClick( wxMouseEvent& event ) |
2271 | { | |
2272 | if ( event.ControlDown() && event.AltDown() ) | |
2273 | { | |
dddd1f21 VZ |
2274 | #ifdef __WXDEBUG__ |
2275 | // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds | |
2276 | if ( event.ShiftDown() ) | |
2277 | { | |
2278 | DrawSizers(this); | |
2279 | return; | |
2280 | } | |
2281 | #endif // __WXDEBUG__ | |
2282 | ||
2283 | #if wxUSE_MSGDLG | |
8bb6b2c0 VZ |
2284 | // don't translate these strings, they're for diagnostics purposes only |
2285 | wxString msg; | |
2286 | msg.Printf(_T("wxWidgets Library (%s port)\n") | |
449090b5 VZ |
2287 | _T("Version %d.%d.%d%s%s, compiled at %s %s\n") |
2288 | _T("Runtime version of toolkit used is %d.%d.%s\n") | |
c05daf1b | 2289 | _T("Copyright (c) 1995-2007 wxWidgets team"), |
449090b5 | 2290 | wxPlatformInfo::Get().GetPortIdName().c_str(), |
8bb6b2c0 VZ |
2291 | wxMAJOR_VERSION, |
2292 | wxMINOR_VERSION, | |
2293 | wxRELEASE_NUMBER, | |
3f562374 | 2294 | #if wxUSE_UNICODE |
8bb6b2c0 | 2295 | L" (Unicode)", |
3f562374 | 2296 | #else |
8bb6b2c0 | 2297 | wxEmptyString, |
b1433926 | 2298 | #endif |
4200d1f4 | 2299 | #ifdef __WXDEBUG__ |
8bb6b2c0 | 2300 | _T(" Debug build"), |
b1433926 | 2301 | #else |
8bb6b2c0 | 2302 | wxEmptyString, |
3f562374 | 2303 | #endif |
8bb6b2c0 VZ |
2304 | __TDATE__, |
2305 | __TTIME__, | |
449090b5 VZ |
2306 | wxPlatformInfo::Get().GetToolkitMajorVersion(), |
2307 | wxPlatformInfo::Get().GetToolkitMinorVersion(), | |
0118b60b | 2308 | #ifdef __WXGTK__ |
449090b5 | 2309 | wxString::Format(_T("\nThe compile-time GTK+ version is %d.%d.%d."), GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION).c_str() |
0118b60b | 2310 | #else |
8bb6b2c0 | 2311 | wxEmptyString |
0118b60b | 2312 | #endif |
8bb6b2c0 VZ |
2313 | ); |
2314 | ||
2315 | wxMessageBox(msg, _T("wxWidgets information"), | |
a02dc3e3 VZ |
2316 | wxICON_INFORMATION | wxOK, |
2317 | (wxWindow *)this); | |
2318 | } | |
2319 | else | |
1e6feb95 | 2320 | #endif // wxUSE_MSGDLG |
a02dc3e3 VZ |
2321 | { |
2322 | event.Skip(); | |
2323 | } | |
2324 | } | |
2325 | ||
ed5317e5 JS |
2326 | // ---------------------------------------------------------------------------- |
2327 | // accessibility | |
2328 | // ---------------------------------------------------------------------------- | |
2329 | ||
2330 | #if wxUSE_ACCESSIBILITY | |
2331 | void wxWindowBase::SetAccessible(wxAccessible* accessible) | |
2332 | { | |
2aefc528 | 2333 | if (m_accessible && (accessible != m_accessible)) |
ed5317e5 JS |
2334 | delete m_accessible; |
2335 | m_accessible = accessible; | |
2336 | if (m_accessible) | |
2337 | m_accessible->SetWindow((wxWindow*) this); | |
2338 | } | |
2339 | ||
2340 | // Returns the accessible object, creating if necessary. | |
2341 | wxAccessible* wxWindowBase::GetOrCreateAccessible() | |
2342 | { | |
2343 | if (!m_accessible) | |
2344 | m_accessible = CreateAccessible(); | |
2345 | return m_accessible; | |
2346 | } | |
2347 | ||
2348 | // Override to create a specific accessible object. | |
2349 | wxAccessible* wxWindowBase::CreateAccessible() | |
2350 | { | |
2351 | return new wxWindowAccessible((wxWindow*) this); | |
2352 | } | |
2353 | ||
2354 | #endif | |
2355 | ||
f03fc89f VZ |
2356 | // ---------------------------------------------------------------------------- |
2357 | // list classes implementation | |
2358 | // ---------------------------------------------------------------------------- | |
2359 | ||
ed1288c1 VZ |
2360 | #if wxUSE_STL |
2361 | ||
7ec69821 | 2362 | #include "wx/listimpl.cpp" |
412e0d47 | 2363 | WX_DEFINE_LIST(wxWindowList) |
ed1288c1 | 2364 | |
602a2e02 | 2365 | #else // !wxUSE_STL |
ed1288c1 | 2366 | |
f03fc89f VZ |
2367 | void wxWindowListNode::DeleteData() |
2368 | { | |
2369 | delete (wxWindow *)GetData(); | |
2370 | } | |
ed1288c1 | 2371 | |
602a2e02 | 2372 | #endif // wxUSE_STL/!wxUSE_STL |
f03fc89f | 2373 | |
1e6feb95 VZ |
2374 | // ---------------------------------------------------------------------------- |
2375 | // borders | |
2376 | // ---------------------------------------------------------------------------- | |
2377 | ||
aede4ebb | 2378 | wxBorder wxWindowBase::GetBorder(long flags) const |
1e6feb95 | 2379 | { |
aede4ebb | 2380 | wxBorder border = (wxBorder)(flags & wxBORDER_MASK); |
1e6feb95 VZ |
2381 | if ( border == wxBORDER_DEFAULT ) |
2382 | { | |
2383 | border = GetDefaultBorder(); | |
2384 | } | |
2385 | ||
2386 | return border; | |
2387 | } | |
2388 | ||
2389 | wxBorder wxWindowBase::GetDefaultBorder() const | |
2390 | { | |
2391 | return wxBORDER_NONE; | |
2392 | } | |
2393 | ||
2394 | // ---------------------------------------------------------------------------- | |
2395 | // hit testing | |
2396 | // ---------------------------------------------------------------------------- | |
2397 | ||
2398 | wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const | |
2399 | { | |
2400 | // here we just check if the point is inside the window or not | |
2401 | ||
2402 | // check the top and left border first | |
2403 | bool outside = x < 0 || y < 0; | |
2404 | if ( !outside ) | |
2405 | { | |
2406 | // check the right and bottom borders too | |
2407 | wxSize size = GetSize(); | |
2408 | outside = x >= size.x || y >= size.y; | |
2409 | } | |
2410 | ||
2411 | return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE; | |
2412 | } | |
2413 | ||
94633ad9 VZ |
2414 | // ---------------------------------------------------------------------------- |
2415 | // mouse capture | |
2416 | // ---------------------------------------------------------------------------- | |
2417 | ||
2418 | struct WXDLLEXPORT wxWindowNext | |
2419 | { | |
2420 | wxWindow *win; | |
2421 | wxWindowNext *next; | |
786646f3 | 2422 | } *wxWindowBase::ms_winCaptureNext = NULL; |
63e819f2 VS |
2423 | wxWindow *wxWindowBase::ms_winCaptureCurrent = NULL; |
2424 | bool wxWindowBase::ms_winCaptureChanging = false; | |
94633ad9 | 2425 | |
a83e1475 | 2426 | void wxWindowBase::CaptureMouse() |
94633ad9 | 2427 | { |
008202b7 | 2428 | wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this)); |
45e0dc94 | 2429 | |
63e819f2 VS |
2430 | wxASSERT_MSG( !ms_winCaptureChanging, _T("recursive CaptureMouse call?") ); |
2431 | ||
2432 | ms_winCaptureChanging = true; | |
2433 | ||
94633ad9 VZ |
2434 | wxWindow *winOld = GetCapture(); |
2435 | if ( winOld ) | |
2436 | { | |
df2f507b | 2437 | ((wxWindowBase*) winOld)->DoReleaseMouse(); |
edd802c6 | 2438 | |
94633ad9 VZ |
2439 | // save it on stack |
2440 | wxWindowNext *item = new wxWindowNext; | |
2441 | item->win = winOld; | |
2442 | item->next = ms_winCaptureNext; | |
2443 | ms_winCaptureNext = item; | |
2444 | } | |
2445 | //else: no mouse capture to save | |
2446 | ||
2447 | DoCaptureMouse(); | |
63e819f2 VS |
2448 | ms_winCaptureCurrent = (wxWindow*)this; |
2449 | ||
2450 | ms_winCaptureChanging = false; | |
94633ad9 VZ |
2451 | } |
2452 | ||
a83e1475 | 2453 | void wxWindowBase::ReleaseMouse() |
94633ad9 | 2454 | { |
008202b7 | 2455 | wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this)); |
349d1942 | 2456 | |
63e819f2 VS |
2457 | wxASSERT_MSG( !ms_winCaptureChanging, _T("recursive ReleaseMouse call?") ); |
2458 | ||
63fd5f0b | 2459 | wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") ); |
a7b09001 | 2460 | |
63e819f2 VS |
2461 | ms_winCaptureChanging = true; |
2462 | ||
94633ad9 | 2463 | DoReleaseMouse(); |
63e819f2 | 2464 | ms_winCaptureCurrent = NULL; |
94633ad9 VZ |
2465 | |
2466 | if ( ms_winCaptureNext ) | |
2467 | { | |
44f8caa7 | 2468 | ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse(); |
63e819f2 | 2469 | ms_winCaptureCurrent = ms_winCaptureNext->win; |
edd802c6 | 2470 | |
94633ad9 VZ |
2471 | wxWindowNext *item = ms_winCaptureNext; |
2472 | ms_winCaptureNext = item->next; | |
2473 | delete item; | |
2474 | } | |
2475 | //else: stack is empty, no previous capture | |
2476 | ||
63e819f2 VS |
2477 | ms_winCaptureChanging = false; |
2478 | ||
94633ad9 | 2479 | wxLogTrace(_T("mousecapture"), |
e11f4636 | 2480 | (const wxChar *) _T("After ReleaseMouse() mouse is captured by %p"), |
008202b7 | 2481 | wx_static_cast(void*, GetCapture())); |
94633ad9 VZ |
2482 | } |
2483 | ||
63e819f2 VS |
2484 | static void DoNotifyWindowAboutCaptureLost(wxWindow *win) |
2485 | { | |
2486 | wxMouseCaptureLostEvent event(win->GetId()); | |
2487 | event.SetEventObject(win); | |
40bdc5d6 VZ |
2488 | if ( !win->GetEventHandler()->ProcessEvent(event) ) |
2489 | { | |
44038f9a VS |
2490 | // windows must handle this event, otherwise the app wouldn't behave |
2491 | // correctly if it loses capture unexpectedly; see the discussion here: | |
2492 | // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863 | |
2493 | // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376 | |
40bdc5d6 VZ |
2494 | wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") ); |
2495 | } | |
63e819f2 VS |
2496 | } |
2497 | ||
2498 | /* static */ | |
72f8c792 | 2499 | void wxWindowBase::NotifyCaptureLost() |
63e819f2 VS |
2500 | { |
2501 | // don't do anything if capture lost was expected, i.e. resulted from | |
2502 | // a wx call to ReleaseMouse or CaptureMouse: | |
2503 | if ( ms_winCaptureChanging ) | |
2504 | return; | |
2505 | ||
2506 | // if the capture was lost unexpectedly, notify every window that has | |
2507 | // capture (on stack or current) about it and clear the stack: | |
2508 | ||
2509 | if ( ms_winCaptureCurrent ) | |
2510 | { | |
2511 | DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent); | |
2512 | ms_winCaptureCurrent = NULL; | |
2513 | } | |
2514 | ||
2515 | while ( ms_winCaptureNext ) | |
2516 | { | |
2517 | wxWindowNext *item = ms_winCaptureNext; | |
2518 | ms_winCaptureNext = item->next; | |
2519 | ||
2520 | DoNotifyWindowAboutCaptureLost(item->win); | |
2521 | ||
2522 | delete item; | |
2523 | } | |
2524 | } | |
2525 | ||
5048c832 | 2526 | #if wxUSE_HOTKEY |
540b6b09 VZ |
2527 | |
2528 | bool | |
2529 | wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId), | |
2530 | int WXUNUSED(modifiers), | |
2531 | int WXUNUSED(keycode)) | |
5048c832 JS |
2532 | { |
2533 | // not implemented | |
2534 | return false; | |
2535 | } | |
2536 | ||
540b6b09 | 2537 | bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId)) |
5048c832 JS |
2538 | { |
2539 | // not implemented | |
2540 | return false; | |
2541 | } | |
540b6b09 VZ |
2542 | |
2543 | #endif // wxUSE_HOTKEY | |
7de59551 | 2544 | |
4caf847c VZ |
2545 | // ---------------------------------------------------------------------------- |
2546 | // event processing | |
2547 | // ---------------------------------------------------------------------------- | |
2548 | ||
ac8d0c11 | 2549 | bool wxWindowBase::TryValidator(wxEvent& wxVALIDATOR_PARAM(event)) |
4caf847c | 2550 | { |
6eabf58c | 2551 | #if wxUSE_VALIDATORS |
4caf847c VZ |
2552 | // Can only use the validator of the window which |
2553 | // is receiving the event | |
2554 | if ( event.GetEventObject() == this ) | |
2555 | { | |
2556 | wxValidator *validator = GetValidator(); | |
2557 | if ( validator && validator->ProcessEvent(event) ) | |
2558 | { | |
6eabf58c | 2559 | return true; |
4caf847c VZ |
2560 | } |
2561 | } | |
6eabf58c | 2562 | #endif // wxUSE_VALIDATORS |
4caf847c | 2563 | |
6eabf58c | 2564 | return false; |
4caf847c VZ |
2565 | } |
2566 | ||
4caf847c VZ |
2567 | bool wxWindowBase::TryParent(wxEvent& event) |
2568 | { | |
90e572f1 | 2569 | // carry on up the parent-child hierarchy if the propagation count hasn't |
040e234d VZ |
2570 | // reached zero yet |
2571 | if ( event.ShouldPropagate() ) | |
4caf847c VZ |
2572 | { |
2573 | // honour the requests to stop propagation at this window: this is | |
2574 | // used by the dialogs, for example, to prevent processing the events | |
2575 | // from the dialog controls in the parent frame which rarely, if ever, | |
2576 | // makes sense | |
2577 | if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) ) | |
2578 | { | |
2579 | wxWindow *parent = GetParent(); | |
2580 | if ( parent && !parent->IsBeingDeleted() ) | |
040e234d VZ |
2581 | { |
2582 | wxPropagateOnce propagateOnce(event); | |
2583 | ||
4caf847c | 2584 | return parent->GetEventHandler()->ProcessEvent(event); |
040e234d | 2585 | } |
4caf847c VZ |
2586 | } |
2587 | } | |
2588 | ||
2589 | return wxEvtHandler::TryParent(event); | |
2590 | } | |
2591 | ||
5f6cfda7 | 2592 | // ---------------------------------------------------------------------------- |
a24de76b | 2593 | // keyboard navigation |
5f6cfda7 JS |
2594 | // ---------------------------------------------------------------------------- |
2595 | ||
2596 | // Navigates in the specified direction. | |
eedc82f4 | 2597 | bool wxWindowBase::Navigate(int flags) |
5f6cfda7 JS |
2598 | { |
2599 | wxNavigationKeyEvent eventNav; | |
eedc82f4 | 2600 | eventNav.SetFlags(flags); |
5f6cfda7 JS |
2601 | eventNav.SetEventObject(this); |
2602 | if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) ) | |
2603 | { | |
2604 | return true; | |
2605 | } | |
2606 | return false; | |
2607 | } | |
2608 | ||
a24de76b VZ |
2609 | void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move) |
2610 | { | |
2611 | // check that we're not a top level window | |
2612 | wxCHECK_RET( GetParent(), | |
2613 | _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") ); | |
2614 | ||
ef6816ef VZ |
2615 | // detect the special case when we have nothing to do anyhow and when the |
2616 | // code below wouldn't work | |
2617 | if ( win == this ) | |
2618 | return; | |
2619 | ||
a24de76b VZ |
2620 | // find the target window in the siblings list |
2621 | wxWindowList& siblings = GetParent()->GetChildren(); | |
2622 | wxWindowList::compatibility_iterator i = siblings.Find(win); | |
2623 | wxCHECK_RET( i, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") ); | |
2624 | ||
2625 | // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we | |
2626 | // can't just move the node around | |
feef1ecf VZ |
2627 | wxWindow *self = (wxWindow *)this; |
2628 | siblings.DeleteObject(self); | |
9e9300c4 VZ |
2629 | if ( move == MoveAfter ) |
2630 | { | |
2631 | i = i->GetNext(); | |
2632 | } | |
2633 | ||
2634 | if ( i ) | |
a24de76b | 2635 | { |
feef1ecf | 2636 | siblings.Insert(i, self); |
a24de76b VZ |
2637 | } |
2638 | else // MoveAfter and win was the last sibling | |
2639 | { | |
feef1ecf | 2640 | siblings.Append(self); |
a24de76b VZ |
2641 | } |
2642 | } | |
2643 | ||
0fe02759 VS |
2644 | // ---------------------------------------------------------------------------- |
2645 | // focus handling | |
2646 | // ---------------------------------------------------------------------------- | |
2647 | ||
2648 | /*static*/ wxWindow* wxWindowBase::FindFocus() | |
2649 | { | |
9c52a429 | 2650 | wxWindowBase *win = DoFindFocus(); |
0fe02759 VS |
2651 | return win ? win->GetMainWindowOfCompositeControl() : NULL; |
2652 | } | |
2653 | ||
33b494d6 VZ |
2654 | // ---------------------------------------------------------------------------- |
2655 | // global functions | |
2656 | // ---------------------------------------------------------------------------- | |
2657 | ||
2658 | wxWindow* wxGetTopLevelParent(wxWindow *win) | |
2659 | { | |
2660 | while ( win && !win->IsTopLevel() ) | |
2661 | win = win->GetParent(); | |
2662 | ||
2663 | return win; | |
2664 | } | |
2665 | ||
ed5317e5 JS |
2666 | #if wxUSE_ACCESSIBILITY |
2667 | // ---------------------------------------------------------------------------- | |
2668 | // accessible object for windows | |
2669 | // ---------------------------------------------------------------------------- | |
2670 | ||
2671 | // Can return either a child object, or an integer | |
2672 | // representing the child element, starting from 1. | |
66b9ec3d | 2673 | wxAccStatus wxWindowAccessible::HitTest(const wxPoint& WXUNUSED(pt), int* WXUNUSED(childId), wxAccessible** WXUNUSED(childObject)) |
ed5317e5 JS |
2674 | { |
2675 | wxASSERT( GetWindow() != NULL ); | |
2676 | if (!GetWindow()) | |
2677 | return wxACC_FAIL; | |
2678 | ||
2679 | return wxACC_NOT_IMPLEMENTED; | |
2680 | } | |
2681 | ||
2682 | // Returns the rectangle for this object (id = 0) or a child element (id > 0). | |
2683 | wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId) | |
2684 | { | |
2685 | wxASSERT( GetWindow() != NULL ); | |
2686 | if (!GetWindow()) | |
2687 | return wxACC_FAIL; | |
2688 | ||
c6e2af45 JS |
2689 | wxWindow* win = NULL; |
2690 | if (elementId == 0) | |
2691 | { | |
2692 | win = GetWindow(); | |
2693 | } | |
2694 | else | |
2695 | { | |
2696 | if (elementId <= (int) GetWindow()->GetChildren().GetCount()) | |
2697 | { | |
ee6eb8d8 | 2698 | win = GetWindow()->GetChildren().Item(elementId-1)->GetData(); |
c6e2af45 JS |
2699 | } |
2700 | else | |
2701 | return wxACC_FAIL; | |
2702 | } | |
2703 | if (win) | |
2704 | { | |
2705 | rect = win->GetRect(); | |
2706 | if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow))) | |
2707 | rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition())); | |
2708 | return wxACC_OK; | |
2709 | } | |
2710 | ||
ed5317e5 JS |
2711 | return wxACC_NOT_IMPLEMENTED; |
2712 | } | |
2713 | ||
2714 | // Navigates from fromId to toId/toObject. | |
2715 | wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId, | |
66b9ec3d | 2716 | int* WXUNUSED(toId), wxAccessible** toObject) |
ed5317e5 JS |
2717 | { |
2718 | wxASSERT( GetWindow() != NULL ); | |
2719 | if (!GetWindow()) | |
2720 | return wxACC_FAIL; | |
2721 | ||
c6e2af45 JS |
2722 | switch (navDir) |
2723 | { | |
2724 | case wxNAVDIR_FIRSTCHILD: | |
2725 | { | |
2726 | if (GetWindow()->GetChildren().GetCount() == 0) | |
2727 | return wxACC_FALSE; | |
2728 | wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData(); | |
2729 | *toObject = childWindow->GetOrCreateAccessible(); | |
2730 | ||
2731 | return wxACC_OK; | |
2732 | } | |
2733 | case wxNAVDIR_LASTCHILD: | |
2734 | { | |
2735 | if (GetWindow()->GetChildren().GetCount() == 0) | |
2736 | return wxACC_FALSE; | |
2737 | wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData(); | |
2738 | *toObject = childWindow->GetOrCreateAccessible(); | |
2739 | ||
2740 | return wxACC_OK; | |
2741 | } | |
2742 | case wxNAVDIR_RIGHT: | |
2743 | case wxNAVDIR_DOWN: | |
2744 | case wxNAVDIR_NEXT: | |
2745 | { | |
ee6eb8d8 MB |
2746 | wxWindowList::compatibility_iterator node = |
2747 | wxWindowList::compatibility_iterator(); | |
c6e2af45 JS |
2748 | if (fromId == 0) |
2749 | { | |
2750 | // Can't navigate to sibling of this window | |
2751 | // if we're a top-level window. | |
2752 | if (!GetWindow()->GetParent()) | |
2753 | return wxACC_NOT_IMPLEMENTED; | |
2754 | ||
2755 | node = GetWindow()->GetParent()->GetChildren().Find(GetWindow()); | |
2756 | } | |
2757 | else | |
2758 | { | |
2759 | if (fromId <= (int) GetWindow()->GetChildren().GetCount()) | |
33b3f7c3 | 2760 | node = GetWindow()->GetChildren().Item(fromId-1); |
c6e2af45 JS |
2761 | } |
2762 | ||
2763 | if (node && node->GetNext()) | |
2764 | { | |
ee6eb8d8 | 2765 | wxWindow* nextWindow = node->GetNext()->GetData(); |
c6e2af45 JS |
2766 | *toObject = nextWindow->GetOrCreateAccessible(); |
2767 | return wxACC_OK; | |
2768 | } | |
2769 | else | |
2770 | return wxACC_FALSE; | |
2771 | } | |
2772 | case wxNAVDIR_LEFT: | |
2773 | case wxNAVDIR_UP: | |
2774 | case wxNAVDIR_PREVIOUS: | |
2775 | { | |
ee6eb8d8 MB |
2776 | wxWindowList::compatibility_iterator node = |
2777 | wxWindowList::compatibility_iterator(); | |
c6e2af45 JS |
2778 | if (fromId == 0) |
2779 | { | |
2780 | // Can't navigate to sibling of this window | |
2781 | // if we're a top-level window. | |
2782 | if (!GetWindow()->GetParent()) | |
2783 | return wxACC_NOT_IMPLEMENTED; | |
2784 | ||
2785 | node = GetWindow()->GetParent()->GetChildren().Find(GetWindow()); | |
2786 | } | |
2787 | else | |
2788 | { | |
2789 | if (fromId <= (int) GetWindow()->GetChildren().GetCount()) | |
33b3f7c3 | 2790 | node = GetWindow()->GetChildren().Item(fromId-1); |
c6e2af45 JS |
2791 | } |
2792 | ||
2793 | if (node && node->GetPrevious()) | |
2794 | { | |
ee6eb8d8 | 2795 | wxWindow* previousWindow = node->GetPrevious()->GetData(); |
c6e2af45 JS |
2796 | *toObject = previousWindow->GetOrCreateAccessible(); |
2797 | return wxACC_OK; | |
2798 | } | |
2799 | else | |
2800 | return wxACC_FALSE; | |
2801 | } | |
2802 | } | |
2803 | ||
ed5317e5 JS |
2804 | return wxACC_NOT_IMPLEMENTED; |
2805 | } | |
2806 | ||
2807 | // Gets the name of the specified object. | |
2808 | wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name) | |
2809 | { | |
2810 | wxASSERT( GetWindow() != NULL ); | |
2811 | if (!GetWindow()) | |
2812 | return wxACC_FAIL; | |
2813 | ||
2aefc528 JS |
2814 | wxString title; |
2815 | ||
77ffb593 | 2816 | // If a child, leave wxWidgets to call the function on the actual |
2aefc528 JS |
2817 | // child object. |
2818 | if (childId > 0) | |
2819 | return wxACC_NOT_IMPLEMENTED; | |
2820 | ||
2821 | // This will eventually be replaced by specialised | |
77ffb593 | 2822 | // accessible classes, one for each kind of wxWidgets |
2aefc528 | 2823 | // control or window. |
0b4f47a3 | 2824 | #if wxUSE_BUTTON |
2aefc528 JS |
2825 | if (GetWindow()->IsKindOf(CLASSINFO(wxButton))) |
2826 | title = ((wxButton*) GetWindow())->GetLabel(); | |
2827 | else | |
0b4f47a3 | 2828 | #endif |
2aefc528 | 2829 | title = GetWindow()->GetName(); |
e11f4636 | 2830 | |
ba889513 | 2831 | if (!title.empty()) |
ed5317e5 JS |
2832 | { |
2833 | *name = title; | |
2834 | return wxACC_OK; | |
2835 | } | |
2836 | else | |
2837 | return wxACC_NOT_IMPLEMENTED; | |
2838 | } | |
2839 | ||
2840 | // Gets the number of children. | |
2841 | wxAccStatus wxWindowAccessible::GetChildCount(int* childId) | |
2842 | { | |
2843 | wxASSERT( GetWindow() != NULL ); | |
2844 | if (!GetWindow()) | |
2845 | return wxACC_FAIL; | |
2846 | ||
2847 | *childId = (int) GetWindow()->GetChildren().GetCount(); | |
2848 | return wxACC_OK; | |
2849 | } | |
2850 | ||
2851 | // Gets the specified child (starting from 1). | |
2852 | // If *child is NULL and return value is wxACC_OK, | |
2853 | // this means that the child is a simple element and | |
2854 | // not an accessible object. | |
2855 | wxAccStatus wxWindowAccessible::GetChild(int childId, wxAccessible** child) | |
2856 | { | |
2857 | wxASSERT( GetWindow() != NULL ); | |
2858 | if (!GetWindow()) | |
2859 | return wxACC_FAIL; | |
2860 | ||
2861 | if (childId == 0) | |
2862 | { | |
2863 | *child = this; | |
2864 | return wxACC_OK; | |
2865 | } | |
2866 | ||
2867 | if (childId > (int) GetWindow()->GetChildren().GetCount()) | |
2868 | return wxACC_FAIL; | |
2869 | ||
ee6eb8d8 | 2870 | wxWindow* childWindow = GetWindow()->GetChildren().Item(childId-1)->GetData(); |
ed5317e5 JS |
2871 | *child = childWindow->GetOrCreateAccessible(); |
2872 | if (*child) | |
2873 | return wxACC_OK; | |
2874 | else | |
2875 | return wxACC_FAIL; | |
2876 | } | |
2877 | ||
2878 | // Gets the parent, or NULL. | |
2879 | wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent) | |
2880 | { | |
2881 | wxASSERT( GetWindow() != NULL ); | |
2882 | if (!GetWindow()) | |
2883 | return wxACC_FAIL; | |
2884 | ||
2885 | wxWindow* parentWindow = GetWindow()->GetParent(); | |
c6e2af45 | 2886 | if (!parentWindow) |
ed5317e5 JS |
2887 | { |
2888 | *parent = NULL; | |
2889 | return wxACC_OK; | |
2890 | } | |
2891 | else | |
2892 | { | |
2893 | *parent = parentWindow->GetOrCreateAccessible(); | |
2894 | if (*parent) | |
2895 | return wxACC_OK; | |
2896 | else | |
2897 | return wxACC_FAIL; | |
2898 | } | |
2899 | } | |
2900 | ||
2901 | // Performs the default action. childId is 0 (the action for this object) | |
2902 | // or > 0 (the action for a child). | |
2903 | // Return wxACC_NOT_SUPPORTED if there is no default action for this | |
2904 | // window (e.g. an edit control). | |
66b9ec3d | 2905 | wxAccStatus wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId)) |
ed5317e5 JS |
2906 | { |
2907 | wxASSERT( GetWindow() != NULL ); | |
2908 | if (!GetWindow()) | |
2909 | return wxACC_FAIL; | |
2910 | ||
2911 | return wxACC_NOT_IMPLEMENTED; | |
2912 | } | |
2913 | ||
2914 | // Gets the default action for this object (0) or > 0 (the action for a child). | |
2915 | // Return wxACC_OK even if there is no action. actionName is the action, or the empty | |
2916 | // string if there is no action. | |
2917 | // The retrieved string describes the action that is performed on an object, | |
2918 | // not what the object does as a result. For example, a toolbar button that prints | |
2919 | // a document has a default action of "Press" rather than "Prints the current document." | |
66b9ec3d | 2920 | wxAccStatus wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId), wxString* WXUNUSED(actionName)) |
ed5317e5 JS |
2921 | { |
2922 | wxASSERT( GetWindow() != NULL ); | |
2923 | if (!GetWindow()) | |
2924 | return wxACC_FAIL; | |
2925 | ||
2926 | return wxACC_NOT_IMPLEMENTED; | |
2927 | } | |
2928 | ||
2929 | // Returns the description for this object or a child. | |
66b9ec3d | 2930 | wxAccStatus wxWindowAccessible::GetDescription(int WXUNUSED(childId), wxString* description) |
ed5317e5 JS |
2931 | { |
2932 | wxASSERT( GetWindow() != NULL ); | |
2933 | if (!GetWindow()) | |
2934 | return wxACC_FAIL; | |
2935 | ||
dc6588e7 | 2936 | wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard)); |
ba889513 | 2937 | if (!ht.empty()) |
2aefc528 JS |
2938 | { |
2939 | *description = ht; | |
2940 | return wxACC_OK; | |
2941 | } | |
ed5317e5 JS |
2942 | return wxACC_NOT_IMPLEMENTED; |
2943 | } | |
2944 | ||
2945 | // Returns help text for this object or a child, similar to tooltip text. | |
66b9ec3d | 2946 | wxAccStatus wxWindowAccessible::GetHelpText(int WXUNUSED(childId), wxString* helpText) |
ed5317e5 JS |
2947 | { |
2948 | wxASSERT( GetWindow() != NULL ); | |
2949 | if (!GetWindow()) | |
2950 | return wxACC_FAIL; | |
2951 | ||
dc6588e7 | 2952 | wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard)); |
ba889513 | 2953 | if (!ht.empty()) |
ed5317e5 JS |
2954 | { |
2955 | *helpText = ht; | |
2956 | return wxACC_OK; | |
2957 | } | |
2958 | return wxACC_NOT_IMPLEMENTED; | |
2959 | } | |
2960 | ||
2961 | // Returns the keyboard shortcut for this object or child. | |
2962 | // Return e.g. ALT+K | |
66b9ec3d | 2963 | wxAccStatus wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId), wxString* WXUNUSED(shortcut)) |
ed5317e5 JS |
2964 | { |
2965 | wxASSERT( GetWindow() != NULL ); | |
2966 | if (!GetWindow()) | |
2967 | return wxACC_FAIL; | |
2968 | ||
2969 | return wxACC_NOT_IMPLEMENTED; | |
2970 | } | |
2971 | ||
2972 | // Returns a role constant. | |
2973 | wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role) | |
2974 | { | |
2975 | wxASSERT( GetWindow() != NULL ); | |
2976 | if (!GetWindow()) | |
2977 | return wxACC_FAIL; | |
2978 | ||
77ffb593 | 2979 | // If a child, leave wxWidgets to call the function on the actual |
2aefc528 JS |
2980 | // child object. |
2981 | if (childId > 0) | |
2982 | return wxACC_NOT_IMPLEMENTED; | |
2983 | ||
2984 | if (GetWindow()->IsKindOf(CLASSINFO(wxControl))) | |
2985 | return wxACC_NOT_IMPLEMENTED; | |
2986 | #if wxUSE_STATUSBAR | |
2987 | if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar))) | |
2988 | return wxACC_NOT_IMPLEMENTED; | |
2989 | #endif | |
2990 | #if wxUSE_TOOLBAR | |
2991 | if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar))) | |
2992 | return wxACC_NOT_IMPLEMENTED; | |
2993 | #endif | |
2994 | ||
2995 | //*role = wxROLE_SYSTEM_CLIENT; | |
2996 | *role = wxROLE_SYSTEM_CLIENT; | |
2997 | return wxACC_OK; | |
2998 | ||
66b9ec3d | 2999 | #if 0 |
ed5317e5 | 3000 | return wxACC_NOT_IMPLEMENTED; |
66b9ec3d | 3001 | #endif |
ed5317e5 JS |
3002 | } |
3003 | ||
3004 | // Returns a state constant. | |
3005 | wxAccStatus wxWindowAccessible::GetState(int childId, long* state) | |
3006 | { | |
3007 | wxASSERT( GetWindow() != NULL ); | |
3008 | if (!GetWindow()) | |
3009 | return wxACC_FAIL; | |
3010 | ||
77ffb593 | 3011 | // If a child, leave wxWidgets to call the function on the actual |
2aefc528 JS |
3012 | // child object. |
3013 | if (childId > 0) | |
3014 | return wxACC_NOT_IMPLEMENTED; | |
3015 | ||
3016 | if (GetWindow()->IsKindOf(CLASSINFO(wxControl))) | |
3017 | return wxACC_NOT_IMPLEMENTED; | |
3018 | ||
3019 | #if wxUSE_STATUSBAR | |
3020 | if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar))) | |
3021 | return wxACC_NOT_IMPLEMENTED; | |
3022 | #endif | |
3023 | #if wxUSE_TOOLBAR | |
3024 | if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar))) | |
3025 | return wxACC_NOT_IMPLEMENTED; | |
3026 | #endif | |
3027 | ||
3028 | *state = 0; | |
3029 | return wxACC_OK; | |
3030 | ||
66b9ec3d | 3031 | #if 0 |
ed5317e5 | 3032 | return wxACC_NOT_IMPLEMENTED; |
66b9ec3d | 3033 | #endif |
ed5317e5 JS |
3034 | } |
3035 | ||
3036 | // Returns a localized string representing the value for the object | |
3037 | // or child. | |
66b9ec3d | 3038 | wxAccStatus wxWindowAccessible::GetValue(int WXUNUSED(childId), wxString* WXUNUSED(strValue)) |
ed5317e5 JS |
3039 | { |
3040 | wxASSERT( GetWindow() != NULL ); | |
3041 | if (!GetWindow()) | |
3042 | return wxACC_FAIL; | |
3043 | ||
3044 | return wxACC_NOT_IMPLEMENTED; | |
3045 | } | |
3046 | ||
3047 | // Selects the object or child. | |
66b9ec3d | 3048 | wxAccStatus wxWindowAccessible::Select(int WXUNUSED(childId), wxAccSelectionFlags WXUNUSED(selectFlags)) |
ed5317e5 JS |
3049 | { |
3050 | wxASSERT( GetWindow() != NULL ); | |
3051 | if (!GetWindow()) | |
3052 | return wxACC_FAIL; | |
3053 | ||
3054 | return wxACC_NOT_IMPLEMENTED; | |
3055 | } | |
3056 | ||
3057 | // Gets the window with the keyboard focus. | |
3058 | // If childId is 0 and child is NULL, no object in | |
3059 | // this subhierarchy has the focus. | |
3060 | // If this object has the focus, child should be 'this'. | |
66b9ec3d | 3061 | wxAccStatus wxWindowAccessible::GetFocus(int* WXUNUSED(childId), wxAccessible** WXUNUSED(child)) |
ed5317e5 JS |
3062 | { |
3063 | wxASSERT( GetWindow() != NULL ); | |
3064 | if (!GetWindow()) | |
3065 | return wxACC_FAIL; | |
3066 | ||
3067 | return wxACC_NOT_IMPLEMENTED; | |
3068 | } | |
3069 | ||
ca5c6ac3 | 3070 | #if wxUSE_VARIANT |
ed5317e5 JS |
3071 | // Gets a variant representing the selected children |
3072 | // of this object. | |
3073 | // Acceptable values: | |
cab1a605 | 3074 | // - a null variant (IsNull() returns true) |
ed5317e5 JS |
3075 | // - a list variant (GetType() == wxT("list") |
3076 | // - an integer representing the selected child element, | |
3077 | // or 0 if this object is selected (GetType() == wxT("long") | |
3078 | // - a "void*" pointer to a wxAccessible child object | |
66b9ec3d | 3079 | wxAccStatus wxWindowAccessible::GetSelections(wxVariant* WXUNUSED(selections)) |
ed5317e5 JS |
3080 | { |
3081 | wxASSERT( GetWindow() != NULL ); | |
3082 | if (!GetWindow()) | |
3083 | return wxACC_FAIL; | |
3084 | ||
3085 | return wxACC_NOT_IMPLEMENTED; | |
3086 | } | |
ca5c6ac3 | 3087 | #endif // wxUSE_VARIANT |
ed5317e5 JS |
3088 | |
3089 | #endif // wxUSE_ACCESSIBILITY | |
978af864 VZ |
3090 | |
3091 | // ---------------------------------------------------------------------------- | |
3092 | // RTL support | |
3093 | // ---------------------------------------------------------------------------- | |
3094 | ||
3095 | wxCoord | |
3096 | wxWindowBase::AdjustForLayoutDirection(wxCoord x, | |
3097 | wxCoord width, | |
3098 | wxCoord widthTotal) const | |
3099 | { | |
3100 | if ( GetLayoutDirection() == wxLayout_RightToLeft ) | |
3101 | { | |
3102 | x = widthTotal - x - width; | |
3103 | } | |
3104 | ||
3105 | return x; | |
3106 | } | |
3107 |