]> git.lyx.org Git - lyx.git/blob - src/mathed/ref_inset.C
Make Helge happy: no more crash on arrow up/down in math macro
[lyx.git] / src / mathed / ref_inset.C
1 /**
2  * \file ref_inset.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 "ref_inset.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 "gettext.h"
22 #include "math_data.h"
23 #include "math_factory.h"
24 #include "math_support.h"
25 #include "outputparams.h"
26 #include "sgml.h"
27
28 #include "frontends/LyXView.h"
29 #include "frontends/Dialogs.h"
30
31 using std::string;
32 using std::auto_ptr;
33 using std::endl;
34
35
36
37 RefInset::RefInset()
38         : CommandInset("ref")
39 {}
40
41
42 RefInset::RefInset(string 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(std::ostream & 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 (createMathInset_fromDialogStr(cmd.argument, ar)) {
66                                 *this = *ar[0].nucleus()->asRefInset();
67                                 break;
68                         }
69                 }
70                 cur.undispatched();
71                 break;
72
73         case LFUN_MOUSE_RELEASE:
74                 if (cmd.button() == mouse_button::button3) {
75                         lyxerr << "trying to goto ref '" << asString(cell(0)) << "'" << endl;
76                         cur.bv().dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
77                         break;
78                 }
79                 if (cmd.button() == mouse_button::button1) {
80                         // Eventually trigger dialog with button 3, not 1
81                         string const data = createDialogStr("ref");
82                         cur.bv().owner()->getDialogs().show("ref", data, this);
83                         break;
84                 }
85                 cur.undispatched();
86                 break;
87
88         case LFUN_MOUSE_PRESS:
89         case LFUN_MOUSE_MOTION:
90                 // eat other mouse commands
91                 break;
92
93         default:
94                 CommandInset::doDispatch(cur, cmd);
95                 break;
96         }
97 }
98
99
100 string const RefInset::screenLabel() const
101 {
102         string str;
103         for (int i = 0; !types[i].latex_name.empty(); ++i)
104                 if (commandname() == types[i].latex_name) {
105                         str = _(types[i].short_gui_name);
106                         break;
107                 }
108         str += asString(cell(0));
109
110         //if (/* !isLatex && */ !cell(0).empty()) {
111         //      str += "||";
112         //      str += asString(cell(1));
113         //}
114         return str;
115 }
116
117
118 void RefInset::validate(LaTeXFeatures & features) const
119 {
120         if (commandname() == "vref" || commandname() == "vpageref")
121                 features.require("varioref");
122         else if (commandname() == "prettyref")
123                 features.require("prettyref");
124 }
125
126
127 int RefInset::plaintext(std::ostream & os, OutputParams const &) const
128 {
129         os << '[' << asString(cell(0)) << ']';
130         return 0;
131 }
132
133
134 int RefInset::linuxdoc(std::ostream & os, OutputParams const &) const
135 {
136         os << "<ref id=\"" << asString(cell(0))
137            << "\" name=\"" << asString(cell(1)) << "\">";
138         return 0;
139 }
140
141
142 int RefInset::docbook(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const
143 {
144         if (cell(1).empty()) {
145                 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)));
146                 if (runparams.flavor == OutputParams::XML)
147                         os << "\"/>";
148                 else
149                         os << "\">";
150         } else {
151                 os << "<link linkend=\"" << sgml::cleanID(buf, runparams, asString(cell(0)))
152                    << "\">" << asString(cell(1)) << "</link>";
153         }
154
155         return 0;
156 }
157
158
159
160
161 RefInset::ref_type_info RefInset::types[] = {
162         { "ref",       N_("Standard"),              N_("Ref: ")},
163         { "eqref",     N_("Equation"),              N_("EqRef: ")},
164         { "pageref",   N_("Page Number"),           N_("Page: ")},
165         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
166         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
167         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
168         { "", "", "" }
169 };