]> git.lyx.org Git - lyx.git/blob - src/mathed/ref_inset.C
IU of drawing phase one without 'semantic changes' as requested by John
[lyx.git] / src / mathed / ref_inset.C
1
2 #include <config.h>
3
4 #include "ref_inset.h"
5 #include "math_factory.h"
6
7 #include "BufferView.h"
8 #include "debug.h"
9 #include "funcrequest.h"
10 #include "math_support.h"
11 #include "gettext.h"
12 #include "LaTeXFeatures.h"
13
14 #include "frontends/LyXView.h"
15 #include "frontends/Dialogs.h"
16
17 #include "support/LOstream.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 dispatch_result
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                                 // Eventually trigger dialog with button 3
54                                 // not 1
55                                 string const data = createDialogStr("ref");
56                                 cmd.view()->owner()->getDialogs().
57                                         show("ref", data, this);
58                                 return DISPATCHED;
59                         }
60                         break;
61                 case LFUN_MOUSE_PRESS:
62                 case LFUN_MOUSE_MOTION:
63                         // eat other mouse commands
64                         return DISPATCHED;
65                 default:
66                         return CommandInset::dispatch(cmd, idx, pos);
67         }
68         // not our business
69         return UNDISPATCHED;
70 }
71
72
73 string RefInset::screenLabel() const
74 {
75         string str;
76         for (int i = 0; !types[i].latex_name.empty(); ++i)
77                 if (name_ == types[i].latex_name) {
78                         str = _(types[i].short_gui_name);
79                         break;
80                 }
81         str += asString(cell(0));
82
83         //if (/* !isLatex && */ !cell(0).empty()) {
84         //      str += "||";
85         //      str += asString(cell(1));
86         //}
87         return str;
88 }
89
90
91 void RefInset::validate(LaTeXFeatures & features) const
92 {
93         if (name_ == "vref" || name_ == "vpageref")
94                 features.require("varioref");
95         else if (name_ == "prettyref")
96                 features.require("prettyref");
97 }
98
99
100 int RefInset::ascii(std::ostream & os, int) const
101 {
102         os << '[' << asString(cell(0)) << ']';
103         return 0;
104 }
105
106
107 int RefInset::linuxdoc(std::ostream & os) const
108 {
109         os << "<ref id=\"" << asString(cell(0))
110            << "\" name=\"" << asString(cell(1)) << "\" >";
111         return 0;
112 }
113
114
115 int RefInset::docbook(std::ostream & os, bool) const
116 {
117         if (cell(1).empty()) {
118                 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
119         } else {
120                 os << "<link linkend=\"" << asString(cell(0))
121                    << "\">" << asString(cell(1)) << "</link>";
122         }
123
124         return 0;
125 }
126
127
128 dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
129 {
130         if (cmd.action != LFUN_INSET_MODIFY || cmd.getArg(0) != "ref")
131                 return UNDISPATCHED;
132
133         MathArray ar;
134         if (!createMathInset_fromDialogStr(cmd.argument, ar))
135                 return UNDISPATCHED;
136
137         *this = *ar[0].nucleus()->asRefInset();
138 //      if (cmd.view())
139 //                 // This does not compile because updateInset expects
140 //                 // an Inset* and 'this' isn't.
141 //              cmd.view()->updateInset(this);
142         return DISPATCHED;
143 }
144
145
146 RefInset::ref_type_info RefInset::types[] = {
147         { "ref",       N_("Standard"),              N_("Ref: ")},
148         { "eqref",     N_("Equation"),              N_("EqRef: ")},
149         { "pageref",   N_("Page Number"),           N_("Page: ")},
150         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
151         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
152         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
153         { "", "", "" }
154 };