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 &);
40 InsetCommand(InsetCommand const & rhs);
42 virtual ~InsetCommand();
44 InsetCommand * asInsetCommand() { return this; }
46 InsetCommand const * asInsetCommand() const { return this; }
48 /// \return true if params are successfully read
49 static bool string2params(std::string const & data,
50 InsetCommandParams &);
52 static std::string params2string(InsetCommandParams const &);
54 InsetCommandParams const & params() const { return p_; }
56 void setParams(InsetCommandParams const &);
58 docstring const & getParam(std::string const & name) const;
60 void setParam(std::string const & name, docstring const & value);
62 docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
64 /// \name Public functions inherited from Inset class
67 void write(std::ostream & os) const { p_.write(os); }
69 void read(Lexer & lex) { p_.read(lex); }
71 void doDispatch(Cursor & cur, FuncRequest & cmd);
73 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
75 void metrics(MetricsInfo &, Dimension &) const;
77 void draw(PainterInfo & pi, int x, int y) const;
79 int latex(odocstream &, OutputParams const &) const;
81 int plaintext(odocstream &, OutputParams const &) const;
83 int docbook(odocstream &, OutputParams const & runparams) const;
85 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
87 bool clickable(int, int) const { return hasSettings(); }
89 docstring contextMenu(BufferView const & bv, int x, int y) const;
91 bool showInsetDialog(BufferView * bv) const;
93 Dimension const dimension(BufferView const &) const
94 { return button_.dimension(); }
98 /// \name Functions relaying to the InsetCommandParams
100 /// Build the complete LaTeX command
101 /// \see InsetCommandParams::getCommand
102 docstring const getCommand(OutputParams const & rp) const
103 { return p_.getCommand(rp); }
104 /// Return the command name
105 /// \see InsetCommandParams::getCmdName
106 std::string const & getCmdName() const { return p_.getCmdName(); }
107 /// Set the name to \p n. This must be a known name. All parameters
108 /// are cleared except those that exist also in the new command.
109 /// What matters here is the parameter name, not position.
110 /// \see InsetCommandParams::setCmdName
111 void setCmdName(std::string const & n) { p_.setCmdName(n); }
116 RenderButton & button() const { return button_; }
117 /// This should provide the text for the button
118 virtual docstring screenLabel() const = 0;
120 /// \name Static public methods obligated for InsetCommand derived classes
122 /// Return parameter information for command cmdName.
123 /// Not implemented here. Must be implemented in derived class.
124 static ParamInfo const & findInfo(std::string const & cmdName);
125 /// Return default command for this inset.
126 /// Not implemented here. Must be implemented in derived class.
127 static std::string defaultCommand();
128 /// Whether this is a command this inset can represent.
129 /// Not implemented here. Must be implemented in derived class.
130 static bool isCompatibleCommand(std::string const & cmd);
134 InsetCommandParams p_;
135 /// changes color when mouse enters/leaves this inset
136 mutable std::map<BufferView const *, bool> mouse_hover_;
138 mutable RenderButton button_;
141 /// Decode InsetCommand considering Inset name and data.
142 bool decodeInsetParam(std::string const & name, std::string & data,
143 Buffer const & buffer);