]> git.lyx.org Git - lyx.git/blob - src/insets/insetref.C
clear()->erase() ; lots of using directives for cxx
[lyx.git] / src / insets / insetref.C
1 #include <config.h>
2
3 #include <cstdlib>
4
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
8
9 #include FORMS_H_LOCATION 
10 #include "insetref.h"
11 #include "buffer.h"
12 #include "debug.h"
13 #include "lyx_gui_misc.h" // CancelCloseBoxCB
14 #include "LyXView.h"
15 #include "lyxfunc.h"
16 #include "commandtags.h"
17 #include "gettext.h"
18
19 using std::ostream;
20
21 extern BufferView * current_view;
22
23
24 InsetRef::InsetRef(string const & cmd, Buffer * bf)
25         : master(bf)
26 {
27         scanCommand(cmd);
28         if (getCmdName() == "ref")
29                 flag = InsetRef::REF;
30         else
31                 flag = InsetRef::PAGE_REF;
32 }
33
34
35 InsetRef::InsetRef(InsetCommand const & inscmd, Buffer * bf)
36         : master(bf)
37 {
38         setCmdName(inscmd.getCmdName());
39         setContents(inscmd.getContents());
40         setOptions(inscmd.getOptions());
41         if (getCmdName() == "ref")
42                 flag = InsetRef::REF;
43         else
44                 flag = InsetRef::PAGE_REF;
45 }
46
47
48 void InsetRef::Edit(BufferView * bv, int, int, unsigned int)
49 {
50         bv->owner()->getLyXFunc()->
51                 Dispatch(LFUN_REFGOTO, getContents().c_str());
52 }
53
54
55 string InsetRef::getScreenLabel() const
56 {
57         string temp;
58         if (flag == InsetRef::PAGE_REF)
59                 temp += _("Page: ");
60         else 
61                 temp += _("Ref: ");
62         temp += getContents();
63         if(!current_view->buffer()->isLatex()
64            && !getOptions().empty()) {
65                 temp += "||";
66                 temp += getOptions();
67         }
68         return temp;
69 }
70
71
72 int InsetRef::Latex(ostream & os,
73                     bool /*fragile*/, bool /*fs*/) const
74 {
75         if(getOptions().empty())
76                 os << escape(getCommand());
77         else {
78                 string ns;
79                 InsetCommand clone = InsetCommand(getCmdName(),
80                                                   getContents(), ns);
81                 os << escape(clone.getCommand());
82         }
83         return 0;
84 }
85
86
87 int InsetRef::Ascii(ostream & os) const
88 {
89         os << "[" << getContents() << "]";
90         return 0;
91 }
92
93
94 int InsetRef::Linuxdoc(ostream & os) const
95 {
96         os << "<ref id=\"" << getContents()
97            << "\" name=\"" << getOptions() << "\" >";
98         return 0;
99 }
100
101
102 int InsetRef::DocBook(ostream & os) const
103 {
104         os << "<link linkend=\"" << getContents()
105            << "\">" << getOptions() << "</link>";
106         return 0;
107 }
108
109
110 // This function escapes 8-bit characters and other problematic characters
111 // It's exactly the same code as in insetlabel.C.
112 string InsetRef::escape(string const & lab) const
113 {
114         char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
115                               '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
116         string enc;
117         for (string::size_type i = 0; i < lab.length(); ++i) {
118                 unsigned char c= lab[i];
119                 if (c >= 128 || c == '=' || c == '%') {
120                         enc += '=';
121                         enc += hexdigit[c>>4];
122                         enc += hexdigit[c & 15];
123                 } else {
124                         enc += c;
125                 }
126         }
127         return enc;
128 }