]> git.lyx.org Git - lyx.git/commitdiff
Fix for wrong cursor.x pos when before a fullRow inset (added ix), small
authorJürgen Vigna <jug@sad.it>
Fri, 12 Apr 2002 15:59:03 +0000 (15:59 +0000)
committerJürgen Vigna <jug@sad.it>
Fri, 12 Apr 2002 15:59:03 +0000 (15:59 +0000)
perfomance fix in LyXText's raw drawing, fix for adding paragraph in insets
when not allowed to do so (bug in Michaels list not on lyxbugs.).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3990 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView_pimpl.C
src/ChangeLog
src/buffer.C
src/insets/ChangeLog
src/insets/insettext.C
src/insets/insettext.h
src/lyxcursor.C
src/lyxcursor.h
src/lyxtext.h
src/text.C
src/text2.C

index 1549d3338a442383a5c5999e7569b03284cf370c..ee6dde8a4c46006c1e0b3b0903f5c8c30d34874a 100644 (file)
@@ -547,12 +547,12 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
                                                  cursor.par(), cursor.pos());
                int width = bv_->theLockingInset()->width(bv_, font);
                int inset_x = font.isVisibleRightToLeft()
-                       ? cursor.x() - width : cursor.x();
+                       ? cursor.ix() - width : cursor.ix();
                int start_x = inset_x + bv_->theLockingInset()->scroll();
                bv_->theLockingInset()->
                        insetMotionNotify(bv_,
                                          x - start_x,
-                                         y - cursor.y() + bv_->text->first_y,
+                                         y - cursor.iy() + bv_->text->first_y,
                                          state);
                return;
        }
index 3ae0942835b5d49ad76a3d72f06137b2c9b81e24..49d6fb4869115d57bf51399795750c31ee012485 100644 (file)
@@ -1,7 +1,21 @@
 2002-04-12  Juergen Vigna  <jug@sad.it>
 
+       * BufferView_pimpl.C (workAreaMotionNotify): use new ix() cursor pos.
+
+       * text2.C (getCursorX): new helper function
+       (setCursor): compute also ix_
+       (setCursorFromCoordinates): set also ix.
+
+       * lyxcursor.h: added ix_ and helper functions.
+
+       * BufferView_pimpl.C (workAreaMotionNotify): forgot to use iy().
+
+       * buffer.C (insertStringAsLines): dont break paragraph if the this
+       paragraph is inside an inset which does not permit it!
+
        * text.C (breakParagraph): honor keepempty flag and break the paragraph
        also with no chars on this paragraph.
+       (paintRowText): only paint stuff if it's inside the workarea!
 
        * paragraph.C (breakParagraph): honor keepempty flag and break the
        paragraph always below not above.
index 185e4ee4d6ec7babd41b1c7e5656285913eea7f6..d55a1b38357ba2447ee57867bbd40936bb993ea2 100644 (file)
@@ -1400,10 +1400,12 @@ void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
        par->checkInsertChar(font);
        // insert the string, don't insert doublespace
        bool space_inserted = true;
