void InsetFormula::write(Buffer const *, ostream & os) const
{
- os << "Formula ";
WriteStream wi(os, false, false);
+ os << par_->fileInsetLabel() << " ";
par_->write(wi);
}
const_cast<InsetFormulaBase const *>(mathcursor->formula()) == this)
{
mathcursor->drawSelection(pi);
- pi.pain.rectangle(x, y - a, w, h, LColor::mathframe);
+ //pi.pain.rectangle(x, y - a, w, h, LColor::mathframe);
}
- par_->draw(pi, x, y);
+ par_->draw(pi, x + 1, y);
}
xx += w;
vector<string> const InsetFormula::getLabelList() const
{
- return hull()->getLabelList();
+ return par()->getLabelList();
}
//lyxerr << "toggling all numbers\n";
if (display()) {
bv->lockedInsetStoreUndo(Undo::INSERT);
- bool old = hull()->numberedType();
+ bool old = par()->numberedType();
for (MathInset::row_type row = 0; row < par_->nrows(); ++row)
hull()->numbered(row, !old);
bv->owner()->message(old ? _("No number") : _("Number"));
string InsetFormula::hullType() const
{
- return hull() ? hull()->getType() : "none";
+ return par()->getType();
}
-void InsetFormula::mutate(string const & type )
+void InsetFormula::mutate(string const & type)
{
- if (hull())
- hull()->mutate(type);
+ par()->mutate(type);
}
#include "frontends/Dialogs.h"
#include "intl.h"
#include "insets/insetcommandparams.h"
-
#include "ref_inset.h"
using std::endl;
bool InsetFormulaBase::insetButtonRelease(BufferView * bv,
int /*x*/, int /*y*/, mouse_button::state button)
{
- //lyxerr << "insetButtonRelease: " << x << " " << y << "\n";
-
if (!mathcursor)
return false;
+
+ //lyxerr << "insetButtonRelease: " << x << " " << y << "\n";
hideInsetCursor(bv);
showInsetCursor(bv);
bv->updateInset(this, false);
if (button == mouse_button::button3) {
// try to dispatch to enclosed insets first
- if (mathcursor->dispatch("mouse 3"))
+ if (mathcursor->dispatch("mouse-3-release"))
return true;
// launch math panel for right mouse button
bv->owner()->getDialogs()->showMathPanel();
return true;
}
+
+ if (button == mouse_button::button1) {
+ // try to dispatch to enclosed insets first
+ if (mathcursor->dispatch("mouse-1-release"))
+ return true;
+
+ // try to set the cursor
+ //delete mathcursor;
+ //mathcursor = new MathCursor(this, x == 0);
+ //metrics(bv);
+ //mathcursor->setPos(x + xo_, y + yo_);
+ return true;
+ }
return false;
}
void InsetFormulaBase::insetButtonPress(BufferView * bv,
int x, int y, mouse_button::state button)
{
- //lyxerr << "insetButtonPress: "
- // << x << " " << y << " but: " << button << "\n";
-#if 0
- switch (button) {
- default:
- case 1:
- // left click
- delete mathcursor;
- mathcursor = new MathCursor(this, x == 0);
- metrics(bv);
- first_x = x;
- first_y = y;
- mathcursor->selClear();
- mathcursor->setPos(x + xo_, y + yo_);
- break;
-/*
- case 2:
- lyxerr << "insetButtonPress: 2\n";
- // insert stuff
- if (mathcursor) {
- bv->lockedInsetStoreUndo(Undo::EDIT);
- MathArray ar;
- mathcursor->selGet(ar);
- mathcursor->setPos(x + xo_, y + yo_);
- string sel =
- bv->getLyXText()->selectionAsString(bv->buffer(), false);
- mathed_parse_cell(ar, sel);
- mathcursor->insert(ar);
- }
- break;
-*/
- case 3:
- // launch math panel for right mouse button
- bv->owner()->getDialogs()->showMathPanel();
- break;
- }
-#else
- if (button == mouse_button::button1 || !mathcursor) {
- delete mathcursor;
- mathcursor = new MathCursor(this, x == 0);
+ lyxerr << "insetButtonPress: "
+ << x << " " << y << " but: " << button << "\n";
+ lyxerr << "formula: ";
+ par()->dump();
+
+ delete mathcursor;
+ mathcursor = new MathCursor(this, x == 0);
+
+ if (button == mouse_button::button1) {
+ // just set the cursor here
+ lyxerr << "setting cursor\n";
metrics(bv);
first_x = x;
first_y = y;
mathcursor->selClear();
mathcursor->setPos(x + xo_, y + yo_);
+
+ if (mathcursor->dispatch("mouse-1-press")) {
+ //delete mathcursor;
+ return;
+ }
+
}
-#if 0
-#warning Never launch a Dialog on "Press" event ONLY on "Release" event!
- if (button == 3) {
- // launch math panel for right mouse button
- bv->owner()->getDialogs()->showMathPanel();
+ if (button == mouse_button::button3) {
+ if (mathcursor->dispatch("mouse-3-press")) {
+ //delete mathcursor;
+ return;
+ }
}
-#endif
-#endif
bv->updateInset(this, false);
}
void InsetFormulaBase::insetMotionNotify(BufferView * bv,
- int x, int y, mouse_button::state)
+ int x, int y, mouse_button::state button)
{
if (!mathcursor)
return;
+ if (button == mouse_button::button1)
+ if (mathcursor->dispatch("mouse-1-motion"))
+ return;
+
+ if (button == mouse_button::button3)
+ if (mathcursor->dispatch("mouse-3-motion"))
+ return;
+
if (abs(x - first_x) < 2 && abs(y - first_y) < 2) {
//lyxerr << "insetMotionNotify: ignored\n";
return;
string const & arg)
{
//lyxerr << "InsetFormulaBase::localDispatch: act: " << action
- // << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
+ // << " arg: '" << arg
+ // << "' cursor: " << mathcursor
+ // << "\n";
if (!mathcursor)
return UNDISPATCHED;
}
-InsetFormulaBase * MathCursor::formula()
+InsetFormulaBase * MathCursor::formula() const
{
return formula_;
}
int MathCursor::dispatch(string const & cmd)
{
+ // try to dispatch to adajcent items if they are not editable
+ // actually, this should only happen for mouse clicks...
+ if (hasNextAtom() && !openable(nextAtom(), false))
+ if (int res = nextAtom()->dispatch(cmd, 0, 0))
+ return res;
+ if (hasPrevAtom() && !openable(prevAtom(), false))
+ if (int res = prevAtom()->dispatch(cmd, 0, 0))
+ return res;
+
for (int i = Cursor_.size() - 1; i >= 0; --i) {
MathCursorPos & pos = Cursor_[i];
- if (int res = pos.par_-> dispatch(cmd, pos.idx_, pos.pos_))
+ if (int res = pos.par_->dispatch(cmd, pos.idx_, pos.pos_))
return res;
}
return 0;
/// go up to the hull inset
void popToEnclosingHull();
///
- InsetFormulaBase * formula();
+ InsetFormulaBase * formula() const;
/// current offset in the current cell
pos_type pos() const;
/// current cell
#include "math_xymatrixinset.h"
#include "math_xyarrowinset.h"
+//#include "insets/insetref.h"
#include "ref_inset.h"
#include "math_metricsinfo.h"
{"overline", "decoration", ""},
{"overrightarrow", "decoration", ""},
{"overleftrightarrow", "decoration", ""},
+ {"pageref", "ref", ""},
{"pmatrix", "matrix", ""},
+ {"prettyref", "ref", ""},
{"protect", "protect", ""},
{"qquad", "space", ""},
{"quad", "space", ""},
+ {"ref", "ref", ""},
{"right", "right", ""},
{"rm", "oldfont", ""},
{"scriptscriptstyle", "style", ""},
{"vdots", "dots", ""},
{"vec", "decoration", ""},
{"vmatrix", "matrix", ""},
+ {"vpageref", "ref", ""},
+ {"vref", "ref", ""},
{"widehat", "decoration", ""},
{"widetilde", "decoration", ""}
};
return MathAtom(new MathNotInset);
if (s == "lefteqn")
return MathAtom(new MathLefteqnInset);
- if (s == "ref")
- return MathAtom(new RefInset);
-
latexkeys const * l = in_word_set(s);
if (l) {
string const & inset = l->inset;
lyxerr[Debug::MATHED] << " found inset: '" << inset << "'\n";
+ if (inset == "ref")
+ return MathAtom(new RefInset(l->name));
if (inset == "underset")
return MathAtom(new MathUndersetInset);
if (inset == "decoration")
math_font_max_dim(mi.base.font, asc, des);
ascent_ = max(ascent_, asc);
descent_ = max(descent_, des);
+
+ // for markers
+ width_ += 2;
+ descent_ += 1;
}
void MathHullInset::draw(MathPainterInfo & pi, int x, int y) const
{
MathFontSetChanger dummy(pi.base, standardFont());
- MathGridInset::draw(pi, x, y);
+ MathGridInset::draw(pi, x + 1, y);
if (numberedType()) {
int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
drawStr(pi, pi.base.font, xx, yy, nicelabel(row));
}
}
+
+ drawMarkers(pi, x, y);
}
}
-vector<string> const MathHullInset::getLabelList() const
+vector<string> MathHullInset::getLabelList() const
{
vector<string> res;
for (row_type row = 0; row < nrows(); ++row)
///
bool ams() const;
///
- std::vector<string> const getLabelList() const;
+ std::vector<string> getLabelList() const;
///
void validate(LaTeXFeatures & features) const;
/// identifies MatrixInsets
#include "math_scriptinset.h"
#include "math_charinset.h"
#include "math_mathmlstream.h"
+#include "math_cursor.h"
#include "debug.h"
+#include "frontends/LyXView.h"
+#include "frontends/Dialogs.h"
+#include "BufferView.h"
+#include "formulabase.h"
+
using std::ostream;
using std::vector;
}
+std::vector<string> MathInset::getLabelList() const
+{
+ return std::vector<string>();
+}
+
+
+string const & MathInset::getType() const
+{
+ static string t("none");
+ return t;
+}
+
+
string asString(MathArray const & ar)
{
string res;
ar.push_back(MathAtom(new MathCharInset(*it)));
return ar;
}
+
+
+Dialogs * getDialogs()
+{
+ return mathcursor->formula()->view()->owner()->getDialogs();
+}
+
+
+LyXFunc * getLyXFunc()
+{
+ return mathcursor->formula()->view()->owner()->getLyXFunc();
+}
class MathSymbolInset;
class MathUnknownInset;
class MathXYMatrixInset;
+class MathXYMatrixInset;
+
+class InsetRef;
class NormalStream;
class OctaveStream;
virtual MathUnknownInset * asUnknownInset() { return 0; }
virtual MathUnknownInset const * asUnknownInset() const { return 0; }
virtual MathXYMatrixInset const* asXYMatrixInset() const{ return 0; }
+ virtual InsetRef * asInsetRef() { return 0; }
/// identifies things that can get scripts
virtual bool isScriptable() const { return false; }
virtual void dump() const;
/// local dispatcher
virtual int dispatch(string const & cmd, idx_type idx, pos_type pos);
+
+ /// LyXInset stuff
+ virtual std::vector<string> getLabelList() const;
+ /// LyXInset stuff
+ virtual bool numberedType() const { return false; }
+ /// hull type
+ virtual string const & getType() const;
+ /// change type
+ virtual void mutate(string const &) {}
+ /// how is the inset called in the .lyx file?
+ virtual string fileInsetLabel() const { return "Formula"; }
};
std::ostream & operator<<(std::ostream &, MathInset const &);
string asString(MathArray const & ar);
MathArray asArray(string const & str);
+/// here to ssave a few includes in the insets
+class Dialogs;
+class LyXFunc;
+
+Dialogs * getDialogs();
+LyXFunc * getLyXFunc();
+
#endif
#include "math_support.h"
#include "math_xyarrowinset.h"
+//#include "insets/insetref.h"
#include "ref_inset.h"
#include "lyxlex.h"
skipSpaces();
MathArray ar;
parse_into(ar, false, false);
- if (ar.size() != 1) {
- lyxerr << "Unusual contents found: " << ar << endl;
+ if (ar.size() != 1 || ar.front()->getType() == "none") {
+ lyxerr << "unusual contents found: " << ar << endl;
at.reset(new MathParInset);
if (at->nargs() > 0)
at->cell(0) = ar;
else
- lyxerr << "Unusual contents found: " << ar << endl;
+ lyxerr << "unusual contents found: " << ar << endl;
return true;
}
at = ar[0];
int RefInset::dispatch(string const & cmd, idx_type, pos_type)
{
- if (cmd == "mouse 3") {
+ if (cmd == "mouse-3-release") {
lyxerr << "trying to goto ref" << cell(0) << "\n";
mathcursor->formula()->view()->owner()->getLyXFunc()->
dispatch(LFUN_REF_GOTO, asString(cell(0)));
return 1; // dispatched
}
- if (cmd == "mouse 1") {
+ if (cmd == "mouse-1-release") {
lyxerr << "trying to open ref" << cell(0) << "\n";
// Eventually trigger dialog with button 3 not 1
// mathcursor->formula()->view()->owner()->getDialogs()
return 1; // dispatched
}
+ // eat other mouse commands
+ if (cmd.substr(0, 6) == "mouse-")
+ return 1;
+
return 0; // undispatched
}