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