+       bool autobreakrows = !par->inInset() ||
+               static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
        for(string::const_iterator cit = str.begin();
            cit != str.end(); ++cit) {
                if (*cit == '\n') {
-                       if (par->size() || layout.keepempty) {
+                       if (autobreakrows && (par->size() || layout.keepempty)) {
                                par->breakParagraph(params, pos,
                                                    layout.isEnvironment());
                                par = par->next();
index b0d4470e4effecc88cefc2fe038387ec2bfeb3a6..448a456a03311c3a8a49b6847cc6459d839242c9 100644 (file)
@@ -1,3 +1,7 @@
+2002-04-12  Juergen Vigna  <jug@sad.it>
+
+       * insettext.h: added cix() helper function and use it where appropriate
+
 2002-04-12  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
 
        * insetgraphics.C (prepareFile): fix bug when graphics is a
@@ -6,6 +10,9 @@
 2002-04-12  Juergen Vigna  <jug@sad.it>
 
        * insettext.C (insertInset): remove unneeded code!
+       (updateLocal): fitCursor() fixes.
+       (collapseParagraphs): fix a possible problem when having a selection
+       and collapsing the paragraphs.
 
 2002-04-08  Herbert Voss  <voss@perce.de>
 
index b532a4c79c5e4477346a1a0c07fbcf409aeb8182..2919ea6d7230827c2f83dd98a046dad1d7f66e35 100644 (file)
@@ -424,7 +424,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
 
        if (the_locking_inset && (cpar(bv) == inset_par)
                && (cpos(bv) == inset_pos)) {
-               inset_x = cx(bv) - top_x + drawTextXOffset;
+               inset_x = cix(bv) - top_x + drawTextXOffset;
                inset_y = ciy(bv) + drawTextYOffset;
        }
        if (!cleared && (need_update == CURSOR)
@@ -555,10 +555,10 @@ void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
        }
 
        if (!autoBreakRows && par->next())
-               collapseParagraphs(bv->buffer()->params);
+               collapseParagraphs(bv);
 
        if (the_locking_inset) {
-               inset_x = cx(bv) - top_x + drawTextXOffset;
+               inset_x = cix(bv) - top_x + drawTextXOffset;
                inset_y = ciy(bv) + drawTextYOffset;
                the_locking_inset->update(bv, font, reinit);
        }
@@ -610,7 +610,7 @@ void InsetText::setUpdateStatus(BufferView * bv, int what) const
 void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
 {
        if (!autoBreakRows && par->next())
-               collapseParagraphs(bv->buffer()->params);
+               collapseParagraphs(bv);
        bool clear = false;
        if (!lt) {
                lt = getLyXText(bv);
@@ -625,8 +625,15 @@ void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
                lt->selection.cursor = lt->cursor;
        if (clear)
                lt = 0;
+#if 0
+       // IMO this is not anymore needed as we do this in fitInsetCursor!
+       // and we always get "true" as returnvalue of this function in the
+       // case of a locking inset (Jug 20020412)
        if (locked && (need_update & CURSOR) && bv->fitCursor())
                need_update |= FULL;
+#else
+       bv->fitCursor();
+#endif
        if (flag)
                bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
 
@@ -785,7 +792,7 @@ void InsetText::insetUnlock(BufferView * bv)
 void InsetText::lockInset(BufferView * bv, UpdatableInset * inset)
 {
        the_locking_inset = inset;
-       inset_x = cx(bv) - top_x + drawTextXOffset;
+       inset_x = cix(bv) - top_x + drawTextXOffset;
        inset_y = ciy(bv) + drawTextYOffset;
        inset_pos = cpos(bv);
        inset_par = cpar(bv);
@@ -831,7 +838,7 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
        } else if (the_locking_inset && (the_locking_inset == inset)) {
                if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
                        lyxerr[Debug::INSETS] << "OK" << endl;
-                       inset_x = cx(bv) - top_x + drawTextXOffset;
+                       inset_x = cix(bv) - top_x + drawTextXOffset;
                        inset_y = ciy(bv) + drawTextYOffset;
                } else {
                        lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
@@ -870,7 +877,7 @@ bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
 bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
 {
        if (!autoBreakRows && par->next())
-               collapseParagraphs(bv->buffer()->params);
+               collapseParagraphs(bv);
        if (inset == this)
                return true;
        bool clear = false;
@@ -909,7 +916,7 @@ bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
                if (the_locking_inset &&
                    cpar(bv) == inset_par && cpos(bv) == inset_pos)
                {
-                       inset_x = cx(bv) - top_x + drawTextXOffset;
+                       inset_x = cix(bv) - top_x + drawTextXOffset;
                        inset_y = ciy(bv) + drawTextYOffset;
                }
        }
@@ -942,7 +949,7 @@ void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
                else if (inset) {
                        // otherwise unlock the_locking_inset and lock the new inset
                        the_locking_inset->insetUnlock(bv);
-                       inset_x = cx(bv) - top_x + drawTextXOffset;
+                       inset_x = cix(bv) - top_x + drawTextXOffset;
                        inset_y = ciy(bv) + drawTextYOffset;
                        the_locking_inset = 0;
                        inset->insetButtonPress(bv, x - inset_x,
@@ -1043,7 +1050,7 @@ bool InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
                        ret = inset->insetButtonRelease(bv, x - inset_x,
                                                        y - inset_y, button);
                } else {
-                       inset_x = cx(bv) - top_x + drawTextXOffset;
+                       inset_x = cix(bv) - top_x + drawTextXOffset;
                        inset_y = ciy(bv) + drawTextYOffset;
                        ret = inset->insetButtonRelease(bv, x - inset_x,
                                                        y - inset_y, button);
@@ -2009,7 +2016,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
                        x = insetWidth;
                if (y < 0)
                        y = insetDescent;
-               inset_x = cx(bv) - top_x + drawTextXOffset;
+               inset_x = cix(bv) - top_x + drawTextXOffset;
                inset_y = ciy(bv) + drawTextYOffset;
                inset->edit(bv, x - inset_x, y - inset_y, button);
                if (!the_locking_inset)
@@ -2120,6 +2127,21 @@ int InsetText::cx(BufferView * bv) const
 }
 
 
+int InsetText::cix(BufferView * bv) const
+{
+       // we do nothing dangerous so we use a local cache
+       LyXText * llt = getLyXText(bv);
+       int x = llt->cursor.ix() + top_x + TEXT_TO_INSET_OFFSET;
+       if (the_locking_inset) {
+               LyXFont font = llt->getFont(bv->buffer(), llt->cursor.par(),
+                                           llt->cursor.pos());
+               if (font.isVisibleRightToLeft())
+                       x -= the_locking_inset->width(bv, font);
+       }
+       return x;
+}
+
+
 int InsetText::cy(BufferView * bv) const
 {
        LyXFont font;
@@ -2282,7 +2304,7 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const
        t->init(bv, true);
        restoreLyXTextState(bv, t);
        if (the_locking_inset) {
-               inset_x = cx(bv) - top_x + drawTextXOffset;
+               inset_x = cix(bv) - top_x + drawTextXOffset;
                inset_y = ciy(bv) + drawTextYOffset;
        }
 
@@ -2323,7 +2345,7 @@ void InsetText::reinitLyXText() const
                t->init(bv, true);
                restoreLyXTextState(bv, t);
                if (the_locking_inset) {
-                       inset_x = cx(bv) - top_x + drawTextXOffset;
+                       inset_x = cix(bv) - top_x + drawTextXOffset;
                        inset_y = ciy(bv) + drawTextYOffset;
                }
                if (bv->screen()) {
@@ -2656,14 +2678,29 @@ bool InsetText::checkInsertChar(LyXFont & font)
 }
 
 
-void InsetText::collapseParagraphs(BufferParams const & bparams) const
+void InsetText::collapseParagraphs(BufferView * bv) const
 {
+       BufferParams const & bparams = bv->buffer()->params;
+       LyXText * llt = getLyXText(bv);
+       
        while(par->next()) {
                if (par->size() && par->next()->size() &&
                        !par->isSeparator(par->size()-1))
                {
                        par->insertChar(par->size(), ' ');
                }
+               if (llt->selection.set()) {
+                       if (llt->selection.start.par() == par->next()) {
+                               llt->selection.start.par(par);
+                               llt->selection.start.pos(
+                                       llt->selection.start.pos() + par->size());
+                       }
+                       if (llt->selection.end.par() == par->next()) {
+                               llt->selection.end.par(par);
+                               llt->selection.end.pos(
+                                       llt->selection.end.pos() + par->size());
+                       }
+               }
                par->pasteParagraph(bparams);
        }
        reinitLyXText();
index 69f712dbe8804db095fead7bb9a0a6310ea17a34..20fcfbdaec7df4a19b31ac239a2d3e6ed95d1d3b 100644 (file)
@@ -321,6 +321,8 @@ private:
        ///
        int cx(BufferView *) const;
        ///
+       int cix(BufferView *) const;
+       ///
        int cy(BufferView *) const;
        ///
        int ciy(BufferView *) const;
@@ -345,7 +347,7 @@ private:
        ///
        void reinitLyXText() const;
        ///
-       void collapseParagraphs(BufferParams const & bparams) const;
+       void collapseParagraphs(BufferView *) const;
 
        /* Private structures and variables */
        ///
index 4e02327fbc0b982a41bfb466522085f4ff7d39cd..47489a0fddea40b4c763a51bca35ab398dea20fd 100644 (file)
@@ -19,7 +19,7 @@
 
 LyXCursor::LyXCursor()
        : par_(0), pos_(0), boundary_(false),
-         x_(0), x_fix_(0), y_(0), iy_(0), row_(0)
+         x_(0), ix_(0), x_fix_(0), y_(0), iy_(0), row_(0)
 {}
 
 
@@ -70,6 +70,17 @@ int LyXCursor::x() const
 }
 
 
+void LyXCursor::ix(int n)
+{
+       ix_ = n;
+}
+
+int LyXCursor::ix() const
+{
+       return ix_;
+}
+
+
 void LyXCursor::x_fix(int i)
 {
        x_fix_ = i;
index 9c37d0dff992c13ddd47cadc725814327b615475..fe3cc2842cc6af2cd158c6b781859f7b6acdec79 100644 (file)
@@ -44,6 +44,10 @@ public:
        ///
        int x() const;
        ///
+       void ix(int i);
+       ///
+       int ix() const;
+       ///
        void x_fix(int i);
        ///
        int x_fix() const;
@@ -68,6 +72,9 @@ private:
        bool boundary_;
        ///
        int x_;
+       /// the x position of the position before the inset when we put
+       /// the cursor on the end of the row before, otherwise equal to x.
+       int ix_;
        ///
        int x_fix_;
        ///
index 646f736ffa41fe01a6f04a3917197b0633064486..a595e2f7856fdc3f70153e6e29408886a44538dd 100644 (file)
@@ -321,6 +321,9 @@ public:
                             bool setfont = true,
                             bool boundary = false) const;
        ///
+       float getCursorX(BufferView *, Row *, lyx::pos_type pos,
+                                        lyx::pos_type last, bool boundary) const;
+       ///
        void setCurrentFont(BufferView *) const;
 
        ///
index b53d26db66c9fd801b6d355a323187001c182e8c..217398f890a7b39ae556b028f6b2fefa8544aeec 100644 (file)
@@ -3609,7 +3609,14 @@ void LyXText::paintRowText(DrawRowParams & p)
 
        pos_type vpos = p.row->pos();
        while (vpos <= last) {
+               if (p.x > p.bv->workWidth())
+                       break;
                pos_type pos = vis2log(vpos);
+               if (p.x + singleWidth(p.bv, par, pos) < 0) {
+                       p.x += singleWidth(p.bv, par, pos);
+                       ++vpos;
+                       continue;
+               }
                if (main_body > 0 && pos == main_body - 1) {
                        int const lwidth = lyxfont::width(layout.labelsep,
                                getLabelFont(buffer, par));
index bab91e69280dadb45ba976238749aead0761c195..089965c9973152fe4fa658a803281bbb3c92baee 100644 (file)
@@ -2083,14 +2083,6 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
        // y is now the cursor baseline
        cur.y(y);
 
-       // now get the cursors x position
-       float x;
-       float fill_separator;
-       float fill_hfill;
-       float fill_label_hfill;
-       prepareToPrint(bview, row, x, fill_separator, fill_hfill,
-                      fill_label_hfill);
-       pos_type cursor_vpos = 0;
        pos_type last = rowLastPrintable(old_row);
 
        if (pos > last + 1) {
@@ -2102,6 +2094,30 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
                cur.pos(pos);
        }
 
+       // now get the cursors x position
+       float x = getCursorX(bview, row, pos, last, boundary);
+       cur.x(int(x));
+       cur.x_fix(cur.x());
+       if (old_row != row) {
+               x = getCursorX(bview, old_row, pos, last, boundary);
+               cur.ix(int(x));
+       } else
+               cur.ix(cur.x());
+}
+
+
+float LyXText::getCursorX(BufferView * bview, Row * row,
+                                                 pos_type pos, pos_type last, bool boundary) const
+{
+       pos_type cursor_vpos = 0;
+       float x;
+       float fill_separator;
+       float fill_hfill;
+       float fill_label_hfill;
+       // This call HAS to be here because of the BidiTables!!!
+       prepareToPrint(bview, row, x, fill_separator, fill_hfill,
+                      fill_label_hfill);
+
        if (last < row->pos())
                cursor_vpos = row->pos();
        else if (pos > last && !boundary)
@@ -2125,7 +2141,7 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
                main_body = 0;
 
        for (pos_type vpos = row->pos(); vpos < cursor_vpos; ++vpos) {
-               pos = vis2log(vpos);
+               pos_type pos = vis2log(vpos);
                if (main_body > 0 && pos == main_body - 1) {
                        x += fill_label_hfill +
                                lyxfont::width(textclasslist[
@@ -2149,9 +2165,7 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
                } else
                        x += singleWidth(bview, row->par(), pos);
        }
-
-       cur.x(int(x));
-       cur.x_fix(cur.x());
+       return x;
 }
 
 
@@ -2248,6 +2262,7 @@ void LyXText::setCursorFromCoordinates(BufferView * bview, LyXCursor & cur,
        cur.par(row->par());
        cur.pos(row->pos() + column);
        cur.x(x);
+       cur.ix(x);
        cur.y(y + row->baseline());
        Inset * ins;
        if (row->next() && cur.pos() &&