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