]> git.lyx.org Git - lyx.git/blob - src/mathed/ref_inset.C
split LyXText::rowlist_ into individual Paragraph::rows_ chunks
[lyx.git] / src / mathed / ref_inset.C
1 #include <config.h>
2
3 #include "ref_inset.h"
4 #include "math_factory.h"
5
6 #include "BufferView.h"
7 #include "debug.h"
8 #include "funcrequest.h"
9 #include "math_support.h"
10 #include "gettext.h"
11 #include "LaTeXFeatures.h"
12
13 #include "frontends/LyXView.h"
14 #include "frontends/Dialogs.h"
15
16 #include "support/LOstream.h"
17
18 using std::auto_ptr;
19 using std::endl;
20
21
22 RefInset::RefInset()
23         : CommandInset("ref")
24 {}
25
26
27 RefInset::RefInset(string const & data)
28         : CommandInset(data)
29 {}
30
31
32 auto_ptr<InsetBase> RefInset::clone() const
33 {
34         return auto_ptr<InsetBase>(new RefInset(*this));
35 }
36
37
38 void RefInset::infoize(std::ostream & os) const
39 {
40         os << "Ref: " << cell(0);
41 }
42
43
44 dispatch_result
45 RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
46 {
47         switch (cmd.action) {
48                 case LFUN_MOUSE_RELEASE:
49                         if (cmd.button() == mouse_button::button3) {
50                                 lyxerr << "trying to goto ref" << cell(0) << endl;
51                                 cmd.view()->dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
52                                 return DISPATCHED;
53                         }
54                         if (cmd.button() == mouse_button::button1) {
55                                 // Eventually trigger dialog with button 3
56                                 // not 1
57                                 string const data = createDialogStr("ref");
58                                 cmd.view()->owner()->getDialogs().
59                                         show("ref", data, this);
60                                 return DISPATCHED;
61                         }
62                         break;
63                 case LFUN_MOUSE_PRESS:
64                 case LFUN_MOUSE_MOTION:
65                         // eat other mouse commands
66                         return DISPATCHED;
67                 default:
68                         return CommandInset::dispatch(cmd, idx, pos);
69         }
70         // not our business
71         return UNDISPATCHED;
72 }
73
74
75 string const RefInset::screenLabel() const
76 {
77         string str;
78         for (int i = 0; !types[i].latex_name.empty(); ++i)
79                 if (commandname() == types[i].latex_name) {
80                         str = _(types[i].short_gui_name);
81                         break;
82                 }
83         str += asString(cell(0));
84
85         //if (/* !isLatex && */ !cell(0).empty()) {
86         //      str += "||";
87         //      str += asString(cell(1));
88         //}
89         return str;
90 }
91
92
93 void RefInset::validate(LaTeXFeatures & features) const
94 {
95         if (commandname() == "vref" || commandname() == "vpageref")
96                 features.require("varioref");
97         else if (commandname() == "prettyref")
98                 features.require("prettyref");
99 }
100
101
102 int RefInset::ascii(std::ostream & os, int) const
103 {
104         os << '[' << asString(cell(0)) << ']';
105         return 0;
106 }
107
108
109 int RefInset::linuxdoc(std::ostream & os) const
110 {
111         os << "<ref id=\"" << asString(cell(0))
112            << "\" name=\"" << asString(cell(1)) << "\" >";
113         return 0;
114 }
115
116
117 int RefInset::docbook(std::ostream & os, bool) const
118 {
119         if (cell(1).empty()) {
120                 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
121         } else {
122                 os << "<link linkend=\"" << asString(cell(0))
123                    << "\">" << asString(cell(1)) << "</link>";
124         }
125
126         return 0;
127 }
128
129
130 dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
131 {
132         if (cmd.action != LFUN_INSET_MODIFY || cmd.getArg(0) != "ref")
133                 return UNDISPATCHED;
134
135         MathArray ar;
136         if (!createMathInset_fromDialogStr(cmd.argument, ar))
137                 return UNDISPATCHED;
138
139         *this = *ar[0].nucleus()->asRefInset();
140 //      if (cmd.view())
141 //                 // This does not compile because updateInset expects
142 //                 // an Inset* and 'this' isn't.
143 //              cmd.view()->updateInset(this);
144         return DISPATCHED;
145 }
146
147
148 RefInset::ref_type_info RefInset::types[] = {
149         { "ref",       N_("Standard"),              N_("Ref: ")},
150         { "eqref",     N_("Equation"),              N_("EqRef: ")},
151         { "pageref",   N_("Page Number"),           N_("Page: ")},
152         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
153         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
154         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
155         { "", "", "" }
156 };