]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
Make it compile when USE_BOOST_FORMAT is unset
[lyx.git] / src / insets / insettabular.C
index e5f7ad7ab5baa0dc174c91a3e27254801eb02a64..fbe8c938e1247cca0100f21a48aabd902dc14082 100644 (file)
@@ -1,11 +1,11 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file insettabular.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Jürgen Vigna
  *
- *           Copyright 2001 The LyX Team.
- *
- * ======================================================
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
@@ -86,6 +86,7 @@ TabularFeature tabularFeature[] =
        { LyXTabular::ALIGN_LEFT, "align-left" },
        { LyXTabular::ALIGN_RIGHT, "align-right" },
        { LyXTabular::ALIGN_CENTER, "align-center" },
+       { LyXTabular::ALIGN_BLOCK, "align-block" },
        { LyXTabular::VALIGN_TOP, "valign-top" },
        { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
        { LyXTabular::VALIGN_CENTER, "valign-center" },
@@ -771,18 +772,19 @@ bool InsetTabular::insertInset(BufferView * bv, Inset * inset)
 }
 
 
-void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, mouse_button::state button)
+void InsetTabular::lfunMousePress(FuncRequest const & cmd)
 {
-       if (hasSelection() && (button == mouse_button::button3))
+       if (hasSelection() && cmd.button() == mouse_button::button3)
                return;
 
        if (hasSelection()) {
                clearSelection();
-               updateLocal(bv, SELECTION, false);
+               updateLocal(cmd.view(), SELECTION, false);
        }
 
        int const ocell = actcell;
        int const orow = actrow;
+       BufferView * bv = cmd.view();
 
        hideInsetCursor(bv);
        if (!locked) {
@@ -791,12 +793,12 @@ void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, mouse_button:
                inset_x = 0;
                inset_y = 0;
        }
-       setPos(bv, x, y);
+       setPos(bv, cmd.x, cmd.y);
        if (actrow != orow)
                updateLocal(bv, NONE, false);
        clearSelection();
 #if 0
-       if (button == 3) {
+       if (cmd.button() == mouse_button::button3) {
                if ((ocell != actcell) && the_locking_inset) {
                        the_locking_inset->insetUnlock(bv);
                        updateLocal(bv, CELL, false);
@@ -807,65 +809,77 @@ void InsetTabular::insetButtonPress(BufferView * bv, int x, int y, mouse_button:
        }
 #endif
 
-       bool const inset_hit = insetHit(bv, x, y);
+       bool const inset_hit = insetHit(bv, cmd.x, cmd.y);
 
        if ((ocell == actcell) && the_locking_inset && inset_hit) {
                resetPos(bv);
-               the_locking_inset->insetButtonPress(bv,
-                                                   x - inset_x, y - inset_y,
-                                                   button);
+               FuncRequest cmd1 = cmd;
+               cmd1.x -= inset_x;
+               cmd1.y -= inset_y;
+               the_locking_inset->localDispatch(cmd1);
                return;
-       } else if (the_locking_inset) {
+       }
+
+       if (the_locking_inset) {
                the_locking_inset->insetUnlock(bv);
                updateLocal(bv, CELL, false);
                the_locking_inset = 0;
        }
-       if (button == mouse_button::button2) {
-               localDispatch(bv, FuncRequest(LFUN_PASTESELECTION, "paragraph"));
+
+       if (cmd.button() == mouse_button::button2) {
+               localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
                return;
        }
+
        if (inset_hit && bv->theLockingInset()) {
-               if (!bv->lockInset(static_cast<UpdatableInset*>(tabular->GetCellInset(actcell)))) {
+               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);
+               FuncRequest cmd1 = cmd;
+               cmd1.x -= inset_x;
+               cmd1.y -= inset_y;
+               the_locking_inset->localDispatch(cmd1);
                return;
        }
        showInsetCursor(bv);
 }
 
 
-bool InsetTabular::insetButtonRelease(BufferView * bv,
-                                     int x, int y, mouse_button::state button)
+bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
 {
        bool ret = false;
-       if (the_locking_inset)
-               ret = the_locking_inset->insetButtonRelease(bv, x - inset_x,
-                                                                                                       y - inset_y, button);
-       if (button == mouse_button::button3 && !ret) {
-               bv->owner()->getDialogs().showTabular(this);
+       if (the_locking_inset) {
+               FuncRequest cmd1 = cmd;
+               cmd1.x -= inset_x;
+               cmd1.y -= inset_y;
+               ret = the_locking_inset->localDispatch(cmd1);
+       }
+       if (cmd.button() == mouse_button::button3 && !ret) {
+               cmd.view()->owner()->getDialogs().showTabular(this);
                return true;
        }
        return ret;
 }
 
 
-void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, mouse_button::state button)
+void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
 {
        if (the_locking_inset) {
-               the_locking_inset->insetMotionNotify(bv,
-                                                    x - inset_x,
-                                                    y - inset_y,
-                                                    button);
+               FuncRequest cmd1 = cmd;
+               cmd1.x -= inset_x;
+               cmd1.y -= inset_y;
+               the_locking_inset->localDispatch(cmd1);
                return;
        }
 
+       BufferView * bv = cmd.view();
        hideInsetCursor(bv);
        int const old_cell = actcell;
 
-       setPos(bv, x, y);
+       setPos(bv, cmd.x, cmd.y);
        if (!hasSelection()) {
                setSelection(actcell, actcell);
                updateLocal(bv, SELECTION, false);
@@ -877,20 +891,20 @@ void InsetTabular::insetMotionNotify(BufferView * bv, int x, int y, mouse_button
 }
 
 
-UpdatableInset::RESULT
-InsetTabular::localDispatch(BufferView * bv, FuncRequest const & ev)
+Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
 {
        // We need to save the value of the_locking_inset as the call to
-       // the_locking_inset->LocalDispatch might unlock it.
+       // the_locking_inset->localDispatch might unlock it.
        old_locking_inset = the_locking_inset;
-       UpdatableInset::RESULT result =
-               UpdatableInset::localDispatch(bv, ev);
+       RESULT result = UpdatableInset::localDispatch(cmd);
+
+       BufferView * bv = cmd.view();
        if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
                resetPos(bv);
                return result;
        }
 
-       if (ev.action < 0 && ev.argument.empty())
+       if (cmd.action < 0 && cmd.argument.empty())
                return FINISHED;
 
        bool hs = hasSelection();
@@ -899,12 +913,23 @@ InsetTabular::localDispatch(BufferView * bv, FuncRequest const & ev)
        // this one have priority over the locked InsetText, if we're not already
        // inside another tabular then that one get's priority!
        if (getFirstLockingInsetOfType(Inset::TABULAR_CODE) == this) {
-               switch (ev.action) {
+               switch (cmd.action) {
+               case LFUN_MOUSE_PRESS:
+                       lfunMousePress(cmd);
+                       return DISPATCHED;
+
+               case LFUN_MOUSE_MOTION:
+                       lfunMouseMotion(cmd);
+                       return DISPATCHED;
+
+               case LFUN_MOUSE_RELEASE:
+                       return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
+
                case LFUN_SHIFT_TAB:
                case LFUN_TAB:
                        hideInsetCursor(bv);
                        unlockInsetInInset(bv, the_locking_inset);
-                       if (ev.action == LFUN_TAB)
+                       if (cmd.action == LFUN_TAB)
                                moveNextCell(bv, old_locking_inset != 0);
                        else
                                movePrevCell(bv, old_locking_inset != 0);
@@ -922,10 +947,10 @@ InsetTabular::localDispatch(BufferView * bv, FuncRequest const & ev)
                }
        }
 
-       kb_action action = ev.action;
-       string    arg    = ev.argument;
+       kb_action action = cmd.action;
+       string    arg    = cmd.argument;
        if (the_locking_inset) {
-               result = the_locking_inset->localDispatch(bv, ev);
+               result = the_locking_inset->localDispatch(cmd);
                if (result == DISPATCHED_NOUPDATE) {
                        int sc = scroll();
                        resetPos(bv);
@@ -1102,6 +1127,7 @@ InsetTabular::localDispatch(BufferView * bv, FuncRequest const & ev)
        case LFUN_WORDLEFTSEL:
        case LFUN_WORDRIGHT:
        case LFUN_WORDRIGHTSEL:
+       case LFUN_WORDSEL:
        case LFUN_DOWN_PARAGRAPH:
        case LFUN_DOWN_PARAGRAPHSEL:
        case LFUN_UP_PARAGRAPH:
@@ -1251,7 +1277,7 @@ InsetTabular::localDispatch(BufferView * bv, FuncRequest const & ev)
                        case LFUN_DEFAULT:
                        case LFUN_UNDERLINE:
                        case LFUN_FONT_SIZE:
-                               if (bv->dispatch(FuncRequest(action, arg)))
+                               if (bv->dispatch(FuncRequest(bv, action, arg)))
                                        result = DISPATCHED;
                                break;
                        default:
@@ -1266,7 +1292,7 @@ InsetTabular::localDispatch(BufferView * bv, FuncRequest const & ev)
                if (activateCellInset(bv)) {
                        // reset need_update setted in above function!
                        need_update = NONE;
-                       result = the_locking_inset->localDispatch(bv, FuncRequest(action, arg));
+                       result = the_locking_inset->localDispatch(FuncRequest(bv, action, arg));
                        if ((result == UNDISPATCHED) || (result >= FINISHED)) {
                                unlockInsetInInset(bv, the_locking_inset);
                                nodraw(false);
@@ -1538,7 +1564,7 @@ void InsetTabular::resetPos(BufferView * bv) const
 #warning This should be fixed in the right manner (20011128 Jug)
 #endif
        // fast hack to fix infinite repaintings!
-       if (in_reset_pos > 10)
+       if (in_reset_pos > 0)
                return;
 
        int cell = 0;
@@ -1566,7 +1592,7 @@ void InsetTabular::resetPos(BufferView * bv) const
        new_x += offset;
        cursor_.x(new_x);
 //    cursor.x(getCellXPos(actcell) + offset);
-       if ((actcol < tabular->columns()-1) && scroll(false) &&
+       if ((actcol < tabular->columns() - 1) && scroll(false) &&
                (tabular->GetWidthOfTabular() < bv->workWidth()-20))
        {
                scroll(bv, 0.0F);
@@ -1614,7 +1640,7 @@ void InsetTabular::resetPos(BufferView * bv) const
 }
 
 
-UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
+Inset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
 {
        if (lock && !old_locking_inset) {
                if (activateCellInset(bv))
@@ -1632,7 +1658,7 @@ UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
 }
 
 
-UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
+Inset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
 {
        bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv);
        if (!moved)
@@ -1646,7 +1672,7 @@ UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
 }
 
 
-UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
+Inset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
 {
        int const ocell = actcell;
        actcell = tabular->GetCellAbove(actcell);
@@ -1667,7 +1693,7 @@ UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv, bool lock)
 }
 
 
-UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
+Inset::RESULT InsetTabular::moveDown(BufferView * bv, bool lock)
 {
        int const ocell = actcell;
        actcell = tabular->GetCellBelow(actcell);
@@ -1855,6 +1881,9 @@ void InsetTabular::tabularFeatures(BufferView * bv,
        case LyXTabular::ALIGN_CENTER:
                setAlign = LYX_ALIGN_CENTER;
                break;
+       case LyXTabular::ALIGN_BLOCK:
+               setAlign = LYX_ALIGN_BLOCK;
+               break;
        case LyXTabular::M_VALIGN_TOP:
        case LyXTabular::VALIGN_TOP:
                setVAlign = LyXTabular::LYX_VALIGN_TOP;
@@ -1901,6 +1930,13 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                        }
                        updateLocal(bv, INIT, true);
                }
+
+               if (vallen.zero()
+                   && tabular->GetAlignment(actcell, true) == LYX_ALIGN_BLOCK)
+                       tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
+               else if (!vallen.zero()
+                        && tabular->GetAlignment(actcell, true) != LYX_ALIGN_BLOCK)
+                       tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
        }
        break;
        case LyXTabular::SET_MPWIDTH:
@@ -2025,6 +2061,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
        case LyXTabular::ALIGN_LEFT:
        case LyXTabular::ALIGN_RIGHT:
        case LyXTabular::ALIGN_CENTER:
+       case LyXTabular::ALIGN_BLOCK:
                for (int i = sel_row_start; i <= sel_row_end; ++i)
                        for (int j = sel_col_start; j <= sel_col_end; ++j)
                                tabular->SetAlignment(
@@ -2218,7 +2255,7 @@ int InsetTabular::getMaxWidthOfCell(BufferView * bv, int cell) const
 
        if (len.zero())
                return -1;
-       return len.inPixels(latexTextWidth(bv), bv->text->defaultHeight());
+       return len.inPixels(latexTextWidth(bv));
 }
 
 
@@ -2395,6 +2432,10 @@ FuncStatus InsetTabular::getStatus(string const & what) const
        case LyXTabular::ALIGN_CENTER:
                status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_CENTER);
                break;
+       case LyXTabular::ALIGN_BLOCK:
+               status.disabled(tabular->GetPWidth(actcell).zero());
+               status.setOnOff(tabular->GetAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
+               break;
        case LyXTabular::M_VALIGN_TOP:
                flag = false;
        case LyXTabular::VALIGN_TOP:
@@ -2504,7 +2545,7 @@ bool InsetTabular::copySelection(BufferView * bv)
        ostringstream sstr;
        paste_tabular->ascii(bv->buffer(), sstr,
                             (int)parOwner()->params().depth(), true, '\t');
-       bv->stuffClipboard(sstr.str().c_str());
+       bv->stuffClipboard(STRCONV(sstr.str()));
        return true;
 }