]> git.lyx.org Git - lyx.git/blob - src/mathed/ref_inset.C
First shot at inset-unification mathed & rest of the world
[lyx.git] / src / mathed / ref_inset.C
1
2 #include "ref_inset.h"
3 #include "math_cursor.h"
4 #include "commandtags.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
14 RefInset::RefInset()
15         : CommandInset("ref")
16 {}
17
18
19 RefInset::RefInset(string const & data)
20         : CommandInset(data)
21 {}
22
23
24 MathInset * RefInset::clone() const
25 {
26         return new RefInset(*this);
27 }
28
29
30 void RefInset::infoize(std::ostream & os) const
31 {
32         os << "Ref: " << cell(0);
33 }
34
35
36 int RefInset::dispatch(string const & cmd, idx_type, pos_type) 
37 {
38         if (cmd == "mouse 3") {
39                 cerr << "trying to goto ref" << cell(0) << "\n";
40                 mathcursor->formula()->view()->owner()->getLyXFunc()->
41                         dispatch(LFUN_REF_GOTO, asString(cell(0)));
42                 return 1; // dispatched
43         }
44         
45         if (cmd == "mouse 1") {
46                 cerr << "trying to open ref" << cell(0) << "\n";
47                 // Eventually trigger dialog with button 3 not 1
48 //              mathcursor->formula()->view()->owner()->getDialogs()
49 //                      ->showRef(this);
50                 return 1; // dispatched
51         }
52
53         return 0; // undispatched
54 }
55
56
57 string RefInset::screenLabel() const
58 {
59         string str;
60         for (int i = 0; !types[i].latex_name.empty(); ++i)
61                 if (name_ == types[i].latex_name) {
62                         str = _(types[i].short_gui_name);
63                         break;
64                 }
65         str += asString(cell(0));
66
67         //if (/* !isLatex && */ !cell(0).empty()) {
68         //      str += "||";
69         //      str += asString(cell(1));
70         //}
71         return str;
72 }
73
74
75 void RefInset::validate(LaTeXFeatures & features) const
76 {
77         if (name_ == "vref" || name_ == "vpageref")
78                 features.require("varioref");
79         else if (name_ == "prettyref")
80                 features.require("prettyref");
81 }
82
83
84 int RefInset::ascii(std::ostream & os, int) const
85 {
86         os << "[" << asString(cell(0)) << "]";
87         return 0;
88 }
89
90
91 int RefInset::linuxdoc(std::ostream & os) const
92 {
93         os << "<ref id=\"" << asString(cell(0))
94            << "\" name=\"" << asString(cell(1)) << "\" >";
95         return 0;
96 }
97
98
99 int RefInset::docbook(std::ostream & os, bool) const
100 {
101         if (cell(1).empty()) {
102                 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
103         } else {
104                 os << "<link linkend=\"" << asString(cell(0))
105                    << "\">" << asString(cell(1)) << "</link>";
106         }
107
108         return 0;
109 }
110
111 RefInset::type_info RefInset::types[] = {
112         { "ref",        N_("Standard"),                 N_("Ref: ")},
113         { "pageref",    N_("Page Number"),              N_("Page: ")},
114         { "vpageref",   N_("Textual Page Number"),      N_("TextPage: ")},
115         { "vref",       N_("Standard+Textual Page"),    N_("Ref+Text: ")},
116         { "prettyref",  N_("PrettyRef"),                N_("PrettyRef: ")},
117         { "", "", "" }
118 };