]> git.lyx.org Git - lyx.git/blob - src/insets/insetref.C
Cruft removal, small clean-up, no functional changes.
[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 "BufferView.h"
16 #include "dispatchresult.h"
17 #include "funcrequest.h"
18 #include "gettext.h"
19 #include "LaTeXFeatures.h"
20
21 #include "frontends/LyXView.h"
22
23 #include "support/lstrings.h"
24
25
26 using lyx::support::escape;
27
28 using std::string;
29 using std::ostream;
30
31
32 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
33         : InsetCommand(p, "ref"), isLatex(buf.isLatex())
34 {}
35
36
37 InsetRef::InsetRef(InsetRef const & ir)
38         : InsetCommand(ir), isLatex(ir.isLatex)
39 {}
40
41
42 DispatchResult
43 InsetRef::priv_dispatch(FuncRequest const & cmd,
44                         idx_type & idx, pos_type & pos)
45 {
46         switch (cmd.action) {
47         case LFUN_MOUSE_PRESS:
48                 // Eventually trigger dialog with button 3 not 1
49                 if (cmd.button() == mouse_button::button3)
50                         cmd.view()->owner()->
51                                 dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
52                 else
53                         InsetCommandMailer("ref", *this).showDialog(cmd.view());
54                 return DispatchResult(true, true);
55
56         default:
57                 return InsetCommand::priv_dispatch(cmd, idx, pos);
58         }
59 }
60
61
62 string const InsetRef::getScreenLabel(Buffer const &) const
63 {
64         string temp;
65         for (int i = 0; !types[i].latex_name.empty(); ++ i)
66                 if (getCmdName() == types[i].latex_name) {
67                         temp = _(types[i].short_gui_name);
68                         break;
69                 }
70         temp += getContents();
71
72         if (!isLatex
73            && !getOptions().empty()) {
74                 temp += "||";
75                 temp += getOptions();
76         }
77         return temp;
78 }
79
80
81 int InsetRef::latex(Buffer const &, ostream & os,
82                     OutputParams const &) const
83 {
84         if (getOptions().empty())
85                 os << escape(getCommand());
86         else {
87                 InsetCommandParams p(getCmdName(), getContents(), "");
88                 os << escape(p.getCommand());
89         }
90         return 0;
91 }
92
93
94 int InsetRef::plaintext(Buffer const &, ostream & os,
95                     OutputParams const &) const
96 {
97         os << '[' << getContents() << ']';
98         return 0;
99 }
100
101
102 int InsetRef::linuxdoc(Buffer const &, ostream & os,
103                        OutputParams const &) const
104 {
105         os << "<ref id=\"" << getContents()
106            << "\" name=\"" << getOptions() << "\" >";
107         return 0;
108 }
109
110
111 int InsetRef::docbook(Buffer const &, ostream & os,
112                       OutputParams const &) const
113 {
114         if (getOptions().empty()) {
115                 os << "<xref linkend=\"" << getContents() << "\">";
116         } else {
117                 os << "<link linkend=\"" << getContents()
118                    << "\">" << getOptions() << "</link>";
119         }
120
121         return 0;
122 }
123
124
125 void InsetRef::validate(LaTeXFeatures & features) const
126 {
127         if (getCmdName() == "vref" || getCmdName() == "vpageref")
128                 features.require("varioref");
129         else if (getCmdName() == "prettyref")
130                 features.require("prettyref");
131         else if (getCmdName() == "eqref")
132                 features.require("amsmath");
133 }
134
135
136 InsetRef::type_info InsetRef::types[] = {
137         { "ref",       N_("Standard"),              N_("Ref: ")},
138         { "eqref",     N_("Equation"),              N_("EqRef: ")},
139         { "pageref",   N_("Page Number"),           N_("Page: ")},
140         { "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
141         { "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
142         { "prettyref", N_("PrettyRef"),             N_("PrettyRef: ")},
143         { "", "", "" }
144 };
145
146
147 int InsetRef::getType(string const & name)
148 {
149         for (int i = 0; !types[i].latex_name.empty(); ++i)
150                 if (name == types[i].latex_name)
151                         return i;
152         return 0;
153 }
154
155
156 string const & InsetRef::getName(int type)
157 {
158         return types[type].latex_name;
159 }