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