]> git.lyx.org Git - features.git/blobdiff - src/mathed/formulabase.C
Replace LString.h with support/std_string.h,
[features.git] / src / mathed / formulabase.C
index 9078c9ffce2552c55ea57801841d9cffd3098d44..c50427587aff15045308bfaa425a397065a12262 100644 (file)
@@ -1,56 +1,43 @@
-/*
-*  File:        formulabase.C
-*  Purpose:     Implementation of common parts of the LyX  math insets
-*  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
-*  Created:     January 1996
-*
-*  Copyright: 1996-1998 Alejandro Aguilar Sierra
-*
-*  Version: 0.4, Lyx project.
-*
-*   You are free to use and modify this code under the terms of
-*   the GNU General Public Licence version 2 or later.
-*/
+/**
+ * \file formulabase.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Alejandro Aguilar Sierra
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
-#include "Lsstream.h"
+#include "formulabase.h"
+#include "support/std_sstream.h"
 #include "support/LAssert.h"
 #include "formula.h"
 #include "formulamacro.h"
-#include "lyxrc.h"
 #include "funcrequest.h"
 #include "BufferView.h"
 #include "lyxtext.h"
 #include "gettext.h"
-#include "LaTeXFeatures.h"
 #include "debug.h"
 #include "math_support.h"
-#include "metricsinfo.h"
-#include "math_data.h"
 #include "support/lstrings.h"
+#include "support/lyxlib.h"
 #include "frontends/LyXView.h"
-#include "frontends/font_metrics.h"
-#include "frontends/mouse_state.h"
 #include "math_arrayinset.h"
-#include "math_charinset.h"
 #include "math_deliminset.h"
 #include "math_cursor.h"
 #include "math_factory.h"
-#include "math_fontinset.h"
 #include "math_hullinset.h"
-#include "math_iterator.h"
-#include "math_macrotable.h"
 #include "math_parser.h"
-#include "math_pos.h"
 #include "math_spaceinset.h"
 #include "undo_funcs.h"
-#include "textpainter.h"
 #include "frontends/Dialogs.h"
-#include "intl.h"
 #include "ref_inset.h"
 
-#include <fstream>
+
+using namespace lyx::support;
 
 using std::endl;
 using std::ostream;
@@ -83,14 +70,14 @@ bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
 
 
 InsetFormulaBase::InsetFormulaBase()
-       : xo_(0), yo_(0)
+       : view_(0), xo_(0), yo_(0)
 {
        // This is needed as long the math parser is not re-entrant
        initMath();
-       //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
-       //lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << "\n";
-       //lyxerr << "sizeof MathCharInset: " << sizeof(MathCharInset) << "\n";
-       //lyxerr << "sizeof LyXFont: " << sizeof(LyXFont) << "\n";
+       //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << endl;
+       //lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << endl;
+       //lyxerr << "sizeof MathCharInset: " << sizeof(MathCharInset) << endl;
+       //lyxerr << "sizeof LyXFont: " << sizeof(LyXFont) << endl;
 }
 
 
@@ -121,7 +108,8 @@ void InsetFormulaBase::handleFont
 {
        // this whole function is a hack and won't work for incremental font
        // changes...
-       bv->lockedInsetStoreUndo(Undo::EDIT);
+       recordUndo(bv, Undo::ATOMIC);
+
        if (mathcursor->inset()->name() == font)
                mathcursor->handleFont(font);
        else {
@@ -207,12 +195,6 @@ void InsetFormulaBase::toggleInsetSelection(BufferView * bv)
 }
 
 
-vector<string> const InsetFormulaBase::getLabelList() const
-{
-  return vector<string>();
-}
-
-
 dispatch_result InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd)
 {
        if (!mathcursor)
@@ -333,9 +315,9 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
 
        switch (cmd.action) {
                case LFUN_INSET_EDIT:
-                       lyxerr << "Called EDIT with '" << cmd.argument << "'\n";
+                       lyxerr << "Called EDIT with '" << cmd.argument << "'" << endl;
                        if (!bv->lockInset(this))
-                               lyxerr << "Cannot lock math inset in edit call!\n";
+                               lyxerr << "Cannot lock math inset in edit call!" << endl;
                        releaseMathCursor(bv);
                        if (!cmd.argument.empty()) {
                                mathcursor = new MathCursor(this, cmd.argument == "left");
@@ -351,16 +333,16 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
                        return DISPATCHED;
 
                case LFUN_MOUSE_PRESS:
-                       //lyxerr << "Mouse single press\n";
+                       //lyxerr << "Mouse single press" << endl;
                        return lfunMousePress(cmd);
                case LFUN_MOUSE_MOTION:
-                       //lyxerr << "Mouse motion\n";
+                       //lyxerr << "Mouse motion" << endl;
                        return lfunMouseMotion(cmd);
                case LFUN_MOUSE_RELEASE:
-                       //lyxerr << "Mouse single release\n";
+                       //lyxerr << "Mouse single release" << endl;
                        return lfunMouseRelease(cmd);
                case LFUN_MOUSE_DOUBLE:
-                       //lyxerr << "Mouse double\n";
+                       //lyxerr << "Mouse double" << endl;
                        return localDispatch(FuncRequest(LFUN_WORDSEL));
                default:
                        break;
@@ -392,7 +374,7 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        case LFUN_TABULAR_FEATURE:
        case LFUN_PASTESELECTION:
        case LFUN_MATH_LIMITS:
-               bv->lockedInsetStoreUndo(Undo::EDIT);
+               recordUndo(bv, Undo::ATOMIC);
                mathcursor->dispatch(cmd);
                break;
 
@@ -400,7 +382,7 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
                sel = true; // fall through...
        case LFUN_RIGHT:
                result = mathcursor->right(sel) ? DISPATCHED : FINISHED_RIGHT;
-               //lyxerr << "calling scroll 20\n";
+               //lyxerr << "calling scroll 20" << endl;
                //scroll(bv, 20);
                // write something to the minibuffer
                //bv->owner()->message(mathcursor->info());
@@ -476,7 +458,7 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
 
        case LFUN_DELETE_WORD_BACKWARD:
        case LFUN_BACKSPACE:
-               bv->lockedInsetStoreUndo(Undo::EDIT);
+               recordUndo(bv, Undo::ATOMIC);
                if (!mathcursor->backspace()) {
                        result = FINISHED;
                        remove_inset = true;
@@ -485,7 +467,7 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
 
        case LFUN_DELETE_WORD_FORWARD:
        case LFUN_DELETE:
-               bv->lockedInsetStoreUndo(Undo::EDIT);
+               recordUndo(bv, Undo::ATOMIC);
                if (!mathcursor->erase()) {
                        result = FINISHED;
                        remove_inset = true;
@@ -497,7 +479,7 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        //      dispatch_result = dispatch_buffer;
        //      break;
        case LFUN_SETXY: {
-               lyxerr << "LFUN_SETXY broken!\n";
+               lyxerr << "LFUN_SETXY broken!" << endl;
                int x = 0;
                int y = 0;
                istringstream is(cmd.argument.c_str());
@@ -507,18 +489,18 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        }
 
        case LFUN_PASTE: {
-               int n = 0;
+               size_t n = 0;
                istringstream is(cmd.argument.c_str());
                is >> n;
                if (was_macro)
                        mathcursor->macroModeClose();
-               bv->lockedInsetStoreUndo(Undo::EDIT);
+               recordUndo(bv, Undo::ATOMIC);
                mathcursor->selPaste(n);
                break;
        }
 
        case LFUN_CUT:
-               bv->lockedInsetStoreUndo(Undo::DELETE);
+               recordUndo(bv, Undo::DELETE);
                mathcursor->selCut();
                break;
 
@@ -533,7 +515,7 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
                if (cmd.argument.empty()) {
                        // do superscript if LyX handles
                        // deadkeys
-                       bv->lockedInsetStoreUndo(Undo::EDIT);
+                       recordUndo(bv, Undo::ATOMIC);
                        mathcursor->script(true);
                }
                break;
@@ -577,14 +559,14 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        case LFUN_MATH_SIZE:
 #if 0
                if (!arg.empty()) {
-                       bv->lockedInsetStoreUndo(Undo::EDIT);
+                       recordUndo(bv, Undo::ATOMIC);
                        mathcursor->setSize(arg);
                }
 #endif
                break;
 
        case LFUN_INSERT_MATRIX: {
-               bv->lockedInsetStoreUndo(Undo::EDIT);
+               recordUndo(bv, Undo::ATOMIC);
                unsigned int m = 1;
                unsigned int n = 1;
                string v_align;
@@ -602,14 +584,14 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        case LFUN_SUPERSCRIPT:
        case LFUN_SUBSCRIPT:
        {
-               bv->lockedInsetStoreUndo(Undo::EDIT);
+               recordUndo(bv, Undo::ATOMIC);
                mathcursor->script(cmd.action == LFUN_SUPERSCRIPT);
                break;
        }
 
        case LFUN_MATH_DELIM:
        {
-               //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
+               //lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'" << endl;
                string ls;
                string rs = split(cmd.argument, ls, ' ');
                // Reasonable default values
@@ -618,14 +600,14 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
                if (rs.empty())
                        rs = ')';
 
-               bv->lockedInsetStoreUndo(Undo::EDIT);
+               recordUndo(bv, Undo::ATOMIC);
                mathcursor->handleNest(MathAtom(new MathDelimInset(ls, rs)));
                break;
        }
 
        case LFUN_SPACE_INSERT:
        case LFUN_MATH_SPACE:
-               bv->lockedInsetStoreUndo(Undo::EDIT);
+               recordUndo(bv, Undo::ATOMIC);
                mathcursor->insert(MathAtom(new MathSpaceInset(",")));
                break;
 
@@ -640,7 +622,7 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
 
        case LFUN_INSET_ERT:
                // interpret this as if a backslash was typed
-               bv->lockedInsetStoreUndo(Undo::EDIT);
+               recordUndo(bv, Undo::ATOMIC);
                mathcursor->interpret('\\');
                break;
 
@@ -654,17 +636,17 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
 // handling such that "self-insert" works on "arbitrary stuff" too, and
 // math-insert only handles special math things like "matrix".
        case LFUN_INSERT_MATH:
-               bv->lockedInsetStoreUndo(Undo::EDIT);
+               recordUndo(bv, Undo::ATOMIC);
                mathcursor->niceInsert(argument);
                break;
 
        case -1:
        case LFUN_SELFINSERT:
                if (!argument.empty()) {
-                       bv->lockedInsetStoreUndo(Undo::EDIT);
+                       recordUndo(bv, Undo::ATOMIC);
                        if (argument.size() == 1)
                                result = mathcursor->interpret(argument[0]) ? DISPATCHED : FINISHED_RIGHT;
-                       else 
+                       else
                                mathcursor->insert(argument);
                }
                break;
@@ -681,8 +663,7 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_DIALOG_SHOW:
-               if (argument == "mathpanel")
-                       result = UNDISPATCHED;
+               result = UNDISPATCHED;
                break;
 
        case LFUN_DIALOG_SHOW_NEW_INSET: {
@@ -731,7 +712,7 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        mathcursor->normalize();
        mathcursor->touch();
 
-       lyx::Assert(mathcursor);
+       Assert(mathcursor);
 
        if (mathcursor->selection() || was_selection)
                toggleInsetSelection(bv);
@@ -787,9 +768,9 @@ void InsetFormulaBase::revealCodes(BufferView * bv) const
 }
 
 
-Inset::Code InsetFormulaBase::lyxCode() const
+InsetOld::Code InsetFormulaBase::lyxCode() const
 {
-       return Inset::MATH_CODE;
+       return InsetOld::MATH_CODE;
 }
 
 
@@ -832,7 +813,7 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
        static string laststr;
 
        if (lastformula != this || laststr != str) {
-               //lyxerr << "reset lastformula to " << this << "\n";
+               //lyxerr << "reset lastformula to " << this << endl;
                lastformula = this;
                laststr = str;
                current = ibegin(par().nucleus());
@@ -861,7 +842,7 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
                }
        }
 
-       //lyxerr << "not found!\n";
+       //lyxerr << "not found!" << endl;
        lastformula = 0;
        return false;
 }
@@ -870,7 +851,7 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
 bool InsetFormulaBase::searchBackward(BufferView * bv, string const & what,
                                      bool a, bool b)
 {
-       lyxerr[Debug::MATHED] << "searching backward not implemented in mathed\n";
+       lyxerr[Debug::MATHED] << "searching backward not implemented in mathed" << endl;
        return searchForward(bv, what, a, b);
 }
 
@@ -898,7 +879,7 @@ void mathDispatchCreation(FuncRequest const & cmd, bool display)
        //      sel = "";
        //else
 
-       string sel = bv->getLyXText()->selectionAsString(bv->buffer(), false);
+       string sel = bv->getLyXText()->selectionAsString(*bv->buffer(), false);
 
        if (sel.empty()) {
                InsetFormula * f = new InsetFormula(bv);
@@ -954,8 +935,10 @@ void mathDispatch(FuncRequest const & cmd)
                        else {
                                string s = cmd.argument;
                                string const s1 = token(s, ' ', 1);
-                               int const na = s1.empty() ? 0 : lyx::atoi(s1);
-                               openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
+                               int const nargs = s1.empty() ? 0 : atoi(s1);
+                               string const s2 = token(s, ' ', 2);
+                               string const type = s2.empty() ? "newcommand" : s2;
+                               openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
                        }
                        break;