Back to index

tetex-bin  3.0
xm_prefs_fonts.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 Stefan Ulrich
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to
00006  * deal in the Software without restriction, including without limitation the
00007  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00008  * sell copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00017  * PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM,
00018  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  */
00023 
00024 /*
00025  * Panel 2 (Fonts and colors) for xdvik preferences dialog.
00026  */
00027 
00028 #include "xdvi-config.h"
00029 #include "xdvi.h"
00030 
00031 #include "x_util.h"
00032 #include "xm_colorsel.h"
00033 #include "topic-window.h"
00034 #include "util.h"
00035 #include "events.h"
00036 #include "hypertex.h"
00037 #include "my-snprintf.h"
00038 
00039 #include "xm_prefsP.h"
00040 #include "xm_prefs_fonts.h"
00041 
00042 #ifdef MOTIF /* entire file */
00043 
00044 #include <X11/Xatom.h>
00045 
00046 #include <Xm/Xm.h>
00047 #include <Xm/Protocols.h>
00048 #include <Xm/DialogS.h>
00049 #include <Xm/LabelG.h>
00050 #include <Xm/PushB.h>
00051 #include <Xm/Form.h>
00052 #include <Xm/Frame.h>
00053 #include <Xm/PanedW.h>
00054 #include <Xm/DrawnB.h>
00055 #include <Xm/RowColumn.h>
00056 #include <Xm/Scale.h>
00057 #include <Xm/ToggleBG.h>
00058 #include <Xm/Text.h>
00059 #include <Xm/TextF.h>
00060 
00061 #if XmVersion >= 2000 && !defined(LESSTIF_VERSION)
00062 /* spinbox only available with Motif 2.0; the lesstif version (as of 0.93) looks like shit */
00063 #include <Xm/SpinB.h>
00064 #define USE_SPINBOX 1
00065 #else
00066 #define USE_SPINBOX 0
00067 #endif
00068 
00069 /*
00070  * Handy defaults
00071  */
00072 static Arg v_off = { XmNtopOffset, 10 };
00073 static Arg n_of_many = { XmNindicatorType, XmN_OF_MANY };
00074 static Arg frame_title = { XmNchildType, XmFRAME_TITLE_CHILD };
00075 
00076 
00077 static void
00078 underline_toggle_cb(Widget w, XtPointer client_data, XtPointer call_data)
00079 {
00080     struct topic_info *tinfo = (struct topic_info *)client_data;
00081     struct prefs_choice *prefs;
00082     Boolean is_set;
00083     
00084     UNUSED(call_data);
00085 
00086     ASSERT(tinfo != NULL, "struct topic_info * in underline_toggle_cb mustn't be NULL!");
00087     prefs = (struct prefs_choice *)tinfo->data;
00088     
00089     XtVaGetValues(w, XmNset, &is_set, NULL);
00090     if (is_set)
00091        resource.link_style |= 1;
00092     else
00093        resource.link_style &= ~1;
00094 
00095     store_preference(&(prefs->db), "linkStyle", "%d", resource.link_style);
00096 
00097     /* update display */
00098     globals.ev.flags |= EV_NEWPAGE;
00099     XFlush(DISP);
00100 }
00101 
00102 static void
00103 colorspecial_toggle_cb(Widget w, XtPointer client_data, XtPointer call_data)
00104 {
00105     struct topic_info *tinfo = (struct topic_info *)client_data;
00106     struct prefs_choice *prefs;
00107 
00108     UNUSED(w);
00109 /*     UNUSED(client_data); */
00110     UNUSED(call_data);
00111 
00112     ASSERT(tinfo != NULL, "struct topic_info * in colorspecial_toggle_cb mustn't be NULL!");
00113     prefs = (struct prefs_choice *)tinfo->data;
00114     
00115     do_toggle_color(False);
00116     store_preference(&(prefs->db), "color", "%s", resource.use_color ? "True" : "False");
00117 }
00118 
00119 static void
00120 darkness_text_cb(Widget w, XtPointer client_data, XtPointer call_data)
00121 {
00122     char *text;
00123     int val;
00124     struct topic_info *info = (struct topic_info *)client_data;
00125     struct prefs_choice *prefs = (struct prefs_choice *)(info->data);
00126     
00127 #if USE_SPINBOX
00128     /* synchronize internal spinbox value. Apparently this loses the insertion position,
00129        so we need to save it and set it again. */
00130     XmTextPosition pos = XmTextFieldGetInsertionPosition(w);
00131     
00132     UNUSED(call_data);
00133     text = XmTextFieldGetString(w);
00134     val = strtol(text, (char **)NULL, 10);
00135 
00136     if (val != 0) {
00137        XtVaSetValues(w, XmNposition, val, NULL);
00138        XmTextFieldSetInsertionPosition(w, pos);
00139     }
00140 #else
00141     Widget text_field;
00142     UNUSED(call_data);
00143 
00144     XtVaGetValues(w, XmNuserData, &text_field, NULL);
00145     XtVaGetValues(text_field, XmNvalue, &text, NULL);
00146     val = strtol(text, (char **)NULL, 10);
00147 #endif
00148     if (XtIsRealized(w)) {
00149        do_set_density(val / 100.0, True, False);
00150        store_preference(&(prefs->db), "gamma", "%f", val / 100.0);
00151     }
00152     XtFree(text);
00153 }
00154 
00155 
00156 #if 0 /* currently unused */
00157 static void
00158 darkness_spinbox_cb(Widget w, XtPointer client_data, XtPointer call_data)
00159 {
00160     int val;
00161     struct topic_info *info = (struct topic_info *)client_data;
00162     struct prefs_choice *prefs = (struct prefs_choice *)(info->data);
00163     UNUSED(client_data);
00164     UNUSED(call_data);
00165 
00166     XtVaGetValues(w, XmNposition, &val, NULL);
00167     if (XtIsRealized(w)) {
00168        do_set_density(val / 100.0, True, False);
00169        /* fprintf(stderr, "storing pref: %d\n", val); */
00170        store_preference(&(prefs->db), "gamma", "%f", val / 100.0);
00171     }
00172        
00173 }
00174 #endif /* currently unused */
00175 
00176 
00177 void
00178 h_update_hyperlinks(Widget w, Pixel pix)
00179 {
00180     const char *name = XtName(w);
00181     int type = 0;
00182 
00183     if (strcmp(name, Xdvi_UNVISITED_LINKS_BTN) == 0) {
00184        type = 1;
00185     }
00186     else if (strcmp(name, Xdvi_VISITED_LINKS_BTN) == 0) {
00187        type = 2;
00188     }
00189 
00190     /* fprintf(stderr, "WIDGET: |%s|; type: %d\n", name, type); */
00191 
00192     if (type != 0) {
00193        GC new_gc = set_or_make_gc(NULL, GXcopy, pix, resource.back_Pixel);
00194        GC old_gc;
00195        double r, g, b;
00196        double factor = 65535.0;
00197        XColor color;
00198 
00199        pixel_to_color(pix, &color, DISP, G_colormap);
00200        r = color.red / factor;
00201        g = color.green / factor;
00202        b = color.blue / factor;
00203 
00204        if (type == 1) {
00205            old_gc = globals.gc.linkcolor;
00206            sprintf(g_link_color_rgb, "push rgb %.2f %.2f %.2f", r, g, b);
00207        }
00208        else {
00209            old_gc = globals.gc.visited_linkcolor;
00210            sprintf(g_visited_link_color_rgb, "push rgb %.2f %.2f %.2f", r, g, b);
00211        }
00212 
00213        if (type == 1) {
00214            globals.gc.linkcolor = new_gc;
00215            XFreeGC(XtDisplay(w), old_gc);
00216        }
00217        else {
00218            globals.gc.visited_linkcolor = new_gc;
00219            XFreeGC(XtDisplay(w), old_gc);
00220        }
00221        /* update display */
00222        globals.ev.flags |= EV_NEWPAGE;
00223        XFlush(DISP);
00224     }
00225 }
00226 
00227 static void
00228 redraw_or_push_cb(Widget w, XtPointer client_data, XtPointer call_data)
00229 {
00230     XmDrawnButtonCallbackStruct *cbs = (XmDrawnButtonCallbackStruct *)call_data;
00231     static GC border_gc = 0;
00232     struct color_button_info *cinfo;
00233     Pixel pix = (Pixel)client_data;
00234 
00235     if (cbs == NULL) {
00236        XDVI_WARNING((stderr, "cinfo mustn't be NULL in redraw_or_push_cb!\n"));
00237        return;
00238     }
00239 
00240     /* this can also be called via XtCallCallbacks, without call_data */
00241     if (cbs->reason == XmCR_EXPOSE) {
00242        /* redraw button label */
00243        Dimension high_thick, st, wd, ht;
00244        Dimension inner_w, inner_h, off_x, off_y;
00245        GC label_gc;
00246        XGCValues values;
00247        
00248        XtVaGetValues(w,
00249                     XmNhighlightThickness, &high_thick,
00250                     XmNshadowThickness, &st,
00251                     XmNwidth, &wd,
00252                     XmNheight, &ht,
00253                     XmNuserData, &cinfo,
00254                     NULL);
00255        
00256        values.function = GXcopy;
00257        
00258        if (border_gc == 0) {
00259            /* create the static GC for drawing the border - Note: never free'd! */
00260            values.foreground = BlackPixelOfScreen(XtScreen(w));
00261            /* values.line_width = 2; */
00262            /* note: never free'd! */
00263            border_gc = XCreateGC(XtDisplay(w), XtWindow(w),
00264                               GCFunction | GCForeground /*  | GCLineWidth */, &values);
00265        }
00266        values.foreground = cinfo->pixel;
00267        label_gc = XCreateGC(XtDisplay(w), XtWindow(w),
00268                           GCFunction | GCForeground, &values);
00269        
00270        off_x = high_thick + st + 4;
00271        inner_w = wd - 2 * off_x;
00272        off_y = high_thick + st + 4;
00273        inner_h = ht - 2 * off_y;
00274 #if 0
00275        fprintf(stderr, "shadow: %d, high: %d\n", st, high_thick);
00276        fprintf(stderr, "width: %d, height: %d\n", wd, ht);
00277        fprintf(stderr, "inner w: %d, inner h: %d\n", inner_w, inner_h);
00278 #endif
00279        
00280        XFillRectangle(XtDisplay(w), XtWindow(w), label_gc,
00281                      off_x, off_y, inner_w, inner_h);
00282        XDrawRectangle(XtDisplay(w), XtWindow(w), border_gc,
00283                      off_x - 1, off_y - 1, inner_w + 1, inner_h + 1);
00284        XFreeGC(XtDisplay(w), label_gc);
00285 
00286        if (pix != cinfo->pixel) {
00287            h_update_hyperlinks(w, cinfo->pixel);
00288        }
00289     }
00290     else if (cbs->reason == XmCR_ACTIVATE) {
00291        /* pushed, open color dialog */
00292        XtVaGetValues(w, XmNuserData, &cinfo, NULL);
00293        if (cinfo != NULL) {
00294            cinfo->w = w;
00295            popup_color_dialog(globals.widgets.top_level, cinfo);
00296        }
00297        else {
00298            XDVI_WARNING((stderr, "cinfo mustn't be NULL in redraw_or_push_cb!\n"));
00299            return;
00300        }
00301     }
00302     /* else, XmCR_RESIZE - nothing to do */
00303 }
00304 
00305 static Widget
00306 h_create_colorsample(Widget parent, Widget left,
00307                    const char *name,
00308                    const char *resource_name,
00309                    Pixel pix,
00310                    struct topic_info *info)
00311 {
00312     struct color_button_info *cinfo = xmalloc(sizeof *cinfo); /* note: never free()d */
00313     Widget button;
00314     
00315     UNUSED(left);
00316 
00317     cinfo->pixel = pix;
00318     cinfo->tinfo = info;
00319     cinfo->resource_name = xstrdup(resource_name); /* note: never free()d */
00320     
00321     button = XtVaCreateManagedWidget(name, xmDrawnButtonWidgetClass, parent,
00322                                  XtNwidth, 42,
00323                                  XtNheight, 28,
00324                                  XmNuserData, cinfo,
00325                                  /* we want the normal button look here to
00326                                    make it obvious that users can press it */
00327                                  XmNshadowType, XmSHADOW_OUT,
00328                                  XmNpushButtonEnabled, True,
00329                                  NULL);
00330     XtAddCallback(button, XmNactivateCallback, redraw_or_push_cb, (XtPointer)pix);
00331     XtAddCallback(button, XmNexposeCallback, redraw_or_push_cb, (XtPointer)pix);
00332     XtAddCallback(button, XmNresizeCallback, redraw_or_push_cb, (XtPointer)pix);
00333 
00334     return button;
00335 }
00336 
00337 
00338 static Widget
00339 h_create_fonts_frame(Widget top, struct topic_info *info)
00340 {
00341     Widget darkness_form, darkness_label;
00342 
00343     UNUSED(info);
00344     
00345     darkness_form = XmCreateForm(top, "darkness_form", NULL, 0);
00346     XtVaSetValues(darkness_form,
00347                 XmNverticalSpacing, 10,
00348                 XmNhorizontalSpacing, 10,
00349                 NULL);
00350 
00351     
00352     darkness_label = XmCreateLabelGadget(darkness_form, "Font Darkness: ", NULL, 0);
00353     XtVaSetValues(darkness_label,
00354                 XmNtopAttachment, XmATTACH_FORM,
00355                 XmNleftAttachment, XmATTACH_FORM,
00356                 XmNbottomAttachment, XmATTACH_FORM,
00357                 NULL);
00358     XtManageChild(darkness_label);
00359     {
00360        Widget darkness_text;
00361 #if USE_SPINBOX
00362        Widget darkness_spinbox = XmCreateSpinBox(darkness_form, Xdvi_DARKNESS_SPINBOX, NULL, 0);
00363        darkness_text = XmCreateTextField(darkness_spinbox, Xdvi_DARKNESS_TEXT, NULL, 0);
00364        XtVaSetValues(darkness_spinbox,
00365                     XmNtopAttachment, XmATTACH_FORM,
00366                     XmNleftAttachment, XmATTACH_WIDGET,
00367                     XmNleftWidget, darkness_label,
00368                     XmNinitialDelay, 200,
00369                     XmNrepeatDelay, 50,
00370                     NULL);
00371        XtVaSetValues(darkness_text,
00372                     XmNspinBoxChildType, XmNUMERIC,
00373                     XmNminimumValue, 0,
00374                     XmNmaximumValue, 1000,
00375                     XmNeditable, True,
00376                     XmNcolumns, 4,
00377                     XmNincrementValue, 1,
00378                     XmNwrap, False, /* too confusing */
00379                     XmNposition, (int)(resource.gamma * 100.0 + 0.5),
00380                     NULL);
00381        XtAddCallback(darkness_text, XmNactivateCallback, darkness_text_cb, (XtPointer)info);
00382        XtAddCallback(darkness_text, XmNvalueChangedCallback, darkness_text_cb, (XtPointer)info);
00383 
00384        adjust_heights(darkness_spinbox, darkness_text, darkness_label, NULL);
00385        
00386        XtManageChild(darkness_text);
00387        XtManageChild(darkness_spinbox);
00388 #else
00389        char buf[LENGTH_OF_INT];
00390        Widget darkness_button;
00391        darkness_text = XmCreateTextField(darkness_form, Xdvi_DARKNESS_TEXT, NULL, 0);
00392        SNPRINTF(buf, LENGTH_OF_INT, "%d", (int)(resource.gamma * 100.0 + 0.5));
00393        XtVaSetValues(darkness_text,
00394                     XmNtopAttachment, XmATTACH_FORM,
00395                     XmNleftAttachment, XmATTACH_WIDGET,
00396                     XmNleftWidget, darkness_label,
00397                     XmNcolumns, 4,
00398                     XmNvalue, buf,
00399                     XmNuserData, darkness_text,
00400                     NULL);
00401        XtOverrideTranslations(darkness_text, XtParseTranslationTable("<Key>Return:activate()"));
00402        XtAddCallback(darkness_text, XmNactivateCallback, darkness_text_cb, (XtPointer)info);
00403 
00404        darkness_button = XmCreatePushButton(darkness_form, Xdvi_APPLY_STR, NULL, 0);
00405        XtVaSetValues(darkness_button,
00406                     XmNtopAttachment, XmATTACH_FORM,
00407                     XmNleftAttachment, XmATTACH_WIDGET,
00408                     XmNleftWidget, darkness_text,
00409                     XmNuserData, darkness_text,
00410                     NULL);
00411        XtAddCallback(darkness_button, XmNactivateCallback, darkness_text_cb, (XtPointer)info);
00412        
00413        adjust_heights(darkness_label, darkness_text, darkness_button, NULL);
00414        XtManageChild(darkness_text);
00415        XtManageChild(darkness_button);
00416 #endif
00417     }
00418     
00419 /*     XtManageChild(darkness_form); */
00420 
00421     return darkness_form;
00422 }
00423 
00424 static Widget
00425 h_create_colors_form(Widget top, struct topic_info *info)
00426 {
00427     Widget text_bg_frame, text_bg_label, text_bg_form;
00428     Widget links_frame, links_label, links_form;
00429     Widget fg_label, fg_button;
00430     Widget bg_label, bg_button;
00431     Widget unvisited_label, unvisited_button;
00432     Widget visited_label, visited_button;
00433     Widget underline_toggle;
00434     Widget colorspecials_toggle;
00435     
00436     Widget form = XmCreateForm(top, "colors_form", NULL, 0);
00437     Pixel visited_link_pix, link_pix;
00438 
00439     str_to_pixel(top, resource.visited_link_color, &visited_link_pix);
00440     str_to_pixel(top, resource.link_color, &link_pix);
00441     
00442     text_bg_frame = XmCreateFrame(form, "text_bg_frame", NULL, 0);
00443     XtVaSetValues(text_bg_frame,
00444                 XmNmarginWidth, 10,
00445                 XmNmarginHeight, 10,
00446                 XmNtopAttachment, XmATTACH_FORM,
00447                 XmNleftAttachment, XmATTACH_FORM,
00448                 XmNrightAttachment, XmATTACH_POSITION,
00449                 XmNrightPosition, 50,
00450                 XmNrightOffset, 10,
00451                 XmNbottomAttachment, XmATTACH_FORM,
00452                 NULL);
00453 
00454     text_bg_label = XmCreateLabelGadget(text_bg_frame, "Text Color", &frame_title, 1);
00455     XtManageChild(text_bg_label);
00456 
00457     text_bg_form = XmCreateForm(text_bg_frame, "fg_form", NULL, 0);
00458     XtVaSetValues(text_bg_form, XmNverticalSpacing, 2, NULL);
00459     
00460     fg_label = XmCreateLabelGadget(text_bg_form, Xdvi_FG_COLOR_STR, NULL, 0);
00461     fg_button = h_create_colorsample(text_bg_form, fg_label,
00462                                  Xdvi_FG_COLOR_BTN, "foreground",
00463                                  resource.fore_Pixel, info);
00464     XtVaSetValues(fg_label,
00465                 XmNleftAttachment, XmATTACH_FORM,
00466                 XmNtopAttachment, XmATTACH_FORM,
00467                 NULL);
00468     XtVaSetValues(fg_button,
00469                 XmNrightAttachment, XmATTACH_FORM,
00470                 XmNleftAttachment, XmATTACH_NONE,
00471                 NULL);
00472     adjust_heights(fg_label, fg_button, NULL);
00473     XtManageChild(fg_label);
00474     XtManageChild(fg_button);
00475     
00476     bg_label = XmCreateLabelGadget(text_bg_form, Xdvi_BG_COLOR_STR, NULL, 0);
00477     bg_button = h_create_colorsample(text_bg_form, bg_label,
00478                                  Xdvi_BG_COLOR_BTN, "background",
00479                                  resource.back_Pixel, info);
00480     XtVaSetValues(bg_label,
00481                 XmNleftAttachment, XmATTACH_FORM,
00482                 XmNtopAttachment, XmATTACH_WIDGET,
00483                 XmNtopWidget, fg_label,
00484                 NULL);
00485     XtVaSetValues(bg_button,
00486                 XmNrightAttachment, XmATTACH_FORM,
00487                 XmNleftAttachment, XmATTACH_NONE,
00488                 XmNtopAttachment, XmATTACH_WIDGET,
00489                 XmNtopWidget, fg_label,
00490                 NULL);
00491     adjust_heights(bg_label, bg_button, NULL);
00492     XtManageChild(bg_label);
00493     XtManageChild(bg_button);
00494 
00495     colorspecials_toggle = XmCreateToggleButtonGadget(text_bg_form, Xdvi_DOCUMENT_COLORS_STR, &n_of_many, 1);
00496     XtVaSetValues(colorspecials_toggle,
00497                 XmNleftAttachment, XmATTACH_FORM,
00498                 XmNtopAttachment, XmATTACH_WIDGET,
00499                 XmNtopWidget, bg_label,
00500                 NULL);
00501     XtManageChild(colorspecials_toggle);
00502     XmToggleButtonGadgetSetState(colorspecials_toggle, resource.use_color, False);
00503     XtAddCallback(colorspecials_toggle, XmNvalueChangedCallback, colorspecial_toggle_cb, (XtPointer)info);
00504     
00505     links_frame = XmCreateFrame(form, "links_frame", NULL, 0);
00506     XtVaSetValues(links_frame,
00507                 XmNmarginWidth, 10,
00508                 XmNmarginHeight, 10,
00509                 XmNtopAttachment, XmATTACH_FORM,
00510                 XmNleftAttachment, XmATTACH_WIDGET,
00511                 XmNleftWidget, text_bg_frame,
00512                 XmNleftOffset, 10,
00513                 XmNrightAttachment, XmATTACH_FORM,
00514                 XmNbottomAttachment, XmATTACH_FORM,
00515                 NULL);
00516 
00517     links_label = XmCreateLabelGadget(links_frame, "Hyperlinks", &frame_title, 1);
00518     XtManageChild(links_label);
00519 
00520     links_form = XmCreateForm(links_frame, "links_form", NULL, 0);
00521     XtVaSetValues(links_form,
00522                 XmNverticalSpacing, 2,
00523                 NULL);
00524 
00525     unvisited_label = XmCreateLabelGadget(links_form, Xdvi_UNVISITED_LINKS_STR, NULL, 0);
00526     unvisited_button = h_create_colorsample(links_form, unvisited_label,
00527                                        Xdvi_UNVISITED_LINKS_BTN, "linkColor",
00528                                        link_pix, info);
00529     XtVaSetValues(unvisited_label,
00530                 XmNleftAttachment, XmATTACH_FORM,
00531                 XmNtopAttachment, XmATTACH_FORM,
00532                 NULL);
00533     XtVaSetValues(unvisited_button,
00534                 XmNrightAttachment, XmATTACH_FORM,
00535                 XmNleftAttachment, XmATTACH_NONE,
00536                 XmNtopAttachment, XmATTACH_FORM,
00537                 NULL);
00538     adjust_heights(unvisited_label, unvisited_button, NULL);
00539     XtManageChild(unvisited_label);
00540     XtManageChild(unvisited_button);
00541     
00542     visited_label = XmCreateLabelGadget(links_form, Xdvi_VISITED_LINKS_STR, NULL, 0);
00543     visited_button = h_create_colorsample(links_form, visited_label,
00544                                      Xdvi_VISITED_LINKS_BTN, "visitedLinkColor",
00545                                      visited_link_pix, info);
00546     XtVaSetValues(visited_label,
00547                 XmNleftAttachment, XmATTACH_FORM,
00548                 XmNtopAttachment, XmATTACH_WIDGET,
00549                 XmNtopWidget, unvisited_label,
00550                 NULL);
00551     XtVaSetValues(visited_button,
00552                 XmNrightAttachment, XmATTACH_FORM,
00553                 XmNleftAttachment, XmATTACH_NONE,
00554                 XmNtopAttachment, XmATTACH_WIDGET,
00555                 XmNtopWidget, unvisited_label,
00556                 NULL);
00557     adjust_heights(visited_label, visited_button, NULL);
00558     XtManageChild(visited_label);
00559     XtManageChild(visited_button);
00560 
00561     underline_toggle = XmCreateToggleButtonGadget(links_form, Xdvi_LINKS_UNDERLINED_STR, &n_of_many, 1);
00562     XtVaSetValues(underline_toggle,
00563                 XmNleftAttachment, XmATTACH_FORM,
00564                 XmNtopAttachment, XmATTACH_WIDGET,
00565                 XmNtopWidget, visited_label,
00566                 NULL);
00567     XtManageChild(underline_toggle);
00568 
00569 /*     if (res->link_style & 1) */
00570     if (resource.link_style & 1)
00571        XmToggleButtonGadgetSetState(underline_toggle, True, False);
00572     else
00573        XmToggleButtonGadgetSetState(underline_toggle, False, False);
00574     
00575     XtAddCallback(underline_toggle, XmNvalueChangedCallback, underline_toggle_cb, (XtPointer)info);
00576     
00577     XtManageChild(links_frame);
00578     XtManageChild(text_bg_frame);
00579 
00580     XtManageChild(text_bg_form);
00581     XtManageChild(links_form);
00582 
00583     return form;
00584 }
00585 
00586 void update_preferences_color(void)
00587 {
00588     Widget shell, button;
00589 
00590     /* it's not an error if the prefs dialog doesn't exist yet */
00591     if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, False)
00592        && get_widget_by_name(&button, shell, Xdvi_DOCUMENT_COLORS_STR, True)) {
00593        XmToggleButtonGadgetSetState(button, resource.use_color, False);
00594     }
00595 }
00596 
00597 void update_preferences_hyperlinks(void)
00598 {
00599     Widget shell, button;
00600 
00601     /* it's not an error if the prefs dialog doesn't exist yet */
00602     if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, False)
00603        && get_widget_by_name(&button, shell, Xdvi_LINKS_UNDERLINED_STR, True)) {
00604        XmToggleButtonGadgetSetState(button, resource.link_style & 1 ? True : False, False);
00605     }
00606 }
00607 
00608 void update_preferences_darkness(void)
00609 {
00610     Widget shell, text;
00611 
00612     if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, False)
00613        && get_widget_by_name(&text, shell, Xdvi_DARKNESS_TEXT, True)) {
00614 
00615        char buf[LENGTH_OF_INT];
00616        SNPRINTF(buf, LENGTH_OF_INT, "%d", (int)(resource.gamma * 100.0 + 0.5));
00617 #if USE_SPINBOX
00618        XmTextFieldSetString(text, buf);
00619        XtVaSetValues(text, XmNposition, (int)(resource.gamma * 100.0 + 0.5), NULL);
00620 #else
00621        XtVaSetValues(text, XmNvalue, buf, NULL);
00622 #endif
00623     }
00624 }
00625 
00626 Widget
00627 prefs_fonts_and_colors(struct topic_info *info)
00628 {
00629     Widget form;
00630     Widget colors_form;
00631     Widget other_colors_frame, fonts_frame;
00632 
00633     form = XmCreateForm(info->right_form, "fonts_colors_form", NULL, 0);
00634     h_attach_below(form, NULL);
00635     
00636     colors_form = h_create_colors_form(form, info);
00637     h_attach_below(colors_form, NULL);
00638     XtManageChild(colors_form);
00639 
00640     {  /* other colors - currently only highlight color */
00641        Widget other_colors_form, other_colors_label;
00642        Widget hl_color_text, hl_color_button;
00643        
00644        other_colors_frame = XmCreateFrame(form, "other_colors_frame", &v_off, 1);
00645        XtVaSetValues(other_colors_frame,
00646                     XmNmarginWidth, 10,
00647                     NULL);
00648        h_attach_below(other_colors_frame, colors_form);
00649 
00650        other_colors_label = XmCreateLabelGadget(other_colors_frame, "Highlight Color", &frame_title, 1);
00651        other_colors_form = XmCreateForm(other_colors_frame, "other_colors_form", NULL, 0);
00652        XtVaSetValues(other_colors_form, XmNverticalSpacing, 2, NULL);
00653 
00654        hl_color_text = XmCreateLabelGadget(other_colors_form,
00655 #if defined(LESSTIF_VERSION) /* stupid LessTif doesn't wrap Labels at '\n' */
00656                                        "Color of page border, rulers and bounding boxes.",
00657 #else                                  
00658                                        "Color used for page border, rulers in `ruler mode', and\n"
00659                                        "bounding boxes for forward search and EPS images.",
00660 #endif
00661                                        NULL, 0);
00662        hl_color_button = h_create_colorsample(other_colors_form, hl_color_text,
00663                                           Xdvi_HL_COLOR_BTN, "highlight",
00664                                           resource.hl_Pixel, info);
00665        XtVaSetValues(hl_color_text,
00666                     XmNleftAttachment, XmATTACH_FORM,
00667                     XmNtopAttachment, XmATTACH_FORM,
00668                     XmNbottomAttachment, XmATTACH_FORM,
00669                     XmNbottomOffset, 10,
00670                     XmNalignment, XmALIGNMENT_BEGINNING,
00671                     NULL);
00672        XtVaSetValues(hl_color_button,
00673                     XmNtopAttachment, XmATTACH_FORM,
00674                     XmNrightAttachment, XmATTACH_FORM,
00675                     NULL);
00676        
00677        XtManageChild(hl_color_text);
00678        XtManageChild(hl_color_button);
00679        XtManageChild(other_colors_form);
00680        XtManageChild(other_colors_label);
00681        XtManageChild(other_colors_frame);
00682     }
00683     
00684     fonts_frame = h_create_fonts_frame(form, info);
00685     h_attach_below(fonts_frame, other_colors_frame);
00686     XtManageChild(fonts_frame);
00687 
00688     XtManageChild(form);
00689 
00690     return form;
00691 }
00692 
00693 #else
00694 /* silence `empty compilation unit' warnings */
00695 static void bar(void); static void foo() { bar(); } static void bar(void) { foo(); }
00696 #endif /* MOTIF */