#include "lyxtext.h"
#include "support/textutils.h"
#include "insets/insetbib.h"
+#include "insets/insettext.h"
#include "lyx_gui_misc.h"
#include "gettext.h"
#include "bufferparams.h"
int LyXText::workWidth(BufferView * bview) const
{
if (inset_owner) {
-#if 1
- return inset_owner->getMaxWidth(bview->painter(), inset_owner);
-#else
- LyXFont font(LyXFont::ALL_SANE);
- return inset_owner->width(bview->painter(), font);
-#endif
+ return inset_owner->textWidth(bview->painter());
}
return bview->workWidth();
}
} else if (IsHfillChar(c)) {
return 3; /* Because of the representation
* as vertical lines */
+#ifndef NEW_INSETS
} else if (c == LyXParagraph::META_FOOTNOTE ||
c == LyXParagraph::META_MARGIN ||
c == LyXParagraph::META_FIG ||
font.decSize();
font.decSize();
return lyxfont::width(fs, font);
+#endif
} else if (c == LyXParagraph::META_INSET) {
- Inset * tmpinset= par->GetInset(pos);
- if (tmpinset)
- return par->GetInset(pos)->width(bview->painter(),
- font);
- else
+ Inset * tmpinset = par->GetInset(pos);
+ if (tmpinset) {
+ tmpinset->update(bview, font);
+ return tmpinset->width(bview->painter(), font);
+ } else
return 0;
} else if (IsSeparatorChar(c))
return rtl != rtl2;
}
+
bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
LyXParagraph::size_type pos,
LyXFont const & font) const
void LyXText::draw(BufferView * bview, Row const * row,
LyXParagraph::size_type & vpos,
- int offset, float & x)
+ int offset, float & x, bool cleared)
{
Painter & pain = bview->painter();
LyXFont font = GetFont(bview->buffer(), row->par(), pos);
LyXFont font2 = font;
-
+#ifndef NEW_INSETS
if (c == LyXParagraph::META_FOOTNOTE
|| c == LyXParagraph::META_MARGIN
|| c == LyXParagraph::META_FIG
++vpos;
return;
- } else if (c == LyXParagraph::META_INSET) {
- Inset const * tmpinset = row->par()->GetInset(pos);
+ } else
+#endif
+ if (c == LyXParagraph::META_INSET) {
+ Inset * tmpinset = row->par()->GetInset(pos);
if (tmpinset) {
- tmpinset->draw(bview->painter(), font,
- offset + row->baseline(), x);
+ tmpinset->update(bview, font, false);
+ tmpinset->draw(bview, font, offset+row->baseline(), x,
+ cleared);
}
++vpos;
textclasslist
.TextClass(bview->buffer()->params.textclass)
.defaultfont());
-
+#ifndef NEW_INSETS
if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
LyXFont font(LyXFont::ALL_SANE);
font.setSize(LyXFont::SIZE_SMALL);
x += lyxfont::width("Mwide-figM", font)
+ LYX_PAPER_MARGIN/2;
}
-
+#endif
// this is the way, LyX handles the LaTeX-Environments.
// I have had this idea very late, so it seems to be a
// later added hack and this is true
textclasslist
.TextClass(buf->params.textclass)
.defaultfont());
-
+
+#ifndef NEW_INSETS
if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
x += LYX_PAPER_MARGIN / 2;
}
-
+#endif
// this is the way, LyX handles the LaTeX-Environments.
// I have had this idea very late, so it seems to be a
// later added hack and this is true
}
+#ifndef NEW_TABULAR
/* table stuff -- begin*/
int LyXText::NumberOfCell(LyXParagraph * par,
LyXParagraph::size_type pos) const
}
-#ifndef NEW_TABULAR
bool LyXText::HitInTable(BufferView * bview, Row * row, int x) const
{
float tmpx;
fill_hfill, fill_label_hfill, false);
return (x > tmpx && x < tmpx + row->par()->table->WidthOfTable());
}
-#endif
bool LyXText::MouseHitInTable(BufferView * bview, int x, long y) const
/* table stuff -- end*/
+#endif
// get the next breakpoint in a given paragraph
par->Last();
// this is the usual handling
int x = LeftMargin(bview, row);
- while (x < width && i < last) {
+ bool doitonetime = true;
+ while (doitonetime || ((x < width) && (i < last))) {
+ doitonetime = false;
char c = par->GetChar(i);
if (IsNewlineChar(c)) {
last_separator = i;
x = width; // this means break
} else if (c == LyXParagraph::META_INSET &&
- par->GetInset(i) && par->GetInset(i)->display()){
+ par->GetInset(i)) {
+
// check wether a Display() inset is
// valid here. if not, change it to
// non-display
- if (layout.isCommand()
- || (layout.labeltype == LABEL_MANUAL
- && i < BeginningOfMainBody(bview->buffer(), par))){
+ if (par->GetInset(i)->display() &&
+ (layout.isCommand() ||
+ ((layout.labeltype == LABEL_MANUAL) &&
+ (i < BeginningOfMainBody(bview->buffer(), par))))) {
// display istn't allowd
par->GetInset(i)->display(false);
x += SingleWidth(bview, par, i, c);
- } else {
- // inset is display. So break the line here
- if (i == pos){
+ } else if (par->GetInset(i)->display() ||
+ par->GetInset(i)->needFullRow()) {
+ // So break the line here
+ if (i == pos) {
if (pos < last-1) {
last_separator = i;
if (IsLineSeparatorChar(par->GetChar(i+1)))
} else
last_separator = i - 1;
x = width; // this means break
+ } else {
+#if 0
+ last_separator = i;
+ x += width;
+#else
+ x += SingleWidth(bview, par, i, c);
+#endif
}
} else {
if (IsLineSeparatorChar(c))
int maxdesc = int(lyxfont::maxDescent(font) *
layout.spacing.getValue() *
spacing_val);
-
int pos_end = RowLast(row_ptr);
-
int labeladdon = 0;
+ int maxwidth = 0;
// Check if any insets are larger
for (pos = row_ptr->pos(); pos <= pos_end; ++pos) {
- if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
- tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
- tmpinset = row_ptr->par()->GetInset(pos);
- if (tmpinset) {
- asc = tmpinset->ascent(bview->painter(), tmpfont);
- desc = tmpinset->descent(bview->painter(), tmpfont);
- if (asc > maxasc)
- maxasc = asc;
- if (desc > maxdesc)
- maxdesc = desc;
- }
- }
+ if (row_ptr->par()->GetChar(pos) == LyXParagraph::META_INSET) {
+ tmpfont = GetFont(bview->buffer(), row_ptr->par(), pos);
+ tmpinset = row_ptr->par()->GetInset(pos);
+ if (tmpinset) {
+ tmpinset->update(bview, tmpfont);
+ asc = tmpinset->ascent(bview->painter(), tmpfont);
+ desc = tmpinset->descent(bview->painter(), tmpfont);
+ maxwidth += tmpinset->width(bview->painter(), tmpfont);
+ maxasc = max(maxasc, asc);
+ maxdesc = max(maxdesc, desc);
+ }
+ } else {
+ maxwidth += SingleWidth(bview, row_ptr->par(), pos);
+ }
}
// Check if any custom fonts are larger (Asger)
row_ptr->baseline(maxasc + labeladdon);
height += row_ptr->height();
+ float x, dummy;
+ PrepareToPrint(bview, row_ptr, x, dummy, dummy, dummy);
+ row_ptr->width(maxwidth+x);
+ if (inset_owner) {
+ Row * r = firstrow;
+ width = max(0,workWidth(bview));
+ while(r) {
+ if (r->width() > width)
+ width = r->width();
+ r = r->next();
+ }
+ }
}
}
+#ifndef NEW_INSETS
void LyXText::OpenFootnote(BufferView * bview)
{
LyXParagraph * endpar,* tmppar;
SetCursor(bview, par->next, 0);
sel_cursor = cursor;
}
-
+#endif
+
+#ifndef NEW_TABULAR
/* table stuff -- begin*/
void LyXText::TableFeatures(BufferView * bview, int feature, string const & val) const
Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
LyXFont font(LyXFont::ALL_INHERIT,lang);
for (int i = 0; i < number; ++i) {
- cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
- cursor.par()->SetFont(pos, font);
+ cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
}
/* append the row into the table */
Language const * lang = cursor.par()->getParLanguage(bview->buffer()->params);
LyXFont font(LyXFont::ALL_INHERIT,lang);
for (int i = 0; i < number; ++i) {
- cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
- cursor.par()->SetFont(pos, font);
+ cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
}
/* append the row into the table */
do{
if (pos && (cursor.par()->IsNewline(pos-1))){
if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
- cursor.par()->InsertChar(pos, LyXParagraph::META_NEWLINE);
- cursor.par()->SetFont(pos, font);
+ cursor.par()->InsertChar(pos,
+ LyXParagraph::META_NEWLINE,
+ font);
if (pos <= cursor.pos())
cursor.pos(cursor.pos() + 1);
++pos;
This saves one byte memory per table ;-) */
if (cursor.par()->table->AppendCellAfterCell(cell_org, cell)) {
LyXParagraph::size_type last = cursor.par()->Last();
- cursor.par()->InsertChar(last, LyXParagraph::META_NEWLINE);
- cursor.par()->SetFont(last, font);
+ cursor.par()->InsertChar(last,
+ LyXParagraph::META_NEWLINE, font);
}
/* append the column into the table */
}
/* table stuff -- end*/
+#endif
// Just a macro to make some thing easier.
// the display inset stuff
if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
&& cursor.row()->par()->GetInset(cursor.row()->pos())
- && cursor.row()->par()->GetInset(cursor.row()->pos())->display())
+ && (cursor.row()->par()->GetInset(cursor.row()->pos())->display() ||
+ cursor.row()->par()->GetInset(cursor.row()->pos())->needFullRow()))
cursor.row()->fill(-1); // to force a new break
// get the cursor row fist
}
}
+
void LyXText::PrepareToPrint(BufferView * bview,
Row * row, float & x,
float & fill_separator,
fill_separator = 0;
fill_label_hfill = 0;
+#ifndef NEW_INSETS
bool is_rtl = row->par()->isRightToLeftPar(bview->buffer()->params);
if (is_rtl) {
font.setSize(LyXFont::SIZE_SMALL);
x += lyxfont::width("Mwide-figM", font);
}
- } else if (workWidth(bview) > 0)
+ } else
+#endif
+ if (workWidth(bview) > 0)
x = LeftMargin(bview, row);
else
x = 0;
SetCursor(bview, cursor.par(), cursor.pos() );
// finally set the selection
- SetSelection(bview);
+ SetSelection();
}
SetCursor(bview, cursor.par(), cursor.pos());
// finally set the selection
- SetSelection(bview);
+ SetSelection();
}
SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
sel_cursor = cursor;
cursor = tmpcursor;
- SetSelection(bview);
+ SetSelection();
/* -----> Great, CutSelection() gets rid of multiple spaces. */
CutSelection(bview);
SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
sel_cursor = cursor;
cursor = tmpcursor;
- SetSelection(bview);
+ SetSelection();
CutSelection(bview);
}
}
SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
sel_cursor = cursor;
cursor = tmpcursor;
- SetSelection(bview);
+ SetSelection();
// What is this test for ??? (JMarc)
if (!selection) {
DeleteWordForward(bview);
return;
// force complete redo when erasing display insets
// this is a cruel method but safe..... Matthias
- if (cursor.par()->GetInset(cursor.pos())->display()){
+ if (cursor.par()->GetInset(cursor.pos())->display() ||
+ cursor.par()->GetInset(cursor.pos())->needFullRow()) {
cursor.par()->Erase(cursor.pos());
RedoParagraph(bview);
return;
void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
- Row * row_ptr, long y)
+ Row * row_ptr, long y, bool cleared)
{
/* returns a printed row */
Painter & pain = bview->painter();
int y_top, y_bottom;
float fill_separator, fill_hfill, fill_label_hfill;
- LyXFont font;
+ LyXFont font(LyXFont::ALL_SANE);
int maxdesc;
if (row_ptr->height() <= 0) {
lyxerr << "LYX_ERROR: row.height: "
PrepareToPrint(bview, row_ptr, x, fill_separator,
fill_hfill, fill_label_hfill);
+ if (inset_owner && (x < 0))
+ x = 0;
x += x_offset;
// clear the area where we want to paint/print
- int ww = workWidth(bview);
- if (ww < 0)
- ww = bview->workWidth();
- if (bv_owner)
- pain.fillRectangle(x_offset, y_offset, ww, row_ptr->height());
+ int ww;
+ ww = bview->workWidth();
+
+ bool clear_area = true;
+ Inset * inset = 0;
+
+ if ((last == row_ptr->pos()) &&
+ (row_ptr->par()->GetChar(row_ptr->pos()) == LyXParagraph::META_INSET) &&
+ (inset=row_ptr->par()->GetInset(row_ptr->pos())))
+ {
+ clear_area = inset->doClearArea();
+ }
+ if (cleared) { // we don't need to clear it's already done!!!
+ clear_area = true;
+ } else if (clear_area) {
+ int w;
+ if (inset_owner)
+ w = inset_owner->width(bview->painter(), font);
+ else
+ w = ww;
+ pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
+ } else if (inset != 0) {
+ int h = row_ptr->baseline() - inset->ascent(pain, font);
+ if (h > 0) {
+ int w;
+ if (inset_owner)
+ w = inset_owner->width(bview->painter(), font);
+ else
+ w = ww;
+ pain.fillRectangle(x_offset, y_offset, w, h);
+ }
+ }
if (selection) {
/* selection code */
if (sel_start_cursor.row() == row_ptr &&
sel_end_cursor.row() == row_ptr) {
if (sel_start_cursor.x() < sel_end_cursor.x())
- pain.fillRectangle(sel_start_cursor.x(), y_offset,
+ pain.fillRectangle(x_offset + sel_start_cursor.x(),
+ y_offset,
sel_end_cursor.x() - sel_start_cursor.x(),
row_ptr->height(),
LColor::selection);
else
- pain.fillRectangle(sel_end_cursor.x(), y_offset,
+ pain.fillRectangle(x_offset + sel_end_cursor.x(),
+ y_offset,
sel_start_cursor.x() - sel_end_cursor.x(),
row_ptr->height(),
LColor::selection);
} else if (sel_start_cursor.row() == row_ptr) {
if (is_rtl)
- pain.fillRectangle(0, y_offset,
+ pain.fillRectangle(x_offset, y_offset,
sel_start_cursor.x(),
row_ptr->height(),
LColor::selection);
else
- pain.fillRectangle(sel_start_cursor.x(), y_offset,
+ pain.fillRectangle(x_offset + sel_start_cursor.x(),
+ y_offset,
ww - sel_start_cursor.x(),
row_ptr->height(),
LColor::selection);
} else if (sel_end_cursor.row() == row_ptr) {
if (is_rtl)
- pain.fillRectangle(sel_end_cursor.x(), y_offset,
+ pain.fillRectangle(x_offset + sel_end_cursor.x(),
+ y_offset,
ww - sel_end_cursor.x(),
row_ptr->height(),
LColor::selection);
else
- pain.fillRectangle(0, y_offset,
+ pain.fillRectangle(x_offset, y_offset,
sel_end_cursor.x(),
row_ptr->height(),
LColor::selection);
} else if (y > long(sel_start_cursor.y())
&& y < long(sel_end_cursor.y())) {
- pain.fillRectangle(0, y_offset,
- ww, row_ptr->height(),
+ pain.fillRectangle(x_offset, y_offset, ww,
+ row_ptr->height(),
LColor::selection);
}
} else if ( sel_start_cursor.row() != row_ptr &&
sel_end_cursor.row() != row_ptr &&
y > long(sel_start_cursor.y())
&& y < long(sel_end_cursor.y())) {
- pain.fillRectangle(0, y_offset, ww, row_ptr->height(),
+ pain.fillRectangle(x_offset, y_offset, ww,
+ row_ptr->height(),
LColor::selection);
} else if (sel_start_cursor.row() == row_ptr ||
sel_end_cursor.row() == row_ptr) {
#endif
if ( (sel_start_cursor.row() != row_ptr && !is_rtl) ||
(sel_end_cursor.row() != row_ptr && is_rtl))
- pain.fillRectangle(0, y_offset,
+ pain.fillRectangle(x_offset, y_offset,
int(tmpx),
row_ptr->height(),
LColor::selection);
sel_start_cursor.pos() <= pos) &&
(sel_end_cursor.row() != row_ptr ||
pos < sel_end_cursor.pos()) )
- pain.fillRectangle(int(old_tmpx), y_offset,
+ pain.fillRectangle(x_offset + int(old_tmpx),
+ y_offset,
int(tmpx - old_tmpx + 1),
row_ptr->height(),
LColor::selection);
sel_start_cursor.pos() <= pos) &&
(sel_end_cursor.row() != row_ptr ||
pos < sel_end_cursor.pos()) )
- pain.fillRectangle(int(old_tmpx), y_offset,
+ pain.fillRectangle(x_offset + int(old_tmpx),
+ y_offset,
int(tmpx - old_tmpx + 1),
row_ptr->height(),
- LColor::selection);
+ LColor::selection);
}
#ifndef NEW_TABULAR
}
#endif
if ( (sel_start_cursor.row() != row_ptr && is_rtl) ||
(sel_end_cursor.row() != row_ptr && !is_rtl) )
- pain.fillRectangle(int(tmpx), y_offset,
+ pain.fillRectangle(x_offset + int(tmpx),
+ y_offset,
int(ww - tmpx),
row_ptr->height(),
LColor::selection);
}
int box_x = 0;
+#ifndef NEW_INSETS
if (row_ptr->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
LyXFont font(LyXFont::ALL_SANE);
font.setSize(LyXFont::SIZE_FOOTNOTE);
workWidth(bview) - LYX_PAPER_MARGIN,
y_offset, LColor::footnote);
}
-
+#endif
// Draw appendix lines
LyXParagraph * firstpar = row_ptr->par()->FirstPhysicalPar();
if (firstpar->appendix){
else
tmpx = x - lyxfont::width(layout.labelsep, font)
- row_ptr->par()->bibkey->width(bview->painter(), font);
- row_ptr->par()->bibkey->draw(pain,
- font,
+ row_ptr->par()->bibkey->draw(bview, font,
y_offset + row_ptr->baseline(),
- tmpx);
+ tmpx, clear_area);
}
}
row_ptr->par(), pos);
++vpos;
} else
- draw(bview, row_ptr, vpos, y_offset, x);
+ draw(bview, row_ptr, vpos, y_offset, x, clear_area);
}
/* do not forget the very last cell. This has no NEWLINE so
x += fill_separator;
++vpos;
} else
- draw(bview, row_ptr, vpos, y_offset, x);
+ draw(bview, row_ptr, vpos, y_offset, x, clear_area);
}
#ifndef NEW_TABULAR
}
#endif
- // Jürgen!!! FIX This! (NOW!!!) (please)
- width = max(x - x_offset, float(width));
}
return c;
}
-
+
+#ifndef NEW_INSETS
/* turn the selection into a new environment. If there is no selection,
* create an empty environment */
void LyXText::InsertFootnoteEnvironment(BufferView * bview,
ClearSelection();
}
-
+#endif
+
// returns pointer to a specified row
Row * LyXText::GetRow(LyXParagraph * par,