using std::string;
using std::auto_ptr;
using std::istringstream;
+using std::max;
using std::ostream;
using std::ostringstream;
void InsetCharStyle::init()
{
setInsetName("CharStyle");
- setStatus(Inlined);
+ setInlined();
setDrawFrame(false);
has_label_ = true;
}
+InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s)
+ : InsetCollapsable(bp)
+{
+ params_.type = s;
+ setUndefined();
+ init();
+}
+
+
InsetCharStyle::InsetCharStyle(BufferParams const & bp,
CharStyles::iterator cs)
: InsetCollapsable(bp)
{
params_.type = cs->name;
- params_.latextype = cs->latextype;
- params_.latexname = cs->latexname;
- params_.latexparam = cs->latexparam;
- params_.font = cs->font;
- params_.labelfont = cs->labelfont;
+ setDefined(cs);
init();
}
}
+bool InsetCharStyle::undefined() const
+{
+ return params_.latexname.empty();
+}
+
+
+void InsetCharStyle::setUndefined()
+{
+ params_.latextype.clear();
+ params_.latexname.clear();
+ params_.latexparam.clear();
+ params_.font = LyXFont(LyXFont::ALL_INHERIT);
+ params_.labelfont = LyXFont(LyXFont::ALL_INHERIT);
+ params_.labelfont.setColor(LColor::error);
+}
+
+
+void InsetCharStyle::setDefined(CharStyles::iterator cs)
+{
+ params_.latextype = cs->latextype;
+ params_.latexname = cs->latexname;
+ params_.latexparam = cs->latexparam;
+ params_.font = cs->font;
+ params_.labelfont = cs->labelfont;
+}
+
+
string const InsetCharStyle::editMessage() const
{
return _("Opened CharStyle Inset");
void InsetCharStyle::read(Buffer const & buf, LyXLex & lex)
{
InsetCollapsable::read(buf, lex);
- setStatus(Inlined);
+ setInlined();
}
mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
InsetText::metrics(mi, dim);
mi.base.font = tmpfont;
+ if (has_label_) {
+ // consider width of the inset label
+ LyXFont font(params_.labelfont);
+ font.realize(LyXFont(LyXFont::ALL_SANE));
+ font.decSize();
+ font.decSize();
+ int w = 0;
+ int a = 0;
+ int d = 0;
+ string s(params_.type);
+ if (undefined())
+ s = _("Undef: ") + s;
+ font_metrics::rectText(s, font, w, a, d);
+ dim.wid = max(dim.wid, w);
+ }
dim.asc += TEXT_TO_INSET_OFFSET;
dim.des += TEXT_TO_INSET_OFFSET;
dim.wid += 2 * TEXT_TO_INSET_OFFSET;
LyXFont tmpfont = pi.base.font;
getDrawFont(pi.base.font);
- // I don't understand why the above .reduce and .realize aren't
+ // I don't understand why the above .reduce and .realize aren't
//needed, or even wanted, here. It just works. -- MV 10.04.2005
InsetText::draw(pi, x, y);
pi.base.font = tmpfont;
int w = 0;
int a = 0;
int d = 0;
- font_metrics::rectText(params_.type, font, w, a, d);
+ string s(params_.type);
+ if (undefined())
+ s = _("Undef: ") + s;
+ font_metrics::rectText(s, font, w, a, d);
pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a,
- params_.type, font, LColor::none, LColor::none);
+ s, font, LColor::none, LColor::none);
}
// a visual clue when the cursor is inside the inset
void InsetCharStyle::doDispatch(LCursor & cur, FuncRequest & cmd)
{
- setStatus(Inlined);
+ setInlined();
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
if (cmd.button() == mouse_button::button3)
int InsetCharStyle::latex(Buffer const & buf, ostream & os,
OutputParams const & runparams) const
{
- os << "\\" << params_.latexname;
- if (!params_.latexparam.empty())
- os << params_.latexparam;
- os << "{";
+ if (!undefined()) {
+ os << "\\" << params_.latexname;
+ if (!params_.latexparam.empty())
+ os << params_.latexparam;
+ os << "{";
+ }
int i = InsetText::latex(buf, os, runparams);
- os << "}";
+ if (!undefined())
+ os << "}";
return i;
}
int InsetCharStyle::linuxdoc(Buffer const & buf, ostream & os,
OutputParams const & runparams) const
{
- sgml::openTag(os, params_.latexname, params_.latexparam);
+ if (!undefined())
+ sgml::openTag(os, params_.latexname, params_.latexparam);
int i = InsetText::linuxdoc(buf, os, runparams);
- sgml::closeTag(os, params_.latexname);
+ if (!undefined())
+ sgml::closeTag(os, params_.latexname);
return i;
}
ParagraphList::const_iterator par = paragraphs().begin();
ParagraphList::const_iterator end = paragraphs().end();
- sgml::openTag(os, params_.latexname, par->getID(buf, runparams) + params_.latexparam);
+ if (!undefined())
+ sgml::openTag(os, params_.latexname,
+ par->getID(buf, runparams) + params_.latexparam);
for (; par != end; ++par) {
par->simpleDocBookOnePar(buf, os, runparams,
- outerFont(par - paragraphs().begin(),
+ outerFont(par - paragraphs().begin(),
paragraphs()));
}
- sgml::closeTag(os, params_.latexname);
+ if (!undefined())
+ sgml::closeTag(os, params_.latexname);
+
return 0;
}
}
+int InsetCharStyle::textString(Buffer const & buf, ostream & os,
+ OutputParams const & op) const
+{
+ return plaintext(buf, os, op);
+}
+
+
void InsetCharStyle::validate(LaTeXFeatures & features) const
{
+ // Force inclusion of preamble snippet in layout file
features.require(params_.type);
InsetText::validate(features);
}