]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
More header file include dependency work
[lyx.git] / src / insets / insettabular.C
index a343e41cd93c52344afd1a701967aa38b7698883..b15d80e5e43ae4fe8c53a4dcb5d67ddc1509048b 100644 (file)
@@ -40,6 +40,8 @@
 #include "language.h"
 #include "BufferView.h"
 #include "undo_funcs.h"
+#include "support/LAssert.h"
+#include "support/lstrings.h"
 
 using std::ostream;
 using std::ifstream;
@@ -141,7 +143,7 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
 
 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
                                                   bool same_id)
-       : buffer(&buf)
+       : UpdatableInset(tab, same_id), buffer(&buf)
 {
        tabular.reset(new LyXTabular(this, *(tab.tabular)));
        the_locking_inset = 0;
@@ -150,8 +152,6 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
        actrow = actcell = 0;
        sel_cell_start = sel_cell_end = 0;
        need_update = INIT;
-       if (same_id)
-               id_ = tab.id_;
 }
 
 
@@ -259,7 +259,7 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                        h = pain.paperHeight();
                if ((top_x + w) > pain.paperWidth())
                        w = pain.paperWidth();
-               pain.fillRectangle(tx, ty, w, h);
+               pain.fillRectangle(tx, ty, w, h, backgroundColor());
                need_update = FULL;
                cleared = true;
        }
@@ -366,7 +366,8 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                                baseline - tabular->GetAscentOfRow(i) + 1,
                                int(cx - nx - 1),
                                tabular->GetAscentOfRow(i) +
-                               tabular->GetDescentOfRow(i) - 1);
+                               tabular->GetDescentOfRow(i) - 1,
+                               backgroundColor());
                        // clear behind the inset
                        pain.fillRectangle(
                                int(cx + the_locking_inset->width(bv,font) + 1),
@@ -376,7 +377,8 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                                the_locking_inset->width(bv,font) -
                                tabular->GetAdditionalWidth(cell) - 1,
                                tabular->GetAscentOfRow(i) +
-                               tabular->GetDescentOfRow(i) - 1);
+                               tabular->GetDescentOfRow(i) - 1,
+                               backgroundColor());
                }
        }
        x -= ADD_TO_TABULAR_WIDTH;
@@ -510,8 +512,28 @@ void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
        if (insetHit(bv, x, y) && (button != 3)) {
                activateCellInsetAbs(bv, x, y, button);
        }
-//    UpdateLocal(bv, NONE, false);
-//    bv->getOwner()->getPopups().updateFormTabular();
+}
+
+
+void InsetTabular::edit(BufferView * bv, bool front)
+{
+       UpdatableInset::edit(bv, front);
+       
+       if (!bv->lockInset(this)) {
+               lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
+               return;
+       }
+       locked = true;
+       the_locking_inset = 0;
+       inset_x = 0;
+       inset_y = 0;
+       if (front)
+               actcell = 0;
+       else
+               actcell = tabular->GetNumberOfCells() - 1;
+       sel_cell_start = sel_cell_end = actcell;
+       resetPos(bv);
+       finishUndo();
 }
 
 
@@ -632,9 +654,10 @@ unsigned int InsetTabular::insetInInsetY()
 }
 
 
-UpdatableInset * InsetTabular::getLockingInset()
+UpdatableInset * InsetTabular::getLockingInset() const
 {
-       return the_locking_inset ? the_locking_inset->getLockingInset() : this;
+       return the_locking_inset ? the_locking_inset->getLockingInset() :
+               const_cast<InsetTabular *>(this);
 }
 
 
@@ -1172,9 +1195,12 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
 }
 
 
-void InsetTabular::getCursorPos(BufferView *,
-                               int & x, int & y) const
+void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
 {
+       if (the_locking_inset) {
+               the_locking_inset->getCursorPos(bv, x, y);
+               return;
+       }
        x = cursor_.x() - top_x;
        y = cursor_.y();
 }
@@ -1255,6 +1281,7 @@ void InsetTabular::setPos(BufferView * bv, int x, int y) const
                     tabular->GetAdditionalWidth(actcell - 1));
 #else
        // Jürgen, you should check that this is correct. (Lgb)
+#warning Jürgen, please check. (Lgb)
        for (; !tabular->IsLastCellInRow(actcell) && lx < x; ++actcell) {
                lx += tabular->GetWidthOfColumn(actcell + 1)
                        + tabular->GetAdditionalWidth(actcell);
@@ -1478,10 +1505,8 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
 }
 
 
-bool InsetTabular::Delete()
+bool InsetTabular::deletable()
 {
-#warning Is this func correctly named? Or should it be "deletable"? (Lgb?)
-#warning I guess this could be 'deletable'! (Jug)
        return true;
 }
 
@@ -1965,10 +1990,19 @@ void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
 
 
 LyXText * InsetTabular::getLyXText(BufferView const * bv,
-                                  bool const recursive) const
+                                   bool const recursive) const
 {
        if (the_locking_inset)
                return the_locking_inset->getLyXText(bv, recursive);
+#if 0
+       // if we're locked lock the actual insettext and return it's LyXText!!!
+       if (locked) {
+               UpdatableInset * inset =
+                       static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
+               inset->edit(const_cast<BufferView *>(bv), 0,  0, 0);
+               return the_locking_inset->getLyXText(bv, recursive);
+       }
+#endif
        return Inset::getLyXText(bv, recursive);
 }
 
@@ -1996,6 +2030,7 @@ void InsetTabular::openLayoutDialog(BufferView * bv) const
                const_cast<InsetTabular *>(this));
 }
 
