2000-07-27 08:55:59 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2000-07-27 10:26:38 +00:00
|
|
|
|
2000-07-27 08:55:59 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2000-07-27 10:26:38 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include "gettext.h"
|
2000-07-27 08:55:59 +00:00
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "FormUrl.h"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "form_url.h"
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
|
|
|
|
FormUrl::FormUrl(LyXView * lv, Dialogs * d)
|
2000-08-03 12:56:25 +00:00
|
|
|
: FormCommand(lv, d, _("Url")), dialog_(0)
|
2000-07-27 08:55:59 +00:00
|
|
|
{
|
|
|
|
// let the dialog be shown
|
|
|
|
// These are permanent connections so we won't bother
|
|
|
|
// storing a copy because we won't be disconnecting.
|
|
|
|
d->showUrl.connect(slot(this, &FormUrl::showInset));
|
|
|
|
d->createUrl.connect(slot(this, &FormUrl::createInset));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FormUrl::~FormUrl()
|
|
|
|
{
|
2000-08-01 17:33:32 +00:00
|
|
|
delete dialog_;
|
2000-07-27 08:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormUrl::build()
|
|
|
|
{
|
|
|
|
dialog_ = build_url();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
FL_FORM * const FormUrl::form() const
|
2000-07-27 08:55:59 +00:00
|
|
|
{
|
2000-08-01 17:33:32 +00:00
|
|
|
if( dialog_ && dialog_->form_url )
|
|
|
|
return dialog_->form_url;
|
|
|
|
else
|
|
|
|
return 0;
|
2000-07-27 08:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
void FormUrl::update()
|
2000-07-27 08:55:59 +00:00
|
|
|
{
|
2000-08-01 17:33:32 +00:00
|
|
|
static int ow = -1, oh;
|
2000-07-27 08:55:59 +00:00
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
if (ow < 0) {
|
|
|
|
ow = dialog_->form_url->w;
|
|
|
|
oh = dialog_->form_url->h;
|
2000-07-27 08:55:59 +00:00
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
fl_set_form_minsize(dialog_->form_url, ow, oh);
|
|
|
|
fl_set_form_maxsize(dialog_->form_url, 2*ow, oh);
|
2000-07-27 08:55:59 +00:00
|
|
|
}
|
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
fl_freeze_form( dialog_->form_url );
|
2000-07-27 08:55:59 +00:00
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
fl_set_input(dialog_->url, params.getContents().c_str());
|
|
|
|
fl_set_input(dialog_->name, params.getOptions().c_str());
|
2000-07-27 08:55:59 +00:00
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
if ( params.getCmdName() == "url" )
|
2000-07-27 08:55:59 +00:00
|
|
|
fl_set_button(dialog_->radio_html, 0);
|
|
|
|
else
|
|
|
|
fl_set_button(dialog_->radio_html, 1);
|
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
if( lv_->buffer()->isReadonly() ) {
|
|
|
|
fl_deactivate_object( dialog_->url );
|
|
|
|
fl_deactivate_object( dialog_->name );
|
|
|
|
fl_deactivate_object( dialog_->radio_html );
|
|
|
|
fl_deactivate_object( dialog_->ok );
|
|
|
|
fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
|
|
|
|
} else {
|
|
|
|
fl_activate_object( dialog_->url );
|
|
|
|
fl_activate_object( dialog_->name );
|
|
|
|
fl_activate_object( dialog_->radio_html );
|
|
|
|
fl_activate_object( dialog_->ok );
|
|
|
|
fl_set_object_lcol( dialog_->ok, FL_BLACK );
|
2000-07-27 08:55:59 +00:00
|
|
|
}
|
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
fl_unfreeze_form( dialog_->form_url );
|
2000-07-27 08:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormUrl::apply()
|
|
|
|
{
|
|
|
|
if( lv_->buffer()->isReadonly() ) return;
|
|
|
|
|
2000-08-01 17:33:32 +00:00
|
|
|
params.setContents( fl_get_input(dialog_->url) );
|
|
|
|
params.setOptions( fl_get_input(dialog_->name) );
|
2000-07-27 08:55:59 +00:00
|
|
|
|
|
|
|
if (fl_get_button(dialog_->radio_html))
|
2000-08-01 17:33:32 +00:00
|
|
|
params.setCmdName("htmlurl");
|
2000-07-27 08:55:59 +00:00
|
|
|
else
|
2000-08-01 17:33:32 +00:00
|
|
|
params.setCmdName("url");
|
2000-07-27 08:55:59 +00:00
|
|
|
|
|
|
|
if( inset_ != 0 )
|
|
|
|
{
|
2000-08-01 17:33:32 +00:00
|
|
|
// Only update if contents have changed
|
|
|
|
if( params.getCmdName() != inset_->getCmdName() ||
|
|
|
|
params.getContents() != inset_->getContents() ||
|
|
|
|
params.getOptions() != inset_->getOptions() ) {
|
|
|
|
inset_->setParams( params );
|
|
|
|
lv_->view()->updateInset( inset_, true );
|
|
|
|
}
|
2000-07-27 08:55:59 +00:00
|
|
|
} else {
|
|
|
|
lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
|
2000-08-01 17:33:32 +00:00
|
|
|
params.getAsString().c_str() );
|
2000-07-27 08:55:59 +00:00
|
|
|
}
|
|
|
|
}
|