]> git.lyx.org Git - features.git/blobdiff - src/insets/insettabular.C
read the Changelog
[features.git] / src / insets / insettabular.C
index c957576010ace2e07347eb5a63d1be0fa229fef6..6e6aeac44ae78069c5e5f7bd1cb0a2a333b67e63 100644 (file)
@@ -5,7 +5,7 @@
  *
  *           Copyright 2000 The LyX Team.
  *
- *======================================================
+ * ======================================================
  */
 
 #include <config.h>
 #include "insets/insettext.h"
 #include "frontends/Dialogs.h"
 
-extern void MenuLayoutTabular(bool, InsetTabular *);
-extern bool UpdateLayoutTabular(bool, InsetTabular *);
-extern void TabularOptClose();
-
 const int ADD_TO_HEIGHT = 2;
 const int ADD_TO_TABULAR_WIDTH = 2;
 
@@ -44,11 +40,10 @@ using std::ostream;
 using std::ifstream;
 using std::max;
 using std::endl;
+using std::swap;
 
 #define cellstart(p) ((p % 2) == 0)
 
-#define USE_NEW_LAYOUT 1
-
 InsetTabular::InsetTabular(Buffer * buf, int rows, int columns)
 {
     if (rows <= 0)
@@ -66,6 +61,7 @@ InsetTabular::InsetTabular(Buffer * buf, int rows, int columns)
     actcell = 0;
     cursor.pos(0);
     sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
+    dialogs_ = 0;
     need_update = INIT;
 }
 
@@ -81,6 +77,7 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
     actcell = 0;
     cursor.pos(0);
     sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
+    dialogs_ = 0;
     need_update = INIT;
 }
 
@@ -88,10 +85,8 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
 InsetTabular::~InsetTabular()
 {
     delete tabular;
-#ifdef USE_NEW_LAYOUT
-    if (buffer->getUser())
-       buffer->getUser()->owner()->getDialogs()->hideTabular(this);
-#endif
+    if (dialogs_)
+       dialogs_->hideTabular(this);
 }
 
 
@@ -146,7 +141,7 @@ int InsetTabular::ascent(BufferView *, LyXFont const &) const
 
 int InsetTabular::descent(BufferView *, LyXFont const &) const
 {
-    return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0);
+    return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
 }
 
 
@@ -160,16 +155,15 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                        float & x, bool cleared) const
 {
     Painter & pain = bv->painter();
-    int i, j, cell=0;
+    int i, j, cell = 0;
     int nx;
     float cx;
 
     UpdatableInset::draw(bv,font,baseline,x,cleared);
     if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
                     (top_x != int(x)) || (top_baseline != baseline))) {
-#if 1
        int h = ascent(bv, font) + descent(bv, font);
-       int tx = display()? 0:top_x;
+       int tx = display()||!owner()? 0:top_x;
        int w =  tx? width(bv, font):pain.paperWidth();
        int ty = baseline - ascent(bv, font);
        
@@ -182,18 +176,6 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
        pain.fillRectangle(tx, ty, w, h);
        need_update = FULL;
        cleared = true;
-#else
-       need_update = FULL;
-       resetPos(pain);
-       if (locked) { // repaint this way as the background was not cleared
-               if (the_locking_inset)
-                       the_locking_inset->update(bv, font, true);
-               locked = false;
-               bv->updateInset(const_cast<InsetTabular*>(this), false);
-               locked = true;
-               return;
-       }
-#endif
     }
     top_x = int(x);
     top_baseline = baseline;
