Abdelrazak Younes wrote:
Abdelrazak Younes wrote:
Juergen,
This patch back port the look and feel of text insets from trunk:
multi-rows or multi-paragraph Text will be automatically expanded to
the full width. This has two main benefits:
1) It optimize drawing in non-wide insets.
2) It gets rid of the wide() hack.
It works well and I've tested it with all kind of Text insets.
Hum, except tables...
Here is a better patch. There are some issues when the text is too close
to the right edge of an inset. But these issues are already in 1.5svn
and are not brought by my patch.
Abdel.
Index: insets/InsetCaption.h
===================================================================
--- insets/InsetCaption.h (revision 20564)
+++ insets/InsetCaption.h (working copy)
@@ -59,8 +59,6 @@
///
virtual bool getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus &) const;
///
- virtual bool wide() const { return false; }
- ///
int latex(Buffer const & buf, odocstream & os,
OutputParams const &) const;
///
Index: insets/InsetFloat.h
===================================================================
--- insets/InsetFloat.h (revision 20564)
+++ insets/InsetFloat.h (working copy)
@@ -61,8 +61,6 @@
///
Inset::Code lyxCode() const { return Inset::FLOAT_CODE; }
///
- virtual bool wide() const { return false; }
- ///
int latex(Buffer const &, odocstream &,
OutputParams const &) const;
///
Index: insets/InsetOptArg.h
===================================================================
--- insets/InsetOptArg.h (revision 20564)
+++ insets/InsetOptArg.h (working copy)
@@ -31,8 +31,6 @@
Inset::Code lyxCode() const { return Inset::OPTARG_CODE; }
/// return an message upon editing
virtual docstring const editMessage() const;
- ///
- virtual bool wide() const { return false; }
/// Standard LaTeX output -- short-circuited
int latex(Buffer const &, odocstream &,
Index: insets/InsetText.cpp
===================================================================
--- insets/InsetText.cpp (revision 20564)
+++ insets/InsetText.cpp (working copy)
@@ -78,7 +78,7 @@
InsetText::InsetText(BufferParams const & bp)
- : drawFrame_(false), frame_color_(Color::insetframe)
+ : drawFrame_(false), frame_color_(Color::insetframe),
fixed_width_(false)
{
paragraphs().push_back(Paragraph());
paragraphs().back().layout(bp.getTextClass().defaultLayout());
@@ -90,7 +90,7 @@
InsetText::InsetText(InsetText const & in)
- : Inset(in), text_()
+ : Inset(in), text_(), fixed_width_(fixed_width_)
{
text_.autoBreakRows_ = in.text_.autoBreakRows_;
drawFrame_ = in.drawFrame_;
@@ -174,10 +174,13 @@
font_ = mi.base.font;
// Hand font through to contained lyxtext:
text_.font_ = mi.base.font;
+ // Expand the inset if
+ fixed_width_ = text_.paragraphs().size() > 1;
if (hasFixedWidth())
tm.metrics(mi, dim, mi.base.textwidth);
else
tm.metrics(mi, dim);
+ fixed_width_ |= tm.parMetrics(0).rows().size() > 1;
dim.asc += border_;
dim.des += border_;
dim.wid += 2 * border_;
@@ -203,7 +206,7 @@
int const a = tm.ascent() + border_;
int const h = a + tm.descent() + border_;
pi.pain.rectangle(x, y - a,
- ((wide() || hasFixedWidth()) ? tm.maxWidth()
: w),
+ (hasFixedWidth() ? tm.maxWidth() : w),
h, frameColor());
}
}
@@ -217,24 +220,12 @@
int const a = tm.ascent() + border_;
int const h = a + tm.descent() + border_;
pi.pain.fillRectangle(x, y - a,
- ((wide() || hasFixedWidth()) ? tm.maxWidth() : w),
+ (hasFixedWidth() ? tm.maxWidth() : w),
h, backgroundColor());
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
{
return _("Opened Text Inset");
@@ -347,13 +338,6 @@
}
-bool InsetText::notifyCursorLeaves(Cursor & cur) {
- if(wide())
- cur.updateFlags(cur.disp_.update() | Update::Force);
- return false;
-}
-
-
void InsetText::cursorPos(BufferView const & bv,
CursorSlice const & sl, bool boundary, int & x, int & y) const
{
Index: insets/InsetText.h
===================================================================
--- insets/InsetText.h (revision 20564)
+++ insets/InsetText.h (working copy)
@@ -42,6 +42,8 @@
explicit InsetText(BufferParams const &);
///
InsetText();
+ ///
+ bool hasFixedWidth() const { return fixed_width_; }
/// empty inset to empty par
void clear();
@@ -55,8 +57,6 @@
void draw(PainterInfo & pi, int x, int y) const;
/// draw inset selection
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;
///
@@ -75,9 +75,6 @@
int docbook(Buffer const &, odocstream &, OutputParams const &) 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
void cursorPos(BufferView const & bv, CursorSlice const & sl,
@@ -137,10 +134,6 @@
bool neverIndent(Buffer const &) const;
///
InsetText(InsetText const &);
- ///
- virtual bool wide() const { return wide_inset_; }
- ///
- void setWide(bool wide_inset) { wide_inset_ = wide_inset; }
protected:
///
@@ -160,8 +153,9 @@
int frame_color_;
///
mutable pit_type old_pit;
- ///
- bool wide_inset_;
+ /// Does the inset has fixed width?
+ /// Allow horizontal maximization of the inset.
+ mutable bool fixed_width_;
public:
///
Index: rowpainter.cpp
===================================================================
--- rowpainter.cpp (revision 20568)
+++ rowpainter.cpp (working copy)
@@ -196,7 +196,7 @@
InsetText const * const in = inset->asTextInset();
// non-wide insets are painted completely. Recursive
bool tmp = refreshInside;
- if (!in || !in->wide()) {
+ if (!in) {
refreshInside = true;
}
if (refreshInside)
@@ -911,33 +911,6 @@
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
(PainterInfo & pi, Text const & text, pit_type pit, int x, int y,
bool repaintAll)
@@ -947,7 +920,6 @@
pi.base.bv->coordCache().parPos()[&text][pit] = Point(x, y);
- Paragraph const & par = text.paragraphs()[pit];
ParagraphMetrics const & pm = pi.base.bv->parMetrics(&text, pit);
if (pm.rows().empty())
return;
@@ -971,30 +943,7 @@
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
// from cache, or cursor is inside an inset _on this row_,
// then paint the row
@@ -1007,7 +956,7 @@
// Clear background of this row
// (if paragraph background was not cleared)
if (!repaintAll &&
- (!(in_inset_alone_on_row && leftEdgeFixed &&
!inNarrowIns)
+ (!(in_inset_alone_on_row)
|| row_has_changed)) {
pi.pain.fillRectangle(x, y - rit->ascent(),
rp.maxWidth(), rit->height(),