]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCommand.h
Cleanup mouse/selection/context-menu interactions.
[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
30 ///
31 class InsetCommand : public Inset {
32 public:
33         ///
34         InsetCommand(InsetCommandParams const &, std::string const & mailer_name);
35         ///
36         ~InsetCommand();
37         ///
38         void metrics(MetricsInfo &, Dimension &) const;
39         ///
40         Dimension const dimension(BufferView const &) const { return button_.dimension(); }
41         ///
42         void draw(PainterInfo & pi, int x, int y) const;
43         ///
44         void write(std::ostream & os) const { p_.write(os); }
45         ///
46         void read(Lexer & lex) { p_.read(lex); }
47         ///
48         int latex(odocstream &, OutputParams const &) const;
49         ///
50         int plaintext(odocstream &, OutputParams const &) const;
51         ///
52         int docbook(odocstream &, OutputParams const & runparams) const;
53         ///
54         InsetCode lyxCode() const { return NO_CODE; }
55         ///
56         InsetCommandParams const & params() const { return p_; }
57         /// FIXME Remove
58         docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
59         ///
60         void setParam(std::string const & name, docstring const & value)
61         {
62                 p_[name] = value;
63         }
64         ///
65         docstring const & getParam(std::string const & name) const
66         {
67                 return p_[name];
68         }
69         ///
70         void edit(Cursor & cur, bool front, 
71                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
72         ///
73         RenderButton & button() const { return button_; }
74         ///
75         bool setMouseHover(bool mouse_hover);
76         /// Return parameter information for command cmdName.
77         /// Not implemented here. Must be implemented in derived class.
78         static ParamInfo const & findInfo(std::string const & cmdName);
79         /// Return default command for this inset.
80         /// Not implemented here. Must be implemented in derived class.
81         static std::string defaultCommand();
82         /// Whether this is a command this inset can represent.
83         /// Not implemented here. Must be implemented in derived class.
84         static bool isCompatibleCommand(std::string const & cmd);
85         /// update label and references.
86         virtual void updateCommand(docstring const &, bool) {};
87         ///
88         virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
89
90 protected:
91         ///
92         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
93         ///
94         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
95         ///
96         docstring const getCommand() const { return p_.getCommand(); }
97         ///
98         std::string const & getCmdName() const { return p_.getCmdName(); }
99         ///
100         void setCmdName(std::string const & n) { p_.setCmdName(n); }
101         ///
102         void setParams(InsetCommandParams const &);
103         /// This should provide the text for the button
104         virtual docstring screenLabel() const = 0;
105
106 private:
107         ///
108         InsetCommandParams p_;
109         ///
110         std::string mailer_name_;
111         /// changes color when mouse enters/leaves this inset
112         bool mouse_hover_;
113         ///
114         mutable RenderButton button_;
115 };
116
117
118 class InsetCommandMailer : public MailInset {
119 public:
120         ///
121         InsetCommandMailer(std::string const & name, InsetCommand & inset);
122         ///
123         virtual Inset & inset() const { return inset_; }
124         ///
125         virtual std::string const & name() const { return name_; }
126         ///
127         virtual std::string const inset2string(Buffer const &) const;
128         /// returns true if params are successfully read
129         static bool string2params(std::string const &, std::string const & name,
130                                   InsetCommandParams &);
131         ///
132         static std::string const params2string(std::string const & name,
133                                                InsetCommandParams const &);
134 private:
135         ///
136         std::string const name_;
137         ///
138         InsetCommand & inset_;
139 };
140
141
142
143 } // namespace lyx
144
145 #endif