]>
Commit | Line | Data |
---|---|---|
bbcf2821 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/generic/custombgwin.h | |
3 | // Purpose: Generic implementation of wxCustomBackgroundWindow. | |
4 | // Author: Vadim Zeitlin | |
5 | // Created: 2011-10-10 | |
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_GENERIC_CUSTOMBGWIN_H_ | |
12 | #define _WX_GENERIC_CUSTOMBGWIN_H_ | |
13 | ||
14 | #include "wx/bitmap.h" | |
15 | ||
16 | // A helper to avoid template bloat: this class contains all type-independent | |
17 | // code of wxCustomBackgroundWindow<> below. | |
18 | class wxCustomBackgroundWindowGenericBase : public wxCustomBackgroundWindowBase | |
19 | { | |
20 | public: | |
21 | wxCustomBackgroundWindowGenericBase() { } | |
22 | ||
23 | protected: | |
24 | void DoEraseBackground(wxEraseEvent& event, wxWindow* win) | |
25 | { | |
26 | wxDC& dc = *event.GetDC(); | |
27 | ||
28 | const wxSize clientSize = win->GetClientSize(); | |
29 | const wxSize bitmapSize = m_bitmapBg.GetSize(); | |
30 | ||
31 | for ( int x = 0; x < clientSize.x; x += bitmapSize.x ) | |
32 | { | |
33 | for ( int y = 0; y < clientSize.y; y += bitmapSize.y ) | |
34 | { | |
35 | dc.DrawBitmap(m_bitmapBg, x, y); | |
36 | } | |
37 | } | |
38 | } | |
39 | ||
40 | ||
41 | // The bitmap used for painting the background if valid. | |
42 | wxBitmap m_bitmapBg; | |
43 | ||
44 | ||
45 | wxDECLARE_NO_COPY_CLASS(wxCustomBackgroundWindowGenericBase); | |
46 | }; | |
47 | ||
48 | // ---------------------------------------------------------------------------- | |
49 | // wxCustomBackgroundWindow | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
52 | template <class W> | |
53 | class wxCustomBackgroundWindow : public W, | |
54 | public wxCustomBackgroundWindowGenericBase | |
55 | { | |
56 | public: | |
57 | typedef W BaseWindowClass; | |
58 | ||
59 | wxCustomBackgroundWindow() { } | |
60 | ||
61 | protected: | |
62 | virtual void DoSetBackgroundBitmap(const wxBitmap& bmp) | |
63 | { | |
64 | m_bitmapBg = bmp; | |
65 | ||
66 | if ( m_bitmapBg.IsOk() ) | |
67 | { | |
68 | BaseWindowClass::Connect | |
69 | ( | |
70 | wxEVT_ERASE_BACKGROUND, | |
71 | wxEraseEventHandler(wxCustomBackgroundWindow::OnEraseBackground) | |
72 | ); | |
73 | } | |
74 | else | |
75 | { | |
76 | BaseWindowClass::Disconnect | |
77 | ( | |
78 | wxEVT_ERASE_BACKGROUND, | |
79 | wxEraseEventHandler(wxCustomBackgroundWindow::OnEraseBackground) | |
80 | ); | |
81 | } | |
82 | } | |
83 | ||
84 | private: | |
85 | // Event handler for erasing the background which is only used when we have | |
86 | // a valid background bitmap. | |
87 | void OnEraseBackground(wxEraseEvent& event) | |
88 | { | |
89 | DoEraseBackground(event, this); | |
90 | } | |
91 | ||
92 | ||
93 | wxDECLARE_NO_COPY_TEMPLATE_CLASS(wxCustomBackgroundWindow, W); | |
94 | }; | |
95 | ||
96 | #endif // _WX_GENERIC_CUSTOMBGWIN_H_ |