#include "BufferView.h"
#include "CutAndPaste.h"
#include "debug.h"
+#include "dimension.h"
#include "funcrequest.h"
#include "gettext.h"
#include "intl.h"
#include "LaTeXFeatures.h"
#include "LColor.h"
+#include "Lsstream.h"
#include "lyxfont.h"
#include "lyxcursor.h"
#include "lyxfind.h"
using lyx::pos_type;
using lyx::textclass_type;
+
// These functions should probably go into bufferview_funcs somehow (Jug)
void InsetText::saveLyXTextState(LyXText * t) const
autoBreakRows = false;
}
top_y = 0;
- insetAscent = 0;
- insetDescent = 0;
- insetWidth = 0;
old_max_width = 0;
no_selection = true;
need_update = FULL;
}
-int InsetText::ascent(BufferView * bv, LyXFont const &) const
+void InsetText::dimension(BufferView * bv, LyXFont const &,
+ Dimension & dim) const
{
- insetAscent = getLyXText(bv)->rows().begin()->ascent_of_text() +
- TEXT_TO_INSET_OFFSET;
- return insetAscent;
+ LyXText * text = getLyXText(bv);
+ dim.a = text->rows().begin()->ascent_of_text() + TEXT_TO_INSET_OFFSET;
+ dim.d = text->height - dim.a + TEXT_TO_INSET_OFFSET;
+ dim.w = max(textWidth(bv), int(text->width)) + 2 * TEXT_TO_INSET_OFFSET;
+ dim.w = max(dim.w, 10);
+ // cache it
+ dim_ = dim;
}
-int InsetText::descent(BufferView * bv, LyXFont const &) const
+int InsetText::textWidth(BufferView * bv, bool fordraw) const
{
- LyXText * llt = getLyXText(bv);
- insetDescent = llt->height - llt->rows().begin()->ascent_of_text() +
- TEXT_TO_INSET_OFFSET;
- return insetDescent;
-}
-
+ int w = autoBreakRows ? getMaxWidth(bv, this) : -1;
-int InsetText::width(BufferView * bv, LyXFont const &) const
-{
- insetWidth = max(textWidth(bv), (int)getLyXText(bv)->width) +
- (2 * TEXT_TO_INSET_OFFSET);
- insetWidth = max(insetWidth, 10);
- return insetWidth;
-}
+ if (fordraw)
+ return max(w - 2 * TEXT_TO_INSET_OFFSET,
+ (int)getLyXText(bv)->width);
+ if (w < 0)
+ return -1;
-int InsetText::textWidth(BufferView * bv, bool fordraw) const
-{
- 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);
+ return w - 2 * TEXT_TO_INSET_OFFSET;
}
Painter & pain = bv->painter();
- // call these methods so that insetWidth, insetAscent and
- // insetDescent have the right values.
- width(bv, f);
- ascent(bv, f);
- descent(bv, f);
+ // call this method so that dim_ has the right value
+ dimension(bv, f, dim_);
// repaint the background if needed
if (backgroundColor() != LColor::background)
x += static_cast<float>(scroll());
top_baseline = baseline;
- top_y = baseline - insetAscent;
+ top_y = baseline - dim_.a;
- if (last_drawn_width != insetWidth) {
+ if (last_drawn_width != dim_.w) {
need_update |= FULL;
- last_drawn_width = insetWidth;
+ last_drawn_width = dim_.w;
}
if (the_locking_inset && (cpar(bv) == inset_par)
drawFrame(pain, int(start_x));
}
- x += insetWidth - TEXT_TO_INSET_OFFSET;
+ x += dim_.w - TEXT_TO_INSET_OFFSET;
if (need_update != INIT) {
need_update = NONE;
{
static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
frame_x = x + ttoD2;
- frame_y = top_baseline - insetAscent + ttoD2;
- frame_w = insetWidth - TEXT_TO_INSET_OFFSET;
- frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET;
+ frame_y = top_baseline - dim_.a + ttoD2;
+ frame_w = dim_.w - TEXT_TO_INSET_OFFSET;
+ frame_h = dim_.a + dim_.d - TEXT_TO_INSET_OFFSET;
pain.rectangle(frame_x, frame_y, frame_w, frame_h,
frame_color);
}
}
-void InsetText::edit(BufferView * bv, int x, int y, mouse_button::state button)
-{
- UpdatableInset::edit(bv, x, y, button);
-
- if (!bv->lockInset(this)) {
- lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
- return;
- }
- locked = true;
- the_locking_inset = 0;
- inset_pos = inset_x = inset_y = 0;
- inset_boundary = false;
- inset_par = 0;
- old_par = 0;
- int tmp_y = (y < 0) ? 0 : y;
- bool clear = false;
- if (!lt) {
- lt = getLyXText(bv);
- clear = true;
- }
- // 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)
- // FIXME: GUII I've changed this to none: probably WRONG
- if (!checkAndActivateInset(bv, x, tmp_y, mouse_button::none)) {
- lt->setCursorFromCoordinates(x - drawTextXOffset,
- 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
- // language to the surronding text (if different).
- if (paragraphs.begin()->empty() &&
- boost::next(paragraphs.begin()) == paragraphs.end()&&
- 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;
- updateLocal(bv, code, false);
-
- // Tell the paragraph dialog that we've entered an insettext.
- bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
-}
-
-
-void InsetText::edit(BufferView * bv, bool front)
-{
- UpdatableInset::edit(bv, front);
-
- if (!bv->lockInset(this)) {
- lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
- return;
- }
- 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;
- }
- if (front)
- lt->setCursor(paragraphs.begin(), 0);
- else {
- ParagraphList::iterator it = paragraphs.begin();
- ParagraphList::iterator end = paragraphs.end();
- while (boost::next(it) != end)
- ++it;
-// int const pos = (p->size() ? p->size()-1 : p->size());
- lt->setCursor(it, it->size());
- }
- 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 (paragraphs.begin()->empty() &&
- boost::next(paragraphs.begin()) == paragraphs.end() &&
- 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;
- updateLocal(bv, code, false);
-}
-
-
void InsetText::insetUnlock(BufferView * bv)
{
if (the_locking_inset) {
}
if (it.getInset()->getInsetFromID(id)) {
getLyXText(bv)->setCursorIntern(pit, it.getPos());
- it.getInset()->edit(bv);
+ it.getInset()->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
return the_locking_inset->lockInsetInInset(bv, inset);
}
}
lockInset(bv);
int tmp_x = cmd.x - drawTextXOffset;
- int tmp_y = cmd.y + insetAscent - getLyXText(bv)->top_y();
+ int tmp_y = cmd.y + dim_.a - getLyXText(bv)->top_y();
Inset * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
if (the_locking_inset) {
int old_top_y = lt->top_y();
lt->setCursorFromCoordinates(cmd.x - drawTextXOffset,
- cmd.y + insetAscent);
+ cmd.y + dim_.a);
// set the selection cursor!
lt->selection.cursor = lt->cursor;
lt->cursor.x_fix(lt->cursor.x());
return the_locking_inset->localDispatch(cmd1);
int tmp_x = cmd.x - drawTextXOffset;
- int tmp_y = cmd.y + insetAscent - getLyXText(bv)->top_y();
+ int tmp_y = cmd.y + dim_.a - getLyXText(bv)->top_y();
Inset * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
bool ret = false;
if (inset) {
}
LyXCursor cur = lt->cursor;
lt->setCursorFromCoordinates
- (cmd.x - drawTextXOffset, cmd.y + insetAscent);
+ (cmd.x - drawTextXOffset, cmd.y + dim_.a);
lt->cursor.x_fix(lt->cursor.x());
if (cur == lt->cursor) {
if (clear)
}
-Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
+Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd)
{
- BufferView * bv = ev.view();
- switch (ev.action) {
+ BufferView * bv = cmd.view();
+
+ if (cmd.action == LFUN_INSET_EDIT) {
+ UpdatableInset::localDispatch(cmd);
+
+ if (!bv->lockInset(this)) {
+ lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
+ return DISPATCHED;
+ }
+
+ 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;
+ }
+
+ if (cmd.argument.size()) {
+ if (cmd.argument == "left")
+ lt->setCursor(paragraphs.begin(), 0);
+ else {
+ ParagraphList::iterator it = paragraphs.begin();
+ ParagraphList::iterator end = paragraphs.end();
+ while (boost::next(it) != end)
+ ++it;
+ // int const pos = (p->size() ? p->size()-1 : p->size());
+ lt->setCursor(it, it->size());
+ }
+ } else {
+ int tmp_y = (cmd.y < 0) ? 0 : cmd.y;
+ // 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)
+ // FIXME: GUII I've changed this to none: probably WRONG
+ if (!checkAndActivateInset(bv, cmd.x, tmp_y, mouse_button::none)) {
+ lt->setCursorFromCoordinates(cmd.x - drawTextXOffset,
+ cmd.y + dim_.a);
+ lt->cursor.x_fix(lt->cursor.x());
+ }
+ }
+
+ 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 (paragraphs.begin()->empty() &&
+ boost::next(paragraphs.begin()) == paragraphs.end()&&
+ 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;
+
+ updateLocal(bv, code, false);
+ // Tell the paragraph dialog that we've entered an insettext.
+ bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
+ return DISPATCHED;
+ }
+
+
+ switch (cmd.action) {
case LFUN_MOUSE_PRESS:
- lfunMousePress(ev);
+ lfunMousePress(cmd);
return DISPATCHED;
case LFUN_MOUSE_MOTION:
- lfunMouseMotion(ev);
+ lfunMouseMotion(cmd);
return DISPATCHED;
case LFUN_MOUSE_RELEASE:
- return lfunMouseRelease(ev) ? DISPATCHED : UNDISPATCHED;
+ return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
default:
break;
}
bool was_empty = (paragraphs.begin()->empty() &&
boost::next(paragraphs.begin()) == paragraphs.end());
no_selection = false;
- RESULT result = UpdatableInset::localDispatch(ev);
+ RESULT result = UpdatableInset::localDispatch(cmd);
if (result != UNDISPATCHED)
return DISPATCHED;
result = DISPATCHED;
- if (ev.action < 0 && ev.argument.empty())
+ if (cmd.action < 0 && cmd.argument.empty())
return FINISHED;
if (the_locking_inset) {
- result = the_locking_inset->localDispatch(ev);
+ result = the_locking_inset->localDispatch(cmd);
if (result == DISPATCHED_NOUPDATE)
return result;
else if (result == DISPATCHED) {
if (lt->selection.set())
cursor_update = SELECTION;
- switch (ev.action) {
+ switch (cmd.action) {
// Normal chars
case LFUN_SELFINSERT:
// setErrorMessage(N_("Document is read only"));
break;
}
- if (!ev.argument.empty()) {
+ if (!cmd.argument.empty()) {
/* Automatically delete the currently selected
* text and replace it with what is being
* typed in now. Depends on lyxrc settings
}
}
lt->clearSelection();
- for (string::size_type i = 0; i < ev.argument.length(); ++i) {
+ for (string::size_type i = 0; i < cmd.argument.length(); ++i) {
bv->owner()->getIntl().getTransManager().
- TranslateAndInsert(ev.argument[i], lt);
+ TranslateAndInsert(cmd.argument[i], lt);
}
}
lt->selection.cursor = lt->cursor;
if (clip.empty())
break;
- if (ev.argument == "paragraph") {
+ if (cmd.argument == "paragraph") {
lt->insertStringAsParagraphs(clip);
} else {
lt->insertStringAsLines(clip);
// and current buffer's textclass (number). */
LyXTextClass const & tclass =
bv->buffer()->params.getLyXTextClass();
- string layout = ev.argument;
+ string layout = cmd.argument;
bool hasLayout = tclass.hasLayout(layout);
// If the entry is obsolete, use the new one instead.
// see if we found the layout number:
if (!hasLayout) {
- FuncRequest lf(LFUN_MESSAGE, N_("Layout ") + ev.argument + N_(" not known"));
+ FuncRequest lf(LFUN_MESSAGE, N_("Layout ") + cmd.argument + N_(" not known"));
bv->owner()->dispatch(lf);
break;
}
cur_value = pit->params().spacing().getValue();
}
- istringstream istr(ev.argument.c_str());
+ istringstream istr(STRCONV(cmd.argument));
string tmp;
istr >> tmp;
Spacing::Space new_spacing = cur_spacing;
new_spacing = Spacing::Default;
} else {
lyxerr << _("Unknown spacing argument: ")
- << ev.argument << endl;
+ << cmd.argument << endl;
}
if (cur_spacing != new_spacing || cur_value != new_value) {
pit->params().spacing(Spacing(new_spacing, new_value));
case LFUN_ENDBUF:
case LFUN_BEGINNINGBUF:
updwhat = cursor_update;
- if (!bv->dispatch(ev))
+ if (!bv->dispatch(cmd))
result = UNDISPATCHED;
break;
// fallthrough
default:
- if (!bv->dispatch(ev))
+ if (!bv->dispatch(cmd))
result = UNDISPATCHED;
break;
}
}
-int InsetText::latex(Buffer const * buf, ostream & os,
- bool moving_arg, bool) const
+int InsetText::latex(Buffer const * buf, ostream & os, LatexRunParams const & runparams,
+ bool fragile, bool) const
{
TexRow texrow;
- latexParagraphs(buf, paragraphs,
- paragraphs.begin(), paragraphs.end(),
- os, texrow, moving_arg);
+ latexParagraphs(buf, paragraphs, os, texrow, runparams, fragile);
return texrow.rows();
}
break;
case LATEX_COMMAND:
- buf->sgmlError(&*pit, 0, _("Error: LatexType Command not allowed here.\n"));
+ buf->sgmlError(pit, 0, _("Error: LatexType Command not allowed here.\n"));
return -1;
break;
static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
if (!isHighlyEditableInset(inset))
return false;
- inset->edit(bv, front);
+ FuncRequest cmd(bv, LFUN_INSET_EDIT, front ? "left" : "right");
+ inset->localDispatch(cmd);
if (!the_locking_inset)
return false;
updateLocal(bv, CURSOR, false);
{
x -= drawTextXOffset;
int dummyx = x;
- int dummyy = y + insetAscent;
+ int dummyy = y + dim_.a;
Inset * inset = getLyXText(bv)->checkInsetHit(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
if (inset) {
if (x < 0)
- x = insetWidth;
+ x = dim_.w;
if (y < 0)
- y = insetDescent;
+ y = dim_.d;
inset_x = cix(bv) - top_x + drawTextXOffset;
inset_y = ciy(bv) + drawTextYOffset;
- inset->edit(bv, x - inset_x, y - inset_y, button);
+ FuncRequest cmd(bv, LFUN_INSET_EDIT, x - inset_x, y - inset_y, button);
+ inset->localDispatch(cmd);
if (!the_locking_inset)
return false;
updateLocal(bv, CURSOR, false);
void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const
{
Painter & pain = bv->painter();
- int w = insetWidth;
- int h = insetAscent + insetDescent;
- int ty = baseline - insetAscent;
+ int w = dim_.w;
+ int h = dim_.a + dim_.d;
+ int ty = baseline - dim_.a;
if (ty < 0) {
h += ty;
}
-void InsetText::paragraph(Paragraph * p)
-{
- // GENERAL COMMENT: We don't have to free the old paragraphs as the
- // caller of this function has to take care of it. This IS important
- // as we could have to insert a paragraph before this one and just
- // link the actual to a new ones next and set it with this function
- // and are done!
- paragraphs.set(p);
- // set ourself as owner for all the paragraphs inserted!
- for_each(paragraphs.begin(), paragraphs.end(),
- boost::bind(&Paragraph::setInsetOwner, _1, this));
-
- reinitLyXText();
- // redraw myself when asked for
- need_update = INIT;
-}
-
-
Inset * InsetText::getInsetFromID(int id_arg) const
{
if (id_arg == id())
}
-void InsetText::appendParagraphs(Buffer * buffer,
- ParagraphList & plist)
+void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
{
#warning FIXME Check if Changes stuff needs changing here. (Lgb)
// And it probably does. You have to take a look at this John. (Lgb)
#warning John, have a look here. (Lgb)
- BufferParams const & bparams = buffer->params;
#if 0
+ BufferParams const & bparams = buffer->params;
Paragraph * buf;
Paragraph * tmpbuf = newpar;
Paragraph * lastbuffer = buf = new Paragraph(*tmpbuf, false);