1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/string.h"
32 #include "wx/window.h"
33 #include "wx/control.h"
34 #include "wx/checkbox.h"
35 #include "wx/radiobut.h"
36 #include "wx/statbox.h"
37 #include "wx/textctrl.h"
38 #include "wx/settings.h"
39 #include "wx/dialog.h"
40 #include "wx/msgdlg.h"
41 #include "wx/statusbr.h"
42 #include "wx/toolbar.h"
43 #include "wx/dcclient.h"
44 #include "wx/scrolbar.h"
45 #include "wx/layout.h"
49 #if wxUSE_DRAG_AND_DROP
51 #endif // wxUSE_DRAG_AND_DROP
53 #if wxUSE_ACCESSIBILITY
54 #include "wx/access.h"
58 #include "wx/cshelp.h"
62 #include "wx/tooltip.h"
63 #endif // wxUSE_TOOLTIPS
69 #if wxUSE_SYSTEM_OPTIONS
70 #include "wx/sysopt.h"
73 // For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog.
74 // The gtk includes don't pull any other headers in, at least not on my system - MR
77 #include <gtk/gtkversion.h>
79 #include <gtk/gtkfeatures.h>
81 extern const unsigned int gtk_major_version
;
82 extern const unsigned int gtk_minor_version
;
83 extern const unsigned int gtk_micro_version
;
87 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 #if defined(__WXPALMOS__)
94 int wxWindowBase::ms_lastControlId
= 32767;
95 #elif defined(__WXPM__)
96 int wxWindowBase::ms_lastControlId
= 2000;
98 int wxWindowBase::ms_lastControlId
= -200;
101 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
108 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
109 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
110 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
113 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
118 // ============================================================================
119 // implementation of the common functionality of the wxWindow class
120 // ============================================================================
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 // the default initialization
127 wxWindowBase::wxWindowBase()
129 // no window yet, no parent nor children
130 m_parent
= (wxWindow
*)NULL
;
131 m_windowId
= wxID_ANY
;
133 // no constraints on the minimal window size
135 m_maxWidth
= wxDefaultCoord
;
137 m_maxHeight
= wxDefaultCoord
;
139 // invalidiated cache value
140 m_bestSizeCache
= wxDefaultSize
;
142 // window are created enabled and visible by default
146 // the default event handler is just this window
147 m_eventHandler
= this;
151 m_windowValidator
= (wxValidator
*) NULL
;
152 #endif // wxUSE_VALIDATORS
154 // the colours/fonts are default for now, so leave m_font,
155 // m_backgroundColour and m_foregroundColour uninitialized and set those
161 m_inheritFont
= false;
167 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
169 #if wxUSE_CONSTRAINTS
170 // no constraints whatsoever
171 m_constraints
= (wxLayoutConstraints
*) NULL
;
172 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
173 #endif // wxUSE_CONSTRAINTS
175 m_windowSizer
= (wxSizer
*) NULL
;
176 m_containingSizer
= (wxSizer
*) NULL
;
177 m_autoLayout
= false;
179 #if wxUSE_DRAG_AND_DROP
180 m_dropTarget
= (wxDropTarget
*)NULL
;
181 #endif // wxUSE_DRAG_AND_DROP
184 m_tooltip
= (wxToolTip
*)NULL
;
185 #endif // wxUSE_TOOLTIPS
188 m_caret
= (wxCaret
*)NULL
;
189 #endif // wxUSE_CARET
192 m_hasCustomPalette
= false;
193 #endif // wxUSE_PALETTE
195 #if wxUSE_ACCESSIBILITY
199 m_virtualSize
= wxDefaultSize
;
202 m_maxVirtualWidth
= wxDefaultCoord
;
204 m_maxVirtualHeight
= wxDefaultCoord
;
206 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
207 #if wxUSE_SYSTEM_OPTIONS
208 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
210 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
214 // Whether we're using the current theme for this window (wxGTK only for now)
215 m_themeEnabled
= false;
217 // VZ: this one shouldn't exist...
218 m_isBeingDeleted
= false;
221 // common part of window creation process
222 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
224 const wxPoint
& WXUNUSED(pos
),
225 const wxSize
& WXUNUSED(size
),
227 const wxValidator
& wxVALIDATOR_PARAM(validator
),
228 const wxString
& name
)
231 // wxGTK doesn't allow to create controls with static box as the parent so
232 // this will result in a crash when the program is ported to wxGTK so warn
235 // if you get this assert, the correct solution is to create the controls
236 // as siblings of the static box
237 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
238 _T("wxStaticBox can't be used as a window parent!") );
239 #endif // wxUSE_STATBOX
241 // ids are limited to 16 bits under MSW so if you care about portability,
242 // it's not a good idea to use ids out of this range (and negative ids are
243 // reserved for wxWidgets own usage)
244 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
245 _T("invalid id value") );
247 // generate a new id if the user doesn't care about it
248 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
251 SetWindowStyleFlag(style
);
255 SetValidator(validator
);
256 #endif // wxUSE_VALIDATORS
258 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
259 // have it too - like this it's possible to set it only in the top level
260 // dialog/frame and all children will inherit it by defult
261 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
263 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
269 // ----------------------------------------------------------------------------
271 // ----------------------------------------------------------------------------
274 wxWindowBase::~wxWindowBase()
276 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
278 // FIXME if these 2 cases result from programming errors in the user code
279 // we should probably assert here instead of silently fixing them
281 // Just in case the window has been Closed, but we're then deleting
282 // immediately: don't leave dangling pointers.
283 wxPendingDelete
.DeleteObject(this);
285 // Just in case we've loaded a top-level window via LoadNativeDialog but
286 // we weren't a dialog class
287 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
289 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
291 // reset the dangling pointer our parent window may keep to us
294 if ( m_parent
->GetDefaultItem() == this )
296 m_parent
->SetDefaultItem(NULL
);
299 m_parent
->RemoveChild(this);
304 #endif // wxUSE_CARET
307 delete m_windowValidator
;
308 #endif // wxUSE_VALIDATORS
310 #if wxUSE_CONSTRAINTS
311 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
312 // at deleted windows as they delete themselves.
313 DeleteRelatedConstraints();
317 // This removes any dangling pointers to this window in other windows'
318 // constraintsInvolvedIn lists.
319 UnsetConstraints(m_constraints
);
320 delete m_constraints
;
321 m_constraints
= NULL
;
323 #endif // wxUSE_CONSTRAINTS
325 if ( m_containingSizer
)
326 m_containingSizer
->Detach( (wxWindow
*)this );
328 delete m_windowSizer
;
330 #if wxUSE_DRAG_AND_DROP
332 #endif // wxUSE_DRAG_AND_DROP
336 #endif // wxUSE_TOOLTIPS
338 #if wxUSE_ACCESSIBILITY
343 bool wxWindowBase::Destroy()
350 bool wxWindowBase::Close(bool force
)
352 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
353 event
.SetEventObject(this);
354 event
.SetCanVeto(!force
);
356 // return false if window wasn't closed because the application vetoed the
358 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
361 bool wxWindowBase::DestroyChildren()
363 wxWindowList::compatibility_iterator node
;
366 // we iterate until the list becomes empty
367 node
= GetChildren().GetFirst();
371 wxWindow
*child
= node
->GetData();
373 // note that we really want to call delete and not ->Destroy() here
374 // because we want to delete the child immediately, before we are
375 // deleted, and delayed deletion would result in problems as our (top
376 // level) child could outlive its parent
379 wxASSERT_MSG( !GetChildren().Find(child
),
380 wxT("child didn't remove itself using RemoveChild()") );
386 // ----------------------------------------------------------------------------
387 // size/position related methods
388 // ----------------------------------------------------------------------------
390 // centre the window with respect to its parent in either (or both) directions
391 void wxWindowBase::DoCentre(int dir
)
393 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
394 _T("this method only implements centering child windows") );
396 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
399 // fits the window around the children
400 void wxWindowBase::Fit()
402 if ( !GetChildren().empty() )
404 SetClientSize(GetBestSize());
406 //else: do nothing if we have no children
409 // fits virtual size (ie. scrolled area etc.) around children
410 void wxWindowBase::FitInside()
412 if ( GetChildren().GetCount() > 0 )
414 SetVirtualSize( GetBestVirtualSize() );
418 // On Mac, scrollbars are explicitly children.
420 static bool wxHasRealChildren(const wxWindowBase
* win
)
422 int realChildCount
= 0;
424 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
426 node
= node
->GetNext() )
428 wxWindow
*win
= node
->GetData();
429 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
432 return (realChildCount
> 0);
436 void wxWindowBase::InvalidateBestSize()
438 m_bestSizeCache
= wxDefaultSize
;
440 // parent's best size calculation may depend on its children's
441 // as long as child window we are in is not top level window itself
442 // (because the TLW size is never resized automatically)
443 // so let's invalidate it as well to be safe:
444 if (m_parent
&& !IsTopLevel())
445 m_parent
->InvalidateBestSize();
448 // return the size best suited for the current window
449 wxSize
wxWindowBase::DoGetBestSize() const
455 best
= GetWindowSizeForVirtualSize(m_windowSizer
->GetMinSize());
457 #if wxUSE_CONSTRAINTS
458 else if ( m_constraints
)
460 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
462 // our minimal acceptable size is such that all our windows fit inside
466 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
468 node
= node
->GetNext() )
470 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
473 // it's not normal that we have an unconstrained child, but
474 // what can we do about it?
478 int x
= c
->right
.GetValue(),
479 y
= c
->bottom
.GetValue();
487 // TODO: we must calculate the overlaps somehow, otherwise we
488 // will never return a size bigger than the current one :-(
491 best
= wxSize(maxX
, maxY
);
493 #endif // wxUSE_CONSTRAINTS
494 else if ( !GetChildren().empty()
496 && wxHasRealChildren(this)
500 // our minimal acceptable size is such that all our visible child windows fit inside
504 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
506 node
= node
->GetNext() )
508 wxWindow
*win
= node
->GetData();
509 if ( win
->IsTopLevel() || ( ! win
->IsShown() )
511 || wxDynamicCast(win
, wxStatusBar
)
512 #endif // wxUSE_STATUSBAR
515 // dialogs and frames lie in different top level windows -
516 // don't deal with them here; as for the status bars, they
517 // don't lie in the client area at all
522 win
->GetPosition(&wx
, &wy
);
524 // if the window hadn't been positioned yet, assume that it is in
526 if ( wx
== wxDefaultCoord
)
528 if ( wy
== wxDefaultCoord
)
531 win
->GetSize(&ww
, &wh
);
532 if ( wx
+ ww
> maxX
)
534 if ( wy
+ wh
> maxY
)
538 // for compatibility with the old versions and because it really looks
539 // slightly more pretty like this, add a pad
543 best
= wxSize(maxX
, maxY
);
545 else // ! has children
547 // for a generic window there is no natural best size so, if the
548 // minimal size is not set, use the current size but take care to
549 // remember it as minimal size for the next time because our best size
550 // should be constant: otherwise we could get into a situation when the
551 // window is initially at some size, then expanded to a larger size and
552 // then, when the containing window is shrunk back (because our initial
553 // best size had been used for computing the parent min size), we can't
554 // be shrunk back any more because our best size is now bigger
555 wxSize size
= GetMinSize();
556 if ( !size
.IsFullySpecified() )
558 size
.SetDefaults(GetSize());
559 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
562 // return as-is, unadjusted by the client size difference.
566 // Add any difference between size and client size
567 wxSize diff
= GetSize() - GetClientSize();
568 best
.x
+= wxMax(0, diff
.x
);
569 best
.y
+= wxMax(0, diff
.y
);
575 wxSize
wxWindowBase::GetBestFittingSize() const
577 // merge the best size with the min size, giving priority to the min size
578 wxSize min
= GetMinSize();
579 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
581 wxSize best
= GetBestSize();
582 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
583 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
589 void wxWindowBase::SetBestFittingSize(const wxSize
& size
)
591 // Set the min size to the size passed in. This will usually either be
592 // wxDefaultSize or the size passed to this window's ctor/Create function.
595 // Merge the size with the best size if needed
596 wxSize best
= GetBestFittingSize();
598 // If the current size doesn't match then change it
599 if (GetSize() != best
)
604 // by default the origin is not shifted
605 wxPoint
wxWindowBase::GetClientAreaOrigin() const
610 // set the min/max size of the window
611 void wxWindowBase::DoSetSizeHints(int minW
, int minH
,
613 int WXUNUSED(incW
), int WXUNUSED(incH
))
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
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
618 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
619 _T("min width/height must be less than max width/height!") );
627 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
629 if ( m_windowVariant
!= variant
)
631 m_windowVariant
= variant
;
633 DoSetWindowVariant(variant
);
637 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
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();
645 case wxWINDOW_VARIANT_NORMAL
:
648 case wxWINDOW_VARIANT_SMALL
:
653 case wxWINDOW_VARIANT_MINI
:
658 case wxWINDOW_VARIANT_LARGE
:
664 wxFAIL_MSG(_T("unexpected window variant"));
668 font
.SetPointSize(size
);
672 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
675 m_minVirtualWidth
= minW
;
676 m_maxVirtualWidth
= maxW
;
677 m_minVirtualHeight
= minH
;
678 m_maxVirtualHeight
= maxH
;
681 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
683 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
684 x
= m_minVirtualWidth
;
685 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
686 x
= m_maxVirtualWidth
;
687 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
688 y
= m_minVirtualHeight
;
689 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
690 y
= m_maxVirtualHeight
;
692 m_virtualSize
= wxSize(x
, y
);
695 wxSize
wxWindowBase::DoGetVirtualSize() const
697 // we should use the entire client area so if it is greater than our
698 // virtual size, expand it to fit (otherwise if the window is big enough we
699 // wouldn't be using parts of it)
700 wxSize size
= GetClientSize();
701 if ( m_virtualSize
.x
> size
.x
)
702 size
.x
= m_virtualSize
.x
;
704 if ( m_virtualSize
.y
>= size
.y
)
705 size
.y
= m_virtualSize
.y
;
710 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
712 // screen position is the same as (0, 0) in client coords for non TLWs (and
713 // TLWs override this method)
719 ClientToScreen(x
, y
);
722 // ----------------------------------------------------------------------------
723 // show/hide/enable/disable the window
724 // ----------------------------------------------------------------------------
726 bool wxWindowBase::Show(bool show
)
728 if ( show
!= m_isShown
)
740 bool wxWindowBase::Enable(bool enable
)
742 if ( enable
!= m_isEnabled
)
744 m_isEnabled
= enable
;
753 // ----------------------------------------------------------------------------
755 // ----------------------------------------------------------------------------
757 bool wxWindowBase::IsTopLevel() const
762 // ----------------------------------------------------------------------------
763 // reparenting the window
764 // ----------------------------------------------------------------------------
766 void wxWindowBase::AddChild(wxWindowBase
*child
)
768 wxCHECK_RET( child
, wxT("can't add a NULL child") );
770 // this should never happen and it will lead to a crash later if it does
771 // because RemoveChild() will remove only one node from the children list
772 // and the other(s) one(s) will be left with dangling pointers in them
773 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
775 GetChildren().Append((wxWindow
*)child
);
776 child
->SetParent(this);
779 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
781 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
783 GetChildren().DeleteObject((wxWindow
*)child
);
784 child
->SetParent(NULL
);
787 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
789 wxWindow
*oldParent
= GetParent();
790 if ( newParent
== oldParent
)
796 // unlink this window from the existing parent.
799 oldParent
->RemoveChild(this);
803 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
806 // add it to the new one
809 newParent
->AddChild(this);
813 wxTopLevelWindows
.Append((wxWindow
*)this);
819 // ----------------------------------------------------------------------------
820 // event handler stuff
821 // ----------------------------------------------------------------------------
823 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
825 wxEvtHandler
*handlerOld
= GetEventHandler();
827 handler
->SetNextHandler(handlerOld
);
830 GetEventHandler()->SetPreviousHandler(handler
);
832 SetEventHandler(handler
);
835 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
837 wxEvtHandler
*handlerA
= GetEventHandler();
840 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
841 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
844 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
845 SetEventHandler(handlerB
);
850 handlerA
= (wxEvtHandler
*)NULL
;
857 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
859 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
861 wxEvtHandler
*handlerPrev
= NULL
,
862 *handlerCur
= GetEventHandler();
865 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
867 if ( handlerCur
== handler
)
871 handlerPrev
->SetNextHandler(handlerNext
);
875 SetEventHandler(handlerNext
);
880 handlerNext
->SetPreviousHandler ( handlerPrev
);
883 handler
->SetNextHandler(NULL
);
884 handler
->SetPreviousHandler(NULL
);
889 handlerPrev
= handlerCur
;
890 handlerCur
= handlerNext
;
893 wxFAIL_MSG( _T("where has the event handler gone?") );
898 // ----------------------------------------------------------------------------
900 // ----------------------------------------------------------------------------
902 void wxWindowBase::InheritAttributes()
904 const wxWindowBase
* const parent
= GetParent();
908 // we only inherit attributes which had been explicitly set for the parent
909 // which ensures that this only happens if the user really wants it and
910 // not by default which wouldn't make any sense in modern GUIs where the
911 // controls don't all use the same fonts (nor colours)
912 if ( parent
->m_inheritFont
&& !m_hasFont
)
913 SetFont(parent
->GetFont());
915 // in addition, there is a possibility to explicitly forbid inheriting
916 // colours at each class level by overriding ShouldInheritColours()
917 if ( ShouldInheritColours() )
919 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
920 SetForegroundColour(parent
->GetForegroundColour());
922 // inheriting (solid) background colour is wrong as it totally breaks
923 // any kind of themed backgrounds
925 // instead, the controls should use the same background as their parent
926 // (ideally by not drawing it at all)
928 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
929 SetBackgroundColour(parent
->GetBackgroundColour());
934 /* static */ wxVisualAttributes
935 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
937 // it is important to return valid values for all attributes from here,
938 // GetXXX() below rely on this
939 wxVisualAttributes attrs
;
940 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
941 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
943 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
944 // the usual background colour than wxSYS_COLOUR_BTNFACE.
945 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
946 // colour on other platforms.
948 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
949 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
951 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
956 wxColour
wxWindowBase::GetBackgroundColour() const
958 if ( !m_backgroundColour
.Ok() )
960 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
962 // get our default background colour
963 wxColour colBg
= GetDefaultAttributes().colBg
;
965 // we must return some valid colour to avoid redoing this every time
966 // and also to avoid surprizing the applications written for older
967 // wxWidgets versions where GetBackgroundColour() always returned
968 // something -- so give them something even if it doesn't make sense
969 // for this window (e.g. it has a themed background)
971 colBg
= GetClassDefaultAttributes().colBg
;
976 return m_backgroundColour
;
979 wxColour
wxWindowBase::GetForegroundColour() const
981 // logic is the same as above
982 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
984 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
986 wxColour colFg
= GetDefaultAttributes().colFg
;
989 colFg
= GetClassDefaultAttributes().colFg
;
994 return m_foregroundColour
;
997 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
999 if ( colour
== m_backgroundColour
)
1002 m_hasBgCol
= colour
.Ok();
1003 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1004 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1006 m_inheritBgCol
= m_hasBgCol
;
1007 m_backgroundColour
= colour
;
1008 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1012 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1014 if (colour
== m_foregroundColour
)
1017 m_hasFgCol
= colour
.Ok();
1018 m_inheritFgCol
= m_hasFgCol
;
1019 m_foregroundColour
= colour
;
1020 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1024 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1026 // setting an invalid cursor is ok, it means that we don't have any special
1028 if ( m_cursor
== cursor
)
1039 wxFont
wxWindowBase::GetFont() const
1041 // logic is the same as in GetBackgroundColour()
1044 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1046 wxFont font
= GetDefaultAttributes().font
;
1048 font
= GetClassDefaultAttributes().font
;
1056 bool wxWindowBase::SetFont(const wxFont
& font
)
1058 if ( font
== m_font
)
1065 m_hasFont
= font
.Ok();
1066 m_inheritFont
= m_hasFont
;
1068 InvalidateBestSize();
1075 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1077 m_hasCustomPalette
= true;
1080 // VZ: can anyone explain me what do we do here?
1081 wxWindowDC
d((wxWindow
*) this);
1085 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1087 wxWindow
*win
= (wxWindow
*)this;
1088 while ( win
&& !win
->HasCustomPalette() )
1090 win
= win
->GetParent();
1096 #endif // wxUSE_PALETTE
1099 void wxWindowBase::SetCaret(wxCaret
*caret
)
1110 wxASSERT_MSG( m_caret
->GetWindow() == this,
1111 wxT("caret should be created associated to this window") );
1114 #endif // wxUSE_CARET
1116 #if wxUSE_VALIDATORS
1117 // ----------------------------------------------------------------------------
1119 // ----------------------------------------------------------------------------
1121 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1123 if ( m_windowValidator
)
1124 delete m_windowValidator
;
1126 m_windowValidator
= (wxValidator
*)validator
.Clone();
1128 if ( m_windowValidator
)
1129 m_windowValidator
->SetWindow(this);
1131 #endif // wxUSE_VALIDATORS
1133 // ----------------------------------------------------------------------------
1134 // update region stuff
1135 // ----------------------------------------------------------------------------
1137 wxRect
wxWindowBase::GetUpdateClientRect() const
1139 wxRegion rgnUpdate
= GetUpdateRegion();
1140 rgnUpdate
.Intersect(GetClientRect());
1141 wxRect rectUpdate
= rgnUpdate
.GetBox();
1142 wxPoint ptOrigin
= GetClientAreaOrigin();
1143 rectUpdate
.x
-= ptOrigin
.x
;
1144 rectUpdate
.y
-= ptOrigin
.y
;
1149 bool wxWindowBase::IsExposed(int x
, int y
) const
1151 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1154 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1156 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1159 void wxWindowBase::ClearBackground()
1161 // wxGTK uses its own version, no need to add never used code
1163 wxClientDC
dc((wxWindow
*)this);
1164 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1165 dc
.SetBackground(brush
);
1170 // ----------------------------------------------------------------------------
1171 // find child window by id or name
1172 // ----------------------------------------------------------------------------
1174 wxWindow
*wxWindowBase::FindWindow(long id
) const
1176 if ( id
== m_windowId
)
1177 return (wxWindow
*)this;
1179 wxWindowBase
*res
= (wxWindow
*)NULL
;
1180 wxWindowList::compatibility_iterator node
;
1181 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1183 wxWindowBase
*child
= node
->GetData();
1184 res
= child
->FindWindow( id
);
1187 return (wxWindow
*)res
;
1190 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1192 if ( name
== m_windowName
)
1193 return (wxWindow
*)this;
1195 wxWindowBase
*res
= (wxWindow
*)NULL
;
1196 wxWindowList::compatibility_iterator node
;
1197 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1199 wxWindow
*child
= node
->GetData();
1200 res
= child
->FindWindow(name
);
1203 return (wxWindow
*)res
;
1207 // find any window by id or name or label: If parent is non-NULL, look through
1208 // children for a label or title matching the specified string. If NULL, look
1209 // through all top-level windows.
1211 // to avoid duplicating code we reuse the same helper function but with
1212 // different comparators
1214 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1215 const wxString
& label
, long id
);
1218 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1221 return win
->GetLabel() == label
;
1225 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1228 return win
->GetName() == label
;
1232 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1235 return win
->GetId() == id
;
1238 // recursive helper for the FindWindowByXXX() functions
1240 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1241 const wxString
& label
,
1243 wxFindWindowCmp cmp
)
1247 // see if this is the one we're looking for
1248 if ( (*cmp
)(parent
, label
, id
) )
1249 return (wxWindow
*)parent
;
1251 // It wasn't, so check all its children
1252 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1254 node
= node
->GetNext() )
1256 // recursively check each child
1257 wxWindow
*win
= (wxWindow
*)node
->GetData();
1258 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1268 // helper for FindWindowByXXX()
1270 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1271 const wxString
& label
,
1273 wxFindWindowCmp cmp
)
1277 // just check parent and all its children
1278 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1281 // start at very top of wx's windows
1282 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1284 node
= node
->GetNext() )
1286 // recursively check each window & its children
1287 wxWindow
*win
= node
->GetData();
1288 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1298 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1300 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1305 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1307 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1311 // fall back to the label
1312 win
= FindWindowByLabel(title
, parent
);
1320 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1322 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1325 // ----------------------------------------------------------------------------
1326 // dialog oriented functions
1327 // ----------------------------------------------------------------------------
1329 void wxWindowBase::MakeModal(bool modal
)
1331 // Disable all other windows
1334 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1337 wxWindow
*win
= node
->GetData();
1339 win
->Enable(!modal
);
1341 node
= node
->GetNext();
1346 bool wxWindowBase::Validate()
1348 #if wxUSE_VALIDATORS
1349 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1351 wxWindowList::compatibility_iterator node
;
1352 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1354 wxWindowBase
*child
= node
->GetData();
1355 wxValidator
*validator
= child
->GetValidator();
1356 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1361 if ( recurse
&& !child
->Validate() )
1366 #endif // wxUSE_VALIDATORS
1371 bool wxWindowBase::TransferDataToWindow()
1373 #if wxUSE_VALIDATORS
1374 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1376 wxWindowList::compatibility_iterator node
;
1377 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1379 wxWindowBase
*child
= node
->GetData();
1380 wxValidator
*validator
= child
->GetValidator();
1381 if ( validator
&& !validator
->TransferToWindow() )
1383 wxLogWarning(_("Could not transfer data to window"));
1385 wxLog::FlushActive();
1393 if ( !child
->TransferDataToWindow() )
1395 // warning already given
1400 #endif // wxUSE_VALIDATORS
1405 bool wxWindowBase::TransferDataFromWindow()
1407 #if wxUSE_VALIDATORS
1408 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1410 wxWindowList::compatibility_iterator node
;
1411 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1413 wxWindow
*child
= node
->GetData();
1414 wxValidator
*validator
= child
->GetValidator();
1415 if ( validator
&& !validator
->TransferFromWindow() )
1417 // nop warning here because the application is supposed to give
1418 // one itself - we don't know here what might have gone wrongly
1425 if ( !child
->TransferDataFromWindow() )
1427 // warning already given
1432 #endif // wxUSE_VALIDATORS
1437 void wxWindowBase::InitDialog()
1439 wxInitDialogEvent
event(GetId());
1440 event
.SetEventObject( this );
1441 GetEventHandler()->ProcessEvent(event
);
1444 // ----------------------------------------------------------------------------
1445 // context-sensitive help support
1446 // ----------------------------------------------------------------------------
1450 // associate this help text with this window
1451 void wxWindowBase::SetHelpText(const wxString
& text
)
1453 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1456 helpProvider
->AddHelp(this, text
);
1460 // associate this help text with all windows with the same id as this
1462 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1464 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1467 helpProvider
->AddHelp(GetId(), text
);
1471 // get the help string associated with this window (may be empty)
1472 // default implementation forwards calls to the help provider
1474 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1475 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1478 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1481 text
= helpProvider
->GetHelp(this);
1487 // show help for this window
1488 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1490 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1493 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1495 // skip the event.Skip() below
1503 #endif // wxUSE_HELP
1505 // ----------------------------------------------------------------------------
1506 // tooltipsroot.Replace("\\", "/");
1507 // ----------------------------------------------------------------------------
1511 void wxWindowBase::SetToolTip( const wxString
&tip
)
1513 // don't create the new tooltip if we already have one
1516 m_tooltip
->SetTip( tip
);
1520 SetToolTip( new wxToolTip( tip
) );
1523 // setting empty tooltip text does not remove the tooltip any more - use
1524 // SetToolTip((wxToolTip *)NULL) for this
1527 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1529 if ( m_tooltip
!= tooltip
)
1534 m_tooltip
= tooltip
;
1538 #endif // wxUSE_TOOLTIPS
1540 // ----------------------------------------------------------------------------
1541 // constraints and sizers
1542 // ----------------------------------------------------------------------------
1544 #if wxUSE_CONSTRAINTS
1546 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1548 if ( m_constraints
)
1550 UnsetConstraints(m_constraints
);
1551 delete m_constraints
;
1553 m_constraints
= constraints
;
1554 if ( m_constraints
)
1556 // Make sure other windows know they're part of a 'meaningful relationship'
1557 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1558 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1559 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1560 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1561 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1562 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1563 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1564 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1565 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1566 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1567 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1568 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1569 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1570 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1571 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1572 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1576 // This removes any dangling pointers to this window in other windows'
1577 // constraintsInvolvedIn lists.
1578 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1582 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1583 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1584 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1585 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1586 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1587 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1588 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1589 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1590 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1591 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1592 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1593 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1594 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1595 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1596 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1597 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1601 // Back-pointer to other windows we're involved with, so if we delete this
1602 // window, we must delete any constraints we're involved with.
1603 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1605 if ( !m_constraintsInvolvedIn
)
1606 m_constraintsInvolvedIn
= new wxWindowList
;
1607 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1608 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1611 // REMOVE back-pointer to other windows we're involved with.
1612 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1614 if ( m_constraintsInvolvedIn
)
1615 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1618 // Reset any constraints that mention this window
1619 void wxWindowBase::DeleteRelatedConstraints()
1621 if ( m_constraintsInvolvedIn
)
1623 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1626 wxWindow
*win
= node
->GetData();
1627 wxLayoutConstraints
*constr
= win
->GetConstraints();
1629 // Reset any constraints involving this window
1632 constr
->left
.ResetIfWin(this);
1633 constr
->top
.ResetIfWin(this);
1634 constr
->right
.ResetIfWin(this);
1635 constr
->bottom
.ResetIfWin(this);
1636 constr
->width
.ResetIfWin(this);
1637 constr
->height
.ResetIfWin(this);
1638 constr
->centreX
.ResetIfWin(this);
1639 constr
->centreY
.ResetIfWin(this);
1642 wxWindowList::compatibility_iterator next
= node
->GetNext();
1643 m_constraintsInvolvedIn
->Erase(node
);
1647 delete m_constraintsInvolvedIn
;
1648 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1652 #endif // wxUSE_CONSTRAINTS
1654 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1656 if ( sizer
== m_windowSizer
)
1660 delete m_windowSizer
;
1662 m_windowSizer
= sizer
;
1664 SetAutoLayout( sizer
!= NULL
);
1667 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1669 SetSizer( sizer
, deleteOld
);
1670 sizer
->SetSizeHints( (wxWindow
*) this );
1674 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1676 // adding a window to a sizer twice is going to result in fatal and
1677 // hard to debug problems later because when deleting the second
1678 // associated wxSizerItem we're going to dereference a dangling
1679 // pointer; so try to detect this as early as possible
1680 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1681 _T("Adding a window to the same sizer twice?") );
1683 m_containingSizer
= sizer
;
1686 #if wxUSE_CONSTRAINTS
1688 void wxWindowBase::SatisfyConstraints()
1690 wxLayoutConstraints
*constr
= GetConstraints();
1691 bool wasOk
= constr
&& constr
->AreSatisfied();
1693 ResetConstraints(); // Mark all constraints as unevaluated
1697 // if we're a top level panel (i.e. our parent is frame/dialog), our
1698 // own constraints will never be satisfied any more unless we do it
1702 while ( noChanges
> 0 )
1704 LayoutPhase1(&noChanges
);
1708 LayoutPhase2(&noChanges
);
1711 #endif // wxUSE_CONSTRAINTS
1713 bool wxWindowBase::Layout()
1715 // If there is a sizer, use it instead of the constraints
1719 GetVirtualSize(&w
, &h
);
1720 GetSizer()->SetDimension( 0, 0, w
, h
);
1722 #if wxUSE_CONSTRAINTS
1725 SatisfyConstraints(); // Find the right constraints values
1726 SetConstraintSizes(); // Recursively set the real window sizes
1733 #if wxUSE_CONSTRAINTS
1735 // first phase of the constraints evaluation: set our own constraints
1736 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1738 wxLayoutConstraints
*constr
= GetConstraints();
1740 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1743 // second phase: set the constraints for our children
1744 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1751 // Layout grand children
1757 // Do a phase of evaluating child constraints
1758 bool wxWindowBase::DoPhase(int phase
)
1760 // the list containing the children for which the constraints are already
1762 wxWindowList succeeded
;
1764 // the max number of iterations we loop before concluding that we can't set
1766 static const int maxIterations
= 500;
1768 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1772 // loop over all children setting their constraints
1773 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1775 node
= node
->GetNext() )
1777 wxWindow
*child
= node
->GetData();
1778 if ( child
->IsTopLevel() )
1780 // top level children are not inside our client area
1784 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1786 // this one is either already ok or nothing we can do about it
1790 int tempNoChanges
= 0;
1791 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1792 : child
->LayoutPhase2(&tempNoChanges
);
1793 noChanges
+= tempNoChanges
;
1797 succeeded
.Append(child
);
1803 // constraints are set
1811 void wxWindowBase::ResetConstraints()
1813 wxLayoutConstraints
*constr
= GetConstraints();
1816 constr
->left
.SetDone(false);
1817 constr
->top
.SetDone(false);
1818 constr
->right
.SetDone(false);
1819 constr
->bottom
.SetDone(false);
1820 constr
->width
.SetDone(false);
1821 constr
->height
.SetDone(false);
1822 constr
->centreX
.SetDone(false);
1823 constr
->centreY
.SetDone(false);
1826 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1829 wxWindow
*win
= node
->GetData();
1830 if ( !win
->IsTopLevel() )
1831 win
->ResetConstraints();
1832 node
= node
->GetNext();
1836 // Need to distinguish between setting the 'fake' size for windows and sizers,
1837 // and setting the real values.
1838 void wxWindowBase::SetConstraintSizes(bool recurse
)
1840 wxLayoutConstraints
*constr
= GetConstraints();
1841 if ( constr
&& constr
->AreSatisfied() )
1843 int x
= constr
->left
.GetValue();
1844 int y
= constr
->top
.GetValue();
1845 int w
= constr
->width
.GetValue();
1846 int h
= constr
->height
.GetValue();
1848 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1849 (constr
->height
.GetRelationship() != wxAsIs
) )
1851 SetSize(x
, y
, w
, h
);
1855 // If we don't want to resize this window, just move it...
1861 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1862 GetClassInfo()->GetClassName(),
1868 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1871 wxWindow
*win
= node
->GetData();
1872 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1873 win
->SetConstraintSizes();
1874 node
= node
->GetNext();
1879 // Only set the size/position of the constraint (if any)
1880 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1882 wxLayoutConstraints
*constr
= GetConstraints();
1885 if ( x
!= wxDefaultCoord
)
1887 constr
->left
.SetValue(x
);
1888 constr
->left
.SetDone(true);
1890 if ( y
!= wxDefaultCoord
)
1892 constr
->top
.SetValue(y
);
1893 constr
->top
.SetDone(true);
1895 if ( w
!= wxDefaultCoord
)
1897 constr
->width
.SetValue(w
);
1898 constr
->width
.SetDone(true);
1900 if ( h
!= wxDefaultCoord
)
1902 constr
->height
.SetValue(h
);
1903 constr
->height
.SetDone(true);
1908 void wxWindowBase::MoveConstraint(int x
, int y
)
1910 wxLayoutConstraints
*constr
= GetConstraints();
1913 if ( x
!= wxDefaultCoord
)
1915 constr
->left
.SetValue(x
);
1916 constr
->left
.SetDone(true);
1918 if ( y
!= wxDefaultCoord
)
1920 constr
->top
.SetValue(y
);
1921 constr
->top
.SetDone(true);
1926 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1928 wxLayoutConstraints
*constr
= GetConstraints();
1931 *w
= constr
->width
.GetValue();
1932 *h
= constr
->height
.GetValue();
1938 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1940 wxLayoutConstraints
*constr
= GetConstraints();
1943 *w
= constr
->width
.GetValue();
1944 *h
= constr
->height
.GetValue();
1947 GetClientSize(w
, h
);
1950 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1952 wxLayoutConstraints
*constr
= GetConstraints();
1955 *x
= constr
->left
.GetValue();
1956 *y
= constr
->top
.GetValue();
1962 #endif // wxUSE_CONSTRAINTS
1964 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1966 // don't do it for the dialogs/frames - they float independently of their
1968 if ( !IsTopLevel() )
1970 wxWindow
*parent
= GetParent();
1971 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1973 wxPoint
pt(parent
->GetClientAreaOrigin());
1980 // ----------------------------------------------------------------------------
1981 // do Update UI processing for child controls
1982 // ----------------------------------------------------------------------------
1984 void wxWindowBase::UpdateWindowUI(long flags
)
1986 wxUpdateUIEvent
event(GetId());
1987 event
.SetEventObject(this);
1989 if ( GetEventHandler()->ProcessEvent(event
) )
1991 DoUpdateWindowUI(event
);
1994 if (flags
& wxUPDATE_UI_RECURSE
)
1996 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1999 wxWindow
* child
= (wxWindow
*) node
->GetData();
2000 child
->UpdateWindowUI(flags
);
2001 node
= node
->GetNext();
2006 // do the window-specific processing after processing the update event
2007 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2009 if ( event
.GetSetEnabled() )
2010 Enable(event
.GetEnabled());
2012 if ( event
.GetSetShown() )
2013 Show(event
.GetShown());
2017 // call internal idle recursively
2018 // may be obsolete (wait until OnIdle scheme stabilises)
2019 void wxWindowBase::ProcessInternalIdle()
2023 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2026 wxWindow
*child
= node
->GetData();
2027 child
->ProcessInternalIdle();
2028 node
= node
->GetNext();
2033 // ----------------------------------------------------------------------------
2034 // dialog units translations
2035 // ----------------------------------------------------------------------------
2037 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2039 int charWidth
= GetCharWidth();
2040 int charHeight
= GetCharHeight();
2041 wxPoint pt2
= wxDefaultPosition
;
2042 if (pt
.x
!= wxDefaultCoord
)
2043 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2044 if (pt
.y
!= wxDefaultCoord
)
2045 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2050 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2052 int charWidth
= GetCharWidth();
2053 int charHeight
= GetCharHeight();
2054 wxPoint pt2
= wxDefaultPosition
;
2055 if (pt
.x
!= wxDefaultCoord
)
2056 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2057 if (pt
.y
!= wxDefaultCoord
)
2058 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2063 // ----------------------------------------------------------------------------
2065 // ----------------------------------------------------------------------------
2067 // propagate the colour change event to the subwindows
2068 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2070 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2073 // Only propagate to non-top-level windows
2074 wxWindow
*win
= node
->GetData();
2075 if ( !win
->IsTopLevel() )
2077 wxSysColourChangedEvent event2
;
2078 event
.SetEventObject(win
);
2079 win
->GetEventHandler()->ProcessEvent(event2
);
2082 node
= node
->GetNext();
2088 // the default action is to populate dialog with data when it's created,
2089 // and nudge the UI into displaying itself correctly in case
2090 // we've turned the wxUpdateUIEvents frequency down low.
2091 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2093 TransferDataToWindow();
2095 // Update the UI at this point
2096 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2099 // methods for drawing the sizers in a visible way
2102 static void DrawSizers(wxWindowBase
*win
);
2104 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2106 wxClientDC
dc((wxWindow
*)win
);
2107 dc
.SetPen(*wxRED_PEN
);
2108 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2109 dc
.DrawRectangle(rect
.Deflate(1, 1));
2112 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2114 const wxSizerItemList
& items
= sizer
->GetChildren();
2115 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2120 wxSizerItem
*item
= *i
;
2121 if ( item
->IsSizer() )
2123 DrawBorder(win
, item
->GetRect().Deflate(2));
2124 DrawSizer(win
, item
->GetSizer());
2126 else if ( item
->IsSpacer() )
2128 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2130 else if ( item
->IsWindow() )
2132 DrawSizers(item
->GetWindow());
2137 static void DrawSizers(wxWindowBase
*win
)
2139 wxSizer
*sizer
= win
->GetSizer();
2142 DrawBorder(win
, win
->GetClientSize());
2143 DrawSizer(win
, sizer
);
2145 else // no sizer, still recurse into the children
2147 const wxWindowList
& children
= win
->GetChildren();
2148 for ( wxWindowList::const_iterator i
= children
.begin(),
2149 end
= children
.end();
2158 #endif // __WXDEBUG__
2160 // process special middle clicks
2161 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2163 if ( event
.ControlDown() && event
.AltDown() )
2166 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2167 if ( event
.ShiftDown() )
2172 #endif // __WXDEBUG__
2175 // don't translate these strings
2178 #ifdef __WXUNIVERSAL__
2180 #endif // __WXUNIVERSAL__
2182 switch ( wxGetOsVersion() )
2184 case wxMOTIF_X
: port
+= _T("Motif"); break;
2186 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2187 case wxBEOS
: port
+= _T("BeOS"); break;
2191 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2197 case wxWIN386
: port
+= _T("MS Windows"); break;
2201 case wxMGL_OS2
: port
+= _T("MGL"); break;
2203 case wxOS2_PM
: port
+= _T("OS/2"); break;
2204 case wxPALMOS
: port
+= _T("Palm OS"); break;
2205 case wxWINDOWS_CE
: port
+= _T("Windows CE (generic)"); break;
2206 case wxWINDOWS_POCKETPC
: port
+= _T("Windows CE PocketPC"); break;
2207 case wxWINDOWS_SMARTPHONE
: port
+= _T("Windows CE Smartphone"); break;
2208 default: port
+= _T("unknown"); break;
2211 wxMessageBox(wxString::Format(
2213 " wxWidgets Library (%s port)\nVersion %d.%d.%d%s%s, compiled at %s %s%s\n Copyright (c) 1995-2006 wxWidgets team"
2232 wxString::Format(_T("\nagainst GTK+ %d.%d.%d. Runtime GTK+ version: %d.%d.%d"), GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
, gtk_major_version
, gtk_minor_version
, gtk_micro_version
).c_str()
2237 _T("wxWidgets information"),
2238 wxICON_INFORMATION
| wxOK
,
2242 #endif // wxUSE_MSGDLG
2248 // ----------------------------------------------------------------------------
2250 // ----------------------------------------------------------------------------
2252 #if wxUSE_ACCESSIBILITY
2253 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2255 if (m_accessible
&& (accessible
!= m_accessible
))
2256 delete m_accessible
;
2257 m_accessible
= accessible
;
2259 m_accessible
->SetWindow((wxWindow
*) this);
2262 // Returns the accessible object, creating if necessary.
2263 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2266 m_accessible
= CreateAccessible();
2267 return m_accessible
;
2270 // Override to create a specific accessible object.
2271 wxAccessible
* wxWindowBase::CreateAccessible()
2273 return new wxWindowAccessible((wxWindow
*) this);
2278 // ----------------------------------------------------------------------------
2279 // list classes implementation
2280 // ----------------------------------------------------------------------------
2284 #include "wx/listimpl.cpp"
2285 WX_DEFINE_LIST(wxWindowList
)
2289 void wxWindowListNode::DeleteData()
2291 delete (wxWindow
*)GetData();
2296 // ----------------------------------------------------------------------------
2298 // ----------------------------------------------------------------------------
2300 wxBorder
wxWindowBase::GetBorder(long flags
) const
2302 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2303 if ( border
== wxBORDER_DEFAULT
)
2305 border
= GetDefaultBorder();
2311 wxBorder
wxWindowBase::GetDefaultBorder() const
2313 return wxBORDER_NONE
;
2316 // ----------------------------------------------------------------------------
2318 // ----------------------------------------------------------------------------
2320 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2322 // here we just check if the point is inside the window or not
2324 // check the top and left border first
2325 bool outside
= x
< 0 || y
< 0;
2328 // check the right and bottom borders too
2329 wxSize size
= GetSize();
2330 outside
= x
>= size
.x
|| y
>= size
.y
;
2333 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2336 // ----------------------------------------------------------------------------
2338 // ----------------------------------------------------------------------------
2340 struct WXDLLEXPORT wxWindowNext
2344 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2346 void wxWindowBase::CaptureMouse()
2348 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2350 wxWindow
*winOld
= GetCapture();
2353 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2356 wxWindowNext
*item
= new wxWindowNext
;
2358 item
->next
= ms_winCaptureNext
;
2359 ms_winCaptureNext
= item
;
2361 //else: no mouse capture to save
2366 void wxWindowBase::ReleaseMouse()
2368 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2370 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2374 if ( ms_winCaptureNext
)
2376 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2378 wxWindowNext
*item
= ms_winCaptureNext
;
2379 ms_winCaptureNext
= item
->next
;
2382 //else: stack is empty, no previous capture
2384 wxLogTrace(_T("mousecapture"),
2385 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2392 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2393 int WXUNUSED(modifiers
),
2394 int WXUNUSED(keycode
))
2400 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2406 #endif // wxUSE_HOTKEY
2408 void wxWindowBase::SendDestroyEvent()
2410 wxWindowDestroyEvent event
;
2411 event
.SetEventObject(this);
2412 event
.SetId(GetId());
2413 GetEventHandler()->ProcessEvent(event
);
2416 // ----------------------------------------------------------------------------
2418 // ----------------------------------------------------------------------------
2420 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2422 #if wxUSE_VALIDATORS
2423 // Can only use the validator of the window which
2424 // is receiving the event
2425 if ( event
.GetEventObject() == this )
2427 wxValidator
*validator
= GetValidator();
2428 if ( validator
&& validator
->ProcessEvent(event
) )
2433 #endif // wxUSE_VALIDATORS
2438 bool wxWindowBase::TryParent(wxEvent
& event
)
2440 // carry on up the parent-child hierarchy if the propagation count hasn't
2442 if ( event
.ShouldPropagate() )
2444 // honour the requests to stop propagation at this window: this is
2445 // used by the dialogs, for example, to prevent processing the events
2446 // from the dialog controls in the parent frame which rarely, if ever,
2448 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2450 wxWindow
*parent
= GetParent();
2451 if ( parent
&& !parent
->IsBeingDeleted() )
2453 wxPropagateOnce
propagateOnce(event
);
2455 return parent
->GetEventHandler()->ProcessEvent(event
);
2460 return wxEvtHandler::TryParent(event
);
2463 // ----------------------------------------------------------------------------
2464 // keyboard navigation
2465 // ----------------------------------------------------------------------------
2467 // Navigates in the specified direction.
2468 bool wxWindowBase::Navigate(int flags
)
2470 wxNavigationKeyEvent eventNav
;
2471 eventNav
.SetFlags(flags
);
2472 eventNav
.SetEventObject(this);
2473 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2480 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2482 // check that we're not a top level window
2483 wxCHECK_RET( GetParent(),
2484 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2486 // detect the special case when we have nothing to do anyhow and when the
2487 // code below wouldn't work
2491 // find the target window in the siblings list
2492 wxWindowList
& siblings
= GetParent()->GetChildren();
2493 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2494 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2496 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2497 // can't just move the node around
2498 wxWindow
*self
= (wxWindow
*)this;
2499 siblings
.DeleteObject(self
);
2500 if ( move
== MoveAfter
)
2507 siblings
.Insert(i
, self
);
2509 else // MoveAfter and win was the last sibling
2511 siblings
.Append(self
);
2515 // ----------------------------------------------------------------------------
2517 // ----------------------------------------------------------------------------
2519 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2521 wxWindowBase
*win
= DoFindFocus();
2522 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2525 // ----------------------------------------------------------------------------
2527 // ----------------------------------------------------------------------------
2529 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2531 while ( win
&& !win
->IsTopLevel() )
2532 win
= win
->GetParent();
2537 #if wxUSE_ACCESSIBILITY
2538 // ----------------------------------------------------------------------------
2539 // accessible object for windows
2540 // ----------------------------------------------------------------------------
2542 // Can return either a child object, or an integer
2543 // representing the child element, starting from 1.
2544 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2546 wxASSERT( GetWindow() != NULL
);
2550 return wxACC_NOT_IMPLEMENTED
;
2553 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2554 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2556 wxASSERT( GetWindow() != NULL
);
2560 wxWindow
* win
= NULL
;
2567 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2569 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2576 rect
= win
->GetRect();
2577 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2578 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2582 return wxACC_NOT_IMPLEMENTED
;
2585 // Navigates from fromId to toId/toObject.
2586 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2587 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2589 wxASSERT( GetWindow() != NULL
);
2595 case wxNAVDIR_FIRSTCHILD
:
2597 if (GetWindow()->GetChildren().GetCount() == 0)
2599 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2600 *toObject
= childWindow
->GetOrCreateAccessible();
2604 case wxNAVDIR_LASTCHILD
:
2606 if (GetWindow()->GetChildren().GetCount() == 0)
2608 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2609 *toObject
= childWindow
->GetOrCreateAccessible();
2613 case wxNAVDIR_RIGHT
:
2617 wxWindowList::compatibility_iterator node
=
2618 wxWindowList::compatibility_iterator();
2621 // Can't navigate to sibling of this window
2622 // if we're a top-level window.
2623 if (!GetWindow()->GetParent())
2624 return wxACC_NOT_IMPLEMENTED
;
2626 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2630 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2631 node
= GetWindow()->GetChildren().Item(fromId
-1);
2634 if (node
&& node
->GetNext())
2636 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2637 *toObject
= nextWindow
->GetOrCreateAccessible();
2645 case wxNAVDIR_PREVIOUS
:
2647 wxWindowList::compatibility_iterator node
=
2648 wxWindowList::compatibility_iterator();
2651 // Can't navigate to sibling of this window
2652 // if we're a top-level window.
2653 if (!GetWindow()->GetParent())
2654 return wxACC_NOT_IMPLEMENTED
;
2656 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2660 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2661 node
= GetWindow()->GetChildren().Item(fromId
-1);
2664 if (node
&& node
->GetPrevious())
2666 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2667 *toObject
= previousWindow
->GetOrCreateAccessible();
2675 return wxACC_NOT_IMPLEMENTED
;
2678 // Gets the name of the specified object.
2679 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2681 wxASSERT( GetWindow() != NULL
);
2687 // If a child, leave wxWidgets to call the function on the actual
2690 return wxACC_NOT_IMPLEMENTED
;
2692 // This will eventually be replaced by specialised
2693 // accessible classes, one for each kind of wxWidgets
2694 // control or window.
2696 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2697 title
= ((wxButton
*) GetWindow())->GetLabel();
2700 title
= GetWindow()->GetName();
2708 return wxACC_NOT_IMPLEMENTED
;
2711 // Gets the number of children.
2712 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2714 wxASSERT( GetWindow() != NULL
);
2718 *childId
= (int) GetWindow()->GetChildren().GetCount();
2722 // Gets the specified child (starting from 1).
2723 // If *child is NULL and return value is wxACC_OK,
2724 // this means that the child is a simple element and
2725 // not an accessible object.
2726 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2728 wxASSERT( GetWindow() != NULL
);
2738 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2741 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2742 *child
= childWindow
->GetOrCreateAccessible();
2749 // Gets the parent, or NULL.
2750 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2752 wxASSERT( GetWindow() != NULL
);
2756 wxWindow
* parentWindow
= GetWindow()->GetParent();
2764 *parent
= parentWindow
->GetOrCreateAccessible();
2772 // Performs the default action. childId is 0 (the action for this object)
2773 // or > 0 (the action for a child).
2774 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2775 // window (e.g. an edit control).
2776 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2778 wxASSERT( GetWindow() != NULL
);
2782 return wxACC_NOT_IMPLEMENTED
;
2785 // Gets the default action for this object (0) or > 0 (the action for a child).
2786 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2787 // string if there is no action.
2788 // The retrieved string describes the action that is performed on an object,
2789 // not what the object does as a result. For example, a toolbar button that prints
2790 // a document has a default action of "Press" rather than "Prints the current document."
2791 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2793 wxASSERT( GetWindow() != NULL
);
2797 return wxACC_NOT_IMPLEMENTED
;
2800 // Returns the description for this object or a child.
2801 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2803 wxASSERT( GetWindow() != NULL
);
2807 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2813 return wxACC_NOT_IMPLEMENTED
;
2816 // Returns help text for this object or a child, similar to tooltip text.
2817 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2819 wxASSERT( GetWindow() != NULL
);
2823 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2829 return wxACC_NOT_IMPLEMENTED
;
2832 // Returns the keyboard shortcut for this object or child.
2833 // Return e.g. ALT+K
2834 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2836 wxASSERT( GetWindow() != NULL
);
2840 return wxACC_NOT_IMPLEMENTED
;
2843 // Returns a role constant.
2844 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2846 wxASSERT( GetWindow() != NULL
);
2850 // If a child, leave wxWidgets to call the function on the actual
2853 return wxACC_NOT_IMPLEMENTED
;
2855 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2856 return wxACC_NOT_IMPLEMENTED
;
2858 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2859 return wxACC_NOT_IMPLEMENTED
;
2862 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2863 return wxACC_NOT_IMPLEMENTED
;
2866 //*role = wxROLE_SYSTEM_CLIENT;
2867 *role
= wxROLE_SYSTEM_CLIENT
;
2871 return wxACC_NOT_IMPLEMENTED
;
2875 // Returns a state constant.
2876 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2878 wxASSERT( GetWindow() != NULL
);
2882 // If a child, leave wxWidgets to call the function on the actual
2885 return wxACC_NOT_IMPLEMENTED
;
2887 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2888 return wxACC_NOT_IMPLEMENTED
;
2891 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2892 return wxACC_NOT_IMPLEMENTED
;
2895 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2896 return wxACC_NOT_IMPLEMENTED
;
2903 return wxACC_NOT_IMPLEMENTED
;
2907 // Returns a localized string representing the value for the object
2909 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2911 wxASSERT( GetWindow() != NULL
);
2915 return wxACC_NOT_IMPLEMENTED
;
2918 // Selects the object or child.
2919 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2921 wxASSERT( GetWindow() != NULL
);
2925 return wxACC_NOT_IMPLEMENTED
;
2928 // Gets the window with the keyboard focus.
2929 // If childId is 0 and child is NULL, no object in
2930 // this subhierarchy has the focus.
2931 // If this object has the focus, child should be 'this'.
2932 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2934 wxASSERT( GetWindow() != NULL
);
2938 return wxACC_NOT_IMPLEMENTED
;
2941 // Gets a variant representing the selected children
2943 // Acceptable values:
2944 // - a null variant (IsNull() returns true)
2945 // - a list variant (GetType() == wxT("list")
2946 // - an integer representing the selected child element,
2947 // or 0 if this object is selected (GetType() == wxT("long")
2948 // - a "void*" pointer to a wxAccessible child object
2949 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2951 wxASSERT( GetWindow() != NULL
);
2955 return wxACC_NOT_IMPLEMENTED
;
2958 #endif // wxUSE_ACCESSIBILITY