]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
Make buffer's member variables private; use accessor functions.
[lyx.git] / src / insets / insettabular.C
index f5ca11fc7e20aa7729b3407f9cc7d76a15621b11..bbc4f28e2b3f849429b02fb1bc33ca30e900df3d 100644 (file)
@@ -5,59 +5,49 @@
  *
  * \author Jürgen Vigna
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
 #include "insettabular.h"
-#include "insettext.h"
 
 #include "buffer.h"
 #include "BufferView.h"
-#include "lfuns.h"
 #include "debug.h"
-#include "dimension.h"
 #include "funcrequest.h"
+#include "FuncStatus.h"
 #include "gettext.h"
 #include "language.h"
-#include "LaTeXFeatures.h"
-#include "Lsstream.h"
 #include "lyx_cb.h"
-#include "lyxfunc.h"
-#include "lyxlength.h"
 #include "lyxlex.h"
-#include "lyxtext.h"
+#include "metricsinfo.h"
+#include "paragraph.h"
+#include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
 #include "undo_funcs.h"
 #include "WordLangTuple.h"
-#include "metricsinfo.h"
 
 #include "frontends/Alert.h"
-#include "frontends/Dialogs.h"
 #include "frontends/font_metrics.h"
 #include "frontends/LyXView.h"
 #include "frontends/Painter.h"
 
 #include "support/LAssert.h"
-#include "support/lstrings.h"
-
-#include <fstream>
-#include <algorithm>
-#include <cstdlib>
 
+#include "support/std_sstream.h"
 
 using namespace lyx::support;
 using namespace lyx::graphics;
 
-using std::vector;
-using std::ostream;
-using std::ifstream;
-using std::max;
 using std::endl;
-using std::swap;
 using std::max;
+using std::swap;
+
 using std::auto_ptr;
