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