#include "wx/msw/private.h"
#include "wx/log.h"
+#if !defined(__WXMICROWIN__)
#include "wx/msw/dib.h"
+#endif
+
#include "wx/image.h"
+#include "wx/xpmdecod.h"
// missing from mingw32 header
#ifndef CLR_INVALID
bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon)
{
+#ifndef __WXMICROWIN__
// it may be either HICON or HCURSOR
HICON hicon = (HICON)icon.GetHandle();
#endif // WXWIN_COMPATIBILITY_2
return TRUE;
+#else
+ return FALSE;
+#endif
}
#endif // Win32
{
Init();
+#ifndef __WXMICROWIN__
wxBitmapRefData *refData = new wxBitmapRefData;
m_refData = refData;
// we assume that it is in XBM format which is not quite the same as
// the format CreateBitmap() wants because the order of bytes in the
// line is inversed!
- static const size_t bytesPerLine = (width + 7) / 8;
- static const size_t padding = bytesPerLine % 2;
- static const size_t len = height * ( padding + bytesPerLine );
+ const size_t bytesPerLine = (width + 7) / 8;
+ const size_t padding = bytesPerLine % 2;
+ const size_t len = height * ( padding + bytesPerLine );
data = (char *)malloc(len);
const char *src = bits;
char *dst = data;
}
SetHBITMAP((WXHBITMAP)hbmp);
+#endif
}
// Create from XPM data
bool wxBitmap::CreateFromXpm(const char **data)
{
+#if wxUSE_IMAGE && wxUSE_XPM
Init();
- return Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
+ wxCHECK_MSG( data != NULL, FALSE, wxT("invalid bitmap data") )
+
+ wxXPMDecoder decoder;
+ wxImage img = decoder.ReadData(data);
+ wxCHECK_MSG( img.Ok(), FALSE, wxT("invalid bitmap data") )
+
+ *this = wxBitmap(img);
+ return TRUE;
+#else
+ return FALSE;
+#endif
}
wxBitmap::wxBitmap(int w, int h, int d)
bool wxBitmap::Create(int w, int h, int d)
{
+#ifndef __WXMICROWIN__
UnRef();
m_refData = new wxBitmapRefData;
#if WXWIN_COMPATIBILITY_2
GetBitmapData()->m_ok = hbmp != 0;
#endif // WXWIN_COMPATIBILITY_2
-
return Ok();
+#else
+ return FALSE;
+#endif
}
// ----------------------------------------------------------------------------
bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
{
+#ifdef __WXMICROWIN__
+ // TODO
+ return FALSE;
+#else
wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") )
m_refData = new wxBitmapRefData();
if (depth == -1) depth = wxDisplayDepth();
SetDepth( depth );
+ // Copy the palette from the source image
+ SetPalette(image.GetPalette());
+
// create a DIB header
int headersize = sizeof(BITMAPINFOHEADER);
BITMAPINFO *lpDIBh = (BITMAPINFO *) malloc( headersize );
hbitmap = ::CreateCompatibleBitmap( hdc, width, bmpHeight );
::SelectObject( memdc, hbitmap);
+#if wxUSE_PALETTE
HPALETTE hOldPalette = 0;
if (image.GetPalette().Ok())
{
hOldPalette = ::SelectPalette(memdc, (HPALETTE) image.GetPalette().GetHPALETTE(), FALSE);
::RealizePalette(memdc);
}
+#endif // wxUSE_PALETTE
// copy image data into DIB data and then into DDB (in a loop)
unsigned char *data = image.GetData();
}
SetHBITMAP( (WXHBITMAP) hbitmap );
+#if wxUSE_PALETTE
if (hOldPalette)
SelectPalette(memdc, hOldPalette, FALSE);
+#endif // wxUSE_PALETTE
// similarly, created an mono-bitmap for the possible mask
if( image.HasMask() )
if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
return TRUE;
+#endif
}
wxImage wxBitmap::ConvertToImage() const
{
+#ifdef __WXMICROWIN__
+ // TODO
+ return wxImage();
+#else
wxImage image;
wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
free(lpBits);
return image;
+#endif
}
#endif // wxUSE_IMAGE
return handler->Create(this, data, type, width, height, depth);
}
-bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *palette)
+bool wxBitmap::SaveFile(const wxString& filename,
+ int type,
+ const wxPalette *palette)
{
wxBitmapHandler *handler = wxDynamicCast(FindHandler(type), wxBitmapHandler);
wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const
{
+#ifndef __WXMICROWIN__
wxCHECK_MSG( Ok() &&
(rect.x >= 0) && (rect.y >= 0) &&
(rect.x+rect.width <= GetWidth()) &&
DeleteDC(dcSrc);
return ret;
+#else
+ return wxBitmap();
+#endif
}
// ----------------------------------------------------------------------------
}
#endif // WXWIN_COMPATIBILITY_2
+#if wxUSE_PALETTE
+
void wxBitmap::SetPalette(const wxPalette& palette)
{
EnsureHasData();
GetBitmapData()->m_bitmapPalette = palette;
}
+#endif // wxUSE_PALETTE
+
void wxBitmap::SetMask(wxMask *mask)
{
EnsureHasData();
// Contributed by Frederic Villeneuve <frederic.villeneuve@natinst.com>
wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const
{
+#ifdef __WXMICROWIN__
+ return wxBitmap();
+#else
wxMemoryDC memDC;
wxBitmap tmpBitmap(GetWidth(), GetHeight(), dc.GetDepth());
HPALETTE hPal = (HPALETTE) NULL;
LPBITMAPINFO lpDib;
void *lpBits = (void*) NULL;
+#if wxUSE_PALETTE
if( GetPalette() && GetPalette()->Ok() )
{
tmpBitmap.SetPalette(*GetPalette());
memDC.SelectObject(tmpBitmap);
memDC.SetPalette( palette );
}
+#else // !wxUSE_PALETTE
+ hPal = (HPALETTE) ::GetStockObject(DEFAULT_PALETTE);
+#endif // wxUSE_PALETTE/!wxUSE_PALETTE
// set the height negative because in a DIB the order of the lines is
// reversed
wxFreeDIB(lpDib);
return tmpBitmap;
+#endif
}
// ----------------------------------------------------------------------------
// Create a mask from a mono bitmap (copies the bitmap).
bool wxMask::Create(const wxBitmap& bitmap)
{
+#ifndef __WXMICROWIN__
wxCHECK_MSG( bitmap.Ok() && bitmap.GetDepth() == 1, FALSE,
_T("can't create mask from invalid or not monochrome bitmap") );
SelectObject(destDC, 0);
DeleteDC(destDC);
return TRUE;
+#else
+ return FALSE;
+#endif
}
// Create a mask from a bitmap and a palette index indicating
::DeleteObject((HBITMAP) m_maskBitmap);
m_maskBitmap = 0;
}
+
+#if wxUSE_PALETTE
if (bitmap.Ok() && bitmap.GetPalette()->Ok())
{
unsigned char red, green, blue;
return Create(bitmap, transparentColour);
}
}
+#endif // wxUSE_PALETTE
+
return FALSE;
}
// the transparent area
bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
{
+#ifndef __WXMICROWIN__
wxCHECK_MSG( bitmap.Ok(), FALSE, _T("invalid bitmap in wxMask::Create") );
if ( m_maskBitmap )
bool ok = TRUE;
+ // SelectObject() will fail
+ wxASSERT_MSG( !bitmap.GetSelectedInto(),
+ _T("bitmap can't be selected in another DC") );
+
HGDIOBJ hbmpSrcOld = ::SelectObject(srcDC, GetHbitmapOf(bitmap));
if ( !hbmpSrcOld )
{
::DeleteDC(destDC);
return ok;
+#else
+ return FALSE;
+#endif
}
// ----------------------------------------------------------------------------
// DIB functions
// ----------------------------------------------------------------------------
+#ifndef __WXMICROWIN__
bool wxCreateDIB(long xSize, long ySize, long bitsPerPixel,
HPALETTE hPal, LPBITMAPINFO* lpDIBHeader)
{
{
free(lpDIBHeader);
}
+#endif
// ----------------------------------------------------------------------------
// other helper functions
extern HBITMAP wxInvertMask(HBITMAP hbmpMask, int w, int h)
{
+#ifndef __WXMICROWIN__
wxCHECK_MSG( hbmpMask, 0, _T("invalid bitmap in wxInvertMask") );
// get width/height from the bitmap if not given
::DeleteDC(hdcDst);
return hbmpInvMask;
+#else
+ return 0;
+#endif
}