]> git.lyx.org Git - lyx.git/blob - src/graphics/ImageLoader.h
small fix with footnote, use stringstream some more
[lyx.git] / src / graphics / ImageLoader.h
1 // -*- C++ -*-
2 /* This file is part of
3  * =================================================
4  * 
5  *          LyX, The Document Processor
6  *          Copyright 1995 Matthias Ettrich.
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  * ================================================= */
10
11 #ifndef IMAGELOADER_H
12 #define IMAGELOADER_H
13
14 #ifdef __GNUG__
15 #pragma interface
16 #endif
17
18 #include "LString.h"
19 #include "boost/utility.hpp"
20 #include <vector>
21
22 class LyXImage;
23
24 /** ImageLoader is a base class for all image loaders. An ImageLoader instance is
25  *  platform dependent, and knows how to load some image formats into a memory
26  *  representation (LyXImage).
27  *
28  *  It may do the image loading asynchronously.
29  *  
30  *  @Author Baruch Even, <baruch.even@writeme.com>
31  */
32 class ImageLoader : boost::noncopyable {
33 public:
34         /// Errors that can be returned from this class.
35         enum Result {
36                 OK = 0,                 
37                 ImageFormatUnknown, // This loader doesn't know how to load this file.
38                 NoFile,                         // File doesn't exists.
39                 ErrorWhileLoading  // Unknown error when loading.
40         };
41         
42         /// A list of supported formats.
43         typedef std::vector<string> FormatList;
44         
45         /// c-tor.
46         ImageLoader();
47         /// d-tor.
48         virtual ~ImageLoader();
49
50         /// Start loading the image file.
51         ImageLoader::Result loadImage(string const & filename);
52
53         /** Get the last rendered pixmap. Returns 0 if no image is ready.
54          *  
55          *  It is a one time operation, that is, after you get the image
56          *  you are completely responsible to destroy it and the ImageLoader
57          *  will not know about the image.
58          *
59          *  This way we avoid deleting the image if you still use it and the 
60          *  ImageLoader is destructed, and if you don't use it we get to 
61          *  destruct the image to avoid memory leaks.
62          */
63         LyXImage * getImage();
64
65         /// Return the list of loadable formats.
66         virtual FormatList const loadableFormats() const;
67         
68 protected:
69         /// Verify that the file is one that we can handle.
70         virtual bool isImageFormatOK(string const & filename) const = 0;
71
72         /// Do the actual image loading.
73         virtual Result runImageLoader(string const & filename) = 0;
74
75         /// Set the image that was loaded.
76         void setImage(LyXImage * image);
77         
78 private:
79         /// Free the loaded image.
80         void freeImage();
81         
82         /// The loaded image. An auto_ptr would be great here, but it's not
83         /// available everywhere (gcc 2.95.2 doesnt have it).
84         LyXImage * image_;
85 };
86
87 #endif