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();
21 inline void DeactivateParagraphExtraButtons ()
23 fl_deactivate_object(fd_form_paragraph_extra->button_ok);
24 fl_deactivate_object(fd_form_paragraph_extra->button_apply);
25 fl_set_object_lcol(fd_form_paragraph_extra->button_ok, FL_INACTIVE);
26 fl_set_object_lcol(fd_form_paragraph_extra->button_apply, FL_INACTIVE);
29 inline void ActivateParagraphExtraButtons ()
31 fl_activate_object(fd_form_paragraph_extra->button_ok);
32 fl_activate_object(fd_form_paragraph_extra->button_apply);
33 fl_set_object_lcol(fd_form_paragraph_extra->button_ok, FL_BLACK);
34 fl_set_object_lcol(fd_form_paragraph_extra->button_apply, FL_BLACK);
37 inline void DisableParagraphExtra ()
39 DeactivateParagraphExtraButtons();
40 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
41 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
42 fl_deactivate_object(fd_form_paragraph_extra->group_alignment);
43 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
44 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
45 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
46 fl_deactivate_object(fd_form_paragraph_extra->text_warning);
47 fl_deactivate_object(fd_form_paragraph_extra->group_extraopt);
48 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_indent);
49 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_minipage);
50 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_floatflt);
51 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_hfill);
52 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_startmp);
55 inline void EnableParagraphExtra ()
57 ActivateParagraphExtraButtons();
58 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
59 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
60 fl_activate_object(fd_form_paragraph_extra->group_alignment);
61 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
62 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
63 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
64 fl_activate_object(fd_form_paragraph_extra->text_warning);
65 fl_activate_object(fd_form_paragraph_extra->group_extraopt);
66 fl_activate_object(fd_form_paragraph_extra->radio_pextra_indent);
67 fl_activate_object(fd_form_paragraph_extra->radio_pextra_minipage);
68 fl_activate_object(fd_form_paragraph_extra->radio_pextra_floatflt);
69 fl_activate_object(fd_form_paragraph_extra->radio_pextra_hfill);
70 fl_activate_object(fd_form_paragraph_extra->radio_pextra_startmp);
73 bool UpdateParagraphExtra()
76 if (current_view->getScreen() && current_view->available()) {
78 LyXParagraph * par = current_view->text->cursor.par;
80 EnableParagraphExtra();
82 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
83 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
84 fl_set_input(fd_form_paragraph_extra->input_pextra_width,
85 par->pextra_width.c_str());
86 fl_set_input(fd_form_paragraph_extra->input_pextra_widthp,
87 par->pextra_widthp.c_str());
88 switch(par->pextra_alignment) {
89 case LyXParagraph::MINIPAGE_ALIGN_TOP:
90 fl_set_button(fd_form_paragraph_extra->radio_pextra_top, 1);
92 case LyXParagraph::MINIPAGE_ALIGN_MIDDLE:
93 fl_set_button(fd_form_paragraph_extra->radio_pextra_middle, 1);
95 case LyXParagraph::MINIPAGE_ALIGN_BOTTOM:
96 fl_set_button(fd_form_paragraph_extra->radio_pextra_bottom, 1);
99 fl_set_button(fd_form_paragraph_extra->radio_pextra_hfill,
101 fl_set_button(fd_form_paragraph_extra->radio_pextra_startmp,
102 par->pextra_start_minipage);
104 if (par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
105 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 1);
106 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
107 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
108 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
109 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
110 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
111 } else if (par->pextra_type == LyXParagraph::PEXTRA_MINIPAGE) {
112 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
113 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 1);
114 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
115 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
116 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
117 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
118 } else if (par->pextra_type == LyXParagraph::PEXTRA_FLOATFLT) {
119 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
120 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
121 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 1);
122 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
123 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
124 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
126 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
127 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
128 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
129 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
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 if (par->pextra_type == LyXParagraph::PEXTRA_NONE)
135 ActivateParagraphExtraButtons();
137 fl_hide_object(fd_form_paragraph_extra->text_warning);
139 if (current_view->buffer()->isReadonly()) {
140 DisableParagraphExtra();
141 fl_set_object_label(fd_form_paragraph_extra->text_warning,
142 _("Document is read-only. "
143 "No changes to layout permitted."));
144 fl_show_object(fd_form_paragraph_extra->text_warning);
146 if (!update && fd_form_paragraph_extra->form_paragraph_extra->visible) {
147 fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
153 void ParagraphExtraOpen(FL_OBJECT *, long)
155 if (UpdateParagraphExtra()) {
156 if (fd_form_paragraph_extra->form_paragraph_extra->visible) {
157 fl_raise_form(fd_form_paragraph_extra->form_paragraph_extra);
159 fl_show_form(fd_form_paragraph_extra->form_paragraph_extra,
160 FL_PLACE_MOUSE, FL_FULLBORDER,
161 _("ParagraphExtra Layout"));
167 void ParagraphExtraApplyCB(FL_OBJECT *, long)
169 if (current_view->getScreen() && current_view->available()) {
170 FD_form_paragraph_extra const * fd = fd_form_paragraph_extra;
171 char const * width = fl_get_input(fd->input_pextra_width);
172 char const * widthp = fl_get_input(fd->input_pextra_widthp);
173 LyXText * text = current_view->text;
174 int type = LyXParagraph::PEXTRA_NONE;
175 LyXParagraph::MINIPAGE_ALIGNMENT alignment =
176 LyXParagraph::MINIPAGE_ALIGN_TOP;
179 start_minipage = false;
181 if (fl_get_button(fd_form_paragraph_extra->radio_pextra_indent)) {
182 type = LyXParagraph::PEXTRA_INDENT;
183 } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage)) {
184 type = LyXParagraph::PEXTRA_MINIPAGE;
185 hfill = fl_get_button(fd_form_paragraph_extra->radio_pextra_hfill);
187 fl_get_button(fd_form_paragraph_extra->radio_pextra_startmp);
188 if (fl_get_button(fd_form_paragraph_extra->radio_pextra_top))
189 alignment = LyXParagraph::MINIPAGE_ALIGN_TOP;
190 else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_middle))
191 alignment = LyXParagraph::MINIPAGE_ALIGN_MIDDLE;
192 else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_bottom))
193 alignment = LyXParagraph::MINIPAGE_ALIGN_BOTTOM;
194 } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt)) {
195 type = LyXParagraph::PEXTRA_FLOATFLT;
197 text->SetParagraphExtraOpt(type, width, widthp, alignment, hfill,
199 current_view->update(1);
200 current_view->owner()->getMiniBuffer()->
201 Set(_("ParagraphExtra layout set"));
207 void ParagraphExtraCancelCB(FL_OBJECT *, long)
209 fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
213 void ParagraphExtraOKCB(FL_OBJECT * ob, long data)
215 ParagraphExtraCancelCB(ob, data);
216 ParagraphExtraApplyCB(ob, data);
220 void CheckPExtraOptCB(FL_OBJECT * ob, long)
222 ActivateParagraphExtraButtons();
224 if (ob == fd_form_paragraph_extra->radio_pextra_indent) {
225 int n = fl_get_button(fd_form_paragraph_extra->radio_pextra_indent);
227 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
228 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
229 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
230 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
231 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
232 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
233 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
235 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
236 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
237 ActivateParagraphExtraButtons();
239 } else if (ob == fd_form_paragraph_extra->radio_pextra_minipage) {
240 int n = fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage);
242 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
243 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
244 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
245 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
246 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
247 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
248 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
250 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
251 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
252 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
253 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
254 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
255 ActivateParagraphExtraButtons();
257 } else if (ob == fd_form_paragraph_extra->radio_pextra_floatflt) {
258 int n = fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt);
260 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
261 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
262 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
263 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
264 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
265 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
266 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
268 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
269 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
270 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
271 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
272 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
273 ActivateParagraphExtraButtons();
280 static bool CheckInputWidth()
282 string s1 = fl_get_input(fd_form_paragraph_extra->input_pextra_width);
283 string s2 = fl_get_input(fd_form_paragraph_extra->input_pextra_widthp);
284 if (s1.empty() && s2.empty()) {
285 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
286 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
287 fl_hide_object(fd_form_paragraph_extra->text_warning);
288 DeactivateParagraphExtraButtons();
291 if (!s1.empty()) { // LyXLength parameter
292 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
293 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
294 if (!isValidLength(s1)) {
295 DeactivateParagraphExtraButtons();
296 fl_set_object_label(fd_form_paragraph_extra->text_warning,
297 _("Warning: Invalid Length (valid example: 10mm)"));
298 fl_show_object(fd_form_paragraph_extra->text_warning);
301 } else { // !s2.empty() % parameter
302 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
303 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
304 if ((atoi(s2.c_str()) < 0 ) || (atoi(s2.c_str()) > 100)) {
305 DeactivateParagraphExtraButtons();
306 fl_set_object_label(fd_form_paragraph_extra->text_warning,
307 _("Warning: Invalid percent value (0-100)"));
308 fl_show_object(fd_form_paragraph_extra->text_warning);
312 fl_hide_object(fd_form_paragraph_extra->text_warning);