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 InsetCommand * asInsetCommand() { return this; }
47 InsetCommand const * asInsetCommand() const { return this; }
50 /// returns true if params are successfully read
51 static bool string2params(std::string const &, std::string const & name,
52 InsetCommandParams &);
54 static std::string params2string(std::string const & name,
55 InsetCommandParams const &);
57 InsetCommandParams const & params() const { return p_; }
59 void setParams(InsetCommandParams const &);
61 docstring const & getParam(std::string const & name) const;
63 void setParam(std::string const & name, docstring const & value);
65 docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
67 /// \name Methods inherited from Inset class
70 void write(std::ostream & os) const { p_.write(os); }
72 void read(Lexer & lex) { p_.read(lex); }
74 void doDispatch(Cursor & cur, FuncRequest & cmd);
76 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
78 void metrics(MetricsInfo &, Dimension &) const;
80 void draw(PainterInfo & pi, int x, int y) const;
82 int latex(odocstream &, OutputParams const &) const;
84 int plaintext(odocstream &, OutputParams const &) const;
86 int docbook(odocstream &, OutputParams const & runparams) const;
88 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
90 bool clickable(int, int) const { return hasSettings(); }
92 docstring contextMenu(BufferView const & bv, int x, int y) const;
94 bool showInsetDialog(BufferView * bv) const;
96 Dimension const dimension(BufferView const &) const
97 { return button_.dimension(); }
101 /// \name Methods relaying to the InsetCommandParams
103 /// Build the complete LaTeX command
104 /// \see InsetCommandParams::getCommand
105 docstring const getCommand(OutputParams const & rp) const
106 { return p_.getCommand(rp); }
107 /// Return the command name
108 /// \see InsetCommandParams::getCmdName
109 std::string const & getCmdName() const { return p_.getCmdName(); }
110 /// Set the name to \p n. This must be a known name. All parameters
111 /// are cleared except those that exist also in the new command.
112 /// What matters here is the parameter name, not position.
113 /// \see InsetCommandParams::setCmdName
114 void setCmdName(std::string const & n) { p_.setCmdName(n); }
119 RenderButton & button() const { return button_; }
120 /// This should provide the text for the button
121 virtual docstring screenLabel() const = 0;
123 /// \name Methods obligated for InsetCommand derived classes
125 /// Return parameter information for command cmdName.
126 /// Not implemented here. Must be implemented in derived class.
127 static ParamInfo const & findInfo(std::string const & cmdName);
128 /// Return default command for this inset.
129 /// Not implemented here. Must be implemented in derived class.
130 static std::string defaultCommand();
131 /// Whether this is a command this inset can represent.
132 /// Not implemented here. Must be implemented in derived class.
133 static bool isCompatibleCommand(std::string const & cmd);
137 InsetCommandParams p_;
139 std::string mailer_name_;
140 /// changes color when mouse enters/leaves this inset
141 mutable std::map<BufferView const *, bool> mouse_hover_;
143 mutable RenderButton button_;
146 /// Decode InsetCommand considering Inset name and data.
147 bool decodeInsetParam(std::string const & name, std::string & data,
148 Buffer const & buffer);