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