X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2FFormWrap.C;h=37788f02026d9c819649869f947be8d485c44de9;hb=37e82a546392d43f787826b85481a11f2a27af15;hp=17f99ef5b78eb3ce04e8193910352ee50a81ddaf;hpb=bc56bb9ffadbdf457153547851986cf867d22aa1;p=lyx.git diff --git a/src/frontends/xforms/FormWrap.C b/src/frontends/xforms/FormWrap.C index 17f99ef5b7..37788f0202 100644 --- a/src/frontends/xforms/FormWrap.C +++ b/src/frontends/xforms/FormWrap.C @@ -5,29 +5,39 @@ * * \author Dekel Tsur * - * Full author contact details are available in file CREDITS + * Full author contact details are available in file CREDITS. */ #include -#ifdef __GNUG__ -#pragma implementation -#endif - #include "xformsBC.h" #include "ControlWrap.h" #include "FormWrap.h" #include "forms/form_wrap.h" -#include "support/lstrings.h" +#include "Tooltips.h" + #include "helper_funcs.h" -#include "debug.h" #include "xforms_helpers.h" -#include FORMS_H_LOCATION +#include "checkedwidgets.h" + +#include "insets/insetwrap.h" +#include "support/lstrings.h" +#include "lyx_forms.h" +#include "support/tostr.h" + +using std::string; -typedef FormCB > base_class; +namespace lyx { -FormWrap::FormWrap() - : base_class(_("Wrap Options")) +using support::getStringFromVector; +using support::subst; + +namespace frontend { + +typedef FormController > base_class; + +FormWrap::FormWrap(Dialog & parent) + : base_class(parent, _("Text Wrap Settings")) {} @@ -35,89 +45,77 @@ void FormWrap::build() { dialog_.reset(build_wrap(this)); - // Allow the base class to control messages - setMessageWidget(dialog_->text_warning); + // 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); - fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED); + // disable for read-only documents + bcview().addReadOnly(dialog_->input_width); + bcview().addReadOnly(dialog_->choice_width_units); + + // check validity of "length + unit" input + addCheckedGlueLength(bcview(), dialog_->input_width); + + // trigger an input event for cut&paste with middle mouse button. setPrehandler(dialog_->input_width); - 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); - // 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); - - bc().addReadOnly(dialog_->input_width); - bc().addReadOnly(dialog_->choice_width_units); - bc().addReadOnly(dialog_->radio_left); - bc().addReadOnly(dialog_->radio_right); - bc().addReadOnly(dialog_->radio_inner); - bc().addReadOnly(dialog_->radio_default); + string const choice = getStringFromVector(getLatexUnits(), "|"); + fl_addto_choice(dialog_->choice_width_units, + subst(choice, "%", "%%").c_str()); + + placement_.init(dialog_->radio_default, 0); // default + placement_.init(dialog_->radio_outer, 'p'); + placement_.init(dialog_->radio_left, 'l'); + placement_.init(dialog_->radio_right, 'r'); + + // set up the tooltips + string str = _("Enter width for the float."); + tooltips().init(dialog_->input_width, str); + str = _("Forces float to the right in a paragraph if the page number " + "is odd, and to the left if page number is even."); + tooltips().init(dialog_->radio_default, str); + str = _("Forces float to the left in a paragraph if the pagenumber " + "is odd, and to the right if page number is even."); + tooltips().init(dialog_->radio_outer, str); + str = _("Forces float to the left in the paragraph."); + tooltips().init(dialog_->radio_left, str); + str = _("Forces float to the right in the paragraph."); + tooltips().init(dialog_->radio_right, str); } void FormWrap::apply() { - controller().params().pageWidth = + InsetWrapParams & params = controller().params(); + + params.width = LyXLength(getLengthFromWidgets(dialog_->input_width, dialog_->choice_width_units)); - if (fl_get_button(dialog_->radio_left)) - controller().params().placement = "l"; - else if (fl_get_button(dialog_->radio_right)) - controller().params().placement = "r"; - else if (fl_get_button(dialog_->radio_inner)) - controller().params().placement = "p"; + char const c = static_cast(placement_.get()); + if (c) + params.placement = c; else - controller().params().placement.erase(); + params.placement.erase(); // default } void FormWrap::update() { - LyXLength len(controller().params().pageWidth); + InsetWrapParams const & params = controller().params(); + LyXLength len(params.width); fl_set_input(dialog_->input_width, tostr(len.value()).c_str()); fl_set_choice(dialog_->choice_width_units, len.unit() + 1); - if (controller().params().placement == "l") - fl_set_button(dialog_->radio_left, 1); - else if (controller().params().placement == "r") - fl_set_button(dialog_->radio_right, 1); - else if (controller().params().placement == "p") - fl_set_button(dialog_->radio_inner, 1); + if (params.placement.empty()) + placement_.set(dialog_->radio_default); // default else - fl_set_button(dialog_->radio_default, 1); + placement_.set(params.placement.c_str()[0]); } - -ButtonPolicy::SMInput FormWrap::input(FL_OBJECT * ob, long) -{ - clearMessage(); - - ButtonPolicy::SMInput action = ButtonPolicy::SMI_NOOP; - - if (ob == dialog_->radio_left || - ob == dialog_->radio_right || - ob == dialog_->radio_inner || - ob == dialog_->radio_default || - 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; -} +} // namespace frontend +} // namespace lyx