]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
Remove unused font variable which caused a warning.
[lyx.git] / src / text2.C
index 575405f685f1d7dd8e8f215caed1b09b457759ab..c61d56219ea49188cbb6af5881c50000d3a5f54d 100644 (file)
@@ -65,9 +65,21 @@ LyXText::LyXText(InsetText * inset)
           copylayouttype(0)
 {}
 
-void LyXText::init(BufferView * bview)
-{
-       if (firstrow)
+void LyXText::init(BufferView * bview, bool reinit)
+{
+       if (reinit) {
+               // Delete all rows, this does not touch the paragraphs!
+               Row * tmprow = firstrow;
+               while (firstrow) {
+                       tmprow = firstrow->next();
+                       delete firstrow;
+                       firstrow = tmprow;
+               }
+               lastrow = refresh_row = need_break_row = 0;
+               width = height = copylayouttype = 0;
+               number_of_rows = first = refresh_y = 0;
+               status_ = LyXText::UNCHANGED;
+       } else if (firstrow)
                return;
 
        Paragraph * par = ownerParagraph();
@@ -101,7 +113,7 @@ LyXText::~LyXText()
 // If position is -1, we get the layout font of the paragraph.
 // If position is -2, we get the font of the manual label of the paragraph.
 LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
-                              Paragraph::size_type pos) const
+                               Paragraph::size_type pos) const
 {
        LyXLayout const & layout = 
                textclasslist.Style(buf->params.textclass, par->getLayout());
@@ -116,10 +128,10 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
                                // 1% goes here
                                LyXFont f = par->getFontSettings(buf->params,
                                                                 pos);
-                               return f.realize(layout.reslabelfont);
+                               return f.realize(layout.reslabelfont, buf->params.language);
                        } else {
                                LyXFont f = par->getFontSettings(buf->params, pos);
-                               return f.realize(layout.resfont);
+                               return f.realize(layout.resfont, buf->params.language);
                        }
                        
                } else {
@@ -146,7 +158,7 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
                        layoutfont = layout.font;
                }
                tmpfont = par->getFontSettings(buf->params, pos);
-               tmpfont.realize(layoutfont);
+               tmpfont.realize(layoutfont, buf->params.language);
        } else {
                // 5% goes here.
                // process layoutfont for pos == -1 and labelfont for pos < -1
@@ -162,12 +174,14 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
                if (par) {
                        tmpfont.realize(textclasslist.
                                        Style(buf->params.textclass,
-                                             par->getLayout()).font);
+                                             par->getLayout()).font,
+                                                       buf->params.language);
                        par_depth = par->getDepth();
                }
        }
 
-       tmpfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont());
+       tmpfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(),
+                       buf->params.language);
 
        return tmpfont;
 }
@@ -179,7 +193,7 @@ void LyXText::setCharFont(BufferView * bv, Paragraph * par,
 {
        Buffer const * buf = bv->buffer();
        LyXFont font = getFont(buf, par, pos);
-       font.update(fnt, buf->params.language, toggleall);
+       font.update(fnt, toggleall);
        // Let the insets convert their font
        if (par->getChar(pos) == Paragraph::META_INSET) {
                Inset * inset = par->getInset(pos);
@@ -212,12 +226,14 @@ void LyXText::setCharFont(BufferView * bv, Paragraph * par,
                        tp = tp->outerHook();
                        if (tp)
                                layoutfont.realize(textclasslist.
-                                                  Style(buf->params.textclass,
-                                                        tp->getLayout()).font);
+                                                  Style(buf->params.textclass,
+                                                        tp->getLayout()).font,
+                                                  buf->params.language);
                }
        }
 
-       layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont());
+       layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(),
+                          buf->params.language);
 
        // Now, reduce font against full layout font
        font.reduce(layoutfont);
@@ -254,12 +270,14 @@ void LyXText::setCharFont(Buffer const * buf, Paragraph * par,
                        tp = tp->outerHook();
                        if (tp)
                                layoutfont.realize(textclasslist.
-                                                  Style(buf->params.textclass,
-                                                        tp->getLayout()).font);
+                                                  Style(buf->params.textclass,
+                                                        tp->getLayout()).font,
+                                                  buf->params.language);
                }
        }
 
-       layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont());
+       layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(),
+                          buf->params.language);
 
        // Now, reduce font against full layout font
        font.reduce(layoutfont);
