]> git.lyx.org Git - lyx.git/blob - src/graphics/ImageLoader.C
remove more forms.h cruft
[lyx.git] / src / graphics / ImageLoader.C
1 /* This file is part of
2  * =================================================
3  * 
4  *          LyX, The Document Processor
5  *          Copyright 1995 Matthias Ettrich.
6  *          Copyright 1995-2001 The LyX Team.
7  *
8  * ================================================= */
9
10 #ifdef __GNUG__
11 #pragma implementation
12 #endif
13
14 #include <config.h>
15 #include "ImageLoader.h"
16 #include "frontends/support/LyXImage.h"
17
18 #include "support/filetools.h"
19
20 using std::endl;
21
22 ImageLoader::ImageLoader()
23                 : image_(0)
24 {
25 }
26
27 ImageLoader::~ImageLoader()
28 {
29         freeImage();
30 }
31
32 void
33 ImageLoader::freeImage()
34 {
35         delete image_;
36         image_ = 0;
37 }
38
39 bool ImageLoader::isImageFormatOK(string const & /*filename*/) const
40 {
41         return false;
42 }
43
44 void ImageLoader::setImage(LyXImage * image)
45 {
46         image_ = image;
47 }
48
49 LyXImage * ImageLoader::getImage()
50 {
51         LyXImage * tmp = image_;
52         image_ = 0;
53         return tmp;
54 }
55
56 ImageLoader::FormatList const
57 ImageLoader::loadableFormats() const
58 {
59         return FormatList();
60 }
61
62 ImageLoader::Result
63 ImageLoader::loadImage(string const & filename)
64 {
65         // Make sure file exists and is readable.
66         if (! IsFileReadable(filename)) {
67                 lyxerr << "No XPM file found." << endl;
68                 return NoFile;
69         }
70
71         // Verify that the file format is correct.
72         if (! isImageFormatOK(filename)) {
73                 lyxerr << "File format incorrect." << endl;
74                 return ImageFormatUnknown;
75         }
76
77         freeImage();
78
79         return runImageLoader(filename);
80 }
81