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