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"
33 #include "wx/window.h"
34 #include "wx/control.h"
35 #include "wx/checkbox.h"
36 #include "wx/radiobut.h"
37 #include "wx/statbox.h"
38 #include "wx/textctrl.h"
39 #include "wx/settings.h"
40 #include "wx/dialog.h"
41 #include "wx/msgdlg.h"
42 #include "wx/statusbr.h"
43 #include "wx/toolbar.h"
44 #include "wx/dcclient.h"
47 #if defined(__WXMAC__) && wxUSE_SCROLLBAR
48 #include "wx/scrolbar.h"
52 #include "wx/layout.h"
53 #endif // wxUSE_CONSTRAINTS
57 #if wxUSE_DRAG_AND_DROP
59 #endif // wxUSE_DRAG_AND_DROP
61 #if wxUSE_ACCESSIBILITY
62 #include "wx/access.h"
66 #include "wx/cshelp.h"
70 #include "wx/tooltip.h"
71 #endif // wxUSE_TOOLTIPS
77 #if wxUSE_SYSTEM_OPTIONS
78 #include "wx/sysopt.h"
81 // For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog.
82 // The gtk includes don't pull any other headers in, at least not on my system - MR
85 #include <gtk/gtkversion.h>
87 #include <gtk/gtkfeatures.h>
89 extern const unsigned int gtk_major_version
;
90 extern const unsigned int gtk_minor_version
;
91 extern const unsigned int gtk_micro_version
;
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 #if defined(__WXPALMOS__)
99 int wxWindowBase::ms_lastControlId
= 32767;
100 #elif defined(__WXPM__)
101 int wxWindowBase::ms_lastControlId
= 2000;
103 int wxWindowBase::ms_lastControlId
= -200;
106 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
108 // ----------------------------------------------------------------------------
110 // ----------------------------------------------------------------------------
112 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
113 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
114 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
115 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
118 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
123 // ============================================================================
124 // implementation of the common functionality of the wxWindow class
125 // ============================================================================
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
131 // the default initialization
132 wxWindowBase::wxWindowBase()
134 // no window yet, no parent nor children
135 m_parent
= (wxWindow
*)NULL
;
136 m_windowId
= wxID_ANY
;
138 // no constraints on the minimal window size
140 m_maxWidth
= wxDefaultCoord
;
142 m_maxHeight
= wxDefaultCoord
;
144 // invalidiated cache value
145 m_bestSizeCache
= wxDefaultSize
;
147 // window are created enabled and visible by default
151 // the default event handler is just this window
152 m_eventHandler
= this;
156 m_windowValidator
= (wxValidator
*) NULL
;
157 #endif // wxUSE_VALIDATORS
159 // the colours/fonts are default for now, so leave m_font,
160 // m_backgroundColour and m_foregroundColour uninitialized and set those
166 m_inheritFont
= false;
172 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
174 #if wxUSE_CONSTRAINTS
175 // no constraints whatsoever
176 m_constraints
= (wxLayoutConstraints
*) NULL
;
177 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
178 #endif // wxUSE_CONSTRAINTS
180 m_windowSizer
= (wxSizer
*) NULL
;
181 m_containingSizer
= (wxSizer
*) NULL
;
182 m_autoLayout
= false;
184 #if wxUSE_DRAG_AND_DROP
185 m_dropTarget
= (wxDropTarget
*)NULL
;
186 #endif // wxUSE_DRAG_AND_DROP
189 m_tooltip
= (wxToolTip
*)NULL
;
190 #endif // wxUSE_TOOLTIPS
193 m_caret
= (wxCaret
*)NULL
;
194 #endif // wxUSE_CARET
197 m_hasCustomPalette
= false;
198 #endif // wxUSE_PALETTE
200 #if wxUSE_ACCESSIBILITY
204 m_virtualSize
= wxDefaultSize
;
207 m_maxVirtualWidth
= wxDefaultCoord
;
209 m_maxVirtualHeight
= wxDefaultCoord
;
211 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
212 #if wxUSE_SYSTEM_OPTIONS
213 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
215 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
219 // Whether we're using the current theme for this window (wxGTK only for now)
220 m_themeEnabled
= false;
222 // VZ: this one shouldn't exist...
223 m_isBeingDeleted
= false;
225 // Reserved for future use
226 m_windowReserved
= NULL
;
229 // common part of window creation process
230 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
232 const wxPoint
& WXUNUSED(pos
),
233 const wxSize
& WXUNUSED(size
),
235 const wxValidator
& wxVALIDATOR_PARAM(validator
),
236 const wxString
& name
)
239 // wxGTK doesn't allow to create controls with static box as the parent so
240 // this will result in a crash when the program is ported to wxGTK so warn
243 // if you get this assert, the correct solution is to create the controls
244 // as siblings of the static box
245 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
246 _T("wxStaticBox can't be used as a window parent!") );
247 #endif // wxUSE_STATBOX
249 // ids are limited to 16 bits under MSW so if you care about portability,
250 // it's not a good idea to use ids out of this range (and negative ids are
251 // reserved for wxWidgets own usage)
252 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
253 _T("invalid id value") );
255 // generate a new id if the user doesn't care about it
256 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
259 SetWindowStyleFlag(style
);
263 SetValidator(validator
);
264 #endif // wxUSE_VALIDATORS
266 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
267 // have it too - like this it's possible to set it only in the top level
268 // dialog/frame and all children will inherit it by defult
269 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
271 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
277 // ----------------------------------------------------------------------------
279 // ----------------------------------------------------------------------------
282 wxWindowBase::~wxWindowBase()
284 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
286 // FIXME if these 2 cases result from programming errors in the user code
287 // we should probably assert here instead of silently fixing them
289 // Just in case the window has been Closed, but we're then deleting
290 // immediately: don't leave dangling pointers.
291 wxPendingDelete
.DeleteObject(this);
293 // Just in case we've loaded a top-level window via LoadNativeDialog but
294 // we weren't a dialog class
295 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
297 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
299 // reset the dangling pointer our parent window may keep to us
302 if ( m_parent
->GetDefaultItem() == this )
304 m_parent
->SetDefaultItem(NULL
);
307 m_parent
->RemoveChild(this);
312 #endif // wxUSE_CARET
315 delete m_windowValidator
;
316 #endif // wxUSE_VALIDATORS
318 #if wxUSE_CONSTRAINTS
319 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
320 // at deleted windows as they delete themselves.
321 DeleteRelatedConstraints();
325 // This removes any dangling pointers to this window in other windows'
326 // constraintsInvolvedIn lists.
327 UnsetConstraints(m_constraints
);
328 delete m_constraints
;
329 m_constraints
= NULL
;
331 #endif // wxUSE_CONSTRAINTS
333 if ( m_containingSizer
)
334 m_containingSizer
->Detach( (wxWindow
*)this );
336 delete m_windowSizer
;
338 #if wxUSE_DRAG_AND_DROP
340 #endif // wxUSE_DRAG_AND_DROP
344 #endif // wxUSE_TOOLTIPS
346 #if wxUSE_ACCESSIBILITY
351 bool wxWindowBase::Destroy()
358 bool wxWindowBase::Close(bool force
)
360 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
361 event
.SetEventObject(this);
362 event
.SetCanVeto(!force
);
364 // return false if window wasn't closed because the application vetoed the
366 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
369 bool wxWindowBase::DestroyChildren()
371 wxWindowList::compatibility_iterator node
;
374 // we iterate until the list becomes empty
375 node
= GetChildren().GetFirst();
379 wxWindow
*child
= node
->GetData();
381 // note that we really want to call delete and not ->Destroy() here
382 // because we want to delete the child immediately, before we are
383 // deleted, and delayed deletion would result in problems as our (top
384 // level) child could outlive its parent
387 wxASSERT_MSG( !GetChildren().Find(child
),
388 wxT("child didn't remove itself using RemoveChild()") );
394 // ----------------------------------------------------------------------------
395 // size/position related methods
396 // ----------------------------------------------------------------------------
398 // centre the window with respect to its parent in either (or both) directions
399 void wxWindowBase::DoCentre(int dir
)
401 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
402 _T("this method only implements centering child windows") );
404 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
407 // fits the window around the children
408 void wxWindowBase::Fit()
410 if ( !GetChildren().empty() )
412 SetClientSize(GetBestSize());
414 //else: do nothing if we have no children
417 // fits virtual size (ie. scrolled area etc.) around children
418 void wxWindowBase::FitInside()
420 if ( GetChildren().GetCount() > 0 )
422 SetVirtualSize( GetBestVirtualSize() );
426 // On Mac, scrollbars are explicitly children.
428 static bool wxHasRealChildren(const wxWindowBase
* win
)
430 int realChildCount
= 0;
432 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
434 node
= node
->GetNext() )
436 wxWindow
*win
= node
->GetData();
437 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
440 return (realChildCount
> 0);
444 void wxWindowBase::InvalidateBestSize()
446 m_bestSizeCache
= wxDefaultSize
;
448 // parent's best size calculation may depend on its children's
449 // best sizes, so let's invalidate it as well to be safe:
451 m_parent
->InvalidateBestSize();
454 // return the size best suited for the current window
455 wxSize
wxWindowBase::DoGetBestSize() const
461 best
= GetWindowSizeForVirtualSize(m_windowSizer
->GetMinSize());
463 #if wxUSE_CONSTRAINTS
464 else if ( m_constraints
)
466 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
468 // our minimal acceptable size is such that all our windows fit inside
472 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
474 node
= node
->GetNext() )
476 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
479 // it's not normal that we have an unconstrained child, but
480 // what can we do about it?
484 int x
= c
->right
.GetValue(),
485 y
= c
->bottom
.GetValue();
493 // TODO: we must calculate the overlaps somehow, otherwise we
494 // will never return a size bigger than the current one :-(
497 best
= wxSize(maxX
, maxY
);
499 #endif // wxUSE_CONSTRAINTS
500 else if ( !GetChildren().empty()
502 && wxHasRealChildren(this)
506 // our minimal acceptable size is such that all our visible child windows fit inside
510 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
512 node
= node
->GetNext() )
514 wxWindow
*win
= node
->GetData();
515 if ( win
->IsTopLevel() || ( ! win
->IsShown() )
517 || wxDynamicCast(win
, wxStatusBar
)
518 #endif // wxUSE_STATUSBAR
521 // dialogs and frames lie in different top level windows -
522 // don't deal with them here; as for the status bars, they
523 // don't lie in the client area at all
528 win
->GetPosition(&wx
, &wy
);
530 // if the window hadn't been positioned yet, assume that it is in
532 if ( wx
== wxDefaultCoord
)
534 if ( wy
== wxDefaultCoord
)
537 win
->GetSize(&ww
, &wh
);
538 if ( wx
+ ww
> maxX
)
540 if ( wy
+ wh
> maxY
)
544 // for compatibility with the old versions and because it really looks
545 // slightly more pretty like this, add a pad
549 best
= wxSize(maxX
, maxY
);
551 else // ! has children
553 // for a generic window there is no natural best size so, if the
554 // minimal size is not set, use the current size but take care to
555 // remember it as minimal size for the next time because our best size
556 // should be constant: otherwise we could get into a situation when the
557 // window is initially at some size, then expanded to a larger size and
558 // then, when the containing window is shrunk back (because our initial
559 // best size had been used for computing the parent min size), we can't
560 // be shrunk back any more because our best size is now bigger
561 wxSize size
= GetMinSize();
562 if ( !size
.IsFullySpecified() )
564 size
.SetDefaults(GetSize());
565 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
568 // return as-is, unadjusted by the client size difference.
572 // Add any difference between size and client size
573 wxSize diff
= GetSize() - GetClientSize();
574 best
.x
+= wxMax(0, diff
.x
);
575 best
.y
+= wxMax(0, diff
.y
);
581 wxSize
wxWindowBase::GetBestFittingSize() const
583 // merge the best size with the min size, giving priority to the min size
584 wxSize min
= GetMinSize();
585 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
587 wxSize best
= GetBestSize();
588 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
589 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
595 void wxWindowBase::SetBestFittingSize(const wxSize
& size
)
597 // Set the min size to the size passed in. This will usually either be
598 // wxDefaultSize or the size passed to this window's ctor/Create function.
601 // Merge the size with the best size if needed
602 wxSize best
= GetBestFittingSize();
604 // If the current size doesn't match then change it
605 if (GetSize() != best
)
610 // by default the origin is not shifted
611 wxPoint
wxWindowBase::GetClientAreaOrigin() const
616 // set the min/max size of the window
617 void wxWindowBase::DoSetSizeHints(int minW
, int minH
,
619 int WXUNUSED(incW
), int WXUNUSED(incH
))
621 // setting min width greater than max width leads to infinite loops under
622 // X11 and generally doesn't make any sense, so don't allow it
623 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
624 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
625 _T("min width/height must be less than max width/height!") );
633 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
635 if ( m_windowVariant
!= variant
)
637 m_windowVariant
= variant
;
639 DoSetWindowVariant(variant
);
643 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
645 // adjust the font height to correspond to our new variant (notice that
646 // we're only called if something really changed)
647 wxFont font
= GetFont();
648 int size
= font
.GetPointSize();
651 case wxWINDOW_VARIANT_NORMAL
:
654 case wxWINDOW_VARIANT_SMALL
:
659 case wxWINDOW_VARIANT_MINI
:
664 case wxWINDOW_VARIANT_LARGE
:
670 wxFAIL_MSG(_T("unexpected window variant"));
674 font
.SetPointSize(size
);
678 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
681 m_minVirtualWidth
= minW
;
682 m_maxVirtualWidth
= maxW
;
683 m_minVirtualHeight
= minH
;
684 m_maxVirtualHeight
= maxH
;
687 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
689 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
690 x
= m_minVirtualWidth
;
691 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
692 x
= m_maxVirtualWidth
;
693 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
694 y
= m_minVirtualHeight
;
695 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
696 y
= m_maxVirtualHeight
;
698 m_virtualSize
= wxSize(x
, y
);
701 wxSize
wxWindowBase::DoGetVirtualSize() const
703 // we should use the entire client area so if it is greater than our
704 // virtual size, expand it to fit (otherwise if the window is big enough we
705 // wouldn't be using parts of it)
706 wxSize size
= GetClientSize();
707 if ( m_virtualSize
.x
> size
.x
)
708 size
.x
= m_virtualSize
.x
;
710 if ( m_virtualSize
.y
>= size
.y
)
711 size
.y
= m_virtualSize
.y
;
716 // ----------------------------------------------------------------------------
717 // show/hide/enable/disable the window
718 // ----------------------------------------------------------------------------
720 bool wxWindowBase::Show(bool show
)
722 if ( show
!= m_isShown
)
734 bool wxWindowBase::Enable(bool enable
)
736 if ( enable
!= m_isEnabled
)
738 m_isEnabled
= enable
;
747 // ----------------------------------------------------------------------------
749 // ----------------------------------------------------------------------------
751 bool wxWindowBase::IsTopLevel() const
756 // ----------------------------------------------------------------------------
757 // reparenting the window
758 // ----------------------------------------------------------------------------
760 void wxWindowBase::AddChild(wxWindowBase
*child
)
762 wxCHECK_RET( child
, wxT("can't add a NULL child") );
764 // this should never happen and it will lead to a crash later if it does
765 // because RemoveChild() will remove only one node from the children list
766 // and the other(s) one(s) will be left with dangling pointers in them
767 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
769 GetChildren().Append((wxWindow
*)child
);
770 child
->SetParent(this);
773 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
775 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
777 GetChildren().DeleteObject((wxWindow
*)child
);
778 child
->SetParent(NULL
);
781 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
783 wxWindow
*oldParent
= GetParent();
784 if ( newParent
== oldParent
)
790 // unlink this window from the existing parent.
793 oldParent
->RemoveChild(this);
797 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
800 // add it to the new one
803 newParent
->AddChild(this);
807 wxTopLevelWindows
.Append((wxWindow
*)this);
813 // ----------------------------------------------------------------------------
814 // event handler stuff
815 // ----------------------------------------------------------------------------
817 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
819 wxEvtHandler
*handlerOld
= GetEventHandler();
821 handler
->SetNextHandler(handlerOld
);
824 GetEventHandler()->SetPreviousHandler(handler
);
826 SetEventHandler(handler
);
829 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
831 wxEvtHandler
*handlerA
= GetEventHandler();
834 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
835 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
838 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
839 SetEventHandler(handlerB
);
844 handlerA
= (wxEvtHandler
*)NULL
;
851 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
853 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
855 wxEvtHandler
*handlerPrev
= NULL
,
856 *handlerCur
= GetEventHandler();
859 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
861 if ( handlerCur
== handler
)
865 handlerPrev
->SetNextHandler(handlerNext
);
869 SetEventHandler(handlerNext
);
874 handlerNext
->SetPreviousHandler ( handlerPrev
);
877 handler
->SetNextHandler(NULL
);
878 handler
->SetPreviousHandler(NULL
);
883 handlerPrev
= handlerCur
;
884 handlerCur
= handlerNext
;
887 wxFAIL_MSG( _T("where has the event handler gone?") );
892 // ----------------------------------------------------------------------------
894 // ----------------------------------------------------------------------------
896 void wxWindowBase::InheritAttributes()
898 const wxWindowBase
* const parent
= GetParent();
902 // we only inherit attributes which had been explicitly set for the parent
903 // which ensures that this only happens if the user really wants it and
904 // not by default which wouldn't make any sense in modern GUIs where the
905 // controls don't all use the same fonts (nor colours)
906 if ( parent
->m_inheritFont
&& !m_hasFont
)
907 SetFont(parent
->GetFont());
909 // in addition, there is a possibility to explicitly forbid inheriting
910 // colours at each class level by overriding ShouldInheritColours()
911 if ( ShouldInheritColours() )
913 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
914 SetForegroundColour(parent
->GetForegroundColour());
916 // inheriting (solid) background colour is wrong as it totally breaks
917 // any kind of themed backgrounds
919 // instead, the controls should use the same background as their parent
920 // (ideally by not drawing it at all)
922 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
923 SetBackgroundColour(parent
->GetBackgroundColour());
928 /* static */ wxVisualAttributes
929 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
931 // it is important to return valid values for all attributes from here,
932 // GetXXX() below rely on this
933 wxVisualAttributes attrs
;
934 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
935 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
937 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
938 // the usual background colour than wxSYS_COLOUR_BTNFACE.
939 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
940 // colour on other platforms.
942 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
943 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
945 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
950 wxColour
wxWindowBase::GetBackgroundColour() const
952 if ( !m_backgroundColour
.Ok() )
954 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
956 // get our default background colour
957 wxColour colBg
= GetDefaultAttributes().colBg
;
959 // we must return some valid colour to avoid redoing this every time
960 // and also to avoid surprizing the applications written for older
961 // wxWidgets versions where GetBackgroundColour() always returned
962 // something -- so give them something even if it doesn't make sense
963 // for this window (e.g. it has a themed background)
965 colBg
= GetClassDefaultAttributes().colBg
;
970 return m_backgroundColour
;
973 wxColour
wxWindowBase::GetForegroundColour() const
975 // logic is the same as above
976 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
978 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
980 wxColour colFg
= GetDefaultAttributes().colFg
;
983 colFg
= GetClassDefaultAttributes().colFg
;
988 return m_foregroundColour
;
991 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
993 if ( colour
== m_backgroundColour
)
996 m_hasBgCol
= colour
.Ok();
997 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
998 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1000 m_inheritBgCol
= m_hasBgCol
;
1001 m_backgroundColour
= colour
;
1002 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1006 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1008 if (colour
== m_foregroundColour
)
1011 m_hasFgCol
= colour
.Ok();
1012 m_inheritFgCol
= m_hasFgCol
;
1013 m_foregroundColour
= colour
;
1014 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1018 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1020 // setting an invalid cursor is ok, it means that we don't have any special
1022 if ( m_cursor
== cursor
)
1033 wxFont
wxWindowBase::GetFont() const
1035 // logic is the same as in GetBackgroundColour()
1038 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1040 wxFont font
= GetDefaultAttributes().font
;
1042 font
= GetClassDefaultAttributes().font
;
1050 bool wxWindowBase::SetFont(const wxFont
& font
)
1052 if ( font
== m_font
)
1059 m_hasFont
= font
.Ok();
1060 m_inheritFont
= m_hasFont
;
1062 InvalidateBestSize();
1069 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1071 m_hasCustomPalette
= true;
1074 // VZ: can anyone explain me what do we do here?
1075 wxWindowDC
d((wxWindow
*) this);
1079 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1081 wxWindow
*win
= (wxWindow
*)this;
1082 while ( win
&& !win
->HasCustomPalette() )
1084 win
= win
->GetParent();
1090 #endif // wxUSE_PALETTE
1093 void wxWindowBase::SetCaret(wxCaret
*caret
)
1104 wxASSERT_MSG( m_caret
->GetWindow() == this,
1105 wxT("caret should be created associated to this window") );
1108 #endif // wxUSE_CARET
1110 #if wxUSE_VALIDATORS
1111 // ----------------------------------------------------------------------------
1113 // ----------------------------------------------------------------------------
1115 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1117 if ( m_windowValidator
)
1118 delete m_windowValidator
;
1120 m_windowValidator
= (wxValidator
*)validator
.Clone();
1122 if ( m_windowValidator
)
1123 m_windowValidator
->SetWindow(this);
1125 #endif // wxUSE_VALIDATORS
1127 // ----------------------------------------------------------------------------
1128 // update region stuff
1129 // ----------------------------------------------------------------------------
1131 wxRect
wxWindowBase::GetUpdateClientRect() const
1133 wxRegion rgnUpdate
= GetUpdateRegion();
1134 rgnUpdate
.Intersect(GetClientRect());
1135 wxRect rectUpdate
= rgnUpdate
.GetBox();
1136 wxPoint ptOrigin
= GetClientAreaOrigin();
1137 rectUpdate
.x
-= ptOrigin
.x
;
1138 rectUpdate
.y
-= ptOrigin
.y
;
1143 bool wxWindowBase::IsExposed(int x
, int y
) const
1145 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1148 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1150 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1153 void wxWindowBase::ClearBackground()
1155 // wxGTK uses its own version, no need to add never used code
1157 wxClientDC
dc((wxWindow
*)this);
1158 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1159 dc
.SetBackground(brush
);
1164 // ----------------------------------------------------------------------------
1165 // find child window by id or name
1166 // ----------------------------------------------------------------------------
1168 wxWindow
*wxWindowBase::FindWindow(long id
) const
1170 if ( id
== m_windowId
)
1171 return (wxWindow
*)this;
1173 wxWindowBase
*res
= (wxWindow
*)NULL
;
1174 wxWindowList::compatibility_iterator node
;
1175 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1177 wxWindowBase
*child
= node
->GetData();
1178 res
= child
->FindWindow( id
);
1181 return (wxWindow
*)res
;
1184 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1186 if ( name
== m_windowName
)
1187 return (wxWindow
*)this;
1189 wxWindowBase
*res
= (wxWindow
*)NULL
;
1190 wxWindowList::compatibility_iterator node
;
1191 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1193 wxWindow
*child
= node
->GetData();
1194 res
= child
->FindWindow(name
);
1197 return (wxWindow
*)res
;
1201 // find any window by id or name or label: If parent is non-NULL, look through
1202 // children for a label or title matching the specified string. If NULL, look
1203 // through all top-level windows.
1205 // to avoid duplicating code we reuse the same helper function but with
1206 // different comparators
1208 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1209 const wxString
& label
, long id
);
1212 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1215 return win
->GetLabel() == label
;
1219 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1222 return win
->GetName() == label
;
1226 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1229 return win
->GetId() == id
;
1232 // recursive helper for the FindWindowByXXX() functions
1234 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1235 const wxString
& label
,
1237 wxFindWindowCmp cmp
)
1241 // see if this is the one we're looking for
1242 if ( (*cmp
)(parent
, label
, id
) )
1243 return (wxWindow
*)parent
;
1245 // It wasn't, so check all its children
1246 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1248 node
= node
->GetNext() )
1250 // recursively check each child
1251 wxWindow
*win
= (wxWindow
*)node
->GetData();
1252 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1262 // helper for FindWindowByXXX()
1264 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1265 const wxString
& label
,
1267 wxFindWindowCmp cmp
)
1271 // just check parent and all its children
1272 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1275 // start at very top of wx's windows
1276 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1278 node
= node
->GetNext() )
1280 // recursively check each window & its children
1281 wxWindow
*win
= node
->GetData();
1282 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1292 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1294 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1299 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1301 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1305 // fall back to the label
1306 win
= FindWindowByLabel(title
, parent
);
1314 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1316 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1319 // ----------------------------------------------------------------------------
1320 // dialog oriented functions
1321 // ----------------------------------------------------------------------------
1323 void wxWindowBase::MakeModal(bool modal
)
1325 // Disable all other windows
1328 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1331 wxWindow
*win
= node
->GetData();
1333 win
->Enable(!modal
);
1335 node
= node
->GetNext();
1340 bool wxWindowBase::Validate()
1342 #if wxUSE_VALIDATORS
1343 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1345 wxWindowList::compatibility_iterator node
;
1346 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1348 wxWindowBase
*child
= node
->GetData();
1349 wxValidator
*validator
= child
->GetValidator();
1350 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1355 if ( recurse
&& !child
->Validate() )
1360 #endif // wxUSE_VALIDATORS
1365 bool wxWindowBase::TransferDataToWindow()
1367 #if wxUSE_VALIDATORS
1368 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1370 wxWindowList::compatibility_iterator node
;
1371 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1373 wxWindowBase
*child
= node
->GetData();
1374 wxValidator
*validator
= child
->GetValidator();
1375 if ( validator
&& !validator
->TransferToWindow() )
1377 wxLogWarning(_("Could not transfer data to window"));
1379 wxLog::FlushActive();
1387 if ( !child
->TransferDataToWindow() )
1389 // warning already given
1394 #endif // wxUSE_VALIDATORS
1399 bool wxWindowBase::TransferDataFromWindow()
1401 #if wxUSE_VALIDATORS
1402 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1404 wxWindowList::compatibility_iterator node
;
1405 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1407 wxWindow
*child
= node
->GetData();
1408 wxValidator
*validator
= child
->GetValidator();
1409 if ( validator
&& !validator
->TransferFromWindow() )
1411 // nop warning here because the application is supposed to give
1412 // one itself - we don't know here what might have gone wrongly
1419 if ( !child
->TransferDataFromWindow() )
1421 // warning already given
1426 #endif // wxUSE_VALIDATORS
1431 void wxWindowBase::InitDialog()
1433 wxInitDialogEvent
event(GetId());
1434 event
.SetEventObject( this );
1435 GetEventHandler()->ProcessEvent(event
);
1438 // ----------------------------------------------------------------------------
1439 // context-sensitive help support
1440 // ----------------------------------------------------------------------------
1444 // associate this help text with this window
1445 void wxWindowBase::SetHelpText(const wxString
& text
)
1447 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1450 helpProvider
->AddHelp(this, text
);
1454 // associate this help text with all windows with the same id as this
1456 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1458 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1461 helpProvider
->AddHelp(GetId(), text
);
1465 // get the help string associated with this window (may be empty)
1466 wxString
wxWindowBase::GetHelpText() const
1469 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1472 text
= helpProvider
->GetHelp(this);
1478 // show help for this window
1479 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1481 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1484 if ( helpProvider
->ShowHelp(this) )
1486 // skip the event.Skip() below
1494 #endif // wxUSE_HELP
1496 // ----------------------------------------------------------------------------
1497 // tooltipsroot.Replace("\\", "/");
1498 // ----------------------------------------------------------------------------
1502 void wxWindowBase::SetToolTip( const wxString
&tip
)
1504 // don't create the new tooltip if we already have one
1507 m_tooltip
->SetTip( tip
);
1511 SetToolTip( new wxToolTip( tip
) );
1514 // setting empty tooltip text does not remove the tooltip any more - use
1515 // SetToolTip((wxToolTip *)NULL) for this
1518 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1523 m_tooltip
= tooltip
;
1526 #endif // wxUSE_TOOLTIPS
1528 // ----------------------------------------------------------------------------
1529 // constraints and sizers
1530 // ----------------------------------------------------------------------------
1532 #if wxUSE_CONSTRAINTS
1534 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1536 if ( m_constraints
)
1538 UnsetConstraints(m_constraints
);
1539 delete m_constraints
;
1541 m_constraints
= constraints
;
1542 if ( m_constraints
)
1544 // Make sure other windows know they're part of a 'meaningful relationship'
1545 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1546 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1547 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1548 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1549 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1550 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1551 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1552 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1553 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1554 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1555 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1556 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1557 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1558 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1559 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1560 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1564 // This removes any dangling pointers to this window in other windows'
1565 // constraintsInvolvedIn lists.
1566 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1570 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1571 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1572 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1573 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1574 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1575 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1576 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1577 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1578 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1579 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1580 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1581 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1582 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1583 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1584 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1585 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1589 // Back-pointer to other windows we're involved with, so if we delete this
1590 // window, we must delete any constraints we're involved with.
1591 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1593 if ( !m_constraintsInvolvedIn
)
1594 m_constraintsInvolvedIn
= new wxWindowList
;
1595 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1596 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1599 // REMOVE back-pointer to other windows we're involved with.
1600 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1602 if ( m_constraintsInvolvedIn
)
1603 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1606 // Reset any constraints that mention this window
1607 void wxWindowBase::DeleteRelatedConstraints()
1609 if ( m_constraintsInvolvedIn
)
1611 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1614 wxWindow
*win
= node
->GetData();
1615 wxLayoutConstraints
*constr
= win
->GetConstraints();
1617 // Reset any constraints involving this window
1620 constr
->left
.ResetIfWin(this);
1621 constr
->top
.ResetIfWin(this);
1622 constr
->right
.ResetIfWin(this);
1623 constr
->bottom
.ResetIfWin(this);
1624 constr
->width
.ResetIfWin(this);
1625 constr
->height
.ResetIfWin(this);
1626 constr
->centreX
.ResetIfWin(this);
1627 constr
->centreY
.ResetIfWin(this);
1630 wxWindowList::compatibility_iterator next
= node
->GetNext();
1631 m_constraintsInvolvedIn
->Erase(node
);
1635 delete m_constraintsInvolvedIn
;
1636 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1640 #endif // wxUSE_CONSTRAINTS
1642 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1644 if ( sizer
== m_windowSizer
)
1648 delete m_windowSizer
;
1650 m_windowSizer
= sizer
;
1652 SetAutoLayout( sizer
!= NULL
);
1655 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1657 SetSizer( sizer
, deleteOld
);
1658 sizer
->SetSizeHints( (wxWindow
*) this );
1662 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1664 // adding a window to a sizer twice is going to result in fatal and
1665 // hard to debug problems later because when deleting the second
1666 // associated wxSizerItem we're going to dereference a dangling
1667 // pointer; so try to detect this as early as possible
1668 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1669 _T("Adding a window to the same sizer twice?") );
1671 m_containingSizer
= sizer
;
1674 #if wxUSE_CONSTRAINTS
1676 void wxWindowBase::SatisfyConstraints()
1678 wxLayoutConstraints
*constr
= GetConstraints();
1679 bool wasOk
= constr
&& constr
->AreSatisfied();
1681 ResetConstraints(); // Mark all constraints as unevaluated
1685 // if we're a top level panel (i.e. our parent is frame/dialog), our
1686 // own constraints will never be satisfied any more unless we do it
1690 while ( noChanges
> 0 )
1692 LayoutPhase1(&noChanges
);
1696 LayoutPhase2(&noChanges
);
1699 #endif // wxUSE_CONSTRAINTS
1701 bool wxWindowBase::Layout()
1703 // If there is a sizer, use it instead of the constraints
1707 GetVirtualSize(&w
, &h
);
1708 GetSizer()->SetDimension( 0, 0, w
, h
);
1710 #if wxUSE_CONSTRAINTS
1713 SatisfyConstraints(); // Find the right constraints values
1714 SetConstraintSizes(); // Recursively set the real window sizes
1721 #if wxUSE_CONSTRAINTS
1723 // first phase of the constraints evaluation: set our own constraints
1724 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1726 wxLayoutConstraints
*constr
= GetConstraints();
1728 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1731 // second phase: set the constraints for our children
1732 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1739 // Layout grand children
1745 // Do a phase of evaluating child constraints
1746 bool wxWindowBase::DoPhase(int phase
)
1748 // the list containing the children for which the constraints are already
1750 wxWindowList succeeded
;
1752 // the max number of iterations we loop before concluding that we can't set
1754 static const int maxIterations
= 500;
1756 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1760 // loop over all children setting their constraints
1761 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1763 node
= node
->GetNext() )
1765 wxWindow
*child
= node
->GetData();
1766 if ( child
->IsTopLevel() )
1768 // top level children are not inside our client area
1772 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1774 // this one is either already ok or nothing we can do about it
1778 int tempNoChanges
= 0;
1779 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1780 : child
->LayoutPhase2(&tempNoChanges
);
1781 noChanges
+= tempNoChanges
;
1785 succeeded
.Append(child
);
1791 // constraints are set
1799 void wxWindowBase::ResetConstraints()
1801 wxLayoutConstraints
*constr
= GetConstraints();
1804 constr
->left
.SetDone(false);
1805 constr
->top
.SetDone(false);
1806 constr
->right
.SetDone(false);
1807 constr
->bottom
.SetDone(false);
1808 constr
->width
.SetDone(false);
1809 constr
->height
.SetDone(false);
1810 constr
->centreX
.SetDone(false);
1811 constr
->centreY
.SetDone(false);
1814 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1817 wxWindow
*win
= node
->GetData();
1818 if ( !win
->IsTopLevel() )
1819 win
->ResetConstraints();
1820 node
= node
->GetNext();
1824 // Need to distinguish between setting the 'fake' size for windows and sizers,
1825 // and setting the real values.
1826 void wxWindowBase::SetConstraintSizes(bool recurse
)
1828 wxLayoutConstraints
*constr
= GetConstraints();
1829 if ( constr
&& constr
->AreSatisfied() )
1831 int x
= constr
->left
.GetValue();
1832 int y
= constr
->top
.GetValue();
1833 int w
= constr
->width
.GetValue();
1834 int h
= constr
->height
.GetValue();
1836 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1837 (constr
->height
.GetRelationship() != wxAsIs
) )
1839 SetSize(x
, y
, w
, h
);
1843 // If we don't want to resize this window, just move it...
1849 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1850 GetClassInfo()->GetClassName(),
1856 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1859 wxWindow
*win
= node
->GetData();
1860 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1861 win
->SetConstraintSizes();
1862 node
= node
->GetNext();
1867 // Only set the size/position of the constraint (if any)
1868 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1870 wxLayoutConstraints
*constr
= GetConstraints();
1873 if ( x
!= wxDefaultCoord
)
1875 constr
->left
.SetValue(x
);
1876 constr
->left
.SetDone(true);
1878 if ( y
!= wxDefaultCoord
)
1880 constr
->top
.SetValue(y
);
1881 constr
->top
.SetDone(true);
1883 if ( w
!= wxDefaultCoord
)
1885 constr
->width
.SetValue(w
);
1886 constr
->width
.SetDone(true);
1888 if ( h
!= wxDefaultCoord
)
1890 constr
->height
.SetValue(h
);
1891 constr
->height
.SetDone(true);
1896 void wxWindowBase::MoveConstraint(int x
, int y
)
1898 wxLayoutConstraints
*constr
= GetConstraints();
1901 if ( x
!= wxDefaultCoord
)
1903 constr
->left
.SetValue(x
);
1904 constr
->left
.SetDone(true);
1906 if ( y
!= wxDefaultCoord
)
1908 constr
->top
.SetValue(y
);
1909 constr
->top
.SetDone(true);
1914 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1916 wxLayoutConstraints
*constr
= GetConstraints();
1919 *w
= constr
->width
.GetValue();
1920 *h
= constr
->height
.GetValue();
1926 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1928 wxLayoutConstraints
*constr
= GetConstraints();
1931 *w
= constr
->width
.GetValue();
1932 *h
= constr
->height
.GetValue();
1935 GetClientSize(w
, h
);
1938 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1940 wxLayoutConstraints
*constr
= GetConstraints();
1943 *x
= constr
->left
.GetValue();
1944 *y
= constr
->top
.GetValue();
1950 #endif // wxUSE_CONSTRAINTS
1952 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1954 // don't do it for the dialogs/frames - they float independently of their
1956 if ( !IsTopLevel() )
1958 wxWindow
*parent
= GetParent();
1959 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1961 wxPoint
pt(parent
->GetClientAreaOrigin());
1968 // ----------------------------------------------------------------------------
1969 // do Update UI processing for child controls
1970 // ----------------------------------------------------------------------------
1972 void wxWindowBase::UpdateWindowUI(long flags
)
1974 wxUpdateUIEvent
event(GetId());
1975 event
.SetEventObject(this);
1977 if ( GetEventHandler()->ProcessEvent(event
) )
1979 DoUpdateWindowUI(event
);
1982 if (flags
& wxUPDATE_UI_RECURSE
)
1984 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1987 wxWindow
* child
= (wxWindow
*) node
->GetData();
1988 child
->UpdateWindowUI(flags
);
1989 node
= node
->GetNext();
1994 // do the window-specific processing after processing the update event
1995 // TODO: take specific knowledge out of this function and
1996 // put in each control's base class. Unfortunately we don't
1997 // yet have base implementation files for wxCheckBox and wxRadioButton.
1998 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2000 if ( event
.GetSetEnabled() )
2001 Enable(event
.GetEnabled());
2004 if ( event
.GetSetText() )
2006 wxControl
*control
= wxDynamicCastThis(wxControl
);
2009 if ( event
.GetText() != control
->GetLabel() )
2010 control
->SetLabel(event
.GetText());
2013 #endif // wxUSE_CONTROLS
2015 if ( event
.GetSetChecked() )
2018 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
2021 checkbox
->SetValue(event
.GetChecked());
2023 #endif // wxUSE_CHECKBOX
2026 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
2029 radiobtn
->SetValue(event
.GetChecked());
2031 #endif // wxUSE_RADIOBTN
2036 // call internal idle recursively
2037 // may be obsolete (wait until OnIdle scheme stabilises)
2038 void wxWindowBase::ProcessInternalIdle()
2042 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2045 wxWindow
*child
= node
->GetData();
2046 child
->ProcessInternalIdle();
2047 node
= node
->GetNext();
2052 // ----------------------------------------------------------------------------
2053 // dialog units translations
2054 // ----------------------------------------------------------------------------
2056 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2058 int charWidth
= GetCharWidth();
2059 int charHeight
= GetCharHeight();
2060 wxPoint pt2
= wxDefaultPosition
;
2061 if (pt
.x
!= wxDefaultCoord
)
2062 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2063 if (pt
.y
!= wxDefaultCoord
)
2064 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2069 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2071 int charWidth
= GetCharWidth();
2072 int charHeight
= GetCharHeight();
2073 wxPoint pt2
= wxDefaultPosition
;
2074 if (pt
.x
!= wxDefaultCoord
)
2075 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2076 if (pt
.y
!= wxDefaultCoord
)
2077 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2082 // ----------------------------------------------------------------------------
2084 // ----------------------------------------------------------------------------
2086 // propagate the colour change event to the subwindows
2087 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2089 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2092 // Only propagate to non-top-level windows
2093 wxWindow
*win
= node
->GetData();
2094 if ( !win
->IsTopLevel() )
2096 wxSysColourChangedEvent event2
;
2097 event
.SetEventObject(win
);
2098 win
->GetEventHandler()->ProcessEvent(event2
);
2101 node
= node
->GetNext();
2107 // the default action is to populate dialog with data when it's created,
2108 // and nudge the UI into displaying itself correctly in case
2109 // we've turned the wxUpdateUIEvents frequency down low.
2110 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2112 TransferDataToWindow();
2114 // Update the UI at this point
2115 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2118 // methods for drawing the sizers in a visible way
2121 static void DrawSizers(wxWindowBase
*win
);
2123 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2125 wxClientDC
dc((wxWindow
*)win
);
2126 dc
.SetPen(*wxRED_PEN
);
2127 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2128 dc
.DrawRectangle(rect
.Deflate(1, 1));
2131 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2133 const wxSizerItemList
& items
= sizer
->GetChildren();
2134 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2139 wxSizerItem
*item
= *i
;
2140 if ( item
->IsSizer() )
2142 DrawBorder(win
, item
->GetRect().Deflate(2));
2143 DrawSizer(win
, item
->GetSizer());
2145 else if ( item
->IsSpacer() )
2147 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2149 else if ( item
->IsWindow() )
2151 DrawSizers(item
->GetWindow());
2156 static void DrawSizers(wxWindowBase
*win
)
2158 wxSizer
*sizer
= win
->GetSizer();
2161 DrawBorder(win
, win
->GetClientSize());
2162 DrawSizer(win
, sizer
);
2164 else // no sizer, still recurse into the children
2166 const wxWindowList
& children
= win
->GetChildren();
2167 for ( wxWindowList::const_iterator i
= children
.begin(),
2168 end
= children
.end();
2177 #endif // __WXDEBUG__
2179 // process special middle clicks
2180 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2182 if ( event
.ControlDown() && event
.AltDown() )
2185 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2186 if ( event
.ShiftDown() )
2191 #endif // __WXDEBUG__
2194 // don't translate these strings
2197 #ifdef __WXUNIVERSAL__
2199 #endif // __WXUNIVERSAL__
2201 switch ( wxGetOsVersion() )
2203 case wxMOTIF_X
: port
+= _T("Motif"); break;
2205 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2206 case wxBEOS
: port
+= _T("BeOS"); break;
2210 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2216 case wxWIN386
: port
+= _T("MS Windows"); break;
2220 case wxMGL_OS2
: port
+= _T("MGL"); break;
2222 case wxOS2_PM
: port
+= _T("OS/2"); break;
2223 case wxPALMOS
: port
+= _T("Palm OS"); break;
2224 case wxWINDOWS_CE
: port
+= _T("Windows CE (generic)"); break;
2225 case wxWINDOWS_POCKETPC
: port
+= _T("Windows CE PocketPC"); break;
2226 case wxWINDOWS_SMARTPHONE
: port
+= _T("Windows CE Smartphone"); break;
2227 default: port
+= _T("unknown"); break;
2230 wxMessageBox(wxString::Format(
2232 " wxWidgets Library (%s port)\nVersion %d.%d.%d%s%s, compiled at %s %s%s\n Copyright (c) 1995-2006 wxWidgets team"
2251 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()
2256 _T("wxWidgets information"),
2257 wxICON_INFORMATION
| wxOK
,
2261 #endif // wxUSE_MSGDLG
2267 // ----------------------------------------------------------------------------
2269 // ----------------------------------------------------------------------------
2271 #if wxUSE_ACCESSIBILITY
2272 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2274 if (m_accessible
&& (accessible
!= m_accessible
))
2275 delete m_accessible
;
2276 m_accessible
= accessible
;
2278 m_accessible
->SetWindow((wxWindow
*) this);
2281 // Returns the accessible object, creating if necessary.
2282 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2285 m_accessible
= CreateAccessible();
2286 return m_accessible
;
2289 // Override to create a specific accessible object.
2290 wxAccessible
* wxWindowBase::CreateAccessible()
2292 return new wxWindowAccessible((wxWindow
*) this);
2297 // ----------------------------------------------------------------------------
2298 // list classes implementation
2299 // ----------------------------------------------------------------------------
2303 #include "wx/listimpl.cpp"
2304 WX_DEFINE_LIST(wxWindowList
)
2308 void wxWindowListNode::DeleteData()
2310 delete (wxWindow
*)GetData();
2315 // ----------------------------------------------------------------------------
2317 // ----------------------------------------------------------------------------
2319 wxBorder
wxWindowBase::GetBorder(long flags
) const
2321 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2322 if ( border
== wxBORDER_DEFAULT
)
2324 border
= GetDefaultBorder();
2330 wxBorder
wxWindowBase::GetDefaultBorder() const
2332 return wxBORDER_NONE
;
2335 // ----------------------------------------------------------------------------
2337 // ----------------------------------------------------------------------------
2339 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2341 // here we just check if the point is inside the window or not
2343 // check the top and left border first
2344 bool outside
= x
< 0 || y
< 0;
2347 // check the right and bottom borders too
2348 wxSize size
= GetSize();
2349 outside
= x
>= size
.x
|| y
>= size
.y
;
2352 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2355 // ----------------------------------------------------------------------------
2357 // ----------------------------------------------------------------------------
2359 struct WXDLLEXPORT wxWindowNext
2363 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2365 void wxWindowBase::CaptureMouse()
2367 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2369 wxWindow
*winOld
= GetCapture();
2372 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2375 wxWindowNext
*item
= new wxWindowNext
;
2377 item
->next
= ms_winCaptureNext
;
2378 ms_winCaptureNext
= item
;
2380 //else: no mouse capture to save
2385 void wxWindowBase::ReleaseMouse()
2387 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2389 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2393 if ( ms_winCaptureNext
)
2395 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2397 wxWindowNext
*item
= ms_winCaptureNext
;
2398 ms_winCaptureNext
= item
->next
;
2401 //else: stack is empty, no previous capture
2403 wxLogTrace(_T("mousecapture"),
2404 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2411 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2412 int WXUNUSED(modifiers
),
2413 int WXUNUSED(keycode
))
2419 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2425 #endif // wxUSE_HOTKEY
2427 void wxWindowBase::SendDestroyEvent()
2429 wxWindowDestroyEvent event
;
2430 event
.SetEventObject(this);
2431 event
.SetId(GetId());
2432 GetEventHandler()->ProcessEvent(event
);
2435 // ----------------------------------------------------------------------------
2437 // ----------------------------------------------------------------------------
2439 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2441 #if wxUSE_VALIDATORS
2442 // Can only use the validator of the window which
2443 // is receiving the event
2444 if ( event
.GetEventObject() == this )
2446 wxValidator
*validator
= GetValidator();
2447 if ( validator
&& validator
->ProcessEvent(event
) )
2452 #endif // wxUSE_VALIDATORS
2457 bool wxWindowBase::TryParent(wxEvent
& event
)
2459 // carry on up the parent-child hierarchy if the propagation count hasn't
2461 if ( event
.ShouldPropagate() )
2463 // honour the requests to stop propagation at this window: this is
2464 // used by the dialogs, for example, to prevent processing the events
2465 // from the dialog controls in the parent frame which rarely, if ever,
2467 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2469 wxWindow
*parent
= GetParent();
2470 if ( parent
&& !parent
->IsBeingDeleted() )
2472 wxPropagateOnce
propagateOnce(event
);
2474 return parent
->GetEventHandler()->ProcessEvent(event
);
2479 return wxEvtHandler::TryParent(event
);
2482 // ----------------------------------------------------------------------------
2483 // keyboard navigation
2484 // ----------------------------------------------------------------------------
2486 // Navigates in the specified direction.
2487 bool wxWindowBase::Navigate(int flags
)
2489 wxNavigationKeyEvent eventNav
;
2490 eventNav
.SetFlags(flags
);
2491 eventNav
.SetEventObject(this);
2492 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2499 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2501 // check that we're not a top level window
2502 wxCHECK_RET( GetParent(),
2503 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2505 // detect the special case when we have nothing to do anyhow and when the
2506 // code below wouldn't work
2510 // find the target window in the siblings list
2511 wxWindowList
& siblings
= GetParent()->GetChildren();
2512 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2513 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2515 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2516 // can't just move the node around
2517 wxWindow
*self
= (wxWindow
*)this;
2518 siblings
.DeleteObject(self
);
2519 if ( move
== MoveAfter
)
2526 siblings
.Insert(i
, self
);
2528 else // MoveAfter and win was the last sibling
2530 siblings
.Append(self
);
2534 // ----------------------------------------------------------------------------
2536 // ----------------------------------------------------------------------------
2538 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2540 wxWindowBase
*win
= DoFindFocus();
2541 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2544 // ----------------------------------------------------------------------------
2546 // ----------------------------------------------------------------------------
2548 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2550 while ( win
&& !win
->IsTopLevel() )
2551 win
= win
->GetParent();
2556 #if wxUSE_ACCESSIBILITY
2557 // ----------------------------------------------------------------------------
2558 // accessible object for windows
2559 // ----------------------------------------------------------------------------
2561 // Can return either a child object, or an integer
2562 // representing the child element, starting from 1.
2563 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2565 wxASSERT( GetWindow() != NULL
);
2569 return wxACC_NOT_IMPLEMENTED
;
2572 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2573 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2575 wxASSERT( GetWindow() != NULL
);
2579 wxWindow
* win
= NULL
;
2586 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2588 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2595 rect
= win
->GetRect();
2596 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2597 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2601 return wxACC_NOT_IMPLEMENTED
;
2604 // Navigates from fromId to toId/toObject.
2605 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2606 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2608 wxASSERT( GetWindow() != NULL
);
2614 case wxNAVDIR_FIRSTCHILD
:
2616 if (GetWindow()->GetChildren().GetCount() == 0)
2618 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2619 *toObject
= childWindow
->GetOrCreateAccessible();
2623 case wxNAVDIR_LASTCHILD
:
2625 if (GetWindow()->GetChildren().GetCount() == 0)
2627 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2628 *toObject
= childWindow
->GetOrCreateAccessible();
2632 case wxNAVDIR_RIGHT
:
2636 wxWindowList::compatibility_iterator node
=
2637 wxWindowList::compatibility_iterator();
2640 // Can't navigate to sibling of this window
2641 // if we're a top-level window.
2642 if (!GetWindow()->GetParent())
2643 return wxACC_NOT_IMPLEMENTED
;
2645 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2649 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2650 node
= GetWindow()->GetChildren().Item(fromId
-1);
2653 if (node
&& node
->GetNext())
2655 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2656 *toObject
= nextWindow
->GetOrCreateAccessible();
2664 case wxNAVDIR_PREVIOUS
:
2666 wxWindowList::compatibility_iterator node
=
2667 wxWindowList::compatibility_iterator();
2670 // Can't navigate to sibling of this window
2671 // if we're a top-level window.
2672 if (!GetWindow()->GetParent())
2673 return wxACC_NOT_IMPLEMENTED
;
2675 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2679 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2680 node
= GetWindow()->GetChildren().Item(fromId
-1);
2683 if (node
&& node
->GetPrevious())
2685 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2686 *toObject
= previousWindow
->GetOrCreateAccessible();
2694 return wxACC_NOT_IMPLEMENTED
;
2697 // Gets the name of the specified object.
2698 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2700 wxASSERT( GetWindow() != NULL
);
2706 // If a child, leave wxWidgets to call the function on the actual
2709 return wxACC_NOT_IMPLEMENTED
;
2711 // This will eventually be replaced by specialised
2712 // accessible classes, one for each kind of wxWidgets
2713 // control or window.
2715 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2716 title
= ((wxButton
*) GetWindow())->GetLabel();
2719 title
= GetWindow()->GetName();
2727 return wxACC_NOT_IMPLEMENTED
;
2730 // Gets the number of children.
2731 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2733 wxASSERT( GetWindow() != NULL
);
2737 *childId
= (int) GetWindow()->GetChildren().GetCount();
2741 // Gets the specified child (starting from 1).
2742 // If *child is NULL and return value is wxACC_OK,
2743 // this means that the child is a simple element and
2744 // not an accessible object.
2745 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2747 wxASSERT( GetWindow() != NULL
);
2757 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2760 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2761 *child
= childWindow
->GetOrCreateAccessible();
2768 // Gets the parent, or NULL.
2769 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2771 wxASSERT( GetWindow() != NULL
);
2775 wxWindow
* parentWindow
= GetWindow()->GetParent();
2783 *parent
= parentWindow
->GetOrCreateAccessible();
2791 // Performs the default action. childId is 0 (the action for this object)
2792 // or > 0 (the action for a child).
2793 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2794 // window (e.g. an edit control).
2795 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2797 wxASSERT( GetWindow() != NULL
);
2801 return wxACC_NOT_IMPLEMENTED
;
2804 // Gets the default action for this object (0) or > 0 (the action for a child).
2805 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2806 // string if there is no action.
2807 // The retrieved string describes the action that is performed on an object,
2808 // not what the object does as a result. For example, a toolbar button that prints
2809 // a document has a default action of "Press" rather than "Prints the current document."
2810 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2812 wxASSERT( GetWindow() != NULL
);
2816 return wxACC_NOT_IMPLEMENTED
;
2819 // Returns the description for this object or a child.
2820 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2822 wxASSERT( GetWindow() != NULL
);
2826 wxString
ht(GetWindow()->GetHelpText());
2832 return wxACC_NOT_IMPLEMENTED
;
2835 // Returns help text for this object or a child, similar to tooltip text.
2836 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2838 wxASSERT( GetWindow() != NULL
);
2842 wxString
ht(GetWindow()->GetHelpText());
2848 return wxACC_NOT_IMPLEMENTED
;
2851 // Returns the keyboard shortcut for this object or child.
2852 // Return e.g. ALT+K
2853 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2855 wxASSERT( GetWindow() != NULL
);
2859 return wxACC_NOT_IMPLEMENTED
;
2862 // Returns a role constant.
2863 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
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
;
2877 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2878 return wxACC_NOT_IMPLEMENTED
;
2881 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2882 return wxACC_NOT_IMPLEMENTED
;
2885 //*role = wxROLE_SYSTEM_CLIENT;
2886 *role
= wxROLE_SYSTEM_CLIENT
;
2890 return wxACC_NOT_IMPLEMENTED
;
2894 // Returns a state constant.
2895 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2897 wxASSERT( GetWindow() != NULL
);
2901 // If a child, leave wxWidgets to call the function on the actual
2904 return wxACC_NOT_IMPLEMENTED
;
2906 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2907 return wxACC_NOT_IMPLEMENTED
;
2910 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2911 return wxACC_NOT_IMPLEMENTED
;
2914 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2915 return wxACC_NOT_IMPLEMENTED
;
2922 return wxACC_NOT_IMPLEMENTED
;
2926 // Returns a localized string representing the value for the object
2928 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2930 wxASSERT( GetWindow() != NULL
);
2934 return wxACC_NOT_IMPLEMENTED
;
2937 // Selects the object or child.
2938 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2940 wxASSERT( GetWindow() != NULL
);
2944 return wxACC_NOT_IMPLEMENTED
;
2947 // Gets the window with the keyboard focus.
2948 // If childId is 0 and child is NULL, no object in
2949 // this subhierarchy has the focus.
2950 // If this object has the focus, child should be 'this'.
2951 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2953 wxASSERT( GetWindow() != NULL
);
2957 return wxACC_NOT_IMPLEMENTED
;
2960 // Gets a variant representing the selected children
2962 // Acceptable values:
2963 // - a null variant (IsNull() returns true)
2964 // - a list variant (GetType() == wxT("list")
2965 // - an integer representing the selected child element,
2966 // or 0 if this object is selected (GetType() == wxT("long")
2967 // - a "void*" pointer to a wxAccessible child object
2968 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2970 wxASSERT( GetWindow() != NULL
);
2974 return wxACC_NOT_IMPLEMENTED
;
2977 #endif // wxUSE_ACCESSIBILITY