added CreateFromXpm method that uses image xpm decoder
use of the old xpm library code is conditionned by OBSOLETE_XPM_DATA_HANDLER which is set be default under Classic Mac OS and not set under Mac OS X git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10054 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -21,12 +21,15 @@
|
|||||||
#include "wx/icon.h"
|
#include "wx/icon.h"
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
|
#include "wx/xpmdecod.h"
|
||||||
|
|
||||||
|
#ifndef __UNIX__
|
||||||
|
#define OBSOLETE_XPM_DATA_HANDLER
|
||||||
|
#endif
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#ifdef __UNIX__
|
#ifdef OBSOLETE_XPM_DATA_HANDLER
|
||||||
#include "xpm/xpm.h"
|
|
||||||
#else
|
|
||||||
#include "xpm.h"
|
#include "xpm.h"
|
||||||
#endif
|
#endif
|
||||||
} ;
|
} ;
|
||||||
@@ -305,7 +308,6 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits
|
|||||||
SetCPixel( x , y , &colors[0] ) ;
|
SetCPixel( x , y , &colors[0] ) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
UnlockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
|
UnlockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
|
||||||
|
|
||||||
@@ -345,14 +347,33 @@ wxBitmap::wxBitmap(const wxString& filename, long type)
|
|||||||
wxTheBitmapList->AddBitmap(this);
|
wxTheBitmapList->AddBitmap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap::wxBitmap(const char **data)
|
bool wxBitmap::CreateFromXpm(const char **bits)
|
||||||
{
|
{
|
||||||
(void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
|
wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") )
|
||||||
|
wxXPMDecoder decoder;
|
||||||
|
wxImage img = decoder.ReadData(bits);
|
||||||
|
wxCHECK_MSG( img.Ok(), FALSE, wxT("invalid bitmap data") )
|
||||||
|
*this = wxBitmap(img);
|
||||||
|
if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap::wxBitmap(char **data)
|
wxBitmap::wxBitmap(const char **bits)
|
||||||
{
|
{
|
||||||
(void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
|
#ifdef OBSOLETE_XPM_DATA_HANDLER
|
||||||
|
(void) Create((void *)bits, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
|
||||||
|
#else
|
||||||
|
(void) CreateFromXpm(bits);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
wxBitmap::wxBitmap(char **bits)
|
||||||
|
{
|
||||||
|
#ifdef OBSOLETE_XPM_DATA_HANDLER
|
||||||
|
(void) Create((void *)bits, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
|
||||||
|
#else
|
||||||
|
(void) CreateFromXpm((const char **)bits);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
|
wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
|
||||||
@@ -567,7 +588,7 @@ wxBitmap::wxBitmap(const wxImage& image, int depth)
|
|||||||
|
|
||||||
// Create mask
|
// Create mask
|
||||||
if ( image.HasMask() ) {
|
if ( image.HasMask() ) {
|
||||||
wxMask *mask = new wxMask( maskBitmap );
|
SetMask(new wxMask( maskBitmap ));
|
||||||
}
|
}
|
||||||
|
|
||||||
UnlockPixels( GetGWorldPixMap(GetHBITMAP()) );
|
UnlockPixels( GetGWorldPixMap(GetHBITMAP()) );
|
||||||
@@ -1264,7 +1285,7 @@ bool wxXPMFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef OBSOLETE_XPM_DATA_HANDLER
|
||||||
class WXDLLEXPORT wxXPMDataHandler: public wxBitmapHandler
|
class WXDLLEXPORT wxXPMDataHandler: public wxBitmapHandler
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS(wxXPMDataHandler)
|
DECLARE_DYNAMIC_CLASS(wxXPMDataHandler)
|
||||||
@@ -1322,6 +1343,7 @@ bool wxXPMDataHandler::Create(wxBitmap *bitmap, void *data, long flags, int widt
|
|||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
|
class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
|
||||||
{
|
{
|
||||||
@@ -1416,10 +1438,12 @@ void wxBitmap::CleanUpHandlers()
|
|||||||
|
|
||||||
void wxBitmap::InitStandardHandlers()
|
void wxBitmap::InitStandardHandlers()
|
||||||
{
|
{
|
||||||
AddHandler( new wxPICTResourceHandler ) ;
|
AddHandler(new wxPICTResourceHandler) ;
|
||||||
AddHandler( new wxICONResourceHandler ) ;
|
AddHandler(new wxICONResourceHandler) ;
|
||||||
AddHandler(new wxXPMFileHandler);
|
AddHandler(new wxXPMFileHandler);
|
||||||
|
#ifdef OBSOLETE_XPM_DATA_HANDLER
|
||||||
AddHandler(new wxXPMDataHandler);
|
AddHandler(new wxXPMDataHandler);
|
||||||
|
#endif
|
||||||
AddHandler(new wxBMPResourceHandler);
|
AddHandler(new wxBMPResourceHandler);
|
||||||
AddHandler(new wxBMPFileHandler);
|
AddHandler(new wxBMPFileHandler);
|
||||||
}
|
}
|
||||||
|
@@ -21,12 +21,15 @@
|
|||||||
#include "wx/icon.h"
|
#include "wx/icon.h"
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
|
#include "wx/xpmdecod.h"
|
||||||
|
|
||||||
|
#ifndef __UNIX__
|
||||||
|
#define OBSOLETE_XPM_DATA_HANDLER
|
||||||
|
#endif
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#ifdef __UNIX__
|
#ifdef OBSOLETE_XPM_DATA_HANDLER
|
||||||
#include "xpm/xpm.h"
|
|
||||||
#else
|
|
||||||
#include "xpm.h"
|
#include "xpm.h"
|
||||||
#endif
|
#endif
|
||||||
} ;
|
} ;
|
||||||
@@ -305,7 +308,6 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits
|
|||||||
SetCPixel( x , y , &colors[0] ) ;
|
SetCPixel( x , y , &colors[0] ) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
UnlockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
|
UnlockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ;
|
||||||
|
|
||||||
@@ -345,14 +347,33 @@ wxBitmap::wxBitmap(const wxString& filename, long type)
|
|||||||
wxTheBitmapList->AddBitmap(this);
|
wxTheBitmapList->AddBitmap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap::wxBitmap(const char **data)
|
bool wxBitmap::CreateFromXpm(const char **bits)
|
||||||
{
|
{
|
||||||
(void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
|
wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") )
|
||||||
|
wxXPMDecoder decoder;
|
||||||
|
wxImage img = decoder.ReadData(bits);
|
||||||
|
wxCHECK_MSG( img.Ok(), FALSE, wxT("invalid bitmap data") )
|
||||||
|
*this = wxBitmap(img);
|
||||||
|
if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap::wxBitmap(char **data)
|
wxBitmap::wxBitmap(const char **bits)
|
||||||
{
|
{
|
||||||
(void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
|
#ifdef OBSOLETE_XPM_DATA_HANDLER
|
||||||
|
(void) Create((void *)bits, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
|
||||||
|
#else
|
||||||
|
(void) CreateFromXpm(bits);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
wxBitmap::wxBitmap(char **bits)
|
||||||
|
{
|
||||||
|
#ifdef OBSOLETE_XPM_DATA_HANDLER
|
||||||
|
(void) Create((void *)bits, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
|
||||||
|
#else
|
||||||
|
(void) CreateFromXpm((const char **)bits);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
|
wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
|
||||||
@@ -567,7 +588,7 @@ wxBitmap::wxBitmap(const wxImage& image, int depth)
|
|||||||
|
|
||||||
// Create mask
|
// Create mask
|
||||||
if ( image.HasMask() ) {
|
if ( image.HasMask() ) {
|
||||||
wxMask *mask = new wxMask( maskBitmap );
|
SetMask(new wxMask( maskBitmap ));
|
||||||
}
|
}
|
||||||
|
|
||||||
UnlockPixels( GetGWorldPixMap(GetHBITMAP()) );
|
UnlockPixels( GetGWorldPixMap(GetHBITMAP()) );
|
||||||
@@ -1264,7 +1285,7 @@ bool wxXPMFileHandler::SaveFile(wxBitmap *bitmap, const wxString& name, int type
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef OBSOLETE_XPM_DATA_HANDLER
|
||||||
class WXDLLEXPORT wxXPMDataHandler: public wxBitmapHandler
|
class WXDLLEXPORT wxXPMDataHandler: public wxBitmapHandler
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS(wxXPMDataHandler)
|
DECLARE_DYNAMIC_CLASS(wxXPMDataHandler)
|
||||||
@@ -1322,6 +1343,7 @@ bool wxXPMDataHandler::Create(wxBitmap *bitmap, void *data, long flags, int widt
|
|||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
|
class WXDLLEXPORT wxBMPResourceHandler: public wxBitmapHandler
|
||||||
{
|
{
|
||||||
@@ -1416,10 +1438,12 @@ void wxBitmap::CleanUpHandlers()
|
|||||||
|
|
||||||
void wxBitmap::InitStandardHandlers()
|
void wxBitmap::InitStandardHandlers()
|
||||||
{
|
{
|
||||||
AddHandler( new wxPICTResourceHandler ) ;
|
AddHandler(new wxPICTResourceHandler) ;
|
||||||
AddHandler( new wxICONResourceHandler ) ;
|
AddHandler(new wxICONResourceHandler) ;
|
||||||
AddHandler(new wxXPMFileHandler);
|
AddHandler(new wxXPMFileHandler);
|
||||||
|
#ifdef OBSOLETE_XPM_DATA_HANDLER
|
||||||
AddHandler(new wxXPMDataHandler);
|
AddHandler(new wxXPMDataHandler);
|
||||||
|
#endif
|
||||||
AddHandler(new wxBMPResourceHandler);
|
AddHandler(new wxBMPResourceHandler);
|
||||||
AddHandler(new wxBMPFileHandler);
|
AddHandler(new wxBMPFileHandler);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user