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