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