1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
#include <cstdlib>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
#include "inseturl.h"
|
|
|
|
#include "LString.h"
|
|
|
|
#include "commandtags.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "lyx_gui_misc.h" // CancelCloseBoxCB
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
2000-02-22 00:36:17 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
InsetUrl::InsetUrl(string const & cmd)
|
1999-10-25 14:50:26 +00:00
|
|
|
: fd_form_url(0)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
scanCommand(cmd);
|
|
|
|
if (getCmdName() == "url")
|
|
|
|
flag = InsetUrl::URL;
|
|
|
|
else
|
|
|
|
flag = InsetUrl::HTML_URL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
InsetUrl::InsetUrl(InsetCommand const & inscmd)
|
1999-10-25 14:50:26 +00:00
|
|
|
: fd_form_url(0)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
setCmdName(inscmd.getCmdName());
|
|
|
|
setContents(inscmd.getContents());
|
|
|
|
setOptions(inscmd.getOptions());
|
|
|
|
if (getCmdName() == "url")
|
|
|
|
flag = InsetUrl::URL;
|
|
|
|
else
|
|
|
|
flag = InsetUrl::HTML_URL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
InsetUrl::InsetUrl(string const & ins_name, string const & ins_cont,
|
|
|
|
string const & ins_opt)
|
1999-10-25 14:50:26 +00:00
|
|
|
: fd_form_url(0)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
setCmdName(ins_name);
|
|
|
|
setContents(ins_cont);
|
|
|
|
setOptions(ins_opt);
|
|
|
|
if (ins_name == "url")
|
|
|
|
flag = InsetUrl::URL;
|
|
|
|
else
|
|
|
|
flag = InsetUrl::HTML_URL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetUrl::~InsetUrl()
|
|
|
|
{
|
1999-10-25 14:50:26 +00:00
|
|
|
if (fd_form_url) {
|
|
|
|
fl_hide_form(fd_form_url->form_url);
|
|
|
|
fl_free_form(fd_form_url->form_url);
|
|
|
|
fd_form_url = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
void InsetUrl::CloseUrlCB(FL_OBJECT * ob, long)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-02-22 00:36:17 +00:00
|
|
|
Holder * holder = static_cast<Holder*>(ob->u_vdata);
|
|
|
|
|
|
|
|
InsetUrl * inset = holder->inset;
|
|
|
|
BufferView * bv = holder->view;
|
|
|
|
|
1999-10-25 14:50:26 +00:00
|
|
|
string url = fl_get_input(inset->fd_form_url->url_name);
|
|
|
|
string name = fl_get_input(inset->fd_form_url->name_name);
|
1999-10-02 16:21:10 +00:00
|
|
|
string cmdname;
|
1999-10-25 14:50:26 +00:00
|
|
|
if (fl_get_button(inset->fd_form_url->radio_html))
|
1999-09-27 18:44:28 +00:00
|
|
|
cmdname = "htmlurl";
|
|
|
|
else
|
|
|
|
cmdname = "url";
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
Buffer * buffer = bv->buffer();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if ((url != inset->getContents() ||
|
|
|
|
name != inset->getOptions() ||
|
|
|
|
cmdname != inset->getCmdName())
|
|
|
|
&& !(buffer->isReadonly()) ) {
|
|
|
|
buffer->markDirty();
|
|
|
|
inset->setContents(url);
|
|
|
|
inset->setOptions(name);
|
|
|
|
inset->setCmdName(cmdname);
|
|
|
|
if (cmdname == "url")
|
|
|
|
inset->flag = InsetUrl::URL;
|
|
|
|
else
|
|
|
|
inset->flag = InsetUrl::HTML_URL;
|
2000-02-23 16:39:03 +00:00
|
|
|
bv->updateInset(inset, true);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-10-25 14:50:26 +00:00
|
|
|
if (inset->fd_form_url) {
|
|
|
|
fl_hide_form(inset->fd_form_url->form_url);
|
1999-11-04 01:40:20 +00:00
|
|
|
fl_free_form(inset->fd_form_url->form_url);
|
1999-10-25 14:50:26 +00:00
|
|
|
inset->fd_form_url = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
|
|
|
extern "C" void C_InsetUrl_CloseUrlCB(FL_OBJECT * ob, long data)
|
1999-10-19 15:06:30 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
InsetUrl::CloseUrlCB(ob, data);
|
1999-10-19 15:06:30 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
char const * InsetUrl::EditMessage() const
|
|
|
|
{
|
|
|
|
return _("Opened Url");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
void InsetUrl::Edit(BufferView * bv, int, int, unsigned int)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-25 14:50:26 +00:00
|
|
|
static int ow = -1, oh;
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
if(bv->buffer()->isReadonly())
|
|
|
|
WarnReadonly(bv->buffer()->fileName());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-25 14:50:26 +00:00
|
|
|
if (!fd_form_url) {
|
|
|
|
fd_form_url = create_form_form_url();
|
2000-02-22 00:36:17 +00:00
|
|
|
holder.inset = this;
|
|
|
|
fd_form_url->button_close->u_vdata = &holder;
|
1999-12-07 00:44:53 +00:00
|
|
|
fl_set_form_atclose(fd_form_url->form_url,
|
|
|
|
CancelCloseBoxCB, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-02-22 00:36:17 +00:00
|
|
|
holder.view = bv;
|
1999-10-25 14:50:26 +00:00
|
|
|
fl_set_input(fd_form_url->url_name, getContents().c_str());
|
|
|
|
fl_set_input(fd_form_url->name_name, getOptions().c_str());
|
1999-09-27 18:44:28 +00:00
|
|
|
switch(flag) {
|
|
|
|
case InsetUrl::URL:
|
1999-10-25 14:50:26 +00:00
|
|
|
fl_set_button(fd_form_url->radio_html, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case InsetUrl::HTML_URL:
|
1999-10-25 14:50:26 +00:00
|
|
|
fl_set_button(fd_form_url->radio_html, 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-10-25 14:50:26 +00:00
|
|
|
if (fd_form_url->form_url->visible) {
|
|
|
|
fl_raise_form(fd_form_url->form_url);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
1999-10-25 14:50:26 +00:00
|
|
|
fl_show_form(fd_form_url->form_url,
|
|
|
|
FL_PLACE_MOUSE | FL_FREE_SIZE,
|
1999-09-27 18:44:28 +00:00
|
|
|
FL_FULLBORDER, _("Insert Url"));
|
1999-10-25 14:50:26 +00:00
|
|
|
if (ow < 0) {
|
|
|
|
ow = fd_form_url->form_url->w;
|
|
|
|
oh = fd_form_url->form_url->h;
|
|
|
|
}
|
|
|
|
fl_set_form_minsize(fd_form_url->form_url, ow, oh);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string InsetUrl::getScreenLabel() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string temp;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (flag == InsetUrl::HTML_URL)
|
|
|
|
temp += _("HtmlUrl: ");
|
|
|
|
else
|
|
|
|
temp += _("Url: ");
|
|
|
|
if(!getOptions().empty()) {
|
|
|
|
temp += getOptions();
|
2000-06-12 11:27:15 +00:00
|
|
|
} else {
|
|
|
|
temp += getContents();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetUrl::Latex(Buffer const *, ostream & os,
|
2000-04-19 01:42:55 +00:00
|
|
|
bool fragile, bool /*free_spc*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-03-02 02:19:43 +00:00
|
|
|
if (!getOptions().empty())
|
|
|
|
os << getOptions() + ' ';
|
|
|
|
if (fragile)
|
|
|
|
os << "\\protect";
|
|
|
|
os << "\\url{" << getContents() << '}';
|
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetUrl::Ascii(Buffer const *, ostream & os) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
|
|
|
if (getOptions().empty())
|
|
|
|
os << "[" << getContents() << "]";
|
|
|
|
else
|
|
|
|
os << "[" << getContents() << "||" << getOptions() << "]";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetUrl::Linuxdoc(Buffer const *, ostream & os) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
|
|
|
os << "<" << getCmdName()
|
|
|
|
<< " url=\"" << getContents() << "\""
|
|
|
|
<< " name=\"" << getOptions() << "\">";
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetUrl::DocBook(Buffer const *, ostream & os) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
|
|
|
os << "<ulink url=\"" << getContents() << "\">"
|
|
|
|
<< getOptions() << "</ulink>";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
void InsetUrl::Validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
features.url = true;
|
|
|
|
}
|