]> git.lyx.org Git - lyx.git/blob - src/insets/insetcommand.h
829db405bb9164fa0eecece0157febabdb18e1f8
[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
17 #include "inset.h"
18 #include "insetcommandparams.h"
19 #include "render_button.h"
20 #include "mailinset.h"
21
22 // Created by Alejandro 970222
23 /** Used to insert a LaTeX command automatically
24  *
25  * Similar to InsetLaTeX but having control of the basic structure of a
26  *   LaTeX command: \name[options]{contents}.
27  */
28
29 ///
30 class InsetCommand : public InsetOld {
31 public:
32         ///
33         explicit
34         InsetCommand(InsetCommandParams const &,
35                      std::string const & mailer_name);
36         ///
37         ~InsetCommand();
38         ///
39         void metrics(MetricsInfo &, Dimension &) const;
40         ///
41         void draw(PainterInfo & pi, int x, int y) const;
42         ///
43         void write(Buffer const &, std::ostream & os) const
44                 { p_.write(os); }
45         ///
46         virtual void read(Buffer const &, LyXLex & lex)
47                 { p_.read(lex); }
48         /// Can remove one InsetBibKey is modified
49         void scanCommand(std::string const & c) { p_.scanCommand(c); };
50         ///
51         virtual int latex(Buffer const &, std::ostream &,
52                           OutputParams const &) const;
53         ///
54         int plaintext(Buffer const &, std::ostream &,
55                   OutputParams const &) const;
56         ///
57         virtual int linuxdoc(Buffer const &, std::ostream &,
58                              OutputParams const &) const;
59         ///
60         virtual int docbook(Buffer const &, std::ostream &,
61                             OutputParams const & runparams) const;
62         ///
63         InsetOld::Code lyxCode() const { return InsetOld::NO_CODE; }
64
65         ///
66         InsetCommandParams const & params() const { return p_; }
67         ///
68         std::string const & getContents() const { return p_.getContents(); }
69         ///
70         void setContents(std::string const & c) { p_.setContents(c); }
71         ///
72         std::string const & getOptions() const { return p_.getOptions(); }
73         ///
74         RenderButton & button() const { return button_; }
75
76 protected:
77         ///
78         virtual
79         DispatchResult
80         priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &);
81         ///
82         std::string const getCommand() const { return p_.getCommand(); }
83         ///
84         std::string const & getCmdName() const { return p_.getCmdName(); }
85         ///
86         void setCmdName(std::string const & n) { p_.setCmdName(n); }
87         ///
88         void setOptions(std::string const & o) { p_.setOptions(o); }
89         ///
90         void setParams(InsetCommandParams const &);
91         /// This should provide the text for the button
92         virtual std::string const getScreenLabel(Buffer const &) const = 0;
93
94 private:
95         ///
96         InsetCommandParams p_;
97         std::string mailer_name_;
98         mutable bool set_label_;
99         mutable RenderButton button_;
100 };
101
102
103 class InsetCommandMailer : public MailInset {
104 public:
105         ///
106         InsetCommandMailer(std::string const & name, InsetCommand & inset);
107         ///
108         virtual InsetBase & inset() const { return inset_; }
109         ///
110         virtual std::string const & name() const { return name_; }
111         ///
112         virtual std::string const inset2string(Buffer const &) const;
113         ///
114         static void string2params(std::string const &, std::string const & name,
115                                   InsetCommandParams &);
116         ///
117         static std::string const params2string(std::string const & name,
118                                                InsetCommandParams const &);
119 private:
120         ///
121         std::string const name_;
122         ///
123         InsetCommand & inset_;
124 };
125
126
127 #endif