]> git.lyx.org Git - features.git/commitdiff
preliminary support for \mbox
authorAndré Pönitz <poenitz@gmx.net>
Tue, 18 Dec 2001 12:21:33 +0000 (12:21 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 18 Dec 2001 12:21:33 +0000 (12:21 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3237 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/formulabase.C
src/mathed/math_boxinset.C
src/mathed/math_boxinset.h
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_defs.h
src/mathed/math_hash.C
src/mathed/math_inset.h
src/mathed/math_parser.C
src/mathed/math_support.C

index fc2b83b1ff330a0e4a82a8d00fc530154bd93c36..1af5cd2f1d3df38eaa268ba817493a8445cab130 100644 (file)
 #include "LyXView.h"
 #include "Painter.h"
 #include "font.h"
-#include "math_cursor.h"
 #include "math_arrayinset.h"
-#include "math_spaceinset.h"
-#include "math_macrotable.h"
+#include "math_cursor.h"
 #include "math_factory.h"
+#include "math_hullinset.h"
+#include "math_macrotable.h"
 #include "math_parser.h"
+#include "math_spaceinset.h"
 #include "undo_funcs.h"
 
 using std::endl;
@@ -523,7 +524,9 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
                break;
 
        case LFUN_MATH_MODE:
-               handleFont(bv, LM_TC_TEXTRM);
+               //handleFont(bv, LM_TC_TEXTRM);
+               mathcursor->niceInsert(MathAtom(new MathHullInset(LM_OT_SIMPLE)));
+               updateLocal(bv, true);
                //bv->owner()->message(_("math text mode toggled"));
                break;
 
index 1a546c78264f8ae9a2bed53d2576f17236a25462..b2ed64015f875667382793ff64fffec246bb6e15 100644 (file)
@@ -6,47 +6,23 @@
 
 #include "math_boxinset.h"
 #include "support/LOstream.h"
-#include "LColor.h"
 #include "debug.h"
 #include "Painter.h"
 #include "math_cursor.h"
-#include "insets/insettext.h"
 #include "math_mathmlstream.h"
 #include "math_streamstr.h"
 
 MathBoxInset::MathBoxInset(string const & name)
-       : MathDimInset(), name_(name), text_(new InsetText), buffer_(0)
+       : MathGridInset(1, 1), name_(name)
 {}
 
 
-MathBoxInset::MathBoxInset(MathBoxInset const & m)
-       :       MathDimInset(*this), name_(m.name_), text_(0), buffer_(m.buffer_)
-{
-       if (!m.buffer_)
-               lyxerr << "no buffer\n";
-       else
-               text_ = static_cast<InsetText *>(m.text_->clone(*m.buffer_, false));
-}
-
-
-MathBoxInset::~MathBoxInset()
-{
-       delete text_;
-}
-
-
 MathInset * MathBoxInset::clone() const
 {
        return new MathBoxInset(*this);
 }
 
 
-UpdatableInset * MathBoxInset::asHyperActiveInset() const
-{
-       return text_;
-}
-
-
 void MathBoxInset::write(WriteStream & os) const
 {
        os << "\\" << name_ << "{" << cell(0) << "}";
@@ -55,40 +31,23 @@ void MathBoxInset::write(WriteStream & os) const
 
 void MathBoxInset::normalize(NormalStream & os) const
 {
-       os << "[mbox ";
+       os << '[' << name_ << ' ';
        //text_->write(buffer(), os);
        os << "] ";
 }
 
 
-void MathBoxInset::metrics(MathMetricsInfo const & st) const
+void MathBoxInset::rebreak()
 {
-       mi_ = st;
-       if (text_ && mi_.view) {
-               ascent_  = text_->ascent(mi_.view, mi_.font)  + 2;
-               descent_ = text_->descent(mi_.view, mi_.font) + 2;
-               width_   = text_->width(mi_.view, mi_.font)   + 4;
-       } else {
-               ascent_  = 10;
-               descent_ = 0;
-               width_   = 10;
-       }
+       //lyxerr << "trying to rebreak...\n";
 }
 
 
 void MathBoxInset::draw(Painter & pain, int x, int y) const
 {
-       float fx = x + 2;
-       if (text_ && mi_.view)
-               text_->draw(mi_.view, mi_.font, y, fx, false);
-       if (mathcursor && mathcursor->isInside(this))
-               pain.rectangle(x, y - ascent(), xcell(0).width(), height(),
+       MathGridInset::draw(pain, x, y);
+       if (mathcursor && mathcursor->isInside(this)) {
+               pain.rectangle(x - 1, y - ascent() - 1, width(), height(),
                        LColor::mathframe);
-}
-
-
-void MathBoxInset::edit(BufferView * bv, int x, int y, unsigned int button)
-{
-       if (text_)
-               text_->edit(bv, x, y, button);
+       }
 }
index f67fa168f687520b938596d2b4734a4986a7a0a3..c2f4364daaf4b5ea371f9ffed1b26dde16796e61 100644 (file)
@@ -2,59 +2,40 @@
 #ifndef MATH_BOXINSET_H
 #define MATH_BOXINSET_H
 
-#include "math_diminset.h"
+#include "math_gridinset.h"
 #include "LString.h"
 
 #ifdef __GNUG__
 #pragma interface
 #endif
 
-class InsetText;
-class UpdatableInset;
-class BufferView;
-class Buffer;
 class LyXFont;
 
 /// Support for \\mbox
 
-class MathBoxInset : public MathDimInset {
+class MathBoxInset : public MathGridInset {
 public:
        ///
        explicit MathBoxInset(string const &);
        ///
-       MathBoxInset(MathBoxInset const &);
-       ///
-       ~MathBoxInset();
-       ///
        MathInset * clone() const;
+       /// identifies BoxInsets
+       MathBoxInset * asBoxInset() { return this; }
+       /// identifies BoxInsets
+       MathBoxInset const * asBoxInset() const { return this; }
        ///
-       void draw(Painter &, int x, int y) const;
+       void rebreak();
        ///
        void write(WriteStream & os) const;
        ///
        void normalize(NormalStream &) const;
        ///
-       void metrics(MathMetricsInfo const &) const;
-       /// identifies BoxInsets
-       MathBoxInset * asBoxInset() { return this; }
-       ///
-       bool isHyperActive() const { return 1; }
-       ///
-       void edit(BufferView * bv, int x, int y, unsigned int button);
-       /// identifies hyperactive insets
-       UpdatableInset * asHyperActiveInset() const;
+       void draw(Painter &, int x, int y) const;
 
 private:
-       /// unimplemented
-       void operator=(MathBoxInset const &);
-
        ///
        mutable MathMetricsInfo mi_;
        ///
        string name_;
-       ///
-       InsetText * text_;
-       ///
-       mutable Buffer * buffer_;       
 };
 #endif
index 12126ff24529212e1a31eb67a0809cfa16714cdf..2c9cf7fa59f14fd69dd1317f3512dc3ad05c3d6d 100644 (file)
 #pragma implementation
 #endif
 
+#include "support/lstrings.h"
+#include "support/LAssert.h"
+#include "debug.h"
+#include "LColor.h"
+#include "Painter.h"
 #include "math_cursor.h"
 #include "formulabase.h"
 #include "math_arrayinset.h"
 #include "math_braceinset.h"
+#include "math_boxinset.h"
 #include "math_casesinset.h"
 #include "math_charinset.h"
 #include "math_deliminset.h"
 #include "math_specialcharinset.h"
 #include "math_support.h"
 
-#include "debug.h"
-#include "LColor.h"
-#include "Painter.h"
-
-#include "support/lstrings.h"
-#include "support/LAssert.h"
-
 #include <algorithm>
 #include <cctype>
 
@@ -891,30 +890,34 @@ void MathCursor::pullArg(bool goright)
 }
 
 
-void MathCursor::normalize() const
+void MathCursor::normalize()
 {
-#ifdef WITH_WARNINGS
-#warning This is evil!
-#endif
-       MathCursor * it = const_cast<MathCursor *>(this);
+       // rebreak
+       {
+               MathIterator it = ibegin(formula()->par().nucleus());
+               MathIterator et = iend(formula()->par().nucleus());
+               for ( ; it != et; ++it) 
+                       if (it.par()->asBoxInset())
+                               it.par()->asBoxInset()->rebreak();
+       }
 
        if (idx() >= par()->nargs()) {
                lyxerr << "this should not really happen - 1: "
                       << idx() << " " << par()->nargs() << "\n";
                dump("error 2");
        }
-       it->idx() = min(idx(), par()->nargs() - 1);
+       idx() = min(idx(), par()->nargs() - 1);
 
        if (pos() > size()) {
                lyxerr << "this should not really happen - 2: "
-                       << pos() << " " << size() <<  " in idx: " << it->idx()
+                       << pos() << " " << size() <<  " in idx: " << idx()
                        << " in atom: '";
                WriteStream wi(lyxerr, false);
-               it->par()->write(wi);
+               par()->write(wi);
                lyxerr << "\n";
                dump("error 4");
        }
-       it->pos() = min(pos(), size());
+       pos() = min(pos(), size());
 }
 
 
@@ -1339,7 +1342,7 @@ bool MathCursor::interpret(char c)
                // fall through in the other cases
        }
 
-       if (lastcode_ == LM_TC_TEXTRM) {
+       if (lastcode_ == LM_TC_TEXTRM || par()->asBoxInset()) {
                // suppress direct insertion of two spaces in a row
                // the still allows typing  '<space>a<space>' and deleting the 'a', but
                // it is better than nothing...
@@ -1354,7 +1357,7 @@ bool MathCursor::interpret(char c)
                        prevAtom()->asSpaceInset()->incSpace();
                        return true;
                }
-               if (mathcursor->popRight())
+               if (popRight())
                        return true;
                // if are at the very end, leave the formula
                return pos() != size();
index b15fef5dc7812bb82f264b7eb0683d199d2e881d..91a52bb00959eb2c1bc93a180c409a9c6bc24599 100644 (file)
@@ -182,7 +182,7 @@ public:
        row_type gridRow() const;
 
        /// make sure cursor position is valid
-       void normalize() const;
+       void normalize();
        ///
        UpdatableInset * asHyperActiveInset() const;
 
index adba3adb4ef08c14d92583d05086eeb1cb0e151c..d84036f31a981c57cd4cd84877c415cb589bdb36 100644 (file)
 #endif
 
 
-/** The restrictions of a standard LaTeX math paragraph
-  allows to get a small number of text codes (<30) */
+///
 enum MathTextCodes  {
-       /// This must be >= 0
+       /// 
        LM_TC_MIN = 0,
-       /// Math Inset
-       LM_TC_INSET,
-
-       ///
-       LM_FONT_BEGIN,
-       /// Internal code for variables
+       /// internal code for variables
        LM_TC_VAR,
+       /// internal code for stuff in wrapped in mbox etc
+       LM_TC_BOX,
        ///
        LM_TC_CONST,
        ///
@@ -57,13 +53,13 @@ enum MathTextCodes  {
        LM_TC_IT,
        ///
        LM_TC_TEXTRM,
-       /// Math mode TeX characters ",;:{}"  
+       /// math mode TeX characters ",;:{}"  
        LM_TC_TEX,
-       /// Internal code when typing greek
+       /// internal code when typing greek
        LM_TC_GREEK,
-       /// Internal code when typing a single greek character
+       /// internal code when typing a single greek character
        LM_TC_GREEK1,
-       /// Internal code for symbols
+       /// internal code for symbols
        LM_TC_SYMB,
        /// internal code for symbols that get bigger in displayed math
        LM_TC_BOLDSYMB,
@@ -81,9 +77,6 @@ enum MathTextCodes  {
        LM_TC_MSB,
        ///
        LM_FONT_END,
-       
-       /// This must be < 32 
-       LM_TC_MAX
 };
 
 
index 6d0fb8ccec76a908c2f1d0c90b87ebf282f32de1..1f22147ab4633847dbf692f99865ff872867c139 100644 (file)
@@ -90,6 +90,7 @@ key_type wordlist_array[] =
        {"limsup",  LM_TK_FUNCLIM, 0},
        {"ln",  LM_TK_FUNC, 0},
        {"log",  LM_TK_FUNC, 0},
+       {"lyxbox",  LM_TK_BOX, 0},
        {"mathbb",  LM_TK_FONT, LM_TC_BB},
        {"mathbf",  LM_TK_FONT, LM_TC_BF},
        {"mathcal",  LM_TK_FONT, LM_TC_CAL},
index bf2f2ec3141c40db12300168a69a4a911f17eeda..5b8d6de1da09769f6b1a0172d68af1f0c5809f43 100644 (file)
@@ -177,6 +177,7 @@ public:
        /// identifies certain types of insets
        virtual MathArrayInset        * asArrayInset()        { return 0; }
        virtual MathBoxInset          * asBoxInset()          { return 0; }
+       virtual MathBoxInset const    * asBoxInset() const    { return 0; }
        virtual MathCharInset const   * asCharInset() const   { return 0; }
        virtual MathDelimInset        * asDelimInset()        { return 0; }
        virtual MathDelimInset const  * asDelimInset() const  { return 0; }
index eff6c33f5715ce83b14137a70a7697e4c4ba6d06..7538fce72c38fbf3d9d7edfad4b9bada56b79d24 100644 (file)
@@ -137,6 +137,7 @@ enum {
        FLAG_RIGHT      = 1 << 2,  //  next \\right ends the parsing process
        FLAG_END        = 1 << 3,  //  next \\end ends the parsing process
        FLAG_BRACK_END  = 1 << 4,  //  next closing bracket ends the parsing process
+       FLAG_BOX        = 1 << 5,  //  we are in a box
        FLAG_ITEM       = 1 << 7,  //  read a (possibly braced token)
        FLAG_BLOCK      = 1 << 8,  //  next block ends the parsing process
        FLAG_LEAVE      = 1 << 9   //  leave the loop at the end
@@ -148,13 +149,6 @@ void catInit()
        fill(theCatcode, theCatcode + 256, catOther);
        fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
        fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);
-       
-//     for (int i = 0; i <= 255; ++i) 
-//             theCatcode[i] = catOther;
-//     for (int i = 'a'; i <= 'z'; ++i) 
-//             theCatcode[i] = catLetter;
-//     for (int i = 'A'; i <= 'Z'; ++i) 
-//             theCatcode[i] = catLetter;
 
        theCatcode['\\'] = catEscape;   
        theCatcode['{']  = catBegin;    
@@ -767,8 +761,16 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
                //
                // cat codes
                //
-               if (t.cat() == catMath)
-                       break;
+               if (t.cat() == catMath) {
+                       if (flags & FLAG_BOX) {
+                               // we are inside an mbox, so opening new math is allowed
+                               array.push_back(MathAtom(new MathHullInset(LM_OT_SIMPLE)));
+                               parse_into(array.back()->cell(0), 0);
+                       } else {
+                               // otherwise this is the end of the formula
+                               break;
+                       }
+               }
 
                else if (t.cat() == catLetter)
                        add(array, t.character(), code);
@@ -992,6 +994,12 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
                                        code = static_cast<MathTextCodes>(l->id);
                                }
 
+                               else if (l->token == LM_TK_BOX) {
+                                       MathAtom p = createMathInset(t.cs());
+                                       parse_into(p->cell(0), FLAG_ITEM | FLAG_BOX, LM_TC_BOX);
+                                       array.push_back(p);
+                               }
+
                                else {
                                        MathAtom p = createMathInset(t.cs());
                                        for (MathInset::idx_type i = 0; i < p->nargs(); ++i) 
index 29c1d6b4ffc8b8e9dad161309fa85ef872dc54f8..f3d5a0b3d5c9725bc827ad4df219070f89446a2f 100644 (file)
@@ -153,6 +153,7 @@ LyXFont const & whichFontBaseIntern(MathTextCodes type)
        case LM_TC_TT:
                return MathFonts[FONT_TT];
 
+       case LM_TC_BOX:
        case LM_TC_TEXTRM:
        case LM_TC_CONST:
        case LM_TC_TEX:
@@ -253,7 +254,7 @@ LyXFont whichFont(MathTextCodes type, MathMetricsInfo const & size)
                break;
        }
 
-       if (type != LM_TC_TEXTRM)
+       if (type != LM_TC_TEXTRM && type != LM_TC_BOX)
                f.setColor(LColor::math);
 
        if (type == LM_TC_TEX)