9 #include FORMS_H_LOCATION
12 #include "commandtags.h"
14 #include "LaTeXFeatures.h"
15 #include "lyx_gui_misc.h" // CancelCloseBoxCB
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 bv->updateInset(inset, true);
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;
109 void C_InsetUrl_CloseUrlCB(FL_OBJECT * ob, long data)
111 InsetUrl::CloseUrlCB(ob, data);
115 char const * InsetUrl::EditMessage() const
117 return _("Opened Url");
121 void InsetUrl::Edit(BufferView * bv, int, int, unsigned int)
123 static int ow = -1, oh;
125 if(bv->buffer()->isReadonly())
126 WarnReadonly(bv->buffer()->fileName());
129 fd_form_url = create_form_form_url();
131 fd_form_url->button_close->u_vdata = &holder;
132 fl_set_form_atclose(fd_form_url->form_url,
133 CancelCloseBoxCB, 0);
136 fl_set_input(fd_form_url->url_name, getContents().c_str());
137 fl_set_input(fd_form_url->name_name, getOptions().c_str());
140 fl_set_button(fd_form_url->radio_html, 0);
142 case InsetUrl::HTML_URL:
143 fl_set_button(fd_form_url->radio_html, 1);
147 if (fd_form_url->form_url->visible) {
148 fl_raise_form(fd_form_url->form_url);
150 fl_show_form(fd_form_url->form_url,
151 FL_PLACE_MOUSE | FL_FREE_SIZE,
152 FL_FULLBORDER, _("Insert Url"));
154 ow = fd_form_url->form_url->w;
155 oh = fd_form_url->form_url->h;
157 fl_set_form_minsize(fd_form_url->form_url, ow, oh);
162 string InsetUrl::getScreenLabel() const
165 if (flag == InsetUrl::HTML_URL)
166 temp += _("HtmlUrl: ");
169 if(!getOptions().empty()) {
170 temp += getOptions();
172 temp += getContents();
178 int InsetUrl::Latex(Buffer const *, ostream & os,
179 bool fragile, bool /*free_spc*/) const
181 if (!getOptions().empty())
182 os << getOptions() + ' ';
185 os << "\\url{" << getContents() << '}';
190 int InsetUrl::Ascii(Buffer const *, ostream & os) const
192 if (getOptions().empty())
193 os << "[" << getContents() << "]";
195 os << "[" << getContents() << "||" << getOptions() << "]";
200 int InsetUrl::Linuxdoc(Buffer const *, ostream & os) const
202 os << "<" << getCmdName()
203 << " url=\"" << getContents() << "\""
204 << " name=\"" << getOptions() << "\">";
210 int InsetUrl::DocBook(Buffer const *, ostream & os) const
212 os << "<ulink url=\"" << getContents() << "\">"
213 << getOptions() << "</ulink>";
218 void InsetUrl::Validate(LaTeXFeatures & features) const