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