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