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