mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-11 05:33:33 +00:00
* first tries to make the math macro template more verbose
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22270 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
7fa64792f5
commit
e5bd44aadc
@ -163,6 +163,15 @@ void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
|
|||||||
FontSetChanger dummy1(mi.base, from_ascii("mathnormal"));
|
FontSetChanger dummy1(mi.base, from_ascii("mathnormal"));
|
||||||
StyleChanger dummy2(mi.base, LM_ST_TEXT);
|
StyleChanger dummy2(mi.base, LM_ST_TEXT);
|
||||||
|
|
||||||
|
// tiny font for sublabels
|
||||||
|
FontInfo slFont = sane_font;
|
||||||
|
slFont.decSize();
|
||||||
|
slFont.decSize();
|
||||||
|
slFont.decSize();
|
||||||
|
slFont.decSize();
|
||||||
|
Dimension slDim;
|
||||||
|
bool edit = editing(mi.base.bv);
|
||||||
|
|
||||||
// valid macro?
|
// valid macro?
|
||||||
MacroData const * macro = 0;
|
MacroData const * macro = 0;
|
||||||
if (validName()) {
|
if (validName()) {
|
||||||
@ -209,23 +218,41 @@ void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
|
|||||||
dim.wid = 2 + mathed_string_width(mi.base.font, from_ascii("\\")) +
|
dim.wid = 2 + mathed_string_width(mi.base.font, from_ascii("\\")) +
|
||||||
dim0.width() +
|
dim0.width() +
|
||||||
labeldim.width() +
|
labeldim.width() +
|
||||||
defdim.width() + 16 + dspdim.width() + 2;
|
defdim.width() + 10;
|
||||||
|
|
||||||
dim.asc = dim0.ascent();
|
dim.asc = dim0.ascent();
|
||||||
dim.asc = max(dim.asc, labeldim.ascent());
|
|
||||||
dim.asc = max(dim.asc, defdim.ascent());
|
|
||||||
dim.asc = max(dim.asc, dspdim.ascent());
|
|
||||||
|
|
||||||
dim.des = dim0.descent();
|
dim.des = dim0.descent();
|
||||||
|
|
||||||
|
dim.asc = max(dim.asc, labeldim.ascent());
|
||||||
dim.des = max(dim.des, labeldim.descent());
|
dim.des = max(dim.des, labeldim.descent());
|
||||||
|
|
||||||
|
dim.asc = max(dim.asc, defdim.ascent());
|
||||||
dim.des = max(dim.des, defdim.descent());
|
dim.des = max(dim.des, defdim.descent());
|
||||||
dim.des = max(dim.des, dspdim.descent());
|
|
||||||
|
// hide empty display cells if not edited
|
||||||
|
if (edit || !cell(displayIdx()).empty()) {
|
||||||
|
// display
|
||||||
|
dim.asc = max(dim.asc, dspdim.ascent());
|
||||||
|
dim.des = max(dim.des, dspdim.descent());
|
||||||
|
if (edit) {
|
||||||
|
mathed_string_dim(slFont, from_ascii("LyX"), slDim);
|
||||||
|
dim.wid += max(dspdim.width(), slDim.wid) + 8;
|
||||||
|
} else
|
||||||
|
dim.wid += dspdim.width() + 8;
|
||||||
|
}
|
||||||
|
|
||||||
// make the name cell vertically centered, and 5 pixel lines margin
|
// make the name cell vertically centered, and 5 pixel lines margin
|
||||||
int real_asc = dim.asc - dim0.ascent() / 2;
|
int real_asc = dim.asc - dim0.ascent() / 2;
|
||||||
int real_des = dim.des + dim0.ascent() / 2;
|
int real_des = dim.des + dim0.ascent() / 2;
|
||||||
dim.asc = max(real_asc, real_des) + dim0.ascent() / 2 + 5;
|
dim.asc = max(real_asc, real_des) + dim0.ascent() / 2 + 5;
|
||||||
dim.des = max(real_asc, real_des) - dim0.ascent() / 2 + 5;
|
dim.des = max(real_asc, real_des) - dim0.ascent() / 2 + 5;
|
||||||
|
cellDim_ = dim;
|
||||||
|
|
||||||
|
// add sublabels below
|
||||||
|
if (edit) {
|
||||||
|
mathed_string_dim(slFont, from_ascii("Mg"), slDim);
|
||||||
|
dim.des += 2 + slDim.asc + slDim.des + 2;
|
||||||
|
}
|
||||||
|
|
||||||
setDimCache(mi, dim);
|
setDimCache(mi, dim);
|
||||||
}
|
}
|
||||||
@ -239,6 +266,20 @@ void MathMacroTemplate::draw(PainterInfo & pi, int x, int y) const
|
|||||||
setPosCache(pi, x, y);
|
setPosCache(pi, x, y);
|
||||||
Dimension const dim = dimension(*pi.base.bv);
|
Dimension const dim = dimension(*pi.base.bv);
|
||||||
|
|
||||||
|
// sublabel font
|
||||||
|
FontInfo slFont = sane_font;
|
||||||
|
slFont.setColor(Color_command);
|
||||||
|
slFont.decSize();
|
||||||
|
slFont.decSize();
|
||||||
|
slFont.decSize();
|
||||||
|
slFont.decSize();
|
||||||
|
bool edit = editing(pi.base.bv);
|
||||||
|
|
||||||
|
// sublabel position
|
||||||
|
Dimension slDim;
|
||||||
|
mathed_string_dim(slFont, from_ascii("Mg"), slDim);
|
||||||
|
int const sly = y + cellDim_.des + slDim.asc + 2;
|
||||||
|
|
||||||
// create fonts
|
// create fonts
|
||||||
bool valid = validMacro();
|
bool valid = validMacro();
|
||||||
FontInfo font = pi.base.font;
|
FontInfo font = pi.base.font;
|
||||||
@ -271,13 +312,39 @@ void MathMacroTemplate::draw(PainterInfo & pi, int x, int y) const
|
|||||||
// draw definition
|
// draw definition
|
||||||
cell(defIdx()).draw(pi, x + 2, y);
|
cell(defIdx()).draw(pi, x + 2, y);
|
||||||
int const w1 = cell(defIdx()).dimension(*pi.base.bv).width();
|
int const w1 = cell(defIdx()).dimension(*pi.base.bv).width();
|
||||||
pi.pain.rectangle(x, y - dim.ascent() + 3, w1 + 4, dim.height() - 6, Color_mathline);
|
pi.pain.rectangle(x, y - dim.ascent() + 3, w1 + 4, cellDim_.height() - 6,
|
||||||
|
Color_mathline);
|
||||||
x += w1 + 8;
|
x += w1 + 8;
|
||||||
|
|
||||||
// draw display
|
// hide empty display cells if not edited
|
||||||
cell(displayIdx()).draw(pi, x + 2, y);
|
if (edit || !cell(displayIdx()).empty()) {
|
||||||
int const w2 = cell(displayIdx()).dimension(*pi.base.bv).width();
|
// draw sublabel
|
||||||
pi.pain.rectangle(x, y - dim.ascent() + 3, w2 + 4, dim.height() - 6, Color_mathline);
|
if (edit)
|
||||||
|
pi.pain.text(x + 2, sly, from_ascii("LyX"), slFont);
|
||||||
|
|
||||||
|
// draw display
|
||||||
|
cell(displayIdx()).draw(pi, x + 2, y);
|
||||||
|
int const w2 = cell(displayIdx()).dimension(*pi.base.bv).width();
|
||||||
|
pi.pain.rectangle(x, y - dim.ascent() + 3, w2 + 4, cellDim_.height() - 6,
|
||||||
|
Color_mathline);
|
||||||
|
} else {
|
||||||
|
// at least update the coord cache if not drawn
|
||||||
|
cell(displayIdx()).setXY(*pi.base.bv, x + 2, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathMacroTemplate::edit(Cursor & cur, bool left)
|
||||||
|
{
|
||||||
|
cur.updateFlags(Update::Force);
|
||||||
|
InsetMathNest::edit(cur, left);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool MathMacroTemplate::notifyCursorLeaves(Cursor & cur)
|
||||||
|
{
|
||||||
|
cur.updateFlags(Update::Force);
|
||||||
|
return InsetMathNest::notifyCursorLeaves(cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -836,4 +903,10 @@ size_t MathMacroTemplate::numOptionals() const
|
|||||||
return optionals_;
|
return optionals_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MathMacroTemplate::infoize(odocstream & os) const
|
||||||
|
{
|
||||||
|
os << "Math Macro: \\" << name();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -38,6 +38,10 @@ public:
|
|||||||
///
|
///
|
||||||
EDITABLE editable() const { return HIGHLY_EDITABLE; }
|
EDITABLE editable() const { return HIGHLY_EDITABLE; }
|
||||||
///
|
///
|
||||||
|
void edit(Cursor & cur, bool left);
|
||||||
|
///
|
||||||
|
bool notifyCursorLeaves(Cursor & cur);
|
||||||
|
///
|
||||||
void read(Buffer const &, Lexer & lex);
|
void read(Buffer const &, Lexer & lex);
|
||||||
///
|
///
|
||||||
void write(Buffer const &, std::ostream & os) const;
|
void write(Buffer const &, std::ostream & os) const;
|
||||||
@ -90,6 +94,8 @@ public:
|
|||||||
MathMacroTemplate const * asMacroTemplate() const { return this; }
|
MathMacroTemplate const * asMacroTemplate() const { return this; }
|
||||||
///
|
///
|
||||||
InsetCode lyxCode() const { return MATHMACRO_CODE; }
|
InsetCode lyxCode() const { return MATHMACRO_CODE; }
|
||||||
|
///
|
||||||
|
void infoize(odocstream & os) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///
|
///
|
||||||
@ -133,6 +139,8 @@ private:
|
|||||||
mutable MacroType type_;
|
mutable MacroType type_;
|
||||||
/// defined before already?
|
/// defined before already?
|
||||||
mutable bool redefinition_;
|
mutable bool redefinition_;
|
||||||
|
///
|
||||||
|
mutable Dimension cellDim_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user