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