#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)
(void)Create(data, type, width, height, depth);
}
-wxBitmap::wxBitmap(const wxString& filename, long type)
+wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type)
{
Init();
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
}
+// ----------------------------------------------------------------------------
+// wxImage to/from conversions
+// ----------------------------------------------------------------------------
+
+#if wxUSE_IMAGE
+
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();
}
// set bitmap parameters
- wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") );
+ wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") );
SetWidth( width );
SetHeight( bmpHeight );
if (depth == -1) depth = wxDisplayDepth();
// check the wxBitmap object
GetBitmapData()->SetOk();
#endif // WXWIN_COMPATIBILITY_2
-
+
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") );
// create an wxImage object
free(lpBits);
return image;
+#endif
}
+#endif // wxUSE_IMAGE
+
bool wxBitmap::LoadFile(const wxString& filename, long type)
{
UnRef();
return handler->LoadFile(this, filename, type, -1, -1);
}
+#if wxUSE_IMAGE
else
{
wxImage image;
- if ( !image.LoadFile( filename, type ) || !image.Ok() )
- return FALSE;
-
- *this = image.ConvertToBitmap();
+ if ( image.LoadFile( filename, type ) && image.Ok() )
+ {
+ *this = image.ConvertToBitmap();
- return TRUE;
+ return TRUE;
+ }
}
+#endif // wxUSE_IMAGE
+
+ return FALSE;
}
bool wxBitmap::Create(void *data, long type, int width, int height, int depth)
{
return handler->SaveFile(this, filename, type, palette);
}
+#if wxUSE_IMAGE
else
{
// FIXME what about palette? shouldn't we use it?
wxImage image( *this );
- if (!image.Ok())
- return FALSE;
-
- return image.SaveFile( filename, type );
+ if ( image.Ok() )
+ {
+ return image.SaveFile(filename, type);
+ }
}
+#endif // wxUSE_IMAGE
+
+ return FALSE;
}
// ----------------------------------------------------------------------------
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
}
// ----------------------------------------------------------------------------
// 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;
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
// 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
}