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