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 INSETCOMMAND_H
14 #define INSETCOMMAND_H
17 #include "InsetCommandParams.h"
18 #include "RenderButton.h"
25 /////////////////////////////////////////////////////////////////////////
29 /////////////////////////////////////////////////////////////////////////
31 // Created by Alejandro 970222
32 // Used to insert a LaTeX command automatically.
34 class InsetCommand : public Inset
38 InsetCommand(Buffer *, InsetCommandParams const &,
39 std::string const & mailer_name);
41 InsetCommand(InsetCommand const & rhs);
43 virtual ~InsetCommand();
45 /// returns true if params are successfully read
46 static bool string2params(std::string const &, std::string const & name,
47 InsetCommandParams &);
49 static std::string params2string(std::string const & name,
50 InsetCommandParams const &);
52 InsetCommandParams const & params() const { return p_; }
54 void setParams(InsetCommandParams const &);
56 void setParam(std::string const & name, docstring const & value);
58 Dimension const dimension(BufferView const &) const { return button_.dimension(); }
60 docstring const & getParam(std::string const & name) const;
62 docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
63 /// update label and references.
64 virtual void updateCommand(docstring const &, bool) {}
66 InsetCommand * asInsetCommand() { return this; }
68 InsetCommand const * asInsetCommand() const { return this; }
69 /// whether to include this inset in the strings generated for the TOC
70 virtual bool isInToc() const { return false; }
74 void write(std::ostream & os) const { p_.write(os); }
76 void read(Lexer & lex) { p_.read(lex); }
78 void doDispatch(Cursor & cur, FuncRequest & cmd);
80 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
82 docstring const getCommand(OutputParams & rp) const { return p_.getCommand(rp); }
84 std::string const & getCmdName() const { return p_.getCmdName(); }
86 void setCmdName(std::string const & n) { p_.setCmdName(n); }
90 void metrics(MetricsInfo &, Dimension &) const;
92 void draw(PainterInfo & pi, int x, int y) const;
94 int latex(odocstream &, OutputParams const &) const;
96 int plaintext(odocstream &, OutputParams const &) const;
98 int docbook(odocstream &, OutputParams const & runparams) const;
100 InsetCode lyxCode() const { return NO_CODE; }
102 RenderButton & button() const { return button_; }
104 bool setMouseHover(BufferView const * bv, bool mouse_hover);
105 /// Return parameter information for command cmdName.
106 /// Not implemented here. Must be implemented in derived class.
107 static ParamInfo const & findInfo(std::string const & cmdName);
108 /// Return default command for this inset.
109 /// Not implemented here. Must be implemented in derived class.
110 static std::string defaultCommand();
111 /// Whether this is a command this inset can represent.
112 /// Not implemented here. Must be implemented in derived class.
113 static bool isCompatibleCommand(std::string const & cmd);
115 docstring contextMenu(BufferView const & bv, int x, int y) const;
116 /// This should provide the text for the button
117 virtual docstring screenLabel() const = 0;
119 bool showInsetDialog(BufferView * bv) const;
121 InsetCommandParams p_;
123 std::string mailer_name_;
124 /// changes color when mouse enters/leaves this inset
125 mutable std::map<BufferView const *, bool> mouse_hover_;
127 mutable RenderButton button_;
130 /// Decode InsetCommand considering Inset name and data.
131 bool decodeInsetParam(std::string const & name, std::string & data,
132 Buffer const & buffer);