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