2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetCaption.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2000-07-17 18:27:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetCaption.h"
|
|
|
|
#include "InsetFloat.h"
|
|
|
|
#include "InsetWrap.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
2007-11-03 18:50:54 +00:00
|
|
|
#include "BufferView.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Counters.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-11-03 18:50:54 +00:00
|
|
|
#include "Dimension.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
#include "Floating.h"
|
2001-03-11 03:20:44 +00:00
|
|
|
#include "FloatList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2007-01-30 13:23:21 +00:00
|
|
|
#include "FuncStatus.h"
|
2007-10-24 15:32:43 +00:00
|
|
|
#include "InsetList.h"
|
2009-07-12 20:09:53 +00:00
|
|
|
#include "Language.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
2007-01-30 13:23:21 +00:00
|
|
|
#include "output_latex.h"
|
2009-11-30 17:27:10 +00:00
|
|
|
#include "output_xhtml.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "OutputParams.h"
|
|
|
|
#include "Paragraph.h"
|
2013-05-25 23:38:20 +00:00
|
|
|
#include "ParIterator.h"
|
2007-11-07 23:34:45 +00:00
|
|
|
#include "TextClass.h"
|
2010-12-01 00:32:30 +00:00
|
|
|
#include "TextMetrics.h"
|
2007-02-01 12:45:14 +00:00
|
|
|
#include "TocBackend.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
#include "frontends/Painter.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/gettext.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
2002-11-21 18:33:09 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 19:57:42 +00:00
|
|
|
using namespace lyx::support;
|
2003-06-02 10:03:27 +00:00
|
|
|
|
2007-02-01 12:45:14 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
2012-12-30 17:29:02 +00:00
|
|
|
InsetCaption::InsetCaption(Buffer * buf, string const & type)
|
|
|
|
: InsetText(buf, InsetText::PlainLayout), type_(type)
|
2001-03-11 03:20:44 +00:00
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
setAutoBreakRows(true);
|
2004-08-14 15:55:22 +00:00
|
|
|
setDrawFrame(true);
|
2010-08-24 01:29:22 +00:00
|
|
|
setFrameColor(Color_collapsableframe);
|
2001-03-11 03:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetCaption::write(ostream & os) const
|
2000-07-18 17:45:27 +00:00
|
|
|
{
|
2012-12-30 17:29:02 +00:00
|
|
|
os << "Caption";
|
|
|
|
if (!type_.empty()) {
|
|
|
|
os << " "
|
|
|
|
<< type_;
|
|
|
|
}
|
|
|
|
os << "\n";
|
2009-08-09 15:29:34 +00:00
|
|
|
text().write(os);
|
2000-07-18 17:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-28 22:33:04 +00:00
|
|
|
docstring InsetCaption::layoutName() const
|
2009-12-14 17:15:32 +00:00
|
|
|
{
|
|
|
|
if (type_.empty())
|
|
|
|
return from_ascii("Caption");
|
|
|
|
return from_utf8("Caption:" + type_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-17 16:23:27 +00:00
|
|
|
void InsetCaption::cursorPos(BufferView const & bv,
|
|
|
|
CursorSlice const & sl, bool boundary, int & x, int & y) const
|
2006-05-05 05:51:51 +00:00
|
|
|
{
|
2006-10-17 16:23:27 +00:00
|
|
|
InsetText::cursorPos(bv, sl, boundary, x, y);
|
2006-05-05 05:51:51 +00:00
|
|
|
x += labelwidth_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-01 12:45:14 +00:00
|
|
|
void InsetCaption::setCustomLabel(docstring const & label)
|
2006-05-28 17:02:57 +00:00
|
|
|
{
|
2014-02-16 08:57:17 +00:00
|
|
|
custom_label_ = translateIfPossible(label);
|
2007-02-01 12:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 21:18:26 +00:00
|
|
|
void InsetCaption::addToToc(DocIterator const & cpit, bool output_active) const
|
2007-02-01 12:45:14 +00:00
|
|
|
{
|
2012-12-30 17:29:02 +00:00
|
|
|
if (floattype_.empty())
|
2007-02-01 12:45:14 +00:00
|
|
|
return;
|
|
|
|
|
2008-05-13 08:23:44 +00:00
|
|
|
DocIterator pit = cpit;
|
2011-01-12 22:23:27 +00:00
|
|
|
pit.push_back(CursorSlice(const_cast<InsetCaption &>(*this)));
|
2007-02-01 12:45:14 +00:00
|
|
|
|
2012-12-30 17:29:02 +00:00
|
|
|
Toc & toc = buffer().tocBackend().toc(floattype_);
|
|
|
|
docstring str = full_label_;
|
2013-03-24 13:34:00 +00:00
|
|
|
int length = output_active ? INT_MAX : TOC_ENTRY_LENGTH;
|
2014-03-29 17:34:36 +00:00
|
|
|
text().forOutliner(str, length);
|
2013-03-08 21:18:26 +00:00
|
|
|
toc.push_back(TocItem(pit, 0, str, output_active));
|
2008-06-03 11:33:13 +00:00
|
|
|
|
|
|
|
// Proceed with the rest of the inset.
|
2013-03-08 21:18:26 +00:00
|
|
|
InsetText::addToToc(cpit, output_active);
|
2006-05-28 17:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const
|
2006-05-05 05:51:51 +00:00
|
|
|
{
|
2007-10-28 18:51:54 +00:00
|
|
|
FontInfo tmpfont = mi.base.font;
|
|
|
|
mi.base.font = mi.base.bv->buffer().params().getFont().fontInfo();
|
2007-01-30 13:23:21 +00:00
|
|
|
labelwidth_ = theFontMetrics(mi.base.font).width(full_label_);
|
2007-02-11 23:35:12 +00:00
|
|
|
// add some space to separate the label from the inset text
|
|
|
|
labelwidth_ += 2 * TEXT_TO_INSET_OFFSET;
|
2006-05-05 05:51:51 +00:00
|
|
|
dim.wid = labelwidth_;
|
|
|
|
Dimension textdim;
|
2007-08-31 17:32:27 +00:00
|
|
|
// Correct for button and label width
|
2007-01-30 13:23:21 +00:00
|
|
|
mi.base.textwidth -= dim.wid;
|
|
|
|
InsetText::metrics(mi, textdim);
|
2007-09-24 17:51:15 +00:00
|
|
|
mi.base.font = tmpfont;
|
2007-08-31 17:32:27 +00:00
|
|
|
mi.base.textwidth += dim.wid;
|
2007-12-12 19:28:07 +00:00
|
|
|
dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des);
|
2006-05-05 05:51:51 +00:00
|
|
|
dim.asc = textdim.asc;
|
|
|
|
dim.wid += textdim.wid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-01 00:32:30 +00:00
|
|
|
void InsetCaption::drawBackground(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
|
|
|
TextMetrics & tm = pi.base.bv->textMetrics(&text());
|
|
|
|
int const h = tm.height() + 2 * TEXT_TO_INSET_OFFSET;
|
|
|
|
int const yy = y - TEXT_TO_INSET_OFFSET - tm.ascent();
|
2010-12-01 00:35:35 +00:00
|
|
|
pi.pain.fillRectangle(x, yy, labelwidth_, h, pi.backgroundColor(this));
|
2010-12-01 00:32:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
void InsetCaption::draw(PainterInfo & pi, int x, int y) const
|
2001-03-11 03:20:44 +00:00
|
|
|
{
|
|
|
|
// We must draw the label, we should get the label string
|
|
|
|
// from the enclosing float inset.
|
|
|
|
// The question is: Who should draw the label, the caption inset,
|
|
|
|
// the text inset or the paragraph?
|
|
|
|
// We should also draw the float number (Lgb)
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
// Answer: the text inset (in buffer_funcs.cpp: setCaption).
|
2007-01-30 13:23:21 +00:00
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
FontInfo tmpfont = pi.base.font;
|
|
|
|
pi.base.font = pi.base.bv->buffer().params().getFont().fontInfo();
|
2010-09-09 13:15:25 +00:00
|
|
|
pi.base.font.setColor(pi.textColor(pi.base.font.color()).baseColor);
|
2010-12-01 00:32:30 +00:00
|
|
|
int const xx = x + TEXT_TO_INSET_OFFSET;
|
|
|
|
pi.pain.text(xx, y, full_label_, pi.base.font);
|
2007-09-09 20:21:43 +00:00
|
|
|
InsetText::draw(pi, x + labelwidth_, y);
|
2007-09-24 17:51:15 +00:00
|
|
|
pi.base.font = tmpfont;
|
2006-05-05 05:51:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-11 08:20:13 +00:00
|
|
|
void InsetCaption::edit(Cursor & cur, bool front, EntryDirection entry_from)
|
2006-05-05 05:51:51 +00:00
|
|
|
{
|
|
|
|
cur.push(*this);
|
2008-02-10 19:52:45 +00:00
|
|
|
InsetText::edit(cur, front, entry_from);
|
2006-05-05 05:51:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset * InsetCaption::editXY(Cursor & cur, int x, int y)
|
2006-05-05 05:51:51 +00:00
|
|
|
{
|
|
|
|
cur.push(*this);
|
|
|
|
return InsetText::editXY(cur, x, y);
|
2001-03-11 03:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-13 09:04:52 +00:00
|
|
|
bool InsetCaption::insetAllowed(InsetCode code) const
|
2007-02-02 13:55:14 +00:00
|
|
|
{
|
|
|
|
switch (code) {
|
2009-12-09 23:36:59 +00:00
|
|
|
// code that is not allowed in a caption
|
2007-02-02 13:55:14 +00:00
|
|
|
case CAPTION_CODE:
|
2010-08-07 03:16:38 +00:00
|
|
|
case FLOAT_CODE:
|
|
|
|
case FOOT_CODE:
|
2007-11-23 02:10:00 +00:00
|
|
|
case NEWPAGE_CODE:
|
2010-08-07 03:16:38 +00:00
|
|
|
case MARGIN_CODE:
|
2007-12-21 20:42:46 +00:00
|
|
|
case MATHMACRO_CODE:
|
2010-08-07 03:16:38 +00:00
|
|
|
case TABULAR_CODE:
|
|
|
|
case WRAP_CODE:
|
2007-02-02 13:55:14 +00:00
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return InsetText::insetAllowed(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-30 17:29:02 +00:00
|
|
|
void InsetCaption::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
|
|
|
switch (cmd.action()) {
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
2014-03-05 22:53:29 +00:00
|
|
|
if (cmd.getArg(0) == "changetype") {
|
2012-12-30 17:29:02 +00:00
|
|
|
cur.recordUndoInset(ATOMIC_UNDO, this);
|
|
|
|
type_ = cmd.getArg(1);
|
|
|
|
cur.forceBufferUpdate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
InsetText::doDispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetCaption::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2007-01-30 13:23:21 +00:00
|
|
|
FuncStatus & status) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2007-01-30 13:23:21 +00:00
|
|
|
|
2012-12-30 17:29:02 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
string const first_arg = cmd.getArg(0);
|
|
|
|
if (first_arg == "changetype") {
|
|
|
|
string const type = cmd.getArg(1);
|
|
|
|
status.setOnOff(type == type_);
|
2013-03-22 21:23:38 +00:00
|
|
|
bool varia = type != "LongTableNoNumber";
|
2012-12-30 17:29:02 +00:00
|
|
|
// check if the immediate parent inset allows caption variation
|
|
|
|
if (cur.depth() > 1) {
|
2013-03-22 21:23:38 +00:00
|
|
|
if (&cur[cur.depth() - 2].inset())
|
|
|
|
varia = cur[cur.depth() - 2].inset().allowsCaptionVariation(type);
|
2012-12-30 17:29:02 +00:00
|
|
|
}
|
|
|
|
status.setEnabled(varia
|
|
|
|
&& buffer().params().documentClass().hasInsetLayout(
|
|
|
|
from_ascii("Caption:" + type)));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return InsetText::getStatus(cur, cmd, status);
|
|
|
|
}
|
|
|
|
|
2012-09-29 16:06:42 +00:00
|
|
|
case LFUN_PARAGRAPH_BREAK:
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(false);
|
2007-01-30 13:23:21 +00:00
|
|
|
return true;
|
|
|
|
|
2008-03-25 05:33:39 +00:00
|
|
|
case LFUN_INSET_TOGGLE:
|
|
|
|
// pass back to owner
|
|
|
|
cur.undispatched();
|
|
|
|
return false;
|
|
|
|
|
2007-01-30 13:23:21 +00:00
|
|
|
default:
|
|
|
|
return InsetText::getStatus(cur, cmd, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetCaption::latex(otexstream & os,
|
|
|
|
OutputParams const & runparams_in) const
|
2001-03-11 03:20:44 +00:00
|
|
|
{
|
2009-02-07 12:27:24 +00:00
|
|
|
if (runparams_in.inFloat == OutputParams::SUBFLOAT)
|
2008-03-02 11:30:50 +00:00
|
|
|
// caption is output as an optional argument
|
2011-02-10 20:02:48 +00:00
|
|
|
return;
|
2001-03-11 03:20:44 +00:00
|
|
|
// This is a bit too simplistic to take advantage of
|
|
|
|
// caption options we must add more later. (Lgb)
|
|
|
|
// This code is currently only able to handle the simple
|
|
|
|
// \caption{...}, later we will make it take advantage
|
|
|
|
// of the one of the caption packages. (Lgb)
|
2007-02-02 13:55:14 +00:00
|
|
|
OutputParams runparams = runparams_in;
|
|
|
|
// FIXME: actually, it is moving only when there is no
|
|
|
|
// optional argument.
|
2012-12-30 17:29:02 +00:00
|
|
|
runparams.moving_arg = !runparams.inTableCell;
|
2011-02-10 20:02:48 +00:00
|
|
|
InsetText::latex(os, runparams);
|
2013-05-31 14:20:00 +00:00
|
|
|
// Backwards compatibility: We always had a linebreak after
|
|
|
|
// the caption (see #8514)
|
|
|
|
os << breakln;
|
2007-03-18 10:59:16 +00:00
|
|
|
runparams_in.encoding = runparams.encoding;
|
2001-03-11 03:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetCaption::plaintext(odocstringstream & os,
|
|
|
|
OutputParams const & runparams, size_t max_length) const
|
2001-03-11 03:20:44 +00:00
|
|
|
{
|
2007-02-16 09:53:51 +00:00
|
|
|
os << '[' << full_label_ << "\n";
|
2013-03-08 19:52:18 +00:00
|
|
|
InsetText::plaintext(os, runparams, max_length);
|
2007-02-16 09:53:51 +00:00
|
|
|
os << "\n]";
|
|
|
|
|
2007-02-20 17:52:41 +00:00
|
|
|
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
2001-03-11 03:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetCaption::docbook(odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
OutputParams const & runparams) const
|
2001-03-11 03:20:44 +00:00
|
|
|
{
|
2001-11-02 16:11:19 +00:00
|
|
|
int ret;
|
|
|
|
os << "<title>";
|
2008-02-27 20:43:16 +00:00
|
|
|
ret = InsetText::docbook(os, runparams);
|
2001-11-02 16:11:19 +00:00
|
|
|
os << "</title>\n";
|
|
|
|
return ret;
|
2001-03-11 03:20:44 +00:00
|
|
|
}
|
2005-02-23 12:01:50 +00:00
|
|
|
|
|
|
|
|
2009-11-30 17:27:10 +00:00
|
|
|
docstring InsetCaption::xhtml(XHTMLStream & xs, OutputParams const & rp) const
|
2009-06-19 12:49:08 +00:00
|
|
|
{
|
2009-10-26 20:47:12 +00:00
|
|
|
if (rp.html_disable_captions)
|
2009-06-19 18:32:50 +00:00
|
|
|
return docstring();
|
2012-07-10 21:44:21 +00:00
|
|
|
InsetLayout const & il = getLayout();
|
|
|
|
string const tag = il.htmltag();
|
|
|
|
string attr = il.htmlattr();
|
|
|
|
if (!type_.empty()) {
|
|
|
|
string const our_class = "float-caption-" + type_;
|
|
|
|
size_t const loc = attr.find("class='");
|
|
|
|
if (loc != string::npos)
|
2013-07-20 13:56:34 +00:00
|
|
|
attr.insert(loc + 7, our_class+ " ");
|
|
|
|
else
|
|
|
|
attr = attr + " class='" + our_class + "'";
|
2012-07-10 21:44:21 +00:00
|
|
|
}
|
|
|
|
xs << html::StartTag(tag, attr);
|
2009-11-30 17:27:10 +00:00
|
|
|
docstring def = getCaptionAsHTML(xs, rp);
|
2012-07-10 21:44:21 +00:00
|
|
|
xs << html::EndTag(tag);
|
2009-06-19 18:32:50 +00:00
|
|
|
return def;
|
2009-06-19 12:49:08 +00:00
|
|
|
}
|
|
|
|
|
2009-11-30 17:27:10 +00:00
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetCaption::getArgument(otexstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
OutputParams const & runparams) const
|
2007-05-14 20:42:14 +00:00
|
|
|
{
|
2012-12-04 16:06:52 +00:00
|
|
|
InsetLayout const & il = getLayout();
|
|
|
|
|
|
|
|
if (!il.leftdelim().empty())
|
|
|
|
os << il.leftdelim();
|
|
|
|
|
|
|
|
OutputParams rp = runparams;
|
|
|
|
if (isPassThru())
|
|
|
|
rp.pass_thru = true;
|
|
|
|
if (il.isNeedProtect())
|
|
|
|
rp.moving_arg = true;
|
|
|
|
rp.par_begin = 0;
|
|
|
|
rp.par_end = paragraphs().size();
|
|
|
|
|
|
|
|
// Output the contents of the inset
|
|
|
|
latexParagraphs(buffer(), text(), os, rp);
|
|
|
|
runparams.encoding = rp.encoding;
|
|
|
|
|
|
|
|
if (!il.rightdelim().empty())
|
|
|
|
os << il.rightdelim();
|
2007-05-14 20:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-19 13:50:19 +00:00
|
|
|
int InsetCaption::getCaptionAsPlaintext(odocstream & os,
|
2008-04-10 09:22:49 +00:00
|
|
|
OutputParams const & runparams) const
|
|
|
|
{
|
|
|
|
os << full_label_ << ' ';
|
2013-03-08 19:52:18 +00:00
|
|
|
odocstringstream ods;
|
2013-03-15 20:16:40 +00:00
|
|
|
int const retval = InsetText::plaintext(ods, runparams);
|
2013-03-08 19:52:18 +00:00
|
|
|
os << ods.str();
|
2013-03-15 20:16:40 +00:00
|
|
|
return retval;
|
2008-04-10 09:22:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-30 17:27:10 +00:00
|
|
|
docstring InsetCaption::getCaptionAsHTML(XHTMLStream & xs,
|
2009-06-19 12:49:08 +00:00
|
|
|
OutputParams const & runparams) const
|
|
|
|
{
|
2009-11-30 17:27:10 +00:00
|
|
|
xs << full_label_ << ' ';
|
|
|
|
InsetText::XHTMLOptions const opts =
|
|
|
|
InsetText::WriteLabel | InsetText::WriteInnerTag;
|
|
|
|
return InsetText::insetAsXHTML(xs, runparams, opts);
|
2009-06-19 12:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-03 22:13:45 +00:00
|
|
|
void InsetCaption::updateBuffer(ParIterator const & it, UpdateType utype)
|
2007-02-16 09:53:51 +00:00
|
|
|
{
|
2008-05-20 11:54:23 +00:00
|
|
|
Buffer const & master = *buffer().masterBuffer();
|
|
|
|
DocumentClass const & tclass = master.params().documentClass();
|
2009-07-12 20:09:53 +00:00
|
|
|
string const & lang = it.paragraph().getParLanguage(master.params())->code();
|
2007-08-12 21:43:58 +00:00
|
|
|
Counters & cnts = tclass.counters();
|
|
|
|
string const & type = cnts.current_float();
|
2010-01-20 19:42:12 +00:00
|
|
|
if (utype == OutputUpdate) {
|
2010-01-20 19:03:17 +00:00
|
|
|
// counters are local to the caption
|
|
|
|
cnts.saveLastCounter();
|
|
|
|
}
|
2008-02-11 13:23:42 +00:00
|
|
|
// Memorize type for addToToc().
|
2012-12-30 17:29:02 +00:00
|
|
|
floattype_ = type;
|
2007-08-12 21:43:58 +00:00
|
|
|
if (type.empty())
|
2008-05-20 11:54:23 +00:00
|
|
|
full_label_ = master.B_("Senseless!!! ");
|
2007-02-16 09:53:51 +00:00
|
|
|
else {
|
2007-08-12 21:43:58 +00:00
|
|
|
// FIXME: life would be _much_ simpler if listings was
|
|
|
|
// listed in Floating.
|
|
|
|
docstring name;
|
|
|
|
if (type == "listing")
|
2008-05-20 11:54:23 +00:00
|
|
|
name = master.B_("Listing");
|
2007-08-12 21:43:58 +00:00
|
|
|
else
|
2008-05-20 11:54:23 +00:00
|
|
|
name = master.B_(tclass.floats().getType(type).name());
|
2008-03-02 11:30:50 +00:00
|
|
|
docstring counter = from_utf8(type);
|
2009-02-07 12:27:24 +00:00
|
|
|
if (cnts.isSubfloat()) {
|
2012-12-30 17:29:02 +00:00
|
|
|
// only standard captions allowed in subfloats
|
|
|
|
type_ = "Standard";
|
2008-03-02 11:30:50 +00:00
|
|
|
counter = "sub-" + from_utf8(type);
|
|
|
|
name = bformat(_("Sub-%1$s"),
|
2008-05-20 11:54:23 +00:00
|
|
|
master.B_(tclass.floats().getType(type).name()));
|
2008-03-02 11:30:50 +00:00
|
|
|
}
|
2012-12-30 17:29:02 +00:00
|
|
|
docstring sec;
|
2014-02-16 09:23:30 +00:00
|
|
|
docstring const lstring = getLayout().labelstring();
|
|
|
|
docstring const labelstring = isAscii(lstring) ?
|
|
|
|
master.B_(to_ascii(lstring)) : lstring;
|
2008-03-02 11:30:50 +00:00
|
|
|
if (cnts.hasCounter(counter)) {
|
2014-02-25 07:00:43 +00:00
|
|
|
// for longtables, we step the counter upstream
|
|
|
|
if (!cnts.isLongtable())
|
|
|
|
cnts.step(counter, utype);
|
2012-12-30 17:29:02 +00:00
|
|
|
sec = cnts.theCounter(counter, lang);
|
|
|
|
}
|
2014-02-16 09:23:30 +00:00
|
|
|
if (labelstring != master.B_("standard")) {
|
2012-12-30 17:29:02 +00:00
|
|
|
if (!sec.empty())
|
|
|
|
sec += from_ascii(" ");
|
2014-02-16 09:23:30 +00:00
|
|
|
sec += bformat(from_ascii("(%1$s)"), labelstring);
|
2012-12-30 17:29:02 +00:00
|
|
|
}
|
|
|
|
if (!sec.empty())
|
|
|
|
full_label_ = bformat(from_ascii("%1$s %2$s:"), name, sec);
|
|
|
|
else
|
|
|
|
full_label_ = bformat(from_ascii("%1$s #:"), name);
|
2007-02-16 09:53:51 +00:00
|
|
|
}
|
2007-08-12 21:43:58 +00:00
|
|
|
|
|
|
|
// Do the real work now.
|
2010-03-03 22:13:45 +00:00
|
|
|
InsetText::updateBuffer(it, utype);
|
2010-01-20 19:42:12 +00:00
|
|
|
if (utype == OutputUpdate)
|
2010-01-20 19:03:17 +00:00
|
|
|
cnts.restoreLastCounter();
|
2007-02-16 09:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-30 17:29:02 +00:00
|
|
|
string InsetCaption::contextMenuName() const
|
|
|
|
{
|
|
|
|
return "context-caption";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|