X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsettext.C;h=3355374259fdf4c345b553e51ce725933b41c29f;hb=8075064372c5361f2dfd91860003f0cb317b4e39;hp=3d21be31783b12a0d4f9bc30928aae4d28da8cab;hpb=cc3955aa12f0616a951883e022b2a3c4da452eb0;p=lyx.git diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 3d21be3178..3355374259 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -80,6 +80,7 @@ void InsetText::saveLyXTextState(LyXText * t) const sstate.selendboundary = t->selection.end.boundary(); sstate.selection = t->selection.set(); sstate.mark_set = t->selection.mark(); + sstate.refresh = t->refresh_row != 0; } void InsetText::restoreLyXTextState(BufferView * bv, LyXText * t) const @@ -102,6 +103,8 @@ void InsetText::restoreLyXTextState(BufferView * bv, LyXText * t) const t->selection.cursor = t->cursor; t->selection.set(false); } + if (sstate.refresh) { + } } } @@ -231,13 +234,13 @@ void InsetText::read(Buffer const * buf, LyXLex & lex) clear(); - while (lex.IsOK()) { + while (lex.isOK()) { lex.nextToken(); - token = lex.GetString(); + token = lex.getString(); if (token.empty()) continue; if (token == "\\end_inset") { -#ifdef NO_LATEX +#ifndef NO_COMPABILITY const_cast(buf)->insertErtContents(par, pos, font, false); #endif break; @@ -295,18 +298,28 @@ int InsetText::descent(BufferView * bv, LyXFont const &) const int InsetText::width(BufferView * bv, LyXFont const &) const { - insetWidth = max(textWidth(bv), - (int)getLyXText(bv)->width + (2 * TEXT_TO_INSET_OFFSET)); + insetWidth = max(textWidth(bv), (int)getLyXText(bv)->width) + + (2 * TEXT_TO_INSET_OFFSET); + insetWidth = max(insetWidth, 10); return insetWidth; } -int InsetText::textWidth(BufferView * bv) const +int InsetText::textWidth(BufferView * bv, bool fordraw) const { - if (!autoBreakRows) - return -1; - int const w = getMaxWidth(bv, this); - return w; + int w; + if (!autoBreakRows) { + w = -1; + } else { + w = getMaxWidth(bv, this); + } + if (fordraw) { + return max(w - (2 * TEXT_TO_INSET_OFFSET), + (int)getLyXText(bv)->width); + } else if (w < 0) { + return -1; + } + return w - (2 * TEXT_TO_INSET_OFFSET); } @@ -317,16 +330,38 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, return; Painter & pain = bv->painter(); + + // this is the first thing we have to ask because if the x pos + // changed we have to do a complete rebreak of the text as we + // may have few space to draw in. Well we should check on this too + int old_x = top_x; + if (top_x != int(x)) { + top_x = int(x); + int nw = getMaxWidth(bv, this); + if (nw > 0 && old_max_width != nw) { + need_update = INIT; + old_max_width = nw; + bv->text->status(bv, LyXText::CHANGED_IN_DRAW); + return; + } else { + top_x = old_x; + } + } + + // repaint the background if needed + if (cleared && backgroundColor() != LColor::background) { + top_x = int(x); + clearInset(pain, baseline, cleared); + top_x = old_x; + } // no draw is necessary !!! if ((drawFrame_ == LOCKED) && !locked && !par->size()) { top_x = int(x); top_baseline = baseline; x += width(bv, f); - if (!cleared && (need_update & CLEAR_FRAME)) + if (need_update & CLEAR_FRAME) clearFrame(pain, cleared); - else if (cleared) - frame_is_visible = false; need_update = NONE; return; } @@ -341,43 +376,37 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, (last_drawn_width!=insetWidth))) { clearInset(pain, baseline, cleared); } + + top_x = int(x); if (cleared) frame_is_visible = false; - if (!cleared && (need_update == NONE)) + if (!cleared && (need_update == NONE)) { + if (locked) + drawFrame(pain, cleared); return; - - if (top_x != int(x)) { - if ((getMaxWidth(bv, this) > 0) && - (getLyXText(bv)->width != old_max_width)) { - resizeLyXText(bv); - need_update |= FULL; - old_max_width = getLyXText(bv)->width; - bv->text->status(bv, LyXText::CHANGED_IN_DRAW); - } - top_x = int(x); - clearInset(pain, baseline, cleared); } -// lyxerr << "InsetText::draw[" << this << "](" << need_update << ":" << int(x) << ":" << top_x << ")\n"; + top_baseline = baseline; + top_y = baseline - ascent(bv, f); + last_width = width(bv, f); + last_height = ascent(bv, f) + descent(bv, f); if (cleared || (last_drawn_width != insetWidth)) { + if (!cleared) + clearInset(pain, baseline, cleared); need_update |= FULL; last_drawn_width = insetWidth; } - top_baseline = baseline; - top_y = baseline - ascent(bv, f); - last_width = width(bv, f); - last_height = ascent(bv, f) + descent(bv, f); - if (the_locking_inset && (cpar(bv) == inset_par) && (cpos(bv) == inset_pos)) { inset_x = cx(bv) - top_x + drawTextXOffset; inset_y = cy(bv) + drawTextYOffset; } if (!cleared && (need_update == CURSOR) - && !getLyXText(bv)->selection.set()) { + && !getLyXText(bv)->selection.set()) + { drawFrame(pain, cleared); x += last_width; // was width(bv, f); need_update = NONE; @@ -404,7 +433,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, if (y_offset < 0) y_offset = y; lt->first = first; - if (cleared) { + if (cleared || (need_update&(INIT|FULL))) { int yf = y_offset; y = 0; while ((row != 0) && (yf < ph)) { @@ -453,11 +482,12 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, void InsetText::drawFrame(Painter & pain, bool cleared) const { + static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2; if (!frame_is_visible || cleared) { - frame_x = top_x + 1; - frame_y = top_baseline - insetAscent + 1; - frame_w = insetWidth - 1; - frame_h = insetAscent + insetDescent - 1; + frame_x = top_x + ttoD2; + frame_y = top_baseline - insetAscent + ttoD2; + frame_w = last_width - TEXT_TO_INSET_OFFSET; + frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET; pain.rectangle(frame_x, frame_y, frame_w, frame_h, frame_color); frame_is_visible = true; @@ -532,13 +562,19 @@ void InsetText::setUpdateStatus(BufferView * bv, int what) const clear = true; } need_update |= what; - if (lt->status() == LyXText::NEED_MORE_REFRESH) + // we have to redraw us full if our LyXText NEEDS_MORE_REFRES or + // if we don't break row so that we only have one row to update! + if ((lt->status() == LyXText::NEED_MORE_REFRESH) || + (!autoBreakRows && + (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH))) + { need_update |= FULL; - else if (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH) + } else if (lt->status() == LyXText::NEED_VERY_LITTLE_REFRESH) { need_update |= CURSOR_PAR; + } // this to not draw a selection when we redraw all of it! - if (need_update & CURSOR) { + if (need_update & CURSOR && !(need_update & SELECTION)) { if (lt->selection.set()) need_update = FULL; lt->clearSelection(); @@ -557,11 +593,13 @@ void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const } lt->fullRebreak(bv); setUpdateStatus(bv, what); - if ((need_update != CURSOR) || (lt->status() != LyXText::UNCHANGED) || - lt->selection.set()) + if (((need_update != CURSOR) && (need_update != NONE)) || + (lt->status() != LyXText::UNCHANGED) || lt->selection.set()) { bv->updateInset(const_cast(this), mark_dirty); } + if (need_update == CURSOR) + need_update = NONE; bv->owner()->showState(); if (old_par != cpar(bv)) { bv->owner()->setLayout(cpar(bv)->getLayout()); @@ -645,7 +683,8 @@ void InsetText::edit(BufferView * bv, bool front) Paragraph * p = par; while(p->next()) p = p->next(); - lt->setCursor(bv, p, p->size()-1); + int const pos = (p->size() ? p->size()-1 : p->size()); + lt->setCursor(bv, p, pos); } lt->clearSelection(); finishUndo(); @@ -762,7 +801,6 @@ bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset) setUpdateStatus(bv, CURSOR_PAR); return the_locking_inset->updateInsetInInset(bv, inset); } -// updateLocal(bv, FULL, false); if (getLyXText(bv)->updateInset(bv, inset)) updateLocal(bv, CURSOR_PAR, false); if (cpar(bv) == inset_par && cpos(bv) == inset_pos) { @@ -828,11 +866,18 @@ void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button) localDispatch(bv, LFUN_COPY, ""); paste_internally = true; } - getLyXText(bv)->setCursorFromCoordinates(bv, x-drawTextXOffset, - y + insetAscent); - getLyXText(bv)->clearSelection(); - updateLocal(bv, FULL, false); - getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor; + bool clear = false; + if (!lt) { + lt = getLyXText(bv); + clear = true; + } + lt->setCursorFromCoordinates(bv, x-drawTextXOffset, y + insetAscent); + if (lt->selection.set()) { + lt->clearSelection(); + updateLocal(bv, FULL, false); + } else { + lt->clearSelection(); + } bv->owner()->setLayout(cpar(bv)->getLayout()); old_par = cpar(bv); // Insert primary selection with middle mouse @@ -845,6 +890,8 @@ void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button) localDispatch(bv, LFUN_PASTESELECTION, "paragraph"); } + if (clear) + lt = 0; } showInsetCursor(bv); no_selection = false; @@ -989,15 +1036,7 @@ InsetText::localDispatch(BufferView * bv, } lt->clearSelection(); for (string::size_type i = 0; i < arg.length(); ++i) { - if (greek_kb_flag) { - if (!math_insert_greek(bv, arg[i])) { - bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt); - } else if (!the_locking_inset) { - (void)moveRight(bv, false); - } - } else { - bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt); - } + bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt); } } lt->selection.cursor = lt->cursor; @@ -1501,7 +1540,7 @@ bool InsetText::insertInset(BufferView * bv, Inset * inset) (cpar(bv)->getInset(cpos(bv)) != inset)) lt->cursorLeft(bv); #endif - bv->fitCursor(lt); + bv->fitCursor(); updateLocal(bv, CURSOR_PAR|CURSOR, true); showInsetCursor(bv); if (clear) @@ -1568,6 +1607,10 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall, the_locking_inset->setFont(bv, font, toggleall, selectall); return; } + if ((!par->next() && !par->size()) || !cpar(bv)->size()) { + getLyXText(bv)->setFont(bv, font, toggleall); + return; + } bool clear = false; if (!lt) { lt = getLyXText(bv); @@ -1578,14 +1621,10 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall, } if (selectall) selectAll(bv); -#if 1 lt->toggleFree(bv, font, toggleall); -#else - lt->setFont(bv, font, toggleall); -#endif if (selectall) lt->clearSelection(); - bv->fitCursor(lt); + bv->fitCursor(); if (selectall || lt->selection.set()) updateLocal(bv, FULL, true); else @@ -1662,7 +1701,6 @@ int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const } w -= (2 * TEXT_TO_INSET_OFFSET); return w - top_x; -// return w - (2*TEXT_TO_INSET_OFFSET); } @@ -1878,7 +1916,7 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const if (!owner()) updateLocal(bv, FULL, false); else - need_update = FULL; + need_update |= FULL; // this will scroll the screen such that the cursor becomes visible bv->updateScrollbar(); } @@ -1968,7 +2006,7 @@ void InsetText::clearSelection(BufferView * bv) void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const { - int w = insetWidth; + int w = insetWidth; int h = insetAscent + insetDescent; int ty = baseline - insetAscent; @@ -1980,15 +2018,17 @@ void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const h = pain.paperHeight(); if ((top_x + drawTextXOffset + w) > pain.paperWidth()) w = pain.paperWidth(); - pain.fillRectangle(top_x+drawTextXOffset, ty, w, h, - backgroundColor()); +// w -= TEXT_TO_INSET_OFFSET; + pain.fillRectangle(top_x, ty, w+1, h+1, backgroundColor()); cleared = true; need_update = FULL; + frame_is_visible = false; } Paragraph * InsetText::getParFromID(int id) const { +#if 0 Paragraph * result = par; Paragraph * ires = 0; while (result && result->id() != id) { @@ -1997,6 +2037,22 @@ Paragraph * InsetText::getParFromID(int id) const result = result->next(); } return result; +#else + Paragraph * tmp = par; + while (tmp) { + int tmp_id = tmp->id(); + lyxerr << "Looking at paragraph: " << tmp_id << endl; + if (tmp->id() == id) { + return tmp; + } + Paragraph * tmp2 = tmp->getParFromID(id); + if (tmp2 != 0) { + return tmp2; + } + tmp = tmp->next(); + } + return 0; +#endif }