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