]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormWrap.C
If I ever see another licence blurb again, it'll be too soon...
[lyx.git] / src / frontends / xforms / FormWrap.C
1 /**
2  * \file FormWrap.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Dekel Tsur
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "xformsBC.h"
14 #include "ControlWrap.h"
15 #include "FormWrap.h"
16 #include "forms/form_wrap.h"
17 #include "Tooltips.h"
18
19 #include "helper_funcs.h"
20 #include "xforms_helpers.h"
21 #include "checkedwidgets.h"
22
23 #include "insets/insetwrap.h"
24 #include "support/lstrings.h"
25 #include "lyx_forms.h"
26 #include "support/tostr.h"
27
28 using namespace lyx::support;
29
30 typedef FormController<ControlWrap, FormView<FD_wrap> > base_class;
31
32
33 FormWrap::FormWrap(Dialog & parent)
34         : base_class(parent, _("Text Wrap Settings"))
35 {}
36
37
38 void FormWrap::build()
39 {
40         dialog_.reset(build_wrap(this));
41
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);
47
48         // disable for read-only documents
49         bcview().addReadOnly(dialog_->input_width);
50         bcview().addReadOnly(dialog_->choice_width_units);
51
52         // check validity of "length + unit" input
53         addCheckedGlueLength(bcview(), dialog_->input_width);
54
55         // trigger an input event for cut&paste with middle mouse button.
56         setPrehandler(dialog_->input_width);
57
58         fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
59
60         string const choice = getStringFromVector(getLatexUnits(), "|");
61         fl_addto_choice(dialog_->choice_width_units,
62                         subst(choice, "%", "%%").c_str());
63
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');
68
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);
82 }
83
84
85 void FormWrap::apply()
86 {
87         InsetWrapParams & params = controller().params();
88
89         params.width =
90                 LyXLength(getLengthFromWidgets(dialog_->input_width,
91                                                dialog_->choice_width_units));
92
93         char const c = static_cast<char>(placement_.get());
94         if (c)
95                 params.placement = c;
96         else
97                 params.placement.erase(); // default
98 }
99
100
101 void FormWrap::update()
102 {
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);
107
108         if (params.placement.empty())
109                 placement_.set(dialog_->radio_default); // default
110         else
111                 placement_.set(params.placement.c_str()[0]);
112 }