]> git.lyx.org Git - lyx.git/blob - src/mathed/ref_inset.C
Hold on to your hats.
[lyx.git] / src / mathed / ref_inset.C
1
2 #include <config.h>
3
4 #include "ref_inset.h"
5 #include "funcrequest.h"
6 #include "formulabase.h"
7 #include "BufferView.h"
8 #include "frontends/LyXView.h"
9 #include "frontends/Painter.h"
10 #include "frontends/Dialogs.h"
11 #include "lyxfunc.h"
12 #include "gettext.h"
13 #include "LaTeXFeatures.h"
14 #include "debug.h"
15 #include "math_mathmlstream.h"
16 #include "Lsstream.h"
17
18
19 RefInset::RefInset()
20         : CommandInset("ref")
21 {}
22
23
24 RefInset::RefInset(string const & data)
25         : CommandInset(data)
26 {}
27
28
29 MathInset * RefInset::clone() const
30 {
31         return new RefInset(*this);
32 }
33
34
35 void RefInset::infoize(std::ostream & os) const
36 {
37         os << "Ref: " << cell(0);
38 }
39
40
41 dispatch_result
42 RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
43 {
44         lyxerr << "RefInset::dispatch" << std::endl;
45         lyxerr << "dispatching " << cmd.argument << "\n";
46         switch (cmd.action) {
47                 case LFUN_MOUSE_RELEASE:
48                         if (cmd.button() == mouse_button::button3) {
49                                 lyxerr << "trying to goto ref" << cell(0) << "\n";
50                                 cmd.view()->dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
51                                 return DISPATCHED;
52                         }
53                         if (cmd.button() == mouse_button::button1) {
54                                 lyxerr << "trying to open ref" << cell(0) << "\n";
55                                 // Eventually trigger dialog with button 3
56                                 // not 1
57                                 ostringstream data;
58                                 WriteStream wsdata(data);
59                                 write(wsdata);
60
61                                 lyxerr << "ref_inset dispatch.\n"
62                                        << "this " << this << "\n"
63                                        << "The data is "<< data.str()
64                                        << std::endl;
65
66                                 cmd.view()->owner()->getDialogs().
67                                         show("ref", data.str(), this);
68                                 return DISPATCHED;
69                         }
70                         break;
71                 case LFUN_MOUSE_PRESS:
72                 case LFUN_MOUSE_MOTION:
73                         // eat other mouse commands
74                         return DISPATCHED;
75                 default:
76                         return CommandInset::dispatch(cmd, idx, pos);
77         }
78         // not our business
79         return UNDISPATCHED;
80 }
81
82
83 string RefInset::screenLabel() const
84 {
85         string str;
86         for (int i = 0; !types[i].latex_name.empty(); ++i)
87                 if (name_ == types[i].latex_name) {
88                         str = _(types[i].short_gui_name);
89                         break;
90                 }
91         str += asString(cell(0));
92
93         //if (/* !isLatex && */ !cell(0).empty()) {
94         //      str += "||";
95         //      str += asString(cell(1));
96         //}
97         return str;
98 }
99
100
101 void RefInset::validate(LaTeXFeatures & features) const
102 {
103         if (name_ == "vref" || name_ == "vpageref")
104                 features.require("varioref");
105         else if (name_ == "prettyref")
106                 features.require("prettyref");
107 }
108
109
110 int RefInset::ascii(std::ostream & os, int) const
111 {
112         os << '[' << asString(cell(0)) << ']';
113         return 0;
114 }
115
116
117 int RefInset::linuxdoc(std::ostream & os) const
118 {
119         os << "<ref id=\"" << asString(cell(0))
120            << "\" name=\"" << asString(cell(1)) << "\" >";
121         return 0;
122 }
123
124
125 int RefInset::docbook(std::ostream & os, bool) const
126 {
127         if (cell(1).empty()) {
128                 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
129         } else {
130                 os << "<link linkend=\"" << asString(cell(0))
131                    << "\">" << asString(cell(1)) << "</link>";
132         }
133
134         return 0;
135 }
136
137
138 RefInset::ref_type_info RefInset::types[] = {
139         { "ref",        N_("Standard"),                 N_("Ref: ")},
140         { "pageref",    N_("Page Number"),              N_("Page: ")},
141         { "vpageref",   N_("Textual Page Number"),      N_("TextPage: ")},
142         { "vref",       N_("Standard+Textual Page"),    N_("Ref+Text: ")},
143         { "prettyref",  N_("PrettyRef"),                N_("PrettyRef: ")},
144         { "", "", "" }
145 };