]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetBox.cpp
Remove all BufferParam arguments in InsetXXX methods (since insets know about their...
[lyx.git] / src / insets / InsetBox.cpp
index 25911bc985f4f0b0612c1a0b4b8a0cc56e818652..1300533feeac126c4655aa4e7b249c4e864b31e7 100644 (file)
@@ -5,7 +5,7 @@
  *
  * \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 "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"
@@ -35,6 +37,7 @@
 #include <sstream>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
@@ -95,10 +98,7 @@ BoxTranslatorLoc const & boxtranslator_loc()
 
 InsetBox::InsetBox(Buffer const & buffer, string const & label)
        : InsetCollapsable(buffer), params_(label)
-{
-       if (forceEmptyLayout())
-               paragraphs().back().setLayout(buffer.params().documentClass().emptyLayout());
-}
+{}
 
 
 InsetBox::~InsetBox()
@@ -139,21 +139,34 @@ void InsetBox::read(Lexer & lex)
 
 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);
 }
 
@@ -176,7 +189,7 @@ void InsetBox::metrics(MetricsInfo & m, Dimension & dim) const
 }
 
 
-bool InsetBox::forceEmptyLayout(idx_type) const
+bool InsetBox::forcePlainLayout(idx_type) const
 {
        return !params_.inner_box && params_.type != "Framed";
 }
@@ -200,7 +213,7 @@ void InsetBox::doDispatch(Cursor & cur, FuncRequest & cmd)
                        params_.type = cmd.getArg(1);
                else
                        string2params(to_utf8(cmd.argument()), params_);
-               setLayout(cur.buffer().params());
+               setLayout();
                break;
        }
 
@@ -293,7 +306,7 @@ int InsetBox::latex(odocstream & os, OutputParams const & runparams) const
                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()
@@ -472,6 +485,27 @@ int InsetBox::docbook(odocstream & os, OutputParams const & runparams) const
 }
 
 
+docstring InsetBox::xhtml(odocstream &, OutputParams const & runparams) const
+{
+       string style;
+       if (!params_.width.empty())
+               style += ("width: " + params_.width.asHTMLString() + ";");
+       if (!params_.height.empty())
+               style += ("height: " + params_.height.asHTMLString() + ";");
+       
+       docstring retval = from_ascii("<div class='" + params_.type + "'");
+       if (!style.empty())
+               retval += from_ascii(" style='" + style + "'");
+       retval += ">\n";
+       odocstringstream os;
+       docstring defer = InsetText::xhtml(os, runparams);
+       retval += os.str();
+       retval += "</div>\n";
+       retval += defer + "\n";
+       return retval;
+}
+
+
 void InsetBox::validate(LaTeXFeatures & features) const
 {
        BoxType btype = boxtranslator().find(params_.type);
@@ -496,7 +530,7 @@ void InsetBox::validate(LaTeXFeatures & features) const
                features.require("framed");
                break;
        }
-       InsetText::validate(features);
+       InsetCollapsable::validate(features);
 }