]> git.saurik.com Git - wxWidgets.git/blame - include/wx/compositewin.h
Improve print preview appearance and functionality.
[wxWidgets.git] / include / wx / compositewin.h
CommitLineData
a9e41db7
VZ
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// ----------------------------------------------------------------------------
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// ----------------------------------------------------------------------------
26
27// The template parameter W must be a wxWindow-derived class.
28template <class W>
29class wxCompositeWindow : public W
30{
31public:
32 typedef W BaseWindowClass;
33
34 // Default ctor doesn't do anything.
35 wxCompositeWindow() { }
36
37 // Override all wxWindow methods which must be forwarded to the composite
38 // window parts.
39
40 // Attribute setters group.
41 //
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)
48 {
49 if ( !BaseWindowClass::SetForegroundColour(colour) )
50 return false;
51
52 DoSetForAllParts(&wxWindow::SetForegroundColour, colour);
53
54 return true;
55 }
56
57 virtual bool SetBackgroundColour(const wxColour& colour)
58 {
59 if ( !BaseWindowClass::SetBackgroundColour(colour) )
60 return false;
61
62 DoSetForAllParts(&wxWindow::SetBackgroundColour, colour);
63
64 return true;
65 }
66
67 virtual bool SetFont(const wxFont& font)
68 {
69 if ( !BaseWindowClass::SetFont(font) )
70 return false;
71
72 DoSetForAllParts(&wxWindow::SetFont, font);
73
74 return true;
75 }
76
77 virtual bool SetCursor(const wxCursor& cursor)
78 {
79 if ( !BaseWindowClass::SetCursor(cursor) )
80 return false;
81
82 DoSetForAllParts(&wxWindow::SetCursor, cursor);
83
84 return true;
85 }
86
87private:
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;
91
92 template <class T>
93 void DoSetForAllParts(bool (wxWindow::*func)(const T&), const T& arg)
94 {
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();
98 i != parts.end();
99 ++i )
100 {
101 wxWindow * const child = *i;
102
103 (child->*func)(arg);
104 }
105 }
106
107 wxDECLARE_NO_COPY_TEMPLATE_CLASS(wxCompositeWindow, W);
108};
109
110#endif // _WX_COMPOSITEWIN_H_