]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
some visual feedback for extra vertical space
[lyx.git] / src / text.C
index b71245a4858aff55a92899b1c59e9b669040e1e8..6a80460c7afbf422c5bd3c9c2a251e4770cc7aa2 100644 (file)
@@ -253,7 +253,7 @@ void LyXText::computeBidiTables(Buffer const * buf, Row * row) const
                LyXFont font = row->par()->getFontSettings(buf->params, pos);
                if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
                    font.number() == LyXFont::ON &&
-                   row->par()->getFontSettings(buf->params, lpos-1).number()
+                   row->par()->getFontSettings(buf->params, lpos - 1).number()
                    == LyXFont::ON) {
                        font = row->par()->getFontSettings(buf->params, lpos);
                        is_space = false;
@@ -440,7 +440,7 @@ void LyXText::draw(BufferView * bview, Row const * row,
                        tmpinset->update(bview, font, false);
                        tmpinset->draw(bview, font, offset+row->baseline(), x,
                                       cleared);
-                       if (!need_break_row &&
+                       if (!need_break_row && !inset_owner &&
                            bview->text->status() == CHANGED_IN_DRAW)
                        {
                                if (row->previous() && row->previous()->par() == row->par())
@@ -659,7 +659,7 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
                
        }
        
-       LyXFont const labelfont = getFont(bview->buffer(), row->par(), -2);
+       LyXFont const labelfont = getLabelFont(bview->buffer(), row->par());
        switch (layout.margintype) {
        case MARGIN_DYNAMIC:
                if (!layout.leftmargin.empty()) {
@@ -944,7 +944,7 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
                        ++i;
                        if (i == main_body) {
                                x += lyxfont::width(layout.labelsep,
-                                                   getFont(bview->buffer(), par, -2));
+                                                   getLabelFont(bview->buffer(), par));
                                if (par->isLineSeparator(i - 1))
                                        x-= singleWidth(bview, par, i - 1);
                                int left_margin = labelEnd(bview, row);
@@ -1000,7 +1000,7 @@ int LyXText::fill(BufferView * bview, Row * row, int paper_width) const
 
        while (i <= last) {
                if (main_body > 0 && i == main_body) {
-                       w += lyxfont::width(layout.labelsep, getFont(bview->buffer(), row->par(), -2));
+                       w += lyxfont::width(layout.labelsep, getLabelFont(bview->buffer(), row->par()));
                        if (row->par()->isLineSeparator(i - 1))
                                w -= singleWidth(bview, row->par(), i - 1);
                        int left_margin = labelEnd(bview, row);
@@ -1011,7 +1011,7 @@ int LyXText::fill(BufferView * bview, Row * row, int paper_width) const
                ++i;
        }
        if (main_body > 0 && main_body > last) {
-               w += lyxfont::width(layout.labelsep, getFont(bview->buffer(), row->par(), -2));
+               w += lyxfont::width(layout.labelsep, getLabelFont(bview->buffer(), row->par()));
                if (last >= 0 && row->par()->isLineSeparator(last))
                        w -= singleWidth(bview, row->par(), last);
                int const left_margin = labelEnd(bview, row);
@@ -1059,7 +1059,7 @@ int LyXText::labelFill(BufferView * bview, Row const * row) const
        int fill = 0;
        if (!row->par()->params().labelWidthString().empty()) {
                fill = max(lyxfont::width(row->par()->params().labelWidthString(),
-                                         getFont(bview->buffer(), row->par(), -2)) - w,
+                                         getLabelFont(bview->buffer(), row->par())) - w,
                           0);
        }
        
@@ -1210,11 +1210,11 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const
        // do the assignment below too often.
        LyXFont font = getFont(bview->buffer(), par, row_ptr->pos());
        LyXFont::FONT_SIZE const tmpsize = font.size();
-       font = getFont(bview->buffer(), par, -1);
+       font = getLayoutFont(bview->buffer(), par);
        LyXFont::FONT_SIZE const size = font.size();
        font.setSize(tmpsize);
 
-       LyXFont labelfont = getFont(bview->buffer(), par, -2);
+       LyXFont labelfont = getLabelFont(bview->buffer(), par);
 
        float spacing_val = 1.0;
        if (!row_ptr->par()->params().spacing().isDefault()) {
@@ -1745,12 +1745,12 @@ void LyXText::insertChar(BufferView * bview, char c)
                                      cursor.pos()).number() == LyXFont::ON &&
                              getFont(bview->buffer(),
                                      cursor.par(),
-                                     cursor.pos()-1).number() == LyXFont::ON)
+                                     cursor.pos() - 1).number() == LyXFont::ON)
                            )
-                               Number(bview); // Set current_font.number to OFF
+                               number(bview); // Set current_font.number to OFF
                } else if (isdigit(c) &&
                           real_current_font.isVisibleRightToLeft()) {
-                       Number(bview); // Set current_font.number to ON
+                       number(bview); // Set current_font.number to ON
 
                        if (cursor.pos() > 0) {
                                char const c = cursor.par()->getChar(cursor.pos() - 1);
@@ -1767,7 +1767,7 @@ void LyXText::insertChar(BufferView * bview, char c)
                                           cursor.pos() >= 2 &&
                                           getFont(bview->buffer(),
                                                   cursor.par(),
-                                                  cursor.pos()-2).number() == LyXFont::ON) {
+                                                  cursor.pos() - 2).number() == LyXFont::ON) {
                                        setCharFont(bview->buffer(),
                                                    cursor.par(),
                                                    cursor.pos() - 1,
@@ -2086,7 +2086,7 @@ void LyXText::prepareToPrint(BufferView * bview,
                                textclasslist.Style(bview->buffer()->params.textclass,
                                                    row->par()->getLayout());
                        x += lyxfont::width(layout.labelsep,
-                                           getFont(bview->buffer(), row->par(), -2));
+                                           getLabelFont(bview->buffer(), row->par()));
                        if (main_body-1 <= last)
                                x += fill_label_hfill;
                }
@@ -2264,7 +2264,7 @@ 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
+                                     float & value) const
 {
        if (the_locking_inset) {
                string str = the_locking_inset->selectNextWord(bview, value);
@@ -2295,12 +2295,7 @@ string const LyXText::selectNextWord(BufferView * bview,
        
        // Now, skip until we have real text (will jump paragraphs)
        while ((cursor.par()->size() > cursor.pos()
-              && (!cursor.par()->isLetter(cursor.pos())
-#ifndef NO_LATEX
-                   || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
-                   .latex() == LyXFont::ON
-#endif
-                       )
+              && (!cursor.par()->isLetter(cursor.pos()))
               && (!cursor.par()->isInset(cursor.pos()) ||
                   !cursor.par()->getInset(cursor.pos())->isTextInset()))
               || (cursor.par()->size() == cursor.pos()
@@ -2405,10 +2400,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);
        }
 }
 
@@ -2427,7 +2422,7 @@ void LyXText::deleteWordBackward(BufferView * bview)
               selection.cursor = cursor;
               cursor = tmpcursor;
               setSelection(bview);
-              cutSelection(bview);
+              cutSelection(bview, true, false);
        }
 }
 
@@ -2453,7 +2448,7 @@ void LyXText::deleteLineForward(BufferView * bview)
                if (!selection.set()) {
                        deleteWordForward(bview);
                } else {
-                       cutSelection(bview);
+                       cutSelection(bview, true, false);
                }
        }
 }
