// 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->rowFlags() & Inset::Display) {
+ if (inset->rowFlags() & Inset::AlignLeft)
+ align = LYX_ALIGN_BLOCK;
+ else if (inset->rowFlags() & 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->rowFlags() & Inset::BreakBefore)
+ || (prevInset && prevInset->rowFlags() & Inset::BreakAfter)) {
row.flushed(true);
- // We will force a row creation after either
- // - a newline;
- // - a display inset followed by a end label.
- need_new_row =
- par.isNewline(i)
- || (inset && inset->display() && i + 1 == end
- && text_->getEndLabel(row.pit()) != END_LABEL_NO_LABEL);
+ // Force a row creation after this one if it is ended by
+ // an inset that either
+ // - has row flag RowAfter that enforces that;
+ // - or (1) did force the row breaking, (2) is at end of
+ // paragraph and (3) the said paragraph has an end label.
+ need_new_row = prevInset &&
+ (prevInset->rowFlags() & Inset::RowAfter
+ || (prevInset->rowFlags() & Inset::BreakAfter && i + 1 == end
+ && text_->getEndLabel(row.pit()) != END_LABEL_NO_LABEL));
++i;
break;
}
&& !par.params().noindent()
// in some insets, paragraphs are never indented
&& !text_->inset().neverIndent()
- // display style insets are always centered, omit indentation
+ // display style insets do not need indentation
&& !(!par.empty()
&& par.isInset(pos)
- && par.getInset(pos)->display())
+ && par.getInset(pos)->rowFlags() & Inset::Display)
&& (!(tclass.isDefaultLayout(par.layout())
|| tclass.isPlainLayout(par.layout()))
|| buffer.params().paragraph_separation
virtual OutputParams::CtObject CtObject(OutputParams const &) const { return OutputParams::CT_NORMAL; }
- enum DisplayType {
+ enum RowFlags {
Inline = 0,
- AlignLeft,
- AlignCenter,
- AlignRight
+ // break row before this inset
+ BreakBefore = 1 << 0,
+ // break row after this inset
+ BreakAfter = 1 << 1,
+ // force new (maybe empty) row after this inset
+ RowAfter = 1 << 2,
+ // specify an alignment (left, right) for a display inset
+ // (default is center)
+ AlignLeft = 1 << 3,
+ AlignRight = 1 << 4,
+ // A display inset breaks row at both ends
+ Display = BreakBefore | BreakAfter
};
- /// should we have a non-filled line before this inset?
- virtual DisplayType display() const { return Inline; }
+ /// How should this inset be displayed in its row?
+ virtual RowFlags rowFlags() 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::RowFlags operator|(Inset::RowFlags const d1,
+ Inset::RowFlags const d2)
+{
+ return static_cast<Inset::RowFlags>(int(d1) | int(d2));
+}
+
+
+inline Inset::RowFlags operator&(Inset::RowFlags const d1,
+ Inset::RowFlags const d2)
+{
+ return static_cast<Inset::RowFlags>(int(d1) & int(d2));
+}
+
+
} // namespace lyx
#endif
///
InsetCode lyxCode() const { return BIBTEX_CODE; }
///
- DisplayType display() const { return AlignCenter; }
+ RowFlags rowFlags() 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; }
+ RowFlags rowFlags() const { return Display; }
///
bool neverIndent() const { return true; }
///
///
InsetCode lyxCode() const { return FLOAT_LIST_CODE; }
///
- DisplayType display() const { return AlignCenter; }
+ RowFlags rowFlags() const { return Display; }
///
void write(std::ostream &) const;
///
}
-Inset::DisplayType InsetInclude::display() const
+Inset::RowFlags InsetInclude::rowFlags() const
{
- return type(params()) == INPUT ? Inline : AlignCenter;
+ return type(params()) == INPUT ? Inline : Display;
}
///
void draw(PainterInfo & pi, int x, int y) const;
///
- DisplayType display() const;
+ RowFlags rowFlags() const;
///
InsetCode lyxCode() const { return INCLUDE_CODE; }
///
///
bool hasSettings() const;
///
- DisplayType display() const { return AlignCenter; }
+ RowFlags rowFlags() const { return Display; }
//@}
/// \name Static public methods obligated for InsetCommand derived classes
}
-Inset::DisplayType InsetListings::display() const
+Inset::RowFlags InsetListings::rowFlags() const
{
- return params().isInline() || params().isFloat() ? Inline : AlignLeft;
+ return params().isInline() || params().isFloat() ? Inline : Display | AlignLeft;
}
///
InsetCode lyxCode() const { return LISTINGS_CODE; }
/// lstinline is inlined, normal listing is displayed
- DisplayType display() const;
+ RowFlags rowFlags() const;
///
docstring layoutName() const;
///
explicit InsetNewline(InsetNewlineParams par) : Inset(0)
{ params_.kind = par.kind; }
///
+ RowFlags rowFlags() const { return BreakAfter | RowAfter; }
+ ///
static void string2params(std::string const &, InsetNewlineParams &);
///
static std::string params2string(InsetNewlineParams const &);
///
void write(std::ostream & os) const;
///
- DisplayType display() const { return AlignCenter; }
+ RowFlags rowFlags() const { return Display; }
///
docstring insetLabel() const;
///
///
bool hasSettings() const { return true; }
///
- DisplayType display() const { return AlignCenter; }
+ RowFlags rowFlags() 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);
InsetCode lyxCode() const { return SCRIPT_CODE; }
///
docstring layoutName() const;
- ///
- DisplayType display() const;
///
int topOffset(BufferView const *) const { return 0; }
// remove warning
return docstring();
}
+ ///
+ RowFlags rowFlags() const { return BreakAfter; }
private:
///
InsetCode lyxCode() const { return SEPARATOR_CODE; }
///
docstring layoutName() const;
///
- DisplayType display() const { return AlignCenter; }
+ RowFlags rowFlags() const { return Display; }
///
virtual void validate(LaTeXFeatures &) const;
///
}
-Inset::DisplayType InsetTabular::display() const
+Inset::RowFlags InsetTabular::rowFlags() 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;
//
bool isTable() const { return true; }
///
- DisplayType display() const;
+ RowFlags rowFlags() const;
///
void latex(otexstream &, OutputParams const &) const;
///
///
void write(std::ostream & os) const;
///
- DisplayType display() const { return AlignCenter; }
+ RowFlags rowFlags() const { return Display; }
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///
}
-Inset::DisplayType InsetMathHull::display() const
+Inset::RowFlags InsetMathHull::rowFlags() const
{
switch (type_) {
case hullUnknown:
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;
}
{
// FIXME: set this in the textclass. This value is what the article class uses.
static Length default_indent(2.5, Length::EM);
- if (display() != Inline && buffer().params().is_math_indent) {
+ if (display() && buffer().params().is_math_indent) {
Length const & len = buffer().params().getMathIndent();
if (len.empty())
return bv.inPixels(default_indent);
return true;
}
case LFUN_MATH_DISPLAY: {
- status.setEnabled(display() != Inline || allowDisplayMath(cur));
- status.setOnOff(display() != Inline);
+ status.setEnabled(display() || allowDisplayMath(cur));
+ status.setOnOff(display());
return true;
}
case LFUN_MATH_NUMBER_TOGGLE:
// FIXME: what is the right test, this or the one of
// LABEL_INSERT?
- status.setEnabled(display() != Inline);
+ status.setEnabled(display());
status.setOnOff(numberedType());
return true;
// LABEL_INSERT?
bool const enable = (type_ == hullMultline)
? (nrows() - 1 == cur.row())
- : display() != Inline;
+ : display();
row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
status.setEnabled(enable);
status.setOnOff(enable && numbered(r));
bool InsetMathHull::canPaintChange(BufferView const &) const
{
// We let RowPainter do it seamlessly for inline insets
- return display() != Inline;
+ return display();
}
///
Inset * editXY(Cursor & cur, int x, int y);
///
- DisplayType display() const;
+ RowFlags rowFlags() const;
+ /// helper function
+ bool display() const { return rowFlags() & Display; }
+
///
int indent(BufferView const &) const;