4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
8 * \author Lars Gullik Bjønnes
10 * Full author contact details are available in file CREDITS.
13 #ifndef INSET_LATEXCOMMAND_H
14 #define INSET_LATEXCOMMAND_H
17 #include "insetcommandparams.h"
18 #include "render_button.h"
19 #include "mailinset.h"
26 // Created by Alejandro 970222
27 /** Used to insert a LaTeX command automatically
29 * Similar to InsetLaTeX but having control of the basic structure of a
30 * LaTeX command: \name[options]{contents}.
34 class InsetCommand : public InsetOld {
37 InsetCommand(InsetCommandParams const &, std::string const & mailer_name);
41 void metrics(MetricsInfo &, Dimension &) const;
43 void draw(PainterInfo & pi, int x, int y) const;
45 void write(Buffer const &, std::ostream & os) const
48 virtual void read(Buffer const &, LyXLex & lex)
50 /// Can remove one InsetBibKey is modified
52 void scanCommand(std::string const & c) { p_.scanCommand(c); };
54 virtual int latex(Buffer const &, odocstream &,
55 OutputParams const &) const;
57 int plaintext(Buffer const &, odocstream &,
58 OutputParams const &) const;
60 virtual int docbook(Buffer const &, odocstream &,
61 OutputParams const & runparams) const;
63 InsetBase::Code lyxCode() const { return InsetBase::NO_CODE; }
66 InsetCommandParams const & params() const { return p_; }
68 std::string const getContents() const { return p_.getContents(); }
70 void setContents(std::string const & c)
72 updateButtonLabel_ = true;
76 void setParam(std::string const & name, docstring const & value)
78 updateButtonLabel_ = true;
82 docstring const & getParam(std::string const & name) const
87 virtual void replaceContents(std::string const & from, std::string const & to);
89 std::string const getOptions() const { return p_.getOptions(); }
91 std::string const getSecOptions() const { return p_.getSecOptions(); }
93 RenderButton & button() const { return button_; }
97 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
99 bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
101 docstring const getCommand() const { return p_.getCommand(); }
103 std::string const & getCmdName() const { return p_.getCmdName(); }
105 void setCmdName(std::string const & n)
107 updateButtonLabel_ = true;
111 void setOptions(std::string const & o)
113 updateButtonLabel_ = true;
117 void setSecOptions(std::string const & s)
119 updateButtonLabel_ = true;
123 void setParams(InsetCommandParams const &);
124 /// This should provide the text for the button
125 virtual docstring const getScreenLabel(Buffer const &) const = 0;
129 InsetCommandParams p_;
130 std::string mailer_name_;
131 mutable bool updateButtonLabel_;
132 mutable RenderButton button_;
136 class InsetCommandMailer : public MailInset {
139 InsetCommandMailer(std::string const & name, InsetCommand & inset);
141 virtual InsetBase & inset() const { return inset_; }
143 virtual std::string const & name() const { return name_; }
145 virtual std::string const inset2string(Buffer const &) const;
147 static void string2params(std::string const &, std::string const & name,
148 InsetCommandParams &);
150 static std::string const params2string(std::string const & name,
151 InsetCommandParams const &);
154 std::string const name_;
156 InsetCommand & inset_;