1 /* options - global options that may be set on the command line
2 Copyright (C) 1996-2017 Paul Sheer
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307, USA.
18 */
19
20
21 #include <config.h>
22 #include "edit.h"
23 #include "cmdlineopt.h"
24 #include "editoptions.h"
25 #include "mad.h"
26
27 extern Window main_window;
28
29 extern int option_save_setup_on_exit;
30 extern int option_suppress_load_files;
31 extern int option_toolbar;
32 extern int option_toolhint_milliseconds;
33
34 extern int option_text_fg_normal;
35 extern int option_text_fg_bold;
36 extern int option_text_fg_italic;
37
38 extern int option_text_bg_normal;
39 extern int option_text_bg_marked;
40 extern int option_text_bg_highlighted;
41 extern int option_hint_messages;
42 extern int option_cursor_blink_rate;
43 extern int option_pull_down_window_list;
44 extern int option_find_bracket;
45 extern int option_edit_right_extreme;
46 extern int option_edit_left_extreme;
47 extern int option_edit_top_extreme;
48 extern int option_edit_bottom_extreme;
49 extern int option_typing_replaces_selection;
50 extern int option_latin2;
51 extern int option_utf_interpretation;
52 extern int option_reverse_hebrew;
53 extern int option_rgb_order;
54 extern int option_interchar_spacing;
55 extern int option_file_browser_width;
56 extern int option_file_browser_height;
57 extern int option_shell_command_line_sticky;
58 extern int option_shell_command_line_pty;
59 extern int option_invert_colors;
60 extern int option_invert_crome;
61
62 extern int option_invert_red_green;
63 extern int option_invert_green_blue;
64 extern int option_invert_red_blue;
65
66 extern int last_unichar_left;
67 extern int last_unichar_right;
68
69 extern int option_xor_cursor;
70 extern int option_flashing_cursor;
71 extern int option_long_whitespace;
72
73 extern int option_force_own_colormap;
74 extern int option_force_default_colormap;
75 extern int option_mouse_double_click;
76 extern int option_middle_button_pastes;
77 extern int option_syntax_highlighting;
78 extern int option_auto_spellcheck;
79
80 extern int option_smooth_scrolling;
81
82 extern int option_new_window_ask_for_file;
83
84 extern int option_never_raise_wm_windows;
85
86 #ifdef HAVE_DND
87 extern int option_dnd_version;
88 #endif
89
90 extern int option_interpret_numlock;
91
92 extern char *editor_options_file;
93 extern char *option_preferred_visual;
94
95
96 extern int option_color_0;
97 extern int option_color_1;
98 extern int option_color_2;
99 extern int option_color_3;
100 extern int option_color_4;
101 extern int option_color_5;
102 extern int option_color_6;
103 extern int option_color_7;
104 extern int option_color_8;
105 extern int option_color_9;
106 extern int option_color_10;
107 extern int option_color_11;
108 extern int option_color_12;
109 extern int option_color_13;
110 extern int option_color_14;
111 extern int option_color_15;
112 extern int option_color_16;
113 extern int option_color_17;
114 extern int option_color_18;
115 extern int option_color_19;
116 extern int option_color_20;
117 extern int option_color_21;
118 extern int option_color_22;
119 extern int option_color_23;
120 extern int option_color_24;
121 extern int option_color_25;
122 extern int option_color_26;
123
124
125 static struct {
126 char *name;
127 int *value;
128 char *prompt;
129 #define TYPE_ON_OFF 1
130 #define TYPE_VALUE 2
131 #define TYPE_HIDDEN_VALUE 3
132 #define TYPE_HIDDEN_HEX_VALUE 4
133 int type;
134 } integer_options [] = {
135 /* The following are check box labels */
136 {"option_international_characters", &option_international_characters, gettext_noop(" Display characters outside locale "), TYPE_ON_OFF},
137 {"option_word_wrap_line_length", &option_word_wrap_line_length, gettext_noop(" Word wrap line length: "), TYPE_VALUE},
138 {"option_tab_spacing", &option_tab_spacing, gettext_noop(" Tab spacing: "), TYPE_VALUE},
139 {"option_fill_tabs_with_spaces", &option_fill_tabs_with_spaces, gettext_noop(" Fill tabs with spaces "), TYPE_ON_OFF},
140 {"option_return_does_auto_indent", &option_return_does_auto_indent, gettext_noop(" Return does auto indent "), TYPE_ON_OFF},
141 {"option_backspace_through_tabs", &option_backspace_through_tabs, gettext_noop(" Backspace through all tabs "), TYPE_ON_OFF},
142 {"option_fake_half_tabs", &option_fake_half_tabs, gettext_noop(" Emulate half tabs with spaces "), TYPE_ON_OFF},
143 {"option_save_setup_on_exit", &option_save_setup_on_exit, gettext_noop(" Save setup on exit "), TYPE_ON_OFF},
144 {"option_suppress_load_files", &option_suppress_load_files, gettext_noop(" Don't load back desktop on startup "), TYPE_ON_OFF},
145 {"option_save_mode", &option_save_mode, 0, 0},
146 {"option_hint_messages", &option_hint_messages, gettext_noop(" Hint time on title bar "), TYPE_VALUE},
147 {"option_cursor_blink_rate", &option_cursor_blink_rate, 0, 0},
148 {"option_flashing_cursor", &option_flashing_cursor, gettext_noop(" Flashing cursor "), TYPE_ON_OFF},
149 {"option_xor_cursor", &option_xor_cursor, gettext_noop(" Xor cursor "), TYPE_ON_OFF},
150 {"option_pull_down_window_list", &option_pull_down_window_list, gettext_noop(" Pull down 'Window' menu "), TYPE_ON_OFF},
151 {"option_find_bracket", &option_find_bracket, gettext_noop(" Highlight matching bracket "), TYPE_ON_OFF},
152 {"option_never_raise_wm_windows", &option_never_raise_wm_windows, gettext_noop(" Never Raise WM Windows "), TYPE_ON_OFF},
153 {"option_edit_right_extreme", &option_edit_right_extreme, 0, 0},
154 {"option_edit_left_extreme", &option_edit_left_extreme, 0, 0},
155 {"option_edit_top_extreme", &option_edit_top_extreme, 0, 0},
156 {"option_edit_bottom_extreme", &option_edit_bottom_extreme, 0, 0},
157 {"option_text_line_spacing", &option_text_line_spacing, 0, 0},
158 {"option_force_own_colormap", &option_force_own_colormap, 0, 0},
159 {"option_force_default_colormap", &option_force_default_colormap, 0, 0},
160 {"option_mouse_double_click", &option_mouse_double_click, gettext_noop(" Mouse double click time-out "), TYPE_VALUE},
161 #ifdef HAVE_DND
162 {"option_dnd_version", &option_dnd_version, 0, 0},
163 #endif
164 {"option_max_undo", &option_max_undo, 0, 0},
165 #if 0
166 {"option_interwidget_spacing", &option_interwidget_spacing, 0, 0},
167 #endif
168 {"option_toolbar", &option_toolbar, gettext_noop(" Toolbar on edit windows "), TYPE_ON_OFF},
169 {"option_interpret_numlock", &option_interpret_numlock, gettext_noop(" Interpret Num-Lock "), TYPE_ON_OFF},
170 {"option_long_whitespace", &option_long_whitespace, gettext_noop(" Whitespace is doubled "), TYPE_ON_OFF},
171 {"option_toolhint_milliseconds", &option_toolhint_milliseconds, gettext_noop(" Time to show button hints "), TYPE_VALUE},
172 {"option_edit_right_extreme", &option_edit_right_extreme, gettext_noop(" Right cursor limit "), TYPE_VALUE},
173 {"option_edit_left_extreme", &option_edit_left_extreme, gettext_noop(" Left cursor limit "), TYPE_VALUE},
174 {"option_edit_top_extreme", &option_edit_top_extreme, gettext_noop(" Top cursor limit "), TYPE_VALUE},
175 {"option_edit_bottom_extreme", &option_edit_bottom_extreme, gettext_noop(" Bottom cursor limit "), TYPE_VALUE},
176 #if 0
177 {"option_low_bandwidth", &option_low_bandwidth, gettext_noop(" Slow server network connection "), TYPE_ON_OFF},
178 #endif
179 {"option_middle_button_pastes", &option_middle_button_pastes, gettext_noop(" Mouse middle button pastes "), TYPE_ON_OFF},
180 {"option_new_window_ask_for_file", &option_new_window_ask_for_file, gettext_noop(" New windows ask for file "), TYPE_ON_OFF},
181 {"option_smooth_scrolling", &option_smooth_scrolling, gettext_noop(" Smooth scrolling "), TYPE_ON_OFF},
182 {"option_typing_replaces_selection", &option_typing_replaces_selection, gettext_noop(" Typing replaces selection "), TYPE_ON_OFF},
183 {"option_latin2", &option_latin2, gettext_noop(" Latin 2 composing "), TYPE_ON_OFF},
184 {"option_utf_interpretation", &option_utf_interpretation, gettext_noop(" UTF8 Interpretation "), TYPE_ON_OFF},
185 {"option_reverse_hebrew", &option_reverse_hebrew, gettext_noop(" Reverse Hebrew (Exprmntl!) "), TYPE_ON_OFF},
186 {"last_unichar_left", &last_unichar_left, 0, TYPE_HIDDEN_VALUE},
187 {"last_unichar_right", &last_unichar_right, 0, TYPE_HIDDEN_VALUE},
188 {"option_rgb_order", &option_rgb_order, 0, TYPE_HIDDEN_VALUE},
189 {"option_interchar_spacing", &option_interchar_spacing, 0, TYPE_HIDDEN_VALUE},
190 {"option_file_browser_width", &option_file_browser_width, 0, TYPE_HIDDEN_VALUE},
191 {"option_file_browser_height", &option_file_browser_height, 0, TYPE_HIDDEN_VALUE},
192 {"option_shell_command_line_sticky", &option_shell_command_line_sticky, 0, TYPE_HIDDEN_VALUE},
193 {"option_shell_command_line_pty", &option_shell_command_line_pty, 0, TYPE_HIDDEN_VALUE},
194 {"option_invert_colors", &option_invert_colors, 0, TYPE_HIDDEN_VALUE},
195 {"option_invert_crome", &option_invert_crome, 0, TYPE_HIDDEN_VALUE},
196 {"option_invert_red_green", &option_invert_red_green, 0, TYPE_HIDDEN_VALUE},
197 {"option_invert_green_blue", &option_invert_green_blue, 0, TYPE_HIDDEN_VALUE},
198 {"option_invert_red_blue", &option_invert_red_blue, 0, TYPE_HIDDEN_VALUE},
199 {"option_color_0", &option_color_0, 0, TYPE_HIDDEN_HEX_VALUE},
200 {"option_color_1", &option_color_1, 0, TYPE_HIDDEN_HEX_VALUE},
201 {"option_color_2", &option_color_2, 0, TYPE_HIDDEN_HEX_VALUE},
202 {"option_color_3", &option_color_3, 0, TYPE_HIDDEN_HEX_VALUE},
203 {"option_color_4", &option_color_4, 0, TYPE_HIDDEN_HEX_VALUE},
204 {"option_color_5", &option_color_5, 0, TYPE_HIDDEN_HEX_VALUE},
205 {"option_color_6", &option_color_6, 0, TYPE_HIDDEN_HEX_VALUE},
206 {"option_color_7", &option_color_7, 0, TYPE_HIDDEN_HEX_VALUE},
207 {"option_color_8", &option_color_8, 0, TYPE_HIDDEN_HEX_VALUE},
208 {"option_color_9", &option_color_9, 0, TYPE_HIDDEN_HEX_VALUE},
209 {"option_color_10", &option_color_10, 0, TYPE_HIDDEN_HEX_VALUE},
210 {"option_color_11", &option_color_11, 0, TYPE_HIDDEN_HEX_VALUE},
211 {"option_color_12", &option_color_12, 0, TYPE_HIDDEN_HEX_VALUE},
212 {"option_color_13", &option_color_13, 0, TYPE_HIDDEN_HEX_VALUE},
213 {"option_color_14", &option_color_14, 0, TYPE_HIDDEN_HEX_VALUE},
214 {"option_color_15", &option_color_15, 0, TYPE_HIDDEN_HEX_VALUE},
215 {"option_color_16", &option_color_16, 0, TYPE_HIDDEN_HEX_VALUE},
216 {"option_color_17", &option_color_17, 0, TYPE_HIDDEN_HEX_VALUE},
217 {"option_color_18", &option_color_18, 0, TYPE_HIDDEN_HEX_VALUE},
218 {"option_color_19", &option_color_19, 0, TYPE_HIDDEN_HEX_VALUE},
219 {"option_color_20", &option_color_20, 0, TYPE_HIDDEN_HEX_VALUE},
220 {"option_color_21", &option_color_21, 0, TYPE_HIDDEN_HEX_VALUE},
221 {"option_color_22", &option_color_22, 0, TYPE_HIDDEN_HEX_VALUE},
222 {"option_color_23", &option_color_23, 0, TYPE_HIDDEN_HEX_VALUE},
223 {"option_color_24", &option_color_24, 0, TYPE_HIDDEN_HEX_VALUE},
224 {"option_color_25", &option_color_25, 0, TYPE_HIDDEN_HEX_VALUE},
225 {"option_color_26", &option_color_26, 0, TYPE_HIDDEN_HEX_VALUE},
226 {"option_syntax_highlighting", &option_syntax_highlighting, 0, 0},
227 {"option_auto_spellcheck", &option_auto_spellcheck, 0, 0},
228 {0, 0}
229 };
230
231 extern char *option_display;
232 extern char *option_geometry;
233 extern char *option_background_color;
234 extern char *option_foreground_red;
235 extern char *option_foreground_green;
236 extern char *option_foreground_blue;
237 extern char *option_font;
238 extern char *option_widget_font;
239
240 extern char *option_man_cmdline;
241 extern char *option_alternate_dictionary;
242
243 extern char *option_look;
244
245 static struct {
246 char *name;
247 char **value;
248 } string_options [] = {
249 {"option_look", &option_look},
250 {"option_whole_chars_search", &option_whole_chars_search},
251 {"option_chars_move_whole_word", &option_chars_move_whole_word},
252 #if 0 /* mmmmmmh it shouldn't remember the display */
253 {"option_display", &option_display},
254 #endif
255 {"option_geometry", &option_geometry},
256 {"option_background_color", &option_background_color},
257 {"option_foreground_red", &option_foreground_red},
258 {"option_foreground_green", &option_foreground_green},
259 {"option_foreground_blue", &option_foreground_blue},
260 {"option_font", &option_font},
261 {"option_widget_font", &option_widget_font},
262 {"option_backup_ext", &option_backup_ext},
263 {"option_man_cmdline", &option_man_cmdline},
264 {"option_preferred_visual", &option_preferred_visual},
265 {"option_alternate_dictionary", &option_alternate_dictionary},
266 {0, 0}
267 };
268
269 static struct {
270 char *name;
271 int *value;
272 char *cname;
273 } color_options [] = {
274 {"option_editor_fg_normal", &option_editor_fg_normal, 0},
275 {"option_editor_fg_bold", &option_editor_fg_bold, 0},
276 {"option_editor_fg_italic", &option_editor_fg_italic, 0},
277 {"option_editor_bg_normal", &option_editor_bg_normal, 0},
278 {"option_editor_bg_abnormal", &option_editor_bg_abnormal, 0},
279 {"option_editor_bg_marked", &option_editor_bg_marked, 0},
280 {"option_editor_bg_marked_abnormal", &option_editor_bg_marked_abnormal, 0},
281 {"option_editor_bg_highlighted", &option_editor_bg_highlighted, 0},
282 {"option_editor_fg_cursor", &option_editor_fg_cursor, 0},
283 {"option_text_fg_normal", &option_text_fg_normal, 0},
284 {"option_text_fg_bold", &option_text_fg_bold, 0},
285 {"option_text_fg_italic", &option_text_fg_italic, 0},
286 {"option_text_bg_normal", &option_text_bg_normal, 0},
287 {"option_text_bg_marked", &option_text_bg_marked, 0},
288 {"option_text_bg_highlighted", &option_text_bg_highlighted, 0},
289 {0, 0}
290 };
291
292
293 int save_options_section (const char *file, const char *section, const char *text);
294
load_setup(const char * file)295 int load_setup (const char *file)
296 {
297 static char *options_section = 0;
298 char *p, *q;
299 int fin = 0;
300
301 if (options_section) {
302 free (options_section);
303 options_section = 0;
304 }
305 if (!file)
306 return 0;
307
308 options_section = get_options_section (file, "[Options]");
309 p = q = options_section;
310
311 if (!options_section)
312 return -1;
313
314 for (fin = 0; !fin;) {
315 if (*q == '\n' || !*q) {
316 int i;
317 if (!*q)
318 fin = 1;
319 *q = 0;
320 for (i = 0; string_options[i].name; i++) {
321 int l;
322 l = strlen (string_options[i].name);
323 l = strnlen (p, l);
324 if (p[l] && strchr ("\t =", p[l])) {
325 if (!strncasecmp (p, string_options[i].name, l)) {
326 *(string_options[i].value) = p + l + strspn (p + l, " =\t");
327 break;
328 }
329 }
330 }
331 for (i = 0; integer_options[i].name; i++) {
332 int l;
333 l = strlen (integer_options[i].name);
334 l = strnlen (p, l);
335 if (p[l] && strchr ("\t =", p[l])) {
336 if (!strncasecmp (p, integer_options[i].name, l)) {
337 *(integer_options[i].value) = strtol (p + l + strspn (p + l, " =\t"), (char **) 0, 0);
338 break;
339 }
340 }
341 }
342 for (i = 0; color_options[i].name; i++) {
343 int l;
344 l = strlen (color_options[i].name);
345 l = strnlen (p, l);
346 if (p[l] && strchr ("\t =", p[l])) {
347 if (!strncasecmp (p, color_options[i].name, l)) {
348 *(color_options[i].value) = atoi (p + l + strspn (p + l, " =\t"));
349 color_options[i].cname = p + l + strspn (p + l, " =\t");
350 break;
351 }
352 }
353 }
354 p = (++q);
355 } else {
356 q++;
357 }
358 }
359 return 0;
360 }
361
get_main_window_geometry(void)362 void get_main_window_geometry (void)
363 {
364 int x, y;
365 unsigned int width, height, d;
366 Window win, root;
367 static char save_geom[80];
368 int bitmask;
369
370 XGetGeometry (CDisplay, main_window, &root, &x, &y, &width, &height, &d, &d);
371 win = CGetWMWindow (main_window);
372 XGetGeometry (CDisplay, win, &root, &x, &y, &d, &d, &d, &d);
373
374 if (option_geometry)
375 bitmask = XParseGeometry (option_geometry, (int *) &d, (int *) &d, &d, &d);
376 else
377 bitmask = WidthValue | HeightValue;
378
379 save_geom[0] = '\0';
380 if (bitmask & (WidthValue | HeightValue)) {
381 strcat (save_geom, itoa (width));
382 strcat (save_geom, "x");
383 strcat (save_geom, itoa (height));
384 }
385 if (bitmask & (XValue | YValue)) {
386 if (x >= 0)
387 strcat (save_geom, "+");
388 strcat (save_geom, itoa (x));
389 if (y >= 0)
390 strcat (save_geom, "+");
391 strcat (save_geom, itoa (y));
392 }
393 option_geometry = save_geom;
394 }
395
396 /* option_geometry is not strdup'ed here so don't free it */
save_setup(const char * file)397 int save_setup (const char *file)
398 {
399 char *p, *s;
400 int r, i;
401
402 get_main_window_geometry ();
403
404 p = s = CMalloc (16384);
405
406 for (i = 0; string_options[i].name; i++) {
407 if (*string_options[i].value) {
408 sprintf (p, "%s = %s\n%n", string_options[i].name, *string_options[i].value, &r);
409 p += r;
410 }
411 }
412 for (i = 0; integer_options[i].name; i++) {
413 if (integer_options[i].type == TYPE_HIDDEN_HEX_VALUE)
414 sprintf (p, "%s = 0x%X\n%n", integer_options[i].name, *integer_options[i].value, &r);
415 else
416 sprintf (p, "%s = %d\n%n", integer_options[i].name, *integer_options[i].value, &r);
417 p += r;
418 }
419 for (i = 0; color_options[i].name; i++) {
420 if (color_options[i].cname)
421 sprintf (p, "%s = %s\n%n", color_options[i].name, color_options[i].cname, &r);
422 else
423 sprintf (p, "%s = %d\n%n", color_options[i].name, *color_options[i].value, &r);
424 p += r;
425 }
426 *p = 0;
427
428 r = save_options_section (file, "[Options]", s);
429 free (s);
430 return r;
431 }
432
save_options(void)433 void save_options (void)
434 {
435 if (save_setup (editor_options_file) < 0)
436 CErrorDialog (main_window, 20, 20, _(" Save Options "), "%s", get_sys_error (
437 catstrs (_(" Error trying to save : "), editor_options_file, " ", NULL)));
438 }
439
short_name(char * a,char * b)440 static char *short_name (char *a, char *b)
441 {
442 static char r[128];
443 strcpy (r, a);
444 strcat (r, b);
445 r[30] = 0;
446 return r;
447 }
448
449 #define WHICH_SWITCHES 1
450 #define WHICH_GENERAL 2
451
assign_options(int which)452 static void assign_options (int which)
453 {
454 int i = 0;
455 static char whole_chars_search[128];
456 static char whole_chars_move[128];
457 static char alternate_dictionary[MAX_PATH_LEN];
458
459 while (integer_options[i].value) {
460 if (integer_options[i].prompt) {
461 if (which == WHICH_SWITCHES) {
462 if (integer_options[i].type == TYPE_ON_OFF)
463 *integer_options[i].value = (CIdent (short_name (integer_options[i].name, "")))->keypressed;
464 }
465 if (which == WHICH_GENERAL) {
466 if (integer_options[i].type == TYPE_VALUE)
467 *integer_options[i].value = atoi ((CIdent (short_name (integer_options[i].name, "")))->text);
468 }
469 }
470 i++;
471 }
472 if (which == WHICH_SWITCHES) {
473 #ifdef HAVE_DND
474 option_dnd_version = (CIdent ("dnd_version"))->keypressed;
475 #endif
476 option_auto_para_formatting = (CIdent ("para_form"))->keypressed;
477 option_typewriter_wrap = (CIdent ("typew_wrap"))->keypressed;
478 option_auto_spellcheck = (CIdent ("auto_spell"))->keypressed;
479 option_syntax_highlighting = (CIdent ("syntax_high"))->keypressed;
480 }
481 if (which == WHICH_GENERAL) {
482 strncpy (alternate_dictionary, (CIdent ("options.a_dict"))->text, MAX_PATH_LEN - 1);
483 option_alternate_dictionary = alternate_dictionary;
484 alternate_dictionary[MAX_PATH_LEN - 1] = '\0';
485
486 strncpy (whole_chars_search, (CIdent ("options.wc_search"))->text, 127);
487 option_whole_chars_search = whole_chars_search;
488 whole_chars_search[127] = '\0';
489
490 strncpy (whole_chars_move, (CIdent ("options.wc_move"))->text, 127);
491 option_chars_move_whole_word = whole_chars_move;
492 whole_chars_move[127] = '\0';
493 }
494 }
495
draw_options_dialog(Window parent,int x,int y)496 void draw_options_dialog (Window parent, int x, int y)
497 {
498 Window win;
499 XEvent xev;
500 CEvent cev;
501 int xh, i;
502 CState s;
503 CWidget *w, *wdt;
504
505 CBackupState (&s);
506 CDisable ("*");
507
508 win = CDrawHeadedDialog ("options", parent, x, y, _(" Options "));
509 CGetHintPos (&x, &y);
510
511 i = 0;
512 xh = x;
513 while (integer_options[i].value) {
514 if (integer_options[i].prompt && integer_options[i].type == TYPE_VALUE) {
515 wdt = CDrawText (short_name ("T", integer_options[i].name), win, xh, y, _(integer_options[i].prompt));
516 CGetHintPos (&x, 0);
517 w = CDrawTextInput (short_name (integer_options[i].name, ""), win, x, y, FONT_MEAN_WIDTH * 8 + FONT_PIX_PER_LINE + 4, AUTO_HEIGHT, 8, itoa (*integer_options[i].value));
518 w->position |= POSITION_FILL;
519 w->label = (char *) _(integer_options[i].prompt); /* FIXME: memory leak? should not label be free'd? */
520 w->hotkey = find_hotkey (w);
521 w->label = 0;
522 wdt->hotkey = w->hotkey;
523 CGetHintPos (0, &y);
524 }
525 i++;
526 }
527
528 CGetHintPos (0, &y);
529 CDrawText ("options.twc_search", win, xh, y, _(" Whole chars search: "));
530 CGetHintPos (&x, 0);
531 (CDrawTextInput ("options.wc_search", win, x, y, FONT_MEAN_WIDTH * 16, AUTO_HEIGHT, 258, option_whole_chars_search)->position) |= POSITION_FILL;
532 CGetHintPos (0, &y);
533 CDrawText ("options.twc_move", win, xh, y, _(" Whole chars move: "));
534 CGetHintPos (&x, 0);
535 (CDrawTextInput ("options.wc_move", win, x, y, FONT_MEAN_WIDTH * 16, AUTO_HEIGHT, 258, option_chars_move_whole_word)->position) |= POSITION_FILL;
536 CGetHintPos (0, &y);
537 CDrawText ("options.ta_dict", win, xh, y, _(" Ispell alternate dict: "));
538 CGetHintPos (&x, 0);
539 (CDrawTextInput ("options.a_dict", win, x, y, FONT_MEAN_WIDTH * 16, AUTO_HEIGHT, 258, option_alternate_dictionary)->position) |= POSITION_FILL;
540
541 CGetHintPos (0, &y);
542 CDrawPixmapButton ("options.ok", win, xh, y, PIXMAP_BUTTON_TICK);
543 /* Toolhint */
544 CSetToolHint ("options.ok", _("Apply options, Enter"));
545 CGetHintPos (&xh, 0);
546 CDrawPixmapButton ("options.cancel", win, xh, y, PIXMAP_BUTTON_CROSS);
547 /* Toolhint */
548 CSetToolHint ("options.cancel", _("Abort dialog, Escape"));
549 CGetHintPos (&xh, 0);
550 CDrawPixmapButton ("options.save", win, xh, y, PIXMAP_BUTTON_SAVE);
551 /* Toolhint */
552 CSetToolHint ("options.save", _("Save options"));
553 CSetSizeHintPos ("options");
554 CMapDialog ("options");
555
556 CFocus (CIdent ("options.ok"));
557
558 for (;;) {
559 CNextEvent (&xev, &cev);
560 if (!CIdent("options"))
561 break;
562 if (!strcmp (cev.ident, "options.cancel") || cev.command == CK_Cancel)
563 break;
564 if (!strcmp (cev.ident, "options.ok") || cev.command == CK_Enter) {
565 /* keypressed holds the whether switch is on or off */
566 assign_options (WHICH_GENERAL);
567 break;
568 }
569 if (!strcmp (cev.ident, "options.save")) {
570 /* keypressed holds the whether switch is on or off */
571 assign_options (WHICH_GENERAL);
572 save_options ();
573 }
574 }
575 w = CGetEditMenu ();
576 if (w)
577 CExpose (w->ident);
578 CDestroyWidget ("options");
579 CRestoreState (&s);
580 }
581
draw_switches_dialog(Window parent,int x,int y)582 void draw_switches_dialog (Window parent, int x, int y)
583 {
584 Window win;
585 XEvent xev;
586 CEvent cev;
587 int xh, yh;
588 int i, n;
589 CState s;
590 CWidget *w;
591
592 CBackupState (&s);
593 CDisable ("*");
594
595 win = CDrawHeadedDialog ("options", parent, x, y, _ (" Options "));
596 CGetHintPos (&x, &y);
597
598 n = i = 0;
599 while (integer_options[i].value) {
600 if (integer_options[i].prompt && integer_options[i].type == TYPE_ON_OFF)
601 n++;
602 i++;
603 }
604
605 i = 0;
606 xh = x;
607 yh = y;
608 while (integer_options[i].value) {
609 if (integer_options[i].prompt && integer_options[i].type == TYPE_ON_OFF) {
610 if (n <= 0) {
611 get_hint_limits (&xh, 0); /* half on the left, half on the right */
612 n = 9999;
613 yh = y;
614 }
615 CDrawSwitch (short_name (integer_options[i].name, ""), win, xh, yh, *integer_options[i].value, _ (integer_options[i].prompt), 0);
616 CGetHintPos (0, &yh);
617 n -= 2;
618 }
619 i++;
620 }
621
622 #ifdef HAVE_DND
623 get_hint_limits (0, &y);
624 CDrawSwitch ("dnd_version_not", win, x, y, !option_dnd_version, _ (" Dnd version 0 "), 1 | RADIO_INVERT_GROUP);
625 CDrawSwitch ("dnd_version", win, xh, y, option_dnd_version, _ (" Dnd version 1 "), 1 | RADIO_INVERT_GROUP);
626 #endif
627
628 get_hint_limits (0, &y);
629 CDrawSwitch ("para_form", win, x, y, option_auto_para_formatting, _ (" Auto paragraph formatting "), 2);
630 CDrawSwitch ("typew_wrap", win, xh, y, option_typewriter_wrap, _ (" Type-writer wrap "), 2);
631 CGetHintPos (0, &y);
632
633 get_hint_limits (0, &y);
634 CDrawSwitch ("syntax_high", win, x, y, option_syntax_highlighting, _ (" Syntax highlighting "), 0);
635 CDrawSwitch ("auto_spell", win, xh, y, option_auto_spellcheck, _ (" Spellcheck as you type "), 0);
636 CGetHintPos (0, &y);
637
638 CDrawPixmapButton ("options.ok", win, x, y, PIXMAP_BUTTON_TICK);
639 /* Toolhint */
640 CSetToolHint ("options.ok", _ ("Apply options, Enter"));
641 CGetHintPos (&xh, 0);
642 CDrawPixmapButton ("options.cancel", win, xh, y, PIXMAP_BUTTON_CROSS);
643 /* Toolhint */
644 CSetToolHint ("options.cancel", _ ("Abort dialog, Escape"));
645 CGetHintPos (&xh, 0);
646 CDrawPixmapButton ("options.save", win, xh, y, PIXMAP_BUTTON_SAVE);
647 /* Toolhint */
648 CSetToolHint ("options.save", _ ("Save options"));
649 CSetSizeHintPos ("options");
650 CMapDialog ("options");
651
652 CFocus (CIdent ("options.ok"));
653
654 for (;;) {
655 CNextEvent (&xev, &cev);
656 if (!CIdent ("options"))
657 break;
658 if (!strcmp (cev.ident, "syntax_high")) {
659 /* turn off spell checkig if syntax high is on */
660 if ((CIdent ("auto_spell"))->keypressed && !(CIdent ("syntax_high"))->keypressed) {
661 (CIdent ("auto_spell"))->keypressed = 0;
662 render_switch (CIdent ("auto_spell"));
663 }
664 }
665 if (!strcmp (cev.ident, "auto_spell")) {
666 /* turn on syntax highlighting if spellchecking is on */
667 if ((CIdent ("auto_spell"))->keypressed && !(CIdent ("syntax_high"))->keypressed) {
668 (CIdent ("syntax_high"))->keypressed = 1;
669 render_switch (CIdent ("syntax_high"));
670 }
671 }
672 if (!strcmp (cev.ident, "options.cancel") || cev.command == CK_Cancel)
673 break;
674 if (!strcmp (cev.ident, "options.ok") || cev.command == CK_Enter) {
675 /* keypressed holds the whether switch is on or off */
676 assign_options (WHICH_SWITCHES);
677 break;
678 }
679 if (!strcmp (cev.ident, "options.save")) {
680 /* keypressed holds the whether switch is on or off */
681 assign_options (WHICH_SWITCHES);
682 save_options ();
683 }
684 }
685 w = CGetEditMenu ();
686 if (w)
687 CExpose (w->ident);
688 CDestroyWidget ("options");
689 CRestoreState (&s);
690 }
691
692
save_mode_options_dialog(Window parent,int x,int y)693 void save_mode_options_dialog (Window parent, int x, int y)
694 {
695 Window win;
696 XEvent xev;
697 CEvent cev;
698 int x2, y2;
699 CState s;
700 CWidget *quick, *safe, *backup;
701
702 CBackupState (&s);
703 CDisable ("*");
704
705 win = CDrawHeadedDialog ("saving", parent, x, y, _(" Options "));
706 CGetHintPos (&x, &y);
707
708 quick = CDrawSwitch ("saving.Rquick", win, x, y, option_save_mode == 0, _(" Quick save "), 1 | RADIO_ONE_ALWAYS_ON);
709 /* Toolhint */
710 CSetToolHint ("saving.Rquick", _("Truncates file then writes contents of editor"));
711 CSetToolHint ("saving.Rquick.label", _("Truncates file then writes contents of editor"));
712 CGetHintPos (0, &y2);
713
714 safe = CDrawSwitch ("saving.Rsafe", win, x, y2, option_save_mode == 1, _(" Safe save "), 1 | RADIO_ONE_ALWAYS_ON);
715 /* Toolhint */
716 CSetToolHint ("saving.Rsafe", _("Writes to temporary file, then renames if succesful"));
717 CSetToolHint ("saving.Rsafe.label", _("Writes to temporary file, then renames if succesful"));
718 CGetHintPos (0, &y);
719
720 backup = CDrawSwitch ("saving.Rbackup", win, x, y, option_save_mode == 2, _(" Create backups "), 1 | RADIO_ONE_ALWAYS_ON);
721 /* Toolhint */
722 CSetToolHint ("saving.Rbackup", _("Creates a backup file first"));
723 CSetToolHint ("saving.Rbackup.label", _("Creates a backup file first"));
724 CGetHintPos (0, &y2);
725
726 CDrawText ("saving.ext", win, x, y2, _(" Backup file extension: "));
727 CGetHintPos (&x2, 0);
728 CDrawTextInput ("saving.extti", win, x2, y2, FONT_MEAN_WIDTH * 16, AUTO_HEIGHT, 16, option_backup_ext);
729
730 CGetHintPos (0, &y);
731 CDrawPixmapButton ("saving.ok", win, x, y, PIXMAP_BUTTON_TICK);
732 CGetHintPos (&x2, 0);
733 CDrawPixmapButton ("saving.cancel", win, x2, y, PIXMAP_BUTTON_CROSS);
734 CGetHintPos (&x2, 0);
735 CDrawPixmapButton ("saving.save", win, x2, y, PIXMAP_BUTTON_SAVE);
736 CSetSizeHintPos ("saving");
737 CMapDialog ("saving");
738
739 CFocus (CIdent ("saving.ok"));
740
741 for (;;) {
742 CNextEvent (&xev, &cev);
743 if (!CIdent("saving"))
744 break;
745 if (!strcmp (cev.ident, "saving.cancel") || cev.command == CK_Cancel)
746 break;
747 if (!strcmp (cev.ident, "saving.ok") || cev.command == CK_Enter
748 || !strcmp (cev.ident, "saving.save")) {
749 /* keypressed holds the whether switch is on or off */
750 if (CIdent ("saving.extti"))
751 option_backup_ext = (char *) strdup ((CIdent ("saving.extti"))->text);
752 if (quick->keypressed)
753 option_save_mode = 0;
754 else if (safe->keypressed)
755 option_save_mode = 1;
756 else if (backup->keypressed)
757 option_save_mode = 2;
758 if (!strcmp (cev.ident, "saving.save")) {
759 save_options ();
760 } else
761 break;
762 }
763 }
764 CDestroyWidget ("saving");
765 CRestoreState (&s);
766 }
767
768
syntax_get_line(void * data,int line)769 static char *syntax_get_line (void *data, int line)
770 {
771 char **names;
772 names = (char **) data;
773 return names[line];
774 }
775
menu_syntax_highlighting_dialog(Window parent,int x,int y)776 void menu_syntax_highlighting_dialog (Window parent, int x, int y)
777 {
778 char *names[1024] =
779 {"None", 0};
780 int i, n;
781 CWidget *w;
782
783 w = CGetEditMenu ();
784 if (!w)
785 return;
786 if (!w->editor)
787 return;
788
789 edit_load_syntax (0, names + 1, 0);
790 for (n = 0; names[n]; n++);
791
792 i = CListboxDialog (parent, x, y, 50, 20,
793 _ (" Syntax Highlighting "), 0, 0, n,
794 syntax_get_line, (void *) names);
795
796 if (i >= 0) {
797 if (!i) {
798 edit_free_syntax_rules (w->editor);
799 } else {
800 edit_load_syntax (w->editor, 0, names[i]);
801 }
802 w->editor->explicit_syntax = 1;
803 }
804 for (n = 1; names[n]; n++)
805 free (names[n]);
806 CExpose (w->ident);
807 }
808
809
810
811