]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCommand.h
204ae93a087ca76b60dd9a563d33d30f81dc5025
[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 public:
62         /// tell that the button label should be recomputed.
63         void refresh() { updateButtonLabel_ = true; }
64         ///
65         void setParam(std::string const & name, docstring const & value)
66         {
67                 updateButtonLabel_ = true;
68                 p_[name] = value;
69         }
70         ///
71         docstring const & getParam(std::string const & name) const
72         {
73                 return p_[name];
74         }
75         ///
76         void edit(Cursor & cur, bool left);
77         ///
78         RenderButton & button() const { return button_; }
79         ///
80         bool setMouseHover(bool mouse_hover);
81
82 protected:
83         ///
84         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
85         ///
86         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
87         ///
88         docstring const getCommand() const { return p_.getCommand(); }
89         ///
90         std::string const & getCmdName() const { return p_.getCmdName(); }
91         ///
92         void setCmdName(std::string const & n)
93         {
94                 updateButtonLabel_ = true;
95                 p_.setCmdName(n);
96         }
97         ///
98         void setParams(InsetCommandParams const &);
99         /// This should provide the text for the button
100         virtual docstring const getScreenLabel(Buffer const &) const = 0;
101
102 private:
103         ///
104         InsetCommandParams p_;
105         ///
106         std::string mailer_name_;
107         /// changes color when mouse enters/leaves this inset
108         bool mouse_hover_;
109         ///
110         mutable bool updateButtonLabel_;
111         ///
112         mutable RenderButton button_;
113 };
114
115
116 class InsetCommandMailer : public MailInset {
117 public:
118         ///
119         InsetCommandMailer(std::string const & name, InsetCommand & inset);
120         ///
121         virtual Inset & inset() const { return inset_; }
122         ///
123         virtual std::string const & name() const { return name_; }
124         ///
125         virtual std::string const inset2string(Buffer const &) const;
126         /// returns true if params are successfully read
127         static bool string2params(std::string const &, std::string const & name,
128                                   InsetCommandParams &);
129         ///
130         static std::string const params2string(std::string const & name,
131                                                InsetCommandParams const &);
132 private:
133         ///
134         std::string const name_;
135         ///
136         InsetCommand & inset_;
137 };
138
139
140
141 } // namespace lyx
142
143 #endif