mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Revert "Linearize macros in box edit mode too."
Guillaume tells me that there are problems. We'll return to it later.
This reverts commit 0140348118
.
This commit is contained in:
parent
33b696c8ac
commit
fc02744119
@ -199,6 +199,8 @@ public:
|
||||
///
|
||||
virtual bool showInsetDialog(BufferView *) const;
|
||||
|
||||
// The possible marker types for insets
|
||||
enum marker_type { NO_MARKER, MARKER2, MARKER };
|
||||
/// draw two angular markers
|
||||
void drawMarkers(PainterInfo & pi, int x, int y) const;
|
||||
/// draw four angular markers
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
explicit CommandInset(Buffer * buf, docstring const & name,
|
||||
bool needs_math_mode = true);
|
||||
///
|
||||
marker_type marker(BufferView const *) const { return NO_MARKER; }
|
||||
marker_type marker() const { return NO_MARKER; }
|
||||
///
|
||||
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
||||
///
|
||||
|
@ -58,7 +58,7 @@ MathClass InsetMath::mathClass() const
|
||||
}
|
||||
|
||||
|
||||
InsetMath::marker_type InsetMath::marker(BufferView const *) const
|
||||
InsetMath::marker_type InsetMath::marker() const
|
||||
{
|
||||
return nargs() > 0 ? MARKER : NO_MARKER;
|
||||
}
|
||||
@ -68,7 +68,7 @@ bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
|
||||
{
|
||||
MathRow::Element e(mi, MathRow::INSET, mathClass());
|
||||
e.inset = this;
|
||||
e.marker = mi.base.macro_nesting ? NO_MARKER : marker(mi.base.bv);
|
||||
e.marker = mi.base.macro_nesting ? NO_MARKER : marker();
|
||||
mrow.push_back(e);
|
||||
return true;
|
||||
}
|
||||
|
@ -114,10 +114,8 @@ public:
|
||||
/// this is overridden by specific insets
|
||||
virtual mode_type currentMode() const { return MATH_MODE; }
|
||||
|
||||
// The possible marker types for math insets
|
||||
enum marker_type { NO_MARKER, MARKER2, MARKER, BOX_MARKER };
|
||||
/// this is overridden by insets with specific edit marker type
|
||||
virtual marker_type marker(BufferView const *) const;
|
||||
virtual marker_type marker() const;
|
||||
|
||||
/// the ascent of the inset above the baseline
|
||||
/// compute the size of the object for text based drawing
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
///
|
||||
mode_type currentMode() const { return TEXT_MODE; }
|
||||
///
|
||||
marker_type marker(BufferView const *) const { return NO_MARKER; }
|
||||
marker_type marker() const { return NO_MARKER; }
|
||||
///
|
||||
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
||||
///
|
||||
@ -118,7 +118,7 @@ public:
|
||||
///
|
||||
InsetMathBoxed(Buffer * buf);
|
||||
///
|
||||
marker_type marker(BufferView const *) const { return NO_MARKER; }
|
||||
marker_type marker() const { return NO_MARKER; }
|
||||
///
|
||||
void validate(LaTeXFeatures & features) const;
|
||||
///
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
///
|
||||
MathClass mathClass() const { return MC_INNER; }
|
||||
///
|
||||
marker_type marker(BufferView const *) const { return NO_MARKER; }
|
||||
marker_type marker() const { return NO_MARKER; }
|
||||
/// is it (...)?
|
||||
bool isParenthesis() const;
|
||||
/// is it [...]?
|
||||
|
@ -125,7 +125,7 @@ public:
|
||||
/// Generalized fractions are of inner class (see The TeXbook, p.292)
|
||||
MathClass mathClass() const { return MC_INNER; }
|
||||
///
|
||||
marker_type marker(BufferView const *) const { return MARKER2; }
|
||||
marker_type marker() const { return MARKER2; }
|
||||
///
|
||||
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
||||
///
|
||||
|
@ -276,8 +276,8 @@ void MathData::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
sshift_ = xascent / 4;
|
||||
|
||||
MathRow mrow(mi, this);
|
||||
mrow.metrics(mi, dim);
|
||||
mrow_cache_[mi.base.bv] = mrow;
|
||||
mrow.metrics(mi, dim);
|
||||
kerning_ = mrow.kerning(mi.base.bv);
|
||||
|
||||
// Cache the dimension.
|
||||
|
@ -67,7 +67,7 @@ public:
|
||||
///
|
||||
MathMacro const * owner() { return mathMacro_; }
|
||||
///
|
||||
marker_type marker(BufferView const *) const { return NO_MARKER; }
|
||||
marker_type marker() const { return NO_MARKER; }
|
||||
///
|
||||
InsetCode lyxCode() const { return ARGUMENT_PROXY_CODE; }
|
||||
/// The math data to use for display
|
||||
@ -331,7 +331,7 @@ bool MathMacro::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
|
||||
// - editing with parameter list
|
||||
// - editing with box around macro
|
||||
if (displayMode() != MathMacro::DISPLAY_NORMAL
|
||||
|| (d->editing_[mi.base.bv] && lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST))
|
||||
|| (d->editing_[mi.base.bv] && lyxrc.macro_edit_style != LyXRC::MACRO_EDIT_INLINE))
|
||||
return InsetMath::addToMathRow(mrow, mi);
|
||||
|
||||
/// The macro nesting can change display of insets. Change it locally.
|
||||
@ -339,7 +339,7 @@ bool MathMacro::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
|
||||
|
||||
MathRow::Element e_beg(mi, MathRow::BEGIN);
|
||||
e_beg.inset = this;
|
||||
e_beg.marker = (d->nesting_ == 1) ? marker(mi.base.bv) : NO_MARKER;
|
||||
e_beg.marker = (d->nesting_ == 1 && nargs()) ? marker() : NO_MARKER;
|
||||
mrow.push_back(e_beg);
|
||||
|
||||
d->macro_->lock();
|
||||
@ -358,7 +358,6 @@ bool MathMacro::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
|
||||
|
||||
MathRow::Element e_end(mi, MathRow::END);
|
||||
e_end.inset = this;
|
||||
e_end.marker = (d->nesting_ == 1) ? marker(mi.base.bv) : NO_MARKER;
|
||||
mrow.push_back(e_end);
|
||||
|
||||
return has_contents;
|
||||
@ -486,29 +485,24 @@ bool MathMacro::editMetrics(BufferView const * bv) const
|
||||
}
|
||||
|
||||
|
||||
InsetMath::marker_type MathMacro::marker(BufferView const * bv) const
|
||||
Inset::marker_type MathMacro::marker() const
|
||||
{
|
||||
if (nargs() == 0)
|
||||
return NO_MARKER;
|
||||
|
||||
switch (d->displayMode_) {
|
||||
case DISPLAY_INIT:
|
||||
case DISPLAY_INTERACTIVE_INIT:
|
||||
return NO_MARKER;
|
||||
case DISPLAY_UNFOLDED:
|
||||
return MARKER;
|
||||
case DISPLAY_NORMAL:
|
||||
default:
|
||||
switch (lyxrc.macro_edit_style) {
|
||||
case LyXRC::MACRO_EDIT_INLINE:
|
||||
return MARKER;
|
||||
case LyXRC::MACRO_EDIT_INLINE_BOX:
|
||||
return d->editing_[bv] ? BOX_MARKER : MARKER;
|
||||
case LyXRC::MACRO_EDIT_LIST:
|
||||
return MARKER2;
|
||||
case LyXRC::MACRO_EDIT_INLINE_BOX:
|
||||
return NO_MARKER;
|
||||
default:
|
||||
return MARKER;
|
||||
}
|
||||
}
|
||||
// please gcc 4.6
|
||||
return NO_MARKER;
|
||||
}
|
||||
|
||||
|
||||
@ -572,8 +566,38 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
dim.des += 1;
|
||||
dim.wid += 2;
|
||||
} else {
|
||||
// We should not be here, since the macro is linearized in this case.
|
||||
LBUFERR(false);
|
||||
LBUFERR(d->macro_);
|
||||
|
||||
// calculate metrics, hoping that all cells are seen
|
||||
d->macro_->lock();
|
||||
d->expanded_.metrics(mi, dim);
|
||||
|
||||
// otherwise do a manual metrics call
|
||||
CoordCache & coords = mi.base.bv->coordCache();
|
||||
for (idx_type i = 0; i < nargs(); ++i) {
|
||||
if (!coords.getArrays().hasDim(&cell(i))) {
|
||||
Dimension tdim;
|
||||
cell(i).metrics(mi, tdim);
|
||||
}
|
||||
}
|
||||
d->macro_->unlock();
|
||||
|
||||
// calculate dimension with label while editing
|
||||
if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX
|
||||
&& d->editing_[mi.base.bv]) {
|
||||
FontInfo font = mi.base.font;
|
||||
augmentFont(font, "lyxtex");
|
||||
Dimension namedim;
|
||||
mathed_string_dim(font, name(), namedim);
|
||||
#if 0
|
||||
dim.wid += 2 + namedim.wid + 2 + 2;
|
||||
dim.asc = max(dim.asc, namedim.asc) + 2;
|
||||
dim.des = max(dim.des, namedim.des) + 2;
|
||||
#endif
|
||||
dim.wid = max(1 + namedim.wid + 1, 2 + dim.wid + 2);
|
||||
dim.asc += 1 + namedim.height() + 1;
|
||||
dim.des += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -743,8 +767,34 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
|
||||
pi.pain.rectangle(expx, expy - dim.asc + 1, dim.wid - 1,
|
||||
dim.height() - 2, Color_mathmacroframe);
|
||||
} else {
|
||||
// We should not be here, since the macro is linearized in this case.
|
||||
LBUFERR(false);
|
||||
bool drawBox = lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX
|
||||
&& d->editing_[pi.base.bv];
|
||||
|
||||
// warm up cells
|
||||
for (size_t i = 0; i < nargs(); ++i)
|
||||
cell(i).setXY(*pi.base.bv, x, y);
|
||||
|
||||
if (drawBox) {
|
||||
// draw header and rectangle around
|
||||
FontInfo font = pi.base.font;
|
||||
augmentFont(font, "lyxtex");
|
||||
font.setSize(FONT_SIZE_TINY);
|
||||
font.setColor(Color_mathmacrolabel);
|
||||
Dimension namedim;
|
||||
mathed_string_dim(font, name(), namedim);
|
||||
|
||||
pi.pain.fillRectangle(x, y - dim.asc, dim.wid, 1 + namedim.height() + 1, Color_mathmacrobg);
|
||||
pi.pain.text(x + 1, y - dim.asc + namedim.asc + 2, name(), font);
|
||||
expx += (dim.wid - d->expanded_.dimension(*pi.base.bv).width()) / 2;
|
||||
}
|
||||
|
||||
beforeDraw(pi);
|
||||
d->expanded_.draw(pi, expx, expy);
|
||||
afterDraw(pi);
|
||||
|
||||
if (drawBox)
|
||||
pi.pain.rectangle(x, y - dim.asc, dim.wid,
|
||||
dim.height(), Color_mathmacroframe);
|
||||
}
|
||||
|
||||
// edit mode changed?
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
///
|
||||
virtual MathMacro const * asMacro() const { return this; }
|
||||
///
|
||||
marker_type marker(BufferView const *) const;
|
||||
marker_type marker() const;
|
||||
/// If the macro is in normal edit mode, dissolve its contents in
|
||||
/// the row. Otherwise, just insert the inset.
|
||||
bool addToMathRow(MathRow &, MetricsInfo & mi) const;
|
||||
|
@ -90,14 +90,14 @@ MathRow::MathRow(MetricsInfo & mi, MathData const * ar)
|
||||
}
|
||||
|
||||
// finally reserve space for markers
|
||||
if (bef.marker != InsetMath::NO_MARKER)
|
||||
if (bef.marker != Inset::NO_MARKER)
|
||||
bef.after = max(bef.after, 1);
|
||||
if (e.mclass != MC_UNKNOWN && e.marker != InsetMath::NO_MARKER)
|
||||
if (e.mclass != MC_UNKNOWN && e.marker != Inset::NO_MARKER)
|
||||
e.before = max(e.before, 1);
|
||||
// for linearized insets (macros...) too
|
||||
if (e.type == BEGIN && e.marker != InsetMath::NO_MARKER)
|
||||
if (e.type == BEGIN && e.marker != Inset::NO_MARKER)
|
||||
bef.after = max(bef.after, 1);
|
||||
if (e.type == END && e.marker != InsetMath::NO_MARKER) {
|
||||
if (e.type == END && e.marker != Inset::NO_MARKER) {
|
||||
Element & aft = elements_[after(i)];
|
||||
aft.before = max(aft.before, 1);
|
||||
}
|
||||
@ -133,7 +133,7 @@ int MathRow::after(int i) const
|
||||
|
||||
namespace {
|
||||
|
||||
void afterMetricsMarkers(MetricsInfo const & mi, MathRow::Element & e,
|
||||
void metricsMarkersVertical(MetricsInfo const & , MathRow::Element const & e,
|
||||
Dimension & dim)
|
||||
{
|
||||
// handle vertical space for markers
|
||||
@ -146,26 +146,13 @@ void afterMetricsMarkers(MetricsInfo const & mi, MathRow::Element & e,
|
||||
case InsetMath::MARKER2:
|
||||
++dim.asc;
|
||||
++dim.des;
|
||||
break;
|
||||
case InsetMath::BOX_MARKER:
|
||||
FontInfo font = mi.base.font;
|
||||
augmentFont(font, "lyxtex");
|
||||
font.setSize(FONT_SIZE_TINY);
|
||||
Dimension namedim;
|
||||
mathed_string_dim(font, e.inset->name(), namedim);
|
||||
int const namewid = 1 + namedim.wid + 1;
|
||||
dim.wid += 2;
|
||||
if (namewid > dim.wid)
|
||||
e.after += namewid - dim.wid;
|
||||
dim.asc += 2;
|
||||
dim.des += 2 + namedim.height();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MathRow::metrics(MetricsInfo & mi, Dimension & dim)
|
||||
void MathRow::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
{
|
||||
dim.asc = 0;
|
||||
dim.wid = 0;
|
||||
@ -174,7 +161,7 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim)
|
||||
vector<pair<InsetMath const *, Dimension>> dim_insets;
|
||||
vector<pair<MathData const *, Dimension>> dim_arrays;
|
||||
CoordCache & coords = mi.base.bv->coordCache();
|
||||
for (Element & e : elements_) {
|
||||
for (Element const & e : elements_) {
|
||||
mi.base.macro_nesting = e.macro_nesting;
|
||||
Dimension d;
|
||||
switch (e.type) {
|
||||
@ -189,7 +176,6 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim)
|
||||
if (e.inset) {
|
||||
dim_insets.push_back(make_pair(e.inset, Dimension()));
|
||||
dim_insets.back().second.wid += e.before + e.after;
|
||||
d.wid = e.before + e.after;
|
||||
e.inset->beforeMetrics();
|
||||
}
|
||||
if (e.ar)
|
||||
@ -199,14 +185,11 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim)
|
||||
if (e.inset) {
|
||||
e.inset->afterMetrics();
|
||||
LATTEST(dim_insets.back().first == e.inset);
|
||||
d = dim_insets.back().second;
|
||||
afterMetricsMarkers(mi, e, d);
|
||||
d.wid += e.before + e.after;
|
||||
coords.insets().add(e.inset, d);
|
||||
Dimension & idim = dim_insets.back().second;
|
||||
metricsMarkersVertical(mi, e, idim);
|
||||
idim.wid += e.before + e.after;
|
||||
coords.insets().add(e.inset, idim);
|
||||
dim_insets.pop_back();
|
||||
// We do not want to count the width again, but the
|
||||
// padding and the vertical dimension are meaningful.
|
||||
d.wid = e.before + e.after;
|
||||
}
|
||||
if (e.ar) {
|
||||
LATTEST(dim_arrays.back().first == e.ar);
|
||||
@ -220,7 +203,7 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim)
|
||||
// allow for one pixel before/after the box.
|
||||
d.wid += e.before + e.after + 2;
|
||||
} else {
|
||||
// hide the box, but keep its height
|
||||
// hide the box, but give it some height
|
||||
d.wid = 0;
|
||||
}
|
||||
break;
|
||||
@ -259,22 +242,6 @@ void drawMarkers(PainterInfo const & pi, MathRow::Element const & e, int const x
|
||||
int const l = x + e.before - 1;
|
||||
int const r = x + dim.width() - e.after;
|
||||
|
||||
if (e.marker == InsetMath::BOX_MARKER) {
|
||||
// draw header and rectangle around
|
||||
FontInfo font = pi.base.font;
|
||||
augmentFont(font, "lyxtex");
|
||||
font.setSize(FONT_SIZE_TINY);
|
||||
font.setColor(Color_mathmacrolabel);
|
||||
Dimension namedim;
|
||||
mathed_string_dim(font, e.inset->name(), namedim);
|
||||
pi.pain.rectangle(l, y - dim.asc, dim.wid,
|
||||
dim.height(), Color_mathmacroframe);
|
||||
pi.pain.fillRectangle(l, y + dim.des - namedim.height() - 2,
|
||||
dim.wid, namedim.height() + 2, Color_mathmacrobg);
|
||||
pi.pain.text(l + 1, y + dim.des - namedim.des - 1, e.inset->name(), font);
|
||||
return;
|
||||
}
|
||||
|
||||
// Duplicated from Inset.cpp and adapted. It is believed that the
|
||||
// Inset version should die eventually
|
||||
ColorCode pen_color = e.inset->mouseHovered(pi.base.bv) || e.inset->editing(pi.base.bv)?
|
||||
|
@ -111,7 +111,7 @@ public:
|
||||
MathRow(MetricsInfo & mi, MathData const * ar);
|
||||
|
||||
//
|
||||
void metrics(MetricsInfo & mi, Dimension & dim);
|
||||
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
||||
//
|
||||
void draw(PainterInfo & pi, int const x, int const y) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user