]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetlabel.C
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[lyx.git] / src / insets / insetlabel.C
index 8e0e8c8f13dfa850742b5426ad1c88b32337118f..3d995c3ea0085da9053c82672d54dbf8df5de48e 100644 (file)
-/* This file is part of
- * ======================================================
- * 
- *           LyX, The Document Processor
- *      
- *         Copyright (C) 1995 Matthias Ettrich
- *          Copyright (C) 1995-1998 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"
 
-//     $Id: insetlabel.C,v 1.1 1999/09/27 18:44:39 larsbj Exp $        
+#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"
 
-#if !defined(lint) && !defined(WITH_WARNINGS)
-static char vcid[] = "$Id: insetlabel.C,v 1.1 1999/09/27 18:44:39 larsbj Exp $";
-#endif /* lint */
+#include "support/lstrings.h"
+#include "support/lyxalgo.h"
+#include "support/std_ostream.h"
 
-/* Label. Used to insert a label automatically */
 
+namespace lyx {
 
-InsetLabel::InsetLabel(LString const & cmd)
-{
-       scanCommand(cmd);
-}
+using support::escape;
 
+using std::string;
+using std::ostream;
+using std::vector;
 
-InsetLabel::~InsetLabel()
-{
-}
 
+InsetLabel::InsetLabel(InsetCommandParams const & p)
+       : InsetCommand(p, "label")
+{}
 
-Inset* InsetLabel::Clone()
+
+std::auto_ptr<InsetBase> InsetLabel::doClone() const
 {
-       InsetLabel *result = new InsetLabel(getCommand());
-       return result;
+       return std::auto_ptr<InsetBase>(new InsetLabel(params()));
 }
 
 
-int InsetLabel::GetNumberOfLabels() const
+void InsetLabel::getLabelList(Buffer const &, std::vector<docstring> & list) const
 {
-       return 1;
+       list.push_back(getParam("name"));
 }
 
 
-LString InsetLabel::getLabel(int) const
+docstring const InsetLabel::getScreenLabel(Buffer const &) const
 {
-       return contents;
+       return getParam("name");
 }
 
-int InsetLabel::Latex(FILE *file, signed char /*fragile*/)
+
+void InsetLabel::doDispatch(LCursor & cur, FuncRequest & cmd)
 {
-       fprintf(file, "%s", escape(getCommand()).c_str());
-       return 0;
+       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(LString &file, signed char /*fragile*/)
+int InsetLabel::latex(Buffer const &, odocstream & os,
+                     OutputParams const &) const
 {
-       file += escape(getCommand());
+       os << escape(getCommand());
        return 0;
 }
 
 
-int InsetLabel::Linuxdoc(LString &file)
+int InsetLabel::plaintext(Buffer const &, odocstream & os,
+                     OutputParams const &) const
 {
-       file += "<label id=\"" + getContents() +"\" >";
+       os << '<' << getParam("name") << '>';
        return 0;
 }
 
 
-int InsetLabel::DocBook(LString &file)
+int InsetLabel::docbook(Buffer const & buf, odocstream & os,
+                       OutputParams const & runparams) const
 {
-       file += "<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.
-LString InsetLabel::escape(LString const & lab) const {
-       char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
-                             '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
-       LString enc;
-       for (int 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 += (char) c;
-               }
-       }
-       return enc;
-}
+} // namespace lyx