* src/insets/insetcaption.*: fix plaintext(); add private computeFullLabel() to

refactor code used at two places


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17219 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Michael Schmitt 2007-02-16 09:53:51 +00:00
parent 26054c940e
commit bcb5133e54
2 changed files with 31 additions and 16 deletions

View File

@ -125,13 +125,9 @@ bool InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const
{
int const width_offset = TEXT_TO_INSET_OFFSET / 2;
mi.base.textwidth -= width_offset;
if (type_.empty())
full_label_ = _("Senseless!!! ");
else {
docstring const number = convert<docstring>(counter_);
docstring label = custom_label_.empty()? _(type_): custom_label_;
full_label_ = bformat(from_ascii("%1$s %2$s:"), label, number);
}
computeFullLabel();
labelwidth_ = theFontMetrics(mi.base.font).width(full_label_);
// add some space to separate the label from the inset text
labelwidth_ += 2 * TEXT_TO_INSET_OFFSET;
@ -229,7 +225,7 @@ bool InsetCaption::getStatus(LCursor & cur, FuncRequest const & cmd,
int InsetCaption::latex(Buffer const & buf, odocstream & os,
OutputParams const & runparams_in) const
OutputParams const & runparams_in) const
{
// This is a bit too simplistic to take advantage of
// caption options we must add more later. (Lgb)
@ -250,15 +246,20 @@ int InsetCaption::latex(Buffer const & buf, odocstream & os,
int InsetCaption::plaintext(Buffer const & buf, odocstream & os,
OutputParams const & runparams) const
OutputParams const & runparams) const
{
os << full_label_ << ' ';
return InsetText::plaintext(buf, os, runparams);
computeFullLabel();
os << '[' << full_label_ << "\n";
InsetText::plaintext(buf, os, runparams);
os << "\n]";
return 1 + runparams.linelen; // one char on a separate line
}
int InsetCaption::docbook(Buffer const & buf, odocstream & os,
OutputParams const & runparams) const
OutputParams const & runparams) const
{
int ret;
os << "<title>";
@ -268,6 +269,18 @@ int InsetCaption::docbook(Buffer const & buf, odocstream & os,
}
void InsetCaption::computeFullLabel() const
{
if (type_.empty())
full_label_ = _("Senseless!!! ");
else {
docstring const number = convert<docstring>(counter_);
docstring label = custom_label_.empty()? _(type_): custom_label_;
full_label_ = bformat(from_ascii("%1$s %2$s:"), label, number);
}
}
auto_ptr<InsetBase> InsetCaption::doClone() const
{
return auto_ptr<InsetBase>(new InsetCaption(*this));

View File

@ -60,14 +60,14 @@ public:
///
virtual bool wide() const { return false; }
///
virtual int latex(Buffer const & buf, odocstream & os,
OutputParams const &) const;
int latex(Buffer const & buf, odocstream & os,
OutputParams const &) const;
///
int plaintext(Buffer const & buf, odocstream & os,
OutputParams const & runparams) const;
OutputParams const & runparams) const;
///
int docbook(Buffer const & buf, odocstream & os,
OutputParams const & runparams) const;
OutputParams const & runparams) const;
///
void setCount(int c) { counter_ = c; }
///
@ -78,6 +78,8 @@ public:
void addToToc(TocList &, Buffer const &) const;
private:
///
void computeFullLabel() const;
///
virtual std::auto_ptr<InsetBase> doClone() const;
///