1999-09-27 18:44:28 +00:00
|
|
|
|
/* This file is part of
|
1999-10-07 18:44:17 +00:00
|
|
|
|
* ======================================================
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
1999-10-07 18:44:17 +00:00
|
|
|
|
* LyX, The Document Processor
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
1999-10-07 18:44:17 +00:00
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-10-07 18:44:17 +00:00
|
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma implementation "lyxtext.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
|
#include "lyxtext.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "LString.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "paragraph.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
#include "lyxtextclasslist.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2001-07-06 15:57:54 +00:00
|
|
|
|
#include "undo_funcs.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "bufferparams.h"
|
|
|
|
|
#include "gettext.h"
|
1999-12-19 22:35:36 +00:00
|
|
|
|
#include "BufferView.h"
|
2000-04-10 14:29:05 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2002-05-23 09:21:32 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2002-05-24 14:34:32 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
2000-04-08 17:02:02 +00:00
|
|
|
|
#include "debug.h"
|
2000-07-10 10:31:34 +00:00
|
|
|
|
#include "lyxrc.h"
|
2001-11-26 16:42:04 +00:00
|
|
|
|
#include "lyxrow.h"
|
2000-07-18 17:45:27 +00:00
|
|
|
|
#include "FloatList.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "language.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
|
|
|
|
#include "insets/inseterror.h"
|
|
|
|
|
#include "insets/insetbib.h"
|
|
|
|
|
#include "insets/insetspecialchar.h"
|
|
|
|
|
#include "insets/insettext.h"
|
|
|
|
|
#include "insets/insetfloat.h"
|
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#include "support/LAssert.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "support/textutils.h"
|
|
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::vector;
|
1999-12-19 22:35:36 +00:00
|
|
|
|
using std::copy;
|
2001-01-19 15:31:40 +00:00
|
|
|
|
using std::find;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2001-01-19 15:31:40 +00:00
|
|
|
|
using std::find;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::pair;
|
2001-11-27 10:34:16 +00:00
|
|
|
|
using lyx::pos_type;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-21 18:47:54 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
LyXText::LyXText(BufferView * bv)
|
2002-03-03 20:25:07 +00:00
|
|
|
|
: number_of_rows(0), height(0), width(0), first_y(0),
|
2001-07-06 15:41:17 +00:00
|
|
|
|
bv_owner(bv), inset_owner(0), the_locking_inset(0),
|
2001-07-07 18:02:19 +00:00
|
|
|
|
need_break_row(0), refresh_y(0), refresh_row(0),
|
2002-03-02 16:39:54 +00:00
|
|
|
|
status_(LyXText::UNCHANGED), firstrow(0), lastrow(0)
|
2001-07-06 15:41:17 +00:00
|
|
|
|
{}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXText::LyXText(InsetText * inset)
|
2002-03-03 20:25:07 +00:00
|
|
|
|
: number_of_rows(0), height(0), width(0), first_y(0),
|
2001-07-06 15:41:17 +00:00
|
|
|
|
bv_owner(0), inset_owner(inset), the_locking_inset(0),
|
2001-07-07 18:02:19 +00:00
|
|
|
|
need_break_row(0), refresh_y(0), refresh_row(0),
|
2002-03-02 16:39:54 +00:00
|
|
|
|
status_(LyXText::UNCHANGED), firstrow(0), lastrow(0)
|
2001-07-06 15:41:17 +00:00
|
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
|
void LyXText::init(BufferView * bview, bool reinit)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2001-07-20 14:18:48 +00:00
|
|
|
|
if (reinit) {
|
|
|
|
|
// Delete all rows, this does not touch the paragraphs!
|
|
|
|
|
Row * tmprow = firstrow;
|
|
|
|
|
while (firstrow) {
|
|
|
|
|
tmprow = firstrow->next();
|
|
|
|
|
delete firstrow;
|
|
|
|
|
firstrow = tmprow;
|
|
|
|
|
}
|
2002-03-03 20:25:07 +00:00
|
|
|
|
|
|
|
|
|
lastrow = 0;
|
|
|
|
|
refresh_row = 0;
|
|
|
|
|
need_break_row = 0;
|
2002-03-02 16:39:54 +00:00
|
|
|
|
width = height = 0;
|
|
|
|
|
copylayouttype.erase();
|
2002-03-03 20:25:07 +00:00
|
|
|
|
number_of_rows = first_y = refresh_y = 0;
|
2001-07-20 14:18:48 +00:00
|
|
|
|
status_ = LyXText::UNCHANGED;
|
|
|
|
|
} else if (firstrow)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = ownerParagraph();
|
|
|
|
|
current_font = getFont(bview->buffer(), par, 0);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
while (par) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
insertParagraph(bview, par, lastrow);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursorIntern(bview, firstrow->par(), 0);
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-06 15:41:17 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
LyXText::~LyXText()
|
|
|
|
|
{
|
|
|
|
|
// Delete all rows, this does not touch the paragraphs!
|
1999-11-04 01:40:20 +00:00
|
|
|
|
Row * tmprow = firstrow;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (firstrow) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
tmprow = firstrow->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
delete firstrow;
|
|
|
|
|
firstrow = tmprow;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
LyXFont const realizeFont(LyXFont const & font,
|
|
|
|
|
Buffer const * buf,
|
|
|
|
|
Paragraph * par)
|
|
|
|
|
{
|
|
|
|
|
LyXFont tmpfont(font);
|
|
|
|
|
Paragraph::depth_type par_depth = par->getDepth();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
// Resolve against environment font information
|
|
|
|
|
while (par && par_depth && !tmpfont.resolved()) {
|
|
|
|
|
par = par->outerHook();
|
|
|
|
|
if (par) {
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#ifndef INHERIT_LANGUAGE
|
2002-06-24 20:28:12 +00:00
|
|
|
|
tmpfont.realize(par->layout()->font);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#else
|
2001-08-03 18:28:11 +00:00
|
|
|
|
tmpfont.realize(textclasslist.
|
|
|
|
|
Style(buf->params.textclass,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
par->layout())->font,
|
2001-08-11 18:31:14 +00:00
|
|
|
|
buf->params.language);
|
|
|
|
|
#endif
|
2001-08-03 18:28:11 +00:00
|
|
|
|
par_depth = par->getDepth();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#ifndef INHERIT_LANGUAGE
|
2002-03-02 16:39:54 +00:00
|
|
|
|
tmpfont.realize(textclasslist[buf->params.textclass].defaultfont());
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#else
|
2002-03-02 16:39:54 +00:00
|
|
|
|
tmpfont.realize(textclasslist[buf->params.textclass].defaultfont(),
|
2002-03-21 17:27:08 +00:00
|
|
|
|
buf->params.language);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#endif
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
|
|
|
|
return tmpfont;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Gets the fully instantiated font at a given position in a paragraph
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// Basically the same routine as Paragraph::getFont() in paragraph.C.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// The difference is that this one is used for displaying, and thus we
|
|
|
|
|
// are allowed to make cosmetic improvements. For instance make footnotes
|
|
|
|
|
// smaller. (Asger)
|
|
|
|
|
// If position is -1, we get the layout font of the paragraph.
|
|
|
|
|
// If position is -2, we get the font of the manual label of the paragraph.
|
2001-06-25 00:06:33 +00:00
|
|
|
|
LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
pos_type pos) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-08-03 18:28:11 +00:00
|
|
|
|
lyx::Assert(pos >= 0);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par->layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type par_depth = par->getDepth();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// We specialize the 95% common case:
|
2001-05-03 14:31:33 +00:00
|
|
|
|
if (!par_depth) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->labeltype == LABEL_MANUAL
|
2001-08-03 18:28:11 +00:00
|
|
|
|
&& pos < beginningOfMainBody(buf, par)) {
|
2002-02-20 14:55:17 +00:00
|
|
|
|
// 1% goes here
|
|
|
|
|
LyXFont f = par->getFontSettings(buf->params, pos);
|
|
|
|
|
if (par->inInset())
|
|
|
|
|
par->inInset()->getDrawFont(f);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#ifndef INHERIT_LANGUAGE
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return f.realize(layout->reslabelfont);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#else
|
2001-08-03 18:28:11 +00:00
|
|
|
|
return f.realize(layout.reslabelfont, buf->params.language);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
LyXFont f = par->getFontSettings(buf->params, pos);
|
2002-02-20 14:55:17 +00:00
|
|
|
|
if (par->inInset())
|
|
|
|
|
par->inInset()->getDrawFont(f);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#ifndef INHERIT_LANGUAGE
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return f.realize(layout->resfont);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#else
|
2001-08-03 18:28:11 +00:00
|
|
|
|
return f.realize(layout.resfont, buf->params.language);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// The uncommon case need not be optimized as much
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
LyXFont layoutfont;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
if (pos < beginningOfMainBody(buf, par)) {
|
|
|
|
|
// 1% goes here
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->labelfont;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
} else {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
// 99% goes here
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
LyXFont tmpfont = par->getFontSettings(buf->params, pos);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#ifndef INHERIT_LANGUAGE
|
|
|
|
|
tmpfont.realize(layoutfont);
|
|
|
|
|
#else
|
2001-08-03 18:28:11 +00:00
|
|
|
|
tmpfont.realize(layoutfont, buf->params.language);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#endif
|
2002-02-20 14:55:17 +00:00
|
|
|
|
if (par->inInset())
|
|
|
|
|
par->inInset()->getDrawFont(tmpfont);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
return realizeFont(tmpfont, buf, par);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXFont const LyXText::getLayoutFont(Buffer const * buf, Paragraph * par) const
|
|
|
|
|
{
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par->layout();
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
|
|
|
|
Paragraph::depth_type par_depth = par->getDepth();
|
|
|
|
|
|
|
|
|
|
if (!par_depth) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return layout->resfont;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return realizeFont(layout->font, buf, par);
|
2001-08-03 18:28:11 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
|
|
|
|
LyXFont const LyXText::getLabelFont(Buffer const * buf, Paragraph * par) const
|
|
|
|
|
{
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par->layout();
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
|
|
|
|
Paragraph::depth_type par_depth = par->getDepth();
|
|
|
|
|
|
|
|
|
|
if (!par_depth) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return layout->reslabelfont;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return realizeFont(layout->labelfont, buf, par);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setCharFont(BufferView * bv, Paragraph * par,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
pos_type pos, LyXFont const & fnt,
|
|
|
|
|
bool toggleall)
|
2001-05-28 15:11:24 +00:00
|
|
|
|
{
|
|
|
|
|
Buffer const * buf = bv->buffer();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
LyXFont font = getFont(buf, par, pos);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
font.update(fnt, buf->params.language, toggleall);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
// Let the insets convert their font
|
2001-11-23 10:16:02 +00:00
|
|
|
|
if (par->isInset(pos)) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Inset * inset = par->getInset(pos);
|
2001-11-09 13:44:48 +00:00
|
|
|
|
if (isEditableInset(inset)) {
|
|
|
|
|
UpdatableInset * uinset =
|
|
|
|
|
static_cast<UpdatableInset *>(inset);
|
|
|
|
|
uinset->setFont(bv, fnt, toggleall, true);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-01 12:39:22 +00:00
|
|
|
|
// Plug thru to version below:
|
|
|
|
|
setCharFont(buf, par, pos, font);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-06 15:41:17 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setCharFont(Buffer const * buf, Paragraph * par,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
pos_type pos, LyXFont const & fnt)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LyXFont font(fnt);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
LyXTextClass const & tclass = textclasslist[buf->params.textclass];
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par->layout();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Get concrete layout font to reduce against
|
|
|
|
|
LyXFont layoutfont;
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (pos < beginningOfMainBody(buf, par))
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->labelfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Realize against environment font information
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (par->getDepth()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * tp = par;
|
|
|
|
|
while (!layoutfont.resolved() && tp && tp->getDepth()) {
|
|
|
|
|
tp = tp->outerHook();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (tp)
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#ifndef INHERIT_LANGUAGE
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont.realize(tp->layout()->font);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#else
|
1999-11-04 01:40:20 +00:00
|
|
|
|
layoutfont.realize(textclasslist.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
Style(buf->params.textclass,
|
|
|
|
|
tp->layout()).font,
|
|
|
|
|
buf->params.language);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#ifndef INHERIT_LANGUAGE
|
2002-03-02 16:39:54 +00:00
|
|
|
|
layoutfont.realize(tclass.defaultfont());
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#else
|
2002-03-02 16:39:54 +00:00
|
|
|
|
layoutfont.realize(tclass.defaultfont(), buf->params.language);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Now, reduce font against full layout font
|
|
|
|
|
font.reduce(layoutfont);
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->setFont(pos, font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// inserts a new row behind the specified row, increments
|
|
|
|
|
// the touched counters
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::insertRow(Row * row, Paragraph * par,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
pos_type pos) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
Row * tmprow = new Row;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (!row) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
tmprow->previous(0);
|
|
|
|
|
tmprow->next(firstrow);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
firstrow = tmprow;
|
2000-02-23 16:39:03 +00:00
|
|
|
|
} else {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
tmprow->previous(row);
|
|
|
|
|
tmprow->next(row->next());
|
|
|
|
|
row->next(tmprow);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (tmprow->next())
|
|
|
|
|
tmprow->next()->previous(tmprow);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (tmprow->previous())
|
|
|
|
|
tmprow->previous()->next(tmprow);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
tmprow->par(par);
|
|
|
|
|
tmprow->pos(pos);
|
2000-02-23 16:39:03 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (row == lastrow)
|
|
|
|
|
lastrow = tmprow;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
++number_of_rows;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// removes the row and reset the touched counters
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::removeRow(Row * row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-01-16 12:57:26 +00:00
|
|
|
|
Row * row_prev = row->previous();
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (row->next())
|
2002-01-16 12:57:26 +00:00
|
|
|
|
row->next()->previous(row_prev);
|
|
|
|
|
if (!row_prev) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
firstrow = row->next();
|
2001-11-29 14:08:19 +00:00
|
|
|
|
// lyx::Assert(firstrow);
|
2000-02-23 16:39:03 +00:00
|
|
|
|
} else {
|
2002-01-16 12:57:26 +00:00
|
|
|
|
row_prev->next(row->next());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-01-16 12:57:26 +00:00
|
|
|
|
if (row == lastrow) {
|
|
|
|
|
lyx::Assert(!row->next());
|
|
|
|
|
lastrow = row_prev;
|
|
|
|
|
}
|
|
|
|
|
if (refresh_row == row) {
|
|
|
|
|
refresh_row = row_prev ? row_prev : row->next();
|
2002-01-18 03:50:19 +00:00
|
|
|
|
// what about refresh_y, refresh_height
|
2002-01-16 12:57:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
height -= row->height(); // the text becomes smaller
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
delete row;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
--number_of_rows; // one row less
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// remove all following rows of the paragraph of the specified row.
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::removeParagraph(Row * row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * tmppar = row->par();
|
2000-06-08 23:16:16 +00:00
|
|
|
|
row = row->next();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
Row * tmprow;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
while (row && row->par() == tmppar) {
|
|
|
|
|
tmprow = row->next();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
removeRow(row);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
row = tmprow;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-02-23 16:39:03 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// insert the specified paragraph behind the specified row
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::insertParagraph(BufferView * bview, Paragraph * par,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
Row * row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-03-21 17:27:08 +00:00
|
|
|
|
insertRow(row, par, 0); /* insert a new row, starting
|
|
|
|
|
* at postition 0 */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCounter(bview->buffer(), par); // set the counters
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// and now append the whole paragraph behind the new row
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (!row) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
firstrow->height(0);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
appendParagraph(bview, firstrow);
|
2000-02-23 16:39:03 +00:00
|
|
|
|
} else {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
row->next()->height(0);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
appendParagraph(bview, row->next());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
|
2001-07-19 08:52:59 +00:00
|
|
|
|
Inset * LyXText::getInset() const
|
2001-07-11 12:10:46 +00:00
|
|
|
|
{
|
2001-07-19 08:52:59 +00:00
|
|
|
|
Inset * inset = 0;
|
2001-07-20 14:18:48 +00:00
|
|
|
|
if (cursor.pos() == 0 && cursor.par()->bibkey) {
|
2001-07-19 08:52:59 +00:00
|
|
|
|
inset = cursor.par()->bibkey;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
} else if (cursor.pos() < cursor.par()->size()
|
2001-11-23 10:16:02 +00:00
|
|
|
|
&& cursor.par()->isInset(cursor.pos())) {
|
2001-07-19 08:52:59 +00:00
|
|
|
|
inset = cursor.par()->getInset(cursor.pos());
|
2001-07-11 12:10:46 +00:00
|
|
|
|
}
|
2001-07-19 08:52:59 +00:00
|
|
|
|
return inset;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
|
2001-07-19 08:52:59 +00:00
|
|
|
|
void LyXText::toggleInset(BufferView * bview)
|
|
|
|
|
{
|
|
|
|
|
Inset * inset = getInset();
|
2002-02-12 12:56:46 +00:00
|
|
|
|
// is there an editable inset at cursor position?
|
|
|
|
|
if (!isEditableInset(inset)) {
|
|
|
|
|
// No, try to see if we are inside a collapsable inset
|
|
|
|
|
if (inset_owner && inset_owner->owner()
|
|
|
|
|
&& inset_owner->owner()->isOpen()) {
|
|
|
|
|
bview->unlockInset(static_cast<UpdatableInset *>(inset_owner->owner()));
|
|
|
|
|
inset_owner->owner()->close(bview);
|
2002-07-19 21:44:14 +00:00
|
|
|
|
bview->getLyXText()->cursorRight(bview);
|
2002-02-12 12:56:46 +00:00
|
|
|
|
}
|
2001-07-19 08:52:59 +00:00
|
|
|
|
return;
|
2002-02-12 12:56:46 +00:00
|
|
|
|
}
|
2001-07-19 08:52:59 +00:00
|
|
|
|
//bview->owner()->message(inset->editMessage());
|
|
|
|
|
|
|
|
|
|
// do we want to keep this?? (JMarc)
|
2001-11-09 13:44:48 +00:00
|
|
|
|
if (!isHighlyEditableInset(inset))
|
2001-07-19 08:52:59 +00:00
|
|
|
|
setCursorParUndo(bview);
|
2001-07-24 22:08:49 +00:00
|
|
|
|
|
|
|
|
|
if (inset->isOpen()) {
|
|
|
|
|
inset->close(bview);
|
|
|
|
|
} else {
|
|
|
|
|
inset->open(bview);
|
|
|
|
|
}
|
|
|
|
|
#if 0
|
2001-07-19 08:52:59 +00:00
|
|
|
|
inset->open(bview, !inset->isOpen());
|
2001-07-24 22:08:49 +00:00
|
|
|
|
#endif
|
2001-07-11 12:10:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/* used in setlayout */
|
|
|
|
|
// Asger is not sure we want to do this...
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::makeFontEntriesLayoutSpecific(Buffer const * buf,
|
|
|
|
|
Paragraph * par)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par->layout();
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2001-07-30 11:56:00 +00:00
|
|
|
|
LyXFont layoutfont;
|
2001-11-26 16:42:04 +00:00
|
|
|
|
for (pos_type pos = 0; pos < par->size(); ++pos) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (pos < beginningOfMainBody(buf, par))
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->labelfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->font;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-30 11:56:00 +00:00
|
|
|
|
LyXFont tmpfont = par->getFontSettings(buf->params, pos);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmpfont.reduce(layoutfont);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->setFont(pos, tmpfont);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * LyXText::setLayout(BufferView * bview,
|
2001-07-07 18:19:18 +00:00
|
|
|
|
LyXCursor & cur, LyXCursor & sstart_cur,
|
|
|
|
|
LyXCursor & send_cur,
|
2002-03-02 16:39:54 +00:00
|
|
|
|
string const & layout)
|
2001-04-04 21:47:26 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * endpar = send_cur.par()->next();
|
|
|
|
|
Paragraph * undoendpar = endpar;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (endpar && endpar->getDepth()) {
|
|
|
|
|
while (endpar && endpar->getDepth()) {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
endpar = endpar->next();
|
|
|
|
|
undoendpar = endpar;
|
|
|
|
|
}
|
|
|
|
|
} else if (endpar) {
|
|
|
|
|
endpar = endpar->next(); // because of parindents etc.
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-03-15 15:28:25 +00:00
|
|
|
|
setUndo(bview, Undo::EDIT, sstart_cur.par(), undoendpar);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// ok we have a selection. This is always between sstart_cur
|
|
|
|
|
// and sel_end cursor
|
2001-04-04 21:47:26 +00:00
|
|
|
|
cur = sstart_cur;
|
2002-04-18 14:14:06 +00:00
|
|
|
|
Paragraph * par = sstart_cur.par();
|
|
|
|
|
Paragraph * epar = send_cur.par()->next();
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & lyxlayout =
|
2002-03-02 16:39:54 +00:00
|
|
|
|
textclasslist[bview->buffer()->params.textclass][layout];
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-02-27 14:02:10 +00:00
|
|
|
|
do {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
par->applyLayout(lyxlayout);
|
2002-04-18 14:14:06 +00:00
|
|
|
|
makeFontEntriesLayoutSpecific(bview->buffer(), par);
|
|
|
|
|
Paragraph * fppar = par;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
fppar->params().spaceTop(lyxlayout->fill_top ?
|
2001-07-07 18:19:18 +00:00
|
|
|
|
VSpace(VSpace::VFILL)
|
|
|
|
|
: VSpace(VSpace::NONE));
|
2002-06-24 20:28:12 +00:00
|
|
|
|
fppar->params().spaceBottom(lyxlayout->fill_bottom ?
|
2001-07-07 18:19:18 +00:00
|
|
|
|
VSpace(VSpace::VFILL)
|
|
|
|
|
: VSpace(VSpace::NONE));
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (lyxlayout->margintype == MARGIN_MANUAL)
|
|
|
|
|
par->setLabelWidthString(lyxlayout->labelstring());
|
|
|
|
|
if (lyxlayout->labeltype != LABEL_BIBLIO
|
2000-05-04 08:14:34 +00:00
|
|
|
|
&& fppar->bibkey) {
|
|
|
|
|
delete fppar->bibkey;
|
|
|
|
|
fppar->bibkey = 0;
|
|
|
|
|
}
|
2002-04-18 14:14:06 +00:00
|
|
|
|
cur.par(par);
|
|
|
|
|
par = par->next();
|
|
|
|
|
} while (par != epar);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
|
return endpar;
|
|
|
|
|
}
|
2001-04-04 21:47:26 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// set layout over selection and make a total rebreak of those paragraphs
|
2002-03-02 16:39:54 +00:00
|
|
|
|
void LyXText::setLayout(BufferView * bview, string const & layout)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-05-31 02:23:46 +00:00
|
|
|
|
LyXCursor tmpcursor = cursor; /* store the current cursor */
|
|
|
|
|
|
|
|
|
|
// if there is no selection just set the layout
|
|
|
|
|
// of the current paragraph */
|
|
|
|
|
if (!selection.set()) {
|
|
|
|
|
selection.start = cursor; // dummy selection
|
|
|
|
|
selection.end = cursor;
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * endpar = setLayout(bview, cursor, selection.start,
|
2001-07-07 18:19:18 +00:00
|
|
|
|
selection.end, layout);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
redoParagraphs(bview, selection.start, endpar);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
// we have to reset the selection, because the
|
|
|
|
|
// geometry could have changed
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, selection.start.par(),
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.start.pos(), false);
|
|
|
|
|
selection.cursor = cursor;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
setCursor(bview, selection.end.par(), selection.end.pos(), false);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
updateCounters(bview, cursor.row());
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setSelection(bview);
|
|
|
|
|
setCursor(bview, tmpcursor.par(), tmpcursor.pos(), true);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
// increment depth over selection and
|
|
|
|
|
// make a total rebreak of those paragraphs
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::incDepth(BufferView * bview)
|
2001-05-31 02:23:46 +00:00
|
|
|
|
{
|
|
|
|
|
// If there is no selection, just use the current paragraph
|
|
|
|
|
if (!selection.set()) {
|
|
|
|
|
selection.start = cursor; // dummy selection
|
|
|
|
|
selection.end = cursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We end at the next paragraph with depth 0
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * endpar = selection.end.par()->next();
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * undoendpar = endpar;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (endpar && endpar->getDepth()) {
|
|
|
|
|
while (endpar && endpar->getDepth()) {
|
2001-05-31 02:23:46 +00:00
|
|
|
|
endpar = endpar->next();
|
|
|
|
|
undoendpar = endpar;
|
|
|
|
|
}
|
2001-07-07 18:19:18 +00:00
|
|
|
|
} else if (endpar) {
|
2001-05-31 02:23:46 +00:00
|
|
|
|
endpar = endpar->next(); // because of parindents etc.
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setUndo(bview, Undo::EDIT,
|
|
|
|
|
selection.start.par(), undoendpar);
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
|
|
|
|
LyXCursor tmpcursor = cursor; // store the current cursor
|
|
|
|
|
|
|
|
|
|
// ok we have a selection. This is always between sel_start_cursor
|
|
|
|
|
// and sel_end cursor
|
|
|
|
|
cursor = selection.start;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
bool anything_changed = false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
while (true) {
|
|
|
|
|
// NOTE: you can't change the depth of a bibliography entry
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (cursor.par()->layout()->labeltype != LABEL_BIBLIO) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * prev = cursor.par()->previous();
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
2002-02-28 15:07:11 +00:00
|
|
|
|
if (prev) {
|
|
|
|
|
if (cursor.par()->getDepth()
|
2002-06-24 20:28:12 +00:00
|
|
|
|
< prev->getMaxDepthAfter()) {
|
2002-02-28 15:07:11 +00:00
|
|
|
|
cursor.par()->params().depth(cursor.par()->getDepth() + 1);
|
2002-02-27 11:36:20 +00:00
|
|
|
|
anything_changed = true;
|
|
|
|
|
}
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2001-05-31 02:23:46 +00:00
|
|
|
|
}
|
|
|
|
|
if (cursor.par() == selection.end.par())
|
2001-07-07 18:19:18 +00:00
|
|
|
|
break;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
cursor.par(cursor.par()->next());
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
// if nothing changed set all depth to 0
|
|
|
|
|
if (!anything_changed) {
|
|
|
|
|
cursor = selection.start;
|
|
|
|
|
while (cursor.par() != selection.end.par()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cursor.par()->params().depth(0);
|
2001-05-31 02:23:46 +00:00
|
|
|
|
cursor.par(cursor.par()->next());
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cursor.par()->params().depth(0);
|
2001-05-31 02:23:46 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
redoParagraphs(bview, selection.start, endpar);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
// we have to reset the selection, because the
|
|
|
|
|
// geometry could have changed
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, selection.start.par(), selection.start.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, selection.end.par(), selection.end.pos());
|
|
|
|
|
updateCounters(bview, cursor.row());
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setSelection(bview);
|
|
|
|
|
setCursor(bview, tmpcursor.par(), tmpcursor.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// decrement depth over selection and
|
|
|
|
|
// make a total rebreak of those paragraphs
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::decDepth(BufferView * bview)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// if there is no selection just set the layout
|
|
|
|
|
// of the current paragraph
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set()) {
|
|
|
|
|
selection.start = cursor; // dummy selection
|
|
|
|
|
selection.end = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * endpar = selection.end.par()->next();
|
|
|
|
|
Paragraph * undoendpar = endpar;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (endpar && endpar->getDepth()) {
|
|
|
|
|
while (endpar && endpar->getDepth()) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
endpar = endpar->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
undoendpar = endpar;
|
|
|
|
|
}
|
2001-05-31 02:23:46 +00:00
|
|
|
|
} else if (endpar) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
endpar = endpar->next(); // because of parindents etc.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setUndo(bview, Undo::EDIT,
|
|
|
|
|
selection.start.par(), undoendpar);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LyXCursor tmpcursor = cursor; // store the current cursor
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// ok we have a selection. This is always between sel_start_cursor
|
|
|
|
|
// and sel_end cursor
|
2001-05-31 02:23:46 +00:00
|
|
|
|
cursor = selection.start;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
while (true) {
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (cursor.par()->params().depth()) {
|
|
|
|
|
cursor.par()->params()
|
|
|
|
|
.depth(cursor.par()->params().depth() - 1);
|
|
|
|
|
}
|
|
|
|
|
if (cursor.par() == selection.end.par()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2001-03-09 00:56:42 +00:00
|
|
|
|
cursor.par(cursor.par()->next());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
redoParagraphs(bview, selection.start, endpar);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// we have to reset the selection, because the
|
|
|
|
|
// geometry could have changed
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, selection.start.par(),
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.start.pos());
|
|
|
|
|
selection.cursor = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, selection.end.par(), selection.end.pos());
|
|
|
|
|
updateCounters(bview, cursor.row());
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setSelection(bview);
|
|
|
|
|
setCursor(bview, tmpcursor.par(), tmpcursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// set font over selection and make a total rebreak of those paragraphs
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setFont(BufferView * bview, LyXFont const & font, bool toggleall)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// if there is no selection just set the current_font
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Determine basis font
|
|
|
|
|
LyXFont layoutfont;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (cursor.pos() < beginningOfMainBody(bview->buffer(),
|
2002-03-21 17:27:08 +00:00
|
|
|
|
cursor.par())) {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
layoutfont = getLabelFont(bview->buffer(),
|
|
|
|
|
cursor.par());
|
2001-08-03 13:09:59 +00:00
|
|
|
|
} else {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
layoutfont = getLayoutFont(bview->buffer(),
|
|
|
|
|
cursor.par());
|
2001-08-03 13:09:59 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Update current font
|
2002-03-21 17:27:08 +00:00
|
|
|
|
real_current_font.update(font,
|
2001-08-11 18:31:14 +00:00
|
|
|
|
bview->buffer()->params.language,
|
|
|
|
|
toggleall);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Reduce to implicit settings
|
|
|
|
|
current_font = real_current_font;
|
|
|
|
|
current_font.reduce(layoutfont);
|
|
|
|
|
// And resolve it completely
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#ifndef INHERIT_LANGUAGE
|
|
|
|
|
real_current_font.realize(layoutfont);
|
|
|
|
|
#else
|
2001-07-27 12:03:36 +00:00
|
|
|
|
real_current_font.realize(layoutfont,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
bview->buffer()->params.language);
|
2001-08-11 18:31:14 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LyXCursor tmpcursor = cursor; // store the current cursor
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// ok we have a selection. This is always between sel_start_cursor
|
|
|
|
|
// and sel_end cursor
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setUndo(bview, Undo::EDIT,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.start.par(), selection.end.par()->next());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
freezeUndo();
|
2001-05-31 02:23:46 +00:00
|
|
|
|
cursor = selection.start;
|
|
|
|
|
while (cursor.par() != selection.end.par() ||
|
2002-05-29 16:21:03 +00:00
|
|
|
|
cursor.pos() < selection.end.pos())
|
2001-08-03 13:09:59 +00:00
|
|
|
|
{
|
2001-05-03 14:31:33 +00:00
|
|
|
|
if (cursor.pos() < cursor.par()->size()) {
|
2002-05-23 09:21:32 +00:00
|
|
|
|
// an open footnote should behave like a closed one
|
2001-07-07 18:19:18 +00:00
|
|
|
|
setCharFont(bview, cursor.par(), cursor.pos(),
|
|
|
|
|
font, toggleall);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.pos(cursor.pos() + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.pos(0);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
cursor.par(cursor.par()->next());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
unFreezeUndo();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
redoParagraphs(bview, selection.start, selection.end.par()->next());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// we have to reset the selection, because the
|
2001-12-11 14:33:52 +00:00
|
|
|
|
// geometry could have changed, but we keep
|
|
|
|
|
// it for user convenience
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, selection.start.par(), selection.start.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, selection.end.par(), selection.end.pos());
|
|
|
|
|
setSelection(bview);
|
|
|
|
|
setCursor(bview, tmpcursor.par(), tmpcursor.pos(), true,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
tmpcursor.boundary());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::redoHeightOfParagraph(BufferView * bview, LyXCursor const & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
|
Row * tmprow = cur.row();
|
2000-09-29 18:44:07 +00:00
|
|
|
|
int y = cur.y() - tmprow->baseline();
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setHeightOfRow(bview, tmprow);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-07 18:02:19 +00:00
|
|
|
|
while (tmprow->previous()
|
|
|
|
|
&& tmprow->previous()->par() == tmprow->par()) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
tmprow = tmprow->previous();
|
|
|
|
|
y -= tmprow->height();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setHeightOfRow(bview, tmprow);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// we can set the refreshing parameters now
|
2001-07-06 15:57:54 +00:00
|
|
|
|
status(bview, LyXText::NEED_MORE_REFRESH);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
refresh_y = y;
|
|
|
|
|
refresh_row = tmprow;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cur.par(), cur.pos(), false, cursor.boundary());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::redoDrawingOfParagraph(BufferView * bview, LyXCursor const & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
|
Row * tmprow = cur.row();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
|
int y = cur.y() - tmprow->baseline();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setHeightOfRow(bview, tmprow);
|
2001-07-03 15:19:04 +00:00
|
|
|
|
|
2001-07-07 18:02:19 +00:00
|
|
|
|
while (tmprow->previous()
|
|
|
|
|
&& tmprow->previous()->par() == tmprow->par()) {
|
2001-07-03 15:19:04 +00:00
|
|
|
|
tmprow = tmprow->previous();
|
|
|
|
|
y -= tmprow->height();
|
|
|
|
|
}
|
2001-07-07 18:02:19 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// we can set the refreshing parameters now
|
2001-07-06 15:57:54 +00:00
|
|
|
|
if (status_ == LyXText::UNCHANGED || y < refresh_y) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
refresh_y = y;
|
|
|
|
|
refresh_row = tmprow;
|
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
status(bview, LyXText::NEED_MORE_REFRESH);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cur.par(), cur.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// deletes and inserts again all paragaphs between the cursor
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// and the specified par
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// This function is needed after SetLayout and SetFont etc.
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
Paragraph const * endpar) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
Row * tmprow2;
|
2001-07-03 15:19:04 +00:00
|
|
|
|
Paragraph * tmppar = 0;
|
|
|
|
|
Paragraph * first_phys_par = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
Row * tmprow = cur.row();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
|
int y = cur.y() - tmprow->baseline();
|
2001-07-03 15:19:04 +00:00
|
|
|
|
|
|
|
|
|
if (!tmprow->previous()) {
|
|
|
|
|
// a trick/hack for UNDO
|
2001-12-14 11:55:58 +00:00
|
|
|
|
// This is needed because in an UNDO/REDO we could have changed
|
2002-01-13 00:33:21 +00:00
|
|
|
|
// the ownerParagrah() so the paragraph inside the row is NOT
|
2001-12-14 11:55:58 +00:00
|
|
|
|
// my really first par anymore. Got it Lars ;) (Jug 20011206)
|
2002-01-13 00:33:21 +00:00
|
|
|
|
first_phys_par = ownerParagraph();
|
2001-07-03 15:19:04 +00:00
|
|
|
|
} else {
|
|
|
|
|
first_phys_par = tmprow->par();
|
|
|
|
|
while (tmprow->previous()
|
2001-08-02 14:55:06 +00:00
|
|
|
|
&& tmprow->previous()->par() == first_phys_par)
|
|
|
|
|
{
|
2001-07-03 15:19:04 +00:00
|
|
|
|
tmprow = tmprow->previous();
|
|
|
|
|
y -= tmprow->height();
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-12-11 14:33:52 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// we can set the refreshing parameters now
|
2001-07-06 15:57:54 +00:00
|
|
|
|
status(bview, LyXText::NEED_MORE_REFRESH);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
refresh_y = y;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
refresh_row = tmprow->previous(); /* the real refresh row will
|
2002-03-21 17:27:08 +00:00
|
|
|
|
be deleted, so I store
|
|
|
|
|
the previous here */
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// remove it
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (tmprow->next())
|
|
|
|
|
tmppar = tmprow->next()->par();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-10-02 16:21:10 +00:00
|
|
|
|
tmppar = 0;
|
2001-12-14 11:55:58 +00:00
|
|
|
|
while (tmprow->next() && tmppar != endpar) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
removeRow(tmprow->next());
|
2001-12-11 14:33:52 +00:00
|
|
|
|
if (tmprow->next()) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
tmppar = tmprow->next()->par();
|
2001-12-11 14:33:52 +00:00
|
|
|
|
} else {
|
1999-10-02 16:21:10 +00:00
|
|
|
|
tmppar = 0;
|
2001-12-11 14:33:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// remove the first one
|
2000-06-08 23:16:16 +00:00
|
|
|
|
tmprow2 = tmprow; /* this is because tmprow->previous()
|
2002-03-21 17:27:08 +00:00
|
|
|
|
can be 0 */
|
2000-06-08 23:16:16 +00:00
|
|
|
|
tmprow = tmprow->previous();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
removeRow(tmprow2);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmppar = first_phys_par;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
if (tmppar) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
insertParagraph(bview, tmppar, tmprow);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (!tmprow) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmprow = firstrow;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
|
|
|
|
while (tmprow->next()
|
|
|
|
|
&& tmprow->next()->par() == tmppar) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
tmprow = tmprow->next();
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2001-03-09 00:56:42 +00:00
|
|
|
|
tmppar = tmppar->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
} while (tmppar && tmppar != endpar);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// this is because of layout changes
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (refresh_row) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
refresh_y -= refresh_row->height();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
setHeightOfRow(bview, refresh_row);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
} else {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
refresh_row = firstrow;
|
|
|
|
|
refresh_y = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
setHeightOfRow(bview, refresh_row);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (tmprow && tmprow->next())
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setHeightOfRow(bview, tmprow->next());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-01 22:17:09 +00:00
|
|
|
|
void LyXText::fullRebreak(BufferView * bview)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-21 15:07:57 +00:00
|
|
|
|
if (!firstrow) {
|
|
|
|
|
init(bview);
|
2002-05-01 22:17:09 +00:00
|
|
|
|
return;
|
2000-06-21 15:07:57 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (need_break_row) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
breakAgain(bview, need_break_row);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
need_break_row = 0;
|
2002-05-01 22:17:09 +00:00
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// important for the screen
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2002-05-29 13:28:11 +00:00
|
|
|
|
// the cursor set functions have a special mechanism. When they
|
|
|
|
|
// realize, that you left an empty paragraph, they will delete it.
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// They also delete the corresponding row
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// need the selection cursor:
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setSelection(BufferView * bview)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-05-31 02:23:46 +00:00
|
|
|
|
bool const lsel = selection.set();
|
2001-02-14 08:38:21 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set()) {
|
|
|
|
|
last_sel_cursor = selection.cursor;
|
|
|
|
|
selection.start = selection.cursor;
|
|
|
|
|
selection.end = selection.cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.set(true);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// first the toggling area
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (cursor.y() < last_sel_cursor.y()
|
|
|
|
|
|| (cursor.y() == last_sel_cursor.y()
|
2001-07-07 18:19:18 +00:00
|
|
|
|
&& cursor.x() < last_sel_cursor.x())) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
toggle_end_cursor = last_sel_cursor;
|
|
|
|
|
toggle_cursor = cursor;
|
2000-05-20 21:37:05 +00:00
|
|
|
|
} else {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
toggle_end_cursor = cursor;
|
|
|
|
|
toggle_cursor = last_sel_cursor;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
last_sel_cursor = cursor;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// and now the whole selection
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (selection.cursor.par() == cursor.par())
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (selection.cursor.pos() < cursor.pos()) {
|
|
|
|
|
selection.end = cursor;
|
|
|
|
|
selection.start = selection.cursor;
|
|
|
|
|
} else {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.end = selection.cursor;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
selection.start = cursor;
|
|
|
|
|
}
|
2001-05-31 02:23:46 +00:00
|
|
|
|
else if (selection.cursor.y() < cursor.y() ||
|
2001-07-07 18:19:18 +00:00
|
|
|
|
(selection.cursor.y() == cursor.y()
|
|
|
|
|
&& selection.cursor.x() < cursor.x())) {
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.end = cursor;
|
|
|
|
|
selection.start = selection.cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.end = selection.cursor;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.start = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// a selection with no contents is not a selection
|
2002-03-21 17:27:08 +00:00
|
|
|
|
if (selection.start.par() == selection.end.par() &&
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.start.pos() == selection.end.pos())
|
|
|
|
|
selection.set(false);
|
2001-02-14 08:38:21 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (inset_owner && (selection.set() || lsel))
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset_owner->setUpdateStatus(bview, InsetText::SELECTION);
|
2000-05-20 21:37:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-12 10:41:25 +00:00
|
|
|
|
string const LyXText::selectionAsString(Buffer const * buffer,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
bool label) const
|
2000-05-20 21:37:05 +00:00
|
|
|
|
{
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set()) return string();
|
2000-05-20 21:37:05 +00:00
|
|
|
|
string result;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-05-20 21:37:05 +00:00
|
|
|
|
// Special handling if the whole selection is within one paragraph
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (selection.start.par() == selection.end.par()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
result += selection.start.par()->asString(buffer,
|
2001-07-07 18:19:18 +00:00
|
|
|
|
selection.start.pos(),
|
2001-09-12 10:41:25 +00:00
|
|
|
|
selection.end.pos(),
|
|
|
|
|
label);
|
2000-05-20 21:37:05 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-05-20 21:37:05 +00:00
|
|
|
|
// The selection spans more than one paragraph
|
|
|
|
|
|
|
|
|
|
// First paragraph in selection
|
2001-06-25 00:06:33 +00:00
|
|
|
|
result += selection.start.par()->asString(buffer,
|
2001-07-07 18:19:18 +00:00
|
|
|
|
selection.start.pos(),
|
2001-09-12 10:41:25 +00:00
|
|
|
|
selection.start.par()->size(),
|
|
|
|
|
label)
|
2001-03-11 00:21:13 +00:00
|
|
|
|
+ "\n\n";
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-05-20 21:37:05 +00:00
|
|
|
|
// The paragraphs in between (if any)
|
2001-05-31 02:23:46 +00:00
|
|
|
|
LyXCursor tmpcur(selection.start);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
tmpcur.par(tmpcur.par()->next());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
while (tmpcur.par() != selection.end.par()) {
|
2001-07-07 18:19:18 +00:00
|
|
|
|
result += tmpcur.par()->asString(buffer, 0,
|
2001-09-12 10:41:25 +00:00
|
|
|
|
tmpcur.par()->size(),
|
|
|
|
|
label) + "\n\n";
|
2001-07-07 18:19:18 +00:00
|
|
|
|
tmpcur.par(tmpcur.par()->next());
|
2000-05-20 21:37:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Last paragraph in selection
|
2001-07-07 18:19:18 +00:00
|
|
|
|
result += selection.end.par()->asString(buffer, 0,
|
2001-09-12 10:41:25 +00:00
|
|
|
|
selection.end.pos(), label);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-05-20 21:37:05 +00:00
|
|
|
|
return result;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-01 15:42:53 +00:00
|
|
|
|
void LyXText::clearSelection() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.set(false);
|
|
|
|
|
selection.mark(false);
|
2001-12-04 16:10:19 +00:00
|
|
|
|
last_sel_cursor = selection.end = selection.start = selection.cursor = cursor;
|
2002-03-20 10:36:03 +00:00
|
|
|
|
// reset this in the bv_owner!
|
|
|
|
|
if (bv_owner && bv_owner->text)
|
|
|
|
|
bv_owner->text->xsel_cache.set(false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::cursorHome(BufferView * bview) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), cursor.row()->pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::cursorEnd(BufferView * bview) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (!cursor.row()->next()
|
|
|
|
|
|| cursor.row()->next()->par() != cursor.row()->par()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), rowLast(cursor.row()) + 1);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
} else {
|
2001-03-11 00:21:13 +00:00
|
|
|
|
if (cursor.par()->size() &&
|
2001-06-25 00:06:33 +00:00
|
|
|
|
(cursor.par()->getChar(rowLast(cursor.row())) == ' '
|
2001-07-07 18:19:18 +00:00
|
|
|
|
|| cursor.par()->isNewline(rowLast(cursor.row())))) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), rowLast(cursor.row()));
|
2001-07-07 18:19:18 +00:00
|
|
|
|
} else {
|
|
|
|
|
setCursor(bview,cursor.par(),
|
|
|
|
|
rowLast(cursor.row()) + 1);
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::cursorTop(BufferView * bview) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-03-09 00:56:42 +00:00
|
|
|
|
while (cursor.par()->previous())
|
|
|
|
|
cursor.par(cursor.par()->previous());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::cursorBottom(BufferView * bview) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-03-09 00:56:42 +00:00
|
|
|
|
while (cursor.par()->next())
|
|
|
|
|
cursor.par(cursor.par()->next());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), cursor.par()->size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::toggleFree(BufferView * bview,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
LyXFont const & font, bool toggleall)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
// If the mask is completely neutral, tell user
|
2000-02-17 19:59:08 +00:00
|
|
|
|
if (font == LyXFont(LyXFont::ALL_IGNORE)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Could only happen with user style
|
2001-04-24 17:33:01 +00:00
|
|
|
|
bview->owner()->message(_("No font change defined. Use Character under the Layout menu to define font change."));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try implicit word selection
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// If there is a change in the language the implicit word selection
|
2000-04-24 20:58:23 +00:00
|
|
|
|
// is disabled.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
LyXCursor resetCursor = cursor;
|
2000-10-09 12:30:52 +00:00
|
|
|
|
bool implicitSelection = (font.language() == ignore_language
|
2002-03-21 17:27:08 +00:00
|
|
|
|
&& font.number() == LyXFont::IGNORE)
|
2001-07-27 16:07:33 +00:00
|
|
|
|
? selectWordWhenUnderCursor(bview, WHOLE_WORD_STRICT) : false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Set font
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setFont(bview, font, toggleall);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// Implicit selections are cleared afterwards
|
|
|
|
|
//and cursor is set to the original position.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (implicitSelection) {
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
cursor = resetCursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), cursor.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-02-14 08:38:21 +00:00
|
|
|
|
if (inset_owner)
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset_owner->setUpdateStatus(bview, InsetText::CURSOR_PAR);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-10-18 16:17:46 +00:00
|
|
|
|
string LyXText::getStringToIndex(BufferView * bview)
|
2001-07-30 10:50:37 +00:00
|
|
|
|
{
|
|
|
|
|
string idxstring;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-30 10:50:37 +00:00
|
|
|
|
// Try implicit word selection
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// If there is a change in the language the implicit word selection
|
2001-07-30 10:50:37 +00:00
|
|
|
|
// is disabled.
|
|
|
|
|
LyXCursor resetCursor = cursor;
|
|
|
|
|
bool implicitSelection = selectWordWhenUnderCursor(bview, PREVIOUS_WORD);
|
|
|
|
|
|
|
|
|
|
if (!selection.set()) {
|
|
|
|
|
bview->owner()->message(_("Nothing to index!"));
|
|
|
|
|
return string();
|
|
|
|
|
}
|
|
|
|
|
if (selection.start.par() != selection.end.par()) {
|
|
|
|
|
bview->owner()->message(_("Cannot index more than one paragraph!"));
|
|
|
|
|
return string();
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-12 10:41:25 +00:00
|
|
|
|
idxstring = selectionAsString(bview->buffer(), false);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-30 10:50:37 +00:00
|
|
|
|
// Implicit selections are cleared afterwards
|
|
|
|
|
//and cursor is set to the original position.
|
|
|
|
|
if (implicitSelection) {
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2001-07-30 10:50:37 +00:00
|
|
|
|
cursor = resetCursor;
|
|
|
|
|
setCursor(bview, cursor.par(), cursor.pos());
|
|
|
|
|
selection.cursor = cursor;
|
|
|
|
|
}
|
|
|
|
|
return idxstring;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-18 16:17:46 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
pos_type LyXText::beginningOfMainBody(Buffer const * /*buf*/,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph const * par) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (par->layout()->labeltype != LABEL_MANUAL)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
else
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return par->beginningOfMainBody();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-29 13:28:11 +00:00
|
|
|
|
// the DTP switches for paragraphs. LyX will store them in the first
|
|
|
|
|
// physicla paragraph. When a paragraph is broken, the top settings rest,
|
|
|
|
|
// the bottom settings are given to the new one. So I can make shure,
|
|
|
|
|
// they do not duplicate themself and you cannnot make dirty things with
|
|
|
|
|
// them!
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setParagraph(BufferView * bview,
|
2000-06-12 11:27:15 +00:00
|
|
|
|
bool line_top, bool line_bottom,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
bool pagebreak_top, bool pagebreak_bottom,
|
2000-01-13 16:28:54 +00:00
|
|
|
|
VSpace const & space_top,
|
|
|
|
|
VSpace const & space_bottom,
|
2001-10-18 16:17:46 +00:00
|
|
|
|
Spacing const & spacing,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
LyXAlignment align,
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string labelwidthstring,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
bool noindent)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXCursor tmpcursor = cursor;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set()) {
|
|
|
|
|
selection.start = cursor;
|
|
|
|
|
selection.end = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// make sure that the depth behind the selection are restored, too
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * endpar = selection.end.par()->next();
|
|
|
|
|
Paragraph * undoendpar = endpar;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (endpar && endpar->getDepth()) {
|
|
|
|
|
while (endpar && endpar->getDepth()) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
endpar = endpar->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
undoendpar = endpar;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (endpar) {
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// because of parindents etc.
|
|
|
|
|
endpar = endpar->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setUndo(bview, Undo::EDIT, selection.start.par(), undoendpar);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * tmppar = selection.end.par();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
while (tmppar != selection.start.par()->previous()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, tmppar, 0);
|
2001-07-06 15:57:54 +00:00
|
|
|
|
status(bview, LyXText::NEED_MORE_REFRESH);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
refresh_row = cursor.row();
|
|
|
|
|
refresh_y = cursor.y() - cursor.row()->baseline();
|
2001-07-07 18:19:18 +00:00
|
|
|
|
cursor.par()->params().lineTop(line_top);
|
|
|
|
|
cursor.par()->params().lineBottom(line_bottom);
|
|
|
|
|
cursor.par()->params().pagebreakTop(pagebreak_top);
|
|
|
|
|
cursor.par()->params().pagebreakBottom(pagebreak_bottom);
|
|
|
|
|
cursor.par()->params().spaceTop(space_top);
|
|
|
|
|
cursor.par()->params().spaceBottom(space_bottom);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
cursor.par()->params().spacing(spacing);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// does the layout allow the new alignment?
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = cursor.par()->layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (align == LYX_ALIGN_LAYOUT)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
align = layout->align;
|
|
|
|
|
if (align & layout->alignpossible) {
|
|
|
|
|
if (align == layout->align)
|
2001-07-07 18:19:18 +00:00
|
|
|
|
cursor.par()->params().align(LYX_ALIGN_LAYOUT);
|
|
|
|
|
else
|
|
|
|
|
cursor.par()->params().align(align);
|
|
|
|
|
}
|
|
|
|
|
cursor.par()->setLabelWidthString(labelwidthstring);
|
|
|
|
|
cursor.par()->params().noindent(noindent);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
tmppar = cursor.par()->previous();
|
1999-11-04 01:40:20 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
redoParagraphs(bview, selection.start, endpar);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, selection.start.par(), selection.start.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, selection.end.par(), selection.end.pos());
|
|
|
|
|
setSelection(bview);
|
|
|
|
|
setCursor(bview, tmpcursor.par(), tmpcursor.pos());
|
2000-08-01 09:35:42 +00:00
|
|
|
|
if (inset_owner)
|
2001-07-07 18:19:18 +00:00
|
|
|
|
bview->updateInset(inset_owner, true);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-03-10 13:22:20 +00:00
|
|
|
|
char loweralphaCounter(int n)
|
|
|
|
|
{
|
|
|
|
|
if (n < 1 || n > 26)
|
|
|
|
|
return '?';
|
|
|
|
|
else
|
|
|
|
|
return 'a' + n - 1;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-18 17:45:27 +00:00
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
inline
|
2000-03-10 13:22:20 +00:00
|
|
|
|
char alphaCounter(int n)
|
|
|
|
|
{
|
|
|
|
|
if (n < 1 || n > 26)
|
|
|
|
|
return '?';
|
|
|
|
|
else
|
|
|
|
|
return 'A' + n - 1;
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-18 17:45:27 +00:00
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
inline
|
2000-03-10 13:22:20 +00:00
|
|
|
|
char hebrewCounter(int n)
|
|
|
|
|
{
|
|
|
|
|
static const char hebrew[22] = {
|
|
|
|
|
'<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>',
|
2002-03-21 17:27:08 +00:00
|
|
|
|
'<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>',
|
2000-03-10 13:22:20 +00:00
|
|
|
|
'<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>'
|
|
|
|
|
};
|
|
|
|
|
if (n < 1 || n > 22)
|
|
|
|
|
return '?';
|
|
|
|
|
else
|
|
|
|
|
return hebrew[n-1];
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-18 17:45:27 +00:00
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
inline
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const romanCounter(int n)
|
2000-03-10 13:22:20 +00:00
|
|
|
|
{
|
|
|
|
|
static char const * roman[20] = {
|
|
|
|
|
"i", "ii", "iii", "iv", "v",
|
|
|
|
|
"vi", "vii", "viii", "ix", "x",
|
|
|
|
|
"xi", "xii", "xiii", "xiv", "xv",
|
|
|
|
|
"xvi", "xvii", "xviii", "xix", "xx"
|
|
|
|
|
};
|
|
|
|
|
if (n < 1 || n > 20)
|
|
|
|
|
return "??";
|
|
|
|
|
else
|
|
|
|
|
return roman[n-1];
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
2000-07-18 17:45:27 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// set the counter of a paragraph. This includes the labels
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-03-02 16:39:54 +00:00
|
|
|
|
LyXTextClass const & textclass = textclasslist[buf->params.textclass];
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par->layout();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// copy the prev-counters to this one,
|
|
|
|
|
// unless this is the first paragraph
|
2001-07-07 11:49:07 +00:00
|
|
|
|
if (par->previous()) {
|
2000-01-24 18:34:46 +00:00
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->setCounter(i, par->previous()->getFirstCounter(i));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().appendix(par->previous()->params().appendix());
|
|
|
|
|
if (!par->params().appendix() && par->params().startOfAppendix()) {
|
2001-07-07 18:19:18 +00:00
|
|
|
|
par->params().appendix(true);
|
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
|
par->setCounter(i, 0);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par->enumdepth = par->previous()->enumdepth;
|
|
|
|
|
par->itemdepth = par->previous()->itemdepth;
|
2000-07-18 17:45:27 +00:00
|
|
|
|
} else {
|
2000-01-24 18:34:46 +00:00
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
par->setCounter(i, 0);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().appendix(par->params().startOfAppendix());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
par->enumdepth = 0;
|
|
|
|
|
par->itemdepth = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Maybe we have to increment the enumeration depth.
|
|
|
|
|
* BUT, enumeration in a footnote is considered in isolation from its
|
|
|
|
|
* surrounding paragraph so don't increment if this is the
|
|
|
|
|
* first line of the footnote
|
|
|
|
|
* AND, bibliographies can't have their depth changed ie. they
|
|
|
|
|
* are always of depth 0
|
|
|
|
|
*/
|
2001-03-09 00:56:42 +00:00
|
|
|
|
if (par->previous()
|
2001-06-25 00:06:33 +00:00
|
|
|
|
&& par->previous()->getDepth() < par->getDepth()
|
2002-06-24 20:28:12 +00:00
|
|
|
|
&& par->previous()->layout()->labeltype == LABEL_COUNTER_ENUMI
|
1999-09-27 18:44:28 +00:00
|
|
|
|
&& par->enumdepth < 3
|
2002-06-24 20:28:12 +00:00
|
|
|
|
&& layout->labeltype != LABEL_BIBLIO) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
par->enumdepth++;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// Maybe we have to decrement the enumeration depth, see note above
|
2001-03-09 00:56:42 +00:00
|
|
|
|
if (par->previous()
|
2001-06-25 00:06:33 +00:00
|
|
|
|
&& par->previous()->getDepth() > par->getDepth()
|
2002-06-24 20:28:12 +00:00
|
|
|
|
&& layout->labeltype != LABEL_BIBLIO) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->enumdepth = par->depthHook(par->getDepth())->enumdepth;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
par->setCounter(6 + par->enumdepth,
|
2001-07-07 18:19:18 +00:00
|
|
|
|
par->depthHook(par->getDepth())->getCounter(6 + par->enumdepth));
|
2002-05-29 13:28:11 +00:00
|
|
|
|
// reset the counters.A depth change is like a breaking layout
|
2000-01-24 18:34:46 +00:00
|
|
|
|
for (int i = 6 + par->enumdepth + 1; i < 10; ++i)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
par->setCounter(i, 0);
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (!par->params().labelString().empty()) {
|
|
|
|
|
par->params().labelString(string());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->margintype == MARGIN_MANUAL) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->params().labelWidthString().empty()) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
par->setLabelWidthString(layout->labelstring());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-02-29 02:19:17 +00:00
|
|
|
|
} else {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->setLabelWidthString(string());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// is it a layout that has an automatic label?
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->labeltype >= LABEL_COUNTER_CHAPTER) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
int i = layout->labeltype - LABEL_COUNTER_CHAPTER;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (i >= 0 && i<= buf->params.secnumdepth) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
par->incCounter(i); // increment the counter
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Is there a label? Useful for Chapter layout
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (!par->params().appendix()) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (!layout->labelstring().empty())
|
|
|
|
|
par->params().labelString(layout->labelstring());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().labelString(string());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
} else {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (!layout->labelstring_appendix().empty())
|
|
|
|
|
par->params().labelString(layout->labelstring_appendix());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().labelString(string());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-03-08 01:45:25 +00:00
|
|
|
|
|
2001-07-13 14:03:48 +00:00
|
|
|
|
ostringstream s;
|
2000-09-18 17:39:21 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (!par->params().appendix()) {
|
2000-07-17 18:27:53 +00:00
|
|
|
|
switch (2 * LABEL_COUNTER_CHAPTER -
|
1999-11-04 01:40:20 +00:00
|
|
|
|
textclass.maxcounter() + i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LABEL_COUNTER_CHAPTER:
|
2000-03-08 01:45:25 +00:00
|
|
|
|
s << par->getCounter(i);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LABEL_COUNTER_SECTION:
|
2000-03-08 01:45:25 +00:00
|
|
|
|
s << par->getCounter(i - 1) << '.'
|
2001-07-07 18:19:18 +00:00
|
|
|
|
<< par->getCounter(i);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LABEL_COUNTER_SUBSECTION:
|
2000-03-08 01:45:25 +00:00
|
|
|
|
s << par->getCounter(i - 2) << '.'
|
|
|
|
|
<< par->getCounter(i - 1) << '.'
|
|
|
|
|
<< par->getCounter(i);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LABEL_COUNTER_SUBSUBSECTION:
|
2000-03-08 01:45:25 +00:00
|
|
|
|
s << par->getCounter(i - 3) << '.'
|
|
|
|
|
<< par->getCounter(i - 2) << '.'
|
|
|
|
|
<< par->getCounter(i - 1) << '.'
|
|
|
|
|
<< par->getCounter(i);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LABEL_COUNTER_PARAGRAPH:
|
2000-03-08 01:45:25 +00:00
|
|
|
|
s << par->getCounter(i - 4) << '.'
|
|
|
|
|
<< par->getCounter(i - 3) << '.'
|
|
|
|
|
<< par->getCounter(i - 2) << '.'
|
|
|
|
|
<< par->getCounter(i - 1) << '.'
|
|
|
|
|
<< par->getCounter(i);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LABEL_COUNTER_SUBPARAGRAPH:
|
2000-03-08 01:45:25 +00:00
|
|
|
|
s << par->getCounter(i - 5) << '.'
|
|
|
|
|
<< par->getCounter(i - 4) << '.'
|
|
|
|
|
<< par->getCounter(i - 3) << '.'
|
|
|
|
|
<< par->getCounter(i - 2) << '.'
|
|
|
|
|
<< par->getCounter(i - 1) << '.'
|
|
|
|
|
<< par->getCounter(i);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2000-07-17 18:27:53 +00:00
|
|
|
|
// Can this ever be reached? And in the
|
|
|
|
|
// case it is, how can this be correct?
|
|
|
|
|
// (Lgb)
|
2000-03-08 01:45:25 +00:00
|
|
|
|
s << par->getCounter(i) << '.';
|
2002-03-21 17:27:08 +00:00
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-03-08 01:45:25 +00:00
|
|
|
|
} else { // appendix
|
2000-07-17 18:27:53 +00:00
|
|
|
|
switch (2 * LABEL_COUNTER_CHAPTER - textclass.maxcounter() + i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LABEL_COUNTER_CHAPTER:
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (par->isRightToLeftPar(buf->params))
|
2000-03-10 13:22:20 +00:00
|
|
|
|
s << hebrewCounter(par->getCounter(i));
|
2000-04-10 21:40:13 +00:00
|
|
|
|
else
|
|
|
|
|
s << alphaCounter(par->getCounter(i));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LABEL_COUNTER_SECTION:
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (par->isRightToLeftPar(buf->params))
|
2000-03-10 13:22:20 +00:00
|
|
|
|
s << hebrewCounter(par->getCounter(i - 1));
|
2000-04-10 21:40:13 +00:00
|
|
|
|
else
|
|
|
|
|
s << alphaCounter(par->getCounter(i - 1));
|
2000-03-10 13:22:20 +00:00
|
|
|
|
|
|
|
|
|
s << '.'
|
2000-03-08 01:45:25 +00:00
|
|
|
|
<< par->getCounter(i);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LABEL_COUNTER_SUBSECTION:
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (par->isRightToLeftPar(buf->params))
|
2000-03-10 13:22:20 +00:00
|
|
|
|
s << hebrewCounter(par->getCounter(i - 2));
|
2000-04-10 21:40:13 +00:00
|
|
|
|
else
|
|
|
|
|
s << alphaCounter(par->getCounter(i - 2));
|
2000-03-10 13:22:20 +00:00
|
|
|
|
|
|
|
|
|
s << '.'
|
2000-03-08 01:45:25 +00:00
|
|
|
|
<< par->getCounter(i-1) << '.'
|
|
|
|
|
<< par->getCounter(i);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LABEL_COUNTER_SUBSUBSECTION:
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (par->isRightToLeftPar(buf->params))
|
2000-03-10 13:22:20 +00:00
|
|
|
|
s << hebrewCounter(par->getCounter(i-3));
|
2000-04-10 21:40:13 +00:00
|
|
|
|
else
|
|
|
|
|
s << alphaCounter(par->getCounter(i-3));
|
2000-03-10 13:22:20 +00:00
|
|
|
|
|
|
|
|
|
s << '.'
|
2000-03-08 01:45:25 +00:00
|
|
|
|
<< par->getCounter(i-2) << '.'
|
|
|
|
|
<< par->getCounter(i-1) << '.'
|
|
|
|
|
<< par->getCounter(i);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LABEL_COUNTER_PARAGRAPH:
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (par->isRightToLeftPar(buf->params))
|
2000-03-10 13:22:20 +00:00
|
|
|
|
s << hebrewCounter(par->getCounter(i-4));
|
2000-04-10 21:40:13 +00:00
|
|
|
|
else
|
|
|
|
|
s << alphaCounter(par->getCounter(i-4));
|
2000-03-10 13:22:20 +00:00
|
|
|
|
|
|
|
|
|
s << '.'
|
2000-03-08 01:45:25 +00:00
|
|
|
|
<< par->getCounter(i-3) << '.'
|
|
|
|
|
<< par->getCounter(i-2) << '.'
|
|
|
|
|
<< par->getCounter(i-1) << '.'
|
|
|
|
|
<< par->getCounter(i);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LABEL_COUNTER_SUBPARAGRAPH:
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (par->isRightToLeftPar(buf->params))
|
2000-03-10 13:22:20 +00:00
|
|
|
|
s << hebrewCounter(par->getCounter(i-5));
|
2000-04-10 21:40:13 +00:00
|
|
|
|
else
|
|
|
|
|
s << alphaCounter(par->getCounter(i-5));
|
2000-03-10 13:22:20 +00:00
|
|
|
|
|
|
|
|
|
s << '.'
|
2000-03-08 01:45:25 +00:00
|
|
|
|
<< par->getCounter(i-4) << '.'
|
|
|
|
|
<< par->getCounter(i-3) << '.'
|
|
|
|
|
<< par->getCounter(i-2) << '.'
|
|
|
|
|
<< par->getCounter(i-1) << '.'
|
|
|
|
|
<< par->getCounter(i);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2000-03-08 01:45:25 +00:00
|
|
|
|
// Can this ever be reached? And in the
|
|
|
|
|
// case it is, how can this be correct?
|
|
|
|
|
// (Lgb)
|
2000-07-17 18:27:53 +00:00
|
|
|
|
s << par->getCounter(i) << '.';
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-09-18 17:39:21 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().labelString(par->params().labelString() +s.str().c_str());
|
2000-03-08 01:45:25 +00:00
|
|
|
|
// We really want to remove the c_str as soon as
|
|
|
|
|
// possible...
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
for (i++; i < 10; ++i) {
|
|
|
|
|
// reset the following counters
|
1999-09-27 18:44:28 +00:00
|
|
|
|
par->setCounter(i, 0);
|
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
} else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
|
2000-01-13 16:28:54 +00:00
|
|
|
|
for (i++; i < 10; ++i) {
|
|
|
|
|
// reset the following counters
|
1999-09-27 18:44:28 +00:00
|
|
|
|
par->setCounter(i, 0);
|
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
} else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
par->incCounter(i + par->enumdepth);
|
|
|
|
|
int number = par->getCounter(i + par->enumdepth);
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2001-07-13 14:03:48 +00:00
|
|
|
|
ostringstream s;
|
2000-09-18 17:39:21 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
switch (par->enumdepth) {
|
|
|
|
|
case 1:
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (par->isRightToLeftPar(buf->params))
|
2000-03-08 01:45:25 +00:00
|
|
|
|
s << '('
|
2000-04-10 21:40:13 +00:00
|
|
|
|
<< hebrewCounter(number)
|
2000-03-08 01:45:25 +00:00
|
|
|
|
<< ')';
|
2000-02-03 19:51:27 +00:00
|
|
|
|
else
|
2000-03-08 01:45:25 +00:00
|
|
|
|
s << '('
|
2000-04-10 21:40:13 +00:00
|
|
|
|
<< loweralphaCounter(number)
|
2000-03-08 01:45:25 +00:00
|
|
|
|
<< ')';
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (par->isRightToLeftPar(buf->params))
|
2000-03-10 13:22:20 +00:00
|
|
|
|
s << '.' << romanCounter(number);
|
2000-04-10 21:40:13 +00:00
|
|
|
|
else
|
|
|
|
|
s << romanCounter(number) << '.';
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (par->isRightToLeftPar(buf->params))
|
2000-03-08 01:45:25 +00:00
|
|
|
|
s << '.'
|
2000-03-10 13:22:20 +00:00
|
|
|
|
<< alphaCounter(number);
|
2000-04-10 21:40:13 +00:00
|
|
|
|
else
|
|
|
|
|
s << alphaCounter(number)
|
|
|
|
|
<< '.';
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (par->isRightToLeftPar(buf->params))
|
2000-03-08 01:45:25 +00:00
|
|
|
|
s << '.' << number;
|
2000-04-10 21:40:13 +00:00
|
|
|
|
else
|
|
|
|
|
s << number << '.';
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2000-09-18 17:39:21 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().labelString(s.str().c_str());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
for (i += par->enumdepth + 1; i < 10; ++i) {
|
|
|
|
|
// reset the following counters
|
|
|
|
|
par->setCounter(i, 0);
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
} else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
|
2000-07-17 18:27:53 +00:00
|
|
|
|
int i = LABEL_COUNTER_ENUMI - LABEL_COUNTER_CHAPTER + par->enumdepth;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
par->incCounter(i);
|
|
|
|
|
int number = par->getCounter(i);
|
2000-08-04 13:12:30 +00:00
|
|
|
|
if (!par->bibkey) {
|
2002-02-16 15:59:55 +00:00
|
|
|
|
InsetCommandParams p("bibitem" );
|
2000-08-04 13:12:30 +00:00
|
|
|
|
par->bibkey = new InsetBibKey(p);
|
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
par->bibkey->setCounter(number);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
par->params().labelString(layout->labelstring());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// In biblio should't be following counters but...
|
|
|
|
|
} else {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
string s = layout->labelstring();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// the caption hack:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->labeltype == LABEL_SENSITIVE) {
|
2001-07-11 12:10:46 +00:00
|
|
|
|
bool isOK (par->inInset() && par->inInset()->owner() &&
|
|
|
|
|
(par->inInset()->owner()->lyxCode() == Inset::FLOAT_CODE));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-07-19 17:16:27 +00:00
|
|
|
|
if (isOK) {
|
2001-07-11 12:10:46 +00:00
|
|
|
|
InsetFloat * tmp = static_cast<InsetFloat*>(par->inInset()->owner());
|
2000-07-18 17:45:27 +00:00
|
|
|
|
Floating const & fl
|
|
|
|
|
= floatList.getType(tmp->type());
|
|
|
|
|
// We should get the correct number here too.
|
2000-12-29 12:48:02 +00:00
|
|
|
|
s = fl.name() + " #:";
|
2000-07-18 17:45:27 +00:00
|
|
|
|
} else {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
/* par->SetLayout(0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
s = layout->labelstring; */
|
2000-06-12 11:27:15 +00:00
|
|
|
|
s = (par->getParLanguage(buf->params)->lang() == "hebrew")
|
2000-04-10 21:40:13 +00:00
|
|
|
|
? " :<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>" : "Senseless: ";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().labelString(s);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/* reset the enumeration counter. They are always resetted
|
2002-03-21 17:27:08 +00:00
|
|
|
|
* when there is any other layout between */
|
2000-01-13 16:28:54 +00:00
|
|
|
|
for (int i = 6 + par->enumdepth; i < 10; ++i)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
par->setCounter(i, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// Updates all counters BEHIND the row. Changed paragraphs
|
|
|
|
|
// with a dynamic left margin will be rebroken.
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::updateCounters(BufferView * bview, Row * row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par;
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2001-03-09 00:56:42 +00:00
|
|
|
|
if (!row) {
|
|
|
|
|
row = firstrow;
|
|
|
|
|
par = row->par();
|
|
|
|
|
} else {
|
|
|
|
|
par = row->par()->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (par) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
while (row->par() != par)
|
|
|
|
|
row = row->next();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCounter(bview->buffer(), par);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// now check for the headline layouts. remember that they
|
|
|
|
|
// have a dynamic left margin
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par->layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->margintype == MARGIN_DYNAMIC
|
|
|
|
|
|| layout->labeltype == LABEL_SENSITIVE) {
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// Rebreak the paragraph
|
2001-06-25 00:06:33 +00:00
|
|
|
|
removeParagraph(row);
|
|
|
|
|
appendParagraph(bview, row);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::insertInset(BufferView * bview, Inset * inset)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-19 08:52:59 +00:00
|
|
|
|
if (!cursor.par()->insetAllowed(inset->lyxCode()))
|
2000-04-10 14:29:05 +00:00
|
|
|
|
return;
|
2002-04-12 08:31:06 +00:00
|
|
|
|
setUndo(bview, Undo::FINISH, cursor.par(), cursor.par()->next());
|
|
|
|
|
freezeUndo();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cursor.par()->insertInset(cursor.pos(), inset);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// Just to rebreak and refresh correctly.
|
|
|
|
|
// The character will not be inserted a second time
|
|
|
|
|
insertChar(bview, Paragraph::META_INSET);
|
2001-01-08 16:14:09 +00:00
|
|
|
|
// If we enter a highly editable inset the cursor should be to before
|
|
|
|
|
// the inset. This couldn't happen before as Undo was not handled inside
|
2000-09-28 14:05:24 +00:00
|
|
|
|
// inset now after the Undo LyX tries to call inset->Edit(...) again
|
|
|
|
|
// and cannot do this as the cursor is behind the inset and GetInset
|
|
|
|
|
// does not return the inset!
|
2001-11-09 13:44:48 +00:00
|
|
|
|
if (isHighlyEditableInset(inset)) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cursorLeft(bview, true);
|
2000-09-28 14:05:24 +00:00
|
|
|
|
}
|
2002-04-12 08:31:06 +00:00
|
|
|
|
unFreezeUndo();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::copyEnvironmentType()
|
|
|
|
|
{
|
2002-06-24 20:28:12 +00:00
|
|
|
|
copylayouttype = cursor.par()->layout()->name();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::pasteEnvironmentType(BufferView * bview)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setLayout(bview, copylayouttype);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
|
|
2001-08-08 14:36:56 +00:00
|
|
|
|
void LyXText::cutSelection(BufferView * bview, bool doclear, bool realcut)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-15 15:44:39 +00:00
|
|
|
|
// Stuff what we got on the clipboard. Even if there is no selection.
|
|
|
|
|
|
|
|
|
|
// There is a problem with having the stuffing here in that the
|
|
|
|
|
// larger the selection the slower LyX will get. This can be
|
|
|
|
|
// solved by running the line below only when the selection has
|
|
|
|
|
// finished. The solution used currently just works, to make it
|
|
|
|
|
// faster we need to be more clever and probably also have more
|
|
|
|
|
// calls to stuffClipboard. (Lgb)
|
2001-09-12 10:41:25 +00:00
|
|
|
|
bview->stuffClipboard(selectionAsString(bview->buffer(), true));
|
2000-06-15 15:44:39 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// This doesn't make sense, if there is no selection
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set())
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
// OK, we have a selection. This is always between selection.start
|
|
|
|
|
// and selection.end
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// make sure that the depth behind the selection are restored, too
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * endpar = selection.end.par()->next();
|
|
|
|
|
Paragraph * undoendpar = endpar;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (endpar && endpar->getDepth()) {
|
|
|
|
|
while (endpar && endpar->getDepth()) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
endpar = endpar->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
undoendpar = endpar;
|
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
} else if (endpar) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
endpar = endpar->next(); // because of parindents etc.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setUndo(bview, Undo::DELETE,
|
|
|
|
|
selection.start.par(), undoendpar);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// there are two cases: cut only within one paragraph or
|
|
|
|
|
// more than one paragraph
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (selection.start.par() == selection.end.par()) {
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// only within one paragraph
|
2001-05-31 02:23:46 +00:00
|
|
|
|
endpar = selection.end.par();
|
|
|
|
|
int pos = selection.end.pos();
|
2001-07-03 15:39:17 +00:00
|
|
|
|
CutAndPaste::cutSelection(selection.start.par(), &endpar,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.start.pos(), pos,
|
|
|
|
|
bview->buffer()->params.textclass,
|
2001-10-16 14:47:10 +00:00
|
|
|
|
doclear, realcut);
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.end.pos(pos);
|
2000-01-17 21:01:30 +00:00
|
|
|
|
} else {
|
2001-05-31 02:23:46 +00:00
|
|
|
|
endpar = selection.end.par();
|
|
|
|
|
int pos = selection.end.pos();
|
2001-07-03 15:39:17 +00:00
|
|
|
|
CutAndPaste::cutSelection(selection.start.par(), &endpar,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.start.pos(), pos,
|
|
|
|
|
bview->buffer()->params.textclass,
|
2001-10-16 14:47:10 +00:00
|
|
|
|
doclear, realcut);
|
2000-06-15 15:44:39 +00:00
|
|
|
|
cursor.par(endpar);
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.end.par(endpar);
|
|
|
|
|
selection.end.pos(pos);
|
|
|
|
|
cursor.pos(selection.end.pos());
|
2000-01-17 21:01:30 +00:00
|
|
|
|
}
|
2001-03-09 00:56:42 +00:00
|
|
|
|
endpar = endpar->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// sometimes necessary
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (doclear)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
selection.start.par()->stripLeadingSpaces();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
redoParagraphs(bview, selection.start, endpar);
|
2001-05-30 13:17:50 +00:00
|
|
|
|
|
|
|
|
|
// cutSelection can invalidate the cursor so we need to set
|
|
|
|
|
// it anew. (Lgb)
|
2001-05-31 02:23:46 +00:00
|
|
|
|
cursor = selection.start;
|
2001-05-30 13:17:50 +00:00
|
|
|
|
|
|
|
|
|
// need a valid cursor. (Lgb)
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2001-05-30 13:17:50 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), cursor.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
updateCounters(bview, cursor.row());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-06-16 15:13:25 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::copySelection(BufferView * bview)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-01-13 17:28:42 +00:00
|
|
|
|
// stuff the selection onto the X clipboard, from an explicit copy request
|
2001-09-12 10:41:25 +00:00
|
|
|
|
bview->stuffClipboard(selectionAsString(bview->buffer(), true));
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
// this doesnt make sense, if there is no selection
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set())
|
2000-04-10 14:29:05 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
// ok we have a selection. This is always between selection.start
|
2000-04-10 14:29:05 +00:00
|
|
|
|
// and sel_end cursor
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2000-04-10 14:29:05 +00:00
|
|
|
|
// copy behind a space if there is one
|
2001-05-31 02:23:46 +00:00
|
|
|
|
while (selection.start.par()->size() > selection.start.pos()
|
2001-06-25 00:06:33 +00:00
|
|
|
|
&& selection.start.par()->isLineSeparator(selection.start.pos())
|
2001-05-31 02:23:46 +00:00
|
|
|
|
&& (selection.start.par() != selection.end.par()
|
|
|
|
|
|| selection.start.pos() < selection.end.pos()))
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.start.pos(selection.start.pos() + 1);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2001-07-03 15:39:17 +00:00
|
|
|
|
CutAndPaste::copySelection(selection.start.par(), selection.end.par(),
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.start.pos(), selection.end.pos(),
|
|
|
|
|
bview->buffer()->params.textclass);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::pasteSelection(BufferView * bview)
|
2000-04-10 14:29:05 +00:00
|
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
|
// this does not make sense, if there is nothing to paste
|
2001-07-03 15:39:17 +00:00
|
|
|
|
if (!CutAndPaste::checkPastePossible(cursor.par()))
|
2000-06-12 11:27:15 +00:00
|
|
|
|
return;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setUndo(bview, Undo::INSERT,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
cursor.par(), cursor.par()->next());
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * endpar;
|
|
|
|
|
Paragraph * actpar = cursor.par();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
int pos = cursor.pos();
|
2001-09-20 10:16:24 +00:00
|
|
|
|
|
2001-07-03 15:39:17 +00:00
|
|
|
|
CutAndPaste::pasteSelection(&actpar, &endpar, pos,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
bview->buffer()->params.textclass);
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
redoParagraphs(bview, cursor, endpar);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), cursor.pos());
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2002-03-18 13:47:37 +00:00
|
|
|
|
|
|
|
|
|
selection.cursor = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, actpar, pos);
|
2002-03-18 13:47:37 +00:00
|
|
|
|
setSelection(bview);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
updateCounters(bview, cursor.row());
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
2000-06-15 15:44:39 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// sets the selection over the number of characters of string, no check!!
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setSelectionOverString(BufferView * bview, string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-06-13 16:32:36 +00:00
|
|
|
|
if (str.empty())
|
|
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2001-06-13 16:32:36 +00:00
|
|
|
|
for (string::size_type i = 0; i < str.length(); ++i)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cursorRight(bview);
|
|
|
|
|
setSelection(bview);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// simple replacing. The font of the first selected character is used
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::replaceSelectionWithString(BufferView * bview,
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setCursorParUndo(bview);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
freezeUndo();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (!selection.set()) { // create a dummy selection
|
|
|
|
|
selection.end = cursor;
|
|
|
|
|
selection.start = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get font setting before we cut
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type pos = selection.end.pos();
|
2001-05-31 02:23:46 +00:00
|
|
|
|
LyXFont const font = selection.start.par()
|
2001-06-25 00:06:33 +00:00
|
|
|
|
->getFontSettings(bview->buffer()->params,
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.start.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Insert the new string
|
2000-09-14 17:53:12 +00:00
|
|
|
|
for (string::const_iterator cit = str.begin(); cit != str.end(); ++cit) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
selection.end.par()->insertChar(pos, (*cit), font);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
++pos;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Cut the selection
|
2001-08-08 14:36:56 +00:00
|
|
|
|
cutSelection(bview, true, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
unFreezeUndo();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// needed to insert the selection
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::insertStringAsLines(BufferView * bview, string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = cursor.par();
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type pos = cursor.pos();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * endpar = cursor.par()->next();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setCursorParUndo(bview);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// only to be sure, should not be neccessary
|
2001-08-01 15:42:53 +00:00
|
|
|
|
clearSelection();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-23 09:11:14 +00:00
|
|
|
|
bview->buffer()->insertStringAsLines(par, pos, current_font, str);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
redoParagraphs(bview, cursor, endpar);
|
|
|
|
|
setCursor(bview, cursor.par(), cursor.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, par, pos);
|
|
|
|
|
setSelection(bview);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// turns double-CR to single CR, others where converted into one
|
|
|
|
|
// blank. Then InsertStringAsLines is called
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::insertStringAsParagraphs(BufferView * bview, string const & str)
|
|
|
|
|
{
|
|
|
|
|
string linestr(str);
|
|
|
|
|
bool newline_inserted = false;
|
|
|
|
|
for (string::size_type i = 0; i < linestr.length(); ++i) {
|
|
|
|
|
if (linestr[i] == '\n') {
|
|
|
|
|
if (newline_inserted) {
|
|
|
|
|
// we know that \r will be ignored by
|
|
|
|
|
// InsertStringA. Of course, it is a dirty
|
|
|
|
|
// trick, but it works...
|
|
|
|
|
linestr[i - 1] = '\r';
|
|
|
|
|
linestr[i] = '\n';
|
|
|
|
|
} else {
|
|
|
|
|
linestr[i] = ' ';
|
|
|
|
|
newline_inserted = true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
} else if (IsPrintable(linestr[i])) {
|
|
|
|
|
newline_inserted = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
insertStringAsLines(bview, linestr);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
bool LyXText::gotoNextInset(BufferView * bview,
|
2002-02-16 15:59:55 +00:00
|
|
|
|
vector<Inset::Code> const & codes,
|
2001-01-15 18:54:31 +00:00
|
|
|
|
string const & contents) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
|
LyXCursor res = cursor;
|
2001-01-15 18:54:31 +00:00
|
|
|
|
Inset * inset;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
do {
|
2001-03-11 00:21:13 +00:00
|
|
|
|
if (res.pos() < res.par()->size() - 1) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
res.pos(res.pos() + 1);
|
|
|
|
|
} else {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
res.par(res.par()->next());
|
2000-06-08 23:16:16 +00:00
|
|
|
|
res.pos(0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
|
|
} while (res.par() &&
|
2001-11-23 10:16:02 +00:00
|
|
|
|
!(res.par()->isInset(res.pos())
|
2001-06-25 00:06:33 +00:00
|
|
|
|
&& (inset = res.par()->getInset(res.pos())) != 0
|
2001-06-28 10:25:20 +00:00
|
|
|
|
&& find(codes.begin(), codes.end(), inset->lyxCode())
|
2001-07-07 18:19:18 +00:00
|
|
|
|
!= codes.end()
|
2001-01-15 18:54:31 +00:00
|
|
|
|
&& (contents.empty() ||
|
2001-06-25 00:06:33 +00:00
|
|
|
|
static_cast<InsetCommand *>(res.par()->getInset(res.pos()))->getContents()
|
2001-01-15 18:54:31 +00:00
|
|
|
|
== contents)));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (res.par()) {
|
2001-11-09 13:44:48 +00:00
|
|
|
|
setCursor(bview, res.par(), res.pos(), false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::checkParagraph(BufferView * bview, Paragraph * par,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
pos_type pos)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-03-21 17:27:08 +00:00
|
|
|
|
LyXCursor tmpcursor;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
|
int y = 0;
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type z;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Row * row = getRow(par, pos, y);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-09-23 04:57:18 +00:00
|
|
|
|
// is there a break one row above
|
|
|
|
|
if (row->previous() && row->previous()->par() == row->par()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
z = nextBreakPoint(bview, row->previous(), workWidth(bview));
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (z >= row->pos()) {
|
2000-09-23 04:57:18 +00:00
|
|
|
|
// set the dimensions of the row above
|
|
|
|
|
y -= row->previous()->height();
|
|
|
|
|
refresh_y = y;
|
|
|
|
|
refresh_row = row->previous();
|
2001-07-06 15:57:54 +00:00
|
|
|
|
status(bview, LyXText::NEED_MORE_REFRESH);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
breakAgain(bview, row->previous());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-09-23 04:57:18 +00:00
|
|
|
|
// set the cursor again. Otherwise
|
|
|
|
|
// dangling pointers are possible
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), cursor.pos(),
|
2000-12-17 06:09:35 +00:00
|
|
|
|
false, cursor.boundary());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2000-09-23 04:57:18 +00:00
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-09-23 04:57:18 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-09-23 04:57:18 +00:00
|
|
|
|
int const tmpheight = row->height();
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type const tmplast = rowLast(row);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
refresh_y = y;
|
|
|
|
|
refresh_row = row;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
breakAgain(bview, row);
|
|
|
|
|
if (row->height() == tmpheight && rowLast(row) == tmplast)
|
2001-07-06 15:57:54 +00:00
|
|
|
|
status(bview, LyXText::NEED_VERY_LITTLE_REFRESH);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
else
|
2002-03-21 17:27:08 +00:00
|
|
|
|
status(bview, LyXText::NEED_MORE_REFRESH);
|
|
|
|
|
|
2000-09-23 04:57:18 +00:00
|
|
|
|
// check the special right address boxes
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (par->layout()->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
|
2000-09-23 04:57:18 +00:00
|
|
|
|
tmpcursor.par(par);
|
|
|
|
|
tmpcursor.row(row);
|
|
|
|
|
tmpcursor.y(y);
|
|
|
|
|
tmpcursor.x(0);
|
|
|
|
|
tmpcursor.x_fix(0);
|
|
|
|
|
tmpcursor.pos(pos);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
redoDrawingOfParagraph(bview, tmpcursor);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// set the cursor again. Otherwise dangling pointers are possible
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// also set the selection
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (selection.set()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmpcursor = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursorIntern(bview, selection.cursor.par(), selection.cursor.pos(),
|
2001-05-31 02:23:46 +00:00
|
|
|
|
false, selection.cursor.boundary());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.cursor = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursorIntern(bview, selection.start.par(),
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.start.pos(),
|
|
|
|
|
false, selection.start.boundary());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.start = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursorIntern(bview, selection.end.par(),
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.end.pos(),
|
|
|
|
|
false, selection.end.boundary());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
selection.end = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursorIntern(bview, last_sel_cursor.par(),
|
2000-12-17 06:09:35 +00:00
|
|
|
|
last_sel_cursor.pos(),
|
|
|
|
|
false, last_sel_cursor.boundary());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
last_sel_cursor = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
cursor = tmpcursor;
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursorIntern(bview, cursor.par(), cursor.pos(),
|
2000-12-17 06:09:35 +00:00
|
|
|
|
false, cursor.boundary());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
|
// returns false if inset wasn't found
|
2001-06-25 00:06:33 +00:00
|
|
|
|
bool LyXText::updateInset(BufferView * bview, Inset * inset)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// first check the current paragraph
|
2001-06-25 00:06:33 +00:00
|
|
|
|
int pos = cursor.par()->getPositionOfInset(inset);
|
2001-10-18 16:17:46 +00:00
|
|
|
|
if (pos != -1) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
checkParagraph(bview, cursor.par(), pos);
|
2000-06-21 15:07:57 +00:00
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// check every paragraph
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-01-13 00:33:21 +00:00
|
|
|
|
Paragraph * par = ownerParagraph();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
do {
|
2001-07-07 18:19:18 +00:00
|
|
|
|
pos = par->getPositionOfInset(inset);
|
2001-10-18 16:17:46 +00:00
|
|
|
|
if (pos != -1) {
|
2001-07-07 18:19:18 +00:00
|
|
|
|
checkParagraph(bview, par, pos);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} while (par);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-01-12 21:03:30 +00:00
|
|
|
|
bool LyXText::setCursor(BufferView * bview, Paragraph * par,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
pos_type pos,
|
|
|
|
|
bool setfont, bool boundary) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
LyXCursor old_cursor = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursorIntern(bview, par, pos, setfont, boundary);
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return deleteEmptyParagraphMechanism(bview, old_cursor);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2001-12-28 21:17:18 +00:00
|
|
|
|
void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
pos_type pos, bool boundary) const
|
2000-04-19 14:42:19 +00:00
|
|
|
|
{
|
2001-12-28 21:17:18 +00:00
|
|
|
|
lyx::Assert(par);
|
|
|
|
|
lyx::Assert(bview);
|
2002-03-14 13:40:19 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cur.par(par);
|
|
|
|
|
cur.pos(pos);
|
|
|
|
|
cur.boundary(boundary);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// get the cursor y position in text
|
2000-09-29 18:44:07 +00:00
|
|
|
|
int y = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Row * row = getRow(par, pos, y);
|
2002-04-11 09:53:23 +00:00
|
|
|
|
Row * old_row = row;
|
2002-04-16 14:10:39 +00:00
|
|
|
|
cur.irow(row);
|
2002-04-11 09:53:23 +00:00
|
|
|
|
// if we are before the first char of this row and are still in the
|
|
|
|
|
// same paragraph and there is a previous row then put the cursor on
|
|
|
|
|
// the end of the previous row
|
|
|
|
|
cur.iy(y + row->baseline());
|
|
|
|
|
Inset * ins;
|
2002-04-12 08:22:16 +00:00
|
|
|
|
if (row->previous() && pos &&
|
2002-05-02 12:45:27 +00:00
|
|
|
|
row->previous()->par() == row->par() &&
|
2002-04-12 08:22:16 +00:00
|
|
|
|
par->getChar(pos) == Paragraph::META_INSET &&
|
2002-04-11 09:53:23 +00:00
|
|
|
|
(ins=par->getInset(pos)) && (ins->needFullRow() || ins->display()))
|
|
|
|
|
{
|
|
|
|
|
row = row->previous();
|
|
|
|
|
y -= row->height();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cur.row(row);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// y is now the beginning of the cursor row
|
2000-06-08 23:16:16 +00:00
|
|
|
|
y += row->baseline();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// y is now the cursor baseline
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cur.y(y);
|
2001-11-09 13:44:48 +00:00
|
|
|
|
|
2002-04-11 09:53:23 +00:00
|
|
|
|
pos_type last = rowLastPrintable(old_row);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
2001-12-28 21:17:18 +00:00
|
|
|
|
if (pos > last + 1) {
|
|
|
|
|
// This shouldn't happen.
|
2000-06-08 23:16:16 +00:00
|
|
|
|
pos = last + 1;
|
2001-12-28 21:17:18 +00:00
|
|
|
|
cur.pos(pos);
|
|
|
|
|
} else if (pos < row->pos()) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
pos = row->pos();
|
2001-12-28 21:17:18 +00:00
|
|
|
|
cur.pos(pos);
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-04-12 15:59:03 +00:00
|
|
|
|
// now get the cursors x position
|
|
|
|
|
float x = getCursorX(bview, row, pos, last, boundary);
|
|
|
|
|
cur.x(int(x));
|
|
|
|
|
cur.x_fix(cur.x());
|
|
|
|
|
if (old_row != row) {
|
|
|
|
|
x = getCursorX(bview, old_row, pos, last, boundary);
|
|
|
|
|
cur.ix(int(x));
|
|
|
|
|
} else
|
|
|
|
|
cur.ix(cur.x());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float LyXText::getCursorX(BufferView * bview, Row * row,
|
|
|
|
|
pos_type pos, pos_type last, bool boundary) const
|
|
|
|
|
{
|
|
|
|
|
pos_type cursor_vpos = 0;
|
|
|
|
|
float x;
|
|
|
|
|
float fill_separator;
|
|
|
|
|
float fill_hfill;
|
|
|
|
|
float fill_label_hfill;
|
|
|
|
|
// This call HAS to be here because of the BidiTables!!!
|
|
|
|
|
prepareToPrint(bview, row, x, fill_separator, fill_hfill,
|
2002-04-22 16:31:14 +00:00
|
|
|
|
fill_label_hfill);
|
2002-04-12 15:59:03 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (last < row->pos())
|
2002-03-14 13:40:19 +00:00
|
|
|
|
cursor_vpos = row->pos();
|
2000-05-30 19:31:11 +00:00
|
|
|
|
else if (pos > last && !boundary)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
cursor_vpos = (row->par()->isRightToLeftPar(bview->buffer()->params))
|
2002-03-21 17:27:08 +00:00
|
|
|
|
? row->pos() : last + 1;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
else if (pos > row->pos() &&
|
2002-03-21 17:27:08 +00:00
|
|
|
|
(pos > last || boundary))
|
2000-06-08 23:16:16 +00:00
|
|
|
|
/// Place cursor after char at (logical) position pos - 1
|
|
|
|
|
cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
|
|
|
|
|
? log2vis(pos - 1) + 1 : log2vis(pos - 1);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
else
|
|
|
|
|
/// Place cursor before char at (logical) position pos
|
2000-05-30 19:31:11 +00:00
|
|
|
|
cursor_vpos = (bidi_level(pos) % 2 == 0)
|
2000-04-19 14:42:19 +00:00
|
|
|
|
? log2vis(pos) : log2vis(pos) + 1;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type main_body =
|
2001-06-25 00:06:33 +00:00
|
|
|
|
beginningOfMainBody(bview->buffer(), row->par());
|
2000-09-23 04:57:18 +00:00
|
|
|
|
if ((main_body > 0) &&
|
2002-03-21 17:27:08 +00:00
|
|
|
|
((main_body-1 > last) ||
|
2001-06-25 00:06:33 +00:00
|
|
|
|
!row->par()->isLineSeparator(main_body-1)))
|
2000-09-23 04:57:18 +00:00
|
|
|
|
main_body = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-03-14 13:40:19 +00:00
|
|
|
|
for (pos_type vpos = row->pos(); vpos < cursor_vpos; ++vpos) {
|
2002-04-12 15:59:03 +00:00
|
|
|
|
pos_type pos = vis2log(vpos);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
if (main_body > 0 && pos == main_body - 1) {
|
|
|
|
|
x += fill_label_hfill +
|
2002-06-24 20:28:12 +00:00
|
|
|
|
font_metrics::width(
|
|
|
|
|
row->par()->layout()->labelsep,
|
|
|
|
|
getLabelFont(bview->buffer(),
|
|
|
|
|
row->par()));
|
|
|
|
|
if (row->par()->isLineSeparator(main_body - 1))
|
|
|
|
|
x -= singleWidth(bview,
|
|
|
|
|
row->par(), main_body - 1);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (hfillExpansion(bview->buffer(), row, pos)) {
|
|
|
|
|
x += singleWidth(bview, row->par(), pos);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
if (pos >= main_body)
|
|
|
|
|
x += fill_hfill;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
else
|
2000-09-23 04:57:18 +00:00
|
|
|
|
x += fill_label_hfill;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
} else if (row->par()->isSeparator(pos)) {
|
|
|
|
|
x += singleWidth(bview, row->par(), pos);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
if (pos >= main_body)
|
|
|
|
|
x += fill_separator;
|
|
|
|
|
} else
|
2001-06-25 00:06:33 +00:00
|
|
|
|
x += singleWidth(bview, row->par(), pos);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
2002-04-12 15:59:03 +00:00
|
|
|
|
return x;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setCursorIntern(BufferView * bview, Paragraph * par,
|
2002-03-21 17:27:08 +00:00
|
|
|
|
pos_type pos, bool setfont, bool boundary) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-11 12:10:46 +00:00
|
|
|
|
InsetText * it = static_cast<InsetText *>(par->inInset());
|
2001-08-05 22:12:27 +00:00
|
|
|
|
if (it) {
|
|
|
|
|
if (it != inset_owner) {
|
2002-03-19 21:42:50 +00:00
|
|
|
|
lyxerr[Debug::INSETS] << "InsetText is " << it
|
|
|
|
|
<< endl
|
|
|
|
|
<< "inset_owner is "
|
|
|
|
|
<< inset_owner << endl;
|
2002-02-26 10:50:48 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2001-09-27 09:52:06 +00:00
|
|
|
|
#warning I believe this code is wrong. (Lgb)
|
2001-08-05 22:12:27 +00:00
|
|
|
|
#warning J<>rgen, have a look at this. (Lgb)
|
2001-08-08 14:36:56 +00:00
|
|
|
|
#warning Hmmm, I guess you are right but we
|
|
|
|
|
#warning should verify when this is needed
|
2002-02-26 10:50:48 +00:00
|
|
|
|
#endif
|
2001-08-05 22:12:27 +00:00
|
|
|
|
// J<>rgen, would you like to have a look?
|
|
|
|
|
// I guess we need to move the outer cursor
|
|
|
|
|
// and open and lock the inset (bla bla bla)
|
|
|
|
|
// stuff I don't know... so can you have a look?
|
|
|
|
|
// (Lgb)
|
2001-09-09 22:02:19 +00:00
|
|
|
|
// I moved the lyxerr stuff in here so we can see if
|
|
|
|
|
// this is actually really needed and where!
|
2001-08-08 14:36:56 +00:00
|
|
|
|
// (Jug)
|
2001-12-14 11:55:58 +00:00
|
|
|
|
// it->getLyXText(bview)->setCursorIntern(bview, par, pos, setfont, boundary);
|
2001-08-05 22:12:27 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-08-05 22:12:27 +00:00
|
|
|
|
setCursor(bview, cursor, par, pos, boundary);
|
|
|
|
|
if (setfont)
|
|
|
|
|
setCurrentFont(bview);
|
2000-05-30 19:31:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setCurrentFont(BufferView * bview) const
|
2000-05-30 19:31:11 +00:00
|
|
|
|
{
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type pos = cursor.pos();
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (cursor.boundary() && pos > 0)
|
2000-05-30 19:31:11 +00:00
|
|
|
|
--pos;
|
|
|
|
|
|
|
|
|
|
if (pos > 0) {
|
2001-03-11 00:21:13 +00:00
|
|
|
|
if (pos == cursor.par()->size())
|
2000-05-30 19:31:11 +00:00
|
|
|
|
--pos;
|
2001-05-30 13:17:50 +00:00
|
|
|
|
else // potentional bug... BUG (Lgb)
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (cursor.par()->isSeparator(pos)) {
|
|
|
|
|
if (pos > cursor.row()->pos() &&
|
2002-03-21 17:27:08 +00:00
|
|
|
|
bidi_level(pos) % 2 ==
|
2001-07-07 18:19:18 +00:00
|
|
|
|
bidi_level(pos - 1) % 2)
|
|
|
|
|
--pos;
|
|
|
|
|
else if (pos + 1 < cursor.par()->size())
|
|
|
|
|
++pos;
|
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
2000-05-30 19:31:11 +00:00
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
current_font =
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cursor.par()->getFontSettings(bview->buffer()->params, pos);
|
|
|
|
|
real_current_font = getFont(bview->buffer(), cursor.par(), pos);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
|
2001-03-11 00:21:13 +00:00
|
|
|
|
if (cursor.pos() == cursor.par()->size() &&
|
2001-06-25 00:06:33 +00:00
|
|
|
|
isBoundary(bview->buffer(), cursor.par(), cursor.pos()) &&
|
2000-07-10 10:31:34 +00:00
|
|
|
|
!cursor.boundary()) {
|
|
|
|
|
Language const * lang =
|
|
|
|
|
cursor.par()->getParLanguage(bview->buffer()->params);
|
|
|
|
|
current_font.setLanguage(lang);
|
2001-02-26 10:50:03 +00:00
|
|
|
|
current_font.setNumber(LyXFont::OFF);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
real_current_font.setLanguage(lang);
|
2001-02-26 10:50:03 +00:00
|
|
|
|
real_current_font.setNumber(LyXFont::OFF);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setCursorFromCoordinates(BufferView * bview, int x, int y) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXCursor old_cursor = cursor;
|
2001-07-30 11:56:00 +00:00
|
|
|
|
|
|
|
|
|
setCursorFromCoordinates(bview, cursor, x, y);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCurrentFont(bview);
|
|
|
|
|
deleteEmptyParagraphMechanism(bview, old_cursor);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setCursorFromCoordinates(BufferView * bview, LyXCursor & cur,
|
2000-09-29 18:44:07 +00:00
|
|
|
|
int x, int y) const
|
2000-03-27 15:13:47 +00:00
|
|
|
|
{
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// Get the row first.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Row * row = getRowNearY(y);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
bool bound = false;
|
2001-11-26 16:42:04 +00:00
|
|
|
|
pos_type const column = getColumnNearX(bview, row, x, bound);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cur.par(row->par());
|
|
|
|
|
cur.pos(row->pos() + column);
|
|
|
|
|
cur.x(x);
|
|
|
|
|
cur.y(y + row->baseline());
|
2002-04-16 14:10:39 +00:00
|
|
|
|
cur.row(row);
|
2002-04-11 14:22:39 +00:00
|
|
|
|
Inset * ins;
|
2002-04-16 14:10:39 +00:00
|
|
|
|
if (row->next() && row->next()->pos() == cur.pos() &&
|
|
|
|
|
cur.par() == row->next()->par() &&
|
2002-04-11 14:22:39 +00:00
|
|
|
|
cur.par()->getChar(cur.pos()) == Paragraph::META_INSET &&
|
|
|
|
|
(ins=cur.par()->getInset(cur.pos())) &&
|
|
|
|
|
(ins->needFullRow() || ins->display()))
|
|
|
|
|
{
|
2002-04-16 14:10:39 +00:00
|
|
|
|
// we enter here if we put the cursor on the end of the row before
|
|
|
|
|
// a inset which uses a full row and in that case we HAVE to calculate
|
|
|
|
|
// the right (i) values.
|
|
|
|
|
pos_type last = rowLastPrintable(row);
|
|
|
|
|
float x = getCursorX(bview, row->next(), cur.pos(), last, bound);
|
|
|
|
|
cur.ix(int(x));
|
2002-04-11 14:22:39 +00:00
|
|
|
|
cur.iy(y + row->height() + row->next()->baseline());
|
2002-04-16 14:10:39 +00:00
|
|
|
|
cur.irow(row->next());
|
2002-04-11 14:22:39 +00:00
|
|
|
|
} else {
|
|
|
|
|
cur.iy(cur.y());
|
2002-04-16 14:10:39 +00:00
|
|
|
|
cur.ix(cur.x());
|
|
|
|
|
cur.irow(row);
|
2002-04-11 14:22:39 +00:00
|
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cur.boundary(bound);
|
2000-03-27 15:13:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::cursorLeft(BufferView * bview, bool internal) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (cursor.pos() > 0) {
|
|
|
|
|
bool boundary = cursor.boundary();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), cursor.pos() - 1, true, false);
|
2000-05-30 19:31:11 +00:00
|
|
|
|
if (!internal && !boundary &&
|
2001-06-25 00:06:33 +00:00
|
|
|
|
isBoundary(bview->buffer(), cursor.par(), cursor.pos() + 1))
|
|
|
|
|
setCursor(bview, cursor.par(), cursor.pos() + 1, true, true);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
} else if (cursor.par()->previous()) { // steps into the above paragraph.
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = cursor.par()->previous();
|
|
|
|
|
setCursor(bview, par, par->size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::cursorRight(BufferView * bview, bool internal) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-07-10 10:31:34 +00:00
|
|
|
|
if (!internal && cursor.boundary() &&
|
2001-06-25 00:06:33 +00:00
|
|
|
|
!cursor.par()->isNewline(cursor.pos()))
|
|
|
|
|
setCursor(bview, cursor.par(), cursor.pos(), true, false);
|
2001-03-11 00:21:13 +00:00
|
|
|
|
else if (cursor.pos() < cursor.par()->size()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), cursor.pos() + 1, true, false);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
if (!internal &&
|
2001-06-25 00:06:33 +00:00
|
|
|
|
isBoundary(bview->buffer(), cursor.par(), cursor.pos()))
|
|
|
|
|
setCursor(bview, cursor.par(), cursor.pos(), true, true);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
} else if (cursor.par()->next())
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par()->next(), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-04-17 08:34:59 +00:00
|
|
|
|
void LyXText::cursorUp(BufferView * bview, bool selecting) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-04-16 14:10:39 +00:00
|
|
|
|
#if 1
|
|
|
|
|
int x = cursor.x_fix();
|
|
|
|
|
int y = cursor.y() - cursor.row()->baseline() - 1;
|
|
|
|
|
setCursorFromCoordinates(bview, x, y);
|
2002-04-17 08:34:59 +00:00
|
|
|
|
if (!selecting) {
|
|
|
|
|
int y1 = cursor.iy() - first_y;
|
|
|
|
|
int y2 = y1;
|
|
|
|
|
y -= first_y;
|
|
|
|
|
Inset * inset_hit =
|
|
|
|
|
bview->checkInsetHit(const_cast<LyXText *>(this), x, y1);
|
|
|
|
|
if (inset_hit && isHighlyEditableInset(inset_hit)) {
|
2002-05-26 17:33:14 +00:00
|
|
|
|
inset_hit->edit(bview, x, y - (y2 - y1), mouse_button::none);
|
2002-04-17 08:34:59 +00:00
|
|
|
|
}
|
2002-04-16 14:10:39 +00:00
|
|
|
|
}
|
|
|
|
|
#else
|
2002-03-21 17:27:08 +00:00
|
|
|
|
setCursorFromCoordinates(bview, cursor.x_fix(),
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.y() - cursor.row()->baseline() - 1);
|
2002-04-16 14:10:39 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-04-17 08:34:59 +00:00
|
|
|
|
void LyXText::cursorDown(BufferView * bview, bool selecting) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-04-16 14:10:39 +00:00
|
|
|
|
#if 1
|
|
|
|
|
int x = cursor.x_fix();
|
|
|
|
|
int y = cursor.y() - cursor.row()->baseline() +
|
|
|
|
|
cursor.row()->height() + 1;
|
|
|
|
|
setCursorFromCoordinates(bview, x, y);
|
2002-04-19 11:06:09 +00:00
|
|
|
|
if (!selecting && cursor.row() == cursor.irow()) {
|
2002-04-17 08:34:59 +00:00
|
|
|
|
int y1 = cursor.iy() - first_y;
|
|
|
|
|
int y2 = y1;
|
|
|
|
|
y -= first_y;
|
|
|
|
|
Inset * inset_hit =
|
|
|
|
|
bview->checkInsetHit(const_cast<LyXText *>(this), x, y1);
|
|
|
|
|
if (inset_hit && isHighlyEditableInset(inset_hit)) {
|
2002-05-26 17:33:14 +00:00
|
|
|
|
inset_hit->edit(bview, x, y - (y2 - y1), mouse_button::none);
|
2002-04-17 08:34:59 +00:00
|
|
|
|
}
|
2002-04-16 14:10:39 +00:00
|
|
|
|
}
|
|
|
|
|
#else
|
2002-03-21 17:27:08 +00:00
|
|
|
|
setCursorFromCoordinates(bview, cursor.x_fix(),
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.y() - cursor.row()->baseline()
|
|
|
|
|
+ cursor.row()->height() + 1);
|
2002-04-16 14:10:39 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::cursorUpParagraph(BufferView * bview) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (cursor.pos() > 0) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-03-09 00:56:42 +00:00
|
|
|
|
else if (cursor.par()->previous()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par()->previous(), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::cursorDownParagraph(BufferView * bview) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-03-09 00:56:42 +00:00
|
|
|
|
if (cursor.par()->next()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par()->next(), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), cursor.par()->size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-27 09:52:06 +00:00
|
|
|
|
// fix the cursor `cur' after a characters has been deleted at `where'
|
|
|
|
|
// position. Called by deleteEmptyParagraphMechanism
|
|
|
|
|
void LyXText::fixCursorAfterDelete(BufferView * bview,
|
|
|
|
|
LyXCursor & cur,
|
|
|
|
|
LyXCursor const & where) const
|
|
|
|
|
{
|
|
|
|
|
// if cursor is not in the paragraph where the delete occured,
|
|
|
|
|
// do nothing
|
|
|
|
|
if (cur.par() != where.par())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// if cursor position is after the place where the delete occured,
|
|
|
|
|
// update it
|
|
|
|
|
if (cur.pos() > where.pos())
|
|
|
|
|
cur.pos(cur.pos()-1);
|
|
|
|
|
|
2002-05-02 12:45:27 +00:00
|
|
|
|
// check also if we don't want to set the cursor on a spot behind the
|
|
|
|
|
// pagragraph because we erased the last character.
|
|
|
|
|
if (cur.pos() > cur.par()->size())
|
|
|
|
|
cur.pos(cur.par()->size());
|
2002-05-29 16:21:03 +00:00
|
|
|
|
|
2001-09-27 09:52:06 +00:00
|
|
|
|
// recompute row et al. for this cursor
|
|
|
|
|
setCursor(bview, cur, cur.par(), cur.pos(), cur.boundary());
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-01-12 21:03:30 +00:00
|
|
|
|
bool LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
|
2000-06-12 11:27:15 +00:00
|
|
|
|
LyXCursor const & old_cursor) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-03-14 23:33:15 +00:00
|
|
|
|
// Would be wrong to delete anything if we have a selection.
|
2002-03-07 11:58:19 +00:00
|
|
|
|
if (selection.set())
|
|
|
|
|
return false;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2000-03-14 23:33:15 +00:00
|
|
|
|
// We allow all kinds of "mumbo-jumbo" when freespacing.
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (old_cursor.par()->layout()->free_spacing
|
|
|
|
|
|| old_cursor.par()->isFreeSpacing()) {
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2001-11-29 16:29:30 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
/* Ok I'll put some comments here about what is missing.
|
|
|
|
|
I have fixed BackSpace (and thus Delete) to not delete
|
|
|
|
|
double-spaces automagically. I have also changed Cut,
|
|
|
|
|
Copy and Paste to hopefully do some sensible things.
|
|
|
|
|
There are still some small problems that can lead to
|
|
|
|
|
double spaces stored in the document file or space at
|
|
|
|
|
the beginning of paragraphs. This happens if you have
|
|
|
|
|
the cursor betwenn to spaces and then save. Or if you
|
|
|
|
|
cut and paste and the selection have a space at the
|
|
|
|
|
beginning and then save right after the paste. I am
|
|
|
|
|
sure none of these are very hard to fix, but I will
|
|
|
|
|
put out 1.1.4pre2 with FIX_DOUBLE_SPACE defined so
|
|
|
|
|
that I can get some feedback. (Lgb)
|
|
|
|
|
*/
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// If old_cursor.pos() == 0 and old_cursor.pos()(1) == LineSeparator
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// delete the LineSeparator.
|
|
|
|
|
// MISSING
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
// If old_cursor.pos() == 1 and old_cursor.pos()(0) == LineSeparator
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// delete the LineSeparator.
|
|
|
|
|
// MISSING
|
|
|
|
|
|
|
|
|
|
// If the pos around the old_cursor were spaces, delete one of them.
|
2001-12-11 14:33:52 +00:00
|
|
|
|
if (old_cursor.par() != cursor.par()
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|| old_cursor.pos() != cursor.pos()) {
|
2000-05-26 16:13:01 +00:00
|
|
|
|
// Only if the cursor has really moved
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (old_cursor.pos() > 0
|
2001-03-11 00:21:13 +00:00
|
|
|
|
&& old_cursor.pos() < old_cursor.par()->size()
|
2001-06-25 00:06:33 +00:00
|
|
|
|
&& old_cursor.par()->isLineSeparator(old_cursor.pos())
|
|
|
|
|
&& old_cursor.par()->isLineSeparator(old_cursor.pos() - 1)) {
|
|
|
|
|
old_cursor.par()->erase(old_cursor.pos() - 1);
|
|
|
|
|
redoParagraphs(bview, old_cursor, old_cursor.par()->next());
|
2001-09-27 09:52:06 +00:00
|
|
|
|
|
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning This will not work anymore when we have multiple views of the same buffer
|
|
|
|
|
// In this case, we will have to correct also the cursors held by
|
|
|
|
|
// other bufferviews. It will probably be easier to do that in a more
|
|
|
|
|
// automated way in LyXCursor code. (JMarc 26/09/2001)
|
|
|
|
|
#endif
|
|
|
|
|
// correct all cursors held by the LyXText
|
|
|
|
|
fixCursorAfterDelete(bview, cursor, old_cursor);
|
|
|
|
|
fixCursorAfterDelete(bview, selection.cursor,
|
|
|
|
|
old_cursor);
|
|
|
|
|
fixCursorAfterDelete(bview, selection.start,
|
|
|
|
|
old_cursor);
|
|
|
|
|
fixCursorAfterDelete(bview, selection.end, old_cursor);
|
|
|
|
|
fixCursorAfterDelete(bview, last_sel_cursor,
|
|
|
|
|
old_cursor);
|
|
|
|
|
fixCursorAfterDelete(bview, toggle_cursor, old_cursor);
|
|
|
|
|
fixCursorAfterDelete(bview, toggle_end_cursor,
|
|
|
|
|
old_cursor);
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2000-03-14 23:33:15 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2001-12-11 14:33:52 +00:00
|
|
|
|
// don't delete anything if this is the ONLY paragraph!
|
|
|
|
|
if (!old_cursor.par()->next() && !old_cursor.par()->previous())
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-03-14 23:33:15 +00:00
|
|
|
|
// Do not delete empty paragraphs with keepempty set.
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (old_cursor.par()->layout()->keepempty)
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
// only do our magic if we changed paragraph
|
2002-03-21 17:27:08 +00:00
|
|
|
|
if (old_cursor.par() == cursor.par())
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-01-12 21:03:30 +00:00
|
|
|
|
// record if we have deleted a paragraph
|
|
|
|
|
// we can't possibly have deleted a paragraph before this point
|
|
|
|
|
bool deleted = false;
|
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
if ((old_cursor.par()->size() == 0
|
|
|
|
|
|| (old_cursor.par()->size() == 1
|
|
|
|
|
&& old_cursor.par()->isLineSeparator(0)))) {
|
|
|
|
|
// ok, we will delete anything
|
|
|
|
|
LyXCursor tmpcursor;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
// make sure that you do not delete any environments
|
|
|
|
|
status(bview, LyXText::NEED_MORE_REFRESH);
|
|
|
|
|
deleted = true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
if (old_cursor.row()->previous()) {
|
|
|
|
|
refresh_row = old_cursor.row()->previous();
|
|
|
|
|
refresh_y = old_cursor.y() - old_cursor.row()->baseline() - refresh_row->height();
|
|
|
|
|
tmpcursor = cursor;
|
|
|
|
|
cursor = old_cursor; // that undo can restore the right cursor position
|
|
|
|
|
Paragraph * endpar = old_cursor.par()->next();
|
|
|
|
|
if (endpar && endpar->getDepth()) {
|
|
|
|
|
while (endpar && endpar->getDepth()) {
|
|
|
|
|
endpar = endpar->next();
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2001-09-27 10:52:53 +00:00
|
|
|
|
}
|
|
|
|
|
setUndo(bview, Undo::DELETE, old_cursor.par(), endpar);
|
|
|
|
|
cursor = tmpcursor;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
|
2001-12-05 16:11:47 +00:00
|
|
|
|
// delete old row
|
2001-09-27 10:52:53 +00:00
|
|
|
|
removeRow(old_cursor.row());
|
|
|
|
|
if (ownerParagraph() == old_cursor.par()) {
|
|
|
|
|
ownerParagraph(ownerParagraph()->next());
|
|
|
|
|
}
|
2002-01-12 21:03:30 +00:00
|
|
|
|
// delete old par
|
2001-09-27 10:52:53 +00:00
|
|
|
|
delete old_cursor.par();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
/* Breakagain the next par. Needed because of
|
|
|
|
|
* the parindent that can occur or dissappear.
|
|
|
|
|
* The next row can change its height, if
|
|
|
|
|
* there is another layout before */
|
|
|
|
|
if (refresh_row->next()) {
|
|
|
|
|
breakAgain(bview, refresh_row->next());
|
|
|
|
|
updateCounters(bview, refresh_row);
|
|
|
|
|
}
|
|
|
|
|
setHeightOfRow(bview, refresh_row);
|
|
|
|
|
} else {
|
|
|
|
|
refresh_row = old_cursor.row()->next();
|
|
|
|
|
refresh_y = old_cursor.y() - old_cursor.row()->baseline();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
tmpcursor = cursor;
|
|
|
|
|
cursor = old_cursor; // that undo can restore the right cursor position
|
|
|
|
|
Paragraph * endpar = old_cursor.par()->next();
|
|
|
|
|
if (endpar && endpar->getDepth()) {
|
|
|
|
|
while (endpar && endpar->getDepth()) {
|
|
|
|
|
endpar = endpar->next();
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2001-09-27 10:52:53 +00:00
|
|
|
|
}
|
|
|
|
|
setUndo(bview, Undo::DELETE, old_cursor.par(), endpar);
|
|
|
|
|
cursor = tmpcursor;
|
|
|
|
|
|
|
|
|
|
// delete old row
|
|
|
|
|
removeRow(old_cursor.row());
|
|
|
|
|
// delete old par
|
|
|
|
|
if (ownerParagraph() == old_cursor.par()) {
|
|
|
|
|
ownerParagraph(ownerParagraph()->next());
|
|
|
|
|
}
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
delete old_cursor.par();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
/* Breakagain the next par. Needed because of
|
|
|
|
|
the parindent that can occur or dissappear.
|
|
|
|
|
The next row can change its height, if
|
|
|
|
|
there is another layout before */
|
|
|
|
|
if (refresh_row) {
|
|
|
|
|
breakAgain(bview, refresh_row);
|
|
|
|
|
updateCounters(bview, refresh_row->previous());
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2001-09-27 10:52:53 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
// correct cursor y
|
|
|
|
|
setCursorIntern(bview, cursor.par(), cursor.pos());
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
if (selection.cursor.par() == old_cursor.par()
|
2002-01-12 21:03:30 +00:00
|
|
|
|
&& selection.cursor.pos() == old_cursor.pos()) {
|
2001-09-27 10:52:53 +00:00
|
|
|
|
// correct selection
|
|
|
|
|
selection.cursor = cursor;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2001-09-27 10:52:53 +00:00
|
|
|
|
}
|
|
|
|
|
if (!deleted) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (old_cursor.par()->stripLeadingSpaces()) {
|
2001-09-27 10:52:53 +00:00
|
|
|
|
redoParagraphs(bview, old_cursor,
|
|
|
|
|
old_cursor.par()->next());
|
|
|
|
|
// correct cursor y
|
|
|
|
|
setCursorIntern(bview, cursor.par(), cursor.pos());
|
|
|
|
|
selection.cursor = cursor;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return deleted;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::toggleAppendix(BufferView * bview)
|
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = cursor.par();
|
|
|
|
|
bool start = !par->params().startOfAppendix();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
|
|
|
|
// ensure that we have only one start_of_appendix in this document
|
2002-01-13 00:33:21 +00:00
|
|
|
|
Paragraph * tmp = ownerParagraph();
|
2001-07-07 18:19:18 +00:00
|
|
|
|
for (; tmp; tmp = tmp->next()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
tmp->params().startOfAppendix(false);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().startOfAppendix(start);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
|
|
|
|
// we can set the refreshing parameters now
|
2001-07-06 15:57:54 +00:00
|
|
|
|
status(bview, LyXText::NEED_MORE_REFRESH);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
refresh_y = 0;
|
|
|
|
|
refresh_row = 0; // not needed for full update
|
2001-06-25 00:06:33 +00:00
|
|
|
|
updateCounters(bview, 0);
|
|
|
|
|
setCursor(bview, cursor.par(), cursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-18 17:45:27 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * LyXText::ownerParagraph() const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (inset_owner) {
|
2001-07-06 15:57:54 +00:00
|
|
|
|
return inset_owner->paragraph();
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
return bv_owner->buffer()->paragraph;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-10-18 16:17:46 +00:00
|
|
|
|
void LyXText::ownerParagraph(Paragraph * p) const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (inset_owner) {
|
2001-07-06 15:57:54 +00:00
|
|
|
|
inset_owner->paragraph(p);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
} else {
|
2000-06-12 11:27:15 +00:00
|
|
|
|
bv_owner->buffer()->paragraph = p;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
|
2001-10-18 16:17:46 +00:00
|
|
|
|
|
|
|
|
|
void LyXText::ownerParagraph(int id, Paragraph * p) const
|
2001-07-06 15:57:54 +00:00
|
|
|
|
{
|
2001-07-09 09:16:00 +00:00
|
|
|
|
Paragraph * op = bv_owner->buffer()->getParFromID(id);
|
2001-07-11 12:10:46 +00:00
|
|
|
|
if (op && op->inInset()) {
|
|
|
|
|
static_cast<InsetText *>(op->inInset())->paragraph(p);
|
2001-07-06 15:57:54 +00:00
|
|
|
|
} else {
|
2001-12-13 11:35:25 +00:00
|
|
|
|
ownerParagraph(p);
|
2001-07-06 15:57:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXText::text_status LyXText::status() const
|
|
|
|
|
{
|
|
|
|
|
return status_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::status(BufferView * bview, LyXText::text_status st) const
|
|
|
|
|
{
|
2001-07-17 15:39:12 +00:00
|
|
|
|
// We should only go up with refreshing code so this means that if
|
|
|
|
|
// we have a MORE refresh we should never set it to LITTLE if we still
|
|
|
|
|
// didn't handle it (and then it will be UNCHANGED. Now as long as
|
|
|
|
|
// we stay inside one LyXText this may work but we need to tell the
|
|
|
|
|
// outermost LyXText that it should REALLY draw us if there is some
|
|
|
|
|
// change in a Inset::LyXText. So you see that when we are inside a
|
|
|
|
|
// inset's LyXText we give the LITTLE to the outermost LyXText to
|
|
|
|
|
// tell'em that it should redraw the actual row (where the inset
|
|
|
|
|
// resides! Capito?!
|
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if ((status_ != NEED_MORE_REFRESH)
|
|
|
|
|
|| (status_ == NEED_MORE_REFRESH
|
2001-07-17 15:39:12 +00:00
|
|
|
|
&& st != NEED_VERY_LITTLE_REFRESH))
|
|
|
|
|
{
|
2001-07-07 18:19:18 +00:00
|
|
|
|
status_ = st;
|
|
|
|
|
if (inset_owner && st != UNCHANGED) {
|
|
|
|
|
bview->text->status(bview, NEED_VERY_LITTLE_REFRESH);
|
2001-08-01 15:42:53 +00:00
|
|
|
|
if (!bview->text->refresh_row) {
|
|
|
|
|
bview->text->refresh_row = bview->text->cursor.row();
|
|
|
|
|
bview->text->refresh_y = bview->text->cursor.y() -
|
|
|
|
|
bview->text->cursor.row()->baseline();
|
|
|
|
|
}
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
}
|