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
|
|
|
|
*
|
2002-09-25 14:26:13 +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"
|
2002-05-23 09:21:32 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2002-05-24 14:34:32 +00:00
|
|
|
|
#include "frontends/font_metrics.h"
|
2001-03-11 03:20:44 +00:00
|
|
|
|
#include "BufferView.h"
|
2002-08-27 15:51:19 +00:00
|
|
|
|
#include "buffer.h"
|
2001-03-11 03:20:44 +00:00
|
|
|
|
#include "FloatList.h"
|
|
|
|
|
#include "insets/insetfloat.h"
|
2003-05-06 06:16:59 +00:00
|
|
|
|
#include "insets/insetwrap.h"
|
2000-07-18 17:45:27 +00:00
|
|
|
|
#include "debug.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
|
#include "gettext.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
|
#include "Lsstream.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2003-05-06 06:16:59 +00:00
|
|
|
|
#include "support/LAssert.h"
|
2003-03-30 20:25:44 +00:00
|
|
|
|
#include "support/BoostFormat.h"
|
2002-11-21 18:33:09 +00:00
|
|
|
|
|
2000-07-19 10:22:12 +00:00
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::endl;
|
|
|
|
|
|
2002-03-03 20:25:07 +00:00
|
|
|
|
InsetCaption::InsetCaption(BufferParams const & bp)
|
|
|
|
|
: InsetText(bp)
|
2001-03-11 03:20:44 +00:00
|
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
|
setAutoBreakRows(true);
|
|
|
|
|
setDrawFrame(0, InsetText::LOCKED);
|
|
|
|
|
setFrameColor(0, LColor::captionframe);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetCaption::write(Buffer const * buf, ostream & os) const
|
2000-07-18 17:45:27 +00:00
|
|
|
|
{
|
|
|
|
|
os << "Caption\n";
|
2001-06-28 10:25:20 +00:00
|
|
|
|
writeParagraphData(buf, os);
|
2000-07-18 17:45:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +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
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
string const InsetCaption::editMessage() const
|
2001-03-11 03:20:44 +00:00
|
|
|
|
{
|
|
|
|
|
return _("Opened Caption Inset");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCaption::draw(BufferView * bv, LyXFont const & f,
|
2003-03-17 01:34:36 +00:00
|
|
|
|
int baseline, float & x) 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)
|
|
|
|
|
|
|
|
|
|
// See if we can find the name of the float this caption
|
|
|
|
|
// belongs to.
|
|
|
|
|
Inset * i1 = owner();
|
|
|
|
|
Inset * i2 = i1 ? i1->owner() : 0;
|
2003-05-06 06:16:59 +00:00
|
|
|
|
string type;
|
|
|
|
|
if (i2->lyxCode() == FLOAT_CODE)
|
|
|
|
|
type = static_cast<InsetFloat *>(i2)->params().type;
|
|
|
|
|
else if (i2->lyxCode() == WRAP_CODE)
|
|
|
|
|
type = static_cast<InsetWrap *>(i2)->params().type;
|
|
|
|
|
else
|
|
|
|
|
lyx::Assert(0);
|
|
|
|
|
|
2002-08-27 15:51:19 +00:00
|
|
|
|
FloatList const & floats =
|
|
|
|
|
bv->buffer()->params.getLyXTextClass().floats();
|
|
|
|
|
string const fl = i2 ? floats.getType(type).name() : N_("Float");
|
2001-03-11 03:20:44 +00:00
|
|
|
|
|
|
|
|
|
// Discover the number...
|
2003-05-13 09:48:57 +00:00
|
|
|
|
string const num = "#";
|
2001-03-11 03:20:44 +00:00
|
|
|
|
|
2002-11-24 15:20:31 +00:00
|
|
|
|
// Generate the label
|
2003-05-13 09:48:57 +00:00
|
|
|
|
string const label = bformat("%1$s %2$s:", _(fl), num);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
Painter & pain = bv->painter();
|
2002-05-24 14:34:32 +00:00
|
|
|
|
int const w = font_metrics::width(label, f);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
pain.text(int(x), baseline, label, f);
|
|
|
|
|
x += w;
|
|
|
|
|
|
2003-03-17 01:34:36 +00:00
|
|
|
|
InsetText::draw(bv, f, baseline, x);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
int InsetCaption::latex(Buffer const * buf, ostream & os,
|
2001-03-11 03:20:44 +00:00
|
|
|
|
bool fragile, bool free_spc) const
|
|
|
|
|
{
|
|
|
|
|
// 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)
|
|
|
|
|
ostringstream ost;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
int const l = InsetText::latex(buf, ost, fragile, free_spc);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
os << "\\caption{" << ost.str() << "}\n";
|
|
|
|
|
return l + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
int InsetCaption::ascii(Buffer const * /*buf*/,
|
2001-03-11 03:20:44 +00:00
|
|
|
|
ostream & /*os*/, int /*linelen*/) const
|
|
|
|
|
{
|
2001-08-19 13:13:47 +00:00
|
|
|
|
// FIX: Implement me!
|
2001-03-11 03:20:44 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
int InsetCaption::docbook(Buffer const * buf, ostream & os, bool mixcont) const
|
2001-03-11 03:20:44 +00:00
|
|
|
|
{
|
2001-11-02 16:11:19 +00:00
|
|
|
|
int ret;
|
|
|
|
|
os << "<title>";
|
2002-06-18 15:44:30 +00:00
|
|
|
|
ret = InsetText::docbook(buf, os, mixcont);
|
2001-11-02 16:11:19 +00:00
|
|
|
|
os << "</title>\n";
|
|
|
|
|
return ret;
|
2001-03-11 03:20:44 +00:00
|
|
|
|
}
|