]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
do what the FIXME suggested
[lyx.git] / src / Text.cpp
index c29876d9a1efe030cd6e0403c79387c6679887c6..5e18d6f18544fd41fb0ba7d924bd59f25a0cd689 100644 (file)
@@ -96,7 +96,7 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                font = Font(inherit_font, bp.language);
                change = Change(Change::UNCHANGED);
 
-               TextClass const & tclass = bp.getTextClass();
+               DocumentClass const & tclass = bp.documentClass();
 
                if (layoutname.empty())
                        layoutname = tclass.defaultLayoutName();
@@ -125,12 +125,12 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                                        tclass.defaultLayoutName();
                }
 
-               par.setLayout(bp.getTextClass()[layoutname]);
+               par.setLayout(bp.documentClass()[layoutname]);
 
                // Test whether the layout is obsolete.
                LayoutPtr const & layout = par.layout();
                if (!layout->obsoleted_by().empty())
-                       par.setLayout(bp.getTextClass()[layout->obsoleted_by()]);
+                       par.setLayout(bp.documentClass()[layout->obsoleted_by()]);
 
                par.params().read(lex);
 
@@ -220,7 +220,7 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                                inset.reset(new InsetSpecialChar);
                        else
                                inset.reset(new InsetSpace);
-                       inset->read(buf, lex);
+                       inset->read(lex);
                        par.insertInset(par.size(), inset.release(),
                                        font, change);
                }
@@ -228,15 +228,15 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                par.appendChar('\\', font, change);
        } else if (token == "\\linebreak") {
                auto_ptr<Inset> inset(new InsetLinebreak);
-               inset->read(buf, lex);
+               inset->read(lex);
                par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\newline") {
                auto_ptr<Inset> inset(new InsetNewline);
-               inset->read(buf, lex);
+               inset->read(lex);
                par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\LyXTable") {
                auto_ptr<Inset> inset(new InsetTabular(buf));
-               inset->read(buf, lex);
+               inset->read(lex);
                par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\hfill") {
                par.insertInset(par.size(), new InsetHFill, font, change);
@@ -355,7 +355,7 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic)
        Paragraph & cpar = cur.paragraph();
        pit_type cpit = cur.pit();
 
-       TextClass const & tclass = cur.buffer().params().getTextClass();
+       DocumentClass const & tclass = cur.buffer().params().documentClass();
        LayoutPtr const & layout = cpar.layout();
 
        // this is only allowed, if the current paragraph is not empty
@@ -450,8 +450,8 @@ void Text::insertChar(Cursor & cur, char_type c)
                            !(contains(number_seperators, c) &&
                              cur.pos() != 0 &&
                              cur.pos() != cur.lastpos() &&
-                             tm.getDisplayFont(pit, cur.pos()).fontInfo().number() == FONT_ON &&
-                             tm.getDisplayFont(pit, cur.pos() - 1).fontInfo().number() == FONT_ON)
+                             tm.displayFont(pit, cur.pos()).fontInfo().number() == FONT_ON &&
+                             tm.displayFont(pit, cur.pos() - 1).fontInfo().number() == FONT_ON)
                           )
                                number(cur); // Set current_font.number to OFF
                } else if (isDigit(c) &&
@@ -469,7 +469,7 @@ void Text::insertChar(Cursor & cur, char_type c)
                                                tm.font_);
                                } else if (contains(number_seperators, c)
                                     && cur.pos() >= 2
-                                    && tm.getDisplayFont(pit, cur.pos() - 2).fontInfo().number() == FONT_ON) {
+                                    && tm.displayFont(pit, cur.pos() - 2).fontInfo().number() == FONT_ON) {
                                        setCharFont(buffer, pit, cur.pos() - 1, cur.current_font,
                                                tm.font_);
                                }
@@ -502,7 +502,7 @@ void Text::insertChar(Cursor & cur, char_type c)
        if ((cur.pos() >= 2) && (par.isLineSeparator(cur.pos() - 1))) {
                // get font in front and behind the space in question. But do NOT 
                // use getFont(cur.pos()) because the character c is not inserted yet
-               Font const pre_space_font  = tm.getDisplayFont(cur.pit(), cur.pos() - 2);
+               Font const pre_space_font  = tm.displayFont(cur.pit(), cur.pos() - 2);
                Font const & post_space_font = cur.real_current_font;
                bool pre_space_rtl  = pre_space_font.isVisibleRightToLeft();
                bool post_space_rtl = post_space_font.isVisibleRightToLeft();
@@ -515,7 +515,7 @@ void Text::insertChar(Cursor & cur, char_type c)
                                (pre_space_rtl == par.isRTL(buffer.params())) ?
                                pre_space_font.language() : post_space_font.language();
 
-                       Font space_font = tm.getDisplayFont(cur.pit(), cur.pos() - 1);
+                       Font space_font = tm.displayFont(cur.pit(), cur.pos() - 1);
                        space_font.setLanguage(lang);
                        par.setFont(cur.pos() - 1, space_font);
                }
