Back to index

tetex-bin  3.0
Defines | Functions | Variables
sfSelFile.c File Reference
#include "xdvi-config.h"
#include "xdvi.h"
#include "dvi-init.h"
#include "message-window.h"
#include "kpathsea/c-stat.h"
#include <string.h>
#include "sfDir.h"
#include "sfPath.h"
#include "sfDraw.h"
#include "sfSelFile.h"
#include "util.h"
#include <ctype.h>
#include "kpathsea/c-fopen.h"
#include <errno.h>
#include <sys/param.h>
#include <X11/cursorfont.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Composite.h>
#include <X11/Shell.h>
#include <X11/Xaw/Paned.h>
#include <X11/Xaw/Text.h>
#include <X11/Xaw/AsciiText.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Scrollbar.h>
#include <X11/Xaw/Label.h>
#include <X11/Xaw/Cardinals.h>

Go to the source code of this file.

Defines

#define SEL_FILE_CANCEL   -1
#define SEL_FILE_OK   0
#define SEL_FILE_NULL   1
#define SEL_FILE_TEXT   2
#define MAXPATHLEN   1024
#define MASKWIDTH   16

Functions

static char * strerror (int errnum)
void raise_file_selector (void)
static void SFexposeList (Widget w, XtPointer n, XEvent *event, Boolean *cont)
static void SFmodVerifyCallback (Widget w, XtPointer client_data, XEvent *event, Boolean *cont)
static void SFokCallback (Widget w, XtPointer cl, XtPointer cd)
static void SFcancelCallback (Widget w, XtPointer cl, XtPointer cd)
static void SFdismissAction (Widget w, XEvent *event, String *params, Cardinal *num_params)
static int maskFile (const char *mask, char *filename)
static int showEntry (char *entryReal, char **entryShown, struct stat *statBuf)
static void maskChanged (Widget w, XtPointer client_data, XEvent *call_data, Boolean *cont)
static void hideFiles (Widget w, XtPointer client_data, XtPointer call_data)
static Widget SFcreateWidgets (Widget parent, const char *title, const char *prompt, const char *ok, const char *cancel)
void SFpositionWidget (Widget w)
FILESFopenFile (const char *name, const char *mode, const char *prompt, const char *failed)
void SFtextChanged (void)
static void SFprepareToReturn (void)
void XsraSelFile (Widget parent, struct filesel_callback *callback)

Variables

char SFstartDir [MAXPATHLEN]
char SFcurrentPath [MAXPATHLEN]
char SFcurrentDir [MAXPATHLEN]
Widget selFileField
Widget selFileForm
Widget selFileHScroll
Widget selFileHScrolls [3]
Widget selFileLists [3]
Widget selFileVScrolls [3]
DisplaySFdisplay
Pixel SFfore
Pixel SFback
XSegment SFsegs [2]
XSegment SFcompletionSegs [2]
XawTextPosition SFtextPos
int SFupperX
int SFlowerY
int SFupperY
int SFtextX
int SFtextYoffset
int SFentryWidth
int SFentryHeight
int SFlineToTextH = 3
int SFlineToTextV = 3
int SFbesideText = 3
int SFaboveAndBelowText = 2
int SFcharsPerEntry = 15
int SFlistSize = 10
int SFworkProcAdded = 0
XtAppContext SFapp
int SFpathScrollWidth
int SFvScrollHeight
int SFhScrollWidth
char SFtextBuffer [MAXPATHLEN]
XtIntervalId SFdirModTimerId
int(* SFfunc )()
static int SFstatus = SEL_FILE_NULL
static Widget selFile
static Widget selFileCancel
static Widget selFileOK
static Widget selFilePrompt
static Widget selFileLabel
static Widget selFileMask
static Widget selFileHide
static char fileMask [MASKWIDTH+2] = "*.dvi"
static Atom SFwmDeleteWindow
static char * oneLineTextEditTranslations = "Ctrl<Key>M: redraw-display()\n"
static XtCallbackRec SFokSelect []
static XtCallbackRec SFcancelSelect []
static char * wmDeleteWindowTranslation = "<Message>WM_PROTOCOLS: SelFileDismiss()\n"
static XtActionsRec sf_actions []
Boolean hideFlag = False

Define Documentation

#define MASKWIDTH   16

Definition at line 127 of file sfSelFile.c.

