2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
|
* \file InsetMathNest.cpp
|
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 "InsetMathDelim.h"
|
|
|
|
|
#include "InsetMathHull.h"
|
2007-04-29 16:22:46 +00:00
|
|
|
|
#include "InsetMathRef.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathScript.h"
|
|
|
|
|
#include "InsetMathSpace.h"
|
|
|
|
|
#include "InsetMathSymbol.h"
|
|
|
|
|
#include "InsetMathUnknown.h"
|
2007-04-29 16:22:46 +00:00
|
|
|
|
#include "MathData.h"
|
|
|
|
|
#include "MathFactory.h"
|
2007-11-01 11:14:14 +00:00
|
|
|
|
#include "MathMacro.h"
|
2007-04-29 16:22:46 +00:00
|
|
|
|
#include "MathMacroArgument.h"
|
|
|
|
|
#include "MathParser.h"
|
|
|
|
|
#include "MathStream.h"
|
|
|
|
|
#include "MathSupport.h"
|
2004-01-30 11:41:12 +00:00
|
|
|
|
|
2007-09-20 20:44:08 +00:00
|
|
|
|
#include "Bidi.h"
|
2008-02-21 19:42:34 +00:00
|
|
|
|
#include "Buffer.h"
|
2002-08-22 07:06:02 +00:00
|
|
|
|
#include "BufferView.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "CoordCache.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
|
#include "Cursor.h"
|
2007-04-29 16:22:46 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "DispatchResult.h"
|
|
|
|
|
#include "FuncRequest.h"
|
2007-04-29 16:22:46 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2007-10-22 22:18:52 +00:00
|
|
|
|
#include "LyXFunc.h"
|
2008-02-10 19:57:00 +00:00
|
|
|
|
#include "LyXRC.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "OutputParams.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
|
#include "Text.h"
|
2004-01-30 11:41:12 +00:00
|
|
|
|
|
2007-01-04 12:05:24 +00:00
|
|
|
|
#include "frontends/Clipboard.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"
|
2001-08-03 17:10:22 +00:00
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
|
#include "support/debug.h"
|
|
|
|
|
#include "support/gettext.h"
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
#include "support/textutils.h"
|
|
|
|
|
#include "support/docstream.h"
|
2006-09-29 22:06:28 +00:00
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
#include <algorithm>
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2007-12-12 19:57:42 +00:00
|
|
|
|
using namespace lyx::support;
|
2006-10-15 22:32:56 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using cap::copySelection;
|
|
|
|
|
using cap::grabAndEraseSelection;
|
|
|
|
|
using cap::cutSelection;
|
|
|
|
|
using cap::replaceSelection;
|
|
|
|
|
using cap::selClearOrDel;
|
2001-08-03 17:10:22 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathNest::InsetMathNest(idx_type nargs)
|
2007-06-07 18:08:03 +00:00
|
|
|
|
: cells_(nargs), lock_(false), mouse_hover_(false)
|
2001-08-08 17:26:30 +00:00
|
|
|
|
{}
|
2001-08-03 17:10:22 +00:00
|
|
|
|
|
|
|
|
|
|
2007-05-31 12:30:17 +00:00
|
|
|
|
InsetMathNest::InsetMathNest(InsetMathNest const & inset)
|
2007-06-07 18:08:03 +00:00
|
|
|
|
: InsetMath(inset), cells_(inset.cells_), lock_(inset.lock_),
|
|
|
|
|
mouse_hover_(false)
|
2007-05-31 12:30:17 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetMathNest & InsetMathNest::operator=(InsetMathNest const & inset)
|
|
|
|
|
{
|
|
|
|
|
cells_ = inset.cells_;
|
|
|
|
|
lock_ = inset.lock_;
|
2007-06-07 18:08:03 +00:00
|
|
|
|
mouse_hover_ = false;
|
2007-05-31 12:30:17 +00:00
|
|
|
|
InsetMath::operator=(inset);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-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
|
2007-04-26 16:05:57 +00:00
|
|
|
|
// setXY() not in MathData::draw(), but in the parent insets' draw()
|
2004-11-30 01:59:49 +00:00
|
|
|
|
// 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.
|
2007-11-01 22:17:22 +00:00
|
|
|
|
BOOST_ASSERT(&sl.inset() == this);
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData 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);
|
2007-04-26 16:05:57 +00:00
|
|
|
|
//lyxerr << "retrieving position cache for MathData "
|
2007-12-12 19:28:07 +00:00
|
|
|
|
// << pt.x_ << ' ' << pt.y_ << endl;
|
2007-12-24 10:52:58 +00:00
|
|
|
|
x = pt.x_ - pt2.x_ + ar.pos2x(&bv, sl.pos());
|
2004-11-30 01:59:49 +00:00
|
|
|
|
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;
|
2007-09-24 13:52:04 +00:00
|
|
|
|
for (idx_type i = 0, n = nargs(); i != n; ++i) {
|
|
|
|
|
Dimension dim;
|
|
|
|
|
cell(i).metrics(m, dim);
|
|
|
|
|
}
|
2001-08-03 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathNest::idxNext(Cursor & cur) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2007-11-01 22:17:22 +00:00
|
|
|
|
BOOST_ASSERT(&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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 19:44:03 +00:00
|
|
|
|
bool InsetMathNest::idxForward(Cursor & 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathNest::idxPrev(Cursor & cur) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2007-11-01 22:17:22 +00:00
|
|
|
|
BOOST_ASSERT(&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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-05 19:44:03 +00:00
|
|
|
|
bool InsetMathNest::idxBackward(Cursor & 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathNest::idxFirst(Cursor & cur) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2007-11-01 22:17:22 +00:00
|
|
|
|
BOOST_ASSERT(&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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathNest::idxLast(Cursor & cur) const
|
2001-08-03 17:10:22 +00:00
|
|
|
|
{
|
2007-11-01 22:17:22 +00:00
|
|
|
|
BOOST_ASSERT(&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
|
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
|
odocstringstream oss;
|
2006-10-19 16:51:30 +00:00
|
|
|
|
WriteStream os(oss);
|
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";
|
2006-10-21 00:16:43 +00:00
|
|
|
|
lyxerr << to_utf8(oss.str());
|
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(),
|
2007-10-25 12:41:02 +00:00
|
|
|
|
Color_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
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor & cur = bv.cursor();
|
2004-02-02 17:32:56 +00:00
|
|
|
|
if (!cur.selection())
|
|
|
|
|
return;
|
2007-11-01 22:17:22 +00:00
|
|
|
|
if (&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
|
2007-11-06 14:07:49 +00:00
|
|
|
|
bool const original_drawing_state = pi.pain.isDrawingEnabled();
|
2006-10-30 10:09:59 +00:00
|
|
|
|
pi.pain.setDrawingEnabled(false);
|
|
|
|
|
draw(pi, x, y);
|
2007-11-06 14:07:49 +00:00
|
|
|
|
pi.pain.setDrawingEnabled(original_drawing_state);
|
2006-01-27 22:24:37 +00:00
|
|
|
|
|
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()) {
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData const & c = cell(s1.idx());
|
2007-09-24 13:52:04 +00:00
|
|
|
|
Geometry const & g = bv.coordCache().getArrays().geometry(&c);
|
2007-12-24 10:52:58 +00:00
|
|
|
|
int x1 = g.pos.x_ + c.pos2x(pi.base.bv, s1.pos());
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int y1 = g.pos.y_ - g.dim.ascent();
|
2007-12-24 10:52:58 +00:00
|
|
|
|
int x2 = g.pos.x_ + c.pos2x(pi.base.bv, s2.pos());
|
2007-09-24 13:52:04 +00:00
|
|
|
|
int y2 = g.pos.y_ + g.dim.descent();
|
2007-10-25 12:41:02 +00:00
|
|
|
|
pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, Color_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())) {
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData const & c = cell(i);
|
2007-09-24 13:52:04 +00:00
|
|
|
|
Geometry const & g = bv.coordCache().getArrays().geometry(&c);
|
|
|
|
|
int x1 = g.pos.x_;
|
|
|
|
|
int y1 = g.pos.y_ - g.dim.ascent();
|
|
|
|
|
int x2 = g.pos.x_ + g.dim.width();
|
|
|
|
|
int y2 = g.pos.y_ + g.dim.descent();
|
2007-10-25 12:41:02 +00:00
|
|
|
|
pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, Color_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
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
bool InsetMathNest::contains(MathData 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
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData InsetMathNest::glue() const
|
2002-06-18 15:44:30 +00:00
|
|
|
|
{
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData 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-10-19 16:51:30 +00:00
|
|
|
|
int InsetMathNest::latex(Buffer const &, odocstream & 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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-06-07 18:08:03 +00:00
|
|
|
|
bool InsetMathNest::setMouseHover(bool mouse_hover)
|
|
|
|
|
{
|
|
|
|
|
mouse_hover_ = mouse_hover;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-22 20:45:18 +00:00
|
|
|
|
bool InsetMathNest::notifyCursorLeaves(Cursor const & /*old*/, Cursor & /*cur*/)
|
2002-10-29 08:23:32 +00:00
|
|
|
|
{
|
2007-08-10 11:47:12 +00:00
|
|
|
|
// FIXME: look here
|
2004-04-08 15:03:33 +00:00
|
|
|
|
#if 0
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData & ar = cur.cell();
|
2004-04-05 16:31:52 +00:00
|
|
|
|
// 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) {
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar = p->nuc();
|
2004-04-05 16:31:52 +00:00
|
|
|
|
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
|
2007-04-26 14:56:30 +00:00
|
|
|
|
(Cursor & cur, docstring const & arg, char const * const font)
|
2006-10-22 10:15:23 +00:00
|
|
|
|
{
|
|
|
|
|
handleFont(cur, arg, from_ascii(font));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathNest::handleFont
|
2007-04-26 14:56:30 +00:00
|
|
|
|
(Cursor & cur, docstring const & arg, docstring const & font)
|
2004-01-30 11:41:12 +00:00
|
|
|
|
{
|
|
|
|
|
// this whole function is a hack and won't work for incremental font
|
|
|
|
|
// changes...
|
|
|
|
|
|
2006-12-29 11:07:23 +00:00
|
|
|
|
if (cur.inset().asInsetMath()->name() == font) {
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndoInset();
|
2006-10-22 10:15:23 +00:00
|
|
|
|
cur.handleFont(to_utf8(font));
|
2006-12-29 11:07:23 +00:00
|
|
|
|
} else {
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cur.handleNest(createInsetMath(font));
|
2004-01-30 11:41:12 +00:00
|
|
|
|
cur.insert(arg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetMathNest::handleFont2(Cursor & cur, docstring const & arg)
|
2004-01-30 11:41:12 +00:00
|
|
|
|
{
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2007-04-29 18:17:15 +00:00
|
|
|
|
Font font;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
bool b;
|
2007-09-29 11:00:18 +00:00
|
|
|
|
font.fromString(to_utf8(arg), b);
|
2007-10-28 18:51:54 +00:00
|
|
|
|
if (font.fontInfo().color() != Color_inherit) {
|
|
|
|
|
MathAtom at = MathAtom(new InsetMathColor(true, font.fontInfo().color()));
|
2005-06-17 14:35:19 +00:00
|
|
|
|
cur.handleNest(at, 0);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2002-08-15 10:02:53 +00:00
|
|
|
|
{
|
2007-12-12 19:28:07 +00:00
|
|
|
|
//lyxerr << "InsetMathNest: request: " << cmd << 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: {
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-09-11 08:54:10 +00:00
|
|
|
|
cur.message(_("Paste"));
|
2004-04-18 07:34:15 +00:00
|
|
|
|
replaceSelection(cur);
|
2007-01-04 12:05:24 +00:00
|
|
|
|
docstring topaste;
|
|
|
|
|
if (cmd.argument().empty() && !theClipboard().isInternal())
|
2007-01-13 18:29:50 +00:00
|
|
|
|
topaste = theClipboard().getAsText();
|
2007-01-04 12:05:24 +00:00
|
|
|
|
else {
|
|
|
|
|
size_t n = 0;
|
|
|
|
|
idocstringstream is(cmd.argument());
|
|
|
|
|
is >> n;
|
|
|
|
|
topaste = cap::getSelection(cur.buffer(), n);
|
|
|
|
|
}
|
|
|
|
|
cur.niceInsert(topaste);
|
2004-04-18 07:34:15 +00:00
|
|
|
|
cur.clearSelection(); // bug 393
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.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:
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
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-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;
|
|
|
|
|
|
2008-02-10 19:57:00 +00:00
|
|
|
|
case LFUN_FINISHED_LEFT: // in math, left is backwards
|
2007-10-22 22:18:52 +00:00
|
|
|
|
case LFUN_FINISHED_BACKWARD:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
cur.bv().cursor() = cur;
|
|
|
|
|
break;
|
|
|
|
|
|
2008-02-10 19:57:00 +00:00
|
|
|
|
case LFUN_FINISHED_RIGHT: // in math, right is forward
|
2007-10-22 22:18:52 +00:00
|
|
|
|
case LFUN_FINISHED_FORWARD:
|
2004-02-16 11:58:51 +00:00
|
|
|
|
++cur.pos();
|
|
|
|
|
cur.bv().cursor() = cur;
|
|
|
|
|
break;
|
|
|
|
|
|
2008-02-10 19:57:00 +00:00
|
|
|
|
case LFUN_CHAR_RIGHT:
|
|
|
|
|
case LFUN_CHAR_LEFT:
|
|
|
|
|
case LFUN_CHAR_BACKWARD:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_CHAR_FORWARD:
|
2007-01-20 01:23:07 +00:00
|
|
|
|
cur.updateFlags(Update::Decoration | Update::FitCursor);
|
2008-02-10 19:57:00 +00:00
|
|
|
|
case LFUN_CHAR_RIGHT_SELECT:
|
|
|
|
|
case LFUN_CHAR_LEFT_SELECT:
|
|
|
|
|
case LFUN_CHAR_BACKWARD_SELECT:
|
|
|
|
|
case LFUN_CHAR_FORWARD_SELECT: {
|
|
|
|
|
// are we in a selection?
|
|
|
|
|
bool select = (cmd.action == LFUN_CHAR_RIGHT_SELECT
|
|
|
|
|
|| cmd.action == LFUN_CHAR_LEFT_SELECT
|
|
|
|
|
|| cmd.action == LFUN_CHAR_BACKWARD_SELECT
|
|
|
|
|
|| cmd.action == LFUN_CHAR_FORWARD_SELECT);
|
|
|
|
|
// are we moving forward or backwards?
|
|
|
|
|
// If the command was RIGHT or LEFT, then whether we're moving forward
|
|
|
|
|
// or backwards depends on the cursor movement mode (logical or visual):
|
|
|
|
|
// * in visual mode, since math is always LTR, right -> forward,
|
|
|
|
|
// left -> backwards
|
|
|
|
|
// * in logical mode, the mapping is determined by the
|
|
|
|
|
// reverseDirectionNeeded() function
|
|
|
|
|
|
|
|
|
|
bool forward;
|
|
|
|
|
kb_action finish_lfun;
|
|
|
|
|
|
|
|
|
|
if (cmd.action == LFUN_CHAR_FORWARD
|
|
|
|
|
|| cmd.action == LFUN_CHAR_FORWARD_SELECT) {
|
|
|
|
|
forward = true;
|
|
|
|
|
finish_lfun = LFUN_FINISHED_FORWARD;
|
|
|
|
|
}
|
|
|
|
|
else if (cmd.action == LFUN_CHAR_BACKWARD
|
|
|
|
|
|| cmd.action == LFUN_CHAR_BACKWARD_SELECT) {
|
|
|
|
|
forward = false;
|
|
|
|
|
finish_lfun = LFUN_FINISHED_BACKWARD;
|
|
|
|
|
}
|
2005-07-18 00:09:20 +00:00
|
|
|
|
else {
|
2008-02-10 19:57:00 +00:00
|
|
|
|
bool right = (cmd.action == LFUN_CHAR_RIGHT_SELECT
|
|
|
|
|
|| cmd.action == LFUN_CHAR_RIGHT);
|
|
|
|
|
if (lyxrc.visual_cursor || !reverseDirectionNeeded(cur))
|
|
|
|
|
forward = right;
|
|
|
|
|
else
|
|
|
|
|
forward = !right;
|
|
|
|
|
|
|
|
|
|
if (right)
|
|
|
|
|
finish_lfun = LFUN_FINISHED_RIGHT;
|
|
|
|
|
else
|
|
|
|
|
finish_lfun = LFUN_FINISHED_LEFT;
|
2005-07-18 00:09:20 +00:00
|
|
|
|
}
|
2008-02-10 19:57:00 +00:00
|
|
|
|
// Now that we know exactly what we want to do, let's do it!
|
|
|
|
|
cur.selHandle(select);
|
2004-02-25 14:39:14 +00:00
|
|
|
|
cur.autocorrect() = false;
|
|
|
|
|
cur.clearTargetX();
|
2004-08-13 09:31:48 +00:00
|
|
|
|
cur.macroModeClose();
|
2008-02-10 19:57:00 +00:00
|
|
|
|
// try moving forward or backwards as necessary...
|
|
|
|
|
if (!(forward ? cursorMathForward(cur) : cursorMathBackward(cur))) {
|
|
|
|
|
// ... and if movement failed, then finish forward or backwards
|
|
|
|
|
// as necessary
|
|
|
|
|
cmd = FuncRequest(finish_lfun);
|
2005-07-18 00:09:20 +00:00
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2008-02-10 19:57:00 +00:00
|
|
|
|
}
|
2007-10-22 22:18:52 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
case LFUN_DOWN:
|
2007-06-14 20:32:28 +00:00
|
|
|
|
case LFUN_UP:
|
2007-01-20 01:23:07 +00:00
|
|
|
|
cur.updateFlags(Update::Decoration | Update::FitCursor);
|
2007-08-11 08:48:57 +00:00
|
|
|
|
case LFUN_DOWN_SELECT:
|
2007-06-14 20:32:28 +00:00
|
|
|
|
case LFUN_UP_SELECT: {
|
|
|
|
|
// close active macro
|
2005-04-08 12:15:28 +00:00
|
|
|
|
if (cur.inMacroMode()) {
|
|
|
|
|
cur.macroModeClose();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-06-14 20:32:28 +00:00
|
|
|
|
|
|
|
|
|
// stop/start the selection
|
|
|
|
|
bool select = cmd.action == LFUN_DOWN_SELECT ||
|
|
|
|
|
cmd.action == LFUN_UP_SELECT;
|
|
|
|
|
cur.selHandle(select);
|
|
|
|
|
|
|
|
|
|
// go up/down
|
|
|
|
|
bool up = cmd.action == LFUN_UP || cmd.action == LFUN_UP_SELECT;
|
|
|
|
|
bool successful = cur.upDownInMath(up);
|
2008-02-22 20:45:18 +00:00
|
|
|
|
if (successful)
|
2007-08-19 13:32:21 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (cur.fixIfBroken())
|
|
|
|
|
// FIXME: Something bad happened. We pass the corrected Cursor
|
|
|
|
|
// instead of letting things go worse.
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// We did not manage to move the cursor.
|
|
|
|
|
cur.undispatched();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2007-06-14 20:32:28 +00:00
|
|
|
|
}
|
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-05 20:23:12 +00:00
|
|
|
|
case LFUN_PARAGRAPH_UP:
|
|
|
|
|
case LFUN_PARAGRAPH_DOWN:
|
2007-01-20 01:23:07 +00:00
|
|
|
|
cur.updateFlags(Update::Decoration | Update::FitCursor);
|
2006-11-21 16:58:45 +00:00
|
|
|
|
case LFUN_PARAGRAPH_UP_SELECT:
|
|
|
|
|
case LFUN_PARAGRAPH_DOWN_SELECT:
|
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_LINE_BEGIN:
|
|
|
|
|
case LFUN_WORD_BACKWARD:
|
2007-10-28 20:35:57 +00:00
|
|
|
|
case LFUN_WORD_LEFT:
|
2007-01-20 01:23:07 +00:00
|
|
|
|
cur.updateFlags(Update::Decoration | Update::FitCursor);
|
2006-11-21 16:58:45 +00:00
|
|
|
|
case LFUN_LINE_BEGIN_SELECT:
|
|
|
|
|
case LFUN_WORD_BACKWARD_SELECT:
|
2007-10-28 20:35:57 +00:00
|
|
|
|
case LFUN_WORD_LEFT_SELECT:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT ||
|
2007-10-28 20:35:57 +00:00
|
|
|
|
cmd.action == LFUN_WORD_LEFT_SELECT ||
|
2006-05-08 18:09:19 +00:00
|
|
|
|
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 {
|
2007-10-22 22:18:52 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
|
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-05 20:23:12 +00:00
|
|
|
|
case LFUN_WORD_FORWARD:
|
2007-10-28 20:35:57 +00:00
|
|
|
|
case LFUN_WORD_RIGHT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_LINE_END:
|
2007-01-20 01:23:07 +00:00
|
|
|
|
cur.updateFlags(Update::Decoration | Update::FitCursor);
|
2006-11-21 16:58:45 +00:00
|
|
|
|
case LFUN_WORD_FORWARD_SELECT:
|
2007-10-28 20:35:57 +00:00
|
|
|
|
case LFUN_WORD_RIGHT_SELECT:
|
2006-11-21 16:58:45 +00:00
|
|
|
|
case LFUN_LINE_END_SELECT:
|
2006-05-08 18:09:19 +00:00
|
|
|
|
cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT ||
|
2007-10-28 20:35:57 +00:00
|
|
|
|
cmd.action == LFUN_WORD_RIGHT_SELECT ||
|
2006-05-08 18:09:19 +00:00
|
|
|
|
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 {
|
2007-10-22 22:18:52 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
|
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:
|
2007-10-22 22:18:52 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
|
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:
|
2007-10-22 22:18:52 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
|
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:
|
2007-01-20 01:23:07 +00:00
|
|
|
|
cur.updateFlags(Update::Decoration | Update::FitCursor);
|
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:
|
2007-01-20 01:23:07 +00:00
|
|
|
|
cur.updateFlags(Update::Decoration | Update::FitCursor);
|
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:
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndoInset();
|
2005-10-03 09:50:28 +00:00
|
|
|
|
else
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-11-19 18:33:13 +00:00
|
|
|
|
// if the inset can not be removed from within, delete it
|
|
|
|
|
if (!cur.backspace()) {
|
|
|
|
|
FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD);
|
2007-02-01 20:05:59 +00:00
|
|
|
|
cur.innerText()->dispatch(cur, cmd);
|
2006-11-19 18:33:13 +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_DELETE_FORWARD:
|
|
|
|
|
case LFUN_CHAR_DELETE_FORWARD:
|
2006-04-13 08:40:11 +00:00
|
|
|
|
if (cur.pos() == cur.lastpos())
|
|
|
|
|
// May affect external cell:
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndoInset();
|
2006-04-13 08:40:11 +00:00
|
|
|
|
else
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-11-19 18:33:13 +00:00
|
|
|
|
// if the inset can not be removed from within, delete it
|
|
|
|
|
if (!cur.erase()) {
|
|
|
|
|
FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD);
|
2007-02-01 20:05:59 +00:00
|
|
|
|
cur.innerText()->dispatch(cur, cmd);
|
2006-11-19 18:33:13 +00:00
|
|
|
|
}
|
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 {
|
2007-10-22 22:18:52 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
|
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
|
|
|
|
|
2007-12-10 19:50:12 +00:00
|
|
|
|
// 'Locks' the math inset. A 'locked' math inset behaves as a unit
|
|
|
|
|
// that is traversed by a single <CursorLeft>/<CursorRight>.
|
2004-01-26 10:13:15 +00:00
|
|
|
|
case LFUN_INSET_TOGGLE:
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-08-11 21:41:56 +00:00
|
|
|
|
lock(!lock());
|
2007-11-05 19:41:16 +00:00
|
|
|
|
cur.popForward();
|
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) {
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const arg = cmd.argument();
|
2006-10-19 16:38:13 +00:00
|
|
|
|
if (!interpretString(cur, arg))
|
2006-09-01 15:41:38 +00:00
|
|
|
|
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,
|
2007-04-26 14:56:30 +00:00
|
|
|
|
// e.g. sqrt. Cursor::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())
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
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();
|
2007-06-11 18:26:42 +00:00
|
|
|
|
if (atom->asNestInset() && atom->isActive()) {
|
2007-11-05 19:41:16 +00:00
|
|
|
|
cur.posBackward();
|
|
|
|
|
cur.pushBackward(*cur.nextInset());
|
2006-01-11 17:08:50 +00:00
|
|
|
|
}
|
2006-10-19 18:56:16 +00:00
|
|
|
|
} else if (!interpretChar(cur, cmd.argument()[0])) {
|
2007-10-22 22:18:52 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
|
2006-10-19 18:56:16 +00:00
|
|
|
|
cur.undispatched();
|
2005-07-18 00:09:20 +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_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-10-21 00:16:43 +00:00
|
|
|
|
istringstream is(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
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
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-10-22 10:15:23 +00:00
|
|
|
|
handleFont2(cur, 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-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, cmd.argument(), "textbf");
|
2005-06-24 10:14:33 +00:00
|
|
|
|
else
|
2006-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, 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-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, cmd.argument(), "textsf");
|
2005-06-24 10:14:33 +00:00
|
|
|
|
else
|
2006-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, 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-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, cmd.argument(), "emph");
|
2005-06-24 10:14:33 +00:00
|
|
|
|
else
|
2006-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, 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-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, cmd.argument(), "textrm");
|
2005-06-24 10:14:33 +00:00
|
|
|
|
else
|
2006-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, cmd.argument(), "mathrm");
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2007-09-20 18:02:39 +00:00
|
|
|
|
case LFUN_FONT_TYPEWRITER:
|
2005-07-15 16:52:27 +00:00
|
|
|
|
if (currentMode() == TEXT_MODE)
|
2006-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, cmd.argument(), "texttt");
|
2005-07-15 16:52:27 +00:00
|
|
|
|
else
|
2006-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, 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-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, 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-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, cmd.argument(), "textit");
|
2005-06-24 10:14:33 +00:00
|
|
|
|
else
|
2006-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, 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-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, cmd.argument(), "textsc");
|
2005-06-24 10:14:33 +00:00
|
|
|
|
else
|
2006-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, cmd.argument(), "mathbb");
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-12-30 21:05:44 +00:00
|
|
|
|
/*
|
|
|
|
|
case LFUN_FONT_FREE_APPLY:
|
2006-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, cmd.argument(), "textrm");
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2006-12-30 21:05:44 +00:00
|
|
|
|
*/
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_FONT_DEFAULT:
|
2006-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, 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
|
2007-04-29 13:39:47 +00:00
|
|
|
|
if (currentMode() == Inset::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-10-22 10:15:23 +00:00
|
|
|
|
docstring 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())));
|
2006-10-22 10:15:23 +00:00
|
|
|
|
cur.plainInsert(MathAtom(new InsetMathBox(from_ascii("mbox"))));
|
2007-11-05 19:41:16 +00:00
|
|
|
|
cur.posBackward();
|
|
|
|
|
cur.pushBackward(*cur.nextInset());
|
2006-03-20 14:42:04 +00:00
|
|
|
|
cur.niceInsert(save_selection);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
#else
|
2007-04-29 13:39:47 +00:00
|
|
|
|
if (currentMode() == Inset::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-10-22 10:15:23 +00:00
|
|
|
|
handleFont(cur, 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
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2004-04-18 19:41:40 +00:00
|
|
|
|
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: {
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
unsigned int m = 1;
|
|
|
|
|
unsigned int n = 1;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring v_align;
|
|
|
|
|
docstring h_align;
|
|
|
|
|
idocstringstream is(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-10-22 10:15:23 +00:00
|
|
|
|
MathAtom(new InsetMathArray(from_ascii("array"), m, n, (char)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: {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring ls;
|
2007-12-12 19:57:42 +00:00
|
|
|
|
docstring rs = split(cmd.argument(), ls, ' ');
|
2004-01-26 10:13:15 +00:00
|
|
|
|
// Reasonable default values
|
|
|
|
|
if (ls.empty())
|
|
|
|
|
ls = '(';
|
|
|
|
|
if (rs.empty())
|
|
|
|
|
rs = ')';
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
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: {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const lname = from_utf8(cmd.getArg(0));
|
|
|
|
|
docstring const ldelim = from_utf8(cmd.getArg(1));
|
|
|
|
|
docstring const rname = from_utf8(cmd.getArg(2));
|
|
|
|
|
docstring const rdelim = from_utf8(cmd.getArg(3));
|
2006-05-07 10:51:19 +00:00
|
|
|
|
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) {
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const selection = grabAndEraseSelection(cur);
|
2006-05-07 10:51:19 +00:00
|
|
|
|
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
|
2007-04-29 23:33:02 +00:00
|
|
|
|
// lead to infinite recursion via Text::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:
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-10-22 10:15:23 +00:00
|
|
|
|
cur.insert(MathAtom(new InsetMathSpace(from_ascii(","))));
|
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
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-10-19 16:38:13 +00:00
|
|
|
|
interpretChar(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
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-10-19 16:38:13 +00:00
|
|
|
|
interpretChar(cur, '_');
|
2005-01-04 09:18:48 +00:00
|
|
|
|
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
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-10-19 16:38:13 +00:00
|
|
|
|
interpretChar(cur, '^');
|
2005-01-04 09:18:48 +00:00
|
|
|
|
break;
|
2007-11-01 11:14:14 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_MATH_MACRO_FOLD:
|
|
|
|
|
case LFUN_MATH_MACRO_UNFOLD: {
|
|
|
|
|
Cursor it = cur;
|
|
|
|
|
bool fold = cmd.action == LFUN_MATH_MACRO_FOLD;
|
|
|
|
|
bool found = findMacroToFoldUnfold(it, fold);
|
|
|
|
|
if (found) {
|
2007-12-21 20:42:46 +00:00
|
|
|
|
MathMacro * macro = it.nextInset()->asInsetMath()->asMacro();
|
|
|
|
|
cur.recordUndoInset();
|
2007-11-01 11:14:14 +00:00
|
|
|
|
if (fold)
|
2007-12-21 20:42:46 +00:00
|
|
|
|
macro->fold(cur);
|
2007-11-01 11:14:14 +00:00
|
|
|
|
else
|
2007-12-21 20:42:46 +00:00
|
|
|
|
macro->unfold(cur);
|
|
|
|
|
}
|
2007-11-01 11:14:14 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2006-12-27 15:01:09 +00:00
|
|
|
|
case LFUN_QUOTE_INSERT:
|
|
|
|
|
// interpret this as if a straight " was typed
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-12-27 15:01:09 +00:00
|
|
|
|
interpretChar(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: {
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-10-19 16:38:13 +00:00
|
|
|
|
if (cmd.argument() == "^" || cmd.argument() == "_") {
|
2006-10-19 18:56:16 +00:00
|
|
|
|
interpretChar(cur, cmd.argument()[0]);
|
2006-10-19 16:38:13 +00:00
|
|
|
|
} else
|
2006-10-22 10:15:23 +00:00
|
|
|
|
cur.niceInsert(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-10-22 10:15:23 +00:00
|
|
|
|
docstring const & name = cmd.argument();
|
2004-01-26 10:13:15 +00:00
|
|
|
|
string data;
|
|
|
|
|
if (name == "ref") {
|
2007-04-28 20:49:56 +00:00
|
|
|
|
InsetMathRef tmp(name);
|
2006-10-22 10:15:23 +00:00
|
|
|
|
data = tmp.createDialogStr(to_utf8(name));
|
2004-01-26 10:13:15 +00:00
|
|
|
|
}
|
2007-11-18 00:39:15 +00:00
|
|
|
|
cur.bv().showDialog(to_utf8(name), data);
|
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: {
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-09-30 17:17:31 +00:00
|
|
|
|
cur.insert(ar);
|
|
|
|
|
} else
|
|
|
|
|
cur.undispatched();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-10-03 10:24:37 +00:00
|
|
|
|
case LFUN_INSET_DISSOLVE:
|
|
|
|
|
if (!asHullInset()) {
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndoInset();
|
2007-10-03 10:24:37 +00:00
|
|
|
|
cur.pullArg();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2006-09-30 17:17:31 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
default:
|
2007-04-30 10:31:51 +00:00
|
|
|
|
InsetMath::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
|
|
|
|
|
|
|
|
|
|
2007-11-01 11:14:14 +00:00
|
|
|
|
bool InsetMathNest::findMacroToFoldUnfold(Cursor & it, bool fold) const {
|
|
|
|
|
// look for macro to open/close, but stay in mathed
|
|
|
|
|
for (; !it.empty(); it.pop_back()) {
|
|
|
|
|
|
|
|
|
|
// go backward through the current cell
|
|
|
|
|
Inset * inset = it.nextInset();
|
|
|
|
|
while (inset && inset->asInsetMath()) {
|
|
|
|
|
MathMacro * macro = inset->asInsetMath()->asMacro();
|
|
|
|
|
if (macro) {
|
|
|
|
|
// found the an macro to open/close?
|
|
|
|
|
if (macro->folded() != fold)
|
|
|
|
|
return true;
|
|
|
|
|
|
2007-11-02 00:11:51 +00:00
|
|
|
|
// Wrong folding state.
|
|
|
|
|
// If this was the first we see in this slice, look further left,
|
|
|
|
|
// otherwise go up.
|
|
|
|
|
if (inset != it.nextInset())
|
|
|
|
|
break;
|
2007-11-01 11:14:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// go up if this was the left most position
|
|
|
|
|
if (it.pos() == 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// go left
|
|
|
|
|
it.pos()--;
|
|
|
|
|
inset = it.nextInset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathNest::getStatus(Cursor & 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-10-21 00:16:43 +00:00
|
|
|
|
string const arg = 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:
|
2007-09-20 18:02:39 +00:00
|
|
|
|
case LFUN_FONT_TYPEWRITER:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
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-10-21 00:16:43 +00:00
|
|
|
|
//flag.setOnOff(mathcursor::formula()->hullType() == 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_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;
|
2007-11-01 11:14:14 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_MATH_MACRO_FOLD:
|
|
|
|
|
case LFUN_MATH_MACRO_UNFOLD: {
|
|
|
|
|
Cursor it = cur;
|
|
|
|
|
bool found = findMacroToFoldUnfold(it, cmd.action == LFUN_MATH_MACRO_FOLD);
|
|
|
|
|
flag.enabled(found);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-06 11:04:56 +00:00
|
|
|
|
case LFUN_SPECIALCHAR_INSERT:
|
2007-05-15 17:33:42 +00:00
|
|
|
|
// FIXME: These would probably make sense in math-text mode
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-10-03 10:24:37 +00:00
|
|
|
|
case LFUN_INSET_DISSOLVE:
|
|
|
|
|
flag.enabled(!asHullInset());
|
|
|
|
|
break;
|
|
|
|
|
|
2004-03-18 13:57:20 +00:00
|
|
|
|
default:
|
|
|
|
|
ret = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-27 12:46:30 +00:00
|
|
|
|
|
2008-02-11 08:20:13 +00:00
|
|
|
|
void InsetMathNest::edit(Cursor & cur, bool front, EntryDirection entry_from)
|
2003-05-28 13:22:36 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
cur.push(*this);
|
2008-02-11 08:20:13 +00:00
|
|
|
|
bool enter_front = (entry_from == Inset::ENTRY_DIRECTION_RIGHT ||
|
|
|
|
|
(entry_from == Inset::ENTRY_DIRECTION_IGNORE && front));
|
2008-02-10 19:52:45 +00:00
|
|
|
|
cur.idx() = enter_front ? 0 : cur.lastidx();
|
|
|
|
|
cur.pos() = enter_front ? 0 : cur.lastpos();
|
2004-02-06 16:14:06 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset * InsetMathNest::editXY(Cursor & 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData & ar = cell(idx_min);
|
2005-07-15 00:39:44 +00:00
|
|
|
|
cur.push(*this);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
cur.idx() = idx_min;
|
2007-12-24 10:52:58 +00:00
|
|
|
|
cur.pos() = ar.x2pos(&cur.bv(), x - ar.xo(cur.bv()));
|
2006-10-13 16:44:44 +00:00
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetMathNest::lfunMousePress(Cursor & 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();
|
2007-10-13 09:04:52 +00:00
|
|
|
|
bool do_selection = cmd.button() == mouse_button::button1
|
|
|
|
|
&& cmd.argument() == "region-select";
|
|
|
|
|
bv.mouseSetCursor(cur, do_selection);
|
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;
|
2007-04-13 11:35:11 +00:00
|
|
|
|
// Update the cursor update flags as needed:
|
|
|
|
|
//
|
2007-08-13 15:38:32 +00:00
|
|
|
|
// Update::Decoration: tells to update the decoration
|
|
|
|
|
// (visual box corners that define
|
|
|
|
|
// the inset)/
|
|
|
|
|
// Update::FitCursor: adjust the screen to the cursor
|
|
|
|
|
// position if needed
|
2007-04-13 11:35:11 +00:00
|
|
|
|
// cur.result().update(): don't overwrite previously set flags.
|
2007-08-13 15:38:32 +00:00
|
|
|
|
cur.updateFlags(Update::Decoration | Update::FitCursor
|
|
|
|
|
| cur.result().update());
|
2006-08-22 13:58:09 +00:00
|
|
|
|
} else if (cmd.button() == mouse_button::button2) {
|
2007-02-02 03:10:15 +00:00
|
|
|
|
if (cap::selection()) {
|
2007-04-29 23:33:02 +00:00
|
|
|
|
// See comment in Text::dispatch why we do this
|
2007-02-02 03:10:15 +00:00
|
|
|
|
cap::copySelectionToStack();
|
|
|
|
|
cmd = FuncRequest(LFUN_PASTE, "0");
|
2007-08-13 15:38:32 +00:00
|
|
|
|
doDispatch(bv.cursor(), cmd);
|
|
|
|
|
} else {
|
|
|
|
|
MathData ar;
|
2006-10-17 14:46:45 +00:00
|
|
|
|
asArray(theSelection().get(), ar);
|
2007-08-13 15:38:32 +00:00
|
|
|
|
bv.cursor().insert(ar);
|
|
|
|
|
}
|
2004-02-06 16:14:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetMathNest::lfunMouseMotion(Cursor & 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) {
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor & 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;
|
2007-01-04 08:57:55 +00:00
|
|
|
|
} else
|
2004-11-30 01:59:49 +00:00
|
|
|
|
cur.undispatched();
|
2004-08-14 20:34:46 +00:00
|
|
|
|
}
|
2004-02-06 16:14:06 +00:00
|
|
|
|
}
|
2004-02-27 09:18:03 +00:00
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetMathNest::lfunMouseRelease(Cursor & 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-11-22 14:45:33 +00:00
|
|
|
|
if (!cur.selection())
|
|
|
|
|
cur.noUpdate();
|
2007-02-02 03:10:15 +00:00
|
|
|
|
else {
|
2007-04-26 14:56:30 +00:00
|
|
|
|
Cursor & bvcur = cur.bv().cursor();
|
2007-02-02 03:10:15 +00:00
|
|
|
|
bvcur.selection() = true;
|
|
|
|
|
}
|
2004-08-13 21:21:10 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cur.undispatched();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathNest::interpretChar(Cursor & cur, char_type c)
|
2004-02-27 09:18:03 +00:00
|
|
|
|
{
|
2005-07-15 08:51:34 +00:00
|
|
|
|
//lyxerr << "interpret 2: '" << c << "'" << endl;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring 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()) {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring 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
|
|
|
|
|
2007-04-02 15:21:36 +00:00
|
|
|
|
if (isAlphaASCII(c)) {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
cur.activeMacro()->setName(name + docstring(1, 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());
|
2006-10-22 10:15:23 +00:00
|
|
|
|
cur.activeMacro()->setName(name + docstring(1, c));
|
2004-02-27 09:18:03 +00:00
|
|
|
|
} else {
|
2004-04-18 07:34:15 +00:00
|
|
|
|
cur.backspace();
|
2006-10-22 10:15:23 +00:00
|
|
|
|
cur.niceInsert(createInsetMath(docstring(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-10-19 18:56:16 +00:00
|
|
|
|
// interpretString().
|
2006-04-20 09:55:45 +00:00
|
|
|
|
latexkeys const * l = in_word_set(name.substr(1));
|
|
|
|
|
if (name[0] == '\\' && l && l->inset == "big") {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring delim;
|
2006-04-20 09:55:45 +00:00
|
|
|
|
switch (c) {
|
|
|
|
|
case '{':
|
2006-10-22 10:15:23 +00:00
|
|
|
|
delim = from_ascii("\\{");
|
2006-04-20 09:55:45 +00:00
|
|
|
|
break;
|
|
|
|
|
case '}':
|
2006-10-22 10:15:23 +00:00
|
|
|
|
delim = from_ascii("\\}");
|
2006-04-20 09:55:45 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2006-10-22 10:15:23 +00:00
|
|
|
|
delim = docstring(1, c);
|
2006-04-20 09:55:45 +00:00
|
|
|
|
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 != ' ')
|
2006-10-19 16:38:13 +00:00
|
|
|
|
interpretChar(cur, c);
|
2004-02-27 09:18:03 +00:00
|
|
|
|
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-10-22 10:15:23 +00:00
|
|
|
|
cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), 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...
|
2006-11-21 16:58:45 +00:00
|
|
|
|
if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ') {
|
2004-02-27 09:18:03 +00:00
|
|
|
|
cur.insert(c);
|
2006-11-22 14:45:33 +00:00
|
|
|
|
// FIXME: we have to enable full redraw here because of the
|
|
|
|
|
// visual box corners that define the inset. If we know for
|
|
|
|
|
// sure that we stay within the same cell we can optimize for
|
|
|
|
|
// that using:
|
|
|
|
|
//cur.updateFlags(Update::SinglePar | Update::FitCursor);
|
2006-11-21 16:58:45 +00:00
|
|
|
|
}
|
2004-02-27 09:18:03 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
|
|
|
|
|
cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
|
2006-11-22 14:45:33 +00:00
|
|
|
|
// FIXME: we have to enable full redraw here because of the
|
|
|
|
|
// visual box corners that define the inset. If we know for
|
|
|
|
|
// sure that we stay within the same cell we can optimize for
|
|
|
|
|
// that using:
|
|
|
|
|
//cur.updateFlags(Update::SinglePar | Update::FitCursor);
|
2004-02-27 09:18:03 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2006-11-21 16:58:45 +00:00
|
|
|
|
|
2007-11-05 19:41:16 +00:00
|
|
|
|
if (cur.popForward()) {
|
2006-11-22 14:45:33 +00:00
|
|
|
|
// FIXME: we have to enable full redraw here because of the
|
|
|
|
|
// visual box corners that define the inset. If we know for
|
|
|
|
|
// sure that we stay within the same cell we can optimize for
|
|
|
|
|
// that using:
|
|
|
|
|
//cur.updateFlags(Update::FitCursor);
|
2004-02-27 09:18:03 +00:00
|
|
|
|
return true;
|
2006-11-21 16:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if we are at the very end, leave the formula
|
2004-02-27 09:18:03 +00:00
|
|
|
|
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-10-22 10:15:23 +00:00
|
|
|
|
cur.niceInsert(createInsetMath(docstring(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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetMathNest::interpretString(Cursor & cur, docstring 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-10-22 10:15:23 +00:00
|
|
|
|
docstring prev = asString(cur.cell()[cur.pos() - 1]);
|
2006-05-01 08:05:22 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
|
bool InsetMathNest::script(Cursor & cur, bool up,
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const & 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
|
2006-10-19 16:38:13 +00:00
|
|
|
|
interpretChar(cur, '_');
|
2004-02-27 09:18:03 +00:00
|
|
|
|
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();
|
2007-04-25 03:01:35 +00:00
|
|
|
|
// See comment in MathParser.cpp for special handling of {}-bases
|
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;
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
bool InsetMathNest::completionSupported(Cursor const & cur) const
|
|
|
|
|
{
|
|
|
|
|
return cur.inMacroMode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetMathNest::inlineCompletionSupported(Cursor const & cur) const
|
|
|
|
|
{
|
|
|
|
|
return cur.inMacroMode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetMathNest::automaticInlineCompletion() const
|
|
|
|
|
{
|
|
|
|
|
return lyxrc.completion_inline_math;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetMathNest::automaticPopupCompletion() const
|
|
|
|
|
{
|
|
|
|
|
return lyxrc.completion_popup_math;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-21 23:36:02 +00:00
|
|
|
|
Inset::CompletionList const * InsetMathNest::completionList(Cursor const & cur) const
|
2008-02-21 19:42:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (!cur.inMacroMode())
|
2008-02-21 23:36:02 +00:00
|
|
|
|
return 0;
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
2008-02-21 23:36:02 +00:00
|
|
|
|
return new MathCompletionList(cur);
|
2008-02-21 19:42:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetMathNest::completionPrefix(Cursor const & cur) const
|
|
|
|
|
{
|
|
|
|
|
if (!cur.inMacroMode())
|
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
|
|
return cur.activeMacro()->name();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetMathNest::insertCompletion(Cursor & cur, docstring const & s,
|
|
|
|
|
bool finished)
|
|
|
|
|
{
|
|
|
|
|
if (!cur.inMacroMode())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// append completion to active macro
|
|
|
|
|
InsetMathUnknown * inset = cur.activeMacro();
|
|
|
|
|
inset->setName(inset->name() + s);
|
|
|
|
|
|
|
|
|
|
// finish macro
|
|
|
|
|
if (finished) {
|
|
|
|
|
#if 0
|
|
|
|
|
// FIXME: this creates duplicates in the completion popup
|
|
|
|
|
// which looks ugly. Moreover the changes the list lengths
|
|
|
|
|
// which seems to
|
|
|
|
|
confuse the popup as well.
|
|
|
|
|
MathCompletionList::addToFavorites(inset->name());
|
|
|
|
|
#endif
|
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, " "));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathNest::completionPosAndDim(Cursor const & cur, int & x, int & y,
|
|
|
|
|
Dimension & dim) const
|
|
|
|
|
{
|
|
|
|
|
Inset const * inset = cur.activeMacro();
|
|
|
|
|
if (!inset)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// get inset dimensions
|
|
|
|
|
dim = cur.bv().coordCache().insets().dim(inset);
|
2008-02-21 19:45:05 +00:00
|
|
|
|
// FIXME: these 3 are no accurate, but should depend on the font.
|
|
|
|
|
// Now the popup jumps down if you enter a char with descent > 0.
|
|
|
|
|
dim.des += 3;
|
|
|
|
|
dim.asc += 3;
|
|
|
|
|
|
|
|
|
|
// and position
|
2008-02-21 19:42:34 +00:00
|
|
|
|
Point xy
|
|
|
|
|
= cur.bv().coordCache().insets().xy(inset);
|
|
|
|
|
x = xy.x_;
|
|
|
|
|
y = xy.y_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-10 19:57:00 +00:00
|
|
|
|
bool InsetMathNest::cursorMathForward(Cursor & cur)
|
|
|
|
|
{
|
|
|
|
|
if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
|
|
|
|
|
cur.pushBackward(*cur.nextAtom().nucleus());
|
|
|
|
|
cur.inset().idxFirst(cur);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (cur.posForward() || idxForward(cur) || cur.selection())
|
|
|
|
|
return true;
|
|
|
|
|
// try to pop forwards --- but don't pop out of math! leave that to
|
|
|
|
|
// the FINISH lfuns
|
|
|
|
|
int s = cur.depth() - 2;
|
|
|
|
|
if (s >= 0 && cur[s].inset().asInsetMath())
|
|
|
|
|
return cur.popForward();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetMathNest::cursorMathBackward(Cursor & cur)
|
|
|
|
|
{
|
|
|
|
|
if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
|
|
|
|
|
cur.posBackward();
|
|
|
|
|
cur.push(*cur.nextAtom().nucleus());
|
|
|
|
|
cur.inset().idxLast(cur);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (cur.posBackward() || idxBackward(cur) || cur.selection())
|
|
|
|
|
return true;
|
|
|
|
|
// try to pop backwards --- but don't pop out of math! leave that to
|
|
|
|
|
// the FINISH lfuns
|
|
|
|
|
int s = cur.depth() - 2;
|
|
|
|
|
if (s >= 0 && cur[s].inset().asInsetMath())
|
|
|
|
|
return cur.popBackward();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
MathCompletionList::MathCompletionList(Cursor const & cur)
|
|
|
|
|
{
|
|
|
|
|
// fill it with macros from the buffer
|
|
|
|
|
Buffer::MacroNameSet macros;
|
|
|
|
|
cur.buffer().listMacroNames(macros);
|
|
|
|
|
Buffer::MacroNameSet::const_iterator it;
|
|
|
|
|
for (it = macros.begin(); it != macros.end(); ++it) {
|
|
|
|
|
if (cur.buffer().getMacro(*it, cur, false))
|
|
|
|
|
locals.push_back("\\" + *it);
|
|
|
|
|
}
|
|
|
|
|
sort(locals.begin(), locals.end());
|
|
|
|
|
|
|
|
|
|
if (globals.size() > 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// fill in global macros
|
|
|
|
|
macros.clear();
|
|
|
|
|
MacroTable::globalMacros().getMacroNames(macros);
|
|
|
|
|
lyxerr << "Globals completion macros: ";
|
|
|
|
|
for (it = macros.begin(); it != macros.end(); ++it) {
|
|
|
|
|
lyxerr << "\\" + *it << " ";
|
|
|
|
|
globals.push_back("\\" + *it);
|
|
|
|
|
}
|
|
|
|
|
lyxerr << std::endl;
|
|
|
|
|
|
|
|
|
|
// fill in global commands
|
|
|
|
|
globals.push_back(from_ascii("\\boxed"));
|
|
|
|
|
globals.push_back(from_ascii("\\fbox"));
|
|
|
|
|
globals.push_back(from_ascii("\\framebox"));
|
|
|
|
|
globals.push_back(from_ascii("\\makebox"));
|
|
|
|
|
globals.push_back(from_ascii("\\kern"));
|
|
|
|
|
globals.push_back(from_ascii("\\xrightarrow"));
|
|
|
|
|
globals.push_back(from_ascii("\\xleftarrow"));
|
|
|
|
|
globals.push_back(from_ascii("\\split"));
|
|
|
|
|
globals.push_back(from_ascii("\\gathered"));
|
|
|
|
|
globals.push_back(from_ascii("\\aligned"));
|
|
|
|
|
globals.push_back(from_ascii("\\alignedat"));
|
|
|
|
|
globals.push_back(from_ascii("\\cases"));
|
|
|
|
|
globals.push_back(from_ascii("\\substack"));
|
|
|
|
|
globals.push_back(from_ascii("\\subarray"));
|
|
|
|
|
globals.push_back(from_ascii("\\array"));
|
|
|
|
|
globals.push_back(from_ascii("\\sqrt"));
|
|
|
|
|
globals.push_back(from_ascii("\\root"));
|
|
|
|
|
globals.push_back(from_ascii("\\tabular"));
|
|
|
|
|
globals.push_back(from_ascii("\\stackrel"));
|
|
|
|
|
globals.push_back(from_ascii("\\binom"));
|
|
|
|
|
globals.push_back(from_ascii("\\choose"));
|
|
|
|
|
globals.push_back(from_ascii("\\choose"));
|
|
|
|
|
globals.push_back(from_ascii("\\frac"));
|
|
|
|
|
globals.push_back(from_ascii("\\over"));
|
|
|
|
|
globals.push_back(from_ascii("\\nicefrac"));
|
|
|
|
|
globals.push_back(from_ascii("\\unitfrac"));
|
|
|
|
|
globals.push_back(from_ascii("\\unitfracthree"));
|
|
|
|
|
globals.push_back(from_ascii("\\unitone"));
|
|
|
|
|
globals.push_back(from_ascii("\\unittwo"));
|
|
|
|
|
globals.push_back(from_ascii("\\infer"));
|
|
|
|
|
globals.push_back(from_ascii("\\atop"));
|
|
|
|
|
globals.push_back(from_ascii("\\lefteqn"));
|
|
|
|
|
globals.push_back(from_ascii("\\boldsymbol"));
|
|
|
|
|
globals.push_back(from_ascii("\\color"));
|
|
|
|
|
globals.push_back(from_ascii("\\normalcolor"));
|
|
|
|
|
globals.push_back(from_ascii("\\textcolor"));
|
|
|
|
|
globals.push_back(from_ascii("\\dfrac"));
|
|
|
|
|
globals.push_back(from_ascii("\\tfrac"));
|
|
|
|
|
globals.push_back(from_ascii("\\dbinom"));
|
|
|
|
|
globals.push_back(from_ascii("\\tbinom"));
|
|
|
|
|
globals.push_back(from_ascii("\\hphantom"));
|
|
|
|
|
globals.push_back(from_ascii("\\phantom"));
|
|
|
|
|
globals.push_back(from_ascii("\\vphantom"));
|
|
|
|
|
WordList const & words = mathedWordList();
|
|
|
|
|
WordList::const_iterator it2;
|
|
|
|
|
lyxerr << "Globals completion commands: ";
|
|
|
|
|
for (it2 = words.begin(); it2 != words.end(); ++it2) {
|
|
|
|
|
globals.push_back("\\" + (*it2).first);
|
|
|
|
|
lyxerr << "\\" + (*it2).first << " ";
|
|
|
|
|
}
|
|
|
|
|
lyxerr << std::endl;
|
|
|
|
|
sort(globals.begin(), globals.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathCompletionList::~MathCompletionList()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_type MathCompletionList::size() const
|
|
|
|
|
{
|
2008-02-21 23:36:02 +00:00
|
|
|
|
return locals.size() + globals.size();
|
2008-02-21 19:42:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring MathCompletionList::data(size_t idx) const
|
|
|
|
|
{
|
|
|
|
|
size_t lsize = locals.size();
|
2008-02-21 23:36:02 +00:00
|
|
|
|
if (idx >= lsize)
|
|
|
|
|
return globals[idx - lsize];
|
2008-02-21 19:42:34 +00:00
|
|
|
|
else
|
2008-02-21 23:36:02 +00:00
|
|
|
|
return locals[idx];
|
2008-02-21 19:42:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string MathCompletionList::icon(size_t idx) const
|
|
|
|
|
{
|
|
|
|
|
// get the latex command
|
|
|
|
|
docstring cmd;
|
|
|
|
|
size_t lsize = locals.size();
|
2008-02-21 23:36:02 +00:00
|
|
|
|
if (idx >= lsize)
|
|
|
|
|
cmd = globals[idx - lsize];
|
2008-02-21 19:42:34 +00:00
|
|
|
|
else
|
2008-02-21 23:36:02 +00:00
|
|
|
|
cmd = locals[idx];
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
|
|
|
|
// get the icon resource name by stripping the backslash
|
|
|
|
|
return "images/math/" + to_utf8(cmd.substr(1)) + ".png";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<docstring> MathCompletionList::globals;
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|