#include <config.h>
-
#include "insettabular.h"
#include "insettext.h"
#include "BufferView.h"
#include "lfuns.h"
#include "debug.h"
+#include "dimension.h"
#include "funcrequest.h"
#include "gettext.h"
#include "language.h"
#include "LaTeXFeatures.h"
+#include "Lsstream.h"
#include "lyx_cb.h"
#include "lyxfunc.h"
#include "lyxlength.h"
#include "ParagraphParameters.h"
#include "undo_funcs.h"
#include "WordLangTuple.h"
+#include "Lsstream.h"
#include "frontends/Alert.h"
#include "frontends/Dialogs.h"
}
-int InsetTabular::ascent(BufferView *, LyXFont const &) const
-{
- return tabular->GetAscentOfRow(0);
-}
-
-
-int InsetTabular::descent(BufferView *, LyXFont const &) const
-{
- return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
-}
-
-
-int InsetTabular::width(BufferView *, LyXFont const &) const
+void InsetTabular::dimension(BufferView *, LyXFont const &,
+ Dimension & dim) const
{
- return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
+ dim.a = tabular->GetAscentOfRow(0);
+ dim.d = tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
+ dim.w = tabular->GetWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
}
string const InsetTabular::editMessage() const
{
- return _("Opened Tabular Inset");
-}
-
-
-void InsetTabular::edit(BufferView * bv, int x, int y, mouse_button::state button)
-{
- UpdatableInset::edit(bv, x, y, button);
-
- if (!bv->lockInset(this)) {
- lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
- return;
- }
- locked = true;
- the_locking_inset = 0;
- inset_x = 0;
- inset_y = 0;
- setPos(bv, x, y);
- clearSelection();
- finishUndo();
- if (insetHit(bv, x, y) && (button != mouse_button::button3)) {
- activateCellInsetAbs(bv, x, y, button);
- }
-}
-
-
-void InsetTabular::edit(BufferView * bv, bool front)
-{
- UpdatableInset::edit(bv, front);
-
- if (!bv->lockInset(this)) {
- lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
- return;
- }
- finishUndo();
- locked = true;
- the_locking_inset = 0;
- inset_x = 0;
- inset_y = 0;
- if (front) {
- if (isRightToLeft(bv))
- actcell = tabular->GetLastCellInRow(0);
- else
- actcell = 0;
- } else {
- if (isRightToLeft(bv))
- actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
- else
- actcell = tabular->GetNumberOfCells() - 1;
- }
- clearSelection();
- resetPos(bv);
- bv->fitCursor();
+ return _("Opened table");
}
updateLocal(bv, CELL);
the_locking_inset = 0;
}
- hideInsetCursor(bv);
actcell = 0;
oldcell = -1;
locked = false;
}
if (in->getInsetFromID(id)) {
actcell = i;
- in->edit(bv);
+ in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
return the_locking_inset->lockInsetInInset(bv, inset);
}
}
updateLocal(bv, CELL);
// this has to be here otherwise we don't redraw the cell!
the_locking_inset = 0;
-// showInsetCursor(bv, false);
return true;
}
if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
int const orow = actrow;
BufferView * bv = cmd.view();
- hideInsetCursor(bv);
if (!locked) {
locked = true;
the_locking_inset = 0;
updateLocal(bv, CELL);
the_locking_inset = 0;
}
- showInsetCursor(bv);
return;
}
#endif
the_locking_inset->localDispatch(cmd1);
return;
}
- showInsetCursor(bv);
}
}
BufferView * bv = cmd.view();
- hideInsetCursor(bv);
int const old_cell = actcell;
setPos(bv, cmd.x, cmd.y);
setSelection(sel_cell_start, actcell);
updateLocal(bv, SELECTION);
}
- showInsetCursor(bv);
}
// the_locking_inset->localDispatch might unlock it.
old_locking_inset = the_locking_inset;
RESULT result = UpdatableInset::localDispatch(cmd);
-
BufferView * bv = cmd.view();
+
+ if (cmd.action == LFUN_INSET_EDIT) {
+
+ if (!bv->lockInset(this)) {
+ lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
+ return DISPATCHED;
+ }
+
+ finishUndo();
+ locked = true;
+ the_locking_inset = 0;
+ inset_x = 0;
+ inset_y = 0;
+
+ if (cmd.argument.size()) {
+ if (cmd.argument == "left") {
+ if (isRightToLeft(bv))
+ actcell = tabular->GetLastCellInRow(0);
+ else
+ actcell = 0;
+ } else {
+ if (isRightToLeft(bv))
+ actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
+ else
+ actcell = tabular->GetNumberOfCells() - 1;
+ }
+ clearSelection();
+ resetPos(bv);
+ bv->fitCursor();
+ }
+
+ else {
+ setPos(bv, cmd.x, cmd.y);
+ clearSelection();
+ finishUndo();
+ if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
+ activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
+ }
+ }
+ return DISPATCHED;
+ }
+
if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
resetPos(bv);
return result;
case LFUN_CELL_BACKWARD:
case LFUN_CELL_FORWARD:
- hideInsetCursor(bv);
unlockInsetInInset(bv, the_locking_inset);
if (cmd.action == LFUN_CELL_FORWARD)
moveNextCell(bv, old_locking_inset != 0);
if (hs)
updateLocal(bv, SELECTION);
if (!the_locking_inset) {
- showInsetCursor(bv);
return DISPATCHED_NOUPDATE;
}
return result;
int sc = scroll();
resetPos(bv);
if (sc != scroll()) { // inset has been scrolled
- the_locking_inset->toggleInsetCursor(bv);
updateLocal(bv, FULL);
- the_locking_inset->toggleInsetCursor(bv);
}
return result;
} else if (result == DISPATCHED) {
- the_locking_inset->toggleInsetCursor(bv);
updateLocal(bv, CELL);
- the_locking_inset->toggleInsetCursor(bv);
return result;
} else if (result == FINISHED_UP) {
action = LFUN_UP;
}
}
- hideInsetCursor(bv);
result = DISPATCHED;
switch (action) {
// --- Cursor Movements ----------------------------------
if (!the_locking_inset) {
if (bv->fitCursor())
updateLocal(bv, FULL);
- if (locked)
- showInsetCursor(bv);
}
} else
bv->unlockInset(this);
int InsetTabular::latex(Buffer const * buf, ostream & os,
- bool fragile, bool fp) const
+ LatexRunParams const & runparams) const
{
- return tabular->latex(buf, os, fragile, fp);
+ return tabular->latex(buf, os, runparams);
}
}
-void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
+void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
{
if (the_locking_inset) {
- the_locking_inset->getCursorPos(bv, x, y);
+ the_locking_inset->getCursor(bv, x, y);
return;
}
- x = cursor_.x() - top_x;
- y = cursor_.y();
-}
+ x = cursor_.x();
+ y = cursor_.y() + InsetTabular::y();
-void InsetTabular::toggleInsetCursor(BufferView * bv)
-{
- if (nodraw()) {
- if (isCursorVisible())
- bv->hideLockedInsetCursor();
- return;
- }
- if (the_locking_inset) {
- the_locking_inset->toggleInsetCursor(bv);
- return;
- }
-
- LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
-
- int const asc = font_metrics::maxAscent(font);
- int const desc = font_metrics::maxDescent(font);
-
- if (isCursorVisible())
- bv->hideLockedInsetCursor();
- else
- bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
- toggleCursorVisible();
+ // Fun stuff
+ int desc = tabular->GetDescentOfRow(actrow);
+ y += desc;
+ int ascdesc = tabular->GetAscentOfRow(actrow) + desc;
+ y -= ascdesc / 2;
+ y += ADD_TO_HEIGHT * 2;
+ y += TEXT_TO_INSET_OFFSET;
}
-void InsetTabular::showInsetCursor(BufferView * bv, bool show)
+void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
{
- if (nodraw())
+ if (the_locking_inset) {
+ the_locking_inset->getCursorPos(bv, x, y);
return;
- if (!isCursorVisible()) {
- LyXFont font; // = GetFont(par, cursor.pos);
-
- 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);
- setCursorVisible(true);
- }
-}
-
-
-void InsetTabular::hideInsetCursor(BufferView * bv)
-{
- if (isCursorVisible()) {
- bv->hideLockedInsetCursor();
- setCursorVisible(false);
}
+ x = cursor_.x() - top_x;
+ y = cursor_.y();
}
}
//inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
//inset_y = cursor.y();
- inset->edit(bv, x, y, button);
+ inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x, y, button));
if (!the_locking_inset)
return false;
updateLocal(bv, CELL);
}
-Paragraph * InsetTabular::firstParagraph() const
-{
- if (the_locking_inset)
- return the_locking_inset->firstParagraph();
- return 0;
-}
-
-
-Paragraph * InsetTabular::getFirstParagraph(int i) const
+ParagraphList * InsetTabular::getParagraphs(int i) const
{
return (i < tabular->GetNumberOfCells())
- ? tabular->GetCellInset(i)->getFirstParagraph(0)
+ ? tabular->GetCellInset(i)->getParagraphs(0)
: 0;
}
// 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, mouse_button::none);
+ inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
WordLangTuple word(selectNextWordInt(bv, value));
nodraw(false);
if (!word.word().empty())
// 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);
+ inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
return selectNextWordInt(bv, value);
}
int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
{
- istringstream data(in);
+ istringstream data(STRCONV(in));
LyXLex lex(0,0);
lex.setStream(data);
}
-string const
-InsetTabularMailer::params2string(InsetTabular const & inset)
+string const InsetTabularMailer::params2string(InsetTabular const & inset)
{
BufferView * const bv = inset.view();
Buffer const * const buffer = bv ? bv->buffer() : 0;
data << name_ << " \\active_cell " << inset.getActCell() << '\n';
inset.write(buffer, data);
data << "\\end_inset\n";
-
- return data.str();
+ return STRCONV(data.str());
}