]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.C
use more specific smart_ptr headers
[lyx.git] / src / insets / insettext.C
index 2919ea6d7230827c2f83dd98a046dad1d7f66e35..a433a3f35ca85a425420783f9a22254771beb653 100644 (file)
@@ -451,15 +451,35 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                first += row->height();
                row = row->next();
        }
-       if (y_offset < 0)
-               y_offset = y;
-       lt->first_y = first;
+       if (y_offset < 0) {
+               lt->first_y = -y_offset;
+               first = y;
+               y_offset = 0;
+       } else {
+               lt->first_y = first;
+               first = 0;
+       }
        if (cleared || (need_update&(INIT|FULL))) {
-               int yf = y_offset;
+               int yf = y_offset + first;
                y = 0;
                while ((row != 0) && (yf < ph)) {
-                       lt->getVisibleRow(bv, y+y_offset, int(x), row,
-                                               y+first, cleared);
+                       lt->getVisibleRow(bv, y + y_offset + first, int(x),
+                                         row, y + lt->first_y, cleared);
+                       if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
+                               lt->need_break_row = row;
+                               lt->fullRebreak(bv);
+                               lt->setCursor(bv, lt->cursor.par(),
+                                             lt->cursor.pos());
+                               if (lt->selection.set()) {
+                                       lt->setCursor(bv, lt->selection.start,
+                                                     lt->selection.start.par(),
+                                                     lt->selection.start.pos());
+                                       lt->setCursor(bv, lt->selection.end,
+                                                     lt->selection.end.par(),
+                                                     lt->selection.end.pos());
+                               }
+                               break;
+                       }
                        y += row->height();
                        yf += row->height();
                        row = row->next();
@@ -675,9 +695,14 @@ void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
                lt = getLyXText(bv);
                clear = true;
        }
-       if (!checkAndActivateInset(bv, x, tmp_y, button))
+       // we put here -1 and not button as now the button in the
+       // edit call should not be needed we will fix this in 1.3.x
+       // cycle hopefully (Jug 20020509)
+       if (!checkAndActivateInset(bv, x, tmp_y, -1)) {
                lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
                                            y + insetAscent);
+               lt->cursor.x_fix(lt->cursor.x());
+       }
        lt->clearSelection();
        finishUndo();
        // If the inset is empty set the language of the current font to the
@@ -756,15 +781,21 @@ void InsetText::insetUnlock(BufferView * bv)
        if (the_locking_inset) {
                the_locking_inset->insetUnlock(bv);
                the_locking_inset = 0;
+               updateLocal(bv, CURSOR_PAR, false);
        }
        hideInsetCursor(bv);
        no_selection = true;
        locked = false;
-       int code;
+       int code = NONE;
+#if 0
        if (drawFrame_ == LOCKED)
                code = CURSOR|CLEAR_FRAME;
        else
                code = CURSOR;
+#else
+       if (drawFrame_ == LOCKED)
+               code = CLEAR_FRAME;
+#endif
        bool clear = false;
        if (!lt) {
                lt = getLyXText(bv);
@@ -786,9 +817,48 @@ void InsetText::insetUnlock(BufferView * bv)
        }
        if (clear)
                lt = 0;
+#if 0
        updateLocal(bv, code, false);
+#else
+       if (code != NONE)
+               setUpdateStatus(bv, code);
+#endif
 }
 
+
+void InsetText::lockInset(BufferView * bv)
+{
+       locked = true;
+       the_locking_inset = 0;
+       inset_pos = inset_x = inset_y = 0;
+       inset_boundary = false;
+       inset_par = 0;
+       old_par = 0;
+       bool clear = false;
+       if (!lt) {
+               lt = getLyXText(bv);
+               clear = true;
+       }
+       lt->setCursor(bv, par, 0);
+       lt->clearSelection();
+       finishUndo();
+       // If the inset is empty set the language of the current font to the
+       // language to the surronding text (if different).
+       if (par->size() == 0 && !par->next() &&
+               bv->getParentLanguage(this) != lt->current_font.language()) {
+               LyXFont font(LyXFont::ALL_IGNORE);
+               font.setLanguage(bv->getParentLanguage(this));
+               setFont(bv, font, false);
+       }
+       if (clear)
+               lt = 0;
+       int code = CURSOR;
+       if (drawFrame_ == LOCKED)
+               code = CURSOR|DRAW_FRAME;
+       setUpdateStatus(bv, code);
+}
+
+
 void InsetText::lockInset(BufferView * bv, UpdatableInset * inset)
 {
        the_locking_inset = inset;
@@ -932,6 +1002,9 @@ void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
        mouse_x = x;
        mouse_y = y;
 
+       if (!locked)
+               lockInset(bv);
+
        int tmp_x = x - drawTextXOffset;
        int tmp_y = y + insetAscent - getLyXText(bv)->first_y;
        Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y);
@@ -1082,6 +1155,7 @@ void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state)
        hideInsetCursor(bv);
        LyXCursor cur = lt->cursor;
        lt->setCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent);
