2000-02-25 12:06:15 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2000-02-25 12:06:15 +00:00
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1998-2001 The LyX Team.
|
2000-02-25 12:06:15 +00:00
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "insettext.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "paragraph.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
#include "lyxlex.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "lyxfont.h"
|
|
|
|
#include "commandtags.h"
|
|
|
|
#include "buffer.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
#include "frontends/LyXView.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
#include "BufferView.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
#include "lyxtextclasslist.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
#include "frontends/Painter.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"
|
2002-05-24 14:34:32 +00:00
|
|
|
#include "frontends/font_metrics.h"
|
2000-05-15 14:49:36 +00:00
|
|
|
#include "LColor.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
#include "lyxrow.h"
|
2000-06-16 15:13:25 +00:00
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "intl.h"
|
|
|
|
#include "trans_mgr.h"
|
2002-05-23 15:43:25 +00:00
|
|
|
#include "frontends/screen.h"
|
2001-04-17 14:17:11 +00:00
|
|
|
#include "gettext.h"
|
2001-04-27 14:03:25 +00:00
|
|
|
#include "lyxfunc.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2001-07-06 15:57:54 +00:00
|
|
|
#include "undo_funcs.h"
|
2001-07-20 14:18:48 +00:00
|
|
|
#include "lyxfind.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
|
2001-12-18 03:21:10 +00:00
|
|
|
#include "frontends/Alert.h"
|
2002-03-22 15:24:32 +00:00
|
|
|
#include "frontends/Dialogs.h"
|
2001-12-18 03:21:10 +00:00
|
|
|
|
|
|
|
#include "support/textutils.h"
|
|
|
|
#include "support/LAssert.h"
|
|
|
|
#include "support/lstrings.h"
|
2002-01-14 13:04:06 +00:00
|
|
|
#include "support/lyxalgo.h" // lyx::count
|
2001-12-18 03:21:10 +00:00
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdlib>
|
|
|
|
//#include <csignal>
|
|
|
|
|
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;
|
2001-07-03 11:02:12 +00:00
|
|
|
using std::make_pair;
|
2001-11-07 13:22:43 +00:00
|
|
|
using std::vector;
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::pair;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2001-11-27 10:34:16 +00:00
|
|
|
using lyx::pos_type;
|
2001-11-29 17:12:21 +00:00
|
|
|
using lyx::textclass_type;
|
2001-11-27 10:34:16 +00:00
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
extern unsigned char getCurrentTextClass(Buffer *);
|
2001-01-02 16:06:14 +00:00
|
|
|
extern bool math_insert_greek(BufferView *, char);
|
|
|
|
extern int greek_kb_flag;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2001-07-12 12:26:06 +00:00
|
|
|
|
2001-08-19 13:13:47 +00:00
|
|
|
// These functions should probably go into bufferview_funcs somehow (Jug)
|
2001-07-12 12:26:06 +00:00
|
|
|
|
|
|
|
void InsetText::saveLyXTextState(LyXText * t) const
|
|
|
|
{
|
2001-08-10 12:21:42 +00:00
|
|
|
// check if my paragraphs are still valid
|
|
|
|
Paragraph * p = par;
|
2001-12-05 08:04:20 +00:00
|
|
|
while (p) {
|
2001-08-10 12:21:42 +00:00
|
|
|
if (p == t->cursor.par())
|
|
|
|
break;
|
|
|
|
p = p->next();
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-08-10 12:21:42 +00:00
|
|
|
if (p && t->cursor.pos() <= p->size()) {
|
|
|
|
sstate.lpar = t->cursor.par();
|
|
|
|
sstate.pos = t->cursor.pos();
|
|
|
|
sstate.boundary = t->cursor.boundary();
|
|
|
|
sstate.selstartpar = t->selection.start.par();
|
|
|
|
sstate.selstartpos = t->selection.start.pos();
|
|
|
|
sstate.selstartboundary = t->selection.start.boundary();
|
|
|
|
sstate.selendpar = t->selection.end.par();
|
|
|
|
sstate.selendpos = t->selection.end.pos();
|
|
|
|
sstate.selendboundary = t->selection.end.boundary();
|
|
|
|
sstate.selection = t->selection.set();
|
|
|
|
sstate.mark_set = t->selection.mark();
|
|
|
|
sstate.refresh = t->refresh_row != 0;
|
|
|
|
} else {
|
|
|
|
sstate.lpar = 0;
|
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InsetText::restoreLyXTextState(BufferView * bv, LyXText * t) const
|
|
|
|
{
|
|
|
|
if (sstate.lpar) {
|
|
|
|
t->selection.set(true);
|
|
|
|
/* at this point just to avoid the Delete-Empty-Paragraph
|
|
|
|
* Mechanism when setting the cursor */
|
|
|
|
t->selection.mark(sstate.mark_set);
|
|
|
|
if (sstate.selection) {
|
|
|
|
t->setCursor(bv, sstate.selstartpar, sstate.selstartpos,
|
2002-03-21 17:09:55 +00:00
|
|
|
true, sstate.selstartboundary);
|
2001-07-12 12:26:06 +00:00
|
|
|
t->selection.cursor = t->cursor;
|
|
|
|
t->setCursor(bv, sstate.selendpar, sstate.selendpos,
|
2002-03-21 17:09:55 +00:00
|
|
|
true, sstate.selendboundary);
|
2001-07-12 12:26:06 +00:00
|
|
|
t->setSelection(bv);
|
|
|
|
t->setCursor(bv, sstate.lpar, sstate.pos);
|
|
|
|
} else {
|
|
|
|
t->setCursor(bv, sstate.lpar, sstate.pos, true, sstate.boundary);
|
|
|
|
t->selection.cursor = t->cursor;
|
|
|
|
t->selection.set(false);
|
|
|
|
}
|
2001-08-02 14:55:06 +00:00
|
|
|
if (sstate.refresh) {
|
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetText::InnerCache::InnerCache(boost::shared_ptr<LyXText> t)
|
|
|
|
{
|
|
|
|
text = t;
|
|
|
|
remove = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-03 20:25:07 +00:00
|
|
|
InsetText::InsetText(BufferParams const & bp)
|
2001-08-13 11:04:49 +00:00
|
|
|
: UpdatableInset(), lt(0), in_update(false), do_resize(0),
|
|
|
|
do_reinit(false)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
par = new Paragraph;
|
2002-03-03 20:25:07 +00:00
|
|
|
par->layout(textclasslist[bp.textclass].defaultLayoutName());
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
init();
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-07 15:07:36 +00:00
|
|
|
InsetText::InsetText(InsetText const & in, bool same_id)
|
2001-08-13 11:04:49 +00:00
|
|
|
: UpdatableInset(in, same_id), lt(0), in_update(false), do_resize(0),
|
|
|
|
do_reinit(false)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
par = 0;
|
2001-08-07 15:07:36 +00:00
|
|
|
init(&in, same_id);
|
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)
|
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
init(&it);
|
|
|
|
return * this;
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
void InsetText::init(InsetText const * ins, bool same_id)
|
2000-03-28 16:18:02 +00:00
|
|
|
{
|
2001-08-07 15:07:36 +00:00
|
|
|
if (ins) {
|
2001-11-30 16:10:24 +00:00
|
|
|
setParagraphData(ins->par, same_id);
|
2001-08-07 15:07:36 +00:00
|
|
|
autoBreakRows = ins->autoBreakRows;
|
|
|
|
drawFrame_ = ins->drawFrame_;
|
|
|
|
frame_color = ins->frame_color;
|
|
|
|
if (same_id)
|
|
|
|
id_ = ins->id_;
|
|
|
|
} else {
|
|
|
|
Paragraph * p = par;
|
2001-12-05 08:04:20 +00:00
|
|
|
while (p) {
|
2001-08-07 15:07:36 +00:00
|
|
|
p->setInsetOwner(this);
|
|
|
|
p = p->next();
|
|
|
|
}
|
|
|
|
the_locking_inset = 0;
|
|
|
|
drawFrame_ = NEVER;
|
|
|
|
frame_color = LColor::insetframe;
|
|
|
|
autoBreakRows = false;
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
top_y = 0;
|
|
|
|
insetAscent = 0;
|
|
|
|
insetDescent = 0;
|
|
|
|
insetWidth = 0;
|
2001-05-28 15:11:24 +00:00
|
|
|
old_max_width = 0;
|
2002-03-29 12:24:50 +00:00
|
|
|
no_selection = true;
|
2001-08-10 09:39:15 +00:00
|
|
|
need_update = FULL;
|
2001-04-02 14:02:58 +00:00
|
|
|
drawTextXOffset = 0;
|
|
|
|
drawTextYOffset = 0;
|
|
|
|
xpos = 0.0;
|
|
|
|
locked = false;
|
|
|
|
old_par = 0;
|
|
|
|
last_drawn_width = -1;
|
2001-04-27 14:03:25 +00:00
|
|
|
frame_is_visible = false;
|
2001-07-02 15:29:23 +00:00
|
|
|
cached_bview = 0;
|
2001-07-12 12:26:06 +00:00
|
|
|
sstate.lpar = 0;
|
2001-12-05 15:34:41 +00:00
|
|
|
in_insetAllowed = false;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetText::~InsetText()
|
|
|
|
{
|
2001-07-02 15:29:23 +00:00
|
|
|
cached_bview = 0;
|
2001-05-03 14:31:33 +00:00
|
|
|
|
2001-07-05 14:52:08 +00:00
|
|
|
// NOTE
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-06 12:47:50 +00:00
|
|
|
while (par) {
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * tmp = par->next();
|
2001-04-06 12:47:50 +00:00
|
|
|
delete par;
|
|
|
|
par = tmp;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-14 14:57:20 +00:00
|
|
|
void InsetText::clear()
|
|
|
|
{
|
2002-03-04 16:10:47 +00:00
|
|
|
// This is a gross hack...
|
|
|
|
string old_layout = par->layout();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-06 12:47:50 +00:00
|
|
|
while (par) {
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * tmp = par->next();
|
2001-04-02 14:02:58 +00:00
|
|
|
delete par;
|
2001-04-06 12:47:50 +00:00
|
|
|
par = tmp;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
par = new Paragraph;
|
2002-03-06 16:02:51 +00:00
|
|
|
par->setInsetOwner(this);
|
2002-03-04 16:10:47 +00:00
|
|
|
par->layout(old_layout);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-11-29 12:58:59 +00:00
|
|
|
reinitLyXText();
|
2001-08-10 10:24:44 +00:00
|
|
|
need_update = INIT;
|
2000-07-14 14:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
Inset * InsetText::clone(Buffer const &, bool same_id) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2002-03-04 16:10:47 +00:00
|
|
|
return new InsetText(*this, same_id);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::write(Buffer const * buf, ostream & os) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
os << "Text\n";
|
2001-06-28 10:25:20 +00:00
|
|
|
writeParagraphData(buf, os);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-05-08 17:08:44 +00:00
|
|
|
par->writeFile(buf, os, buf->params, 0);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::read(Buffer const * buf, LyXLex & lex)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
string token;
|
|
|
|
int pos = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * return_par = 0;
|
2002-03-21 17:09:55 +00:00
|
|
|
Paragraph::depth_type depth = 0;
|
2001-04-02 14:02:58 +00:00
|
|
|
LyXFont font(LyXFont::ALL_INHERIT);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2001-05-08 10:50:09 +00:00
|
|
|
clear();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-08-06 19:13:25 +00:00
|
|
|
while (lex.isOK()) {
|
2001-04-02 14:02:58 +00:00
|
|
|
lex.nextToken();
|
2001-08-06 19:13:25 +00:00
|
|
|
token = lex.getString();
|
2001-04-02 14:02:58 +00:00
|
|
|
if (token.empty())
|
|
|
|
continue;
|
2001-07-25 19:45:21 +00:00
|
|
|
if (token == "\\end_inset") {
|
2001-08-03 18:28:11 +00:00
|
|
|
#ifndef NO_COMPABILITY
|
2002-01-12 18:40:05 +00:00
|
|
|
const_cast<Buffer*>(buf)->insertErtContents(par, pos, false);
|
2001-07-25 19:45:21 +00:00
|
|
|
#endif
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
2001-07-25 19:45:21 +00:00
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
if (const_cast<Buffer*>(buf)->
|
2001-04-06 12:47:50 +00:00
|
|
|
parseSingleLyXformat2Token(lex, par, return_par,
|
2001-05-03 14:31:33 +00:00
|
|
|
token, pos, depth, font)) {
|
2001-04-02 14:02:58 +00:00
|
|
|
// the_end read this should NEVER happen
|
|
|
|
lex.printError("\\the_end read in inset! Error in document!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!return_par)
|
|
|
|
return_par = par;
|
|
|
|
par = return_par;
|
2001-12-05 08:04:20 +00:00
|
|
|
while (return_par) {
|
2001-06-25 00:06:33 +00:00
|
|
|
return_par->setInsetOwner(this);
|
2001-04-02 14:02:58 +00:00
|
|
|
return_par = return_par->next();
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
if (token != "\\end_inset") {
|
|
|
|
lex.printError("Missing \\end_inset at this point. "
|
|
|
|
"Read: `$$Token'");
|
|
|
|
}
|
2001-08-10 09:39:15 +00:00
|
|
|
need_update = FULL;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetText::ascent(BufferView * bv, LyXFont const &) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-12-18 12:35:53 +00:00
|
|
|
insetAscent = getLyXText(bv)->firstRow()->ascent_of_text() +
|
|
|
|
TEXT_TO_INSET_OFFSET;
|
2001-04-02 14:02:58 +00:00
|
|
|
return insetAscent;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetText::descent(BufferView * bv, LyXFont const &) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-12-18 12:35:53 +00:00
|
|
|
LyXText * llt = getLyXText(bv);
|
|
|
|
insetDescent = llt->height - llt->firstRow()->ascent_of_text() +
|
2001-11-29 13:43:12 +00:00
|
|
|
TEXT_TO_INSET_OFFSET;
|
2001-04-02 14:02:58 +00:00
|
|
|
return insetDescent;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetText::width(BufferView * bv, LyXFont const &) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-08-06 14:55:02 +00:00
|
|
|
insetWidth = max(textWidth(bv), (int)getLyXText(bv)->width) +
|
|
|
|
(2 * TEXT_TO_INSET_OFFSET);
|
|
|
|
insetWidth = max(insetWidth, 10);
|
2001-04-02 14:02:58 +00:00
|
|
|
return insetWidth;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
int InsetText::textWidth(BufferView * bv, bool fordraw) const
|
2000-06-23 15:02:46 +00:00
|
|
|
{
|
2001-08-06 14:55:02 +00:00
|
|
|
int w;
|
|
|
|
if (!autoBreakRows) {
|
|
|
|
w = -1;
|
|
|
|
} else {
|
|
|
|
w = getMaxWidth(bv, this);
|
|
|
|
}
|
|
|
|
if (fordraw) {
|
|
|
|
return max(w - (2 * TEXT_TO_INSET_OFFSET),
|
2002-03-21 17:09:55 +00:00
|
|
|
(int)getLyXText(bv)->width);
|
2001-08-06 14:55:02 +00:00
|
|
|
} else if (w < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return w - (2 * TEXT_TO_INSET_OFFSET);
|
2000-06-23 15:02:46 +00:00
|
|
|
}
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
void InsetText::draw(BufferView * bv, LyXFont const & f,
|
2002-03-21 17:09:55 +00:00
|
|
|
int baseline, float & x, bool cleared) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-27 14:03:25 +00:00
|
|
|
if (nodraw())
|
|
|
|
return;
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
Painter & pain = bv->painter();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-08-02 14:55:06 +00:00
|
|
|
// this is the first thing we have to ask because if the x pos
|
|
|
|
// changed we have to do a complete rebreak of the text as we
|
|
|
|
// may have few space to draw in. Well we should check on this too
|
2001-08-06 14:55:02 +00:00
|
|
|
int old_x = top_x;
|
2001-08-02 14:55:06 +00:00
|
|
|
if (top_x != int(x)) {
|
|
|
|
top_x = int(x);
|
2002-01-17 10:13:23 +00:00
|
|
|
topx_set = true;
|
2001-08-02 14:55:06 +00:00
|
|
|
int nw = getMaxWidth(bv, this);
|
|
|
|
if (nw > 0 && old_max_width != nw) {
|
|
|
|
need_update = INIT;
|
|
|
|
old_max_width = nw;
|
|
|
|
bv->text->status(bv, LyXText::CHANGED_IN_DRAW);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-06 19:34:30 +00:00
|
|
|
// call these methods so that insetWidth, insetAscent and
|
2002-03-21 17:09:55 +00:00
|
|
|
// insetDescent have the right values.
|
2002-01-06 19:34:30 +00:00
|
|
|
width(bv, f);
|
|
|
|
ascent(bv, f);
|
|
|
|
descent(bv, f);
|
|
|
|
|
2001-08-02 14:55:06 +00:00
|
|
|
// repaint the background if needed
|
|
|
|
if (cleared && backgroundColor() != LColor::background) {
|
2001-12-04 16:10:19 +00:00
|
|
|
clearInset(bv, baseline, cleared);
|
2001-08-02 14:55:06 +00:00
|
|
|
}
|
2000-06-21 15:07:57 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
// no draw is necessary !!!
|
2001-04-27 14:03:25 +00:00
|
|
|
if ((drawFrame_ == LOCKED) && !locked && !par->size()) {
|
|
|
|
top_baseline = baseline;
|
|
|
|
x += width(bv, f);
|
2001-08-06 14:55:02 +00:00
|
|
|
if (need_update & CLEAR_FRAME)
|
2001-04-27 14:03:25 +00:00
|
|
|
clearFrame(pain, cleared);
|
|
|
|
need_update = NONE;
|
|
|
|
return;
|
2000-08-09 13:51:59 +00:00
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
|
|
|
xpos = x;
|
2001-04-27 14:03:25 +00:00
|
|
|
if (!owner())
|
|
|
|
x += static_cast<float>(scroll());
|
2001-04-02 14:02:58 +00:00
|
|
|
|
2001-08-07 15:07:36 +00:00
|
|
|
// if top_x differs we did it already
|
2002-01-17 10:13:23 +00:00
|
|
|
if (!cleared && (old_x == int(x))
|
2001-12-10 09:59:39 +00:00
|
|
|
&& ((need_update&(INIT|FULL)) || (top_baseline != baseline)
|
2002-01-17 10:13:23 +00:00
|
|
|
||(last_drawn_width != insetWidth)))
|
|
|
|
{
|
2002-01-07 10:17:44 +00:00
|
|
|
// Condition necessary to eliminate bug 59 attachment 37
|
2002-01-17 10:13:23 +00:00
|
|
|
if (baseline > 0)
|
|
|
|
clearInset(bv, baseline, cleared);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-08-06 14:55:02 +00:00
|
|
|
|
2001-05-28 15:11:24 +00:00
|
|
|
if (cleared)
|
|
|
|
frame_is_visible = false;
|
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
if (!cleared && (need_update == NONE)) {
|
|
|
|
if (locked)
|
|
|
|
drawFrame(pain, cleared);
|
2001-04-02 14:02:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-06-26 15:10:49 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
top_baseline = baseline;
|
2001-12-10 13:30:27 +00:00
|
|
|
top_y = baseline - insetAscent;
|
2001-04-02 14:02:58 +00:00
|
|
|
|
2001-12-04 16:10:19 +00:00
|
|
|
if (last_drawn_width != insetWidth) {
|
2002-03-21 17:09:55 +00:00
|
|
|
if (!cleared)
|
2001-12-04 16:10:19 +00:00
|
|
|
clearInset(bv, baseline, cleared);
|
2001-08-06 14:55:02 +00:00
|
|
|
need_update |= FULL;
|
|
|
|
last_drawn_width = insetWidth;
|
|
|
|
}
|
|
|
|
|
2001-06-29 15:17:05 +00:00
|
|
|
if (the_locking_inset && (cpar(bv) == inset_par)
|
|
|
|
&& (cpos(bv) == inset_pos)) {
|
2002-04-12 15:59:03 +00:00
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2002-04-11 15:08:22 +00:00
|
|
|
inset_y = ciy(bv) + drawTextYOffset;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-06-29 15:17:05 +00:00
|
|
|
if (!cleared && (need_update == CURSOR)
|
2001-09-09 22:02:19 +00:00
|
|
|
&& !getLyXText(bv)->selection.set()) {
|
2001-04-27 14:03:25 +00:00
|
|
|
drawFrame(pain, cleared);
|
2002-03-21 17:09:55 +00:00
|
|
|
x += insetWidth;
|
2001-04-02 14:02:58 +00:00
|
|
|
need_update = NONE;
|
|
|
|
return;
|
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
x += TEXT_TO_INSET_OFFSET;
|
2001-04-06 12:47:50 +00:00
|
|
|
|
2001-11-29 13:43:12 +00:00
|
|
|
Row * row = lt->firstRow();
|
2000-10-19 09:11:39 +00:00
|
|
|
int y_offset = baseline - row->ascent_of_text();
|
|
|
|
int ph = pain.paperHeight();
|
|
|
|
int first = 0;
|
2001-11-29 13:43:12 +00:00
|
|
|
int y = y_offset;
|
2000-10-19 09:11:39 +00:00
|
|
|
while ((row != 0) && ((y+row->height()) <= 0)) {
|
2001-04-02 14:02:58 +00:00
|
|
|
y += row->height();
|
|
|
|
first += row->height();
|
|
|
|
row = row->next();
|
2000-06-21 15:07:57 +00:00
|
|
|
}
|
2002-04-18 09:47:08 +00:00
|
|
|
if (y_offset < 0) {
|
|
|
|
lt->first_y = -y_offset;
|
|
|
|
first = y;
|
|
|
|
y_offset = 0;
|
|
|
|
} else {
|
|
|
|
lt->first_y = first;
|
|
|
|
first = 0;
|
|
|
|
}
|
2001-08-06 14:55:02 +00:00
|
|
|
if (cleared || (need_update&(INIT|FULL))) {
|
2002-04-18 09:47:08 +00:00
|
|
|
int yf = y_offset + first;
|
2001-04-02 14:02:58 +00:00
|
|
|
y = 0;
|
|
|
|
while ((row != 0) && (yf < ph)) {
|
2002-05-01 22:17:09 +00:00
|
|
|
lt->getVisibleRow(bv, y + y_offset + first, int(x),
|
|
|
|
row, y + lt->first_y, cleared);
|
2002-04-19 14:16:08 +00:00
|
|
|
if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
|
|
|
|
lt->need_break_row = row;
|
2002-05-01 22:17:09 +00:00
|
|
|
lt->fullRebreak(bv);
|
|
|
|
lt->setCursor(bv, lt->cursor.par(),
|
|
|
|
lt->cursor.pos());
|
|
|
|
if (lt->selection.set()) {
|
|
|
|
lt->setCursor(bv, lt->selection.start,
|
|
|
|
lt->selection.start.par(),
|
|
|
|
lt->selection.start.pos());
|
|
|
|
lt->setCursor(bv, lt->selection.end,
|
|
|
|
lt->selection.end.par(),
|
|
|
|
lt->selection.end.pos());
|
2002-04-19 14:16:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-05-28 15:11:24 +00:00
|
|
|
y += row->height();
|
|
|
|
yf += row->height();
|
|
|
|
row = row->next();
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-02-23 16:10:03 +00:00
|
|
|
} else if (!locked) {
|
2001-04-02 14:02:58 +00:00
|
|
|
if (need_update & CURSOR) {
|
2001-07-12 12:26:06 +00:00
|
|
|
bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
|
2001-08-01 15:42:53 +00:00
|
|
|
lt->clearSelection();
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->selection.cursor = lt->cursor;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
bv->screen()->update(lt, bv, y_offset, int(x));
|
2000-10-19 09:11:39 +00:00
|
|
|
} else {
|
2001-04-02 14:02:58 +00:00
|
|
|
locked = false;
|
2001-09-09 22:02:19 +00:00
|
|
|
if (need_update & SELECTION) {
|
2001-07-12 12:26:06 +00:00
|
|
|
bv->screen()->toggleToggle(lt, bv, y_offset, int(x));
|
2001-09-09 22:02:19 +00:00
|
|
|
} else if (need_update & CURSOR) {
|
2001-07-12 12:26:06 +00:00
|
|
|
bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
|
2001-08-01 15:42:53 +00:00
|
|
|
lt->clearSelection();
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->selection.cursor = lt->cursor;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
bv->screen()->update(lt, bv, y_offset, int(x));
|
2001-04-02 14:02:58 +00:00
|
|
|
locked = true;
|
|
|
|
}
|
2001-06-14 14:10:25 +00:00
|
|
|
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->refresh_y = 0;
|
|
|
|
lt->status(bv, LyXText::UNCHANGED);
|
2002-03-06 10:40:31 +00:00
|
|
|
if ((drawFrame_ == ALWAYS) ||
|
|
|
|
((cleared || (need_update != CURSOR_PAR)) &&
|
|
|
|
(drawFrame_ == LOCKED) && locked))
|
|
|
|
{
|
2001-04-27 14:03:25 +00:00
|
|
|
drawFrame(pain, cleared);
|
2001-09-09 22:02:19 +00:00
|
|
|
} else if (need_update & CLEAR_FRAME) {
|
2001-04-27 14:03:25 +00:00
|
|
|
clearFrame(pain, cleared);
|
2001-09-09 22:02:19 +00:00
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-12-10 09:59:39 +00:00
|
|
|
x += insetWidth - TEXT_TO_INSET_OFFSET;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
|
2001-08-10 09:39:15 +00:00
|
|
|
need_update |= FULL;
|
2001-09-09 22:02:19 +00:00
|
|
|
} else if (need_update != INIT) {
|
2001-04-02 14:02:58 +00:00
|
|
|
need_update = NONE;
|
2001-09-09 22:02:19 +00:00
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-27 14:03:25 +00:00
|
|
|
void InsetText::drawFrame(Painter & pain, bool cleared) const
|
|
|
|
{
|
2001-08-06 14:55:02 +00:00
|
|
|
static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
|
2001-04-27 14:03:25 +00:00
|
|
|
if (!frame_is_visible || cleared) {
|
2001-08-06 14:55:02 +00:00
|
|
|
frame_x = top_x + ttoD2;
|
|
|
|
frame_y = top_baseline - insetAscent + ttoD2;
|
2001-12-10 09:59:39 +00:00
|
|
|
frame_w = insetWidth - TEXT_TO_INSET_OFFSET;
|
2001-08-06 14:55:02 +00:00
|
|
|
frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET;
|
2002-01-06 19:34:30 +00:00
|
|
|
pain.rectangle(frame_x, frame_y, frame_w, frame_h,
|
2002-03-21 17:09:55 +00:00
|
|
|
frame_color);
|
2001-04-27 14:03:25 +00:00
|
|
|
frame_is_visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::clearFrame(Painter & pain, bool cleared) const
|
|
|
|
{
|
|
|
|
if (frame_is_visible) {
|
|
|
|
if (!cleared) {
|
2001-07-31 09:53:40 +00:00
|
|
|
pain.rectangle(frame_x, frame_y, frame_w, frame_h,
|
2002-03-21 17:09:55 +00:00
|
|
|
backgroundColor());
|
2001-04-27 14:03:25 +00:00
|
|
|
}
|
|
|
|
frame_is_visible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-07 07:46:37 +00:00
|
|
|
void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
|
2000-06-16 15:13:25 +00:00
|
|
|
{
|
2001-08-07 15:07:36 +00:00
|
|
|
if (in_update) {
|
|
|
|
if (reinit && owner()) {
|
2001-08-08 13:29:13 +00:00
|
|
|
reinitLyXText();
|
2001-08-07 15:07:36 +00:00
|
|
|
owner()->update(bv, font, true);
|
|
|
|
}
|
2001-08-01 15:42:53 +00:00
|
|
|
return;
|
2001-08-07 15:07:36 +00:00
|
|
|
}
|
2001-08-01 15:42:53 +00:00
|
|
|
in_update = true;
|
2001-08-07 15:07:36 +00:00
|
|
|
if (reinit || need_update == INIT) {
|
2001-08-10 10:24:44 +00:00
|
|
|
need_update = FULL;
|
2001-11-29 12:58:59 +00:00
|
|
|
// we should put this call where we set need_update to INIT!
|
2001-08-07 15:07:36 +00:00
|
|
|
reinitLyXText();
|
2001-04-02 14:02:58 +00:00
|
|
|
if (owner())
|
|
|
|
owner()->update(bv, font, true);
|
2001-08-01 15:42:53 +00:00
|
|
|
in_update = false;
|
2001-04-02 14:02:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-03-26 11:05:30 +00:00
|
|
|
|
|
|
|
if (!autoBreakRows && par->next())
|
2002-04-12 15:59:03 +00:00
|
|
|
collapseParagraphs(bv);
|
2002-03-26 11:05:30 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
if (the_locking_inset) {
|
2002-04-12 15:59:03 +00:00
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2002-04-11 15:08:22 +00:00
|
|
|
inset_y = ciy(bv) + drawTextYOffset;
|
2001-04-02 14:02:58 +00:00
|
|
|
the_locking_inset->update(bv, font, reinit);
|
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
|
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
if ((need_update & CURSOR_PAR) && (lt->status() == LyXText::UNCHANGED) &&
|
2001-07-06 15:57:54 +00:00
|
|
|
the_locking_inset)
|
|
|
|
{
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->updateInset(bv, the_locking_inset);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
if (lt->status() == LyXText::NEED_MORE_REFRESH)
|
2001-04-27 14:03:25 +00:00
|
|
|
need_update |= FULL;
|
2001-07-12 12:26:06 +00:00
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
2001-08-01 15:42:53 +00:00
|
|
|
in_update = false;
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
|
|
|
|
2001-04-06 12:47:50 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::setUpdateStatus(BufferView * bv, int what) const
|
2001-02-14 08:38:21 +00:00
|
|
|
{
|
2001-12-18 12:35:53 +00:00
|
|
|
// this does nothing dangerous so use only a localized buffer
|
|
|
|
LyXText * llt = getLyXText(bv);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
need_update |= what;
|
2001-08-06 14:55:02 +00:00
|
|
|
// we have to redraw us full if our LyXText NEEDS_MORE_REFRES or
|
|
|
|
// if we don't break row so that we only have one row to update!
|
2001-12-18 12:35:53 +00:00
|
|
|
if ((llt->status() == LyXText::NEED_MORE_REFRESH) ||
|
2001-08-06 14:55:02 +00:00
|
|
|
(!autoBreakRows &&
|
2001-12-18 12:35:53 +00:00
|
|
|
(llt->status() == LyXText::NEED_VERY_LITTLE_REFRESH)))
|
2001-08-06 14:55:02 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
need_update |= FULL;
|
2001-12-18 12:35:53 +00:00
|
|
|
} else if (llt->status() == LyXText::NEED_VERY_LITTLE_REFRESH) {
|
2001-04-02 14:02:58 +00:00
|
|
|
need_update |= CURSOR_PAR;
|
2001-08-06 14:55:02 +00:00
|
|
|
}
|
2001-02-22 14:33:08 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
// this to not draw a selection when we redraw all of it!
|
2001-08-06 14:55:02 +00:00
|
|
|
if (need_update & CURSOR && !(need_update & SELECTION)) {
|
2001-12-18 12:35:53 +00:00
|
|
|
if (llt->selection.set())
|
2001-08-01 15:42:53 +00:00
|
|
|
need_update = FULL;
|
2001-12-18 12:35:53 +00:00
|
|
|
llt->clearSelection();
|
2001-08-01 15:42:53 +00:00
|
|
|
}
|
2001-02-14 08:38:21 +00:00
|
|
|
}
|
2000-07-04 11:30:07 +00:00
|
|
|
|
2001-04-06 12:47:50 +00:00
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
|
2000-07-04 11:30:07 +00:00
|
|
|
{
|
2001-12-18 12:35:53 +00:00
|
|
|
if (!autoBreakRows && par->next())
|
2002-04-12 15:59:03 +00:00
|
|
|
collapseParagraphs(bv);
|
2001-07-12 12:26:06 +00:00
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
|
|
|
lt->fullRebreak(bv);
|
2001-06-28 10:25:20 +00:00
|
|
|
setUpdateStatus(bv, what);
|
2002-03-29 15:49:45 +00:00
|
|
|
bool flag = mark_dirty ||
|
|
|
|
(((need_update != CURSOR) && (need_update != NONE)) ||
|
|
|
|
(lt->status() != LyXText::UNCHANGED) || lt->selection.set());
|
2002-03-05 14:55:20 +00:00
|
|
|
if (!lt->selection.set())
|
|
|
|
lt->selection.cursor = lt->cursor;
|
2001-12-18 12:35:53 +00:00
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
2002-04-12 15:59:03 +00:00
|
|
|
#if 0
|
|
|
|
// IMO this is not anymore needed as we do this in fitInsetCursor!
|
|
|
|
// and we always get "true" as returnvalue of this function in the
|
|
|
|
// case of a locking inset (Jug 20020412)
|
2002-03-29 15:49:45 +00:00
|
|
|
if (locked && (need_update & CURSOR) && bv->fitCursor())
|
|
|
|
need_update |= FULL;
|
2002-04-12 15:59:03 +00:00
|
|
|
#else
|
|
|
|
bv->fitCursor();
|
|
|
|
#endif
|
2001-12-18 12:35:53 +00:00
|
|
|
if (flag)
|
2001-07-20 14:18:48 +00:00
|
|
|
bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
if (need_update == CURSOR)
|
|
|
|
need_update = NONE;
|
2001-04-02 14:02:58 +00:00
|
|
|
bv->owner()->showState();
|
2002-01-13 13:07:27 +00:00
|
|
|
bv->owner()->updateMenubar();
|
|
|
|
bv->owner()->updateToolbar();
|
2001-04-02 14:02:58 +00:00
|
|
|
if (old_par != cpar(bv)) {
|
2002-03-02 16:39:54 +00:00
|
|
|
bv->owner()->setLayout(cpar(bv)->layout());
|
2001-04-02 14:02:58 +00:00
|
|
|
old_par = cpar(bv);
|
|
|
|
}
|
2000-06-16 15:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
string const InsetText::editMessage() const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
return _("Opened Text Inset");
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-26 17:33:14 +00:00
|
|
|
void InsetText::edit(BufferView * bv, int x, int y, mouse_button::state button)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
UpdatableInset::edit(bv, x, y, button);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!bv->lockInset(this)) {
|
|
|
|
lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
locked = true;
|
|
|
|
the_locking_inset = 0;
|
|
|
|
inset_pos = inset_x = inset_y = 0;
|
|
|
|
inset_boundary = false;
|
|
|
|
inset_par = 0;
|
|
|
|
old_par = 0;
|
2001-06-29 15:17:05 +00:00
|
|
|
int tmp_y = (y < 0) ? 0 : y;
|
2001-07-12 12:26:06 +00:00
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
2002-05-14 09:10:14 +00:00
|
|
|
// we put here -1 and not button as now the button in the
|
|
|
|
// edit call should not be needed we will fix this in 1.3.x
|
|
|
|
// cycle hopefully (Jug 20020509)
|
2002-05-26 17:33:14 +00:00
|
|
|
// FIXME: GUII I've changed this to none: probably WRONG
|
|
|
|
if (!checkAndActivateInset(bv, x, tmp_y, mouse_button::none)) {
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
|
2002-03-21 17:09:55 +00:00
|
|
|
y + insetAscent);
|
2002-04-16 14:10:39 +00:00
|
|
|
lt->cursor.x_fix(lt->cursor.x());
|
|
|
|
}
|
2001-08-01 15:42:53 +00:00
|
|
|
lt->clearSelection();
|
2001-07-20 14:18:48 +00:00
|
|
|
finishUndo();
|
|
|
|
// If the inset is empty set the language of the current font to the
|
|
|
|
// language to the surronding text (if different).
|
|
|
|
if (par->size() == 0 && !par->next() &&
|
2001-12-18 12:35:53 +00:00
|
|
|
bv->getParentLanguage(this) != lt->current_font.language())
|
|
|
|
{
|
2001-07-20 14:18:48 +00:00
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
font.setLanguage(bv->getParentLanguage(this));
|
|
|
|
setFont(bv, font, false);
|
|
|
|
}
|
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2002-01-17 14:27:01 +00:00
|
|
|
int code = CURSOR;
|
|
|
|
if (drawFrame_ == LOCKED)
|
|
|
|
code = CURSOR|DRAW_FRAME;
|
|
|
|
updateLocal(bv, code, false);
|
2002-03-29 15:49:45 +00:00
|
|
|
showInsetCursor(bv);
|
2002-03-22 15:24:32 +00:00
|
|
|
|
|
|
|
// Tell the paragraph dialog that we've entered an insettext.
|
|
|
|
bv->owner()->getDialogs()->updateParagraph();
|
2001-07-20 14:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::edit(BufferView * bv, bool front)
|
|
|
|
{
|
|
|
|
UpdatableInset::edit(bv, front);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
if (!bv->lockInset(this)) {
|
|
|
|
lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
locked = true;
|
|
|
|
the_locking_inset = 0;
|
|
|
|
inset_pos = inset_x = inset_y = 0;
|
|
|
|
inset_boundary = false;
|
|
|
|
inset_par = 0;
|
|
|
|
old_par = 0;
|
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
|
|
|
if (front)
|
|
|
|
lt->setCursor(bv, par, 0);
|
|
|
|
else {
|
|
|
|
Paragraph * p = par;
|
2001-12-05 08:04:20 +00:00
|
|
|
while (p->next())
|
2001-07-20 14:18:48 +00:00
|
|
|
p = p->next();
|
2001-08-13 11:27:53 +00:00
|
|
|
// int const pos = (p->size() ? p->size()-1 : p->size());
|
|
|
|
lt->setCursor(bv, p, p->size());
|
2001-07-20 14:18:48 +00:00
|
|
|
}
|
2001-08-01 15:42:53 +00:00
|
|
|
lt->clearSelection();
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2001-04-02 14:02:58 +00:00
|
|
|
// If the inset is empty set the language of the current font to the
|
2001-05-28 15:11:24 +00:00
|
|
|
// language to the surronding text (if different).
|
|
|
|
if (par->size() == 0 && !par->next() &&
|
2001-07-12 12:26:06 +00:00
|
|
|
bv->getParentLanguage(this) != lt->current_font.language()) {
|
2001-04-02 14:02:58 +00:00
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
font.setLanguage(bv->getParentLanguage(this));
|
2001-06-28 10:25:20 +00:00
|
|
|
setFont(bv, font, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
2002-01-17 14:27:01 +00:00
|
|
|
int code = CURSOR;
|
|
|
|
if (drawFrame_ == LOCKED)
|
|
|
|
code = CURSOR|DRAW_FRAME;
|
|
|
|
updateLocal(bv, code, false);
|
2002-03-29 15:49:45 +00:00
|
|
|
showInsetCursor(bv);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::insetUnlock(BufferView * bv)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (the_locking_inset) {
|
2001-06-28 10:25:20 +00:00
|
|
|
the_locking_inset->insetUnlock(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
the_locking_inset = 0;
|
2002-04-16 14:10:39 +00:00
|
|
|
updateLocal(bv, CURSOR_PAR, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
hideInsetCursor(bv);
|
2002-03-29 12:24:50 +00:00
|
|
|
no_selection = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
locked = false;
|
2002-04-22 14:31:47 +00:00
|
|
|
int code = NONE;
|
2002-04-16 14:10:39 +00:00
|
|
|
#if 0
|
2001-07-24 10:13:19 +00:00
|
|
|
if (drawFrame_ == LOCKED)
|
|
|
|
code = CURSOR|CLEAR_FRAME;
|
2002-03-21 17:09:55 +00:00
|
|
|
else
|
2001-07-24 10:13:19 +00:00
|
|
|
code = CURSOR;
|
2002-04-16 14:10:39 +00:00
|
|
|
#else
|
|
|
|
if (drawFrame_ == LOCKED)
|
|
|
|
code = CLEAR_FRAME;
|
|
|
|
#endif
|
2001-07-12 12:26:06 +00:00
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
|
|
|
if (lt->selection.set()) {
|
2001-08-01 15:42:53 +00:00
|
|
|
lt->clearSelection();
|
2001-05-28 15:11:24 +00:00
|
|
|
code = FULL;
|
2001-06-29 15:17:05 +00:00
|
|
|
} else if (owner()) {
|
2001-04-02 14:02:58 +00:00
|
|
|
bv->owner()->setLayout(owner()->getLyXText(bv)
|
2002-03-21 17:09:55 +00:00
|
|
|
->cursor.par()->layout());
|
2001-06-29 15:17:05 +00:00
|
|
|
} else
|
2002-03-02 16:39:54 +00:00
|
|
|
bv->owner()->setLayout(bv->text->cursor.par()->layout());
|
2001-08-08 13:29:13 +00:00
|
|
|
// hack for deleteEmptyParMech
|
2002-02-22 13:25:03 +00:00
|
|
|
if (par->size()) {
|
|
|
|
lt->setCursor(bv, par, 0);
|
|
|
|
} else if (par->next()) {
|
|
|
|
lt->setCursor(bv, par->next(), 0);
|
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
2002-04-16 14:10:39 +00:00
|
|
|
#if 0
|
2001-12-18 12:35:53 +00:00
|
|
|
updateLocal(bv, code, false);
|
2002-04-16 14:10:39 +00:00
|
|
|
#else
|
2002-04-22 14:31:47 +00:00
|
|
|
if (code != NONE)
|
|
|
|
setUpdateStatus(bv, code);
|
2002-04-16 14:10:39 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::lockInset(BufferView * bv)
|
|
|
|
{
|
|
|
|
locked = true;
|
|
|
|
the_locking_inset = 0;
|
|
|
|
inset_pos = inset_x = inset_y = 0;
|
|
|
|
inset_boundary = false;
|
|
|
|
inset_par = 0;
|
|
|
|
old_par = 0;
|
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
|
|
|
lt->setCursor(bv, par, 0);
|
|
|
|
lt->clearSelection();
|
|
|
|
finishUndo();
|
|
|
|
// If the inset is empty set the language of the current font to the
|
|
|
|
// language to the surronding text (if different).
|
|
|
|
if (par->size() == 0 && !par->next() &&
|
|
|
|
bv->getParentLanguage(this) != lt->current_font.language()) {
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
font.setLanguage(bv->getParentLanguage(this));
|
|
|
|
setFont(bv, font, false);
|
|
|
|
}
|
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
|
|
|
int code = CURSOR;
|
|
|
|
if (drawFrame_ == LOCKED)
|
|
|
|
code = CURSOR|DRAW_FRAME;
|
|
|
|
setUpdateStatus(bv, code);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
2002-04-16 14:10:39 +00:00
|
|
|
|
2001-12-14 11:55:58 +00:00
|
|
|
void InsetText::lockInset(BufferView * bv, UpdatableInset * inset)
|
|
|
|
{
|
|
|
|
the_locking_inset = inset;
|
2002-04-12 15:59:03 +00:00
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2002-04-11 15:08:22 +00:00
|
|
|
inset_y = ciy(bv) + drawTextYOffset;
|
2001-12-14 11:55:58 +00:00
|
|
|
inset_pos = cpos(bv);
|
|
|
|
inset_par = cpar(bv);
|
|
|
|
inset_boundary = cboundary(bv);
|
|
|
|
updateLocal(bv, CURSOR, false);
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2001-04-06 12:47:50 +00:00
|
|
|
lyxerr[Debug::INSETS] << "InsetText::LockInsetInInset("
|
|
|
|
<< inset << "): ";
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!inset)
|
|
|
|
return false;
|
2001-12-14 11:55:58 +00:00
|
|
|
if (!the_locking_inset) {
|
|
|
|
Paragraph * p = par;
|
|
|
|
int const id = inset->id();
|
|
|
|
while(p) {
|
|
|
|
Paragraph::inset_iterator it =
|
|
|
|
p->inset_iterator_begin();
|
|
|
|
Paragraph::inset_iterator const end =
|
|
|
|
p->inset_iterator_end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if ((*it) == inset) {
|
|
|
|
getLyXText(bv)->setCursorIntern(bv, p, it.getPos());
|
|
|
|
lockInset(bv, inset);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ((*it)->getInsetFromID(id)) {
|
2002-01-04 16:03:53 +00:00
|
|
|
getLyXText(bv)->setCursorIntern(bv, p, it.getPos());
|
2002-01-17 14:27:01 +00:00
|
|
|
(*it)->edit(bv);
|
2001-12-14 11:55:58 +00:00
|
|
|
return the_locking_inset->lockInsetInInset(bv, inset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p = p->next();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
if (inset == cpar(bv)->getInset(cpos(bv))) {
|
2001-04-02 14:02:58 +00:00
|
|
|
lyxerr[Debug::INSETS] << "OK" << endl;
|
2001-12-14 11:55:58 +00:00
|
|
|
lockInset(bv, inset);
|
2001-04-02 14:02:58 +00:00
|
|
|
return true;
|
|
|
|
} else if (the_locking_inset && (the_locking_inset == inset)) {
|
|
|
|
if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
|
|
|
|
lyxerr[Debug::INSETS] << "OK" << endl;
|
2002-04-12 15:59:03 +00:00
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2002-04-11 15:08:22 +00:00
|
|
|
inset_y = ciy(bv) + drawTextYOffset;
|
2001-04-02 14:02:58 +00:00
|
|
|
} else {
|
|
|
|
lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
|
|
|
|
}
|
|
|
|
} else if (the_locking_inset) {
|
|
|
|
lyxerr[Debug::INSETS] << "MAYBE" << endl;
|
2001-06-28 10:25:20 +00:00
|
|
|
return the_locking_inset->lockInsetInInset(bv, inset);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
lyxerr[Debug::INSETS] << "NOT OK" << endl;
|
|
|
|
return false;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
|
2002-03-21 17:09:55 +00:00
|
|
|
bool lr)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!the_locking_inset)
|
|
|
|
return false;
|
|
|
|
if (the_locking_inset == inset) {
|
2001-06-28 10:25:20 +00:00
|
|
|
the_locking_inset->insetUnlock(bv);
|
2001-06-29 15:17:05 +00:00
|
|
|
getLyXText(bv)->updateInset(bv, inset);
|
2001-04-02 14:02:58 +00:00
|
|
|
the_locking_inset = 0;
|
|
|
|
if (lr)
|
|
|
|
moveRight(bv, false);
|
|
|
|
old_par = 0; // force layout setting
|
2001-04-27 14:03:25 +00:00
|
|
|
if (scroll())
|
|
|
|
scroll(bv, 0.0F);
|
|
|
|
else
|
2001-06-28 10:25:20 +00:00
|
|
|
updateLocal(bv, CURSOR, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-06-28 10:25:20 +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
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-12-18 12:35:53 +00:00
|
|
|
if (!autoBreakRows && par->next())
|
2002-04-12 15:59:03 +00:00
|
|
|
collapseParagraphs(bv);
|
2001-12-18 14:36:27 +00:00
|
|
|
if (inset == this)
|
|
|
|
return true;
|
2001-12-03 13:17:04 +00:00
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
2002-03-08 11:42:30 +00:00
|
|
|
if (inset->owner() != this) {
|
2002-03-11 11:26:22 +00:00
|
|
|
int ustat = CURSOR_PAR;
|
|
|
|
bool found = false;
|
|
|
|
UpdatableInset * tl_inset = the_locking_inset;
|
|
|
|
if (tl_inset)
|
|
|
|
found = tl_inset->updateInsetInInset(bv, inset);
|
|
|
|
if (!found) {
|
|
|
|
tl_inset = static_cast<UpdatableInset *>(inset);
|
|
|
|
while(tl_inset->owner() && tl_inset->owner() != this)
|
|
|
|
tl_inset = static_cast<UpdatableInset *>(tl_inset->owner());
|
|
|
|
if (!tl_inset->owner())
|
|
|
|
return false;
|
|
|
|
found = tl_inset->updateInsetInInset(bv, inset);
|
|
|
|
ustat = FULL;
|
|
|
|
}
|
|
|
|
if (found)
|
|
|
|
lt->updateInset(bv, tl_inset);
|
2001-12-03 14:46:22 +00:00
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
|
|
|
if (found)
|
2002-03-11 11:26:22 +00:00
|
|
|
setUpdateStatus(bv, ustat);
|
2001-12-03 14:46:22 +00:00
|
|
|
return found;
|
|
|
|
}
|
|
|
|
bool found = lt->updateInset(bv, inset);
|
|
|
|
if (clear)
|
2001-12-03 13:17:04 +00:00
|
|
|
lt = 0;
|
2001-12-03 14:46:22 +00:00
|
|
|
if (found) {
|
|
|
|
setUpdateStatus(bv, CURSOR_PAR);
|
2002-03-08 11:42:30 +00:00
|
|
|
if (the_locking_inset &&
|
|
|
|
cpar(bv) == inset_par && cpos(bv) == inset_pos)
|
|
|
|
{
|
2002-04-12 15:59:03 +00:00
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2002-04-11 15:08:22 +00:00
|
|
|
inset_y = ciy(bv) + drawTextYOffset;
|
2001-12-03 14:46:22 +00:00
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-12-03 14:46:22 +00:00
|
|
|
return found;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-26 17:33:14 +00:00
|
|
|
void InsetText::insetButtonPress(BufferView * bv,
|
|
|
|
int x, int y, mouse_button::state button)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2002-03-29 15:49:45 +00:00
|
|
|
no_selection = true;
|
2000-07-04 11:30:07 +00:00
|
|
|
|
2001-12-24 14:36:31 +00:00
|
|
|
// use this to check mouse motion for selection!
|
|
|
|
mouse_x = x;
|
|
|
|
mouse_y = y;
|
|
|
|
|
2002-04-16 14:10:39 +00:00
|
|
|
if (!locked)
|
|
|
|
lockInset(bv);
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
int tmp_x = x - drawTextXOffset;
|
2002-03-03 20:25:07 +00:00
|
|
|
int tmp_y = y + insetAscent - getLyXText(bv)->first_y;
|
2001-12-17 14:25:04 +00:00
|
|
|
Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y);
|
2000-07-04 11:30:07 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
hideInsetCursor(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
if (the_locking_inset) {
|
|
|
|
if (the_locking_inset == inset) {
|
2001-12-18 03:21:10 +00:00
|
|
|
the_locking_inset->insetButtonPress(bv,
|
2002-03-21 17:09:55 +00:00
|
|
|
x - inset_x,
|
|
|
|
y - inset_y,
|
|
|
|
button);
|
2001-04-02 14:02:58 +00:00
|
|
|
return;
|
2002-04-03 13:59:04 +00:00
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
else if (inset) {
|
2001-04-02 14:02:58 +00:00
|
|
|
// otherwise unlock the_locking_inset and lock the new inset
|
2001-06-28 10:25:20 +00:00
|
|
|
the_locking_inset->insetUnlock(bv);
|
2002-04-12 15:59:03 +00:00
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2002-04-11 15:08:22 +00:00
|
|
|
inset_y = ciy(bv) + drawTextYOffset;
|
2002-01-11 16:00:28 +00:00
|
|
|
the_locking_inset = 0;
|
2001-12-18 03:21:10 +00:00
|
|
|
inset->insetButtonPress(bv, x - inset_x,
|
2002-03-21 17:09:55 +00:00
|
|
|
y - inset_y, button);
|
2002-03-05 11:51:07 +00:00
|
|
|
// inset->edit(bv, x - inset_x, y - inset_y, button);
|
2001-04-02 14:02:58 +00:00
|
|
|
if (the_locking_inset)
|
2001-06-28 10:25:20 +00:00
|
|
|
updateLocal(bv, CURSOR, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-04-03 13:59:04 +00:00
|
|
|
#endif
|
2001-04-02 14:02:58 +00:00
|
|
|
// otherwise only unlock the_locking_inset
|
2001-06-28 10:25:20 +00:00
|
|
|
the_locking_inset->insetUnlock(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
the_locking_inset = 0;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2002-03-29 15:49:45 +00:00
|
|
|
if (!inset)
|
|
|
|
no_selection = false;
|
2002-03-29 12:24:50 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
if (bv->theLockingInset()) {
|
2001-11-09 13:44:48 +00:00
|
|
|
if (isHighlyEditableInset(inset)) {
|
2002-04-03 13:59:04 +00:00
|
|
|
// We just have to lock the inset before calling a
|
|
|
|
// PressEvent on it!
|
2001-04-02 14:02:58 +00:00
|
|
|
UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
|
2002-04-03 13:59:04 +00:00
|
|
|
if (!bv->lockInset(uinset)) {
|
|
|
|
lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
|
|
|
|
}
|
|
|
|
inset->insetButtonPress(bv, x - inset_x, y - inset_y, button);
|
2001-04-02 14:02:58 +00:00
|
|
|
if (the_locking_inset)
|
2001-06-28 10:25:20 +00:00
|
|
|
updateLocal(bv, CURSOR, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-09-19 13:50:47 +00:00
|
|
|
}
|
2002-05-26 17:33:14 +00:00
|
|
|
if (!inset) { // && (button == mouse_button::button2)) {
|
2001-04-02 14:02:58 +00:00
|
|
|
bool paste_internally = false;
|
2002-05-26 17:33:14 +00:00
|
|
|
if ((button == mouse_button::button2) && getLyXText(bv)->selection.set()) {
|
2001-06-28 10:25:20 +00:00
|
|
|
localDispatch(bv, LFUN_COPY, "");
|
2001-04-02 14:02:58 +00:00
|
|
|
paste_internally = true;
|
|
|
|
}
|
2001-08-06 14:55:02 +00:00
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
2002-03-29 12:24:50 +00:00
|
|
|
int old_first_y = lt->first_y;
|
2001-12-18 03:21:10 +00:00
|
|
|
|
|
|
|
lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
|
2002-03-21 17:09:55 +00:00
|
|
|
y + insetAscent);
|
2001-12-17 14:53:31 +00:00
|
|
|
// set the selection cursor!
|
|
|
|
lt->selection.cursor = lt->cursor;
|
|
|
|
lt->cursor.x_fix(lt->cursor.x());
|
2001-12-18 03:21:10 +00:00
|
|
|
|
2001-08-06 14:55:02 +00:00
|
|
|
if (lt->selection.set()) {
|
|
|
|
lt->clearSelection();
|
2001-12-18 12:35:53 +00:00
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
2001-08-06 14:55:02 +00:00
|
|
|
updateLocal(bv, FULL, false);
|
|
|
|
} else {
|
|
|
|
lt->clearSelection();
|
2001-12-18 12:35:53 +00:00
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
2002-01-08 15:32:11 +00:00
|
|
|
updateLocal(bv, CURSOR, false);
|
2001-08-06 14:55:02 +00:00
|
|
|
}
|
2002-03-02 16:39:54 +00:00
|
|
|
bv->owner()->setLayout(cpar(bv)->layout());
|
2002-03-29 12:24:50 +00:00
|
|
|
// we moved the view we cannot do mouse selection in this case!
|
|
|
|
if (getLyXText(bv)->first_y != old_first_y)
|
|
|
|
no_selection = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
old_par = cpar(bv);
|
|
|
|
// Insert primary selection with middle mouse
|
|
|
|
// if there is a local selection in the current buffer,
|
|
|
|
// insert this
|
2002-05-26 17:33:14 +00:00
|
|
|
if (button == mouse_button::button2) {
|
2001-04-02 14:02:58 +00:00
|
|
|
if (paste_internally)
|
2001-06-28 10:25:20 +00:00
|
|
|
localDispatch(bv, LFUN_PASTE, "");
|
2001-04-02 14:02:58 +00:00
|
|
|
else
|
2001-06-28 10:25:20 +00:00
|
|
|
localDispatch(bv, LFUN_PASTESELECTION,
|
2002-03-21 17:09:55 +00:00
|
|
|
"paragraph");
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-12-17 14:53:31 +00:00
|
|
|
} else {
|
2001-12-18 09:13:34 +00:00
|
|
|
getLyXText(bv)->clearSelection();
|
2000-09-19 13:50:47 +00:00
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
showInsetCursor(bv);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-26 17:33:14 +00:00
|
|
|
bool InsetText::insetButtonRelease(BufferView * bv,
|
|
|
|
int x, int y, mouse_button::state button)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2002-03-29 12:24:50 +00:00
|
|
|
no_selection = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
if (the_locking_inset) {
|
2001-12-17 13:33:22 +00:00
|
|
|
return the_locking_inset->insetButtonRelease(bv,
|
2002-03-21 17:09:55 +00:00
|
|
|
x - inset_x, y - inset_y,
|
|
|
|
button);
|
2001-12-17 13:33:22 +00:00
|
|
|
}
|
|
|
|
int tmp_x = x - drawTextXOffset;
|
2002-03-03 20:25:07 +00:00
|
|
|
int tmp_y = y + insetAscent - getLyXText(bv)->first_y;
|
2001-12-17 15:08:51 +00:00
|
|
|
Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y);
|
2001-12-17 13:33:22 +00:00
|
|
|
bool ret = false;
|
|
|
|
if (inset) {
|
|
|
|
if (isHighlyEditableInset(inset)) {
|
|
|
|
ret = inset->insetButtonRelease(bv, x - inset_x,
|
2002-03-21 17:09:55 +00:00
|
|
|
y - inset_y, button);
|
2001-12-17 13:33:22 +00:00
|
|
|
} else {
|
2002-04-12 15:59:03 +00:00
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2002-04-11 15:08:22 +00:00
|
|
|
inset_y = ciy(bv) + drawTextYOffset;
|
2001-12-17 13:33:22 +00:00
|
|
|
ret = inset->insetButtonRelease(bv, x - inset_x,
|
2002-03-21 17:09:55 +00:00
|
|
|
y - inset_y, button);
|
2001-12-17 13:33:22 +00:00
|
|
|
inset->edit(bv, x - inset_x,
|
2002-03-21 17:09:55 +00:00
|
|
|
y - inset_y, button);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-12-17 13:33:22 +00:00
|
|
|
updateLocal(bv, CURSOR_PAR, false);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2001-12-17 13:33:22 +00:00
|
|
|
return ret;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-26 17:33:14 +00:00
|
|
|
void InsetText::insetMotionNotify(BufferView * bv, int x, int y, mouse_button::state state)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (the_locking_inset) {
|
2001-06-28 10:25:20 +00:00
|
|
|
the_locking_inset->insetMotionNotify(bv, x - inset_x,
|
2002-03-21 17:09:55 +00:00
|
|
|
y - inset_y,state);
|
2001-04-02 14:02:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-03-29 15:49:45 +00:00
|
|
|
|
|
|
|
if (no_selection || ((mouse_x == x) && (mouse_y == y)))
|
|
|
|
return;
|
|
|
|
|
2001-12-04 16:10:19 +00:00
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
hideInsetCursor(bv);
|
2001-12-17 14:53:31 +00:00
|
|
|
LyXCursor cur = lt->cursor;
|
2001-12-04 16:10:19 +00:00
|
|
|
lt->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent);
|
2002-04-16 14:10:39 +00:00
|
|
|
lt->cursor.x_fix(lt->cursor.x());
|
2001-12-18 12:35:53 +00:00
|
|
|
if (cur == lt->cursor) {
|
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
2001-12-17 14:53:31 +00:00
|
|
|
return;
|
2001-12-18 12:35:53 +00:00
|
|
|
}
|
2001-12-04 16:10:19 +00:00
|
|
|
lt->setSelection(bv);
|
2001-12-18 12:35:53 +00:00
|
|
|
bool flag = (lt->toggle_cursor.par() != lt->toggle_end_cursor.par() ||
|
|
|
|
lt->toggle_cursor.pos() != lt->toggle_end_cursor.pos());
|
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
|
|
|
if (flag) {
|
2001-06-28 10:25:20 +00:00
|
|
|
updateLocal(bv, SELECTION, false);
|
2001-12-04 16:10:19 +00:00
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
showInsetCursor(bv);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
UpdatableInset::RESULT
|
2001-06-28 10:25:20 +00:00
|
|
|
InsetText::localDispatch(BufferView * bv,
|
2002-03-21 17:09:55 +00:00
|
|
|
kb_action action, string const & arg)
|
2001-04-02 14:02:58 +00:00
|
|
|
{
|
2001-08-11 18:31:14 +00:00
|
|
|
bool was_empty = par->size() == 0 && !par->next();
|
2001-04-02 14:02:58 +00:00
|
|
|
no_selection = false;
|
|
|
|
UpdatableInset::RESULT
|
2001-06-28 10:25:20 +00:00
|
|
|
result= UpdatableInset::localDispatch(bv, action, arg);
|
2001-04-02 14:02:58 +00:00
|
|
|
if (result != UNDISPATCHED) {
|
2001-01-08 16:14:09 +00:00
|
|
|
return DISPATCHED;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
2001-04-06 12:47:50 +00:00
|
|
|
result = DISPATCHED;
|
2001-04-02 14:02:58 +00:00
|
|
|
if ((action < 0) && arg.empty())
|
|
|
|
return FINISHED;
|
|
|
|
|
|
|
|
if (the_locking_inset) {
|
2001-06-28 10:25:20 +00:00
|
|
|
result = the_locking_inset->localDispatch(bv, action, arg);
|
2001-04-02 14:02:58 +00:00
|
|
|
if (result == DISPATCHED_NOUPDATE)
|
|
|
|
return result;
|
|
|
|
else if (result == DISPATCHED) {
|
2001-06-28 10:25:20 +00:00
|
|
|
updateLocal(bv, CURSOR_PAR, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
return result;
|
2001-10-01 11:55:08 +00:00
|
|
|
} else if (result >= FINISHED) {
|
2002-02-16 15:59:55 +00:00
|
|
|
switch (result) {
|
2001-10-01 11:55:08 +00:00
|
|
|
case FINISHED_RIGHT:
|
2001-04-02 14:02:58 +00:00
|
|
|
moveRightIntern(bv, false, false);
|
2001-10-01 11:55:08 +00:00
|
|
|
result = DISPATCHED;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
2001-10-01 11:55:08 +00:00
|
|
|
case FINISHED_UP:
|
|
|
|
if ((result = moveUp(bv)) >= FINISHED) {
|
|
|
|
updateLocal(bv, CURSOR, false);
|
|
|
|
bv->unlockInset(this);
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
2001-10-01 11:55:08 +00:00
|
|
|
case FINISHED_DOWN:
|
|
|
|
if ((result = moveDown(bv)) >= FINISHED) {
|
|
|
|
updateLocal(bv, CURSOR, false);
|
|
|
|
bv->unlockInset(this);
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
2001-10-01 11:55:08 +00:00
|
|
|
result = DISPATCHED;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
the_locking_inset = 0;
|
2001-10-01 11:55:08 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning I changed this to always return Dispatched maybe it is wrong (20011001 Jug)
|
|
|
|
#endif
|
2002-03-29 15:49:45 +00:00
|
|
|
updateLocal(bv, CURSOR, false);
|
2001-10-01 11:55:08 +00:00
|
|
|
return result;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
hideInsetCursor(bv);
|
2001-07-12 12:26:06 +00:00
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
2001-12-18 12:35:53 +00:00
|
|
|
int updwhat = 0;
|
|
|
|
int updflag = false;
|
2001-04-02 14:02:58 +00:00
|
|
|
switch (action) {
|
2000-03-09 16:04:28 +00:00
|
|
|
// Normal chars
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_SELFINSERT:
|
2001-04-02 14:02:58 +00:00
|
|
|
if (bv->buffer()->isReadonly()) {
|
2000-06-16 15:13:25 +00:00
|
|
|
// setErrorMessage(N_("Document is read only"));
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!arg.empty()) {
|
|
|
|
/* Automatically delete the currently selected
|
|
|
|
* text and replace it with what is being
|
|
|
|
* typed in now. Depends on lyxrc settings
|
|
|
|
* "auto_region_delete", which defaults to
|
|
|
|
* true (on). */
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
setUndo(bv, Undo::INSERT,
|
2002-03-21 17:09:55 +00:00
|
|
|
lt->cursor.par(), lt->cursor.par()->next());
|
2001-04-02 14:02:58 +00:00
|
|
|
bv->setState();
|
|
|
|
if (lyxrc.auto_region_delete) {
|
2001-07-12 12:26:06 +00:00
|
|
|
if (lt->selection.set()) {
|
|
|
|
lt->cutSelection(bv, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
|
|
|
}
|
2001-08-01 15:42:53 +00:00
|
|
|
lt->clearSelection();
|
2001-04-02 14:02:58 +00:00
|
|
|
for (string::size_type i = 0; i < arg.length(); ++i) {
|
2001-08-02 18:46:53 +00:00
|
|
|
bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-01-02 16:06:14 +00:00
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->selection.cursor = lt->cursor;
|
2002-04-05 12:31:42 +00:00
|
|
|
updwhat = CURSOR | CURSOR_PAR;
|
2001-12-18 12:35:53 +00:00
|
|
|
updflag = true;
|
2001-06-29 15:17:05 +00:00
|
|
|
result = DISPATCHED_NOUPDATE;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
2001-04-06 12:47:50 +00:00
|
|
|
// --- Cursor Movements -----------------------------------
|
2001-04-02 14:02:58 +00:00
|
|
|
case LFUN_RIGHTSEL:
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2001-04-02 14:02:58 +00:00
|
|
|
moveRight(bv, false, true);
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->setSelection(bv);
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = SELECTION;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
case LFUN_RIGHT:
|
|
|
|
result = moveRight(bv);
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
case LFUN_LEFTSEL:
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2001-04-02 14:02:58 +00:00
|
|
|
moveLeft(bv, false, true);
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->setSelection(bv);
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = SELECTION;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
case LFUN_LEFT:
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2001-04-02 14:02:58 +00:00
|
|
|
result = moveLeft(bv);
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
case LFUN_DOWNSEL:
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2001-04-02 14:02:58 +00:00
|
|
|
moveDown(bv);
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->setSelection(bv);
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = SELECTION;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
case LFUN_DOWN:
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2001-04-02 14:02:58 +00:00
|
|
|
result = moveDown(bv);
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
case LFUN_UPSEL:
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2001-04-02 14:02:58 +00:00
|
|
|
moveUp(bv);
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->setSelection(bv);
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = SELECTION;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
case LFUN_UP:
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2001-04-02 14:02:58 +00:00
|
|
|
result = moveUp(bv);
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
case LFUN_HOME:
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->cursorHome(bv);
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
case LFUN_END:
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->cursorEnd(bv);
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
2001-06-29 15:17:05 +00:00
|
|
|
case LFUN_BACKSPACE: {
|
2001-07-06 15:57:54 +00:00
|
|
|
setUndo(bv, Undo::DELETE,
|
2002-03-21 17:09:55 +00:00
|
|
|
lt->cursor.par(), lt->cursor.par()->next());
|
2001-07-12 12:26:06 +00:00
|
|
|
if (lt->selection.set())
|
|
|
|
lt->cutSelection(bv);
|
2001-07-06 15:57:54 +00:00
|
|
|
else
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->backspace(bv);
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
updflag = true;
|
2001-06-29 15:17:05 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
case LFUN_DELETE: {
|
|
|
|
setUndo(bv, Undo::DELETE,
|
2002-03-21 17:09:55 +00:00
|
|
|
lt->cursor.par(), lt->cursor.par()->next());
|
2001-07-12 12:26:06 +00:00
|
|
|
if (lt->selection.set()) {
|
|
|
|
lt->cutSelection(bv);
|
2001-06-29 15:17:05 +00:00
|
|
|
} else {
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->Delete(bv);
|
2001-06-29 15:17:05 +00:00
|
|
|
}
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
updflag = true;
|
2001-06-29 15:17:05 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
case LFUN_CUT: {
|
|
|
|
setUndo(bv, Undo::DELETE,
|
2002-03-21 17:09:55 +00:00
|
|
|
lt->cursor.par(), lt->cursor.par()->next());
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->cutSelection(bv);
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
updflag = true;
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
case LFUN_COPY:
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->copySelection(bv);
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR_PAR;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
case LFUN_PASTESELECTION:
|
|
|
|
{
|
2001-05-08 17:08:44 +00:00
|
|
|
string const clip(bv->getClipboard());
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
if (clip.empty())
|
|
|
|
break;
|
|
|
|
if (arg == "paragraph") {
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->insertStringAsParagraphs(bv, clip);
|
2001-04-02 14:02:58 +00:00
|
|
|
} else {
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->insertStringAsLines(bv, clip);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2002-05-15 23:49:08 +00:00
|
|
|
// bug 393
|
|
|
|
lt->clearSelection();
|
|
|
|
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
updflag = true;
|
2000-07-14 14:57:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
case LFUN_PASTE: {
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!autoBreakRows) {
|
|
|
|
|
2001-07-03 15:39:17 +00:00
|
|
|
if (CutAndPaste::nrOfParagraphs() > 1) {
|
2001-11-26 10:19:58 +00:00
|
|
|
Alert::alert(_("Impossible operation"),
|
2001-04-02 14:02:58 +00:00
|
|
|
_("Cannot include more than one paragraph!"),
|
|
|
|
_("Sorry."));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
setUndo(bv, Undo::INSERT,
|
2002-03-21 17:09:55 +00:00
|
|
|
lt->cursor.par(), lt->cursor.par()->next());
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->pasteSelection(bv);
|
2002-05-15 23:49:08 +00:00
|
|
|
// bug 393
|
|
|
|
lt->clearSelection();
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
updflag = true;
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
case LFUN_BREAKPARAGRAPH:
|
2001-07-12 12:26:06 +00:00
|
|
|
if (!autoBreakRows) {
|
|
|
|
result = DISPATCHED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lt->breakParagraph(bv, 0);
|
2002-03-29 15:49:45 +00:00
|
|
|
updwhat = CURSOR | FULL;
|
2001-12-18 12:35:53 +00:00
|
|
|
updflag = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
|
2001-07-12 12:26:06 +00:00
|
|
|
if (!autoBreakRows) {
|
|
|
|
result = DISPATCHED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lt->breakParagraph(bv, 1);
|
2002-03-29 15:49:45 +00:00
|
|
|
updwhat = CURSOR | FULL;
|
2001-12-18 12:35:53 +00:00
|
|
|
updflag = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
2001-07-06 15:57:54 +00:00
|
|
|
|
|
|
|
case LFUN_BREAKLINE: {
|
2001-07-12 12:26:06 +00:00
|
|
|
if (!autoBreakRows) {
|
|
|
|
result = DISPATCHED;
|
|
|
|
break;
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
setUndo(bv, Undo::INSERT,
|
2002-03-21 17:09:55 +00:00
|
|
|
lt->cursor.par(), lt->cursor.par()->next());
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->insertChar(bv, Paragraph::META_NEWLINE);
|
2002-03-29 15:49:45 +00:00
|
|
|
updwhat = CURSOR | CURSOR_PAR;
|
2001-12-18 12:35:53 +00:00
|
|
|
updflag = true;
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
case LFUN_LAYOUT:
|
|
|
|
// do not set layouts on non breakable textinsets
|
|
|
|
if (autoBreakRows) {
|
2002-03-02 16:39:54 +00:00
|
|
|
string cur_layout = cpar(bv)->layout();
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
// Derive layout number from given argument (string)
|
2002-03-21 17:09:55 +00:00
|
|
|
// and current buffer's textclass (number). */
|
2001-11-29 17:12:21 +00:00
|
|
|
textclass_type tclass = bv->buffer()->params.textclass;
|
2002-03-03 20:25:07 +00:00
|
|
|
string layout = arg;
|
2002-03-02 16:39:54 +00:00
|
|
|
bool hasLayout = textclasslist[tclass].hasLayout(layout);
|
2001-04-02 14:02:58 +00:00
|
|
|
|
|
|
|
// If the entry is obsolete, use the new one instead.
|
2002-03-02 16:39:54 +00:00
|
|
|
if (hasLayout) {
|
|
|
|
string const & obs =
|
|
|
|
textclasslist[tclass][layout].
|
2001-04-02 14:02:58 +00:00
|
|
|
obsoleted_by();
|
2002-03-21 17:09:55 +00:00
|
|
|
if (!obs.empty())
|
2002-03-03 20:25:07 +00:00
|
|
|
layout = obs;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// see if we found the layout number:
|
2002-03-02 16:39:54 +00:00
|
|
|
if (!hasLayout) {
|
2001-04-17 14:17:11 +00:00
|
|
|
string const msg = string(N_("Layout ")) + arg + N_(" not known");
|
2001-07-16 15:42:57 +00:00
|
|
|
bv->owner()->getLyXFunc()->dispatch(LFUN_MESSAGE, msg);
|
2001-04-02 14:02:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
if (cur_layout != layout) {
|
|
|
|
cur_layout = layout;
|
|
|
|
lt->setLayout(bv, layout);
|
|
|
|
bv->owner()->setLayout(cpar(bv)->layout());
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
updflag = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// reset the layout box
|
2002-03-02 16:39:54 +00:00
|
|
|
bv->owner()->setLayout(cpar(bv)->layout());
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LFUN_PARAGRAPH_SPACING:
|
|
|
|
// This one is absolutely not working. When fiddling with this
|
|
|
|
// it also seems to me that the paragraphs inside the insettext
|
|
|
|
// inherit bufferparams/paragraphparams in a strange way. (Lgb)
|
|
|
|
{
|
2001-07-12 12:26:06 +00:00
|
|
|
Paragraph * par = lt->cursor.par();
|
2001-06-25 00:06:33 +00:00
|
|
|
Spacing::Space cur_spacing = par->params().spacing().getSpace();
|
2001-04-02 14:02:58 +00:00
|
|
|
float cur_value = 1.0;
|
|
|
|
if (cur_spacing == Spacing::Other) {
|
2001-06-25 00:06:33 +00:00
|
|
|
cur_value = par->params().spacing().getValue();
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-07-13 14:03:48 +00:00
|
|
|
istringstream istr(arg.c_str());
|
2001-04-02 14:02:58 +00:00
|
|
|
string tmp;
|
|
|
|
istr >> tmp;
|
|
|
|
Spacing::Space new_spacing = cur_spacing;
|
|
|
|
float new_value = cur_value;
|
|
|
|
if (tmp.empty()) {
|
|
|
|
lyxerr << "Missing argument to `paragraph-spacing'"
|
|
|
|
<< endl;
|
|
|
|
} else if (tmp == "single") {
|
|
|
|
new_spacing = Spacing::Single;
|
|
|
|
} else if (tmp == "onehalf") {
|
|
|
|
new_spacing = Spacing::Onehalf;
|
|
|
|
} else if (tmp == "double") {
|
|
|
|
new_spacing = Spacing::Double;
|
|
|
|
} else if (tmp == "other") {
|
|
|
|
new_spacing = Spacing::Other;
|
|
|
|
float tmpval = 0.0;
|
|
|
|
istr >> tmpval;
|
|
|
|
lyxerr << "new_value = " << tmpval << endl;
|
|
|
|
if (tmpval != 0.0)
|
|
|
|
new_value = tmpval;
|
|
|
|
} else if (tmp == "default") {
|
|
|
|
new_spacing = Spacing::Default;
|
|
|
|
} else {
|
|
|
|
lyxerr << _("Unknown spacing argument: ")
|
|
|
|
<< arg << endl;
|
|
|
|
}
|
|
|
|
if (cur_spacing != new_spacing || cur_value != new_value) {
|
2001-06-25 00:06:33 +00:00
|
|
|
par->params().spacing(Spacing(new_spacing, new_value));
|
2001-12-18 12:35:53 +00:00
|
|
|
updwhat = CURSOR_PAR;
|
|
|
|
updflag = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
}
|
2000-09-25 11:10:15 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
default:
|
|
|
|
if (!bv->Dispatch(action, arg))
|
|
|
|
result = UNDISPATCHED;
|
|
|
|
break;
|
|
|
|
}
|
2001-02-11 09:58:20 +00:00
|
|
|
|
2001-12-18 12:35:53 +00:00
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
|
|
|
if (updwhat > 0)
|
|
|
|
updateLocal(bv, updwhat, updflag);
|
2001-04-02 14:02:58 +00:00
|
|
|
/// If the action has deleted all text in the inset, we need to change the
|
2001-07-12 12:26:06 +00:00
|
|
|
// language to the language of the surronding text.
|
2001-08-11 18:31:14 +00:00
|
|
|
if (!was_empty && par->size() == 0 && !par->next()) {
|
2001-04-02 14:02:58 +00:00
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
font.setLanguage(bv->getParentLanguage(this));
|
2001-06-28 10:25:20 +00:00
|
|
|
setFont(bv, font, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-02-11 09:58:20 +00:00
|
|
|
|
2002-03-18 14:53:21 +00:00
|
|
|
if (result >= FINISHED)
|
2001-04-02 14:02:58 +00:00
|
|
|
bv->unlockInset(this);
|
2002-03-29 15:49:45 +00:00
|
|
|
|
|
|
|
if (result == DISPATCHED_NOUPDATE && (need_update & FULL))
|
|
|
|
result = DISPATCHED;
|
2001-04-02 14:02:58 +00:00
|
|
|
return result;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-14 14:22:11 +00:00
|
|
|
int InsetText::latex(Buffer const * buf, ostream & os, bool moving_arg, bool) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
TexRow texrow;
|
2002-05-14 14:22:11 +00:00
|
|
|
buf->latexParagraphs(os, par, 0, texrow, moving_arg);
|
2001-04-02 14:02:58 +00:00
|
|
|
return texrow.rows();
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
|
2000-09-26 15:25:14 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * p = par;
|
2001-04-02 14:02:58 +00:00
|
|
|
unsigned int lines = 0;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
while (p) {
|
2001-12-27 15:54:25 +00:00
|
|
|
string const tmp = buf->asciiParagraph(p, linelen, p->previous()==0);
|
2002-01-14 13:04:06 +00:00
|
|
|
lines += lyx::count(tmp.begin(), tmp.end(), '\n');
|
2001-04-02 14:02:58 +00:00
|
|
|
os << tmp;
|
|
|
|
p = p->next();
|
|
|
|
}
|
|
|
|
return lines;
|
2000-09-26 15:25:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-04 11:02:09 +00:00
|
|
|
int InsetText::docbook(Buffer const * buf, ostream & os) const
|
2000-10-27 10:04:51 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * p = par;
|
2001-04-02 14:02:58 +00:00
|
|
|
unsigned int lines = 0;
|
2001-11-07 13:22:43 +00:00
|
|
|
|
|
|
|
vector<string> environment_stack(10);
|
|
|
|
vector<string> environment_inner(10);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-11-07 13:22:43 +00:00
|
|
|
int const command_depth = 0;
|
|
|
|
string item_name;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-11-07 13:22:43 +00:00
|
|
|
Paragraph::depth_type depth = 0; // paragraph depth
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
while (p) {
|
2001-11-07 13:22:43 +00:00
|
|
|
string sgmlparam;
|
|
|
|
int desc_on = 0; // description mode
|
|
|
|
|
|
|
|
LyXLayout const & style =
|
2002-03-02 16:39:54 +00:00
|
|
|
textclasslist[buf->params.textclass][p->layout()];
|
2001-11-07 13:22:43 +00:00
|
|
|
|
|
|
|
// environment tag closing
|
|
|
|
for (; depth > p->params().depth(); --depth) {
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
|
|
|
item_name = "listitem";
|
|
|
|
buf->sgmlCloseTag(os, command_depth + depth,
|
|
|
|
item_name);
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
|
|
|
buf->sgmlCloseTag(os, depth+command_depth,
|
|
|
|
environment_inner[depth]);
|
|
|
|
}
|
|
|
|
buf->sgmlCloseTag(os, depth + command_depth,
|
|
|
|
environment_stack[depth]);
|
|
|
|
environment_stack[depth].erase();
|
|
|
|
environment_inner[depth].erase();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (depth == p->params().depth()
|
|
|
|
&& environment_stack[depth] != style.latexname()
|
|
|
|
&& !environment_stack[depth].empty()) {
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
|
|
|
item_name= "listitem";
|
|
|
|
buf->sgmlCloseTag(os, command_depth+depth,
|
|
|
|
item_name);
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
|
|
|
buf->sgmlCloseTag(os,
|
|
|
|
depth + command_depth,
|
|
|
|
environment_inner[depth]);
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-11-07 13:22:43 +00:00
|
|
|
buf->sgmlCloseTag(os, depth + command_depth,
|
|
|
|
environment_stack[depth]);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-11-07 13:22:43 +00:00
|
|
|
environment_stack[depth].erase();
|
|
|
|
environment_inner[depth].erase();
|
2002-03-21 17:09:55 +00:00
|
|
|
}
|
2001-11-07 13:22:43 +00:00
|
|
|
|
|
|
|
// Write opening SGML tags.
|
|
|
|
switch (style.latextype) {
|
|
|
|
case LATEX_PARAGRAPH:
|
|
|
|
buf->sgmlOpenTag(os, depth + command_depth,
|
|
|
|
style.latexname());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LATEX_COMMAND:
|
|
|
|
buf->sgmlError(p, 0,
|
|
|
|
_("Error : LatexType Command not allowed here.\n"));
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
|
|
|
if (depth < p->params().depth()) {
|
|
|
|
depth = p->params().depth();
|
|
|
|
environment_stack[depth].erase();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (environment_stack[depth] != style.latexname()) {
|
2002-02-16 15:59:55 +00:00
|
|
|
if (environment_stack.size() == depth + 1) {
|
2001-11-07 13:22:43 +00:00
|
|
|
environment_stack.push_back("!-- --");
|
|
|
|
environment_inner.push_back("!-- --");
|
|
|
|
}
|
|
|
|
environment_stack[depth] = style.latexname();
|
|
|
|
environment_inner[depth] = "!-- --";
|
|
|
|
buf->sgmlOpenTag(os, depth + command_depth,
|
|
|
|
environment_stack[depth]);
|
|
|
|
} else {
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
|
|
|
item_name= "listitem";
|
|
|
|
buf->sgmlCloseTag(os,
|
|
|
|
command_depth + depth,
|
|
|
|
item_name);
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
|
|
|
buf->sgmlCloseTag(os,
|
|
|
|
depth + command_depth,
|
|
|
|
environment_inner[depth]);
|
|
|
|
}
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-11-07 13:22:43 +00:00
|
|
|
if (style.latextype == LATEX_ENVIRONMENT) {
|
|
|
|
if (!style.latexparam().empty()) {
|
2002-02-16 15:59:55 +00:00
|
|
|
if (style.latexparam() == "CDATA")
|
2001-11-07 13:22:43 +00:00
|
|
|
os << "<![CDATA[";
|
|
|
|
else
|
|
|
|
buf->sgmlOpenTag(os, depth + command_depth,
|
|
|
|
style.latexparam());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
desc_on = (style.labeltype == LABEL_MANUAL);
|
|
|
|
|
|
|
|
if (desc_on)
|
|
|
|
environment_inner[depth]= "varlistentry";
|
|
|
|
else
|
|
|
|
environment_inner[depth]= "listitem";
|
|
|
|
|
|
|
|
buf->sgmlOpenTag(os, depth + 1 + command_depth,
|
|
|
|
environment_inner[depth]);
|
|
|
|
|
|
|
|
if (desc_on) {
|
|
|
|
item_name= "term";
|
|
|
|
buf->sgmlOpenTag(os, depth + 1 + command_depth,
|
|
|
|
item_name);
|
|
|
|
} else {
|
|
|
|
item_name= "para";
|
|
|
|
buf->sgmlOpenTag(os, depth + 1 + command_depth,
|
|
|
|
item_name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
buf->sgmlOpenTag(os, depth + command_depth,
|
|
|
|
style.latexname());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-11-14 09:46:05 +00:00
|
|
|
buf->simpleDocBookOnePar(os, p, desc_on,
|
2001-11-07 13:22:43 +00:00
|
|
|
depth + 1 + command_depth);
|
2001-04-02 14:02:58 +00:00
|
|
|
p = p->next();
|
2001-11-07 13:22:43 +00:00
|
|
|
|
|
|
|
string end_tag;
|
|
|
|
// write closing SGML tags
|
|
|
|
switch (style.latextype) {
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
if (!style.latexparam().empty()) {
|
2002-02-16 15:59:55 +00:00
|
|
|
if (style.latexparam() == "CDATA")
|
2001-11-07 13:22:43 +00:00
|
|
|
os << "]]>";
|
|
|
|
else
|
|
|
|
buf->sgmlCloseTag(os, depth + command_depth,
|
|
|
|
style.latexparam());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
|
|
|
if (desc_on == 1) break;
|
|
|
|
end_tag= "para";
|
|
|
|
buf->sgmlCloseTag(os, depth + 1 + command_depth, end_tag);
|
|
|
|
break;
|
|
|
|
case LATEX_PARAGRAPH:
|
|
|
|
buf->sgmlCloseTag(os, depth + command_depth, style.latexname());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
buf->sgmlCloseTag(os, depth + command_depth, style.latexname());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close open tags
|
|
|
|
for (int d = depth; d >= 0; --d) {
|
|
|
|
if (!environment_stack[depth].empty()) {
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
|
|
|
item_name = "listitem";
|
|
|
|
buf->sgmlCloseTag(os, command_depth + depth,
|
|
|
|
item_name);
|
2002-03-21 17:09:55 +00:00
|
|
|
if (environment_inner[depth] == "varlistentry")
|
2001-11-07 13:22:43 +00:00
|
|
|
buf->sgmlCloseTag(os, depth + command_depth,
|
|
|
|
environment_inner[depth]);
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-11-07 13:22:43 +00:00
|
|
|
buf->sgmlCloseTag(os, depth + command_depth,
|
|
|
|
environment_stack[depth]);
|
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
return lines;
|
2000-10-27 10:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::validate(LaTeXFeatures & features) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * p = par;
|
2001-05-08 17:08:44 +00:00
|
|
|
while (p) {
|
2001-04-02 14:02:58 +00:00
|
|
|
p->validate(features);
|
|
|
|
p = p->next();
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2002-03-02 16:39:54 +00:00
|
|
|
if (textclasslist[buf->params.textclass][p->layout()].labeltype != LABEL_MANUAL)
|
2001-04-02 14:02:58 +00:00
|
|
|
return 0;
|
|
|
|
else
|
2001-06-25 00:06:33 +00:00
|
|
|
return p->beginningOfMainBody();
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-16 14:10:39 +00:00
|
|
|
void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-07-17 15:39:12 +00:00
|
|
|
if (the_locking_inset) {
|
|
|
|
the_locking_inset->getCursorPos(bv, x, y);
|
|
|
|
return;
|
|
|
|
}
|
2002-04-16 14:10:39 +00:00
|
|
|
x = cx(bv) - top_x - TEXT_TO_INSET_OFFSET;
|
|
|
|
y = cy(bv) - TEXT_TO_INSET_OFFSET;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-16 14:10:39 +00:00
|
|
|
int InsetText::insetInInsetY() const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!the_locking_inset)
|
|
|
|
return 0;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
return (inset_y + the_locking_inset->insetInInsetY());
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::toggleInsetCursor(BufferView * bv)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (the_locking_inset) {
|
2001-06-28 10:25:20 +00:00
|
|
|
the_locking_inset->toggleInsetCursor(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2001-06-29 15:17:05 +00:00
|
|
|
LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
|
2000-02-25 13:35:38 +00:00
|
|
|
|
2002-05-24 14:34:32 +00:00
|
|
|
int const asc = font_metrics::maxAscent(font);
|
|
|
|
int const desc = font_metrics::maxDescent(font);
|
|
|
|
|
2001-04-04 22:08:13 +00:00
|
|
|
if (isCursorVisible())
|
2001-04-02 14:02:58 +00:00
|
|
|
bv->hideLockedInsetCursor();
|
|
|
|
else
|
|
|
|
bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
|
2001-04-04 22:08:13 +00:00
|
|
|
toggleCursorVisible();
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::showInsetCursor(BufferView * bv, bool show)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (the_locking_inset) {
|
2001-07-20 14:18:48 +00:00
|
|
|
the_locking_inset->showInsetCursor(bv, show);
|
2001-04-02 14:02:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-04 22:08:13 +00:00
|
|
|
if (!isCursorVisible()) {
|
|
|
|
LyXFont const font =
|
2001-06-29 15:17:05 +00:00
|
|
|
getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
|
2002-05-24 14:34:32 +00:00
|
|
|
|
|
|
|
int const asc = font_metrics::maxAscent(font);
|
|
|
|
int const desc = font_metrics::maxDescent(font);
|
2000-06-16 15:13:25 +00:00
|
|
|
|
2002-04-16 14:10:39 +00:00
|
|
|
bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
|
2001-04-02 14:02:58 +00:00
|
|
|
if (show)
|
|
|
|
bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
|
2001-04-04 22:08:13 +00:00
|
|
|
setCursorVisible(true);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::hideInsetCursor(BufferView * bv)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-04 22:08:13 +00:00
|
|
|
if (isCursorVisible()) {
|
2001-04-02 14:02:58 +00:00
|
|
|
bv->hideLockedInsetCursor();
|
2001-04-04 22:08:13 +00:00
|
|
|
setCursorVisible(false);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
|
|
|
if (the_locking_inset)
|
2001-06-28 10:25:20 +00:00
|
|
|
the_locking_inset->hideInsetCursor(bv);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
void InsetText::fitInsetCursor(BufferView * bv) const
|
|
|
|
{
|
|
|
|
if (the_locking_inset) {
|
|
|
|
the_locking_inset->fitInsetCursor(bv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LyXFont const font =
|
|
|
|
getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
|
2002-05-24 14:34:32 +00:00
|
|
|
|
|
|
|
int const asc = font_metrics::maxAscent(font);
|
|
|
|
int const desc = font_metrics::maxDescent(font);
|
2001-07-20 14:18:48 +00:00
|
|
|
|
2002-03-29 15:49:45 +00:00
|
|
|
if (bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc))
|
|
|
|
need_update |= FULL;
|
2001-07-20 14:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
UpdatableInset::RESULT
|
2000-09-27 15:23:24 +00:00
|
|
|
InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
|
2001-01-08 16:14:09 +00:00
|
|
|
{
|
2001-06-29 15:17:05 +00:00
|
|
|
if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
|
2002-04-17 08:34:59 +00:00
|
|
|
return moveLeftIntern(bv, true, activate_inset, selecting);
|
2001-04-02 14:02:58 +00:00
|
|
|
else
|
2002-04-17 08:34:59 +00:00
|
|
|
return moveRightIntern(bv, true, activate_inset, selecting);
|
2001-01-08 16:14:09 +00:00
|
|
|
}
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
2001-01-08 16:14:09 +00:00
|
|
|
UpdatableInset::RESULT
|
|
|
|
InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
|
|
|
|
{
|
2001-06-29 15:17:05 +00:00
|
|
|
if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
|
2002-04-17 08:34:59 +00:00
|
|
|
return moveRightIntern(bv, false, activate_inset, selecting);
|
2001-04-02 14:02:58 +00:00
|
|
|
else
|
2002-04-17 08:34:59 +00:00
|
|
|
return moveLeftIntern(bv, false, activate_inset, selecting);
|
2001-01-08 16:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UpdatableInset::RESULT
|
2002-04-17 08:34:59 +00:00
|
|
|
InsetText::moveRightIntern(BufferView * bv, bool front,
|
2002-03-21 17:09:55 +00:00
|
|
|
bool activate_inset, bool selecting)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
|
2001-08-16 08:52:30 +00:00
|
|
|
return FINISHED_RIGHT;
|
2002-04-17 08:34:59 +00:00
|
|
|
if (activate_inset && checkAndActivateInset(bv, front))
|
2001-04-02 14:02:58 +00:00
|
|
|
return DISPATCHED;
|
2001-06-29 15:17:05 +00:00
|
|
|
getLyXText(bv)->cursorRight(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!selecting)
|
2001-06-29 15:17:05 +00:00
|
|
|
getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
|
2001-04-02 14:02:58 +00:00
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
UpdatableInset::RESULT
|
2002-04-17 08:34:59 +00:00
|
|
|
InsetText::moveLeftIntern(BufferView * bv, bool front,
|
2002-03-21 17:09:55 +00:00
|
|
|
bool activate_inset, bool selecting)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!cpar(bv)->previous() && (cpos(bv) <= 0))
|
|
|
|
return FINISHED;
|
2001-06-29 15:17:05 +00:00
|
|
|
getLyXText(bv)->cursorLeft(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!selecting)
|
2001-06-29 15:17:05 +00:00
|
|
|
getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
|
2002-04-17 08:34:59 +00:00
|
|
|
if (activate_inset && checkAndActivateInset(bv, front))
|
2001-04-02 14:02:58 +00:00
|
|
|
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
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!crow(bv)->previous())
|
2001-08-16 08:52:30 +00:00
|
|
|
return FINISHED_UP;
|
2001-06-29 15:17:05 +00:00
|
|
|
getLyXText(bv)->cursorUp(bv);
|
2001-04-02 14:02:58 +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
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!crow(bv)->next())
|
2001-08-16 08:52:30 +00:00
|
|
|
return FINISHED_DOWN;
|
2001-06-29 15:17:05 +00:00
|
|
|
getLyXText(bv)->cursorDown(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool InsetText::insertInset(BufferView * bv, Inset * inset)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (the_locking_inset) {
|
2001-07-19 08:52:59 +00:00
|
|
|
if (the_locking_inset->insetAllowed(inset))
|
2001-06-28 10:25:20 +00:00
|
|
|
return the_locking_inset->insertInset(bv, inset);
|
2001-04-02 14:02:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-01-04 16:03:53 +00:00
|
|
|
inset->setOwner(this);
|
|
|
|
hideInsetCursor(bv);
|
2002-04-12 08:31:06 +00:00
|
|
|
getLyXText(bv)->insertInset(bv, inset);
|
2001-08-02 14:55:06 +00:00
|
|
|
bv->fitCursor();
|
2001-12-18 12:35:53 +00:00
|
|
|
updateLocal(bv, CURSOR_PAR|CURSOR, true);
|
2001-07-12 12:26:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-19 08:52:59 +00:00
|
|
|
bool InsetText::insetAllowed(Inset::Code code) const
|
2001-07-12 12:26:06 +00:00
|
|
|
{
|
2001-12-05 23:13:02 +00:00
|
|
|
// in_insetAllowed is a really gross hack,
|
|
|
|
// to allow us to call the owner's insetAllowed
|
|
|
|
// without stack overflow, which can happen
|
|
|
|
// when the owner uses InsetCollapsable::insetAllowed()
|
2001-12-05 15:34:41 +00:00
|
|
|
bool ret = true;
|
|
|
|
if (in_insetAllowed)
|
|
|
|
return ret;
|
|
|
|
in_insetAllowed = true;
|
2001-07-12 12:26:06 +00:00
|
|
|
if (the_locking_inset)
|
2001-12-05 15:34:41 +00:00
|
|
|
ret = the_locking_inset->insetAllowed(code);
|
|
|
|
else if (owner())
|
|
|
|
ret = owner()->insetAllowed(code);
|
|
|
|
in_insetAllowed = false;
|
|
|
|
return ret;
|
2001-07-12 14:35:38 +00:00
|
|
|
}
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
|
2001-07-12 12:26:06 +00:00
|
|
|
UpdatableInset * InsetText::getLockingInset() const
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-07-12 12:26:06 +00:00
|
|
|
return the_locking_inset ? the_locking_inset->getLockingInset() :
|
|
|
|
const_cast<InsetText *>(this);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
UpdatableInset * InsetText::getFirstLockingInsetOfType(Inset::Code c)
|
2000-05-15 14:49:36 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
if (c == lyxCode())
|
2001-04-02 14:02:58 +00:00
|
|
|
return this;
|
|
|
|
if (the_locking_inset)
|
2001-06-28 10:25:20 +00:00
|
|
|
return the_locking_inset->getFirstLockingInsetOfType(c);
|
2001-04-02 14:02:58 +00:00
|
|
|
return 0;
|
2000-05-15 14:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool InsetText::showInsetDialog(BufferView * bv) const
|
2001-03-26 14:47:34 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (the_locking_inset)
|
2001-06-28 10:25:20 +00:00
|
|
|
return the_locking_inset->showInsetDialog(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
return false;
|
2001-03-26 14:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
vector<string> const InsetText::getLabelList() const
|
2001-04-04 23:00:42 +00:00
|
|
|
{
|
2002-02-16 15:59:55 +00:00
|
|
|
vector<string> label_list;
|
2001-04-04 23:00:42 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * tpar = par;
|
2001-04-04 23:00:42 +00:00
|
|
|
while (tpar) {
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph::inset_iterator beg = tpar->inset_iterator_begin();
|
|
|
|
Paragraph::inset_iterator end = tpar->inset_iterator_end();
|
2001-04-04 23:00:42 +00:00
|
|
|
for (; beg != end; ++beg) {
|
2002-02-16 15:59:55 +00:00
|
|
|
vector<string> const l = (*beg)->getLabelList();
|
2001-04-04 23:00:42 +00:00
|
|
|
label_list.insert(label_list.end(), l.begin(), l.end());
|
|
|
|
}
|
|
|
|
tpar = tpar->next();
|
|
|
|
}
|
|
|
|
return label_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
|
2002-03-21 17:09:55 +00:00
|
|
|
bool selectall)
|
2000-02-25 12:06:15 +00:00
|
|
|
{
|
2001-06-01 15:10:26 +00:00
|
|
|
if (the_locking_inset) {
|
2001-06-28 10:25:20 +00:00
|
|
|
the_locking_inset->setFont(bv, font, toggleall, selectall);
|
2001-06-01 15:10:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-08-03 13:09:59 +00:00
|
|
|
if ((!par->next() && !par->size()) || !cpar(bv)->size()) {
|
|
|
|
getLyXText(bv)->setFont(bv, font, toggleall);
|
|
|
|
return;
|
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
|
|
|
if (lt->selection.set()) {
|
|
|
|
setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-05-28 15:11:24 +00:00
|
|
|
if (selectall)
|
|
|
|
selectAll(bv);
|
2001-07-12 12:26:06 +00:00
|
|
|
lt->toggleFree(bv, font, toggleall);
|
2001-05-28 15:11:24 +00:00
|
|
|
if (selectall)
|
2001-08-01 15:42:53 +00:00
|
|
|
lt->clearSelection();
|
2001-08-02 14:55:06 +00:00
|
|
|
bv->fitCursor();
|
2001-12-18 12:35:53 +00:00
|
|
|
bool flag = (selectall || lt->selection.set());
|
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
|
|
|
if (flag)
|
2001-06-28 10:25:20 +00:00
|
|
|
updateLocal(bv, FULL, true);
|
2001-05-28 15:11:24 +00:00
|
|
|
else
|
2001-06-28 10:25:20 +00:00
|
|
|
updateLocal(bv, CURSOR_PAR, true);
|
2000-02-25 12:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-17 08:34:59 +00:00
|
|
|
bool InsetText::checkAndActivateInset(BufferView * bv, bool front)
|
2000-03-08 13:52:57 +00:00
|
|
|
{
|
2001-11-23 10:16:02 +00:00
|
|
|
if (cpar(bv)->isInset(cpos(bv))) {
|
2001-04-02 14:02:58 +00:00
|
|
|
Inset * inset =
|
2001-06-25 00:06:33 +00:00
|
|
|
static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
|
2001-11-09 13:44:48 +00:00
|
|
|
if (!isHighlyEditableInset(inset))
|
2001-04-02 14:02:58 +00:00
|
|
|
return false;
|
2002-04-17 08:34:59 +00:00
|
|
|
inset->edit(bv, front);
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!the_locking_inset)
|
|
|
|
return false;
|
2001-06-28 10:25:20 +00:00
|
|
|
updateLocal(bv, CURSOR, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
return true;
|
2000-07-04 11:30:07 +00:00
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
return false;
|
2000-03-27 15:13:47 +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,
|
2002-05-26 17:33:14 +00:00
|
|
|
mouse_button::state button)
|
2001-04-02 14:02:58 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
x -= drawTextXOffset;
|
|
|
|
int dummyx = x;
|
|
|
|
int dummyy = y + insetAscent;
|
2001-12-17 14:25:04 +00:00
|
|
|
Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy);
|
2002-05-14 09:10:14 +00:00
|
|
|
// we only do the edit() call if the inset was hit by the mouse
|
|
|
|
// or if it is a highly editable inset. So we should call this
|
|
|
|
// function from our own edit with button < 0.
|
2002-05-26 17:33:14 +00:00
|
|
|
// FIXME: GUII jbl. I've changed this to ::none for now which is probably
|
|
|
|
// WRONG
|
|
|
|
if (button == mouse_button::none && !isHighlyEditableInset(inset))
|
2002-05-14 09:10:14 +00:00
|
|
|
return false;
|
|
|
|
|
2001-04-02 14:02:58 +00:00
|
|
|
if (inset) {
|
|
|
|
if (x < 0)
|
|
|
|
x = insetWidth;
|
|
|
|
if (y < 0)
|
|
|
|
y = insetDescent;
|
2002-04-12 15:59:03 +00:00
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2002-04-11 15:08:22 +00:00
|
|
|
inset_y = ciy(bv) + drawTextYOffset;
|
2001-06-28 10:25:20 +00:00
|
|
|
inset->edit(bv, x - inset_x, y - inset_y, button);
|
2001-04-02 14:02:58 +00:00
|
|
|
if (!the_locking_inset)
|
|
|
|
return false;
|
2001-06-28 10:25:20 +00:00
|
|
|
updateLocal(bv, CURSOR, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2001-03-29 15:00:20 +00:00
|
|
|
int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2001-08-07 15:07:36 +00:00
|
|
|
#if 0
|
2001-04-02 14:02:58 +00:00
|
|
|
int w = UpdatableInset::getMaxWidth(bv, inset);
|
|
|
|
if (w < 0) {
|
2001-08-07 15:07:36 +00:00
|
|
|
return -1;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
|
|
|
if (owner()) {
|
|
|
|
w = w - top_x + owner()->x();
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
w -= (2 * TEXT_TO_INSET_OFFSET);
|
|
|
|
return w - top_x;
|
2001-08-07 15:07:36 +00:00
|
|
|
#else
|
|
|
|
return UpdatableInset::getMaxWidth(bv, inset);
|
|
|
|
#endif
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2001-11-30 16:10:24 +00:00
|
|
|
void InsetText::setParagraphData(Paragraph * p, bool same_id)
|
2000-05-04 08:14:34 +00:00
|
|
|
{
|
2001-08-07 15:07:36 +00:00
|
|
|
// we have to unlock any locked inset otherwise we're in troubles
|
|
|
|
the_locking_inset = 0;
|
2001-04-06 12:47:50 +00:00
|
|
|
while (par) {
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * tmp = par->next();
|
2001-04-02 14:02:58 +00:00
|
|
|
delete par;
|
2001-04-06 12:47:50 +00:00
|
|
|
par = tmp;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-04-06 12:47:50 +00:00
|
|
|
|
2001-11-30 16:10:24 +00:00
|
|
|
par = new Paragraph(*p, same_id);
|
2001-06-25 00:06:33 +00:00
|
|
|
par->setInsetOwner(this);
|
|
|
|
Paragraph * np = par;
|
2001-04-06 12:47:50 +00:00
|
|
|
while (p->next()) {
|
2001-04-02 14:02:58 +00:00
|
|
|
p = p->next();
|
2001-11-30 16:10:24 +00:00
|
|
|
np->next(new Paragraph(*p, same_id));
|
2001-04-02 14:02:58 +00:00
|
|
|
np->next()->previous(np);
|
|
|
|
np = np->next();
|
2001-06-25 00:06:33 +00:00
|
|
|
np->setInsetOwner(this);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-11-29 12:58:59 +00:00
|
|
|
reinitLyXText();
|
2001-08-10 10:24:44 +00:00
|
|
|
need_update = INIT;
|
2000-05-04 08:14:34 +00:00
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2002-03-26 11:05:30 +00:00
|
|
|
void InsetText::setText(string const & data, LyXFont const & font)
|
2001-01-03 16:04:05 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
clear();
|
2001-04-06 12:47:50 +00:00
|
|
|
for (unsigned int i=0; i < data.length(); ++i)
|
2001-06-25 00:06:33 +00:00
|
|
|
par->insertChar(i, data[i], font);
|
2002-03-26 11:05:30 +00:00
|
|
|
reinitLyXText();
|
2001-01-03 16:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::setAutoBreakRows(bool flag)
|
2000-05-15 14:49:36 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (flag != autoBreakRows) {
|
|
|
|
autoBreakRows = flag;
|
|
|
|
if (!flag)
|
|
|
|
removeNewlines();
|
2001-08-10 10:24:44 +00:00
|
|
|
need_update = INIT;
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
}
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::setDrawFrame(BufferView * bv, DrawFrame how)
|
2000-05-15 14:49:36 +00:00
|
|
|
{
|
2001-04-27 14:03:25 +00:00
|
|
|
if (how != drawFrame_) {
|
|
|
|
drawFrame_ = how;
|
2001-04-02 14:02:58 +00:00
|
|
|
if (bv)
|
2001-06-28 10:25:20 +00:00
|
|
|
updateLocal(bv, DRAW_FRAME, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
}
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetText::setFrameColor(BufferView * bv, LColor::color col)
|
2000-05-15 14:49:36 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
if (frame_color != col) {
|
|
|
|
frame_color = col;
|
|
|
|
if (bv)
|
2001-06-28 10:25:20 +00:00
|
|
|
updateLocal(bv, DRAW_FRAME, false);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2000-06-19 15:33:58 +00:00
|
|
|
}
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2000-09-27 18:13:30 +00:00
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
int InsetText::cx(BufferView * bv) const
|
2000-06-16 15:13:25 +00:00
|
|
|
{
|
2001-12-18 12:35:53 +00:00
|
|
|
// we do nothing dangerous so we use a local cache
|
|
|
|
LyXText * llt = getLyXText(bv);
|
|
|
|
int x = llt->cursor.x() + top_x + TEXT_TO_INSET_OFFSET;
|
2000-12-05 14:15:44 +00:00
|
|
|
if (the_locking_inset) {
|
2001-12-18 12:35:53 +00:00
|
|
|
LyXFont font = llt->getFont(bv->buffer(), llt->cursor.par(),
|
2002-03-21 17:09:55 +00:00
|
|
|
llt->cursor.pos());
|
2000-12-05 14:15:44 +00:00
|
|
|
if (font.isVisibleRightToLeft())
|
|
|
|
x -= the_locking_inset->width(bv, font);
|
|
|
|
}
|
|
|
|
return x;
|
2000-06-16 15:13:25 +00:00
|
|
|
}
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2002-04-12 15:59:03 +00:00
|
|
|
int InsetText::cix(BufferView * bv) const
|
|
|
|
{
|
|
|
|
// we do nothing dangerous so we use a local cache
|
|
|
|
LyXText * llt = getLyXText(bv);
|
|
|
|
int x = llt->cursor.ix() + top_x + TEXT_TO_INSET_OFFSET;
|
|
|
|
if (the_locking_inset) {
|
|
|
|
LyXFont font = llt->getFont(bv->buffer(), llt->cursor.par(),
|
|
|
|
llt->cursor.pos());
|
|
|
|
if (font.isVisibleRightToLeft())
|
|
|
|
x -= the_locking_inset->width(bv, font);
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
int InsetText::cy(BufferView * bv) const
|
2000-06-16 15:13:25 +00:00
|
|
|
{
|
2001-04-02 14:02:58 +00:00
|
|
|
LyXFont font;
|
2001-06-29 15:17:05 +00:00
|
|
|
return getLyXText(bv)->cursor.y() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
|
2000-06-21 15:07:57 +00:00
|
|
|
}
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2002-04-11 15:08:22 +00:00
|
|
|
int InsetText::ciy(BufferView * bv) const
|
|
|
|
{
|
|
|
|
LyXFont font;
|
|
|
|
return getLyXText(bv)->cursor.iy() - ascent(bv, font) + TEXT_TO_INSET_OFFSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-27 10:34:16 +00:00
|
|
|
pos_type InsetText::cpos(BufferView * bv) const
|
2000-06-21 15:07:57 +00:00
|
|
|
{
|
2001-06-29 15:17:05 +00:00
|
|
|
return getLyXText(bv)->cursor.pos();
|
2000-06-21 15:07:57 +00:00
|
|
|
}
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * InsetText::cpar(BufferView * bv) const
|
2000-06-21 15:07:57 +00:00
|
|
|
{
|
2001-06-29 15:17:05 +00:00
|
|
|
return getLyXText(bv)->cursor.par();
|
2000-06-16 15:13:25 +00:00
|
|
|
}
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
2000-12-17 06:09:35 +00:00
|
|
|
bool InsetText::cboundary(BufferView * bv) const
|
|
|
|
{
|
2001-06-29 15:17:05 +00:00
|
|
|
return getLyXText(bv)->cursor.boundary();
|
2000-12-17 06:09:35 +00:00
|
|
|
}
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
Row * InsetText::crow(BufferView * bv) const
|
2000-06-16 15:13:25 +00:00
|
|
|
{
|
2001-06-29 15:17:05 +00:00
|
|
|
return getLyXText(bv)->cursor.row();
|
2000-06-16 15:13:25 +00:00
|
|
|
}
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2001-04-06 12:47:50 +00:00
|
|
|
LyXText * InsetText::getLyXText(BufferView const * lbv,
|
2002-03-21 17:09:55 +00:00
|
|
|
bool const recursive) const
|
2000-06-16 15:13:25 +00:00
|
|
|
{
|
2002-03-06 16:02:51 +00:00
|
|
|
if (cached_bview == lbv) {
|
|
|
|
if (recursive && the_locking_inset)
|
|
|
|
return the_locking_inset->getLyXText(lbv, true);
|
2001-11-29 12:58:59 +00:00
|
|
|
LyXText * lt = cached_text.get();
|
2001-11-29 13:43:12 +00:00
|
|
|
lyx::Assert(lt && lt->firstRow()->par() == par);
|
2002-01-14 15:29:40 +00:00
|
|
|
return lt;
|
2001-11-29 12:58:59 +00:00
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
// Super UGLY! (Lgb)
|
|
|
|
BufferView * bv = const_cast<BufferView *>(lbv);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-07-02 15:29:23 +00:00
|
|
|
cached_bview = bv;
|
2001-07-03 07:46:50 +00:00
|
|
|
Cache::iterator it = cache.find(bv);
|
2001-07-27 20:27:56 +00:00
|
|
|
|
|
|
|
if (it != cache.end()) {
|
2002-01-07 14:50:57 +00:00
|
|
|
if (do_reinit) {
|
2001-08-13 11:04:49 +00:00
|
|
|
reinitLyXText();
|
2002-01-07 14:50:57 +00:00
|
|
|
} else if (do_resize) {
|
2001-08-13 11:04:49 +00:00
|
|
|
resizeLyXText(do_resize);
|
2002-01-07 14:50:57 +00:00
|
|
|
} else {
|
|
|
|
if (lt || !it->second.remove) {
|
|
|
|
lyx::Assert(it->second.text.get());
|
|
|
|
cached_text = it->second.text;
|
|
|
|
if (recursive && the_locking_inset) {
|
|
|
|
return the_locking_inset->getLyXText(bv, true);
|
|
|
|
}
|
|
|
|
return cached_text.get();
|
|
|
|
} else if (it->second.remove) {
|
|
|
|
if (locked) {
|
|
|
|
saveLyXTextState(it->second.text.get());
|
|
|
|
} else {
|
|
|
|
sstate.lpar = 0;
|
|
|
|
}
|
2001-07-27 20:27:56 +00:00
|
|
|
}
|
2002-01-07 14:50:57 +00:00
|
|
|
//
|
|
|
|
// when we have to reinit the existing LyXText!
|
|
|
|
//
|
|
|
|
it->second.text->init(bv);
|
|
|
|
restoreLyXTextState(bv, it->second.text.get());
|
|
|
|
it->second.remove = false;
|
|
|
|
}
|
|
|
|
cached_text = it->second.text;
|
|
|
|
if (the_locking_inset && recursive) {
|
|
|
|
return the_locking_inset->getLyXText(bv);
|
2001-07-12 12:26:06 +00:00
|
|
|
}
|
2002-01-07 14:50:57 +00:00
|
|
|
return cached_text.get();
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2002-01-07 14:50:57 +00:00
|
|
|
///
|
|
|
|
// we are here only if we don't have a BufferView * in the cache!!!
|
|
|
|
///
|
2001-07-05 14:52:08 +00:00
|
|
|
cached_text.reset(new LyXText(const_cast<InsetText *>(this)));
|
2001-07-02 15:29:23 +00:00
|
|
|
cached_text->init(bv);
|
2001-07-12 12:26:06 +00:00
|
|
|
restoreLyXTextState(bv, cached_text.get());
|
2001-07-03 07:46:50 +00:00
|
|
|
|
|
|
|
cache.insert(make_pair(bv, cached_text));
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-07-12 12:26:06 +00:00
|
|
|
if (the_locking_inset && recursive) {
|
|
|
|
return the_locking_inset->getLyXText(bv);
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2001-07-05 14:52:08 +00:00
|
|
|
return cached_text.get();
|
2000-06-16 15:13:25 +00:00
|
|
|
}
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2000-07-14 14:57:20 +00:00
|
|
|
void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
|
2000-06-16 15:13:25 +00:00
|
|
|
{
|
2001-07-02 15:29:23 +00:00
|
|
|
cached_bview = 0;
|
2001-07-03 07:46:50 +00:00
|
|
|
|
|
|
|
Cache::iterator it = cache.find(bv);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-07-03 07:46:50 +00:00
|
|
|
if (it == cache.end()) {
|
2001-04-02 14:02:58 +00:00
|
|
|
return;
|
2001-07-03 07:46:50 +00:00
|
|
|
}
|
|
|
|
|
2001-07-12 12:26:06 +00:00
|
|
|
lyx::Assert(it->second.text.get());
|
2001-07-05 14:52:08 +00:00
|
|
|
|
2001-07-12 12:26:06 +00:00
|
|
|
it->second.remove = true;
|
2001-04-02 14:02:58 +00:00
|
|
|
if (recursive) {
|
|
|
|
/// then remove all LyXText in text-insets
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * p = par;
|
2001-04-02 14:02:58 +00:00
|
|
|
for (; p; p = p->next()) {
|
|
|
|
p->deleteInsetsLyXText(bv);
|
|
|
|
}
|
|
|
|
}
|
2000-07-14 14:57:20 +00:00
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2001-06-07 14:51:20 +00:00
|
|
|
void InsetText::resizeLyXText(BufferView * bv, bool force) const
|
2000-07-14 14:57:20 +00:00
|
|
|
{
|
2001-08-13 11:04:49 +00:00
|
|
|
if (lt) {
|
|
|
|
// we cannot resize this because we are in use!
|
|
|
|
// so do this on the next possible getLyXText()
|
|
|
|
do_resize = bv;
|
|
|
|
return;
|
|
|
|
}
|
2001-08-13 21:50:13 +00:00
|
|
|
do_resize = 0;
|
2001-08-10 09:39:15 +00:00
|
|
|
// lyxerr << "InsetText::resizeLyXText\n";
|
2001-12-19 16:13:21 +00:00
|
|
|
if (!par->next() && !par->size()) { // no data, resize not neccessary!
|
|
|
|
// we have to do this as a fixed width may have changed!
|
|
|
|
LyXText * t = getLyXText(bv);
|
|
|
|
saveLyXTextState(t);
|
|
|
|
t->init(bv, true);
|
|
|
|
restoreLyXTextState(bv, t);
|
2001-05-28 15:11:24 +00:00
|
|
|
return;
|
2001-12-19 16:13:21 +00:00
|
|
|
}
|
2001-06-07 14:51:20 +00:00
|
|
|
// one endless line, resize normally not necessary
|
|
|
|
if (!force && getMaxWidth(bv, this) < 0)
|
2001-04-02 14:02:58 +00:00
|
|
|
return;
|
|
|
|
|
2001-07-03 07:46:50 +00:00
|
|
|
Cache::iterator it = cache.find(bv);
|
|
|
|
if (it == cache.end()) {
|
|
|
|
return;
|
|
|
|
}
|
2001-07-12 12:26:06 +00:00
|
|
|
lyx::Assert(it->second.text.get());
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
LyXText * t = it->second.text.get();
|
|
|
|
saveLyXTextState(t);
|
|
|
|
for (Paragraph * p = par; p; p = p->next()) {
|
|
|
|
p->resizeInsetsLyXText(bv);
|
|
|
|
}
|
|
|
|
t->init(bv, true);
|
|
|
|
restoreLyXTextState(bv, t);
|
|
|
|
if (the_locking_inset) {
|
2002-04-12 15:59:03 +00:00
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2002-04-11 15:08:22 +00:00
|
|
|
inset_y = ciy(bv) + drawTextYOffset;
|
2001-07-20 14:18:48 +00:00
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
|
2001-06-29 15:17:05 +00:00
|
|
|
if (bv->screen()) {
|
2002-03-03 20:25:07 +00:00
|
|
|
t->first_y = bv->screen()->topCursorVisible(t);
|
2001-06-29 15:17:05 +00:00
|
|
|
}
|
2001-08-07 15:07:36 +00:00
|
|
|
if (!owner()) {
|
2001-07-20 14:18:48 +00:00
|
|
|
updateLocal(bv, FULL, false);
|
2002-03-21 17:09:55 +00:00
|
|
|
// this will scroll the screen such that the cursor becomes visible
|
2001-08-07 15:07:36 +00:00
|
|
|
bv->updateScrollbar();
|
|
|
|
} else {
|
2001-08-02 14:55:06 +00:00
|
|
|
need_update |= FULL;
|
2001-08-07 15:07:36 +00:00
|
|
|
}
|
2000-06-16 15:13:25 +00:00
|
|
|
}
|
2000-08-07 15:21:05 +00:00
|
|
|
|
|
|
|
|
2001-08-10 12:21:42 +00:00
|
|
|
void InsetText::reinitLyXText() const
|
2001-07-31 09:53:40 +00:00
|
|
|
{
|
2001-08-13 11:04:49 +00:00
|
|
|
if (lt) {
|
|
|
|
// we cannot resize this because we are in use!
|
|
|
|
// so do this on the next possible getLyXText()
|
|
|
|
do_reinit = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
do_reinit = false;
|
2001-08-13 21:50:13 +00:00
|
|
|
do_resize = 0;
|
2001-08-10 09:39:15 +00:00
|
|
|
// lyxerr << "InsetText::reinitLyXText\n";
|
2001-07-31 09:53:40 +00:00
|
|
|
for(Cache::iterator it = cache.begin(); it != cache.end(); ++it) {
|
|
|
|
lyx::Assert(it->second.text.get());
|
|
|
|
|
|
|
|
LyXText * t = it->second.text.get();
|
|
|
|
BufferView * bv = it->first;
|
|
|
|
|
|
|
|
saveLyXTextState(t);
|
|
|
|
for (Paragraph * p = par; p; p = p->next()) {
|
|
|
|
p->resizeInsetsLyXText(bv);
|
|
|
|
}
|
|
|
|
t->init(bv, true);
|
|
|
|
restoreLyXTextState(bv, t);
|
|
|
|
if (the_locking_inset) {
|
2002-04-12 15:59:03 +00:00
|
|
|
inset_x = cix(bv) - top_x + drawTextXOffset;
|
2002-04-11 15:08:22 +00:00
|
|
|
inset_y = ciy(bv) + drawTextYOffset;
|
2001-07-31 09:53:40 +00:00
|
|
|
}
|
|
|
|
if (bv->screen()) {
|
2002-03-03 20:25:07 +00:00
|
|
|
t->first_y = bv->screen()->topCursorVisible(t);
|
2001-07-31 09:53:40 +00:00
|
|
|
}
|
2001-08-07 15:07:36 +00:00
|
|
|
if (!owner()) {
|
2001-07-31 09:53:40 +00:00
|
|
|
updateLocal(bv, FULL, false);
|
2002-03-21 17:09:55 +00:00
|
|
|
// this will scroll the screen such that the cursor becomes visible
|
2001-08-07 15:07:36 +00:00
|
|
|
bv->updateScrollbar();
|
|
|
|
} else {
|
2001-07-31 09:53:40 +00:00
|
|
|
need_update = FULL;
|
2001-08-07 15:07:36 +00:00
|
|
|
}
|
2001-07-31 09:53:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-07 15:21:05 +00:00
|
|
|
void InsetText::removeNewlines()
|
|
|
|
{
|
2001-12-03 13:17:04 +00:00
|
|
|
bool changed = false;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
for (Paragraph * p = par; p; p = p->next()) {
|
2001-04-02 14:02:58 +00:00
|
|
|
for (int i = 0; i < p->size(); ++i) {
|
2001-12-03 13:17:04 +00:00
|
|
|
if (p->getChar(i) == Paragraph::META_NEWLINE) {
|
|
|
|
changed = true;
|
2001-06-25 00:06:33 +00:00
|
|
|
p->erase(i);
|
2001-12-03 13:17:04 +00:00
|
|
|
}
|
2001-04-02 14:02:58 +00:00
|
|
|
}
|
2000-08-07 15:21:05 +00:00
|
|
|
}
|
2001-12-03 13:17:04 +00:00
|
|
|
if (changed)
|
|
|
|
reinitLyXText();
|
2000-08-07 15:21:05 +00:00
|
|
|
}
|
2001-04-27 14:03:25 +00:00
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
2001-04-27 14:03:25 +00:00
|
|
|
bool InsetText::nodraw() const
|
|
|
|
{
|
|
|
|
if (the_locking_inset)
|
|
|
|
return the_locking_inset->nodraw();
|
|
|
|
return UpdatableInset::nodraw();
|
|
|
|
}
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
2001-04-27 14:03:25 +00:00
|
|
|
int InsetText::scroll(bool recursive) const
|
|
|
|
{
|
|
|
|
int sx = UpdatableInset::scroll(false);
|
|
|
|
|
|
|
|
if (recursive && the_locking_inset)
|
|
|
|
sx += the_locking_inset->scroll(recursive);
|
|
|
|
|
|
|
|
return sx;
|
|
|
|
}
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
2001-04-27 14:03:25 +00:00
|
|
|
bool InsetText::doClearArea() const
|
|
|
|
{
|
|
|
|
return !locked || (need_update & (FULL|INIT));
|
|
|
|
}
|
2001-05-28 15:11:24 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-05-28 15:11:24 +00:00
|
|
|
void InsetText::selectAll(BufferView * bv)
|
|
|
|
{
|
2001-06-29 15:17:05 +00:00
|
|
|
getLyXText(bv)->cursorTop(bv);
|
|
|
|
getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
|
|
|
|
getLyXText(bv)->cursorBottom(bv);
|
|
|
|
getLyXText(bv)->setSelection(bv);
|
2001-05-28 15:11:24 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-05-28 15:11:24 +00:00
|
|
|
void InsetText::clearSelection(BufferView * bv)
|
|
|
|
{
|
2001-08-01 15:42:53 +00:00
|
|
|
getLyXText(bv)->clearSelection();
|
2001-05-28 15:11:24 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-12-04 16:10:19 +00:00
|
|
|
void InsetText::clearInset(BufferView * bv, int baseline, bool & cleared) const
|
2001-06-01 15:10:26 +00:00
|
|
|
{
|
2001-12-04 16:10:19 +00:00
|
|
|
Painter & pain = bv->painter();
|
2001-08-06 14:55:02 +00:00
|
|
|
int w = insetWidth;
|
2002-01-06 19:34:30 +00:00
|
|
|
int h = insetAscent + insetDescent;
|
2001-06-01 15:10:26 +00:00
|
|
|
int ty = baseline - insetAscent;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-06-01 15:10:26 +00:00
|
|
|
if (ty < 0) {
|
|
|
|
h += ty;
|
|
|
|
ty = 0;
|
|
|
|
}
|
|
|
|
if ((ty + h) > pain.paperHeight())
|
|
|
|
h = pain.paperHeight();
|
|
|
|
if ((top_x + drawTextXOffset + w) > pain.paperWidth())
|
|
|
|
w = pain.paperWidth();
|
2001-08-06 14:55:02 +00:00
|
|
|
// w -= TEXT_TO_INSET_OFFSET;
|
2002-05-23 09:21:32 +00:00
|
|
|
pain.fillRectangle(top_x + 1, ty + 1, w - 1, h - 1, backgroundColor());
|
2001-06-01 15:10:26 +00:00
|
|
|
cleared = true;
|
|
|
|
need_update = FULL;
|
2001-08-06 14:55:02 +00:00
|
|
|
frame_is_visible = false;
|
2001-06-01 15:10:26 +00:00
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
2001-07-09 09:16:00 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
Paragraph * InsetText::getParFromID(int id) const
|
|
|
|
{
|
2001-08-05 22:12:27 +00:00
|
|
|
#if 0
|
2001-07-06 15:57:54 +00:00
|
|
|
Paragraph * result = par;
|
|
|
|
Paragraph * ires = 0;
|
|
|
|
while (result && result->id() != id) {
|
|
|
|
if ((ires = result->getParFromID(id)))
|
|
|
|
return ires;
|
|
|
|
result = result->next();
|
|
|
|
}
|
|
|
|
return result;
|
2001-08-05 22:12:27 +00:00
|
|
|
#else
|
|
|
|
Paragraph * tmp = par;
|
|
|
|
while (tmp) {
|
|
|
|
if (tmp->id() == id) {
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
Paragraph * tmp2 = tmp->getParFromID(id);
|
|
|
|
if (tmp2 != 0) {
|
|
|
|
return tmp2;
|
|
|
|
}
|
|
|
|
tmp = tmp->next();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
#endif
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
|
|
|
|
2001-07-09 09:16:00 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
Paragraph * InsetText::firstParagraph() const
|
|
|
|
{
|
|
|
|
Paragraph * result;
|
|
|
|
if (the_locking_inset)
|
|
|
|
if ((result = the_locking_inset->firstParagraph()))
|
|
|
|
return result;
|
|
|
|
return par;
|
|
|
|
}
|
|
|
|
|
2001-07-09 09:16:00 +00:00
|
|
|
|
2001-09-01 21:26:34 +00:00
|
|
|
Paragraph * InsetText::getFirstParagraph(int i) const
|
|
|
|
{
|
|
|
|
return (i == 0) ? par : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
LyXCursor const & InsetText::cursor(BufferView * bv) const
|
|
|
|
{
|
|
|
|
if (the_locking_inset)
|
|
|
|
return the_locking_inset->cursor(bv);
|
|
|
|
return getLyXText(bv)->cursor;
|
|
|
|
}
|
|
|
|
|
2001-07-09 09:16:00 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
Paragraph * InsetText::paragraph() const
|
|
|
|
{
|
|
|
|
return par;
|
|
|
|
}
|
|
|
|
|
2001-07-09 09:16:00 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
void InsetText::paragraph(Paragraph * p)
|
|
|
|
{
|
2001-12-14 11:55:58 +00:00
|
|
|
// GENERAL COMMENT: We don't have to free the old paragraphs as the
|
|
|
|
// caller of this function has to take care of it. This IS important
|
|
|
|
// as we could have to insert a paragraph before this one and just
|
|
|
|
// link the actual to a new ones next and set it with this function
|
|
|
|
// and are done!
|
2001-07-06 15:57:54 +00:00
|
|
|
par = p;
|
2001-11-29 16:29:30 +00:00
|
|
|
// set ourself as owner for all the paragraphs inserted!
|
|
|
|
Paragraph * np = par;
|
|
|
|
while (np) {
|
|
|
|
np->setInsetOwner(this);
|
|
|
|
np = np->next();
|
|
|
|
}
|
2001-11-29 12:58:59 +00:00
|
|
|
reinitLyXText();
|
2001-07-06 15:57:54 +00:00
|
|
|
// redraw myself when asked for
|
2001-08-10 09:39:15 +00:00
|
|
|
need_update = INIT;
|
2001-07-06 15:57:54 +00:00
|
|
|
}
|
|
|
|
|
2001-07-09 09:16:00 +00:00
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
Inset * InsetText::getInsetFromID(int id_arg) const
|
|
|
|
{
|
|
|
|
if (id_arg == id())
|
|
|
|
return const_cast<InsetText *>(this);
|
|
|
|
|
|
|
|
Paragraph * lp = par;
|
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
while (lp) {
|
2001-07-06 15:57:54 +00:00
|
|
|
for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
|
|
|
|
en = lp->inset_iterator_end();
|
|
|
|
it != en; ++it)
|
|
|
|
{
|
|
|
|
if ((*it)->id() == id_arg)
|
|
|
|
return *it;
|
|
|
|
Inset * in = (*it)->getInsetFromID(id_arg);
|
|
|
|
if (in)
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
lp = lp->next();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2001-07-17 15:39:12 +00:00
|
|
|
|
|
|
|
|
2001-09-21 16:21:23 +00:00
|
|
|
string const InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
|
2001-07-17 15:39:12 +00:00
|
|
|
{
|
|
|
|
bool clear = false;
|
|
|
|
string str;
|
|
|
|
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
|
|
|
if (the_locking_inset) {
|
2001-09-21 16:21:23 +00:00
|
|
|
str = the_locking_inset->selectNextWordToSpellcheck(bv, value);
|
2001-07-17 15:39:12 +00:00
|
|
|
if (!str.empty()) {
|
|
|
|
value += cy(bv);
|
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
|
|
|
return str;
|
|
|
|
}
|
2002-01-13 15:34:53 +00:00
|
|
|
// we have to go on checking so move cusor to the next char
|
2001-07-17 15:39:12 +00:00
|
|
|
lt->cursor.pos(lt->cursor.pos() + 1);
|
|
|
|
}
|
2001-09-21 16:21:23 +00:00
|
|
|
str = lt->selectNextWordToSpellcheck(bv, value);
|
2001-07-17 15:39:12 +00:00
|
|
|
if (str.empty())
|
|
|
|
bv->unlockInset(const_cast<InsetText *>(this));
|
|
|
|
else
|
|
|
|
value = cy(bv);
|
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::selectSelectedWord(BufferView * bv)
|
|
|
|
{
|
|
|
|
if (the_locking_inset) {
|
|
|
|
the_locking_inset->selectSelectedWord(bv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
getLyXText(bv)->selectSelectedWord(bv);
|
|
|
|
updateLocal(bv, SELECTION, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
|
|
|
|
{
|
|
|
|
if (the_locking_inset) {
|
|
|
|
the_locking_inset->toggleSelection(bv, kill_selection);
|
|
|
|
}
|
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int x = top_x + TEXT_TO_INSET_OFFSET;
|
|
|
|
|
2001-11-29 13:43:12 +00:00
|
|
|
Row * row = lt->firstRow();
|
2001-07-17 15:39:12 +00:00
|
|
|
int y_offset = top_baseline - row->ascent_of_text();
|
2001-11-29 13:43:12 +00:00
|
|
|
int y = y_offset;
|
2001-07-17 15:39:12 +00:00
|
|
|
while ((row != 0) && ((y+row->height()) <= 0)) {
|
|
|
|
y += row->height();
|
|
|
|
row = row->next();
|
|
|
|
}
|
|
|
|
if (y_offset < 0)
|
|
|
|
y_offset = y;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
if (need_update & SELECTION)
|
|
|
|
need_update = NONE;
|
2001-07-17 15:39:12 +00:00
|
|
|
bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
|
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
|
|
|
}
|
2001-07-20 14:18:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::searchForward(BufferView * bv, string const & str,
|
2002-03-21 17:09:55 +00:00
|
|
|
bool cs, bool mw)
|
2001-07-20 14:18:48 +00:00
|
|
|
{
|
2001-08-01 15:42:53 +00:00
|
|
|
if (the_locking_inset) {
|
2001-07-20 14:18:48 +00:00
|
|
|
if (the_locking_inset->searchForward(bv, str, cs, mw))
|
|
|
|
return true;
|
2001-08-01 15:42:53 +00:00
|
|
|
bool clear = false;
|
|
|
|
if (!lt) {
|
|
|
|
lt = getLyXText(bv);
|
|
|
|
clear = true;
|
|
|
|
}
|
|
|
|
Paragraph * lpar = lt->cursor.par();
|
2001-11-27 10:34:16 +00:00
|
|
|
pos_type pos = lt->cursor.pos();
|
2001-08-01 15:42:53 +00:00
|
|
|
if (pos < lpar->size() - 1)
|
|
|
|
++pos;
|
|
|
|
else {
|
|
|
|
pos = 0;
|
|
|
|
lpar = lpar->next();
|
|
|
|
}
|
|
|
|
if (!lpar) {
|
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
2001-08-13 11:27:53 +00:00
|
|
|
// we have to unlock ourself in this function by default!
|
|
|
|
bv->unlockInset(const_cast<InsetText *>(this));
|
2001-08-01 15:42:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
lt->setCursor(bv, lpar, pos);
|
|
|
|
if (clear)
|
|
|
|
lt = 0;
|
|
|
|
}
|
2001-07-20 14:18:48 +00:00
|
|
|
if (LyXFind(bv, str, true, true, cs , mw)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// we have to unlock ourself in this function by default!
|
|
|
|
bv->unlockInset(const_cast<InsetText *>(this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InsetText::searchBackward(BufferView * bv, string const & str,
|
2002-03-21 17:09:55 +00:00
|
|
|
bool cs, bool mw)
|
2001-07-20 14:18:48 +00:00
|
|
|
{
|
|
|
|
if (the_locking_inset)
|
|
|
|
if (the_locking_inset->searchBackward(bv, str, cs, mw))
|
|
|
|
return true;
|
|
|
|
if (LyXFind(bv, str, false, true, cs, mw)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// we have to unlock ourself in this function by default!
|
|
|
|
bv->unlockInset(const_cast<InsetText *>(this));
|
|
|
|
return false;
|
|
|
|
}
|
2001-10-22 09:45:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool InsetText::checkInsertChar(LyXFont & font)
|
|
|
|
{
|
|
|
|
if (owner())
|
|
|
|
return owner()->checkInsertChar(font);
|
|
|
|
return true;
|
|
|
|
}
|
2001-12-18 12:35:53 +00:00
|
|
|
|
|
|
|
|
2002-04-12 15:59:03 +00:00
|
|
|
void InsetText::collapseParagraphs(BufferView * bv) const
|
2001-12-18 12:35:53 +00:00
|
|
|
{
|
2002-04-12 15:59:03 +00:00
|
|
|
BufferParams const & bparams = bv->buffer()->params;
|
|
|
|
LyXText * llt = getLyXText(bv);
|
2002-04-22 16:31:14 +00:00
|
|
|
|
2001-12-18 12:35:53 +00:00
|
|
|
while(par->next()) {
|
2002-03-26 11:05:30 +00:00
|
|
|
if (par->size() && par->next()->size() &&
|
|
|
|
!par->isSeparator(par->size()-1))
|
|
|
|
{
|
|
|
|
par->insertChar(par->size(), ' ');
|
|
|
|
}
|
2002-04-12 15:59:03 +00:00
|
|
|
if (llt->selection.set()) {
|
|
|
|
if (llt->selection.start.par() == par->next()) {
|
|
|
|
llt->selection.start.par(par);
|
|
|
|
llt->selection.start.pos(
|
|
|
|
llt->selection.start.pos() + par->size());
|
|
|
|
}
|
|
|
|
if (llt->selection.end.par() == par->next()) {
|
|
|
|
llt->selection.end.par(par);
|
|
|
|
llt->selection.end.pos(
|
|
|
|
llt->selection.end.pos() + par->size());
|
|
|
|
}
|
|
|
|
}
|
2001-12-18 12:35:53 +00:00
|
|
|
par->pasteParagraph(bparams);
|
|
|
|
}
|
|
|
|
reinitLyXText();
|
|
|
|
}
|
2002-02-20 14:55:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
void InsetText::getDrawFont(LyXFont & font) const
|
|
|
|
{
|
|
|
|
if (!owner())
|
|
|
|
return;
|
|
|
|
owner()->getDrawFont(font);
|
|
|
|
}
|
2002-03-21 15:58:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
void InsetText::appendParagraphs(BufferParams const & bparams,
|
2002-03-21 17:09:55 +00:00
|
|
|
Paragraph * newpar)
|
2002-03-21 15:58:54 +00:00
|
|
|
{
|
|
|
|
Paragraph * buf;
|
|
|
|
Paragraph * tmpbuf = newpar;
|
|
|
|
Paragraph * lastbuffer = buf = new Paragraph(*tmpbuf, false);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2002-03-21 15:58:54 +00:00
|
|
|
while (tmpbuf->next()) {
|
|
|
|
tmpbuf = tmpbuf->next();
|
|
|
|
lastbuffer->next(new Paragraph(*tmpbuf, false));
|
|
|
|
lastbuffer->next()->previous(lastbuffer);
|
|
|
|
lastbuffer = lastbuffer->next();
|
|
|
|
}
|
|
|
|
lastbuffer = par;
|
|
|
|
while (lastbuffer->next())
|
|
|
|
lastbuffer = lastbuffer->next();
|
|
|
|
if (newpar->size() && lastbuffer->size() &&
|
|
|
|
!lastbuffer->isSeparator(lastbuffer->size()-1))
|
|
|
|
{
|
|
|
|
lastbuffer->insertChar(lastbuffer->size(), ' ');
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2002-03-21 15:58:54 +00:00
|
|
|
// make the buf exactly the same layout than our last paragraph
|
|
|
|
buf->makeSameLayout(lastbuffer);
|
|
|
|
|
|
|
|
// paste it!
|
|
|
|
lastbuffer->next(buf);
|
|
|
|
buf->previous(lastbuffer);
|
|
|
|
lastbuffer->pasteParagraph(bparams);
|
|
|
|
|
|
|
|
reinitLyXText();
|
|
|
|
}
|