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