]> git.saurik.com Git - wxWidgets.git/blame - src/common/imaggif.cpp
fixing modal dialog quit after nested message box problem
[wxWidgets.git] / src / common / imaggif.cpp
CommitLineData
b59bf2db 1/////////////////////////////////////////////////////////////////////////////
8898456d 2// Name: src/common/imaggif.cpp
b59bf2db 3// Purpose: wxGIFHandler
8a68d8b6 4// Author: Vaclav Slavik & Guillermo Rodriguez Garcia
464122b6 5// RCS-ID: $Id$
e08e239b 6// Copyright: (c) 1999 Vaclav Slavik & Guillermo Rodriguez Garcia
65571936 7// Licence: wxWindows licence
b59bf2db
JS
8/////////////////////////////////////////////////////////////////////////////
9
b59bf2db 10// For compilers that support precompilation, includes "wx.h".
3096bd2f 11#include "wx/wxprec.h"
b59bf2db
JS
12
13#ifdef __BORLANDC__
8898456d 14 #pragma hdrstop
b59bf2db
JS
15#endif
16
8898456d
WS
17#if wxUSE_IMAGE && wxUSE_GIF
18
ce4169a4 19#ifndef WX_PRECOMP
8898456d
WS
20 #include "wx/intl.h"
21 #include "wx/log.h"
ce4169a4 22#endif
b59bf2db 23
8f493002 24#include "wx/imaggif.h"
464122b6 25#include "wx/gifdecod.h"
ce4169a4 26#include "wx/wfstream.h"
b59bf2db 27
ce4169a4
RR
28IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler,wxImageHandler)
29
b59bf2db
JS
30//-----------------------------------------------------------------------------
31// wxGIFHandler
32//-----------------------------------------------------------------------------
33
9ab6ee85
GRG
34#if wxUSE_STREAMS
35
b931f7ee
VS
36bool wxGIFHandler::LoadFile(wxImage *image, wxInputStream& stream,
37 bool verbose, int index)
b59bf2db 38{
464122b6 39 wxGIFDecoder *decod;
72045d57 40 wxGIFErrorCode error;
7beb59f3 41 bool ok = true;
b59bf2db 42
0141d2c9 43// image->Destroy();
72045d57
VZ
44 decod = new wxGIFDecoder();
45 error = decod->LoadGIF(stream);
8a68d8b6 46
8141573c 47 if ((error != wxGIF_OK) && (error != wxGIF_TRUNCATED))
995612e2 48 {
e08e239b
GRG
49 if (verbose)
50 {
51 switch (error)
52 {
8141573c 53 case wxGIF_INVFORMAT:
add95ac3 54 wxLogError(_("GIF: error in GIF image format."));
8141573c
GRG
55 break;
56 case wxGIF_MEMERR:
add95ac3 57 wxLogError(_("GIF: not enough memory."));
8141573c
GRG
58 break;
59 default:
add95ac3 60 wxLogError(_("GIF: unknown error!!!"));
8141573c 61 break;
e08e239b
GRG
62 }
63 }
b59bf2db 64 delete decod;
7beb59f3 65 return false;
b59bf2db 66 }
b59bf2db 67
8141573c
GRG
68 if ((error == wxGIF_TRUNCATED) && verbose)
69 {
add95ac3 70 wxLogError(_("GIF: data stream seems to be truncated."));
8141573c
GRG
71 /* go on; image data is OK */
72 }
73
b931f7ee
VS
74 if (ok)
75 {
72045d57 76 ok = decod->ConvertToImage(index != -1 ? (size_t)index : 0, image);
b931f7ee
VS
77 }
78 else
79 {
80 wxLogError(_("GIF: Invalid gif index."));
81 }
82
464122b6 83 delete decod;
0141d2c9 84
464122b6 85 return ok;
b59bf2db
JS
86}
87
74e3313b 88bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image),
deb2fec0 89 wxOutputStream& WXUNUSED(stream), bool verbose )
b59bf2db 90{
8a68d8b6 91 if (verbose)
add95ac3 92 wxLogDebug(wxT("GIF: the handler is read-only!!"));
8a68d8b6 93
7beb59f3 94 return false;
b59bf2db
JS
95}
96
995612e2 97bool wxGIFHandler::DoCanRead( wxInputStream& stream )
0828c087 98{
72045d57
VZ
99 wxGIFDecoder decod;
100 return decod.CanRead(stream);
8faef7cc 101 // it's ok to modify the stream position here
0828c087
VS
102}
103
8faef7cc 104int wxGIFHandler::DoGetImageCount( wxInputStream& stream )
85fcb94f
VZ
105{
106 wxGIFDecoder decod;
107 wxGIFErrorCode error = decod.LoadGIF(stream);
108 if ( (error != wxGIF_OK) && (error != wxGIF_TRUNCATED) )
109 return -1;
8faef7cc
FM
110
111 // NOTE: this function modifies the current stream position but it's ok
112 // (see wxImageHandler::GetImageCount)
85fcb94f
VZ
113
114 return decod.GetFrameCount();
115}
116
9ab6ee85
GRG
117#endif // wxUSE_STREAMS
118
119#endif // wxUSE_GIF