]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
Convert labels to unicode
[lyx.git] / src / insets / insetlabel.C
1 /**
2  * \file insetlabel.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "insetlabel.h"
14
15 #include "buffer.h"
16 #include "BufferView.h"
17 #include "dispatchresult.h"
18 #include "funcrequest.h"
19 #include "InsetList.h"
20 #include "lyxtext.h"
21 #include "paragraph.h"
22 #include "pariterator.h"
23 #include "sgml.h"
24
25 #include "support/lstrings.h"
26 #include "support/lyxalgo.h"
27 #include "support/std_ostream.h"
28
29 using lyx::docstring;
30 using lyx::support::escape;
31
32 using std::string;
33 using std::ostream;
34 using std::vector;
35
36
37 InsetLabel::InsetLabel(InsetCommandParams const & p)
38         : InsetCommand(p, "label")
39 {}
40
41
42 std::auto_ptr<InsetBase> InsetLabel::doClone() const
43 {
44         return std::auto_ptr<InsetBase>(new InsetLabel(params()));
45 }
46
47
48 void InsetLabel::getLabelList(Buffer const &, std::vector<docstring> & list) const
49 {
50         // FIXME UNICODE
51         list.push_back(lyx::from_utf8(getContents()));
52 }
53
54
55 docstring const InsetLabel::getScreenLabel(Buffer const &) const
56 {
57         // FIXME UNICODE
58         return lyx::from_utf8(getContents());
59 }
60
61
62 void InsetLabel::doDispatch(LCursor & cur, FuncRequest & cmd)
63 {
64         switch (cmd.action) {
65
66         case LFUN_INSET_MODIFY: {
67                 InsetCommandParams p;
68                 InsetCommandMailer::string2params("label", lyx::to_utf8(cmd.argument()), p);
69                 if (p.getCmdName().empty()) {
70                         cur.noUpdate();
71                         break;
72                 }
73                 if (p.getContents() != params().getContents())
74                         cur.bv().buffer()->changeRefsIfUnique(params().getContents(),
75                                                        p.getContents(), InsetBase::REF_CODE);
76                 setParams(p);
77                 break;
78         }
79
80         default:
81                 InsetCommand::doDispatch(cur, cmd);
82                 break;
83         }
84 }
85
86
87 int InsetLabel::latex(Buffer const &, ostream & os,
88                       OutputParams const &) const
89 {
90         os << escape(getCommand());
91         return 0;
92 }
93
94
95 int InsetLabel::plaintext(Buffer const &, lyx::odocstream & os,
96                       OutputParams const &) const
97 {
98         // FIXME UNICODE
99         os << '<' << lyx::from_utf8(getContents()) << '>';
100         return 0;
101 }
102
103
104 int InsetLabel::docbook(Buffer const & buf, ostream & os,
105                         OutputParams const & runparams) const
106 {
107         os << "<!-- anchor id=\"" << sgml::cleanID(buf, runparams, getContents()) << "\" -->";
108         return 0;
109 }