1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/string.h"
32 #include "wx/window.h"
33 #include "wx/control.h"
34 #include "wx/checkbox.h"
35 #include "wx/radiobut.h"
36 #include "wx/statbox.h"
37 #include "wx/textctrl.h"
38 #include "wx/settings.h"
39 #include "wx/dialog.h"
40 #include "wx/msgdlg.h"
41 #include "wx/statusbr.h"
42 #include "wx/toolbar.h"
43 #include "wx/dcclient.h"
44 #include "wx/scrolbar.h"
45 #include "wx/layout.h"
49 #if wxUSE_DRAG_AND_DROP
51 #endif // wxUSE_DRAG_AND_DROP
53 #if wxUSE_ACCESSIBILITY
54 #include "wx/access.h"
58 #include "wx/cshelp.h"
62 #include "wx/tooltip.h"
63 #endif // wxUSE_TOOLTIPS
69 #if wxUSE_SYSTEM_OPTIONS
70 #include "wx/sysopt.h"
73 // For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog.
74 // The gtk includes don't pull any other headers in, at least not on my system - MR
77 #include <gtk/gtkversion.h>
79 #include <gtk/gtkfeatures.h>
81 extern const unsigned int gtk_major_version
;
82 extern const unsigned int gtk_minor_version
;
83 extern const unsigned int gtk_micro_version
;
86 #include "wx/platinfo.h"
89 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 #if defined(__WXPALMOS__)
96 int wxWindowBase::ms_lastControlId
= 32767;
97 #elif defined(__WXPM__)
98 int wxWindowBase::ms_lastControlId
= 2000;
100 int wxWindowBase::ms_lastControlId
= -200;
103 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
110 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
111 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
112 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
115 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
120 // ============================================================================
121 // implementation of the common functionality of the wxWindow class
122 // ============================================================================
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
128 // the default initialization
129 wxWindowBase::wxWindowBase()
131 // no window yet, no parent nor children
132 m_parent
= (wxWindow
*)NULL
;
133 m_windowId
= wxID_ANY
;
135 // no constraints on the minimal window size
137 m_maxWidth
= wxDefaultCoord
;
139 m_maxHeight
= wxDefaultCoord
;
141 // invalidiated cache value
142 m_bestSizeCache
= wxDefaultSize
;
144 // window are created enabled and visible by default
148 // the default event handler is just this window
149 m_eventHandler
= this;
153 m_windowValidator
= (wxValidator
*) NULL
;
154 #endif // wxUSE_VALIDATORS
156 // the colours/fonts are default for now, so leave m_font,
157 // m_backgroundColour and m_foregroundColour uninitialized and set those
163 m_inheritFont
= false;
169 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
171 #if wxUSE_CONSTRAINTS
172 // no constraints whatsoever
173 m_constraints
= (wxLayoutConstraints
*) NULL
;
174 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
175 #endif // wxUSE_CONSTRAINTS
177 m_windowSizer
= (wxSizer
*) NULL
;
178 m_containingSizer
= (wxSizer
*) NULL
;
179 m_autoLayout
= false;
181 #if wxUSE_DRAG_AND_DROP
182 m_dropTarget
= (wxDropTarget
*)NULL
;
183 #endif // wxUSE_DRAG_AND_DROP
186 m_tooltip
= (wxToolTip
*)NULL
;
187 #endif // wxUSE_TOOLTIPS
190 m_caret
= (wxCaret
*)NULL
;
191 #endif // wxUSE_CARET
194 m_hasCustomPalette
= false;
195 #endif // wxUSE_PALETTE
197 #if wxUSE_ACCESSIBILITY
201 m_virtualSize
= wxDefaultSize
;
203 m_scrollHelper
= (wxScrollHelper
*) NULL
;
206 m_maxVirtualWidth
= wxDefaultCoord
;
208 m_maxVirtualHeight
= wxDefaultCoord
;
210 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
211 #if wxUSE_SYSTEM_OPTIONS
212 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
214 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
218 // Whether we're using the current theme for this window (wxGTK only for now)
219 m_themeEnabled
= false;
221 // VZ: this one shouldn't exist...
222 m_isBeingDeleted
= false;
225 // common part of window creation process
226 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
228 const wxPoint
& WXUNUSED(pos
),
229 const wxSize
& WXUNUSED(size
),
231 const wxValidator
& wxVALIDATOR_PARAM(validator
),
232 const wxString
& name
)
235 // wxGTK doesn't allow to create controls with static box as the parent so
236 // this will result in a crash when the program is ported to wxGTK so warn
239 // if you get this assert, the correct solution is to create the controls
240 // as siblings of the static box
241 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
242 _T("wxStaticBox can't be used as a window parent!") );
243 #endif // wxUSE_STATBOX
245 // ids are limited to 16 bits under MSW so if you care about portability,
246 // it's not a good idea to use ids out of this range (and negative ids are
247 // reserved for wxWidgets own usage)
248 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
249 _T("invalid id value") );
251 // generate a new id if the user doesn't care about it
252 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
255 SetWindowStyleFlag(style
);
259 SetValidator(validator
);
260 #endif // wxUSE_VALIDATORS
262 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
263 // have it too - like this it's possible to set it only in the top level
264 // dialog/frame and all children will inherit it by defult
265 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
267 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
273 // ----------------------------------------------------------------------------
275 // ----------------------------------------------------------------------------
278 wxWindowBase::~wxWindowBase()
280 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
282 // FIXME if these 2 cases result from programming errors in the user code
283 // we should probably assert here instead of silently fixing them
285 // Just in case the window has been Closed, but we're then deleting
286 // immediately: don't leave dangling pointers.
287 wxPendingDelete
.DeleteObject(this);
289 // Just in case we've loaded a top-level window via LoadNativeDialog but
290 // we weren't a dialog class
291 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
293 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
295 // reset the top-level parent's default item if it is this widget
298 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this),
301 if ( tlw
&& tlw
->GetDefaultItem() == this )
302 tlw
->SetDefaultItem(NULL
);
303 if ( tlw
&& tlw
->GetTmpDefaultItem() == this )
304 tlw
->SetTmpDefaultItem(NULL
);
307 // reset the dangling pointer our parent window may keep to us
310 m_parent
->RemoveChild(this);
315 #endif // wxUSE_CARET
318 delete m_windowValidator
;
319 #endif // wxUSE_VALIDATORS
321 #if wxUSE_CONSTRAINTS
322 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
323 // at deleted windows as they delete themselves.
324 DeleteRelatedConstraints();
328 // This removes any dangling pointers to this window in other windows'
329 // constraintsInvolvedIn lists.
330 UnsetConstraints(m_constraints
);
331 delete m_constraints
;
332 m_constraints
= NULL
;
334 #endif // wxUSE_CONSTRAINTS
336 if ( m_containingSizer
)
337 m_containingSizer
->Detach( (wxWindow
*)this );
339 delete m_windowSizer
;
341 #if wxUSE_DRAG_AND_DROP
343 #endif // wxUSE_DRAG_AND_DROP
347 #endif // wxUSE_TOOLTIPS
349 #if wxUSE_ACCESSIBILITY
354 void wxWindowBase::SendDestroyEvent()
356 wxWindowDestroyEvent event
;
357 event
.SetEventObject(this);
358 event
.SetId(GetId());
359 GetEventHandler()->ProcessEvent(event
);
362 bool wxWindowBase::Destroy()
369 bool wxWindowBase::Close(bool force
)
371 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
372 event
.SetEventObject(this);
373 event
.SetCanVeto(!force
);
375 // return false if window wasn't closed because the application vetoed the
377 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
380 bool wxWindowBase::DestroyChildren()
382 wxWindowList::compatibility_iterator node
;
385 // we iterate until the list becomes empty
386 node
= GetChildren().GetFirst();
390 wxWindow
*child
= node
->GetData();
392 // note that we really want to call delete and not ->Destroy() here
393 // because we want to delete the child immediately, before we are
394 // deleted, and delayed deletion would result in problems as our (top
395 // level) child could outlive its parent
398 wxASSERT_MSG( !GetChildren().Find(child
),
399 wxT("child didn't remove itself using RemoveChild()") );
405 // ----------------------------------------------------------------------------
406 // size/position related methods
407 // ----------------------------------------------------------------------------
409 // centre the window with respect to its parent in either (or both) directions
410 void wxWindowBase::DoCentre(int dir
)
412 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
413 _T("this method only implements centering child windows") );
415 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
418 // fits the window around the children
419 void wxWindowBase::Fit()
421 if ( !GetChildren().empty() )
423 SetSize(GetBestSize());
425 //else: do nothing if we have no children
428 // fits virtual size (ie. scrolled area etc.) around children
429 void wxWindowBase::FitInside()
431 if ( GetChildren().GetCount() > 0 )
433 SetVirtualSize( GetBestVirtualSize() );
437 // On Mac, scrollbars are explicitly children.
439 static bool wxHasRealChildren(const wxWindowBase
* win
)
441 int realChildCount
= 0;
443 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
445 node
= node
->GetNext() )
447 wxWindow
*win
= node
->GetData();
448 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
451 return (realChildCount
> 0);
455 void wxWindowBase::InvalidateBestSize()
457 m_bestSizeCache
= wxDefaultSize
;
459 // parent's best size calculation may depend on its children's
460 // as long as child window we are in is not top level window itself
461 // (because the TLW size is never resized automatically)
462 // so let's invalidate it as well to be safe:
463 if (m_parent
&& !IsTopLevel())
464 m_parent
->InvalidateBestSize();
467 // return the size best suited for the current window
468 wxSize
wxWindowBase::DoGetBestSize() const
474 best
= GetWindowSizeForVirtualSize(m_windowSizer
->GetMinSize());
476 #if wxUSE_CONSTRAINTS
477 else if ( m_constraints
)
479 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
481 // our minimal acceptable size is such that all our windows fit inside
485 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
487 node
= node
->GetNext() )
489 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
492 // it's not normal that we have an unconstrained child, but
493 // what can we do about it?
497 int x
= c
->right
.GetValue(),
498 y
= c
->bottom
.GetValue();
506 // TODO: we must calculate the overlaps somehow, otherwise we
507 // will never return a size bigger than the current one :-(
510 best
= wxSize(maxX
, maxY
);
512 #endif // wxUSE_CONSTRAINTS
513 else if ( !GetChildren().empty()
515 && wxHasRealChildren(this)
519 // our minimal acceptable size is such that all our visible child
520 // windows fit inside
524 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
526 node
= node
->GetNext() )
528 wxWindow
*win
= node
->GetData();
529 if ( win
->IsTopLevel()
532 || wxDynamicCast(win
, wxStatusBar
)
533 #endif // wxUSE_STATUSBAR
536 // dialogs and frames lie in different top level windows -
537 // don't deal with them here; as for the status bars, they
538 // don't lie in the client area at all
543 win
->GetPosition(&wx
, &wy
);
545 // if the window hadn't been positioned yet, assume that it is in
547 if ( wx
== wxDefaultCoord
)
549 if ( wy
== wxDefaultCoord
)
552 win
->GetSize(&ww
, &wh
);
553 if ( wx
+ ww
> maxX
)
555 if ( wy
+ wh
> maxY
)
559 best
= wxSize(maxX
, maxY
);
561 else // ! has children
563 // for a generic window there is no natural best size so, if the
564 // minimal size is not set, use the current size but take care to
565 // remember it as minimal size for the next time because our best size
566 // should be constant: otherwise we could get into a situation when the
567 // window is initially at some size, then expanded to a larger size and
568 // then, when the containing window is shrunk back (because our initial
569 // best size had been used for computing the parent min size), we can't
570 // be shrunk back any more because our best size is now bigger
571 wxSize size
= GetMinSize();
572 if ( !size
.IsFullySpecified() )
574 size
.SetDefaults(GetSize());
575 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
578 // return as-is, unadjusted by the client size difference.
582 // Add any difference between size and client size
583 wxSize diff
= GetSize() - GetClientSize();
584 best
.x
+= wxMax(0, diff
.x
);
585 best
.y
+= wxMax(0, diff
.y
);
590 // helper of GetWindowBorderSize(): as many ports don't implement support for
591 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
592 // fallbacks in this case
593 static int wxGetMetricOrDefault(wxSystemMetric what
)
595 int rc
= wxSystemSettings::GetMetric(what
);
602 // 2D border is by default 1 pixel wide
608 // 3D borders are by default 2 pixels
613 wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
621 wxSize
wxWindowBase::GetWindowBorderSize() const
625 switch ( GetBorder() )
628 // nothing to do, size is already (0, 0)
631 case wxBORDER_SIMPLE
:
632 case wxBORDER_STATIC
:
633 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
);
634 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
);
637 case wxBORDER_SUNKEN
:
638 case wxBORDER_RAISED
:
639 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
),
640 wxGetMetricOrDefault(wxSYS_BORDER_X
));
641 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
),
642 wxGetMetricOrDefault(wxSYS_BORDER_Y
));
645 case wxBORDER_DOUBLE
:
646 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
) +
647 wxGetMetricOrDefault(wxSYS_BORDER_X
);
648 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
) +
649 wxGetMetricOrDefault(wxSYS_BORDER_Y
);
653 wxFAIL_MSG(_T("Unknown border style."));
657 // we have borders on both sides
661 wxSize
wxWindowBase::GetEffectiveMinSize() const
663 // merge the best size with the min size, giving priority to the min size
664 wxSize min
= GetMinSize();
665 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
667 wxSize best
= GetBestSize();
668 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
669 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
675 void wxWindowBase::SetInitialSize(const wxSize
& size
)
677 // Set the min size to the size passed in. This will usually either be
678 // wxDefaultSize or the size passed to this window's ctor/Create function.
681 // Merge the size with the best size if needed
682 wxSize best
= GetEffectiveMinSize();
684 // If the current size doesn't match then change it
685 if (GetSize() != best
)
690 // by default the origin is not shifted
691 wxPoint
wxWindowBase::GetClientAreaOrigin() const
696 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
698 if ( m_windowVariant
!= variant
)
700 m_windowVariant
= variant
;
702 DoSetWindowVariant(variant
);
706 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
708 // adjust the font height to correspond to our new variant (notice that
709 // we're only called if something really changed)
710 wxFont font
= GetFont();
711 int size
= font
.GetPointSize();
714 case wxWINDOW_VARIANT_NORMAL
:
717 case wxWINDOW_VARIANT_SMALL
:
722 case wxWINDOW_VARIANT_MINI
:
727 case wxWINDOW_VARIANT_LARGE
:
733 wxFAIL_MSG(_T("unexpected window variant"));
737 font
.SetPointSize(size
);
741 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
743 int WXUNUSED(incW
), int WXUNUSED(incH
) )
745 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
746 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
747 _T("min width/height must be less than max width/height!") );
756 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
759 m_minVirtualWidth
= minW
;
760 m_maxVirtualWidth
= maxW
;
761 m_minVirtualHeight
= minH
;
762 m_maxVirtualHeight
= maxH
;
765 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
767 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
768 x
= m_minVirtualWidth
;
769 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
770 x
= m_maxVirtualWidth
;
771 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
772 y
= m_minVirtualHeight
;
773 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
774 y
= m_maxVirtualHeight
;
776 m_virtualSize
= wxSize(x
, y
);
779 wxSize
wxWindowBase::DoGetVirtualSize() const
781 // we should use the entire client area so if it is greater than our
782 // virtual size, expand it to fit (otherwise if the window is big enough we
783 // wouldn't be using parts of it)
784 wxSize size
= GetClientSize();
785 if ( m_virtualSize
.x
> size
.x
)
786 size
.x
= m_virtualSize
.x
;
788 if ( m_virtualSize
.y
>= size
.y
)
789 size
.y
= m_virtualSize
.y
;
794 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
796 // screen position is the same as (0, 0) in client coords for non TLWs (and
797 // TLWs override this method)
803 ClientToScreen(x
, y
);
806 // ----------------------------------------------------------------------------
807 // show/hide/enable/disable the window
808 // ----------------------------------------------------------------------------
810 bool wxWindowBase::Show(bool show
)
812 if ( show
!= m_isShown
)
824 bool wxWindowBase::Enable(bool enable
)
826 if ( enable
!= m_isEnabled
)
828 m_isEnabled
= enable
;
838 bool wxWindowBase::IsShownOnScreen() const
841 (GetParent() == NULL
|| GetParent()->IsShownOnScreen());
844 // ----------------------------------------------------------------------------
846 // ----------------------------------------------------------------------------
848 bool wxWindowBase::IsTopLevel() const
853 // ----------------------------------------------------------------------------
854 // reparenting the window
855 // ----------------------------------------------------------------------------
857 void wxWindowBase::AddChild(wxWindowBase
*child
)
859 wxCHECK_RET( child
, wxT("can't add a NULL child") );
861 // this should never happen and it will lead to a crash later if it does
862 // because RemoveChild() will remove only one node from the children list
863 // and the other(s) one(s) will be left with dangling pointers in them
864 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
866 GetChildren().Append((wxWindow
*)child
);
867 child
->SetParent(this);
870 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
872 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
874 GetChildren().DeleteObject((wxWindow
*)child
);
875 child
->SetParent(NULL
);
878 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
880 wxWindow
*oldParent
= GetParent();
881 if ( newParent
== oldParent
)
887 // unlink this window from the existing parent.
890 oldParent
->RemoveChild(this);
894 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
897 // add it to the new one
900 newParent
->AddChild(this);
904 wxTopLevelWindows
.Append((wxWindow
*)this);
910 // ----------------------------------------------------------------------------
911 // event handler stuff
912 // ----------------------------------------------------------------------------
914 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
916 wxEvtHandler
*handlerOld
= GetEventHandler();
918 handler
->SetNextHandler(handlerOld
);
921 GetEventHandler()->SetPreviousHandler(handler
);
923 SetEventHandler(handler
);
926 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
928 wxEvtHandler
*handlerA
= GetEventHandler();
931 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
932 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
935 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
936 SetEventHandler(handlerB
);
941 handlerA
= (wxEvtHandler
*)NULL
;
948 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
950 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
952 wxEvtHandler
*handlerPrev
= NULL
,
953 *handlerCur
= GetEventHandler();
956 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
958 if ( handlerCur
== handler
)
962 handlerPrev
->SetNextHandler(handlerNext
);
966 SetEventHandler(handlerNext
);
971 handlerNext
->SetPreviousHandler ( handlerPrev
);
974 handler
->SetNextHandler(NULL
);
975 handler
->SetPreviousHandler(NULL
);
980 handlerPrev
= handlerCur
;
981 handlerCur
= handlerNext
;
984 wxFAIL_MSG( _T("where has the event handler gone?") );
989 // ----------------------------------------------------------------------------
991 // ----------------------------------------------------------------------------
993 void wxWindowBase::InheritAttributes()
995 const wxWindowBase
* const parent
= GetParent();
999 // we only inherit attributes which had been explicitly set for the parent
1000 // which ensures that this only happens if the user really wants it and
1001 // not by default which wouldn't make any sense in modern GUIs where the
1002 // controls don't all use the same fonts (nor colours)
1003 if ( parent
->m_inheritFont
&& !m_hasFont
)
1004 SetFont(parent
->GetFont());
1006 // in addition, there is a possibility to explicitly forbid inheriting
1007 // colours at each class level by overriding ShouldInheritColours()
1008 if ( ShouldInheritColours() )
1010 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1011 SetForegroundColour(parent
->GetForegroundColour());
1013 // inheriting (solid) background colour is wrong as it totally breaks
1014 // any kind of themed backgrounds
1016 // instead, the controls should use the same background as their parent
1017 // (ideally by not drawing it at all)
1019 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1020 SetBackgroundColour(parent
->GetBackgroundColour());
1025 /* static */ wxVisualAttributes
1026 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1028 // it is important to return valid values for all attributes from here,
1029 // GetXXX() below rely on this
1030 wxVisualAttributes attrs
;
1031 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1032 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1034 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1035 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1036 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1037 // colour on other platforms.
1039 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1040 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1042 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1047 wxColour
wxWindowBase::GetBackgroundColour() const
1049 if ( !m_backgroundColour
.Ok() )
1051 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1053 // get our default background colour
1054 wxColour colBg
= GetDefaultAttributes().colBg
;
1056 // we must return some valid colour to avoid redoing this every time
1057 // and also to avoid surprizing the applications written for older
1058 // wxWidgets versions where GetBackgroundColour() always returned
1059 // something -- so give them something even if it doesn't make sense
1060 // for this window (e.g. it has a themed background)
1062 colBg
= GetClassDefaultAttributes().colBg
;
1067 return m_backgroundColour
;
1070 wxColour
wxWindowBase::GetForegroundColour() const
1072 // logic is the same as above
1073 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1075 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
1077 wxColour colFg
= GetDefaultAttributes().colFg
;
1080 colFg
= GetClassDefaultAttributes().colFg
;
1085 return m_foregroundColour
;
1088 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1090 if ( colour
== m_backgroundColour
)
1093 m_hasBgCol
= colour
.Ok();
1094 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1095 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1097 m_inheritBgCol
= m_hasBgCol
;
1098 m_backgroundColour
= colour
;
1099 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1103 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1105 if (colour
== m_foregroundColour
)
1108 m_hasFgCol
= colour
.Ok();
1109 m_inheritFgCol
= m_hasFgCol
;
1110 m_foregroundColour
= colour
;
1111 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1115 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1117 // setting an invalid cursor is ok, it means that we don't have any special
1119 if ( m_cursor
.IsSameAs(cursor
) )
1130 wxFont
wxWindowBase::GetFont() const
1132 // logic is the same as in GetBackgroundColour()
1135 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1137 wxFont font
= GetDefaultAttributes().font
;
1139 font
= GetClassDefaultAttributes().font
;
1147 bool wxWindowBase::SetFont(const wxFont
& font
)
1149 if ( font
== m_font
)
1156 m_hasFont
= font
.Ok();
1157 m_inheritFont
= m_hasFont
;
1159 InvalidateBestSize();
1166 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1168 m_hasCustomPalette
= true;
1171 // VZ: can anyone explain me what do we do here?
1172 wxWindowDC
d((wxWindow
*) this);
1176 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1178 wxWindow
*win
= (wxWindow
*)this;
1179 while ( win
&& !win
->HasCustomPalette() )
1181 win
= win
->GetParent();
1187 #endif // wxUSE_PALETTE
1190 void wxWindowBase::SetCaret(wxCaret
*caret
)
1201 wxASSERT_MSG( m_caret
->GetWindow() == this,
1202 wxT("caret should be created associated to this window") );
1205 #endif // wxUSE_CARET
1207 #if wxUSE_VALIDATORS
1208 // ----------------------------------------------------------------------------
1210 // ----------------------------------------------------------------------------
1212 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1214 if ( m_windowValidator
)
1215 delete m_windowValidator
;
1217 m_windowValidator
= (wxValidator
*)validator
.Clone();
1219 if ( m_windowValidator
)
1220 m_windowValidator
->SetWindow(this);
1222 #endif // wxUSE_VALIDATORS
1224 // ----------------------------------------------------------------------------
1225 // update region stuff
1226 // ----------------------------------------------------------------------------
1228 wxRect
wxWindowBase::GetUpdateClientRect() const
1230 wxRegion rgnUpdate
= GetUpdateRegion();
1231 rgnUpdate
.Intersect(GetClientRect());
1232 wxRect rectUpdate
= rgnUpdate
.GetBox();
1233 wxPoint ptOrigin
= GetClientAreaOrigin();
1234 rectUpdate
.x
-= ptOrigin
.x
;
1235 rectUpdate
.y
-= ptOrigin
.y
;
1240 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1242 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1245 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1247 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1250 void wxWindowBase::ClearBackground()
1252 // wxGTK uses its own version, no need to add never used code
1254 wxClientDC
dc((wxWindow
*)this);
1255 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1256 dc
.SetBackground(brush
);
1261 // ----------------------------------------------------------------------------
1262 // find child window by id or name
1263 // ----------------------------------------------------------------------------
1265 wxWindow
*wxWindowBase::FindWindow(long id
) const
1267 if ( id
== m_windowId
)
1268 return (wxWindow
*)this;
1270 wxWindowBase
*res
= (wxWindow
*)NULL
;
1271 wxWindowList::compatibility_iterator node
;
1272 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1274 wxWindowBase
*child
= node
->GetData();
1275 res
= child
->FindWindow( id
);
1278 return (wxWindow
*)res
;
1281 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1283 if ( name
== m_windowName
)
1284 return (wxWindow
*)this;
1286 wxWindowBase
*res
= (wxWindow
*)NULL
;
1287 wxWindowList::compatibility_iterator node
;
1288 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1290 wxWindow
*child
= node
->GetData();
1291 res
= child
->FindWindow(name
);
1294 return (wxWindow
*)res
;
1298 // find any window by id or name or label: If parent is non-NULL, look through
1299 // children for a label or title matching the specified string. If NULL, look
1300 // through all top-level windows.
1302 // to avoid duplicating code we reuse the same helper function but with
1303 // different comparators
1305 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1306 const wxString
& label
, long id
);
1309 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1312 return win
->GetLabel() == label
;
1316 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1319 return win
->GetName() == label
;
1323 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1326 return win
->GetId() == id
;
1329 // recursive helper for the FindWindowByXXX() functions
1331 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1332 const wxString
& label
,
1334 wxFindWindowCmp cmp
)
1338 // see if this is the one we're looking for
1339 if ( (*cmp
)(parent
, label
, id
) )
1340 return (wxWindow
*)parent
;
1342 // It wasn't, so check all its children
1343 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1345 node
= node
->GetNext() )
1347 // recursively check each child
1348 wxWindow
*win
= (wxWindow
*)node
->GetData();
1349 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1359 // helper for FindWindowByXXX()
1361 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1362 const wxString
& label
,
1364 wxFindWindowCmp cmp
)
1368 // just check parent and all its children
1369 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1372 // start at very top of wx's windows
1373 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1375 node
= node
->GetNext() )
1377 // recursively check each window & its children
1378 wxWindow
*win
= node
->GetData();
1379 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1389 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1391 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1396 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1398 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1402 // fall back to the label
1403 win
= FindWindowByLabel(title
, parent
);
1411 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1413 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1416 // ----------------------------------------------------------------------------
1417 // dialog oriented functions
1418 // ----------------------------------------------------------------------------
1420 void wxWindowBase::MakeModal(bool modal
)
1422 // Disable all other windows
1425 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1428 wxWindow
*win
= node
->GetData();
1430 win
->Enable(!modal
);
1432 node
= node
->GetNext();
1437 bool wxWindowBase::Validate()
1439 #if wxUSE_VALIDATORS
1440 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1442 wxWindowList::compatibility_iterator node
;
1443 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1445 wxWindowBase
*child
= node
->GetData();
1446 wxValidator
*validator
= child
->GetValidator();
1447 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1452 if ( recurse
&& !child
->Validate() )
1457 #endif // wxUSE_VALIDATORS
1462 bool wxWindowBase::TransferDataToWindow()
1464 #if wxUSE_VALIDATORS
1465 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1467 wxWindowList::compatibility_iterator node
;
1468 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1470 wxWindowBase
*child
= node
->GetData();
1471 wxValidator
*validator
= child
->GetValidator();
1472 if ( validator
&& !validator
->TransferToWindow() )
1474 wxLogWarning(_("Could not transfer data to window"));
1476 wxLog::FlushActive();
1484 if ( !child
->TransferDataToWindow() )
1486 // warning already given
1491 #endif // wxUSE_VALIDATORS
1496 bool wxWindowBase::TransferDataFromWindow()
1498 #if wxUSE_VALIDATORS
1499 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1501 wxWindowList::compatibility_iterator node
;
1502 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1504 wxWindow
*child
= node
->GetData();
1505 wxValidator
*validator
= child
->GetValidator();
1506 if ( validator
&& !validator
->TransferFromWindow() )
1508 // nop warning here because the application is supposed to give
1509 // one itself - we don't know here what might have gone wrongly
1516 if ( !child
->TransferDataFromWindow() )
1518 // warning already given
1523 #endif // wxUSE_VALIDATORS
1528 void wxWindowBase::InitDialog()
1530 wxInitDialogEvent
event(GetId());
1531 event
.SetEventObject( this );
1532 GetEventHandler()->ProcessEvent(event
);
1535 // ----------------------------------------------------------------------------
1536 // context-sensitive help support
1537 // ----------------------------------------------------------------------------
1541 // associate this help text with this window
1542 void wxWindowBase::SetHelpText(const wxString
& text
)
1544 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1547 helpProvider
->AddHelp(this, text
);
1551 // associate this help text with all windows with the same id as this
1553 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1555 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1558 helpProvider
->AddHelp(GetId(), text
);
1562 // get the help string associated with this window (may be empty)
1563 // default implementation forwards calls to the help provider
1565 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1566 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1569 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1572 text
= helpProvider
->GetHelp(this);
1578 // show help for this window
1579 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1581 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1584 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1586 // skip the event.Skip() below
1594 #endif // wxUSE_HELP
1596 // ----------------------------------------------------------------------------
1598 // ----------------------------------------------------------------------------
1602 void wxWindowBase::SetToolTip( const wxString
&tip
)
1604 // don't create the new tooltip if we already have one
1607 m_tooltip
->SetTip( tip
);
1611 SetToolTip( new wxToolTip( tip
) );
1614 // setting empty tooltip text does not remove the tooltip any more - use
1615 // SetToolTip((wxToolTip *)NULL) for this
1618 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1620 if ( m_tooltip
!= tooltip
)
1625 m_tooltip
= tooltip
;
1629 #endif // wxUSE_TOOLTIPS
1631 // ----------------------------------------------------------------------------
1632 // constraints and sizers
1633 // ----------------------------------------------------------------------------
1635 #if wxUSE_CONSTRAINTS
1637 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1639 if ( m_constraints
)
1641 UnsetConstraints(m_constraints
);
1642 delete m_constraints
;
1644 m_constraints
= constraints
;
1645 if ( m_constraints
)
1647 // Make sure other windows know they're part of a 'meaningful relationship'
1648 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1649 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1650 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1651 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1652 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1653 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1654 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1655 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1656 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1657 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1658 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1659 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1660 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1661 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1662 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1663 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1667 // This removes any dangling pointers to this window in other windows'
1668 // constraintsInvolvedIn lists.
1669 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1673 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1674 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1675 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1676 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1677 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1678 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1679 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1680 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1681 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1682 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1683 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1684 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1685 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1686 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1687 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1688 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1692 // Back-pointer to other windows we're involved with, so if we delete this
1693 // window, we must delete any constraints we're involved with.
1694 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1696 if ( !m_constraintsInvolvedIn
)
1697 m_constraintsInvolvedIn
= new wxWindowList
;
1698 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1699 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1702 // REMOVE back-pointer to other windows we're involved with.
1703 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1705 if ( m_constraintsInvolvedIn
)
1706 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1709 // Reset any constraints that mention this window
1710 void wxWindowBase::DeleteRelatedConstraints()
1712 if ( m_constraintsInvolvedIn
)
1714 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1717 wxWindow
*win
= node
->GetData();
1718 wxLayoutConstraints
*constr
= win
->GetConstraints();
1720 // Reset any constraints involving this window
1723 constr
->left
.ResetIfWin(this);
1724 constr
->top
.ResetIfWin(this);
1725 constr
->right
.ResetIfWin(this);
1726 constr
->bottom
.ResetIfWin(this);
1727 constr
->width
.ResetIfWin(this);
1728 constr
->height
.ResetIfWin(this);
1729 constr
->centreX
.ResetIfWin(this);
1730 constr
->centreY
.ResetIfWin(this);
1733 wxWindowList::compatibility_iterator next
= node
->GetNext();
1734 m_constraintsInvolvedIn
->Erase(node
);
1738 delete m_constraintsInvolvedIn
;
1739 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1743 #endif // wxUSE_CONSTRAINTS
1745 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1747 if ( sizer
== m_windowSizer
)
1750 if ( m_windowSizer
)
1752 m_windowSizer
->SetContainingWindow(NULL
);
1755 delete m_windowSizer
;
1758 m_windowSizer
= sizer
;
1759 if ( m_windowSizer
)
1761 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1764 SetAutoLayout(m_windowSizer
!= NULL
);
1767 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1769 SetSizer( sizer
, deleteOld
);
1770 sizer
->SetSizeHints( (wxWindow
*) this );
1774 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1776 // adding a window to a sizer twice is going to result in fatal and
1777 // hard to debug problems later because when deleting the second
1778 // associated wxSizerItem we're going to dereference a dangling
1779 // pointer; so try to detect this as early as possible
1780 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1781 _T("Adding a window to the same sizer twice?") );
1783 m_containingSizer
= sizer
;
1786 #if wxUSE_CONSTRAINTS
1788 void wxWindowBase::SatisfyConstraints()
1790 wxLayoutConstraints
*constr
= GetConstraints();
1791 bool wasOk
= constr
&& constr
->AreSatisfied();
1793 ResetConstraints(); // Mark all constraints as unevaluated
1797 // if we're a top level panel (i.e. our parent is frame/dialog), our
1798 // own constraints will never be satisfied any more unless we do it
1802 while ( noChanges
> 0 )
1804 LayoutPhase1(&noChanges
);
1808 LayoutPhase2(&noChanges
);
1811 #endif // wxUSE_CONSTRAINTS
1813 bool wxWindowBase::Layout()
1815 // If there is a sizer, use it instead of the constraints
1819 GetVirtualSize(&w
, &h
);
1820 GetSizer()->SetDimension( 0, 0, w
, h
);
1822 #if wxUSE_CONSTRAINTS
1825 SatisfyConstraints(); // Find the right constraints values
1826 SetConstraintSizes(); // Recursively set the real window sizes
1833 #if wxUSE_CONSTRAINTS
1835 // first phase of the constraints evaluation: set our own constraints
1836 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1838 wxLayoutConstraints
*constr
= GetConstraints();
1840 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1843 // second phase: set the constraints for our children
1844 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1851 // Layout grand children
1857 // Do a phase of evaluating child constraints
1858 bool wxWindowBase::DoPhase(int phase
)
1860 // the list containing the children for which the constraints are already
1862 wxWindowList succeeded
;
1864 // the max number of iterations we loop before concluding that we can't set
1866 static const int maxIterations
= 500;
1868 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1872 // loop over all children setting their constraints
1873 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1875 node
= node
->GetNext() )
1877 wxWindow
*child
= node
->GetData();
1878 if ( child
->IsTopLevel() )
1880 // top level children are not inside our client area
1884 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1886 // this one is either already ok or nothing we can do about it
1890 int tempNoChanges
= 0;
1891 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1892 : child
->LayoutPhase2(&tempNoChanges
);
1893 noChanges
+= tempNoChanges
;
1897 succeeded
.Append(child
);
1903 // constraints are set
1911 void wxWindowBase::ResetConstraints()
1913 wxLayoutConstraints
*constr
= GetConstraints();
1916 constr
->left
.SetDone(false);
1917 constr
->top
.SetDone(false);
1918 constr
->right
.SetDone(false);
1919 constr
->bottom
.SetDone(false);
1920 constr
->width
.SetDone(false);
1921 constr
->height
.SetDone(false);
1922 constr
->centreX
.SetDone(false);
1923 constr
->centreY
.SetDone(false);
1926 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1929 wxWindow
*win
= node
->GetData();
1930 if ( !win
->IsTopLevel() )
1931 win
->ResetConstraints();
1932 node
= node
->GetNext();
1936 // Need to distinguish between setting the 'fake' size for windows and sizers,
1937 // and setting the real values.
1938 void wxWindowBase::SetConstraintSizes(bool recurse
)
1940 wxLayoutConstraints
*constr
= GetConstraints();
1941 if ( constr
&& constr
->AreSatisfied() )
1943 int x
= constr
->left
.GetValue();
1944 int y
= constr
->top
.GetValue();
1945 int w
= constr
->width
.GetValue();
1946 int h
= constr
->height
.GetValue();
1948 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1949 (constr
->height
.GetRelationship() != wxAsIs
) )
1951 SetSize(x
, y
, w
, h
);
1955 // If we don't want to resize this window, just move it...
1961 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1962 GetClassInfo()->GetClassName(),
1968 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1971 wxWindow
*win
= node
->GetData();
1972 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1973 win
->SetConstraintSizes();
1974 node
= node
->GetNext();
1979 // Only set the size/position of the constraint (if any)
1980 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1982 wxLayoutConstraints
*constr
= GetConstraints();
1985 if ( x
!= wxDefaultCoord
)
1987 constr
->left
.SetValue(x
);
1988 constr
->left
.SetDone(true);
1990 if ( y
!= wxDefaultCoord
)
1992 constr
->top
.SetValue(y
);
1993 constr
->top
.SetDone(true);
1995 if ( w
!= wxDefaultCoord
)
1997 constr
->width
.SetValue(w
);
1998 constr
->width
.SetDone(true);
2000 if ( h
!= wxDefaultCoord
)
2002 constr
->height
.SetValue(h
);
2003 constr
->height
.SetDone(true);
2008 void wxWindowBase::MoveConstraint(int x
, int y
)
2010 wxLayoutConstraints
*constr
= GetConstraints();
2013 if ( x
!= wxDefaultCoord
)
2015 constr
->left
.SetValue(x
);
2016 constr
->left
.SetDone(true);
2018 if ( y
!= wxDefaultCoord
)
2020 constr
->top
.SetValue(y
);
2021 constr
->top
.SetDone(true);
2026 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2028 wxLayoutConstraints
*constr
= GetConstraints();
2031 *w
= constr
->width
.GetValue();
2032 *h
= constr
->height
.GetValue();
2038 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2040 wxLayoutConstraints
*constr
= GetConstraints();
2043 *w
= constr
->width
.GetValue();
2044 *h
= constr
->height
.GetValue();
2047 GetClientSize(w
, h
);
2050 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2052 wxLayoutConstraints
*constr
= GetConstraints();
2055 *x
= constr
->left
.GetValue();
2056 *y
= constr
->top
.GetValue();
2062 #endif // wxUSE_CONSTRAINTS
2064 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2066 // don't do it for the dialogs/frames - they float independently of their
2068 if ( !IsTopLevel() )
2070 wxWindow
*parent
= GetParent();
2071 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2073 wxPoint
pt(parent
->GetClientAreaOrigin());
2080 // ----------------------------------------------------------------------------
2081 // Update UI processing
2082 // ----------------------------------------------------------------------------
2084 void wxWindowBase::UpdateWindowUI(long flags
)
2086 wxUpdateUIEvent
event(GetId());
2087 event
.SetEventObject(this);
2089 if ( GetEventHandler()->ProcessEvent(event
) )
2091 DoUpdateWindowUI(event
);
2094 if (flags
& wxUPDATE_UI_RECURSE
)
2096 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2099 wxWindow
* child
= (wxWindow
*) node
->GetData();
2100 child
->UpdateWindowUI(flags
);
2101 node
= node
->GetNext();
2106 // do the window-specific processing after processing the update event
2107 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2109 if ( event
.GetSetEnabled() )
2110 Enable(event
.GetEnabled());
2112 if ( event
.GetSetShown() )
2113 Show(event
.GetShown());
2116 // ----------------------------------------------------------------------------
2117 // dialog units translations
2118 // ----------------------------------------------------------------------------
2120 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2122 int charWidth
= GetCharWidth();
2123 int charHeight
= GetCharHeight();
2124 wxPoint pt2
= wxDefaultPosition
;
2125 if (pt
.x
!= wxDefaultCoord
)
2126 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2127 if (pt
.y
!= wxDefaultCoord
)
2128 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2133 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2135 int charWidth
= GetCharWidth();
2136 int charHeight
= GetCharHeight();
2137 wxPoint pt2
= wxDefaultPosition
;
2138 if (pt
.x
!= wxDefaultCoord
)
2139 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2140 if (pt
.y
!= wxDefaultCoord
)
2141 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2146 // ----------------------------------------------------------------------------
2148 // ----------------------------------------------------------------------------
2150 // propagate the colour change event to the subwindows
2151 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2153 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2156 // Only propagate to non-top-level windows
2157 wxWindow
*win
= node
->GetData();
2158 if ( !win
->IsTopLevel() )
2160 wxSysColourChangedEvent event2
;
2161 event
.SetEventObject(win
);
2162 win
->GetEventHandler()->ProcessEvent(event2
);
2165 node
= node
->GetNext();
2171 // the default action is to populate dialog with data when it's created,
2172 // and nudge the UI into displaying itself correctly in case
2173 // we've turned the wxUpdateUIEvents frequency down low.
2174 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2176 TransferDataToWindow();
2178 // Update the UI at this point
2179 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2182 // methods for drawing the sizers in a visible way
2185 static void DrawSizers(wxWindowBase
*win
);
2187 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2189 wxClientDC
dc((wxWindow
*)win
);
2190 dc
.SetPen(*wxRED_PEN
);
2191 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2192 dc
.DrawRectangle(rect
.Deflate(1, 1));
2195 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2197 const wxSizerItemList
& items
= sizer
->GetChildren();
2198 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2203 wxSizerItem
*item
= *i
;
2204 if ( item
->IsSizer() )
2206 DrawBorder(win
, item
->GetRect().Deflate(2));
2207 DrawSizer(win
, item
->GetSizer());
2209 else if ( item
->IsSpacer() )
2211 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2213 else if ( item
->IsWindow() )
2215 DrawSizers(item
->GetWindow());
2220 static void DrawSizers(wxWindowBase
*win
)
2222 wxSizer
*sizer
= win
->GetSizer();
2225 DrawBorder(win
, win
->GetClientSize());
2226 DrawSizer(win
, sizer
);
2228 else // no sizer, still recurse into the children
2230 const wxWindowList
& children
= win
->GetChildren();
2231 for ( wxWindowList::const_iterator i
= children
.begin(),
2232 end
= children
.end();
2241 #endif // __WXDEBUG__
2243 // process special middle clicks
2244 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2246 if ( event
.ControlDown() && event
.AltDown() )
2249 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2250 if ( event
.ShiftDown() )
2255 #endif // __WXDEBUG__
2258 // don't translate these strings, they're for diagnostics purposes only
2260 msg
.Printf(_T("wxWidgets Library (%s port)\n")
2261 _T("Version %d.%d.%d%s%s, compiled at %s %s\n")
2262 _T("Runtime version of toolkit used is %d.%d.%s\n")
2263 _T("Copyright (c) 1995-2006 wxWidgets team"),
2264 wxPlatformInfo::Get().GetPortIdName().c_str(),
2280 wxPlatformInfo::Get().GetToolkitMajorVersion(),
2281 wxPlatformInfo::Get().GetToolkitMinorVersion(),
2283 wxString::Format(_T("\nThe compile-time GTK+ version is %d.%d.%d."), GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
).c_str()
2289 wxMessageBox(msg
, _T("wxWidgets information"),
2290 wxICON_INFORMATION
| wxOK
,
2294 #endif // wxUSE_MSGDLG
2300 // ----------------------------------------------------------------------------
2302 // ----------------------------------------------------------------------------
2304 #if wxUSE_ACCESSIBILITY
2305 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2307 if (m_accessible
&& (accessible
!= m_accessible
))
2308 delete m_accessible
;
2309 m_accessible
= accessible
;
2311 m_accessible
->SetWindow((wxWindow
*) this);
2314 // Returns the accessible object, creating if necessary.
2315 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2318 m_accessible
= CreateAccessible();
2319 return m_accessible
;
2322 // Override to create a specific accessible object.
2323 wxAccessible
* wxWindowBase::CreateAccessible()
2325 return new wxWindowAccessible((wxWindow
*) this);
2330 // ----------------------------------------------------------------------------
2331 // list classes implementation
2332 // ----------------------------------------------------------------------------
2336 #include "wx/listimpl.cpp"
2337 WX_DEFINE_LIST(wxWindowList
)
2341 void wxWindowListNode::DeleteData()
2343 delete (wxWindow
*)GetData();
2346 #endif // wxUSE_STL/!wxUSE_STL
2348 // ----------------------------------------------------------------------------
2350 // ----------------------------------------------------------------------------
2352 wxBorder
wxWindowBase::GetBorder(long flags
) const
2354 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2355 if ( border
== wxBORDER_DEFAULT
)
2357 border
= GetDefaultBorder();
2363 wxBorder
wxWindowBase::GetDefaultBorder() const
2365 return wxBORDER_NONE
;
2368 // ----------------------------------------------------------------------------
2370 // ----------------------------------------------------------------------------
2372 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2374 // here we just check if the point is inside the window or not
2376 // check the top and left border first
2377 bool outside
= x
< 0 || y
< 0;
2380 // check the right and bottom borders too
2381 wxSize size
= GetSize();
2382 outside
= x
>= size
.x
|| y
>= size
.y
;
2385 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2388 // ----------------------------------------------------------------------------
2390 // ----------------------------------------------------------------------------
2392 struct WXDLLEXPORT wxWindowNext
2396 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2397 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2398 bool wxWindowBase::ms_winCaptureChanging
= false;
2400 void wxWindowBase::CaptureMouse()
2402 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2404 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2406 ms_winCaptureChanging
= true;
2408 wxWindow
*winOld
= GetCapture();
2411 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2414 wxWindowNext
*item
= new wxWindowNext
;
2416 item
->next
= ms_winCaptureNext
;
2417 ms_winCaptureNext
= item
;
2419 //else: no mouse capture to save
2422 ms_winCaptureCurrent
= (wxWindow
*)this;
2424 ms_winCaptureChanging
= false;
2427 void wxWindowBase::ReleaseMouse()
2429 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2431 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2433 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2435 ms_winCaptureChanging
= true;
2438 ms_winCaptureCurrent
= NULL
;
2440 if ( ms_winCaptureNext
)
2442 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2443 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2445 wxWindowNext
*item
= ms_winCaptureNext
;
2446 ms_winCaptureNext
= item
->next
;
2449 //else: stack is empty, no previous capture
2451 ms_winCaptureChanging
= false;
2453 wxLogTrace(_T("mousecapture"),
2454 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2455 wx_static_cast(void*, GetCapture()));
2458 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2460 wxMouseCaptureLostEvent
event(win
->GetId());
2461 event
.SetEventObject(win
);
2462 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2464 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2469 void wxWindowBase::NotifyCaptureLost()
2471 // don't do anything if capture lost was expected, i.e. resulted from
2472 // a wx call to ReleaseMouse or CaptureMouse:
2473 if ( ms_winCaptureChanging
)
2476 // if the capture was lost unexpectedly, notify every window that has
2477 // capture (on stack or current) about it and clear the stack:
2479 if ( ms_winCaptureCurrent
)
2481 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2482 ms_winCaptureCurrent
= NULL
;
2485 while ( ms_winCaptureNext
)
2487 wxWindowNext
*item
= ms_winCaptureNext
;
2488 ms_winCaptureNext
= item
->next
;
2490 DoNotifyWindowAboutCaptureLost(item
->win
);
2499 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2500 int WXUNUSED(modifiers
),
2501 int WXUNUSED(keycode
))
2507 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2513 #endif // wxUSE_HOTKEY
2515 // ----------------------------------------------------------------------------
2517 // ----------------------------------------------------------------------------
2519 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2521 #if wxUSE_VALIDATORS
2522 // Can only use the validator of the window which
2523 // is receiving the event
2524 if ( event
.GetEventObject() == this )
2526 wxValidator
*validator
= GetValidator();
2527 if ( validator
&& validator
->ProcessEvent(event
) )
2532 #endif // wxUSE_VALIDATORS
2537 bool wxWindowBase::TryParent(wxEvent
& event
)
2539 // carry on up the parent-child hierarchy if the propagation count hasn't
2541 if ( event
.ShouldPropagate() )
2543 // honour the requests to stop propagation at this window: this is
2544 // used by the dialogs, for example, to prevent processing the events
2545 // from the dialog controls in the parent frame which rarely, if ever,
2547 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2549 wxWindow
*parent
= GetParent();
2550 if ( parent
&& !parent
->IsBeingDeleted() )
2552 wxPropagateOnce
propagateOnce(event
);
2554 return parent
->GetEventHandler()->ProcessEvent(event
);
2559 return wxEvtHandler::TryParent(event
);
2562 // ----------------------------------------------------------------------------
2563 // keyboard navigation
2564 // ----------------------------------------------------------------------------
2566 // Navigates in the specified direction.
2567 bool wxWindowBase::Navigate(int flags
)
2569 wxNavigationKeyEvent eventNav
;
2570 eventNav
.SetFlags(flags
);
2571 eventNav
.SetEventObject(this);
2572 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2579 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2581 // check that we're not a top level window
2582 wxCHECK_RET( GetParent(),
2583 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2585 // detect the special case when we have nothing to do anyhow and when the
2586 // code below wouldn't work
2590 // find the target window in the siblings list
2591 wxWindowList
& siblings
= GetParent()->GetChildren();
2592 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2593 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2595 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2596 // can't just move the node around
2597 wxWindow
*self
= (wxWindow
*)this;
2598 siblings
.DeleteObject(self
);
2599 if ( move
== MoveAfter
)
2606 siblings
.Insert(i
, self
);
2608 else // MoveAfter and win was the last sibling
2610 siblings
.Append(self
);
2614 // ----------------------------------------------------------------------------
2616 // ----------------------------------------------------------------------------
2618 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2620 wxWindowBase
*win
= DoFindFocus();
2621 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2624 // ----------------------------------------------------------------------------
2626 // ----------------------------------------------------------------------------
2628 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2630 while ( win
&& !win
->IsTopLevel() )
2631 win
= win
->GetParent();
2636 #if wxUSE_ACCESSIBILITY
2637 // ----------------------------------------------------------------------------
2638 // accessible object for windows
2639 // ----------------------------------------------------------------------------
2641 // Can return either a child object, or an integer
2642 // representing the child element, starting from 1.
2643 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2645 wxASSERT( GetWindow() != NULL
);
2649 return wxACC_NOT_IMPLEMENTED
;
2652 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2653 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2655 wxASSERT( GetWindow() != NULL
);
2659 wxWindow
* win
= NULL
;
2666 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2668 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2675 rect
= win
->GetRect();
2676 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2677 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2681 return wxACC_NOT_IMPLEMENTED
;
2684 // Navigates from fromId to toId/toObject.
2685 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2686 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2688 wxASSERT( GetWindow() != NULL
);
2694 case wxNAVDIR_FIRSTCHILD
:
2696 if (GetWindow()->GetChildren().GetCount() == 0)
2698 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2699 *toObject
= childWindow
->GetOrCreateAccessible();
2703 case wxNAVDIR_LASTCHILD
:
2705 if (GetWindow()->GetChildren().GetCount() == 0)
2707 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2708 *toObject
= childWindow
->GetOrCreateAccessible();
2712 case wxNAVDIR_RIGHT
:
2716 wxWindowList::compatibility_iterator node
=
2717 wxWindowList::compatibility_iterator();
2720 // Can't navigate to sibling of this window
2721 // if we're a top-level window.
2722 if (!GetWindow()->GetParent())
2723 return wxACC_NOT_IMPLEMENTED
;
2725 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2729 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2730 node
= GetWindow()->GetChildren().Item(fromId
-1);
2733 if (node
&& node
->GetNext())
2735 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2736 *toObject
= nextWindow
->GetOrCreateAccessible();
2744 case wxNAVDIR_PREVIOUS
:
2746 wxWindowList::compatibility_iterator node
=
2747 wxWindowList::compatibility_iterator();
2750 // Can't navigate to sibling of this window
2751 // if we're a top-level window.
2752 if (!GetWindow()->GetParent())
2753 return wxACC_NOT_IMPLEMENTED
;
2755 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2759 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2760 node
= GetWindow()->GetChildren().Item(fromId
-1);
2763 if (node
&& node
->GetPrevious())
2765 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2766 *toObject
= previousWindow
->GetOrCreateAccessible();
2774 return wxACC_NOT_IMPLEMENTED
;
2777 // Gets the name of the specified object.
2778 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2780 wxASSERT( GetWindow() != NULL
);
2786 // If a child, leave wxWidgets to call the function on the actual
2789 return wxACC_NOT_IMPLEMENTED
;
2791 // This will eventually be replaced by specialised
2792 // accessible classes, one for each kind of wxWidgets
2793 // control or window.
2795 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2796 title
= ((wxButton
*) GetWindow())->GetLabel();
2799 title
= GetWindow()->GetName();
2807 return wxACC_NOT_IMPLEMENTED
;
2810 // Gets the number of children.
2811 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2813 wxASSERT( GetWindow() != NULL
);
2817 *childId
= (int) GetWindow()->GetChildren().GetCount();
2821 // Gets the specified child (starting from 1).
2822 // If *child is NULL and return value is wxACC_OK,
2823 // this means that the child is a simple element and
2824 // not an accessible object.
2825 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2827 wxASSERT( GetWindow() != NULL
);
2837 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2840 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2841 *child
= childWindow
->GetOrCreateAccessible();
2848 // Gets the parent, or NULL.
2849 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2851 wxASSERT( GetWindow() != NULL
);
2855 wxWindow
* parentWindow
= GetWindow()->GetParent();
2863 *parent
= parentWindow
->GetOrCreateAccessible();
2871 // Performs the default action. childId is 0 (the action for this object)
2872 // or > 0 (the action for a child).
2873 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2874 // window (e.g. an edit control).
2875 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2877 wxASSERT( GetWindow() != NULL
);
2881 return wxACC_NOT_IMPLEMENTED
;
2884 // Gets the default action for this object (0) or > 0 (the action for a child).
2885 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2886 // string if there is no action.
2887 // The retrieved string describes the action that is performed on an object,
2888 // not what the object does as a result. For example, a toolbar button that prints
2889 // a document has a default action of "Press" rather than "Prints the current document."
2890 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2892 wxASSERT( GetWindow() != NULL
);
2896 return wxACC_NOT_IMPLEMENTED
;
2899 // Returns the description for this object or a child.
2900 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2902 wxASSERT( GetWindow() != NULL
);
2906 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2912 return wxACC_NOT_IMPLEMENTED
;
2915 // Returns help text for this object or a child, similar to tooltip text.
2916 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2918 wxASSERT( GetWindow() != NULL
);
2922 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2928 return wxACC_NOT_IMPLEMENTED
;
2931 // Returns the keyboard shortcut for this object or child.
2932 // Return e.g. ALT+K
2933 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2935 wxASSERT( GetWindow() != NULL
);
2939 return wxACC_NOT_IMPLEMENTED
;
2942 // Returns a role constant.
2943 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2945 wxASSERT( GetWindow() != NULL
);
2949 // If a child, leave wxWidgets to call the function on the actual
2952 return wxACC_NOT_IMPLEMENTED
;
2954 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2955 return wxACC_NOT_IMPLEMENTED
;
2957 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2958 return wxACC_NOT_IMPLEMENTED
;
2961 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2962 return wxACC_NOT_IMPLEMENTED
;
2965 //*role = wxROLE_SYSTEM_CLIENT;
2966 *role
= wxROLE_SYSTEM_CLIENT
;
2970 return wxACC_NOT_IMPLEMENTED
;
2974 // Returns a state constant.
2975 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2977 wxASSERT( GetWindow() != NULL
);
2981 // If a child, leave wxWidgets to call the function on the actual
2984 return wxACC_NOT_IMPLEMENTED
;
2986 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2987 return wxACC_NOT_IMPLEMENTED
;
2990 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2991 return wxACC_NOT_IMPLEMENTED
;
2994 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2995 return wxACC_NOT_IMPLEMENTED
;
3002 return wxACC_NOT_IMPLEMENTED
;
3006 // Returns a localized string representing the value for the object
3008 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3010 wxASSERT( GetWindow() != NULL
);
3014 return wxACC_NOT_IMPLEMENTED
;
3017 // Selects the object or child.
3018 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3020 wxASSERT( GetWindow() != NULL
);
3024 return wxACC_NOT_IMPLEMENTED
;
3027 // Gets the window with the keyboard focus.
3028 // If childId is 0 and child is NULL, no object in
3029 // this subhierarchy has the focus.
3030 // If this object has the focus, child should be 'this'.
3031 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3033 wxASSERT( GetWindow() != NULL
);
3037 return wxACC_NOT_IMPLEMENTED
;
3041 // Gets a variant representing the selected children
3043 // Acceptable values:
3044 // - a null variant (IsNull() returns true)
3045 // - a list variant (GetType() == wxT("list")
3046 // - an integer representing the selected child element,
3047 // or 0 if this object is selected (GetType() == wxT("long")
3048 // - a "void*" pointer to a wxAccessible child object
3049 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3051 wxASSERT( GetWindow() != NULL
);
3055 return wxACC_NOT_IMPLEMENTED
;
3057 #endif // wxUSE_VARIANT
3059 #endif // wxUSE_ACCESSIBILITY
3061 // ----------------------------------------------------------------------------
3063 // ----------------------------------------------------------------------------
3066 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3068 wxCoord widthTotal
) const
3070 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3072 x
= widthTotal
- x
- width
;