]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
Fix working of the spellchecker dialog with ispell when there are no
[lyx.git] / src / text.C
index cd1390753a3dc03c555de02f68ee71004a1fc175..6ad71787f855a3821ac3757f1348fa97d89957db 100644 (file)
@@ -138,7 +138,7 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par,
 
 
 int LyXText::singleWidth(BufferView * bview, Paragraph * par,
-                        Paragraph::size_type pos, char c) const
+                         Paragraph::size_type pos, char c) const
 {
        LyXFont const font = getFont(bview->buffer(), par, pos);
 
@@ -452,7 +452,7 @@ void LyXText::draw(BufferView * bview, Row const * row,
                ++vpos;
 
                if (lyxrc.mark_foreign_language &&
-                       font.language() != ignore_language &&
+                       font.language() != latex_language &&
                    font.language() != bview->buffer()->params.language) {
                        int const y = offset + row->height() - 1;
                        pain.line(int(tmpx), y, int(x), y, LColor::language);
@@ -568,12 +568,15 @@ void LyXText::draw(BufferView * bview, Row const * row,
                x += lyxfont::width(textstring, font);
        }
 
+#ifdef INHERIT_LANGUAGE
 #ifdef WITH_WARNINGS
        if ((font.language() == inherit_language) ||
                (font.language() == ignore_language))
                lyxerr << "No this shouldn't happen!\n";
+#endif
 #endif
        if (lyxrc.mark_foreign_language &&
+           font.language() != latex_language &&
            font.language() != bview->buffer()->params.language) {
                int const y = offset + row->height() - 1;
                pain.line(int(tmpx), y, int(x), y,
@@ -975,7 +978,7 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
 int LyXText::fill(BufferView * bview, Row * row, int paper_width) const
 {
        if (paper_width < 0)
-               return 20;
+               return 0;
 
        int w;
        // get the pure distance
@@ -1134,7 +1137,7 @@ int LyXText::numberOfLabelHfills(Buffer const * buf, Row const * row) const
 // returns true, if a expansion is needed.
 // Rules are given by LaTeX
 bool LyXText::hfillExpansion(Buffer const * buf, Row const * row_ptr,
-                            Paragraph::size_type pos) const
+                             Paragraph::size_type pos) const
 {
        // by the way, is it a hfill?
        if (!row_ptr->par()->isHfill(pos))
@@ -1426,7 +1429,8 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const
                if (firstpar->params().lineBottom())
                        maxdesc += 2 * lyxfont::ascent('x',
                                                       getFont(bview->buffer(),
-                                                      par, par->size() - 1));
+                                                              par,
+                                                              max(Paragraph::size_type(0), par->size() - 1)));
          
                // and now the pagebreaks
                if (firstpar->params().pagebreakBottom())
@@ -1991,11 +1995,11 @@ void LyXText::charInserted()
 
 
 void LyXText::prepareToPrint(BufferView * bview,
-                            Row * row, float & x,
-                            float & fill_separator, 
-                            float & fill_hfill,
-                            float & fill_label_hfill,
-                            bool bidi) const
+                             Row * row, float & x,
+                             float & fill_separator, 
+                             float & fill_hfill,
+                             float & fill_label_hfill,
+                             bool bidi) const
 {
        float nlh;
        float ns;
@@ -2030,45 +2034,49 @@ void LyXText::prepareToPrint(BufferView * bview,
        // are there any hfills in the row?
        float const nh = numberOfHfills(bview->buffer(), row);
 
-       if (nh)
-         fill_hfill = w / nh;
-       else  {
+       if (nh) {
+               if (w > 0)
+                       fill_hfill = w / nh;
+       } else  {
                // is it block, flushleft or flushright? 
                // set x how you need it
-       int align;
-       if (row->par()->params().align() == LYX_ALIGN_LAYOUT)
-         align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->getLayout()).align;
-       else
-         align = row->par()->params().align();
-          
-       // center displayed insets 
-       Inset * inset;
-          if (row->par()->getChar(row->pos()) == Paragraph::META_INSET
-              && (inset=row->par()->getInset(row->pos()))
-              && (inset->display())) // || (inset->scroll() < 0)))
-            align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
-                    ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
-
-          switch (align) {
+               int align;
+               if (row->par()->params().align() == LYX_ALIGN_LAYOUT) {
+                       align = textclasslist.Style(bview->buffer()->params.textclass, row->par()->getLayout()).align;
+               } else {
+                       align = row->par()->params().align();
+               }
+               
+               // center displayed insets 
+               Inset * inset;
+               if (row->par()->getChar(row->pos()) == Paragraph::META_INSET
+                   && (inset=row->par()->getInset(row->pos()))
+                   && (inset->display())) // || (inset->scroll() < 0)))
+                   align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
+                       ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
+               
+               switch (align) {
            case LYX_ALIGN_BLOCK:
-             ns = numberOfSeparators(bview->buffer(), row);
-             if (ns && row->next() && row->next()->par() == row->par() &&
-                 !(row->next()->par()->isNewline(row->next()->pos() - 1))
-                 && !(row->next()->par()->getChar(row->next()->pos()) == Paragraph::META_INSET
-                      && row->next()->par()->getInset(row->next()->pos())
-                      && row->next()->par()->getInset(row->next()->pos())->display())
-                 )
-               fill_separator = w / ns;
-             else if (is_rtl)
-               x += w;
-             break;
+                       ns = numberOfSeparators(bview->buffer(), row);
+                       if (ns && row->next() && row->next()->par() == row->par() &&
+                           !(row->next()->par()->isNewline(row->next()->pos() - 1))
+                           && !(row->next()->par()->getChar(row->next()->pos()) == Paragraph::META_INSET
+                                && row->next()->par()->getInset(row->next()->pos())
+                                && row->next()->par()->getInset(row->next()->pos())->display())
+                               )
+                       {
+                               fill_separator = w / ns;
+                       } else if (is_rtl) {
+                               x += w;
+                       }
+                       break;
            case LYX_ALIGN_RIGHT:
-             x += w;
-             break;
+                       x += w;
+                       break;
            case LYX_ALIGN_CENTER:
-             x += w / 2;
-             break;
-          }
+                       x += w / 2;
+                       break;
+               }
        }
        if (!bidi)
                return;
@@ -2263,16 +2271,17 @@ bool LyXText::selectWordWhenUnderCursor(BufferView * bview,
 
 // This function is only used by the spellchecker for NextWord().
 // It doesn't handle LYX_ACCENTs and probably never will.
-string const LyXText::selectNextWord(BufferView * bview,
-                                    float & value) const
+string const LyXText::selectNextWordToSpellcheck(BufferView * bview,
+                                     float & value) const
 {
        if (the_locking_inset) {
-               string str = the_locking_inset->selectNextWord(bview, value);
+               string str = the_locking_inset->selectNextWordToSpellcheck(bview, value);
                if (!str.empty()) {
                        value += float(cursor.y())/float(height);
                        return str;
                }
 #warning Dekel please have a look on this one RTL? (Jug)
+#warning DEKEL!
                // we have to go on checking so move cusor to the right
                if (cursor.pos() == cursor.par()->size()) {
                        if (!cursor.par()->next())
@@ -2300,7 +2309,7 @@ string const LyXText::selectNextWord(BufferView * bview,
                   !cursor.par()->getInset(cursor.pos())->isTextInset()))
               || (cursor.par()->size() == cursor.pos()
                   && cursor.par()->next()))
-       {
+       {      
                if (cursor.pos() == cursor.par()->size()) {
                        cursor.par(cursor.par()->next());
                        cursor.pos(0);
@@ -2310,13 +2319,13 @@ string const LyXText::selectNextWord(BufferView * bview,
 
        // now check if we hit an inset so it has to be a inset containing text!
        if (cursor.pos() < cursor.par()->size() &&
-               cursor.par()->isInset(cursor.pos()))
+           cursor.par()->isInset(cursor.pos()))
        {
                // lock the inset!
                cursor.par()->getInset(cursor.pos())->edit(bview);
                // now call us again to do the above trick
                // but obviously we have to start from down below ;)
-               return bview->text->selectNextWord(bview, value);
+               return bview->text->selectNextWordToSpellcheck(bview, value);
        }               
   
        // Update the value if we changed paragraphs
@@ -2400,10 +2409,10 @@ void LyXText::deleteWordForward(BufferView * bview)
                setCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
                selection.cursor = cursor;
                cursor = tmpcursor;
-               setSelection(bview); 
+               setSelection(bview);
                
                /* -----> Great, CutSelection() gets rid of multiple spaces. */
-               cutSelection(bview);
+               cutSelection(bview, true, false);
        }
 }
 
@@ -2422,7 +2431,7 @@ void LyXText::deleteWordBackward(BufferView * bview)
               selection.cursor = cursor;
               cursor = tmpcursor;
               setSelection(bview);
-              cutSelection(bview);
+              cutSelection(bview, true, false);
        }
 }
 
@@ -2448,7 +2457,7 @@ void LyXText::deleteLineForward(BufferView * bview)
                if (!selection.set()) {
                        deleteWordForward(bview);
                } else {
-                       cutSelection(bview);
+                       cutSelection(bview, true, false);
                }
        }
 }
@@ -2576,7 +2585,9 @@ void LyXText::Delete(BufferView * bview)
        if ((cursor.par()->previous() ? cursor.par()->previous()->id() : 0)
            == old_cur_par_prev_id
            && cursor.par()->id() != old_cur_par_id)
+       {
                return; // delete-empty-paragraph-mechanism has done it
+       }
 
        // if you had success make a backspace
        if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
@@ -2639,8 +2650,7 @@ void LyXText::backspace(BufferView * bview)
 
                if (cursor.par()->previous()) {
                        setUndo(bview, Undo::DELETE,
-                               cursor.par()->previous(),
-                               cursor.par()->next());
+                               cursor.par()->previous(), cursor.par()->next());
                }
                
                Paragraph * tmppar = cursor.par();
@@ -2653,8 +2663,8 @@ void LyXText::backspace(BufferView * bview)
                if (cursor.par()->previous()) { 
                        // steps into the above paragraph.
                        setCursorIntern(bview, cursor.par()->previous(),
-                                       cursor.par()->previous()->size(),
-                                       false);
+                                       cursor.par()->previous()->size(),
+                                       false);
                }
 
                /* Pasting is not allowed, if the paragraphs have different
@@ -2670,8 +2680,8 @@ void LyXText::backspace(BufferView * bview)
                if (cursor.par() != tmppar
                    && (cursor.par()->getLayout() == tmppar->getLayout()
                        || tmppar->getLayout() == 0 /*standard*/)
-                   && cursor.par()->getAlign() == tmppar->getAlign()) {
-
+                   && cursor.par()->getAlign() == tmppar->getAlign())
+               {
                        removeParagraph(tmprow);
                        removeRow(tmprow);
                        cursor.par()->pasteParagraph(bview->buffer()->params);
@@ -2708,13 +2718,13 @@ void LyXText::backspace(BufferView * bview)
                /* this is the code for a normal backspace, not pasting
                 * any paragraphs */ 
                setUndo(bview, Undo::DELETE,
-                       cursor.par(), cursor.par()->next()); 
+                       cursor.par(), cursor.par()->next()); 
                // We used to do cursorLeftIntern() here, but it is
                // not a good idea since it triggers the auto-delete
                // mechanism. So we do a cursorLeftIntern()-lite,
                // without the dreaded mechanism. (JMarc)
                setCursorIntern(bview, cursor.par(), cursor.pos()- 1,
-                               false, cursor.boundary());
+                               false, cursor.boundary());
                
                // some insets are undeletable here
                if (cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET) {
@@ -2738,8 +2748,8 @@ void LyXText::backspace(BufferView * bview)
                if (cursor.pos() < rowLast(row) ||
                    !cursor.par()->isLineSeparator(cursor.pos())) {
                        row->fill(row->fill() + singleWidth(bview,
-                                                           cursor.par(),
-                                                           cursor.pos()));
+                                                           cursor.par(),
+                                                           cursor.pos()));
                }
                
                /* some special code when deleting a newline. This is similar
@@ -2959,52 +2969,47 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset,
        if (cleared) {
                clear_area = true;
        } else if (clear_area) {
-#ifdef WITH_WARNINGS
-#warning Should be fixed with a lyxinset::clear_width(bv, font) function! (Jug)
-#warning Should we not fix this in the Painter, please have a look Lars! (Jug)
-#endif
                int const y = y_offset < 0 ? 0 : y_offset;
                int const h = y_offset < 0 ?
                        row_ptr->height() + y_offset : row_ptr->height();
                int const w = inset_owner ?
-                       inset_owner->width(bview, font) - 2 : ww;
+                       inset_owner->textWidth(bview, true) : ww;
                int const x = x_offset;
                pain.fillRectangle(x, y, w, h, backgroundColor());
        } else if (inset != 0) {
                int h = row_ptr->baseline() - inset->ascent(bview, font);
                // first clear the whole row above the inset!
                if (h > 0) {
-#if 0
                        int const w = (inset_owner ?
-                                inset_owner->width(bview, font) : ww);
-#endif
-                       pain.fillRectangle(x_offset, y_offset, ww, h,
+                                inset_owner->textWidth(bview, true) : ww);
+                       pain.fillRectangle(x_offset, y_offset, w, h,
                                           backgroundColor());
                }
                h += inset->ascent(bview, font) + inset->descent(bview, font);
                // clear the space below the inset!
                if ((row_ptr->height() - h) > 0) {
-#if 0
                        int const w = (inset_owner ?
-                                inset_owner->width(bview, font) : ww);
-#endif
+                                      inset_owner->textWidth(bview, true) : ww);
                        pain.fillRectangle(x_offset, y_offset + h,
-                                          ww, row_ptr->height() - h,
+                                          w, row_ptr->height() - h,
                                           backgroundColor());
                }
                // clear the space behind the inset, if needed
-               if (!inset_owner && !inset->display() && !inset->needFullRow())
-               {
-                       int const w = inset->width(bview, font) + int(x);
-                       pain.fillRectangle(w, y_offset, 
-                                          ww - w, row_ptr->height(),
-                                          backgroundColor());
+               if (!inset->display() && !inset->needFullRow()) {
+                       int const w = (inset_owner ?
+                                      inset_owner->textWidth(bview, true) : ww);
+                       int const xp = int(x) + inset->width(bview, font);
+                       if (w-xp > 0) {
+                               pain.fillRectangle(xp, y_offset,
+                                                  w-xp, row_ptr->height(),
+                                                  backgroundColor());
+                       }
                }
        }
 
        if (selection.set()) {
                int const w = (inset_owner ?
-                              inset_owner->width(bview, font) : ww);
+                              inset_owner->textWidth(bview, true) : ww);
                // selection code
                if (bidi_same_direction) {
                        if (selection.start.row() == row_ptr &&
@@ -3420,7 +3425,7 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset,
                        y_bottom -= lyxfont::ascent('x',
                                                    getFont(bview->buffer(),
                                                            par,
-                                                           par->size() - 1));
+                                                           max(Paragraph::size_type(0), par->size() - 1)));
                        int const w = (inset_owner ?
                                       inset_owner->width(bview, font) : ww);
                        int const xp = static_cast<int>(inset_owner ? x : 0);
@@ -3431,7 +3436,7 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset,
                        y_bottom -= lyxfont::ascent('x',
                                                    getFont(bview->buffer(),
                                                            par,
-                                                           par->size() - 1));
+                                                           max(Paragraph::size_type(0), par->size() - 1)));
                }
 
                // draw an endlabel