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"
|
2002-02-07 08:19:47 +00:00
|
|
|
#include "Lsstream.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "math_arrayinset.h"
|
2002-03-19 16:55:58 +00:00
|
|
|
#include "math_charinset.h"
|
2001-12-18 12:21:33 +00:00
|
|
|
#include "math_cursor.h"
|
2001-08-15 05:50:39 +00:00
|
|
|
#include "math_factory.h"
|
2001-12-18 12:21:33 +00:00
|
|
|
#include "math_hullinset.h"
|
2002-01-03 09:41:26 +00:00
|
|
|
#include "math_iterator.h"
|
2001-12-18 12:21:33 +00:00
|
|
|
#include "math_macrotable.h"
|
2001-11-20 14:48:25 +00:00
|
|
|
#include "math_parser.h"
|
2002-01-03 09:41:26 +00:00
|
|
|
#include "math_pos.h"
|
2001-12-18 12:21:33 +00:00
|
|
|
#include "math_spaceinset.h"
|
2001-07-06 15:57:54 +00:00
|
|
|
#include "undo_funcs.h"
|
2002-03-18 11:45:53 +00:00
|
|
|
#include "textpainter.h"
|
2002-02-08 09:42:59 +00:00
|
|
|
#include "frontends/Dialogs.h"
|
2002-02-07 08:19:47 +00:00
|
|
|
#include "intl.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
|
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-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";
|
2002-03-19 17:30:41 +00:00
|
|
|
//lyxerr << "sizeof(MathMetricsInfo): " << sizeof(MathMetricsInfo) << "\n";
|
|
|
|
//lyxerr << "sizeof(MathCharInset): " << sizeof(MathCharInset) << "\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
|
|
|
|
2002-02-07 08:19:47 +00:00
|
|
|
// simply scrap this function if you want
|
|
|
|
void InsetFormulaBase::mutateToText()
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
// translate to latex
|
|
|
|
ostringstream os;
|
|
|
|
latex(NULL, os, false, false);
|
|
|
|
string str = os.str();
|
|
|
|
|
|
|
|
// insert this text
|
|
|
|
LyXText * lt = view_->getLyXText();
|
|
|
|
string::const_iterator cit = str.begin();
|
|
|
|
string::const_iterator end = str.end();
|
|
|
|
for (; cit != end; ++cit)
|
|
|
|
view_->owner()->getIntl()->getTrans().TranslateAndInsert(*cit, lt);
|
|
|
|
|
|
|
|
// remove ourselves
|
|
|
|
//view_->owner()->getLyXFunc()->dispatch(LFUN_ESCAPE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const
|
2001-11-13 15:04:46 +00:00
|
|
|
{
|
|
|
|
font_ = f;
|
|
|
|
metrics(bv);
|
|
|
|
}
|
|
|
|
|
2002-01-03 09:41:26 +00:00
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-15 15:26:32 +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;
|
2002-04-15 15:26:32 +00:00
|
|
|
delete mathcursor;
|
|
|
|
mathcursor = new MathCursor(this, true);
|
2002-04-03 13:40:22 +00:00
|
|
|
metrics(bv);
|
2002-04-15 15:26:32 +00:00
|
|
|
mathcursor->setPos(x, y);
|
|
|
|
//lyxerr << "setting pos to " << x << "," << y << "\n";
|
2002-04-22 16:31:14 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2002-04-15 15:26:32 +00:00
|
|
|
if (!bv->lockInset(this))
|
|
|
|
lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
|
|
|
|
delete mathcursor;
|
|
|
|
mathcursor = new MathCursor(this, front);
|
|
|
|
metrics(bv);
|
|
|
|
bv->updateInset(this, false);
|
2001-07-20 14:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-15 21:53:28 +00:00
|
|
|
void InsetFormulaBase::handleFont
|
|
|
|
(BufferView * bv, string const & arg, MathTextCodes t)
|
|
|
|
{
|
|
|
|
if (mathcursor->selection()) {
|
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
|
|
|
updateLocal(bv, true);
|
|
|
|
}
|
|
|
|
mathcursor->handleFont(t);
|
|
|
|
for (string::const_iterator it = arg.begin(); it != arg.end(); ++it)
|
|
|
|
mathcursor->insert(*it);
|
|
|
|
updateLocal(bv, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2002-04-15 15:26:32 +00:00
|
|
|
//x -= xo_;
|
|
|
|
y -= yo_;
|
2001-10-24 09:16:06 +00:00
|
|
|
//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-10-24 09:16:06 +00:00
|
|
|
y -= yo_;
|
2001-10-19 17:46:13 +00:00
|
|
|
int asc = 0;
|
|
|
|
int des = 0;
|
2002-03-19 16:55:58 +00:00
|
|
|
math_font_max_dim(font_, 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) {
|
2001-12-13 14:12:09 +00:00
|
|
|
metrics(bv);
|
2001-11-20 09:06:12 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
mathcursor->getPos(x, y);
|
2001-12-13 14:12:09 +00:00
|
|
|
y -= yo_;
|
2001-11-20 09:06:12 +00:00
|
|
|
int asc = 0;
|
|
|
|
int des = 0;
|
2002-03-19 16:55:58 +00:00
|
|
|
math_font_max_dim(font_, asc, des);
|
2001-12-13 14:12:09 +00:00
|
|
|
bv->fitLockedInsetCursor(x, y, asc, des);
|
2002-01-03 09:41:26 +00:00
|
|
|
//lyxerr << "showInsetCursor: x: " << x << " y: " << y << " yo: " << yo_ << "\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
|
|
|
|
{
|
2002-02-16 15:59:55 +00:00
|
|
|
return vector<string>();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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-12-17 13:33:22 +00:00
|
|
|
bool InsetFormulaBase::insetButtonRelease(BufferView * bv,
|
2002-04-09 14:45:52 +00:00
|
|
|
int /*x*/, int /*y*/, int button)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2002-04-03 13:40:22 +00:00
|
|
|
//lyxerr << "insetButtonRelease: " << x << " " << y << "\n";
|
2002-04-09 14:45:52 +00:00
|
|
|
|
2001-11-20 09:06:12 +00:00
|
|
|
if (!mathcursor)
|
2001-12-17 13:33:22 +00:00
|
|
|
return false;
|
2001-11-20 09:06:12 +00:00
|
|
|
hideInsetCursor(bv);
|
|
|
|
showInsetCursor(bv);
|
|
|
|
bv->updateInset(this, false);
|
2002-04-09 14:45:52 +00:00
|
|
|
|
|
|
|
if (button == 3) {
|
|
|
|
// launch math panel for right mouse button
|
|
|
|
bv->owner()->getDialogs()->showMathPanel();
|
|
|
|
return true;
|
|
|
|
}
|
2001-12-17 13:33:22 +00:00
|
|
|
return false;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFormulaBase::insetButtonPress(BufferView * bv,
|
2001-11-20 14:48:25 +00:00
|
|
|
int x, int y, int button)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2002-04-03 13:40:22 +00:00
|
|
|
//lyxerr << "insetButtonPress: "
|
|
|
|
// << x << " " << y << " but: " << button << "\n";
|
2002-04-24 09:01:03 +00:00
|
|
|
#if 0
|
2001-11-20 14:48:25 +00:00
|
|
|
switch (button) {
|
|
|
|
default:
|
|
|
|
case 1:
|
2002-04-03 13:40:22 +00:00
|
|
|
// left click
|
2002-04-15 15:26:32 +00:00
|
|
|
delete mathcursor;
|
|
|
|
mathcursor = new MathCursor(this, x == 0);
|
|
|
|
metrics(bv);
|
2001-11-20 14:48:25 +00:00
|
|
|
first_x = x;
|
|
|
|
first_y = y;
|
2002-04-03 13:40:22 +00:00
|
|
|
mathcursor->selClear();
|
|
|
|
mathcursor->setPos(x + xo_, y + yo_);
|
2001-11-20 14:48:25 +00:00
|
|
|
break;
|
2001-11-26 11:08:43 +00:00
|
|
|
/*
|
2001-11-20 14:48:25 +00:00
|
|
|
case 2:
|
|
|
|
lyxerr << "insetButtonPress: 2\n";
|
|
|
|
// insert stuff
|
|
|
|
if (mathcursor) {
|
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
|
|
|
MathArray ar;
|
|
|
|
mathcursor->selGet(ar);
|
|
|
|
mathcursor->setPos(x + xo_, y + yo_);
|
|
|
|
string sel =
|
|
|
|
bv->getLyXText()->selectionAsString(bv->buffer(), false);
|
2001-11-20 17:16:21 +00:00
|
|
|
mathed_parse_cell(ar, sel);
|
2001-11-20 14:48:25 +00:00
|
|
|
mathcursor->insert(ar);
|
2002-03-21 17:42:56 +00:00
|
|
|
}
|
2001-11-20 14:48:25 +00:00
|
|
|
break;
|
2001-11-26 11:08:43 +00:00
|
|
|
*/
|
2002-02-08 09:42:59 +00:00
|
|
|
case 3:
|
|
|
|
// launch math panel for right mouse button
|
|
|
|
bv->owner()->getDialogs()->showMathPanel();
|
|
|
|
break;
|
2001-11-20 11:15:18 +00:00
|
|
|
}
|
2002-04-24 09:01:03 +00:00
|
|
|
#else
|
|
|
|
if (button == 1 || !mathcursor) {
|
|
|
|
delete mathcursor;
|
|
|
|
mathcursor = new MathCursor(this, x == 0);
|
|
|
|
metrics(bv);
|
|
|
|
first_x = x;
|
|
|
|
first_y = y;
|
|
|
|
mathcursor->selClear();
|
|
|
|
mathcursor->setPos(x + xo_, y + yo_);
|
|
|
|
}
|
2002-04-24 13:52:04 +00:00
|
|
|
#if 0
|
|
|
|
#warning Never launch a Dialog on "Press" event ONLY on "Release" event!
|
2002-04-24 09:01:03 +00:00
|
|
|
if (button == 3) {
|
|
|
|
// launch math panel for right mouse button
|
|
|
|
bv->owner()->getDialogs()->showMathPanel();
|
|
|
|
}
|
2002-04-24 13:52:04 +00:00
|
|
|
#endif
|
2002-04-24 09:01:03 +00:00
|
|
|
#endif
|
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 14:48:25 +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;
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
if (!mathcursor->selection())
|
2001-11-20 11:15:18 +00:00
|
|
|
mathcursor->selStart();
|
2002-03-21 17:42:56 +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";
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
if (!mathcursor)
|
2001-06-25 00:06:33 +00:00
|
|
|
return UNDISPATCHED;
|
|
|
|
|
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();
|
2002-03-12 14:59:08 +00:00
|
|
|
mathcursor->touch();
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
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;
|
2002-02-13 13:15:15 +00:00
|
|
|
//lyxerr << "calling scroll 20\n";
|
|
|
|
//scroll(bv, 20);
|
2001-07-17 09:46:07 +00:00
|
|
|
updateLocal(bv, false);
|
2002-01-16 14:24:38 +00:00
|
|
|
// write something to the minibuffer
|
|
|
|
//bv->owner()->message(mathcursor->info());
|
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;
|
|
|
|
|
2002-02-08 08:03:38 +00:00
|
|
|
// Special casing for superscript in case of LyX handling
|
|
|
|
// dead-keys:
|
|
|
|
case LFUN_CIRCUMFLEX:
|
|
|
|
if (arg.empty()) {
|
|
|
|
// do superscript if LyX handles
|
|
|
|
// deadkeys
|
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
|
|
|
mathcursor->script(true);
|
|
|
|
updateLocal(bv, true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LFUN_UMLAUT:
|
|
|
|
case LFUN_ACUTE:
|
|
|
|
case LFUN_GRAVE:
|
|
|
|
case LFUN_BREVE:
|
|
|
|
case LFUN_DOT:
|
|
|
|
case LFUN_MACRON:
|
|
|
|
case LFUN_CARON:
|
|
|
|
case LFUN_TILDE:
|
|
|
|
case LFUN_CEDILLA:
|
|
|
|
case LFUN_CIRCLE:
|
|
|
|
case LFUN_UNDERDOT:
|
|
|
|
case LFUN_TIE:
|
|
|
|
case LFUN_OGONEK:
|
|
|
|
case LFUN_HUNG_UMLAUT:
|
|
|
|
break;
|
2001-08-13 14:02:37 +00:00
|
|
|
|
|
|
|
// Math fonts
|
2002-02-01 14:56:49 +00:00
|
|
|
case LFUN_GREEK_TOGGLE: handleFont(bv, arg, LM_TC_GREEK); break;
|
|
|
|
case LFUN_BOLD: handleFont(bv, arg, LM_TC_BF); break;
|
|
|
|
case LFUN_SANS: handleFont(bv, arg, LM_TC_SF); break;
|
|
|
|
case LFUN_EMPH: handleFont(bv, arg, LM_TC_CAL); break;
|
|
|
|
case LFUN_ROMAN: handleFont(bv, arg, LM_TC_RM); break;
|
|
|
|
case LFUN_CODE: handleFont(bv, arg, LM_TC_TT); break;
|
|
|
|
case LFUN_FRAK: handleFont(bv, arg, LM_TC_EUFRAK); break;
|
|
|
|
case LFUN_ITAL: handleFont(bv, arg, LM_TC_IT); break;
|
|
|
|
case LFUN_NOUN: handleFont(bv, arg, LM_TC_BB); break;
|
|
|
|
case LFUN_DEFAULT: handleFont(bv, arg, LM_TC_VAR); break;
|
|
|
|
case LFUN_FREE: handleFont(bv, arg, LM_TC_TEXTRM); break;
|
2001-07-03 07:56:55 +00:00
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
case LFUN_GREEK:
|
2002-02-01 14:56:49 +00:00
|
|
|
handleFont(bv, arg, LM_TC_GREEK1);
|
2001-10-12 12:02:49 +00:00
|
|
|
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:
|
2002-03-07 17:55:39 +00:00
|
|
|
#if 1
|
2002-02-15 14:07:09 +00:00
|
|
|
handleFont(bv, arg, LM_TC_TEXTRM);
|
|
|
|
#endif
|
2002-01-03 18:37:18 +00:00
|
|
|
|
2002-02-15 14:07:09 +00:00
|
|
|
#if 0
|
|
|
|
mathcursor->niceInsert(MathAtom(new MathHullInset(LM_OT_SIMPLE)));
|
|
|
|
updateLocal(bv, true);
|
|
|
|
#endif
|
2002-01-03 18:37:18 +00:00
|
|
|
|
2001-07-03 07:56:55 +00:00
|
|
|
//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-12-12 14:37:59 +00:00
|
|
|
case LFUN_SUPERSCRIPT:
|
|
|
|
case LFUN_SUBSCRIPT:
|
|
|
|
{
|
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
2002-04-18 15:29:27 +00:00
|
|
|
mathcursor->script(action == LFUN_SUPERSCRIPT);
|
2001-12-12 14:37:59 +00:00
|
|
|
updateLocal(bv, true);
|
|
|
|
break;
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LFUN_MATH_DELIM:
|
|
|
|
{
|
2002-04-12 15:12:10 +00:00
|
|
|
//lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
|
2002-04-16 09:57:37 +00:00
|
|
|
string ls;
|
|
|
|
string rs = split(arg, ls, ' ');
|
|
|
|
// Reasonable default values
|
|
|
|
if (ls.empty())
|
|
|
|
ls = '(';
|
|
|
|
if (rs.empty())
|
|
|
|
rs = ')';
|
2002-04-22 16:31:14 +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:
|
2002-04-22 22:31:49 +00:00
|
|
|
case LFUN_MATH_SPACE:
|
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) {
|
2002-03-26 12:38:59 +00:00
|
|
|
mathcursor->popToEnclosingGrid();
|
2001-10-31 12:26:42 +00:00
|
|
|
bv->lockedInsetStoreUndo(Undo::EDIT);
|
2002-03-26 12:38:59 +00:00
|
|
|
char align = arg.size() ? arg[0] : 'c';
|
2001-10-31 12:26:42 +00:00
|
|
|
switch (action) {
|
2002-03-26 12:38:59 +00:00
|
|
|
case LFUN_MATH_HALIGN: p->halign(align, p->col(idx)); break;
|
|
|
|
case LFUN_MATH_VALIGN: p->valign(align); break;
|
2001-10-31 12:26:42 +00:00
|
|
|
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);
|
2002-04-04 10:11:13 +00:00
|
|
|
mathcursor->interpret('\\');
|
2001-11-12 08:20:30 +00:00
|
|
|
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);
|
2002-04-04 10:11:13 +00:00
|
|
|
if (arg.size() == 1)
|
|
|
|
result = mathcursor->interpret(arg[0]) ? DISPATCHED : FINISHED_RIGHT;
|
|
|
|
else
|
|
|
|
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;
|
|
|
|
|
2001-12-14 17:15:56 +00:00
|
|
|
case LFUN_ESCAPE:
|
|
|
|
if (mathcursor->selection())
|
|
|
|
mathcursor->selClear();
|
|
|
|
else
|
|
|
|
result = UNDISPATCHED;
|
|
|
|
break;
|
|
|
|
|
2001-08-13 14:02:37 +00:00
|
|
|
default:
|
2001-09-13 16:14:43 +00:00
|
|
|
result = UNDISPATCHED;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-11-28 13:09:40 +00:00
|
|
|
mathcursor->normalize();
|
2002-03-12 14:59:08 +00:00
|
|
|
mathcursor->touch();
|
2001-11-28 13:09:40 +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);
|
|
|
|
|
2002-02-15 14:07:09 +00:00
|
|
|
revealCodes(bv);
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
return result; // original version
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
void InsetFormulaBase::revealCodes(BufferView * /*bv*/) const
|
2002-02-15 14:07:09 +00:00
|
|
|
{
|
|
|
|
if (!mathcursor)
|
|
|
|
return;
|
|
|
|
#if 0
|
|
|
|
// write something to the minibuffer
|
|
|
|
// translate to latex
|
|
|
|
mathcursor->markInsert();
|
|
|
|
ostringstream os;
|
|
|
|
write(NULL, os);
|
|
|
|
string str = os.str();
|
|
|
|
mathcursor->markErase();
|
|
|
|
string::size_type pos = 0;
|
|
|
|
string res;
|
|
|
|
for (string::iterator it = str.begin(); it != str.end(); ++it) {
|
|
|
|
if (*it == '\n')
|
|
|
|
res += ' ';
|
|
|
|
else if (*it == '\0') {
|
|
|
|
res += " -X- ";
|
|
|
|
pos = it - str.begin();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res += *it;
|
|
|
|
}
|
|
|
|
if (pos > 30)
|
|
|
|
res = res.substr(pos - 30);
|
|
|
|
if (res.size() > 60)
|
|
|
|
res = res.substr(0, 60);
|
|
|
|
bv->owner()->message(res);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-12-05 18:55:45 +00:00
|
|
|
int InsetFormulaBase::ylow() const
|
2001-10-24 09:16:06 +00:00
|
|
|
{
|
|
|
|
return yo_ - ascent(view_, font_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-05 18:55:45 +00:00
|
|
|
int InsetFormulaBase::yhigh() const
|
2001-10-24 09:16:06 +00:00
|
|
|
{
|
|
|
|
return yo_ + descent(view_, font_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-05 18:55:45 +00:00
|
|
|
int InsetFormulaBase::xlow() const
|
|
|
|
{
|
|
|
|
return xo_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetFormulaBase::xhigh() const
|
|
|
|
{
|
|
|
|
return xo_ + width(view_, font_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-24 09:16:06 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2002-01-03 09:41:26 +00:00
|
|
|
bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
|
2002-01-14 16:10:29 +00:00
|
|
|
bool, bool)
|
2002-01-03 09:41:26 +00:00
|
|
|
{
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning pretty ugly
|
|
|
|
#endif
|
|
|
|
static InsetFormulaBase * lastformula = 0;
|
|
|
|
static MathIterator current = MathIterator(ibegin(par().nucleus()));
|
|
|
|
static MathArray ar;
|
|
|
|
static string laststr;
|
|
|
|
|
|
|
|
if (lastformula != this || laststr != str) {
|
|
|
|
//lyxerr << "reset lastformula to " << this << "\n";
|
|
|
|
lastformula = this;
|
|
|
|
laststr = str;
|
2002-03-21 17:42:56 +00:00
|
|
|
current = ibegin(par().nucleus());
|
2002-01-03 09:41:26 +00:00
|
|
|
ar.clear();
|
|
|
|
mathed_parse_cell(ar, str);
|
|
|
|
} else {
|
|
|
|
++current;
|
|
|
|
}
|
|
|
|
//lyxerr << "searching '" << str << "' in " << this << ar << endl;
|
|
|
|
|
|
|
|
for (MathIterator it = current; it != iend(par().nucleus()); ++it) {
|
|
|
|
if (it.cell().matchpart(ar, it.position().pos_)) {
|
|
|
|
mathcursor->setSelection(it.cursor(), ar.size());
|
|
|
|
current = it;
|
|
|
|
it.jump(ar.size());
|
|
|
|
// I guess some of the following can go
|
|
|
|
bv->toggleSelection(true);
|
|
|
|
hideInsetCursor(bv);
|
|
|
|
updateLocal(bv, true);
|
|
|
|
showInsetCursor(bv);
|
|
|
|
metrics(bv);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//lyxerr << "not found!\n";
|
|
|
|
lastformula = 0;
|
|
|
|
// we have to unlock ourself in this function by default!
|
|
|
|
// don't ask me why...
|
|
|
|
bv->unlockInset(this);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetFormulaBase::searchBackward(BufferView * bv, string const & what,
|
2002-01-14 16:10:29 +00:00
|
|
|
bool a, bool b)
|
2002-01-03 09:41:26 +00:00
|
|
|
{
|
|
|
|
lyxerr << "searching backward not implemented in mathed" << endl;
|
|
|
|
return searchForward(bv, what, a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
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
|
2002-03-27 16:13:52 +00:00
|
|
|
if (sel.find("\\newcommand") == string::npos &&
|
|
|
|
sel.find("\\def") == string::npos)
|
2001-08-14 07:46:11 +00:00
|
|
|
f = new InsetFormula(sel);
|
2002-02-01 17:01:30 +00:00
|
|
|
else {
|
|
|
|
string name;
|
|
|
|
if (!mathed_parse_macro(name, sel))
|
|
|
|
return;
|
2001-08-14 07:46:11 +00:00
|
|
|
f = new InsetFormulaMacro(sel);
|
2002-02-01 17:01:30 +00:00
|
|
|
}
|
2001-08-14 07:46:11 +00:00
|
|
|
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
|
|
|
|
2002-03-21 17:42:56 +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 {
|
2002-03-25 12:11:25 +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)
|
2001-12-03 16:24:50 +00:00
|
|
|
{
|
2002-03-21 17:42:56 +00:00
|
|
|
if (bv->available()) {
|
2001-07-06 12:09:32 +00:00
|
|
|
if (openNewInset(bv, new InsetFormula))
|
|
|
|
bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
}
|
2001-07-06 12:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
|
2002-03-21 17:42:56 +00:00
|
|
|
{
|
|
|
|
if (bv->available()) {
|
2001-07-06 12:09:32 +00:00
|
|
|
if (openNewInset(bv, new InsetFormula))
|
|
|
|
bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
}
|
2001-07-06 12:09:32 +00:00
|
|
|
|
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;
|
2002-04-22 16:31:14 +00:00
|
|
|
else if (!mathcursor) // hotfix
|
2002-04-15 08:50:20 +00:00
|
|
|
bv->getLyXText()->cursorRight(bv);
|
|
|
|
} else {
|
2001-07-09 10:32:44 +00:00
|
|
|
mathDispatchMathMode(bv, arg);
|
2002-04-15 08:50:20 +00:00
|
|
|
}
|
2001-07-06 12:09:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-30 09:35:11 +00:00
|
|
|
|
|
|
|
void mathDispatchGreek(BufferView * bv, string const & arg)
|
2002-03-21 17:42:56 +00:00
|
|
|
{
|
|
|
|
if (bv->available()) {
|
2001-08-30 09:35:11 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
}
|
2001-08-30 09:35:11 +00:00
|
|
|
|
2001-10-24 09:16:06 +00:00
|
|
|
|
2001-11-16 12:00:27 +00:00
|
|
|
void mathDispatch(BufferView *, kb_action, string const &)
|
2002-03-21 17:42:56 +00:00
|
|
|
{}
|