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