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