]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormMinipage.C
fix crash with "save as"
[lyx.git] / src / frontends / xforms / FormMinipage.C
index 62c4e3e96388342508aab8642bbe98cf8ab33e2d..ef1c3efd4aa667bf85eda3c6f092bc5cfcf7b990 100644 (file)
@@ -1,15 +1,11 @@
-// -*- C++ -*-
-/* This file is part of
- * ====================================================== 
+/**
+ * \file FormMinipage.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Jürgen Vigna
  *
- *           Copyright 2000 The LyX Team.
- *
- * ======================================================
- */
-/* FormMinipage.C
- * FormMinipage Interface Class Implementation
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
 #pragma implementation
 #endif
 
+#include "xformsBC.h"
+#include "ControlMinipage.h"
 #include "FormMinipage.h"
-#include "form_minipage.h"
-#include "Dialogs.h"
-#include "LyXView.h"
-#include "buffer.h"
-#include "insets/insetminipage.h"
+#include "forms/form_minipage.h"
 #include "support/lstrings.h"
+#include "helper_funcs.h"
+#include "debug.h"
+#include "xforms_helpers.h"
+#include FORMS_H_LOCATION
 
-FormMinipage::FormMinipage(LyXView * lv, Dialogs * d)
-       : FormInset(lv, d, _("Minipage Options")),
-         inset_(0)
-{
-    // let the dialog be shown
-    // This is a permanent connection so we won't bother
-    // storing a copy because we won't be disconnecting.
-    d->showMinipage.connect(SigC::slot(this, &FormMinipage::showInset));
-    d->updateMinipage.connect(SigC::slot(this, &FormMinipage::updateInset));
-}
+typedef FormCB<ControlMinipage, FormDB<FD_minipage> > base_class;
 
-
-FL_FORM * FormMinipage::form() const
-{
-    if (dialog_.get())
-       return dialog_->form;
-    return 0;
-}
+FormMinipage::FormMinipage()
+       : base_class(_("Minipage Options"))
+{}
 
 
-void FormMinipage::connect()
-{
-    bc().valid(true);
-    FormBaseBD::connect();
-}
-
-
-void FormMinipage::showInset(InsetMinipage * inset)
+void FormMinipage::build()
 {
-    if (inset == 0) return;
-
-    // If connected to another inset, disconnect from it.
-    if (inset_ != inset) {
-       ih_.disconnect();
-       ih_ = inset->hideDialog.connect(SigC::slot(this, &FormMinipage::hide));
-       inset_ = inset;
-    }
+       dialog_.reset(build_minipage(this));
 
-    show();
-}
+       // Allow the base class to control messages
+       setMessageWidget(dialog_->text_warning);
 
+       fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
+       setPrehandler(dialog_->input_width);
 
-void FormMinipage::updateInset(InsetMinipage * inset)
-{
-    if (inset == 0 || inset_ == 0) return;
+       string const choice = getStringFromVector(getLatexUnits(), "|");
+       fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str());
 
-    // If connected to another inset, disconnect from it.
-    if (inset_ != inset) {
-       ih_.disconnect();
-       ih_ = inset->hideDialog.connect(SigC::slot(this, &FormMinipage::hide));
-       inset_ = inset;
-    }
+       // Manage the ok, apply and cancel/close buttons
+       bc().setOK(dialog_->button_ok);
+       bc().setApply(dialog_->button_apply);
+       bc().setCancel(dialog_->button_close);
+       bc().setRestore(dialog_->button_restore);
 
-    update();
+       bc().addReadOnly(dialog_->input_width);
+       bc().addReadOnly(dialog_->choice_width_units);
+       bc().addReadOnly(dialog_->radio_top);
+       bc().addReadOnly(dialog_->radio_middle);
+       bc().addReadOnly(dialog_->radio_bottom);
 }
 
-void FormMinipage::build()
-{
-    dialog_.reset(build_minipage());
 
-    // Workaround dumb xforms sizing bug
-    minw_ = form()->w;
-    minh_ = form()->h;
-
-    fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
-    fl_set_input_return(dialog_->input_widthp, FL_RETURN_CHANGED);
-
-    // Manage the ok, apply and cancel/close buttons
-    bc().setOK(dialog_->button_ok);
-    bc().setApply(dialog_->button_apply);
-    bc().setCancel(dialog_->button_cancel);
-    bc().refresh();
+void FormMinipage::apply()
+{
+       controller().params().pageWidth =
+               LyXLength(getLengthFromWidgets(dialog_->input_width,
+                                              dialog_->choice_width_units));
+
+       if (fl_get_button(dialog_->radio_top))
+               controller().params().pos = InsetMinipage::top;
+       else if (fl_get_button(dialog_->radio_middle))
+               controller().params().pos = InsetMinipage::center;
+       else
+               controller().params().pos = InsetMinipage::bottom;
 }
 
 
-void FormMinipage::apply()
+void FormMinipage::update()
 {
-#if 0
-    int ysize = int(fl_get_slider_value(dialog_->slider_columns) + 0.5);
-    int xsize = int(fl_get_slider_value(dialog_->slider_rows) + 0.5);
-
-    string tmp = tostr(xsize) + " " + tostr(ysize);
-    lv_->getLyXFunc()->Dispatch(LFUN_INSET_TABULAR, tmp);
-#endif
+       LyXLength len(controller().params().pageWidth);
+       fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
+       fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
+
+       switch (controller().params().pos) {
+       case InsetMinipage::top:
+               fl_set_button(dialog_->radio_top, 1);
+               break;
+       case InsetMinipage::center:
+               fl_set_button(dialog_->radio_middle, 1);
+               break;
+       case InsetMinipage::bottom:
+               fl_set_button(dialog_->radio_bottom, 1);
+               break;
+       }
 }
 
 
-void FormMinipage::update()
+ButtonPolicy::SMInput FormMinipage::input(FL_OBJECT * ob, long)
 {
-    if (!inset_)
-       return;
-    fl_set_input(dialog_->input_width, inset_->width().c_str());
-    fl_set_input(dialog_->input_widthp, tostr(inset_->widthp()).c_str());
-                
-    switch (inset_->pos()) {
-    case InsetMinipage::top:
-       fl_set_button(dialog_->radio_top, 1);
-       break;
-    case InsetMinipage::center:
-       fl_set_button(dialog_->radio_middle, 1);
-       break;
-    case InsetMinipage::bottom:
-       fl_set_button(dialog_->radio_bottom, 1);
-       break;
-    }
-    bc().readOnly(lv_->buffer()->isReadonly());
+       clearMessage();
+
+       ButtonPolicy::SMInput action = ButtonPolicy::SMI_NOOP;
+
+       if (ob == dialog_->radio_top ||
+           ob == dialog_->radio_middle ||
+           ob == dialog_->radio_bottom ||
+           ob == dialog_->choice_width_units)
+               return ButtonPolicy::SMI_VALID;
+
+       // disallow senseless data
+       // warnings if input is senseless
+       if (ob == dialog_->input_width) {
+               string const input = getString(dialog_->input_width);
+               bool const invalid = !isValidLength(input) && !isStrDbl(input);
+               if (invalid) {
+                       postWarning(_("Invalid Length!"));
+                       action = ButtonPolicy::SMI_INVALID;
+               } else {
+                       action = ButtonPolicy::SMI_VALID;
+               }
+       }
+
+       return action;
 }