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
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
extern BufferView * current_view;
|
|
|
|
extern void UpdateInset(Inset * inset, bool mark_dirty = true);
|
1999-09-27 18:44:28 +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
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
InsetUrl * inset = static_cast<InsetUrl*>(ob->u_vdata);
|
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";
|
|
|
|
|
1999-11-09 22:53:41 +00:00
|
|
|
Buffer * buffer = current_view->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;
|
|
|
|
UpdateInset(inset);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void InsetUrl::Edit(int, int)
|
|
|
|
{
|
1999-10-25 14:50:26 +00:00
|
|
|
static int ow = -1, oh;
|
|
|
|
|
1999-11-09 22:53:41 +00:00
|
|
|
if(current_view->buffer()->isReadonly())
|
1999-09-27 18:44:28 +00:00
|
|
|
WarnReadonly();
|
|
|
|
|
1999-10-25 14:50:26 +00:00
|
|
|
if (!fd_form_url) {
|
|
|
|
fd_form_url = create_form_form_url();
|
|
|
|
fd_form_url->button_close->u_vdata = this;
|
|
|
|
fl_set_form_atclose(fd_form_url->form_url,CancelCloseBoxCB, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
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: ");
|
|
|
|
temp += getContents();
|
|
|
|
if(!getOptions().empty()) {
|
|
|
|
temp += "||";
|
|
|
|
temp += getOptions();
|
|
|
|
}
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int InsetUrl::Latex(FILE * file, signed char fragile)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string latex_output;
|
1999-09-27 18:44:28 +00:00
|
|
|
int res = Latex(latex_output, fragile);
|
|
|
|
fprintf(file, "%s", latex_output.c_str());
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
int InsetUrl::Latex(string &file, signed char fragile)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (!getOptions().empty())
|
|
|
|
file += getOptions() + ' ';
|
|
|
|
if (fragile)
|
|
|
|
file += "\\protect";
|
|
|
|
|
|
|
|
file += "\\url{" + getContents() + '}';
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int InsetUrl::Linuxdoc(string & file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
file += "<"+ getCmdName() +
|
|
|
|
" url=\"" + getContents()+"\"" +
|
|
|
|
" name=\"" + getOptions() +"\">";
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int InsetUrl::DocBook(string & file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
file += "<ulink url=\"" + getContents() + "\">" +
|
|
|
|
getOptions() +"</ulink>";
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|