]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/src/fl/newbmpbtn.cpp
use full 32bit range for the process ids
[wxWidgets.git] / contrib / src / fl / newbmpbtn.cpp
index b811e40c124e5e6e4f8b49fb63c7b9c137c5c8d8..138e9cf1c673f85d1d18b1bb739edeec1494967d 100644 (file)
 #include "wx/fl/newbmpbtn.h"
 #include "wx/utils.h"     // import wxMin,wxMax macros
 
+#ifdef __WXMSW__
+#include "wx/msw/private.h"
+#endif
+
 ///////////// button-label rendering helpers //////////////////
 
 static int* create_array( int width, int height, int fill = 0 )
@@ -516,7 +520,14 @@ void wxNewBitmapButton::RenderLabelImage( wxBitmap*& destBmp, wxBitmap* srcBmp,
                  destBmp->GetHeight() + mMarginY*2, 0 
             );
     }
+    destDc.SelectObject( wxNullBitmap );
+    
+#ifdef __WXMSW__
+    // Map to system colours
+    (void) MapBitmap(destBmp->GetHBITMAP(), destBmp->GetWidth(), destBmp->GetHeight());
+#endif    
 }
+
 void wxNewBitmapButton::RenderAllLabelImages()
 {
     if ( !mIsCreated )
@@ -802,3 +813,49 @@ void wxNewBitmapButton::OnKillFocus( wxFocusEvent& event )
     wxMessageBox("kill-focus for button!");
 }
 
+#ifdef __WXMSW__
+WXHBITMAP wxNewBitmapButton::MapBitmap(WXHBITMAP bitmap, int width, int height)
+{
+    MemoryHDC hdcMem;
+
+    if ( !hdcMem )
+    {
+        wxLogLastError(_T("CreateCompatibleDC"));
+
+        return bitmap;
+    }
+
+    SelectInHDC bmpInHDC(hdcMem, (HBITMAP)bitmap);
+
+    if ( !bmpInHDC )
+    {
+        wxLogLastError(_T("SelectObject"));
+
+        return bitmap;
+    }
+
+    wxCOLORMAP *cmap = wxGetStdColourMap();
+
+    for ( int i = 0; i < width; i++ )
+    {
+        for ( int j = 0; j < height; j++ )
+        {
+            COLORREF pixel = ::GetPixel(hdcMem, i, j);
+
+            for ( size_t k = 0; k < wxSTD_COL_MAX; k++ )
+            {
+                COLORREF col = cmap[k].from;
+                if ( abs(GetRValue(pixel) - GetRValue(col)) < 10 &&
+                     abs(GetGValue(pixel) - GetGValue(col)) < 10 &&
+                     abs(GetBValue(pixel) - GetBValue(col)) < 10 )
+                {
+                    ::SetPixel(hdcMem, i, j, cmap[k].to);
+                    break;
+                }
+            }
+        }
+    }
+
+    return bitmap;
+}
+#endif