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