Back to index

tetex-bin  3.0
Typedefs | Functions | Variables
x_util.h File Reference
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include "xdvi.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* property_cbT )(Window w)

Functions

void center_window (Widget w1, Widget w2)
void position_window (Widget w, Position x, Position y)
void scroll_page_if_needed (int x_min, int x_max, int y_min, int y_max)
void adjust_width (Widget a, Widget b)
GC set_or_make_gc (GC gc, int function, Pixel fg, Pixel bg)
size_t property_get_data (Window, Atom, char **, int(*x_get_property)(Display *, Window, Atom, long, long, Bool, Atom, Atom *, int *, unsigned long *, unsigned long *, unsigned char **))
size_t property_get_window_list (char **window_list)
void set_dvi_property (void)
 set_dvi_property sets the appropriate property for the main window (used in source special handoff).
void set_window_id (Window w, unsigned char *data)
Window get_window_id (char *window_p)
void update_window_property (Window w, Boolean prepend)
void update_dvi_property (void)
void property_initialize (void)
Atom atom_xdvi_windows (void)
Atom atom_dvi_file (void)
Atom atom_src_goto (void)
Atom atom_find_string (void)
Atom atom_reload (void)
Atom atom_newdoc (void)
Atom atom_newpage (void)
Atom atom_raise (void)
Atom atom_reread_prefs (void)
void synthetisize_event (XEvent *ev, Widget button)
Widget get_matching_parent (Widget w, Widget p, const char *fmt,...)
Boolean widget_is_parent (Widget w, Widget p, Widget s)
void adjust_vertically (Widget w1, Widget w2, int default_dist)
void adjust_heights (Widget w1,...)
void adjust_heights_min (Widget w1,...)
void block_event_callback (Widget w, XtPointer client_data, XEvent *ev, Boolean *cont)
void unexpected_widget_in_callback (Widget w, const char *callback)
Boolean get_widget_by_name (Widget *ret, Widget parent, const char *name, Boolean report_error)
void merge_into_user_db (XrmDatabase db)
void store_user_preference (const char *name, const char *fmt,...)
void store_preference (XrmDatabase *db, const char *name, const char *fmt,...)
Boolean save_user_preferences (Boolean full_save)
void read_user_preferences (Widget toplevel, const char *filename)
Window get_xdvi_window_id (Boolean same_file, property_cbT callback)
void set_string_property (const char *str, Atom prop, Window win)
Boolean clip_region (int *x, int *y, int *w, int *h)
Boolean clip_region_to_rect (XRectangle *rect)

Variables

Boolean do_autoscroll

Typedef Documentation

typedef void(* property_cbT)(Window w)

Definition at line 134 of file x_util.h.


Function Documentation

void adjust_heights ( Widget  w1,
  ... 
)

Definition at line 626 of file x_util.c.

{
    va_list ap;
    Widget curr;
    Dimension h, max;

    ASSERT(w != NULL, "Must have at least one element in va_list for adjust_heights!");

#if MOTIF
#define HEIGHT XmNheight
#else
#define HEIGHT XtNheight
#endif
    
    /* initialize maximum */
    XtVaGetValues(w, HEIGHT, &max, NULL);

    /* get maximum height */
    va_start(ap, w);
    while ((curr = va_arg(ap, Widget)) != NULL) {
       XtVaGetValues(curr, HEIGHT, &h, NULL);
       if (h > max)
           max = h;
    }
    va_end(ap);

    /* set maximum height for all widgets */
    XtVaSetValues(w, HEIGHT, max, NULL);
    
    va_start(ap, w);
    while ((curr = va_arg(ap, Widget)) != NULL)
       XtVaSetValues(curr, HEIGHT, max, NULL);
    va_end(ap);

#undef HEIGHT

}

Here is the caller graph for this function:

void adjust_heights_min ( Widget  w1,
  ... 
)

Definition at line 669 of file x_util.c.

