]> git.lyx.org Git - lyx.git/blob - src/mathed/ref_inset.C
mathed uglyfication
[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(BufferView & bv, FuncRequest const & cmd)
58 {
59         switch (cmd.action) {
60         case LFUN_INSET_MODIFY:
61                 if (cmd.getArg(0) == "ref") {
62                         MathArray ar;
63                         if (!createMathInset_fromDialogStr(cmd.argument, ar))
64                                 return DispatchResult(false);
65
66                         *this = *ar[0].nucleus()->asRefInset();
67
68                         return DispatchResult(true, true);
69                 }
70                 break;
71         case LFUN_MOUSE_RELEASE:
72                 if (cmd.button() == mouse_button::button3) {
73                         lyxerr << "trying to goto ref" << cell(0) << endl;
74                         bv.dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
75                         return DispatchResult(true, true);
76                 }
77                 if (cmd.button() == mouse_button::button1) {
78                         // Eventually trigger dialog with button 3
79                         // not 1
80                         string const data = createDialogStr("ref");
81                         bv.owner()->getDialogs().show("ref", data, this);
82                         return DispatchResult(true, true);
83                 }
84                 break;
85         case LFUN_MOUSE_PRESS:
86         case LFUN_MOUSE_MOTION:
87                 // eat other mouse commands
88                 return DispatchResult(true, true);
89         default:
90                 return CommandInset::priv_dispatch(bv, cmd);
91         }
92         // not our business
93         return DispatchResult(false);
94 }
95
96
97 string const RefInset::screenLabel() const
98 {
99         string str;
100         for (int i = 0; !types[i].latex_name.empty(); ++i)
101                 if (commandname() == types[i].latex_name) {
102                         str = _(types[i].short_gui_name);
103                         break;
104                 }
105         str += asString(cell(0));
106
107         //if (/* !isLatex && */ !cell(0).empty()) {
108         //      str += "||";
109         //      str += asString(cell(1));
110         //}
111         return str;
112 }
113
114
115 void RefInset::validate(LaTeXFeatures & features) const
116 {
117         if (commandname() == "vref" || commandname() == "vpageref")
118                 features.require("varioref");
119         else if (commandname() == "prettyref")
120                 features.require("prettyref");
121 }
122
123
124 int RefInset::plaintext(std::ostream & os, OutputParams const &) const
125 {
126         os << '[' << asString(cell(0)) << ']';
127         return 0;
128 }
129
130
131 int RefInset::linuxdoc(std::ostream & os, OutputParams const &) const
132 {
133         os << "<ref id=\"" << asString(cell(0))
134            << "\" name=\"" << asString(cell(1)) << "\" >";
135         return 0;
136 }
137
138
139 int RefInset::docbook(std::ostream & os, OutputParams const &) const
140 {
141         if (cell(1).empty()) {
142                 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
143         } else {
144                 os << "<link linkend=\"" << asString(cell(0))
145                    << "\">" << asString(cell(1)) << "</link>";
146         }
147
148         return 0;
149 }
150
151
152
153
154 RefInset::ref_type_info RefInset::types[] = {
155         { "ref",       N_("Standard"),              N_("Ref: ")},
156         { "eqref",     N_("Equation"),              N_("EqRef: ")},
157         { "pageref",   N_("Page Number"),           N_("Page: ")},
158         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
159         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
160         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
161         { "", "", "" }
162 };