/* This file is part of
* ======================================================
- *
+ *
* LyX, The Document Processor
*
* Copyright 1998-2001 The LyX Team.
#include "lyxfind.h"
#include "frontends/Alert.h"
+#include "frontends/Dialogs.h"
#include "support/textutils.h"
#include "support/LAssert.h"
break;
p = p->next();
}
-
+
if (p && t->cursor.pos() <= p->size()) {
sstate.lpar = t->cursor.par();
sstate.pos = t->cursor.pos();
t->selection.mark(sstate.mark_set);
if (sstate.selection) {
t->setCursor(bv, sstate.selstartpar, sstate.selstartpos,
- true, sstate.selstartboundary);
+ true, sstate.selstartboundary);
t->selection.cursor = t->cursor;
t->setCursor(bv, sstate.selendpar, sstate.selendpos,
- true, sstate.selendboundary);
+ true, sstate.selendboundary);
t->setSelection(bv);
t->setCursor(bv, sstate.lpar, sstate.pos);
} else {
{
par = new Paragraph;
par->layout(textclasslist[bp.textclass].defaultLayoutName());
-
+
init();
}
insetDescent = 0;
insetWidth = 0;
old_max_width = 0;
- no_selection = false;
+ no_selection = true;
need_update = FULL;
drawTextXOffset = 0;
drawTextYOffset = 0;
cached_bview = 0;
// NOTE
-
+
while (par) {
Paragraph * tmp = par->next();
delete par;
{
// This is a gross hack...
string old_layout = par->layout();
-
+
while (par) {
Paragraph * tmp = par->next();
delete par;
par = new Paragraph;
par->setInsetOwner(this);
par->layout(old_layout);
-
+
reinitLyXText();
need_update = INIT;
}
string token;
int pos = 0;
Paragraph * return_par = 0;
- Paragraph::depth_type depth = 0;
+ Paragraph::depth_type depth = 0;
LyXFont font(LyXFont::ALL_INHERIT);
clear();
-
+
while (lex.isOK()) {
lex.nextToken();
token = lex.getString();
#endif
break;
}
-
+
if (const_cast<Buffer*>(buf)->
parseSingleLyXformat2Token(lex, par, return_par,
token, pos, depth, font)) {
return_par->setInsetOwner(this);
return_par = return_par->next();
}
-
+
if (token != "\\end_inset") {
lex.printError("Missing \\end_inset at this point. "
"Read: `$$Token'");
}
if (fordraw) {
return max(w - (2 * TEXT_TO_INSET_OFFSET),
- (int)getLyXText(bv)->width);
+ (int)getLyXText(bv)->width);
} else if (w < 0) {
return -1;
}
void InsetText::draw(BufferView * bv, LyXFont const & f,
- int baseline, float & x, bool cleared) const
+ int baseline, float & x, bool cleared) const
{
if (nodraw())
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
}
// call these methods so that insetWidth, insetAscent and
- // insetDescent have the right values.
+ // insetDescent have the right values.
width(bv, f);
ascent(bv, f);
descent(bv, f);
top_y = baseline - insetAscent;
if (last_drawn_width != insetWidth) {
- if (!cleared)
+ if (!cleared)
clearInset(bv, 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;
- inset_y = cy(bv) + drawTextYOffset;
+ inset_x = cix(bv) - top_x + drawTextXOffset;
+ inset_y = ciy(bv) + drawTextYOffset;
}
if (!cleared && (need_update == CURSOR)
&& !getLyXText(bv)->selection.set()) {
drawFrame(pain, cleared);
- x += insetWidth;
+ x += insetWidth;
need_update = NONE;
return;
}
first += row->height();
row = row->next();
}
- if (y_offset < 0)
- y_offset = y;
- lt->first_y = first;
+ if (y_offset < 0) {
+ lt->first_y = -y_offset;
+ first = y;
+ y_offset = 0;
+ } else {
+ lt->first_y = first;
+ first = 0;
+ }
if (cleared || (need_update&(INIT|FULL))) {
- int yf = y_offset;
+ int yf = y_offset + first;
y = 0;
while ((row != 0) && (yf < ph)) {
- lt->getVisibleRow(bv, y+y_offset, int(x), row,
- y+first, cleared);
+ lt->getVisibleRow(bv, y + y_offset + first, int(x),
+ row, y + lt->first_y, cleared);
+ if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
+ lt->need_break_row = row;
+ lt->fullRebreak(bv);
+ lt->setCursor(bv, lt->cursor.par(),
+ lt->cursor.pos());
+ if (lt->selection.set()) {
+ lt->setCursor(bv, lt->selection.start,
+ lt->selection.start.par(),
+ lt->selection.start.pos());
+ lt->setCursor(bv, lt->selection.end,
+ lt->selection.end.par(),
+ lt->selection.end.pos());
+ }
+ break;
+ }
y += row->height();
yf += row->height();
row = row->next();
} else if (need_update & CLEAR_FRAME) {
clearFrame(pain, cleared);
}
-
+
x += insetWidth - TEXT_TO_INSET_OFFSET;
-
+
if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
need_update |= FULL;
} else if (need_update != INIT) {
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,
- frame_color);
+ frame_color);
frame_is_visible = true;
}
}
if (frame_is_visible) {
if (!cleared) {
pain.rectangle(frame_x, frame_y, frame_w, frame_h,
- backgroundColor());
+ backgroundColor());
}
frame_is_visible = false;
}
in_update = false;
return;
}
+
+ if (!autoBreakRows && par->next())
+ collapseParagraphs(bv);
+
if (the_locking_inset) {
- inset_x = cx(bv) - top_x + drawTextXOffset;
- inset_y = cy(bv) + drawTextYOffset;
+ inset_x = cix(bv) - top_x + drawTextXOffset;
+ inset_y = ciy(bv) + drawTextYOffset;
the_locking_inset->update(bv, font, reinit);
}
{
// this does nothing dangerous so use only a localized buffer
LyXText * llt = getLyXText(bv);
-
+
need_update |= what;
// 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!
void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
{
if (!autoBreakRows && par->next())
- collapseParagraphs(bv->buffer()->params);
+ collapseParagraphs(bv);
bool clear = false;
if (!lt) {
lt = getLyXText(bv);
}
lt->fullRebreak(bv);
setUpdateStatus(bv, what);
- bool flag = (((need_update != CURSOR) && (need_update != NONE)) ||
- (lt->status() != LyXText::UNCHANGED) || lt->selection.set());
+ bool flag = mark_dirty ||
+ (((need_update != CURSOR) && (need_update != NONE)) ||
+ (lt->status() != LyXText::UNCHANGED) || lt->selection.set());
if (!lt->selection.set())
lt->selection.cursor = lt->cursor;
if (clear)
lt = 0;
+#if 0
+ // IMO this is not anymore needed as we do this in fitInsetCursor!
+ // and we always get "true" as returnvalue of this function in the
+ // case of a locking inset (Jug 20020412)
+ if (locked && (need_update & CURSOR) && bv->fitCursor())
+ need_update |= FULL;
+#else
+ bv->fitCursor();
+#endif
if (flag)
bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
- else
- bv->fitCursor();
-
+
if (need_update == CURSOR)
need_update = NONE;
bv->owner()->showState();
void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
{
UpdatableInset::edit(bv, x, y, button);
-
+
if (!bv->lockInset(this)) {
lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
return;
lt = getLyXText(bv);
clear = true;
}
- if (!checkAndActivateInset(bv, x, tmp_y, button))
+ // we put here -1 and not button as now the button in the
+ // edit call should not be needed we will fix this in 1.3.x
+ // cycle hopefully (Jug 20020509)
+ if (!checkAndActivateInset(bv, x, tmp_y, -1)) {
lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
- y + insetAscent);
+ y + insetAscent);
+ lt->cursor.x_fix(lt->cursor.x());
+ }
lt->clearSelection();
finishUndo();
// If the inset is empty set the language of the current font to the
font.setLanguage(bv->getParentLanguage(this));
setFont(bv, font, false);
}
-// showInsetCursor(bv);
if (clear)
lt = 0;
-
+
int code = CURSOR;
if (drawFrame_ == LOCKED)
code = CURSOR|DRAW_FRAME;
updateLocal(bv, code, false);
+ showInsetCursor(bv);
+
+ // Tell the paragraph dialog that we've entered an insettext.
+ bv->owner()->getDialogs()->updateParagraph();
}
void InsetText::edit(BufferView * bv, bool front)
{
UpdatableInset::edit(bv, front);
-
+
if (!bv->lockInset(this)) {
lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
return;
font.setLanguage(bv->getParentLanguage(this));
setFont(bv, font, false);
}
-// showInsetCursor(bv);
if (clear)
lt = 0;
int code = CURSOR;
if (drawFrame_ == LOCKED)
code = CURSOR|DRAW_FRAME;
updateLocal(bv, code, false);
+ showInsetCursor(bv);
}
if (the_locking_inset) {
the_locking_inset->insetUnlock(bv);
the_locking_inset = 0;
+ updateLocal(bv, CURSOR_PAR, false);
}
hideInsetCursor(bv);
- no_selection = false;
+ no_selection = true;
locked = false;
- int code;
+ int code = NONE;
+#if 0
if (drawFrame_ == LOCKED)
code = CURSOR|CLEAR_FRAME;
- else
+ else
code = CURSOR;
+#else
+ if (drawFrame_ == LOCKED)
+ code = CLEAR_FRAME;
+#endif
bool clear = false;
if (!lt) {
lt = getLyXText(bv);
code = FULL;
} else if (owner()) {
bv->owner()->setLayout(owner()->getLyXText(bv)
- ->cursor.par()->layout());
+ ->cursor.par()->layout());
} else
bv->owner()->setLayout(bv->text->cursor.par()->layout());
// hack for deleteEmptyParMech
}
if (clear)
lt = 0;
+#if 0
updateLocal(bv, code, false);
+#else
+ if (code != NONE)
+ setUpdateStatus(bv, code);
+#endif
}
+
+void InsetText::lockInset(BufferView * bv)
+{
+ locked = true;
+ the_locking_inset = 0;
+ inset_pos = inset_x = inset_y = 0;
+ inset_boundary = false;
+ inset_par = 0;
+ old_par = 0;
+ bool clear = false;
+ if (!lt) {
+ lt = getLyXText(bv);
+ clear = true;
+ }
+ lt->setCursor(bv, par, 0);
+ lt->clearSelection();
+ finishUndo();
+ // If the inset is empty set the language of the current font to the
+ // language to the surronding text (if different).
+ if (par->size() == 0 && !par->next() &&
+ bv->getParentLanguage(this) != lt->current_font.language()) {
+ LyXFont font(LyXFont::ALL_IGNORE);
+ font.setLanguage(bv->getParentLanguage(this));
+ setFont(bv, font, false);
+ }
+ if (clear)
+ lt = 0;
+ int code = CURSOR;
+ if (drawFrame_ == LOCKED)
+ code = CURSOR|DRAW_FRAME;
+ setUpdateStatus(bv, code);
+}
+
+
void InsetText::lockInset(BufferView * bv, UpdatableInset * inset)
{
the_locking_inset = inset;
- inset_x = cx(bv) - top_x + drawTextXOffset;
- inset_y = cy(bv) + drawTextYOffset;
+ inset_x = cix(bv) - top_x + drawTextXOffset;
+ inset_y = ciy(bv) + drawTextYOffset;
inset_pos = cpos(bv);
inset_par = cpar(bv);
inset_boundary = cboundary(bv);
} else if (the_locking_inset && (the_locking_inset == inset)) {
if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
lyxerr[Debug::INSETS] << "OK" << endl;
- inset_x = cx(bv) - top_x + drawTextXOffset;
- inset_y = cy(bv) + drawTextYOffset;
+ inset_x = cix(bv) - top_x + drawTextXOffset;
+ inset_y = ciy(bv) + drawTextYOffset;
} else {
lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
}
bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
- bool lr)
+ bool lr)
{
if (!the_locking_inset)
return false;
bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
{
if (!autoBreakRows && par->next())
- collapseParagraphs(bv->buffer()->params);
+ collapseParagraphs(bv);
if (inset == this)
return true;
bool clear = false;
if (the_locking_inset &&
cpar(bv) == inset_par && cpos(bv) == inset_pos)
{
- inset_x = cx(bv) - top_x + drawTextXOffset;
- inset_y = cy(bv) + drawTextYOffset;
+ inset_x = cix(bv) - top_x + drawTextXOffset;
+ inset_y = ciy(bv) + drawTextYOffset;
}
}
return found;
mouse_x = x;
mouse_y = y;
+ if (!locked)
+ lockInset(bv);
+
int tmp_x = x - drawTextXOffset;
int tmp_y = y + insetAscent - getLyXText(bv)->first_y;
Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y);
if (the_locking_inset) {
if (the_locking_inset == inset) {
the_locking_inset->insetButtonPress(bv,
- x - inset_x,
- y - inset_y,
- button);
- no_selection = false;
+ x - inset_x,
+ y - inset_y,
+ button);
return;
- } else if (inset) {
+ }
+#if 0
+ else if (inset) {
// otherwise unlock the_locking_inset and lock the new inset
the_locking_inset->insetUnlock(bv);
- inset_x = cx(bv) - top_x + drawTextXOffset;
- inset_y = cy(bv) + drawTextYOffset;
+ inset_x = cix(bv) - top_x + drawTextXOffset;
+ inset_y = ciy(bv) + drawTextYOffset;
the_locking_inset = 0;
inset->insetButtonPress(bv, x - inset_x,
- y - inset_y, button);
+ y - inset_y, button);
// inset->edit(bv, x - inset_x, y - inset_y, button);
if (the_locking_inset)
updateLocal(bv, CURSOR, false);
- no_selection = false;
return;
}
+#endif
// otherwise only unlock the_locking_inset
the_locking_inset->insetUnlock(bv);
the_locking_inset = 0;
}
+ if (!inset)
+ no_selection = false;
+
if (bv->theLockingInset()) {
if (isHighlyEditableInset(inset)) {
+ // We just have to lock the inset before calling a
+ // PressEvent on it!
UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
- inset_x = cx(bv) - top_x + drawTextXOffset;
- inset_y = cy(bv) + drawTextYOffset;
- inset_pos = cpos(bv);
- inset_par = cpar(bv);
- inset_boundary = cboundary(bv);
- the_locking_inset = uinset;
- uinset->insetButtonPress(bv, x - inset_x, y - inset_y,
- button);
- uinset->edit(bv, x - inset_x, y - inset_y, 0);
+ if (!bv->lockInset(uinset)) {
+ lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
+ }
+ inset->insetButtonPress(bv, x - inset_x, y - inset_y, button);
if (the_locking_inset)
updateLocal(bv, CURSOR, false);
- no_selection = false;
return;
}
}
lt = getLyXText(bv);
clear = true;
}
+ int old_first_y = lt->first_y;
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());
updateLocal(bv, CURSOR, false);
}
bv->owner()->setLayout(cpar(bv)->layout());
+ // we moved the view we cannot do mouse selection in this case!
+ if (getLyXText(bv)->first_y != old_first_y)
+ no_selection = true;
old_par = cpar(bv);
// Insert primary selection with middle mouse
// if there is a local selection in the current buffer,
localDispatch(bv, LFUN_PASTE, "");
else
localDispatch(bv, LFUN_PASTESELECTION,
- "paragraph");
+ "paragraph");
}
} else {
getLyXText(bv)->clearSelection();
}
showInsetCursor(bv);
- no_selection = false;
}
bool InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
{
+ no_selection = true;
if (the_locking_inset) {
return the_locking_inset->insetButtonRelease(bv,
- x - inset_x, y - inset_y,
- button);
+ x - inset_x, y - inset_y,
+ button);
}
int tmp_x = x - drawTextXOffset;
int tmp_y = y + insetAscent - getLyXText(bv)->first_y;
if (inset) {
if (isHighlyEditableInset(inset)) {
ret = inset->insetButtonRelease(bv, x - inset_x,
- y - inset_y, button);
+ y - inset_y, button);
} else {
- inset_x = cx(bv) - top_x + drawTextXOffset;
- inset_y = cy(bv) + drawTextYOffset;
+ inset_x = cix(bv) - top_x + drawTextXOffset;
+ inset_y = ciy(bv) + drawTextYOffset;
ret = inset->insetButtonRelease(bv, x - inset_x,
- y - inset_y, button);
+ y - inset_y, button);
inset->edit(bv, x - inset_x,
- y - inset_y, button);
+ y - inset_y, button);
}
updateLocal(bv, CURSOR_PAR, false);
}
void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state)
{
- if (no_selection || ((mouse_x == x) && (mouse_y == y)))
- return;
if (the_locking_inset) {
the_locking_inset->insetMotionNotify(bv, x - inset_x,
- y - inset_y,state);
+ y - inset_y,state);
return;
}
+
+ if (no_selection || ((mouse_x == x) && (mouse_y == y)))
+ return;
+
bool clear = false;
if (!lt) {
lt = getLyXText(bv);
hideInsetCursor(bv);
LyXCursor cur = lt->cursor;
lt->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent);
+ lt->cursor.x_fix(lt->cursor.x());
if (cur == lt->cursor) {
if (clear)
lt = 0;
UpdatableInset::RESULT
InsetText::localDispatch(BufferView * bv,
- kb_action action, string const & arg)
+ kb_action action, string const & arg)
{
bool was_empty = par->size() == 0 && !par->next();
no_selection = false;
#ifdef WITH_WARNINGS
#warning I changed this to always return Dispatched maybe it is wrong (20011001 Jug)
#endif
+ updateLocal(bv, CURSOR, false);
return result;
}
}
* true (on). */
setUndo(bv, Undo::INSERT,
- lt->cursor.par(), lt->cursor.par()->next());
+ lt->cursor.par(), lt->cursor.par()->next());
bv->setState();
if (lyxrc.auto_region_delete) {
if (lt->selection.set()) {
}
}
lt->selection.cursor = lt->cursor;
- updwhat = CURSOR_PAR;
+ updwhat = CURSOR | CURSOR_PAR;
updflag = true;
result = DISPATCHED_NOUPDATE;
break;
break;
case LFUN_BACKSPACE: {
setUndo(bv, Undo::DELETE,
- lt->cursor.par(), lt->cursor.par()->next());
+ lt->cursor.par(), lt->cursor.par()->next());
if (lt->selection.set())
lt->cutSelection(bv);
else
updflag = true;
}
break;
-
+
case LFUN_DELETE: {
setUndo(bv, Undo::DELETE,
- lt->cursor.par(), lt->cursor.par()->next());
+ lt->cursor.par(), lt->cursor.par()->next());
if (lt->selection.set()) {
lt->cutSelection(bv);
} else {
updflag = true;
}
break;
-
+
case LFUN_CUT: {
setUndo(bv, Undo::DELETE,
- lt->cursor.par(), lt->cursor.par()->next());
+ lt->cursor.par(), lt->cursor.par()->next());
lt->cutSelection(bv);
updwhat = CURSOR_PAR;
updflag = true;
case LFUN_PASTESELECTION:
{
string const clip(bv->getClipboard());
-
+
if (clip.empty())
break;
if (arg == "paragraph") {
} else {
lt->insertStringAsLines(bv, clip);
}
+ // bug 393
+ lt->clearSelection();
+
updwhat = CURSOR_PAR;
updflag = true;
break;
}
}
setUndo(bv, Undo::INSERT,
- lt->cursor.par(), lt->cursor.par()->next());
+ lt->cursor.par(), lt->cursor.par()->next());
lt->pasteSelection(bv);
+ // bug 393
+ lt->clearSelection();
updwhat = CURSOR_PAR;
updflag = true;
}
break;
}
lt->breakParagraph(bv, 0);
- updwhat = FULL;
+ updwhat = CURSOR | FULL;
updflag = true;
break;
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
break;
}
lt->breakParagraph(bv, 1);
- updwhat = FULL;
+ updwhat = CURSOR | FULL;
updflag = true;
break;
break;
}
setUndo(bv, Undo::INSERT,
- lt->cursor.par(), lt->cursor.par()->next());
+ lt->cursor.par(), lt->cursor.par()->next());
lt->insertChar(bv, Paragraph::META_NEWLINE);
- updwhat = CURSOR_PAR;
+ updwhat = CURSOR | CURSOR_PAR;
updflag = true;
}
break;
// do not set layouts on non breakable textinsets
if (autoBreakRows) {
string cur_layout = cpar(bv)->layout();
-
+
// Derive layout number from given argument (string)
- // and current buffer's textclass (number). */
+ // and current buffer's textclass (number). */
textclass_type tclass = bv->buffer()->params.textclass;
string layout = arg;
bool hasLayout = textclasslist[tclass].hasLayout(layout);
string const & obs =
textclasslist[tclass][layout].
obsoleted_by();
- if (!obs.empty())
+ if (!obs.empty())
layout = obs;
}
if (cur_spacing == Spacing::Other) {
cur_value = par->params().spacing().getValue();
}
-
+
istringstream istr(arg.c_str());
string tmp;
istr >> tmp;
}
}
break;
-
+
default:
if (!bv->Dispatch(action, arg))
result = UNDISPATCHED;
if (result >= FINISHED)
bv->unlockInset(this);
+
+ if (result == DISPATCHED_NOUPDATE && (need_update & FULL))
+ result = DISPATCHED;
return result;
}
-int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
+int InsetText::latex(Buffer const * buf, ostream & os, bool moving_arg, bool) const
{
TexRow texrow;
- buf->latexParagraphs(os, par, 0, texrow);
+ buf->latexParagraphs(os, par, 0, texrow, moving_arg);
return texrow.rows();
}
{
Paragraph * p = par;
unsigned int lines = 0;
-
+
while (p) {
string const tmp = buf->asciiParagraph(p, linelen, p->previous()==0);
lines += lyx::count(tmp.begin(), tmp.end(), '\n');
vector<string> environment_stack(10);
vector<string> environment_inner(10);
-
+
int const command_depth = 0;
string item_name;
-
+
Paragraph::depth_type depth = 0; // paragraph depth
while (p) {
depth + command_depth,
environment_inner[depth]);
}
-
+
buf->sgmlCloseTag(os, depth + command_depth,
environment_stack[depth]);
-
+
environment_stack[depth].erase();
environment_inner[depth].erase();
- }
+ }
// Write opening SGML tags.
switch (style.latextype) {
environment_inner[depth]);
}
}
-
+
if (style.latextype == LATEX_ENVIRONMENT) {
if (!style.latexparam().empty()) {
if (style.latexparam() == "CDATA")
item_name = "listitem";
buf->sgmlCloseTag(os, command_depth + depth,
item_name);
- if (environment_inner[depth] == "varlistentry")
+ if (environment_inner[depth] == "varlistentry")
buf->sgmlCloseTag(os, depth + command_depth,
environment_inner[depth]);
}
-
+
buf->sgmlCloseTag(os, depth + command_depth,
environment_stack[depth]);
}
}
-
+
return lines;
}
}
-void InsetText::getCursorPos(BufferView * bv,
- int & x, int & y) const
+void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const
{
if (the_locking_inset) {
the_locking_inset->getCursorPos(bv, x, y);
return;
}
- x = cx(bv);
- y = cy(bv);
+ x = cx(bv) - top_x - TEXT_TO_INSET_OFFSET;
+ y = cy(bv) - TEXT_TO_INSET_OFFSET;
}
-unsigned int InsetText::insetInInsetY()
+int InsetText::insetInInsetY() const
{
if (!the_locking_inset)
return 0;
int const asc = lyxfont::maxAscent(font);
int const desc = lyxfont::maxDescent(font);
-
+
if (isCursorVisible())
bv->hideLockedInsetCursor();
else
if (!isCursorVisible()) {
LyXFont const font =
getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
-
+
int const asc = lyxfont::maxAscent(font);
int const desc = lyxfont::maxDescent(font);
}
LyXFont const font =
getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
-
+
int const asc = lyxfont::maxAscent(font);
int const desc = lyxfont::maxDescent(font);
- bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
+ if (bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc))
+ need_update |= FULL;
}
InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
{
if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
- return moveLeftIntern(bv, false, activate_inset, selecting);
+ return moveLeftIntern(bv, true, activate_inset, selecting);
else
- return moveRightIntern(bv, false, activate_inset, selecting);
+ return moveRightIntern(bv, true, activate_inset, selecting);
}
InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
{
if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
- return moveRightIntern(bv, true, activate_inset, selecting);
+ return moveRightIntern(bv, false, activate_inset, selecting);
else
- return moveLeftIntern(bv, true, activate_inset, selecting);
+ return moveLeftIntern(bv, false, activate_inset, selecting);
}
UpdatableInset::RESULT
-InsetText::moveRightIntern(BufferView * bv, bool behind,
- bool activate_inset, bool selecting)
+InsetText::moveRightIntern(BufferView * bv, bool front,
+ bool activate_inset, bool selecting)
{
if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
return FINISHED_RIGHT;
- if (activate_inset && checkAndActivateInset(bv, behind))
+ if (activate_inset && checkAndActivateInset(bv, front))
return DISPATCHED;
getLyXText(bv)->cursorRight(bv);
if (!selecting)
UpdatableInset::RESULT
-InsetText::moveLeftIntern(BufferView * bv, bool behind,
- bool activate_inset, bool selecting)
+InsetText::moveLeftIntern(BufferView * bv, bool front,
+ bool activate_inset, bool selecting)
{
if (!cpar(bv)->previous() && (cpos(bv) <= 0))
return FINISHED;
getLyXText(bv)->cursorLeft(bv);
if (!selecting)
getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
- if (activate_inset && checkAndActivateInset(bv, behind))
+ if (activate_inset && checkAndActivateInset(bv, front))
return DISPATCHED;
return DISPATCHED_NOUPDATE;
}
return the_locking_inset->insertInset(bv, inset);
return false;
}
- bool clear = false;
- if (!lt) {
- lt = getLyXText(bv);
- clear = true;
- }
- setUndo(bv, Undo::FINISH, lt->cursor.par(), lt->cursor.par()->next());
- freezeUndo();
inset->setOwner(this);
hideInsetCursor(bv);
- lt->insertInset(bv, inset);
+ getLyXText(bv)->insertInset(bv, inset);
bv->fitCursor();
- if (clear)
- lt = 0;
updateLocal(bv, CURSOR_PAR|CURSOR, true);
- unFreezeUndo();
return true;
}
}
-vector<string> const InsetText::getLabelList() const
+vector<string> const InsetText::getLabelList() const
{
vector<string> label_list;
void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
- bool selectall)
+ bool selectall)
{
if (the_locking_inset) {
the_locking_inset->setFont(bv, font, toggleall, selectall);
}
-bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
+bool InsetText::checkAndActivateInset(BufferView * bv, bool front)
{
if (cpar(bv)->isInset(cpos(bv))) {
- unsigned int x;
- unsigned int y;
Inset * inset =
static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
if (!isHighlyEditableInset(inset))
return false;
- LyXFont const font =
- getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
- if (behind) {
- x = inset->width(bv, font);
- y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
- } else {
- x = 0;
- y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
- }
- //inset_x = cx(bv) - top_x + drawTextXOffset;
- //inset_y = cy(bv) + drawTextYOffset;
- inset->edit(bv, x, y, 0);
+ inset->edit(bv, front);
if (!the_locking_inset)
return false;
updateLocal(bv, CURSOR, false);
int dummyx = x;
int dummyy = y + insetAscent;
Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy);
-
+ // we only do the edit() call if the inset was hit by the mouse
+ // or if it is a highly editable inset. So we should call this
+ // function from our own edit with button < 0.
+ if (button < 0 && !isHighlyEditableInset(inset))
+ return false;
+
if (inset) {
if (x < 0)
x = insetWidth;
if (y < 0)
y = insetDescent;
- inset_x = cx(bv) - top_x + drawTextXOffset;
- inset_y = cy(bv) + drawTextYOffset;
+ inset_x = cix(bv) - top_x + drawTextXOffset;
+ inset_y = ciy(bv) + drawTextYOffset;
inset->edit(bv, x - inset_x, y - inset_y, button);
if (!the_locking_inset)
return false;
}
-void InsetText::setText(string const & data)
+void InsetText::setText(string const & data, LyXFont const & font)
{
clear();
- LyXFont font(LyXFont::ALL_SANE);
for (unsigned int i=0; i < data.length(); ++i)
par->insertChar(i, data[i], font);
+ reinitLyXText();
}
int x = llt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
if (the_locking_inset) {
LyXFont font = llt->getFont(bv->buffer(), llt->cursor.par(),
- llt->cursor.pos());
+ llt->cursor.pos());
+ if (font.isVisibleRightToLeft())
+ x -= the_locking_inset->width(bv, font);
+ }
+ return x;
+}
+
+
+int InsetText::cix(BufferView * bv) const
+{
+ // we do nothing dangerous so we use a local cache
+ LyXText * llt = getLyXText(bv);
+ int x = llt->cursor.ix() + top_x + TEXT_TO_INSET_OFFSET;
+ if (the_locking_inset) {
+ LyXFont font = llt->getFont(bv->buffer(), llt->cursor.par(),
+ llt->cursor.pos());
if (font.isVisibleRightToLeft())
x -= the_locking_inset->width(bv, font);
}
}
+int InsetText::ciy(BufferView * bv) const
+{
+ LyXFont font;
+ return getLyXText(bv)->cursor.iy() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
+}
+
+
pos_type InsetText::cpos(BufferView * bv) const
{
return getLyXText(bv)->cursor.pos();
LyXText * InsetText::getLyXText(BufferView const * lbv,
- bool const recursive) const
+ bool const recursive) const
{
if (cached_bview == lbv) {
if (recursive && the_locking_inset)
}
// Super UGLY! (Lgb)
BufferView * bv = const_cast<BufferView *>(lbv);
-
+
cached_bview = bv;
Cache::iterator it = cache.find(bv);
restoreLyXTextState(bv, cached_text.get());
cache.insert(make_pair(bv, cached_text));
-
+
if (the_locking_inset && recursive) {
return the_locking_inset->getLyXText(bv);
}
cached_bview = 0;
Cache::iterator it = cache.find(bv);
-
+
if (it == cache.end()) {
return;
}
t->init(bv, true);
restoreLyXTextState(bv, t);
if (the_locking_inset) {
- inset_x = cx(bv) - top_x + drawTextXOffset;
- inset_y = cy(bv) + drawTextYOffset;
+ inset_x = cix(bv) - top_x + drawTextXOffset;
+ inset_y = ciy(bv) + drawTextYOffset;
}
if (bv->screen()) {
}
if (!owner()) {
updateLocal(bv, FULL, false);
- // this will scroll the screen such that the cursor becomes visible
+ // this will scroll the screen such that the cursor becomes visible
bv->updateScrollbar();
} else {
need_update |= FULL;
t->init(bv, true);
restoreLyXTextState(bv, t);
if (the_locking_inset) {
- inset_x = cx(bv) - top_x + drawTextXOffset;
- inset_y = cy(bv) + drawTextYOffset;
+ inset_x = cix(bv) - top_x + drawTextXOffset;
+ inset_y = ciy(bv) + drawTextYOffset;
}
if (bv->screen()) {
t->first_y = bv->screen()->topCursorVisible(t);
}
if (!owner()) {
updateLocal(bv, FULL, false);
- // this will scroll the screen such that the cursor becomes visible
+ // this will scroll the screen such that the cursor becomes visible
bv->updateScrollbar();
} else {
need_update = FULL;
void InsetText::removeNewlines()
{
bool changed = false;
-
+
for (Paragraph * p = par; p; p = p->next()) {
for (int i = 0; i < p->size(); ++i) {
if (p->getChar(i) == Paragraph::META_NEWLINE) {
int w = insetWidth;
int h = insetAscent + insetDescent;
int ty = baseline - insetAscent;
-
+
if (ty < 0) {
h += ty;
ty = 0;
}
if (y_offset < 0)
y_offset = y;
-
+
if (need_update & SELECTION)
need_update = NONE;
bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
bool InsetText::searchForward(BufferView * bv, string const & str,
- bool cs, bool mw)
+ bool cs, bool mw)
{
if (the_locking_inset) {
if (the_locking_inset->searchForward(bv, str, cs, mw))
}
bool InsetText::searchBackward(BufferView * bv, string const & str,
- bool cs, bool mw)
+ bool cs, bool mw)
{
if (the_locking_inset)
if (the_locking_inset->searchBackward(bv, str, cs, mw))
}
-void InsetText::collapseParagraphs(BufferParams const & bparams) const
+void InsetText::collapseParagraphs(BufferView * bv) const
{
+ BufferParams const & bparams = bv->buffer()->params;
+ LyXText * llt = getLyXText(bv);
+
while(par->next()) {
- if (!par->isSeparator(par->size()-1))
- par->insertChar(par->size()-1, ' ');
+ if (par->size() && par->next()->size() &&
+ !par->isSeparator(par->size()-1))
+ {
+ par->insertChar(par->size(), ' ');
+ }
+ if (llt->selection.set()) {
+ if (llt->selection.start.par() == par->next()) {
+ llt->selection.start.par(par);
+ llt->selection.start.pos(
+ llt->selection.start.pos() + par->size());
+ }
+ if (llt->selection.end.par() == par->next()) {
+ llt->selection.end.par(par);
+ llt->selection.end.pos(
+ llt->selection.end.pos() + par->size());
+ }
+ }
par->pasteParagraph(bparams);
}
reinitLyXText();
void InsetText::appendParagraphs(BufferParams const & bparams,
- Paragraph * newpar)
+ Paragraph * newpar)
{
Paragraph * buf;
Paragraph * tmpbuf = newpar;
Paragraph * lastbuffer = buf = new Paragraph(*tmpbuf, false);
-
+
while (tmpbuf->next()) {
tmpbuf = tmpbuf->next();
lastbuffer->next(new Paragraph(*tmpbuf, false));
{
lastbuffer->insertChar(lastbuffer->size(), ' ');
}
-
+
// make the buf exactly the same layout than our last paragraph
buf->makeSameLayout(lastbuffer);