+       lt->cursor.x_fix(lt->cursor.x());
        if (cur == lt->cursor) {
                if (clear)
                        lt = 0;
@@ -1305,6 +1379,9 @@ InsetText::localDispatch(BufferView * bv,
                } else {
                        lt->insertStringAsLines(bv, clip);
                }
+               // bug 393
+               lt->clearSelection();
                updwhat = CURSOR_PAR;
                updflag = true;
                break;
@@ -1322,6 +1399,8 @@ InsetText::localDispatch(BufferView * bv,
                setUndo(bv, Undo::INSERT,
                        lt->cursor.par(), lt->cursor.par()->next());
                lt->pasteSelection(bv);
+               // bug 393
+               lt->clearSelection();
                updwhat = CURSOR_PAR;
                updflag = true;
        }
@@ -1472,10 +1551,10 @@ InsetText::localDispatch(BufferView * bv,
 }
 
 
-int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
+int InsetText::latex(Buffer const * buf, ostream & os, bool moving_arg, bool) const
 {
        TexRow texrow;
-       buf->latexParagraphs(os, par, 0, texrow);
+       buf->latexParagraphs(os, par, 0, texrow, moving_arg);
        return texrow.rows();
 }
 
@@ -1700,19 +1779,18 @@ int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
 }
 
 
-void InsetText::getCursorPos(BufferView * bv,
-                            int & x, int & y) const
+void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const
 {
        if (the_locking_inset) {
                the_locking_inset->getCursorPos(bv, x, y);
                return;
        }
-       x = cx(bv);
-       y = cy(bv);
+       x = cx(bv) - top_x - TEXT_TO_INSET_OFFSET;
+       y = cy(bv) - TEXT_TO_INSET_OFFSET;
 }
 
 
-unsigned int InsetText::insetInInsetY()
+int InsetText::insetInInsetY() const
 {
        if (!the_locking_inset)
                return 0;
@@ -1754,7 +1832,7 @@ void InsetText::showInsetCursor(BufferView * bv, bool show)
                int const asc = lyxfont::maxAscent(font);
                int const desc = lyxfont::maxDescent(font);
 
-               bv->fitLockedInsetCursor(cx(bv), ciy(bv), asc, desc);
+               bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
                if (show)
                        bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
                setCursorVisible(true);
@@ -1794,9 +1872,9 @@ UpdatableInset::RESULT
 InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
 {
        if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
-               return moveLeftIntern(bv, false, activate_inset, selecting);
+               return moveLeftIntern(bv, true, activate_inset, selecting);
        else
-               return moveRightIntern(bv, false, activate_inset, selecting);
+               return moveRightIntern(bv, true, activate_inset, selecting);
 }
 
 
@@ -1804,19 +1882,19 @@ UpdatableInset::RESULT
 InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
 {
        if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
-               return moveRightIntern(bv, true, activate_inset, selecting);
+               return moveRightIntern(bv, false, activate_inset, selecting);
        else
-               return moveLeftIntern(bv, true, activate_inset, selecting);
+               return moveLeftIntern(bv, false, activate_inset, selecting);
 }
 
 
 UpdatableInset::RESULT
-InsetText::moveRightIntern(BufferView * bv, bool behind,
+InsetText::moveRightIntern(BufferView * bv, bool front,
                           bool activate_inset, bool selecting)
 {
        if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
                return FINISHED_RIGHT;
-       if (activate_inset && checkAndActivateInset(bv, behind))
+       if (activate_inset && checkAndActivateInset(bv, front))
                return DISPATCHED;
        getLyXText(bv)->cursorRight(bv);
        if (!selecting)
@@ -1826,7 +1904,7 @@ InsetText::moveRightIntern(BufferView * bv, bool behind,
 
 
 UpdatableInset::RESULT
-InsetText::moveLeftIntern(BufferView * bv, bool behind,
+InsetText::moveLeftIntern(BufferView * bv, bool front,
                          bool activate_inset, bool selecting)
 {
        if (!cpar(bv)->previous() && (cpos(bv) <= 0))
@@ -1834,7 +1912,7 @@ InsetText::moveLeftIntern(BufferView * bv, bool behind,
        getLyXText(bv)->cursorLeft(bv);
        if (!selecting)
                getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
-       if (activate_inset && checkAndActivateInset(bv, behind))
+       if (activate_inset && checkAndActivateInset(bv, front))
                return DISPATCHED;
        return DISPATCHED_NOUPDATE;
 }
@@ -1973,27 +2051,14 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
 }
 
 
-bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
+bool InsetText::checkAndActivateInset(BufferView * bv, bool front)
 {
        if (cpar(bv)->isInset(cpos(bv))) {
-               unsigned int x;
-               unsigned int y;
                Inset * inset =
                        static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
                if (!isHighlyEditableInset(inset))
                        return false;
-               LyXFont const font =
-                       getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
-               if (behind) {
-                       x = inset->width(bv, font);
-                       y = font.isRightToLeft() ? 0 : inset->descent(bv, font);
-               } else {
-                       x = 0;
-                       y = font.isRightToLeft() ? inset->descent(bv, font) : 0;
-               }
-               //inset_x = cx(bv) - top_x + drawTextXOffset;
-               //inset_y = cy(bv) + drawTextYOffset;
-               inset->edit(bv, x, y, 0);
+               inset->edit(bv, front);
                if (!the_locking_inset)
                        return false;
                updateLocal(bv, CURSOR, false);
@@ -2010,7 +2075,12 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
        int dummyx = x;
        int dummyy = y + insetAscent;
        Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy);
-
+       // we only do the edit() call if the inset was hit by the mouse
+       // or if it is a highly editable inset. So we should call this
+       // function from our own edit with button < 0.
+       if (button < 0 && !isHighlyEditableInset(inset))
+               return false;
+       
        if (inset) {
                if (x < 0)
                        x = insetWidth;
@@ -2682,7 +2752,7 @@ 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))