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