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