]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph_pimpl.C
Remove unused font variable which caused a warning.
[lyx.git] / src / paragraph_pimpl.C
index 8e3a9eee818f6226ce2cb80f30ec153abee27c42..182d1165d8d0ef30ff42ea336bdcc7fceae94236 100644 (file)
@@ -39,12 +39,17 @@ Paragraph::Pimpl::Pimpl(Paragraph * owner)
 }
 
 
-Paragraph::Pimpl::Pimpl(Paragraph::Pimpl const & p, Paragraph * owner)
-       : owner_(owner)
+Paragraph::Pimpl::Pimpl(Paragraph::Pimpl const & p, Paragraph * owner,
+                        bool same_ids)
+       : params(p.params), owner_(owner)
 {
        inset_owner = p.inset_owner;
        text = p.text;
        fontlist = p.fontlist;
+       if (same_ids)
+               id_ = p.id_;
+       else
+               id_ = paragraph_id++;
 }
 
 
@@ -93,19 +98,19 @@ void Paragraph::Pimpl::insertChar(Paragraph::size_type pos,
 
        // Update the font table.
        FontTable search_font(pos, LyXFont());
-       for (FontList::iterator it = lower_bound(fontlist.begin(),
-                                                fontlist.end(),
-                                                search_font, matchFT());
+       for (FontList::iterator it = std::lower_bound(fontlist.begin(),
+                                                     fontlist.end(),
+                                                     search_font, matchFT());
             it != fontlist.end(); ++it)
-               (*it).pos((*it).pos() + 1);
+               it->pos(it->pos() + 1);
    
        // Update the inset table.
        InsetTable search_inset(pos, 0);
-       for (InsetList::iterator it = lower_bound(owner_->insetlist.begin(),
-                                                 owner_->insetlist.end(),
-                                                 search_inset, matchIT());
+       for (InsetList::iterator it = std::lower_bound(owner_->insetlist.begin(),
+                                                      owner_->insetlist.end(),
+                                                      search_inset, matchIT());
             it != owner_->insetlist.end(); ++it)
-               ++(*it).pos;
+               ++it->pos;
 
        owner_->setFont(pos, font);
 }
@@ -122,12 +127,12 @@ void Paragraph::Pimpl::insertInset(Paragraph::size_type pos,
        
        // Add a new entry in the inset table.
        InsetTable search_inset(pos, 0);
-       InsetList::iterator it = lower_bound(owner_->insetlist.begin(),
-                                            owner_->insetlist.end(),
-                                            search_inset, matchIT());
-       if (it != owner_->insetlist.end() && (*it).pos == pos) {
+       InsetList::iterator it = std::lower_bound(owner_->insetlist.begin(),
+                                                 owner_->insetlist.end(),
+                                                 search_inset, matchIT());
+       if (it != owner_->insetlist.end() && it->pos == pos) {
                lyxerr << "ERROR (Paragraph::InsertInset): "
-                       "there is an inset in position: " << pos << endl;
+                       "there is an inset in position: " << pos << std::endl;
        } else {
                owner_->insetlist.insert(it, InsetTable(pos, inset));
        }
@@ -145,11 +150,11 @@ void Paragraph::Pimpl::erase(Paragraph::size_type pos)
                // find the entry
                InsetTable search_inset(pos, 0);
                InsetList::iterator it =
-                       lower_bound(owner_->insetlist.begin(),
-                                   owner_->insetlist.end(),
-                                   search_inset, matchIT());
-               if (it != owner_->insetlist.end() && (*it).pos == pos) {
-                       delete (*it).inset;
+                       std::lower_bound(owner_->insetlist.begin(),
+                                        owner_->insetlist.end(),
+                                        search_inset, matchIT());
+               if (it != owner_->insetlist.end() && it->pos == pos) {
+                       delete it->inset;
                        owner_->insetlist.erase(it);
                }
        }
@@ -160,13 +165,13 @@ void Paragraph::Pimpl::erase(Paragraph::size_type pos)
        FontTable search_font(pos, LyXFont());
        
        FontList::iterator it =
-               lower_bound(fontlist.begin(),
+               std::lower_bound(fontlist.begin(),
                            fontlist.end(),
                            search_font, matchFT());
-       if (it != fontlist.end() && (*it).pos() == pos &&
+       if (it != fontlist.end() && it->pos() == pos &&
            (pos == 0 || 
             (it != fontlist.begin() 
-             && (*(it - 1)).pos() == pos - 1))) {
+             && boost::prior(it)->pos() == pos - 1))) {
                // If it is a multi-character font
                // entry, we just make it smaller
                // (see update below), otherwise we
@@ -184,42 +189,45 @@ void Paragraph::Pimpl::erase(Paragraph::size_type pos)
        // Update all other entries.
        FontList::iterator fend = fontlist.end();
        for (; it != fend; ++it)
-               (*it).pos((*it).pos() - 1);
+               it->pos(it->pos() - 1);
        
        // Update the inset table.
        InsetTable search_inset(pos, 0);
        InsetList::iterator lend = owner_->insetlist.end();
        for (InsetList::iterator it =
-                    upper_bound(owner_->insetlist.begin(),
-                                lend,
-                                search_inset, matchIT());
+                    std::upper_bound(owner_->insetlist.begin(),
+                                     lend,
+                                     search_inset, matchIT());
             it != lend; ++it)
-               --(*it).pos;
+               --it->pos;
 }
 
 
-void Paragraph::Pimpl::simpleTeXBlanks(ostream & os, TexRow & texrow,
-                                  Paragraph::size_type const i,
-                                  int & column, LyXFont const & font,
-                                  LyXLayout const & style)
+void Paragraph::Pimpl::simpleTeXBlanks(std::ostream & os, TexRow & texrow,
+                                      Paragraph::size_type const i,
+                                      int & column, LyXFont const & font,
+                                      LyXLayout const & style)
 {
+       if (style.pass_thru) return;
        if (column > tex_code_break_column
            && i 
-           && owner_->getChar(i - 1) != ' '
-           && (i < owner_->size() - 1)
+           && getChar(i - 1) != ' '
+           && (i < size() - 1)
+#ifndef NO_LATEX
            // In LaTeX mode, we don't want to
            // break lines since some commands
            // do not like this
            && ! (font.latex() == LyXFont::ON)
+#endif
            // same in FreeSpacing mode
            && !style.free_spacing
            // In typewriter mode, we want to avoid 
            // ! . ? : at the end of a line
            && !(font.family() == LyXFont::TYPEWRITER_FAMILY
-                && (owner_->getChar(i-1) == '.'
-                    || owner_->getChar(i-1) == '?' 
-                    || owner_->getChar(i-1) == ':'
-                    || owner_->getChar(i-1) == '!'))) {
+                && (getChar(i - 1) == '.'
+                    || getChar(i - 1) == '?' 
+                    || getChar(i - 1) == ':'
+                    || getChar(i - 1) == '!'))) {
                if (tex_code_break_column == 0) {
                        // in batchmode we need LaTeX to still
                        // see it as a space not as an extra '\n'
@@ -230,19 +238,25 @@ void Paragraph::Pimpl::simpleTeXBlanks(ostream & os, TexRow & texrow,
                texrow.newline();
                texrow.start(owner_, i + 1);
                column = 0;
-       } else if (font.latex() == LyXFont::OFF) {
+       } else
+#ifndef NO_LATEX
+               if (font.latex() == LyXFont::OFF) {
+#endif
                if (style.free_spacing) {
                        os << '~';
                } else {
                        os << ' ';
                }
+#ifndef NO_LATEX
        }
+#endif
 }
 
 
 void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf,
                                             BufferParams const & bparams,
-                                            ostream & os, TexRow & texrow,
+                                            std::ostream & os,
+                                            TexRow & texrow,
                                             bool moving_arg,
                                             LyXFont & font,
                                             LyXFont & running_font,
@@ -253,6 +267,10 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf,
                                             int & column,
                                             Paragraph::value_type const c)
 {
+       if (style.pass_thru) {
+               if (c != '\0') os << c;
+               return;
+       }
        // Two major modes:  LaTeX or plain
        // Handle here those cases common to both modes
        // and then split to handle the two modes separately.
@@ -263,15 +281,15 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf,
                        bool close = false;
                        int const len = os.tellp();
                        //ostream::pos_type const len = os.tellp();
-                       if ((inset->LyxCode() == Inset::GRAPHICS_CODE
-                            || inset->LyxCode() == Inset::MATH_CODE
-                            || inset->LyxCode() == Inset::URL_CODE)
+                       if ((inset->lyxCode() == Inset::GRAPHICS_CODE
+                            || inset->lyxCode() == Inset::MATH_CODE
+                            || inset->lyxCode() == Inset::URL_CODE)
                            && running_font.isRightToLeft()) {
                                os << "\\L{";
                                close = true;
                        }
 
-                       int tmp = inset->Latex(buf, os, moving_arg,
+                       int tmp = inset->latex(buf, os, moving_arg,
                                               style.free_spacing);
 
                        if (close)
@@ -307,6 +325,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf,
 
        default:
                // And now for the special cases within each mode
+#ifndef NO_LATEX
                // Are we in LaTeX mode?
                if (font.latex() == LyXFont::ON) {
                        // at present we only have one option
@@ -325,6 +344,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf,
                                break;
                        }
                } else {
+#endif
                        // Plain mode (i.e. not LaTeX)
                        switch (c) {
                        case '\\': 
@@ -354,8 +374,8 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf,
                                        os << c;
                                        //... but we should avoid ligatures
                                        if ((c == '>' || c == '<')
-                                           && i <= owner_->size() - 2
-                                           && owner_->getChar(i + 1) == c) {
+                                           && i <= size() - 2
+                                           && getChar(i + 1) == c) {
                                                //os << "\\textcompwordmark{}";
                                                // Jean-Marc, have a look at
                                                // this. I think this works
@@ -390,8 +410,8 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf,
                                break;
 
                        case '-': // "--" in Typewriter mode -> "-{}-"
-                               if (i <= owner_->size() - 2
-                                   && owner_->getChar(i + 1) == '-'
+                               if (i <= size() - 2
+                                   && getChar(i + 1) == '-'
                                    && font.family() == LyXFont::TYPEWRITER_FAMILY) {
                                        os << "-{}";
                                        column += 2;
@@ -449,46 +469,46 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf,
                                /* idea for labels --- begin*/
                                // Check for "LyX"
                                if (c ==  'L'
-                                   && i <= owner_->size() - 3
+                                   && i <= size() - 3
                                    && font.family() != LyXFont::TYPEWRITER_FAMILY
-                                   && owner_->getChar(i + 1) == 'y'
-                                   && owner_->getChar(i + 2) == 'X') {
+                                   && getChar(i + 1) == 'y'
+                                   && getChar(i + 2) == 'X') {
                                        os << "\\LyX{}";
                                        i += 2;
                                        column += 5;
                                }
                                // Check for "TeX"
                                else if (c == 'T'
-                                        && i <= owner_->size() - 3
+                                        && i <= size() - 3
                                         && font.family() != LyXFont::TYPEWRITER_FAMILY
-                                        && owner_->getChar(i + 1) == 'e'
-                                        && owner_->getChar(i + 2) == 'X') {
+                                        && getChar(i + 1) == 'e'
+                                        && getChar(i + 2) == 'X') {
                                        os << "\\TeX{}";
                                        i += 2;
                                        column += 5;
                                }
                                // Check for "LaTeX2e"
                                else if (c == 'L'
-                                        && i <= owner_->size() - 7
+                                        && i <= size() - 7
                                         && font.family() != LyXFont::TYPEWRITER_FAMILY
-                                        && owner_->getChar(i + 1) == 'a'
-                                        && owner_->getChar(i + 2) == 'T'
-                                        && owner_->getChar(i + 3) == 'e'
-                                        && owner_->getChar(i + 4) == 'X'
-                                        && owner_->getChar(i + 5) == '2'
-                                        && owner_->getChar(i + 6) == 'e') {
+                                        && getChar(i + 1) == 'a'
+                                        && getChar(i + 2) == 'T'
+                                        && getChar(i + 3) == 'e'
+                                        && getChar(i + 4) == 'X'
+                                        && getChar(i + 5) == '2'
+                                        && getChar(i + 6) == 'e') {
                                        os << "\\LaTeXe{}";
                                        i += 6;
                                        column += 8;
                                }
                                // Check for "LaTeX"
                                else if (c == 'L'
-                                        && i <= owner_->size() - 5
+                                        && i <= size() - 5
                                         && font.family() != LyXFont::TYPEWRITER_FAMILY
-                                        && owner_->getChar(i + 1) == 'a'
-                                        && owner_->getChar(i + 2) == 'T'
-                                        && owner_->getChar(i + 3) == 'e'
-                                        && owner_->getChar(i + 4) == 'X') {
+                                        && getChar(i + 1) == 'a'
+                                        && getChar(i + 2) == 'T'
+                                        && getChar(i + 3) == 'e'
+                                        && getChar(i + 4) == 'X') {
                                        os << "\\LaTeX{}";
                                        i += 4;
                                        column += 7;
@@ -498,7 +518,9 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf,
                                }
                                break;
                        }
+#ifndef NO_LATEX
                }
+#endif
        }
 }
 
@@ -506,9 +528,9 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const * buf,
 
 Paragraph * Paragraph::Pimpl::TeXDeeper(Buffer const * buf,
                                        BufferParams const & bparams,
-                                       ostream & os, TexRow & texrow)
+                                       std::ostream & os, TexRow & texrow)
 {
-       lyxerr[Debug::LATEX] << "TeXDeeper...     " << this << endl;
+       lyxerr[Debug::LATEX] << "TeXDeeper...     " << this << std::endl;
        Paragraph * par = owner_;
 
        while (par && par->params().depth() == owner_->params().depth()) {
@@ -521,9 +543,21 @@ Paragraph * Paragraph::Pimpl::TeXDeeper(Buffer const * buf,
                                             os, texrow, false);
                }
        }
-       lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
+       lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << std::endl;
 
        return par;
 }
 
 
+Paragraph * Paragraph::Pimpl::getParFromID(int id) const
+{
+       InsetList::const_iterator cit = owner_->insetlist.begin();
+       InsetList::const_iterator lend = owner_->insetlist.end();
+       Paragraph * result;
+       for (; cit != lend; ++cit) {
+               if ((result = cit->inset->getParFromID(id)))
+                       return result;
+       }
+       return 0;
+}
+