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