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