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