]> git.lyx.org Git - lyx.git/blob - src/insets/insetref.C
LyX Drinkers United: patch 2
[lyx.git] / src / insets / insetref.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "insetref.h"
8 #include "buffer.h"
9 #include "commandtags.h"
10 #include "debug.h"
11 #include "gettext.h"
12 #include "LaTeXFeatures.h"
13 #include "LyXView.h"
14 #include "frontends/Dialogs.h"
15 #include "lyxfunc.h"
16 #include "BufferView.h"
17 #include "support/lstrings.h"
18
19 using std::ostream;
20
21 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
22         : InsetCommand(p), isLatex(buf.isLatex())
23 {}
24
25 void InsetRef::Edit(BufferView * bv, int, int, unsigned int button)
26 {
27         // Eventually trigger dialog with button 3 not 1
28         if (button == 3 )
29                 bv->owner()->getLyXFunc()->
30                         Dispatch(LFUN_REF_GOTO, getContents());
31         else if (button == 1 )
32                 bv->owner()->getDialogs()->showRef( this );
33 }
34
35
36 string const InsetRef::getScreenLabel() const
37 {
38         string temp;
39         for (int i = 0; !types[i].latex_name.empty(); ++ i)
40                 if (getCmdName() == types[i].latex_name) {
41                         temp = _(types[i].short_gui_name);
42                         break;
43                 }
44         temp += getContents();
45
46         if (!isLatex
47            && !getOptions().empty()) {
48                 temp += "||";
49                 temp += getOptions();
50         }
51         return temp;
52 }
53
54
55 int InsetRef::Latex(Buffer const *, ostream & os,
56                     bool /*fragile*/, bool /*fs*/) const
57 {
58         if (getOptions().empty())
59                 os << escape(getCommand());
60         else {
61                 InsetCommandParams p( getCmdName(), getContents(), "" );
62                 os << escape(p.getCommand());
63         }
64         return 0;
65 }
66
67
68 int InsetRef::Ascii(Buffer const *, ostream & os, int) const
69 {
70         os << "[" << getContents() << "]";
71         return 0;
72 }
73
74
75 int InsetRef::Linuxdoc(Buffer const *, ostream & os) const
76 {
77         os << "<ref id=\"" << getContents()
78            << "\" name=\"" << getOptions() << "\" >";
79         return 0;
80 }
81
82
83 int InsetRef::DocBook(Buffer const *, ostream & os) const
84 {
85         if (getOptions().empty()) {
86                 os << "<xref linkend=\"" << getContents() << "\"/>";
87         } else {
88                 os << "<link linkend=\"" << getContents()
89                    << "\">" << getOptions() << "</link>";
90         }
91
92         return 0;
93 }
94
95
96 void InsetRef::Validate(LaTeXFeatures & features) const
97 {
98         if (getCmdName() == "vref" || getCmdName() == "vpageref")
99                 features.varioref = true;
100         else if (getCmdName() == "prettyref")
101                 features.prettyref = true;
102 }
103
104 InsetRef::type_info InsetRef::types[] = {
105         { "ref",        N_("Standard"),                 N_("Ref: ")},
106         { "pageref",    N_("Page Number"),              N_("Page: ")},
107         { "vpageref",   N_("Textual Page Number"),      N_("TextPage: ")},
108         { "vref",       N_("Standard+Textual Page"),    N_("Ref+Text: ")},
109         { "prettyref",  N_("PrettyRef"),                N_("PrettyRef: ")},
110         { "", "", "" }
111 };
112
113
114 int InsetRef::getType(string const & name)
115 {
116         for (int i = 0; !types[i].latex_name.empty(); ++i)
117                 if (name == types[i].latex_name)
118                         return i;
119         return 0;
120 }
121
122
123 string const & InsetRef::getName(int type)
124 {
125         return types[type].latex_name;
126 }