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