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