]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
Remove unused font variable which caused a warning.
[lyx.git] / src / paragraph.C
index c1ca96b893e9efe524cf4b67b240d6b719068d1f..d272c778cbf3645106a7c8b83ef5121e05e2c0ed 100644 (file)
@@ -107,35 +107,36 @@ Paragraph::Paragraph(Paragraph * par)
 }
 
 
-Paragraph::Paragraph(Paragraph const & lp)
-       : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
+Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
+       : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
 {
-       for (int i = 0; i < 10; ++i) setCounter(i , 0);
+       for (int i = 0; i < 10; ++i)
+               setCounter(i , 0);
        enumdepth = 0;
        itemdepth = 0;
        next_ = 0;
        previous_ = 0;
-       clear();
-
-       makeSameLayout(&lp);
 
        // this is because of the dummy layout of the paragraphs that
        // follow footnotes
        layout = lp.layout;
 
         // ale970302
-       if (lp.bibkey)
+       if (lp.bibkey) {
                bibkey = static_cast<InsetBibKey *>
-                       (lp.bibkey->Clone(*current_view->buffer()));
-       else
+                       (lp.bibkey->clone(*current_view->buffer()));
+       } else {
                bibkey = 0;
+       }
        
        // copy everything behind the break-position to the new paragraph
 
        insetlist = lp.insetlist;
        for (InsetList::iterator it = insetlist.begin();
             it != insetlist.end(); ++it)
-               it->inset = it->inset->Clone(*current_view->buffer());
+       {
+               it->inset = it->inset->clone(*current_view->buffer(), same_ids);
+       }
 }
 
 
@@ -149,7 +150,7 @@ Paragraph::~Paragraph()
 
        for (InsetList::iterator it = insetlist.begin();
             it != insetlist.end(); ++it) {
-               delete (*it).inset;
+               delete it->inset;
        }
 
         // ale970302
