1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWindows 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"
51 #include "wx/layout.h"
52 #endif // wxUSE_CONSTRAINTS
56 #if wxUSE_DRAG_AND_DROP
58 #endif // wxUSE_DRAG_AND_DROP
60 #if wxUSE_ACCESSIBILITY
61 #include "wx/access.h"
65 #include "wx/cshelp.h"
69 #include "wx/tooltip.h"
70 #endif // wxUSE_TOOLTIPS
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
81 int wxWindowBase::ms_lastControlId
= 2000;
83 int wxWindowBase::ms_lastControlId
= -200;
86 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
93 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
94 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
95 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
98 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
103 // ============================================================================
104 // implementation of the common functionality of the wxWindow class
105 // ============================================================================
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 // the default initialization
112 wxWindowBase::wxWindowBase()
114 // no window yet, no parent nor children
115 m_parent
= (wxWindow
*)NULL
;
116 m_windowId
= wxID_ANY
;
118 // no constraints on the minimal window size
124 // window are created enabled and visible by default
128 // the default event handler is just this window
129 m_eventHandler
= this;
133 m_windowValidator
= (wxValidator
*) NULL
;
134 #endif // wxUSE_VALIDATORS
136 // the colours/fonts are default for now, so leave m_font,
137 // m_backgroundColour and m_foregroundColour uninitialized and set those
146 #if wxUSE_CONSTRAINTS
147 // no constraints whatsoever
148 m_constraints
= (wxLayoutConstraints
*) NULL
;
149 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
150 #endif // wxUSE_CONSTRAINTS
152 m_windowSizer
= (wxSizer
*) NULL
;
153 m_containingSizer
= (wxSizer
*) NULL
;
154 m_autoLayout
= false;
156 #if wxUSE_DRAG_AND_DROP
157 m_dropTarget
= (wxDropTarget
*)NULL
;
158 #endif // wxUSE_DRAG_AND_DROP
161 m_tooltip
= (wxToolTip
*)NULL
;
162 #endif // wxUSE_TOOLTIPS
165 m_caret
= (wxCaret
*)NULL
;
166 #endif // wxUSE_CARET
169 m_hasCustomPalette
= false;
170 #endif // wxUSE_PALETTE
172 #if wxUSE_ACCESSIBILITY
176 m_virtualSize
= wxDefaultSize
;
181 m_maxVirtualHeight
= -1;
183 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
185 // Whether we're using the current theme for this window (wxGTK only for now)
186 m_themeEnabled
= false;
188 // VZ: this one shouldn't exist...
189 m_isBeingDeleted
= false;
192 // common part of window creation process
193 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
195 const wxPoint
& WXUNUSED(pos
),
198 const wxValidator
& wxVALIDATOR_PARAM(validator
),
199 const wxString
& name
)
202 // wxGTK doesn't allow to create controls with static box as the parent so
203 // this will result in a crash when the program is ported to wxGTK so warn
206 // if you get this assert, the correct solution is to create the controls
207 // as siblings of the static box
208 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
209 _T("wxStaticBox can't be used as a window parent!") );
210 #endif // wxUSE_STATBOX
212 // ids are limited to 16 bits under MSW so if you care about portability,
213 // it's not a good idea to use ids out of this range (and negative ids are
214 // reserved for wxWindows own usage)
215 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
216 _T("invalid id value") );
218 // generate a new id if the user doesn't care about it
219 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
222 SetWindowStyleFlag(style
);
225 // Set the minsize to be the size passed to the ctor (if any) for
226 // non-TLWs. This is so items used in a sizer will use this explicitly
227 // set size for layout, instead of falling back the (probably smaller)
234 SetValidator(validator
);
235 #endif // wxUSE_VALIDATORS
237 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
238 // have it too - like this it's possible to set it only in the top level
239 // dialog/frame and all children will inherit it by defult
240 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
242 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
248 // ----------------------------------------------------------------------------
250 // ----------------------------------------------------------------------------
253 wxWindowBase::~wxWindowBase()
255 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
257 // FIXME if these 2 cases result from programming errors in the user code
258 // we should probably assert here instead of silently fixing them
260 // Just in case the window has been Closed, but we're then deleting
261 // immediately: don't leave dangling pointers.
262 wxPendingDelete
.DeleteObject(this);
264 // Just in case we've loaded a top-level window via LoadNativeDialog but
265 // we weren't a dialog class
266 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
268 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
270 // reset the dangling pointer our parent window may keep to us
273 if ( m_parent
->GetDefaultItem() == this )
275 m_parent
->SetDefaultItem(NULL
);
278 m_parent
->RemoveChild(this);
283 #endif // wxUSE_CARET
286 delete m_windowValidator
;
287 #endif // wxUSE_VALIDATORS
289 #if wxUSE_CONSTRAINTS
290 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
291 // at deleted windows as they delete themselves.
292 DeleteRelatedConstraints();
296 // This removes any dangling pointers to this window in other windows'
297 // constraintsInvolvedIn lists.
298 UnsetConstraints(m_constraints
);
299 delete m_constraints
;
300 m_constraints
= NULL
;
302 #endif // wxUSE_CONSTRAINTS
304 if ( m_containingSizer
)
305 m_containingSizer
->Detach( (wxWindow
*)this );
307 delete m_windowSizer
;
309 #if wxUSE_DRAG_AND_DROP
311 #endif // wxUSE_DRAG_AND_DROP
315 #endif // wxUSE_TOOLTIPS
317 #if wxUSE_ACCESSIBILITY
322 bool wxWindowBase::Destroy()
329 bool wxWindowBase::Close(bool force
)
331 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
332 event
.SetEventObject(this);
333 event
.SetCanVeto(!force
);
335 // return false if window wasn't closed because the application vetoed the
337 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
340 bool wxWindowBase::DestroyChildren()
342 wxWindowList::compatibility_iterator node
;
345 // we iterate until the list becomes empty
346 node
= GetChildren().GetFirst();
350 wxWindow
*child
= node
->GetData();
352 // note that we really want to call delete and not ->Destroy() here
353 // because we want to delete the child immediately, before we are
354 // deleted, and delayed deletion would result in problems as our (top
355 // level) child could outlive its parent
358 wxASSERT_MSG( !GetChildren().Find(child
),
359 wxT("child didn't remove itself using RemoveChild()") );
365 // ----------------------------------------------------------------------------
366 // size/position related methods
367 // ----------------------------------------------------------------------------
369 // centre the window with respect to its parent in either (or both) directions
370 void wxWindowBase::Centre(int direction
)
372 // the position/size of the parent window or of the entire screen
374 int widthParent
, heightParent
;
376 wxWindow
*parent
= NULL
;
378 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
380 // find the parent to centre this window on: it should be the
381 // immediate parent for the controls but the top level parent for the
382 // top level windows (like dialogs)
383 parent
= GetParent();
386 while ( parent
&& !parent
->IsTopLevel() )
388 parent
= parent
->GetParent();
392 // there is no wxTopLevelWindow under wxMotif yet
394 // we shouldn't center the dialog on the iconized window: under
395 // Windows, for example, this places it completely off the screen
398 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
399 if ( winTop
&& winTop
->IsIconized() )
404 #endif // __WXMOTIF__
406 // did we find the parent?
410 direction
|= wxCENTRE_ON_SCREEN
;
414 if ( direction
& wxCENTRE_ON_SCREEN
)
416 // centre with respect to the whole screen
417 wxDisplaySize(&widthParent
, &heightParent
);
423 // centre on the parent
424 parent
->GetSize(&widthParent
, &heightParent
);
426 // adjust to the parents position
427 posParent
= parent
->GetPosition();
431 // centre inside the parents client rectangle
432 parent
->GetClientSize(&widthParent
, &heightParent
);
437 GetSize(&width
, &height
);
442 if ( direction
& wxHORIZONTAL
)
443 xNew
= (widthParent
- width
)/2;
445 if ( direction
& wxVERTICAL
)
446 yNew
= (heightParent
- height
)/2;
451 // Base size of the visible dimensions of the display
452 // to take into account the taskbar
453 wxRect rect
= wxGetClientDisplayRect();
454 wxSize
size (rect
.width
,rect
.height
);
456 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
457 // but it may mean that the window is placed on other than the main
458 // display. Therefore we only make sure centered window is on the main display
459 // if the parent is at least partially present here.
460 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
464 else if (xNew
+width
> size
.x
)
465 xNew
= size
.x
-width
-1;
467 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
469 if (yNew
+height
> size
.y
)
470 yNew
= size
.y
-height
-1;
472 // Make certain that the title bar is initially visible
473 // always, even if this would push the bottom of the
474 // dialog of the visible area of the display
479 // move the window to this position (keeping the old size but using
480 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
481 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
484 // fits the window around the children
485 void wxWindowBase::Fit()
487 if ( GetChildren().GetCount() > 0 )
489 SetClientSize(DoGetBestSize());
491 //else: do nothing if we have no children
494 // fits virtual size (ie. scrolled area etc.) around children
495 void wxWindowBase::FitInside()
497 if ( GetChildren().GetCount() > 0 )
499 SetVirtualSize( GetBestVirtualSize() );
503 // return the size best suited for the current window
504 wxSize
wxWindowBase::DoGetBestSize() const
508 return m_windowSizer
->GetMinSize();
510 #if wxUSE_CONSTRAINTS
511 else if ( m_constraints
)
513 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
515 // our minimal acceptable size is such that all our windows fit inside
519 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
521 node
= node
->GetNext() )
523 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
526 // it's not normal that we have an unconstrained child, but
527 // what can we do about it?
531 int x
= c
->right
.GetValue(),
532 y
= c
->bottom
.GetValue();
540 // TODO: we must calculate the overlaps somehow, otherwise we
541 // will never return a size bigger than the current one :-(
544 return wxSize(maxX
, maxY
);
546 #endif // wxUSE_CONSTRAINTS
547 else if ( !GetChildren().empty() )
549 // our minimal acceptable size is such that all our windows fit inside
553 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
555 node
= node
->GetNext() )
557 wxWindow
*win
= node
->GetData();
558 if ( win
->IsTopLevel()
560 || wxDynamicCast(win
, wxStatusBar
)
561 #endif // wxUSE_STATUSBAR
564 // dialogs and frames lie in different top level windows -
565 // don't deal with them here; as for the status bars, they
566 // don't lie in the client area at all
571 win
->GetPosition(&wx
, &wy
);
573 // if the window hadn't been positioned yet, assume that it is in
580 win
->GetSize(&ww
, &wh
);
581 if ( wx
+ ww
> maxX
)
583 if ( wy
+ wh
> maxY
)
587 // for compatibility with the old versions and because it really looks
588 // slightly more pretty like this, add a pad
592 return wxSize(maxX
, maxY
);
596 // for a generic window there is no natural best size - just use the
602 // by default the origin is not shifted
603 wxPoint
wxWindowBase::GetClientAreaOrigin() const
605 return wxPoint(0, 0);
608 // set the min/max size of the window
609 void wxWindowBase::SetSizeHints(int minW
, int minH
,
611 int WXUNUSED(incW
), int WXUNUSED(incH
))
613 // setting min width greater than max width leads to infinite loops under
614 // X11 and generally doesn't make any sense, so don't allow it
615 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
616 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
617 _T("min width/height must be less than max width/height!") );
625 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
627 if ( m_windowVariant
!= variant
)
629 m_windowVariant
= variant
;
631 DoSetWindowVariant(variant
);
635 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
637 // adjust the font height to correspond to our new variant (notice that
638 // we're only called if something really changed)
639 wxFont font
= GetFont();
640 int size
= font
.GetPointSize();
643 case wxWINDOW_VARIANT_NORMAL
:
646 case wxWINDOW_VARIANT_SMALL
:
651 case wxWINDOW_VARIANT_MINI
:
656 case wxWINDOW_VARIANT_LARGE
:
662 wxFAIL_MSG(_T("unexpected window variant"));
666 font
.SetPointSize(size
);
670 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
673 m_minVirtualWidth
= minW
;
674 m_maxVirtualWidth
= maxW
;
675 m_minVirtualHeight
= minH
;
676 m_maxVirtualHeight
= maxH
;
679 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
681 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
682 x
= m_minVirtualWidth
;
683 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
684 x
= m_maxVirtualWidth
;
685 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
686 y
= m_minVirtualHeight
;
687 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
688 y
= m_maxVirtualHeight
;
690 m_virtualSize
= wxSize(x
, y
);
693 wxSize
wxWindowBase::DoGetVirtualSize() const
695 wxSize
s( GetClientSize() );
697 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
698 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
701 // ----------------------------------------------------------------------------
702 // show/hide/enable/disable the window
703 // ----------------------------------------------------------------------------
705 bool wxWindowBase::Show(bool show
)
707 if ( show
!= m_isShown
)
719 bool wxWindowBase::Enable(bool enable
)
721 if ( enable
!= m_isEnabled
)
723 m_isEnabled
= enable
;
732 // ----------------------------------------------------------------------------
734 // ----------------------------------------------------------------------------
736 bool wxWindowBase::IsTopLevel() const
741 // ----------------------------------------------------------------------------
742 // reparenting the window
743 // ----------------------------------------------------------------------------
745 void wxWindowBase::AddChild(wxWindowBase
*child
)
747 wxCHECK_RET( child
, wxT("can't add a NULL child") );
749 // this should never happen and it will lead to a crash later if it does
750 // because RemoveChild() will remove only one node from the children list
751 // and the other(s) one(s) will be left with dangling pointers in them
752 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
754 GetChildren().Append((wxWindow
*)child
);
755 child
->SetParent(this);
758 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
760 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
762 GetChildren().DeleteObject((wxWindow
*)child
);
763 child
->SetParent(NULL
);
766 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
768 wxWindow
*oldParent
= GetParent();
769 if ( newParent
== oldParent
)
775 // unlink this window from the existing parent.
778 oldParent
->RemoveChild(this);
782 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
785 // add it to the new one
788 newParent
->AddChild(this);
792 wxTopLevelWindows
.Append((wxWindow
*)this);
798 // ----------------------------------------------------------------------------
799 // event handler stuff
800 // ----------------------------------------------------------------------------
802 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
804 wxEvtHandler
*handlerOld
= GetEventHandler();
806 handler
->SetNextHandler(handlerOld
);
809 GetEventHandler()->SetPreviousHandler(handler
);
811 SetEventHandler(handler
);
814 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
816 wxEvtHandler
*handlerA
= GetEventHandler();
819 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
820 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
823 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
824 SetEventHandler(handlerB
);
829 handlerA
= (wxEvtHandler
*)NULL
;
836 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
838 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
840 wxEvtHandler
*handlerPrev
= NULL
,
841 *handlerCur
= GetEventHandler();
844 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
846 if ( handlerCur
== handler
)
850 handlerPrev
->SetNextHandler(handlerNext
);
854 SetEventHandler(handlerNext
);
859 handlerNext
->SetPreviousHandler ( handlerPrev
);
862 handler
->SetNextHandler(NULL
);
863 handler
->SetPreviousHandler(NULL
);
868 handlerPrev
= handlerCur
;
869 handlerCur
= handlerNext
;
872 wxFAIL_MSG( _T("where has the event handler gone?") );
877 // ----------------------------------------------------------------------------
879 // ----------------------------------------------------------------------------
881 void wxWindowBase::InheritAttributes()
883 const wxWindowBase
* const parent
= GetParent();
887 // we only inherit attributes which had been explicitly set for the parent
888 // which ensures that this only happens if the user really wants it and
889 // not by default which wouldn't make any sense in modern GUIs where the
890 // controls don't all use the same fonts (nor colours)
891 if ( parent
->m_hasFont
&& !m_hasFont
)
892 SetFont(parent
->GetFont());
894 // in addition, there is a possibility to explicitly forbid inheriting
895 // colours at each class level by overriding ShouldInheritColours()
896 if ( ShouldInheritColours() )
898 if ( parent
->m_hasFgCol
&& !m_hasFgCol
)
899 SetForegroundColour(parent
->GetForegroundColour());
901 if ( parent
->m_hasBgCol
&& !m_hasBgCol
)
902 SetBackgroundColour(parent
->GetBackgroundColour());
906 /* static */ wxVisualAttributes
907 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
909 // it is important to return valid values for all attributes from here,
910 // GetXXX() below rely on this
911 wxVisualAttributes attrs
;
912 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
913 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
914 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
919 wxColour
wxWindowBase::GetBackgroundColour() const
921 if ( !m_backgroundColour
.Ok() )
923 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
925 // get our default background colour
926 wxColour colBg
= GetDefaultAttributes().colBg
;
928 // we must return some valid colour to avoid redoing this every time
929 // and also to avoid surprizing the applications written for older
930 // wxWindows versions where GetBackgroundColour() always returned
931 // something -- so give them something even if it doesn't make sense
932 // for this window (e.g. it has a themed background)
934 colBg
= GetClassDefaultAttributes().colBg
;
936 // cache it for the next call
937 wxConstCast(this, wxWindowBase
)->m_backgroundColour
= colBg
;
940 return m_backgroundColour
;
943 wxColour
wxWindowBase::GetForegroundColour() const
945 // logic is the same as above
946 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
948 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
950 wxColour colFg
= GetDefaultAttributes().colFg
;
953 colFg
= GetClassDefaultAttributes().colFg
;
955 wxConstCast(this, wxWindowBase
)->m_foregroundColour
= colFg
;
958 return m_foregroundColour
;
961 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
963 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
966 m_backgroundColour
= colour
;
973 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
975 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
978 m_foregroundColour
= colour
;
985 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
987 // setting an invalid cursor is ok, it means that we don't have any special
989 if ( m_cursor
== cursor
)
1000 wxFont
& wxWindowBase::DoGetFont() const
1002 // logic is the same as in GetBackgroundColour()
1005 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1007 wxFont font
= GetDefaultAttributes().font
;
1009 font
= GetClassDefaultAttributes().font
;
1011 wxConstCast(this, wxWindowBase
)->m_font
= font
;
1014 // cast is here for non-const GetFont() convenience
1015 return wxConstCast(this, wxWindowBase
)->m_font
;
1018 bool wxWindowBase::SetFont(const wxFont
& font
)
1023 if ( font
== m_font
)
1038 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1040 m_hasCustomPalette
= true;
1043 // VZ: can anyone explain me what do we do here?
1044 wxWindowDC
d((wxWindow
*) this);
1048 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1050 wxWindow
*win
= (wxWindow
*)this;
1051 while ( win
&& !win
->HasCustomPalette() )
1053 win
= win
->GetParent();
1059 #endif // wxUSE_PALETTE
1062 void wxWindowBase::SetCaret(wxCaret
*caret
)
1073 wxASSERT_MSG( m_caret
->GetWindow() == this,
1074 wxT("caret should be created associated to this window") );
1077 #endif // wxUSE_CARET
1079 #if wxUSE_VALIDATORS
1080 // ----------------------------------------------------------------------------
1082 // ----------------------------------------------------------------------------
1084 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1086 if ( m_windowValidator
)
1087 delete m_windowValidator
;
1089 m_windowValidator
= (wxValidator
*)validator
.Clone();
1091 if ( m_windowValidator
)
1092 m_windowValidator
->SetWindow(this);
1094 #endif // wxUSE_VALIDATORS
1096 // ----------------------------------------------------------------------------
1097 // update region stuff
1098 // ----------------------------------------------------------------------------
1100 wxRect
wxWindowBase::GetUpdateClientRect() const
1102 wxRegion rgnUpdate
= GetUpdateRegion();
1103 rgnUpdate
.Intersect(GetClientRect());
1104 wxRect rectUpdate
= rgnUpdate
.GetBox();
1105 wxPoint ptOrigin
= GetClientAreaOrigin();
1106 rectUpdate
.x
-= ptOrigin
.x
;
1107 rectUpdate
.y
-= ptOrigin
.y
;
1112 bool wxWindowBase::IsExposed(int x
, int y
) const
1114 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1117 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1119 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1122 void wxWindowBase::ClearBackground()
1124 // wxGTK uses its own version, no need to add never used code
1126 wxClientDC
dc((wxWindow
*)this);
1127 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1128 dc
.SetBackground(brush
);
1133 // ----------------------------------------------------------------------------
1134 // find child window by id or name
1135 // ----------------------------------------------------------------------------
1137 wxWindow
*wxWindowBase::FindWindow( long id
)
1139 if ( id
== m_windowId
)
1140 return (wxWindow
*)this;
1142 wxWindowBase
*res
= (wxWindow
*)NULL
;
1143 wxWindowList::compatibility_iterator node
;
1144 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1146 wxWindowBase
*child
= node
->GetData();
1147 res
= child
->FindWindow( id
);
1150 return (wxWindow
*)res
;
1153 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1155 if ( name
== m_windowName
)
1156 return (wxWindow
*)this;
1158 wxWindowBase
*res
= (wxWindow
*)NULL
;
1159 wxWindowList::compatibility_iterator node
;
1160 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1162 wxWindow
*child
= node
->GetData();
1163 res
= child
->FindWindow(name
);
1166 return (wxWindow
*)res
;
1170 // find any window by id or name or label: If parent is non-NULL, look through
1171 // children for a label or title matching the specified string. If NULL, look
1172 // through all top-level windows.
1174 // to avoid duplicating code we reuse the same helper function but with
1175 // different comparators
1177 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1178 const wxString
& label
, long id
);
1181 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1184 return win
->GetLabel() == label
;
1188 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1191 return win
->GetName() == label
;
1195 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1198 return win
->GetId() == id
;
1201 // recursive helper for the FindWindowByXXX() functions
1203 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1204 const wxString
& label
,
1206 wxFindWindowCmp cmp
)
1210 // see if this is the one we're looking for
1211 if ( (*cmp
)(parent
, label
, id
) )
1212 return (wxWindow
*)parent
;
1214 // It wasn't, so check all its children
1215 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1217 node
= node
->GetNext() )
1219 // recursively check each child
1220 wxWindow
*win
= (wxWindow
*)node
->GetData();
1221 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1231 // helper for FindWindowByXXX()
1233 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1234 const wxString
& label
,
1236 wxFindWindowCmp cmp
)
1240 // just check parent and all its children
1241 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1244 // start at very top of wx's windows
1245 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1247 node
= node
->GetNext() )
1249 // recursively check each window & its children
1250 wxWindow
*win
= node
->GetData();
1251 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1261 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1263 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1268 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1270 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1274 // fall back to the label
1275 win
= FindWindowByLabel(title
, parent
);
1283 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1285 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1288 // ----------------------------------------------------------------------------
1289 // dialog oriented functions
1290 // ----------------------------------------------------------------------------
1292 void wxWindowBase::MakeModal(bool modal
)
1294 // Disable all other windows
1297 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1300 wxWindow
*win
= node
->GetData();
1302 win
->Enable(!modal
);
1304 node
= node
->GetNext();
1309 bool wxWindowBase::Validate()
1311 #if wxUSE_VALIDATORS
1312 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1314 wxWindowList::compatibility_iterator node
;
1315 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1317 wxWindowBase
*child
= node
->GetData();
1318 wxValidator
*validator
= child
->GetValidator();
1319 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1324 if ( recurse
&& !child
->Validate() )
1329 #endif // wxUSE_VALIDATORS
1334 bool wxWindowBase::TransferDataToWindow()
1336 #if wxUSE_VALIDATORS
1337 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1339 wxWindowList::compatibility_iterator node
;
1340 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1342 wxWindowBase
*child
= node
->GetData();
1343 wxValidator
*validator
= child
->GetValidator();
1344 if ( validator
&& !validator
->TransferToWindow() )
1346 wxLogWarning(_("Could not transfer data to window"));
1348 wxLog::FlushActive();
1356 if ( !child
->TransferDataToWindow() )
1358 // warning already given
1363 #endif // wxUSE_VALIDATORS
1368 bool wxWindowBase::TransferDataFromWindow()
1370 #if wxUSE_VALIDATORS
1371 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1373 wxWindowList::compatibility_iterator node
;
1374 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1376 wxWindow
*child
= node
->GetData();
1377 wxValidator
*validator
= child
->GetValidator();
1378 if ( validator
&& !validator
->TransferFromWindow() )
1380 // nop warning here because the application is supposed to give
1381 // one itself - we don't know here what might have gone wrongly
1388 if ( !child
->TransferDataFromWindow() )
1390 // warning already given
1395 #endif // wxUSE_VALIDATORS
1400 void wxWindowBase::InitDialog()
1402 wxInitDialogEvent
event(GetId());
1403 event
.SetEventObject( this );
1404 GetEventHandler()->ProcessEvent(event
);
1407 // ----------------------------------------------------------------------------
1408 // context-sensitive help support
1409 // ----------------------------------------------------------------------------
1413 // associate this help text with this window
1414 void wxWindowBase::SetHelpText(const wxString
& text
)
1416 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1419 helpProvider
->AddHelp(this, text
);
1423 // associate this help text with all windows with the same id as this
1425 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1427 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1430 helpProvider
->AddHelp(GetId(), text
);
1434 // get the help string associated with this window (may be empty)
1435 wxString
wxWindowBase::GetHelpText() const
1438 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1441 text
= helpProvider
->GetHelp(this);
1447 // show help for this window
1448 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1450 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1453 if ( helpProvider
->ShowHelp(this) )
1455 // skip the event.Skip() below
1463 #endif // wxUSE_HELP
1465 // ----------------------------------------------------------------------------
1466 // tooltipsroot.Replace("\\", "/");
1467 // ----------------------------------------------------------------------------
1471 void wxWindowBase::SetToolTip( const wxString
&tip
)
1473 // don't create the new tooltip if we already have one
1476 m_tooltip
->SetTip( tip
);
1480 SetToolTip( new wxToolTip( tip
) );
1483 // setting empty tooltip text does not remove the tooltip any more - use
1484 // SetToolTip((wxToolTip *)NULL) for this
1487 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1492 m_tooltip
= tooltip
;
1495 #endif // wxUSE_TOOLTIPS
1497 // ----------------------------------------------------------------------------
1498 // constraints and sizers
1499 // ----------------------------------------------------------------------------
1501 #if wxUSE_CONSTRAINTS
1503 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1505 if ( m_constraints
)
1507 UnsetConstraints(m_constraints
);
1508 delete m_constraints
;
1510 m_constraints
= constraints
;
1511 if ( m_constraints
)
1513 // Make sure other windows know they're part of a 'meaningful relationship'
1514 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1515 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1516 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1517 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1518 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1519 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1520 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1521 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1522 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1523 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1524 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1525 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1526 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1527 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1528 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1529 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1533 // This removes any dangling pointers to this window in other windows'
1534 // constraintsInvolvedIn lists.
1535 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1539 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1540 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1541 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1542 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1543 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1544 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1545 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1546 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1547 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1548 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1549 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1550 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1551 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1552 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1553 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1554 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1558 // Back-pointer to other windows we're involved with, so if we delete this
1559 // window, we must delete any constraints we're involved with.
1560 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1562 if ( !m_constraintsInvolvedIn
)
1563 m_constraintsInvolvedIn
= new wxWindowList
;
1564 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1565 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1568 // REMOVE back-pointer to other windows we're involved with.
1569 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1571 if ( m_constraintsInvolvedIn
)
1572 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1575 // Reset any constraints that mention this window
1576 void wxWindowBase::DeleteRelatedConstraints()
1578 if ( m_constraintsInvolvedIn
)
1580 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1583 wxWindow
*win
= node
->GetData();
1584 wxLayoutConstraints
*constr
= win
->GetConstraints();
1586 // Reset any constraints involving this window
1589 constr
->left
.ResetIfWin(this);
1590 constr
->top
.ResetIfWin(this);
1591 constr
->right
.ResetIfWin(this);
1592 constr
->bottom
.ResetIfWin(this);
1593 constr
->width
.ResetIfWin(this);
1594 constr
->height
.ResetIfWin(this);
1595 constr
->centreX
.ResetIfWin(this);
1596 constr
->centreY
.ResetIfWin(this);
1599 wxWindowList::compatibility_iterator next
= node
->GetNext();
1600 m_constraintsInvolvedIn
->Erase(node
);
1604 delete m_constraintsInvolvedIn
;
1605 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1609 #endif // wxUSE_CONSTRAINTS
1611 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1613 if ( sizer
== m_windowSizer
)
1617 delete m_windowSizer
;
1619 m_windowSizer
= sizer
;
1621 SetAutoLayout( sizer
!= NULL
);
1624 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1626 SetSizer( sizer
, deleteOld
);
1627 sizer
->SetSizeHints( (wxWindow
*) this );
1630 #if wxUSE_CONSTRAINTS
1632 void wxWindowBase::SatisfyConstraints()
1634 wxLayoutConstraints
*constr
= GetConstraints();
1635 bool wasOk
= constr
&& constr
->AreSatisfied();
1637 ResetConstraints(); // Mark all constraints as unevaluated
1641 // if we're a top level panel (i.e. our parent is frame/dialog), our
1642 // own constraints will never be satisfied any more unless we do it
1646 while ( noChanges
> 0 )
1648 LayoutPhase1(&noChanges
);
1652 LayoutPhase2(&noChanges
);
1655 #endif // wxUSE_CONSTRAINTS
1657 bool wxWindowBase::Layout()
1659 // If there is a sizer, use it instead of the constraints
1663 GetVirtualSize(&w
, &h
);
1664 GetSizer()->SetDimension( 0, 0, w
, h
);
1666 #if wxUSE_CONSTRAINTS
1669 SatisfyConstraints(); // Find the right constraints values
1670 SetConstraintSizes(); // Recursively set the real window sizes
1677 #if wxUSE_CONSTRAINTS
1679 // first phase of the constraints evaluation: set our own constraints
1680 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1682 wxLayoutConstraints
*constr
= GetConstraints();
1684 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1687 // second phase: set the constraints for our children
1688 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1695 // Layout grand children
1701 // Do a phase of evaluating child constraints
1702 bool wxWindowBase::DoPhase(int phase
)
1704 // the list containing the children for which the constraints are already
1706 wxWindowList succeeded
;
1708 // the max number of iterations we loop before concluding that we can't set
1710 static const int maxIterations
= 500;
1712 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1716 // loop over all children setting their constraints
1717 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1719 node
= node
->GetNext() )
1721 wxWindow
*child
= node
->GetData();
1722 if ( child
->IsTopLevel() )
1724 // top level children are not inside our client area
1728 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1730 // this one is either already ok or nothing we can do about it
1734 int tempNoChanges
= 0;
1735 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1736 : child
->LayoutPhase2(&tempNoChanges
);
1737 noChanges
+= tempNoChanges
;
1741 succeeded
.Append(child
);
1747 // constraints are set
1755 void wxWindowBase::ResetConstraints()
1757 wxLayoutConstraints
*constr
= GetConstraints();
1760 constr
->left
.SetDone(false);
1761 constr
->top
.SetDone(false);
1762 constr
->right
.SetDone(false);
1763 constr
->bottom
.SetDone(false);
1764 constr
->width
.SetDone(false);
1765 constr
->height
.SetDone(false);
1766 constr
->centreX
.SetDone(false);
1767 constr
->centreY
.SetDone(false);
1770 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1773 wxWindow
*win
= node
->GetData();
1774 if ( !win
->IsTopLevel() )
1775 win
->ResetConstraints();
1776 node
= node
->GetNext();
1780 // Need to distinguish between setting the 'fake' size for windows and sizers,
1781 // and setting the real values.
1782 void wxWindowBase::SetConstraintSizes(bool recurse
)
1784 wxLayoutConstraints
*constr
= GetConstraints();
1785 if ( constr
&& constr
->AreSatisfied() )
1787 int x
= constr
->left
.GetValue();
1788 int y
= constr
->top
.GetValue();
1789 int w
= constr
->width
.GetValue();
1790 int h
= constr
->height
.GetValue();
1792 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1793 (constr
->height
.GetRelationship() != wxAsIs
) )
1795 SetSize(x
, y
, w
, h
);
1799 // If we don't want to resize this window, just move it...
1805 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1806 GetClassInfo()->GetClassName(),
1812 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1815 wxWindow
*win
= node
->GetData();
1816 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1817 win
->SetConstraintSizes();
1818 node
= node
->GetNext();
1823 // Only set the size/position of the constraint (if any)
1824 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1826 wxLayoutConstraints
*constr
= GetConstraints();
1831 constr
->left
.SetValue(x
);
1832 constr
->left
.SetDone(true);
1836 constr
->top
.SetValue(y
);
1837 constr
->top
.SetDone(true);
1841 constr
->width
.SetValue(w
);
1842 constr
->width
.SetDone(true);
1846 constr
->height
.SetValue(h
);
1847 constr
->height
.SetDone(true);
1852 void wxWindowBase::MoveConstraint(int x
, int y
)
1854 wxLayoutConstraints
*constr
= GetConstraints();
1859 constr
->left
.SetValue(x
);
1860 constr
->left
.SetDone(true);
1864 constr
->top
.SetValue(y
);
1865 constr
->top
.SetDone(true);
1870 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1872 wxLayoutConstraints
*constr
= GetConstraints();
1875 *w
= constr
->width
.GetValue();
1876 *h
= constr
->height
.GetValue();
1882 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1884 wxLayoutConstraints
*constr
= GetConstraints();
1887 *w
= constr
->width
.GetValue();
1888 *h
= constr
->height
.GetValue();
1891 GetClientSize(w
, h
);
1894 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1896 wxLayoutConstraints
*constr
= GetConstraints();
1899 *x
= constr
->left
.GetValue();
1900 *y
= constr
->top
.GetValue();
1906 #endif // wxUSE_CONSTRAINTS
1908 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1910 // don't do it for the dialogs/frames - they float independently of their
1912 if ( !IsTopLevel() )
1914 wxWindow
*parent
= GetParent();
1915 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1917 wxPoint
pt(parent
->GetClientAreaOrigin());
1924 // ----------------------------------------------------------------------------
1925 // do Update UI processing for child controls
1926 // ----------------------------------------------------------------------------
1928 void wxWindowBase::UpdateWindowUI(long flags
)
1930 wxUpdateUIEvent
event(GetId());
1931 event
.m_eventObject
= this;
1933 if ( GetEventHandler()->ProcessEvent(event
) )
1935 DoUpdateWindowUI(event
);
1938 if (flags
& wxUPDATE_UI_RECURSE
)
1940 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1943 wxWindow
* child
= (wxWindow
*) node
->GetData();
1944 child
->UpdateWindowUI(flags
);
1945 node
= node
->GetNext();
1950 // do the window-specific processing after processing the update event
1951 // TODO: take specific knowledge out of this function and
1952 // put in each control's base class. Unfortunately we don't
1953 // yet have base implementation files for wxCheckBox and wxRadioButton.
1954 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1956 if ( event
.GetSetEnabled() )
1957 Enable(event
.GetEnabled());
1960 if ( event
.GetSetText() )
1962 wxControl
*control
= wxDynamicCastThis(wxControl
);
1965 if ( event
.GetText() != control
->GetLabel() )
1966 control
->SetLabel(event
.GetText());
1969 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1972 if ( event
.GetSetChecked() )
1973 checkbox
->SetValue(event
.GetChecked());
1975 #endif // wxUSE_CHECKBOX
1978 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1981 if ( event
.GetSetChecked() )
1982 radiobtn
->SetValue(event
.GetChecked());
1984 #endif // wxUSE_RADIOBTN
1990 // call internal idle recursively
1991 // may be obsolete (wait until OnIdle scheme stabilises)
1992 void wxWindowBase::ProcessInternalIdle()
1996 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1999 wxWindow
*child
= node
->GetData();
2000 child
->ProcessInternalIdle();
2001 node
= node
->GetNext();
2006 // ----------------------------------------------------------------------------
2007 // dialog units translations
2008 // ----------------------------------------------------------------------------
2010 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2012 int charWidth
= GetCharWidth();
2013 int charHeight
= GetCharHeight();
2014 wxPoint
pt2(-1, -1);
2016 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2018 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2023 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2025 int charWidth
= GetCharWidth();
2026 int charHeight
= GetCharHeight();
2027 wxPoint
pt2(-1, -1);
2029 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2031 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2036 // ----------------------------------------------------------------------------
2038 // ----------------------------------------------------------------------------
2040 // propagate the colour change event to the subwindows
2041 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2043 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2046 // Only propagate to non-top-level windows
2047 wxWindow
*win
= node
->GetData();
2048 if ( !win
->IsTopLevel() )
2050 wxSysColourChangedEvent event2
;
2051 event
.m_eventObject
= win
;
2052 win
->GetEventHandler()->ProcessEvent(event2
);
2055 node
= node
->GetNext();
2059 // the default action is to populate dialog with data when it's created,
2060 // and nudge the UI into displaying itself correctly in case
2061 // we've turned the wxUpdateUIEvents frequency down low.
2062 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2064 TransferDataToWindow();
2066 // Update the UI at this point
2067 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2070 // process Ctrl-Alt-mclick
2071 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2074 if ( event
.ControlDown() && event
.AltDown() )
2076 // don't translate these strings
2079 #ifdef __WXUNIVERSAL__
2081 #endif // __WXUNIVERSAL__
2083 switch ( wxGetOsVersion() )
2085 case wxMOTIF_X
: port
+= _T("Motif"); break;
2087 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2088 case wxBEOS
: port
+= _T("BeOS"); break;
2092 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2098 case wxWIN386
: port
+= _T("MS Windows"); break;
2102 case wxMGL_OS2
: port
+= _T("MGL"); break;
2104 case wxOS2_PM
: port
+= _T("OS/2"); break;
2105 default: port
+= _T("unknown"); break;
2108 wxMessageBox(wxString::Format(
2110 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
2124 _T("wxWindows information"),
2125 wxICON_INFORMATION
| wxOK
,
2129 #endif // wxUSE_MSGDLG
2135 // ----------------------------------------------------------------------------
2137 // ----------------------------------------------------------------------------
2139 #if wxUSE_ACCESSIBILITY
2140 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2142 if (m_accessible
&& (accessible
!= m_accessible
))
2143 delete m_accessible
;
2144 m_accessible
= accessible
;
2146 m_accessible
->SetWindow((wxWindow
*) this);
2149 // Returns the accessible object, creating if necessary.
2150 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2153 m_accessible
= CreateAccessible();
2154 return m_accessible
;
2157 // Override to create a specific accessible object.
2158 wxAccessible
* wxWindowBase::CreateAccessible()
2160 return new wxWindowAccessible((wxWindow
*) this);
2166 // ----------------------------------------------------------------------------
2167 // list classes implementation
2168 // ----------------------------------------------------------------------------
2170 void wxWindowListNode::DeleteData()
2172 delete (wxWindow
*)GetData();
2176 // ----------------------------------------------------------------------------
2178 // ----------------------------------------------------------------------------
2180 wxBorder
wxWindowBase::GetBorder(long flags
) const
2182 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2183 if ( border
== wxBORDER_DEFAULT
)
2185 border
= GetDefaultBorder();
2191 wxBorder
wxWindowBase::GetDefaultBorder() const
2193 return wxBORDER_NONE
;
2196 // ----------------------------------------------------------------------------
2198 // ----------------------------------------------------------------------------
2200 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2202 // here we just check if the point is inside the window or not
2204 // check the top and left border first
2205 bool outside
= x
< 0 || y
< 0;
2208 // check the right and bottom borders too
2209 wxSize size
= GetSize();
2210 outside
= x
>= size
.x
|| y
>= size
.y
;
2213 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2216 // ----------------------------------------------------------------------------
2218 // ----------------------------------------------------------------------------
2220 struct WXDLLEXPORT wxWindowNext
2224 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2226 void wxWindowBase::CaptureMouse()
2228 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2230 wxWindow
*winOld
= GetCapture();
2233 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2236 wxWindowNext
*item
= new wxWindowNext
;
2238 item
->next
= ms_winCaptureNext
;
2239 ms_winCaptureNext
= item
;
2241 //else: no mouse capture to save
2246 void wxWindowBase::ReleaseMouse()
2248 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2250 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2254 if ( ms_winCaptureNext
)
2256 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2258 wxWindowNext
*item
= ms_winCaptureNext
;
2259 ms_winCaptureNext
= item
->next
;
2262 //else: stack is empty, no previous capture
2264 wxLogTrace(_T("mousecapture"),
2265 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2272 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2273 int WXUNUSED(modifiers
),
2274 int WXUNUSED(keycode
))
2280 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2286 #endif // wxUSE_HOTKEY
2288 void wxWindowBase::SendDestroyEvent()
2290 wxWindowDestroyEvent event
;
2291 event
.SetEventObject(this);
2292 event
.SetId(GetId());
2293 GetEventHandler()->ProcessEvent(event
);
2296 // ----------------------------------------------------------------------------
2298 // ----------------------------------------------------------------------------
2300 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2302 #if wxUSE_VALIDATORS
2303 // Can only use the validator of the window which
2304 // is receiving the event
2305 if ( event
.GetEventObject() == this )
2307 wxValidator
*validator
= GetValidator();
2308 if ( validator
&& validator
->ProcessEvent(event
) )
2313 #endif // wxUSE_VALIDATORS
2318 bool wxWindowBase::TryParent(wxEvent
& event
)
2320 // carry on up the parent-child hierarchy if the propgation count hasn't
2322 if ( event
.ShouldPropagate() )
2324 // honour the requests to stop propagation at this window: this is
2325 // used by the dialogs, for example, to prevent processing the events
2326 // from the dialog controls in the parent frame which rarely, if ever,
2328 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2330 wxWindow
*parent
= GetParent();
2331 if ( parent
&& !parent
->IsBeingDeleted() )
2333 wxPropagateOnce
propagateOnce(event
);
2335 return parent
->GetEventHandler()->ProcessEvent(event
);
2340 return wxEvtHandler::TryParent(event
);
2343 // ----------------------------------------------------------------------------
2345 // ----------------------------------------------------------------------------
2347 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2349 while ( win
&& !win
->IsTopLevel() )
2350 win
= win
->GetParent();
2355 #if wxUSE_ACCESSIBILITY
2356 // ----------------------------------------------------------------------------
2357 // accessible object for windows
2358 // ----------------------------------------------------------------------------
2360 // Can return either a child object, or an integer
2361 // representing the child element, starting from 1.
2362 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2364 wxASSERT( GetWindow() != NULL
);
2368 return wxACC_NOT_IMPLEMENTED
;
2371 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2372 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2374 wxASSERT( GetWindow() != NULL
);
2378 wxWindow
* win
= NULL
;
2385 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2387 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2394 rect
= win
->GetRect();
2395 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2396 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2400 return wxACC_NOT_IMPLEMENTED
;
2403 // Navigates from fromId to toId/toObject.
2404 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2405 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2407 wxASSERT( GetWindow() != NULL
);
2413 case wxNAVDIR_FIRSTCHILD
:
2415 if (GetWindow()->GetChildren().GetCount() == 0)
2417 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2418 *toObject
= childWindow
->GetOrCreateAccessible();
2422 case wxNAVDIR_LASTCHILD
:
2424 if (GetWindow()->GetChildren().GetCount() == 0)
2426 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2427 *toObject
= childWindow
->GetOrCreateAccessible();
2431 case wxNAVDIR_RIGHT
:
2435 wxWindowList::compatibility_iterator node
=
2436 wxWindowList::compatibility_iterator();
2439 // Can't navigate to sibling of this window
2440 // if we're a top-level window.
2441 if (!GetWindow()->GetParent())
2442 return wxACC_NOT_IMPLEMENTED
;
2444 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2448 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2449 node
= GetWindow()->GetChildren().Item(fromId
-1);
2452 if (node
&& node
->GetNext())
2454 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2455 *toObject
= nextWindow
->GetOrCreateAccessible();
2463 case wxNAVDIR_PREVIOUS
:
2465 wxWindowList::compatibility_iterator node
=
2466 wxWindowList::compatibility_iterator();
2469 // Can't navigate to sibling of this window
2470 // if we're a top-level window.
2471 if (!GetWindow()->GetParent())
2472 return wxACC_NOT_IMPLEMENTED
;
2474 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2478 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2479 node
= GetWindow()->GetChildren().Item(fromId
-1);
2482 if (node
&& node
->GetPrevious())
2484 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2485 *toObject
= previousWindow
->GetOrCreateAccessible();
2493 return wxACC_NOT_IMPLEMENTED
;
2496 // Gets the name of the specified object.
2497 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2499 wxASSERT( GetWindow() != NULL
);
2505 // If a child, leave wxWindows to call the function on the actual
2508 return wxACC_NOT_IMPLEMENTED
;
2510 // This will eventually be replaced by specialised
2511 // accessible classes, one for each kind of wxWindows
2512 // control or window.
2513 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2514 title
= ((wxButton
*) GetWindow())->GetLabel();
2516 title
= GetWindow()->GetName();
2518 if (!title
.IsEmpty())
2524 return wxACC_NOT_IMPLEMENTED
;
2527 // Gets the number of children.
2528 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2530 wxASSERT( GetWindow() != NULL
);
2534 *childId
= (int) GetWindow()->GetChildren().GetCount();
2538 // Gets the specified child (starting from 1).
2539 // If *child is NULL and return value is wxACC_OK,
2540 // this means that the child is a simple element and
2541 // not an accessible object.
2542 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2544 wxASSERT( GetWindow() != NULL
);
2554 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2557 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2558 *child
= childWindow
->GetOrCreateAccessible();
2565 // Gets the parent, or NULL.
2566 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2568 wxASSERT( GetWindow() != NULL
);
2572 wxWindow
* parentWindow
= GetWindow()->GetParent();
2580 *parent
= parentWindow
->GetOrCreateAccessible();
2588 // Performs the default action. childId is 0 (the action for this object)
2589 // or > 0 (the action for a child).
2590 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2591 // window (e.g. an edit control).
2592 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2594 wxASSERT( GetWindow() != NULL
);
2598 return wxACC_NOT_IMPLEMENTED
;
2601 // Gets the default action for this object (0) or > 0 (the action for a child).
2602 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2603 // string if there is no action.
2604 // The retrieved string describes the action that is performed on an object,
2605 // not what the object does as a result. For example, a toolbar button that prints
2606 // a document has a default action of "Press" rather than "Prints the current document."
2607 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2609 wxASSERT( GetWindow() != NULL
);
2613 return wxACC_NOT_IMPLEMENTED
;
2616 // Returns the description for this object or a child.
2617 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2619 wxASSERT( GetWindow() != NULL
);
2623 wxString
ht(GetWindow()->GetHelpText());
2629 return wxACC_NOT_IMPLEMENTED
;
2632 // Returns help text for this object or a child, similar to tooltip text.
2633 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2635 wxASSERT( GetWindow() != NULL
);
2639 wxString
ht(GetWindow()->GetHelpText());
2645 return wxACC_NOT_IMPLEMENTED
;
2648 // Returns the keyboard shortcut for this object or child.
2649 // Return e.g. ALT+K
2650 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2652 wxASSERT( GetWindow() != NULL
);
2656 return wxACC_NOT_IMPLEMENTED
;
2659 // Returns a role constant.
2660 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2662 wxASSERT( GetWindow() != NULL
);
2666 // If a child, leave wxWindows to call the function on the actual
2669 return wxACC_NOT_IMPLEMENTED
;
2671 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2672 return wxACC_NOT_IMPLEMENTED
;
2674 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2675 return wxACC_NOT_IMPLEMENTED
;
2678 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2679 return wxACC_NOT_IMPLEMENTED
;
2682 //*role = wxROLE_SYSTEM_CLIENT;
2683 *role
= wxROLE_SYSTEM_CLIENT
;
2687 return wxACC_NOT_IMPLEMENTED
;
2691 // Returns a state constant.
2692 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2694 wxASSERT( GetWindow() != NULL
);
2698 // If a child, leave wxWindows to call the function on the actual
2701 return wxACC_NOT_IMPLEMENTED
;
2703 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2704 return wxACC_NOT_IMPLEMENTED
;
2707 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2708 return wxACC_NOT_IMPLEMENTED
;
2711 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2712 return wxACC_NOT_IMPLEMENTED
;
2719 return wxACC_NOT_IMPLEMENTED
;
2723 // Returns a localized string representing the value for the object
2725 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2727 wxASSERT( GetWindow() != NULL
);
2731 return wxACC_NOT_IMPLEMENTED
;
2734 // Selects the object or child.
2735 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2737 wxASSERT( GetWindow() != NULL
);
2741 return wxACC_NOT_IMPLEMENTED
;
2744 // Gets the window with the keyboard focus.
2745 // If childId is 0 and child is NULL, no object in
2746 // this subhierarchy has the focus.
2747 // If this object has the focus, child should be 'this'.
2748 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2750 wxASSERT( GetWindow() != NULL
);
2754 return wxACC_NOT_IMPLEMENTED
;
2757 // Gets a variant representing the selected children
2759 // Acceptable values:
2760 // - a null variant (IsNull() returns TRUE)
2761 // - a list variant (GetType() == wxT("list")
2762 // - an integer representing the selected child element,
2763 // or 0 if this object is selected (GetType() == wxT("long")
2764 // - a "void*" pointer to a wxAccessible child object
2765 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2767 wxASSERT( GetWindow() != NULL
);
2771 return wxACC_NOT_IMPLEMENTED
;
2774 #endif // wxUSE_ACCESSIBILITY