]> git.lyx.org Git - lyx.git/blob - src/mathed/ref_inset.C
* LyXView: the accessor methods now return a reference to the member
[lyx.git] / src / mathed / ref_inset.C
1 #include <config.h>
2
3 #include "ref_inset.h"
4 #include "math_cursor.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 int 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                                 mathcursor->formula()->view()->owner()->getLyXFunc().
46                                         dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
47                                 return 1; // dispatched
48                         }
49                         if (cmd.extra == 1) {
50                                 lyxerr << "trying to open ref" << cell(0) << "\n";
51                                 // Eventually trigger dialog with button 3 not 1
52                 //              mathcursor->formula()->view()->owner()->getDialogs()
53                 //                      ->showRef(this);
54                                 return 1; // dispatched
55                         }
56                         break;
57                 case LFUN_MOUSE_PRESS:  
58                 case LFUN_MOUSE_MOTION:
59                         // eat other mouse commands
60                         return 1;
61                 default:
62                         break;
63         }
64         // not our business
65         return 0;
66 }
67
68
69 string RefInset::screenLabel() const
70 {
71         string str;
72         for (int i = 0; !types[i].latex_name.empty(); ++i)
73                 if (name_ == types[i].latex_name) {
74                         str = _(types[i].short_gui_name);
75                         break;
76                 }
77         str += asString(cell(0));
78
79         //if (/* !isLatex && */ !cell(0).empty()) {
80         //      str += "||";
81         //      str += asString(cell(1));
82         //}
83         return str;
84 }
85
86
87 void RefInset::validate(LaTeXFeatures & features) const
88 {
89         if (name_ == "vref" || name_ == "vpageref")
90                 features.require("varioref");
91         else if (name_ == "prettyref")
92                 features.require("prettyref");
93 }
94
95
96 int RefInset::ascii(std::ostream & os, int) const
97 {
98         os << "[" << asString(cell(0)) << "]";
99         return 0;
100 }
101
102
103 int RefInset::linuxdoc(std::ostream & os) const
104 {
105         os << "<ref id=\"" << asString(cell(0))
106            << "\" name=\"" << asString(cell(1)) << "\" >";
107         return 0;
108 }
109
110
111 int RefInset::docbook(std::ostream & os, bool) const
112 {
113         if (cell(1).empty()) {
114                 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
115         } else {
116                 os << "<link linkend=\"" << asString(cell(0))
117                    << "\">" << asString(cell(1)) << "</link>";
118         }
119
120         return 0;
121 }
122
123
124 RefInset::type_info RefInset::types[] = {
125         { "ref",        N_("Standard"),                 N_("Ref: ")},
126         { "pageref",    N_("Page Number"),              N_("Page: ")},
127         { "vpageref",   N_("Textual Page Number"),      N_("TextPage: ")},
128         { "vref",       N_("Standard+Textual Page"),    N_("Ref+Text: ")},
129         { "prettyref",  N_("PrettyRef"),                N_("PrettyRef: ")},
130         { "", "", "" }
131 };