mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-23 00:38:01 +00:00
Fix lists of figures and tables. Prepare the code for user defined captions.
* buffer_funcs.C::setCaptionLabels(): set the type as well as the custom label. * InsetCaption: - setType(): new method to set the type of the caption - setCustomLabel(): renamed from setLabel, translate if possible. - addToToc(): implement. - metrics(): use custom_label_ if defined. * InsetFloat::addToToc(): don't do anything. * InsetWrap::addToToc(): don't do anything. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17001 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
42ff801ec9
commit
0e0a17ff0a
@ -363,8 +363,9 @@ void setCaptionLabels(InsetBase & inset, Floating const & fl,
|
||||
if (pars.empty())
|
||||
return;
|
||||
|
||||
// FIXME UNICODE
|
||||
string const & type = fl.type();
|
||||
docstring const counter = from_ascii(fl.type());
|
||||
// FIXME UNICODE
|
||||
docstring const label = from_utf8(fl.name());
|
||||
|
||||
ParagraphList::iterator p = pars.begin();
|
||||
@ -381,8 +382,10 @@ void setCaptionLabels(InsetBase & inset, Floating const & fl,
|
||||
// We found a caption!
|
||||
counters.step(counter);
|
||||
int number = counters.value(counter);
|
||||
static_cast<InsetCaption &>(icap).setCount(number);
|
||||
static_cast<InsetCaption &>(icap).setLabel(label);
|
||||
InsetCaption & ic = static_cast<InsetCaption &>(icap);
|
||||
ic.setType(type);
|
||||
ic.setCount(number);
|
||||
ic.setCustomLabel(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "metricsinfo.h"
|
||||
#include "output_latex.h"
|
||||
#include "paragraph.h"
|
||||
#include "TocBackend.h"
|
||||
|
||||
#include "frontends/FontMetrics.h"
|
||||
#include "frontends/Painter.h"
|
||||
@ -38,18 +39,18 @@
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using support::bformat;
|
||||
|
||||
using std::auto_ptr;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
using std::ostream;
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using support::bformat;
|
||||
|
||||
InsetCaption::InsetCaption(BufferParams const & bp)
|
||||
: InsetText(bp), textclass_(bp.getLyXTextClass()), counter_(-1)
|
||||
: InsetText(bp), textclass_(bp.getLyXTextClass())
|
||||
{
|
||||
setAutoBreakRows(true);
|
||||
setDrawFrame(true);
|
||||
@ -93,20 +94,40 @@ void InsetCaption::cursorPos(BufferView const & bv,
|
||||
}
|
||||
|
||||
|
||||
void InsetCaption::setLabel(docstring const & label)
|
||||
void InsetCaption::setCustomLabel(docstring const & label)
|
||||
{
|
||||
label_ = _(to_ascii(label));
|
||||
if (!support::isAscii(label) || label.empty())
|
||||
// This must be a user defined layout. We cannot translate
|
||||
// this, since gettext accepts only ascii keys.
|
||||
custom_label_ = label;
|
||||
else
|
||||
custom_label_ = _(to_ascii(label));
|
||||
}
|
||||
|
||||
|
||||
void InsetCaption::addToToc(TocList & toclist, Buffer const & buf) const
|
||||
{
|
||||
if (type_.empty())
|
||||
return;
|
||||
|
||||
ParConstIterator pit = par_const_iterator_begin(*this);
|
||||
|
||||
Toc & toc = toclist[type_];
|
||||
docstring const str = convert<docstring>(counter_)
|
||||
+ ". " + pit->asString(buf, false);
|
||||
toc.push_back(TocItem(pit, 0, str));
|
||||
}
|
||||
|
||||
|
||||
bool InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
{
|
||||
mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
|
||||
if (counter_ < 0)
|
||||
if (type_.empty())
|
||||
full_label_ = _("Senseless!!! ");
|
||||
else {
|
||||
docstring const number = convert<docstring>(counter_);
|
||||
full_label_ = bformat(from_ascii("%1$s %2$s:"), label_, number);
|
||||
docstring label = custom_label_.empty()? _(type_): custom_label_;
|
||||
full_label_ = bformat(from_ascii("%1$s %2$s:"), label, number);
|
||||
}
|
||||
labelwidth_ = theFontMetrics(mi.base.font).width(full_label_);
|
||||
dim.wid = labelwidth_;
|
||||
|
@ -67,7 +67,11 @@ public:
|
||||
///
|
||||
void setCount(int c) { counter_ = c; }
|
||||
///
|
||||
void setLabel(docstring const & label);
|
||||
void setType(std::string const & type) { type_ = type; }
|
||||
///
|
||||
void setCustomLabel(docstring const & label);
|
||||
///
|
||||
void addToToc(TocList &, Buffer const &) const;
|
||||
|
||||
private:
|
||||
///
|
||||
@ -77,7 +81,9 @@ private:
|
||||
///
|
||||
mutable int labelwidth_;
|
||||
///
|
||||
docstring label_;
|
||||
std::string type_;
|
||||
///
|
||||
docstring custom_label_;
|
||||
///
|
||||
int counter_;
|
||||
///
|
||||
|
@ -378,6 +378,12 @@ void InsetFloat::sideways(bool s, BufferParams const & bp)
|
||||
|
||||
void InsetFloat::addToToc(TocList & toclist, Buffer const & buf) const
|
||||
{
|
||||
// Is there a need to provide a list of float insets?
|
||||
return;
|
||||
|
||||
// Abdel (01/02/2006): I'll let this code for reference in case
|
||||
// there's a need to do something similar for another kind of
|
||||
// inset.
|
||||
ParConstIterator pit = par_const_iterator_begin(*this);
|
||||
ParConstIterator end = par_const_iterator_end(*this);
|
||||
|
||||
|
@ -226,19 +226,8 @@ bool InsetWrap::showInsetDialog(BufferView * bv) const
|
||||
|
||||
void InsetWrap::addToToc(TocList & toclist, Buffer const & buf) const
|
||||
{
|
||||
ParConstIterator pit = par_const_iterator_begin(*this);
|
||||
ParConstIterator end = par_const_iterator_end(*this);
|
||||
|
||||
// Find a caption layout in one of the (child inset's) pars
|
||||
for (; pit != end; ++pit) {
|
||||
if (pit->layout()->labeltype == LABEL_SENSITIVE) {
|
||||
Toc & toc = toclist[params_.type];
|
||||
docstring const str =
|
||||
convert<docstring>(toc.size() + 1)
|
||||
+ ". " + pit->asString(buf, false);
|
||||
toc.push_back(TocItem(pit, 0, str));
|
||||
}
|
||||
}
|
||||
// Is there a need to provide a list of wrap insets?
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user