#include "dispatchresult.h"
#include "funcrequest.h"
#include "gettext.h"
+#include "lyxtext.h"
#include "outputparams.h"
#include "undo.h"
#include "support/lstrings.h"
-#include "frontends/Dialogs.h"
-#include "frontends/Gui.h"
-#include "frontends/LyXView.h"
#include "frontends/Painter.h"
#include "frontends/Selection.h"
#include "frontends/nullpainter.h"
+#include "funcrequest.h"
+#include "lyxserver.h"
+#include "lyxsocket.h"
+
#include <sstream>
+using lyx::docstring;
using lyx::cap::copySelection;
using lyx::cap::grabAndEraseSelection;
using lyx::cap::cutSelection;
using lyx::cap::replaceSelection;
using lyx::cap::selClearOrDel;
-using lyx::frontend::Gui;
-using lyx::frontend::Clipboard;
-
using std::endl;
using std::string;
using std::istringstream;
// absolute again when actually drawing the cursor. What a mess.
BOOST_ASSERT(ptr_cmp(&sl.inset(), this));
MathArray const & ar = sl.cell();
- if (!theCoords.getArrays().has(&ar)) {
+ CoordCache & coord_cache = sl.text()->bv()->coordCache();
+ if (!coord_cache.getArrays().has(&ar)) {
// this can (semi-)legally happen if we just created this cell
// and it never has been drawn before. So don't ASSERT.
//lyxerr << "no cached data for array " << &ar << endl;
y = 0;
return;
}
- Point const pt = theCoords.getArrays().xy(&ar);
- if (!theCoords.getInsets().has(this)) {
+ Point const pt = coord_cache.getArrays().xy(&ar);
+ if (!coord_cache.getInsets().has(this)) {
// same as above
//lyxerr << "no cached data for inset " << this << endl;
x = 0;
y = 0;
return;
}
- Point const pt2 = theCoords.getInsets().xy(this);
+ Point const pt2 = coord_cache.getInsets().xy(this);
//lyxerr << "retrieving position cache for MathArray "
// << pt.x_ << ' ' << pt.y_ << std::endl;
x = pt.x_ - pt2.x_ + ar.pos2x(sl.pos());
void InsetMathNest::drawSelection(PainterInfo & pi, int x, int y) const
{
+ BufferView & bv = *pi.base.bv;
// this should use the x/y values given, not the cached values
- LCursor & cur = pi.base.bv->cursor();
+ LCursor & cur = bv.cursor();
if (!cur.selection())
return;
if (!ptr_cmp(&cur.inset(), this))
CursorSlice s1 = cur.selBegin();
CursorSlice s2 = cur.selEnd();
+
//lyxerr << "InsetMathNest::drawing selection: "
// << " s1: " << s1 << " s2: " << s2 << endl;
if (s1.idx() == s2.idx()) {
MathArray const & c = cell(s1.idx());
- int x1 = c.xo() + c.pos2x(s1.pos());
- int y1 = c.yo() - c.ascent();
- int x2 = c.xo() + c.pos2x(s2.pos());
- int y2 = c.yo() + c.descent();
+ int x1 = c.xo(bv) + c.pos2x(s1.pos());
+ int y1 = c.yo(bv) - c.ascent();
+ int x2 = c.xo(bv) + c.pos2x(s2.pos());
+ int y2 = c.yo(bv) + c.descent();
pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
//lyxerr << "InsetMathNest::drawing selection 3: "
// << " x1: " << x1 << " x2: " << x2
for (idx_type i = 0; i < nargs(); ++i) {
if (idxBetween(i, s1.idx(), s2.idx())) {
MathArray const & c = cell(i);
- int x1 = c.xo();
- int y1 = c.yo() - c.ascent();
- int x2 = c.xo() + c.width();
- int y2 = c.yo() + c.descent();
+ int x1 = c.xo(bv);
+ int y1 = c.yo(bv) - c.ascent();
+ int x2 = c.xo(bv) + c.width();
+ int y2 = c.yo(bv) + c.descent();
pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
}
}
size_t n = 0;
istringstream is(lyx::to_utf8(cmd.argument()));
is >> n;
- string const selection = lyx::cap::getSelection(cur.buffer(), n);
- cur.niceInsert(selection);
+ docstring const selection = lyx::cap::getSelection(cur.buffer(), n);
+ // FIXME UNICODE
+ cur.niceInsert(lyx::to_utf8(selection));
cur.clearSelection(); // bug 393
cur.bv().switchKeyMap();
finishUndo();
RefInset tmp(name);
data = tmp.createDialogStr(name);
}
- cur.bv().owner()->getDialogs().show(name, data, 0);
+ cur.bv().showInsetDialog(name, data, 0);
+ break;
+ }
+
+ case LFUN_INSET_INSERT: {
+ MathArray ar;
+ if (createInsetMath_fromDialogStr(lyx::to_utf8(cmd.argument()), ar)) {
+ recordUndo(cur);
+ cur.insert(ar);
+ } else
+ cur.undispatched();
break;
}
flag.enabled(currentMode() == MATH_MODE);
break;
+ 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;
+ }
+
case LFUN_MATH_DELIM:
case LFUN_MATH_BIGDELIM:
// Don't do this with multi-cell selections
int idx_min = 0;
int dist_min = 1000000;
for (idx_type i = 0, n = nargs(); i != n; ++i) {
- int const d = cell(i).dist(x, y);
+ int const d = cell(i).dist(cur.bv(), x, y);
if (d < dist_min) {
dist_min = d;
idx_min = i;
MathArray & ar = cell(idx_min);
cur.push(*this);
cur.idx() = idx_min;
- cur.pos() = ar.x2pos(x - ar.xo());
+ cur.pos() = ar.x2pos(x - ar.xo(cur.bv()));
+
//lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
if (dist_min == 0) {
// hit inside cell
for (pos_type i = 0, n = ar.size(); i < n; ++i)
- if (ar[i]->covers(x, y))
+ if (ar[i]->covers(cur.bv(), x, y))
return ar[i].nucleus()->editXY(cur, x, y);
}
return this;
if (cur.selection())
asArray(lyx::to_utf8(bv.cursor().selectionAsString(false)), ar);
else
- asArray(lyx::to_utf8(bv.owner()->gui().selection().get()), ar);
+ asArray(lyx::to_utf8(theSelection().get()), ar);
cur.insert(ar);
bv.mouseSetCursor(cur);
//lyxerr << "## lfunMouseRelease: buttons: " << cmd.button() << endl;
if (cmd.button() == mouse_button::button1) {
- //cur.bv().owner()->gui().selection().put(cur.grabSelection());
+ //theSelection().put(cur.grabSelection());
return;
}
if (cmd.button() == mouse_button::button3) {
// try to dispatch to enclosed insets first
- cur.bv().owner()->getDialogs().show("mathpanel");
+ cur.bv().showDialog("mathpanel");
return;
}