MIME support
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2088 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -46,10 +46,14 @@ Creates an image with the given width and height.
|
||||
|
||||
\func{}{wxImage}{\param{const wxString\& }{name}, \param{long}{ type = wxBITMAP\_TYPE\_PNG}}
|
||||
|
||||
\func{}{wxImage}{\param{const wxString\& }{name}, \param{const wxString\&}{ mimetype}}
|
||||
|
||||
Loads an image from a file.
|
||||
|
||||
\func{}{wxImage}{\param{wxInputStream\& }{stream}, \param{long}{ type = wxBITMAP\_TYPE\_PNG}}
|
||||
|
||||
\func{}{wxImage}{\param{wxInputStream\& }{stream}, \param{const wxString\&}{ mimetype}}
|
||||
|
||||
Loads an image from an input stream.
|
||||
|
||||
\wxheading{Parameters}
|
||||
@@ -76,6 +80,8 @@ If all possible wxWindows settings are used, the loading a BMP (Windows bitmap)
|
||||
a PNG (portable network graphics) file and a JPEG file is supported on all platforms that
|
||||
implement wxImage.}
|
||||
|
||||
\docparam{mimetype}{MIME type string (for example 'image/jpeg')}
|
||||
|
||||
Note : you must call wxImage::AddHandler(new wxJPEGHandler) during application
|
||||
initialization in order to work with JPEGs.
|
||||
|
||||
@@ -157,12 +163,18 @@ Finds the handler associated with the given extension and type.
|
||||
|
||||
Finds the handler associated with the given image type.
|
||||
|
||||
\func{static wxImageHandler*}{FindHandlerMime}{\param{const wxString\& }{mimetype}}
|
||||
|
||||
Finds the handler associated with the given MIME type.
|
||||
|
||||
\docparam{name}{The handler name.}
|
||||
|
||||
\docparam{extension}{The file extension, such as ``bmp".}
|
||||
|
||||
\docparam{imageType}{The image type, such as wxBITMAP\_TYPE\_BMP.}
|
||||
|
||||
\docparam{mimetype}{MIME type.}
|
||||
|
||||
\wxheading{Return value}
|
||||
|
||||
A pointer to the handler if found, NULL otherwise.
|
||||
@@ -278,10 +290,14 @@ of a given handler class in an application session.}
|
||||
|
||||
\func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{long}{ type}}
|
||||
|
||||
\func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{const wxString\&}{ mimetype}}
|
||||
|
||||
Loads an image from a file.
|
||||
|
||||
\func{bool}{LoadFile}{\param{wxInputStream\&}{ stream}, \param{long}{ type}}
|
||||
|
||||
\func{bool}{LoadFile}{\param{wxInputStream\&}{ stream}, \param{const wxString\&}{ mimetype}}
|
||||
|
||||
Loads an image from an input stream.
|
||||
|
||||
\wxheading{Parameters}
|
||||
@@ -303,6 +319,8 @@ The meaning of {\it stream} data is determined by the {\it type} parameter.}
|
||||
|
||||
The validity of these flags depends on the platform and wxWindows configuration.}
|
||||
|
||||
\docparam{mimetype}{MIME type string (for example 'image/jpeg')}
|
||||
|
||||
\wxheading{Return value}
|
||||
|
||||
TRUE if the operation succeeded, FALSE otherwise.
|
||||
@@ -338,10 +356,14 @@ TRUE if the handler was found and removed, FALSE otherwise.
|
||||
|
||||
\func{bool}{SaveFile}{\param{const wxString\& }{name}, \param{int}{ type}}
|
||||
|
||||
\func{bool}{SaveFile}{\param{const wxString\& }{name}, \param{const wxString\&}{ mimetype}}
|
||||
|
||||
Saves a image in the named file.
|
||||
|
||||
\func{bool}{SaveFile}{\param{wxOutputStream\& }{stream}, \param{int}{ type}}
|
||||
|
||||
\func{bool}{SaveFile}{\param{wxOutputStream\& }{stream}, \param{const wxString\&}{ mimetype}}
|
||||
|
||||
Saves a image in the given stream.
|
||||
|
||||
\wxheading{Parameters}
|
||||
@@ -361,6 +383,8 @@ Saves a image in the given stream.
|
||||
The validity of these flags depends on the platform and wxWindows configuration
|
||||
as well as user-added handlers.}
|
||||
|
||||
\docparam{mimetype}{MIME type.}
|
||||
|
||||
\wxheading{Return value}
|
||||
|
||||
TRUE if the operation succeeded, FALSE otherwise.
|
||||
@@ -519,6 +543,12 @@ Gets the file extension associated with this handler.
|
||||
|
||||
Gets the image type associated with this handler.
|
||||
|
||||
\membersection{wxImageHandler::GetMimeType}
|
||||
|
||||
\constfunc{wxString}{GetMimeType}{\void}
|
||||
|
||||
Gets the MIME type associated with this handler.
|
||||
|
||||
\membersection{wxImageHandler::LoadFile}\label{wximagehandlerloadfile}
|
||||
|
||||
\func{bool}{LoadFile}{\param{wxImage* }{image}, \param{wxInputStream\&}{ stream}}
|
||||
@@ -594,3 +624,14 @@ Sets the handler type.
|
||||
|
||||
\docparam{name}{Handler type.}
|
||||
|
||||
|
||||
\membersection{wxImageHandler::SetMimeType}
|
||||
|
||||
\func{void}{SetMimeType}{\param{const wxString\& }{mimetype}}
|
||||
|
||||
Sets the handler MIME type.
|
||||
|
||||
\wxheading{Parameters}
|
||||
|
||||
\docparam{mimename}{Handler MIME type.}
|
||||
|
||||
|
@@ -58,13 +58,16 @@ public:
|
||||
inline void SetName(const wxString& name) { m_name = name; }
|
||||
inline void SetExtension(const wxString& ext) { m_extension = ext; }
|
||||
inline void SetType(long type) { m_type = type; }
|
||||
inline void SetMimeType(const wxString& type) { m_mime = type; }
|
||||
inline wxString GetName() const { return m_name; }
|
||||
inline wxString GetExtension() const { return m_extension; }
|
||||
inline long GetType() const { return m_type; }
|
||||
inline wxString GetMimeType() const { return m_mime; }
|
||||
|
||||
protected:
|
||||
wxString m_name;
|
||||
wxString m_extension;
|
||||
wxString m_mime;
|
||||
long m_type;
|
||||
|
||||
};
|
||||
@@ -85,6 +88,7 @@ public:
|
||||
m_name = "PNG file";
|
||||
m_extension = "png";
|
||||
m_type = wxBITMAP_TYPE_PNG;
|
||||
m_mime = "image/png";
|
||||
};
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
@@ -111,6 +115,7 @@ public:
|
||||
m_name = "JPEG file";
|
||||
m_extension = "jpg";
|
||||
m_type = wxBITMAP_TYPE_JPEG;
|
||||
m_mime = "image/jpeg";
|
||||
};
|
||||
|
||||
virtual bool LoadFile( wxImage *image, wxInputStream& stream );
|
||||
@@ -133,6 +138,7 @@ public:
|
||||
m_name = "BMP file";
|
||||
m_extension = "bmp";
|
||||
m_type = wxBITMAP_TYPE_BMP;
|
||||
m_mime = "image/bmp";
|
||||
};
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
@@ -156,6 +162,8 @@ public:
|
||||
wxImage( int width, int height );
|
||||
wxImage( const wxString& name, long type = wxBITMAP_TYPE_PNG );
|
||||
wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
|
||||
wxImage( const wxString& name, const wxString& mimetype );
|
||||
wxImage( wxInputStream& stream, const wxString& mimetype );
|
||||
|
||||
wxImage( const wxImage& image );
|
||||
wxImage( const wxImage* image );
|
||||
@@ -176,15 +184,19 @@ public:
|
||||
unsigned char GetBlue( int x, int y );
|
||||
|
||||
virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_PNG );
|
||||
virtual bool LoadFile( const wxString& name, const wxString& mimetype );
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
|
||||
virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype );
|
||||
#endif
|
||||
|
||||
virtual bool SaveFile( const wxString& name, int type );
|
||||
virtual bool SaveFile( const wxString& name, const wxString& mimetype );
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
virtual bool SaveFile( wxOutputStream& stream, int type );
|
||||
virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype );
|
||||
#endif
|
||||
|
||||
bool Ok() const;
|
||||
@@ -219,6 +231,7 @@ public:
|
||||
static wxImageHandler *FindHandler( const wxString& name );
|
||||
static wxImageHandler *FindHandler( const wxString& extension, long imageType );
|
||||
static wxImageHandler *FindHandler( long imageType );
|
||||
static wxImageHandler *FindHandlerMime( const wxString& mimetype );
|
||||
|
||||
static void CleanUpHandlers();
|
||||
static void InitStandardHandlers();
|
||||
@@ -231,3 +244,4 @@ protected:
|
||||
|
||||
#endif
|
||||
// _WX_IMAGE_H_
|
||||
|
||||
|
@@ -101,11 +101,21 @@ wxImage::wxImage( const wxString& name, long type )
|
||||
LoadFile( name, type );
|
||||
}
|
||||
|
||||
wxImage::wxImage( const wxString& name, const wxString& mimetype )
|
||||
{
|
||||
LoadFile( name, mimetype );
|
||||
}
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
wxImage::wxImage( wxInputStream& stream, long type )
|
||||
{
|
||||
LoadFile( stream, type );
|
||||
}
|
||||
|
||||
wxImage::wxImage( wxInputStream& stream, const wxString& mimetype )
|
||||
{
|
||||
LoadFile( stream, mimetype );
|
||||
}
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
wxImage::wxImage( const wxImage& image )
|
||||
@@ -336,6 +346,25 @@ bool wxImage::LoadFile( const wxString& filename, long type )
|
||||
#endif // wxUSE_STREAMS
|
||||
}
|
||||
|
||||
bool wxImage::LoadFile( const wxString& filename, const wxString& mimetype )
|
||||
{
|
||||
#if wxUSE_STREAMS
|
||||
if (wxFileExists(filename))
|
||||
{
|
||||
wxFileInputStream stream(filename);
|
||||
return LoadFile(stream, mimetype);
|
||||
}
|
||||
|
||||
else {
|
||||
wxLogError( "Can't load image from file '%s': file does not exist.", filename.c_str() );
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
#else // !wxUSE_STREAMS
|
||||
return FALSE;
|
||||
#endif // wxUSE_STREAMS
|
||||
}
|
||||
|
||||
bool wxImage::SaveFile( const wxString& filename, int type )
|
||||
{
|
||||
#if wxUSE_STREAMS
|
||||
@@ -348,6 +377,18 @@ bool wxImage::SaveFile( const wxString& filename, int type )
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype )
|
||||
{
|
||||
#if wxUSE_STREAMS
|
||||
wxFileOutputStream stream(filename);
|
||||
|
||||
if ( stream.LastError() == wxStream_NOERROR )
|
||||
return SaveFile(stream, mimetype);
|
||||
else
|
||||
#endif // wxUSE_STREAMS
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
bool wxImage::LoadFile( wxInputStream& stream, long type )
|
||||
{
|
||||
@@ -367,6 +408,24 @@ bool wxImage::LoadFile( wxInputStream& stream, long type )
|
||||
return handler->LoadFile( this, stream );
|
||||
}
|
||||
|
||||
bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype )
|
||||
{
|
||||
UnRef();
|
||||
|
||||
m_refData = new wxImageRefData;
|
||||
|
||||
wxImageHandler *handler = FindHandlerMime(mimetype);
|
||||
|
||||
if (handler == NULL)
|
||||
{
|
||||
wxLogWarning( "No image handler for type %s defined.", mimetype.GetData() );
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return handler->LoadFile( this, stream );
|
||||
}
|
||||
|
||||
bool wxImage::SaveFile( wxOutputStream& stream, int type )
|
||||
{
|
||||
wxCHECK_MSG( Ok(), FALSE, "invalid image" );
|
||||
@@ -382,6 +441,22 @@ bool wxImage::SaveFile( wxOutputStream& stream, int type )
|
||||
|
||||
return handler->SaveFile( this, stream );
|
||||
}
|
||||
|
||||
bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype )
|
||||
{
|
||||
wxCHECK_MSG( Ok(), FALSE, "invalid image" );
|
||||
|
||||
wxImageHandler *handler = FindHandlerMime(mimetype);
|
||||
|
||||
if (handler == NULL)
|
||||
{
|
||||
wxLogWarning( "No image handler for type %s defined.", mimetype.GetData() );
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return handler->SaveFile( this, stream );
|
||||
}
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
void wxImage::AddHandler( wxImageHandler *handler )
|
||||
@@ -451,6 +526,18 @@ wxImageHandler *wxImage::FindHandler( long bitmapType )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxImageHandler *wxImage::FindHandlerMime( const wxString& mimetype )
|
||||
{
|
||||
wxNode *node = sm_handlers.First();
|
||||
while (node)
|
||||
{
|
||||
wxImageHandler *handler = (wxImageHandler *)node->Data();
|
||||
if (handler->GetMimeType().IsSameAs(mimetype, FALSE)) return handler;
|
||||
node = node->Next();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void wxImage::InitStandardHandlers()
|
||||
{
|
||||
AddHandler( new wxBMPHandler );
|
||||
|
Reference in New Issue
Block a user