-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2000 The LyX Team.
+/**
+ * \file insetlabel.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * ====================================================== */
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "insetlabel.h"
+#include "buffer.h"
+#include "BufferView.h"
+#include "dispatchresult.h"
+#include "funcrequest.h"
+#include "InsetList.h"
+#include "lyxtext.h"
+#include "paragraph.h"
+#include "pariterator.h"
+#include "sgml.h"
+
+#include "support/lstrings.h"
+#include "support/lyxalgo.h"
+#include "support/std_ostream.h"
+
+
+namespace lyx {
+
+using support::escape;
+
+using std::string;
using std::ostream;
+using std::vector;
+
-/* Label. Used to insert a label automatically */
+InsetLabel::InsetLabel(InsetCommandParams const & p)
+ : InsetCommand(p, "label")
+{}
-InsetLabel::InsetLabel(string const & cmd)
+std::auto_ptr<InsetBase> InsetLabel::doClone() const
{
- scanCommand(cmd);
+ return std::auto_ptr<InsetBase>(new InsetLabel(params()));
}
-Inset * InsetLabel::Clone() const
+void InsetLabel::getLabelList(Buffer const &, std::vector<docstring> & list) const
{
- return new InsetLabel(getCommand());
+ list.push_back(getParam("name"));
}
-int InsetLabel::GetNumberOfLabels() const
+docstring const InsetLabel::getScreenLabel(Buffer const &) const
{
- return 1;
+ return getParam("name");
}
-string InsetLabel::getLabel(int) const
+void InsetLabel::doDispatch(LCursor & cur, FuncRequest & cmd)
{
- return contents;
+ switch (cmd.action) {
+
+ case LFUN_INSET_MODIFY: {
+ InsetCommandParams p("label");
+ // FIXME UNICODE
+ InsetCommandMailer::string2params("label", to_utf8(cmd.argument()), p);
+ if (p.getCmdName().empty()) {
+ cur.noUpdate();
+ break;
+ }
+ if (p["name"] != params()["name"])
+ cur.bv().buffer()->changeRefsIfUnique(params()["name"],
+ p["name"], InsetBase::REF_CODE);
+ setParams(p);
+ break;
+ }
+
+ default:
+ InsetCommand::doDispatch(cur, cmd);
+ break;
+ }
}
-int InsetLabel::Latex(ostream & os,
- signed char /*fragile*/, bool /*fs*/) const
+int InsetLabel::latex(Buffer const &, odocstream & os,
+ OutputParams const &) const
{
os << escape(getCommand());
return 0;
}
-int InsetLabel::Linuxdoc(ostream & os) const
+int InsetLabel::plaintext(Buffer const &, odocstream & os,
+ OutputParams const &) const
{
- os << "<label id=\"" << getContents() << "\" >";
+ os << '<' << getParam("name") << '>';
return 0;
}
-int InsetLabel::DocBook(ostream & os) const
+int InsetLabel::docbook(Buffer const & buf, odocstream & os,
+ OutputParams const & runparams) const
{
- os << "<anchor id=\"" << getContents() << "\" >";
+ os << "<!-- anchor id=\""
+ << sgml::cleanID(buf, runparams, getParam("name"))
+ << "\" -->";
return 0;
}
-// This function escapes 8-bit characters and other problematic characters
-// It's exactly the same code as in insetref.C.
-string InsetLabel::escape(string const & lab) const {
- char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
- string enc;
- for (string::size_type i= 0; i < lab.length(); ++i) {
- unsigned char c = lab[i];
- if (c >= 128 || c == '=' || c == '%') {
- enc += '=';
- enc += hexdigit[c >> 4];
- enc += hexdigit[c & 15];
- } else {
- enc += c;
- }
- }
- return enc;
-}
+} // namespace lyx