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 "RenderButton.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 Inset {
37 InsetCommand(InsetCommandParams const &, std::string const & mailer_name);
41 bool 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 &, Lexer & lex)
51 int latex(Buffer const &, odocstream &, OutputParams const &) const;
53 int plaintext(Buffer const &, odocstream &, OutputParams const &) const;
55 int docbook(Buffer const &, odocstream &, OutputParams const & runparams) const;
57 Inset::Code lyxCode() const { return Inset::NO_CODE; }
60 InsetCommandParams const & params() const { return p_; }
62 std::string const getContents() const { return p_.getContents(); }
65 void setContents(std::string const & c)
67 updateButtonLabel_ = true;
71 /// tell that the button label should be recomputed.
72 void refresh() { updateButtonLabel_ = true; }
74 void setParam(std::string const & name, docstring const & value)
76 updateButtonLabel_ = true;
80 docstring const & getParam(std::string const & name) const
85 void edit(Cursor & cur, bool left);
87 virtual void replaceContents(std::string const & from, std::string const & to);
89 RenderButton & button() const { return button_; }
91 bool setMouseHover(bool mouse_hover);
95 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
97 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
99 docstring const getCommand() const { return p_.getCommand(); }
101 std::string const & getCmdName() const { return p_.getCmdName(); }
103 void setCmdName(std::string const & n)
105 updateButtonLabel_ = true;
109 void setParams(InsetCommandParams const &);
110 /// This should provide the text for the button
111 virtual docstring const getScreenLabel(Buffer const &) const = 0;
115 InsetCommandParams p_;
117 std::string mailer_name_;
118 /// changes color when mouse enters/leaves this inset
121 mutable bool updateButtonLabel_;
123 mutable RenderButton button_;
127 class InsetCommandMailer : public MailInset {
130 InsetCommandMailer(std::string const & name, InsetCommand & inset);
132 virtual Inset & inset() const { return inset_; }
134 virtual std::string const & name() const { return name_; }
136 virtual std::string const inset2string(Buffer const &) const;
138 static void string2params(std::string const &, std::string const & name,
139 InsetCommandParams &);
141 static std::string const params2string(std::string const & name,
142 InsetCommandParams const &);
145 std::string const name_;
147 InsetCommand & inset_;