1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
10 *======================================================*/
15 #pragma implementation
18 #include FORMS_H_LOCATION
20 #include "FormParagraph.h"
21 #include "form_paragraph.h"
27 #include "xforms_helpers.h"
29 using Liason::setMinibuffer;
33 FormParagraph::FormParagraph(LyXView * lv, Dialogs * d)
34 : FormBaseBD(lv, d, _("Paragraph Layout"))
36 // let the dialog be shown
37 // This is a permanent connection so we won't bother
38 // storing a copy because we won't be disconnecting.
39 d->showLayoutParagraph.connect(slot(this, &FormParagraph::show));
43 void FormParagraph::redraw()
45 if( form() && form()->visible )
46 fl_redraw_form( form() );
50 FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
51 if (outer_form && outer_form->visible)
52 fl_redraw_form( outer_form );
56 FL_FORM * FormParagraph::form() const
58 if (dialog_.get()) return dialog_->form;
63 void FormParagraph::build()
66 dialog_.reset(build_tabbed_paragraph());
68 // Manage the ok, apply, restore and cancel/close buttons
69 bc_.setOK(dialog_->button_ok);
70 bc_.setApply(dialog_->button_apply);
71 bc_.setCancel(dialog_->button_cancel);
72 bc_.setRestore(dialog_->button_restore);
74 // the general paragraph data form
75 general_.reset(build_paragraph_general());
77 fl_addto_choice(general_->choice_space_above,
78 _(" None | Defskip | Smallskip "
79 "| Medskip | Bigskip | VFill | Length "));
80 fl_addto_choice(general_->choice_space_below,
81 _(" None | Defskip | Smallskip "
82 "| Medskip | Bigskip | VFill | Length "));
84 fl_set_input_return(general_->input_space_above, FL_RETURN_CHANGED);
85 fl_set_input_return(general_->input_space_below, FL_RETURN_CHANGED);
86 fl_set_input_return(general_->input_labelwidth, FL_RETURN_CHANGED);
88 bc_.addReadOnly (general_->radio_align_right);
89 bc_.addReadOnly (general_->radio_align_left);
90 bc_.addReadOnly (general_->radio_align_block);
91 bc_.addReadOnly (general_->radio_align_center);
92 bc_.addReadOnly (general_->check_lines_top);
93 bc_.addReadOnly (general_->check_lines_bottom);
94 bc_.addReadOnly (general_->check_pagebreaks_top);
95 bc_.addReadOnly (general_->check_pagebreaks_bottom);
96 bc_.addReadOnly (general_->choice_space_above);
97 bc_.addReadOnly (general_->input_space_above);
98 bc_.addReadOnly (general_->check_space_above);
99 bc_.addReadOnly (general_->choice_space_below);
100 bc_.addReadOnly (general_->input_space_below);
101 bc_.addReadOnly (general_->check_space_below);
102 bc_.addReadOnly (general_->check_noindent);
103 bc_.addReadOnly (general_->input_labelwidth);
105 // now make them fit together
106 fl_addto_tabfolder(dialog_->tabbed_folder,_("General"), general_->form);
110 void FormParagraph::apply()
112 if (!lv_->view()->available() || !dialog_.get())
117 lv_->view()->update(lv_->view()->text,
118 BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE);
119 lv_->buffer()->markDirty();
120 setMinibuffer(lv_, _("Paragraph layout set"));
124 void FormParagraph::update()
129 // Do this first; some objects may be de/activated subsequently.
130 bc_.readOnly(lv_->buffer()->isReadonly());
136 void FormParagraph::general_apply()
138 VSpace space_top, space_bottom;
140 string labelwidthstring;
143 // If a vspace kind is "Length" but there's no text in
144 // the input field, reset the kind to "None".
145 if ((fl_get_choice (general_->choice_space_above) == 7) &&
146 !*(fl_get_input (general_->input_space_above)))
148 fl_set_choice (general_->choice_space_above, 1);
150 if ((fl_get_choice (general_->choice_space_below) == 7) &&
151 !*(fl_get_input (general_->input_space_below)))
153 fl_set_choice (general_->choice_space_below, 1);
156 bool line_top = fl_get_button(general_->check_lines_top);
157 bool line_bottom = fl_get_button(general_->check_lines_bottom);
158 bool pagebreak_top = fl_get_button(general_->check_pagebreaks_top);
159 bool pagebreak_bottom = fl_get_button(general_->check_pagebreaks_bottom);
161 switch (fl_get_choice (general_->choice_space_above)) {
163 space_top = VSpace(VSpace::NONE);
166 space_top = VSpace(VSpace::DEFSKIP);
169 space_top = VSpace(VSpace::SMALLSKIP);
172 space_top = VSpace(VSpace::MEDSKIP);
175 space_top = VSpace(VSpace::BIGSKIP);
178 space_top = VSpace(VSpace::VFILL);
182 VSpace(LyXGlueLength(fl_get_input(general_->input_space_above)));
185 if (fl_get_button (general_->check_space_above))
186 space_top.setKeep (true);
187 switch (fl_get_choice (general_->choice_space_below)) {
189 space_bottom = VSpace(VSpace::NONE);
192 space_bottom = VSpace(VSpace::DEFSKIP);
195 space_bottom = VSpace(VSpace::SMALLSKIP);
198 space_bottom = VSpace(VSpace::MEDSKIP);
201 space_bottom = VSpace(VSpace::BIGSKIP);
204 space_bottom = VSpace(VSpace::VFILL);
208 VSpace(LyXGlueLength(fl_get_input(general_->input_space_below)));
211 if (fl_get_button (general_->check_space_below))
212 space_bottom.setKeep (true);
214 if (fl_get_button(general_->radio_align_left))
215 align = LYX_ALIGN_LEFT;
216 else if (fl_get_button(general_->radio_align_right))
217 align = LYX_ALIGN_RIGHT;
218 else if (fl_get_button(general_->radio_align_center))
219 align = LYX_ALIGN_CENTER;
221 align = LYX_ALIGN_BLOCK;
223 labelwidthstring = fl_get_input(general_->input_labelwidth);
224 noindent = fl_get_button(general_->check_noindent);
227 if (lv_->view()->theLockingInset())
228 text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
230 text = lv_->view()->text;
231 text->SetParagraph(lv_->view(), line_top, line_bottom, pagebreak_top,
232 pagebreak_bottom, space_top, space_bottom, align,
233 labelwidthstring, noindent);
237 void FormParagraph::general_update()
242 Buffer * buf = lv_->view()->buffer();
245 if (lv_->view()->theLockingInset())
246 text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
248 text = lv_->view()->text;
250 fl_set_input(general_->input_labelwidth,
251 text->cursor.par()->GetLabelWidthString().c_str());
252 fl_set_button(general_->radio_align_right, 0);
253 fl_set_button(general_->radio_align_left, 0);
254 fl_set_button(general_->radio_align_center, 0);
255 fl_set_button(general_->radio_align_block, 0);
257 int align = text->cursor.par()->GetAlign();
258 if (align == LYX_ALIGN_LAYOUT)
259 align = textclasslist.Style(buf->params.textclass,
260 text->cursor.par()->GetLayout()).align;
263 case LYX_ALIGN_RIGHT:
264 fl_set_button(general_->radio_align_right, 1);
267 fl_set_button(general_->radio_align_left, 1);
269 case LYX_ALIGN_CENTER:
270 fl_set_button(general_->radio_align_center, 1);
273 fl_set_button(general_->radio_align_block, 1);
277 LyXAlignment alignpos =
278 textclasslist.Style(buf->params.textclass,
279 text->cursor.par()->GetLayout()).alignpossible;
281 setEnabled(general_->radio_align_block, bool(alignpos & LYX_ALIGN_BLOCK));
282 setEnabled(general_->radio_align_center, bool(alignpos & LYX_ALIGN_CENTER));
283 setEnabled(general_->radio_align_left, bool(alignpos & LYX_ALIGN_LEFT));
284 setEnabled(general_->radio_align_right, bool(alignpos & LYX_ALIGN_RIGHT));
286 fl_set_button(general_->check_lines_top,
287 text->cursor.par()->params.lineTop());
288 fl_set_button(general_->check_lines_bottom,
289 text->cursor.par()->params.lineBottom());
290 fl_set_button(general_->check_pagebreaks_top,
291 text->cursor.par()->params.pagebreakTop());
292 fl_set_button(general_->check_pagebreaks_bottom,
293 text->cursor.par()->params.pagebreakBottom());
294 fl_set_button(general_->check_noindent,
295 text->cursor.par()->params.noindent());
297 fl_set_input (general_->input_space_above, "");
299 switch (text->cursor.par()->params.spaceTop().kind()) {
301 fl_set_choice (general_->choice_space_above, 1);
303 case VSpace::DEFSKIP:
304 fl_set_choice (general_->choice_space_above, 2);
306 case VSpace::SMALLSKIP:
307 fl_set_choice (general_->choice_space_above, 3);
309 case VSpace::MEDSKIP:
310 fl_set_choice (general_->choice_space_above, 4);
312 case VSpace::BIGSKIP:
313 fl_set_choice (general_->choice_space_above, 5);
316 fl_set_choice (general_->choice_space_above, 6);
319 fl_set_choice (general_->choice_space_above, 7);
320 fl_set_input(general_->input_space_above, text->cursor.par()->
321 params.spaceTop().length().asString().c_str());
325 fl_set_button (general_->check_space_above,
326 text->cursor.par()->params.spaceTop().keep());
327 fl_set_input (general_->input_space_below, "");
329 switch (text->cursor.par()->params.spaceBottom().kind()) {
331 fl_set_choice (general_->choice_space_below, 1);
333 case VSpace::DEFSKIP:
334 fl_set_choice (general_->choice_space_below, 2);
336 case VSpace::SMALLSKIP:
337 fl_set_choice (general_->choice_space_below, 3);
339 case VSpace::MEDSKIP:
340 fl_set_choice (general_->choice_space_below, 4);
342 case VSpace::BIGSKIP:
343 fl_set_choice (general_->choice_space_below, 5);
346 fl_set_choice (general_->choice_space_below, 6);
349 fl_set_choice (general_->choice_space_below, 7);
350 fl_set_input(general_->input_space_below, text->cursor.par()->
351 params.spaceBottom().length().asString().c_str());
354 fl_set_button(general_->check_space_below,
355 text->cursor.par()->params.spaceBottom().keep());
356 fl_set_button(general_->check_noindent,
357 text->cursor.par()->params.noindent());
361 bool FormParagraph::input(FL_OBJECT * ob, long)
365 fl_hide_object(dialog_->text_warning);
367 // First check the buttons which are exclusive and you have to
368 // check only the actuall de/activated button.
370 // general form first
372 // "Synchronize" the choices and input fields, making it
373 // impossible to commit senseless data.
375 if (fl_get_choice (general_->choice_space_above) != 7)
376 fl_set_input (general_->input_space_above, "");
378 if (fl_get_choice (general_->choice_space_below) != 7)
379 fl_set_input (general_->input_space_below, "");
382 // first the general form
384 string input = fl_get_input (general_->input_space_above);
385 bool invalid = false;
387 if (fl_get_choice(general_->choice_space_above)==7)
388 invalid = !input.empty() && !isValidGlueLength(input);
390 input = fl_get_input (general_->input_space_below);
392 if (fl_get_choice(general_->choice_space_below)==7)
393 invalid = invalid || (!input.empty() && !isValidGlueLength(input));
395 if (ob == general_->input_space_above || ob == general_->input_space_below) {
397 fl_set_object_label(dialog_->text_warning,
398 _("Warning: Invalid Length (valid example: 10mm)"));
399 fl_show_object(dialog_->text_warning);
402 fl_hide_object(dialog_->text_warning);