]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsLoader.h
add <string> and other small fixes to make
[lyx.git] / src / graphics / GraphicsLoader.h
1 // -*- C++ -*-
2 /**
3  * \file GraphicsLoader.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * The public face of the graphics cache.
12  *
13  *  * The user supplies an image file and the display parameters.
14  *  * He can change the file or the display parameters through a reset() method.
15  *  * He must start the loading process explicitly with startLoading().
16  *  * If he is connected through the connect() method, then he'll be informed
17  *    when the loading status changes.
18  *  * When (status() == Ready), he can use image() to access the loaded image
19  *    and pass it to the Painter.
20  *
21  * What could be simpler?
22  */
23
24 #ifndef GRAPHICSLOADER_H
25 #define GRAPHICSLOADER_H
26
27 #include "GraphicsTypes.h"
28
29 #include <boost/signals/signal0.hpp>
30 #include <boost/scoped_ptr.hpp>
31
32 class InsetOld;
33
34 namespace lyx {
35 namespace graphics {
36
37 class Image;
38 class Params;
39
40 class Loader {
41 public:
42         /// Must use the reset methods to make this instance usable.
43         Loader();
44         /// The image is not transformed, just displayed as-is.
45         Loader(std::string const & file_with_path, DisplayType = ColorDisplay);
46         /// The image is transformed before display.
47         Loader(std::string const & file_with_path, Params const &);
48         ///
49         Loader(Loader const &);
50
51         /// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
52         ~Loader();
53
54         Loader & operator=(Loader const &);
55
56         /// The file can be changed, or the display params, or both.
57         void reset(std::string const & file_with_path,
58                    DisplayType = ColorDisplay) const;
59         ///
60         void reset(std::string const & file_with_path, Params const &) const;
61         ///
62         void reset(Params const &) const;
63
64         /// Returns the absolute path of the loaded (loading?) file.
65         std::string const & filename() const;
66         ///
67         bool empty() const { return filename().empty(); }
68
69         /** starting loading of the image is done by a urgency-based
70          *  decision. Here we only call LoaderQueue::touch to request it.
71          */
72         void startLoading() const;
73
74         /** Monitor any changes to the file.
75          *  There is no point monitoring the file before startLoading() is
76          *  invoked.
77          */
78         void startMonitoring() const;
79         ///
80         bool monitoring() const;
81         /** Returns the check sum of filename() so that, for example, you can
82          *  ascertain whether to output a new PostScript version of the file
83          *  for a LaTeX run.
84          */
85         unsigned long checksum() const;
86
87         /// How far have we got in loading the image?
88         ImageStatus status() const;
89
90         /** Connect and you'll be informed when the loading status of the image
91          *  changes.
92          */
93         typedef boost::signal0<void>::slot_type slot_type;
94         ///
95         boost::signals::connection connect(slot_type const &) const;
96
97         /** The loaded image with Pixmap set.
98          *  If the Pixmap is not yet set (see status() for why...), returns 0.
99          */
100         Image const * image() const;
101
102 private:
103         /// Use the Pimpl idiom to hide the internals.
104         class Impl;
105         /// The pointer never changes although *pimpl_'s contents may.
106         boost::scoped_ptr<Impl> const pimpl_;
107 };
108
109 } // namespace graphics
110 } // namespace lyx
111
112 #endif // GRAPHICSLOADER_H