2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
|
* \file InsetMathNest.C
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2001-08-03 17:10:22 +00:00
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathNest.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathArray.h"
|
|
|
|
|
#include "InsetMathBig.h"
|
|
|
|
|
#include "InsetMathBox.h"
|
|
|
|
|
#include "InsetMathBrace.h"
|
|
|
|
|
#include "InsetMathColor.h"
|
|
|
|
|
#include "InsetMathComment.h"
|
|
|
|
|
#include "MathData.h"
|
|
|
|
|
#include "InsetMathDelim.h"
|
|
|
|
|
#include "MathFactory.h"
|
|
|
|
|
#include "InsetMathHull.h"
|
|
|
|
|
#include "MathMLStream.h"
|
|
|
|
|
#include "MathMacroArgument.h"
|
|
|
|
|
//#include "InsetMathMBox.h"
|
|
|
|
|
#include "MathParser.h"
|
|
|
|
|
#include "InsetMathScript.h"
|
|
|
|
|
#include "InsetMathSpace.h"
|
|
|
|
|
#include "InsetMathSymbol.h"
|
|
|
|
|
#include "MathSupport.h"
|
|
|
|
|
#include "InsetMathUnknown.h"
|
|
|
|
|
#include "InsetMathRef.h"
|
2004-01-30 11:41:12 +00:00
|
|
|
|
|
2002-08-22 07:06:02 +00:00
|
|
|
|
#include "BufferView.h"
|
2004-04-18 07:34:15 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2004-03-18 13:57:20 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2004-04-07 18:15:29 +00:00
|
|
|
|
#include "LColor.h"
|
2004-01-30 11:41:12 +00:00
|
|
|
|
#include "bufferview_funcs.h"
|
2004-11-30 01:59:49 +00:00
|
|
|
|
#include "coordcache.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#include "cursor.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include "debug.h"
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-09-16 09:01:15 +00:00
|
|
|
|
#include "funcrequest.h"
|
2004-01-30 11:41:12 +00:00
|
|
|
|
#include "gettext.h"
|
2006-10-13 16:44:44 +00:00
|
|
|
|
#include "lyxtext.h"
|
2004-04-07 18:15:29 +00:00
|
|
|
|
#include "outputparams.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "undo.h"
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
2002-06-14 10:48:27 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
Split clipboard and X selection
* src/LyXAction.C
(LyXAction::init): handle new LFUN_CLIPBOARD_PASTE
* src/insets/insettabular.C
(InsetTabular::doDispatch): ditto
* src/insets/insetbox.C
(InsetBox::doDispatch): ditto
* src/insets/insetert.C
(InsetERT::doDispatch): ditto
(InsetERT::getStatus): ditto
* src/insets/insetcharstyle.C
(InsetCharStyle::doDispatch): ditto
* src/BufferView_pimpl.C
(BufferView::Pimpl::selectionRequest): stuff selection, not clipboard
* src/mathed/math_nestinset.C
(MathNestInset::lfunMousePress): get stuff selection, not clipboard
(MathNestInset::lfunMouseRelease): clipboard -> selection in
commented code
* src/CutAndPaste.C
(cutSelection): ditto
* src/frontends/{qt3,gtk}/GuiImplementation.C
(GuiImplementation::newWorkArea): create new selection, not clipboard,
since the clipboard is now an object
(GuiImplementation::destroyWorkArea): destroy selection, not clipboard
* src/frontends/{qt4,qt3,gtk}/GuiSelection.h: new, copied from
GuiClipboard.h
* src/frontends/{qt4,qt3,gtk}/GuiSelection.C: new, copied from
GuiClipboard.C
* src/frontends/{qt3,gtk}/GuiImplementation.h
(selection): new accessor for selection_
(selection_): new, the global selection object
* src/frontends/{qt4,qt3,gtk}/Makefile.am: add GuiSelection.C and
GuiSelection.h
* src/frontends/{qt4,qt3,gtk}/GuiClipboard.C
(GuiClipboard::get): return clipboard, not selection
(GuiClipboard::put): stuff clipboard, not selection
* src/frontends/{qt4,qt3,gtk}/GuiClipboard.h
(haveSelection): remove (this is now in GuiSelection)
* src/frontends/{qt3,gtk}/GuiClipboard.h
(old_work_area_): remove, since it is not needed anymore
* src/frontends/gtk/ghelpers.C
(getGTKStockIcon): handle LFUN_CLIPBOARD_PASTE
* src/frontends/Clipboard.h
(haveSelection): remove (this is now in Selection)
* src/frontends/qt4/GuiImplementation.[Ch]
(GuiImplementation::selection): new accessor for selection_
* src/frontends/Gui.h
(selection): New accessor for the global selection object
* src/frontends/Selection.h; new, copied from Clipboard.h
* src/frontends/Makefile.am: add Selection.h
* src/text3.C
(various): s/clipboard().haveSelection/selection().haveSelection/
(LyXText::dispatch): handle LFUN_CLIPBOARD_PASTE
(LyXText::getStatus): ditto
* src/lfuns.h: new lfun LFUN_CLIPBOARD_PASTE
* lib/ui/stdmenus.ui: add new lfun LFUN_CLIPBOARD_PASTE
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14408 a592a061-630c-0410-9148-cb99ea01b6c8
2006-07-10 11:32:25 +00:00
|
|
|
|
#include "frontends/Selection.h"
|
2006-01-27 22:24:37 +00:00
|
|
|
|
#include "frontends/nullpainter.h"
|
2001-08-03 17:10:22 +00:00
|
|
|
|
|
2006-09-29 22:06:28 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "lyxserver.h"
|
|
|
|
|
#include "lyxsocket.h"
|
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
|
|
|
|
|
2006-10-15 22:32:56 +00:00
|
|
|
|
using lyx::CoordCache;
|
2006-10-11 19:40:50 +00:00
|
|
|
|
using lyx::docstring;
|
2006-10-15 22:32:56 +00:00
|
|
|
|
using lyx::Point;
|
|
|
|
|
|
2004-04-18 07:34:15 +00:00
|
|
|
|
using lyx::cap::copySelection;
|
|
|
|
|
using lyx::cap::grabAndEraseSelection;
|
|
|
|
|
using lyx::cap::cutSelection;
|
|
|
|
|
using lyx::cap::replaceSelection;
|
|
|
|
|
using lyx::cap::selClearOrDel;
|
2001-08-03 17:10:22 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::istringstream;
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathNest::InsetMathNest(idx_type nargs)
|
2003-05-28 13:22:36 +00:00
|
|
|
|
: cells_(nargs), lock_(false)
|
2001-08-08 17:26:30 +00:00
|
|
|
|
{}
|
2001-08-03 17:10:22 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMath::idx_type InsetMathNest::nargs() const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
return cells_.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
MathArray & InsetMathNest::cell(idx_type i)
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return cells_[i];
|
2001-08-03 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
MathArray const & InsetMathNest::cell(idx_type i) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
return cells_[i];
|
2001-08-03 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-17 16:23:27 +00:00
|
|
|
|
void InsetMathNest::cursorPos(BufferView const & bv,
|
|
|
|
|
CursorSlice const & sl, bool /*boundary*/,
|
|
|
|
|
int & x, int & y) const
|
2004-11-30 01:59:49 +00:00
|
|
|
|
{
|
|
|
|
|
// FIXME: This is a hack. Ideally, the coord cache should not store
|
|
|
|
|
// absolute positions, but relative ones. This would mean to call
|
|
|
|
|
// setXY() not in MathArray::draw(), but in the parent insets' draw()
|
|
|
|
|
// with the correctly adjusted x,y values. But this means that we'd have
|
|
|
|
|
// to touch all (math)inset's draw() methods. Right now, we'll store
|
|
|
|
|
// absolute value, and make them here relative, only to make them
|
|
|
|
|
// absolute again when actually drawing the cursor. What a mess.
|
|
|
|
|
BOOST_ASSERT(ptr_cmp(&sl.inset(), this));
|
|
|
|
|
MathArray const & ar = sl.cell();
|
2006-10-17 16:23:27 +00:00
|
|
|
|
CoordCache const & coord_cache = bv.coordCache();
|
2006-10-13 16:44:44 +00:00
|
|
|
|
if (!coord_cache.getArrays().has(&ar)) {
|
2005-01-31 16:29:48 +00:00
|
|
|
|
// this can (semi-)legally happen if we just created this cell
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// and it never has been drawn before. So don't ASSERT.
|
|
|
|
|
//lyxerr << "no cached data for array " << &ar << endl;
|
|
|
|
|
x = 0;
|
|
|
|
|
y = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2006-10-13 16:44:44 +00:00
|
|
|
|
Point const pt = coord_cache.getArrays().xy(&ar);
|
|
|
|
|
if (!coord_cache.getInsets().has(this)) {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// same as above
|
|
|
|
|
//lyxerr << "no cached data for inset " << this << endl;
|
|
|
|
|
x = 0;
|
|
|
|
|
y = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2006-10-13 16:44:44 +00:00
|
|
|
|
Point const pt2 = coord_cache.getInsets().xy(this);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
//lyxerr << "retrieving position cache for MathArray "
|
|
|
|
|
// << pt.x_ << ' ' << pt.y_ << std::endl;
|
|
|
|
|
x = pt.x_ - pt2.x_ + ar.pos2x(sl.pos());
|
|
|
|
|
y = pt.y_ - pt2.y_;
|
|
|
|
|
// lyxerr << "pt.y_ : " << pt.y_ << " pt2_.y_ : " << pt2.y_
|
|
|
|
|
// << " asc: " << ascent() << " des: " << descent()
|
|
|
|
|
// << " ar.asc: " << ar.ascent() << " ar.des: " << ar.descent() << endl;
|
2002-07-16 18:22:45 +00:00
|
|
|
|
// move cursor visually into empty cells ("blue rectangles");
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (ar.empty())
|
2002-07-16 18:22:45 +00:00
|
|
|
|
x += 2;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-04 22:11:53 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::metrics(MetricsInfo const & mi) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2003-03-21 14:20:48 +00:00
|
|
|
|
MetricsInfo m = mi;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
for (idx_type i = 0, n = nargs(); i != n; ++i)
|
2002-08-02 14:29:42 +00:00
|
|
|
|
cell(i).metrics(m);
|
2001-08-03 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::idxNext(LCursor & cur) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
|
2004-02-03 14:29:00 +00:00
|
|
|
|
if (cur.idx() == cur.lastidx())
|
2001-08-03 17:10:22 +00:00
|
|
|
|
return false;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
++cur.idx();
|
|
|
|
|
cur.pos() = 0;
|
2001-08-03 17:10:22 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::idxRight(LCursor & cur) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2004-01-16 12:36:23 +00:00
|
|
|
|
return idxNext(cur);
|
2001-08-03 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::idxPrev(LCursor & cur) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
|
2004-01-15 17:34:44 +00:00
|
|
|
|
if (cur.idx() == 0)
|
2001-08-03 17:10:22 +00:00
|
|
|
|
return false;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
--cur.idx();
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2001-08-03 17:10:22 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::idxLeft(LCursor & cur) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2004-01-16 12:36:23 +00:00
|
|
|
|
return idxPrev(cur);
|
2001-08-03 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::idxFirst(LCursor & cur) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
|
2001-08-03 17:10:22 +00:00
|
|
|
|
if (nargs() == 0)
|
|
|
|
|
return false;
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.idx() = 0;
|
|
|
|
|
cur.pos() = 0;
|
2001-08-03 17:10:22 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::idxLast(LCursor & cur) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
|
2001-08-03 17:10:22 +00:00
|
|
|
|
if (nargs() == 0)
|
|
|
|
|
return false;
|
2004-02-03 14:29:00 +00:00
|
|
|
|
cur.idx() = cur.lastidx();
|
2004-01-15 17:34:44 +00:00
|
|
|
|
cur.pos() = cur.lastpos();
|
2001-08-03 17:10:22 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::dump() const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2001-11-09 08:35:57 +00:00
|
|
|
|
WriteStream os(lyxerr);
|
2001-10-19 11:25:48 +00:00
|
|
|
|
os << "---------------------------------------------\n";
|
|
|
|
|
write(os);
|
|
|
|
|
os << "\n";
|
2004-11-30 01:59:49 +00:00
|
|
|
|
for (idx_type i = 0, n = nargs(); i != n; ++i)
|
2001-10-19 11:25:48 +00:00
|
|
|
|
os << cell(i) << "\n";
|
|
|
|
|
os << "---------------------------------------------\n";
|
2001-08-03 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::draw(PainterInfo & pi, int x, int y) const
|
2002-06-14 10:48:27 +00:00
|
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
|
#if 0
|
2002-06-14 12:24:28 +00:00
|
|
|
|
if (lock_)
|
2002-06-14 10:48:27 +00:00
|
|
|
|
pi.pain.fillRectangle(x, y - ascent(), width(), height(),
|
|
|
|
|
LColor::mathlockbg);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
#endif
|
2004-04-07 16:54:15 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2002-06-14 10:48:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::drawSelection(PainterInfo & pi, int x, int y) const
|
2002-07-26 17:23:44 +00:00
|
|
|
|
{
|
2006-10-13 16:44:44 +00:00
|
|
|
|
BufferView & bv = *pi.base.bv;
|
2004-02-02 17:32:56 +00:00
|
|
|
|
// this should use the x/y values given, not the cached values
|
2006-10-13 16:44:44 +00:00
|
|
|
|
LCursor & cur = bv.cursor();
|
2004-02-02 17:32:56 +00:00
|
|
|
|
if (!cur.selection())
|
|
|
|
|
return;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (!ptr_cmp(&cur.inset(), this))
|
2004-02-02 17:32:56 +00:00
|
|
|
|
return;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
2006-01-27 22:24:37 +00:00
|
|
|
|
// FIXME: hack to get position cache warm
|
2006-06-20 08:39:16 +00:00
|
|
|
|
static lyx::frontend::NullPainter nop;
|
2006-01-27 22:24:37 +00:00
|
|
|
|
PainterInfo pinop(pi);
|
|
|
|
|
pinop.pain = nop;
|
|
|
|
|
draw(pinop, x, y);
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
CursorSlice s1 = cur.selBegin();
|
|
|
|
|
CursorSlice s2 = cur.selEnd();
|
2006-10-13 16:44:44 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
//lyxerr << "InsetMathNest::drawing selection: "
|
2004-04-20 08:44:30 +00:00
|
|
|
|
// << " s1: " << s1 << " s2: " << s2 << endl;
|
2004-02-02 17:32:56 +00:00
|
|
|
|
if (s1.idx() == s2.idx()) {
|
2004-02-11 14:45:44 +00:00
|
|
|
|
MathArray const & c = cell(s1.idx());
|
2006-10-13 16:44:44 +00:00
|
|
|
|
int x1 = c.xo(bv) + c.pos2x(s1.pos());
|
|
|
|
|
int y1 = c.yo(bv) - c.ascent();
|
|
|
|
|
int x2 = c.xo(bv) + c.pos2x(s2.pos());
|
|
|
|
|
int y2 = c.yo(bv) + c.descent();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
|
2006-09-16 18:11:38 +00:00
|
|
|
|
//lyxerr << "InsetMathNest::drawing selection 3: "
|
2004-04-18 07:34:15 +00:00
|
|
|
|
// << " x1: " << x1 << " x2: " << x2
|
2004-04-20 08:44:30 +00:00
|
|
|
|
// << " y1: " << y1 << " y2: " << y2 << endl;
|
2002-07-26 17:23:44 +00:00
|
|
|
|
} else {
|
2002-08-02 13:35:05 +00:00
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i) {
|
2004-02-02 17:32:56 +00:00
|
|
|
|
if (idxBetween(i, s1.idx(), s2.idx())) {
|
2002-08-02 14:29:42 +00:00
|
|
|
|
MathArray const & c = cell(i);
|
2006-10-13 16:44:44 +00:00
|
|
|
|
int x1 = c.xo(bv);
|
|
|
|
|
int y1 = c.yo(bv) - c.ascent();
|
|
|
|
|
int x2 = c.xo(bv) + c.width();
|
|
|
|
|
int y2 = c.yo(bv) + c.descent();
|
2004-02-11 14:45:44 +00:00
|
|
|
|
pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
|
2002-08-02 13:35:05 +00:00
|
|
|
|
}
|
2002-07-26 17:23:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::validate(LaTeXFeatures & features) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2001-09-26 16:52:34 +00:00
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2001-08-03 17:10:22 +00:00
|
|
|
|
cell(i).validate(features);
|
|
|
|
|
}
|
2001-10-24 09:16:06 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::replace(ReplaceData & rep)
|
2001-11-16 09:55:37 +00:00
|
|
|
|
{
|
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
|
|
|
|
cell(i).replace(rep);
|
|
|
|
|
}
|
2002-02-01 17:01:30 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::contains(MathArray const & ar) const
|
2002-02-01 17:01:30 +00:00
|
|
|
|
{
|
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
|
|
|
|
if (cell(i).contains(ar))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2002-02-11 15:55:13 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::lock() const
|
2002-05-30 07:09:54 +00:00
|
|
|
|
{
|
|
|
|
|
return lock_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::lock(bool l)
|
2002-05-30 07:09:54 +00:00
|
|
|
|
{
|
|
|
|
|
lock_ = l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::isActive() const
|
2002-05-30 07:09:54 +00:00
|
|
|
|
{
|
2002-06-14 10:48:27 +00:00
|
|
|
|
return nargs() > 0;
|
2002-05-30 07:09:54 +00:00
|
|
|
|
}
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
MathArray InsetMathNest::glue() const
|
2002-06-18 15:44:30 +00:00
|
|
|
|
{
|
|
|
|
|
MathArray ar;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
for (size_t i = 0; i < nargs(); ++i)
|
2002-07-30 13:56:02 +00:00
|
|
|
|
ar.append(cell(i));
|
2002-06-18 15:44:30 +00:00
|
|
|
|
return ar;
|
|
|
|
|
}
|
2002-06-27 18:12:50 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::write(WriteStream & os) const
|
2002-08-01 15:53:46 +00:00
|
|
|
|
{
|
|
|
|
|
os << '\\' << name().c_str();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
for (size_t i = 0; i < nargs(); ++i)
|
2002-08-01 15:53:46 +00:00
|
|
|
|
os << '{' << cell(i) << '}';
|
2002-08-02 14:29:42 +00:00
|
|
|
|
if (nargs() == 0)
|
2002-08-22 10:04:11 +00:00
|
|
|
|
os.pendingSpace(true);
|
|
|
|
|
if (lock_ && !os.latex()) {
|
|
|
|
|
os << "\\lyxlock";
|
|
|
|
|
os.pendingSpace(true);
|
|
|
|
|
}
|
2002-08-01 15:53:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::normalize(NormalStream & os) const
|
2002-08-01 15:53:46 +00:00
|
|
|
|
{
|
|
|
|
|
os << '[' << name().c_str();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
for (size_t i = 0; i < nargs(); ++i)
|
2002-08-01 15:53:46 +00:00
|
|
|
|
os << ' ' << cell(i);
|
|
|
|
|
os << ']';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
int InsetMathNest::latex(Buffer const &, std::ostream & os,
|
2004-04-07 18:15:29 +00:00
|
|
|
|
OutputParams const & runparams) const
|
|
|
|
|
{
|
|
|
|
|
WriteStream wi(os, runparams.moving_arg, true);
|
|
|
|
|
write(wi);
|
|
|
|
|
return wi.line();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::notifyCursorLeaves(LCursor & /*cur*/)
|
2002-10-29 08:23:32 +00:00
|
|
|
|
{
|
2004-04-29 14:49:02 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2004-04-08 15:03:33 +00:00
|
|
|
|
#warning look here
|
2004-04-29 14:49:02 +00:00
|
|
|
|
#endif
|
2004-04-08 15:03:33 +00:00
|
|
|
|
#if 0
|
2004-04-05 16:31:52 +00:00
|
|
|
|
MathArray & ar = cur.cell();
|
|
|
|
|
// remove base-only "scripts"
|
2004-04-18 07:34:15 +00:00
|
|
|
|
for (pos_type i = 0; i + 1 < ar.size(); ++i) {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathScript * p = operator[](i).nucleus()->asScriptInset();
|
2004-04-08 15:03:33 +00:00
|
|
|
|
if (p && p->nargs() == 1) {
|
2004-04-05 16:31:52 +00:00
|
|
|
|
MathArray ar = p->nuc();
|
|
|
|
|
erase(i);
|
|
|
|
|
insert(i, ar);
|
2004-04-08 15:03:33 +00:00
|
|
|
|
cur.adjust(i, ar.size() - 1);
|
2004-04-05 16:31:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// glue adjacent font insets of the same kind
|
|
|
|
|
for (pos_type i = 0; i + 1 < size(); ++i) {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathFont * p = operator[](i).nucleus()->asFontInset();
|
|
|
|
|
InsetMathFont const * q = operator[](i + 1)->asFontInset();
|
2004-04-05 16:31:52 +00:00
|
|
|
|
if (p && q && p->name() == q->name()) {
|
|
|
|
|
p->cell(0).append(q->cell(0));
|
|
|
|
|
erase(i + 1);
|
2004-04-08 15:03:33 +00:00
|
|
|
|
cur.adjust(i, -1);
|
2004-04-05 16:31:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-04-08 15:03:33 +00:00
|
|
|
|
#endif
|
2006-08-17 21:32:04 +00:00
|
|
|
|
return false;
|
2002-10-29 08:23:32 +00:00
|
|
|
|
}
|
2002-08-15 10:02:53 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::handleFont
|
2004-01-30 11:41:12 +00:00
|
|
|
|
(LCursor & cur, string const & arg, string const & font)
|
|
|
|
|
{
|
|
|
|
|
// this whole function is a hack and won't work for incremental font
|
|
|
|
|
// changes...
|
2004-03-08 21:14:45 +00:00
|
|
|
|
recordUndo(cur, Undo::ATOMIC);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
if (cur.inset().asInsetMath()->name() == font)
|
2004-01-30 11:41:12 +00:00
|
|
|
|
cur.handleFont(font);
|
|
|
|
|
else {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.handleNest(createInsetMath(font));
|
2004-01-30 11:41:12 +00:00
|
|
|
|
cur.insert(arg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::handleFont2(LCursor & cur, string const & arg)
|
2004-01-30 11:41:12 +00:00
|
|
|
|
{
|
2004-03-08 21:14:45 +00:00
|
|
|
|
recordUndo(cur, Undo::ATOMIC);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
LyXFont font;
|
|
|
|
|
bool b;
|
|
|
|
|
bv_funcs::string2font(arg, font, b);
|
|
|
|
|
if (font.color() != LColor::inherit) {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
MathAtom at = MathAtom(new InsetMathColor(true, font.color()));
|
2005-06-17 14:35:19 +00:00
|
|
|
|
cur.handleNest(at, 0);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd)
|
2002-08-15 10:02:53 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
//lyxerr << "InsetMathNest: request: " << cmd << std::endl;
|
2004-02-27 09:18:03 +00:00
|
|
|
|
//CursorSlice sl = cur.current();
|
2002-08-15 10:02:53 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
switch (cmd.action) {
|
2002-08-15 10:02:53 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
case LFUN_PASTE: {
|
2004-04-20 08:44:30 +00:00
|
|
|
|
recordUndo(cur);
|
2006-09-11 08:54:10 +00:00
|
|
|
|
cur.message(_("Paste"));
|
2004-04-18 07:34:15 +00:00
|
|
|
|
replaceSelection(cur);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
size_t n = 0;
|
2006-09-01 15:41:38 +00:00
|
|
|
|
istringstream is(lyx::to_utf8(cmd.argument()));
|
2004-01-30 11:41:12 +00:00
|
|
|
|
is >> n;
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring const selection = lyx::cap::getSelection(cur.buffer(), n);
|
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
cur.niceInsert(lyx::to_utf8(selection));
|
2004-04-18 07:34:15 +00:00
|
|
|
|
cur.clearSelection(); // bug 393
|
|
|
|
|
cur.bv().switchKeyMap();
|
|
|
|
|
finishUndo();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
}
|
2004-04-18 07:34:15 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_CUT:
|
2005-09-26 11:14:59 +00:00
|
|
|
|
recordUndo(cur);
|
2004-04-18 07:34:15 +00:00
|
|
|
|
cutSelection(cur, true, true);
|
2006-09-11 08:54:10 +00:00
|
|
|
|
cur.message(_("Cut"));
|
2005-09-19 09:57:04 +00:00
|
|
|
|
// Prevent stale position >= size crash
|
2005-10-12 18:44:53 +00:00
|
|
|
|
// Probably not necessary anymore, see eraseSelection (gb 2005-10-09)
|
2005-09-19 09:57:04 +00:00
|
|
|
|
cur.normalize();
|
2004-04-18 07:34:15 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_COPY:
|
|
|
|
|
copySelection(cur);
|
2006-09-09 15:27:44 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-09-11 08:54:10 +00:00
|
|
|
|
cur.message(_("Copy"));
|
2004-04-18 07:34:15 +00:00
|
|
|
|
break;
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
case LFUN_MOUSE_PRESS:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
lfunMousePress(cur, cmd);
|
|
|
|
|
break;
|
|
|
|
|
|
2004-02-06 16:14:06 +00:00
|
|
|
|
case LFUN_MOUSE_MOTION:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
lfunMouseMotion(cur, cmd);
|
|
|
|
|
break;
|
|
|
|
|
|
2004-02-06 16:14:06 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
lfunMouseRelease(cur, cmd);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_FINISHED_LEFT:
|
|
|
|
|
cur.bv().cursor() = cur;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_FINISHED_RIGHT:
|
|
|
|
|
++cur.pos();
|
|
|
|
|
cur.bv().cursor() = cur;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_FINISHED_UP:
|
|
|
|
|
cur.bv().cursor() = cur;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_FINISHED_DOWN:
|
2005-07-18 00:45:10 +00:00
|
|
|
|
++cur.pos();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
cur.bv().cursor() = cur;
|
|
|
|
|
break;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_CHAR_FORWARD_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_CHAR_FORWARD:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.autocorrect() = false;
|
|
|
|
|
cur.clearTargetX();
|
2004-08-13 09:31:48 +00:00
|
|
|
|
cur.macroModeClose();
|
2004-08-13 10:59:12 +00:00
|
|
|
|
if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cur.pushLeft(*cur.nextAtom().nucleus());
|
|
|
|
|
cur.inset().idxFirst(cur);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
} else if (cur.posRight() || idxRight(cur)
|
|
|
|
|
|| cur.popRight() || cur.selection())
|
|
|
|
|
;
|
2005-07-18 00:09:20 +00:00
|
|
|
|
else {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
|
2005-07-18 00:09:20 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_CHAR_BACKWARD_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_CHAR_BACKWARD:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.autocorrect() = false;
|
|
|
|
|
cur.clearTargetX();
|
2004-08-13 09:31:48 +00:00
|
|
|
|
cur.macroModeClose();
|
|
|
|
|
if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.posLeft();
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cur.push(*cur.nextAtom().nucleus());
|
|
|
|
|
cur.inset().idxLast(cur);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
} else if (cur.posLeft() || idxLeft(cur)
|
|
|
|
|
|| cur.popLeft() || cur.selection())
|
|
|
|
|
;
|
2005-07-18 00:09:20 +00:00
|
|
|
|
else {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_LEFT);
|
2005-07-18 00:09:20 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_UP_SELECT:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
case LFUN_UP:
|
2005-04-08 12:15:28 +00:00
|
|
|
|
// FIXME Tried to use clearTargetX and macroModeClose, crashed on cur.up()
|
|
|
|
|
if (cur.inMacroMode()) {
|
|
|
|
|
// Make Helge happy
|
|
|
|
|
cur.macroModeClose();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-05-05 20:23:12 +00:00
|
|
|
|
cur.selHandle(cmd.action == LFUN_UP_SELECT);
|
2005-07-18 00:09:20 +00:00
|
|
|
|
if (!cur.up()) {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_UP);
|
2005-07-18 00:09:20 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
2005-02-12 15:46:22 +00:00
|
|
|
|
// fixes bug 1598. Please check!
|
|
|
|
|
cur.normalize();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_DOWN_SELECT:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
case LFUN_DOWN:
|
2005-04-08 12:15:28 +00:00
|
|
|
|
if (cur.inMacroMode()) {
|
|
|
|
|
cur.macroModeClose();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-05-05 20:23:12 +00:00
|
|
|
|
cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
|
2005-07-18 00:09:20 +00:00
|
|
|
|
if (!cur.down()) {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_DOWN);
|
2005-07-18 00:09:20 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
2005-02-12 15:46:22 +00:00
|
|
|
|
// fixes bug 1598. Please check!
|
|
|
|
|
cur.normalize();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
case LFUN_MOUSE_DOUBLE:
|
|
|
|
|
case LFUN_MOUSE_TRIPLE:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_WORD_SELECT:
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.pos() = 0;
|
|
|
|
|
cur.idx() = 0;
|
2004-02-11 14:45:44 +00:00
|
|
|
|
cur.resetAnchor();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
cur.selection() = true;
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
|
cur.idx() = cur.lastidx();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_PARAGRAPH_UP_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_PARAGRAPH_UP:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_PARAGRAPH_DOWN_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_PARAGRAPH_DOWN:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_LINE_BEGIN_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_LINE_BEGIN:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_WORD_BACKWARD_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_WORD_BACKWARD:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT ||
|
|
|
|
|
cmd.action == LFUN_LINE_BEGIN_SELECT);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.macroModeClose();
|
|
|
|
|
if (cur.pos() != 0) {
|
|
|
|
|
cur.pos() = 0;
|
|
|
|
|
} else if (cur.col() != 0) {
|
|
|
|
|
cur.idx() -= cur.col();
|
|
|
|
|
cur.pos() = 0;
|
|
|
|
|
} else if (cur.idx() != 0) {
|
|
|
|
|
cur.idx() = 0;
|
|
|
|
|
cur.pos() = 0;
|
|
|
|
|
} else {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_LEFT);
|
2005-04-10 09:07:28 +00:00
|
|
|
|
cur.undispatched();
|
2004-02-25 14:39:14 +00:00
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_WORD_FORWARD_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_WORD_FORWARD:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_LINE_END_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_LINE_END:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT ||
|
|
|
|
|
cmd.action == LFUN_LINE_END_SELECT);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.macroModeClose();
|
|
|
|
|
cur.clearTargetX();
|
|
|
|
|
if (cur.pos() != cur.lastpos()) {
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2005-04-06 19:01:55 +00:00
|
|
|
|
} else if (ncols() && (cur.col() != cur.lastcol())) {
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.idx() = cur.idx() - cur.col() + cur.lastcol();
|
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
|
} else if (cur.idx() != cur.lastidx()) {
|
|
|
|
|
cur.idx() = cur.lastidx();
|
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
|
} else {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
|
2005-04-10 09:07:28 +00:00
|
|
|
|
cur.undispatched();
|
2004-02-25 14:39:14 +00:00
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_SCREEN_UP_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_SCREEN_UP:
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_LEFT);
|
2005-07-14 11:54:45 +00:00
|
|
|
|
cur.undispatched();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_SCREEN_DOWN_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_SCREEN_DOWN:
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
|
2005-07-14 11:54:45 +00:00
|
|
|
|
cur.undispatched();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_CELL_FORWARD:
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cur.inset().idxNext(cur);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_CELL_BACKWARD:
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cur.inset().idxPrev(cur);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_WORD_DELETE_BACKWARD:
|
|
|
|
|
case LFUN_CHAR_DELETE_BACKWARD:
|
2005-10-03 09:50:28 +00:00
|
|
|
|
if (cur.pos() == 0)
|
2006-04-13 08:40:11 +00:00
|
|
|
|
// May affect external cell:
|
2005-10-03 09:50:28 +00:00
|
|
|
|
recordUndoInset(cur, Undo::ATOMIC);
|
|
|
|
|
else
|
|
|
|
|
recordUndo(cur, Undo::ATOMIC);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
cur.backspace();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_WORD_DELETE_FORWARD:
|
|
|
|
|
case LFUN_CHAR_DELETE_FORWARD:
|
2006-04-13 08:40:11 +00:00
|
|
|
|
if (cur.pos() == cur.lastpos())
|
|
|
|
|
// May affect external cell:
|
|
|
|
|
recordUndoInset(cur, Undo::ATOMIC);
|
|
|
|
|
else
|
|
|
|
|
recordUndo(cur, Undo::ATOMIC);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
cur.erase();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_ESCAPE:
|
2004-04-03 08:37:12 +00:00
|
|
|
|
if (cur.selection())
|
2004-04-07 08:07:26 +00:00
|
|
|
|
cur.clearSelection();
|
2005-07-14 14:48:46 +00:00
|
|
|
|
else {
|
2005-09-27 08:42:28 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
|
2005-07-14 14:48:46 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_INSET_TOGGLE:
|
2004-04-18 19:41:40 +00:00
|
|
|
|
recordUndo(cur);
|
2006-08-11 21:41:56 +00:00
|
|
|
|
lock(!lock());
|
|
|
|
|
cur.popRight();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_SELF_INSERT:
|
2006-09-01 15:41:38 +00:00
|
|
|
|
if (cmd.argument().size() != 1) {
|
2005-10-12 18:40:22 +00:00
|
|
|
|
recordUndo(cur);
|
2006-09-01 15:41:38 +00:00
|
|
|
|
string const arg = lyx::to_utf8(cmd.argument());
|
|
|
|
|
if (!interpret(cur, arg))
|
|
|
|
|
cur.insert(arg);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
2005-10-12 18:40:22 +00:00
|
|
|
|
// Don't record undo steps if we are in macro mode and
|
|
|
|
|
// cmd.argument is the next character of the macro name.
|
|
|
|
|
// Otherwise we'll get an invalid cursor if we undo after
|
|
|
|
|
// the macro was finished and the macro is a known command,
|
|
|
|
|
// e.g. sqrt. LCursor::macroModeClose replaces in this case
|
2006-09-16 18:11:38 +00:00
|
|
|
|
// the InsetMathUnknown with name "frac" by an empty
|
|
|
|
|
// InsetMathFrac -> a pos value > 0 is invalid.
|
2005-10-12 18:40:22 +00:00
|
|
|
|
// A side effect is that an undo before the macro is finished
|
|
|
|
|
// undoes the complete macro, not only the last character.
|
|
|
|
|
if (!cur.inMacroMode())
|
|
|
|
|
recordUndo(cur);
|
2006-01-11 17:08:50 +00:00
|
|
|
|
|
|
|
|
|
// spacial handling of space. If we insert an inset
|
|
|
|
|
// via macro mode, we want to put the cursor inside it
|
|
|
|
|
// if relevant. Think typing "\frac<space>".
|
2006-09-01 15:41:38 +00:00
|
|
|
|
if (cmd.argument()[0] == ' '
|
2006-01-11 17:08:50 +00:00
|
|
|
|
&& cur.inMacroMode() && cur.macroName() != "\\"
|
|
|
|
|
&& cur.macroModeClose()) {
|
|
|
|
|
MathAtom const atom = cur.prevAtom();
|
|
|
|
|
if (atom->asNestInset() && atom->nargs() > 0) {
|
|
|
|
|
cur.posLeft();
|
|
|
|
|
cur.pushLeft(*cur.nextInset());
|
|
|
|
|
}
|
2006-09-01 15:41:38 +00:00
|
|
|
|
// FIXME: Change to
|
|
|
|
|
// } else if (!interpret(cur, cmd.argument()[0])) {
|
|
|
|
|
// when interpret accepts UCS4 characters
|
|
|
|
|
} else if (!interpret(cur, lyx::to_utf8(cmd.argument()))) {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
|
2005-07-18 00:09:20 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
//case LFUN_SERVER_GET_XY:
|
2004-04-18 19:41:40 +00:00
|
|
|
|
// sprintf(dispatch_buffer, "%d %d",);
|
|
|
|
|
// break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_SERVER_SET_XY: {
|
|
|
|
|
lyxerr << "LFUN_SERVER_SET_XY broken!" << endl;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
int x = 0;
|
|
|
|
|
int y = 0;
|
2006-09-01 15:41:38 +00:00
|
|
|
|
istringstream is(lyx::to_utf8(cmd.argument()));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
is >> x >> y;
|
|
|
|
|
cur.setScreenPos(x, y);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Special casing for superscript in case of LyX handling
|
|
|
|
|
// dead-keys:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_ACCENT_CIRCUMFLEX:
|
2006-09-01 15:41:38 +00:00
|
|
|
|
if (cmd.argument().empty()) {
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// do superscript if LyX handles
|
|
|
|
|
// deadkeys
|
2004-03-08 21:14:45 +00:00
|
|
|
|
recordUndo(cur, Undo::ATOMIC);
|
2006-03-20 14:42:04 +00:00
|
|
|
|
script(cur, true, grabAndEraseSelection(cur));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_ACCENT_UMLAUT:
|
|
|
|
|
case LFUN_ACCENT_ACUTE:
|
|
|
|
|
case LFUN_ACCENT_GRAVE:
|
|
|
|
|
case LFUN_ACCENT_BREVE:
|
|
|
|
|
case LFUN_ACCENT_DOT:
|
|
|
|
|
case LFUN_ACCENT_MACRON:
|
|
|
|
|
case LFUN_ACCENT_CARON:
|
|
|
|
|
case LFUN_ACCENT_TILDE:
|
|
|
|
|
case LFUN_ACCENT_CEDILLA:
|
|
|
|
|
case LFUN_ACCENT_CIRCLE:
|
|
|
|
|
case LFUN_ACCENT_UNDERDOT:
|
|
|
|
|
case LFUN_ACCENT_TIE:
|
|
|
|
|
case LFUN_ACCENT_OGONEK:
|
|
|
|
|
case LFUN_ACCENT_HUNGARIAN_UMLAUT:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
// Math fonts
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_FONT_FREE_APPLY:
|
|
|
|
|
case LFUN_FONT_FREE_UPDATE:
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont2(cur, lyx::to_utf8(cmd.argument()));
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_FONT_BOLD:
|
2005-06-24 10:14:33 +00:00
|
|
|
|
if (currentMode() == TEXT_MODE)
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "textbf");
|
2005-06-24 10:14:33 +00:00
|
|
|
|
else
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "mathbf");
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_FONT_SANS:
|
2005-06-24 10:14:33 +00:00
|
|
|
|
if (currentMode() == TEXT_MODE)
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "textsf");
|
2005-06-24 10:14:33 +00:00
|
|
|
|
else
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "mathsf");
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_FONT_EMPH:
|
2005-06-24 10:14:33 +00:00
|
|
|
|
if (currentMode() == TEXT_MODE)
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "emph");
|
2005-06-24 10:14:33 +00:00
|
|
|
|
else
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "mathcal");
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_FONT_ROMAN:
|
2005-06-24 10:14:33 +00:00
|
|
|
|
if (currentMode() == TEXT_MODE)
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "textrm");
|
2005-06-24 10:14:33 +00:00
|
|
|
|
else
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "mathrm");
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_FONT_CODE:
|
2005-07-15 16:52:27 +00:00
|
|
|
|
if (currentMode() == TEXT_MODE)
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "texttt");
|
2005-07-15 16:52:27 +00:00
|
|
|
|
else
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "mathtt");
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_FONT_FRAK:
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "mathfrak");
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_FONT_ITAL:
|
2005-06-24 10:14:33 +00:00
|
|
|
|
if (currentMode() == TEXT_MODE)
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "textit");
|
2005-06-24 10:14:33 +00:00
|
|
|
|
else
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "mathit");
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_FONT_NOUN:
|
2005-06-24 10:14:33 +00:00
|
|
|
|
if (currentMode() == TEXT_MODE)
|
|
|
|
|
// FIXME: should be "noun"
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "textsc");
|
2005-06-24 10:14:33 +00:00
|
|
|
|
else
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "mathbb");
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-05-05 20:23:12 +00:00
|
|
|
|
//case LFUN_FONT_FREE_APPLY:
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "textrm");
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_FONT_DEFAULT:
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "textnormal");
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-03-20 14:42:04 +00:00
|
|
|
|
case LFUN_MATH_MODE: {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
#if 1
|
2004-11-07 09:39:34 +00:00
|
|
|
|
// ignore math-mode on when already in math mode
|
2006-09-01 15:41:38 +00:00
|
|
|
|
if (currentMode() == InsetBase::MATH_MODE && cmd.argument() == "on")
|
2004-11-07 09:39:34 +00:00
|
|
|
|
break;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
cur.macroModeClose();
|
2006-03-20 14:42:04 +00:00
|
|
|
|
string const save_selection = grabAndEraseSelection(cur);
|
2004-04-18 07:34:15 +00:00
|
|
|
|
selClearOrDel(cur);
|
2006-09-16 18:11:38 +00:00
|
|
|
|
//cur.plainInsert(MathAtom(new InsetMathMBox(cur.bv())));
|
|
|
|
|
cur.plainInsert(MathAtom(new InsetMathBox("mbox")));
|
2004-01-30 11:41:12 +00:00
|
|
|
|
cur.posLeft();
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cur.pushLeft(*cur.nextInset());
|
2006-03-20 14:42:04 +00:00
|
|
|
|
cur.niceInsert(save_selection);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
#else
|
2004-04-18 19:41:40 +00:00
|
|
|
|
if (currentMode() == InsetBase::TEXT_MODE) {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.niceInsert(MathAtom(new InsetMathHull("simple")));
|
2004-04-18 19:41:40 +00:00
|
|
|
|
cur.message(_("create new math text environment ($...$)"));
|
|
|
|
|
} else {
|
2006-09-01 15:41:38 +00:00
|
|
|
|
handleFont(cur, lyx::to_utf8(cmd.argument()), "textrm");
|
2004-04-18 19:41:40 +00:00
|
|
|
|
cur.message(_("entered math text mode (textrm)"));
|
|
|
|
|
}
|
2004-01-30 11:41:12 +00:00
|
|
|
|
#endif
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-03-20 14:42:04 +00:00
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_MATH_SIZE:
|
|
|
|
|
#if 0
|
2004-04-18 19:41:40 +00:00
|
|
|
|
recordUndo(cur);
|
|
|
|
|
cur.setSize(arg);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
#endif
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_MATH_MATRIX: {
|
2004-03-08 21:14:45 +00:00
|
|
|
|
recordUndo(cur, Undo::ATOMIC);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
unsigned int m = 1;
|
|
|
|
|
unsigned int n = 1;
|
|
|
|
|
string v_align;
|
|
|
|
|
string h_align;
|
2006-09-01 15:41:38 +00:00
|
|
|
|
istringstream is(lyx::to_utf8(cmd.argument()));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
is >> m >> n >> v_align >> h_align;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
if (m < 1)
|
|
|
|
|
m = 1;
|
|
|
|
|
if (n < 1)
|
|
|
|
|
n = 1;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
v_align += 'c';
|
|
|
|
|
cur.niceInsert(
|
2006-09-16 18:11:38 +00:00
|
|
|
|
MathAtom(new InsetMathArray("array", m, n, v_align[0], h_align)));
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_MATH_DELIM: {
|
|
|
|
|
string ls;
|
2006-09-01 15:41:38 +00:00
|
|
|
|
string rs = lyx::support::split(lyx::to_utf8(cmd.argument()), ls, ' ');
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// Reasonable default values
|
|
|
|
|
if (ls.empty())
|
|
|
|
|
ls = '(';
|
|
|
|
|
if (rs.empty())
|
|
|
|
|
rs = ')';
|
2004-03-08 21:14:45 +00:00
|
|
|
|
recordUndo(cur, Undo::ATOMIC);
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.handleNest(MathAtom(new InsetMathDelim(ls, rs)));
|
2006-05-07 10:51:19 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_MATH_BIGDELIM: {
|
|
|
|
|
string const lname = cmd.getArg(0);
|
|
|
|
|
string const ldelim = cmd.getArg(1);
|
|
|
|
|
string const rname = cmd.getArg(2);
|
|
|
|
|
string const rdelim = cmd.getArg(3);
|
|
|
|
|
latexkeys const * l = in_word_set(lname);
|
|
|
|
|
bool const have_l = l && l->inset == "big" &&
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathBig::isBigInsetDelim(ldelim);
|
2006-05-07 10:51:19 +00:00
|
|
|
|
l = in_word_set(rname);
|
|
|
|
|
bool const have_r = l && l->inset == "big" &&
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathBig::isBigInsetDelim(rdelim);
|
2006-05-07 10:51:19 +00:00
|
|
|
|
// We mimic LFUN_MATH_DELIM in case we have an empty left
|
|
|
|
|
// or right delimiter.
|
|
|
|
|
if (have_l || have_r) {
|
|
|
|
|
recordUndo(cur, Undo::ATOMIC);
|
|
|
|
|
string const selection = grabAndEraseSelection(cur);
|
|
|
|
|
selClearOrDel(cur);
|
|
|
|
|
if (have_l)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.insert(MathAtom(new InsetMathBig(lname,
|
2006-05-07 10:51:19 +00:00
|
|
|
|
ldelim)));
|
|
|
|
|
cur.niceInsert(selection);
|
|
|
|
|
if (have_r)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.insert(MathAtom(new InsetMathBig(rname,
|
2006-05-07 10:51:19 +00:00
|
|
|
|
rdelim)));
|
|
|
|
|
}
|
|
|
|
|
// Don't call cur.undispatched() if we did nothing, this would
|
|
|
|
|
// lead to infinite recursion via LyXText::dispatch().
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_SPACE_INSERT:
|
|
|
|
|
case LFUN_MATH_SPACE:
|
2004-03-08 21:14:45 +00:00
|
|
|
|
recordUndo(cur, Undo::ATOMIC);
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.insert(MathAtom(new InsetMathSpace(",")));
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_ERT_INSERT:
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// interpret this as if a backslash was typed
|
2004-03-08 21:14:45 +00:00
|
|
|
|
recordUndo(cur, Undo::ATOMIC);
|
2004-02-27 09:18:03 +00:00
|
|
|
|
interpret(cur, '\\');
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2005-01-06 16:07:02 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_MATH_SUBSCRIPT:
|
2005-01-04 09:18:48 +00:00
|
|
|
|
// interpret this as if a _ was typed
|
|
|
|
|
recordUndo(cur, Undo::ATOMIC);
|
|
|
|
|
interpret(cur, '_');
|
|
|
|
|
break;
|
2005-01-06 16:07:02 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_MATH_SUPERSCRIPT:
|
2005-01-04 09:18:48 +00:00
|
|
|
|
// interpret this as if a ^ was typed
|
|
|
|
|
recordUndo(cur, Undo::ATOMIC);
|
|
|
|
|
interpret(cur, '^');
|
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
// FIXME: We probably should swap parts of "math-insert" and "self-insert"
|
|
|
|
|
// handling such that "self-insert" works on "arbitrary stuff" too, and
|
|
|
|
|
// math-insert only handles special math things like "matrix".
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_MATH_INSERT: {
|
2004-03-08 21:14:45 +00:00
|
|
|
|
recordUndo(cur, Undo::ATOMIC);
|
2006-09-01 15:41:38 +00:00
|
|
|
|
if (cmd.argument() == "^" || cmd.argument() == "_")
|
|
|
|
|
interpret(cur, cmd.argument()[0]);
|
|
|
|
|
else
|
|
|
|
|
cur.niceInsert(lyx::to_utf8(cmd.argument()));
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2005-04-06 19:01:55 +00:00
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_DIALOG_SHOW_NEW_INSET: {
|
2006-09-01 15:41:38 +00:00
|
|
|
|
string const & name = lyx::to_utf8(cmd.argument());
|
2004-01-26 10:13:15 +00:00
|
|
|
|
string data;
|
|
|
|
|
if (name == "ref") {
|
|
|
|
|
RefInset tmp(name);
|
|
|
|
|
data = tmp.createDialogStr(name);
|
|
|
|
|
}
|
2006-09-19 13:36:20 +00:00
|
|
|
|
cur.bv().showInsetDialog(name, data, 0);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-30 17:17:31 +00:00
|
|
|
|
case LFUN_INSET_INSERT: {
|
|
|
|
|
MathArray ar;
|
|
|
|
|
if (createInsetMath_fromDialogStr(lyx::to_utf8(cmd.argument()), ar)) {
|
|
|
|
|
recordUndo(cur);
|
|
|
|
|
cur.insert(ar);
|
|
|
|
|
} else
|
|
|
|
|
cur.undispatched();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
default:
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathDim::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2002-08-15 10:02:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-05-28 13:22:36 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::getStatus(LCursor & cur, FuncRequest const & cmd,
|
2004-03-18 13:57:20 +00:00
|
|
|
|
FuncStatus & flag) const
|
|
|
|
|
{
|
|
|
|
|
// the font related toggles
|
2004-04-20 08:44:30 +00:00
|
|
|
|
//string tc = "mathnormal";
|
2004-03-18 13:57:20 +00:00
|
|
|
|
bool ret = true;
|
2006-09-01 15:41:38 +00:00
|
|
|
|
string const arg = lyx::to_utf8(cmd.argument());
|
2004-03-18 13:57:20 +00:00
|
|
|
|
switch (cmd.action) {
|
2005-04-25 14:10:10 +00:00
|
|
|
|
case LFUN_TABULAR_FEATURE:
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
break;
|
2004-03-18 13:57:20 +00:00
|
|
|
|
#if 0
|
|
|
|
|
case LFUN_TABULAR_FEATURE:
|
|
|
|
|
// FIXME: check temporarily disabled
|
|
|
|
|
// valign code
|
|
|
|
|
char align = mathcursor::valign();
|
|
|
|
|
if (align == '\0') {
|
|
|
|
|
enable = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-09-01 15:41:38 +00:00
|
|
|
|
if (cmd.argument().empty()) {
|
2004-03-18 13:57:20 +00:00
|
|
|
|
flag.clear();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-09-01 15:41:38 +00:00
|
|
|
|
if (!contains("tcb", cmd.argument()[0])) {
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-09-01 15:41:38 +00:00
|
|
|
|
flag.setOnOff(cmd.argument()[0] == align);
|
2004-03-18 13:57:20 +00:00
|
|
|
|
break;
|
2005-07-15 16:52:27 +00:00
|
|
|
|
#endif
|
|
|
|
|
/// We have to handle them since 1.4 blocks all unhandled actions
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_FONT_ITAL:
|
|
|
|
|
case LFUN_FONT_BOLD:
|
|
|
|
|
case LFUN_FONT_SANS:
|
|
|
|
|
case LFUN_FONT_EMPH:
|
|
|
|
|
case LFUN_FONT_CODE:
|
|
|
|
|
case LFUN_FONT_NOUN:
|
|
|
|
|
case LFUN_FONT_ROMAN:
|
|
|
|
|
case LFUN_FONT_DEFAULT:
|
2005-07-15 16:52:27 +00:00
|
|
|
|
flag.enabled(true);
|
2004-03-18 13:57:20 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_MATH_MUTATE:
|
2006-09-01 15:41:38 +00:00
|
|
|
|
//flag.setOnOff(mathcursor::formula()->hullType() == lyx::to_utf8(cmd.argument()));
|
2004-03-18 13:57:20 +00:00
|
|
|
|
flag.setOnOff(false);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// we just need to be in math mode to enable that
|
|
|
|
|
case LFUN_MATH_SIZE:
|
|
|
|
|
case LFUN_MATH_SPACE:
|
|
|
|
|
case LFUN_MATH_LIMITS:
|
|
|
|
|
case LFUN_MATH_NONUMBER:
|
|
|
|
|
case LFUN_MATH_NUMBER:
|
|
|
|
|
case LFUN_MATH_EXTERN:
|
|
|
|
|
flag.enabled(true);
|
|
|
|
|
break;
|
2005-06-24 10:14:33 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_FONT_FRAK:
|
2005-06-24 10:14:33 +00:00
|
|
|
|
flag.enabled(currentMode() != TEXT_MODE);
|
|
|
|
|
break;
|
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_MATH_INSERT: {
|
2005-06-09 09:58:08 +00:00
|
|
|
|
bool const textarg =
|
2005-05-01 16:15:32 +00:00
|
|
|
|
arg == "\\textbf" || arg == "\\textsf" ||
|
|
|
|
|
arg == "\\textrm" || arg == "\\textmd" ||
|
|
|
|
|
arg == "\\textit" || arg == "\\textsc" ||
|
|
|
|
|
arg == "\\textsl" || arg == "\\textup" ||
|
|
|
|
|
arg == "\\texttt" || arg == "\\textbb" ||
|
|
|
|
|
arg == "\\textnormal";
|
2005-06-24 10:14:33 +00:00
|
|
|
|
flag.enabled(currentMode() != TEXT_MODE || textarg);
|
2005-05-01 16:15:32 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2005-06-24 10:14:33 +00:00
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_MATH_MATRIX:
|
2005-05-01 16:15:32 +00:00
|
|
|
|
flag.enabled(currentMode() == MATH_MODE);
|
|
|
|
|
break;
|
2006-05-07 10:51:19 +00:00
|
|
|
|
|
2006-09-30 17:17:31 +00:00
|
|
|
|
case LFUN_INSET_INSERT: {
|
|
|
|
|
// Don't test createMathInset_fromDialogStr(), since
|
|
|
|
|
// getStatus is not called with a valid reference and the
|
|
|
|
|
// dialog would not be applyable.
|
|
|
|
|
string const name = cmd.getArg(0);
|
|
|
|
|
flag.enabled(name == "ref");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-07 10:51:19 +00:00
|
|
|
|
case LFUN_MATH_DELIM:
|
|
|
|
|
case LFUN_MATH_BIGDELIM:
|
|
|
|
|
// Don't do this with multi-cell selections
|
|
|
|
|
flag.enabled(cur.selBegin().idx() == cur.selEnd().idx());
|
|
|
|
|
break;
|
|
|
|
|
|
2004-03-18 13:57:20 +00:00
|
|
|
|
default:
|
|
|
|
|
ret = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-27 12:46:30 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::edit(LCursor & cur, bool left)
|
2003-05-28 13:22:36 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cur.push(*this);
|
2004-02-06 16:14:06 +00:00
|
|
|
|
cur.idx() = left ? 0 : cur.lastidx();
|
|
|
|
|
cur.pos() = left ? 0 : cur.lastpos();
|
|
|
|
|
cur.resetAnchor();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
//lyxerr << "InsetMathNest::edit, cur:\n" << cur << endl;
|
2004-02-06 16:14:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetBase * InsetMathNest::editXY(LCursor & cur, int x, int y)
|
2004-02-06 16:14:06 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
int idx_min = 0;
|
|
|
|
|
int dist_min = 1000000;
|
2005-07-15 00:39:44 +00:00
|
|
|
|
for (idx_type i = 0, n = nargs(); i != n; ++i) {
|
2006-10-13 16:44:44 +00:00
|
|
|
|
int const d = cell(i).dist(cur.bv(), x, y);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
if (d < dist_min) {
|
|
|
|
|
dist_min = d;
|
|
|
|
|
idx_min = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-07-15 00:39:44 +00:00
|
|
|
|
MathArray & ar = cell(idx_min);
|
|
|
|
|
cur.push(*this);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
cur.idx() = idx_min;
|
2006-10-13 16:44:44 +00:00
|
|
|
|
cur.pos() = ar.x2pos(x - ar.xo(cur.bv()));
|
|
|
|
|
|
2005-07-15 08:51:34 +00:00
|
|
|
|
//lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
if (dist_min == 0) {
|
|
|
|
|
// hit inside cell
|
|
|
|
|
for (pos_type i = 0, n = ar.size(); i < n; ++i)
|
2006-10-13 16:44:44 +00:00
|
|
|
|
if (ar[i]->covers(cur.bv(), x, y))
|
2004-02-13 13:51:12 +00:00
|
|
|
|
return ar[i].nucleus()->editXY(cur, x, y);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
2005-07-15 00:39:44 +00:00
|
|
|
|
return this;
|
2003-05-28 13:22:36 +00:00
|
|
|
|
}
|
2004-02-06 16:14:06 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::lfunMousePress(LCursor & cur, FuncRequest & cmd)
|
2004-02-06 16:14:06 +00:00
|
|
|
|
{
|
2005-02-28 11:32:58 +00:00
|
|
|
|
//lyxerr << "## lfunMousePress: buttons: " << cmd.button() << endl;
|
2006-08-22 13:58:09 +00:00
|
|
|
|
BufferView & bv = cur.bv();
|
2004-02-06 16:14:06 +00:00
|
|
|
|
if (cmd.button() == mouse_button::button1) {
|
2005-02-28 11:32:58 +00:00
|
|
|
|
//lyxerr << "## lfunMousePress: setting cursor to: " << cur << endl;
|
2006-08-22 13:58:09 +00:00
|
|
|
|
bv.mouseSetCursor(cur);
|
|
|
|
|
} else if (cmd.button() == mouse_button::button2) {
|
2006-04-09 07:06:57 +00:00
|
|
|
|
MathArray ar;
|
2006-08-22 13:58:09 +00:00
|
|
|
|
if (cur.selection())
|
2006-10-17 14:46:45 +00:00
|
|
|
|
asArray(bv.cursor().selectionAsString(false), ar);
|
2006-08-22 13:58:09 +00:00
|
|
|
|
else
|
2006-10-17 14:46:45 +00:00
|
|
|
|
asArray(theSelection().get(), ar);
|
2006-08-22 13:58:09 +00:00
|
|
|
|
|
2006-04-09 07:06:57 +00:00
|
|
|
|
cur.insert(ar);
|
2006-08-22 13:58:09 +00:00
|
|
|
|
bv.mouseSetCursor(cur);
|
2004-02-06 16:14:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::lfunMouseMotion(LCursor & cur, FuncRequest & cmd)
|
2004-02-06 16:14:06 +00:00
|
|
|
|
{
|
|
|
|
|
// only select with button 1
|
2004-08-14 20:34:46 +00:00
|
|
|
|
if (cmd.button() == mouse_button::button1) {
|
|
|
|
|
LCursor & bvcur = cur.bv().cursor();
|
2005-02-28 11:32:58 +00:00
|
|
|
|
if (bvcur.anchor_.hasPart(cur)) {
|
|
|
|
|
//lyxerr << "## lfunMouseMotion: cursor: " << cur << endl;
|
2004-08-14 20:34:46 +00:00
|
|
|
|
bvcur.setCursor(cur);
|
|
|
|
|
bvcur.selection() = true;
|
2005-02-28 11:32:58 +00:00
|
|
|
|
//lyxerr << "MOTION " << bvcur << endl;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2004-11-30 01:59:49 +00:00
|
|
|
|
cur.undispatched();
|
2005-02-28 11:32:58 +00:00
|
|
|
|
}
|
2004-08-14 20:34:46 +00:00
|
|
|
|
}
|
2004-02-06 16:14:06 +00:00
|
|
|
|
}
|
2004-02-27 09:18:03 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathNest::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
|
2004-08-13 21:21:10 +00:00
|
|
|
|
{
|
2005-02-28 11:32:58 +00:00
|
|
|
|
//lyxerr << "## lfunMouseRelease: buttons: " << cmd.button() << endl;
|
2004-08-13 21:21:10 +00:00
|
|
|
|
|
|
|
|
|
if (cmd.button() == mouse_button::button1) {
|
2006-10-11 17:24:46 +00:00
|
|
|
|
//theSelection().put(cur.grabSelection());
|
2004-08-13 21:21:10 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cmd.button() == mouse_button::button3) {
|
|
|
|
|
// try to dispatch to enclosed insets first
|
2006-09-19 13:36:20 +00:00
|
|
|
|
cur.bv().showDialog("mathpanel");
|
2004-08-13 21:21:10 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::interpret(LCursor & cur, char c)
|
2004-02-27 09:18:03 +00:00
|
|
|
|
{
|
2005-07-15 08:51:34 +00:00
|
|
|
|
//lyxerr << "interpret 2: '" << c << "'" << endl;
|
2006-03-20 14:42:04 +00:00
|
|
|
|
string save_selection;
|
2006-03-20 06:53:29 +00:00
|
|
|
|
if (c == '^' || c == '_')
|
2006-03-20 14:42:04 +00:00
|
|
|
|
save_selection = grabAndEraseSelection(cur);
|
2006-03-20 06:53:29 +00:00
|
|
|
|
|
2004-02-27 09:18:03 +00:00
|
|
|
|
cur.clearTargetX();
|
|
|
|
|
|
|
|
|
|
// handle macroMode
|
|
|
|
|
if (cur.inMacroMode()) {
|
|
|
|
|
string name = cur.macroName();
|
2004-04-18 07:34:15 +00:00
|
|
|
|
|
|
|
|
|
/// are we currently typing '#1' or '#2' or...?
|
|
|
|
|
if (name == "\\#") {
|
|
|
|
|
cur.backspace();
|
|
|
|
|
int n = c - '0';
|
|
|
|
|
if (n >= 1 && n <= 9)
|
|
|
|
|
cur.insert(new MathMacroArgument(n));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2004-02-27 09:18:03 +00:00
|
|
|
|
|
|
|
|
|
if (isalpha(c)) {
|
2004-04-18 07:34:15 +00:00
|
|
|
|
cur.activeMacro()->setName(name + c);
|
2004-02-27 09:18:03 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handle 'special char' macros
|
|
|
|
|
if (name == "\\") {
|
|
|
|
|
// remove the '\\'
|
|
|
|
|
if (c == '\\') {
|
2004-04-18 07:34:15 +00:00
|
|
|
|
cur.backspace();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
if (currentMode() == InsetMath::TEXT_MODE)
|
|
|
|
|
cur.niceInsert(createInsetMath("textbackslash"));
|
2004-02-27 09:18:03 +00:00
|
|
|
|
else
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.niceInsert(createInsetMath("backslash"));
|
2004-02-27 09:18:03 +00:00
|
|
|
|
} else if (c == '{') {
|
2004-04-18 07:34:15 +00:00
|
|
|
|
cur.backspace();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.niceInsert(MathAtom(new InsetMathBrace));
|
2004-08-12 19:49:25 +00:00
|
|
|
|
} else if (c == '%') {
|
|
|
|
|
cur.backspace();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.niceInsert(MathAtom(new InsetMathComment));
|
2004-04-18 07:34:15 +00:00
|
|
|
|
} else if (c == '#') {
|
|
|
|
|
BOOST_ASSERT(cur.activeMacro());
|
|
|
|
|
cur.activeMacro()->setName(name + c);
|
2004-02-27 09:18:03 +00:00
|
|
|
|
} else {
|
2004-04-18 07:34:15 +00:00
|
|
|
|
cur.backspace();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.niceInsert(createInsetMath(string(1, c)));
|
2004-02-27 09:18:03 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-20 09:55:45 +00:00
|
|
|
|
// One character big delimiters. The others are handled in
|
2006-05-01 08:05:22 +00:00
|
|
|
|
// the other interpret() method.
|
2006-04-20 09:55:45 +00:00
|
|
|
|
latexkeys const * l = in_word_set(name.substr(1));
|
|
|
|
|
if (name[0] == '\\' && l && l->inset == "big") {
|
|
|
|
|
string delim;
|
|
|
|
|
switch (c) {
|
|
|
|
|
case '{':
|
|
|
|
|
delim = "\\{";
|
|
|
|
|
break;
|
|
|
|
|
case '}':
|
|
|
|
|
delim = "\\}";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
delim = string(1, c);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
|
if (InsetMathBig::isBigInsetDelim(delim)) {
|
|
|
|
|
// name + delim ared a valid InsetMathBig.
|
2006-04-20 09:55:45 +00:00
|
|
|
|
// We can't use cur.macroModeClose() because
|
|
|
|
|
// it does not handle delim.
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathUnknown * p = cur.activeMacro();
|
2006-04-20 09:55:45 +00:00
|
|
|
|
p->finalize();
|
|
|
|
|
--cur.pos();
|
|
|
|
|
cur.cell().erase(cur.pos());
|
|
|
|
|
cur.plainInsert(MathAtom(
|
2006-09-16 18:11:38 +00:00
|
|
|
|
new InsetMathBig(name.substr(1), delim)));
|
2006-04-20 09:55:45 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-27 09:18:03 +00:00
|
|
|
|
// leave macro mode and try again if necessary
|
|
|
|
|
cur.macroModeClose();
|
|
|
|
|
if (c == '{')
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.niceInsert(MathAtom(new InsetMathBrace));
|
2004-02-27 09:18:03 +00:00
|
|
|
|
else if (c != ' ')
|
|
|
|
|
interpret(cur, c);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is annoying as one has to press <space> far too often.
|
|
|
|
|
// Disable it.
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
// leave autocorrect mode if necessary
|
|
|
|
|
if (autocorrect() && c == ' ') {
|
|
|
|
|
autocorrect() = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// just clear selection on pressing the space bar
|
|
|
|
|
if (cur.selection() && c == ' ') {
|
|
|
|
|
cur.selection() = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-18 07:34:15 +00:00
|
|
|
|
selClearOrDel(cur);
|
2004-02-27 09:18:03 +00:00
|
|
|
|
|
|
|
|
|
if (c == '\\') {
|
|
|
|
|
//lyxerr << "starting with macro" << endl;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.insert(MathAtom(new InsetMathUnknown("\\", false)));
|
2004-02-27 09:18:03 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c == '\n') {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
if (currentMode() == InsetMath::TEXT_MODE)
|
2004-02-27 09:18:03 +00:00
|
|
|
|
cur.insert(c);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c == ' ') {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
if (currentMode() == InsetMath::TEXT_MODE) {
|
2004-02-27 09:18:03 +00:00
|
|
|
|
// insert spaces in text mode,
|
|
|
|
|
// but suppress direct insertion of two spaces in a row
|
|
|
|
|
// the still allows typing '<space>a<space>' and deleting the 'a', but
|
|
|
|
|
// it is better than nothing...
|
|
|
|
|
if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ')
|
|
|
|
|
cur.insert(c);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
|
|
|
|
|
cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (cur.popRight())
|
|
|
|
|
return true;
|
|
|
|
|
// if are at the very end, leave the formula
|
|
|
|
|
return cur.pos() != cur.lastpos();
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-01 16:15:32 +00:00
|
|
|
|
// These shouldn't work in text mode:
|
2006-09-16 18:11:38 +00:00
|
|
|
|
if (currentMode() != InsetMath::TEXT_MODE) {
|
2005-05-01 16:15:32 +00:00
|
|
|
|
if (c == '_') {
|
2006-03-20 14:42:04 +00:00
|
|
|
|
script(cur, false, save_selection);
|
2005-05-01 16:15:32 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (c == '^') {
|
2006-03-20 14:42:04 +00:00
|
|
|
|
script(cur, true, save_selection);
|
2005-05-01 16:15:32 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (c == '~') {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.niceInsert(createInsetMath("sim"));
|
2005-05-01 16:15:32 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2004-02-27 09:18:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-05-01 08:05:22 +00:00
|
|
|
|
if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' ||
|
|
|
|
|
c == '%' || c == '_' || c == '^') {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.niceInsert(createInsetMath(string(1, c)));
|
2004-02-27 09:18:03 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// try auto-correction
|
|
|
|
|
//if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
|
|
// no special circumstances, so insert the character without any fuss
|
|
|
|
|
cur.insert(c);
|
|
|
|
|
cur.autocorrect() = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::interpret(LCursor & cur, string const & str)
|
2006-05-01 08:05:22 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
// Create a InsetMathBig from cur.cell()[cur.pos() - 1] and t if
|
2006-05-01 08:05:22 +00:00
|
|
|
|
// possible
|
|
|
|
|
if (!cur.empty() && cur.pos() > 0 &&
|
|
|
|
|
cur.cell()[cur.pos() - 1]->asUnknownInset()) {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
if (InsetMathBig::isBigInsetDelim(str)) {
|
2006-05-01 08:05:22 +00:00
|
|
|
|
string prev = asString(cur.cell()[cur.pos() - 1]);
|
|
|
|
|
if (prev[0] == '\\') {
|
|
|
|
|
prev = prev.substr(1);
|
|
|
|
|
latexkeys const * l = in_word_set(prev);
|
|
|
|
|
if (l && l->inset == "big") {
|
|
|
|
|
cur.cell()[cur.pos() - 1] =
|
2006-09-16 18:11:38 +00:00
|
|
|
|
MathAtom(new InsetMathBig(prev, str));
|
2006-05-01 08:05:22 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathNest::script(LCursor & cur, bool up, string const &
|
2006-03-20 14:42:04 +00:00
|
|
|
|
save_selection)
|
2004-02-27 09:18:03 +00:00
|
|
|
|
{
|
2004-08-12 21:48:21 +00:00
|
|
|
|
// Hack to get \^ and \_ working
|
2006-08-08 21:55:41 +00:00
|
|
|
|
//lyxerr << "handling script: up: " << up << endl;
|
2004-02-27 09:18:03 +00:00
|
|
|
|
if (cur.inMacroMode() && cur.macroName() == "\\") {
|
|
|
|
|
if (up)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.niceInsert(createInsetMath("mathcircumflex"));
|
2004-02-27 09:18:03 +00:00
|
|
|
|
else
|
|
|
|
|
interpret(cur, '_');
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cur.macroModeClose();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (asScriptInset() && cur.idx() == 0) {
|
2004-02-27 09:18:03 +00:00
|
|
|
|
// we are in a nucleus of a script inset, move to _our_ script
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathScript * inset = asScriptInset();
|
2006-08-08 21:55:41 +00:00
|
|
|
|
//lyxerr << " going to cell " << inset->idxOfScript(up) << endl;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
inset->ensure(up);
|
|
|
|
|
cur.idx() = inset->idxOfScript(up);
|
2004-02-27 09:18:03 +00:00
|
|
|
|
cur.pos() = 0;
|
|
|
|
|
} else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
|
|
|
|
|
--cur.pos();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathScript * inset = cur.nextAtom().nucleus()->asScriptInset();
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cur.push(*inset);
|
2005-12-02 06:34:19 +00:00
|
|
|
|
inset->ensure(up);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cur.idx() = inset->idxOfScript(up);
|
2004-02-27 09:18:03 +00:00
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
|
} else {
|
2004-03-25 09:16:36 +00:00
|
|
|
|
// convert the thing to our left to a scriptinset or create a new
|
|
|
|
|
// one if in the very first position of the array
|
|
|
|
|
if (cur.pos() == 0) {
|
2005-07-15 08:51:34 +00:00
|
|
|
|
//lyxerr << "new scriptinset" << endl;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.insert(new InsetMathScript(up));
|
2004-03-25 09:16:36 +00:00
|
|
|
|
} else {
|
2005-07-15 08:51:34 +00:00
|
|
|
|
//lyxerr << "converting prev atom " << endl;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.prevAtom() = MathAtom(new InsetMathScript(cur.prevAtom(), up));
|
2004-03-25 09:16:36 +00:00
|
|
|
|
}
|
2004-04-05 16:31:52 +00:00
|
|
|
|
--cur.pos();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathScript * inset = cur.nextAtom().nucleus()->asScriptInset();
|
2006-08-23 10:57:49 +00:00
|
|
|
|
// special handling of {}-bases
|
|
|
|
|
// is this always correct?
|
2006-09-09 15:27:44 +00:00
|
|
|
|
if (inset->nuc().size() == 1
|
2006-08-23 10:57:49 +00:00
|
|
|
|
&& inset->nuc().back()->asBraceInset())
|
|
|
|
|
inset->nuc() = inset->nuc().back()->asNestInset()->cell(0);
|
2006-09-09 15:27:44 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
cur.push(*inset);
|
|
|
|
|
cur.idx() = 1;
|
2004-02-27 09:18:03 +00:00
|
|
|
|
cur.pos() = 0;
|
|
|
|
|
}
|
2006-03-20 14:42:04 +00:00
|
|
|
|
//lyxerr << "inserting selection 1:\n" << save_selection << endl;
|
|
|
|
|
cur.niceInsert(save_selection);
|
2004-04-05 16:31:52 +00:00
|
|
|
|
cur.resetAnchor();
|
2006-03-20 14:42:04 +00:00
|
|
|
|
//lyxerr << "inserting selection 2:\n" << save_selection << endl;
|
2004-02-27 09:18:03 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|