]> 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 0a393c0f618428f4503ea6778b05328726856bdc..2d1846ab94ee4f821510b53de6292023dee377cc 100644 (file)
@@ -60,9 +60,7 @@
 #include "insets/insettext.h"
 
 #include "frontends/Alert.h"
-#include "frontends/Application.h"
 #include "frontends/FileDialog.h"
-#include "frontends/FontLoader.h"
 #include "frontends/FontMetrics.h"
 
 #include "graphics/Previews.h"
 #include <vector>
 
 
+using lyx::CoordCache;
 using lyx::docstring;
 using lyx::pos_type;
+using lyx::Point;
 
 using lyx::support::addPath;
 using lyx::support::bformat;
@@ -105,7 +105,6 @@ using std::vector;
 
 namespace Alert = lyx::frontend::Alert;
 
-
 namespace {
 
 unsigned int const saved_positions_num = 20;
@@ -188,7 +187,7 @@ void BufferView::setBuffer(Buffer * b)
                lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
                                    << " No Buffer!" << endl;
                // We are closing the buffer, use the first buffer as current
-               buffer_ = theApp->bufferList().first();
+               buffer_ = theBufferList().first();
        } else {
                // Set current buffer
                buffer_ = b;
@@ -235,7 +234,7 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
                s = filename;
 
        // File already open?
-       if (theApp->bufferList().exists(s)) {
+       if (theBufferList().exists(s)) {
                docstring const file = makeDisplayPath(s, 20);
                docstring text = bformat(_("The document %1$s is already "
                                                     "loaded.\n\nDo you want to revert "
@@ -244,11 +243,11 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
                        text, 0, 1,  _("&Revert"), _("&Switch to document"));
 
                if (ret != 0) {
-                       setBuffer(theApp->bufferList().getBuffer(s));
+                       setBuffer(theBufferList().getBuffer(s));
                        return true;
                }
                // FIXME: should be LFUN_REVERT
-               if (!theApp->bufferList().close(theApp->bufferList().getBuffer(s), false))
+               if (!theBufferList().close(theBufferList().getBuffer(s), false))
                        return false;
                // Fall through to new load. (Asger)
        }
@@ -256,9 +255,9 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
        Buffer * b = 0;
 
        if (found) {
-               b = theApp->bufferList().newBuffer(s);
+               b = theBufferList().newBuffer(s);
                if (!::loadLyXFile(b, s)) {
-                       theApp->bufferList().release(b);
+                       theBufferList().release(b);
                        return false;
                }
        } else {
@@ -312,7 +311,7 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
 void BufferView::reload()
 {
        string const fn = buffer_->fileName();
-       if (theApp->bufferList().close(buffer_, false))
+       if (theBufferList().close(buffer_, false))
                loadLyXFile(fn);
 }
 
@@ -333,11 +332,11 @@ void BufferView::resize()
 bool BufferView::fitCursor()
 {
        if (bv_funcs::status(this, cursor_) == bv_funcs::CUR_INSIDE) {
-               lyx::frontend::FontMetrics const & fm 
-                       = theApp->fontLoader().metrics(cursor_.getFont());
+               lyx::frontend::FontMetrics const & fm =
+                       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;
        }
@@ -493,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());
@@ -503,7 +502,7 @@ void BufferView::setCursorFromScrollbar()
 }
 
 
-Change const BufferView::getCurrentChange()
+Change const BufferView::getCurrentChange() const
 {
        if (!cursor_.selection())
                return Change(Change::UNCHANGED);
@@ -538,10 +537,10 @@ void BufferView::restorePosition(unsigned int i)
 
        if (fname != buffer_->fileName()) {
                Buffer * b = 0;
-               if (theApp->bufferList().exists(fname))
-                       b = theApp->bufferList().getBuffer(fname);
+               if (theBufferList().exists(fname))
+                       b = theBufferList().getBuffer(fname);
                else {
-                       b = theApp->bufferList().newBuffer(fname);
+                       b = theBufferList().newBuffer(fname);
                        // Don't ask, just load it
                        ::loadLyXFile(b, fname);
                }
@@ -609,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;
 }
 
@@ -767,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);
                        }
                }
@@ -1150,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);
@@ -1262,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());
 
@@ -1327,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();
@@ -1369,6 +1375,7 @@ void BufferView::menuInsertLyXFile(string const & filenm)
 
        if (filename.empty()) {
                // Launch a file browser
+               // FIXME UNICODE
                string initpath = lyxrc.document_path;
 
                if (buffer_) {
@@ -1378,22 +1385,22 @@ void BufferView::menuInsertLyXFile(string const & filenm)
                                initpath = trypath;
                }
 
-               FileDialog fileDlg(lyx::to_utf8(_("Select LyX document to insert")),
+               // FIXME UNICODE
+               FileDialog fileDlg(_("Select LyX document to insert"),
                        LFUN_FILE_INSERT,
-                       make_pair(string(lyx::to_utf8(_("Documents|#o#O"))),
-                                 string(lyxrc.document_path)),
-                       make_pair(string(lyx::to_utf8(_("Examples|#E#e"))),
-                                 string(addPath(package().system_support(), "examples"))));
+                       make_pair(_("Documents|#o#O"), lyx::from_utf8(lyxrc.document_path)),
+                       make_pair(_("Examples|#E#e"), lyx::from_utf8(addPath(package().system_support(), "examples"))));
 
                FileDialog::Result result =
-                       fileDlg.open(initpath,
-                                    FileFilterList(lyx::to_utf8(_("LyX Documents (*.lyx)"))),
-                                    string());
+                       fileDlg.open(lyx::from_utf8(initpath),
+                                    FileFilterList(_("LyX Documents (*.lyx)")),
+                                    docstring());
 
                if (result.first == FileDialog::Later)
                        return;
 
-               filename = result.second;
+               // FIXME UNICODE
+               filename = lyx::to_utf8(result.second);
 
                // check selected filename
                if (filename.empty()) {