@@ -271,8 +253,6 @@ void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
                                     int row, int column, int cell) const
 {
-    int tmp;
-
     int cs = tabular->column_of_cell(sel_cell_start);
     int ce = tabular->column_of_cell(sel_cell_end);
     if (cs > ce) {
@@ -284,11 +264,7 @@ void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
 
     int rs = tabular->row_of_cell(sel_cell_start);
     int re = tabular->row_of_cell(sel_cell_end);
-    if (rs > re) {
-       tmp = rs;
-       rs = re;
-       re = tmp;
-    }
+    if (rs > re) swap(rs, re);
 
     if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
        int w = tabular->GetWidthOfColumn(cell);
@@ -357,7 +333,6 @@ void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
 
 void InsetTabular::InsetUnlock(BufferView * bv)
 {
-    TabularOptClose();
     if (the_locking_inset) {
        the_locking_inset->InsetUnlock(bv);
        the_locking_inset = 0;
@@ -373,6 +348,7 @@ void InsetTabular::InsetUnlock(BufferView * bv)
     locked = false;
 }
 
+
 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
                               bool mark_dirty)
 {
@@ -382,6 +358,7 @@ void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
        resetPos(bv);
 }
 
+
 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
 {
     lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
@@ -413,6 +390,7 @@ bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
     return false;
 }
 
+
 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                                   bool lr)
 {
@@ -430,7 +408,8 @@ bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
        if ((inset->LyxCode() == TABULAR_CODE) &&
            !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
        {
-           UpdateLayoutTabular(true, const_cast<InsetTabular *>(this));
+           dialogs_ = bv->owner()->getDialogs();
+           dialogs_->updateTabular(const_cast<InsetTabular *>(this));
            oldcell = actcell;
        }
        return true;
@@ -438,6 +417,7 @@ bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
     return false;
 }
 
+
 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
 {
     if (!the_locking_inset)
@@ -523,14 +503,11 @@ void InsetTabular::InsetButtonRelease(BufferView * bv,
                return;
            }
        }
-#ifdef USE_NEW_LAYOUT
-        bv->owner()->getDialogs()->showTabular(this);
+       dialogs_ = bv->owner()->getDialogs();
+        dialogs_->showTabular(this);
 #if 0
        else if (ocell != actcell)
                bview->getOwner()->getPopups().updateTabular();
-#endif
-#else
-       MenuLayoutTabular(true, this);
 #endif
        return;
     }
@@ -589,7 +566,6 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
        resetPos(bv);
        return result;
     }
-    result=DISPATCHED;
 
     if ((action < 0) && arg.empty())
         return FINISHED;
@@ -621,6 +597,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
 
     bool hs = hasSelection();
     HideInsetCursor(bv);
