// headers
// ----------------------------------------------------------------------------
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "bitmap.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
unsigned char* pixels = dib.GetData();
for (int idx=0; idx<w*h*4; idx+=4)
{
- if (pixels[idx+3] != 0)
+ if (pixels[idx+3] != 0)
{
// If there is an alpha byte that is non-zero then set the
// alpha flag and bail out of the loop.
// wxWin convention
refData->SetMask(wxInvertMask(iconInfo.hbmMask, w, h));
}
-
+
// delete the old one now as we don't need it any more
::DeleteObject(iconInfo.hbmMask);
wxDIB dib(image);
if ( !dib.IsOk() )
return false;
-
+ if (depth == -1)
+ depth = dib.GetDepth(); // Get depth from image if none specified
// store the bitmap parameters
wxBitmapRefData *refData = new wxBitmapRefData;
hbitmap = dib.Detach();
refData->m_isDIB = true;
- refData->m_depth = dib.GetDepth();
+ refData->m_depth = depth;
}
#ifndef ALWAYS_USE_DIB
else // we need to convert DIB to DDB
{
hbitmap = dib.CreateDDB((HDC)hdc);
- refData->m_depth = depth == -1 ? dib.GetDepth() : depth;
+ refData->m_depth = depth;
}
#endif // !ALWAYS_USE_DIB
SetMask(new wxMask((WXHBITMAP)hbitmap));
}
- delete data;
+ delete[] data;
}
return true;
#ifndef __WXMICROWIN__
// handle alpha channel, if any
if (HasAlpha())
- ret.UseAlpha();
+ ret.UseAlpha();
// copy bitmap data
MemoryHDC dcSrc,
HBITMAP hDIB;
if ( !GetBitmapData()->m_isDIB )
{
- wxCHECK_MSG( !GetBitmapData()->m_dib, FALSE,
+ wxCHECK_MSG( !GetBitmapData()->m_dib, NULL,
_T("GetRawData() may be called only once") );
wxDIB *dib = new wxDIB(*this);
// this value must be 1, 4, 8 or 24 so PixelDepth can only be
lpDIBheader->bmiHeader.biBitCount = (WORD)(bitsPerPixel);
lpDIBheader->bmiHeader.biCompression = BI_RGB;
- lpDIBheader->bmiHeader.biSizeImage = xSize * abs(ySize) * bitsPerPixel >> 3;
+ lpDIBheader->bmiHeader.biSizeImage = (xSize * abs(ySize) * bitsPerPixel) >> 3;
lpDIBheader->bmiHeader.biClrUsed = 256;
return 0;
}
- wxMask* mask;
- wxBitmap newbmp;
if ( bmp.HasAlpha() )
{
- // Convert alpha to a mask. NOTE: It would be better to actually put
- // the alpha into the icon instead of making a mask, but I don't have
- // time to figure that out today.
- wxImage img = bmp.ConvertToImage();
- img.ConvertAlphaToMask();
- newbmp = wxBitmap(img);
- mask = newbmp.GetMask();
- }
- else
- {
- mask = bmp.GetMask();
+ // Create an empty mask bitmap.
+ // it doesn't seem to work if we mess with the mask at all.
+ HBITMAP hMonoBitmap = CreateBitmap(bmp.GetWidth(),bmp.GetHeight(),1,1,NULL);
+
+ ICONINFO iconInfo;
+ wxZeroMemory(iconInfo);
+ iconInfo.fIcon = iconWanted; // do we want an icon or a cursor?
+ if ( !iconWanted )
+ {
+ iconInfo.xHotspot = hotSpotX;
+ iconInfo.yHotspot = hotSpotY;
+ }
+
+ iconInfo.hbmMask = hMonoBitmap;
+ iconInfo.hbmColor = GetHbitmapOf(bmp);
+
+ HICON hicon = ::CreateIconIndirect(&iconInfo);
+
+ ::DeleteObject(hMonoBitmap);
+
+ return hicon;
}
-
+
+ wxMask* mask = bmp.GetMask();
+
if ( !mask )
{
// we must have a mask for an icon, so even if it's probably incorrect,