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