]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCommand.h
InsetCommand.h: Reorder and add comments.
[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 #include "Cursor.h"
20
21
22 namespace lyx {
23
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                 std::string const & mailer_name);
40         ///
41         InsetCommand(InsetCommand const & rhs);
42         ///
43         virtual ~InsetCommand();
44         ///
45         InsetCommand * asInsetCommand() { return this; }
46         ///
47         InsetCommand const * asInsetCommand() const { return this; }
48
49
50         /// returns true if params are successfully read
51         static bool string2params(std::string const &, std::string const & name,
52                                   InsetCommandParams &);
53         ///
54         static std::string params2string(std::string const & name,
55                                                InsetCommandParams const &);
56         ///
57         InsetCommandParams const & params() const { return p_; }
58         ///
59         void setParams(InsetCommandParams const &);
60         ///
61         docstring const & getParam(std::string const & name) const;
62         ///
63         void setParam(std::string const & name, docstring const & value);
64         /// FIXME Remove
65         docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
66         /// whether to include this inset in the strings generated for the TOC
67         virtual bool isInToc() const { return false; }
68
69         /// \name Methods inherited from Inset class
70         //@{
71         ///
72         void write(std::ostream & os) const { p_.write(os); }
73         ///
74         void read(Lexer & lex) { p_.read(lex); }
75         ///
76         void doDispatch(Cursor & cur, FuncRequest & cmd);
77         ///
78         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
79         ///
80         void metrics(MetricsInfo &, Dimension &) const;
81         ///
82         void draw(PainterInfo & pi, int x, int y) const;
83         ///
84         int latex(odocstream &, OutputParams const &) const;
85         ///
86         int plaintext(odocstream &, OutputParams const &) const;
87         ///
88         int docbook(odocstream &, OutputParams const & runparams) const;
89         ///
90         bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
91         ///
92         bool clickable(int, int) const { return hasSettings(); }
93         ///
94         docstring contextMenu(BufferView const & bv, int x, int y) const;
95         ///
96         bool showInsetDialog(BufferView * bv) const;
97         ///
98         Dimension const dimension(BufferView const &) const 
99                 { return button_.dimension(); }
100         //@}
101
102 protected:
103         /// \name Methods relaying to the InsetCommandParams
104         //@{
105         /// Build the complete LaTeX command
106         /// \see InsetCommandParams::getCommand
107         docstring const getCommand(OutputParams const & rp) const 
108                 { return p_.getCommand(rp); }
109         /// Return the command name
110         /// \see InsetCommandParams::getCmdName
111         std::string const & getCmdName() const { return p_.getCmdName(); }
112         /// Set the name to \p n. This must be a known name. All parameters
113         /// are cleared except those that exist also in the new command.
114         /// What matters here is the parameter name, not position.
115         /// \see InsetCommandParams::setCmdName
116         void setCmdName(std::string const & n) { p_.setCmdName(n); }
117         //@}
118
119 private:
120         ///
121         RenderButton & button() const { return button_; }
122         /// This should provide the text for the button
123         virtual docstring screenLabel() const = 0;
124
125         /// \name Methods obligated for InsetCommand derived classes
126         //@{
127         /// Return parameter information for command cmdName.
128         /// Not implemented here. Must be implemented in derived class.
129         static ParamInfo const & findInfo(std::string const & cmdName);
130         /// Return default command for this inset.
131         /// Not implemented here. Must be implemented in derived class.
132         static std::string defaultCommand();
133         /// Whether this is a command this inset can represent.
134         /// Not implemented here. Must be implemented in derived class.
135         static bool isCompatibleCommand(std::string const & cmd);
136         //@}
137
138         ///
139         InsetCommandParams p_;
140         ///
141         std::string mailer_name_;
142         /// changes color when mouse enters/leaves this inset
143         mutable std::map<BufferView const *, bool> mouse_hover_;
144         ///
145         mutable RenderButton button_;
146 };
147
148 /// Decode InsetCommand considering Inset name and data.
149 bool decodeInsetParam(std::string const & name, std::string & data,
150         Buffer const & buffer);
151
152 } // namespace lyx
153
154 #endif