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