1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "windowbase.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/string.h"
37 #include "wx/window.h"
38 #include "wx/control.h"
39 #include "wx/checkbox.h"
40 #include "wx/radiobut.h"
41 #include "wx/statbox.h"
42 #include "wx/textctrl.h"
43 #include "wx/settings.h"
44 #include "wx/dialog.h"
45 #include "wx/msgdlg.h"
46 #include "wx/statusbr.h"
47 #include "wx/dcclient.h"
50 #if defined(__WXMAC__) && wxUSE_SCROLLBAR
51 #include "wx/scrolbar.h"
55 #include "wx/layout.h"
56 #endif // wxUSE_CONSTRAINTS
60 #if wxUSE_DRAG_AND_DROP
62 #endif // wxUSE_DRAG_AND_DROP
64 #if wxUSE_ACCESSIBILITY
65 #include "wx/access.h"
69 #include "wx/cshelp.h"
73 #include "wx/tooltip.h"
74 #endif // wxUSE_TOOLTIPS
81 #include "wx/display.h"
84 #if wxUSE_SYSTEM_OPTIONS
85 #include "wx/sysopt.h"
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 #if defined(__WXPALMOS__)
93 int wxWindowBase::ms_lastControlId
= 32767;
94 #elif defined(__WXPM__)
95 int wxWindowBase::ms_lastControlId
= 2000;
97 int wxWindowBase::ms_lastControlId
= -200;
100 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
107 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
108 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
109 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
112 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
117 // ============================================================================
118 // implementation of the common functionality of the wxWindow class
119 // ============================================================================
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 // the default initialization
126 wxWindowBase::wxWindowBase()
128 // no window yet, no parent nor children
129 m_parent
= (wxWindow
*)NULL
;
130 m_windowId
= wxID_ANY
;
132 // no constraints on the minimal window size
134 m_maxWidth
= wxDefaultCoord
;
136 m_maxHeight
= wxDefaultCoord
;
138 // invalidiated cache value
139 m_bestSizeCache
= wxDefaultSize
;
141 // window are created enabled and visible by default
145 // the default event handler is just this window
146 m_eventHandler
= this;
150 m_windowValidator
= (wxValidator
*) NULL
;
151 #endif // wxUSE_VALIDATORS
153 // the colours/fonts are default for now, so leave m_font,
154 // m_backgroundColour and m_foregroundColour uninitialized and set those
160 m_inheritFont
= false;
166 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
168 #if wxUSE_CONSTRAINTS
169 // no constraints whatsoever
170 m_constraints
= (wxLayoutConstraints
*) NULL
;
171 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
172 #endif // wxUSE_CONSTRAINTS
174 m_windowSizer
= (wxSizer
*) NULL
;
175 m_containingSizer
= (wxSizer
*) NULL
;
176 m_autoLayout
= false;
178 #if wxUSE_DRAG_AND_DROP
179 m_dropTarget
= (wxDropTarget
*)NULL
;
180 #endif // wxUSE_DRAG_AND_DROP
183 m_tooltip
= (wxToolTip
*)NULL
;
184 #endif // wxUSE_TOOLTIPS
187 m_caret
= (wxCaret
*)NULL
;
188 #endif // wxUSE_CARET
191 m_hasCustomPalette
= false;
192 #endif // wxUSE_PALETTE
194 #if wxUSE_ACCESSIBILITY
198 m_virtualSize
= wxDefaultSize
;
201 m_maxVirtualWidth
= wxDefaultCoord
;
203 m_maxVirtualHeight
= wxDefaultCoord
;
205 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
206 #if wxUSE_SYSTEM_OPTIONS
207 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
209 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
213 // Whether we're using the current theme for this window (wxGTK only for now)
214 m_themeEnabled
= false;
216 // VZ: this one shouldn't exist...
217 m_isBeingDeleted
= false;
220 // common part of window creation process
221 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
223 const wxPoint
& WXUNUSED(pos
),
224 const wxSize
& WXUNUSED(size
),
226 const wxValidator
& wxVALIDATOR_PARAM(validator
),
227 const wxString
& name
)
230 // wxGTK doesn't allow to create controls with static box as the parent so
231 // this will result in a crash when the program is ported to wxGTK so warn
234 // if you get this assert, the correct solution is to create the controls
235 // as siblings of the static box
236 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
237 _T("wxStaticBox can't be used as a window parent!") );
238 #endif // wxUSE_STATBOX
240 // ids are limited to 16 bits under MSW so if you care about portability,
241 // it's not a good idea to use ids out of this range (and negative ids are
242 // reserved for wxWidgets own usage)
243 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
244 _T("invalid id value") );
246 // generate a new id if the user doesn't care about it
247 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
250 SetWindowStyleFlag(style
);
254 SetValidator(validator
);
255 #endif // wxUSE_VALIDATORS
257 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
258 // have it too - like this it's possible to set it only in the top level
259 // dialog/frame and all children will inherit it by defult
260 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
262 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
268 // ----------------------------------------------------------------------------
270 // ----------------------------------------------------------------------------
273 wxWindowBase::~wxWindowBase()
275 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
277 // FIXME if these 2 cases result from programming errors in the user code
278 // we should probably assert here instead of silently fixing them
280 // Just in case the window has been Closed, but we're then deleting
281 // immediately: don't leave dangling pointers.
282 wxPendingDelete
.DeleteObject(this);
284 // Just in case we've loaded a top-level window via LoadNativeDialog but
285 // we weren't a dialog class
286 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
288 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
290 // reset the dangling pointer our parent window may keep to us
293 if ( m_parent
->GetDefaultItem() == this )
295 m_parent
->SetDefaultItem(NULL
);
298 m_parent
->RemoveChild(this);
303 #endif // wxUSE_CARET
306 delete m_windowValidator
;
307 #endif // wxUSE_VALIDATORS
309 #if wxUSE_CONSTRAINTS
310 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
311 // at deleted windows as they delete themselves.
312 DeleteRelatedConstraints();
316 // This removes any dangling pointers to this window in other windows'
317 // constraintsInvolvedIn lists.
318 UnsetConstraints(m_constraints
);
319 delete m_constraints
;
320 m_constraints
= NULL
;
322 #endif // wxUSE_CONSTRAINTS
324 if ( m_containingSizer
)
325 m_containingSizer
->Detach( (wxWindow
*)this );
327 delete m_windowSizer
;
329 #if wxUSE_DRAG_AND_DROP
331 #endif // wxUSE_DRAG_AND_DROP
335 #endif // wxUSE_TOOLTIPS
337 #if wxUSE_ACCESSIBILITY
342 bool wxWindowBase::Destroy()
349 bool wxWindowBase::Close(bool force
)
351 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
352 event
.SetEventObject(this);
353 event
.SetCanVeto(!force
);
355 // return false if window wasn't closed because the application vetoed the
357 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
360 bool wxWindowBase::DestroyChildren()
362 wxWindowList::compatibility_iterator node
;
365 // we iterate until the list becomes empty
366 node
= GetChildren().GetFirst();
370 wxWindow
*child
= node
->GetData();
372 // note that we really want to call delete and not ->Destroy() here
373 // because we want to delete the child immediately, before we are
374 // deleted, and delayed deletion would result in problems as our (top
375 // level) child could outlive its parent
378 wxASSERT_MSG( !GetChildren().Find(child
),
379 wxT("child didn't remove itself using RemoveChild()") );
385 // ----------------------------------------------------------------------------
386 // size/position related methods
387 // ----------------------------------------------------------------------------
389 // centre the window with respect to its parent in either (or both) directions
390 void wxWindowBase::Centre(int direction
)
392 // the position/size of the parent window or of the entire screen
394 int widthParent
, heightParent
;
396 wxWindow
*parent
= NULL
;
397 wxTopLevelWindow
*winTop
= NULL
;
399 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
401 // find the parent to centre this window on: it should be the
402 // immediate parent for the controls but the top level parent for the
403 // top level windows (like dialogs)
404 parent
= GetParent();
407 while ( parent
&& !parent
->IsTopLevel() )
409 parent
= parent
->GetParent();
413 // there is no wxTopLevelWindow under wxMotif yet
415 // we shouldn't center the dialog on the iconized window: under
416 // Windows, for example, this places it completely off the screen
419 winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
420 if ( winTop
&& winTop
->IsIconized() )
426 #endif // __WXMOTIF__
428 // did we find the parent?
432 direction
|= wxCENTRE_ON_SCREEN
;
436 if ( direction
& wxCENTRE_ON_SCREEN
)
438 //RN: If we are using wxDisplay we get
439 //the dimensions of the monitor the window is on,
440 //otherwise we get the dimensions of the primary monitor
441 //FIXME: wxDisplay::GetFromWindow only implemented on MSW
442 #if wxUSE_DISPLAY && defined(__WXMSW__)
443 int nDisplay
= wxDisplay::GetFromWindow((wxWindow
*)this);
444 if(nDisplay
!= wxNOT_FOUND
)
446 wxDisplay
windowDisplay(nDisplay
);
447 wxRect displayRect
= windowDisplay
.GetGeometry();
448 widthParent
= displayRect
.width
;
449 heightParent
= displayRect
.height
;
453 // centre with respect to the whole screen
454 wxDisplaySize(&widthParent
, &heightParent
);
461 winTop
->GetRectForTopLevelChildren(&posParent
.x
, &posParent
.y
, &widthParent
, &heightParent
);
464 // centre on the parent
465 parent
->GetSize(&widthParent
, &heightParent
);
467 // adjust to the parents position
468 posParent
= parent
->GetPosition();
473 // centre inside the parents client rectangle
474 parent
->GetClientSize(&widthParent
, &heightParent
);
479 GetSize(&width
, &height
);
481 int xNew
= wxDefaultCoord
,
482 yNew
= wxDefaultCoord
;
484 if ( direction
& wxHORIZONTAL
)
485 xNew
= (widthParent
- width
)/2;
487 if ( direction
& wxVERTICAL
)
488 yNew
= (heightParent
- height
)/2;
493 // FIXME: This needs to get the client display rect of the display
494 // the window is (via wxDisplay::GetFromWindow).
496 // Base size of the visible dimensions of the display
497 // to take into account the taskbar. And the Mac menu bar at top.
498 wxRect clientrect
= wxGetClientDisplayRect();
500 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
501 // but it may mean that the window is placed on other than the main
502 // display. Therefore we only make sure centered window is on the main display
503 // if the parent is at least partially present here.
504 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
506 if (xNew
< clientrect
.GetLeft())
507 xNew
= clientrect
.GetLeft();
508 else if (xNew
+ width
> clientrect
.GetRight())
509 xNew
= clientrect
.GetRight() - width
;
511 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
513 if (yNew
+ height
> clientrect
.GetBottom())
514 yNew
= clientrect
.GetBottom() - height
;
516 // Make certain that the title bar is initially visible
517 // always, even if this would push the bottom of the
518 // dialog off the visible area of the display
519 if (yNew
< clientrect
.GetTop())
520 yNew
= clientrect
.GetTop();
523 // move the window to this position (keeping the old size but using
524 // SetSize() and not Move() to allow xNew and/or yNew to be wxDefaultCoord)
525 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
528 // fits the window around the children
529 void wxWindowBase::Fit()
531 if ( GetChildren().GetCount() > 0 )
533 SetSize(GetBestSize());
535 //else: do nothing if we have no children
538 // fits virtual size (ie. scrolled area etc.) around children
539 void wxWindowBase::FitInside()
541 if ( GetChildren().GetCount() > 0 )
543 SetVirtualSize( GetBestVirtualSize() );
547 // On Mac, scrollbars are explicitly children.
549 static bool wxHasRealChildren(const wxWindowBase
* win
)
551 int realChildCount
= 0;
553 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
555 node
= node
->GetNext() )
557 wxWindow
*win
= node
->GetData();
558 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
561 return (realChildCount
> 0);
565 void wxWindowBase::InvalidateBestSize()
567 m_bestSizeCache
= wxDefaultSize
;
569 // parent's best size calculation may depend on its children's
570 // best sizes, so let's invalidate it as well to be safe:
572 m_parent
->InvalidateBestSize();
575 // return the size best suited for the current window
576 wxSize
wxWindowBase::DoGetBestSize() const
582 best
= m_windowSizer
->GetMinSize();
584 #if wxUSE_CONSTRAINTS
585 else if ( m_constraints
)
587 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
589 // our minimal acceptable size is such that all our windows fit inside
593 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
595 node
= node
->GetNext() )
597 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
600 // it's not normal that we have an unconstrained child, but
601 // what can we do about it?
605 int x
= c
->right
.GetValue(),
606 y
= c
->bottom
.GetValue();
614 // TODO: we must calculate the overlaps somehow, otherwise we
615 // will never return a size bigger than the current one :-(
618 best
= wxSize(maxX
, maxY
);
620 #endif // wxUSE_CONSTRAINTS
621 else if ( !GetChildren().empty()
623 && wxHasRealChildren(this)
627 // our minimal acceptable size is such that all our visible child windows fit inside
631 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
633 node
= node
->GetNext() )
635 wxWindow
*win
= node
->GetData();
636 if ( win
->IsTopLevel() || ( ! win
->IsShown() )
638 || wxDynamicCast(win
, wxStatusBar
)
639 #endif // wxUSE_STATUSBAR
642 // dialogs and frames lie in different top level windows -
643 // don't deal with them here; as for the status bars, they
644 // don't lie in the client area at all
649 win
->GetPosition(&wx
, &wy
);
651 // if the window hadn't been positioned yet, assume that it is in
653 if ( wx
== wxDefaultCoord
)
655 if ( wy
== wxDefaultCoord
)
658 win
->GetSize(&ww
, &wh
);
659 if ( wx
+ ww
> maxX
)
661 if ( wy
+ wh
> maxY
)
665 // for compatibility with the old versions and because it really looks
666 // slightly more pretty like this, add a pad
670 best
= wxSize(maxX
, maxY
);
672 else // ! has children
674 // For a generic window there is no natural best size - just use
675 // either the minimum size if there is one, or the current size.
676 // These are returned as-is, unadjusted by the client size difference.
677 if ( GetMinSize().IsFullySpecified() )
683 // Add any difference between size and client size
684 wxSize diff
= GetSize() - GetClientSize();
685 best
.x
+= wxMax(0, diff
.x
);
686 best
.y
+= wxMax(0, diff
.y
);
692 wxSize
wxWindowBase::GetBestFittingSize() const
694 // merge the best size with the min size, giving priority to the min size
695 wxSize min
= GetMinSize();
696 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
698 wxSize best
= GetBestSize();
699 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
700 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
706 void wxWindowBase::SetBestFittingSize(const wxSize
& size
)
708 // Set the min size to the size passed in. This will usually either be
709 // wxDefaultSize or the size passed to this window's ctor/Create function.
712 // Merge the size with the best size if needed
713 wxSize best
= GetBestFittingSize();
715 // If the current size doesn't match then change it
716 if (GetSize() != best
)
721 // by default the origin is not shifted
722 wxPoint
wxWindowBase::GetClientAreaOrigin() const
727 // set the min/max size of the window
728 void wxWindowBase::DoSetSizeHints(int minW
, int minH
,
730 int WXUNUSED(incW
), int WXUNUSED(incH
))
732 // setting min width greater than max width leads to infinite loops under
733 // X11 and generally doesn't make any sense, so don't allow it
734 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
735 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
736 _T("min width/height must be less than max width/height!") );
744 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
746 if ( m_windowVariant
!= variant
)
748 m_windowVariant
= variant
;
750 DoSetWindowVariant(variant
);
754 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
756 // adjust the font height to correspond to our new variant (notice that
757 // we're only called if something really changed)
758 wxFont font
= GetFont();
759 int size
= font
.GetPointSize();
762 case wxWINDOW_VARIANT_NORMAL
:
765 case wxWINDOW_VARIANT_SMALL
:
770 case wxWINDOW_VARIANT_MINI
:
775 case wxWINDOW_VARIANT_LARGE
:
781 wxFAIL_MSG(_T("unexpected window variant"));
785 font
.SetPointSize(size
);
789 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
792 m_minVirtualWidth
= minW
;
793 m_maxVirtualWidth
= maxW
;
794 m_minVirtualHeight
= minH
;
795 m_maxVirtualHeight
= maxH
;
798 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
800 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
801 x
= m_minVirtualWidth
;
802 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
803 x
= m_maxVirtualWidth
;
804 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
805 y
= m_minVirtualHeight
;
806 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
807 y
= m_maxVirtualHeight
;
809 m_virtualSize
= wxSize(x
, y
);
812 wxSize
wxWindowBase::DoGetVirtualSize() const
814 if ( m_virtualSize
.IsFullySpecified() )
815 return m_virtualSize
;
817 wxSize size
= GetClientSize();
818 if ( m_virtualSize
.x
!= wxDefaultCoord
)
819 size
.x
= m_virtualSize
.x
;
821 if ( m_virtualSize
.y
!= wxDefaultCoord
)
822 size
.y
= m_virtualSize
.y
;
827 // ----------------------------------------------------------------------------
828 // show/hide/enable/disable the window
829 // ----------------------------------------------------------------------------
831 bool wxWindowBase::Show(bool show
)
833 if ( show
!= m_isShown
)
845 bool wxWindowBase::Enable(bool enable
)
847 if ( enable
!= m_isEnabled
)
849 m_isEnabled
= enable
;
858 // ----------------------------------------------------------------------------
860 // ----------------------------------------------------------------------------
862 bool wxWindowBase::IsTopLevel() const
867 // ----------------------------------------------------------------------------
868 // reparenting the window
869 // ----------------------------------------------------------------------------
871 void wxWindowBase::AddChild(wxWindowBase
*child
)
873 wxCHECK_RET( child
, wxT("can't add a NULL child") );
875 // this should never happen and it will lead to a crash later if it does
876 // because RemoveChild() will remove only one node from the children list
877 // and the other(s) one(s) will be left with dangling pointers in them
878 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
880 GetChildren().Append((wxWindow
*)child
);
881 child
->SetParent(this);
884 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
886 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
888 GetChildren().DeleteObject((wxWindow
*)child
);
889 child
->SetParent(NULL
);
892 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
894 wxWindow
*oldParent
= GetParent();
895 if ( newParent
== oldParent
)
901 // unlink this window from the existing parent.
904 oldParent
->RemoveChild(this);
908 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
911 // add it to the new one
914 newParent
->AddChild(this);
918 wxTopLevelWindows
.Append((wxWindow
*)this);
924 // ----------------------------------------------------------------------------
925 // event handler stuff
926 // ----------------------------------------------------------------------------
928 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
930 wxEvtHandler
*handlerOld
= GetEventHandler();
932 handler
->SetNextHandler(handlerOld
);
935 GetEventHandler()->SetPreviousHandler(handler
);
937 SetEventHandler(handler
);
940 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
942 wxEvtHandler
*handlerA
= GetEventHandler();
945 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
946 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
949 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
950 SetEventHandler(handlerB
);
955 handlerA
= (wxEvtHandler
*)NULL
;
962 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
964 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
966 wxEvtHandler
*handlerPrev
= NULL
,
967 *handlerCur
= GetEventHandler();
970 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
972 if ( handlerCur
== handler
)
976 handlerPrev
->SetNextHandler(handlerNext
);
980 SetEventHandler(handlerNext
);
985 handlerNext
->SetPreviousHandler ( handlerPrev
);
988 handler
->SetNextHandler(NULL
);
989 handler
->SetPreviousHandler(NULL
);
994 handlerPrev
= handlerCur
;
995 handlerCur
= handlerNext
;
998 wxFAIL_MSG( _T("where has the event handler gone?") );
1003 // ----------------------------------------------------------------------------
1004 // colours, fonts &c
1005 // ----------------------------------------------------------------------------
1007 void wxWindowBase::InheritAttributes()
1009 const wxWindowBase
* const parent
= GetParent();
1013 // we only inherit attributes which had been explicitly set for the parent
1014 // which ensures that this only happens if the user really wants it and
1015 // not by default which wouldn't make any sense in modern GUIs where the
1016 // controls don't all use the same fonts (nor colours)
1017 if ( parent
->m_inheritFont
&& !m_hasFont
)
1018 SetFont(parent
->GetFont());
1020 // in addition, there is a possibility to explicitly forbid inheriting
1021 // colours at each class level by overriding ShouldInheritColours()
1022 if ( ShouldInheritColours() )
1024 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1025 SetForegroundColour(parent
->GetForegroundColour());
1027 // inheriting (solid) background colour is wrong as it totally breaks
1028 // any kind of themed backgrounds
1030 // instead, the controls should use the same background as their parent
1031 // (ideally by not drawing it at all)
1033 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1034 SetBackgroundColour(parent
->GetBackgroundColour());
1039 /* static */ wxVisualAttributes
1040 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1042 // it is important to return valid values for all attributes from here,
1043 // GetXXX() below rely on this
1044 wxVisualAttributes attrs
;
1045 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1046 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1047 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1052 wxColour
wxWindowBase::GetBackgroundColour() const
1054 if ( !m_backgroundColour
.Ok() )
1056 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1058 // get our default background colour
1059 wxColour colBg
= GetDefaultAttributes().colBg
;
1061 // we must return some valid colour to avoid redoing this every time
1062 // and also to avoid surprizing the applications written for older
1063 // wxWidgets versions where GetBackgroundColour() always returned
1064 // something -- so give them something even if it doesn't make sense
1065 // for this window (e.g. it has a themed background)
1067 colBg
= GetClassDefaultAttributes().colBg
;
1072 return m_backgroundColour
;
1075 wxColour
wxWindowBase::GetForegroundColour() const
1077 // logic is the same as above
1078 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1080 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
1082 wxColour colFg
= GetDefaultAttributes().colFg
;
1085 colFg
= GetClassDefaultAttributes().colFg
;
1090 return m_foregroundColour
;
1093 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1095 if ( colour
== m_backgroundColour
)
1098 m_hasBgCol
= colour
.Ok();
1099 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1100 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1102 m_inheritBgCol
= m_hasBgCol
;
1103 m_backgroundColour
= colour
;
1104 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1108 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1110 if (colour
== m_foregroundColour
)
1113 m_hasFgCol
= colour
.Ok();
1114 m_inheritFgCol
= m_hasFgCol
;
1115 m_foregroundColour
= colour
;
1116 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1120 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1122 // setting an invalid cursor is ok, it means that we don't have any special
1124 if ( m_cursor
== cursor
)
1135 wxFont
wxWindowBase::GetFont() const
1137 // logic is the same as in GetBackgroundColour()
1140 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1142 wxFont font
= GetDefaultAttributes().font
;
1144 font
= GetClassDefaultAttributes().font
;
1152 bool wxWindowBase::SetFont(const wxFont
& font
)
1154 if ( font
== m_font
)
1161 m_hasFont
= font
.Ok();
1162 m_inheritFont
= m_hasFont
;
1164 InvalidateBestSize();
1171 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1173 m_hasCustomPalette
= true;
1176 // VZ: can anyone explain me what do we do here?
1177 wxWindowDC
d((wxWindow
*) this);
1181 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1183 wxWindow
*win
= (wxWindow
*)this;
1184 while ( win
&& !win
->HasCustomPalette() )
1186 win
= win
->GetParent();
1192 #endif // wxUSE_PALETTE
1195 void wxWindowBase::SetCaret(wxCaret
*caret
)
1206 wxASSERT_MSG( m_caret
->GetWindow() == this,
1207 wxT("caret should be created associated to this window") );
1210 #endif // wxUSE_CARET
1212 #if wxUSE_VALIDATORS
1213 // ----------------------------------------------------------------------------
1215 // ----------------------------------------------------------------------------
1217 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1219 if ( m_windowValidator
)
1220 delete m_windowValidator
;
1222 m_windowValidator
= (wxValidator
*)validator
.Clone();
1224 if ( m_windowValidator
)
1225 m_windowValidator
->SetWindow(this);
1227 #endif // wxUSE_VALIDATORS
1229 // ----------------------------------------------------------------------------
1230 // update region stuff
1231 // ----------------------------------------------------------------------------
1233 wxRect
wxWindowBase::GetUpdateClientRect() const
1235 wxRegion rgnUpdate
= GetUpdateRegion();
1236 rgnUpdate
.Intersect(GetClientRect());
1237 wxRect rectUpdate
= rgnUpdate
.GetBox();
1238 wxPoint ptOrigin
= GetClientAreaOrigin();
1239 rectUpdate
.x
-= ptOrigin
.x
;
1240 rectUpdate
.y
-= ptOrigin
.y
;
1245 bool wxWindowBase::IsExposed(int x
, int y
) const
1247 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1250 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1252 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1255 void wxWindowBase::ClearBackground()
1257 // wxGTK uses its own version, no need to add never used code
1259 wxClientDC
dc((wxWindow
*)this);
1260 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1261 dc
.SetBackground(brush
);
1266 // ----------------------------------------------------------------------------
1267 // find child window by id or name
1268 // ----------------------------------------------------------------------------
1270 wxWindow
*wxWindowBase::FindWindow(long id
) const
1272 if ( id
== m_windowId
)
1273 return (wxWindow
*)this;
1275 wxWindowBase
*res
= (wxWindow
*)NULL
;
1276 wxWindowList::compatibility_iterator node
;
1277 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1279 wxWindowBase
*child
= node
->GetData();
1280 res
= child
->FindWindow( id
);
1283 return (wxWindow
*)res
;
1286 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1288 if ( name
== m_windowName
)
1289 return (wxWindow
*)this;
1291 wxWindowBase
*res
= (wxWindow
*)NULL
;
1292 wxWindowList::compatibility_iterator node
;
1293 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1295 wxWindow
*child
= node
->GetData();
1296 res
= child
->FindWindow(name
);
1299 return (wxWindow
*)res
;
1303 // find any window by id or name or label: If parent is non-NULL, look through
1304 // children for a label or title matching the specified string. If NULL, look
1305 // through all top-level windows.
1307 // to avoid duplicating code we reuse the same helper function but with
1308 // different comparators
1310 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1311 const wxString
& label
, long id
);
1314 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1317 return win
->GetLabel() == label
;
1321 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1324 return win
->GetName() == label
;
1328 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1331 return win
->GetId() == id
;
1334 // recursive helper for the FindWindowByXXX() functions
1336 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1337 const wxString
& label
,
1339 wxFindWindowCmp cmp
)
1343 // see if this is the one we're looking for
1344 if ( (*cmp
)(parent
, label
, id
) )
1345 return (wxWindow
*)parent
;
1347 // It wasn't, so check all its children
1348 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1350 node
= node
->GetNext() )
1352 // recursively check each child
1353 wxWindow
*win
= (wxWindow
*)node
->GetData();
1354 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1364 // helper for FindWindowByXXX()
1366 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1367 const wxString
& label
,
1369 wxFindWindowCmp cmp
)
1373 // just check parent and all its children
1374 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1377 // start at very top of wx's windows
1378 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1380 node
= node
->GetNext() )
1382 // recursively check each window & its children
1383 wxWindow
*win
= node
->GetData();
1384 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1394 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1396 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1401 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1403 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1407 // fall back to the label
1408 win
= FindWindowByLabel(title
, parent
);
1416 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1418 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1421 // ----------------------------------------------------------------------------
1422 // dialog oriented functions
1423 // ----------------------------------------------------------------------------
1425 void wxWindowBase::MakeModal(bool modal
)
1427 // Disable all other windows
1430 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1433 wxWindow
*win
= node
->GetData();
1435 win
->Enable(!modal
);
1437 node
= node
->GetNext();
1442 bool wxWindowBase::Validate()
1444 #if wxUSE_VALIDATORS
1445 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1447 wxWindowList::compatibility_iterator node
;
1448 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1450 wxWindowBase
*child
= node
->GetData();
1451 wxValidator
*validator
= child
->GetValidator();
1452 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1457 if ( recurse
&& !child
->Validate() )
1462 #endif // wxUSE_VALIDATORS
1467 bool wxWindowBase::TransferDataToWindow()
1469 #if wxUSE_VALIDATORS
1470 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1472 wxWindowList::compatibility_iterator node
;
1473 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1475 wxWindowBase
*child
= node
->GetData();
1476 wxValidator
*validator
= child
->GetValidator();
1477 if ( validator
&& !validator
->TransferToWindow() )
1479 wxLogWarning(_("Could not transfer data to window"));
1481 wxLog::FlushActive();
1489 if ( !child
->TransferDataToWindow() )
1491 // warning already given
1496 #endif // wxUSE_VALIDATORS
1501 bool wxWindowBase::TransferDataFromWindow()
1503 #if wxUSE_VALIDATORS
1504 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1506 wxWindowList::compatibility_iterator node
;
1507 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1509 wxWindow
*child
= node
->GetData();
1510 wxValidator
*validator
= child
->GetValidator();
1511 if ( validator
&& !validator
->TransferFromWindow() )
1513 // nop warning here because the application is supposed to give
1514 // one itself - we don't know here what might have gone wrongly
1521 if ( !child
->TransferDataFromWindow() )
1523 // warning already given
1528 #endif // wxUSE_VALIDATORS
1533 void wxWindowBase::InitDialog()
1535 wxInitDialogEvent
event(GetId());
1536 event
.SetEventObject( this );
1537 GetEventHandler()->ProcessEvent(event
);
1540 // ----------------------------------------------------------------------------
1541 // context-sensitive help support
1542 // ----------------------------------------------------------------------------
1546 // associate this help text with this window
1547 void wxWindowBase::SetHelpText(const wxString
& text
)
1549 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1552 helpProvider
->AddHelp(this, text
);
1556 // associate this help text with all windows with the same id as this
1558 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1560 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1563 helpProvider
->AddHelp(GetId(), text
);
1567 // get the help string associated with this window (may be empty)
1568 wxString
wxWindowBase::GetHelpText() const
1571 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1574 text
= helpProvider
->GetHelp(this);
1580 // show help for this window
1581 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1583 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1586 if ( helpProvider
->ShowHelp(this) )
1588 // skip the event.Skip() below
1596 #endif // wxUSE_HELP
1598 // ----------------------------------------------------------------------------
1599 // tooltipsroot.Replace("\\", "/");
1600 // ----------------------------------------------------------------------------
1604 void wxWindowBase::SetToolTip( const wxString
&tip
)
1606 // don't create the new tooltip if we already have one
1609 m_tooltip
->SetTip( tip
);
1613 SetToolTip( new wxToolTip( tip
) );
1616 // setting empty tooltip text does not remove the tooltip any more - use
1617 // SetToolTip((wxToolTip *)NULL) for this
1620 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1625 m_tooltip
= tooltip
;
1628 #endif // wxUSE_TOOLTIPS
1630 // ----------------------------------------------------------------------------
1631 // constraints and sizers
1632 // ----------------------------------------------------------------------------
1634 #if wxUSE_CONSTRAINTS
1636 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1638 if ( m_constraints
)
1640 UnsetConstraints(m_constraints
);
1641 delete m_constraints
;
1643 m_constraints
= constraints
;
1644 if ( m_constraints
)
1646 // Make sure other windows know they're part of a 'meaningful relationship'
1647 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1648 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1649 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1650 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1651 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1652 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1653 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1654 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1655 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1656 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1657 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1658 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1659 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1660 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1661 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1662 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1666 // This removes any dangling pointers to this window in other windows'
1667 // constraintsInvolvedIn lists.
1668 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1672 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1673 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1674 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1675 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1676 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1677 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1678 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1679 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1680 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1681 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1682 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1683 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1684 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1685 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1686 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1687 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1691 // Back-pointer to other windows we're involved with, so if we delete this
1692 // window, we must delete any constraints we're involved with.
1693 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1695 if ( !m_constraintsInvolvedIn
)
1696 m_constraintsInvolvedIn
= new wxWindowList
;
1697 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1698 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1701 // REMOVE back-pointer to other windows we're involved with.
1702 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1704 if ( m_constraintsInvolvedIn
)
1705 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1708 // Reset any constraints that mention this window
1709 void wxWindowBase::DeleteRelatedConstraints()
1711 if ( m_constraintsInvolvedIn
)
1713 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1716 wxWindow
*win
= node
->GetData();
1717 wxLayoutConstraints
*constr
= win
->GetConstraints();
1719 // Reset any constraints involving this window
1722 constr
->left
.ResetIfWin(this);
1723 constr
->top
.ResetIfWin(this);
1724 constr
->right
.ResetIfWin(this);
1725 constr
->bottom
.ResetIfWin(this);
1726 constr
->width
.ResetIfWin(this);
1727 constr
->height
.ResetIfWin(this);
1728 constr
->centreX
.ResetIfWin(this);
1729 constr
->centreY
.ResetIfWin(this);
1732 wxWindowList::compatibility_iterator next
= node
->GetNext();
1733 m_constraintsInvolvedIn
->Erase(node
);
1737 delete m_constraintsInvolvedIn
;
1738 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1742 #endif // wxUSE_CONSTRAINTS
1744 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1746 if ( sizer
== m_windowSizer
)
1750 delete m_windowSizer
;
1752 m_windowSizer
= sizer
;
1754 SetAutoLayout( sizer
!= NULL
);
1757 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1759 SetSizer( sizer
, deleteOld
);
1760 sizer
->SetSizeHints( (wxWindow
*) this );
1764 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1766 // adding a window to a sizer twice is going to result in fatal and
1767 // hard to debug problems later because when deleting the second
1768 // associated wxSizerItem we're going to dereference a dangling
1769 // pointer; so try to detect this as early as possible
1770 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1771 _T("Adding a window to the same sizer twice?") );
1773 m_containingSizer
= sizer
;
1776 #if wxUSE_CONSTRAINTS
1778 void wxWindowBase::SatisfyConstraints()
1780 wxLayoutConstraints
*constr
= GetConstraints();
1781 bool wasOk
= constr
&& constr
->AreSatisfied();
1783 ResetConstraints(); // Mark all constraints as unevaluated
1787 // if we're a top level panel (i.e. our parent is frame/dialog), our
1788 // own constraints will never be satisfied any more unless we do it
1792 while ( noChanges
> 0 )
1794 LayoutPhase1(&noChanges
);
1798 LayoutPhase2(&noChanges
);
1801 #endif // wxUSE_CONSTRAINTS
1803 bool wxWindowBase::Layout()
1805 // If there is a sizer, use it instead of the constraints
1809 GetVirtualSize(&w
, &h
);
1810 GetSizer()->SetDimension( 0, 0, w
, h
);
1812 #if wxUSE_CONSTRAINTS
1815 SatisfyConstraints(); // Find the right constraints values
1816 SetConstraintSizes(); // Recursively set the real window sizes
1823 #if wxUSE_CONSTRAINTS
1825 // first phase of the constraints evaluation: set our own constraints
1826 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1828 wxLayoutConstraints
*constr
= GetConstraints();
1830 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1833 // second phase: set the constraints for our children
1834 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1841 // Layout grand children
1847 // Do a phase of evaluating child constraints
1848 bool wxWindowBase::DoPhase(int phase
)
1850 // the list containing the children for which the constraints are already
1852 wxWindowList succeeded
;
1854 // the max number of iterations we loop before concluding that we can't set
1856 static const int maxIterations
= 500;
1858 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1862 // loop over all children setting their constraints
1863 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1865 node
= node
->GetNext() )
1867 wxWindow
*child
= node
->GetData();
1868 if ( child
->IsTopLevel() )
1870 // top level children are not inside our client area
1874 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1876 // this one is either already ok or nothing we can do about it
1880 int tempNoChanges
= 0;
1881 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1882 : child
->LayoutPhase2(&tempNoChanges
);
1883 noChanges
+= tempNoChanges
;
1887 succeeded
.Append(child
);
1893 // constraints are set
1901 void wxWindowBase::ResetConstraints()
1903 wxLayoutConstraints
*constr
= GetConstraints();
1906 constr
->left
.SetDone(false);
1907 constr
->top
.SetDone(false);
1908 constr
->right
.SetDone(false);
1909 constr
->bottom
.SetDone(false);
1910 constr
->width
.SetDone(false);
1911 constr
->height
.SetDone(false);
1912 constr
->centreX
.SetDone(false);
1913 constr
->centreY
.SetDone(false);
1916 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1919 wxWindow
*win
= node
->GetData();
1920 if ( !win
->IsTopLevel() )
1921 win
->ResetConstraints();
1922 node
= node
->GetNext();
1926 // Need to distinguish between setting the 'fake' size for windows and sizers,
1927 // and setting the real values.
1928 void wxWindowBase::SetConstraintSizes(bool recurse
)
1930 wxLayoutConstraints
*constr
= GetConstraints();
1931 if ( constr
&& constr
->AreSatisfied() )
1933 int x
= constr
->left
.GetValue();
1934 int y
= constr
->top
.GetValue();
1935 int w
= constr
->width
.GetValue();
1936 int h
= constr
->height
.GetValue();
1938 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1939 (constr
->height
.GetRelationship() != wxAsIs
) )
1941 SetSize(x
, y
, w
, h
);
1945 // If we don't want to resize this window, just move it...
1951 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1952 GetClassInfo()->GetClassName(),
1958 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1961 wxWindow
*win
= node
->GetData();
1962 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1963 win
->SetConstraintSizes();
1964 node
= node
->GetNext();
1969 // Only set the size/position of the constraint (if any)
1970 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1972 wxLayoutConstraints
*constr
= GetConstraints();
1975 if ( x
!= wxDefaultCoord
)
1977 constr
->left
.SetValue(x
);
1978 constr
->left
.SetDone(true);
1980 if ( y
!= wxDefaultCoord
)
1982 constr
->top
.SetValue(y
);
1983 constr
->top
.SetDone(true);
1985 if ( w
!= wxDefaultCoord
)
1987 constr
->width
.SetValue(w
);
1988 constr
->width
.SetDone(true);
1990 if ( h
!= wxDefaultCoord
)
1992 constr
->height
.SetValue(h
);
1993 constr
->height
.SetDone(true);
1998 void wxWindowBase::MoveConstraint(int x
, int y
)
2000 wxLayoutConstraints
*constr
= GetConstraints();
2003 if ( x
!= wxDefaultCoord
)
2005 constr
->left
.SetValue(x
);
2006 constr
->left
.SetDone(true);
2008 if ( y
!= wxDefaultCoord
)
2010 constr
->top
.SetValue(y
);
2011 constr
->top
.SetDone(true);
2016 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2018 wxLayoutConstraints
*constr
= GetConstraints();
2021 *w
= constr
->width
.GetValue();
2022 *h
= constr
->height
.GetValue();
2028 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2030 wxLayoutConstraints
*constr
= GetConstraints();
2033 *w
= constr
->width
.GetValue();
2034 *h
= constr
->height
.GetValue();
2037 GetClientSize(w
, h
);
2040 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2042 wxLayoutConstraints
*constr
= GetConstraints();
2045 *x
= constr
->left
.GetValue();
2046 *y
= constr
->top
.GetValue();
2052 #endif // wxUSE_CONSTRAINTS
2054 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2056 // don't do it for the dialogs/frames - they float independently of their
2058 if ( !IsTopLevel() )
2060 wxWindow
*parent
= GetParent();
2061 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2063 wxPoint
pt(parent
->GetClientAreaOrigin());
2070 // ----------------------------------------------------------------------------
2071 // do Update UI processing for child controls
2072 // ----------------------------------------------------------------------------
2074 void wxWindowBase::UpdateWindowUI(long flags
)
2076 wxUpdateUIEvent
event(GetId());
2077 event
.SetEventObject(this);
2079 if ( GetEventHandler()->ProcessEvent(event
) )
2081 DoUpdateWindowUI(event
);
2084 if (flags
& wxUPDATE_UI_RECURSE
)
2086 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2089 wxWindow
* child
= (wxWindow
*) node
->GetData();
2090 child
->UpdateWindowUI(flags
);
2091 node
= node
->GetNext();
2096 // do the window-specific processing after processing the update event
2097 // TODO: take specific knowledge out of this function and
2098 // put in each control's base class. Unfortunately we don't
2099 // yet have base implementation files for wxCheckBox and wxRadioButton.
2100 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2102 if ( event
.GetSetEnabled() )
2103 Enable(event
.GetEnabled());
2106 if ( event
.GetSetText() )
2108 wxControl
*control
= wxDynamicCastThis(wxControl
);
2111 if ( event
.GetText() != control
->GetLabel() )
2112 control
->SetLabel(event
.GetText());
2115 #endif // wxUSE_CONTROLS
2117 if ( event
.GetSetChecked() )
2120 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
2123 checkbox
->SetValue(event
.GetChecked());
2125 #endif // wxUSE_CHECKBOX
2128 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
2131 radiobtn
->SetValue(event
.GetChecked());
2133 #endif // wxUSE_RADIOBTN
2138 // call internal idle recursively
2139 // may be obsolete (wait until OnIdle scheme stabilises)
2140 void wxWindowBase::ProcessInternalIdle()
2144 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2147 wxWindow
*child
= node
->GetData();
2148 child
->ProcessInternalIdle();
2149 node
= node
->GetNext();
2154 // ----------------------------------------------------------------------------
2155 // dialog units translations
2156 // ----------------------------------------------------------------------------
2158 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2160 int charWidth
= GetCharWidth();
2161 int charHeight
= GetCharHeight();
2162 wxPoint pt2
= wxDefaultPosition
;
2163 if (pt
.x
!= wxDefaultCoord
)
2164 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2165 if (pt
.y
!= wxDefaultCoord
)
2166 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2171 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2173 int charWidth
= GetCharWidth();
2174 int charHeight
= GetCharHeight();
2175 wxPoint pt2
= wxDefaultPosition
;
2176 if (pt
.x
!= wxDefaultCoord
)
2177 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2178 if (pt
.y
!= wxDefaultCoord
)
2179 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2184 // ----------------------------------------------------------------------------
2186 // ----------------------------------------------------------------------------
2188 // propagate the colour change event to the subwindows
2189 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2191 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2194 // Only propagate to non-top-level windows
2195 wxWindow
*win
= node
->GetData();
2196 if ( !win
->IsTopLevel() )
2198 wxSysColourChangedEvent event2
;
2199 event
.SetEventObject(win
);
2200 win
->GetEventHandler()->ProcessEvent(event2
);
2203 node
= node
->GetNext();
2209 // the default action is to populate dialog with data when it's created,
2210 // and nudge the UI into displaying itself correctly in case
2211 // we've turned the wxUpdateUIEvents frequency down low.
2212 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2214 TransferDataToWindow();
2216 // Update the UI at this point
2217 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2220 // process Ctrl-Alt-mclick
2221 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2224 if ( event
.ControlDown() && event
.AltDown() )
2226 // don't translate these strings
2229 #ifdef __WXUNIVERSAL__
2231 #endif // __WXUNIVERSAL__
2233 switch ( wxGetOsVersion() )
2235 case wxMOTIF_X
: port
+= _T("Motif"); break;
2237 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2238 case wxBEOS
: port
+= _T("BeOS"); break;
2242 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2248 case wxWIN386
: port
+= _T("MS Windows"); break;
2252 case wxMGL_OS2
: port
+= _T("MGL"); break;
2254 case wxOS2_PM
: port
+= _T("OS/2"); break;
2255 default: port
+= _T("unknown"); break;
2258 wxMessageBox(wxString::Format(
2260 " wxWidgets Library (%s port)\nVersion %u.%u.%u%s%s, compiled at %s %s\n Copyright (c) 1995-2005 wxWidgets team"
2279 _T("wxWidgets information"),
2280 wxICON_INFORMATION
| wxOK
,
2284 #endif // wxUSE_MSGDLG
2290 // ----------------------------------------------------------------------------
2292 // ----------------------------------------------------------------------------
2294 #if wxUSE_ACCESSIBILITY
2295 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2297 if (m_accessible
&& (accessible
!= m_accessible
))
2298 delete m_accessible
;
2299 m_accessible
= accessible
;
2301 m_accessible
->SetWindow((wxWindow
*) this);
2304 // Returns the accessible object, creating if necessary.
2305 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2308 m_accessible
= CreateAccessible();
2309 return m_accessible
;
2312 // Override to create a specific accessible object.
2313 wxAccessible
* wxWindowBase::CreateAccessible()
2315 return new wxWindowAccessible((wxWindow
*) this);
2320 // ----------------------------------------------------------------------------
2321 // list classes implementation
2322 // ----------------------------------------------------------------------------
2326 #include <wx/listimpl.cpp>
2327 WX_DEFINE_LIST(wxWindowList
);
2331 void wxWindowListNode::DeleteData()
2333 delete (wxWindow
*)GetData();
2338 // ----------------------------------------------------------------------------
2340 // ----------------------------------------------------------------------------
2342 wxBorder
wxWindowBase::GetBorder(long flags
) const
2344 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2345 if ( border
== wxBORDER_DEFAULT
)
2347 border
= GetDefaultBorder();
2353 wxBorder
wxWindowBase::GetDefaultBorder() const
2355 return wxBORDER_NONE
;
2358 // ----------------------------------------------------------------------------
2360 // ----------------------------------------------------------------------------
2362 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2364 // here we just check if the point is inside the window or not
2366 // check the top and left border first
2367 bool outside
= x
< 0 || y
< 0;
2370 // check the right and bottom borders too
2371 wxSize size
= GetSize();
2372 outside
= x
>= size
.x
|| y
>= size
.y
;
2375 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2378 // ----------------------------------------------------------------------------
2380 // ----------------------------------------------------------------------------
2382 struct WXDLLEXPORT wxWindowNext
2386 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2388 void wxWindowBase::CaptureMouse()
2390 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2392 wxWindow
*winOld
= GetCapture();
2395 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2398 wxWindowNext
*item
= new wxWindowNext
;
2400 item
->next
= ms_winCaptureNext
;
2401 ms_winCaptureNext
= item
;
2403 //else: no mouse capture to save
2408 void wxWindowBase::ReleaseMouse()
2410 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2412 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2416 if ( ms_winCaptureNext
)
2418 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2420 wxWindowNext
*item
= ms_winCaptureNext
;
2421 ms_winCaptureNext
= item
->next
;
2424 //else: stack is empty, no previous capture
2426 wxLogTrace(_T("mousecapture"),
2427 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2434 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2435 int WXUNUSED(modifiers
),
2436 int WXUNUSED(keycode
))
2442 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2448 #endif // wxUSE_HOTKEY
2450 void wxWindowBase::SendDestroyEvent()
2452 wxWindowDestroyEvent event
;
2453 event
.SetEventObject(this);
2454 event
.SetId(GetId());
2455 GetEventHandler()->ProcessEvent(event
);
2458 // ----------------------------------------------------------------------------
2460 // ----------------------------------------------------------------------------
2462 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2464 #if wxUSE_VALIDATORS
2465 // Can only use the validator of the window which
2466 // is receiving the event
2467 if ( event
.GetEventObject() == this )
2469 wxValidator
*validator
= GetValidator();
2470 if ( validator
&& validator
->ProcessEvent(event
) )
2475 #endif // wxUSE_VALIDATORS
2480 bool wxWindowBase::TryParent(wxEvent
& event
)
2482 // carry on up the parent-child hierarchy if the propgation count hasn't
2484 if ( event
.ShouldPropagate() )
2486 // honour the requests to stop propagation at this window: this is
2487 // used by the dialogs, for example, to prevent processing the events
2488 // from the dialog controls in the parent frame which rarely, if ever,
2490 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2492 wxWindow
*parent
= GetParent();
2493 if ( parent
&& !parent
->IsBeingDeleted() )
2495 wxPropagateOnce
propagateOnce(event
);
2497 return parent
->GetEventHandler()->ProcessEvent(event
);
2502 return wxEvtHandler::TryParent(event
);
2505 // ----------------------------------------------------------------------------
2506 // keyboard navigation
2507 // ----------------------------------------------------------------------------
2509 // Navigates in the specified direction.
2510 bool wxWindowBase::Navigate(int flags
)
2512 wxNavigationKeyEvent eventNav
;
2513 eventNav
.SetFlags(flags
);
2514 eventNav
.SetEventObject(this);
2515 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2522 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2524 // check that we're not a top level window
2525 wxCHECK_RET( GetParent(),
2526 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2528 // detect the special case when we have nothing to do anyhow and when the
2529 // code below wouldn't work
2533 // find the target window in the siblings list
2534 wxWindowList
& siblings
= GetParent()->GetChildren();
2535 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2536 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2538 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2539 // can't just move the node around
2540 wxWindow
*self
= (wxWindow
*)this;
2541 siblings
.DeleteObject(self
);
2542 if ( move
== MoveAfter
)
2549 siblings
.Insert(i
, self
);
2551 else // MoveAfter and win was the last sibling
2553 siblings
.Append(self
);
2557 // ----------------------------------------------------------------------------
2559 // ----------------------------------------------------------------------------
2561 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2563 wxWindowBase
*win
= DoFindFocus();
2564 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2567 // ----------------------------------------------------------------------------
2569 // ----------------------------------------------------------------------------
2571 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2573 while ( win
&& !win
->IsTopLevel() )
2574 win
= win
->GetParent();
2579 #if wxUSE_ACCESSIBILITY
2580 // ----------------------------------------------------------------------------
2581 // accessible object for windows
2582 // ----------------------------------------------------------------------------
2584 // Can return either a child object, or an integer
2585 // representing the child element, starting from 1.
2586 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2588 wxASSERT( GetWindow() != NULL
);
2592 return wxACC_NOT_IMPLEMENTED
;
2595 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2596 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2598 wxASSERT( GetWindow() != NULL
);
2602 wxWindow
* win
= NULL
;
2609 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2611 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2618 rect
= win
->GetRect();
2619 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2620 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2624 return wxACC_NOT_IMPLEMENTED
;
2627 // Navigates from fromId to toId/toObject.
2628 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2629 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2631 wxASSERT( GetWindow() != NULL
);
2637 case wxNAVDIR_FIRSTCHILD
:
2639 if (GetWindow()->GetChildren().GetCount() == 0)
2641 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2642 *toObject
= childWindow
->GetOrCreateAccessible();
2646 case wxNAVDIR_LASTCHILD
:
2648 if (GetWindow()->GetChildren().GetCount() == 0)
2650 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2651 *toObject
= childWindow
->GetOrCreateAccessible();
2655 case wxNAVDIR_RIGHT
:
2659 wxWindowList::compatibility_iterator node
=
2660 wxWindowList::compatibility_iterator();
2663 // Can't navigate to sibling of this window
2664 // if we're a top-level window.
2665 if (!GetWindow()->GetParent())
2666 return wxACC_NOT_IMPLEMENTED
;
2668 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2672 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2673 node
= GetWindow()->GetChildren().Item(fromId
-1);
2676 if (node
&& node
->GetNext())
2678 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2679 *toObject
= nextWindow
->GetOrCreateAccessible();
2687 case wxNAVDIR_PREVIOUS
:
2689 wxWindowList::compatibility_iterator node
=
2690 wxWindowList::compatibility_iterator();
2693 // Can't navigate to sibling of this window
2694 // if we're a top-level window.
2695 if (!GetWindow()->GetParent())
2696 return wxACC_NOT_IMPLEMENTED
;
2698 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2702 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2703 node
= GetWindow()->GetChildren().Item(fromId
-1);
2706 if (node
&& node
->GetPrevious())
2708 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2709 *toObject
= previousWindow
->GetOrCreateAccessible();
2717 return wxACC_NOT_IMPLEMENTED
;
2720 // Gets the name of the specified object.
2721 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2723 wxASSERT( GetWindow() != NULL
);
2729 // If a child, leave wxWidgets to call the function on the actual
2732 return wxACC_NOT_IMPLEMENTED
;
2734 // This will eventually be replaced by specialised
2735 // accessible classes, one for each kind of wxWidgets
2736 // control or window.
2738 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2739 title
= ((wxButton
*) GetWindow())->GetLabel();
2742 title
= GetWindow()->GetName();
2750 return wxACC_NOT_IMPLEMENTED
;
2753 // Gets the number of children.
2754 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2756 wxASSERT( GetWindow() != NULL
);
2760 *childId
= (int) GetWindow()->GetChildren().GetCount();
2764 // Gets the specified child (starting from 1).
2765 // If *child is NULL and return value is wxACC_OK,
2766 // this means that the child is a simple element and
2767 // not an accessible object.
2768 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2770 wxASSERT( GetWindow() != NULL
);
2780 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2783 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2784 *child
= childWindow
->GetOrCreateAccessible();
2791 // Gets the parent, or NULL.
2792 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2794 wxASSERT( GetWindow() != NULL
);
2798 wxWindow
* parentWindow
= GetWindow()->GetParent();
2806 *parent
= parentWindow
->GetOrCreateAccessible();
2814 // Performs the default action. childId is 0 (the action for this object)
2815 // or > 0 (the action for a child).
2816 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2817 // window (e.g. an edit control).
2818 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2820 wxASSERT( GetWindow() != NULL
);
2824 return wxACC_NOT_IMPLEMENTED
;
2827 // Gets the default action for this object (0) or > 0 (the action for a child).
2828 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2829 // string if there is no action.
2830 // The retrieved string describes the action that is performed on an object,
2831 // not what the object does as a result. For example, a toolbar button that prints
2832 // a document has a default action of "Press" rather than "Prints the current document."
2833 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2835 wxASSERT( GetWindow() != NULL
);
2839 return wxACC_NOT_IMPLEMENTED
;
2842 // Returns the description for this object or a child.
2843 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2845 wxASSERT( GetWindow() != NULL
);
2849 wxString
ht(GetWindow()->GetHelpText());
2855 return wxACC_NOT_IMPLEMENTED
;
2858 // Returns help text for this object or a child, similar to tooltip text.
2859 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2861 wxASSERT( GetWindow() != NULL
);
2865 wxString
ht(GetWindow()->GetHelpText());
2871 return wxACC_NOT_IMPLEMENTED
;
2874 // Returns the keyboard shortcut for this object or child.
2875 // Return e.g. ALT+K
2876 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2878 wxASSERT( GetWindow() != NULL
);
2882 return wxACC_NOT_IMPLEMENTED
;
2885 // Returns a role constant.
2886 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2888 wxASSERT( GetWindow() != NULL
);
2892 // If a child, leave wxWidgets to call the function on the actual
2895 return wxACC_NOT_IMPLEMENTED
;
2897 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2898 return wxACC_NOT_IMPLEMENTED
;
2900 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2901 return wxACC_NOT_IMPLEMENTED
;
2904 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2905 return wxACC_NOT_IMPLEMENTED
;
2908 //*role = wxROLE_SYSTEM_CLIENT;
2909 *role
= wxROLE_SYSTEM_CLIENT
;
2913 return wxACC_NOT_IMPLEMENTED
;
2917 // Returns a state constant.
2918 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2920 wxASSERT( GetWindow() != NULL
);
2924 // If a child, leave wxWidgets to call the function on the actual
2927 return wxACC_NOT_IMPLEMENTED
;
2929 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2930 return wxACC_NOT_IMPLEMENTED
;
2933 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2934 return wxACC_NOT_IMPLEMENTED
;
2937 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2938 return wxACC_NOT_IMPLEMENTED
;
2945 return wxACC_NOT_IMPLEMENTED
;
2949 // Returns a localized string representing the value for the object
2951 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2953 wxASSERT( GetWindow() != NULL
);
2957 return wxACC_NOT_IMPLEMENTED
;
2960 // Selects the object or child.
2961 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2963 wxASSERT( GetWindow() != NULL
);
2967 return wxACC_NOT_IMPLEMENTED
;
2970 // Gets the window with the keyboard focus.
2971 // If childId is 0 and child is NULL, no object in
2972 // this subhierarchy has the focus.
2973 // If this object has the focus, child should be 'this'.
2974 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2976 wxASSERT( GetWindow() != NULL
);
2980 return wxACC_NOT_IMPLEMENTED
;
2983 // Gets a variant representing the selected children
2985 // Acceptable values:
2986 // - a null variant (IsNull() returns true)
2987 // - a list variant (GetType() == wxT("list")
2988 // - an integer representing the selected child element,
2989 // or 0 if this object is selected (GetType() == wxT("long")
2990 // - a "void*" pointer to a wxAccessible child object
2991 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2993 wxASSERT( GetWindow() != NULL
);
2997 return wxACC_NOT_IMPLEMENTED
;
3000 #endif // wxUSE_ACCESSIBILITY