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