From d50dbf7c6a8044a4084f6ffc51aa13d4a2c620c4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 18 Sep 2004 12:34:45 +0000 Subject: [PATCH] construct brush used for painting disabled bitmap buttons dynamically (heavily modified patch 1027243) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29197 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/bmpbuttn.h | 4 +++- src/msw/app.cpp | 19 ------------------ src/msw/bmpbuttn.cpp | 42 +++++++++++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/include/wx/msw/bmpbuttn.h b/include/wx/msw/bmpbuttn.h index f1d236b1d9..fed82429c3 100644 --- a/include/wx/msw/bmpbuttn.h +++ b/include/wx/msw/bmpbuttn.h @@ -48,6 +48,7 @@ public: const wxString& name = wxButtonNameStr); // Implementation + virtual bool SetBackgroundColour(const wxColour& colour); virtual void SetDefault(); virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *item); virtual void DrawFace( WXHDC dc, int left, int top, int right, int bottom, bool sel ); @@ -57,7 +58,8 @@ public: protected: virtual wxSize DoGetBestSize() const; -private: + wxBrush m_brushDisabled; + DECLARE_DYNAMIC_CLASS_NO_COPY(wxBitmapButton) }; diff --git a/src/msw/app.cpp b/src/msw/app.cpp index bcbe186896..ea195db53c 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -111,8 +111,6 @@ const wxChar *wxMDIFrameClassNameNoRedraw = wxT("wxMDIFrameClassNR"); const wxChar *wxMDIChildFrameClassName = wxT("wxMDIChildFrameClass"); const wxChar *wxMDIChildFrameClassNameNoRedraw = wxT("wxMDIChildFrameClassNR"); -HBRUSH wxDisableButtonBrush = (HBRUSH) 0; - // ---------------------------------------------------------------------------- // private functions // ---------------------------------------------------------------------------- @@ -325,20 +323,6 @@ bool wxApp::Initialize(int& argc, wxChar **argv) RegisterWindowClasses(); -#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) - // Create the brush for disabling bitmap buttons - LOGBRUSH lb; - lb.lbStyle = BS_PATTERN; - lb.lbColor = 0; - lb.lbHatch = (int)LoadBitmap( wxhInstance, wxT("wxDISABLE_BUTTON_BITMAP") ); - if ( lb.lbHatch ) - { - wxDisableButtonBrush = ::CreateBrushIndirect( &lb ); - ::DeleteObject( (HGDIOBJ)lb.lbHatch ); - } - //else: wxWidgets resources are probably not linked in -#endif // !__WXMICROWIN__ && !__WXWINCE__ - #if wxUSE_PENWINDOWS wxRegisterPenWin(); #endif @@ -512,9 +496,6 @@ void wxApp::CleanUp() wxCleanUpPenWin(); #endif - if ( wxDisableButtonBrush ) - ::DeleteObject( wxDisableButtonBrush ); - #if wxUSE_OLE #ifdef __WXWINCE__ ::CoUninitialize(); diff --git a/src/msw/bmpbuttn.cpp b/src/msw/bmpbuttn.cpp index adc1a5e90f..8a7ff239e0 100644 --- a/src/msw/bmpbuttn.cpp +++ b/src/msw/bmpbuttn.cpp @@ -29,6 +29,7 @@ #endif #include "wx/msw/private.h" +#include "wx/image.h" // ---------------------------------------------------------------------------- // macros @@ -168,6 +169,20 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, return true; } +bool wxBitmapButton::SetBackgroundColour(const wxColour& colour) +{ + if ( !wxBitmapButtonBase::SetBackgroundColour(colour) ) + { + // didn't change + return false; + } + + // invalidate the brush, it will be recreated the next time it's needed + m_brushDisabled = wxNullBrush; + + return true; +} + // VZ: should be at the very least less than wxDEFAULT_BUTTON_MARGIN #define FOCUS_MARGIN 3 @@ -415,11 +430,28 @@ void wxBitmapButton::DrawButtonFocus( WXHDC dc, int left, int top, int right, DrawFocusRect( (HDC) dc, &rect ); } -extern HBRUSH wxDisableButtonBrush; -void wxBitmapButton::DrawButtonDisable( WXHDC dc, int left, int top, int right, - int bottom, bool with_marg ) +void +wxBitmapButton::DrawButtonDisable( WXHDC dc, + int left, int top, int right, int bottom, + bool with_marg ) { - HBRUSH old = (HBRUSH) SelectObject( (HDC) dc, wxDisableButtonBrush ); + if ( !m_brushDisabled.Ok() ) + { + // draw a bitmap with two black and two background colour pixels + wxBitmap bmp(2, 2); + wxMemoryDC dc; + dc.SelectObject(bmp); + dc.SetPen(*wxBLACK_PEN); + dc.DrawPoint(0, 0); + dc.DrawPoint(1, 1); + dc.SetPen(GetBackgroundColour()); + dc.DrawPoint(0, 1); + dc.DrawPoint(1, 0); + + m_brushDisabled = wxBrush(bmp); + } + + SelectInHDC selectBrush((HDC)dc, GetHbrushOf(m_brushDisabled)); // ROP for "dest |= pattern" operation -- as it doesn't have a standard // name, give it our own @@ -434,8 +466,6 @@ void wxBitmapButton::DrawButtonDisable( WXHDC dc, int left, int top, int right, } ::PatBlt( (HDC) dc, left, top, right, bottom, PATTERNPAINT); - - ::SelectObject( (HDC) dc, old ); } void wxBitmapButton::SetDefault()