2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-04-25 16:11:45 +00:00
|
|
|
|
* \file MathMacro.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.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
2007-11-01 11:13:07 +00:00
|
|
|
|
* \author Stefan Schimanski
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-08-02 11:30:30 +00:00
|
|
|
|
#include <config.h>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-04-25 16:11:45 +00:00
|
|
|
|
#include "MathMacro.h"
|
2008-03-15 00:22:54 +00:00
|
|
|
|
|
|
|
|
|
#include "MathCompletionList.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathExtern.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
|
#include "MathStream.h"
|
2008-03-15 00:22:54 +00:00
|
|
|
|
#include "MathSupport.h"
|
2004-04-13 06:27:29 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
2007-11-01 11:13:07 +00:00
|
|
|
|
#include "BufferView.h"
|
2008-01-14 21:53:49 +00:00
|
|
|
|
#include "CoordCache.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
|
#include "Cursor.h"
|
2007-11-01 11:13:07 +00:00
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
|
#include "FuncRequest.h"
|
2008-02-21 19:42:34 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
|
#include "LyXFunc.h"
|
|
|
|
|
#include "LyXRC.h"
|
2007-11-01 11:13:07 +00:00
|
|
|
|
#include "Undo.h"
|
|
|
|
|
|
2005-07-17 10:31:44 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
|
#include "support/debug.h"
|
2008-06-19 09:16:05 +00:00
|
|
|
|
#include "support/lassert.h"
|
|
|
|
|
#include "support/textutils.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
|
|
2008-05-06 10:36:32 +00:00
|
|
|
|
#include <ostream>
|
2007-11-01 11:13:07 +00:00
|
|
|
|
#include <vector>
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2006-08-13 22:54:59 +00:00
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
namespace lyx {
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
/// A proxy for the macro values
|
|
|
|
|
class ArgumentProxy : public InsetMath {
|
2007-04-17 16:52:43 +00:00
|
|
|
|
public:
|
|
|
|
|
///
|
2007-11-01 11:13:07 +00:00
|
|
|
|
ArgumentProxy(MathMacro & mathMacro, size_t idx)
|
2007-05-24 16:29:40 +00:00
|
|
|
|
: mathMacro_(mathMacro), idx_(idx) {}
|
2007-04-17 16:52:43 +00:00
|
|
|
|
///
|
2007-11-01 11:13:07 +00:00
|
|
|
|
ArgumentProxy(MathMacro & mathMacro, size_t idx, docstring const & def)
|
|
|
|
|
: mathMacro_(mathMacro), idx_(idx)
|
|
|
|
|
{
|
|
|
|
|
asArray(def, def_);
|
|
|
|
|
}
|
|
|
|
|
///
|
|
|
|
|
void metrics(MetricsInfo & mi, Dimension & dim) const {
|
|
|
|
|
mathMacro_.macro()->unlock();
|
2008-01-07 13:50:21 +00:00
|
|
|
|
if (!mathMacro_.editMetrics(mi.base.bv)
|
|
|
|
|
&& mathMacro_.cell(idx_).empty())
|
2007-11-01 11:13:07 +00:00
|
|
|
|
def_.metrics(mi, dim);
|
2008-01-14 21:53:49 +00:00
|
|
|
|
else {
|
|
|
|
|
CoordCache & coords = mi.base.bv->coordCache();
|
|
|
|
|
dim = coords.arrays().dim(&mathMacro_.cell(idx_));
|
|
|
|
|
}
|
2007-11-01 11:13:07 +00:00
|
|
|
|
mathMacro_.macro()->lock();
|
|
|
|
|
}
|
|
|
|
|
///
|
|
|
|
|
void draw(PainterInfo & pi, int x, int y) const {
|
2007-12-24 10:54:39 +00:00
|
|
|
|
if (mathMacro_.editMetrics(pi.base.bv)) {
|
2007-11-08 10:14:18 +00:00
|
|
|
|
// The only way a ArgumentProxy can appear is in a cell of the
|
|
|
|
|
// MathMacro. Moreover the cells are only drawn in the DISPLAY_FOLDED
|
2007-12-24 10:54:39 +00:00
|
|
|
|
// mode and then, if the macro is edited the monochrome
|
2007-11-08 10:14:18 +00:00
|
|
|
|
// mode is entered by the MathMacro before calling the cells' draw
|
|
|
|
|
// method. Then eventually this code is reached and the proxy leaves
|
|
|
|
|
// monochrome mode temporarely. Hence, if it is not in monochrome
|
|
|
|
|
// here (and the assert triggers in pain.leaveMonochromeMode())
|
|
|
|
|
// it's a bug.
|
2007-11-01 11:13:07 +00:00
|
|
|
|
pi.pain.leaveMonochromeMode();
|
|
|
|
|
mathMacro_.cell(idx_).draw(pi, x, y);
|
|
|
|
|
pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
|
2008-01-07 13:50:21 +00:00
|
|
|
|
} else if (mathMacro_.cell(idx_).empty()) {
|
|
|
|
|
mathMacro_.cell(idx_).setXY(*pi.base.bv, x, y);
|
|
|
|
|
def_.draw(pi, x, y);
|
|
|
|
|
} else
|
|
|
|
|
mathMacro_.cell(idx_).draw(pi, x, y);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
}
|
2007-04-17 16:52:43 +00:00
|
|
|
|
///
|
2007-11-01 11:13:07 +00:00
|
|
|
|
size_t idx() const { return idx_; }
|
2007-06-15 18:26:35 +00:00
|
|
|
|
///
|
2007-12-24 10:54:39 +00:00
|
|
|
|
int kerning(BufferView const * bv) const
|
|
|
|
|
{
|
2008-01-07 13:50:21 +00:00
|
|
|
|
if (mathMacro_.editMetrics(bv)
|
|
|
|
|
|| !mathMacro_.cell(idx_).empty())
|
2007-12-24 10:54:39 +00:00
|
|
|
|
return mathMacro_.cell(idx_).kerning(bv);
|
|
|
|
|
else
|
|
|
|
|
return def_.kerning(bv);
|
|
|
|
|
}
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-04-17 16:52:43 +00:00
|
|
|
|
private:
|
2007-11-01 11:13:07 +00:00
|
|
|
|
///
|
|
|
|
|
Inset * clone() const
|
|
|
|
|
{
|
|
|
|
|
return new ArgumentProxy(*this);
|
|
|
|
|
}
|
|
|
|
|
///
|
|
|
|
|
MathMacro & mathMacro_;
|
|
|
|
|
///
|
2007-05-24 16:29:40 +00:00
|
|
|
|
size_t idx_;
|
2007-11-01 11:13:07 +00:00
|
|
|
|
///
|
|
|
|
|
MathData def_;
|
2007-04-17 16:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
MathMacro::MathMacro(docstring const & name)
|
|
|
|
|
: InsetMathNest(0), name_(name), displayMode_(DISPLAY_INIT),
|
2007-12-21 20:44:37 +00:00
|
|
|
|
attachedArgsNum_(0), optionals_(0), nextFoldMode_(true),
|
2008-03-04 14:49:03 +00:00
|
|
|
|
macro_(0), needsUpdate_(false), appetite_(9)
|
2001-07-12 11:55:57 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * MathMacro::clone() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-11-01 11:13:07 +00:00
|
|
|
|
MathMacro * copy = new MathMacro(*this);
|
|
|
|
|
copy->needsUpdate_ = true;
|
|
|
|
|
copy->expanded_.cell(0).clear();
|
|
|
|
|
return copy;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-09 09:19:18 +00:00
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring MathMacro::name() const
|
2001-08-08 17:26:30 +00:00
|
|
|
|
{
|
2008-06-19 09:16:05 +00:00
|
|
|
|
if (displayMode_ == DISPLAY_UNFOLDED
|
|
|
|
|
&& (name_.size() > 1 || (name_[0] != '_' && name_[0] != '^')))
|
2007-11-01 11:13:07 +00:00
|
|
|
|
return asString(cell(0));
|
2008-06-19 09:16:05 +00:00
|
|
|
|
|
|
|
|
|
return name_;
|
2001-08-08 17:26:30 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-08-09 09:19:18 +00:00
|
|
|
|
|
2006-10-17 16:23:27 +00:00
|
|
|
|
void MathMacro::cursorPos(BufferView const & bv,
|
|
|
|
|
CursorSlice const & sl, bool boundary, int & x, int & y) const
|
2005-10-05 21:19:32 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
// We may have 0 arguments, but InsetMathNest requires at least one.
|
2005-10-05 21:19:32 +00:00
|
|
|
|
if (nargs() > 0)
|
2006-10-17 16:23:27 +00:00
|
|
|
|
InsetMathNest::cursorPos(bv, sl, boundary, x, y);
|
2005-10-05 21:19:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-24 10:54:39 +00:00
|
|
|
|
bool MathMacro::editMode(BufferView const * bv) const {
|
2007-11-01 11:13:07 +00:00
|
|
|
|
// find this in cursor trace
|
2007-12-24 10:54:39 +00:00
|
|
|
|
Cursor const & cur = bv->cursor();
|
2007-11-01 11:13:07 +00:00
|
|
|
|
for (size_t i = 0; i != cur.depth(); ++i)
|
|
|
|
|
if (&cur[i].inset() == this) {
|
|
|
|
|
// look if there is no other macro in edit mode above
|
|
|
|
|
++i;
|
|
|
|
|
for (; i != cur.depth(); ++i) {
|
|
|
|
|
MathMacro const * macro = dynamic_cast<MathMacro const *>(&cur[i].inset());
|
|
|
|
|
if (macro && macro->displayMode() == DISPLAY_NORMAL)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ok, none found, I am the highest one
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-24 10:54:39 +00:00
|
|
|
|
bool MathMacro::editMetrics(BufferView const * bv) const
|
|
|
|
|
{
|
|
|
|
|
return editing_[bv];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
|
void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-03-25 12:11:25 +00:00
|
|
|
|
{
|
2007-12-24 10:54:39 +00:00
|
|
|
|
// set edit mode for which we will have calculated metrics. But only
|
|
|
|
|
editing_[mi.base.bv] = editMode(mi.base.bv);
|
2007-12-22 14:39:47 +00:00
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
// calculate new metrics according to display mode
|
2007-11-14 17:33:49 +00:00
|
|
|
|
if (displayMode_ == DISPLAY_INIT || displayMode_ == DISPLAY_INTERACTIVE_INIT) {
|
2007-11-01 11:13:07 +00:00
|
|
|
|
mathed_string_dim(mi.base.font, from_ascii("\\") + name(), dim);
|
|
|
|
|
} else if (displayMode_ == DISPLAY_UNFOLDED) {
|
|
|
|
|
cell(0).metrics(mi, dim);
|
|
|
|
|
Dimension bsdim;
|
|
|
|
|
mathed_string_dim(mi.base.font, from_ascii("\\"), bsdim);
|
|
|
|
|
dim.wid += bsdim.width() + 1;
|
2007-12-12 19:28:07 +00:00
|
|
|
|
dim.asc = max(bsdim.ascent(), dim.ascent());
|
|
|
|
|
dim.des = max(bsdim.descent(), dim.descent());
|
2007-11-01 11:13:07 +00:00
|
|
|
|
metricsMarkers(dim);
|
2008-01-25 22:02:38 +00:00
|
|
|
|
} else if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST
|
|
|
|
|
&& editing_[mi.base.bv]) {
|
|
|
|
|
// Macro will be edited in a old-style list mode here:
|
|
|
|
|
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(macro_ != 0, /**/);
|
2008-01-25 22:02:38 +00:00
|
|
|
|
Dimension fontDim;
|
|
|
|
|
FontInfo labelFont = sane_font;
|
|
|
|
|
math_font_max_dim(labelFont, fontDim.asc, fontDim.des);
|
|
|
|
|
|
|
|
|
|
// get dimension of components of list view
|
|
|
|
|
Dimension nameDim;
|
|
|
|
|
nameDim.wid = mathed_string_width(mi.base.font, from_ascii("Macro \\") + name() + ": ");
|
|
|
|
|
nameDim.asc = fontDim.asc;
|
|
|
|
|
nameDim.des = fontDim.des;
|
|
|
|
|
|
|
|
|
|
Dimension argDim;
|
|
|
|
|
argDim.wid = mathed_string_width(labelFont, from_ascii("#9: "));
|
|
|
|
|
argDim.asc = fontDim.asc;
|
|
|
|
|
argDim.des = fontDim.des;
|
|
|
|
|
|
|
|
|
|
Dimension defDim;
|
|
|
|
|
definition_.metrics(mi, defDim);
|
|
|
|
|
|
|
|
|
|
// add them up
|
|
|
|
|
dim.wid = nameDim.wid + defDim.wid;
|
|
|
|
|
dim.asc = max(nameDim.asc, defDim.asc);
|
|
|
|
|
dim.des = max(nameDim.des, defDim.des);
|
|
|
|
|
|
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i) {
|
|
|
|
|
Dimension cdim;
|
|
|
|
|
cell(i).metrics(mi, cdim);
|
|
|
|
|
dim.des += max(argDim.height(), cdim.height()) + 1;
|
|
|
|
|
dim.wid = max(dim.wid, argDim.wid + cdim.wid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// make space for box and markers, 2 pixels
|
|
|
|
|
dim.asc += 1;
|
|
|
|
|
dim.des += 1;
|
|
|
|
|
dim.wid += 2;
|
|
|
|
|
metricsMarkers2(dim);
|
2004-04-13 13:54:58 +00:00
|
|
|
|
} else {
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(macro_ != 0, /**/);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2008-01-14 21:53:49 +00:00
|
|
|
|
// metrics are computed here for the cells,
|
|
|
|
|
// in the proxy we will then use the dim from the cache
|
|
|
|
|
InsetMathNest::metrics(mi);
|
|
|
|
|
|
2007-12-24 10:54:39 +00:00
|
|
|
|
// calculate metrics finally
|
2007-11-01 11:13:07 +00:00
|
|
|
|
macro_->lock();
|
|
|
|
|
expanded_.cell(0).metrics(mi, dim);
|
|
|
|
|
macro_->unlock();
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
// calculate dimension with label while editing
|
2008-01-25 22:02:38 +00:00
|
|
|
|
if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX
|
|
|
|
|
&& editing_[mi.base.bv]) {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
FontInfo font = mi.base.font;
|
2007-04-17 16:52:43 +00:00
|
|
|
|
augmentFont(font, from_ascii("lyxtex"));
|
2007-11-01 11:13:07 +00:00
|
|
|
|
Dimension namedim;
|
|
|
|
|
mathed_string_dim(font, name(), namedim);
|
|
|
|
|
#if 0
|
|
|
|
|
dim.wid += 2 + namedim.wid + 2 + 2;
|
2007-12-12 19:28:07 +00:00
|
|
|
|
dim.asc = max(dim.asc, namedim.asc) + 2;
|
|
|
|
|
dim.des = max(dim.des, namedim.des) + 2;
|
2007-11-01 11:13:07 +00:00
|
|
|
|
#endif
|
2007-12-12 19:28:07 +00:00
|
|
|
|
dim.wid = max(1 + namedim.wid + 1, 2 + dim.wid + 2);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
dim.asc += 1 + namedim.height() + 1;
|
|
|
|
|
dim.des += 2;
|
2007-04-17 16:52:43 +00:00
|
|
|
|
}
|
2008-01-25 22:02:38 +00:00
|
|
|
|
|
2004-04-13 13:54:58 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-22 14:39:22 +00:00
|
|
|
|
int MathMacro::kerning(BufferView const * bv) const {
|
2007-12-24 10:54:39 +00:00
|
|
|
|
if (displayMode_ == DISPLAY_NORMAL && !editing_[bv])
|
2007-12-22 14:39:22 +00:00
|
|
|
|
return expanded_.kerning(bv);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-21 20:42:46 +00:00
|
|
|
|
void MathMacro::updateMacro(MacroContext const & mc)
|
2000-02-10 17:53:36 +00:00
|
|
|
|
{
|
2007-12-21 20:42:46 +00:00
|
|
|
|
if (validName()) {
|
|
|
|
|
macro_ = mc.get(name());
|
|
|
|
|
if (macro_ && macroBackup_ != *macro_) {
|
2007-11-01 11:13:07 +00:00
|
|
|
|
macroBackup_ = *macro_;
|
|
|
|
|
needsUpdate_ = true;
|
|
|
|
|
}
|
2004-04-13 13:54:58 +00:00
|
|
|
|
} else {
|
2007-11-01 11:13:07 +00:00
|
|
|
|
macro_ = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
|
2008-03-04 14:57:46 +00:00
|
|
|
|
void MathMacro::updateRepresentation()
|
2007-11-01 11:13:07 +00:00
|
|
|
|
{
|
|
|
|
|
// known macro?
|
2007-12-21 20:42:46 +00:00
|
|
|
|
if (macro_ == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// update requires
|
|
|
|
|
requires_ = macro_->requires();
|
|
|
|
|
|
|
|
|
|
// non-normal mode? We are done!
|
|
|
|
|
if (displayMode_ != DISPLAY_NORMAL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// macro changed?
|
2008-03-04 14:57:46 +00:00
|
|
|
|
if (!needsUpdate_)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
needsUpdate_ = false;
|
|
|
|
|
|
|
|
|
|
// get default values of macro
|
|
|
|
|
vector<docstring> const & defaults = macro_->defaults();
|
|
|
|
|
|
|
|
|
|
// create MathMacroArgumentValue objects pointing to the cells of the macro
|
|
|
|
|
vector<MathData> values(nargs());
|
|
|
|
|
for (size_t i = 0; i < nargs(); ++i) {
|
|
|
|
|
ArgumentProxy * proxy;
|
|
|
|
|
if (i < defaults.size())
|
|
|
|
|
proxy = new ArgumentProxy(*this, i, defaults[i]);
|
|
|
|
|
else
|
|
|
|
|
proxy = new ArgumentProxy(*this, i);
|
|
|
|
|
values[i].insert(0, MathAtom(proxy));
|
2008-01-14 21:53:49 +00:00
|
|
|
|
}
|
2008-03-04 14:57:46 +00:00
|
|
|
|
|
|
|
|
|
// expanding macro with the values
|
|
|
|
|
macro_->expand(values, expanded_.cell(0));
|
|
|
|
|
// get definition for list edit mode
|
|
|
|
|
docstring const & display = macro_->display();
|
|
|
|
|
asArray(display.empty() ? macro_->definition() : display, definition_);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacro::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
|
|
|
|
|
|
setPosCache(pi, x, y);
|
|
|
|
|
int expx = x;
|
|
|
|
|
int expy = y;
|
|
|
|
|
|
2007-11-14 17:33:49 +00:00
|
|
|
|
if (displayMode_ == DISPLAY_INIT || displayMode_ == DISPLAY_INTERACTIVE_INIT) {
|
2008-07-05 23:29:48 +00:00
|
|
|
|
FontSetChanger dummy(pi.base, "lyxtex");
|
|
|
|
|
pi.pain.text(x, y, from_ascii("\\") + name(), pi.base.font);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
} else if (displayMode_ == DISPLAY_UNFOLDED) {
|
2008-07-05 23:29:48 +00:00
|
|
|
|
FontSetChanger dummy(pi.base, "lyxtex");
|
|
|
|
|
pi.pain.text(x, y, from_ascii("\\"), pi.base.font);
|
|
|
|
|
x += mathed_string_width(pi.base.font, from_ascii("\\")) + 1;
|
|
|
|
|
cell(0).draw(pi, x, y);
|
|
|
|
|
drawMarkers(pi, expx, expy);
|
2008-01-25 22:02:38 +00:00
|
|
|
|
} else if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST
|
|
|
|
|
&& editing_[pi.base.bv]) {
|
|
|
|
|
// Macro will be edited in a old-style list mode here:
|
|
|
|
|
|
|
|
|
|
CoordCache & coords = pi.base.bv->coordCache();
|
|
|
|
|
FontInfo const & labelFont = sane_font;
|
|
|
|
|
|
|
|
|
|
// markers and box needs two pixels
|
|
|
|
|
x += 2;
|
|
|
|
|
|
|
|
|
|
// get maximal font height
|
|
|
|
|
Dimension fontDim;
|
|
|
|
|
math_font_max_dim(pi.base.font, fontDim.asc, fontDim.des);
|
|
|
|
|
|
|
|
|
|
// draw label
|
|
|
|
|
docstring label = from_ascii("Macro \\") + name() + from_ascii(": ");
|
|
|
|
|
pi.pain.text(x, y, label, labelFont);
|
|
|
|
|
x += mathed_string_width(labelFont, label);
|
|
|
|
|
|
|
|
|
|
// draw definition
|
|
|
|
|
definition_.draw(pi, x, y);
|
|
|
|
|
Dimension defDim
|
|
|
|
|
= coords.arrays().dim(&definition_);
|
|
|
|
|
y += max(fontDim.des, defDim.des);
|
|
|
|
|
|
|
|
|
|
// draw parameters
|
|
|
|
|
docstring str = from_ascii("#9");
|
|
|
|
|
int strw1 = mathed_string_width(labelFont, from_ascii("#9"));
|
|
|
|
|
int strw2 = mathed_string_width(labelFont, from_ascii(": "));
|
|
|
|
|
|
|
|
|
|
for (idx_type i = 0; i < nargs(); ++i) {
|
|
|
|
|
// position of label
|
|
|
|
|
Dimension cdim
|
|
|
|
|
= coords.arrays().dim(&cell(i));
|
|
|
|
|
x = expx + 2;
|
|
|
|
|
y += max(fontDim.asc, cdim.asc) + 1;
|
|
|
|
|
|
|
|
|
|
// draw label
|
|
|
|
|
str[1] = '1' + i;
|
|
|
|
|
pi.pain.text(x, y, str, labelFont);
|
|
|
|
|
x += strw1;
|
|
|
|
|
pi.pain.text(x, y, from_ascii(":"), labelFont);
|
|
|
|
|
x += strw2;
|
|
|
|
|
|
|
|
|
|
// draw paramter
|
|
|
|
|
cell(i).draw(pi, x, y);
|
|
|
|
|
|
|
|
|
|
// next line
|
|
|
|
|
y += max(fontDim.des, cdim.des);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pi.pain.rectangle(expx + 1, expy - dim.asc + 1, dim.wid - 3,
|
|
|
|
|
dim.height() - 2, Color_mathmacroframe);
|
|
|
|
|
drawMarkers2(pi, expx, expy);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
} else {
|
2008-01-25 22:02:38 +00:00
|
|
|
|
bool drawBox = lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX;
|
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
// warm up cells
|
2007-05-24 16:29:40 +00:00
|
|
|
|
for (size_t i = 0; i < nargs(); ++i)
|
|
|
|
|
cell(i).setXY(*pi.base.bv, x, y);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2008-01-25 22:02:38 +00:00
|
|
|
|
if (drawBox && editing_[pi.base.bv]) {
|
2007-11-01 11:13:07 +00:00
|
|
|
|
// draw header and rectangle around
|
2007-10-28 18:51:54 +00:00
|
|
|
|
FontInfo font = pi.base.font;
|
2007-04-17 16:52:43 +00:00
|
|
|
|
augmentFont(font, from_ascii("lyxtex"));
|
2007-11-01 11:13:07 +00:00
|
|
|
|
font.setSize(FONT_SIZE_TINY);
|
|
|
|
|
font.setColor(Color_mathmacrolabel);
|
|
|
|
|
Dimension namedim;
|
|
|
|
|
mathed_string_dim(font, name(), namedim);
|
2008-01-22 21:23:41 +00:00
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
pi.pain.fillRectangle(x, y - dim.asc, dim.wid, 1 + namedim.height() + 1, Color_mathmacrobg);
|
|
|
|
|
pi.pain.text(x + 1, y - dim.asc + namedim.asc + 2, name(), font);
|
|
|
|
|
expx += (dim.wid - expanded_.cell(0).dimension(*pi.base.bv).width()) / 2;
|
2008-01-22 21:23:41 +00:00
|
|
|
|
}
|
2007-11-01 11:13:07 +00:00
|
|
|
|
|
2008-01-22 21:23:41 +00:00
|
|
|
|
if (editing_[pi.base.bv]) {
|
2007-11-01 11:13:07 +00:00
|
|
|
|
pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
|
|
|
|
|
expanded_.cell(0).draw(pi, expx, expy);
|
|
|
|
|
pi.pain.leaveMonochromeMode();
|
2008-01-22 21:23:41 +00:00
|
|
|
|
|
2008-01-25 22:02:38 +00:00
|
|
|
|
if (drawBox)
|
2008-01-22 21:23:41 +00:00
|
|
|
|
pi.pain.rectangle(x, y - dim.asc, dim.wid,
|
|
|
|
|
dim.height(), Color_mathmacroframe);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
} else
|
|
|
|
|
expanded_.cell(0).draw(pi, expx, expy);
|
|
|
|
|
|
2008-01-25 22:02:38 +00:00
|
|
|
|
if (!drawBox)
|
2008-01-22 21:23:41 +00:00
|
|
|
|
drawMarkers(pi, x, y);
|
2004-04-13 13:54:58 +00:00
|
|
|
|
}
|
2007-11-01 11:13:07 +00:00
|
|
|
|
|
2008-01-14 21:53:49 +00:00
|
|
|
|
// edit mode changed?
|
|
|
|
|
if (editing_[pi.base.bv] != editMode(pi.base.bv))
|
2008-03-03 15:21:13 +00:00
|
|
|
|
pi.base.bv->cursor().updateFlags(Update::SinglePar);
|
2001-04-24 16:13:38 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-04-25 15:43:57 +00:00
|
|
|
|
|
2005-10-05 21:19:32 +00:00
|
|
|
|
void MathMacro::drawSelection(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
// We may have 0 arguments, but InsetMathNest requires at least one.
|
2007-11-01 11:13:07 +00:00
|
|
|
|
if (cells_.size() > 0)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathNest::drawSelection(pi, x, y);
|
2005-10-05 21:19:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-04 14:49:03 +00:00
|
|
|
|
void MathMacro::setDisplayMode(MathMacro::DisplayMode mode, int appetite)
|
2007-11-01 11:13:07 +00:00
|
|
|
|
{
|
|
|
|
|
if (displayMode_ != mode) {
|
|
|
|
|
// transfer name if changing from or to DISPLAY_UNFOLDED
|
|
|
|
|
if (mode == DISPLAY_UNFOLDED) {
|
|
|
|
|
cells_.resize(1);
|
|
|
|
|
asArray(name_, cell(0));
|
|
|
|
|
} else if (displayMode_ == DISPLAY_UNFOLDED) {
|
|
|
|
|
name_ = asString(cell(0));
|
|
|
|
|
cells_.resize(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
displayMode_ = mode;
|
|
|
|
|
needsUpdate_ = true;
|
|
|
|
|
}
|
2008-03-04 14:49:03 +00:00
|
|
|
|
|
|
|
|
|
// the interactive init mode is non-greedy by default
|
|
|
|
|
if (appetite == -1)
|
|
|
|
|
appetite_ = (mode == DISPLAY_INTERACTIVE_INIT) ? 0 : 9;
|
|
|
|
|
else
|
|
|
|
|
appetite_ = size_t(appetite);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-21 20:42:46 +00:00
|
|
|
|
MathMacro::DisplayMode MathMacro::computeDisplayMode() const
|
2007-11-01 11:13:07 +00:00
|
|
|
|
{
|
|
|
|
|
if (nextFoldMode_ == true && macro_ && !macro_->locked())
|
|
|
|
|
return DISPLAY_NORMAL;
|
|
|
|
|
else
|
|
|
|
|
return DISPLAY_UNFOLDED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathMacro::validName() const
|
|
|
|
|
{
|
|
|
|
|
docstring n = name();
|
|
|
|
|
|
|
|
|
|
// empty name?
|
|
|
|
|
if (n.size() == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// converting back and force doesn't swallow anything?
|
|
|
|
|
/*MathData ma;
|
|
|
|
|
asArray(n, ma);
|
|
|
|
|
if (asString(ma) != n)
|
|
|
|
|
return false;*/
|
|
|
|
|
|
|
|
|
|
// valid characters?
|
|
|
|
|
for (size_t i = 0; i<n.size(); ++i) {
|
2008-02-27 10:43:29 +00:00
|
|
|
|
if (!(n[i] >= 'a' && n[i] <= 'z')
|
|
|
|
|
&& !(n[i] >= 'A' && n[i] <= 'Z')
|
|
|
|
|
&& n[i] != '*')
|
2007-11-01 11:13:07 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
|
void MathMacro::validate(LaTeXFeatures & features) const
|
2001-07-13 14:54:56 +00:00
|
|
|
|
{
|
2007-11-01 11:13:07 +00:00
|
|
|
|
if (!requires_.empty())
|
|
|
|
|
features.require(requires_);
|
2007-05-04 15:30:27 +00:00
|
|
|
|
|
2002-04-03 10:45:32 +00:00
|
|
|
|
if (name() == "binom" || name() == "mathcircumflex")
|
2006-10-22 10:15:23 +00:00
|
|
|
|
features.require(to_utf8(name()));
|
2008-03-26 12:55:36 +00:00
|
|
|
|
|
|
|
|
|
// validate the cells and the definition
|
|
|
|
|
if (displayMode() == DISPLAY_NORMAL) {
|
|
|
|
|
definition_.validate(features);
|
|
|
|
|
InsetMathNest::validate(features);
|
|
|
|
|
}
|
2001-07-13 14:54:56 +00:00
|
|
|
|
}
|
2001-11-16 08:26:41 +00:00
|
|
|
|
|
|
|
|
|
|
2008-02-11 08:20:13 +00:00
|
|
|
|
void MathMacro::edit(Cursor & cur, bool front, EntryDirection entry_from)
|
2007-11-01 11:13:07 +00:00
|
|
|
|
{
|
2008-03-03 15:21:13 +00:00
|
|
|
|
cur.updateFlags(Update::SinglePar);
|
2008-02-10 19:52:45 +00:00
|
|
|
|
InsetMathNest::edit(cur, front, entry_from);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset * MathMacro::editXY(Cursor & cur, int x, int y)
|
2005-10-05 21:19:32 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
// We may have 0 arguments, but InsetMathNest requires at least one.
|
2007-04-17 16:49:17 +00:00
|
|
|
|
if (nargs() > 0) {
|
2008-03-03 15:21:13 +00:00
|
|
|
|
cur.updateFlags(Update::SinglePar);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
return InsetMathNest::editXY(cur, x, y);
|
|
|
|
|
} else
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-01 15:36:27 +00:00
|
|
|
|
void MathMacro::removeArgument(Inset::pos_type pos) {
|
2007-11-01 11:13:07 +00:00
|
|
|
|
if (displayMode_ == DISPLAY_NORMAL) {
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(size_t(pos) < cells_.size(), /**/);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
cells_.erase(cells_.begin() + pos);
|
2007-11-01 15:36:27 +00:00
|
|
|
|
if (size_t(pos) < attachedArgsNum_)
|
2007-11-01 11:13:07 +00:00
|
|
|
|
--attachedArgsNum_;
|
2007-11-01 15:36:27 +00:00
|
|
|
|
if (size_t(pos) < optionals_) {
|
2007-11-01 11:13:07 +00:00
|
|
|
|
--optionals_;
|
2007-04-17 16:49:17 +00:00
|
|
|
|
}
|
2007-11-01 11:13:07 +00:00
|
|
|
|
|
|
|
|
|
needsUpdate_ = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-01 15:36:27 +00:00
|
|
|
|
void MathMacro::insertArgument(Inset::pos_type pos) {
|
2007-11-01 11:13:07 +00:00
|
|
|
|
if (displayMode_ == DISPLAY_NORMAL) {
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(size_t(pos) <= cells_.size(), /**/);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
cells_.insert(cells_.begin() + pos, MathData());
|
2007-11-01 15:36:27 +00:00
|
|
|
|
if (size_t(pos) < attachedArgsNum_)
|
2007-11-01 11:13:07 +00:00
|
|
|
|
++attachedArgsNum_;
|
2007-11-01 15:36:27 +00:00
|
|
|
|
if (size_t(pos) < optionals_)
|
2007-11-01 11:13:07 +00:00
|
|
|
|
++optionals_;
|
|
|
|
|
|
|
|
|
|
needsUpdate_ = true;
|
2007-04-17 16:49:17 +00:00
|
|
|
|
}
|
2005-10-05 21:19:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
void MathMacro::detachArguments(vector<MathData> & args, bool strip)
|
2007-11-01 11:13:07 +00:00
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(displayMode_ == DISPLAY_NORMAL, /**/);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
args = cells_;
|
|
|
|
|
|
|
|
|
|
// strip off empty cells, but not more than arity-attachedArgsNum_
|
|
|
|
|
if (strip) {
|
|
|
|
|
size_t i;
|
|
|
|
|
for (i = cells_.size(); i > attachedArgsNum_; --i)
|
|
|
|
|
if (!cell(i - 1).empty()) break;
|
|
|
|
|
args.resize(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attachedArgsNum_ = 0;
|
|
|
|
|
expanded_.cell(0) = MathData();
|
|
|
|
|
cells_.resize(0);
|
|
|
|
|
|
|
|
|
|
needsUpdate_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
void MathMacro::attachArguments(vector<MathData> const & args, size_t arity, int optionals)
|
2007-11-01 11:13:07 +00:00
|
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(displayMode_ == DISPLAY_NORMAL, /**/);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
cells_ = args;
|
|
|
|
|
attachedArgsNum_ = args.size();
|
|
|
|
|
cells_.resize(arity);
|
|
|
|
|
expanded_.cell(0) = MathData();
|
|
|
|
|
optionals_ = optionals;
|
|
|
|
|
|
|
|
|
|
needsUpdate_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathMacro::idxFirst(Cursor & cur) const
|
2007-04-16 14:42:53 +00:00
|
|
|
|
{
|
2008-03-03 15:21:13 +00:00
|
|
|
|
cur.updateFlags(Update::SinglePar);
|
2007-04-16 14:42:53 +00:00
|
|
|
|
return InsetMathNest::idxFirst(cur);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
bool MathMacro::idxLast(Cursor & cur) const
|
2007-04-16 14:42:53 +00:00
|
|
|
|
{
|
2008-03-03 15:21:13 +00:00
|
|
|
|
cur.updateFlags(Update::SinglePar);
|
2007-04-16 14:42:53 +00:00
|
|
|
|
return InsetMathNest::idxLast(cur);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-22 20:45:18 +00:00
|
|
|
|
bool MathMacro::notifyCursorLeaves(Cursor const & old, Cursor & cur)
|
2007-06-14 20:57:56 +00:00
|
|
|
|
{
|
2007-11-01 11:13:07 +00:00
|
|
|
|
cur.updateFlags(Update::Force);
|
2008-02-22 20:45:18 +00:00
|
|
|
|
return InsetMathNest::notifyCursorLeaves(old, cur);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacro::fold(Cursor & cur)
|
|
|
|
|
{
|
|
|
|
|
if (!nextFoldMode_) {
|
|
|
|
|
nextFoldMode_ = true;
|
2008-03-03 15:21:13 +00:00
|
|
|
|
cur.updateFlags(Update::SinglePar);
|
2007-06-14 20:57:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
void MathMacro::unfold(Cursor & cur)
|
2007-04-16 14:42:53 +00:00
|
|
|
|
{
|
2007-11-01 11:13:07 +00:00
|
|
|
|
if (nextFoldMode_) {
|
|
|
|
|
nextFoldMode_ = false;
|
2008-03-03 15:21:13 +00:00
|
|
|
|
cur.updateFlags(Update::SinglePar);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
}
|
2007-04-16 14:42:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
bool MathMacro::folded() const
|
2001-11-16 08:26:41 +00:00
|
|
|
|
{
|
2007-11-01 11:13:07 +00:00
|
|
|
|
return nextFoldMode_;
|
2001-11-16 08:26:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
void MathMacro::write(WriteStream & os) const
|
2001-11-16 08:29:11 +00:00
|
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
|
MathEnsurer ensurer(os, macro_ != 0, true);
|
2008-06-16 01:21:17 +00:00
|
|
|
|
|
2007-12-21 20:42:46 +00:00
|
|
|
|
// non-normal mode
|
|
|
|
|
if (displayMode_ != DISPLAY_NORMAL) {
|
2008-06-16 01:21:17 +00:00
|
|
|
|
os << "\\" << name();
|
2008-06-19 09:16:05 +00:00
|
|
|
|
if (name().size() != 1 || isAlphaASCII(name()[0]))
|
|
|
|
|
os.pendingSpace(true);
|
2007-12-21 20:42:46 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// normal mode
|
2008-04-10 21:49:34 +00:00
|
|
|
|
LASSERT(macro_, /**/);
|
2007-12-21 20:42:46 +00:00
|
|
|
|
|
2007-12-21 20:43:50 +00:00
|
|
|
|
// optional arguments make macros fragile
|
|
|
|
|
if (optionals_ > 0 && os.fragile())
|
|
|
|
|
os << "\\protect";
|
|
|
|
|
|
2007-12-21 20:42:46 +00:00
|
|
|
|
os << "\\" << name();
|
|
|
|
|
bool first = true;
|
|
|
|
|
|
2007-12-23 16:31:37 +00:00
|
|
|
|
// Optional arguments:
|
|
|
|
|
// First find last non-empty optional argument
|
|
|
|
|
idx_type emptyOptFrom = 0;
|
|
|
|
|
idx_type i = 0;
|
|
|
|
|
for (; i < cells_.size() && i < optionals_; ++i) {
|
|
|
|
|
if (!cell(i).empty())
|
|
|
|
|
emptyOptFrom = i + 1;
|
|
|
|
|
}
|
2007-12-21 20:42:46 +00:00
|
|
|
|
|
2007-12-23 16:31:37 +00:00
|
|
|
|
// print out optionals
|
|
|
|
|
for (i=0; i < cells_.size() && i < emptyOptFrom; ++i) {
|
|
|
|
|
first = false;
|
|
|
|
|
os << "[" << cell(i) << "]";
|
2007-11-01 11:13:07 +00:00
|
|
|
|
}
|
2007-12-23 16:31:37 +00:00
|
|
|
|
|
|
|
|
|
// skip the tailing empty optionals
|
|
|
|
|
i = optionals_;
|
|
|
|
|
|
2007-12-21 20:42:46 +00:00
|
|
|
|
// Print remaining macros
|
|
|
|
|
for (; i < cells_.size(); ++i) {
|
2007-12-23 16:31:37 +00:00
|
|
|
|
if (cell(i).size() == 1
|
2007-12-21 20:42:46 +00:00
|
|
|
|
&& cell(i)[0].nucleus()->asCharInset()) {
|
|
|
|
|
if (first)
|
|
|
|
|
os << " ";
|
|
|
|
|
os << cell(i);
|
|
|
|
|
} else
|
|
|
|
|
os << "{" << cell(i) << "}";
|
|
|
|
|
first = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add space if there was no argument
|
|
|
|
|
if (first)
|
|
|
|
|
os.pendingSpace(true);
|
2001-11-16 08:29:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
void MathMacro::maple(MapleStream & os) const
|
|
|
|
|
{
|
|
|
|
|
lyx::maple(expanded_.cell(0), os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacro::mathmlize(MathStream & os) const
|
2001-11-16 08:29:11 +00:00
|
|
|
|
{
|
2007-11-01 11:13:07 +00:00
|
|
|
|
lyx::mathmlize(expanded_.cell(0), os);
|
2001-11-16 08:26:41 +00:00
|
|
|
|
}
|
2001-12-11 11:33:43 +00:00
|
|
|
|
|
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
void MathMacro::octave(OctaveStream & os) const
|
2007-04-17 16:49:17 +00:00
|
|
|
|
{
|
2007-11-01 11:13:07 +00:00
|
|
|
|
lyx::octave(expanded_.cell(0), os);
|
2007-04-17 16:49:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void MathMacro::infoize(odocstream & os) const
|
2003-01-07 11:24:43 +00:00
|
|
|
|
{
|
|
|
|
|
os << "Macro: " << name();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void MathMacro::infoize2(odocstream & os) const
|
2003-01-07 11:24:43 +00:00
|
|
|
|
{
|
|
|
|
|
os << "Macro: " << name();
|
2007-04-17 16:49:17 +00:00
|
|
|
|
|
2003-01-07 11:24:43 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
bool MathMacro::completionSupported(Cursor const & cur) const
|
|
|
|
|
{
|
2008-02-21 19:45:36 +00:00
|
|
|
|
if (displayMode() != DISPLAY_UNFOLDED)
|
|
|
|
|
return InsetMathNest::completionSupported(cur);
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
return lyxrc.completion_popup_math
|
|
|
|
|
&& displayMode() == DISPLAY_UNFOLDED
|
|
|
|
|
&& cur.bv().cursor().pos() == int(name().size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathMacro::inlineCompletionSupported(Cursor const & cur) const
|
|
|
|
|
{
|
2008-02-21 19:45:36 +00:00
|
|
|
|
if (displayMode() != DISPLAY_UNFOLDED)
|
|
|
|
|
return InsetMathNest::inlineCompletionSupported(cur);
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
return lyxrc.completion_inline_math
|
|
|
|
|
&& displayMode() == DISPLAY_UNFOLDED
|
|
|
|
|
&& cur.bv().cursor().pos() == int(name().size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathMacro::automaticInlineCompletion() const
|
|
|
|
|
{
|
2008-02-21 19:45:36 +00:00
|
|
|
|
if (displayMode() != DISPLAY_UNFOLDED)
|
|
|
|
|
return InsetMathNest::automaticInlineCompletion();
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
return lyxrc.completion_inline_math;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathMacro::automaticPopupCompletion() const
|
|
|
|
|
{
|
2008-02-21 19:45:36 +00:00
|
|
|
|
if (displayMode() != DISPLAY_UNFOLDED)
|
|
|
|
|
return InsetMathNest::automaticPopupCompletion();
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
return lyxrc.completion_popup_math;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-15 00:22:54 +00:00
|
|
|
|
CompletionList const *
|
2008-02-22 21:11:19 +00:00
|
|
|
|
MathMacro::createCompletionList(Cursor const & cur) const
|
2008-02-21 19:42:34 +00:00
|
|
|
|
{
|
2008-02-21 19:45:36 +00:00
|
|
|
|
if (displayMode() != DISPLAY_UNFOLDED)
|
2008-02-22 21:11:19 +00:00
|
|
|
|
return InsetMathNest::createCompletionList(cur);
|
2008-02-21 19:45:36 +00:00
|
|
|
|
|
2008-02-21 23:36:02 +00:00
|
|
|
|
return new MathCompletionList(cur.bv().cursor());
|
2008-02-21 19:42:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring MathMacro::completionPrefix(Cursor const & cur) const
|
|
|
|
|
{
|
2008-02-21 19:45:36 +00:00
|
|
|
|
if (displayMode() != DISPLAY_UNFOLDED)
|
|
|
|
|
return InsetMathNest::completionPrefix(cur);
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
if (!completionSupported(cur))
|
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
|
|
return "\\" + name();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathMacro::insertCompletion(Cursor & cur, docstring const & s,
|
|
|
|
|
bool finished)
|
|
|
|
|
{
|
2008-02-21 19:45:36 +00:00
|
|
|
|
if (displayMode() != DISPLAY_UNFOLDED)
|
|
|
|
|
return InsetMathNest::insertCompletion(cur, s, finished);
|
|
|
|
|
|
|
|
|
|
if (!completionSupported(cur))
|
2008-02-21 19:42:34 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// append completion
|
|
|
|
|
docstring newName = name() + s;
|
|
|
|
|
asArray(newName, cell(0));
|
|
|
|
|
cur.bv().cursor().pos() = name().size();
|
2008-03-03 15:21:13 +00:00
|
|
|
|
cur.updateFlags(Update::SinglePar);
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
|
|
|
|
// finish macro
|
|
|
|
|
if (finished) {
|
|
|
|
|
cur.bv().cursor().pop();
|
|
|
|
|
++cur.bv().cursor().pos();
|
2008-02-26 14:22:56 +00:00
|
|
|
|
cur.updateFlags(Update::SinglePar);
|
2008-02-21 19:42:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacro::completionPosAndDim(Cursor const & cur, int & x, int & y,
|
|
|
|
|
Dimension & dim) const
|
|
|
|
|
{
|
2008-02-21 19:45:36 +00:00
|
|
|
|
if (displayMode() != DISPLAY_UNFOLDED)
|
|
|
|
|
InsetMathNest::completionPosAndDim(cur, x, y, dim);
|
|
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
|
// get inset dimensions
|
|
|
|
|
dim = cur.bv().coordCache().insets().dim(this);
|
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(this);
|
|
|
|
|
x = xy.x_;
|
|
|
|
|
y = xy.y_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|