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 #include <boost/bind.hpp>
37 using lyx::support::contains;
38 using lyx::support::getStringFromVector;
39 using lyx::support::rtrim;
51 string defaultUnit("cm");
56 typedef FormController<ControlParagraph, FormView<FD_paragraph> > base_class;
58 FormParagraph::FormParagraph(Dialog & parent)
59 : base_class(parent, _("Paragraph Settings"))
63 void FormParagraph::build()
66 dialog_.reset(build_paragraph(this));
68 // Manage the ok, apply, restore and cancel/close buttons
69 bcview().setOK(dialog_->button_ok);
70 bcview().setApply(dialog_->button_apply);
71 bcview().setCancel(dialog_->button_close);
72 bcview().setRestore(dialog_->button_restore);
74 // disable for read-only documents
75 bcview().addReadOnly(dialog_->check_noindent);
76 bcview().addReadOnly(dialog_->choice_linespacing);
77 bcview().addReadOnly(dialog_->input_linespacing);
79 bcview().addReadOnly(dialog_->input_labelwidth);
81 // trigger an input event for cut&paste with middle mouse button.
82 setPrehandler(dialog_->input_linespacing);
83 setPrehandler(dialog_->input_labelwidth);
85 fl_set_input_return(dialog_->input_labelwidth, FL_RETURN_CHANGED);
86 fl_set_input_return(dialog_->input_linespacing, FL_RETURN_CHANGED);
88 // limit these inputs to unsigned floats
89 fl_set_input_filter(dialog_->input_linespacing, fl_unsigned_float_filter);
91 // add alignment radio buttons
92 alignment_.init(dialog_->radio_align_left, LYX_ALIGN_LEFT);
93 alignment_.init(dialog_->radio_align_right, LYX_ALIGN_RIGHT);
94 alignment_.init(dialog_->radio_align_block, LYX_ALIGN_BLOCK);
95 alignment_.init(dialog_->radio_align_center, LYX_ALIGN_CENTER);
97 string const linespacing = _("Default|Single|OneHalf|Double|Custom");
98 fl_addto_choice(dialog_->choice_linespacing, linespacing.c_str());
100 // Create the contents of the unit choices; don't include the "%" terms.
101 vector<string> units_vec = getLatexUnits();
102 vector<string>::iterator del =
103 remove_if(units_vec.begin(), units_vec.end(),
104 bind(contains<char>, _1, '%'));
105 units_vec.erase(del, units_vec.end());
107 // set default unit for custom length
108 switch (lyxrc.default_papersize) {
111 case PAPER_LEGALPAPER:
112 case PAPER_EXECUTIVEPAPER:
125 void FormParagraph::apply()
131 LyXAlignment const alignment =
132 static_cast<LyXAlignment>(alignment_.get());
133 controller().params().align(alignment);
136 string const labelwidthstring =
137 getString(dialog_->input_labelwidth);
138 controller().params().labelWidthString(labelwidthstring);
141 bool const noindent = fl_get_button(dialog_->check_noindent);
142 controller().params().noindent(noindent);
145 Spacing::Space linespacing = Spacing::Default;
147 switch (fl_get_choice(dialog_->choice_linespacing)) {
149 linespacing = Spacing::Default;
152 linespacing = Spacing::Single;
155 linespacing = Spacing::Onehalf;
158 linespacing = Spacing::Double;
161 // reset to default if input is empty
162 other = getString(dialog_->input_linespacing);
163 if (!other.empty()) {
164 linespacing = Spacing::Other;
166 linespacing = Spacing::Default;
167 fl_set_choice(dialog_->choice_linespacing, 1);
171 Spacing const spacing(linespacing, other);
172 controller().params().spacing(spacing);
176 void FormParagraph::update()
182 string const labelwidth = controller().params().labelWidthString();
183 fl_set_input(dialog_->input_labelwidth, labelwidth.c_str());
184 setEnabled(dialog_->input_labelwidth,
185 labelwidth != _("Senseless with this layout!"));
188 alignment_.set(controller().params().align());
190 // mark default alignment
191 LyXAlignment const default_alignment = controller().alignDefault();
193 string label = _("Block");
194 if (default_alignment == LYX_ALIGN_BLOCK) {
195 label += _(" (default)");
197 fl_set_object_label(dialog_->radio_align_block, label.c_str());
198 fl_set_button_shortcut(dialog_->radio_align_block, "#B", 1);
201 if (default_alignment == LYX_ALIGN_CENTER) {
202 label += _(" (default)");
204 fl_set_object_label(dialog_->radio_align_center, label.c_str());
205 fl_set_button_shortcut(dialog_->radio_align_center, "#C", 1);
208 if (default_alignment == LYX_ALIGN_LEFT) {
209 label += _(" (default)");
211 fl_set_object_label(dialog_->radio_align_left, label.c_str());
212 fl_set_button_shortcut(dialog_->radio_align_left, "#L", 1);
215 if (default_alignment == LYX_ALIGN_RIGHT) {
216 label = _(" (default)");
218 fl_set_object_label(dialog_->radio_align_right, label.c_str());
219 fl_set_button_shortcut(dialog_->radio_align_right, "#R", 1);
221 // Ensure that there's no crud left on the screen from this change
223 fl_redraw_form(form());
225 LyXAlignment alignpos = controller().alignPossible();
226 setEnabled(dialog_->radio_align_block,
227 bool(alignpos & LYX_ALIGN_BLOCK));
228 setEnabled(dialog_->radio_align_center,
229 bool(alignpos & LYX_ALIGN_CENTER));
230 setEnabled(dialog_->radio_align_left,
231 bool(alignpos & LYX_ALIGN_LEFT));
232 setEnabled(dialog_->radio_align_right,
233 bool(alignpos & LYX_ALIGN_RIGHT));
235 // lines, pagebreaks and indent
236 fl_set_button(dialog_->check_noindent,
237 controller().params().noindent());
240 Spacing const space = controller().params().spacing();
243 switch (space.getSpace()) {
247 case Spacing::Double:
250 case Spacing::Onehalf:
253 case Spacing::Single:
256 case Spacing::Default:
261 fl_set_choice(dialog_->choice_linespacing, pos);
263 bool const spacing_other = space.getSpace() == Spacing::Other;
264 setEnabled(dialog_->input_linespacing, spacing_other);
266 string const sp = tostr(space.getValue());
267 fl_set_input(dialog_->input_linespacing, sp.c_str());
269 fl_set_input(dialog_->input_linespacing, "");
273 fl_set_button(dialog_->check_noindent,
274 controller().params().noindent());
278 ButtonPolicy::SMInput FormParagraph::input(FL_OBJECT * ob, long)
280 // Enable input when custum length is choosen,
281 // disable 'keep' when no space is choosen
282 if (ob == dialog_->choice_linespacing) {
283 bool const custom_spacing =
284 fl_get_choice(dialog_->choice_linespacing) == 5;
285 setEnabled(dialog_->input_linespacing, custom_spacing);
288 return ButtonPolicy::SMI_VALID;