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
|
2000-03-16 04:29:22 +00:00
|
|
|
|
* Copyright 1995-2000 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>
|
|
|
|
|
|
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
|
|
1999-11-08 13:54:04 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#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"
|
|
|
|
|
#include "lyxparagraph.h"
|
|
|
|
|
#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"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "undo.h"
|
|
|
|
|
#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"
|
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)
|
|
|
|
|
{
|
|
|
|
|
bv_owner = bv;
|
|
|
|
|
inset_owner = 0;
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXText::LyXText(InsetText * inset)
|
|
|
|
|
{
|
|
|
|
|
inset_owner = inset;
|
|
|
|
|
bv_owner = 0;
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::init()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-10-03 13:55:48 +00:00
|
|
|
|
the_locking_inset = 0;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
firstrow = 0;
|
|
|
|
|
lastrow = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
number_of_rows = 0;
|
1999-11-15 12:01:38 +00:00
|
|
|
|
refresh_y = 0;
|
2000-06-23 15:02:46 +00:00
|
|
|
|
height = 0;
|
2000-06-26 15:10:49 +00:00
|
|
|
|
width = 0;
|
2000-06-22 14:55:46 +00:00
|
|
|
|
first = 0;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
status = LyXText::UNCHANGED;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// set cursor at the very top position
|
|
|
|
|
selection = true; /* these setting is necessary
|
|
|
|
|
because of the delete-empty-
|
|
|
|
|
paragraph mechanism in
|
|
|
|
|
SetCursor */
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (bv_owner) {
|
|
|
|
|
LyXParagraph * par = OwnerParagraph();
|
|
|
|
|
current_font = GetFont(bv_owner->buffer(), par, 0);
|
|
|
|
|
while (par) {
|
|
|
|
|
InsertParagraph(bv_owner, par, lastrow);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
SetCursor(bv_owner, firstrow->par(), 0);
|
|
|
|
|
} else
|
|
|
|
|
current_font = LyXFont(LyXFont::ALL_SANE);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_cursor = cursor;
|
|
|
|
|
selection = false;
|
|
|
|
|
mark_set = false;
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// no rebreak necessary
|
1999-10-02 16:21:10 +00:00
|
|
|
|
need_break_row = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
undo_finished = true;
|
|
|
|
|
undo_frozen = false;
|
|
|
|
|
|
|
|
|
|
// Default layouttype for copy environment type
|
|
|
|
|
copylayouttype = 0;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
// Dump all rowinformation:
|
|
|
|
|
Row * tmprow = firstrow;
|
|
|
|
|
lyxerr << "Baseline Paragraph Pos Height Ascent Fill\n";
|
|
|
|
|
while (tmprow) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
lyxerr << tmprow->baseline() << '\t'
|
2000-04-26 13:57:28 +00:00
|
|
|
|
<< tmprow->par << '\t'
|
2000-06-08 23:16:16 +00:00
|
|
|
|
<< tmprow->pos() << '\t'
|
2000-04-26 13:57:28 +00:00
|
|
|
|
<< tmprow->height << '\t'
|
|
|
|
|
<< tmprow->ascent_of_text << '\t'
|
|
|
|
|
<< tmprow->fill << '\n';
|
2000-06-08 23:16:16 +00:00
|
|
|
|
tmprow = tmprow->next();
|
2000-04-26 13:57:28 +00:00
|
|
|
|
}
|
|
|
|
|
lyxerr.flush();
|
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::init(BufferView * bview)
|
|
|
|
|
{
|
|
|
|
|
if (firstrow)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LyXParagraph * par = OwnerParagraph();
|
|
|
|
|
current_font = GetFont(bview->buffer(), par, 0);
|
|
|
|
|
while (par) {
|
|
|
|
|
InsertParagraph(bview, par, lastrow);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
SetCursorIntern(bview, firstrow->par(), 0);
|
2000-07-07 15:00:56 +00:00
|
|
|
|
sel_cursor = cursor;
|
2000-06-23 15:02:46 +00:00
|
|
|
|
#if 0
|
2000-06-12 11:27:15 +00:00
|
|
|
|
// Dump all rowinformation:
|
|
|
|
|
Row * tmprow = firstrow;
|
2000-06-16 15:13:25 +00:00
|
|
|
|
lyxerr << "Width = " << width << endl;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
lyxerr << "Baseline Paragraph Pos Height Ascent Fill\n";
|
|
|
|
|
while (tmprow) {
|
|
|
|
|
lyxerr << tmprow->baseline() << '\t'
|
|
|
|
|
<< tmprow->par() << '\t'
|
|
|
|
|
<< tmprow->pos() << '\t'
|
|
|
|
|
<< tmprow->height() << '\t'
|
|
|
|
|
<< tmprow->ascent_of_text() << '\t'
|
|
|
|
|
<< tmprow->fill() << '\n';
|
|
|
|
|
tmprow = tmprow->next();
|
|
|
|
|
}
|
|
|
|
|
lyxerr.flush();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
// Basically the same routine as LyXParagraph::getFont() in paragraph.C.
|
|
|
|
|
// The difference is that this one is used for displaying, and thus we
|
|
|
|
|
// are allowed to make cosmetic improvements. For instance make footnotes
|
|
|
|
|
// smaller. (Asger)
|
|
|
|
|
// If position is -1, we get the layout font of the paragraph.
|
|
|
|
|
// If position is -2, we get the font of the manual label of the paragraph.
|
2000-09-14 17:53:12 +00:00
|
|
|
|
LyXFont const LyXText::GetFont(Buffer const * buf, LyXParagraph * par,
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LyXParagraph::size_type pos) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXLayout const & layout =
|
2000-06-12 11:27:15 +00:00
|
|
|
|
textclasslist.Style(buf->params.textclass, par->GetLayout());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
char par_depth = par->GetDepth();
|
|
|
|
|
// 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
|
2000-06-12 11:27:15 +00:00
|
|
|
|
&& pos < BeginningOfMainBody(buf, par)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// 1% goes here
|
2000-09-14 17:53:12 +00:00
|
|
|
|
LyXFont f = par->GetFontSettings(buf->params,
|
|
|
|
|
pos);
|
|
|
|
|
return f.realize(layout.reslabelfont);
|
|
|
|
|
} else {
|
|
|
|
|
LyXFont f = par->GetFontSettings(buf->params, pos);
|
|
|
|
|
return f.realize(layout.resfont);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2000-06-12 11:27:15 +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
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
tmpfont = par->GetFontSettings(buf->params, pos);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmpfont.realize(layoutfont);
|
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()) {
|
|
|
|
|
par = par->DepthHook(par_depth - 1);
|
|
|
|
|
if (par) {
|
|
|
|
|
tmpfont.realize(textclasslist.
|
2000-06-12 11:27:15 +00:00
|
|
|
|
Style(buf->params.textclass,
|
1999-11-04 01:40:20 +00:00
|
|
|
|
par->GetLayout()).font);
|
|
|
|
|
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
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
tmpfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
return tmpfont;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::SetCharFont(Buffer const * buf, LyXParagraph * par,
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXParagraph::size_type pos,
|
2000-01-13 16:28:54 +00:00
|
|
|
|
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
|
1999-11-15 12:01:38 +00:00
|
|
|
|
if (par->GetChar(pos) == LyXParagraph::META_INSET) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (par->GetInset(pos))
|
|
|
|
|
font = par->GetInset(pos)->ConvertFont(font);
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-19 01:42:55 +00:00
|
|
|
|
LyXLayout const & layout =
|
2000-06-12 11:27:15 +00:00
|
|
|
|
textclasslist.Style(buf->params.textclass,
|
2000-04-19 01:42:55 +00:00
|
|
|
|
par->GetLayout());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Get concrete layout font to reduce against
|
|
|
|
|
LyXFont layoutfont;
|
|
|
|
|
|
2000-06-12 11:27:15 +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
|
|
|
|
|
if (par->GetDepth()){
|
|
|
|
|
LyXParagraph * tp = par;
|
|
|
|
|
while (!layoutfont.resolved() && tp && tp->GetDepth()) {
|
|
|
|
|
tp = tp->DepthHook(tp->GetDepth()-1);
|
|
|
|
|
if (tp)
|
1999-11-04 01:40:20 +00:00
|
|
|
|
layoutfont.realize(textclasslist.
|
2000-06-12 11:27:15 +00:00
|
|
|
|
Style(buf->params.textclass,
|
1999-11-04 01:40:20 +00:00
|
|
|
|
tp->GetLayout()).font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Now, reduce font against full layout font
|
|
|
|
|
font.reduce(layoutfont);
|
|
|
|
|
|
|
|
|
|
par->SetFont(pos, font);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* inserts a new row behind the specified row, increments
|
|
|
|
|
* the touched counters */
|
1999-11-04 01:40:20 +00:00
|
|
|
|
void LyXText::InsertRow(Row * row, LyXParagraph * par,
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LyXParagraph::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;
|
2000-01-24 18:34:46 +00:00
|
|
|
|
++number_of_rows; // one more row
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// removes the row and reset the touched counters
|
|
|
|
|
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;
|
2000-06-08 23:16:16 +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.
|
|
|
|
|
void LyXText::RemoveParagraph(Row * row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
|
LyXParagraph * tmppar = row->par();
|
|
|
|
|
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();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
RemoveRow(row);
|
|
|
|
|
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
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::InsertParagraph(BufferView * bview, LyXParagraph * par,
|
|
|
|
|
Row * row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
InsertRow(row, par, 0); /* insert a new row, starting
|
|
|
|
|
* at postition 0 */
|
|
|
|
|
|
2000-06-12 11:27:15 +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);
|
2000-06-12 11:27:15 +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);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
AppendParagraph(bview, row->next());
|
1999-09-27 18:44:28 +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...
|
2000-06-28 13:35:52 +00:00
|
|
|
|
void LyXText::MakeFontEntriesLayoutSpecific(Buffer const * buf,
|
|
|
|
|
LyXParagraph * par)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LyXLayout const & layout =
|
2000-06-12 11:27:15 +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;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
for (LyXParagraph::size_type pos = 0;
|
2001-03-11 00:21:13 +00:00
|
|
|
|
pos < par->size(); ++pos) {
|
2000-06-12 11:27:15 +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
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
tmpfont = par->GetFontSettings(buf->params, pos);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmpfont.reduce(layoutfont);
|
|
|
|
|
par->SetFont(pos, tmpfont);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
LyXParagraph * LyXText::SetLayout(BufferView * bview,
|
|
|
|
|
LyXCursor & cur, LyXCursor & sstart_cur,
|
|
|
|
|
LyXCursor & send_cur,
|
|
|
|
|
LyXTextClass::size_type layout)
|
|
|
|
|
{
|
|
|
|
|
LyXParagraph * endpar = send_cur.par()->next();
|
|
|
|
|
LyXParagraph * undoendpar = endpar;
|
|
|
|
|
|
|
|
|
|
if (endpar && endpar->GetDepth()) {
|
|
|
|
|
while (endpar && endpar->GetDepth()) {
|
|
|
|
|
endpar = endpar->next();
|
|
|
|
|
undoendpar = endpar;
|
|
|
|
|
}
|
|
|
|
|
} else if (endpar) {
|
|
|
|
|
endpar = endpar->next(); // because of parindents etc.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetUndo(bview->buffer(), Undo::EDIT,
|
|
|
|
|
sstart_cur.par()->previous(),
|
|
|
|
|
undoendpar);
|
|
|
|
|
|
|
|
|
|
/* ok we have a selection. This is always between sstart_cur
|
|
|
|
|
* and sel_end cursor */
|
|
|
|
|
cur = sstart_cur;
|
|
|
|
|
|
|
|
|
|
LyXLayout const & lyxlayout =
|
|
|
|
|
textclasslist.Style(bview->buffer()->params.textclass, layout);
|
|
|
|
|
|
|
|
|
|
while (cur.par() != send_cur.par()) {
|
|
|
|
|
cur.par()->SetLayout(layout);
|
|
|
|
|
MakeFontEntriesLayoutSpecific(bview->buffer(), cur.par());
|
2000-07-19 17:16:27 +00:00
|
|
|
|
LyXParagraph * fppar = cur.par();
|
2001-03-06 14:07:14 +00:00
|
|
|
|
fppar->params.spaceTop(lyxlayout.fill_top ?
|
2001-04-04 21:47:26 +00:00
|
|
|
|
VSpace(VSpace::VFILL)
|
|
|
|
|
: VSpace(VSpace::NONE));
|
2001-03-06 14:07:14 +00:00
|
|
|
|
fppar->params.spaceBottom(lyxlayout.fill_bottom ?
|
2001-04-04 21:47:26 +00:00
|
|
|
|
VSpace(VSpace::VFILL)
|
|
|
|
|
: VSpace(VSpace::NONE));
|
2000-05-04 08:14:34 +00:00
|
|
|
|
if (lyxlayout.margintype == MARGIN_MANUAL)
|
2000-06-08 23:16:16 +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());
|
|
|
|
|
}
|
|
|
|
|
cur.par()->SetLayout(layout);
|
|
|
|
|
MakeFontEntriesLayoutSpecific(bview->buffer(), cur.par());
|
|
|
|
|
LyXParagraph * fppar = cur.par();
|
|
|
|
|
fppar->params.spaceTop(lyxlayout.fill_top ?
|
|
|
|
|
VSpace(VSpace::VFILL) : VSpace(VSpace::NONE));
|
|
|
|
|
fppar->params.spaceBottom(lyxlayout.fill_bottom ?
|
|
|
|
|
VSpace(VSpace::VFILL) : VSpace(VSpace::NONE));
|
|
|
|
|
if (lyxlayout.margintype == MARGIN_MANUAL)
|
|
|
|
|
cur.par()->SetLabelWidthString(lyxlayout.labelstring());
|
|
|
|
|
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
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::SetLayout(BufferView * bview, LyXTextClass::size_type layout)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-07-21 18:47:54 +00:00
|
|
|
|
LyXCursor tmpcursor = cursor; /* store the current cursor */
|
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
|
// if there is no selection just set the layout
|
|
|
|
|
// of the current paragraph */
|
|
|
|
|
if (!selection) {
|
|
|
|
|
sel_start_cursor = cursor; // dummy selection
|
|
|
|
|
sel_end_cursor = cursor;
|
|
|
|
|
}
|
|
|
|
|
LyXParagraph *
|
2000-06-12 11:27:15 +00:00
|
|
|
|
endpar = SetLayout(bview, cursor, sel_start_cursor,
|
|
|
|
|
sel_end_cursor, layout);
|
|
|
|
|
RedoParagraphs(bview, sel_start_cursor, 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
|
2000-07-21 18:47:54 +00:00
|
|
|
|
// geometry could have changed
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, sel_start_cursor.par(),
|
|
|
|
|
sel_start_cursor.pos(), false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_cursor = cursor;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos(),
|
|
|
|
|
false);
|
|
|
|
|
UpdateCounters(bview, cursor.row());
|
2001-02-22 14:09:20 +00:00
|
|
|
|
ClearSelection(bview);
|
2001-02-14 10:11:22 +00:00
|
|
|
|
SetSelection(bview);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, tmpcursor.par(), tmpcursor.pos(), true);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// increment depth over selection and
|
|
|
|
|
// make a total rebreak of those paragraphs
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::IncDepth(BufferView * bview)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
// If there is no selection, just use the current paragraph
|
|
|
|
|
if (!selection) {
|
2000-01-13 16:28:54 +00:00
|
|
|
|
sel_start_cursor = cursor; // dummy selection
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_end_cursor = cursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We end at the next paragraph with depth 0
|
2001-05-03 14:31:33 +00:00
|
|
|
|
LyXParagraph * endpar = sel_end_cursor.par()->next();
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXParagraph * undoendpar = endpar;
|
1999-09-27 18:44:28 +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-03-09 00:56:42 +00:00
|
|
|
|
endpar = endpar->next(); // because of parindents etc.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
SetUndo(bview->buffer(), Undo::EDIT,
|
2001-03-09 00:56:42 +00:00
|
|
|
|
sel_start_cursor.par()->previous(),
|
1999-09-27 18:44:28 +00:00
|
|
|
|
undoendpar);
|
|
|
|
|
|
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
|
|
|
|
cursor = sel_start_cursor;
|
|
|
|
|
|
|
|
|
|
bool anything_changed = false;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
// NOTE: you can't change the depth of a bibliography entry
|
2000-07-19 17:16:27 +00:00
|
|
|
|
if (
|
|
|
|
|
textclasslist.Style(bview->buffer()->params.textclass,
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.par()->GetLayout()
|
1999-11-04 01:40:20 +00:00
|
|
|
|
).labeltype != LABEL_BIBLIO) {
|
2001-05-03 14:31:33 +00:00
|
|
|
|
LyXParagraph * prev = cursor.par()->previous();
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (prev
|
2000-06-08 23:16:16 +00:00
|
|
|
|
&& (prev->GetDepth() - cursor.par()->GetDepth() > 0
|
|
|
|
|
|| (prev->GetDepth() == cursor.par()->GetDepth()
|
2000-06-12 11:27:15 +00:00
|
|
|
|
&& textclasslist.Style(bview->buffer()->params.textclass,
|
1999-11-04 01:40:20 +00:00
|
|
|
|
prev->GetLayout()).isEnvironment()))) {
|
2001-03-06 14:07:14 +00:00
|
|
|
|
cursor.par()->params.depth(cursor.par()->params.depth() + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
anything_changed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (cursor.par() == sel_end_cursor.par())
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
cursor.par(cursor.par()->next());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// if nothing changed set all depth to 0
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (!anything_changed) {
|
|
|
|
|
cursor = sel_start_cursor;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
while (cursor.par() != sel_end_cursor.par()) {
|
2001-03-06 14:07:14 +00:00
|
|
|
|
cursor.par()->params.depth(0);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
cursor.par(cursor.par()->next());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-05-03 14:31:33 +00:00
|
|
|
|
cursor.par()->params.depth(0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
RedoParagraphs(bview, sel_start_cursor, 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
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, sel_start_cursor.par(),
|
|
|
|
|
sel_start_cursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_cursor = cursor;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
|
|
|
|
|
UpdateCounters(bview, cursor.row());
|
2001-02-22 14:09:20 +00:00
|
|
|
|
ClearSelection(bview);
|
2001-02-14 10:11:22 +00:00
|
|
|
|
SetSelection(bview);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
|
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
|
2000-06-12 11:27:15 +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
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (!selection) {
|
2000-01-13 16:28:54 +00:00
|
|
|
|
sel_start_cursor = cursor; // dummy selection
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_end_cursor = cursor;
|
|
|
|
|
}
|
2001-03-09 00:56:42 +00:00
|
|
|
|
LyXParagraph * endpar = sel_end_cursor.par()->next();
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXParagraph * undoendpar = endpar;
|
1999-09-27 18:44:28 +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-03-09 00:56:42 +00:00
|
|
|
|
endpar = endpar->next(); // because of parindents etc.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
SetUndo(bview->buffer(), Undo::EDIT,
|
2001-03-09 00:56:42 +00:00
|
|
|
|
sel_start_cursor.par()->previous(),
|
1999-09-27 18:44:28 +00:00
|
|
|
|
undoendpar);
|
|
|
|
|
|
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
|
|
|
|
cursor = sel_start_cursor;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
2001-05-03 14:31:33 +00:00
|
|
|
|
if (cursor.par()->params.depth())
|
|
|
|
|
cursor.par()->params.depth(cursor.par()->params.depth() - 1);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (cursor.par() == sel_end_cursor.par())
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
cursor.par(cursor.par()->next());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
RedoParagraphs(bview, sel_start_cursor, 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
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, sel_start_cursor.par(),
|
|
|
|
|
sel_start_cursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_cursor = cursor;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
|
|
|
|
|
UpdateCounters(bview, cursor.row());
|
2001-02-22 14:09:20 +00:00
|
|
|
|
ClearSelection(bview);
|
2001-02-14 10:11:22 +00:00
|
|
|
|
SetSelection(bview);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
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
|
2000-06-12 11:27:15 +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
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (!selection) {
|
|
|
|
|
// Determine basis font
|
|
|
|
|
LyXFont layoutfont;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (cursor.pos() < BeginningOfMainBody(bview->buffer(),
|
|
|
|
|
cursor.par()))
|
|
|
|
|
layoutfont = GetFont(bview->buffer(), cursor.par(),-2);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2000-06-12 11:27:15 +00:00
|
|
|
|
layoutfont = GetFont(bview->buffer(), cursor.par(),-1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Update current font
|
2000-04-19 01:42:55 +00:00
|
|
|
|
real_current_font.update(font,
|
2000-10-10 12:36:36 +00:00
|
|
|
|
bview->buffer()->params.language,
|
2000-04-19 01:42:55 +00:00
|
|
|
|
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
|
|
|
|
|
real_current_font.realize(layoutfont);
|
|
|
|
|
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
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
SetUndo(bview->buffer(), Undo::EDIT,
|
2001-03-09 00:56:42 +00:00
|
|
|
|
sel_start_cursor.par()->previous(),
|
2001-05-03 14:31:33 +00:00
|
|
|
|
sel_end_cursor.par()->next());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
cursor = sel_start_cursor;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
while (cursor.par() != sel_end_cursor.par() ||
|
2001-05-03 14:31:33 +00:00
|
|
|
|
(cursor.pos() < sel_end_cursor.pos())) {
|
|
|
|
|
if (cursor.pos() < cursor.par()->size()) {
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// an open footnote should behave
|
|
|
|
|
// like a closed one
|
2000-06-12 11:27:15 +00:00
|
|
|
|
LyXFont newfont = GetFont(bview->buffer(),
|
|
|
|
|
cursor.par(), cursor.pos());
|
2000-04-19 01:42:55 +00:00
|
|
|
|
newfont.update(font,
|
2000-10-10 12:36:36 +00:00
|
|
|
|
bview->buffer()->params.language,
|
2000-04-19 01:42:55 +00:00
|
|
|
|
toggleall);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCharFont(bview->buffer(),
|
|
|
|
|
cursor.par(), cursor.pos(), newfont);
|
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-03-09 00:56:42 +00:00
|
|
|
|
RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.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
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, sel_start_cursor.par(), sel_start_cursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_cursor = cursor;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
|
2001-02-22 14:09:20 +00:00
|
|
|
|
ClearSelection(bview);
|
2001-02-14 10:11:22 +00:00
|
|
|
|
SetSelection(bview);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, tmpcursor.par(), tmpcursor.pos(), true,
|
|
|
|
|
tmpcursor.boundary());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +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
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetHeightOfRow(bview, tmprow);
|
2000-07-19 17:16:27 +00:00
|
|
|
|
LyXParagraph * first_phys_par = tmprow->par();
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// find the first row of the paragraph
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (first_phys_par != tmprow->par())
|
|
|
|
|
while (tmprow->previous()
|
|
|
|
|
&& tmprow->previous()->par() != first_phys_par) {
|
|
|
|
|
tmprow = tmprow->previous();
|
|
|
|
|
y -= tmprow->height();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetHeightOfRow(bview, tmprow);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
|
while (tmprow->previous() && tmprow->previous()->par() == first_phys_par) {
|
|
|
|
|
tmprow = tmprow->previous();
|
|
|
|
|
y -= tmprow->height();
|
2000-06-12 11:27:15 +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
|
1999-09-27 18:44:28 +00:00
|
|
|
|
status = LyXText::NEED_MORE_REFRESH;
|
|
|
|
|
refresh_y = y;
|
|
|
|
|
refresh_row = tmprow;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, cur.par(), cur.pos(), false, cursor.boundary());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +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();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetHeightOfRow(bview, tmprow);
|
2000-07-19 17:16:27 +00:00
|
|
|
|
LyXParagraph * first_phys_par = tmprow->par();
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// find the first row of the paragraph
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (first_phys_par != tmprow->par())
|
|
|
|
|
while (tmprow->previous() && tmprow->previous()->par() != first_phys_par) {
|
|
|
|
|
tmprow = tmprow->previous();
|
|
|
|
|
y -= tmprow->height();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
|
while (tmprow->previous() && tmprow->previous()->par() == first_phys_par) {
|
|
|
|
|
tmprow = tmprow->previous();
|
|
|
|
|
y -= tmprow->height();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// we can set the refreshing parameters now
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (status == LyXText::UNCHANGED || y < refresh_y) {
|
|
|
|
|
refresh_y = y;
|
|
|
|
|
refresh_row = tmprow;
|
|
|
|
|
}
|
|
|
|
|
status = LyXText::NEED_MORE_REFRESH;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, cur.par(), cur.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* deletes and inserts again all paragaphs between the cursor
|
|
|
|
|
* and the specified par
|
|
|
|
|
* This function is needed after SetLayout and SetFont etc. */
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::RedoParagraphs(BufferView * bview, LyXCursor const & cur,
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LyXParagraph const * endpar) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
Row * tmprow2;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
LyXParagraph * tmppar = 0, * 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();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (!tmprow->previous()){
|
1999-09-27 18:44:28 +00:00
|
|
|
|
first_phys_par = FirstParagraph(); // a trick/hack for UNDO
|
2000-01-13 16:28:54 +00:00
|
|
|
|
} else {
|
2000-07-19 17:16:27 +00:00
|
|
|
|
first_phys_par = tmprow->par();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// find the first row of the paragraph
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (first_phys_par != tmprow->par())
|
|
|
|
|
while (tmprow->previous() &&
|
|
|
|
|
(tmprow->previous()->par() != first_phys_par)) {
|
|
|
|
|
tmprow = tmprow->previous();
|
|
|
|
|
y -= tmprow->height();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
|
while (tmprow->previous()
|
|
|
|
|
&& tmprow->previous()->par() == first_phys_par) {
|
|
|
|
|
tmprow = tmprow->previous();
|
|
|
|
|
y -= tmprow->height();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// we can set the refreshing parameters now
|
1999-09-27 18:44:28 +00:00
|
|
|
|
status = LyXText::NEED_MORE_REFRESH;
|
|
|
|
|
refresh_y = y;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
refresh_row = tmprow->previous(); /* the real refresh row will
|
2000-01-13 16:28:54 +00:00
|
|
|
|
be deleted, so I store
|
|
|
|
|
the previous here */
|
|
|
|
|
// 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) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
RemoveRow(tmprow->next());
|
|
|
|
|
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();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
RemoveRow(tmprow2);
|
|
|
|
|
|
|
|
|
|
tmppar = first_phys_par;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
if (tmppar) {
|
2000-06-12 11:27:15 +00:00
|
|
|
|
InsertParagraph(bview, tmppar, tmprow);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (!tmprow)
|
|
|
|
|
tmprow = firstrow;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
while (tmprow->next() && tmprow->next()->par() == tmppar)
|
|
|
|
|
tmprow = tmprow->next();
|
2001-03-09 00:56:42 +00:00
|
|
|
|
tmppar = tmppar->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
} while (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();
|
2000-06-12 11:27:15 +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;
|
2000-06-12 11:27:15 +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())
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetHeightOfRow(bview, tmprow->next());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +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) {
|
2000-06-12 11:27:15 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* important for the screen */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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-02-14 10:11:22 +00:00
|
|
|
|
void LyXText::SetSelection(BufferView * bview)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-02-14 08:38:21 +00:00
|
|
|
|
const bool lsel = selection;
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (!selection) {
|
|
|
|
|
last_sel_cursor = sel_cursor;
|
|
|
|
|
sel_start_cursor = sel_cursor;
|
|
|
|
|
sel_end_cursor = sel_cursor;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-08 01:45:25 +00:00
|
|
|
|
selection = 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()
|
|
|
|
|
&& 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
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (sel_cursor.par() == cursor.par())
|
|
|
|
|
if (sel_cursor.pos() < cursor.pos()) {
|
2000-02-03 19:51:27 +00:00
|
|
|
|
sel_end_cursor = cursor;
|
|
|
|
|
sel_start_cursor = sel_cursor;
|
|
|
|
|
} else {
|
|
|
|
|
sel_end_cursor = sel_cursor;
|
|
|
|
|
sel_start_cursor = cursor;
|
|
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
|
else if (sel_cursor.y() < cursor.y() ||
|
|
|
|
|
(sel_cursor.y() == cursor.y() && sel_cursor.x() < cursor.x())) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_end_cursor = cursor;
|
|
|
|
|
sel_start_cursor = sel_cursor;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sel_end_cursor = sel_cursor;
|
|
|
|
|
sel_start_cursor = cursor;
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// a selection with no contents is not a selection
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (sel_start_cursor.par() == sel_end_cursor.par() &&
|
|
|
|
|
sel_start_cursor.pos() == sel_end_cursor.pos())
|
1999-09-27 18:44:28 +00:00
|
|
|
|
selection = false;
|
2001-02-14 08:38:21 +00:00
|
|
|
|
|
|
|
|
|
if (inset_owner && (selection || lsel))
|
2001-02-14 10:11:22 +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
|
|
|
|
{
|
|
|
|
|
if (!selection) return string();
|
|
|
|
|
string result;
|
|
|
|
|
|
|
|
|
|
// Special handling if the whole selection is within one paragraph
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (sel_start_cursor.par() == sel_end_cursor.par()) {
|
2000-06-12 11:27:15 +00:00
|
|
|
|
result += sel_start_cursor.par()->String(buffer,
|
|
|
|
|
sel_start_cursor.pos(),
|
|
|
|
|
sel_end_cursor.pos());
|
2000-05-20 21:37:05 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The selection spans more than one paragraph
|
|
|
|
|
|
|
|
|
|
// First paragraph in selection
|
2001-03-11 00:21:13 +00:00
|
|
|
|
result += sel_start_cursor.par()->String(buffer,
|
|
|
|
|
sel_start_cursor.pos(),
|
|
|
|
|
sel_start_cursor.par()->size())
|
|
|
|
|
+ "\n\n";
|
2000-05-20 21:37:05 +00:00
|
|
|
|
|
|
|
|
|
// The paragraphs in between (if any)
|
|
|
|
|
LyXCursor tmpcur(sel_start_cursor);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
tmpcur.par(tmpcur.par()->next());
|
2000-06-08 23:16:16 +00:00
|
|
|
|
while (tmpcur.par() != sel_end_cursor.par()) {
|
2001-03-11 00:21:13 +00:00
|
|
|
|
result += tmpcur.par()->String(buffer, 0, tmpcur.par()->size()) + "\n\n";
|
2001-03-09 00:56:42 +00:00
|
|
|
|
tmpcur.par(tmpcur.par()->next()); // Or NextAfterFootnote??
|
2000-05-20 21:37:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Last paragraph in selection
|
2000-06-12 11:27:15 +00:00
|
|
|
|
result += sel_end_cursor.par()->String(buffer, 0, sel_end_cursor.pos());
|
2000-05-20 21:37:05 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-06 14:07:14 +00:00
|
|
|
|
void LyXText::ClearSelection(BufferView * /*bview*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
selection = false;
|
|
|
|
|
mark_set = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::CursorHome(BufferView * bview) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, cursor.par(), cursor.row()->pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::CursorEnd(BufferView * bview) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (!cursor.row()->next() || cursor.row()->next()->par() != cursor.row()->par())
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, cursor.par(), RowLast(cursor.row()) + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else {
|
2001-03-11 00:21:13 +00:00
|
|
|
|
if (cursor.par()->size() &&
|
2000-06-08 23:16:16 +00:00
|
|
|
|
(cursor.par()->GetChar(RowLast(cursor.row())) == ' '
|
|
|
|
|
|| cursor.par()->IsNewline(RowLast(cursor.row()))))
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, cursor.par(), RowLast(cursor.row()));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview,cursor.par(), RowLast(cursor.row()) + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-05-03 14:31: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());
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, cursor.par(), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-05-03 14:31: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-03-11 00:21:13 +00:00
|
|
|
|
SetCursor(bview, cursor.par(), cursor.par()->size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
void LyXText::ToggleFree(BufferView * bview,
|
|
|
|
|
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
|
|
|
|
|
&& font.number() == LyXFont::IGNORE)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
? SelectWordWhenUnderCursor(bview) : false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Set font
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetFont(bview, font, toggleall);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
/* Implicit selections are cleared afterwards and cursor is set to the
|
|
|
|
|
original position. */
|
|
|
|
|
if (implicitSelection) {
|
2001-02-22 14:09:20 +00:00
|
|
|
|
ClearSelection(bview);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
cursor = resetCursor;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, cursor.par(), cursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_cursor = cursor;
|
|
|
|
|
}
|
2001-02-14 08:38:21 +00:00
|
|
|
|
if (inset_owner)
|
2001-02-14 10:11:22 +00:00
|
|
|
|
inset_owner->SetUpdateStatus(bview, InsetText::CURSOR_PAR);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
LyXParagraph::size_type
|
2000-06-28 13:35:52 +00:00
|
|
|
|
LyXText::BeginningOfMainBody(Buffer const * buf,
|
|
|
|
|
LyXParagraph 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,
|
2000-01-13 16:28:54 +00:00
|
|
|
|
par->GetLayout()).labeltype != LABEL_MANUAL)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
return par->BeginningOfMainBody();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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! */
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::SetParagraph(BufferView * bview,
|
|
|
|
|
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;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (!selection) {
|
|
|
|
|
sel_start_cursor = cursor;
|
|
|
|
|
sel_end_cursor = cursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// make sure that the depth behind the selection are restored, too
|
2001-03-09 00:56:42 +00:00
|
|
|
|
LyXParagraph * endpar = sel_end_cursor.par()->next();
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXParagraph * undoendpar = endpar;
|
1999-09-27 18:44:28 +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-03-09 00:56:42 +00:00
|
|
|
|
endpar = endpar->next(); // because of parindents etc.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
SetUndo(bview->buffer(), Undo::EDIT,
|
2001-03-09 00:56:42 +00:00
|
|
|
|
sel_start_cursor.par()->previous(),
|
1999-09-27 18:44:28 +00:00
|
|
|
|
undoendpar);
|
|
|
|
|
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
LyXParagraph * tmppar = sel_end_cursor.par();
|
2001-03-09 00:56:42 +00:00
|
|
|
|
while (tmppar != sel_start_cursor.par()->previous()) {
|
2000-07-19 17:16:27 +00:00
|
|
|
|
SetCursor(bview, tmppar, 0);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
status = LyXText::NEED_MORE_REFRESH;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
refresh_row = cursor.row();
|
|
|
|
|
refresh_y = cursor.y() - cursor.row()->baseline();
|
2001-03-06 14:07:14 +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);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// does the layout allow the new alignment?
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (align == LYX_ALIGN_LAYOUT)
|
|
|
|
|
align = textclasslist
|
2000-06-12 11:27:15 +00:00
|
|
|
|
.Style(bview->buffer()->params.textclass,
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.par()->GetLayout()).align;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (align & textclasslist
|
2000-06-12 11:27:15 +00:00
|
|
|
|
.Style(bview->buffer()->params.textclass,
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.par()->GetLayout()).alignpossible) {
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (align == textclasslist
|
2000-06-12 11:27:15 +00:00
|
|
|
|
.Style(bview->buffer()->params.textclass,
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.par()->GetLayout()).align)
|
2001-03-06 14:07:14 +00:00
|
|
|
|
cursor.par()->params.align(LYX_ALIGN_LAYOUT);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
else
|
2001-03-06 14:07:14 +00:00
|
|
|
|
cursor.par()->params.align(align);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.par()->SetLabelWidthString(labelwidthstring);
|
2001-03-06 14:07:14 +00:00
|
|
|
|
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
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
RedoParagraphs(bview, sel_start_cursor, endpar);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-02-22 14:09:20 +00:00
|
|
|
|
ClearSelection(bview);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, sel_start_cursor.par(), sel_start_cursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_cursor = cursor;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
|
2001-02-14 10:11:22 +00:00
|
|
|
|
SetSelection(bview);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
|
2000-08-01 09:35:42 +00:00
|
|
|
|
if (inset_owner)
|
|
|
|
|
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
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::SetCounter(Buffer const * buf, LyXParagraph * 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,
|
2000-04-19 01:42:55 +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
|
|
|
|
|
|
|
|
|
/* copy the prev-counters to this one, unless this is the start of a
|
|
|
|
|
footnote or of a bibliography or the very first paragraph */
|
2001-03-09 00:56:42 +00:00
|
|
|
|
if (par->previous()
|
2000-06-12 11:27:15 +00:00
|
|
|
|
&& !(textclasslist.Style(buf->params.textclass,
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par->previous()->GetLayout()
|
1999-11-04 01:40:20 +00:00
|
|
|
|
).labeltype != LABEL_BIBLIO
|
|
|
|
|
&& layout.labeltype == LABEL_BIBLIO)) {
|
2000-01-24 18:34:46 +00:00
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par->setCounter(i, par->previous()->GetFirstCounter(i));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par->params.appendix(par->previous()->params.appendix());
|
2001-03-06 14:07:14 +00:00
|
|
|
|
if (!par->params.appendix() && par->params.startOfAppendix()) {
|
|
|
|
|
par->params.appendix(true);
|
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-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-03-06 14:07:14 +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()
|
|
|
|
|
&& par->previous()->GetDepth() < par->GetDepth()
|
2000-06-12 11:27:15 +00:00
|
|
|
|
&& textclasslist.Style(buf->params.textclass,
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par->previous()->GetLayout()
|
1999-11-04 01:40:20 +00:00
|
|
|
|
).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++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Maybe we have to decrement the enumeration depth, see note above */
|
2001-03-09 00:56:42 +00:00
|
|
|
|
if (par->previous()
|
|
|
|
|
&& par->previous()->GetDepth() > par->GetDepth()
|
1999-11-04 01:40:20 +00:00
|
|
|
|
&& layout.labeltype != LABEL_BIBLIO) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
par->enumdepth = par->DepthHook(par->GetDepth())->enumdepth;
|
|
|
|
|
par->setCounter(6 + par->enumdepth,
|
|
|
|
|
par->DepthHook(par->GetDepth())->getCounter(6 + par->enumdepth));
|
|
|
|
|
/* 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-03-06 14:07:14 +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-03-06 14:07:14 +00:00
|
|
|
|
if (par->params.labelWidthString().empty()) {
|
1999-11-04 01:40:20 +00:00
|
|
|
|
par->SetLabelWidthString(layout.labelstring());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-02-29 02:19:17 +00:00
|
|
|
|
} else {
|
1999-10-02 16:21:10 +00:00
|
|
|
|
par->SetLabelWidthString(string());
|
1999-09-27 18:44:28 +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-03-06 14:07:14 +00:00
|
|
|
|
if (!par->params.appendix()) {
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (!layout.labelstring().empty())
|
2001-03-06 14:07:14 +00:00
|
|
|
|
par->params.labelString(layout.labelstring());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2001-03-06 14:07:14 +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-03-06 14:07:14 +00:00
|
|
|
|
par->params.labelString(layout.labelstring_appendix());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2001-03-06 14:07:14 +00:00
|
|
|
|
par->params.labelString(string());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-03-08 01:45:25 +00:00
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
std::ostringstream s;
|
2000-09-18 17:39:21 +00:00
|
|
|
|
|
2001-03-06 14:07:14 +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) << '.'
|
|
|
|
|
<< 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-03-06 14:07:14 +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
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
std::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-03-06 14:07:14 +00:00
|
|
|
|
par->params.labelString(s.str().c_str());
|
2000-03-08 01:45:25 +00:00
|
|
|
|
// we really want to get rid of that c_str()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
for (i += par->enumdepth + 1; i < 10; ++i)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
par->setCounter(i, 0); /* reset the following counters */
|
|
|
|
|
|
|
|
|
|
}
|
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-03-06 14:07:14 +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) {
|
2000-07-18 17:45:27 +00:00
|
|
|
|
bool isOK (par->InInset() && par->InInset()->owner() &&
|
|
|
|
|
(par->InInset()->owner()->LyxCode() == Inset::FLOAT_CODE));
|
2000-07-19 17:16:27 +00:00
|
|
|
|
if (isOK) {
|
2000-07-18 17:45:27 +00:00
|
|
|
|
InsetFloat * tmp = static_cast<InsetFloat*>(par->InInset()->owner());
|
|
|
|
|
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-03-06 14:07:14 +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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Updates all counters BEHIND the row. Changed paragraphs
|
|
|
|
|
* with a dynamic left margin will be rebroken. */
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::UpdateCounters(BufferView * bview, Row * row) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXParagraph * 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
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCounter(bview->buffer(), par);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +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)) {
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/* Rebreak the paragraph */
|
|
|
|
|
RemoveParagraph(row);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* insets an inset. */
|
2000-06-28 13:35:52 +00:00
|
|
|
|
void LyXText::InsertInset(BufferView * bview, Inset * inset)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (!cursor.par()->InsertInsetAllowed(inset))
|
2000-04-10 14:29:05 +00:00
|
|
|
|
return;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
SetUndo(bview->buffer(), Undo::INSERT,
|
2001-03-09 00:56:42 +00:00
|
|
|
|
cursor.par()->previous(),
|
2001-05-03 14:31:33 +00:00
|
|
|
|
cursor.par()->next());
|
2000-06-28 13:35:52 +00:00
|
|
|
|
cursor.par()->InsertInset(cursor.pos(), inset);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
InsertChar(bview, LyXParagraph::META_INSET); /* just to rebreak and refresh correctly.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
* The character will not be inserted a
|
|
|
|
|
* second time */
|
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-01-08 16:14:09 +00:00
|
|
|
|
if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
|
|
|
|
|
CursorLeft(bview, true);
|
2000-09-28 14:05:24 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::copyEnvironmentType()
|
|
|
|
|
{
|
2000-06-08 23:16:16 +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
|
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetLayout(bview, copylayouttype);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-15 15:44:39 +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
|
|
|
|
|
if (!selection)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// OK, we have a selection. This is always between sel_start_cursor
|
2000-12-19 00:22:04 +00:00
|
|
|
|
// and sel_end_cursor
|
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-03-09 00:56:42 +00:00
|
|
|
|
LyXParagraph * endpar = sel_end_cursor.par()->next();
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXParagraph * undoendpar = endpar;
|
2000-06-15 15:44:39 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +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
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
SetUndo(bview->buffer(), Undo::DELETE,
|
2001-03-09 00:56:42 +00:00
|
|
|
|
sel_start_cursor.par()->previous(),
|
2000-07-19 17:16:27 +00:00
|
|
|
|
undoendpar);
|
2000-06-15 15:44:39 +00:00
|
|
|
|
|
|
|
|
|
CutAndPaste cap;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
|
|
|
|
// there are two cases: cut only within one paragraph or
|
|
|
|
|
// more than one paragraph
|
2001-05-03 14:31:33 +00:00
|
|
|
|
if (sel_start_cursor.par() == sel_end_cursor.par()) {
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// only within one paragraph
|
2000-06-15 15:44:39 +00:00
|
|
|
|
endpar = sel_start_cursor.par();
|
|
|
|
|
int pos = sel_end_cursor.pos();
|
|
|
|
|
cap.cutSelection(sel_start_cursor.par(), &endpar,
|
|
|
|
|
sel_start_cursor.pos(), pos,
|
|
|
|
|
bview->buffer()->params.textclass, doclear);
|
|
|
|
|
sel_end_cursor.pos(pos);
|
2000-01-17 21:01:30 +00:00
|
|
|
|
} else {
|
2000-06-15 15:44:39 +00:00
|
|
|
|
endpar = sel_end_cursor.par();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
|
int pos = sel_end_cursor.pos();
|
|
|
|
|
cap.cutSelection(sel_start_cursor.par(), &endpar,
|
|
|
|
|
sel_start_cursor.pos(), pos,
|
|
|
|
|
bview->buffer()->params.textclass, doclear);
|
|
|
|
|
cursor.par(endpar);
|
|
|
|
|
sel_end_cursor.par(endpar);
|
|
|
|
|
sel_end_cursor.pos(pos);
|
|
|
|
|
cursor.pos(sel_end_cursor.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)
|
2000-06-15 15:44:39 +00:00
|
|
|
|
sel_start_cursor.par()->StripLeadingSpaces(bview->buffer()->params.textclass);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
|
RedoParagraphs(bview, sel_start_cursor, endpar);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-02-22 14:09:20 +00:00
|
|
|
|
ClearSelection(bview);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
cursor = sel_start_cursor;
|
2000-06-15 15:44:39 +00:00
|
|
|
|
SetCursor(bview, cursor.par(), cursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_cursor = cursor;
|
2000-06-15 15:44:39 +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
|
|
|
|
|
2000-06-15 15:44:39 +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
|
|
|
|
|
if (!selection)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// ok we have a selection. This is always between sel_start_cursor
|
|
|
|
|
// 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-03-11 00:21:13 +00:00
|
|
|
|
while (sel_start_cursor.par()->size() > sel_start_cursor.pos()
|
2000-06-08 23:16:16 +00:00
|
|
|
|
&& sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos())
|
|
|
|
|
&& (sel_start_cursor.par() != sel_end_cursor.par()
|
|
|
|
|
|| sel_start_cursor.pos() < sel_end_cursor.pos()))
|
|
|
|
|
sel_start_cursor.pos(sel_start_cursor.pos() + 1);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
CutAndPaste cap;
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cap.copySelection(sel_start_cursor.par(), sel_end_cursor.par(),
|
|
|
|
|
sel_start_cursor.pos(), sel_end_cursor.pos(),
|
2000-06-15 15:44:39 +00:00
|
|
|
|
bview->buffer()->params.textclass);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::PasteSelection(BufferView * bview)
|
2000-04-10 14:29:05 +00:00
|
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
|
CutAndPaste cap;
|
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-03-11 18:39:00 +00:00
|
|
|
|
if (!cap.checkPastePossible(cursor.par()))
|
2000-06-12 11:27:15 +00:00
|
|
|
|
return;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
SetUndo(bview->buffer(), Undo::INSERT,
|
2001-03-09 00:56:42 +00:00
|
|
|
|
cursor.par()->previous(),
|
2001-05-03 14:31:33 +00:00
|
|
|
|
cursor.par()->next());
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
LyXParagraph * endpar;
|
|
|
|
|
LyXParagraph * actpar = cursor.par();
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
int pos = cursor.pos();
|
2001-05-03 14:31:33 +00:00
|
|
|
|
cap.pasteSelection(&actpar, &endpar, pos,
|
|
|
|
|
bview->buffer()->params.textclass);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
RedoParagraphs(bview, cursor, endpar);
|
|
|
|
|
|
|
|
|
|
SetCursor(bview, cursor.par(), cursor.pos());
|
2001-02-22 14:09:20 +00:00
|
|
|
|
ClearSelection(bview);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
sel_cursor = cursor;
|
|
|
|
|
SetCursor(bview, actpar, pos);
|
2001-02-14 10:11:22 +00:00
|
|
|
|
SetSelection(bview);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
UpdateCounters(bview, cursor.row());
|
2000-04-10 14:29:05 +00:00
|
|
|
|
}
|
2000-06-15 15:44:39 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// returns a pointer to the very first LyXParagraph
|
|
|
|
|
LyXParagraph * LyXText::FirstParagraph() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-12 11:27:15 +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!!
|
2000-09-14 17:53:12 +00:00
|
|
|
|
void LyXText::SetSelectionOverString(BufferView * bview, string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
sel_cursor = cursor;
|
2000-09-14 17:53:12 +00:00
|
|
|
|
for (int i = 0; str[i]; ++i)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
CursorRight(bview);
|
2001-02-14 10:11:22 +00:00
|
|
|
|
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
|
2000-09-14 17:53:12 +00:00
|
|
|
|
void LyXText::ReplaceSelectionWithString(BufferView * bview,
|
|
|
|
|
string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursorParUndo(bview->buffer());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
FreezeUndo();
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
if (!selection) { // create a dummy selection
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_end_cursor = cursor;
|
|
|
|
|
sel_start_cursor = cursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get font setting before we cut
|
2000-06-08 23:16:16 +00:00
|
|
|
|
LyXParagraph::size_type pos = sel_end_cursor.pos();
|
2000-09-14 17:53:12 +00:00
|
|
|
|
LyXFont const font = sel_start_cursor.par()
|
|
|
|
|
->GetFontSettings(bview->buffer()->params,
|
|
|
|
|
sel_start_cursor.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) {
|
|
|
|
|
sel_end_cursor.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
|
2000-06-12 11:27:15 +00:00
|
|
|
|
CutSelection(bview);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
UnFreezeUndo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// needed to insert the selection
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::InsertStringA(BufferView * bview, string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
|
LyXParagraph * par = cursor.par();
|
|
|
|
|
LyXParagraph::size_type pos = cursor.pos();
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXParagraph::size_type a = 0;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
LyXParagraph * endpar = cursor.par()->next();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursorParUndo(bview->buffer());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
|
bool flag =
|
2000-06-12 11:27:15 +00:00
|
|
|
|
textclasslist.Style(bview->buffer()->params.textclass,
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.par()->GetLayout()).isEnvironment();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// only to be sure, should not be neccessary
|
2001-02-22 14:09:20 +00:00
|
|
|
|
ClearSelection(bview);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
|
|
|
|
// insert the string, don't insert doublespace
|
1999-11-19 14:50:33 +00:00
|
|
|
|
string::size_type i = 0;
|
|
|
|
|
while (i < str.length()) {
|
|
|
|
|
if (str[i] != '\n') {
|
|
|
|
|
if (str[i] == ' '
|
2000-01-13 16:28:54 +00:00
|
|
|
|
&& i + 1 < str.length() && str[i + 1] != ' '
|
|
|
|
|
&& pos && par->GetChar(pos - 1)!= ' ') {
|
2000-06-28 13:35:52 +00:00
|
|
|
|
par->InsertChar(pos, ' ', current_font);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
++pos;
|
|
|
|
|
} else if (str[i] == ' ') {
|
2000-02-29 02:19:17 +00:00
|
|
|
|
InsetSpecialChar * new_inset =
|
|
|
|
|
new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
if (par->InsertInsetAllowed(new_inset)) {
|
2000-06-28 13:35:52 +00:00
|
|
|
|
par->InsertInset(pos, new_inset,
|
|
|
|
|
current_font);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
} else {
|
|
|
|
|
delete new_inset;
|
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
++pos;
|
|
|
|
|
} else if (str[i] == '\t') {
|
|
|
|
|
for (a = pos; a < (pos / 8 + 1) * 8 ; ++a) {
|
2000-02-29 02:19:17 +00:00
|
|
|
|
InsetSpecialChar * new_inset =
|
|
|
|
|
new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
if (par->InsertInsetAllowed(new_inset)) {
|
2000-06-28 13:35:52 +00:00
|
|
|
|
par->InsertInset(pos, new_inset,
|
|
|
|
|
current_font);
|
2000-04-10 14:29:05 +00:00
|
|
|
|
} else {
|
|
|
|
|
delete new_inset;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
pos = a;
|
2000-03-16 04:29:22 +00:00
|
|
|
|
} else if (str[i] != 13 &&
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// Ignore unprintables
|
|
|
|
|
(str[i] & 127) >= ' ') {
|
2000-06-28 13:35:52 +00:00
|
|
|
|
par->InsertChar(pos, str[i], current_font);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
++pos;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2000-09-23 04:57:18 +00:00
|
|
|
|
if (!par->size()) { // par is empty
|
|
|
|
|
InsetSpecialChar * new_inset =
|
|
|
|
|
new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
|
|
|
|
|
if (par->InsertInsetAllowed(new_inset)) {
|
|
|
|
|
par->InsertInset(pos,
|
|
|
|
|
new_inset,
|
|
|
|
|
current_font);
|
|
|
|
|
} else {
|
|
|
|
|
delete new_inset;
|
|
|
|
|
}
|
|
|
|
|
++pos;
|
|
|
|
|
}
|
|
|
|
|
par->BreakParagraph(bview->buffer()->params, pos, flag);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
2000-09-23 04:57:18 +00:00
|
|
|
|
pos = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
++i;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
RedoParagraphs(bview, cursor, endpar);
|
|
|
|
|
SetCursor(bview, cursor.par(), cursor.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_cursor = cursor;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, par, pos);
|
2001-02-14 10:11:22 +00:00
|
|
|
|
SetSelection(bview);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/* turns double-CR to single CR, others where converted into one blank and 13s
|
|
|
|
|
* that are ignored .Double spaces are also converted into one. Spaces at
|
|
|
|
|
* the beginning of a paragraph are forbidden. tabs are converted into one
|
|
|
|
|
* space. then InsertStringA is called */
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::InsertStringB(BufferView * bview, string const & s)
|
1999-11-04 01:40:20 +00:00
|
|
|
|
{
|
|
|
|
|
string str(s);
|
1999-11-19 14:50:33 +00:00
|
|
|
|
string::size_type i = 1;
|
|
|
|
|
while (i < str.length()) {
|
2000-09-23 04:57:18 +00:00
|
|
|
|
if (str[i] == '\t')
|
1999-11-04 01:40:20 +00:00
|
|
|
|
str[i] = ' ';
|
2000-01-13 16:28:54 +00:00
|
|
|
|
if (str[i] == ' ' && i + 1 < str.length() && str[i + 1] == ' ')
|
1999-11-04 01:40:20 +00:00
|
|
|
|
str[i] = 13;
|
2000-09-23 04:57:18 +00:00
|
|
|
|
if (str[i] == '\n' && i + 1 < str.length()) {
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (str[i + 1] != '\n') {
|
|
|
|
|
if (str[i - 1] != ' ')
|
|
|
|
|
str[i] = ' ';
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-11-04 01:40:20 +00:00
|
|
|
|
str[i] = 13;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
while (i + 1 < str.length()
|
1999-11-19 14:50:33 +00:00
|
|
|
|
&& (str[i + 1] == ' '
|
|
|
|
|
|| str[i + 1] == '\t'
|
|
|
|
|
|| str[i + 1] == '\n'
|
|
|
|
|
|| str[i + 1] == 13)) {
|
1999-11-04 01:40:20 +00:00
|
|
|
|
str[i + 1] = 13;
|
|
|
|
|
++i;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
|
++i;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
InsertStringA(bview, str);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-01-15 18:54:31 +00:00
|
|
|
|
bool LyXText::GotoNextInset(BufferView * bview,
|
|
|
|
|
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() &&
|
|
|
|
|
!(res.par()->GetChar(res.pos()) == LyXParagraph::META_INSET
|
2001-01-15 18:54:31 +00:00
|
|
|
|
&& (inset = res.par()->GetInset(res.pos())) != 0
|
|
|
|
|
&& find(codes.begin(), codes.end(), inset->LyxCode())
|
|
|
|
|
!= codes.end()
|
|
|
|
|
&& (contents.empty() ||
|
|
|
|
|
static_cast<InsetCommand *>(res.par()->GetInset(res.pos()))->getContents()
|
|
|
|
|
== contents)));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (res.par()) {
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, res.par(), res.pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::CheckParagraph(BufferView * bview, LyXParagraph * par,
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXParagraph::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;
|
2000-09-23 04:57:18 +00:00
|
|
|
|
LyXParagraph::size_type z;
|
|
|
|
|
Row * row = GetRow(par, pos, y);
|
|
|
|
|
|
|
|
|
|
// is there a break one row above
|
|
|
|
|
if (row->previous() && row->previous()->par() == row->par()) {
|
|
|
|
|
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();
|
|
|
|
|
status = LyXText::NEED_MORE_REFRESH;
|
|
|
|
|
|
|
|
|
|
BreakAgain(bview, row->previous());
|
|
|
|
|
|
|
|
|
|
// set the cursor again. Otherwise
|
|
|
|
|
// dangling pointers are possible
|
2000-12-17 06:09:35 +00:00
|
|
|
|
SetCursor(bview, cursor.par(), cursor.pos(),
|
|
|
|
|
false, cursor.boundary());
|
2000-09-23 04:57:18 +00:00
|
|
|
|
sel_cursor = cursor;
|
|
|
|
|
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();
|
|
|
|
|
LyXParagraph::size_type const tmplast = RowLast(row);
|
|
|
|
|
refresh_y = y;
|
|
|
|
|
refresh_row = row;
|
|
|
|
|
|
|
|
|
|
BreakAgain(bview, row);
|
|
|
|
|
if (row->height() == tmpheight && RowLast(row) == tmplast)
|
|
|
|
|
status = LyXText::NEED_VERY_LITTLE_REFRESH;
|
|
|
|
|
else
|
|
|
|
|
status = LyXText::NEED_MORE_REFRESH;
|
|
|
|
|
|
|
|
|
|
// check the special right address boxes
|
|
|
|
|
if (textclasslist.Style(bview->buffer()->params.textclass,
|
|
|
|
|
par->GetLayout()).margintype
|
|
|
|
|
== MARGIN_RIGHT_ADDRESS_BOX) {
|
|
|
|
|
tmpcursor.par(par);
|
|
|
|
|
tmpcursor.row(row);
|
|
|
|
|
tmpcursor.y(y);
|
|
|
|
|
tmpcursor.x(0);
|
|
|
|
|
tmpcursor.x_fix(0);
|
|
|
|
|
tmpcursor.pos(pos);
|
|
|
|
|
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
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
if (selection) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmpcursor = cursor;
|
2000-12-17 06:09:35 +00:00
|
|
|
|
SetCursorIntern(bview, sel_cursor.par(), sel_cursor.pos(),
|
|
|
|
|
false, sel_cursor.boundary());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_cursor = cursor;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursorIntern(bview, sel_start_cursor.par(),
|
2000-12-17 06:09:35 +00:00
|
|
|
|
sel_start_cursor.pos(),
|
|
|
|
|
false, sel_start_cursor.boundary());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_start_cursor = cursor;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursorIntern(bview, sel_end_cursor.par(),
|
2000-12-17 06:09:35 +00:00
|
|
|
|
sel_end_cursor.pos(),
|
|
|
|
|
false, sel_end_cursor.boundary());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel_end_cursor = cursor;
|
2000-06-12 11:27:15 +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;
|
|
|
|
|
}
|
2000-12-17 06:09:35 +00:00
|
|
|
|
SetCursorIntern(bview, cursor.par(), cursor.pos(),
|
|
|
|
|
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
|
|
|
|
|
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
|
2000-06-08 23:16:16 +00:00
|
|
|
|
int pos = cursor.par()->GetPositionOfInset(inset);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (pos != -1){
|
2000-06-12 11:27:15 +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
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXParagraph * par = FirstParagraph();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
do {
|
|
|
|
|
pos = par->GetPositionOfInset(inset);
|
|
|
|
|
if (pos != -1){
|
2000-06-12 11:27:15 +00:00
|
|
|
|
CheckParagraph(bview, par, pos);
|
2000-06-21 15:07:57 +00:00
|
|
|
|
return true;
|
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
|
|
|
|
} while (par);
|
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::SetCursor(BufferView * bview, LyXParagraph * par,
|
2000-05-30 19:31:11 +00:00
|
|
|
|
LyXParagraph::size_type pos,
|
|
|
|
|
bool setfont, bool boundary) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
LyXCursor old_cursor = cursor;
|
2000-06-12 11:27:15 +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
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::SetCursor(BufferView *bview, LyXCursor & cur, LyXParagraph * par,
|
2000-05-30 19:31:11 +00:00
|
|
|
|
LyXParagraph::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
|
|
|
|
|
|
|
|
|
/* get the cursor y position in text */
|
2000-09-29 18:44:07 +00:00
|
|
|
|
int y = 0;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
Row * row = GetRow(par, pos, y);
|
|
|
|
|
/* y is now the beginning of the cursor row */
|
2000-06-08 23:16:16 +00:00
|
|
|
|
y += row->baseline();
|
2000-04-19 14:42:19 +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
|
|
|
|
|
|
|
|
|
/* now get the cursors x position */
|
|
|
|
|
float x;
|
|
|
|
|
float fill_separator, fill_hfill, fill_label_hfill;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
PrepareToPrint(bview, row, x, fill_separator, fill_hfill,
|
|
|
|
|
fill_label_hfill);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
LyXParagraph::size_type cursor_vpos = 0;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
LyXParagraph::size_type last = RowLastPrintable(row);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
LyXParagraph::size_type main_body =
|
|
|
|
|
BeginningOfMainBody(bview->buffer(), row->par());
|
|
|
|
|
if ((main_body > 0) &&
|
|
|
|
|
((main_body-1 > last) ||
|
|
|
|
|
!row->par()->IsLineSeparator(main_body-1)))
|
|
|
|
|
main_body = 0;
|
|
|
|
|
|
|
|
|
|
for (LyXParagraph::size_type vpos = row->pos();
|
|
|
|
|
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,
|
|
|
|
|
row->par()->GetLayout())
|
|
|
|
|
.labelsep,
|
|
|
|
|
GetFont(bview->buffer(), row->par(), -2));
|
|
|
|
|
if (row->par()->IsLineSeparator(main_body-1))
|
|
|
|
|
x -= SingleWidth(bview, row->par(),main_body-1);
|
|
|
|
|
}
|
|
|
|
|
if (HfillExpansion(bview->buffer(), row, pos)) {
|
|
|
|
|
x += SingleWidth(bview, row->par(), pos);
|
|
|
|
|
if (pos >= main_body)
|
|
|
|
|
x += fill_hfill;
|
|
|
|
|
else
|
|
|
|
|
x += fill_label_hfill;
|
|
|
|
|
} else if (row->par()->IsSeparator(pos)) {
|
|
|
|
|
x += SingleWidth(bview, row->par(), pos);
|
|
|
|
|
if (pos >= main_body)
|
|
|
|
|
x += fill_separator;
|
|
|
|
|
} else
|
|
|
|
|
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
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::SetCursorIntern(BufferView * bview, LyXParagraph * par,
|
2000-05-30 19:31:11 +00:00
|
|
|
|
LyXParagraph::size_type pos,
|
|
|
|
|
bool setfont, bool boundary) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, cursor, par, pos, boundary);
|
2000-05-30 19:31:11 +00:00
|
|
|
|
if (setfont)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCurrentFont(bview);
|
2000-05-30 19:31:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::SetCurrentFont(BufferView * bview) const
|
2000-05-30 19:31:11 +00:00
|
|
|
|
{
|
2000-06-08 23:16:16 +00:00
|
|
|
|
LyXParagraph::size_type pos = cursor.pos();
|
|
|
|
|
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;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
else if (cursor.par()->IsSeparator(pos)) {
|
|
|
|
|
if (pos > cursor.row()->pos() &&
|
2000-05-30 19:31:11 +00:00
|
|
|
|
bidi_level(pos) % 2 ==
|
|
|
|
|
bidi_level(pos - 1) % 2)
|
|
|
|
|
--pos;
|
2001-03-11 00:21:13 +00:00
|
|
|
|
else if (pos + 1 < cursor.par()->size())
|
2000-05-30 19:31:11 +00:00
|
|
|
|
++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 =
|
|
|
|
|
cursor.par()->GetFontSettings(bview->buffer()->params, pos);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
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() &&
|
2000-07-10 10:31:34 +00:00
|
|
|
|
IsBoundary(bview->buffer(), cursor.par(), cursor.pos()) &&
|
|
|
|
|
!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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-29 18:44:07 +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
|
|
|
|
|
|
|
|
|
/* get the row first */
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
Row * row = GetRowNearY(y);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
cursor.par(row->par());
|
|
|
|
|
|
|
|
|
|
bool bound = false;
|
2000-06-12 11:27:15 +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);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCurrentFont(bview);
|
|
|
|
|
DeleteEmptyParagraphMechanism(bview, old_cursor);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +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
|
|
|
|
{
|
|
|
|
|
/* get the row first */
|
|
|
|
|
|
|
|
|
|
Row * row = GetRowNearY(y);
|
2000-06-08 23:16:16 +00:00
|
|
|
|
bool bound = false;
|
2000-06-12 11:27:15 +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
|
|
|
|
|
2000-06-12 11:27:15 +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();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursor(bview, cursor.par(), cursor.pos() - 1, true, false);
|
2000-05-30 19:31:11 +00:00
|
|
|
|
if (!internal && !boundary &&
|
2000-06-12 11:27:15 +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.
|
|
|
|
|
LyXParagraph * par = cursor.par()->previous();
|
2001-03-11 00:21:13 +00:00
|
|
|
|
SetCursor(bview, par, par->size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +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() &&
|
2000-09-23 04:57:18 +00:00
|
|
|
|
!cursor.par()->IsNewline(cursor.pos()))
|
2000-07-10 10:31:34 +00:00
|
|
|
|
SetCursor(bview, cursor.par(), cursor.pos(), true, false);
|
2001-03-11 00:21:13 +00:00
|
|
|
|
else if (cursor.pos() < cursor.par()->size()) {
|
2000-07-10 10:31:34 +00:00
|
|
|
|
SetCursor(bview, cursor.par(), cursor.pos() + 1, true, false);
|
|
|
|
|
if (!internal &&
|
|
|
|
|
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())
|
|
|
|
|
SetCursor(bview, cursor.par()->next(), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::CursorUp(BufferView * bview) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-12 11:27:15 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::CursorDown(BufferView * bview) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-12 11:27:15 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +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) {
|
2000-06-12 11:27:15 +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()) {
|
|
|
|
|
SetCursor(bview, cursor.par()->previous(), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +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()) {
|
|
|
|
|
SetCursor(bview, cursor.par()->next(), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2001-03-11 00:21:13 +00:00
|
|
|
|
SetCursor(bview, cursor.par(), cursor.par()->size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::DeleteEmptyParagraphMechanism(BufferView * bview,
|
|
|
|
|
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.
|
2000-01-13 16:28:54 +00:00
|
|
|
|
if (selection) return;
|
|
|
|
|
|
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,
|
2000-06-08 23:16:16 +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()
|
2000-06-08 23:16:16 +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);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
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()) {
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursorIntern(bview, cursor.par(),
|
|
|
|
|
cursor.pos() - 1);
|
2000-04-12 14:58:27 +00:00
|
|
|
|
} else
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursorIntern(bview, cursor.par(),
|
|
|
|
|
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,
|
2000-06-08 23:16:16 +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
|
|
|
|
|
|| (old_cursor.par()->size() == 1
|
2001-05-03 14:31:33 +00:00
|
|
|
|
&& 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
|
|
|
|
|
status = LyXText::NEED_MORE_REFRESH;
|
|
|
|
|
deleted = true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +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();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
tmpcursor = cursor;
|
|
|
|
|
cursor = old_cursor; // that undo can restore the right cursor position
|
2001-03-09 00:56:42 +00:00
|
|
|
|
LyXParagraph * endpar = old_cursor.par()->next();
|
|
|
|
|
if (endpar && endpar->GetDepth()) {
|
|
|
|
|
while (endpar && endpar->GetDepth()) {
|
|
|
|
|
endpar = endpar->next();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetUndo(bview->buffer(), Undo::DELETE,
|
2001-03-09 00:56:42 +00:00
|
|
|
|
old_cursor.par()->previous(),
|
2000-01-13 16:28:54 +00:00
|
|
|
|
endpar);
|
|
|
|
|
cursor = tmpcursor;
|
|
|
|
|
|
|
|
|
|
// delete old row
|
2000-06-08 23:16:16 +00:00
|
|
|
|
RemoveRow(old_cursor.row());
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (OwnerParagraph() == old_cursor.par()) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
OwnerParagraph(OwnerParagraph()->next());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
// delete old par
|
2000-06-08 23:16:16 +00:00
|
|
|
|
delete old_cursor.par();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +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 */
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (refresh_row->next()) {
|
2000-06-12 11:27:15 +00:00
|
|
|
|
BreakAgain(bview, refresh_row->next());
|
|
|
|
|
UpdateCounters(bview, refresh_row);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetHeightOfRow(bview, refresh_row);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
} else {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
refresh_row = old_cursor.row()->next();
|
|
|
|
|
refresh_y = old_cursor.y() - old_cursor.row()->baseline();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
tmpcursor = cursor;
|
|
|
|
|
cursor = old_cursor; // that undo can restore the right cursor position
|
2001-03-09 00:56:42 +00:00
|
|
|
|
LyXParagraph * endpar = old_cursor.par()->next();
|
|
|
|
|
if (endpar && endpar->GetDepth()) {
|
|
|
|
|
while (endpar && endpar->GetDepth()) {
|
|
|
|
|
endpar = endpar->next();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetUndo(bview->buffer(), Undo::DELETE,
|
2001-03-09 00:56:42 +00:00
|
|
|
|
old_cursor.par()->previous(),
|
2000-01-13 16:28:54 +00:00
|
|
|
|
endpar);
|
|
|
|
|
cursor = tmpcursor;
|
|
|
|
|
|
|
|
|
|
// delete old row
|
2000-06-08 23:16:16 +00:00
|
|
|
|
RemoveRow(old_cursor.row());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// delete old par
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (OwnerParagraph() == old_cursor.par()) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
OwnerParagraph(OwnerParagraph()->next());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
delete old_cursor.par();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +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) {
|
2000-06-12 11:27:15 +00:00
|
|
|
|
BreakAgain(bview, refresh_row);
|
|
|
|
|
UpdateCounters(bview, refresh_row->previous());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// correct cursor y
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursorIntern(bview, cursor.par(), cursor.pos());
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (sel_cursor.par() == old_cursor.par()
|
|
|
|
|
&& sel_cursor.pos() == sel_cursor.pos()) {
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// correct selection
|
|
|
|
|
sel_cursor = cursor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!deleted) {
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (old_cursor.par()->StripLeadingSpaces(bview->buffer()->params.textclass)) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
RedoParagraphs(bview, old_cursor, old_cursor.par()->next());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// correct cursor y
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursorIntern(bview, cursor.par(), cursor.pos());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
sel_cursor = cursor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-09 00:56:42 +00:00
|
|
|
|
LyXParagraph * LyXText::GetParFromID(int id)
|
|
|
|
|
{
|
|
|
|
|
LyXParagraph * result = FirstParagraph();
|
|
|
|
|
while (result && result->id() != id)
|
|
|
|
|
result = result->next();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// undo functions
|
2000-06-12 11:27:15 +00:00
|
|
|
|
bool LyXText::TextUndo(BufferView * bview)
|
2000-01-13 16:28:54 +00:00
|
|
|
|
{
|
2000-06-16 15:13:25 +00:00
|
|
|
|
if (inset_owner)
|
|
|
|
|
return false;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// returns false if no undo possible
|
2000-06-12 11:27:15 +00:00
|
|
|
|
Undo * undo = bview->buffer()->undostack.pop();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
if (undo) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
FinishUndo();
|
|
|
|
|
if (!undo_frozen)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
bview->buffer()->redostack
|
|
|
|
|
.push(CreateUndo(bview->buffer(), undo->kind,
|
2000-01-13 16:28:54 +00:00
|
|
|
|
GetParFromID(undo->number_of_before_par),
|
|
|
|
|
GetParFromID(undo->number_of_behind_par)));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
return TextHandleUndo(bview, undo);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
bool LyXText::TextRedo(BufferView * bview)
|
2000-01-13 16:28:54 +00:00
|
|
|
|
{
|
2000-06-16 15:13:25 +00:00
|
|
|
|
if (inset_owner)
|
|
|
|
|
return false;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// returns false if no redo possible
|
2000-06-12 11:27:15 +00:00
|
|
|
|
Undo * undo = bview->buffer()->redostack.pop();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
if (undo) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
FinishUndo();
|
|
|
|
|
if (!undo_frozen)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
bview->buffer()->undostack
|
|
|
|
|
.push(CreateUndo(bview->buffer(), undo->kind,
|
2000-01-13 16:28:54 +00:00
|
|
|
|
GetParFromID(undo->number_of_before_par),
|
|
|
|
|
GetParFromID(undo->number_of_behind_par)));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
|
return TextHandleUndo(bview, undo);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
bool LyXText::TextHandleUndo(BufferView * bview, Undo * undo)
|
2000-01-13 16:28:54 +00:00
|
|
|
|
{
|
2000-06-16 15:13:25 +00:00
|
|
|
|
if (inset_owner)
|
|
|
|
|
return false;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// returns false if no undo possible
|
1999-09-27 18:44:28 +00:00
|
|
|
|
bool result = false;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
if (undo) {
|
|
|
|
|
LyXParagraph * before =
|
|
|
|
|
GetParFromID(undo->number_of_before_par);
|
|
|
|
|
LyXParagraph * behind =
|
|
|
|
|
GetParFromID(undo->number_of_behind_par);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXParagraph * tmppar;
|
|
|
|
|
LyXParagraph * tmppar2;
|
|
|
|
|
LyXParagraph * endpar;
|
|
|
|
|
LyXParagraph * tmppar5;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// if there's no before take the beginning
|
|
|
|
|
// of the document for redoing
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (!before)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursorIntern(bview, FirstParagraph(), 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// replace the paragraphs with the undo informations
|
|
|
|
|
|
2000-03-16 04:29:22 +00:00
|
|
|
|
LyXParagraph * tmppar3 = undo->par;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
undo->par = 0; // otherwise the undo destructor would delete the paragraph
|
2000-03-16 04:29:22 +00:00
|
|
|
|
LyXParagraph * tmppar4 = tmppar3;
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2001-03-09 00:56:42 +00:00
|
|
|
|
if (tmppar4) {
|
|
|
|
|
while (tmppar4->next())
|
|
|
|
|
tmppar4 = tmppar4->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} // get last undo par
|
|
|
|
|
|
|
|
|
|
// now remove the old text if there is any
|
2001-03-09 00:56:42 +00:00
|
|
|
|
if (before != behind || (!behind && !before)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (before)
|
2001-03-09 00:56:42 +00:00
|
|
|
|
tmppar5 = before->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2000-06-12 11:27:15 +00:00
|
|
|
|
tmppar5 = OwnerParagraph();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmppar2 = tmppar3;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
while (tmppar5 && tmppar5 != behind) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmppar = tmppar5;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
tmppar5 = tmppar5->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// a memory optimization for edit: Only layout information
|
|
|
|
|
// is stored in the undo. So restore the text informations.
|
2000-03-16 04:29:22 +00:00
|
|
|
|
if (undo->kind == Undo::EDIT) {
|
|
|
|
|
tmppar2->setContentsFromPar(tmppar);
|
|
|
|
|
tmppar->clearContents();
|
2001-03-09 00:56:42 +00:00
|
|
|
|
tmppar2 = tmppar2->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// put the new stuff in the list if there is one
|
|
|
|
|
if (tmppar3){
|
|
|
|
|
if (before)
|
2001-03-09 00:56:42 +00:00
|
|
|
|
before->next(tmppar3);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2000-06-12 11:27:15 +00:00
|
|
|
|
OwnerParagraph(tmppar3);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
tmppar3->previous(before);
|
2000-07-18 17:45:27 +00:00
|
|
|
|
} else {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (!before)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
OwnerParagraph(behind);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
if (tmppar4) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
tmppar4->next(behind);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (behind)
|
2001-03-09 00:56:42 +00:00
|
|
|
|
behind->previous(tmppar4);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set the cursor for redoing
|
2000-03-16 04:29:22 +00:00
|
|
|
|
if (before) {
|
2000-07-19 17:16:27 +00:00
|
|
|
|
SetCursorIntern(bview, before, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-07-18 17:45:27 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// calculate the endpar for redoing the paragraphs.
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (behind) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
endpar = behind->next();
|
2000-06-08 23:16:16 +00:00
|
|
|
|
} else
|
1999-09-27 18:44:28 +00:00
|
|
|
|
endpar = behind;
|
|
|
|
|
|
|
|
|
|
tmppar = GetParFromID(undo->number_of_cursor_par);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
RedoParagraphs(bview, cursor, endpar);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (tmppar){
|
2000-06-12 11:27:15 +00:00
|
|
|
|
SetCursorIntern(bview, tmppar, undo->cursor_pos);
|
|
|
|
|
UpdateCounters(bview, cursor.row());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
result = true;
|
|
|
|
|
delete undo;
|
|
|
|
|
}
|
|
|
|
|
FinishUndo();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::FinishUndo()
|
2000-01-13 16:28:54 +00:00
|
|
|
|
{
|
2000-06-16 15:13:25 +00:00
|
|
|
|
if (inset_owner)
|
|
|
|
|
return;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// makes sure the next operation will be stored
|
2000-05-30 15:41:16 +00:00
|
|
|
|
undo_finished = true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::FreezeUndo()
|
2000-01-13 16:28:54 +00:00
|
|
|
|
{
|
2000-06-16 15:13:25 +00:00
|
|
|
|
if (inset_owner)
|
|
|
|
|
return;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// this is dangerous and for internal use only
|
2000-05-30 15:41:16 +00:00
|
|
|
|
undo_frozen = true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXText::UnFreezeUndo()
|
2000-01-13 16:28:54 +00:00
|
|
|
|
{
|
2000-06-16 15:13:25 +00:00
|
|
|
|
if (inset_owner)
|
|
|
|
|
return;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// this is dangerous and for internal use only
|
1999-09-27 18:44:28 +00:00
|
|
|
|
undo_frozen = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::SetUndo(Buffer * buf, Undo::undo_kind kind,
|
|
|
|
|
LyXParagraph const * before,
|
2000-01-13 16:28:54 +00:00
|
|
|
|
LyXParagraph const * behind) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-16 15:13:25 +00:00
|
|
|
|
if (inset_owner)
|
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (!undo_frozen)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
buf->undostack.push(CreateUndo(buf, kind, before, behind));
|
|
|
|
|
buf->redostack.clear();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::SetRedo(Buffer * buf, Undo::undo_kind kind,
|
|
|
|
|
LyXParagraph const * before, LyXParagraph const * behind)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-16 15:13:25 +00:00
|
|
|
|
if (inset_owner)
|
|
|
|
|
return;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
buf->redostack.push(CreateUndo(buf, kind, before, behind));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
Undo * LyXText::CreateUndo(Buffer * buf, Undo::undo_kind kind,
|
|
|
|
|
LyXParagraph const * before,
|
|
|
|
|
LyXParagraph const * behind) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-16 15:13:25 +00:00
|
|
|
|
if (inset_owner)
|
|
|
|
|
return 0;
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
int before_number = -1;
|
|
|
|
|
int behind_number = -1;
|
|
|
|
|
if (before)
|
1999-11-22 16:19:48 +00:00
|
|
|
|
before_number = before->id();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (behind)
|
1999-11-22 16:19:48 +00:00
|
|
|
|
behind_number = behind->id();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Undo::EDIT and Undo::FINISH are
|
|
|
|
|
// always finished. (no overlapping there)
|
|
|
|
|
// overlapping only with insert and delete inside one paragraph:
|
|
|
|
|
// Nobody wants all removed character
|
|
|
|
|
// appear one by one when undoing.
|
|
|
|
|
// EDIT is special since only layout information, not the
|
|
|
|
|
// contents of a paragaph are stored.
|
2000-06-16 15:13:25 +00:00
|
|
|
|
if (!undo_finished && (kind != Undo::EDIT) && (kind != Undo::FINISH)){
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// check wether storing is needed
|
2000-06-12 11:27:15 +00:00
|
|
|
|
if (!buf->undostack.empty() &&
|
|
|
|
|
buf->undostack.top()->kind == kind &&
|
|
|
|
|
buf->undostack.top()->number_of_before_par == before_number &&
|
|
|
|
|
buf->undostack.top()->number_of_behind_par == behind_number ){
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// no undo needed
|
1999-10-02 16:21:10 +00:00
|
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// create a new Undo
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXParagraph * undopar;
|
|
|
|
|
LyXParagraph * tmppar;
|
|
|
|
|
LyXParagraph * tmppar2;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
LyXParagraph * start = 0;
|
|
|
|
|
LyXParagraph * end = 0;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
|
|
|
|
|
if (before)
|
|
|
|
|
start = const_cast<LyXParagraph*>(before->next());
|
|
|
|
|
else
|
|
|
|
|
start = FirstParagraph();
|
|
|
|
|
if (behind)
|
|
|
|
|
end = const_cast<LyXParagraph*>(behind->previous());
|
|
|
|
|
else {
|
|
|
|
|
end = FirstParagraph();
|
|
|
|
|
while (end->next())
|
|
|
|
|
end = end->next();
|
|
|
|
|
}
|
|
|
|
|
if (start && end && (start != end->next()) &&
|
|
|
|
|
((before != behind) || (!before && !behind))) {
|
|
|
|
|
tmppar = start;
|
|
|
|
|
tmppar2 = tmppar->Clone();
|
|
|
|
|
tmppar2->id(tmppar->id());
|
|
|
|
|
|
|
|
|
|
// a memory optimization: Just store the layout information
|
|
|
|
|
// when only edit
|
|
|
|
|
if (kind == Undo::EDIT){
|
|
|
|
|
//tmppar2->text.clear();
|
|
|
|
|
tmppar2->clearContents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
undopar = tmppar2;
|
|
|
|
|
|
|
|
|
|
while (tmppar != end && tmppar->next()) {
|
|
|
|
|
tmppar = tmppar->next();
|
|
|
|
|
tmppar2->next(tmppar->Clone());
|
|
|
|
|
tmppar2->next()->id(tmppar->id());
|
|
|
|
|
// a memory optimization: Just store the layout
|
|
|
|
|
// information when only edit
|
|
|
|
|
if (kind == Undo::EDIT){
|
|
|
|
|
//tmppar2->next->text.clear();
|
|
|
|
|
tmppar2->clearContents();
|
|
|
|
|
}
|
|
|
|
|
tmppar2->next()->previous(tmppar2);
|
|
|
|
|
tmppar2 = tmppar2->next();
|
|
|
|
|
}
|
|
|
|
|
tmppar2->next(0);
|
|
|
|
|
} else
|
|
|
|
|
undopar = 0; // nothing to replace (undo of delete maybe)
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
int cursor_par = cursor.par()->id();
|
|
|
|
|
int cursor_pos = cursor.pos();
|
2001-03-09 00:56:42 +00:00
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
Undo * undo = new Undo(kind,
|
2000-01-13 16:28:54 +00:00
|
|
|
|
before_number, behind_number,
|
|
|
|
|
cursor_par, cursor_pos,
|
|
|
|
|
undopar);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
undo_finished = false;
|
|
|
|
|
return undo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::SetCursorParUndo(Buffer * buf)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-06-16 15:13:25 +00:00
|
|
|
|
if (inset_owner)
|
|
|
|
|
return;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
SetUndo(buf, Undo::FINISH,
|
2001-03-09 00:56:42 +00:00
|
|
|
|
cursor.par()->previous(),
|
2001-05-03 14:31:33 +00:00
|
|
|
|
cursor.par()->next());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
void LyXText::toggleAppendix(BufferView * bview)
|
|
|
|
|
{
|
2000-07-19 17:16:27 +00:00
|
|
|
|
LyXParagraph * par = cursor.par();
|
2001-03-06 14:07:14 +00:00
|
|
|
|
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
|
|
|
|
|
LyXParagraph * tmp = FirstParagraph();
|
2001-03-09 00:56:42 +00:00
|
|
|
|
for (; tmp; tmp = tmp->next())
|
|
|
|
|
tmp->params.startOfAppendix(false);
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2001-03-06 14:07:14 +00:00
|
|
|
|
par->params.startOfAppendix(start);
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
|
|
|
|
// we can set the refreshing parameters now
|
|
|
|
|
status = LyXText::NEED_MORE_REFRESH;
|
|
|
|
|
refresh_y = 0;
|
|
|
|
|
refresh_row = 0; // not needed for full update
|
2000-06-12 11:27:15 +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
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
LyXParagraph * LyXText::OwnerParagraph() const
|
|
|
|
|
{
|
|
|
|
|
if (inset_owner)
|
|
|
|
|
return inset_owner->par;
|
|
|
|
|
|
|
|
|
|
return bv_owner->buffer()->paragraph;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXParagraph * LyXText::OwnerParagraph(LyXParagraph * p) const
|
|
|
|
|
{
|
|
|
|
|
if (inset_owner)
|
|
|
|
|
inset_owner->par = p;
|
|
|
|
|
else
|
|
|
|
|
bv_owner->buffer()->paragraph = p;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|