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