]> git.lyx.org Git - features.git/blobdiff - src/mathed/InsetMath.h
Assure correct spacing of colored items in mathed
[features.git] / src / mathed / InsetMath.h
index e791099b728e7b3118397b66a3bc033eb42546c9..067bf6e876a2d0b7e46ee7f596fc37a89e44341a 100644 (file)
@@ -39,6 +39,17 @@ enum HullType {
 HullType hullType(docstring const & name);
 docstring hullName(HullType type);
 
+
+enum Limits {
+       // what is obtained with \c \\nolimits
+       NO_LIMITS = -1,
+       // the default
+       AUTO_LIMITS = 0,
+       // what is obtained with \c \\limits
+       LIMITS = 1
+};
+
+
 /**
 
 Abstract base class for all math objects.  A math insets is for use of the
@@ -53,11 +64,15 @@ inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
 
 */
 
+class Cursor;
 class OutputParams;
+class MetricsInfo;
+
 class InsetMathArray;
 class InsetMathAMSArray;
 class InsetMathBrace;
 class InsetMathChar;
+class InsetMathClass;
 class InsetMathDelim;
 class InsetMathFracBase;
 class InsetMathFrac;
@@ -71,8 +86,8 @@ class InsetMathString;
 class InsetMathSpace;
 class InsetMathSpecialChar;
 class InsetMathSymbol;
+class InsetMathSubstack;
 class InsetMathUnknown;
-
 class InsetMathRef;
 
 class HtmlStream;
@@ -85,9 +100,9 @@ class MathStream;
 class WriteStream;
 
 class MathData;
-class MathMacroTemplate;
-class MathMacro;
-class Cursor;
+class InsetMathMacroTemplate;
+class InsetMathMacro;
+class MathRow;
 class TextPainter;
 class TextMetricsInfo;
 class ReplaceData;
@@ -99,7 +114,7 @@ typedef void const * uid_type;
 class InsetMath : public Inset {
 public:
        ///
-       InsetMath(Buffer * buf = 0) : Inset(buf) {}
+       explicit InsetMath(Buffer * buf = 0) : Inset(buf) {}
        /// identification as math inset
        InsetMath * asInsetMath() { return this; }
        /// identification as math inset
@@ -112,6 +127,11 @@ public:
        /// this is overridden by specific insets
        virtual mode_type currentMode() const { return MATH_MODE; }
 
+       // The possible marker types for math insets
+       enum marker_type { NO_MARKER, MARKER2, MARKER, BOX_MARKER };
+       /// this is overridden by insets with specific edit marker type
+       virtual marker_type marker(BufferView const *) const;
+
        /// the ascent of the inset above the baseline
        /// compute the size of the object for text based drawing
        virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
@@ -124,56 +144,76 @@ public:
        virtual MathData const & cell(idx_type) const;
 
        /// identifies certain types of insets
-       virtual InsetMathAMSArray       * asAMSArrayInset()       { return 0; }
-       virtual InsetMathAMSArray const * asAMSArrayInset() const { return 0; }
-       virtual InsetMathArray          * asArrayInset()          { return 0; }
-       virtual InsetMathArray const    * asArrayInset() const    { return 0; }
-       virtual InsetMathBrace          * asBraceInset()          { return 0; }
-       virtual InsetMathBrace const    * asBraceInset() const    { return 0; }
-       virtual InsetMathChar const     * asCharInset() const     { return 0; }
-       virtual InsetMathDelim          * asDelimInset()          { return 0; }
-       virtual InsetMathDelim const    * asDelimInset() const    { return 0; }
-       virtual InsetMathFracBase       * asFracBaseInset()       { return 0; }
-       virtual InsetMathFracBase const * asFracBaseInset() const { return 0; }
-       virtual InsetMathFrac           * asFracInset()           { return 0; }
-       virtual InsetMathFrac const     * asFracInset() const     { return 0; }
-       virtual InsetMathFont           * asFontInset()           { return 0; }
-       virtual InsetMathFont const     * asFontInset() const     { return 0; }
-       virtual InsetMathGrid           * asGridInset()           { return 0; }
-       virtual InsetMathGrid const     * asGridInset() const     { return 0; }
-       virtual InsetMathHull           * asHullInset()           { return 0; }
-       virtual InsetMathHull const     * asHullInset() const     { return 0; }
-       virtual MathMacro               * asMacro()               { return 0; }
-       virtual MathMacro const         * asMacro() const         { return 0; }
-       virtual MathMacroTemplate       * asMacroTemplate()       { return 0; }
-       virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
-       virtual InsetMathMatrix const   * asMatrixInset() const   { return 0; }
-       virtual InsetMathNest           * asNestInset()           { return 0; }
-       virtual InsetMathNest const     * asNestInset() const     { return 0; }
-       virtual InsetMathScript         * asScriptInset()         { return 0; }
-       virtual InsetMathScript const   * asScriptInset() const   { return 0; }
-       virtual InsetMathSpace          * asSpaceInset()          { return 0; }
-       virtual InsetMathSpace const    * asSpaceInset() const    { return 0; }
-       virtual InsetMathString         * asStringInset()         { return 0; }
-       virtual InsetMathString const   * asStringInset() const   { return 0; }
-       virtual InsetMathSymbol const   * asSymbolInset() const   { return 0; }
-       virtual InsetMathUnknown        * asUnknownInset()        { return 0; }
-       virtual InsetMathUnknown const  * asUnknownInset() const  { return 0; }
-       virtual InsetMathRef            * asRefInset()            { return 0; }
-       virtual InsetMathSpecialChar const * asSpecialCharInset() const { return 0; }
+       virtual InsetMathAMSArray       * asAMSArrayInset()       { return nullptr; }
+       virtual InsetMathAMSArray const * asAMSArrayInset() const { return nullptr; }
+       virtual InsetMathArray          * asArrayInset()          { return nullptr; }
+       virtual InsetMathArray const    * asArrayInset() const    { return nullptr; }
+       virtual InsetMathBrace          * asBraceInset()          { return nullptr; }
+       virtual InsetMathBrace const    * asBraceInset() const    { return nullptr; }
+       virtual InsetMathChar const     * asCharInset() const     { return nullptr; }
+       virtual InsetMathClass const    * asClassInset() const    { return nullptr; }
+       virtual InsetMathDelim          * asDelimInset()          { return nullptr; }
+       virtual InsetMathDelim const    * asDelimInset() const    { return nullptr; }
+       virtual InsetMathFracBase       * asFracBaseInset()       { return nullptr; }
+       virtual InsetMathFracBase const * asFracBaseInset() const { return nullptr; }
+       virtual InsetMathFrac           * asFracInset()           { return nullptr; }
+       virtual InsetMathFrac const     * asFracInset() const     { return nullptr; }
+       virtual InsetMathFont           * asFontInset()           { return nullptr; }
+       virtual InsetMathFont const     * asFontInset() const     { return nullptr; }
+       virtual InsetMathGrid           * asGridInset()           { return nullptr; }
+       virtual InsetMathGrid const     * asGridInset() const     { return nullptr; }
+       virtual InsetMathHull           * asHullInset()           { return nullptr; }
+       virtual InsetMathHull const     * asHullInset() const     { return nullptr; }
+       virtual InsetMathMacro               * asMacro()               { return nullptr; }
+       virtual InsetMathMacro const         * asMacro() const         { return nullptr; }
+       virtual InsetMathMacroTemplate       * asMacroTemplate()       { return nullptr; }
+       virtual InsetMathMacroTemplate const * asMacroTemplate() const { return nullptr; }
+       virtual InsetMathMatrix const   * asMatrixInset() const   { return nullptr; }
+       virtual InsetMathNest           * asNestInset()           { return nullptr; }
+       virtual InsetMathNest const     * asNestInset() const     { return nullptr; }
+       virtual InsetMathScript         * asScriptInset()         { return nullptr; }
+       virtual InsetMathScript const   * asScriptInset() const   { return nullptr; }
+       virtual InsetMathSpace          * asSpaceInset()          { return nullptr; }
+       virtual InsetMathSpace const    * asSpaceInset() const    { return nullptr; }
+       virtual InsetMathString         * asStringInset()         { return nullptr; }
+       virtual InsetMathString const   * asStringInset() const   { return nullptr; }
+       virtual InsetMathSubstack       * asSubstackInset()       { return nullptr; }
+       virtual InsetMathSubstack const * asSubstackInset() const { return nullptr; }
+       virtual InsetMathSymbol const   * asSymbolInset() const   { return nullptr; }
+       virtual InsetMathUnknown        * asUnknownInset()        { return nullptr; }
+       virtual InsetMathUnknown const  * asUnknownInset() const  { return nullptr; }
+       virtual InsetMathRef            * asRefInset()            { return nullptr; }
+       virtual InsetMathSpecialChar const * asSpecialCharInset() const { return nullptr; }
 
        /// The class of the math object (used primarily for spacing)
-       virtual MathClass mathClass() const;
+       virtual MathClass mathClass() const { return MC_ORD; }
+       /// Add this inset to a math row. Return true if contents got added
+       virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const;
+       /// Hook that is run before metrics computation starts
+       virtual void beforeMetrics() const {}
+       /// Hook that is run after metrics computation
+       virtual void afterMetrics() const {}
+       /// Hook that is run before actual drawing
+       virtual void beforeDraw(PainterInfo const &) const {}
+       /// Hook that is run after drawing
+       virtual void afterDraw(PainterInfo const &) const {}
 
-       /// identifies things that can get scripts
-       virtual bool isScriptable() const { return false; }
        /// will this get written as a single block in {..}
        virtual bool extraBraces() const { return false; }
 
        /// return the content as char if the inset is able to do so
        virtual char_type getChar() const { return 0; }
-       /// identifies things that can get \limits or \nolimits
-       virtual bool takesLimits() const { return false; }
+
+       /// Whether the inset allows \(no)limits
+       bool allowsLimitsChange() const { return mathClass() == MC_OP; }
+       /// The default limits value
+       virtual Limits defaultLimits() const { return NO_LIMITS; }
+       /// whether the inset has limit-like sub/superscript
+       virtual Limits limits() const { return AUTO_LIMITS; }
+       /// sets types of sub/superscripts
+       virtual void limits(Limits) {}
+       /// write limits status for LaTeX and LyX code
+       void writeLimits(WriteStream & os) const;
 
        /// replace things by other things
        virtual void replace(ReplaceData &) {}
@@ -223,7 +263,7 @@ public:
        /// math stuff usually isn't allowed in text mode
        virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
 
-       /// superscript kerning
+       /// Italic correction as described in InsetMathScript.h
        virtual int kerning(BufferView const *) const { return 0; }
        ///
        bool isInToc() const { return true; }