@@ -163,8 +164,8 @@ Paragraph::~Paragraph()
 
 
 void Paragraph::writeFile(Buffer const * buf, ostream & os,
-                            BufferParams const & bparams,
-                            depth_type dth) const
+                          BufferParams const & bparams,
+                          depth_type dth) const
 {
        // The beginning or end of a deeper (i.e. nested) area?
        if (dth != params().depth()) {
@@ -236,7 +237,7 @@ void Paragraph::writeFile(Buffer const * buf, ostream & os,
        
        // bibitem  ale970302
        if (bibkey)
-               bibkey->Write(buf, os);
+               bibkey->write(buf, os);
        
        LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
        
@@ -250,7 +251,7 @@ void Paragraph::writeFile(Buffer const * buf, ostream & os,
                // Write font changes
                LyXFont font2 = getFontSettings(bparams, i);
                if (font2 != font1) {
-                       font2.lyxWriteChanges(font1, os);
+                       font2.lyxWriteChanges(font1, bparams.language, os);
                        column = 0;
                        font1 = font2;
                }
@@ -261,14 +262,14 @@ void Paragraph::writeFile(Buffer const * buf, ostream & os,
                {
                        Inset const * inset = getInset(i);
                        if (inset)
-                               if (inset->DirectWrite()) {
+                               if (inset->directWrite()) {
                                        // international char, let it write
                                        // code directly so it's shorter in
                                        // the file
-                                       inset->Write(buf, os);
+                                       inset->write(buf, os);
                                } else {
                                        os << "\n\\begin_inset ";
-                                       inset->Write(buf, os);
+                                       inset->write(buf, os);
                                        os << "\n\\end_inset \n\n";
                                        column = 0;
                                }
@@ -335,29 +336,36 @@ void Paragraph::validate(LaTeXFeatures & features) const
        
        for (Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
             cit != pimpl_->fontlist.end(); ++cit) {
-               if ((*cit).font().noun() == LyXFont::ON) {
+               if (cit->font().noun() == LyXFont::ON) {
                        lyxerr[Debug::LATEX] << "font.noun: "
-                                            << (*cit).font().noun()
+                                            << cit->font().noun()
                                             << endl;
                        features.noun = true;
                        lyxerr[Debug::LATEX] << "Noun enabled. Font: "
-                                            << (*cit).font().stateText(0)
+                                            << cit->font().stateText(0)
                                             << endl;
                }
-               switch ((*cit).font().color()) {
+               switch (cit->font().color()) {
                case LColor::none:
                case LColor::inherit:
                case LColor::ignore:
+                       // probably we should put here all interface colors used for
+                       // font displaying! For now I just add this ones I know of (Jug)
+               case LColor::latex:
+               case LColor::note:
                        break;
                default:
                        features.color = true;
                        lyxerr[Debug::LATEX] << "Color enabled. Font: "
-                                            << (*cit).font().stateText(0)
+                                            << cit->font().stateText(0)
                                             << endl;
                }
 
-               Language const * language = (*cit).font().language();
-               if (language->babel() != doc_language->babel()) {
+               Language const * language = cit->font().language();
+               if (language != ignore_language &&
+                       language != inherit_language &&
+                       language->babel() != doc_language->babel())
+               {
                        features.UsedLanguages.insert(language);
                        lyxerr[Debug::LATEX] << "Found language "
                                             << language->babel() << endl;
@@ -367,8 +375,8 @@ void Paragraph::validate(LaTeXFeatures & features) const
        // then the insets
        for (InsetList::const_iterator cit = insetlist.begin();
             cit != insetlist.end(); ++cit) {
-               if ((*cit).inset)
-                       (*cit).inset->Validate(features);
+               if (cit->inset)
+                       cit->inset->validate(features);
        }
 }
 
@@ -384,7 +392,7 @@ void Paragraph::copyIntoMinibuffer(Buffer const & buffer,
        minibuffer_inset = 0;
        if (minibuffer_char == Paragraph::META_INSET) {
                if (getInset(pos)) {
-                       minibuffer_inset = getInset(pos)->Clone(buffer);
+                       minibuffer_inset = getInset(pos)->clone(buffer);
                } else {
                        minibuffer_inset = 0;
                        minibuffer_char = ' ';
@@ -412,8 +420,8 @@ void Paragraph::cutIntoMinibuffer(BufferParams const & bparams,
                                lower_bound(insetlist.begin(),
                                            insetlist.end(),
                                            search_elem, Pimpl::matchIT());
-                       if (it != insetlist.end() && (*it).pos == pos)
-                               (*it).inset = 0;
+                       if (it != insetlist.end() && it->pos == pos)
+                               it->inset = 0;
                } else {
                        minibuffer_inset = 0;
                        minibuffer_char = ' ';
@@ -429,12 +437,15 @@ void Paragraph::cutIntoMinibuffer(BufferParams const & bparams,
 bool Paragraph::insertFromMinibuffer(Paragraph::size_type pos)
 {
        if ((minibuffer_char == Paragraph::META_INSET) &&
-           !insertInsetAllowed(minibuffer_inset))
+           !insetAllowed(minibuffer_inset->lyxCode()))
                return false;
        if (minibuffer_char == Paragraph::META_INSET)
                insertInset(pos, minibuffer_inset, minibuffer_font);
-       else
-               insertChar(pos, minibuffer_char, minibuffer_font);
+       else {
+               LyXFont f = minibuffer_font;
+               if (checkInsertChar(f))
+                       insertChar(pos, minibuffer_char, f);
+       }
        return true;
 }
 
@@ -457,6 +468,14 @@ void Paragraph::erase(Paragraph::size_type pos)
 }
 
 
+bool Paragraph::checkInsertChar(LyXFont & font)
+{
+       if (pimpl_->inset_owner)
+               return pimpl_->inset_owner->checkInsertChar(font);
+       return true;
+}
+
+
 void Paragraph::insertChar(Paragraph::size_type pos,
                              Paragraph::value_type c)
 {
@@ -488,12 +507,12 @@ void Paragraph::insertInset(Paragraph::size_type pos,
 }
 
 
-bool Paragraph::insertInsetAllowed(Inset * inset)
+bool Paragraph::insetAllowed(Inset::Code code)
 {
        //lyxerr << "Paragraph::InsertInsetAllowed" << endl;
        
        if (pimpl_->inset_owner)
-               return pimpl_->inset_owner->InsertInsetAllowed(inset);
+               return pimpl_->inset_owner->insetAllowed(code);
        return true;
 }
 
@@ -507,8 +526,8 @@ Inset * Paragraph::getInset(Paragraph::size_type pos)
        InsetList::iterator it = lower_bound(insetlist.begin(),
                                             insetlist.end(),
                                             search_inset, Pimpl::matchIT());
-       if (it != insetlist.end() && (*it).pos == pos)
-               return (*it).inset;
+       if (it != insetlist.end() && it->pos == pos)
+               return it->inset;
 
        lyxerr << "ERROR (Paragraph::GetInset): "
                "Inset does not exist: " << pos << endl;
@@ -532,8 +551,8 @@ Inset const * Paragraph::getInset(Paragraph::size_type pos) const
        InsetList::const_iterator cit = lower_bound(insetlist.begin(),
                                                    insetlist.end(),
                                                    search_inset, Pimpl::matchIT());
-       if (cit != insetlist.end() && (*cit).pos == pos)
-               return (*cit).inset;
+       if (cit != insetlist.end() && cit->pos == pos)
+               return cit->inset;
 
        lyxerr << "ERROR (Paragraph::GetInset): "
                "Inset does not exist: " << pos << endl;
@@ -549,7 +568,7 @@ Inset const * Paragraph::getInset(Paragraph::size_type pos) const
 
 // Gets uninstantiated font setting at position.
 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
-                                           Paragraph::size_type pos) const
+                                         Paragraph::size_type pos) const
 {
        lyx::Assert(pos <= size());
        
@@ -557,13 +576,17 @@ LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
        Pimpl::FontList::const_iterator cit = lower_bound(pimpl_->fontlist.begin(),
                                                   pimpl_->fontlist.end(),
                                                   search_font, Pimpl::matchFT());
-       if (cit != pimpl_->fontlist.end())
-               return (*cit).font();
-       
-       if (pos == size() && size())
-               return getFontSettings(bparams, pos - 1);
-       
-       return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
+       LyXFont retfont;
+       if (cit != pimpl_->fontlist.end()) {
+               retfont = cit->font();
+       } else if (pos == size() && size()) {
+               retfont = getFontSettings(bparams, pos - 1);
+       } else
+               retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
+       if (retfont.language() == inherit_language)
+               retfont.setLanguage(bparams.language);
+
+       return retfont;
 }
 
 
@@ -604,7 +627,7 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams,
                else
                        layoutfont = layout.font;
                tmpfont = getFontSettings(bparams, pos);
-               tmpfont.realize(layoutfont);
+               tmpfont.realize(layoutfont, bparams.language);
        } else {
                // process layoutfont for pos == -1 and labelfont for pos < -1
                if (pos == -1)
@@ -622,14 +645,14 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams,
                if (par) {
                        tmpfont.realize(textclasslist.
                                        Style(bparams.textclass,
-                                             par->getLayout()).font);
+                                             par->getLayout()).font, bparams.language);
                        par_depth = par->getDepth();
                }
        }
 
        tmpfont.realize(textclasslist
                        .TextClass(bparams.textclass)
-                       .defaultfont());
+                       .defaultfont(), bparams.language);
        return tmpfont;
 }
 
@@ -656,7 +679,7 @@ Paragraph::highestFontInRange(Paragraph::size_type startpos,
                                 pimpl_->fontlist.end(),
                                 start_search, Pimpl::matchFT());
             cit != end_it; ++cit) {
-               LyXFont::FONT_SIZE size = (*cit).font().size();
+               LyXFont::FONT_SIZE size = cit->font().size();
                if (size > maxsize && size <= LyXFont::SIZE_HUGER)
                        maxsize = size;
        }
@@ -706,52 +729,6 @@ Paragraph::getUChar(BufferParams const & bparams,
 }
 
 
-// return an string of the current word, and the end of the word in lastpos.
-string const Paragraph::getWord(Paragraph::size_type & lastpos) const
-{
-       lyx::Assert(lastpos >= 0);
-
-       // the current word is defined as starting at the first character
-       // from the immediate left of lastpospos which meets the definition
-       // of IsLetter(), continuing to the last character to the right
-       // of this meeting IsLetter.
-
-       string theword;
-
-       // grab a word
-               
-       // move back until we have a letter
-
-       //there's no real reason to have firstpos & lastpos as
-       //separate variables as this is written, but maybe someon
-       // will want to return firstpos in the future.
-
-       //since someone might have typed a punctuation first
-       int firstpos = lastpos;
-       
-       while ((firstpos >= 0) && !isLetter(firstpos))
-               --firstpos;
-
-       // now find the beginning by looking for a nonletter
-       
-       while ((firstpos>= 0) && isLetter(firstpos))
-               --firstpos;
-
-       // the above is now pointing to the preceeding non-letter
-       ++firstpos;
-       lastpos = firstpos;
-
-       // so copy characters into theword  until we get a nonletter
-       // note that this can easily exceed lastpos, wich means
-       // that if used in the middle of a word, the whole word
-       // is included
-
-       while (isLetter(lastpos)) theword += getChar(lastpos++);
-       
-       return theword;
-}
-
-
 void Paragraph::setFont(Paragraph::size_type pos,
                           LyXFont const & font)
 {
@@ -860,7 +837,7 @@ void Paragraph::breakParagraph(BufferParams const & bparams,
        // create a new paragraph
        Paragraph * tmp = new Paragraph(this);
        // remember to set the inset_owner
-       tmp->setInsetOwner(InInset());
+       tmp->setInsetOwner(inInset());
        
        // this is an idea for a more userfriendly layout handling, I will
        // see what the users say
@@ -921,10 +898,8 @@ void Paragraph::breakParagraph(BufferParams const & bparams,
 void Paragraph::makeSameLayout(Paragraph const * par)
 {
        layout = par->layout;
-       params().makeSame(par->params());
-       
-       // This can be changed after NEW_INSETS is in effect. (Lgb)
-       setLabelWidthString(par->params().labelWidthString());
+       // move to pimpl?
+       params() = par->params();
 }
 
 
@@ -1190,7 +1165,7 @@ int Paragraph::autoDeleteInsets()
        int count = 0;
        InsetList::size_type index = 0;
        while (index < insetlist.size()) {
-               if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
+               if (insetlist[index].inset && insetlist[index].inset->autoDelete()) {
                        erase(insetlist[index].pos); 
                        // Erase() calls to insetlist.erase(&insetlist[index])
                        // so index shouldn't be increased.
@@ -1219,8 +1194,8 @@ int Paragraph::getPositionOfInset(Inset * inset) const
        // Find the entry.
        for (InsetList::const_iterator cit = insetlist.begin();
             cit != insetlist.end(); ++cit) {
-               if ((*cit).inset == inset) {
-                       return (*cit).pos;
+               if (cit->inset == inset) {
+                       return cit->pos;
                }
        }
        if (inset == bibkey)
@@ -1282,6 +1257,8 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
        Language const * doc_language = bparams.language;
        Language const * previous_language = previous_
                ? previous_->getParLanguage(bparams) : doc_language;
+       if (language == ignore_language || language == inherit_language)
+               lyxerr << "1:" << language->lang() << endl;
        if (language->babel() != doc_language->babel() &&
            language->babel() != previous_language->babel()) {
                os << subst(lyxrc.language_command_begin, "$$lang",
@@ -1291,13 +1268,14 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
        }
 
        if (bparams.inputenc == "auto" &&
-           language->encoding() != previous_language->encoding()) {
+           language->encoding() != previous_language->encoding())
+       {
                os << "\\inputencoding{"
                   << language->encoding()->LatexName()
                   << "}" << endl;
                texrow.newline();
        }
-       
+
        switch (style.latextype) {
        case LATEX_COMMAND:
                os << '\\'
@@ -1306,7 +1284,7 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
                break;
        case LATEX_ITEM_ENVIRONMENT:
                if (bibkey) {
-                       bibkey->Latex(buf, os, false, false);
+                       bibkey->latex(buf, os, false, false);
                } else
                        os << "\\item ";
                break;
@@ -1342,8 +1320,9 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
                os << "}";
 
        if (language->babel() != doc_language->babel() &&
-           (!next_
-            || next_->getParLanguage(bparams)->babel() != language->babel())) {
+           (!next_ ||
+            next_->getParLanguage(bparams)->babel() != language->babel()))
+       {
                os << endl 
                   << subst(lyxrc.language_command_end, "$$lang",
                            doc_language->babel());
@@ -1597,15 +1576,24 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
 
        // If we have an open font definition, we have to close it
        if (open_font) {
+#ifdef FIXED_LANGUAGE_END_DETECTION
                if (next_) {
                        running_font
                                .latexWriteEndChanges(os, basefont,
-                                                     next_->getFont(bparams,
-                                                                    0));
+                                                     next_->getFont(bparams,
+                                                     0));
                } else {
                        running_font.latexWriteEndChanges(os, basefont,
-                                                         basefont);
+                                                         basefont);
                }
+#else
+#ifdef WITH_WARNINGS
+#warning For now we ALWAYS have to close the foreign font settings if they are
+#warning there as we start another \selectlanguage with the next paragraph if
+#warning we are in need of this. This should be fixed sometime (Jug)
+#endif
+               running_font.latexWriteEndChanges(os, basefont,  basefont);
+#endif
        }
 
        // Needed if there is an optional argument but no contents.
@@ -1841,9 +1829,13 @@ bool Paragraph::isWord(size_type pos ) const
 Language const *
 Paragraph::getParLanguage(BufferParams const & bparams) const 
 {
-       if (size() > 0)
-               return getFirstFontSettings().language();
-       else if (previous_)
+       if (size() > 0) {
+               Language const * lang = getFirstFontSettings().language();
+#warning We should make this somewhat better, any ideas? (Jug)
+               if (lang == inherit_language || lang == ignore_language)
+                       lang = bparams.language;
+               return lang;
+       } else if (previous_)
                return previous_->getParLanguage(bparams);
        else
                return bparams.language;
@@ -1875,7 +1867,9 @@ bool Paragraph::isMultiLingual(BufferParams const & bparams)
        Language const * doc_language = bparams.language;
        for (Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
             cit != pimpl_->fontlist.end(); ++cit)
-               if ((*cit).font().language() != doc_language)
+               if (cit->font().language() != inherit_language &&
+                       cit->font().language() != ignore_language &&
+                       cit->font().language() != doc_language)
                        return true;
        return false;
 }
@@ -1896,9 +1890,9 @@ string const Paragraph::asString(Buffer const * buffer, bool label)
                if (IsPrintable(c))
                        s += c;
                else if (c == META_INSET &&
-                        getInset(i)->LyxCode() == Inset::MATH_CODE) {
-                       std::ostringstream ost;
-                       getInset(i)->Ascii(buffer, ost);
+                        getInset(i)->lyxCode() == Inset::MATH_CODE) {
+                       ostringstream ost;
+                       getInset(i)->ascii(buffer, ost);
                        s += subst(ost.str().c_str(),'\n',' ');
                }
        }
@@ -1914,7 +1908,7 @@ string const Paragraph::asString(Buffer const * buffer,
                            Paragraph::size_type beg,
                            Paragraph::size_type end)
 {
-       std::ostringstream ost;
+       ostringstream ost;
 
        if (beg == 0 && !params().labelString().empty())
                ost << params().labelString() << ' ';
@@ -1924,7 +1918,7 @@ string const Paragraph::asString(Buffer const * buffer,
                if (IsPrintable(c))
                        ost << c;
                else if (c == META_INSET) {
-                       getInset(i)->Ascii(buffer, ost);
+                       getInset(i)->ascii(buffer, ost);
                }
        }
 
@@ -1937,8 +1931,8 @@ void Paragraph::setInsetOwner(Inset * i)
        pimpl_->inset_owner = i;
        for (InsetList::const_iterator cit = insetlist.begin();
             cit != insetlist.end(); ++cit) {
-               if ((*cit).inset)
-                       (*cit).inset->setOwner(i);
+               if (cit->inset)
+                       cit->inset->setOwner(i);
        }
 }
 
@@ -1948,10 +1942,10 @@ void Paragraph::deleteInsetsLyXText(BufferView * bv)
        // then the insets
        for (InsetList::const_iterator cit = insetlist.begin();
             cit != insetlist.end(); ++cit) {
-               if ((*cit).inset) {
-                       if ((*cit).inset->IsTextInset()) {
+               if (cit->inset) {
+                       if (cit->inset->isTextInset()) {
                                static_cast<UpdatableInset *>
-                                       ((*cit).inset)->deleteLyXText(bv, true);
+                                       (cit->inset)->deleteLyXText(bv, true);
                        }
                }
        }
@@ -1963,10 +1957,10 @@ void Paragraph::resizeInsetsLyXText(BufferView * bv)
        // then the insets
        for (InsetList::const_iterator cit = insetlist.begin();
             cit != insetlist.end(); ++cit) {
-               if ((*cit).inset) {
-                       if ((*cit).inset->IsTextInset()) {
+               if (cit->inset) {
+                       if (cit->inset->isTextInset()) {
                                static_cast<UpdatableInset *>
-                                       ((*cit).inset)->resizeLyXText(bv, true);
+                                       (cit->inset)->resizeLyXText(bv, true);
                        }
                }
        }
@@ -2004,7 +1998,7 @@ void  Paragraph::id(int id_arg)
 }
 
 
-LyXTextClass::size_type Paragraph::getLayout() const
+LyXTextClass::LayoutList::size_type Paragraph::getLayout() const
 {
        return layout;
 }
@@ -2019,7 +2013,7 @@ bool Paragraph::isFirstInSequence() const
 }
 
 
-Inset * Paragraph::InInset()
+Inset * Paragraph::inInset() const
 {
        return pimpl_->inset_owner;
 }
@@ -2057,9 +2051,7 @@ void Paragraph::setChar(size_type pos, value_type c)
 
 Paragraph::inset_iterator::inset_iterator(Paragraph::InsetList::iterator const & iter)
  : it(iter) 
-{
-
-}
+{}
 
 
 Paragraph::inset_iterator Paragraph::inset_iterator_begin()
@@ -2079,8 +2071,14 @@ ParagraphParameters & Paragraph::params()
        return pimpl_->params;
 }
 
+
 ParagraphParameters const & Paragraph::params() const
 {
        return pimpl_->params;
 }
 
+
+Paragraph * Paragraph::getParFromID(int id) const
+{
+       return pimpl_->getParFromID(id);
+}