X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsettext.C;h=8889f2869eaf74df095728353ab3e7f85d664d23;hb=4a5b7a5952ad2381fcdf4830511293e184c7c5a1;hp=ba4966ab23669fbd144e314f362c82b38cd1e52b;hpb=de78a7b2d67e90c70ecb23984d3298c385faa65d;p=lyx.git diff --git a/src/insets/insettext.C b/src/insets/insettext.C index ba4966ab23..8889f2869e 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -48,6 +48,7 @@ #include "support/textutils.h" #include "support/LAssert.h" #include "support/lstrings.h" +#include "support/lyxalgo.h" // lyx::count #include #include @@ -61,6 +62,7 @@ using std::min; using std::max; using std::make_pair; using std::vector; +using std::pair; using lyx::pos_type; using lyx::layout_type; @@ -262,7 +264,7 @@ void InsetText::read(Buffer const * buf, LyXLex & lex) continue; if (token == "\\end_inset") { #ifndef NO_COMPABILITY - const_cast(buf)->insertErtContents(par, pos, font, false); + const_cast(buf)->insertErtContents(par, pos, false); #endif break; } @@ -349,29 +351,29 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, int old_x = top_x; if (top_x != int(x)) { top_x = int(x); + topx_set = true; 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); - topx_set = true; return; - } else { - top_x = old_x; } } + // call these methods so that insetWidth, insetAscent and + // insetDescent have the right values. + width(bv, f); + ascent(bv, f); + descent(bv, f); + // repaint the background if needed if (cleared && backgroundColor() != LColor::background) { - top_x = int(x); clearInset(bv, baseline, cleared); - top_x = old_x; } // no draw is necessary !!! if ((drawFrame_ == LOCKED) && !locked && !par->size()) { - top_x = int(x); - topx_set = true; top_baseline = baseline; x += width(bv, f); if (need_update & CLEAR_FRAME) @@ -385,14 +387,15 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, x += static_cast(scroll()); // if top_x differs we did it already - if (!cleared && (top_x == int(x)) + if (!cleared && (old_x == int(x)) && ((need_update&(INIT|FULL)) || (top_baseline != baseline) - ||(last_drawn_width != insetWidth))) { - clearInset(bv, baseline, cleared); + ||(last_drawn_width != insetWidth))) + { + // Condition necessary to eliminate bug 59 attachment 37 + if (baseline > 0) + clearInset(bv, baseline, cleared); } - top_x = int(x); - topx_set = true; if (cleared) frame_is_visible = false; @@ -402,12 +405,6 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, return; } - // call these methods so that insetWidth, insetAscent and - // insetDescent have the right values. - width(bv, f); - ascent(bv, f); - descent(bv, f); - top_baseline = baseline; top_y = baseline - insetAscent; @@ -509,8 +506,7 @@ void InsetText::drawFrame(Painter & pain, bool cleared) const frame_y = top_baseline - insetAscent + ttoD2; frame_w = insetWidth - TEXT_TO_INSET_OFFSET; frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET; - pain.rectangle(frame_x, frame_y, - frame_w, frame_h, + pain.rectangle(frame_x, frame_y, frame_w, frame_h, frame_color); frame_is_visible = true; } @@ -615,9 +611,14 @@ void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const lt = 0; if (flag) bv->updateInset(const_cast(this), mark_dirty); + else + bv->fitCursor(); + if (need_update == CURSOR) need_update = NONE; bv->owner()->showState(); + bv->owner()->updateMenubar(); + bv->owner()->updateToolbar(); if (old_par != cpar(bv)) { bv->owner()->setLayout(cpar(bv)->getLayout()); old_par = cpar(bv); @@ -668,7 +669,11 @@ void InsetText::edit(BufferView * bv, int x, int y, unsigned int button) showInsetCursor(bv); if (clear) lt = 0; - updateLocal(bv, CURSOR, false); + + int code = CURSOR; + if (drawFrame_ == LOCKED) + code = CURSOR|DRAW_FRAME; + updateLocal(bv, code, false); } @@ -713,7 +718,10 @@ void InsetText::edit(BufferView * bv, bool front) showInsetCursor(bv); if (clear) lt = 0; - updateLocal(bv, CURSOR, false); + int code = CURSOR; + if (drawFrame_ == LOCKED) + code = CURSOR|DRAW_FRAME; + updateLocal(bv, code, false); } @@ -785,7 +793,7 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset) } if ((*it)->getInsetFromID(id)) { getLyXText(bv)->setCursorIntern(bv, p, it.getPos()); - lockInset(bv, static_cast(*it)); + (*it)->edit(bv); return the_locking_inset->lockInsetInInset(bv, inset); } } @@ -903,7 +911,7 @@ void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button) the_locking_inset->insetUnlock(bv); inset_x = cx(bv) - top_x + drawTextXOffset; inset_y = cy(bv) + drawTextYOffset; - the_locking_inset = static_cast(inset); + the_locking_inset = 0; inset->insetButtonPress(bv, x - inset_x, y - inset_y, button); inset->edit(bv, x - inset_x, y - inset_y, button); @@ -947,7 +955,7 @@ void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button) } lt->setCursorFromCoordinates(bv, x - drawTextXOffset, - y + insetAscent); + y + insetAscent); // set the selection cursor! lt->selection.cursor = lt->cursor; lt->cursor.x_fix(lt->cursor.x()); @@ -961,6 +969,7 @@ void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button) lt->clearSelection(); if (clear) lt = 0; + updateLocal(bv, CURSOR, false); } bv->owner()->setLayout(cpar(bv)->getLayout()); old_par = cpar(bv); @@ -1078,7 +1087,7 @@ InsetText::localDispatch(BufferView * bv, updateLocal(bv, CURSOR_PAR, false); return result; } else if (result >= FINISHED) { - switch(result) { + switch (result) { case FINISHED_RIGHT: moveRightIntern(bv, false, false); result = DISPATCHED; @@ -1312,7 +1321,7 @@ InsetText::localDispatch(BufferView * bv, // Derive layout number from given argument (string) // and current buffer's textclass (number). */ textclass_type tclass = bv->buffer()->params.textclass; - std::pair layout = + pair layout = textclasslist.NumberOfLayout(tclass, arg); // If the entry is obsolete, use the new one instead. @@ -1430,7 +1439,7 @@ int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const while (p) { string const tmp = buf->asciiParagraph(p, linelen, p->previous()==0); - lines += countChar(tmp, '\n'); + lines += lyx::count(tmp.begin(), tmp.end(), '\n'); os << tmp; p = p->next(); } @@ -1516,7 +1525,7 @@ int InsetText::docbook(Buffer const * buf, ostream & os) const } if (environment_stack[depth] != style.latexname()) { - if(environment_stack.size() == depth + 1) { + if (environment_stack.size() == depth + 1) { environment_stack.push_back("!-- --"); environment_inner.push_back("!-- --"); } @@ -1539,7 +1548,7 @@ int InsetText::docbook(Buffer const * buf, ostream & os) const if (style.latextype == LATEX_ENVIRONMENT) { if (!style.latexparam().empty()) { - if(style.latexparam() == "CDATA") + if (style.latexparam() == "CDATA") os << "sgmlOpenTag(os, depth + command_depth, @@ -1583,7 +1592,7 @@ int InsetText::docbook(Buffer const * buf, ostream & os) const switch (style.latextype) { case LATEX_ENVIRONMENT: if (!style.latexparam().empty()) { - if(style.latexparam() == "CDATA") + if (style.latexparam() == "CDATA") os << "]]>"; else buf->sgmlCloseTag(os, depth + command_depth, @@ -1874,16 +1883,16 @@ bool InsetText::showInsetDialog(BufferView * bv) const } -std::vector const InsetText::getLabelList() const +vector const InsetText::getLabelList() const { - std::vector label_list; + vector label_list; Paragraph * tpar = par; while (tpar) { Paragraph::inset_iterator beg = tpar->inset_iterator_begin(); Paragraph::inset_iterator end = tpar->inset_iterator_end(); for (; beg != end; ++beg) { - std::vector const l = (*beg)->getLabelList(); + vector const l = (*beg)->getLabelList(); label_list.insert(label_list.end(), l.begin(), l.end()); } tpar = tpar->next(); @@ -2118,7 +2127,7 @@ LyXText * InsetText::getLyXText(BufferView const * lbv, if (!recursive && (cached_bview == lbv)) { LyXText * lt = cached_text.get(); lyx::Assert(lt && lt->firstRow()->par() == par); - return cached_text.get(); + return lt; } // Super UGLY! (Lgb) @@ -2128,26 +2137,41 @@ LyXText * InsetText::getLyXText(BufferView const * lbv, Cache::iterator it = cache.find(bv); if (it != cache.end()) { - if (do_reinit) + if (do_reinit) { reinitLyXText(); - else if (do_resize) + } else if (do_resize) { resizeLyXText(do_resize); - if (lt || !it->second.remove) { - lyx::Assert(it->second.text.get()); - cached_text = it->second.text; - if (recursive && the_locking_inset) { - return the_locking_inset->getLyXText(bv, true); - } - return cached_text.get(); - } else if (it->second.remove) { - if (locked) { - saveLyXTextState(it->second.text.get()); - } else { - sstate.lpar = 0; + } else { + if (lt || !it->second.remove) { + lyx::Assert(it->second.text.get()); + cached_text = it->second.text; + if (recursive && the_locking_inset) { + return the_locking_inset->getLyXText(bv, true); + } + return cached_text.get(); + } else if (it->second.remove) { + if (locked) { + saveLyXTextState(it->second.text.get()); + } else { + sstate.lpar = 0; + } } + // + // when we have to reinit the existing LyXText! + // + it->second.text->init(bv); + restoreLyXTextState(bv, it->second.text.get()); + it->second.remove = false; + } + cached_text = it->second.text; + if (the_locking_inset && recursive) { + return the_locking_inset->getLyXText(bv); } + return cached_text.get(); } - + /// + // we are here only if we don't have a BufferView * in the cache!!! + /// cached_text.reset(new LyXText(const_cast(this))); cached_text->init(bv); restoreLyXTextState(bv, cached_text.get()); @@ -2337,10 +2361,9 @@ void InsetText::clearSelection(BufferView * bv) void InsetText::clearInset(BufferView * bv, int baseline, bool & cleared) const { - LyXFont dummy; Painter & pain = bv->painter(); int w = insetWidth; - int h = ascent(bv, dummy) + descent(bv, dummy); + int h = insetAscent + insetDescent; int ty = baseline - insetAscent; if (ty < 0) { @@ -2478,9 +2501,7 @@ string const InsetText::selectNextWordToSpellcheck(BufferView * bv, float & valu lt = 0; return str; } -#warning Dekel please have a look on this one RTL? (Jug) -#warning DEKEL! - // we have to go on checking so move cusor to the right + // we have to go on checking so move cusor to the next char lt->cursor.pos(lt->cursor.pos() + 1); } str = lt->selectNextWordToSpellcheck(bv, value);