3 * \file InsetGraphics.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
10 * Full author contact details are available in file CREDITS.
13 #ifndef INSET_GRAPHICS_H
14 #define INSET_GRAPHICS_H
17 #include "InsetGraphicsParams.h"
26 /////////////////////////////////////////////////////////////////////////
30 /////////////////////////////////////////////////////////////////////////
32 /// Used for images etc.
33 class InsetGraphics : public Inset
37 InsetGraphics(Buffer * buf);
42 static void string2params(std::string const & data,
43 Buffer const & buffer,
44 InsetGraphicsParams &);
46 static std::string params2string(InsetGraphicsParams const &,
49 /** Set the inset parameters, used by the GUIndependent dialog.
50 Return true of new params are different from what was so far.
52 bool setParams(InsetGraphicsParams const & params);
54 InsetGraphicsParams getParams() const { return params_;}
56 bool clickable(BufferView const &, int, int) const { return true; }
58 bool canPaintChange(BufferView const &) const { return true; }
60 InsetGraphics * asInsetGraphics() { return this; }
62 InsetGraphics const * asInsetGraphics() const { return this; }
66 InsetGraphics(InsetGraphics const &);
69 bool isLabeled() const { return true; }
70 void metrics(MetricsInfo &, Dimension &) const;
72 bool hasSettings() const { return true; }
74 void write(std::ostream &) const;
76 void read(Lexer & lex);
77 /** returns the number of rows (\n's) of generated tex code.
78 #fragile == true# means, that the inset should take care about
79 fragile commands by adding a #\protect# before.
81 void latex(otexstream &, OutputParams const &) const;
83 int plaintext(odocstringstream & ods, OutputParams const & op,
84 size_t max_length = INT_MAX) const;
86 int docbook(odocstream &, OutputParams const &) const;
88 docstring xhtml(XHTMLStream & os, OutputParams const &) const;
89 /** Tell LyX what the latex features you need i.e. what latex packages
90 you need to be included.
92 void validate(LaTeXFeatures & features) const;
93 /// returns LyX code associated with the inset. Used for TOC, ...)
94 InsetCode lyxCode() const { return GRAPHICS_CODE; }
96 docstring layoutName() const { return from_ascii("Graphics"); }
97 /// Get the inset parameters, used by the GUIndependent dialog.
98 InsetGraphicsParams const & params() const;
100 void draw(PainterInfo & pi, int x, int y) const;
102 bool showInsetDialog(BufferView * bv) const;
104 void editGraphics(InsetGraphicsParams const &) const;
106 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
108 void addToToc(DocIterator const & di, bool output_active,
109 UpdateType utype, TocBackend & backend) const;
111 std::string contextMenuName() const;
112 /// Force inset into LTR environment if surroundings are RTL
113 bool forceLTR() const { return true; }
115 void doDispatch(Cursor & cur, FuncRequest & cmd);
117 Inset * clone() const;
118 /// Get the status message, depends on the image loading status.
119 std::string statusMessage() const;
120 /// Create the options for the latex command.
121 std::string createLatexOptions(bool const ps) const;
122 /// Create length values for docbook export.
123 docstring toDocbookLength(Length const & len) const;
124 /// Create the atributes for docbook export.
125 docstring createDocBookAttributes() const;
126 /// Convert the file if needed, and return the location of the file.
127 /// This version is for use with LaTeX-style output.
128 std::string prepareFile(OutputParams const &) const;
129 /// Convert the file if needed, and return the location of the file.
130 /// This version is for use with HTML-style output.
131 /// \return the new filename, relative to the location of the HTML file,
132 /// or an empty string on error.
133 std::string prepareHTMLFile(OutputParams const & runparams) const;
136 InsetGraphicsParams params_;
137 /// holds the entity name that defines the graphics location (SGML).
138 docstring const graphic_label;
140 docstring toolTip(BufferView const & bv, int x, int y) const;
141 /// The thing that actually draws the image on LyX's screen.
142 RenderGraphic * graphic_;
147 /// Saves the list of currently used groups in the document.
148 void getGraphicsGroups(Buffer const &, std::set<std::string> &);
150 /// how many members has the current group?
151 int countGroupMembers(Buffer const &, std::string const &);
153 /// Returns parameters of a given graphics group (except filename).
154 std::string getGroupParams(Buffer const &, std::string const &);
156 /** Synchronize all Graphics insets of the group.
157 Both groupId and params are taken from argument.
159 void unifyGraphicsGroups(Buffer &, std::string const &);
160 InsetGraphics * getCurrentGraphicsInset(Cursor const &);
162 } // namespace graphics
166 #endif // INSET_GRAPHICS_H