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