]> git.lyx.org Git - lyx.git/blob - src/insets/insetref.C
cleanup after svn hang-up, #undef CursorShape. Should be compilable ganin now.
[lyx.git] / src / insets / insetref.C
1 /**
2  * \file insetref.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author José Matos
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10 #include <config.h>
11
12 #include "insetref.h"
13
14 #include "buffer.h"
15 #include "cursor.h"
16 #include "BufferView.h"
17 #include "dispatchresult.h"
18 #include "funcrequest.h"
19 #include "gettext.h"
20 #include "LaTeXFeatures.h"
21 #include "outputparams.h"
22 #include "sgml.h"
23
24 #include "frontends/LyXView.h"
25
26 #include "support/lstrings.h"
27
28
29 using lyx::support::escape;
30
31 using std::string;
32 using std::ostream;
33
34
35 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
36         : InsetCommand(p, "ref"), isLatex(buf.isLatex())
37 {}
38
39
40 InsetRef::InsetRef(InsetRef const & ir)
41         : InsetCommand(ir), isLatex(ir.isLatex)
42 {}
43
44
45 void InsetRef::doDispatch(LCursor & cur, FuncRequest & cmd)
46 {
47         switch (cmd.action) {
48         case LFUN_MOUSE_PRESS:
49                 // Eventually trigger dialog with button 3 not 1
50                 if (cmd.button() == mouse_button::button3)
51                         cur.bv().owner()->dispatch(FuncRequest(LFUN_LABEL_GOTO, getContents()));
52                 else {
53                         InsetCommandMailer("ref", *this).showDialog(&cur.bv());
54                         cur.undispatched();
55                 }
56                 return;
57
58         case LFUN_MOUSE_RELEASE:
59                 return;
60
61         default:
62                 return InsetCommand::doDispatch(cur, cmd);
63         }
64 }
65
66
67 string const InsetRef::getScreenLabel(Buffer const &) const
68 {
69         string temp;
70         for (int i = 0; !types[i].latex_name.empty(); ++i) {
71                 if (getCmdName() == types[i].latex_name) {
72                         // FIXME UNIOCDE
73                         temp = lyx::to_utf8(_(types[i].short_gui_name));
74                         break;
75                 }
76         }
77         temp += getContents();
78
79         if (!isLatex && !getOptions().empty()) {
80                 temp += "||";
81                 temp += getOptions();
82         }
83         return temp;
84 }
85
86
87 int InsetRef::latex(Buffer const &, ostream & os,
88                     OutputParams const &) const
89 {
90         if (getOptions().empty())
91                 os << escape(getCommand());
92         else {
93                 InsetCommandParams p(getCmdName(), getContents(), "");
94                 os << escape(p.getCommand());
95         }
96         return 0;
97 }
98
99
100 int InsetRef::plaintext(Buffer const &, ostream & os,
101                     OutputParams const &) const
102 {
103         os << '[' << getContents() << ']';
104         return 0;
105 }
106
107
108 int InsetRef::docbook(Buffer const & buf, ostream & os,
109                       OutputParams const & runparams) const
110 {
111         if (getOptions().empty() && runparams.flavor == OutputParams::XML) {
112                 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, getContents()) << "\" />";
113         } else if (getOptions().empty()) {
114                 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, getContents()) << "\">";
115         } else {
116                 os << "<link linkend=\"" << sgml::cleanID(buf, runparams, getContents())
117                    << "\">" << getOptions() << "</link>";
118         }
119
120         return 0;
121 }
122
123
124 int InsetRef::textString(Buffer const & buf, ostream & os,
125                        OutputParams const & op) const
126 {
127         return plaintext(buf, os, op);
128 }
129
130
131 void InsetRef::validate(LaTeXFeatures & features) const
132 {
133         if (getCmdName() == "vref" || getCmdName() == "vpageref")
134                 features.require("varioref");
135         else if (getCmdName() == "prettyref")
136                 features.require("prettyref");
137         else if (getCmdName() == "eqref")
138                 features.require("amsmath");
139 }
140
141
142 InsetRef::type_info InsetRef::types[] = {
143         { "ref",       N_("Standard"),              N_("Ref: ")},
144         { "eqref",     N_("Equation"),              N_("EqRef: ")},
145         { "pageref",   N_("Page Number"),           N_("Page: ")},
146         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
147         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
148         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
149         { "", "", "" }
150 };
151
152
153 int InsetRef::getType(string const & name)
154 {
155         for (int i = 0; !types[i].latex_name.empty(); ++i)
156                 if (name == types[i].latex_name)
157                         return i;
158         return 0;
159 }
160
161
162 string const & InsetRef::getName(int type)
163 {
164         return types[type].latex_name;
165 }