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