Debian Codegraph @

texk/xdvik/gui/xm_prefs_fonts.c

raw
1 /*
2 * Copyright (c) 2004 Stefan Ulrich
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 */
23
24 /*
25 * Panel 2 (Fonts and colors) for xdvik preferences dialog.
26 */
27
28 #include "xdvi-config.h"
29 #include "xdvi.h"
30
31 #include "x_util.h"
32 #include "xm_colorsel.h"
33 #include "topic-window.h"
34 #include "util.h"
35 #include "events.h"
36 #include "hypertex.h"
37 #include "my-snprintf.h"
38
39 #include "xm_prefsP.h"
40 #include "xm_prefs_fonts.h"
41
42 #ifdef MOTIF /* entire file */
43
44 #include <X11/Xatom.h>
45
46 #include <Xm/Xm.h>
47 #include <Xm/Protocols.h>
48 #include <Xm/DialogS.h>
49 #include <Xm/LabelG.h>
50 #include <Xm/PushB.h>
51 #include <Xm/Form.h>
52 #include <Xm/Frame.h>
53 #include <Xm/PanedW.h>
54 #include <Xm/DrawnB.h>
55 #include <Xm/RowColumn.h>
56 #include <Xm/Scale.h>
57 #include <Xm/ToggleBG.h>
58 #include <Xm/Text.h>
59 #include <Xm/TextF.h>
60
61 #if USE_SPINBOX
62 #include <Xm/SpinB.h>
63 #endif
64
65 /*
66 * Handy defaults
67 */
68 static Arg v_off = { XmNtopOffset, 10 };
69 static Arg n_of_many = { XmNindicatorType, XmN_OF_MANY };
70 static Arg frame_title = { XmNchildType, XmFRAME_TITLE_CHILD };
71
72
73 static void
74 underline_toggle_cb(Widget w, XtPointer client_data, XtPointer call_data)
75 {
76 struct topic_info *tinfo = (struct topic_info *)client_data;
77 struct prefs_choice *prefs;
78 Boolean is_set;
79
80 UNUSED(call_data);
81
82 ASSERT(tinfo != NULL, "struct topic_info * in underline_toggle_cb mustn't be NULL!");
83 prefs = (struct prefs_choice *)tinfo->data;
84
85 XtVaGetValues(w, XmNset, &is_set, NULL);
86 if (is_set)
87 resource.link_style |= 1;
88 else
89 resource.link_style &= ~1;
90
91 store_preference(&(prefs->db), "linkStyle", "%d", resource.link_style);
92
93 /* update display */
94 globals.ev.flags |= EV_NEWPAGE;
95 XFlush(DISP);
96 }
97
98 static void
99 colorspecial_toggle_cb(Widget w, XtPointer client_data, XtPointer call_data)
100 {
101 struct topic_info *tinfo = (struct topic_info *)client_data;
102 struct prefs_choice *prefs;
103
104 UNUSED(w);
105 /* UNUSED(client_data); */
106 UNUSED(call_data);
107
108 ASSERT(tinfo != NULL, "struct topic_info * in colorspecial_toggle_cb mustn't be NULL!");
109 prefs = (struct prefs_choice *)tinfo->data;
110
111 do_toggle_color(False);
112 store_preference(&(prefs->db), "color", "%s", resource.use_color ? "True" : "False");
113 }
114
115 static void
116 darkness_text_cb(Widget w, XtPointer client_data, XtPointer call_data)
117 {
118 char *text;
119 int val;
120 struct topic_info *info = (struct topic_info *)client_data;
121 struct prefs_choice *prefs = (struct prefs_choice *)(info->data);
122
123 #if USE_SPINBOX
124 /* synchronize internal spinbox value. Apparently this loses the insertion position,
125 so we need to save it and set it again. */
126 XmTextPosition pos = XmTextFieldGetInsertionPosition(w);
127
128 UNUSED(call_data);
129 text = XmTextFieldGetString(w);
130 val = strtol(text, (char **)NULL, 10);
131
132 if (val != 0) {
133 XtVaSetValues(w, XmNposition, val, NULL);
134 XmTextFieldSetInsertionPosition(w, pos);
135 }
136 #else
137 Widget text_field;
138 UNUSED(call_data);
139
140 XtVaGetValues(w, XmNuserData, &text_field, NULL);
141 XtVaGetValues(text_field, XmNvalue, &text, NULL);
142 val = strtol(text, (char **)NULL, 10);
143 #endif
144 if (XtIsRealized(w)) {
145 do_set_density(val / 100.0, True, False);
146 store_preference(&(prefs->db), "gamma", "%f", val / 100.0);
147 }
148 XtFree(text);
149 }
150
151
152 #if 0 /* currently unused */
153 static void
154 darkness_spinbox_cb(Widget w, XtPointer client_data, XtPointer call_data)
155 {
156 int val;
157 struct topic_info *info = (struct topic_info *)client_data;
158 struct prefs_choice *prefs = (struct prefs_choice *)(info->data);
159 UNUSED(client_data);
160 UNUSED(call_data);
161
162 XtVaGetValues(w, XmNposition, &val, NULL);
163 if (XtIsRealized(w)) {
164 do_set_density(val / 100.0, True, False);
165 /* fprintf(stderr, "storing pref: %d\n", val); */
166 store_preference(&(prefs->db), "gamma", "%f", val / 100.0);
167 }
168
169 }
170 #endif /* currently unused */
171
172
173 void
174 h_update_hyperlinks(Widget w, Pixel pix)
175 {
176 const char *name = XtName(w);
177 int type = 0;
178
179 if (strcmp(name, Xdvi_UNVISITED_LINKS_BTN) == 0) {
180 type = 1;
181 }
182 else if (strcmp(name, Xdvi_VISITED_LINKS_BTN) == 0) {
183 type = 2;
184 }
185
186 /* fprintf(stderr, "WIDGET: |%s|; type: %d\n", name, type); */
187
188 if (type != 0) {
189 GC new_gc = set_or_make_gc(NULL, GXcopy, pix, resource.back_Pixel);
190 GC old_gc;
191 double r, g, b;
192 double factor = 65535.0;
193 XColor color;
194
195 pixel_to_color(pix, &color, DISP, G_colormap);
196 r = color.red / factor;
197 g = color.green / factor;
198 b = color.blue / factor;
199
200 if (type == 1) {
201 old_gc = globals.gc.linkcolor;
202 sprintf(g_link_color_rgb, "push rgb %.2f %.2f %.2f", r, g, b);
203 }
204 else {
205 old_gc = globals.gc.visited_linkcolor;
206 sprintf(g_visited_link_color_rgb, "push rgb %.2f %.2f %.2f", r, g, b);
207 }
208
209 if (type == 1) {
210 globals.gc.linkcolor = new_gc;
211 XFreeGC(XtDisplay(w), old_gc);
212 }
213 else {
214 globals.gc.visited_linkcolor = new_gc;
215 XFreeGC(XtDisplay(w), old_gc);
216 }
217 /* update display */
218 globals.ev.flags |= EV_NEWPAGE;
219 XFlush(DISP);
220 }
221 }
222
223 static void
224 redraw_or_push_cb(Widget w, XtPointer client_data, XtPointer call_data)
225 {
226 XmDrawnButtonCallbackStruct *cbs = (XmDrawnButtonCallbackStruct *)call_data;
227 static GC border_gc = 0;
228 struct color_button_info *cinfo;
229 Pixel pix = (Pixel)client_data;
230
231 if (cbs == NULL) {
232 XDVI_WARNING((stderr, "cinfo mustn't be NULL in redraw_or_push_cb!\n"));
233 return;
234 }
235
236 /* this can also be called via XtCallCallbacks, without call_data */
237 if (cbs->reason == XmCR_EXPOSE) {
238 /* redraw button label */
239 Dimension high_thick, st, wd, ht;
240 Dimension inner_w, inner_h, off_x, off_y;
241 GC label_gc;
242 XGCValues values;
243
244 XtVaGetValues(w,
245 XmNhighlightThickness, &high_thick,
246 XmNshadowThickness, &st,
247 XmNwidth, &wd,
248 XmNheight, &ht,
249 XmNuserData, &cinfo,
250 NULL);
251
252 values.function = GXcopy;
253
254 if (border_gc == 0) {
255 /* create the static GC for drawing the border - Note: never free'd! */
256 values.foreground = BlackPixelOfScreen(XtScreen(w));
257 /* values.line_width = 2; */
258 /* note: never free'd! */
259 border_gc = XCreateGC(XtDisplay(w), XtWindow(w),
260 GCFunction | GCForeground /* | GCLineWidth */, &values);
261 }
262 values.foreground = cinfo->pixel;
263 label_gc = XCreateGC(XtDisplay(w), XtWindow(w),
264 GCFunction | GCForeground, &values);
265
266 off_x = high_thick + st + 4;
267 inner_w = wd - 2 * off_x;
268 off_y = high_thick + st + 4;
269 inner_h = ht - 2 * off_y;
270 #if 0
271 fprintf(stderr, "shadow: %d, high: %d\n", st, high_thick);
272 fprintf(stderr, "width: %d, height: %d\n", wd, ht);
273 fprintf(stderr, "inner w: %d, inner h: %d\n", inner_w, inner_h);
274 #endif
275
276 XFillRectangle(XtDisplay(w), XtWindow(w), label_gc,
277 off_x, off_y, inner_w, inner_h);
278 XDrawRectangle(XtDisplay(w), XtWindow(w), border_gc,
279 off_x - 1, off_y - 1, inner_w + 1, inner_h + 1);
280 XFreeGC(XtDisplay(w), label_gc);
281
282 if (pix != cinfo->pixel) {
283 h_update_hyperlinks(w, cinfo->pixel);
284 }
285 }
286 else if (cbs->reason == XmCR_ACTIVATE) {
287 /* pushed, open color dialog */
288 XtVaGetValues(w, XmNuserData, &cinfo, NULL);
289 if (cinfo != NULL) {
290 cinfo->w = w;
291 popup_color_dialog(globals.widgets.top_level, cinfo);
292 }
293 else {
294 XDVI_WARNING((stderr, "cinfo mustn't be NULL in redraw_or_push_cb!\n"));
295 return;
296 }
297 }
298 /* else, XmCR_RESIZE - nothing to do */
299 }
300
301 static Widget
302 h_create_colorsample(Widget parent, Widget left,
303 const char *name,
304 const char *resource_name,
305 Pixel pix,
306 struct topic_info *info)
307 {
308 struct color_button_info *cinfo = xmalloc(sizeof *cinfo); /* note: never free()d */
309 Widget button;
310
311 UNUSED(left);
312
313 cinfo->pixel = pix;
314 cinfo->tinfo = info;
315 cinfo->resource_name = xstrdup(resource_name); /* note: never free()d */
316
317 button = XtVaCreateManagedWidget(name, xmDrawnButtonWidgetClass, parent,
318 XtNwidth, 42,
319 XtNheight, 28,
320 XmNuserData, cinfo,
321 /* we want the normal button look here to
322 make it obvious that users can press it */
323 XmNshadowType, XmSHADOW_OUT,
324 XmNpushButtonEnabled, True,
325 NULL);
326 XtAddCallback(button, XmNactivateCallback, redraw_or_push_cb, (XtPointer)pix);
327 XtAddCallback(button, XmNexposeCallback, redraw_or_push_cb, (XtPointer)pix);
328 XtAddCallback(button, XmNresizeCallback, redraw_or_push_cb, (XtPointer)pix);
329
330 return button;
331 }
332
333
334 static Widget
335 h_create_fonts_frame(Widget top, struct topic_info *info)
336 {
337 Widget darkness_form, darkness_label;
338
339 UNUSED(info);
340
341 darkness_form = XmCreateForm(top, "darkness_form", NULL, 0);
342 XtVaSetValues(darkness_form,
343 XmNverticalSpacing, 10,
344 XmNhorizontalSpacing, 10,
345 NULL);
346
347
348 darkness_label = XmCreateLabelGadget(darkness_form, "Font Darkness: ", NULL, 0);
349 XtVaSetValues(darkness_label,
350 XmNtopAttachment, XmATTACH_FORM,
351 XmNleftAttachment, XmATTACH_FORM,
352 XmNbottomAttachment, XmATTACH_FORM,
353 NULL);
354 XtManageChild(darkness_label);
355 {
356 Widget darkness_text;
357 #if USE_SPINBOX
358 Widget darkness_spinbox = XmCreateSpinBox(darkness_form, Xdvi_DARKNESS_SPINBOX, NULL, 0);
359 darkness_text = XmCreateTextField(darkness_spinbox, Xdvi_DARKNESS_TEXT, NULL, 0);
360 XtVaSetValues(darkness_spinbox,
361 XmNtopAttachment, XmATTACH_FORM,
362 XmNleftAttachment, XmATTACH_WIDGET,
363 XmNleftWidget, darkness_label,
364 XmNinitialDelay, 200,
365 XmNrepeatDelay, 50,
366 NULL);
367 XtVaSetValues(darkness_text,
368 XmNspinBoxChildType, XmNUMERIC,
369 XmNminimumValue, 0,
370 XmNmaximumValue, 1000,
371 XmNeditable, True,
372 XmNcolumns, 4,
373 XmNincrementValue, 1,
374 XmNwrap, False, /* too confusing */
375 XmNposition, (int)(resource.gamma * 100.0 + 0.5),
376 NULL);
377 XtAddCallback(darkness_text, XmNactivateCallback, darkness_text_cb, (XtPointer)info);
378 XtAddCallback(darkness_text, XmNvalueChangedCallback, darkness_text_cb, (XtPointer)info);
379
380 adjust_heights(darkness_spinbox, darkness_text, darkness_label, NULL);
381
382 XtManageChild(darkness_text);
383 XtManageChild(darkness_spinbox);
384 #else
385 char buf[LENGTH_OF_INT];
386 Widget darkness_button;
387 darkness_text = XmCreateTextField(darkness_form, Xdvi_DARKNESS_TEXT, NULL, 0);
388 SNPRINTF(buf, LENGTH_OF_INT, "%d", (int)(resource.gamma * 100.0 + 0.5));
389 XtVaSetValues(darkness_text,
390 XmNtopAttachment, XmATTACH_FORM,
391 XmNleftAttachment, XmATTACH_WIDGET,
392 XmNleftWidget, darkness_label,
393 XmNcolumns, 4,
394 XmNvalue, buf,
395 XmNuserData, darkness_text,
396 NULL);
397 XtOverrideTranslations(darkness_text, XtParseTranslationTable("<Key>Return:activate()"));
398 XtAddCallback(darkness_text, XmNactivateCallback, darkness_text_cb, (XtPointer)info);
399
400 darkness_button = XmCreatePushButton(darkness_form, Xdvi_APPLY_STR, NULL, 0);
401 XtVaSetValues(darkness_button,
402 XmNtopAttachment, XmATTACH_FORM,
403 XmNleftAttachment, XmATTACH_WIDGET,
404 XmNleftWidget, darkness_text,
405 XmNuserData, darkness_text,
406 NULL);
407 XtAddCallback(darkness_button, XmNactivateCallback, darkness_text_cb, (XtPointer)info);
408
409 adjust_heights(darkness_label, darkness_text, darkness_button, NULL);
410 XtManageChild(darkness_text);
411 XtManageChild(darkness_button);
412 #endif
413 }
414
415 /* XtManageChild(darkness_form); */
416
417 return darkness_form;
418 }
419
420 static Widget
421 h_create_colors_form(Widget top, struct topic_info *info)
422 {
423 Widget text_bg_frame, text_bg_label, text_bg_form;
424 Widget links_frame, links_label, links_form;
425 Widget fg_label, fg_button;
426 Widget bg_label, bg_button;
427 Widget unvisited_label, unvisited_button;
428 Widget visited_label, visited_button;
429 Widget underline_toggle;
430 Widget colorspecials_toggle;
431
432 Widget form = XmCreateForm(top, "colors_form", NULL, 0);
433 Pixel visited_link_pix, link_pix;
434
435 str_to_pixel(top, resource.visited_link_color, &visited_link_pix);
436 str_to_pixel(top, resource.link_color, &link_pix);
437
438 text_bg_frame = XmCreateFrame(form, "text_bg_frame", NULL, 0);
439 XtVaSetValues(text_bg_frame,
440 XmNmarginWidth, 10,
441 XmNmarginHeight, 10,
442 XmNtopAttachment, XmATTACH_FORM,
443 XmNleftAttachment, XmATTACH_FORM,
444 XmNrightAttachment, XmATTACH_POSITION,
445 XmNrightPosition, 50,
446 XmNrightOffset, 10,
447 XmNbottomAttachment, XmATTACH_FORM,
448 NULL);
449
450 text_bg_label = XmCreateLabelGadget(text_bg_frame, "Text Color", &frame_title, 1);
451 XtManageChild(text_bg_label);
452
453 text_bg_form = XmCreateForm(text_bg_frame, "fg_form", NULL, 0);
454 XtVaSetValues(text_bg_form, XmNverticalSpacing, 2, NULL);
455
456 fg_label = XmCreateLabelGadget(text_bg_form, Xdvi_FG_COLOR_STR, NULL, 0);
457 fg_button = h_create_colorsample(text_bg_form, fg_label,
458 Xdvi_FG_COLOR_BTN, "foreground",
459 resource.fore_Pixel, info);
460 XtVaSetValues(fg_label,
461 XmNleftAttachment, XmATTACH_FORM,
462 XmNtopAttachment, XmATTACH_FORM,
463 NULL);
464 XtVaSetValues(fg_button,
465 XmNrightAttachment, XmATTACH_FORM,
466 XmNleftAttachment, XmATTACH_NONE,
467 NULL);
468 adjust_heights(fg_label, fg_button, NULL);
469 XtManageChild(fg_label);
470 XtManageChild(fg_button);
471
472 bg_label = XmCreateLabelGadget(text_bg_form, Xdvi_BG_COLOR_STR, NULL, 0);
473 bg_button = h_create_colorsample(text_bg_form, bg_label,
474 Xdvi_BG_COLOR_BTN, "background",
475 resource.back_Pixel, info);
476 XtVaSetValues(bg_label,
477 XmNleftAttachment, XmATTACH_FORM,
478 XmNtopAttachment, XmATTACH_WIDGET,
479 XmNtopWidget, fg_label,
480 NULL);
481 XtVaSetValues(bg_button,
482 XmNrightAttachment, XmATTACH_FORM,
483 XmNleftAttachment, XmATTACH_NONE,
484 XmNtopAttachment, XmATTACH_WIDGET,
485 XmNtopWidget, fg_label,
486 NULL);
487 adjust_heights(bg_label, bg_button, NULL);
488 XtManageChild(bg_label);
489 XtManageChild(bg_button);
490
491 colorspecials_toggle = XmCreateToggleButtonGadget(text_bg_form, Xdvi_DOCUMENT_COLORS_STR, &n_of_many, 1);
492 XtVaSetValues(colorspecials_toggle,
493 XmNleftAttachment, XmATTACH_FORM,
494 XmNtopAttachment, XmATTACH_WIDGET,
495 XmNtopWidget, bg_label,
496 NULL);
497 XtManageChild(colorspecials_toggle);
498 XmToggleButtonGadgetSetState(colorspecials_toggle, resource.use_color, False);
499 XtAddCallback(colorspecials_toggle, XmNvalueChangedCallback, colorspecial_toggle_cb, (XtPointer)info);
500
501 links_frame = XmCreateFrame(form, "links_frame", NULL, 0);
502 XtVaSetValues(links_frame,
503 XmNmarginWidth, 10,
504 XmNmarginHeight, 10,
505 XmNtopAttachment, XmATTACH_FORM,
506 XmNleftAttachment, XmATTACH_WIDGET,
507 XmNleftWidget, text_bg_frame,
508 XmNleftOffset, 10,
509 XmNrightAttachment, XmATTACH_FORM,
510 XmNbottomAttachment, XmATTACH_FORM,
511 NULL);
512
513 links_label = XmCreateLabelGadget(links_frame, "Hyperlinks", &frame_title, 1);
514 XtManageChild(links_label);
515
516 links_form = XmCreateForm(links_frame, "links_form", NULL, 0);
517 XtVaSetValues(links_form,
518 XmNverticalSpacing, 2,
519 NULL);
520
521 unvisited_label = XmCreateLabelGadget(links_form, Xdvi_UNVISITED_LINKS_STR, NULL, 0);
522 unvisited_button = h_create_colorsample(links_form, unvisited_label,
523 Xdvi_UNVISITED_LINKS_BTN, "linkColor",
524 link_pix, info);
525 XtVaSetValues(unvisited_label,
526 XmNleftAttachment, XmATTACH_FORM,
527 XmNtopAttachment, XmATTACH_FORM,
528 NULL);
529 XtVaSetValues(unvisited_button,
530 XmNrightAttachment, XmATTACH_FORM,
531 XmNleftAttachment, XmATTACH_NONE,
532 XmNtopAttachment, XmATTACH_FORM,
533 NULL);
534 adjust_heights(unvisited_label, unvisited_button, NULL);
535 XtManageChild(unvisited_label);
536 XtManageChild(unvisited_button);
537
538 visited_label = XmCreateLabelGadget(links_form, Xdvi_VISITED_LINKS_STR, NULL, 0);
539 visited_button = h_create_colorsample(links_form, visited_label,
540 Xdvi_VISITED_LINKS_BTN, "visitedLinkColor",
541 visited_link_pix, info);
542 XtVaSetValues(visited_label,
543 XmNleftAttachment, XmATTACH_FORM,
544 XmNtopAttachment, XmATTACH_WIDGET,
545 XmNtopWidget, unvisited_label,
546 NULL);
547 XtVaSetValues(visited_button,
548 XmNrightAttachment, XmATTACH_FORM,
549 XmNleftAttachment, XmATTACH_NONE,
550 XmNtopAttachment, XmATTACH_WIDGET,
551 XmNtopWidget, unvisited_label,
552 NULL);
553 adjust_heights(visited_label, visited_button, NULL);
554 XtManageChild(visited_label);
555 XtManageChild(visited_button);
556
557 underline_toggle = XmCreateToggleButtonGadget(links_form, Xdvi_LINKS_UNDERLINED_STR, &n_of_many, 1);
558 XtVaSetValues(underline_toggle,
559 XmNleftAttachment, XmATTACH_FORM,
560 XmNtopAttachment, XmATTACH_WIDGET,
561 XmNtopWidget, visited_label,
562 NULL);
563 XtManageChild(underline_toggle);
564
565 /* if (res->link_style & 1) */
566 if (resource.link_style & 1)
567 XmToggleButtonGadgetSetState(underline_toggle, True, False);
568 else
569 XmToggleButtonGadgetSetState(underline_toggle, False, False);
570
571 XtAddCallback(underline_toggle, XmNvalueChangedCallback, underline_toggle_cb, (XtPointer)info);
572
573 XtManageChild(links_frame);
574 XtManageChild(text_bg_frame);
575
576 XtManageChild(text_bg_form);
577 XtManageChild(links_form);
578
579 return form;
580 }
581
582 void update_preferences_color(void)
583 {
584 Widget shell, button;
585
586 /* it's not an error if the prefs dialog doesn't exist yet */
587 if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, False)
588 && get_widget_by_name(&button, shell, Xdvi_DOCUMENT_COLORS_STR, True)) {
589 XmToggleButtonGadgetSetState(button, resource.use_color, False);
590 }
591 }
592
593 void update_preferences_hyperlinks(void)
594 {
595 Widget shell, button;
596
597 /* it's not an error if the prefs dialog doesn't exist yet */
598 if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, False)
599 && get_widget_by_name(&button, shell, Xdvi_LINKS_UNDERLINED_STR, True)) {
600 XmToggleButtonGadgetSetState(button, resource.link_style & 1 ? True : False, False);
601 }
602 }
603
604 void update_preferences_darkness(void)
605 {
606 Widget shell, text;
607
608 if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, False)
609 && get_widget_by_name(&text, shell, Xdvi_DARKNESS_TEXT, True)) {
610
611 char buf[LENGTH_OF_INT];
612 SNPRINTF(buf, LENGTH_OF_INT, "%d", (int)(resource.gamma * 100.0 + 0.5));
613 #if USE_SPINBOX
614 XmTextFieldSetString(text, buf);
615 XtVaSetValues(text, XmNposition, (int)(resource.gamma * 100.0 + 0.5), NULL);
616 #else
617 XtVaSetValues(text, XmNvalue, buf, NULL);
618 #endif
619 }
620 }
621
622 Widget
623 prefs_fonts_and_colors(struct topic_info *info)
624 {
625 Widget form;
626 Widget colors_form;
627 Widget other_colors_frame, fonts_frame;
628
629 form = XmCreateForm(info->right_form, "fonts_colors_form", NULL, 0);
630 h_attach_below(form, NULL);
631
632 colors_form = h_create_colors_form(form, info);
633 h_attach_below(colors_form, NULL);
634 XtManageChild(colors_form);
635
636 { /* other colors - currently only highlight color */
637 Widget other_colors_form, other_colors_label;
638 Widget hl_color_text, hl_color_button;
639
640 other_colors_frame = XmCreateFrame(form, "other_colors_frame", &v_off, 1);
641 XtVaSetValues(other_colors_frame,
642 XmNmarginWidth, 10,
643 NULL);
644 h_attach_below(other_colors_frame, colors_form);
645
646 other_colors_label = XmCreateLabelGadget(other_colors_frame, "Highlight Color", &frame_title, 1);
647 other_colors_form = XmCreateForm(other_colors_frame, "other_colors_form", NULL, 0);
648 XtVaSetValues(other_colors_form, XmNverticalSpacing, 2, NULL);
649
650 hl_color_text = XmCreateLabelGadget(other_colors_form,
651 #if defined(LESSTIF_VERSION) /* stupid LessTif doesn't wrap Labels at '\n' */
652 "Color of page border, rulers and bounding boxes.",
653 #else
654 "Color used for page border, rulers in `ruler mode', and\n"
655 "bounding boxes for forward search and EPS images.",
656 #endif
657 NULL, 0);
658 hl_color_button = h_create_colorsample(other_colors_form, hl_color_text,
659 Xdvi_HL_COLOR_BTN, "highlight",
660 resource.hl_Pixel, info);
661 XtVaSetValues(hl_color_text,
662 XmNleftAttachment, XmATTACH_FORM,
663 XmNtopAttachment, XmATTACH_FORM,
664 XmNbottomAttachment, XmATTACH_FORM,
665 XmNbottomOffset, 10,
666 XmNalignment, XmALIGNMENT_BEGINNING,
667 NULL);
668 XtVaSetValues(hl_color_button,
669 XmNtopAttachment, XmATTACH_FORM,
670 XmNrightAttachment, XmATTACH_FORM,
671 NULL);
672
673 XtManageChild(hl_color_text);
674 XtManageChild(hl_color_button);
675 XtManageChild(other_colors_form);
676 XtManageChild(other_colors_label);
677 XtManageChild(other_colors_frame);
678 }
679
680 fonts_frame = h_create_fonts_frame(form, info);
681 h_attach_below(fonts_frame, other_colors_frame);
682 XtManageChild(fonts_frame);
683
684 XtManageChild(form);
685
686 return form;
687 }
688
689 #else
690 /* silence `empty compilation unit' warnings */
691 static void bar(void); static void foo(void) { bar(); } static void bar(void) { foo(); }
692 #endif /* MOTIF */