]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCharStyle.cpp
Fix text frame drawing.
[lyx.git] / src / insets / InsetCharStyle.cpp
index 5822b50f829f0af7f58cc238f9d14f26942960fe..079d872299e85d07855392320456a3bd208f2d10 100644 (file)
@@ -22,7 +22,6 @@
 #include "FuncStatus.h"
 #include "Cursor.h"
 #include "gettext.h"
-#include "LaTeXFeatures.h"
 #include "Color.h"
 #include "Lexer.h"
 #include "Text.h"
 namespace lyx {
 
 using std::string;
-using std::auto_ptr;
-using std::istringstream;
-using std::max;
 using std::ostream;
-using std::ostringstream;
-
-
-void InsetCharStyle::init()
-{}
 
 
 InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s)
        : InsetCollapsable(bp, Collapsed)
 {
        params_.name = s;
-       setUndefined();
-       init();
 }
 
 
 InsetCharStyle::InsetCharStyle(BufferParams const & bp,
-                               CharStyles::iterator cs)
+                               InsetLayout il)
        : InsetCollapsable(bp, Collapsed)
 {
-       params_.name = cs->name;
-       setDefined(cs);
-       init();
+       params_.name = il.name;
+       setLayout(il);
 }
 
 
 InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
        : InsetCollapsable(in), params_(in.params_)
-{
-       init();
-}
+{}
 
 
-auto_ptr<Inset> InsetCharStyle::doClone() const
+Inset * InsetCharStyle::clone() const
 {
-       return auto_ptr<Inset>(new InsetCharStyle(*this));
+       return new InsetCharStyle(*this);
 }
 
 
 bool InsetCharStyle::undefined() const
 {
-       return layout_.latexname.empty();
+       return layout_.labelstring == from_utf8("UNDEFINED");
 }
 
 
-void InsetCharStyle::setUndefined()
+void InsetCharStyle::setLayout(InsetLayout il)
 {
-       layout_.latextype.clear();
-       layout_.latexname.clear();
-       layout_.latexparam.clear();
-       layout_.font = Font(Font::ALL_INHERIT);
-       layout_.labelfont = Font(Font::ALL_INHERIT);
-       layout_.labelfont.setColor(Color::error);
-}
-
-
-void InsetCharStyle::setDefined(CharStyles::iterator cs)
-{
-       layout_ = *cs;
+       layout_ = il;
 }
 
 
@@ -134,40 +109,8 @@ bool InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
        getDrawFont(mi.base.font);
        mi.base.font.reduce(Font(Font::ALL_SANE));
        mi.base.font.realize(tmpfont);
-       mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
-       InsetText::metrics(mi, dim);
+       bool changed = InsetCollapsable::metrics(mi, dim);
        mi.base.font = tmpfont;
-       if (status() == Open) {
-               // consider width of the inset label
-               Font font(layout_.labelfont);
-               font.realize(Font(Font::ALL_SANE));
-               font.decSize();
-               font.decSize();
-               int w = 0;
-               int a = 0;
-               int d = 0;
-               // FIXME UNICODE
-               docstring s(from_utf8(params_.name));
-               if (undefined())
-                       s = _("Undef: ") + s;
-               // Chop off prefix:
-               if (s.find(':') != string::npos)
-                       s = s.substr(s.find(':'));
-               theFontMetrics(font).rectText(s, w, a, d);
-               dim.wid = max(dim.wid, w);
-       }
-       dim.asc += TEXT_TO_INSET_OFFSET;
-       dim.des += TEXT_TO_INSET_OFFSET;
-       dim.wid += 2 * TEXT_TO_INSET_OFFSET;
-       mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
-       if (status() == Open)
-               dim.des += ascent();
-       else {
-               dim.des -= 3;
-               dim.asc -= 3;
-       }
-       bool const changed =  dim_ != dim;
-       dim_ = dim;
        return changed;
 }
 
@@ -182,52 +125,6 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
        //needed, or even wanted, here. It just works. -- MV 10.04.2005
        InsetCollapsable::draw(pi, x, y);
        pi.base.font = tmpfont;
