]> git.saurik.com Git - wxWidgets.git/commitdiff
construct brush used for painting disabled bitmap buttons dynamically (heavily modifi...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 18 Sep 2004 12:34:45 +0000 (12:34 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 18 Sep 2004 12:34:45 +0000 (12:34 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29197 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/bmpbuttn.h
src/msw/app.cpp
src/msw/bmpbuttn.cpp

index f1d236b1d9621580d5dbc8a1701f25c790886cc6..fed82429c3cc053208e4644bbfab360143f6fc18 100644 (file)
@@ -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)
 };
 
index bcbe186896958c81903345463ae4909ec1e29836..ea195db53c51af28b33d1074fd7505f4e65fe45e 100644 (file)
@@ -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();
index adc1a5e90f5ffc006beef55d4fea6236c643d40c..8a7ff239e0646a16a75a33c9b74551cbb6b5504e 100644 (file)
@@ -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()