Remove the wide() hack. This simplifies quite a few things...

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19834 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-08-27 14:38:29 +00:00
parent b3b6f44755
commit 3c92c2ab13
6 changed files with 15 additions and 152 deletions

View File

@ -61,8 +61,6 @@ public:
// Update the counters of this inset and of its contents // Update the counters of this inset and of its contents
virtual void updateLabels(Buffer const &, ParIterator const &); virtual void updateLabels(Buffer const &, ParIterator const &);
/// ///
virtual bool wide() const { return false; }
///
int latex(Buffer const & buf, odocstream & os, int latex(Buffer const & buf, odocstream & os,
OutputParams const &) const; OutputParams const &) const;
/// ///

View File

@ -59,8 +59,6 @@ public:
/// ///
Inset::Code lyxCode() const { return Inset::FLOAT_CODE; } Inset::Code lyxCode() const { return Inset::FLOAT_CODE; }
/// ///
virtual bool wide() const { return false; }
///
int latex(Buffer const &, odocstream &, int latex(Buffer const &, odocstream &,
OutputParams const &) const; OutputParams const &) const;
/// ///

View File

@ -31,8 +31,6 @@ public:
Inset::Code lyxCode() const { return Inset::OPTARG_CODE; } Inset::Code lyxCode() const { return Inset::OPTARG_CODE; }
/// return an message upon editing /// return an message upon editing
virtual docstring const editMessage() const; virtual docstring const editMessage() const;
///
virtual bool wide() const { return false; }
/// Standard LaTeX output -- short-circuited /// Standard LaTeX output -- short-circuited
int latex(Buffer const &, odocstream &, int latex(Buffer const &, odocstream &,

View File

@ -202,7 +202,7 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const
int const a = tm.ascent() + border_; int const a = tm.ascent() + border_;
int const h = a + tm.descent() + border_; int const h = a + tm.descent() + border_;
pi.pain.rectangle(x, y - a, pi.pain.rectangle(x, y - a,
((wide() || hasFixedWidth()) ? tm.maxWidth() : w), (hasFixedWidth() ? tm.maxWidth() : w),
h, frameColor()); h, frameColor());
} }
} }
@ -216,24 +216,12 @@ void InsetText::drawSelection(PainterInfo & pi, int x, int y) const
int const a = tm.ascent() + border_; int const a = tm.ascent() + border_;
int const h = a + tm.descent() + border_; int const h = a + tm.descent() + border_;
pi.pain.fillRectangle(x, y - a, pi.pain.fillRectangle(x, y - a,
((wide() || hasFixedWidth()) ? tm.maxWidth() : w), (hasFixedWidth() ? tm.maxWidth() : w),
h, backgroundColor()); h, backgroundColor());
text_.drawSelection(pi, x + border_, y); text_.drawSelection(pi, x + border_, y);
} }
bool InsetText::covers(BufferView const & bv, int x, int y) const
{
TextMetrics const & tm = bv.textMetrics(&text_);
return bv.coordCache().getInsets().has(this)
&& x >= xo(bv)
&& x <= xo(bv) + width() + (wide() ? tm.maxWidth() : 0)
&& y >= yo(bv) - ascent()
&& y <= yo(bv) + descent();
}
docstring const InsetText::editMessage() const docstring const InsetText::editMessage() const
{ {
return _("Opened Text Inset"); return _("Opened Text Inset");
@ -346,14 +334,6 @@ void InsetText::validate(LaTeXFeatures & features) const
} }
bool InsetText::notifyCursorLeaves(Cursor & cur)
{
if (wide())
cur.updateFlags(cur.disp_.update() | Update::Force);
return false;
}
void InsetText::cursorPos(BufferView const & bv, void InsetText::cursorPos(BufferView const & bv,
CursorSlice const & sl, bool boundary, int & x, int & y) const CursorSlice const & sl, bool boundary, int & x, int & y) const
{ {

View File

@ -55,8 +55,6 @@ public:
void draw(PainterInfo & pi, int x, int y) const; void draw(PainterInfo & pi, int x, int y) const;
/// draw inset selection /// draw inset selection
void drawSelection(PainterInfo & pi, int x, int y) const; void drawSelection(PainterInfo & pi, int x, int y) const;
/// are we inside the area covered by the inset?
virtual bool covers(BufferView const & bv, int x, int y) const;
/// ///
virtual docstring const editMessage() const; virtual docstring const editMessage() const;
/// ///
@ -75,9 +73,6 @@ public:
int docbook(Buffer const &, odocstream &, OutputParams const &) const; int docbook(Buffer const &, odocstream &, OutputParams const &) const;
/// ///
void validate(LaTeXFeatures & features) const; void validate(LaTeXFeatures & features) const;
//FIXME The following should be removed when wide is.
/// Overridden to force an update if the inset was wide().
virtual bool notifyCursorLeaves(Cursor & cur);
/// return x,y of given position relative to the inset's baseline /// return x,y of given position relative to the inset's baseline
void cursorPos(BufferView const & bv, CursorSlice const & sl, void cursorPos(BufferView const & bv, CursorSlice const & sl,
@ -137,10 +132,7 @@ public:
bool neverIndent(Buffer const &) const; bool neverIndent(Buffer const &) const;
/// ///
InsetText(InsetText const &); InsetText(InsetText const &);
///
virtual bool wide() const { return wide_inset_; }
///
void setWide(bool wide_inset) { wide_inset_ = wide_inset; }
// Update the counters of this inset and of its contents // Update the counters of this inset and of its contents
virtual void updateLabels(Buffer const &, ParIterator const &); virtual void updateLabels(Buffer const &, ParIterator const &);
@ -162,8 +154,6 @@ private:
int frame_color_; int frame_color_;
/// ///
mutable pit_type old_pit; mutable pit_type old_pit;
///
bool wide_inset_;
public: public:
/// ///

View File

@ -56,10 +56,6 @@ using std::string;
namespace { namespace {
/// Flag: do a full redraw of inside text of inset
/// Working variable indicating a full screen refresh
bool refreshInside;
/** /**
* A class used for painting an individual row of text. * A class used for painting an individual row of text.
*/ */
@ -76,7 +72,6 @@ public:
void paintFirst(); void paintFirst();
void paintLast(); void paintLast();
void paintText(); void paintText();
int maxWidth() { return max_width_; }
private: private:
void paintForeignMark(double orig_x, Font const & font, int desc = 0); void paintForeignMark(double orig_x, Font const & font, int desc = 0);
@ -112,7 +107,6 @@ private:
pit_type const pit_; pit_type const pit_;
Paragraph const & par_; Paragraph const & par_;
ParagraphMetrics const & pm_; ParagraphMetrics const & pm_;
int max_width_;
/// bidi cache, comes from outside the rowpainter because /// bidi cache, comes from outside the rowpainter because
/// rowpainters are normally created in a for loop and there only /// rowpainters are normally created in a for loop and there only
@ -140,7 +134,6 @@ RowPainter::RowPainter(PainterInfo & pi,
pars_(text.paragraphs()), pars_(text.paragraphs()),
row_(row), pit_(pit), par_(text.paragraphs()[pit]), row_(row), pit_(pit), par_(text.paragraphs()[pit]),
pm_(text_metrics_.parMetrics(pit)), pm_(text_metrics_.parMetrics(pit)),
max_width_(bv_.workWidth()),
bidi_(bidi), erased_(pi.erased_), bidi_(bidi), erased_(pi.erased_),
xo_(x), yo_(y), width_(text_metrics_.width()) xo_(x), yo_(y), width_(text_metrics_.width())
{ {
@ -168,7 +161,8 @@ Font const RowPainter::getLabelFont() const
int RowPainter::leftMargin() const int RowPainter::leftMargin() const
{ {
return text_.leftMargin(bv_.buffer(), max_width_, pit_, row_.pos()); return text_.leftMargin(bv_.buffer(), text_metrics_.width(), pit_,
row_.pos());
} }
@ -193,17 +187,9 @@ void RowPainter::paintInset(pos_type const pos, Font const & font)
int const x1 = int(x_); int const x1 = int(x_);
#endif #endif
bv_.coordCache().insets().add(inset, int(x_), yo_); bv_.coordCache().insets().add(inset, int(x_), yo_);
InsetText const * const in = inset->asTextInset(); // insets are painted completely. Recursive
// non-wide insets are painted completely. Recursive
bool tmp = refreshInside;
if (!in || !in->wide()) {
refreshInside = true;
LYXERR(Debug::PAINTING) << endl << "Paint inset fully" << endl;
}
if (refreshInside)
inset->drawSelection(pi, int(x_), yo_); inset->drawSelection(pi, int(x_), yo_);
inset->draw(pi, int(x_), yo_); inset->draw(pi, int(x_), yo_);
refreshInside = tmp;
x_ += inset->width(); x_ += inset->width();
#ifdef DEBUG_METRICS #ifdef DEBUG_METRICS
Dimension dim; Dimension dim;
@ -416,6 +402,7 @@ void RowPainter::paintFromPos(pos_type & vpos)
double const orig_x = x_; double const orig_x = x_;
if (par_.isInset(pos)) { if (par_.isInset(pos)) {
// If outer row has changed, nested insets are repaint completely.
paintInset(pos, orig_font); paintInset(pos, orig_font);
++vpos; ++vpos;
paintForeignMark(orig_x, orig_font, paintForeignMark(orig_x, orig_font,
@ -890,51 +877,6 @@ bool CursorOnRow(PainterInfo & pi, pit_type const pit,
} }
bool innerCursorOnRow(PainterInfo & pi, pit_type pit,
RowList::const_iterator rit, Text const & text)
{
// Is there a cursor inside an inset on this row, and is this inset
// the only "character" on this row
Cursor & cur = pi.base.bv->cursor();
if (rit->pos() + 1 != rit->endpos())
return false;
for (size_type d = 0; d < cur.depth(); d++) {
CursorSlice const & sl = cur[d];
if (sl.text() == &text
&& sl.pit() == pit
&& sl.pos() == rit->pos())
return d < cur.depth() - 1;
}
return false;
}
// FIXME: once wide() is obsolete, remove this as well!
bool inNarrowInset(PainterInfo & pi)
{
// check whether the current inset is nested in a non-wide inset
Cursor & cur = pi.base.bv->cursor();
Inset const * cur_in = &cur.inset();
// check all higher nested insets
for (size_type i = 1; i < cur.depth(); ++i) {
Inset * const in = &cur[i].inset();
if (in == cur_in)
// we reached the level of the current inset, so stop
return false;
else if (in) {
if (in->hasFixedWidth())
return true;
InsetText * t =
const_cast<InsetText *>(in->asTextInset());
if (t && !t->wide())
// OK, we are in a non-wide() inset
return true;
}
}
return false;
}
void paintPar void paintPar
(PainterInfo & pi, Text const & text, pit_type pit, int x, int y, (PainterInfo & pi, Text const & text, pit_type pit, int x, int y,
bool repaintAll) bool repaintAll)
@ -944,8 +886,8 @@ void paintPar
pi.base.bv->coordCache().parPos()[&text][pit] = Point(x, y); pi.base.bv->coordCache().parPos()[&text][pit] = Point(x, y);
Paragraph const & par = text.paragraphs()[pit]; TextMetrics const & tm = pi.base.bv->textMetrics(&text);
ParagraphMetrics const & pm = pi.base.bv->parMetrics(&text, pit); ParagraphMetrics const & pm = tm.parMetrics(pit);
if (pm.rows().empty()) if (pm.rows().empty())
return; return;
@ -958,39 +900,10 @@ void paintPar
size_type rowno = 0; size_type rowno = 0;
for (RowList::const_iterator rit = rb; rit != re; ++rit, ++rowno) { for (RowList::const_iterator rit = rb; rit != re; ++rit, ++rowno) {
y += rit->ascent(); y += rit->ascent();
// Allow setting of refreshInside for nested insets in
// this row only
bool tmp = refreshInside;
// Row signature; has row changed since last paint? // Row signature; has row changed since last paint?
bool row_has_changed = pm.rowChangeStatus()[rowno]; bool row_has_changed = pm.rowChangeStatus()[rowno];
bool cursor_on_row = CursorOnRow(pi, pit, rit, text); bool cursor_on_row = CursorOnRow(pi, pit, rit, text);
bool in_inset_alone_on_row =
innerCursorOnRow(pi, pit, rit, text);
bool leftEdgeFixed =
(par.getAlign() == LYX_ALIGN_LEFT ||
par.getAlign() == LYX_ALIGN_BLOCK);
bool inNarrowIns = inNarrowInset(pi);
// If this is the only object on the row, we can make it wide
//
// FIXME: there is a const_cast here because paintPar() is not supposed
// to touch the paragraph contents. So either we move this "wide"
// property out of InsetText or we localize the feature to the painting
// done here.
// JSpitzm: We should aim at removing wide() altogether while retaining
// typing speed within insets.
for (pos_type i = rit->pos() ; i != rit->endpos(); ++i) {
Inset const * const in = par.getInset(i);
if (in) {
InsetText * t = const_cast<InsetText *>(in->asTextInset());
if (t)
t->setWide(in_inset_alone_on_row
&& leftEdgeFixed
&& !inNarrowIns);
}
}
// If selection is on, the current row signature differs // If selection is on, the current row signature differs
// from cache, or cursor is inside an inset _on this row_, // from cache, or cursor is inside an inset _on this row_,
@ -1002,18 +915,9 @@ void paintPar
pi.pain.setDrawingEnabled(inside); pi.pain.setDrawingEnabled(inside);
RowPainter rp(pi, text, pit, *rit, bidi, x, y); RowPainter rp(pi, text, pit, *rit, bidi, x, y);
// Clear background of this row // Clear background of this row
// (if paragraph background was not cleared)
if (!repaintAll &&
(!(in_inset_alone_on_row && leftEdgeFixed && !inNarrowIns)
|| row_has_changed)) {
pi.pain.fillRectangle(x, y - rit->ascent(), pi.pain.fillRectangle(x, y - rit->ascent(),
rp.maxWidth(), rit->height(), tm.width(), rit->height(),
text.backgroundColor()); text.backgroundColor());
// If outer row has changed, force nested
// insets to repaint completely
if (row_has_changed)
refreshInside = true;
}
// Instrumentation for testing row cache (see also // Instrumentation for testing row cache (see also
// 12 lines lower): // 12 lines lower):
@ -1035,8 +939,6 @@ void paintPar
rp.paintLast(); rp.paintLast();
} }
y += rit->descent(); y += rit->descent();
// Restore, see above
refreshInside = tmp;
} }
// Re-enable screen drawing for future use of the painter. // Re-enable screen drawing for future use of the painter.
pi.pain.setDrawingEnabled(true); pi.pain.setDrawingEnabled(true);
@ -1074,7 +976,6 @@ void paintText(BufferView & bv,
int yy = vi.y1; int yy = vi.y1;
// draw contents // draw contents
for (pit_type pit = vi.p1; pit <= vi.p2; ++pit) { for (pit_type pit = vi.p1; pit <= vi.p2; ++pit) {
refreshInside = repaintAll;
ParagraphMetrics const & pm = bv.parMetrics(&text, pit); ParagraphMetrics const & pm = bv.parMetrics(&text, pit);
yy += pm.ascent(); yy += pm.ascent();
paintPar(pi, text, pit, 0, yy, repaintAll); paintPar(pi, text, pit, 0, yy, repaintAll);
@ -1098,13 +999,11 @@ void paintTextInset(Text const & text, PainterInfo & pi, int x, int y)
// lyxerr << " paintTextInset: y: " << y << endl; // lyxerr << " paintTextInset: y: " << y << endl;
y -= pi.base.bv->parMetrics(&text, 0).ascent(); y -= pi.base.bv->parMetrics(&text, 0).ascent();
// This flag cannot be set from within same inset:
bool repaintAll = refreshInside;
for (int pit = 0; pit < int(text.paragraphs().size()); ++pit) { for (int pit = 0; pit < int(text.paragraphs().size()); ++pit) {
ParagraphMetrics const & pmi ParagraphMetrics const & pmi
= pi.base.bv->parMetrics(&text, pit); = pi.base.bv->parMetrics(&text, pit);
y += pmi.ascent(); y += pmi.ascent();
paintPar(pi, text, pit, x, y, repaintAll); paintPar(pi, text, pit, x, y, true);
y += pmi.descent(); y += pmi.descent();
} }
} }