]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetQuotes.cpp
This should be the last of the commits refactoring the InsetLayout code.
[lyx.git] / src / insets / InsetQuotes.cpp
index 7c66ba81987e1c6ea780d6c408650a4bdb4cbcbc..98ed950521898f1e8b1f5df9f1de8b755759574c 100644 (file)
 
 #include "Buffer.h"
 #include "BufferParams.h"
-#include "debug.h"
+#include "BufferView.h"
+#include "Dimension.h"
 #include "Language.h"
 #include "LaTeXFeatures.h"
-#include "LyXLex.h"
+#include "Lexer.h"
 #include "LyXRC.h"
 #include "MetricsInfo.h"
 #include "OutputParams.h"
-#include "Paragraph.h"
-#include "paragraph_funcs.h"
 
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
+#include "support/debug.h"
+#include "support/docstring.h"
+#include "support/docstream.h"
 #include "support/lstrings.h"
 
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
-using support::prefixIs;
-
-using std::endl;
-using std::string;
-using std::auto_ptr;
-using std::ostream;
-
-
 namespace {
 
 /* codes used to read/write quotes to LyX files
@@ -61,23 +57,27 @@ char const * const quote_char = ",'`<>";
 // Index of chars used for the quote. Index is [side, language]
 int quote_index[2][6] = {
        { 2, 1, 0, 0, 3, 4 },    // "'',,<>"
-       { 1, 1, 2, 1, 4, 3 } };  // "`'`'><"
+       { 1, 1, 2, 1, 4, 3 }     // "`'`'><"
+};
 
 // Corresponding LaTeX code, for double and single quotes.
-char const * const latex_quote_t1[2][5] =
-{ { "\\quotesinglbase ",  "'", "`",
+char const * const latex_quote_t1[2][5] = {
+       { "\\quotesinglbase ",  "'", "`",
     "\\guilsinglleft{}", "\\guilsinglright{}" },
-  { ",,", "''", "``", "<<", ">>" } };
+  { ",,", "''", "``", "<<", ">>" }
+};
 
-char const * const latex_quote_ot1[2][5] =
-{ { "\\quotesinglbase ",  "'", "`",
+char const * const latex_quote_ot1[2][5] = {
+       { "\\quotesinglbase ",  "'", "`",
     "\\guilsinglleft{}", "\\guilsinglright{}" },
   { "\\quotedblbase ", "''", "``",
-    "\\guillemotleft{}", "\\guillemotright{}" } };
+    "\\guillemotleft{}", "\\guillemotright{}" }
+};
 
-char const * const latex_quote_babel[2][5] =
-{ { "\\glq ",  "'", "`", "\\flq{}", "\\frq{}" },
-  { "\\glqq ", "''", "``", "\\flqq{}", "\\frqq{}" } };
+char const * const latex_quote_babel[2][5] = {
+       { "\\glq ",  "'", "`", "\\flq{}", "\\frq{}" },
+  { "\\glqq ", "''", "``", "\\flqq{}", "\\frqq{}" }
+};
 
 } // namespace anon
 
@@ -85,14 +85,12 @@ char const * const latex_quote_babel[2][5] =
 InsetQuotes::InsetQuotes(string const & str)
 {
        parseString(str);
-       setInsetName(from_utf8("InsetQuotes"));
 }
 
 
 InsetQuotes::InsetQuotes(quote_language l, quote_side s, quote_times t)
        : language_(l), side_(s), times_(t)
 {
-       setInsetName(from_utf8("InsetQuotes"));
 }
 
 
@@ -100,7 +98,6 @@ InsetQuotes::InsetQuotes(char_type c, BufferParams const & params)
        : language_(params.quotes_language), times_(params.quotes_times)
 {
        getPosition(c);
-       setInsetName(from_utf8("InsetQuotes"));
 }
 
 
@@ -108,7 +105,12 @@ InsetQuotes::InsetQuotes(char_type c, quote_language l, quote_times t)
        : language_(l), times_(t)
 {
        getPosition(c);
-       setInsetName(from_utf8("InsetQuotes"));
+}
+
+
+docstring InsetQuotes::name() const
+{
+       return from_ascii("Quotes");
 }
 
 
@@ -116,7 +118,9 @@ void InsetQuotes::getPosition(char_type c)
 {
        // Decide whether left or right
        switch (c) {
-       case ' ': case '(': case '[':
+       case ' ':
+       case '(':
+       case '[':
                side_ = LeftQ;   // left quote
                break;
        default:
@@ -127,7 +131,7 @@ void InsetQuotes::getPosition(char_type c)
 
 void InsetQuotes::parseString(string const & s)
 {
-       string str(s);
+       string str = s;
        if (str.length() != 3) {
                lyxerr << "ERROR (InsetQuotes::InsetQuotes):"
                        " bad string length." << endl;
@@ -207,30 +211,32 @@ docstring const InsetQuotes::dispString(Language const * loclang) const
                retdisp = docstring(1, 0x2018);
 #endif
        else
-               retdisp = lyx::from_ascii(disp);
-       
+               retdisp = from_ascii(disp);
+
        // in french, spaces are added inside double quotes
        if (times_ == DoubleQ && prefixIs(loclang->code(), "fr")) {
                if (side_ == LeftQ)
                        retdisp += ' ';
                else
-                       retdisp.insert(docstring::size_type(0), 1, ' ');
+                       retdisp.insert(size_t(0), 1, ' ');
        }
 
        return retdisp;
 }
 
 
-bool InsetQuotes::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetQuotes::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       LyXFont & font = mi.base.font;
+       FontInfo & font = mi.base.font;
        frontend::FontMetrics const & fm =
                theFontMetrics(font);
        dim.asc = fm.maxAscent();
        dim.des = fm.maxDescent();
        dim.wid = 0;
 
-       docstring const text = dispString(font.language());
+       // FIXME: should we add a language or a font parameter member?
+       docstring const text = dispString(
+               mi.base.bv->buffer().params().language);
        for (string::size_type i = 0; i < text.length(); ++i) {
                if (text[i] == ' ')
                        dim.wid += fm.width('i');
@@ -239,28 +245,14 @@ bool InsetQuotes::metrics(MetricsInfo & mi, Dimension & dim) const
                else
                        dim.wid += fm.width(',');
        }
-       bool const changed = dim_ != dim;
-       dim_ = dim;
-       return changed;
-}
-
-
-#if 0
-LyXFont const InsetQuotes::convertFont(LyXFont const & f) const
-{
-#if 1
-       return f;
-#else
-       LyXFont font(f);
-       return font;
-#endif
 }
-#endif
 
 
 void InsetQuotes::draw(PainterInfo & pi, int x, int y) const
 {
-       docstring const text = dispString(pi.base.font.language());
+       // FIXME: should we add a language or a font parameter member?
+       docstring const text = dispString(
+               pi.base.bv->buffer().params().language);
 
        if (text.length() == 2 && text[0] == text[1]) {
                pi.pain.text(x, y, text[0], pi.base.font);
@@ -270,7 +262,6 @@ void InsetQuotes::draw(PainterInfo & pi, int x, int y) const
        } else {
                pi.pain.text(x, y, text, pi.base.font);
        }
-       setPosCache(pi, x, y);
 }
 
 
@@ -284,7 +275,7 @@ void InsetQuotes::write(Buffer const &, ostream & os) const
 }
 
 
-void InsetQuotes::read(Buffer const &, LyXLex & lex)
+void InsetQuotes::read(Buffer const &, Lexer & lex)
 {
        lex.next();
        parseString(lex.getString());
@@ -296,7 +287,7 @@ void InsetQuotes::read(Buffer const &, LyXLex & lex)
 
 
 int InsetQuotes::latex(Buffer const &, odocstream & os,
-                       OutputParams const & runparams) const
+                      OutputParams const & runparams) const
 {
        const int quoteind = quote_index[side_][language_];
        string qstr;
@@ -329,7 +320,7 @@ int InsetQuotes::latex(Buffer const &, odocstream & os,
 
 
 int InsetQuotes::plaintext(Buffer const & buf, odocstream & os,
-                           OutputParams const &) const
+                          OutputParams const &) const
 {
        docstring const str = dispString(buf.params().language);
        os << str;
@@ -338,7 +329,7 @@ int InsetQuotes::plaintext(Buffer const & buf, odocstream & os,
 
 
 int InsetQuotes::docbook(Buffer const &, odocstream & os,
-                         OutputParams const &) const
+                        OutputParams const &) const
 {
        if (times_ == DoubleQ) {
                if (side_ == LeftQ)
@@ -374,7 +365,7 @@ void InsetQuotes::validate(LaTeXFeatures & features) const
            && lyxrc.fontenc != "T1") {
                if (times_ == SingleQ)
                        switch (type) {
-                               case ',': features.require("quotesinglbase");  break;
+                       case ',': features.require("quotesinglbase"); break;
                        case '<': features.require("guilsinglleft");  break;
                        case '>': features.require("guilsinglright"); break;
                        default: break;
@@ -390,15 +381,9 @@ void InsetQuotes::validate(LaTeXFeatures & features) const
 }
 
 
-auto_ptr<InsetBase> InsetQuotes::doClone() const
-{
-       return auto_ptr<InsetBase>(new InsetQuotes(language_, side_, times_));
-}
-
-
-InsetBase::Code InsetQuotes::lyxCode() const
+Inset * InsetQuotes::clone() const
 {
-       return InsetBase::QUOTE_CODE;
+       return new InsetQuotes(language_, side_, times_);
 }