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