]> git.lyx.org Git - lyx.git/blob - src/insets/insetlabel.C
The speed patch: redraw only rows that have changed
[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 "frontends/LyXView.h"
26
27 #include "support/lstrings.h"
28 #include "support/lyxalgo.h"
29 #include "support/std_ostream.h"
30
31 using lyx::support::escape;
32
33 using std::string;
34 using std::ostream;
35 using std::vector;
36
37
38 InsetLabel::InsetLabel(InsetCommandParams const & p)
39         : InsetCommand(p, "label")
40 {}
41
42
43 std::auto_ptr<InsetBase> InsetLabel::doClone() const
44 {
45         return std::auto_ptr<InsetBase>(new InsetLabel(params()));
46 }
47
48
49 void InsetLabel::getLabelList(Buffer const &, std::vector<string> & list) const
50 {
51         list.push_back(getContents());
52 }
53
54
55 string const InsetLabel::getScreenLabel(Buffer const &) const
56 {
57         return getContents();
58 }
59
60
61 void InsetLabel::doDispatch(LCursor & cur, FuncRequest & cmd)
62 {
63         switch (cmd.action) {
64
65         case LFUN_INSET_MODIFY: {
66                 InsetCommandParams p;
67                 InsetCommandMailer::string2params("label", cmd.argument, p);
68                 if (p.getCmdName().empty()) {
69                         cur.noUpdate();
70                         break;
71                 }
72                 if (p.getContents() != params().getContents())
73                         cur.bv().buffer()->changeRefsIfUnique(params().getContents(),
74                                                        p.getContents());
75                 setParams(p);
76                 break;
77         }
78
79         default:
80                 InsetCommand::doDispatch(cur, cmd);
81                 break;
82         }
83 }
84
85
86 int InsetLabel::latex(Buffer const &, ostream & os,
87                       OutputParams const &) const
88 {
89         os << escape(getCommand());
90         return 0;
91 }
92
93
94 int InsetLabel::plaintext(Buffer const &, ostream & os,
95                       OutputParams const &) const
96 {
97         os << '<' << getContents()  << '>';
98         return 0;
99 }
100
101
102 int InsetLabel::linuxdoc(Buffer const & buf, ostream & os,
103                          OutputParams const & runparams) const
104 {
105         os << "<label id=\"" << sgml::cleanID(buf, runparams, getContents()) << "\" >";
106         return 0;
107 }
108
109
110 int InsetLabel::docbook(Buffer const & buf, ostream & os,
111                         OutputParams const & runparams) const
112 {
113         os << "<!-- anchor id=\"" << sgml::cleanID(buf, runparams, getContents()) << "\" -->";
114         return 0;
115 }