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