9 #include FORMS_H_LOCATION
12 #include "commandtags.h"
15 #include "LaTeXFeatures.h"
16 #include "lyx_gui_misc.h" // CancelCloseBoxCB
21 InsetUrl::InsetUrl(string const & cmd)
25 if (getCmdName() == "url")
28 flag = InsetUrl::HTML_URL;
32 InsetUrl::InsetUrl(InsetCommand const & inscmd)
35 setCmdName(inscmd.getCmdName());
36 setContents(inscmd.getContents());
37 setOptions(inscmd.getOptions());
38 if (getCmdName() == "url")
41 flag = InsetUrl::HTML_URL;
45 InsetUrl::InsetUrl(string const & ins_name, string const & ins_cont,
46 string const & ins_opt)
50 setContents(ins_cont);
52 if (ins_name == "url")
55 flag = InsetUrl::HTML_URL;
62 fl_hide_form(fd_form_url->form_url);
63 fl_free_form(fd_form_url->form_url);
69 void InsetUrl::CloseUrlCB(FL_OBJECT * ob, long)
71 Holder * holder = static_cast<Holder*>(ob->u_vdata);
73 InsetUrl * inset = holder->inset;
74 BufferView * bv = holder->view;
76 string url = fl_get_input(inset->fd_form_url->url_name);
77 string name = fl_get_input(inset->fd_form_url->name_name);
79 if (fl_get_button(inset->fd_form_url->radio_html))
84 Buffer * buffer = bv->buffer();
86 if ((url != inset->getContents() ||
87 name != inset->getOptions() ||
88 cmdname != inset->getCmdName())
89 && !(buffer->isReadonly()) ) {
91 inset->setContents(url);
92 inset->setOptions(name);
93 inset->setCmdName(cmdname);
95 inset->flag = InsetUrl::URL;
97 inset->flag = InsetUrl::HTML_URL;
98 bv->updateInset(inset, true);
101 if (inset->fd_form_url) {
102 fl_hide_form(inset->fd_form_url->form_url);
103 fl_free_form(inset->fd_form_url->form_url);
104 inset->fd_form_url = 0;
110 void C_InsetUrl_CloseUrlCB(FL_OBJECT * ob, long data)
112 InsetUrl::CloseUrlCB(ob, data);
116 char const * InsetUrl::EditMessage() const
118 return _("Opened Url");
122 void InsetUrl::Edit(BufferView * bv, int, int, unsigned int)
124 static int ow = -1, oh;
126 if(bv->buffer()->isReadonly())
127 WarnReadonly(bv->buffer()->fileName());
130 fd_form_url = create_form_form_url();
132 fd_form_url->button_close->u_vdata = &holder;
133 fl_set_form_atclose(fd_form_url->form_url,
134 CancelCloseBoxCB, 0);
137 fl_set_input(fd_form_url->url_name, getContents().c_str());
138 fl_set_input(fd_form_url->name_name, getOptions().c_str());
141 fl_set_button(fd_form_url->radio_html, 0);
143 case InsetUrl::HTML_URL:
144 fl_set_button(fd_form_url->radio_html, 1);
148 if (fd_form_url->form_url->visible) {
149 fl_raise_form(fd_form_url->form_url);
151 fl_show_form(fd_form_url->form_url,
152 FL_PLACE_MOUSE | FL_FREE_SIZE,
153 FL_FULLBORDER, _("Insert Url"));
155 ow = fd_form_url->form_url->w;
156 oh = fd_form_url->form_url->h;
158 fl_set_form_minsize(fd_form_url->form_url, ow, oh);
163 string InsetUrl::getScreenLabel() const
166 if (flag == InsetUrl::HTML_URL)
167 temp += _("HtmlUrl: ");
170 if(!getOptions().empty()) {
171 temp += getOptions();
173 temp += getContents();
179 int InsetUrl::Latex(Buffer const *, ostream & os,
180 bool fragile, bool /*free_spc*/) const
182 if (!getOptions().empty())
183 os << getOptions() + ' ';
186 os << "\\url{" << getContents() << '}';
191 int InsetUrl::Ascii(Buffer const *, ostream & os) const
193 if (getOptions().empty())
194 os << "[" << getContents() << "]";
196 os << "[" << getContents() << "||" << getOptions() << "]";
201 int InsetUrl::Linuxdoc(Buffer const *, ostream & os) const
203 os << "<" << getCmdName()
204 << " url=\"" << getContents() << "\""
205 << " name=\"" << getOptions() << "\">";
211 int InsetUrl::DocBook(Buffer const *, ostream & os) const
213 os << "<ulink url=\"" << getContents() << "\">"
214 << getOptions() << "</ulink>";
219 void InsetUrl::Validate(LaTeXFeatures & features) const