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-03-12 22:17:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
* \author John Levon
|
|
|
|
* \author Angus Leeming
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2003-03-12 22:17:50 +00:00
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
*/
|
2000-07-24 13:53:19 +00:00
|
|
|
|
2000-04-12 15:11:29 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "bufferview_funcs.h"
|
|
|
|
#include "BufferView.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "paragraph.h"
|
2000-04-12 15:11:29 +00:00
|
|
|
#include "lyxfont.h"
|
2003-03-12 22:17:50 +00:00
|
|
|
#include "lyxlex.h"
|
2000-04-12 15:11:29 +00:00
|
|
|
#include "lyxtext.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "lyx_cb.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "language.h"
|
2001-04-17 15:15:59 +00:00
|
|
|
#include "gettext.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2003-02-08 19:18:01 +00:00
|
|
|
#include "author.h"
|
|
|
|
#include "changes.h"
|
2000-04-12 15:11:29 +00:00
|
|
|
|
2003-02-20 17:39:48 +00:00
|
|
|
#include "frontends/LyXView.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
#include "frontends/Alert.h"
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2003-03-12 22:17:50 +00:00
|
|
|
#include "Lsstream.h"
|
2001-08-02 18:46:53 +00:00
|
|
|
|
2003-02-20 17:39:48 +00:00
|
|
|
#include "insets/updatableinset.h"
|
|
|
|
|
2003-03-30 20:25:44 +00:00
|
|
|
#include "support/BoostFormat.h"
|
2002-11-21 18:33:09 +00:00
|
|
|
|
2003-03-12 22:17:50 +00:00
|
|
|
namespace {
|
|
|
|
LyXFont freefont(LyXFont::ALL_IGNORE);
|
|
|
|
bool toggleall(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
data = os.str();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set font and toggle using data
|
|
|
|
// If successful, returns true
|
|
|
|
bool string2font(string const & data, LyXFont & font, bool & toggle)
|
|
|
|
{
|
|
|
|
istringstream is(data);
|
|
|
|
LyXLex lex(0,0);
|
|
|
|
lex.setStream(is);
|
|
|
|
|
|
|
|
int Int = 0;
|
|
|
|
bool Bool = false;
|
|
|
|
string String;
|
2003-03-30 21:42:09 +00:00
|
|
|
|
2003-03-12 22:17:50 +00:00
|
|
|
int nset = 0;
|
|
|
|
while (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
string const token = lex.getString();
|
|
|
|
|
|
|
|
if (token == "family" ||
|
|
|
|
token == "series" ||
|
|
|
|
token == "shape" ||
|
|
|
|
token == "size" ||
|
|
|
|
token == "emph" ||
|
|
|
|
token == "underbar" ||
|
|
|
|
token == "noun" ||
|
|
|
|
token == "number" ||
|
|
|
|
token == "color") {
|
|
|
|
lex.next();
|
|
|
|
Int = lex.getInteger();
|
|
|
|
} else if (token == "language") {
|
|
|
|
lex.next();
|
|
|
|
String = lex.getString();
|
|
|
|
} else if (token == "toggleall") {
|
|
|
|
lex.next();
|
|
|
|
Bool = lex.getBool();
|
|
|
|
} else {
|
|
|
|
// Unrecognised token
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lex.isOK())
|
|
|
|
break;
|
|
|
|
++nset;
|
|
|
|
|
|
|
|
if (token == "family") {
|
|
|
|
font.setFamily(static_cast<LyXFont::FONT_FAMILY>(Int));
|
2003-03-30 21:42:09 +00:00
|
|
|
|
2003-03-12 22:17:50 +00:00
|
|
|
} else if (token == "series") {
|
|
|
|
font.setSeries(static_cast<LyXFont::FONT_SERIES>(Int));
|
|
|
|
|
|
|
|
} else if (token == "shape") {
|
|
|
|
font.setShape(static_cast<LyXFont::FONT_SHAPE>(Int));
|
|
|
|
|
|
|
|
} else if (token == "size") {
|
|
|
|
font.setSize(static_cast<LyXFont::FONT_SIZE>(Int));
|
|
|
|
|
|
|
|
} else if (token == "emph") {
|
|
|
|
font.setEmph(static_cast<LyXFont::FONT_MISC_STATE>(Int));
|
|
|
|
|
|
|
|
} else if (token == "underbar") {
|
|
|
|
font.setUnderbar(static_cast<LyXFont::FONT_MISC_STATE>(Int));
|
|
|
|
|
|
|
|
} else if (token == "noun") {
|
|
|
|
font.setNoun(static_cast<LyXFont::FONT_MISC_STATE>(Int));
|
|
|
|
|
|
|
|
} else if (token == "number") {
|
|
|
|
font.setNumber(static_cast<LyXFont::FONT_MISC_STATE>(Int));
|
|
|
|
|
|
|
|
} else if (token == "color") {
|
|
|
|
font.setColor(static_cast<LColor::color>(Int));
|
|
|
|
|
|
|
|
} else if (token == "language") {
|
|
|
|
if (String == "ignore")
|
|
|
|
font.setLanguage(ignore_language);
|
|
|
|
else
|
|
|
|
font.setLanguage(languages.getLanguage(String));
|
|
|
|
|
|
|
|
} else if (token == "toggleall") {
|
|
|
|
toggle = Bool;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (nset > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const freefont2string()
|
|
|
|
{
|
|
|
|
string data;
|
|
|
|
if (font2string(freefont, toggleall, data))
|
|
|
|
return data;
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void update_and_apply_freefont(BufferView * bv, string const & data)
|
|
|
|
{
|
|
|
|
LyXFont font;
|
|
|
|
bool toggle;
|
|
|
|
if (string2font(data, font, toggle)) {
|
|
|
|
freefont = font;
|
|
|
|
toggleall = toggle;
|
|
|
|
apply_freefont(bv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void apply_freefont(BufferView * bv)
|
|
|
|
{
|
|
|
|
toggleAndShow(bv, freefont, toggleall);
|
|
|
|
bv->owner()->view_state_changed();
|
|
|
|
bv->owner()->message(_("Character set"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
void emph(BufferView * bv)
|
2000-04-12 15:11:29 +00:00
|
|
|
{
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
font.setEmph(LyXFont::TOGGLE);
|
2001-08-02 18:46:53 +00:00
|
|
|
toggleAndShow(bv, font);
|
2000-04-12 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
void bold(BufferView * bv)
|
2000-04-12 15:11:29 +00:00
|
|
|
{
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
font.setSeries(LyXFont::BOLD_SERIES);
|
2001-08-02 18:46:53 +00:00
|
|
|
toggleAndShow(bv, font);
|
2000-04-12 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
void noun(BufferView * bv)
|
2000-04-12 15:11:29 +00:00
|
|
|
{
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
font.setNoun(LyXFont::TOGGLE);
|
2001-08-02 18:46:53 +00:00
|
|
|
toggleAndShow(bv, font);
|
2000-04-12 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
void number(BufferView * bv)
|
2000-10-09 12:30:52 +00:00
|
|
|
{
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
font.setNumber(LyXFont::TOGGLE);
|
2001-08-02 18:46:53 +00:00
|
|
|
toggleAndShow(bv, font);
|
2000-10-09 12:30:52 +00:00
|
|
|
}
|
2000-04-12 15:11:29 +00:00
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
void lang(BufferView * bv, string const & l)
|
2000-04-12 15:11:29 +00:00
|
|
|
{
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
2000-10-10 12:36:36 +00:00
|
|
|
Language const * lang = languages.getLanguage(l);
|
2003-03-29 10:55:48 +00:00
|
|
|
if (!lang)
|
|
|
|
return;
|
|
|
|
|
|
|
|
font.setLanguage(lang);
|
|
|
|
toggleAndShow(bv, font);
|
2000-04-12 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Change environment depth.
|
|
|
|
// if decInc >= 0, increment depth
|
2003-03-12 22:17:50 +00:00
|
|
|
// if decInc < 0, decrement depth
|
2000-12-22 14:44:29 +00:00
|
|
|
void changeDepth(BufferView * bv, LyXText * text, int decInc)
|
2000-04-12 15:11:29 +00:00
|
|
|
{
|
2000-12-22 14:44:29 +00:00
|
|
|
if (!bv->available() || !text)
|
|
|
|
return;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-04-12 15:11:29 +00:00
|
|
|
bv->hideCursor();
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->update(BufferView::SELECT);
|
2000-04-12 15:11:29 +00:00
|
|
|
if (decInc >= 0)
|
2003-03-17 16:25:00 +00:00
|
|
|
text->incDepth();
|
2000-04-12 15:11:29 +00:00
|
|
|
else
|
2003-03-17 16:25:00 +00:00
|
|
|
text->decDepth();
|
2000-12-22 14:44:29 +00:00
|
|
|
if (text->inset_owner)
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->updateInset((Inset *)text->inset_owner);
|
|
|
|
bv->update(BufferView::SELECT);
|
2000-04-12 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
void code(BufferView * bv)
|
2000-04-12 15:11:29 +00:00
|
|
|
{
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
|
2001-08-02 18:46:53 +00:00
|
|
|
toggleAndShow(bv, font);
|
2000-04-12 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
void sans(BufferView * bv)
|
2000-04-12 15:11:29 +00:00
|
|
|
{
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
font.setFamily(LyXFont::SANS_FAMILY);
|
2001-08-02 18:46:53 +00:00
|
|
|
toggleAndShow(bv, font);
|
2000-04-12 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
void roman(BufferView * bv)
|
2000-04-12 15:11:29 +00:00
|
|
|
{
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
font.setFamily(LyXFont::ROMAN_FAMILY);
|
2001-08-02 18:46:53 +00:00
|
|
|
toggleAndShow(bv, font);
|
2000-04-12 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
void styleReset(BufferView * bv)
|
2000-04-12 15:11:29 +00:00
|
|
|
{
|
2001-08-11 18:31:14 +00:00
|
|
|
LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
|
2001-08-02 18:46:53 +00:00
|
|
|
toggleAndShow(bv, font);
|
2000-04-12 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
void underline(BufferView * bv)
|
2000-04-12 15:11:29 +00:00
|
|
|
{
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
|
|
|
font.setUnderbar(LyXFont::TOGGLE);
|
2001-08-02 18:46:53 +00:00
|
|
|
toggleAndShow(bv, font);
|
2000-04-12 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-02 18:46:53 +00:00
|
|
|
void fontSize(BufferView * bv, string const & size)
|
2000-04-12 15:11:29 +00:00
|
|
|
{
|
|
|
|
LyXFont font(LyXFont::ALL_IGNORE);
|
2000-11-28 15:54:29 +00:00
|
|
|
font.setLyXSize(size);
|
2001-08-02 18:46:53 +00:00
|
|
|
toggleAndShow(bv, font);
|
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-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-02-08 19:18:01 +00:00
|
|
|
LyXCursor const & c(text->cursor);
|
|
|
|
|
|
|
|
bool const show_change = buffer->params.tracking_changes
|
|
|
|
&& c.pos() != c.par()->size()
|
|
|
|
&& c.par()->lookupChange(c.pos()) != Change::UNCHANGED;
|
|
|
|
|
|
|
|
if (show_change) {
|
|
|
|
Change change(c.par()->lookupChangeFull(c.pos()));
|
|
|
|
Author const & a(bv->buffer()->authors().get(change.author));
|
|
|
|
state << _("Change: ") << a.name();
|
|
|
|
if (!a.email().empty()) {
|
|
|
|
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;
|
|
|
|
LyXFont const & defaultfont =
|
|
|
|
buffer->params.getLyXTextClass().defaultfont();
|
|
|
|
font.reduce(defaultfont);
|
|
|
|
|
2002-11-24 15:20:31 +00:00
|
|
|
#if USE_BOOST_FORMAT
|
2002-11-21 18:33:09 +00:00
|
|
|
state << boost::format(_("Font: %1$s")) % font.stateText(&buffer->params);
|
2002-11-24 15:20:31 +00:00
|
|
|
#else
|
|
|
|
state << _("Font: ") << font.stateText(&buffer->params);
|
|
|
|
#endif
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
|
|
// The paragraph depth
|
|
|
|
int depth = text->getDepth();
|
2002-11-24 15:20:31 +00:00
|
|
|
if (depth > 0) {
|
|
|
|
#if USE_BOOST_FORMAT
|
2002-11-21 18:33:09 +00:00
|
|
|
state << boost::format(_(", Depth: %1$d")) % depth;
|
2002-11-24 15:20:31 +00:00
|
|
|
#else
|
|
|
|
state << _(", Depth: ") << depth;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
|
|
|
|
// The paragraph spacing, but only if different from
|
|
|
|
// buffer spacing.
|
|
|
|
if (!text->cursor.par()->params().spacing().isDefault()) {
|
|
|
|
Spacing::Space cur_space =
|
|
|
|
text->cursor.par()->params().spacing().getSpace();
|
|
|
|
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 (")
|
|
|
|
<< text->cursor.par()->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
|
2002-08-24 22:02:30 +00:00
|
|
|
state << _(", Paragraph: ") << text->cursor.par()->id();
|
2001-08-05 22:12:27 +00:00
|
|
|
#endif
|
2002-11-04 02:12:42 +00:00
|
|
|
return STRCONV(state.str());
|
2000-04-12 15:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-23 12:08:47 +00:00
|
|
|
/* Does the actual toggle job of the calls above.
|
2000-04-12 15:11:29 +00:00
|
|
|
* Also shows the current font state.
|
|
|
|
*/
|
2001-08-02 18:46:53 +00:00
|
|
|
void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
|
2000-04-12 15:11:29 +00:00
|
|
|
{
|
2002-08-09 00:42:12 +00:00
|
|
|
if (!bv->available())
|
|
|
|
return;
|
2002-09-06 15:18:11 +00:00
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
if (bv->theLockingInset()) {
|
|
|
|
bv->theLockingInset()->setFont(bv, font, toggleall);
|
|
|
|
return;
|
|
|
|
}
|
2002-09-06 15:18:11 +00:00
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
LyXText * text = bv->getLyXText();
|
2002-09-06 15:18:11 +00:00
|
|
|
// FIXME: can this happen ??
|
2002-08-09 00:42:12 +00:00
|
|
|
if (!text)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bv->hideCursor();
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->update(text, BufferView::SELECT);
|
2003-03-17 16:25:00 +00:00
|
|
|
text->toggleFree(font, toggleall);
|
2003-03-19 14:45:22 +00:00
|
|
|
bv->update(text, BufferView::SELECT);
|
2002-08-09 00:42:12 +00:00
|
|
|
|
|
|
|
if (font.language() != ignore_language ||
|
|
|
|
font.number() != LyXFont::IGNORE) {
|
|
|
|
LyXCursor & cursor = text->cursor;
|
2003-03-30 21:42:09 +00:00
|
|
|
text->computeBidiTables(bv->buffer(), *cursor.row());
|
2002-08-09 00:42:12 +00:00
|
|
|
if (cursor.boundary() !=
|
|
|
|
text->isBoundary(bv->buffer(), cursor.par(), cursor.pos(),
|
|
|
|
text->real_current_font))
|
2003-03-17 16:25:00 +00:00
|
|
|
text->setCursor(cursor.par(), cursor.pos(),
|
2002-08-09 00:42:12 +00:00
|
|
|
false, !cursor.boundary());
|
2000-04-12 15:11:29 +00:00
|
|
|
}
|
|
|
|
}
|