2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetFloat.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 Jürgen Vigna
|
|
|
|
* \author Lars Gullik Bjønnes
|
|
|
|
* \author Jürgen Spitzmüller
|
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.
|
2002-09-25 14:26:13 +00:00
|
|
|
*/
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
#include <config.h>
|
2000-06-28 13:35:52 +00:00
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetFloat.h"
|
2008-03-02 11:30:50 +00:00
|
|
|
#include "InsetCaption.h"
|
2003-03-05 19:46:08 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
2003-03-05 19:46:08 +00:00
|
|
|
#include "BufferView.h"
|
2007-08-12 21:43:58 +00:00
|
|
|
#include "Counters.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
2003-03-05 19:46:08 +00:00
|
|
|
#include "Floating.h"
|
|
|
|
#include "FloatList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2005-04-22 08:57:22 +00:00
|
|
|
#include "FuncStatus.h"
|
2008-03-02 11:30:50 +00:00
|
|
|
#include "InsetList.h"
|
2003-03-05 19:46:08 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "OutputParams.h"
|
2008-03-02 11:30:50 +00:00
|
|
|
#include "ParIterator.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.h"
|
2003-03-05 19:46:08 +00:00
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
#include "support/convert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/docstream.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/gettext.h"
|
2001-07-30 11:56:00 +00:00
|
|
|
#include "support/lstrings.h"
|
2008-03-27 22:26:24 +00:00
|
|
|
|
|
|
|
#include "frontends/Application.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
namespace lyx {
|
2003-05-13 16:24:49 +00:00
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
// With this inset it will be possible to support the latex package
|
|
|
|
// float.sty, and I am sure that with this and some additional support
|
|
|
|
// classes we can support similar functionality in other formats
|
|
|
|
// (read DocBook).
|
|
|
|
// By using float.sty we will have the same handling for all floats, both
|
|
|
|
// for those already in existance (table and figure) and all user created
|
2008-11-14 15:58:50 +00:00
|
|
|
// ones¹. So suddenly we give the users the possibility of creating new
|
2000-06-28 13:35:52 +00:00
|
|
|
// kinds of floats on the fly. (and with a uniform look)
|
|
|
|
//
|
|
|
|
// API to float.sty:
|
|
|
|
// \newfloat{type}{placement}{ext}[within]
|
|
|
|
// type - The "type" of the new class of floats, like program or
|
|
|
|
// algorithm. After the appropriate \newfloat, commands
|
|
|
|
// such as \begin{program} or \end{algorithm*} will be
|
|
|
|
// available.
|
|
|
|
// placement - The default placement for the given class of floats.
|
|
|
|
// They are like in standard LaTeX: t, b, p and h for top,
|
|
|
|
// bottom, page, and here, respectively. On top of that
|
|
|
|
// there is a new type, H, which does not really correspond
|
|
|
|
// to a float, since it means: put it "here" and nowhere else.
|
|
|
|
// Note, however that the H specifier is special and, because
|
|
|
|
// of implementation details cannot be used in the second
|
|
|
|
// argument of \newfloat.
|
|
|
|
// ext - The file name extension of an auxiliary file for the list
|
|
|
|
// of figures (or whatever). LaTeX writes the captions to
|
|
|
|
// this file.
|
|
|
|
// within - This (optional) argument determines whether floats of this
|
|
|
|
// class will be numbered within some sectional unit of the
|
|
|
|
// document. For example, if within is equal to chapter, the
|
2002-03-21 17:09:55 +00:00
|
|
|
// floats will be numbered within chapters.
|
2000-06-28 13:35:52 +00:00
|
|
|
// \floatstyle{style}
|
|
|
|
// style - plain, boxed, ruled
|
|
|
|
// \floatname{float}{floatname}
|
|
|
|
// float -
|
|
|
|
// floatname -
|
|
|
|
// \floatplacement{float}{placement}
|
|
|
|
// float -
|
|
|
|
// placement -
|
|
|
|
// \restylefloat{float}
|
|
|
|
// float -
|
|
|
|
// \listof{type}{title}
|
|
|
|
// title -
|
|
|
|
|
2008-11-14 15:58:50 +00:00
|
|
|
// ¹ the algorithm float is defined using the float.sty package. Like this
|
2000-06-28 13:35:52 +00:00
|
|
|
// \floatstyle{ruled}
|
|
|
|
// \newfloat{algorithm}{htbp}{loa}[<sect>]
|
|
|
|
// \floatname{algorithm}{Algorithm}
|
|
|
|
//
|
2001-03-11 03:20:44 +00:00
|
|
|
// The intention is that floats should be definable from two places:
|
|
|
|
// - layout files
|
|
|
|
// - the "gui" (i.e. by the user)
|
|
|
|
//
|
|
|
|
// From layout files.
|
|
|
|
// This should only be done for floats defined in a documentclass and that
|
|
|
|
// does not need any additional packages. The two most known floats in this
|
|
|
|
// category is "table" and "figure". Floats defined in layout files are only
|
|
|
|
// stored in lyx files if the user modifies them.
|
|
|
|
//
|
|
|
|
// By the user.
|
|
|
|
// There should be a gui dialog (and also a collection of lyxfuncs) where
|
|
|
|
// the user can modify existing floats and/or create new ones.
|
|
|
|
//
|
|
|
|
// The individual floats will also have some settable
|
|
|
|
// variables: wide and placement.
|
|
|
|
//
|
2000-06-28 13:35:52 +00:00
|
|
|
// Lgb
|
|
|
|
|
2002-04-26 15:38:15 +00:00
|
|
|
|
2008-03-04 22:28:18 +00:00
|
|
|
InsetFloat::InsetFloat(Buffer const & buf, string const & type)
|
|
|
|
: InsetCollapsable(buf), name_(from_utf8(type))
|
2000-06-28 13:35:52 +00:00
|
|
|
{
|
2008-03-04 22:28:18 +00:00
|
|
|
setLabel(_("float: ") + floatName(type, buf.params()));
|
2003-03-05 17:56:47 +00:00
|
|
|
params_.type = type;
|
2000-06-28 13:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-30 11:56:00 +00:00
|
|
|
InsetFloat::~InsetFloat()
|
|
|
|
{
|
2008-03-27 22:26:24 +00:00
|
|
|
hideDialogs("float", this);
|
2001-07-30 11:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-05 15:35:02 +00:00
|
|
|
docstring InsetFloat::name() const
|
|
|
|
{
|
|
|
|
return "Float:" + name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-10 09:22:49 +00:00
|
|
|
docstring InsetFloat::toolTip(BufferView const & bv, int x, int y) const
|
|
|
|
{
|
2008-08-29 00:38:51 +00:00
|
|
|
if (InsetCollapsable::toolTip(bv, x, y).empty() || isOpen())
|
2008-04-27 14:47:07 +00:00
|
|
|
return docstring();
|
|
|
|
|
2008-04-10 09:22:49 +00:00
|
|
|
OutputParams rp(&buffer().params().encoding());
|
2008-08-29 00:38:51 +00:00
|
|
|
return getCaptionText(rp);
|
2008-04-10 09:22:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetFloat::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2000-06-28 13:35:52 +00:00
|
|
|
{
|
2003-03-05 19:46:08 +00:00
|
|
|
switch (cmd.action) {
|
2003-08-05 08:07:07 +00:00
|
|
|
|
2003-03-05 19:46:08 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
InsetFloatParams params;
|
2008-03-27 22:26:24 +00:00
|
|
|
string2params(to_utf8(cmd.argument()), params);
|
2008-08-19 14:56:12 +00:00
|
|
|
|
|
|
|
// placement, wide and sideways are not used for subfloats
|
|
|
|
if (!params_.subfloat) {
|
|
|
|
params_.placement = params.placement;
|
|
|
|
params_.wide = params.wide;
|
|
|
|
params_.sideways = params.sideways;
|
|
|
|
setWide(params_.wide, cur.buffer().params(), false);
|
|
|
|
setSideways(params_.sideways, cur.buffer().params(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
setNewLabel(cur.buffer().params());
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2000-07-17 18:27:53 +00:00
|
|
|
}
|
2003-03-07 15:58:02 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE: {
|
2008-03-27 22:26:24 +00:00
|
|
|
cur.bv().updateDialog("float", params2string(params()));
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-03-07 15:58:02 +00:00
|
|
|
}
|
|
|
|
|
2003-03-05 19:46:08 +00:00
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2001-05-31 16:48:26 +00:00
|
|
|
}
|
2003-03-05 17:56:47 +00:00
|
|
|
}
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetFloat::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2005-04-22 08:57:22 +00:00
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(true);
|
2005-04-22 09:16:28 +00:00
|
|
|
return true;
|
2005-04-22 08:57:22 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetFloat::updateLabels(ParIterator const & it)
|
2007-08-12 21:43:58 +00:00
|
|
|
{
|
2008-05-20 11:54:23 +00:00
|
|
|
Counters & cnts = buffer().masterBuffer()->params().documentClass().counters();
|
2007-08-12 21:43:58 +00:00
|
|
|
string const saveflt = cnts.current_float();
|
2008-03-02 11:30:50 +00:00
|
|
|
bool const savesubflt = cnts.isSubfloat();
|
|
|
|
|
2008-06-05 16:05:52 +00:00
|
|
|
bool const subflt = (it.innerInsetOfType(FLOAT_CODE)
|
|
|
|
|| it.innerInsetOfType(WRAP_CODE));
|
2008-03-02 11:30:50 +00:00
|
|
|
// floats can only embed subfloats of their own kind
|
|
|
|
if (subflt)
|
|
|
|
params_.type = saveflt;
|
2008-03-27 22:26:24 +00:00
|
|
|
setSubfloat(subflt, buffer().params());
|
2007-08-12 21:43:58 +00:00
|
|
|
|
|
|
|
// Tell to captions what the current float is
|
|
|
|
cnts.current_float(params().type);
|
2008-03-02 11:30:50 +00:00
|
|
|
cnts.isSubfloat(subflt);
|
2007-08-12 21:43:58 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetCollapsable::updateLabels(it);
|
2007-08-12 21:43:58 +00:00
|
|
|
|
|
|
|
//reset afterwards
|
|
|
|
cnts.current_float(saveflt);
|
2008-03-02 11:30:50 +00:00
|
|
|
cnts.isSubfloat(savesubflt);
|
2007-08-12 21:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-05 19:46:08 +00:00
|
|
|
void InsetFloatParams::write(ostream & os) const
|
2003-03-05 17:56:47 +00:00
|
|
|
{
|
2004-04-02 08:54:37 +00:00
|
|
|
os << "Float " << type << '\n';
|
2003-03-05 19:46:08 +00:00
|
|
|
|
2003-08-05 08:07:07 +00:00
|
|
|
if (!placement.empty())
|
2003-03-05 19:46:08 +00:00
|
|
|
os << "placement " << placement << "\n";
|
2003-08-05 08:07:07 +00:00
|
|
|
|
|
|
|
if (wide)
|
2003-03-05 19:46:08 +00:00
|
|
|
os << "wide true\n";
|
2003-08-05 08:07:07 +00:00
|
|
|
else
|
2003-03-05 19:46:08 +00:00
|
|
|
os << "wide false\n";
|
2004-04-03 08:37:12 +00:00
|
|
|
|
2004-03-29 11:38:39 +00:00
|
|
|
if (sideways)
|
|
|
|
os << "sideways true\n";
|
|
|
|
else
|
|
|
|
os << "sideways false\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
void InsetFloatParams::read(Lexer & lex)
|
2000-06-28 13:35:52 +00:00
|
|
|
{
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.setContext("InsetFloatParams::read");
|
|
|
|
if (lex.checkFor("placement"))
|
2004-04-02 08:54:37 +00:00
|
|
|
lex >> placement;
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> "wide" >> wide;
|
|
|
|
lex >> "sideways" >> sideways;
|
2003-03-05 17:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetFloat::write(ostream & os) const
|
2003-03-05 19:46:08 +00:00
|
|
|
{
|
|
|
|
params_.write(os);
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetCollapsable::write(os);
|
2003-03-05 19:46:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetFloat::read(Lexer & lex)
|
2003-03-05 17:56:47 +00:00
|
|
|
{
|
2003-03-05 19:46:08 +00:00
|
|
|
params_.read(lex);
|
2008-03-27 22:26:24 +00:00
|
|
|
setWide(params_.wide, buffer().params());
|
|
|
|
setSideways(params_.sideways, buffer().params());
|
|
|
|
setSubfloat(params_.subfloat, buffer().params());
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetCollapsable::read(lex);
|
2000-06-28 13:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetFloat::validate(LaTeXFeatures & features) const
|
2000-06-28 13:35:52 +00:00
|
|
|
{
|
2008-03-05 00:21:05 +00:00
|
|
|
if (support::contains(params_.placement, 'H'))
|
2002-01-10 10:05:45 +00:00
|
|
|
features.require("float");
|
2004-04-03 08:37:12 +00:00
|
|
|
|
2004-03-29 11:38:39 +00:00
|
|
|
if (params_.sideways)
|
2008-01-11 18:56:53 +00:00
|
|
|
features.require("rotfloat");
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2008-03-02 11:30:50 +00:00
|
|
|
if (params_.subfloat)
|
|
|
|
features.require("subfig");
|
|
|
|
|
|
|
|
features.useFloat(params_.type, params_.subfloat);
|
2001-06-28 10:25:20 +00:00
|
|
|
InsetCollapsable::validate(features);
|
2000-06-28 13:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring InsetFloat::editMessage() const
|
2000-06-28 13:35:52 +00:00
|
|
|
{
|
2006-09-09 18:52:00 +00:00
|
|
|
return _("Opened Float Inset");
|
2000-06-28 13:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetFloat::latex(odocstream & os, OutputParams const & runparams) const
|
2000-06-28 13:35:52 +00:00
|
|
|
{
|
2008-03-02 11:30:50 +00:00
|
|
|
if (params_.subfloat) {
|
|
|
|
if (runparams.moving_arg)
|
|
|
|
os << "\\protect";
|
|
|
|
os << "\\subfloat";
|
|
|
|
|
|
|
|
OutputParams rp = runparams;
|
|
|
|
docstring const caption = getCaption(rp);
|
|
|
|
if (!caption.empty()) {
|
|
|
|
os << caption;
|
|
|
|
}
|
|
|
|
os << '{';
|
|
|
|
int const i = InsetText::latex(os, runparams);
|
|
|
|
os << "}";
|
|
|
|
|
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
|
2008-02-28 01:42:02 +00:00
|
|
|
FloatList const & floats = buffer().params().documentClass().floats();
|
2008-01-11 18:56:53 +00:00
|
|
|
string tmptype = params_.type;
|
|
|
|
if (params_.sideways)
|
|
|
|
tmptype = "sideways" + params_.type;
|
|
|
|
if (params_.wide && (!params_.sideways ||
|
|
|
|
params_.type == "figure" ||
|
|
|
|
params_.type == "table"))
|
|
|
|
tmptype += "*";
|
2001-07-04 07:44:27 +00:00
|
|
|
// Figure out the float placement to use.
|
|
|
|
// From lowest to highest:
|
|
|
|
// - float default placement
|
|
|
|
// - document wide default placement
|
|
|
|
// - specific float placement
|
|
|
|
string placement;
|
2008-02-27 20:43:16 +00:00
|
|
|
string const buf_placement = buffer().params().float_placement;
|
2003-03-05 17:56:47 +00:00
|
|
|
string const def_placement = floats.defaultPlacement(params_.type);
|
|
|
|
if (!params_.placement.empty()
|
|
|
|
&& params_.placement != def_placement) {
|
|
|
|
placement = params_.placement;
|
|
|
|
} else if (params_.placement.empty()
|
2002-09-26 08:59:34 +00:00
|
|
|
&& !buf_placement.empty()
|
2001-07-04 07:44:27 +00:00
|
|
|
&& buf_placement != def_placement) {
|
|
|
|
placement = buf_placement;
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2002-05-05 15:15:51 +00:00
|
|
|
// The \n is used to force \begin{<floatname>} to appear in a new line.
|
|
|
|
// The % is needed to prevent two consecutive \n chars in the case
|
|
|
|
// when the current output line is empty.
|
2006-10-21 00:16:43 +00:00
|
|
|
os << "%\n\\begin{" << from_ascii(tmptype) << '}';
|
2001-07-04 07:44:27 +00:00
|
|
|
// We only output placement if different from the def_placement.
|
2004-03-29 11:38:39 +00:00
|
|
|
// sidewaysfloats always use their own page
|
|
|
|
if (!placement.empty() && !params_.sideways) {
|
2006-10-21 00:16:43 +00:00
|
|
|
os << '[' << from_ascii(placement) << ']';
|
2001-07-04 07:44:27 +00:00
|
|
|
}
|
2002-11-27 10:30:28 +00:00
|
|
|
os << '\n';
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int const i = InsetText::latex(os, runparams);
|
2002-05-05 15:15:51 +00:00
|
|
|
|
|
|
|
// The \n is used to force \end{<floatname>} to appear in a new line.
|
|
|
|
// In this case, we do not case if the current output line is empty.
|
2006-10-21 00:16:43 +00:00
|
|
|
os << "\n\\end{" << from_ascii(tmptype) << "}\n";
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2002-05-09 13:36:45 +00:00
|
|
|
return i + 4;
|
2000-06-28 13:35:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetFloat::plaintext(odocstream & os, OutputParams const & runparams) const
|
2007-02-16 08:15:16 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
os << '[' << buffer().B_("float") << ' '
|
|
|
|
<< floatName(params_.type, buffer().params()) << ":\n";
|
|
|
|
InsetText::plaintext(os, runparams);
|
2007-02-16 08:15:16 +00:00
|
|
|
os << "\n]";
|
|
|
|
|
2007-02-20 17:52:41 +00:00
|
|
|
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
2007-02-16 08:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetFloat::docbook(odocstream & os, OutputParams const & runparams) const
|
2001-03-23 08:37:44 +00:00
|
|
|
{
|
2008-03-02 11:30:50 +00:00
|
|
|
// FIXME Implement subfloat!
|
2007-05-28 22:27:45 +00:00
|
|
|
// FIXME UNICODE
|
|
|
|
os << '<' << from_ascii(params_.type) << '>';
|
2008-02-27 20:43:16 +00:00
|
|
|
int const i = InsetText::docbook(os, runparams);
|
2006-10-21 00:16:43 +00:00
|
|
|
os << "</" << from_ascii(params_.type) << '>';
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-13 09:04:52 +00:00
|
|
|
bool InsetFloat::insetAllowed(InsetCode code) const
|
2001-07-12 14:35:38 +00:00
|
|
|
{
|
2008-03-02 11:30:50 +00:00
|
|
|
return code != FOOT_CODE
|
|
|
|
&& code != MARGIN_CODE
|
|
|
|
&& (code != FLOAT_CODE || !params_.subfloat);
|
2000-06-28 13:35:52 +00:00
|
|
|
}
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
2001-07-30 11:56:00 +00:00
|
|
|
bool InsetFloat::showInsetDialog(BufferView * bv) const
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
if (!InsetText::showInsetDialog(bv))
|
2008-03-27 22:26:24 +00:00
|
|
|
bv->showDialog("float", params2string(params()),
|
|
|
|
const_cast<InsetFloat *>(this));
|
2001-07-30 11:56:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-19 14:56:12 +00:00
|
|
|
void InsetFloat::setWide(bool w, BufferParams const & bp, bool update_label)
|
2000-07-15 23:51:46 +00:00
|
|
|
{
|
2003-03-05 17:56:47 +00:00
|
|
|
params_.wide = w;
|
2008-08-19 14:56:12 +00:00
|
|
|
if (update_label)
|
|
|
|
setNewLabel(bp);
|
2000-07-15 23:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-19 14:56:12 +00:00
|
|
|
void InsetFloat::setSideways(bool s, BufferParams const & bp, bool update_label)
|
2004-03-29 11:38:39 +00:00
|
|
|
{
|
|
|
|
params_.sideways = s;
|
2008-08-19 14:56:12 +00:00
|
|
|
if (update_label)
|
|
|
|
setNewLabel(bp);
|
2004-03-29 11:38:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-19 14:56:12 +00:00
|
|
|
void InsetFloat::setSubfloat(bool s, BufferParams const & bp, bool update_label)
|
2008-03-02 11:30:50 +00:00
|
|
|
{
|
|
|
|
params_.subfloat = s;
|
2008-08-19 14:56:12 +00:00
|
|
|
if (update_label)
|
|
|
|
setNewLabel(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFloat::setNewLabel(BufferParams const & bp)
|
|
|
|
{
|
|
|
|
docstring lab = _("float: ");
|
|
|
|
|
|
|
|
if( params_.subfloat )
|
|
|
|
lab = _("subfloat: ");
|
|
|
|
|
|
|
|
lab += floatName(params_.type, bp);
|
|
|
|
|
|
|
|
if (params_.wide)
|
|
|
|
lab += '*';
|
|
|
|
|
|
|
|
if (params_.sideways)
|
|
|
|
lab += _(" (sideways)");
|
|
|
|
|
2008-03-02 11:30:50 +00:00
|
|
|
setLabel(lab);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetFloat::getCaption(OutputParams const & runparams) const
|
|
|
|
{
|
|
|
|
if (paragraphs().empty())
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
ParagraphList::const_iterator pit = paragraphs().begin();
|
|
|
|
for (; pit != paragraphs().end(); ++pit) {
|
|
|
|
InsetList::const_iterator it = pit->insetList().begin();
|
|
|
|
for (; it != pit->insetList().end(); ++it) {
|
|
|
|
Inset & inset = *it->inset;
|
|
|
|
if (inset.lyxCode() == CAPTION_CODE) {
|
|
|
|
odocstringstream ods;
|
|
|
|
InsetCaption * ins =
|
|
|
|
static_cast<InsetCaption *>(it->inset);
|
|
|
|
ins->getOptArg(ods, runparams);
|
|
|
|
ods << '[';
|
|
|
|
ins->getArgument(ods, runparams);
|
|
|
|
ods << ']';
|
|
|
|
return ods.str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-10 09:22:49 +00:00
|
|
|
docstring InsetFloat::getCaptionText(OutputParams const & runparams) const
|
|
|
|
{
|
|
|
|
if (paragraphs().empty())
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
ParagraphList::const_iterator pit = paragraphs().begin();
|
|
|
|
for (; pit != paragraphs().end(); ++pit) {
|
|
|
|
InsetList::const_iterator it = pit->insetList().begin();
|
|
|
|
for (; it != pit->insetList().end(); ++it) {
|
|
|
|
Inset & inset = *it->inset;
|
|
|
|
if (inset.lyxCode() == CAPTION_CODE) {
|
|
|
|
odocstringstream ods;
|
|
|
|
InsetCaption * ins =
|
|
|
|
static_cast<InsetCaption *>(it->inset);
|
|
|
|
ins->getCaptionText(ods, runparams);
|
|
|
|
return ods.str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
void InsetFloat::string2params(string const & in, InsetFloatParams & params)
|
2003-03-05 19:46:08 +00:00
|
|
|
{
|
|
|
|
params = InsetFloatParams();
|
2003-04-24 20:02:49 +00:00
|
|
|
if (in.empty())
|
|
|
|
return;
|
2003-05-21 21:20:50 +00:00
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
istringstream data(in);
|
2008-04-02 23:06:22 +00:00
|
|
|
Lexer lex;
|
2003-03-07 14:08:10 +00:00
|
|
|
lex.setStream(data);
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.setContext("InsetFloat::string2params");
|
|
|
|
lex >> "float" >> "Float";
|
|
|
|
lex >> params.type; // We have to read the type here!
|
2003-12-11 15:23:15 +00:00
|
|
|
params.read(lex);
|
2003-03-05 19:46:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
string InsetFloat::params2string(InsetFloatParams const & params)
|
2003-03-05 19:46:08 +00:00
|
|
|
{
|
|
|
|
ostringstream data;
|
2008-03-27 22:26:24 +00:00
|
|
|
data << "float" << ' ';
|
2003-03-05 19:46:08 +00:00
|
|
|
params.write(data);
|
2003-09-15 11:00:00 +00:00
|
|
|
return data.str();
|
2003-03-05 19:46:08 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|