#include <config.h>
#include "insetbox.h"
-#include "debug.h"
-#include "BufferView.h"
+#include "cursor.h"
+#include "dispatchresult.h"
+#include "debug.h"
+#include "FuncStatus.h"
#include "funcrequest.h"
#include "gettext.h"
#include "LaTeXFeatures.h"
#include "metricsinfo.h"
#include "paragraph.h"
-#include "support/std_sstream.h"
+#include "support/translator.h"
+
+#include <sstream>
+
+
+namespace lyx {
using std::auto_ptr;
using std::string;
namespace {
-BoxTranslator const init_boxtranslator() {
+typedef Translator<std::string, InsetBox::BoxType> BoxTranslator;
+
+BoxTranslator const init_boxtranslator()
+{
BoxTranslator translator("Boxed", InsetBox::Boxed);
translator.addPair("Frameless", InsetBox::Frameless);
translator.addPair("ovalbox", InsetBox::ovalbox);
}
-BoxTranslator const init_boxtranslator_loc() {
- BoxTranslator 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);
+BoxTranslator 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);
return translator;
}
-BoxTranslator const & boxtranslator() {
+BoxTranslator const & boxtranslator()
+{
static BoxTranslator translator = init_boxtranslator();
return translator;
}
-BoxTranslator const & boxtranslator_loc() {
+BoxTranslator const & boxtranslator_loc()
+{
static BoxTranslator translator = init_boxtranslator_loc();
return translator;
}
void InsetBox::init()
{
- setInsetName("Box");
+ setInsetName(from_ascii("Box"));
setButtonLabel();
}
InsetBox::~InsetBox()
{
- InsetBoxMailer mailer(*this);
- mailer.hideDialog();
+ InsetBoxMailer(*this).hideDialog();
}
-auto_ptr<InsetBase> InsetBox::clone() const
+auto_ptr<InsetBase> InsetBox::doClone() const
{
return auto_ptr<InsetBase>(new InsetBox(*this));
}
-string const InsetBox::editMessage() const
+docstring const InsetBox::editMessage() const
{
return _("Opened Box Inset");
}
font.decSize();
BoxType btype = boxtranslator().find(params_.type);
+
+ docstring label;
+ label += _("Box");
+ label += " (";
if (btype == Frameless) {
if (params_.use_parbox)
- setLabel(_("Parbox"));
+ label += _("Parbox");
else
- setLabel(_("Minipage"));
+ label += _("Minipage");
} else
- setLabel(boxtranslator_loc().find(btype));
+ // FIXME UNICODE
+ label += from_utf8(boxtranslator_loc().find(btype));
+ label += ")";
+
+ setLabel(label);
font.setColor(LColor::foreground);
setBackgroundColor(LColor::background);
}
-void InsetBox::metrics(MetricsInfo & mi, Dimension & dim) const
+void 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);
InsetCollapsable::metrics(mi, dim);
- if (params_.inner_box && isOpen())
- dim.wid = mi.base.textwidth;
dim_ = dim;
}
+bool InsetBox::forceDefaultParagraphs(idx_type) const
+{
+ return !params_.inner_box;
+}
+
+
bool InsetBox::showInsetDialog(BufferView * bv) const
{
InsetBoxMailer(const_cast<InsetBox &>(*this)).showDialog(bv);
}
-dispatch_result InsetBox::localDispatch(FuncRequest const & cmd)
+void InsetBox::doDispatch(LCursor & cur, FuncRequest & cmd)
{
- BufferView * bv = cmd.view();
-
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
- InsetBoxMailer::string2params(cmd.argument, params_);
+ //lyxerr << "InsetBox::dispatch MODIFY" << endl;
+ InsetBoxMailer::string2params(to_utf8(cmd.argument()), params_);
setButtonLabel();
- bv->updateInset(this);
- return DISPATCHED;
+ break;
}
+
case LFUN_INSET_DIALOG_UPDATE:
- InsetBoxMailer(*this).updateDialog(bv);
- return DISPATCHED;
+ InsetBoxMailer(*this).updateDialog(&cur.bv());
+ break;
case LFUN_MOUSE_RELEASE:
if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
- InsetBoxMailer(*this).showDialog(bv);
- return DISPATCHED;
+ InsetBoxMailer(*this).showDialog(&cur.bv());
+ break;
+ }
+ InsetCollapsable::doDispatch(cur, cmd);
+ break;
+
+ default:
+ InsetCollapsable::doDispatch(cur, cmd);
+ break;
+ }
+}
+
+
+bool InsetBox::getStatus(LCursor & cur, FuncRequest const & cmd,
+ FuncStatus & flag) const
+{
+ switch (cmd.action) {
+
+ case LFUN_INSET_MODIFY:
+ case LFUN_INSET_DIALOG_UPDATE:
+ flag.enabled(true);
+ return true;
+ case LFUN_BREAK_PARAGRAPH:
+ if (params_.inner_box) {
+ return InsetCollapsable::getStatus(cur, cmd, flag);
+ } else {
+ flag.enabled(false);
+ return true;
}
- // fallthrough:
default:
- return InsetCollapsable::localDispatch(cmd);
+ return InsetCollapsable::getStatus(cur, cmd, flag);
}
}
-int InsetBox::latex(Buffer const & buf, ostream & os,
- LatexRunParams const & runparams) const
+int InsetBox::latex(Buffer const & buf, odocstream & os,
+ OutputParams const & runparams) const
{
BoxType btype = boxtranslator().find(params_.type);
break;
}
}
-
+
int i = 0;
os << "%\n";
// Adapt to column/text width correctly also if paragraphs indented:
if (stdwidth)
os << "\\noindent";
-
+
switch (btype) {
case Frameless:
break;
if (!params_.inner_box) {
os << "{\\makebox";
// Special widths, see usrguide ยง3.5
+ // FIXME UNICODE
if (params_.special != "none") {
os << "[" << params_.width.value()
- << "\\" << params_.special << "]";
+ << '\\' << from_utf8(params_.special)
+ << ']';
} else
- os << "[" << width_string << "]";
+ os << '[' << from_ascii(width_string)
+ << ']';
if (params_.hor_pos != 'c')
os << "[" << params_.hor_pos << "]";
}
-
+
os << "{";
break;
case ovalbox:
os << "[" << params_.pos << "]";
if (params_.height_special == "none") {
- os << "[" << params_.height.asLatexString() << "]";
+ // FIXME UNICODE
+ os << '[' << from_ascii(params_.height.asLatexString())
+ << ']';
} else {
// Special heights
+ // FIXME UNICODE
os << "[" << params_.height.value()
- << "\\" << params_.height_special << "]";
+ << '\\' << from_utf8(params_.height_special)
+ << ']';
}
if (params_.inner_pos != params_.pos)
os << "[" << params_.inner_pos << "]";
- os << "{" << width_string << "}";
+ // FIXME UNICODE
+ os << '{' << from_ascii(width_string) << '}';
if (params_.use_parbox)
os << "{";
i += 1;
}
- i += inset.latex(buf, os, runparams);
+ i += InsetText::latex(buf, os, runparams);
if (params_.inner_box) {
if (params_.use_parbox)
else
os << "%\n\\end{minipage}";
}
-
+
switch (btype) {
case Frameless:
break;
case Shadowbox:
os << "}";
break;
- }
+ }
os << "%\n";
-
+
i += 3;
return i;
}
-int InsetBox::linuxdoc(Buffer const & buf, std::ostream & os) const
+int InsetBox::docbook(Buffer const & buf, odocstream & os,
+ OutputParams const & runparams) const
{
- return inset.linuxdoc(buf, os);
+ return InsetText::docbook(buf, os, runparams);
}
-int InsetBox::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
+int InsetBox::plaintext(Buffer const & buf, odocstream & os,
+ OutputParams const & runparams) const
{
- return inset.docbook(buf, os, mixcont);
-}
+ BoxType const btype = boxtranslator().find(params_.type);
-
-int InsetBox::ascii(Buffer const & buf, std::ostream & os, int ll) const
-{
- int i = 0;
- string const pt = params_.type;
- BoxType 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 Frameless: break;
+ case Boxed: os << "["; break;
+ case ovalbox: os << "("; break;
+ case Ovalbox: os << "(("; break;
+ case Shadowbox: os << "["; break;
+ case Doublebox: os << "[["; break;
}
- i = inset.ascii(buf, os, ll);
+ int i = InsetText::plaintext(buf, os, runparams);
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: break;
+ case Boxed: os << "]"; break;
+ case ovalbox: os << ")"; break;
+ case Ovalbox: os << "))"; break;
+ case Shadowbox: os << "]/"; break;
+ case Doublebox: os << "]]"; break;
}
return i;
features.require("fancybox");
break;
}
- inset.validate(features);
+ InsetText::validate(features);
}
InsetBoxMailer::InsetBoxMailer(InsetBox & inset)
: inset_(inset)
-{
-}
+{}
string const InsetBoxMailer::name_ = "box";
void InsetBoxMailer::string2params(string const & in,
- InsetBoxParams & params)
+ InsetBoxParams & params)
{
params = InsetBoxParams(string());
-
if (in.empty())
return;
LyXLex lex(0,0);
lex.setStream(data);
- string token;
- lex.next();
- token = lex.getString();
- lex.next();
+ string name;
+ lex >> name;
+ if (!lex || name != name_)
+ return print_mailer_error("InsetBoxMailer", in, 1, name_);
+
+ // This is part of the inset proper that is usually swallowed
+ // by LyXText::readInset
+ string id;
+ lex >> id;
+ if (!lex || id != "Box")
+ return print_mailer_error("InsetBoxMailer", in, 2, "Box");
params.read(lex);
}
void InsetBoxParams::write(ostream & os) const
{
- os << type << "\n";
+ os << "Box " << type << "\n";
os << "position \"" << pos << "\"\n";
os << "hor_pos \"" << hor_pos << "\"\n";
os << "has_inner_box " << inner_box << "\n";
void InsetBoxParams::read(LyXLex & lex)
{
+ if (!lex.isOK())
+ return;
+
if (lex.isOK()) {
+ lex.next();
type = lex.getString();
}
- string token;
if (!lex.isOK())
- return;
+ return;
lex.next();
+ string token;
token = lex.getString();
if (token == "position") {
lex.next();
lex.pushToken(token);
}
if (!lex.isOK())
- return;
+ return;
lex.next();
token = lex.getString();
if (token == "hor_pos") {
lex.pushToken(token);
}
if (!lex.isOK())
- return;
+ return;
lex.next();
token = lex.getString();
if (token == "has_inner_box") {
}
if (!lex.isOK())
- return;
+ return;
lex.next();
token = lex.getString();
if (token == "inner_pos") {
lex.pushToken(token);
}
if (!lex.isOK())
- return;
+ return;
lex.next();
token = lex.getString();
if (token == "use_parbox") {
lex.pushToken(token);
}
if (!lex.isOK())
- return;
+ return;
lex.next();
token = lex.getString();
if (token == "width") {
lex.pushToken(token);
}
if (!lex.isOK())
- return;
+ return;
lex.next();
token = lex.getString();
if (token == "special") {
lex.pushToken(token);
}
if (!lex.isOK())
- return;
+ return;
lex.next();
token = lex.getString();
if (token == "height") {
lex.pushToken(token);
}
if (!lex.isOK())
- return;
+ return;
lex.next();
token = lex.getString();
if (token == "height_special") {
lex.pushToken(token);
}
}
+
+
+} // namespace lyx