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