*
* \author Angus Leeming
* \author Martin Vermeer
- * \author Jürgen Spitzmüller
+ * \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#include "DispatchResult.h"
#include "FuncStatus.h"
#include "FuncRequest.h"
-#include "support/gettext.h"
#include "LaTeXFeatures.h"
#include "Lexer.h"
#include "MetricsInfo.h"
+#include "output_xhtml.h"
#include "TextClass.h"
#include "support/debug.h"
+#include "support/docstream.h"
+#include "support/gettext.h"
+#include "support/lstrings.h"
#include "support/Translator.h"
#include "frontends/Application.h"
#include <sstream>
using namespace std;
+using namespace lyx::support;
namespace lyx {
//
/////////////////////////////////////////////////////////////////////////
-InsetBox::InsetBox(Buffer const & buffer, string const & label)
+InsetBox::InsetBox(Buffer * buffer, string const & label)
: InsetCollapsable(buffer), params_(label)
-{
- if (forceEmptyLayout())
- paragraphs().back().setLayout(buffer.params().documentClass().emptyLayout());
-}
+{}
InsetBox::~InsetBox()
}
-docstring InsetBox::editMessage() const
-{
- return _("Opened Box Inset");
-}
-
-
docstring InsetBox::name() const
{
// FIXME: UNICODE
void InsetBox::setButtonLabel()
{
- BoxType btype = boxtranslator().find(params_.type);
+ BoxType const btype = boxtranslator().find(params_.type);
- docstring label;
- label += _("Box");
- label += " (";
- if (btype == Frameless) {
+ docstring const type = _("Box");
+
+ docstring inner;
+ if (params_.inner_box) {
if (params_.use_parbox)
- label += _("Parbox");
+ inner = _("Parbox");
else
- label += _("Minipage");
- } else {
- label += boxtranslator_loc().find(btype);
+ inner = _("Minipage");
}
- label += ")";
+ docstring frame;
+ if (btype != Frameless)
+ frame = boxtranslator_loc().find(btype);
+
+ docstring label;
+ if (inner.empty() && frame.empty())
+ label = type;
+ else if (inner.empty())
+ label = bformat(_("%1$s (%2$s)"),
+ type, frame);
+ else if (frame.empty())
+ label = bformat(_("%1$s (%2$s)"),
+ type, inner);
+ else
+ label = bformat(_("%1$s (%2$s, %3$s)"),
+ type, inner, frame);
setLabel(label);
}
}
-bool InsetBox::forceEmptyLayout(idx_type) const
+bool InsetBox::forcePlainLayout(idx_type) const
{
- return !params_.inner_box;
+ return !params_.inner_box && params_.type != "Framed";
}
bool InsetBox::showInsetDialog(BufferView * bv) const
{
- bv->showDialog("box", params2string(params_),
+ bv->showDialog("box", params2string(params_),
const_cast<InsetBox *>(this));
return true;
}
params_.type = cmd.getArg(1);
else
string2params(to_utf8(cmd.argument()), params_);
- setLayout(cur.buffer().params());
break;
}
case LFUN_INSET_MODIFY:
if (cmd.getArg(0) == "changetype")
flag.setOnOff(cmd.getArg(1) == params_.type);
- else
- flag.enabled(true);
+ flag.setEnabled(true);
return true;
case LFUN_INSET_DIALOG_UPDATE:
- flag.enabled(true);
+ flag.setEnabled(true);
return true;
case LFUN_BREAK_PARAGRAPH:
- if (params_.inner_box)
+ if (params_.inner_box || params_.type == "Framed")
return InsetCollapsable::getStatus(cur, cmd, flag);
- flag.enabled(false);
+ flag.setEnabled(false);
return true;
default:
os << "\\framebox";
if (!params_.inner_box) {
os << "{\\makebox";
- // Special widths, see usrguide §3.5
+ // Special widths, see usrguide §3.5
// FIXME UNICODE
if (params_.special != "none") {
os << "[" << params_.width.value()
}
+docstring InsetBox::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
+{
+ // construct attributes
+ string attrs = "class='" + params_.type + "'";
+ string style;
+ if (!params_.width.empty())
+ style += ("width: " + params_.width.asHTMLString() + "; ");
+ // The special heights don't really mean anything for us.
+ if (!params_.height.empty() && params_.height_special == "none")
+ style += ("height: " + params_.height.asHTMLString() + "; ");
+ if (!style.empty())
+ attrs += " style='" + style + "'";
+
+ xs << StartTag("div", attrs);
+ XHTMLOptions const opts = InsetText::WriteLabel | InsetText::WriteInnerTag;
+ docstring defer = InsetText::insetAsXHTML(xs, runparams, opts);
+ xs << EndTag("div");
+ xs << defer;
+ return docstring();
+}
+
+
void InsetBox::validate(LaTeXFeatures & features) const
{
BoxType btype = boxtranslator().find(params_.type);
features.require("framed");
break;
}
- InsetText::validate(features);
+ InsetCollapsable::validate(features);
}
void InsetBoxParams::read(Lexer & lex)
{
- if (!lex.isOK())
- return;
-
- lex.next();
- type = lex.getString();
-
- if (!lex)
- return;
-
- lex.next();
- string token;
- token = lex.getString();
- if (!lex)
- return;
- if (token == "position") {
- lex.next();
- // The [0] is needed. We need the first and only char in
- // this string -- MV
- pos = lex.getString()[0];
- } else {
- lyxerr << "InsetBox::Read: Missing 'position'-tag!" << token << endl;
- lex.pushToken(token);
- }
-
- lex.next();
- token = lex.getString();
- if (!lex)
- return;
- if (token == "hor_pos") {
- lex.next();
- hor_pos = lex.getString()[0];
- } else {
- lyxerr << "InsetBox::Read: Missing 'hor_pos'-tag!" << token << endl;
- lex.pushToken(token);
- }
-
- lex.next();
- token = lex.getString();
- if (!lex)
- return;
- if (token == "has_inner_box") {
- lex.next();
- inner_box = lex.getInteger();
- } else {
- lyxerr << "InsetBox::Read: Missing 'has_inner_box'-tag!" << endl;
- lex.pushToken(token);
- }
-
- lex.next();
- token = lex.getString();
- if (!lex)
- return;
- if (token == "inner_pos") {
- lex.next();
- inner_pos = lex.getString()[0];
- } else {
- lyxerr << "InsetBox::Read: Missing 'inner_pos'-tag!"
- << token << endl;
- lex.pushToken(token);
- }
-
- lex.next();
- token = lex.getString();
- if (!lex)
- return;
- if (token == "use_parbox") {
- lex.next();
- use_parbox = lex.getInteger();
- } else {
- lyxerr << "InsetBox::Read: Missing 'use_parbox'-tag!" << endl;
- lex.pushToken(token);
- }
-
- lex.next();
- token = lex.getString();
- if (!lex)
- return;
- if (token == "width") {
- lex.next();
- width = Length(lex.getString());
- } else {
- lyxerr << "InsetBox::Read: Missing 'width'-tag!" << endl;
- lex.pushToken(token);
- }
-
- lex.next();
- token = lex.getString();
- if (!lex)
- return;
- if (token == "special") {
- lex.next();
- special = lex.getString();
- } else {
- lyxerr << "InsetBox::Read: Missing 'special'-tag!" << endl;
- lex.pushToken(token);
- }
-
- lex.next();
- token = lex.getString();
- if (!lex)
- return;
- if (token == "height") {
- lex.next();
- height = Length(lex.getString());
- } else {
- lyxerr << "InsetBox::Read: Missing 'height'-tag!" << endl;
- lex.pushToken(token);
- }
-
- lex.next();
- token = lex.getString();
- if (!lex)
- return;
- if (token == "height_special") {
- lex.next();
- height_special = lex.getString();
- } else {
- lyxerr << "InsetBox::Read: Missing 'height_special'-tag!" << endl;
- lex.pushToken(token);
- }
+ lex.setContext("InsetBoxParams::read");
+ lex >> type;
+ lex >> "position" >> pos;
+ lex >> "hor_pos" >> hor_pos;
+ lex >> "has_inner_box" >> inner_box;
+ if (type == "Framed")
+ inner_box = false;
+ lex >> "inner_pos" >> inner_pos;
+ lex >> "use_parbox" >> use_parbox;
+ lex >> "width" >> width;
+ lex >> "special" >> special;
+ lex >> "height" >> height;
+ lex >> "height_special" >> height_special;
}