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