]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormParagraph.C
some formatting changes some simplifications and removal of dead code
[lyx.git] / src / frontends / xforms / FormParagraph.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *           Copyright 2000 The LyX Team.
7  *
8  *           @author Jürgen Vigna
9  *
10  *======================================================*/
11
12 #include <config.h>
13
14 #ifdef __GNUG_
15 #pragma implementation
16 #endif
17
18 #include FORMS_H_LOCATION
19
20 #include "FormParagraph.h"
21 #include "form_paragraph.h"
22 #include "Dialogs.h"
23 #include "Liason.h"
24 #include "LyXView.h"
25 #include "buffer.h"
26 #include "lyxtext.h"
27
28 #ifdef CXX_WORKING_NAMESPACES
29 using Liason::setMinibuffer;
30 #endif
31
32 FormParagraph::FormParagraph(LyXView * lv, Dialogs * d)
33         : FormBaseBD(lv, d, _("Paragraph Layout"),
34                      new NoRepeatedApplyReadOnlyPolicy),
35         dialog_(0), general_(0), extra_(0)
36 {
37     // let the popup be shown
38     // This is a permanent connection so we won't bother
39     // storing a copy because we won't be disconnecting.
40     d->showLayoutParagraph.connect(slot(this, &FormParagraph::show));
41 }
42
43
44 FormParagraph::~FormParagraph()
45 {
46     delete general_;
47     delete extra_;
48     delete dialog_;
49 }
50
51
52 FL_FORM * FormParagraph::form() const
53 {
54     if (dialog_) return dialog_->form;
55     return 0;
56 }
57
58
59 void FormParagraph::build()
60 {
61     // the tabbed folder
62     dialog_ = build_tabbed_paragraph();
63
64     // Workaround dumb xforms sizing bug
65     minw_ = form()->w;
66     minh_ = form()->h;
67
68     // manage the restore, ok, apply and cancel/close buttons
69     bc_.setOK(dialog_->button_ok);
70     bc_.setApply(dialog_->button_apply);
71     bc_.setCancel(dialog_->button_cancel);
72     bc_.setUndoAll(dialog_->button_restore);
73     bc_.refresh();
74
75     // the general paragraph data form
76     general_ = build_paragraph_general();
77
78     fl_addto_choice(general_->choice_space_above,
79                     _(" None | Defskip | Smallskip "
80                       "| Medskip | Bigskip | VFill | Length "));
81     fl_addto_choice(general_->choice_space_below,
82                     _(" None | Defskip | Smallskip "
83                       "| Medskip | Bigskip | VFill | Length ")); 
84
85     fl_set_input_return(general_->input_space_above, FL_RETURN_CHANGED);
86     fl_set_input_return(general_->input_space_below, FL_RETURN_CHANGED);
87     fl_set_input_return(general_->input_labelwidth, FL_RETURN_CHANGED);
88
89     bc_.addReadOnly (general_->radio_align_right);
90     bc_.addReadOnly (general_->radio_align_left);
91     bc_.addReadOnly (general_->radio_align_block);
92     bc_.addReadOnly (general_->radio_align_center);
93     bc_.addReadOnly (general_->check_lines_top);
94     bc_.addReadOnly (general_->check_lines_bottom);
95     bc_.addReadOnly (general_->check_pagebreaks_top);
96     bc_.addReadOnly (general_->check_pagebreaks_bottom);
97     bc_.addReadOnly (general_->choice_space_above);
98     bc_.addReadOnly (general_->input_space_above);
99     bc_.addReadOnly (general_->check_space_above);
100     bc_.addReadOnly (general_->choice_space_below);
101     bc_.addReadOnly (general_->input_space_below);
102     bc_.addReadOnly (general_->check_space_below);
103     bc_.addReadOnly (general_->check_noindent);
104     bc_.addReadOnly (general_->input_labelwidth);
105
106     // the document class form
107     extra_ = build_paragraph_extra();
108
109     fl_set_input_return(extra_->input_pextra_width, FL_RETURN_CHANGED);
110     fl_set_input_return(extra_->input_pextra_widthp, FL_RETURN_CHANGED);
111
112     bc_.addReadOnly (extra_->radio_pextra_indent);
113     bc_.addReadOnly (extra_->radio_pextra_minipage);
114     bc_.addReadOnly (extra_->radio_pextra_floatflt);
115     bc_.addReadOnly (extra_->radio_pextra_hfill);
116     bc_.addReadOnly (extra_->radio_pextra_startmp);
117
118     // now make them fit together
119     fl_addto_tabfolder(dialog_->tabbed_folder,_("General"), general_->form);
120     fl_addto_tabfolder(dialog_->tabbed_folder,_("Extra"), extra_->form);
121 }
122
123
124 void FormParagraph::apply()
125 {
126     if (!lv_->view()->available() || !dialog_)
127         return;
128
129     general_apply();
130     extra_apply();
131
132     lv_->view()->update(BufferView::SELECT | BufferView::FITCUR |
133                         BufferView::CHANGE);
134     lv_->buffer()->markDirty();
135     setMinibuffer(lv_, _("Paragraph layout set"));
136 }
137
138
139 void FormParagraph::update()
140 {
141     if (!dialog_)
142         return;
143
144     general_update();
145     extra_update();
146     bc_.readOnly(lv_->buffer()->isReadonly());
147 }
148
149
150 void FormParagraph::general_apply()
151 {
152     VSpace space_top, space_bottom;
153     LyXAlignment align;
154     string labelwidthstring;
155     bool noindent;
156
157     // If a vspace kind is "Length" but there's no text in
158     // the input field, reset the kind to "None". 
159     if ((fl_get_choice (general_->choice_space_above) == 7) &&
160         !*(fl_get_input (general_->input_space_above)))
161     {
162         fl_set_choice (general_->choice_space_above, 1);
163     }
164     if ((fl_get_choice (general_->choice_space_below) == 7) &&
165         !*(fl_get_input (general_->input_space_below)))
166     {
167         fl_set_choice (general_->choice_space_below, 1);
168     }
169    
170     bool line_top = fl_get_button(general_->check_lines_top);
171     bool line_bottom = fl_get_button(general_->check_lines_bottom);
172     bool pagebreak_top = fl_get_button(general_->check_pagebreaks_top);
173     bool pagebreak_bottom = fl_get_button(general_->check_pagebreaks_bottom);
174     
175     switch (fl_get_choice (general_->choice_space_above)) {
176     case 1:
177         space_top = VSpace(VSpace::NONE);
178         break;
179     case 2:
180         space_top = VSpace(VSpace::DEFSKIP);
181         break;
182     case 3:
183         space_top = VSpace(VSpace::SMALLSKIP);
184         break;
185     case 4:
186         space_top = VSpace(VSpace::MEDSKIP);
187         break;
188     case 5:
189         space_top = VSpace(VSpace::BIGSKIP);
190         break;
191     case 6:
192         space_top = VSpace(VSpace::VFILL);
193         break;
194     case 7:
195         space_top =
196                 VSpace(LyXGlueLength(fl_get_input(general_->input_space_above)));
197         break;
198     }
199     if (fl_get_button (general_->check_space_above))
200         space_top.setKeep (true);
201     switch (fl_get_choice (general_->choice_space_below)) {
202     case 1:
203         space_bottom = VSpace(VSpace::NONE);
204         break;
205     case 2:
206         space_bottom = VSpace(VSpace::DEFSKIP);
207         break;
208     case 3:
209         space_bottom = VSpace(VSpace::SMALLSKIP);
210         break;
211     case 4:
212         space_bottom = VSpace(VSpace::MEDSKIP);
213         break;
214     case 5:
215         space_bottom = VSpace(VSpace::BIGSKIP);
216         break;
217     case 6:
218         space_bottom = VSpace(VSpace::VFILL);
219         break;
220     case 7:
221         space_bottom =
222                 VSpace(LyXGlueLength(fl_get_input(general_->input_space_below)));
223         break;
224     }
225     if (fl_get_button (general_->check_space_below))
226         space_bottom.setKeep (true);
227
228     if (fl_get_button(general_->radio_align_left))
229         align = LYX_ALIGN_LEFT;
230     else if (fl_get_button(general_->radio_align_right))
231         align = LYX_ALIGN_RIGHT;
232     else if (fl_get_button(general_->radio_align_center))
233         align = LYX_ALIGN_CENTER;
234     else 
235         align = LYX_ALIGN_BLOCK;
236    
237     labelwidthstring = fl_get_input(general_->input_labelwidth);
238     noindent = fl_get_button(general_->check_noindent);
239
240     LyXText * text = 0;
241     if (lv_->view()->theLockingInset())
242         text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
243     if (!text)
244         text = lv_->view()->text;
245     text->SetParagraph(lv_->view(), line_top, line_bottom, pagebreak_top,
246                        pagebreak_bottom, space_top, space_bottom, align, 
247                        labelwidthstring, noindent);
248 }
249
250
251 void FormParagraph::extra_apply()
252 {
253     char const * width = fl_get_input(extra_->input_pextra_width);
254     char const * widthp = fl_get_input(extra_->input_pextra_widthp);
255     LyXText * text = lv_->view()->text;
256     int type = LyXParagraph::PEXTRA_NONE;
257     LyXParagraph::MINIPAGE_ALIGNMENT
258         alignment = LyXParagraph::MINIPAGE_ALIGN_TOP;
259     bool
260         hfill = false,
261         start_minipage = false;
262
263     if (fl_get_button(extra_->radio_pextra_indent)) {
264         type = LyXParagraph::PEXTRA_INDENT;
265     } else if (fl_get_button(extra_->radio_pextra_minipage)) {
266         type = LyXParagraph::PEXTRA_MINIPAGE;
267         hfill = fl_get_button(extra_->radio_pextra_hfill);
268         start_minipage = fl_get_button(extra_->radio_pextra_startmp);
269         if (fl_get_button(extra_->radio_pextra_top))
270             alignment = LyXParagraph::MINIPAGE_ALIGN_TOP;
271         else if (fl_get_button(extra_->radio_pextra_middle))
272             alignment = LyXParagraph::MINIPAGE_ALIGN_MIDDLE;
273         else if (fl_get_button(extra_->radio_pextra_bottom))
274             alignment = LyXParagraph::MINIPAGE_ALIGN_BOTTOM;
275     } else if (fl_get_button(extra_->radio_pextra_floatflt)) {
276         type = LyXParagraph::PEXTRA_FLOATFLT;
277     }
278     text->SetParagraphExtraOpt(lv_->view(), type, width, widthp, alignment,
279                                hfill, start_minipage);
280 }
281
282
283 void FormParagraph::general_update()
284 {
285     if (!general_)
286         return;
287
288     Buffer * buf = lv_->view()->buffer();
289     LyXText * text = 0;
290
291     if (lv_->view()->theLockingInset())
292         text = lv_->view()->theLockingInset()->getLyXText(lv_->view());
293     if (!text)
294         text = lv_->view()->text;
295
296     fl_set_input(general_->input_labelwidth,
297                  text->cursor.par()->GetLabelWidthString().c_str());
298     fl_set_button(general_->radio_align_right, 0);
299     fl_set_button(general_->radio_align_left, 0);
300     fl_set_button(general_->radio_align_center, 0);
301     fl_set_button(general_->radio_align_block, 0);
302
303     int align = text->cursor.par()->GetAlign();
304     if (align == LYX_ALIGN_LAYOUT)
305         align = textclasslist.Style(buf->params.textclass,
306                                     text->cursor.par()->GetLayout()).align;
307          
308     switch (align) {
309     case LYX_ALIGN_RIGHT:
310         fl_set_button(general_->radio_align_right, 1);
311         break;
312     case LYX_ALIGN_LEFT:
313         fl_set_button(general_->radio_align_left, 1);
314         break;
315     case LYX_ALIGN_CENTER:
316         fl_set_button(general_->radio_align_center, 1);
317         break;
318     default:
319         fl_set_button(general_->radio_align_block, 1);
320         break;
321     }
322
323 #ifndef NEW_INSETS
324     fl_set_button(general_->check_lines_top,
325                   text->cursor.par()->FirstPhysicalPar()->line_top);
326     
327     fl_set_button(general_->check_lines_bottom,
328                   text->cursor.par()->FirstPhysicalPar()->line_bottom);
329     
330     fl_set_button(general_->check_pagebreaks_top,
331                   text->cursor.par()->FirstPhysicalPar()->pagebreak_top);
332     
333     fl_set_button(general_->check_pagebreaks_bottom,
334                   text->cursor.par()->FirstPhysicalPar()->pagebreak_bottom);
335     fl_set_button(general_->check_noindent,
336                   text->cursor.par()->FirstPhysicalPar()->noindent);
337 #else
338     fl_set_button(general_->check_lines_top,
339                   text->cursor.par()->line_top);
340     fl_set_button(general_->check_lines_bottom,
341                   text->cursor.par()->line_bottom);
342     fl_set_button(general_->check_pagebreaks_top,
343                   text->cursor.par()->pagebreak_top);
344     fl_set_button(general_->check_pagebreaks_bottom,
345                   text->cursor.par()->pagebreak_bottom);
346     fl_set_button(general_->check_noindent,
347                   text->cursor.par()->noindent);
348 #endif
349     fl_set_input (general_->input_space_above, "");
350
351 #ifndef NEW_INSETS
352     switch (text->cursor.par()->FirstPhysicalPar()->added_space_top.kind()) {
353 #else
354     switch (text->cursor.par()->added_space_top.kind()) {
355 #endif
356
357     case VSpace::NONE:
358         fl_set_choice (general_->choice_space_above, 1);
359         break;
360     case VSpace::DEFSKIP:
361         fl_set_choice (general_->choice_space_above, 2);
362         break;
363     case VSpace::SMALLSKIP:
364         fl_set_choice (general_->choice_space_above, 3);
365         break;
366     case VSpace::MEDSKIP:
367         fl_set_choice (general_->choice_space_above, 4);
368         break;
369     case VSpace::BIGSKIP:
370         fl_set_choice (general_->choice_space_above, 5);
371         break;
372     case VSpace::VFILL:
373         fl_set_choice (general_->choice_space_above, 6);
374         break;
375     case VSpace::LENGTH:
376         fl_set_choice (general_->choice_space_above, 7);
377 #ifndef NEW_INSETS
378         fl_set_input(general_->input_space_above, 
379                      text->cursor.par()->FirstPhysicalPar()->
380                      added_space_top.length().asString().c_str());
381 #else
382         fl_set_input(general_->input_space_above, text->cursor.par()->
383                      added_space_top.length().asString().c_str());
384 #endif
385         break;
386     }
387 #ifndef NEW_INSETS
388     fl_set_button(general_->check_space_above,
389                    text->cursor.par()->FirstPhysicalPar()->
390                    added_space_top.keep());
391     fl_set_input(general_->input_space_below, "");
392     switch (text->cursor.par()->FirstPhysicalPar()->
393             added_space_bottom.kind()) {
394 #else
395     fl_set_button (general_->check_space_above,
396                    text->cursor.par()->added_space_top.keep());
397     fl_set_input (general_->input_space_below, "");
398     switch (text->cursor.par()->added_space_bottom.kind()) {
399 #endif
400     case VSpace::NONE:
401         fl_set_choice (general_->choice_space_below, 1);
402         break;
403     case VSpace::DEFSKIP:
404         fl_set_choice (general_->choice_space_below, 2);
405         break;
406     case VSpace::SMALLSKIP:
407         fl_set_choice (general_->choice_space_below, 3);
408         break;
409     case VSpace::MEDSKIP:
410         fl_set_choice (general_->choice_space_below, 4);
411         break;
412     case VSpace::BIGSKIP:
413         fl_set_choice (general_->choice_space_below, 5);
414         break;
415     case VSpace::VFILL:
416         fl_set_choice (general_->choice_space_below, 6);
417         break;
418     case VSpace::LENGTH:
419         fl_set_choice (general_->choice_space_below, 7);
420 #ifndef NEW_INSETS
421         fl_set_input(general_->input_space_below, 
422                      text->cursor.par()->FirstPhysicalPar()->
423                      added_space_bottom.length().asString().c_str());
424         break;
425     }
426     fl_set_button(general_->check_space_below,
427                    text->cursor.par()->FirstPhysicalPar()->
428                    added_space_bottom.keep());
429     fl_set_button(general_->check_noindent,
430                   text->cursor.par()->FirstPhysicalPar()->noindent);
431     if (text->cursor.par()->FirstPhysicalPar()->InInset()) {
432         fl_set_button(general_->check_pagebreaks_top, 0);
433         fl_deactivate_object(general_->check_pagebreaks_top);
434         fl_set_object_lcol(general_->check_pagebreaks_top, FL_INACTIVE);
435         fl_set_button(general_->check_pagebreaks_bottom, 0);
436         fl_deactivate_object(general_->check_pagebreaks_bottom);
437         fl_set_object_lcol(general_->check_pagebreaks_bottom, FL_INACTIVE);
438     } else {
439         fl_activate_object(general_->check_pagebreaks_top);
440         fl_set_object_lcol(general_->check_pagebreaks_top, FL_BLACK);
441         fl_activate_object(general_->check_pagebreaks_bottom);
442         fl_set_object_lcol(general_->check_pagebreaks_bottom, FL_BLACK);
443     }
444 #else
445         fl_set_input(general_->input_space_below, text->cursor.par()->
446                      added_space_bottom.length().asString().c_str());
447         break;
448     }
449     fl_set_button(general_->check_space_below,
450                    text->cursor.par()->added_space_bottom.keep());
451     fl_set_button(general_->check_noindent,
452                   text->cursor.par()->noindent);
453 #endif
454 }
455
456
457 void FormParagraph::extra_update()
458 {
459     if (!lv_->view()->available() || !extra_)
460         return;
461
462     LyXParagraph * par = lv_->view()->text->cursor.par();
463
464     fl_activate_object(extra_->input_pextra_width);
465     fl_set_object_lcol(extra_->input_pextra_width, FL_BLACK);
466     fl_activate_object(extra_->input_pextra_widthp);
467     fl_set_object_lcol(extra_->input_pextra_widthp, FL_BLACK);
468     fl_set_input(extra_->input_pextra_width,
469                  par->pextra_width.c_str());
470     fl_set_input(extra_->input_pextra_widthp,
471                  par->pextra_widthp.c_str());
472     switch (par->pextra_alignment) {
473     case LyXParagraph::MINIPAGE_ALIGN_TOP:
474         fl_set_button(extra_->radio_pextra_top, 1);
475         break;
476     case LyXParagraph::MINIPAGE_ALIGN_MIDDLE:
477         fl_set_button(extra_->radio_pextra_middle, 1);
478         break;
479     case LyXParagraph::MINIPAGE_ALIGN_BOTTOM:
480         fl_set_button(extra_->radio_pextra_bottom, 1);
481         break;
482     }
483     fl_set_button(extra_->radio_pextra_hfill,
484                   par->pextra_hfill);
485     fl_set_button(extra_->radio_pextra_startmp,
486                   par->pextra_start_minipage);
487     if (par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
488         fl_set_button(extra_->radio_pextra_indent, 1);
489         fl_set_button(extra_->radio_pextra_minipage, 0);
490         fl_set_button(extra_->radio_pextra_floatflt, 0);
491         fl_deactivate_object(extra_->radio_pextra_top);
492         fl_set_object_lcol(extra_->radio_pextra_top, FL_INACTIVE);
493         fl_deactivate_object(extra_->radio_pextra_middle);
494         fl_set_object_lcol(extra_->radio_pextra_middle, FL_INACTIVE);
495         fl_deactivate_object(extra_->radio_pextra_bottom);
496         fl_set_object_lcol(extra_->radio_pextra_bottom, FL_INACTIVE);
497         input(extra_->radio_pextra_indent, 0);
498     } else if (par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
499         fl_set_button(extra_->radio_pextra_indent, 0);
500         fl_set_button(extra_->radio_pextra_minipage, 1);
501         fl_set_button(extra_->radio_pextra_floatflt, 0);
502         fl_activate_object(extra_->radio_pextra_top);
503         fl_set_object_lcol(extra_->radio_pextra_top, FL_BLACK);
504         fl_activate_object(extra_->radio_pextra_middle);
505         fl_set_object_lcol(extra_->radio_pextra_middle, FL_BLACK);
506         fl_activate_object(extra_->radio_pextra_bottom);
507         fl_set_object_lcol(extra_->radio_pextra_bottom, FL_BLACK);
508         input(extra_->radio_pextra_minipage, 0);
509     } else if (par->pextra_type == LyXParagraph::PEXTRA_FLOATFLT) {
510         fl_set_button(extra_->radio_pextra_indent, 0);
511         fl_set_button(extra_->radio_pextra_minipage, 0);
512         fl_set_button(extra_->radio_pextra_floatflt, 1);
513         fl_deactivate_object(extra_->radio_pextra_top);
514         fl_set_object_lcol(extra_->radio_pextra_top, FL_INACTIVE);
515         fl_deactivate_object(extra_->radio_pextra_middle);
516         fl_set_object_lcol(extra_->radio_pextra_middle, FL_INACTIVE);
517         fl_deactivate_object(extra_->radio_pextra_bottom);
518         fl_set_object_lcol(extra_->radio_pextra_bottom, FL_INACTIVE);
519         input(extra_->radio_pextra_floatflt, 0);
520     } else {
521         fl_set_button(extra_->radio_pextra_indent, 0);
522         fl_set_button(extra_->radio_pextra_minipage, 0);
523         fl_set_button(extra_->radio_pextra_floatflt, 0);
524         fl_deactivate_object(extra_->input_pextra_width);
525         fl_set_object_lcol(extra_->input_pextra_width, FL_INACTIVE);
526         fl_deactivate_object(extra_->input_pextra_widthp);
527         fl_set_object_lcol(extra_->input_pextra_widthp, FL_INACTIVE);
528         fl_deactivate_object(extra_->radio_pextra_top);
529         fl_set_object_lcol(extra_->radio_pextra_top, FL_INACTIVE);
530         fl_deactivate_object(extra_->radio_pextra_middle);
531         fl_set_object_lcol(extra_->radio_pextra_middle, FL_INACTIVE);
532         fl_deactivate_object(extra_->radio_pextra_bottom);
533         fl_set_object_lcol(extra_->radio_pextra_bottom, FL_INACTIVE);
534         input(0, 0);
535     }
536     fl_hide_object(dialog_->text_warning);
537 }
538
539
540 bool FormParagraph::input(FL_OBJECT * ob, long)
541 {
542     bool ret = true;
543
544     fl_hide_object(dialog_->text_warning);
545
546     // First check the buttons which are exclusive and you have to
547     // check only the actuall de/activated button.
548     //
549     // general form first
550     //
551     // "Synchronize" the choices and input fields, making it
552     // impossible to commit senseless data.
553
554     if (fl_get_choice (general_->choice_space_above) != 7)
555         fl_set_input (general_->input_space_above, "");
556
557     if (fl_get_choice (general_->choice_space_below) != 7)
558         fl_set_input (general_->input_space_below, "");
559
560     //
561     // then the extra form
562     //
563     if (ob == extra_->radio_pextra_indent) {
564         int n = fl_get_button(extra_->radio_pextra_indent);
565         if (n) {
566             fl_set_button(extra_->radio_pextra_minipage, 0);
567             fl_set_button(extra_->radio_pextra_floatflt, 0);
568             fl_activate_object(extra_->input_pextra_width);
569             fl_set_object_lcol(extra_->input_pextra_width, FL_BLACK);
570             fl_activate_object(extra_->input_pextra_widthp);
571             fl_set_object_lcol(extra_->input_pextra_widthp, FL_BLACK);
572         } else {
573             fl_deactivate_object(extra_->input_pextra_width);
574             fl_set_object_lcol(extra_->input_pextra_width, FL_INACTIVE);
575             fl_deactivate_object(extra_->input_pextra_widthp);
576             fl_set_object_lcol(extra_->input_pextra_widthp, FL_INACTIVE);
577         }
578         fl_deactivate_object(extra_->radio_pextra_top);
579         fl_set_object_lcol(extra_->radio_pextra_top, FL_INACTIVE);
580         fl_deactivate_object(extra_->radio_pextra_middle);
581         fl_set_object_lcol(extra_->radio_pextra_middle, FL_INACTIVE);
582         fl_deactivate_object(extra_->radio_pextra_bottom);
583         fl_set_object_lcol(extra_->radio_pextra_bottom, FL_INACTIVE);
584         fl_activate_object(extra_->radio_pextra_hfill);
585         fl_set_object_lcol(extra_->radio_pextra_hfill, FL_INACTIVE);
586         fl_activate_object(extra_->radio_pextra_startmp);
587         fl_set_object_lcol(extra_->radio_pextra_startmp, FL_INACTIVE);
588     } else if (ob == extra_->radio_pextra_minipage) {
589         int n = fl_get_button(extra_->radio_pextra_minipage);
590         if (n) {
591             fl_set_button(extra_->radio_pextra_indent, 0);
592             fl_set_button(extra_->radio_pextra_floatflt, 0);
593             fl_activate_object(extra_->input_pextra_width);
594             fl_set_object_lcol(extra_->input_pextra_width, FL_BLACK);
595             fl_activate_object(extra_->input_pextra_widthp);
596             fl_set_object_lcol(extra_->input_pextra_widthp, FL_BLACK);
597             fl_activate_object(extra_->radio_pextra_top);
598             fl_set_object_lcol(extra_->radio_pextra_top, FL_BLACK);
599             fl_activate_object(extra_->radio_pextra_middle);
600             fl_set_object_lcol(extra_->radio_pextra_middle, FL_BLACK);
601             fl_activate_object(extra_->radio_pextra_bottom);
602             fl_set_object_lcol(extra_->radio_pextra_bottom, FL_BLACK);
603             fl_activate_object(extra_->radio_pextra_hfill);
604             fl_set_object_lcol(extra_->radio_pextra_hfill, FL_BLACK);
605             fl_activate_object(extra_->radio_pextra_startmp);
606             fl_set_object_lcol(extra_->radio_pextra_startmp, FL_BLACK);
607         } else {
608             fl_deactivate_object(extra_->input_pextra_width);
609             fl_set_object_lcol(extra_->input_pextra_width, FL_INACTIVE);
610             fl_deactivate_object(extra_->input_pextra_widthp);
611             fl_set_object_lcol(extra_->input_pextra_widthp, FL_INACTIVE);
612             fl_deactivate_object(extra_->radio_pextra_top);
613             fl_set_object_lcol(extra_->radio_pextra_top, FL_INACTIVE);
614             fl_deactivate_object(extra_->radio_pextra_middle);
615             fl_set_object_lcol(extra_->radio_pextra_middle, FL_INACTIVE);
616             fl_deactivate_object(extra_->radio_pextra_bottom);
617             fl_set_object_lcol(extra_->radio_pextra_bottom, FL_INACTIVE);
618             fl_activate_object(extra_->radio_pextra_hfill);
619             fl_set_object_lcol(extra_->radio_pextra_hfill, FL_INACTIVE);
620             fl_activate_object(extra_->radio_pextra_startmp);
621             fl_set_object_lcol(extra_->radio_pextra_startmp, FL_INACTIVE);
622         }
623     } else if (ob == extra_->radio_pextra_floatflt) {
624         int n = fl_get_button(extra_->radio_pextra_floatflt);
625         if (n) {
626             fl_set_button(extra_->radio_pextra_indent, 0);
627             fl_set_button(extra_->radio_pextra_minipage, 0);
628             fl_activate_object(extra_->input_pextra_width);
629             fl_set_object_lcol(extra_->input_pextra_width, FL_BLACK);
630             fl_activate_object(extra_->input_pextra_widthp);
631             fl_set_object_lcol(extra_->input_pextra_widthp, FL_BLACK);
632         } else {
633             fl_deactivate_object(extra_->input_pextra_width);
634             fl_set_object_lcol(extra_->input_pextra_width, FL_INACTIVE);
635             fl_deactivate_object(extra_->input_pextra_widthp);
636             fl_set_object_lcol(extra_->input_pextra_widthp, FL_INACTIVE);
637         }
638         fl_deactivate_object(extra_->radio_pextra_top);
639         fl_set_object_lcol(extra_->radio_pextra_top, FL_INACTIVE);
640         fl_deactivate_object(extra_->radio_pextra_middle);
641         fl_set_object_lcol(extra_->radio_pextra_middle, FL_INACTIVE);
642         fl_deactivate_object(extra_->radio_pextra_bottom);
643         fl_set_object_lcol(extra_->radio_pextra_bottom, FL_INACTIVE);
644         fl_activate_object(extra_->radio_pextra_hfill);
645         fl_set_object_lcol(extra_->radio_pextra_hfill, FL_INACTIVE);
646         fl_activate_object(extra_->radio_pextra_startmp);
647         fl_set_object_lcol(extra_->radio_pextra_startmp, FL_INACTIVE);
648     }
649     
650     //
651     // first the general form
652     //
653     string input = fl_get_input (general_->input_space_above);
654     bool invalid = false;
655         
656     if (fl_get_choice(general_->choice_space_above)==7)
657         invalid = !input.empty() && !isValidGlueLength(input);
658
659     input = fl_get_input (general_->input_space_below);
660
661     if (fl_get_choice(general_->choice_space_below)==7)
662         invalid = invalid || (!input.empty() && !isValidGlueLength(input));
663     
664     if (ob == general_->input_space_above || ob == general_->input_space_below) {
665         if (invalid) {
666             fl_set_object_label(dialog_->text_warning,
667                 _("Warning: Invalid Length (valid example: 10mm)"));
668             fl_show_object(dialog_->text_warning);
669             return false;
670         } else {
671             fl_hide_object(dialog_->text_warning);
672             return true;
673         }
674     }
675
676     //
677     // then the extra form
678     //
679     int n = fl_get_button(extra_->radio_pextra_indent) +
680         fl_get_button(extra_->radio_pextra_minipage) +
681         fl_get_button(extra_->radio_pextra_floatflt);
682     string s1 = fl_get_input(extra_->input_pextra_width);
683     string s2 = fl_get_input(extra_->input_pextra_widthp);
684     if (!n) { // no button pressed both should be deactivated now
685         fl_deactivate_object(extra_->input_pextra_width);
686         fl_set_object_lcol(extra_->input_pextra_width, FL_INACTIVE);
687         fl_deactivate_object(extra_->input_pextra_widthp);
688         fl_set_object_lcol(extra_->input_pextra_widthp, FL_INACTIVE);
689         fl_hide_object(dialog_->text_warning);
690     } else if (s1.empty() && s2.empty()) {
691         fl_activate_object(extra_->input_pextra_width);
692         fl_set_object_lcol(extra_->input_pextra_width, FL_BLACK);
693         fl_activate_object(extra_->input_pextra_widthp);
694         fl_set_object_lcol(extra_->input_pextra_widthp, FL_BLACK);
695         fl_hide_object(dialog_->text_warning);
696         ret = false;
697     } else if (!s1.empty()) { // LyXLength parameter
698         fl_activate_object(extra_->input_pextra_width);
699         fl_set_object_lcol(extra_->input_pextra_width, FL_BLACK);
700         fl_deactivate_object(extra_->input_pextra_widthp);
701         fl_set_object_lcol(extra_->input_pextra_widthp, FL_INACTIVE);
702         if (!isValidLength(s1)) {
703             fl_set_object_label(dialog_->text_warning,
704                         _("Warning: Invalid Length (valid example: 10mm)"));
705             fl_show_object(dialog_->text_warning);
706             ret = false;
707         }
708     } else { // !s2.empty() % parameter
709         fl_deactivate_object(extra_->input_pextra_width);
710         fl_set_object_lcol(extra_->input_pextra_width, FL_INACTIVE);
711         fl_activate_object(extra_->input_pextra_widthp);
712         fl_set_object_lcol(extra_->input_pextra_widthp, FL_BLACK);
713         if ((lyx::atoi(s2) < 0 ) || (lyx::atoi(s2) > 100)) {
714             ret = false;
715             fl_set_object_label(dialog_->text_warning,
716                         _("Warning: Invalid percent value (0-100)"));
717             fl_show_object(dialog_->text_warning);
718         }
719     }
720     return ret;
721 }
722