@@ -271,7 +289,7 @@ void LyXText::setCharFont(Buffer const * buf, Paragraph * par,
 // inserts a new row behind the specified row, increments
 // the touched counters
 void LyXText::insertRow(Row * row, Paragraph * par,
-                       Paragraph::size_type pos) const
+                        Paragraph::size_type pos) const
 {
        Row * tmprow = new Row;
        if (!row) {
@@ -343,10 +361,10 @@ void LyXText::removeParagraph(Row * row) const
 
 // insert the specified paragraph behind the specified row
 void LyXText::insertParagraph(BufferView * bview, Paragraph * par,
-                             Row * row) const
+                              Row * row) const
 {
-       insertRow(row, par, 0);        /* insert a new row, starting 
-                                       * at postition 0 */
+       insertRow(row, par, 0);            /* insert a new row, starting 
+                                           * at postition 0 */
 
        setCounter(bview->buffer(), par);  // set the counters
    
@@ -361,6 +379,41 @@ void LyXText::insertParagraph(BufferView * bview, Paragraph * par,
 }
 
 
+Inset * LyXText::getInset() const
+{
+       Inset * inset = 0;
+       if (cursor.pos() == 0 && cursor.par()->bibkey) {
+               inset = cursor.par()->bibkey;
+       } else if (cursor.pos() < cursor.par()->size() 
+                  && cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET) {
+               inset = cursor.par()->getInset(cursor.pos());
+       }
+       return inset;
+}
+
+
+void LyXText::toggleInset(BufferView * bview)
+{
+       Inset * inset = getInset();
+       if (!inset->editable())
+               return;
+       //bview->owner()->message(inset->editMessage());
+
+       // do we want to keep this?? (JMarc)
+       if (inset->editable() != Inset::HIGHLY_EDITABLE)
+               setCursorParUndo(bview);
+
+       if (inset->isOpen()) {
+               inset->close(bview);
+       } else {
+               inset->open(bview);
+       }
+#if 0
+       inset->open(bview, !inset->isOpen());
+#endif
+}
+
+
 /* used in setlayout */
 // Asger is not sure we want to do this...
 void LyXText::makeFontEntriesLayoutSpecific(Buffer const * buf,
@@ -627,15 +680,14 @@ void LyXText::setFont(BufferView * bview, LyXFont const & font, bool toggleall)
                else
                        layoutfont = getFont(bview->buffer(), cursor.par(),-1);
                // Update current font
-               real_current_font.update(font,
-                                        bview->buffer()->params.language,
-                                        toggleall);
+               real_current_font.update(font, toggleall);
 
                // Reduce to implicit settings
                current_font = real_current_font;
                current_font.reduce(layoutfont);
                // And resolve it completely
-               real_current_font.realize(layoutfont);
+               real_current_font.realize(layoutfont,
+                                         bview->buffer()->params.language);
                return;
        }
 
@@ -928,7 +980,7 @@ void LyXText::clearSelection(BufferView * /*bview*/) const
 {
        selection.set(false);
        selection.mark(false);
-       selection.end = selection.start = cursor;
+       selection.end = selection.start = selection.cursor = cursor;
 }
 
 
@@ -987,7 +1039,7 @@ void LyXText::toggleFree(BufferView * bview,
        // is disabled.
        LyXCursor resetCursor = cursor;
        bool implicitSelection = (font.language() == ignore_language
-                                 && font.number() == LyXFont::IGNORE)
+                                 && font.number() == LyXFont::IGNORE)
                ? selectWordWhenUnderCursor(bview) : false;
 
        // Set font
@@ -1253,7 +1305,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                                        par->params().labelString(string());
                        }
 
-                       std::ostringstream s;
+                       ostringstream s;
 
                        if (!par->params().appendix()) {
                                switch (2 * LABEL_COUNTER_CHAPTER -
@@ -1395,7 +1447,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                        par->incCounter(i + par->enumdepth);
                        int number = par->getCounter(i + par->enumdepth);
 
-                       std::ostringstream s;
+                       ostringstream s;
 
                        switch (par->enumdepth) {
                        case 1:
@@ -1455,11 +1507,11 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                
                // the caption hack:
                if (layout.labeltype == LABEL_SENSITIVE) {
-                       bool isOK (par->InInset() && par->InInset()->owner() &&
-                                  (par->InInset()->owner()->lyxCode() == Inset::FLOAT_CODE));
+                       bool isOK (par->inInset() && par->inInset()->owner() &&
+                                  (par->inInset()->owner()->lyxCode() == Inset::FLOAT_CODE));
                        
                        if (isOK) {
-                               InsetFloat * tmp = static_cast<InsetFloat*>(par->InInset()->owner());
+                               InsetFloat * tmp = static_cast<InsetFloat*>(par->inInset()->owner());
                                Floating const & fl
                                        = floatList.getType(tmp->type());
                                // We should get the correct number here too.
@@ -1518,7 +1570,7 @@ void LyXText::updateCounters(BufferView * bview, Row * row) const
 
 void LyXText::insertInset(BufferView * bview, Inset * inset)
 {
-       if (!cursor.par()->insertInsetAllowed(inset))
+       if (!cursor.par()->insetAllowed(inset->lyxCode()))
                return;
        setUndo(bview, Undo::INSERT,
                cursor.par(), cursor.par()->next());
@@ -1748,65 +1800,10 @@ void LyXText::insertStringAsLines(BufferView * bview, string const & str)
        
        setCursorParUndo(bview);
        
-       bool isEnvironment =
-               textclasslist.Style(bview->buffer()->params.textclass, 
-                                   cursor.par()->getLayout()).isEnvironment();
-       bool free_spacing =
-               textclasslist.Style(bview->buffer()->params.textclass, 
-                                   cursor.par()->getLayout()).free_spacing;
-       bool keepempty =
-               textclasslist.Style(bview->buffer()->params.textclass, 
-                                   cursor.par()->getLayout()).keepempty;
-
        // only to be sure, should not be neccessary
        clearSelection(bview);
        
-       // insert the string, don't insert doublespace
-       bool space_inserted = true;
-       for(string::const_iterator cit = str.begin(); 
-           cit != str.end(); ++cit) {
-               if (*cit == '\n') {
-                       if (par->size() || keepempty) { 
-                               par->breakParagraph(bview->buffer()->params, 
-                                                   pos, isEnvironment);
-                               par = par->next();
-                               pos = 0;
-                               space_inserted = true;
-                       } else {
-                               continue;
-                       }
-                       // do not insert consecutive spaces if !free_spacing
-               } else if ((*cit == ' ' || *cit == '\t')
-                          && space_inserted && !free_spacing) {
-                       continue;
-               } else if (*cit == '\t') {
-                       if (!free_spacing) {
-                               // tabs are like spaces here
-                               par->insertChar(pos, ' ', 
-                                               current_font);
-                               ++pos;
-                               space_inserted = true;
-                       } else {
-                               const Paragraph::value_type nb = 8 - pos % 8;
-                               for (Paragraph::size_type a = 0; 
-                                    a < nb ; ++a) {
-                                       par->insertChar(pos, ' ', 
-                                                       current_font);
-                                       ++pos;
-                               }
-                               space_inserted = true;
-                       }
-               } else if (!IsPrintable(*cit)) {
-                       // Ignore unprintables
-                       continue;
-               } else {
-                       // just insert the character
-                       par->insertChar(pos, *cit, current_font);
-                       ++pos;
-                       space_inserted = (*cit == ' ');
-               }
-
-       }       
+       bview->buffer()->insertStringAsLines(par, pos, current_font, str);
 
        redoParagraphs(bview, cursor, endpar);
        setCursor(bview, cursor.par(), cursor.pos());
@@ -2079,7 +2076,7 @@ void LyXText::setCursorIntern(BufferView * bview, Paragraph * par,
                              Paragraph::size_type pos,
                              bool setfont, bool boundary) const
 {
-       InsetText * it = static_cast<InsetText *>(par->InInset());
+       InsetText * it = static_cast<InsetText *>(par->inInset());
        if (it && (it != inset_owner)) {
                it->getLyXText(bview)->setCursorIntern(bview, par, pos, setfont,
                                                       boundary);
@@ -2402,20 +2399,6 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
 }
 
 
-Paragraph * LyXText::getParFromID(int id) const
-{
-       if (id < 0)
-               return 0;
-       Paragraph * result = firstParagraph();
-       Paragraph * ires = 0;
-       while (result && result->id() != id) {
-               if ((ires = result->getParFromID(id)))
-                       return ires;
-               result = result->next();
-       }
-       return result;
-}
-
 void LyXText::toggleAppendix(BufferView * bview)
 {
        Paragraph * par = cursor.par();
@@ -2459,9 +2442,9 @@ Paragraph * LyXText::ownerParagraph(Paragraph * p) const
 
 Paragraph * LyXText::ownerParagraph(int id, Paragraph * p) const
 {
-       Paragraph * op = getParFromID(id);
-       if (op && op->InInset()) {
-               static_cast<InsetText *>(op->InInset())->paragraph(p);
+       Paragraph * op = bv_owner->buffer()->getParFromID(id);
+       if (op && op->inInset()) {
+               static_cast<InsetText *>(op->inInset())->paragraph(p);
        } else {
                if (inset_owner) {
                        inset_owner->paragraph(p);
@@ -2491,12 +2474,27 @@ void LyXText::status(BufferView * bview, LyXText::text_status st) const
                }
        }
 #else
-#warning Please tell what the intention is here.
+#warning Please tell what the intention is here. (Lgb)
        // The above does not make any sense, I changed it to what is here,
        // but it still does not make much sense. (Lgb)
+#warning Sure have a look now! (Jug)
+       // well as much as I know && binds more then || so the above and the
+       // below are identical (this for your known use of parentesis!)
+       // Now some explanation:
+       // We should only go up with refreshing code so this means that if
+       // we have a MORE refresh we should never set it to LITTLE if we still
+       // didn't handle it (and then it will be UNCHANGED. Now as long as
+       // we stay inside one LyXText this may work but we need to tell the
+       // outermost LyXText that it should REALLY draw us if there is some
+       // change in a Inset::LyXText. So you see that when we are inside a
+       // inset's LyXText we give the LITTLE to the outermost LyXText to
+       // tell'em that it should redraw the actual row (where the inset
+       // resides! Capito?!
+
        if ((status_ != NEED_MORE_REFRESH)
            || (status_ == NEED_MORE_REFRESH
-               && st != NEED_VERY_LITTLE_REFRESH)) {
+               && st != NEED_VERY_LITTLE_REFRESH))
+       {
                status_ = st;
                if (inset_owner && st != UNCHANGED) {
                        bview->text->status(bview, NEED_VERY_LITTLE_REFRESH);