switched to new XPM code in wxMSW

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10078 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2001-05-08 22:29:49 +00:00
parent 50c679c81a
commit ea39b21033
3 changed files with 1 additions and 282 deletions

View File

@@ -1,51 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: xpmhand.h
// Purpose: XPM bitmap handler
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma interface "xpmhand.h"
#endif
#ifndef _WX_XPMHAND_H_
#define _WX_XPMHAND_H_
class WXDLLEXPORT wxXPMFileHandler: public wxBitmapHandler
{
DECLARE_DYNAMIC_CLASS(wxXPMFileHandler)
public:
inline wxXPMFileHandler(void)
{
m_name = "XPM bitmap file";
m_extension = "xpm";
m_type = wxBITMAP_TYPE_XPM;
};
virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
int desiredWidth = -1, int desiredHeight = -1);
virtual bool SaveFile(wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette = NULL);
};
class WXDLLEXPORT wxXPMDataHandler: public wxBitmapHandler
{
DECLARE_DYNAMIC_CLASS(wxXPMDataHandler)
public:
inline wxXPMDataHandler(void)
{
m_name = "XPM bitmap data";
m_extension = "xpm";
m_type = wxBITMAP_TYPE_XPM_DATA;
};
virtual bool Create(wxBitmap *bitmap, void *data, long flags, int width, int height, int depth = 1);
};
#endif
// _WX_XPMHAND_H_

View File

