2003-03-12 22:17:50 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file bufferview_funcs.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 Lars Gullik Bj<EFBFBD>nnes
|
2003-03-12 22:17:50 +00:00
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Angus Leeming
|
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.
|
2003-03-12 22:17:50 +00:00
|
|
|
|
*/
|
2000-07-24 13:53:19 +00:00
|
|
|
|
|
2000-04-12 15:11:29 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "bufferview_funcs.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "author.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2000-04-12 15:11:29 +00:00
|
|
|
|
#include "BufferView.h"
|
2003-11-11 13:17:28 +00:00
|
|
|
|
#include "cursor.h"
|
2004-11-30 01:59:49 +00:00
|
|
|
|
#include "coordcache.h"
|
2001-04-17 15:15:59 +00:00
|
|
|
|
#include "gettext.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "language.h"
|
2003-09-16 10:30:59 +00:00
|
|
|
|
#include "LColor.h"
|
2003-09-06 12:36:58 +00:00
|
|
|
|
#include "lyxlex.h"
|
|
|
|
|
#include "lyxrow.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
|
#include "paragraph.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2004-03-28 22:00:22 +00:00
|
|
|
|
#include "pariterator.h"
|
2000-04-12 15:11:29 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
#include "frontends/Alert.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
|
|
|
|
|
#include "insets/insettext.h"
|
|
|
|
|
|
2003-05-13 14:36:24 +00:00
|
|
|
|
#include "support/tostr.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
|
|
|
|
#include <sstream>
|
2003-02-20 17:39:48 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::bformat;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
|
|
|
|
using std::ostringstream;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
|
2002-11-21 18:33:09 +00:00
|
|
|
|
|
2003-04-03 00:36:31 +00:00
|
|
|
|
namespace bv_funcs {
|
2003-03-12 22:17:50 +00:00
|
|
|
|
|
|
|
|
|
// Set data using font and toggle
|
|
|
|
|
// If successful, returns true
|
2005-01-05 20:21:27 +00:00
|
|
|
|
bool font2string(LyXFont const & font, bool const toggle, string & data)
|
2003-03-12 22:17:50 +00:00
|
|
|
|
{
|
|
|
|
|
string lang = "ignore";
|
|
|
|
|
if (font.language())
|
|
|
|
|
lang = font.language()->lang();
|
|
|
|
|
|
|
|
|
|
ostringstream os;
|
|
|
|
|
os << "family " << font.family() << '\n'
|
|
|
|
|
<< "series " << font.series() << '\n'
|
|
|
|
|
<< "shape " << font.shape() << '\n'
|
|
|
|
|
<< "size " << font.size() << '\n'
|
|
|
|
|
<< "emph " << font.emph() << '\n'
|
|
|
|
|
<< "underbar " << font.underbar() << '\n'
|
|
|
|
|
<< "noun " << font.noun() << '\n'
|
|
|
|
|
<< "number " << font.number() << '\n'
|
|
|
|
|
<< "color " << font.color() << '\n'
|
|
|
|
|
<< "language " << lang << '\n'
|
2005-01-06 15:40:49 +00:00
|
|
|
|
<< "toggleall " << convert<string>(toggle);
|
2003-09-15 11:00:00 +00:00
|
|
|
|
data = os.str();
|
2003-03-12 22:17:50 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set font and toggle using data
|
|
|
|
|
// If successful, returns true
|
|
|
|
|
bool string2font(string const & data, LyXFont & font, bool & toggle)
|
|
|
|
|
{
|
2003-09-15 11:00:00 +00:00
|
|
|
|
istringstream is(data);
|
2003-03-12 22:17:50 +00:00
|
|
|
|
LyXLex lex(0,0);
|
|
|
|
|
lex.setStream(is);
|
|
|
|
|
|
|
|
|
|
int nset = 0;
|
|
|
|
|
while (lex.isOK()) {
|
2003-04-01 09:39:06 +00:00
|
|
|
|
string token;
|
|
|
|
|
if (lex.next())
|
|
|
|
|
token = lex.getString();
|
2003-03-12 22:17:50 +00:00
|
|
|
|
|
2003-04-01 09:39:06 +00:00
|
|
|
|
if (token.empty() || !lex.next())
|
2003-03-12 22:17:50 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (token == "family") {
|
2003-04-01 09:39:06 +00:00
|
|
|
|
int const next = lex.getInteger();
|
2003-04-01 10:07:08 +00:00
|
|
|
|
font.setFamily(LyXFont::FONT_FAMILY(next));
|
2003-03-30 21:42:09 +00:00
|
|
|
|
|
2003-03-12 22:17:50 +00:00
|
|
|
|
} else if (token == "series") {
|
2003-04-01 09:39:06 +00:00
|
|
|
|
int const next = lex.getInteger();
|
2003-04-01 10:07:08 +00:00
|
|
|
|
font.setSeries(LyXFont::FONT_SERIES(next));
|
2003-03-12 22:17:50 +00:00
|
|
|
|
|
|
|
|
|
} else if (token == "shape") {
|
2003-04-01 09:39:06 +00:00
|
|
|
|
int const next = lex.getInteger();
|
2003-04-01 10:07:08 +00:00
|
|
|
|
font.setShape(LyXFont::FONT_SHAPE(next));
|
2003-03-12 22:17:50 +00:00
|
|
|
|
|
|
|
|
|
} else if (token == "size") {
|
2003-04-01 09:39:06 +00:00
|
|
|
|
int const next = lex.getInteger();
|
2003-04-01 10:07:08 +00:00
|
|
|
|
font.setSize(LyXFont::FONT_SIZE(next));
|
2003-04-01 09:39:06 +00:00
|
|
|
|
|
|
|
|
|
} else if (token == "emph" || token == "underbar" ||
|
|
|
|
|
token == "noun" || token == "number") {
|
|
|
|
|
|
|
|
|
|
int const next = lex.getInteger();
|
|
|
|
|
LyXFont::FONT_MISC_STATE const misc =
|
2003-04-01 10:07:08 +00:00
|
|
|
|
LyXFont::FONT_MISC_STATE(next);
|
2003-04-01 09:39:06 +00:00
|
|
|
|
|
|
|
|
|
if (token == "emph")
|
|
|
|
|
font.setEmph(misc);
|
|
|
|
|
else if (token == "underbar")
|
|
|
|
|
font.setUnderbar(misc);
|
|
|
|
|
else if (token == "noun")
|
|
|
|
|
font.setNoun(misc);
|
|
|
|
|
else if (token == "number")
|
|
|
|
|
font.setNumber(misc);
|
2003-03-12 22:17:50 +00:00
|
|
|
|
|
|
|
|
|
} else if (token == "color") {
|
2003-04-01 09:39:06 +00:00
|
|
|
|
int const next = lex.getInteger();
|
2003-04-01 10:07:08 +00:00
|
|
|
|
font.setColor(LColor::color(next));
|
2003-03-12 22:17:50 +00:00
|
|
|
|
|
|
|
|
|
} else if (token == "language") {
|
2003-04-01 09:39:06 +00:00
|
|
|
|
string const next = lex.getString();
|
|
|
|
|
if (next == "ignore")
|
2003-03-12 22:17:50 +00:00
|
|
|
|
font.setLanguage(ignore_language);
|
|
|
|
|
else
|
2003-04-01 09:39:06 +00:00
|
|
|
|
font.setLanguage(languages.getLanguage(next));
|
2003-03-12 22:17:50 +00:00
|
|
|
|
|
|
|
|
|
} else if (token == "toggleall") {
|
2003-04-01 09:39:06 +00:00
|
|
|
|
toggle = lex.getBool();
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// Unrecognised token
|
|
|
|
|
break;
|
2003-03-12 22:17:50 +00:00
|
|
|
|
}
|
2003-04-01 09:39:06 +00:00
|
|
|
|
|
|
|
|
|
++nset;
|
2003-03-12 22:17:50 +00:00
|
|
|
|
}
|
|
|
|
|
return (nset > 0);
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
// the next two should probably go elsewhere
|
|
|
|
|
// this give the position relative to (0, baseline) of outermost
|
|
|
|
|
// paragraph
|
2005-01-06 15:40:49 +00:00
|
|
|
|
Point coordOffset(DocIterator const & dit)
|
2004-11-30 01:59:49 +00:00
|
|
|
|
{
|
|
|
|
|
int x = 0;
|
|
|
|
|
int y = 0;
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// Contribution of nested insets
|
|
|
|
|
for (size_t i = 1; i != dit.size(); ++i) {
|
|
|
|
|
CursorSlice const & sl = dit[i];
|
|
|
|
|
int xx = 0, yy = 0;
|
|
|
|
|
sl.inset().getCursorPos(sl, xx, yy);
|
|
|
|
|
x += xx;
|
|
|
|
|
y += yy;
|
|
|
|
|
//lyxerr << "LCursor::getPos, i: " << i << " x: " << xx << " y: " << y << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add contribution of initial rows of outermost paragraph
|
|
|
|
|
CursorSlice const & sl = dit[0];
|
|
|
|
|
Paragraph const & par = sl.text()->getPar(sl.pit());
|
|
|
|
|
y -= par.rows()[0].ascent();
|
|
|
|
|
for (size_t rit = 0, rend = par.pos2row(sl.pos()); rit != rend; ++rit)
|
|
|
|
|
y += par.rows()[rit].height();
|
|
|
|
|
y += par.rows()[par.pos2row(sl.pos())].ascent();
|
|
|
|
|
x += dit.bottom().text()->cursorX(dit.bottom());
|
|
|
|
|
return Point(x,y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Point getPos(DocIterator const & dit)
|
|
|
|
|
{
|
|
|
|
|
CursorSlice const & bot = dit.bottom();
|
|
|
|
|
CoordCache::InnerParPosCache & cache = theCoords.pars_[bot.text()];
|
|
|
|
|
CoordCache::InnerParPosCache::iterator it = cache.find(bot.pit());
|
|
|
|
|
if (it == cache.end()) {
|
|
|
|
|
//lyxerr << "cursor out of view" << std::endl;
|
|
|
|
|
return Point(-1,-1);
|
|
|
|
|
}
|
|
|
|
|
Point p = coordOffset(dit); // offset from outer paragraph
|
|
|
|
|
p.y_ += it->second.y_;
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this could be used elsewhere as well?
|
|
|
|
|
CurStatus status(BufferView const * bv, DocIterator const & dit)
|
|
|
|
|
{
|
|
|
|
|
CoordCache::InnerParPosCache & cache = theCoords.pars_[dit.bottom().text()];
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (cache.find(dit.bottom().pit()) != cache.end())
|
|
|
|
|
return CUR_INSIDE;
|
|
|
|
|
else if (dit.bottom().pit() < bv->anchor_ref())
|
|
|
|
|
return CUR_ABOVE;
|
|
|
|
|
else
|
|
|
|
|
return CUR_BELOW;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-10 09:45:32 +00:00
|
|
|
|
} // namespace bv_funcs
|