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.
31 class InsetCommand : public Inset {
34 InsetCommand(InsetCommandParams const &, std::string const & mailer_name);
38 void metrics(MetricsInfo &, Dimension &) const;
40 Dimension const dimension(BufferView const &) const { return button_.dimension(); }
42 void draw(PainterInfo & pi, int x, int y) const;
44 void write(std::ostream & os) const { p_.write(os); }
46 void read(Lexer & lex) { p_.read(lex); }
48 int latex(odocstream &, OutputParams const &) const;
50 int plaintext(odocstream &, OutputParams const &) const;
52 int docbook(odocstream &, OutputParams const & runparams) const;
54 InsetCode lyxCode() const { return NO_CODE; }
56 InsetCommandParams const & params() const { return p_; }
58 docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
59 /// Whether the button label should be recomputed.
60 void refresh() { updateButtonLabel_ = true; }
62 void setParam(std::string const & name, docstring const & value)
64 updateButtonLabel_ = true;
68 docstring const & getParam(std::string const & name) const
73 void edit(Cursor & cur, bool front,
74 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
76 RenderButton & button() const { return button_; }
78 bool setMouseHover(bool mouse_hover);
79 /// Return parameter information for command cmdName.
80 /// Not implemented here. Must be implemented in derived class.
81 static ParamInfo const & findInfo(std::string const & cmdName);
82 /// Return default command for this inset.
83 /// Not implemented here. Must be implemented in derived class.
84 static std::string defaultCommand();
85 /// Whether this is a command this inset can represent.
86 /// Not implemented here. Must be implemented in derived class.
87 static bool isCompatibleCommand(std::string const & cmd);
91 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
93 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
95 docstring const getCommand() const { return p_.getCommand(); }
97 std::string const & getCmdName() const { return p_.getCmdName(); }
99 void setCmdName(std::string const & n)
101 updateButtonLabel_ = true;
105 void setParams(InsetCommandParams const &);
106 /// This should provide the text for the button
107 virtual docstring screenLabel() const = 0;
111 InsetCommandParams p_;
113 std::string mailer_name_;
114 /// changes color when mouse enters/leaves this inset
117 mutable bool updateButtonLabel_;
119 mutable RenderButton button_;
123 class InsetCommandMailer : public MailInset {
126 InsetCommandMailer(std::string const & name, InsetCommand & inset);
128 virtual Inset & inset() const { return inset_; }
130 virtual std::string const & name() const { return name_; }
132 virtual std::string const inset2string(Buffer const &) const;
133 /// returns true if params are successfully read
134 static bool string2params(std::string const &, std::string const & name,
135 InsetCommandParams &);
137 static std::string const params2string(std::string const & name,
138 InsetCommandParams const &);
141 std::string const name_;
143 InsetCommand & inset_;