2001-07-07 09:19:51 +00:00
|
|
|
/*
|
2001-06-25 00:06:33 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include "Lsstream.h"
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "formula.h"
|
2001-07-06 12:09:32 +00:00
|
|
|
#include "formulamacro.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "commandtags.h"
|
|
|
|
#include "math_cursor.h"
|
|
|
|
#include "math_parser.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "lyxtext.h"
|
2001-07-06 12:09:32 +00:00
|
|
|
#include "lyxfunc.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "support/LOstream.h"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "Painter.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "math_arrayinset.h"
|
|
|
|
#include "math_spaceinset.h"
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
#include "mathed/support.h"
|
2001-07-06 15:57:54 +00:00
|
|
|
#include "undo_funcs.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-06-27 15:57:57 +00:00
|
|
|
using std::endl;
|
|
|
|
using std::ostream;
|
|
|
|
using std::vector;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
extern char const * latex_special_chars;
|
|
|
|
|
|
|
|
int greek_kb_flag = 0;
|
|
|
|
extern char const * latex_mathenv[];
|
|
|
|
MathCursor * mathcursor = 0;
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
|
|
// local global
|
|
|
|
int sel_x;
|
|
|
|
int sel_y;
|
|
|
|
bool sel_flag;
|
|
|
|
|
|
|
|
void mathed_init_fonts();
|
|
|
|
|
|
|
|
string nicelabel(string const & label)
|
|
|
|
{
|
2001-07-06 12:09:32 +00:00
|
|
|
return "(" + (label.empty() ? "#" : label) + ")";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-07-03 07:56:55 +00:00
|
|
|
void handleFont(BufferView * bv, MathTextCodes t)
|
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
if (mathcursor->selection())
|
2001-07-03 07:56:55 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
|
|
|
mathcursor->handleFont(t);
|
|
|
|
}
|
|
|
|
|
2001-07-26 16:14:23 +00:00
|
|
|
void handleAccent(BufferView * bv, string const & name)
|
2001-07-10 13:17:43 +00:00
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
2001-07-26 16:14:23 +00:00
|
|
|
mathcursor->handleAccent(name);
|
2001-07-10 13:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handleDelim(BufferView * bv, int l, int r)
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
|
|
|
mathcursor->handleDelim(l, r);
|
|
|
|
}
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
|
|
|
|
{
|
|
|
|
LyXText * lt = bv->getLyXText();
|
|
|
|
|
|
|
|
bv->beforeChange(lt);
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2001-07-06 12:09:32 +00:00
|
|
|
if (!bv->insertInset(new_inset)) {
|
|
|
|
delete new_inset;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
new_inset->edit(bv, 0, 0, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-07-10 13:17:43 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
} // namespaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
|
|
// returns the nearest enclosing matrix
|
|
|
|
MathArrayInset * matrixpar(int & idx)
|
|
|
|
{
|
|
|
|
idx = 0;
|
|
|
|
return
|
|
|
|
static_cast<MathArrayInset *>
|
|
|
|
(mathcursor ? mathcursor->enclosing(LM_OT_MATRIX, idx) : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
InsetFormulaBase::InsetFormulaBase(MathInset * par)
|
|
|
|
: par_(par)
|
|
|
|
{}
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
InsetFormulaBase::InsetFormulaBase(InsetFormulaBase const & f)
|
2001-06-28 10:25:20 +00:00
|
|
|
: UpdatableInset(f), par_(static_cast<MathInset *>(f.par_->clone()))
|
2001-06-25 00:06:33 +00:00
|
|
|
{}
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
InsetFormulaBase::~InsetFormulaBase()
|
|
|
|
{
|
2001-07-24 05:53:32 +00:00
|
|
|
delete par_;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void InsetFormulaBase::read(Buffer const *, LyXLex & lex)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-06 12:09:32 +00:00
|
|
|
read(lex);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void InsetFormulaBase::write(Buffer const *, ostream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-06 12:09:32 +00:00
|
|
|
write(os);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
int InsetFormulaBase::latex(Buffer const *, ostream & os,
|
|
|
|
bool fragile, bool spacing) const
|
|
|
|
{
|
|
|
|
return latex(os, fragile, spacing);
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
int InsetFormulaBase::ascii(Buffer const *, ostream & os, int spacing) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-06 12:09:32 +00:00
|
|
|
return ascii(os, spacing);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
int InsetFormulaBase::linuxdoc(Buffer const *, ostream & os) const
|
|
|
|
{
|
|
|
|
return linuxdoc(os);
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
int InsetFormulaBase::docBook(Buffer const *, ostream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-06 12:09:32 +00:00
|
|
|
return docBook(os);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
// Check if uses AMS macros
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::validate(LaTeXFeatures &) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
string const InsetFormulaBase::editMessage() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
return _("Math editor mode");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
mathcursor = new MathCursor(this);
|
|
|
|
|
|
|
|
if (!bv->lockInset(this))
|
|
|
|
lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
metrics();
|
2001-07-12 13:19:55 +00:00
|
|
|
//bv->updateInset(this, false);
|
|
|
|
if (x == 0)
|
2001-06-25 00:06:33 +00:00
|
|
|
mathcursor->first();
|
2001-07-12 13:19:55 +00:00
|
|
|
else
|
2001-06-25 00:06:33 +00:00
|
|
|
mathcursor->last();
|
|
|
|
sel_x = 0;
|
|
|
|
sel_y = 0;
|
|
|
|
sel_flag = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
void InsetFormulaBase::edit(BufferView * bv, bool front)
|
|
|
|
{
|
|
|
|
#warning Please have a look if this is right (Jug)
|
|
|
|
edit(bv, front ? 0 : 1, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::insetUnlock(BufferView * bv)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (mathcursor) {
|
2001-07-26 09:01:36 +00:00
|
|
|
if (mathcursor->inMacroMode()) {
|
|
|
|
mathcursor->macroModeClose();
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
delete mathcursor;
|
2001-07-17 09:46:07 +00:00
|
|
|
mathcursor = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
bv->updateInset(this, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->getPos(x, y);
|
2001-06-25 00:06:33 +00:00
|
|
|
x -= par_->xo();
|
|
|
|
y -= par_->yo();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (!mathcursor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (isCursorVisible())
|
|
|
|
bv->hideLockedInsetCursor();
|
|
|
|
else {
|
|
|
|
int x;
|
|
|
|
int y;
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->getPos(x, y);
|
2001-06-25 00:06:33 +00:00
|
|
|
//x -= par_->xo();
|
|
|
|
y -= par_->yo();
|
2001-07-20 14:54:13 +00:00
|
|
|
int asc;
|
|
|
|
int desc;
|
|
|
|
math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, desc);
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->showLockedInsetCursor(x, y, asc, desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleCursorVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (!isCursorVisible()) {
|
|
|
|
if (mathcursor) {
|
|
|
|
int x;
|
|
|
|
int y;
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->getPos(x, y);
|
2001-06-25 00:06:33 +00:00
|
|
|
x -= par_->xo();
|
|
|
|
y -= par_->yo();
|
2001-07-20 14:54:13 +00:00
|
|
|
int asc;
|
|
|
|
int desc;
|
|
|
|
math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, desc);
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->fitLockedInsetCursor(x, y, asc, desc);
|
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
toggleInsetCursor(bv);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::hideInsetCursor(BufferView * bv)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (isCursorVisible())
|
2001-06-28 10:25:20 +00:00
|
|
|
toggleInsetCursor(bv);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::toggleInsetSelection(BufferView * bv)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-17 09:46:07 +00:00
|
|
|
if (mathcursor)
|
|
|
|
bv->updateInset(this, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vector<string> const InsetFormulaBase::getLabelList() const
|
|
|
|
{
|
|
|
|
return std::vector<string>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-17 09:46:07 +00:00
|
|
|
void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-26 06:56:43 +00:00
|
|
|
metrics();
|
2001-07-17 09:46:07 +00:00
|
|
|
bv->updateInset(this, dirty);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
void InsetFormulaBase::metrics() const
|
2001-07-16 15:53:25 +00:00
|
|
|
{
|
2001-07-26 06:56:43 +00:00
|
|
|
const_cast<MathInset *>(par_)->metrics(LM_ST_TEXT);
|
2001-07-16 15:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::insetButtonRelease(BufferView * bv,
|
|
|
|
int x, int y, int /*button*/)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (mathcursor) {
|
2001-06-28 10:25:20 +00:00
|
|
|
hideInsetCursor(bv);
|
2001-06-25 00:06:33 +00:00
|
|
|
x += par_->xo();
|
|
|
|
y += par_->yo();
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->setPos(x, y);
|
2001-06-28 10:25:20 +00:00
|
|
|
showInsetCursor(bv);
|
2001-06-25 00:06:33 +00:00
|
|
|
if (sel_flag) {
|
|
|
|
sel_flag = false;
|
|
|
|
sel_x = 0;
|
|
|
|
sel_y = 0;
|
|
|
|
}
|
2001-07-06 12:09:32 +00:00
|
|
|
bv->updateInset(this, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::insetButtonPress(BufferView * bv,
|
|
|
|
int x, int y, int /*button*/)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
sel_flag = false;
|
|
|
|
sel_x = x;
|
|
|
|
sel_y = y;
|
2001-07-26 09:01:36 +00:00
|
|
|
if (mathcursor && mathcursor->selection()) {
|
|
|
|
mathcursor->selClear();
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->updateInset(this, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::insetMotionNotify(BufferView * bv,
|
|
|
|
int x, int y, int /*button*/)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
|
|
|
|
sel_flag = true;
|
2001-06-28 10:25:20 +00:00
|
|
|
hideInsetCursor(bv);
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->setPos(sel_x + par_->xo(), sel_y + par_->yo());
|
|
|
|
mathcursor->selStart();
|
2001-06-28 10:25:20 +00:00
|
|
|
showInsetCursor(bv);
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->getPos(sel_x, sel_y);
|
2001-06-25 00:06:33 +00:00
|
|
|
} else if (sel_flag) {
|
2001-06-28 10:25:20 +00:00
|
|
|
hideInsetCursor(bv);
|
2001-06-25 00:06:33 +00:00
|
|
|
x += par_->xo();
|
|
|
|
y += par_->yo();
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->setPos(x, y);
|
2001-06-28 10:25:20 +00:00
|
|
|
showInsetCursor(bv);
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->getPos(x, y);
|
2001-06-25 00:06:33 +00:00
|
|
|
if (sel_x != x || sel_y != y)
|
|
|
|
bv->updateInset(this, false);
|
|
|
|
sel_x = x;
|
|
|
|
sel_y = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::insetKeyPress(XKeyEvent *)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-26 09:01:36 +00:00
|
|
|
lyxerr[Debug::MATHED] << "Used InsetFormulaBase::InsetKeyPress." << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-03 07:56:55 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
UpdatableInset::RESULT
|
2001-06-28 10:25:20 +00:00
|
|
|
InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
|
2001-06-25 00:06:33 +00:00
|
|
|
string const & arg)
|
|
|
|
{
|
|
|
|
//lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
|
|
|
|
// << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
|
|
|
|
|
|
|
|
if (!mathcursor)
|
|
|
|
return UNDISPATCHED;
|
|
|
|
|
|
|
|
MathTextCodes varcode = LM_TC_MIN;
|
2001-07-26 09:01:36 +00:00
|
|
|
bool was_macro = mathcursor->inMacroMode();
|
2001-06-25 00:06:33 +00:00
|
|
|
bool sel = false;
|
2001-07-26 09:01:36 +00:00
|
|
|
bool was_selection = mathcursor->selection();
|
2001-06-25 00:06:33 +00:00
|
|
|
RESULT result = DISPATCHED;
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
hideInsetCursor(bv);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
if (mathcursor->getLastCode() == LM_TC_TEX)
|
|
|
|
varcode = LM_TC_TEX;
|
|
|
|
|
|
|
|
mathcursor->normalize();
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
|
|
|
|
// --- Cursor Movements ---------------------------------------------
|
|
|
|
|
|
|
|
case LFUN_RIGHTSEL:
|
|
|
|
sel = true; // fall through...
|
|
|
|
|
|
|
|
case LFUN_RIGHT:
|
2001-07-26 09:01:36 +00:00
|
|
|
result = DISPATCH_RESULT(mathcursor->right(sel));
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case LFUN_LEFTSEL:
|
|
|
|
sel = true; // fall through
|
|
|
|
|
|
|
|
case LFUN_LEFT:
|
2001-07-26 09:01:36 +00:00
|
|
|
result = DISPATCH_RESULT(mathcursor->left(sel));
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case LFUN_UPSEL:
|
|
|
|
sel = true;
|
|
|
|
|
|
|
|
case LFUN_UP:
|
2001-07-26 09:01:36 +00:00
|
|
|
result = DISPATCH_RESULT(mathcursor->up(sel));
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case LFUN_DOWNSEL:
|
|
|
|
sel = true;
|
|
|
|
|
|
|
|
case LFUN_DOWN:
|
2001-07-26 09:01:36 +00:00
|
|
|
result = DISPATCH_RESULT(mathcursor->down(sel));
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_HOME:
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->home();
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_END:
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->end();
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_DELETE_LINE_FORWARD:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::DELETE);
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->delLine();
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_TAB:
|
2001-07-06 12:09:32 +00:00
|
|
|
mathcursor->idxNext();
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, false);
|
2001-07-06 12:09:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_SHIFT_TAB:
|
|
|
|
mathcursor->idxPrev();
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_TABINSERT:
|
2001-07-06 12:09:32 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
|
|
|
mathcursor->splitCell();
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_BACKSPACE:
|
2001-07-26 09:01:36 +00:00
|
|
|
// if (!mathcursor->inMacroMode() && mathcursor->pos() == 0)
|
2001-07-13 14:54:56 +00:00
|
|
|
if (mathcursor->pos() == 0) {
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::DELETE);
|
2001-07-23 14:15:14 +00:00
|
|
|
mathcursor->pullArg(false);
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->updateInset(this, true);
|
|
|
|
break;
|
|
|
|
}
|
2001-07-26 09:01:36 +00:00
|
|
|
if (mathcursor->inMacroMode())
|
|
|
|
mathcursor->left();
|
2001-07-13 16:06:10 +00:00
|
|
|
else
|
|
|
|
mathcursor->plainLeft();
|
2001-06-25 00:06:33 +00:00
|
|
|
// fall through...
|
|
|
|
|
|
|
|
case LFUN_DELETE:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::DELETE);
|
2001-07-23 14:15:14 +00:00
|
|
|
if (mathcursor->pos() == mathcursor->array().size())
|
|
|
|
mathcursor->pullArg(true);
|
|
|
|
else
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->erase();
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->updateInset(this, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// case LFUN_GETXY:
|
|
|
|
// sprintf(dispatch_buffer, "%d %d",);
|
|
|
|
// dispatch_result = dispatch_buffer;
|
|
|
|
// break;
|
|
|
|
case LFUN_SETXY:
|
|
|
|
{
|
|
|
|
lyxerr << "LFUN_SETXY broken!\n";
|
2001-06-29 06:30:53 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int x1;
|
|
|
|
int y1;
|
2001-06-29 11:54:39 +00:00
|
|
|
istringstream is(arg.c_str());
|
2001-06-25 00:06:33 +00:00
|
|
|
is >> x >> y;
|
2001-07-26 06:56:43 +00:00
|
|
|
par_->getXY(x1, y1);
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->setPos(x1 + x, y1 + y);
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case LFUN_PASTE:
|
|
|
|
if (was_macro)
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->macroModeClose();
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->selPaste();
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_CUT:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::DELETE);
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->selCut();
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_COPY:
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->selCopy();
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_HOMESEL:
|
|
|
|
case LFUN_ENDSEL:
|
|
|
|
case LFUN_WORDRIGHTSEL:
|
|
|
|
case LFUN_WORDLEFTSEL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// --- accented characters ------------------------------
|
|
|
|
|
2001-07-26 16:14:23 +00:00
|
|
|
case LFUN_UMLAUT: handleAccent(bv, "ddot"); break;
|
|
|
|
case LFUN_CIRCUMFLEX: handleAccent(bv, "hat"); break;
|
|
|
|
case LFUN_GRAVE: handleAccent(bv, "grave"); break;
|
|
|
|
case LFUN_ACUTE: handleAccent(bv, "acute"); break;
|
|
|
|
case LFUN_TILDE: handleAccent(bv, "tilde"); break;
|
|
|
|
case LFUN_MACRON: handleAccent(bv, "bar"); break;
|
|
|
|
case LFUN_DOT: handleAccent(bv, "dot"); break;
|
|
|
|
case LFUN_CARON: handleAccent(bv, "check"); break;
|
|
|
|
case LFUN_BREVE: handleAccent(bv, "breve"); break;
|
|
|
|
case LFUN_VECTOR: handleAccent(bv, "vec"); break;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
// Greek mode
|
|
|
|
case LFUN_GREEK:
|
|
|
|
if (!greek_kb_flag) {
|
|
|
|
greek_kb_flag = 1;
|
|
|
|
bv->owner()->message(_("Math greek mode on"));
|
|
|
|
} else
|
|
|
|
greek_kb_flag = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Greek keyboard
|
|
|
|
case LFUN_GREEK_TOGGLE:
|
|
|
|
greek_kb_flag = greek_kb_flag ? 0 : 2;
|
|
|
|
if (greek_kb_flag)
|
|
|
|
bv->owner()->message(_("Math greek keyboard on"));
|
|
|
|
else
|
|
|
|
bv->owner()->message(_("Math greek keyboard off"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Math fonts
|
2001-07-03 07:56:55 +00:00
|
|
|
case LFUN_BOLD: handleFont(bv, LM_TC_BF); break;
|
|
|
|
case LFUN_SANS: handleFont(bv, LM_TC_SF); break;
|
|
|
|
case LFUN_EMPH: handleFont(bv, LM_TC_CAL); break;
|
|
|
|
case LFUN_ROMAN: handleFont(bv, LM_TC_RM); break;
|
|
|
|
case LFUN_CODE: handleFont(bv, LM_TC_TT); break;
|
|
|
|
case LFUN_DEFAULT: handleFont(bv, LM_TC_VAR); break;
|
|
|
|
|
|
|
|
case LFUN_MATH_MODE:
|
|
|
|
handleFont(bv, LM_TC_TEXTRM);
|
|
|
|
//bv->owner()->message(_("math text mode toggled"));
|
|
|
|
break;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
#ifndef NO_LATEX
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_TEX:
|
2001-07-26 09:01:36 +00:00
|
|
|
if (!mathcursor->selection()) {
|
2001-07-03 07:56:55 +00:00
|
|
|
mathcursor->handleFont(LM_TC_TEX);
|
|
|
|
//bv->owner()->message(_("TeX mode toggled"));
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2001-06-27 14:10:35 +00:00
|
|
|
#endif
|
2001-07-03 07:56:55 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_MATH_LIMITS:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
if (mathcursor->toggleLimits())
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_MATH_SIZE:
|
|
|
|
if (!arg.empty()) {
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
latexkeys const * l = in_word_set(arg);
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->setSize(MathStyles(l ? l->id : static_cast<unsigned int>(-1)));
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-07-09 10:19:50 +00:00
|
|
|
case LFUN_INSERT_MATRIX:
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!arg.empty()) {
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->interpret("matrix " + arg);
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-07-09 10:19:50 +00:00
|
|
|
case LFUN_INSERT_MATH:
|
|
|
|
if (!arg.empty()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->interpret(arg);
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-07-25 14:15:05 +00:00
|
|
|
case LFUN_MATH_SPACE:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
|
|
|
MathSpaceInset * p = mathcursor->prevSpaceInset();
|
|
|
|
if (p)
|
|
|
|
p->incSpace();
|
|
|
|
else
|
|
|
|
mathcursor->insert(new MathSpaceInset(1));
|
|
|
|
updateLocal(bv, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_MATH_DELIM:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
static const string vdelim("(){}[]./|");
|
2001-07-13 07:55:55 +00:00
|
|
|
//lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
if (arg.empty())
|
|
|
|
break;
|
|
|
|
|
2001-07-23 16:08:41 +00:00
|
|
|
// try to read integers first
|
|
|
|
int ilt = '(';
|
|
|
|
int irt = '.';
|
2001-06-29 11:54:39 +00:00
|
|
|
istringstream is(arg.c_str());
|
2001-07-23 16:08:41 +00:00
|
|
|
is >> ilt >> irt;
|
|
|
|
|
|
|
|
if (!is) { // ok, the beasties are no integers... try something else
|
|
|
|
ilt = '(';
|
|
|
|
irt = '.';
|
|
|
|
|
|
|
|
istringstream is(arg.c_str());
|
|
|
|
string lt;
|
|
|
|
string rt;
|
|
|
|
is >> lt >> rt;
|
|
|
|
//lyxerr << "formulabase::LFUN_MATH_DELIM, lt: '" << lt << "'\n";
|
|
|
|
//lyxerr << "formulabase::LFUN_MATH_DELIM, rt: '" << rt << "'\n";
|
|
|
|
|
|
|
|
if (lt.size() > 1) {
|
|
|
|
latexkeys const * l = in_word_set(lt);
|
|
|
|
if (l)
|
|
|
|
ilt = l->id;
|
|
|
|
} else if (vdelim.find(lt[0]) != string::npos)
|
|
|
|
ilt = lt[0];
|
|
|
|
|
|
|
|
if (rt.size() > 1) {
|
|
|
|
latexkeys const * l = in_word_set(rt);
|
|
|
|
if (l)
|
|
|
|
irt = l->id;
|
|
|
|
} else if (vdelim.find(rt[0]) != string::npos)
|
|
|
|
irt = rt[0];
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-10 13:17:43 +00:00
|
|
|
handleDelim(bv, ilt, irt);
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_PROTECTEDSPACE:
|
2001-07-25 09:32:38 +00:00
|
|
|
//lyxerr << " called LFUN_PROTECTEDSPACE\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
mathcursor->insert(new MathSpaceInset(1));
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_UNDO:
|
|
|
|
bv->owner()->message(_("Invalid action in math mode!"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case LFUN_MATH_HALIGN:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
lyxerr << "handling halign '" << arg << "'\n";
|
|
|
|
int idx;
|
|
|
|
MathArrayInset * p = matrixpar(idx);
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
p->halign(arg.size() ? arg[0] : 'c', p->col(idx));
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_VALIGN:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
lyxerr << "handling valign '" << arg << "'\n";
|
|
|
|
int idx;
|
|
|
|
MathArrayInset * p = matrixpar(idx);
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
p->valign(arg.size() ? arg[0] : 'c');
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_ROW_INSERT:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
int idx;
|
|
|
|
MathArrayInset * p = matrixpar(idx);
|
|
|
|
lyxerr << " calling LFUN_MATH_ROW_INSERT on " << p << endl;
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
p->addRow(p->row(idx));
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_ROW_DELETE:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
int idx;
|
|
|
|
MathArrayInset * p = matrixpar(idx);
|
|
|
|
lyxerr << " calling LFUN_MATH_ROW_DELETE on " << p << endl;
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
p->delRow(p->row(idx));
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_COLUMN_INSERT:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
int idx;
|
|
|
|
MathArrayInset * p = matrixpar(idx);
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
p->addCol(p->col(idx));
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_COLUMN_DELETE:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
int idx;
|
|
|
|
MathArrayInset * p = matrixpar(idx);
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
p->delCol(p->col(idx));
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_EXEC_COMMAND:
|
|
|
|
result = UNDISPATCHED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-06-27 14:10:35 +00:00
|
|
|
if ((action == -1 || action == LFUN_SELFINSERT) && !arg.empty()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
unsigned char c = arg[0];
|
2001-07-17 09:41:34 +00:00
|
|
|
|
|
|
|
lyxerr << "Action: " << action << endl;
|
|
|
|
|
|
|
|
lyxerr << "char: '" << c << "' int: " << int(c) << endl;
|
2001-07-06 12:09:32 +00:00
|
|
|
//owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
|
2001-07-10 13:17:43 +00:00
|
|
|
//lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::INSERT);
|
|
|
|
|
|
|
|
if (c == 0) { // Dead key, do nothing
|
|
|
|
//lyxerr << "deadkey" << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isalpha(c)) {
|
|
|
|
if (mathcursor->getLastCode() == LM_TC_TEX) {
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->macroModeOpen();
|
2001-06-25 00:06:33 +00:00
|
|
|
mathcursor->clearLastCode();
|
|
|
|
varcode = LM_TC_MIN;
|
|
|
|
} else if (!varcode) {
|
2001-07-20 14:54:13 +00:00
|
|
|
MathTextCodes f = mathcursor->getLastCode() ?
|
2001-06-25 00:06:33 +00:00
|
|
|
mathcursor->getLastCode() :
|
|
|
|
mathcursor->nextCode();
|
|
|
|
varcode = MathIsAlphaFont(f) ?
|
|
|
|
static_cast<MathTextCodes>(f) :
|
|
|
|
LM_TC_VAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// lyxerr << "Varcode << vardoce;
|
|
|
|
MathTextCodes 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);
|
|
|
|
|
|
|
|
varcode = LM_TC_MIN;
|
|
|
|
|
|
|
|
if (greek_kb_flag < 2)
|
|
|
|
greek_kb_flag = 0;
|
|
|
|
|
|
|
|
} else if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
|
|
|
|
mathcursor->insert(c, LM_TC_TEX);
|
|
|
|
if (c == '{') {
|
|
|
|
mathcursor->insert('}', LM_TC_TEX);
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->left();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
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)) {
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->macroModeOpen();
|
2001-06-25 00:06:33 +00:00
|
|
|
mathcursor->clearLastCode();
|
|
|
|
mathcursor->insert(c, LM_TC_MIN);
|
|
|
|
} else if (('0' <= c && c <= '9') || strchr(";:!|[]().,?", c)) {
|
2001-06-27 14:10:35 +00:00
|
|
|
MathTextCodes code = mathcursor->getLastCode();
|
|
|
|
if (code != LM_TC_TEXTRM)
|
|
|
|
code = LM_TC_CONST;
|
|
|
|
mathcursor->insert(c, code);
|
2001-06-25 00:06:33 +00:00
|
|
|
} else if (strchr("+/-*<>=", c)) {
|
2001-06-27 14:10:35 +00:00
|
|
|
MathTextCodes code = mathcursor->getLastCode();
|
|
|
|
if (code != LM_TC_TEXTRM)
|
|
|
|
code = LM_TC_BOP;
|
|
|
|
mathcursor->insert(c, code);
|
2001-07-09 10:19:50 +00:00
|
|
|
} else if (strchr(latex_special_chars, c) && c != '_') {
|
2001-06-27 14:10:35 +00:00
|
|
|
MathTextCodes code = mathcursor->getLastCode();
|
|
|
|
if (code != LM_TC_TEXTRM)
|
|
|
|
code = LM_TC_SPECIAL;
|
|
|
|
mathcursor->insert(c, code);
|
2001-06-25 00:06:33 +00:00
|
|
|
} else if (c == '_' || c == '^') {
|
|
|
|
char s[2];
|
|
|
|
s[0] = c;
|
|
|
|
s[1] = 0;
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->interpret(s);
|
2001-07-17 09:46:07 +00:00
|
|
|
} else if (c == ' ') {
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!varcode) {
|
2001-07-17 09:46:07 +00:00
|
|
|
MathTextCodes f = (mathcursor->getLastCode()) ?
|
2001-06-25 00:06:33 +00:00
|
|
|
mathcursor->getLastCode() :
|
|
|
|
mathcursor->nextCode();
|
2001-07-17 09:46:07 +00:00
|
|
|
varcode = MathIsAlphaFont(f) ? f : LM_TC_VAR;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-07-17 09:46:07 +00:00
|
|
|
if (varcode == LM_TC_TEXTRM)
|
2001-06-25 00:06:33 +00:00
|
|
|
mathcursor->insert(c, LM_TC_TEXTRM);
|
2001-07-17 09:46:07 +00:00
|
|
|
else if (was_macro)
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->macroModeClose();
|
2001-07-17 09:46:07 +00:00
|
|
|
else if (mathcursor->pop())
|
2001-06-27 14:10:35 +00:00
|
|
|
mathcursor->plainRight();
|
2001-07-17 09:46:07 +00:00
|
|
|
else {
|
|
|
|
// this would not work if the inset is in an table!
|
|
|
|
//bv->text->cursorRight(bv, true);
|
|
|
|
result = FINISHED;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
} else if (c == '\'' || c == '@') {
|
2001-07-17 09:46:07 +00:00
|
|
|
mathcursor->insert(c, LM_TC_VAR);
|
2001-06-25 00:06:33 +00:00
|
|
|
} else if (c == '\\') {
|
|
|
|
if (was_macro)
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->macroModeClose();
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->owner()->message(_("TeX mode"));
|
|
|
|
mathcursor->setLastCode(LM_TC_TEX);
|
|
|
|
}
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
} else if (action == LFUN_MATH_PANEL) {
|
|
|
|
result = UNDISPATCHED;
|
|
|
|
} else {
|
|
|
|
lyxerr << "Closed by action " << action << endl;
|
|
|
|
result = FINISHED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-09 16:59:57 +00:00
|
|
|
mathcursor->normalize();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
if (was_macro != mathcursor->inMacroMode()
|
2001-07-17 09:46:07 +00:00
|
|
|
&& action >= 0 && action != LFUN_BACKSPACE)
|
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-26 09:01:36 +00:00
|
|
|
if (mathcursor->selection() || was_selection)
|
2001-06-28 10:25:20 +00:00
|
|
|
toggleInsetSelection(bv);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
|
|
|
|
result == UNDISPATCHED)
|
2001-06-28 10:25:20 +00:00
|
|
|
showInsetCursor(bv);
|
2001-06-25 00:06:33 +00:00
|
|
|
else
|
|
|
|
bv->unlockInset(this);
|
|
|
|
|
|
|
|
return result; // original version
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!isalpha(c))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
string tmp;
|
|
|
|
tmp = c;
|
2001-06-28 10:25:20 +00:00
|
|
|
if (!bv->theLockingInset() || bv->theLockingInset()->isTextInset()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
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
|
2001-06-28 10:25:20 +00:00
|
|
|
new_inset->edit(bv, 0, 0, 0);
|
|
|
|
new_inset->localDispatch(bv, LFUN_SELFINSERT, tmp);
|
2001-06-25 00:06:33 +00:00
|
|
|
if (greek_kb_flag_save < 2) {
|
|
|
|
bv->unlockInset(new_inset); // bv->theLockingInset());
|
2001-06-27 14:10:35 +00:00
|
|
|
bv->text->cursorRight(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
} else
|
2001-06-28 10:25:20 +00:00
|
|
|
if (bv->theLockingInset()->lyxCode() == Inset::MATH_CODE ||
|
|
|
|
bv->theLockingInset()->lyxCode() == Inset::MATHMACRO_CODE)
|
|
|
|
static_cast<InsetFormula*>(bv->theLockingInset())->localDispatch(bv, LFUN_SELFINSERT, tmp);
|
2001-06-25 00:06:33 +00:00
|
|
|
else
|
|
|
|
lyxerr << "Math error: attempt to write on a wrong "
|
|
|
|
"class of inset." << endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
Inset::Code InsetFormulaBase::lyxCode() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
return Inset::MATH_CODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
LyXFont const InsetFormulaBase::convertFont(LyXFont const & f) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
// We have already discussed what was here
|
|
|
|
LyXFont font(f);
|
2001-06-27 14:10:35 +00:00
|
|
|
#ifndef NO_LATEX
|
2001-06-25 00:06:33 +00:00
|
|
|
font.setLatex(LyXFont::OFF);
|
2001-06-27 14:10:35 +00:00
|
|
|
#endif
|
2001-06-25 00:06:33 +00:00
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
MathInset * InsetFormulaBase::par() const
|
|
|
|
{
|
|
|
|
return par_;
|
|
|
|
}
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
|
|
|
|
void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
|
|
|
|
{
|
|
|
|
if (bv->available()) {
|
|
|
|
// Feature "Read math inset from selection" disabled.
|
|
|
|
// // use selection if available..
|
|
|
|
// string sel;
|
|
|
|
// if (action == LFUN_MATH_IMPORT_SELECTION)
|
|
|
|
// sel = "";
|
|
|
|
// else
|
|
|
|
// sel = bv->getLyXText()->selectionAsString(bv->buffer());
|
|
|
|
|
|
|
|
InsetFormula * f;
|
|
|
|
// if (sel.empty()) {
|
|
|
|
f = new InsetFormula;
|
2001-07-09 14:19:41 +00:00
|
|
|
if (openNewInset(bv, f)) {
|
|
|
|
// don't do that also for LFUN_MATH_MODE unless you want end up with
|
|
|
|
// always changing to mathrm when opening an inlined inset
|
|
|
|
// -- I really hate "LyXfunc overloading"...
|
|
|
|
if (display)
|
|
|
|
f->localDispatch(bv, LFUN_MATH_DISPLAY, string());
|
|
|
|
f->localDispatch(bv, LFUN_INSERT_MATH, arg);
|
|
|
|
}
|
2001-07-06 12:09:32 +00:00
|
|
|
// } else {
|
|
|
|
// f = new InsetFormula(sel);
|
|
|
|
// bv->getLyXText()->cutSelection(bv);
|
|
|
|
// openNewInset(bv, f);
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void mathDispatchMathDisplay(BufferView * bv, string const & arg)
|
|
|
|
{
|
|
|
|
mathDispatchCreation(bv, arg, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mathDispatchMathMode(BufferView * bv, string const & arg)
|
|
|
|
{
|
|
|
|
mathDispatchCreation(bv, arg, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
|
|
|
|
{
|
|
|
|
mathDispatchCreation(bv, arg, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mathDispatchMathMacro(BufferView * bv, string const & arg)
|
|
|
|
{
|
|
|
|
if (bv->available()) {
|
2001-07-17 09:46:07 +00:00
|
|
|
if (arg.empty())
|
2001-07-06 12:09:32 +00:00
|
|
|
bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
|
|
|
|
else {
|
2001-07-17 09:46:07 +00:00
|
|
|
string s(arg);
|
2001-07-06 12:09:32 +00:00
|
|
|
string const s1 = token(s, ' ', 1);
|
|
|
|
int const na = s1.empty() ? 0 : lyx::atoi(s1);
|
|
|
|
openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mathDispatchMathDelim(BufferView * bv, string const & arg)
|
|
|
|
{
|
|
|
|
if (bv->available()) {
|
|
|
|
if (openNewInset(bv, new InsetFormula))
|
|
|
|
bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
|
|
|
|
{
|
|
|
|
if (bv->available()) {
|
|
|
|
if (openNewInset(bv, new InsetFormula))
|
|
|
|
bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mathDispatchInsertMath(BufferView * bv, string const & arg)
|
|
|
|
{
|
|
|
|
if (bv->available()) {
|
2001-07-17 09:46:07 +00:00
|
|
|
if (arg.size() && arg[0] == '\\')
|
|
|
|
openNewInset(bv, new InsetFormula(arg));
|
|
|
|
else
|
2001-07-09 10:32:44 +00:00
|
|
|
mathDispatchMathMode(bv, arg);
|
2001-07-06 12:09:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|