9 #include FORMS_H_LOCATION
13 #include "lyx_gui_misc.h" // CancelCloseBoxCB
16 #include "commandtags.h"
19 extern BufferView *current_view;
21 // Temporarily disabled the GUI code. Reasons:
22 // - Only page-ref button works currently, IMO we should use a LyX action
23 // instead, to toggle the kind of refs.
24 // - To change the label, IMO it's faster to delete the old one and insert
26 // - To goto to the label, IMO it's much faster to just click on the
27 // inset. That's how I've implemented it now, I hope you'll like it.
28 // - The more GUI code we can remove, the less work we'll have at
29 // the toolkit switch.
34 /* Header file generated with fdesign. */
36 /**** Callback routines ****/
38 static void ref_close_cb(FL_OBJECT *, long);
39 static void goto_label_cb(FL_OBJECT *, long);
40 static void label_change_cb(FL_OBJECT *, long);
42 /**** Forms and Objects ****/
53 /* Form definition file generated with fdesign. */
56 FD_ref *create_form_ref(void)
59 FD_ref *fdui = (FD_ref *) fl_calloc(1, sizeof(*fdui));
61 fdui->ref = fl_bgn_form(FL_NO_BOX, 210, 170);
62 obj = fl_add_box(FL_UP_BOX,0,0,210,170,"");
63 obj = fl_add_frame(FL_ENGRAVED_FRAME,10,20,130,60,"");
64 obj = fl_add_button(FL_RETURN_BUTTON,120,130,80,30,_("Close"));
65 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
66 fl_set_object_callback(obj,ref_close_cb,0);
67 obj = fl_add_text(FL_NORMAL_TEXT,20,10,110,20,_("Reference Type"));
68 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
69 fl_set_object_lalign(obj,FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
70 obj = fl_add_button(FL_NORMAL_BUTTON,10,130,100,30,_("Goto Label"));
71 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
72 fl_set_object_callback(obj,goto_label_cb,0);
73 obj = fl_add_button(FL_NORMAL_BUTTON,10,90,100,30,_("Change Label"));
74 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
75 fl_set_object_callback(obj,label_change_cb,0);
77 fdui->pg_grp = fl_bgn_group();
78 fdui->flag1 = obj = fl_add_checkbutton(FL_RADIO_BUTTON,20,30,20,20,_("Page Number"));
79 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
80 fdui->flag2 = obj = fl_add_checkbutton(FL_RADIO_BUTTON,20,50,20,20,_("Reference"));
81 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
86 fdui->ref->fdui = fdui;
90 /*---------------------------------------*/
93 static FD_ref *form = 0;
97 void ref_close_cb(FL_OBJECT *, long)
99 InsetRef *inset = (InsetRef*)form->vdata;
101 if (fl_get_button(form->flag1)) {
102 inset->setFlag(InsetRef::PAGE_REF);
103 inset->setCmdName("pageref");
105 inset->setFlag(InsetRef::REF);
106 inset->setCmdName("ref");
109 fl_hide_form(form->ref);
114 void goto_label_cb(FL_OBJECT *, long)
116 // code yet to be written
117 InsetRef *inset = (InsetRef*)form->vdata;
124 void label_change_cb(FL_OBJECT *, long)
126 // code yet to be written
127 InsetRef *inset = (InsetRef*)form->vdata;
133 InsetRef::InsetRef(string const & cmd, Buffer *bf)
137 if (getCmdName() == "ref")
138 flag = InsetRef::REF;
140 flag = InsetRef::PAGE_REF;
144 InsetRef::InsetRef(InsetCommand const &inscmd, Buffer *bf)
147 setCmdName(inscmd.getCmdName());
148 setContents(inscmd.getContents());
149 setOptions(inscmd.getOptions());
150 if (getCmdName() == "ref")
151 flag = InsetRef::REF;
153 flag = InsetRef::PAGE_REF;
157 InsetRef::~InsetRef()
162 void InsetRef::Edit(int, int)
164 current_view->getOwner()->getLyXFunc()->Dispatch(LFUN_REFGOTO
165 , getContents().c_str());
169 form = create_form_ref();
170 fl_set_form_atclose(form->ref, IgnoreCloseBoxCB, 0);
174 fl_set_button(form->flag1, (flag == InsetRef::REF) ? 1 : 0);
175 fl_set_button(form->flag2, (flag == InsetRef::PAGE_REF) ? 1 : 0);
177 if (form->ref->visible) {
178 fl_raise_form(form->ref);
180 fl_show_form(form->ref,FL_PLACE_MOUSE, FL_FULLBORDER,
181 _("Cross-Reference"));
187 string InsetRef::getScreenLabel() const
190 if (flag == InsetRef::PAGE_REF)
194 temp += getContents();
195 if(!current_view->currentBuffer()->isLatex() && !getOptions().empty()) {
197 temp += getOptions();
203 int InsetRef::Latex(FILE *file, signed char /*fragile*/)
205 if(getOptions().empty())
206 fprintf(file, "%s", escape(getCommand()).c_str());
209 InsetCommand clone= InsetCommand(getCmdName(),getContents(),ns);
210 fprintf(file, "%s", escape(clone.getCommand()).c_str());
216 int InsetRef::Latex(string &file, signed char /*fragile*/)
218 if(getOptions().empty())
219 file += escape(getCommand());
222 InsetCommand clone= InsetCommand(getCmdName(),getContents(),ns);
223 file += escape(clone.getCommand());
229 int InsetRef::Linuxdoc(string &file)
231 file += "<ref id=\"" + getContents() + "\" name=\""+ getOptions() +"\" >" ;
237 int InsetRef::DocBook(string &file)
239 file += "<link linkend=\"" + getContents() + "\">"+ getOptions() +"</link>" ;
245 // This function escapes 8-bit characters and other problematic characters
246 // It's exactly the same code as in insetlabel.C.
247 string InsetRef::escape(string const & lab) const {
248 char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
249 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
251 for (string::size_type i = 0; i < lab.length(); ++i) {
252 unsigned char c=lab[i];
253 if (c >= 128 || c=='=' || c=='%') {
255 enc += hexdigit[c>>4];
256 enc += hexdigit[c & 15];