2000-04-19 14:42:19 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2000-04-24 20:58:23 +00:00
|
|
|
* Copyright 2000 The LyX Team.
|
2000-04-19 14:42:19 +00:00
|
|
|
*
|
|
|
|
*======================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "insettabular.h"
|
|
|
|
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "commandtags.h"
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "Painter.h"
|
|
|
|
#include "font.h"
|
2000-05-04 08:14:34 +00:00
|
|
|
#include "lyxtext.h"
|
2000-05-05 14:45:59 +00:00
|
|
|
#include "lyx_gui_misc.h"
|
2000-05-08 13:39:45 +00:00
|
|
|
#include "LyXView.h"
|
|
|
|
#include "lyxfunc.h"
|
2000-04-19 14:42:19 +00:00
|
|
|
#include "insets/insettext.h"
|
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
extern void MenuLayoutTabular(bool, InsetTabular *);
|
2000-05-16 15:17:19 +00:00
|
|
|
extern bool UpdateLayoutTabular(bool, InsetTabular *);
|
|
|
|
extern void TabularOptClose();
|
2000-05-08 13:39:45 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
const int ADD_TO_HEIGHT = 2;
|
2000-04-21 15:16:22 +00:00
|
|
|
const int ADD_TO_TABULAR_WIDTH = 2;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
|
|
using std::ostream;
|
|
|
|
using std::ifstream;
|
2000-04-24 20:58:23 +00:00
|
|
|
using std::max;
|
|
|
|
using std::endl;
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-04-21 15:16:22 +00:00
|
|
|
InsetTabular::InsetTabular(Buffer * buf, int rows, int columns)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
|
|
|
if (rows <= 0)
|
|
|
|
rows = 1;
|
|
|
|
if (columns <= 0)
|
|
|
|
columns = 1;
|
2000-05-15 14:49:36 +00:00
|
|
|
buffer = buf; // set this first!!!
|
|
|
|
tabular = new LyXTabular(this, rows,columns);
|
2000-04-21 15:16:22 +00:00
|
|
|
// for now make it always display as display() inset
|
|
|
|
// just for test!!!
|
2000-04-19 14:42:19 +00:00
|
|
|
the_locking_inset = 0;
|
2000-05-16 15:17:19 +00:00
|
|
|
locked = no_selection = cursor_visible = false;
|
2000-04-21 15:16:22 +00:00
|
|
|
cursor.x_fix = -1;
|
2000-05-16 15:17:19 +00:00
|
|
|
oldcell = -1;
|
2000-05-04 08:14:34 +00:00
|
|
|
actcell = cursor.pos = sel_pos_start = sel_pos_end = 0;
|
2000-05-15 14:49:36 +00:00
|
|
|
init_inset = true;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
|
|
|
|
{
|
2000-05-15 14:49:36 +00:00
|
|
|
buffer = buf; // set this first
|
|
|
|
tabular = new LyXTabular(this, *(tab.tabular));
|
2000-04-19 14:42:19 +00:00
|
|
|
the_locking_inset = 0;
|
2000-05-16 15:17:19 +00:00
|
|
|
locked = no_selection = cursor_visible = false;
|
2000-04-21 15:16:22 +00:00
|
|
|
cursor.x_fix = -1;
|
2000-05-16 15:17:19 +00:00
|
|
|
oldcell = -1;
|
2000-05-04 08:14:34 +00:00
|
|
|
actcell = cursor.pos = sel_pos_start = sel_pos_end = 0;
|
2000-05-15 14:49:36 +00:00
|
|
|
init_inset = true;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
InsetTabular::~InsetTabular()
|
|
|
|
{
|
2000-05-04 08:14:34 +00:00
|
|
|
delete tabular;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-26 14:56:50 +00:00
|
|
|
Inset * InsetTabular::Clone() const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
|
|
|
InsetTabular * t = new InsetTabular(*this, buffer);
|
2000-05-16 15:17:19 +00:00
|
|
|
delete t->tabular;
|
|
|
|
t->tabular = tabular->Clone(t);
|
2000-04-19 14:42:19 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetTabular::Write(ostream & os) const
|
|
|
|
{
|
2000-05-04 08:14:34 +00:00
|
|
|
os << " Tabular" << endl;
|
|
|
|
tabular->Write(os);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetTabular::Read(LyXLex & lex)
|
|
|
|
{
|
2000-05-17 14:43:09 +00:00
|
|
|
bool old_format = (lex.GetString() == "\\LyXTable");
|
2000-05-04 08:14:34 +00:00
|
|
|
string token;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
if (tabular)
|
|
|
|
delete tabular;
|
2000-05-15 14:49:36 +00:00
|
|
|
tabular = new LyXTabular(this, lex);
|
2000-05-04 08:14:34 +00:00
|
|
|
|
2000-05-17 14:43:09 +00:00
|
|
|
init_inset = true;
|
|
|
|
|
|
|
|
if (old_format)
|
|
|
|
return;
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
lex.nextToken();
|
|
|
|
token = lex.GetString();
|
|
|
|
while (lex.IsOK() && (token != "\\end_inset")) {
|
|
|
|
lex.nextToken();
|
|
|
|
token = lex.GetString();
|
|
|
|
}
|
|
|
|
if (token != "\\end_inset") {
|
|
|
|
lex.printError("Missing \\end_inset at this point. "
|
|
|
|
"Read: `$$Token'");
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetTabular::ascent(Painter & pain, LyXFont const & font) const
|
|
|
|
{
|
2000-05-15 14:49:36 +00:00
|
|
|
if (init_inset) {
|
2000-04-19 14:42:19 +00:00
|
|
|
calculate_width_of_cells(pain, font);
|
2000-05-15 14:49:36 +00:00
|
|
|
init_inset = false;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
return tabular->GetAscentOfRow(0);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetTabular::descent(Painter & pain, LyXFont const & font) const
|
|
|
|
{
|
2000-05-15 14:49:36 +00:00
|
|
|
if (init_inset) {
|
2000-04-19 14:42:19 +00:00
|
|
|
calculate_width_of_cells(pain, font);
|
2000-05-15 14:49:36 +00:00
|
|
|
init_inset = false;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetTabular::width(Painter & pain, LyXFont const & font) const
|
|
|
|
{
|
2000-05-15 14:49:36 +00:00
|
|
|
if (init_inset) {
|
2000-04-19 14:42:19 +00:00
|
|
|
calculate_width_of_cells(pain, font);
|
2000-05-15 14:49:36 +00:00
|
|
|
init_inset = false;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-21 15:16:22 +00:00
|
|
|
void InsetTabular::draw(Painter & pain, const LyXFont & font, int baseline,
|
|
|
|
float & x) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-04-21 15:16:22 +00:00
|
|
|
int i, j, cell=0;
|
|
|
|
int nx;
|
2000-05-04 08:14:34 +00:00
|
|
|
float cx;
|
2000-05-15 14:49:36 +00:00
|
|
|
bool reinit = false;
|
2000-04-21 15:16:22 +00:00
|
|
|
|
|
|
|
UpdatableInset::draw(pain,font,baseline,x);
|
2000-05-15 14:49:36 +00:00
|
|
|
if (init_inset || (top_x != int(x)) || (top_baseline != baseline)) {
|
|
|
|
int ox = top_x;
|
|
|
|
init_inset = false;
|
2000-04-21 15:16:22 +00:00
|
|
|
top_x = int(x);
|
2000-05-04 08:14:34 +00:00
|
|
|
top_baseline = baseline;
|
2000-05-15 14:49:36 +00:00
|
|
|
if (ox != top_x)
|
|
|
|
recomputeTextInsets(pain, font);
|
|
|
|
calculate_width_of_cells(pain, font);
|
2000-05-04 08:14:34 +00:00
|
|
|
resetPos(pain);
|
2000-05-15 14:49:36 +00:00
|
|
|
reinit = true;
|
2000-04-21 15:16:22 +00:00
|
|
|
}
|
2000-05-16 15:17:19 +00:00
|
|
|
x += ADD_TO_TABULAR_WIDTH;
|
2000-04-21 15:16:22 +00:00
|
|
|
for(i=0;i<tabular->rows();++i) {
|
|
|
|
nx = int(x);
|
|
|
|
for(j=0;j<tabular->columns();++j) {
|
2000-05-15 14:49:36 +00:00
|
|
|
if (tabular->IsPartOfMultiColumn(i,j))
|
|
|
|
continue;
|
2000-05-04 08:14:34 +00:00
|
|
|
cx = nx + tabular->GetBeginningOfTextInCell(cell);
|
|
|
|
tabular->GetCellInset(cell)->draw(pain, font, baseline, cx);
|
2000-04-21 15:16:22 +00:00
|
|
|
DrawCellLines(pain, nx, baseline, i, cell);
|
2000-05-04 08:14:34 +00:00
|
|
|
nx += tabular->GetWidthOfColumn(cell);
|
2000-04-21 15:16:22 +00:00
|
|
|
++cell;
|
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
baseline += tabular->GetDescentOfRow(i) + tabular->GetAscentOfRow(i+1)
|
|
|
|
+ tabular->GetAdditionalHeight(cell+1);
|
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
x += width(pain, font);
|
2000-05-04 08:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
|
|
|
|
int row, int cell) const
|
|
|
|
{
|
|
|
|
int x2 = x + tabular->GetWidthOfColumn(cell);
|
|
|
|
bool on_off;
|
|
|
|
|
|
|
|
if (!tabular->TopAlreadyDrawed(cell)) {
|
|
|
|
on_off = !tabular->TopLine(cell);
|
|
|
|
pain.line(x, baseline - tabular->GetAscentOfRow(row),
|
|
|
|
x2, baseline - tabular->GetAscentOfRow(row),
|
|
|
|
on_off ? LColor::tabularonoffline:LColor::tabularline,
|
|
|
|
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),
|
|
|
|
on_off ? LColor::tabularonoffline:LColor::tabularline,
|
|
|
|
on_off ? Painter::line_onoffdash:Painter::line_solid);
|
|
|
|
if (!tabular->LeftAlreadyDrawed(cell)) {
|
|
|
|
on_off = !tabular->LeftLine(cell);
|
|
|
|
pain.line(x, baseline - tabular->GetAscentOfRow(row),
|
|
|
|
x, baseline + tabular->GetDescentOfRow(row),
|
|
|
|
on_off ? LColor::tabularonoffline:LColor::tabularline,
|
|
|
|
on_off ? Painter::line_onoffdash:Painter::line_solid);
|
2000-04-21 15:16:22 +00:00
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
on_off = !tabular->RightLine(cell);
|
|
|
|
pain.line(x2 - tabular->GetAdditionalWidth(cell),
|
|
|
|
baseline - tabular->GetAscentOfRow(row),
|
|
|
|
x2 - tabular->GetAdditionalWidth(cell),
|
|
|
|
baseline + tabular->GetDescentOfRow(row),
|
|
|
|
on_off ? LColor::tabularonoffline:LColor::tabularline,
|
|
|
|
on_off ? Painter::line_onoffdash:Painter::line_solid);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
char const * InsetTabular::EditMessage() const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
|
|
|
return _("Opened Tabular Inset");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
|
|
|
|
{
|
|
|
|
UpdatableInset::Edit(bv, x, y, button);
|
|
|
|
|
2000-04-21 15:16:22 +00:00
|
|
|
if (!bv->lockInset(this)) {
|
|
|
|
lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
|
|
|
|
return;
|
|
|
|
}
|
2000-05-16 15:17:19 +00:00
|
|
|
locked = true;
|
2000-04-19 14:42:19 +00:00
|
|
|
the_locking_inset = 0;
|
2000-04-21 15:16:22 +00:00
|
|
|
sel_pos_start = sel_pos_end = inset_pos = inset_x = inset_y = 0;
|
|
|
|
setPos(bv->painter(), x, y);
|
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
2000-05-04 08:14:34 +00:00
|
|
|
bv->text->FinishUndo();
|
|
|
|
if (InsetHit(bv, x, y)) {
|
|
|
|
ActivateCellInset(bv, x, y, button);
|
|
|
|
}
|
2000-04-21 15:16:22 +00:00
|
|
|
UpdateLocal(bv, true);
|
|
|
|
// bv->getOwner()->getPopups().updateFormTabular();
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetTabular::InsetUnlock(BufferView * bv)
|
|
|
|
{
|
2000-05-16 15:17:19 +00:00
|
|
|
TabularOptClose();
|
2000-05-04 08:14:34 +00:00
|
|
|
if (the_locking_inset) {
|
2000-04-19 14:42:19 +00:00
|
|
|
the_locking_inset->InsetUnlock(bv);
|
2000-05-04 08:14:34 +00:00
|
|
|
the_locking_inset = 0;
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
HideInsetCursor(bv);
|
|
|
|
if (hasCharSelection()) {
|
2000-04-21 15:16:22 +00:00
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
2000-04-19 14:42:19 +00:00
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else
|
2000-04-21 15:16:22 +00:00
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
2000-04-19 14:42:19 +00:00
|
|
|
no_selection = false;
|
2000-05-16 15:17:19 +00:00
|
|
|
oldcell = -1;
|
|
|
|
locked = false;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
void InsetTabular::UpdateLocal(BufferView * bv, bool flag)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-05-15 14:49:36 +00:00
|
|
|
if (flag)
|
2000-05-04 08:14:34 +00:00
|
|
|
calculate_width_of_cells(bv->painter(), LyXFont(LyXFont::ALL_SANE));
|
|
|
|
bv->updateInset(this, flag);
|
2000-05-15 14:49:36 +00:00
|
|
|
if (flag)
|
|
|
|
resetPos(bv->painter());
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-05-04 08:14:34 +00:00
|
|
|
lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
|
|
|
|
if (!inset)
|
2000-04-19 14:42:19 +00:00
|
|
|
return false;
|
2000-05-16 15:17:19 +00:00
|
|
|
oldcell = -1;
|
2000-05-04 08:14:34 +00:00
|
|
|
if (inset == tabular->GetCellInset(actcell)) {
|
|
|
|
lyxerr[Debug::INSETS] << "OK" << endl;
|
|
|
|
the_locking_inset = tabular->GetCellInset(actcell);
|
|
|
|
resetPos(bv->painter());
|
|
|
|
inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
|
|
|
|
inset_y = cursor.y;
|
|
|
|
inset_pos = cursor.pos;
|
2000-04-19 14:42:19 +00:00
|
|
|
return true;
|
2000-05-04 08:14:34 +00:00
|
|
|
} else if (the_locking_inset && (the_locking_inset == inset)) {
|
|
|
|
if (cursor.pos == inset_pos) {
|
|
|
|
lyxerr[Debug::INSETS] << "OK" << endl;
|
|
|
|
resetPos(bv->painter());
|
|
|
|
inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
|
|
|
|
inset_y = cursor.y;
|
|
|
|
} else {
|
|
|
|
lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
|
|
|
|
}
|
|
|
|
} else if (the_locking_inset) {
|
|
|
|
lyxerr[Debug::INSETS] << "MAYBE" << endl;
|
|
|
|
return the_locking_inset->LockInsetInInset(bv, inset);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
lyxerr[Debug::INSETS] << "NOT OK" << endl;
|
|
|
|
return false;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
|
|
|
|
bool lr)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-05-04 08:14:34 +00:00
|
|
|
if (!the_locking_inset)
|
|
|
|
return false;
|
|
|
|
if (the_locking_inset == inset) {
|
|
|
|
the_locking_inset->InsetUnlock(bv);
|
|
|
|
the_locking_inset = 0;
|
|
|
|
if (lr)
|
|
|
|
moveRight(bv, false);
|
|
|
|
return true;
|
|
|
|
}
|
2000-05-16 15:17:19 +00:00
|
|
|
if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
|
|
|
|
if ((inset->LyxCode() == TABULAR_CODE) &&
|
|
|
|
!the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
|
|
|
|
{
|
|
|
|
UpdateLayoutTabular(true, const_cast<InsetTabular *>(this));
|
|
|
|
oldcell = actcell;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
|
|
|
|
{
|
|
|
|
if (!the_locking_inset)
|
|
|
|
return false;
|
|
|
|
if (the_locking_inset != inset)
|
|
|
|
return the_locking_inset->UpdateInsetInInset(bv, inset);
|
|
|
|
UpdateLocal(bv);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
int InsetTabular::InsetInInsetY()
|
|
|
|
{
|
|
|
|
if (!the_locking_inset)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return (inset_y + the_locking_inset->InsetInInsetY());
|
|
|
|
}
|
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
|
|
|
|
UpdatableInset * InsetTabular::GetLockingInset()
|
|
|
|
{
|
|
|
|
return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
|
|
|
|
{
|
|
|
|
if (c == LyxCode())
|
|
|
|
return this;
|
|
|
|
if (the_locking_inset)
|
|
|
|
return the_locking_inset->GetFirstLockingInsetOfType(c);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
|
|
|
|
{
|
|
|
|
if (the_locking_inset)
|
|
|
|
return the_locking_inset->InsertInset(bv, inset);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
void InsetTabular::InsetButtonRelease(BufferView * bv,
|
|
|
|
int x, int y, int button)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-05-08 13:39:45 +00:00
|
|
|
if (button == 3) {
|
2000-05-15 14:49:36 +00:00
|
|
|
if (the_locking_inset) {
|
|
|
|
UpdatableInset * i;
|
|
|
|
if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
|
|
|
|
i->InsetButtonRelease(bv, x, y, button);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MenuLayoutTabular(true, this);
|
2000-05-08 13:39:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
if (the_locking_inset) {
|
2000-05-04 08:14:34 +00:00
|
|
|
the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
|
2000-04-19 14:42:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
no_selection = false;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
|
|
|
if (hasCharSelection()) {
|
|
|
|
sel_pos_start = sel_pos_end = 0;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
}
|
|
|
|
no_selection = false;
|
2000-05-04 08:14:34 +00:00
|
|
|
|
2000-05-16 15:17:19 +00:00
|
|
|
int ocell = actcell;
|
2000-05-04 08:14:34 +00:00
|
|
|
|
|
|
|
setPos(bv->painter(), x, y);
|
|
|
|
|
|
|
|
bool inset_hit = InsetHit(bv, x, y);
|
|
|
|
|
2000-05-16 15:17:19 +00:00
|
|
|
if ((ocell == actcell) && the_locking_inset && inset_hit) {
|
2000-05-04 08:14:34 +00:00
|
|
|
the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
|
|
|
|
return;
|
|
|
|
} else if (the_locking_inset) {
|
2000-04-19 14:42:19 +00:00
|
|
|
the_locking_inset->InsetUnlock(bv);
|
|
|
|
}
|
|
|
|
the_locking_inset = 0;
|
2000-04-21 15:16:22 +00:00
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
2000-04-19 14:42:19 +00:00
|
|
|
sel_cell_start = sel_cell_end = actcell;
|
2000-05-04 08:14:34 +00:00
|
|
|
if (inset_hit && bv->the_locking_inset) {
|
|
|
|
ActivateCellInset(bv, x, y, button);
|
|
|
|
the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
|
|
|
|
}
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
#if 0
|
|
|
|
if (button == 3)
|
2000-04-21 15:16:22 +00:00
|
|
|
bview->getOwner()->getPopups().showFormTabular();
|
2000-05-16 15:17:19 +00:00
|
|
|
else if (ocell != actcell)
|
2000-04-21 15:16:22 +00:00
|
|
|
bview->getOwner()->getPopups().updateFormTabular();
|
2000-04-19 14:42:19 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
|
|
|
|
{
|
|
|
|
if (the_locking_inset) {
|
2000-04-24 20:58:23 +00:00
|
|
|
the_locking_inset->InsetMotionNotify(bv, x - inset_x,
|
|
|
|
y - inset_y, button);
|
2000-04-19 14:42:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!no_selection) {
|
2000-05-16 15:17:19 +00:00
|
|
|
// int ocell = actcell,
|
2000-04-24 20:58:23 +00:00
|
|
|
int old = sel_pos_end;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-04-21 15:16:22 +00:00
|
|
|
setPos(bv->painter(), x, y);
|
|
|
|
sel_pos_end = cursor.pos;
|
2000-04-19 14:42:19 +00:00
|
|
|
sel_cell_end = actcell;
|
|
|
|
if (old != sel_pos_end)
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
#if 0
|
2000-05-16 15:17:19 +00:00
|
|
|
if (ocell != actcell)
|
2000-04-21 15:16:22 +00:00
|
|
|
bview->getOwner()->getPopups().updateFormTabular();
|
2000-04-19 14:42:19 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
no_selection = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetTabular::InsetKeyPress(XKeyEvent * xke)
|
|
|
|
{
|
|
|
|
if (the_locking_inset) {
|
|
|
|
the_locking_inset->InsetKeyPress(xke);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
|
2000-04-19 14:42:19 +00:00
|
|
|
string const & arg)
|
|
|
|
{
|
2000-04-21 15:16:22 +00:00
|
|
|
UpdatableInset::RESULT
|
|
|
|
result;
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
no_selection = false;
|
2000-04-21 15:16:22 +00:00
|
|
|
if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
|
|
|
|
|| (result == DISPATCHED_NOUPDATE)) {
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
resetPos(bv->painter());
|
2000-04-21 15:16:22 +00:00
|
|
|
return result;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-04-21 15:16:22 +00:00
|
|
|
result=DISPATCHED;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
|
|
if ((action < 0) && arg.empty())
|
|
|
|
return FINISHED;
|
|
|
|
|
|
|
|
if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
|
|
|
|
(action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
|
2000-04-21 15:16:22 +00:00
|
|
|
cursor.x_fix = -1;
|
2000-04-19 14:42:19 +00:00
|
|
|
if (the_locking_inset) {
|
|
|
|
result=the_locking_inset->LocalDispatch(bv, action, arg);
|
2000-04-21 15:16:22 +00:00
|
|
|
if (result == DISPATCHED_NOUPDATE)
|
|
|
|
return result;
|
|
|
|
else if (result == DISPATCHED) {
|
2000-05-04 08:14:34 +00:00
|
|
|
bool upd = SetCellDimensions(bv->painter(), actcell, actrow);
|
2000-04-19 14:42:19 +00:00
|
|
|
the_locking_inset->ToggleInsetCursor(bv);
|
2000-05-04 08:14:34 +00:00
|
|
|
UpdateLocal(bv, upd);
|
2000-04-19 14:42:19 +00:00
|
|
|
the_locking_inset->ToggleInsetCursor(bv);
|
|
|
|
return result;
|
|
|
|
} else if (result == FINISHED) {
|
|
|
|
if ((action == LFUN_RIGHT) || (action == -1)) {
|
2000-04-21 15:16:22 +00:00
|
|
|
cursor.pos = inset_pos + 1;
|
2000-05-04 08:14:34 +00:00
|
|
|
resetPos(bv->painter());
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
the_locking_inset=0;
|
|
|
|
result = DISPATCHED;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HideInsetCursor(bv);
|
|
|
|
switch (action) {
|
2000-05-08 13:39:45 +00:00
|
|
|
// Normal chars not handled here
|
|
|
|
case -1:
|
|
|
|
break;
|
|
|
|
// --- Cursor Movements ---------------------------------------------
|
|
|
|
case LFUN_RIGHTSEL:
|
|
|
|
moveRight(bv, false);
|
|
|
|
sel_pos_end = cursor.pos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
break;
|
|
|
|
case LFUN_RIGHT:
|
|
|
|
result = moveRight(bv);
|
|
|
|
if (hasCharSelection()) {
|
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else
|
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
2000-04-19 14:42:19 +00:00
|
|
|
break;
|
2000-05-08 13:39:45 +00:00
|
|
|
case LFUN_LEFTSEL:
|
|
|
|
moveLeft(bv, false);
|
|
|
|
sel_pos_end = cursor.pos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
break;
|
|
|
|
case LFUN_LEFT:
|
|
|
|
result = moveLeft(bv);
|
|
|
|
if (hasCharSelection()) {
|
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else
|
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
|
|
|
break;
|
|
|
|
case LFUN_DOWNSEL:
|
|
|
|
moveDown();
|
|
|
|
sel_pos_end = cursor.pos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
break;
|
|
|
|
case LFUN_DOWN:
|
|
|
|
result= moveDown();
|
|
|
|
if (hasCharSelection()) {
|
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else
|
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
|
|
|
break;
|
|
|
|
case LFUN_UPSEL:
|
|
|
|
moveUp();
|
|
|
|
sel_pos_end = cursor.pos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
break;
|
|
|
|
case LFUN_UP:
|
|
|
|
result= moveUp();
|
|
|
|
if (hasCharSelection()) {
|
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
} else
|
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
|
|
|
break;
|
|
|
|
case LFUN_BACKSPACE:
|
|
|
|
break;
|
|
|
|
case LFUN_DELETE:
|
|
|
|
break;
|
|
|
|
case LFUN_HOME:
|
|
|
|
break;
|
|
|
|
case LFUN_END:
|
|
|
|
break;
|
|
|
|
case LFUN_TAB:
|
|
|
|
if (hasCharSelection()) {
|
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
|
|
|
UpdateLocal(bv, false);
|
|
|
|
}
|
|
|
|
sel_pos_start = sel_pos_end = cursor.pos;
|
|
|
|
moveNextCell();
|
|
|
|
break;
|
|
|
|
case LFUN_LAYOUT_TABLE:
|
|
|
|
{
|
|
|
|
int flag = (arg == "true");
|
2000-05-15 14:49:36 +00:00
|
|
|
MenuLayoutTabular(flag, this);
|
2000-05-08 13:39:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = UNDISPATCHED;
|
|
|
|
break;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
if (result!=FINISHED) {
|
|
|
|
if (!the_locking_inset) {
|
|
|
|
#if 0
|
2000-05-16 15:17:19 +00:00
|
|
|
if (ocell != actcell)
|
2000-04-21 15:16:22 +00:00
|
|
|
bview->getOwner()->getPopups().updateFormTabular();
|
2000-04-19 14:42:19 +00:00
|
|
|
#endif
|
|
|
|
ShowInsetCursor(bv);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
bv->unlockInset(this);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
int InsetTabular::Latex(ostream & os, bool fragile, bool fp) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-05-15 14:49:36 +00:00
|
|
|
return tabular->Latex(os, fragile, fp);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
|
|
int InsetTabular::Ascii(ostream &) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
int InsetTabular::Linuxdoc(ostream &) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
int InsetTabular::DocBook(ostream &) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
void InsetTabular::Validate(LaTeXFeatures & features) const
|
|
|
|
{
|
2000-05-19 10:32:05 +00:00
|
|
|
tabular->Validate(features);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
void InsetTabular::calculate_width_of_cells(Painter & pain,
|
|
|
|
LyXFont const & font) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-05-04 08:14:34 +00:00
|
|
|
int cell = -1;
|
|
|
|
int maxAsc, maxDesc;
|
|
|
|
InsetText * inset;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
for(int i = 0; i < tabular->rows(); ++i) {
|
|
|
|
maxAsc = maxDesc = 0;
|
|
|
|
for(int j= 0; j < tabular->columns(); ++j) {
|
|
|
|
if (tabular->IsPartOfMultiColumn(i,j))
|
|
|
|
continue;
|
|
|
|
++cell;
|
|
|
|
inset = tabular->GetCellInset(cell);
|
|
|
|
maxAsc = max(maxAsc, inset->ascent(pain, font));
|
|
|
|
maxDesc = max(maxDesc, inset->descent(pain, font));
|
|
|
|
tabular->SetWidthOfCell(cell, inset->width(pain, font));
|
2000-04-24 20:58:23 +00:00
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
|
|
|
|
tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
void InsetTabular::GetCursorPos(int & x, int & y) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-04-21 15:16:22 +00:00
|
|
|
x = cursor.x-top_x;
|
|
|
|
y = cursor.y;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetTabular::ToggleInsetCursor(BufferView * bv)
|
|
|
|
{
|
|
|
|
if (the_locking_inset) {
|
|
|
|
the_locking_inset->ToggleInsetCursor(bv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
int asc = lyxfont::maxAscent(font);
|
|
|
|
int desc = lyxfont::maxDescent(font);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
|
|
|
if (cursor_visible)
|
|
|
|
bv->hideLockedInsetCursor();
|
|
|
|
else
|
2000-04-21 15:16:22 +00:00
|
|
|
bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
|
2000-04-19 14:42:19 +00:00
|
|
|
cursor_visible = !cursor_visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetTabular::ShowInsetCursor(BufferView * bv)
|
|
|
|
{
|
|
|
|
if (!cursor_visible) {
|
2000-04-24 20:58:23 +00:00
|
|
|
LyXFont font; // = GetFont(par, cursor.pos);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
int asc = lyxfont::maxAscent(font);
|
|
|
|
int desc = lyxfont::maxDescent(font);
|
2000-04-21 15:16:22 +00:00
|
|
|
bv->fitLockedInsetCursor(cursor.x, cursor.y, asc, desc);
|
|
|
|
bv->showLockedInsetCursor(cursor.x, cursor.y, asc, desc);
|
2000-04-19 14:42:19 +00:00
|
|
|
cursor_visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetTabular::HideInsetCursor(BufferView * bv)
|
|
|
|
{
|
|
|
|
if (cursor_visible)
|
|
|
|
ToggleInsetCursor(bv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
void InsetTabular::setPos(Painter & pain, int x, int y) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-04-21 15:16:22 +00:00
|
|
|
cursor.y = cursor.pos = actcell = actrow = actcol = 0;
|
2000-05-04 08:14:34 +00:00
|
|
|
int ly = tabular->GetDescentOfRow(actrow);
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-21 15:16:22 +00:00
|
|
|
// first search the right row
|
|
|
|
while((ly < y) && (actrow < tabular->rows())) {
|
2000-05-04 08:14:34 +00:00
|
|
|
cursor.y += tabular->GetDescentOfRow(actrow) +
|
2000-05-15 14:49:36 +00:00
|
|
|
tabular->GetAscentOfRow(actrow+1) +
|
|
|
|
tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow+1,
|
|
|
|
actcol));
|
2000-04-21 15:16:22 +00:00
|
|
|
++actrow;
|
2000-05-04 08:14:34 +00:00
|
|
|
ly = cursor.y + tabular->GetDescentOfRow(actrow);
|
2000-04-21 15:16:22 +00:00
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
actcell = tabular->GetCellNumber(actrow, actcol);
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-21 15:16:22 +00:00
|
|
|
// now search the right column
|
2000-05-04 08:14:34 +00:00
|
|
|
int lx = tabular->GetWidthOfColumn(actcell) -
|
|
|
|
tabular->GetAdditionalWidth(actcell);
|
|
|
|
for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
|
|
|
|
++actcell,lx += tabular->GetWidthOfColumn(actcell) +
|
|
|
|
tabular->GetAdditionalWidth(actcell-1));
|
|
|
|
cursor.pos = ((actcell+1) * 2) - 1;
|
|
|
|
resetPos(pain);
|
|
|
|
if ((lx - (tabular->GetWidthOfColumn(actcell)/2)) < x) {
|
|
|
|
cursor.x = lx + top_x - 2;
|
|
|
|
} else {
|
|
|
|
--cursor.pos;
|
|
|
|
cursor.x = lx - tabular->GetWidthOfColumn(actcell) + top_x + 2;
|
|
|
|
}
|
|
|
|
resetPos(pain);
|
2000-04-21 15:16:22 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
int InsetTabular::getCellXPos(int cell) const
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
for(c=cell;!tabular->IsFirstCellInRow(c);--c)
|
|
|
|
;
|
|
|
|
int lx = tabular->GetWidthOfColumn(cell);
|
|
|
|
for(; (c < cell); ++c) {
|
|
|
|
lx += tabular->GetWidthOfColumn(c);
|
|
|
|
}
|
2000-05-16 15:17:19 +00:00
|
|
|
return (lx - tabular->GetWidthOfColumn(cell) + top_x +
|
|
|
|
ADD_TO_TABULAR_WIDTH);
|
2000-05-15 14:49:36 +00:00
|
|
|
}
|
2000-04-21 15:16:22 +00:00
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
void InsetTabular::resetPos(Painter & pain) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
2000-05-16 15:17:19 +00:00
|
|
|
if (!locked)
|
|
|
|
return;
|
2000-05-15 14:49:36 +00:00
|
|
|
actcol = tabular->column_of_cell(actcell);
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
|
|
int cell = 0;
|
2000-05-15 14:49:36 +00:00
|
|
|
actrow = cursor.y = 0;
|
2000-04-24 20:58:23 +00:00
|
|
|
for(; (cell<actcell) && !tabular->IsLastRow(cell); ++cell) {
|
2000-04-21 15:16:22 +00:00
|
|
|
if (tabular->IsLastCellInRow(cell)) {
|
2000-05-04 08:14:34 +00:00
|
|
|
cursor.y += tabular->GetDescentOfRow(actrow) +
|
|
|
|
tabular->GetAscentOfRow(actrow+1) +
|
|
|
|
tabular->GetAdditionalHeight(cell+1);
|
2000-04-21 15:16:22 +00:00
|
|
|
++actrow;
|
|
|
|
}
|
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
cursor.x = getCellXPos(actcell) + 2;
|
2000-04-21 15:16:22 +00:00
|
|
|
if (cursor.pos % 2) {
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
2000-05-04 08:14:34 +00:00
|
|
|
cursor.x += tabular->GetCellInset(actcell)->width(pain,font) +
|
|
|
|
tabular->GetBeginningOfTextInCell(actcell);
|
2000-04-21 15:16:22 +00:00
|
|
|
}
|
2000-05-16 15:17:19 +00:00
|
|
|
if ((!the_locking_inset ||
|
|
|
|
!the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
|
|
|
|
(actcell != oldcell)) {
|
|
|
|
UpdateLayoutTabular(true, const_cast<InsetTabular *>(this));
|
|
|
|
oldcell = actcell;
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
bool InsetTabular::SetCellDimensions(Painter & pain, int cell, int row)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-05-04 08:14:34 +00:00
|
|
|
InsetText * inset = tabular->GetCellInset(cell);
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
int asc = inset->ascent(pain, font) + ADD_TO_HEIGHT;
|
|
|
|
int desc = inset->descent(pain, font) + ADD_TO_HEIGHT;
|
|
|
|
int maxAsc = tabular->GetAscentOfRow(row);
|
|
|
|
int maxDesc = tabular->GetDescentOfRow(row);
|
|
|
|
bool ret = tabular->SetWidthOfCell(cell, inset->width(pain, font));
|
|
|
|
|
|
|
|
if (maxAsc < asc) {
|
|
|
|
ret = true;
|
|
|
|
tabular->SetAscentOfRow(row, asc);
|
|
|
|
}
|
|
|
|
if (maxDesc < desc) {
|
|
|
|
ret = true;
|
|
|
|
tabular->SetDescentOfRow(row, desc);
|
|
|
|
}
|
|
|
|
return ret;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-04-21 15:16:22 +00:00
|
|
|
if (cursor.pos % 2) { // behind the inset
|
|
|
|
++actcell;
|
|
|
|
if (actcell >= tabular->GetNumberOfCells())
|
|
|
|
return FINISHED;
|
|
|
|
++cursor.pos;
|
2000-05-04 08:14:34 +00:00
|
|
|
} else if (lock) {
|
|
|
|
if (ActivateCellInset(bv))
|
|
|
|
return DISPATCHED;
|
2000-04-21 15:16:22 +00:00
|
|
|
} else { // before the inset
|
|
|
|
++cursor.pos;
|
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
resetPos(bv->painter());
|
2000-04-21 15:16:22 +00:00
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-05-04 08:14:34 +00:00
|
|
|
if (!cursor.pos)
|
|
|
|
return FINISHED;
|
|
|
|
--cursor.pos;
|
|
|
|
if (cursor.pos % 2) { // behind the inset
|
|
|
|
--actcell;
|
|
|
|
} else if (lock) { // behind the inset
|
2000-05-15 14:49:36 +00:00
|
|
|
if (ActivateCellInset(bv, 0, 0, 0, true))
|
2000-05-04 08:14:34 +00:00
|
|
|
return DISPATCHED;
|
|
|
|
}
|
|
|
|
resetPos(bv->painter());
|
2000-04-21 15:16:22 +00:00
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-21 15:16:22 +00:00
|
|
|
UpdatableInset::RESULT InsetTabular::moveUp()
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-04-21 15:16:22 +00:00
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-21 15:16:22 +00:00
|
|
|
UpdatableInset::RESULT InsetTabular::moveDown()
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-04-21 15:16:22 +00:00
|
|
|
return DISPATCHED_NOUPDATE;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
bool InsetTabular::moveNextCell()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
bool InsetTabular::movePrevCell()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
bool InsetTabular::Delete()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
void InsetTabular::SetFont(BufferView *, LyXFont const &, bool)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-05-05 14:45:59 +00:00
|
|
|
void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
|
|
|
int
|
|
|
|
i,
|
2000-05-17 14:43:09 +00:00
|
|
|
sel_start,
|
|
|
|
sel_end,
|
2000-04-19 14:42:19 +00:00
|
|
|
setLines = 0,
|
|
|
|
setAlign = LYX_ALIGN_LEFT,
|
|
|
|
lineSet;
|
|
|
|
bool
|
|
|
|
what;
|
|
|
|
|
|
|
|
switch (feature) {
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::ALIGN_LEFT:
|
2000-04-19 14:42:19 +00:00
|
|
|
setAlign=LYX_ALIGN_LEFT;
|
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::ALIGN_RIGHT:
|
2000-04-19 14:42:19 +00:00
|
|
|
setAlign=LYX_ALIGN_RIGHT;
|
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::ALIGN_CENTER:
|
2000-04-19 14:42:19 +00:00
|
|
|
setAlign=LYX_ALIGN_CENTER;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (hasCellSelection()) {
|
|
|
|
if (sel_cell_start > sel_cell_end) {
|
2000-05-17 14:43:09 +00:00
|
|
|
sel_start = sel_cell_end;
|
|
|
|
sel_end = sel_cell_start;
|
2000-04-19 14:42:19 +00:00
|
|
|
} else {
|
2000-05-17 14:43:09 +00:00
|
|
|
sel_start = sel_cell_start;
|
|
|
|
sel_end = sel_cell_end;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
} else
|
2000-05-17 14:43:09 +00:00
|
|
|
sel_start = sel_end = actcell;
|
2000-04-19 14:42:19 +00:00
|
|
|
switch (feature) {
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::SET_PWIDTH:
|
2000-05-15 14:49:36 +00:00
|
|
|
{
|
2000-05-19 10:32:05 +00:00
|
|
|
bool update = (tabular->GetPWidth(actcell) != val);
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetPWidth(actcell,val);
|
2000-05-19 10:32:05 +00:00
|
|
|
if (update)
|
2000-05-15 14:49:36 +00:00
|
|
|
UpdateLocal(bv, true);
|
|
|
|
}
|
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::SET_SPECIAL_COLUMN:
|
|
|
|
case LyXTabular::SET_SPECIAL_MULTI:
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetAlignSpecial(actcell,val,feature);
|
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::APPEND_ROW:
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-04-21 15:16:22 +00:00
|
|
|
// append the row into the tabular
|
2000-05-05 14:45:59 +00:00
|
|
|
tabular->AppendRow(actcell);
|
|
|
|
UpdateLocal(bv, true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::APPEND_COLUMN:
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-04-21 15:16:22 +00:00
|
|
|
// append the column into the tabular
|
2000-05-05 14:45:59 +00:00
|
|
|
tabular->AppendColumn(actcell);
|
|
|
|
UpdateLocal(bv, true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::DELETE_ROW:
|
|
|
|
RemoveTabularRow();
|
2000-05-05 14:45:59 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::DELETE_COLUMN:
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-04-21 15:16:22 +00:00
|
|
|
/* delete the column from the tabular */
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->DeleteColumn(actcell);
|
2000-05-05 14:45:59 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::TOGGLE_LINE_TOP:
|
2000-04-19 14:42:19 +00:00
|
|
|
lineSet = !tabular->TopLine(actcell);
|
2000-05-17 14:43:09 +00:00
|
|
|
for(i=sel_start; i<=sel_end; ++i)
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetTopLine(i,lineSet);
|
2000-05-05 14:45:59 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::TOGGLE_LINE_BOTTOM:
|
2000-04-19 14:42:19 +00:00
|
|
|
lineSet = !tabular->BottomLine(actcell);
|
2000-05-17 14:43:09 +00:00
|
|
|
for(i=sel_start; i<=sel_end; ++i)
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetBottomLine(i,lineSet);
|
2000-05-05 14:45:59 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::TOGGLE_LINE_LEFT:
|
2000-04-19 14:42:19 +00:00
|
|
|
lineSet = !tabular->LeftLine(actcell);
|
2000-05-17 14:43:09 +00:00
|
|
|
for(i=sel_start; i<=sel_end; ++i)
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetLeftLine(i,lineSet);
|
2000-05-05 14:45:59 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::TOGGLE_LINE_RIGHT:
|
2000-04-19 14:42:19 +00:00
|
|
|
lineSet = !tabular->RightLine(actcell);
|
2000-05-17 14:43:09 +00:00
|
|
|
for(i=sel_start; i<=sel_end; ++i)
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetRightLine(i,lineSet);
|
2000-05-05 14:45:59 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::ALIGN_LEFT:
|
|
|
|
case LyXTabular::ALIGN_RIGHT:
|
|
|
|
case LyXTabular::ALIGN_CENTER:
|
2000-05-17 14:43:09 +00:00
|
|
|
for(i=sel_start; i<=sel_end; ++i)
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetAlignment(i,setAlign);
|
2000-05-05 14:45:59 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::MULTICOLUMN:
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2000-05-17 14:43:09 +00:00
|
|
|
if (tabular->row_of_cell(sel_start) !=
|
|
|
|
tabular->row_of_cell(sel_end)) {
|
2000-04-19 14:42:19 +00:00
|
|
|
WriteAlert(_("Impossible Operation!"),
|
|
|
|
_("Multicolumns can only be horizontally."),
|
|
|
|
_("Sorry."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// just multicol for one Single Cell
|
|
|
|
if (!hasCellSelection()) {
|
|
|
|
// check wether we are completly in a multicol
|
|
|
|
if (tabular->IsMultiColumn(actcell)) {
|
2000-05-05 14:45:59 +00:00
|
|
|
tabular->UnsetMultiColumn(actcell);
|
|
|
|
UpdateLocal(bv, true);
|
2000-04-19 14:42:19 +00:00
|
|
|
} else {
|
|
|
|
tabular->SetMultiColumn(actcell, 1);
|
2000-05-05 14:45:59 +00:00
|
|
|
UpdateLocal(bv, false);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// we have a selection so this means we just add all this
|
|
|
|
// cells to form a multicolumn cell
|
|
|
|
int
|
|
|
|
s_start, s_end;
|
|
|
|
|
2000-05-17 14:43:09 +00:00
|
|
|
if (sel_start > sel_end) {
|
|
|
|
s_start = sel_end;
|
|
|
|
s_end = sel_start;
|
2000-04-19 14:42:19 +00:00
|
|
|
} else {
|
2000-05-17 14:43:09 +00:00
|
|
|
s_start = sel_start;
|
|
|
|
s_end = sel_end;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-05-05 14:45:59 +00:00
|
|
|
tabular->SetMultiColumn(s_start, s_end);
|
2000-04-21 15:16:22 +00:00
|
|
|
cursor.pos = s_start;
|
2000-04-19 14:42:19 +00:00
|
|
|
sel_cell_end = sel_cell_start;
|
2000-05-05 14:45:59 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::SET_ALL_LINES:
|
2000-04-19 14:42:19 +00:00
|
|
|
setLines = 1;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::UNSET_ALL_LINES:
|
2000-05-17 14:43:09 +00:00
|
|
|
for(i=sel_start; i<=sel_end; ++i)
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetAllLines(i, setLines);
|
2000-05-05 14:45:59 +00:00
|
|
|
UpdateLocal(bv, true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::SET_LONGTABULAR:
|
|
|
|
tabular->SetLongTabular(true);
|
2000-05-05 14:45:59 +00:00
|
|
|
UpdateLocal(bv, true); // because this toggles displayed
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::UNSET_LONGTABULAR:
|
|
|
|
tabular->SetLongTabular(false);
|
2000-05-05 14:45:59 +00:00
|
|
|
UpdateLocal(bv, true); // because this toggles displayed
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::SET_ROTATE_TABULAR:
|
|
|
|
tabular->SetRotateTabular(true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::UNSET_ROTATE_TABULAR:
|
|
|
|
tabular->SetRotateTabular(false);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::SET_ROTATE_CELL:
|
2000-05-17 14:43:09 +00:00
|
|
|
for(i=sel_start; i<=sel_end; ++i)
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetRotateCell(i,true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::UNSET_ROTATE_CELL:
|
2000-05-17 14:43:09 +00:00
|
|
|
for(i=sel_start; i<=sel_end; ++i)
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetRotateCell(i,false);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::SET_LINEBREAKS:
|
2000-05-05 14:45:59 +00:00
|
|
|
what = !tabular->GetLinebreaks(actcell);
|
2000-05-17 14:43:09 +00:00
|
|
|
for(i=sel_start; i<=sel_end; ++i)
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetLinebreaks(i,what);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::SET_LTFIRSTHEAD:
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetLTHead(actcell,true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::SET_LTHEAD:
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetLTHead(actcell,false);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::SET_LTFOOT:
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetLTFoot(actcell,false);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::SET_LTLASTFOOT:
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetLTFoot(actcell,true);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-21 15:16:22 +00:00
|
|
|
case LyXTabular::SET_LTNEWPAGE:
|
2000-05-05 14:45:59 +00:00
|
|
|
what = !tabular->GetLTNewPage(actcell);
|
2000-04-19 14:42:19 +00:00
|
|
|
tabular->SetLTNewPage(actcell,what);
|
2000-05-15 14:49:36 +00:00
|
|
|
break;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-21 15:16:22 +00:00
|
|
|
void InsetTabular::RemoveTabularRow()
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
|
|
|
|
bool behind)
|
2000-05-04 08:14:34 +00:00
|
|
|
{
|
|
|
|
// the cursor.pos has to be before the inset so if it isn't now just
|
|
|
|
// reset the curor pos first!
|
|
|
|
if (cursor.pos % 2) { // behind the inset
|
|
|
|
--cursor.pos;
|
|
|
|
resetPos(bv->painter());
|
|
|
|
}
|
|
|
|
UpdatableInset * inset =
|
|
|
|
static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
2000-05-15 14:49:36 +00:00
|
|
|
if (behind) {
|
|
|
|
x = inset->x() + inset->width(bv->painter(), font);
|
2000-05-04 08:14:34 +00:00
|
|
|
y = inset->descent(bv->painter(), font);
|
2000-05-15 14:49:36 +00:00
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
inset_x = cursor.x - top_x + tabular->GetBeginningOfTextInCell(actcell);
|
|
|
|
inset_y = cursor.y;
|
|
|
|
inset->Edit(bv, x-inset_x, y-inset_y, button);
|
|
|
|
if (!the_locking_inset)
|
|
|
|
return false;
|
|
|
|
UpdateLocal(bv, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
|
|
|
|
{
|
|
|
|
InsetText * inset = tabular->GetCellInset(actcell);
|
|
|
|
int x1 = x + top_x;
|
|
|
|
|
|
|
|
if (cursor.pos % 2) { // behind the inset
|
|
|
|
return (((x+top_x) < cursor.x) &&
|
|
|
|
((x+top_x) > (cursor.x - inset->width(bv->painter(),
|
|
|
|
LyXFont(LyXFont::ALL_SANE)))));
|
|
|
|
} else {
|
|
|
|
int x2 = cursor.x + tabular->GetBeginningOfTextInCell(actcell);
|
|
|
|
return ((x1 > x2) &&
|
|
|
|
(x1 < (x2 + inset->width(bv->painter(),
|
|
|
|
LyXFont(LyXFont::ALL_SANE)))));
|
|
|
|
}
|
|
|
|
}
|
2000-05-15 14:49:36 +00:00
|
|
|
|
|
|
|
// 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 & pain, int cell) const
|
|
|
|
{
|
|
|
|
string w;
|
|
|
|
|
|
|
|
if ((w=tabular->GetPWidth(cell)).empty())
|
|
|
|
return pain.paperWidth();
|
|
|
|
return VSpace(w).inPixels( 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int InsetTabular::getMaxWidth(Painter & pain,
|
|
|
|
UpdatableInset const * inset) const
|
|
|
|
{
|
|
|
|
int cell;
|
|
|
|
int n = tabular->GetNumberOfCells();
|
|
|
|
for(cell=0; cell < n; ++cell) {
|
|
|
|
if (tabular->GetCellInset(cell) == inset)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cell >= n)
|
|
|
|
return pain.paperWidth();
|
|
|
|
int w = GetMaxWidthOfCell(pain, cell);
|
|
|
|
// this because text insets remove the xpos from the maxwidth because
|
|
|
|
// otherwise the would not break good!!!
|
|
|
|
// w += getCellXPos(cell) + tabular->GetBeginningOfTextInCell(cell);
|
|
|
|
// w += inset->x();
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InsetTabular::recomputeTextInsets(Painter & pain, const LyXFont & font) const
|
|
|
|
{
|
|
|
|
InsetText * inset;
|
|
|
|
int cx, cell;
|
|
|
|
|
|
|
|
cx = top_x;
|
|
|
|
for(int j= 0; j < tabular->columns(); ++j) {
|
|
|
|
for(int i = 0; i < tabular->rows(); ++i) {
|
|
|
|
if (tabular->IsPartOfMultiColumn(i,j))
|
|
|
|
continue;
|
|
|
|
cell = tabular->GetCellNumber(i,j);
|
|
|
|
inset = tabular->GetCellInset(cell);
|
|
|
|
inset->computeTextRows(pain);
|
|
|
|
tabular->SetWidthOfCell(cell, inset->width(pain, font));
|
|
|
|
}
|
|
|
|
cell = tabular->GetCellNumber(0, j);
|
|
|
|
cx += tabular->GetWidthOfColumn(cell);
|
|
|
|
}
|
|
|
|
}
|