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