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