#include "InsetVSpace.h"
#include "Buffer.h"
+#include "BufferView.h"
#include "Cursor.h"
+#include "Dimension.h"
#include "DispatchResult.h"
#include "FuncRequest.h"
-#include "gettext.h"
-#include "Color.h"
+#include "FuncStatus.h"
#include "Lexer.h"
-#include "Text.h"
#include "MetricsInfo.h"
#include "OutputParams.h"
+#include "Text.h"
+#include "support/debug.h"
+#include "support/gettext.h"
+#include "support/lassert.h"
+
+#include "frontends/Application.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include <sstream>
+using namespace std;
namespace lyx {
-using std::istringstream;
-using std::ostream;
-using std::ostringstream;
-using std::string;
-using std::max;
-
-
namespace {
int const ADD_TO_VSPACE_WIDTH = 5;
InsetVSpace::~InsetVSpace()
{
- InsetVSpaceMailer(*this).hideDialog();
-}
-
-
-Inset * InsetVSpace::clone() const
-{
- return new InsetVSpace(*this);
+ hideDialogs("vspace", this);
}
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
- InsetVSpaceMailer::string2params(to_utf8(cmd.argument()), space_);
+ InsetVSpace::string2params(to_utf8(cmd.argument()), space_);
break;
}
case LFUN_MOUSE_RELEASE:
- if (!cur.selection())
- InsetVSpaceMailer(*this).showDialog(&cur.bv());
+ if (!cur.selection() && cmd.button() == mouse_button::button1)
+ cur.bv().showDialog("vspace", params2string(space()),
+ const_cast<InsetVSpace *>(this));
break;
default:
}
-void InsetVSpace::read(Buffer const &, Lexer & lex)
+bool InsetVSpace::getStatus(Cursor & cur, FuncRequest const & cmd,
+ FuncStatus & status) const
+{
+ switch (cmd.action) {
+ // we handle these
+ case LFUN_INSET_MODIFY:
+ if (cmd.getArg(0) == "vspace") {
+ VSpace vspace;
+ InsetVSpace::string2params(to_utf8(cmd.argument()), vspace);
+ status.setOnOff(vspace == space_);
+ }
+ status.setEnabled(true);
+ return true;
+ default:
+ return Inset::getStatus(cur, cmd, status);
+ }
+}
+
+
+void InsetVSpace::edit(Cursor & cur, bool, EntryDirection)
{
- BOOST_ASSERT(lex.isOK());
+ cur.bv().showDialog("vspace", params2string(space()),
+ const_cast<InsetVSpace *>(this));
+}
+
+
+void InsetVSpace::read(Lexer & lex)
+{
+ LASSERT(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'");
+ lex >> "\\end_inset";
}
-void InsetVSpace::write(Buffer const &, ostream & os) const
+void InsetVSpace::write(ostream & os) const
{
os << "VSpace " << space_.asLyXCommand();
}
if (space_.length().len().value() >= 0.0)
height = max(height, space_.inPixels(*mi.base.bv));
- Font font;
+ FontInfo font;
font.decSize();
font.decSize();
int a = 0;
int d = 0;
- Font font;
- font.setColor(Color::added_space);
+ FontInfo font;
+ font.setColor(Color_added_space);
font.decSize();
font.decSize();
docstring const lab = label();
pi.pain.rectText(x + 2 * arrow_size + 5,
start + (end - start) / 2 + (a - d) / 2,
- lab, font, Color::none, Color::none);
+ lab, font, Color_none, Color_none);
// top arrow
- pi.pain.line(x, ty1, midx, ty2, Color::added_space);
- pi.pain.line(midx, ty2, rightx, ty1, Color::added_space);
+ pi.pain.line(x, ty1, midx, ty2, Color_added_space);
+ pi.pain.line(midx, ty2, rightx, ty1, Color_added_space);
// bottom arrow
- pi.pain.line(x, by1, midx, by2, Color::added_space);
- pi.pain.line(midx, by2, rightx, by1, Color::added_space);
+ pi.pain.line(x, by1, midx, by2, Color_added_space);
+ pi.pain.line(midx, by2, rightx, by1, Color_added_space);
// joining line
- pi.pain.line(midx, ty2, midx, by2, Color::added_space);
+ pi.pain.line(midx, ty2, midx, by2, Color_added_space);
}
-int InsetVSpace::latex(Buffer const & buf, odocstream & os,
- OutputParams const &) const
+int InsetVSpace::latex(odocstream & os, OutputParams const &) const
{
- os << from_ascii(space_.asLatexCommand(buf.params())) << '\n';
+ os << from_ascii(space_.asLatexCommand(buffer().params())) << '\n';
return 1;
}
-int InsetVSpace::plaintext(Buffer const &, odocstream & os,
- OutputParams const &) const
+int InsetVSpace::plaintext(odocstream & os, OutputParams const &) const
{
os << "\n\n";
return PLAINTEXT_NEWLINE;
}
-int InsetVSpace::docbook(Buffer const &, odocstream & os,
- OutputParams const &) const
+int InsetVSpace::docbook(odocstream & os, OutputParams const &) const
{
os << '\n';
return 1;
}
-string const InsetVSpaceMailer::name_ = "vspace";
-
-
-InsetVSpaceMailer::InsetVSpaceMailer(InsetVSpace & inset)
- : inset_(inset)
-{}
-
-
-string const InsetVSpaceMailer::inset2string(Buffer const &) const
+docstring InsetVSpace::contextMenu(BufferView const &, int, int) const
{
- return params2string(inset_.space());
+ return from_ascii("context-vspace");
}
-void InsetVSpaceMailer::string2params(string const & in, VSpace & vspace)
+void InsetVSpace::string2params(string const & in, VSpace & vspace)
{
vspace = VSpace();
if (in.empty())
return;
istringstream data(in);
- Lexer lex(0,0);
+ Lexer lex;
lex.setStream(data);
-
- string name;
- lex >> name;
- if (!lex || name != name_)
- return print_mailer_error("InsetVSpaceMailer", in, 1, name_);
-
- string vsp;
- lex >> vsp;
- if (lex)
- vspace = VSpace(vsp);
+ lex.setContext("InsetVSpace::string2params");
+ lex >> "vspace" >> vspace;
}
-string const InsetVSpaceMailer::params2string(VSpace const & vspace)
+string InsetVSpace::params2string(VSpace const & vspace)
{
ostringstream data;
- data << name_ << ' ' << vspace.asLyXCommand();
+ data << "vspace" << ' ' << vspace.asLyXCommand();
return data.str();
}