// Replaces a bitmap, optionally passing a mask bitmap. // Note that wxImageList creates new bitmaps, so you may delete // 'bitmap' and 'mask'. bool wxImageList::Replace(int index, const wxBitmap& bitmap, const wxBitmap& mask) { HBITMAP hbmp; #if wxUSE_WXDIB && wxUSE_IMAGE // See the comment in Add() above. AutoHBITMAP hbmpRelease; if ( bitmap.HasAlpha() ) { hbmp = wxDIB(bitmap.ConvertToImage(), wxDIB::PixelFormat_NotPreMultiplied).Detach(); hbmpRelease.Init(hbmp); } else #endif // wxUSE_WXDIB && wxUSE_IMAGE hbmp = GetHbitmapOf(bitmap); AutoHBITMAP hbmpMask(GetMaskForImage(bitmap, mask)); if ( !ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) ) { wxLogLastError(wxT("ImageList_Replace()")); return false; } return true; }
// Adds a bitmap, and optionally a mask bitmap. // Note that wxImageList creates new bitmaps, so you may delete // 'bitmap' and 'mask'. int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask) { HBITMAP hbmp; #if wxUSE_WXDIB && wxUSE_IMAGE // wxBitmap normally stores alpha in pre-multiplied format but // ImageList_Draw() does pre-multiplication internally so we need to undo // the pre-multiplication here. Converting back and forth like this is, of // course, very inefficient but it's better than wrong appearance so we do // this for now until a better way can be found. AutoHBITMAP hbmpRelease; if ( bitmap.HasAlpha() ) { hbmp = wxDIB(bitmap.ConvertToImage(), wxDIB::PixelFormat_NotPreMultiplied).Detach(); hbmpRelease.Init(hbmp); } else #endif // wxUSE_WXDIB && wxUSE_IMAGE hbmp = GetHbitmapOf(bitmap); // Use mask only if we don't have alpha, the bitmap isn't drawn correctly // if we use both. AutoHBITMAP hbmpMask; if ( !bitmap.HasAlpha() ) hbmpMask.Init(GetMaskForImage(bitmap, mask)); int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask); if ( index == -1 ) { wxLogError(_("Couldn't add an image to the image list.")); } return index; }
// Adds a bitmap, using the specified colour to create the mask bitmap // Note that wxImageList creates new bitmaps, so you may delete // 'bitmap'. int wxImageList::Add(const wxBitmap& bitmap, const wxColour& maskColour) { HBITMAP hbmp; #if wxUSE_WXDIB && wxUSE_IMAGE // See the comment in overloaded Add() above. AutoHBITMAP hbmpRelease; if ( bitmap.HasAlpha() ) { hbmp = wxDIB(bitmap.ConvertToImage(), wxDIB::PixelFormat_NotPreMultiplied).Detach(); hbmpRelease.Init(hbmp); } else #endif // wxUSE_WXDIB && wxUSE_IMAGE hbmp = GetHbitmapOf(bitmap); int index = ImageList_AddMasked(GetHImageList(), hbmp, wxColourToRGB(maskColour)); if ( index == -1 ) { wxLogError(_("Couldn't add an image to the image list.")); } return index; }
size_t wxBitmapDataObject::GetDataSize() const { #if wxUSE_WXDIB && !defined(__WXWINCE__) return wxDIB::ConvertFromBitmap(NULL, GetHbitmapOf(GetBitmap())); #else return 0; #endif }
bool wxDIB::Create(const wxBitmap& bmp) { wxCHECK_MSG( bmp.Ok(), false, wxT("wxDIB::Create(): invalid bitmap") ); if ( !Create(GetHbitmapOf(bmp)) ) return false; m_hasAlpha = bmp.HasAlpha(); return true; }
bool wxBitmapDataObject::GetDataHere(void *buf) const { #if wxUSE_WXDIB && !defined(__WXWINCE__) BITMAPINFO * const pbi = (BITMAPINFO *)buf; return wxDIB::ConvertFromBitmap(pbi, GetHbitmapOf(GetBitmap())) != 0; #else wxUnusedVar(buf); return false; #endif }
// Adds a bitmap, using the specified colour to create the mask bitmap // Note that wxImageList creates new bitmaps, so you may delete // 'bitmap'. int wxImageList::Add(const wxBitmap& bitmap, const wxColour& maskColour) { int index = ImageList_AddMasked(GetHImageList(), GetHbitmapOf(bitmap), wxColourToRGB(maskColour)); if ( index == -1 ) { wxLogError(_("Couldn't add an image to the image list.")); } return index; }
// Adds a bitmap, and optionally a mask bitmap. // Note that wxImageList creates new bitmaps, so you may delete // 'bitmap' and 'mask'. int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask) { HBITMAP hbmp; bool useMask; #if wxUSE_WXDIB && wxUSE_IMAGE // wxBitmap normally stores alpha in pre-multiplied format but // ImageList_Draw() does pre-multiplication internally so we need to undo // the pre-multiplication here. Converting back and forth like this is, of // course, very inefficient but it's better than wrong appearance so we do // this for now until a better way can be found. AutoHBITMAP hbmpRelease; if ( bitmap.HasAlpha() ) { wxImage img = bitmap.ConvertToImage(); // For comctl32.dll < 6 remove alpha channel from image // to prevent possible interferences with the mask. if ( wxApp::GetComCtl32Version() < 600 ) { img.ClearAlpha(); useMask = true; } else { useMask = false; } hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach(); hbmpRelease.Init(hbmp); } else #endif // wxUSE_WXDIB && wxUSE_IMAGE { hbmp = GetHbitmapOf(bitmap); useMask = true; } // Use mask only if we don't have alpha, the bitmap isn't drawn correctly // if we use both. AutoHBITMAP hbmpMask; if ( useMask ) hbmpMask.Init(GetMaskForImage(bitmap, mask)); int index = ImageList_Add(GetHImageList(), hbmp, hbmpMask); if ( index == -1 ) { wxLogError(_("Couldn't add an image to the image list.")); } return index; }
// Adds a bitmap, and optionally a mask bitmap. // Note that wxImageList creates new bitmaps, so you may delete // 'bitmap' and 'mask'. int wxImageList::Add(const wxBitmap& bitmap, const wxBitmap& mask) { HBITMAP hbmpMask = GetMaskForImage(bitmap, mask); int index = ImageList_Add(GetHImageList(), GetHbitmapOf(bitmap), hbmpMask); if ( index == -1 ) { wxLogError(_("Couldn't add an image to the image list.")); } ::DeleteObject(hbmpMask); return index; }
// Replaces a bitmap, optionally passing a mask bitmap. // Note that wxImageList creates new bitmaps, so you may delete // 'bitmap' and 'mask'. bool wxImageList::Replace(int index, const wxBitmap& bitmap, const wxBitmap& mask) { HBITMAP hbmpMask = GetMaskForImage(bitmap, mask); bool ok = ImageList_Replace(GetHImageList(), index, GetHbitmapOf(bitmap), hbmpMask) != 0; if ( !ok ) { wxLogLastError(wxT("ImageList_Replace()")); } ::DeleteObject(hbmpMask); return ok; }
// Replaces a bitmap, optionally passing a mask bitmap. // Note that wxImageList creates new bitmaps, so you may delete // 'bitmap' and 'mask'. bool wxImageList::Replace(int index, const wxBitmap& bitmap, const wxBitmap& mask) { HBITMAP hbmp; bool useMask; #if wxUSE_WXDIB && wxUSE_IMAGE // See the comment in Add() above. AutoHBITMAP hbmpRelease; if ( bitmap.HasAlpha() ) { wxImage img = bitmap.ConvertToImage(); if ( wxApp::GetComCtl32Version() < 600 ) { img.ClearAlpha(); useMask = true; } else { useMask = false; } hbmp = wxDIB(img, wxDIB::PixelFormat_NotPreMultiplied).Detach(); hbmpRelease.Init(hbmp); } else #endif // wxUSE_WXDIB && wxUSE_IMAGE { hbmp = GetHbitmapOf(bitmap); useMask = true; } AutoHBITMAP hbmpMask; if ( useMask ) hbmpMask.Init(GetMaskForImage(bitmap, mask)); if ( !ImageList_Replace(GetHImageList(), index, hbmp, hbmpMask) ) { wxLogLastError(wxT("ImageList_Replace()")); return false; } return true; }
// returns the HBITMAP to use in MENUITEMINFO HBITMAP wxMenuItem::GetHBitmapForMenu(bool checked) { // Under versions of Windows older than Vista we can't pass HBITMAP // directly as hbmpItem for 2 reasons: // 1. We can't draw it with transparency then (this is not // very important now but would be with themed menu bg) // 2. Worse, Windows inverts the bitmap for the selected // item and this looks downright ugly // // So we prefer to instead draw it ourselves in MSWOnDrawItem().by using // HBMMENU_CALLBACK when inserting it // // However under Vista using HBMMENU_CALLBACK causes the entire menu to be // drawn using the classic theme instead of the current one and it does // handle transparency just fine so do use the real bitmap there #if wxUSE_IMAGE if ( wxGetWinVersion() >= wxWinVersion_Vista ) { wxBitmap bmp = GetBitmap(checked); if ( bmp.IsOk() ) { // we must use PARGB DIB for the menu bitmaps so ensure that we do wxImage img(bmp.ConvertToImage()); if ( !img.HasAlpha() ) { img.InitAlpha(); SetBitmap(img, checked); } return GetHbitmapOf(GetBitmap(checked)); } //else: bitmap is not set return NULL; } #endif // wxUSE_IMAGE return HBMMENU_CALLBACK; }
static HBITMAP GetMaskForImage(const wxBitmap& bitmap, const wxBitmap& mask) { #if wxUSE_IMAGE wxBitmap bitmapWithMask; #endif // wxUSE_IMAGE HBITMAP hbmpMask; wxMask *pMask; bool deleteMask = false; if ( mask.IsOk() ) { hbmpMask = GetHbitmapOf(mask); pMask = NULL; } else { pMask = bitmap.GetMask(); #if wxUSE_IMAGE // check if we don't have alpha in this bitmap -- we can create a mask // from it (and we need to do it for the older systems which don't // support 32bpp bitmaps natively) if ( !pMask ) { wxImage img(bitmap.ConvertToImage()); if ( img.HasAlpha() ) { img.ConvertAlphaToMask(); bitmapWithMask = wxBitmap(img); pMask = bitmapWithMask.GetMask(); } } #endif // wxUSE_IMAGE if ( !pMask ) { // use the light grey count as transparent: the trouble here is // that the light grey might have been changed by Windows behind // our back, so use the standard colour map to get its real value wxCOLORMAP *cmap = wxGetStdColourMap(); wxColour col; wxRGBToColour(col, cmap[wxSTD_COL_BTNFACE].from); pMask = new wxMask(bitmap, col); deleteMask = true; } hbmpMask = (HBITMAP)pMask->GetMaskBitmap(); } // windows mask convention is opposite to the wxWidgets one HBITMAP hbmpMaskInv = wxInvertMask(hbmpMask); if ( deleteMask ) { delete pMask; } return hbmpMaskInv; }