custombgwin.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/custombgwin.h
  3. // Purpose: wxMSW 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. #ifndef _WX_MSW_CUSTOMBGWIN_H_
  10. #define _WX_MSW_CUSTOMBGWIN_H_
  11. #include "wx/bitmap.h"
  12. #include "wx/brush.h"
  13. // ----------------------------------------------------------------------------
  14. // wxCustomBackgroundWindow
  15. // ----------------------------------------------------------------------------
  16. template <class W>
  17. class wxCustomBackgroundWindow : public W,
  18. public wxCustomBackgroundWindowBase
  19. {
  20. public:
  21. typedef W BaseWindowClass;
  22. wxCustomBackgroundWindow() { m_backgroundBrush = NULL; }
  23. virtual ~wxCustomBackgroundWindow() { delete m_backgroundBrush; }
  24. protected:
  25. virtual void DoSetBackgroundBitmap(const wxBitmap& bmp)
  26. {
  27. delete m_backgroundBrush;
  28. m_backgroundBrush = bmp.IsOk() ? new wxBrush(bmp) : NULL;
  29. // Our transparent children should use our background if we have it,
  30. // otherwise try to restore m_inheritBgCol to some reasonable value: true
  31. // if we also have non-default background colour or false otherwise.
  32. BaseWindowClass::m_inheritBgCol = bmp.IsOk()
  33. || BaseWindowClass::UseBgCol();
  34. }
  35. virtual WXHBRUSH MSWGetCustomBgBrush()
  36. {
  37. if ( m_backgroundBrush )
  38. return (WXHBRUSH)m_backgroundBrush->GetResourceHandle();
  39. return BaseWindowClass::MSWGetCustomBgBrush();
  40. }
  41. wxBrush *m_backgroundBrush;
  42. wxDECLARE_NO_COPY_TEMPLATE_CLASS(wxCustomBackgroundWindow, W);
  43. };
  44. #endif // _WX_MSW_CUSTOMBGWIN_H_