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()
113 : m_bestSize(wxDefaultSize
)
115 // no window yet, no parent nor children
116 m_parent
= (wxWindow
*)NULL
;
117 m_windowId
= wxID_ANY
;
119 // no constraints on the minimal window size
125 // window are created enabled and visible by default
129 // the default event handler is just this window
130 m_eventHandler
= this;
134 m_windowValidator
= (wxValidator
*) NULL
;
135 #endif // wxUSE_VALIDATORS
137 // the colours/fonts are default for now, so leave m_font,
138 // m_backgroundColour and m_foregroundColour uninitialized and set those
147 #if wxUSE_CONSTRAINTS
148 // no constraints whatsoever
149 m_constraints
= (wxLayoutConstraints
*) NULL
;
150 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
151 #endif // wxUSE_CONSTRAINTS
153 m_windowSizer
= (wxSizer
*) NULL
;
154 m_containingSizer
= (wxSizer
*) NULL
;
155 m_autoLayout
= false;
157 #if wxUSE_DRAG_AND_DROP
158 m_dropTarget
= (wxDropTarget
*)NULL
;
159 #endif // wxUSE_DRAG_AND_DROP
162 m_tooltip
= (wxToolTip
*)NULL
;
163 #endif // wxUSE_TOOLTIPS
166 m_caret
= (wxCaret
*)NULL
;
167 #endif // wxUSE_CARET
170 m_hasCustomPalette
= false;
171 #endif // wxUSE_PALETTE
173 #if wxUSE_ACCESSIBILITY
177 m_virtualSize
= wxDefaultSize
;
182 m_maxVirtualHeight
= -1;
184 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
186 // Whether we're using the current theme for this window (wxGTK only for now)
187 m_themeEnabled
= false;
189 // VZ: this one shouldn't exist...
190 m_isBeingDeleted
= false;
193 // common part of window creation process
194 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
196 const wxPoint
& WXUNUSED(pos
),
199 const wxValidator
& wxVALIDATOR_PARAM(validator
),
200 const wxString
& name
)
203 // wxGTK doesn't allow to create controls with static box as the parent so
204 // this will result in a crash when the program is ported to wxGTK so warn
207 // if you get this assert, the correct solution is to create the controls
208 // as siblings of the static box
209 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
210 _T("wxStaticBox can't be used as a window parent!") );
211 #endif // wxUSE_STATBOX
213 // ids are limited to 16 bits under MSW so if you care about portability,
214 // it's not a good idea to use ids out of this range (and negative ids are
215 // reserved for wxWindows own usage)
216 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
217 _T("invalid id value") );
219 // generate a new id if the user doesn't care about it
220 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
223 SetWindowStyleFlag(style
);
226 // Set the minsize to be the size passed to the ctor (if any) for
227 // non-TLWs. This is so items used in a sizer will use this explicitly
228 // set size for layout, instead of falling back the (probably smaller)
235 SetValidator(validator
);
236 #endif // wxUSE_VALIDATORS
238 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
239 // have it too - like this it's possible to set it only in the top level
240 // dialog/frame and all children will inherit it by defult
241 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
243 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
249 // ----------------------------------------------------------------------------
251 // ----------------------------------------------------------------------------
254 wxWindowBase::~wxWindowBase()
256 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
258 // FIXME if these 2 cases result from programming errors in the user code
259 // we should probably assert here instead of silently fixing them
261 // Just in case the window has been Closed, but we're then deleting
262 // immediately: don't leave dangling pointers.
263 wxPendingDelete
.DeleteObject(this);
265 // Just in case we've loaded a top-level window via LoadNativeDialog but
266 // we weren't a dialog class
267 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
269 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
271 // reset the dangling pointer our parent window may keep to us
274 if ( m_parent
->GetDefaultItem() == this )
276 m_parent
->SetDefaultItem(NULL
);
279 m_parent
->RemoveChild(this);
284 #endif // wxUSE_CARET
287 delete m_windowValidator
;
288 #endif // wxUSE_VALIDATORS
290 #if wxUSE_CONSTRAINTS
291 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
292 // at deleted windows as they delete themselves.
293 DeleteRelatedConstraints();
297 // This removes any dangling pointers to this window in other windows'
298 // constraintsInvolvedIn lists.
299 UnsetConstraints(m_constraints
);
300 delete m_constraints
;
301 m_constraints
= NULL
;
303 #endif // wxUSE_CONSTRAINTS
305 if ( m_containingSizer
)
306 m_containingSizer
->Detach( (wxWindow
*)this );
308 delete m_windowSizer
;
310 #if wxUSE_DRAG_AND_DROP
312 #endif // wxUSE_DRAG_AND_DROP
316 #endif // wxUSE_TOOLTIPS
318 #if wxUSE_ACCESSIBILITY
323 bool wxWindowBase::Destroy()
330 bool wxWindowBase::Close(bool force
)
332 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
333 event
.SetEventObject(this);
334 event
.SetCanVeto(!force
);
336 // return false if window wasn't closed because the application vetoed the
338 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
341 bool wxWindowBase::DestroyChildren()
343 wxWindowList::compatibility_iterator node
;
346 // we iterate until the list becomes empty
347 node
= GetChildren().GetFirst();
351 wxWindow
*child
= node
->GetData();
353 // note that we really want to call delete and not ->Destroy() here
354 // because we want to delete the child immediately, before we are
355 // deleted, and delayed deletion would result in problems as our (top
356 // level) child could outlive its parent
359 wxASSERT_MSG( !GetChildren().Find(child
),
360 wxT("child didn't remove itself using RemoveChild()") );
366 // ----------------------------------------------------------------------------
367 // size/position related methods
368 // ----------------------------------------------------------------------------
370 // centre the window with respect to its parent in either (or both) directions
371 void wxWindowBase::Centre(int direction
)
373 // the position/size of the parent window or of the entire screen
375 int widthParent
, heightParent
;
377 wxWindow
*parent
= NULL
;
379 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
381 // find the parent to centre this window on: it should be the
382 // immediate parent for the controls but the top level parent for the
383 // top level windows (like dialogs)
384 parent
= GetParent();
387 while ( parent
&& !parent
->IsTopLevel() )
389 parent
= parent
->GetParent();
393 // there is no wxTopLevelWindow under wxMotif yet
395 // we shouldn't center the dialog on the iconized window: under
396 // Windows, for example, this places it completely off the screen
399 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
400 if ( winTop
&& winTop
->IsIconized() )
405 #endif // __WXMOTIF__
407 // did we find the parent?
411 direction
|= wxCENTRE_ON_SCREEN
;
415 if ( direction
& wxCENTRE_ON_SCREEN
)
417 // centre with respect to the whole screen
418 wxDisplaySize(&widthParent
, &heightParent
);
424 // centre on the parent
425 parent
->GetSize(&widthParent
, &heightParent
);
427 // adjust to the parents position
428 posParent
= parent
->GetPosition();
432 // centre inside the parents client rectangle
433 parent
->GetClientSize(&widthParent
, &heightParent
);
438 GetSize(&width
, &height
);
443 if ( direction
& wxHORIZONTAL
)
444 xNew
= (widthParent
- width
)/2;
446 if ( direction
& wxVERTICAL
)
447 yNew
= (heightParent
- height
)/2;
452 // Base size of the visible dimensions of the display
453 // to take into account the taskbar
454 wxRect rect
= wxGetClientDisplayRect();
455 wxSize
size (rect
.width
,rect
.height
);
457 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
458 // but it may mean that the window is placed on other than the main
459 // display. Therefore we only make sure centered window is on the main display
460 // if the parent is at least partially present here.
461 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
465 else if (xNew
+width
> size
.x
)
466 xNew
= size
.x
-width
-1;
468 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
470 if (yNew
+height
> size
.y
)
471 yNew
= size
.y
-height
-1;
473 // Make certain that the title bar is initially visible
474 // always, even if this would push the bottom of the
475 // dialog of the visible area of the display
480 // move the window to this position (keeping the old size but using
481 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
482 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
485 // fits the window around the children
486 void wxWindowBase::Fit()
488 if ( GetChildren().GetCount() > 0 )
490 SetClientSize(DoGetBestSize());
492 //else: do nothing if we have no children
495 // fits virtual size (ie. scrolled area etc.) around children
496 void wxWindowBase::FitInside()
498 if ( GetChildren().GetCount() > 0 )
500 SetVirtualSize( GetBestVirtualSize() );
504 // return the size best suited for the current window
505 wxSize
wxWindowBase::DoGetBestSize() const
509 return m_windowSizer
->GetMinSize();
511 #if wxUSE_CONSTRAINTS
512 else if ( m_constraints
)
514 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
516 // our minimal acceptable size is such that all our windows fit inside
520 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
522 node
= node
->GetNext() )
524 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
527 // it's not normal that we have an unconstrained child, but
528 // what can we do about it?
532 int x
= c
->right
.GetValue(),
533 y
= c
->bottom
.GetValue();
541 // TODO: we must calculate the overlaps somehow, otherwise we
542 // will never return a size bigger than the current one :-(
545 return wxSize(maxX
, maxY
);
547 #endif // wxUSE_CONSTRAINTS
548 else if ( GetChildren().GetCount() > 0 )
550 // our minimal acceptable size is such that all our windows fit inside
554 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
556 node
= node
->GetNext() )
558 wxWindow
*win
= node
->GetData();
559 if ( win
->IsTopLevel()
561 || wxDynamicCast(win
, wxStatusBar
)
562 #endif // wxUSE_STATUSBAR
565 // dialogs and frames lie in different top level windows -
566 // don't deal with them here; as for the status bars, they
567 // don't lie in the client area at all
572 win
->GetPosition(&wx
, &wy
);
574 // if the window hadn't been positioned yet, assume that it is in
581 win
->GetSize(&ww
, &wh
);
582 if ( wx
+ ww
> maxX
)
584 if ( wy
+ wh
> maxY
)
588 // for compatibility with the old versions and because it really looks
589 // slightly more pretty like this, add a pad
593 return wxSize(maxX
, maxY
);
597 // Windows which don't implement DoGetBestSize and aren't parents.
598 // This emulates the behavior of a wxSizer without wxADJUST_MINSIZE
600 // If you get the following message you should do one of two things
601 // 1. Do what it says (best)
602 // 2. m_bestSize = GetSize() at end of Create() (hack)
603 if(m_bestSize
== wxDefaultSize
)
605 wxLogDebug(wxT("Class %s (or superclass) should implement DoGetBestSize()"),GetClassInfo()->GetClassName());
606 wxConstCast(this,wxWindowBase
)->m_bestSize
= GetSize();
612 // by default the origin is not shifted
613 wxPoint
wxWindowBase::GetClientAreaOrigin() const
615 return wxPoint(0, 0);
618 // set the min/max size of the window
619 void wxWindowBase::SetSizeHints(int minW
, int minH
,
621 int WXUNUSED(incW
), int WXUNUSED(incH
))
623 // setting min width greater than max width leads to infinite loops under
624 // X11 and generally doesn't make any sense, so don't allow it
625 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
626 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
627 _T("min width/height must be less than max width/height!") );
635 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
637 if ( m_windowVariant
!= variant
)
639 m_windowVariant
= variant
;
641 DoSetWindowVariant(variant
);
645 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
647 // adjust the font height to correspond to our new variant (notice that
648 // we're only called if something really changed)
649 wxFont font
= GetFont();
650 int size
= font
.GetPointSize();
653 case wxWINDOW_VARIANT_NORMAL
:
656 case wxWINDOW_VARIANT_SMALL
:
661 case wxWINDOW_VARIANT_MINI
:
666 case wxWINDOW_VARIANT_LARGE
:
672 wxFAIL_MSG(_T("unexpected window variant"));
676 font
.SetPointSize(size
);
680 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
683 m_minVirtualWidth
= minW
;
684 m_maxVirtualWidth
= maxW
;
685 m_minVirtualHeight
= minH
;
686 m_maxVirtualHeight
= maxH
;
689 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
691 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
692 x
= m_minVirtualWidth
;
693 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
694 x
= m_maxVirtualWidth
;
695 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
696 y
= m_minVirtualHeight
;
697 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
698 y
= m_maxVirtualHeight
;
700 m_virtualSize
= wxSize(x
, y
);
703 wxSize
wxWindowBase::DoGetVirtualSize() const
705 wxSize
s( GetClientSize() );
707 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
708 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
711 // ----------------------------------------------------------------------------
712 // show/hide/enable/disable the window
713 // ----------------------------------------------------------------------------
715 bool wxWindowBase::Show(bool show
)
717 if ( show
!= m_isShown
)
729 bool wxWindowBase::Enable(bool enable
)
731 if ( enable
!= m_isEnabled
)
733 m_isEnabled
= enable
;
742 // ----------------------------------------------------------------------------
744 // ----------------------------------------------------------------------------
746 bool wxWindowBase::IsTopLevel() const
751 // ----------------------------------------------------------------------------
752 // reparenting the window
753 // ----------------------------------------------------------------------------
755 void wxWindowBase::AddChild(wxWindowBase
*child
)
757 wxCHECK_RET( child
, wxT("can't add a NULL child") );
759 // this should never happen and it will lead to a crash later if it does
760 // because RemoveChild() will remove only one node from the children list
761 // and the other(s) one(s) will be left with dangling pointers in them
762 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
764 GetChildren().Append((wxWindow
*)child
);
765 child
->SetParent(this);
768 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
770 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
772 GetChildren().DeleteObject((wxWindow
*)child
);
773 child
->SetParent(NULL
);
776 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
778 wxWindow
*oldParent
= GetParent();
779 if ( newParent
== oldParent
)
785 // unlink this window from the existing parent.
788 oldParent
->RemoveChild(this);
792 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
795 // add it to the new one
798 newParent
->AddChild(this);
802 wxTopLevelWindows
.Append((wxWindow
*)this);
808 // ----------------------------------------------------------------------------
809 // event handler stuff
810 // ----------------------------------------------------------------------------
812 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
814 wxEvtHandler
*handlerOld
= GetEventHandler();
816 handler
->SetNextHandler(handlerOld
);
819 GetEventHandler()->SetPreviousHandler(handler
);
821 SetEventHandler(handler
);
824 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
826 wxEvtHandler
*handlerA
= GetEventHandler();
829 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
830 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
833 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
834 SetEventHandler(handlerB
);
839 handlerA
= (wxEvtHandler
*)NULL
;
846 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
848 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
850 wxEvtHandler
*handlerPrev
= NULL
,
851 *handlerCur
= GetEventHandler();
854 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
856 if ( handlerCur
== handler
)
860 handlerPrev
->SetNextHandler(handlerNext
);
864 SetEventHandler(handlerNext
);
869 handlerNext
->SetPreviousHandler ( handlerPrev
);
872 handler
->SetNextHandler(NULL
);
873 handler
->SetPreviousHandler(NULL
);
878 handlerPrev
= handlerCur
;
879 handlerCur
= handlerNext
;
882 wxFAIL_MSG( _T("where has the event handler gone?") );
887 // ----------------------------------------------------------------------------
889 // ----------------------------------------------------------------------------
891 /* static */ wxVisualAttributes
892 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
894 // it is important to return valid values for all attributes from here,
895 // GetXXX() below rely on this
896 wxVisualAttributes attrs
;
897 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
898 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
899 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
904 wxColour
wxWindowBase::GetBackgroundColour() const
906 if ( !m_backgroundColour
.Ok() )
908 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
910 // get our default background colour
911 wxColour colBg
= GetDefaultAttributes().colBg
;
913 // we must return some valid colour to avoid redoing this every time
914 // and also to avoid surprizing the applications written for older
915 // wxWindows versions where GetBackgroundColour() always returned
916 // something -- so give them something even if it doesn't make sense
917 // for this window (e.g. it has a themed background)
919 colBg
= GetClassDefaultAttributes().colBg
;
921 // cache it for the next call
922 wxConstCast(this, wxWindowBase
)->m_backgroundColour
= colBg
;
925 return m_backgroundColour
;
928 wxColour
wxWindowBase::GetForegroundColour() const
930 // logic is the same as above
931 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
933 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
935 wxColour colFg
= GetDefaultAttributes().colFg
;
938 colFg
= GetClassDefaultAttributes().colFg
;
940 wxConstCast(this, wxWindowBase
)->m_foregroundColour
= colFg
;
943 return m_foregroundColour
;
946 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
948 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
951 m_backgroundColour
= colour
;
958 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
960 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
963 m_foregroundColour
= colour
;
970 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
972 // setting an invalid cursor is ok, it means that we don't have any special
974 if ( m_cursor
== cursor
)
985 wxFont
& wxWindowBase::DoGetFont() const
987 // logic is the same as in GetBackgroundColour()
990 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
992 wxFont font
= GetDefaultAttributes().font
;
994 font
= GetClassDefaultAttributes().font
;
996 wxConstCast(this, wxWindowBase
)->m_font
= font
;
999 // cast is here for non-const GetFont() convenience
1000 return wxConstCast(this, wxWindowBase
)->m_font
;
1003 bool wxWindowBase::SetFont(const wxFont
& font
)
1008 if ( font
== m_font
)
1023 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1025 m_hasCustomPalette
= true;
1028 // VZ: can anyone explain me what do we do here?
1029 wxWindowDC
d((wxWindow
*) this);
1033 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1035 wxWindow
*win
= (wxWindow
*)this;
1036 while ( win
&& !win
->HasCustomPalette() )
1038 win
= win
->GetParent();
1044 #endif // wxUSE_PALETTE
1047 void wxWindowBase::SetCaret(wxCaret
*caret
)
1058 wxASSERT_MSG( m_caret
->GetWindow() == this,
1059 wxT("caret should be created associated to this window") );
1062 #endif // wxUSE_CARET
1064 #if wxUSE_VALIDATORS
1065 // ----------------------------------------------------------------------------
1067 // ----------------------------------------------------------------------------
1069 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1071 if ( m_windowValidator
)
1072 delete m_windowValidator
;
1074 m_windowValidator
= (wxValidator
*)validator
.Clone();
1076 if ( m_windowValidator
)
1077 m_windowValidator
->SetWindow(this);
1079 #endif // wxUSE_VALIDATORS
1081 // ----------------------------------------------------------------------------
1082 // update region stuff
1083 // ----------------------------------------------------------------------------
1085 wxRect
wxWindowBase::GetUpdateClientRect() const
1087 wxRegion rgnUpdate
= GetUpdateRegion();
1088 rgnUpdate
.Intersect(GetClientRect());
1089 wxRect rectUpdate
= rgnUpdate
.GetBox();
1090 wxPoint ptOrigin
= GetClientAreaOrigin();
1091 rectUpdate
.x
-= ptOrigin
.x
;
1092 rectUpdate
.y
-= ptOrigin
.y
;
1097 bool wxWindowBase::IsExposed(int x
, int y
) const
1099 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1102 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1104 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1107 void wxWindowBase::ClearBackground()
1109 // wxGTK uses its own version, no need to add never used code
1111 wxClientDC
dc((wxWindow
*)this);
1112 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1113 dc
.SetBackground(brush
);
1118 // ----------------------------------------------------------------------------
1119 // find child window by id or name
1120 // ----------------------------------------------------------------------------
1122 wxWindow
*wxWindowBase::FindWindow( long id
)
1124 if ( id
== m_windowId
)
1125 return (wxWindow
*)this;
1127 wxWindowBase
*res
= (wxWindow
*)NULL
;
1128 wxWindowList::compatibility_iterator node
;
1129 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1131 wxWindowBase
*child
= node
->GetData();
1132 res
= child
->FindWindow( id
);
1135 return (wxWindow
*)res
;
1138 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1140 if ( name
== m_windowName
)
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 wxWindow
*child
= node
->GetData();
1148 res
= child
->FindWindow(name
);
1151 return (wxWindow
*)res
;
1155 // find any window by id or name or label: If parent is non-NULL, look through
1156 // children for a label or title matching the specified string. If NULL, look
1157 // through all top-level windows.
1159 // to avoid duplicating code we reuse the same helper function but with
1160 // different comparators
1162 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1163 const wxString
& label
, long id
);
1166 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1169 return win
->GetLabel() == label
;
1173 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1176 return win
->GetName() == label
;
1180 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1183 return win
->GetId() == id
;
1186 // recursive helper for the FindWindowByXXX() functions
1188 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1189 const wxString
& label
,
1191 wxFindWindowCmp cmp
)
1195 // see if this is the one we're looking for
1196 if ( (*cmp
)(parent
, label
, id
) )
1197 return (wxWindow
*)parent
;
1199 // It wasn't, so check all its children
1200 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1202 node
= node
->GetNext() )
1204 // recursively check each child
1205 wxWindow
*win
= (wxWindow
*)node
->GetData();
1206 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1216 // helper for FindWindowByXXX()
1218 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1219 const wxString
& label
,
1221 wxFindWindowCmp cmp
)
1225 // just check parent and all its children
1226 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1229 // start at very top of wx's windows
1230 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1232 node
= node
->GetNext() )
1234 // recursively check each window & its children
1235 wxWindow
*win
= node
->GetData();
1236 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1246 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1248 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1253 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1255 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1259 // fall back to the label
1260 win
= FindWindowByLabel(title
, parent
);
1268 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1270 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1273 // ----------------------------------------------------------------------------
1274 // dialog oriented functions
1275 // ----------------------------------------------------------------------------
1277 void wxWindowBase::MakeModal(bool modal
)
1279 // Disable all other windows
1282 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1285 wxWindow
*win
= node
->GetData();
1287 win
->Enable(!modal
);
1289 node
= node
->GetNext();
1294 bool wxWindowBase::Validate()
1296 #if wxUSE_VALIDATORS
1297 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1299 wxWindowList::compatibility_iterator node
;
1300 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1302 wxWindowBase
*child
= node
->GetData();
1303 wxValidator
*validator
= child
->GetValidator();
1304 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1309 if ( recurse
&& !child
->Validate() )
1314 #endif // wxUSE_VALIDATORS
1319 bool wxWindowBase::TransferDataToWindow()
1321 #if wxUSE_VALIDATORS
1322 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1324 wxWindowList::compatibility_iterator node
;
1325 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1327 wxWindowBase
*child
= node
->GetData();
1328 wxValidator
*validator
= child
->GetValidator();
1329 if ( validator
&& !validator
->TransferToWindow() )
1331 wxLogWarning(_("Could not transfer data to window"));
1333 wxLog::FlushActive();
1341 if ( !child
->TransferDataToWindow() )
1343 // warning already given
1348 #endif // wxUSE_VALIDATORS
1353 bool wxWindowBase::TransferDataFromWindow()
1355 #if wxUSE_VALIDATORS
1356 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1358 wxWindowList::compatibility_iterator node
;
1359 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1361 wxWindow
*child
= node
->GetData();
1362 wxValidator
*validator
= child
->GetValidator();
1363 if ( validator
&& !validator
->TransferFromWindow() )
1365 // nop warning here because the application is supposed to give
1366 // one itself - we don't know here what might have gone wrongly
1373 if ( !child
->TransferDataFromWindow() )
1375 // warning already given
1380 #endif // wxUSE_VALIDATORS
1385 void wxWindowBase::InitDialog()
1387 wxInitDialogEvent
event(GetId());
1388 event
.SetEventObject( this );
1389 GetEventHandler()->ProcessEvent(event
);
1392 // ----------------------------------------------------------------------------
1393 // context-sensitive help support
1394 // ----------------------------------------------------------------------------
1398 // associate this help text with this window
1399 void wxWindowBase::SetHelpText(const wxString
& text
)
1401 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1404 helpProvider
->AddHelp(this, text
);
1408 // associate this help text with all windows with the same id as this
1410 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1412 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1415 helpProvider
->AddHelp(GetId(), text
);
1419 // get the help string associated with this window (may be empty)
1420 wxString
wxWindowBase::GetHelpText() const
1423 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1426 text
= helpProvider
->GetHelp(this);
1432 // show help for this window
1433 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1435 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1438 if ( helpProvider
->ShowHelp(this) )
1440 // skip the event.Skip() below
1448 #endif // wxUSE_HELP
1450 // ----------------------------------------------------------------------------
1451 // tooltipsroot.Replace("\\", "/");
1452 // ----------------------------------------------------------------------------
1456 void wxWindowBase::SetToolTip( const wxString
&tip
)
1458 // don't create the new tooltip if we already have one
1461 m_tooltip
->SetTip( tip
);
1465 SetToolTip( new wxToolTip( tip
) );
1468 // setting empty tooltip text does not remove the tooltip any more - use
1469 // SetToolTip((wxToolTip *)NULL) for this
1472 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1477 m_tooltip
= tooltip
;
1480 #endif // wxUSE_TOOLTIPS
1482 // ----------------------------------------------------------------------------
1483 // constraints and sizers
1484 // ----------------------------------------------------------------------------
1486 #if wxUSE_CONSTRAINTS
1488 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1490 if ( m_constraints
)
1492 UnsetConstraints(m_constraints
);
1493 delete m_constraints
;
1495 m_constraints
= constraints
;
1496 if ( m_constraints
)
1498 // Make sure other windows know they're part of a 'meaningful relationship'
1499 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1500 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1501 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1502 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1503 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1504 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1505 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1506 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1507 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1508 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1509 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1510 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1511 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1512 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1513 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1514 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1518 // This removes any dangling pointers to this window in other windows'
1519 // constraintsInvolvedIn lists.
1520 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1524 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1525 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1526 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1527 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1528 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1529 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1530 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1531 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1532 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1533 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1534 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1535 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1536 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1537 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1538 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1539 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1543 // Back-pointer to other windows we're involved with, so if we delete this
1544 // window, we must delete any constraints we're involved with.
1545 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1547 if ( !m_constraintsInvolvedIn
)
1548 m_constraintsInvolvedIn
= new wxWindowList
;
1549 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1550 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1553 // REMOVE back-pointer to other windows we're involved with.
1554 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1556 if ( m_constraintsInvolvedIn
)
1557 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1560 // Reset any constraints that mention this window
1561 void wxWindowBase::DeleteRelatedConstraints()
1563 if ( m_constraintsInvolvedIn
)
1565 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1568 wxWindow
*win
= node
->GetData();
1569 wxLayoutConstraints
*constr
= win
->GetConstraints();
1571 // Reset any constraints involving this window
1574 constr
->left
.ResetIfWin(this);
1575 constr
->top
.ResetIfWin(this);
1576 constr
->right
.ResetIfWin(this);
1577 constr
->bottom
.ResetIfWin(this);
1578 constr
->width
.ResetIfWin(this);
1579 constr
->height
.ResetIfWin(this);
1580 constr
->centreX
.ResetIfWin(this);
1581 constr
->centreY
.ResetIfWin(this);
1584 wxWindowList::compatibility_iterator next
= node
->GetNext();
1585 m_constraintsInvolvedIn
->Erase(node
);
1589 delete m_constraintsInvolvedIn
;
1590 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1594 #endif // wxUSE_CONSTRAINTS
1596 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1598 if ( sizer
== m_windowSizer
)
1602 delete m_windowSizer
;
1604 m_windowSizer
= sizer
;
1606 SetAutoLayout( sizer
!= NULL
);
1609 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1611 SetSizer( sizer
, deleteOld
);
1612 sizer
->SetSizeHints( (wxWindow
*) this );
1615 #if wxUSE_CONSTRAINTS
1617 void wxWindowBase::SatisfyConstraints()
1619 wxLayoutConstraints
*constr
= GetConstraints();
1620 bool wasOk
= constr
&& constr
->AreSatisfied();
1622 ResetConstraints(); // Mark all constraints as unevaluated
1626 // if we're a top level panel (i.e. our parent is frame/dialog), our
1627 // own constraints will never be satisfied any more unless we do it
1631 while ( noChanges
> 0 )
1633 LayoutPhase1(&noChanges
);
1637 LayoutPhase2(&noChanges
);
1640 #endif // wxUSE_CONSTRAINTS
1642 bool wxWindowBase::Layout()
1644 // If there is a sizer, use it instead of the constraints
1648 GetVirtualSize(&w
, &h
);
1649 GetSizer()->SetDimension( 0, 0, w
, h
);
1651 #if wxUSE_CONSTRAINTS
1654 SatisfyConstraints(); // Find the right constraints values
1655 SetConstraintSizes(); // Recursively set the real window sizes
1662 #if wxUSE_CONSTRAINTS
1664 // first phase of the constraints evaluation: set our own constraints
1665 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1667 wxLayoutConstraints
*constr
= GetConstraints();
1669 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1672 // second phase: set the constraints for our children
1673 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1680 // Layout grand children
1686 // Do a phase of evaluating child constraints
1687 bool wxWindowBase::DoPhase(int phase
)
1689 // the list containing the children for which the constraints are already
1691 wxWindowList succeeded
;
1693 // the max number of iterations we loop before concluding that we can't set
1695 static const int maxIterations
= 500;
1697 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1701 // loop over all children setting their constraints
1702 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1704 node
= node
->GetNext() )
1706 wxWindow
*child
= node
->GetData();
1707 if ( child
->IsTopLevel() )
1709 // top level children are not inside our client area
1713 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1715 // this one is either already ok or nothing we can do about it
1719 int tempNoChanges
= 0;
1720 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1721 : child
->LayoutPhase2(&tempNoChanges
);
1722 noChanges
+= tempNoChanges
;
1726 succeeded
.Append(child
);
1732 // constraints are set
1740 void wxWindowBase::ResetConstraints()
1742 wxLayoutConstraints
*constr
= GetConstraints();
1745 constr
->left
.SetDone(false);
1746 constr
->top
.SetDone(false);
1747 constr
->right
.SetDone(false);
1748 constr
->bottom
.SetDone(false);
1749 constr
->width
.SetDone(false);
1750 constr
->height
.SetDone(false);
1751 constr
->centreX
.SetDone(false);
1752 constr
->centreY
.SetDone(false);
1755 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1758 wxWindow
*win
= node
->GetData();
1759 if ( !win
->IsTopLevel() )
1760 win
->ResetConstraints();
1761 node
= node
->GetNext();
1765 // Need to distinguish between setting the 'fake' size for windows and sizers,
1766 // and setting the real values.
1767 void wxWindowBase::SetConstraintSizes(bool recurse
)
1769 wxLayoutConstraints
*constr
= GetConstraints();
1770 if ( constr
&& constr
->AreSatisfied() )
1772 int x
= constr
->left
.GetValue();
1773 int y
= constr
->top
.GetValue();
1774 int w
= constr
->width
.GetValue();
1775 int h
= constr
->height
.GetValue();
1777 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1778 (constr
->height
.GetRelationship() != wxAsIs
) )
1780 SetSize(x
, y
, w
, h
);
1784 // If we don't want to resize this window, just move it...
1790 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1791 GetClassInfo()->GetClassName(),
1797 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1800 wxWindow
*win
= node
->GetData();
1801 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1802 win
->SetConstraintSizes();
1803 node
= node
->GetNext();
1808 // Only set the size/position of the constraint (if any)
1809 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1811 wxLayoutConstraints
*constr
= GetConstraints();
1816 constr
->left
.SetValue(x
);
1817 constr
->left
.SetDone(true);
1821 constr
->top
.SetValue(y
);
1822 constr
->top
.SetDone(true);
1826 constr
->width
.SetValue(w
);
1827 constr
->width
.SetDone(true);
1831 constr
->height
.SetValue(h
);
1832 constr
->height
.SetDone(true);
1837 void wxWindowBase::MoveConstraint(int x
, int y
)
1839 wxLayoutConstraints
*constr
= GetConstraints();
1844 constr
->left
.SetValue(x
);
1845 constr
->left
.SetDone(true);
1849 constr
->top
.SetValue(y
);
1850 constr
->top
.SetDone(true);
1855 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1857 wxLayoutConstraints
*constr
= GetConstraints();
1860 *w
= constr
->width
.GetValue();
1861 *h
= constr
->height
.GetValue();
1867 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1869 wxLayoutConstraints
*constr
= GetConstraints();
1872 *w
= constr
->width
.GetValue();
1873 *h
= constr
->height
.GetValue();
1876 GetClientSize(w
, h
);
1879 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1881 wxLayoutConstraints
*constr
= GetConstraints();
1884 *x
= constr
->left
.GetValue();
1885 *y
= constr
->top
.GetValue();
1891 #endif // wxUSE_CONSTRAINTS
1893 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1895 // don't do it for the dialogs/frames - they float independently of their
1897 if ( !IsTopLevel() )
1899 wxWindow
*parent
= GetParent();
1900 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1902 wxPoint
pt(parent
->GetClientAreaOrigin());
1909 // ----------------------------------------------------------------------------
1910 // do Update UI processing for child controls
1911 // ----------------------------------------------------------------------------
1913 void wxWindowBase::UpdateWindowUI(long flags
)
1915 wxUpdateUIEvent
event(GetId());
1916 event
.m_eventObject
= this;
1918 if ( GetEventHandler()->ProcessEvent(event
) )
1920 DoUpdateWindowUI(event
);
1923 if (flags
& wxUPDATE_UI_RECURSE
)
1925 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1928 wxWindow
* child
= (wxWindow
*) node
->GetData();
1929 child
->UpdateWindowUI(flags
);
1930 node
= node
->GetNext();
1935 // do the window-specific processing after processing the update event
1936 // TODO: take specific knowledge out of this function and
1937 // put in each control's base class. Unfortunately we don't
1938 // yet have base implementation files for wxCheckBox and wxRadioButton.
1939 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1941 if ( event
.GetSetEnabled() )
1942 Enable(event
.GetEnabled());
1945 if ( event
.GetSetText() )
1947 wxControl
*control
= wxDynamicCastThis(wxControl
);
1950 if ( event
.GetText() != control
->GetLabel() )
1951 control
->SetLabel(event
.GetText());
1954 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1957 if ( event
.GetSetChecked() )
1958 checkbox
->SetValue(event
.GetChecked());
1960 #endif // wxUSE_CHECKBOX
1963 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1966 if ( event
.GetSetChecked() )
1967 radiobtn
->SetValue(event
.GetChecked());
1969 #endif // wxUSE_RADIOBTN
1975 // call internal idle recursively
1976 // may be obsolete (wait until OnIdle scheme stabilises)
1977 void wxWindowBase::ProcessInternalIdle()
1981 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1984 wxWindow
*child
= node
->GetData();
1985 child
->ProcessInternalIdle();
1986 node
= node
->GetNext();
1991 // ----------------------------------------------------------------------------
1992 // dialog units translations
1993 // ----------------------------------------------------------------------------
1995 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1997 int charWidth
= GetCharWidth();
1998 int charHeight
= GetCharHeight();
1999 wxPoint
pt2(-1, -1);
2001 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2003 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2008 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2010 int charWidth
= GetCharWidth();
2011 int charHeight
= GetCharHeight();
2012 wxPoint
pt2(-1, -1);
2014 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2016 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2021 // ----------------------------------------------------------------------------
2023 // ----------------------------------------------------------------------------
2025 // propagate the colour change event to the subwindows
2026 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2028 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2031 // Only propagate to non-top-level windows
2032 wxWindow
*win
= node
->GetData();
2033 if ( !win
->IsTopLevel() )
2035 wxSysColourChangedEvent event2
;
2036 event
.m_eventObject
= win
;
2037 win
->GetEventHandler()->ProcessEvent(event2
);
2040 node
= node
->GetNext();
2044 // the default action is to populate dialog with data when it's created,
2045 // and nudge the UI into displaying itself correctly in case
2046 // we've turned the wxUpdateUIEvents frequency down low.
2047 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2049 TransferDataToWindow();
2051 // Update the UI at this point
2052 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2055 // process Ctrl-Alt-mclick
2056 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2059 if ( event
.ControlDown() && event
.AltDown() )
2061 // don't translate these strings
2064 #ifdef __WXUNIVERSAL__
2066 #endif // __WXUNIVERSAL__
2068 switch ( wxGetOsVersion() )
2070 case wxMOTIF_X
: port
+= _T("Motif"); break;
2072 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2073 case wxBEOS
: port
+= _T("BeOS"); break;
2077 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2083 case wxWIN386
: port
+= _T("MS Windows"); break;
2087 case wxMGL_OS2
: port
+= _T("MGL"); break;
2089 case wxOS2_PM
: port
+= _T("OS/2"); break;
2090 default: port
+= _T("unknown"); break;
2093 wxMessageBox(wxString::Format(
2095 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
2109 _T("wxWindows information"),
2110 wxICON_INFORMATION
| wxOK
,
2114 #endif // wxUSE_MSGDLG
2120 // ----------------------------------------------------------------------------
2122 // ----------------------------------------------------------------------------
2124 #if wxUSE_ACCESSIBILITY
2125 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2127 if (m_accessible
&& (accessible
!= m_accessible
))
2128 delete m_accessible
;
2129 m_accessible
= accessible
;
2131 m_accessible
->SetWindow((wxWindow
*) this);
2134 // Returns the accessible object, creating if necessary.
2135 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2138 m_accessible
= CreateAccessible();
2139 return m_accessible
;
2142 // Override to create a specific accessible object.
2143 wxAccessible
* wxWindowBase::CreateAccessible()
2145 return new wxWindowAccessible((wxWindow
*) this);
2151 // ----------------------------------------------------------------------------
2152 // list classes implementation
2153 // ----------------------------------------------------------------------------
2155 void wxWindowListNode::DeleteData()
2157 delete (wxWindow
*)GetData();
2161 // ----------------------------------------------------------------------------
2163 // ----------------------------------------------------------------------------
2165 wxBorder
wxWindowBase::GetBorder(long flags
) const
2167 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2168 if ( border
== wxBORDER_DEFAULT
)
2170 border
= GetDefaultBorder();
2176 wxBorder
wxWindowBase::GetDefaultBorder() const
2178 return wxBORDER_NONE
;
2181 // ----------------------------------------------------------------------------
2183 // ----------------------------------------------------------------------------
2185 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2187 // here we just check if the point is inside the window or not
2189 // check the top and left border first
2190 bool outside
= x
< 0 || y
< 0;
2193 // check the right and bottom borders too
2194 wxSize size
= GetSize();
2195 outside
= x
>= size
.x
|| y
>= size
.y
;
2198 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2201 // ----------------------------------------------------------------------------
2203 // ----------------------------------------------------------------------------
2205 struct WXDLLEXPORT wxWindowNext
2209 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2211 void wxWindowBase::CaptureMouse()
2213 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2215 wxWindow
*winOld
= GetCapture();
2218 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2221 wxWindowNext
*item
= new wxWindowNext
;
2223 item
->next
= ms_winCaptureNext
;
2224 ms_winCaptureNext
= item
;
2226 //else: no mouse capture to save
2231 void wxWindowBase::ReleaseMouse()
2233 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2235 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2239 if ( ms_winCaptureNext
)
2241 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2243 wxWindowNext
*item
= ms_winCaptureNext
;
2244 ms_winCaptureNext
= item
->next
;
2247 //else: stack is empty, no previous capture
2249 wxLogTrace(_T("mousecapture"),
2250 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2257 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2258 int WXUNUSED(modifiers
),
2259 int WXUNUSED(keycode
))
2265 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2271 #endif // wxUSE_HOTKEY
2273 void wxWindowBase::SendDestroyEvent()
2275 wxWindowDestroyEvent event
;
2276 event
.SetEventObject(this);
2277 event
.SetId(GetId());
2278 GetEventHandler()->ProcessEvent(event
);
2281 // ----------------------------------------------------------------------------
2283 // ----------------------------------------------------------------------------
2285 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2287 #if wxUSE_VALIDATORS
2288 // Can only use the validator of the window which
2289 // is receiving the event
2290 if ( event
.GetEventObject() == this )
2292 wxValidator
*validator
= GetValidator();
2293 if ( validator
&& validator
->ProcessEvent(event
) )
2298 #endif // wxUSE_VALIDATORS
2303 bool wxWindowBase::TryParent(wxEvent
& event
)
2305 // carry on up the parent-child hierarchy if the propgation count hasn't
2307 if ( event
.ShouldPropagate() )
2309 // honour the requests to stop propagation at this window: this is
2310 // used by the dialogs, for example, to prevent processing the events
2311 // from the dialog controls in the parent frame which rarely, if ever,
2313 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2315 wxWindow
*parent
= GetParent();
2316 if ( parent
&& !parent
->IsBeingDeleted() )
2318 wxPropagateOnce
propagateOnce(event
);
2320 return parent
->GetEventHandler()->ProcessEvent(event
);
2325 return wxEvtHandler::TryParent(event
);
2328 // ----------------------------------------------------------------------------
2330 // ----------------------------------------------------------------------------
2332 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2334 while ( win
&& !win
->IsTopLevel() )
2335 win
= win
->GetParent();
2340 #if wxUSE_ACCESSIBILITY
2341 // ----------------------------------------------------------------------------
2342 // accessible object for windows
2343 // ----------------------------------------------------------------------------
2345 // Can return either a child object, or an integer
2346 // representing the child element, starting from 1.
2347 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2349 wxASSERT( GetWindow() != NULL
);
2353 return wxACC_NOT_IMPLEMENTED
;
2356 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2357 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2359 wxASSERT( GetWindow() != NULL
);
2363 wxWindow
* win
= NULL
;
2370 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2372 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2379 rect
= win
->GetRect();
2380 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2381 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2385 return wxACC_NOT_IMPLEMENTED
;
2388 // Navigates from fromId to toId/toObject.
2389 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2390 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2392 wxASSERT( GetWindow() != NULL
);
2398 case wxNAVDIR_FIRSTCHILD
:
2400 if (GetWindow()->GetChildren().GetCount() == 0)
2402 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2403 *toObject
= childWindow
->GetOrCreateAccessible();
2407 case wxNAVDIR_LASTCHILD
:
2409 if (GetWindow()->GetChildren().GetCount() == 0)
2411 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2412 *toObject
= childWindow
->GetOrCreateAccessible();
2416 case wxNAVDIR_RIGHT
:
2420 wxWindowList::compatibility_iterator node
=
2421 wxWindowList::compatibility_iterator();
2424 // Can't navigate to sibling of this window
2425 // if we're a top-level window.
2426 if (!GetWindow()->GetParent())
2427 return wxACC_NOT_IMPLEMENTED
;
2429 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2433 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2434 node
= GetWindow()->GetChildren().Item(fromId
-1);
2437 if (node
&& node
->GetNext())
2439 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2440 *toObject
= nextWindow
->GetOrCreateAccessible();
2448 case wxNAVDIR_PREVIOUS
:
2450 wxWindowList::compatibility_iterator node
=
2451 wxWindowList::compatibility_iterator();
2454 // Can't navigate to sibling of this window
2455 // if we're a top-level window.
2456 if (!GetWindow()->GetParent())
2457 return wxACC_NOT_IMPLEMENTED
;
2459 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2463 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2464 node
= GetWindow()->GetChildren().Item(fromId
-1);
2467 if (node
&& node
->GetPrevious())
2469 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2470 *toObject
= previousWindow
->GetOrCreateAccessible();
2478 return wxACC_NOT_IMPLEMENTED
;
2481 // Gets the name of the specified object.
2482 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2484 wxASSERT( GetWindow() != NULL
);
2490 // If a child, leave wxWindows to call the function on the actual
2493 return wxACC_NOT_IMPLEMENTED
;
2495 // This will eventually be replaced by specialised
2496 // accessible classes, one for each kind of wxWindows
2497 // control or window.
2498 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2499 title
= ((wxButton
*) GetWindow())->GetLabel();
2501 title
= GetWindow()->GetName();
2503 if (!title
.IsEmpty())
2509 return wxACC_NOT_IMPLEMENTED
;
2512 // Gets the number of children.
2513 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2515 wxASSERT( GetWindow() != NULL
);
2519 *childId
= (int) GetWindow()->GetChildren().GetCount();
2523 // Gets the specified child (starting from 1).
2524 // If *child is NULL and return value is wxACC_OK,
2525 // this means that the child is a simple element and
2526 // not an accessible object.
2527 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2529 wxASSERT( GetWindow() != NULL
);
2539 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2542 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2543 *child
= childWindow
->GetOrCreateAccessible();
2550 // Gets the parent, or NULL.
2551 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2553 wxASSERT( GetWindow() != NULL
);
2557 wxWindow
* parentWindow
= GetWindow()->GetParent();
2565 *parent
= parentWindow
->GetOrCreateAccessible();
2573 // Performs the default action. childId is 0 (the action for this object)
2574 // or > 0 (the action for a child).
2575 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2576 // window (e.g. an edit control).
2577 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2579 wxASSERT( GetWindow() != NULL
);
2583 return wxACC_NOT_IMPLEMENTED
;
2586 // Gets the default action for this object (0) or > 0 (the action for a child).
2587 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2588 // string if there is no action.
2589 // The retrieved string describes the action that is performed on an object,
2590 // not what the object does as a result. For example, a toolbar button that prints
2591 // a document has a default action of "Press" rather than "Prints the current document."
2592 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2594 wxASSERT( GetWindow() != NULL
);
2598 return wxACC_NOT_IMPLEMENTED
;
2601 // Returns the description for this object or a child.
2602 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2604 wxASSERT( GetWindow() != NULL
);
2608 wxString
ht(GetWindow()->GetHelpText());
2614 return wxACC_NOT_IMPLEMENTED
;
2617 // Returns help text for this object or a child, similar to tooltip text.
2618 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2620 wxASSERT( GetWindow() != NULL
);
2624 wxString
ht(GetWindow()->GetHelpText());
2630 return wxACC_NOT_IMPLEMENTED
;
2633 // Returns the keyboard shortcut for this object or child.
2634 // Return e.g. ALT+K
2635 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2637 wxASSERT( GetWindow() != NULL
);
2641 return wxACC_NOT_IMPLEMENTED
;
2644 // Returns a role constant.
2645 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2647 wxASSERT( GetWindow() != NULL
);
2651 // If a child, leave wxWindows to call the function on the actual
2654 return wxACC_NOT_IMPLEMENTED
;
2656 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2657 return wxACC_NOT_IMPLEMENTED
;
2659 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2660 return wxACC_NOT_IMPLEMENTED
;
2663 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2664 return wxACC_NOT_IMPLEMENTED
;
2667 //*role = wxROLE_SYSTEM_CLIENT;
2668 *role
= wxROLE_SYSTEM_CLIENT
;
2672 return wxACC_NOT_IMPLEMENTED
;
2676 // Returns a state constant.
2677 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2679 wxASSERT( GetWindow() != NULL
);
2683 // If a child, leave wxWindows to call the function on the actual
2686 return wxACC_NOT_IMPLEMENTED
;
2688 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2689 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
;
2704 return wxACC_NOT_IMPLEMENTED
;
2708 // Returns a localized string representing the value for the object
2710 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2712 wxASSERT( GetWindow() != NULL
);
2716 return wxACC_NOT_IMPLEMENTED
;
2719 // Selects the object or child.
2720 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2722 wxASSERT( GetWindow() != NULL
);
2726 return wxACC_NOT_IMPLEMENTED
;
2729 // Gets the window with the keyboard focus.
2730 // If childId is 0 and child is NULL, no object in
2731 // this subhierarchy has the focus.
2732 // If this object has the focus, child should be 'this'.
2733 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2735 wxASSERT( GetWindow() != NULL
);
2739 return wxACC_NOT_IMPLEMENTED
;
2742 // Gets a variant representing the selected children
2744 // Acceptable values:
2745 // - a null variant (IsNull() returns TRUE)
2746 // - a list variant (GetType() == wxT("list")
2747 // - an integer representing the selected child element,
2748 // or 0 if this object is selected (GetType() == wxT("long")
2749 // - a "void*" pointer to a wxAccessible child object
2750 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2752 wxASSERT( GetWindow() != NULL
);
2756 return wxACC_NOT_IMPLEMENTED
;
2759 #endif // wxUSE_ACCESSIBILITY