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