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