1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/custombgwin.h
3 // Purpose: Generic implementation of wxCustomBackgroundWindow.
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_GENERIC_CUSTOMBGWIN_H_
11 #define _WX_GENERIC_CUSTOMBGWIN_H_
13 #include "wx/bitmap.h"
15 // A helper to avoid template bloat: this class contains all type-independent
16 // code of wxCustomBackgroundWindow<> below.
17 class wxCustomBackgroundWindowGenericBase
: public wxCustomBackgroundWindowBase
20 wxCustomBackgroundWindowGenericBase() { }
23 void DoEraseBackground(wxEraseEvent
& event
, wxWindow
* win
)
25 wxDC
& dc
= *event
.GetDC();
27 const wxSize clientSize
= win
->GetClientSize();
28 const wxSize bitmapSize
= m_bitmapBg
.GetSize();
30 for ( int x
= 0; x
< clientSize
.x
; x
+= bitmapSize
.x
)
32 for ( int y
= 0; y
< clientSize
.y
; y
+= bitmapSize
.y
)
34 dc
.DrawBitmap(m_bitmapBg
, x
, y
);
40 // The bitmap used for painting the background if valid.
44 wxDECLARE_NO_COPY_CLASS(wxCustomBackgroundWindowGenericBase
);
47 // ----------------------------------------------------------------------------
48 // wxCustomBackgroundWindow
49 // ----------------------------------------------------------------------------
52 class wxCustomBackgroundWindow
: public W
,
53 public wxCustomBackgroundWindowGenericBase
56 typedef W BaseWindowClass
;
58 wxCustomBackgroundWindow() { }
61 virtual void DoSetBackgroundBitmap(const wxBitmap
& bmp
)
65 if ( m_bitmapBg
.IsOk() )
67 BaseWindowClass::Connect
69 wxEVT_ERASE_BACKGROUND
,
70 wxEraseEventHandler(wxCustomBackgroundWindow::OnEraseBackground
)
75 BaseWindowClass::Disconnect
77 wxEVT_ERASE_BACKGROUND
,
78 wxEraseEventHandler(wxCustomBackgroundWindow::OnEraseBackground
)
84 // Event handler for erasing the background which is only used when we have
85 // a valid background bitmap.
86 void OnEraseBackground(wxEraseEvent
& event
)
88 DoEraseBackground(event
, this);
92 wxDECLARE_NO_COPY_TEMPLATE_CLASS(wxCustomBackgroundWindow
, W
);
95 #endif // _WX_GENERIC_CUSTOMBGWIN_H_