]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/imaglist.cpp
1. derive wxGTK wxRadioBox from wxRadioBoxBase now, as in all other ports
[wxWidgets.git] / src / msw / imaglist.cpp
index ca1952008269fdf309aded771c08b0e5a9afbd3f..39c071e1fdb390225b75e52737062fdc351d48aa 100644 (file)
 // headers
 // ----------------------------------------------------------------------------
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-    #pragma implementation "imaglist.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
@@ -42,6 +38,7 @@
 
 #include "wx/log.h"
 #include "wx/intl.h"
+#include "wx/image.h"
 
 #include "wx/msw/imaglist.h"
 #include "wx/msw/private.h"
@@ -202,7 +199,7 @@ bool wxImageList::Replace(int index,
                                 GetHbitmapOf(bitmap), hbmpMask) != 0;
     if ( !ok )
     {
-        wxLogLastError(wxT("ImageList_Add()"));
+        wxLogLastError(wxT("ImageList_Replace()"));
     }
 
     ::DeleteObject(hbmpMask);
@@ -293,6 +290,62 @@ bool wxImageList::Draw(int index,
     return ok;
 }
 
+// Get the bitmap
+wxBitmap wxImageList::GetBitmap(int index) const
+{
+    int bmp_width = 0, bmp_height = 0;
+    GetSize(index, bmp_width, bmp_height);
+
+    wxBitmap bitmap(bmp_width, bmp_height);
+    wxMemoryDC dc;
+    dc.SelectObject(bitmap);
+
+    // draw it the first time to find a suitable mask colour
+    ((wxImageList*)this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
+    dc.SelectObject(wxNullBitmap);
+
+    // find the suitable mask colour
+    wxImage image = bitmap.ConvertToImage();
+    unsigned char r = 0, g = 0, b = 0;
+    image.FindFirstUnusedColour(&r, &g, &b);
+
+    // redraw whole image and bitmap in the mask colour
+    image.Create(bmp_width, bmp_height);
+    image.Replace(0, 0, 0, r, g, b);
+    bitmap = wxBitmap(image);
+
+    // redraw icon over the mask colour to actually draw it
+    dc.SelectObject(bitmap);
+    ((wxImageList*)this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
+    dc.SelectObject(wxNullBitmap);
+
+    // get the image, set the mask colour and convert back to get transparent bitmap
+    image = bitmap.ConvertToImage();
+    image.SetMaskColour(r, g, b);
+    bitmap = wxBitmap(image);
+    
+    return bitmap;
+}
+
+// Get the icon
+wxIcon wxImageList::GetIcon(int index) const
+{
+    HICON hIcon = ImageList_ExtractIcon(0, GetHImageList(), index);
+    if (hIcon)
+    {
+        wxIcon icon;
+        icon.SetHICON((WXHICON)hIcon);
+        
+        int iconW, iconH;
+        GetSize(index, iconW, iconH);
+        icon.SetSize(iconW, iconH);
+        
+        return icon;
+    }
+    else               
+        return wxNullIcon;
+}
+
 // ----------------------------------------------------------------------------
 // helpers
 // ----------------------------------------------------------------------------