2001-10-12 13:29:46 +00:00
|
|
|
/*
|
2001-09-13 16:14:43 +00:00
|
|
|
* File: formulabase.C
|
|
|
|
* Purpose: Implementation of common parts of the LyX math insets
|
2001-06-25 00:06:33 +00:00
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: January 1996
|
|
|
|
*
|
|
|
|
* 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"
|
2001-10-12 15:38:58 +00:00
|
|
|
#include "support/LAssert.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
#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 "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"
|
2001-11-08 12:15:12 +00:00
|
|
|
#include "math_support.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
#include "support/lstrings.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "LyXView.h"
|
|
|
|
#include "Painter.h"
|
|
|
|
#include "font.h"
|
2001-11-13 14:49:54 +00:00
|
|
|
#include "math_cursor.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "math_arrayinset.h"
|
|
|
|
#include "math_spaceinset.h"
|
2001-07-27 12:32:29 +00:00
|
|
|
#include "math_macrotable.h"
|
2001-08-15 05:50:39 +00:00
|
|
|
#include "math_factory.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
|
|
|
|
2001-11-13 14:49:54 +00:00
|
|
|
MathCursor * mathcursor = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
|
|
// local global
|
|
|
|
int sel_x;
|
|
|
|
int sel_y;
|
2001-11-20 11:15:18 +00:00
|
|
|
int first_x;
|
|
|
|
int first_y;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-10-31 12:26:42 +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-08-09 15:19:31 +00:00
|
|
|
|
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-08-15 05:50:39 +00:00
|
|
|
mathcursor->insert(createMathInset(name));
|
2001-07-10 13:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
|
|
|
|
{
|
|
|
|
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
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2001-08-01 13:28:45 +00:00
|
|
|
|
2001-08-03 09:54:48 +00:00
|
|
|
InsetFormulaBase::InsetFormulaBase()
|
2001-10-24 09:16:06 +00:00
|
|
|
: view_(0), font_(), xo_(0), yo_(0)
|
2001-07-27 12:32:29 +00:00
|
|
|
{
|
2001-09-09 22:02:19 +00:00
|
|
|
// This is needed as long the math parser is not re-entrant
|
2001-07-27 12:32:29 +00:00
|
|
|
MathMacroTable::builtinMacros();
|
2001-08-03 18:01:09 +00:00
|
|
|
//lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
|
2001-07-27 12:32:29 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-06-28 10:25:20 +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-10-22 15:37:49 +00:00
|
|
|
void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const
|
2001-11-13 15:04:46 +00:00
|
|
|
{
|
|
|
|
font_ = f;
|
|
|
|
metrics(bv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InsetFormulaBase::metrics(BufferView * bv) const
|
2001-10-19 11:25:48 +00:00
|
|
|
{
|
|
|
|
if (bv)
|
|
|
|
view_ = bv;
|
|
|
|
MathMetricsInfo mi(view_, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
|
|
|
|
par()->metrics(mi);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (!bv->lockInset(this))
|
|
|
|
lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
mathcursor = new MathCursor(this, x == 0);
|
2001-10-19 11:25:48 +00:00
|
|
|
metrics(bv);
|
2001-08-14 09:35:44 +00:00
|
|
|
// if that is removed, we won't get the magenta box when entering an
|
|
|
|
// inset for the first time
|
|
|
|
bv->updateInset(this, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
void InsetFormulaBase::edit(BufferView * bv, bool front)
|
|
|
|
{
|
2001-08-14 07:46:11 +00:00
|
|
|
// looks hackish but seems to work
|
2001-07-20 14:18:48 +00:00
|
|
|
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-10-24 09:16:06 +00:00
|
|
|
x += xo_;
|
|
|
|
y += yo_ - 3;
|
|
|
|
//lyxerr << "getCursorPos: " << x << " " << y << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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 {
|
2001-10-31 10:00:43 +00:00
|
|
|
metrics(bv);
|
2001-06-25 00:06:33 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->getPos(x, y);
|
2001-09-03 11:38:04 +00:00
|
|
|
y -= 3;
|
2001-10-24 09:16:06 +00:00
|
|
|
y -= yo_;
|
2001-10-19 17:46:13 +00:00
|
|
|
int asc = 0;
|
|
|
|
int des = 0;
|
2001-11-13 15:04:46 +00:00
|
|
|
MathMetricsInfo mi(bv, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
|
2001-10-19 17:46:13 +00:00
|
|
|
math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
|
2001-09-03 11:38:04 +00:00
|
|
|
bv->showLockedInsetCursor(x, y, asc, des);
|
2001-10-24 09:16:06 +00:00
|
|
|
//lyxerr << "toggleInsetCursor: " << x << " " << y << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toggleCursorVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-11-20 09:06:12 +00:00
|
|
|
if (isCursorVisible())
|
|
|
|
return;
|
|
|
|
if (mathcursor) {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
mathcursor->getPos(x, y);
|
|
|
|
int asc = 0;
|
|
|
|
int des = 0;
|
|
|
|
MathMetricsInfo mi(bv, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
|
|
|
|
math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
|
|
|
|
//bv->fitLockedInsetCursor(x, y, asc, des);
|
|
|
|
//metrics(bv);
|
|
|
|
//lyxerr << "showInsetCursor: " << x << " " << y << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-11-20 09:06:12 +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-10-19 11:25:48 +00:00
|
|
|
metrics(bv);
|
2001-07-17 09:46:07 +00:00
|
|
|
bv->updateInset(this, dirty);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::insetButtonRelease(BufferView * bv,
|
2001-11-20 11:15:18 +00:00
|
|
|
int x, int y, int /*button*/)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-11-20 09:06:12 +00:00
|
|
|
if (!mathcursor)
|
|
|
|
return;
|
2001-11-20 11:15:18 +00:00
|
|
|
//lyxerr << "insetButtonRelease: " << x << " " << y << "\n";
|
2001-11-20 09:06:12 +00:00
|
|
|
hideInsetCursor(bv);
|
|
|
|
showInsetCursor(bv);
|
|
|
|
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
|
|
|
{
|
2001-11-16 13:38:00 +00:00
|
|
|
//lyxerr << "insetButtonPress: " << x + xo_ << " " << y + yo_ << "\n";
|
2001-11-20 11:15:18 +00:00
|
|
|
first_x = x;
|
|
|
|
first_y = y;
|
|
|
|
if (mathcursor) {
|
|
|
|
mathcursor->selClear();
|
|
|
|
mathcursor->setPos(x + xo_, y + yo_);
|
|
|
|
}
|
2001-11-16 13:38:00 +00:00
|
|
|
bv->updateInset(this, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::insetMotionNotify(BufferView * bv,
|
2001-11-20 09:06:12 +00:00
|
|
|
int x, int y, int button)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-11-20 09:06:12 +00:00
|
|
|
if (!mathcursor)
|
|
|
|
return;
|
2001-11-16 13:38:00 +00:00
|
|
|
|
2001-11-20 11:15:18 +00:00
|
|
|
if (abs(x - first_x) < 2 && abs(y - first_y) < 2) {
|
2001-11-20 09:06:12 +00:00
|
|
|
//lyxerr << "insetMotionNotify: ignored\n";
|
|
|
|
return;
|
|
|
|
}
|
2001-11-20 11:15:18 +00:00
|
|
|
first_x = x;
|
|
|
|
first_y = y;
|
|
|
|
|
|
|
|
if (!mathcursor->selection())
|
|
|
|
mathcursor->selStart();
|
2001-11-20 09:06:12 +00:00
|
|
|
|
2001-11-20 11:15:18 +00:00
|
|
|
//lyxerr << "insetMotionNotify: " << x + xo_ << ' ' << y + yo_
|
2001-11-20 09:06:12 +00:00
|
|
|
// << ' ' << button << "\n";
|
2001-11-20 11:15:18 +00:00
|
|
|
hideInsetCursor(bv);
|
|
|
|
mathcursor->setPos(x + xo_, y + yo_);
|
|
|
|
showInsetCursor(bv);
|
|
|
|
bv->updateInset(this, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2001-10-10 16:35:18 +00:00
|
|
|
//lyxerr << "InsetFormulaBase::localDispatch: act: " << action
|
2001-06-25 00:06:33 +00:00
|
|
|
// << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
|
|
|
|
|
|
|
|
if (!mathcursor)
|
|
|
|
return UNDISPATCHED;
|
|
|
|
|
2001-10-24 19:09:31 +00:00
|
|
|
if (mathcursor->asHyperActiveInset()) {
|
|
|
|
lyxerr << " uurr.... getting dificult now\n";
|
|
|
|
return mathcursor->asHyperActiveInset()->localDispatch(bv, action, arg);
|
|
|
|
}
|
|
|
|
|
2001-08-13 14:02:37 +00:00
|
|
|
RESULT result = DISPATCHED;
|
|
|
|
bool sel = false;
|
|
|
|
bool was_macro = mathcursor->inMacroMode();
|
2001-07-26 09:01:36 +00:00
|
|
|
bool was_selection = mathcursor->selection();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
hideInsetCursor(bv);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
mathcursor->normalize();
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
|
|
|
|
// --- Cursor Movements ---------------------------------------------
|
|
|
|
|
|
|
|
case LFUN_RIGHTSEL:
|
|
|
|
sel = true; // fall through...
|
|
|
|
|
|
|
|
case LFUN_RIGHT:
|
2001-08-16 11:57:45 +00:00
|
|
|
result = mathcursor->right(sel) ? DISPATCHED : FINISHED_RIGHT;
|
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-08-16 11:57:45 +00:00
|
|
|
result = mathcursor->left(sel) ? DISPATCHED : FINISHED;
|
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-08-16 11:57:45 +00:00
|
|
|
result = mathcursor->up(sel) ? DISPATCHED : FINISHED_UP;
|
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-08-16 11:57:45 +00:00
|
|
|
result = mathcursor->down(sel) ? DISPATCHED : FINISHED_DOWN;
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
2001-08-30 10:17:28 +00:00
|
|
|
case LFUN_HOMESEL:
|
|
|
|
sel = true;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_HOME:
|
2001-08-30 10:17:28 +00:00
|
|
|
mathcursor->home(sel);
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
2001-08-30 10:17:28 +00:00
|
|
|
case LFUN_ENDSEL:
|
|
|
|
sel = true;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_END:
|
2001-08-30 10:17:28 +00:00
|
|
|
mathcursor->end(sel);
|
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;
|
|
|
|
|
2001-10-23 13:56:10 +00:00
|
|
|
case LFUN_DELETE_WORD_BACKWARD:
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_BACKSPACE:
|
2001-08-07 15:04:57 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::DELETE);
|
|
|
|
mathcursor->backspace();
|
|
|
|
bv->updateInset(this, true);
|
|
|
|
break;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-10-23 13:56:10 +00:00
|
|
|
case LFUN_DELETE_WORD_FORWARD:
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_DELETE:
|
|
|
|
bv->lockedInsetStoreUndo(Undo::DELETE);
|
2001-08-07 15:04:57 +00:00
|
|
|
mathcursor->erase();
|
2001-06-25 00:06:33 +00:00
|
|
|
bv->updateInset(this, true);
|
|
|
|
break;
|
|
|
|
|
2001-11-13 15:29:45 +00:00
|
|
|
// case LFUN_GETXY:
|
|
|
|
// sprintf(dispatch_buffer, "%d %d",);
|
|
|
|
// dispatch_result = dispatch_buffer;
|
|
|
|
// break;
|
2001-08-13 14:02:37 +00:00
|
|
|
case LFUN_SETXY: {
|
2001-06-25 00:06:33 +00:00
|
|
|
lyxerr << "LFUN_SETXY broken!\n";
|
2001-10-24 09:16:06 +00:00
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
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-10-24 09:16:06 +00:00
|
|
|
mathcursor->setPos(x, y);
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, false);
|
2001-08-13 14:02:37 +00:00
|
|
|
break;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_PASTE:
|
|
|
|
if (was_macro)
|
2001-07-26 09:01:36 +00:00
|
|
|
mathcursor->macroModeClose();
|
2001-10-31 12:26:42 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
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_WORDRIGHTSEL:
|
|
|
|
case LFUN_WORDLEFTSEL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// --- accented characters ------------------------------
|
|
|
|
|
2001-08-13 14:02:37 +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;
|
|
|
|
|
|
|
|
// Math fonts
|
|
|
|
case LFUN_GREEK_TOGGLE: handleFont(bv, LM_TC_GREEK); break;
|
|
|
|
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;
|
2001-08-31 21:15:57 +00:00
|
|
|
case LFUN_NOUN: handleFont(bv, LM_TC_BB); break;
|
2001-08-13 14:02:37 +00:00
|
|
|
case LFUN_DEFAULT: handleFont(bv, LM_TC_VAR); break;
|
2001-07-03 07:56:55 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
case LFUN_GREEK:
|
|
|
|
handleFont(bv, LM_TC_GREEK1);
|
|
|
|
if (arg.size())
|
2001-10-23 08:14:52 +00:00
|
|
|
mathcursor->interpret(arg);
|
2001-10-12 12:02:49 +00:00
|
|
|
break;
|
|
|
|
|
2001-07-03 07:56:55 +00:00
|
|
|
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
|
|
|
|
|
|
|
case LFUN_MATH_LIMITS:
|
2001-10-31 12:26:42 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
2001-06-25 00:06:33 +00:00
|
|
|
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:
|
2001-10-23 09:03:07 +00:00
|
|
|
#if 0
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!arg.empty()) {
|
2001-10-31 12:26:42 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
2001-10-23 09:03:07 +00:00
|
|
|
mathcursor->setSize(arg);
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-10-23 09:03:07 +00:00
|
|
|
#endif
|
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()) {
|
2001-10-31 12:26:42 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
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-25 14:15:05 +00:00
|
|
|
case LFUN_MATH_SPACE:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
2001-10-12 12:02:49 +00:00
|
|
|
mathcursor->insert(MathAtom(new MathSpaceInset(1)));
|
2001-07-25 14:15:05 +00:00
|
|
|
updateLocal(bv, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_MATH_DELIM:
|
|
|
|
{
|
2001-07-13 07:55:55 +00:00
|
|
|
//lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
|
2001-08-09 15:19:31 +00:00
|
|
|
string ls;
|
|
|
|
string rs;
|
2001-06-29 11:54:39 +00:00
|
|
|
istringstream is(arg.c_str());
|
2001-08-09 15:19:31 +00:00
|
|
|
is >> ls >> rs;
|
2001-09-12 12:51:55 +00:00
|
|
|
if (!is) {
|
2001-08-09 15:19:31 +00:00
|
|
|
lyxerr << "can't parse delimeters from '" << arg << "'\n";
|
|
|
|
break;
|
2001-07-23 16:08:41 +00:00
|
|
|
}
|
2001-08-09 15:19:31 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
2001-09-12 12:51:55 +00:00
|
|
|
mathcursor->handleDelim(ls, rs);
|
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-10-31 12:26:42 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
2001-10-12 12:02:49 +00:00
|
|
|
mathcursor->insert(MathAtom(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:
|
|
|
|
case LFUN_MATH_VALIGN:
|
|
|
|
case LFUN_MATH_ROW_INSERT:
|
|
|
|
case LFUN_MATH_ROW_DELETE:
|
|
|
|
case LFUN_MATH_COLUMN_INSERT:
|
|
|
|
case LFUN_MATH_COLUMN_DELETE:
|
|
|
|
{
|
2001-10-31 12:26:42 +00:00
|
|
|
MathInset::idx_type idx = 0;
|
2001-11-13 08:21:03 +00:00
|
|
|
MathGridInset * p = mathcursor ? mathcursor->enclosingGrid(idx) : 0;
|
2001-10-31 12:26:42 +00:00
|
|
|
if (p) {
|
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
|
|
|
char al = arg.size() ? arg[0] : 'c';
|
|
|
|
switch (action) {
|
|
|
|
case LFUN_MATH_HALIGN: p->halign(al, p->col(idx)); break;
|
|
|
|
case LFUN_MATH_VALIGN: p->valign(al); break;
|
|
|
|
case LFUN_MATH_ROW_INSERT: p->addRow(p->row(idx)); break;
|
|
|
|
case LFUN_MATH_ROW_DELETE: p->delRow(p->row(idx)); break;
|
|
|
|
case LFUN_MATH_COLUMN_INSERT: p->addCol(p->col(idx)); break;
|
|
|
|
case LFUN_MATH_COLUMN_DELETE: p->delCol(p->col(idx)); break;
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
updateLocal(bv, true);
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_EXEC_COMMAND:
|
|
|
|
result = UNDISPATCHED;
|
|
|
|
break;
|
|
|
|
|
2001-10-24 17:59:35 +00:00
|
|
|
case LFUN_BREAKPARAGRAPH:
|
|
|
|
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
|
|
|
|
//lyxerr << "LFUN ignored\n";
|
|
|
|
break;
|
|
|
|
|
2001-11-12 08:20:30 +00:00
|
|
|
case LFUN_INSET_ERT:
|
|
|
|
// interpret this as if a backslash was typed
|
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
|
|
|
mathcursor->interpret("\\");
|
|
|
|
updateLocal(bv, true);
|
|
|
|
break;
|
|
|
|
|
2001-08-13 14:02:37 +00:00
|
|
|
case -1:
|
|
|
|
case LFUN_INSERT_MATH:
|
|
|
|
case LFUN_SELFINSERT:
|
|
|
|
if (!arg.empty()) {
|
2001-10-31 12:26:42 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
2001-11-13 08:03:52 +00:00
|
|
|
result = mathcursor->interpret(arg) ? DISPATCHED : FINISHED_RIGHT;
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, true);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2001-08-13 14:02:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_MATH_PANEL:
|
|
|
|
result = UNDISPATCHED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-09-13 16:14:43 +00:00
|
|
|
result = UNDISPATCHED;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-10-12 15:38:58 +00:00
|
|
|
lyx::Assert(mathcursor);
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-10-24 09:16:06 +00:00
|
|
|
int InsetFormulaBase::upperY() const
|
|
|
|
{
|
|
|
|
return yo_ - ascent(view_, font_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetFormulaBase::lowerY() const
|
|
|
|
{
|
|
|
|
return yo_ + descent(view_, font_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
|
|
|
|
{
|
|
|
|
if (bv->available()) {
|
2001-08-14 07:46:11 +00:00
|
|
|
// use selection if available..
|
|
|
|
//string sel;
|
|
|
|
//if (action == LFUN_MATH_IMPORT_SELECTION)
|
|
|
|
// sel = "";
|
|
|
|
//else
|
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
string sel = bv->getLyXText()->selectionAsString(bv->buffer(), false);
|
2001-08-14 07:46:11 +00:00
|
|
|
|
|
|
|
InsetFormulaBase * f;
|
|
|
|
if (sel.empty()) {
|
2001-09-24 13:38:52 +00:00
|
|
|
f = new InsetFormula;
|
|
|
|
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-08-14 07:46:11 +00:00
|
|
|
} else {
|
|
|
|
// create a macro if we see "\\newcommand" somewhere, and an ordinary
|
|
|
|
// formula otherwise
|
|
|
|
if (sel.find("\\newcommand") == string::npos)
|
|
|
|
f = new InsetFormula(sel);
|
|
|
|
else
|
|
|
|
f = new InsetFormulaMacro(sel);
|
|
|
|
bv->getLyXText()->cutSelection(bv);
|
|
|
|
openNewInset(bv, f);
|
|
|
|
}
|
2001-07-06 12:09:32 +00:00
|
|
|
}
|
|
|
|
bv->owner()->getLyXFunc()->setMessage(N_("Math editor mode"));
|
|
|
|
}
|
|
|
|
|
2001-08-30 09:35:11 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void mathDispatchMathDisplay(BufferView * bv, string const & arg)
|
|
|
|
{
|
|
|
|
mathDispatchCreation(bv, arg, true);
|
|
|
|
}
|
2001-08-14 07:46:11 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
|
|
|
|
void mathDispatchMathMode(BufferView * bv, string const & arg)
|
|
|
|
{
|
|
|
|
mathDispatchCreation(bv, arg, false);
|
|
|
|
}
|
|
|
|
|
2001-08-14 07:46:11 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void mathDispatchMathImportSelection(BufferView * bv, string const & arg)
|
|
|
|
{
|
|
|
|
mathDispatchCreation(bv, arg, true);
|
|
|
|
}
|
|
|
|
|
2001-08-14 07:46:11 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-14 07:46:11 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-14 07:46:11 +00:00
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
void mathDispatchInsertMath(BufferView * bv, string const & arg)
|
|
|
|
{
|
|
|
|
if (bv->available()) {
|
2001-10-12 14:33:38 +00:00
|
|
|
if (arg.size() && arg[0] == '\\') {
|
|
|
|
InsetFormula * f = new InsetFormula(arg);
|
|
|
|
if (!bv->insertInset(f))
|
|
|
|
delete f;
|
|
|
|
} else
|
2001-07-09 10:32:44 +00:00
|
|
|
mathDispatchMathMode(bv, arg);
|
2001-07-06 12:09:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-30 09:35:11 +00:00
|
|
|
|
|
|
|
void mathDispatchGreek(BufferView * bv, string const & arg)
|
|
|
|
{
|
|
|
|
if (bv->available()) {
|
|
|
|
InsetFormula * f = new InsetFormula;
|
|
|
|
if (openNewInset(bv, f)) {
|
2001-10-12 12:02:49 +00:00
|
|
|
bv->theLockingInset()->localDispatch(bv, LFUN_GREEK, arg);
|
2001-08-30 09:35:11 +00:00
|
|
|
bv->unlockInset(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-24 09:16:06 +00:00
|
|
|
|
2001-11-16 12:00:27 +00:00
|
|
|
void mathDispatch(BufferView *, kb_action, string const &)
|
|
|
|
{}
|