]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCommand.h
rename LCursor->Cursor
[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  * Similar to InsetLaTeX but having control of the basic structure of a
30  *   LaTeX command: \name[options]{contents}.
31  */
32
33 ///
34 class InsetCommand : public InsetOld {
35 public:
36         ///
37         InsetCommand(InsetCommandParams const &, std::string const & mailer_name);
38         ///
39         ~InsetCommand();
40         ///
41         bool metrics(MetricsInfo &, Dimension &) const;
42         ///
43         void draw(PainterInfo & pi, int x, int y) const;
44         ///
45         void write(Buffer const &, std::ostream & os) const
46                 { p_.write(os); }
47         ///
48         virtual void read(Buffer const &, Lexer & lex)
49                 { p_.read(lex); }
50         ///
51         int latex(Buffer const &, odocstream &, OutputParams const &) const;
52         ///
53         int plaintext(Buffer const &, odocstream &, OutputParams const &) const;
54         ///
55         int docbook(Buffer const &, odocstream &, OutputParams const & runparams) const;
56         ///
57         InsetBase::Code lyxCode() const { return InsetBase::NO_CODE; }
58
59         ///
60         InsetCommandParams const & params() const { return p_; }
61         /// FIXME remove
62         std::string const getContents() const { return p_.getContents(); }
63 protected:
64         /// FIXME remove
65         void setContents(std::string const & c)
66         {
67                 updateButtonLabel_ = true;
68                 p_.setContents(c);
69         }
70 public:
71         ///
72         void setParam(std::string const & name, docstring const & value)
73         {
74                 updateButtonLabel_ = true;
75                 p_[name] = value;
76         }
77         ///
78         docstring const & getParam(std::string const & name) const
79         {
80                 return p_[name];
81         }
82         /// FIXME remove
83         virtual void replaceContents(std::string const & from, std::string const & to);
84         ///
85         RenderButton & button() const { return button_; }
86         ///
87         bool setMouseHover(bool mouse_hover);
88
89 protected:
90         ///
91         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
92         ///
93         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
94         ///
95         docstring const getCommand() const { return p_.getCommand(); }
96         ///
97         std::string const & getCmdName() const { return p_.getCmdName(); }
98         ///
99         void setCmdName(std::string const & n)
100         {
101                 updateButtonLabel_ = true;
102                 p_.setCmdName(n);
103         }
104         ///
105         void setParams(InsetCommandParams const &);
106         /// This should provide the text for the button
107         virtual docstring const getScreenLabel(Buffer const &) const = 0;
108
109 private:
110         ///
111         InsetCommandParams p_;
112         std::string mailer_name_;
113         /// changes color when mouse enters/leaves this inset
114         bool mouse_hover_;
115         mutable bool updateButtonLabel_;
116         mutable RenderButton button_;
117 };
118
119
120 class InsetCommandMailer : public MailInset {
121 public:
122         ///
123         InsetCommandMailer(std::string const & name, InsetCommand & inset);
124         ///
125         virtual InsetBase & inset() const { return inset_; }
126         ///
127         virtual std::string const & name() const { return name_; }
128         ///
129         virtual std::string const inset2string(Buffer const &) const;
130         ///
131         static void string2params(std::string const &, std::string const & name,
132                                   InsetCommandParams &);
133         ///
134         static std::string const params2string(std::string const & name,
135                                                InsetCommandParams const &);
136 private:
137         ///
138         std::string const name_;
139         ///
140         InsetCommand & inset_;
141 };
142
143
144
145 } // namespace lyx
146
147 #endif