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