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