Back to index

tetex-bin  3.0
Classes | Functions
sfSelFile.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  filesel_callback

Functions

void SFpositionWidget (Widget w)
FILESFopenFile (const char *name, const char *mode, const char *prompt, const char *failed)
void SFtextChanged (void)
void XsraSelFile (Widget parent, struct filesel_callback *callback)
void raise_file_selector (void)

Function Documentation

Definition at line 146 of file sfSelFile.c.

{
    if (selFile != 0) {
       XRaiseWindow(DISP, XtWindow(selFile));
    }
}

Here is the caller graph for this function:

FILE* SFopenFile ( const char *  name,
const char *  mode,
const char *  prompt,
const char *  failed 
)

Definition at line 825 of file sfSelFile.c.

{
    Arg args[1];
    FILE *fp;

    UNUSED(args);
    UNUSED(prompt);
    UNUSED(failed);
    
    SFchdir(SFstartDir);
    errno = 0;
    if (!name || *name == 0 || (fp = XFOPEN(name, mode)) == NULL) {
       XBell(DISP, 0);
       return NULL;
    }
    return fp;
}

Here is the call graph for this function:

void SFpositionWidget ( Widget  w)

Definition at line 779 of file sfSelFile.c.

{
    Arg args[3];
    Cardinal num_args;
    Dimension width, height, b_width;
    int x, y, max_x, max_y;
    Window root, child;
    int dummyx, dummyy;
    unsigned int dummymask;

    XQueryPointer(XtDisplay(w), XtWindow(w), &root, &child, &x, &y,
                &dummyx, &dummyy, &dummymask);
    num_args = 0;
    XtSetArg(args[num_args], XtNwidth, &width);
    num_args++;
    XtSetArg(args[num_args], XtNheight, &height);
    num_args++;
    XtSetArg(args[num_args], XtNborderWidth, &b_width);
    num_args++;
    XtGetValues(w, args, num_args);

    width += 2 * b_width;
    height += 2 * b_width;

    x -= ((Position) width / 2);
    if (x < 0)
       x = 0;
    if (x > (max_x = (Position) (XtScreen(w)->width - width)))
       x = max_x;

    y -= ((Position) height / 2);
    if (y < 0)
       y = 0;
    if (y > (max_y = (Position) (XtScreen(w)->height - height)))
       y = max_y;

    num_args = 0;
    XtSetArg(args[num_args], XtNx, x);
    num_args++;
    XtSetArg(args[num_args], XtNy, y);
    num_args++;
    XtSetValues(w, args, num_args);
}

Here is the caller graph for this function:

Definition at line 844 of file sfSelFile.c.

