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