]> git.lyx.org Git - lyx.git/blob - src/insets/InsetGraphics.h
bfb4784aed5325a282bbffe1702f82a55a38e5c8
[lyx.git] / src / insets / InsetGraphics.h
1 // -*- C++ -*-
2 /**
3  * \file InsetGraphics.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Baruch Even
8  * \author Herbert Voß
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef INSET_GRAPHICS_H
14 #define INSET_GRAPHICS_H
15
16 #include <set>
17 #include "Inset.h"
18 #include "InsetGraphicsParams.h"
19
20 #include <boost/scoped_ptr.hpp>
21 #include <boost/signals/trackable.hpp>
22
23
24 namespace lyx {
25
26 class RenderGraphic;
27 class LaTeXFeatures;
28
29 /////////////////////////////////////////////////////////////////////////
30 //
31 // InsetGraphics
32 //
33 /////////////////////////////////////////////////////////////////////////
34
35 /// Used for images etc.
36 class InsetGraphics : public Inset, public boost::signals::trackable
37 {
38 public:
39         ///
40         InsetGraphics(Buffer & buf);
41         ///
42         ~InsetGraphics();
43
44         ///
45         static void string2params(std::string const & data,
46                                   Buffer const & buffer,
47                                   InsetGraphicsParams &);
48         ///
49         static std::string params2string(InsetGraphicsParams const &,
50                                           Buffer const &);
51         /// Saves the list of currently used groups in the document.
52         static void getGraphicsGroups(Buffer const &, std::set<std::string> &);
53         /// Returns parameters of a given graphics group (except filename).
54         static std::string getGroupParams(Buffer const &,
55                                                 std::string const &);
56         /** Synchronize all Graphics insets of the group.
57             Both groupId and params are taken from argument.
58         */
59         static void unifyGraphicsGroups(Buffer const &, std::string const &);
60         static InsetGraphics * getCurrentGraphicsInset(Cursor const &);
61
62         /** Set the inset parameters, used by the GUIndependent dialog.
63             Return true of new params are different from what was so far.
64         */
65         bool setParams(InsetGraphicsParams const & params);
66
67         InsetGraphicsParams getParams() const { return params_;}
68
69 private:
70         ///
71         InsetGraphics(InsetGraphics const &);
72
73         ///
74         bool isLabeled() const { return true; }
75         void metrics(MetricsInfo &, Dimension &) const;
76         ///
77         EDITABLE editable() const;
78         ///
79         void write(std::ostream &) const;
80         ///
81         void read(Lexer & lex);
82         /** returns the number of rows (\n's) of generated tex code.
83          #fragile == true# means, that the inset should take care about
84          fragile commands by adding a #\protect# before.
85          */
86         int latex(odocstream &, OutputParams const &) const;
87         ///
88         int plaintext(odocstream &, OutputParams const &) const;
89         ///
90         int docbook(odocstream &, OutputParams const &) const;
91         /** Tell LyX what the latex features you need i.e. what latex packages
92             you need to be included.
93          */
94         void validate(LaTeXFeatures & features) const;
95         /// returns LyX code associated with the inset. Used for TOC, ...)
96         InsetCode lyxCode() const { return GRAPHICS_CODE; }
97         /// Get the inset parameters, used by the GUIndependent dialog.
98         InsetGraphicsParams const & params() const;
99         ///
100         void draw(PainterInfo & pi, int x, int y) const;
101         ///
102         void edit(Cursor & cur, bool front, EntryDirection entry_from);
103         ///
104         void editGraphics(InsetGraphicsParams const &, Buffer const &) const;
105         ///
106         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
107         ///
108         void addToToc(DocIterator const &);
109         ///
110         docstring contextMenu(BufferView const & bv, int x, int y) const;
111         /// Force inset into LTR environment if surroundings are RTL?
112         bool forceLTR() const { return true; }
113         ///
114         void doDispatch(Cursor & cur, FuncRequest & cmd);
115         ///
116         Inset * clone() const;
117         /// Get the status message, depends on the image loading status.
118         std::string statusMessage() const;
119         /// Create the options for the latex command.
120         std::string createLatexOptions() const;
121         /// Create length values for docbook export.
122         docstring toDocbookLength(Length const & len) const;
123         /// Create the atributes for docbook export.
124         docstring createDocBookAttributes() const;
125         /// Convert the file if needed, and return the location of the file.
126         std::string prepareFile(OutputParams const &) const;
127
128         ///
129         InsetGraphicsParams params_;
130         /// holds the entity name that defines the graphics location (SGML).
131         docstring const graphic_label;
132         /// The thing that actually draws the image on LyX's screen.
133         boost::scoped_ptr<RenderGraphic> const graphic_;
134 };
135
136 } // namespace lyx
137
138 #endif // INSET_GRAPHICS_H