]> git.lyx.org Git - lyx.git/blob - src/mathed/ref_inset.C
The std::string mammoth path.
[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 #include "math_data.h"
15 #include "math_factory.h"
16
17 #include "BufferView.h"
18 #include "debug.h"
19 #include "funcrequest.h"
20 #include "math_support.h"
21 #include "gettext.h"
22 #include "LaTeXFeatures.h"
23
24 #include "frontends/LyXView.h"
25 #include "frontends/Dialogs.h"
26
27
28 using std::string;
29 using std::auto_ptr;
30 using std::endl;
31
32
33 RefInset::RefInset()
34         : CommandInset("ref")
35 {}
36
37
38 RefInset::RefInset(string const & data)
39         : CommandInset(data)
40 {}
41
42
43 auto_ptr<InsetBase> RefInset::clone() const
44 {
45         return auto_ptr<InsetBase>(new RefInset(*this));
46 }
47
48
49 void RefInset::infoize(std::ostream & os) const
50 {
51         os << "Ref: " << cell(0);
52 }
53
54
55 dispatch_result
56 RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
57 {
58         switch (cmd.action) {
59                 case LFUN_MOUSE_RELEASE:
60                         if (cmd.button() == mouse_button::button3) {
61                                 lyxerr << "trying to goto ref" << cell(0) << endl;
62                                 cmd.view()->dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
63                                 return DISPATCHED;
64                         }
65                         if (cmd.button() == mouse_button::button1) {
66                                 // Eventually trigger dialog with button 3
67                                 // not 1
68                                 string const data = createDialogStr("ref");
69                                 cmd.view()->owner()->getDialogs().
70                                         show("ref", data, this);
71                                 return DISPATCHED;
72                         }
73                         break;
74                 case LFUN_MOUSE_PRESS:
75                 case LFUN_MOUSE_MOTION:
76                         // eat other mouse commands
77                         return DISPATCHED;
78                 default:
79                         return CommandInset::dispatch(cmd, idx, pos);
80         }
81         // not our business
82         return UNDISPATCHED;
83 }
84
85
86 string const RefInset::screenLabel() const
87 {
88         string str;
89         for (int i = 0; !types[i].latex_name.empty(); ++i)
90                 if (commandname() == types[i].latex_name) {
91                         str = _(types[i].short_gui_name);
92                         break;
93                 }
94         str += asString(cell(0));
95
96         //if (/* !isLatex && */ !cell(0).empty()) {
97         //      str += "||";
98         //      str += asString(cell(1));
99         //}
100         return str;
101 }
102
103
104 void RefInset::validate(LaTeXFeatures & features) const
105 {
106         if (commandname() == "vref" || commandname() == "vpageref")
107                 features.require("varioref");
108         else if (commandname() == "prettyref")
109                 features.require("prettyref");
110 }
111
112
113 int RefInset::ascii(std::ostream & os, int) const
114 {
115         os << '[' << asString(cell(0)) << ']';
116         return 0;
117 }
118
119
120 int RefInset::linuxdoc(std::ostream & os) const
121 {
122         os << "<ref id=\"" << asString(cell(0))
123            << "\" name=\"" << asString(cell(1)) << "\" >";
124         return 0;
125 }
126
127
128 int RefInset::docbook(std::ostream & os, bool) const
129 {
130         if (cell(1).empty()) {
131                 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
132         } else {
133                 os << "<link linkend=\"" << asString(cell(0))
134                    << "\">" << asString(cell(1)) << "</link>";
135         }
136
137         return 0;
138 }
139
140
141 dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
142 {
143         if (cmd.action != LFUN_INSET_MODIFY || cmd.getArg(0) != "ref")
144                 return UNDISPATCHED;
145
146         MathArray ar;
147         if (!createMathInset_fromDialogStr(cmd.argument, ar))
148                 return UNDISPATCHED;
149
150         *this = *ar[0].nucleus()->asRefInset();
151 //      if (cmd.view())
152 //                 // This does not compile because updateInset expects
153 //                 // an Inset* and 'this' isn't.
154 //              cmd.view()->updateInset(this);
155         return DISPATCHED;
156 }
157
158
159 RefInset::ref_type_info RefInset::types[] = {
160         { "ref",       N_("Standard"),              N_("Ref: ")},
161         { "eqref",     N_("Equation"),              N_("EqRef: ")},
162         { "pageref",   N_("Page Number"),           N_("Page: ")},
163         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
164         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
165         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
166         { "", "", "" }
167 };