1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        common/window.cpp 
   3 // Purpose:     common (to all ports) wxWindow functions 
   4 // Author:      Julian Smart, Vadim Zeitlin 
   8 // Copyright:   (c) wxWidgets team 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  21     #pragma implementation "windowbase.h" 
  24 // For compilers that support precompilation, includes "wx.h". 
  25 #include "wx/wxprec.h" 
  32     #include "wx/string.h" 
  37     #include "wx/window.h" 
  38     #include "wx/control.h" 
  39     #include "wx/checkbox.h" 
  40     #include "wx/radiobut.h" 
  41     #include "wx/statbox.h" 
  42     #include "wx/textctrl.h" 
  43     #include "wx/settings.h" 
  44     #include "wx/dialog.h" 
  45     #include "wx/msgdlg.h" 
  46     #include "wx/statusbr.h" 
  47     #include "wx/dcclient.h" 
  50 #if defined(__WXMAC__) && wxUSE_SCROLLBAR 
  51     #include "wx/scrolbar.h" 
  55     #include "wx/layout.h" 
  56 #endif // wxUSE_CONSTRAINTS 
  60 #if wxUSE_DRAG_AND_DROP 
  62 #endif // wxUSE_DRAG_AND_DROP 
  64 #if wxUSE_ACCESSIBILITY 
  65     #include "wx/access.h" 
  69     #include "wx/cshelp.h" 
  73     #include "wx/tooltip.h" 
  74 #endif // wxUSE_TOOLTIPS 
  80 #if wxUSE_SYSTEM_OPTIONS 
  81     #include "wx/sysopt.h" 
  84 // ---------------------------------------------------------------------------- 
  86 // ---------------------------------------------------------------------------- 
  89 int wxWindowBase::ms_lastControlId 
= 2000; 
  91 int wxWindowBase::ms_lastControlId 
= -200; 
  94 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
) 
  96 // ---------------------------------------------------------------------------- 
  98 // ---------------------------------------------------------------------------- 
 100 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
) 
 101     EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
) 
 102     EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
) 
 103     EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
) 
 106     EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
) 
 111 // ============================================================================ 
 112 // implementation of the common functionality of the wxWindow class 
 113 // ============================================================================ 
 115 // ---------------------------------------------------------------------------- 
 117 // ---------------------------------------------------------------------------- 
 119 // the default initialization 
 120 wxWindowBase::wxWindowBase() 
 122     // no window yet, no parent nor children 
 123     m_parent 
= (wxWindow 
*)NULL
; 
 124     m_windowId 
= wxID_ANY
; 
 126     // no constraints on the minimal window size 
 128     m_maxWidth 
= wxDefaultCoord
; 
 130     m_maxHeight 
= wxDefaultCoord
; 
 132     // invalidiated cache value 
 133     m_bestSizeCache 
= wxDefaultSize
; 
 135     // window are created enabled and visible by default 
 139     // the default event handler is just this window 
 140     m_eventHandler 
= this; 
 144     m_windowValidator 
= (wxValidator 
*) NULL
; 
 145 #endif // wxUSE_VALIDATORS 
 147     // the colours/fonts are default for now, so leave m_font, 
 148     // m_backgroundColour and m_foregroundColour uninitialized and set those 
 154     m_inheritFont 
= false; 
 160     m_backgroundStyle 
= wxBG_STYLE_SYSTEM
; 
 162 #if wxUSE_CONSTRAINTS 
 163     // no constraints whatsoever 
 164     m_constraints 
= (wxLayoutConstraints 
*) NULL
; 
 165     m_constraintsInvolvedIn 
= (wxWindowList 
*) NULL
; 
 166 #endif // wxUSE_CONSTRAINTS 
 168     m_windowSizer 
= (wxSizer 
*) NULL
; 
 169     m_containingSizer 
= (wxSizer 
*) NULL
; 
 170     m_autoLayout 
= false; 
 172 #if wxUSE_DRAG_AND_DROP 
 173     m_dropTarget 
= (wxDropTarget 
*)NULL
; 
 174 #endif // wxUSE_DRAG_AND_DROP 
 177     m_tooltip 
= (wxToolTip 
*)NULL
; 
 178 #endif // wxUSE_TOOLTIPS 
 181     m_caret 
= (wxCaret 
*)NULL
; 
 182 #endif // wxUSE_CARET 
 185     m_hasCustomPalette 
= false; 
 186 #endif // wxUSE_PALETTE 
 188 #if wxUSE_ACCESSIBILITY 
 192     m_virtualSize 
= wxDefaultSize
; 
 195     m_maxVirtualWidth 
= wxDefaultCoord
; 
 197     m_maxVirtualHeight 
= wxDefaultCoord
; 
 199     m_windowVariant 
= wxWINDOW_VARIANT_NORMAL
; 
 200 #if wxUSE_SYSTEM_OPTIONS 
 201     if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) ) 
 203        m_windowVariant 
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT 
) ; 
 207     // Whether we're using the current theme for this window (wxGTK only for now) 
 208     m_themeEnabled 
= false; 
 210     // VZ: this one shouldn't exist... 
 211     m_isBeingDeleted 
= false; 
 214 // common part of window creation process 
 215 bool wxWindowBase::CreateBase(wxWindowBase 
*parent
, 
 217                               const wxPoint
& WXUNUSED(pos
), 
 218                               const wxSize
& WXUNUSED(size
), 
 220                               const wxValidator
& wxVALIDATOR_PARAM(validator
), 
 221                               const wxString
& name
) 
 224     // wxGTK doesn't allow to create controls with static box as the parent so 
 225     // this will result in a crash when the program is ported to wxGTK so warn 
 228     // if you get this assert, the correct solution is to create the controls 
 229     // as siblings of the static box 
 230     wxASSERT_MSG( !parent 
|| !wxDynamicCast(parent
, wxStaticBox
), 
 231                   _T("wxStaticBox can't be used as a window parent!") ); 
 232 #endif // wxUSE_STATBOX 
 234     // ids are limited to 16 bits under MSW so if you care about portability, 
 235     // it's not a good idea to use ids out of this range (and negative ids are 
 236     // reserved for wxWidgets own usage) 
 237     wxASSERT_MSG( id 
== wxID_ANY 
|| (id 
>= 0 && id 
< 32767), 
 238                   _T("invalid id value") ); 
 240     // generate a new id if the user doesn't care about it 
 241     m_windowId 
= id 
== wxID_ANY 
? NewControlId() : id
; 
 244     SetWindowStyleFlag(style
); 
 248     SetValidator(validator
); 
 249 #endif // wxUSE_VALIDATORS 
 251     // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to 
 252     // have it too - like this it's possible to set it only in the top level 
 253     // dialog/frame and all children will inherit it by defult 
 254     if ( parent 
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) ) 
 256         SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
); 
 262 // ---------------------------------------------------------------------------- 
 264 // ---------------------------------------------------------------------------- 
 267 wxWindowBase::~wxWindowBase() 
 269     wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") ); 
 271     // FIXME if these 2 cases result from programming errors in the user code 
 272     //       we should probably assert here instead of silently fixing them 
 274     // Just in case the window has been Closed, but we're then deleting 
 275     // immediately: don't leave dangling pointers. 
 276     wxPendingDelete
.DeleteObject(this); 
 278     // Just in case we've loaded a top-level window via LoadNativeDialog but 
 279     // we weren't a dialog class 
 280     wxTopLevelWindows
.DeleteObject((wxWindow
*)this); 
 282     wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") ); 
 284     // reset the dangling pointer our parent window may keep to us 
 287         if ( m_parent
->GetDefaultItem() == this ) 
 289             m_parent
->SetDefaultItem(NULL
); 
 292         m_parent
->RemoveChild(this); 
 297 #endif // wxUSE_CARET 
 300     delete m_windowValidator
; 
 301 #endif // wxUSE_VALIDATORS 
 303 #if wxUSE_CONSTRAINTS 
 304     // Have to delete constraints/sizer FIRST otherwise sizers may try to look 
 305     // at deleted windows as they delete themselves. 
 306     DeleteRelatedConstraints(); 
 310         // This removes any dangling pointers to this window in other windows' 
 311         // constraintsInvolvedIn lists. 
 312         UnsetConstraints(m_constraints
); 
 313         delete m_constraints
; 
 314         m_constraints 
= NULL
; 
 316 #endif // wxUSE_CONSTRAINTS 
 318     if ( m_containingSizer 
) 
 319         m_containingSizer
->Detach( (wxWindow
*)this ); 
 321     delete m_windowSizer
; 
 323 #if wxUSE_DRAG_AND_DROP 
 325 #endif // wxUSE_DRAG_AND_DROP 
 329 #endif // wxUSE_TOOLTIPS 
 331 #if wxUSE_ACCESSIBILITY 
 336 bool wxWindowBase::Destroy() 
 343 bool wxWindowBase::Close(bool force
) 
 345     wxCloseEvent 
event(wxEVT_CLOSE_WINDOW
, m_windowId
); 
 346     event
.SetEventObject(this); 
 347     event
.SetCanVeto(!force
); 
 349     // return false if window wasn't closed because the application vetoed the 
 351     return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto(); 
 354 bool wxWindowBase::DestroyChildren() 
 356     wxWindowList::compatibility_iterator node
; 
 359         // we iterate until the list becomes empty 
 360         node 
= GetChildren().GetFirst(); 
 364         wxWindow 
