]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCommandParams.h
* MetricsInfo::background_color: int -> ColorCode
[lyx.git] / src / insets / InsetCommandParams.h
1 // -*- C++ -*-
2 /**
3  * \file InsetCommandParams.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 Georg Baum
9  * \author Richard Heck
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef INSETCOMMANDPARAMS_H
15 #define INSETCOMMANDPARAMS_H
16
17 #include "InsetCode.h"
18 #include "support/docstring.h"
19
20 #include <iosfwd>
21 #include <list>
22 #include <string>
23 #include <vector>
24
25
26 namespace lyx {
27
28 class Lexer;
29
30 // No parameter may be named "preview", because that is a required
31 // flag for all commands.
32 struct CommandInfo {
33         /// Number of parameters
34         size_t n;
35         /// Parameter names. paramnames[n] must be "".
36         char const * const * paramnames;
37         /// Tells whether a parameter is optional
38         bool const * optional;
39 };
40
41
42 class InsetCommandParams {
43 public:
44         /// Construct parameters for inset of type \p code.
45         explicit InsetCommandParams(InsetCode code);
46         /// Construct parameters for inset of type \p code with
47         /// command name \p cmdName.
48         explicit InsetCommandParams(InsetCode code,
49                         std::string const & cmdName);
50         ///
51         std::string insetType() const { return insetName(insetCode_); }
52         ///
53         InsetCode code() const { return insetCode_; }
54         ///
55         void read(Lexer &);
56         /// Parse the command
57         ///
58         void write(std::ostream &) const;
59         /// Build the complete LaTeX command
60         docstring const getCommand() const;
61         /// Return the command name
62         std::string const & getCmdName() const { return cmdName_; }
63         /// Set the name to \p n. This must be a known name. All parameters
64         /// are cleared except those that exist also in the new command.
65         /// What matters here is the parameter name, not position.
66         void setCmdName(std::string const & n);
67         /// FIXME Would be better removed, but is used in BufferView.cpp in 
68         /// ways that make removal hard.
69         docstring const getFirstNonOptParam() const;
70         /// get parameter \p name
71         docstring const & operator[](std::string const & name) const;
72         /// set parameter \p name
73         docstring & operator[](std::string const & name);
74         ///
75         bool preview() const { return preview_; }
76         ///
77         void preview(bool p) { preview_ = p; }
78         /// Clear the values of all parameters
79         void clear();
80
81 private:
82         ///
83         /// Get information for inset type \p code.
84         /// Returns 0 if the inset is not known.
85         static CommandInfo const * findInfo(InsetCode code);
86         /// Get information for \p code and command \p cmdName.
87         /// Returns 0 if the combination is not known.
88         /// Don't call this without first making sure the command name is
89         /// acceptable to the inset.
90         static CommandInfo const * findInfo(InsetCode code,
91                                             std::string const & cmdName);
92         ///
93         static bool isCompatibleCommand(InsetCode code, std::string const & s);
94         ///
95         std::string getDefaultCmd(InsetCode);
96         /// Description of all command properties
97         CommandInfo const * info_;
98         /// what kind of inset we're the parameters for
99         InsetCode insetCode_;
100         /// The name of this command as it appears in .lyx and .tex files
101         std::string cmdName_;
102         ///
103         typedef std::vector<docstring> ParamVector;
104         /// The parameters (both optional and required ones). The order is
105         /// the same that is required for LaTeX output. The size of params_
106         /// is always info_->n.
107         ParamVector params_;
108         ///
109         bool preview_;
110         ///
111         friend bool operator==(InsetCommandParams const &,
112                         InsetCommandParams const &);
113 };
114
115
116 ///
117 bool operator==(InsetCommandParams const &, InsetCommandParams const &);
118
119 ///
120 bool operator!=(InsetCommandParams const &, InsetCommandParams const &);
121
122
123 } // namespace lyx
124
125 #endif