More fixes to insettabular/text (and some missing features added).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1299 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 2001-01-03 16:04:05 +00:00
parent ec64f0ded6
commit 16a5be3ecc
8 changed files with 167 additions and 33 deletions

View File

@ -1,3 +1,31 @@
2001-01-03 Juergen Vigna <jug@sad.it>
* src/insets/insettabular.C (InsetButtonPress): look for button==2
and do Clipboard Paste!
* src/insets/insettext.C (SetText): added function.
* src/insets/insettabular.C (LocalDispatch): Fixed LFUN_PASTE and
new LFUN_PASTESELECTION.
* src/insets/insettext.C (draw): don't clear if top_x changes.
* src/insets/insettabular.C (draw): clear only if the inset didn't
change in the draw routine.
* src/insets/insettext.C (width): make the width dependant on the
textWidth too.
* src/text.C (draw): comment out the UpdateInset call.
* src/screen.C (DrawOneRow):
(DrawFromTo): check for bv->text->status not text->status.
* src/insets/insettabular.C (calculate_dimensions_of_cells): calculate
dimensions of ascent-descent for the whole row.
* src/insets/insettext.C (draw): check also for need_update == INIT.
2001-01-03 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr> 2001-01-03 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* Makefile.am (EXTRA_DIST): add autogen.sh * Makefile.am (EXTRA_DIST): add autogen.sh

View File

