]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormWrap.C
Introduce LFUN_PRINT.
[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 lyx::support::getStringFromVector;
29 using lyx::support::subst;
30
31 using std::string;
32
33
34 typedef FormController<ControlWrap, FormView<FD_wrap> > base_class;
35
36 FormWrap::FormWrap(Dialog & parent)
37         : base_class(parent, _("Text Wrap Settings"))
38 {}
39
40
41 void FormWrap::build()
42 {
43         dialog_.reset(build_wrap(this));
44
45         // Manage the ok, apply and cancel/close buttons
46         bcview().setOK(dialog_->button_ok);
47         bcview().setApply(dialog_->button_apply);
48         bcview().setCancel(dialog_->button_close);
49         bcview().setRestore(dialog_->button_restore);
50
51         // disable for read-only documents
52         bcview().addReadOnly(dialog_->input_width);
53         bcview().addReadOnly(dialog_->choice_width_units);
54
55         // check validity of "length + unit" input
56         addCheckedGlueLength(bcview(), dialog_->input_width);
57
58         // trigger an input event for cut&paste with middle mouse button.
59         setPrehandler(dialog_->input_width);
60
61         fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
62
63         string const choice = getStringFromVector(getLatexUnits(), "|");
64         fl_addto_choice(dialog_->choice_width_units,
65                         subst(choice, "%", "%%").c_str());
66
67         placement_.init(dialog_->radio_default, 0); // default
68         placement_.init(dialog_->radio_outer, 'p');
69         placement_.init(dialog_->radio_left,  'l');
70         placement_.init(dialog_->radio_right, 'r');
71
72         // set up the tooltips
73         string str = _("Enter width for the float.");
74         tooltips().init(dialog_->input_width, str);
75         str = _("Forces float to the right in a paragraph if the page number "
76                 "is odd, and to the left if page number is even.");
77         tooltips().init(dialog_->radio_default, str);
78         str = _("Forces float to the left in a paragraph if the pagenumber "
79                 "is odd, and to the right if page number is even.");
80         tooltips().init(dialog_->radio_outer, str);
81         str = _("Forces float to the left in the paragraph.");
82         tooltips().init(dialog_->radio_left, str);
83         str = _("Forces float to the right in the paragraph.");
84         tooltips().init(dialog_->radio_right, str);
85 }
86
87
88 void FormWrap::apply()
89 {
90         InsetWrapParams & params = controller().params();
91
92         params.width =
93                 LyXLength(getLengthFromWidgets(dialog_->input_width,
94                                                dialog_->choice_width_units));
95
96         char const c = static_cast<char>(placement_.get());
97         if (c)
98                 params.placement = c;
99         else
100                 params.placement.erase(); // default
101 }
102
103
104 void FormWrap::update()
105 {
106         InsetWrapParams const & params = controller().params();
107         LyXLength len(params.width);
108         fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
109         fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
110
111         if (params.placement.empty())
112                 placement_.set(dialog_->radio_default); // default
113         else
114                 placement_.set(params.placement.c_str()[0]);
115 }