#include "dispatchresult.h"
#include "funcrequest.h"
#include "gettext.h"
+#include "lyxtext.h"
#include "outputparams.h"
#include "undo.h"
#include "support/lstrings.h"
-#include "frontends/Application.h"
#include "frontends/Painter.h"
#include "frontends/Selection.h"
#include "frontends/nullpainter.h"
-//#include "bufferlist.h"
#include "funcrequest.h"
#include "lyxserver.h"
#include "lyxsocket.h"
#include <sstream>
+using lyx::CoordCache;
+using lyx::docstring;
+using lyx::odocstream;
+using lyx::Point;
+
using lyx::cap::copySelection;
using lyx::cap::grabAndEraseSelection;
using lyx::cap::cutSelection;
using lyx::cap::replaceSelection;
using lyx::cap::selClearOrDel;
-using lyx::frontend::Clipboard;
-
using std::endl;
using std::string;
using std::istringstream;
}
-void InsetMathNest::cursorPos(CursorSlice const & sl, bool /*boundary*/,
- int & x, int & y) const
+void InsetMathNest::cursorPos(BufferView const & bv,
+ CursorSlice const & sl, bool /*boundary*/,
+ int & x, int & y) const
{
// FIXME: This is a hack. Ideally, the coord cache should not store
// absolute positions, but relative ones. This would mean to call
// 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 const & coord_cache = 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::dump() const
{
- WriteStream os(lyxerr);
+ lyx::odocstringstream oss;
+ WriteStream os(oss);
os << "---------------------------------------------\n";
write(os);
os << "\n";
for (idx_type i = 0, n = nargs(); i != n; ++i)
os << cell(i) << "\n";
os << "---------------------------------------------\n";
+ lyxerr << lyx::to_utf8(oss.str());
}
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);
}
}
}
-int InsetMathNest::latex(Buffer const &, std::ostream & os,
+int InsetMathNest::latex(Buffer const &, odocstream & os,
OutputParams const & runparams) const
{
WriteStream wi(os, runparams.moving_arg, true);
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();
if (cmd.argument().size() != 1) {
recordUndo(cur);
string const arg = lyx::to_utf8(cmd.argument());
- if (!interpret(cur, arg))
+ if (!interpretString(cur, arg))
cur.insert(arg);
break;
}
cur.posLeft();
cur.pushLeft(*cur.nextInset());
}
- // FIXME: Change to
- // } else if (!interpret(cur, cmd.argument()[0])) {
- // when interpret accepts UCS4 characters
- } else if (!interpret(cur, lyx::to_utf8(cmd.argument()))) {
+ } else if (!interpretChar(cur, cmd.argument()[0])) {
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
cur.undispatched();
}
case LFUN_ERT_INSERT:
// interpret this as if a backslash was typed
recordUndo(cur, Undo::ATOMIC);
- interpret(cur, '\\');
+ interpretChar(cur, '\\');
break;
case LFUN_MATH_SUBSCRIPT:
// interpret this as if a _ was typed
recordUndo(cur, Undo::ATOMIC);
- interpret(cur, '_');
+ interpretChar(cur, '_');
break;
case LFUN_MATH_SUPERSCRIPT:
// interpret this as if a ^ was typed
recordUndo(cur, Undo::ATOMIC);
- interpret(cur, '^');
+ interpretChar(cur, '^');
break;
// FIXME: We probably should swap parts of "math-insert" and "self-insert"
// math-insert only handles special math things like "matrix".
case LFUN_MATH_INSERT: {
recordUndo(cur, Undo::ATOMIC);
- if (cmd.argument() == "^" || cmd.argument() == "_")
- interpret(cur, cmd.argument()[0]);
- else
+ if (cmd.argument() == "^" || cmd.argument() == "_") {
+ interpretChar(cur, cmd.argument()[0]);
+ } else
cur.niceInsert(lyx::to_utf8(cmd.argument()));
break;
}
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;
+ }
+
default:
InsetMathDim::doDispatch(cur, cmd);
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;
} else if (cmd.button() == mouse_button::button2) {
MathArray ar;
if (cur.selection())
- asArray(lyx::to_utf8(bv.cursor().selectionAsString(false)), ar);
+ asArray(bv.cursor().selectionAsString(false), ar);
else
- asArray(lyx::to_utf8(theApp->selection().get()), ar);
+ asArray(theSelection().get(), ar);
cur.insert(ar);
bv.mouseSetCursor(cur);
//lyxerr << "## lfunMouseRelease: buttons: " << cmd.button() << endl;
if (cmd.button() == mouse_button::button1) {
- //theApp->selection().put(cur.grabSelection());
+ //theSelection().put(cur.grabSelection());
return;
}
}
-bool InsetMathNest::interpret(LCursor & cur, char c)
+bool InsetMathNest::interpretChar(LCursor & cur, lyx::char_type c)
{
//lyxerr << "interpret 2: '" << c << "'" << endl;
string save_selection;
}
if (isalpha(c)) {
- cur.activeMacro()->setName(name + c);
+ cur.activeMacro()->setName(name + lyx::to_ascii(docstring(1, c)));
return true;
}
cur.niceInsert(MathAtom(new InsetMathComment));
} else if (c == '#') {
BOOST_ASSERT(cur.activeMacro());
- cur.activeMacro()->setName(name + c);
+ cur.activeMacro()->setName(name + lyx::to_ascii(docstring(1, c)));
} else {
cur.backspace();
- cur.niceInsert(createInsetMath(string(1, c)));
+ cur.niceInsert(createInsetMath(lyx::to_ascii(docstring(1, c))));
}
return true;
}
// One character big delimiters. The others are handled in
- // the other interpret() method.
+ // interpretString().
latexkeys const * l = in_word_set(name.substr(1));
if (name[0] == '\\' && l && l->inset == "big") {
string delim;
delim = "\\}";
break;
default:
- delim = string(1, c);
+ delim = lyx::to_ascii(docstring(1, c));
break;
}
if (InsetMathBig::isBigInsetDelim(delim)) {
if (c == '{')
cur.niceInsert(MathAtom(new InsetMathBrace));
else if (c != ' ')
- interpret(cur, c);
+ interpretChar(cur, c);
return true;
}
if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' ||
c == '%' || c == '_' || c == '^') {
- cur.niceInsert(createInsetMath(string(1, c)));
+ cur.niceInsert(createInsetMath(lyx::to_ascii(docstring(1, c))));
return true;
}
}
-bool InsetMathNest::interpret(LCursor & cur, string const & str)
+bool InsetMathNest::interpretString(LCursor & cur, string const & str)
{
// Create a InsetMathBig from cur.cell()[cur.pos() - 1] and t if
// possible
if (up)
cur.niceInsert(createInsetMath("mathcircumflex"));
else
- interpret(cur, '_');
+ interpretChar(cur, '_');
return true;
}