@ -35,6 +35,7 @@
#include "frontends/Dialogs.h" #include "frontends/Dialogs.h"
#include "debug.h" #include "debug.h"
#include "lyxfunc.h" #include "lyxfunc.h"
#include "WorkArea.h"
const int ADD_TO_HEIGHT = 2; const int ADD_TO_HEIGHT = 2;
const int ADD_TO_TABULAR_WIDTH = 2; const int ADD_TO_TABULAR_WIDTH = 2;
@ -50,6 +51,7 @@ using std::ifstream;
using std::max; using std::max;
using std::endl; using std::endl;
using std::swap; using std::swap;
using std::max;
struct tabular_features { struct tabular_features {
@ -225,7 +227,6 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
Painter & pain = bv->painter(); Painter & pain = bv->painter();
int i, j; int i, j;
int nx; int nx;
float cx;
UpdatableInset::draw(bv, font, baseline, x, cleared); UpdatableInset::draw(bv, font, baseline, x, cleared);
if (!cleared && ((need_update == INIT) || (need_update == FULL) || if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
@ -253,6 +254,7 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
x += ADD_TO_TABULAR_WIDTH; x += ADD_TO_TABULAR_WIDTH;
if (cleared) { if (cleared) {
int cell = 0; int cell = 0;
float cx;
for (i = 0; i < tabular->rows(); ++i) { for (i = 0; i < tabular->rows(); ++i) {
nx = int(x); nx = int(x);
dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) && dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) &&
@ -319,10 +321,10 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n"; lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n";
return; return;
} }
// LyXText::text_status st = bv->text->status;
#if 0 #if 0
LyXText::text_status st = bv->text->status;
do { do {
cx = nx + tabular->GetBeginningOfTextInCell(cell); float cx = nx + tabular->GetBeginningOfTextInCell(cell);
bv->text->status = st; bv->text->status = st;
if (need_update == CELL) { if (need_update == CELL) {
// clear before the inset // clear before the inset
@ -346,7 +348,13 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
tabular->GetCellInset(cell)->draw(bv,font,baseline, cx, false); tabular->GetCellInset(cell)->draw(bv,font,baseline, cx, false);
} while(bv->text->status == LyXText::CHANGED_IN_DRAW); } while(bv->text->status == LyXText::CHANGED_IN_DRAW);
#else #else
cx = nx + tabular->GetBeginningOfTextInCell(cell); float dx;
float cx;
cx = dx = nx + tabular->GetBeginningOfTextInCell(cell);
tabular->GetCellInset(cell)->draw(bv,font,baseline, dx, false);
if (bv->text->status == LyXText::CHANGED_IN_DRAW)
return;
// clear only if we didn't have a change
if (need_update == CELL) { if (need_update == CELL) {
// clear before the inset // clear before the inset
pain.fillRectangle( pain.fillRectangle(
@ -366,9 +374,6 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
tabular->GetAscentOfRow(i) + tabular->GetAscentOfRow(i) +
tabular->GetDescentOfRow(i) - 1); tabular->GetDescentOfRow(i) - 1);
} }
tabular->GetCellInset(cell)->draw(bv,font,baseline, cx, false);
if (bv->text->status == LyXText::CHANGED_IN_DRAW)
return;
#endif #endif
} }
x -= ADD_TO_TABULAR_WIDTH; x -= ADD_TO_TABULAR_WIDTH;
@ -687,6 +692,10 @@ void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
the_locking_inset->InsetUnlock(bv); the_locking_inset->InsetUnlock(bv);
} }
the_locking_inset = 0; the_locking_inset = 0;
if (button == 2) {
LocalDispatch(bv, LFUN_PASTESELECTION, "paragraph");
return;
}
if (inset_hit && bv->theLockingInset()) { if (inset_hit && bv->theLockingInset()) {
if (ActivateCellInset(bv, x, y, button)) if (ActivateCellInset(bv, x, y, button))
the_locking_inset->InsetButtonPress(bv, x - inset_x, the_locking_inset->InsetButtonPress(bv, x - inset_x,
@ -954,9 +963,71 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
bv->text->FinishUndo(); bv->text->FinishUndo();
copySelection(bv); copySelection(bv);
break; break;
case LFUN_PASTE: case LFUN_PASTESELECTION:
if (!hasPasteBuffer()) {
string clip(bv->workarea()->getClipboard());
if (clip.empty())
break; break;
if (clip.find('\t') != string::npos) {
int cols = 0;
int rows = 0;
int maxCols = 0;
string::size_type p = 0;
while((p < clip.length()) &&
(p = clip.find_first_of("\t\n", p)) != string::npos)
{
switch(clip[p]) {
case '\t':
++cols;
break;
case '\n':
++rows;
maxCols = max(cols+1, maxCols);
cols = 0;
break;
}
++p;
}
delete paste_tabular;
paste_tabular = new LyXTabular(this, rows+1, maxCols);
string::size_type op = 0;
int cell = 0;
unsigned int len = clip.length();
int cells = paste_tabular->GetNumberOfCells();
p = cols = 0;
while((cell < cells) && (p < len) &&
(p = clip.find_first_of("\t\n", p)) != string::npos)
{
switch(clip[p]) {
case '\t':
paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
++cols;
++cell;
break;
case '\n':
paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
while(cols++ < maxCols)
++cell;
cols = 0;
break;
}
op = p + 1;
++p;
}
// check for the last cell if there is no trailing '\n'
if ((cell < cells) && ((op-1) < len))
paste_tabular->GetCellInset(cell)->SetText(clip.substr(op, p-op));
} else {
// so that the clipboard is used and it goes on to default
// and executes LFUN_PASTESELECTION in insettext!
delete paste_tabular;
paste_tabular = 0;
}
}
case LFUN_PASTE:
if (hasPasteBuffer()) {
bv->text->SetUndo(bv->buffer(), Undo::INSERT, bv->text->SetUndo(bv->buffer(), Undo::INSERT,
#ifndef NEW_INSETS #ifndef NEW_INSETS
bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous, bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
@ -969,6 +1040,8 @@ UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
pasteSelection(bv); pasteSelection(bv);
UpdateLocal(bv, INIT, true); UpdateLocal(bv, INIT, true);
break; break;
}
// ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
default: default:
// we try to activate the actual inset and put this event down to // we try to activate the actual inset and put this event down to
// the insets dispatch function. // the insets dispatch function.
@ -1037,7 +1110,8 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
bool reinit) const bool reinit) const
{ {
int cell = -1; int cell = -1;
int maxAsc, maxDesc; int maxAsc = 0;
int maxDesc = 0;
InsetText * inset; InsetText * inset;
bool changed = false; bool changed = false;
@ -1045,15 +1119,18 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
// change so I'll try this to have a boost, but who knows ;) // change so I'll try this to have a boost, but who knows ;)
if ((need_update != INIT) && if ((need_update != INIT) &&
(the_locking_inset == tabular->GetCellInset(actcell))) { (the_locking_inset == tabular->GetCellInset(actcell))) {
maxAsc = the_locking_inset->ascent(bv, font); for(int i = 0; i < tabular->columns(); ++i) {
maxDesc = the_locking_inset->descent(bv, font); maxAsc = max(tabular->GetCellInset(actrow, i)->ascent(bv, font),
maxAsc);
maxDesc = max(tabular->GetCellInset(actrow, i)->descent(bv, font),
maxDesc);
}
changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font)); changed = tabular->SetWidthOfCell(actcell, the_locking_inset->width(bv, font));
changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed; changed = tabular->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed; changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
return changed; return changed;
} }
for (int i = 0; i < tabular->rows(); ++i) { for (int i = 0; i < tabular->rows(); ++i) {
maxAsc = maxDesc = 0;
for (int j= 0; j < tabular->columns(); ++j) { for (int j= 0; j < tabular->columns(); ++j) {
if (tabular->IsPartOfMultiColumn(i,j)) if (tabular->IsPartOfMultiColumn(i,j))
continue; continue;

View File

@ -253,7 +253,8 @@ int InsetText::descent(BufferView * bv, LyXFont const &) const
int InsetText::width(BufferView * bv, LyXFont const &) const int InsetText::width(BufferView * bv, LyXFont const &) const
{ {
insetWidth = TEXT(bv)->width + (2 * TEXT_TO_INSET_OFFSET); insetWidth = max(textWidth(bv->painter()),
(int)TEXT(bv)->width + (2 * TEXT_TO_INSET_OFFSET));
return insetWidth; return insetWidth;
} }
@ -288,8 +289,10 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
xpos = x; xpos = x;
UpdatableInset::draw(bv, f, baseline, x, cleared); UpdatableInset::draw(bv, f, baseline, x, cleared);
if (!cleared && ((need_update==FULL) || (top_x!=int(x)) || // if top_x differs we have a rule down and we don't have to clear anything
(top_baseline!=baseline))) { if (!cleared && (top_x == int(x)) &&
((need_update==FULL) || (top_baseline!=baseline)))
{
int w = insetWidth; int w = insetWidth;
int h = insetAscent + insetDescent; int h = insetAscent + insetDescent;
int ty = baseline - insetAscent; int ty = baseline - insetAscent;
@ -310,6 +313,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
return; return;
if (top_x != int(x)) { if (top_x != int(x)) {
// printf("InsetText::draw1 -> INIT(%d)\n",insetWidth);
need_update = INIT; need_update = INIT;
top_x = int(x); top_x = int(x);
bv->text->status = LyXText::CHANGED_IN_DRAW; bv->text->status = LyXText::CHANGED_IN_DRAW;
@ -346,7 +350,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
if (y_offset < 0) if (y_offset < 0)
y_offset = y; y_offset = y;
TEXT(bv)->first = first; TEXT(bv)->first = first;
if (cleared || !locked || (need_update == FULL)) { if (cleared || !locked || (need_update==FULL) || (need_update==INIT)) {
int yf = y_offset; int yf = y_offset;
y = 0; y = 0;
while ((row != 0) && (yf < ph)) { while ((row != 0) && (yf < ph)) {
@ -384,7 +388,10 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
} }
x += width(bv, f) - TEXT_TO_INSET_OFFSET; x += width(bv, f) - TEXT_TO_INSET_OFFSET;
if (bv->text->status==LyXText::CHANGED_IN_DRAW) if (bv->text->status==LyXText::CHANGED_IN_DRAW)
{
need_update = INIT; need_update = INIT;
// printf("InsetText::draw2 -> INIT(%d)\n",insetWidth);
}
else if (need_update != INIT) else if (need_update != INIT)
need_update = NONE; need_update = NONE;
} }
@ -446,6 +453,8 @@ void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty) void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
{ {
// if (what == INIT)
// printf("InsetText::UpdateLocal -> INIT(%d)\n",insetWidth);
TEXT(bv)->FullRebreak(bv); TEXT(bv)->FullRebreak(bv);
if (need_update != INIT) { if (need_update != INIT) {
if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH) if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
@ -1432,6 +1441,15 @@ void InsetText::SetParagraphData(LyXParagraph *p)
} }
void InsetText::SetText(string const & data)
{
clear();
LyXFont font(LyXFont::ALL_SANE);
for(unsigned int i=0; i < data.length(); ++i)
par->InsertChar(i, data[i], font);
}
void InsetText::SetAutoBreakRows(bool flag) void InsetText::SetAutoBreakRows(bool flag)
{ {
if (flag != autoBreakRows) { if (flag != autoBreakRows) {

View File

@ -158,6 +158,8 @@ public:
/// ///
void SetParagraphData(LyXParagraph *); void SetParagraphData(LyXParagraph *);
/// ///
void SetText(string const &);
///
void SetAutoBreakRows(bool); void SetAutoBreakRows(bool);
/// ///
void SetDrawFrame(BufferView *, DrawFrame); void SetDrawFrame(BufferView *, DrawFrame);

View File

@ -113,9 +113,9 @@ void LyXScreen::DrawFromTo(LyXText * text, BufferView * bv,
// y1 is now the real beginning of row on the screen // y1 is now the real beginning of row on the screen
while (row != 0 && y < y2) { while (row != 0 && y < y2) {
LyXText::text_status st = text->status; LyXText::text_status st = bv->text->status;
do { do {
text->status = st; bv->text->status = st;
#if 0 #if 0
text->GetVisibleRow(owner.owner(), y + y_offset, text->GetVisibleRow(owner.owner(), y + y_offset,
x_offset, row, y + text->first); x_offset, row, y + text->first);
@ -123,8 +123,8 @@ void LyXScreen::DrawFromTo(LyXText * text, BufferView * bv,
text->GetVisibleRow(bv, y + y_offset, text->GetVisibleRow(bv, y + y_offset,
x_offset, row, y + text->first); x_offset, row, y + text->first);
#endif #endif
} while (text->status == LyXText::CHANGED_IN_DRAW); } while (bv->text->status == LyXText::CHANGED_IN_DRAW);
text->status = st; bv->text->status = st;
y += row->height(); y += row->height();
row = row->next(); row = row->next();
} }
@ -148,9 +148,9 @@ void LyXScreen::DrawOneRow(LyXText * text, BufferView * bv, Row * row,
if (((y + row->height()) > 0) && if (((y + row->height()) > 0) &&
((y - row->height()) <= static_cast<int>(owner.height()))) { ((y - row->height()) <= static_cast<int>(owner.height()))) {
// ok there is something visible // ok there is something visible
LyXText::text_status st = text->status; LyXText::text_status st = bv->text->status;
do { do {
text->status = st; bv->text->status = st;
#if 0 #if 0
text->GetVisibleRow(owner.owner(), y, x_offset, row, text->GetVisibleRow(owner.owner(), y, x_offset, row,
y + text->first); y + text->first);
@ -158,8 +158,8 @@ void LyXScreen::DrawOneRow(LyXText * text, BufferView * bv, Row * row,
text->GetVisibleRow(bv, y, x_offset, row, text->GetVisibleRow(bv, y, x_offset, row,
y + text->first); y + text->first);
#endif #endif
} while (text->status == LyXText::CHANGED_IN_DRAW); } while (bv->text->status == LyXText::CHANGED_IN_DRAW);
text->status = st; bv->text->status = st;
} }
force_clear = false; force_clear = false;
} }

View File

@ -2548,6 +2548,12 @@ InsetText * LyXTabular::GetCellInset(int cell) const
} }
InsetText * LyXTabular::GetCellInset(int row, int column) const
{
return GetCellInset(GetCellNumber(row, column));
}
void LyXTabular::Validate(LaTeXFeatures & features) const void LyXTabular::Validate(LaTeXFeatures & features) const
{ {
if (IsLongTabular()) if (IsLongTabular())

View File

@ -365,6 +365,7 @@ public:
bool GetLTNewPage(int cell) const; bool GetLTNewPage(int cell) const;
/// ///
InsetText * GetCellInset(int cell) const; InsetText * GetCellInset(int cell) const;
InsetText * GetCellInset(int row, int column) const;
/// ///
int rows() const { return rows_; } int rows() const { return rows_; }
/// ///

View File

@ -504,10 +504,12 @@ void LyXText::draw(BufferView * bview, Row const * row,
// tmpinset->update(bview, font, false); // tmpinset->update(bview, font, false);
tmpinset->draw(bview, font, offset+row->baseline(), x, tmpinset->draw(bview, font, offset+row->baseline(), x,
cleared); cleared);
#ifdef SEEMS_TO_BE_NOT_NEEDED
if (status == CHANGED_IN_DRAW) { if (status == CHANGED_IN_DRAW) {
UpdateInset(bview, tmpinset); UpdateInset(bview, tmpinset);
status = CHANGED_IN_DRAW; status = CHANGED_IN_DRAW;
} }
#endif
} }
++vpos; ++vpos;