1999-09-27 18:44:28 +00:00
|
|
|
/*
|
2001-02-14 19:35:25 +00:00
|
|
|
* File: formula.C
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Copyright: 1996-1998 Alejandro Aguilar Sierra
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
2001-04-25 15:43:57 +00:00
|
|
|
#include <fstream>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
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__
|
2001-02-15 12:22:01 +00:00
|
|
|
#pragma implementation
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "formula.h"
|
|
|
|
#include "commandtags.h"
|
|
|
|
#include "math_cursor.h"
|
|
|
|
#include "math_parser.h"
|
|
|
|
#include "lyx_main.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"
|
2001-04-25 15:43:57 +00:00
|
|
|
#include "support/lyxlib.h"
|
|
|
|
#include "support/syscall.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-12-11 09:46:09 +00:00
|
|
|
#include "lyxrc.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_inset.h"
|
|
|
|
#include "math_parinset.h"
|
|
|
|
#include "math_matrixinset.h"
|
|
|
|
#include "math_rowst.h"
|
|
|
|
#include "math_spaceinset.h"
|
|
|
|
#include "math_deliminset.h"
|
2001-02-13 19:10:18 +00:00
|
|
|
#include "mathed/support.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-04-25 15:43:57 +00:00
|
|
|
using std::ostringstream;
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
2001-04-25 15:43:57 +00:00
|
|
|
using std::ifstream;
|
2000-04-04 00:19:15 +00:00
|
|
|
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 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;
|
2001-02-16 09:25:43 +00:00
|
|
|
extern char const * latex_mathenv[];
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-14 19:35:25 +00:00
|
|
|
// this is only used by Whichfont and mathed_init_fonts (Lgb)
|
|
|
|
LyXFont * Math_Fonts = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
|
|
|
|
MathedCursor * mathcursor = 0;
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
LyXFont::FONT_SIZE lfont_size = LyXFont::SIZE_NORMAL;
|
2000-09-29 18:44:07 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
// local global
|
|
|
|
int sel_x;
|
|
|
|
int sel_y;
|
|
|
|
bool sel_flag;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
int mathed_write(MathParInset *, std::ostream &, bool fragile,
|
|
|
|
string const & label = string());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
void mathed_init_fonts();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
void mathedValidate(LaTeXFeatures & features, MathParInset * par);
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespaces
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
LyXFont WhichFont(short type, int size)
|
|
|
|
{
|
2001-02-13 13:28:32 +00:00
|
|
|
LyXFont f;
|
2001-02-15 12:22:01 +00:00
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
if (!Math_Fonts)
|
|
|
|
mathed_init_fonts();
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
switch (type) {
|
2001-02-15 12:22:01 +00:00
|
|
|
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;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
f.setSize(lfont_size);
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
switch (size) {
|
2001-02-15 12:22:01 +00:00
|
|
|
case LM_ST_DISPLAY:
|
|
|
|
if (type == LM_TC_BSYM) {
|
|
|
|
f.incSize();
|
|
|
|
f.incSize();
|
|
|
|
}
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LM_ST_TEXT:
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LM_ST_SCRIPT:
|
|
|
|
f.decSize();
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LM_ST_SCRIPTSCRIPT:
|
|
|
|
f.decSize();
|
|
|
|
f.decSize();
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
default:
|
|
|
|
lyxerr << "Mathed Error: wrong font size: " << size << endl;
|
|
|
|
break;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
if (type != LM_TC_TEXTRM)
|
2001-02-13 13:28:32 +00:00
|
|
|
f.setColor(LColor::math);
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
return f;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void mathed_init_fonts() //removed 'static' because DEC cxx does not
|
2001-02-14 19:35:25 +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
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
Math_Fonts = new LyXFont[8]; //DEC cxx cannot initialize all fonts
|
|
|
|
//at once (JMarc) rc
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-14 19:35:25 +00:00
|
|
|
for (int i = 0 ; i < 8 ; ++i) {
|
|
|
|
Math_Fonts[i] = LyXFont(LyXFont::ALL_SANE);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-14 19:35:25 +00:00
|
|
|
Math_Fonts[0].setShape(LyXFont::ITALIC_SHAPE);
|
2000-02-17 19:59:08 +00:00
|
|
|
|
2001-02-14 19:35:25 +00:00
|
|
|
Math_Fonts[1].setFamily(LyXFont::SYMBOL_FAMILY);
|
2000-10-26 00:03:21 +00:00
|
|
|
|
2001-02-14 19:35:25 +00:00
|
|
|
Math_Fonts[2].setFamily(LyXFont::SYMBOL_FAMILY);
|
|
|
|
Math_Fonts[2].setShape(LyXFont::ITALIC_SHAPE);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-14 19:35:25 +00:00
|
|
|
Math_Fonts[3].setSeries(LyXFont::BOLD_SERIES);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-14 19:35:25 +00:00
|
|
|
Math_Fonts[4].setFamily(LyXFont::SANS_FAMILY);
|
|
|
|
Math_Fonts[4].setShape(LyXFont::ITALIC_SHAPE);
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-02-14 19:35:25 +00:00
|
|
|
Math_Fonts[5].setFamily(LyXFont::TYPEWRITER_FAMILY);
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2001-02-14 19:35:25 +00:00
|
|
|
Math_Fonts[6].setFamily(LyXFont::ROMAN_FAMILY);
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2001-02-14 19:35:25 +00:00
|
|
|
Math_Fonts[7].setFamily(LyXFont::SANS_FAMILY);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-14 19:35:25 +00:00
|
|
|
LyXFont f = WhichFont(LM_TC_VAR, LM_ST_TEXT);
|
2001-02-15 12:22:01 +00:00
|
|
|
MathedInset::defaultAscent(lyxfont::maxAscent(f));
|
|
|
|
MathedInset::defaultDescent(lyxfont::maxDescent(f));
|
|
|
|
MathedInset::defaultWidth(lyxfont::width('I', f));
|
2001-02-14 19:35:25 +00:00
|
|
|
}
|
2000-10-26 00:03:21 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
// quite a hack i know. Should be done with return values...
|
|
|
|
int number_of_newlines = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
InsetFormula::InsetFormula(bool display)
|
|
|
|
{
|
2001-02-13 13:28:32 +00:00
|
|
|
par = new MathParInset; // this leaks
|
2001-02-14 19:35:25 +00:00
|
|
|
// mathcursor = 0;
|
2001-02-28 17:21:16 +00:00
|
|
|
disp_flag_ = display;
|
|
|
|
if (disp_flag_) {
|
2001-02-13 13:28:32 +00:00
|
|
|
par->SetType(LM_OT_PAR);
|
|
|
|
par->SetStyle(LM_ST_DISPLAY);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
|
|
|
InsetFormula::InsetFormula(MathParInset * p)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
if (is_matrix_type(p->GetType()))
|
|
|
|
lyxerr << "InsetFormula::InsetFormula: This shouldn't happen" << endl;
|
|
|
|
|
|
|
|
par = is_multiline(p->GetType()) ?
|
2001-02-28 17:21:16 +00:00
|
|
|
new MathMatrixInset(*static_cast<MathMatrixInset*>(p)):
|
2001-02-20 13:16:07 +00:00
|
|
|
new MathParInset(*p);
|
2001-02-14 19:35:25 +00:00
|
|
|
// mathcursor = 0;
|
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
disp_flag_ = par->GetType() > 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()
|
|
|
|
{
|
2001-04-24 16:13:38 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning leak this for a while...
|
|
|
|
#endif
|
|
|
|
//delete par;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2001-04-24 16:13:38 +00:00
|
|
|
return new InsetFormula(par);
|
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
|
|
|
{
|
2001-04-24 16:13:38 +00:00
|
|
|
return mathed_write(par, os, fragile, par->label());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
par->Write(os, false);
|
|
|
|
return 0;
|
2000-04-24 20:58:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2001-02-14 19:35:25 +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
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
return Ascii(buf, os, 0);
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-14 19:35:25 +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
|
|
|
{
|
2001-02-03 21:02:22 +00:00
|
|
|
if (is_ams(par->GetType()))
|
|
|
|
features.amsstyle = true;
|
|
|
|
|
|
|
|
// Validation is necessary only if not using AMS math.
|
|
|
|
// To be safe, we will always run mathedValidate.
|
|
|
|
//if (!features.amsstyle)
|
|
|
|
mathedValidate(features, par);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-01 15:03:52 +00:00
|
|
|
void InsetFormula::Read(Buffer const *buffer, LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-01-06 02:44:26 +00:00
|
|
|
istream & is = lex.getStream();
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
mathed_parser_file(is, lex.GetLineNo());
|
|
|
|
|
2001-02-20 17:45:56 +00:00
|
|
|
MathedArray ar;
|
2001-04-24 16:13:38 +00:00
|
|
|
mathed_parse(ar, par, 0);
|
|
|
|
if (par->isMatrix()) {
|
|
|
|
//lyxerr << "################## InsetFormula::Read: IsMatrix\n";
|
|
|
|
static_cast<MathMatrixInset*>(par)->setData(ar);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
par->setData(ar);
|
|
|
|
//lyxerr << "################## InsetFormula::Read: keine Matrix\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//lyxerr << "InsetFormula::Read: par: " << par << " " << par->GetData() << endl;
|
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
par->Metrics();
|
2001-02-28 17:21:16 +00:00
|
|
|
disp_flag_ = (par->GetType() > 0);
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
// Update line number
|
|
|
|
lex.setLineNo(mathed_parser_lineno());
|
2001-02-14 19:35:25 +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,"
|
2001-02-15 12:22:01 +00:00
|
|
|
" or missing \\end_inset!" << endl;
|
2000-05-15 14:49:36 +00:00
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-03-01 15:03:52 +00:00
|
|
|
if (lyxerr.debugging(Debug::MATHED))
|
|
|
|
Write(buffer, lyxerr);
|
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::ascent(BufferView *, LyXFont const &) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2001-02-28 17:21:16 +00:00
|
|
|
return par->Ascent() + (disp_flag_ ? 8 : 1);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
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
|
|
|
{
|
2001-02-28 17:21:16 +00:00
|
|
|
return par->Descent() + (disp_flag_ ? 8 : 1);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-02-12 11:56:08 +00:00
|
|
|
int InsetFormula::width(BufferView * bv, LyXFont const & f) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
MathedInset::workWidth = bv->workWidth();
|
|
|
|
lfont_size = f.size();
|
|
|
|
par->Metrics();
|
|
|
|
return par->Width(); //+2;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
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,
|
2001-02-15 12:22:01 +00:00
|
|
|
int baseline, float & x, bool) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2001-02-12 11:56:08 +00:00
|
|
|
MathedInset::workWidth = bv->workWidth();
|
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);
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
// otherwise a segfault could occur
|
|
|
|
// in some XDrawRectangles (i.e. matrix) (Matthias)
|
2001-02-14 19:35:25 +00:00
|
|
|
if (mathcursor && mathcursor->GetPar() == par) {
|
2000-02-10 17:53:36 +00:00
|
|
|
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));
|
2001-02-03 21:02:22 +00:00
|
|
|
|
|
|
|
if (is_numbered(par->GetType())) {
|
2001-02-15 12:22:01 +00:00
|
|
|
LyXFont wfont = WhichFont(LM_TC_BF, par->size());
|
2000-05-19 19:46:23 +00:00
|
|
|
wfont.setLatex(LyXFont::OFF);
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-03 21:02:22 +00:00
|
|
|
if (is_singlely_numbered(par->GetType())) {
|
2000-02-10 17:53:36 +00:00
|
|
|
string str;
|
2001-04-24 16:13:38 +00:00
|
|
|
if (!par->label().empty())
|
|
|
|
str = string("(") + par->label() + ")";
|
2000-02-10 17:53:36 +00:00
|
|
|
else
|
|
|
|
str = string("(#)");
|
2000-05-19 19:46:23 +00:00
|
|
|
pain.text(int(x + 20), baseline, str, wfont);
|
2001-02-03 21:02:22 +00:00
|
|
|
} else {
|
2001-04-24 16:13:38 +00:00
|
|
|
MathedRowContainer::iterator crow = par->getRowSt().begin();
|
2000-02-10 17:53:36 +00:00
|
|
|
while (crow) {
|
2001-02-28 17:21:16 +00:00
|
|
|
int const y = baseline + crow->getBaseline();
|
2000-02-10 17:53:36 +00:00
|
|
|
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
|
|
|
}
|
2001-03-06 18:17:16 +00:00
|
|
|
++crow;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-04 20:43:54 +00:00
|
|
|
setCursorVisible(false);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-02-14 19:35:25 +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
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
mathcursor = new MathedCursor(par);
|
|
|
|
|
|
|
|
if (!bv->lockInset(this))
|
|
|
|
lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
|
|
|
|
|
|
|
|
par->Metrics();
|
|
|
|
bv->updateInset(this, false);
|
2001-02-15 12:22:01 +00:00
|
|
|
x += par->xo();
|
|
|
|
y += par->yo();
|
2001-02-14 19:35:25 +00:00
|
|
|
mathcursor->SetPos(x, y);
|
|
|
|
sel_x = 0;
|
|
|
|
sel_y = 0;
|
|
|
|
sel_flag = 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::InsetUnlock(BufferView * bv)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
if (mathcursor) {
|
|
|
|
if (mathcursor->InMacroMode()) {
|
|
|
|
mathcursor->MacroModeClose();
|
|
|
|
UpdateLocal(bv);
|
|
|
|
}
|
|
|
|
delete mathcursor;
|
|
|
|
}
|
|
|
|
mathcursor = 0;
|
|
|
|
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
|
2001-04-24 16:13:38 +00:00
|
|
|
void InsetFormula::InsertSymbol(BufferView *, string const & s)
|
2001-02-14 19:35:25 +00:00
|
|
|
{
|
|
|
|
if (s.empty() || !mathcursor)
|
|
|
|
return;
|
|
|
|
mathcursor->Interpret(s);
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre: UpdateLocal(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-02-14 19:35:25 +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
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
mathcursor->GetPos(x, y);
|
2001-02-15 12:22:01 +00:00
|
|
|
x -= par->xo();
|
|
|
|
y -= par->yo();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
if (!mathcursor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
mathcursor->GetPos(x, y);
|
|
|
|
// x -= par->xo;
|
2001-02-15 12:22:01 +00:00
|
|
|
y -= par->yo();
|
2001-02-14 19:35:25 +00:00
|
|
|
LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
|
2001-04-04 20:43:54 +00:00
|
|
|
int const asc = lyxfont::maxAscent(font);
|
|
|
|
int const desc = lyxfont::maxDescent(font);
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-04-04 20:43:54 +00:00
|
|
|
if (isCursorVisible())
|
2001-02-14 19:35:25 +00:00
|
|
|
bv->hideLockedInsetCursor();
|
|
|
|
else
|
|
|
|
bv->showLockedInsetCursor(x, y, asc, desc);
|
|
|
|
|
2001-04-04 20:43:54 +00:00
|
|
|
toggleCursorVisible();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2001-04-04 20:43:54 +00:00
|
|
|
if (!isCursorVisible()) {
|
2001-02-14 19:35:25 +00:00
|
|
|
if (mathcursor) {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
mathcursor->GetPos(x, y);
|
|
|
|
// x -= par->xo;
|
2001-02-15 12:22:01 +00:00
|
|
|
y -= par->yo();
|
2001-02-14 19:35:25 +00:00
|
|
|
LyXFont font = WhichFont(LM_TC_TEXTRM, LM_ST_TEXT);
|
2001-04-04 20:43:54 +00:00
|
|
|
int const asc = lyxfont::maxAscent(font);
|
|
|
|
int const desc = lyxfont::maxDescent(font);
|
2001-02-14 19:35:25 +00:00
|
|
|
bv->fitLockedInsetCursor(x, y, asc, desc);
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2001-04-04 20:43:54 +00:00
|
|
|
if (isCursorVisible())
|
2001-02-14 19:35:25 +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
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
if (!mathcursor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2001-02-28 17:21:16 +00:00
|
|
|
if (dspf != disp_flag_) {
|
2001-02-14 19:35:25 +00:00
|
|
|
if (dspf) {
|
|
|
|
par->SetType(LM_OT_PAR);
|
|
|
|
par->SetStyle(LM_ST_DISPLAY);
|
|
|
|
} else {
|
|
|
|
if (is_multiline(par->GetType())) {
|
|
|
|
if (mathcursor)
|
|
|
|
mathcursor->SetPar(par);
|
|
|
|
}
|
|
|
|
par->SetType(LM_OT_MIN);
|
|
|
|
par->SetStyle(LM_ST_TEXT);
|
2001-04-24 16:13:38 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning Labels
|
|
|
|
#endif
|
|
|
|
/*
|
2001-02-28 17:21:16 +00:00
|
|
|
if (!label_.empty()) {
|
|
|
|
label_.erase();
|
2001-02-14 19:35:25 +00:00
|
|
|
}
|
2001-04-24 16:13:38 +00:00
|
|
|
*/
|
2001-02-14 19:35:25 +00:00
|
|
|
}
|
2001-02-28 17:21:16 +00:00
|
|
|
disp_flag_ = dspf;
|
2001-02-14 19:35:25 +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
|
|
|
vector<string> label_list;
|
2001-04-24 16:13:38 +00:00
|
|
|
MathedRowContainer::iterator crow = par->getRowSt().begin();
|
|
|
|
for ( ; crow; ++crow)
|
|
|
|
label_list.push_back(crow->getLabel());
|
2000-05-19 16:46:01 +00:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
par->Metrics(); // To inform lyx kernel the exact size
|
2001-02-15 12:22:01 +00:00
|
|
|
// (there were problems with arrays).
|
2001-02-14 19:35:25 +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,
|
2001-02-15 12:22:01 +00:00
|
|
|
int x, int y, int /*button*/)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
if (mathcursor) {
|
|
|
|
HideInsetCursor(bv);
|
2001-02-15 12:22:01 +00:00
|
|
|
x += par->xo();
|
|
|
|
y += par->yo();
|
2001-02-14 19:35:25 +00:00
|
|
|
mathcursor->SetPos(x, y);
|
|
|
|
ShowInsetCursor(bv);
|
|
|
|
if (sel_flag) {
|
|
|
|
sel_flag = false;
|
|
|
|
sel_x = sel_y = 0;
|
|
|
|
bv->updateInset(this, false);
|
|
|
|
}
|
2000-03-24 13:24:58 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-02-14 19:35:25 +00:00
|
|
|
void InsetFormula::InsetButtonPress(BufferView * bv, int x, int y,
|
2001-02-15 12:22:01 +00:00
|
|
|
int /*button*/)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
sel_flag = false;
|
2001-02-28 17:21:16 +00:00
|
|
|
sel_x = x;
|
|
|
|
sel_y = y;
|
2001-02-14 19:35:25 +00:00
|
|
|
if (mathcursor && mathcursor->Selection()) {
|
|
|
|
mathcursor->SelClear();
|
|
|
|
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,
|
2001-02-15 12:22:01 +00:00
|
|
|
int x, int y, int /*button*/)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-14 19:35:25 +00:00
|
|
|
if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
|
|
|
|
sel_flag = true;
|
|
|
|
HideInsetCursor(bv);
|
2001-02-15 12:22:01 +00:00
|
|
|
mathcursor->SetPos(sel_x + par->xo(), sel_y + par->yo());
|
2001-02-14 19:35:25 +00:00
|
|
|
mathcursor->SelStart();
|
|
|
|
ShowInsetCursor(bv);
|
|
|
|
mathcursor->GetPos(sel_x, sel_y);
|
|
|
|
} else if (sel_flag) {
|
|
|
|
HideInsetCursor(bv);
|
2001-02-15 12:22:01 +00:00
|
|
|
x += par->xo();
|
|
|
|
y += par->yo();
|
2001-02-14 19:35:25 +00:00
|
|
|
mathcursor->SetPos(x, y);
|
|
|
|
ShowInsetCursor(bv);
|
|
|
|
mathcursor->GetPos(x, y);
|
|
|
|
if (sel_x != x || sel_y != y)
|
|
|
|
bv->updateInset(this, false);
|
|
|
|
sel_x = x;
|
|
|
|
sel_y = y;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2001-02-28 17:21:16 +00:00
|
|
|
if (disp_flag_) {
|
2001-02-14 19:35:25 +00:00
|
|
|
short type = par->GetType();
|
2001-02-15 12:22:01 +00:00
|
|
|
bool const oldf = is_numbered(type);
|
2001-02-14 19:35:25 +00:00
|
|
|
if (numbf && !oldf)
|
|
|
|
++type;
|
|
|
|
if (!numbf && oldf)
|
|
|
|
--type;
|
|
|
|
par->SetType(type);
|
|
|
|
return oldf;
|
|
|
|
} else
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-02-25 13:35:38 +00:00
|
|
|
UpdatableInset::RESULT
|
2001-02-23 16:10:03 +00:00
|
|
|
InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
|
|
|
|
string const & arg)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-24 16:13:38 +00:00
|
|
|
//lyxerr << "InsetFormula::LocalDispatch: act: " << action
|
|
|
|
// << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
|
2001-02-14 19:35:25 +00:00
|
|
|
// extern char *dispatch_result;
|
2001-04-24 16:13:38 +00:00
|
|
|
|
|
|
|
if (!mathcursor) {
|
|
|
|
return UNDISPATCHED;
|
|
|
|
}
|
|
|
|
|
2001-02-14 19:35:25 +00:00
|
|
|
MathedTextCodes varcode = LM_TC_MIN;
|
|
|
|
bool was_macro = mathcursor->InMacroMode();
|
|
|
|
bool sel = false;
|
|
|
|
bool space_on = false;
|
|
|
|
bool was_selection = mathcursor->Selection();
|
|
|
|
RESULT result = DISPATCHED;
|
|
|
|
static MathSpaceInset * sp= 0;
|
|
|
|
|
|
|
|
HideInsetCursor(bv);
|
|
|
|
|
|
|
|
if (mathcursor->getLastCode() == LM_TC_TEX) {
|
|
|
|
varcode = LM_TC_TEX;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
// --- Cursor Movements ---------------------------------------------
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_RIGHTSEL:
|
|
|
|
sel = true; // fall through...
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_RIGHT:
|
|
|
|
result = DISPATCH_RESULT(mathcursor->Right(sel));
|
|
|
|
if (!sel && (result == DISPATCHED))
|
|
|
|
result = DISPATCHED_NOUPDATE;
|
2001-04-24 16:13:38 +00:00
|
|
|
UpdateLocal(bv);
|
2001-02-15 12:22:01 +00:00
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_LEFTSEL:
|
|
|
|
sel = true; // fall through
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_LEFT:
|
|
|
|
result = DISPATCH_RESULT(mathcursor->Left(sel));
|
|
|
|
if (!sel && (result == DISPATCHED))
|
2001-02-14 19:35:25 +00:00
|
|
|
result = DISPATCHED_NOUPDATE;
|
2001-04-24 16:13:38 +00:00
|
|
|
UpdateLocal(bv);
|
2001-02-15 12:22:01 +00:00
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_UPSEL:
|
|
|
|
sel = true;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_UP:
|
|
|
|
result = DISPATCH_RESULT(mathcursor->Up(sel));
|
|
|
|
if (!sel && (result == DISPATCHED))
|
|
|
|
result = DISPATCHED_NOUPDATE;
|
2001-04-24 16:13:38 +00:00
|
|
|
UpdateLocal(bv);
|
2001-02-15 12:22:01 +00:00
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_DOWNSEL:
|
|
|
|
sel = true;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_DOWN:
|
|
|
|
result = DISPATCH_RESULT(mathcursor->Down(sel));
|
|
|
|
if (!sel && (result == DISPATCHED))
|
2001-02-14 19:35:25 +00:00
|
|
|
result = DISPATCHED_NOUPDATE;
|
2001-04-24 16:13:38 +00:00
|
|
|
UpdateLocal(bv);
|
2001-02-15 12:22:01 +00:00
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_HOME:
|
|
|
|
mathcursor->Home();
|
|
|
|
result = DISPATCHED_NOUPDATE;
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_END:
|
|
|
|
mathcursor->End();
|
|
|
|
result = DISPATCHED_NOUPDATE;
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_DELETE_LINE_FORWARD:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::DELETE);
|
|
|
|
mathcursor->DelLine();
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BREAKLINE:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
byte c = arg.empty() ? '1' : arg[0];
|
|
|
|
mathcursor->Insert(c, LM_TC_CR);
|
2001-04-24 16:13:38 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning Labels
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
if (!par->label().empty()) {
|
2001-02-28 17:21:16 +00:00
|
|
|
mathcursor->setLabel(label_);
|
|
|
|
label_.erase();
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
2001-04-24 16:13:38 +00:00
|
|
|
*/
|
2001-02-15 12:22:01 +00:00
|
|
|
par = mathcursor->GetPar();
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
}
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_TAB:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
mathcursor->Insert(0, LM_TC_TAB);
|
|
|
|
//UpdateInset(this);
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_TABINSERT:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
mathcursor->Insert('T', LM_TC_TAB);
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_BACKSPACE:
|
|
|
|
if (!mathcursor->Left())
|
2001-02-14 19:35:25 +00:00
|
|
|
break;
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
if (!mathcursor->InMacroMode() && mathcursor->pullArg()) {
|
2001-02-14 19:35:25 +00:00
|
|
|
bv->updateInset(this, true);
|
|
|
|
break;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
// fall through...
|
|
|
|
|
|
|
|
case LFUN_DELETE:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::DELETE);
|
|
|
|
mathcursor->Delete();
|
|
|
|
bv->updateInset(this, true);
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
// case LFUN_GETXY:
|
|
|
|
// sprintf(dispatch_buffer, "%d %d",);
|
|
|
|
// dispatch_result = dispatch_buffer;
|
|
|
|
// break;
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_SETXY:
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int x1;
|
|
|
|
int y1;
|
|
|
|
istringstream ist(arg.c_str());
|
|
|
|
ist >> x >> y;
|
|
|
|
par->GetXY(x1, y1);
|
|
|
|
mathcursor->SetPos(x1 + x, y1 + y);
|
|
|
|
}
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
/* cursor selection ---------------------------- */
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_PASTE:
|
|
|
|
if (was_macro)
|
|
|
|
mathcursor->MacroModeClose();
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
mathcursor->SelPaste();
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_CUT:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::DELETE);
|
|
|
|
mathcursor->SelCut();
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_COPY:
|
|
|
|
mathcursor->SelCopy();
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_HOMESEL:
|
|
|
|
case LFUN_ENDSEL:
|
|
|
|
case LFUN_WORDRIGHTSEL:
|
|
|
|
case LFUN_WORDLEFTSEL:
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
// --- accented characters ------------------------------
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
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;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
// Greek mode
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_GREEK:
|
|
|
|
if (!greek_kb_flag) {
|
|
|
|
greek_kb_flag = 1;
|
2001-04-24 17:33:01 +00:00
|
|
|
bv->owner()->message(_("Math greek mode on"));
|
2001-02-15 12:22:01 +00:00
|
|
|
} else
|
|
|
|
greek_kb_flag = 0;
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
// Greek keyboard
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_GREEK_TOGGLE:
|
|
|
|
greek_kb_flag = (greek_kb_flag) ? 0 : 2;
|
|
|
|
if (greek_kb_flag)
|
2001-04-24 17:33:01 +00:00
|
|
|
bv->owner()->message(_("Math greek keyboard on"));
|
2001-02-15 12:22:01 +00:00
|
|
|
else
|
2001-04-24 17:33:01 +00:00
|
|
|
bv->owner()->message(_("Math greek keyboard off"));
|
2001-02-15 12:22:01 +00:00
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
// Math fonts
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_BOLD: mathcursor->toggleLastCode(LM_TC_BF); break;
|
|
|
|
case LFUN_SANS: mathcursor->toggleLastCode(LM_TC_SF); break;
|
|
|
|
case LFUN_EMPH: mathcursor->toggleLastCode(LM_TC_CAL); break;
|
|
|
|
case LFUN_ROMAN: mathcursor->toggleLastCode(LM_TC_RM); break;
|
|
|
|
case LFUN_CODE: mathcursor->toggleLastCode(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);
|
2001-04-24 17:33:01 +00:00
|
|
|
bv->owner()->message(_("TeX mode"));
|
2001-02-15 12:22:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_MATH_NUMBER:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
2001-02-28 17:21:16 +00:00
|
|
|
if (disp_flag_) {
|
2001-02-15 12:22:01 +00:00
|
|
|
short type = par->GetType();
|
|
|
|
if (is_numbered(type)) {
|
|
|
|
--type;
|
2001-04-24 16:13:38 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning Labels
|
|
|
|
#endif
|
|
|
|
/*
|
2001-02-28 17:21:16 +00:00
|
|
|
if (!label_.empty()) {
|
|
|
|
label_.erase();
|
2001-02-14 19:35:25 +00:00
|
|
|
}
|
2001-04-24 16:13:38 +00:00
|
|
|
*/
|
2001-04-24 17:33:01 +00:00
|
|
|
bv->owner()->message(_("No number"));
|
2001-02-15 12:22:01 +00:00
|
|
|
} else {
|
|
|
|
++type;
|
2001-04-24 17:33:01 +00:00
|
|
|
bv->owner()->message(_("Number"));
|
2001-02-14 19:35:25 +00:00
|
|
|
}
|
2001-02-15 12:22:01 +00:00
|
|
|
par->SetType(type);
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
}
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_MATH_NONUMBER:
|
|
|
|
if (is_multi_numbered(par->GetType())) {
|
2001-02-14 19:35:25 +00:00
|
|
|
//BUG
|
2001-04-24 16:13:38 +00:00
|
|
|
// par->SetNumbered(!par->IsNumbered());
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-04-17 00:19:49 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
2001-02-15 12:22:01 +00:00
|
|
|
#warning This is a terrible hack! We should find a better solution.
|
2001-04-17 00:19:49 +00:00
|
|
|
#endif
|
2001-02-15 12:22:01 +00:00
|
|
|
while (mathcursor->getLabel() == MathedXIter::error_label) {
|
|
|
|
if (LocalDispatch(bv, LFUN_LEFT, string()) == FINISHED)
|
2001-02-14 19:35:25 +00:00
|
|
|
return DISPATCHED;
|
|
|
|
}
|
2001-02-15 12:22:01 +00:00
|
|
|
mathcursor->setNumbered();
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
}
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_MATH_LIMITS:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
if (mathcursor->Limits())
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
// fall through!
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_MATH_SIZE:
|
|
|
|
if (!arg.empty()) {
|
2001-02-16 09:25:43 +00:00
|
|
|
latexkeys const * l = in_word_set(arg);
|
2001-04-24 16:13:38 +00:00
|
|
|
int const sz = l ? l->id : -1;
|
2001-02-15 12:22:01 +00:00
|
|
|
mathcursor->SetSize(sz);
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
2001-02-14 19:35:25 +00:00
|
|
|
break;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
// possible fall through?
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_INSERT_MATH:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
InsertSymbol(bv, arg);
|
2001-04-27 20:26:24 +00:00
|
|
|
UpdateLocal(bv);
|
2001-02-15 12:22:01 +00:00
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
|
|
|
|
case LFUN_INSERT_MATRIX:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
2001-02-28 17:21:16 +00:00
|
|
|
char s[80];
|
2001-05-31 02:23:46 +00:00
|
|
|
//char arg2[80];
|
|
|
|
|
2001-02-28 17:21:16 +00:00
|
|
|
// This is just so that too long args won't ooze out of s.
|
2001-05-31 02:23:46 +00:00
|
|
|
//strncpy(arg2, arg.c_str(), 80);
|
|
|
|
//arg2[79]= '\0';
|
|
|
|
string arg2(arg, 0, 80);
|
|
|
|
|
2001-02-28 17:21:16 +00:00
|
|
|
int m;
|
|
|
|
int n;
|
2001-05-31 02:23:46 +00:00
|
|
|
int const k = sscanf(arg2.c_str(), "%d %d %s", &m, &n, s);
|
2001-02-15 12:22:01 +00:00
|
|
|
s[79] = '\0';
|
|
|
|
|
|
|
|
if (k < 1) {
|
|
|
|
m = n = 1;
|
|
|
|
} else if (k == 1) {
|
|
|
|
n = 1;
|
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
if (mathcursor) {
|
|
|
|
MathMatrixInset * p = new MathMatrixInset(m, n);
|
2001-05-31 02:23:46 +00:00
|
|
|
if (k > 2 && int(std::strlen(s)) > m)
|
2001-02-15 12:22:01 +00:00
|
|
|
p->SetAlign(s[0], &s[1]);
|
2001-02-17 18:52:53 +00:00
|
|
|
mathcursor->insertInset(p, LM_TC_ACTIVE_INSET);
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_MATH_DELIM:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
2001-02-28 17:21:16 +00:00
|
|
|
char lf[40];
|
|
|
|
char rg[40];
|
2001-05-31 02:23:46 +00:00
|
|
|
//char arg2[40];
|
2001-02-28 17:21:16 +00:00
|
|
|
int ilf = '(';
|
|
|
|
int irg = '.';
|
2001-02-16 09:25:43 +00:00
|
|
|
latexkeys const * l;
|
2001-02-15 12:22:01 +00:00
|
|
|
string vdelim("(){}[]./|");
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
if (arg.empty())
|
|
|
|
break;
|
2001-05-31 02:23:46 +00:00
|
|
|
//::strncpy(arg2, arg.c_str(), 40);
|
|
|
|
//arg2[39]= '\0';
|
|
|
|
string arg2(arg, 0, 40);
|
|
|
|
|
|
|
|
int const n = sscanf(arg2.c_str(), "%s %s", lf, rg);
|
2001-02-15 12:22:01 +00:00
|
|
|
lf[39] = '\0';
|
|
|
|
rg[39] = '\0';
|
|
|
|
|
|
|
|
if (n > 0) {
|
|
|
|
if (isdigit(lf[0]))
|
|
|
|
ilf = lyx::atoi(lf);
|
|
|
|
else
|
2001-02-14 19:35:25 +00:00
|
|
|
if (lf[1]) {
|
2001-04-25 15:43:57 +00:00
|
|
|
l = in_word_set(lf);
|
2001-02-14 19:35:25 +00:00
|
|
|
// Long words will cause l == 0; so check.
|
|
|
|
if (l)
|
|
|
|
ilf = l->id;
|
|
|
|
} else if (vdelim.find(lf[0]) != string::npos)
|
|
|
|
ilf = lf[0];
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
if (n > 1) {
|
|
|
|
if (isdigit(rg[0]))
|
2001-02-14 19:35:25 +00:00
|
|
|
irg = lyx::atoi(rg);
|
2001-02-15 12:22:01 +00:00
|
|
|
else
|
2001-02-14 19:35:25 +00:00
|
|
|
if (rg[1]) {
|
2001-04-25 15:43:57 +00:00
|
|
|
l = in_word_set(rg);
|
2001-02-14 19:35:25 +00:00
|
|
|
if (l)
|
|
|
|
irg = l->id;
|
|
|
|
} else if (vdelim.find(rg[0]) != string::npos)
|
|
|
|
irg = rg[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
MathDelimInset * p = new MathDelimInset(ilf, irg);
|
2001-02-17 18:52:53 +00:00
|
|
|
mathcursor->insertInset(p, LM_TC_ACTIVE_INSET);
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
break;
|
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_PROTECTEDSPACE:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
sp = new MathSpaceInset(1);
|
2001-02-17 18:52:53 +00:00
|
|
|
mathcursor->insertInset(sp, LM_TC_INSET);
|
2001-02-15 12:22:01 +00:00
|
|
|
space_on = true;
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_INSERT_LABEL:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
if (par->GetType() < LM_OT_PAR)
|
2001-02-14 19:35:25 +00:00
|
|
|
break;
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
string old_label = is_multiline(par->GetType())
|
2001-04-24 16:13:38 +00:00
|
|
|
? mathcursor->getLabel() : par->label();
|
2001-02-15 12:22:01 +00:00
|
|
|
|
2001-04-17 00:19:49 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
2001-02-15 12:22:01 +00:00
|
|
|
#warning This is a terrible hack! We should find a better solution.
|
2001-04-17 00:19:49 +00:00
|
|
|
#endif
|
2001-02-15 12:22:01 +00:00
|
|
|
// This is needed because in some positions
|
|
|
|
// mathcursor->cursor->crow is equal to 0, and therefore
|
|
|
|
// the label cannot be inserted.
|
|
|
|
// So we move the cursor left until
|
|
|
|
// mathcursor->cursor->crow != 0.
|
|
|
|
while (old_label == MathedXIter::error_label) {
|
|
|
|
if (LocalDispatch(bv, LFUN_LEFT, string()) == FINISHED)
|
|
|
|
return DISPATCHED;
|
|
|
|
old_label = mathcursor->getLabel();
|
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
string new_label = arg;
|
|
|
|
if (new_label.empty()) {
|
2001-04-04 20:43:54 +00:00
|
|
|
string const default_label =
|
|
|
|
(lyxrc.label_init_length >= 0) ? "eq:" : "";
|
|
|
|
pair<bool, string> const res = old_label.empty()
|
|
|
|
? askForText(_("Enter new label to insert:"),
|
|
|
|
default_label)
|
2001-02-15 12:22:01 +00:00
|
|
|
: askForText(_("Enter label:"), old_label);
|
|
|
|
if (!res.first)
|
|
|
|
break;
|
|
|
|
new_label = frontStrip(strip(res.second));
|
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
if (new_label == old_label)
|
|
|
|
break; // Nothing to do
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
if (!new_label.empty())
|
|
|
|
SetNumber(true);
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
|
|
|
|
bv->redraw();
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning Labels
|
|
|
|
#endif
|
|
|
|
/*
|
2001-02-15 12:22:01 +00:00
|
|
|
if (is_multi_numbered(par->GetType())) {
|
|
|
|
mathcursor->setLabel(new_label);
|
2001-04-24 16:13:38 +00:00
|
|
|
// par->SetLabel(new_label);
|
2001-02-15 12:22:01 +00:00
|
|
|
} else
|
2001-02-28 17:21:16 +00:00
|
|
|
label_ = new_label;
|
2001-04-24 16:13:38 +00:00
|
|
|
*/
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
break;
|
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_MATH_DISPLAY:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
2001-02-28 17:21:16 +00:00
|
|
|
display(!disp_flag_);
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
// Invalid actions under math mode
|
|
|
|
case LFUN_MATH_MODE:
|
|
|
|
if (mathcursor->getLastCode()!= LM_TC_TEXTRM) {
|
2001-04-24 17:33:01 +00:00
|
|
|
bv->owner()->message(_("math text mode"));
|
2001-02-15 12:22:01 +00:00
|
|
|
varcode = LM_TC_TEXTRM;
|
|
|
|
} else {
|
|
|
|
varcode = LM_TC_VAR;
|
|
|
|
}
|
|
|
|
mathcursor->setLastCode(varcode);
|
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
case LFUN_UNDO:
|
2001-04-24 17:33:01 +00:00
|
|
|
bv->owner()->message(_("Invalid action in math mode!"));
|
2001-02-15 12:22:01 +00:00
|
|
|
break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-04-25 15:43:57 +00:00
|
|
|
case LFUN_MATH_EXTERN:
|
|
|
|
HandleExtern(arg, bv);
|
|
|
|
break;
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
//------- dummy actions
|
2001-04-20 02:43:42 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
2001-04-17 14:20:21 +00:00
|
|
|
#warning Is this needed here? Shouldnt the main dispatch handle this? (Lgb)
|
2001-04-20 02:43:42 +00:00
|
|
|
#endif
|
2001-04-17 14:20:21 +00:00
|
|
|
//case LFUN_EXEC_COMMAND:
|
|
|
|
//bv->owner()->getMiniBuffer()->PrepareForCommand();
|
|
|
|
//break;
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
default:
|
2001-04-04 20:43:54 +00:00
|
|
|
if ((action == -1 || action == LFUN_SELFINSERT)
|
|
|
|
&& !arg.empty()) {
|
2001-02-15 12:22:01 +00:00
|
|
|
unsigned char c = arg[0];
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
if (c == ' ' && mathcursor->getAccent() == LM_hat) {
|
|
|
|
c = '^';
|
|
|
|
mathcursor->setAccent(0);
|
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
if (c == 0) { // Dead key, do nothing
|
|
|
|
//lyxerr << "deadkey" << endl;
|
|
|
|
break;
|
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
if (isalpha(c)) {
|
|
|
|
if (mathcursor->getLastCode() == LM_TC_TEX) {
|
2001-02-14 19:35:25 +00:00
|
|
|
mathcursor->MacroModeOpen();
|
|
|
|
mathcursor->clearLastCode();
|
2001-02-15 12:22:01 +00:00
|
|
|
varcode = LM_TC_MIN;
|
|
|
|
} else if (!varcode) {
|
|
|
|
short f = (mathcursor->getLastCode()) ?
|
|
|
|
mathcursor->getLastCode() :
|
|
|
|
static_cast<MathedTextCodes>(mathcursor->GetFCode());
|
|
|
|
varcode = MathIsAlphaFont(f) ?
|
2001-02-14 19:35:25 +00:00
|
|
|
static_cast<MathedTextCodes>(f) :
|
|
|
|
LM_TC_VAR;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// lyxerr << "Varcode << vardoce;
|
|
|
|
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'];
|
2001-02-14 19:35:25 +00:00
|
|
|
} else
|
2001-02-15 12:22:01 +00:00
|
|
|
char_code = LM_TC_SYMB;
|
2001-02-14 19:35:25 +00:00
|
|
|
}
|
2001-02-15 12:22:01 +00:00
|
|
|
|
|
|
|
mathcursor->Insert(c, char_code);
|
|
|
|
|
|
|
|
if (greek_kb_flag && char_code == LM_TC_RM )
|
|
|
|
mathcursor->setLastCode(LM_TC_VAR);
|
|
|
|
|
|
|
|
varcode = LM_TC_MIN;
|
|
|
|
|
2001-02-28 17:21:16 +00:00
|
|
|
if (greek_kb_flag < 2)
|
2001-02-15 12:22:01 +00:00
|
|
|
greek_kb_flag = 0;
|
2001-05-31 02:23:46 +00:00
|
|
|
#if 0
|
2001-02-15 12:22:01 +00:00
|
|
|
} else if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
|
2001-05-31 02:23:46 +00:00
|
|
|
#else
|
|
|
|
} else if (contains("!,:;{}", c)
|
|
|
|
&& (varcode == LM_TC_TEX||was_macro)) {
|
|
|
|
#endif
|
2001-02-15 12:22:01 +00:00
|
|
|
mathcursor->Insert(c, LM_TC_TEX);
|
|
|
|
if (c == '{') {
|
|
|
|
mathcursor->Insert('}', LM_TC_TEX);
|
|
|
|
mathcursor->Left();
|
|
|
|
}
|
|
|
|
mathcursor->clearLastCode();
|
|
|
|
// varcode = LM_TC_MIN;
|
|
|
|
} else if (c == '_' && varcode == LM_TC_TEX) {
|
|
|
|
mathcursor->Insert(c, LM_TC_SPECIAL);
|
|
|
|
mathcursor->clearLastCode();
|
|
|
|
// varcode = LM_TC_MIN;
|
|
|
|
} else if (('0'<= c && c<= '9') && (varcode == LM_TC_TEX||was_macro)) {
|
|
|
|
mathcursor->MacroModeOpen();
|
|
|
|
mathcursor->clearLastCode();
|
|
|
|
mathcursor->Insert(c, LM_TC_MIN);
|
2001-05-31 02:23:46 +00:00
|
|
|
} else if (('0'<= c && c<= '9') ||
|
|
|
|
#if 0
|
|
|
|
strchr(";:!|[]().,?", c)
|
|
|
|
#else
|
|
|
|
contains(";:!|[]().,?", c)
|
|
|
|
#endif
|
|
|
|
) {
|
2001-02-15 12:22:01 +00:00
|
|
|
mathcursor->Insert(c, LM_TC_CONST);
|
2001-05-31 02:23:46 +00:00
|
|
|
} else if (
|
|
|
|
#if 0
|
|
|
|
strchr("+/-*<>=", c)
|
|
|
|
#else
|
|
|
|
contains("+/-*<>=", c)
|
|
|
|
#endif
|
|
|
|
) {
|
2001-02-15 12:22:01 +00:00
|
|
|
mathcursor->Insert(c, LM_TC_BOP);
|
2001-05-31 02:23:46 +00:00
|
|
|
} else if (
|
|
|
|
#if 0
|
|
|
|
strchr(latex_special_chars, c)
|
|
|
|
#else
|
|
|
|
contains(latex_special_chars, c)
|
|
|
|
#endif
|
|
|
|
&& c!= '_') {
|
2001-02-15 12:22:01 +00:00
|
|
|
mathcursor->Insert(c, LM_TC_SPECIAL);
|
|
|
|
} else if (c == '_' || c == '^') {
|
|
|
|
char s[2];
|
|
|
|
s[0] = c;
|
|
|
|
s[1] = 0;
|
|
|
|
mathcursor->Interpret(s);
|
|
|
|
} else if (c == ' ') {
|
|
|
|
if (!varcode) {
|
|
|
|
short f = (mathcursor->getLastCode()) ?
|
|
|
|
mathcursor->getLastCode() :
|
|
|
|
static_cast<MathedTextCodes>(mathcursor->GetFCode());
|
|
|
|
varcode = MathIsAlphaFont(f) ?
|
|
|
|
static_cast<MathedTextCodes>(f) :
|
|
|
|
LM_TC_VAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (varcode == LM_TC_TEXTRM) {
|
|
|
|
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())
|
|
|
|
result = FINISHED;
|
|
|
|
} else if (c == '\'' || c == '@') {
|
|
|
|
mathcursor->Insert (c, LM_TC_VAR);
|
|
|
|
} else if (c == '\\') {
|
|
|
|
if (was_macro)
|
|
|
|
mathcursor->MacroModeClose();
|
2001-04-24 16:13:38 +00:00
|
|
|
// This line nukes the mathcursor. Why?
|
2001-04-24 17:33:01 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning Still? (Lgb)
|
|
|
|
#endif
|
|
|
|
bv->owner()->message(_("TeX mode"));
|
2001-02-15 12:22:01 +00:00
|
|
|
mathcursor->setLastCode(LM_TC_TEX);
|
2001-02-14 19:35:25 +00:00
|
|
|
}
|
2001-04-24 16:13:38 +00:00
|
|
|
// Andre:
|
2001-02-15 12:22:01 +00:00
|
|
|
UpdateLocal(bv);
|
|
|
|
} else if (action == LFUN_MATH_PANEL) {
|
|
|
|
result = UNDISPATCHED;
|
|
|
|
} else {
|
|
|
|
// lyxerr << "Closed by action " << action << endl;
|
|
|
|
result = FINISHED;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-02-15 12:22:01 +00:00
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
//UpdateLocal(bv);
|
|
|
|
|
|
|
|
// Andre:
|
|
|
|
if ((mathcursor && was_macro != mathcursor->InMacroMode())
|
2001-02-15 12:22:01 +00:00
|
|
|
&& action >= 0
|
|
|
|
&& action != LFUN_BACKSPACE)
|
2001-04-24 16:13:38 +00:00
|
|
|
UpdateLocal(bv);
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
if (sp && !space_on)
|
|
|
|
sp = 0;
|
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
if (mathcursor && (mathcursor->Selection() || was_selection))
|
2001-02-14 19:35:25 +00:00
|
|
|
ToggleInsetSelection(bv);
|
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
|
|
|
|
result == UNDISPATCHED)
|
2001-02-14 19:35:25 +00:00
|
|
|
ShowInsetCursor(bv);
|
|
|
|
else
|
|
|
|
bv->unlockInset(this);
|
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
return result; // original version
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
void mathedValidate(LaTeXFeatures & features, MathParInset * par)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-20 16:00:22 +00:00
|
|
|
MathedIter it(&par->GetData());
|
2001-02-14 19:35:25 +00:00
|
|
|
|
|
|
|
while (it.OK() && !(features.binom && features.boldsymbol)) {
|
|
|
|
if (it.IsInset()) {
|
|
|
|
if (it.IsActive()) {
|
|
|
|
MathParInset * p = it.GetActiveInset();
|
|
|
|
if (!features.binom && p->GetType() == LM_OT_MACRO &&
|
2001-02-15 12:22:01 +00:00
|
|
|
p->GetName() == "binom") {
|
2001-02-14 19:35:25 +00:00
|
|
|
features.binom = true;
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i <= p->getMaxArgumentIdx(); ++i) {
|
|
|
|
p->setArgumentIdx(i);
|
|
|
|
mathedValidate(features, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MathedInset * p = it.GetInset();
|
|
|
|
if (!features.boldsymbol && p->GetName() == "boldsymbol") {
|
|
|
|
features.boldsymbol = true;
|
|
|
|
}
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-02-14 19:35:25 +00:00
|
|
|
it.Next();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-16 09:25:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
int mathed_write(MathParInset * p, ostream & os,
|
|
|
|
bool fragile, string const & label)
|
|
|
|
{
|
|
|
|
number_of_newlines = 0;
|
|
|
|
short mathed_env = p->GetType();
|
|
|
|
|
|
|
|
if (mathed_env == LM_OT_MIN) {
|
|
|
|
if (fragile) os << "\\protect";
|
|
|
|
os << "\\( "; // changed from " \\( " (Albrecht Dress)
|
|
|
|
} else {
|
|
|
|
if (mathed_env == LM_OT_PAR){
|
|
|
|
os << "\\[\n";
|
|
|
|
} else {
|
|
|
|
os << "\\begin{"
|
|
|
|
<< latex_mathenv[mathed_env]
|
|
|
|
<< "}";
|
|
|
|
if (is_multicolumn(mathed_env)) {
|
|
|
|
if (mathed_env != LM_OT_ALIGNAT
|
|
|
|
&& mathed_env != LM_OT_ALIGNATN)
|
|
|
|
os << "%";
|
|
|
|
os << "{" << p->GetColumns()/2 << "}";
|
|
|
|
}
|
|
|
|
os << "\n";
|
|
|
|
}
|
|
|
|
++number_of_newlines;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!label.empty() && label[0] > ' '
|
|
|
|
&& is_singlely_numbered(mathed_env)) {
|
|
|
|
os << "\\label{"
|
|
|
|
<< label
|
|
|
|
<< "}\n";
|
|
|
|
++number_of_newlines;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->Write(os, fragile);
|
|
|
|
|
|
|
|
if (mathed_env == LM_OT_MIN){
|
|
|
|
if (fragile) os << "\\protect";
|
|
|
|
os << " \\)";
|
|
|
|
} else if (mathed_env == LM_OT_PAR) {
|
|
|
|
os << "\\]\n";
|
|
|
|
++number_of_newlines;
|
|
|
|
} else {
|
|
|
|
os << "\n\\end{"
|
|
|
|
<< latex_mathenv[mathed_env]
|
|
|
|
<< "}\n";
|
|
|
|
number_of_newlines += 2;
|
|
|
|
}
|
|
|
|
return number_of_newlines;
|
|
|
|
}
|
2001-03-16 12:08:14 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2001-03-16 12:08:14 +00:00
|
|
|
/* FIXME: math-greek-toggle seems to work OK, but math-greek doesn't turn
|
|
|
|
* on greek mode */
|
|
|
|
bool math_insert_greek(BufferView * bv, char c)
|
|
|
|
{
|
|
|
|
if (bv->available() &&
|
|
|
|
(('A' <= c && c <= 'Z') ||
|
|
|
|
('a'<= c && c<= 'z'))) {
|
|
|
|
string tmp;
|
|
|
|
tmp = c;
|
|
|
|
if (!bv->theLockingInset() || bv->theLockingInset()->IsTextInset()) {
|
|
|
|
int greek_kb_flag_save = greek_kb_flag;
|
|
|
|
InsetFormula * new_inset = new InsetFormula();
|
|
|
|
bv->beforeChange(bv->text);
|
|
|
|
if (!bv->insertInset(new_inset)) {
|
|
|
|
delete new_inset;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Update(1);//BUG
|
|
|
|
new_inset->Edit(bv, 0, 0, 0);
|
|
|
|
new_inset->LocalDispatch(bv, LFUN_SELFINSERT, tmp);
|
|
|
|
if (greek_kb_flag_save < 2) {
|
|
|
|
bv->unlockInset(new_inset); // bv->theLockingInset());
|
|
|
|
bv->text->CursorRight(bv, true);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (bv->theLockingInset()->LyxCode() == Inset::MATH_CODE ||
|
|
|
|
bv->theLockingInset()->LyxCode() == Inset::MATHMACRO_CODE)
|
|
|
|
static_cast<InsetFormula*>(bv->theLockingInset())->LocalDispatch(bv, LFUN_SELFINSERT, tmp);
|
|
|
|
else
|
|
|
|
lyxerr << "Math error: attempt to write on a wrong "
|
|
|
|
"class of inset." << endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2001-04-25 15:43:57 +00:00
|
|
|
|
|
|
|
void InsetFormula::HandleExtern(const string & arg, BufferView * bv)
|
|
|
|
{
|
|
|
|
//string outfile = lyx::tempName("maple.out");
|
|
|
|
string outfile = "/tmp/lyx2" + arg + ".out";
|
|
|
|
ostringstream os;
|
|
|
|
par->WriteNormal(os);
|
2001-05-02 08:18:00 +00:00
|
|
|
string code = os.str().c_str();
|
2001-04-25 15:43:57 +00:00
|
|
|
string script = "lyx2" + arg + " '" + code + "' " + outfile;
|
|
|
|
lyxerr << "calling: " << script << endl;
|
|
|
|
Systemcalls cmd(Systemcalls::System, script, 0);
|
|
|
|
|
|
|
|
ifstream is(outfile.c_str());
|
|
|
|
MathedArray ar;
|
|
|
|
mathed_parser_file(is, 0);
|
|
|
|
mathed_parse(ar, par, 0);
|
|
|
|
par->array = ar;
|
|
|
|
|
|
|
|
UpdateLocal(bv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|