]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
static_cast-based key/mouse-state. Kill insetKeyPress.
[lyx.git] / src / insets / insettabular.C
index b4496156bc563170accf8f75e60dc3f75e8be368..8ac934c79d4ecf2232f02bff00e36f2cd8f31e6d 100644 (file)
 #include "lyxfunc.h"
 #include "debug.h"
 #include "LaTeXFeatures.h"
-#include "Painter.h"
-#include "font.h"
+#include "frontends/Painter.h"
+#include "frontends/font_metrics.h"
 #include "lyxtext.h"
-#include "LyXView.h"
+#include "frontends/LyXView.h"
 #include "insets/insettext.h"
 #include "debug.h"
 #include "gettext.h"
@@ -450,8 +450,8 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
                          on_off ? Painter::line_onoffdash : Painter::line_solid);
        }
        on_off = !tabular->BottomLine(cell);
-       pain.line(x,baseline +  tabular->GetDescentOfRow(row),
-                 x2, baseline +  tabular->GetDescentOfRow(row),
+       pain.line(x, baseline + tabular->GetDescentOfRow(row),
+                 x2, baseline + tabular->GetDescentOfRow(row),
                  on_off ? LColor::tabularonoffline : LColor::tabularline,
                  on_off ? Painter::line_onoffdash : Painter::line_solid);
        if (!tabular->LeftAlreadyDrawed(cell)) {
@@ -491,8 +491,8 @@ void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
 
        if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
                int w = tabular->GetWidthOfColumn(cell);
-               int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
-               pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
+               int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
+               pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
                                   w, h, LColor::selection);
        }
 }
@@ -530,8 +530,10 @@ void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
        case INIT:
        case FULL:
        case CELL:
-               if (calculate_dimensions_of_cells(bv, font, false))
+               if (calculate_dimensions_of_cells(bv, font, false)) {
                        need_update = INIT;
+                       resetPos(bv);
+               }
                break;
        case SELECTION:
                need_update = FULL;
@@ -549,7 +551,7 @@ string const InsetTabular::editMessage() const
 }
 
 
-void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
+void InsetTabular::edit(BufferView * bv, int x, int y, mouse_button::state button)
 {
        UpdatableInset::edit(bv, x, y, button);
 
@@ -564,7 +566,7 @@ void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
        setPos(bv, x, y);
        clearSelection();
        finishUndo();
-       if (insetHit(bv, x, y) && (button != 3)) {
+       if (insetHit(bv, x, y) && (button != mouse_button::button3)) {
                activateCellInsetAbs(bv, x, y, button);
        }
 }
@@ -597,6 +599,7 @@ void InsetTabular::insetUnlock(BufferView * bv)
 {
        if (the_locking_inset) {
                the_locking_inset->insetUnlock(bv);
+               updateLocal(bv, CELL, false);
                the_locking_inset = 0;
        }
        hideInsetCursor(bv);
@@ -686,7 +689,6 @@ bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                return false;
        if (the_locking_inset == inset) {
                the_locking_inset->insetUnlock(bv);
-               the_locking_inset = 0;
 #ifdef WITH_WARNINGS
 #warning fix scrolling when cellinset has requested a scroll (Jug)!!!
 #endif
@@ -695,6 +697,8 @@ bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                        scroll(bv, 0.0F);
 #endif
                updateLocal(bv, CELL, false);
+               // this has to be here otherwise we don't redraw the cell!
+               the_locking_inset = 0;
 //             showInsetCursor(bv, false);
                return true;
        }
@@ -729,7 +733,7 @@ bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
 }
 
 
-unsigned int InsetTabular::insetInInsetY()
+int InsetTabular::insetInInsetY() const
 {
        if (!the_locking_inset)
                return 0;
@@ -762,9 +766,9 @@ bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
 }
 
 
-void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
+void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, mouse_button::state button)
 {
-       if (hasSelection() && (button == 3))
+       if (hasSelection() && (button == mouse_button::button3))
                return;
 
        if (hasSelection()) {
@@ -776,6 +780,12 @@ void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
        int const orow = actrow;
 
        hideInsetCursor(bv);
+       if (!locked) {
+               locked = true;
+               the_locking_inset = 0;
+               inset_x = 0;
+               inset_y = 0;
+       }
        setPos(bv, x, y);
        if (actrow != orow)
                updateLocal(bv, NONE, false);
@@ -784,6 +794,7 @@ void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
        if (button == 3) {
                if ((ocell != actcell) && the_locking_inset) {
                        the_locking_inset->insetUnlock(bv);
+                       updateLocal(bv, CELL, false);
                        the_locking_inset = 0;
                }
                showInsetCursor(bv);
@@ -801,20 +812,20 @@ void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
                return;
        } else if (the_locking_inset) {
                the_locking_inset->insetUnlock(bv);
+               updateLocal(bv, CELL, false);
+               the_locking_inset = 0;
        }
-       the_locking_inset = 0;
-       if (button == 2) {
+       if (button == mouse_button::button2) {
                localDispatch(bv, LFUN_PASTESELECTION, "paragraph");
                return;
        }
        if (inset_hit && bv->theLockingInset()) {
-               // only activate the Inset so that no internal inset is hit
-               // by this call. It should be only hit by the insetButtonPress call.
-               if (activateCellInsetAbs(bv, 0, 0, 0))
-                       the_locking_inset->insetButtonPress(bv,
-                                                           x - inset_x,
-                                                           y - inset_y,
-                                                           button);
+               if (!bv->lockInset(static_cast<UpdatableInset*>(tabular->GetCellInset(actcell)))) {
+                       lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
+                       return;
+               }
+               the_locking_inset->insetButtonPress(
+                       bv, x - inset_x, y - inset_y, button);
                return;
        }
        showInsetCursor(bv);
@@ -822,13 +833,13 @@ void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, int button)
 
 
 bool InsetTabular::insetButtonRelease(BufferView * bv,
-                                     int x, int y, int button)
+                                     int x, int y, mouse_button::state button)
 {
        bool ret = false;
        if (the_locking_inset)
                ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
                                                                                                        y - inset_y, button);
-       if (button == 3 && !ret) {
+       if (button == mouse_button::button3 && !ret) {
                bv->owner()->getDialogs()->showTabular(this);
                return true;
        }
@@ -836,7 +847,7 @@ bool InsetTabular::insetButtonRelease(BufferView * bv,
 }
 
 
-void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
+void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, mouse_button::state button)
 {
        if (the_locking_inset) {
                the_locking_inset->insetMotionNotify(bv,
@@ -860,15 +871,6 @@ void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, int button)
 }
 
 
-void InsetTabular::insetKeyPress(XKeyEvent * xke)
-{
-       if (the_locking_inset) {
-               the_locking_inset->insetKeyPress(xke);
-               return;
-       }
-}
-
-
 UpdatableInset::RESULT
 InsetTabular::localDispatch(BufferView * bv, kb_action action,
                            string const & arg)
@@ -1417,10 +1419,10 @@ void InsetTabular::toggleInsetCursor(BufferView * bv)
        }
 
        LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
-
-       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
@@ -1435,9 +1437,9 @@ void InsetTabular::showInsetCursor(BufferView * bv, bool show)
                return;
        if (!isCursorVisible()) {
                LyXFont font; // = GetFont(par, cursor.pos);
-
-               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(cursor_.x(), cursor_.y(), asc, desc);
                if (show)
                        bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
@@ -1465,9 +1467,11 @@ void InsetTabular::fitInsetCursor(BufferView * bv) const
                return;
        }
        LyXFont font;
+       
+       int const asc = font_metrics::maxAscent(font);
+       int const desc = font_metrics::maxDescent(font);
+       resetPos(bv);
 
-       int const asc = lyxfont::maxAscent(font);
-       int const desc = lyxfont::maxDescent(font);
        if (bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc))
                need_update = FULL;
 }
