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