]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
Change Assert to BOOST_ASSERT.
[lyx.git] / src / text3.C
index 29c8d568133ce15f93f89ed0aa858af383860f8a..b3797f0333cc5c6fbcd8869bcc24212eb92fe945 100644 (file)
@@ -1,47 +1,51 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file text3.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Asger Alstrup
+ * \author Lars Gullik Bjønnes
+ * \author Alfredo Braunstein
+ * \author Angus Leeming
+ * \author John Levon
+ * \author André Pönitz
  *
- *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2002 The LyX Team.
- *
- * ====================================================== */
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
 #include "lyxtext.h"
-#include "paragraph.h"
+
+#include "buffer.h"
+#include "bufferparams.h"
 #include "BufferView.h"
-#include "funcrequest.h"
-#include "lyxrc.h"
-#include "Lsstream.h"
 #include "debug.h"
-#include "bufferparams.h"
-#include "buffer.h"
-#include "bufferview_funcs.h"
-#include "ParagraphParameters.h"
-#include "gettext.h"
 #include "factory.h"
+#include "funcrequest.h"
+#include "gettext.h"
 #include "intl.h"
-#include "box.h"
 #include "language.h"
-#include "support/tostr.h"
-#include "support/lstrings.h"
-#include "support/LAssert.h"
-#include "frontends/LyXView.h"
-#include "frontends/screen.h"
+#include "lyxrc.h"
+#include "lyxrow.h"
+#include "paragraph.h"
+#include "ParagraphParameters.h"
+#include "text_funcs.h"
+#include "undo_funcs.h"
+#include "vspace.h"
+
 #include "frontends/Dialogs.h"
-#include "insets/insetspecialchar.h"
-#include "insets/insettext.h"
-#include "insets/insetquotes.h"
+#include "frontends/LyXView.h"
+
 #include "insets/insetcommand.h"
 #include "insets/insetnewline.h"
-#include "undo_funcs.h"
-#include "text_funcs.h"
-#include "Lsstream.h"
+#include "insets/insetspecialchar.h"
+#include "insets/insettext.h"
 
-#include <ctime>
+#include "support/lstrings.h"
+#include "support/tostr.h"
+
+#include "support/std_sstream.h"
 #include <clocale>
 
 using namespace lyx::support;
@@ -49,9 +53,13 @@ using namespace bv_funcs;
 
 using std::endl;
 using std::find;
+
+using std::istringstream;
 using std::vector;
+
 using lyx::pos_type;
 
+
 extern string current_layout;
 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
 