@@ -581,19 +581,7 @@ void Text::charInserted(Cursor & cur)
            && !par.isLetter(cur.pos() - 1)) {
                // get the word in front of cursor
                BOOST_ASSERT(this == cur.text());
-               CursorSlice focus = cur.top();
-               focus.backwardPos();
-               CursorSlice from = focus;
-               CursorSlice to = focus;
-               getWord(from, to, PREVIOUS_WORD);
-               if (focus == from || to == from)
-                       return;
-               docstring word
-               = par.asString(cur.buffer(), from.pos(), to.pos(), false);
-
-               // register words longer than 5 characters
-               if (word.length() > 5)
-                       cur.buffer().registerWord(word);
+               cur.paragraph().updateWords(cur.top());
        }
 }
 
@@ -927,10 +915,7 @@ bool Text::handleBibitems(Cursor & cur)
        } 
 
        // otherwise reset to default
-       if (par.useEmptyLayout())
-               cur.paragraph().setLayout(bufparams.getTextClass().emptyLayout());
-       else
-               cur.paragraph().setLayout(bufparams.getTextClass().defaultLayout());
+       cur.paragraph().setEmptyOrDefaultLayout(bufparams.documentClass());
        return true;
 }
 
@@ -991,7 +976,7 @@ bool Text::backspacePos0(Cursor & cur)
        bool needsUpdate = false;
 
        BufferParams const & bufparams = cur.buffer().params();
-       TextClass const & tclass = bufparams.getTextClass();
+       DocumentClass const & tclass = bufparams.documentClass();
        ParagraphList & plist = cur.text()->paragraphs();
        Paragraph const & par = cur.paragraph();
        Cursor prevcur = cur;
@@ -1116,7 +1101,7 @@ bool Text::dissolveInset(Cursor & cur) {
                for (; it != it_end; it++)
                        it->changeLanguage(b.params(), latex_language, b.language());
 
-               pasteParagraphList(cur, plist, b.params().getTextClassPtr(),
+               pasteParagraphList(cur, plist, b.params().documentClassPtr(),
                                   b.errorList("Paste"));
                // restore position
                cur.pit() = min(cur.lastpit(), spit);
@@ -1129,7 +1114,7 @@ bool Text::dissolveInset(Cursor & cur) {
 
 
 void Text::getWord(CursorSlice & from, CursorSlice & to,
-       word_location const loc)
+       word_location const loc) const
 {
        Paragraph const & from_par = pars_[from.pit()];
        switch (loc) {
@@ -1161,7 +1146,7 @@ void Text::getWord(CursorSlice & from, CursorSlice & to,
                break;
        }
        to = from;
-       Paragraph & to_par = pars_[to.pit()];
+       Paragraph const & to_par = pars_[to.pit()];
        while (to.pos() < to_par.size() && to_par.isLetter(to.pos()))
                ++to.pos();
 }
@@ -1173,7 +1158,7 @@ void Text::write(Buffer const & buf, ostream & os) const
        ParagraphList::const_iterator end = paragraphs().end();
        depth_type dth = 0;
        for (; pit != end; ++pit)
-               pit->write(buf, os, buf.params(), dth);
+               pit->write(os, buf.params(), dth);
 
        // Close begin_deeper
        for(; dth > 0; --dth)
@@ -1218,6 +1203,10 @@ bool Text::read(Buffer const & buf, Lexer & lex,
                        // not BufferParams
                        lyx::readParagraph(buf, pars_.back(), lex, errorList);
 
+                       // register the words in the global word list
+                       CursorSlice sl = CursorSlice(*insetPtr);
+                       sl.pit() = pars_.size() - 1;
+                       pars_.back().updateWords(sl);
                } else if (token == "\\begin_deeper") {
                        ++depth;
                } else if (token == "\\end_deeper") {
@@ -1319,7 +1308,7 @@ docstring Text::getPossibleLabel(Cursor & cur) const
        LayoutPtr layout = pars_[pit].layout();
 
        docstring text;
-       docstring par_text = pars_[pit].asString(cur.buffer(), false);
+       docstring par_text = pars_[pit].asString(false);
        string piece;
        // the return string of math matrices might contain linebreaks
        par_text = subst(par_text, '\n', '-');