/* This file is part of
* ======================================================
- *
+ *
* LyX, The Document Processor
*
* Copyright 1998-2001 The LyX Team.
#include "intl.h"
#include "trans_mgr.h"
#include "lyxscreen.h"
-#include "WorkArea.h"
#include "gettext.h"
#include "lyxfunc.h"
#include "ParagraphParameters.h"
#include "lyxfind.h"
#include "frontends/Alert.h"
+#include "frontends/Dialogs.h"
#include "support/textutils.h"
#include "support/LAssert.h"
using std::pair;
using lyx::pos_type;
-using lyx::layout_type;
using lyx::textclass_type;
extern unsigned char getCurrentTextClass(Buffer *);
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 {
}
-InsetText::InsetText()
+InsetText::InsetText(BufferParams const & bp)
: UpdatableInset(), lt(0), in_update(false), do_resize(0),
do_reinit(false)
{
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;
void InsetText::clear()
{
+ // This is a gross hack...
+ string old_layout = par->layout();
+
while (par) {
Paragraph * tmp = par->next();
delete par;
par = tmp;
}
par = new Paragraph;
+ par->setInsetOwner(this);
+ par->layout(old_layout);
+
reinitLyXText();
need_update = INIT;
}
Inset * InsetText::clone(Buffer const &, bool same_id) const
{
- return new InsetText(*this, same_id);
+ return new InsetText(*this, same_id);
}
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 (!cleared && (need_update == CURSOR)
&& !getLyXText(bv)->selection.set()) {
drawFrame(pain, cleared);
- x += insetWidth;
+ x += insetWidth;
need_update = NONE;
return;
}
}
if (y_offset < 0)
y_offset = y;
- lt->first = first;
+ lt->first_y = first;
if (cleared || (need_update&(INIT|FULL))) {
int yf = y_offset;
y = 0;
while ((row != 0) && (yf < ph)) {
lt->getVisibleRow(bv, y+y_offset, int(x), row,
- y+first, cleared);
+ y+first, cleared);
y += row->height();
yf += row->height();
row = row->next();
lt->refresh_y = 0;
lt->status(bv, LyXText::UNCHANGED);
- if ((need_update != CURSOR_PAR) &&
- ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked))) {
+ if ((drawFrame_ == ALWAYS) ||
+ ((cleared || (need_update != CURSOR_PAR)) &&
+ (drawFrame_ == LOCKED) && locked))
+ {
drawFrame(pain, cleared);
} 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->buffer()->params);
+
if (the_locking_inset) {
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_y = cy(bv) + drawTextYOffset;
{
// 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!
}
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 (locked && (need_update & CURSOR) && bv->fitCursor())
+ need_update |= FULL;
if (flag)
bv->updateInset(const_cast<InsetText *>(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());
+ bv->owner()->setLayout(cpar(bv)->layout());
old_par = cpar(bv);
}
}
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;
}
if (!checkAndActivateInset(bv, x, tmp_y, button))
lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
- y + insetAscent);
+ y + insetAscent);
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);
}
the_locking_inset = 0;
}
hideInsetCursor(bv);
- no_selection = false;
+ no_selection = true;
locked = false;
int code;
if (drawFrame_ == LOCKED)
code = CURSOR|CLEAR_FRAME;
- else
+ else
code = CURSOR;
bool clear = false;
if (!lt) {
code = FULL;
} else if (owner()) {
bv->owner()->setLayout(owner()->getLyXText(bv)
- ->cursor.par()->getLayout());
+ ->cursor.par()->layout());
} else
- bv->owner()->setLayout(bv->text->cursor.par()->getLayout());
+ bv->owner()->setLayout(bv->text->cursor.par()->layout());
// hack for deleteEmptyParMech
if (par->size()) {
lt->setCursor(bv, par, 0);
bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
- bool lr)
+ bool lr)
{
if (!the_locking_inset)
return false;
lt = getLyXText(bv);
clear = true;
}
- if (!the_locking_inset) {
- bool found = lt->updateInset(bv, inset);
- if (clear)
- lt = 0;
+ if (inset->owner() != this) {
+ int ustat = CURSOR_PAR;
+ bool found = false;
+ UpdatableInset * tl_inset = the_locking_inset;
+ if (tl_inset)
+ found = tl_inset->updateInsetInInset(bv, inset);
+ if (!found) {
+ tl_inset = static_cast<UpdatableInset *>(inset);
+ while(tl_inset->owner() && tl_inset->owner() != this)
+ tl_inset = static_cast<UpdatableInset *>(tl_inset->owner());
+ if (!tl_inset->owner())
+ return false;
+ found = tl_inset->updateInsetInInset(bv, inset);
+ ustat = FULL;
+ }
if (found)
- setUpdateStatus(bv, NONE);
- return found;
- }
- if (the_locking_inset != inset) {
- bool found = the_locking_inset->updateInsetInInset(bv, inset);
+ lt->updateInset(bv, tl_inset);
if (clear)
lt = 0;
if (found)
- setUpdateStatus(bv, CURSOR_PAR);
+ setUpdateStatus(bv, ustat);
return found;
}
bool found = lt->updateInset(bv, inset);
lt = 0;
if (found) {
setUpdateStatus(bv, CURSOR_PAR);
- if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
+ if (the_locking_inset &&
+ cpar(bv) == inset_par && cpos(bv) == inset_pos)
+ {
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_y = cy(bv) + drawTextYOffset;
}
mouse_y = y;
int tmp_x = x - drawTextXOffset;
- int tmp_y = y + insetAscent - getLyXText(bv)->first;
+ int tmp_y = y + insetAscent - getLyXText(bv)->first_y;
Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y);
hideInsetCursor(bv);
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) {
// otherwise unlock the_locking_inset and lock the new inset
inset_y = cy(bv) + drawTextYOffset;
the_locking_inset = 0;
inset->insetButtonPress(bv, x - inset_x,
- y - inset_y, button);
- inset->edit(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;
}
// 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)) {
UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
inset_boundary = cboundary(bv);
the_locking_inset = uinset;
uinset->insetButtonPress(bv, x - inset_x, y - inset_y,
- button);
+ button);
uinset->edit(bv, x - inset_x, y - inset_y, 0);
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());
lt = 0;
updateLocal(bv, CURSOR, false);
}
- bv->owner()->setLayout(cpar(bv)->getLayout());
+ 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;
+ int tmp_y = y + insetAscent - getLyXText(bv)->first_y;
Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y);
bool ret = false;
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;
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);
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()) {
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") {
}
}
setUndo(bv, Undo::INSERT,
- lt->cursor.par(), lt->cursor.par()->next());
+ lt->cursor.par(), lt->cursor.par()->next());
lt->pasteSelection(bv);
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;
case LFUN_LAYOUT:
// do not set layouts on non breakable textinsets
if (autoBreakRows) {
- layout_type cur_layout = cpar(bv)->layout;
-
+ 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;
- pair<bool, layout_type> layout =
- textclasslist.NumberOfLayout(tclass, arg);
+ string layout = arg;
+ bool hasLayout = textclasslist[tclass].hasLayout(layout);
// If the entry is obsolete, use the new one instead.
- if (layout.first) {
- string obs = textclasslist.Style(tclass,layout.second).
+ if (hasLayout) {
+ string const & obs =
+ textclasslist[tclass][layout].
obsoleted_by();
- if (!obs.empty())
- layout = textclasslist.NumberOfLayout(tclass, obs);
+ if (!obs.empty())
+ layout = obs;
}
// see if we found the layout number:
- if (!layout.first) {
+ if (!hasLayout) {
string const msg = string(N_("Layout ")) + arg + N_(" not known");
bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
break;
}
- if (cur_layout != layout.second) {
- cur_layout = layout.second;
- lt->setLayout(bv, layout.second);
- bv->owner()->setLayout(cpar(bv)->getLayout());
+ if (cur_layout != layout) {
+ cur_layout = layout;
+ lt->setLayout(bv, layout);
+ bv->owner()->setLayout(cpar(bv)->layout());
updwhat = CURSOR_PAR;
updflag = true;
}
} else {
// reset the layout box
- bv->owner()->setLayout(cpar(bv)->getLayout());
+ bv->owner()->setLayout(cpar(bv)->layout());
}
break;
case LFUN_PARAGRAPH_SPACING:
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;
setFont(bv, font, false);
}
- if (result < FINISHED) {
- showInsetCursor(bv);
- } else
+ if (result >= FINISHED)
bv->unlockInset(this);
+
+ if (result == DISPATCHED_NOUPDATE && (need_update & FULL))
+ result = DISPATCHED;
return result;
}
{
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) {
int desc_on = 0; // description mode
LyXLayout const & style =
- textclasslist.Style(buf->params.textclass,
- p->layout);
+ textclasslist[buf->params.textclass][p->layout()];
// environment tag closing
for (; depth > p->params().depth(); --depth) {
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;
}
int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
{
- if (textclasslist.Style(buf->params.textclass,
- p->getLayout()).labeltype != LABEL_MANUAL)
+ if (textclasslist[buf->params.textclass][p->layout()].labeltype != LABEL_MANUAL)
return 0;
else
return p->beginningOfMainBody();
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;
}
UpdatableInset::RESULT
-InsetText::moveRightIntern(BufferView * bv, bool behind,
- bool activate_inset, bool selecting)
+InsetText::moveRightIntern(BufferView * bv, bool behind,
+ bool activate_inset, bool selecting)
{
if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
return FINISHED_RIGHT;
UpdatableInset::RESULT
InsetText::moveLeftIntern(BufferView * bv, bool behind,
- bool activate_inset, bool selecting)
+ bool activate_inset, bool selecting)
{
if (!cpar(bv)->previous() && (cpos(bv) <= 0))
return FINISHED;
}
-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);
}
-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);
}
LyXText * InsetText::getLyXText(BufferView const * lbv,
- bool const recursive) const
+ bool const recursive) const
{
- if (!recursive && (cached_bview == lbv)) {
+ if (cached_bview == lbv) {
+ if (recursive && the_locking_inset)
+ return the_locking_inset->getLyXText(lbv, true);
LyXText * lt = cached_text.get();
lyx::Assert(lt && lt->firstRow()->par() == par);
return lt;
}
-
// 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;
}
}
if (bv->screen()) {
- t->first = bv->screen()->topCursorVisible(t);
+ 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;
inset_y = cy(bv) + drawTextYOffset;
}
if (bv->screen()) {
- t->first = bv->screen()->topCursorVisible(t);
+ 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
{
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(), ' ');
+ }
par->pasteParagraph(bparams);
}
reinitLyXText();
return;
owner()->getDrawFont(font);
}
+
+
+void InsetText::appendParagraphs(BufferParams const & bparams,
+ 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->next()->previous(lastbuffer);
+ lastbuffer = lastbuffer->next();
+ }
+ lastbuffer = par;
+ while (lastbuffer->next())
+ lastbuffer = lastbuffer->next();
+ if (newpar->size() && lastbuffer->size() &&
+ !lastbuffer->isSeparator(lastbuffer->size()-1))
+ {
+ lastbuffer->insertChar(lastbuffer->size(), ' ');
+ }
+
+ // make the buf exactly the same layout than our last paragraph
+ buf->makeSameLayout(lastbuffer);
+
+ // paste it!
+ lastbuffer->next(buf);
+ buf->previous(lastbuffer);
+ lastbuffer->pasteParagraph(bparams);
+
+ reinitLyXText();
+}