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
);
592 else // ! has children
594 // for a generic window there is no natural best size - just use either the
595 // minimum size if there is one, or the current size
596 if ( GetMinSize().IsFullySpecified() )
603 // by default the origin is not shifted
604 wxPoint
wxWindowBase::GetClientAreaOrigin() const
606 return wxPoint(0, 0);
609 // set the min/max size of the window
610 void wxWindowBase::SetSizeHints(int minW
, int minH
,
612 int WXUNUSED(incW
), int WXUNUSED(incH
))
614 // setting min width greater than max width leads to infinite loops under
615 // X11 and generally doesn't make any sense, so don't allow it
616 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
617 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
618 _T("min width/height must be less than max width/height!") );
626 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
628 if ( m_windowVariant
!= variant
)
630 m_windowVariant
= variant
;
632 DoSetWindowVariant(variant
);
636 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
638 // adjust the font height to correspond to our new variant (notice that
639 // we're only called if something really changed)
640 wxFont font
= GetFont();
641 int size
= font
.GetPointSize();
644 case wxWINDOW_VARIANT_NORMAL
:
647 case wxWINDOW_VARIANT_SMALL
:
652 case wxWINDOW_VARIANT_MINI
:
657 case wxWINDOW_VARIANT_LARGE
:
663 wxFAIL_MSG(_T("unexpected window variant"));
667 font
.SetPointSize(size
);
671 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
674 m_minVirtualWidth
= minW
;
675 m_maxVirtualWidth
= maxW
;
676 m_minVirtualHeight
= minH
;
677 m_maxVirtualHeight
= maxH
;
680 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
682 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
683 x
= m_minVirtualWidth
;
684 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
685 x
= m_maxVirtualWidth
;
686 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
687 y
= m_minVirtualHeight
;
688 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
689 y
= m_maxVirtualHeight
;
691 m_virtualSize
= wxSize(x
, y
);
694 wxSize
wxWindowBase::DoGetVirtualSize() const
696 wxSize
s( GetClientSize() );
698 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
699 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
702 // ----------------------------------------------------------------------------
703 // show/hide/enable/disable the window
704 // ----------------------------------------------------------------------------
706 bool wxWindowBase::Show(bool show
)
708 if ( show
!= m_isShown
)
720 bool wxWindowBase::Enable(bool enable
)
722 if ( enable
!= m_isEnabled
)
724 m_isEnabled
= enable
;
733 // ----------------------------------------------------------------------------
735 // ----------------------------------------------------------------------------
737 bool wxWindowBase::IsTopLevel() const
742 // ----------------------------------------------------------------------------
743 // reparenting the window
744 // ----------------------------------------------------------------------------
746 void wxWindowBase::AddChild(wxWindowBase
*child
)
748 wxCHECK_RET( child
, wxT("can't add a NULL child") );
750 // this should never happen and it will lead to a crash later if it does
751 // because RemoveChild() will remove only one node from the children list
752 // and the other(s) one(s) will be left with dangling pointers in them
753 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
755 GetChildren().Append((wxWindow
*)child
);
756 child
->SetParent(this);
759 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
761 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
763 GetChildren().DeleteObject((wxWindow
*)child
);
764 child
->SetParent(NULL
);
767 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
769 wxWindow
*oldParent
= GetParent();
770 if ( newParent
== oldParent
)
776 // unlink this window from the existing parent.
779 oldParent
->RemoveChild(this);
783 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
786 // add it to the new one
789 newParent
->AddChild(this);
793 wxTopLevelWindows
.Append((wxWindow
*)this);
799 // ----------------------------------------------------------------------------
800 // event handler stuff
801 // ----------------------------------------------------------------------------
803 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
805 wxEvtHandler
*handlerOld
= GetEventHandler();
807 handler
->SetNextHandler(handlerOld
);
810 GetEventHandler()->SetPreviousHandler(handler
);
812 SetEventHandler(handler
);
815 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
817 wxEvtHandler
*handlerA
= GetEventHandler();
820 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
821 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
824 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
825 SetEventHandler(handlerB
);
830 handlerA
= (wxEvtHandler
*)NULL
;
837 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
839 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
841 wxEvtHandler
*handlerPrev
= NULL
,
842 *handlerCur
= GetEventHandler();
845 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
847 if ( handlerCur
== handler
)
851 handlerPrev
->SetNextHandler(handlerNext
);
855 SetEventHandler(handlerNext
);
860 handlerNext
->SetPreviousHandler ( handlerPrev
);
863 handler
->SetNextHandler(NULL
);
864 handler
->SetPreviousHandler(NULL
);
869 handlerPrev
= handlerCur
;
870 handlerCur
= handlerNext
;
873 wxFAIL_MSG( _T("where has the event handler gone?") );
878 // ----------------------------------------------------------------------------
880 // ----------------------------------------------------------------------------
882 void wxWindowBase::InheritAttributes()
884 const wxWindowBase
* const parent
= GetParent();
888 // we only inherit attributes which had been explicitly set for the parent
889 // which ensures that this only happens if the user really wants it and
890 // not by default which wouldn't make any sense in modern GUIs where the
891 // controls don't all use the same fonts (nor colours)
892 if ( parent
->m_hasFont
&& !m_hasFont
)
893 SetFont(parent
->GetFont());
895 // in addition, there is a possibility to explicitly forbid inheriting
896 // colours at each class level by overriding ShouldInheritColours()
897 if ( ShouldInheritColours() )
899 if ( parent
->m_hasFgCol
&& !m_hasFgCol
)
900 SetForegroundColour(parent
->GetForegroundColour());
902 if ( parent
->m_hasBgCol
&& !m_hasBgCol
)
903 SetBackgroundColour(parent
->GetBackgroundColour());
907 /* static */ wxVisualAttributes
908 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
910 // it is important to return valid values for all attributes from here,
911 // GetXXX() below rely on this
912 wxVisualAttributes attrs
;
913 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
914 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
915 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
920 wxColour
wxWindowBase::GetBackgroundColour() const
922 if ( !m_backgroundColour
.Ok() )
924 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
926 // get our default background colour
927 wxColour colBg
= GetDefaultAttributes().colBg
;
929 // we must return some valid colour to avoid redoing this every time
930 // and also to avoid surprizing the applications written for older
931 // wxWindows versions where GetBackgroundColour() always returned
932 // something -- so give them something even if it doesn't make sense
933 // for this window (e.g. it has a themed background)
935 colBg
= GetClassDefaultAttributes().colBg
;
937 // cache it for the next call
938 wxConstCast(this, wxWindowBase
)->m_backgroundColour
= colBg
;
941 return m_backgroundColour
;
944 wxColour
wxWindowBase::GetForegroundColour() const
946 // logic is the same as above
947 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
949 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
951 wxColour colFg
= GetDefaultAttributes().colFg
;
954 colFg
= GetClassDefaultAttributes().colFg
;
956 wxConstCast(this, wxWindowBase
)->m_foregroundColour
= colFg
;
959 return m_foregroundColour
;
962 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
964 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
967 m_backgroundColour
= colour
;
974 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
976 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
979 m_foregroundColour
= colour
;
986 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
988 // setting an invalid cursor is ok, it means that we don't have any special
990 if ( m_cursor
== cursor
)
1001 wxFont
& wxWindowBase::DoGetFont() const
1003 // logic is the same as in GetBackgroundColour()
1006 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1008 wxFont font
= GetDefaultAttributes().font
;
1010 font
= GetClassDefaultAttributes().font
;
1012 wxConstCast(this, wxWindowBase
)->m_font
= font
;
1015 // cast is here for non-const GetFont() convenience
1016 return wxConstCast(this, wxWindowBase
)->m_font
;
1019 bool wxWindowBase::SetFont(const wxFont
& font
)
1024 if ( font
== m_font
)
1039 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1041 m_hasCustomPalette
= true;
1044 // VZ: can anyone explain me what do we do here?
1045 wxWindowDC
d((wxWindow
*) this);
1049 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1051 wxWindow
*win
= (wxWindow
*)this;
1052 while ( win
&& !win
->HasCustomPalette() )
1054 win
= win
->GetParent();
1060 #endif // wxUSE_PALETTE
1063 void wxWindowBase::SetCaret(wxCaret
*caret
)
1074 wxASSERT_MSG( m_caret
->GetWindow() == this,
1075 wxT("caret should be created associated to this window") );
1078 #endif // wxUSE_CARET
1080 #if wxUSE_VALIDATORS
1081 // ----------------------------------------------------------------------------
1083 // ----------------------------------------------------------------------------
1085 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1087 if ( m_windowValidator
)
1088 delete m_windowValidator
;
1090 m_windowValidator
= (wxValidator
*)validator
.Clone();
1092 if ( m_windowValidator
)
1093 m_windowValidator
->SetWindow(this);
1095 #endif // wxUSE_VALIDATORS
1097 // ----------------------------------------------------------------------------
1098 // update region stuff
1099 // ----------------------------------------------------------------------------
1101 wxRect
wxWindowBase::GetUpdateClientRect() const
1103 wxRegion rgnUpdate
= GetUpdateRegion();
1104 rgnUpdate
.Intersect(GetClientRect());
1105 wxRect rectUpdate
= rgnUpdate
.GetBox();
1106 wxPoint ptOrigin
= GetClientAreaOrigin();
1107 rectUpdate
.x
-= ptOrigin
.x
;
1108 rectUpdate
.y
-= ptOrigin
.y
;
1113 bool wxWindowBase::IsExposed(int x
, int y
) const
1115 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1118 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1120 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1123 void wxWindowBase::ClearBackground()
1125 // wxGTK uses its own version, no need to add never used code
1127 wxClientDC
dc((wxWindow
*)this);
1128 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1129 dc
.SetBackground(brush
);
1134 // ----------------------------------------------------------------------------
1135 // find child window by id or name
1136 // ----------------------------------------------------------------------------
1138 wxWindow
*wxWindowBase::FindWindow( long id
)
1140 if ( id
== m_windowId
)
1141 return (wxWindow
*)this;
1143 wxWindowBase
*res
= (wxWindow
*)NULL
;
1144 wxWindowList::compatibility_iterator node
;
1145 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1147 wxWindowBase
*child
= node
->GetData();
1148 res
= child
->FindWindow( id
);
1151 return (wxWindow
*)res
;
1154 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1156 if ( name
== m_windowName
)
1157 return (wxWindow
*)this;
1159 wxWindowBase
*res
= (wxWindow
*)NULL
;
1160 wxWindowList::compatibility_iterator node
;
1161 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1163 wxWindow
*child
= node
->GetData();
1164 res
= child
->FindWindow(name
);
1167 return (wxWindow
*)res
;
1171 // find any window by id or name or label: If parent is non-NULL, look through
1172 // children for a label or title matching the specified string. If NULL, look
1173 // through all top-level windows.
1175 // to avoid duplicating code we reuse the same helper function but with
1176 // different comparators
1178 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1179 const wxString
& label
, long id
);
1182 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1185 return win
->GetLabel() == label
;
1189 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1192 return win
->GetName() == label
;
1196 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1199 return win
->GetId() == id
;
1202 // recursive helper for the FindWindowByXXX() functions
1204 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1205 const wxString
& label
,
1207 wxFindWindowCmp cmp
)
1211 // see if this is the one we're looking for
1212 if ( (*cmp
)(parent
, label
, id
) )
1213 return (wxWindow
*)parent
;
1215 // It wasn't, so check all its children
1216 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1218 node
= node
->GetNext() )
1220 // recursively check each child
1221 wxWindow
*win
= (wxWindow
*)node
->GetData();
1222 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1232 // helper for FindWindowByXXX()
1234 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1235 const wxString
& label
,
1237 wxFindWindowCmp cmp
)
1241 // just check parent and all its children
1242 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1245 // start at very top of wx's windows
1246 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1248 node
= node
->GetNext() )
1250 // recursively check each window & its children
1251 wxWindow
*win
= node
->GetData();
1252 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1262 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1264 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1269 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1271 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1275 // fall back to the label
1276 win
= FindWindowByLabel(title
, parent
);
1284 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1286 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1289 // ----------------------------------------------------------------------------
1290 // dialog oriented functions
1291 // ----------------------------------------------------------------------------
1293 void wxWindowBase::MakeModal(bool modal
)
1295 // Disable all other windows
1298 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1301 wxWindow
*win
= node
->GetData();
1303 win
->Enable(!modal
);
1305 node
= node
->GetNext();
1310 bool wxWindowBase::Validate()
1312 #if wxUSE_VALIDATORS
1313 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1315 wxWindowList::compatibility_iterator node
;
1316 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1318 wxWindowBase
*child
= node
->GetData();
1319 wxValidator
*validator
= child
->GetValidator();
1320 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1325 if ( recurse
&& !child
->Validate() )
1330 #endif // wxUSE_VALIDATORS
1335 bool wxWindowBase::TransferDataToWindow()
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 wxWindowBase
*child
= node
->GetData();
1344 wxValidator
*validator
= child
->GetValidator();
1345 if ( validator
&& !validator
->TransferToWindow() )
1347 wxLogWarning(_("Could not transfer data to window"));
1349 wxLog::FlushActive();
1357 if ( !child
->TransferDataToWindow() )
1359 // warning already given
1364 #endif // wxUSE_VALIDATORS
1369 bool wxWindowBase::TransferDataFromWindow()
1371 #if wxUSE_VALIDATORS
1372 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1374 wxWindowList::compatibility_iterator node
;
1375 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1377 wxWindow
*child
= node
->GetData();
1378 wxValidator
*validator
= child
->GetValidator();
1379 if ( validator
&& !validator
->TransferFromWindow() )
1381 // nop warning here because the application is supposed to give
1382 // one itself - we don't know here what might have gone wrongly
1389 if ( !child
->TransferDataFromWindow() )
1391 // warning already given
1396 #endif // wxUSE_VALIDATORS
1401 void wxWindowBase::InitDialog()
1403 wxInitDialogEvent
event(GetId());
1404 event
.SetEventObject( this );
1405 GetEventHandler()->ProcessEvent(event
);
1408 // ----------------------------------------------------------------------------
1409 // context-sensitive help support
1410 // ----------------------------------------------------------------------------
1414 // associate this help text with this window
1415 void wxWindowBase::SetHelpText(const wxString
& text
)
1417 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1420 helpProvider
->AddHelp(this, text
);
1424 // associate this help text with all windows with the same id as this
1426 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1428 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1431 helpProvider
->AddHelp(GetId(), text
);
1435 // get the help string associated with this window (may be empty)
1436 wxString
wxWindowBase::GetHelpText() const
1439 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1442 text
= helpProvider
->GetHelp(this);
1448 // show help for this window
1449 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1451 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1454 if ( helpProvider
->ShowHelp(this) )
1456 // skip the event.Skip() below
1464 #endif // wxUSE_HELP
1466 // ----------------------------------------------------------------------------
1467 // tooltipsroot.Replace("\\", "/");
1468 // ----------------------------------------------------------------------------
1472 void wxWindowBase::SetToolTip( const wxString
&tip
)
1474 // don't create the new tooltip if we already have one
1477 m_tooltip
->SetTip( tip
);
1481 SetToolTip( new wxToolTip( tip
) );
1484 // setting empty tooltip text does not remove the tooltip any more - use
1485 // SetToolTip((wxToolTip *)NULL) for this
1488 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1493 m_tooltip
= tooltip
;
1496 #endif // wxUSE_TOOLTIPS
1498 // ----------------------------------------------------------------------------
1499 // constraints and sizers
1500 // ----------------------------------------------------------------------------
1502 #if wxUSE_CONSTRAINTS
1504 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1506 if ( m_constraints
)
1508 UnsetConstraints(m_constraints
);
1509 delete m_constraints
;
1511 m_constraints
= constraints
;
1512 if ( m_constraints
)
1514 // Make sure other windows know they're part of a 'meaningful relationship'
1515 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1516 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1517 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1518 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1519 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1520 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1521 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1522 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1523 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1524 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1525 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1526 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1527 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1528 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1529 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1530 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1534 // This removes any dangling pointers to this window in other windows'
1535 // constraintsInvolvedIn lists.
1536 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1540 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1541 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1542 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1543 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1544 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1545 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1546 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1547 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1548 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1549 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1550 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1551 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1552 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1553 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1554 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1555 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1559 // Back-pointer to other windows we're involved with, so if we delete this
1560 // window, we must delete any constraints we're involved with.
1561 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1563 if ( !m_constraintsInvolvedIn
)
1564 m_constraintsInvolvedIn
= new wxWindowList
;
1565 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1566 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1569 // REMOVE back-pointer to other windows we're involved with.
1570 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1572 if ( m_constraintsInvolvedIn
)
1573 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1576 // Reset any constraints that mention this window
1577 void wxWindowBase::DeleteRelatedConstraints()
1579 if ( m_constraintsInvolvedIn
)
1581 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1584 wxWindow
*win
= node
->GetData();
1585 wxLayoutConstraints
*constr
= win
->GetConstraints();
1587 // Reset any constraints involving this window
1590 constr
->left
.ResetIfWin(this);
1591 constr
->top
.ResetIfWin(this);
1592 constr
->right
.ResetIfWin(this);
1593 constr
->bottom
.ResetIfWin(this);
1594 constr
->width
.ResetIfWin(this);
1595 constr
->height
.ResetIfWin(this);
1596 constr
->centreX
.ResetIfWin(this);
1597 constr
->centreY
.ResetIfWin(this);
1600 wxWindowList::compatibility_iterator next
= node
->GetNext();
1601 m_constraintsInvolvedIn
->Erase(node
);
1605 delete m_constraintsInvolvedIn
;
1606 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1610 #endif // wxUSE_CONSTRAINTS
1612 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1614 if ( sizer
== m_windowSizer
)
1618 delete m_windowSizer
;
1620 m_windowSizer
= sizer
;
1622 SetAutoLayout( sizer
!= NULL
);
1625 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1627 SetSizer( sizer
, deleteOld
);
1628 sizer
->SetSizeHints( (wxWindow
*) this );
1632 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1634 // adding a window to a sizer twice is going to result in fatal and
1635 // hard to debug problems later because when deleting the second
1636 // associated wxSizerItem we're going to dereference a dangling
1637 // pointer; so try to detect this as early as possible
1638 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1639 _T("Adding a window to the same sizer twice?") );
1641 m_containingSizer
= sizer
;
1643 // If there was an initial size for this window, and if a minsize has not
1644 // been set, then set the initial size as the minsize. This helps with
1645 // sizer layout when a larger than GetBestSize size is needed for
1647 if (m_initialSize
!= wxDefaultSize
&& GetMinSize() == wxDefaultSize
)
1648 SetSizeHints(m_initialSize
);
1651 #if wxUSE_CONSTRAINTS
1653 void wxWindowBase::SatisfyConstraints()
1655 wxLayoutConstraints
*constr
= GetConstraints();
1656 bool wasOk
= constr
&& constr
->AreSatisfied();
1658 ResetConstraints(); // Mark all constraints as unevaluated
1662 // if we're a top level panel (i.e. our parent is frame/dialog), our
1663 // own constraints will never be satisfied any more unless we do it
1667 while ( noChanges
> 0 )
1669 LayoutPhase1(&noChanges
);
1673 LayoutPhase2(&noChanges
);
1676 #endif // wxUSE_CONSTRAINTS
1678 bool wxWindowBase::Layout()
1680 // If there is a sizer, use it instead of the constraints
1684 GetVirtualSize(&w
, &h
);
1685 GetSizer()->SetDimension( 0, 0, w
, h
);
1687 #if wxUSE_CONSTRAINTS
1690 SatisfyConstraints(); // Find the right constraints values
1691 SetConstraintSizes(); // Recursively set the real window sizes
1698 #if wxUSE_CONSTRAINTS
1700 // first phase of the constraints evaluation: set our own constraints
1701 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1703 wxLayoutConstraints
*constr
= GetConstraints();
1705 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1708 // second phase: set the constraints for our children
1709 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1716 // Layout grand children
1722 // Do a phase of evaluating child constraints
1723 bool wxWindowBase::DoPhase(int phase
)
1725 // the list containing the children for which the constraints are already
1727 wxWindowList succeeded
;
1729 // the max number of iterations we loop before concluding that we can't set
1731 static const int maxIterations
= 500;
1733 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1737 // loop over all children setting their constraints
1738 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1740 node
= node
->GetNext() )
1742 wxWindow
*child
= node
->GetData();
1743 if ( child
->IsTopLevel() )
1745 // top level children are not inside our client area
1749 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1751 // this one is either already ok or nothing we can do about it
1755 int tempNoChanges
= 0;
1756 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1757 : child
->LayoutPhase2(&tempNoChanges
);
1758 noChanges
+= tempNoChanges
;
1762 succeeded
.Append(child
);
1768 // constraints are set
1776 void wxWindowBase::ResetConstraints()
1778 wxLayoutConstraints
*constr
= GetConstraints();
1781 constr
->left
.SetDone(false);
1782 constr
->top
.SetDone(false);
1783 constr
->right
.SetDone(false);
1784 constr
->bottom
.SetDone(false);
1785 constr
->width
.SetDone(false);
1786 constr
->height
.SetDone(false);
1787 constr
->centreX
.SetDone(false);
1788 constr
->centreY
.SetDone(false);
1791 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1794 wxWindow
*win
= node
->GetData();
1795 if ( !win
->IsTopLevel() )
1796 win
->ResetConstraints();
1797 node
= node
->GetNext();
1801 // Need to distinguish between setting the 'fake' size for windows and sizers,
1802 // and setting the real values.
1803 void wxWindowBase::SetConstraintSizes(bool recurse
)
1805 wxLayoutConstraints
*constr
= GetConstraints();
1806 if ( constr
&& constr
->AreSatisfied() )
1808 int x
= constr
->left
.GetValue();
1809 int y
= constr
->top
.GetValue();
1810 int w
= constr
->width
.GetValue();
1811 int h
= constr
->height
.GetValue();
1813 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1814 (constr
->height
.GetRelationship() != wxAsIs
) )
1816 SetSize(x
, y
, w
, h
);
1820 // If we don't want to resize this window, just move it...
1826 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1827 GetClassInfo()->GetClassName(),
1833 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1836 wxWindow
*win
= node
->GetData();
1837 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1838 win
->SetConstraintSizes();
1839 node
= node
->GetNext();
1844 // Only set the size/position of the constraint (if any)
1845 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1847 wxLayoutConstraints
*constr
= GetConstraints();
1852 constr
->left
.SetValue(x
);
1853 constr
->left
.SetDone(true);
1857 constr
->top
.SetValue(y
);
1858 constr
->top
.SetDone(true);
1862 constr
->width
.SetValue(w
);
1863 constr
->width
.SetDone(true);
1867 constr
->height
.SetValue(h
);
1868 constr
->height
.SetDone(true);
1873 void wxWindowBase::MoveConstraint(int x
, int y
)
1875 wxLayoutConstraints
*constr
= GetConstraints();
1880 constr
->left
.SetValue(x
);
1881 constr
->left
.SetDone(true);
1885 constr
->top
.SetValue(y
);
1886 constr
->top
.SetDone(true);
1891 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1893 wxLayoutConstraints
*constr
= GetConstraints();
1896 *w
= constr
->width
.GetValue();
1897 *h
= constr
->height
.GetValue();
1903 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1905 wxLayoutConstraints
*constr
= GetConstraints();
1908 *w
= constr
->width
.GetValue();
1909 *h
= constr
->height
.GetValue();
1912 GetClientSize(w
, h
);
1915 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1917 wxLayoutConstraints
*constr
= GetConstraints();
1920 *x
= constr
->left
.GetValue();
1921 *y
= constr
->top
.GetValue();
1927 #endif // wxUSE_CONSTRAINTS
1929 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1931 // don't do it for the dialogs/frames - they float independently of their
1933 if ( !IsTopLevel() )
1935 wxWindow
*parent
= GetParent();
1936 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1938 wxPoint
pt(parent
->GetClientAreaOrigin());
1945 // ----------------------------------------------------------------------------
1946 // do Update UI processing for child controls
1947 // ----------------------------------------------------------------------------
1949 void wxWindowBase::UpdateWindowUI(long flags
)
1951 wxUpdateUIEvent
event(GetId());
1952 event
.m_eventObject
= this;
1954 if ( GetEventHandler()->ProcessEvent(event
) )
1956 DoUpdateWindowUI(event
);
1959 if (flags
& wxUPDATE_UI_RECURSE
)
1961 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1964 wxWindow
* child
= (wxWindow
*) node
->GetData();
1965 child
->UpdateWindowUI(flags
);
1966 node
= node
->GetNext();
1971 // do the window-specific processing after processing the update event
1972 // TODO: take specific knowledge out of this function and
1973 // put in each control's base class. Unfortunately we don't
1974 // yet have base implementation files for wxCheckBox and wxRadioButton.
1975 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1977 if ( event
.GetSetEnabled() )
1978 Enable(event
.GetEnabled());
1981 if ( event
.GetSetText() )
1983 wxControl
*control
= wxDynamicCastThis(wxControl
);
1986 if ( event
.GetText() != control
->GetLabel() )
1987 control
->SetLabel(event
.GetText());
1990 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1993 if ( event
.GetSetChecked() )
1994 checkbox
->SetValue(event
.GetChecked());
1996 #endif // wxUSE_CHECKBOX
1999 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
2002 if ( event
.GetSetChecked() )
2003 radiobtn
->SetValue(event
.GetChecked());
2005 #endif // wxUSE_RADIOBTN
2011 // call internal idle recursively
2012 // may be obsolete (wait until OnIdle scheme stabilises)
2013 void wxWindowBase::ProcessInternalIdle()
2017 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2020 wxWindow
*child
= node
->GetData();
2021 child
->ProcessInternalIdle();
2022 node
= node
->GetNext();
2027 // ----------------------------------------------------------------------------
2028 // dialog units translations
2029 // ----------------------------------------------------------------------------
2031 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2033 int charWidth
= GetCharWidth();
2034 int charHeight
= GetCharHeight();
2035 wxPoint
pt2(-1, -1);
2037 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2039 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2044 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2046 int charWidth
= GetCharWidth();
2047 int charHeight
= GetCharHeight();
2048 wxPoint
pt2(-1, -1);
2050 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2052 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2057 // ----------------------------------------------------------------------------
2059 // ----------------------------------------------------------------------------
2061 // propagate the colour change event to the subwindows
2062 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2064 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2067 // Only propagate to non-top-level windows
2068 wxWindow
*win
= node
->GetData();
2069 if ( !win
->IsTopLevel() )
2071 wxSysColourChangedEvent event2
;
2072 event
.m_eventObject
= win
;
2073 win
->GetEventHandler()->ProcessEvent(event2
);
2076 node
= node
->GetNext();
2080 // the default action is to populate dialog with data when it's created,
2081 // and nudge the UI into displaying itself correctly in case
2082 // we've turned the wxUpdateUIEvents frequency down low.
2083 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2085 TransferDataToWindow();
2087 // Update the UI at this point
2088 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2091 // process Ctrl-Alt-mclick
2092 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2095 if ( event
.ControlDown() && event
.AltDown() )
2097 // don't translate these strings
2100 #ifdef __WXUNIVERSAL__
2102 #endif // __WXUNIVERSAL__
2104 switch ( wxGetOsVersion() )
2106 case wxMOTIF_X
: port
+= _T("Motif"); break;
2108 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2109 case wxBEOS
: port
+= _T("BeOS"); break;
2113 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2119 case wxWIN386
: port
+= _T("MS Windows"); break;
2123 case wxMGL_OS2
: port
+= _T("MGL"); break;
2125 case wxOS2_PM
: port
+= _T("OS/2"); break;
2126 default: port
+= _T("unknown"); break;
2129 wxMessageBox(wxString::Format(
2131 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
2145 _T("wxWindows information"),
2146 wxICON_INFORMATION
| wxOK
,
2150 #endif // wxUSE_MSGDLG
2156 // ----------------------------------------------------------------------------
2158 // ----------------------------------------------------------------------------
2160 #if wxUSE_ACCESSIBILITY
2161 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2163 if (m_accessible
&& (accessible
!= m_accessible
))
2164 delete m_accessible
;
2165 m_accessible
= accessible
;
2167 m_accessible
->SetWindow((wxWindow
*) this);
2170 // Returns the accessible object, creating if necessary.
2171 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2174 m_accessible
= CreateAccessible();
2175 return m_accessible
;
2178 // Override to create a specific accessible object.
2179 wxAccessible
* wxWindowBase::CreateAccessible()
2181 return new wxWindowAccessible((wxWindow
*) this);
2187 // ----------------------------------------------------------------------------
2188 // list classes implementation
2189 // ----------------------------------------------------------------------------
2191 void wxWindowListNode::DeleteData()
2193 delete (wxWindow
*)GetData();
2197 // ----------------------------------------------------------------------------
2199 // ----------------------------------------------------------------------------
2201 wxBorder
wxWindowBase::GetBorder(long flags
) const
2203 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2204 if ( border
== wxBORDER_DEFAULT
)
2206 border
= GetDefaultBorder();
2212 wxBorder
wxWindowBase::GetDefaultBorder() const
2214 return wxBORDER_NONE
;
2217 // ----------------------------------------------------------------------------
2219 // ----------------------------------------------------------------------------
2221 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2223 // here we just check if the point is inside the window or not
2225 // check the top and left border first
2226 bool outside
= x
< 0 || y
< 0;
2229 // check the right and bottom borders too
2230 wxSize size
= GetSize();
2231 outside
= x
>= size
.x
|| y
>= size
.y
;
2234 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2237 // ----------------------------------------------------------------------------
2239 // ----------------------------------------------------------------------------
2241 struct WXDLLEXPORT wxWindowNext
2245 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2247 void wxWindowBase::CaptureMouse()
2249 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2251 wxWindow
*winOld
= GetCapture();
2254 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2257 wxWindowNext
*item
= new wxWindowNext
;
2259 item
->next
= ms_winCaptureNext
;
2260 ms_winCaptureNext
= item
;
2262 //else: no mouse capture to save
2267 void wxWindowBase::ReleaseMouse()
2269 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2271 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2275 if ( ms_winCaptureNext
)
2277 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2279 wxWindowNext
*item
= ms_winCaptureNext
;
2280 ms_winCaptureNext
= item
->next
;
2283 //else: stack is empty, no previous capture
2285 wxLogTrace(_T("mousecapture"),
2286 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2293 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2294 int WXUNUSED(modifiers
),
2295 int WXUNUSED(keycode
))
2301 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2307 #endif // wxUSE_HOTKEY
2309 void wxWindowBase::SendDestroyEvent()
2311 wxWindowDestroyEvent event
;
2312 event
.SetEventObject(this);
2313 event
.SetId(GetId());
2314 GetEventHandler()->ProcessEvent(event
);
2317 // ----------------------------------------------------------------------------
2319 // ----------------------------------------------------------------------------
2321 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2323 #if wxUSE_VALIDATORS
2324 // Can only use the validator of the window which
2325 // is receiving the event
2326 if ( event
.GetEventObject() == this )
2328 wxValidator
*validator
= GetValidator();
2329 if ( validator
&& validator
->ProcessEvent(event
) )
2334 #endif // wxUSE_VALIDATORS
2339 bool wxWindowBase::TryParent(wxEvent
& event
)
2341 // carry on up the parent-child hierarchy if the propgation count hasn't
2343 if ( event
.ShouldPropagate() )
2345 // honour the requests to stop propagation at this window: this is
2346 // used by the dialogs, for example, to prevent processing the events
2347 // from the dialog controls in the parent frame which rarely, if ever,
2349 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2351 wxWindow
*parent
= GetParent();
2352 if ( parent
&& !parent
->IsBeingDeleted() )
2354 wxPropagateOnce
propagateOnce(event
);
2356 return parent
->GetEventHandler()->ProcessEvent(event
);
2361 return wxEvtHandler::TryParent(event
);
2364 // ----------------------------------------------------------------------------
2366 // ----------------------------------------------------------------------------
2368 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2370 while ( win
&& !win
->IsTopLevel() )
2371 win
= win
->GetParent();
2376 #if wxUSE_ACCESSIBILITY
2377 // ----------------------------------------------------------------------------
2378 // accessible object for windows
2379 // ----------------------------------------------------------------------------
2381 // Can return either a child object, or an integer
2382 // representing the child element, starting from 1.
2383 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2385 wxASSERT( GetWindow() != NULL
);
2389 return wxACC_NOT_IMPLEMENTED
;
2392 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2393 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2395 wxASSERT( GetWindow() != NULL
);
2399 wxWindow
* win
= NULL
;
2406 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2408 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2415 rect
= win
->GetRect();
2416 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2417 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2421 return wxACC_NOT_IMPLEMENTED
;
2424 // Navigates from fromId to toId/toObject.
2425 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2426 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2428 wxASSERT( GetWindow() != NULL
);
2434 case wxNAVDIR_FIRSTCHILD
:
2436 if (GetWindow()->GetChildren().GetCount() == 0)
2438 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2439 *toObject
= childWindow
->GetOrCreateAccessible();
2443 case wxNAVDIR_LASTCHILD
:
2445 if (GetWindow()->GetChildren().GetCount() == 0)
2447 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2448 *toObject
= childWindow
->GetOrCreateAccessible();
2452 case wxNAVDIR_RIGHT
:
2456 wxWindowList::compatibility_iterator node
=
2457 wxWindowList::compatibility_iterator();
2460 // Can't navigate to sibling of this window
2461 // if we're a top-level window.
2462 if (!GetWindow()->GetParent())
2463 return wxACC_NOT_IMPLEMENTED
;
2465 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2469 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2470 node
= GetWindow()->GetChildren().Item(fromId
-1);
2473 if (node
&& node
->GetNext())
2475 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2476 *toObject
= nextWindow
->GetOrCreateAccessible();
2484 case wxNAVDIR_PREVIOUS
:
2486 wxWindowList::compatibility_iterator node
=
2487 wxWindowList::compatibility_iterator();
2490 // Can't navigate to sibling of this window
2491 // if we're a top-level window.
2492 if (!GetWindow()->GetParent())
2493 return wxACC_NOT_IMPLEMENTED
;
2495 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2499 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2500 node
= GetWindow()->GetChildren().Item(fromId
-1);
2503 if (node
&& node
->GetPrevious())
2505 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2506 *toObject
= previousWindow
->GetOrCreateAccessible();
2514 return wxACC_NOT_IMPLEMENTED
;
2517 // Gets the name of the specified object.
2518 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2520 wxASSERT( GetWindow() != NULL
);
2526 // If a child, leave wxWindows to call the function on the actual
2529 return wxACC_NOT_IMPLEMENTED
;
2531 // This will eventually be replaced by specialised
2532 // accessible classes, one for each kind of wxWindows
2533 // control or window.
2534 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2535 title
= ((wxButton
*) GetWindow())->GetLabel();
2537 title
= GetWindow()->GetName();
2539 if (!title
.IsEmpty())
2545 return wxACC_NOT_IMPLEMENTED
;
2548 // Gets the number of children.
2549 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2551 wxASSERT( GetWindow() != NULL
);
2555 *childId
= (int) GetWindow()->GetChildren().GetCount();
2559 // Gets the specified child (starting from 1).
2560 // If *child is NULL and return value is wxACC_OK,
2561 // this means that the child is a simple element and
2562 // not an accessible object.
2563 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2565 wxASSERT( GetWindow() != NULL
);
2575 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2578 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2579 *child
= childWindow
->GetOrCreateAccessible();
2586 // Gets the parent, or NULL.
2587 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2589 wxASSERT( GetWindow() != NULL
);
2593 wxWindow
* parentWindow
= GetWindow()->GetParent();
2601 *parent
= parentWindow
->GetOrCreateAccessible();
2609 // Performs the default action. childId is 0 (the action for this object)
2610 // or > 0 (the action for a child).
2611 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2612 // window (e.g. an edit control).
2613 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2615 wxASSERT( GetWindow() != NULL
);
2619 return wxACC_NOT_IMPLEMENTED
;
2622 // Gets the default action for this object (0) or > 0 (the action for a child).
2623 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2624 // string if there is no action.
2625 // The retrieved string describes the action that is performed on an object,
2626 // not what the object does as a result. For example, a toolbar button that prints
2627 // a document has a default action of "Press" rather than "Prints the current document."
2628 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2630 wxASSERT( GetWindow() != NULL
);
2634 return wxACC_NOT_IMPLEMENTED
;
2637 // Returns the description for this object or a child.
2638 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2640 wxASSERT( GetWindow() != NULL
);
2644 wxString
ht(GetWindow()->GetHelpText());
2650 return wxACC_NOT_IMPLEMENTED
;
2653 // Returns help text for this object or a child, similar to tooltip text.
2654 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2656 wxASSERT( GetWindow() != NULL
);
2660 wxString
ht(GetWindow()->GetHelpText());
2666 return wxACC_NOT_IMPLEMENTED
;
2669 // Returns the keyboard shortcut for this object or child.
2670 // Return e.g. ALT+K
2671 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2673 wxASSERT( GetWindow() != NULL
);
2677 return wxACC_NOT_IMPLEMENTED
;
2680 // Returns a role constant.
2681 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2683 wxASSERT( GetWindow() != NULL
);
2687 // If a child, leave wxWindows to call the function on the actual
2690 return wxACC_NOT_IMPLEMENTED
;
2692 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2693 return wxACC_NOT_IMPLEMENTED
;
2695 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2696 return wxACC_NOT_IMPLEMENTED
;
2699 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2700 return wxACC_NOT_IMPLEMENTED
;
2703 //*role = wxROLE_SYSTEM_CLIENT;
2704 *role
= wxROLE_SYSTEM_CLIENT
;
2708 return wxACC_NOT_IMPLEMENTED
;
2712 // Returns a state constant.
2713 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2715 wxASSERT( GetWindow() != NULL
);
2719 // If a child, leave wxWindows to call the function on the actual
2722 return wxACC_NOT_IMPLEMENTED
;
2724 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2725 return wxACC_NOT_IMPLEMENTED
;
2728 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2729 return wxACC_NOT_IMPLEMENTED
;
2732 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2733 return wxACC_NOT_IMPLEMENTED
;
2740 return wxACC_NOT_IMPLEMENTED
;
2744 // Returns a localized string representing the value for the object
2746 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2748 wxASSERT( GetWindow() != NULL
);
2752 return wxACC_NOT_IMPLEMENTED
;
2755 // Selects the object or child.
2756 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2758 wxASSERT( GetWindow() != NULL
);
2762 return wxACC_NOT_IMPLEMENTED
;
2765 // Gets the window with the keyboard focus.
2766 // If childId is 0 and child is NULL, no object in
2767 // this subhierarchy has the focus.
2768 // If this object has the focus, child should be 'this'.
2769 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2771 wxASSERT( GetWindow() != NULL
);
2775 return wxACC_NOT_IMPLEMENTED
;
2778 // Gets a variant representing the selected children
2780 // Acceptable values:
2781 // - a null variant (IsNull() returns TRUE)
2782 // - a list variant (GetType() == wxT("list")
2783 // - an integer representing the selected child element,
2784 // or 0 if this object is selected (GetType() == wxT("long")
2785 // - a "void*" pointer to a wxAccessible child object
2786 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2788 wxASSERT( GetWindow() != NULL
);
2792 return wxACC_NOT_IMPLEMENTED
;
2795 #endif // wxUSE_ACCESSIBILITY