]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormGraphics.C
More pref work from Angus
[lyx.git] / src / frontends / xforms / FormGraphics.C
index e76c5d923a01116d51e3f898191d112ddc0a6f2a..49cb50d87de065fa2f56fb950717b2548739ad51 100644 (file)
 #endif 
 
 #include "lyx_gui_misc.h"
-#include "gettext.h"
-#include FORMS_H_LOCATION
-
-#include "xform_macros.h"
 #include "input_validators.h"
 #include "FormGraphics.h"
 #include "form_graphics.h"
 
 using std::endl;
 
-C_RETURNCB(FormGraphics, WMHideCB)
-C_GENERICCB(FormGraphics, OKCB)
-C_GENERICCB(FormGraphics, ApplyCB)
-C_GENERICCB(FormGraphics, CancelCB)
-C_GENERICCB(FormGraphics, BrowseCB)
-C_GENERICCB(FormGraphics, AdvancedOptionsCB)
-C_GENERICCB(FormGraphics, InputCB)
-
 
 FormGraphics::FormGraphics(LyXView * lv, Dialogs * d)
-               : dialog_(0), lv_(lv), d_(d), inset_(0),
-               // The buttons c-tor values are the number of buttons we use
-               // This is only to reduce memory waste.
-               widthButtons(5), heightButtons(4), displayButtons(4),
-               ih_(0), h_(0), u_(0),
-               last_image_path(".")
+       : FormInset( lv, d, _("Graphics"), new NoRepeatedApplyReadOnlyPolicy ),
+         dialog_(0), inset_(0),
+         // The buttons c-tor values are the number of buttons we use
+         // This is only to reduce memory waste.
+         widthButtons(5), heightButtons(4), displayButtons(4),
+         last_image_path(".")
 {
        // let the dialog be shown
        // This is a permanent connection so we won't bother
@@ -76,8 +64,14 @@ void FormGraphics::build()
 {
        dialog_ = build_graphics();
        Assert(dialog_ != 0);
-       if (!dialog_)
+       if (!dialog_) {
+               lyxerr << "ERROR: Failed to create the Graphics Inset dialog." << endl;
                return ;
+       }
+
+       // Workaround dumb xforms sizing bug
+       minw_ = form()->w;
+       minh_ = form()->h;
 
        // This is the place to add settings of the dialog that did not go
        // to the .fd file.
@@ -142,78 +136,39 @@ void FormGraphics::build()
        displayButtons.registerRadioButton(dialog_->radio_no_display,
                                           InsetGraphicsParams::NONE);
 
-       // Connect a signal to hide the window when the window manager orders it.
-       fl_set_form_atclose(dialog_->form,
-                           C_FormGraphicsWMHideCB, 0);
+        // manage the ok, apply and cancel/close buttons
+       bc_.setOK(dialog_->button_ok);
+       bc_.setApply(dialog_->button_apply);
+       bc_.setCancel(dialog_->button_cancel);
+       bc_.setUndoAll(0);
+       bc_.refresh();
 }
 
-void FormGraphics::show()
-{
-       // If the dialog doesn't exist yet, build it.
-       if (!dialog_) {
-               build();
-       }
 
-       // Update the form with the data from the inset.
-       update();
-
-       // If the form is visible
-       if (dialog_->form->visible) {
-               // Raise it.
-               fl_raise_form(dialog_->form);
-       } else {
-               // Otherwise (invisible), show it.
-               fl_show_form(dialog_->form,
-                            FL_PLACE_MOUSE,
-                            FL_FULLBORDER,
-                            _("Graphics"));
-
-               // And connect the signals 'updateBufferDependent',
-               // 'hideBufferDependent' and 'hideGraphics'.
-               u_ = d_->updateBufferDependent.connect(slot(this,
-                                                      &FormGraphics::update));
-               h_ = d_->hideBufferDependent.connect(slot(this,
-                                                    &FormGraphics::hide));
-       }
+FL_FORM * FormGraphics::form() const
+{
+       if ( dialog_ ) return dialog_->form;
+       return 0;
 }
 
-void FormGraphics::showDialog(InsetGraphics* inset)
+
+void FormGraphics::disconnect()
 {
-       Assert(inset != 0);
+       inset_ = 0;
+       FormInset::disconnect();
+}
 
+
+void FormGraphics::showDialog(InsetGraphics * inset)
+{
        // If we are connected to another inset, disconnect.
        if (inset_)
                ih_.disconnect();
 
        inset_ = inset;
 
-       if (inset_) {
-               ih_ = inset_->hide.connect(slot(this, &FormGraphics::hide));
-               show();
-       }
-}
-
-
-void FormGraphics::hide()
-{
-       // If the dialog exists, and the form is allocated and visible.
-       if (dialog_
-               && dialog_->form
-               && dialog_->form->visible) {
-               // Hide the form
-               fl_hide_form(dialog_->form);
-
-               // And disconnect the signals.
-               u_.disconnect();
-               h_.disconnect();
-               ih_.disconnect();
-
-               // Forget the inset.
-               inset_ = 0;
-       }
-       // Most of the time, the dialog is not needed anymore, we'll free it
-       // now to save memory.
-       free();
+       ih_ = inset_->hide.connect(slot(this, &FormGraphics::hide));
+       show();
 }
 
 
@@ -224,11 +179,13 @@ void FormGraphics::free()
        heightButtons.reset();
        displayButtons.reset();
 
+       
        // Free the form.
        delete dialog_;
        dialog_ = 0;
 }
 
+
 void FormGraphics::apply()
 {
        Assert(inset_ != 0);
@@ -272,6 +229,7 @@ void FormGraphics::apply()
        lv_->view()->updateInset(inset_, changed);
 }
 
+
 void FormGraphics::update()
 {
        Assert(inset_ != 0);
@@ -311,10 +269,37 @@ void FormGraphics::update()
                      igp.inlineFigure);
 
        // Now make sure that the buttons are set correctly.
-       input();
+       input(0, 0);
 }
 