#define MAXPATHLEN   1024

Definition at line 95 of file sfSelFile.c.

#define SEL_FILE_CANCEL   -1

Definition at line 56 of file sfSelFile.c.

#define SEL_FILE_NULL   1

Definition at line 58 of file sfSelFile.c.

#define SEL_FILE_OK   0

Definition at line 57 of file sfSelFile.c.

#define SEL_FILE_TEXT   2

Definition at line 59 of file sfSelFile.c.


Function Documentation

static void hideFiles ( Widget  w,
XtPointer  client_data,
XtPointer  call_data 
) [static]

Definition at line 301 of file sfSelFile.c.

{
    SFDir *dir;
    SFEntry *entry;

    UNUSED(client_data);
    UNUSED(call_data);
    
    hideFlag = !hideFlag;
    if (hideFlag) {
       XtVaSetValues(w, XtNlabel, "hidden", NULL);
       for (dir = &(SFdirs[SFdirEnd - 1]); dir >= SFdirs; dir--) {
           if (!(dir->nEntries))
              continue;
           dir->vOrigin = 0;
           for (entry = &(dir->entries[dir->nEntries - 1]);
               entry >= dir->entries; entry--)
              entry->statDone = 0;
           SFdrawLists(SF_DO_SCROLL);
       }
    }
    else {
       XtVaSetValues(w, XtNlabel, "shown", NULL);
       for (dir = &(SFdirs[SFdirEnd - 1]); dir >= SFdirs; dir--)
           *(dir->dir) = 0; /* force a re-read */
       SFupdatePath();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void maskChanged ( Widget  w,
XtPointer  client_data,
XEvent *  call_data,
Boolean cont 
) [static]

Definition at line 284 of file sfSelFile.c.

{
    char buf[2];
    SFDir *dir;

    UNUSED(w);
    UNUSED(client_data);
    UNUSED(cont);
    
    if ((XLookupString((XKeyPressedEvent *)call_data, buf, 2, NULL, NULL) == 1) && ((*buf) == '\r')) {
       for (dir = &(SFdirs[SFdirEnd - 1]); dir >= SFdirs; dir--)
           *(dir->dir) = 0; /* force a re-read */
       SFupdatePath();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int maskFile ( const char *  mask,
char *  filename 
) [static]

Definition at line 237 of file sfSelFile.c.

{
    int c, c1;

    while ((c = *mask++)) {
       if (c == '*') {
           while ((c1 = *mask++)) {
              if (c1 != '*') {
                  if (!(*filename))
                     return 1;
                  if (c1 != '?') {
                     while ((filename = strchr(filename, c1))) {
                         if (!maskFile(mask, ++filename))
                            return 0;
                     }
                     return 1;
                  }
                  else
                     filename++;
              }
           }
           return 0;
       }
       if (c == '?') {
           if (!*filename)
              return 1;
       }
       else if (c != *filename)
           return 1;
       filename++;
    }
    return (*filename) ? 1 : 0;
}

Here is the caller graph for this function:

Definition at line 146 of file sfSelFile.c.

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

Here is the caller graph for this function:

static void SFcancelCallback ( Widget  w,
XtPointer  cl,
XtPointer  cd 
) [static]

Definition at line 200 of file sfSelFile.c.

static Widget SFcreateWidgets ( Widget  parent,
const char *  title,
const char *  prompt,
const char *  ok,
const char *  cancel 
) [static]

Definition at line 332 of file sfSelFile.c.

{
    Cardinal i, n;
    int listWidth, listHeight;
    int listSpacing = 10;
    int scrollThickness = 15;
    int hScrollX, hScrollY;
    int vScrollX, vScrollY;
    Cursor xtermCursor, sbRightArrowCursor, arrowCursor;
    Arg arglist[20];
    Widget paned, box;
    
    i = 0;
    XtSetArg(arglist[i], XtNtransientFor, parent);
    XtSetArg(arglist[i], XtNtitle, title);
    i++;

    selFile = XtAppCreateShell("xdviSelFile", "XdviSelFile",
                            transientShellWidgetClass, SFdisplay,
                            arglist, i);

    /* Add WM_DELETE_WINDOW protocol */
    XtAppAddActions(XtWidgetToApplicationContext(selFile),
                  sf_actions, XtNumber(sf_actions));
    XtOverrideTranslations(selFile,
                        XtParseTranslationTable(wmDeleteWindowTranslation));

    paned = XtVaCreateManagedWidget("paned", panedWidgetClass, selFile, NULL);
    i = 0;
    XtSetArg(arglist[i], XtNdefaultDistance, 6);
    i++;
    selFileForm = XtCreateManagedWidget("selFileForm",
                                   formWidgetClass, paned, arglist, i);

    i = 0;
    XtSetArg(arglist[i], XtNlabel, prompt);
    i++;
    XtSetArg(arglist[i], XtNresizable, True);
    i++;
    XtSetArg(arglist[i], XtNtop, XtChainTop);
    i++;
    XtSetArg(arglist[i], XtNbottom, XtChainTop);
    i++;
    XtSetArg(arglist[i], XtNleft, XtChainLeft);
    i++;
    XtSetArg(arglist[i], XtNright, XtChainLeft);
    i++;
    XtSetArg(arglist[i], XtNborderWidth, 0);
    i++;
    XtSetArg(arglist[i], XtNvertDistance, 20);
    i++;
    selFilePrompt = XtCreateManagedWidget("selFilePrompt",
                                     labelWidgetClass, selFileForm,
                                     arglist, i);

#if 1
    i = 0;
    XtSetArg(arglist[i], XtNforeground, &SFfore);
    i++;
    XtSetArg(arglist[i], XtNbackground, &SFback);
    i++;
    XtGetValues(selFilePrompt, arglist, i);
#endif

    SFinitFont();

    SFentryWidth = SFbesideText + SFcharsPerEntry * SFcharWidth + SFbesideText;
    SFentryHeight = SFaboveAndBelowText + SFcharHeight + SFaboveAndBelowText;

    listWidth = SFlineToTextH + SFentryWidth + SFlineToTextH + 1 +
       scrollThickness;
    listHeight = SFlineToTextV + SFentryHeight + SFlineToTextV + 1 +
       SFlineToTextV + SFlistSize * SFentryHeight +
       SFlineToTextV + 1 + scrollThickness;

    SFpathScrollWidth = 3 * listWidth + 2 * listSpacing + 4;

    hScrollX = -1;
    hScrollY = SFlineToTextV + SFentryHeight + SFlineToTextV + 1 +
       SFlineToTextV + SFlistSize * SFentryHeight + SFlineToTextV;
    SFhScrollWidth = SFlineToTextH + SFentryWidth + SFlineToTextH;

    vScrollX = SFlineToTextH + SFentryWidth + SFlineToTextH;
    vScrollY = SFlineToTextV + SFentryHeight + SFlineToTextV;
    SFvScrollHeight = SFlineToTextV + SFlistSize * SFentryHeight +
       SFlineToTextV;

    SFupperX = SFlineToTextH + SFentryWidth + SFlineToTextH - 1;
    SFlowerY = SFlineToTextV + SFentryHeight + SFlineToTextV + 1 +
       SFlineToTextV;
    SFupperY = SFlineToTextV + SFentryHeight + SFlineToTextV + 1 +
       SFlineToTextV + SFlistSize * SFentryHeight - 1;

    SFtextX = SFlineToTextH + SFbesideText;
    SFtextYoffset = SFlowerY + SFaboveAndBelowText + SFcharAscent;

    SFsegs[0].x1 = 0;
    SFsegs[0].y1 = vScrollY;
    SFsegs[0].x2 = vScrollX - 1;
    SFsegs[0].y2 = vScrollY;
    SFsegs[1].x1 = vScrollX;
    SFsegs[1].y1 = 0;
    SFsegs[1].x2 = vScrollX;
    SFsegs[1].y2 = vScrollY - 1;

    SFcompletionSegs[0].x1 = SFcompletionSegs[0].x2 = SFlineToTextH;
    SFcompletionSegs[1].x1 = SFcompletionSegs[1].x2 =
       SFlineToTextH + SFentryWidth - 1;

    i = 0;
/*     XtSetArg(arglist[i], XtNwidth, 3 * listWidth + 2 * listSpacing + 4 - w - 10); */
    XtSetArg(arglist[i], XtNwidth, 3 * listWidth + 2 * listSpacing + 4);
    i++;
/*      XtSetArg(arglist[i], XtNborderColor, SFfore); */
/*      i++; */

/*     XtSetArg(arglist[i], XtNfromHoriz, selFilePrompt); */
/*     i++; */
/*     XtSetArg(arglist[i], XtNhorizDistance, 10); */
    XtSetArg(arglist[i], XtNfromVert, selFilePrompt);
    i++;
/*      XtSetArg(arglist[i], XtNvertDistance, 0); */
/*      i++; */
    XtSetArg(arglist[i], XtNresizable, True);
    i++;
    XtSetArg(arglist[i], XtNtop, XtChainTop);
    i++;
    XtSetArg(arglist[i], XtNbottom, XtChainTop);
    i++;
    XtSetArg(arglist[i], XtNleft, XtChainLeft);
    i++;
    XtSetArg(arglist[i], XtNright, XtChainLeft);
    i++;
    XtSetArg(arglist[i], XtNstring, SFtextBuffer);
    i++;
    XtSetArg(arglist[i], XtNlength, MAXPATHLEN);
    i++;
    XtSetArg(arglist[i], XtNeditType, XawtextEdit);
    i++;
    XtSetArg(arglist[i], XtNwrap, XawtextWrapWord);
    i++;
    XtSetArg(arglist[i], XtNresize, XawtextResizeHeight);
    i++;
    XtSetArg(arglist[i], XtNuseStringInPlace, True);
    i++;
    XtSetArg(arglist[i], XtNvertDistance, 5);
    i++;
    selFileField = XtCreateManagedWidget("selFileField",
                                      asciiTextWidgetClass, selFileForm,
                                      arglist, i);

    XtOverrideTranslations(selFileField,
                        XtParseTranslationTable
                        (oneLineTextEditTranslations));
/*     XtSetKeyboardFocus(selFileForm, selFileField);
       need focus for selFileMask widget to set the filter */

    i = 0;
    XtSetArg(arglist[i], XtNorientation, XtorientHorizontal);
    i++;
    XtSetArg(arglist[i], XtNwidth, SFpathScrollWidth);
    i++;
    XtSetArg(arglist[i], XtNheight, scrollThickness);
    i++;
/*      XtSetArg(arglist[i], XtNborderColor, SFfore); */
/*      i++; */
    XtSetArg(arglist[i], XtNfromVert, selFileField);
    i++;
    XtSetArg(arglist[i], XtNvertDistance, 30);
    i++;
    XtSetArg(arglist[i], XtNtop, XtChainTop);
    i++;
    XtSetArg(arglist[i], XtNbottom, XtChainTop);
    i++;
    XtSetArg(arglist[i], XtNleft, XtChainLeft);
    i++;
    XtSetArg(arglist[i], XtNright, XtChainLeft);
    i++;
    selFileHScroll = XtCreateManagedWidget("selFileHScroll",
                                      scrollbarWidgetClass, selFileForm,
                                      arglist, i);

    XtAddCallback(selFileHScroll, XtNjumpProc,
                (XtCallbackProc)SFpathSliderMovedCallback, (XtPointer) NULL);
    XtAddCallback(selFileHScroll, XtNscrollProc,
                (XtCallbackProc)SFpathAreaSelectedCallback, (XtPointer) NULL);

    i = 0;
    XtSetArg(arglist[i], XtNwidth, listWidth);
    i++;
    XtSetArg(arglist[i], XtNheight, listHeight);
    i++;
/*      XtSetArg(arglist[i], XtNborderColor, SFfore); */
/*      i++; */
    XtSetArg(arglist[i], XtNfromVert, selFileHScroll);
    i++;
    XtSetArg(arglist[i], XtNvertDistance, 10);
    i++;
    XtSetArg(arglist[i], XtNtop, XtChainTop);
    i++;
    XtSetArg(arglist[i], XtNbottom, XtChainTop);
    i++;
    XtSetArg(arglist[i], XtNleft, XtChainLeft);
    i++;
    XtSetArg(arglist[i], XtNright, XtChainLeft);
    i++;
    selFileLists[0] = XtCreateManagedWidget("selFileList1",
                                       compositeWidgetClass, selFileForm,
                                       arglist, i);

    i = 0;
    XtSetArg(arglist[i], XtNwidth, listWidth);
    i++;
    XtSetArg(arglist[i], XtNheight, listHeight);
    i++;
/*      XtSetArg(arglist[i], XtNborderColor, SFfore); */
/*      i++; */
    XtSetArg(arglist[i], XtNfromHoriz, selFileLists[0]);
    i++;
    XtSetArg(arglist[i], XtNfromVert, selFileHScroll);
    i++;
    XtSetArg(arglist[i], XtNhorizDistance, listSpacing);
    i++;
    XtSetArg(arglist[i], XtNvertDistance, 10);
    i++;
    XtSetArg(arglist[i], XtNtop, XtChainTop);
    i++;
    XtSetArg(arglist[i], XtNbottom, XtChainTop);
    i++;
    XtSetArg(arglist[i], XtNleft, XtChainLeft);
    i++;
    XtSetArg(arglist[i], XtNright, XtChainLeft);
    i++;
    selFileLists[1] = XtCreateManagedWidget("selFileList2",
                                       compositeWidgetClass, selFileForm,
                                       arglist, i);

    i = 0;
    XtSetArg(arglist[i], XtNwidth, listWidth);
    i++;
    XtSetArg(arglist[i], XtNheight, listHeight);
    i++;
/*      XtSetArg(arglist[i], XtNborderColor, SFfore); */
/*      i++; */
    XtSetArg(arglist[i], XtNfromHoriz, selFileLists[1]);
    i++;
    XtSetArg(arglist[i], XtNfromVert, selFileHScroll);
    i++;
    XtSetArg(arglist[i], XtNhorizDistance, listSpacing);
    i++;
    XtSetArg(arglist[i], XtNvertDistance, 10);
    i++;
    XtSetArg(arglist[i], XtNtop, XtChainTop);
    i++;
    XtSetArg(arglist[i], XtNbottom, XtChainTop);
    i++;
    XtSetArg(arglist[i], XtNleft, XtChainLeft);
    i++;
    XtSetArg(arglist[i], XtNright, XtChainLeft);
    i++;
    selFileLists[2] = XtCreateManagedWidget("selFileList3",
                                       compositeWidgetClass, selFileForm,
                                       arglist, i);

    for (n = 0; n < 3; n++) {

       i = 0;
       XtSetArg(arglist[i], XtNx, vScrollX);
       i++;
       XtSetArg(arglist[i], XtNy, vScrollY);
       i++;
       XtSetArg(arglist[i], XtNwidth, scrollThickness);
       i++;
       XtSetArg(arglist[i], XtNheight, SFvScrollHeight);
       i++;
/*     XtSetArg(arglist[i], XtNborderColor, SFfore); */
/*     i++; */
       selFileVScrolls[n] = XtCreateManagedWidget("selFileVScroll",
                                             scrollbarWidgetClass,
                                             selFileLists[n], arglist, i);

       XtAddCallback(selFileVScrolls[n], XtNjumpProc,
                    (XtCallbackProc)SFvFloatSliderMovedCallback, (XtPointer) n);
       XtAddCallback(selFileVScrolls[n], XtNscrollProc,
                    (XtCallbackProc)SFvAreaSelectedCallback, (XtPointer) n);

       i = 0;

       XtSetArg(arglist[i], XtNorientation, XtorientHorizontal);
       i++;
       XtSetArg(arglist[i], XtNx, hScrollX);
       i++;
       XtSetArg(arglist[i], XtNy, hScrollY);
       i++;
       XtSetArg(arglist[i], XtNwidth, SFhScrollWidth);
       i++;
       XtSetArg(arglist[i], XtNheight, scrollThickness);
       i++;
/*     XtSetArg(arglist[i], XtNborderColor, SFfore); */
/*     i++; */
       selFileHScrolls[n] = XtCreateManagedWidget("selFileHScroll",
                                             scrollbarWidgetClass,
                                             selFileLists[n], arglist, i);

       XtAddCallback(selFileHScrolls[n], XtNjumpProc,
                    (XtCallbackProc)SFhSliderMovedCallback, (XtPointer) n);
       XtAddCallback(selFileHScrolls[n], XtNscrollProc,
                    (XtCallbackProc)SFhAreaSelectedCallback, (XtPointer) n);
    }

    /* Do the file filter stuff.  */
    selFileLabel = XtVaCreateManagedWidget("selFileLabel",
                                      labelWidgetClass, selFileForm,
                                      XtNfromVert, selFileLists[0],
                                      XtNvertDistance, 30,
/*                                    XtNfromHoriz, selFileCancel, */
/*                                    XtNhorizDistance, 60, */
                                      XtNlabel, "File Mask:",
                                      XtNborderWidth, 0,
                                      XtNtop, XtChainTop,
                                      XtNbottom, XtChainTop, NULL);

    selFileMask = XtVaCreateManagedWidget("selFileMask",
                                     asciiTextWidgetClass, selFileForm,
                                     XtNwidth, MASKWIDTH / 2 * SFcharWidth,
                                     XtNfromVert, selFileLists[0],
                                     XtNvertDistance, 30,
                                     XtNfromHoriz, selFileLabel,
                                     XtNhorizDistance, 0,
                                     XtNtop, XtChainTop,
                                     XtNbottom, XtChainTop,
                                     XtNstring, fileMask,
                                     XtNlength, MASKWIDTH,
                                     XtNeditType, XawtextEdit,
                                     XtNwrap, XawtextWrapNever,
                                     XtNuseStringInPlace, True, NULL);

    for (i = 0; i < 3; i++)
       XtSetKeyboardFocus(selFileLists[i], selFileField);

    XtOverrideTranslations(selFileMask,
                        XtParseTranslationTable
                        (oneLineTextEditTranslations));

    XtAddEventHandler(selFileMask, KeyPressMask, False,
                    (XtEventHandler)maskChanged, (XtPointer) NULL);

    selFileLabel = XtVaCreateManagedWidget("selFileLabel",
                                      labelWidgetClass, selFileForm,
                                      XtNfromVert, selFileLists[0],
                                      XtNvertDistance, 30,
                                      XtNfromHoriz, selFileMask,
                                      XtNhorizDistance, 40,
                                      XtNlabel, "Dot files are:",
                                      XtNborderWidth, 0,
                                      XtNtop, XtChainTop,
                                      XtNbottom, XtChainTop, NULL);

    selFileHide = XtVaCreateManagedWidget("selFileHide",
                                     commandWidgetClass, selFileForm,
/*                                   XtNwidth, 7 * SFcharWidth, */
                                     XtNfromVert, selFileLists[0],
                                     XtNvertDistance, 30,
                                     XtNfromHoriz, selFileLabel,
                                     XtNhorizDistance, 2,
                                     XtNlabel, hideFlag ? "hidden" : "shown",
/*                                   XtNborderWidth, 1, */
                                     XtNtop, XtChainTop,
/*                                   XtNjustify, XtJustifyLeft, */
                                     XtNbottom, XtChainTop,
                                     NULL);
    XtAddCallback(selFileHide, XtNcallback, (XtCallbackProc)hideFiles, NULL);

    box = XtVaCreateManagedWidget("box", formWidgetClass,
                              paned,
                              XtNshowGrip, False,
                              XtNdefaultDistance, 6,
                              XtNskipAdjust, True,
                              XtNaccelerators, G_accels_cr,
                              NULL);
    selFileOK = XtVaCreateManagedWidget("selFileOK", commandWidgetClass,
                                  box,
                                  XtNlabel, ok,
                                  XtNcallback, SFokSelect,
                                  XtNtop, XtChainTop,
                                  XtNbottom, XtChainBottom,
                                  XtNleft, XtChainLeft,
                                  XtNright, XtChainLeft,
                                  NULL);
    selFileCancel = XtVaCreateManagedWidget("selFileCancel", commandWidgetClass,
                                       box,
                                       XtNlabel, cancel,
                                       XtNcallback, SFcancelSelect,
/*                                     XtNborderColor, SFfore, */
                                       XtNfromHoriz, selFileOK,
                                       XtNbottom, XtChainBottom,
                                       XtNleft, XtChainRight,
                                       XtNright, XtChainRight,
                                       NULL);

    XtSetMappedWhenManaged(selFile, False);
    XtRealizeWidget(selFile);

    /* Add WM_DELETE_WINDOW protocol */
    SFwmDeleteWindow = XInternAtom(SFdisplay, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(SFdisplay, XtWindow(selFile), &SFwmDeleteWindow, 1);

    SFcreateGC();

    xtermCursor = XCreateFontCursor(SFdisplay, XC_xterm);

    sbRightArrowCursor = XCreateFontCursor(SFdisplay, XC_sb_right_arrow);
    arrowCursor = XCreateFontCursor(SFdisplay, XC_left_ptr);

    XDefineCursor(SFdisplay, XtWindow(selFileForm), arrowCursor);
    XDefineCursor(SFdisplay, XtWindow(selFileField), xtermCursor);

    for (n = 0; n < 3; n++) {
       XDefineCursor(SFdisplay, XtWindow(selFileLists[n]), sbRightArrowCursor);
    }
    XDefineCursor(SFdisplay, XtWindow(selFileOK), arrowCursor);
    XDefineCursor(SFdisplay, XtWindow(selFileCancel), arrowCursor);

    for (n = 0; n < 3; n++) {
       XtAddEventHandler(selFileLists[n], ExposureMask, True,
                       (XtEventHandler)SFexposeList, (XtPointer) n);
       XtAddEventHandler(selFileLists[n], EnterWindowMask, False,
                       (XtEventHandler)SFenterList, (XtPointer) n);
       XtAddEventHandler(selFileLists[n], LeaveWindowMask, False,
                       (XtEventHandler)SFleaveList, (XtPointer) n);
       XtAddEventHandler(selFileLists[n], PointerMotionMask, False,
                       (XtEventHandler)SFmotionList, (XtPointer) n);
       XtAddEventHandler(selFileLists[n], ButtonPressMask, False,
                       (XtEventHandler)SFbuttonPressList, (XtPointer) n);
       XtAddEventHandler(selFileLists[n], ButtonReleaseMask, False,
                       (XtEventHandler)SFbuttonReleaseList, (XtPointer) n);
    }

    XtAddEventHandler(selFileField, KeyPressMask, False,
                    (XtEventHandler)SFmodVerifyCallback, (XtPointer) NULL);

    SFapp = XtWidgetToApplicationContext(selFile);
    return selFile;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void SFdismissAction ( Widget  w,
XEvent *  event,
String params,
Cardinal *  num_params 
) [static]

Definition at line 215 of file sfSelFile.c.

{
    UNUSED(w);
    UNUSED(params);
    UNUSED(num_params);
    
    if (event->type == ClientMessage && (unsigned)(event->xclient.data.l[0]) != SFwmDeleteWindow)
       return;

    SFstatus = SEL_FILE_CANCEL;
}
static void SFexposeList ( Widget  w,
XtPointer  n,
XEvent *  event,
Boolean cont 
) [static]

Definition at line 154 of file sfSelFile.c.

{
    UNUSED(w);
    UNUSED(cont);
    
    if ((event->type == NoExpose) || event->xexpose.count) {
       return;
    }

    SFdrawList((int)n, SF_DO_NOT_SCROLL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void SFmodVerifyCallback ( Widget  w,
XtPointer  client_data,
XEvent *  event,
Boolean cont 
) [static]

Definition at line 167 of file sfSelFile.c.

{
    char buf[2];

    UNUSED(w);
    UNUSED(client_data);
    UNUSED(cont);
    
    if ((XLookupString(&(event->xkey), buf, 2, NULL, NULL) == 1) &&
       ((*buf) == '\r')) {
       SFstatus = SEL_FILE_OK;
    }
    else {
       SFstatus = SEL_FILE_TEXT;
    }
}

Here is the caller graph for this function:

static void SFokCallback ( Widget  w,
XtPointer  cl,
XtPointer  cd 
) [static]

Definition at line 185 of file sfSelFile.c.

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:

static void SFprepareToReturn ( void  ) [static]

Definition at line 866 of file sfSelFile.c.

{
    SFstatus = SEL_FILE_NULL;
    /* XtRemoveGrab(selFile); */
    XtUnmapWidget(selFile);

    if (SFdirModTimerId) {
       XtRemoveTimeOut(SFdirModTimerId);
       SFdirModTimerId = 0;
    }
    if (SFchdir(SFstartDir)) {
       XtAppError(SFapp, "XsraSelFile: can't return to current directory");
    }
}

Here is the call graph for this function:

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:

static int showEntry ( char *  entryReal,
char **  entryShown,
struct stat statBuf 
) [static]

Definition at line 273 of file sfSelFile.c.

{
    UNUSED(entryShown);

    if ((hideFlag && entryReal[0] == '.') || (!S_ISDIR(statBuf->st_mode) && maskFile(fileMask, entryReal)))
       return 0;
    entryReal[strlen(entryReal)] = SFstatChar(statBuf);
    return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* strerror ( int  errnum) [static]

Definition at line 138 of file sfSelFile.c.

{
    return 0 < errnum && errnum <= sys_nerr
       ? sys_errlist[errnum] : "Unknown system error";
}
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:


Variable Documentation

char fileMask[MASKWIDTH+2] = "*.dvi" [static]

Definition at line 128 of file sfSelFile.c.

Definition at line 271 of file sfSelFile.c.

char* oneLineTextEditTranslations = "Ctrl<Key>M: redraw-display()\n" [static]

Definition at line 132 of file sfSelFile.c.

Widget selFile [static]

Definition at line 123 of file sfSelFile.c.

Widget selFileCancel [static]

Definition at line 123 of file sfSelFile.c.

Widget selFileField

Definition at line 100 of file sfSelFile.c.

Widget selFileForm

Definition at line 100 of file sfSelFile.c.

Widget selFileHide [static]

Definition at line 125 of file sfSelFile.c.

Definition at line 100 of file sfSelFile.c.

Widget selFileHScrolls[3]

Definition at line 100 of file sfSelFile.c.

Widget selFileLabel [static]

Definition at line 125 of file sfSelFile.c.

Widget selFileLists[3]

Definition at line 100 of file sfSelFile.c.

Widget selFileMask [static]

Definition at line 125 of file sfSelFile.c.

Widget selFileOK [static]

Definition at line 123 of file sfSelFile.c.

Widget selFilePrompt [static]

Definition at line 123 of file sfSelFile.c.

Widget selFileVScrolls[3]

Definition at line 100 of file sfSelFile.c.

XtActionsRec sf_actions[] [static]
Initial value:
 {
    {"SelFileDismiss", SFdismissAction},
}

Definition at line 229 of file sfSelFile.c.

Definition at line 111 of file sfSelFile.c.

XtAppContext SFapp

Definition at line 115 of file sfSelFile.c.

Pixel SFback

Definition at line 102 of file sfSelFile.c.

Definition at line 110 of file sfSelFile.c.

XtCallbackRec SFcancelSelect[] [static]
Initial value:
 {
    {SFcancelCallback, (XtPointer) NULL},
    {NULL, (XtPointer) NULL},
}

Definition at line 209 of file sfSelFile.c.

Definition at line 112 of file sfSelFile.c.

XSegment SFcompletionSegs[2]

Definition at line 103 of file sfSelFile.c.

Definition at line 99 of file sfSelFile.c.

Definition at line 99 of file sfSelFile.c.

XtIntervalId SFdirModTimerId

Definition at line 118 of file sfSelFile.c.

Definition at line 101 of file sfSelFile.c.

Definition at line 107 of file sfSelFile.c.

Definition at line 107 of file sfSelFile.c.

Pixel SFfore

Definition at line 102 of file sfSelFile.c.

int(* SFfunc)()

Definition at line 119 of file sfSelFile.c.

Definition at line 116 of file sfSelFile.c.

Definition at line 108 of file sfSelFile.c.

Definition at line 109 of file sfSelFile.c.

Definition at line 113 of file sfSelFile.c.

Definition at line 105 of file sfSelFile.c.

XtCallbackRec SFokSelect[] [static]
Initial value:
 {
    {SFokCallback, (XtPointer) NULL},
    {NULL, (XtPointer) NULL},
}

Definition at line 194 of file sfSelFile.c.

Definition at line 116 of file sfSelFile.c.

XSegment SFsegs[2]

Definition at line 103 of file sfSelFile.c.

Definition at line 99 of file sfSelFile.c.

Definition at line 121 of file sfSelFile.c.

Definition at line 117 of file sfSelFile.c.

XawTextPosition SFtextPos

Definition at line 104 of file sfSelFile.c.

Definition at line 106 of file sfSelFile.c.

Definition at line 106 of file sfSelFile.c.

Definition at line 105 of file sfSelFile.c.

Definition at line 105 of file sfSelFile.c.

Definition at line 116 of file sfSelFile.c.

Definition at line 130 of file sfSelFile.c.

Definition at line 114 of file sfSelFile.c.

char* wmDeleteWindowTranslation = "<Message>WM_PROTOCOLS: SelFileDismiss()\n" [static]

Definition at line 227 of file sfSelFile.c.