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