1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 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()
131 bc_.readOnly(lv_->buffer()->isReadonly());
135 void FormParagraph::general_apply()
137 VSpace space_top, space_bottom;
139 string labelwidthstring;
142 // If a vspace kind is "Length" but there's no text in
143 // the input field, reset the kind to "None".
144 if ((fl_get_choice (general_->choice_space_above) == 7) &&
145 !*(fl_get_input (general_->input_space_above)))
147 fl_set_choice (general_->choice_space_above, 1);
149 if ((fl_get_choice (general_->choice_space_below) == 7) &&
150 !*(fl_get_input (general_->input_space_below)))
152 fl_set_choice (general_->choice_space_below, 1);
155 bool line_top = fl_get_button(general_->check_lines_top);
156 bool line_bottom = fl_get_button(general_->check_lines_bottom);
157 bool pagebreak_top = fl_get_button(general_->check_pagebreaks_top);
158 bool pagebreak_bottom = fl_get_button(general_->check_pagebreaks_bottom);
160 switch (fl_get_choice (general_->choice_space_above)) {
162 space_top = VSpace(VSpace::NONE);
165 space_top = VSpace(VSpace::DEFSKIP);
168 space_top = VSpace(VSpace::SMALLSKIP);
171 space_top = VSpace(VSpace::MEDSKIP);
174 space_top = VSpace(VSpace::BIGSKIP);
177 space_top = VSpace(VSpace::VFILL);
181 VSpace(LyXGlueLength(fl_get_input(general_->input_space_above)));
184 if (fl_get_button (general_->check_space_above))
185 space_top.setKeep (true);
186 switch (fl_get_choice (general_->choice_space_below)) {
188 space_bottom = VSpace(VSpace::NONE);
191 space_bottom = VSpace(VSpace::DEFSKIP);
194 space_bottom = VSpace(VSpace::SMALLSKIP);
197 space_bottom = VSpace(VSpace::MEDSKIP);
200 space_bottom = VSpace(VSpace::BIGSKIP);
203 space_bottom = VSpace(VSpace::VFILL);
207 VSpace(LyXGlueLength(fl_get_input(general_->input_space_below)));
210 if (fl_get_button (general_->check_space_below))
211 space_bottom.setKeep (true);
213 if (fl_get_button(general_->radio_align_left))
214 align = LYX_ALIGN_LEFT;
215 else if (fl_get_button(general_->radio_align_right))
216 align = LYX_ALIGN_RIGHT;
217 else if (fl_get_button(general_->radio_align_center))
218 align = LYX_ALIGN_CENTER;
220 align = LYX_ALIGN_BLOCK;
222 labelwidthstring = fl_get_input(general_->input_labelwidth);
223 noindent = fl_get_button(general_->check_noindent);
226 if (lv_->view()->theLockingInset())
227 text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
229 text = lv_->view()->text;
230 text->SetParagraph(lv_->view(), line_top, line_bottom, pagebreak_top,
231 pagebreak_bottom, space_top, space_bottom, align,
232 labelwidthstring, noindent);
236 void FormParagraph::general_update()
241 Buffer * buf = lv_->view()->buffer();
244 if (lv_->view()->theLockingInset())
245 text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
247 text = lv_->view()->text;
249 fl_set_input(general_->input_labelwidth,
250 text->cursor.par()->GetLabelWidthString().c_str());
251 fl_set_button(general_->radio_align_right, 0);
252 fl_set_button(general_->radio_align_left, 0);
253 fl_set_button(general_->radio_align_center, 0);
254 fl_set_button(general_->radio_align_block, 0);
256 int align = text->cursor.par()->GetAlign();
257 if (align == LYX_ALIGN_LAYOUT)
258 align = textclasslist.Style(buf->params.textclass,
259 text->cursor.par()->GetLayout()).align;
262 case LYX_ALIGN_RIGHT:
263 fl_set_button(general_->radio_align_right, 1);
266 fl_set_button(general_->radio_align_left, 1);
268 case LYX_ALIGN_CENTER:
269 fl_set_button(general_->radio_align_center, 1);
272 fl_set_button(general_->radio_align_block, 1);
276 fl_set_button(general_->check_lines_top,
277 text->cursor.par()->params.lineTop());
278 fl_set_button(general_->check_lines_bottom,
279 text->cursor.par()->params.lineBottom());
280 fl_set_button(general_->check_pagebreaks_top,
281 text->cursor.par()->params.pagebreakTop());
282 fl_set_button(general_->check_pagebreaks_bottom,
283 text->cursor.par()->params.pagebreakBottom());
284 fl_set_button(general_->check_noindent,
285 text->cursor.par()->params.noindent());
287 fl_set_input (general_->input_space_above, "");
289 switch (text->cursor.par()->params.spaceTop().kind()) {
291 fl_set_choice (general_->choice_space_above, 1);
293 case VSpace::DEFSKIP:
294 fl_set_choice (general_->choice_space_above, 2);
296 case VSpace::SMALLSKIP:
297 fl_set_choice (general_->choice_space_above, 3);
299 case VSpace::MEDSKIP:
300 fl_set_choice (general_->choice_space_above, 4);
302 case VSpace::BIGSKIP:
303 fl_set_choice (general_->choice_space_above, 5);
306 fl_set_choice (general_->choice_space_above, 6);
309 fl_set_choice (general_->choice_space_above, 7);
310 fl_set_input(general_->input_space_above, text->cursor.par()->
311 params.spaceTop().length().asString().c_str());
315 fl_set_button (general_->check_space_above,
316 text->cursor.par()->params.spaceTop().keep());
317 fl_set_input (general_->input_space_below, "");
319 switch (text->cursor.par()->params.spaceBottom().kind()) {
321 fl_set_choice (general_->choice_space_below, 1);
323 case VSpace::DEFSKIP:
324 fl_set_choice (general_->choice_space_below, 2);
326 case VSpace::SMALLSKIP:
327 fl_set_choice (general_->choice_space_below, 3);
329 case VSpace::MEDSKIP:
330 fl_set_choice (general_->choice_space_below, 4);
332 case VSpace::BIGSKIP:
333 fl_set_choice (general_->choice_space_below, 5);
336 fl_set_choice (general_->choice_space_below, 6);
339 fl_set_choice (general_->choice_space_below, 7);
340 fl_set_input(general_->input_space_below, text->cursor.par()->
341 params.spaceBottom().length().asString().c_str());
344 fl_set_button(general_->check_space_below,
345 text->cursor.par()->params.spaceBottom().keep());
346 fl_set_button(general_->check_noindent,
347 text->cursor.par()->params.noindent());
351 bool FormParagraph::input(FL_OBJECT * ob, long)
355 fl_hide_object(dialog_->text_warning);
357 // First check the buttons which are exclusive and you have to
358 // check only the actuall de/activated button.
360 // general form first
362 // "Synchronize" the choices and input fields, making it
363 // impossible to commit senseless data.
365 if (fl_get_choice (general_->choice_space_above) != 7)
366 fl_set_input (general_->input_space_above, "");
368 if (fl_get_choice (general_->choice_space_below) != 7)
369 fl_set_input (general_->input_space_below, "");
372 // first the general form
374 string input = fl_get_input (general_->input_space_above);
375 bool invalid = false;
377 if (fl_get_choice(general_->choice_space_above)==7)
378 invalid = !input.empty() && !isValidGlueLength(input);
380 input = fl_get_input (general_->input_space_below);
382 if (fl_get_choice(general_->choice_space_below)==7)
383 invalid = invalid || (!input.empty() && !isValidGlueLength(input));
385 if (ob == general_->input_space_above || ob == general_->input_space_below) {
387 fl_set_object_label(dialog_->text_warning,
388 _("Warning: Invalid Length (valid example: 10mm)"));
389 fl_show_object(dialog_->text_warning);
392 fl_hide_object(dialog_->text_warning);