int Add( const wxBitmap& bitmap );
int Add( const wxBitmap& bitmap, const wxBitmap& mask );
int Add( const wxBitmap& bitmap, const wxColour& maskColour );
- const wxBitmap *GetBitmap(int index) const;
+ wxBitmap GetBitmap(int index) const;
+ wxIcon GetIcon(int index) const;
bool Replace( int index, const wxBitmap &bitmap );
bool Remove( int index );
bool RemoveAll();
int flags = wxIMAGELIST_DRAW_NORMAL,
bool solidBackground = false);
+ // Internal use only
+ const wxBitmap *GetBitmapPtr(int index) const;
private:
wxList m_images;
int flags = wxIMAGELIST_DRAW_NORMAL,
bool solidBackground = false);
+ // Get a bitmap
+ wxBitmap GetBitmap(int index) const;
+
+ // Get an icon
+ wxIcon GetIcon(int index) const;
+
// TODO: miscellaneous functionality
/*
wxIcon *MakeIcon(int index);
m_pages.Insert(page,pos);
NSTabViewItem *tvitem = [[WXCTabViewImageItem alloc] initWithIdentifier:nil];
[tvitem setLabel: wxNSStringWithWxString(title)];
- const wxBitmap *bmp = (imageId!=-1)?m_imageList->GetBitmap(imageId):NULL;
+ const wxBitmap *bmp = (imageId!=-1)?m_imageList->GetBitmapPtr(imageId):NULL;
if(bmp)
[(WXCTabViewImageItem*) tvitem setImage: bmp->GetNSImage(true)];
bool wxNotebook::SetPageImage(size_t nPage, int nImage)
{
- const wxBitmap *bmp = nImage!=-1?m_imageList->GetBitmap(nImage):NULL;
+ const wxBitmap *bmp = nImage!=-1?m_imageList->GetBitmapPtr(nImage):NULL;
if(!bmp)
return false;
NSTabViewItem *tvitem = [GetNSTabView() tabViewItemAtIndex: nPage];
return Add(wxBitmap(img));
}
-const wxBitmap *wxGenericImageList::GetBitmap( int index ) const
+const wxBitmap *wxGenericImageList::GetBitmapPtr( int index ) const
{
wxList::compatibility_iterator node = m_images.Item( index );
return (wxBitmap*)node->GetData();
}
+// Get the bitmap
+wxBitmap wxImageList::GetBitmap(int index) const
+{
+ const wxBitmap* bmp = GetBitmapPtr(index);
+ if (bmp)
+ return *bmp;
+ else
+ return wxNullBitmap;
+}
+
+// Get the icon
+wxIcon wxImageList::GetIcon(int index) const
+{
+ const wxBitmap* bmp = GetBitmapPtr(index);
+ if (bmp)
+ {
+ wxIcon icon;
+ icon.CopyFromBitmap(*bmp);
+ return icon;
+ }
+ else
+ return wxNullIcon;
+}
+
bool wxGenericImageList::Replace( int index, const wxBitmap &bitmap )
{
wxList::compatibility_iterator node = m_images.Item( index );
wxASSERT( m_imageList != NULL ); /* Just in case */
/* Construct the new pixmap */
- const wxBitmap *bmp = m_imageList->GetBitmap(image);
+ const wxBitmap *bmp = m_imageList->GetBitmapPtr(image);
GdkPixmap *pixmap = bmp->GetPixmap();
GdkBitmap *mask = (GdkBitmap*) NULL;
if ( bmp->GetMask() )
{
wxASSERT( m_imageList != NULL );
- const wxBitmap *bmp = m_imageList->GetBitmap(imageId);
+ const wxBitmap *bmp = m_imageList->GetBitmapPtr(imageId);
GdkPixmap *pixmap = bmp->GetPixmap();
GdkBitmap *mask = (GdkBitmap*) NULL;
if ( bmp->GetMask() )
const wxBitmap *bmp;
const wxImageList *list;
if ((list = GetImageList(wxIMAGE_LIST_NORMAL)) != NULL)
- if ((bmp = list->GetBitmap(image)) != NULL)
+ if ((bmp = list->GetBitmapPtr(image)) != NULL)
if (bmp->Ok()) {
GdkBitmap *mask = NULL;
if (bmp->GetMask())
wxASSERT( m_imageList != NULL ); /* Just in case */
/* Construct the new pixmap */
- const wxBitmap *bmp = m_imageList->GetBitmap(image);
+ const wxBitmap *bmp = m_imageList->GetBitmapPtr(image);
GdkPixmap *pixmap = bmp->GetPixmap();
GdkBitmap *mask = (GdkBitmap*) NULL;
if ( bmp->GetMask() )
{
wxASSERT( m_imageList != NULL );
- const wxBitmap *bmp = m_imageList->GetBitmap(imageId);
+ const wxBitmap *bmp = m_imageList->GetBitmapPtr(imageId);
GdkPixmap *pixmap = bmp->GetPixmap();
GdkBitmap *mask = (GdkBitmap*) NULL;
if ( bmp->GetMask() )
const wxBitmap *bmp;
const wxImageList *list;
if ((list = GetImageList(wxIMAGE_LIST_NORMAL)) != NULL)
- if ((bmp = list->GetBitmap(image)) != NULL)
+ if ((bmp = list->GetBitmapPtr(image)) != NULL)
if (bmp->Ok()) {
GdkBitmap *mask = NULL;
if (bmp->GetMask())
if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 )
{
- const wxBitmap* bmap = GetImageList()->GetBitmap( GetPageImage(ii ) ) ;
+ const wxBitmap* bmap = GetImageList()->GetBitmapPtr( GetPageImage(ii ) ) ;
if ( bmap )
{
ControlButtonContentInfo info ;
// afterwards Unregister it (IconRef is ref counted, so it will stay on the tab even if we
// unregister it) in case this will ever lead to having the same icon everywhere add some kind
// of static counter
- const wxBitmap* bmap = GetImageList()->GetBitmap( GetPageImage(ii ) ) ;
+ const wxBitmap* bmap = GetImageList()->GetBitmapPtr( GetPageImage(ii ) ) ;
if ( bmap )
{
wxBitmap scaledBitmap ;
#include "wx/log.h"
#include "wx/intl.h"
+#include "wx/image.h"
#include "wx/msw/imaglist.h"
#include "wx/msw/private.h"
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
// ----------------------------------------------------------------------------
m_imageList->Draw(image, dc, 0, 0, wxIMAGELIST_DRAW_NORMAL, true);
dc.SelectObject(wxNullBitmap);
#else
- bmp = *m_imageList->GetBitmap(image);
+ bmp = m_imageList->GetBitmap(image);
#endif
}