]> git.lyx.org Git - lyx.git/blob - src/graphics/ImageLoader.h
Implemented synchronous inline image viewing for InsetGraphics.
[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 : public 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         LyXImage * getImage() const { return image_; };
55
56         /// Return the list of loadable formats.
57         virtual FormatList const loadableFormats() const;
58         
59 protected:
60         /// Verify that the file is one that we can handle.
61         virtual bool isImageFormatOK(string const & filename) const = 0;
62
63         /// Do the actual image loading.
64         virtual Result runImageLoader(string const & filename) = 0;
65
66         /// Set the image that was loaded.
67         void setImage(LyXImage * image);
68         
69 private:
70         /// Free the loaded image.
71         void freeImage();
72         
73         /// The loaded image.
74         LyXImage * image_;
75 };
76
77 #endif