]> git.lyx.org Git - lyx.git/blob - src/insets/InsetGraphics.h
392a7acd82971ef4826adc7ef1389548b7f63b28
[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 namespace lyx {
21
22 class RenderGraphic;
23 class LaTeXFeatures;
24
25 /////////////////////////////////////////////////////////////////////////
26 //
27 // InsetGraphics
28 //
29 /////////////////////////////////////////////////////////////////////////
30
31 /// Used for images etc.
32 class InsetGraphics : public Inset
33 {
34 public:
35         ///
36         InsetGraphics(Buffer * buf);
37         ///
38         ~InsetGraphics();
39
40         ///
41         static void string2params(std::string const & data,
42                                   Buffer const & buffer,
43                                   InsetGraphicsParams &);
44         ///
45         static std::string params2string(InsetGraphicsParams const &,
46                                           Buffer const &);
47
48         /** Set the inset parameters, used by the GUIndependent dialog.
49             Return true of new params are different from what was so far.
50         */
51         bool setParams(InsetGraphicsParams const & params);
52
53         InsetGraphicsParams getParams() const { return params_;}
54
55 private:
56         ///
57         InsetGraphics(InsetGraphics const &);
58
59         ///
60         bool isLabeled() const { return true; }
61         void metrics(MetricsInfo &, Dimension &) const;
62         ///
63         bool hasSettings() const { return true; }
64         ///
65         void write(std::ostream &) const;
66         ///
67         void read(Lexer & lex);
68         /** returns the number of rows (\n's) of generated tex code.
69          #fragile == true# means, that the inset should take care about
70          fragile commands by adding a #\protect# before.
71          */
72         int latex(odocstream &, OutputParams const &) const;
73         ///
74         int plaintext(odocstream &, OutputParams const &) const;
75         ///
76         int docbook(odocstream &, OutputParams const &) const;
77         ///
78         docstring xhtml(odocstream & os, OutputParams const &) const;
79         /** Tell LyX what the latex features you need i.e. what latex packages
80             you need to be included.
81          */
82         void validate(LaTeXFeatures & features) const;
83         /// returns LyX code associated with the inset. Used for TOC, ...)
84         InsetCode lyxCode() const { return GRAPHICS_CODE; }
85         /// Get the inset parameters, used by the GUIndependent dialog.
86         InsetGraphicsParams const & params() const;
87         ///
88         void draw(PainterInfo & pi, int x, int y) const;
89         ///
90         bool showInsetDialog(BufferView * bv) const;
91         ///
92         void editGraphics(InsetGraphicsParams const &) const;
93         ///
94         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
95         ///
96         void addToToc(DocIterator const &);
97         ///
98         docstring contextMenu(BufferView const & bv, int x, int y) const;
99         /// Force inset into LTR environment if surroundings are RTL?
100         bool forceLTR() const { return true; }
101         ///
102         void doDispatch(Cursor & cur, FuncRequest & cmd);
103         ///
104         Inset * clone() const;
105         /// Get the status message, depends on the image loading status.
106         std::string statusMessage() const;
107         /// Create the options for the latex command.
108         std::string createLatexOptions() const;
109         /// Create length values for docbook export.
110         docstring toDocbookLength(Length const & len) const;
111         /// Create the atributes for docbook export.
112         docstring createDocBookAttributes() const;
113         /// Convert the file if needed, and return the location of the file.
114         /// This version is for use with LaTeX-style output.
115         std::string prepareFile(OutputParams const &) const;
116         /// Convert the file if needed, and return the location of the file.
117         /// This version is for use with HTML-style output.
118         /// \return the new filename, relative to the location of the HTML file,
119         /// or an empty string on error.
120         std::string prepareHTMLFile(OutputParams const & runparams) const;
121
122         ///
123         InsetGraphicsParams params_;
124         /// holds the entity name that defines the graphics location (SGML).
125         docstring const graphic_label;
126         /// The thing that actually draws the image on LyX's screen.
127         RenderGraphic * graphic_;
128 };
129
130 namespace graphics {
131
132         /// Saves the list of currently used groups in the document.
133         void getGraphicsGroups(Buffer const &, std::set<std::string> &);
134
135         /// how many members has the current group?
136         int countGroupMembers(Buffer const &, std::string const &);
137
138         /// Returns parameters of a given graphics group (except filename).
139         std::string getGroupParams(Buffer const &, std::string const &);
140
141         /** Synchronize all Graphics insets of the group.
142             Both groupId and params are taken from argument.
143         */
144         void unifyGraphicsGroups(Buffer &, std::string const &);
145         InsetGraphics * getCurrentGraphicsInset(Cursor const &);
146
147 }
148
149 } // namespace lyx
150
151 #endif // INSET_GRAPHICS_H