-void setCaptionLabels(Inset & inset, string const & type,
- docstring const label, Counters & counters)
-{
- Text * text = inset.getText(0);
- if (!text)
- return;
-
- ParagraphList & pars = text->paragraphs();
- if (pars.empty())
- return;
-
- docstring const counter = from_ascii(type);
-
- ParagraphList::iterator p = pars.begin();
- for (; p != pars.end(); ++p) {
- InsetList::iterator it2 = p->insetlist.begin();
- InsetList::iterator end2 = p->insetlist.end();
- // Any caption within this float should have the same
- // label prefix but different numbers.
- for (; it2 != end2; ++it2) {
- Inset & icap = *it2->inset;
- // Look deeper just in case.
- setCaptionLabels(icap, type, label, counters);
- if (icap.lyxCode() == Inset::CAPTION_CODE) {
- // We found a caption!
- counters.step(counter);
- int number = counters.value(counter);
- InsetCaption & ic = static_cast<InsetCaption &>(icap);
- ic.setType(type);
- ic.setCount(number);
- ic.setCustomLabel(label);
- }
- }
- }
-}
-
-
-void setCaptions(Paragraph & par, TextClass const & textclass)
-{
- if (par.insetlist.empty())
- return;
-
- Counters & counters = textclass.counters();
-
- InsetList::iterator it = par.insetlist.begin();
- InsetList::iterator end = par.insetlist.end();
- for (; it != end; ++it) {
- Inset & inset = *it->inset;
- if (inset.lyxCode() == Inset::FLOAT_CODE
- || inset.lyxCode() == Inset::WRAP_CODE) {
- docstring const name = inset.name();
- if (name.empty())
- continue;
-
- Floating const & fl = textclass.floats().getType(to_ascii(name));
- // FIXME UNICODE
- string const & type = fl.type();
- docstring const label = from_utf8(fl.name());
- setCaptionLabels(inset, type, label, counters);
- }
- else if (inset.lyxCode() == Inset::TABULAR_CODE
- && static_cast<InsetTabular &>(inset).tabular.isLongTabular()) {
- // FIXME: are "table" and "Table" the correct type and label?
- setCaptionLabels(inset, "table", from_ascii("Table"), counters);
- }
- }
-}
-