]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCommand.h
* InsetCollapsable:
[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 INSET_LATEXCOMMAND_H
14 #define INSET_LATEXCOMMAND_H
15
16 #include "Inset.h"
17 #include "InsetCommandParams.h"
18 #include "RenderButton.h"
19 #include "MailInset.h"
20 #include "Cursor.h"
21
22
23 namespace lyx {
24
25
26 // Created by Alejandro 970222
27 /** Used to insert a LaTeX command automatically.
28  */
29
30 ///
31 class InsetCommand : public Inset {
32 public:
33         ///
34         InsetCommand(InsetCommandParams const &, std::string const & mailer_name);
35         ///
36         ~InsetCommand();
37         ///
38         void metrics(MetricsInfo &, Dimension &) const;
39         ///
40         Dimension const dimension(BufferView const &) const { return button_.dimension(); }
41         ///
42         void draw(PainterInfo & pi, int x, int y) const;
43         ///
44         void write(Buffer const &, std::ostream & os) const
45                 { p_.write(os); }
46         ///
47         virtual void read(Buffer const &, Lexer & lex)
48                 { p_.read(lex); }
49         ///
50         int latex(Buffer const &, odocstream &, OutputParams const &) const;
51         ///
52         int plaintext(Buffer const &, odocstream &, OutputParams const &) const;
53         ///
54         int docbook(Buffer const &, odocstream &, OutputParams const & runparams) const;
55         ///
56         InsetCode lyxCode() const { return NO_CODE; }
57         ///
58         InsetCommandParams const & params() const { return p_; }
59         /// FIXME Remove
60         docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
61         /// Whether the button label should be recomputed.
62         void refresh() { updateButtonLabel_ = true; }
63         ///
64         void setParam(std::string const & name, docstring const & value)
65         {
66                 updateButtonLabel_ = true;
67                 p_[name] = value;
68         }
69         ///
70         docstring const & getParam(std::string const & name) const
71         {
72                 return p_[name];
73         }
74         ///
75         void edit(Cursor & cur, bool left);
76         ///
77         RenderButton & button() const { return button_; }
78         ///
79         bool setMouseHover(bool mouse_hover);
80         /// Return parameter information for command cmdName.
81         /// Not implemented here. Must be implemented in derived class.
82         static CommandInfo const * findInfo(std::string const & cmdName);
83         /// Return default command for this inset.
84         /// Not implemented here. Must be implemented in derived class.
85         static std::string defaultCommand();
86         /// Whether this is a command this inset can represent.
87         /// Not implemented here. Must be implemented in derived class.
88         static bool isCompatibleCommand(std::string const & cmd);
89
90 protected:
91         ///
92         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
93         ///
94         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
95         ///
96         docstring const getCommand() const { return p_.getCommand(); }
97         ///
98         std::string const & getCmdName() const { return p_.getCmdName(); }
99         ///
100         void setCmdName(std::string const & n)
101         {
102                 updateButtonLabel_ = true;
103                 p_.setCmdName(n);
104         }
105         ///
106         void setParams(InsetCommandParams const &);
107         /// This should provide the text for the button
108         virtual docstring const getScreenLabel(Buffer const &) const = 0;
109
110 private:
111         ///
112         InsetCommandParams p_;
113         ///
114         std::string mailer_name_;
115         /// changes color when mouse enters/leaves this inset
116         bool mouse_hover_;
117         ///
118         mutable bool updateButtonLabel_;
119         ///
120         mutable RenderButton button_;
121 };
122
123
124 class InsetCommandMailer : public MailInset {
125 public:
126         ///
127         InsetCommandMailer(std::string const & name, InsetCommand & inset);
128         ///
129         virtual Inset & inset() const { return inset_; }
130         ///
131         virtual std::string const & name() const { return name_; }
132         ///
133         virtual std::string const inset2string(Buffer const &) const;
134         /// returns true if params are successfully read
135         static bool string2params(std::string const &, std::string const & name,
136                                   InsetCommandParams &);
137         ///
138         static std::string const params2string(std::string const & name,
139                                                InsetCommandParams const &);
140 private:
141         ///
142         std::string const name_;
143         ///
144         InsetCommand & inset_;
145 };
146
147
148
149 } // namespace lyx
150
151 #endif