4 #include "definitions.h"
5 #include FORMS_H_LOCATION
6 #include "layout_forms.h"
8 #include "minibuffer.h"
11 #include "BufferView.h"
12 #include "lyxparagraph.h"
16 // $Id: ParagraphExtra.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $
18 #if !defined(lint) && !defined(WITH_WARNINGS)
19 static char vcid[] = "$Id: ParagraphExtra.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $";
23 extern FD_form_paragraph_extra *fd_form_paragraph_extra;
24 extern MiniBuffer *minibuffer;
25 extern BufferView *current_view;
26 extern void BeforeChange();
27 static bool CheckInputWidth();
29 inline void DeactivateParagraphExtraButtons ()
31 fl_deactivate_object (fd_form_paragraph_extra->button_ok);
32 fl_deactivate_object (fd_form_paragraph_extra->button_apply);
33 fl_set_object_lcol (fd_form_paragraph_extra->button_ok, FL_INACTIVE);
34 fl_set_object_lcol (fd_form_paragraph_extra->button_apply, FL_INACTIVE);
37 inline void ActivateParagraphExtraButtons ()
39 fl_activate_object (fd_form_paragraph_extra->button_ok);
40 fl_activate_object (fd_form_paragraph_extra->button_apply);
41 fl_set_object_lcol (fd_form_paragraph_extra->button_ok, FL_BLACK);
42 fl_set_object_lcol (fd_form_paragraph_extra->button_apply, FL_BLACK);
45 inline void DisableParagraphExtra ()
47 DeactivateParagraphExtraButtons();
48 fl_deactivate_object (fd_form_paragraph_extra->input_pextra_width);
49 fl_deactivate_object (fd_form_paragraph_extra->input_pextra_widthp);
50 fl_deactivate_object (fd_form_paragraph_extra->group_alignment);
51 fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_top);
52 fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_middle);
53 fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_bottom);
54 fl_deactivate_object (fd_form_paragraph_extra->text_warning);
55 fl_deactivate_object (fd_form_paragraph_extra->group_extraopt);
56 fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_indent);
57 fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_minipage);
58 fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_floatflt);
59 fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_hfill);
60 fl_deactivate_object (fd_form_paragraph_extra->radio_pextra_startmp);
63 inline void EnableParagraphExtra ()
65 ActivateParagraphExtraButtons();
66 fl_activate_object (fd_form_paragraph_extra->input_pextra_width);
67 fl_activate_object (fd_form_paragraph_extra->input_pextra_widthp);
68 fl_activate_object (fd_form_paragraph_extra->group_alignment);
69 fl_activate_object (fd_form_paragraph_extra->radio_pextra_top);
70 fl_activate_object (fd_form_paragraph_extra->radio_pextra_middle);
71 fl_activate_object (fd_form_paragraph_extra->radio_pextra_bottom);
72 fl_activate_object (fd_form_paragraph_extra->text_warning);
73 fl_activate_object (fd_form_paragraph_extra->group_extraopt);
74 fl_activate_object (fd_form_paragraph_extra->radio_pextra_indent);
75 fl_activate_object (fd_form_paragraph_extra->radio_pextra_minipage);
76 fl_activate_object (fd_form_paragraph_extra->radio_pextra_floatflt);
77 fl_activate_object (fd_form_paragraph_extra->radio_pextra_hfill);
78 fl_activate_object (fd_form_paragraph_extra->radio_pextra_startmp);
81 bool UpdateParagraphExtra()
84 if (current_view->getScreen() && current_view->available()) {
86 LyXParagraph* par = current_view->currentBuffer()->text->cursor.par;
88 EnableParagraphExtra();
90 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
91 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
92 fl_set_input(fd_form_paragraph_extra->input_pextra_width,
93 par->pextra_width.c_str());
94 fl_set_input(fd_form_paragraph_extra->input_pextra_widthp,
95 par->pextra_widthp.c_str());
96 switch(par->pextra_alignment) {
97 case MINIPAGE_ALIGN_TOP:
98 fl_set_button(fd_form_paragraph_extra->radio_pextra_top,1);
100 case MINIPAGE_ALIGN_MIDDLE:
101 fl_set_button(fd_form_paragraph_extra->radio_pextra_middle,1);
103 case MINIPAGE_ALIGN_BOTTOM:
104 fl_set_button(fd_form_paragraph_extra->radio_pextra_bottom,1);
107 fl_set_button(fd_form_paragraph_extra->radio_pextra_hfill,
109 fl_set_button(fd_form_paragraph_extra->radio_pextra_startmp,
110 par->pextra_start_minipage);
112 if (par->pextra_type == PEXTRA_INDENT) {
113 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,1);
114 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
115 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,0);
116 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
117 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
118 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
119 } else if (par->pextra_type == PEXTRA_MINIPAGE) {
120 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
121 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,1);
122 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,0);
123 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
124 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
125 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
126 } else if (par->pextra_type == PEXTRA_FLOATFLT) {
127 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
128 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
129 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,1);
130 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
131 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
132 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
134 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
135 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
136 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
137 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
138 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
139 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
140 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
142 if (par->pextra_type == PEXTRA_NONE)
143 ActivateParagraphExtraButtons();
145 fl_hide_object(fd_form_paragraph_extra->text_warning);
147 if (current_view->currentBuffer()->isReadonly()) {
148 DisableParagraphExtra();
149 fl_set_object_label(fd_form_paragraph_extra->text_warning,
150 _("Document is read-only. No changes to layout permitted."));
151 fl_show_object(fd_form_paragraph_extra->text_warning);
153 if (!update && fd_form_paragraph_extra->form_paragraph_extra->visible) {
154 fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
159 void ParagraphExtraOpen(FL_OBJECT *, long)
161 if (UpdateParagraphExtra()) {
162 if (fd_form_paragraph_extra->form_paragraph_extra->visible) {
163 fl_raise_form(fd_form_paragraph_extra->form_paragraph_extra);
165 fl_show_form(fd_form_paragraph_extra->form_paragraph_extra,
166 FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
167 _("ParagraphExtra Layout"));
172 void ParagraphExtraApplyCB(FL_OBJECT *, long)
174 if (current_view->getScreen() && current_view->available()) {
175 const FD_form_paragraph_extra* fd = fd_form_paragraph_extra;
177 *width = fl_get_input(fd->input_pextra_width),
178 *widthp = fl_get_input(fd->input_pextra_widthp);
180 *text = current_view->currentBuffer()->text;
186 start_minipage = false;
188 if (fl_get_button(fd_form_paragraph_extra->radio_pextra_indent)) {
189 type = PEXTRA_INDENT;
190 } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage)) {
191 type = PEXTRA_MINIPAGE;
192 hfill = fl_get_button(fd_form_paragraph_extra->radio_pextra_hfill);
194 fl_get_button(fd_form_paragraph_extra->radio_pextra_startmp);
195 if (fl_get_button(fd_form_paragraph_extra->radio_pextra_top))
196 alignment = MINIPAGE_ALIGN_TOP;
197 else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_middle))
198 alignment = MINIPAGE_ALIGN_MIDDLE;
199 else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_bottom))
200 alignment = MINIPAGE_ALIGN_BOTTOM;
201 } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt)) {
202 type = PEXTRA_FLOATFLT;
204 text->SetParagraphExtraOpt(type,width,widthp,alignment,hfill,
206 // current_view->redoCurrentBuffer();
207 current_view->currentBuffer()->update(1);
208 minibuffer->Set(_("ParagraphExtra layout set"));
209 // current_view->currentBuffer()->markDirty();
214 void ParagraphExtraCancelCB(FL_OBJECT *, long)
216 fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
219 void ParagraphExtraOKCB(FL_OBJECT *ob, long data)
221 ParagraphExtraCancelCB(ob,data);
222 ParagraphExtraApplyCB(ob,data);
225 void CheckPExtraOptCB(FL_OBJECT *ob, long)
232 ActivateParagraphExtraButtons();
234 if (ob == fd_form_paragraph_extra->radio_pextra_indent) {
235 n = fl_get_button(fd_form_paragraph_extra->radio_pextra_indent);
237 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
238 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,0);
239 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
240 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
241 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
242 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
243 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
245 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
246 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
247 ActivateParagraphExtraButtons();
249 } else if (ob == fd_form_paragraph_extra->radio_pextra_minipage) {
250 n = fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage);
252 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
253 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,0);
254 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
255 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
256 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
257 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
258 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
260 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
261 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
262 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
263 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
264 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
265 ActivateParagraphExtraButtons();
267 } else if (ob == fd_form_paragraph_extra->radio_pextra_floatflt) {
268 n = fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt);
270 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
271 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
272 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
273 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
274 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
275 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
276 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
278 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
279 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
280 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
281 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
282 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
283 ActivateParagraphExtraButtons();
289 static bool CheckInputWidth()
294 s1 = fl_get_input(fd_form_paragraph_extra->input_pextra_width);
295 s2 = fl_get_input(fd_form_paragraph_extra->input_pextra_widthp);
296 if (s1.empty() && s2.empty()) {
297 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
298 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
299 fl_hide_object(fd_form_paragraph_extra->text_warning);
300 DeactivateParagraphExtraButtons();
303 if (!s1.empty()) { // LyXLength parameter
304 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
305 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
306 if (!isValidLength(s1)) {
307 DeactivateParagraphExtraButtons();
308 fl_set_object_label(fd_form_paragraph_extra->text_warning,
309 _("Warning: Invalid Length (valid example: 10mm)"));
310 fl_show_object(fd_form_paragraph_extra->text_warning);
313 } else { // !s2.empty() % parameter
314 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
315 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
316 if ((atoi(s2.c_str()) < 0 ) || (atoi(s2.c_str()) > 100)) {
317 DeactivateParagraphExtraButtons();
318 fl_set_object_label(fd_form_paragraph_extra->text_warning,
319 _("Warning: Invalid percent value (0-100)"));
320 fl_show_object(fd_form_paragraph_extra->text_warning);
324 fl_hide_object(fd_form_paragraph_extra->text_warning);