@@ -1622,7 +1626,7 @@ UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
        if (!moved)
                return FINISHED;
        if (lock) {       // behind the inset
-               if (activateCellInset(bv, 0, 0, 0, true))
+               if (activateCellInset(bv, 0, 0, mouse_button::none, true))
                        return DISPATCHED;
        }
        resetPos(bv);
@@ -1694,7 +1698,7 @@ bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
        if (lock) {
                bool rtl = tabular->GetCellInset(actcell)->paragraph()->
                        isRightToLeftPar(bv->buffer()->params);
-               activateCellInset(bv, 0, 0, 0, !rtl);
+               activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
        }
        resetPos(bv);
        return true;
@@ -1723,7 +1727,7 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
        if (lock) {
                bool rtl = tabular->GetCellInset(actcell)->paragraph()->
                        isRightToLeftPar(bv->buffer()->params);
-               activateCellInset(bv, 0, 0, 0, !rtl);
+               activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
        }
        resetPos(bv);
        return true;
@@ -1762,6 +1766,8 @@ void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
                }
                if (!frozen)
                        unFreezeUndo();
+               if (selectall)
+                       clearSelection();
                updateLocal(bv, INIT, true);
        }
        if (the_locking_inset)
@@ -2155,7 +2161,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
 }
 
 
-bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
+bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button::state button,
                                     bool behind)
 {
        UpdatableInset * inset =
@@ -2176,7 +2182,7 @@ bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, int button,
 
 
 bool InsetTabular::activateCellInsetAbs(BufferView * bv, int x, int y,
-                                       int button)
+                                       mouse_button::state button)
 {
        inset_x = cursor_.x()
                - top_x + tabular->GetBeginningOfTextInCell(actcell);
@@ -2680,7 +2686,7 @@ InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
        // otherwise we have to lock the next inset and ask for it's selecttion
        UpdatableInset * inset =
                static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
-       inset->edit(bv, 0,  0, 0);
+       inset->edit(bv, 0,  0, mouse_button::none);
        string const str(selectNextWordInt(bv, value));
        nodraw(false);
        if (!str.empty())
@@ -2815,7 +2821,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
 {
        if (buf.length() <= 0)
                return true;
-       
+
        int cols = 1;
        int rows = 1;
        int maxCols = 1;