-// -*- C++ -*-
-/* This file is part of
- * ======================================================
+/**
+ * \file FormUrl.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * LyX, The Document Processor
+ * \author Angus Leeming
*
- * Copyright 2000 The LyX Team.
- *
- * ======================================================
+ * Full author contact details are available in file CREDITS.
*/
+
#include <config.h>
-#include FORMS_H_LOCATION
+#include "FormUrl.h"
+#include "ControlCommand.h"
+#include "forms/form_url.h"
-#ifdef __GNUG__
-#pragma implementation
-#endif
+#include "xformsBC.h"
+#include "lyx_forms.h"
-#include "gettext.h"
-#include "BufferView.h"
-#include "Dialogs.h"
-#include "FormUrl.h"
-#include "LyXView.h"
-#include "buffer.h"
-#include "form_url.h"
-#include "lyxfunc.h"
-#include "xform_macros.h"
-#include "insets/insetcommand.h"
-#include "insets/inseturl.h"
-#include "support/filetools.h"
-
-C_RETURNCB(FormUrl, WMHideCB)
-C_GENERICCB(FormUrl, OKCB)
-C_GENERICCB(FormUrl, CancelCB)
-
-FormUrl::FormUrl(LyXView * lv, Dialogs * d)
- : dialog_(0), lv_(lv), d_(d), u_(0), h_(0), ih_(0),
- inset_(0), dialogIsOpen(false)
-{
- // 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));
- params = new InsetCommandParams();
-}
+typedef FormController<ControlCommand, FormView<FD_url> > base_class;
-FormUrl::~FormUrl()
-{
- free();
- delete params;
-}
+FormUrl::FormUrl(Dialog & parent)
+ : base_class(parent, _("URL"))
+{}
void FormUrl::build()
{
- dialog_ = build_url();
-}
-
-
-void FormUrl::showInset( InsetUrl * inset )
-{
- if( dialogIsOpen || inset == 0 ) return;
-
- inset_ = inset;
- ih_ = inset_->hide.connect(slot(this, &FormUrl::hide));
+ dialog_.reset(build_url(this));
- (*params) = inset->params();
- show();
-}
+ fl_set_input_return(dialog_->input_name, FL_RETURN_CHANGED);
+ fl_set_input_return(dialog_->input_url, FL_RETURN_CHANGED);
+ setPrehandler(dialog_->input_name);
+ setPrehandler(dialog_->input_url);
-void FormUrl::createInset( string const & arg )
-{
- if( dialogIsOpen ) return;
+ // Manage the ok, apply, restore and cancel/close buttons
+ bcview().setOK(dialog_->button_ok);
+ bcview().setApply(dialog_->button_apply);
+ bcview().setCancel(dialog_->button_close);
+ bcview().setRestore(dialog_->button_restore);
- params->setFromString( arg );
- show();
-}
-
-
-void FormUrl::show()
-{
- if (!dialog_) {
- build();
- fl_set_form_atclose(dialog_->form_url,
- C_FormUrlWMHideCB, 0);
- }
-
- update(); // make sure its up-to-date
-
- dialogIsOpen = true;
- if (dialog_->form_url->visible) {
- fl_raise_form(dialog_->form_url);
- } else {
- fl_show_form(dialog_->form_url,
- FL_PLACE_MOUSE | FL_FREE_SIZE,
- FL_TRANSIENT,
- _("Url"));
- u_ = d_->updateBufferDependent.
- connect(slot(this, &FormUrl::update));
- h_ = d_->hideBufferDependent.
- connect(slot(this, &FormUrl::hide));
- }
+ bcview().addReadOnly(dialog_->input_name);
+ bcview().addReadOnly(dialog_->input_url);
+ bcview().addReadOnly(dialog_->check_html);
}
void FormUrl::update()
{
- fl_set_input(dialog_->url, params->getContents().c_str());
- fl_set_input(dialog_->name, params->getOptions().c_str());
+ fl_set_input(dialog_->input_url,
+ controller().params().getContents().c_str());
+ fl_set_input(dialog_->input_name,
+ controller().params().getOptions().c_str());
- if ( params->getCmdName() == "url" )
- fl_set_button(dialog_->radio_html, 0);
+ if (controller().params().getCmdName() == "url")
+ fl_set_button(dialog_->check_html, 0);
else
- fl_set_button(dialog_->radio_html, 1);
-
- static int ow = -1, oh;
-
- if (ow < 0) {
- ow = dialog_->form_url->w;
- oh = dialog_->form_url->h;
- }
-
- fl_set_form_minsize(dialog_->form_url, ow, oh);
- fl_set_form_maxsize(dialog_->form_url, 2*ow, oh);
+ fl_set_button(dialog_->check_html, 1);
}
void FormUrl::apply()
{
- if( lv_->buffer()->isReadonly() ) return;
+ controller().params().setContents(fl_get_input(dialog_->input_url));
+ controller().params().setOptions(fl_get_input(dialog_->input_name));
- params->setContents( fl_get_input(dialog_->url) );
- params->setOptions( fl_get_input(dialog_->name) );
-
- if (fl_get_button(dialog_->radio_html))
- params->setCmdName("htmlurl");
+ if (fl_get_button(dialog_->check_html))
+ controller().params().setCmdName("htmlurl");
else
- params->setCmdName("url");
-
- if( inset_ != 0 )
- {
- inset_->setParams( *params );
- lv_->view()->updateInset( inset_, true );
- } else {
- lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
- params->getAsString().c_str() );
- }
-}
-
-
-void FormUrl::hide()
-{
- if (dialog_
- && dialog_->form_url
- && dialog_->form_url->visible) {
- fl_hide_form(dialog_->form_url);
- u_.disconnect();
- h_.disconnect();
- }
-
- // free up the dialog for another inset
- inset_ = 0;
- ih_.disconnect();
- dialogIsOpen = false;
-}
-
-
-void FormUrl::free()
-{
- // we don't need to delete u and h here because
- // hide() does that after disconnecting.
- if (dialog_) {
- if (dialog_->form_url
- && dialog_->form_url->visible) {
- hide();
- }
- fl_free_form(dialog_->form_url);
- delete dialog_;
- dialog_ = 0;
- }
-}
-
-
-int FormUrl::WMHideCB(FL_FORM * form, void *)
-{
- // Ensure that the signals (u and h) are disconnected even if the
- // window manager is used to close the dialog.
- FormUrl * pre = static_cast<FormUrl*>(form->u_vdata);
- pre->hide();
- return FL_CANCEL;
-}
-
-
-void FormUrl::OKCB(FL_OBJECT * ob, long)
-{
- FormUrl * pre = static_cast<FormUrl*>(ob->form->u_vdata);
- pre->apply();
- pre->hide();
-}
-
-
-void FormUrl::CancelCB(FL_OBJECT * ob, long)
-{
- FormUrl * pre = static_cast<FormUrl*>(ob->form->u_vdata);
- pre->hide();
+ controller().params().setCmdName("url");
}