This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / insets / insetref.C
bloba66d536ade98408df1c6ddc8880f76a2515db893
1 #include <config.h>
3 #include <cstdlib>
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
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"
19 extern BufferView * current_view;
22 InsetRef::InsetRef(string const & cmd, Buffer * bf)
23         : master(bf)
25         scanCommand(cmd);
26         if (getCmdName() == "ref")
27                 flag = InsetRef::REF;
28         else
29                 flag = InsetRef::PAGE_REF;
33 InsetRef::InsetRef(InsetCommand const & inscmd, Buffer * bf)
34         : master(bf)
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;
46 InsetRef::~InsetRef()
51 void InsetRef::Edit(int, int)
53         current_view->getOwner()->getLyXFunc()
54                 ->Dispatch(LFUN_REFGOTO, getContents().c_str());
58 string InsetRef::getScreenLabel() const
60         string temp;
61         if (flag == InsetRef::PAGE_REF)
62                 temp += _("Page: ");
63         else 
64                 temp += _("Ref: ");
65         temp += getContents();
66         if(!current_view->currentBuffer()->isLatex()
67            && !getOptions().empty()) {
68                 temp += "||";
69                 temp += getOptions();
70         }
71         return temp;
75 int InsetRef::Latex(FILE * file, signed char /*fragile*/)
77         if(getOptions().empty())
78                 fprintf(file, "%s", escape(getCommand()).c_str());
79         else {
80                 string ns;
81                 InsetCommand clone= InsetCommand(getCmdName(),getContents(),ns);
82                 fprintf(file, "%s", escape(clone.getCommand()).c_str());
83         }
84         return 0;
88 int InsetRef::Latex(string & file, signed char /*fragile*/)
90         if(getOptions().empty())
91                 file += escape(getCommand());
92         else {
93                 string ns;
94                 InsetCommand clone= InsetCommand(getCmdName(),getContents(),ns);
95                 file += escape(clone.getCommand());
96         }
97         return 0;
101 int InsetRef::Linuxdoc(string & file)
103         file += "<ref id=\"" + getContents()
104                 + "\" name=\""+ getOptions() +"\" >" ;
106         return 0;
110 int InsetRef::DocBook(string & file)
112         file += "<link linkend=\"" + getContents()
113                 + "\">"+ getOptions() +"</link>" ;
115         return 0;
119 // This function escapes 8-bit characters and other problematic characters
120 // It's exactly the same code as in insetlabel.C.
121 string InsetRef::escape(string const & lab) const {
122         char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
123                               '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
124         string enc;
125         for (string::size_type i = 0; i < lab.length(); ++i) {
126                 unsigned char c=lab[i];
127                 if (c >= 128 || c=='=' || c=='%') {
128                         enc += '=';
129                         enc += hexdigit[c>>4];
130                         enc += hexdigit[c & 15];
131                 } else {
132                         enc += c;
133                 }
134         }
135         return enc;