]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCommand.h
DocBook: support bookauthor in bibliographies.
[lyx.git] / src / insets / InsetCommand.h
1 // -*- C++ -*-
2 /**
3  * \file InsetCommand.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  * \author Lars Gullik Bjønnes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef INSETCOMMAND_H
14 #define INSETCOMMAND_H
15
16 #include "Inset.h"
17 #include "InsetCommandParams.h"
18 #include "RenderButton.h"
19
20
21 namespace lyx {
22
23 class Cursor;
24
25 /////////////////////////////////////////////////////////////////////////
26 //
27 // InsetCommand
28 //
29 /////////////////////////////////////////////////////////////////////////
30
31 // Created by Alejandro 970222
32 // Used to insert a LaTeX command automatically.
33
34 class InsetCommand : public Inset
35 {
36 public:
37         ///
38         InsetCommand(Buffer *, InsetCommandParams const &);
39         ///
40         InsetCommand(InsetCommand const & rhs);
41         ///
42         InsetCommand & operator=(InsetCommand const & rhs);
43         ///
44         virtual ~InsetCommand();
45         ///
46         InsetCommand * asInsetCommand() override { return this; }
47         ///
48         InsetCommand const * asInsetCommand() const override { return this; }
49
50         /// \return true if params are successfully read
51         static bool string2params(std::string const & data,
52                                   InsetCommandParams &);
53         ///
54         static std::string params2string(InsetCommandParams const &);
55         ///
56         InsetCommandParams const & params() const { return p_; }
57         ///
58         void setParams(InsetCommandParams const &);
59         ///
60         docstring const & getParam(std::string const & name) const;
61         ///
62         void setParam(std::string const & name, docstring const & value);
63         /// FIXME Remove
64         docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
65         ///
66         void setBroken(bool const b) const { broken_ = b; }
67         ///
68         bool isBroken() const { return broken_; }
69
70         /// \name Public functions inherited from Inset class
71         //@{
72         ///
73         void write(std::ostream & os) const override { p_.write(os); }
74         ///
75         void read(Lexer & lex) override { p_.Read(lex, &buffer()); }
76         ///
77         void doDispatch(Cursor & cur, FuncRequest & cmd) override;
78         ///
79         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const override;
80         ///
81         void metrics(MetricsInfo &, Dimension &) const override;
82         ///
83         void draw(PainterInfo & pi, int x, int y) const override;
84         ///
85         void drawBackground(PainterInfo &, int, int) const override {}
86         ///
87         void latex(otexstream &, OutputParams const &) const override;
88         ///
89         int plaintext(odocstringstream & ods, OutputParams const & op,
90                       size_t max_length = INT_MAX) const override;
91         ///
92         void docbook(XMLStream &, OutputParams const &) const override;
93         ///
94         void validate(LaTeXFeatures & features) const override;
95         ///
96         bool setMouseHover(BufferView const * bv, bool mouse_hover) const override;
97         ///
98         bool clickable(BufferView const &, int, int) const override { return hasSettings(); }
99         //@}
100
101 protected:
102         /// \name Methods relaying to the InsetCommandParams p_
103         //@{
104         ///
105         std::string contextMenuName() const override;
106         ///
107         bool showInsetDialog(BufferView * bv) const override;
108         //@}
109
110 protected:
111         /// \name Functions relaying to the InsetCommandParams
112         //@{
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); }
125         ///
126         void changeCmdName(std::string const & new_name);
127         /// was this inset changed by the current author?
128         /// if we're unable to find out, we return true, because of
129         /// how this is used.
130         bool isChangedByCurrentAuthor() const;
131         //@}
132
133 private:
134         /// This should provide the text for the button
135         virtual docstring screenLabel() const = 0;
136
137         /// \name Static public methods obligated for InsetCommand derived classes
138         //@{
139         /// Return parameter information for command cmdName.
140         /// Not implemented here. Must be implemented in derived class.
141         static ParamInfo const & findInfo(std::string const & cmdName);
142         /// Return default command for this inset.
143         /// Not implemented here. Must be implemented in derived class.
144         static std::string defaultCommand();
145         /// Whether this is a command this inset can represent.
146         /// Not implemented here. Must be implemented in derived class.
147         static bool isCompatibleCommand(std::string const & cmd);
148         //@}
149
150         ///
151         InsetCommandParams p_;
152         /// changes color when mouse enters/leaves this inset
153         mutable std::map<BufferView const *, bool> mouse_hover_;
154         ///
155         mutable RenderButton button_;
156         ///
157         mutable bool broken_;
158 };
159
160 /// Decode InsetCommand considering Inset name and data.
161 bool decodeInsetParam(std::string const & name, std::string & data,
162         Buffer const & buffer);
163
164 } // namespace lyx
165
166 #endif