/////////////////////////////////////////////////////////////////////////////
-// Name: imaggif.h
+// Name: wx/imaggif.h
// Purpose: wxImage GIF handler
// Author: Vaclav Slavik & Guillermo Rodriguez Garcia
// RCS-ID: $Id$
}
#if wxUSE_STREAMS
- virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
- virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );
+ virtual bool LoadFile(wxImage *image, wxInputStream& stream,
+ bool verbose = true, int index = -1);
+ virtual bool SaveFile(wxImage *image, wxOutputStream& stream,
+ bool verbose=true);
+ virtual int GetImageCount(wxInputStream& stream);
protected:
- virtual bool DoCanRead( wxInputStream& stream );
-#endif
+ virtual bool DoCanRead(wxInputStream& stream);
+#endif // wxUSE_STREAMS
private:
DECLARE_DYNAMIC_CLASS(wxGIFHandler)
};
-#endif
+#endif // wxUSE_GIF
-#endif
- // _WX_IMAGGIF_H_
+#endif // _WX_IMAGGIF_H_
Currently, the stream must support seeking.
@return Number of available images. For most image handlers, this is 1
- (exceptions are TIFF and ICO formats).
+ (exceptions are TIFF and ICO formats as well as animated GIFs
+ for which this function returns the number of frames in the
+ animation).
*/
virtual int GetImageCount(wxInputStream& stream);
@li wxBITMAP_TYPE_ANY: Will try to autodetect the format.
@return Number of available images. For most image handlers, this is 1
- (exceptions are TIFF and ICO formats).
+ (exceptions are TIFF and ICO formats as well as animated GIFs
+ for which this function returns the number of frames in the
+ animation).
*/
static int GetImageCount(const wxString& filename,
wxBitmapType type = wxBITMAP_TYPE_ANY);
class MyImageFrame : public wxFrame
{
public:
+ MyImageFrame(wxFrame *parent, const wxString& desc, const wxImage& image)
+ {
+ Create(parent, desc, wxBitmap(image), image.GetImageCount(desc));
+ }
+
MyImageFrame(wxFrame *parent, const wxString& desc, const wxBitmap& bitmap)
- : wxFrame(parent, wxID_ANY,
- wxString::Format(_T("Image from %s"), desc.c_str()),
- wxDefaultPosition, wxDefaultSize,
- wxDEFAULT_FRAME_STYLE | wxFULL_REPAINT_ON_RESIZE),
- m_bitmap(bitmap)
{
+ Create(parent, desc, bitmap);
+ }
+
+ bool Create(wxFrame *parent,
+ const wxString& desc,
+ const wxBitmap& bitmap,
+ int numImages = 1)
+ {
+ if ( !wxFrame::Create(parent, wxID_ANY,
+ wxString::Format(_T("Image from %s"), desc),
+ wxDefaultPosition, wxDefaultSize,
+ wxDEFAULT_FRAME_STYLE | wxFULL_REPAINT_ON_RESIZE) )
+ return false;
+
+ m_bitmap = bitmap;
+
wxMenu *menu = new wxMenu;
menu->Append(wxID_SAVE);
menu->AppendSeparator();
mbar->Append(menu, _T("&Image"));
SetMenuBar(mbar);
- CreateStatusBar();
+ CreateStatusBar(2);
+ if ( numImages != 1 )
+ SetStatusText(wxString::Format("%d images", numImages), 1);
SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
UpdateStatusBar();
-// SetBackgroundColour(*wxWHITE);
+ Show();
+
+ return true;
}
void OnEraseBackground(wxEraseEvent& WXUNUSED(event))
wxImage image;
wxString filename = LoadUserImage(image);
if ( !filename.empty() )
- (new MyImageFrame(this, filename, wxBitmap(image)))->Show();
+ new MyImageFrame(this, filename, image);
}
void MyFrame::OnImageInfo( wxCommandEvent &WXUNUSED(event) )
}
else
{
- (new MyImageFrame(this, _T("Clipboard"), dobjBmp.GetBitmap()))->Show();
+ new MyImageFrame(this, _T("Clipboard"), dobjBmp.GetBitmap());
}
wxTheClipboard->Close();
}
const long loadTime = sw.Time();
- MyImageFrame * const
- frame = new MyImageFrame(this, filename, wxBitmap(image));
- frame->Show();
+ MyImageFrame * const frame = new MyImageFrame(this, filename, image);
wxLogStatus(frame, "Loaded \"%s\" in %ldms", filename, loadTime);
#else
wxLogError( _T("Couldn't create file selector dialog") );