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