X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftext2.C;h=938d9fd3a201fea559db7fc53fa9f8fff6538588;hb=757e2c55d8c15db0db5b4127bb3f6f22e4d7d81b;hp=99497d055529a6e1f79872f7cefe5806f5f12223;hpb=b15e539c6868321078523e60d2c1a210c639a4eb;p=lyx.git diff --git a/src/text2.C b/src/text2.C index 99497d0555..938d9fd3a2 100644 --- a/src/text2.C +++ b/src/text2.C @@ -25,6 +25,7 @@ #include "layout.h" #include "LyXView.h" #include "support/textutils.h" +#include "support/lstrings.h" #include "undo_funcs.h" #include "buffer.h" #include "bufferparams.h" @@ -65,9 +66,21 @@ LyXText::LyXText(InsetText * inset) copylayouttype(0) {} -void LyXText::init(BufferView * bview) +void LyXText::init(BufferView * bview, bool reinit) { - if (firstrow) + 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 +114,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 +129,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 +159,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 +175,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,12 +194,12 @@ 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); if (inset) { - if (inset->editable()==Inset::HIGHLY_EDITABLE) { + if (inset->editable()==Inset::IS_EDITABLE) { UpdatableInset * uinset = static_cast(inset); uinset->setFont(bv, fnt, toggleall, true); @@ -212,12 +227,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 +271,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 +290,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 +362,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 @@ -360,10 +379,11 @@ void LyXText::insertParagraph(BufferView * bview, Paragraph * par, } } + Inset * LyXText::getInset() const { Inset * inset = 0; - if (cursor.pos() == 0 && cursor.par()->bibkey){ + 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) { @@ -372,6 +392,7 @@ Inset * LyXText::getInset() const return inset; } + void LyXText::toggleInset(BufferView * bview) { Inset * inset = getInset(); @@ -382,7 +403,15 @@ void LyXText::toggleInset(BufferView * bview) // 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 } @@ -394,15 +423,14 @@ void LyXText::makeFontEntriesLayoutSpecific(Buffer const * buf, LyXLayout const & layout = textclasslist.Style(buf->params.textclass, par->getLayout()); - LyXFont layoutfont, tmpfont; - for (Paragraph::size_type pos = 0; - pos < par->size(); ++pos) { + LyXFont layoutfont; + for (Paragraph::size_type pos = 0; pos < par->size(); ++pos) { if (pos < beginningOfMainBody(buf, par)) layoutfont = layout.labelfont; else layoutfont = layout.font; - tmpfont = par->getFontSettings(buf->params, pos); + LyXFont tmpfont = par->getFontSettings(buf->params, pos); tmpfont.reduce(layoutfont); par->setFont(pos, tmpfont); } @@ -495,7 +523,7 @@ void LyXText::setLayout(BufferView * bview, LyXTextClass::size_type layout) selection.cursor = cursor; setCursor(bview, selection.end.par(), selection.end.pos(), false); updateCounters(bview, cursor.row()); - clearSelection(bview); + clearSelection(); setSelection(bview); setCursor(bview, tmpcursor.par(), tmpcursor.pos(), true); } @@ -576,7 +604,7 @@ void LyXText::incDepth(BufferView * bview) selection.cursor = cursor; setCursor(bview, selection.end.par(), selection.end.pos()); updateCounters(bview, cursor.row()); - clearSelection(bview); + clearSelection(); setSelection(bview); setCursor(bview, tmpcursor.par(), tmpcursor.pos()); } @@ -633,7 +661,7 @@ void LyXText::decDepth(BufferView * bview) selection.cursor = cursor; setCursor(bview, selection.end.par(), selection.end.pos()); updateCounters(bview, cursor.row()); - clearSelection(bview); + clearSelection(); setSelection(bview); setCursor(bview, tmpcursor.par(), tmpcursor.pos()); } @@ -652,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; } @@ -696,7 +723,7 @@ void LyXText::setFont(BufferView * bview, LyXFont const & font, bool toggleall) setCursor(bview, selection.start.par(), selection.start.pos()); selection.cursor = cursor; setCursor(bview, selection.end.par(), selection.end.pos()); - clearSelection(bview); + clearSelection(); setSelection(bview); setCursor(bview, tmpcursor.par(), tmpcursor.pos(), true, tmpcursor.boundary()); @@ -752,7 +779,7 @@ void LyXText::redoDrawingOfParagraph(BufferView * bview, LyXCursor const & cur) // and the specified par // This function is needed after SetLayout and SetFont etc. void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur, - Paragraph const * endpar) const + Paragraph const * endpar) const { Row * tmprow2; Paragraph * tmppar = 0; @@ -770,7 +797,8 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur, } else { first_phys_par = tmprow->par(); while (tmprow->previous() - && tmprow->previous()->par() == first_phys_par) { + && tmprow->previous()->par() == first_phys_par) + { tmprow = tmprow->previous(); y -= tmprow->height(); } @@ -780,8 +808,8 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur, status(bview, LyXText::NEED_MORE_REFRESH); refresh_y = y; refresh_row = tmprow->previous(); /* the real refresh row will - be deleted, so I store - the previous here */ + be deleted, so I store + the previous here */ // remove it if (tmprow->next()) tmppar = tmprow->next()->par(); @@ -797,7 +825,7 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur, // remove the first one tmprow2 = tmprow; /* this is because tmprow->previous() - can be 0 */ + can be 0 */ tmprow = tmprow->previous(); removeRow(tmprow2); @@ -949,11 +977,11 @@ string const LyXText::selectionAsString(Buffer const * buffer) const } -void LyXText::clearSelection(BufferView * /*bview*/) const +void LyXText::clearSelection() const { selection.set(false); selection.mark(false); - selection.end = selection.start = cursor; + selection.end = selection.start = selection.cursor = cursor; } @@ -1012,8 +1040,8 @@ void LyXText::toggleFree(BufferView * bview, // is disabled. LyXCursor resetCursor = cursor; bool implicitSelection = (font.language() == ignore_language - && font.number() == LyXFont::IGNORE) - ? selectWordWhenUnderCursor(bview) : false; + && font.number() == LyXFont::IGNORE) + ? selectWordWhenUnderCursor(bview, WHOLE_WORD_STRICT) : false; // Set font setFont(bview, font, toggleall); @@ -1021,7 +1049,7 @@ void LyXText::toggleFree(BufferView * bview, // Implicit selections are cleared afterwards //and cursor is set to the original position. if (implicitSelection) { - clearSelection(bview); + clearSelection(); cursor = resetCursor; setCursor(bview, cursor.par(), cursor.pos()); selection.cursor = cursor; @@ -1031,6 +1059,39 @@ void LyXText::toggleFree(BufferView * bview, } +string +LyXText::getStringToIndex(BufferView * bview) +{ + string idxstring; + + // Try implicit word selection + // If there is a change in the language the implicit word selection + // is disabled. + LyXCursor resetCursor = cursor; + bool implicitSelection = selectWordWhenUnderCursor(bview, PREVIOUS_WORD); + + if (!selection.set()) { + bview->owner()->message(_("Nothing to index!")); + return string(); + } + if (selection.start.par() != selection.end.par()) { + bview->owner()->message(_("Cannot index more than one paragraph!")); + return string(); + } + + idxstring = selectionAsString(bview->buffer()); + + // Implicit selections are cleared afterwards + //and cursor is set to the original position. + if (implicitSelection) { + clearSelection(); + cursor = resetCursor; + setCursor(bview, cursor.par(), cursor.pos()); + selection.cursor = cursor; + } + return idxstring; +} + Paragraph::size_type LyXText::beginningOfMainBody(Buffer const * buf, Paragraph const * par) const @@ -1116,7 +1177,7 @@ void LyXText::setParagraph(BufferView * bview, redoParagraphs(bview, selection.start, endpar); - clearSelection(bview); + clearSelection(); setCursor(bview, selection.start.par(), selection.start.pos()); selection.cursor = cursor; setCursor(bview, selection.end.par(), selection.end.pos()); @@ -1645,7 +1706,7 @@ void LyXText::cutSelection(BufferView * bview, bool doclear) cursor = selection.start; // need a valid cursor. (Lgb) - clearSelection(bview); + clearSelection(); setCursor(bview, cursor.par(), cursor.pos()); selection.cursor = cursor; @@ -1704,7 +1765,7 @@ void LyXText::pasteSelection(BufferView * bview) redoParagraphs(bview, cursor, endpar); setCursor(bview, cursor.par(), cursor.pos()); - clearSelection(bview); + clearSelection(); selection.cursor = cursor; setCursor(bview, actpar, pos); @@ -1773,65 +1834,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); + clearSelection(); - // 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()); @@ -2156,19 +2162,24 @@ void LyXText::setCurrentFont(BufferView * bview) const void LyXText::setCursorFromCoordinates(BufferView * bview, int x, int y) const { LyXCursor old_cursor = cursor; - + +#if 0 // Get the row first. Row * row = getRowNearY(y); - cursor.par(row->par()); bool bound = false; int column = getColumnNearX(bview, row, x, bound); + + cursor.par(row->par()); cursor.pos(row->pos() + column); cursor.x(x); cursor.y(y + row->baseline()); cursor.row(row); cursor.boundary(bound); +#else + setCursorFromCoordinates(bview, cursor, x, y); +#endif setCurrentFont(bview); deleteEmptyParagraphMechanism(bview, old_cursor); } @@ -2181,7 +2192,7 @@ void LyXText::setCursorFromCoordinates(BufferView * bview, LyXCursor & cur, Row * row = getRowNearY(y); bool bound = false; - int column = getColumnNearX(bview, row, x, bound); + int const column = getColumnNearX(bview, row, x, bound); cur.par(row->par()); cur.pos(row->pos() + column); @@ -2526,6 +2537,11 @@ void LyXText::status(BufferView * bview, LyXText::text_status st) const status_ = st; if (inset_owner && st != UNCHANGED) { bview->text->status(bview, NEED_VERY_LITTLE_REFRESH); + if (!bview->text->refresh_row) { + bview->text->refresh_row = bview->text->cursor.row(); + bview->text->refresh_y = bview->text->cursor.y() - + bview->text->cursor.row()->baseline(); + } } } #endif