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