]> git.lyx.org Git - features.git/commitdiff
mathed87.diff (Bug fixes, new feature "change font on selection")
authorAndré Pönitz <poenitz@gmx.net>
Tue, 3 Jul 2001 07:56:55 +0000 (07:56 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 3 Jul 2001 07:56:55 +0000 (07:56 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2169 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/array.C
src/mathed/array.h
src/mathed/formulabase.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_parser.C
src/mathed/math_rowst.C [deleted file]
src/mathed/math_rowst.h [deleted file]

index 1f732a7db3b8c2ac90e6a87d070f42aae6fd95a7..7bda17ac372b4cbbf3bd34471d6e277f5ece21c9 100644 (file)
@@ -1,3 +1,11 @@
+2001-04-27 André Pönitz  <poenitz@htwm.de>
+
+       * math_parser.C: fix bug where equations did not get their labels
+
+       * formulabase.C: new feature: changing font on selection
+
+       * several files: subsequent changes
+
 2001-06-29  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
 
        * formulabase.C (localDispatch): use .c_str() on istringstream
 
        * math_cursor.C: Renamed stack to path.
 
+2001-06-24  The LyX Project  <André>
+
+       * *.[Ch]:
+         Makefile.am: The Big Patch
+         (rewrite of MathArray, MathCursor, MathMatrixInset, MathBigopInset;
+     new MathScriptInset for up/down stuff;
+          delete MathIter/MatXIter, MathParInset, MathRowSt
+     Changes to the inset inheritance tree, reunification of abstract math
+     inset base classes;
+     label/numbering handling back to life;
+     major changes to the parser(s);
+     new base class FormulaBase for the two math LyXInsets;
+          general cleanup and cosmetic changes)
+
 2001-06-19  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * math_macro.C:
index bf2d916877ad45688d635d0f3473dc9e86c664d6..a1e7063a4bf0b0e135862160d1313fef5af9eeea 100644 (file)
@@ -110,6 +110,14 @@ MathTextCodes MathArray::GetCode(int pos) const
        return pos < size() ? MathTextCodes(bf_[pos]) : LM_TC_MIN;
 }
 
+void MathArray::setCode(int pos, MathTextCodes t)
+{
+       if (pos > size() || isInset(pos))
+               return;
+       bf_[pos] = t;
+       bf_[pos + 2] = t;
+}
+
 void MathArray::insert(int pos, MathInset * p)
 {
        bf_.insert(bf_.begin() + pos, 2 + sizeof(p), LM_TC_INSET);
index cd0c071efd54962e477c67465d230bea0fb3fca9..82bd8bd32b947b2893cb89c2c1054d97516f692f 100644 (file)
@@ -110,6 +110,8 @@ public:
        ///
        MathTextCodes GetCode(int pos) const;
        ///
+       void setCode(int pos, MathTextCodes t);
+       ///
        bool isInset(int pos) const;
        ///
        void Write(std::ostream &, bool) const;
index bb4115960515719f88a986afd582715fed28d87d..21e2c6eba55a0e21799e32fc28c47e808acedb17 100644 (file)
@@ -68,6 +68,13 @@ string nicelabel(string const & label)
        return label.empty() ? string("(#)") : "(" + label + ")";
 }
 
+void handleFont(BufferView * bv, MathTextCodes t) 
+{
+       if (mathcursor->Selection())
+               bv->lockedInsetStoreUndo(Undo::EDIT);
+       mathcursor->handleFont(t);
+}
+
 } // namespaces
 
 
@@ -431,6 +438,7 @@ void InsetFormulaBase::insetKeyPress(XKeyEvent *)
 }
 
 
+
 UpdatableInset::RESULT
 InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
                            string const & arg)
@@ -619,24 +627,27 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
                break;
 
                //  Math fonts
-       case LFUN_BOLD:  mathcursor->toggleLastCode(LM_TC_BF); break;
-       case LFUN_SANS:  mathcursor->toggleLastCode(LM_TC_SF); break;
-       case LFUN_EMPH:  mathcursor->toggleLastCode(LM_TC_CAL); break;
-       case LFUN_ROMAN: mathcursor->toggleLastCode(LM_TC_RM); break;
-       case LFUN_CODE:  mathcursor->toggleLastCode(LM_TC_TT); break;
-       case LFUN_DEFAULT:  mathcursor->setLastCode(LM_TC_VAR); break;
+       case LFUN_BOLD:    handleFont(bv, LM_TC_BF); break;
+       case LFUN_SANS:    handleFont(bv, LM_TC_SF); break;
+       case LFUN_EMPH:    handleFont(bv, LM_TC_CAL); break;
+       case LFUN_ROMAN:   handleFont(bv, LM_TC_RM); break;
+       case LFUN_CODE:    handleFont(bv, LM_TC_TT); break;
+       case LFUN_DEFAULT: handleFont(bv, LM_TC_VAR); break;
+
+       case LFUN_MATH_MODE:
+               handleFont(bv, LM_TC_TEXTRM);
+               //bv->owner()->message(_("math text mode toggled"));
+               break;
 
 #ifndef NO_LATEX