*child 
= node
->GetData(); 
 366         // note that we really want to call delete and not ->Destroy() here 
 367         // because we want to delete the child immediately, before we are 
 368         // deleted, and delayed deletion would result in problems as our (top 
 369         // level) child could outlive its parent 
 372         wxASSERT_MSG( !GetChildren().Find(child
), 
 373                       wxT("child didn't remove itself using RemoveChild()") ); 
 379 // ---------------------------------------------------------------------------- 
 380 // size/position related methods 
 381 // ---------------------------------------------------------------------------- 
 383 // centre the window with respect to its parent in either (or both) directions 
 384 void wxWindowBase::Centre(int direction
) 
 386     // the position/size of the parent window or of the entire screen 
 388     int widthParent
, heightParent
; 
 390     wxWindow 
*parent 
= NULL
; 
 391     wxTopLevelWindow 
*winTop 
= NULL
; 
 393     if ( !(direction 
& wxCENTRE_ON_SCREEN
) ) 
 395         // find the parent to centre this window on: it should be the 
 396         // immediate parent for the controls but the top level parent for the 
 397         // top level windows (like dialogs) 
 398         parent 
= GetParent(); 
 401             while ( parent 
&& !parent
->IsTopLevel() ) 
 403                 parent 
= parent
->GetParent(); 
 407         // there is no wxTopLevelWindow under wxMotif yet 
 409         // we shouldn't center the dialog on the iconized window: under 
 410         // Windows, for example, this places it completely off the screen 
 413             winTop 
= wxDynamicCast(parent
, wxTopLevelWindow
); 
 414             if ( winTop 
&& winTop
->IsIconized() ) 
 420 #endif // __WXMOTIF__ 
 422         // did we find the parent? 
 426             direction 
|= wxCENTRE_ON_SCREEN
; 
 430     if ( direction 
& wxCENTRE_ON_SCREEN 
) 
 432         // centre with respect to the whole screen 
 433         wxDisplaySize(&widthParent
, &heightParent
); 
 440                 winTop
->GetRectForTopLevelChildren(&posParent
.x
, &posParent
.y
, &widthParent
, &heightParent
); 
 443                 // centre on the parent 
 444                 parent
->GetSize(&widthParent
, &heightParent
); 
 446                 // adjust to the parents position 
 447                 posParent 
= parent
->GetPosition(); 
 452             // centre inside the parents client rectangle 
 453             parent
->GetClientSize(&widthParent
, &heightParent
); 
 458     GetSize(&width
, &height
); 
 460     int xNew 
= wxDefaultCoord
, 
 461         yNew 
= wxDefaultCoord
; 
 463     if ( direction 
& wxHORIZONTAL 
) 
 464         xNew 
= (widthParent 
- width
)/2; 
 466     if ( direction 
& wxVERTICAL 
) 
 467         yNew 
= (heightParent 
- height
)/2; 
 472     // Base size of the visible dimensions of the display 
 473     // to take into account the taskbar. And the Mac menu bar at top. 
 474     wxRect clientrect 
= wxGetClientDisplayRect(); 
 476     // NB: in wxMSW, negative position may not neccessary mean "out of screen", 
 477     //     but it may mean that the window is placed on other than the main 
 478     //     display. Therefore we only make sure centered window is on the main display 
 479     //     if the parent is at least partially present here. 
 480     if (posParent
.x 
+ widthParent 
>= 0)  // if parent is (partially) on the main display 
 482         if (xNew 
< clientrect
.GetLeft()) 
 483             xNew 
= clientrect
.GetLeft(); 
 484         else if (xNew 
+ width 
> clientrect
.GetRight()) 
 485             xNew 
= clientrect
.GetRight() - width
; 
 487     if (posParent
.y 
+ heightParent 
>= 0)  // if parent is (partially) on the main display 
 489         if (yNew 
+ height 
> clientrect
.GetBottom()) 
 490             yNew 
= clientrect
.GetBottom() - height
; 
 492         // Make certain that the title bar is initially visible 
 493         // always, even if this would push the bottom of the 
 494         // dialog off the visible area of the display 
 495         if (yNew 
< clientrect
.GetTop()) 
 496             yNew 
= clientrect
.GetTop(); 
 499     // move the window to this position (keeping the old size but using 
 500     // SetSize() and not Move() to allow xNew and/or yNew to be wxDefaultCoord) 
 501     SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
); 
 504 // fits the window around the children 
 505 void wxWindowBase::Fit() 
 507     if ( GetChildren().GetCount() > 0 ) 
 509         SetClientSize(GetBestSize()); 
 511     //else: do nothing if we have no children 
 514 // fits virtual size (ie. scrolled area etc.) around children 
 515 void wxWindowBase::FitInside() 
 517     if ( GetChildren().GetCount() > 0 ) 
 519         SetVirtualSize( GetBestVirtualSize() ); 
 523 // On Mac, scrollbars are explicitly children. 
 525 static bool wxHasRealChildren(const wxWindowBase
* win
) 
 527     int realChildCount 
= 0; 
 529     for ( wxWindowList::compatibility_iterator node 
= win
->GetChildren().GetFirst(); 
 531           node 
= node
->GetNext() ) 
 533         wxWindow 
*win 
= node
->GetData(); 
 534         if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
))) 
 537     return (realChildCount 
> 0); 
 541 void wxWindowBase::InvalidateBestSize() 
 543     m_bestSizeCache 
= wxDefaultSize
; 
 545     // parent's best size calculation may depend on its children's 
 546     // best sizes, so let's invalidate it as well to be safe: 
 548         m_parent
->InvalidateBestSize(); 
 551 // return the size best suited for the current window 
 552 wxSize 
wxWindowBase::DoGetBestSize() const 
 556         return m_windowSizer
->GetMinSize(); 
 558 #if wxUSE_CONSTRAINTS 
 559     else if ( m_constraints 
) 
 561         wxConstCast(this, wxWindowBase
)->SatisfyConstraints(); 
 563         // our minimal acceptable size is such that all our windows fit inside 
 567         for ( wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
 569               node 
= node
->GetNext() ) 
 571             wxLayoutConstraints 
*c 
= node
->GetData()->GetConstraints(); 
 574                 // it's not normal that we have an unconstrained child, but 
 575                 // what can we do about it? 
 579             int x 
= c
->right
.GetValue(), 
 580                 y 
= c
->bottom
.GetValue(); 
 588             // TODO: we must calculate the overlaps somehow, otherwise we 
 589             //       will never return a size bigger than the current one :-( 
 592         return wxSize(maxX
, maxY
); 
 594 #endif // wxUSE_CONSTRAINTS 
 595     else if ( !GetChildren().empty() 
 597               && wxHasRealChildren(this) 
 601         // our minimal acceptable size is such that all our visible child windows fit inside 
 605         for ( wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
 607               node 
= node
->GetNext() ) 
 609             wxWindow 
*win 
= node
->GetData(); 
 610             if ( win
->IsTopLevel()  || ( ! win
->IsShown() ) 
 612                     || wxDynamicCast(win
, wxStatusBar
) 
 613 #endif // wxUSE_STATUSBAR 
 616                 // dialogs and frames lie in different top level windows - 
 617                 // don't deal with them here; as for the status bars, they 
 618                 // don't lie in the client area at all 
 623             win
->GetPosition(&wx
, &wy
); 
 625             // if the window hadn't been positioned yet, assume that it is in 
 627             if ( wx 
== wxDefaultCoord 
) 
 629             if ( wy 
== wxDefaultCoord 
) 
 632             win
->GetSize(&ww
, &wh
); 
 633             if ( wx 
+ ww 
> maxX 
) 
 635             if ( wy 
+ wh 
> maxY 
) 
 639         // for compatibility with the old versions and because it really looks 
 640         // slightly more pretty like this, add a pad 
 644         return wxSize(maxX
, maxY
); 
 646     else // ! has children 
 648         // for a generic window there is no natural best size - just use either the 
 649         // minimum size if there is one, or the current size 
 650         if ( GetMinSize().IsFullySpecified() ) 
 658 wxSize 
wxWindowBase::GetBestFittingSize() const 
 660     // merge the best size with the min size, giving priority to the min size 
 661     wxSize min 
= GetMinSize(); 
 662     if (min
.x 
== wxDefaultCoord 
|| min
.y 
== wxDefaultCoord
) 
 664         wxSize best 
= GetBestSize(); 
 665         if (min
.x 
== wxDefaultCoord
) min
.x 
=  best
.x
; 
 666         if (min
.y 
== wxDefaultCoord
) min
.y 
=  best
.y
; 
 672 void wxWindowBase::SetBestFittingSize(const wxSize
& size
) 
 674     // Set the min size to the size passed in.  This will usually either be 
 675     // wxDefaultSize or the size passed to this window's ctor/Create function. 
 678     // Merge the size with the best size if needed 
 679     wxSize best 
= GetBestFittingSize(); 
 681     // If the current size doesn't match then change it 
 682     if (GetSize() != best
) 
 687 // by default the origin is not shifted 
 688 wxPoint 
wxWindowBase::GetClientAreaOrigin() const 
 690     return wxPoint(0, 0); 
 693 // set the min/max size of the window 
 694 void wxWindowBase::DoSetSizeHints(int minW
, int minH
, 
 696                                   int WXUNUSED(incW
), int WXUNUSED(incH
)) 
 698     // setting min width greater than max width leads to infinite loops under 
 699     // X11 and generally doesn't make any sense, so don't allow it 
 700     wxCHECK_RET( (minW 
== wxDefaultCoord 
|| maxW 
== wxDefaultCoord 
|| minW 
<= maxW
) && 
 701                     (minH 
== wxDefaultCoord 
|| maxH 
== wxDefaultCoord 
|| minH 
<= maxH
), 
 702                  _T("min width/height must be less than max width/height!") ); 
 710 void wxWindowBase::SetWindowVariant( wxWindowVariant variant 
) 
 712     if ( m_windowVariant 
!= variant 
) 
 714         m_windowVariant 
= variant
; 
 716         DoSetWindowVariant(variant
); 
 720 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant 
) 
 722     // adjust the font height to correspond to our new variant (notice that 
 723     // we're only called if something really changed) 
 724     wxFont font 
= GetFont(); 
 725     int size 
= font
.GetPointSize(); 
 728         case wxWINDOW_VARIANT_NORMAL
: 
 731         case wxWINDOW_VARIANT_SMALL
: 
 736         case wxWINDOW_VARIANT_MINI
: 
 741         case wxWINDOW_VARIANT_LARGE
: 
 747             wxFAIL_MSG(_T("unexpected window variant")); 
 751     font
.SetPointSize(size
); 
 755 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
, 
 758     m_minVirtualWidth 
= minW
; 
 759     m_maxVirtualWidth 
= maxW
; 
 760     m_minVirtualHeight 
= minH
; 
 761     m_maxVirtualHeight 
= maxH
; 
 764 void wxWindowBase::DoSetVirtualSize( int x
, int y 
) 
 766     if ( m_minVirtualWidth 
!= wxDefaultCoord 
&& m_minVirtualWidth 
> x 
) 
 767         x 
= m_minVirtualWidth
; 
 768     if ( m_maxVirtualWidth 
!= wxDefaultCoord 
&& m_maxVirtualWidth 
< x 
) 
 769         x 
= m_maxVirtualWidth
; 
 770     if ( m_minVirtualHeight 
!= wxDefaultCoord 
&& m_minVirtualHeight 
> y 
) 
 771         y 
= m_minVirtualHeight
; 
 772     if ( m_maxVirtualHeight 
!= wxDefaultCoord 
&& m_maxVirtualHeight 
< y 
) 
 773         y 
= m_maxVirtualHeight
; 
 775     m_virtualSize 
= wxSize(x
, y
); 
 778 wxSize 
wxWindowBase::DoGetVirtualSize() const 
 780     wxSize  
s( GetClientSize() ); 
 782     return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ), 
 783                    wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) ); 
 786 // ---------------------------------------------------------------------------- 
 787 // show/hide/enable/disable the window 
 788 // ---------------------------------------------------------------------------- 
 790 bool wxWindowBase::Show(bool show
) 
 792     if ( show 
!= m_isShown 
) 
 804 bool wxWindowBase::Enable(bool enable
) 
 806     if ( enable 
!= m_isEnabled 
) 
 808         m_isEnabled 