-void FormGraphics::input()
+
+bool FormGraphics::input(FL_OBJECT *, long data )
+{
+       State cb = static_cast<State>( data );
+
+       bool inputOK = true;
+
+       switch( cb ) {
+       case CHECKINPUT:
+               inputOK = checkInput();
+               break;
+       case BROWSE:
+               browse();
+               break;
+       case ADVANCEDINPUT:
+               lyxerr << "Advanced Options button depressed, "
+                      << "show advanced options dialog"
+                      << endl;
+               break;
+       default:
+               break;
+       }
+       
+       return inputOK;
+}
+
+
+bool FormGraphics::checkInput()
 {
        // Put verifications that the dialog shows some sane values,
        // if not disallow clicking on ok/apply.
@@ -358,19 +343,7 @@ void FormGraphics::input()
                inputOK = false;
        }
 
-
-       // Now set the buttons to the correct state.
-       if (inputOK && ! lv_->buffer()->isReadonly()) {
-               fl_activate_object(dialog_->button_ok);
-               fl_activate_object(dialog_->button_apply);
-               fl_set_object_lcol(dialog_->button_ok, FL_BLACK);
-               fl_set_object_lcol(dialog_->button_apply, FL_BLACK);
-       } else {
-               fl_deactivate_object(dialog_->button_ok);
-               fl_deactivate_object(dialog_->button_apply);
-               fl_set_object_lcol(dialog_->button_ok, FL_INACTIVE);
-               fl_set_object_lcol(dialog_->button_apply, FL_INACTIVE);
-       }
+       return inputOK;
 }
 
 
@@ -379,6 +352,7 @@ extern string system_lyxdir;
 extern string user_lyxdir;
 //extern string system_tempdir;
 
+
 // Need to move this to the form_graphics
 string FormGraphics::browseFile(string const & filename)
 {
@@ -421,6 +395,7 @@ string FormGraphics::browseFile(string const & filename)
        return buf;
 }
 
+
 void FormGraphics::browse()
 {
        // Get the filename from the dialog
@@ -436,58 +411,7 @@ void FormGraphics::browse()
                // The above set input doesn't cause an input event so we do
                // it manually. Otherwise the user needs to cause an input event
                // to get the ok/apply buttons to be activated.
-               input();
+               input(0, 0);
        }
 
 }
-
-int FormGraphics::WMHideCB(FL_FORM * form, void *)
-{
-       // Ensure that the signal h is disconnected even if the
-       // window manager is used to close the dialog.
-       FormGraphics * pre = static_cast < FormGraphics* > (form->u_vdata);
-       pre->hide();
-       return FL_CANCEL;
-}
-
-
-void FormGraphics::OKCB(FL_OBJECT * ob, long)
-{
-       FormGraphics * pre = static_cast < FormGraphics* > (ob->form->u_vdata);
-       pre->apply();
-       pre->hide();
-}
-
-void FormGraphics::ApplyCB(FL_OBJECT * ob, long)
-{
-       FormGraphics * pre = static_cast < FormGraphics* > (ob->form->u_vdata);
-       pre->apply();
-}
-
-void FormGraphics::CancelCB(FL_OBJECT * ob, long)
-{
-       FormGraphics * pre = static_cast < FormGraphics* > (ob->form->u_vdata);
-       pre->hide();
-}
-
-void FormGraphics::BrowseCB(FL_OBJECT * ob, long)
-{
-       FormGraphics * pre = static_cast < FormGraphics* > (ob->form->u_vdata);
-       pre->browse();
-}
-
-void FormGraphics::AdvancedOptionsCB(FL_OBJECT * /* ob */, long)
-{
-       //  FormGraphics * pre = static_cast<FormGraphics*>(ob->form->u_vdata);
-       //      pre->showAdvancedOptions();
-       lyxerr << "Advanced Options button depressed, "
-       "show advanced options dialog"
-       << endl;
-}
-
-void FormGraphics::InputCB(FL_OBJECT * ob, long)
-{
-       FormGraphics * pre = static_cast < FormGraphics* > (ob->form->u_vdata);
-       pre->input();
-}
-