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