This moves the format used by mathed's internal cut buffer from something called 'MathGridInset' to 'string'.
The change is completely transparent to the outside world but moves math and non-math a bit closer together. Actually I think we could get rid of the (math-) internal cut buffer some day. At least stuffing the X selection correctly when mathed has the selection should be possible... Ok? Andre' -- Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. (T. Jefferson)
Index: formulabase.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulabase.C,v retrieving revision 1.217 diff -u -p -r1.217 formulabase.C --- formulabase.C 22 Oct 2002 11:13:40 -0000 1.217 +++ formulabase.C 22 Oct 2002 12:55:13 -0000 @@ -721,7 +721,7 @@ Inset::RESULT InsetFormulaBase::localDis // math-insert only handles special math things like "matrix". case LFUN_INSERT_MATH: bv->lockedInsetStoreUndo(Undo::EDIT); - mathcursor->insert(asArray(argument)); + mathcursor->niceInsert(argument); updateLocal(bv, true); break; Index: math_cursor.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.C,v retrieving revision 1.322 diff -u -p -r1.322 math_cursor.C --- math_cursor.C 22 Oct 2002 11:13:40 -0000 1.322 +++ math_cursor.C 22 Oct 2002 12:55:13 -0000 @@ -64,7 +60,7 @@ using std::isalpha; // matheds own cut buffer -MathGridInset theCutBuffer = MathGridInset(1, 1); +string theCutBuffer; MathCursor::MathCursor(InsetFormulaBase * formula, bool front) @@ -376,10 +372,20 @@ void MathCursor::insert(MathAtom const & } +void MathCursor::niceInsert(string const & t) +{ + MathArray ar = asArray(t); + if (ar.size() == 1) + niceInsert(ar[0]); + else + insert(ar); +} + + void MathCursor::niceInsert(MathAtom const & t) { macroModeClose(); - MathGridInset safe = grabAndEraseSelection(); + string safe = grabAndEraseSelection(); plainInsert(t); // enter the new inset and move the contents of the selection if possible if (t->isActive()) { @@ -400,12 +406,9 @@ void MathCursor::insert(MathArray const } -void MathCursor::paste(MathGridInset const & data) +void MathCursor::paste(string const & data) { - ostringstream os; - WriteStream wi(os, false, false); - data.write(wi); - dispatch(FuncRequest(LFUN_PASTE, os.str())); + dispatch(FuncRequest(LFUN_PASTE, data)); } @@ -534,7 +537,7 @@ void MathCursor::selCopy() theCutBuffer = grabSelection(); selection_ = false; } else { - theCutBuffer = MathGridInset(1, 1); + theCutBuffer.erase(); } } @@ -595,14 +598,6 @@ void MathCursor::selClearOrDel() } -void MathCursor::selGet(MathArray & ar) -{ - dump("selGet"); - if (selection_) - ar = grabSelection().glue(); -} - - void MathCursor::drawSelection(MathPainterInfo & pi) const { if (!selection_) @@ -617,7 +612,7 @@ void MathCursor::drawSelection(MathPaint void MathCursor::handleNest(MathAtom const & a) { MathAtom at = a; - at.nucleus()->cell(0) = grabAndEraseSelection().glue(); + at.nucleus()->cell(0) = asArray(grabAndEraseSelection()); insert(at); pushRight(prevAtom()); } @@ -1096,7 +1091,7 @@ bool MathCursor::script(bool up) } macroModeClose(); - MathGridInset safe = grabAndEraseSelection(); + string safe = grabAndEraseSelection(); if (inNucleus()) { // we are in a nucleus of a script inset, move to _our_ script par()->asScriptInset()->ensure(up); @@ -1347,29 +1323,29 @@ void region(MathCursorPos const & i1, Ma } -MathGridInset MathCursor::grabSelection() const +string MathCursor::grabSelection() const { if (!selection_) - return MathGridInset(); + return string(); + MathCursorPos i1; MathCursorPos i2; getSelection(i1, i2); - // shouldn't we assert on i1.par_ == i2.par_? - if (i1.idx_ == i2.idx_) { - MathGridInset data(1, 1); - MathArray::const_iterator it = i1.cell().begin(); - data.cell(0) = MathArray(it + i1.pos_, it + i2.pos_); - return data; - } + row_type r1, r2; col_type c1, c2; region(i1, i2, r1, r2, c1, c2); - MathGridInset data(c2 - c1 + 1, r2 - r1 + 1); - for (row_type row = 0; row < data.nrows(); ++row) - for (col_type col = 0; col < data.ncols(); ++col) { - idx_type i = i1.par_->index(row + r1, col + c1); - data.cell(data.index(row, col)) = i1.par_->cell(i); + + string data; + for (row_type row = r1; row <= r2; ++row) { + if (row > r1) + data += "\\n"; + for (col_type col = c1; col <= c2; ++col) { + if (col > c1) + data += "&"; + data += asString(i1.par_->cell(i1.par_->index(row, col))); } + } return data; } @@ -1394,11 +1370,11 @@ void MathCursor::eraseSelection() } -MathGridInset MathCursor::grabAndEraseSelection() +string MathCursor::grabAndEraseSelection() { if (!selection_) - return MathGridInset(); - MathGridInset res = grabSelection(); + return string(); + string res = grabSelection(); eraseSelection(); selection_ = false; return res; Index: math_cursor.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.h,v retrieving revision 1.133 diff -u -p -r1.133 math_cursor.h --- math_cursor.h 22 Oct 2002 11:13:40 -0000 1.133 +++ math_cursor.h 22 Oct 2002 12:55:13 -0000 @@ -65,7 +65,7 @@ public: /// void insert(MathArray const &); /// - void paste(MathGridInset const & data); + void paste(string const & data); /// void erase(); /// @@ -96,6 +96,8 @@ public: void plainInsert(MathAtom const &); /// void niceInsert(MathAtom const &); + /// + void niceInsert(string const &); /// in pixels from top of screen void setPos(int x, int y); @@ -157,10 +159,8 @@ public: void selClear(); /// clears or deletes selection depending on lyxrc setting void selClearOrDel(); - /// - void selGet(MathArray & ar); - /// - void drawSelection(MathPainterInfo & pain) const; + /// draws light-blue selection background + void drawSelection(MathPainterInfo & pi) const; /// void handleNest(MathAtom const & at); /// remove this as soon as LyXFunc::getStatus is "localized" @@ -265,12 +265,12 @@ private: /// are we in a nucleus of a script inset? bool inNucleus() const; - /// grab grid marked by anchor and current cursor - MathGridInset grabSelection() const; + /// grab selection marked by anchor and current cursor + string grabSelection() const; /// erase the selected part and re-sets the cursor void eraseSelection(); /// guess what - MathGridInset grabAndEraseSelection(); + string grabAndEraseSelection(); /// the name of the macro we are currently inputting string macroName() const;