2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetcaption.C
|
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
|
|
#include "insetcaption.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "insetfloat.h"
|
|
|
|
|
#include "insetwrap.h"
|
|
|
|
|
|
2002-08-27 15:51:19 +00:00
|
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2006-05-05 05:51:51 +00:00
|
|
|
|
#include "counters.h"
|
|
|
|
|
#include "cursor.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "BufferView.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "Floating.h"
|
2001-03-11 03:20:44 +00:00
|
|
|
|
#include "FloatList.h"
|
2007-01-30 13:23:21 +00:00
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "FuncStatus.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "gettext.h"
|
2003-09-16 10:54:23 +00:00
|
|
|
|
#include "LColor.h"
|
2003-05-30 06:48:24 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2007-01-30 13:23:21 +00:00
|
|
|
|
#include "output_latex.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
|
#include "paragraph.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"
|
2006-05-05 05:51:51 +00:00
|
|
|
|
#include "support/convert.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
2002-11-21 18:33:09 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::bformat;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2005-02-23 12:01:50 +00:00
|
|
|
|
using std::auto_ptr;
|
2000-07-19 10:22:12 +00:00
|
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
2000-07-19 10:22:12 +00:00
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
|
2002-03-03 20:25:07 +00:00
|
|
|
|
InsetCaption::InsetCaption(BufferParams const & bp)
|
2006-05-05 05:51:51 +00:00
|
|
|
|
: InsetText(bp), textclass_(bp.getLyXTextClass())
|
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);
|
2003-08-11 09:09:01 +00:00
|
|
|
|
setFrameColor(LColor::captionframe);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetCaption::write(Buffer const & buf, ostream & os) const
|
2000-07-18 17:45:27 +00:00
|
|
|
|
{
|
|
|
|
|
os << "Caption\n";
|
2003-12-02 12:39:14 +00:00
|
|
|
|
text_.write(buf, os);
|
2000-07-18 17:45:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetCaption::read(Buffer const & buf, LyXLex & 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
|
2001-06-28 10:25:20 +00:00
|
|
|
|
InsetText::read(buf, lex);
|
2000-07-18 17:45:27 +00:00
|
|
|
|
}
|
2001-03-11 03:20:44 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-09 18:52:00 +00:00
|
|
|
|
docstring const 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-01-30 13:23:21 +00:00
|
|
|
|
void InsetCaption::setLabel(docstring const & label)
|
2006-05-28 17:02:57 +00:00
|
|
|
|
{
|
2007-01-30 13:23:21 +00:00
|
|
|
|
label_ = _(to_ascii(label));
|
2006-05-28 17:02:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const
|
2006-05-05 05:51:51 +00:00
|
|
|
|
{
|
|
|
|
|
mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
|
2007-01-30 13:23:21 +00:00
|
|
|
|
docstring const number = convert<docstring>(counter_);
|
|
|
|
|
full_label_ = bformat(from_ascii("%1$s %2$s:"), label_, number);
|
|
|
|
|
labelwidth_ = theFontMetrics(mi.base.font).width(full_label_);
|
2006-05-05 05:51:51 +00:00
|
|
|
|
dim.wid = labelwidth_;
|
|
|
|
|
Dimension textdim;
|
|
|
|
|
InsetText::metrics(mi, textdim);
|
2007-01-30 13:23:21 +00:00
|
|
|
|
// Correct for button width, and re-fit
|
|
|
|
|
mi.base.textwidth -= dim.wid;
|
|
|
|
|
InsetText::metrics(mi, textdim);
|
2006-05-05 05:51:51 +00:00
|
|
|
|
dim.des = std::max(dim.des - textdim.asc + dim.asc, textdim.des);
|
|
|
|
|
dim.asc = textdim.asc;
|
|
|
|
|
dim.wid += textdim.wid;
|
|
|
|
|
dim.asc += TEXT_TO_INSET_OFFSET;
|
|
|
|
|
dim.des += TEXT_TO_INSET_OFFSET;
|
|
|
|
|
dim.wid += 2 * TEXT_TO_INSET_OFFSET;
|
|
|
|
|
mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool const changed = dim_ != dim;
|
2006-05-05 05:51:51 +00:00
|
|
|
|
dim_ = dim;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
return changed;
|
2006-05-05 05:51:51 +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-01-30 13:23:21 +00:00
|
|
|
|
// Answer: the text inset (in buffer_funcs.C: setCaption).
|
|
|
|
|
|
|
|
|
|
labelwidth_ = pi.pain.text(x, y, full_label_, pi.base.font);
|
2006-05-05 05:51:51 +00:00
|
|
|
|
InsetText::draw(pi, x + labelwidth_, y);
|
|
|
|
|
setPosCache(pi, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCaption::edit(LCursor & cur, bool left)
|
|
|
|
|
{
|
|
|
|
|
cur.push(*this);
|
|
|
|
|
InsetText::edit(cur, left);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetBase * InsetCaption::editXY(LCursor & cur, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
cur.push(*this);
|
|
|
|
|
return InsetText::editXY(cur, x, y);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-01-30 13:23:21 +00:00
|
|
|
|
bool InsetCaption::getStatus(LCursor & cur, FuncRequest const & cmd,
|
|
|
|
|
FuncStatus & status) const
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_CAPTION_INSERT:
|
|
|
|
|
case LFUN_FLOAT_INSERT:
|
|
|
|
|
case LFUN_FLOAT_WIDE_INSERT:
|
|
|
|
|
case LFUN_WRAP_INSERT:
|
|
|
|
|
case LFUN_PARAGRAPH_MOVE_UP:
|
|
|
|
|
case LFUN_PARAGRAPH_MOVE_DOWN:
|
|
|
|
|
case LFUN_BREAK_PARAGRAPH:
|
|
|
|
|
case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
|
|
|
|
|
case LFUN_BREAK_PARAGRAPH_SKIP:
|
|
|
|
|
case LFUN_PARAGRAPH_SPACING:
|
|
|
|
|
case LFUN_PAGEBREAK_INSERT:
|
|
|
|
|
status.enabled(false);
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return InsetText::getStatus(cur, cmd, status);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetCaption::latex(Buffer const & buf, odocstream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
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-01-30 13:23:21 +00:00
|
|
|
|
os << "\\caption";
|
|
|
|
|
int l = latexOptArgInsets(buf, paragraphs()[0], os, runparams, 1);
|
|
|
|
|
os << '{';
|
|
|
|
|
l += InsetText::latex(buf, os, runparams);
|
|
|
|
|
os << "}\n";
|
2001-03-11 03:20:44 +00:00
|
|
|
|
return l + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-01-30 13:23:21 +00:00
|
|
|
|
int InsetCaption::plaintext(Buffer const & buf, odocstream & os,
|
|
|
|
|
OutputParams const & runparams) const
|
2001-03-11 03:20:44 +00:00
|
|
|
|
{
|
2007-01-30 13:23:21 +00:00
|
|
|
|
os << full_label_ << ' ';
|
|
|
|
|
return InsetText::plaintext(buf, os, runparams);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 21:00:33 +00:00
|
|
|
|
int InsetCaption::docbook(Buffer const & buf, odocstream & os,
|
2003-11-05 12:06:20 +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>";
|
2003-10-31 18:45:43 +00:00
|
|
|
|
ret = InsetText::docbook(buf, 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto_ptr<InsetBase> InsetCaption::doClone() const
|
|
|
|
|
{
|
|
|
|
|
return auto_ptr<InsetBase>(new InsetCaption(*this));
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|