]> git.lyx.org Git - features.git/commitdiff
Fixed long standing bug in breaking rows correctly. Fixed redraws when
authorJürgen Vigna <jug@sad.it>
Sun, 6 Jan 2002 19:34:30 +0000 (19:34 +0000)
committerJürgen Vigna <jug@sad.it>
Sun, 6 Jan 2002 19:34:30 +0000 (19:34 +0000)
searching/spellchecking inside tabulars. Fixed wrong frame redraw and
wrong clearing of inset (visible when the inset has a background color).

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

po/POTFILES.in
src/BufferView2.C
src/ChangeLog
src/insets/ChangeLog
src/insets/insettabular.C
src/insets/insettext.C
src/text.C

index 70e9cdc5419824a319fc621ab7c2e6bc366be90e..d1725fb6609df7aab9891d762bfb18c936b885c2 100644 (file)
@@ -9,6 +9,7 @@ src/converter.C
 src/CutAndPaste.C
 src/debug.C
 src/exporter.C
+src/ext_l10n.h
 src/figure_form.C
 src/figureForm.C
 src/FontLoader.C
index cf53e9b2ee8d3c94e79ea8d248b2c1d088326060..7bdda14a64331c48a76ad5896b6e4f6514771b29 100644 (file)
@@ -457,7 +457,7 @@ bool BufferView::lockInset(UpdatableInset * inset)
 
 void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc)
 {
-       if (available() && theLockingInset()) {
+       if (available() && theLockingInset() && !theLockingInset()->nodraw()) {
                LyXCursor cursor = text->cursor;
                Inset * locking_inset = theLockingInset()->getLockingInset();
 
index 259603b7e85883494faedc123626e4fafa348d2f..d5bccea896a98ba15f769c2d8c04e39a9e6ba6db 100644 (file)
@@ -1,3 +1,15 @@
+2002-01-06  Juergen Vigna  <jug@sad.it>
+
+       * text.C (nextBreakPoint): fixed up this function we had this bug
+       since ever but now hopefully we break row better.
+       (insertChar): we have to check if an inset is the next char as it
+       could now happen that a large inset is causing a break.
+
+2002-01-05  Juergen Vigna  <jug@sad.it>
+
+       * BufferView2.C (showLockedInsetCursor): don't draw the inset cursor
+       if it doesn't like to be drawed.
+
 2002-01-04  Juergen Vigna  <jug@sad.it>
 
        * BufferView2.C (lockInset): forgot to set a cursor.
index 35430b74800da40dbe25a191c04d5cb0b8b26447..2754b22c7bc470a2fc526ce43f15a41f483f41c6 100644 (file)
@@ -1,3 +1,12 @@
+2002-01-05  Juergen Vigna  <jug@sad.it>
+
+       * insettext.C (draw): move the calls so that insetWidth/Asc/Desc
+       variables are updated.
+
+       * insettabular.C (resetPos): set always the inset_y as it may be
+       needed in another function.
+       (searchBackward): don't draw while searching.
+
 2002-01-04  Juergen Vigna  <jug@sad.it>
 
        * insettext.C (lockInsetInInset): forgot to set a cursor.
index 16623088a14b0566ffb52b20ac9fee877e1a6d07..655637564078a86d2ad8f823d27506975115271f 100644 (file)
@@ -699,7 +699,6 @@ unsigned int InsetTabular::insetInInsetY()
 {
        if (!the_locking_inset)
                return 0;
-       
        return inset_y + the_locking_inset->insetInInsetY();
 }
 
@@ -1305,6 +1304,11 @@ void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
 
 void InsetTabular::toggleInsetCursor(BufferView * bv)
 {
+       if (nodraw()) {
+               if (isCursorVisible())
+                       bv->hideLockedInsetCursor();
+               return;
+       }
        if (the_locking_inset) {
                the_locking_inset->toggleInsetCursor(bv);
                return;
@@ -1325,6 +1329,8 @@ void InsetTabular::toggleInsetCursor(BufferView * bv)
 
 void InsetTabular::showInsetCursor(BufferView * bv, bool show)
 {
+       if (nodraw())
+               return;
        if (!isCursorVisible()) {
                LyXFont font; // = GetFont(par, cursor.pos);
        
@@ -1406,17 +1412,13 @@ int InsetTabular::getCellXPos(int cell) const
 
 void InsetTabular::resetPos(BufferView * bv) const
 {
-       if (!locked || nodraw())
-               return;
 #warning This should be fixed in the right manner (20011128 Jug)
        // fast hack to fix infinite repaintings!
        if (in_reset_pos)
                return;
-       in_reset_pos = true;
-
-       actcol = tabular->column_of_cell(actcell);
 
        int cell = 0;
+       actcol = tabular->column_of_cell(actcell);
        actrow = 0;
        cursor_.y(0);
        for (; (cell < actcell) && !tabular->IsLastRow(cell); ++cell) {
@@ -1427,6 +1429,13 @@ void InsetTabular::resetPos(BufferView * bv) const
                        ++actrow;
                }
        }
+       if (!locked || nodraw()) {
+               if (the_locking_inset)
+                       inset_y = cursor_.y();
+               return;
+       }
+       // we need this only from here on!!!
+       in_reset_pos = true;
        static int const offset = ADD_TO_TABULAR_WIDTH + 2;
        int new_x = getCellXPos(actcell);
        int old_x = cursor_.x();
@@ -2635,17 +2644,20 @@ Inset * InsetTabular::getInsetFromID(int id_arg) const
 string const
 InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
 {
+       nodraw(true);
        if (the_locking_inset) {
                string const str(the_locking_inset->selectNextWordToSpellcheck(bv, value));
-               if (!str.empty())
+               if (!str.empty()) {
+                       nodraw(false);
                        return str;
+               }
                if (tabular->IsLastCell(actcell)) {
                        bv->unlockInset(const_cast<InsetTabular *>(this));
+                       nodraw(false);
                        return string();
                }
                ++actcell;
        }
-       nodraw(true);
        // otherwise we have to lock the next inset and ask for it's selecttion
        UpdatableInset * inset =
                static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
@@ -2701,10 +2713,15 @@ void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
 bool InsetTabular::searchForward(BufferView * bv, string const & str,
                                  bool const & cs, bool const & mw)
 {
+       nodraw(true);
        if (the_locking_inset) {
-               if (the_locking_inset->searchForward(bv, str, cs, mw))
+               if (the_locking_inset->searchForward(bv, str, cs, mw)) {
+                       nodraw(false);
+                       updateLocal(bv, CELL, false);
                        return true;
+               }
                if (tabular->IsLastCell(actcell)) {
+                       nodraw(false);
                        bv->unlockInset(const_cast<InsetTabular *>(this));
                        return false;
                }
@@ -2714,24 +2731,25 @@ bool InsetTabular::searchForward(BufferView * bv, string const & str,
        UpdatableInset * inset =
                static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
        inset->edit(bv);
-#if 0
-       bool const res = searchForward(bv, str, cs, mw);
-       updateLocal(bv, NONE, false);
-       bv->updateInset(const_cast<InsetTabular *>(this), false);
-       return res;
-#else
-       return searchForward(bv, str, cs, mw);
-#endif
+       bool const ret = searchForward(bv, str, cs, mw);
+       nodraw(false);
+       updateLocal(bv, CELL, false);
+       return ret;
 }
 
 
 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
                                bool const & cs, bool const & mw)
 {
+       nodraw(true);
        if (the_locking_inset) {
-               if (the_locking_inset->searchBackward(bv, str, cs, mw))
+               if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
+                       nodraw(false);
+                       updateLocal(bv, CELL, false);
                        return true;
+               }
                if (!actcell) { // we are already in the first cell
+                       nodraw(false);
                        bv->unlockInset(const_cast<InsetTabular *>(this));
                        return false;
                }
@@ -2741,13 +2759,10 @@ bool InsetTabular::searchBackward(BufferView * bv, string const & str,
        UpdatableInset * inset =
                static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
        inset->edit(bv, false);
-#if 0
-       bool const res = searchBackward(bv, str, cs, mw);
-       bv->updateInset(const_cast<InsetTabular *>(this), false);
-       return res;
-#else
-       return searchBackward(bv, str, cs, mw);
-#endif
+       bool const ret = searchBackward(bv, str, cs, mw);
+       nodraw(false);
+       updateLocal(bv, CELL, false);
+       return ret;
 }
 
 
index ba4966ab23669fbd144e314f362c82b38cd1e52b..c67cd03c4616f31215d27865a05ae8933a6a1ea5 100644 (file)
@@ -361,6 +361,12 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                }
        }
 
+       // call these methods so that insetWidth, insetAscent and
+       // insetDescent have the right values. 
+       width(bv, f);
+       ascent(bv, f);
+       descent(bv, f);
+
        // repaint the background if needed
        if (cleared && backgroundColor() != LColor::background) {
                top_x = int(x);
@@ -402,12 +408,6 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                return;
        }
 
-       // call these methods so that insetWidth, insetAscent and
-       // insetDescent have the right values. 
-       width(bv, f);
-       ascent(bv, f);
-       descent(bv, f);
-
        top_baseline = baseline;
        top_y = baseline - insetAscent;
 
@@ -509,8 +509,7 @@ void InsetText::drawFrame(Painter & pain, bool cleared) const
                frame_y = top_baseline - insetAscent + ttoD2;
                frame_w = insetWidth - TEXT_TO_INSET_OFFSET;
                frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET;
-               pain.rectangle(frame_x, frame_y,
-                              frame_w, frame_h,
+               pain.rectangle(frame_x, frame_y, frame_w, frame_h,
                               frame_color);
                frame_is_visible = true;
        }
@@ -2337,10 +2336,9 @@ void InsetText::clearSelection(BufferView * bv)
 
 void InsetText::clearInset(BufferView * bv, int baseline, bool & cleared) const
 {
-       LyXFont dummy;
        Painter & pain = bv->painter();
        int w = insetWidth;
-       int h = ascent(bv, dummy) + descent(bv, dummy);
+       int h = insetAscent + insetDescent;
        int ty = baseline - insetAscent;
        
        if (ty < 0) {
index 8a1027265571d66ac9bbe8bffdcaf528dbbc060d..2d7197b7708110983235eb87f4f934d2f44f443e 100644 (file)
@@ -931,7 +931,7 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
                textclasslist.Style(bview->buffer()->params.textclass,
                                    par->getLayout());
        pos_type i = pos;
-
+       
        if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
                /* special code for right address boxes, only newlines count */
                while (i < par->size()) {
@@ -959,7 +959,7 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
                                last_separator = i;
                                x = width; // this means break
                        } else if (c == Paragraph::META_INSET &&
-                                  par->getInset(i)) {
+                                  par->getInset(i)) {
                                
                                // check wether a Display() inset is
                                // valid here. if not, change it to
@@ -967,12 +967,14 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
                                if (par->getInset(i)->display() &&
                                    (layout.isCommand() ||
                                     (layout.labeltype == LABEL_MANUAL
-                                     && i < beginningOfMainBody(bview->buffer(), par)))) {
+                                     && i < beginningOfMainBody(bview->buffer(), par))))
+                               {
                                        // display istn't allowd
                                        par->getInset(i)->display(false);
                                        x += singleWidth(bview, par, i, c);
                                } else if (par->getInset(i)->display() ||
-                                        par->getInset(i)->needFullRow()) {
+                                          par->getInset(i)->needFullRow())
+                               {
                                        // So break the line here
                                        if (i == pos) {
                                                if (pos < last-1) {
@@ -986,6 +988,16 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
                                        x = width;  // this means break
                                } else {
                                        x += singleWidth(bview, par, i, c);
+                                       // we have to check this separately as we could have a
+                                       // lineseparator and then the algorithm below would prefer
+                                       // that which IS wrong! We should always break on an inset
+                                       // if it's too long and not on the last separator.
+                                       // Maybe the only exeption is insets used as chars but
+                                       // then we would have to have a special function inside
+                                       // the inset to tell us this. Till then we leave it as
+                                       // it is now. (Jug 20020106)
+                                       if (pos < i && x >= width && last_separator >= 0)
+                                               last_separator = i - 1;
                                }
                        } else  {
                                if (IsLineSeparatorChar(c))
@@ -1003,8 +1015,12 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
                                        x = left_margin;
                        }
                }
+               if ((pos+1 < i) && (last_separator < 0) && (x >= width))
+                       last_separator = i - 2;
+               else if ((pos < i) && (last_separator < 0) && (x >= width))
+                       last_separator = i - 1;
                // end of paragraph is always a suitable separator
-               if (i == last && x < width)
+               else if (i == last && x < width)
                        last_separator = i;
        }
        
@@ -1018,6 +1034,7 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
        if (main_body && last_separator < main_body)
                last_separator = main_body - 1;
        
+       lyxerr << last_separator << ":" << pos << endl;
        return last_separator;
 }
 
@@ -1920,6 +1937,8 @@ void LyXText::insertChar(BufferView * bview, char c)
        // Is there a break one row above
        if ((cursor.par()->isLineSeparator(cursor.pos())
             || cursor.par()->isNewline(cursor.pos())
+                || ((cursor.pos() < cursor.par()->size()) &&
+                        cursor.par()->isInset(cursor.pos()+1))
             || cursor.row()->fill() == -1)
            && row->previous() && row->previous()->par() == row->par()) {
                pos_type z = nextBreakPoint(bview,