]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCommandParams.h
In multi-par sequences, check for arguments in all pars
[lyx.git] / src / insets / InsetCommandParams.h
index 6cec1ffabc8efa4178e52de91c7a9e102adf00f8..7dc59fa5ee764fc0e46cf65d4d5a6008ee5fdb42 100644 (file)
 #define INSETCOMMANDPARAMS_H
 
 #include "InsetCode.h"
+
+#include "OutputParams.h"
+
 #include "support/docstring.h"
 
-#include <iosfwd>
 #include <string>
 #include <vector>
 #include <map>
@@ -30,49 +32,32 @@ class Lexer;
 class ParamInfo {
 public:
        /// Types of parameters
-       /// WARNING: LATEX_KV_* `parameters' aren't really parameters at all
-       /// but merely markers for where the keyval-type parameters should
-       /// appear in the LaTeX output. ParamInfo::hasParam(name) therefore 
-       /// returns FALSE if the corresponding `parameter' is of type
-       /// LATEX_KV_*.
-       /// It is assumed here that there is exactly one argument that accepts
-       /// the key=value pairs.
        enum ParamType {
                LATEX_OPTIONAL,    /// normal optional argument
                LATEX_REQUIRED,    /// normal required argument
-               LATEX_KV_OPTIONAL, /// optional argument that uses keyval
-               LATEX_KV_REQUIRED, /// required argument that uses keyval
-               LATEX_KEY,         /// a key to be used with keyval argument
                LYX_INTERNAL       /// a parameter used internally by LyX
        };
+       /// Special handling on output
+       enum ParamHandling {
+               HANDLING_NONE,    /// no special handling
+               HANDLING_ESCAPE,  /// escape special characters
+               HANDLING_LATEXIFY /// transform special characters to LaTeX macros
+       };
        ///
        class ParamData {
        // No parameter may be named "preview", because that is a required
        // flag for all commands.
        public:
                ///
-               ParamData(std::string const &, ParamType);
+               ParamData(std::string const &, ParamType, ParamHandling = HANDLING_NONE);
                ///
                std::string name() const { return name_; }
                ///
                ParamType type() const { return type_; }
-               /// whether this is a key for use with keyval
-               bool isKey() const
-                       { return type_ == LATEX_KEY; }
+               ///
+               ParamHandling handling() const { return handling_; }
                /// whether this is an optional LaTeX argument
-               inline bool isOptional() const;
-               /// whether this is a keyval argument
-               inline bool isKeyValArg() const;
-#if 0
-               //presently unused but perhaps useful at some point
-               /// whether this is a required LaTeX argument
-               bool isRequired() const
-                       { return type_ == ParamInfo::LATEX_REQUIRED ||
-                                       type_ == ParamInfo::LATEX_KV_REQUIRED; }
-               /// whether this is a LaTeX argument
-               inline bool isLaTeXArgument() const
-                       { return isOptional() || isRequired(); }
-#endif
+               bool isOptional() const;
                ///
                bool operator==(ParamData const &) const;
                /// 
@@ -83,10 +68,13 @@ public:
                std::string name_;
                ///
                ParamType type_;
+               /// do we need special handling on latex output?
+               ParamHandling handling_;
        };
 
        /// adds a new parameter
-       void add(std::string const & name, ParamType type);
+       void add(std::string const & name, ParamType type,
+                ParamHandling = HANDLING_NONE);
        ///
        bool empty() const { return info_.empty(); }
        ///
@@ -99,8 +87,6 @@ public:
        const_iterator const end() const { return info_.end(); }
        /// \return true if name corresponds to a parameter of some sort.
        /// \return false if the parameter does not exist at all of it it 
-       /// corresponds to a `parameter' of type LATEX_KV_*; these do not 
-       /// really represent parameters but just argument places.
        bool hasParam(std::string const & name) const;
        ///
        ParamData const & operator[](std::string const & name) const;
@@ -121,7 +107,7 @@ public:
        explicit InsetCommandParams(InsetCode code,
                        std::string const & cmdName);
        ///
-       std::string insetType() const { return insetName(insetCode_); }
+       std::string insetType() const;
        ///
        InsetCode code() const { return insetCode_; }
        ///
@@ -130,7 +116,7 @@ public:
        ///
        void write(std::ostream &) const;
        /// Build the complete LaTeX command
-       docstring const getCommand() const;
+       docstring getCommand(OutputParams const &) const;
        /// Return the command name
        std::string const & getCmdName() const { return cmdName_; }
        /// Set the name to \p n. This must be a known name. All parameters
@@ -139,14 +125,12 @@ public:
        void setCmdName(std::string const & n);
        /// FIXME Would be better removed, but is used in BufferView.cpp in 
        /// ways that make removal hard.
-       docstring const getFirstNonOptParam() const;
+       docstring getFirstNonOptParam() const;
        /// get parameter \p name
-       /// WARNING: You cannot access LATEX_KV_* arguments in this way.
-       /// LyX will assert if you attempt to do so.
+       /// LyX will assert if name is not a valid parameter.
        docstring const & operator[](std::string const & name) const;
        /// set parameter \p name
-       /// WARNING: You cannot access LATEX_KV_* arguments in this way.
-       /// LyX will assert if you attempt to do so.
+       /// LyX will assert if name is not a valid parameter.
        docstring & operator[](std::string const & name);
        ///
        bool preview() const { return preview_; }
@@ -154,27 +138,19 @@ public:
        void preview(bool p) { preview_ = p; }
        /// Clear the values of all parameters
        void clear();
-
-private:
-       ///
-       /// Get information for inset type \p code.
-       /// Returns 0 if the inset is not known.
-       static ParamInfo const & findInfo(InsetCode code);
-       /// Get information for \p code and command \p cmdName.
-       /// Returns 0 if the combination is not known.
-       /// Don't call this without first making sure the command name is
-       /// acceptable to the inset.
-       static ParamInfo const & findInfo(InsetCode code,
-                                           std::string const & cmdName);
        ///
        static bool isCompatibleCommand(InsetCode code, std::string const & s);
+       /// 
+       ParamInfo const & info() const { return info_; };
        ///
-       std::string getDefaultCmd(InsetCode);
-       ///
-       docstring makeKeyValArgument() const;
+       docstring prepareCommand(OutputParams const & runparams,
+               docstring const & command, ParamInfo::ParamHandling handling) const;
+private:
+       std::string getDefaultCmd(InsetCode code);
        /// checks whether we need to write an empty optional parameter
        /// \return true if a non-empty optional parameter follows ci
        bool writeEmptyOptional(ParamInfo::const_iterator ci) const;
+
        /// Description of all command properties
        ParamInfo info_;
        /// what kind of inset we're the parameters for