Added GetBitmap, GetIcon to wxImageList
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32400 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -68,7 +68,8 @@ public:
|
||||
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();
|
||||
@@ -77,6 +78,8 @@ public:
|
||||
int flags = wxIMAGELIST_DRAW_NORMAL,
|
||||
bool solidBackground = false);
|
||||
|
||||
// Internal use only
|
||||
const wxBitmap *GetBitmapPtr(int index) const;
|
||||
private:
|
||||
wxList m_images;
|
||||
|
||||
|
@@ -130,6 +130,12 @@ public:
|
||||
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);
|
||||
|
@@ -202,7 +202,7 @@ bool wxNotebook::InsertPage( size_t pos,
|
||||
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)];
|
||||
|
||||
@@ -250,7 +250,7 @@ int wxNotebook::GetPageImage(size_t nPage) const
|
||||
|
||||
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];
|
||||
|
@@ -107,7 +107,7 @@ int wxGenericImageList::Add( const wxBitmap& bitmap, const wxColour& maskColour
|
||||
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 );
|
||||
|
||||
@@ -116,6 +116,30 @@ const wxBitmap *wxGenericImageList::GetBitmap( int index ) const
|
||||
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 );
|
||||
|
@@ -499,7 +499,7 @@ bool wxNotebook::SetPageImage( size_t page, int image )
|
||||
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() )
|
||||
@@ -673,7 +673,7 @@ bool wxNotebook::InsertPage( size_t position,
|
||||
{
|
||||
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() )
|
||||
|
@@ -496,7 +496,7 @@ printf("begin insert\n");
|
||||
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())
|
||||
|
@@ -499,7 +499,7 @@ bool wxNotebook::SetPageImage( size_t page, int image )
|
||||
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() )
|
||||
@@ -673,7 +673,7 @@ bool wxNotebook::InsertPage( size_t position,
|
||||
{
|
||||
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() )
|
||||
|
@@ -496,7 +496,7 @@ printf("begin insert\n");
|
||||
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())
|
||||
|
@@ -351,7 +351,7 @@ void wxNotebook::MacSetupTabs()
|
||||
|
||||
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 ;
|
||||
|
@@ -457,7 +457,7 @@ void wxNotebook::MacSetupTabs()
|
||||
// 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 ;
|
||||
|
@@ -42,6 +42,7 @@
|
||||
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/image.h"
|
||||
|
||||
#include "wx/msw/imaglist.h"
|
||||
#include "wx/msw/private.h"
|
||||
@@ -293,6 +294,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
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@@ -473,7 +473,7 @@ void wxNotebook::DoDrawTab(wxDC& dc, const wxRect& rect, size_t n)
|
||||
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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user