4 #include FORMS_H_LOCATION
6 #include "layout_forms.h"
8 #include "minibuffer.h"
11 #include "BufferView.h"
12 #include "lyxparagraph.h"
16 extern FD_form_paragraph_extra * fd_form_paragraph_extra;
17 extern MiniBuffer * minibuffer;
18 extern BufferView * current_view;
19 extern void BeforeChange();
20 static bool CheckInputWidth();
22 inline 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);
30 inline void ActivateParagraphExtraButtons ()
32 fl_activate_object(fd_form_paragraph_extra->button_ok);
33 fl_activate_object(fd_form_paragraph_extra->button_apply);
34 fl_set_object_lcol(fd_form_paragraph_extra->button_ok, FL_BLACK);
35 fl_set_object_lcol(fd_form_paragraph_extra->button_apply, FL_BLACK);
38 inline void DisableParagraphExtra ()
40 DeactivateParagraphExtraButtons();
41 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
42 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
43 fl_deactivate_object(fd_form_paragraph_extra->group_alignment);
44 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
45 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
46 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
47 fl_deactivate_object(fd_form_paragraph_extra->text_warning);
48 fl_deactivate_object(fd_form_paragraph_extra->group_extraopt);
49 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_indent);
50 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_minipage);
51 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_floatflt);
52 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_hfill);
53 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_startmp);
56 inline void EnableParagraphExtra ()
58 ActivateParagraphExtraButtons();
59 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
60 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
61 fl_activate_object(fd_form_paragraph_extra->group_alignment);
62 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
63 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
64 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
65 fl_activate_object(fd_form_paragraph_extra->text_warning);
66 fl_activate_object(fd_form_paragraph_extra->group_extraopt);
67 fl_activate_object(fd_form_paragraph_extra->radio_pextra_indent);
68 fl_activate_object(fd_form_paragraph_extra->radio_pextra_minipage);
69 fl_activate_object(fd_form_paragraph_extra->radio_pextra_floatflt);
70 fl_activate_object(fd_form_paragraph_extra->radio_pextra_hfill);
71 fl_activate_object(fd_form_paragraph_extra->radio_pextra_startmp);
74 bool UpdateParagraphExtra()
77 if (current_view->getScreen() && current_view->available()) {
80 LyXParagraph * par = current_view->text->cursor.par;
82 LyXParagraph * par = current_view->buffer()->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->getScreen() && 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);
179 LyXText * text = current_view->text;
181 LyXText * text = current_view->buffer()->text;
183 int type = LyXParagraph::PEXTRA_NONE;
184 LyXParagraph::MINIPAGE_ALIGNMENT alignment =
185 LyXParagraph::MINIPAGE_ALIGN_TOP;
188 start_minipage = false;
190 if (fl_get_button(fd_form_paragraph_extra->radio_pextra_indent)) {
191 type = LyXParagraph::PEXTRA_INDENT;
192 } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage)) {
193 type = LyXParagraph::PEXTRA_MINIPAGE;
194 hfill = fl_get_button(fd_form_paragraph_extra->radio_pextra_hfill);
196 fl_get_button(fd_form_paragraph_extra->radio_pextra_startmp);
197 if (fl_get_button(fd_form_paragraph_extra->radio_pextra_top))
198 alignment = LyXParagraph::MINIPAGE_ALIGN_TOP;
199 else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_middle))
200 alignment = LyXParagraph::MINIPAGE_ALIGN_MIDDLE;
201 else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_bottom))
202 alignment = LyXParagraph::MINIPAGE_ALIGN_BOTTOM;
203 } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt)) {
204 type = LyXParagraph::PEXTRA_FLOATFLT;
206 text->SetParagraphExtraOpt(type, width, widthp, alignment, hfill,
209 current_view->update(1);
211 current_view->buffer()->update(1);
213 minibuffer->Set(_("ParagraphExtra layout set"));
219 void ParagraphExtraCancelCB(FL_OBJECT *, long)
221 fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
225 void ParagraphExtraOKCB(FL_OBJECT * ob, long data)
227 ParagraphExtraCancelCB(ob, data);
228 ParagraphExtraApplyCB(ob, data);
232 void CheckPExtraOptCB(FL_OBJECT * ob, long)
234 ActivateParagraphExtraButtons();
236 if (ob == fd_form_paragraph_extra->radio_pextra_indent) {
237 int n = fl_get_button(fd_form_paragraph_extra->radio_pextra_indent);
239 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
240 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
241 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
242 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
243 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
244 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
245 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
247 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
248 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
249 ActivateParagraphExtraButtons();
251 } else if (ob == fd_form_paragraph_extra->radio_pextra_minipage) {
252 int n = fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage);
254 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
255 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt, 0);
256 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
257 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
258 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
259 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
260 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
262 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
263 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
264 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
265 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
266 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
267 ActivateParagraphExtraButtons();
269 } else if (ob == fd_form_paragraph_extra->radio_pextra_floatflt) {
270 int n = fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt);
272 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent, 0);
273 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage, 0);
274 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
275 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
276 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
277 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
278 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
280 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
281 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
282 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
283 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
284 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
285 ActivateParagraphExtraButtons();
292 static bool CheckInputWidth()
294 string s1 = fl_get_input(fd_form_paragraph_extra->input_pextra_width);
295 string 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);