#include "support/std_sstream.h"
-using lyx::support::trim;
using std::endl;
using std::max;
DispatchResult
MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
- lyxerr << "*** MathHullInset: request: " << cmd << endl;
+ //lyxerr << "*** MathHullInset: request: " << cmd << endl;
switch (cmd.action) {
case LFUN_BREAKLINE:
case LFUN_MATH_NUMBER:
//lyxerr << "toggling all numbers" << endl;
if (display()) {
- //recordUndo(cur, Undo::INSERT);
+ ////recordUndo(cur, Undo::INSERT);
bool old = numberedType();
if (type_ == "multline")
numbered(nrows() - 1, !old);
else
for (row_type row = 0; row < nrows(); ++row)
numbered(row, !old);
- //cur.bv()->owner()->message(old ? _("No number") : _("Number"));
+ cur.message(old ? _("No number") : _("Number"));
}
return DispatchResult(true, true);
case LFUN_MATH_NONUMBER:
if (display()) {
row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
- //recordUndo(cur, Undo::INSERT);
+ ////recordUndo(cur, Undo::INSERT);
bool old = numbered(r);
- //cur.bv()->owner()->message(old ? _("No number") : _("Number"));
+ cur.message(old ? _("No number") : _("Number"));
numbered(r, !old);
}
return DispatchResult(true, true);
: Alert::askForText(_("Enter label:"), old_label);
if (!res.first)
return DispatchResult(false);
- new_label = trim(res.second);
+ new_label = lyx::support::trim(res.second);
}
//if (new_label == old_label)
#include "support/lyxlib.h"
-
-namespace {
-
-// local global
-int first_x;
-int first_y;
-
-} // namespace anon
-
-
-
int MathHullInset::ylow() const
{
return yo_ - dim_.asc;
{
// this whole function is a hack and won't work for incremental font
// changes...
- recordUndo(cur, Undo::ATOMIC);
+ //recordUndo(cur, Undo::ATOMIC);
if (cur.inset()->asMathInset()->name() == font)
cur.handleFont(font);
void MathHullInset::handleFont2(LCursor & cur, string const & arg)
{
- recordUndo(cur, Undo::ATOMIC);
+ //recordUndo(cur, Undo::ATOMIC);
LyXFont font;
bool b;
bv_funcs::string2font(arg, font, b);
}
-DispatchResult
-MathHullInset::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
-{
- if (!cur.inMathed())
- return DispatchResult(false);
- cur.bv().update();
- //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
-
- if (cmd.button() == mouse_button::button3) {
- // try to dispatch to enclosed insets first
- if (!cur.dispatch(cmd).dispatched()) {
- // launch math panel for right mouse button
- lyxerr << "lfunMouseRelease: undispatched: " << cmd.button() << endl;
- cur.bv().owner()->getDialogs().show("mathpanel");
- }
- 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::button1) {
- // try to dispatch to enclosed insets first
- cur.dispatch(cmd);
- cur.bv().stuffClipboard(cur.grabSelection());
- return DispatchResult(true, true);
- }
-
- return DispatchResult(false);
-}
-
-
-DispatchResult
-MathHullInset::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
-{
- //lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
-
- if (!cur.inMathed() || cur.formula() != this) {
- lyxerr[Debug::MATHED] << "re-create cursor" << endl;
- cur.releaseMathCursor();
- cur.idx() = 0;
- //metrics(bv);
- cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
- }
-
- if (cmd.button() == mouse_button::button3) {
- cur.dispatch(cmd);
- return DispatchResult(true, true);
- }
-
- if (cmd.button() == mouse_button::button1) {
- first_x = cmd.x;
- first_y = cmd.y;
- cur.selClear();
- cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
- cur.dispatch(cmd);
- return DispatchResult(true, true);
- }
-
- cur.bv().update();
- return DispatchResult(true, true);
-}
-
-
-DispatchResult
-MathHullInset::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd)
-{
- if (!cur.inMathed())
- return DispatchResult(true, true);
-
- if (cur.dispatch(FuncRequest(cmd)).dispatched())
- return DispatchResult(true, true);
-
- // 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().update();
- return DispatchResult(true, true);
-}
-
-
-void MathHullInset::edit(LCursor & cur, bool left)
-{
- lyxerr << "Called FormulaBase::edit" << endl;
- cur.push(this);
- cur.idx() = left ? 0 : cur.lastidx();
- cur.pos() = left ? 0 : cur.lastpos();
- cur.resetAnchor();
-}
-
-
-/*
-void MathHullInset::edit(LCursor & cur, int x, int y)
-{
- lyxerr << "Called MathHullInset::edit with '" << x << ' ' << y << "'" << endl;
- cur.push(this);
- //cur.idx() = left ? 0 : cur.lastidx();
- cur.idx() = 0;
- cur.pos() = 0;
- cur.setScreenPos(x + xo_, y + yo_);
- // if that is removed, we won't get the magenta box when entering an
- // inset for the first time
- cur.bv().update();
-}
-*/
-
-
void MathHullInset::revealCodes(LCursor & cur) const
{
if (!cur.inMathed())
return;
ostringstream os;
cur.info(os);
- cur.bv().owner()->message(os.str());
+ cur.message(os.str());
/*
// write something to the minibuffer
// translate to latex
res = res.substr(pos - 30);
if (res.size() > 60)
res = res.substr(0, 60);
- bv.owner()->message(res);
+ cur.message(res);
*/
}
ms << ETag("equation");
return ms.line() + res;
}
-
-
-
-/////////////////////////////////////////////
-
-namespace {
-
-bool openNewInset(LCursor & cur, InsetBase * inset)
-{
- if (!cur.bv().insertInset(inset)) {
- delete inset;
- return false;
- }
- inset->edit(cur, true);
- return true;
-}
-
-
-void mathDispatchCreation(LCursor & cur, FuncRequest const & cmd,
- bool display)
-{
- // use selection if available..
- //string sel;
- //if (action == LFUN_MATH_IMPORT_SELECTION)
- // sel = "";
- //else
-
- string sel =
- cur.bv().getLyXText()->selectionAsString(*cur.bv().buffer(), false);
-
- if (sel.empty()) {
- InsetBase * f = new MathHullInset;
- if (openNewInset(cur, f)) {
- cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, "simple"));
- // don't do that also for LFUN_MATH_MODE unless you want end up with
- // always changing to mathrm when opening an inlined inset
- // -- I really hate "LyXfunc overloading"...
- if (display)
- f->dispatch(cur, FuncRequest(LFUN_MATH_DISPLAY));
- f->dispatch(cur, FuncRequest(LFUN_INSERT_MATH, cmd.argument));
- }
- } else {
- // create a macro if we see "\\newcommand" somewhere, and an ordinary
- // formula otherwise
- InsetBase * f;
- if (sel.find("\\newcommand") == string::npos &&
- sel.find("\\def") == string::npos)
- f = new MathHullInset(sel);
- else
- f = new InsetFormulaMacro(sel);
- cur.bv().getLyXText()->cutSelection(true, false);
- openNewInset(cur, f);
- }
- cmd.message(N_("Math editor mode"));
-}
-
-} // namespace anon
-
-
-void mathDispatch(LCursor & cur, FuncRequest const & cmd)
-{
- if (!cur.bv().available())
- return;
-
- switch (cmd.action) {
-
- case LFUN_MATH_DISPLAY:
- mathDispatchCreation(cur, cmd, true);
- break;
-
- case LFUN_MATH_MODE:
- mathDispatchCreation(cur, cmd, false);
- break;
-
- case LFUN_MATH_IMPORT_SELECTION:
- mathDispatchCreation(cur, cmd, false);
- break;
-
-/*
- case LFUN_MATH_MACRO:
- if (cmd.argument.empty())
- cmd.errorMessage(N_("Missing argument"));
- else {
- string s = cmd.argument;
- string const s1 = token(s, ' ', 1);
- int const nargs = s1.empty() ? 0 : atoi(s1);
- string const s2 = token(s, ' ', 2);
- string const type = s2.empty() ? "newcommand" : s2;
- openNewInset(cur, new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
- }
- break;
-
- 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);
- }
- break;
- }
-*/
-
- default:
- break;
- }
-}