]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathRef.C
cleanup after svn hang-up, #undef CursorShape. Should be compilable ganin now.
[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 #include "frontends/LyXView.h"
30 #include "frontends/Dialogs.h"
31
32 using std::string;
33 using std::auto_ptr;
34 using std::endl;
35
36
37
38 RefInset::RefInset()
39         : CommandInset("ref")
40 {}
41
42
43 RefInset::RefInset(string const & data)
44         : CommandInset(data)
45 {}
46
47
48 auto_ptr<InsetBase> RefInset::doClone() const
49 {
50         return auto_ptr<InsetBase>(new RefInset(*this));
51 }
52
53
54 void RefInset::infoize(std::ostream & os) const
55 {
56         os << "Ref: " << cell(0);
57 }
58
59
60 void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd)
61 {
62         switch (cmd.action) {
63         case LFUN_INSET_MODIFY:
64                 if (cmd.getArg(0) == "ref") {
65                         MathArray ar;
66                         if (createInsetMath_fromDialogStr(lyx::to_utf8(cmd.argument()), ar)) {
67                                 *this = *ar[0].nucleus()->asRefInset();
68                                 break;
69                         }
70                 }
71                 cur.undispatched();
72                 break;
73
74         case LFUN_INSET_DIALOG_UPDATE: {
75                 string const data = createDialogStr("ref");
76                 if (cur.bv().owner()->getDialogs().visible("ref"))
77                         cur.bv().owner()->getDialogs().update("ref", data);
78                 break;
79         }
80
81         case LFUN_MOUSE_RELEASE:
82                 if (cmd.button() == mouse_button::button3) {
83                         lyxerr << "trying to goto ref '" << asString(cell(0)) << "'" << endl;
84                         cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
85                         break;
86                 }
87                 if (cmd.button() == mouse_button::button1) {
88                         // Eventually trigger dialog with button 3, not 1
89                         string const data = createDialogStr("ref");
90                         cur.bv().owner()->getDialogs().show("ref", data, this);
91                         break;
92                 }
93                 cur.undispatched();
94                 break;
95
96         case LFUN_MOUSE_PRESS:
97         case LFUN_MOUSE_MOTION:
98                 // eat other mouse commands
99                 break;
100
101         default:
102                 CommandInset::doDispatch(cur, cmd);
103                 break;
104         }
105 }
106
107
108 bool RefInset::getStatus(LCursor & cur, FuncRequest const & cmd,
109                          FuncStatus & status) const
110 {
111         switch (cmd.action) {
112         // we handle these
113         case LFUN_INSET_MODIFY:
114         case LFUN_INSET_DIALOG_UPDATE:
115         case LFUN_MOUSE_RELEASE:
116         case LFUN_MOUSE_PRESS:
117         case LFUN_MOUSE_MOTION:
118                 status.enabled(true);
119                 return true;
120         default:
121                 return CommandInset::getStatus(cur, cmd, status);
122         }
123 }
124
125
126 string const RefInset::screenLabel() const
127 {
128         string str;
129         for (int i = 0; !types[i].latex_name.empty(); ++i)
130                 if (commandname() == types[i].latex_name) {
131                         // FIXME UNICODE
132                         str = lyx::to_utf8(_(types[i].short_gui_name));
133                         break;
134                 }
135         str += asString(cell(0));
136
137         //if (/* !isLatex && */ !cell(0).empty()) {
138         //      str += "||";
139         //      str += asString(cell(1));
140         //}
141         return str;
142 }
143
144
145 void RefInset::validate(LaTeXFeatures & features) const
146 {
147         if (commandname() == "vref" || commandname() == "vpageref")
148                 features.require("varioref");
149         else if (commandname() == "prettyref")
150                 features.require("prettyref");
151 }
152
153
154 int RefInset::plaintext(std::ostream & os, OutputParams const &) const
155 {
156         os << '[' << asString(cell(0)) << ']';
157         return 0;
158 }
159
160
161 int RefInset::docbook(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const
162 {
163         if (cell(1).empty()) {
164                 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)));
165                 if (runparams.flavor == OutputParams::XML)
166                         os << "\"/>";
167                 else
168                         os << "\">";
169         } else {
170                 os << "<link linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)))
171                    << "\">" << asString(cell(1)) << "</link>";
172         }
173
174         return 0;
175 }
176
177
178 RefInset::ref_type_info RefInset::types[] = {
179         { "ref",       N_("Standard"),              N_("Ref: ")},
180         { "eqref",     N_("Equation"),              N_("EqRef: ")},
181         { "pageref",   N_("Page Number"),           N_("Page: ")},
182         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
183         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
184         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
185         { "", "", "" }
186 };