]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCommand.h
Correctly load documents moved elsewhere after save.
[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
20
21 namespace lyx {
22
23 class Cursor;
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         ///
40         InsetCommand(InsetCommand const & rhs);
41         ///
42         virtual ~InsetCommand();
43         ///
44         InsetCommand * asInsetCommand() { return this; }
45         ///
46         InsetCommand const * asInsetCommand() const { return this; }
47
48         /// \return true if params are successfully read
49         static bool string2params(std::string const & data,
50                                   InsetCommandParams &);
51         ///
52         static std::string params2string(InsetCommandParams const &);
53         ///
54         InsetCommandParams const & params() const { return p_; }
55         ///
56         void setParams(InsetCommandParams const &);
57         ///
58         docstring const & getParam(std::string const & name) const;
59         ///
60         void setParam(std::string const & name, docstring const & value);
61         /// FIXME Remove
62         docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); }
63
64         /// \name Public functions inherited from Inset class
65         //@{
66         ///
67         void write(std::ostream & os) const { p_.write(os); }
68         ///
69         void read(Lexer & lex, Buffer const * buf) { p_.read(lex, buf); }
70         ///
71         void doDispatch(Cursor & cur, FuncRequest & cmd);
72         ///
73         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
74         ///
75         void metrics(MetricsInfo &, Dimension &) const;
76         ///
77         void draw(PainterInfo & pi, int x, int y) const;
78         ///
79         void latex(otexstream &, OutputParams const &) const;
80         ///
81         int plaintext(odocstringstream & ods, OutputParams const & op,
82                       size_t max_length = INT_MAX) const;
83         ///
84         int docbook(odocstream &, OutputParams const & runparams) const;
85         ///
86         bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
87         ///
88         bool clickable(int, int) const { return hasSettings(); }
89         //@}
90
91 protected:
92         /// \name Methods relaying to the InsetCommandParams p_
93         //@{
94         ///
95         std::string contextMenuName() const;
96         ///
97         bool showInsetDialog(BufferView * bv) const;
98         ///
99         Dimension const dimension(BufferView const &) const 
100                 { return button_.dimension(); }
101         //@}
102
103 protected:
104         /// \name Functions relaying to the InsetCommandParams
105         //@{
106         /// Build the complete LaTeX command
107         /// \see InsetCommandParams::getCommand
108         docstring const getCommand(OutputParams const & rp) const 
109                 { return p_.getCommand(rp); }
110         /// Return the command name
111         /// \see InsetCommandParams::getCmdName
112         std::string const & getCmdName() const { return p_.getCmdName(); }
113         /// Set the name to \p n. This must be a known name. All parameters
114         /// are cleared except those that exist also in the new command.
115         /// What matters here is the parameter name, not position.
116         /// \see InsetCommandParams::setCmdName
117         void setCmdName(std::string const & n) { p_.setCmdName(n); }
118         //@}
119
120 private:
121         ///
122         RenderButton & button() const { return button_; }
123         /// This should provide the text for the button
124         virtual docstring screenLabel() const = 0;
125
126         /// \name Static public methods obligated for InsetCommand derived classes
127         //@{
128         /// Return parameter information for command cmdName.
129         /// Not implemented here. Must be implemented in derived class.
130         static ParamInfo const & findInfo(std::string const & cmdName);
131         /// Return default command for this inset.
132         /// Not implemented here. Must be implemented in derived class.
133         static std::string defaultCommand();
134         /// Whether this is a command this inset can represent.
135         /// Not implemented here. Must be implemented in derived class.
136         static bool isCompatibleCommand(std::string const & cmd);
137         //@}
138
139         ///
140         InsetCommandParams p_;
141         /// changes color when mouse enters/leaves this inset
142         mutable std::map<BufferView const *, bool> mouse_hover_;
143         ///
144         mutable RenderButton button_;
145 };
146
147 /// Decode InsetCommand considering Inset name and data.
148 bool decodeInsetParam(std::string const & name, std::string & data,
149         Buffer const & buffer);
150
151 } // namespace lyx
152
153 #endif