9 #include FORMS_H_LOCATION
12 #include "commandtags.h"
14 #include "LaTeXFeatures.h"
15 #include "lyx_gui_misc.h" // CancelCloseBoxCB
18 InsetUrl::InsetUrl(string const & cmd)
22 if (getCmdName() == "url")
25 flag = InsetUrl::HTML_URL;
29 InsetUrl::InsetUrl(InsetCommand const & inscmd)
32 setCmdName(inscmd.getCmdName());
33 setContents(inscmd.getContents());
34 setOptions(inscmd.getOptions());
35 if (getCmdName() == "url")
38 flag = InsetUrl::HTML_URL;
42 InsetUrl::InsetUrl(string const & ins_name, string const & ins_cont,
43 string const & ins_opt)
47 setContents(ins_cont);
49 if (ins_name == "url")
52 flag = InsetUrl::HTML_URL;
59 fl_hide_form(fd_form_url->form_url);
60 fl_free_form(fd_form_url->form_url);
66 void InsetUrl::CloseUrlCB(FL_OBJECT * ob, long)
68 Holder * holder = static_cast<Holder*>(ob->u_vdata);
70 InsetUrl * inset = holder->inset;
71 BufferView * bv = holder->view;
73 string url = fl_get_input(inset->fd_form_url->url_name);
74 string name = fl_get_input(inset->fd_form_url->name_name);
76 if (fl_get_button(inset->fd_form_url->radio_html))
81 Buffer * buffer = bv->buffer();
83 if ((url != inset->getContents() ||
84 name != inset->getOptions() ||
85 cmdname != inset->getCmdName())
86 && !(buffer->isReadonly()) ) {
88 inset->setContents(url);
89 inset->setOptions(name);
90 inset->setCmdName(cmdname);
92 inset->flag = InsetUrl::URL;
94 inset->flag = InsetUrl::HTML_URL;
95 bv->updateInset(inset, true);
98 if (inset->fd_form_url) {
99 fl_hide_form(inset->fd_form_url->form_url);
100 fl_free_form(inset->fd_form_url->form_url);
101 inset->fd_form_url = 0;
106 extern "C" void C_InsetUrl_CloseUrlCB(FL_OBJECT * ob, long data)
108 InsetUrl::CloseUrlCB(ob, data);
112 void InsetUrl::Edit(BufferView * bv, int, int, unsigned int)
114 static int ow = -1, oh;
116 if(bv->buffer()->isReadonly())
117 WarnReadonly(bv->buffer()->fileName());
120 fd_form_url = create_form_form_url();
122 fd_form_url->button_close->u_vdata = &holder;
123 fl_set_form_atclose(fd_form_url->form_url,
124 CancelCloseBoxCB, 0);
127 fl_set_input(fd_form_url->url_name, getContents().c_str());
128 fl_set_input(fd_form_url->name_name, getOptions().c_str());
131 fl_set_button(fd_form_url->radio_html, 0);
133 case InsetUrl::HTML_URL:
134 fl_set_button(fd_form_url->radio_html, 1);
138 if (fd_form_url->form_url->visible) {
139 fl_raise_form(fd_form_url->form_url);
141 fl_show_form(fd_form_url->form_url,
142 FL_PLACE_MOUSE | FL_FREE_SIZE,
143 FL_FULLBORDER, _("Insert Url"));
145 ow = fd_form_url->form_url->w;
146 oh = fd_form_url->form_url->h;
148 fl_set_form_minsize(fd_form_url->form_url, ow, oh);
153 string InsetUrl::getScreenLabel() const
156 if (flag == InsetUrl::HTML_URL)
157 temp += _("HtmlUrl: ");
160 temp += getContents();
161 if(!getOptions().empty()) {
163 temp += getOptions();
169 int InsetUrl::Latex(ostream & os, signed char fragile, bool free_spc) const
171 if (!getOptions().empty())
172 os << getOptions() + ' ';
175 os << "\\url{" << getContents() << '}';
180 int InsetUrl::Linuxdoc(ostream & os) const
182 os << "<" << getCmdName()
183 << " url=\"" << getContents() << "\""
184 << " name=\"" << getOptions() << "\">";
190 int InsetUrl::DocBook(ostream & os) const
192 os << "<ulink url=\"" << getContents() << "\">"
193 << getOptions() << "</ulink>";
198 void InsetUrl::Validate(LaTeXFeatures & features) const