2000-02-25 12:06:15 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2000-04-19 14:42:19 +00:00
|
|
|
* Copyright 1998-2000 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
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "insettext.h"
|
2000-05-15 14:49:36 +00:00
|
|
|
#include "lyxparagraph.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
#include "lyxlex.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "lyxfont.h"
|
|
|
|
#include "commandtags.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "layout.h"
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "Painter.h"
|
|
|
|
#include "lyx_gui_misc.h"
|
2000-03-28 16:18:02 +00:00
|
|
|
#include "lyxtext.h"
|
|
|
|
#include "lyxcursor.h"
|
2000-04-10 14:29:05 +00:00
|
|
|
#include "CutAndPaste.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
#include "font.h"
|
2000-05-04 08:14:34 +00:00
|
|
|
#include "minibuffer.h"
|
|
|
|
#include "toolbar.h"
|
2000-05-15 14:49:36 +00:00
|
|
|
#include "LColor.h"
|
|
|
|
#include "support/textutils.h"
|
|
|
|
#include "support/LAssert.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
#include "lyxrow.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
|
|
|
|
using std::ostream;
|
|
|
|
using std::ifstream;
|
2000-04-24 20:58:23 +00:00
|
|
|
using std::endl;
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::min;
|
|
|
|
using std::max;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
extern unsigned char getCurrentTextClass(Buffer *);
|
2000-06-12 11:27:15 +00:00
|
|
|
#warning BAAAAAAAADDDDDDD current_view (but Lars wanted it :) !!!
|
|
|
|
extern BufferView * current_view;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
InsetText::InsetText()
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
|
|
|
par = new LyXParagraph();
|
2000-06-12 11:27:15 +00:00
|
|
|
init();
|
|
|
|
text = new LyXText(this);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
InsetText::InsetText(InsetText const & ins) : UpdatableInset()
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-03-28 16:18:02 +00:00
|
|
|
par = 0;
|
2000-06-12 11:27:15 +00:00
|
|
|
init(&ins);
|
|
|
|
text = new LyXText(this);
|
2000-04-10 14:29:05 +00:00
|
|
|
autoBreakRows = ins.autoBreakRows;
|
2000-03-28 16:18:02 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
InsetText & InsetText::operator=(InsetText const & it)
|
|
|
|
{
|
|
|
|
init(&it);
|
|
|
|
text = new LyXText(this);
|
|
|
|
autoBreakRows = it.autoBreakRows;
|
|
|
|
return * this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InsetText::init(InsetText const * ins)
|
2000-03-28 16:18:02 +00:00
|
|
|
{
|
2000-02-25 12:06:15 +00:00
|
|
|
the_locking_inset = 0;
|
|
|
|
cursor_visible = false;
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.x_fix(-1);
|
2000-02-25 12:06:15 +00:00
|
|
|
interline_space = 1;
|
|
|
|
no_selection = false;
|
|
|
|
init_inset = true;
|
2000-03-31 10:35:53 +00:00
|
|
|
maxAscent = maxDescent = insetWidth = 0;
|
2000-04-19 14:42:19 +00:00
|
|
|
drawTextXOffset = drawTextYOffset = 0;
|
2000-05-15 14:49:36 +00:00
|
|
|
autoBreakRows = drawLockedFrame = false;
|
2000-03-08 13:52:57 +00:00
|
|
|
xpos = 0.0;
|
2000-04-10 14:29:05 +00:00
|
|
|
if (ins) {
|
2000-05-04 08:14:34 +00:00
|
|
|
SetParagraphData(ins->par);
|
2000-04-10 14:29:05 +00:00
|
|
|
autoBreakRows = ins->autoBreakRows;
|
2000-05-16 15:17:19 +00:00
|
|
|
drawLockedFrame = ins->drawLockedFrame;
|
2000-04-10 14:29:05 +00:00
|
|
|
}
|
|
|
|
par->SetInsetOwner(this);
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.par(par);
|
|
|
|
cursor.pos(0);
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-05-15 14:49:36 +00:00
|
|
|
frame_color = LColor::insetframe;
|
|
|
|
locked = false;
|
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
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
InsetText * t = new InsetText(*this);
|
2000-02-25 12:06:15 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetText::Write(Buffer const * buf, ostream & os) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
|
|
|
os << "Text\n";
|
2000-06-12 11:27:15 +00:00
|
|
|
WriteParagraphData(buf, os);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetText::WriteParagraphData(Buffer const * buf, ostream & os) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
par->writeFile(buf, os, buf->params, 0, 0);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetText::Read(Buffer const * buf, LyXLex & lex)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
|
|
|
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;
|
2000-04-19 14:42:19 +00:00
|
|
|
par->SetInsetOwner(this);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
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-06-12 11:27:15 +00:00
|
|
|
if (const_cast<Buffer*>(buf)->parseSingleLyXformat2Token(lex, par, return_par,
|
|
|
|
token, pos, depth,
|
|
|
|
font, footnoteflag,
|
|
|
|
footnotekind)) {
|
2000-03-01 14:13:21 +00:00
|
|
|
// 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-06-12 11:27:15 +00:00
|
|
|
text->init(current_view);
|
2000-05-15 14:49:36 +00:00
|
|
|
computeTextRows(pain);
|
2000-02-25 16:05:26 +00:00
|
|
|
init_inset = false;
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
long int y_temp = 0;
|
|
|
|
Row * row = text->GetRowNearY(y_temp);
|
2000-06-12 14:58:10 +00:00
|
|
|
return row->ascent_of_text() + 2;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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-06-12 11:27:15 +00:00
|
|
|
text->init(current_view);
|
2000-05-15 14:49:36 +00:00
|
|
|
computeTextRows(pain);
|
2000-02-25 16:05:26 +00:00
|
|
|
init_inset = false;
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
long int y = 0;
|
|
|
|
Row * row = text->GetRowNearY(y);
|
2000-06-12 14:58:10 +00:00
|
|
|
return text->height - row->ascent_of_text() + 2;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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-06-12 11:27:15 +00:00
|
|
|
text->init(current_view);
|
2000-05-15 14:49:36 +00:00
|
|
|
computeTextRows(pain);
|
2000-02-25 16:05:26 +00:00
|
|
|
init_inset = false;
|
|
|
|
}
|
2000-06-12 14:58:10 +00:00
|
|
|
return std::max(static_cast<long int>(getMaxTextWidth(pain, this)),
|
|
|
|
text->width);
|
2000-06-12 11:27:15 +00:00
|
|
|
// return insetWidth;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2000-02-25 12:06:15 +00:00
|
|
|
UpdatableInset::draw(pain, f, baseline, x);
|
2000-02-25 13:35:38 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
if (init_inset) {
|
|
|
|
text->init(current_view);
|
2000-05-15 14:49:36 +00:00
|
|
|
computeTextRows(pain);
|
2000-04-20 13:48:34 +00:00
|
|
|
init_inset = false;
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
if ((baseline != top_baseline) || (top_x != int(x))) {
|
|
|
|
top_baseline = baseline;
|
|
|
|
top_x = int(x);
|
2000-04-20 13:48:34 +00:00
|
|
|
computeBaselines(baseline);
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
if (the_locking_inset && (text->cursor.pos() == inset_pos)) {
|
2000-04-19 14:42:19 +00:00
|
|
|
resetPos(pain);
|
2000-06-12 11:27:15 +00:00
|
|
|
inset_x = text->cursor.x() - top_x + drawTextXOffset;
|
|
|
|
inset_y = text->cursor.y() + drawTextYOffset;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
if (drawLockedFrame && locked) {
|
2000-06-12 14:58:10 +00:00
|
|
|
pain.rectangle(int(x), baseline - ascent(pain, f), width(pain, f),
|
2000-05-15 14:49:36 +00:00
|
|
|
ascent(pain,f) + descent(pain, f), frame_color);
|
|
|
|
}
|
|
|
|
x += TEXT_TO_INSET_OFFSET; // place for border
|
2000-06-12 11:27:15 +00:00
|
|
|
#if 1
|
2000-06-12 14:58:10 +00:00
|
|
|
// Dump all rowinformation:
|
|
|
|
long y_dummy = 0;
|
|
|
|
Row * tmprow = text->GetRowNearY(y_dummy);
|
|
|
|
lyxerr << "Baseline Paragraph Pos Height Ascent Fill\n";
|
|
|
|
while (tmprow) {
|
|
|
|
lyxerr << tmprow->baseline() << '\t'
|
|
|
|
<< tmprow->par() << '\t'
|
|
|
|
<< tmprow->pos() << '\t'
|
|
|
|
<< tmprow->height() << '\t'
|
|
|
|
<< tmprow->ascent_of_text() << '\t'
|
|
|
|
<< tmprow->fill() << '\n';
|
|
|
|
tmprow = tmprow->next();
|
|
|
|
}
|
|
|
|
lyxerr.flush();
|
2000-06-12 11:27:15 +00:00
|
|
|
long int y = 0;
|
|
|
|
Row * row = text->GetRowNearY(y);
|
2000-06-12 14:58:10 +00:00
|
|
|
y += baseline - row->ascent_of_text() + 1;
|
2000-06-12 11:27:15 +00:00
|
|
|
text->width = 0;
|
|
|
|
while (row != 0) {
|
2000-06-12 14:58:10 +00:00
|
|
|
text->GetVisibleRow(current_view, y, x, row, y);
|
2000-06-12 11:27:15 +00:00
|
|
|
y += row->height();
|
|
|
|
row = row->next();
|
|
|
|
}
|
|
|
|
#else
|
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
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
#endif
|
2000-05-15 14:49:36 +00:00
|
|
|
x += insetWidth - TEXT_TO_INSET_OFFSET;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-06-08 23:16:16 +00:00
|
|
|
if (selection_start_cursor.pos() > selection_end_cursor.pos()) {
|
|
|
|
s_start = selection_end_cursor.pos();
|
|
|
|
s_end = selection_start_cursor.pos();
|
2000-02-25 12:06:15 +00:00
|
|
|
} else {
|
2000-06-08 23:16:16 +00:00
|
|
|
s_start = selection_start_cursor.pos();
|
|
|
|
s_end = selection_end_cursor.pos();
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
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-06-12 11:27:15 +00:00
|
|
|
font = GetDrawFont(current_view->buffer(), par, p);
|
2000-02-25 12:06:15 +00:00
|
|
|
if (IsFloatChar(ch)) {
|
|
|
|
// skip for now
|
|
|
|
} else if (ch == LyXParagraph::META_INSET) {
|
|
|
|
Inset const * tmpinset = par->GetInset(p);
|
|
|
|
x += tmpinset->width(pain, font);
|
|
|
|
} else {
|
2000-04-04 00:19:15 +00:00
|
|
|
x += lyxfont::width(ch, font);
|
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);
|
|
|
|
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);
|
2000-06-12 11:27:15 +00:00
|
|
|
LyXFont font = GetDrawFont(current_view->buffer(), 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
|
2000-04-04 00:19:15 +00:00
|
|
|
int wid = lyxfont::width('n', font);
|
|
|
|
int asc = lyxfont::maxAscent(font);
|
2000-03-09 16:04:28 +00:00
|
|
|
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);
|
2000-04-04 00:19:15 +00:00
|
|
|
x += lyxfont::width(ch, font);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2000-04-10 14:29:05 +00:00
|
|
|
par->SetInsetOwner(this);
|
2000-02-25 12:06:15 +00:00
|
|
|
UpdatableInset::Edit(bv, x, y, button);
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
if (!bv->lockInset(this)) {
|
|
|
|
lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
|
|
|
|
return;
|
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
locked = true;
|
2000-02-25 12:06:15 +00:00
|
|
|
the_locking_inset = 0;
|
2000-05-04 08:14:34 +00:00
|
|
|
inset_pos = inset_x = inset_y = 0;
|
2000-04-19 14:42:19 +00:00
|
|
|
setPos(bv->painter(), x, y);
|
|
|
|
checkAndActivateInset(bv, x, y, button);
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-06-12 11:27:15 +00:00
|
|
|
current_font = real_current_font =GetFont(bv->buffer(), par, cursor.pos());
|
2000-03-28 16:18:02 +00:00
|
|
|
bv->text->FinishUndo();
|
2000-04-19 14:42:19 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
void InsetText::InsetUnlock(BufferView * bv)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-04-19 14:42:19 +00:00
|
|
|
if (the_locking_inset) {
|
2000-02-25 12:06:15 +00:00
|
|
|
the_locking_inset->InsetUnlock(bv);
|
2000-04-19 14:42:19 +00:00
|
|
|
the_locking_inset = 0;
|
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
HideInsetCursor(bv);
|
2000-04-19 14:42:19 +00:00
|
|
|
lyxerr[Debug::INSETS] << "InsetText::InsetUnlock(" << this <<
|
|
|
|
")" << endl;
|
2000-05-15 14:49:36 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-02-25 12:06:15 +00:00
|
|
|
no_selection = false;
|
2000-05-15 14:49:36 +00:00
|
|
|
locked = false;
|
|
|
|
UpdateLocal(bv, true);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
|
|
|
|
{
|
|
|
|
lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset(" << inset << "): ";
|
|
|
|
if (!inset)
|
|
|
|
return false;
|
2000-06-12 11:27:15 +00:00
|
|
|
if (inset == par->GetInset(text->cursor.pos())) {
|
2000-04-19 14:42:19 +00:00
|
|
|
lyxerr[Debug::INSETS] << "OK" << endl;
|
|
|
|
the_locking_inset = inset;
|
|
|
|
resetPos(bv->painter());
|
2000-06-12 11:27:15 +00:00
|
|
|
inset_x = text->cursor.x() - top_x + drawTextXOffset;
|
|
|
|
inset_y = text->cursor.y() + drawTextYOffset;
|
|
|
|
inset_pos = text->cursor.pos();
|
2000-04-19 14:42:19 +00:00
|
|
|
return true;
|
|
|
|
} else if (the_locking_inset && (the_locking_inset == inset)) {
|
2000-06-12 11:27:15 +00:00
|
|
|
if (text->cursor.pos() == inset_pos) {
|
2000-04-19 14:42:19 +00:00
|
|
|
lyxerr[Debug::INSETS] << "OK" << endl;
|
|
|
|
resetPos(bv->painter());
|
2000-06-12 11:27:15 +00:00
|
|
|
inset_x = text->cursor.x() - top_x + drawTextXOffset;
|
|
|
|
inset_y = text->cursor.y() + drawTextYOffset;
|
2000-04-19 14:42:19 +00:00
|
|
|
} else {
|
|
|
|
lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
|
|
|
|
}
|
|
|
|
} else if (the_locking_inset) {
|
|
|
|
lyxerr[Debug::INSETS] << "MAYBE" << endl;
|
|
|
|
return the_locking_inset->LockInsetInInset(bv, inset);
|
|
|
|
}
|
|
|
|
lyxerr[Debug::INSETS] << "NOT OK" << endl;
|
|
|
|
return false;
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
|
|
|
|
bool lr)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2000-04-19 14:42:19 +00:00
|
|
|
lyxerr[Debug::INSETS] << "InsetText::UpdateInsetInInset(" << inset <<
|
|
|
|
")" << endl;
|
2000-03-08 13:52:57 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-06-12 11:27:15 +00:00
|
|
|
if (text->cursor.pos() == inset_pos) {
|
|
|
|
inset_x = text->cursor.x() - top_x + drawTextXOffset;
|
|
|
|
inset_y = text->cursor.y() + drawTextYOffset;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
return true;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
|
|
|
|
{
|
|
|
|
if (hasSelection()) {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-08 13:52:57 +00:00
|
|
|
UpdateLocal(bv, false);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
no_selection = false;
|
2000-04-19 14:42:19 +00:00
|
|
|
setPos(bv->painter(), x, y);
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.x_fix(-1);
|
2000-02-25 12:06:15 +00:00
|
|
|
if (the_locking_inset) {
|
2000-06-08 23:16:16 +00:00
|
|
|
UpdatableInset * inset = 0;
|
|
|
|
if (par->GetChar(cursor.pos()) == LyXParagraph::META_INSET)
|
|
|
|
inset = static_cast<UpdatableInset*>(par->GetInset(cursor.pos()));
|
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
|
|
|
|
the_locking_inset->InsetUnlock(bv);
|
2000-06-08 23:16:16 +00:00
|
|
|
inset_x = cursor.x() - top_x + drawTextXOffset;
|
|
|
|
inset_y = cursor.y() + drawTextYOffset;
|
|
|
|
inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
|
2000-04-19 14:42:19 +00:00
|
|
|
inset->Edit(bv, x - inset_x, y - inset_y, button);
|
|
|
|
UpdateLocal(bv, true);
|
2000-02-25 12:06:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// otherwise only unlock the_locking_inset
|
|
|
|
the_locking_inset->InsetUnlock(bv);
|
2000-04-19 14:42:19 +00:00
|
|
|
the_locking_inset = 0;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
if (bv->the_locking_inset) {
|
2000-06-08 23:16:16 +00:00
|
|
|
if ((par->GetChar(cursor.pos()) == LyXParagraph::META_INSET) &&
|
|
|
|
par->GetInset(cursor.pos()) &&
|
|
|
|
(par->GetInset(cursor.pos())->Editable() == Inset::HIGHLY_EDITABLE)) {
|
|
|
|
UpdatableInset * inset =
|
|
|
|
static_cast<UpdatableInset*>(par->GetInset(cursor.pos()));
|
|
|
|
inset_x = cursor.x() - top_x + drawTextXOffset;
|
|
|
|
inset_y = cursor.y() + drawTextYOffset;
|
|
|
|
inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
|
|
|
|
inset->Edit(bv, x - inset_x, y - inset_y, 0);
|
2000-04-19 14:42:19 +00:00
|
|
|
UpdateLocal(bv, true);
|
|
|
|
}
|
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::InsetButtonRelease(BufferView * bv, int x, int y, int button)
|
|
|
|
{
|
|
|
|
UpdatableInset * inset = 0;
|
|
|
|
|
|
|
|
if (the_locking_inset) {
|
|
|
|
the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
|
|
|
|
} else {
|
2000-06-08 23:16:16 +00:00
|
|
|
if (par->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
|
|
|
|
inset = static_cast<UpdatableInset*>(par->GetInset(cursor.pos()));
|
|
|
|
if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
|
|
|
|
inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
|
2000-04-19 14:42:19 +00:00
|
|
|
} else {
|
2000-06-08 23:16:16 +00:00
|
|
|
inset_x = cursor.x() - top_x + drawTextXOffset;
|
|
|
|
inset_y = cursor.y() + drawTextYOffset;
|
|
|
|
inset->InsetButtonRelease(bv, x - inset_x, y - inset_y,button);
|
|
|
|
inset->Edit(bv, x - inset_x, y - inset_y, button);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
no_selection = false;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
|
|
|
if (the_locking_inset) {
|
2000-02-25 13:35:38 +00:00
|
|
|
the_locking_inset->InsetMotionNotify(bv, x - inset_x,
|
2000-04-19 14:42:19 +00:00
|
|
|
y - inset_y,state);
|
2000-02-25 12:06:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!no_selection) {
|
2000-05-04 08:14:34 +00:00
|
|
|
LyXCursor old = selection_end_cursor;
|
2000-04-19 14:42:19 +00:00
|
|
|
HideInsetCursor(bv);
|
|
|
|
setPos(bv->painter(), x, y);
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_end_cursor = cursor;
|
|
|
|
if (old != selection_end_cursor)
|
2000-03-08 13:52:57 +00:00
|
|
|
UpdateLocal(bv, false);
|
2000-04-19 14:42:19 +00:00
|
|
|
ShowInsetCursor(bv);
|
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;
|
2000-04-19 14:42:19 +00:00
|
|
|
UpdatableInset::RESULT
|
|
|
|
result= UpdatableInset::LocalDispatch(bv, action, arg);
|
|
|
|
if (result != UNDISPATCHED) {
|
|
|
|
resetPos(bv->painter());
|
2000-02-25 12:06:15 +00:00
|
|
|
return DISPATCHED;
|
|
|
|
}
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
result=DISPATCHED;
|
2000-02-25 12:06:15 +00:00
|
|
|
if ((action < 0) && arg.empty())
|
|
|
|
return FINISHED;
|
|
|
|
|
|
|
|
if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
|
|
|
|
(action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.x_fix(-1);
|
2000-02-25 12:06:15 +00:00
|
|
|
if (the_locking_inset) {
|
|
|
|
result = the_locking_inset->LocalDispatch(bv, action, arg);
|
2000-04-19 14:42:19 +00:00
|
|
|
if (result == DISPATCHED_NOUPDATE)
|
|
|
|
return result;
|
|
|
|
else if (result == DISPATCHED) {
|
2000-02-25 12:06:15 +00:00
|
|
|
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) {
|
2000-04-19 14:42:19 +00:00
|
|
|
switch(action) {
|
|
|
|
case -1:
|
|
|
|
case LFUN_RIGHT:
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.pos(inset_pos + 1);
|
2000-04-19 14:42:19 +00:00
|
|
|
resetPos(bv->painter());
|
|
|
|
break;
|
|
|
|
case LFUN_DOWN:
|
|
|
|
moveDown(bv);
|
|
|
|
break;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
the_locking_inset = 0;
|
|
|
|
return DISPATCHED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HideInsetCursor(bv);
|
|
|
|
switch (action) {
|
2000-03-09 16:04:28 +00:00
|
|
|
// Normal chars
|
|
|
|
case -1:
|
2000-06-12 11:27:15 +00:00
|
|
|
bv->text->SetUndo(bv->buffer(), Undo::INSERT,
|
2000-06-08 23:16:16 +00:00
|
|
|
bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
|
|
|
|
bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
|
2000-06-12 11:27:15 +00:00
|
|
|
cutSelection(bv->buffer());
|
2000-05-04 08:14:34 +00:00
|
|
|
cursor = selection_start_cursor;
|
2000-06-08 23:16:16 +00:00
|
|
|
par->InsertChar(cursor.pos(), arg[0]);
|
2000-06-12 11:27:15 +00:00
|
|
|
SetCharFont(bv->buffer(), cursor.pos(), current_font);
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.pos(cursor.pos() + 1);
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
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:
|
2000-03-28 16:18:02 +00:00
|
|
|
bv->text->FinishUndo();
|
2000-03-09 16:04:28 +00:00
|
|
|
moveRight(bv, false);
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
break;
|
|
|
|
case LFUN_RIGHT:
|
2000-03-28 16:18:02 +00:00
|
|
|
bv->text->FinishUndo();
|
2000-04-19 14:42:19 +00:00
|
|
|
result = moveRight(bv);
|
2000-03-09 16:04:28 +00:00
|
|
|
if (hasSelection()) {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LFUN_LEFTSEL:
|
2000-03-28 16:18:02 +00:00
|
|
|
bv->text->FinishUndo();
|
2000-03-09 16:04:28 +00:00
|
|
|
moveLeft(bv, false);
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
break;
|
|
|
|
case LFUN_LEFT:
|
2000-03-28 16:18:02 +00:00
|
|
|
bv->text->FinishUndo();
|
2000-04-19 14:42:19 +00:00
|
|
|
result= moveLeft(bv);
|
2000-03-28 16:18:02 +00:00
|
|
|
if (hasSelection()) {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-28 16:18:02 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-28 16:18:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2000-03-09 16:04:28 +00:00
|
|
|
case LFUN_DOWNSEL:
|
2000-03-28 16:18:02 +00:00
|
|
|
bv->text->FinishUndo();
|
2000-04-19 14:42:19 +00:00
|
|
|
moveDown(bv);
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
break;
|
|
|
|
case LFUN_DOWN:
|
2000-03-28 16:18:02 +00:00
|
|
|
bv->text->FinishUndo();
|
2000-04-19 14:42:19 +00:00
|
|
|
result = moveDown(bv);
|
2000-03-09 16:04:28 +00:00
|
|
|
if (hasSelection()) {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LFUN_UPSEL:
|
2000-03-28 16:18:02 +00:00
|
|
|
bv->text->FinishUndo();
|
2000-04-19 14:42:19 +00:00
|
|
|
moveUp(bv);
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
break;
|
|
|
|
case LFUN_UP:
|
2000-03-28 16:18:02 +00:00
|
|
|
bv->text->FinishUndo();
|
2000-04-19 14:42:19 +00:00
|
|
|
result = moveUp(bv);
|
2000-03-09 16:04:28 +00:00
|
|
|
if (hasSelection()) {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LFUN_BACKSPACE:
|
2000-06-08 23:16:16 +00:00
|
|
|
if (!cursor.pos()) {
|
2000-03-09 16:04:28 +00:00
|
|
|
if (hasSelection()) {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
moveLeft(bv);
|
|
|
|
case LFUN_DELETE:
|
2000-04-10 14:29:05 +00:00
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
bv->text->SetUndo(bv->buffer(), Undo::DELETE,
|
2000-06-08 23:16:16 +00:00
|
|
|
bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
|
|
|
|
bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
|
2000-04-10 14:29:05 +00:00
|
|
|
bool ret = true;
|
|
|
|
if (hasSelection()) {
|
2000-06-08 23:16:16 +00:00
|
|
|
LyXParagraph::size_type i = selection_start_cursor.pos();
|
|
|
|
for (; i < selection_end_cursor.pos(); ++i) {
|
|
|
|
par->Erase(selection_start_cursor.pos());
|
2000-04-10 14:29:05 +00:00
|
|
|
}
|
|
|
|
} else
|
2000-03-27 15:13:47 +00:00
|
|
|
ret = Delete();
|
|
|
|
if (ret) { // we need update
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-27 15:13:47 +00:00
|
|
|
UpdateLocal(bv, true);
|
|
|
|
} else if (hasSelection()) {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-27 15:13:47 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
}
|
2000-04-10 14:29:05 +00:00
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
resetPos(bv->painter());
|
2000-04-10 14:29:05 +00:00
|
|
|
break;
|
2000-03-27 15:13:47 +00:00
|
|
|
case LFUN_CUT:
|
2000-06-12 11:27:15 +00:00
|
|
|
bv->text->SetUndo(bv->buffer(), Undo::DELETE,
|
2000-06-08 23:16:16 +00:00
|
|
|
bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
|
|
|
|
bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
if (cutSelection(bv->buffer())) {
|
2000-04-10 14:29:05 +00:00
|
|
|
// we need update
|
2000-05-04 08:14:34 +00:00
|
|
|
cursor = selection_end_cursor = selection_start_cursor;
|
2000-03-27 15:13:47 +00:00
|
|
|
UpdateLocal(bv, true);
|
|
|
|
} else if (hasSelection()) {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-27 15:13:47 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
resetPos(bv->painter());
|
2000-03-27 15:13:47 +00:00
|
|
|
break;
|
|
|
|
case LFUN_COPY:
|
2000-03-28 16:18:02 +00:00
|
|
|
bv->text->FinishUndo();
|
2000-06-12 11:27:15 +00:00
|
|
|
if (copySelection(bv->buffer())) {
|
2000-04-10 14:29:05 +00:00
|
|
|
// we need update
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
UpdateLocal(bv, true);
|
|
|
|
} else if (hasSelection()) {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
}
|
|
|
|
break;
|
2000-03-27 15:13:47 +00:00
|
|
|
case LFUN_PASTE:
|
2000-04-10 14:29:05 +00:00
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
bv->text->SetUndo(bv->buffer(), Undo::INSERT,
|
2000-06-08 23:16:16 +00:00
|
|
|
bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
|
|
|
|
bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
|
2000-06-12 11:27:15 +00:00
|
|
|
if (pasteSelection(bv->buffer())) {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-27 15:13:47 +00:00
|
|
|
UpdateLocal(bv, true);
|
|
|
|
}
|
2000-04-10 14:29:05 +00:00
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
resetPos(bv->painter());
|
2000-04-10 14:29:05 +00:00
|
|
|
break;
|
2000-03-09 16:04:28 +00:00
|
|
|
case LFUN_HOME:
|
2000-03-28 16:18:02 +00:00
|
|
|
bv->text->FinishUndo();
|
2000-06-08 23:16:16 +00:00
|
|
|
for(; cursor.pos() > rows[actrow].pos;) {
|
|
|
|
cursor.x(cursor.x() - SingleWidth(bv->painter(), par, cursor.pos()));
|
|
|
|
cursor.pos(cursor.pos() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor.x(cursor.x() - SingleWidth(bv->painter(), par, cursor.pos()));
|
2000-03-09 16:04:28 +00:00
|
|
|
if (hasSelection()) {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
resetPos(bv->painter());
|
2000-03-09 16:04:28 +00:00
|
|
|
break;
|
|
|
|
case LFUN_END:
|
|
|
|
{
|
2000-03-28 16:18:02 +00:00
|
|
|
bv->text->FinishUndo();
|
2000-03-09 16:04:28 +00:00
|
|
|
int checkpos = (int)rows[actrow + 1].pos;
|
|
|
|
if ((actrow + 2) < (int)rows.size())
|
|
|
|
--checkpos;
|
2000-06-08 23:16:16 +00:00
|
|
|
for(; cursor.pos() < checkpos;) {
|
|
|
|
cursor.x(cursor.x() + SingleWidth(bv->painter(), par, cursor.pos()));
|
|
|
|
cursor.pos(cursor.pos() + 1);
|
|
|
|
}
|
2000-03-09 16:04:28 +00:00
|
|
|
if (hasSelection()) {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-03-09 16:04:28 +00:00
|
|
|
}
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
resetPos(bv->painter());
|
2000-03-09 16:04:28 +00:00
|
|
|
break;
|
2000-04-10 14:29:05 +00:00
|
|
|
case LFUN_BREAKPARAGRAPH:
|
2000-03-09 16:04:28 +00:00
|
|
|
case LFUN_BREAKLINE:
|
2000-04-10 15:18:09 +00:00
|
|
|
if (!autoBreakRows)
|
|
|
|
return DISPATCHED;
|
2000-06-12 11:27:15 +00:00
|
|
|
bv->text->SetUndo(bv->buffer(), Undo::INSERT,
|
2000-06-08 23:16:16 +00:00
|
|
|
bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
|
|
|
|
bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
|
|
|
|
par->InsertChar(cursor.pos(),LyXParagraph::META_NEWLINE);
|
2000-06-12 11:27:15 +00:00
|
|
|
SetCharFont(bv->buffer(), cursor.pos(),current_font);
|
2000-03-09 16:04:28 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.pos(cursor.pos() + 1);
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-04-19 14:42:19 +00:00
|
|
|
resetPos(bv->painter());
|
2000-03-09 16:04:28 +00:00
|
|
|
break;
|
2000-05-04 08:14:34 +00:00
|
|
|
case LFUN_LAYOUT:
|
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
static LyXTextClass::size_type cur_layout = par->layout;
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
// Derive layout number from given argument (string)
|
|
|
|
// and current buffer's textclass (number). */
|
|
|
|
LyXTextClassList::ClassList::size_type tclass =
|
2000-06-12 11:27:15 +00:00
|
|
|
bv->buffer()->params.textclass;
|
2000-05-04 10:57:00 +00:00
|
|
|
std::pair <bool, LyXTextClass::size_type> layout =
|
2000-05-04 08:14:34 +00:00
|
|
|
textclasslist.NumberOfLayout(tclass, arg);
|
|
|
|
|
|
|
|
// If the entry is obsolete, use the new one instead.
|
|
|
|
if (layout.first) {
|
|
|
|
string obs = textclasslist.Style(tclass,layout.second).
|
|
|
|
obsoleted_by();
|
|
|
|
if (!obs.empty())
|
|
|
|
layout = textclasslist.NumberOfLayout(tclass, obs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// see if we found the layout number:
|
|
|
|
if (!layout.first) {
|
|
|
|
string msg = string(N_("Layout ")) + arg + N_(" not known");
|
|
|
|
|
|
|
|
bv->owner()->getMiniBuffer()->Set(msg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
if (cur_layout != layout.second) {
|
|
|
|
cur_layout = layout.second;
|
|
|
|
text->SetLayout(bv, layout.second);
|
2000-06-08 23:16:16 +00:00
|
|
|
bv->owner()->getToolbar()->combox->select(cursor.par()->GetLayout()+1);
|
2000-05-04 08:14:34 +00:00
|
|
|
UpdateLocal(bv, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2000-03-09 16:04:28 +00:00
|
|
|
default:
|
|
|
|
result = UNDISPATCHED;
|
|
|
|
break;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
if (result != FINISHED) {
|
2000-04-19 14:42:19 +00:00
|
|
|
ShowInsetCursor(bv);
|
2000-02-25 12:06:15 +00:00
|
|
|
} else
|
|
|
|
bv->unlockInset(this);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetText::Latex(Buffer const * buf, ostream & os, bool, bool) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-05-04 08:14:34 +00:00
|
|
|
TexRow texrow;
|
2000-06-12 11:27:15 +00:00
|
|
|
buf->latexParagraphs(os, par, 0, texrow);
|
2000-05-04 08:14:34 +00:00
|
|
|
return texrow.rows();
|
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-05-17 14:43:09 +00:00
|
|
|
int InsetText::SingleWidth(Painter & pain, LyXParagraph * p, int pos) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
LyXFont font = GetDrawFont(current_view->buffer(), p, pos);
|
2000-05-17 14:43:09 +00:00
|
|
|
char c = p->GetChar(pos);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
if (IsPrintable(c)) {
|
2000-04-04 00:19:15 +00:00
|
|
|
return lyxfont::width(c, font);
|
2000-02-25 12:06:15 +00:00
|
|
|
} else if (c == LyXParagraph::META_INSET) {
|
2000-05-17 14:43:09 +00:00
|
|
|
Inset const * tmpinset = p->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';
|
2000-04-04 00:19:15 +00:00
|
|
|
return lyxfont::width(c, font);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns the width of a character at a certain spot
|
2000-05-17 14:43:09 +00:00
|
|
|
void InsetText::SingleHeight(Painter & pain, LyXParagraph * p,int pos,
|
2000-02-25 16:05:26 +00:00
|
|
|
int & asc, int & desc) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
LyXFont font = GetDrawFont(current_view->buffer(), p, pos);
|
2000-05-17 14:43:09 +00:00
|
|
|
char c = p->GetChar(pos);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
asc = desc = 0;
|
|
|
|
if (c == LyXParagraph::META_INSET) {
|
2000-05-17 14:43:09 +00:00
|
|
|
Inset const * tmpinset=p->GetInset(pos);
|
2000-02-25 12:06:15 +00:00
|
|
|
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 {
|
2000-04-04 00:19:15 +00:00
|
|
|
asc = lyxfont::maxAscent(font);
|
|
|
|
desc = lyxfont::maxDescent(font);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
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.
|
2000-06-12 11:27:15 +00:00
|
|
|
LyXFont InsetText::GetFont(Buffer const * buf, LyXParagraph * p, int pos) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-05-17 14:43:09 +00:00
|
|
|
char par_depth = p->GetDepth();
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
LyXLayout const & layout =
|
2000-06-12 11:27:15 +00:00
|
|
|
textclasslist.Style(buf->params.textclass, p->GetLayout());
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
// We specialize the 95% common case:
|
2000-05-17 14:43:09 +00:00
|
|
|
if (p->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
|
2000-02-25 12:06:15 +00:00
|
|
|
if (pos >= 0) {
|
|
|
|
// 95% goes here
|
|
|
|
if (layout.labeltype == LABEL_MANUAL
|
2000-06-12 11:27:15 +00:00
|
|
|
&& pos < BeginningOfMainBody(buf, p)) {
|
2000-02-25 12:06:15 +00:00
|
|
|
// 1% goes here
|
2000-06-12 11:27:15 +00:00
|
|
|
return p->GetFontSettings(buf->params,
|
2000-06-08 23:16:16 +00:00
|
|
|
pos).realize(layout.reslabelfont);
|
2000-02-25 12:06:15 +00:00
|
|
|
} else
|
2000-06-12 11:27:15 +00:00
|
|
|
return p->GetFontSettings(buf->params,
|
2000-06-08 23:16:16 +00:00
|
|
|
pos).realize(layout.resfont);
|
2000-02-25 12:06:15 +00:00
|
|
|
} 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
|
2000-06-12 11:27:15 +00:00
|
|
|
if (pos < BeginningOfMainBody(buf, p)) {
|
2000-02-25 12:06:15 +00:00
|
|
|
// 1% goes here
|
|
|
|
layoutfont = layout.labelfont;
|
|
|
|
} else {
|
|
|
|
// 99% goes here
|
|
|
|
layoutfont = layout.font;
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
tmpfont = p->GetFontSettings(buf->params, pos);
|
2000-02-25 12:06:15 +00:00
|
|
|
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
|
2000-05-17 14:43:09 +00:00
|
|
|
while (p && par_depth && !tmpfont.resolved()) {
|
|
|
|
p = p->DepthHook(par_depth - 1);
|
|
|
|
if (p) {
|
2000-06-12 11:27:15 +00:00
|
|
|
tmpfont.realize(textclasslist.Style(buf->params.textclass,
|
2000-05-17 14:43:09 +00:00
|
|
|
p->GetLayout()).font);
|
|
|
|
par_depth = p->GetDepth();
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
tmpfont.realize((textclasslist.TextClass(buf->params.textclass).
|
2000-02-25 12:06:15 +00:00
|
|
|
defaultfont()));
|
|
|
|
return tmpfont;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-10 14:29:05 +00:00
|
|
|
// the font for drawing may be different from the real font
|
2000-06-12 11:27:15 +00:00
|
|
|
LyXFont InsetText::GetDrawFont(Buffer const * buf, LyXParagraph * p, int pos) const
|
2000-04-10 14:29:05 +00:00
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
return GetFont(buf, p, pos);
|
2000-04-10 14:29:05 +00:00
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetText::BeginningOfMainBody(Buffer const * buf, LyXParagraph * p) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
if (textclasslist.Style(buf->params.textclass,
|
2000-05-17 14:43:09 +00:00
|
|
|
p->GetLayout()).labeltype != LABEL_MANUAL)
|
|
|
|
return 0;
|
2000-02-25 12:06:15 +00:00
|
|
|
else
|
2000-05-17 14:43:09 +00:00
|
|
|
return p->BeginningOfMainBody();
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 16:42:21 +00:00
|
|
|
void InsetText::GetCursorPos(int & x, int & y) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
x = cursor.x();
|
|
|
|
y = cursor.y();
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetText::InsetInInsetY()
|
|
|
|
{
|
|
|
|
if (!the_locking_inset)
|
|
|
|
return 0;
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
return (inset_y + the_locking_inset->InsetInInsetY());
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::ToggleInsetCursor(BufferView * bv)
|
|
|
|
{
|
|
|
|
if (the_locking_inset) {
|
|
|
|
the_locking_inset->ToggleInsetCursor(bv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
LyXFont font = GetDrawFont(bv->buffer(), par, text->cursor.pos());
|
2000-02-25 13:35:38 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
int asc = lyxfont::maxAscent(font);
|
|
|
|
int desc = lyxfont::maxDescent(font);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
asc = text->cursor.row()->ascent_of_text();
|
|
|
|
desc = text->cursor.row()->height() - asc;
|
2000-02-25 12:06:15 +00:00
|
|
|
if (cursor_visible)
|
|
|
|
bv->hideLockedInsetCursor();
|
|
|
|
else
|
2000-06-12 11:27:15 +00:00
|
|
|
bv->showLockedInsetCursor(text->cursor.x(), text->cursor.y(),
|
|
|
|
asc, desc);
|
2000-02-25 12:06:15 +00:00
|
|
|
cursor_visible = !cursor_visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::ShowInsetCursor(BufferView * bv)
|
|
|
|
{
|
2000-04-19 14:42:19 +00:00
|
|
|
if (the_locking_inset) {
|
|
|
|
the_locking_inset->ShowInsetCursor(bv);
|
|
|
|
return;
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
if (!cursor_visible) {
|
2000-06-12 11:27:15 +00:00
|
|
|
LyXFont font = GetDrawFont(bv->buffer(), par, cursor.pos());
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
int asc = lyxfont::maxAscent(font);
|
|
|
|
int desc = lyxfont::maxDescent(font);
|
2000-06-12 11:27:15 +00:00
|
|
|
asc = text->cursor.row()->ascent_of_text();
|
|
|
|
desc = text->cursor.row()->height() - asc;
|
|
|
|
bv->fitLockedInsetCursor(text->cursor.x(), text->cursor.y(), asc, desc);
|
|
|
|
bv->showLockedInsetCursor(text->cursor.x(), text->cursor.y(), asc, desc);
|
2000-02-25 12:06:15 +00:00
|
|
|
cursor_visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::HideInsetCursor(BufferView * bv)
|
|
|
|
{
|
2000-04-19 14:42:19 +00:00
|
|
|
if (cursor_visible) {
|
|
|
|
bv->hideLockedInsetCursor();
|
|
|
|
cursor_visible = false;
|
|
|
|
}
|
|
|
|
if (the_locking_inset)
|
|
|
|
the_locking_inset->HideInsetCursor(bv);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
void InsetText::setPos(Painter & pain, int x, int y) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-04-19 14:42:19 +00:00
|
|
|
x -= drawTextXOffset;
|
|
|
|
y -= drawTextYOffset;
|
2000-02-25 12:06:15 +00:00
|
|
|
// search right X-pos x==0 -> top_x
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.pos(0);
|
|
|
|
actrow = 0;
|
|
|
|
cursor.y(top_baseline);
|
|
|
|
y += cursor.y();
|
2000-02-25 13:35:38 +00:00
|
|
|
for(unsigned int i = 1;
|
2000-06-08 23:16:16 +00:00
|
|
|
(long(cursor.y() + rows[i - 1].desc) < y)
|
2000-04-26 13:57:28 +00:00
|
|
|
&& (i < rows.size() - 1); ++i) {
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.y(rows[i].baseline);
|
|
|
|
cursor.pos(rows[i].pos);
|
2000-02-25 12:06:15 +00:00
|
|
|
actrow = i;
|
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.y(cursor.y() - top_baseline);
|
|
|
|
cursor.x(top_x + 2); // 2 = frame width
|
|
|
|
x += cursor.x();
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
int swh;
|
2000-06-08 23:16:16 +00:00
|
|
|
int sw = swh = SingleWidth(pain, par, cursor.pos());
|
|
|
|
if (par->GetChar(cursor.pos()) != LyXParagraph::META_INSET)
|
2000-02-25 12:06:15 +00:00
|
|
|
swh /= 2;
|
2000-04-09 22:48:51 +00:00
|
|
|
int checkpos = rows[actrow + 1].pos;
|
2000-06-08 23:16:16 +00:00
|
|
|
if ((actrow + 2) < (int)rows.size())
|
2000-03-09 16:04:28 +00:00
|
|
|
--checkpos;
|
2000-06-08 23:16:16 +00:00
|
|
|
while ((cursor.pos() < checkpos) && ((cursor.x() + swh) < x)) {
|
|
|
|
cursor.x(cursor.x() + sw);
|
|
|
|
cursor.pos(cursor.pos() + 1);
|
|
|
|
sw = swh = SingleWidth(pain, par, cursor.pos());
|
|
|
|
if (par->GetChar(cursor.pos())!=LyXParagraph::META_INSET)
|
2000-02-25 12:06:15 +00:00
|
|
|
swh /= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
void InsetText::resetPos(Painter & pain) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.par(par);
|
2000-05-04 08:14:34 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
if (!rows.size())
|
|
|
|
return;
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
int old_pos = cursor.pos();
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.y(top_baseline);
|
2000-04-19 14:42:19 +00:00
|
|
|
actrow = 0;
|
2000-04-24 20:58:23 +00:00
|
|
|
for(unsigned int i = 0;
|
2000-06-08 23:16:16 +00:00
|
|
|
i < (rows.size() - 1) && rows[i].pos <= cursor.pos();
|
2000-04-19 14:42:19 +00:00
|
|
|
++i) {
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.y(rows[i].baseline);
|
2000-04-19 14:42:19 +00:00
|
|
|
actrow = i;
|
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.y(cursor.y() - top_baseline);
|
|
|
|
setPos(pain, 0, cursor.y());
|
|
|
|
cursor.x(top_x + 2); // 2 = frame width
|
|
|
|
while(cursor.pos() < old_pos) {
|
|
|
|
cursor.x(cursor.x() + SingleWidth(pain, par,cursor.pos()));
|
|
|
|
cursor.pos(cursor.pos() + 1);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
UpdatableInset::RESULT
|
|
|
|
InsetText::moveRight(BufferView * bv, bool activate_inset)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
if (cursor.pos() >= par->Last())
|
2000-04-19 14:42:19 +00:00
|
|
|
return FINISHED;
|
|
|
|
if (activate_inset && checkAndActivateInset(bv)) {
|
|
|
|
return DISPATCHED;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.pos(cursor.pos() + 1);
|
2000-04-19 14:42:19 +00:00
|
|
|
resetPos(bv->painter());
|
2000-06-12 11:27:15 +00:00
|
|
|
real_current_font = current_font =GetFont(bv->buffer(), par, cursor.pos());
|
2000-04-19 14:42:19 +00:00
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
UpdatableInset::RESULT
|
|
|
|
InsetText::moveLeft(BufferView * bv, bool activate_inset)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
if (cursor.pos() <= 0)
|
2000-04-19 14:42:19 +00:00
|
|
|
return FINISHED;
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.pos(cursor.pos() - 1);
|
2000-04-19 14:42:19 +00:00
|
|
|
resetPos(bv->painter());
|
|
|
|
if (activate_inset)
|
|
|
|
if (checkAndActivateInset(bv, -1, -1))
|
|
|
|
return DISPATCHED;
|
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
UpdatableInset::RESULT
|
|
|
|
InsetText::moveUp(BufferView * bv)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-04-19 14:42:19 +00:00
|
|
|
if (!actrow)
|
|
|
|
return FINISHED;
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.y(rows[actrow - 1].baseline - top_baseline);
|
|
|
|
if (cursor.x_fix() < 0)
|
|
|
|
cursor.x_fix(cursor.x());
|
|
|
|
setPos(bv->painter(),
|
|
|
|
cursor.x_fix() - top_x + drawTextXOffset, cursor.y());
|
2000-04-19 14:42:19 +00:00
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
UpdatableInset::RESULT
|
|
|
|
InsetText::moveDown(BufferView * bv)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2000-04-19 14:42:19 +00:00
|
|
|
if (actrow >= int(rows.size() - 2))
|
|
|
|
return FINISHED;
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.y(rows[actrow + 1].baseline - top_baseline);
|
|
|
|
if (cursor.x_fix() < 0)
|
|
|
|
cursor.x_fix(cursor.x());
|
|
|
|
setPos(bv->painter(),
|
|
|
|
cursor.x_fix() - top_x + drawTextXOffset, cursor.y());
|
2000-04-19 14:42:19 +00:00
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::Delete()
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
if ((par->GetChar(cursor.pos())==LyXParagraph::META_INSET) &&
|
|
|
|
!par->GetInset(cursor.pos())->Deletable()) {
|
2000-04-19 14:42:19 +00:00
|
|
|
return false;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
par->Erase(cursor.pos());
|
2000-02-25 12:06:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::InsertInset(BufferView * bv, Inset * inset)
|
|
|
|
{
|
2000-05-15 14:49:36 +00:00
|
|
|
if (the_locking_inset) {
|
|
|
|
if (the_locking_inset->InsertInsetAllowed(inset))
|
|
|
|
return the_locking_inset->InsertInset(bv, inset);
|
|
|
|
return false;
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
bv->text->SetUndo(bv->buffer(), Undo::INSERT,
|
2000-06-08 23:16:16 +00:00
|
|
|
bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
|
|
|
|
bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
|
2000-03-08 13:52:57 +00:00
|
|
|
if (inset->Editable() == Inset::IS_EDITABLE) {
|
2000-06-08 23:16:16 +00:00
|
|
|
UpdatableInset * i = static_cast<UpdatableInset *>(inset);
|
|
|
|
i->setOwner(static_cast<UpdatableInset *>(this));
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
par->InsertChar(cursor.pos(), LyXParagraph::META_INSET);
|
|
|
|
par->InsertInset(cursor.pos(), inset);
|
2000-04-19 14:42:19 +00:00
|
|
|
if (hasSelection()) {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-04-19 14:42:19 +00:00
|
|
|
} else {
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-04-19 14:42:19 +00:00
|
|
|
static_cast<UpdatableInset*>(inset)->Edit(bv, 0, 0, 0);
|
2000-02-25 12:06:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UpdatableInset * InsetText::GetLockingInset()
|
|
|
|
{
|
|
|
|
return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
UpdatableInset * InsetText::GetFirstLockingInsetOfType(Inset::Code c)
|
|
|
|
{
|
|
|
|
if (c == LyxCode())
|
|
|
|
return this;
|
|
|
|
if (the_locking_inset)
|
|
|
|
return the_locking_inset->GetFirstLockingInsetOfType(c);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2000-06-12 11:27:15 +00:00
|
|
|
if (cursor.pos() < BeginningOfMainBody(bv->buffer(), par))
|
|
|
|
layoutfont = GetFont(bv->buffer(), par, -2);
|
2000-02-25 12:06:15 +00:00
|
|
|
else
|
2000-06-12 11:27:15 +00:00
|
|
|
layoutfont = GetFont(bv->buffer(), par, -1);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
// 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-06-08 23:16:16 +00:00
|
|
|
if (selection_start_cursor.pos() > selection_end_cursor.pos()) {
|
|
|
|
s_start = selection_end_cursor.pos();
|
|
|
|
s_end = selection_start_cursor.pos();
|
2000-02-25 12:06:15 +00:00
|
|
|
} else {
|
2000-06-08 23:16:16 +00:00
|
|
|
s_start = selection_start_cursor.pos();
|
|
|
|
s_end = selection_end_cursor.pos();
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
2000-02-25 13:35:38 +00:00
|
|
|
LyXFont newfont;
|
2000-02-25 12:06:15 +00:00
|
|
|
while(s_start < s_end) {
|
2000-06-12 11:27:15 +00:00
|
|
|
newfont = GetFont(bv->buffer(), par,s_start);
|
2000-03-17 10:14:46 +00:00
|
|
|
newfont.update(font, bv->buffer()->params.language_info, toggleall);
|
2000-06-12 11:27:15 +00:00
|
|
|
SetCharFont(bv->buffer(), s_start, newfont);
|
2000-02-25 12:06:15 +00:00
|
|
|
++s_start;
|
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetText::SetCharFont(Buffer const * buf, 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-06-12 11:27:15 +00:00
|
|
|
textclasslist.Style(buf->params.textclass,par->GetLayout());
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
// Get concrete layout font to reduce against
|
|
|
|
LyXFont layoutfont;
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
if (pos < BeginningOfMainBody(buf, par))
|
2000-02-25 12:06:15 +00:00
|
|
|
layoutfont = layout.labelfont;
|
|
|
|
else
|
|
|
|
layoutfont = layout.font;
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
layoutfont.realize((textclasslist.TextClass(buf->params.textclass).
|
2000-02-25 12:06:15 +00:00
|
|
|
defaultfont()));
|
|
|
|
|
|
|
|
// Now, reduce font against full layout font
|
|
|
|
font.reduce(layoutfont);
|
|
|
|
|
|
|
|
par->SetFont(pos, font);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
void InsetText::computeTextRows(Painter & pain) 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,
|
|
|
|
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-06-12 11:27:15 +00:00
|
|
|
if (!autoBreakRows || (getMaxTextWidth(pain, this) < 0)) {
|
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
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
insetWidth += (2 * TEXT_TO_INSET_OFFSET);
|
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-03-06 02:42:40 +00:00
|
|
|
int cw, lastWordWidth = 0;
|
2000-05-15 14:49:36 +00:00
|
|
|
int maxWidth = getMaxTextWidth(pain, this);
|
|
|
|
// if we auto break rows than the insetwidth should be always the max
|
|
|
|
// width as the display is stable it may get larger if we have a really
|
|
|
|
// large word below and we draw it!!!
|
|
|
|
insetWidth = maxWidth;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
for(p = 0; p < par->Last(); ++p) {
|
2000-03-09 16:04:28 +00:00
|
|
|
if (par->IsNewline(p)) {
|
|
|
|
rows.back().asc = wordAscent;
|
|
|
|
rows.back().desc = wordDescent;
|
2000-05-19 10:32:05 +00:00
|
|
|
row.pos = p+1;
|
2000-03-09 16:04:28 +00:00
|
|
|
rows.push_back(row);
|
2000-05-19 10:32:05 +00:00
|
|
|
nwp = p+1;
|
2000-05-15 14:49:36 +00:00
|
|
|
width = lastWordWidth = 0;
|
|
|
|
oasc = odesc = wordAscent = wordDescent = 0;
|
|
|
|
is_first_word_in_row = true;
|
2000-03-09 16:04:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
cw = SingleWidth(pain, par, p);
|
2000-04-20 13:48:34 +00:00
|
|
|
Inset * inset = 0;
|
2000-05-15 14:49:36 +00:00
|
|
|
if (par->GetChar(p) == LyXParagraph::META_INSET)
|
|
|
|
inset = par->GetInset(p);
|
|
|
|
if (inset && inset->display()) {
|
|
|
|
inset->setOwner(const_cast<InsetText *>(this));
|
2000-06-12 11:27:15 +00:00
|
|
|
if (cw > insetWidth)
|
2000-05-15 14:49:36 +00:00
|
|
|
insetWidth = cw;
|
|
|
|
if (!is_first_word_in_row || (p != nwp)) {
|
|
|
|
oasc = max(oasc, wordAscent);
|
|
|
|
odesc = max(odesc, wordDescent);
|
2000-03-06 02:42:40 +00:00
|
|
|
rows.back().asc = oasc;
|
|
|
|
rows.back().desc = odesc;
|
2000-05-15 14:49:36 +00:00
|
|
|
row.pos = p;
|
2000-04-20 13:48:34 +00:00
|
|
|
rows.push_back(row);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
SingleHeight(pain, par, p, asc, desc);
|
|
|
|
rows.back().asc = asc;
|
|
|
|
rows.back().desc = desc;
|
|
|
|
row.pos = nwp = p + 1;
|
|
|
|
rows.push_back(row);
|
|
|
|
width = lastWordWidth = 0;
|
|
|
|
oasc = odesc = wordAscent = wordDescent = 0;
|
|
|
|
is_first_word_in_row = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SingleHeight(pain, par, p, asc, desc);
|
|
|
|
width += cw;
|
|
|
|
lastWordWidth += cw;
|
|
|
|
if (width > maxWidth) {
|
|
|
|
if (is_first_word_in_row) {
|
|
|
|
if (!(width-cw)) { // only this character in word
|
|
|
|
rows.back().asc = asc;
|
|
|
|
rows.back().desc = desc;
|
|
|
|
row.pos = p+1;
|
2000-02-25 12:06:15 +00:00
|
|
|
rows.push_back(row);
|
2000-05-15 14:49:36 +00:00
|
|
|
oasc = 0;
|
|
|
|
odesc = 0;
|
|
|
|
wordAscent = 0;
|
|
|
|
wordDescent = 0;
|
|
|
|
nwp = p + 1;
|
|
|
|
lastWordWidth = width = 0;
|
2000-02-25 12:06:15 +00:00
|
|
|
} else {
|
2000-05-15 14:49:36 +00:00
|
|
|
rows.back().asc = wordAscent;
|
|
|
|
rows.back().desc = wordDescent;
|
|
|
|
row.pos = p;
|
2000-02-25 12:06:15 +00:00
|
|
|
rows.push_back(row);
|
2000-05-15 14:49:36 +00:00
|
|
|
oasc = 0;
|
|
|
|
odesc = 0;
|
|
|
|
wordAscent = asc;
|
|
|
|
wordDescent = desc;
|
|
|
|
lastWordWidth = width = cw;
|
|
|
|
nwp = p;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
} else {
|
|
|
|
rows.back().asc = oasc;
|
|
|
|
rows.back().desc = odesc;
|
|
|
|
row.pos = nwp;
|
|
|
|
rows.push_back(row);
|
|
|
|
oasc = wordAscent;
|
|
|
|
odesc = wordDescent;
|
|
|
|
width = lastWordWidth;
|
|
|
|
wordAscent = max(wordAscent, asc);
|
|
|
|
wordDescent = max(wordDescent, desc);
|
|
|
|
is_first_word_in_row = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
wordAscent = max(wordAscent, asc);
|
|
|
|
wordDescent = max(wordDescent, desc);
|
|
|
|
}
|
|
|
|
if (par->IsSeparator(p) || inset) {
|
|
|
|
if (inset) {
|
|
|
|
inset->setOwner(const_cast<InsetText *>(this));
|
|
|
|
if (cw > maxWidth)
|
|
|
|
insetWidth = cw;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
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-05-15 14:49:36 +00:00
|
|
|
// assign last row data
|
|
|
|
rows.back().asc = max(oasc, wordAscent);
|
|
|
|
rows.back().desc = max(odesc, wordDescent);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
insetWidth += (2 * TEXT_TO_INSET_OFFSET);
|
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 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
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
|
|
void InsetText::UpdateLocal(BufferView * bv, bool flag)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2000-03-27 15:13:47 +00:00
|
|
|
if (flag) {
|
2000-06-12 11:27:15 +00:00
|
|
|
text->FullRebreak(bv);
|
2000-05-15 14:49:36 +00:00
|
|
|
computeTextRows(bv->painter());
|
2000-03-27 15:13:47 +00:00
|
|
|
computeBaselines(top_baseline);
|
|
|
|
}
|
2000-03-08 13:52:57 +00:00
|
|
|
bv->updateInset(this, flag);
|
2000-04-03 11:36:35 +00:00
|
|
|
if (flag)
|
2000-04-19 14:42:19 +00:00
|
|
|
resetPos(bv->painter());
|
2000-06-08 23:16:16 +00:00
|
|
|
bv->owner()->getToolbar()->combox->select(cursor.par()->GetLayout()+1);
|
2000-03-27 15:13:47 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
bool InsetText::cutSelection(Buffer const * buf)
|
2000-03-27 15:13:47 +00:00
|
|
|
{
|
|
|
|
if (!hasSelection())
|
|
|
|
return false;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
CutAndPaste cap;
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
LyXParagraph * endpar = par;
|
2000-04-20 13:48:34 +00:00
|
|
|
int start, end;
|
2000-06-08 23:16:16 +00:00
|
|
|
if (selection_start_cursor.pos() > selection_end_cursor.pos()) {
|
|
|
|
start = selection_end_cursor.pos();
|
|
|
|
end = selection_start_cursor.pos();
|
2000-04-20 13:48:34 +00:00
|
|
|
} else {
|
2000-06-08 23:16:16 +00:00
|
|
|
start = selection_start_cursor.pos();
|
|
|
|
end = selection_end_cursor.pos();
|
2000-04-20 13:48:34 +00:00
|
|
|
}
|
2000-04-10 14:29:05 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
return cap.cutSelection(par, &endpar, start, end, buf->params.textclass);
|
2000-03-27 15:13:47 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
bool InsetText::copySelection(Buffer const * buf)
|
2000-03-27 15:13:47 +00:00
|
|
|
{
|
|
|
|
if (!hasSelection())
|
|
|
|
return false;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
CutAndPaste cap;
|
|
|
|
|
2000-04-20 13:48:34 +00:00
|
|
|
int start, end;
|
2000-06-08 23:16:16 +00:00
|
|
|
if (selection_start_cursor.pos() > selection_end_cursor.pos()) {
|
|
|
|
start = selection_end_cursor.pos();
|
|
|
|
end = selection_start_cursor.pos();
|
2000-04-20 13:48:34 +00:00
|
|
|
} else {
|
2000-06-08 23:16:16 +00:00
|
|
|
start = selection_start_cursor.pos();
|
|
|
|
end = selection_end_cursor.pos();
|
2000-04-20 13:48:34 +00:00
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
return cap.copySelection(par, par, start, end, buf->params.textclass);
|
2000-03-27 15:13:47 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
bool InsetText::pasteSelection(Buffer const * buf)
|
2000-03-27 15:13:47 +00:00
|
|
|
{
|
2000-04-10 14:29:05 +00:00
|
|
|
CutAndPaste cap;
|
2000-03-27 15:13:47 +00:00
|
|
|
|
2000-04-10 14:29:05 +00:00
|
|
|
if (cap.nrOfParagraphs() > 1) {
|
|
|
|
WriteAlert(_("Impossible operation"),
|
|
|
|
_("Cannot include more than one paragraph!"),
|
|
|
|
_("Sorry."));
|
|
|
|
return false;
|
2000-03-27 15:13:47 +00:00
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
LyXParagraph * endpar;
|
|
|
|
LyXParagraph * actpar = par;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
int pos = cursor.pos();
|
2000-06-12 11:27:15 +00:00
|
|
|
bool ret = cap.pasteSelection(&actpar, &endpar, pos,buf->params.textclass);
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.pos(pos);
|
|
|
|
return ret;
|
2000-03-08 13:52:57 +00:00
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
|
|
|
|
int button)
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
if (par->GetChar(cursor.pos()) == LyXParagraph::META_INSET) {
|
2000-04-19 14:42:19 +00:00
|
|
|
UpdatableInset * inset =
|
2000-06-08 23:16:16 +00:00
|
|
|
static_cast<UpdatableInset*>(par->GetInset(cursor.pos()));
|
2000-06-12 11:27:15 +00:00
|
|
|
LyXFont font = GetFont(bv->buffer(), par, cursor.pos());
|
2000-04-19 14:42:19 +00:00
|
|
|
if (x < 0)
|
|
|
|
x = inset->width(bv->painter(), font);
|
|
|
|
if (y < 0)
|
|
|
|
y = inset->descent(bv->painter(), font);
|
2000-06-08 23:16:16 +00:00
|
|
|
inset_x = cursor.x() - top_x + drawTextXOffset;
|
|
|
|
inset_y = cursor.y() + drawTextYOffset;
|
|
|
|
inset->Edit(bv, x - inset_x, y - inset_y, button);
|
2000-04-19 14:42:19 +00:00
|
|
|
if (!the_locking_inset)
|
|
|
|
return false;
|
|
|
|
UpdateLocal(bv, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
int InsetText::getMaxTextWidth(Painter & pain, UpdatableInset const * inset) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-05-15 14:49:36 +00:00
|
|
|
// int w=getMaxWidth(pain, inset);
|
|
|
|
// return (w - x);
|
|
|
|
return getMaxWidth(pain, inset) - 4; // 2+2 width of eventual border
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
|
|
|
|
void InsetText::SetParagraphData(LyXParagraph *p)
|
|
|
|
{
|
|
|
|
if (par)
|
|
|
|
delete par;
|
|
|
|
par = p->Clone();
|
|
|
|
par->SetInsetOwner(this);
|
|
|
|
init_inset = true;
|
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
|
|
|
|
void InsetText::SetAutoBreakRows(bool flag)
|
|
|
|
{
|
|
|
|
if (flag != autoBreakRows) {
|
|
|
|
autoBreakRows = flag;
|
|
|
|
init_inset = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InsetText::SetDrawLockedFrame(bool flag)
|
|
|
|
{
|
|
|
|
if (flag != drawLockedFrame) {
|
|
|
|
drawLockedFrame = flag;
|
|
|
|
init_inset = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InsetText::SetFrameColor(LColor::color col)
|
|
|
|
{
|
|
|
|
if (frame_color != col) {
|
|
|
|
frame_color = col;
|
|
|
|
init_inset = true;
|
|
|
|
}
|
|
|
|
}
|