The enum is now made of flags that can be combined.
This introduces several new values for Inset::DisplayType:
BreakBefore, BreakAfter and Display=BreakBefore|BreakAfter. This
last value replaces AlignCenter.
Additionally the flags NoBoundary and CanBreakAfter are introduced for
future use.
Now a left aligned displayed inset will be defined as Display|LeftAlign.
A newline inset is characterized as BreakAfter.
This structure is used in breakRow to avoid explicit calls to
isNewline() or isEnvSeparator(). More improvements will be built on
top of this.
Additionally several redundant display() methods (which returned
Inline) have been removed.
// Display-style insets should always be on a centered row
if (Inset const * inset = par.getInset(row.pos())) {
- switch (inset->display()) {
- case Inset::AlignLeft:
- align = LYX_ALIGN_BLOCK;
- break;
- case Inset::AlignCenter:
- align = LYX_ALIGN_CENTER;
- break;
- case Inset::Inline:
- // unchanged (use align)
- break;
- case Inset::AlignRight:
- align = LYX_ALIGN_RIGHT;
- break;
+ if (inset->display() & Inset::Display) {
+ if (inset->display() & Inset::AlignLeft)
+ align = LYX_ALIGN_BLOCK;
+ else if (inset->display() & Inset::AlignRight)
+ align = LYX_ALIGN_RIGHT;
+ else
+ align = LYX_ALIGN_CENTER;
}
}
}
// Handle some situations that abruptly terminate the row
- // - A newline inset
- // - Before a display inset
- // - After a display inset
- Inset const * inset = 0;
- if (par.isNewline(i) || par.isEnvSeparator(i)
- || (i + 1 < end && (inset = par.getInset(i + 1))
- && inset->display())
- || (!row.empty() && row.back().inset
- && row.back().inset->display())) {
+ // - Before an inset with BreakBefore
+ // - After an inset with BreakAfter
+ Inset const * prevInset = !row.empty() ? row.back().inset : 0;
+ Inset const * nextInset = (i + 1 < end) ? par.getInset(i + 1) : 0;
+ if ((nextInset && nextInset->display() & Inset::BreakBefore)
+ || (prevInset && prevInset->display() & Inset::BreakAfter)) {
row.flushed(true);
// We will force a row creation after either
// - a newline;
// display style insets are always centered, omit indentation
&& !(!par.empty()
&& par.isInset(pos)
- && par.getInset(pos)->display())
+ && par.getInset(pos)->display() & Inset::Display)
&& (!(tclass.isDefaultLayout(par.layout())
|| tclass.isPlainLayout(par.layout()))
|| buffer.params().paragraph_separation
enum DisplayType {
Inline = 0,
- AlignLeft,
- AlignCenter,
- AlignRight
+ // break row before this inset
+ BreakBefore = 1,
+ // break row after this inset
+ BreakAfter = 2,
+ // optionally break row after this inset (not used yet)
+ CanBreakAfter = 4,
+ // specify an alignment (left, right) for a display inset (default is center)
+ AlignLeft = 8,
+ AlignRight = 16,
+ // do not allow cursor to go at the end of the row before
+ // a display inset (not used yet)
+ NoBoundary = 32,
+ // A display inset breaks row at both ends
+ Display = BreakBefore | BreakAfter
};
- /// should we have a non-filled line before this inset?
+ /// How should this inset be typeset?
virtual DisplayType display() const { return Inline; }
/// indentation before this inset (only needed for displayed hull insets with fleqn option)
virtual int indent(BufferView const &) const { return 0; }
Buffer * buffer_;
};
+
+inline Inset::DisplayType operator|(Inset::DisplayType const d1,
+ Inset::DisplayType const d2)
+{
+ return static_cast<Inset::DisplayType>(int(d1) | int(d2));
+}
+
+
+inline Inset::DisplayType operator&(Inset::DisplayType const d1,
+ Inset::DisplayType const d2)
+{
+ return static_cast<Inset::DisplayType>(int(d1) & int(d2));
+}
+
+
} // namespace lyx
#endif
///
InsetCode lyxCode() const { return BIBTEX_CODE; }
///
- DisplayType display() const { return AlignCenter; }
+ DisplayType display() const { return Display; }
///
void latex(otexstream &, OutputParams const &) const;
///
///
void metrics(MetricsInfo &, Dimension &) const;
///
- DisplayType display() const { return Inline; }
- ///
ColorCode backgroundColor(PainterInfo const &) const;
///
LyXAlignment contentAlignment() const;
///
void write(std::ostream & os) const;
///
- DisplayType display() const { return AlignCenter; }
+ DisplayType display() const { return Display; }
///
bool neverIndent() const { return true; }
///
///
InsetCode lyxCode() const { return FLOAT_LIST_CODE; }
///
- DisplayType display() const { return AlignCenter; }
+ DisplayType display() const { return Display; }
///
void write(std::ostream &) const;
///
Inset::DisplayType InsetInclude::display() const
{
- return type(params()) == INPUT ? Inline : AlignCenter;
+ return type(params()) == INPUT ? Inline : Display;
}
///
bool hasSettings() const;
///
- DisplayType display() const { return AlignCenter; }
+ DisplayType display() const { return Display; }
//@}
/// \name Static public methods obligated for InsetCommand derived classes
Inset::DisplayType InsetListings::display() const
{
- return params().isInline() || params().isFloat() ? Inline : AlignLeft;
+ return params().isInline() || params().isFloat() ? Inline : Display | AlignLeft;
}
explicit InsetNewline(InsetNewlineParams par) : Inset(0)
{ params_.kind = par.kind; }
///
+ DisplayType display() const { return BreakAfter | NoBoundary; }
+ ///
static void string2params(std::string const &, InsetNewlineParams &);
///
static std::string params2string(InsetNewlineParams const &);
///
void write(std::ostream & os) const;
///
- DisplayType display() const { return AlignCenter; }
+ DisplayType display() const { return Display; }
///
docstring insetLabel() const;
///
///
bool hasSettings() const { return true; }
///
- DisplayType display() const { return AlignCenter; }
+ DisplayType display() const { return Display; }
///
void latex(otexstream &, OutputParams const &) const;
///
}
-Inset::DisplayType InsetNote::display() const
-{
- return Inline;
-}
-
-
void InsetNote::write(ostream & os) const
{
params_.write(os);
InsetCode lyxCode() const { return NOTE_CODE; }
///
docstring layoutName() const;
- ///
- DisplayType display() const;
/** returns false if, when outputing LaTeX, font changes should
be closed before generating this inset. This is needed for
insets that may contain several paragraphs */
///
InsetCode lyxCode() const { return REF_CODE; }
///
- DisplayType display() const { return Inline; }
- ///
void latex(otexstream &, OutputParams const &) const;
///
int plaintext(odocstringstream & ods, OutputParams const & op,
}
-Inset::DisplayType InsetScript::display() const
-{
- return Inline;
-}
-
-
void InsetScript::metrics(MetricsInfo & mi, Dimension & dim) const
{
int const shift = params_.shift(mi.base.font);
// remove warning
return docstring();
}
+ ///
+ DisplayType display() const { return BreakAfter | NoBoundary; }
private:
///
InsetCode lyxCode() const { return SEPARATOR_CODE; }
///
docstring layoutName() const;
///
- DisplayType display() const { return AlignCenter; }
+ DisplayType display() const { return Display; }
///
virtual void validate(LaTeXFeatures &) const;
///
if (tabular.is_long_tabular) {
switch (tabular.longtabular_alignment) {
case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
- return AlignLeft;
+ return Display | AlignLeft;
case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
- return AlignCenter;
+ return Display;
case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
- return AlignRight;
+ return Display | AlignRight;
default:
- return AlignCenter;
+ return Display;
}
} else
return Inline;
///
void write(std::ostream & os) const;
///
- DisplayType display() const { return AlignCenter; }
+ DisplayType display() const { return Display; }
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///
// insert a gap in front of the formula
// value was hardcoded to 1 pixel
dim.wid += mi.base.bv->zoomedPixels(1) ;
- if (display()) {
+ if (display() != Inline) {
dim.asc += display_margin;
dim.des += display_margin;
}
{
Changer dummy1 = mi.base.changeFontSet(standardFont());
- Changer dummy2 = mi.base.font.changeStyle(display() ? DISPLAY_STYLE
+ Changer dummy2 = mi.base.font.changeStyle(display() != Inline ? DISPLAY_STYLE
: TEXT_STYLE);
// let the cells adjust themselves
// Then the equations
Changer dummy1 = pi.base.changeFontSet(standardFont());
- Changer dummy2 = pi.base.font.changeStyle(display() ? DISPLAY_STYLE
+ Changer dummy2 = pi.base.font.changeStyle(display() != Inline ? DISPLAY_STYLE
: TEXT_STYLE);
InsetMathGrid::draw(pi, x + 1, y);
drawMarkers(pi, x, y);
// drawing change line
if (canPaintChange(*bv)) {
// like in metrics()
- int const display_margin = display() ? pi.base.inPixels(Length(12, Length::PT)) : 0;
+ int const display_margin = display() != Inline ? pi.base.inPixels(Length(12, Length::PT)) : 0;
pi.change.paintCue(pi, x + 1, y + 1 - dim.asc + display_margin,
x + dim.wid, y + dim.des - display_margin);
}
void InsetMathHull::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
{
- if (display()) {
+ if (display() != Inline) {
InsetMathGrid::metricsT(mi, dim);
} else {
odocstringstream os;
void InsetMathHull::drawT(TextPainter & pain, int x, int y) const
{
- if (display()) {
+ if (display() != Inline) {
InsetMathGrid::drawT(pain, x, y);
} else {
odocstringstream os;
case hullMultline:
case hullGather:
if (buffer().params().is_math_indent)
- return AlignLeft;
+ return Display | AlignLeft;
else
- return AlignCenter;
+ return Display;
}
// avoid warning
- return AlignCenter;
+ return Display;
}
OutputParams const & op, size_t max_length) const
{
// Try enabling this now that there is a flag as requested at #2275.
- if (buffer().isExporting() && display()) {
+ if (buffer().isExporting() && display() != Inline) {
Dimension dim;
TextMetricsInfo mi;
metricsT(mi, dim);