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 InsetCommand & operator=(InsetCommand const & rhs);
44 virtual ~InsetCommand();
46 InsetCommand * asInsetCommand() { return this; }
48 InsetCommand const * asInsetCommand() const { return this; }
50 /// \return true if params are successfully read
51 static bool string2params(std::string const & data,
52 InsetCommandParams &);
54 static std::string params2string(InsetCommandParams const &);
56 InsetCommandParams const & params() const { return p_; }
58 void setParams(InsetCommandParams const &);
60 docstring const & getParam(std::string const & name) const;
62 void setParam(std::string const & name, docstring const & value);
64 docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
66 void setBroken(bool const b) const { broken_ = b; }
68 bool isBroken() const { return broken_; }
70 /// \name Public functions inherited from Inset class
73 void write(std::ostream & os) const { p_.write(os); }
75 void read(Lexer & lex) { p_.Read(lex, &buffer()); }
77 void doDispatch(Cursor & cur, FuncRequest & cmd);
79 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
81 void metrics(MetricsInfo &, Dimension &) const;
83 void draw(PainterInfo & pi, int x, int y) const;
85 virtual void drawBackground(PainterInfo &, int, int) const {}
87 void latex(otexstream &, OutputParams const &) const;
89 int plaintext(odocstringstream & ods, OutputParams const & op,
90 size_t max_length = INT_MAX) const;
92 int docbook(odocstream &, OutputParams const & runparams) const;
94 void validate(LaTeXFeatures & features) const;
96 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
98 bool clickable(BufferView const &, int, int) const { return hasSettings(); }
102 /// \name Methods relaying to the InsetCommandParams p_
105 std::string contextMenuName() const;
107 bool showInsetDialog(BufferView * bv) const;
111 /// \name Functions relaying to the InsetCommandParams
113 /// Build the complete LaTeX command
114 /// \see InsetCommandParams::getCommand
115 docstring const getCommand(OutputParams const & rp) const
116 { return p_.getCommand(rp); }
117 /// Return the command name
118 /// \see InsetCommandParams::getCmdName
119 std::string const & getCmdName() const { return p_.getCmdName(); }
120 /// Set the name to \p n. This must be a known name. All parameters
121 /// are cleared except those that exist also in the new command.
122 /// What matters here is the parameter name, not position.
123 /// \see InsetCommandParams::setCmdName
124 void setCmdName(std::string const & n) { p_.setCmdName(n); }
126 void changeCmdName(std::string const & new_name);
131 RenderButton & button() const { return button_; }
132 /// This should provide the text for the button
133 virtual docstring screenLabel() const = 0;
135 /// \name Static public methods obligated for InsetCommand derived classes
137 /// Return parameter information for command cmdName.
138 /// Not implemented here. Must be implemented in derived class.
139 static ParamInfo const & findInfo(std::string const & cmdName);
140 /// Return default command for this inset.
141 /// Not implemented here. Must be implemented in derived class.
142 static std::string defaultCommand();
143 /// Whether this is a command this inset can represent.
144 /// Not implemented here. Must be implemented in derived class.
145 static bool isCompatibleCommand(std::string const & cmd);
149 InsetCommandParams p_;
150 /// changes color when mouse enters/leaves this inset
151 mutable std::map<BufferView const *, bool> mouse_hover_;
153 mutable RenderButton button_;
155 mutable bool broken_;
158 /// Decode InsetCommand considering Inset name and data.
159 bool decodeInsetParam(std::string const & name, std::string & data,
160 Buffer const & buffer);