]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathRef.C
Fix comment according to Enricos explanation
[lyx.git] / src / mathed / InsetMathRef.C
1 /**
2  * \file InsetMathRef.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathRef.h"
14
15 #include "BufferView.h"
16 #include "LaTeXFeatures.h"
17 #include "buffer.h"
18 #include "cursor.h"
19 #include "debug.h"
20 #include "funcrequest.h"
21 #include "FuncStatus.h"
22 #include "gettext.h"
23 #include "MathData.h"
24 #include "MathFactory.h"
25 #include "MathSupport.h"
26 #include "outputparams.h"
27 #include "sgml.h"
28
29
30 namespace lyx {
31
32 using std::string;
33 using std::auto_ptr;
34 using std::endl;
35
36
37 RefInset::RefInset()
38         : CommandInset(from_ascii("ref"))
39 {}
40
41
42 RefInset::RefInset(docstring const & data)
43         : CommandInset(data)
44 {}
45
46
47 auto_ptr<InsetBase> RefInset::doClone() const
48 {
49         return auto_ptr<InsetBase>(new RefInset(*this));
50 }
51
52
53 void RefInset::infoize(odocstream & os) const
54 {
55         os << "Ref: " << cell(0);
56 }
57
58
59 void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd)
60 {
61         switch (cmd.action) {
62         case LFUN_INSET_MODIFY:
63                 if (cmd.getArg(0) == "ref") {
64                         MathArray ar;
65                         if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
66                                 *this = *ar[0].nucleus()->asRefInset();
67                                 break;
68                         }
69                 }
70                 cur.undispatched();
71                 break;
72
73         case LFUN_INSET_DIALOG_UPDATE: {
74                 string const data = createDialogStr("ref");
75                 cur.bv().updateDialog("ref", data);
76                 break;
77         }
78
79         case LFUN_MOUSE_RELEASE:
80                 if (cmd.button() == mouse_button::button3) {
81                         lyxerr << "trying to goto ref '" << to_utf8(asString(cell(0))) << "'" << endl;
82                         cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
83                         break;
84                 }
85                 if (cmd.button() == mouse_button::button1) {
86                         // Eventually trigger dialog with button 3, not 1
87                         string const data = createDialogStr("ref");
88                         cur.bv().showInsetDialog("ref", data, this);
89                         break;
90                 }
91                 cur.undispatched();
92                 break;
93
94         case LFUN_MOUSE_PRESS:
95         case LFUN_MOUSE_MOTION:
96                 // eat other mouse commands
97                 break;
98
99         default:
100                 CommandInset::doDispatch(cur, cmd);
101                 break;
102         }
103 }
104
105
106 bool RefInset::getStatus(LCursor & cur, FuncRequest const & cmd,
107                          FuncStatus & status) const
108 {
109         switch (cmd.action) {
110         // we handle these
111         case LFUN_INSET_MODIFY:
112         case LFUN_INSET_DIALOG_UPDATE:
113         case LFUN_MOUSE_RELEASE:
114         case LFUN_MOUSE_PRESS:
115         case LFUN_MOUSE_MOTION:
116                 status.enabled(true);
117                 return true;
118         default:
119                 return CommandInset::getStatus(cur, cmd, status);
120         }
121 }
122
123
124 docstring const RefInset::screenLabel() const
125 {
126         docstring str;
127         for (int i = 0; !types[i].latex_name.empty(); ++i) {
128                 if (commandname() == types[i].latex_name) {
129                         str = _(to_utf8(types[i].short_gui_name));
130                         break;
131                 }
132         }
133         str += asString(cell(0));
134
135         //if (/* !isLatex && */ !cell(0).empty()) {
136         //      str += "||";
137         //      str += asString(cell(1));
138         //}
139         return str;
140 }
141
142
143 void RefInset::validate(LaTeXFeatures & features) const
144 {
145         if (commandname() == "vref" || commandname() == "vpageref")
146                 features.require("varioref");
147         else if (commandname() == "prettyref")
148                 features.require("prettyref");
149 }
150
151
152 int RefInset::plaintext(odocstream & os, OutputParams const &) const
153 {
154         // FIXME UNICODE
155         os << '[' << asString(cell(0)) << ']';
156         return 0;
157 }
158
159
160 int RefInset::docbook(Buffer const & buf, odocstream & os,
161                 OutputParams const & runparams) const
162 {
163         if (cell(1).empty()) {
164                 os << "<xref linkend=\""
165                    << sgml::cleanID(buf, runparams, asString(cell(0)));
166                 if (runparams.flavor == OutputParams::XML)
167                         os << "\"/>";
168                 else
169                         os << "\">";
170         } else {
171                 os << "<link linkend=\""
172                    << sgml::cleanID(buf, runparams, asString(cell(0)))
173                    << "\">"
174                    << asString(cell(1))
175                    << "</link>";
176         }
177
178         return 0;
179 }
180
181
182 RefInset::ref_type_info RefInset::types[] = {
183         { from_ascii("ref"),       from_ascii(N_("Standard")),              from_ascii(N_("Ref: "))},
184         { from_ascii("eqref"),     from_ascii(N_("Equation")),              from_ascii(N_("EqRef: "))},
185         { from_ascii("pageref"),   from_ascii(N_("Page Number")),           from_ascii(N_("Page: "))},
186         { from_ascii("vpageref"),  from_ascii(N_("Textual Page Number")),   from_ascii(N_("TextPage: "))},
187         { from_ascii("vref"),      from_ascii(N_("Standard+Textual Page")), from_ascii(N_("Ref+Text: "))},
188         { from_ascii("prettyref"), from_ascii(N_("PrettyRef")),             from_ascii(N_("PrettyRef: "))},
189         { from_ascii(""), from_ascii(""), from_ascii("") }
190 };
191
192
193 } // namespace lyx