]> git.lyx.org Git - lyx.git/blob - src/insets/insetcommand.h
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[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         virtual int latex(Buffer const &, odocstream &,
52                           OutputParams const &) const;
53         ///
54         int plaintext(Buffer const &, odocstream &,
55                   OutputParams const &) const;
56         ///
57         virtual int docbook(Buffer const &, odocstream &,
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, docstring const & value)
74         {
75                 updateButtonLabel_ = true;
76                 p_[name] = value;
77         }
78         ///
79         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         bool setMouseHover(bool mouse_hover);
93
94 protected:
95         ///
96         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
97         ///
98         bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
99         ///
100         docstring const getCommand() const { return p_.getCommand(); }
101         ///
102         std::string const & getCmdName() const { return p_.getCmdName(); }
103         ///
104         void setCmdName(std::string const & n)
105         {
106                 updateButtonLabel_ = true;
107                 p_.setCmdName(n);
108         }
109         ///
110         void setOptions(std::string const & o)
111         {
112                 updateButtonLabel_ = true;
113                 p_.setOptions(o);
114         }
115         ///
116         void setSecOptions(std::string const & s)
117         {
118                 updateButtonLabel_ = true;
119                 p_.setSecOptions(s);
120         }
121         ///
122         void setParams(InsetCommandParams const &);
123         /// This should provide the text for the button
124         virtual docstring const getScreenLabel(Buffer const &) const = 0;
125
126 private:
127         ///
128         InsetCommandParams p_;
129         std::string mailer_name_;
130         /// changes color when mouse enters/leaves this inset
131         bool mouse_hover_;
132         mutable bool updateButtonLabel_;
133         mutable RenderButton button_;
134 };
135
136
137 class InsetCommandMailer : public MailInset {
138 public:
139         ///
140         InsetCommandMailer(std::string const & name, InsetCommand & inset);
141         ///
142         virtual InsetBase & inset() const { return inset_; }
143         ///
144         virtual std::string const & name() const { return name_; }
145         ///
146         virtual std::string const inset2string(Buffer const &) const;
147         ///
148         static void string2params(std::string const &, std::string const & name,
149                                   InsetCommandParams &);
150         ///
151         static std::string const params2string(std::string const & name,
152                                                InsetCommandParams const &);
153 private:
154         ///
155         std::string const name_;
156         ///
157         InsetCommand & inset_;
158 };
159
160
161
162 } // namespace lyx
163
164 #endif