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