]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.C
move inset related stuff from src/graphics to src/inset/
[lyx.git] / src / insets / insettext.C
index 27db48df81a157b2eeb6efcca79b53ceb3fe6b3c..63cf4106b52f9b935a5ef49f679dfd4b3884bfef 100644 (file)
 #include "lyxfont.h"
 #include "commandtags.h"
 #include "buffer.h"
-#include "LyXView.h"
+#include "frontends/LyXView.h"
 #include "BufferView.h"
 #include "lyxtextclasslist.h"
 #include "LaTeXFeatures.h"
-#include "Painter.h"
+#include "frontends/Painter.h"
 #include "lyxtext.h"
 #include "lyxcursor.h"
 #include "CutAndPaste.h"
-#include "font.h"
+#include "frontends/font_metrics.h"
 #include "LColor.h"
 #include "lyxrow.h"
 #include "lyxrc.h"
 #include "intl.h"
 #include "trans_mgr.h"
-#include "lyxscreen.h"
+#include "frontends/screen.h"
 #include "gettext.h"
 #include "lyxfunc.h"
 #include "ParagraphParameters.h"
@@ -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();
@@ -655,7 +675,7 @@ string const InsetText::editMessage() const
 }
 
 
-void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
+void InsetText::edit(BufferView * bv, int x, int y, mouse_button::state button)
 {
        UpdatableInset::edit(bv, x, y, button);
 
@@ -675,7 +695,11 @@ 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)
+       // FIXME: GUII I've changed this to none: probably WRONG
+       if (!checkAndActivateInset(bv, x, tmp_y, mouse_button::none)) {
                lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
                                            y + insetAscent);
                lt->cursor.x_fix(lt->cursor.x());
@@ -763,7 +787,7 @@ void InsetText::insetUnlock(BufferView * bv)
        hideInsetCursor(bv);
        no_selection = true;
        locked = false;
-       int code;
+       int code = NONE;
 #if 0
        if (drawFrame_ == LOCKED)
                code = CURSOR|CLEAR_FRAME;
@@ -797,7 +821,8 @@ void InsetText::insetUnlock(BufferView * bv)
 #if 0
        updateLocal(bv, code, false);
 #else
-       setUpdateStatus(bv, code);
+       if (code != NONE)
+               setUpdateStatus(bv, code);
 #endif
 }
 
@@ -970,7 +995,8 @@ bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
 }
 
 
-void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
+void InsetText::insetButtonPress(BufferView * bv, 
+       int x, int y, mouse_button::state button)
 {
        no_selection = true;
 
@@ -1030,9 +1056,9 @@ void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
                        return;
                }
        }
-       if (!inset) { // && (button == 2)) {
+       if (!inset) { // && (button == mouse_button::button2)) {
                bool paste_internally = false;
-               if ((button == 2) && getLyXText(bv)->selection.set()) {
+               if ((button == mouse_button::button2) && getLyXText(bv)->selection.set()) {
                        localDispatch(bv, LFUN_COPY, "");
                        paste_internally = true;
                }
@@ -1068,7 +1094,7 @@ void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
                // Insert primary selection with middle mouse
                // if there is a local selection in the current buffer,
                // insert this
-               if (button == 2) {
+               if (button == mouse_button::button2) {
                        if (paste_internally)
                                localDispatch(bv, LFUN_PASTE, "");
                        else
@@ -1082,7 +1108,8 @@ void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
 }
 
 
-bool InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
+bool InsetText::insetButtonRelease(BufferView * bv, 
+       int x, int y, mouse_button::state button)
 {
        no_selection = true;
        if (the_locking_inset) {
@@ -1112,7 +1139,7 @@ bool InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
 }
 
 
-void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state)
+void InsetText::insetMotionNotify(BufferView * bv, int x, int y, mouse_button::state state)
 {
        if (the_locking_inset) {
                the_locking_inset->insetMotionNotify(bv, x - inset_x,
@@ -1149,15 +1176,6 @@ void InsetText::insetMotionNotify(BufferView * bv, int x, int y, int state)
 }
 
 
-void InsetText::insetKeyPress(XKeyEvent * xke)
-{
-       if (the_locking_inset) {
-               the_locking_inset->insetKeyPress(xke);
-               return;
-       }
-}
-
-
 UpdatableInset::RESULT
 InsetText::localDispatch(BufferView * bv,
                         kb_action action, string const & arg)
@@ -1355,6 +1373,9 @@ InsetText::localDispatch(BufferView * bv,
                } else {
                        lt->insertStringAsLines(bv, clip);
                }
+               // bug 393
+               lt->clearSelection();
                updwhat = CURSOR_PAR;
                updflag = true;
                break;
@@ -1372,6 +1393,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;
        }
@@ -1522,10 +1545,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();
 }
 
@@ -1779,9 +1802,9 @@ void InsetText::toggleInsetCursor(BufferView * bv)
 
        LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
 
-       int const asc = lyxfont::maxAscent(font);
-       int const desc = lyxfont::maxDescent(font);
-
+       int const asc = font_metrics::maxAscent(font);
+       int const desc = font_metrics::maxDescent(font);
+  
        if (isCursorVisible())
                bv->hideLockedInsetCursor();
        else
@@ -1799,9 +1822,9 @@ void InsetText::showInsetCursor(BufferView * bv, bool show)
        if (!isCursorVisible()) {
                LyXFont const font =
                        getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
-
-               int const asc = lyxfont::maxAscent(font);
-               int const desc = lyxfont::maxDescent(font);
+       
+               int const asc = font_metrics::maxAscent(font);
+               int const desc = font_metrics::maxDescent(font);
 
                bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
                if (show)
@@ -1830,9 +1853,9 @@ void InsetText::fitInsetCursor(BufferView * bv) const
        }
        LyXFont const font =
                getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
-
-       int const asc = lyxfont::maxAscent(font);
-       int const desc = lyxfont::maxDescent(font);
+       
+       int const asc = font_metrics::maxAscent(font);
+       int const desc = font_metrics::maxDescent(font);
 
        if (bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc))
                need_update |= FULL;
@@ -1843,9 +1866,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);
 }
 
 
@@ -1853,19 +1876,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)
@@ -1875,7 +1898,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))
@@ -1883,7 +1906,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;
 }
@@ -2022,27 +2045,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);
@@ -2053,13 +2063,20 @@ bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
 
 
 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
-                                     int button)
+                                     mouse_button::state button)
 {
        x -= drawTextXOffset;
        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.
+       // FIXME: GUII jbl. I've changed this to ::none for now which is probably
+       // WRONG
+       if (button == mouse_button::none && !isHighlyEditableInset(inset))
+               return false;
+       
        if (inset) {
                if (x < 0)
                        x = insetWidth;
@@ -2484,7 +2501,7 @@ void InsetText::clearInset(BufferView * bv, int baseline, bool & cleared) const
        if ((top_x + drawTextXOffset + w) > pain.paperWidth())
                w = pain.paperWidth();
 //     w -= TEXT_TO_INSET_OFFSET;
-       pain.fillRectangle(top_x, ty, w+1, h+1, backgroundColor());
+       pain.fillRectangle(top_x + 1, ty + 1, w - 1, h - 1, backgroundColor());
        cleared = true;
        need_update = FULL;
        frame_is_visible = false;
@@ -2731,7 +2748,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))