]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetSpecialChar.cpp
This should be the last of the commits refactoring the InsetLayout code.
[lyx.git] / src / insets / InsetSpecialChar.cpp
index 3d0129e88b8658cb8cee02090c4af5437f6e126f..bc62e4e7651575325a969a37c71cd57326c75853 100644 (file)
 
 #include "InsetSpecialChar.h"
 
-#include "debug.h"
+#include "Dimension.h"
 #include "LaTeXFeatures.h"
-#include "Color.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
 
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
+#include "support/debug.h"
+#include "support/docstream.h"
 
-namespace lyx {
+using namespace std;
 
-using std::string;
-using std::ostream;
+namespace lyx {
 
 
 InsetSpecialChar::InsetSpecialChar(Kind k)
@@ -41,7 +41,7 @@ InsetSpecialChar::Kind InsetSpecialChar::kind() const
 }
 
 
-bool InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        frontend::FontMetrics const & fm =
                theFontMetrics(mi.base.font);
@@ -50,48 +50,63 @@ bool InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
 
        string s;
        switch (kind_) {
-               case LIGATURE_BREAK:      s = "|";     break;
-               case END_OF_SENTENCE:     s = ".";     break;
-               case LDOTS:               s = ". . ."; break;
-               case MENU_SEPARATOR:      s = " x ";   break;
-               case HYPHENATION:      s = "-";   break;
+               case LIGATURE_BREAK:
+                       s = "|";
+                       break;
+               case END_OF_SENTENCE:
+                       s = ".";
+                       break;
+               case LDOTS:
+                       s = ". . .";
+                       break;
+               case MENU_SEPARATOR:
+                       s = " x ";
+                       break;
+               case HYPHENATION:
+                       s = "-";
+                       break;
+               case SLASH:
+                       s = "/";
+                       break;
+               case NOBREAKDASH:
+                       s = "-";
+                       break;
        }
        docstring ds(s.begin(), s.end());
        dim.wid = fm.width(ds);
        if (kind_ == HYPHENATION && dim.wid > 5)
                dim.wid -= 2; // to make it look shorter
-       bool const changed = dim_ != dim;
-       dim_ = dim;
-       return changed;
+       
+       setDimCache(mi, dim);
 }
 
 
 void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
 {
-       Font font = pi.base.font;
+       FontInfo font = pi.base.font;
 
        switch (kind_) {
        case HYPHENATION:
        {
-               font.setColor(Color::special);
+               font.setColor(Color_special);
                pi.pain.text(x, y, char_type('-'), font);
                break;
        }
        case LIGATURE_BREAK:
        {
-               font.setColor(Color::special);
+               font.setColor(Color_special);
                pi.pain.text(x, y, char_type('|'), font);
                break;
        }
        case END_OF_SENTENCE:
        {
-               font.setColor(Color::special);
+               font.setColor(Color_special);
                pi.pain.text(x, y, char_type('.'), font);
                break;
        }
        case LDOTS:
        {
-               font.setColor(Color::special);
+               font.setColor(Color_special);
                string ell = ". . . ";
                docstring dell(ell.begin(), ell.end());
                pi.pain.text(x, y, dell, font);
@@ -113,7 +128,19 @@ void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const
                xp[2] = ox + w; yp[2] = y - h/2;
                xp[3] = ox;     yp[3] = y;
 
-               pi.pain.lines(xp, yp, 4, Color::special);
+               pi.pain.lines(xp, yp, 4, Color_special);
+               break;
+       }
+       case SLASH:
+       {
+               font.setColor(Color_special);
+               pi.pain.text(x, y, char_type('/'), font);
+               break;
+       }
+       case NOBREAKDASH:
+       {
+               font.setColor(Color_latex);
+               pi.pain.text(x, y, char_type('-'), font);
                break;
        }
        }
@@ -140,6 +167,12 @@ void InsetSpecialChar::write(Buffer const &, ostream & os) const
        case MENU_SEPARATOR:
                command = "\\menuseparator";
                break;
+       case SLASH:
+               command = "\\slash{}";
+               break;
+       case NOBREAKDASH:
+               command = "\\nobreakdash-";
+               break;
        }
        os << "\\SpecialChar " << command << "\n";
 }
@@ -161,6 +194,10 @@ void InsetSpecialChar::read(Buffer const &, Lexer & lex)
                kind_ = LDOTS;
        else if (command == "\\menuseparator")
                kind_ = MENU_SEPARATOR;
+       else if (command == "\\slash{}")
+               kind_ = SLASH;
+       else if (command == "\\nobreakdash-")
+               kind_ = NOBREAKDASH;
        else
                lex.printError("InsetSpecialChar: Unknown kind: `$$Token'");
 }
@@ -185,6 +222,12 @@ int InsetSpecialChar::latex(Buffer const &, odocstream & os,
        case MENU_SEPARATOR:
                os << "\\lyxarrow{}";
                break;
+       case SLASH:
+               os << "\\slash{}";
+               break;
+       case NOBREAKDASH:
+               os << "\\nobreakdash-";
+               break;
        }
        return 0;
 }
@@ -206,6 +249,12 @@ int InsetSpecialChar::plaintext(Buffer const &, odocstream & os,
        case MENU_SEPARATOR:
                os << "->";
                return 2;
+       case SLASH:
+               os << '/';
+               return 1;
+       case NOBREAKDASH:
+               os << '-';
+               return 1;
        }
        return 0;
 }
@@ -227,15 +276,20 @@ int InsetSpecialChar::docbook(Buffer const &, odocstream & os,
        case MENU_SEPARATOR:
                os << "&lyxarrow;";
                break;
+       case SLASH:
+               os << '/';
+               break;
+       case NOBREAKDASH:
+               os << '-';
+               break;
        }
        return 0;
 }
 
 
-int InsetSpecialChar::textString(Buffer const & buf, odocstream & os,
-                      OutputParams const & op) const
+void InsetSpecialChar::textString(Buffer const & buf, odocstream & os) const
 {
-       return plaintext(buf, os, op);
+       plaintext(buf, os, OutputParams(0));
 }
 
 
@@ -249,6 +303,8 @@ void InsetSpecialChar::validate(LaTeXFeatures & features) const
 {
        if (kind_ == MENU_SEPARATOR)
                features.require("lyxarrow");
+       if (kind_ == NOBREAKDASH)
+               features.require("amsmath");
 }