1999-09-27 18:44:28 +00:00
|
|
|
|
/* This file is part of
|
1999-10-07 18:44:17 +00:00
|
|
|
|
* ======================================================
|
|
|
|
|
*
|
|
|
|
|
* LyX, The Document Processor
|
|
|
|
|
*
|
|
|
|
|
* 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"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "insets/inseterror.h"
|
2000-02-18 22:22:42 +00:00
|
|
|
|
#include "insets/insetbib.h"
|
2000-02-29 02:19:17 +00:00
|
|
|
|
#include "insets/insetspecialchar.h"
|
2000-06-21 15:07:57 +00:00
|
|
|
|
#include "insets/insettext.h"
|
2000-07-18 17:45:27 +00:00
|
|
|
|
#include "insets/insetfloat.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "layout.h"
|
|
|
|
|
#include "LyXView.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/textutils.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 "lyx_gui_misc.h"
|
|
|
|
|
#include "gettext.h"
|
1999-12-19 22:35:36 +00:00
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "LyXView.h"
|
2000-04-10 14:29:05 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
|
#include "Painter.h"
|
|
|
|
|
#include "font.h"
|
2000-04-08 17:02:02 +00:00
|
|
|
|
#include "debug.h"
|
2000-07-10 10:31:34 +00:00
|
|
|
|
#include "lyxrc.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"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
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;
|
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)
|
2001-07-06 15:41:17 +00:00
|
|
|
|
: number_of_rows(0), height(0), width(0), first(0),
|
|
|
|
|
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),
|
|
|
|
|
status_(LyXText::UNCHANGED), firstrow(0), lastrow(0),
|
|
|
|
|
copylayouttype(0)
|
2001-07-06 15:41:17 +00:00
|
|
|
|
{}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXText::LyXText(InsetText * inset)
|
2001-07-06 15:41:17 +00:00
|
|
|
|
: number_of_rows(0), height(0), width(0), first(0),
|
|
|
|
|
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),
|
|
|
|
|
status_(LyXText::UNCHANGED), firstrow(0), lastrow(0),
|
|
|
|
|
copylayouttype(0)
|
2001-07-06 15:41:17 +00:00
|
|
|
|
{}
|
1999-09-27 18:44:28 +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;
|
|
|
|
|
}
|
|
|
|
|
lastrow = refresh_row = need_break_row = 0;
|
|
|
|
|
width = height = copylayouttype = 0;
|
|
|
|
|
number_of_rows = first = refresh_y = 0;
|
|
|
|
|
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);
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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,
|
2001-07-27 12:03:36 +00:00
|
|
|
|
Paragraph::size_type pos) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXLayout const & layout =
|
2001-06-25 00:06:33 +00:00
|
|
|
|
textclasslist.Style(buf->params.textclass, par->getLayout());
|
1999-09-27 18:44:28 +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) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (pos >= 0){
|
|
|
|
|
// 95% goes here
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (layout.labeltype == LABEL_MANUAL
|
2001-06-25 00:06:33 +00:00
|
|
|
|
&& pos < beginningOfMainBody(buf, par)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// 1% goes here
|
2001-06-25 00:06:33 +00:00
|
|
|
|
LyXFont f = par->getFontSettings(buf->params,
|
2000-09-14 17:53:12 +00:00
|
|
|
|
pos);
|
2001-07-27 12:03:36 +00:00
|
|
|
|
return f.realize(layout.reslabelfont, buf->params.language);
|
2000-09-14 17:53:12 +00:00
|
|
|
|
} else {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
LyXFont f = par->getFontSettings(buf->params, pos);
|
2001-07-27 12:03:36 +00:00
|
|
|
|
return f.realize(layout.resfont, buf->params.language);
|
2000-09-14 17:53:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
// 5% goes here.
|
|
|
|
|
// process layoutfont for pos == -1 and labelfont for pos < -1
|
|
|
|
|
if (pos == -1)
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return layout.resfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return layout.reslabelfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The uncommon case need not be optimized as much
|
|
|
|
|
|
|
|
|
|
LyXFont layoutfont, tmpfont;
|
|
|
|
|
|
|
|
|
|
if (pos >= 0){
|
|
|
|
|
// 95% goes here
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (pos < beginningOfMainBody(buf, par)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// 1% goes here
|
1999-11-04 01:40:20 +00:00
|
|
|
|
layoutfont = layout.labelfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
// 99% goes here
|
1999-11-04 01:40:20 +00:00
|
|
|
|
layoutfont = layout.font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
tmpfont = par->getFontSettings(buf->params, pos);
|
2001-07-27 12:03:36 +00:00
|
|
|
|
tmpfont.realize(layoutfont, buf->params.language);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
} else {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// 5% goes here.
|
|
|
|
|
// process layoutfont for pos == -1 and labelfont for pos < -1
|
|
|
|
|
if (pos == -1)
|
1999-11-04 01:40:20 +00:00
|
|
|
|
tmpfont = layout.font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-11-04 01:40:20 +00:00
|
|
|
|
tmpfont = layout.labelfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resolve against environment font information
|
1999-11-04 01:40:20 +00:00
|
|
|
|
while (par && par_depth && !tmpfont.resolved()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par = par->outerHook();
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (par) {
|
|
|
|
|
tmpfont.realize(textclasslist.
|
2000-06-12 11:27:15 +00:00
|
|
|
|
Style(buf->params.textclass,
|
2001-07-27 12:03:36 +00:00
|
|
|
|
par->getLayout()).font,
|
|
|
|
|
buf->params.language);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par_depth = par->getDepth();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-27 12:03:36 +00:00
|
|
|
|
tmpfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(),
|
|
|
|
|
buf->params.language);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
return tmpfont;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setCharFont(BufferView * bv, Paragraph * par,
|
|
|
|
|
Paragraph::size_type pos, LyXFont const & fnt,
|
2001-05-28 15:11:24 +00:00
|
|
|
|
bool toggleall)
|
|
|
|
|
{
|
|
|
|
|
Buffer const * buf = bv->buffer();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
LyXFont font = getFont(buf, par, pos);
|
2001-07-27 12:03:36 +00:00
|
|
|
|
font.update(fnt, toggleall);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
// Let the insets convert their font
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->getChar(pos) == Paragraph::META_INSET) {
|
|
|
|
|
Inset * inset = par->getInset(pos);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
if (inset) {
|
2001-06-28 10:25:20 +00:00
|
|
|
|
if (inset->editable()==Inset::HIGHLY_EDITABLE) {
|
2001-07-07 18:19:18 +00:00
|
|
|
|
UpdatableInset * uinset =
|
|
|
|
|
static_cast<UpdatableInset *>(inset);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
uinset->setFont(bv, fnt, toggleall, true);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
|
font = inset->convertFont(font);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LyXLayout const & layout =
|
|
|
|
|
textclasslist.Style(buf->params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout());
|
2001-05-28 15:11:24 +00:00
|
|
|
|
|
|
|
|
|
// Get concrete layout font to reduce against
|
|
|
|
|
LyXFont layoutfont;
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (pos < beginningOfMainBody(buf, par))
|
2001-05-28 15:11:24 +00:00
|
|
|
|
layoutfont = layout.labelfont;
|
|
|
|
|
else
|
|
|
|
|
layoutfont = layout.font;
|
|
|
|
|
|
|
|
|
|
// Realize against environment font information
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->getDepth()){
|
|
|
|
|
Paragraph * tp = par;
|
|
|
|
|
while (!layoutfont.resolved() && tp && tp->getDepth()) {
|
|
|
|
|
tp = tp->outerHook();
|
2001-05-28 15:11:24 +00:00
|
|
|
|
if (tp)
|
|
|
|
|
layoutfont.realize(textclasslist.
|
2001-07-27 12:03:36 +00:00
|
|
|
|
Style(buf->params.textclass,
|
|
|
|
|
tp->getLayout()).font,
|
|
|
|
|
buf->params.language);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-27 12:03:36 +00:00
|
|
|
|
layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(),
|
|
|
|
|
buf->params.language);
|
2001-05-28 15:11:24 +00:00
|
|
|
|
|
|
|
|
|
// Now, reduce font against full layout font
|
|
|
|
|
font.reduce(layoutfont);
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->setFont(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,
|
|
|
|
|
Paragraph::size_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-12-19 22:35:36 +00:00
|
|
|
|
// Let the insets convert their font
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->getChar(pos) == Paragraph::META_INSET) {
|
2001-06-28 10:25:20 +00:00
|
|
|
|
font = par->getInset(pos)->convertFont(font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-19 01:42:55 +00:00
|
|
|
|
LyXLayout const & layout =
|
2000-06-12 11:27:15 +00:00
|
|
|
|
textclasslist.Style(buf->params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout());
|
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))
|
1999-11-04 01:40:20 +00:00
|
|
|
|
layoutfont = layout.labelfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-11-04 01:40:20 +00:00
|
|
|
|
layoutfont = layout.font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Realize against environment font information
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->getDepth()){
|
|
|
|
|
Paragraph * tp = par;
|
|
|
|
|
while (!layoutfont.resolved() && tp && tp->getDepth()) {
|
|
|
|
|
tp = tp->outerHook();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (tp)
|
1999-11-04 01:40:20 +00:00
|
|
|
|
layoutfont.realize(textclasslist.
|
2001-07-27 12:03:36 +00:00
|
|
|
|
Style(buf->params.textclass,
|
|
|
|
|
tp->getLayout()).font,
|
|
|
|
|
buf->params.language);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-27 12:03:36 +00:00
|
|
|
|
layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(),
|
|
|
|
|
buf->params.language);
|
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,
|
2001-07-20 14:18:48 +00:00
|
|
|
|
Paragraph::size_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
|
|
|
|
}
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (tmprow->next())
|
|
|
|
|
tmprow->next()->previous(tmprow);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (tmprow->previous())
|
|
|
|
|
tmprow->previous()->next(tmprow);
|
1999-09-27 18:44:28 +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
|
|
|
|
{
|
|
|
|
|
/* this must not happen before the currentrow for clear reasons.
|
|
|
|
|
so the trick is just to set the current row onto the previous
|
|
|
|
|
row of this row */
|
2000-09-29 18:44:07 +00:00
|
|
|
|
int unused_y;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
getRow(row->par(), row->pos(), unused_y);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (row->next())
|
|
|
|
|
row->next()->previous(row->previous());
|
|
|
|
|
if (!row->previous()) {
|
|
|
|
|
firstrow = row->next();
|
2000-02-23 16:39:03 +00:00
|
|
|
|
} else {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
row->previous()->next(row->next());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
if (row == lastrow)
|
2000-06-08 23:16:16 +00:00
|
|
|
|
lastrow = row->previous();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
height -= row->height(); // the text becomes smaller
|
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();
|
1999-09-27 18:44:28 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
2001-07-20 14:18:48 +00:00
|
|
|
|
Row * row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-20 14:18:48 +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
|
1999-09-27 18:44:28 +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;
|
2001-07-11 12:10:46 +00:00
|
|
|
|
} else if (cursor.pos() < cursor.par()->size()
|
|
|
|
|
&& cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET) {
|
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();
|
|
|
|
|
if (!inset->editable())
|
|
|
|
|
return;
|
|
|
|
|
//bview->owner()->message(inset->editMessage());
|
|
|
|
|
|
|
|
|
|
// do we want to keep this?? (JMarc)
|
|
|
|
|
if (inset->editable() != Inset::HIGHLY_EDITABLE)
|
|
|
|
|
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
|
|
|
|
{
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LyXLayout const & layout =
|
2001-06-25 00:06:33 +00:00
|
|
|
|
textclasslist.Style(buf->params.textclass, par->getLayout());
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
|
LyXFont layoutfont, tmpfont;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::size_type pos = 0;
|
2001-03-11 00:21:13 +00:00
|
|
|
|
pos < par->size(); ++pos) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (pos < beginningOfMainBody(buf, par))
|
1999-11-04 01:40:20 +00:00
|
|
|
|
layoutfont = layout.labelfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-11-04 01:40:20 +00:00
|
|
|
|
layoutfont = layout.font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
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,
|
|
|
|
|
LyXTextClass::size_type 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;
|
2001-04-04 21:47:26 +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.
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setUndo(bview, Undo::EDIT,
|
|
|
|
|
sstart_cur.par(), undoendpar);
|
2001-04-04 21:47:26 +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;
|
|
|
|
|
|
|
|
|
|
LyXLayout const & lyxlayout =
|
|
|
|
|
textclasslist.Style(bview->buffer()->params.textclass, layout);
|
|
|
|
|
|
|
|
|
|
while (cur.par() != send_cur.par()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cur.par()->setLayout(layout);
|
|
|
|
|
makeFontEntriesLayoutSpecific(bview->buffer(), cur.par());
|
|
|
|
|
Paragraph * fppar = cur.par();
|
|
|
|
|
fppar->params().spaceTop(lyxlayout.fill_top ?
|
2001-07-07 18:19:18 +00:00
|
|
|
|
VSpace(VSpace::VFILL)
|
|
|
|
|
: VSpace(VSpace::NONE));
|
2001-06-25 00:06:33 +00:00
|
|
|
|
fppar->params().spaceBottom(lyxlayout.fill_bottom ?
|
2001-07-07 18:19:18 +00:00
|
|
|
|
VSpace(VSpace::VFILL)
|
|
|
|
|
: VSpace(VSpace::NONE));
|
2000-05-04 08:14:34 +00:00
|
|
|
|
if (lyxlayout.margintype == MARGIN_MANUAL)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cur.par()->setLabelWidthString(lyxlayout.labelstring());
|
2000-05-04 08:14:34 +00:00
|
|
|
|
if (lyxlayout.labeltype != LABEL_BIBLIO
|
|
|
|
|
&& fppar->bibkey) {
|
|
|
|
|
delete fppar->bibkey;
|
|
|
|
|
fppar->bibkey = 0;
|
|
|
|
|
}
|
2001-04-04 21:47:26 +00:00
|
|
|
|
cur.par(cur.par()->next());
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cur.par()->setLayout(layout);
|
|
|
|
|
makeFontEntriesLayoutSpecific(bview->buffer(), cur.par());
|
|
|
|
|
Paragraph * fppar = cur.par();
|
|
|
|
|
fppar->params().spaceTop(lyxlayout.fill_top ?
|
2001-07-07 18:19:18 +00:00
|
|
|
|
VSpace(VSpace::VFILL) : VSpace(VSpace::NONE));
|
2001-06-25 00:06:33 +00:00
|
|
|
|
fppar->params().spaceBottom(lyxlayout.fill_bottom ?
|
2001-07-07 18:19:18 +00:00
|
|
|
|
VSpace(VSpace::VFILL) : VSpace(VSpace::NONE));
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (lyxlayout.margintype == MARGIN_MANUAL)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cur.par()->setLabelWidthString(lyxlayout.labelstring());
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (lyxlayout.labeltype != LABEL_BIBLIO
|
|
|
|
|
&& fppar->bibkey) {
|
|
|
|
|
delete fppar->bibkey;
|
|
|
|
|
fppar->bibkey = 0;
|
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
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setLayout(BufferView * bview, LyXTextClass::size_type 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);
|
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());
|
|
|
|
|
clearSelection(bview);
|
|
|
|
|
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.
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
bool anything_changed = false;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
// NOTE: you can't change the depth of a bibliography entry
|
|
|
|
|
if (
|
2001-07-07 18:19:18 +00:00
|
|
|
|
textclasslist.Style(bview->buffer()->params.textclass,
|
|
|
|
|
cursor.par()->getLayout()
|
|
|
|
|
).labeltype != LABEL_BIBLIO) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * prev = cursor.par()->previous();
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
|
|
|
|
if (prev
|
2001-06-25 00:06:33 +00:00
|
|
|
|
&& (prev->getDepth() - cursor.par()->getDepth() > 0
|
|
|
|
|
|| (prev->getDepth() == cursor.par()->getDepth()
|
2001-05-31 02:23:46 +00:00
|
|
|
|
&& textclasslist.Style(bview->buffer()->params.textclass,
|
2001-07-07 18:19:18 +00:00
|
|
|
|
prev->getLayout()).isEnvironment()))) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cursor.par()->params().depth(cursor.par()->params().depth() + 1);
|
2001-05-31 02:23:46 +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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
redoParagraphs(bview, selection.start, endpar);
|
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());
|
|
|
|
|
clearSelection(bview);
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
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);
|
1999-09-27 18:44:28 +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());
|
|
|
|
|
clearSelection(bview);
|
|
|
|
|
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(),
|
2000-06-12 11:27:15 +00:00
|
|
|
|
cursor.par()))
|
2001-06-25 00:06:33 +00:00
|
|
|
|
layoutfont = getFont(bview->buffer(), cursor.par(),-2);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2001-06-25 00:06:33 +00:00
|
|
|
|
layoutfont = getFont(bview->buffer(), cursor.par(),-1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Update current font
|
2001-07-27 12:03:36 +00:00
|
|
|
|
real_current_font.update(font, 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-07-27 12:03:36 +00:00
|
|
|
|
real_current_font.realize(layoutfont,
|
|
|
|
|
bview->buffer()->params.language);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setUndo(bview, Undo::EDIT,
|
|
|
|
|
selection.start.par(),
|
2001-05-31 02:23:46 +00:00
|
|
|
|
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() ||
|
|
|
|
|
(cursor.pos() < selection.end.pos())) {
|
2001-05-03 14:31:33 +00:00
|
|
|
|
if (cursor.pos() < cursor.par()->size()) {
|
2000-01-13 16:28:54 +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();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
redoParagraphs(bview, selection.start, selection.end.par()->next());
|
1999-09-27 18:44:28 +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(), 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());
|
|
|
|
|
clearSelection(bview);
|
|
|
|
|
setSelection(bview);
|
|
|
|
|
setCursor(bview, tmpcursor.par(), tmpcursor.pos(), true,
|
2000-06-12 11:27:15 +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);
|
2001-07-03 15:19:04 +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
|
|
|
|
}
|
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();
|
1999-09-27 18:44:28 +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
|
|
|
|
|
// and the specified par
|
|
|
|
|
// 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,
|
|
|
|
|
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;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
Row * tmprow = cur.row();
|
1999-09-27 18:44:28 +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
|
|
|
|
|
// Can somebody please tell me _why_ this solves
|
|
|
|
|
// anything. (Lgb)
|
|
|
|
|
first_phys_par = firstParagraph();
|
|
|
|
|
} else {
|
|
|
|
|
first_phys_par = tmprow->par();
|
|
|
|
|
while (tmprow->previous()
|
|
|
|
|
&& tmprow->previous()->par() == first_phys_par) {
|
|
|
|
|
tmprow = tmprow->previous();
|
|
|
|
|
y -= tmprow->height();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2001-07-07 18:19:18 +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;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (tmppar != endpar) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
removeRow(tmprow->next());
|
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;
|
1999-09-27 18:44:28 +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()
|
2000-01-13 16:28:54 +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);
|
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);
|
1999-09-27 18:44:28 +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();
|
2001-06-25 00:06:33 +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;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setHeightOfRow(bview, refresh_row);
|
1999-09-27 18:44:28 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
bool LyXText::fullRebreak(BufferView * bview)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-21 15:07:57 +00:00
|
|
|
|
if (!firstrow) {
|
|
|
|
|
init(bview);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
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;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-04-26 13:57:28 +00:00
|
|
|
|
return false;
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* the cursor set functions have a special mechanism. When they
|
2000-05-20 21:37:05 +00:00
|
|
|
|
* realize, that you left an empty paragraph, they will delete it.
|
|
|
|
|
* They also delete the corresponding row */
|
1999-09-27 18:44:28 +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
|
|
|
|
}
|
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.set(true);
|
1999-09-27 18:44:28 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
last_sel_cursor = cursor;
|
|
|
|
|
|
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 {
|
|
|
|
|
selection.end = selection.cursor;
|
|
|
|
|
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 {
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.end = selection.cursor;
|
|
|
|
|
selection.start = cursor;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// a selection with no contents is not a selection
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (selection.start.par() == selection.end.par() &&
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const LyXText::selectionAsString(Buffer const * buffer) 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;
|
|
|
|
|
|
|
|
|
|
// 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(),
|
|
|
|
|
selection.end.pos());
|
2000-05-20 21:37:05 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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(),
|
|
|
|
|
selection.start.par()->size())
|
2001-03-11 00:21:13 +00:00
|
|
|
|
+ "\n\n";
|
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,
|
|
|
|
|
tmpcur.par()->size()) +"\n\n";
|
|
|
|
|
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,
|
|
|
|
|
selection.end.pos());
|
2000-05-20 21:37:05 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::clearSelection(BufferView * /*bview*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.set(false);
|
|
|
|
|
selection.mark(false);
|
2001-07-20 14:18:48 +00:00
|
|
|
|
selection.end = selection.start = selection.cursor = cursor;
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::toggleFree(BufferView * bview,
|
2001-05-28 15:11:24 +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
|
2000-04-24 20:58:23 +00:00
|
|
|
|
// If there is a change in the language the implicit word selection
|
|
|
|
|
// 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
|
2001-07-27 12:03:36 +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-06-25 00:06:33 +00:00
|
|
|
|
clearSelection(bview);
|
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-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::size_type
|
|
|
|
|
LyXText::beginningOfMainBody(Buffer const * buf,
|
|
|
|
|
Paragraph const * par) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (textclasslist.Style(buf->params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout()).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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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! */
|
|
|
|
|
|
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,
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXAlignment align,
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string labelwidthstring,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
bool noindent)
|
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setUndo(bview, Undo::EDIT, selection.start.par(), undoendpar);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * tmppar = selection.end.par();
|
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);
|
|
|
|
|
// does the layout allow the new alignment?
|
|
|
|
|
if (align == LYX_ALIGN_LAYOUT)
|
|
|
|
|
align = textclasslist
|
|
|
|
|
.Style(bview->buffer()->params.textclass,
|
|
|
|
|
cursor.par()->getLayout()).align;
|
|
|
|
|
if (align & textclasslist
|
|
|
|
|
.Style(bview->buffer()->params.textclass,
|
|
|
|
|
cursor.par()->getLayout()).alignpossible) {
|
|
|
|
|
if (align == textclasslist
|
2000-06-12 11:27:15 +00:00
|
|
|
|
.Style(bview->buffer()->params.textclass,
|
2001-07-07 18:19:18 +00:00
|
|
|
|
cursor.par()->getLayout()).align)
|
|
|
|
|
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
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
redoParagraphs(bview, selection.start, endpar);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
clearSelection(bview);
|
|
|
|
|
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>',
|
|
|
|
|
'<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>', '<EFBFBD>',
|
|
|
|
|
'<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
|
|
|
|
{
|
2000-04-19 01:42:55 +00:00
|
|
|
|
LyXLayout const & layout =
|
2000-06-12 11:27:15 +00:00
|
|
|
|
textclasslist.Style(buf->params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LyXTextClass const & textclass =
|
2000-06-12 11:27:15 +00:00
|
|
|
|
textclasslist.TextClass(buf->params.textclass);
|
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);
|
|
|
|
|
}
|
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);
|
|
|
|
|
}
|
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()
|
2000-06-12 11:27:15 +00:00
|
|
|
|
&& textclasslist.Style(buf->params.textclass,
|
2001-07-07 18:19:18 +00:00
|
|
|
|
par->previous()->getLayout()
|
|
|
|
|
).labeltype == LABEL_COUNTER_ENUMI
|
1999-09-27 18:44:28 +00:00
|
|
|
|
&& par->enumdepth < 3
|
1999-11-04 01:40:20 +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()
|
1999-11-04 01:40:20 +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));
|
1999-09-27 18:44:28 +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);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (layout.margintype == MARGIN_MANUAL) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->params().labelWidthString().empty()) {
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// is it a layout that has an automatic label?
|
2000-07-17 18:27:53 +00:00
|
|
|
|
if (layout.labeltype >= LABEL_COUNTER_CHAPTER) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-17 18:27:53 +00:00
|
|
|
|
int i = layout.labeltype - LABEL_COUNTER_CHAPTER;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (i >= 0 && i<= buf->params.secnumdepth) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
par->incCounter(i); // increment the counter
|
|
|
|
|
|
|
|
|
|
// Is there a label? Useful for Chapter layout
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (!par->params().appendix()) {
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (!layout.labelstring().empty())
|
2001-06-25 00:06:33 +00:00
|
|
|
|
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());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
} else {
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (!layout.labelstring_appendix().empty())
|
2001-06-25 00:06:33 +00:00
|
|
|
|
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);
|
|
|
|
|
|
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) << '.';
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
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) << '.';
|
2000-03-08 01:45:25 +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...
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
1999-11-04 01:40:20 +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);
|
|
|
|
|
}
|
1999-11-04 01:40:20 +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);
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-11-04 01:40:20 +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) {
|
|
|
|
|
InsetCommandParams p( "bibitem" );
|
|
|
|
|
par->bibkey = new InsetBibKey(p);
|
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
par->bibkey->setCounter(number);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().labelString(layout.labelstring());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
|
|
|
|
// In biblio should't be following counters but...
|
|
|
|
|
} else {
|
1999-11-04 01:40:20 +00:00
|
|
|
|
string s = layout.labelstring();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
|
|
|
|
// the caption hack:
|
1999-11-04 01:40:20 +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));
|
2001-05-31 22:34:05 +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 {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/* par->SetLayout(0);
|
|
|
|
|
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);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/* reset the enumeration counter. They are always resetted
|
|
|
|
|
* 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();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCounter(bview->buffer(), par);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// now check for the headline layouts. remember that they
|
|
|
|
|
// have a dynamic left margin
|
2001-05-03 14:31:33 +00:00
|
|
|
|
if ((textclasslist.Style(bview->buffer()->params.textclass,
|
|
|
|
|
par->layout).margintype == MARGIN_DYNAMIC
|
|
|
|
|
|| textclasslist.Style(bview->buffer()->params.textclass,
|
|
|
|
|
par->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;
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setUndo(bview, Undo::INSERT,
|
|
|
|
|
cursor.par(), cursor.par()->next());
|
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);
|
2000-09-28 14:05:24 +00:00
|
|
|
|
#if 1
|
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-06-28 10:25:20 +00:00
|
|
|
|
if (inset->editable() == Inset::HIGHLY_EDITABLE) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cursorLeft(bview, true);
|
2000-09-28 14:05:24 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::copyEnvironmentType()
|
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
copylayouttype = cursor.par()->getLayout();
|
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-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::cutSelection(BufferView * bview, bool doclear)
|
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)
|
|
|
|
|
bview->stuffClipboard(selectionAsString(bview->buffer()));
|
|
|
|
|
|
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;
|
|
|
|
|
|
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;
|
2000-06-15 15:44:39 +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
|
|
|
|
}
|
2000-06-15 15:44:39 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setUndo(bview, Undo::DELETE,
|
|
|
|
|
selection.start.par(), undoendpar);
|
2000-06-15 15:44:39 +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,
|
2001-07-07 18:19:18 +00:00
|
|
|
|
selection.start.pos(), pos,
|
|
|
|
|
bview->buffer()->params.textclass, doclear);
|
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,
|
2001-07-07 18:19:18 +00:00
|
|
|
|
selection.start.pos(), pos,
|
|
|
|
|
bview->buffer()->params.textclass, doclear);
|
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)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
selection.start.par()->stripLeadingSpaces(bview->buffer()->params.textclass);
|
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-06-25 00:06:33 +00:00
|
|
|
|
clearSelection(bview);
|
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
|
|
|
|
{
|
2000-06-15 15:44:39 +00:00
|
|
|
|
// Stuff what we got on the clipboard. Even if there is no selection.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
|
// 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)
|
|
|
|
|
bview->stuffClipboard(selectionAsString(bview->buffer()));
|
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()))
|
|
|
|
|
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(),
|
2001-07-06 15:57:54 +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,
|
|
|
|
|
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-04-10 14:29:05 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
int pos = cursor.pos();
|
2001-07-03 15:39:17 +00:00
|
|
|
|
CutAndPaste::pasteSelection(&actpar, &endpar, pos,
|
2001-07-07 18:19:18 +00:00
|
|
|
|
bview->buffer()->params.textclass);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
redoParagraphs(bview, cursor, endpar);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, cursor.par(), cursor.pos());
|
|
|
|
|
clearSelection(bview);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, actpar, pos);
|
|
|
|
|
setSelection(bview);
|
|
|
|
|
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
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// returns a pointer to the very first Paragraph
|
|
|
|
|
Paragraph * LyXText::firstParagraph() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return ownerParagraph();
|
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;
|
|
|
|
|
|
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-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::size_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
|
|
|
|
}
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Cut the selection
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cutSelection(bview);
|
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();
|
|
|
|
|
Paragraph::size_type pos = cursor.pos();
|
|
|
|
|
Paragraph * endpar = cursor.par()->next();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
setCursorParUndo(bview);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
|
|
|
|
// only to be sure, should not be neccessary
|
2001-06-25 00:06:33 +00:00
|
|
|
|
clearSelection(bview);
|
2000-01-13 16:28:54 +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;
|
|
|
|
|
}
|
|
|
|
|
} 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,
|
2001-01-15 18:54:31 +00:00
|
|
|
|
std::vector<Inset::Code> const & codes,
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
} while (res.par() &&
|
2001-06-25 00:06:33 +00:00
|
|
|
|
!(res.par()->getChar(res.pos()) == Paragraph::META_INSET
|
|
|
|
|
&& (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-06-25 00:06:33 +00:00
|
|
|
|
setCursor(bview, res.par(), res.pos());
|
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,
|
|
|
|
|
Paragraph::size_type pos)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-04-26 13:57:28 +00:00
|
|
|
|
LyXCursor tmpcursor;
|
|
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
|
int y = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::size_type z;
|
|
|
|
|
Row * row = getRow(par, pos, y);
|
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);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
breakAgain(bview, row->previous());
|
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-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::size_type const tmplast = rowLast(row);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
refresh_y = y;
|
|
|
|
|
refresh_row = row;
|
|
|
|
|
|
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
|
2001-07-06 15:57:54 +00:00
|
|
|
|
status(bview, LyXText::NEED_MORE_REFRESH);
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
|
|
|
|
// check the special right address boxes
|
|
|
|
|
if (textclasslist.Style(bview->buffer()->params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout()).margintype
|
2000-09-23 04:57:18 +00:00
|
|
|
|
== MARGIN_RIGHT_ADDRESS_BOX) {
|
|
|
|
|
tmpcursor.par(par);
|
|
|
|
|
tmpcursor.row(row);
|
|
|
|
|
tmpcursor.y(y);
|
|
|
|
|
tmpcursor.x(0);
|
|
|
|
|
tmpcursor.x_fix(0);
|
|
|
|
|
tmpcursor.pos(pos);
|
2001-06-25 00:06:33 +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
|
|
|
|
|
|
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());
|
|
|
|
|
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());
|
|
|
|
|
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());
|
|
|
|
|
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());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
last_sel_cursor = cursor;
|
|
|
|
|
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);
|
1999-09-27 18:44:28 +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
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// check every paragraph
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = firstParagraph();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
do {
|
2001-07-07 18:19:18 +00:00
|
|
|
|
pos = par->getPositionOfInset(inset);
|
|
|
|
|
if (pos != -1){
|
|
|
|
|
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);
|
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setCursor(BufferView * bview, Paragraph * par,
|
|
|
|
|
Paragraph::size_type pos,
|
2000-05-30 19:31:11 +00:00
|
|
|
|
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);
|
|
|
|
|
deleteEmptyParagraphMechanism(bview, old_cursor);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::setCursor(BufferView *bview, LyXCursor & cur, Paragraph * par,
|
|
|
|
|
Paragraph::size_type pos, bool boundary) const
|
2000-04-19 14:42: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);
|
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();
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// y is now the cursor baseline
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cur.y(y);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// now get the cursors x position
|
2000-04-19 14:42:19 +00:00
|
|
|
|
float x;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
float fill_separator;
|
|
|
|
|
float fill_hfill;
|
|
|
|
|
float fill_label_hfill;
|
|
|
|
|
prepareToPrint(bview, row, x, fill_separator, fill_hfill,
|
2000-06-12 11:27:15 +00:00
|
|
|
|
fill_label_hfill);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::size_type cursor_vpos = 0;
|
|
|
|
|
Paragraph::size_type last = rowLastPrintable(row);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
|
|
|
|
if (pos > last + 1) // This shouldn't happen.
|
2000-06-08 23:16:16 +00:00
|
|
|
|
pos = last + 1;
|
|
|
|
|
else if (pos < row->pos())
|
|
|
|
|
pos = row->pos();
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (last < row->pos())
|
|
|
|
|
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))
|
2000-06-08 23:16:16 +00:00
|
|
|
|
? row->pos() : last + 1;
|
|
|
|
|
else if (pos > row->pos() &&
|
2000-09-23 04:57:18 +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;
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::size_type main_body =
|
|
|
|
|
beginningOfMainBody(bview->buffer(), row->par());
|
2000-09-23 04:57:18 +00:00
|
|
|
|
if ((main_body > 0) &&
|
|
|
|
|
((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;
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::size_type vpos = row->pos();
|
2000-09-23 04:57:18 +00:00
|
|
|
|
vpos < cursor_vpos; ++vpos) {
|
|
|
|
|
pos = vis2log(vpos);
|
|
|
|
|
if (main_body > 0 && pos == main_body - 1) {
|
|
|
|
|
x += fill_label_hfill +
|
|
|
|
|
lyxfont::width(textclasslist.Style(
|
|
|
|
|
bview->buffer()->params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
row->par()->getLayout())
|
2000-09-23 04:57:18 +00:00
|
|
|
|
.labelsep,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
getFont(bview->buffer(), row->par(), -2));
|
|
|
|
|
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;
|
|
|
|
|
else
|
|
|
|
|
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
|
|
|
|
}
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cur.x(int(x));
|
|
|
|
|
cur.x_fix(cur.x());
|
|
|
|
|
cur.row(row);
|
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,
|
|
|
|
|
Paragraph::size_type pos,
|
2000-05-30 19:31:11 +00:00
|
|
|
|
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-07-06 15:57:54 +00:00
|
|
|
|
if (it && (it != inset_owner)) {
|
|
|
|
|
it->getLyXText(bview)->setCursorIntern(bview, par, pos, setfont,
|
2001-07-07 18:19:18 +00:00
|
|
|
|
boundary);
|
2001-07-06 15:57:54 +00:00
|
|
|
|
} else {
|
|
|
|
|
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-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::size_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() &&
|
|
|
|
|
bidi_level(pos) % 2 ==
|
|
|
|
|
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;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// Get the row first.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Row * row = getRowNearY(y);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.par(row->par());
|
|
|
|
|
|
|
|
|
|
bool bound = false;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
int column = getColumnNearX(bview, row, x, bound);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.pos(row->pos() + column);
|
|
|
|
|
cursor.x(x);
|
|
|
|
|
cursor.y(y + row->baseline());
|
|
|
|
|
cursor.row(row);
|
|
|
|
|
cursor.boundary(bound);
|
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.
|
2000-03-27 15:13:47 +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-06-25 00:06:33 +00:00
|
|
|
|
int column = getColumnNearX(bview, row, x, bound);
|
2000-03-27 15:13:47 +00:00
|
|
|
|
|
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());
|
|
|
|
|
cur.row(row);
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::cursorUp(BufferView * bview) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursorFromCoordinates(bview, cursor.x_fix(),
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.y() - cursor.row()->baseline() - 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void LyXText::cursorDown(BufferView * bview) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursorFromCoordinates(bview, cursor.x_fix(),
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.y() - cursor.row()->baseline()
|
|
|
|
|
+ cursor.row()->height() + 1);
|
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-06-25 00:06:33 +00:00
|
|
|
|
void 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.
|
2001-05-31 02:23:46 +00:00
|
|
|
|
if (selection.set()) return;
|
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.
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (textclasslist.Style(bview->buffer()->params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
old_cursor.par()->getLayout()).free_spacing)
|
2000-03-09 03:36:48 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2000-03-14 23:33:15 +00:00
|
|
|
|
bool deleted = false;
|
|
|
|
|
|
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.
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
|
2000-05-26 16:13:01 +00:00
|
|
|
|
// Only if the cursor has really moved
|
2000-03-17 10:14:46 +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());
|
2000-03-14 23:33:15 +00:00
|
|
|
|
// correct cursor
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (old_cursor.par() == cursor.par() &&
|
|
|
|
|
cursor.pos() > old_cursor.pos()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursorIntern(bview, cursor.par(),
|
2000-06-12 11:27:15 +00:00
|
|
|
|
cursor.pos() - 1);
|
2000-04-12 14:58:27 +00:00
|
|
|
|
} else
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursorIntern(bview, cursor.par(),
|
2000-06-12 11:27:15 +00:00
|
|
|
|
cursor.pos());
|
2000-03-17 10:14:46 +00:00
|
|
|
|
return;
|
2000-03-14 23:33:15 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2000-03-14 23:33:15 +00:00
|
|
|
|
// Do not delete empty paragraphs with keepempty set.
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if ((textclasslist.Style(bview->buffer()->params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
old_cursor.par()->getLayout())).keepempty)
|
2000-01-13 16:28:54 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LyXCursor tmpcursor;
|
|
|
|
|
|
2001-03-11 00:21:13 +00:00
|
|
|
|
if (old_cursor.par() != cursor.par()) {
|
|
|
|
|
if ((old_cursor.par()->size() == 0
|
2001-07-07 18:19:18 +00:00
|
|
|
|
|| (old_cursor.par()->size() == 1
|
|
|
|
|
&& old_cursor.par()->isLineSeparator(0)))) {
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// ok, we will delete anything
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// make sure that you do not delete any environments
|
2001-07-07 18:19:18 +00:00
|
|
|
|
status(bview, LyXText::NEED_MORE_REFRESH);
|
|
|
|
|
deleted = true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +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();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
|
|
|
|
setUndo(bview, Undo::DELETE,
|
|
|
|
|
old_cursor.par(),
|
|
|
|
|
endpar);
|
|
|
|
|
cursor = tmpcursor;
|
|
|
|
|
|
|
|
|
|
// delete old row
|
|
|
|
|
removeRow(old_cursor.row());
|
|
|
|
|
if (ownerParagraph() == old_cursor.par()) {
|
|
|
|
|
ownerParagraph(ownerParagraph()->next());
|
|
|
|
|
}
|
|
|
|
|
// delete old par
|
|
|
|
|
delete old_cursor.par();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +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();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +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();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2001-07-07 18:19:18 +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-07-07 18:19:18 +00:00
|
|
|
|
delete old_cursor.par();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +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());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
|
|
|
|
// correct cursor y
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
setCursorIntern(bview, cursor.par(), cursor.pos());
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (selection.cursor.par() == old_cursor.par()
|
|
|
|
|
&& selection.cursor.pos() == selection.cursor.pos()) {
|
|
|
|
|
// correct selection
|
|
|
|
|
selection.cursor = cursor;
|
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
if (!deleted) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (old_cursor.par()->stripLeadingSpaces(bview->buffer()->params.textclass)) {
|
|
|
|
|
redoParagraphs(bview, old_cursor, old_cursor.par()->next());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// correct cursor y
|
2001-06-25 00:06:33 +00:00
|
|
|
|
setCursorIntern(bview, cursor.par(), cursor.pos());
|
2001-05-31 02:23:46 +00:00
|
|
|
|
selection.cursor = cursor;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * tmp = firstParagraph();
|
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
|
|
|
|
}
|
|
|
|
|
|
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-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * 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
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
|
|
|
|
|
Paragraph * LyXText::ownerParagraph(int id, Paragraph * p) const
|
|
|
|
|
{
|
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-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 {
|
2001-07-06 15:57:54 +00:00
|
|
|
|
bv_owner->buffer()->paragraph = p;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXText::text_status LyXText::status() const
|
|
|
|
|
{
|
|
|
|
|
return status_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::status(BufferView * bview, LyXText::text_status st) const
|
|
|
|
|
{
|
2001-07-07 18:19:18 +00:00
|
|
|
|
#if 0
|
|
|
|
|
if ((status_ != NEED_MORE_REFRESH)
|
|
|
|
|
|| (status_ == NEED_MORE_REFRESH)
|
|
|
|
|
&& (st != NEED_VERY_LITTLE_REFRESH)) {
|
2001-07-06 15:57:54 +00:00
|
|
|
|
status_ = st;
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (inset_owner && st != UNCHANGED) {
|
2001-07-06 15:57:54 +00:00
|
|
|
|
bview->text->status(bview, NEED_VERY_LITTLE_REFRESH);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
}
|
2001-07-07 18:19:18 +00:00
|
|
|
|
#else
|
2001-07-17 15:39:12 +00:00
|
|
|
|
#warning Please tell what the intention is here. (Lgb)
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// The above does not make any sense, I changed it to what is here,
|
|
|
|
|
//<2F>but it still does not make much sense. (Lgb)
|
2001-07-17 15:39:12 +00:00
|
|
|
|
#warning Sure have a look now! (Jug)
|
|
|
|
|
// well as much as I know && binds more then || so the above and the
|
|
|
|
|
// below are identical (this for your known use of parentesis!)
|
|
|
|
|
// Now some explanation:
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2001-07-06 15:57:54 +00:00
|
|
|
|
}
|