4 #include FORMS_H_LOCATION
6 #include "layout_forms.h"
8 #include "minibuffer.h"
11 #include "BufferView.h"
12 #include "lyxparagraph.h"
17 extern FD_form_paragraph_extra * fd_form_paragraph_extra;
18 extern BufferView * current_view;
19 static bool CheckInputWidth();
22 void DeactivateParagraphExtraButtons ()
24 fl_deactivate_object(fd_form_paragraph_extra->button_ok);
25 fl_deactivate_object(fd_form_paragraph_extra->button_apply);
26 fl_set_object_lcol(fd_form_paragraph_extra->button_ok, FL_INACTIVE);
27 fl_set_object_lcol(fd_form_paragraph_extra->button_apply, FL_INACTIVE);
31 void ActivateParagraphExtraButtons ()
33 fl_activate_object(fd_form_paragraph_extra->button_ok);
34 fl_activate_object(fd_form_paragraph_extra->button_apply);
35 fl_set_object_lcol(fd_form_paragraph_extra->button_ok, FL_BLACK);
36 fl_set_object_lcol(fd_form_paragraph_extra->button_apply, FL_BLACK);
40 void DisableParagraphExtra ()
42 DeactivateParagraphExtraButtons();
43 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
44 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
45 fl_deactivate_object(fd_form_paragraph_extra->group_alignment);
46 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
47 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
48 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
49 fl_deactivate_object(fd_form_paragraph_extra->text_warning);
50 fl_deactivate_object(fd_form_paragraph_extra->group_extraopt);
51 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_indent);
52 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_minipage);
53 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_floatflt);
54 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_hfill);
55 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_startmp);
59 void EnableParagraphExtra ()
61 ActivateParagraphExtraButtons();
62 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
63 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
64 fl_activate_object(fd_form_paragraph_extra->group_alignment);
65 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
66 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
67 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
68 fl_activate_object(fd_form_paragraph_extra->text_warning);
69 fl_activate_object(fd_form_paragraph_extra->group_extraopt);
70 fl_activate_object(fd_form_paragraph_extra->radio_pextra_indent);
71 fl_activate_object(fd_form_paragraph_extra->radio_pextra_minipage);
72 fl_activate_object(fd_form_paragraph_extra->radio_pextra_floatflt);
73 fl_activate_object(fd_form_paragraph_extra->radio_pextra_hfill);
74 fl_activate_object(fd_form_paragraph_extra->radio_pextra_startmp);
78 bool UpdateParagraphExtra()
81 if (current_view->available()) {
83 LyXParagraph * par = current_view->text->cursor.par();
85 EnableParagraphExtra();
87 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
88 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
89 fl_set_input(fd_form_paragraph_extra->input_pextra_width,
90 par->pextra_width.c_str());
91 fl_set_input(fd_form_paragraph_extra->input_pextra_widthp,
92 par->pextra_widthp.c_str());
93 switch(par->pextra_alignment) {
94 case LyXParagraph::MINIPAGE_ALIGN_TOP:
95 fl_set_button(fd_form_paragraph_extra->radio_pextra_top, 1);
97 case LyXParagraph::MINIPAGE_ALIGN_MIDDLE:
98 fl_set_button(fd_form_paragraph_extra->radio_pextra_middle, 1);
100 case LyXParagraph::MINIPAGE_ALIGN_BOTTOM:
101 fl_set_button(fd_form_paragraph_extra->radio_pextra_bottom, 1);
104 fl_set_button(fd_form_paragraph_extra->radio_pextra_hfill,
106 fl_set_button(fd_form_paragraph_extra->radio_pextra_startmp,
107 par->pextra_start_minipage);
109 if (par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
110 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 1);
111 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
112 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
113 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
114 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
115 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
116 } else if (par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
117 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
118 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 1);
119 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
120 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
121 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
122 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
123 } else if (par->pextra_type == LyXParagraph::PEXTRA_FLOATFLT) {
124 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
125 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
126 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 1);
127 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
128 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
129 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
131 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
132 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
133 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
134 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
135 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
136 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
137 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
139 if (par->pextra_type == LyXParagraph::PEXTRA_NONE)
140 ActivateParagraphExtraButtons();
142 fl_hide_object(fd_form_paragraph_extra->text_warning);
144 if (current_view->buffer()->isReadonly()) {
145 DisableParagraphExtra();
146 fl_set_object_label(fd_form_paragraph_extra->text_warning,
147 _("Document is read-only. "
148 "No changes to layout permitted."));
149 fl_show_object(fd_form_paragraph_extra->text_warning);
151 if (!update && fd_form_paragraph_extra->form_paragraph_extra->visible) {
152 fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
158 void ParagraphExtraOpen(FL_OBJECT *, long)
160 if (UpdateParagraphExtra()) {
161 if (fd_form_paragraph_extra->form_paragraph_extra->visible) {
162 fl_raise_form(fd_form_paragraph_extra->form_paragraph_extra);
164 fl_show_form(fd_form_paragraph_extra->form_paragraph_extra,
165 FL_PLACE_MOUSE, FL_FULLBORDER,
166 _("ParagraphExtra Layout"));
172 void ParagraphExtraApplyCB(FL_OBJECT *, long)
174 if (current_view->available()) {
175 FD_form_paragraph_extra const * fd = fd_form_paragraph_extra;
176 char const * width = fl_get_input(fd->input_pextra_width);
177 char const * widthp = fl_get_input(fd->input_pextra_widthp);
178 LyXText * text = current_view->text;
179 int type = LyXParagraph::PEXTRA_NONE;
180 LyXParagraph::MINIPAGE_ALIGNMENT alignment =
181 LyXParagraph::MINIPAGE_ALIGN_TOP;
184 start_minipage = false;
186 if (fl_get_button(fd_form_paragraph_extra->radio_pextra_indent)) {
187 type = LyXParagraph::PEXTRA_INDENT;
188 } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage)) {
189 type = LyXParagraph::PEXTRA_MINIPAGE;
190 hfill = fl_get_button(fd_form_paragraph_extra->radio_pextra_hfill);
192 fl_get_button(fd_form_paragraph_extra->radio_pextra_startmp);
193 if (fl_get_button(fd_form_paragraph_extra->radio_pextra_top))
194 alignment = LyXParagraph::MINIPAGE_ALIGN_TOP;
195 else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_middle))
196 alignment = LyXParagraph::MINIPAGE_ALIGN_MIDDLE;
197 else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_bottom))
198 alignment = LyXParagraph::MINIPAGE_ALIGN_BOTTOM;
199 } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt)) {
200 type = LyXParagraph::PEXTRA_FLOATFLT;
202 text->SetParagraphExtraOpt(current_view, type, width, widthp, alignment, hfill,
204 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
205 current_view->owner()->getMiniBuffer()->
206 Set(_("ParagraphExtra layout set"));
212 void ParagraphExtraCancelCB(FL_OBJECT *, long)
214 fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
218 void ParagraphExtraOKCB(FL_OBJECT * ob, long data)
220 ParagraphExtraCancelCB(ob, data);
221 ParagraphExtraApplyCB(ob, data);
225 void CheckPExtraOptCB(FL_OBJECT * ob, long)
227 ActivateParagraphExtraButtons();
229 if (ob == fd_form_paragraph_extra->radio_pextra_indent) {
230 int n = fl_get_button(fd_form_paragraph_extra->radio_pextra_indent);
232 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
233 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
234 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
235 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
236 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
237 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
238 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
240 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
241 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
242 ActivateParagraphExtraButtons();
244 } else if (ob == fd_form_paragraph_extra->radio_pextra_minipage) {
245 int n = fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage);
247 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
248 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
249 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
250 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
251 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
252 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
253 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
255 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
256 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
257 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
258 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
259 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
260 ActivateParagraphExtraButtons();
262 } else if (ob == fd_form_paragraph_extra->radio_pextra_floatflt) {
263 int n = fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt);
265 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
266 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
267 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
268 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
269 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
270 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
271 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
273 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
274 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
275 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
276 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
277 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
278 ActivateParagraphExtraButtons();
286 bool CheckInputWidth()
288 string s1 = fl_get_input(fd_form_paragraph_extra->input_pextra_width);
289 string s2 = fl_get_input(fd_form_paragraph_extra->input_pextra_widthp);
290 if (s1.empty() && s2.empty()) {
291 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
292 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
293 fl_hide_object(fd_form_paragraph_extra->text_warning);
294 DeactivateParagraphExtraButtons();
297 if (!s1.empty()) { // LyXLength parameter
298 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
299 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
300 if (!isValidLength(s1)) {
301 DeactivateParagraphExtraButtons();
302 fl_set_object_label(fd_form_paragraph_extra->text_warning,
303 _("Warning: Invalid Length (valid example: 10mm)"));
304 fl_show_object(fd_form_paragraph_extra->text_warning);
307 } else { // !s2.empty() % parameter
308 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
309 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
310 if ((atoi(s2.c_str()) < 0 ) || (atoi(s2.c_str()) > 100)) {
311 DeactivateParagraphExtraButtons();
312 fl_set_object_label(fd_form_paragraph_extra->text_warning,
313 _("Warning: Invalid percent value (0-100)"));
314 fl_show_object(fd_form_paragraph_extra->text_warning);
318 fl_hide_object(fd_form_paragraph_extra->text_warning);