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