]> git.lyx.org Git - lyx.git/blob - src/insets/insetref.C
Re-add the RasterImage template.
[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 using lyx::support::escape;
25
26 using std::ostream;
27
28
29 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
30         : InsetCommand(p), isLatex(buf.isLatex())
31 {}
32
33
34 InsetRef::InsetRef(InsetRef const & ir)
35         : InsetCommand(ir), isLatex(ir.isLatex)
36 {
37 }
38
39
40 InsetRef::~InsetRef()
41 {
42         InsetCommandMailer("ref", *this).hideDialog();
43 }
44
45
46 dispatch_result InsetRef::localDispatch(FuncRequest const & cmd)
47 {
48         switch (cmd.action) {
49         case LFUN_INSET_EDIT:
50                 // Eventually trigger dialog with button 3 not 1
51                 if (cmd.button() == mouse_button::button3)
52                         cmd.view()->owner()->
53                                 dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
54                 else
55                         InsetCommandMailer("ref", *this).showDialog(cmd.view());
56                 return DISPATCHED;
57
58         default:
59                 return InsetCommand::localDispatch(cmd);
60         }
61 }
62
63
64 string const InsetRef::getScreenLabel(Buffer const &) const
65 {
66         string temp;
67         for (int i = 0; !types[i].latex_name.empty(); ++ i)
68                 if (getCmdName() == types[i].latex_name) {
69                         temp = _(types[i].short_gui_name);
70                         break;
71                 }
72         temp += getContents();
73
74         if (!isLatex
75            && !getOptions().empty()) {
76                 temp += "||";
77                 temp += getOptions();
78         }
79         return temp;
80 }
81
82
83 int InsetRef::latex(Buffer const &, ostream & os,
84                     LatexRunParams const &) const
85 {
86         if (getOptions().empty())
87                 os << escape(getCommand());
88         else {
89                 InsetCommandParams p(getCmdName(), getContents(), "");
90                 os << escape(p.getCommand());
91         }
92         return 0;
93 }
94
95
96 int InsetRef::ascii(Buffer const &, ostream & os, int) const
97 {
98         os << '[' << getContents() << ']';
99         return 0;
100 }
101
102
103 int InsetRef::linuxdoc(Buffer const &, ostream & os) const
104 {
105         os << "<ref id=\"" << getContents()
106            << "\" name=\"" << getOptions() << "\" >";
107         return 0;
108 }
109
110
111 int InsetRef::docbook(Buffer const &, ostream & os, bool) 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 }