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"
28 using namespace lyx::support;
30 typedef FormController<ControlWrap, FormView<FD_wrap> > base_class;
33 FormWrap::FormWrap(Dialog & parent)
34 : base_class(parent, _("Text Wrap Settings"))
38 void FormWrap::build()
40 dialog_.reset(build_wrap(this));
42 // Manage the ok, apply and cancel/close buttons
43 bcview().setOK(dialog_->button_ok);
44 bcview().setApply(dialog_->button_apply);
45 bcview().setCancel(dialog_->button_close);
46 bcview().setRestore(dialog_->button_restore);
48 // disable for read-only documents
49 bcview().addReadOnly(dialog_->input_width);
50 bcview().addReadOnly(dialog_->choice_width_units);
52 // check validity of "length + unit" input
53 addCheckedGlueLength(bcview(), dialog_->input_width);
55 // trigger an input event for cut&paste with middle mouse button.
56 setPrehandler(dialog_->input_width);
58 fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
60 string const choice = getStringFromVector(getLatexUnits(), "|");
61 fl_addto_choice(dialog_->choice_width_units,
62 subst(choice, "%", "%%").c_str());
64 placement_.init(dialog_->radio_default, 0); // default
65 placement_.init(dialog_->radio_outer, 'p');
66 placement_.init(dialog_->radio_left, 'l');
67 placement_.init(dialog_->radio_right, 'r');
69 // set up the tooltips
70 string str = _("Enter width for the float.");
71 tooltips().init(dialog_->input_width, str);
72 str = _("Forces float to the right in a paragraph if the page number "
73 "is odd, and to the left if page number is even.");
74 tooltips().init(dialog_->radio_default, str);
75 str = _("Forces float to the left in a paragraph if the pagenumber "
76 "is odd, and to the right if page number is even.");
77 tooltips().init(dialog_->radio_outer, str);
78 str = _("Forces float to the left in the paragraph.");
79 tooltips().init(dialog_->radio_left, str);
80 str = _("Forces float to the right in the paragraph.");
81 tooltips().init(dialog_->radio_right, str);
85 void FormWrap::apply()
87 InsetWrapParams & params = controller().params();
90 LyXLength(getLengthFromWidgets(dialog_->input_width,
91 dialog_->choice_width_units));
93 char const c = static_cast<char>(placement_.get());
97 params.placement.erase(); // default
101 void FormWrap::update()
103 InsetWrapParams const & params = controller().params();
104 LyXLength len(params.width);
105 fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
106 fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
108 if (params.placement.empty())
109 placement_.set(dialog_->radio_default); // default
111 placement_.set(params.placement.c_str()[0]);