-
-       int desc = InsetText::descent();
-       if (status() == Open)
-               desc -= ascent();
-       else
-               desc -= 3;
-
-       pi.pain.line(x, y + desc - 4, x, y + desc, layout_.labelfont.color());
-       pi.pain.line(x, y + desc, x + dim_.wid - 3, y + desc,
-               layout_.labelfont.color());
-       pi.pain.line(x + dim_.wid - 3, y + desc, x + dim_.wid - 3, y + desc - 4,
-               layout_.labelfont.color());
-
-       // the name of the charstyle. Can be toggled.
-       if (status() == Open) {
-               Font font(layout_.labelfont);
-               font.realize(Font(Font::ALL_SANE));
-               font.decSize();
-               font.decSize();
-               int w = 0;
-               int a = 0;
-               int d = 0;
-               // FIXME UNICODE
-               docstring s(from_utf8(params_.name));
-               if (undefined())
-                       s = _("Undef: ") + s;
-               // Chop off prefix:
-               if (s.find(':') != string::npos)
-                       s = s.substr(s.find(':'));
-               theFontMetrics(font).rectText(s, w, a, d);
-               pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a,
-                       s, font, Color::none, Color::none);
-       }
-
-       // a visual cue when the cursor is inside the inset
-       Cursor & cur = pi.base.bv->cursor();
-       if (cur.isInside(this)) {
-               y -= ascent();
-               y += 3;
-               pi.pain.line(x, y + 4, x, y, layout_.labelfont.color());
-               pi.pain.line(x + 4, y, x, y, layout_.labelfont.color());
-               pi.pain.line(x + dim_.wid - 3, y + 4, x + dim_.wid - 3, y,
-                       layout_.labelfont.color());
-               pi.pain.line(x + dim_.wid - 7, y, x + dim_.wid - 3, y,
-                       layout_.labelfont.color());
-       }
 }
 
 
@@ -239,37 +136,7 @@ void InsetCharStyle::getDrawFont(Font & font) const
 
 void InsetCharStyle::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       switch (cmd.action) {
-
-       case LFUN_MOUSE_RELEASE:
-                       if (cmd.button() == mouse_button::button3)
-                               if (status() == Open)
-                                       setStatus(cur, Collapsed);
-                               else
-                                       setStatus(cur, Open);
-                       else
-                               InsetCollapsable::doDispatch(cur, cmd);
-                       break;
-
-       case LFUN_INSET_TOGGLE:
-               if (cmd.argument() == "open")
-                       setStatus(cur, Open);
-               else if (cmd.argument() == "close")
-                       setStatus(cur, Collapsed);
-               else if (cmd.argument() == "toggle" || cmd.argument().empty())
-                       if (status() == Open)
-                               setStatus(cur, Collapsed);
-                       else
-                               setStatus(cur, Open);
-               else // if assign or anything else
-                       cur.undispatched();
-               cur.dispatched();
-               break;
-
-       default:
-               InsetCollapsable::doDispatch(cur, cmd);
-               break;
-       }
+       InsetCollapsable::doDispatch(cur, cmd);
 }
 
 
@@ -290,23 +157,6 @@ bool InsetCharStyle::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-int InsetCharStyle::latex(Buffer const & buf, odocstream & os,
-                         OutputParams const & runparams) const
-{
-       if (!undefined()) {
-               // FIXME UNICODE
-               os << '\\' << from_utf8(layout_.latexname);
-               if (!layout_.latexparam.empty())
-                       os << from_utf8(layout_.latexparam);
-               os << '{';
-       }
-       int i = InsetText::latex(buf, os, runparams);
-       if (!undefined())
-               os << "}";
-       return i;
-}
-
-
 int InsetCharStyle::plaintext(Buffer const & buf, odocstream & os,
                              OutputParams const & runparams) const
 {
@@ -345,14 +195,6 @@ void InsetCharStyle::textString(Buffer const & buf, odocstream & os) const
 }
 
 
-void InsetCharStyle::validate(LaTeXFeatures & features) const
-{
-       // Force inclusion of preamble snippet in layout file
-       features.require(params_.name);
-       InsetText::validate(features);
-}
-
-
 void InsetCharStyleParams::write(ostream & os) const
 {
        os << "CharStyle " << name << "\n";