]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
Hopefully temporary fix for the Tabular crash problem. Of course, this is not the...
[lyx.git] / src / BufferView.C
index af1c147400c508a0fb4fd3ec736641a1fad73abf..2d1846ab94ee4f821510b53de6292023dee377cc 100644 (file)
 #include <vector>
 
 
+using lyx::CoordCache;
 using lyx::docstring;
 using lyx::pos_type;
+using lyx::Point;
 
 using lyx::support::addPath;
 using lyx::support::bformat;
@@ -103,7 +105,6 @@ using std::vector;
 
 namespace Alert = lyx::frontend::Alert;
 
-
 namespace {
 
 unsigned int const saved_positions_num = 20;
@@ -335,7 +336,7 @@ bool BufferView::fitCursor()
                        theFontMetrics(cursor_.getFont());
                int const asc = fm.maxAscent();
                int const des = fm.maxDescent();
-               Point const p = bv_funcs::getPos(cursor_, cursor_.boundary());
+               Point const p = bv_funcs::getPos(*this, cursor_, cursor_.boundary());
                if (p.y_ - asc >= 0 && p.y_ + des < height_)
                        return false;
        }
@@ -491,7 +492,7 @@ void BufferView::setCursorFromScrollbar()
                cur.clearSelection();
                break;
        case bv_funcs::CUR_INSIDE:
-               int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
+               int const y = bv_funcs::getPos(*this, cur, cur.boundary()).y_;
                int const newy = min(last, max(y, first));
                if (y != newy) {
                        cur.reset(buffer_->inset());
@@ -501,7 +502,7 @@ void BufferView::setCursorFromScrollbar()
 }
 
 
-Change const BufferView::getCurrentChange()
+Change const BufferView::getCurrentChange() const
 {
        if (!cursor_.selection())
                return Change(Change::UNCHANGED);
@@ -607,7 +608,7 @@ void BufferView::center()
        bot.text()->redoParagraph(pit);
        Paragraph const & par = bot.text()->paragraphs()[pit];
        anchor_ref_ = pit;
-       offset_ref_ = bv_funcs::coordOffset(cursor_, cursor_.boundary()).y_
+       offset_ref_ = bv_funcs::coordOffset(*this, cursor_, cursor_.boundary()).y_
                + par.ascent() - height_ / 2;
 }
 
@@ -765,13 +766,13 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_LABEL_GOTO: {
-               string label = lyx::to_utf8(cmd.argument());
+               docstring label = cmd.argument();
                if (label.empty()) {
                        InsetRef * inset =
                                getInsetByCode<InsetRef>(cursor_,
                                                         InsetBase::REF_CODE);
                        if (inset) {
-                               label = inset->getContents();
+                               label = lyx::from_utf8(inset->getContents());
                                savePosition(0);
                        }
                }
@@ -1148,10 +1149,10 @@ void BufferView::setCursorFromRow(int row)
 }
 
 
-void BufferView::gotoLabel(string const & label)
+void BufferView::gotoLabel(docstring const & label)
 {
        for (InsetIterator it = inset_iterator_begin(buffer_->inset()); it; ++it) {
-               vector<string> labels;
+               vector<docstring> labels;
                it->getLabelList(*buffer_, labels);
                if (find(labels.begin(),labels.end(),label) != labels.end()) {
                        setCursor(it);
@@ -1260,8 +1261,15 @@ ViewMetricsInfo const & BufferView::viewMetricsInfo()
 
 void BufferView::updateMetrics(bool singlepar)
 {
+       // FIXME (Abdel 19/10/2006):
+       // There's something fishy in tabular. The coord_cache_ is not
+       // correctly reconstructed when a character is trying to be inserted.
+       // Not clearing out the coord_cache_ fixes the crash but I don't know
+       // what side effect this could have on other insets.
+       //
        // Remove old position cache
-       theCoords.clear();
+       // coord_cache_.clear();
+
        LyXText & buftext = buffer_->text();
        lyx::pit_type size = int(buftext.paragraphs().size());
 
@@ -1325,7 +1333,7 @@ void BufferView::updateMetrics(bool singlepar)
 
        // The coordinates of all these paragraphs are correct, cache them
        int y = y1;
-       CoordCache::InnerParPosCache & parPos = theCoords.parPos()[&buftext];
+       CoordCache::InnerParPosCache & parPos = coord_cache_.parPos()[&buftext];
        for (lyx::pit_type pit = pit1; pit <= pit2; ++pit) {
                Paragraph const & par = buftext.getPar(pit);
                y += par.ascent();