#include "frontends/Dialogs.h"
#include "debug.h"
#include "lyxfunc.h"
+#include "WorkArea.h"
const int ADD_TO_HEIGHT = 2;
const int ADD_TO_TABULAR_WIDTH = 2;
using std::max;
using std::endl;
using std::swap;
+using std::max;
struct tabular_features {
Painter & pain = bv->painter();
int i, j;
int nx;
- float cx;
UpdatableInset::draw(bv, font, baseline, x, cleared);
if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
x += ADD_TO_TABULAR_WIDTH;
if (cleared) {
int cell = 0;
+ float cx;
for (i = 0; i < tabular->rows(); ++i) {
nx = int(x);
dodraw = ((baseline + tabular->GetDescentOfRow(i)) > 0) &&
lyxerr[Debug::INSETS] << "ERROR this shouldn't happen\n";
return;
}
+// LyXText::text_status st = bv->text->status;
#if 0
- LyXText::text_status st = bv->text->status;
do {
- cx = nx + tabular->GetBeginningOfTextInCell(cell);
+ float cx = nx + tabular->GetBeginningOfTextInCell(cell);
bv->text->status = st;
if (need_update == CELL) {
// clear before the inset
tabular->GetCellInset(cell)->draw(bv,font,baseline, cx, false);
} while(bv->text->status == LyXText::CHANGED_IN_DRAW);
#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) {
// clear before the inset
pain.fillRectangle(
tabular->GetAscentOfRow(i) +
tabular->GetDescentOfRow(i) - 1);
}
- tabular->GetCellInset(cell)->draw(bv,font,baseline, cx, false);
- if (bv->text->status == LyXText::CHANGED_IN_DRAW)
- return;
#endif
}
x -= ADD_TO_TABULAR_WIDTH;
the_locking_inset->InsetUnlock(bv);
}
the_locking_inset = 0;
+ if (button == 2) {
+ LocalDispatch(bv, LFUN_PASTESELECTION, "paragraph");
+ return;
+ }
if (inset_hit && bv->theLockingInset()) {
if (ActivateCellInset(bv, x, y, button))
the_locking_inset->InsetButtonPress(bv, x - inset_x,
bv->text->FinishUndo();
copySelection(bv);
break;
- case LFUN_PASTE:
- if (!hasPasteBuffer())
+ case LFUN_PASTESELECTION:
+ {
+ string clip(bv->workarea()->getClipboard());
+
+ if (clip.empty())
break;
- bv->text->SetUndo(bv->buffer(), Undo::INSERT,
+ 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,
#ifndef NEW_INSETS
- bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
- bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
+ bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
+ bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next
#else
- bv->text->cursor.par()->previous,
- bv->text->cursor.par()->next
+ bv->text->cursor.par()->previous,
+ bv->text->cursor.par()->next
#endif
);
- pasteSelection(bv);
- UpdateLocal(bv, INIT, true);
- break;
+ pasteSelection(bv);
+ UpdateLocal(bv, INIT, true);
+ break;
+ }
+ // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
default:
// we try to activate the actual inset and put this event down to
// the insets dispatch function.
bool reinit) const
{
int cell = -1;
- int maxAsc, maxDesc;
+ int maxAsc = 0;
+ int maxDesc = 0;
InsetText * inset;
bool changed = false;
// change so I'll try this to have a boost, but who knows ;)
if ((need_update != INIT) &&
(the_locking_inset == tabular->GetCellInset(actcell))) {
- maxAsc = the_locking_inset->ascent(bv, font);
- maxDesc = the_locking_inset->descent(bv, font);
+ for(int i = 0; i < tabular->columns(); ++i) {
+ 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->SetAscentOfRow(actrow, maxAsc + ADD_TO_HEIGHT) || changed;
changed = tabular->SetDescentOfRow(actrow, maxDesc + ADD_TO_HEIGHT) || changed;
return changed;
}
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;
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;
}
xpos = x;
UpdatableInset::draw(bv, f, baseline, x, cleared);
- if (!cleared && ((need_update==FULL) || (top_x!=int(x)) ||
- (top_baseline!=baseline))) {
+ // if top_x differs we have a rule down and we don't have to clear anything
+ if (!cleared && (top_x == int(x)) &&
+ ((need_update==FULL) || (top_baseline!=baseline)))
+ {
int w = insetWidth;
int h = insetAscent + insetDescent;
int ty = baseline - insetAscent;
return;
if (top_x != int(x)) {
+// printf("InsetText::draw1 -> INIT(%d)\n",insetWidth);
need_update = INIT;
top_x = int(x);
bv->text->status = LyXText::CHANGED_IN_DRAW;
if (y_offset < 0)
y_offset = y;
TEXT(bv)->first = first;
- if (cleared || !locked || (need_update == FULL)) {
+ if (cleared || !locked || (need_update==FULL) || (need_update==INIT)) {
int yf = y_offset;
y = 0;
while ((row != 0) && (yf < ph)) {
}
x += width(bv, f) - TEXT_TO_INSET_OFFSET;
if (bv->text->status==LyXText::CHANGED_IN_DRAW)
+ {
need_update = INIT;
+// printf("InsetText::draw2 -> INIT(%d)\n",insetWidth);
+ }
else if (need_update != INIT)
need_update = NONE;
}
void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
{
+// if (what == INIT)
+// printf("InsetText::UpdateLocal -> INIT(%d)\n",insetWidth);
TEXT(bv)->FullRebreak(bv);
if (need_update != INIT) {
if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
}
+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)
{
if (flag != autoBreakRows) {
// y1 is now the real beginning of row on the screen
while (row != 0 && y < y2) {
- LyXText::text_status st = text->status;
+ LyXText::text_status st = bv->text->status;
do {
- text->status = st;
+ bv->text->status = st;
#if 0
text->GetVisibleRow(owner.owner(), y + y_offset,
x_offset, row, y + text->first);
text->GetVisibleRow(bv, y + y_offset,
x_offset, row, y + text->first);
#endif
- } while (text->status == LyXText::CHANGED_IN_DRAW);
- text->status = st;
+ } while (bv->text->status == LyXText::CHANGED_IN_DRAW);
+ bv->text->status = st;
y += row->height();
row = row->next();
}
if (((y + row->height()) > 0) &&
((y - row->height()) <= static_cast<int>(owner.height()))) {
// ok there is something visible
- LyXText::text_status st = text->status;
+ LyXText::text_status st = bv->text->status;
do {
- text->status = st;
+ bv->text->status = st;
#if 0
text->GetVisibleRow(owner.owner(), y, x_offset, row,
y + text->first);
text->GetVisibleRow(bv, y, x_offset, row,
y + text->first);
#endif
- } while (text->status == LyXText::CHANGED_IN_DRAW);
- text->status = st;
+ } while (bv->text->status == LyXText::CHANGED_IN_DRAW);
+ bv->text->status = st;
}
force_clear = false;
}