]> git.lyx.org Git - lyx.git/blob - src/insets/insetcommand.h
Button face-lift: use mouse hover-buttons.
[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         /// Can remove one InsetBibKey is modified
51         /// FIXME remove
52         void scanCommand(std::string const & c) { p_.scanCommand(c); };
53         ///
54         virtual int latex(Buffer const &, odocstream &,
55                           OutputParams const &) const;
56         ///
57         int plaintext(Buffer const &, odocstream &,
58                   OutputParams const &) const;
59         ///
60         virtual int docbook(Buffer const &, odocstream &,
61                             OutputParams const & runparams) const;
62         ///
63         InsetBase::Code lyxCode() const { return InsetBase::NO_CODE; }
64
65         ///
66         InsetCommandParams const & params() const { return p_; }
67         /// FIXME remove
68         std::string const getContents() const { return p_.getContents(); }
69         /// FIXME remove
70         void setContents(std::string const & c)
71         {
72                 updateButtonLabel_ = true;
73                 p_.setContents(c);
74         }
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         /// FIXME remove
87         virtual void replaceContents(std::string const & from, std::string const & to);
88         /// FIXME remove
89         std::string const getOptions() const { return p_.getOptions(); }
90         /// FIXME remove
91         std::string const getSecOptions() const { return p_.getSecOptions(); }
92         ///
93         RenderButton & button() const { return button_; }
94         ///
95         bool setMouseHover(bool mouse_hover);
96
97 protected:
98         ///
99         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
100         ///
101         bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
102         ///
103         docstring const getCommand() const { return p_.getCommand(); }
104         ///
105         std::string const & getCmdName() const { return p_.getCmdName(); }
106         ///
107         void setCmdName(std::string const & n)
108         {
109                 updateButtonLabel_ = true;
110                 p_.setCmdName(n);
111         }
112         ///
113         void setOptions(std::string const & o)
114         {
115                 updateButtonLabel_ = true;
116                 p_.setOptions(o);
117         }
118         ///
119         void setSecOptions(std::string const & s)
120         {
121                 updateButtonLabel_ = true;
122                 p_.setSecOptions(s);
123         }
124         ///
125         void setParams(InsetCommandParams const &);
126         /// This should provide the text for the button
127         virtual docstring const getScreenLabel(Buffer const &) const = 0;
128
129 private:
130         ///
131         InsetCommandParams p_;
132         std::string mailer_name_;
133         /// changes color when mouse enters/leaves this inset
134         bool mouse_hover_;
135         mutable bool updateButtonLabel_;
136         mutable RenderButton button_;
137 };
138
139
140 class InsetCommandMailer : public MailInset {
141 public:
142         ///
143         InsetCommandMailer(std::string const & name, InsetCommand & inset);
144         ///
145         virtual InsetBase & inset() const { return inset_; }
146         ///
147         virtual std::string const & name() const { return name_; }
148         ///
149         virtual std::string const inset2string(Buffer const &) const;
150         ///
151         static void string2params(std::string const &, std::string const & name,
152                                   InsetCommandParams &);
153         ///
154         static std::string const params2string(std::string const & name,
155                                                InsetCommandParams const &);
156 private:
157         ///
158         std::string const name_;
159         ///
160         InsetCommand & inset_;
161 };
162
163
164
165 } // namespace lyx
166
167 #endif