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