-#ifdef WITH_WARNINGS
-#warning This needs a fix.
-               // Can we use the ERT inset here? (Lgb)
-#endif
        case LFUN_TEX:
-               // varcode = LM_TC_TEX;
-               mathcursor->setLastCode(LM_TC_TEX);
-               bv->owner()->message(_("TeX mode"));
+               if (!mathcursor->Selection()) {
+                       mathcursor->handleFont(LM_TC_TEX);
+                       //bv->owner()->message(_("TeX mode toggled"));
+               }
                break;
 #endif
+
        case LFUN_MATH_LIMITS:
                bv->lockedInsetStoreUndo(Undo::INSERT);
                if (mathcursor->toggleLimits())
@@ -730,16 +741,6 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
                updateLocal(bv);
                break;
 
-               // Invalid actions under math mode
-       case LFUN_MATH_MODE:
-               if (mathcursor->getLastCode() != LM_TC_TEXTRM) {
-                       bv->owner()->message(_("math text mode"));
-                       varcode = LM_TC_TEXTRM;
-               } else 
-                       varcode = LM_TC_VAR;
-               mathcursor->setLastCode(varcode);
-               break;
-
        case LFUN_UNDO:
                bv->owner()->message(_("Invalid action in math mode!"));
                break;
index 9086e861e4e12e61fd66c99b6602553ed215d3b3..88c58fb47bc8eb7d9f1e6fdaaeff6030c77888c6 100644 (file)
@@ -915,12 +915,22 @@ void MathCursor::doAccent(MathInset * p)
 }
 
 
