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"
|
2005-01-06 16:39:35 +00:00
|
|
|
|
#include "support/convert.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
|
|
|
|
#include <sstream>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
using lyx::pit_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-11-30 01:59:49 +00:00
|
|
|
|
: maxwidth_(bv ? bv->workWidth() : 100),
|
2004-03-01 16:29:30 +00:00
|
|
|
|
background_color_(LColor::background),
|
2004-12-17 16:27:12 +00:00
|
|
|
|
bv_owner(bv),
|
|
|
|
|
autoBreakRows_(false)
|
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();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
dim_.wid = maxwidth_;
|
|
|
|
|
dim_.asc = 10;
|
|
|
|
|
dim_.des = 10;
|
2003-07-14 09:15:58 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_type const end = paragraphs().size();
|
|
|
|
|
for (pit_type pit = 0; pit != end; ++pit)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
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);
|
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-11-30 01:59:49 +00:00
|
|
|
|
//takes screen x,y coordinates
|
2004-10-05 10:11:42 +00:00
|
|
|
|
InsetBase * LyXText::checkInsetHit(int x, int y) const
|
2004-08-14 19:55:00 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
pit_type pit = getPitNearY(y);
|
|
|
|
|
BOOST_ASSERT(pit != -1);
|
2004-08-14 19:55:00 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Paragraph const & par = pars_[pit];
|
2004-08-14 19:55:00 +00:00
|
|
|
|
|
|
|
|
|
lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
lyxerr << " pit: " << pit << endl;
|
|
|
|
|
InsetList::const_iterator iit = par.insetlist.begin();
|
|
|
|
|
InsetList::const_iterator iend = par.insetlist.end();
|
|
|
|
|
for (; iit != iend; ++iit) {
|
|
|
|
|
InsetBase * inset = iit->inset;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
#if 1
|
2004-11-30 01:59:49 +00:00
|
|
|
|
lyxerr << "examining inset " << inset << endl;
|
2005-01-31 16:29:48 +00:00
|
|
|
|
if (theCoords.getInsets().has(inset))
|
2004-11-30 01:59:49 +00:00
|
|
|
|
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" << endl;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
#endif
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (inset->covers(x, y)) {
|
|
|
|
|
lyxerr << "Hit inset: " << inset << endl;
|
|
|
|
|
return inset;
|
2004-08-14 19:55:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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-11-24 21:53:46 +00:00
|
|
|
|
LyXFont LyXText::getLayoutFont(pit_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-11-24 21:53:46 +00:00
|
|
|
|
void LyXText::setCharFont(pit_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()) {
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_type tp = pit;
|
2003-04-16 08:12:22 +00:00
|
|
|
|
while (!layoutfont.resolved() &&
|
2004-11-24 21:53:46 +00:00
|
|
|
|
tp != pit_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-11-24 21:53:46 +00:00
|
|
|
|
if (tp != pit_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-11-24 21:53:46 +00:00
|
|
|
|
pit_type LyXText::undoSpan(pit_type pit)
|
2004-01-09 09:04:33 +00:00
|
|
|
|
{
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_type end = paragraphs().size();
|
|
|
|
|
pit_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-11-24 21:53:46 +00:00
|
|
|
|
pit_type LyXText::setLayout(pit_type start, pit_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-11-24 21:53:46 +00:00
|
|
|
|
pit_type undopit = undoSpan(end - 1);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
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-11-24 21:53:46 +00:00
|
|
|
|
for (pit_type pit = start; pit != end; ++pit) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
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-11-24 21:53:46 +00:00
|
|
|
|
pit_type start = cur.selBegin().pit();
|
|
|
|
|
pit_type end = cur.selEnd().pit() + 1;
|
2004-12-29 11:39:17 +00:00
|
|
|
|
setLayout(start, end, layout);
|
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-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-12-06 12:55:03 +00:00
|
|
|
|
pit_type const beg = cur.selBegin().pit();
|
|
|
|
|
pit_type const end = cur.selEnd().pit() + 1;
|
|
|
|
|
int max_depth = (beg != 0 ? pars_[beg - 1].getMaxDepthAfter() : 0);
|
2003-04-02 21:19:35 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
for (pit_type pit = beg; pit != end; ++pit) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
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-12-06 12:55:03 +00:00
|
|
|
|
pit_type const beg = cur.selBegin().pit();
|
|
|
|
|
pit_type const end = cur.selEnd().pit() + 1;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
recordUndoSelection(cur);
|
2004-12-06 12:55:03 +00:00
|
|
|
|
int max_depth = (beg != 0 ? pars_[beg - 1].getMaxDepthAfter() : 0);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
for (pit_type pit = beg; pit != end; ++pit) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Paragraph & par = pars_[pit];
|
|
|
|
|
if (::changeDepthAllowed(type, par, max_depth)) {
|
|
|
|
|
int const depth = par.params().depth();
|
2004-03-18 13:57:20 +00:00
|
|
|
|
if (type == INC_DEPTH)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
par.params().depth(depth + 1);
|
2003-11-26 09:48:21 +00:00
|
|
|
|
else
|
2004-11-30 01:59:49 +00:00
|
|
|
|
par.params().depth(depth - 1);
|
2003-11-26 09:48:21 +00:00
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
max_depth = par.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-11-24 21:53:46 +00:00
|
|
|
|
pit_type pit = cur.pit();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
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-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-11-24 21:53:46 +00:00
|
|
|
|
setCharFont(dit.pit(), dit.pos(), f);
|
2004-04-07 08:07:26 +00:00
|
|
|
|
}
|
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());
|
2004-11-24 21:53:46 +00:00
|
|
|
|
setCursor(cur, cur.pit(), 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-11-30 01:59:49 +00:00
|
|
|
|
// FIXME: does this final space exist?
|
2004-02-12 16:36:01 +00:00
|
|
|
|
pos_type const end = cur.textRow().endpos();
|
2004-11-24 21:53:46 +00:00
|
|
|
|
setCursor(cur, cur.pit(), 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());
|
2004-11-24 21:53:46 +00:00
|
|
|
|
setCursor(cur, cur.lastpit(), 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-11-24 21:53:46 +00:00
|
|
|
|
else if (cur.selBegin().pit() != cur.selEnd().pit())
|
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-11-24 21:53:46 +00:00
|
|
|
|
pit_type undopit = undoSpan(cur.selEnd().pit());
|
|
|
|
|
recUndo(cur.selBegin().pit(), undopit - 1);
|
2003-04-13 22:24:28 +00:00
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
for (pit_type pit = cur.selBegin().pit(), end = cur.selEnd().pit();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
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
|
|
|
|
}
|
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-11-24 21:53:46 +00:00
|
|
|
|
void incrementItemDepth(ParagraphList & pars, pit_type pit, pit_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-11-24 21:53:46 +00:00
|
|
|
|
pit_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-11-24 21:53:46 +00:00
|
|
|
|
void resetEnumCounterIfNeeded(ParagraphList & pars, pit_type pit,
|
|
|
|
|
pit_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();
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_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-11-24 21:53:46 +00:00
|
|
|
|
void LyXText::setCounter(Buffer const & buf, pit_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-11-24 21:53:46 +00:00
|
|
|
|
pit_type end = paragraphs().size();
|
|
|
|
|
pit_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();
|
2005-02-13 14:53:47 +00:00
|
|
|
|
// FIXME: in should be always valid.
|
2005-02-10 20:15:14 +00:00
|
|
|
|
if (in &&
|
|
|
|
|
(in->lyxCode() == InsetBase::FLOAT_CODE ||
|
|
|
|
|
in->lyxCode() == InsetBase::WRAP_CODE)) {
|
2002-08-20 11:14:46 +00:00
|
|
|
|
isOK = true;
|
|
|
|
|
break;
|
2004-10-05 10:11:42 +00:00
|
|
|
|
}
|
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
|
2004-11-01 10:33:58 +00:00
|
|
|
|
* that the caption should use "Figure" as label
|
2004-08-16 00:32:04 +00:00
|
|
|
|
*/
|
|
|
|
|
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-11-01 10:33:58 +00:00
|
|
|
|
#else
|
|
|
|
|
++tmppit;
|
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-11-24 21:53:46 +00:00
|
|
|
|
pit_type end = paragraphs().size();
|
|
|
|
|
for (pit_type pit = 0; pit != end; ++pit) {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
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
|
|
|
|
update_pos = true;
|
|
|
|
|
}
|
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);
|
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-11-24 21:53:46 +00:00
|
|
|
|
pit_type pit = cur.pit();
|
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-12-17 16:27:12 +00:00
|
|
|
|
cur.buffer().insertStringAsLines(pars_, pit, pos, current_font, str,
|
|
|
|
|
autoBreakRows_);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.resetAnchor();
|
2004-11-24 21:53:46 +00:00
|
|
|
|
setCursor(cur, cur.pit(), 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-11-24 21:53:46 +00:00
|
|
|
|
bool LyXText::setCursor(LCursor & cur, pit_type par, pos_type pos,
|
2004-02-13 11:05:29 +00:00
|
|
|
|
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-11-24 21:53:46 +00:00
|
|
|
|
void LyXText::setCursor(CursorSlice & cur, pit_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()));
|
2004-11-24 21:53:46 +00:00
|
|
|
|
cur.pit() = par;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
cur.pos() = pos;
|
|
|
|
|
cur.boundary() = boundary;
|
2003-10-08 14:29:16 +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);
|
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()
|
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,
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pit_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);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
cur.setTargetX();
|
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-11-24 21:53:46 +00:00
|
|
|
|
pos_type LyXText::getColumnNearX(pit_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-11-30 01:59:49 +00:00
|
|
|
|
int const xo = theCoords.get(this, pit).x_;
|
|
|
|
|
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-11-30 01:59:49 +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-11-30 01:59:49 +00:00
|
|
|
|
x = int(tmpx) + xo;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
return c - row.pos();
|
2003-03-10 05:03:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// y is screen coordinate
|
|
|
|
|
pit_type LyXText::getPitNearY(int y) const
|
2004-08-14 21:56:40 +00:00
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(!paragraphs().empty());
|
2005-01-31 16:29:48 +00:00
|
|
|
|
BOOST_ASSERT(theCoords.getParPos().find(this) != theCoords.getParPos().end());
|
|
|
|
|
CoordCache::InnerParPosCache const & cc = theCoords.getParPos().find(this)->second;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
lyxerr << "LyXText::getPitNearY: y: " << y << " cache size: "
|
|
|
|
|
<< cc.size() << endl;
|
|
|
|
|
|
|
|
|
|
// look for highest numbered paragraph with y coordinate less than given y
|
|
|
|
|
pit_type pit = 0;
|
|
|
|
|
int yy = -1;
|
|
|
|
|
CoordCache::InnerParPosCache::const_iterator it = cc.begin();
|
|
|
|
|
CoordCache::InnerParPosCache::const_iterator et = cc.end();
|
|
|
|
|
for (; it != et; ++it) {
|
|
|
|
|
lyxerr << " examining: pit: " << it->first << " y: "
|
|
|
|
|
<< it->second.y_ << endl;
|
|
|
|
|
if (it->first >= pit && int(it->second.y_) - int(pars_[it->first].ascent()) <= y) {
|
|
|
|
|
pit = it->first;
|
|
|
|
|
yy = it->second.y_;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-08-14 21:56:40 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
lyxerr << " found best y: " << yy << " for pit: " << pit << endl;
|
|
|
|
|
return pit;
|
2004-08-14 21:56:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Row const & LyXText::getRowNearY(int y, pit_type pit) const
|
2000-03-27 15:13:47 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Paragraph const & par = pars_[pit];
|
|
|
|
|
int yy = theCoords.get(this, pit).y_ - par.ascent();
|
|
|
|
|
BOOST_ASSERT(!par.rows().empty());
|
|
|
|
|
RowList::const_iterator rit = par.rows().begin();
|
|
|
|
|
RowList::const_iterator const rlast = boost::prior(par.rows().end());
|
|
|
|
|
for (; rit != rlast; yy += rit->height(), ++rit)
|
|
|
|
|
if (yy + rit->height() > y)
|
|
|
|
|
break;
|
|
|
|
|
return *rit;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
|
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-11-30 01:59:49 +00:00
|
|
|
|
pit_type pit = getPitNearY(y);
|
|
|
|
|
BOOST_ASSERT(pit != -1);
|
|
|
|
|
Row const & row = getRowNearY(y, 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-11-24 21:53:46 +00:00
|
|
|
|
cur.pit() = pit;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
cur.pos() = pos;
|
|
|
|
|
cur.boundary() = bound;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
cur.x_target() = x;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
|
|
|
|
|
// 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-11-30 01:59:49 +00:00
|
|
|
|
if (!inset) {
|
2005-02-08 02:06:39 +00:00
|
|
|
|
// Either we deconst editXY or better we move current_font
|
|
|
|
|
// and real_current_font to LCursor
|
2004-11-30 01:59:49 +00:00
|
|
|
|
const_cast<LyXText *>(this)->setCurrentFont(cur);
|
2004-02-13 13:51:12 +00:00
|
|
|
|
return 0;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-02-13 13:51:12 +00:00
|
|
|
|
// 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();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
inset = inset->editXY(cur, x, y);
|
|
|
|
|
if (cur.top().text() == this)
|
|
|
|
|
const_cast<LyXText *>(this)->setCurrentFont(cur);
|
|
|
|
|
return inset;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool 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();
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool updateNeeded = setCursor(cur, cur.pit(), 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))
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updateNeeded |=
|
|
|
|
|
setCursor(cur, cur.pit(), cur.pos() + 1, true, true);
|
2004-02-20 17:19:53 +00:00
|
|
|
|
}
|
2005-02-08 02:06:39 +00:00
|
|
|
|
return updateNeeded;
|
2003-11-17 14:28:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (cur.pit() != 0) {
|
2005-02-08 02:06:39 +00:00
|
|
|
|
// Steps into the paragraph above
|
|
|
|
|
return setCursor(cur, cur.pit() - 1, getPar(cur.pit() - 1).size());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2005-02-08 02:06:39 +00:00
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool LyXText::cursorRight(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-02-20 17:19:53 +00:00
|
|
|
|
if (false && cur.boundary()) {
|
2005-02-08 02:06:39 +00:00
|
|
|
|
return setCursor(cur, cur.pit(), cur.pos(), true, false);
|
2003-11-17 14:28:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (cur.pos() != cur.lastpos()) {
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool updateNeeded = false;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
if (!checkAndActivateInset(cur, true)) {
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updateNeeded |= setCursor(cur, cur.pit(), 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()))
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updateNeeded |= setCursor(cur, cur.pit(), cur.pos(), true, true);
|
2004-02-20 17:19:53 +00:00
|
|
|
|
}
|
2005-02-08 02:06:39 +00:00
|
|
|
|
return updateNeeded;
|
2003-11-17 14:28:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (cur.pit() != cur.lastpit())
|
2005-02-08 02:06:39 +00:00
|
|
|
|
return setCursor(cur, cur.pit() + 1, 0);
|
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool LyXText::cursorUp(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Paragraph const & par = cur.paragraph();
|
|
|
|
|
int const row = par.pos2row(cur.pos());
|
|
|
|
|
int const x = cur.targetX();
|
2003-11-22 14:44:59 +00:00
|
|
|
|
|
2004-02-20 17:19:53 +00:00
|
|
|
|
if (!cur.selection()) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int const y = bv_funcs::getPos(cur).y_;
|
2005-02-08 02:06:39 +00:00
|
|
|
|
LCursor old = cur;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
editXY(cur, x, y - par.rows()[row].ascent() - 1);
|
2005-02-08 02:06:39 +00:00
|
|
|
|
|
|
|
|
|
// This happens when you move out of an inset.
|
|
|
|
|
// And to give the DEPM the possibility of doing
|
|
|
|
|
// something we must provide it with two different
|
|
|
|
|
// cursors. (Lgb)
|
|
|
|
|
LCursor dummy = cur;
|
|
|
|
|
if (dummy == old)
|
|
|
|
|
++dummy.pos();
|
|
|
|
|
|
|
|
|
|
return deleteEmptyParagraphMechanism(dummy, old);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool updateNeeded = false;
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (row > 0) {
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updateNeeded |= setCursor(cur, cur.pit(),
|
|
|
|
|
x2pos(cur.pit(), row - 1, x));
|
2004-11-30 01:59:49 +00:00
|
|
|
|
} else if (cur.pit() > 0) {
|
|
|
|
|
--cur.pit();
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updateNeeded |= setCursor(cur, cur.pit(),
|
|
|
|
|
x2pos(cur.pit(), par.rows().size() - 1, x));
|
2002-04-16 14:10:39 +00:00
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
cur.x_target() = x;
|
2005-02-08 02:06:39 +00:00
|
|
|
|
|
|
|
|
|
return updateNeeded;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool LyXText::cursorDown(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
Paragraph const & par = cur.paragraph();
|
|
|
|
|
int const row = par.pos2row(cur.pos());
|
|
|
|
|
int const x = cur.targetX();
|
2003-11-21 08:35:15 +00:00
|
|
|
|
|
2004-02-20 17:19:53 +00:00
|
|
|
|
if (!cur.selection()) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
int const y = bv_funcs::getPos(cur).y_;
|
2005-02-08 02:06:39 +00:00
|
|
|
|
LCursor old = cur;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
editXY(cur, x, y + par.rows()[row].descent() + 1);
|
2005-02-08 02:06:39 +00:00
|
|
|
|
|
|
|
|
|
// This happens when you move out of an inset.
|
|
|
|
|
// And to give the DEPM the possibility of doing
|
|
|
|
|
// something we must provide it with two different
|
|
|
|
|
// cursors. (Lgb)
|
|
|
|
|
LCursor dummy = cur;
|
|
|
|
|
if (dummy == old)
|
|
|
|
|
++dummy.pos();
|
|
|
|
|
|
|
|
|
|
bool const changed = deleteEmptyParagraphMechanism(dummy, old);
|
|
|
|
|
|
|
|
|
|
// Make sure that cur gets back whatever happened to dummy(Lgb)
|
|
|
|
|
if (changed)
|
|
|
|
|
cur = dummy;
|
|
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool updateNeeded = false;
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (row + 1 < int(par.rows().size())) {
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updateNeeded |= setCursor(cur, cur.pit(),
|
|
|
|
|
x2pos(cur.pit(), row + 1, x));
|
2004-11-30 01:59:49 +00:00
|
|
|
|
} else if (cur.pit() + 1 < int(paragraphs().size())) {
|
|
|
|
|
++cur.pit();
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updateNeeded |= setCursor(cur, cur.pit(),
|
|
|
|
|
x2pos(cur.pit(), 0, x));
|
2002-04-16 14:10:39 +00:00
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
cur.x_target() = x;
|
2005-02-08 02:06:39 +00:00
|
|
|
|
|
|
|
|
|
return updateNeeded;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool LyXText::cursorUpParagraph(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool updated = false;
|
2004-02-12 16:36:01 +00:00
|
|
|
|
if (cur.pos() > 0)
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updated = setCursor(cur, cur.pit(), 0);
|
2004-11-24 21:53:46 +00:00
|
|
|
|
else if (cur.pit() != 0)
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updated = setCursor(cur, cur.pit() - 1, 0);
|
|
|
|
|
return updated;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool LyXText::cursorDownParagraph(LCursor & cur)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2005-02-08 02:06:39 +00:00
|
|
|
|
bool updated = false;
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (cur.pit() != cur.lastpit())
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updated = setCursor(cur, cur.pit() + 1, 0);
|
2003-08-01 14:12:04 +00:00
|
|
|
|
else
|
2005-02-08 02:06:39 +00:00
|
|
|
|
updated = setCursor(cur, cur.pit(), cur.lastpos());
|
|
|
|
|
return updated;
|
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
|
|
|
|
{
|
2005-02-08 02:06:39 +00:00
|
|
|
|
// Do nothing if cursor is not in the paragraph where the
|
2004-02-13 13:51:12 +00:00
|
|
|
|
// deletion occured,
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (cur.pit() != where.pit())
|
2001-09-27 09:52:06 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2005-02-08 02:06:39 +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
|
|
|
|
|
2005-02-08 02:06:39 +00:00
|
|
|
|
// Check also if we don't want to set the cursor on a spot behind the
|
2002-05-02 12:45:27 +00:00
|
|
|
|
// 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
|
|
|
|
{
|
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-11-24 21:53:46 +00:00
|
|
|
|
Paragraph const & oldpar = pars_[old.pit()];
|
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.
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (old.pit() != cur.pit() || 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)) {
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pars_[old.pit()].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());
|
2005-02-08 02:06:39 +00:00
|
|
|
|
return true;
|
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
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (old.pit() == cur.pit())
|
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
|
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-11-24 21:53:46 +00:00
|
|
|
|
cur.anchor().pit() == old.pit() && 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...
|
2004-11-24 21:53:46 +00:00
|
|
|
|
recUndo(old.pit(), cur.pit());
|
2001-07-07 18:19:18 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// Delete old par.
|
2004-11-24 21:53:46 +00:00
|
|
|
|
pars_.erase(pars_.begin() + old.pit());
|
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?
|
2004-11-24 21:53:46 +00:00
|
|
|
|
if (cur.pit() > old.pit())
|
|
|
|
|
--cur.pit();
|
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-11-24 21:53:46 +00:00
|
|
|
|
// if (cur.anchor().pit() > old.pit())
|
|
|
|
|
// --cur.anchor().pit();
|
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-11-24 21:53:46 +00:00
|
|
|
|
if (pars_[old.pit()].stripLeadingSpaces())
|
2004-03-25 09:16:36 +00:00
|
|
|
|
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-11-24 21:53:46 +00:00
|
|
|
|
void LyXText::recUndo(pit_type first, pit_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-11-24 21:53:46 +00:00
|
|
|
|
void LyXText::recUndo(pit_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
|
|
|
|
}
|