-// -*- 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>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#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 "ControlMinipage.h"
+#include "forms/form_minipage.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));
-}
+#include "xforms_helpers.h"
+#include "xformsBC.h"
+#include "controllers/helper_funcs.h"
-FL_FORM * FormMinipage::form() const
-{
- if (dialog_.get())
- return dialog_->form;
- return 0;
-}
+#include "support/lstrings.h"
+#include "support/tostr.h"
+#include "lyx_forms.h"
-void FormMinipage::connect()
-{
- bc().valid(true);
- FormBaseBD::connect();
-}
+using lyx::support::getStringFromVector;
+using lyx::support::isStrDbl;
+using lyx::support::subst;
+using std::string;
-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;
- }
+typedef FormController<ControlMinipage, FormView<FD_minipage> > base_class;
- show();
-}
+FormMinipage::FormMinipage(Dialog & parent)
+ : base_class(parent, _("Minipage Settings"))
+{}
-void FormMinipage::updateInset(InsetMinipage * inset)
+void FormMinipage::build()
{
- if (inset == 0 || 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));
- update();
-}
+ // Allow the base class to control messages
+ setMessageWidget(dialog_->text_warning);
-void FormMinipage::build()
-{
- dialog_.reset(build_minipage());
+ fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
+ setPrehandler(dialog_->input_width);
- // 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
+ bcview().setOK(dialog_->button_ok);
+ bcview().setApply(dialog_->button_apply);
+ bcview().setCancel(dialog_->button_close);
+ bcview().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();
+ bcview().addReadOnly(dialog_->input_width);
+ bcview().addReadOnly(dialog_->choice_width_units);
+ bcview().addReadOnly(dialog_->radio_top);
+ bcview().addReadOnly(dialog_->radio_middle);
+ bcview().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().width =
+ 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()) {
- 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());
+ LyXLength len(controller().params().width);
+ 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;
+ }
+}
+
+
+ButtonPolicy::SMInput FormMinipage::input(FL_OBJECT * ob, long)
+{
+ 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;
}