+    result=DISPATCHED;
     switch (action) {
        // Normal chars not handled here
     case -1:
@@ -645,7 +622,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
        sel_pos_start = sel_pos_end = cursor.pos();
        sel_cell_start = sel_cell_end = actcell;
        if (hs)
-           UpdateLocal(bv, CURSOR, false);
+           UpdateLocal(bv, SELECTION, false);
        break;
     case LFUN_LEFTSEL:
        if (tabular->IsFirstCellInRow(actcell) && cellstart(cursor.pos()))
@@ -666,7 +643,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
        sel_pos_start = sel_pos_end = cursor.pos();
        sel_cell_start = sel_cell_end = actcell;
        if (hs)
-           UpdateLocal(bv, CURSOR, false);
+           UpdateLocal(bv, SELECTION, false);
        break;
     case LFUN_DOWNSEL:
     {
@@ -686,7 +663,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
        sel_pos_start = sel_pos_end = cursor.pos();
        sel_cell_start = sel_cell_end = actcell;
        if (hs)
-           UpdateLocal(bv, CURSOR, false);
+           UpdateLocal(bv, SELECTION, false);
        break;
     case LFUN_UPSEL:
     {
@@ -706,7 +683,7 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
        sel_pos_start = sel_pos_end = cursor.pos();
        sel_cell_start = sel_cell_end = actcell;
        if (hs)
-           UpdateLocal(bv, CURSOR, false);
+           UpdateLocal(bv, SELECTION, false);
        break;
     case LFUN_BACKSPACE:
        break;
@@ -719,9 +696,9 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
     case LFUN_SHIFT_TAB:
     case LFUN_TAB:
        if (the_locking_inset) {
-           the_locking_inset->InsetUnlock(bv);
+           UnlockInsetInInset(bv, the_locking_inset);
+           the_locking_inset = 0;
        }
-       the_locking_inset = 0;
        if (action == LFUN_TAB)
            moveNextCell(bv);
        else
@@ -729,12 +706,12 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
        sel_pos_start = sel_pos_end = cursor.pos();
        sel_cell_start = sel_cell_end = actcell;
        if (hs)
-           UpdateLocal(bv, CURSOR, false);
+           UpdateLocal(bv, SELECTION, false);
        break;
     case LFUN_LAYOUT_TABLE:
     {
-       int flag = (arg == "true");
-       MenuLayoutTabular(flag, this);
+       dialogs_ = bv->owner()->getDialogs();
+        dialogs_->showTabular(this);
     }
     break;
     default:
@@ -755,7 +732,8 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
 }
 
 
-int InsetTabular::Latex(Buffer const * buf, ostream & os, bool fragile, bool fp) const
+int InsetTabular::Latex(Buffer const * buf, ostream & os,
+                       bool fragile, bool fp) const
 {
     return tabular->Latex(buf, os, fragile, fp);
 }
@@ -766,6 +744,7 @@ int InsetTabular::Ascii(Buffer const *, ostream &) const
     return 0;
 }
 
+
 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
 {
     return 0;
@@ -897,6 +876,7 @@ void InsetTabular::setPos(BufferView * bv, int x, int y) const
     resetPos(bv);
 }
 
+
 int InsetTabular::getCellXPos(int cell) const
 {
     int c;
@@ -911,6 +891,7 @@ int InsetTabular::getCellXPos(int cell) const
            ADD_TO_TABULAR_WIDTH);
 }
 
+
 void InsetTabular::resetPos(BufferView * bv) const
 {
     if (!locked)
@@ -937,7 +918,8 @@ void InsetTabular::resetPos(BufferView * bv) const
     if ((!the_locking_inset ||
         !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
        (actcell != oldcell)) {
-       UpdateLayoutTabular(true, const_cast<InsetTabular *>(this));
+       dialogs_ = bv->owner()->getDialogs();
+        dialogs_->updateTabular(const_cast<InsetTabular *>(this));
        oldcell = actcell;
     }
 }
@@ -1280,6 +1262,7 @@ void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val)
     }
 }
 
+
 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
                                     bool behind)
 {
@@ -1305,6 +1288,7 @@ bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
     return true;
 }
 
+
 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
 {
     InsetText * inset = tabular->GetCellInset(actcell);
@@ -1321,6 +1305,7 @@ bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
     }
 }
 
+
 // This returns paperWidth() if the cell-width is unlimited or the width
 // in pixels if we have a pwidth for this cell.
 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
@@ -1332,6 +1317,7 @@ int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
     return VSpace(s).inPixels( 0, 0);
 }
 
+
 int InsetTabular::getMaxWidth(Painter & pain,
                              UpdatableInset const * inset) const
 {
@@ -1351,7 +1337,9 @@ int InsetTabular::getMaxWidth(Painter & pain,
     return w;
 }
 
-void InsetTabular::recomputeTextInsets(BufferView * bv, const LyXFont & font) const
+
+void InsetTabular::recomputeTextInsets(BufferView * bv,
+                                      LyXFont const & font) const
 {
     InsetText * inset;
     int cell;
@@ -1370,3 +1358,9 @@ void InsetTabular::recomputeTextInsets(BufferView * bv, const LyXFont & font) co
 //     cx += tabular->GetWidthOfColumn(cell);
     }
 }
+
+
+void InsetTabular::resizeLyXText(BufferView *) const
+{
+    need_update = FULL;
+}