]> git.lyx.org Git - lyx.git/blob - src/insets/insetcommand.h
the dispatch patch
[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         ///
36         void metrics(MetricsInfo &, Dimension &) const;
37         ///
38         void draw(PainterInfo & pi, int x, int y) const;
39         ///
40         void write(Buffer const &, std::ostream & os) const
41                 { p_.write(os); }
42         ///
43         virtual void read(Buffer const &, LyXLex & lex)
44                 { p_.read(lex); }
45         /// Can remove one InsetBibKey is modified
46         void scanCommand(std::string const & c) { p_.scanCommand(c); };
47         ///
48         virtual int latex(Buffer const &, std::ostream &,
49                           LatexRunParams const &) const;
50         ///
51         int ascii(Buffer const &, std::ostream &, int linelen) const;
52         ///
53         virtual int linuxdoc(Buffer const &, std::ostream &) const;
54         ///
55         virtual int docbook(Buffer const &, std::ostream &, bool) const;
56         ///
57         InsetOld::Code lyxCode() const { return InsetOld::NO_CODE; }
58
59         ///
60         InsetCommandParams const & params() const { return p_; }
61         ///
62         std::string const & getContents() const { return p_.getContents(); }
63         ///
64         void setContents(std::string const & c) { p_.setContents(c); }
65         ///
66         std::string const & getOptions() const { return p_.getOptions(); }
67         ///
68         RenderButton & button() const { return button_; }
69
70 protected:
71         ///
72         virtual
73         dispatch_result
74         priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &);
75         ///
76         std::string const getCommand() const { return p_.getCommand(); }
77         ///
78         std::string const & getCmdName() const { return p_.getCmdName(); }
79         ///
80         void setCmdName(std::string const & n) { p_.setCmdName(n); }
81         ///
82         void setOptions(std::string const & o) { p_.setOptions(o); }
83         ///
84         void setParams(InsetCommandParams const &);
85         /// This should provide the text for the button
86         virtual std::string const getScreenLabel(Buffer const &) const = 0;
87
88 private:
89         ///
90         InsetCommandParams p_;
91         mutable bool set_label_;
92         mutable RenderButton button_;
93 };
94
95
96 class InsetCommandMailer : public MailInset {
97 public:
98         ///
99         InsetCommandMailer(std::string const & name, InsetCommand & inset);
100         ///
101         virtual InsetBase & inset() const { return inset_; }
102         ///
103         virtual std::string const & name() const { return name_; }
104         ///
105         virtual std::string const inset2string(Buffer const &) const;
106         ///
107         static void string2params(std::string const &, InsetCommandParams &);
108         ///
109         static std::string const params2string(std::string const & name,
110                                           InsetCommandParams const &);
111 private:
112         ///
113         std::string const name_;
114         ///
115         InsetCommand & inset_;
116 };
117
118
119 #endif