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 m_initialSize
= wxDefaultSize
;
120 // no constraints on the minimal window size
126 // window are created enabled and visible by default
130 // the default event handler is just this window
131 m_eventHandler
= this;
135 m_windowValidator
= (wxValidator
*) NULL
;
136 #endif // wxUSE_VALIDATORS
138 // the colours/fonts are default for now, so leave m_font,
139 // m_backgroundColour and m_foregroundColour uninitialized and set those
148 #if wxUSE_CONSTRAINTS
149 // no constraints whatsoever
150 m_constraints
= (wxLayoutConstraints
*) NULL
;
151 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
152 #endif // wxUSE_CONSTRAINTS
154 m_windowSizer
= (wxSizer
*) NULL
;
155 m_containingSizer
= (wxSizer
*) NULL
;
156 m_autoLayout
= false;
158 #if wxUSE_DRAG_AND_DROP
159 m_dropTarget
= (wxDropTarget
*)NULL
;
160 #endif // wxUSE_DRAG_AND_DROP
163 m_tooltip
= (wxToolTip
*)NULL
;
164 #endif // wxUSE_TOOLTIPS
167 m_caret
= (wxCaret
*)NULL
;
168 #endif // wxUSE_CARET
171 m_hasCustomPalette
= false;
172 #endif // wxUSE_PALETTE
174 #if wxUSE_ACCESSIBILITY
178 m_virtualSize
= wxDefaultSize
;
183 m_maxVirtualHeight
= -1;
185 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
187 // Whether we're using the current theme for this window (wxGTK only for now)
188 m_themeEnabled
= false;
190 // VZ: this one shouldn't exist...
191 m_isBeingDeleted
= false;
194 // common part of window creation process
195 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
197 const wxPoint
& WXUNUSED(pos
),
200 const wxValidator
& wxVALIDATOR_PARAM(validator
),
201 const wxString
& name
)
204 // wxGTK doesn't allow to create controls with static box as the parent so
205 // this will result in a crash when the program is ported to wxGTK so warn
208 // if you get this assert, the correct solution is to create the controls
209 // as siblings of the static box
210 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
211 _T("wxStaticBox can't be used as a window parent!") );
212 #endif // wxUSE_STATBOX
214 // ids are limited to 16 bits under MSW so if you care about portability,
215 // it's not a good idea to use ids out of this range (and negative ids are
216 // reserved for wxWindows own usage)
217 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
218 _T("invalid id value") );
220 // generate a new id if the user doesn't care about it
221 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
224 SetWindowStyleFlag(style
);
227 // Save the size passed to the ctor (if any.) This will be used later as
228 // the minimal size if the window is added to a sizer.
229 m_initialSize
= size
;
232 SetValidator(validator
);
233 #endif // wxUSE_VALIDATORS
235 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
236 // have it too - like this it's possible to set it only in the top level
237 // dialog/frame and all children will inherit it by defult
238 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
240 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
246 // ----------------------------------------------------------------------------
248 // ----------------------------------------------------------------------------
251 wxWindowBase::~wxWindowBase()
253 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
255 // FIXME if these 2 cases result from programming errors in the user code
256 // we should probably assert here instead of silently fixing them
258 // Just in case the window has been Closed, but we're then deleting
259 // immediately: don't leave dangling pointers.
260 wxPendingDelete
.DeleteObject(this);
262 // Just in case we've loaded a top-level window via LoadNativeDialog but
263 // we weren't a dialog class
264 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
266 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
268 // reset the dangling pointer our parent window may keep to us
271 if ( m_parent
->GetDefaultItem() == this )
273 m_parent
->SetDefaultItem(NULL
);
276 m_parent
->RemoveChild(this);
281 #endif // wxUSE_CARET
284 delete m_windowValidator
;
285 #endif // wxUSE_VALIDATORS
287 #if wxUSE_CONSTRAINTS
288 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
289 // at deleted windows as they delete themselves.
290 DeleteRelatedConstraints();
294 // This removes any dangling pointers to this window in other windows'
295 // constraintsInvolvedIn lists.
296 UnsetConstraints(m_constraints
);
297 delete m_constraints
;
298 m_constraints
= NULL
;
300 #endif // wxUSE_CONSTRAINTS
302 if ( m_containingSizer
)
303 m_containingSizer
->Detach( (wxWindow
*)this );
305 delete m_windowSizer
;
307 #if wxUSE_DRAG_AND_DROP
309 #endif // wxUSE_DRAG_AND_DROP
313 #endif // wxUSE_TOOLTIPS
315 #if wxUSE_ACCESSIBILITY
320 bool wxWindowBase::Destroy()
327 bool wxWindowBase::Close(bool force
)
329 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
330 event
.SetEventObject(this);
331 event
.SetCanVeto(!force
);
333 // return false if window wasn't closed because the application vetoed the
335 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
338 bool wxWindowBase::DestroyChildren()
340 wxWindowList::compatibility_iterator node
;
343 // we iterate until the list becomes empty
344 node
= GetChildren().GetFirst();
348 wxWindow
*child
= node
->GetData();
350 // note that we really want to call delete and not ->Destroy() here
351 // because we want to delete the child immediately, before we are
352 // deleted, and delayed deletion would result in problems as our (top
353 // level) child could outlive its parent
356 wxASSERT_MSG( !GetChildren().Find(child
),
357 wxT("child didn't remove itself using RemoveChild()") );
363 // ----------------------------------------------------------------------------
364 // size/position related methods
365 // ----------------------------------------------------------------------------
367 // centre the window with respect to its parent in either (or both) directions
368 void wxWindowBase::Centre(int direction
)
370 // the position/size of the parent window or of the entire screen
372 int widthParent
, heightParent
;
374 wxWindow
*parent
= NULL
;
376 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
378 // find the parent to centre this window on: it should be the
379 // immediate parent for the controls but the top level parent for the
380 // top level windows (like dialogs)
381 parent
= GetParent();
384 while ( parent
&& !parent
->IsTopLevel() )
386 parent
= parent
->GetParent();
390 // there is no wxTopLevelWindow under wxMotif yet
392 // we shouldn't center the dialog on the iconized window: under
393 // Windows, for example, this places it completely off the screen
396 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
397 if ( winTop
&& winTop
->IsIconized() )
402 #endif // __WXMOTIF__
404 // did we find the parent?
408 direction
|= wxCENTRE_ON_SCREEN
;
412 if ( direction
& wxCENTRE_ON_SCREEN
)
414 // centre with respect to the whole screen
415 wxDisplaySize(&widthParent
, &heightParent
);
421 // centre on the parent
422 parent
->GetSize(&widthParent
, &heightParent
);
424 // adjust to the parents position
425 posParent
= parent
->GetPosition();
429 // centre inside the parents client rectangle
430 parent
->GetClientSize(&widthParent
, &heightParent
);
435 GetSize(&width
, &height
);
440 if ( direction
& wxHORIZONTAL
)
441 xNew
= (widthParent
- width
)/2;
443 if ( direction
& wxVERTICAL
)
444 yNew
= (heightParent
- height
)/2;
449 // Base size of the visible dimensions of the display
450 // to take into account the taskbar
451 wxRect rect
= wxGetClientDisplayRect();
452 wxSize
size (rect
.width
,rect
.height
);
454 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
455 // but it may mean that the window is placed on other than the main
456 // display. Therefore we only make sure centered window is on the main display
457 // if the parent is at least partially present here.
458 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
462 else if (xNew
+width
> size
.x
)
463 xNew
= size
.x
-width
-1;
465 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
467 if (yNew
+height
> size
.y
)
468 yNew
= size
.y
-height
-1;
470 // Make certain that the title bar is initially visible
471 // always, even if this would push the bottom of the
472 // dialog of the visible area of the display
477 // move the window to this position (keeping the old size but using
478 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
479 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
482 // fits the window around the children
483 void wxWindowBase::Fit()
485 if ( GetChildren().GetCount() > 0 )
487 SetClientSize(DoGetBestSize());
489 //else: do nothing if we have no children
492 // fits virtual size (ie. scrolled area etc.) around children
493 void wxWindowBase::FitInside()
495 if ( GetChildren().GetCount() > 0 )
497 SetVirtualSize( GetBestVirtualSize() );
501 // return the size best suited for the current window
502 wxSize
wxWindowBase::DoGetBestSize() const
506 return m_windowSizer
->GetMinSize();
508 #if wxUSE_CONSTRAINTS
509 else if ( m_constraints
)
511 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
513 // our minimal acceptable size is such that all our windows fit inside
517 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
519 node
= node
->GetNext() )
521 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
524 // it's not normal that we have an unconstrained child, but
525 // what can we do about it?
529 int x
= c
->right
.GetValue(),
530 y
= c
->bottom
.GetValue();
538 // TODO: we must calculate the overlaps somehow, otherwise we
539 // will never return a size bigger than the current one :-(
542 return wxSize(maxX
, maxY
);
544 #endif // wxUSE_CONSTRAINTS
545 else if ( !GetChildren().empty() )
547 // our minimal acceptable size is such that all our visible child windows fit inside
551 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
553 node
= node
->GetNext() )
555 wxWindow
*win
= node
->GetData();
556 if ( win
->IsTopLevel() || ( ! win
->IsShown() )
558 || wxDynamicCast(win
, wxStatusBar
)
559 #endif // wxUSE_STATUSBAR
562 // dialogs and frames lie in different top level windows -
563 // don't deal with them here; as for the status bars, they
564 // don't lie in the client area at all
569 win
->GetPosition(&wx
, &wy
);
571 // if the window hadn't been positioned yet, assume that it is in
578 win
->GetSize(&ww
, &wh
);
579 if ( wx
+ ww
> maxX
)
581 if ( wy
+ wh
> maxY
)
585 // for compatibility with the old versions and because it really looks
586 // slightly more pretty like this, add a pad
590 return wxSize(maxX
, maxY
);
594 // for a generic window there is no natural best size - just use the
600 // by default the origin is not shifted
601 wxPoint
wxWindowBase::GetClientAreaOrigin() const
603 return wxPoint(0, 0);
606 // set the min/max size of the window
607 void wxWindowBase::SetSizeHints(int minW
, int minH
,
609 int WXUNUSED(incW
), int WXUNUSED(incH
))
611 // setting min width greater than max width leads to infinite loops under
612 // X11 and generally doesn't make any sense, so don't allow it
613 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
614 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
615 _T("min width/height must be less than max width/height!") );
623 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
625 if ( m_windowVariant
!= variant
)
627 m_windowVariant
= variant
;
629 DoSetWindowVariant(variant
);
633 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
635 // adjust the font height to correspond to our new variant (notice that
636 // we're only called if something really changed)
637 wxFont font
= GetFont();
638 int size
= font
.GetPointSize();
641 case wxWINDOW_VARIANT_NORMAL
:
644 case wxWINDOW_VARIANT_SMALL
:
649 case wxWINDOW_VARIANT_MINI
:
654 case wxWINDOW_VARIANT_LARGE
:
660 wxFAIL_MSG(_T("unexpected window variant"));
664 font
.SetPointSize(size
);
668 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
671 m_minVirtualWidth
= minW
;
672 m_maxVirtualWidth
= maxW
;
673 m_minVirtualHeight
= minH
;
674 m_maxVirtualHeight
= maxH
;
677 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
679 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
680 x
= m_minVirtualWidth
;
681 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
682 x
= m_maxVirtualWidth
;
683 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
684 y
= m_minVirtualHeight
;
685 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
686 y
= m_maxVirtualHeight
;
688 m_virtualSize
= wxSize(x
, y
);
691 wxSize
wxWindowBase::DoGetVirtualSize() const
693 wxSize
s( GetClientSize() );
695 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
696 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
699 // ----------------------------------------------------------------------------
700 // show/hide/enable/disable the window
701 // ----------------------------------------------------------------------------
703 bool wxWindowBase::Show(bool show
)
705 if ( show
!= m_isShown
)
717 bool wxWindowBase::Enable(bool enable
)
719 if ( enable
!= m_isEnabled
)
721 m_isEnabled
= enable
;
730 // ----------------------------------------------------------------------------
732 // ----------------------------------------------------------------------------
734 bool wxWindowBase::IsTopLevel() const
739 // ----------------------------------------------------------------------------
740 // reparenting the window
741 // ----------------------------------------------------------------------------
743 void wxWindowBase::AddChild(wxWindowBase
*child
)
745 wxCHECK_RET( child
, wxT("can't add a NULL child") );
747 // this should never happen and it will lead to a crash later if it does
748 // because RemoveChild() will remove only one node from the children list
749 // and the other(s) one(s) will be left with dangling pointers in them
750 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
752 GetChildren().Append((wxWindow
*)child
);
753 child
->SetParent(this);
756 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
758 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
760 GetChildren().DeleteObject((wxWindow
*)child
);
761 child
->SetParent(NULL
);
764 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
766 wxWindow
*oldParent
= GetParent();
767 if ( newParent
== oldParent
)
773 // unlink this window from the existing parent.
776 oldParent
->RemoveChild(this);
780 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
783 // add it to the new one
786 newParent
->AddChild(this);
790 wxTopLevelWindows
.Append((wxWindow
*)this);
796 // ----------------------------------------------------------------------------
797 // event handler stuff
798 // ----------------------------------------------------------------------------
800 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
802 wxEvtHandler
*handlerOld
= GetEventHandler();
804 handler
->SetNextHandler(handlerOld
);
807 GetEventHandler()->SetPreviousHandler(handler
);
809 SetEventHandler(handler
);
812 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
814 wxEvtHandler
*handlerA
= GetEventHandler();
817 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
818 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
821 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
822 SetEventHandler(handlerB
);
827 handlerA
= (wxEvtHandler
*)NULL
;
834 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
836 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
838 wxEvtHandler
*handlerPrev
= NULL
,
839 *handlerCur
= GetEventHandler();
842 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
844 if ( handlerCur
== handler
)
848 handlerPrev
->SetNextHandler(handlerNext
);
852 SetEventHandler(handlerNext
);
857 handlerNext
->SetPreviousHandler ( handlerPrev
);
860 handler
->SetNextHandler(NULL
);
861 handler
->SetPreviousHandler(NULL
);
866 handlerPrev
= handlerCur
;
867 handlerCur
= handlerNext
;
870 wxFAIL_MSG( _T("where has the event handler gone?") );
875 // ----------------------------------------------------------------------------
877 // ----------------------------------------------------------------------------
879 void wxWindowBase::InheritAttributes()
881 const wxWindowBase
* const parent
= GetParent();
885 // we only inherit attributes which had been explicitly set for the parent
886 // which ensures that this only happens if the user really wants it and
887 // not by default which wouldn't make any sense in modern GUIs where the
888 // controls don't all use the same fonts (nor colours)
889 if ( parent
->m_hasFont
&& !m_hasFont
)
890 SetFont(parent
->GetFont());
892 // in addition, there is a possibility to explicitly forbid inheriting
893 // colours at each class level by overriding ShouldInheritColours()
894 if ( ShouldInheritColours() )
896 if ( parent
->m_hasFgCol
&& !m_hasFgCol
)
897 SetForegroundColour(parent
->GetForegroundColour());
899 if ( parent
->m_hasBgCol
&& !m_hasBgCol
)
900 SetBackgroundColour(parent
->GetBackgroundColour());
904 /* static */ wxVisualAttributes
905 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
907 // it is important to return valid values for all attributes from here,
908 // GetXXX() below rely on this
909 wxVisualAttributes attrs
;
910 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
911 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
912 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
917 wxColour
wxWindowBase::GetBackgroundColour() const
919 if ( !m_backgroundColour
.Ok() )
921 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
923 // get our default background colour
924 wxColour colBg
= GetDefaultAttributes().colBg
;
926 // we must return some valid colour to avoid redoing this every time
927 // and also to avoid surprizing the applications written for older
928 // wxWindows versions where GetBackgroundColour() always returned
929 // something -- so give them something even if it doesn't make sense
930 // for this window (e.g. it has a themed background)
932 colBg
= GetClassDefaultAttributes().colBg
;
934 // cache it for the next call
935 wxConstCast(this, wxWindowBase
)->m_backgroundColour
= colBg
;
938 return m_backgroundColour
;
941 wxColour
wxWindowBase::GetForegroundColour() const
943 // logic is the same as above
944 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
946 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
948 wxColour colFg
= GetDefaultAttributes().colFg
;
951 colFg
= GetClassDefaultAttributes().colFg
;
953 wxConstCast(this, wxWindowBase
)->m_foregroundColour
= colFg
;
956 return m_foregroundColour
;
959 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
961 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
964 m_backgroundColour
= colour
;
971 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
973 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
976 m_foregroundColour
= colour
;
983 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
985 // setting an invalid cursor is ok, it means that we don't have any special
987 if ( m_cursor
== cursor
)
998 wxFont
& wxWindowBase::DoGetFont() const
1000 // logic is the same as in GetBackgroundColour()
1003 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1005 wxFont font
= GetDefaultAttributes().font
;
1007 font
= GetClassDefaultAttributes().font
;
1009 wxConstCast(this, wxWindowBase
)->m_font
= font
;
1012 // cast is here for non-const GetFont() convenience
1013 return wxConstCast(this, wxWindowBase
)->m_font
;
1016 bool wxWindowBase::SetFont(const wxFont
& font
)
1021 if ( font
== m_font
)
1036 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1038 m_hasCustomPalette
= true;
1041 // VZ: can anyone explain me what do we do here?
1042 wxWindowDC
d((wxWindow
*) this);
1046 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1048 wxWindow
*win
= (wxWindow
*)this;
1049 while ( win
&& !win
->HasCustomPalette() )
1051 win
= win
->GetParent();
1057 #endif // wxUSE_PALETTE
1060 void wxWindowBase::SetCaret(wxCaret
*caret
)
1071 wxASSERT_MSG( m_caret
->GetWindow() == this,
1072 wxT("caret should be created associated to this window") );
1075 #endif // wxUSE_CARET
1077 #if wxUSE_VALIDATORS
1078 // ----------------------------------------------------------------------------
1080 // ----------------------------------------------------------------------------
1082 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1084 if ( m_windowValidator
)
1085 delete m_windowValidator
;
1087 m_windowValidator
= (wxValidator
*)validator
.Clone();
1089 if ( m_windowValidator
)
1090 m_windowValidator
->SetWindow(this);
1092 #endif // wxUSE_VALIDATORS
1094 // ----------------------------------------------------------------------------
1095 // update region stuff
1096 // ----------------------------------------------------------------------------
1098 wxRect
wxWindowBase::GetUpdateClientRect() const
1100 wxRegion rgnUpdate
= GetUpdateRegion();
1101 rgnUpdate
.Intersect(GetClientRect());
1102 wxRect rectUpdate
= rgnUpdate
.GetBox();
1103 wxPoint ptOrigin
= GetClientAreaOrigin();
1104 rectUpdate
.x
-= ptOrigin
.x
;
1105 rectUpdate
.y
-= ptOrigin
.y
;
1110 bool wxWindowBase::IsExposed(int x
, int y
) const
1112 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1115 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1117 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1120 void wxWindowBase::ClearBackground()
1122 // wxGTK uses its own version, no need to add never used code
1124 wxClientDC
dc((wxWindow
*)this);
1125 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1126 dc
.SetBackground(brush
);
1131 // ----------------------------------------------------------------------------
1132 // find child window by id or name
1133 // ----------------------------------------------------------------------------
1135 wxWindow
*wxWindowBase::FindWindow( long id
)
1137 if ( id
== m_windowId
)
1138 return (wxWindow
*)this;
1140 wxWindowBase
*res
= (wxWindow
*)NULL
;
1141 wxWindowList::compatibility_iterator node
;
1142 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1144 wxWindowBase
*child
= node
->GetData();
1145 res
= child
->FindWindow( id
);
1148 return (wxWindow
*)res
;
1151 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1153 if ( name
== m_windowName
)
1154 return (wxWindow
*)this;
1156 wxWindowBase
*res
= (wxWindow
*)NULL
;
1157 wxWindowList::compatibility_iterator node
;
1158 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1160 wxWindow
*child
= node
->GetData();
1161 res
= child
->FindWindow(name
);
1164 return (wxWindow
*)res
;
1168 // find any window by id or name or label: If parent is non-NULL, look through
1169 // children for a label or title matching the specified string. If NULL, look
1170 // through all top-level windows.
1172 // to avoid duplicating code we reuse the same helper function but with
1173 // different comparators
1175 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1176 const wxString
& label
, long id
);
1179 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1182 return win
->GetLabel() == label
;
1186 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1189 return win
->GetName() == label
;
1193 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1196 return win
->GetId() == id
;
1199 // recursive helper for the FindWindowByXXX() functions
1201 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1202 const wxString
& label
,
1204 wxFindWindowCmp cmp
)
1208 // see if this is the one we're looking for
1209 if ( (*cmp
)(parent
, label
, id
) )
1210 return (wxWindow
*)parent
;
1212 // It wasn't, so check all its children
1213 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1215 node
= node
->GetNext() )
1217 // recursively check each child
1218 wxWindow
*win
= (wxWindow
*)node
->GetData();
1219 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1229 // helper for FindWindowByXXX()
1231 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1232 const wxString
& label
,
1234 wxFindWindowCmp cmp
)
1238 // just check parent and all its children
1239 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1242 // start at very top of wx's windows
1243 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1245 node
= node
->GetNext() )
1247 // recursively check each window & its children
1248 wxWindow
*win
= node
->GetData();
1249 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1259 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1261 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1266 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1268 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1272 // fall back to the label
1273 win
= FindWindowByLabel(title
, parent
);
1281 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1283 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1286 // ----------------------------------------------------------------------------
1287 // dialog oriented functions
1288 // ----------------------------------------------------------------------------
1290 void wxWindowBase::MakeModal(bool modal
)
1292 // Disable all other windows
1295 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1298 wxWindow
*win
= node
->GetData();
1300 win
->Enable(!modal
);
1302 node
= node
->GetNext();
1307 bool wxWindowBase::Validate()
1309 #if wxUSE_VALIDATORS
1310 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1312 wxWindowList::compatibility_iterator node
;
1313 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1315 wxWindowBase
*child
= node
->GetData();
1316 wxValidator
*validator
= child
->GetValidator();
1317 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1322 if ( recurse
&& !child
->Validate() )
1327 #endif // wxUSE_VALIDATORS
1332 bool wxWindowBase::TransferDataToWindow()
1334 #if wxUSE_VALIDATORS
1335 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1337 wxWindowList::compatibility_iterator node
;
1338 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1340 wxWindowBase
*child
= node
->GetData();
1341 wxValidator
*validator
= child
->GetValidator();
1342 if ( validator
&& !validator
->TransferToWindow() )
1344 wxLogWarning(_("Could not transfer data to window"));
1346 wxLog::FlushActive();
1354 if ( !child
->TransferDataToWindow() )
1356 // warning already given
1361 #endif // wxUSE_VALIDATORS
1366 bool wxWindowBase::TransferDataFromWindow()
1368 #if wxUSE_VALIDATORS
1369 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1371 wxWindowList::compatibility_iterator node
;
1372 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1374 wxWindow
*child
= node
->GetData();
1375 wxValidator
*validator
= child
->GetValidator();
1376 if ( validator
&& !validator
->TransferFromWindow() )
1378 // nop warning here because the application is supposed to give
1379 // one itself - we don't know here what might have gone wrongly
1386 if ( !child
->TransferDataFromWindow() )
1388 // warning already given
1393 #endif // wxUSE_VALIDATORS
1398 void wxWindowBase::InitDialog()
1400 wxInitDialogEvent
event(GetId());
1401 event
.SetEventObject( this );
1402 GetEventHandler()->ProcessEvent(event
);
1405 // ----------------------------------------------------------------------------
1406 // context-sensitive help support
1407 // ----------------------------------------------------------------------------
1411 // associate this help text with this window
1412 void wxWindowBase::SetHelpText(const wxString
& text
)
1414 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1417 helpProvider
->AddHelp(this, text
);
1421 // associate this help text with all windows with the same id as this
1423 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1425 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1428 helpProvider
->AddHelp(GetId(), text
);
1432 // get the help string associated with this window (may be empty)
1433 wxString
wxWindowBase::GetHelpText() const
1436 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1439 text
= helpProvider
->GetHelp(this);
1445 // show help for this window
1446 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1448 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1451 if ( helpProvider
->ShowHelp(this) )
1453 // skip the event.Skip() below
1461 #endif // wxUSE_HELP
1463 // ----------------------------------------------------------------------------
1464 // tooltipsroot.Replace("\\", "/");
1465 // ----------------------------------------------------------------------------
1469 void wxWindowBase::SetToolTip( const wxString
&tip
)
1471 // don't create the new tooltip if we already have one
1474 m_tooltip
->SetTip( tip
);
1478 SetToolTip( new wxToolTip( tip
) );
1481 // setting empty tooltip text does not remove the tooltip any more - use
1482 // SetToolTip((wxToolTip *)NULL) for this
1485 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1490 m_tooltip
= tooltip
;
1493 #endif // wxUSE_TOOLTIPS
1495 // ----------------------------------------------------------------------------
1496 // constraints and sizers
1497 // ----------------------------------------------------------------------------
1499 #if wxUSE_CONSTRAINTS
1501 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1503 if ( m_constraints
)
1505 UnsetConstraints(m_constraints
);
1506 delete m_constraints
;
1508 m_constraints
= constraints
;
1509 if ( m_constraints
)
1511 // Make sure other windows know they're part of a 'meaningful relationship'
1512 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1513 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1514 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1515 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1516 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1517 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1518 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1519 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1520 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1521 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1522 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1523 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1524 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1525 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1526 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1527 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1531 // This removes any dangling pointers to this window in other windows'
1532 // constraintsInvolvedIn lists.
1533 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1537 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1538 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1539 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1540 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1541 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1542 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1543 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1544 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1545 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1546 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1547 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1548 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1549 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1550 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1551 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1552 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1556 // Back-pointer to other windows we're involved with, so if we delete this
1557 // window, we must delete any constraints we're involved with.
1558 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1560 if ( !m_constraintsInvolvedIn
)
1561 m_constraintsInvolvedIn
= new wxWindowList
;
1562 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1563 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1566 // REMOVE back-pointer to other windows we're involved with.
1567 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1569 if ( m_constraintsInvolvedIn
)
1570 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1573 // Reset any constraints that mention this window
1574 void wxWindowBase::DeleteRelatedConstraints()
1576 if ( m_constraintsInvolvedIn
)
1578 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1581 wxWindow
*win
= node
->GetData();
1582 wxLayoutConstraints
*constr
= win
->GetConstraints();
1584 // Reset any constraints involving this window
1587 constr
->left
.ResetIfWin(this);
1588 constr
->top
.ResetIfWin(this);
1589 constr
->right
.ResetIfWin(this);
1590 constr
->bottom
.ResetIfWin(this);
1591 constr
->width
.ResetIfWin(this);
1592 constr
->height
.ResetIfWin(this);
1593 constr
->centreX
.ResetIfWin(this);
1594 constr
->centreY
.ResetIfWin(this);
1597 wxWindowList::compatibility_iterator next
= node
->GetNext();
1598 m_constraintsInvolvedIn
->Erase(node
);
1602 delete m_constraintsInvolvedIn
;
1603 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1607 #endif // wxUSE_CONSTRAINTS
1609 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1611 if ( sizer
== m_windowSizer
)
1615 delete m_windowSizer
;
1617 m_windowSizer
= sizer
;
1619 SetAutoLayout( sizer
!= NULL
);
1622 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1624 SetSizer( sizer
, deleteOld
);
1625 sizer
->SetSizeHints( (wxWindow
*) this );
1629 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1631 // adding a window to a sizer twice is going to result in fatal and
1632 // hard to debug problems later because when deleting the second
1633 // associated wxSizerItem we're going to dereference a dangling
1634 // pointer; so try to detect this as early as possible
1635 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1636 _T("Adding a window to the same sizer twice?") );
1638 m_containingSizer
= sizer
;
1640 // If there was an initial size for this window, and if a minsize has not
1641 // been set, then set the initial size as the minsize. This helps with
1642 // sizer layout when a larger than GetBestSize size is needed for
1644 if (m_initialSize
!= wxDefaultSize
&& GetMinSize() == wxDefaultSize
)
1645 SetSizeHints(m_initialSize
);
1648 #if wxUSE_CONSTRAINTS
1650 void wxWindowBase::SatisfyConstraints()
1652 wxLayoutConstraints
*constr
= GetConstraints();
1653 bool wasOk
= constr
&& constr
->AreSatisfied();
1655 ResetConstraints(); // Mark all constraints as unevaluated
1659 // if we're a top level panel (i.e. our parent is frame/dialog), our
1660 // own constraints will never be satisfied any more unless we do it
1664 while ( noChanges
> 0 )
1666 LayoutPhase1(&noChanges
);
1670 LayoutPhase2(&noChanges
);
1673 #endif // wxUSE_CONSTRAINTS
1675 bool wxWindowBase::Layout()
1677 // If there is a sizer, use it instead of the constraints
1681 GetVirtualSize(&w
, &h
);
1682 GetSizer()->SetDimension( 0, 0, w
, h
);
1684 #if wxUSE_CONSTRAINTS
1687 SatisfyConstraints(); // Find the right constraints values
1688 SetConstraintSizes(); // Recursively set the real window sizes
1695 #if wxUSE_CONSTRAINTS
1697 // first phase of the constraints evaluation: set our own constraints
1698 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1700 wxLayoutConstraints
*constr
= GetConstraints();
1702 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1705 // second phase: set the constraints for our children
1706 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1713 // Layout grand children
1719 // Do a phase of evaluating child constraints
1720 bool wxWindowBase::DoPhase(int phase
)
1722 // the list containing the children for which the constraints are already
1724 wxWindowList succeeded
;
1726 // the max number of iterations we loop before concluding that we can't set
1728 static const int maxIterations
= 500;
1730 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1734 // loop over all children setting their constraints
1735 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1737 node
= node
->GetNext() )
1739 wxWindow
*child
= node
->GetData();
1740 if ( child
->IsTopLevel() )
1742 // top level children are not inside our client area
1746 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1748 // this one is either already ok or nothing we can do about it
1752 int tempNoChanges
= 0;
1753 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1754 : child
->LayoutPhase2(&tempNoChanges
);
1755 noChanges
+= tempNoChanges
;
1759 succeeded
.Append(child
);
1765 // constraints are set
1773 void wxWindowBase::ResetConstraints()
1775 wxLayoutConstraints
*constr
= GetConstraints();
1778 constr
->left
.SetDone(false);
1779 constr
->top
.SetDone(false);
1780 constr
->right
.SetDone(false);
1781 constr
->bottom
.SetDone(false);
1782 constr
->width
.SetDone(false);
1783 constr
->height
.SetDone(false);
1784 constr
->centreX
.SetDone(false);
1785 constr
->centreY
.SetDone(false);
1788 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1791 wxWindow
*win
= node
->GetData();
1792 if ( !win
->IsTopLevel() )
1793 win
->ResetConstraints();
1794 node
= node
->GetNext();
1798 // Need to distinguish between setting the 'fake' size for windows and sizers,
1799 // and setting the real values.
1800 void wxWindowBase::SetConstraintSizes(bool recurse
)
1802 wxLayoutConstraints
*constr
= GetConstraints();
1803 if ( constr
&& constr
->AreSatisfied() )
1805 int x
= constr
->left
.GetValue();
1806 int y
= constr
->top
.GetValue();
1807 int w
= constr
->width
.GetValue();
1808 int h
= constr
->height
.GetValue();
1810 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1811 (constr
->height
.GetRelationship() != wxAsIs
) )
1813 SetSize(x
, y
, w
, h
);
1817 // If we don't want to resize this window, just move it...
1823 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1824 GetClassInfo()->GetClassName(),
1830 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1833 wxWindow
*win
= node
->GetData();
1834 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1835 win
->SetConstraintSizes();
1836 node
= node
->GetNext();
1841 // Only set the size/position of the constraint (if any)
1842 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1844 wxLayoutConstraints
*constr
= GetConstraints();
1849 constr
->left
.SetValue(x
);
1850 constr
->left
.SetDone(true);
1854 constr
->top
.SetValue(y
);
1855 constr
->top
.SetDone(true);
1859 constr
->width
.SetValue(w
);
1860 constr
->width
.SetDone(true);
1864 constr
->height
.SetValue(h
);
1865 constr
->height
.SetDone(true);
1870 void wxWindowBase::MoveConstraint(int x
, int y
)
1872 wxLayoutConstraints
*constr
= GetConstraints();
1877 constr
->left
.SetValue(x
);
1878 constr
->left
.SetDone(true);
1882 constr
->top
.SetValue(y
);
1883 constr
->top
.SetDone(true);
1888 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1890 wxLayoutConstraints
*constr
= GetConstraints();
1893 *w
= constr
->width
.GetValue();
1894 *h
= constr
->height
.GetValue();
1900 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1902 wxLayoutConstraints
*constr
= GetConstraints();
1905 *w
= constr
->width
.GetValue();
1906 *h
= constr
->height
.GetValue();
1909 GetClientSize(w
, h
);
1912 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1914 wxLayoutConstraints
*constr
= GetConstraints();
1917 *x
= constr
->left
.GetValue();
1918 *y
= constr
->top
.GetValue();
1924 #endif // wxUSE_CONSTRAINTS
1926 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1928 // don't do it for the dialogs/frames - they float independently of their
1930 if ( !IsTopLevel() )
1932 wxWindow
*parent
= GetParent();
1933 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1935 wxPoint
pt(parent
->GetClientAreaOrigin());
1942 // ----------------------------------------------------------------------------
1943 // do Update UI processing for child controls
1944 // ----------------------------------------------------------------------------
1946 void wxWindowBase::UpdateWindowUI(long flags
)
1948 wxUpdateUIEvent
event(GetId());
1949 event
.m_eventObject
= this;
1951 if ( GetEventHandler()->ProcessEvent(event
) )
1953 DoUpdateWindowUI(event
);
1956 if (flags
& wxUPDATE_UI_RECURSE
)
1958 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1961 wxWindow
* child
= (wxWindow
*) node
->GetData();
1962 child
->UpdateWindowUI(flags
);
1963 node
= node
->GetNext();
1968 // do the window-specific processing after processing the update event
1969 // TODO: take specific knowledge out of this function and
1970 // put in each control's base class. Unfortunately we don't
1971 // yet have base implementation files for wxCheckBox and wxRadioButton.
1972 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1974 if ( event
.GetSetEnabled() )
1975 Enable(event
.GetEnabled());
1978 if ( event
.GetSetText() )
1980 wxControl
*control
= wxDynamicCastThis(wxControl
);
1983 if ( event
.GetText() != control
->GetLabel() )
1984 control
->SetLabel(event
.GetText());
1987 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1990 if ( event
.GetSetChecked() )
1991 checkbox
->SetValue(event
.GetChecked());
1993 #endif // wxUSE_CHECKBOX
1996 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1999 if ( event
.GetSetChecked() )
2000 radiobtn
->SetValue(event
.GetChecked());
2002 #endif // wxUSE_RADIOBTN
2008 // call internal idle recursively
2009 // may be obsolete (wait until OnIdle scheme stabilises)
2010 void wxWindowBase::ProcessInternalIdle()
2014 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2017 wxWindow
*child
= node
->GetData();
2018 child
->ProcessInternalIdle();
2019 node
= node
->GetNext();
2024 // ----------------------------------------------------------------------------
2025 // dialog units translations
2026 // ----------------------------------------------------------------------------
2028 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2030 int charWidth
= GetCharWidth();
2031 int charHeight
= GetCharHeight();
2032 wxPoint
pt2(-1, -1);
2034 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2036 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2041 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2043 int charWidth
= GetCharWidth();
2044 int charHeight
= GetCharHeight();
2045 wxPoint
pt2(-1, -1);
2047 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2049 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2054 // ----------------------------------------------------------------------------
2056 // ----------------------------------------------------------------------------
2058 // propagate the colour change event to the subwindows
2059 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2061 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2064 // Only propagate to non-top-level windows
2065 wxWindow
*win
= node
->GetData();
2066 if ( !win
->IsTopLevel() )
2068 wxSysColourChangedEvent event2
;
2069 event
.m_eventObject
= win
;
2070 win
->GetEventHandler()->ProcessEvent(event2
);
2073 node
= node
->GetNext();
2077 // the default action is to populate dialog with data when it's created,
2078 // and nudge the UI into displaying itself correctly in case
2079 // we've turned the wxUpdateUIEvents frequency down low.
2080 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2082 TransferDataToWindow();
2084 // Update the UI at this point
2085 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2088 // process Ctrl-Alt-mclick
2089 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2092 if ( event
.ControlDown() && event
.AltDown() )
2094 // don't translate these strings
2097 #ifdef __WXUNIVERSAL__
2099 #endif // __WXUNIVERSAL__
2101 switch ( wxGetOsVersion() )
2103 case wxMOTIF_X
: port
+= _T("Motif"); break;
2105 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2106 case wxBEOS
: port
+= _T("BeOS"); break;
2110 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2116 case wxWIN386
: port
+= _T("MS Windows"); break;
2120 case wxMGL_OS2
: port
+= _T("MGL"); break;
2122 case wxOS2_PM
: port
+= _T("OS/2"); break;
2123 default: port
+= _T("unknown"); break;
2126 wxMessageBox(wxString::Format(
2128 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
2142 _T("wxWindows information"),
2143 wxICON_INFORMATION
| wxOK
,
2147 #endif // wxUSE_MSGDLG
2153 // ----------------------------------------------------------------------------
2155 // ----------------------------------------------------------------------------
2157 #if wxUSE_ACCESSIBILITY
2158 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2160 if (m_accessible
&& (accessible
!= m_accessible
))
2161 delete m_accessible
;
2162 m_accessible
= accessible
;
2164 m_accessible
->SetWindow((wxWindow
*) this);
2167 // Returns the accessible object, creating if necessary.
2168 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2171 m_accessible
= CreateAccessible();
2172 return m_accessible
;
2175 // Override to create a specific accessible object.
2176 wxAccessible
* wxWindowBase::CreateAccessible()
2178 return new wxWindowAccessible((wxWindow
*) this);
2184 // ----------------------------------------------------------------------------
2185 // list classes implementation
2186 // ----------------------------------------------------------------------------
2188 void wxWindowListNode::DeleteData()
2190 delete (wxWindow
*)GetData();
2194 // ----------------------------------------------------------------------------
2196 // ----------------------------------------------------------------------------
2198 wxBorder
wxWindowBase::GetBorder(long flags
) const
2200 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2201 if ( border
== wxBORDER_DEFAULT
)
2203 border
= GetDefaultBorder();
2209 wxBorder
wxWindowBase::GetDefaultBorder() const
2211 return wxBORDER_NONE
;
2214 // ----------------------------------------------------------------------------
2216 // ----------------------------------------------------------------------------
2218 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2220 // here we just check if the point is inside the window or not
2222 // check the top and left border first
2223 bool outside
= x
< 0 || y
< 0;
2226 // check the right and bottom borders too
2227 wxSize size
= GetSize();
2228 outside
= x
>= size
.x
|| y
>= size
.y
;
2231 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2234 // ----------------------------------------------------------------------------
2236 // ----------------------------------------------------------------------------
2238 struct WXDLLEXPORT wxWindowNext
2242 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2244 void wxWindowBase::CaptureMouse()
2246 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2248 wxWindow
*winOld
= GetCapture();
2251 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2254 wxWindowNext
*item
= new wxWindowNext
;
2256 item
->next
= ms_winCaptureNext
;
2257 ms_winCaptureNext
= item
;
2259 //else: no mouse capture to save
2264 void wxWindowBase::ReleaseMouse()
2266 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2268 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2272 if ( ms_winCaptureNext
)
2274 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2276 wxWindowNext
*item
= ms_winCaptureNext
;
2277 ms_winCaptureNext
= item
->next
;
2280 //else: stack is empty, no previous capture
2282 wxLogTrace(_T("mousecapture"),
2283 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2290 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2291 int WXUNUSED(modifiers
),
2292 int WXUNUSED(keycode
))
2298 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2304 #endif // wxUSE_HOTKEY
2306 void wxWindowBase::SendDestroyEvent()
2308 wxWindowDestroyEvent event
;
2309 event
.SetEventObject(this);
2310 event
.SetId(GetId());
2311 GetEventHandler()->ProcessEvent(event
);
2314 // ----------------------------------------------------------------------------
2316 // ----------------------------------------------------------------------------
2318 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2320 #if wxUSE_VALIDATORS
2321 // Can only use the validator of the window which
2322 // is receiving the event
2323 if ( event
.GetEventObject() == this )
2325 wxValidator
*validator
= GetValidator();
2326 if ( validator
&& validator
->ProcessEvent(event
) )
2331 #endif // wxUSE_VALIDATORS
2336 bool wxWindowBase::TryParent(wxEvent
& event
)
2338 // carry on up the parent-child hierarchy if the propgation count hasn't
2340 if ( event
.ShouldPropagate() )
2342 // honour the requests to stop propagation at this window: this is
2343 // used by the dialogs, for example, to prevent processing the events
2344 // from the dialog controls in the parent frame which rarely, if ever,
2346 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2348 wxWindow
*parent
= GetParent();
2349 if ( parent
&& !parent
->IsBeingDeleted() )
2351 wxPropagateOnce
propagateOnce(event
);
2353 return parent
->GetEventHandler()->ProcessEvent(event
);
2358 return wxEvtHandler::TryParent(event
);
2361 // ----------------------------------------------------------------------------
2363 // ----------------------------------------------------------------------------
2365 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2367 while ( win
&& !win
->IsTopLevel() )
2368 win
= win
->GetParent();
2373 #if wxUSE_ACCESSIBILITY
2374 // ----------------------------------------------------------------------------
2375 // accessible object for windows
2376 // ----------------------------------------------------------------------------
2378 // Can return either a child object, or an integer
2379 // representing the child element, starting from 1.
2380 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2382 wxASSERT( GetWindow() != NULL
);
2386 return wxACC_NOT_IMPLEMENTED
;
2389 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2390 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2392 wxASSERT( GetWindow() != NULL
);
2396 wxWindow
* win
= NULL
;
2403 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2405 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2412 rect
= win
->GetRect();
2413 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2414 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2418 return wxACC_NOT_IMPLEMENTED
;
2421 // Navigates from fromId to toId/toObject.
2422 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2423 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2425 wxASSERT( GetWindow() != NULL
);
2431 case wxNAVDIR_FIRSTCHILD
:
2433 if (GetWindow()->GetChildren().GetCount() == 0)
2435 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2436 *toObject
= childWindow
->GetOrCreateAccessible();
2440 case wxNAVDIR_LASTCHILD
:
2442 if (GetWindow()->GetChildren().GetCount() == 0)
2444 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2445 *toObject
= childWindow
->GetOrCreateAccessible();
2449 case wxNAVDIR_RIGHT
:
2453 wxWindowList::compatibility_iterator node
=
2454 wxWindowList::compatibility_iterator();
2457 // Can't navigate to sibling of this window
2458 // if we're a top-level window.
2459 if (!GetWindow()->GetParent())
2460 return wxACC_NOT_IMPLEMENTED
;
2462 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2466 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2467 node
= GetWindow()->GetChildren().Item(fromId
-1);
2470 if (node
&& node
->GetNext())
2472 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2473 *toObject
= nextWindow
->GetOrCreateAccessible();
2481 case wxNAVDIR_PREVIOUS
:
2483 wxWindowList::compatibility_iterator node
=
2484 wxWindowList::compatibility_iterator();
2487 // Can't navigate to sibling of this window
2488 // if we're a top-level window.
2489 if (!GetWindow()->GetParent())
2490 return wxACC_NOT_IMPLEMENTED
;
2492 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2496 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2497 node
= GetWindow()->GetChildren().Item(fromId
-1);
2500 if (node
&& node
->GetPrevious())
2502 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2503 *toObject
= previousWindow
->GetOrCreateAccessible();
2511 return wxACC_NOT_IMPLEMENTED
;
2514 // Gets the name of the specified object.
2515 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2517 wxASSERT( GetWindow() != NULL
);
2523 // If a child, leave wxWindows to call the function on the actual
2526 return wxACC_NOT_IMPLEMENTED
;
2528 // This will eventually be replaced by specialised
2529 // accessible classes, one for each kind of wxWindows
2530 // control or window.
2531 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2532 title
= ((wxButton
*) GetWindow())->GetLabel();
2534 title
= GetWindow()->GetName();
2536 if (!title
.IsEmpty())
2542 return wxACC_NOT_IMPLEMENTED
;
2545 // Gets the number of children.
2546 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2548 wxASSERT( GetWindow() != NULL
);
2552 *childId
= (int) GetWindow()->GetChildren().GetCount();
2556 // Gets the specified child (starting from 1).
2557 // If *child is NULL and return value is wxACC_OK,
2558 // this means that the child is a simple element and
2559 // not an accessible object.
2560 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2562 wxASSERT( GetWindow() != NULL
);
2572 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2575 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2576 *child
= childWindow
->GetOrCreateAccessible();
2583 // Gets the parent, or NULL.
2584 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2586 wxASSERT( GetWindow() != NULL
);
2590 wxWindow
* parentWindow
= GetWindow()->GetParent();
2598 *parent
= parentWindow
->GetOrCreateAccessible();
2606 // Performs the default action. childId is 0 (the action for this object)
2607 // or > 0 (the action for a child).
2608 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2609 // window (e.g. an edit control).
2610 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2612 wxASSERT( GetWindow() != NULL
);
2616 return wxACC_NOT_IMPLEMENTED
;
2619 // Gets the default action for this object (0) or > 0 (the action for a child).
2620 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2621 // string if there is no action.
2622 // The retrieved string describes the action that is performed on an object,
2623 // not what the object does as a result. For example, a toolbar button that prints
2624 // a document has a default action of "Press" rather than "Prints the current document."
2625 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2627 wxASSERT( GetWindow() != NULL
);
2631 return wxACC_NOT_IMPLEMENTED
;
2634 // Returns the description for this object or a child.
2635 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2637 wxASSERT( GetWindow() != NULL
);
2641 wxString
ht(GetWindow()->GetHelpText());
2647 return wxACC_NOT_IMPLEMENTED
;
2650 // Returns help text for this object or a child, similar to tooltip text.
2651 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2653 wxASSERT( GetWindow() != NULL
);
2657 wxString
ht(GetWindow()->GetHelpText());
2663 return wxACC_NOT_IMPLEMENTED
;
2666 // Returns the keyboard shortcut for this object or child.
2667 // Return e.g. ALT+K
2668 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2670 wxASSERT( GetWindow() != NULL
);
2674 return wxACC_NOT_IMPLEMENTED
;
2677 // Returns a role constant.
2678 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2680 wxASSERT( GetWindow() != NULL
);
2684 // If a child, leave wxWindows to call the function on the actual
2687 return wxACC_NOT_IMPLEMENTED
;
2689 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2690 return wxACC_NOT_IMPLEMENTED
;
2692 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2693 return wxACC_NOT_IMPLEMENTED
;
2696 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2697 return wxACC_NOT_IMPLEMENTED
;
2700 //*role = wxROLE_SYSTEM_CLIENT;
2701 *role
= wxROLE_SYSTEM_CLIENT
;
2705 return wxACC_NOT_IMPLEMENTED
;
2709 // Returns a state constant.
2710 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2712 wxASSERT( GetWindow() != NULL
);
2716 // If a child, leave wxWindows to call the function on the actual
2719 return wxACC_NOT_IMPLEMENTED
;
2721 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2722 return wxACC_NOT_IMPLEMENTED
;
2725 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2726 return wxACC_NOT_IMPLEMENTED
;
2729 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2730 return wxACC_NOT_IMPLEMENTED
;
2737 return wxACC_NOT_IMPLEMENTED
;
2741 // Returns a localized string representing the value for the object
2743 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2745 wxASSERT( GetWindow() != NULL
);
2749 return wxACC_NOT_IMPLEMENTED
;
2752 // Selects the object or child.
2753 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2755 wxASSERT( GetWindow() != NULL
);
2759 return wxACC_NOT_IMPLEMENTED
;
2762 // Gets the window with the keyboard focus.
2763 // If childId is 0 and child is NULL, no object in
2764 // this subhierarchy has the focus.
2765 // If this object has the focus, child should be 'this'.
2766 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2768 wxASSERT( GetWindow() != NULL
);
2772 return wxACC_NOT_IMPLEMENTED
;
2775 // Gets a variant representing the selected children
2777 // Acceptable values:
2778 // - a null variant (IsNull() returns TRUE)
2779 // - a list variant (GetType() == wxT("list")
2780 // - an integer representing the selected child element,
2781 // or 0 if this object is selected (GetType() == wxT("long")
2782 // - a "void*" pointer to a wxAccessible child object
2783 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2785 wxASSERT( GetWindow() != NULL
);
2789 return wxACC_NOT_IMPLEMENTED
;
2792 #endif // wxUSE_ACCESSIBILITY