-void MathCursor::toggleLastCode(MathTextCodes t)
-{
-       if (lastcode == t)
-               lastcode = LM_TC_VAR;
-       else
-               lastcode = t;
+void MathCursor::handleFont(MathTextCodes t)
+{
+       if (selection)  {
+               int const p1 = std::min(cursor_, anchor_);
+               int const p2 = std::max(cursor_, anchor_);
+               for (int pos = p1; pos != p2; array().next(pos))
+                       if (!array().isInset(pos)) { 
+                               MathTextCodes c = array().GetCode(pos) == t ? LM_TC_VAR : t;
+                               array().setCode(pos, c);
+                       }
+       } else {
+               if (lastcode == t)
+                       lastcode = LM_TC_VAR;
+               else
+                       lastcode = t;
+       }
 }
 
 
index af340065bb03cc5b97e335b5b7e67425e811bbc6..df762363b1621cf026dd33416d296ead4d5f30b6 100644 (file)
@@ -116,7 +116,7 @@ public:
        ///
        void setLastCode(MathTextCodes t);
        ///
-       void toggleLastCode(MathTextCodes t);
+       void handleFont(MathTextCodes t);
        ///
        MathTextCodes getLastCode() const;
        ///
index e5640e6036dcf53e0856fb0a71cbc728baaa4406..d0f79b98c1c75777a3efe61979fe579ca8589354 100644 (file)
@@ -109,10 +109,9 @@ union {
 
 
 string yytext;
-
 int yylineno;
 istream * yyis;
-bool yy_mtextmode = false;
+MathTextCodes yyvarcode;
 
 
 
@@ -234,8 +233,8 @@ int yylex()
                char c;
                yyis->get(c);
                
-               if (yy_mtextmode && c == ' ') {
-                       yylval.i= ' ';
+               if (yyvarcode == LM_TC_TEXTRM && c == ' ') {
+                       yylval.i = ' ';
                        return LM_TK_ALPHA;
                } else if (lexcode[c] == LexNewLine) {
                        ++yylineno; 
@@ -419,6 +418,10 @@ static string curr_label;
 
 void mathed_parse_lines(MathInset * inset, int col, bool numbered, bool outmost)
 {
+       // save global variables
+       bool   saved_num   = curr_num;
+       string saved_label = curr_label;
+
        MathGridInset * p = static_cast<MathGridInset *>(inset);
        for (int row = 0; true; ++row) {
                // reset global variables
@@ -444,6 +447,10 @@ void mathed_parse_lines(MathInset * inset, int col, bool numbered, bool outmost)
 
                p->appendRow();
        }
+
+       // restore global variables
+       curr_num   = saved_num;
+       curr_label = saved_label;
 }
 
 
@@ -536,7 +543,7 @@ void mathed_parse(MathArray & array, unsigned flags)
        int  tprev = 0;
        bool panic = false;
        static int plevel = -1;
-       MathTextCodes varcode = LM_TC_VAR;
+       yyvarcode = LM_TC_VAR;
        
        int brace = 0;
        int acc_brace = 0;
@@ -560,7 +567,7 @@ void mathed_parse(MathArray & array, unsigned flags)
                switch (t) {
                        
                case LM_TK_ALPHA:
-                       do_insert(array, yylval.i, varcode);
+                       do_insert(array, yylval.i, yyvarcode);
                        break;
 
                case LM_TK_ARGUMENT:
@@ -604,8 +611,7 @@ void mathed_parse(MathArray & array, unsigned flags)
                                break;
                        }
                        if (flags & FLAG_BRACE_FONT) {
-                               varcode = LM_TC_VAR;
-                               yy_mtextmode = false;
+                               yyvarcode = LM_TC_VAR;
                                flags &= ~FLAG_BRACE_FONT;
                                break;
                        }
@@ -777,7 +783,7 @@ void mathed_parse(MathArray & array, unsigned flags)
                        break;
                
                case LM_TK_FONT:
-                       yy_mtextmode = (yylval.l->id == LM_TC_TEXTRM);
+                       yyvarcode = static_cast<MathTextCodes>(yylval.l->id);
                        flags |= (FLAG_BRACE | FLAG_BRACE_FONT);
                        break;
 
diff --git a/src/mathed/math_rowst.C b/src/mathed/math_rowst.C
deleted file mode 100644 (file)
index db8077f..0000000
+++ /dev/null
@@ -1,210 +0,0 @@
-#include <config.h>
-
-#include "math_rowst.h"
-#include "support/LAssert.h"
-
-
-//
-// MathedRowContainer
-//
-
-MathedRowStruct::MathedRowStruct()
-       : asc_(0), desc_(0), y_(0), numbered_(true)
-{}
-
-
-string const & MathedRowStruct::getLabel() const
-{
-       return label_;
-}
-
-
-bool MathedRowStruct::isNumbered() const
-{
-       return numbered_;
-}
-
-
-int MathedRowStruct::getBaseline() const
-{
-       return y_;
-}
-
-
-void MathedRowStruct::setBaseline(int b)
-{
-       y_ = b;
-}
-
-
-int MathedRowStruct::ascent() const
-{
-       return asc_;
-}
-
-
-int MathedRowStruct::descent() const
-{
-       return desc_;
-}
-
-
-void MathedRowStruct::ascent(int a)
-{
-       asc_ = a;
-}
-
-
-void MathedRowStruct::descent(int d)
-{
-       desc_ = d;
-}
-
-
-int MathedRowStruct::getTab(unsigned int i) const
-{
-       return i < widths_.size() ? widths_[i] : 0;
-}
-
-
-void MathedRowStruct::setLabel(string const & l)
-{
-       label_ = l;
-}
-
-
-void MathedRowStruct::setNumbered(bool nf)
-{
-       numbered_ = nf;
-}
-
-
-void MathedRowStruct::setTab(unsigned int i, int t)
-{
-       if (i >= widths_.size())
-               widths_.resize(i + 2);  
-       widths_[i] = t;
-}
-
-
-
-//
-// MathedRowContainer
-//
-
-
-MathedRowContainer::iterator MathedRowContainer::begin()
-{
-       return iterator(this);
-}
-
-
-MathedRowContainer::iterator MathedRowContainer::end()
-{
-       iterator it(this);
-       it.pos_ = data_.size();
-       return it;
-}
-
-
-bool MathedRowContainer::empty() const
-{
-       return data_.size() == 0;
-}
-
-
-void MathedRowContainer::insert(iterator const & it)
-{
-       lyx::Assert(it.st_ == this);
-       data_.insert(data_.begin() + it.pos_, MathedRowStruct());
-}
-
-
-void MathedRowContainer::erase(iterator & it)
-{
-       lyx::Assert(it.st_ == this);
-       data_.erase(data_.begin() + it.pos_);
-}
-
-
-MathedRowStruct & MathedRowContainer::back()
-{
-       lyx::Assert(data_.size());
-       return data_.back();
-}
-
-
-MathedRowStruct const & MathedRowContainer::back() const
-{
-       lyx::Assert(data_.size());
-       return data_.back();
-}
-
-
-void MathedRowContainer::push_back()
-{
-       data_.push_back(MathedRowStruct());
-}
-
-
-MathedRowContainer::size_type MathedRowContainer::size() const
-{
-       return data_.size();
-}
-
-
-
-//
-// MathedRowContainer::iterator
-//
-
-MathedRowContainer::iterator::iterator()
-       : st_(0), pos_(0)
-{}
-
-
-MathedRowContainer::iterator::iterator(MathedRowContainer * m)
-       : st_(m), pos_(0)
-{}
-
-
-MathedRowContainer::iterator::operator void *() const
-{
-       return (void *)(st_ && pos_ < st_->size());
-}
-
-
-MathedRowStruct * MathedRowContainer::iterator::operator->()
-{
-       lyx::Assert(st_);
-       return &st_->data_[pos_];
-}
-
-
-MathedRowStruct const * MathedRowContainer::iterator::operator->() const
-{
-       lyx::Assert(st_);
-       return &st_->data_[pos_];
-}
-
-
-void MathedRowContainer::iterator::operator++()
-{
-       lyx::Assert(st_);
-       ++pos_;
-}
-
-
-bool MathedRowContainer::iterator::is_last() const
-{
-       lyx::Assert(st_);
-       return pos_ == st_->size() - 1;
-}
-
-
-bool MathedRowContainer::iterator::operator==(const iterator & it) const
-{
-       return st_ == it.st_ && pos_ == it.pos_;
-}
-
-
diff --git a/src/mathed/math_rowst.h b/src/mathed/math_rowst.h
deleted file mode 100644 (file)
index 5134dfd..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-// -*- C++ -*-
-#ifndef MATH_ROWST_H
-#define MATH_ROWST_H
-
-#include "support/LAssert.h"
-#include <vector>
-
-/** The physical structure of a row and aditional information is stored here.
-    It allows to manage the extra info independently of the paragraph data.  
-    Only used for multiline paragraphs.
- */
-
-class MathedRowStruct
-{
-public:
-       ///
-       typedef std::vector<int> Widths;
-       
-       ///
-       MathedRowStruct();
-       ///
-       string const & getLabel() const;
-       ///
-       bool isNumbered() const;
-       ///
-       int  getBaseline() const;
-       ///
-       void setBaseline(int b);
-       ///
-       int ascent() const;
-       ///
-       int descent() const;
-       ///
-       void ascent(int a);
-       ///
-       void descent(int d);
-       ///
-       int  getTab(unsigned int i) const;
-       /// 
-       void setLabel(string const & l);
-       ///
-       void setNumbered(bool nf);
-       ///
-       void setTab(unsigned int i, int t);
-       ///
-       friend class MathedRowSt;
-protected:
-       /// Vericals 
-       int asc_;
-       ///
-       int desc_;
-       ///
-       int y_;
-       /// widths 
-       Widths widths_;
-       /// 
-       string label_;
-       ///
-       bool numbered_;
-};
-
-
-class MathedRowContainer {
-public:
-       ///
-       typedef std::vector<MathedRowStruct>   data_type;
-       ///
-       typedef data_type::size_type           size_type;
-       ///
-       struct iterator {
-               ///
-               iterator();
-               ///
-               explicit iterator(MathedRowContainer * m);
-               /// "better" conversion to bool
-               operator void *() const;
-               ///
-               MathedRowStruct * operator->();
-               ///
-               MathedRowStruct const * operator->() const;
-               ///
-               void operator++();
-               ///
-               bool is_last() const;
-               ///
-               bool operator==(const iterator & it) const;
-
-       //private:
-               MathedRowContainer * st_;
-               ///
-               unsigned int pos_;
-       };
-
-public:
-       /// 
-       iterator begin();
-       /// 
-       iterator end();
-       ///
-       bool empty() const;
-
-       /// insert item before 'it'
-       void insert(iterator const & it);
-       /// erase item pointed to by 'it'
-       void erase(iterator & it);
-       /// access to last row
-       MathedRowStruct & back();
-       /// access to last row
-       MathedRowStruct const & back() const;
-       /// append empty element
-       void push_back();
-       ///
-       size_type size() const;
-       
-//private:
-       ///
-       std::vector<MathedRowStruct> data_;
-};
-
-#endif