]> git.lyx.org Git - lyx.git/blob - src/insets/insetref.C
Hold on to your hats.
[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, bool)
27         : InsetCommand(p), isLatex(buf.isLatex())
28 {}
29
30
31 InsetRef::~InsetRef()
32 {
33         InsetCommandMailer mailer("ref", *this);
34         mailer.hideDialog();
35 }
36
37
38 void InsetRef::edit(BufferView * bv, int, int, mouse_button::state button)
39 {
40         // FuncRequestually trigger dialog with button 3 not 1
41         if (button == mouse_button::button3)
42                 bv->owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
43         else if (button == mouse_button::button1) {
44                 InsetCommandMailer mailer("ref", *this);
45                 mailer.showDialog();
46         }
47 }
48
49
50 void InsetRef::edit(BufferView *, bool)
51 {}
52
53
54 string const InsetRef::getScreenLabel(Buffer const *) const
55 {
56         string temp;
57         for (int i = 0; !types[i].latex_name.empty(); ++ i)
58                 if (getCmdName() == types[i].latex_name) {
59                         temp = _(types[i].short_gui_name);
60                         break;
61                 }
62         temp += getContents();
63
64         if (!isLatex
65            && !getOptions().empty()) {
66                 temp += "||";
67                 temp += getOptions();
68         }
69         return temp;
70 }
71
72
73 int InsetRef::latex(Buffer const *, ostream & os,
74                     bool /*fragile*/, bool /*fs*/) const
75 {
76         if (getOptions().empty())
77                 os << escape(getCommand());
78         else {
79                 InsetCommandParams p(getCmdName(), getContents(), "");
80                 os << escape(p.getCommand());
81         }
82         return 0;
83 }
84
85
86 int InsetRef::ascii(Buffer const *, ostream & os, int) const
87 {
88         os << '[' << getContents() << ']';
89         return 0;
90 }
91
92
93 int InsetRef::linuxdoc(Buffer const *, ostream & os) const
94 {
95         os << "<ref id=\"" << getContents()
96            << "\" name=\"" << getOptions() << "\" >";
97         return 0;
98 }
99
100
101 int InsetRef::docbook(Buffer const *, ostream & os, bool) const
102 {
103         if (getOptions().empty()) {
104                 os << "<xref linkend=\"" << getContents() << "\">";
105         } else {
106                 os << "<link linkend=\"" << getContents()
107                    << "\">" << getOptions() << "</link>";
108         }
109
110         return 0;
111 }
112
113
114 void InsetRef::validate(LaTeXFeatures & features) const
115 {
116         if (getCmdName() == "vref" || getCmdName() == "vpageref")
117                 features.require("varioref");
118         else if (getCmdName() == "prettyref")
119                 features.require("prettyref");
120 }
121
122
123 InsetRef::type_info InsetRef::types[] = {
124         { "ref",        N_("Standard"),                 N_("Ref: ")},
125         { "pageref",    N_("Page Number"),              N_("Page: ")},
126         { "vpageref",   N_("Textual Page Number"),      N_("TextPage: ")},
127         { "vref",       N_("Standard+Textual Page"),    N_("Ref+Text: ")},
128         { "prettyref",  N_("PrettyRef"),                N_("PrettyRef: ")},
129         { "", "", "" }
130 };
131
132
133 int InsetRef::getType(string const & name)
134 {
135         for (int i = 0; !types[i].latex_name.empty(); ++i)
136                 if (name == types[i].latex_name)
137                         return i;
138         return 0;
139 }
140
141
142 string const & InsetRef::getName(int type)
143 {
144         return types[type].latex_name;
145 }