1999-09-27 18:44:28 +00:00
|
|
|
/*
|
2000-04-19 14:42:19 +00:00
|
|
|
* File: formula.C
|
1999-09-27 18:44:28 +00:00
|
|
|
* Purpose: Implementation of formula inset
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: January 1996
|
|
|
|
* Description: Allows the edition of math paragraphs inside Lyx.
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright: 1996-1998 Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* Version: 0.4, Lyx project.
|
|
|
|
*
|
|
|
|
* You are free to use and modify this code under the terms of
|
|
|
|
* the GNU General Public Licence version 2 or later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
#include "Lsstream.h"
|
2000-03-28 02:18:55 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "formula.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "formula.h"
|
|
|
|
#include "commandtags.h"
|
|
|
|
#include "math_cursor.h"
|
|
|
|
#include "math_parser.h"
|
|
|
|
#include "lyx_main.h"
|
|
|
|
#include "minibuffer.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "lyxtext.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "LaTeXFeatures.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyx_gui_misc.h"
|
1999-12-07 00:44:53 +00:00
|
|
|
#include "support/LOstream.h"
|
1999-12-19 22:35:36 +00:00
|
|
|
#include "LyXView.h"
|
2000-02-10 17:53:36 +00:00
|
|
|
#include "Painter.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
#include "font.h"
|
2000-10-02 00:55:02 +00:00
|
|
|
#include "support/lyxlib.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
|
|
|
using std::istream;
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::pair;
|
|
|
|
using std::endl;
|
2000-05-19 16:46:01 +00:00
|
|
|
using std::vector;
|
2000-09-25 11:10:15 +00:00
|
|
|
using std::max;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
//extern char * mathed_label;
|
|
|
|
extern string mathed_label;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
extern char const * latex_special_chars;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-07-20 10:04:27 +00:00
|
|
|
int greek_kb_flag = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
LyXFont * Math_Fonts = 0; // this is only used by Whichfont and mathed_init_fonts (Lgb)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
static LyXFont::FONT_SIZE lfont_size = LyXFont::SIZE_NORMAL;
|
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
// local global
|
|
|
|
static int sel_x;
|
|
|
|
static int sel_y;
|
1999-09-27 18:44:28 +00:00
|
|
|
static bool sel_flag;
|
2000-09-29 18:44:07 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
MathedCursor * InsetFormula::mathcursor = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
int MathedInset::df_asc;
|
|
|
|
int MathedInset::df_des;
|
|
|
|
int MathedInset::df_width;
|
|
|
|
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
static
|
|
|
|
void mathedValidate(LaTeXFeatures & features, MathParInset * par);
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
LyXFont WhichFont(short type, int size)
|
|
|
|
{
|
|
|
|
LyXFont f;
|
|
|
|
|
|
|
|
if (!Math_Fonts)
|
|
|
|
mathed_init_fonts();
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case LM_TC_SYMB:
|
|
|
|
f = Math_Fonts[2];
|
|
|
|
break;
|
|
|
|
case LM_TC_BSYM:
|
|
|
|
f = Math_Fonts[2];
|
|
|
|
break;
|
|
|
|
case LM_TC_VAR:
|
|
|
|
case LM_TC_IT:
|
|
|
|
f = Math_Fonts[0];
|
|
|
|
break;
|
|
|
|
case LM_TC_BF:
|
|
|
|
f = Math_Fonts[3];
|
|
|
|
break;
|
|
|
|
case LM_TC_SF:
|
|
|
|
f = Math_Fonts[7];
|
|
|
|
break;
|
|
|
|
case LM_TC_CAL:
|
|
|
|
f = Math_Fonts[4];
|
|
|
|
break;
|
|
|
|
case LM_TC_TT:
|
|
|
|
f = Math_Fonts[5];
|
|
|
|
break;
|
|
|
|
case LM_TC_SPECIAL: //f = Math_Fonts[0]; break;
|
|
|
|
case LM_TC_TEXTRM:
|
|
|
|
case LM_TC_RM:
|
|
|
|
f = Math_Fonts[6];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
f = Math_Fonts[1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
f.setSize(lfont_size);
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case LM_ST_DISPLAY:
|
1999-11-15 11:06:41 +00:00
|
|
|
if (type == LM_TC_BSYM) {
|
1999-09-27 18:44:28 +00:00
|
|
|
f.incSize();
|
|
|
|
f.incSize();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LM_ST_TEXT:
|
|
|
|
break;
|
|
|
|
case LM_ST_SCRIPT:
|
|
|
|
f.decSize();
|
|
|
|
break;
|
|
|
|
case LM_ST_SCRIPTSCRIPT:
|
|
|
|
f.decSize();
|
|
|
|
f.decSize();
|
|
|
|
break;
|
|
|
|
default:
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Mathed Error: wrong font size: " << size << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-02-10 17:53:36 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
if (type != LM_TC_TEXTRM)
|
2000-02-10 17:53:36 +00:00
|
|
|
f.setColor(LColor::math);
|
1999-09-27 18:44:28 +00:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mathed_init_fonts() //removed 'static' because DEC cxx does not
|
1999-11-24 22:14:46 +00:00
|
|
|
//like it (JMarc)
|
|
|
|
// Probably because this func is declared as a friend in math_defs.h
|
|
|
|
// Lgb
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
Math_Fonts = new LyXFont[8]; //DEC cxx cannot initialize all fonts
|
|
|
|
//at once (JMarc) rc
|
2000-03-02 02:19:43 +00:00
|
|
|
for (int i = 0 ; i < 8 ; ++i) {
|
2000-02-17 19:59:08 +00:00
|
|
|
Math_Fonts[i] = LyXFont(LyXFont::ALL_SANE);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
Math_Fonts[0].setShape(LyXFont::ITALIC_SHAPE);
|
|
|
|
|
|
|
|
Math_Fonts[1].setFamily(LyXFont::SYMBOL_FAMILY);
|
|
|
|
|
|
|
|
Math_Fonts[2].setFamily(LyXFont::SYMBOL_FAMILY);
|
|
|
|
Math_Fonts[2].setShape(LyXFont::ITALIC_SHAPE);
|
|
|
|
|
|
|
|
Math_Fonts[3].setSeries(LyXFont::BOLD_SERIES);
|
|
|
|
|
|
|
|
Math_Fonts[4].setFamily(LyXFont::SANS_FAMILY);
|
|
|
|
Math_Fonts[4].setShape(LyXFont::ITALIC_SHAPE);
|
|
|
|
|
|
|
|
Math_Fonts[5].setFamily(LyXFont::TYPEWRITER_FAMILY);
|
|
|
|
|
|
|
|
Math_Fonts[6].setFamily(LyXFont::ROMAN_FAMILY);
|
|
|
|
|
|
|
|
Math_Fonts[7].setFamily(LyXFont::SANS_FAMILY);
|
|
|
|
|
|
|
|
LyXFont f = WhichFont(LM_TC_VAR, LM_ST_TEXT);
|
2000-04-04 00:19:15 +00:00
|
|
|
MathedInset::df_asc = lyxfont::maxAscent(f);
|
|
|
|
MathedInset::df_des = lyxfont::maxDescent(f);
|
|
|
|
MathedInset::df_width = lyxfont::width('I', f);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-02-17 19:59:08 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
LyXFont mathed_get_font(short type, int size)
|
|
|
|
{
|
|
|
|
LyXFont f = WhichFont(type, size);
|
|
|
|
if (type == LM_TC_TEX) {
|
|
|
|
f.setLatex(LyXFont::ON);
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
int mathed_string_width(short type, int size, byte const * s, int ls)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
LyXFont f = WhichFont(type, size);
|
|
|
|
|
|
|
|
byte sx[80];
|
|
|
|
if (MathIsBinary(type)) {
|
1999-11-24 22:14:46 +00:00
|
|
|
byte * ps = &sx[0];
|
|
|
|
for (int i = 0; i < ls && i < 75; ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
*(ps++) = ' ';
|
|
|
|
*(ps++) = s[i];
|
|
|
|
*(ps++) = ' ';
|
|
|
|
}
|
|
|
|
*(ps++) = '\0';
|
1999-11-24 22:14:46 +00:00
|
|
|
ls *= 3;
|
1999-09-27 18:44:28 +00:00
|
|
|
s = &sx[0];
|
|
|
|
}
|
2000-04-04 00:19:15 +00:00
|
|
|
return lyxfont::width(reinterpret_cast<char const *>(s), ls, f);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
int mathed_string_width(short type, int size, string const & str)
|
|
|
|
{
|
|
|
|
return mathed_string_width(type, size, reinterpret_cast<unsigned char const *>(str.c_str()), str.length());
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
int mathed_char_width(short type, int size, byte c)
|
|
|
|
{
|
2000-04-04 00:19:15 +00:00
|
|
|
int t = (MathIsBinary(type)) ? mathed_string_width(type, size, &c, 1) :
|
|
|
|
lyxfont::width(c, WhichFont(type, size));
|
1999-09-27 18:44:28 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
|
|
|
int mathed_string_height(short type, int size, byte const * s,
|
|
|
|
int ls, int & asc, int & des)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
LyXFont font = WhichFont(type, size);
|
|
|
|
asc = des = 0;
|
1999-11-24 22:14:46 +00:00
|
|
|
for (int i = 0; i < ls; ++i) {
|
2000-09-25 11:10:15 +00:00
|
|
|
des = max(des, lyxfont::descent(s[i], font));
|
|
|
|
asc = max(asc, lyxfont::ascent(s[i], font));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-24 22:14:46 +00:00
|
|
|
return asc + des;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
int mathed_string_height(short type, int size, string const & str,
|
|
|
|
int & asc, int & des)
|
|
|
|
{
|
|
|
|
return mathed_string_height(type, size,
|
|
|
|
reinterpret_cast<unsigned char const *>(str.c_str()), str.length(),
|
|
|
|
asc, des);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
int mathed_char_height(short type, int size, byte c, int & asc, int & des)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
LyXFont font = WhichFont(type, size);
|
2000-04-04 00:19:15 +00:00
|
|
|
des = lyxfont::descent(c, font);
|
|
|
|
asc = lyxfont::ascent(c, font);
|
1999-11-24 22:14:46 +00:00
|
|
|
return asc + des;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// In a near future maybe we use a better fonts renderer
|
2000-05-05 08:44:11 +00:00
|
|
|
void MathedInset::drawStr(Painter & pain, short type, int siz,
|
2000-03-09 16:13:43 +00:00
|
|
|
int x, int y, byte const * s, int ls)
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
|
|
|
string st;
|
|
|
|
if (MathIsBinary(type)) {
|
|
|
|
for (int i = 0; i < ls; ++i) {
|
|
|
|
st += string(" ") + char(s[i]) + ' ';
|
|
|
|
}
|
|
|
|
} else {
|
2000-03-09 16:13:43 +00:00
|
|
|
st = string(reinterpret_cast<char const *>(s), ls);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
2000-09-14 17:53:12 +00:00
|
|
|
LyXFont const mf = mathed_get_font(type, siz);
|
2000-02-10 17:53:36 +00:00
|
|
|
pain.text(x, y, st, mf);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
InsetFormula::InsetFormula(bool display)
|
|
|
|
{
|
|
|
|
par = new MathParInset; // this leaks
|
1999-10-02 16:21:10 +00:00
|
|
|
// mathcursor = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
disp_flag = display;
|
1999-10-02 16:21:10 +00:00
|
|
|
//label = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (disp_flag) {
|
|
|
|
par->SetType(LM_OT_PAR);
|
|
|
|
par->SetStyle(LM_ST_DISPLAY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
|
|
|
InsetFormula::InsetFormula(MathParInset * p)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
par = (p->GetType()>= LM_OT_MPAR) ?
|
1999-12-13 00:05:34 +00:00
|
|
|
new MathMatrixInset(static_cast<MathMatrixInset*>(p)):
|
1999-09-27 18:44:28 +00:00
|
|
|
new MathParInset(p);
|
1999-10-02 16:21:10 +00:00
|
|
|
// mathcursor = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
disp_flag = (par->GetType()>0);
|
1999-10-02 16:21:10 +00:00
|
|
|
//label = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
InsetFormula::~InsetFormula()
|
|
|
|
{
|
|
|
|
delete par;
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-10-10 11:50:43 +00:00
|
|
|
Inset * InsetFormula::Clone(Buffer const &) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
InsetFormula * f = new InsetFormula(par);
|
1999-09-27 18:44:28 +00:00
|
|
|
f->label = label;
|
1999-11-22 16:19:48 +00:00
|
|
|
return f;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetFormula::Write(Buffer const * buf, ostream & os) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
os << "Formula ";
|
2000-06-12 11:27:15 +00:00
|
|
|
Latex(buf, os, false, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetFormula::Latex(Buffer const *, ostream & os, bool fragile, bool) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
//#warning Alejandro, the number of lines is not returned in this case
|
|
|
|
// This problem will disapear at 0.13.
|
2000-09-26 13:54:57 +00:00
|
|
|
mathed_write(par, os, &ret, fragile, label);
|
1999-09-27 18:44:28 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-26 15:25:14 +00:00
|
|
|
int InsetFormula::Ascii(Buffer const *, ostream & os, int) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
|
|
|
par->Write(os, false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetFormula::Linuxdoc(Buffer const * buf, ostream & os) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
2000-09-26 15:25:14 +00:00
|
|
|
return Ascii(buf, os, 0);
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetFormula::DocBook(Buffer const * buf, ostream & os) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
2000-09-26 15:25:14 +00:00
|
|
|
return Ascii(buf, os, 0);
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Check if uses AMS macros
|
1999-11-24 22:14:46 +00:00
|
|
|
void InsetFormula::Validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// Validation only necesary if not using an AMS Style
|
|
|
|
if (!features.amsstyle)
|
|
|
|
mathedValidate(features, par);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetFormula::Read(Buffer const *, LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-01-06 02:44:26 +00:00
|
|
|
istream & is = lex.getStream();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
mathed_parser_file(is, lex.GetLineNo());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
// Silly hack to read labels.
|
2000-09-26 13:54:57 +00:00
|
|
|
//mathed_label = 0;
|
|
|
|
mathed_label.erase();
|
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
mathed_parse(0, 0, &par);
|
|
|
|
par->Metrics();
|
|
|
|
disp_flag = (par->GetType() > 0);
|
|
|
|
|
|
|
|
// Update line number
|
|
|
|
lex.setLineNo(mathed_parser_lineno());
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
//if (mathed_label) {
|
|
|
|
if (!mathed_label.empty()) {
|
2000-01-06 02:44:26 +00:00
|
|
|
label = mathed_label;
|
2000-09-26 13:54:57 +00:00
|
|
|
//mathed_label = 0;
|
|
|
|
mathed_label.erase();
|
2000-01-06 02:44:26 +00:00
|
|
|
}
|
2000-07-17 18:27:53 +00:00
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
// reading of end_inset in the inset!!!
|
|
|
|
while (lex.IsOK()) {
|
|
|
|
lex.nextToken();
|
|
|
|
if (lex.GetString() == "\\end_inset")
|
|
|
|
break;
|
2000-07-17 18:27:53 +00:00
|
|
|
lyxerr << "InsetFormula::Read: Garbage before \\end_inset,"
|
|
|
|
" or missing \\end_inset!" << endl;
|
2000-05-15 14:49:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2000-01-06 02:44:26 +00:00
|
|
|
Write(lyxerr);
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetFormula::ascent(BufferView *, LyXFont const &) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
|
|
|
return par->Ascent() + ((disp_flag) ? 8 : 1);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetFormula::descent(BufferView *, LyXFont const &) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
|
|
|
return par->Descent() + ((disp_flag) ? 8 : 1);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetFormula::width(BufferView *, LyXFont const & f) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
|
|
|
lfont_size = f.size();
|
|
|
|
par->Metrics();
|
|
|
|
return par->Width(); //+2;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-06-22 09:30:43 +00:00
|
|
|
void InsetFormula::draw(BufferView * bv, LyXFont const & f,
|
2000-06-23 15:02:46 +00:00
|
|
|
int baseline, float & x, bool) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2000-06-22 09:30:43 +00:00
|
|
|
Painter & pain = bv->painter();
|
2000-03-06 02:42:40 +00:00
|
|
|
// Seems commenting out solves a problem.
|
2000-02-10 17:53:36 +00:00
|
|
|
LyXFont font = mathed_get_font(LM_TC_TEXTRM, LM_ST_TEXT);
|
2000-03-06 02:42:40 +00:00
|
|
|
font.setSize(f.size());
|
2000-02-10 17:53:36 +00:00
|
|
|
lfont_size = font.size();
|
|
|
|
/// Let's try to wait a bit with this... (Lgb)
|
|
|
|
//UpdatableInset::draw(pain, font, baseline, x);
|
|
|
|
|
|
|
|
// otherwise a segfault could occur
|
|
|
|
// in some XDrawRectangles (i.e. matrix) (Matthias)
|
|
|
|
if (mathcursor && mathcursor->GetPar() == par) {
|
|
|
|
if (mathcursor->Selection()) {
|
|
|
|
int n;
|
|
|
|
int * xp = 0;
|
|
|
|
int * yp = 0;
|
2000-02-17 15:24:43 +00:00
|
|
|
mathcursor->SelGetArea(&xp, &yp, n);
|
2000-02-10 17:53:36 +00:00
|
|
|
pain.fillPolygon(xp, yp, n, LColor::selection);
|
|
|
|
}
|
|
|
|
mathcursor->draw(pain, int(x), baseline);
|
|
|
|
} else {
|
|
|
|
par->draw(pain, int(x), baseline);
|
|
|
|
}
|
2000-07-05 14:57:48 +00:00
|
|
|
x += float(width(bv, font));
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
if (par->GetType() == LM_OT_PARN || par->GetType() == LM_OT_MPARN) {
|
2000-05-19 19:46:23 +00:00
|
|
|
LyXFont wfont = WhichFont(LM_TC_BF, par->size);
|
|
|
|
wfont.setLatex(LyXFont::OFF);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
if (par->GetType() == LM_OT_PARN) {
|
|
|
|
string str;
|
|
|
|
if (!label.empty())
|
|
|
|
str = string("(") + label + ")";
|
|
|
|
else
|
|
|
|
str = string("(#)");
|
2000-05-19 19:46:23 +00:00
|
|
|
pain.text(int(x + 20), baseline, str, wfont);
|
2000-02-10 17:53:36 +00:00
|
|
|
} else if (par->GetType() == LM_OT_MPARN) {
|
|
|
|
MathMatrixInset * mt =
|
|
|
|
static_cast<MathMatrixInset*>(par);
|
|
|
|
int y;
|
|
|
|
MathedRowSt const * crow = mt->getRowSt();
|
|
|
|
while (crow) {
|
|
|
|
y = baseline + crow->getBaseline();
|
|
|
|
if (crow->isNumbered()) {
|
|
|
|
string str;
|
2000-09-14 17:53:12 +00:00
|
|
|
if (!crow->getLabel().empty())
|
2000-02-10 17:53:36 +00:00
|
|
|
str = string("(") + crow->getLabel() + ")";
|
|
|
|
else
|
|
|
|
str = "(#)";
|
2000-05-19 19:46:23 +00:00
|
|
|
pain.text(int(x + 20), y, str, wfont);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
crow = crow->getNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cursor_visible = false;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const InsetFormula::EditMessage() const
|
2000-04-04 00:19:15 +00:00
|
|
|
{
|
|
|
|
return _("Math editor mode");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
void InsetFormula::Edit(BufferView * bv, int x, int y, unsigned int)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-02-25 12:06:15 +00:00
|
|
|
mathcursor = new MathedCursor(par);
|
2000-04-19 14:42:19 +00:00
|
|
|
if (!bv->lockInset(this))
|
|
|
|
lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
|
2000-02-25 12:06:15 +00:00
|
|
|
par->Metrics();
|
|
|
|
bv->updateInset(this, false);
|
|
|
|
x += par->xo;
|
|
|
|
y += par->yo;
|
|
|
|
mathcursor->SetPos(x, y);
|
1999-09-27 18:44:28 +00:00
|
|
|
sel_x = sel_y = 0;
|
|
|
|
sel_flag = false;
|
|
|
|
}
|
1999-11-24 22:14:46 +00:00
|
|
|
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
void InsetFormula::InsetUnlock(BufferView * bv)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (mathcursor) {
|
|
|
|
if (mathcursor->InMacroMode()) {
|
|
|
|
mathcursor->MacroModeClose();
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
delete mathcursor;
|
|
|
|
}
|
1999-10-02 16:21:10 +00:00
|
|
|
mathcursor = 0;
|
2000-02-23 16:39:03 +00:00
|
|
|
bv->updateInset(this, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Now a symbol can be inserted only if the inset is locked
|
2000-09-14 17:53:12 +00:00
|
|
|
void InsetFormula::InsertSymbol(BufferView * bv, string const & s)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-09-14 17:53:12 +00:00
|
|
|
if (s.empty() || !mathcursor) return;
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Interpret(s);
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
void InsetFormula::GetCursorPos(BufferView *, int & x, int & y) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
mathcursor->GetPos(x, y);
|
|
|
|
x -= par->xo;
|
|
|
|
y -= par->yo;
|
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
void InsetFormula::ToggleInsetCursor(BufferView * bv)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (!mathcursor)
|
|
|
|
return;
|
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->GetPos(x, y);
|
|
|
|
// x -= par->xo;
|
|
|
|
y -= par->yo;
|
|
|
|
LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
|
2000-04-04 00:19:15 +00:00
|
|
|
int asc = lyxfont::maxAscent(font);
|
|
|
|
int desc = lyxfont::maxDescent(font);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (cursor_visible)
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->hideLockedInsetCursor();
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->showLockedInsetCursor(x, y, asc, desc);
|
1999-09-27 18:44:28 +00:00
|
|
|
cursor_visible = !cursor_visible;
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-10-03 13:55:48 +00:00
|
|
|
void InsetFormula::ShowInsetCursor(BufferView * bv, bool)
|
1999-11-24 22:14:46 +00:00
|
|
|
{
|
|
|
|
if (!cursor_visible) {
|
|
|
|
if (mathcursor) {
|
2000-09-29 18:44:07 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->GetPos(x, y);
|
|
|
|
// x -= par->xo;
|
|
|
|
y -= par->yo;
|
|
|
|
LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
|
2000-04-04 00:19:15 +00:00
|
|
|
int asc = lyxfont::maxAscent(font);
|
|
|
|
int desc = lyxfont::maxDescent(font);
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->fitLockedInsetCursor(x, y, asc, desc);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-02-22 00:36:17 +00:00
|
|
|
ToggleInsetCursor(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
void InsetFormula::HideInsetCursor(BufferView * bv)
|
1999-11-24 22:14:46 +00:00
|
|
|
{
|
1999-09-27 18:44:28 +00:00
|
|
|
if (cursor_visible)
|
2000-02-22 00:36:17 +00:00
|
|
|
ToggleInsetCursor(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
void InsetFormula::ToggleInsetSelection(BufferView * bv)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (!mathcursor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// int x, y, w, h;
|
|
|
|
//int n;
|
|
|
|
//XPoint * p =
|
|
|
|
//mathcursor->SelGetArea(n);
|
|
|
|
// XFillPolygon(fl_display, pm, LyXGetSelectionGC(), p, n, Nonconvex, CoordModeOrigin);
|
|
|
|
// x -= par->xo;
|
|
|
|
// y -= par->yo;
|
|
|
|
|
2000-02-23 16:39:03 +00:00
|
|
|
bv->updateInset(this, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
void InsetFormula::display(bool dspf)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-24 22:14:46 +00:00
|
|
|
if (dspf != disp_flag) {
|
1999-09-27 18:44:28 +00:00
|
|
|
if (dspf) {
|
|
|
|
par->SetType(LM_OT_PAR);
|
|
|
|
par->SetStyle(LM_ST_DISPLAY);
|
|
|
|
} else {
|
1999-11-24 22:14:46 +00:00
|
|
|
if (par->GetType() >= LM_OT_MPAR) {
|
1999-11-22 16:19:48 +00:00
|
|
|
MathParInset * p = new MathParInset(par);
|
1999-09-27 18:44:28 +00:00
|
|
|
delete par;
|
|
|
|
par = p;
|
|
|
|
if (mathcursor)
|
|
|
|
mathcursor->SetPar(par);
|
|
|
|
}
|
|
|
|
par->SetType(LM_OT_MIN);
|
|
|
|
par->SetStyle(LM_ST_TEXT);
|
1999-11-24 22:14:46 +00:00
|
|
|
if (!label.empty() && par->GetType() != LM_OT_MPARN) {
|
2000-05-04 10:57:00 +00:00
|
|
|
label.erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
disp_flag = dspf;
|
1999-11-24 22:14:46 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
vector<string> const InsetFormula::getLabelList() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-05-19 16:46:01 +00:00
|
|
|
//#warning This is dirty, I know. Ill clean it at 0.11
|
|
|
|
// Correction, the only way to clean this is with a new kernel: 0.13.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-05-19 16:46:01 +00:00
|
|
|
vector<string> label_list;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
if (par->GetType() == LM_OT_MPARN) {
|
1999-11-24 22:14:46 +00:00
|
|
|
MathMatrixInset * mt = static_cast<MathMatrixInset*>(par);
|
1999-11-04 01:40:20 +00:00
|
|
|
MathedRowSt const * crow = mt->getRowSt();
|
|
|
|
while (crow) {
|
2000-09-14 17:53:12 +00:00
|
|
|
if (!crow->getLabel().empty())
|
2000-05-19 16:46:01 +00:00
|
|
|
label_list.push_back(crow->getLabel());
|
1999-11-04 01:40:20 +00:00
|
|
|
crow = crow->getNext();
|
|
|
|
}
|
2000-05-19 16:46:01 +00:00
|
|
|
} else if (!label.empty())
|
|
|
|
label_list.push_back(label);
|
|
|
|
|
|
|
|
return label_list;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
void InsetFormula::UpdateLocal(BufferView * bv)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
par->Metrics(); // To inform lyx kernel the exact size
|
|
|
|
// (there were problems with arrays).
|
2000-02-23 16:39:03 +00:00
|
|
|
bv->updateInset(this, true);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
void InsetFormula::InsetButtonRelease(BufferView * bv,
|
|
|
|
int x, int y, int /*button*/)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-03-24 13:24:58 +00:00
|
|
|
if (mathcursor) {
|
|
|
|
HideInsetCursor(bv);
|
|
|
|
x += par->xo;
|
|
|
|
y += par->yo;
|
|
|
|
mathcursor->SetPos(x, y);
|
|
|
|
ShowInsetCursor(bv);
|
|
|
|
if (sel_flag) {
|
|
|
|
sel_flag = false;
|
|
|
|
sel_x = sel_y = 0;
|
|
|
|
bv->updateInset(this, false);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
void InsetFormula::InsetButtonPress(BufferView * bv,
|
|
|
|
int x, int y, int /*button*/)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
sel_flag = false;
|
2000-03-24 13:24:58 +00:00
|
|
|
sel_x = x; sel_y = y;
|
|
|
|
if (mathcursor && mathcursor->Selection()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->SelClear();
|
2000-02-23 16:39:03 +00:00
|
|
|
bv->updateInset(this, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
void InsetFormula::InsetMotionNotify(BufferView * bv,
|
|
|
|
int x, int y, int /*button*/)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-24 22:14:46 +00:00
|
|
|
if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
|
1999-09-27 18:44:28 +00:00
|
|
|
sel_flag = true;
|
2000-02-22 00:36:17 +00:00
|
|
|
HideInsetCursor(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->SetPos(sel_x + par->xo, sel_y + par->yo);
|
|
|
|
mathcursor->SelStart();
|
2000-02-22 00:36:17 +00:00
|
|
|
ShowInsetCursor(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->GetPos(sel_x, sel_y);
|
2000-09-29 18:44:07 +00:00
|
|
|
} else if (sel_flag) {
|
2000-02-22 00:36:17 +00:00
|
|
|
HideInsetCursor(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
x += par->xo;
|
|
|
|
y += par->yo;
|
|
|
|
mathcursor->SetPos(x, y);
|
2000-02-22 00:36:17 +00:00
|
|
|
ShowInsetCursor(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->GetPos(x, y);
|
1999-11-15 11:06:41 +00:00
|
|
|
if (sel_x!= x || sel_y!= y)
|
2000-02-23 16:39:03 +00:00
|
|
|
bv->updateInset(this, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
sel_x = x; sel_y = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void InsetFormula::InsetKeyPress(XKeyEvent *)
|
|
|
|
{
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::MATHED] << "Used InsetFormula::InsetKeyPress." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Special Mathed functions
|
|
|
|
bool InsetFormula::SetNumber(bool numbf)
|
|
|
|
{
|
|
|
|
if (disp_flag) {
|
|
|
|
short type = par->GetType();
|
1999-11-15 11:06:41 +00:00
|
|
|
bool oldf = (type == LM_OT_PARN || type == LM_OT_MPARN);
|
1999-11-24 22:14:46 +00:00
|
|
|
if (numbf && !oldf) ++type;
|
|
|
|
if (!numbf && oldf) --type;
|
1999-09-27 18:44:28 +00:00
|
|
|
par->SetType(type);
|
|
|
|
return oldf;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
UpdatableInset::RESULT
|
|
|
|
InsetFormula::LocalDispatch(BufferView * bv,
|
|
|
|
int action, string const & arg)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// extern char *dispatch_result;
|
|
|
|
MathedTextCodes varcode = LM_TC_MIN;
|
2000-02-25 12:06:15 +00:00
|
|
|
bool was_macro = mathcursor->InMacroMode();
|
|
|
|
bool sel = false;
|
|
|
|
bool space_on = false;
|
|
|
|
bool was_selection = mathcursor->Selection();
|
|
|
|
RESULT result = DISPATCHED;
|
|
|
|
static MathSpaceInset * sp= 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
HideInsetCursor(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
if (mathcursor->getLastCode() == LM_TC_TEX) {
|
1999-09-27 18:44:28 +00:00
|
|
|
varcode = LM_TC_TEX;
|
|
|
|
}
|
|
|
|
switch (action) {
|
|
|
|
|
|
|
|
// --- Cursor Movements ---------------------------------------------
|
|
|
|
case LFUN_RIGHTSEL: sel = true;
|
|
|
|
case LFUN_RIGHT:
|
|
|
|
{
|
2000-02-25 12:06:15 +00:00
|
|
|
result = DISPATCH_RESULT(mathcursor->Right(sel));
|
2000-07-04 11:30:07 +00:00
|
|
|
if (!sel && (result == DISPATCHED))
|
|
|
|
result = DISPATCHED_NOUPDATE;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LFUN_LEFTSEL: sel = true;
|
|
|
|
case LFUN_LEFT:
|
|
|
|
{
|
2000-02-25 12:06:15 +00:00
|
|
|
result = DISPATCH_RESULT(mathcursor->Left(sel));
|
2000-07-04 11:30:07 +00:00
|
|
|
if (!sel && (result == DISPATCHED))
|
|
|
|
result = DISPATCHED_NOUPDATE;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LFUN_UPSEL: sel = true;
|
|
|
|
case LFUN_UP:
|
2000-02-25 12:06:15 +00:00
|
|
|
result = DISPATCH_RESULT(mathcursor->Up(sel));
|
2000-07-04 11:30:07 +00:00
|
|
|
if (!sel && (result == DISPATCHED))
|
|
|
|
result = DISPATCHED_NOUPDATE;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_DOWNSEL: sel = true;
|
|
|
|
case LFUN_DOWN:
|
2000-02-25 12:06:15 +00:00
|
|
|
result = DISPATCH_RESULT(mathcursor->Down(sel));
|
2000-07-04 11:30:07 +00:00
|
|
|
if (!sel && (result == DISPATCHED))
|
|
|
|
result = DISPATCHED_NOUPDATE;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LFUN_HOME:
|
|
|
|
mathcursor->Home();
|
2000-07-04 11:30:07 +00:00
|
|
|
result = DISPATCHED_NOUPDATE;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LFUN_END:
|
|
|
|
mathcursor->End();
|
2000-07-04 11:30:07 +00:00
|
|
|
result = DISPATCHED_NOUPDATE;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LFUN_DELETE_LINE_FORWARD:
|
2000-01-08 21:02:58 +00:00
|
|
|
//current_view->lockedInsetStoreUndo(Undo::INSERT);
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::DELETE);
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->DelLine();
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LFUN_BREAKLINE:
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Insert(' ', LM_TC_CR);
|
|
|
|
par = mathcursor->GetPar();
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LFUN_TAB:
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Insert(0, LM_TC_TAB);
|
|
|
|
//UpdateInset(this);
|
|
|
|
break;
|
|
|
|
case LFUN_TABINSERT:
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Insert('T', LM_TC_TAB);
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LFUN_BACKSPACE:
|
|
|
|
if (!mathcursor->Left())
|
|
|
|
break;
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
if (!mathcursor->InMacroMode() && mathcursor->pullArg()) {
|
2000-02-23 16:39:03 +00:00
|
|
|
bv->updateInset(this, true);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_DELETE:
|
2000-01-08 21:02:58 +00:00
|
|
|
//current_view->lockedInsetStoreUndo(Undo::INSERT);
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::DELETE);
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Delete();
|
2000-02-23 16:39:03 +00:00
|
|
|
bv->updateInset(this, true);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
// case LFUN_GETXY:
|
|
|
|
// sprintf(dispatch_buffer, "%d %d",);
|
|
|
|
// dispatch_result = dispatch_buffer;
|
|
|
|
// break;
|
|
|
|
case LFUN_SETXY:
|
|
|
|
{
|
2000-09-29 18:44:07 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int x1;
|
|
|
|
int y1;
|
2000-03-08 01:45:25 +00:00
|
|
|
istringstream ist(arg.c_str());
|
|
|
|
ist >> x >> y;
|
1999-09-27 18:44:28 +00:00
|
|
|
par->GetXY(x1, y1);
|
2000-03-08 01:45:25 +00:00
|
|
|
mathcursor->SetPos(x1 + x, y1 + y);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* cursor selection ---------------------------- */
|
|
|
|
|
|
|
|
case LFUN_PASTE:
|
|
|
|
if (was_macro)
|
|
|
|
mathcursor->MacroModeClose();
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
mathcursor->SelPaste(); UpdateLocal(bv); break;
|
1999-09-27 18:44:28 +00:00
|
|
|
case LFUN_CUT:
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::DELETE);
|
|
|
|
mathcursor->SelCut(); UpdateLocal(bv); break;
|
1999-09-27 18:44:28 +00:00
|
|
|
case LFUN_COPY: mathcursor->SelCopy(); break;
|
|
|
|
case LFUN_HOMESEL:
|
|
|
|
case LFUN_ENDSEL:
|
|
|
|
case LFUN_WORDRIGHTSEL:
|
|
|
|
case LFUN_WORDLEFTSEL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// --- accented characters ------------------------------
|
|
|
|
|
|
|
|
case LFUN_UMLAUT: mathcursor->setAccent(LM_ddot); break;
|
|
|
|
case LFUN_CIRCUMFLEX: mathcursor->setAccent(LM_hat); break;
|
|
|
|
case LFUN_GRAVE: mathcursor->setAccent(LM_grave); break;
|
|
|
|
case LFUN_ACUTE: mathcursor->setAccent(LM_acute); break;
|
|
|
|
case LFUN_TILDE: mathcursor->setAccent(LM_tilde); break;
|
|
|
|
case LFUN_MACRON: mathcursor->setAccent(LM_bar); break;
|
|
|
|
case LFUN_DOT: mathcursor->setAccent(LM_dot); break;
|
|
|
|
case LFUN_CARON: mathcursor->setAccent(LM_check); break;
|
|
|
|
case LFUN_BREVE: mathcursor->setAccent(LM_breve); break;
|
|
|
|
case LFUN_VECTOR: mathcursor->setAccent(LM_vec); break;
|
|
|
|
|
|
|
|
// Greek mode
|
|
|
|
case LFUN_GREEK:
|
|
|
|
{
|
|
|
|
if (!greek_kb_flag) {
|
|
|
|
greek_kb_flag = 1;
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->owner()->getMiniBuffer()->Set(_("Math greek mode on"));
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
|
|
|
greek_kb_flag = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Greek keyboard
|
|
|
|
case LFUN_GREEK_TOGGLE:
|
|
|
|
{
|
1999-11-24 22:14:46 +00:00
|
|
|
greek_kb_flag = (greek_kb_flag) ? 0 : 2;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (greek_kb_flag)
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->owner()->getMiniBuffer()->Set(_("Math greek keyboard on"));
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->owner()->getMiniBuffer()->Set(_("Math greek keyboard off"));
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Math fonts
|
|
|
|
case LFUN_BOLD: mathcursor->setLastCode(LM_TC_BF); break;
|
|
|
|
case LFUN_SANS: mathcursor->setLastCode( LM_TC_SF); break;
|
|
|
|
case LFUN_EMPH: mathcursor->setLastCode(LM_TC_CAL); break;
|
|
|
|
case LFUN_ROMAN: mathcursor->setLastCode(LM_TC_RM); break;
|
|
|
|
case LFUN_CODE: mathcursor->setLastCode(LM_TC_TT); break;
|
|
|
|
case LFUN_DEFAULT: mathcursor->setLastCode(LM_TC_VAR ) ; break;
|
|
|
|
case LFUN_TEX:
|
|
|
|
{
|
|
|
|
// varcode = LM_TC_TEX;
|
|
|
|
mathcursor->setLastCode(LM_TC_TEX);
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->owner()->getMiniBuffer()->Set(_("TeX mode"));
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_NUMBER:
|
|
|
|
{
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (disp_flag) {
|
|
|
|
short type = par->GetType();
|
1999-11-15 11:06:41 +00:00
|
|
|
bool oldf = (type == LM_OT_PARN || type == LM_OT_MPARN);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (oldf) {
|
2000-01-24 18:34:46 +00:00
|
|
|
--type;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!label.empty()) {
|
2000-05-04 10:57:00 +00:00
|
|
|
label.erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->owner()->getMiniBuffer()->Set(_("No number"));
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
2000-01-24 18:34:46 +00:00
|
|
|
++type;
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->owner()->getMiniBuffer()->Set(_("Number"));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
par->SetType(type);
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_NONUMBER:
|
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
if (par->GetType() == LM_OT_MPARN) {
|
1999-09-27 18:44:28 +00:00
|
|
|
// MathMatrixInset *mt = (MathMatrixInset*)par;
|
|
|
|
//BUG
|
|
|
|
// mt->SetNumbered(!mt->IsNumbered());
|
|
|
|
|
|
|
|
mathcursor->setNumbered();
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_LIMITS:
|
|
|
|
{
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (mathcursor->Limits())
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_SIZE:
|
2000-02-25 12:06:15 +00:00
|
|
|
if (!arg.empty()) {
|
2000-09-26 13:54:57 +00:00
|
|
|
latexkeys * l = in_word_set (arg);
|
1999-09-27 18:44:28 +00:00
|
|
|
int sz = (l) ? l->id: -1;
|
|
|
|
mathcursor->SetSize(sz);
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_INSERT_MATH:
|
|
|
|
{
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
2000-09-26 13:54:57 +00:00
|
|
|
InsertSymbol(bv, arg);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_INSERT_MATRIX:
|
|
|
|
{
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
1999-09-27 18:44:28 +00:00
|
|
|
int k, m, n;
|
|
|
|
char s[80], arg2[80];
|
|
|
|
// This is just so that too long args won't ooze out of s.
|
2000-02-25 12:06:15 +00:00
|
|
|
strncpy(arg2, arg.c_str(), 80); arg2[79]= '\0';
|
1999-09-27 18:44:28 +00:00
|
|
|
k = sscanf(arg2, "%d %d %s", &m, &n, s);
|
1999-11-24 22:14:46 +00:00
|
|
|
s[79] = '\0';
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
if (k < 1) {
|
1999-09-27 18:44:28 +00:00
|
|
|
m = n = 1;
|
1999-11-15 11:06:41 +00:00
|
|
|
} else if (k == 1) {
|
1999-09-27 18:44:28 +00:00
|
|
|
n = 1;
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
MathMatrixInset * p = new MathMatrixInset(m, n);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (mathcursor && p) {
|
1999-11-24 22:14:46 +00:00
|
|
|
if (k > 2 && int(strlen(s)) > m)
|
1999-09-27 18:44:28 +00:00
|
|
|
p->SetAlign(s[0], &s[1]);
|
|
|
|
mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_DELIM:
|
|
|
|
{
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
1999-09-27 18:44:28 +00:00
|
|
|
char lf[40], rg[40], arg2[40];
|
|
|
|
int ilf = '(', irg = '.';
|
1999-11-24 22:14:46 +00:00
|
|
|
latexkeys * l;
|
1999-10-02 16:21:10 +00:00
|
|
|
string vdelim("(){}[]./|");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
if (arg.empty())
|
|
|
|
break;
|
|
|
|
strncpy(arg2, arg.c_str(), 40); arg2[39]= '\0';
|
1999-09-27 18:44:28 +00:00
|
|
|
int n = sscanf(arg2, "%s %s", lf, rg);
|
1999-11-24 22:14:46 +00:00
|
|
|
lf[39] = '\0'; rg[39] = '\0';
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
if (n > 0) {
|
|
|
|
if (isdigit(lf[0]))
|
2000-09-26 13:54:57 +00:00
|
|
|
ilf = lyx::atoi(lf);
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
|
|
|
if (lf[1]) {
|
|
|
|
l = in_word_set(lf, strlen(lf));
|
1999-11-15 11:06:41 +00:00
|
|
|
// Long words will cause l == 0; so check.
|
1999-09-27 18:44:28 +00:00
|
|
|
if(l) ilf = l->id;
|
|
|
|
} else
|
1999-10-02 16:21:10 +00:00
|
|
|
if (vdelim.find(lf[0]) != string::npos)
|
1999-09-27 18:44:28 +00:00
|
|
|
ilf = lf[0];
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
if (n > 1) {
|
|
|
|
if (isdigit(rg[0]))
|
2000-09-26 13:54:57 +00:00
|
|
|
irg = lyx::atoi(rg);
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
|
|
|
if (rg[1]) {
|
|
|
|
l = in_word_set(rg, strlen(rg));
|
|
|
|
if(l) irg = l->id;
|
|
|
|
} else
|
1999-10-02 16:21:10 +00:00
|
|
|
if (vdelim.find(rg[0]) != string::npos)
|
1999-09-27 18:44:28 +00:00
|
|
|
irg = rg[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
MathDelimInset * p = new MathDelimInset(ilf, irg);
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Insert(p, LM_TC_ACTIVE_INSET);
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_PROTECTEDSPACE:
|
|
|
|
{
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
1999-09-27 18:44:28 +00:00
|
|
|
sp = new MathSpaceInset(1);
|
|
|
|
mathcursor->Insert(sp);
|
|
|
|
space_on = true;
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_INSERT_LABEL:
|
|
|
|
{
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
1999-11-24 22:14:46 +00:00
|
|
|
if (par->GetType() < LM_OT_PAR) break;
|
1999-10-02 16:21:10 +00:00
|
|
|
string lb = arg;
|
1999-12-30 02:35:43 +00:00
|
|
|
if (lb.empty()) {
|
|
|
|
pair<bool, string>
|
2000-05-19 19:46:23 +00:00
|
|
|
res = askForText(_("Enter new label to insert:"));
|
|
|
|
if (res.first) {
|
|
|
|
lb = res.second;
|
1999-12-30 02:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
1999-11-24 22:14:46 +00:00
|
|
|
if (!lb.empty() && lb[0] > ' ') {
|
1999-09-27 18:44:28 +00:00
|
|
|
SetNumber(true);
|
1999-11-15 11:06:41 +00:00
|
|
|
if (par->GetType() == LM_OT_MPARN) {
|
2000-09-26 13:54:57 +00:00
|
|
|
mathcursor->setLabel(lb);
|
1999-09-27 18:44:28 +00:00
|
|
|
// MathMatrixInset *mt = (MathMatrixInset*)par;
|
|
|
|
// mt->SetLabel(lb);
|
|
|
|
} else {
|
|
|
|
//if (label.notEmpty()) delete label;
|
|
|
|
label = lb;
|
|
|
|
}
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else
|
2000-05-04 10:57:00 +00:00
|
|
|
label.erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_DISPLAY:
|
2000-01-08 21:02:58 +00:00
|
|
|
//current_view->lockedInsetStoreUndo(Undo::INSERT);
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
1999-11-22 16:19:48 +00:00
|
|
|
display(!disp_flag);
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Invalid actions under math mode
|
|
|
|
case LFUN_MATH_MODE:
|
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
if (mathcursor->getLastCode()!= LM_TC_TEXTRM) {
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->owner()->getMiniBuffer()->Set(_("math text mode"));
|
1999-09-27 18:44:28 +00:00
|
|
|
varcode = LM_TC_TEXTRM;
|
|
|
|
} else {
|
|
|
|
varcode = LM_TC_VAR;
|
|
|
|
}
|
|
|
|
mathcursor->setLastCode(varcode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LFUN_UNDO:
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->owner()->getMiniBuffer()->Set(_("Invalid action in math mode!"));
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
//------- dummy actions
|
|
|
|
case LFUN_EXEC_COMMAND:
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->owner()->getMiniBuffer()->ExecCommand();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-02-25 12:06:15 +00:00
|
|
|
if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
unsigned char c = arg[0];
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
if (c == ' ' && mathcursor->getAccent() == LM_hat) {
|
1999-09-27 18:44:28 +00:00
|
|
|
c = '^';
|
|
|
|
mathcursor->setAccent(0);
|
|
|
|
}
|
1999-11-15 11:06:41 +00:00
|
|
|
if (c == 0) { // Dead key, do nothing
|
1999-10-07 18:44:17 +00:00
|
|
|
//lyxerr << "deadkey" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (isalpha(c)) {
|
1999-11-15 11:06:41 +00:00
|
|
|
if (mathcursor->getLastCode() == LM_TC_TEX) {
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->MacroModeOpen();
|
|
|
|
mathcursor->clearLastCode();
|
|
|
|
varcode = LM_TC_MIN;
|
|
|
|
} else
|
|
|
|
if (!varcode) {
|
|
|
|
short f = (mathcursor->getLastCode()) ?
|
1999-12-13 00:05:34 +00:00
|
|
|
mathcursor->getLastCode() :
|
|
|
|
static_cast<MathedTextCodes>(mathcursor->GetFCode());
|
|
|
|
varcode = MathIsAlphaFont(f) ?
|
|
|
|
static_cast<MathedTextCodes>(f) :
|
|
|
|
LM_TC_VAR;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
// lyxerr << "Varcode << vardoce;
|
2000-07-20 10:04:27 +00:00
|
|
|
MathedTextCodes char_code = varcode;
|
|
|
|
if (greek_kb_flag) {
|
|
|
|
char greek[26] =
|
|
|
|
{'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 ,
|
|
|
|
'K', 0 , 'M', 'N', 'O', 0 , 0 , 'P', 0 , 'T',
|
|
|
|
'Y', 0, 0, 0, 0 , 'Z' };
|
|
|
|
if ('A' <= c && c <= 'Z' && greek[c - 'A']) {
|
|
|
|
char_code = LM_TC_RM;
|
|
|
|
c = greek[c - 'A'];
|
|
|
|
} else
|
|
|
|
char_code = LM_TC_SYMB;
|
|
|
|
}
|
|
|
|
mathcursor->Insert(c, char_code);
|
|
|
|
if (greek_kb_flag && char_code == LM_TC_RM )
|
|
|
|
mathcursor->setLastCode(LM_TC_VAR);
|
1999-09-27 18:44:28 +00:00
|
|
|
varcode = LM_TC_MIN;
|
|
|
|
if (greek_kb_flag<2) greek_kb_flag = 0;
|
|
|
|
} else
|
1999-11-15 11:06:41 +00:00
|
|
|
if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Insert(c, LM_TC_TEX);
|
1999-11-15 11:06:41 +00:00
|
|
|
if (c == '{') {
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Insert('}', LM_TC_TEX);
|
|
|
|
mathcursor->Left();
|
|
|
|
}
|
|
|
|
mathcursor->clearLastCode();
|
|
|
|
// varcode = LM_TC_MIN;
|
|
|
|
} else
|
1999-11-15 11:06:41 +00:00
|
|
|
if (c == '_' && varcode == LM_TC_TEX) {
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Insert(c, LM_TC_SPECIAL);
|
|
|
|
mathcursor->clearLastCode();
|
|
|
|
// varcode = LM_TC_MIN;
|
|
|
|
} else
|
1999-11-15 11:06:41 +00:00
|
|
|
if (('0'<= c && c<= '9') && (varcode == LM_TC_TEX||was_macro)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->MacroModeOpen();
|
|
|
|
mathcursor->clearLastCode();
|
|
|
|
mathcursor->Insert(c, LM_TC_MIN);
|
|
|
|
}
|
|
|
|
else
|
1999-11-15 11:06:41 +00:00
|
|
|
if (('0'<= c && c<= '9') || strchr(";:!|[]().,?", c))
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Insert(c, LM_TC_CONST);
|
|
|
|
else
|
1999-12-01 10:31:47 +00:00
|
|
|
if (strchr("+/-*<>=", c))
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Insert(c, LM_TC_BOP);
|
|
|
|
else
|
1999-11-15 11:06:41 +00:00
|
|
|
if (strchr(latex_special_chars, c) && c!= '_')
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Insert(c, LM_TC_SPECIAL);
|
|
|
|
else
|
1999-11-15 11:06:41 +00:00
|
|
|
if (c == '_' || c == '^') {
|
1999-09-27 18:44:28 +00:00
|
|
|
char s[2];
|
|
|
|
s[0] = c;
|
|
|
|
s[1] = 0;
|
|
|
|
mathcursor->Interpret (s);
|
|
|
|
} else
|
1999-11-15 11:06:41 +00:00
|
|
|
if (c == ' ') {
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!varcode) {
|
|
|
|
short f = (mathcursor->getLastCode()) ?
|
1999-12-13 00:05:34 +00:00
|
|
|
mathcursor->getLastCode() :
|
|
|
|
static_cast<MathedTextCodes>(mathcursor->GetFCode());
|
|
|
|
varcode = MathIsAlphaFont(f) ?
|
|
|
|
static_cast<MathedTextCodes>(f) :
|
|
|
|
LM_TC_VAR;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-15 11:06:41 +00:00
|
|
|
if (varcode == LM_TC_TEXTRM) {
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Insert(c, LM_TC_TEXTRM);
|
|
|
|
} else
|
|
|
|
if (was_macro)
|
|
|
|
mathcursor->MacroModeClose();
|
|
|
|
else
|
|
|
|
if (sp) {
|
|
|
|
int isp = (sp->GetSpace()<5) ? sp->GetSpace()+1: 0;
|
|
|
|
sp->SetSpace(isp);
|
|
|
|
space_on = true;
|
|
|
|
} else {
|
|
|
|
if (!mathcursor->Pop() && mathcursor->IsEnd())
|
2000-02-25 12:06:15 +00:00
|
|
|
result = FINISHED;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
} else
|
2000-10-04 14:24:42 +00:00
|
|
|
if (c == '\'' || c == '@') {
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->Insert (c, LM_TC_VAR);
|
|
|
|
} else
|
1999-11-15 11:06:41 +00:00
|
|
|
if (c == '\\') {
|
1999-09-27 18:44:28 +00:00
|
|
|
if (was_macro)
|
|
|
|
mathcursor->MacroModeClose();
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->owner()->getMiniBuffer()->Set(_("TeX mode"));
|
1999-09-27 18:44:28 +00:00
|
|
|
mathcursor->setLastCode(LM_TC_TEX);
|
|
|
|
}
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
1999-10-07 18:44:17 +00:00
|
|
|
// lyxerr << "Closed by action " << action << endl;
|
2000-02-25 12:06:15 +00:00
|
|
|
result = FINISHED;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
1999-11-24 22:14:46 +00:00
|
|
|
if (was_macro != mathcursor->InMacroMode()
|
|
|
|
&& action >= 0
|
|
|
|
&& action != LFUN_BACKSPACE)
|
2000-02-22 00:36:17 +00:00
|
|
|
UpdateLocal(bv);
|
1999-10-02 16:21:10 +00:00
|
|
|
if (sp && !space_on) sp = 0;
|
2000-02-17 19:59:08 +00:00
|
|
|
if (mathcursor->Selection() || was_selection)
|
2000-02-22 00:36:17 +00:00
|
|
|
ToggleInsetSelection(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-07-04 11:30:07 +00:00
|
|
|
if ((result == DISPATCHED) || (result == DISPATCHED_NOUPDATE))
|
2000-02-22 00:36:17 +00:00
|
|
|
ShowInsetCursor(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
2000-02-22 00:36:17 +00:00
|
|
|
bv->unlockInset(this);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
void
|
|
|
|
MathFuncInset::draw(Painter & pain, int x, int y)
|
|
|
|
{
|
2000-09-14 17:53:12 +00:00
|
|
|
if (!name.empty() && name[0] > ' ') {
|
2000-02-10 17:53:36 +00:00
|
|
|
LyXFont font = WhichFont(LM_TC_TEXTRM, size);
|
|
|
|
font.setLatex(LyXFont::ON);
|
2000-04-04 00:19:15 +00:00
|
|
|
x += (lyxfont::width('I', font) + 3) / 4;
|
2000-02-10 17:53:36 +00:00
|
|
|
pain.text(x, y, name, font);
|
|
|
|
}
|
|
|
|
}
|
2000-02-17 19:59:08 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
void MathFuncInset::Metrics()
|
|
|
|
{
|
2000-09-14 17:53:12 +00:00
|
|
|
//ln = (name) ? strlen(name): 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
LyXFont font = WhichFont(LM_TC_TEXTRM, size);
|
|
|
|
font.setLatex(LyXFont::ON);
|
2000-09-25 11:10:15 +00:00
|
|
|
if (name.empty()) {
|
|
|
|
width = df_width;
|
|
|
|
descent = df_des;
|
|
|
|
ascent = df_asc;
|
|
|
|
} else {
|
|
|
|
width = lyxfont::width(name, font)
|
|
|
|
+ lyxfont::width('I', font) / 2;
|
|
|
|
mathed_string_height(LM_TC_TEXTRM, size, name, ascent, descent);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
static
|
|
|
|
void mathedValidate(LaTeXFeatures & features, MathParInset * par)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
MathedIter it(par->GetData());
|
|
|
|
|
|
|
|
while (it.OK() && !(features.binom && features.boldsymbol)) {
|
|
|
|
if (it.IsInset()) {
|
|
|
|
if(it.IsActive()) {
|
1999-11-24 22:14:46 +00:00
|
|
|
MathParInset * p = it.GetActiveInset();
|
1999-11-15 11:06:41 +00:00
|
|
|
if (!features.binom && p->GetType() == LM_OT_MACRO &&
|
2000-09-14 17:53:12 +00:00
|
|
|
p->GetName() == "binom") {
|
1999-09-27 18:44:28 +00:00
|
|
|
features.binom = true;
|
|
|
|
} else {
|
1999-11-24 22:14:46 +00:00
|
|
|
for (int i = 0; i <= p->getMaxArgumentIdx(); ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
p->setArgumentIdx(i);
|
|
|
|
mathedValidate(features, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MathedInset* p = it.GetInset();
|
2000-09-14 17:53:12 +00:00
|
|
|
if (!features.boldsymbol &&
|
|
|
|
p->GetName() == "boldsymbol") {
|
1999-09-27 18:44:28 +00:00
|
|
|
features.boldsymbol = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
it.Next();
|
|
|
|
}
|
|
|
|
}
|