]> git.lyx.org Git - lyx.git/blob - src/insets/insetcommand.h
* BufferParams:
[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 "render_button.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 &, LyXLex & 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         /// FIXME remove
64         void setContents(std::string const & c)
65         {
66                 updateButtonLabel_ = true;
67                 p_.setContents(c);
68         }
69         ///
70         void setParam(std::string const & name, docstring const & value)
71         {
72                 updateButtonLabel_ = true;
73                 p_[name] = value;
74         }
75         ///
76         docstring const & getParam(std::string const & name) const
77         {
78                 return p_[name];
79         }
80         /// FIXME remove
81         virtual void replaceContents(std::string const & from, std::string const & to);
82         /// FIXME remove
83         std::string const getOptions() const { return p_.getOptions(); }
84         /// FIXME remove
85         std::string const getSecOptions() const { return p_.getSecOptions(); }
86         ///
87         RenderButton & button() const { return button_; }
88         ///
89         bool setMouseHover(bool mouse_hover);
90
91 protected:
92         ///
93         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
94         ///
95         bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
96         ///
97         docstring const getCommand() const { return p_.getCommand(); }
98         ///
99         std::string const & getCmdName() const { return p_.getCmdName(); }
100         ///
101         void setCmdName(std::string const & n)
102         {
103                 updateButtonLabel_ = true;
104                 p_.setCmdName(n);
105         }
106         ///
107         void setOptions(std::string const & o)
108         {
109                 updateButtonLabel_ = true;
110                 p_.setOptions(o);
111         }
112         ///
113         void setSecOptions(std::string const & s)
114         {
115                 updateButtonLabel_ = true;
116                 p_.setSecOptions(s);
117         }
118         ///
119         void setParams(InsetCommandParams const &);
120         /// This should provide the text for the button
121         virtual docstring const getScreenLabel(Buffer const &) const = 0;
122
123 private:
124         ///
125         InsetCommandParams p_;
126         std::string mailer_name_;
127         /// changes color when mouse enters/leaves this inset
128         bool mouse_hover_;
129         mutable bool updateButtonLabel_;
130         mutable RenderButton button_;
131 };
132
133
134 class InsetCommandMailer : public MailInset {
135 public:
136         ///
137         InsetCommandMailer(std::string const & name, InsetCommand & inset);
138         ///
139         virtual InsetBase & inset() const { return inset_; }
140         ///
141         virtual std::string const & name() const { return name_; }
142         ///
143         virtual std::string const inset2string(Buffer const &) const;
144         ///
145         static void string2params(std::string const &, std::string const & name,
146                                   InsetCommandParams &);
147         ///
148         static std::string const params2string(std::string const & name,
149                                                InsetCommandParams const &);
150 private:
151         ///
152         std::string const name_;
153         ///
154         InsetCommand & inset_;
155 };
156
157
158
159 } // namespace lyx
160
161 #endif