{
    if ((SFtextBuffer[0] == '/') || (SFtextBuffer[0] == '~')) {
       (void)strcpy(SFcurrentPath, SFtextBuffer);

       SFtextPos = XawTextGetInsertionPoint(selFileField);
    }
    else {
       (void)strcat(strcpy(SFcurrentPath, SFstartDir), SFtextBuffer);

       SFtextPos = XawTextGetInsertionPoint(selFileField) + strlen(SFstartDir);
    }

    if (!SFworkProcAdded) {
       (void)XtAppAddWorkProc(SFapp, (XtWorkProc)SFworkProc, NULL);
       SFworkProcAdded = 1;
    }

    SFupdatePath();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XsraSelFile ( Widget  parent,
struct filesel_callback callback 
)

Definition at line 882 of file sfSelFile.c.

{
    static Boolean firstTime = True;
    Widget w;
    Cardinal i;
    Arg arglist[20];
    XEvent event;
    
    if (!callback->prompt) {
       callback->prompt = "Pathname:";
    }

    if (!callback->title) {
       callback->title = "Xdvi: select filename";
    }

    if (!callback->ok) {
       callback->ok = "OK";
    }

    if (!callback->cancel) {
       callback->cancel = "Cancel";
    }

    if (firstTime) {
       firstTime = False;
       SFdisplay = XtDisplay(parent);
       w = SFcreateWidgets(parent, callback->title, callback->prompt, callback->ok, callback->cancel);
    }
    else {
       i = 0;
       XtSetArg(arglist[i], XtNlabel, callback->prompt);
       i++;
       XtSetValues(selFilePrompt, arglist, i);

       i = 0;
       XtSetArg(arglist[i], XtNlabel, callback->ok);
       i++;
       XtSetValues(selFileOK, arglist, i);

       i = 0;
       XtSetArg(arglist[i], XtNlabel, callback->cancel);
       i++;
       XtSetValues(selFileCancel, arglist, i);
    }

    SFpositionWidget(selFile);
    XtMapWidget(selFile);

    {
       char *cwd = xgetcwd();
       strcpy(SFstartDir, cwd);
       free(cwd);
    }
    if (SFstartDir[0] == 0) {
       XtAppError(SFapp, "XsraSelFile: can't get current directory");
    }
    (void)strcat(SFstartDir, "/");
    (void)strcpy(SFcurrentDir, SFstartDir);

    if (callback->init_path) {
       if (callback->init_path[0] == '/') {
           (void)strcpy(SFcurrentPath, callback->init_path);
           if (strncmp(SFcurrentPath, SFstartDir, strlen(SFstartDir))) {
              SFsetText(SFcurrentPath);
           }
           else {
              SFsetText(&(SFcurrentPath[strlen(SFstartDir)]));
           }
       }
       else {
           (void)strcat(strcpy(SFcurrentPath, SFstartDir), callback->init_path);
           SFsetText(&(SFcurrentPath[strlen(SFstartDir)]));
       }
    }
    else {
       SFsetText(SFcurrentDir);
       (void)strcpy(SFcurrentPath, SFstartDir);
    }

    SFfunc = showEntry;

    SFtextChanged();

    /* don't grab the pointer so that warning popups still work */
    /* XtAddGrab(selFile, True, True); */

    SFdirModTimerId = XtAppAddTimeOut(SFapp, 1200UL,
                                  SFdirModTimer, (XtPointer) NULL);
    
    if (strcmp(fileMask, callback->filemask) != 0) { /* if mask changed */
       SFDir *dir;
       strncpy(fileMask, callback->filemask, MASKWIDTH);
       XtVaSetValues(selFileMask, XtNstring, fileMask, NULL);
       for (dir = &(SFdirs[SFdirEnd - 1]); dir >= SFdirs; dir--)
           *(dir->dir) = 0; /* force a re-read */
       SFupdatePath();
    }

    while (1) {
       XtAppNextEvent(SFapp, &event);
       switch (event.type) {
           Widget w;
#if 0 /* don't do this, it may send the X server into a busy loop if the File selector
        is positioned over a window that is `on top' by default */
       case Expose:
           if (!raise_message_windows())
              raise_file_selector();
           break;
#endif
       case KeyPress:
       case ButtonPress:
           /* beep if keypress was inside main window */
           w = XtWindowToWidget(DISP, event.xany.window);
           while ((w != NULL) && (w != selFile)) {
              /* exception: message windows */
              if (is_message_window(w))
                  break;
              w = XtParent(w);
           }
           if (w == NULL || w == globals.widgets.top_level) {
              XBell(DISP, 0);
           }
           break;
       }

       XtDispatchEvent(&event);

       switch (SFstatus) {
       case SEL_FILE_TEXT:
           SFstatus = SEL_FILE_NULL;
           SFtextChanged();
           break;
       case SEL_FILE_OK:
           if (callback->must_exist) {
              FILE *tmp_fp = XFOPEN(SFtextBuffer, "r");
              dviErrFlagT errflag = NO_ERROR;
              if (tmp_fp == NULL) {
                  popup_message(selFile,
                              MSG_ERR, NULL, "Could not open %s: %s.\n",
                              SFtextBuffer, strerror(errno));
                  SFstatus = SEL_FILE_NULL;
                  break;
              }
              else if (!process_preamble(tmp_fp, &errflag)
                      || !find_postamble(tmp_fp, &errflag)
                      || !read_postamble(tmp_fp, &errflag, False)) {
                  popup_message(selFile,
                              MSG_ERR, NULL, "Error opening %s:\n%s.",
                              SFtextBuffer, get_dvi_error(errflag));
                  fclose(tmp_fp);
                  SFstatus = SEL_FILE_NULL;
                  break;
              }
              else { /* file is OK */
                  fclose(tmp_fp);
                  SFprepareToReturn();
                  callback->func_ptr(SFtextBuffer, callback->data);
                  return;
/*                return xstrdup(SFtextBuffer); */
              }
           }
           else {
              SFprepareToReturn();
              callback->func_ptr(SFtextBuffer, callback->data);
              return;
/*            return xstrdup(SFtextBuffer); */
           }
       case SEL_FILE_CANCEL:
           SFprepareToReturn();
           if (callback->exit_on_cancel)
              exit(0);
           return;
/*         return NULL; */
       case SEL_FILE_NULL:
           break;
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function: