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