]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetvspace.C
insetcharstyle drawing cosmetics
[lyx.git] / src / insets / insetvspace.C
index 91b747c68de152eb7e18c7b6f92324ce0ec602ed..5946dd70e26f6cf58b4dfe07fe9ba0091fba01c9 100644 (file)
 #include "insetvspace.h"
 
 #include "buffer.h"
-#include "debug.h"
+#include "BufferView.h"
+#include "cursor.h"
+#include "dispatchresult.h"
+#include "funcrequest.h"
+#include "gettext.h"
 #include "LColor.h"
 #include "lyxlex.h"
 #include "lyxtext.h"
 #include "metricsinfo.h"
-#include "gettext.h"
 
-#include "frontends/Painter.h"
 #include "frontends/font_metrics.h"
+#include "frontends/Painter.h"
 
-#include "support/std_sstream.h"
+#include <sstream>
 
-using std::endl;
 using std::istringstream;
 using std::ostream;
 using std::ostringstream;
@@ -34,27 +36,66 @@ using std::string;
 using std::max;
 
 
+namespace {
+
+int const ADD_TO_VSPACE_WIDTH = 5;
+
+} // namespace anon
+
 
 InsetVSpace::InsetVSpace(VSpace const & space)
        : space_(space)
 {}
 
 
+InsetVSpace::~InsetVSpace()
+{
+       InsetVSpaceMailer(*this).hideDialog();
+}
+
+
 std::auto_ptr<InsetBase> InsetVSpace::clone() const
 {
        return std::auto_ptr<InsetBase>(new InsetVSpace(*this));
 }
 
 
-void InsetVSpace::read(Buffer const &, LyXLex & lex)
+void InsetVSpace::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
-       if (lex.isOK()) {
-               lex.next();
-               space_ = VSpace(lex.getString());
+       switch (cmd.action) {
+
+       case LFUN_INSET_MODIFY: {
+               InsetVSpaceMailer::string2params(cmd.argument, space_);
+               break;
+       }
+
+       case LFUN_MOUSE_PRESS:
+               InsetVSpaceMailer(*this).showDialog(&cur.bv());
+               break;
+
+       default:
+               InsetOld::priv_dispatch(cur, cmd);
+               break;
        }
 }
 
 
+void InsetVSpace::read(Buffer const &, LyXLex & lex)
+{
+       BOOST_ASSERT(lex.isOK());
+       string vsp;
+       lex >> vsp;
+       if (lex)
+               space_ = VSpace(vsp);
+
+       string end_token;
+       lex >> end_token;
+       if (end_token != "\\end_inset")
+               lex.printError("Missing \\end_inset at this point. "
+                              "Read: `$$Token'");
+}
+
+
 void InsetVSpace::write(Buffer const &, ostream & os) const
 {
        os << "VSpace " << space_.asLyXCommand();
@@ -64,23 +105,21 @@ void InsetVSpace::write(Buffer const &, ostream & os) const
 void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        int size = 10;
-       if (space_.kind() != VSpace::NONE) {
-               int const arrow_size = 4;
-               int const space_size = space_.inPixels(*mi.base.bv);
-
-               LyXFont font;
-               font.decSize();
-               int const min_size = max(3 * arrow_size, font_metrics::maxHeight(font));
-
-               if (space_.length().len().value() < 0.0)
-                       size = min_size;
-               else
-                       size = max(min_size, space_size);
-       }
+       int const arrow_size = 4;
+       int const space_size = space_.inPixels(*mi.base.bv);
+
+       LyXFont font;
+       font.decSize();
+       int const min_size = max(3 * arrow_size, font_metrics::maxHeight(font));
+
+       if (space_.length().len().value() < 0.0)
+               size = min_size;
+       else
+               size = max(min_size, space_size);
 
        dim.asc = size / 2;
        dim.des = size / 2;
-       dim.wid = 10;
+       dim.wid = 10 + 2 * ADD_TO_VSPACE_WIDTH;
 
        dim_ = dim;
 }
@@ -90,11 +129,9 @@ void InsetVSpace::draw(PainterInfo & pi, int x, int y) const
 {
        static std::string const label = _("Vertical Space");
 
-       xo_ = x;
-       yo_ = y;
+       setPosCache(pi, x, y);
 
-       //if (space_.kind() == VSpace::NONE)
-       //      return 0;
+       x += ADD_TO_VSPACE_WIDTH;
 
        int const arrow_size = 4;
        int const start = y - dim_.asc;
@@ -122,7 +159,7 @@ void InsetVSpace::draw(PainterInfo & pi, int x, int y) const
                by2 = added ? end : (end - arrow_size);
        }
 
-       int const midx = xo_ + arrow_size;
+       int const midx = x + arrow_size;
        int const rightx = midx + arrow_size;
 
        // first the string
@@ -194,16 +231,13 @@ InsetVSpaceMailer::InsetVSpaceMailer(InsetVSpace & inset)
 
 string const InsetVSpaceMailer::inset2string(Buffer const &) const
 {
-       return params2string(inset_.space_);
+       return params2string(inset_.space());
 }
 
 
 void InsetVSpaceMailer::string2params(string const & in, VSpace & vspace)
 {
-       //lyxerr << "\nInsetVSpaceMailer::string2params, got: '" << in << "'" << endl;
-
        vspace = VSpace();
-
        if (in.empty())
                return;
 
@@ -211,17 +245,15 @@ void InsetVSpaceMailer::string2params(string const & in, VSpace & vspace)
        LyXLex lex(0,0);
        lex.setStream(data);
 
-       if (lex.isOK()) {
-               lex.next();
-               string const name = lex.getString();
-       }
+       string name;
+       lex >> name;
+       if (!lex || name != name_)
+               return print_mailer_error("InsetVSpaceMailer", in, 1, name_);
 
-       // This is part of the inset proper that is usually swallowed
-       // by Buffer::readInset
-       if (lex.isOK()) {
-               lex.next();
-               vspace = VSpace(lex.getString());
-       }
+       string vsp;
+       lex >> vsp;
+       if (lex)
+               vspace = VSpace(vsp);
 }