#include "insetbox.h"
+#include "BufferView.h"
#include "cursor.h"
#include "dispatchresult.h"
#include "debug.h"
#include "lyxlex.h"
#include "metricsinfo.h"
#include "paragraph.h"
+#include "TextMetrics.h"
#include "support/translator.h"
namespace {
typedef Translator<std::string, InsetBox::BoxType> BoxTranslator;
+typedef Translator<docstring, InsetBox::BoxType> BoxTranslatorLoc;
BoxTranslator const init_boxtranslator()
{
}
-BoxTranslator const init_boxtranslator_loc()
+BoxTranslatorLoc const init_boxtranslator_loc()
{
- // FIXME UNICODE
- BoxTranslator translator(to_utf8(_("Boxed")), InsetBox::Boxed);
- translator.addPair(to_utf8(_("Frameless")), InsetBox::Frameless);
- translator.addPair(to_utf8(_("ovalbox")), InsetBox::ovalbox);
- translator.addPair(to_utf8(_("Ovalbox")), InsetBox::Ovalbox);
- translator.addPair(to_utf8(_("Shadowbox")), InsetBox::Shadowbox);
- translator.addPair(to_utf8(_("Doublebox")), InsetBox::Doublebox);
+ BoxTranslatorLoc translator(_("Boxed"), InsetBox::Boxed);
+ translator.addPair(_("Frameless"), InsetBox::Frameless);
+ translator.addPair(_("ovalbox"), InsetBox::ovalbox);
+ translator.addPair(_("Ovalbox"), InsetBox::Ovalbox);
+ translator.addPair(_("Shadowbox"), InsetBox::Shadowbox);
+ translator.addPair(_("Doublebox"), InsetBox::Doublebox);
return translator;
}
}
-BoxTranslator const & boxtranslator_loc()
+BoxTranslatorLoc const & boxtranslator_loc()
{
- static BoxTranslator translator = init_boxtranslator_loc();
+ static BoxTranslatorLoc translator = init_boxtranslator_loc();
return translator;
}
else
label += _("Minipage");
} else
- // FIXME UNICODE
- label += from_utf8(boxtranslator_loc().find(btype));
+ label += boxtranslator_loc().find(btype);
label += ")";
setLabel(label);
}
-void InsetBox::metrics(MetricsInfo & m, Dimension & dim) const
+bool InsetBox::hasFixedWidth() const
+{
+ return params_.inner_box || params_.special != "width";
+}
+
+
+bool InsetBox::metrics(MetricsInfo & m, Dimension & dim) const
{
MetricsInfo mi = m;
- if (params_.inner_box || params_.special != "width")
- mi.base.textwidth = params_.width.inPixels(m.base.textwidth);
+ // first round in order to know the minimum size.
+ InsetCollapsable::metrics(mi, dim);
+ TextMetrics & tm = mi.base.bv->textMetrics(&text_);
+ if (hasFixedWidth())
+ mi.base.textwidth =
+ std::max(tm.width() + 2 * border_ + (int) (2.5 * TEXT_TO_INSET_OFFSET),
+ params_.width.inPixels(m.base.textwidth));
InsetCollapsable::metrics(mi, dim);
+ bool const changed = dim_ != dim;
dim_ = dim;
+ return changed;
}
int InsetBox::latex(Buffer const & buf, odocstream & os,
- OutputParams const & runparams) const
+ OutputParams const & runparams) const
{
BoxType btype = boxtranslator().find(params_.type);
}
-int InsetBox::docbook(Buffer const & buf, odocstream & os,
- OutputParams const & runparams) const
-{
- return InsetText::docbook(buf, os, runparams);
-}
-
-
int InsetBox::plaintext(Buffer const & buf, odocstream & os,
- OutputParams const & runparams) const
+ OutputParams const & runparams) const
{
BoxType const btype = boxtranslator().find(params_.type);
switch (btype) {
case Frameless: break;
- case Boxed: os << "["; break;
- case ovalbox: os << "("; break;
- case Ovalbox: os << "(("; break;
- case Shadowbox: os << "["; break;
- case Doublebox: os << "[["; break;
+ case Boxed: os << "[\n"; break;
+ case ovalbox: os << "(\n"; break;
+ case Ovalbox: os << "((\n"; break;
+ case Shadowbox: os << "[/\n"; break;
+ case Doublebox: os << "[[\n"; break;
}
- int i = InsetText::plaintext(buf, os, runparams);
+ InsetText::plaintext(buf, os, runparams);
+ int len = 0;
switch (btype) {
- case Frameless: break;
- case Boxed: os << "]"; break;
- case ovalbox: os << ")"; break;
- case Ovalbox: os << "))"; break;
- case Shadowbox: os << "]/"; break;
- case Doublebox: os << "]]"; break;
+ case Frameless: os << "\n"; break;
+ case Boxed: os << "\n]"; len = 1; break;
+ case ovalbox: os << "\n)"; len = 1; break;
+ case Ovalbox: os << "\n))"; len = 2; break;
+ case Shadowbox: os << "\n/]"; len = 2; break;
+ case Doublebox: os << "\n]]"; len = 2; break;
}
- return i;
+ return PLAINTEXT_NEWLINE + len; // len chars on a separate line
+}
+
+
+int InsetBox::docbook(Buffer const & buf, odocstream & os,
+ OutputParams const & runparams) const
+{
+ return InsetText::docbook(buf, os, runparams);
}
void InsetBox::validate(LaTeXFeatures & features) const
{
- features.require("calc");
BoxType btype = boxtranslator().find(params_.type);
switch (btype) {
case Frameless:
+ break;
case Boxed:
+ features.require("calc");
break;
case ovalbox:
case Ovalbox:
case Shadowbox:
case Doublebox:
+ features.require("calc");
features.require("fancybox");
break;
}
if (!lex.isOK())
return;
- if (lex.isOK()) {
- lex.next();
- type = lex.getString();
- }
- if (!lex.isOK())
+ 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
lyxerr << "InsetBox::Read: Missing 'position'-tag!" << token << endl;
lex.pushToken(token);
}
- if (!lex.isOK())
- return;
+
lex.next();
token = lex.getString();
+ if (!lex)
+ return;
if (token == "hor_pos") {
lex.next();
hor_pos = lex.getString()[0];
lyxerr << "InsetBox::Read: Missing 'hor_pos'-tag!" << token << endl;
lex.pushToken(token);
}
- if (!lex.isOK())
- return;
+
lex.next();
token = lex.getString();
+ if (!lex)
+ return;
if (token == "has_inner_box") {
lex.next();
inner_box = lex.getInteger();
lex.pushToken(token);
}
- if (!lex.isOK())
- return;
lex.next();
token = lex.getString();
+ if (!lex)
+ return;
if (token == "inner_pos") {
lex.next();
inner_pos = lex.getString()[0];
<< token << endl;
lex.pushToken(token);
}
- if (!lex.isOK())
- return;
+
lex.next();
token = lex.getString();
+ if (!lex)
+ return;
if (token == "use_parbox") {
lex.next();
use_parbox = lex.getInteger();
lyxerr << "InsetBox::Read: Missing 'use_parbox'-tag!" << endl;
lex.pushToken(token);
}
- if (!lex.isOK())
- return;
+
lex.next();
token = lex.getString();
+ if (!lex)
+ return;
if (token == "width") {
lex.next();
width = LyXLength(lex.getString());
lyxerr << "InsetBox::Read: Missing 'width'-tag!" << endl;
lex.pushToken(token);
}
- if (!lex.isOK())
- return;
+
lex.next();
token = lex.getString();
+ if (!lex)
+ return;
if (token == "special") {
lex.next();
special = lex.getString();
lyxerr << "InsetBox::Read: Missing 'special'-tag!" << endl;
lex.pushToken(token);
}
- if (!lex.isOK())
- return;
+
lex.next();
token = lex.getString();
+ if (!lex)
+ return;
if (token == "height") {
lex.next();
height = LyXLength(lex.getString());
lyxerr << "InsetBox::Read: Missing 'height'-tag!" << endl;
lex.pushToken(token);
}
- if (!lex.isOK())
- return;
+
lex.next();
token = lex.getString();
+ if (!lex)
+ return;
if (token == "height_special") {
lex.next();
height_special = lex.getString();