3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
15 #include "ControlWrap.h"
17 #include "forms/form_wrap.h"
20 #include "support/lstrings.h"
21 #include "helper_funcs.h"
22 #include "xforms_helpers.h"
23 #include "checkedwidgets.h"
25 #include FORMS_H_LOCATION
27 typedef FormCB<ControlWrap, FormDB<FD_wrap> > base_class;
30 : base_class(_("Wrap Options"))
34 void FormWrap::build()
36 dialog_.reset(build_wrap(this));
38 // Manage the ok, apply and cancel/close buttons
39 bc().setOK(dialog_->button_ok);
40 bc().setApply(dialog_->button_apply);
41 bc().setCancel(dialog_->button_close);
42 bc().setRestore(dialog_->button_restore);
44 // disable for read-only documents
45 bc().addReadOnly(dialog_->input_width);
46 bc().addReadOnly(dialog_->choice_width_units);
48 // check validity of "length + unit" input
49 addCheckedGlueLength(bc(), dialog_->input_width);
51 // trigger an input event for cut&paste with middle mouse button.
52 setPrehandler(dialog_->input_width);
54 fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
56 string const choice = getStringFromVector(getLatexUnits(), "|");
57 fl_addto_choice(dialog_->choice_width_units,
58 subst(choice, "%", "%%").c_str());
60 placement_.init(dialog_->radio_default, 0); // default
61 placement_.init(dialog_->radio_outer, 'p');
62 placement_.init(dialog_->radio_left, 'l');
63 placement_.init(dialog_->radio_right, 'r');
65 // set up the tooltips
66 string str = _("Enter width for the float.");
67 tooltips().init(dialog_->input_width, str);
68 str = _("Forces float to the right in a paragraph if the page number "
69 "is odd, and to the left if page number is even.");
70 tooltips().init(dialog_->radio_default, str);
71 str = _("Forces float to the left in a paragraph if the pagenumber "
72 "is odd, and to the right if page number is even.");
73 tooltips().init(dialog_->radio_outer, str);
74 str = _("Forces float to the left in the paragraph.");
75 tooltips().init(dialog_->radio_left, str);
76 str = _("Forces float to the right in the paragraph.");
77 tooltips().init(dialog_->radio_right, str);
81 void FormWrap::apply()
83 controller().params().pageWidth =
84 LyXLength(getLengthFromWidgets(dialog_->input_width,
85 dialog_->choice_width_units));
87 char const c = static_cast<char>(placement_.get());
89 controller().params().placement = c;
91 controller().params().placement.erase(); // default
95 void FormWrap::update()
97 LyXLength len(controller().params().pageWidth);
98 fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
99 fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
101 if (controller().params().placement.empty())
102 placement_.set(dialog_->radio_default); // default
104 placement_.set(controller().params().placement.c_str()[0]);