5 #include FORMS_H_LOCATION
6 #include "layout_forms.h"
10 #include "support/filetools.h"
12 #include "minibuffer.h"
14 #include "lyx_gui_misc.h"
15 #include "BufferView.h"
19 extern FD_form_paper * fd_form_paper;
20 extern BufferView * current_view;
24 void DeactivatePaperButtons ()
26 fl_deactivate_object (fd_form_paper->button_ok);
27 fl_deactivate_object (fd_form_paper->button_apply);
28 fl_set_object_lcol (fd_form_paper->button_ok, FL_INACTIVE);
29 fl_set_object_lcol (fd_form_paper->button_apply, FL_INACTIVE);
34 void ActivatePaperButtons ()
36 fl_activate_object (fd_form_paper->button_ok);
37 fl_activate_object (fd_form_paper->button_apply);
38 fl_set_object_lcol (fd_form_paper->button_ok, FL_BLACK);
39 fl_set_object_lcol (fd_form_paper->button_apply, FL_BLACK);
44 void DisablePaperLayout()
46 DeactivatePaperButtons();
47 fl_deactivate_object (fd_form_paper->choice_paperpackage);
48 fl_deactivate_object (fd_form_paper->greoup_radio_orientation);
49 fl_deactivate_object (fd_form_paper->radio_portrait);
50 fl_deactivate_object (fd_form_paper->radio_landscape);
51 fl_deactivate_object (fd_form_paper->choice_papersize2);
52 fl_deactivate_object (fd_form_paper->push_use_geometry);
53 fl_deactivate_object (fd_form_paper->input_custom_width);
54 fl_deactivate_object (fd_form_paper->input_custom_height);
55 fl_deactivate_object (fd_form_paper->input_top_margin);
56 fl_deactivate_object (fd_form_paper->input_bottom_margin);
57 fl_deactivate_object (fd_form_paper->input_left_margin);
58 fl_deactivate_object (fd_form_paper->input_right_margin);
59 fl_deactivate_object (fd_form_paper->input_head_height);
60 fl_deactivate_object (fd_form_paper->input_head_sep);
61 fl_deactivate_object (fd_form_paper->input_foot_skip);
62 fl_deactivate_object (fd_form_paper->text_warning);
67 void EnablePaperLayout()
69 ActivatePaperButtons();
70 fl_activate_object (fd_form_paper->choice_paperpackage);
71 fl_activate_object (fd_form_paper->greoup_radio_orientation);
72 fl_activate_object (fd_form_paper->radio_portrait);
73 fl_activate_object (fd_form_paper->radio_landscape);
74 fl_activate_object (fd_form_paper->choice_papersize2);
75 fl_activate_object (fd_form_paper->push_use_geometry);
76 fl_activate_object (fd_form_paper->input_custom_width);
77 fl_activate_object (fd_form_paper->input_custom_height);
78 fl_activate_object (fd_form_paper->input_top_margin);
79 fl_activate_object (fd_form_paper->input_bottom_margin);
80 fl_activate_object (fd_form_paper->input_left_margin);
81 fl_activate_object (fd_form_paper->input_right_margin);
82 fl_activate_object (fd_form_paper->input_head_height);
83 fl_activate_object (fd_form_paper->input_head_sep);
84 fl_activate_object (fd_form_paper->input_foot_skip);
85 fl_activate_object (fd_form_paper->text_warning);
90 void checkMarginValues()
94 fl_hide_object(fd_form_paper->text_warning);
95 ActivatePaperButtons();
97 allEmpty = (!strlen(fl_get_input(fd_form_paper->input_top_margin)) &&
98 !strlen(fl_get_input(fd_form_paper->input_bottom_margin)) &&
99 !strlen(fl_get_input(fd_form_paper->input_left_margin)) &&
100 !strlen(fl_get_input(fd_form_paper->input_right_margin)) &&
101 !strlen(fl_get_input(fd_form_paper->input_head_height)) &&
102 !strlen(fl_get_input(fd_form_paper->input_head_sep)) &&
103 !strlen(fl_get_input(fd_form_paper->input_foot_skip)) &&
104 !strlen(fl_get_input(fd_form_paper->input_custom_width)) &&
105 !strlen(fl_get_input(fd_form_paper->input_custom_height)));
107 fl_set_button(fd_form_paper->push_use_geometry, 1);
112 bool UpdateLayoutPaper()
115 if (!current_view->available())
119 BufferParams * params = ¤t_view->buffer()->params;
121 fl_set_choice(fd_form_paper->choice_papersize2,
122 params->papersize2 + 1);
123 fl_set_choice(fd_form_paper->choice_paperpackage,
124 params->paperpackage + 1);
125 fl_set_button(fd_form_paper->push_use_geometry,
126 params->use_geometry);
127 fl_set_button(fd_form_paper->radio_portrait, 0);
128 fl_set_button(fd_form_paper->radio_landscape, 0);
129 if (params->orientation == BufferParams::ORIENTATION_LANDSCAPE)
130 fl_set_button(fd_form_paper->radio_landscape, 1);
132 fl_set_button(fd_form_paper->radio_portrait, 1);
134 fl_set_input(fd_form_paper->input_custom_width,
135 params->paperwidth.c_str());
136 fl_set_input(fd_form_paper->input_custom_height,
137 params->paperheight.c_str());
138 fl_set_input(fd_form_paper->input_left_margin,
139 params->leftmargin.c_str());
140 fl_set_input(fd_form_paper->input_top_margin,
141 params->topmargin.c_str());
142 fl_set_input(fd_form_paper->input_right_margin,
143 params->rightmargin.c_str());
144 fl_set_input(fd_form_paper->input_bottom_margin,
145 params->bottommargin.c_str());
146 fl_set_input(fd_form_paper->input_head_height,
147 params->headheight.c_str());
148 fl_set_input(fd_form_paper->input_head_sep,
149 params->headsep.c_str());
150 fl_set_input(fd_form_paper->input_foot_skip,
151 params->footskip.c_str());
152 fl_set_focus_object(fd_form_paper->form_paper,
153 fd_form_paper->choice_papersize2);
154 fl_hide_object(fd_form_paper->text_warning);
155 if (current_view->buffer()->isReadonly()) {
156 DisablePaperLayout();
157 fl_set_object_label(fd_form_paper->text_warning,
158 _("Document is read-only."
159 " No changes to layout"
161 fl_show_object(fd_form_paper->text_warning);
165 } else if (fd_form_paper->form_paper->visible) {
166 fl_hide_form(fd_form_paper->form_paper);
172 void MenuLayoutPaper()
174 if (UpdateLayoutPaper()) {
175 if (fd_form_paper->form_paper->visible) {
176 fl_raise_form(fd_form_paper->form_paper);
178 fl_show_form(fd_form_paper->form_paper,
179 FL_PLACE_MOUSE, FL_FULLBORDER,
186 void PaperApplyCB(FL_OBJECT *, long)
188 if (!current_view->available())
191 BufferParams * params = ¤t_view->buffer()->params;
193 FD_form_paper const * fd = fd_form_paper;
195 params->papersize2 = fl_get_choice(fd->choice_papersize2)-1;
196 params->paperpackage = fl_get_choice(fd->choice_paperpackage)-1;
197 params->use_geometry = fl_get_button(fd_form_paper->push_use_geometry);
198 if (fl_get_button(fd_form_paper->radio_landscape))
199 params->orientation = BufferParams::ORIENTATION_LANDSCAPE;
201 params->orientation = BufferParams::ORIENTATION_PORTRAIT;
202 params->paperwidth = fl_get_input(fd->input_custom_width);
203 params->paperheight = fl_get_input(fd->input_custom_height);
204 params->leftmargin = fl_get_input(fd->input_left_margin);
205 params->topmargin = fl_get_input(fd->input_top_margin);
206 params->rightmargin = fl_get_input(fd->input_right_margin);
207 params->bottommargin = fl_get_input(fd->input_bottom_margin);
208 params->headheight = fl_get_input(fd->input_head_height);
209 params->headsep = fl_get_input(fd->input_head_sep);
210 params->footskip = fl_get_input(fd->input_foot_skip);
211 current_view->buffer()->setPaperStuff();
212 current_view->owner()->getMiniBuffer()->Set(_("Paper layout set"));
213 current_view->buffer()->markDirty();
219 void PaperCancelCB(FL_OBJECT *, long)
221 fl_hide_form(fd_form_paper->form_paper);
225 void PaperOKCB(FL_OBJECT * ob, long data)
227 PaperCancelCB(ob, data);
228 PaperApplyCB(ob, data);
232 void PaperMarginsCB(FL_OBJECT * ob, long)
234 FD_form_paper const * fd = fd_form_paper;
239 if (ob == fd->choice_papersize2) {
240 val = fl_get_choice(fd->choice_papersize2)-1;
241 if (val == BufferParams::VM_PAPER_DEFAULT) {
242 fl_set_button(fd->push_use_geometry, 0);
245 if (val != BufferParams::VM_PAPER_USLETTER
246 && val != BufferParams::VM_PAPER_USLEGAL
247 && val != BufferParams::VM_PAPER_USEXECUTIVE
248 && val != BufferParams::VM_PAPER_A4
249 && val != BufferParams::VM_PAPER_A5
250 && val != BufferParams::VM_PAPER_B5) {
251 fl_set_button(fd->push_use_geometry, 1);
253 fl_set_choice(fd->choice_paperpackage, BufferParams::PACKAGE_NONE + 1);
255 } else if (ob == fd->choice_paperpackage) {
256 val = fl_get_choice(fd->choice_paperpackage)-1;
257 if (val != BufferParams::PACKAGE_NONE) {
258 fl_set_choice(fd->choice_papersize2,
259 BufferParams::VM_PAPER_DEFAULT + 1);
260 fl_set_button(fd->push_use_geometry, 0);
262 } else if (ob == fd->input_custom_width
263 || ob == fd->input_custom_height
264 || ob == fd->input_left_margin
265 || ob == fd->input_right_margin
266 || ob == fd->input_top_margin
267 || ob == fd->input_bottom_margin
268 || ob == fd->input_head_height
269 || ob == fd->input_head_sep
270 || ob == fd->input_foot_skip) {
271 str = fl_get_input(ob);
272 if (!str.empty() && !isValidLength(str)) {
273 fl_set_object_label(fd_form_paper->text_warning,
274 _("Warning: Invalid Length"
275 " (valid example: 10mm)"));
276 fl_show_object(fd_form_paper->text_warning);
277 DeactivatePaperButtons();
278 } else if (!str.empty())
279 fl_set_button(fd->push_use_geometry, 1);