2 * \file FormParagraph.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "FormParagraph.h"
15 #include "ControlParagraph.h"
16 #include "forms/form_paragraph.h"
18 #include "checkedwidgets.h"
19 #include "input_validators.h"
21 #include "xforms_helpers.h"
24 #include "controllers/helper_funcs.h"
26 #include "lyxrc.h" // to set the deafult length values
27 #include "ParagraphParameters.h"
30 #include "support/lstrings.h"
31 #include "support/tostr.h"
33 #include "lyx_forms.h"
35 using lyx::support::contains_functor;
36 using lyx::support::getStringFromVector;
37 using lyx::support::rtrim;
48 string defaultUnit("cm");
53 typedef FormController<ControlParagraph, FormView<FD_paragraph> > base_class;
55 FormParagraph::FormParagraph(Dialog & parent)
56 : base_class(parent, _("Paragraph Settings"))
60 void FormParagraph::build()
63 dialog_.reset(build_paragraph(this));
65 // Manage the ok, apply, restore and cancel/close buttons
66 bcview().setOK(dialog_->button_ok);
67 bcview().setApply(dialog_->button_apply);
68 bcview().setCancel(dialog_->button_close);
69 bcview().setRestore(dialog_->button_restore);
71 // disable for read-only documents
72 bcview().addReadOnly(dialog_->check_noindent);
73 bcview().addReadOnly(dialog_->choice_linespacing);
74 bcview().addReadOnly(dialog_->input_linespacing);
76 bcview().addReadOnly(dialog_->input_labelwidth);
78 // trigger an input event for cut&paste with middle mouse button.
79 setPrehandler(dialog_->input_linespacing);
80 setPrehandler(dialog_->input_labelwidth);
82 fl_set_input_return(dialog_->input_labelwidth, FL_RETURN_CHANGED);
83 fl_set_input_return(dialog_->input_linespacing, FL_RETURN_CHANGED);
85 // limit these inputs to unsigned floats
86 fl_set_input_filter(dialog_->input_linespacing, fl_unsigned_float_filter);
88 // add alignment radio buttons
89 alignment_.init(dialog_->radio_align_left, LYX_ALIGN_LEFT);
90 alignment_.init(dialog_->radio_align_right, LYX_ALIGN_RIGHT);
91 alignment_.init(dialog_->radio_align_block, LYX_ALIGN_BLOCK);
92 alignment_.init(dialog_->radio_align_center, LYX_ALIGN_CENTER);
94 string const linespacing = _("Default|Single|OneHalf|Double|Custom");
95 fl_addto_choice(dialog_->choice_linespacing, linespacing.c_str());
97 // Create the contents of the unit choices; don't include the "%" terms.
98 vector<string> units_vec = getLatexUnits();
99 vector<string>::iterator del =
100 remove_if(units_vec.begin(), units_vec.end(),
101 bind2nd(contains_functor(), "%"));
102 units_vec.erase(del, units_vec.end());
104 // set default unit for custom length
105 switch (lyxrc.default_papersize) {
108 case PAPER_LEGALPAPER:
109 case PAPER_EXECUTIVEPAPER:
122 void FormParagraph::apply()
128 LyXAlignment const alignment =
129 static_cast<LyXAlignment>(alignment_.get());
130 controller().params().align(alignment);
133 string const labelwidthstring =
134 getString(dialog_->input_labelwidth);
135 controller().params().labelWidthString(labelwidthstring);
138 bool const noindent = fl_get_button(dialog_->check_noindent);
139 controller().params().noindent(noindent);
142 Spacing::Space linespacing = Spacing::Default;
144 switch (fl_get_choice(dialog_->choice_linespacing)) {
146 linespacing = Spacing::Default;
149 linespacing = Spacing::Single;
152 linespacing = Spacing::Onehalf;
155 linespacing = Spacing::Double;
158 // reset to default if input is empty
159 other = getString(dialog_->input_linespacing);
160 if (!other.empty()) {
161 linespacing = Spacing::Other;
163 linespacing = Spacing::Default;
164 fl_set_choice(dialog_->choice_linespacing, 1);
168 Spacing const spacing(linespacing, other);
169 controller().params().spacing(spacing);
173 void FormParagraph::update()
179 string const labelwidth = controller().params().labelWidthString();
180 fl_set_input(dialog_->input_labelwidth, labelwidth.c_str());
181 setEnabled(dialog_->input_labelwidth,
182 labelwidth != _("Senseless with this layout!"));
185 alignment_.set(controller().params().align());
187 // mark default alignment
188 LyXAlignment const default_alignment = controller().alignDefault();
190 string label = _("Block");
191 if (default_alignment == LYX_ALIGN_BLOCK) {
192 label += _(" (default)");
194 fl_set_object_label(dialog_->radio_align_block, label.c_str());
195 fl_set_button_shortcut(dialog_->radio_align_block, "#B", 1);
198 if (default_alignment == LYX_ALIGN_CENTER) {
199 label += _(" (default)");
201 fl_set_object_label(dialog_->radio_align_center, label.c_str());
202 fl_set_button_shortcut(dialog_->radio_align_center, "#C", 1);
205 if (default_alignment == LYX_ALIGN_LEFT) {
206 label += _(" (default)");
208 fl_set_object_label(dialog_->radio_align_left, label.c_str());
209 fl_set_button_shortcut(dialog_->radio_align_left, "#L", 1);
212 if (default_alignment == LYX_ALIGN_RIGHT) {
213 label = _(" (default)");
215 fl_set_object_label(dialog_->radio_align_right, label.c_str());
216 fl_set_button_shortcut(dialog_->radio_align_right, "#R", 1);
218 // Ensure that there's no crud left on the screen from this change
220 fl_redraw_form(form());
222 LyXAlignment alignpos = controller().alignPossible();
223 setEnabled(dialog_->radio_align_block,
224 bool(alignpos & LYX_ALIGN_BLOCK));
225 setEnabled(dialog_->radio_align_center,
226 bool(alignpos & LYX_ALIGN_CENTER));
227 setEnabled(dialog_->radio_align_left,
228 bool(alignpos & LYX_ALIGN_LEFT));
229 setEnabled(dialog_->radio_align_right,
230 bool(alignpos & LYX_ALIGN_RIGHT));
232 // lines, pagebreaks and indent
233 fl_set_button(dialog_->check_noindent,
234 controller().params().noindent());
237 Spacing const space = controller().params().spacing();
240 switch (space.getSpace()) {
244 case Spacing::Double:
247 case Spacing::Onehalf:
250 case Spacing::Single:
253 case Spacing::Default:
258 fl_set_choice(dialog_->choice_linespacing, pos);
260 bool const spacing_other = space.getSpace() == Spacing::Other;
261 setEnabled(dialog_->input_linespacing, spacing_other);
263 string const sp = tostr(space.getValue());
264 fl_set_input(dialog_->input_linespacing, sp.c_str());
266 fl_set_input(dialog_->input_linespacing, "");
270 fl_set_button(dialog_->check_noindent,
271 controller().params().noindent());
275 ButtonPolicy::SMInput FormParagraph::input(FL_OBJECT * ob, long)
277 // Enable input when custum length is choosen,
278 // disable 'keep' when no space is choosen
279 if (ob == dialog_->choice_linespacing) {
280 bool const custom_spacing =
281 fl_get_choice(dialog_->choice_linespacing) == 5;
282 setEnabled(dialog_->input_linespacing, custom_spacing);
285 return ButtonPolicy::SMI_VALID;