From 13794d5ec36619c68996353e2d58091d8aaa2afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Tue, 6 Mar 2001 17:13:12 +0000 Subject: [PATCH] mathed44.diff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1693 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 7 ++++-- src/mathed/math_matrixinset.C | 32 ++++++++++++------------- src/mathed/math_matrixinset.h | 4 ++-- src/mathed/math_parinset.h | 2 +- src/mathed/math_rowst.h | 45 ++++++++++++++++++++++++++++++++++- 5 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 7d87037d9e..ef6f886649 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -2,11 +2,14 @@ * array.[Ch]: factor out deep_copy, remove third argument from raw_pointer_insert - * mathiter.[Ch]: remove unused function Clear() + * math_iter.[Ch]: remove unused function Clear() - * mathcursor.C: change signature of MathStackXIter:push() + * math_cursor.C: change signature of MathStackXIter:push() whitespace changes + * math_rowst.h: introduction of MathRowContainer + several files: corresponding changes + 2001-03-04 André Pönitz * math_macrotemplate.[Ch]: math_macro.C: move update() functionality to the macro diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index 8e6fbdc4b5..21ad67b89c 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -40,9 +40,9 @@ MathMatrixInset::MathMatrixInset(MathMatrixInset const & mt) v_align_(mt.v_align_), h_align_(mt.h_align_) { array = mt.GetData(); - if (mt.row_ != 0) { + if (mt.row_.data_ != 0) { MathedRowSt * ro = 0; - MathedRowSt * mrow = mt.row_; + MathedRowSt * mrow = mt.row_.data_; while (mrow) { MathedRowSt * r = new MathedRowSt(nc_ + 1); @@ -65,7 +65,7 @@ MathMatrixInset::MathMatrixInset(MathMatrixInset const & mt) MathMatrixInset::~MathMatrixInset() { - MathedRowSt * r = row_; + MathedRowSt * r = row_.data_; while (r) { MathedRowSt * q = r->getNext(); delete r; @@ -132,14 +132,14 @@ void MathMatrixInset::draw(Painter & pain, int x, int baseline) void MathMatrixInset::Metrics() { - if (!row_) { + if (!row_.data_) { // lyxerr << " MIDA "; MathedXIter it(this); row_ = it.adjustVerticalSt(); } // Clean the arrays - MathedRowSt * cxrow = row_; + MathedRowSt * cxrow = row_.data_; while (cxrow) { for (int i = 0; i <= nc_; ++i) cxrow->setTab(i, 0); @@ -149,24 +149,24 @@ void MathMatrixInset::Metrics() // Basic metrics MathParInset::Metrics(); - if (nc_ <= 1 && !row_->getNext()) { - row_->ascent(ascent); - row_->descent(descent); + if (nc_ <= 1 && !row_.data_->getNext()) { + row_.data_->ascent(ascent); + row_.data_->descent(descent); } // Vertical positions of each row - cxrow = row_; + cxrow = row_.data_; MathedRowSt * cprow = 0; int h = 0; while (cxrow) { for (int i = 0; i < nc_; ++i) { - if (cxrow == row_ || ws_[i] < cxrow->getTab(i)) + if (cxrow == row_.data_ || ws_[i] < cxrow->getTab(i)) ws_[i] = cxrow->getTab(i); if (cxrow->getNext() == 0 && ws_[i] == 0) ws_[i] = df_width; } - cxrow->setBaseline((cxrow == row_) ? + cxrow->setBaseline((cxrow == row_.data_) ? cxrow->ascent() : cxrow->ascent() + cprow->descent() + MATH_ROWSEP + cprow->getBaseline()); @@ -181,13 +181,13 @@ void MathMatrixInset::Metrics() // Compute vertical align switch (v_align_) { case 't': - ascent = row_->getBaseline(); + ascent = row_.data_->getBaseline(); break; case 'b': ascent = h - hl; break; default: - ascent = (row_->getNext()) ? h / 2 : h - hl; + ascent = (row_.data_->getNext()) ? h / 2 : h - hl; break; } descent = h - ascent + 2; @@ -202,7 +202,7 @@ void MathMatrixInset::Metrics() ws_[0] = 7 * workWidth / 8; // Adjust local tabs - cxrow = row_; + cxrow = row_.data_; width = MATH_COLSEP; while (cxrow) { int rg = MATH_COLSEP; @@ -225,7 +225,7 @@ void MathMatrixInset::Metrics() lf = ws_[i] - cxrow->getTab(i); break; case 'C': - if (cxrow == row_) + if (cxrow == row_.data_) lf = 0; else if (!cxrow->getNext()) lf = ws_[i] - cxrow->getTab(i); @@ -236,7 +236,7 @@ void MathMatrixInset::Metrics() int const ww = (isvoid) ? lf : lf + cxrow->getTab(i); cxrow->setTab(i, lf + rg); rg = ws_[i] - ww + MATH_COLSEP; - if (cxrow == row_) + if (cxrow == row_.data_) width += ws_[i] + MATH_COLSEP; } cxrow->setBaseline(cxrow->getBaseline() - ascent); diff --git a/src/mathed/math_matrixinset.h b/src/mathed/math_matrixinset.h index caf23ea3c1..c8c7cc45b7 100644 --- a/src/mathed/math_matrixinset.h +++ b/src/mathed/math_matrixinset.h @@ -61,7 +61,7 @@ private: //std::vector h_align; string h_align_; // a vector would perhaps be more correct /// Vertical structure - MathedRowSt * row_; + MathedRowContainer row_; }; @@ -89,7 +89,7 @@ bool MathMatrixInset::isMatrix() const inline MathedRowSt * MathMatrixInset::getRowSt() const { - return row_; + return row_.data_; } diff --git a/src/mathed/math_parinset.h b/src/mathed/math_parinset.h index c8797ebd47..c5af2cfb5c 100644 --- a/src/mathed/math_parinset.h +++ b/src/mathed/math_parinset.h @@ -5,12 +5,12 @@ #include "array.h" #include "math_inset.h" #include "math_defs.h" +#include "math_rowst.h" #ifdef __GNUG__ #pragma interface #endif -class MathedRowSt; class MathedArray; diff --git a/src/mathed/math_rowst.h b/src/mathed/math_rowst.h index dba14517a7..5c9c59383b 100644 --- a/src/mathed/math_rowst.h +++ b/src/mathed/math_rowst.h @@ -72,12 +72,55 @@ public: MathedRowSt * getNext() const; /// ...we couldn't use this. void setNext(MathedRowSt * n); -private: +//private: /// MathedRowSt * next_; }; +// The idea is to change this MathedRowContainer to mimic the behaviour +// of std::list in several small steps. In the end it +// could be replaced by such a list and MathedRowSt can go as well. + +struct MathedRowContainer { + /// + struct iterator { + /// + iterator(MathedRowContainer * m) : st_(m->data_) {} + /// "better" conversion to bool + operator void *() const { return st_; } + /// + MathedRowStruct & operator*() { return *st_; } + /// + MathedRowStruct * operator->() { return st_; } + /// + void operator++() { st_ = st_->next_; } + /// + bool is_last() const { return st_->next_ == 0; } + /// + bool operator==(const iterator & it) const { return st_ == it.st_; } + + private: + /// + MathedRowSt * st_; + }; + + /// + MathedRowContainer() : data_(0) {} + /// + MathedRowContainer(MathedRowSt * data) : data_(data) {} + + /// + iterator begin() { return iterator(this); } + /// + bool empty() const { return data_ == 0; } + + /// + MathedRowSt * data_; +}; + + + inline MathedRowSt * MathedRowSt::getNext() const {