]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/compositewin.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/compositewin.h
3 // Purpose: wxCompositeWindow<> declaration
4 // Author: Vadim Zeitlin
6 // RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $
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 // NB: This is an experimental and, as for now, undocumented class used only by
17 // wxWidgets itself internally. Don't use it in your code until its API is
18 // officially stabilized unless you are ready to change it with the next
21 // FIXME-VC6: This compiler can't compile DoSetForAllParts() template function,
22 // it can't determine whether the deduced type should be "T" or "const T&". And
23 // without this function wxCompositeWindow is pretty useless so simply disable
24 // this code for it, this does mean that setting colours/fonts/... for
25 // composite controls won't work in the library compiled with it but so far
26 // this only affects the generic wxDatePickerCtrl which is not used by default
27 // under MSW anyhow so it doesn't seem to be worth it to spend time and uglify
28 // the code to fix it.
31 // ----------------------------------------------------------------------------
32 // wxCompositeWindow is a helper for implementing composite windows: to define
33 // a class using subwindows, simply inherit from it specialized with the real
34 // base class name and implement GetCompositeWindowParts() pure virtual method.
35 // ----------------------------------------------------------------------------
37 // The template parameter W must be a wxWindow-derived class.
39 class wxCompositeWindow
: public W
42 typedef W BaseWindowClass
;
44 // Default ctor doesn't do anything.
45 wxCompositeWindow() { }
47 // Override all wxWindow methods which must be forwarded to the composite
50 // Attribute setters group.
52 // NB: Unfortunately we can't factor out the call for the setter itself
53 // into DoSetForAllParts() because we can't call the function passed to
54 // it non-virtually and we need to do this to avoid infinite recursion,
55 // so we work around this by calling the method of this object itself
56 // manually in each function.
57 virtual bool SetForegroundColour(const wxColour
& colour
)
59 if ( !BaseWindowClass::SetForegroundColour(colour
) )
62 DoSetForAllParts(&wxWindowBase::SetForegroundColour
, colour
);
67 virtual bool SetBackgroundColour(const wxColour
& colour
)
69 if ( !BaseWindowClass::SetBackgroundColour(colour
) )
72 DoSetForAllParts(&wxWindowBase::SetBackgroundColour
, colour
);
77 virtual bool SetFont(const wxFont
& font
)
79 if ( !BaseWindowClass::SetFont(font
) )
82 DoSetForAllParts(&wxWindowBase::SetFont
, font
);
87 virtual bool SetCursor(const wxCursor
& cursor
)
89 if ( !BaseWindowClass::SetCursor(cursor
) )
92 DoSetForAllParts(&wxWindowBase::SetCursor
, cursor
);
98 // Must be implemented by the derived class to return all children to which
99 // the public methods we override should forward to.
100 virtual wxWindowList
GetCompositeWindowParts() const = 0;
103 void DoSetForAllParts(bool (wxWindowBase::*func
)(const T
&), const T
& arg
)
105 // Simply call the setters for all parts of this composite window.
106 const wxWindowList parts
= GetCompositeWindowParts();
107 for ( wxWindowList::const_iterator i
= parts
.begin();
111 wxWindow
* const child
= *i
;
113 // Allow NULL elements in the list, this makes the code of derived
114 // composite controls which may have optionally shown children
115 // simpler and it doesn't cost us much here.
121 wxDECLARE_NO_COPY_TEMPLATE_CLASS(wxCompositeWindow
, W
);
124 #else // __VISUALC6__
127 class wxCompositeWindow
: public W
131 #endif // !__VISUALC6__/__VISUALC6__
133 #endif // _WX_COMPOSITEWIN_H_