]> git.lyx.org Git - lyx.git/blob - src/insets/InsetGraphics.h
Fix bug #11180
[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         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 { return true; }
57         ///
58         bool canPaintChange(BufferView const &) const { return true; };
59
60 private:
61         ///
62         InsetGraphics(InsetGraphics const &);
63
64         ///
65         bool isLabeled() const { return true; }
66         void metrics(MetricsInfo &, Dimension &) const;
67         ///
68         bool hasSettings() const { return true; }
69         ///
70         void write(std::ostream &) const;
71         ///
72         void read(Lexer & lex);
73         /** returns the number of rows (\n's) of generated tex code.
74          #fragile == true# means, that the inset should take care about
75          fragile commands by adding a #\protect# before.
76          */
77         void latex(otexstream &, OutputParams const &) const;
78         ///
79         int plaintext(odocstringstream & ods, OutputParams const & op,
80                       size_t max_length = INT_MAX) const;
81         ///
82         int docbook(odocstream &, OutputParams const &) const;
83         ///
84         docstring xhtml(XHTMLStream & os, OutputParams const &) const;
85         /** Tell LyX what the latex features you need i.e. what latex packages
86             you need to be included.
87          */
88         void validate(LaTeXFeatures & features) const;
89         /// returns LyX code associated with the inset. Used for TOC, ...)
90         InsetCode lyxCode() const { return GRAPHICS_CODE; }
91         ///
92         docstring layoutName() const { return from_ascii("Graphics"); }
93         /// Get the inset parameters, used by the GUIndependent dialog.
94         InsetGraphicsParams const & params() const;
95         ///
96         void draw(PainterInfo & pi, int x, int y) const;
97         ///
98         bool showInsetDialog(BufferView * bv) const;
99         ///
100         void editGraphics(InsetGraphicsParams const &) const;
101         ///
102         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
103         ///
104         void addToToc(DocIterator const & di, bool output_active,
105                                   UpdateType utype, TocBackend & backend) const;
106         ///
107         std::string contextMenuName() const;
108         /// Force inset into LTR environment if surroundings are RTL
109         bool forceLTR() const { return true; }
110         ///
111         void doDispatch(Cursor & cur, FuncRequest & cmd);
112         ///
113         Inset * clone() const;
114         /// Get the status message, depends on the image loading status.
115         std::string statusMessage() const;
116         /// Get the output bounding box accounting for raster formats.
117         void outBoundingBox(graphics::BoundingBox &) const;
118         /// Create the options for the latex command.
119         std::string createLatexOptions(bool const ps) const;
120         /// Create length values for docbook export.
121         docstring toDocbookLength(Length const & len) const;
122         /// Create the atributes for docbook export.
123         docstring createDocBookAttributes() const;
124         /// Convert the file if needed, and return the location of the file.
125         /// This version is for use with LaTeX-style output.
126         std::string prepareFile(OutputParams const &) const;
127         /// Convert the file if needed, and return the location of the file.
128         /// This version is for use with HTML-style output.
129         /// \return the new filename, relative to the location of the HTML file,
130         /// or an empty string on error.
131         std::string prepareHTMLFile(OutputParams const & runparams) const;
132
133         ///
134         InsetGraphicsParams params_;
135         /// holds the entity name that defines the graphics location (SGML).
136         docstring const graphic_label;
137         ///
138         docstring toolTip(BufferView const & bv, int x, int y) const;
139         /// The thing that actually draws the image on LyX's screen.
140         RenderGraphic * graphic_;
141 };
142
143 namespace graphics {
144
145         /// Saves the list of currently used groups in the document.
146         void getGraphicsGroups(Buffer const &, std::set<std::string> &);
147
148         /// how many members has the current group?
149         int countGroupMembers(Buffer const &, std::string const &);
150
151         /// Returns parameters of a given graphics group (except filename).
152         std::string getGroupParams(Buffer const &, std::string const &);
153
154         /** Synchronize all Graphics insets of the group.
155             Both groupId and params are taken from argument.
156         */
157         void unifyGraphicsGroups(Buffer &, std::string const &);
158         InsetGraphics * getCurrentGraphicsInset(Cursor const &);
159
160 } // namespace graphics
161
162 } // namespace lyx
163
164 #endif // INSET_GRAPHICS_H