]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/compositewin.h | |
3 | // Purpose: wxCompositeWindow<> declaration | |
4 | // Author: Vadim Zeitlin | |
5 | // Created: 2011-01-02 | |
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 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_COMPOSITEWIN_H_ | |
12 | #define _WX_COMPOSITEWIN_H_ | |
13 | ||
14 | #include "wx/window.h" | |
15 | ||
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 | |
19 | // wxWidgets release. | |
20 | ||
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. | |
29 | #ifndef __VISUALC6__ | |
30 | ||
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 | // ---------------------------------------------------------------------------- | |
36 | ||
37 | // The template parameter W must be a wxWindow-derived class. | |
38 | template <class W> | |
39 | class wxCompositeWindow : public W | |
40 | { | |
41 | public: | |
42 | typedef W BaseWindowClass; | |
43 | ||
44 | // Default ctor doesn't do anything. | |
45 | wxCompositeWindow() { } | |
46 | ||
47 | // Override all wxWindow methods which must be forwarded to the composite | |
48 | // window parts. | |
49 | ||
50 | // Attribute setters group. | |
51 | // | |
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) | |
58 | { | |
59 | if ( !BaseWindowClass::SetForegroundColour(colour) ) | |
60 | return false; | |
61 | ||
62 | DoSetForAllParts(&wxWindowBase::SetForegroundColour, colour); | |
63 | ||
64 | return true; | |
65 | } | |
66 | ||
67 | virtual bool SetBackgroundColour(const wxColour& colour) | |
68 | { | |
69 | if ( !BaseWindowClass::SetBackgroundColour(colour) ) | |
70 | return false; | |
71 | ||
72 | DoSetForAllParts(&wxWindowBase::SetBackgroundColour, colour); | |
73 | ||
74 | return true; | |
75 | } | |
76 | ||
77 | virtual bool SetFont(const wxFont& font) | |
78 | { | |
79 | if ( !BaseWindowClass::SetFont(font) ) | |
80 | return false; | |
81 | ||
82 | DoSetForAllParts(&wxWindowBase::SetFont, font); | |
83 | ||
84 | return true; | |
85 | } | |
86 | ||
87 | virtual bool SetCursor(const wxCursor& cursor) | |
88 | { | |
89 | if ( !BaseWindowClass::SetCursor(cursor) ) | |
90 | return false; | |
91 | ||
92 | DoSetForAllParts(&wxWindowBase::SetCursor, cursor); | |
93 | ||
94 | return true; | |
95 | } | |
96 | ||
97 | private: | |
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; | |
101 | ||
102 | template <class T> | |
103 | void DoSetForAllParts(bool (wxWindowBase::*func)(const T&), const T& arg) | |
104 | { | |
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(); | |
108 | i != parts.end(); | |
109 | ++i ) | |
110 | { | |
111 | wxWindow * const child = *i; | |
112 | ||
113 | (child->*func)(arg); | |
114 | } | |
115 | } | |
116 | ||
117 | wxDECLARE_NO_COPY_TEMPLATE_CLASS(wxCompositeWindow, W); | |
118 | }; | |
119 | ||
120 | #else // __VISUALC6__ | |
121 | ||
122 | template <class W> | |
123 | class WXDLLIMPEXP_CORE wxCompositeWindow : public W | |
124 | { | |
125 | }; | |
126 | ||
127 | #endif // !__VISUALC6__/__VISUALC6__ | |
128 | ||
129 | #endif // _WX_COMPOSITEWIN_H_ |