@@ -105,22 +113,22 @@ namespace {
                        return 0;
 
                // get inset dimensions
-               Assert(par->getInset(pos));
+               BOOST_ASSERT(par->getInset(pos));
 
                LyXFont const & font = text.getFont(par, pos);
 
                int const width = inset->width();
                int const inset_x = font.isVisibleRightToLeft()
-                       ? (cur.ix() - width) : cur.ix();
+                       ? (cur.x() - width) : cur.x();
 
                Box b(
                        inset_x + inset->scroll(),
                        inset_x + width,
-                       cur.iy() - inset->ascent(),
-                       cur.iy() + inset->descent()
+                       cur.y() - inset->ascent(),
+                       cur.y() + inset->descent()
                );
 
-               if (!b.contained(x, y)) {
+               if (!b.contains(x, y)) {
                        lyxerr[Debug::GUI] << "Missed inset at x,y "
                                           << x << ',' << y
                                           << " box " << b << endl;
@@ -131,7 +139,7 @@ namespace {
 
                x -= b.x1;
                // The origin of an inset is on the baseline
-               y -= text.cursor.iy();
+               y -= text.cursor.y();
 
                return inset;
        }
@@ -141,7 +149,7 @@ namespace {
 
 InsetOld * LyXText::checkInsetHit(int & x, int & y)
 {
-       int y_tmp = y + top_y();
+       int y_tmp = y + bv_owner->top_y();
 
        LyXCursor cur;
        setCursorFromCoordinates(cur, x, y_tmp);
@@ -238,7 +246,7 @@ void LyXText::gotoInset(InsetOld::Code code, bool same_content)
 
 void LyXText::cursorPrevious()
 {
-       int y = top_y();
+       int y = bv_owner->top_y();
 
        RowList::iterator rit = cursorRow();
 
@@ -261,7 +269,7 @@ void LyXText::cursorPrevious()
                // tall rows, but it's not working right now.
        } else {
                if (inset_owner) {
-                       new_y = bv()->text->cursor.iy()
+                       new_y = bv()->text->cursor.y()
                                + bv()->theLockingInset()->insetInInsetY() + y
                                + rit->height()
                                - bv()->workHeight() + 1;
@@ -277,7 +285,7 @@ void LyXText::cursorPrevious()
        ParagraphList::iterator pit = cursor.par();
        previousRow(pit, rit);
        setCursor(cur, pit, rit->pos(), false);
-       if (cur.y() > top_y())
+       if (cur.y() > bv_owner->top_y())
                cursorUp(true);
        bv()->updateScrollbar();
 }
@@ -285,32 +293,32 @@ void LyXText::cursorPrevious()
 
 void LyXText::cursorNext()
 {
-       int topy = top_y();
+       int topy = bv_owner->top_y();
 
        RowList::iterator rit = cursorRow();
        if (rit == lastRow()) {
                int y = cursor.y() - rit->baseline() + cursorRow()->height();
                if (y > topy + bv()->workHeight())
-                       bv()->updateScrollbar();
+                       bv_owner->updateScrollbar();
                return;
        }
 
-       int y = topy + bv()->workHeight();
+       int y = topy + bv_owner->workHeight();
        if (inset_owner && !topy) {
-               y -= (bv()->text->cursor.iy()
-                         - bv()->text->top_y()
-                         + bv()->theLockingInset()->insetInInsetY());
+               y -= (bv_owner->text->cursor.y()
+                         - bv_owner->top_y()
+                         + bv_owner->theLockingInset()->insetInInsetY());
        }
 
        ParagraphList::iterator dummypit;
-       getRowNearY(y, dummypit);
+       y = getRowNearY(y, dummypit)->y();
 
        setCursorFromCoordinates(cursor.x_fix(), y);
        // + bv->workHeight());
        finishUndo();
 
        int new_y;
-       if (rit == bv()->text->cursorRow()) {
+       if (rit == bv_owner->text->cursorRow()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the next row instead.
                cursorDown(true);
@@ -318,11 +326,11 @@ void LyXText::cursorNext()
                // This is what we used to do, so we wouldn't skip right past
                // tall rows, but it's not working right now.
 #if 0
-               new_y = bv->text->top_y() + bv->workHeight();
+               new_y = bv->top_y() + bv->workHeight();
 #endif
        } else {
                if (inset_owner) {
-                       new_y = bv()->text->cursor.iy()
+                       new_y = bv()->text->cursor.y()
                                + bv()->theLockingInset()->insetInInsetY()
                                + y - rit->baseline();
                } else {
@@ -331,10 +339,10 @@ void LyXText::cursorNext()
        }
 
        ParagraphList::iterator pit = cursor.par();
-       nextRow(pit, rit);      
+       nextRow(pit, rit);
        LyXCursor cur;
        setCursor(cur, pit, rit->pos(), false);
-       if (cur.y() < top_y() + bv()->workHeight())
+       if (cur.y() < bv_owner->top_y() + bv()->workHeight())
                cursorDown(true);
        bv()->updateScrollbar();
 }
@@ -350,7 +358,7 @@ void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
        if (!bv->insertInset(new_inset))
                delete new_inset;
        else
-               bv->updateInset();
+               bv->updateInset(new_inset);
 }
 
 
@@ -383,8 +391,9 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd,
 
 InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 {
-       lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
-                             <<"] arg[" << cmd.argument << ']' << endl;
+       lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
+                             <<"] arg[" << cmd.argument << ']' << "xy[" <<
+                                 cmd.x << ',' << cmd.y << ']' << endl;
 
        BufferView * bv = cmd.view();
 
@@ -402,7 +411,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        if (tmp->params().startOfAppendix()) {
                                recordUndo(bv, Undo::ATOMIC, tmp);
                                tmp->params().startOfAppendix(false);
-                               setHeightOfRow(tmp, getRow(tmp, 0));
+                               redoParagraph(tmp);
                                break;
                        }
                }
@@ -439,7 +448,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_WORDRIGHT:
                if (!selection.mark())
                        bv->beforeChange(this);
-               if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+               if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
                        cursorLeftOneWord();
                else
                        cursorRightOneWord();
@@ -449,7 +458,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_WORDLEFT:
                if (!selection.mark())
                        bv->beforeChange(this);
-               if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+               if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
                        cursorRightOneWord();
                else
                        cursorLeftOneWord();
@@ -473,7 +482,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_RIGHTSEL:
                if (!selection.set())
                        selection.cursor = cursor;
-               if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+               if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
                        cursorLeft(bv);
                else
                        cursorRight(bv);
@@ -483,7 +492,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_LEFTSEL:
                if (!selection.set())
                        selection.cursor = cursor;
-               if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+               if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
                        cursorRight(bv);
                else
                        cursorLeft(bv);
@@ -547,7 +556,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_WORDRIGHTSEL:
-               if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+               if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
                        cursorLeftOneWord();
                else
                        cursorRightOneWord();
@@ -555,7 +564,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_WORDLEFTSEL:
-               if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+               if (cursor.par()->isRightToLeftPar(bv->buffer()->params()))
                        cursorRightOneWord();
                else
                        cursorLeftOneWord();
@@ -574,7 +583,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_RIGHT: {
-               bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
+               bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params());
                if (!selection.mark())
                        bv->beforeChange(this);
                if (is_rtl)
@@ -597,7 +606,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_LEFT: {
                // This is soooo ugly. Isn`t it possible to make
                // it simpler? (Lgb)
-               bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
+               bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params());
                if (!selection.mark())
                        bv->beforeChange(this);
                LyXCursor const cur = cursor;
@@ -783,7 +792,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_BREAKPARAGRAPH:
                replaceSelection(bv->getLyXText());
-               breakParagraph(bv->buffer()->paragraphs, 0);
+               breakParagraph(bv->buffer()->paragraphs(), 0);
                bv->update();
                selection.cursor = cursor;
                bv->switchKeyMap();
@@ -792,7 +801,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
                replaceSelection(bv->getLyXText());
-               breakParagraph(bv->buffer()->paragraphs, 1);
+               breakParagraph(bv->buffer()->paragraphs(), 1);
                bv->update();
                selection.cursor = cursor;
                bv->switchKeyMap();
@@ -819,7 +828,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        }
                }
                else {
-                       breakParagraph(bv->buffer()->paragraphs, 0);
+                       breakParagraph(bv->buffer()->paragraphs(), 0);
                }
                bv->update();
                selection.cursor = cur;
@@ -871,7 +880,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_INSET_SETTINGS:
-               Assert(bv->theLockingInset());
+               BOOST_ASSERT(bv->theLockingInset());
                bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
                break;
 
@@ -1046,7 +1055,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                // Derive layout number from given argument (string)
                // and current buffer's textclass (number)
-               LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
+               LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
                bool hasLayout = tclass.hasLayout(cmd.argument);
                string layout = cmd.argument;
 
@@ -1136,10 +1145,10 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                LyXLayout_ptr const & style = pit->layout();
 
+               BufferParams const & bufparams = bv->buffer()->params();
                if (style->pass_thru ||
-                               pit->getFontSettings(bv->buffer()->params,
-                                        pos).language()->lang() == "hebrew" ||
-                       (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
+                   pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
+                   !bv->insertInset(new InsetQuotes(c, bufparams)))
                        bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
                break;
        }
@@ -1209,11 +1218,11 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        LyXFont font = bv->text->getFont(cursor.par(), cursor.pos());
                        int width = tli->width();
                        int inset_x = font.isVisibleRightToLeft()
-                               ? cursor.ix() - width : cursor.ix();
+                               ? cursor.x() - width : cursor.x();
                        int start_x = inset_x + tli->scroll();
                        FuncRequest cmd1 = cmd;
                        cmd1.x = cmd.x - start_x;
-                       cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
+                       cmd1.y = cmd.y - cursor.y() + bv->top_y();
                        tli->localDispatch(cmd1);
                        break;
                }
@@ -1228,7 +1237,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                }
 
                RowList::iterator cursorrow = bv->text->cursorRow();
-               bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
+               bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
        #if 0
                // sorry for this but I have a strange error that the y value jumps at
                // a certain point. This seems like an error in my xforms library or
@@ -1284,7 +1293,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        paste_internally = true;
                }
 
-               int const screen_first = bv->text->top_y();
+               int const screen_first = bv->top_y();
 
                if (bv->theLockingInset()) {
                        // We are in inset locking mode
@@ -1454,7 +1463,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                }
 
                bv->beforeChange(this);
-               LyXFont const old_font(real_current_font);
+               LyXFont const old_font = real_current_font;
 
                string::const_iterator cit = cmd.argument.begin();
                string::const_iterator end = cmd.argument.end();
@@ -1469,6 +1478,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                // update the minibuffer
                if (old_font != real_current_font)
                        bv->owner()->view_state_changed();
+               bv->updateScrollbar();
                break;
        }