@@ -2581,7 +2576,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()) {
@@ -2644,8 +2641,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();
@@ -2658,8 +2654,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
@@ -2675,8 +2671,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);
@@ -2713,13 +2709,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) {
@@ -2743,8 +2739,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
@@ -2964,52 +2960,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 &&
@@ -3083,7 +3074,7 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset,
                                        tmpx += fill_label_hfill +
                                                lyxfont::width(textclasslist.Style(bview->buffer()->params.textclass,
                                                                                   row_ptr->par()->getLayout()).labelsep,
-                                                              getFont(bview->buffer(),row_ptr->par(), -2));
+                                                              getLabelFont(bview->buffer(),row_ptr->par()));
                                        if (row_ptr->par()->isLineSeparator(main_body-1))
                                                tmpx -= singleWidth(bview, row_ptr->par(), main_body-1);
                                }
@@ -3271,7 +3262,7 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset,
                    && (layout.labeltype != LABEL_STATIC
                        || layout.latextype != LATEX_ENVIRONMENT
                        || row_ptr->par()->isFirstInSequence())) {
-                       font = getFont(bview->buffer(), row_ptr->par(), -2);
+                       font = getLabelFont(bview->buffer(), row_ptr->par());
                        if (!row_ptr->par()->getLabelstring().empty()) {
                                tmpx = x;
                                string const tmpstring =
@@ -3320,8 +3311,8 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset,
                           layout.labeltype == LABEL_BIBLIO ||
                           layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
                        if (row_ptr->par()->isFirstInSequence()) {
-                               font = getFont(bview->buffer(),
-                                              row_ptr->par(), -2);
+                               font = getLabelFont(bview->buffer(),
+                                                   row_ptr->par());
                                if (!row_ptr->par()->getLabelstring().empty()) {
                                        string const tmpstring =
                                                row_ptr->par()->getLabelstring();
@@ -3352,7 +3343,7 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset,
                        }
                }
                if (layout.labeltype == LABEL_BIBLIO && row_ptr->par()->bibkey) {
-                       font = getFont(bview->buffer(), row_ptr->par(), -1);
+                       font = getLayoutFont(bview->buffer(), row_ptr->par());
                        if (is_rtl)
                                tmpx = ww - leftMargin(bview, row_ptr)
                                        + lyxfont::width(layout.labelsep, font);
@@ -3475,7 +3466,7 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset,
                        string const tmpstring = textclasslist.
                                Style(bview->buffer()->params.textclass,
                                      layout).endlabelstring();
-                       font = getFont(bview->buffer(), row_ptr->par(), -2);
+                       font = getLabelFont(bview->buffer(), row_ptr->par());
                        int const tmpx = is_rtl ?
                                int(x) - lyxfont::width(tmpstring, font)
                                : ww - rightMargin(bview->buffer(), row_ptr) - row_ptr->fill();
@@ -3503,8 +3494,8 @@ void LyXText::getVisibleRow(BufferView * bview, int y_offset, int x_offset,
                if (main_body > 0 && pos == main_body - 1) {
                        x += fill_label_hfill
                                + lyxfont::width(layout.labelsep,
-                                                getFont(bview->buffer(),
-                                                        row_ptr->par(), -2))
+                                                getLabelFont(bview->buffer(),
+                                                             row_ptr->par()))
                                - singleWidth(bview,
                                              row_ptr->par(),
                                              main_body - 1);
@@ -3601,7 +3592,7 @@ int LyXText::getColumnNearX(BufferView * bview, Row * row, int & x,
                if (main_body > 0 && c == main_body-1) {
                        tmpx += fill_label_hfill +
                                lyxfont::width(layout.labelsep,
-                                              getFont(bview->buffer(), row->par(), -2));
+                                              getLabelFont(bview->buffer(), row->par()));
                        if (row->par()->isLineSeparator(main_body - 1))
                                tmpx -= singleWidth(bview, row->par(), main_body-1);
                }