2000-02-25 12:06:15 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2000-02-25 13:35:38 +00:00
|
|
|
* Copyright 1998 The LyX Team.
|
2000-02-25 12:06:15 +00:00
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <fstream>
|
2000-03-08 01:45:25 +00:00
|
|
|
#include <algorithm>
|
2000-02-25 12:06:15 +00:00
|
|
|
using std::ifstream;
|
2000-03-06 16:05:12 +00:00
|
|
|
using std::min;
|
|
|
|
using std::max;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "insettext.h"
|
|
|
|
#include "lyxlex.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "lyxfont.h"
|
|
|
|
#include "lyxlex.h"
|
|
|
|
#include "commandtags.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "support/textutils.h"
|
|
|
|
#include "layout.h"
|
|
|
|
#include "insetlatexaccent.h"
|
|
|
|
#include "insetquotes.h"
|
|
|
|
#include "mathed/formulamacro.h"
|
|
|
|
#include "figinset.h"
|
|
|
|
#include "insetinfo.h"
|
|
|
|
#include "insetinclude.h"
|
|
|
|
#include "insetbib.h"
|
|
|
|
#include "insetcommand.h"
|
|
|
|
#include "insetindex.h"
|
|
|
|
#include "insetlabel.h"
|
|
|
|
#include "insetref.h"
|
|
|
|
//#include "insettabular.h"
|
|
|
|
#include "insetert.h"
|
|
|
|
#include "insetspecialchar.h"
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "Painter.h"
|
|
|
|
#include "lyx_gui_misc.h"
|
|
|
|
#include "support/LAssert.h"
|
|
|
|
|
|
|
|
extern unsigned char getCurrentTextClass(Buffer *);
|
|
|
|
|
|
|
|
InsetText::InsetText(Buffer * buf)
|
|
|
|
{
|
|
|
|
par = new LyXParagraph();
|
|
|
|
the_locking_inset = 0;
|
|
|
|
buffer = buf;
|
|
|
|
cursor_visible = false;
|
|
|
|
maxWidth = old_x = -1;
|
|
|
|
actpos = selection_start = selection_end = 0;
|
|
|
|
interline_space = 1;
|
|
|
|
no_selection = false;
|
|
|
|
init_inset = true;
|
2000-03-08 13:52:57 +00:00
|
|
|
maxAscent = maxDescent = insetWidth = widthOffset = 0;
|
2000-03-02 18:30:01 +00:00
|
|
|
autoBreakRows = false;
|
2000-03-08 13:52:57 +00:00
|
|
|
xpos = 0.0;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetText::InsetText(InsetText const & ins, Buffer * buf)
|
|
|
|
{
|
|
|
|
par = new LyXParagraph(ins.par);
|
|
|
|
the_locking_inset = 0;
|
|
|
|
buffer = buf;
|
|
|
|
cursor_visible = false;
|
|
|
|
maxWidth = old_x = -1;
|
|
|
|
actpos = selection_start = selection_end = 0;
|
|
|
|
interline_space = 1;
|
|
|
|
no_selection = false;
|
|
|
|
init_inset = true;
|
2000-03-08 13:52:57 +00:00
|
|
|
maxAscent = maxDescent = insetWidth = widthOffset = 0;
|
2000-03-02 18:30:01 +00:00
|
|
|
autoBreakRows = false;
|
2000-03-08 13:52:57 +00:00
|
|
|
xpos = 0.0;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetText::~InsetText()
|
|
|
|
{
|
|
|
|
delete par;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 16:42:21 +00:00
|
|
|
Inset * InsetText::Clone() const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
|
|
|
InsetText * t = new InsetText(*this, buffer);
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::Write(ostream & os) const
|
|
|
|
{
|
|
|
|
os << "Text\n";
|
|
|
|
WriteParagraphData(os);
|
|
|
|
}
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
void InsetText::WriteParagraphData(ostream & os) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-03-01 14:13:21 +00:00
|
|
|
par->writeFile(os, buffer->params, 0, 0);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
void InsetText::Read(LyXLex & lex)
|
|
|
|
{
|
|
|
|
string token, tmptok;
|
|
|
|
int pos = 0;
|
2000-03-02 02:19:43 +00:00
|
|
|
LyXParagraph * return_par = 0;
|
2000-03-01 14:13:21 +00:00
|
|
|
char depth = 0; // signed or unsigned?
|
|
|
|
LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
|
|
|
|
LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
|
|
|
|
LyXFont font(LyXFont::ALL_INHERIT);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
delete par;
|
|
|
|
par = new LyXParagraph;
|
|
|
|
|
|
|
|
while (lex.IsOK()) {
|
|
|
|
lex.nextToken();
|
|
|
|
token = lex.GetString();
|
|
|
|
if (token.empty())
|
|
|
|
continue;
|
2000-03-01 14:13:21 +00:00
|
|
|
if (token == "\\end_inset")
|
2000-02-25 12:06:15 +00:00
|
|
|
break;
|
2000-03-01 14:13:21 +00:00
|
|
|
if (buffer->parseSingleLyXformat2Token(lex, par, return_par,
|
|
|
|
token, pos, depth,
|
|
|
|
font, footnoteflag,
|
|
|
|
footnotekind)) {
|
|
|
|
// the_end read this should NEVER happen
|
|
|
|
lex.printError("\\the_end read in inset! Error in document!");
|
|
|
|
return;
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
if (token != "\\end_inset") {
|
|
|
|
lex.printError("Missing \\end_inset at this point. "
|
|
|
|
"Read: `$$Token'");
|
|
|
|
}
|
|
|
|
init_inset = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
int InsetText::ascent(Painter & pain, LyXFont const & font) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-02-25 16:05:26 +00:00
|
|
|
if (init_inset) {
|
2000-03-08 13:52:57 +00:00
|
|
|
computeTextRows(pain, xpos);
|
2000-02-25 16:05:26 +00:00
|
|
|
init_inset = false;
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
if (maxAscent)
|
|
|
|
return maxAscent;
|
|
|
|
return font.maxAscent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
int InsetText::descent(Painter & pain, LyXFont const & font) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-02-25 16:05:26 +00:00
|
|
|
if (init_inset) {
|
2000-03-08 13:52:57 +00:00
|
|
|
computeTextRows(pain, xpos);
|
2000-02-25 16:05:26 +00:00
|
|
|
init_inset = false;
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
if (maxDescent)
|
|
|
|
return maxDescent;
|
|
|
|
return font.maxDescent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
int InsetText::width(Painter & pain, LyXFont const &) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-02-25 16:05:26 +00:00
|
|
|
if (init_inset) {
|
2000-03-08 13:52:57 +00:00
|
|
|
computeTextRows(pain, xpos);
|
2000-02-25 16:05:26 +00:00
|
|
|
init_inset = false;
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
return insetWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
void InsetText::draw(Painter & pain, LyXFont const & f,
|
|
|
|
int baseline, float & x) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-03-08 13:52:57 +00:00
|
|
|
xpos = x;
|
|
|
|
computeTextRows(pain, x);
|
2000-02-25 12:06:15 +00:00
|
|
|
UpdatableInset::draw(pain, f, baseline, x);
|
2000-02-25 13:35:38 +00:00
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
top_x = int(x);
|
|
|
|
top_baseline = baseline;
|
|
|
|
computeBaselines(baseline);
|
2000-03-06 02:42:40 +00:00
|
|
|
for(RowList::size_type r = 0; r < rows.size() - 1; ++r) {
|
2000-02-29 02:19:17 +00:00
|
|
|
drawRowSelection(pain, rows[r].pos, rows[r + 1].pos, r,
|
2000-02-25 12:06:15 +00:00
|
|
|
rows[r].baseline, x);
|
2000-02-29 02:19:17 +00:00
|
|
|
drawRowText(pain, rows[r].pos, rows[r + 1].pos, rows[r].baseline, x);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
x += insetWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::drawRowSelection(Painter & pain, int startpos, int endpos,
|
|
|
|
int row, int baseline, float x) const
|
|
|
|
{
|
|
|
|
if (!hasSelection())
|
|
|
|
return;
|
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
int s_start, s_end;
|
2000-02-25 12:06:15 +00:00
|
|
|
if (selection_start > selection_end) {
|
|
|
|
s_start = selection_end;
|
|
|
|
s_end = selection_start;
|
|
|
|
} else {
|
|
|
|
s_start = selection_start;
|
|
|
|
s_end = selection_end;
|
|
|
|
}
|
|
|
|
if ((s_start > endpos) || (s_end < startpos))
|
|
|
|
return;
|
2000-02-25 13:35:38 +00:00
|
|
|
|
|
|
|
int esel_x;
|
|
|
|
int ssel_x = esel_x = int(x);
|
|
|
|
LyXFont font;
|
|
|
|
int p = startpos;
|
|
|
|
for(; p < endpos; ++p) {
|
2000-02-25 12:06:15 +00:00
|
|
|
if (p == s_start)
|
|
|
|
ssel_x = int(x);
|
|
|
|
if ((p >= s_start) && (p <= s_end))
|
|
|
|
esel_x = int(x);
|
2000-02-25 13:35:38 +00:00
|
|
|
char ch = par->GetChar(p);
|
2000-02-25 12:06:15 +00:00
|
|
|
font = GetFont(par,p);
|
|
|
|
if (IsFloatChar(ch)) {
|
|
|
|
// skip for now
|
|
|
|
} else if (ch == LyXParagraph::META_INSET) {
|
|
|
|
Inset const * tmpinset = par->GetInset(p);
|
|
|
|
x += tmpinset->width(pain, font);
|
|
|
|
} else {
|
|
|
|
x += pain.width(ch,font);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p == s_start)
|
|
|
|
ssel_x = int(x);
|
|
|
|
if ((p >= s_start) && (p <= s_end))
|
|
|
|
esel_x = int(x);
|
|
|
|
if (ssel_x < esel_x) {
|
|
|
|
pain.fillRectangle(int(ssel_x), baseline-rows[row].asc,
|
|
|
|
int(esel_x - ssel_x),
|
|
|
|
rows[row].asc + rows[row].desc,
|
|
|
|
LColor::selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::drawRowText(Painter & pain, int startpos, int endpos,
|
|
|
|
int baseline, float x) const
|
|
|
|
{
|
|
|
|
Assert(endpos <= par->Last());
|
2000-02-25 13:35:38 +00:00
|
|
|
|
|
|
|
for(int p = startpos; p < endpos; ++p) {
|
|
|
|
char ch = par->GetChar(p);
|
|
|
|
LyXFont font = GetFont(par,p);
|
2000-02-25 12:06:15 +00:00
|
|
|
if (IsFloatChar(ch)) {
|
|
|
|
// skip for now
|
2000-03-09 16:04:28 +00:00
|
|
|
} else if (par->IsNewline(p)) {
|
|
|
|
// Draw end-of-line marker
|
|
|
|
int wid = font.width('n');
|
|
|
|
int asc = font.maxAscent();
|
|
|
|
int y = baseline;
|
|
|
|
int xp[3], yp[3];
|
|
|
|
|
|
|
|
xp[0] = int(x + wid * 0.375);
|
|
|
|
yp[0] = int(y - 0.875 * asc * 0.75);
|
|
|
|
|
|
|
|
xp[1] = int(x);
|
|
|
|
yp[1] = int(y - 0.500 * asc * 0.75);
|
|
|
|
|
|
|
|
xp[2] = int(x + wid * 0.375);
|
|
|
|
yp[2] = int(y - 0.125 * asc * 0.75);
|
|
|
|
|
|
|
|
pain.lines(xp, yp, 3, LColor::eolmarker);
|
|
|
|
|
|
|
|
xp[0] = int(x);
|
|
|
|
yp[0] = int(y - 0.500 * asc * 0.75);
|
|
|
|
|
|
|
|
xp[1] = int(x + wid);
|
|
|
|
yp[1] = int(y - 0.500 * asc * 0.75);
|
|
|
|
|
|
|
|
xp[2] = int(x + wid);
|
|
|
|
yp[2] = int(y - asc * 0.75);
|
|
|
|
|
|
|
|
pain.lines(xp, yp, 3, LColor::eolmarker);
|
|
|
|
x += wid;
|
2000-02-25 12:06:15 +00:00
|
|
|
} else if (ch == LyXParagraph::META_INSET) {
|
|
|
|
Inset * tmpinset = par->GetInset(p);
|
|
|
|
if (tmpinset)
|
|
|
|
tmpinset->draw(pain, font, baseline, x);
|
|
|
|
} else {
|
|
|
|
pain.text(int(x), baseline, ch, font);
|
|
|
|
x += pain.width(ch,font);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
char const * InsetText::EditMessage() const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
|
|
|
return _("Opened Text Inset");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
|
|
|
|
{
|
|
|
|
UpdatableInset::Edit(bv, x, y, button);
|
|
|
|
|
|
|
|
bv->lockInset(this);
|
|
|
|
the_locking_inset = 0;
|
|
|
|
inset_pos = inset_x = inset_y = 0;
|
|
|
|
no_selection = true;
|
|
|
|
setPos(bv, x,y);
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
current_font = real_current_font = GetFont(par, actpos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
void InsetText::InsetUnlock(BufferView * bv)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
|
|
|
if (the_locking_inset)
|
|
|
|
the_locking_inset->InsetUnlock(bv);
|
|
|
|
HideInsetCursor(bv);
|
|
|
|
if (hasSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
2000-03-08 13:52:57 +00:00
|
|
|
UpdateLocal(bv, false);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
the_locking_inset = 0;
|
|
|
|
no_selection = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::UnlockInsetInInset(BufferView * bv, Inset * inset, bool lr)
|
|
|
|
{
|
|
|
|
if (!the_locking_inset)
|
|
|
|
return false;
|
|
|
|
if (the_locking_inset == inset) {
|
|
|
|
the_locking_inset->InsetUnlock(bv);
|
|
|
|
the_locking_inset = 0;
|
|
|
|
if (lr)
|
|
|
|
moveRight(bv, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return the_locking_inset->UnlockInsetInInset(bv, inset,lr);
|
|
|
|
}
|
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
|
|
|
|
{
|
|
|
|
if (!the_locking_inset)
|
|
|
|
return false;
|
|
|
|
if (the_locking_inset != inset)
|
|
|
|
return the_locking_inset->UpdateInsetInInset(bv, inset);
|
|
|
|
float x = inset_x;
|
|
|
|
inset->draw(bv->getPainter(), real_current_font, inset_y, x);
|
2000-03-08 13:52:57 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-02-25 12:06:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
|
|
|
|
{
|
|
|
|
if (the_locking_inset) {
|
|
|
|
the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
no_selection = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
|
|
|
|
{
|
|
|
|
if (hasSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
2000-03-08 13:52:57 +00:00
|
|
|
UpdateLocal(bv, false);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
no_selection = false;
|
|
|
|
if (the_locking_inset) {
|
2000-02-29 02:19:17 +00:00
|
|
|
setPos(bv, x, y, false);
|
2000-02-25 12:06:15 +00:00
|
|
|
UpdatableInset
|
2000-02-29 02:19:17 +00:00
|
|
|
*inset = 0;
|
|
|
|
if (par->GetChar(actpos) == LyXParagraph::META_INSET)
|
|
|
|
inset = static_cast<UpdatableInset*>(par->GetInset(actpos));
|
2000-02-25 12:06:15 +00:00
|
|
|
if (the_locking_inset == inset) {
|
|
|
|
the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
|
|
|
|
return;
|
|
|
|
} else if (inset) {
|
|
|
|
// otherwise unlock the_locking_inset and lock the new inset
|
|
|
|
inset_x = cx-top_x;
|
|
|
|
inset_y = cy;
|
|
|
|
inset_pos = actpos;
|
|
|
|
the_locking_inset->InsetUnlock(bv);
|
|
|
|
the_locking_inset = inset;
|
|
|
|
the_locking_inset->Edit(bv, x - inset_x, y - inset_y, button);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// otherwise only unlock the_locking_inset
|
|
|
|
the_locking_inset->InsetUnlock(bv);
|
|
|
|
}
|
|
|
|
HideInsetCursor(bv);
|
|
|
|
the_locking_inset = 0;
|
|
|
|
setPos(bv, x, y);
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
if (!the_locking_inset)
|
|
|
|
ShowInsetCursor(bv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int button)
|
|
|
|
{
|
|
|
|
if (the_locking_inset) {
|
2000-02-25 13:35:38 +00:00
|
|
|
the_locking_inset->InsetMotionNotify(bv, x - inset_x,
|
|
|
|
y - inset_y,button);
|
2000-02-25 12:06:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!no_selection) {
|
2000-02-25 13:35:38 +00:00
|
|
|
int old = selection_end;
|
2000-02-25 12:06:15 +00:00
|
|
|
setPos(bv, x, y, false);
|
|
|
|
selection_end = actpos;
|
|
|
|
if (old != selection_end)
|
2000-03-08 13:52:57 +00:00
|
|
|
UpdateLocal(bv, false);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
no_selection = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::InsetKeyPress(XKeyEvent * xke)
|
|
|
|
{
|
|
|
|
if (the_locking_inset) {
|
|
|
|
the_locking_inset->InsetKeyPress(xke);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
UpdatableInset::RESULT
|
|
|
|
InsetText::LocalDispatch(BufferView * bv,
|
|
|
|
int action, string const & arg)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
|
|
|
no_selection = false;
|
|
|
|
if (UpdatableInset::LocalDispatch(bv, action, arg)) {
|
|
|
|
resetPos(bv);
|
|
|
|
return DISPATCHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdatableInset::RESULT
|
|
|
|
result=DISPATCHED;
|
|
|
|
|
|
|
|
if ((action < 0) && arg.empty())
|
|
|
|
return FINISHED;
|
|
|
|
|
|
|
|
if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
|
|
|
|
(action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
|
|
|
|
old_x = -1;
|
|
|
|
if (the_locking_inset) {
|
|
|
|
result = the_locking_inset->LocalDispatch(bv, action, arg);
|
|
|
|
if (result == DISPATCHED) {
|
|
|
|
the_locking_inset->ToggleInsetCursor(bv);
|
2000-03-08 13:52:57 +00:00
|
|
|
UpdateLocal(bv, false);
|
2000-02-25 12:06:15 +00:00
|
|
|
the_locking_inset->ToggleInsetCursor(bv);
|
|
|
|
return result;
|
|
|
|
} else if (result == FINISHED) {
|
|
|
|
if ((action == LFUN_RIGHT) || (action == -1)) {
|
|
|
|
actpos = inset_pos + 1;
|
|
|
|
resetPos(bv);
|
|
|
|
}
|
|
|
|
the_locking_inset = 0;
|
|
|
|
return DISPATCHED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HideInsetCursor(bv);
|
|
|
|
switch (action) {
|
2000-03-09 16:04:28 +00:00
|
|
|
// Normal chars
|
|
|
|
case -1:
|
2000-03-27 15:13:47 +00:00
|
|
|
cutSelection();
|
|
|
|
actpos = selection_start;
|
2000-03-09 16:04:28 +00:00
|
|
|
par->InsertChar(actpos,arg[0]);
|
|
|
|
par->SetFont(actpos,real_current_font);
|
|
|
|
++actpos;
|
|
|
|
selection_start = selection_end = actpos;
|
2000-03-27 15:13:47 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-03-09 16:04:28 +00:00
|
|
|
break;
|
2000-02-25 12:06:15 +00:00
|
|
|
// --- Cursor Movements ---------------------------------------------
|
2000-03-09 16:04:28 +00:00
|
|
|
case LFUN_RIGHTSEL:
|
|
|
|
moveRight(bv, false);
|
|
|
|
selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
break;
|
|
|
|
case LFUN_RIGHT:
|
|
|
|
result= DISPATCH_RESULT(moveRight(bv));
|
|
|
|
if (hasSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LFUN_LEFTSEL:
|
|
|
|
moveLeft(bv, false);
|
|
|
|
selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
break;
|
|
|
|
case LFUN_LEFT:
|
2000-02-25 12:06:15 +00:00
|
|
|
result= DISPATCH_RESULT(moveLeft(bv));
|
|
|
|
if (hasSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
2000-03-08 13:52:57 +00:00
|
|
|
UpdateLocal(bv, false);
|
2000-02-25 12:06:15 +00:00
|
|
|
} else {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
}
|
|
|
|
break;
|
2000-03-09 16:04:28 +00:00
|
|
|
case LFUN_DOWNSEL:
|
|
|
|
moveDown(bv, false);
|
|
|
|
selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
break;
|
|
|
|
case LFUN_DOWN:
|
|
|
|
result= DISPATCH_RESULT(moveDown(bv));
|
|
|
|
if (hasSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LFUN_UPSEL:
|
|
|
|
moveUp(bv, false);
|
|
|
|
selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
break;
|
|
|
|
case LFUN_UP:
|
|
|
|
result= DISPATCH_RESULT(moveUp(bv));
|
|
|
|
if (hasSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LFUN_BACKSPACE:
|
|
|
|
if (!actpos || par->IsNewline(actpos-1)) {
|
|
|
|
if (hasSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
moveLeft(bv);
|
|
|
|
case LFUN_DELETE:
|
2000-03-27 15:13:47 +00:00
|
|
|
bool ret;
|
|
|
|
if (hasSelection())
|
|
|
|
ret = cutSelection();
|
|
|
|
else
|
|
|
|
ret = Delete();
|
|
|
|
if (ret) { // we need update
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
UpdateLocal(bv, true);
|
|
|
|
} else if (hasSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LFUN_CUT:
|
|
|
|
if (cutSelection()) { // we need update
|
|
|
|
actpos = selection_end = selection_start;
|
|
|
|
UpdateLocal(bv, true);
|
|
|
|
} else if (hasSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LFUN_COPY:
|
|
|
|
if (copySelection()) { // we need update
|
2000-03-09 16:04:28 +00:00
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
UpdateLocal(bv, true);
|
|
|
|
} else if (hasSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
}
|
|
|
|
break;
|
2000-03-27 15:13:47 +00:00
|
|
|
case LFUN_PASTE:
|
|
|
|
if (pasteSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
UpdateLocal(bv, true);
|
|
|
|
}
|
|
|
|
break;
|
2000-03-09 16:04:28 +00:00
|
|
|
case LFUN_HOME:
|
|
|
|
for(; actpos > rows[actrow].pos; --actpos)
|
|
|
|
cx -= SingleWidth(bv->getPainter(), par, actpos);
|
|
|
|
cx -= SingleWidth(bv->getPainter(), par, actpos);
|
|
|
|
if (hasSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LFUN_END:
|
|
|
|
{
|
|
|
|
int checkpos = (int)rows[actrow + 1].pos;
|
|
|
|
if ((actrow + 2) < (int)rows.size())
|
|
|
|
--checkpos;
|
|
|
|
for(; actpos < checkpos; ++actpos)
|
|
|
|
cx += SingleWidth(bv->getPainter(), par, actpos);
|
|
|
|
if (hasSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LFUN_MATH_MODE: // Open or create a math inset
|
|
|
|
InsertInset(bv, new InsetFormula);
|
|
|
|
if (hasSelection()) {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else {
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
}
|
|
|
|
return DISPATCHED;
|
|
|
|
case LFUN_BREAKLINE:
|
|
|
|
par->InsertChar(actpos,LyXParagraph::META_NEWLINE);
|
|
|
|
par->SetFont(actpos,real_current_font);
|
|
|
|
UpdateLocal(bv, true);
|
|
|
|
++actpos;
|
|
|
|
selection_start = selection_end = actpos;
|
|
|
|
resetPos(bv);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = UNDISPATCHED;
|
|
|
|
break;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
if (result != FINISHED) {
|
|
|
|
if (!the_locking_inset)
|
|
|
|
ShowInsetCursor(bv);
|
|
|
|
} else
|
|
|
|
bv->unlockInset(this);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-09 23:58:55 +00:00
|
|
|
int InsetText::Latex(ostream & os, signed char /*fragile*/, bool) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-03-02 02:19:43 +00:00
|
|
|
TexRow texrow;
|
2000-03-06 02:42:40 +00:00
|
|
|
int ret = par->SimpleTeXOnePar(os, texrow);
|
2000-03-02 02:19:43 +00:00
|
|
|
return ret;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::Validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
par->validate(features);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns the width of a character at a certain spot
|
2000-02-25 16:05:26 +00:00
|
|
|
int InsetText::SingleWidth(Painter & pain, LyXParagraph * par, int pos) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-02-25 13:35:38 +00:00
|
|
|
LyXFont font = GetFont(par, pos);
|
|
|
|
char c = par->GetChar(pos);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
if (IsPrintable(c)) {
|
|
|
|
return font.width(c);
|
|
|
|
} else if (c == LyXParagraph::META_INSET) {
|
2000-02-29 02:19:17 +00:00
|
|
|
Inset const * tmpinset = par->GetInset(pos);
|
2000-02-25 12:06:15 +00:00
|
|
|
if (tmpinset)
|
2000-02-25 16:05:26 +00:00
|
|
|
return tmpinset->width(pain, font);
|
2000-02-25 12:06:15 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
} else if (IsSeparatorChar(c))
|
|
|
|
c = ' ';
|
|
|
|
else if (IsNewlineChar(c))
|
|
|
|
c = 'n';
|
|
|
|
return font.width(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns the width of a character at a certain spot
|
2000-02-25 16:05:26 +00:00
|
|
|
void InsetText::SingleHeight(Painter & pain, LyXParagraph * par,int pos,
|
|
|
|
int & asc, int & desc) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-02-25 13:35:38 +00:00
|
|
|
LyXFont font = GetFont(par, pos);
|
|
|
|
char c = par->GetChar(pos);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
asc = desc = 0;
|
|
|
|
if (c == LyXParagraph::META_INSET) {
|
|
|
|
Inset const * tmpinset=par->GetInset(pos);
|
|
|
|
if (tmpinset) {
|
2000-02-25 16:05:26 +00:00
|
|
|
asc = tmpinset->ascent(pain, font);
|
|
|
|
desc = tmpinset->descent(pain, font);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
asc = font.maxAscent();
|
|
|
|
desc = font.maxDescent();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gets the fully instantiated font at a given position in a paragraph
|
|
|
|
// Basically the same routine as LyXParagraph::getFont() in paragraph.C.
|
|
|
|
// The difference is that this one is used for displaying, and thus we
|
|
|
|
// are allowed to make cosmetic improvements. For instance make footnotes
|
|
|
|
// smaller. (Asger)
|
|
|
|
// If position is -1, we get the layout font of the paragraph.
|
|
|
|
// If position is -2, we get the font of the manual label of the paragraph.
|
|
|
|
LyXFont InsetText::GetFont(LyXParagraph * par, int pos) const
|
|
|
|
{
|
|
|
|
char par_depth = par->GetDepth();
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
LyXLayout const & layout =
|
2000-02-25 12:06:15 +00:00
|
|
|
textclasslist.Style(buffer->params.textclass, par->GetLayout());
|
|
|
|
|
|
|
|
// We specialize the 95% common case:
|
|
|
|
if (par->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
|
|
|
|
if (pos >= 0) {
|
|
|
|
// 95% goes here
|
|
|
|
if (layout.labeltype == LABEL_MANUAL
|
|
|
|
&& pos < BeginningOfMainBody(par)) {
|
|
|
|
// 1% goes here
|
|
|
|
return par->GetFontSettings(pos).realize(layout.reslabelfont);
|
|
|
|
} else
|
|
|
|
return par->GetFontSettings(pos).realize(layout.resfont);
|
|
|
|
} else {
|
|
|
|
// 5% goes here.
|
|
|
|
// process layoutfont for pos == -1 and labelfont for pos < -1
|
|
|
|
if (pos == -1)
|
|
|
|
return layout.resfont;
|
|
|
|
else
|
|
|
|
return layout.reslabelfont;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// The uncommon case need not be optimized as much
|
|
|
|
|
|
|
|
LyXFont layoutfont, tmpfont;
|
|
|
|
|
|
|
|
if (pos >= 0){
|
|
|
|
// 95% goes here
|
|
|
|
if (pos < BeginningOfMainBody(par)) {
|
|
|
|
// 1% goes here
|
|
|
|
layoutfont = layout.labelfont;
|
|
|
|
} else {
|
|
|
|
// 99% goes here
|
|
|
|
layoutfont = layout.font;
|
|
|
|
}
|
|
|
|
tmpfont = par->GetFontSettings(pos);
|
|
|
|
tmpfont.realize(layoutfont);
|
|
|
|
} else{
|
|
|
|
// 5% goes here.
|
|
|
|
// process layoutfont for pos == -1 and labelfont for pos < -1
|
|
|
|
if (pos == -1)
|
|
|
|
tmpfont = layout.font;
|
|
|
|
else
|
|
|
|
tmpfont = layout.labelfont;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resolve against environment font information
|
|
|
|
//if (par->GetDepth()){ // already in while condition
|
|
|
|
while (par && par_depth && !tmpfont.resolved()) {
|
|
|
|
par = par->DepthHook(par_depth - 1);
|
|
|
|
if (par) {
|
|
|
|
tmpfont.realize(textclasslist.Style(buffer->params.textclass,
|
|
|
|
par->GetLayout()).font);
|
|
|
|
par_depth = par->GetDepth();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tmpfont.realize((textclasslist.TextClass(buffer->params.textclass).
|
|
|
|
defaultfont()));
|
|
|
|
return tmpfont;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetText::BeginningOfMainBody(LyXParagraph * par) const
|
|
|
|
{
|
|
|
|
if (textclasslist.Style(buffer->params.textclass,
|
|
|
|
par->GetLayout()).labeltype != LABEL_MANUAL)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return par->BeginningOfMainBody();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 16:42:21 +00:00
|
|
|
void InsetText::GetCursorPos(int & x, int & y) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
|
|
|
x = cx;
|
|
|
|
y = cy;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetText::InsetInInsetY()
|
|
|
|
{
|
|
|
|
if (!the_locking_inset)
|
|
|
|
return 0;
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
int y = inset_y;
|
2000-02-25 12:06:15 +00:00
|
|
|
return (y + the_locking_inset->InsetInInsetY());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::ToggleInsetCursor(BufferView * bv)
|
|
|
|
{
|
|
|
|
if (the_locking_inset) {
|
|
|
|
the_locking_inset->ToggleInsetCursor(bv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
LyXFont font = GetFont(par, actpos);
|
|
|
|
|
|
|
|
int asc = font.maxAscent();
|
|
|
|
int desc = font.maxDescent();
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
if (cursor_visible)
|
|
|
|
bv->hideLockedInsetCursor();
|
|
|
|
else
|
|
|
|
bv->showLockedInsetCursor(cx, cy, asc, desc);
|
|
|
|
cursor_visible = !cursor_visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::ShowInsetCursor(BufferView * bv)
|
|
|
|
{
|
|
|
|
if (!cursor_visible) {
|
2000-02-25 13:35:38 +00:00
|
|
|
LyXFont font = GetFont(par, actpos);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
int asc = font.maxAscent();
|
|
|
|
int desc = font.maxDescent();
|
2000-02-25 12:06:15 +00:00
|
|
|
bv->fitLockedInsetCursor(cx, cy, asc, desc);
|
|
|
|
bv->showLockedInsetCursor(cx, cy, asc, desc);
|
|
|
|
cursor_visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::HideInsetCursor(BufferView * bv)
|
|
|
|
{
|
|
|
|
if (cursor_visible)
|
|
|
|
ToggleInsetCursor(bv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
|
|
|
|
{
|
2000-03-09 16:04:28 +00:00
|
|
|
int ox = x;
|
|
|
|
int oy = y;
|
2000-02-29 02:19:17 +00:00
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
// search right X-pos x==0 -> top_x
|
|
|
|
actpos = actrow = 0;
|
|
|
|
cy = top_baseline;
|
|
|
|
y += cy;
|
2000-02-25 13:35:38 +00:00
|
|
|
for(unsigned int i = 1;
|
|
|
|
((cy + rows[i - 1].desc) < y) && (i < rows.size() - 1); ++i) {
|
2000-02-25 12:06:15 +00:00
|
|
|
cy = rows[i].baseline;
|
|
|
|
actpos = rows[i].pos;
|
|
|
|
actrow = i;
|
|
|
|
}
|
|
|
|
cy -= top_baseline;
|
|
|
|
cx = top_x;
|
|
|
|
x += top_x;
|
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
int swh;
|
2000-03-09 16:04:28 +00:00
|
|
|
int sw;
|
|
|
|
int checkpos;
|
|
|
|
|
|
|
|
sw = swh = SingleWidth(bv->getPainter(), par,actpos);
|
2000-02-25 12:06:15 +00:00
|
|
|
if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
|
|
|
|
swh /= 2;
|
2000-03-09 16:04:28 +00:00
|
|
|
checkpos = rows[actrow + 1].pos;
|
|
|
|
if ((actrow+2) < (int)rows.size())
|
|
|
|
--checkpos;
|
|
|
|
while ((actpos < checkpos) && ((cx + swh) < x)) {
|
2000-02-25 12:06:15 +00:00
|
|
|
cx += sw;
|
|
|
|
++actpos;
|
2000-02-25 16:05:26 +00:00
|
|
|
sw = swh = SingleWidth(bv->getPainter(), par,actpos);
|
2000-02-25 12:06:15 +00:00
|
|
|
if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
|
|
|
|
swh /= 2;
|
|
|
|
}
|
|
|
|
if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
|
2000-02-25 13:35:38 +00:00
|
|
|
the_locking_inset =
|
|
|
|
static_cast<UpdatableInset*>(par->GetInset(actpos));
|
|
|
|
inset_x = cx - top_x;
|
2000-02-25 12:06:15 +00:00
|
|
|
inset_y = cy;
|
|
|
|
inset_pos = actpos;
|
|
|
|
the_locking_inset->Edit(bv, ox - inset_x, oy - inset_y, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::moveRight(BufferView * bv, bool activate_inset)
|
|
|
|
{
|
|
|
|
if (actpos >= par->Last())
|
|
|
|
return false;
|
|
|
|
if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
|
2000-02-25 13:35:38 +00:00
|
|
|
the_locking_inset =
|
|
|
|
static_cast<UpdatableInset*>(par->GetInset(actpos));
|
|
|
|
inset_x = cx - top_x;
|
2000-02-25 12:06:15 +00:00
|
|
|
inset_y = cy;
|
|
|
|
inset_pos = actpos;
|
|
|
|
the_locking_inset->Edit(bv, 0, 0, 0);
|
|
|
|
} else {
|
|
|
|
++actpos;
|
|
|
|
resetPos(bv);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::moveLeft(BufferView * bv, bool activate_inset)
|
|
|
|
{
|
|
|
|
if (actpos <= 0)
|
|
|
|
return false;
|
|
|
|
--actpos;
|
|
|
|
if (activate_inset && par->GetChar(actpos)==LyXParagraph::META_INSET) {
|
2000-02-25 13:35:38 +00:00
|
|
|
the_locking_inset =
|
|
|
|
static_cast<UpdatableInset*>(par->GetInset(actpos));
|
2000-02-25 12:06:15 +00:00
|
|
|
resetPos(bv);
|
2000-02-25 13:35:38 +00:00
|
|
|
inset_x = cx - top_x;
|
2000-02-25 12:06:15 +00:00
|
|
|
inset_y = cy;
|
|
|
|
inset_pos = actpos;
|
|
|
|
the_locking_inset->Edit(bv, the_locking_inset->
|
2000-02-25 13:35:38 +00:00
|
|
|
width(bv->getPainter(), GetFont(par,actpos)),
|
2000-02-25 12:06:15 +00:00
|
|
|
0, 0);
|
|
|
|
} else {
|
|
|
|
resetPos(bv);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::moveUp(BufferView * bv, bool activate_inset)
|
|
|
|
{
|
|
|
|
if (!actrow)
|
|
|
|
return false;
|
2000-02-25 13:35:38 +00:00
|
|
|
cy = rows[actrow - 1].baseline - top_baseline;
|
|
|
|
setPos(bv, cx - top_x, cy, activate_inset);
|
2000-02-25 12:06:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::moveDown(BufferView * bv, bool activate_inset)
|
|
|
|
{
|
2000-02-25 13:35:38 +00:00
|
|
|
if (actrow >= int(rows.size() - 2))
|
2000-02-25 12:06:15 +00:00
|
|
|
return false;
|
2000-02-25 13:35:38 +00:00
|
|
|
cy = rows[actrow + 1].baseline - top_baseline;
|
|
|
|
setPos(bv, cx - top_x, cy, activate_inset);
|
2000-02-25 12:06:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::resetPos(BufferView * bv)
|
|
|
|
{
|
2000-03-27 15:13:47 +00:00
|
|
|
if (!rows.size())
|
|
|
|
return;
|
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
int old_pos = actpos;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
cy = top_baseline;
|
|
|
|
actrow = 0;
|
2000-03-09 16:04:28 +00:00
|
|
|
for(unsigned int i = 0; (i < (rows.size()-1)) && (rows[i].pos <= actpos);
|
|
|
|
++i) {
|
2000-02-25 12:06:15 +00:00
|
|
|
cy = rows[i].baseline;
|
|
|
|
actrow = i;
|
|
|
|
}
|
|
|
|
cy -= top_baseline;
|
|
|
|
setPos(bv, 0, cy, false);
|
|
|
|
cx = top_x;
|
|
|
|
while(actpos < old_pos) {
|
2000-02-25 16:05:26 +00:00
|
|
|
cx += SingleWidth(bv->getPainter(), par,actpos);
|
2000-02-25 12:06:15 +00:00
|
|
|
++actpos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::Delete()
|
|
|
|
{
|
|
|
|
/* some insets are undeletable here */
|
|
|
|
if (par->GetChar(actpos)==LyXParagraph::META_INSET) {
|
|
|
|
/* force complete redo when erasing display insets */
|
2000-03-27 15:13:47 +00:00
|
|
|
/* this is a cruel method but save..... Matthias */
|
2000-02-25 12:06:15 +00:00
|
|
|
if (par->GetInset(actpos)->Deletable() &&
|
|
|
|
par->GetInset(actpos)->display()) {
|
|
|
|
par->Erase(actpos);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
par->Erase(actpos);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::InsertInset(BufferView * bv, Inset * inset)
|
|
|
|
{
|
2000-03-08 13:52:57 +00:00
|
|
|
if (inset->Editable() == Inset::IS_EDITABLE) {
|
|
|
|
UpdatableInset *i = (UpdatableInset *)inset;
|
|
|
|
i->setOwner((UpdatableInset *)this);
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
par->InsertChar(actpos, LyXParagraph::META_INSET);
|
|
|
|
par->InsertInset(actpos, inset);
|
2000-03-08 13:52:57 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-02-25 13:35:38 +00:00
|
|
|
the_locking_inset = static_cast<UpdatableInset*>(inset);
|
|
|
|
inset_x = cx - top_x;
|
2000-02-25 12:06:15 +00:00
|
|
|
inset_y = cy;
|
|
|
|
inset_pos = actpos;
|
|
|
|
inset->Edit(bv, 0, 0, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UpdatableInset * InsetText::GetLockingInset()
|
|
|
|
{
|
|
|
|
return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
|
|
|
// if there is no selection just set the current_font
|
|
|
|
if (!hasSelection()) {
|
|
|
|
// Determine basis font
|
|
|
|
LyXFont layoutfont;
|
|
|
|
if (actpos < BeginningOfMainBody(par))
|
|
|
|
layoutfont = GetFont(par, -2);
|
|
|
|
else
|
|
|
|
layoutfont = GetFont(par, -1);
|
|
|
|
|
|
|
|
// Update current font
|
2000-03-17 10:14:46 +00:00
|
|
|
real_current_font.update(font, bv->buffer()->params.language_info,
|
|
|
|
toggleall);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
// Reduce to implicit settings
|
|
|
|
current_font = real_current_font;
|
|
|
|
current_font.reduce(layoutfont);
|
|
|
|
// And resolve it completely
|
|
|
|
real_current_font.realize(layoutfont);
|
|
|
|
return;
|
|
|
|
}
|
2000-02-25 13:35:38 +00:00
|
|
|
|
|
|
|
int s_start, s_end;
|
2000-02-25 12:06:15 +00:00
|
|
|
if (selection_start > selection_end) {
|
|
|
|
s_start = selection_end;
|
|
|
|
s_end = selection_start;
|
|
|
|
} else {
|
|
|
|
s_start = selection_start;
|
|
|
|
s_end = selection_end;
|
|
|
|
}
|
2000-02-25 13:35:38 +00:00
|
|
|
LyXFont newfont;
|
2000-02-25 12:06:15 +00:00
|
|
|
while(s_start < s_end) {
|
|
|
|
newfont = GetFont(par,s_start);
|
2000-03-17 10:14:46 +00:00
|
|
|
newfont.update(font, bv->buffer()->params.language_info, toggleall);
|
2000-02-25 12:06:15 +00:00
|
|
|
SetCharFont(s_start, newfont);
|
|
|
|
++s_start;
|
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
void InsetText::SetCharFont(int pos, LyXFont const & f)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-02-25 13:35:38 +00:00
|
|
|
/* let the insets convert their font */
|
|
|
|
LyXFont font(f);
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
if (par->GetChar(pos) == LyXParagraph::META_INSET) {
|
|
|
|
if (par->GetInset(pos))
|
|
|
|
font = par->GetInset(pos)->ConvertFont(font);
|
|
|
|
}
|
2000-02-29 02:19:17 +00:00
|
|
|
LyXLayout const & layout =
|
2000-02-25 12:06:15 +00:00
|
|
|
textclasslist.Style(buffer->params.textclass,par->GetLayout());
|
|
|
|
|
|
|
|
// Get concrete layout font to reduce against
|
|
|
|
LyXFont layoutfont;
|
|
|
|
|
|
|
|
if (pos < BeginningOfMainBody(par))
|
|
|
|
layoutfont = layout.labelfont;
|
|
|
|
else
|
|
|
|
layoutfont = layout.font;
|
|
|
|
|
|
|
|
|
|
|
|
layoutfont.realize((textclasslist.TextClass(buffer->params.textclass).
|
|
|
|
defaultfont()));
|
|
|
|
|
|
|
|
// Now, reduce font against full layout font
|
|
|
|
font.reduce(layoutfont);
|
|
|
|
|
|
|
|
par->SetFont(pos, font);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
void InsetText::computeTextRows(Painter & pain, float x) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-02-25 13:35:38 +00:00
|
|
|
int p,
|
2000-02-25 12:06:15 +00:00
|
|
|
nwp = 0,
|
|
|
|
asc = 0,
|
|
|
|
desc = 0,
|
|
|
|
oasc = 0,
|
|
|
|
odesc = 0,
|
|
|
|
owidth = 0,
|
|
|
|
wordAscent,
|
|
|
|
wordDescent;
|
2000-02-25 13:35:38 +00:00
|
|
|
row_struct row;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
if (rows.size())
|
2000-03-06 02:42:40 +00:00
|
|
|
rows.clear();
|
2000-02-25 13:35:38 +00:00
|
|
|
int width = wordAscent = wordDescent = 0;
|
2000-02-25 12:06:15 +00:00
|
|
|
insetWidth = maxAscent = maxDescent = 0;
|
|
|
|
row.asc = 0;
|
|
|
|
row.desc = 0;
|
|
|
|
row.pos = 0;
|
|
|
|
row.baseline = 0;
|
|
|
|
rows.push_back(row);
|
2000-03-02 18:30:01 +00:00
|
|
|
if (!autoBreakRows) {
|
2000-02-29 02:19:17 +00:00
|
|
|
for(p = 0; p < par->Last(); ++p) {
|
2000-02-25 16:05:26 +00:00
|
|
|
insetWidth += SingleWidth(pain, par, p);
|
|
|
|
SingleHeight(pain, par, p, asc, desc);
|
2000-03-06 02:42:40 +00:00
|
|
|
maxAscent = max(maxAscent, asc);
|
|
|
|
maxDescent = max(maxDescent, desc);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
rows[0].asc = maxAscent;
|
|
|
|
rows[0].desc = maxDescent;
|
|
|
|
// alocate a dummy row for the endpos
|
|
|
|
row.pos = par->Last();
|
|
|
|
rows.push_back(row);
|
|
|
|
return;
|
|
|
|
}
|
2000-03-02 18:30:01 +00:00
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
bool is_first_word_in_row = true;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
int cw, lastWordWidth = 0;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-03-09 16:04:28 +00:00
|
|
|
maxWidth = getMaxWidth(pain) - widthOffset;
|
2000-02-25 12:06:15 +00:00
|
|
|
for(p = 0; p < par->Last(); ++p) {
|
2000-02-25 16:05:26 +00:00
|
|
|
cw = SingleWidth(pain, par, p);
|
2000-02-25 12:06:15 +00:00
|
|
|
width += cw;
|
|
|
|
lastWordWidth += cw;
|
2000-02-25 16:05:26 +00:00
|
|
|
SingleHeight(pain, par, p, asc, desc);
|
2000-03-06 02:42:40 +00:00
|
|
|
wordAscent = max(wordAscent, asc);
|
|
|
|
wordDescent = max(wordDescent, desc);
|
2000-03-09 16:04:28 +00:00
|
|
|
if (par->IsNewline(p)) {
|
|
|
|
rows.back().asc = wordAscent;
|
|
|
|
rows.back().desc = wordDescent;
|
|
|
|
row.pos = p+1;
|
|
|
|
rows.push_back(row);
|
|
|
|
SingleHeight(pain, par, p, oasc, odesc);
|
|
|
|
width = lastWordWidth = 0;
|
|
|
|
is_first_word_in_row = true;
|
|
|
|
wordAscent = wordDescent = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
Inset const * inset = 0;
|
|
|
|
if (((p + 1) < par->Last()) &&
|
2000-02-29 02:19:17 +00:00
|
|
|
(par->GetChar(p + 1)==LyXParagraph::META_INSET))
|
|
|
|
inset = par->GetInset(p + 1);
|
2000-02-25 12:06:15 +00:00
|
|
|
if (inset && inset->display()) {
|
2000-03-08 13:52:57 +00:00
|
|
|
if (!is_first_word_in_row && (width >= (maxWidth - x))) {
|
2000-02-25 12:06:15 +00:00
|
|
|
// we have to split also the row above
|
2000-03-06 02:42:40 +00:00
|
|
|
rows.back().asc = oasc;
|
|
|
|
rows.back().desc = odesc;
|
2000-02-25 12:06:15 +00:00
|
|
|
row.pos = nwp;
|
|
|
|
rows.push_back(row);
|
|
|
|
oasc = wordAscent;
|
|
|
|
odesc = wordDescent;
|
2000-03-06 02:42:40 +00:00
|
|
|
insetWidth = max(insetWidth, owidth);
|
2000-02-25 12:06:15 +00:00
|
|
|
width = lastWordWidth;
|
|
|
|
lastWordWidth = 0;
|
|
|
|
} else {
|
2000-03-06 02:42:40 +00:00
|
|
|
oasc = max(oasc, wordAscent);
|
|
|
|
odesc = max(odesc, wordDescent);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
rows.back().asc = oasc;
|
|
|
|
rows.back().desc = odesc;
|
2000-02-25 12:06:15 +00:00
|
|
|
row.pos = ++p;
|
|
|
|
rows.push_back(row);
|
2000-02-25 16:05:26 +00:00
|
|
|
SingleHeight(pain, par, p, asc, desc);
|
2000-03-06 02:42:40 +00:00
|
|
|
rows.back().asc = asc;
|
|
|
|
rows.back().desc = desc;
|
2000-02-25 12:06:15 +00:00
|
|
|
row.pos = nwp = p + 1;
|
|
|
|
rows.push_back(row);
|
|
|
|
oasc = odesc = width = lastWordWidth = 0;
|
|
|
|
is_first_word_in_row = true;
|
|
|
|
wordAscent = wordDescent = 0;
|
|
|
|
continue;
|
|
|
|
} else if (par->IsSeparator(p)) {
|
2000-03-06 02:42:40 +00:00
|
|
|
if (width >= maxWidth - x) {
|
2000-02-25 12:06:15 +00:00
|
|
|
if (is_first_word_in_row) {
|
2000-03-06 02:42:40 +00:00
|
|
|
rows.back().asc = wordAscent;
|
|
|
|
rows.back().desc = wordDescent;
|
2000-02-29 02:19:17 +00:00
|
|
|
row.pos = p + 1;
|
2000-02-25 12:06:15 +00:00
|
|
|
rows.push_back(row);
|
|
|
|
oasc = odesc = width = 0;
|
|
|
|
} else {
|
2000-03-06 02:42:40 +00:00
|
|
|
rows.back().asc = oasc;
|
|
|
|
rows.back().desc = odesc;
|
2000-02-25 12:06:15 +00:00
|
|
|
row.pos = nwp;
|
|
|
|
rows.push_back(row);
|
|
|
|
oasc = wordAscent;
|
|
|
|
odesc = wordDescent;
|
2000-03-06 02:42:40 +00:00
|
|
|
insetWidth = max(insetWidth, owidth);
|
2000-02-25 12:06:15 +00:00
|
|
|
width = lastWordWidth;
|
|
|
|
}
|
|
|
|
wordAscent = wordDescent = lastWordWidth = 0;
|
2000-02-29 02:19:17 +00:00
|
|
|
nwp = p + 1;
|
2000-02-25 12:06:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
owidth = width;
|
2000-03-06 02:42:40 +00:00
|
|
|
oasc = max(oasc, wordAscent);
|
|
|
|
odesc = max(odesc, wordDescent);
|
2000-02-25 12:06:15 +00:00
|
|
|
wordAscent = wordDescent = lastWordWidth = 0;
|
2000-02-29 02:19:17 +00:00
|
|
|
nwp = p + 1;
|
2000-02-25 12:06:15 +00:00
|
|
|
is_first_word_in_row = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if we have some data in the paragraph we have ascent/descent
|
|
|
|
if (p) {
|
2000-03-08 13:52:57 +00:00
|
|
|
if (width >= (maxWidth - x)) {
|
2000-02-25 12:06:15 +00:00
|
|
|
// assign upper row
|
2000-03-06 02:42:40 +00:00
|
|
|
rows.back().asc = oasc;
|
|
|
|
rows.back().desc = odesc;
|
2000-02-25 12:06:15 +00:00
|
|
|
// assign and allocate lower row
|
|
|
|
row.pos = nwp;
|
|
|
|
rows.push_back(row);
|
2000-03-06 02:42:40 +00:00
|
|
|
rows.back().asc = wordAscent;
|
|
|
|
rows.back().desc = wordDescent;
|
2000-03-08 13:52:57 +00:00
|
|
|
width -= lastWordWidth;
|
2000-02-25 12:06:15 +00:00
|
|
|
} else {
|
|
|
|
// assign last row data
|
2000-03-08 13:52:57 +00:00
|
|
|
// width = lastWordWidth;
|
|
|
|
// lastWordWidth = 0;
|
|
|
|
rows.back().asc = max(oasc, wordAscent);
|
|
|
|
rows.back().desc = max(odesc, wordDescent);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
insetWidth = max(insetWidth, width);
|
2000-02-25 12:06:15 +00:00
|
|
|
// alocate a dummy row for the endpos
|
|
|
|
row.pos = par->Last();
|
|
|
|
rows.push_back(row);
|
|
|
|
// calculate maxAscent/Descent
|
|
|
|
maxAscent = rows[0].asc;
|
|
|
|
maxDescent = rows[0].desc;
|
2000-03-06 02:42:40 +00:00
|
|
|
for (RowList::size_type i = 1; i < rows.size() - 1; ++i) {
|
2000-02-25 12:06:15 +00:00
|
|
|
maxDescent += rows[i].asc + rows[i].desc + interline_space;
|
|
|
|
}
|
2000-02-25 16:05:26 +00:00
|
|
|
#if 0
|
2000-02-25 12:06:15 +00:00
|
|
|
if (the_locking_inset) {
|
|
|
|
computeBaselines(top_baseline);
|
|
|
|
actpos = inset_pos;
|
|
|
|
resetPos(bv);
|
2000-02-29 02:19:17 +00:00
|
|
|
inset_x = cx - top_x;
|
2000-02-25 12:06:15 +00:00
|
|
|
inset_y = cy;
|
|
|
|
}
|
2000-02-25 16:05:26 +00:00
|
|
|
#endif
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
void InsetText::computeBaselines(int baseline) const
|
|
|
|
{
|
|
|
|
rows[0].baseline = baseline;
|
2000-02-29 02:19:17 +00:00
|
|
|
for (unsigned int i = 1; i < rows.size() - 1; i++) {
|
|
|
|
rows[i].baseline = rows[i - 1].baseline + rows[i - 1].desc +
|
2000-02-25 12:06:15 +00:00
|
|
|
rows[i].asc + interline_space;
|
|
|
|
}
|
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
|
|
|
|
void InsetText::UpdateLocal(BufferView *bv, bool flag)
|
|
|
|
{
|
2000-03-27 15:13:47 +00:00
|
|
|
HideInsetCursor(bv);
|
|
|
|
if (flag) {
|
|
|
|
computeTextRows(bv->painter(), xpos);
|
|
|
|
computeBaselines(top_baseline);
|
|
|
|
resetPos(bv);
|
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
bv->updateInset(this, flag);
|
2000-03-27 15:13:47 +00:00
|
|
|
ShowInsetCursor(bv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is for the simple cut and paste mechanism
|
|
|
|
// this then should be a global stuff so that cut'n'paste can work in and
|
|
|
|
// and outside text-insets
|
|
|
|
static LyXParagraph * simple_cut_buffer = 0;
|
|
|
|
// static char simple_cut_buffer_textclass = 0;
|
|
|
|
|
|
|
|
// for now here this should be in another Cut&Paste Class!
|
|
|
|
//
|
|
|
|
static void DeleteSimpleCutBuffer()
|
|
|
|
{
|
|
|
|
if (!simple_cut_buffer)
|
|
|
|
return;
|
|
|
|
LyXParagraph * tmppar;
|
|
|
|
|
|
|
|
while (simple_cut_buffer) {
|
|
|
|
tmppar = simple_cut_buffer;
|
|
|
|
simple_cut_buffer = simple_cut_buffer->next;
|
|
|
|
delete tmppar;
|
|
|
|
}
|
|
|
|
simple_cut_buffer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InsetText::cutSelection()
|
|
|
|
{
|
|
|
|
if (!hasSelection())
|
|
|
|
return false;
|
|
|
|
DeleteSimpleCutBuffer();
|
|
|
|
|
|
|
|
// only within one paragraph
|
|
|
|
simple_cut_buffer = new LyXParagraph;
|
|
|
|
LyXParagraph::size_type i = selection_start;
|
|
|
|
for (; i < selection_end; ++i) {
|
|
|
|
par->CopyIntoMinibuffer(selection_start);
|
|
|
|
par->Erase(selection_start);
|
|
|
|
simple_cut_buffer->InsertFromMinibuffer(simple_cut_buffer->Last());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InsetText::copySelection()
|
|
|
|
{
|
|
|
|
if (!hasSelection())
|
|
|
|
return false;
|
|
|
|
DeleteSimpleCutBuffer();
|
|
|
|
|
|
|
|
// only within one paragraph
|
|
|
|
simple_cut_buffer = new LyXParagraph;
|
|
|
|
LyXParagraph::size_type i = selection_start;
|
|
|
|
for (; i < selection_end; ++i) {
|
|
|
|
par->CopyIntoMinibuffer(i);
|
|
|
|
simple_cut_buffer->InsertFromMinibuffer(simple_cut_buffer->Last());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InsetText::pasteSelection()
|
|
|
|
{
|
|
|
|
if (!simple_cut_buffer)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LyXParagraph * tmppar = simple_cut_buffer->Clone();
|
|
|
|
|
|
|
|
while (simple_cut_buffer->size()) {
|
|
|
|
simple_cut_buffer->CutIntoMinibuffer(0);
|
|
|
|
simple_cut_buffer->Erase(0);
|
|
|
|
par->InsertFromMinibuffer(actpos);
|
|
|
|
++actpos;
|
|
|
|
}
|
|
|
|
delete simple_cut_buffer;
|
|
|
|
simple_cut_buffer = tmppar;
|
|
|
|
return true;
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|