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;
52 typedef FormController<ControlParagraph, FormView<FD_paragraph> > base_class;
54 FormParagraph::FormParagraph(Dialog & parent)
55 : base_class(parent, _("Paragraph Settings"))
59 void FormParagraph::build()
62 dialog_.reset(build_paragraph(this));
64 // Manage the ok, apply, restore and cancel/close buttons
65 bcview().setOK(dialog_->button_ok);
66 bcview().setApply(dialog_->button_apply);
67 bcview().setCancel(dialog_->button_close);
68 bcview().setRestore(dialog_->button_restore);
70 // disable for read-only documents
71 bcview().addReadOnly(dialog_->check_noindent);
72 bcview().addReadOnly(dialog_->choice_linespacing);
73 bcview().addReadOnly(dialog_->input_linespacing);
75 bcview().addReadOnly(dialog_->input_labelwidth);
77 // trigger an input event for cut&paste with middle mouse button.
78 setPrehandler(dialog_->input_linespacing);
79 setPrehandler(dialog_->input_labelwidth);
81 fl_set_input_return(dialog_->input_labelwidth, FL_RETURN_CHANGED);
82 fl_set_input_return(dialog_->input_linespacing, FL_RETURN_CHANGED);
84 // limit these inputs to unsigned floats
85 fl_set_input_filter(dialog_->input_linespacing, fl_unsigned_float_filter);
87 // add alignment radio buttons
88 alignment_.init(dialog_->radio_align_left, LYX_ALIGN_LEFT);
89 alignment_.init(dialog_->radio_align_right, LYX_ALIGN_RIGHT);
90 alignment_.init(dialog_->radio_align_block, LYX_ALIGN_BLOCK);
91 alignment_.init(dialog_->radio_align_center, LYX_ALIGN_CENTER);
93 string const linespacing = _("Default|Single|OneHalf|Double|Custom");
94 fl_addto_choice(dialog_->choice_linespacing, linespacing.c_str());
96 // Create the contents of the unit choices; don't include the "%" terms.
97 vector<string> units_vec = getLatexUnits();
98 vector<string>::iterator del =
99 remove_if(units_vec.begin(), units_vec.end(),
100 bind(contains<char>, _1, '%'));
101 units_vec.erase(del, units_vec.end());
105 void FormParagraph::apply()
111 LyXAlignment const alignment =
112 static_cast<LyXAlignment>(alignment_.get());
113 controller().params().align(alignment);
116 string const labelwidthstring =
117 getString(dialog_->input_labelwidth);
118 controller().params().labelWidthString(labelwidthstring);
121 bool const noindent = fl_get_button(dialog_->check_noindent);
122 controller().params().noindent(noindent);
125 Spacing::Space linespacing = Spacing::Default;
127 switch (fl_get_choice(dialog_->choice_linespacing)) {
129 linespacing = Spacing::Default;
132 linespacing = Spacing::Single;
135 linespacing = Spacing::Onehalf;
138 linespacing = Spacing::Double;
141 // reset to default if input is empty
142 other = getString(dialog_->input_linespacing);
143 if (!other.empty()) {
144 linespacing = Spacing::Other;
146 linespacing = Spacing::Default;
147 fl_set_choice(dialog_->choice_linespacing, 1);
151 Spacing const spacing(linespacing, other);
152 controller().params().spacing(spacing);
156 void FormParagraph::update()
162 string const labelwidth = controller().params().labelWidthString();
163 fl_set_input(dialog_->input_labelwidth, labelwidth.c_str());
164 setEnabled(dialog_->input_labelwidth,
165 labelwidth != _("Senseless with this layout!"));
168 alignment_.set(controller().params().align());
170 // mark default alignment
171 LyXAlignment const default_alignment = controller().alignDefault();
173 string label = _("Block");
174 if (default_alignment == LYX_ALIGN_BLOCK) {
175 label += _(" (default)");
177 fl_set_object_label(dialog_->radio_align_block, label.c_str());
178 fl_set_button_shortcut(dialog_->radio_align_block, "#B", 1);
181 if (default_alignment == LYX_ALIGN_CENTER) {
182 label += _(" (default)");
184 fl_set_object_label(dialog_->radio_align_center, label.c_str());
185 fl_set_button_shortcut(dialog_->radio_align_center, "#C", 1);
188 if (default_alignment == LYX_ALIGN_LEFT) {
189 label += _(" (default)");
191 fl_set_object_label(dialog_->radio_align_left, label.c_str());
192 fl_set_button_shortcut(dialog_->radio_align_left, "#L", 1);
195 if (default_alignment == LYX_ALIGN_RIGHT) {
196 label = _(" (default)");
198 fl_set_object_label(dialog_->radio_align_right, label.c_str());
199 fl_set_button_shortcut(dialog_->radio_align_right, "#R", 1);
201 // Ensure that there's no crud left on the screen from this change
203 fl_redraw_form(form());
205 LyXAlignment alignpos = controller().alignPossible();
206 setEnabled(dialog_->radio_align_block,
207 bool(alignpos & LYX_ALIGN_BLOCK));
208 setEnabled(dialog_->radio_align_center,
209 bool(alignpos & LYX_ALIGN_CENTER));
210 setEnabled(dialog_->radio_align_left,
211 bool(alignpos & LYX_ALIGN_LEFT));
212 setEnabled(dialog_->radio_align_right,
213 bool(alignpos & LYX_ALIGN_RIGHT));
215 // lines, pagebreaks and indent
216 fl_set_button(dialog_->check_noindent,
217 controller().params().noindent());
220 Spacing const space = controller().params().spacing();
223 switch (space.getSpace()) {
227 case Spacing::Double:
230 case Spacing::Onehalf:
233 case Spacing::Single:
236 case Spacing::Default:
241 fl_set_choice(dialog_->choice_linespacing, pos);
243 bool const spacing_other = space.getSpace() == Spacing::Other;
244 setEnabled(dialog_->input_linespacing, spacing_other);
246 fl_set_input(dialog_->input_linespacing,
247 space.getValueAsString().c_str());
249 fl_set_input(dialog_->input_linespacing, "");
253 fl_set_button(dialog_->check_noindent,
254 controller().params().noindent());
258 ButtonPolicy::SMInput FormParagraph::input(FL_OBJECT * ob, long)
260 // Enable input when custum length is choosen,
261 // disable 'keep' when no space is choosen
262 if (ob == dialog_->choice_linespacing) {
263 bool const custom_spacing =
264 fl_get_choice(dialog_->choice_linespacing) == 5;
265 setEnabled(dialog_->input_linespacing, custom_spacing);
268 return ButtonPolicy::SMI_VALID;
271 } // namespace frontend