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;
61 fl_hide_form(fd_form_url->form_url);
62 fl_free_form(fd_form_url->form_url);
68 void InsetUrl::CloseUrlCB(FL_OBJECT * ob, long)
70 InsetUrl * inset = static_cast<InsetUrl*>(ob->u_vdata);
71 string url = fl_get_input(inset->fd_form_url->url_name);
72 string name = fl_get_input(inset->fd_form_url->name_name);
74 if (fl_get_button(inset->fd_form_url->radio_html))
79 Buffer * buffer = current_view->buffer();
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;
96 if (inset->fd_form_url) {
97 fl_hide_form(inset->fd_form_url->form_url);
98 fl_free_form(inset->fd_form_url->form_url);
99 inset->fd_form_url = 0;
104 extern "C" void C_InsetUrl_CloseUrlCB(FL_OBJECT * ob, long data)
106 InsetUrl::CloseUrlCB(ob, data);
110 void InsetUrl::Edit(int, int)
112 static int ow = -1, oh;
114 if(current_view->buffer()->isReadonly())
118 fd_form_url = create_form_form_url();
119 fd_form_url->button_close->u_vdata = this;
120 fl_set_form_atclose(fd_form_url->form_url, CancelCloseBoxCB, 0);
122 fl_set_input(fd_form_url->url_name, getContents().c_str());
123 fl_set_input(fd_form_url->name_name, getOptions().c_str());
126 fl_set_button(fd_form_url->radio_html, 0);
128 case InsetUrl::HTML_URL:
129 fl_set_button(fd_form_url->radio_html, 1);
133 if (fd_form_url->form_url->visible) {
134 fl_raise_form(fd_form_url->form_url);
136 fl_show_form(fd_form_url->form_url,
137 FL_PLACE_MOUSE | FL_FREE_SIZE,
138 FL_FULLBORDER, _("Insert Url"));
140 ow = fd_form_url->form_url->w;
141 oh = fd_form_url->form_url->h;
143 fl_set_form_minsize(fd_form_url->form_url, ow, oh);
148 string InsetUrl::getScreenLabel() const
151 if (flag == InsetUrl::HTML_URL)
152 temp += _("HtmlUrl: ");
155 temp += getContents();
156 if(!getOptions().empty()) {
158 temp += getOptions();
164 int InsetUrl::Latex(FILE * file, signed char fragile)
167 int res = Latex(latex_output, fragile);
168 fprintf(file, "%s", latex_output.c_str());
174 int InsetUrl::Latex(string &file, signed char fragile)
176 if (!getOptions().empty())
177 file += getOptions() + ' ';
181 file += "\\url{" + getContents() + '}';
187 int InsetUrl::Linuxdoc(string & file)
189 file += "<"+ getCmdName() +
190 " url=\"" + getContents()+"\"" +
191 " name=\"" + getOptions() +"\">";
197 int InsetUrl::DocBook(string & file)
199 file += "<ulink url=\"" + getContents() + "\">" +
200 getOptions() +"</ulink>";
206 void InsetUrl::Validate(LaTeXFeatures & features) const