{
    va_list ap;
    Widget curr;
    Dimension h, min;

    ASSERT(w != NULL, "Must have at least one element in va_list for adjust_heights!");

#if MOTIF
#define HEIGHT XmNheight
#else
#define HEIGHT XtNheight
#endif
    
    /* initialize minimum */
    XtVaGetValues(w, HEIGHT, &min, NULL);

    /* get minimum height */
    va_start(ap, w);
    while ((curr = va_arg(ap, Widget)) != NULL) {
       XtVaGetValues(curr, HEIGHT, &h, NULL);
       if (h < min)
           min = h;
    }
    va_end(ap);

    /* set maximum height for all widgets */
    XtVaSetValues(w, HEIGHT, min, NULL);
    
    va_start(ap, w);
    while ((curr = va_arg(ap, Widget)) != NULL)
       XtVaSetValues(curr, HEIGHT, min, NULL);
    va_end(ap);

#undef HEIGHT

}
void adjust_vertically ( Widget  w1,
Widget  w2,
int  default_dist 
)

Definition at line 709 of file x_util.c.

{
    Dimension h1, h2;
#if MOTIF
    XtVaGetValues(w1, XmNheight, &h1, NULL);
    XtVaGetValues(w2, XmNheight, &h2, NULL);
    XtVaSetValues(w1, XmNtopOffset, default_dist + (h2 - h1) / 2, NULL);
    /*     XtVaSetValues(w2, XmNtopOffset, default_dist + (h2 - h1) / 2, NULL); */
#else
    XtVaGetValues(w1, XtNheight, &h1, NULL);
    XtVaGetValues(w2, XtNheight, &h2, NULL);
    XtVaSetValues(w1, XtNvertDistance, default_dist + (h2 - h1) / 2, NULL);
    XtVaSetValues(w2, XtNvertDistance, default_dist + (h2 - h1) / 2, NULL);
#endif /* MOTIF */
}

Here is the caller graph for this function:

void adjust_width ( Widget  a,
Widget  b 
)

Definition at line 146 of file x_util.c.

{
    Dimension w1, w2;
    
    XtVaGetValues(a, XtNwidth, &w1, NULL);
    XtVaGetValues(b, XtNwidth, &w2, NULL);
    
    if (w1 < w2)
       XtVaSetValues(a, XtNwidth, w2, NULL);
    else if (w2 > w1)
       XtVaSetValues(b, XtNwidth, w1, NULL);
}

Here is the caller graph for this function:

Definition at line 416 of file x_util.c.

{
    return atoms[1];
}

Here is the caller graph for this function:

Definition at line 446 of file x_util.c.

{
    return atoms[7];
}

Here is the caller graph for this function:

Definition at line 431 of file x_util.c.

{
    return atoms[4];
}

Here is the caller graph for this function:

Definition at line 436 of file x_util.c.

{
    return atoms[5];
}

Here is the caller graph for this function:

Definition at line 441 of file x_util.c.

{
    return atoms[6];
}

Here is the caller graph for this function:

Definition at line 426 of file x_util.c.

{
    return atoms[3];
}

Here is the caller graph for this function:

Definition at line 451 of file x_util.c.

{
    return atoms[8];
}

Here is the caller graph for this function:

Definition at line 421 of file x_util.c.

{
    return atoms[2];
}

Here is the caller graph for this function:

Definition at line 411 of file x_util.c.

{
    return atoms[0];
}

Here is the caller graph for this function:

void block_event_callback ( Widget  w,
XtPointer  client_data,
XEvent *  ev,
Boolean cont 
)

Definition at line 731 of file x_util.c.

{
    UNUSED(w);
    UNUSED(client_data);
    UNUSED(ev);
    
    /* Don't propagate this event further down... */
    *cont = False;

    return;
}

Here is the caller graph for this function:

void center_window ( Widget  w1,
Widget  w2 
)

Definition at line 27 of file x_util.c.

{
    Position x, y;
    Dimension w1, h1, w2, h2;

    if (!XtIsRealized(wa) || !XtIsRealized(wb))
       return;
    
    XtVaGetValues(wa,
                XtNwidth, &w1,
                XtNheight, &h1,
                NULL);
    XtVaGetValues(wb,
                XtNwidth, &w2,
                XtNheight, &h2,
                XtNx, &x,
                XtNy, &y,
                NULL);
    XtVaSetValues(wa, XtNx, x + (w2 - w1) / 2,
                XtNy, y + (h2 - h1) / 2,
                NULL);
}

Here is the caller graph for this function:

Boolean clip_region ( int x,
int y,
int w,
int h 
)

Definition at line 1170 of file x_util.c.

