using std::istringstream;
+namespace {
+
+// local global
+int first_x;
+int first_y;
+
+} // namespace anon
+
+
+
+
MathNestInset::MathNestInset(idx_type nargs)
: cells_(nargs), lock_(false)
{}
}
-void MathNestInset::drawSelection(PainterInfo & pi, int x, int y) const
+void MathNestInset::drawSelection(PainterInfo & pi, int, int) const
{
// this should use the x/y values given, not the cached values
LCursor & cur = pi.base.bv->cursor();
CursorSlice & s1 = cur.selBegin();
CursorSlice & s2 = cur.selEnd();
if (s1.idx() == s2.idx()) {
- MathArray const & c = s1.cell();
- lyxerr << "###### c.xo(): " << c.xo() << " c.yo(): " << c.yo() << endl;
+ 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();
- //pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
- pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::red);
+ pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
} else {
for (idx_type i = 0; i < nargs(); ++i) {
if (idxBetween(i, s1.idx(), s2.idx())) {
int y1 = c.yo() - c.ascent();
int x2 = c.xo() + c.width();
int y2 = c.yo() + c.descent();
- //pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
- pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::red);
+ pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
}
}
}
DispatchResult
MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
- lyxerr << "*** MathNestInset: request: " << cmd << std::endl;
- //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
- // << " arg: '" << cmd.argument
- // << "' x: '" << cmd.x
- // << " y: '" << cmd.y
- // << "' button: " << cmd.button() << endl;
+ lyxerr << "MathNestInset: request: " << cmd << std::endl;
switch (cmd.action) {
return dispatch(cur, FuncRequest(LFUN_PASTE, cur.bv().getClipboard()));
case LFUN_MOUSE_PRESS:
- if (cmd.button() == mouse_button::button2)
- return priv_dispatch(cur, FuncRequest(LFUN_PASTESELECTION));
- return DispatchResult(false);
+ return lfunMousePress(cur, cmd);
+ case LFUN_MOUSE_MOTION:
+ return lfunMouseMotion(cur, cmd);
+ case LFUN_MOUSE_RELEASE:
+ return lfunMouseRelease(cur, cmd);
+ case LFUN_MOUSE_DOUBLE:
+ return dispatch(cur, FuncRequest(LFUN_WORDSEL));
case LFUN_RIGHTSEL:
- cur.selection() = true; // fall through...
case LFUN_RIGHT:
+ cur.selHandle(cmd.action == LFUN_RIGHTSEL);
return cur.right() ?
DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
- //lyxerr << "calling scroll 20" << endl;
- //scroll(&cur.bv(), 20);
- // write something to the minibuffer
- //cur.bv().owner()->message(cur.info());
case LFUN_LEFTSEL:
- cur.selection() = true; // fall through
case LFUN_LEFT:
+ cur.selHandle(cmd.action == LFUN_LEFTSEL);
return cur.left() ?
DispatchResult(true, true) : DispatchResult(false, FINISHED);
case LFUN_UPSEL:
- cur.selection() = true; // fall through
case LFUN_UP:
+ cur.selHandle(cmd.action == LFUN_UPSEL);
return cur.up() ?
DispatchResult(true, true) : DispatchResult(false, FINISHED_UP);
case LFUN_DOWNSEL:
- cur.selection() = true; // fall through
case LFUN_DOWN:
+ cur.selHandle(cmd.action == LFUN_DOWNSEL);
return cur.down() ?
DispatchResult(true, true) : DispatchResult(false, FINISHED_DOWN);
case LFUN_WORDSEL:
cur.home();
+ cur.resetAnchor();
cur.selection() = true;
cur.end();
return DispatchResult(true, true);
case LFUN_DOWN_PARAGRAPH:
return DispatchResult(true, FINISHED);
- case LFUN_HOMESEL:
case LFUN_WORDLEFTSEL:
- cur.selection() = true; // fall through
- case LFUN_HOME:
case LFUN_WORDLEFT:
+ cur.selHandle(cmd.action == LFUN_WORDLEFTSEL);
return cur.home()
? DispatchResult(true, true) : DispatchResult(true, FINISHED);
- case LFUN_ENDSEL:
case LFUN_WORDRIGHTSEL:
- cur.selection() = true; // fall through
- case LFUN_END:
case LFUN_WORDRIGHT:
+ cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL);
+ return cur.end()
+ ? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
+
+ case LFUN_HOMESEL:
+ case LFUN_HOME:
+ cur.selHandle(cmd.action == LFUN_HOMESEL);
+ return cur.home()
+ ? DispatchResult(true, true) : DispatchResult(true, FINISHED);
+
+ case LFUN_ENDSEL:
+ case LFUN_END:
+ cur.selHandle(cmd.action == LFUN_ENDSEL);
return cur.end()
? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
//
// this needs to be incorporated
//
- //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
- // << " arg: '" << cmd.argument
- // << "' x: '" << cmd.x
- // << " y: '" << cmd.y
- // << "' button: " << cmd.button() << endl;
-
// delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
bool remove_inset = false;
- switch (cmd.action) {
- case LFUN_MOUSE_PRESS:
- //lyxerr << "Mouse single press" << endl;
- return lfunMousePress(cur, cmd);
- case LFUN_MOUSE_MOTION:
- //lyxerr << "Mouse motion" << endl;
- return lfunMouseMotion(cur, cmd);
- case LFUN_MOUSE_RELEASE:
- //lyxerr << "Mouse single release" << endl;
- return lfunMouseRelease(cur, cmd);
- case LFUN_MOUSE_DOUBLE:
- //lyxerr << "Mouse double" << endl;
- return dispatch(cur, FuncRequest(LFUN_WORDSEL));
- default:
- break;
- }
-
DispatchResult result(true);
bool was_macro = cur.inMacroMode();
cur.normalize();
cur.touch();
-
- switch (cmd.action) {
-
- case LFUN_MATH_LIMITS:
- //recordUndo(cur, Undo::ATOMIC);
- cur.dispatch(cmd);
- break;
#endif
// case LFUN_GETXY:
}
case LFUN_MATH_DELIM: {
- //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'" << endl;
+ lyxerr << "MathNestInset::LFUN_MATH_DELIM" << endl;
string ls;
string rs = lyx::support::split(cmd.argument, ls, ' ');
// Reasonable default values
cur.interpret('\\');
return DispatchResult(true, true);
-#if 0
- case LFUN_BREAKPARAGRAPH:
- case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
- case LFUN_BREAKPARAGRAPH_SKIP:
- cmd.argument = "\n";
- //recordUndo(cur, Undo::ATOMIC);
- cur.niceInsert(argument);
- return DispatchResult(true, true);
-#endif
-
// 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".
searchForward(&cur.bv(), cmd.getArg(0), false, false)
? DispatchResult(true, true) : DispatchResult(false);
- case LFUN_INSERT_MATH:
- case LFUN_INSERT_MATRIX:
- case LFUN_MATH_DELIM: {
- MathHullInset * f = new MathHullInset;
- if (openNewInset(cur, f)) {
- cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, "simple"));
- cur.inset()->dispatch(cur, cmd);
- }
- return DispatchResult(true, true);
- }
-
cur.normalize();
cur.touch();
}
-void MathNestInset::edit(LCursor & cur, int x, int y)
+void MathNestInset::edit(LCursor & cur, bool left)
{
- lyxerr << "Called MathNestInset::edit with '" << x << ' ' << y << "'" << endl;
cur.push(this);
+ cur.idx() = left ? 0 : cur.lastidx();
+ cur.pos() = left ? 0 : cur.lastpos();
+ cur.resetAnchor();
+}
+
+
+void MathNestInset::edit(LCursor & cur, int x, int y)
+{
int idx_min = 0;
int dist_min = 1000000;
for (idx_type i = 0; i < nargs(); ++i) {
ar[i].nucleus()->edit(cur, x, y);
}
}
+
+
+DispatchResult
+MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
+{
+ //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
+
+ if (cmd.button() == mouse_button::button1) {
+ // try to dispatch to enclosed insets first
+ //cur.bv().stuffClipboard(cur.grabSelection());
+ return DispatchResult(true, true);
+ }
+
+ if (cmd.button() == mouse_button::button2) {
+ MathArray ar;
+ asArray(cur.bv().getClipboard(), ar);
+ cur.selClear();
+ cur.setScreenPos(cmd.x, cmd.y);
+ cur.insert(ar);
+ cur.bv().update();
+ return DispatchResult(true, true);
+ }
+
+ if (cmd.button() == mouse_button::button3) {
+ // try to dispatch to enclosed insets first
+ cur.bv().owner()->getDialogs().show("mathpanel");
+ return DispatchResult(true, true);
+ }
+
+ return DispatchResult(false);
+}
+
+
+DispatchResult
+MathNestInset::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
+{
+ lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
+ if (cmd.button() == mouse_button::button1) {
+ first_x = cmd.x;
+ first_y = cmd.y;
+ cur.selClear();
+ //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
+ lyxerr << "lfunMousePress: setting cursor to: " << cur << endl;
+ cur.bv().cursor() = cur;
+ return DispatchResult(true, true);
+ }
+
+ if (cmd.button() == mouse_button::button2) {
+ return priv_dispatch(cur, FuncRequest(LFUN_PASTESELECTION));
+ }
+
+ if (cmd.button() == mouse_button::button3) {
+ return DispatchResult(true, true);
+ }
+
+ return DispatchResult(true, true);
+}
+
+
+DispatchResult
+MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd)
+{
+ // only select with button 1
+ if (cmd.button() != mouse_button::button1)
+ return DispatchResult(true, true);
+
+ if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
+ return DispatchResult(true, true);
+
+ first_x = cmd.x;
+ first_y = cmd.y;
+
+ if (!cur.selection())
+ cur.selBegin();
+
+ //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
+ cur.bv().cursor().cursor_ = cur.cursor_;
+ cur.bv().cursor().selection() = true;
+ return DispatchResult(true, true);
+}