]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathStream.cpp
Fix external middle-mouse pasting with Qt5/X11.
[lyx.git] / src / mathed / MathStream.cpp
index e616cd0e836612438a65d2b34bbc749efe2d8217..ed23eb416040a88a6303bb721d965d33cb5b68f9 100644 (file)
@@ -107,7 +107,7 @@ WriteStream & operator<<(WriteStream & ws, docstring const & s)
        }
        ws.os() << s.substr(first);
        int lf = 0;
-       char_type lastchar;
+       char_type lastchar = 0;
        docstring::const_iterator dit = s.begin() + first;
        docstring::const_iterator end = s.end();
        for (; dit != end; ++dit) {
@@ -125,7 +125,7 @@ WriteStream::WriteStream(odocstream & os, bool fragile, bool latex, OutputType o
                        Encoding const * encoding)
        : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
          output_(output), pendingspace_(false), pendingbrace_(false),
-         canbreakline_(true), textmode_(false), locked_(0), ascii_(0),
+         textmode_(false), locked_(0), ascii_(0), canbreakline_(true),
          line_(0), encoding_(encoding)
 {}
 
@@ -133,7 +133,7 @@ WriteStream::WriteStream(odocstream & os, bool fragile, bool latex, OutputType o
 WriteStream::WriteStream(odocstream & os)
        : os_(os), fragile_(false), firstitem_(false), latex_(false),
          output_(wsDefault), pendingspace_(false), pendingbrace_(false),
-         canbreakline_(true), textmode_(false), locked_(0), ascii_(0),
+         textmode_(false), locked_(0), ascii_(0), canbreakline_(true),
          line_(0), encoding_(0)
 {}
 
@@ -222,10 +222,9 @@ WriteStream & operator<<(WriteStream & ws, char c)
                ws.pendingSpace(false);
        }
        ws.os() << c;
-       if (c == '\n') {
+       if (c == '\n')
                ws.addlines(1);
-               ws.canBreakLine(false);
-       }
+       ws.canBreakLine(c != '\n');
        return ws;
 }
 
@@ -443,55 +442,16 @@ HtmlStream & operator<<(HtmlStream & ms, docstring const & s)
 
 
 SetMode::SetMode(MathStream & os, bool text)
-       : os_(os), opened_(false)
-{
-       init(text, "");
-}
-
-
-SetMode::SetMode(MathStream & os, bool text, string const & attrs)
-       : os_(os), opened_(false)
-{
-       init(text, attrs);
-}
-
-
-void SetMode::init(bool text, string const & attrs)
+       : os_(os)
 {
        was_text_ = os_.inText();
-       if (was_text_)
-               os_ << "</mtext>";
-       if (text) {
-               os_.setTextMode();
-               os_ << "<mtext";
-               if (!attrs.empty())
-                       os_ << " " << from_utf8(attrs);
-               os_ << ">";
-               opened_ = true;
-       } else {
-               if (!attrs.empty()) {
-                       os_ << "<mstyle " << from_utf8(attrs) << ">";
-                       opened_ = true;
-               }
-               os_.setMathMode();
-       }
+       os_.setTextMode(text);
 }
 
 
 SetMode::~SetMode()
 {
-       if (opened_) {
-               if (os_.inText())
-                       os_ << "</mtext>";
-               else
-                       os_ << "</mstyle>";
-       }
-       if (was_text_) {
-               os_.setTextMode();
-               os_ << "<mtext>";
-       } else {
-               os_.setMathMode();
-       }
+       os_.setTextMode(was_text_);
 }
 
 
@@ -499,42 +459,16 @@ SetMode::~SetMode()
 
 
 SetHTMLMode::SetHTMLMode(HtmlStream & os, bool text)
-       : os_(os), opened_(false)
-{
-       init(text, "");
-}
-
-
-SetHTMLMode::SetHTMLMode(HtmlStream & os, bool text, string attrs)
-       : os_(os), opened_(true)
-{
-       init(text, attrs);
-}
-
-
-void SetHTMLMode::init(bool text, string const & attrs)
+       : os_(os)
 {
        was_text_ = os_.inText();
-       if (text) {
-               os_.setTextMode();
-               if (attrs.empty())
-                       os_ << MTag("span");
-               else
-                       os_ << MTag("span", attrs);
-               opened_ = true;
-       } else
-               os_.setMathMode();
+       os_.setTextMode(text);
 }
 
 
 SetHTMLMode::~SetHTMLMode()
 {
-       if (opened_)
-               os_ << ETag("span");
-       if (was_text_)
-               os_.setTextMode();
-       else
-               os_.setMathMode();
+       os_.setTextMode(was_text_);
 }