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
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>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-11-29 07:04:28 +00:00
|
|
|
|
#include "support/gettext.h"
|
2007-10-24 15:32:43 +00:00
|
|
|
|
#include "InsetList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "MetricsInfo.h"
|
2007-01-30 13:23:21 +00:00
|
|
|
|
#include "output_latex.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "OutputParams.h"
|
|
|
|
|
#include "Paragraph.h"
|
2007-02-02 21:08:44 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2007-11-07 23:34:45 +00:00
|
|
|
|
#include "TextClass.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
|
|
|
|
|
|
|
|
|
#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 {
|
|
|
|
|
|
|
|
|
|
|
2008-03-04 22:28:18 +00:00
|
|
|
|
InsetCaption::InsetCaption(Buffer const & buf)
|
|
|
|
|
: InsetText(buf)
|
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);
|
2007-10-25 12:41:02 +00:00
|
|
|
|
setFrameColor(Color_captionframe);
|
2008-03-04 22:28:18 +00:00
|
|
|
|
// There will always be only one
|
|
|
|
|
paragraphs().back().setLayout(buf.params().documentClass().emptyLayout());
|
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
|
|
|
|
{
|
|
|
|
|
os << "Caption\n";
|
2008-02-27 20:43:16 +00:00
|
|
|
|
text_.write(buffer(), os);
|
2000-07-18 17:45:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
void InsetCaption::read(Lexer & lex)
|
2000-07-18 17:45:27 +00:00
|
|
|
|
{
|
2001-03-11 03:20:44 +00:00
|
|
|
|
#if 0
|
|
|
|
|
// We will enably this check again when the compability
|
|
|
|
|
// code is removed from Buffer::Read (Lgb)
|
|
|
|
|
string const token = lex.GetString();
|
2000-07-18 17:45:27 +00:00
|
|
|
|
if (token != "Caption") {
|
|
|
|
|
lyxerr << "InsetCaption::Read: consistency check failed."
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
2001-03-11 03:20:44 +00:00
|
|
|
|
#endif
|
2008-02-27 20:43:16 +00:00
|
|
|
|
InsetText::read(lex);
|
2000-07-18 17:45:27 +00:00
|
|
|
|
}
|
2001-03-11 03:20:44 +00:00
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
docstring InsetCaption::editMessage() const
|
2001-03-11 03:20:44 +00:00
|
|
|
|
{
|
2006-09-09 18:52:00 +00:00
|
|
|
|
return _("Opened Caption Inset");
|
2001-03-11 03:20:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2007-12-12 19:57:42 +00:00
|
|
|
|
if (!isAscii(label) || label.empty())
|
2007-02-01 12:45:14 +00:00
|
|
|
|
// 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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
void InsetCaption::addToToc(ParConstIterator const & cpit) const
|
2007-02-01 12:45:14 +00:00
|
|
|
|
{
|
|
|
|
|
if (type_.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
2008-02-15 08:32:27 +00:00
|
|
|
|
ParConstIterator pit = cpit;
|
|
|
|
|
pit.push_back(*this);
|
2007-02-01 12:45:14 +00:00
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
Toc & toc = buffer().tocBackend().toc(type_);
|
|
|
|
|
docstring const str = full_label_ + ". " + pit->asString(false);
|
2007-02-01 12:45:14 +00:00
|
|
|
|
toc.push_back(TocItem(pit, 0, str));
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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();
|
2007-09-17 21:45:14 +00:00
|
|
|
|
pi.pain.text(x, 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) {
|
|
|
|
|
case FLOAT_CODE:
|
|
|
|
|
case TABULAR_CODE:
|
|
|
|
|
case WRAP_CODE:
|
|
|
|
|
case CAPTION_CODE:
|
2007-11-23 02:10:00 +00:00
|
|
|
|
case NEWPAGE_CODE:
|
2007-12-21 20:42:46 +00:00
|
|
|
|
case MATHMACRO_CODE:
|
2007-02-02 13:55:14 +00:00
|
|
|
|
return false;
|
|
|
|
|
default:
|
|
|
|
|
return InsetText::insetAllowed(code);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_BREAK_PARAGRAPH:
|
|
|
|
|
case LFUN_BREAK_PARAGRAPH_SKIP:
|
|
|
|
|
status.enabled(false);
|
|
|
|
|
return true;
|
|
|
|
|
|
2007-02-02 21:08:44 +00:00
|
|
|
|
case LFUN_OPTIONAL_INSERT:
|
2007-10-24 15:32:43 +00:00
|
|
|
|
status.enabled(cur.paragraph().insetList().find(OPTARG_CODE) == -1);
|
2007-02-02 21:08:44 +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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetCaption::latex(odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const & runparams_in) const
|
2001-03-11 03:20:44 +00:00
|
|
|
|
{
|
2008-03-02 11:30:50 +00:00
|
|
|
|
if (in_subfloat_)
|
|
|
|
|
// caption is output as an optional argument
|
|
|
|
|
return 0;
|
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.
|
|
|
|
|
runparams.moving_arg = true;
|
2007-01-30 13:23:21 +00:00
|
|
|
|
os << "\\caption";
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int l = latexOptArgInsets(paragraphs()[0], os, runparams, 1);
|
2007-01-30 13:23:21 +00:00
|
|
|
|
os << '{';
|
2008-02-27 20:43:16 +00:00
|
|
|
|
l += InsetText::latex(os, runparams);
|
2007-01-30 13:23:21 +00:00
|
|
|
|
os << "}\n";
|
2007-03-18 10:59:16 +00:00
|
|
|
|
runparams_in.encoding = runparams.encoding;
|
2001-03-11 03:20:44 +00:00
|
|
|
|
return l + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetCaption::plaintext(odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2001-03-11 03:20:44 +00:00
|
|
|
|
{
|
2007-02-16 09:53:51 +00:00
|
|
|
|
os << '[' << full_label_ << "\n";
|
2008-02-27 20:43:16 +00:00
|
|
|
|
InsetText::plaintext(os, runparams);
|
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
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetCaption::getArgument(odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2007-05-14 20:42:14 +00:00
|
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
|
return InsetText::latex(os, runparams);
|
2007-05-14 20:42:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetCaption::getOptArg(odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2007-05-14 20:42:14 +00:00
|
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
|
return latexOptArgInsets(paragraphs()[0], os, runparams, 1);
|
2007-05-14 20:42:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
void InsetCaption::updateLabels(ParIterator const & it)
|
2007-02-16 09:53:51 +00:00
|
|
|
|
{
|
2008-02-28 01:42:02 +00:00
|
|
|
|
DocumentClass const & tclass = buffer().params().documentClass();
|
2007-08-12 21:43:58 +00:00
|
|
|
|
Counters & cnts = tclass.counters();
|
|
|
|
|
string const & type = cnts.current_float();
|
2008-02-11 13:23:42 +00:00
|
|
|
|
// Memorize type for addToToc().
|
|
|
|
|
type_ = type;
|
2008-03-02 11:30:50 +00:00
|
|
|
|
in_subfloat_ = cnts.isSubfloat();
|
2007-08-12 21:43:58 +00:00
|
|
|
|
if (type.empty())
|
2008-02-27 20:43:16 +00:00
|
|
|
|
full_label_ = buffer().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-02-27 20:43:16 +00:00
|
|
|
|
name = buffer().B_("Listing");
|
2007-08-12 21:43:58 +00:00
|
|
|
|
else
|
2008-02-27 20:43:16 +00:00
|
|
|
|
name = buffer().B_(tclass.floats().getType(type).name());
|
2008-03-02 11:30:50 +00:00
|
|
|
|
docstring counter = from_utf8(type);
|
|
|
|
|
if (in_subfloat_) {
|
|
|
|
|
counter = "sub-" + from_utf8(type);
|
|
|
|
|
name = bformat(_("Sub-%1$s"),
|
|
|
|
|
buffer().B_(tclass.floats().getType(type).name()));
|
|
|
|
|
}
|
|
|
|
|
if (cnts.hasCounter(counter)) {
|
|
|
|
|
cnts.step(counter);
|
2007-08-12 21:43:58 +00:00
|
|
|
|
full_label_ = bformat(from_ascii("%1$s %2$s:"),
|
2008-03-02 11:30:50 +00:00
|
|
|
|
name,
|
|
|
|
|
cnts.theCounter(counter));
|
2007-08-12 21:43:58 +00:00
|
|
|
|
} 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.
|
2008-02-27 20:43:16 +00:00
|
|
|
|
InsetText::updateLabels(it);
|
2007-02-16 09:53:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|