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