1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/compositewin.h
3 // Purpose: wxCompositeWindow<> declaration
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_COMPOSITEWIN_H_
12 #define _WX_COMPOSITEWIN_H_
14 #include "wx/window.h"
16 class WXDLLIMPEXP_FWD_CORE wxToolTip
;
18 // NB: This is an experimental and, as for now, undocumented class used only by
19 // wxWidgets itself internally. Don't use it in your code until its API is
20 // officially stabilized unless you are ready to change it with the next
23 // FIXME-VC6: This compiler can't compile DoSetForAllParts() template function,
24 // it can't determine whether the deduced type should be "T" or "const T&". And
25 // without this function wxCompositeWindow is pretty useless so simply disable
26 // this code for it, this does mean that setting colours/fonts/... for
27 // composite controls won't work in the library compiled with it but so far
28 // this only affects the generic wxDatePickerCtrl which is not used by default
29 // under MSW anyhow so it doesn't seem to be worth it to spend time and uglify
30 // the code to fix it.
33 // ----------------------------------------------------------------------------
34 // wxCompositeWindow is a helper for implementing composite windows: to define
35 // a class using subwindows, simply inherit from it specialized with the real
36 // base class name and implement GetCompositeWindowParts() pure virtual method.
37 // ----------------------------------------------------------------------------
39 // The template parameter W must be a wxWindow-derived class.
41 class wxCompositeWindow
: public W
44 typedef W BaseWindowClass
;
46 // Default ctor doesn't do anything.
47 wxCompositeWindow() { }
49 // Override all wxWindow methods which must be forwarded to the composite
52 // Attribute setters group.
54 // NB: Unfortunately we can't factor out the call for the setter itself
55 // into DoSetForAllParts() because we can't call the function passed to
56 // it non-virtually and we need to do this to avoid infinite recursion,
57 // so we work around this by calling the method of this object itself
58 // manually in each function.
59 virtual bool SetForegroundColour(const wxColour
& colour
)
61 if ( !BaseWindowClass::SetForegroundColour(colour
) )
64 SetForAllParts(&wxWindowBase::SetForegroundColour
, colour
);
69 virtual bool SetBackgroundColour(const wxColour
& colour
)
71 if ( !BaseWindowClass::SetBackgroundColour(colour
) )
74 SetForAllParts(&wxWindowBase::SetBackgroundColour
, colour
);
79 virtual bool SetFont(const wxFont
& font
)
81 if ( !BaseWindowClass::SetFont(font
) )
84 SetForAllParts(&wxWindowBase::SetFont
, font
);
89 virtual bool SetCursor(const wxCursor
& cursor
)
91 if ( !BaseWindowClass::SetCursor(cursor
) )
94 SetForAllParts(&wxWindowBase::SetCursor
, cursor
);
100 virtual void DoSetToolTip(wxToolTip
*tip
)
102 BaseWindowClass::DoSetToolTip(tip
);
104 SetForAllParts(&wxWindowBase::CopyToolTip
, tip
);
106 #endif // wxUSE_TOOLTIPS
109 // Must be implemented by the derived class to return all children to which
110 // the public methods we override should forward to.
111 virtual wxWindowList
GetCompositeWindowParts() const = 0;
114 void SetForAllParts(bool (wxWindowBase::*func
)(const T
&), const T
& arg
)
116 DoSetForAllParts
<const T
&>(func
, arg
);
120 void SetForAllParts(bool (wxWindowBase::*func
)(T
*), T
* arg
)
122 DoSetForAllParts
<T
*>(func
, arg
);
126 void DoSetForAllParts(bool (wxWindowBase::*func
)(T
), T arg
)
128 // Simply call the setters for all parts of this composite window.
129 const wxWindowList parts
= GetCompositeWindowParts();
130 for ( wxWindowList::const_iterator i
= parts
.begin();
134 wxWindow
* const child
= *i
;
136 // Allow NULL elements in the list, this makes the code of derived
137 // composite controls which may have optionally shown children
138 // simpler and it doesn't cost us much here.
144 wxDECLARE_NO_COPY_TEMPLATE_CLASS(wxCompositeWindow
, W
);
147 #else // __VISUALC6__
150 class wxCompositeWindow
: public W
154 #endif // !__VISUALC6__/__VISUALC6__
156 #endif // _WX_COMPOSITEWIN_H_