9 #include FORMS_H_LOCATION
12 #include "commandtags.h"
14 #include "LaTeXFeatures.h"
15 #include "lyx_gui_misc.h" // CancelCloseBoxCB
17 extern void UpdateInset(BufferView *, 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 Holder * holder = static_cast<Holder*>(ob->u_vdata);
72 InsetUrl * inset = holder->inset;
73 BufferView * bv = holder->view;
75 string url = fl_get_input(inset->fd_form_url->url_name);
76 string name = fl_get_input(inset->fd_form_url->name_name);
78 if (fl_get_button(inset->fd_form_url->radio_html))
83 Buffer * buffer = bv->buffer();
85 if ((url != inset->getContents() ||
86 name != inset->getOptions() ||
87 cmdname != inset->getCmdName())
88 && !(buffer->isReadonly()) ) {
90 inset->setContents(url);
91 inset->setOptions(name);
92 inset->setCmdName(cmdname);
94 inset->flag = InsetUrl::URL;
96 inset->flag = InsetUrl::HTML_URL;
97 UpdateInset(bv, inset);
100 if (inset->fd_form_url) {
101 fl_hide_form(inset->fd_form_url->form_url);
102 fl_free_form(inset->fd_form_url->form_url);
103 inset->fd_form_url = 0;
108 extern "C" void C_InsetUrl_CloseUrlCB(FL_OBJECT * ob, long data)
110 InsetUrl::CloseUrlCB(ob, data);
114 void InsetUrl::Edit(BufferView * bv, int, int)
116 static int ow = -1, oh;
118 if(bv->buffer()->isReadonly())
119 WarnReadonly(bv->buffer()->fileName());
122 fd_form_url = create_form_form_url();
124 fd_form_url->button_close->u_vdata = &holder;
125 fl_set_form_atclose(fd_form_url->form_url,
126 CancelCloseBoxCB, 0);
129 fl_set_input(fd_form_url->url_name, getContents().c_str());
130 fl_set_input(fd_form_url->name_name, getOptions().c_str());
133 fl_set_button(fd_form_url->radio_html, 0);
135 case InsetUrl::HTML_URL:
136 fl_set_button(fd_form_url->radio_html, 1);
140 if (fd_form_url->form_url->visible) {
141 fl_raise_form(fd_form_url->form_url);
143 fl_show_form(fd_form_url->form_url,
144 FL_PLACE_MOUSE | FL_FREE_SIZE,
145 FL_FULLBORDER, _("Insert Url"));
147 ow = fd_form_url->form_url->w;
148 oh = fd_form_url->form_url->h;
150 fl_set_form_minsize(fd_form_url->form_url, ow, oh);
155 string InsetUrl::getScreenLabel() const
158 if (flag == InsetUrl::HTML_URL)
159 temp += _("HtmlUrl: ");
162 temp += getContents();
163 if(!getOptions().empty()) {
165 temp += getOptions();
171 int InsetUrl::Latex(ostream & os, signed char fragile) const
174 int res = Latex(latex_output, fragile);
181 int InsetUrl::Latex(string & file, signed char fragile) const
183 if (!getOptions().empty())
184 file += getOptions() + ' ';
188 file += "\\url{" + getContents() + '}';
194 int InsetUrl::Linuxdoc(string & file) const
196 file += "<"+ getCmdName() +
197 " url=\"" + getContents()+"\"" +
198 " name=\"" + getOptions() +"\">";
204 int InsetUrl::DocBook(string & file) const
206 file += "<ulink url=\"" + getContents() + "\">" +
207 getOptions() +"</ulink>";
213 void InsetUrl::Validate(LaTeXFeatures & features) const