= enable
; 
 817 // ---------------------------------------------------------------------------- 
 819 // ---------------------------------------------------------------------------- 
 821 bool wxWindowBase::IsTopLevel() const 
 826 // ---------------------------------------------------------------------------- 
 827 // reparenting the window 
 828 // ---------------------------------------------------------------------------- 
 830 void wxWindowBase::AddChild(wxWindowBase 
*child
) 
 832     wxCHECK_RET( child
, wxT("can't add a NULL child") ); 
 834     // this should never happen and it will lead to a crash later if it does 
 835     // because RemoveChild() will remove only one node from the children list 
 836     // and the other(s) one(s) will be left with dangling pointers in them 
 837     wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") ); 
 839     GetChildren().Append((wxWindow
*)child
); 
 840     child
->SetParent(this); 
 843 void wxWindowBase::RemoveChild(wxWindowBase 
*child
) 
 845     wxCHECK_RET( child
, wxT("can't remove a NULL child") ); 
 847     GetChildren().DeleteObject((wxWindow 
*)child
); 
 848     child
->SetParent(NULL
); 
 851 bool wxWindowBase::Reparent(wxWindowBase 
*newParent
) 
 853     wxWindow 
*oldParent 
= GetParent(); 
 854     if ( newParent 
== oldParent 
) 
 860     // unlink this window from the existing parent. 
 863         oldParent
->RemoveChild(this); 
 867         wxTopLevelWindows
.DeleteObject((wxWindow 
*)this); 
 870     // add it to the new one 
 873         newParent
->AddChild(this); 
 877         wxTopLevelWindows
.Append((wxWindow 
*)this); 
 883 // ---------------------------------------------------------------------------- 
 884 // event handler stuff 
 885 // ---------------------------------------------------------------------------- 
 887 void wxWindowBase::PushEventHandler(wxEvtHandler 
*handler
) 
 889     wxEvtHandler 
*handlerOld 
= GetEventHandler(); 
 891     handler
->SetNextHandler(handlerOld
); 
 894         GetEventHandler()->SetPreviousHandler(handler
); 
 896     SetEventHandler(handler
); 
 899 wxEvtHandler 
*wxWindowBase::PopEventHandler(bool deleteHandler
) 
 901     wxEvtHandler 
*handlerA 
= GetEventHandler(); 
 904         wxEvtHandler 
*handlerB 
= handlerA
->GetNextHandler(); 
 905         handlerA
->SetNextHandler((wxEvtHandler 
*)NULL
); 
 908             handlerB
->SetPreviousHandler((wxEvtHandler 
*)NULL
); 
 909         SetEventHandler(handlerB
); 
 914             handlerA 
= (wxEvtHandler 
*)NULL
; 
 921 bool wxWindowBase::RemoveEventHandler(wxEvtHandler 
*handler
) 
 923     wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") ); 
 925     wxEvtHandler 
*handlerPrev 
= NULL
, 
 926                  *handlerCur 
= GetEventHandler(); 
 929         wxEvtHandler 
*handlerNext 
= handlerCur
->GetNextHandler(); 
 931         if ( handlerCur 
== handler 
) 
 935                 handlerPrev
->SetNextHandler(handlerNext
); 
 939                 SetEventHandler(handlerNext
); 
 944                 handlerNext
->SetPreviousHandler ( handlerPrev 
); 
 947             handler
->SetNextHandler(NULL
); 
 948             handler
->SetPreviousHandler(NULL
); 
 953         handlerPrev 
= handlerCur
; 
 954         handlerCur 
= handlerNext
; 
 957     wxFAIL_MSG( _T("where has the event handler gone?") ); 
 962 // ---------------------------------------------------------------------------- 
 964 // ---------------------------------------------------------------------------- 
 966 void wxWindowBase::InheritAttributes() 
 968     const wxWindowBase 
* const parent 
= GetParent(); 
 972     // we only inherit attributes which had been explicitly set for the parent 
 973     // which ensures that this only happens if the user really wants it and 
 974     // not by default which wouldn't make any sense in modern GUIs where the 
 975     // controls don't all use the same fonts (nor colours) 
 976     if ( parent
->m_inheritFont 
&& !m_hasFont 
) 
 977         SetFont(parent
->GetFont()); 
 979     // in addition, there is a possibility to explicitly forbid inheriting 
 980     // colours at each class level by overriding ShouldInheritColours() 
 981     if ( ShouldInheritColours() ) 
 983         if ( parent
->m_inheritFgCol 
&& !m_hasFgCol 
) 
 984             SetForegroundColour(parent
->GetForegroundColour()); 
 986         if ( parent
->m_inheritBgCol 
&& !m_hasBgCol 
) 
 987             SetBackgroundColour(parent
->GetBackgroundColour()); 
 991 /* static */ wxVisualAttributes
 
 992 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant 
WXUNUSED(variant
)) 
 994     // it is important to return valid values for all attributes from here, 
 995     // GetXXX() below rely on this 
 996     wxVisualAttributes attrs
; 
 997     attrs
.font 
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
); 
 998     attrs
.colFg 
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
); 
 999     attrs
