Index: include/wx/ownerdrw.h
===================================================================
RCS file: /pack/cvsroots/wxwidgets/wxWidgets/include/wx/ownerdrw.h,v
retrieving revision 1.26
diff --unified -r1.26 ownerdrw.h
--- include/wx/ownerdrw.h 2005/06/07 18:28:47 1.26
+++ include/wx/ownerdrw.h 2007/01/10 16:27:36
@@ -169,6 +169,12 @@
size_t m_nHeight, // font height
m_nMinHeight, // minimum height, as determined by user's system settings
m_nMarginWidth; // space occupied by bitmap to the left of the item
+
+#if defined(__WXMSW__)
+ // Helper function for creating the image for disabled buttons
+ bool wxCreateGreyedImage(const wxImage& in, wxImage& out) ;
+#endif
+
};
#endif // wxUSE_OWNER_DRAWN
Index: src/msw/ownerdrw.cpp
===================================================================
RCS file: /pack/cvsroots/wxwidgets/wxWidgets/src/msw/ownerdrw.cpp,v
retrieving revision 1.62.2.3
diff --unified -r1.62.2.3 ownerdrw.cpp
--- src/msw/ownerdrw.cpp 2006/05/29 17:35:00 1.62.2.3
+++ src/msw/ownerdrw.cpp 2007/01/10 17:20:11
@@ -36,6 +36,7 @@
#include "wx/menuitem.h"
#include "wx/fontutil.h"
#include "wx/module.h"
+#include "wx/image.h"
#if wxUSE_OWNER_DRAWN
@@ -443,6 +444,18 @@
if ( st & wxODDisabled )
{
bmp = GetDisabledBitmap();
+#if defined(__WXMSW__) && wxUSE_IMAGE && wxUSE_WXDIB
+ if ( !bmp.Ok() && m_bmpChecked.Ok() )
+ {
+ // no disabled bitmap specified but we still need to
+ // fill the space in the image list with something, so
+ // we grey out the normal bitmap
+ wxImage imgGreyed;
+ wxCreateGreyedImage(m_bmpChecked.ConvertToImage(), imgGreyed);
+ bmp = wxBitmap(imgGreyed);
+ SetDisabledBitmap(bmp);
+ }
+#endif // defined(__WXMSW__) && wxUSE_IMAGE && wxUSE_WXDIB
}
if ( !bmp.Ok() )
@@ -488,6 +501,75 @@
return true;
}
+
+#if defined(__WXMSW__) && wxUSE_IMAGE
+
+/*
+ * Make a greyed-out image suitable for disabled buttons.
+ * Code copied from common/tbarbase.cpp method wxCreateGreyedImage.
+ */
+
+bool wxOwnerDrawn::wxCreateGreyedImage(const wxImage& src, wxImage& dst)
+{
+ dst = src.Copy();
+
+ unsigned char rBg, gBg, bBg;
+ if ( src.HasMask() )
+ {
+ src.GetOrFindMaskColour(&rBg, &gBg, &bBg);
+ dst.SetMaskColour(rBg, gBg, bBg);
+ }
+ else // assuming the pixels along the edges are of the background color
+ {
+ rBg = src.GetRed(0, 0);
+ gBg = src.GetGreen(0, 0);
+ bBg = src.GetBlue(0, 0);
+ }
+
+ const wxColour colBg(rBg, gBg, bBg);
+
+ const wxColour colDark = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW);
+ const wxColour colLight = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT);
+
+ // Second attempt, just making things monochrome
+ const int width = src.GetWidth();
+ const int height = src.GetHeight();
+
+ for ( int x = 0; x < width; x++ )
+ {
+ for ( int y = 0; y < height; y++ )
+ {
+ const int r = src.GetRed(x, y);
+ const int g = src.GetGreen(x, y);
+ const int b = src.GetBlue(x, y);
+
+ if ( r == rBg && g == gBg && b == bBg )
+ {
+ // Leave the background colour as-is
+ continue;
+ }
+
+ // Change light things to the background colour
+ wxColour col;
+ if ( r >= (colLight.Red() - 50) &&
+ g >= (colLight.Green() - 50) &&
+ b >= (colLight.Blue() - 50) )
+ {
+ col = colBg;
+ }
+ else // Change dark things to really dark
+ {
+ col = colDark;
+ }
+
+ dst.SetRGB(x, y, col.Red(), col.Green(), col.Blue());
+ }
+ }
+
+ return true;
+}
+
+#endif // defined(__WXMSW__) && wxUSE_IMAGE
#endif // wxUSE_OWNER_DRAWN