{
#if 0
    fprintf(stderr, "globals.win_expose.min_x: %d, globals.win_expose.max_x: %d, "
           "globals.win_expose.min_y: %d, globals.win_expose.max_y: %d\n",
           globals.win_expose.min_x, globals.win_expose.max_x,
           globals.win_expose.min_y, globals.win_expose.max_y);
#endif
    /* check for <= so that we also return false if *w or *h == 0 */
    if (*x + *w <= globals.win_expose.min_x
       || *x >= globals.win_expose.max_x
       || *y + *h <= globals.win_expose.min_y
       || *y >= globals.win_expose.max_y
       /* extra protection agains *w or *h == 0; don't know if this can actually happen ... */
       || globals.win_expose.max_y == globals.win_expose.min_y
       || globals.win_expose.max_x == globals.win_expose.min_x) {
       return False;
    }
    if (*x < globals.win_expose.min_x) {
       *w -= globals.win_expose.min_x - *x;
       *x = globals.win_expose.min_x;
    }
    if (*x + *w > globals.win_expose.max_x) {
       *w = globals.win_expose.max_x - *x;
    }
    if (*y < globals.win_expose.min_y) {
       *h -= globals.win_expose.min_y - *y;
       *y = globals.win_expose.min_y;
    }
    if (*y + *h > globals.win_expose.max_y) {
       *h = globals.win_expose.max_y - *y;
    }
    return True;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean clip_region_to_rect ( XRectangle *  rect)

Definition at line 1206 of file x_util.c.

{
    int x = rect->x;
    int y = rect->y;
    int w = rect->width;
    int h = rect->height;
    Boolean ret = clip_region(&x, &y, &w, &h);
    if (ret) {
       rect->x = x;
       rect->y = y;
       rect->width = w;
       rect->height = h;
    }
    return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Widget get_matching_parent ( Widget  w,
Widget  p,
const char *  fmt,
  ... 
)

Definition at line 582 of file x_util.c.

{
    Widget parent = d;
    const char *str = fmt;

    va_list argp;
    va_start(argp, fmt);

    TRACE_GUI((stderr, "get_matching_parent of %p (0x%lx)", (void *)w, XtWindow(w)));
    while (str != NULL) {
       Widget p;
       if ((p = matches_parent(w, str)) != NULL) {
           parent = p;
           break;
       }
       str = va_arg(argp, char *);
    }
       
    va_end(argp);

    return parent;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean get_widget_by_name ( Widget *  ret,
Widget  parent,
const char *  name,
Boolean  report_error 
)

Definition at line 750 of file x_util.c.

{
    char buf[1024];
    Widget test;

/*      if (parent == 0 || !XtIsManaged(parent)) { */
/*     fprintf(stderr, "Widget %p not managed!\n", parent); */
/*     return False; */
/*      } */
    
    if (strlen(name) > 1023) {
       popup_message(globals.widgets.top_level,
                    MSG_ERR,
                    REPORT_XDVI_BUG_TEMPLATE,
                    "Widget name `%s' too long, couldn't get parent", name);
       return False;
    }

    buf[0] = '*'; /* add wildcard to also match paths */
    strcpy(buf + 1, name);

    if ((test = XtNameToWidget(parent, buf)) != NULL) {
       *ret = test;
       return True;
    }
    else {
       if (report_error)
           popup_message(globals.widgets.top_level,
                       MSG_ERR,
                       REPORT_XDVI_BUG_TEMPLATE,
                       "XtNameToWidget failed for `%s', parent `%s'", name, XtName(parent));
       return False;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Window get_window_id ( char *  window_p)

Definition at line 200 of file x_util.c.

{
    Window w;
    
#ifndef WORD64
    w = (*((xuint32 *) window_p));
#else
# if WORDS_BIGENDIAN
    w = ((unsigned long)wp[0] << 24) |
       ((unsigned long)wp[1] << 16) |
       ((unsigned long)wp[2] << 8)  |
       (unsigned long)wp[3];
# else
    w = ((unsigned long)wp[3] << 24) |
       ((unsigned long)wp[2] << 16) |
       ((unsigned long)wp[1] << 8)  |
       (unsigned long)wp[0];
# endif
#endif
    return w;
}

Here is the caller graph for this function:

Window get_xdvi_window_id ( Boolean  same_file,
property_cbT  callback 
)

Definition at line 1075 of file x_util.c.

{
    char *window_list;
    size_t window_list_len;
    char *window_list_end;
    char *wp;
    char *p;
    Boolean need_rewrite = False;
    Window ret_window = 0;

    /*
     * Get window list.  Copy it over (we'll be calling property_get_data()
     * again).
     */
    if ((window_list_len = property_get_window_list(&p)) == 0)
       return 0;

    window_list = xmalloc(window_list_len);
    memcpy(window_list, p, window_list_len);

    XdviOldErrorHandler = XSetErrorHandler(XdviErrorHandler);

    /* Loop over list of windows.  */

    window_list_end = window_list + window_list_len;
    TRACE_CLIENT((stderr, "My property: `%s'", dvi_property));

    for (wp = window_list; wp < window_list_end; wp += 4) {
       Window w;
       char *buf_ret;
       size_t len;

       w = get_window_id(wp);

       TRACE_CLIENT((stderr, "Checking window %08lx", w));
       
       len = property_get_data(w, atom_dvi_file(), &buf_ret,
                            XdviGetWindowProperty);

       if (len == 0) {
           /* not getting back info for a window usually indicates
              that the application the window had belonged to had
              been killed with signal 9
           */
           TRACE_CLIENT((stderr, "Window %08lx: doesn't exist any more, deleting", w));
           window_list_len -= 4;
           window_list_end -= 4;
           memmove(wp, wp + 4, window_list_end - wp);
           wp -= 4; /* new item is now at wp; don't skip it in next iteration */
           need_rewrite = True;
           continue;
       }
       else { /* window still alive */
           if (globals.debug & DBG_CLIENT) {
#if 0
              unsigned long ino;
              int i;
              
              ino = 0;
              for (i = 7; i >= 0; --i)
                  ino = (ino << 8) | (unsigned char)(buf_ret[i]);
#endif
              TRACE_CLIENT((stderr, "Window %08lx: property: `%s'", w, buf_ret));
           }

           /* invoke callback if given */
           if (callback != NULL) {
              callback(w);
           }
           
           if (!same_file && ret_window == 0) {
              ret_window = w;
              if (callback == 0) /* can return early */
                  break;
           }
           else if (strcmp(buf_ret, dvi_property) == 0 && ret_window == 0) { /* match */
              ret_window = w;
              if (callback == 0) /* can return early */
                  break;
           }
       }
    }

    XSetErrorHandler(XdviOldErrorHandler);

    if (need_rewrite)
       XChangeProperty(DISP, DefaultRootWindow(DISP),
                     atom_xdvi_windows(), atom_xdvi_windows(), 32,
                     PropModeReplace, (unsigned char *)window_list,
                     window_list_len / 4);

    return ret_window;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void merge_into_user_db ( XrmDatabase  db)

Definition at line 828 of file x_util.c.

{
    XrmMergeDatabases(db, &m_user_db);
}
void position_window ( Widget  w,
Position  x,
Position  y 
)

Definition at line 52 of file x_util.c.

{
    if (!XtIsRealized(w))
       return;

    TRACE_GUI((stderr, "positioning %ld at %d, %d", (unsigned long)w, x, y));
    XtVaSetValues(w, XtNx, x, XtNy, y, NULL);
}

Here is the caller graph for this function:

size_t property_get_data ( Window  ,
Atom  ,
char **  ,
int(*)(Display *, Window, Atom, long, long, Bool, Atom, Atom *, int *, unsigned long *, unsigned long *, unsigned char **)  x_get_property 
)

Definition at line 223 of file x_util.c.

{
    /* all of these are in 8-bit units */
    unsigned long byte_offset = 0;
    Atom type_ret;
    int format_ret;
    unsigned long nitems_ret;
    unsigned long bytes_after_ret = 0;
    unsigned char *prop_ret = NULL;
    
    /*
     * buffer for collecting returned data; this is static to
     * avoid expensive malloc()s at every call (which is often!)
     */
    static unsigned char *buffer = NULL;
    static size_t buffer_len = 0;

    while (x_get_property(DISP, w,
                       a, byte_offset / 4, (bytes_after_ret + 3) / 4, False,
                       a, &type_ret, &format_ret, &nitems_ret,
                       &bytes_after_ret, &prop_ret)
          == Success) {

       if (type_ret != a || format_ret == 0)
           break;

       nitems_ret *= (format_ret / 8);    /* convert to bytes */

       while ((byte_offset + nitems_ret) >= buffer_len) {
           buffer_len += 256;
           buffer = xrealloc(buffer, buffer_len);
       }

       /* the +1 captures the extra '\0' that Xlib puts after the end.  */
       memcpy(buffer + byte_offset, prop_ret, nitems_ret + 1);
       byte_offset += nitems_ret;

       XFree(prop_ret);
       prop_ret = NULL;

       if (bytes_after_ret == 0)   /* got all data */
           break;
    }

    if (prop_ret != NULL)
       XFree(prop_ret);

    *ret_buf = (char *)buffer;
    return byte_offset;
}

Here is the call graph for this function:

Here is the caller graph for this function:

size_t property_get_window_list ( char **  window_list)

Definition at line 278 of file x_util.c.

{
    size_t len = property_get_data(DefaultRootWindow(DISP),
                               atom_xdvi_windows(), window_list,
                               XGetWindowProperty);
    if (len == 0) {
       TRACE_CLIENT((stderr, "No \"xdvi windows\" property found"));
       return 0;
    }
    
    if (len % 4 != 0) {
       TRACE_CLIENT((stderr, "\"XDVI_WINDOWS\" property had incorrect size; deleting it."));
       XDeleteProperty(DISP, DefaultRootWindow(DISP), atom_xdvi_windows());
       return 0;
    }
    return len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 390 of file x_util.c.

{
    size_t i;
    
#if XlibSpecificationRelease >= 6
    if (!XInternAtoms(DISP, atom_names, XtNumber(atom_names), False, atoms))
       XDVI_FATAL((stderr, "XtInternAtoms failed."));
#else
    for (i = 0; i < XtNumber(atom_names); i++) {
       if ((atoms[i] = XInternAtom(DISP, atom_names[i], False)) == None)
           XDVI_FATAL((stderr, "XtInternAtoms failed."));
    }
#endif

    if (globals.debug & DBG_CLIENT) {
       for (i = 0; i < XtNumber(atom_names); i++)
           TRACE_CLIENT((stderr, "Atom(%s) = %lu", atom_names[i], atoms[i]));
    }
}

Here is the caller graph for this function:

void read_user_preferences ( Widget  toplevel,
const char *  filename 
)

Definition at line 990 of file x_util.c.

{
    char *fullpath;
    XrmDatabase db;
#if XtSpecificationRelease == 4
    XrmDatabase file_db;
#endif

    fullpath = get_xdvirc_path(filename);
    TRACE_GUI((stderr, "Reading resources from `%s'", fullpath));
    db = XtDatabase(XtDisplay(toplevel));
    
#if XtSpecificationRelease == 4
    file_db  = XrmGetFileDatabase(fullpath);
    XrmMergeDatabases(file_db, &db);
    XrmMergeDatabases(file_db, &m_user_db);
#else /* Xt >= X11R5 */
    XrmCombineFileDatabase(fullpath, &db, True);
    XrmCombineFileDatabase(fullpath, &m_user_db, True);
#endif
    free(fullpath);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 894 of file x_util.c.

{
    char testbuf[1024];
    char *xdvirc_name;
    char *tmpname;
    FILE *from_fp, *to_fp;
    int fd;

    if (resource.no_init_file
       || m_user_db == NULL) /* nothing to do */
       return True;
    
    if (resource.remember_windowsize)
       save_geometry();
    
    xdvirc_name = get_xdvirc_path(xdvirc_filename);

    if ((to_fp = fopen(xdvirc_name, "r")) != NULL) {
       TRACE_GUI((stderr, "~/.xdvirc exists, checking file contents ..."));
       if (fgets(testbuf, 1024, to_fp) != NULL &&
           memcmp(testbuf, xdvirc_signature_line, strlen(xdvirc_signature_line)) != 0) {
           popup_message(globals.widgets.top_level,
                       MSG_WARN,
                       "Xdvi uses the file ~/.xdvirc to save the preferences set via "
                       "the menu bar or the preferences dialog (in the Motif version only). "
                       "To avoid overwriting files created by the user, the first line of the "
                       "file is compared with a special signature line. If that signature line "
                       "is not found, the preferences won't be written. Your file doesn't seem "
                       "to contain that signature line. You should move the file to a safe location, "
                       "and then try to quit xdvi again.",
                       /* message */
                       "The file `%s' was apparently not written by xdvi(k). "
                       "Please move or delete this file first, then try to exit xdvi again. ",
                       xdvirc_name);
           return False;
       }
       fclose(to_fp);
    }

    /* don't use xdvi_temp_fd here, since XrmPutFileDatabase()
       closes the FILE*, creating a temp race */
    tmpname = xstrdup(xdvirc_name);
    tmpname = xstrcat(tmpname, ".tmp");

    /* since XrmPutFileDatabase doesn't give a useful error message if it fails,
       check that creating the file works beforehand. The file is created with 0600 permissions. */
    if ((fd = try_open_mode(tmpname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) < 0) {
       XDVI_ERROR((stderr, "Could not save preferences!\nOpening %s for writing failed: %s", tmpname, strerror(errno)));
       return True;
    }
    close(fd);
    
    XrmPutFileDatabase(m_user_db, tmpname);

    if (full_save) {
       if ((from_fp = try_fopen(tmpname, "r")) == NULL) {
           XDVI_ERROR((stderr, "Could not save preferences!\nOpening %s for reading failed: %s", tmpname, strerror(errno)));
           return True;
       }
       
       /* again, create the file with 600 permissions */
       if ((fd = try_open_mode(xdvirc_name, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) {
           XDVI_ERROR((stderr, "Could not save preferences!\nOpening %s for writing failed: %s", xdvirc_name, strerror(errno)));
           return True;
       }
       
       if ((to_fp = fdopen(fd, "w")) == NULL) {
           XDVI_ERROR((stderr, "Could not save preferences!\nfdopen for %s for writing failed: %s", xdvirc_name, strerror(errno)));
           return True;
       }
       
       if (fputs(xdvirc_signature_line, to_fp) == EOF
           || fputs(xdvirc_header, to_fp) == EOF
           || !copy_fp(from_fp, to_fp)) {
           XDVI_ERROR((stderr, "Could not save preferences!\nError writing to %s: %s", xdvirc_name, strerror(errno)));
       }

       fclose(from_fp);
       fclose(to_fp);
    }
    
    free(xdvirc_name);

    if (full_save)
       unlink(tmpname);
    free(tmpname);

    return True;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void scroll_page_if_needed ( int  x_min,
int  x_max,
int  y_min,
int  y_max 
)

Definition at line 66 of file x_util.c.

{
    Position drawing_x, drawing_y, drawing_h, clip_x, clip_y, clip_h, clip_w;
    int test_scroll, need_v_scroll = 0, need_h_scroll = 0;

    if (!do_autoscroll)
       return;
    
    XtVaGetValues(globals.widgets.clip_widget,
                XtNx, &clip_x, XtNy, &clip_y,
                XtNheight, &clip_h, XtNwidth, &clip_w,
                NULL);
    XtVaGetValues(globals.widgets.draw_widget,
                XtNx, &drawing_x, XtNy, &drawing_y,
                XtNheight, &drawing_h,
                NULL);

#if DEBUG_SCROLL_IF_NEEDED
    fprintf(stderr, "y: %d, drawing_y: %d, clip_h: %d\n", y, drawing_y, clip_h);
#endif
    /* check if we need to scroll vertically; first, down for y_min */
    test_scroll = y_min + drawing_y - clip_h;
    if ((resource.expert_mode & XPRT_SHOW_STATUSLINE) != 0)
       test_scroll += global_statusline_h;

    TRACE_SRC((stderr, "test_scroll vertically: %d", test_scroll));
#if DEBUG_SCROLL_IF_NEEDED
    fprintf(stderr, "%d + %d > %d?\n", drawing_y, y_min, clip_h);
#endif
    if (test_scroll > 0) { /* need to scroll down? */
       need_v_scroll = test_scroll;
       TRACE_SRC((stderr, "need_v_scroll down: %d", need_v_scroll));
    }
    else if (abs(drawing_y) + 2 > y_max) { /* need to scroll up? */
       need_v_scroll = -((abs(drawing_y) - y_max) + 1);
       TRACE_SRC((stderr, "need_v_scroll up: %d (%d > %d; %d)", need_v_scroll, abs(drawing_y), y_max, clip_y));
    }

    /* check if we need to scroll horizontally; x_min < 0 blocks this
       (e.g. for hyperref, where we don't want it) */
    if (x_min >= 0) {
       test_scroll = x_min + drawing_x - clip_w + 1;
       TRACE_SRC((stderr, "test_scroll horizontally: %d", test_scroll));
       
       if (test_scroll > 0) {
           /* need to scroll to right (i.e. make stuff on right-hand side visible)? */
           need_h_scroll = test_scroll;
           TRACE_SRC((stderr, "need_h_scroll right: %d", need_h_scroll));
       }
       else if (abs(drawing_x) > x_max) {
           /* need to scroll to left (i.e. make stuff on left-hand side visible)? */
           need_h_scroll =  -(abs(drawing_x) - x_max);
           TRACE_SRC((stderr, "need_h_scroll left: %d", need_h_scroll));
       }
    }

    /* FIXME: should we not scroll if keep_flag is active? */
    if (need_v_scroll != 0 && globals.widgets.y_bar != NULL) {
#ifdef MOTIF
       /* need to add new value to current one */
       XtVaGetValues(globals.widgets.y_bar, XmNvalue, &test_scroll, NULL);
       (void)set_bar_value(globals.widgets.y_bar, test_scroll + need_v_scroll, (int)(globals.page.h - mane.height));
#else
       XtCallCallbacks(globals.widgets.y_bar, XtNscrollProc, (XtPointer)need_v_scroll);
#endif
    }

    if (need_h_scroll != 0 && globals.widgets.x_bar != NULL) {
#ifdef MOTIF
       /* need to add new value to current one */
       XtVaGetValues(globals.widgets.x_bar, XmNvalue, &test_scroll, NULL);
       (void)set_bar_value(globals.widgets.x_bar, test_scroll + need_h_scroll, (int)(globals.page.w - mane.width));
#else
       XtCallCallbacks(globals.widgets.x_bar, XtNscrollProc, (XtPointer)need_h_scroll);
#endif
    }

    do_autoscroll = False;
}

Here is the call graph for this function:

Here is the caller graph for this function:

set_dvi_property sets the appropriate property for the main window (used in source special handoff).

Definition at line 318 of file x_util.c.

{
    XChangeProperty(DISP, XtWindow(globals.widgets.top_level), atom_dvi_file(), atom_dvi_file(),
                  8, PropModeReplace, (unsigned char *)dvi_property, dvi_property_length);
}

Here is the call graph for this function:

Here is the caller graph for this function:

GC set_or_make_gc ( GC  gc,
int  function,
Pixel  fg,
Pixel  bg 
)

Definition at line 161 of file x_util.c.

{
    XGCValues values;
    values.function = function;
    values.foreground = fg;
    values.background = bg;

    /* Since print is in round dots we make drawings as "smooth" as possible. */
    values.cap_style = CapRound;
    values.join_style = JoinRound;

    if (gc != NULL)
       XChangeGC(DISP, gc, GCFunction | GCForeground | GCBackground
                | GCCapStyle | GCJoinStyle, &values);
    else
       gc = XCreateGC(DISP, XtWindow(globals.widgets.top_level), GCFunction | GCForeground | GCBackground
                     | GCCapStyle | GCJoinStyle, &values);

    return gc;
}

Here is the caller graph for this function:

void set_string_property ( const char *  str,
Atom  prop,
Window  win 
)

Definition at line 1061 of file x_util.c.

{
    XChangeProperty(DISP, win, prop, prop, 8, PropModeReplace,
                  (const unsigned char *)str, strlen(str));
    XFlush(DISP);    /* necessary to get the property set */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void set_window_id ( Window  w,
unsigned char *  data 
)

Definition at line 297 of file x_util.c.

{
#if WORDS_BIGENDIAN
    data[0] = (unsigned int)w >> 24;
    data[1] = (unsigned int)w >> 16;
    data[2] = (unsigned int)w >> 8;
    data[3] = (unsigned int)w;
#else
    data[0] = (unsigned int)w;
    data[1] = (unsigned int)w >> 8;
    data[2] = (unsigned int)w >> 16;
    data[3] = (unsigned int)w >> 24;
#endif
}

Here is the caller graph for this function:

void store_preference ( XrmDatabase *  db,
const char *  name,
const char *  fmt,
  ... 
)

Definition at line 803 of file x_util.c.

{
    size_t offset = strlen("xdvi.");
    size_t name_len = strlen(name);
    char *name_buf = xmalloc(name_len + offset + 1);
    char *buf = NULL;
    XrmDatabase tmp_db = NULL;
    
    if (db == NULL)
       db = &m_user_db;

    XDVI_GET_STRING_ARGP(buf, fmt);

    memcpy(name_buf, "xdvi.", offset);
    strcpy(name_buf + offset, name);

    TRACE_GUI((stderr, "storing resource: `%s: %s'", name_buf, buf));
    XrmPutStringResource(&tmp_db, name_buf, buf);
    XrmMergeDatabases(tmp_db, db);
   
    free(buf);
    free(name_buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void store_user_preference ( const char *  name,
const char *  fmt,
  ... 
)
void synthetisize_event ( XEvent *  ev,
Widget  button 
)

Definition at line 461 of file x_util.c.

{
    memset(ev, 0, sizeof(XButtonPressedEvent));
    ev->type = ButtonPress;
    ev->xbutton.serial = 1;
    ev->xbutton.send_event = True;
    ev->xbutton.button = 1;
    ev->xbutton.display = XtDisplayOfObject(button);
    ev->xbutton.window = XtWindowOfObject(button);
}

Here is the caller graph for this function:

void unexpected_widget_in_callback ( Widget  w,
const char *  callback 
)

Definition at line 786 of file x_util.c.

{
    ASSERT(w != NULL, "Widget mustn't be NULL!");
    popup_message(globals.widgets.top_level,
                MSG_ERR,
                REPORT_XDVI_BUG_TEMPLATE,
                "Unexpected widget `%s' in callback `%s'",
                XtName(w), callback);
}

Here is the call graph for this function:

void update_window_property ( Window  w,
Boolean  prepend 
)

Definition at line 330 of file x_util.c.

{
    char *wlist;
    size_t wlist_len;
    char *wlist_end;
    char *wp;
#if 0
    int i;
#endif /* 0 */

    /* this allocates wlist */
    if ((wlist_len = property_get_window_list(&wlist)) == 0)
       return;

    /* Loop over list of windows.  */
    wlist_end = wlist + wlist_len;

#if 0
    for (i = 0, wp = wlist; wp < wlist_end; wp += 4, i++) {
       fprintf(stderr, "WIN %d: %08lx; len: %d\n", i, get_window_id(wp), wlist_len);
    }
#endif /* 0 */
    
    for (wp = wlist; wp < wlist_end; wp += 4) {
       if (get_window_id(wp) == w) { /* match, remove our ID */
           wlist_len -= 4;
           wlist_end -= 4;
           memmove(wp, wp + 4, wlist_end - wp);
           wp -= 4; /* new item is now at wp; don't skip it in next iteration */
       }
    }
    
    if (prepend) { /* add our ID again to front */
#ifdef WORD64
       unsigned char data[4];
       set_window_id(w, data);
#else
       xuint32 data = w;
#endif
       /* Note: no need to realloc wlist, since the original length
          was sufficient for all elements.
       */
       memmove(wlist + 4, wlist, wlist_len);
       wlist_len += 4;
       memcpy(wlist, &data, 4);
    }
           
    if (wlist_len == 0)
       XDeleteProperty(DISP, DefaultRootWindow(DISP),
                     atom_xdvi_windows());
    else
       XChangeProperty(DISP, DefaultRootWindow(DISP),
                     atom_xdvi_windows(), atom_xdvi_windows(), 32,
                     PropModeReplace, (unsigned char *)wlist,
                     wlist_len / 4);
    
    XFlush(DISP);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean widget_is_parent ( Widget  w,
Widget  p,
Widget  s 
)

Definition at line 609 of file x_util.c.

{
    Widget curr = XtParent(w);
    while (curr != NULL && curr != s) {
       fprintf(stderr, "Comparing: %p - %p\n", (void *)curr, (void *)p);
       if (curr == p)
           return True;
       curr = XtParent(curr);
    }
    return False;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 22 of file x_util.c.