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<Buffer*>(buf)->insertErtContents(par, pos, font, false);
#endif
break;
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);
}
// 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)) {
- int old_x = top_x;
top_x = int(x);
int nw = getMaxWidth(bv, this);
if (nw > 0 && old_max_width != nw) {
} else {
top_x = old_x;
}
- // dummy calls so that the values are again right
- (void)ascent(bv, f);
- (void)descent(bv, f);
- (void)width(bv, f);
}
// 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 !!!
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;
}
(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;
-
-// lyxerr << "InsetText::draw[" << this << "](" << need_update << ":" << int(x) << ":" << top_x << ")\n";
-
- if (cleared || (last_drawn_width != insetWidth)) {
- need_update |= FULL;
- last_drawn_width = insetWidth;
}
top_baseline = baseline;
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;
+ }
+
if (the_locking_inset && (cpar(bv) == inset_par)
&& (cpos(bv) == inset_pos)) {
inset_x = cx(bv) - top_x + drawTextXOffset;
if (y_offset < 0)
y_offset = y;
lt->first = first;
- if (cleared || (need_update&=(INIT|FULL))) {
+ if (cleared || (need_update&(INIT|FULL))) {
int yf = y_offset;
y = 0;
while ((row != 0) && (yf < ph)) {
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 = last_width; // - 2;
- frame_h = insetAscent + insetDescent; // - 2;
+ 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;
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();
}
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<InsetText *>(this), mark_dirty);
}
+ if (need_update == CURSOR)
+ need_update = NONE;
bv->owner()->showState();
if (old_par != cpar(bv)) {
bv->owner()->setLayout(cpar(bv)->getLayout());
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();
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) {
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
localDispatch(bv, LFUN_PASTESELECTION,
"paragraph");
}
+ if (clear)
+ lt = 0;
}
showInsetCursor(bv);
no_selection = false;
void InsetText::clearInset(Painter & pain, int baseline, bool & cleared) const
{
- int w = insetWidth;
+ int w = insetWidth;
int h = insetAscent + insetDescent;
int ty = baseline - insetAscent;
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) {
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
}