+
 //
 // functions returns:
 // 0 ... disabled
@@ -2307,11 +2342,6 @@ bool InsetTabular::cutSelection()
        if (!hasSelection())
                return false;
 
-       //int sel_col_start;
-       //int sel_col_end;
-       //int sel_row_start;
-       //int sel_row_end;
-
        int sel_col_start = tabular->column_of_cell(sel_cell_start);
        int sel_col_end = tabular->column_of_cell(sel_cell_end);
        if (sel_col_start > sel_col_end) {
@@ -2323,15 +2353,9 @@ bool InsetTabular::cutSelection()
        int sel_row_start = tabular->row_of_cell(sel_cell_start);
        int sel_row_end = tabular->row_of_cell(sel_cell_end);
        if (sel_row_start > sel_row_end) {
-               //int tmp = sel_row_start;
-               //sel_row_start = sel_row_end;
-               //sel_row_end = tmp;
                swap(sel_row_start, sel_row_end);
        }
        if (sel_cell_start > sel_cell_end) {
-               //int tmp = sel_cell_start;
-               //sel_cell_start = sel_cell_end;
-               //sel_cell_end = tmp;
                swap(sel_cell_start, sel_cell_end);
        }
        for (int i = sel_row_start; i <= sel_row_end; ++i) {
@@ -2389,11 +2413,12 @@ void InsetTabular::getSelection(int & srow, int & erow, int & scol, int & ecol)
                        ecol = tabular->right_column_of_cell(sel_cell_end);
 }
 
+
 Paragraph * InsetTabular::getParFromID(int id) const
 {
        Paragraph * result;
-       for(int i=0; i < tabular->rows(); ++i) {
-               for(int j=0; j < tabular->columns(); ++j) {
+       for(int i = 0; i < tabular->rows(); ++i) {
+               for(int j = 0; j < tabular->columns(); ++j) {
                        if ((result = tabular->GetCellInset(i, j)->getParFromID(id)))
                                return result;
                }
@@ -2401,6 +2426,7 @@ Paragraph * InsetTabular::getParFromID(int id) const
        return 0;
 }
 
+
 Paragraph * InsetTabular::firstParagraph() const
 {
        if (the_locking_inset)
@@ -2408,6 +2434,7 @@ Paragraph * InsetTabular::firstParagraph() const
        return 0;
 }
 
+
 LyXCursor const & InsetTabular::cursor(BufferView * bv) const
 {
        if (the_locking_inset)
@@ -2430,3 +2457,116 @@ Inset * InsetTabular::getInsetFromID(int id_arg) const
        }
        return 0;
 }
+
+
+string const InsetTabular::selectNextWord(BufferView * bv, float & value) const
+{
+       if (the_locking_inset) {
+               string const str(the_locking_inset->selectNextWord(bv, value));
+               if (!str.empty())
+                       return str;
+               if (tabular->IsLastCell(actcell)) {
+                       bv->unlockInset(const_cast<InsetTabular *>(this));
+                       return string();
+               }
+               ++actcell;
+       }
+       
+       // 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);
+       string const str(selectNextWordInt(bv, value));
+       if (!str.empty())
+               resetPos(bv);
+       return str;
+}
+
+
+string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
+{
+       // when entering this function the inset should be ALWAYS locked!
+       lyx::Assert(the_locking_inset);
+
+       string const str(the_locking_inset->selectNextWord(bv, value));
+       if (!str.empty())
+               return str;
+
+       if (tabular->IsLastCell(actcell)) {
+               bv->unlockInset(const_cast<InsetTabular *>(this));
+               return string();
+       }
+       
+       // 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);
+       return selectNextWordInt(bv, value);
+}
+
+
+void InsetTabular::selectSelectedWord(BufferView * bv)
+{
+       if (the_locking_inset) {
+               the_locking_inset->selectSelectedWord(bv);
+               return;
+       }
+       return;
+}
+
+
+void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
+{
+       if (the_locking_inset) {
+               the_locking_inset->toggleSelection(bv, kill_selection);
+       }
+}
+
+
+bool InsetTabular::searchForward(BufferView * bv, string const & str,
+                              bool const & cs, bool const & mw)
+{
+       if (the_locking_inset) {
+               if (the_locking_inset->searchForward(bv, str, cs, mw))
+                       return true;
+               if (tabular->IsLastCell(actcell)) {
+                       bv->unlockInset(const_cast<InsetTabular *>(this));
+                       return false;
+               }
+               ++actcell;
+       }
+       nodraw(true);
+       // otherwise we have to lock the next inset and search there
+       UpdatableInset * inset =
+               static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
+       inset->edit(bv);
+       bool const res = searchForward(bv, str, cs, mw);
+       updateLocal(bv, NONE, false);
+       nodraw(false);
+       bv->updateInset(const_cast<InsetTabular *>(this), false);
+       return res;
+}
+
+
+bool InsetTabular::searchBackward(BufferView * bv, string const & str,
+                               bool const & cs, bool const & mw)
+{
+       if (the_locking_inset) {
+               if (the_locking_inset->searchBackward(bv, str, cs, mw))
+                       return true;
+               if (!actcell) { // we are already in the first cell
+                       bv->unlockInset(const_cast<InsetTabular *>(this));
+                       return false;
+               }
+               --actcell;
+       }
+       nodraw(true);
+       // otherwise we have to lock the next inset and search there
+       UpdatableInset * inset =
+               static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
+       inset->edit(bv, false);
+       bool const res = searchBackward(bv, str, cs, mw);
+       nodraw(false);
+       bv->updateInset(const_cast<InsetTabular *>(this), false);
+       return res;
+}