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