.colBg 
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
); 
1004 wxColour 
wxWindowBase::GetBackgroundColour() const 
1006     if ( !m_backgroundColour
.Ok() ) 
1008         wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") ); 
1010         // get our default background colour 
1011         wxColour colBg 
= GetDefaultAttributes().colBg
; 
1013         // we must return some valid colour to avoid redoing this every time 
1014         // and also to avoid surprizing the applications written for older 
1015         // wxWidgets versions where GetBackgroundColour() always returned 
1016         // something -- so give them something even if it doesn't make sense 
1017         // for this window (e.g. it has a themed background) 
1019             colBg 
= GetClassDefaultAttributes().colBg
; 
1024         return m_backgroundColour
; 
1027 wxColour 
wxWindowBase::GetForegroundColour() const 
1029     // logic is the same as above 
1030     if ( !m_hasFgCol 
&& !m_foregroundColour
.Ok() ) 
1032         wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") ); 
1034         wxColour colFg 
= GetDefaultAttributes().colFg
; 
1037             colFg 
= GetClassDefaultAttributes().colFg
; 
1042         return m_foregroundColour
; 
1045 bool wxWindowBase::SetBackgroundColour( const wxColour 
&colour 
) 
1047     if ( colour 
== m_backgroundColour 
) 
1050     m_hasBgCol 
= colour
.Ok(); 
1051     if ( m_backgroundStyle 
!= wxBG_STYLE_CUSTOM 
) 
1052         m_backgroundStyle 
= m_hasBgCol 
? wxBG_STYLE_COLOUR 
: wxBG_STYLE_SYSTEM
; 
1054     m_inheritBgCol 
= m_hasBgCol
; 
1055     m_backgroundColour 
= colour
; 
1056     SetThemeEnabled( !m_hasBgCol 
&& !m_foregroundColour
.Ok() ); 
1060 bool wxWindowBase::SetForegroundColour( const wxColour 
&colour 
) 
1062     if (colour 
== m_foregroundColour 
) 
1065     m_hasFgCol 
= colour
.Ok(); 
1066     m_inheritFgCol 
= m_hasFgCol
; 
1067     m_foregroundColour 
= colour
; 
1068     SetThemeEnabled( !m_hasFgCol 
&& !m_backgroundColour
.Ok() ); 
1072 bool wxWindowBase::SetCursor(const wxCursor
& cursor
) 
1074     // setting an invalid cursor is ok, it means that we don't have any special 
1076     if ( m_cursor 
== cursor 
) 
1087 wxFont 
wxWindowBase::GetFont() const 
1089     // logic is the same as in GetBackgroundColour() 
1092         wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") ); 
1094         wxFont font 
= GetDefaultAttributes().font
; 
1096             font 
= GetClassDefaultAttributes().font
; 
1104 bool wxWindowBase::SetFont(const wxFont
& font
) 
1106     if ( font 
== m_font 
) 
1113     m_hasFont 
= font
.Ok(); 
1114     m_inheritFont 
= m_hasFont
; 
1116     InvalidateBestSize(); 
1123 void wxWindowBase::SetPalette(const wxPalette
& pal
) 
1125     m_hasCustomPalette 
= true; 
1128     // VZ: can anyone explain me what do we do here? 
1129     wxWindowDC 
d((wxWindow 
*) this); 
1133 wxWindow 
*wxWindowBase::GetAncestorWithCustomPalette() const 
1135     wxWindow 
*win 
= (wxWindow 
*)this; 
1136     while ( win 
&& !win
->HasCustomPalette() ) 
1138         win 
= win
->GetParent(); 
1144 #endif // wxUSE_PALETTE 
1147 void wxWindowBase::SetCaret(wxCaret 
*caret
) 
1158         wxASSERT_MSG( m_caret
->GetWindow() == this, 
1159                       wxT("caret should be created associated to this window") ); 
1162 #endif // wxUSE_CARET 
1164 #if wxUSE_VALIDATORS 
1165 // ---------------------------------------------------------------------------- 
1167 // ---------------------------------------------------------------------------- 
1169 void wxWindowBase::SetValidator(const wxValidator
& validator
) 
1171     if ( m_windowValidator 
) 
1172         delete m_windowValidator
; 
1174     m_windowValidator 
= (wxValidator 
*)validator
.Clone(); 
1176     if ( m_windowValidator 
) 
1177         m_windowValidator
->SetWindow(this); 
1179 #endif // wxUSE_VALIDATORS 
1181 // ---------------------------------------------------------------------------- 
1182 // update region stuff 
1183 // ---------------------------------------------------------------------------- 
1185 wxRect 
wxWindowBase::GetUpdateClientRect() const 
1187     wxRegion rgnUpdate 
= GetUpdateRegion(); 
1188     rgnUpdate
.Intersect(GetClientRect()); 
1189     wxRect rectUpdate 
= rgnUpdate
.GetBox(); 
1190     wxPoint ptOrigin 
= GetClientAreaOrigin(); 
1191     rectUpdate
.x 
-= ptOrigin
.x
; 
1192     rectUpdate
.y 
-= ptOrigin
.y
; 
1197 bool wxWindowBase::IsExposed(int x
, int y
) const 
1199     return m_updateRegion
.Contains(x
, y
) != wxOutRegion
; 
1202 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const 
1204     return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
; 
1207 void wxWindowBase::ClearBackground() 
1209     // wxGTK uses its own version, no need to add never used code 
1211     wxClientDC 
dc((wxWindow 
*)this); 
1212     wxBrush 
brush(GetBackgroundColour(), wxSOLID
); 
1213     dc
.SetBackground(brush
); 
1218 // ---------------------------------------------------------------------------- 
1219 // find child window by id or name 
1220 // ---------------------------------------------------------------------------- 
1222 wxWindow 
*wxWindowBase::FindWindow( long id 
) 
1224     if ( id 
== m_windowId 
) 
1225         return (wxWindow 
*)this; 
1227     wxWindowBase 
*res 
= (wxWindow 
*)NULL
; 
1228     wxWindowList::compatibility_iterator node
; 
1229     for ( node 
= m_children
.GetFirst(); node 
&& !res
; node 
= node
->GetNext() ) 
1231         wxWindowBase 
*child 
= node
->GetData(); 
1232         res 
= child
->FindWindow( id 
); 
1235     return (wxWindow 
*)res
; 
1238 wxWindow 
*wxWindowBase::FindWindow( const wxString
& name 
) 
1240     if ( name 
== m_windowName 
) 
1241         return (wxWindow 
*)this; 
1243     wxWindowBase 
*res 
= (wxWindow 
*)NULL
; 
1244     wxWindowList::compatibility_iterator node
; 
1245     for ( node 
= m_children
.GetFirst(); node 
&& !res
; node 
= node
->GetNext() ) 
1247         wxWindow 
*child 
= node
->GetData(); 
1248         res 
= child
->FindWindow(name
); 
1251     return (wxWindow 
*)res
; 
1255 // find any window by id or name or label: If parent is non-NULL, look through 
1256 // children for a label or title matching the specified string. If NULL, look 
1257 // through all top-level windows. 
1259 // to avoid duplicating code we reuse the same helper function but with 
1260 // different comparators 
1262 typedef bool (*wxFindWindowCmp
)(const wxWindow 
*win
, 
1263                                 const wxString
& label
, long id
); 
1266 bool wxFindWindowCmpLabels(const wxWindow 
*win
, const wxString
& label
, 
1269     return win
->GetLabel() == label
; 
1273 bool wxFindWindowCmpNames(const wxWindow 
*win
, const wxString
& label
, 
1276     return win
->GetName() == label
; 
1280 bool wxFindWindowCmpIds(const wxWindow 
*win
, const wxString
& WXUNUSED(label
), 
1283     return win
->GetId() == id
; 
1286 // recursive helper for the FindWindowByXXX() functions 
1288 wxWindow 
*wxFindWindowRecursively(const wxWindow 
*parent
, 
1289                                   const wxString
& label
, 
1291                                   wxFindWindowCmp cmp
) 
1295         // see if this is the one we're looking for 
1296         if ( (*cmp
)(parent
, label
, id
) ) 
1297             return (wxWindow 
*)parent
; 
1299         // It wasn't, so check all its children 
1300         for ( wxWindowList::compatibility_iterator node 
= parent
->GetChildren().GetFirst(); 
1302               node 
= node
->GetNext() ) 
1304             // recursively check each child 
1305             wxWindow 
*win 
= (wxWindow 
*)node
->GetData(); 
1306             wxWindow 
*retwin 
= wxFindWindowRecursively(win
, label
, id
, cmp
); 
1316 // helper for FindWindowByXXX() 
1318 wxWindow 
*wxFindWindowHelper(const wxWindow 
*parent
, 
1319                              const wxString
& label
, 
1321                              wxFindWindowCmp cmp
) 
1325         // just check parent and all its children 
1326         return wxFindWindowRecursively(parent
, label
, id
, cmp
); 
1329     // start at very top of wx's windows 
1330     for ( wxWindowList::compatibility_iterator node 
= wxTopLevelWindows
.GetFirst(); 
1332           node 
= node
->GetNext() ) 
1334         // recursively check each window & its children 
1335         wxWindow 
*win 
= node
->GetData(); 
1336         wxWindow 
*retwin 
= wxFindWindowRecursively(win
, label
, id
, cmp
); 
1346 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow 
*parent
) 
1348     return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
); 
1353 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow 
*parent
) 
1355     wxWindow 
*win 
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
); 
1359         // fall back to the label 
1360         win 
= FindWindowByLabel(title
, parent
); 
1368 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent 
) 
1370     return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
); 
1373 // ---------------------------------------------------------------------------- 
1374 // dialog oriented functions 
1375 // ---------------------------------------------------------------------------- 
1377 void wxWindowBase::MakeModal(bool modal
) 
1379     // Disable all other windows 
1382         wxWindowList::compatibility_iterator node 
= wxTopLevelWindows
.GetFirst(); 
1385             wxWindow 
*win 
= node
->GetData(); 
1387                 win
->Enable(!modal
); 
1389             node 
= node
->GetNext(); 
1394 bool wxWindowBase::Validate() 
1396 #if wxUSE_VALIDATORS 
1397     bool recurse 
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0; 
1399     wxWindowList::compatibility_iterator node
; 
1400     for ( node 
= m_children
.GetFirst(); node
; node 
= node
->GetNext() ) 
1402         wxWindowBase 
*child 
= node
->GetData(); 
1403         wxValidator 
*validator 
= child
->GetValidator(); 
1404         if ( validator 
&& !validator
->Validate((wxWindow 
*)this) ) 
1409         if ( recurse 
&& !child
->Validate() ) 
1414 #endif // wxUSE_VALIDATORS 
1419 bool wxWindowBase::TransferDataToWindow() 
1421 #if wxUSE_VALIDATORS 
1422     bool recurse 
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0; 
1424     wxWindowList::compatibility_iterator node
; 
1425     for ( node 
= m_children
.GetFirst(); node
; node 
= node
->GetNext() ) 
1427         wxWindowBase 
*child 
= node
->GetData(); 
1428         wxValidator 
*validator 
= child
->GetValidator(); 
1429         if ( validator 
&& !validator
->TransferToWindow() ) 
1431             wxLogWarning(_("Could not transfer data to window")); 
1433             wxLog::FlushActive(); 
1441             if ( !child
->TransferDataToWindow() ) 
1443                 // warning already given 
1448 #endif // wxUSE_VALIDATORS 
1453 bool wxWindowBase::TransferDataFromWindow() 
1455 #if wxUSE_VALIDATORS 
1456     bool recurse 
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0; 
1458     wxWindowList::compatibility_iterator node
; 
1459     for ( node 
= m_children
.GetFirst(); node
; node 
= node
->GetNext() ) 
1461         wxWindow 
*child 
= node
->GetData(); 
1462         wxValidator 
*validator 
= child
->GetValidator(); 
1463         if ( validator 
&& !validator
->TransferFromWindow() ) 
1465             // nop warning here because the application is supposed to give 
1466             // one itself - we don't know here what might have gone wrongly 
1473             if ( !child
->TransferDataFromWindow() ) 
1475                 // warning already given 
1480 #endif // wxUSE_VALIDATORS 
1485 void wxWindowBase::InitDialog() 
1487     wxInitDialogEvent 
event(GetId()); 
1488     event
.SetEventObject( this ); 
1489     GetEventHandler()->ProcessEvent(event
); 
1492 // ---------------------------------------------------------------------------- 
1493 // context-sensitive help support 
1494 // ---------------------------------------------------------------------------- 
1498 // associate this help text with this window 
1499 void wxWindowBase::SetHelpText(const wxString
& text
) 
1501     wxHelpProvider 
*helpProvider 
= wxHelpProvider::Get(); 
1504         helpProvider
->AddHelp(this, text
); 
1508 // associate this help text with all windows with the same id as this 
1510 void wxWindowBase::SetHelpTextForId(const wxString
& text
) 
1512     wxHelpProvider 
*helpProvider 
= wxHelpProvider::Get(); 
1515         helpProvider
->AddHelp(GetId(), text
); 
1519 // get the help string associated with this window (may be empty) 
1520 wxString 
wxWindowBase::GetHelpText() const 
1523     wxHelpProvider 
*helpProvider 
= wxHelpProvider::Get(); 
1526         text 
= helpProvider
->GetHelp(this); 
1532 // show help for this window 
1533 void wxWindowBase::OnHelp(wxHelpEvent
& event
) 
1535     wxHelpProvider 
*helpProvider 
= wxHelpProvider::Get(); 
1538         if ( helpProvider
->ShowHelp(this) ) 
1540             // skip the event.Skip() below 
1548 #endif // wxUSE_HELP 
1550 // ---------------------------------------------------------------------------- 
1551 // tooltipsroot.Replace("\\", "/"); 
1552 // ---------------------------------------------------------------------------- 
1556 void wxWindowBase::SetToolTip( const wxString 
&tip 
) 
1558     // don't create the new tooltip if we already have one 
1561         m_tooltip
->SetTip( tip 
); 
1565         SetToolTip( new wxToolTip( tip 
) ); 
1568     // setting empty tooltip text does not remove the tooltip any more - use 
1569     // SetToolTip((wxToolTip *)NULL) for this 
1572 void wxWindowBase::DoSetToolTip(wxToolTip 
*tooltip
) 
1577     m_tooltip 
= tooltip
; 
1580 #endif // wxUSE_TOOLTIPS 
1582 // ---------------------------------------------------------------------------- 
1583 // constraints and sizers 
1584 // ---------------------------------------------------------------------------- 
1586 #if wxUSE_CONSTRAINTS 
1588 void wxWindowBase::SetConstraints( wxLayoutConstraints 
*constraints 
) 
1590     if ( m_constraints 
) 
1592         UnsetConstraints(m_constraints
); 
1593         delete m_constraints
; 
1595     m_constraints 
= constraints
; 
1596     if ( m_constraints 
) 
1598         // Make sure other windows know they're part of a 'meaningful relationship' 
1599         if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) ) 
1600             m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this); 
1601         if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) ) 
1602             m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this); 
1603         if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) ) 
1604             m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this); 
1605         if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) ) 
1606             m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this); 
1607         if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) ) 
1608             m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this); 
1609         if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) ) 
1610             m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this); 
1611         if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) ) 
1612             m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this); 
1613         if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) ) 
1614             m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this); 
1618 // This removes any dangling pointers to this window in other windows' 
1619 // constraintsInvolvedIn lists. 
1620 void wxWindowBase::UnsetConstraints(wxLayoutConstraints 
*c
) 
1624         if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) ) 
1625             c
->left
.GetOtherWindow()->RemoveConstraintReference(this); 
1626         if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) ) 
1627             c
->top
.GetOtherWindow()->RemoveConstraintReference(this); 
1628         if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) ) 
1629             c
->right
.GetOtherWindow()->RemoveConstraintReference(this); 
1630         if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) ) 
1631             c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this); 
1632         if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) ) 
1633             c
->width
.GetOtherWindow()->RemoveConstraintReference(this); 
1634         if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) ) 
1635             c
->height
.GetOtherWindow()->RemoveConstraintReference(this); 
1636         if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) ) 
1637             c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this); 
1638         if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) ) 
1639             c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this); 
1643 // Back-pointer to other windows we're involved with, so if we delete this 
1644 // window, we must delete any constraints we're involved with. 
1645 void wxWindowBase::AddConstraintReference(wxWindowBase 
*otherWin
) 
1647     if ( !m_constraintsInvolvedIn 
) 
1648         m_constraintsInvolvedIn 
= new wxWindowList
; 
1649     if ( !m_constraintsInvolvedIn
->Find((wxWindow 
*)otherWin
) ) 
1650         m_constraintsInvolvedIn
->Append((wxWindow 
*)otherWin
); 
1653 // REMOVE back-pointer to other windows we're involved with. 
1654 void wxWindowBase::RemoveConstraintReference(wxWindowBase 
*otherWin
) 
1656     if ( m_constraintsInvolvedIn 
) 
1657         m_constraintsInvolvedIn
->DeleteObject((wxWindow 
*)otherWin
); 
1660 // Reset any constraints that mention this window 
1661 void wxWindowBase::DeleteRelatedConstraints() 
1663     if ( m_constraintsInvolvedIn 
) 
1665         wxWindowList::compatibility_iterator node 
= m_constraintsInvolvedIn
->GetFirst(); 
1668             wxWindow 
*win 
= node
->GetData(); 
1669             wxLayoutConstraints 
*constr 
= win
->GetConstraints(); 
1671             // Reset any constraints involving this window 
1674                 constr
->left
.ResetIfWin(this); 
1675                 constr
->top
.ResetIfWin(this); 
1676                 constr
->right
.ResetIfWin(this); 
1677                 constr
->bottom
.ResetIfWin(this); 
1678                 constr
->width
.ResetIfWin(this); 
1679                 constr
->height
.ResetIfWin(this); 
1680                 constr
->centreX
.ResetIfWin(this); 
1681                 constr
->centreY
.ResetIfWin(this); 
1684             wxWindowList::compatibility_iterator next 
= node
->GetNext(); 
1685             m_constraintsInvolvedIn
->Erase(node
); 
1689         delete m_constraintsInvolvedIn
; 
1690         m_constraintsInvolvedIn 
= (wxWindowList 
*) NULL
; 
1694 #endif // wxUSE_CONSTRAINTS 
1696 void wxWindowBase::SetSizer(wxSizer 
*sizer
, bool deleteOld
) 
1698     if ( sizer 
== m_windowSizer
) 
1702         delete m_windowSizer
; 
1704     m_windowSizer 
= sizer
; 
1706     SetAutoLayout( sizer 
!= NULL 
); 
1709 void wxWindowBase::SetSizerAndFit(wxSizer 
*sizer
, bool deleteOld
) 
1711     SetSizer( sizer
, deleteOld 
); 
1712     sizer
->SetSizeHints( (wxWindow
*) this ); 
1716 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
) 
1718     // adding a window to a sizer twice is going to result in fatal and 
1719     // hard to debug problems later because when deleting the second 
1720     // associated wxSizerItem we're going to dereference a dangling 
1721     // pointer; so try to detect this as early as possible 
1722     wxASSERT_MSG( !sizer 
|| m_containingSizer 
!= sizer
, 
1723                   _T("Adding a window to the same sizer twice?") ); 
1725     m_containingSizer 
= sizer
; 
1728 #if wxUSE_CONSTRAINTS 
1730 void wxWindowBase::SatisfyConstraints() 
1732     wxLayoutConstraints 
*constr 
= GetConstraints(); 
1733     bool wasOk 
= constr 
&& constr
->AreSatisfied(); 
1735     ResetConstraints();   // Mark all constraints as unevaluated 
1739     // if we're a top level panel (i.e. our parent is frame/dialog), our 
1740     // own constraints will never be satisfied any more unless we do it 
1744         while ( noChanges 
> 0 ) 
1746             LayoutPhase1(&noChanges
); 
1750     LayoutPhase2(&noChanges
); 
1753 #endif // wxUSE_CONSTRAINTS 
1755 bool wxWindowBase::Layout() 
1757     // If there is a sizer, use it instead of the constraints 
1761         GetVirtualSize(&w
, &h
); 
1762         GetSizer()->SetDimension( 0, 0, w
, h 
); 
1764 #if wxUSE_CONSTRAINTS 
1767         SatisfyConstraints(); // Find the right constraints values 
1768         SetConstraintSizes(); // Recursively set the real window sizes 
1775 #if wxUSE_CONSTRAINTS 
1777 // first phase of the constraints evaluation: set our own constraints 
1778 bool wxWindowBase::LayoutPhase1(int *noChanges
) 
1780     wxLayoutConstraints 
*constr 
= GetConstraints(); 
1782     return !constr 
|| constr
->SatisfyConstraints(this, noChanges
); 
1785 // second phase: set the constraints for our children 
1786 bool wxWindowBase::LayoutPhase2(int *noChanges
) 
1793     // Layout grand children 
1799 // Do a phase of evaluating child constraints 
1800 bool wxWindowBase::DoPhase(int phase
) 
1802     // the list containing the children for which the constraints are already 
1804     wxWindowList succeeded
; 
1806     // the max number of iterations we loop before concluding that we can't set 
1808     static const int maxIterations 
= 500; 
1810     for ( int noIterations 
= 0; noIterations 
< maxIterations
; noIterations
++ ) 
1814         // loop over all children setting their constraints 
1815         for ( wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
1817               node 
= node
->GetNext() ) 
1819             wxWindow 
*child 
= node
->GetData(); 
1820             if ( child
->IsTopLevel() ) 
1822                 // top level children are not inside our client area 
1826             if ( !child
->GetConstraints() || succeeded
.Find(child
) ) 
1828                 // this one is either already ok or nothing we can do about it 
1832             int tempNoChanges 
= 0; 
1833             bool success 
= phase 
== 1 ? child
->LayoutPhase1(&tempNoChanges
) 
1834                                       : child
->LayoutPhase2(&tempNoChanges
); 
1835             noChanges 
+= tempNoChanges
; 
1839                 succeeded
.Append(child
); 
1845             // constraints are set 
1853 void wxWindowBase::ResetConstraints() 
1855     wxLayoutConstraints 
*constr 
= GetConstraints(); 
1858         constr
->left
.SetDone(false); 
1859         constr
->top
.SetDone(false); 
1860         constr
->right
.SetDone(false); 
1861         constr
->bottom
.SetDone(false); 
1862         constr
->width
.SetDone(false); 
1863         constr
->height
.SetDone(false); 
1864         constr
->centreX
.SetDone(false); 
1865         constr
->centreY
.SetDone(false); 
1868     wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
1871         wxWindow 
*win 
= node
->GetData(); 
1872         if ( !win
->IsTopLevel() ) 
1873             win
->ResetConstraints(); 
1874         node 
= node
->GetNext(); 
1878 // Need to distinguish between setting the 'fake' size for windows and sizers, 
1879 // and setting the real values. 
1880 void wxWindowBase::SetConstraintSizes(bool recurse
) 
1882     wxLayoutConstraints 
*constr 
= GetConstraints(); 
1883     if ( constr 
&& constr
->AreSatisfied() ) 
1885         int x 
= constr
->left
.GetValue(); 
1886         int y 
= constr
->top
.GetValue(); 
1887         int w 
= constr
->width
.GetValue(); 
1888         int h 
= constr
->height
.GetValue(); 
1890         if ( (constr
->width
.GetRelationship() != wxAsIs 
) || 
1891              (constr
->height
.GetRelationship() != wxAsIs
) ) 
1893             SetSize(x
, y
, w
, h
); 
1897             // If we don't want to resize this window, just move it... 
1903         wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."), 
1904                    GetClassInfo()->GetClassName(), 
1910         wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
1913             wxWindow 
*win 
= node
->GetData(); 
1914             if ( !win
->IsTopLevel() && win
->GetConstraints() ) 
1915                 win
->SetConstraintSizes(); 
1916             node 
= node
->GetNext(); 
1921 // Only set the size/position of the constraint (if any) 
1922 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
) 
1924     wxLayoutConstraints 
*constr 
= GetConstraints(); 
1927         if ( x 
!= wxDefaultCoord 
) 
1929             constr
->left
.SetValue(x
); 
1930             constr
->left
.SetDone(true); 
1932         if ( y 
!= wxDefaultCoord 
) 
1934             constr
->top
.SetValue(y
); 
1935             constr
->top
.SetDone(true); 
1937         if ( w 
!= wxDefaultCoord 
) 
1939             constr
->width
.SetValue(w
); 
1940             constr
->width
.SetDone(true); 
1942         if ( h 
!= wxDefaultCoord 
) 
1944             constr
->height
.SetValue(h
); 
1945             constr
->height
.SetDone(true); 
1950 void wxWindowBase::MoveConstraint(int x
, int y
) 
1952     wxLayoutConstraints 
*constr 
= GetConstraints(); 
1955         if ( x 
!= wxDefaultCoord 
) 
1957             constr
->left
.SetValue(x
); 
1958             constr
->left
.SetDone(true); 
1960         if ( y 
!= wxDefaultCoord 
) 
1962             constr
->top
.SetValue(y
); 
1963             constr
->top
.SetDone(true); 
1968 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const 
1970     wxLayoutConstraints 
*constr 
= GetConstraints(); 
1973         *w 
= constr
->width
.GetValue(); 
1974         *h 
= constr
->height
.GetValue(); 
1980 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const 
1982     wxLayoutConstraints 
*constr 
= GetConstraints(); 
1985         *w 
= constr
->width
.GetValue(); 
1986         *h 
= constr
->height
.GetValue(); 
1989         GetClientSize(w
, h
); 
1992 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const 
1994     wxLayoutConstraints 
*constr 
= GetConstraints(); 
1997         *x 
= constr
->left
.GetValue(); 
1998         *y 
= constr
->top
.GetValue(); 
2004 #endif // wxUSE_CONSTRAINTS 
2006 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const 
2008     // don't do it for the dialogs/frames - they float independently of their 
2010     if ( !IsTopLevel() ) 
2012         wxWindow 
*parent 
= GetParent(); 
2013         if ( !(sizeFlags 
& wxSIZE_NO_ADJUSTMENTS
) && parent 
) 
2015             wxPoint 
pt(parent
->GetClientAreaOrigin()); 
2022 // ---------------------------------------------------------------------------- 
2023 // do Update UI processing for child controls 
2024 // ---------------------------------------------------------------------------- 
2026 void wxWindowBase::UpdateWindowUI(long flags
) 
2028     wxUpdateUIEvent 
event(GetId()); 
2029     event
.m_eventObject 
= this; 
2031     if ( GetEventHandler()->ProcessEvent(event
) ) 
2033         DoUpdateWindowUI(event
); 
2036     if (flags 
& wxUPDATE_UI_RECURSE
) 
2038         wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
2041             wxWindow
* child 
= (wxWindow
*) node
->GetData(); 
2042             child
->UpdateWindowUI(flags
); 
2043             node 
= node
->GetNext(); 
2048 // do the window-specific processing after processing the update event 
2049 // TODO: take specific knowledge out of this function and 
2050 // put in each control's base class. Unfortunately we don't 
2051 // yet have base implementation files for wxCheckBox and wxRadioButton. 
2052 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
) 
2054     if ( event
.GetSetEnabled() ) 
2055         Enable(event
.GetEnabled()); 
2058     if ( event
.GetSetText() ) 
2060         wxControl 
*control 
= wxDynamicCastThis(wxControl
); 
2063             if ( event
.GetText() != control
->GetLabel() ) 
2064                 control
->SetLabel(event
.GetText()); 
2067 #endif // wxUSE_CONTROLS 
2069     if ( event
.GetSetChecked() ) 
2072         wxCheckBox 
*checkbox 
= wxDynamicCastThis(wxCheckBox
); 
2075             checkbox
->SetValue(event
.GetChecked()); 
2077 #endif // wxUSE_CHECKBOX 
2080         wxRadioButton 
*radiobtn 
= wxDynamicCastThis(wxRadioButton
); 
2083             radiobtn
->SetValue(event
.GetChecked()); 
2085 #endif // wxUSE_RADIOBTN 
2090 // call internal idle recursively 
2091 // may be obsolete (wait until OnIdle scheme stabilises) 
2092 void wxWindowBase::ProcessInternalIdle() 
2096     wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
2099         wxWindow 
*child 
= node
->GetData(); 
2100         child
->ProcessInternalIdle(); 
2101         node 
= node
->GetNext(); 
2106 // ---------------------------------------------------------------------------- 
2107 // dialog units translations 
2108 // ---------------------------------------------------------------------------- 
2110 wxPoint 
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
) 
2112     int charWidth 
= GetCharWidth(); 
2113     int charHeight 
= GetCharHeight(); 
2114     wxPoint pt2 
= wxDefaultPosition
; 
2115     if (pt
.x 
!= wxDefaultCoord
) 
2116         pt2
.x 
= (int) ((pt
.x 
* 4) / charWidth
); 
2117     if (pt
.y 
!= wxDefaultCoord
) 
2118         pt2
.y 
= (int) ((pt
.y 
* 8) / charHeight
); 
2123 wxPoint 
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
) 
2125     int charWidth 
= GetCharWidth(); 
2126     int charHeight 
= GetCharHeight(); 
2127     wxPoint pt2 
= wxDefaultPosition
; 
2128     if (pt
.x 
!= wxDefaultCoord
) 
2129         pt2
.x 
= (int) ((pt
.x 
* charWidth
) / 4); 
2130     if (pt
.y 
!= wxDefaultCoord
) 
2131         pt2
.y 
= (int) ((pt
.y 
* charHeight
) / 8); 
2136 // ---------------------------------------------------------------------------- 
2138 // ---------------------------------------------------------------------------- 
2140 // propagate the colour change event to the subwindows 
2141 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
) 
2143     wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
2146         // Only propagate to non-top-level windows 
2147         wxWindow 
*win 
= node
->GetData(); 
2148         if ( !win
->IsTopLevel() ) 
2150             wxSysColourChangedEvent event2
; 
2151             event
.m_eventObject 
= win
; 
2152             win
->GetEventHandler()->ProcessEvent(event2
); 
2155         node 
= node
->GetNext(); 
2161 // the default action is to populate dialog with data when it's created, 
2162 // and nudge the UI into displaying itself correctly in case 
2163 // we've turned the wxUpdateUIEvents frequency down low. 
2164 void wxWindowBase::OnInitDialog( wxInitDialogEvent 
&WXUNUSED(event
) ) 
2166     TransferDataToWindow(); 
2168     // Update the UI at this point 
2169     UpdateWindowUI(wxUPDATE_UI_RECURSE
); 
2172 // process Ctrl-Alt-mclick 
2173 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event 
) 
2176     if ( event
.ControlDown() && event
.AltDown() ) 
2178         // don't translate these strings 
2181 #ifdef __WXUNIVERSAL__ 
2183 #endif // __WXUNIVERSAL__ 
2185         switch ( wxGetOsVersion() ) 
2187             case wxMOTIF_X
:     port 
+= _T("Motif"); break; 
2189             case wxMAC_DARWIN
:  port 
+= _T("Mac"); break; 
2190             case wxBEOS
:        port 
+= _T("BeOS"); break; 
2194             case wxGTK_BEOS
:    port 
+= _T("GTK"); break; 
2200             case wxWIN386
:      port 
+= _T("MS Windows"); break; 
2204             case wxMGL_OS2
:     port 
+= _T("MGL"); break; 
2206             case wxOS2_PM
:      port 
+= _T("OS/2"); break; 
2207             default:            port 
+= _T("unknown"); break; 
2210         wxMessageBox(wxString::Format( 
2212                                         "       wxWidgets Library (%s port)\nVersion %u.%u.%u%s%s, compiled at %s %s\n   Copyright (c) 1995-2004 wxWidgets team" 
2231                      _T("wxWidgets information"), 
2232                      wxICON_INFORMATION 
| wxOK
, 
2236 #endif // wxUSE_MSGDLG 
2242 // ---------------------------------------------------------------------------- 
2244 // ---------------------------------------------------------------------------- 
2246 #if wxUSE_ACCESSIBILITY 
2247 void wxWindowBase::SetAccessible(wxAccessible
* accessible
) 
2249     if (m_accessible 
&& (accessible 
!= m_accessible
)) 
2250         delete m_accessible
; 
2251     m_accessible 
= accessible
; 
2253         m_accessible
->SetWindow((wxWindow
*) this); 
2256 // Returns the accessible object, creating if necessary. 
2257 wxAccessible
* wxWindowBase::GetOrCreateAccessible() 
2260         m_accessible 
= CreateAccessible(); 
2261     return m_accessible
; 
2264 // Override to create a specific accessible object. 
2265 wxAccessible
* wxWindowBase::CreateAccessible() 
2267     return new wxWindowAccessible((wxWindow
*) this); 
2273 // ---------------------------------------------------------------------------- 
2274 // list classes implementation 
2275 // ---------------------------------------------------------------------------- 
2277 void wxWindowListNode::DeleteData() 
2279     delete (wxWindow 
*)GetData(); 
2283 // ---------------------------------------------------------------------------- 
2285 // ---------------------------------------------------------------------------- 
2287 wxBorder 
wxWindowBase::GetBorder(long flags
) const 
2289     wxBorder border 
= (wxBorder
)(flags 
& wxBORDER_MASK
); 
2290     if ( border 
== wxBORDER_DEFAULT 
) 
2292         border 
= GetDefaultBorder(); 
2298 wxBorder 
wxWindowBase::GetDefaultBorder() const 
2300     return wxBORDER_NONE
; 
2303 // ---------------------------------------------------------------------------- 
2305 // ---------------------------------------------------------------------------- 
2307 wxHitTest 
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const 
2309     // here we just check if the point is inside the window or not 
2311     // check the top and left border first 
2312     bool outside 
= x 
< 0 || y 
< 0; 
2315         // check the right and bottom borders too 
2316         wxSize size 
= GetSize(); 
2317         outside 
= x 
>= size
.x 
|| y 
>= size
.y
; 
2320     return outside 
? wxHT_WINDOW_OUTSIDE 
: wxHT_WINDOW_INSIDE
; 
2323 // ---------------------------------------------------------------------------- 
2325 // ---------------------------------------------------------------------------- 
2327 struct WXDLLEXPORT wxWindowNext
 
2331 } *wxWindowBase::ms_winCaptureNext 
= NULL
; 
2333 void wxWindowBase::CaptureMouse() 
2335     wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this); 
2337     wxWindow 
*winOld 
= GetCapture(); 
2340         ((wxWindowBase
*) winOld
)->DoReleaseMouse(); 
2343         wxWindowNext 
*item 
= new wxWindowNext
; 
2345         item
->next 
= ms_winCaptureNext
; 
2346         ms_winCaptureNext 
= item
; 
2348     //else: no mouse capture to save 
2353 void wxWindowBase::ReleaseMouse() 
2355     wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this); 
2357     wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") ); 
2361     if ( ms_winCaptureNext 
) 
2363         ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse(); 
2365         wxWindowNext 
*item 
= ms_winCaptureNext
; 
2366         ms_winCaptureNext 
= item
->next
; 
2369     //else: stack is empty, no previous capture 
2371     wxLogTrace(_T("mousecapture"), 
2372         (const wxChar 
*) _T("After ReleaseMouse() mouse is captured by %p"), 
2379 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
), 
2380                              int WXUNUSED(modifiers
), 
2381                              int WXUNUSED(keycode
)) 
2387 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
)) 
2393 #endif // wxUSE_HOTKEY 
2395 void wxWindowBase::SendDestroyEvent() 
2397     wxWindowDestroyEvent event
; 
2398     event
.SetEventObject(this); 
2399     event
.SetId(GetId()); 
2400     GetEventHandler()->ProcessEvent(event
); 
2403 // ---------------------------------------------------------------------------- 
2405 // ---------------------------------------------------------------------------- 
2407 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
)) 
2409 #if wxUSE_VALIDATORS 
2410     // Can only use the validator of the window which 
2411     // is receiving the event 
2412     if ( event
.GetEventObject() == this ) 
2414         wxValidator 
*validator 
= GetValidator(); 
2415         if ( validator 
&& validator
->ProcessEvent(event
) ) 
2420 #endif // wxUSE_VALIDATORS 
2425 bool wxWindowBase::TryParent(wxEvent
& event
) 
2427     // carry on up the parent-child hierarchy if the propgation count hasn't 
2429     if ( event
.ShouldPropagate() ) 
2431         // honour the requests to stop propagation at this window: this is 
2432         // used by the dialogs, for example, to prevent processing the events 
2433         // from the dialog controls in the parent frame which rarely, if ever, 
2435         if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) ) 
2437             wxWindow 
*parent 
= GetParent(); 
2438             if ( parent 
&& !parent
->IsBeingDeleted() ) 
2440                 wxPropagateOnce 
propagateOnce(event
); 
2442                 return parent
->GetEventHandler()->ProcessEvent(event
); 
2447     return wxEvtHandler::TryParent(event
); 
2450 // ---------------------------------------------------------------------------- 
2451 // keyboard navigation 
2452 // ---------------------------------------------------------------------------- 
2454 // Navigates in the specified direction. 
2455 bool wxWindowBase::Navigate(int flags
) 
2457     wxNavigationKeyEvent eventNav
; 
2458     eventNav
.SetFlags(flags
); 
2459     eventNav
.SetEventObject(this); 
2460     if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) ) 
2467 void wxWindowBase::DoMoveInTabOrder(wxWindow 
*win
, MoveKind move
) 
2469     // check that we're not a top level window 
2470     wxCHECK_RET( GetParent(), 
2471                     _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") ); 
2473     // detect the special case when we have nothing to do anyhow and when the 
2474     // code below wouldn't work 
2478     // find the target window in the siblings list 
2479     wxWindowList
& siblings 
= GetParent()->GetChildren(); 
2480     wxWindowList::compatibility_iterator i 
= siblings
.Find(win
); 
2481     wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") ); 
2483     // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we 
2484     // can't just move the node around 
2485     wxWindow 
*self 
= (wxWindow 
*)this; 
2486     siblings
.DeleteObject(self
); 
2487     if ( move 
== MoveAfter 
) 
2494         siblings
.Insert(i
, self
); 
2496     else // MoveAfter and win was the last sibling 
2498         siblings
.Append(self
); 
2502 // ---------------------------------------------------------------------------- 
2504 // ---------------------------------------------------------------------------- 
2506 /*static*/ wxWindow
* wxWindowBase::FindFocus() 
2508     wxWindowBase 
*win 
= DoFindFocus(); 
2509     return win 
? win
->GetMainWindowOfCompositeControl() : NULL
; 
2512 // ---------------------------------------------------------------------------- 
2514 // ---------------------------------------------------------------------------- 
2516 wxWindow
* wxGetTopLevelParent(wxWindow 
*win
) 
2518     while ( win 
&& !win
->IsTopLevel() ) 
2519          win 
= win
->GetParent(); 
2524 #if wxUSE_ACCESSIBILITY 
2525 // ---------------------------------------------------------------------------- 
2526 // accessible object for windows 
2527 // ---------------------------------------------------------------------------- 
2529 // Can return either a child object, or an integer 
2530 // representing the child element, starting from 1. 
2531 wxAccStatus 
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
)) 
2533     wxASSERT( GetWindow() != NULL 
); 
2537     return wxACC_NOT_IMPLEMENTED
; 
2540 // Returns the rectangle for this object (id = 0) or a child element (id > 0). 
2541 wxAccStatus 
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
) 
2543     wxASSERT( GetWindow() != NULL 
); 
2547     wxWindow
* win 
= NULL
; 
2554         if (elementId 
<= (int) GetWindow()->GetChildren().GetCount()) 
2556             win 
= GetWindow()->GetChildren().Item(elementId
-1)->GetData(); 
2563         rect 
= win
->GetRect(); 
2564         if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
))) 
2565             rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition())); 
2569     return wxACC_NOT_IMPLEMENTED
; 
2572 // Navigates from fromId to toId/toObject. 
2573 wxAccStatus 
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
, 
2574                              int* WXUNUSED(toId
), wxAccessible
** toObject
) 
2576     wxASSERT( GetWindow() != NULL 
); 
2582     case wxNAVDIR_FIRSTCHILD
: 
2584             if (GetWindow()->GetChildren().GetCount() == 0) 
2586             wxWindow
* childWindow 
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData(); 
2587             *toObject 
= childWindow
->GetOrCreateAccessible(); 
2591     case wxNAVDIR_LASTCHILD
: 
2593             if (GetWindow()->GetChildren().GetCount() == 0) 
2595             wxWindow
* childWindow 
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData(); 
2596             *toObject 
= childWindow
->GetOrCreateAccessible(); 
2600     case wxNAVDIR_RIGHT
: 
2604             wxWindowList::compatibility_iterator node 
= 
2605                 wxWindowList::compatibility_iterator(); 
2608                 // Can't navigate to sibling of this window 
2609                 // if we're a top-level window. 
2610                 if (!GetWindow()->GetParent()) 
2611                     return wxACC_NOT_IMPLEMENTED
; 
2613                 node 
= GetWindow()->GetParent()->GetChildren().Find(GetWindow()); 
2617                 if (fromId 
<= (int) GetWindow()->GetChildren().GetCount()) 
2618                     node 
= GetWindow()->GetChildren().Item(fromId
-1); 
2621             if (node 
&& node
->GetNext()) 
2623                 wxWindow
* nextWindow 
= node
->GetNext()->GetData(); 
2624                 *toObject 
= nextWindow
->GetOrCreateAccessible(); 
2632     case wxNAVDIR_PREVIOUS
: 
2634             wxWindowList::compatibility_iterator node 
= 
2635                 wxWindowList::compatibility_iterator(); 
2638                 // Can't navigate to sibling of this window 
2639                 // if we're a top-level window. 
2640                 if (!GetWindow()->GetParent()) 
2641                     return wxACC_NOT_IMPLEMENTED
; 
2643                 node 
= GetWindow()->GetParent()->GetChildren().Find(GetWindow()); 
2647                 if (fromId 
<= (int) GetWindow()->GetChildren().GetCount()) 
2648                     node 
= GetWindow()->GetChildren().Item(fromId
-1); 
2651             if (node 
&& node
->GetPrevious()) 
2653                 wxWindow
* previousWindow 
= node
->GetPrevious()->GetData(); 
2654                 *toObject 
= previousWindow
->GetOrCreateAccessible(); 
2662     return wxACC_NOT_IMPLEMENTED
; 
2665 // Gets the name of the specified object. 
2666 wxAccStatus 
wxWindowAccessible::GetName(int childId
, wxString
* name
) 
2668     wxASSERT( GetWindow() != NULL 
); 
2674     // If a child, leave wxWidgets to call the function on the actual 
2677         return wxACC_NOT_IMPLEMENTED
; 
2679     // This will eventually be replaced by specialised 
2680     // accessible classes, one for each kind of wxWidgets 
2681     // control or window. 
2683     if (GetWindow()->IsKindOf(CLASSINFO(wxButton
))) 
2684         title 
= ((wxButton
*) GetWindow())->GetLabel(); 
2687         title 
= GetWindow()->GetName(); 
2689     if (!title
.IsEmpty()) 
2695         return wxACC_NOT_IMPLEMENTED
; 
2698 // Gets the number of children. 
2699 wxAccStatus 
wxWindowAccessible::GetChildCount(int* childId
) 
2701     wxASSERT( GetWindow() != NULL 
); 
2705     *childId 
= (int) GetWindow()->GetChildren().GetCount(); 
2709 // Gets the specified child (starting from 1). 
2710 // If *child is NULL and return value is wxACC_OK, 
2711 // this means that the child is a simple element and 
2712 // not an accessible object. 
2713 wxAccStatus 
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
) 
2715     wxASSERT( GetWindow() != NULL 
); 
2725     if (childId 
> (int) GetWindow()->GetChildren().GetCount()) 
2728     wxWindow
* childWindow 
= GetWindow()->GetChildren().Item(childId
-1)->GetData(); 
2729     *child 
= childWindow
->GetOrCreateAccessible(); 
2736 // Gets the parent, or NULL. 
2737 wxAccStatus 
wxWindowAccessible::GetParent(wxAccessible
** parent
) 
2739     wxASSERT( GetWindow() != NULL 
); 
2743     wxWindow
* parentWindow 
= GetWindow()->GetParent(); 
2751         *parent 
= parentWindow
->GetOrCreateAccessible(); 
2759 // Performs the default action. childId is 0 (the action for this object) 
2760 // or > 0 (the action for a child). 
2761 // Return wxACC_NOT_SUPPORTED if there is no default action for this 
2762 // window (e.g. an edit control). 
2763 wxAccStatus 
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
)) 
2765     wxASSERT( GetWindow() != NULL 
); 
2769     return wxACC_NOT_IMPLEMENTED
; 
2772 // Gets the default action for this object (0) or > 0 (the action for a child). 
2773 // Return wxACC_OK even if there is no action. actionName is the action, or the empty 
2774 // string if there is no action. 
2775 // The retrieved string describes the action that is performed on an object, 
2776 // not what the object does as a result. For example, a toolbar button that prints 
2777 // a document has a default action of "Press" rather than "Prints the current document." 
2778 wxAccStatus 
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
)) 
2780     wxASSERT( GetWindow() != NULL 
); 
2784     return wxACC_NOT_IMPLEMENTED
; 
2787 // Returns the description for this object or a child. 
2788 wxAccStatus 
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
) 
2790     wxASSERT( GetWindow() != NULL 
); 
2794     wxString 
ht(GetWindow()->GetHelpText()); 
2800     return wxACC_NOT_IMPLEMENTED
; 
2803 // Returns help text for this object or a child, similar to tooltip text. 
2804 wxAccStatus 
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
) 
2806     wxASSERT( GetWindow() != NULL 
); 
2810     wxString 
ht(GetWindow()->GetHelpText()); 
2816     return wxACC_NOT_IMPLEMENTED
; 
2819 // Returns the keyboard shortcut for this object or child. 
2820 // Return e.g. ALT+K 
2821 wxAccStatus 
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
)) 
2823     wxASSERT( GetWindow() != NULL 
); 
2827     return wxACC_NOT_IMPLEMENTED
; 
2830 // Returns a role constant. 
2831 wxAccStatus 
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
) 
2833     wxASSERT( GetWindow() != NULL 
); 
2837     // If a child, leave wxWidgets to call the function on the actual 
2840         return wxACC_NOT_IMPLEMENTED
; 
2842     if (GetWindow()->IsKindOf(CLASSINFO(wxControl
))) 
2843         return wxACC_NOT_IMPLEMENTED
; 
2845     if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
))) 
2846         return wxACC_NOT_IMPLEMENTED
; 
2849     if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
))) 
2850         return wxACC_NOT_IMPLEMENTED
; 
2853     //*role = wxROLE_SYSTEM_CLIENT; 
2854     *role 
= wxROLE_SYSTEM_CLIENT
; 
2858     return wxACC_NOT_IMPLEMENTED
; 
2862 // Returns a state constant. 
2863 wxAccStatus 
wxWindowAccessible::GetState(int childId
, long* state
) 
2865     wxASSERT( GetWindow() != NULL 
); 
2869     // If a child, leave wxWidgets to call the function on the actual 
2872         return wxACC_NOT_IMPLEMENTED
; 
2874     if (GetWindow()->IsKindOf(CLASSINFO(wxControl
))) 
2875         return wxACC_NOT_IMPLEMENTED
; 
2878     if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
))) 
2879         return wxACC_NOT_IMPLEMENTED
; 
2882     if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
))) 
2883         return wxACC_NOT_IMPLEMENTED
; 
2890     return wxACC_NOT_IMPLEMENTED
; 
2894 // Returns a localized string representing the value for the object 
2896 wxAccStatus 
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
)) 
2898     wxASSERT( GetWindow() != NULL 
); 
2902     return wxACC_NOT_IMPLEMENTED
; 
2905 // Selects the object or child. 
2906 wxAccStatus 
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags 
WXUNUSED(selectFlags
)) 
2908     wxASSERT( GetWindow() != NULL 
); 
2912     return wxACC_NOT_IMPLEMENTED
; 
2915 // Gets the window with the keyboard focus. 
2916 // If childId is 0 and child is NULL, no object in 
2917 // this subhierarchy has the focus. 
2918 // If this object has the focus, child should be 'this'. 
2919 wxAccStatus 
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
)) 
2921     wxASSERT( GetWindow() != NULL 
); 
2925     return wxACC_NOT_IMPLEMENTED
; 
2928 // Gets a variant representing the selected children 
2930 // Acceptable values: 
2931 // - a null variant (IsNull() returns true) 
2932 // - a list variant (GetType() == wxT("list") 
2933 // - an integer representing the selected child element, 
2934 //   or 0 if this object is selected (GetType() == wxT("long") 
2935 // - a "void*" pointer to a wxAccessible child object 
2936 wxAccStatus 
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
)) 
2938     wxASSERT( GetWindow() != NULL 
); 
2942     return wxACC_NOT_IMPLEMENTED
; 
2945 #endif // wxUSE_ACCESSIBILITY