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
14 #include "ControlWrap.h"
16 #include "forms/form_wrap.h"
19 #include "helper_funcs.h"
20 #include "xforms_helpers.h"
21 #include "checkedwidgets.h"
23 #include "insets/insetwrap.h"
24 #include "support/lstrings.h"
25 #include "lyx_forms.h"
26 #include "support/tostr.h"
29 typedef FormController<ControlWrap, FormView<FD_wrap> > base_class;
32 FormWrap::FormWrap(Dialog & parent)
33 : base_class(parent, _("Text Wrap Settings"))
37 void FormWrap::build()
39 dialog_.reset(build_wrap(this));
41 // Manage the ok, apply and cancel/close buttons
42 bcview().setOK(dialog_->button_ok);
43 bcview().setApply(dialog_->button_apply);
44 bcview().setCancel(dialog_->button_close);
45 bcview().setRestore(dialog_->button_restore);
47 // disable for read-only documents
48 bcview().addReadOnly(dialog_->input_width);
49 bcview().addReadOnly(dialog_->choice_width_units);
51 // check validity of "length + unit" input
52 addCheckedGlueLength(bcview(), dialog_->input_width);
54 // trigger an input event for cut&paste with middle mouse button.
55 setPrehandler(dialog_->input_width);
57 fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
59 string const choice = getStringFromVector(getLatexUnits(), "|");
60 fl_addto_choice(dialog_->choice_width_units,
61 subst(choice, "%", "%%").c_str());
63 placement_.init(dialog_->radio_default, 0); // default
64 placement_.init(dialog_->radio_outer, 'p');
65 placement_.init(dialog_->radio_left, 'l');
66 placement_.init(dialog_->radio_right, 'r');
68 // set up the tooltips
69 string str = _("Enter width for the float.");
70 tooltips().init(dialog_->input_width, str);
71 str = _("Forces float to the right in a paragraph if the page number "
72 "is odd, and to the left if page number is even.");
73 tooltips().init(dialog_->radio_default, str);
74 str = _("Forces float to the left in a paragraph if the pagenumber "
75 "is odd, and to the right if page number is even.");
76 tooltips().init(dialog_->radio_outer, str);
77 str = _("Forces float to the left in the paragraph.");
78 tooltips().init(dialog_->radio_left, str);
79 str = _("Forces float to the right in the paragraph.");
80 tooltips().init(dialog_->radio_right, str);
84 void FormWrap::apply()
86 InsetWrapParams & params = controller().params();
89 LyXLength(getLengthFromWidgets(dialog_->input_width,
90 dialog_->choice_width_units));
92 char const c = static_cast<char>(placement_.get());
96 params.placement.erase(); // default
100 void FormWrap::update()
102 InsetWrapParams const & params = controller().params();
103 LyXLength len(params.width);
104 fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
105 fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
107 if (params.placement.empty())
108 placement_.set(dialog_->radio_default); // default
110 placement_.set(params.placement.c_str()[0]);