@@ -159,7 +159,7 @@ INC=$(EXTRAINC) -I$(WXINC) -I$(WXDIR)/contrib/include -I$(WXDIR)/src/png -I$(WXD
!if "$(WXUSINGDLL)" == "1" || "$(wxUSE_GUI)" == "0"
LIBS = $(EXTRALIBS) $(WXLIB) $(WINLIBS)
!else
LIBS = $(EXTRALIBS) $(WXLIB) $(WINLIBS) $(WXDIR)\lib\png$(LIBEXT).lib $(WXDIR)\lib\zlib$(LIBEXT).lib $(WXDIR)\lib\jpeg$(LIBEXT).lib $(WXDIR)\lib\tiff$(LIBEXT).lib $(WXDIR)\lib\xpm$(LIBEXT).lib
LIBS = $(EXTRALIBS) $(WXLIB) $(WINLIBS) $(WXDIR)\lib\png$(LIBEXT).lib $(WXDIR)\lib\zlib$(LIBEXT).lib $(WXDIR)\lib\jpeg$(LIBEXT).lib $(WXDIR)\lib\tiff$(LIBEXT).lib
!endif
MAKEPRECOMP=/YcWX/WXPREC.H

View File

@@ -1,230 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: xpmhand.cpp
// Purpose: wxBitmap: XPM handler and constructors
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "xpmhand.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/list.h"
#include "wx/utils.h"
#include "wx/app.h"
#include "wx/palette.h"
#include "wx/dcmemory.h"
#include "wx/bitmap.h"
#include "wx/icon.h"
#endif
#include "wx/msw/private.h"
#include "wx/log.h"
#if wxUSE_XPM_IN_MSW
#define FOR_MSW 1
// allow the user to use the system-wide xpm.h by defining
// wxUSE_XPM_H_IN_PATH (and always use xpm.h in path if __WX_SETUP_H__ is
// defined which means that we use configure as it always add -I../xpm to
// the include path if needed)
#if !defined(__WX_SETUP_H__) && !defined(wxUSE_XPM_H_IN_PATH)
#include "../xpm/xpm.h"
#else
#include <xpm.h>
#endif
#endif
#include "wx/xpmhand.h"
#include "wx/msw/dib.h"
#if wxUSE_XPM_IN_MSW
static void XpmToBitmap(wxBitmap *bitmap,
const XImage *ximage,
const XImage *xmask,
const XpmAttributes& xpmAttr)
{
wxBitmapRefData *refData = bitmap->GetBitmapData();
refData->m_hBitmap = (WXHBITMAP)ximage->bitmap;
// first set the bitmap width, height, depth...
BITMAP bm;
if ( !::GetObject(GetHbitmapOf(*bitmap), sizeof(bm), (LPSTR) & bm) )
{
wxLogLastError(wxT("GetObject(bitmap)"));
}
refData->m_width = bm.bmWidth;
refData->m_height = bm.bmHeight;
refData->m_depth = bm.bmPlanes * bm.bmBitsPixel;
refData->m_numColors = xpmAttr.npixels;
// GRG Jan/2000, mask support
if (xmask)
{
wxMask *mask = new wxMask();
mask->SetMaskBitmap((WXHBITMAP) wxInvertMask(xmask->bitmap,
bm.bmWidth, bm.bmHeight));
bitmap->SetMask(mask);
}
}
#endif // wxUSE_XPM_IN_MSW
IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler, wxBitmapHandler)
bool wxXPMFileHandler::LoadFile(wxBitmap *bitmap,
const wxString& name,
long WXUNUSED(flags),
int WXUNUSED(desiredWidth),
int WXUNUSED(desiredHeight))
{
#if wxUSE_XPM_IN_MSW
XImage *ximage = NULL;
XImage *xmask = NULL;
XpmAttributes xpmAttr;
HDC dc;
dc = CreateCompatibleDC(NULL);
if (dc)
{
xpmAttr.valuemask = XpmReturnPixels | XpmColorTable;
int errorStatus = XpmReadFileToImage(&dc,
wxMBSTRINGCAST name.fn_str(),
&ximage,
&xmask,
&xpmAttr);
DeleteDC(dc);
if (errorStatus == XpmSuccess)
{
XpmToBitmap(bitmap, ximage, xmask, xpmAttr);
XpmFree(xpmAttr.pixels);
XpmFreeAttributes(&xpmAttr);
XImageFree(ximage);
if (xmask)
XDestroyImage(xmask);
}
#if WXWIN_COMPATIBILITY_2
bitmap->SetOk(errorStatus == XpmSuccess);
#endif // WXWIN_COMPATIBILITY_2
return bitmap->Ok();
}
#endif // wxUSE_XPM_IN_MSW
return FALSE;
}
bool wxXPMFileHandler::SaveFile(wxBitmap *bitmap,
const wxString& name,
int WXUNUSED(type),
const wxPalette *WXUNUSED(palette))
{
#if wxUSE_XPM_IN_MSW
XImage ximage;
XImage xmask;
bool hasmask = FALSE;
HDC dc = CreateCompatibleDC(NULL);
if (dc)
{
/* fill the XImage struct 'by hand' */
wxBitmapRefData *refData = bitmap->GetBitmapData();
ximage.width = refData->m_width;
ximage.height = refData->m_height;
ximage.depth = refData->m_depth;
ximage.bitmap = (HBITMAP)refData->m_hBitmap;
// GRG Jan/2000, mask support
hasmask = (refData->m_bitmapMask != NULL);
if (hasmask)
{
/* Strangely enough, the MSW version of xpmlib is not
* coherent with itself regarding masks; we have to invert
* the mask we get when loading, but we still must pass it
* 'as is' when saving...
*/
xmask.bitmap = (HBITMAP) refData->m_bitmapMask->GetMaskBitmap();
xmask.width = refData->m_width;
xmask.height = refData->m_height;
xmask.depth = 1;
}
int errorStatus = XpmWriteFileFromImage(
&dc,
wxMBSTRINGCAST name.fn_str(),
&ximage,
(hasmask? &xmask : (XImage *)NULL),
(XpmAttributes *) NULL);
DeleteDC(dc);
return (errorStatus == XpmSuccess);
}
#endif // !wxUSE_XPM_IN_MSW
return FALSE;
}
IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler, wxBitmapHandler)
bool wxXPMDataHandler::Create(wxBitmap *bitmap,
void *data,
long WXUNUSED(flags),
int WXUNUSED(width),
int WXUNUSED(height),
int WXUNUSED(depth))
{
#if wxUSE_XPM_IN_MSW
XImage *ximage = NULL;
XImage *xmask = NULL;
XpmAttributes xpmAttr;
HDC dc = CreateCompatibleDC(NULL); /* memory DC */
if (dc)
{
xpmAttr.valuemask = XpmReturnInfos | XpmColorTable;
int errorStatus = XpmCreateImageFromData(&dc, (char **)data,
&ximage,
&xmask,
&xpmAttr);
DeleteDC(dc);
if ( errorStatus == XpmSuccess )
{
XpmToBitmap(bitmap, ximage, xmask, xpmAttr);
XpmFree(xpmAttr.pixels);
XpmFreeAttributes(&xpmAttr);
XImageFree(ximage); // releases the malloc, but does not destroy bitmap
if (xmask)
XDestroyImage(xmask);
}
#if WXWIN_COMPATIBILITY_2
bitmap->SetOk(errorStatus == XpmSuccess);
#endif // WXWIN_COMPATIBILITY_2
return bitmap->Ok();
}
#endif // wxUSE_XPM_IN_MSW
return FALSE;
}