>>>>> "Jean-Marc" == Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes: Jean-Marc> I'd be interested to know how I could have made it shorter, Jean-Marc> and whether it is right. I have to say I do not like it Jean-Marc> much :)
OK, now that I have tried it, I see I forgot to handle draw() too. This leads me to some code refactoring, and the result looks nice (provided we have some support functions for _() and bformat). And, yes, it works. But I do not propose to apply it until we know where we are heading. JMarc
Index: src/mathed/math_macrotemplate.C =================================================================== --- src/mathed/math_macrotemplate.C (revision 14715) +++ src/mathed/math_macrotemplate.C (working copy) @@ -21,6 +21,9 @@ #include "lyxlex.h" #include "LColor.h" +#include "support/docstring.h" +#include "support/unicode.h" + #include "frontends/Painter.h" #include "frontends/font_metrics.h" @@ -33,7 +36,7 @@ using std::string; using std::auto_ptr; using std::ostream; using std::endl; - +using std::vector; MathMacroTemplate::MathMacroTemplate() : MathNestInset(2), numargs_(0), name_(), type_("newcommand") @@ -102,9 +105,16 @@ string MathMacroTemplate::name() const } -string MathMacroTemplate::prefix() const +namespace { +docstring macroprefix(string const & name) { - return bformat(_(" Macro: %1$s: "), name_); + string pref = bformat(_(" Macro: %1$s: "), name); + vector<char> utf8pref(pref.begin(), pref.end()); + vector<uint32_t> ucs4pref = + utf8_to_ucs4(vector<char>(utf8pref.begin(), + utf8pref.end())); + return docstring(ucs4pref.begin(), ucs4pref.end()); +} } @@ -112,9 +122,8 @@ void MathMacroTemplate::metrics(MetricsI { cell(0).metrics(mi); cell(1).metrics(mi); - docstring dp(prefix().begin(), prefix().end()); dim.wid = cell(0).width() + cell(1).width() + 20 - + font_metrics::width(dp, mi.base.font); + + font_metrics::width(macroprefix(name()), mi.base.font); dim.asc = std::max(cell(0).ascent(), cell(1).ascent()) + 7; dim.des = std::max(cell(0).descent(), cell(1).descent()) + 7; dim_ = dim; @@ -150,7 +159,7 @@ void MathMacroTemplate::draw(PainterInfo if (cur.isInside(this)) cur.drawSelection(pi); #endif - docstring dp(prefix().begin(), prefix().end()); + docstring dp = macroprefix(name()); pi.pain.text(x + 2, y, dp, font); x += font_metrics::width(dp, pi.base.font) + 6;