9 #include FORMS_H_LOCATION
12 #include "commandtags.h"
14 #include "LaTeXFeatures.h"
15 #include "lyx_gui_misc.h" // CancelCloseBoxCB
17 extern BufferView *current_view;
18 extern void UpdateInset(Inset* inset, bool mark_dirty = true);
20 InsetUrl::InsetUrl(string const & cmd)
24 if (getCmdName() == "url")
27 flag = InsetUrl::HTML_URL;
31 InsetUrl::InsetUrl(InsetCommand const &inscmd)
34 setCmdName(inscmd.getCmdName());
35 setContents(inscmd.getContents());
36 setOptions(inscmd.getOptions());
37 if (getCmdName() == "url")
40 flag = InsetUrl::HTML_URL;
44 InsetUrl::InsetUrl(string const &ins_name,string const &ins_cont,
45 string const &ins_opt)
49 setContents(ins_cont);
51 if (ins_name == "url")
54 flag = InsetUrl::HTML_URL;
68 void InsetUrl::CloseUrlCB(FL_OBJECT *ob, long)
70 InsetUrl *inset = (InsetUrl*) ob->u_vdata;
71 string url = fl_get_input(inset->url_name);
72 string name = fl_get_input(inset->name_name);
74 if (fl_get_button(inset->radio_html))
79 Buffer *buffer = current_view->currentBuffer();
81 if ((url != inset->getContents() ||
82 name != inset->getOptions() ||
83 cmdname != inset->getCmdName())
84 && !(buffer->isReadonly()) ) {
86 inset->setContents(url);
87 inset->setOptions(name);
88 inset->setCmdName(cmdname);
90 inset->flag = InsetUrl::URL;
92 inset->flag = InsetUrl::HTML_URL;
97 fl_hide_form(inset->form);
102 extern "C" void C_InsetUrl_CloseUrlCB(FL_OBJECT *ob, long)
104 InsetUrl::CloseUrlCB(0,0);
107 void InsetUrl::Edit(int, int)
109 if(current_view->currentBuffer()->isReadonly())
114 form = fl_bgn_form(FL_NO_BOX, 530, 170);
115 obj = fl_add_box(FL_UP_BOX,0,0,530,170,"");
116 url_name = obj = fl_add_input(FL_NORMAL_INPUT,50,30,460,30,idex(_("Url|#U")));
117 fl_set_button_shortcut(obj,scex(_("Url|#U")),1);
118 name_name = obj = fl_add_input(FL_NORMAL_INPUT,50,80,460,30,idex(_("Name|#N")));
119 fl_set_button_shortcut(obj,scex(_("Name|#N")),1);
120 obj = fl_add_button(FL_RETURN_BUTTON,360,130,100,30,idex(_("Close|#C^[^M")));
121 fl_set_button_shortcut(obj,scex(_("Close|#C^[^M")),1);
123 fl_set_object_callback(obj,C_InsetUrl_CloseUrlCB,0);
124 radio_html = obj = fl_add_checkbutton(FL_PUSH_BUTTON,50,130,240,30,idex(_("HTML type|#H")));
125 fl_set_button_shortcut(obj,scex(_("HTML type|#H")),1);
126 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
128 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
130 fl_set_input(url_name, getContents().c_str());
131 fl_set_input(name_name, getOptions().c_str());
134 fl_set_button(radio_html, 0);
136 case InsetUrl::HTML_URL:
137 fl_set_button(radio_html, 1);
144 fl_show_form(form, FL_PLACE_MOUSE,
145 FL_FULLBORDER, _("Insert Url"));
150 string InsetUrl::getScreenLabel() const
153 if (flag == InsetUrl::HTML_URL)
154 temp += _("HtmlUrl: ");
157 temp += getContents();
158 if(!getOptions().empty()) {
160 temp += getOptions();
166 int InsetUrl::Latex(FILE *file, signed char fragile)
169 int res = Latex(latex_output, fragile);
170 fprintf(file, "%s", latex_output.c_str());
176 int InsetUrl::Latex(string &file, signed char fragile)
178 if (!getOptions().empty())
179 file += getOptions() + ' ';
183 file += "\\url{" + getContents() + '}';
189 int InsetUrl::Linuxdoc(string &file)
191 file += "<"+ getCmdName() +
192 " url=\"" + getContents()+"\"" +
193 " name=\"" + getOptions() +"\">";
199 int InsetUrl::DocBook(string &file)
201 file += "<ulink url=\"" + getContents() + "\">" +
202 getOptions() +"</ulink>";
208 void InsetUrl::Validate(LaTeXFeatures& features) const