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