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"
|
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"
|
2003-11-03 09:23:23 +00:00
|
|
|
|
#include "PosIterator.h"
|
|
|
|
|
#include "iterators.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-04-07 05:37:58 +00:00
|
|
|
|
#include "mathed/math_cursor.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2003-05-13 14:36:24 +00:00
|
|
|
|
#include "support/tostr.h"
|
2001-08-02 18:46:53 +00:00
|
|
|
|
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "support/std_sstream.h"
|
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
|
|
|
|
|
bool font2string(LyXFont const & font, bool toggle, string & data)
|
|
|
|
|
{
|
|
|
|
|
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'
|
|
|
|
|
<< "toggleall " << tostr(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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-03 01:26:02 +00:00
|
|
|
|
bool changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type, bool test_only)
|
2000-04-12 15:11:29 +00:00
|
|
|
|
{
|
2000-12-22 14:44:29 +00:00
|
|
|
|
if (!bv->available() || !text)
|
2003-08-05 08:07:07 +00:00
|
|
|
|
return false;
|
2003-04-03 01:26:02 +00:00
|
|
|
|
|
|
|
|
|
if (test_only)
|
|
|
|
|
return text->changeDepth(type, true);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-03 01:26:02 +00:00
|
|
|
|
bool const changed = text->changeDepth(type, false);
|
2003-11-10 13:23:14 +00:00
|
|
|
|
bv->update();
|
2003-04-03 01:26:02 +00:00
|
|
|
|
return changed;
|
2000-04-12 15:11:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// Returns the current font and depth as a message.
|
2001-08-02 18:46:53 +00:00
|
|
|
|
string const currentState(BufferView * bv)
|
2000-04-12 15:11:29 +00:00
|
|
|
|
{
|
2002-08-24 22:02:30 +00:00
|
|
|
|
if (!bv->available())
|
2003-02-08 19:18:01 +00:00
|
|
|
|
return string();
|
2002-09-06 15:18:11 +00:00
|
|
|
|
|
2003-04-07 05:37:58 +00:00
|
|
|
|
if (mathcursor)
|
|
|
|
|
return mathcursor->info();
|
|
|
|
|
|
2003-02-20 17:39:48 +00:00
|
|
|
|
ostringstream state;
|
|
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
|
LyXText * text = bv->getLyXText();
|
|
|
|
|
Buffer * buffer = bv->buffer();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
LyXCursor const & c = text->cursor;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
bool const show_change = buffer->params().tracking_changes
|
2003-10-09 10:52:12 +00:00
|
|
|
|
&& text->cursor.pos() != text->cursorPar()->size()
|
|
|
|
|
&& text->cursorPar()->lookupChange(c.pos()) != Change::UNCHANGED;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
|
|
if (show_change) {
|
2003-10-09 10:52:12 +00:00
|
|
|
|
Change change = text->cursorPar()->lookupChangeFull(c.pos());
|
|
|
|
|
Author const & a = bv->buffer()->params().authors().get(change.author);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
state << _("Change: ") << a.name();
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (!a.email().empty())
|
2003-02-08 19:18:01 +00:00
|
|
|
|
state << " (" << a.email() << ")";
|
|
|
|
|
if (change.changetime)
|
|
|
|
|
state << _(" at ") << ctime(&change.changetime);
|
|
|
|
|
state << " : ";
|
|
|
|
|
}
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
// I think we should only show changes from the default
|
|
|
|
|
// font. (Asger)
|
2002-08-24 22:02:30 +00:00
|
|
|
|
LyXFont font = text->real_current_font;
|
2003-10-09 10:52:12 +00:00
|
|
|
|
font.reduce(buffer->params().getLyXTextClass().defaultfont());
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
2003-05-16 14:35:15 +00:00
|
|
|
|
// avoid _(...) re-entrance problem
|
2003-09-09 09:47:59 +00:00
|
|
|
|
string const s = font.stateText(&buffer->params());
|
2003-05-16 14:35:15 +00:00
|
|
|
|
state << bformat(_("Font: %1$s"), s);
|
|
|
|
|
|
|
|
|
|
// state << bformat(_("Font: %1$s"), font.stateText(&buffer->params));
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
|
|
|
|
// The paragraph depth
|
|
|
|
|
int depth = text->getDepth();
|
2003-05-13 09:48:57 +00:00
|
|
|
|
if (depth > 0)
|
|
|
|
|
state << bformat(_(", Depth: %1$s"), tostr(depth));
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
|
|
|
|
// The paragraph spacing, but only if different from
|
|
|
|
|
// buffer spacing.
|
2003-10-09 10:52:12 +00:00
|
|
|
|
if (!text->cursorPar()->params().spacing().isDefault()) {
|
2002-08-24 22:02:30 +00:00
|
|
|
|
Spacing::Space cur_space =
|
2003-10-09 10:52:12 +00:00
|
|
|
|
text->cursorPar()->params().spacing().getSpace();
|
2002-08-24 22:02:30 +00:00
|
|
|
|
state << _(", Spacing: ");
|
|
|
|
|
|
|
|
|
|
switch (cur_space) {
|
|
|
|
|
case Spacing::Single:
|
|
|
|
|
state << _("Single");
|
|
|
|
|
break;
|
|
|
|
|
case Spacing::Onehalf:
|
2003-01-23 16:23:43 +00:00
|
|
|
|
state << _("OneHalf");
|
2002-08-24 22:02:30 +00:00
|
|
|
|
break;
|
|
|
|
|
case Spacing::Double:
|
|
|
|
|
state << _("Double");
|
|
|
|
|
break;
|
|
|
|
|
case Spacing::Other:
|
|
|
|
|
state << _("Other (")
|
2003-10-09 10:52:12 +00:00
|
|
|
|
<< text->cursorPar()->params().spacing().getValue()
|
2002-11-27 10:30:28 +00:00
|
|
|
|
<< ')';
|
2002-08-24 22:02:30 +00:00
|
|
|
|
break;
|
|
|
|
|
case Spacing::Default:
|
|
|
|
|
// should never happen, do nothing
|
|
|
|
|
break;
|
2000-04-12 15:11:29 +00:00
|
|
|
|
}
|
2002-08-24 22:02:30 +00:00
|
|
|
|
}
|
2002-03-27 10:27:59 +00:00
|
|
|
|
#ifdef DEVEL_VERSION
|
2003-10-24 09:45:07 +00:00
|
|
|
|
ParagraphList::iterator pit = text->cursorPar();
|
|
|
|
|
state << _(", Paragraph: ") << pit->id();
|
2003-09-04 13:00:12 +00:00
|
|
|
|
state << _(", Position: ") << text->cursor.pos();
|
2003-10-24 09:45:07 +00:00
|
|
|
|
RowList::iterator rit = pit->getRow(text->cursor.pos());
|
2003-10-22 16:30:57 +00:00
|
|
|
|
state << bformat(_(", Row b:%1$d e:%2$d"), rit->pos(), rit->endpos());
|
2003-09-17 16:44:51 +00:00
|
|
|
|
state << _(", Inset: ");
|
2003-10-24 09:45:07 +00:00
|
|
|
|
InsetOld * inset = pit->inInset();
|
2003-09-17 16:44:51 +00:00
|
|
|
|
if (inset)
|
2003-11-10 09:06:48 +00:00
|
|
|
|
state << inset << " owner: " << inset->owner();
|
2003-10-06 15:43:21 +00:00
|
|
|
|
else
|
2003-09-17 16:44:51 +00:00
|
|
|
|
state << -1;
|
2001-08-05 22:12:27 +00:00
|
|
|
|
#endif
|
2003-09-15 11:00:00 +00:00
|
|
|
|
return state.str();
|
2000-04-12 15:11:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-15 06:51:47 +00:00
|
|
|
|
|
|
|
|
|
// deletes a selection during an insertion
|
2003-10-17 10:31:47 +00:00
|
|
|
|
void replaceSelection(LyXText * text)
|
2003-07-15 06:51:47 +00:00
|
|
|
|
{
|
2003-10-17 10:31:47 +00:00
|
|
|
|
if (text->selection.set()) {
|
|
|
|
|
text->cutSelection(true, false);
|
|
|
|
|
text->bv()->update();
|
2003-07-15 06:51:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-03 09:23:23 +00:00
|
|
|
|
|
|
|
|
|
void put_selection_at(BufferView * bv, PosIterator const & cur,
|
|
|
|
|
int length, bool backwards)
|
|
|
|
|
{
|
2003-11-06 09:51:08 +00:00
|
|
|
|
ParIterator par(cur);
|
2003-11-03 09:23:23 +00:00
|
|
|
|
|
|
|
|
|
bv->getLyXText()->clearSelection();
|
|
|
|
|
|
2003-11-05 11:17:11 +00:00
|
|
|
|
LyXText * text = par.text(bv);
|
2003-11-03 09:23:23 +00:00
|
|
|
|
par.lockPath(bv);
|
|
|
|
|
|
|
|
|
|
text->setCursor(cur.pit(), cur.pos());
|
|
|
|
|
|
|
|
|
|
if (length) {
|
|
|
|
|
text->setSelectionRange(length);
|
|
|
|
|
text->setSelection();
|
|
|
|
|
if (backwards)
|
|
|
|
|
text->cursor = text->selection.start;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bv->fitCursor();
|
|
|
|
|
bv->update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-03 00:36:31 +00:00
|
|
|
|
}; // namespace bv_funcs
|