]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetArgument.cpp
Allow for some argument visual customization
[features.git] / src / insets / InsetArgument.cpp
index de239e157e6dd6257acd2615e954877041010e40..b113878f062e9c60eee7c65702ac86daa6fedc5b 100644 (file)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Martin Vermeer
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -18,6 +19,7 @@
 #include "InsetList.h"
 #include "Layout.h"
 #include "Lexer.h"
+#include "OutputParams.h"
 #include "ParIterator.h"
 
 #include "support/convert.h"
@@ -32,7 +34,8 @@ namespace lyx {
 
 
 InsetArgument::InsetArgument(Buffer * buf, string const & name)
-    : InsetCollapsable(buf), name_(name), labelstring_(docstring())
+    : InsetCollapsable(buf), name_(name), labelstring_(docstring()),
+      font_(inherit_font), labelfont_(inherit_font), decoration_(string())
 {}
 
 
@@ -59,12 +62,12 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype)
 
        // Handle pre 2.1 ArgInsets (lyx2lyx cannot classify them)
        if (name_ == "999") {
-               int req = insetlayout ? it.inset().getLayout().requiredArgs()
+               unsigned int const req = insetlayout ? it.inset().getLayout().numRequiredArgs()
                                      : it.paragraph().layout().requiredArgs();
-               int opts = insetlayout ? it.inset().getLayout().optArgs()
+               unsigned int const opts = insetlayout ? it.inset().getLayout().numOptArgs()
                                      : it.paragraph().layout().optArgs();
-               int nr = 0;
-               int ours = 0;
+               unsigned int nr = 0;
+               unsigned int ours = 0;
                InsetList::const_iterator parit = it.paragraph().insetList().begin();
                InsetList::const_iterator parend = it.paragraph().insetList().end();
                for (; parit != parend; ++parit) {
@@ -75,7 +78,7 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype)
                        }
                }
                bool done = false;
-               int realopts = 0;
+               unsigned int realopts = 0;
                if (nr > req) {
                        // We have optional arguments
                        realopts = nr - req;
@@ -95,8 +98,14 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype)
        Layout::LaTeXArgMap::const_iterator const lait =
                        args.find(convert<unsigned int>(name_));
        if (lait != args.end()) {
-               labelstring_ = translateIfPossible((*lait).second.labelstring);
+               docstring label = translateIfPossible((*lait).second.labelstring);
+               docstring striplabel;
+               support::rsplit(label, striplabel, '|');
+               labelstring_ = striplabel.empty() ? label: striplabel;
                tooltip_ = translateIfPossible((*lait).second.tooltip);
+               font_ = (*lait).second.font;
+               labelfont_ = (*lait).second.labelfont;
+               decoration_ = (*lait).second.decoration;
        } else {
                labelstring_ = _("Unknown Argument");
                tooltip_ = _("Argument not known in this Layout. Will be supressed in the output.");
@@ -197,13 +206,53 @@ string InsetArgument::contextMenuName() const
        return "context-argument";
 }
 
+FontInfo InsetArgument::getFont() const
+{
+       if (font_ != inherit_font)
+               return font_;
+       return getLayout().font();
+}
+
+FontInfo InsetArgument::getLabelfont() const
+{
+       if (labelfont_ != inherit_font)
+               return labelfont_;
+       return getLayout().labelfont();
+}
+
+namespace {
+
+InsetLayout::InsetDecoration translateDecoration(std::string const & str) 
+{
+       if (support::compare_ascii_no_case(str, "classic") == 0)
+               return InsetLayout::CLASSIC;
+       if (support::compare_ascii_no_case(str, "minimalistic") == 0)
+               return InsetLayout::MINIMALISTIC;
+       if (support::compare_ascii_no_case(str, "conglomerate") == 0)
+               return InsetLayout::CONGLOMERATE;
+       return InsetLayout::DEFAULT;
+}
+
+}// namespace anon
+
+InsetLayout::InsetDecoration InsetArgument::decoration() const
+{
+       InsetLayout::InsetDecoration dec = getLayout().decoration();
+       if (!decoration_.empty())
+               dec = translateDecoration(decoration_);
+       return dec == InsetLayout::DEFAULT ? InsetLayout::CLASSIC : dec;
+}
+
 void InsetArgument::latexArgument(otexstream & os,
-               OutputParams const & runparams, docstring const & ldelim,
+               OutputParams const & runparams_in, docstring const & ldelim,
                docstring const & rdelim) const
 {
        TexRow texrow;
        odocstringstream ss;
        otexstream ots(ss, texrow);
+       OutputParams runparams = runparams_in;
+       if (getLayout().isPassThru())
+               runparams.pass_thru = true;
        InsetText::latex(ots, runparams);
        docstring str = ss.str();
        if (ldelim != "{" && support::contains(str, rdelim))