2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file text2.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Asger Alstrup
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Alfredo Braunstein
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author Allan Rae
|
|
|
|
|
* \author Dekel Tsur
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
|
#include "lyxtext.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "buffer.h"
|
2003-06-24 20:42:15 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
1999-12-19 22:35:36 +00:00
|
|
|
|
#include "BufferView.h"
|
2003-09-12 17:13:22 +00:00
|
|
|
|
#include "Bullet.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "counters.h"
|
2004-08-14 19:55:00 +00:00
|
|
|
|
#include "coordcache.h"
|
2003-11-04 12:36:59 +00:00
|
|
|
|
#include "cursor.h"
|
2000-04-10 14:29:05 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2000-04-08 17:02:02 +00:00
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "errorlist.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "Floating.h"
|
2000-07-18 17:45:27 +00:00
|
|
|
|
#include "FloatList.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "language.h"
|
2003-12-01 13:35:49 +00:00
|
|
|
|
#include "LColor.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "lyxrc.h"
|
2003-09-06 12:36:58 +00:00
|
|
|
|
#include "lyxrow.h"
|
2003-04-01 16:55:48 +00:00
|
|
|
|
#include "lyxrow_funcs.h"
|
2003-09-16 12:12:33 +00:00
|
|
|
|
#include "paragraph.h"
|
2003-04-14 18:35:29 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#include "undo.h"
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "vspace.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
|
|
|
|
|
#include "frontends/font_metrics.h"
|
|
|
|
|
#include "frontends/LyXView.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
|
#include "insets/insetbibitem.h"
|
2003-05-19 07:12:09 +00:00
|
|
|
|
#include "insets/insetenv.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "insets/insetfloat.h"
|
2003-05-06 06:16:59 +00:00
|
|
|
|
#include "insets/insetwrap.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "support/textutils.h"
|
2003-09-12 17:13:22 +00:00
|
|
|
|
#include "support/tostr.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
|
|
|
|
#include <sstream>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
using lyx::par_type;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::pos_type;
|
|
|
|
|
using lyx::support::bformat;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::ostringstream;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2000-07-21 18:47:54 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
LyXText::LyXText(BufferView * bv)
|
2004-03-08 21:14:45 +00:00
|
|
|
|
: width_(0), maxwidth_(bv ? bv->workWidth() : 100), height_(0),
|
2004-03-01 16:29:30 +00:00
|
|
|
|
background_color_(LColor::background),
|
2004-03-18 12:53:43 +00:00
|
|
|
|
bv_owner(bv), xo_(0), yo_(0)
|
2003-11-10 09:06:48 +00:00
|
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2004-02-02 16:38:13 +00:00
|
|
|
|
void LyXText::init(BufferView * bv)
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
BOOST_ASSERT(bv);
|
2004-02-02 16:38:13 +00:00
|
|
|
|
bv_owner = bv;
|
2004-03-01 16:29:30 +00:00
|
|
|
|
maxwidth_ = bv->workWidth();
|
|
|
|
|
width_ = maxwidth_;
|
|
|
|
|
height_ = 0;
|
2003-07-14 09:15:58 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type const end = paragraphs().size();
|
|
|
|
|
for (par_type pit = 0; pit != end; ++pit)
|
|
|
|
|
pars_[pit].rows.clear();
|
2002-09-06 14:48:01 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
current_font = getFont(pars_[0], 0);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
redoParagraphs(0, end);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
updateCounters();
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-06 15:41:17 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
bool LyXText::isMainText() const
|
|
|
|
|
{
|
|
|
|
|
return &bv()->buffer()->text() == this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-14 19:55:00 +00:00
|
|
|
|
// takes absolute x,y coordinates
|
|
|
|
|
InsetBase * LyXText::checkInsetHit(int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
par_type pit;
|
|
|
|
|
par_type end;
|
|
|
|
|
|
|
|
|
|
getParsInRange(paragraphs(),
|
|
|
|
|
bv()->top_y() - yo_,
|
|
|
|
|
bv()->top_y() - yo_ + bv()->workHeight(),
|
|
|
|
|
pit, end);
|
|
|
|
|
|
2004-08-14 21:56:40 +00:00
|
|
|
|
// convert to screen-absolute y coordinate
|
|
|
|
|
y -= bv()->top_y();
|
2004-08-14 19:55:00 +00:00
|
|
|
|
lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
|
|
|
|
|
lyxerr << " pit: " << pit << " end: " << end << endl;
|
|
|
|
|
for (; pit != end; ++pit) {
|
|
|
|
|
InsetList::const_iterator iit = pars_[pit].insetlist.begin();
|
|
|
|
|
InsetList::const_iterator iend = pars_[pit].insetlist.end();
|
|
|
|
|
for (; iit != iend; ++iit) {
|
|
|
|
|
InsetBase * inset = iit->inset;
|
|
|
|
|
#if 1
|
|
|
|
|
lyxerr << "examining inset " << inset << endl;
|
|
|
|
|
if (theCoords.insets_.has(inset))
|
|
|
|
|
lyxerr
|
|
|
|
|
<< " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
|
|
|
|
|
<< " yo: " << inset->yo() - inset->ascent() << "..."
|
|
|
|
|
<< inset->yo() + inset->descent() << endl;
|
|
|
|
|
else
|
|
|
|
|
lyxerr << " inset has no cached position";
|
|
|
|
|
#endif
|
|
|
|
|
if (inset->covers(x, y)) {
|
|
|
|
|
lyxerr << "Hit inset: " << inset << endl;
|
|
|
|
|
return inset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lyxerr << "No inset hit. " << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Gets the fully instantiated font at a given position in a paragraph
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// Basically the same routine as Paragraph::getFont() in paragraph.C.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// The difference is that this one is used for displaying, and thus we
|
|
|
|
|
// are allowed to make cosmetic improvements. For instance make footnotes
|
|
|
|
|
// smaller. (Asger)
|
2004-08-15 00:01:45 +00:00
|
|
|
|
LyXFont LyXText::getFont(Paragraph const & par, pos_type const pos) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(pos >= 0);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-08-14 22:38:45 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.layout();
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2003-07-27 21:59:06 +00:00
|
|
|
|
#warning broken?
|
2004-04-05 09:36:28 +00:00
|
|
|
|
#endif
|
2003-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & params = bv()->buffer()->params();
|
2004-08-14 22:38:45 +00:00
|
|
|
|
pos_type const body_pos = par.beginOfBody();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// We specialize the 95% common case:
|
2004-08-14 22:38:45 +00:00
|
|
|
|
if (!par.getDepth()) {
|
|
|
|
|
LyXFont f = par.getFontSettings(params, pos);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (!isMainText())
|
2003-12-03 18:17:20 +00:00
|
|
|
|
f.realize(font_);
|
2003-10-21 16:15:14 +00:00
|
|
|
|
if (layout->labeltype == LABEL_MANUAL && pos < body_pos)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return f.realize(layout->reslabelfont);
|
2003-10-21 16:15:14 +00:00
|
|
|
|
else
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return f.realize(layout->resfont);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// The uncommon case need not be optimized as much
|
2001-08-03 18:28:11 +00:00
|
|
|
|
LyXFont layoutfont;
|
2003-10-21 16:15:14 +00:00
|
|
|
|
if (pos < body_pos)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->labelfont;
|
2003-10-21 16:15:14 +00:00
|
|
|
|
else
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-08-14 22:38:45 +00:00
|
|
|
|
LyXFont font = par.getFontSettings(params, pos);
|
2003-10-21 16:15:14 +00:00
|
|
|
|
font.realize(layoutfont);
|
2002-09-06 15:18:11 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (!isMainText())
|
2003-12-03 18:17:20 +00:00
|
|
|
|
font.realize(font_);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-15 00:11:03 +00:00
|
|
|
|
// Realize with the fonts of lesser depth.
|
2003-10-21 16:15:14 +00:00
|
|
|
|
font.realize(defaultfont_);
|
2003-04-15 00:11:03 +00:00
|
|
|
|
|
2003-10-21 16:15:14 +00:00
|
|
|
|
return font;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-14 22:38:45 +00:00
|
|
|
|
LyXFont LyXText::getLayoutFont(par_type const pit) const
|
2001-08-03 18:28:11 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pars_[pit].layout();
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!pars_[pit].getDepth())
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return layout->resfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont font = layout->font;
|
2003-04-15 00:11:03 +00:00
|
|
|
|
// Realize with the fonts of lesser depth.
|
2003-12-01 13:35:49 +00:00
|
|
|
|
//font.realize(outerFont(pit, paragraphs()));
|
2003-07-28 10:41:47 +00:00
|
|
|
|
font.realize(defaultfont_);
|
2003-04-15 00:11:03 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
return font;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
LyXFont LyXText::getLabelFont(Paragraph const & par) const
|
2001-08-03 18:28:11 +00:00
|
|
|
|
{
|
2004-08-15 00:01:45 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.layout();
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
if (!par.getDepth())
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return layout->reslabelfont;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont font = layout->labelfont;
|
2003-04-15 00:11:03 +00:00
|
|
|
|
// Realize with the fonts of lesser depth.
|
2003-07-28 10:41:47 +00:00
|
|
|
|
font.realize(defaultfont_);
|
2003-04-15 00:11:03 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
return font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
void LyXText::setCharFont(par_type pit, pos_type pos, LyXFont const & fnt)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont font = fnt;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr const & layout = pars_[pit].layout();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Get concrete layout font to reduce against
|
|
|
|
|
LyXFont layoutfont;
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pos < pars_[pit].beginOfBody())
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->labelfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->font;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Realize against environment font information
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].getDepth()) {
|
|
|
|
|
par_type tp = pit;
|
2003-04-16 08:12:22 +00:00
|
|
|
|
while (!layoutfont.resolved() &&
|
2004-03-27 01:18:51 +00:00
|
|
|
|
tp != par_type(paragraphs().size()) &&
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[tp].getDepth()) {
|
2003-12-01 13:35:49 +00:00
|
|
|
|
tp = outerHook(tp, paragraphs());
|
2004-03-27 01:18:51 +00:00
|
|
|
|
if (tp != par_type(paragraphs().size()))
|
2004-03-25 09:16:36 +00:00
|
|
|
|
layoutfont.realize(pars_[tp].layout()->font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-28 10:41:47 +00:00
|
|
|
|
layoutfont.realize(defaultfont_);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Now, reduce font against full layout font
|
|
|
|
|
font.reduce(layoutfont);
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[pit].setFont(pos, font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-22 14:44:59 +00:00
|
|
|
|
// used in setLayout
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Asger is not sure we want to do this...
|
2003-07-27 21:59:06 +00:00
|
|
|
|
void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
|
2003-02-26 17:04:10 +00:00
|
|
|
|
Paragraph & par)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-02-26 17:04:10 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.layout();
|
2003-04-13 22:24:28 +00:00
|
|
|
|
pos_type const psize = par.size();
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2001-07-30 11:56:00 +00:00
|
|
|
|
LyXFont layoutfont;
|
2003-04-13 22:24:28 +00:00
|
|
|
|
for (pos_type pos = 0; pos < psize; ++pos) {
|
2003-11-13 13:43:44 +00:00
|
|
|
|
if (pos < par.beginOfBody())
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->labelfont;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2002-06-24 20:28:12 +00:00
|
|
|
|
layoutfont = layout->font;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-07-27 21:59:06 +00:00
|
|
|
|
LyXFont tmpfont = par.getFontSettings(params, pos);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmpfont.reduce(layoutfont);
|
2003-02-26 17:04:10 +00:00
|
|
|
|
par.setFont(pos, tmpfont);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2004-01-09 09:04:33 +00:00
|
|
|
|
// return past-the-last paragraph influenced by a layout change on pit
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type LyXText::undoSpan(par_type pit)
|
2004-01-09 09:04:33 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type end = paragraphs().size();
|
|
|
|
|
par_type nextpit = pit + 1;
|
2004-01-09 09:04:33 +00:00
|
|
|
|
if (nextpit == end)
|
|
|
|
|
return nextpit;
|
|
|
|
|
//because of parindents
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!pars_[pit].getDepth())
|
2004-01-09 09:04:33 +00:00
|
|
|
|
return boost::next(nextpit);
|
|
|
|
|
//because of depth constrains
|
|
|
|
|
for (; nextpit != end; ++pit, ++nextpit) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (!pars_[pit].getDepth())
|
2004-01-09 09:04:33 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return nextpit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type LyXText::setLayout(par_type start, par_type end, string const & layout)
|
2001-04-04 21:47:26 +00:00
|
|
|
|
{
|
2004-01-09 09:04:33 +00:00
|
|
|
|
BOOST_ASSERT(start != end);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type undopit = undoSpan(end - 1);
|
|
|
|
|
recUndo(start, undopit - 1);
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & bufparams = bv()->buffer()->params();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr const & lyxlayout = bufparams.getLyXTextClass()[layout];
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
for (par_type pit = start; pit != end; ++pit) {
|
|
|
|
|
pars_[pit].applyLayout(lyxlayout);
|
|
|
|
|
makeFontEntriesLayoutSpecific(bufparams, pars_[pit]);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (lyxlayout->margintype == MARGIN_MANUAL)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[pit].setLabelWidthString(lyxlayout->labelstring());
|
2003-12-08 12:47:18 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-12-08 12:47:18 +00:00
|
|
|
|
return undopit;
|
2000-05-04 08:14:34 +00:00
|
|
|
|
}
|
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
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::setLayout(LCursor & cur, string const & layout)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2003-05-19 07:12:09 +00:00
|
|
|
|
// special handling of new environment insets
|
2004-04-08 15:03:33 +00:00
|
|
|
|
BufferView & bv = cur.bv();
|
|
|
|
|
BufferParams const & params = bv.buffer()->params();
|
2003-05-19 07:12:09 +00:00
|
|
|
|
LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
|
|
|
|
|
if (lyxlayout->is_environment) {
|
|
|
|
|
// move everything in a new environment inset
|
2004-06-18 13:31:55 +00:00
|
|
|
|
lyxerr[Debug::DEBUG] << "setting layout " << layout << endl;
|
2004-04-08 15:03:33 +00:00
|
|
|
|
bv.owner()->dispatch(FuncRequest(LFUN_HOME));
|
|
|
|
|
bv.owner()->dispatch(FuncRequest(LFUN_ENDSEL));
|
|
|
|
|
bv.owner()->dispatch(FuncRequest(LFUN_CUT));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
InsetBase * inset = new InsetEnvironment(params, layout);
|
2004-02-13 07:30:59 +00:00
|
|
|
|
insertInset(cur, inset);
|
2004-02-13 13:51:12 +00:00
|
|
|
|
//inset->edit(cur, true);
|
2004-04-08 15:03:33 +00:00
|
|
|
|
//bv.owner()->dispatch(FuncRequest(LFUN_PASTE));
|
2003-05-19 07:12:09 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type start = cur.selBegin().par();
|
|
|
|
|
par_type end = cur.selEnd().par() + 1;
|
|
|
|
|
par_type endpit = setLayout(start, end, layout);
|
2003-12-08 12:47:18 +00:00
|
|
|
|
redoParagraphs(start, endpit);
|
2003-03-17 16:25:00 +00:00
|
|
|
|
updateCounters();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
namespace {
|
2003-04-02 17:59:01 +00:00
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
void getSelectionSpan(LCursor & cur, par_type & beg, par_type & end)
|
2003-11-26 09:48:21 +00:00
|
|
|
|
{
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (!cur.selection()) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
beg = cur.par();
|
|
|
|
|
end = cur.par() + 1;
|
2003-11-26 09:48:21 +00:00
|
|
|
|
} else {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
beg = cur.selBegin().par();
|
|
|
|
|
end = cur.selEnd().par() + 1;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
}
|
2003-11-26 09:48:21 +00:00
|
|
|
|
}
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
|
|
|
|
|
2004-03-18 13:57:20 +00:00
|
|
|
|
bool changeDepthAllowed(LyXText::DEPTH_CHANGE type,
|
|
|
|
|
Paragraph const & par, int max_depth)
|
2003-11-26 09:48:21 +00:00
|
|
|
|
{
|
|
|
|
|
if (par.layout()->labeltype == LABEL_BIBLIO)
|
|
|
|
|
return false;
|
|
|
|
|
int const depth = par.params().depth();
|
2004-03-18 13:57:20 +00:00
|
|
|
|
if (type == LyXText::INC_DEPTH && depth < max_depth)
|
2003-11-26 09:48:21 +00:00
|
|
|
|
return true;
|
2004-03-18 13:57:20 +00:00
|
|
|
|
if (type == LyXText::DEC_DEPTH && depth > 0)
|
2003-11-26 09:48:21 +00:00
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2003-04-03 01:26:02 +00:00
|
|
|
|
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
}
|
2001-05-31 02:23:46 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-18 13:57:20 +00:00
|
|
|
|
bool LyXText::changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const
|
2003-11-26 09:48:21 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-04-03 08:37:12 +00:00
|
|
|
|
par_type beg, end;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
getSelectionSpan(cur, beg, end);
|
2003-11-26 09:48:21 +00:00
|
|
|
|
int max_depth = 0;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (beg != 0)
|
|
|
|
|
max_depth = pars_[beg - 1].getMaxDepthAfter();
|
2003-04-02 21:19:35 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
for (par_type pit = beg; pit != end; ++pit) {
|
|
|
|
|
if (::changeDepthAllowed(type, pars_[pit], max_depth))
|
2003-11-26 09:48:21 +00:00
|
|
|
|
return true;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
max_depth = pars_[pit].getMaxDepthAfter();
|
2001-05-31 02:23:46 +00:00
|
|
|
|
}
|
2003-11-26 09:48:21 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-03 01:26:02 +00:00
|
|
|
|
|
2004-03-18 13:57:20 +00:00
|
|
|
|
void LyXText::changeDepth(LCursor & cur, DEPTH_CHANGE type)
|
2003-11-26 09:48:21 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type beg, end;
|
|
|
|
|
getSelectionSpan(cur, beg, end);
|
2004-02-13 07:30:59 +00:00
|
|
|
|
recordUndoSelection(cur);
|
2003-04-02 17:59:01 +00:00
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
int max_depth = 0;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (beg != 0)
|
|
|
|
|
max_depth = pars_[beg - 1].getMaxDepthAfter();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
for (par_type pit = beg; pit != end; ++pit) {
|
|
|
|
|
if (::changeDepthAllowed(type, pars_[pit], max_depth)) {
|
|
|
|
|
int const depth = pars_[pit].params().depth();
|
2004-03-18 13:57:20 +00:00
|
|
|
|
if (type == INC_DEPTH)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[pit].params().depth(depth + 1);
|
2003-11-26 09:48:21 +00:00
|
|
|
|
else
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars_[pit].params().depth(depth - 1);
|
2003-11-26 09:48:21 +00:00
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
max_depth = pars_[pit].getMaxDepthAfter();
|
2003-04-02 17:59:01 +00:00
|
|
|
|
}
|
2003-04-07 20:32:29 +00:00
|
|
|
|
// this handles the counter labels, and also fixes up
|
|
|
|
|
// depth values for follow-on (child) paragraphs
|
2003-03-17 16:25:00 +00:00
|
|
|
|
updateCounters();
|
2001-05-31 02:23:46 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// set font over selection
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// if there is no selection just set the current_font
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (!cur.selection()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Determine basis font
|
|
|
|
|
LyXFont layoutfont;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type pit = cur.par();
|
|
|
|
|
if (cur.pos() < pars_[pit].beginOfBody())
|
2004-08-15 00:01:45 +00:00
|
|
|
|
layoutfont = getLabelFont(pars_[pit]);
|
2003-12-08 12:47:18 +00:00
|
|
|
|
else
|
2004-02-13 07:30:59 +00:00
|
|
|
|
layoutfont = getLayoutFont(pit);
|
2003-12-08 12:47:18 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Update current font
|
2002-03-21 17:27:08 +00:00
|
|
|
|
real_current_font.update(font,
|
2004-04-08 15:03:33 +00:00
|
|
|
|
cur.buffer().params().language,
|
2001-08-11 18:31:14 +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
|
2001-08-11 18:31:14 +00:00
|
|
|
|
real_current_font.realize(layoutfont);
|
2002-09-06 15:18:11 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-01 17:12:09 +00:00
|
|
|
|
// Ok, we have a selection.
|
2004-02-13 07:30:59 +00:00
|
|
|
|
recordUndoSelection(cur);
|
2003-11-27 09:22:41 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type const beg = cur.selBegin().par();
|
|
|
|
|
par_type const end = cur.selEnd().par();
|
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
DocIterator dit = cur.selectionBegin();
|
|
|
|
|
DocIterator ditend = cur.selectionEnd();
|
2004-04-07 08:07:26 +00:00
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
BufferParams const & params = cur.buffer().params();
|
2003-11-27 09:22:41 +00:00
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
// Don't use forwardChar here as ditend might have
|
2004-04-07 08:07:26 +00:00
|
|
|
|
// pos() == lastpos() and forwardChar would miss it.
|
2004-08-15 00:01:45 +00:00
|
|
|
|
for (; dit != ditend; dit.forwardPos()) {
|
|
|
|
|
if (dit.pos() != dit.lastpos()) {
|
|
|
|
|
LyXFont f = getFont(dit.paragraph(), dit.pos());
|
2004-04-07 08:07:26 +00:00
|
|
|
|
f.update(font, params.language, toggleall);
|
2004-08-15 00:01:45 +00:00
|
|
|
|
setCharFont(dit.par(), dit.pos(), f);
|
2004-04-07 08:07:26 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
redoParagraphs(beg, end + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-29 13:28:11 +00:00
|
|
|
|
// the cursor set functions have a special mechanism. When they
|
2004-01-13 15:25:52 +00:00
|
|
|
|
// realize you left an empty paragraph, they will delete it.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorHome(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
|
|
|
|
setCursor(cur, cur.par(), cur.textRow().pos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorEnd(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2003-11-10 09:06:48 +00:00
|
|
|
|
// if not on the last row of the par, put the cursor before
|
|
|
|
|
// the final space
|
2004-02-12 16:36:01 +00:00
|
|
|
|
pos_type const end = cur.textRow().endpos();
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par(), end == cur.lastpos() ? end : end - 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
void LyXText::cursorTop(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
|
|
|
|
setCursor(cur, 0, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorBottom(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
|
|
|
|
setCursor(cur, cur.lastpar(), boost::prior(paragraphs().end())->size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::toggleFree(LCursor & cur, LyXFont const & font, bool toggleall)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
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
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.message(_("No font change defined. "
|
2003-11-25 11:17:27 +00:00
|
|
|
|
"Use Character under the Layout menu to define font change."));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try implicit word selection
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// If there is a change in the language the implicit word selection
|
2000-04-24 20:58:23 +00:00
|
|
|
|
// is disabled.
|
2004-03-01 17:12:09 +00:00
|
|
|
|
CursorSlice resetCursor = cur.top();
|
2003-10-29 10:47:21 +00:00
|
|
|
|
bool implicitSelection =
|
2003-10-28 11:18:40 +00:00
|
|
|
|
font.language() == ignore_language
|
|
|
|
|
&& font.number() == LyXFont::IGNORE
|
2004-02-13 07:30:59 +00:00
|
|
|
|
&& selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD_STRICT);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Set font
|
2004-02-13 07:30:59 +00:00
|
|
|
|
setFont(cur, font, toggleall);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// Implicit selections are cleared afterwards
|
2004-02-13 07:30:59 +00:00
|
|
|
|
// and cursor is set to the original position.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (implicitSelection) {
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.clearSelection();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
cur.top() = resetCursor;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.resetAnchor();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
string LyXText::getStringToIndex(LCursor & cur)
|
2001-07-30 10:50:37 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2001-07-30 10:50:37 +00:00
|
|
|
|
// Try implicit word selection
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// If there is a change in the language the implicit word selection
|
2001-07-30 10:50:37 +00:00
|
|
|
|
// is disabled.
|
2004-03-01 17:12:09 +00:00
|
|
|
|
CursorSlice const reset_cursor = cur.top();
|
2003-07-01 11:51:20 +00:00
|
|
|
|
bool const implicitSelection =
|
2004-02-13 07:30:59 +00:00
|
|
|
|
selectWordWhenUnderCursor(cur, lyx::PREVIOUS_WORD);
|
2001-07-30 10:50:37 +00:00
|
|
|
|
|
2003-01-31 13:50:21 +00:00
|
|
|
|
string idxstring;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (!cur.selection())
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.message(_("Nothing to index!"));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
else if (cur.selBegin().par() != cur.selEnd().par())
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.message(_("Cannot index more than one paragraph!"));
|
2003-01-31 13:50:21 +00:00
|
|
|
|
else
|
2004-02-11 14:45:44 +00:00
|
|
|
|
idxstring = cur.selectionAsString(false);
|
2001-07-30 10:50:37 +00:00
|
|
|
|
|
2003-01-31 13:50:21 +00:00
|
|
|
|
// Reset cursors to their original position.
|
2004-03-01 17:12:09 +00:00
|
|
|
|
cur.top() = reset_cursor;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-01-31 13:50:21 +00:00
|
|
|
|
// Clear the implicit selection.
|
|
|
|
|
if (implicitSelection)
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
2003-01-31 13:50:21 +00:00
|
|
|
|
|
2001-07-30 10:50:37 +00:00
|
|
|
|
return idxstring;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-18 16:17:46 +00:00
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
void LyXText::setParagraph(LCursor & cur,
|
|
|
|
|
Spacing const & spacing, LyXAlignment align,
|
2003-12-08 12:47:18 +00:00
|
|
|
|
string const & labelwidthstring, bool noindent)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(cur.text());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// make sure that the depth behind the selection are restored, too
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type undopit = undoSpan(cur.selEnd().par());
|
|
|
|
|
recUndo(cur.selBegin().par(), undopit - 1);
|
2003-04-13 22:24:28 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
for (par_type pit = cur.selBegin().par(), end = cur.selEnd().par();
|
|
|
|
|
pit <= end; ++pit) {
|
|
|
|
|
Paragraph & par = pars_[pit];
|
|
|
|
|
ParagraphParameters & params = par.params();
|
2003-04-13 22:24:28 +00:00
|
|
|
|
params.spacing(spacing);
|
2003-10-27 12:41:26 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// does the layout allow the new alignment?
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.layout();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
if (align == LYX_ALIGN_LAYOUT)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
align = layout->align;
|
|
|
|
|
if (align & layout->alignpossible) {
|
|
|
|
|
if (align == layout->align)
|
2003-04-13 22:24:28 +00:00
|
|
|
|
params.align(LYX_ALIGN_LAYOUT);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
else
|
2003-04-13 22:24:28 +00:00
|
|
|
|
params.align(align);
|
2001-07-07 18:19:18 +00:00
|
|
|
|
}
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par.setLabelWidthString(labelwidthstring);
|
2003-04-13 22:24:28 +00:00
|
|
|
|
params.noindent(noindent);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
redoParagraphs(cur.selBegin().par(), undopit);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-12 17:13:22 +00:00
|
|
|
|
string expandLabel(LyXTextClass const & textclass,
|
|
|
|
|
LyXLayout_ptr const & layout, bool appendix)
|
|
|
|
|
{
|
|
|
|
|
string fmt = appendix ?
|
|
|
|
|
layout->labelstring_appendix() : layout->labelstring();
|
|
|
|
|
|
|
|
|
|
// handle 'inherited level parts' in 'fmt',
|
|
|
|
|
// i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
|
|
|
|
|
size_t const i = fmt.find('@', 0);
|
|
|
|
|
if (i != string::npos) {
|
|
|
|
|
size_t const j = fmt.find('@', i + 1);
|
|
|
|
|
if (j != string::npos) {
|
|
|
|
|
string parent(fmt, i + 1, j - i - 1);
|
|
|
|
|
string label = expandLabel(textclass, textclass[parent], appendix);
|
|
|
|
|
fmt = string(fmt, 0, i) + label + string(fmt, j + 1, string::npos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return textclass.counters().counterLabel(fmt);
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-08 17:44:32 +00:00
|
|
|
|
|
2003-11-25 17:23:36 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
void incrementItemDepth(ParagraphList & pars, par_type pit, par_type first_pit)
|
2003-10-08 17:44:32 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int const cur_labeltype = pars[pit].layout()->labeltype;
|
2003-10-08 17:44:32 +00:00
|
|
|
|
|
2003-11-25 11:17:27 +00:00
|
|
|
|
if (cur_labeltype != LABEL_ENUMERATE && cur_labeltype != LABEL_ITEMIZE)
|
2003-10-08 17:44:32 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int const cur_depth = pars[pit].getDepth();
|
2003-10-08 17:44:32 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type prev_pit = pit - 1;
|
2003-10-08 17:44:32 +00:00
|
|
|
|
while (true) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int const prev_depth = pars[prev_pit].getDepth();
|
|
|
|
|
int const prev_labeltype = pars[prev_pit].layout()->labeltype;
|
2003-10-08 17:44:32 +00:00
|
|
|
|
if (prev_depth == 0 && cur_depth > 0) {
|
|
|
|
|
if (prev_labeltype == cur_labeltype) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars[pit].itemdepth = pars[prev_pit].itemdepth + 1;
|
2003-10-08 17:44:32 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
} else if (prev_depth < cur_depth) {
|
|
|
|
|
if (prev_labeltype == cur_labeltype) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars[pit].itemdepth = pars[prev_pit].itemdepth + 1;
|
2003-10-08 17:44:32 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (prev_depth == cur_depth) {
|
|
|
|
|
if (prev_labeltype == cur_labeltype) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
pars[pit].itemdepth = pars[prev_pit].itemdepth;
|
2003-10-08 17:44:32 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (prev_pit == first_pit)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
--prev_pit;
|
|
|
|
|
}
|
2003-09-12 17:13:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
void resetEnumCounterIfNeeded(ParagraphList & pars, par_type pit,
|
|
|
|
|
par_type firstpit, Counters & counters)
|
2003-10-08 17:44:32 +00:00
|
|
|
|
{
|
|
|
|
|
if (pit == firstpit)
|
|
|
|
|
return;
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int const cur_depth = pars[pit].getDepth();
|
|
|
|
|
par_type prev_pit = pit - 1;
|
2003-10-08 17:44:32 +00:00
|
|
|
|
while (true) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int const prev_depth = pars[prev_pit].getDepth();
|
|
|
|
|
int const prev_labeltype = pars[prev_pit].layout()->labeltype;
|
2003-10-08 17:44:32 +00:00
|
|
|
|
if (prev_depth <= cur_depth) {
|
|
|
|
|
if (prev_labeltype != LABEL_ENUMERATE) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
switch (pars[pit].itemdepth) {
|
2003-10-08 17:44:32 +00:00
|
|
|
|
case 0:
|
|
|
|
|
counters.reset("enumi");
|
|
|
|
|
case 1:
|
|
|
|
|
counters.reset("enumii");
|
|
|
|
|
case 2:
|
|
|
|
|
counters.reset("enumiii");
|
|
|
|
|
case 3:
|
|
|
|
|
counters.reset("enumiv");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prev_pit == firstpit)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
--prev_pit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// set the counter of a paragraph. This includes the labels
|
2004-03-25 09:16:36 +00:00
|
|
|
|
void LyXText::setCounter(Buffer const & buf, par_type pit)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-08-15 16:52:44 +00:00
|
|
|
|
Paragraph & par = pars_[pit];
|
2003-09-09 09:47:59 +00:00
|
|
|
|
BufferParams const & bufparams = buf.params();
|
|
|
|
|
LyXTextClass const & textclass = bufparams.getLyXTextClass();
|
2004-08-15 16:52:44 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.layout();
|
2003-10-08 17:44:32 +00:00
|
|
|
|
Counters & counters = textclass.counters();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-08 17:44:32 +00:00
|
|
|
|
// Always reset
|
2004-08-15 16:52:44 +00:00
|
|
|
|
par.itemdepth = 0;
|
2003-10-08 17:44:32 +00:00
|
|
|
|
|
2004-08-16 00:32:04 +00:00
|
|
|
|
if (pit == 0) {
|
2004-08-15 16:52:44 +00:00
|
|
|
|
par.params().appendix(par.params().startOfAppendix());
|
2003-10-08 17:44:32 +00:00
|
|
|
|
} else {
|
2004-08-15 16:52:44 +00:00
|
|
|
|
par.params().appendix(pars_[pit - 1].params().appendix());
|
|
|
|
|
if (!par.params().appendix() &&
|
|
|
|
|
par.params().startOfAppendix()) {
|
|
|
|
|
par.params().appendix(true);
|
2002-09-06 14:48:01 +00:00
|
|
|
|
textclass.counters().reset();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-10-08 17:44:32 +00:00
|
|
|
|
// Maybe we have to increment the item depth.
|
2004-08-16 00:32:04 +00:00
|
|
|
|
incrementItemDepth(pars_, pit, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-09-12 17:13:22 +00:00
|
|
|
|
// erase what was there before
|
2004-08-15 16:52:44 +00:00
|
|
|
|
par.params().labelString(string());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->margintype == MARGIN_MANUAL) {
|
2004-08-15 16:52:44 +00:00
|
|
|
|
if (par.params().labelWidthString().empty())
|
|
|
|
|
par.setLabelWidthString(layout->labelstring());
|
2000-02-29 02:19:17 +00:00
|
|
|
|
} else {
|
2004-08-15 16:52:44 +00:00
|
|
|
|
par.setLabelWidthString(string());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-08-10 15:21:07 +00:00
|
|
|
|
|
2001-07-07 18:19:18 +00:00
|
|
|
|
// is it a layout that has an automatic label?
|
2003-09-12 17:13:22 +00:00
|
|
|
|
if (layout->labeltype == LABEL_COUNTER) {
|
|
|
|
|
BufferParams const & bufparams = buf.params();
|
|
|
|
|
LyXTextClass const & textclass = bufparams.getLyXTextClass();
|
2003-10-08 17:44:32 +00:00
|
|
|
|
counters.step(layout->counter);
|
2004-08-15 16:52:44 +00:00
|
|
|
|
string label = expandLabel(textclass, layout, par.params().appendix());
|
|
|
|
|
par.params().labelString(label);
|
2003-09-12 17:13:22 +00:00
|
|
|
|
} else if (layout->labeltype == LABEL_ITEMIZE) {
|
2003-10-08 17:44:32 +00:00
|
|
|
|
// At some point of time we should do something more
|
|
|
|
|
// clever here, like:
|
2004-08-15 16:52:44 +00:00
|
|
|
|
// par.params().labelString(
|
|
|
|
|
// bufparams.user_defined_bullet(par.itemdepth).getText());
|
2003-10-08 17:44:32 +00:00
|
|
|
|
// for now, use a simple hardcoded label
|
|
|
|
|
string itemlabel;
|
2004-08-15 16:52:44 +00:00
|
|
|
|
switch (par.itemdepth) {
|
2003-10-08 17:44:32 +00:00
|
|
|
|
case 0:
|
|
|
|
|
itemlabel = "*";
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
itemlabel = "-";
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
itemlabel = "@";
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
itemlabel = "<EFBFBD>";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-15 16:52:44 +00:00
|
|
|
|
par.params().labelString(itemlabel);
|
2003-09-12 17:13:22 +00:00
|
|
|
|
} else if (layout->labeltype == LABEL_ENUMERATE) {
|
2003-10-08 17:44:32 +00:00
|
|
|
|
// Maybe we have to reset the enumeration counter.
|
2004-08-16 00:32:04 +00:00
|
|
|
|
resetEnumCounterIfNeeded(pars_, pit, 0, counters);
|
2003-10-08 17:44:32 +00:00
|
|
|
|
|
2003-09-12 17:13:22 +00:00
|
|
|
|
// FIXME
|
|
|
|
|
// Yes I know this is a really, really! bad solution
|
|
|
|
|
// (Lgb)
|
|
|
|
|
string enumcounter = "enum";
|
|
|
|
|
|
2004-08-15 16:52:44 +00:00
|
|
|
|
switch (par.itemdepth) {
|
2003-09-12 17:13:22 +00:00
|
|
|
|
case 2:
|
|
|
|
|
enumcounter += 'i';
|
|
|
|
|
case 1:
|
|
|
|
|
enumcounter += 'i';
|
|
|
|
|
case 0:
|
|
|
|
|
enumcounter += 'i';
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
enumcounter += "iv";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// not a valid enumdepth...
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-09-18 17:39:21 +00:00
|
|
|
|
|
2003-10-08 17:44:32 +00:00
|
|
|
|
counters.step(enumcounter);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-08-15 16:52:44 +00:00
|
|
|
|
par.params().labelString(counters.enumLabel(enumcounter));
|
2002-06-24 20:28:12 +00:00
|
|
|
|
} else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
|
2003-10-08 17:44:32 +00:00
|
|
|
|
counters.step("bibitem");
|
|
|
|
|
int number = counters.value("bibitem");
|
2004-08-15 16:52:44 +00:00
|
|
|
|
if (par.bibitem()) {
|
|
|
|
|
par.bibitem()->setCounter(number);
|
|
|
|
|
par.params().labelString(layout->labelstring());
|
2000-08-04 13:12:30 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// In biblio should't be following counters but...
|
|
|
|
|
} else {
|
2003-08-28 07:41:31 +00:00
|
|
|
|
string s = buf.B_(layout->labelstring());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// the caption hack:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->labeltype == LABEL_SENSITIVE) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type end = paragraphs().size();
|
|
|
|
|
par_type tmppit = pit;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
InsetBase * in = 0;
|
2002-08-20 11:14:46 +00:00
|
|
|
|
bool isOK = false;
|
2004-04-08 15:03:33 +00:00
|
|
|
|
while (tmppit != end) {
|
|
|
|
|
in = pars_[tmppit].inInset();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (in->lyxCode() == InsetBase::FLOAT_CODE ||
|
|
|
|
|
in->lyxCode() == InsetBase::WRAP_CODE) {
|
2002-08-20 11:14:46 +00:00
|
|
|
|
isOK = true;
|
|
|
|
|
break;
|
2004-08-16 00:32:04 +00:00
|
|
|
|
}
|
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning replace this code by something that works
|
|
|
|
|
// This code does not work because we have currently no way to move up
|
|
|
|
|
// in the hierarchy of insets (JMarc 16/08/2004)
|
|
|
|
|
#endif
|
|
|
|
|
#if 0
|
|
|
|
|
/* I think this code is supposed to be useful when one has a caption
|
|
|
|
|
* in a minipage in a figure inset. We need to go up to be able to see
|
|
|
|
|
* that the caption sould use "Figure" as label
|
|
|
|
|
*/
|
|
|
|
|
else {
|
2003-08-28 07:41:31 +00:00
|
|
|
|
Paragraph const * owner = &ownerPar(buf, in);
|
2004-08-16 00:32:04 +00:00
|
|
|
|
tmppit = 0;
|
2003-07-31 13:38:06 +00:00
|
|
|
|
for ( ; tmppit != end; ++tmppit)
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (&pars_[tmppit] == owner)
|
2003-07-31 13:38:06 +00:00
|
|
|
|
break;
|
2002-08-20 11:14:46 +00:00
|
|
|
|
}
|
2004-08-16 00:32:04 +00:00
|
|
|
|
#endif
|
2002-08-20 11:14:46 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-07-19 17:16:27 +00:00
|
|
|
|
if (isOK) {
|
2003-05-06 06:16:59 +00:00
|
|
|
|
string type;
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (in->lyxCode() == InsetBase::FLOAT_CODE)
|
2003-05-06 06:16:59 +00:00
|
|
|
|
type = static_cast<InsetFloat*>(in)->params().type;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
else if (in->lyxCode() == InsetBase::WRAP_CODE)
|
2003-05-06 06:16:59 +00:00
|
|
|
|
type = static_cast<InsetWrap*>(in)->params().type;
|
|
|
|
|
else
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2003-05-06 06:16:59 +00:00
|
|
|
|
|
|
|
|
|
Floating const & fl = textclass.floats().getType(type);
|
2002-08-06 22:40:59 +00:00
|
|
|
|
|
2003-10-08 17:44:32 +00:00
|
|
|
|
counters.step(fl.type());
|
2002-08-20 21:50:08 +00:00
|
|
|
|
|
2002-08-12 20:24:10 +00:00
|
|
|
|
// Doesn't work... yet.
|
2003-08-28 07:41:31 +00:00
|
|
|
|
s = bformat(_("%1$s #:"), buf.B_(fl.name()));
|
2000-07-18 17:45:27 +00:00
|
|
|
|
} else {
|
2002-08-21 14:23:28 +00:00
|
|
|
|
// par->SetLayout(0);
|
2002-08-21 17:35:24 +00:00
|
|
|
|
// s = layout->labelstring;
|
2002-12-01 21:10:37 +00:00
|
|
|
|
s = _("Senseless: ");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-08-15 16:52:44 +00:00
|
|
|
|
par.params().labelString(s);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
// Updates all counters.
|
2003-03-18 13:05:08 +00:00
|
|
|
|
void LyXText::updateCounters()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-08-11 09:09:01 +00:00
|
|
|
|
// start over
|
2003-09-09 09:47:59 +00:00
|
|
|
|
bv()->buffer()->params().getLyXTextClass().counters().reset();
|
2002-09-06 14:48:01 +00:00
|
|
|
|
|
2003-11-26 09:48:21 +00:00
|
|
|
|
bool update_pos = false;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type end = paragraphs().size();
|
|
|
|
|
for (par_type pit = 0; pit != end; ++pit) {
|
|
|
|
|
string const oldLabel = pars_[pit].params().labelString();
|
2003-05-16 07:44:00 +00:00
|
|
|
|
size_t maxdepth = 0;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pit != 0)
|
|
|
|
|
maxdepth = pars_[pit - 1].getMaxDepthAfter();
|
2003-04-07 20:32:29 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[pit].params().depth() > maxdepth)
|
|
|
|
|
pars_[pit].params().depth(maxdepth);
|
2003-04-07 20:32:29 +00:00
|
|
|
|
|
2002-12-01 21:10:37 +00:00
|
|
|
|
// setCounter can potentially change the labelString.
|
2003-08-28 07:41:31 +00:00
|
|
|
|
setCounter(*bv()->buffer(), pit);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
string const & newLabel = pars_[pit].params().labelString();
|
2003-11-26 09:48:21 +00:00
|
|
|
|
if (oldLabel != newLabel) {
|
2004-06-18 13:31:55 +00:00
|
|
|
|
//lyxerr[Debug::DEBUG] << "changing labels: old: " << oldLabel << " new: "
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// << newLabel << endl;
|
2003-11-26 09:48:21 +00:00
|
|
|
|
redoParagraphInternal(pit);
|
|
|
|
|
update_pos = true;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-11-26 09:48:21 +00:00
|
|
|
|
if (update_pos)
|
|
|
|
|
updateParPositions();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-16 00:32:04 +00:00
|
|
|
|
// this really should just insert the inset and not move the cursor.
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::insertInset(LCursor & cur, InsetBase * inset)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-03-08 21:14:45 +00:00
|
|
|
|
BOOST_ASSERT(inset);
|
2004-02-13 07:30:59 +00:00
|
|
|
|
cur.paragraph().insertInset(cur.pos(), inset);
|
2004-03-08 21:14:45 +00:00
|
|
|
|
redoParagraph(cur);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// needed to insert the selection
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::insertStringAsLines(LCursor & cur, string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type pit = cur.par();
|
|
|
|
|
par_type endpit = cur.par() + 1;
|
2004-03-18 13:28:49 +00:00
|
|
|
|
pos_type pos = cur.pos();
|
2004-02-13 07:30:59 +00:00
|
|
|
|
recordUndo(cur);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// only to be sure, should not be neccessary
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.clearSelection();
|
2004-04-08 15:03:33 +00:00
|
|
|
|
cur.buffer().insertStringAsLines(pars_, pit, pos, current_font, str);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
redoParagraphs(cur.par(), endpit);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par(), pos);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.setSelection();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
2003-12-01 13:35:49 +00:00
|
|
|
|
// turn double CR to single CR, others are converted into one
|
|
|
|
|
// blank. Then insertStringAsLines is called
|
2004-02-13 07:30:59 +00:00
|
|
|
|
void LyXText::insertStringAsParagraphs(LCursor & cur, string const & str)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2004-02-13 07:30:59 +00:00
|
|
|
|
string linestr = str;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
bool newline_inserted = false;
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
for (string::size_type i = 0, siz = linestr.size(); i < siz; ++i) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (linestr[i] == '\n') {
|
|
|
|
|
if (newline_inserted) {
|
|
|
|
|
// we know that \r will be ignored by
|
2003-12-01 13:35:49 +00:00
|
|
|
|
// insertStringAsLines. Of course, it is a dirty
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// trick, but it works...
|
|
|
|
|
linestr[i - 1] = '\r';
|
|
|
|
|
linestr[i] = '\n';
|
|
|
|
|
} else {
|
|
|
|
|
linestr[i] = ' ';
|
|
|
|
|
newline_inserted = true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
} else if (IsPrintable(linestr[i])) {
|
|
|
|
|
newline_inserted = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-02-13 07:30:59 +00:00
|
|
|
|
insertStringAsLines(cur, linestr);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
bool LyXText::setCursor(LCursor & cur, par_type par, pos_type pos,
|
|
|
|
|
bool setfont, bool boundary)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
LCursor old = cur;
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursorIntern(cur, par, pos, setfont, boundary);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return deleteEmptyParagraphMechanism(cur, old);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
void LyXText::setCursor(CursorSlice & cur, par_type par,
|
2003-10-09 10:52:12 +00:00
|
|
|
|
pos_type pos, bool boundary)
|
2000-04-19 14:42:19 +00:00
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
BOOST_ASSERT(par != int(paragraphs().size()));
|
2002-03-14 13:40:19 +00:00
|
|
|
|
|
2004-02-16 11:58:51 +00:00
|
|
|
|
cur.par() = par;
|
|
|
|
|
cur.pos() = pos;
|
|
|
|
|
cur.boundary() = boundary;
|
2003-10-08 14:29:16 +00:00
|
|
|
|
|
|
|
|
|
// no rows, no fun...
|
2003-12-01 13:35:49 +00:00
|
|
|
|
if (paragraphs().begin()->rows.empty())
|
2003-07-17 06:45:39 +00:00
|
|
|
|
return;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
2004-01-14 09:33:14 +00:00
|
|
|
|
// now some strict checking
|
2004-03-25 09:16:36 +00:00
|
|
|
|
Paragraph & para = getPar(par);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
Row const & row = *para.getRow(pos);
|
2003-10-27 11:44:10 +00:00
|
|
|
|
pos_type const end = row.endpos();
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// None of these should happen, but we're scaredy-cats
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (pos < 0) {
|
|
|
|
|
lyxerr << "dont like -1" << endl;
|
|
|
|
|
BOOST_ASSERT(false);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pos > para.size()) {
|
2003-10-24 15:04:17 +00:00
|
|
|
|
lyxerr << "dont like 1, pos: " << pos
|
2004-01-20 14:25:24 +00:00
|
|
|
|
<< " size: " << para.size()
|
2003-10-24 15:04:17 +00:00
|
|
|
|
<< " row.pos():" << row.pos()
|
2004-02-13 11:05:29 +00:00
|
|
|
|
<< " par: " << par << endl;
|
2003-10-24 15:04:17 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pos > end) {
|
2004-03-08 21:14:45 +00:00
|
|
|
|
lyxerr << "dont like 2, pos: " << pos
|
|
|
|
|
<< " size: " << para.size()
|
|
|
|
|
<< " row.pos():" << row.pos()
|
|
|
|
|
<< " par: " << par << endl;
|
2001-12-28 21:17:18 +00:00
|
|
|
|
// This shouldn't happen.
|
2003-10-24 15:04:17 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
}
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-02-16 11:58:51 +00:00
|
|
|
|
if (pos < row.pos()) {
|
2003-10-24 15:04:17 +00:00
|
|
|
|
lyxerr << "dont like 3 please report pos:" << pos
|
2004-01-20 14:25:24 +00:00
|
|
|
|
<< " size: " << para.size()
|
2003-10-24 15:04:17 +00:00
|
|
|
|
<< " row.pos():" << row.pos()
|
2004-02-13 11:05:29 +00:00
|
|
|
|
<< " par: " << par << endl;
|
2003-10-24 15:04:17 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2001-12-28 21:17:18 +00:00
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
void LyXText::setCursorIntern(LCursor & cur,
|
|
|
|
|
par_type par, pos_type pos, bool setfont, bool boundary)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-03-01 17:12:09 +00:00
|
|
|
|
setCursor(cur.top(), par, pos, boundary);
|
|
|
|
|
cur.x_target() = cursorX(cur.top());
|
2001-08-05 22:12:27 +00:00
|
|
|
|
if (setfont)
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCurrentFont(cur);
|
2000-05-30 19:31:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-23 04:57:18 +00:00
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
void LyXText::setCurrentFont(LCursor & cur)
|
2000-05-30 19:31:11 +00:00
|
|
|
|
{
|
2004-02-13 11:05:29 +00:00
|
|
|
|
BOOST_ASSERT(this == cur.text());
|
2004-01-20 14:25:24 +00:00
|
|
|
|
pos_type pos = cur.pos();
|
2004-08-15 00:01:45 +00:00
|
|
|
|
Paragraph & par = cur.paragraph();
|
2003-04-13 22:24:28 +00:00
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
if (cur.boundary() && pos > 0)
|
2000-05-30 19:31:11 +00:00
|
|
|
|
--pos;
|
|
|
|
|
|
|
|
|
|
if (pos > 0) {
|
2004-02-13 11:05:29 +00:00
|
|
|
|
if (pos == cur.lastpos())
|
2000-05-30 19:31:11 +00:00
|
|
|
|
--pos;
|
2001-05-30 13:17:50 +00:00
|
|
|
|
else // potentional bug... BUG (Lgb)
|
2004-08-15 00:01:45 +00:00
|
|
|
|
if (par.isSeparator(pos)) {
|
2004-02-13 11:05:29 +00:00
|
|
|
|
if (pos > cur.textRow().pos() &&
|
2003-10-23 13:28:49 +00:00
|
|
|
|
bidi.level(pos) % 2 ==
|
|
|
|
|
bidi.level(pos - 1) % 2)
|
2001-07-07 18:19:18 +00:00
|
|
|
|
--pos;
|
2004-02-13 11:05:29 +00:00
|
|
|
|
else if (pos + 1 < cur.lastpos())
|
2001-07-07 18:19:18 +00:00
|
|
|
|
++pos;
|
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
}
|
2000-05-30 19:31:11 +00:00
|
|
|
|
|
2004-04-08 15:03:33 +00:00
|
|
|
|
BufferParams const & bufparams = cur.buffer().params();
|
2004-08-15 00:01:45 +00:00
|
|
|
|
current_font = par.getFontSettings(bufparams, pos);
|
|
|
|
|
real_current_font = getFont(par, pos);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
if (cur.pos() == cur.lastpos()
|
2004-08-15 00:01:45 +00:00
|
|
|
|
&& bidi.isBoundary(cur.buffer(), par, cur.pos())
|
2004-02-13 11:05:29 +00:00
|
|
|
|
&& !cur.boundary()) {
|
2004-08-15 00:01:45 +00:00
|
|
|
|
Language const * lang = par.getParLanguage(bufparams);
|
2000-07-10 10:31:34 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
|
2004-02-06 13:18:49 +00:00
|
|
|
|
// x is an absolute screen coord
|
2003-03-10 05:03:33 +00:00
|
|
|
|
// returns the column near the specified x-coordinate of the row
|
|
|
|
|
// x is set to the real beginning of this column
|
2004-08-15 00:01:45 +00:00
|
|
|
|
pos_type LyXText::getColumnNearX(par_type const pit,
|
2003-10-17 10:31:47 +00:00
|
|
|
|
Row const & row, int & x, bool & boundary) const
|
2003-03-10 05:03:33 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
x -= xo_;
|
2004-03-01 16:29:30 +00:00
|
|
|
|
RowMetrics const r = computeRowMetrics(pit, row);
|
2004-08-15 00:01:45 +00:00
|
|
|
|
Paragraph const & par = pars_[pit];
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2003-10-17 10:31:47 +00:00
|
|
|
|
pos_type vc = row.pos();
|
2003-10-27 11:44:10 +00:00
|
|
|
|
pos_type end = row.endpos();
|
2003-03-10 05:03:33 +00:00
|
|
|
|
pos_type c = 0;
|
2004-08-15 00:01:45 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par.layout();
|
2003-03-10 05:03:33 +00:00
|
|
|
|
|
|
|
|
|
bool left_side = false;
|
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
pos_type body_pos = par.beginOfBody();
|
2004-03-01 12:23:17 +00:00
|
|
|
|
|
|
|
|
|
double tmpx = r.x;
|
2003-07-28 12:20:42 +00:00
|
|
|
|
double last_tmpx = tmpx;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
|
|
|
|
|
if (body_pos > 0 &&
|
2004-08-15 00:01:45 +00:00
|
|
|
|
(body_pos > end || !par.isLineSeparator(body_pos - 1)))
|
2003-03-10 05:03:33 +00:00
|
|
|
|
body_pos = 0;
|
|
|
|
|
|
|
|
|
|
// check for empty row
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (vc == end) {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
x = int(tmpx) + xo_;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-27 11:44:10 +00:00
|
|
|
|
while (vc < end && tmpx <= x) {
|
2003-10-23 13:28:49 +00:00
|
|
|
|
c = bidi.vis2log(vc);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
last_tmpx = tmpx;
|
2003-03-30 21:42:09 +00:00
|
|
|
|
if (body_pos > 0 && c == body_pos - 1) {
|
2004-03-01 12:23:17 +00:00
|
|
|
|
tmpx += r.label_hfill +
|
2004-08-15 00:01:45 +00:00
|
|
|
|
font_metrics::width(layout->labelsep, getLabelFont(par));
|
|
|
|
|
if (par.isLineSeparator(body_pos - 1))
|
|
|
|
|
tmpx -= singleWidth(par, body_pos - 1);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
if (hfillExpansion(par, row, c)) {
|
|
|
|
|
tmpx += singleWidth(par, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (c >= body_pos)
|
2004-03-01 12:23:17 +00:00
|
|
|
|
tmpx += r.hfill;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
else
|
2004-03-01 12:23:17 +00:00
|
|
|
|
tmpx += r.label_hfill;
|
2004-08-15 00:01:45 +00:00
|
|
|
|
} else if (par.isSeparator(c)) {
|
|
|
|
|
tmpx += singleWidth(par, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (c >= body_pos)
|
2004-03-01 12:23:17 +00:00
|
|
|
|
tmpx += r.separator;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
} else {
|
2004-08-15 00:01:45 +00:00
|
|
|
|
tmpx += singleWidth(par, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
++vc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((tmpx + last_tmpx) / 2 > x) {
|
|
|
|
|
tmpx = last_tmpx;
|
|
|
|
|
left_side = true;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-27 11:44:10 +00:00
|
|
|
|
BOOST_ASSERT(vc <= end); // This shouldn't happen.
|
2003-03-10 05:03:33 +00:00
|
|
|
|
|
|
|
|
|
boundary = false;
|
2003-03-31 16:57:45 +00:00
|
|
|
|
// This (rtl_support test) is not needed, but gives
|
2003-08-14 11:16:31 +00:00
|
|
|
|
// some speedup if rtl_support == false
|
2004-08-15 00:01:45 +00:00
|
|
|
|
bool const lastrow = lyxrc.rtl_support && row.endpos() == par.size();
|
2003-06-18 17:43:49 +00:00
|
|
|
|
|
2003-03-31 16:57:45 +00:00
|
|
|
|
// If lastrow is false, we don't need to compute
|
|
|
|
|
// the value of rtl.
|
2004-08-15 00:01:45 +00:00
|
|
|
|
bool const rtl = lastrow ? isRTL(par) : false;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (lastrow &&
|
2003-10-17 10:31:47 +00:00
|
|
|
|
((rtl && left_side && vc == row.pos() && x < tmpx - 5) ||
|
2003-10-27 11:44:10 +00:00
|
|
|
|
(!rtl && !left_side && vc == end && x > tmpx + 5)))
|
|
|
|
|
c = end;
|
2003-10-17 10:31:47 +00:00
|
|
|
|
else if (vc == row.pos()) {
|
2003-10-23 13:28:49 +00:00
|
|
|
|
c = bidi.vis2log(vc);
|
|
|
|
|
if (bidi.level(c) % 2 == 1)
|
2003-03-10 05:03:33 +00:00
|
|
|
|
++c;
|
|
|
|
|
} else {
|
2003-10-23 13:28:49 +00:00
|
|
|
|
c = bidi.vis2log(vc - 1);
|
|
|
|
|
bool const rtl = (bidi.level(c) % 2 == 1);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
if (left_side == rtl) {
|
|
|
|
|
++c;
|
2004-08-15 00:01:45 +00:00
|
|
|
|
boundary = bidi.isBoundary(*bv()->buffer(), par, c);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-15 00:01:45 +00:00
|
|
|
|
if (row.pos() < end && c >= end && par.isNewline(end - 1)) {
|
2003-10-27 11:44:10 +00:00
|
|
|
|
if (bidi.level(end -1) % 2 == 0)
|
2004-08-15 00:01:45 +00:00
|
|
|
|
tmpx -= singleWidth(par, end - 1);
|
2003-03-10 05:03:33 +00:00
|
|
|
|
else
|
2004-08-15 00:01:45 +00:00
|
|
|
|
tmpx += singleWidth(par, end - 1);
|
2003-10-27 11:44:10 +00:00
|
|
|
|
c = end - 1;
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
x = int(tmpx) + xo_;
|
|
|
|
|
return c - row.pos();
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-14 21:56:40 +00:00
|
|
|
|
// y is relative to this LyXText's top
|
|
|
|
|
// this is only used in the two functions below
|
|
|
|
|
Row const & LyXText::getRowNearY(int y, par_type & pit) const
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(!paragraphs().empty());
|
|
|
|
|
BOOST_ASSERT(!paragraphs().begin()->rows.empty());
|
|
|
|
|
par_type const pend = paragraphs().size() - 1;
|
|
|
|
|
pit = 0;
|
|
|
|
|
while (int(pars_[pit].y + pars_[pit].height) < y && pit != pend)
|
|
|
|
|
++pit;
|
|
|
|
|
|
|
|
|
|
RowList::iterator rit = pars_[pit].rows.end();
|
|
|
|
|
RowList::iterator const rbegin = pars_[pit].rows.begin();
|
|
|
|
|
do {
|
|
|
|
|
--rit;
|
|
|
|
|
} while (rit != rbegin && int(pars_[pit].y + rit->y_offset()) > y);
|
|
|
|
|
|
|
|
|
|
return *rit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-16 17:26:09 +00:00
|
|
|
|
// x,y are absolute coordinates
|
2004-08-14 19:55:00 +00:00
|
|
|
|
// sets cursor only within this LyXText
|
2004-02-13 13:51:12 +00:00
|
|
|
|
void LyXText::setCursorFromCoordinates(LCursor & cur, int x, int y)
|
2000-03-27 15:13:47 +00:00
|
|
|
|
{
|
2004-02-16 17:26:09 +00:00
|
|
|
|
x -= xo_;
|
|
|
|
|
y -= yo_;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type pit;
|
2004-04-21 19:51:18 +00:00
|
|
|
|
Row const & row = getRowNearY(y, pit);
|
2004-06-18 13:31:55 +00:00
|
|
|
|
lyxerr[Debug::DEBUG] << "setCursorFromCoordinates:: hit row at: "
|
|
|
|
|
<< row.pos() << endl;
|
2000-06-08 23:16:16 +00:00
|
|
|
|
bool bound = false;
|
2004-02-06 13:18:49 +00:00
|
|
|
|
int xx = x + xo_; // getRowNearX get absolute x coords
|
|
|
|
|
pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
setCursor(cur, pit, pos, true, bound);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// x,y are absolute screen coordinates
|
2004-08-14 19:55:00 +00:00
|
|
|
|
// sets cursor recursively descending into nested editable insets
|
2004-08-13 19:14:17 +00:00
|
|
|
|
InsetBase * LyXText::editXY(LCursor & cur, int x, int y) const
|
2004-01-30 11:41:12 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
par_type pit;
|
2004-04-21 19:51:18 +00:00
|
|
|
|
Row const & row = getRowNearY(y - yo_, pit);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
bool bound = false;
|
2004-02-06 13:18:49 +00:00
|
|
|
|
|
|
|
|
|
int xx = x; // is modified by getColumnNearX
|
2004-01-30 11:41:12 +00:00
|
|
|
|
pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cur.par() = pit;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
cur.pos() = pos;
|
|
|
|
|
cur.boundary() = bound;
|
|
|
|
|
|
|
|
|
|
// try to descend into nested insets
|
|
|
|
|
InsetBase * inset = checkInsetHit(x, y);
|
2004-08-13 22:24:42 +00:00
|
|
|
|
lyxerr << "inset " << inset << " hit at x: " << x << " y: " << y << endl;
|
2004-02-13 13:51:12 +00:00
|
|
|
|
if (!inset)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
// This should be just before or just behind the
|
|
|
|
|
// cursor position set above.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
BOOST_ASSERT((pos != 0 && inset == pars_[pit].getInset(pos - 1))
|
|
|
|
|
|| inset == pars_[pit].getInset(pos));
|
2004-02-13 13:51:12 +00:00
|
|
|
|
// Make sure the cursor points to the position before
|
|
|
|
|
// this inset.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (inset == pars_[pit].getInset(pos - 1))
|
2004-02-13 13:51:12 +00:00
|
|
|
|
--cur.pos();
|
|
|
|
|
return inset->editXY(cur, x, y);
|
2000-03-27 15:13:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
bool LyXText::checkAndActivateInset(LCursor & cur, bool front)
|
2003-11-17 14:28:18 +00:00
|
|
|
|
{
|
2004-02-20 17:19:53 +00:00
|
|
|
|
if (cur.selection())
|
|
|
|
|
return false;
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() == cur.lastpos())
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return false;
|
2004-02-12 16:36:01 +00:00
|
|
|
|
InsetBase * inset = cur.nextInset();
|
2003-11-17 14:28:18 +00:00
|
|
|
|
if (!isHighlyEditableInset(inset))
|
|
|
|
|
return false;
|
2004-02-12 16:36:01 +00:00
|
|
|
|
inset->edit(cur, front);
|
2003-11-17 14:28:18 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-20 17:19:53 +00:00
|
|
|
|
void LyXText::cursorLeft(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() != 0) {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
bool boundary = cur.boundary();
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par(), cur.pos() - 1, true, false);
|
2004-02-20 17:19:53 +00:00
|
|
|
|
if (!checkAndActivateInset(cur, false)) {
|
|
|
|
|
if (false && !boundary &&
|
2004-04-08 15:03:33 +00:00
|
|
|
|
bidi.isBoundary(cur.buffer(), cur.paragraph(), cur.pos() + 1))
|
2004-02-20 17:19:53 +00:00
|
|
|
|
setCursor(cur, cur.par(), cur.pos() + 1, true, true);
|
|
|
|
|
}
|
2004-04-08 08:41:29 +00:00
|
|
|
|
return;
|
2003-11-17 14:28:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (cur.par() != 0) {
|
2003-08-01 14:12:04 +00:00
|
|
|
|
// steps into the paragraph above
|
2004-03-25 09:16:36 +00:00
|
|
|
|
setCursor(cur, cur.par() - 1, getPar(cur.par() - 1).size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-20 17:19:53 +00:00
|
|
|
|
void LyXText::cursorRight(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-20 17:19:53 +00:00
|
|
|
|
if (false && cur.boundary()) {
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par(), cur.pos(), true, false);
|
2004-02-20 17:19:53 +00:00
|
|
|
|
return;
|
2003-11-17 14:28:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (cur.pos() != cur.lastpos()) {
|
2004-04-03 08:37:12 +00:00
|
|
|
|
if (!checkAndActivateInset(cur, true)) {
|
2004-02-20 17:19:53 +00:00
|
|
|
|
setCursor(cur, cur.par(), cur.pos() + 1, true, false);
|
2004-04-08 15:03:33 +00:00
|
|
|
|
if (false && bidi.isBoundary(cur.buffer(), cur.paragraph(),
|
2004-02-20 17:19:53 +00:00
|
|
|
|
cur.pos()))
|
|
|
|
|
setCursor(cur, cur.par(), cur.pos(), true, true);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2003-11-17 14:28:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-02-20 17:19:53 +00:00
|
|
|
|
if (cur.par() != cur.lastpar())
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par() + 1, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-20 17:19:53 +00:00
|
|
|
|
void LyXText::cursorUp(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-13 07:30:59 +00:00
|
|
|
|
Row const & row = cur.textRow();
|
2004-01-30 11:41:12 +00:00
|
|
|
|
int x = cur.x_target();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
int y = cursorY(cur.top()) - row.baseline() - 1;
|
2004-02-16 17:26:09 +00:00
|
|
|
|
setCursorFromCoordinates(cur, x, y);
|
2003-11-22 14:44:59 +00:00
|
|
|
|
|
2004-02-20 17:19:53 +00:00
|
|
|
|
if (!cur.selection()) {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
InsetBase * inset_hit = checkInsetHit(cur.x_target(), y);
|
2003-11-06 16:43:12 +00:00
|
|
|
|
if (inset_hit && isHighlyEditableInset(inset_hit))
|
2004-02-13 13:51:12 +00:00
|
|
|
|
inset_hit->editXY(cur, cur.x_target(), y);
|
2002-04-16 14:10:39 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-20 17:19:53 +00:00
|
|
|
|
void LyXText::cursorDown(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
Row const & row = cur.textRow();
|
2004-01-30 11:41:12 +00:00
|
|
|
|
int x = cur.x_target();
|
2004-03-01 17:12:09 +00:00
|
|
|
|
int y = cursorY(cur.top()) - row.baseline() + row.height() + 1;
|
2004-02-16 17:26:09 +00:00
|
|
|
|
setCursorFromCoordinates(cur, x, y);
|
2003-11-21 08:35:15 +00:00
|
|
|
|
|
2004-02-20 17:19:53 +00:00
|
|
|
|
if (!cur.selection()) {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
InsetBase * inset_hit = checkInsetHit(cur.x_target(), y);
|
2003-11-06 16:43:12 +00:00
|
|
|
|
if (inset_hit && isHighlyEditableInset(inset_hit))
|
2004-02-13 13:51:12 +00:00
|
|
|
|
inset_hit->editXY(cur, cur.x_target(), y);
|
2002-04-16 14:10:39 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorUpParagraph(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() > 0)
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par(), 0);
|
2004-02-12 16:36:01 +00:00
|
|
|
|
else if (cur.par() != 0)
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par() - 1, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-12 16:36:01 +00:00
|
|
|
|
void LyXText::cursorDownParagraph(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.par() != cur.lastpar())
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par() + 1, 0);
|
2003-08-01 14:12:04 +00:00
|
|
|
|
else
|
2004-02-13 11:05:29 +00:00
|
|
|
|
setCursor(cur, cur.par(), cur.lastpos());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-08-01 14:12:04 +00:00
|
|
|
|
|
2001-09-27 09:52:06 +00:00
|
|
|
|
// fix the cursor `cur' after a characters has been deleted at `where'
|
|
|
|
|
// position. Called by deleteEmptyParagraphMechanism
|
2004-01-13 14:13:51 +00:00
|
|
|
|
void LyXText::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where)
|
2001-09-27 09:52:06 +00:00
|
|
|
|
{
|
2004-02-13 13:51:12 +00:00
|
|
|
|
// do notheing if cursor is not in the paragraph where the
|
|
|
|
|
// deletion occured,
|
2001-09-27 09:52:06 +00:00
|
|
|
|
if (cur.par() != where.par())
|
|
|
|
|
return;
|
|
|
|
|
|
2004-02-13 13:51:12 +00:00
|
|
|
|
// if cursor position is after the deletion place update it
|
2001-09-27 09:52:06 +00:00
|
|
|
|
if (cur.pos() > where.pos())
|
2004-02-12 16:36:01 +00:00
|
|
|
|
--cur.pos();
|
2001-09-27 09:52:06 +00:00
|
|
|
|
|
2002-05-02 12:45:27 +00:00
|
|
|
|
// check also if we don't want to set the cursor on a spot behind the
|
|
|
|
|
// pagragraph because we erased the last character.
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (cur.pos() > cur.lastpos())
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2001-09-27 09:52:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor const & old)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
BOOST_ASSERT(cur.size() == old.size());
|
2000-03-14 23:33:15 +00:00
|
|
|
|
// Would be wrong to delete anything if we have a selection.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (cur.selection())
|
|
|
|
|
return false;
|
|
|
|
|
|
2004-06-18 13:31:55 +00:00
|
|
|
|
//lyxerr[Debug::DEBUG] << "DEPM: cur:\n" << cur << "old:\n" << old << endl;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
Paragraph const & oldpar = pars_[old.par()];
|
2003-10-10 09:01:23 +00:00
|
|
|
|
|
2000-03-14 23:33:15 +00:00
|
|
|
|
// We allow all kinds of "mumbo-jumbo" when freespacing.
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (oldpar.isFreeSpacing())
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-01-13 16:28:54 +00:00
|
|
|
|
/* Ok I'll put some comments here about what is missing.
|
|
|
|
|
I have fixed BackSpace (and thus Delete) to not delete
|
|
|
|
|
double-spaces automagically. I have also changed Cut,
|
|
|
|
|
Copy and Paste to hopefully do some sensible things.
|
|
|
|
|
There are still some small problems that can lead to
|
|
|
|
|
double spaces stored in the document file or space at
|
2003-12-01 13:35:49 +00:00
|
|
|
|
the beginning of paragraphs(). This happens if you have
|
2003-08-22 07:49:57 +00:00
|
|
|
|
the cursor between to spaces and then save. Or if you
|
2000-01-13 16:28:54 +00:00
|
|
|
|
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)
|
|
|
|
|
*/
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// If old.pos() == 0 and old.pos()(1) == LineSeparator
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// delete the LineSeparator.
|
|
|
|
|
// MISSING
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// If old.pos() == 1 and old.pos()(0) == LineSeparator
|
2000-01-13 16:28:54 +00:00
|
|
|
|
// delete the LineSeparator.
|
|
|
|
|
// MISSING
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// If the chars around the old cursor were spaces, delete one of them.
|
|
|
|
|
if (old.par() != cur.par() || old.pos() != cur.pos()) {
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// Only if the cursor has really moved.
|
|
|
|
|
if (old.pos() > 0
|
|
|
|
|
&& old.pos() < oldpar.size()
|
|
|
|
|
&& oldpar.isLineSeparator(old.pos())
|
|
|
|
|
&& oldpar.isLineSeparator(old.pos() - 1)) {
|
|
|
|
|
pars_[old.par()].erase(old.pos() - 1);
|
2001-09-27 09:52:06 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning This will not work anymore when we have multiple views of the same buffer
|
|
|
|
|
// In this case, we will have to correct also the cursors held by
|
|
|
|
|
// other bufferviews. It will probably be easier to do that in a more
|
2004-01-13 14:13:51 +00:00
|
|
|
|
// automated way in CursorSlice code. (JMarc 26/09/2001)
|
2001-09-27 09:52:06 +00:00
|
|
|
|
#endif
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// correct all cursor parts
|
|
|
|
|
fixCursorAfterDelete(cur.top(), old.top());
|
2004-04-29 14:49:02 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2004-04-07 16:57:57 +00:00
|
|
|
|
#warning DEPM, look here
|
2004-04-29 14:49:02 +00:00
|
|
|
|
#endif
|
2004-04-07 16:57:57 +00:00
|
|
|
|
//fixCursorAfterDelete(cur.anchor(), old.top());
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2000-03-14 23:33:15 +00:00
|
|
|
|
}
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// only do our magic if we changed paragraph
|
|
|
|
|
if (old.par() == cur.par())
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// don't delete anything if this is the ONLY paragraph!
|
|
|
|
|
if (pars_.size() == 1)
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2000-01-13 16:28:54 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// Do not delete empty paragraphs with keepempty set.
|
|
|
|
|
if (oldpar.allowEmpty())
|
2002-01-12 21:03:30 +00:00
|
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-01-12 21:03:30 +00:00
|
|
|
|
// record if we have deleted a paragraph
|
|
|
|
|
// we can't possibly have deleted a paragraph before this point
|
|
|
|
|
bool deleted = false;
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (oldpar.empty() || (oldpar.size() == 1 && oldpar.isLineSeparator(0))) {
|
2003-08-22 07:49:57 +00:00
|
|
|
|
// ok, we will delete something
|
2004-01-13 14:13:51 +00:00
|
|
|
|
CursorSlice tmpcursor;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-09-27 10:52:53 +00:00
|
|
|
|
deleted = true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-10-13 00:38:09 +00:00
|
|
|
|
bool selection_position_was_oldcursor_position =
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cur.anchor().par() == old.par() && cur.anchor().pos() == old.pos();
|
2003-04-16 00:02:38 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// This is a bit of a overkill. We change the old and the cur par
|
|
|
|
|
// at max, certainly not everything in between...
|
|
|
|
|
recUndo(old.par(), cur.par());
|
2001-07-07 18:19:18 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// Delete old par.
|
|
|
|
|
pars_.erase(pars_.begin() + old.par());
|
2003-08-28 07:41:31 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// Update cursor par offset if necessary.
|
|
|
|
|
// Some 'iterator registration' would be nice that takes care of
|
|
|
|
|
// such events. Maybe even signal/slot?
|
|
|
|
|
if (cur.par() > old.par())
|
|
|
|
|
--cur.par();
|
2004-04-29 14:49:02 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2004-04-07 16:57:57 +00:00
|
|
|
|
#warning DEPM, look here
|
2004-04-29 14:49:02 +00:00
|
|
|
|
#endif
|
2004-04-07 16:57:57 +00:00
|
|
|
|
// if (cur.anchor().par() > old.par())
|
|
|
|
|
// --cur.anchor().par();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-16 00:02:38 +00:00
|
|
|
|
if (selection_position_was_oldcursor_position) {
|
2001-09-27 10:52:53 +00:00
|
|
|
|
// correct selection
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cur.resetAnchor();
|
2000-01-13 16:28:54 +00:00
|
|
|
|
}
|
2001-09-27 10:52:53 +00:00
|
|
|
|
}
|
2003-10-28 11:18:40 +00:00
|
|
|
|
|
|
|
|
|
if (deleted)
|
|
|
|
|
return true;
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (pars_[old.par()].stripLeadingSpaces())
|
|
|
|
|
cur.resetAnchor();
|
|
|
|
|
|
2003-10-28 11:18:40 +00:00
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-01 13:35:49 +00:00
|
|
|
|
ParagraphList & LyXText::paragraphs() const
|
2000-06-12 11:27:15 +00:00
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
|
return const_cast<ParagraphList &>(pars_);
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
void LyXText::recUndo(par_type first, par_type last) const
|
2003-10-13 10:59:31 +00:00
|
|
|
|
{
|
2004-02-03 08:56:28 +00:00
|
|
|
|
recordUndo(bv()->cursor(), Undo::ATOMIC, first, last);
|
2003-10-13 10:59:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-13 11:05:29 +00:00
|
|
|
|
void LyXText::recUndo(par_type par) const
|
2003-10-13 10:59:31 +00:00
|
|
|
|
{
|
2004-02-03 08:56:28 +00:00
|
|
|
|
recordUndo(bv()->cursor(), Undo::ATOMIC, par, par);
|
2003-10-13 10:59:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-14 00:41:44 +00:00
|
|
|
|
int defaultRowHeight()
|
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
return int(font_metrics::maxHeight(LyXFont(LyXFont::ALL_SANE)) * 1.2);
|
2003-02-14 00:41:44 +00:00
|
|
|
|
}
|