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
),
196 const wxSize
& WXUNUSED(size
),
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
);
226 SetValidator(validator
);
227 #endif // wxUSE_VALIDATORS
229 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
230 // have it too - like this it's possible to set it only in the top level
231 // dialog/frame and all children will inherit it by defult
232 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
234 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
240 // ----------------------------------------------------------------------------
242 // ----------------------------------------------------------------------------
245 wxWindowBase::~wxWindowBase()
247 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
249 // FIXME if these 2 cases result from programming errors in the user code
250 // we should probably assert here instead of silently fixing them
252 // Just in case the window has been Closed, but we're then deleting
253 // immediately: don't leave dangling pointers.
254 wxPendingDelete
.DeleteObject(this);
256 // Just in case we've loaded a top-level window via LoadNativeDialog but
257 // we weren't a dialog class
258 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
260 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
262 // reset the dangling pointer our parent window may keep to us
265 if ( m_parent
->GetDefaultItem() == this )
267 m_parent
->SetDefaultItem(NULL
);
270 m_parent
->RemoveChild(this);
275 #endif // wxUSE_CARET
278 delete m_windowValidator
;
279 #endif // wxUSE_VALIDATORS
281 #if wxUSE_CONSTRAINTS
282 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
283 // at deleted windows as they delete themselves.
284 DeleteRelatedConstraints();
288 // This removes any dangling pointers to this window in other windows'
289 // constraintsInvolvedIn lists.
290 UnsetConstraints(m_constraints
);
291 delete m_constraints
;
292 m_constraints
= NULL
;
294 #endif // wxUSE_CONSTRAINTS
296 if ( m_containingSizer
)
297 m_containingSizer
->Detach( (wxWindow
*)this );
299 delete m_windowSizer
;
301 #if wxUSE_DRAG_AND_DROP
303 #endif // wxUSE_DRAG_AND_DROP
307 #endif // wxUSE_TOOLTIPS
309 #if wxUSE_ACCESSIBILITY
314 bool wxWindowBase::Destroy()
321 bool wxWindowBase::Close(bool force
)
323 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
324 event
.SetEventObject(this);
325 event
.SetCanVeto(!force
);
327 // return false if window wasn't closed because the application vetoed the
329 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
332 bool wxWindowBase::DestroyChildren()
334 wxWindowList::compatibility_iterator node
;
337 // we iterate until the list becomes empty
338 node
= GetChildren().GetFirst();
342 wxWindow
*child
= node
->GetData();
344 // note that we really want to call delete and not ->Destroy() here
345 // because we want to delete the child immediately, before we are
346 // deleted, and delayed deletion would result in problems as our (top
347 // level) child could outlive its parent
350 wxASSERT_MSG( !GetChildren().Find(child
),
351 wxT("child didn't remove itself using RemoveChild()") );
357 // ----------------------------------------------------------------------------
358 // size/position related methods
359 // ----------------------------------------------------------------------------
361 // centre the window with respect to its parent in either (or both) directions
362 void wxWindowBase::Centre(int direction
)
364 // the position/size of the parent window or of the entire screen
366 int widthParent
, heightParent
;
368 wxWindow
*parent
= NULL
;
370 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
372 // find the parent to centre this window on: it should be the
373 // immediate parent for the controls but the top level parent for the
374 // top level windows (like dialogs)
375 parent
= GetParent();
378 while ( parent
&& !parent
->IsTopLevel() )
380 parent
= parent
->GetParent();
384 // there is no wxTopLevelWindow under wxMotif yet
386 // we shouldn't center the dialog on the iconized window: under
387 // Windows, for example, this places it completely off the screen
390 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
391 if ( winTop
&& winTop
->IsIconized() )
396 #endif // __WXMOTIF__
398 // did we find the parent?
402 direction
|= wxCENTRE_ON_SCREEN
;
406 if ( direction
& wxCENTRE_ON_SCREEN
)
408 // centre with respect to the whole screen
409 wxDisplaySize(&widthParent
, &heightParent
);
415 // centre on the parent
416 parent
->GetSize(&widthParent
, &heightParent
);
418 // adjust to the parents position
419 posParent
= parent
->GetPosition();
423 // centre inside the parents client rectangle
424 parent
->GetClientSize(&widthParent
, &heightParent
);
429 GetSize(&width
, &height
);
434 if ( direction
& wxHORIZONTAL
)
435 xNew
= (widthParent
- width
)/2;
437 if ( direction
& wxVERTICAL
)
438 yNew
= (heightParent
- height
)/2;
443 // Base size of the visible dimensions of the display
444 // to take into account the taskbar
445 wxRect rect
= wxGetClientDisplayRect();
446 wxSize
size (rect
.width
,rect
.height
);
448 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
449 // but it may mean that the window is placed on other than the main
450 // display. Therefore we only make sure centered window is on the main display
451 // if the parent is at least partially present here.
452 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
456 else if (xNew
+width
> size
.x
)
457 xNew
= size
.x
-width
-1;
459 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
461 if (yNew
+height
> size
.y
)
462 yNew
= size
.y
-height
-1;
464 // Make certain that the title bar is initially visible
465 // always, even if this would push the bottom of the
466 // dialog of the visible area of the display
471 // move the window to this position (keeping the old size but using
472 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
473 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
476 // fits the window around the children
477 void wxWindowBase::Fit()
479 if ( GetChildren().GetCount() > 0 )
481 SetClientSize(DoGetBestSize());
483 //else: do nothing if we have no children
486 // fits virtual size (ie. scrolled area etc.) around children
487 void wxWindowBase::FitInside()
489 if ( GetChildren().GetCount() > 0 )
491 SetVirtualSize( GetBestVirtualSize() );
495 // return the size best suited for the current window
496 wxSize
wxWindowBase::DoGetBestSize() const
500 return m_windowSizer
->GetMinSize();
502 #if wxUSE_CONSTRAINTS
503 else if ( m_constraints
)
505 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
507 // our minimal acceptable size is such that all our windows fit inside
511 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
513 node
= node
->GetNext() )
515 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
518 // it's not normal that we have an unconstrained child, but
519 // what can we do about it?
523 int x
= c
->right
.GetValue(),
524 y
= c
->bottom
.GetValue();
532 // TODO: we must calculate the overlaps somehow, otherwise we
533 // will never return a size bigger than the current one :-(
536 return wxSize(maxX
, maxY
);
538 #endif // wxUSE_CONSTRAINTS
539 else if ( GetChildren().GetCount() > 0 )
541 // our minimal acceptable size is such that all our windows fit inside
545 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
547 node
= node
->GetNext() )
549 wxWindow
*win
= node
->GetData();
550 if ( win
->IsTopLevel()
552 || wxDynamicCast(win
, wxStatusBar
)
553 #endif // wxUSE_STATUSBAR
556 // dialogs and frames lie in different top level windows -
557 // don't deal with them here; as for the status bars, they
558 // don't lie in the client area at all
563 win
->GetPosition(&wx
, &wy
);
565 // if the window hadn't been positioned yet, assume that it is in
572 win
->GetSize(&ww
, &wh
);
573 if ( wx
+ ww
> maxX
)
575 if ( wy
+ wh
> maxY
)
579 // for compatibility with the old versions and because it really looks
580 // slightly more pretty like this, add a pad
584 return wxSize(maxX
, maxY
);
588 // for a generic window there is no natural best size - just use the
594 // by default the origin is not shifted
595 wxPoint
wxWindowBase::GetClientAreaOrigin() const
597 return wxPoint(0, 0);
600 // set the min/max size of the window
601 void wxWindowBase::SetSizeHints(int minW
, int minH
,
603 int WXUNUSED(incW
), int WXUNUSED(incH
))
605 // setting min width greater than max width leads to infinite loops under
606 // X11 and generally doesn't make any sense, so don't allow it
607 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
608 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
609 _T("min width/height must be less than max width/height!") );
617 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
619 if ( m_windowVariant
!= variant
)
621 m_windowVariant
= variant
;
623 DoSetWindowVariant(variant
);
627 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
629 // adjust the font height to correspond to our new variant (notice that
630 // we're only called if something really changed)
631 wxFont font
= GetFont();
632 int size
= font
.GetPointSize();
635 case wxWINDOW_VARIANT_NORMAL
:
638 case wxWINDOW_VARIANT_SMALL
:
643 case wxWINDOW_VARIANT_MINI
:
648 case wxWINDOW_VARIANT_LARGE
:
654 wxFAIL_MSG(_T("unexpected window variant"));
658 font
.SetPointSize(size
);
662 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
665 m_minVirtualWidth
= minW
;
666 m_maxVirtualWidth
= maxW
;
667 m_minVirtualHeight
= minH
;
668 m_maxVirtualHeight
= maxH
;
671 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
673 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
674 x
= m_minVirtualWidth
;
675 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
676 x
= m_maxVirtualWidth
;
677 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
678 y
= m_minVirtualHeight
;
679 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
680 y
= m_maxVirtualHeight
;
682 m_virtualSize
= wxSize(x
, y
);
685 wxSize
wxWindowBase::DoGetVirtualSize() const
687 wxSize
s( GetClientSize() );
689 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
690 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
693 // ----------------------------------------------------------------------------
694 // show/hide/enable/disable the window
695 // ----------------------------------------------------------------------------
697 bool wxWindowBase::Show(bool show
)
699 if ( show
!= m_isShown
)
711 bool wxWindowBase::Enable(bool enable
)
713 if ( enable
!= m_isEnabled
)
715 m_isEnabled
= enable
;
724 // ----------------------------------------------------------------------------
726 // ----------------------------------------------------------------------------
728 bool wxWindowBase::IsTopLevel() const
733 // ----------------------------------------------------------------------------
734 // reparenting the window
735 // ----------------------------------------------------------------------------
737 void wxWindowBase::AddChild(wxWindowBase
*child
)
739 wxCHECK_RET( child
, wxT("can't add a NULL child") );
741 // this should never happen and it will lead to a crash later if it does
742 // because RemoveChild() will remove only one node from the children list
743 // and the other(s) one(s) will be left with dangling pointers in them
744 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
746 GetChildren().Append((wxWindow
*)child
);
747 child
->SetParent(this);
750 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
752 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
754 GetChildren().DeleteObject((wxWindow
*)child
);
755 child
->SetParent(NULL
);
758 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
760 wxWindow
*oldParent
= GetParent();
761 if ( newParent
== oldParent
)
767 // unlink this window from the existing parent.
770 oldParent
->RemoveChild(this);
774 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
777 // add it to the new one
780 newParent
->AddChild(this);
784 wxTopLevelWindows
.Append((wxWindow
*)this);
790 // ----------------------------------------------------------------------------
791 // event handler stuff
792 // ----------------------------------------------------------------------------
794 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
796 wxEvtHandler
*handlerOld
= GetEventHandler();
798 handler
->SetNextHandler(handlerOld
);
801 GetEventHandler()->SetPreviousHandler(handler
);
803 SetEventHandler(handler
);
806 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
808 wxEvtHandler
*handlerA
= GetEventHandler();
811 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
812 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
815 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
816 SetEventHandler(handlerB
);
821 handlerA
= (wxEvtHandler
*)NULL
;
828 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
830 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
832 wxEvtHandler
*handlerPrev
= NULL
,
833 *handlerCur
= GetEventHandler();
836 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
838 if ( handlerCur
== handler
)
842 handlerPrev
->SetNextHandler(handlerNext
);
846 SetEventHandler(handlerNext
);
851 handlerNext
->SetPreviousHandler ( handlerPrev
);
854 handler
->SetNextHandler(NULL
);
855 handler
->SetPreviousHandler(NULL
);
860 handlerPrev
= handlerCur
;
861 handlerCur
= handlerNext
;
864 wxFAIL_MSG( _T("where has the event handler gone?") );
869 // ----------------------------------------------------------------------------
871 // ----------------------------------------------------------------------------
873 /* static */ wxVisualAttributes
874 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
876 // it is important to return valid values for all attributes from here,
877 // GetXXX() below rely on this
878 wxVisualAttributes attrs
;
879 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
880 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
881 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
886 wxColour
wxWindowBase::GetBackgroundColour() const
888 if ( !m_backgroundColour
.Ok() )
890 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
892 // get our default background colour
893 wxColour colBg
= GetDefaultAttributes().colBg
;
895 // we must return some valid colour to avoid redoing this every time
896 // and also to avoid surprizing the applications written for older
897 // wxWindows versions where GetBackgroundColour() always returned
898 // something -- so give them something even if it doesn't make sense
899 // for this window (e.g. it has a themed background)
901 colBg
= GetClassDefaultAttributes().colBg
;
903 // cache it for the next call
904 wxConstCast(this, wxWindowBase
)->m_backgroundColour
= colBg
;
907 return m_backgroundColour
;
910 wxColour
wxWindowBase::GetForegroundColour() const
912 // logic is the same as above
913 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
915 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
917 wxColour colFg
= GetDefaultAttributes().colFg
;
920 colFg
= GetClassDefaultAttributes().colFg
;
922 wxConstCast(this, wxWindowBase
)->m_foregroundColour
= colFg
;
925 return m_foregroundColour
;
928 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
930 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
933 m_backgroundColour
= colour
;
940 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
942 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
945 m_foregroundColour
= colour
;
952 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
954 // setting an invalid cursor is ok, it means that we don't have any special
956 if ( m_cursor
== cursor
)
967 wxFont
& wxWindowBase::DoGetFont() const
969 // logic is the same as in GetBackgroundColour()
972 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
974 wxFont font
= GetDefaultAttributes().font
;
976 font
= GetClassDefaultAttributes().font
;
978 wxConstCast(this, wxWindowBase
)->m_font
= font
;
981 // cast is here for non-const GetFont() convenience
982 return wxConstCast(this, wxWindowBase
)->m_font
;
985 bool wxWindowBase::SetFont(const wxFont
& font
)
990 if ( font
== m_font
)
1005 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1007 m_hasCustomPalette
= true;
1010 // VZ: can anyone explain me what do we do here?
1011 wxWindowDC
d((wxWindow
*) this);
1015 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1017 wxWindow
*win
= (wxWindow
*)this;
1018 while ( win
&& !win
->HasCustomPalette() )
1020 win
= win
->GetParent();
1026 #endif // wxUSE_PALETTE
1029 void wxWindowBase::SetCaret(wxCaret
*caret
)
1040 wxASSERT_MSG( m_caret
->GetWindow() == this,
1041 wxT("caret should be created associated to this window") );
1044 #endif // wxUSE_CARET
1046 #if wxUSE_VALIDATORS
1047 // ----------------------------------------------------------------------------
1049 // ----------------------------------------------------------------------------
1051 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1053 if ( m_windowValidator
)
1054 delete m_windowValidator
;
1056 m_windowValidator
= (wxValidator
*)validator
.Clone();
1058 if ( m_windowValidator
)
1059 m_windowValidator
->SetWindow(this);
1061 #endif // wxUSE_VALIDATORS
1063 // ----------------------------------------------------------------------------
1064 // update region stuff
1065 // ----------------------------------------------------------------------------
1067 wxRect
wxWindowBase::GetUpdateClientRect() const
1069 wxRegion rgnUpdate
= GetUpdateRegion();
1070 rgnUpdate
.Intersect(GetClientRect());
1071 wxRect rectUpdate
= rgnUpdate
.GetBox();
1072 wxPoint ptOrigin
= GetClientAreaOrigin();
1073 rectUpdate
.x
-= ptOrigin
.x
;
1074 rectUpdate
.y
-= ptOrigin
.y
;
1079 bool wxWindowBase::IsExposed(int x
, int y
) const
1081 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1084 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1086 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1089 void wxWindowBase::ClearBackground()
1091 // wxGTK uses its own version, no need to add never used code
1093 wxClientDC
dc((wxWindow
*)this);
1094 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1095 dc
.SetBackground(brush
);
1100 // ----------------------------------------------------------------------------
1101 // find child window by id or name
1102 // ----------------------------------------------------------------------------
1104 wxWindow
*wxWindowBase::FindWindow( long id
)
1106 if ( id
== m_windowId
)
1107 return (wxWindow
*)this;
1109 wxWindowBase
*res
= (wxWindow
*)NULL
;
1110 wxWindowList::compatibility_iterator node
;
1111 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1113 wxWindowBase
*child
= node
->GetData();
1114 res
= child
->FindWindow( id
);
1117 return (wxWindow
*)res
;
1120 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1122 if ( name
== m_windowName
)
1123 return (wxWindow
*)this;
1125 wxWindowBase
*res
= (wxWindow
*)NULL
;
1126 wxWindowList::compatibility_iterator node
;
1127 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1129 wxWindow
*child
= node
->GetData();
1130 res
= child
->FindWindow(name
);
1133 return (wxWindow
*)res
;
1137 // find any window by id or name or label: If parent is non-NULL, look through
1138 // children for a label or title matching the specified string. If NULL, look
1139 // through all top-level windows.
1141 // to avoid duplicating code we reuse the same helper function but with
1142 // different comparators
1144 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1145 const wxString
& label
, long id
);
1148 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1151 return win
->GetLabel() == label
;
1155 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1158 return win
->GetName() == label
;
1162 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1165 return win
->GetId() == id
;
1168 // recursive helper for the FindWindowByXXX() functions
1170 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1171 const wxString
& label
,
1173 wxFindWindowCmp cmp
)
1177 // see if this is the one we're looking for
1178 if ( (*cmp
)(parent
, label
, id
) )
1179 return (wxWindow
*)parent
;
1181 // It wasn't, so check all its children
1182 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1184 node
= node
->GetNext() )
1186 // recursively check each child
1187 wxWindow
*win
= (wxWindow
*)node
->GetData();
1188 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1198 // helper for FindWindowByXXX()
1200 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1201 const wxString
& label
,
1203 wxFindWindowCmp cmp
)
1207 // just check parent and all its children
1208 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1211 // start at very top of wx's windows
1212 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1214 node
= node
->GetNext() )
1216 // recursively check each window & its children
1217 wxWindow
*win
= node
->GetData();
1218 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1228 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1230 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1235 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1237 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1241 // fall back to the label
1242 win
= FindWindowByLabel(title
, parent
);
1250 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1252 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1255 // ----------------------------------------------------------------------------
1256 // dialog oriented functions
1257 // ----------------------------------------------------------------------------
1259 void wxWindowBase::MakeModal(bool modal
)
1261 // Disable all other windows
1264 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1267 wxWindow
*win
= node
->GetData();
1269 win
->Enable(!modal
);
1271 node
= node
->GetNext();
1276 bool wxWindowBase::Validate()
1278 #if wxUSE_VALIDATORS
1279 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1281 wxWindowList::compatibility_iterator node
;
1282 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1284 wxWindowBase
*child
= node
->GetData();
1285 wxValidator
*validator
= child
->GetValidator();
1286 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1291 if ( recurse
&& !child
->Validate() )
1296 #endif // wxUSE_VALIDATORS
1301 bool wxWindowBase::TransferDataToWindow()
1303 #if wxUSE_VALIDATORS
1304 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1306 wxWindowList::compatibility_iterator node
;
1307 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1309 wxWindowBase
*child
= node
->GetData();
1310 wxValidator
*validator
= child
->GetValidator();
1311 if ( validator
&& !validator
->TransferToWindow() )
1313 wxLogWarning(_("Could not transfer data to window"));
1315 wxLog::FlushActive();
1323 if ( !child
->TransferDataToWindow() )
1325 // warning already given
1330 #endif // wxUSE_VALIDATORS
1335 bool wxWindowBase::TransferDataFromWindow()
1337 #if wxUSE_VALIDATORS
1338 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1340 wxWindowList::compatibility_iterator node
;
1341 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1343 wxWindow
*child
= node
->GetData();
1344 wxValidator
*validator
= child
->GetValidator();
1345 if ( validator
&& !validator
->TransferFromWindow() )
1347 // nop warning here because the application is supposed to give
1348 // one itself - we don't know here what might have gone wrongly
1355 if ( !child
->TransferDataFromWindow() )
1357 // warning already given
1362 #endif // wxUSE_VALIDATORS
1367 void wxWindowBase::InitDialog()
1369 wxInitDialogEvent
event(GetId());
1370 event
.SetEventObject( this );
1371 GetEventHandler()->ProcessEvent(event
);
1374 // ----------------------------------------------------------------------------
1375 // context-sensitive help support
1376 // ----------------------------------------------------------------------------
1380 // associate this help text with this window
1381 void wxWindowBase::SetHelpText(const wxString
& text
)
1383 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1386 helpProvider
->AddHelp(this, text
);
1390 // associate this help text with all windows with the same id as this
1392 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1394 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1397 helpProvider
->AddHelp(GetId(), text
);
1401 // get the help string associated with this window (may be empty)
1402 wxString
wxWindowBase::GetHelpText() const
1405 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1408 text
= helpProvider
->GetHelp(this);
1414 // show help for this window
1415 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1417 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1420 if ( helpProvider
->ShowHelp(this) )
1422 // skip the event.Skip() below
1430 #endif // wxUSE_HELP
1432 // ----------------------------------------------------------------------------
1433 // tooltipsroot.Replace("\\", "/");
1434 // ----------------------------------------------------------------------------
1438 void wxWindowBase::SetToolTip( const wxString
&tip
)
1440 // don't create the new tooltip if we already have one
1443 m_tooltip
->SetTip( tip
);
1447 SetToolTip( new wxToolTip( tip
) );
1450 // setting empty tooltip text does not remove the tooltip any more - use
1451 // SetToolTip((wxToolTip *)NULL) for this
1454 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1459 m_tooltip
= tooltip
;
1462 #endif // wxUSE_TOOLTIPS
1464 // ----------------------------------------------------------------------------
1465 // constraints and sizers
1466 // ----------------------------------------------------------------------------
1468 #if wxUSE_CONSTRAINTS
1470 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1472 if ( m_constraints
)
1474 UnsetConstraints(m_constraints
);
1475 delete m_constraints
;
1477 m_constraints
= constraints
;
1478 if ( m_constraints
)
1480 // Make sure other windows know they're part of a 'meaningful relationship'
1481 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1482 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1483 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1484 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1485 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1486 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1487 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1488 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1489 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1490 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1491 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1492 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1493 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1494 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1495 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1496 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1500 // This removes any dangling pointers to this window in other windows'
1501 // constraintsInvolvedIn lists.
1502 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1506 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1507 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1508 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1509 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1510 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1511 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1512 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1513 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1514 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1515 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1516 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1517 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1518 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1519 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1520 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1521 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1525 // Back-pointer to other windows we're involved with, so if we delete this
1526 // window, we must delete any constraints we're involved with.
1527 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1529 if ( !m_constraintsInvolvedIn
)
1530 m_constraintsInvolvedIn
= new wxWindowList
;
1531 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1532 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1535 // REMOVE back-pointer to other windows we're involved with.
1536 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1538 if ( m_constraintsInvolvedIn
)
1539 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1542 // Reset any constraints that mention this window
1543 void wxWindowBase::DeleteRelatedConstraints()
1545 if ( m_constraintsInvolvedIn
)
1547 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1550 wxWindow
*win
= node
->GetData();
1551 wxLayoutConstraints
*constr
= win
->GetConstraints();
1553 // Reset any constraints involving this window
1556 constr
->left
.ResetIfWin(this);
1557 constr
->top
.ResetIfWin(this);
1558 constr
->right
.ResetIfWin(this);
1559 constr
->bottom
.ResetIfWin(this);
1560 constr
->width
.ResetIfWin(this);
1561 constr
->height
.ResetIfWin(this);
1562 constr
->centreX
.ResetIfWin(this);
1563 constr
->centreY
.ResetIfWin(this);
1566 wxWindowList::compatibility_iterator next
= node
->GetNext();
1567 m_constraintsInvolvedIn
->Erase(node
);
1571 delete m_constraintsInvolvedIn
;
1572 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1576 #endif // wxUSE_CONSTRAINTS
1578 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1580 if ( sizer
== m_windowSizer
)
1584 delete m_windowSizer
;
1586 m_windowSizer
= sizer
;
1588 SetAutoLayout( sizer
!= NULL
);
1591 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1593 SetSizer( sizer
, deleteOld
);
1594 sizer
->SetSizeHints( (wxWindow
*) this );
1597 #if wxUSE_CONSTRAINTS
1599 void wxWindowBase::SatisfyConstraints()
1601 wxLayoutConstraints
*constr
= GetConstraints();
1602 bool wasOk
= constr
&& constr
->AreSatisfied();
1604 ResetConstraints(); // Mark all constraints as unevaluated
1608 // if we're a top level panel (i.e. our parent is frame/dialog), our
1609 // own constraints will never be satisfied any more unless we do it
1613 while ( noChanges
> 0 )
1615 LayoutPhase1(&noChanges
);
1619 LayoutPhase2(&noChanges
);
1622 #endif // wxUSE_CONSTRAINTS
1624 bool wxWindowBase::Layout()
1626 // If there is a sizer, use it instead of the constraints
1630 GetVirtualSize(&w
, &h
);
1631 GetSizer()->SetDimension( 0, 0, w
, h
);
1633 #if wxUSE_CONSTRAINTS
1636 SatisfyConstraints(); // Find the right constraints values
1637 SetConstraintSizes(); // Recursively set the real window sizes
1644 #if wxUSE_CONSTRAINTS
1646 // first phase of the constraints evaluation: set our own constraints
1647 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1649 wxLayoutConstraints
*constr
= GetConstraints();
1651 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1654 // second phase: set the constraints for our children
1655 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1662 // Layout grand children
1668 // Do a phase of evaluating child constraints
1669 bool wxWindowBase::DoPhase(int phase
)
1671 // the list containing the children for which the constraints are already
1673 wxWindowList succeeded
;
1675 // the max number of iterations we loop before concluding that we can't set
1677 static const int maxIterations
= 500;
1679 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1683 // loop over all children setting their constraints
1684 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1686 node
= node
->GetNext() )
1688 wxWindow
*child
= node
->GetData();
1689 if ( child
->IsTopLevel() )
1691 // top level children are not inside our client area
1695 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1697 // this one is either already ok or nothing we can do about it
1701 int tempNoChanges
= 0;
1702 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1703 : child
->LayoutPhase2(&tempNoChanges
);
1704 noChanges
+= tempNoChanges
;
1708 succeeded
.Append(child
);
1714 // constraints are set
1722 void wxWindowBase::ResetConstraints()
1724 wxLayoutConstraints
*constr
= GetConstraints();
1727 constr
->left
.SetDone(false);
1728 constr
->top
.SetDone(false);
1729 constr
->right
.SetDone(false);
1730 constr
->bottom
.SetDone(false);
1731 constr
->width
.SetDone(false);
1732 constr
->height
.SetDone(false);
1733 constr
->centreX
.SetDone(false);
1734 constr
->centreY
.SetDone(false);
1737 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1740 wxWindow
*win
= node
->GetData();
1741 if ( !win
->IsTopLevel() )
1742 win
->ResetConstraints();
1743 node
= node
->GetNext();
1747 // Need to distinguish between setting the 'fake' size for windows and sizers,
1748 // and setting the real values.
1749 void wxWindowBase::SetConstraintSizes(bool recurse
)
1751 wxLayoutConstraints
*constr
= GetConstraints();
1752 if ( constr
&& constr
->AreSatisfied() )
1754 int x
= constr
->left
.GetValue();
1755 int y
= constr
->top
.GetValue();
1756 int w
= constr
->width
.GetValue();
1757 int h
= constr
->height
.GetValue();
1759 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1760 (constr
->height
.GetRelationship() != wxAsIs
) )
1762 SetSize(x
, y
, w
, h
);
1766 // If we don't want to resize this window, just move it...
1772 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1773 GetClassInfo()->GetClassName(),
1779 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1782 wxWindow
*win
= node
->GetData();
1783 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1784 win
->SetConstraintSizes();
1785 node
= node
->GetNext();
1790 // Only set the size/position of the constraint (if any)
1791 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1793 wxLayoutConstraints
*constr
= GetConstraints();
1798 constr
->left
.SetValue(x
);
1799 constr
->left
.SetDone(true);
1803 constr
->top
.SetValue(y
);
1804 constr
->top
.SetDone(true);
1808 constr
->width
.SetValue(w
);
1809 constr
->width
.SetDone(true);
1813 constr
->height
.SetValue(h
);
1814 constr
->height
.SetDone(true);
1819 void wxWindowBase::MoveConstraint(int x
, int y
)
1821 wxLayoutConstraints
*constr
= GetConstraints();
1826 constr
->left
.SetValue(x
);
1827 constr
->left
.SetDone(true);
1831 constr
->top
.SetValue(y
);
1832 constr
->top
.SetDone(true);
1837 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1839 wxLayoutConstraints
*constr
= GetConstraints();
1842 *w
= constr
->width
.GetValue();
1843 *h
= constr
->height
.GetValue();
1849 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1851 wxLayoutConstraints
*constr
= GetConstraints();
1854 *w
= constr
->width
.GetValue();
1855 *h
= constr
->height
.GetValue();
1858 GetClientSize(w
, h
);
1861 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1863 wxLayoutConstraints
*constr
= GetConstraints();
1866 *x
= constr
->left
.GetValue();
1867 *y
= constr
->top
.GetValue();
1873 #endif // wxUSE_CONSTRAINTS
1875 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1877 // don't do it for the dialogs/frames - they float independently of their
1879 if ( !IsTopLevel() )
1881 wxWindow
*parent
= GetParent();
1882 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1884 wxPoint
pt(parent
->GetClientAreaOrigin());
1891 // ----------------------------------------------------------------------------
1892 // do Update UI processing for child controls
1893 // ----------------------------------------------------------------------------
1895 void wxWindowBase::UpdateWindowUI(long flags
)
1897 wxUpdateUIEvent
event(GetId());
1898 event
.m_eventObject
= this;
1900 if ( GetEventHandler()->ProcessEvent(event
) )
1902 DoUpdateWindowUI(event
);
1905 if (flags
& wxUPDATE_UI_RECURSE
)
1907 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1910 wxWindow
* child
= (wxWindow
*) node
->GetData();
1911 child
->UpdateWindowUI(flags
);
1912 node
= node
->GetNext();
1917 // do the window-specific processing after processing the update event
1918 // TODO: take specific knowledge out of this function and
1919 // put in each control's base class. Unfortunately we don't
1920 // yet have base implementation files for wxCheckBox and wxRadioButton.
1921 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1923 if ( event
.GetSetEnabled() )
1924 Enable(event
.GetEnabled());
1927 if ( event
.GetSetText() )
1929 wxControl
*control
= wxDynamicCastThis(wxControl
);
1932 if ( event
.GetText() != control
->GetLabel() )
1933 control
->SetLabel(event
.GetText());
1936 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1939 if ( event
.GetSetChecked() )
1940 checkbox
->SetValue(event
.GetChecked());
1942 #endif // wxUSE_CHECKBOX
1945 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1948 if ( event
.GetSetChecked() )
1949 radiobtn
->SetValue(event
.GetChecked());
1951 #endif // wxUSE_RADIOBTN
1957 // call internal idle recursively
1958 // may be obsolete (wait until OnIdle scheme stabilises)
1959 void wxWindowBase::ProcessInternalIdle()
1963 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1966 wxWindow
*child
= node
->GetData();
1967 child
->ProcessInternalIdle();
1968 node
= node
->GetNext();
1973 // ----------------------------------------------------------------------------
1974 // dialog units translations
1975 // ----------------------------------------------------------------------------
1977 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1979 int charWidth
= GetCharWidth();
1980 int charHeight
= GetCharHeight();
1981 wxPoint
pt2(-1, -1);
1983 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
1985 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
1990 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1992 int charWidth
= GetCharWidth();
1993 int charHeight
= GetCharHeight();
1994 wxPoint
pt2(-1, -1);
1996 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
1998 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2003 // ----------------------------------------------------------------------------
2005 // ----------------------------------------------------------------------------
2007 // propagate the colour change event to the subwindows
2008 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2010 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2013 // Only propagate to non-top-level windows
2014 wxWindow
*win
= node
->GetData();
2015 if ( !win
->IsTopLevel() )
2017 wxSysColourChangedEvent event2
;
2018 event
.m_eventObject
= win
;
2019 win
->GetEventHandler()->ProcessEvent(event2
);
2022 node
= node
->GetNext();
2026 // the default action is to populate dialog with data when it's created,
2027 // and nudge the UI into displaying itself correctly in case
2028 // we've turned the wxUpdateUIEvents frequency down low.
2029 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2031 TransferDataToWindow();
2033 // Update the UI at this point
2034 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2037 // process Ctrl-Alt-mclick
2038 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2041 if ( event
.ControlDown() && event
.AltDown() )
2043 // don't translate these strings
2046 #ifdef __WXUNIVERSAL__
2048 #endif // __WXUNIVERSAL__
2050 switch ( wxGetOsVersion() )
2052 case wxMOTIF_X
: port
+= _T("Motif"); break;
2054 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2055 case wxBEOS
: port
+= _T("BeOS"); break;
2059 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2065 case wxWIN386
: port
+= _T("MS Windows"); break;
2069 case wxMGL_OS2
: port
+= _T("MGL"); break;
2071 case wxOS2_PM
: port
+= _T("OS/2"); break;
2072 default: port
+= _T("unknown"); break;
2075 wxMessageBox(wxString::Format(
2077 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
2091 _T("wxWindows information"),
2092 wxICON_INFORMATION
| wxOK
,
2096 #endif // wxUSE_MSGDLG
2102 // ----------------------------------------------------------------------------
2104 // ----------------------------------------------------------------------------
2106 #if wxUSE_ACCESSIBILITY
2107 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2109 if (m_accessible
&& (accessible
!= m_accessible
))
2110 delete m_accessible
;
2111 m_accessible
= accessible
;
2113 m_accessible
->SetWindow((wxWindow
*) this);
2116 // Returns the accessible object, creating if necessary.
2117 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2120 m_accessible
= CreateAccessible();
2121 return m_accessible
;
2124 // Override to create a specific accessible object.
2125 wxAccessible
* wxWindowBase::CreateAccessible()
2127 return new wxWindowAccessible((wxWindow
*) this);
2133 // ----------------------------------------------------------------------------
2134 // list classes implementation
2135 // ----------------------------------------------------------------------------
2137 void wxWindowListNode::DeleteData()
2139 delete (wxWindow
*)GetData();
2143 // ----------------------------------------------------------------------------
2145 // ----------------------------------------------------------------------------
2147 wxBorder
wxWindowBase::GetBorder(long flags
) const
2149 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2150 if ( border
== wxBORDER_DEFAULT
)
2152 border
= GetDefaultBorder();
2158 wxBorder
wxWindowBase::GetDefaultBorder() const
2160 return wxBORDER_NONE
;
2163 // ----------------------------------------------------------------------------
2165 // ----------------------------------------------------------------------------
2167 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2169 // here we just check if the point is inside the window or not
2171 // check the top and left border first
2172 bool outside
= x
< 0 || y
< 0;
2175 // check the right and bottom borders too
2176 wxSize size
= GetSize();
2177 outside
= x
>= size
.x
|| y
>= size
.y
;
2180 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2183 // ----------------------------------------------------------------------------
2185 // ----------------------------------------------------------------------------
2187 struct WXDLLEXPORT wxWindowNext
2191 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2193 void wxWindowBase::CaptureMouse()
2195 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2197 wxWindow
*winOld
= GetCapture();
2200 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2203 wxWindowNext
*item
= new wxWindowNext
;
2205 item
->next
= ms_winCaptureNext
;
2206 ms_winCaptureNext
= item
;
2208 //else: no mouse capture to save
2213 void wxWindowBase::ReleaseMouse()
2215 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2217 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2221 if ( ms_winCaptureNext
)
2223 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2225 wxWindowNext
*item
= ms_winCaptureNext
;
2226 ms_winCaptureNext
= item
->next
;
2229 //else: stack is empty, no previous capture
2231 wxLogTrace(_T("mousecapture"),
2232 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2239 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2240 int WXUNUSED(modifiers
),
2241 int WXUNUSED(keycode
))
2247 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2253 #endif // wxUSE_HOTKEY
2255 void wxWindowBase::SendDestroyEvent()
2257 wxWindowDestroyEvent event
;
2258 event
.SetEventObject(this);
2259 event
.SetId(GetId());
2260 GetEventHandler()->ProcessEvent(event
);
2263 // ----------------------------------------------------------------------------
2265 // ----------------------------------------------------------------------------
2267 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2269 #if wxUSE_VALIDATORS
2270 // Can only use the validator of the window which
2271 // is receiving the event
2272 if ( event
.GetEventObject() == this )
2274 wxValidator
*validator
= GetValidator();
2275 if ( validator
&& validator
->ProcessEvent(event
) )
2280 #endif // wxUSE_VALIDATORS
2285 bool wxWindowBase::TryParent(wxEvent
& event
)
2287 // carry on up the parent-child hierarchy if the propgation count hasn't
2289 if ( event
.ShouldPropagate() )
2291 // honour the requests to stop propagation at this window: this is
2292 // used by the dialogs, for example, to prevent processing the events
2293 // from the dialog controls in the parent frame which rarely, if ever,
2295 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2297 wxWindow
*parent
= GetParent();
2298 if ( parent
&& !parent
->IsBeingDeleted() )
2300 wxPropagateOnce
propagateOnce(event
);
2302 return parent
->GetEventHandler()->ProcessEvent(event
);
2307 return wxEvtHandler::TryParent(event
);
2310 // ----------------------------------------------------------------------------
2312 // ----------------------------------------------------------------------------
2314 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2316 while ( win
&& !win
->IsTopLevel() )
2317 win
= win
->GetParent();
2322 #if wxUSE_ACCESSIBILITY
2323 // ----------------------------------------------------------------------------
2324 // accessible object for windows
2325 // ----------------------------------------------------------------------------
2327 // Can return either a child object, or an integer
2328 // representing the child element, starting from 1.
2329 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2331 wxASSERT( GetWindow() != NULL
);
2335 return wxACC_NOT_IMPLEMENTED
;
2338 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2339 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2341 wxASSERT( GetWindow() != NULL
);
2345 wxWindow
* win
= NULL
;
2352 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2354 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2361 rect
= win
->GetRect();
2362 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2363 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2367 return wxACC_NOT_IMPLEMENTED
;
2370 // Navigates from fromId to toId/toObject.
2371 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2372 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2374 wxASSERT( GetWindow() != NULL
);
2380 case wxNAVDIR_FIRSTCHILD
:
2382 if (GetWindow()->GetChildren().GetCount() == 0)
2384 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2385 *toObject
= childWindow
->GetOrCreateAccessible();
2389 case wxNAVDIR_LASTCHILD
:
2391 if (GetWindow()->GetChildren().GetCount() == 0)
2393 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2394 *toObject
= childWindow
->GetOrCreateAccessible();
2398 case wxNAVDIR_RIGHT
:
2402 wxWindowList::compatibility_iterator node
=
2403 wxWindowList::compatibility_iterator();
2406 // Can't navigate to sibling of this window
2407 // if we're a top-level window.
2408 if (!GetWindow()->GetParent())
2409 return wxACC_NOT_IMPLEMENTED
;
2411 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2415 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2416 node
= GetWindow()->GetChildren().Item(fromId
-1);
2419 if (node
&& node
->GetNext())
2421 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2422 *toObject
= nextWindow
->GetOrCreateAccessible();
2430 case wxNAVDIR_PREVIOUS
:
2432 wxWindowList::compatibility_iterator node
=
2433 wxWindowList::compatibility_iterator();
2436 // Can't navigate to sibling of this window
2437 // if we're a top-level window.
2438 if (!GetWindow()->GetParent())
2439 return wxACC_NOT_IMPLEMENTED
;
2441 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2445 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2446 node
= GetWindow()->GetChildren().Item(fromId
-1);
2449 if (node
&& node
->GetPrevious())
2451 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2452 *toObject
= previousWindow
->GetOrCreateAccessible();
2460 return wxACC_NOT_IMPLEMENTED
;
2463 // Gets the name of the specified object.
2464 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2466 wxASSERT( GetWindow() != NULL
);
2472 // If a child, leave wxWindows to call the function on the actual
2475 return wxACC_NOT_IMPLEMENTED
;
2477 // This will eventually be replaced by specialised
2478 // accessible classes, one for each kind of wxWindows
2479 // control or window.
2480 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2481 title
= ((wxButton
*) GetWindow())->GetLabel();
2483 title
= GetWindow()->GetName();
2485 if (!title
.IsEmpty())
2491 return wxACC_NOT_IMPLEMENTED
;
2494 // Gets the number of children.
2495 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2497 wxASSERT( GetWindow() != NULL
);
2501 *childId
= (int) GetWindow()->GetChildren().GetCount();
2505 // Gets the specified child (starting from 1).
2506 // If *child is NULL and return value is wxACC_OK,
2507 // this means that the child is a simple element and
2508 // not an accessible object.
2509 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2511 wxASSERT( GetWindow() != NULL
);
2521 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2524 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2525 *child
= childWindow
->GetOrCreateAccessible();
2532 // Gets the parent, or NULL.
2533 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2535 wxASSERT( GetWindow() != NULL
);
2539 wxWindow
* parentWindow
= GetWindow()->GetParent();
2547 *parent
= parentWindow
->GetOrCreateAccessible();
2555 // Performs the default action. childId is 0 (the action for this object)
2556 // or > 0 (the action for a child).
2557 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2558 // window (e.g. an edit control).
2559 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2561 wxASSERT( GetWindow() != NULL
);
2565 return wxACC_NOT_IMPLEMENTED
;
2568 // Gets the default action for this object (0) or > 0 (the action for a child).
2569 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2570 // string if there is no action.
2571 // The retrieved string describes the action that is performed on an object,
2572 // not what the object does as a result. For example, a toolbar button that prints
2573 // a document has a default action of "Press" rather than "Prints the current document."
2574 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2576 wxASSERT( GetWindow() != NULL
);
2580 return wxACC_NOT_IMPLEMENTED
;
2583 // Returns the description for this object or a child.
2584 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2586 wxASSERT( GetWindow() != NULL
);
2590 wxString
ht(GetWindow()->GetHelpText());
2596 return wxACC_NOT_IMPLEMENTED
;
2599 // Returns help text for this object or a child, similar to tooltip text.
2600 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2602 wxASSERT( GetWindow() != NULL
);
2606 wxString
ht(GetWindow()->GetHelpText());
2612 return wxACC_NOT_IMPLEMENTED
;
2615 // Returns the keyboard shortcut for this object or child.
2616 // Return e.g. ALT+K
2617 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2619 wxASSERT( GetWindow() != NULL
);
2623 return wxACC_NOT_IMPLEMENTED
;
2626 // Returns a role constant.
2627 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2629 wxASSERT( GetWindow() != NULL
);
2633 // If a child, leave wxWindows to call the function on the actual
2636 return wxACC_NOT_IMPLEMENTED
;
2638 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2639 return wxACC_NOT_IMPLEMENTED
;
2641 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2642 return wxACC_NOT_IMPLEMENTED
;
2645 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2646 return wxACC_NOT_IMPLEMENTED
;
2649 //*role = wxROLE_SYSTEM_CLIENT;
2650 *role
= wxROLE_SYSTEM_CLIENT
;
2654 return wxACC_NOT_IMPLEMENTED
;
2658 // Returns a state constant.
2659 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2661 wxASSERT( GetWindow() != NULL
);
2665 // If a child, leave wxWindows to call the function on the actual
2668 return wxACC_NOT_IMPLEMENTED
;
2670 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2671 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
;
2686 return wxACC_NOT_IMPLEMENTED
;
2690 // Returns a localized string representing the value for the object
2692 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2694 wxASSERT( GetWindow() != NULL
);
2698 return wxACC_NOT_IMPLEMENTED
;
2701 // Selects the object or child.
2702 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2704 wxASSERT( GetWindow() != NULL
);
2708 return wxACC_NOT_IMPLEMENTED
;
2711 // Gets the window with the keyboard focus.
2712 // If childId is 0 and child is NULL, no object in
2713 // this subhierarchy has the focus.
2714 // If this object has the focus, child should be 'this'.
2715 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2717 wxASSERT( GetWindow() != NULL
);
2721 return wxACC_NOT_IMPLEMENTED
;
2724 // Gets a variant representing the selected children
2726 // Acceptable values:
2727 // - a null variant (IsNull() returns TRUE)
2728 // - a list variant (GetType() == wxT("list")
2729 // - an integer representing the selected child element,
2730 // or 0 if this object is selected (GetType() == wxT("long")
2731 // - a "void*" pointer to a wxAccessible child object
2732 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2734 wxASSERT( GetWindow() != NULL
);
2738 return wxACC_NOT_IMPLEMENTED
;
2741 #endif // wxUSE_ACCESSIBILITY