]>
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 // ----------------------------------------------------------------------------
22 // wxCompositeWindow is a helper for implementing composite windows: to define
23 // a class using subwindows, simply inherit from it specialized with the real
24 // base class name and implement GetCompositeWindowParts() pure virtual method.
25 // ----------------------------------------------------------------------------
27 // The template parameter W must be a wxWindow-derived class.
29 class wxCompositeWindow
: public W
32 typedef W BaseWindowClass
;
34 // Default ctor doesn't do anything.
35 wxCompositeWindow() { }
37 // Override all wxWindow methods which must be forwarded to the composite
40 // Attribute setters group.
42 // NB: Unfortunately we can't factor out the call for the setter itself
43 // into DoSetForAllParts() because we can't call the function passed to
44 // it non-virtually and we need to do this to avoid infinite recursion,
45 // so we work around this by calling the method of this object itself
46 // manually in each function.
47 virtual bool SetForegroundColour(const wxColour
& colour
)
49 if ( !BaseWindowClass::SetForegroundColour(colour
) )
52 DoSetForAllParts(&wxWindow::SetForegroundColour
, colour
);
57 virtual bool SetBackgroundColour(const wxColour
& colour
)
59 if ( !BaseWindowClass::SetBackgroundColour(colour
) )
62 DoSetForAllParts(&wxWindow::SetBackgroundColour
, colour
);
67 virtual bool SetFont(const wxFont
& font
)
69 if ( !BaseWindowClass::SetFont(font
) )
72 DoSetForAllParts(&wxWindow::SetFont
, font
);
77 virtual bool SetCursor(const wxCursor
& cursor
)
79 if ( !BaseWindowClass::SetCursor(cursor
) )
82 DoSetForAllParts(&wxWindow::SetCursor
, cursor
);
88 // Must be implemented by the derived class to return all children to which
89 // the public methods we override should forward to.
90 virtual wxWindowList
GetCompositeWindowParts() const = 0;
93 void DoSetForAllParts(bool (wxWindow::*func
)(const T
&), const T
& arg
)
95 // Simply call the setters for all parts of this composite window.
96 const wxWindowList parts
= GetCompositeWindowParts();
97 for ( wxWindowList::const_iterator i
= parts
.begin();
101 wxWindow
* const child
= *i
;
107 wxDECLARE_NO_COPY_TEMPLATE_CLASS(wxCompositeWindow
, W
);
110 #endif // _WX_COMPOSITEWIN_H_