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