]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormUrl.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / FormUrl.C
index bceee127ed473be9738f7cfde3d11de7040cd141..f8a1f885536d52a3db5d13d6c147623c2c71e587 100644 (file)
-// -*- C++ -*-
 /* This file is part of
  * ====================================================== 
  *
  *           LyX, The Document Processor
  *
- *           Copyright 2000 The LyX Team.
+ *           Copyright 2000-2001 The LyX Team.
  *
  * ======================================================
+ * 
+ * \file FormUrl.C
+ * \author Angus Leeming, a.leeming@ic.ac.uk 
  */
 
 #include <config.h>
-#include "gettext.h"
-#include FORMS_H_LOCATION
-#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"
 
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
-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();
-}
+#include "xformsBC.h"
+#include "ControlUrl.h"
+#include "FormUrl.h"
+#include "form_url.h"
 
+typedef FormCB<ControlUrl, FormDB<FD_form_url> > base_class;
 
-FormUrl::~FormUrl()
-{
-       free();
-       delete params;
-}
+FormUrl::FormUrl(ControlUrl & c)
+       : base_class(c, _("Url"))
+{}
 
 
 void FormUrl::build()
 {
-       dialog_ = build_url();
-}
-
+       dialog_.reset(build_url());
 
-void FormUrl::showInset( InsetUrl * inset )
-{
-       if( dialogIsOpen || inset == 0 ) return;
+       fl_set_input_return(dialog_->name, FL_RETURN_CHANGED);
+       fl_set_input_return(dialog_->url,  FL_RETURN_CHANGED);
 
-       inset_ = inset;
-       ih_ = inset_->hide.connect(slot(this, &FormUrl::hide));
+        // Manage the ok, apply, restore and cancel/close buttons
+       bc().setOK(dialog_->button_ok);
+       bc().setApply(dialog_->button_apply);
+       bc().setCancel(dialog_->button_cancel);
+       bc().setRestore(dialog_->button_restore);
 
-       (*params) = inset->params();
-       show();
-}
-
-
-void FormUrl::createInset( string const & arg )
-{
-       if( dialogIsOpen ) return;
-
-       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));
-       }
+       bc().addReadOnly(dialog_->name);
+       bc().addReadOnly(dialog_->url);
+       bc().addReadOnly(dialog_->radio_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_->url,
+                    controller().params().getContents().c_str());
+       fl_set_input(dialog_->name,
+                    controller().params().getOptions().c_str());
 
-       if ( params->getCmdName() == "url" )
+       if (controller().params().getCmdName() == "url")
                fl_set_button(dialog_->radio_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);
 }
 
 
 void FormUrl::apply()
 {
-       if( lv_->buffer()->isReadonly() ) return;
-
-       params->setContents( fl_get_input(dialog_->url) );
-       params->setOptions( fl_get_input(dialog_->name) );
+       controller().params().setContents(fl_get_input(dialog_->url));
+       controller().params().setOptions(fl_get_input(dialog_->name));
 
        if (fl_get_button(dialog_->radio_html))
-               params->setCmdName("htmlurl");
+               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");
 }