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/convert.h"
33 #include "lyx_forms.h"
35 #include <boost/bind.hpp>
46 using support::contains;
47 using support::getStringFromVector;
54 string defaultUnit("cm");
59 typedef FormController<ControlParagraph, FormView<FD_paragraph> > base_class;
61 FormParagraph::FormParagraph(Dialog & parent)
62 : base_class(parent, _("Paragraph Settings"))
66 void FormParagraph::build()
69 dialog_.reset(build_paragraph(this));
71 // Manage the ok, apply, restore and cancel/close buttons
72 bcview().setOK(dialog_->button_ok);
73 bcview().setApply(dialog_->button_apply);
74 bcview().setCancel(dialog_->button_close);
75 bcview().setRestore(dialog_->button_restore);
77 // disable for read-only documents
78 bcview().addReadOnly(dialog_->check_noindent);
79 bcview().addReadOnly(dialog_->choice_linespacing);
80 bcview().addReadOnly(dialog_->input_linespacing);
82 bcview().addReadOnly(dialog_->input_labelwidth);
84 // trigger an input event for cut&paste with middle mouse button.
85 setPrehandler(dialog_->input_linespacing);
86 setPrehandler(dialog_->input_labelwidth);
88 fl_set_input_return(dialog_->input_labelwidth, FL_RETURN_CHANGED);
89 fl_set_input_return(dialog_->input_linespacing, FL_RETURN_CHANGED);
91 // limit these inputs to unsigned floats
92 fl_set_input_filter(dialog_->input_linespacing, fl_unsigned_float_filter);
94 // add alignment radio buttons
95 alignment_.init(dialog_->radio_align_left, LYX_ALIGN_LEFT);
96 alignment_.init(dialog_->radio_align_right, LYX_ALIGN_RIGHT);
97 alignment_.init(dialog_->radio_align_block, LYX_ALIGN_BLOCK);
98 alignment_.init(dialog_->radio_align_center, LYX_ALIGN_CENTER);
100 string const linespacing = _("Default|Single|OneHalf|Double|Custom");
101 fl_addto_choice(dialog_->choice_linespacing, linespacing.c_str());
103 // Create the contents of the unit choices; don't include the "%" terms.
104 vector<string> units_vec = getLatexUnits();
105 vector<string>::iterator del =
106 remove_if(units_vec.begin(), units_vec.end(),
107 bind(contains<char>, _1, '%'));
108 units_vec.erase(del, units_vec.end());
110 // set default unit for custom length
111 switch (lyxrc.default_papersize) {
115 case PAPER_USEXECUTIVE:
128 void FormParagraph::apply()
134 LyXAlignment const alignment =
135 static_cast<LyXAlignment>(alignment_.get());
136 controller().params().align(alignment);
139 string const labelwidthstring =
140 getString(dialog_->input_labelwidth);
141 controller().params().labelWidthString(labelwidthstring);
144 bool const noindent = fl_get_button(dialog_->check_noindent);
145 controller().params().noindent(noindent);
148 Spacing::Space linespacing = Spacing::Default;
150 switch (fl_get_choice(dialog_->choice_linespacing)) {
152 linespacing = Spacing::Default;
155 linespacing = Spacing::Single;
158 linespacing = Spacing::Onehalf;
161 linespacing = Spacing::Double;
164 // reset to default if input is empty
165 other = getString(dialog_->input_linespacing);
166 if (!other.empty()) {
167 linespacing = Spacing::Other;
169 linespacing = Spacing::Default;
170 fl_set_choice(dialog_->choice_linespacing, 1);
174 Spacing const spacing(linespacing, other);
175 controller().params().spacing(spacing);
179 void FormParagraph::update()
185 string const labelwidth = controller().params().labelWidthString();
186 fl_set_input(dialog_->input_labelwidth, labelwidth.c_str());
187 setEnabled(dialog_->input_labelwidth,
188 labelwidth != _("Senseless with this layout!"));
191 alignment_.set(controller().params().align());
193 // mark default alignment
194 LyXAlignment const default_alignment = controller().alignDefault();
196 string label = _("Block");
197 if (default_alignment == LYX_ALIGN_BLOCK) {
198 label += _(" (default)");
200 fl_set_object_label(dialog_->radio_align_block, label.c_str());
201 fl_set_button_shortcut(dialog_->radio_align_block, "#B", 1);
204 if (default_alignment == LYX_ALIGN_CENTER) {
205 label += _(" (default)");
207 fl_set_object_label(dialog_->radio_align_center, label.c_str());
208 fl_set_button_shortcut(dialog_->radio_align_center, "#C", 1);
211 if (default_alignment == LYX_ALIGN_LEFT) {
212 label += _(" (default)");
214 fl_set_object_label(dialog_->radio_align_left, label.c_str());
215 fl_set_button_shortcut(dialog_->radio_align_left, "#L", 1);
218 if (default_alignment == LYX_ALIGN_RIGHT) {
219 label = _(" (default)");
221 fl_set_object_label(dialog_->radio_align_right, label.c_str());
222 fl_set_button_shortcut(dialog_->radio_align_right, "#R", 1);
224 // Ensure that there's no crud left on the screen from this change
226 fl_redraw_form(form());
228 LyXAlignment alignpos = controller().alignPossible();
229 setEnabled(dialog_->radio_align_block,
230 bool(alignpos & LYX_ALIGN_BLOCK));
231 setEnabled(dialog_->radio_align_center,
232 bool(alignpos & LYX_ALIGN_CENTER));
233 setEnabled(dialog_->radio_align_left,
234 bool(alignpos & LYX_ALIGN_LEFT));
235 setEnabled(dialog_->radio_align_right,
236 bool(alignpos & LYX_ALIGN_RIGHT));
238 // lines, pagebreaks and indent
239 fl_set_button(dialog_->check_noindent,
240 controller().params().noindent());
243 Spacing const space = controller().params().spacing();
246 switch (space.getSpace()) {
250 case Spacing::Double:
253 case Spacing::Onehalf:
256 case Spacing::Single:
259 case Spacing::Default:
264 fl_set_choice(dialog_->choice_linespacing, pos);
266 bool const spacing_other = space.getSpace() == Spacing::Other;
267 setEnabled(dialog_->input_linespacing, spacing_other);
269 fl_set_input(dialog_->input_linespacing,
270 space.getValueAsString().c_str());
272 fl_set_input(dialog_->input_linespacing, "");
276 fl_set_button(dialog_->check_noindent,
277 controller().params().noindent());
281 ButtonPolicy::SMInput FormParagraph::input(FL_OBJECT * ob, long)
283 // Enable input when custum length is choosen,
284 // disable 'keep' when no space is choosen
285 if (ob == dialog_->choice_linespacing) {
286 bool const custom_spacing =
287 fl_get_choice(dialog_->choice_linespacing) == 5;
288 setEnabled(dialog_->input_linespacing, custom_spacing);
291 return ButtonPolicy::SMI_VALID;
294 } // namespace frontend