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 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()) {
79 LyXParagraph * par = current_view->buffer()->text->cursor.par;
81 EnableParagraphExtra();
83 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
84 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
85 fl_set_input(fd_form_paragraph_extra->input_pextra_width,
86 par->pextra_width.c_str());
87 fl_set_input(fd_form_paragraph_extra->input_pextra_widthp,
88 par->pextra_widthp.c_str());
89 switch(par->pextra_alignment) {
90 case MINIPAGE_ALIGN_TOP:
91 fl_set_button(fd_form_paragraph_extra->radio_pextra_top,1);
93 case MINIPAGE_ALIGN_MIDDLE:
94 fl_set_button(fd_form_paragraph_extra->radio_pextra_middle,1);
96 case MINIPAGE_ALIGN_BOTTOM:
97 fl_set_button(fd_form_paragraph_extra->radio_pextra_bottom,1);
100 fl_set_button(fd_form_paragraph_extra->radio_pextra_hfill,
102 fl_set_button(fd_form_paragraph_extra->radio_pextra_startmp,
103 par->pextra_start_minipage);
105 if (par->pextra_type == PEXTRA_INDENT) {
106 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,1);
107 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
108 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,0);
109 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
110 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
111 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
112 } else if (par->pextra_type == PEXTRA_MINIPAGE) {
113 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
114 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,1);
115 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,0);
116 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
117 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
118 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
119 } else if (par->pextra_type == PEXTRA_FLOATFLT) {
120 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
121 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
122 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,1);
123 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
124 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
125 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
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_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
130 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
131 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
132 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
133 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
135 if (par->pextra_type == PEXTRA_NONE)
136 ActivateParagraphExtraButtons();
138 fl_hide_object(fd_form_paragraph_extra->text_warning);
140 if (current_view->buffer()->isReadonly()) {
141 DisableParagraphExtra();
142 fl_set_object_label(fd_form_paragraph_extra->text_warning,
143 _("Document is read-only. 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);
152 void ParagraphExtraOpen(FL_OBJECT *, long)
154 if (UpdateParagraphExtra()) {
155 if (fd_form_paragraph_extra->form_paragraph_extra->visible) {
156 fl_raise_form(fd_form_paragraph_extra->form_paragraph_extra);
158 fl_show_form(fd_form_paragraph_extra->form_paragraph_extra,
159 FL_PLACE_MOUSE, FL_FULLBORDER,
160 _("ParagraphExtra Layout"));
165 void ParagraphExtraApplyCB(FL_OBJECT *, long)
167 if (current_view->getScreen() && current_view->available()) {
168 FD_form_paragraph_extra const * fd = fd_form_paragraph_extra;
169 const char * width = fl_get_input(fd->input_pextra_width);
170 const char * widthp = fl_get_input(fd->input_pextra_widthp);
171 LyXText * text = current_view->buffer()->text;
172 int type = PEXTRA_NONE;
176 start_minipage = false;
178 if (fl_get_button(fd_form_paragraph_extra->radio_pextra_indent)) {
179 type = PEXTRA_INDENT;
180 } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage)) {
181 type = PEXTRA_MINIPAGE;
182 hfill = fl_get_button(fd_form_paragraph_extra->radio_pextra_hfill);
184 fl_get_button(fd_form_paragraph_extra->radio_pextra_startmp);
185 if (fl_get_button(fd_form_paragraph_extra->radio_pextra_top))
186 alignment = MINIPAGE_ALIGN_TOP;
187 else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_middle))
188 alignment = MINIPAGE_ALIGN_MIDDLE;
189 else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_bottom))
190 alignment = MINIPAGE_ALIGN_BOTTOM;
191 } else if (fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt)) {
192 type = PEXTRA_FLOATFLT;
194 text->SetParagraphExtraOpt(type,width,widthp,alignment,hfill,
196 current_view->buffer()->update(1);
197 minibuffer->Set(_("ParagraphExtra layout set"));
202 void ParagraphExtraCancelCB(FL_OBJECT *, long)
204 fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra);
207 void ParagraphExtraOKCB(FL_OBJECT *ob, long data)
209 ParagraphExtraCancelCB(ob,data);
210 ParagraphExtraApplyCB(ob,data);
213 void CheckPExtraOptCB(FL_OBJECT *ob, long)
220 ActivateParagraphExtraButtons();
222 if (ob == fd_form_paragraph_extra->radio_pextra_indent) {
223 n = fl_get_button(fd_form_paragraph_extra->radio_pextra_indent);
225 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
226 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,0);
227 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
228 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
229 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
230 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
231 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
233 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
234 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
235 ActivateParagraphExtraButtons();
237 } else if (ob == fd_form_paragraph_extra->radio_pextra_minipage) {
238 n = fl_get_button(fd_form_paragraph_extra->radio_pextra_minipage);
240 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
241 fl_set_button(fd_form_paragraph_extra->radio_pextra_floatflt,0);
242 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
243 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
244 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
245 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
246 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
248 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
249 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
250 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
251 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
252 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
253 ActivateParagraphExtraButtons();
255 } else if (ob == fd_form_paragraph_extra->radio_pextra_floatflt) {
256 n = fl_get_button(fd_form_paragraph_extra->radio_pextra_floatflt);
258 fl_set_button(fd_form_paragraph_extra->radio_pextra_indent,0);
259 fl_set_button(fd_form_paragraph_extra->radio_pextra_minipage,0);
260 fl_activate_object(fd_form_paragraph_extra->input_pextra_width);
261 fl_activate_object(fd_form_paragraph_extra->input_pextra_widthp);
262 fl_activate_object(fd_form_paragraph_extra->radio_pextra_top);
263 fl_activate_object(fd_form_paragraph_extra->radio_pextra_middle);
264 fl_activate_object(fd_form_paragraph_extra->radio_pextra_bottom);
266 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_width);
267 fl_deactivate_object(fd_form_paragraph_extra->input_pextra_widthp);
268 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_top);
269 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_middle);
270 fl_deactivate_object(fd_form_paragraph_extra->radio_pextra_bottom);
271 ActivateParagraphExtraButtons();
277 static bool CheckInputWidth()
282 s1 = fl_get_input(fd_form_paragraph_extra->input_pextra_width);
283 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);