1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/custombgwin.h
3 // Purpose: Generic implementation of wxCustomBackgroundWindow.
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_GENERIC_CUSTOMBGWIN_H_
12 #define _WX_GENERIC_CUSTOMBGWIN_H_
14 #include "wx/bitmap.h"
16 // A helper to avoid template bloat: this class contains all type-independent
17 // code of wxCustomBackgroundWindow<> below.
18 class wxCustomBackgroundWindowGenericBase
: public wxCustomBackgroundWindowBase
21 wxCustomBackgroundWindowGenericBase() { }
24 void DoEraseBackground(wxEraseEvent
& event
, wxWindow
* win
)
26 wxDC
& dc
= *event
.GetDC();
28 const wxSize clientSize
= win
->GetClientSize();
29 const wxSize bitmapSize
= m_bitmapBg
.GetSize();
31 for ( int x
= 0; x
< clientSize
.x
; x
+= bitmapSize
.x
)
33 for ( int y
= 0; y
< clientSize
.y
; y
+= bitmapSize
.y
)
35 dc
.DrawBitmap(m_bitmapBg
, x
, y
);
41 // The bitmap used for painting the background if valid.
45 wxDECLARE_NO_COPY_CLASS(wxCustomBackgroundWindowGenericBase
);
48 // ----------------------------------------------------------------------------
49 // wxCustomBackgroundWindow
50 // ----------------------------------------------------------------------------
53 class wxCustomBackgroundWindow
: public W
,
54 public wxCustomBackgroundWindowGenericBase
57 typedef W BaseWindowClass
;
59 wxCustomBackgroundWindow() { }
62 virtual void DoSetBackgroundBitmap(const wxBitmap
& bmp
)
66 if ( m_bitmapBg
.IsOk() )
68 BaseWindowClass::Connect
70 wxEVT_ERASE_BACKGROUND
,
71 wxEraseEventHandler(wxCustomBackgroundWindow::OnEraseBackground
)
76 BaseWindowClass::Disconnect
78 wxEVT_ERASE_BACKGROUND
,
79 wxEraseEventHandler(wxCustomBackgroundWindow::OnEraseBackground
)
85 // Event handler for erasing the background which is only used when we have
86 // a valid background bitmap.
87 void OnEraseBackground(wxEraseEvent
& event
)
89 DoEraseBackground(event
, this);
93 wxDECLARE_NO_COPY_TEMPLATE_CLASS(wxCustomBackgroundWindow
, W
);
96 #endif // _WX_GENERIC_CUSTOMBGWIN_H_