+using std::istringstream;
+using std::ostream;
+using std::ostringstream;
 
 
 namespace {
@@ -154,7 +144,7 @@ bool InsetTabular::hasPasteBuffer() const
 
 
 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
-       : tabular(buf.params, this, max(rows, 1), max(columns, 1)),
+       : tabular(buf.params(), this, max(rows, 1), max(columns, 1)),
          buffer_(&buf), cursorx_(0), cursory_(0)
 {
        // for now make it always display as display() inset
@@ -173,7 +163,7 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
 
 InsetTabular::InsetTabular(InsetTabular const & tab)
        : UpdatableInset(tab),
-               tabular(tab.buffer_->params, this, tab.tabular),
+               tabular(tab.buffer_->params(), this, tab.tabular),
                buffer_(tab.buffer_), cursorx_(0), cursory_(0)
 {
        the_locking_inset = 0;
@@ -200,9 +190,9 @@ auto_ptr<InsetBase> InsetTabular::clone() const
 }
 
 
-Buffer const * InsetTabular::buffer() const
+Buffer const & InsetTabular::buffer() const
 {
-       return buffer_;
+       return *buffer_;
 }
 
 
@@ -219,14 +209,14 @@ void InsetTabular::buffer(Buffer * b)
 }
 
 
-void InsetTabular::write(Buffer const * buf, ostream & os) const
+void InsetTabular::write(Buffer const & buf, ostream & os) const
 {
        os << "Tabular" << endl;
        tabular.write(buf, os);
 }
 
 
-void InsetTabular::read(Buffer const * buf, LyXLex & lex)
+void InsetTabular::read(Buffer const & buf, LyXLex & lex)
 {
        bool const old_format = (lex.getString() == "\\LyXTable");
 
@@ -421,7 +411,7 @@ void InsetTabular::insetUnlock(BufferView * bv)
 
 void InsetTabular::updateLocal(BufferView * bv) const
 {
-       bv->updateInset();
+       bv->updateInset(this);
        if (locked)
                resetPos(bv);
 }
@@ -855,14 +845,14 @@ InsetOld::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                        updateLocal(bv);
                break;
        case LFUN_NEXT: {
-               if (hs) 
+               if (hs)
                        clearSelection();
                int column = actcol;
                unlockInsetInInset(bv, the_locking_inset);
-               if (bv->text->top_y() + bv->painter().paperHeight() <
+               if (bv->top_y() + bv->painter().paperHeight() <
                    top_baseline + tabular.getHeightOfTabular())
                        {
-                               bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
+                               bv->scrollDocView(bv->top_y() + bv->painter().paperHeight());
                                actcell = tabular.getCellBelow(first_visible_cell) + column;
                        } else {
                                actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
@@ -877,7 +867,7 @@ InsetOld::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                int column = actcol;
                unlockInsetInInset(bv, the_locking_inset);
                if (top_baseline < 0) {
-                       bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
+                       bv->scrollDocView(bv->top_y() - bv->painter().paperHeight());
                        if (top_baseline > 0)
                                actcell = column;
                        else
@@ -945,7 +935,7 @@ InsetOld::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                // no break here!
        case LFUN_DELETE:
                recordUndo(bv, Undo::DELETE);
-               cutSelection(bv->buffer()->params);
+               cutSelection(bv->buffer()->params());
                updateLocal(bv);
                break;
        case LFUN_COPY:
@@ -984,7 +974,7 @@ InsetOld::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                        }
                        maxCols = max(cols, maxCols);
                        delete paste_tabular;
-                       paste_tabular = new LyXTabular(bv->buffer()->params,
+                       paste_tabular = new LyXTabular(bv->buffer()->params(),
                                                       this, rows, maxCols);
                        string::size_type op = 0;
                        int cell = 0;
@@ -1084,29 +1074,29 @@ InsetOld::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
 }
 
 
-int InsetTabular::latex(Buffer const * buf, ostream & os,
+int InsetTabular::latex(Buffer const & buf, ostream & os,
                        LatexRunParams const & runparams) const
 {
        return tabular.latex(buf, os, runparams);
 }
 
 
-int InsetTabular::ascii(Buffer const * buf, ostream & os, int ll) const
+int InsetTabular::ascii(Buffer const & buf, ostream & os, int ll) const
 {
        if (ll > 0)
-               return tabular.ascii(buf, os, (int)parOwner()->params().depth(),
+               return tabular.ascii(buf, os, ownerPar(buf, this).params().depth(),
                                      false, 0);
        return tabular.ascii(buf, os, 0, false, 0);
 }
 
 
-int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const
+int InsetTabular::linuxdoc(Buffer const & buf, ostream & os) const
 {
        return tabular.linuxdoc(buf,os);
 }
 
 
-int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const
+int InsetTabular::docbook(Buffer const & buf, ostream & os, bool mixcont) const
 {
        int ret = 0;
        InsetOld * master;
@@ -1454,7 +1444,7 @@ bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
        }
        if (lock) {
                bool rtl = tabular.getCellInset(actcell).paragraphs.begin()->
-                       isRightToLeftPar(bv->buffer()->params);
+                       isRightToLeftPar(bv->buffer()->params());
                activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
        }
        resetPos(bv);
@@ -1483,7 +1473,7 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
        }
        if (lock) {
                bool rtl = tabular.getCellInset(actcell).paragraphs.begin()->
-                       isRightToLeftPar(bv->buffer()->params);
+                       isRightToLeftPar(bv->buffer()->params());
                activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
        }
        resetPos(bv);
@@ -1685,13 +1675,13 @@ void InsetTabular::tabularFeatures(BufferView * bv,
        case LyXTabular::APPEND_ROW:
                // append the row into the tabular
                unlockInsetInInset(bv, the_locking_inset);
-               tabular.appendRow(bv->buffer()->params, actcell);
+               tabular.appendRow(bv->buffer()->params(), actcell);
                updateLocal(bv);
                break;
        case LyXTabular::APPEND_COLUMN:
                // append the column into the tabular
                unlockInsetInInset(bv, the_locking_inset);
-               tabular.appendColumn(bv->buffer()->params, actcell);
+               tabular.appendColumn(bv->buffer()->params(), actcell);
                actcell = tabular.getCellNumber(row, column);
                updateLocal(bv);
                break;
@@ -1979,7 +1969,7 @@ bool InsetTabular::insetHit(BufferView *, int x, int) const
 }
 
 
-void InsetTabular::deleteLyXText(BufferView * bv, bool recursive) const
+void InsetTabular::deleteLyXText(BufferView * /*bv*/, bool /*recursive*/) const
 {
        //resizeLyXText(bv, recursive);
 }
@@ -2219,7 +2209,7 @@ bool InsetTabular::copySelection(BufferView * bv)
                swap(sel_row_start, sel_row_end);
 
        delete paste_tabular;
-       paste_tabular = new LyXTabular(bv->buffer()->params, this, tabular);
+       paste_tabular = new LyXTabular(bv->buffer()->params(), this, tabular);
 
        for (int i = 0; i < sel_row_start; ++i)
                paste_tabular->deleteRow(0);
@@ -2244,8 +2234,8 @@ bool InsetTabular::copySelection(BufferView * bv)
                                    true, true);
 
        ostringstream os;
-       paste_tabular->ascii(bv->buffer(), os,
-                            (int)parOwner()->params().depth(), true, '\t');
+       paste_tabular->ascii(*bv->buffer(), os,
+                            ownerPar(*bv->buffer(), this).params().depth(), true, '\t');
        bv->stuffClipboard(STRCONV(os.str()));
        return true;
 }
@@ -2585,7 +2575,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
        int row = 0;
        if (usePaste) {
                delete paste_tabular;
-               paste_tabular = new LyXTabular(bv->buffer()->params,
+               paste_tabular = new LyXTabular(bv->buffer()->params(),
                                               this, rows, maxCols);
                loctab = paste_tabular;
                cols = 0;
@@ -2711,9 +2701,8 @@ int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
        if (!lex.isOK())
                return -1;
 
-       Buffer const * const buffer = inset.buffer();
-       if (buffer)
-               inset.read(buffer, lex);
+       Buffer const & buffer = inset.buffer();
+       inset.read(buffer, lex);
 
        // We can't set the active cell, but we can tell the frontend
        // what it is.
@@ -2723,9 +2712,7 @@ int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
 
 string const InsetTabularMailer::params2string(InsetTabular const & inset)
 {
-       Buffer const * const buffer = inset.buffer();
-       if (!buffer)
-               return string();
+       Buffer const & buffer = inset.buffer();
 
        ostringstream data;
        data << name_ << " \\active_cell " << inset.getActCell() << '\n';