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