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