]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormMinipage.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / FormMinipage.C
index 62c4e3e96388342508aab8642bbe98cf8ab33e2d..4e9ec3a12645f46e548a2f353cbde73db341ceef 100644 (file)
@@ -1,15 +1,14 @@
-// -*- C++ -*-
 /* This file is part of
  * ====================================================== 
  *
  *           LyX, The Document Processor
  *
- *           Copyright 2000 The LyX Team.
+ *           Copyright 2001 The LyX Team.
  *
  * ======================================================
- */
-/* FormMinipage.C
- * FormMinipage Interface Class Implementation
+ *
+ * \file FormMinipage.C
+ * \author Jürgen Vigna, jug@sad.it
  */
 
 #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 "support/lstrings.h"
+#include "helper_funcs.h"
+#include "debug.h"
+#include "xforms_helpers.h"
 
-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));
-}
-
-
-FL_FORM * FormMinipage::form() const
-{
-    if (dialog_.get())
-       return dialog_->form;
-    return 0;
-}
-
-
-void FormMinipage::connect()
-{
-    bc().valid(true);
-    FormBaseBD::connect();
-}
-
-
-void FormMinipage::showInset(InsetMinipage * inset)
-{
-    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;
-    }
-
-    show();
-}
-
-
-void FormMinipage::updateInset(InsetMinipage * inset)
-{
-    if (inset == 0 || inset_ == 0) return;
+typedef FormCB<ControlMinipage, FormDB<FD_form_minipage> > base_class;
 
-    // If connected to another inset, disconnect from it.
-    if (inset_ != inset) {
-       ih_.disconnect();
-       ih_ = inset->hideDialog.connect(SigC::slot(this, &FormMinipage::hide));
-       inset_ = inset;
-    }
+FormMinipage::FormMinipage(ControlMinipage & c)
+       : base_class(c, _("Minipage Options"))
+{}
 
-    update();
-}
 
 void FormMinipage::build()
 {
-    dialog_.reset(build_minipage());
+       dialog_.reset(build_minipage());
+
+       fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
 
-    // Workaround dumb xforms sizing bug
-    minw_ = form()->w;
-    minh_ = form()->h;
+       string const choice = getStringFromVector(getLatexUnits(), "|");
+       fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str());
 
-    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().setRestore(dialog_->button_restore);
 
-    // 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();
+       bc().addReadOnly(dialog_->input_width);
+       bc().addReadOnly(dialog_->choice_width_units);
+       bc().addReadOnly(dialog_->group_alignment);
+       bc().addReadOnly(dialog_->radio_top);
+       bc().addReadOnly(dialog_->radio_middle);
+       bc().addReadOnly(dialog_->radio_bottom);
 }
 
 
 void FormMinipage::apply()
 {
-#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
+       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::update()
 {
-    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()) {
+    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;
@@ -131,5 +89,4 @@ void FormMinipage::update()
        fl_set_button(dialog_->radio_bottom, 1);
        break;
     }
-    bc().readOnly(lv_->buffer()->isReadonly());
 }