xgamelist.c xgamelist.h\
history.c xhistory.c xhistory.h \
xoptions.c dialogs.c dialogs.h \
- filebrowser/selfile.c filebrowser/selfile.h \
- filebrowser/draw.c filebrowser/path.c \
- filebrowser/dir.c filebrowser/xstat.h \
$(ZPY)
SUBDIRS = po
xboard_LDADD = -lm @XAW_LIBS@ @X_LIBS@ @LIBINTL@
return;
}
+//----------------------------------- File Browser -------------------------------
+
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#else
+#include <sys/dir.h>
+#define dirent direct
+#endif
+
+#include <sys/stat.h>
+
+static ChessProgramState *savCps;
+static FILE **savFP;
+static char *fileName, *extFilter, *dirListing, *savMode, **namePtr;
+static int folderPtr, filePtr, oldVal, byExtension, extFlag;
+static char curDir[MSG_SIZ], title[MSG_SIZ], *folderList[1000], *fileList[1000];
+
+static char *FileTypes[] = {
+"Chess Games",
+"Chess Positions",
+"Tournaments",
+"Opening Books",
+"Settings (*.ini)",
+"Log files",
+"All files",
+NULL,
+"PGN",
+"Old-Style Games",
+"FEN",
+"Old-Style Positions",
+NULL,
+NULL
+};
+
+static char *Extensions[] = {
+".pgn .game",
+".fen .epd .pos",
+".trn",
+".bin",
+".ini",
+".log",
+"",
+"INVALID",
+".pgn",
+".game",
+".fen",
+".pos",
+NULL,
+""
+};
+
+void DirSelProc P((int n, int sel));
+void FileSelProc P((int n, int sel));
+void SetTypeFilter P((int n));
+int BrowseOK P((int n));
+void Switch P((int n));
+
+Option browseOptions[] = {
+{ 0, LR|T2T, 500, NULL, NULL, NULL, NULL, Label, title },
+{ 0, L2L|T2T, 250, NULL, NULL, NULL, NULL, Label, N_("Directories:") },
+{ 0,R2R|T2T|SAME_ROW,100, NULL, NULL, NULL, NULL, Label, N_("Files:") },
+{ 0,R2R|T2T|SAME_ROW, 70, NULL, (void*) &Switch, NULL, NULL, Button, N_("by name") },
+{ 0,R2R|T2T|SAME_ROW, 70, NULL, (void*) &Switch, NULL, NULL, Button, N_("by type") },
+{ 300, L2L|T2T, 250, NULL, (void*) folderList, (char*) &DirSelProc, NULL, ListBox, "" },
+{ 300,R2R|T2T|SAME_ROW,250, NULL, (void*) fileList, (char*) &FileSelProc, NULL, ListBox, "" },
+{ 0, 0, 350, NULL, (void*) &fileName, NULL, NULL, TextBox, N_("Filename:") },
+{ 0, COMBO_CALLBACK, 150, NULL, (void*) &SetTypeFilter, NULL, FileTypes, ComboBox, N_("File type:") },
+{ 0, SAME_ROW, 0, NULL, (void*) &BrowseOK, "", NULL, EndMark , "" }
+};
+
+int
+BrowseOK (int n)
+{
+ if(!fileName[0]) { // it is enough to have a file selected
+ if(browseOptions[6].textValue) { // kludge: if callback specified we browse for file
+ int sel = SelectedListBoxItem(&browseOptions[6]);
+ if(sel < 0 || sel >= filePtr) return FALSE;
+ ASSIGN(fileName, fileList[sel]);
+ } else { // we browse for path
+ ASSIGN(fileName, curDir); // kludge: without callback we browse for path
+ }
+ }
+ if(!fileName[0]) return FALSE; // refuse OK when no file
+ if(!savMode[0]) { // browsing for name only (dialog Browse button)
+ snprintf(title, MSG_SIZ, "%s/%s", curDir, fileName);
+ SetWidgetText((Option*) savFP, title, TransientDlg);
+ currentCps = savCps; // could return to Engine Settings dialog!
+ return TRUE;
+ }
+ *savFP = fopen(fileName, savMode);
+ if(*savFP == NULL) return FALSE; // refuse OK if file not openable
+ ASSIGN(*namePtr, fileName);
+ ScheduleDelayedEvent(DelayedLoad, 50);
+ currentCps = savCps; // not sure this is ever non-null
+ return TRUE;
+}
+
+void
+FileSelProc (int n, int sel)
+{
+ if(sel<0) return;
+ ASSIGN(fileName, fileList[sel]);
+ if(BrowseOK(0)) PopDown(BrowserDlg);
+}
+
+int
+AlphaNumCompare (char *p, char *q)
+{
+ while(*p) {
+ if(isdigit(*p) && isdigit(*q) && atoi(p) != atoi(q))
+ return (atoi(p) > atoi(q) ? 1 : -1);
+ if(*p != *q) break;
+ p++, q++;
+ }
+ if(*p == *q) return 0;
+ return (*p > *q ? 1 : -1);
+}
+
+int
+Comp (const void *s, const void *t)
+{
+ char *p = *(char**) s, *q = *(char**) t;
+ if(extFlag) {
+ char *h; int r;
+ while(h = strchr(p, '.')) p = h+1;
+ if(p == *(char**) s) p = "";
+ while(h = strchr(q, '.')) q = h+1;
+ if(q == *(char**) t) q = "";
+ r = AlphaNumCompare(p, q);
+ if(r) return r;
+ }
+ return AlphaNumCompare( *(char**) s, *(char**) t );
+}
+
+void
+ListDir (int pathFlag)
+{
+ DIR *dir;
+ struct dirent *dp;
+ struct stat statBuf;
+ static int lastFlag;
+ char buf[MSG_SIZ];
+
+ if(pathFlag < 0) pathFlag = lastFlag;
+ lastFlag = pathFlag;
+ dir = opendir(".");
+ getcwd(curDir, MSG_SIZ);
+ snprintf(title, MSG_SIZ, "%s %s", _("Contents of"), curDir);
+ folderPtr = filePtr = 0; // clear listing
+
+ while (dp = readdir(dir)) { // pass 1: list foders
+ char *s = dp->d_name, match;
+ if(!stat(s, &statBuf) && S_ISDIR(statBuf.st_mode)) { // stat succeeds and tells us it is directory
+ if(s[0] == '.' && strcmp(s, "..")) continue; // suppress hidden, except ".."
+ ASSIGN(folderList[folderPtr], s); folderPtr++;
+ } else if(!pathFlag) {
+ char *s = dp->d_name, match=0;
+ if(s[0] == '.') continue; // suppress hidden files
+ if(extFilter[0]) { // [HGM] filter on extension
+ char *p = extFilter, *q;
+ do {
+ if(q = strchr(p, ' ')) *q = 0;
+ if(strstr(s, p)) match++;
+ if(q) *q = ' ';
+ } while(q && (p = q+1));
+ if(!match) continue;
+ }
+ ASSIGN(fileList[filePtr], s); filePtr++;
+ }
+ }
+ FREE(folderList[folderPtr]); folderList[folderPtr] = NULL;
+ FREE(fileList[filePtr]); fileList[filePtr] = NULL;
+ closedir(dir);
+ extFlag = 0; qsort((void*)folderList, folderPtr, sizeof(char*), &Comp);
+ extFlag = byExtension; qsort((void*)fileList, filePtr, sizeof(char*), &Comp);
+}
+
+void
+Refresh (int pathFlag)
+{
+ ListDir(pathFlag); // and make new one
+ LoadListBox(&browseOptions[5], "");
+ LoadListBox(&browseOptions[6], "");
+}
+
+void
+Switch (int n)
+{
+ if(byExtension == (n == 4)) return;
+ extFlag = byExtension = (n == 4);
+ qsort((void*)fileList, filePtr, sizeof(char*), &Comp);
+ LoadListBox(&browseOptions[6], "");
+}
+
+void
+SetTypeFilter (int n)
+{
+ int j = values[n];
+ if(j == browseOptions[n].value) return; // no change
+ browseOptions[n].value = j;
+ SetWidgetLabel(&browseOptions[n], FileTypes[j]);
+ ASSIGN(extFilter, Extensions[j]);
+ Refresh(-1); // uses pathflag remembered by ListDir
+ values[n] = oldVal; // do not disturb combo settings of underlying dialog
+}
+
+void
+DirSelProc (int n, int sel)
+{
+ if(!chdir(folderList[sel])) { // cd succeeded, so we are in new directory now
+ Refresh(-1);
+ SetWidgetLabel(&browseOptions[0], title);
+ }
+}
+
+FILE *
+Browse (DialogClass dlg, char *label, char *proposed, char *ext, Boolean pathFlag, char *mode, char **name, FILE **fp)
+{
+ int j=0;
+ savFP = fp; savMode = mode, namePtr = name, savCps = currentCps, oldVal = values[8]; // save params, for use in callback
+ ASSIGN(extFilter, ext);
+ ASSIGN(fileName, proposed ? proposed : "");
+ for(j=0; Extensions[j]; j++) // look up actual value in list of possible values, to get selection nr
+ if(extFilter && !strcmp(extFilter, Extensions[j])) break;
+ if(Extensions[j] == NULL) { j++; ASSIGN(FileTypes[j], extFilter); }
+ browseOptions[8].value = j;
+ browseOptions[6].textValue = (char*) (pathFlag ? NULL : &FileSelProc); // disable file listbox during path browsing
+ ListDir(pathFlag);
+ currentCps = NULL;
+ if(GenericPopUp(browseOptions, label, BrowserDlg, dlg, MODAL, 0)) {
+ }
+ SetWidgetLabel(&browseOptions[8], FileTypes[j]);
+}
+
typedef enum { // identifier of dialogs done by GenericPopup
TransientDlg=0, // transient: grabs mouse events and is destroyed at pop-down (so other dialog can use this ID next time)
-CommentDlg, TagsDlg, TextMenuDlg, InputBoxDlg, NoDlg, BrowserDlg, HistoryDlg, // persistent: no grab and reused
+CommentDlg, TagsDlg, TextMenuDlg, InputBoxDlg, NoDlg, DummyDlg, HistoryDlg, // persistent: no grab and reused
GameListDlg,
EngOutDlg,
EvalGraphDlg,
AskDlg, // this and beyond do grab mouse events (and are destroyed)
FatalDlg,
BoardWindow,
+BrowserDlg,
NrOfDialogs // dummy for total
} DialogClass;
typedef Option *PointerCallback(int n, int x, int y);
+typedef void ListBoxCallback(int n, int selected);
typedef void ButtonCallback(int n);
typedef int OKCallback(int n);
void SetScroll P((Option *opt, float f));
void AddHandler P((Option *opt, int nr));
void SendText P((int n));
+FILE *Browse P((DialogClass dlg, char *label, char *proposed, char *ext,
+ Boolean pathFlag, char *mode, char **name, FILE **fp));
void InitDrawingParams P(()); // in xboard.c
void ErrorPopUp P((char *title, char *text, int modal));
int ShiftKeys P((void));
void SetClockIcon P((int color));
+void DelayedLoad P((void));
void DisplayTimerLabel P((int optNr, char *color, long timer, int highlight));
Option *BoardPopUp P((int squareSize, int lineGap, void *clockFontThingy));
+++ /dev/null
-This is not part of the GNU XBoard program, but is used with GNU XBoard.
-
-For copyright information of this code, see the header of each file.
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Software Research Associates not be used
- * in advertising or publicity pertaining to distribution of the software
- * without specific, written prior permission. Software Research Associates
- * makes no representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
- * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Erik M. van der Poel
- * Software Research Associates, Inc., Tokyo, Japan
- * erik@sra.co.jp
- */
-
-#include <stdio.h>
-#include <stdlib.h> /* for qsort */
-#include "config.h" /* to check for dirent.h */
-
-#ifdef SEL_FILE_IGNORE_CASE
-#include <ctype.h>
-#endif /* def SEL_FILE_IGNORE_CASE */
-
-#ifdef HAVE_DIRENT_H
-#include <dirent.h>
-#else
-#include <sys/dir.h>
-#define dirent direct
-#endif
-
-#include <sys/stat.h>
-
-#include "selfile.h"
-
-#ifdef SEL_FILE_IGNORE_CASE
-int
-SFcompareEntries(p, q)
- SFEntry *p;
- SFEntry *q;
-{
- register char *r, *s;
- register char c1, c2;
-
- r = p->real;
- s = q->real;
-
- c1 = *r++;
- if (islower(c1)) {
- c1 = toupper(c1);
- }
- c2 = *s++;
- if (islower(c2)) {
- c2 = toupper(c2);
- }
-
- while (c1 == c2) {
- if (!c1) {
- return strcmp(p->real, q->real);
- }
- c1 = *r++;
- if (islower(c1)) {
- c1 = toupper(c1);
- }
- c2 = *s++;
- if (islower(c2)) {
- c2 = toupper(c2);
- }
- }
-
- return c1 - c2;
-}
-#else /* def SEL_FILE_IGNORE_CASE */
-int
-SFcompareEntries(p, q)
- SFEntry *p;
- SFEntry *q;
-{
- return strcmp(p->real, q->real);
-}
-#endif /* def SEL_FILE_IGNORE_CASE */
-
-int
-SFgetDir(dir)
- SFDir *dir;
-{
- SFEntry *result = NULL;
- int alloc = 0;
- int i;
- DIR *dirp;
- struct dirent *dp;
- char *str;
- int len;
- int maxChars;
- struct stat statBuf;
-
- maxChars = strlen(dir->dir) - 1;
-
- dir->entries = NULL;
- dir->nEntries = 0;
- dir->nChars = 0;
-
- result = NULL;
- i = 0;
-
- dirp = opendir(".");
- if (!dirp) {
- return 1;
- }
-
- (void) stat(".", &statBuf);
- dir->mtime = statBuf.st_mtime;
-
- while (dp = readdir(dirp)) {
-
- struct stat statBuf;
- if(!strcmp(dp->d_name, ".")) continue; /* Throw away "." */
- if(!strcmp(dp->d_name, "..")) continue; /* Throw away ".." */
-#ifndef S_IFLNK
-#endif /* ndef S_IFLNK */
- if (i >= alloc) {
- alloc = 2 * (alloc + 1);
- result = (SFEntry *) XtRealloc((char *) result,
- (unsigned) (alloc * sizeof(SFEntry)));
- }
- result[i].statDone = 0;
- str = dp->d_name;
- len = strlen(str);
- result[i].real = XtMalloc((unsigned) (len + 2));
- (void) strcat(strcpy(result[i].real, str), " ");
- if (len > maxChars) {
- maxChars = len;
- }
- result[i].shown = result[i].real;
- if(SFpathFlag) { // [HGM] only show directories
- if (stat(str, &statBuf) || SFstatChar(&statBuf) != '/') continue;
- } else if(SFfilterBuffer[0]) { // [HGM] filter on extension
- char *p = SFfilterBuffer, match, *q;
- match = !(stat(str, &statBuf) || SFstatChar(&statBuf) != '/');
- do {
- if(q = strchr(p, ' ')) *q = 0;
- if(strstr(str, p)) match++;
- if(q) *q = ' ';
- } while(q && (p = q+1));
- if(!match) continue;
- }
- i++;
- }
-
- qsort((char *) result, (size_t) i, sizeof(SFEntry), SFcompareEntries);
-
- dir->entries = result;
- dir->nEntries = i;
- dir->nChars = maxChars + 1;
-
- closedir(dirp);
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Software Research Associates not be used
- * in advertising or publicity pertaining to distribution of the software
- * without specific, written prior permission. Software Research Associates
- * makes no representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
- * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Erik M. van der Poel
- * Software Research Associates, Inc., Tokyo, Japan
- * erik@sra.co.jp
- */
-
-#include <stdio.h>
-#include "xstat.h"
-#include "selfile.h"
-#include "config.h"
-#include <X11/StringDefs.h>
-#include <X11/Xaw/Scrollbar.h>
-#include <X11/Xaw/Cardinals.h>
-
-#define SF_DEFAULT_FONT "9x15"
-
-#ifdef ABS
-#undef ABS
-#endif
-#define ABS(x) (((x) < 0) ? (-(x)) : (x))
-
-typedef struct {
- char *fontname;
-} TextData, *textPtr;
-
-int SFcharWidth, SFcharAscent, SFcharHeight;
-
-int SFcurrentInvert[3] = { -1, -1, -1 };
-
-static GC SFlineGC, SFscrollGC, SFinvertGC, SFtextGC;
-
-static XtResource textResources[] = {
- {XtNfont, XtCFont, XtRString, sizeof (char *),
- XtOffset(textPtr, fontname), XtRString, SF_DEFAULT_FONT},
-};
-
-#if ENABLE_NLS
-extern XFontSet fontSet; //XXX should really be in a .h file
-#else
-static XFontStruct *SFfont;
-#endif
-
-static int SFcurrentListY;
-
-static XtIntervalId SFscrollTimerId;
-
-void
-SFinitFont()
-{
-#if ENABLE_NLS
- XFontSetExtents *fse = XExtentsOfFontSet(fontSet);
- SFcharWidth = fse->max_logical_extent.width;
- SFcharAscent = -fse->max_logical_extent.y;
- SFcharHeight = fse->max_logical_extent.height;
-#else
- TextData *data;
-
- data = XtNew(TextData);
-
- XtGetApplicationResources(selFileForm, (XtPointer) data, textResources,
- XtNumber(textResources), (Arg *) NULL, ZERO);
-
- SFfont = XLoadQueryFont(SFdisplay, data->fontname);
- if (!SFfont) {
- SFfont = XLoadQueryFont(SFdisplay, SF_DEFAULT_FONT);
- if (!SFfont) {
- char sbuf[256];
-
- (void) sprintf(sbuf, "XsraSelFile: can't get font %s",
- SF_DEFAULT_FONT);
-
- XtAppError(SFapp, sbuf);
- }
- }
-
- SFcharWidth = (SFfont->max_bounds.width + SFfont->min_bounds.width) / 2;
- SFcharAscent = SFfont->max_bounds.ascent;
- SFcharHeight = SFcharAscent + SFfont->max_bounds.descent;
-#endif
- return;
-}
-
-void
-SFcreateGC()
-{
- XGCValues gcValues;
- XRectangle rectangles[1];
-
- gcValues.foreground = SFfore;
-
- SFlineGC = XtGetGC(
- selFileLists[0],
- (XtGCMask)
- GCForeground |
- 0,
- &gcValues
- );
-
- SFscrollGC = XtGetGC(
- selFileLists[0],
- (XtGCMask)
- 0,
- &gcValues
- );
-
- gcValues.function = GXinvert;
- gcValues.plane_mask = (SFfore ^ SFback);
-
- SFinvertGC = XtGetGC(
- selFileLists[0],
- (XtGCMask)
- GCFunction |
- GCPlaneMask |
- 0,
- &gcValues
- );
-
- gcValues.foreground = SFfore;
- gcValues.background = SFback;
-#if !ENABLE_NLS
- gcValues.font = SFfont->fid;
-#endif
-
- SFtextGC = XCreateGC(
- SFdisplay,
- XtWindow(selFileLists[0]),
- (unsigned long)
- GCForeground |
- GCBackground |
-#if !ENABLE_NLS
- GCFont |
-#endif
- 0,
- &gcValues
- );
-
- rectangles[0].x = SFlineToTextH + SFbesideText;
- rectangles[0].y = 0;
- rectangles[0].width = SFcharsPerEntry * SFcharWidth;
- rectangles[0].height = SFupperY + 1;
-
- XSetClipRectangles(
- SFdisplay,
- SFtextGC,
- 0,
- 0,
- rectangles,
- 1,
- Unsorted
- );
- return;
-}
-
-void
-SFclearList(n, doScroll)
- int n;
- int doScroll;
-{
- SFDir *dir;
-
- SFcurrentInvert[n] = -1;
-
- XClearWindow(SFdisplay, XtWindow(selFileLists[n]));
-
- XDrawSegments(SFdisplay, XtWindow(selFileLists[n]), SFlineGC, SFsegs,
- 2);
-
- if (doScroll) {
- dir = &(SFdirs[SFdirPtr + n]);
-
- if ((SFdirPtr + n < SFdirEnd) && dir->nEntries && dir->nChars) {
- XawScrollbarSetThumb(
- selFileVScrolls[n],
- (float) (((double) dir->vOrigin) /
- dir->nEntries),
- (float) (((double) ((dir->nEntries < SFlistSize)
- ? dir->nEntries : SFlistSize)) /
- dir->nEntries)
- );
-
- XawScrollbarSetThumb(
- selFileHScrolls[n],
- (float) (((double) dir->hOrigin) / dir->nChars),
- (float) (((double) ((dir->nChars <
- SFcharsPerEntry) ? dir->nChars :
- SFcharsPerEntry)) / dir->nChars)
- );
- } else {
- XawScrollbarSetThumb(selFileVScrolls[n], (float) 0.0,
- (float) 1.0);
- XawScrollbarSetThumb(selFileHScrolls[n], (float) 0.0,
- (float) 1.0);
- }
- }
- return;
-}
-
-static void
-SFdeleteEntry(dir, entry)
- SFDir *dir;
- SFEntry *entry;
-{
- register SFEntry *e;
- register SFEntry *end;
- int n;
- int idx;
-
- idx = entry - dir->entries;
-
- if (idx < dir->beginSelection) {
- dir->beginSelection--;
- }
- if (idx <= dir->endSelection) {
- dir->endSelection--;
- }
- if (dir->beginSelection > dir->endSelection) {
- dir->beginSelection = dir->endSelection = -1;
- }
-
- if (idx < dir->vOrigin) {
- dir->vOrigin--;
- }
-
- XtFree(entry->real);
-
- end = &(dir->entries[dir->nEntries - 1]);
-
- for (e = entry; e < end; e++) {
- *e = *(e + 1);
- }
-
- if (!(--dir->nEntries)) {
- return;
- }
-
- n = dir - &(SFdirs[SFdirPtr]);
- if ((n < 0) || (n > 2)) {
- return;
- }
-
- XawScrollbarSetThumb(
- selFileVScrolls[n],
- (float) (((double) dir->vOrigin) / dir->nEntries),
- (float) (((double) ((dir->nEntries < SFlistSize) ?
- dir->nEntries : SFlistSize)) / dir->nEntries)
- );
- return;
-}
-
-static void
-SFwriteStatChar(name, last, statBuf)
- char *name;
- int last;
- struct stat *statBuf;
-{
- name[last] = SFstatChar(statBuf);
- return;
-}
-
-static int
-SFstatAndCheck(dir, entry)
- SFDir *dir;
- SFEntry *entry;
-{
- struct stat statBuf;
- char save;
- int last;
-
- /*
- * must be restored before returning
- */
- save = *(dir->path);
- *(dir->path) = 0;
-
- if (!SFchdir(SFcurrentPath)) {
- last = strlen(entry->real) - 1;
- entry->real[last] = 0;
- entry->statDone = 1;
- if (
- (!stat(entry->real, &statBuf))
-
-#ifdef S_IFLNK
-
- || (!lstat(entry->real, &statBuf))
-
-#endif /* ndef S_IFLNK */
-
- ) {
- if (SFfunc) {
- char *shown;
-
- shown = NULL;
- if (SFfunc(entry->real, &shown, &statBuf)) {
- if (shown) {
- int len;
-
- len = strlen(shown);
- entry->shown = XtMalloc(
- (unsigned) (len + 2)
- );
- (void) strcpy(entry->shown,
- shown);
- SFwriteStatChar(
- entry->shown,
- len,
- &statBuf
- );
- entry->shown[len + 1] = 0;
- }
- } else {
- SFdeleteEntry(dir, entry);
-
- *(dir->path) = save;
- return 1;
- }
- }
- SFwriteStatChar(entry->real, last, &statBuf);
- } else {
- entry->real[last] = ' ';
- }
- }
-
- *(dir->path) = save;
- return 0;
-}
-
-static void
-SFdrawStrings(w, dir, from, to)
- register Window w;
- register SFDir *dir;
- register int from;
- register int to;
-{
- register int i;
- register SFEntry *entry;
- int x;
-
- x = SFtextX - dir->hOrigin * SFcharWidth;
-
- if (dir->vOrigin + to >= dir->nEntries) {
- to = dir->nEntries - dir->vOrigin - 1;
- }
- for (i = from; i <= to; i++) {
- entry = &(dir->entries[dir->vOrigin + i]);
- if (!(entry->statDone)) {
- if (SFstatAndCheck(dir, entry)) {
- if (dir->vOrigin + to >= dir->nEntries) {
- to = dir->nEntries - dir->vOrigin - 1;
- }
- i--;
- continue;
- }
- }
-#if ENABLE_NLS
- XmbDrawImageString(
- SFdisplay,
- w,
- fontSet,
- SFtextGC,
- x,
- SFtextYoffset + i * SFentryHeight,
- entry->shown,
- strlen(entry->shown)
- );
-#else
- XDrawImageString(
- SFdisplay,
- w,
- SFtextGC,
- x,
- SFtextYoffset + i * SFentryHeight,
- entry->shown,
- strlen(entry->shown)
- );
-#endif
- if (dir->vOrigin + i == dir->beginSelection) {
- XDrawLine(
- SFdisplay,
- w,
- SFlineGC,
- SFlineToTextH + 1,
- SFlowerY + i * SFentryHeight,
- SFlineToTextH + SFentryWidth - 2,
- SFlowerY + i * SFentryHeight
- );
- }
- if (
- (dir->vOrigin + i >= dir->beginSelection) &&
- (dir->vOrigin + i <= dir->endSelection)
- ) {
- SFcompletionSegs[0].y1 = SFcompletionSegs[1].y1 =
- SFlowerY + i * SFentryHeight;
- SFcompletionSegs[0].y2 = SFcompletionSegs[1].y2 =
- SFlowerY + (i + 1) * SFentryHeight - 1;
- XDrawSegments(
- SFdisplay,
- w,
- SFlineGC,
- SFcompletionSegs,
- 2
- );
- }
- if (dir->vOrigin + i == dir->endSelection) {
- XDrawLine(
- SFdisplay,
- w,
- SFlineGC,
- SFlineToTextH + 1,
- SFlowerY + (i + 1) * SFentryHeight - 1,
- SFlineToTextH + SFentryWidth - 2,
- SFlowerY + (i + 1) * SFentryHeight - 1
- );
- }
- }
- return;
-}
-
-void
-SFdrawList(n, doScroll)
- int n;
- int doScroll;
-{
- SFDir *dir;
- Window w;
-
- SFclearList(n, doScroll);
-
- if (SFdirPtr + (3-NR) + n < SFdirEnd) {
- dir = &(SFdirs[SFdirPtr + n + (3-NR)]);
- w = XtWindow(selFileLists[n]);
-#if ENABLE_NLS
- XmbDrawImageString(
- SFdisplay,
- w,
- fontSet,
- SFtextGC,
- SFtextX - dir->hOrigin * SFcharWidth,
- SFlineToTextV + SFaboveAndBelowText + SFcharAscent,
- dir->dir,
- strlen(dir->dir)
- );
-#else
- XDrawImageString(
- SFdisplay,
- w,
- SFtextGC,
- SFtextX - dir->hOrigin * SFcharWidth,
- SFlineToTextV + SFaboveAndBelowText + SFcharAscent,
- dir->dir,
- strlen(dir->dir)
- );
-#endif
- SFdrawStrings(w, dir, 0, SFlistSize - 1);
- }
- return;
-}
-
-void
-SFdrawLists(doScroll)
- int doScroll;
-{
- int i;
-
- for (i = 0; i < NR; i++) {
- SFdrawList(i, doScroll);
- }
- return;
-}
-
-static void
-SFinvertEntry(n)
- register int n;
-{
- XFillRectangle(
- SFdisplay,
- XtWindow(selFileLists[n]),
- SFinvertGC,
- SFlineToTextH,
- SFcurrentInvert[n] * SFentryHeight + SFlowerY,
- SFentryWidth,
- SFentryHeight
- );
- return;
-}
-
-static unsigned long
-SFscrollTimerInterval()
-{
- static int maxVal = 200;
- static int varyDist = 50;
- static int minDist = 50;
- int t;
- int dist;
-
- if (SFcurrentListY < SFlowerY) {
- dist = SFlowerY - SFcurrentListY;
- } else if (SFcurrentListY > SFupperY) {
- dist = SFcurrentListY - SFupperY;
- } else {
- return (unsigned long) 1;
- }
-
- t = maxVal - ((maxVal / varyDist) * (dist - minDist));
-
- if (t < 1) {
- t = 1;
- }
-
- if (t > maxVal) {
- t = maxVal;
- }
-
- return (unsigned long) t;
-}
-
-static void
-SFscrollTimer(p, id)
- XtPointer p;
- XtIntervalId *id;
-{
- SFDir *dir;
- int save;
- int n;
-
- n = (int)(intptr_t) p;
-
- dir = &(SFdirs[SFdirPtr + n]);
- save = dir->vOrigin;
-
- if (SFcurrentListY < SFlowerY) {
- if (dir->vOrigin > 0) {
- SFvSliderMovedCallback(selFileVScrolls[n], n,
- dir->vOrigin - 1);
- }
- } else if (SFcurrentListY > SFupperY) {
- if (dir->vOrigin < dir->nEntries - SFlistSize) {
- SFvSliderMovedCallback(selFileVScrolls[n], n,
- dir->vOrigin + 1);
- }
- }
-
- if (dir->vOrigin != save) {
- if (dir->nEntries) {
- XawScrollbarSetThumb(
- selFileVScrolls[n],
- (float) (((double) dir->vOrigin) / dir->nEntries),
- (float) (((double) ((dir->nEntries < SFlistSize) ?
- dir->nEntries : SFlistSize)) / dir->nEntries)
- );
- }
- }
-
- if (SFbuttonPressed) {
- SFscrollTimerId = XtAppAddTimeOut(SFapp,
- SFscrollTimerInterval(), SFscrollTimer, (XtPointer)(intptr_t) n);
- }
-}
-
-static int
-SFnewInvertEntry(n, event)
- register int n;
- register XMotionEvent *event;
-{
- register int x, y;
- register int new;
- static int SFscrollTimerAdded = 0;
-
- x = event->x;
- y = event->y;
-
- if (SFdirPtr + n >= SFdirEnd) {
- return -1;
- } else if (
- (x >= 0) && (x <= SFupperX) &&
- (y >= SFlowerY) && (y <= SFupperY)
- ) {
- register SFDir *dir = &(SFdirs[SFdirPtr + n]);
-
- if (SFscrollTimerAdded) {
- SFscrollTimerAdded = 0;
- XtRemoveTimeOut(SFscrollTimerId);
- }
-
- new = (y - SFlowerY) / SFentryHeight;
- if (dir->vOrigin + new >= dir->nEntries) {
- return -1;
- }
- return new;
- } else {
- if (SFbuttonPressed) {
- SFcurrentListY = y;
- if (!SFscrollTimerAdded) {
- SFscrollTimerAdded = 1;
- SFscrollTimerId = XtAppAddTimeOut(SFapp,
- SFscrollTimerInterval(), SFscrollTimer,
- (XtPointer)(intptr_t) n);
- }
- }
-
- return -1;
- }
-}
-
-/* ARGSUSED */
-void
-SFenterList(w, n, event)
- Widget w;
- register int n;
- register XEnterWindowEvent *event;
-{
- register int new;
-
- /* sanity */
- if (SFcurrentInvert[n] != -1) {
- SFinvertEntry(n);
- SFcurrentInvert[n] = -1;
- }
-
- new = SFnewInvertEntry(n, (XMotionEvent *) event);
- if (new != -1) {
- SFcurrentInvert[n] = new;
- SFinvertEntry(n);
- }
-}
-
-/* ARGSUSED */
-void
-SFleaveList(w, n, event)
- Widget w;
- register int n;
- XEvent *event;
-{
- if (SFcurrentInvert[n] != -1) {
- SFinvertEntry(n);
- SFcurrentInvert[n] = -1;
- }
-}
-
-/* ARGSUSED */
-void
-SFmotionList(w, n, event)
- Widget w;
- register int n;
- register XMotionEvent *event;
-{
- register int new;
-
- new = SFnewInvertEntry(n, event);
-
- if (new != SFcurrentInvert[n]) {
- if (SFcurrentInvert[n] != -1) {
- SFinvertEntry(n);
- }
- SFcurrentInvert[n] = new;
- if (new != -1) {
- SFinvertEntry(n);
- }
- }
- return;
-}
-
-/* ARGSUSED */
-void
-SFvSliderMovedCallback(w, n, new)
- Widget w;
- int n;
- int new;
-{
- int old;
- register Window win;
- SFDir *dir;
-
- dir = &(SFdirs[SFdirPtr + n]);
-
-
- old = dir->vOrigin;
- if(new == -1) new = old + 1; else if(new == -2) new = old - 1; // [HGM] indicates scroll direction on mousewheel event
- if(new < 0 || new > dir->nEntries - SFlistSize) return;
- dir->vOrigin = new;
-
- if (old == new) {
- return;
- }
-
- win = XtWindow(selFileLists[n]);
-
- if (ABS(new - old) < SFlistSize) {
- if (new > old) {
- XCopyArea(
- SFdisplay,
- win,
- win,
- SFscrollGC,
- SFlineToTextH,
- SFlowerY + (new - old) * SFentryHeight,
- SFentryWidth + SFlineToTextH,
- (SFlistSize - (new - old)) * SFentryHeight,
- SFlineToTextH,
- SFlowerY
- );
- XClearArea(
- SFdisplay,
- win,
- SFlineToTextH,
- SFlowerY + (SFlistSize - (new - old)) *
- SFentryHeight,
- SFentryWidth + SFlineToTextH,
- (new - old) * SFentryHeight,
- False
- );
- SFdrawStrings(win, dir, SFlistSize - (new - old),
- SFlistSize - 1);
- } else {
- XCopyArea(
- SFdisplay,
- win,
- win,
- SFscrollGC,
- SFlineToTextH,
- SFlowerY,
- SFentryWidth + SFlineToTextH,
- (SFlistSize - (old - new)) * SFentryHeight,
- SFlineToTextH,
- SFlowerY + (old - new) * SFentryHeight
- );
- XClearArea(
- SFdisplay,
- win,
- SFlineToTextH,
- SFlowerY,
- SFentryWidth + SFlineToTextH,
- (old - new) * SFentryHeight,
- False
- );
- SFdrawStrings(win, dir, 0, old - new);
- }
- } else {
- XClearArea(
- SFdisplay,
- win,
- SFlineToTextH,
- SFlowerY,
- SFentryWidth + SFlineToTextH,
- SFlistSize * SFentryHeight,
- False
- );
- SFdrawStrings(win, dir, 0, SFlistSize - 1);
- }
-}
-
-/* ARGSUSED */
-void
-SFvFloatSliderMovedCallback(w, n, fnew)
- Widget w;
- int n;
- float *fnew;
-{
- int new;
-
- new = (*fnew) * SFdirs[SFdirPtr + n].nEntries;
-
- SFvSliderMovedCallback(w, n, new);
-}
-
-
-/* ARGSUSED */
-void
-SFvAreaSelectedCallback(w, n, pnew)
- Widget w;
- int n;
- int pnew;
-{
- SFDir *dir;
- int new;
-
- dir = &(SFdirs[SFdirPtr + n]);
-
- new = dir->vOrigin +
- (((double) pnew) / SFvScrollHeight) * dir->nEntries;
-
- if (new > dir->nEntries - SFlistSize) {
- new = dir->nEntries - SFlistSize;
- }
-
- if (new < 0) {
- new = 0;
- }
-
- if (dir->nEntries) {
- float f;
-
- f = ((double) new) / dir->nEntries;
-
- XawScrollbarSetThumb(
- w,
- f,
- (float) (((double) ((dir->nEntries < SFlistSize) ?
- dir->nEntries : SFlistSize)) / dir->nEntries)
- );
- }
-
- SFvSliderMovedCallback(w, n, new);
-}
-
-/* ARGSUSED */
-void
-SFhSliderMovedCallback(w, n, new)
- Widget w;
- int n;
- float *new;
-{
- SFDir *dir;
- int save;
-
- dir = &(SFdirs[SFdirPtr + n]);
- save = dir->hOrigin;
- dir->hOrigin = (*new) * dir->nChars;
- if (dir->hOrigin == save) {
- return;
- }
-
- SFdrawList(n, SF_DO_NOT_SCROLL);
-}
-
-/* ARGSUSED */
-void
-SFhAreaSelectedCallback(w, n, pnew)
- Widget w;
- int n;
- int pnew;
-{
- SFDir *dir;
- int new;
-
- dir = &(SFdirs[SFdirPtr + n]);
-
- new = dir->hOrigin +
- (((double) pnew) / SFhScrollWidth) * dir->nChars;
-
- if (new > dir->nChars - SFcharsPerEntry) {
- new = dir->nChars - SFcharsPerEntry;
- }
-
- if (new < 0) {
- new = 0;
- }
-
- if (dir->nChars) {
- float f;
-
- f = ((double) new) / dir->nChars;
-
- XawScrollbarSetThumb(
- w,
- f,
- (float) (((double) ((dir->nChars < SFcharsPerEntry) ?
- dir->nChars : SFcharsPerEntry)) / dir->nChars)
- );
-
- SFhSliderMovedCallback(w, n, &f);
- }
-}
-
-/* ARGSUSED */
-void
-SFpathSliderMovedCallback(w, client_data, new)
- Widget w;
- XtPointer client_data;
- float *new;
-{
- SFDir *dir;
- int n;
- XawTextPosition pos;
- int SFdirPtrSave;
-
- SFdirPtrSave = SFdirPtr;
- SFdirPtr = (*new) * SFdirEnd;
- if (SFdirPtr == SFdirPtrSave) {
- return;
- }
-
- SFdrawLists(SF_DO_SCROLL);
-
- n = 2;
- while (SFdirPtr + n >= SFdirEnd) {
- n--;
- }
-
- dir = &(SFdirs[SFdirPtr + n]);
-
- pos = dir->path - SFcurrentPath;
-
- if (!strncmp(SFcurrentPath, SFstartDir, strlen(SFstartDir))) {
- pos -= strlen(SFstartDir);
- if (pos < 0) {
- pos = 0;
- }
- }
-
- XawTextSetInsertionPoint(selFileField, pos);
-}
-
-/* ARGSUSED */
-
-void
-SFpathAreaSelectedCallback(w, client_data, pnew)
- Widget w;
- XtPointer client_data;
- int pnew;
-{
- int new;
- float f;
-
- new = SFdirPtr + (((double) pnew) / SFpathScrollWidth) * SFdirEnd;
-
- if (new > SFdirEnd - 3) {
- new = SFdirEnd - 3;
- }
-
- if (new < 0) {
- new = 0;
- }
-
- f = ((double) new) / SFdirEnd;
-
- XawScrollbarSetThumb(
- w,
- f,
- (float) (((double) ((SFdirEnd < 3) ? SFdirEnd : 3)) /
- SFdirEnd)
- );
-
- SFpathSliderMovedCallback(w, (XtPointer) NULL, &f);
-}
-
-Boolean
-SFworkProc()
-{
- register SFDir *dir;
- register SFEntry *entry;
-
- for (dir = &(SFdirs[SFdirEnd - 1]); dir >= SFdirs; dir--) {
- if (!(dir->nEntries)) {
- continue;
- }
- for (
- entry = &(dir->entries[dir->nEntries - 1]);
- entry >= dir->entries;
- entry--
- ) {
- if (!(entry->statDone)) {
- (void) SFstatAndCheck(dir, entry);
- return False;
- }
- }
- }
-
- SFworkProcAdded = 0;
-
- return True;
-}
+++ /dev/null
-/*
- * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Software Research Associates not be used
- * in advertising or publicity pertaining to distribution of the software
- * without specific, written prior permission. Software Research Associates
- * makes no representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
- * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Erik M. van der Poel
- * Software Research Associates, Inc., Tokyo, Japan
- * erik@sra.co.jp
- */
-
-#include <stdio.h>
-#include <stdlib.h> /* for qsort */
-#include "config.h"
-
-#ifdef SEL_FILE_IGNORE_CASE
-#include <ctype.h>
-#endif /* def SEL_FILE_IGNORE_CASE */
-
-#include <X11/Xos.h>
-#include <pwd.h>
-#include "xstat.h"
-#include "selfile.h"
-#include <X11/Xaw/Scrollbar.h>
-
-#ifndef MAXPATHLEN
-#define MAXPATHLEN 1024
-#endif /* ndef MAXPATHLEN */
-
-#ifdef HAS_DIRENT_H
-extern uid_t getuid();
-#endif /* def HAS_DIRENT_H */
-
-typedef struct {
- char *name;
- char *dir;
-} SFLogin;
-
-SFDir *SFdirs = NULL;
-
-int SFdirEnd;
-
-int SFdirPtr;
-
-int SFbuttonPressed = 0;
-
-static int SFdoNotTouchDirPtr = 0;
-
-static int SFdoNotTouchVorigin = 0;
-
-static SFDir SFrootDir, SFhomeDir;
-
-static SFLogin *SFlogins;
-
-static int SFtwiddle = 0;
-
-void SFsetText(char *path);
-
-int
-SFchdir(path)
- char *path;
-{
- int result;
-
- result = 0;
-
- if (strcmp(path, SFcurrentDir)) {
- result = chdir(path);
- if (!result) {
- (void) strncpy(SFcurrentDir, path, MAXPATHLEN);
- }
- }
-
- return result;
-}
-
-static void
-SFfree(i)
- int i;
-{
- register SFDir *dir;
- register int j;
-
- dir = &(SFdirs[i]);
-
- for (j = dir->nEntries - 1; j >= 0; j--) {
- if (dir->entries[j].shown != dir->entries[j].real) {
- XtFree(dir->entries[j].shown);
- }
- XtFree(dir->entries[j].real);
- }
-
- XtFree((char *) dir->entries);
-
- XtFree(dir->dir);
-
- dir->dir = NULL;
- return;
-}
-
-static void
-SFstrdup(s1, s2)
- char **s1;
- char *s2;
-{
- *s1 = strcpy(XtMalloc((unsigned) (strlen(s2) + 1)), s2);
- return;
-}
-
-static void
-SFunreadableDir(dir)
- SFDir *dir;
-{
- char *cannotOpen = "<cannot open> ";
-
- dir->entries = (SFEntry *) XtMalloc(sizeof(SFEntry));
- dir->entries[0].statDone = 1;
- SFstrdup(&dir->entries[0].real, cannotOpen);
- dir->entries[0].shown = dir->entries[0].real;
- dir->nEntries = 1;
- dir->nChars = strlen(cannotOpen);
- return;
-}
-
-#ifdef SEL_FILE_IGNORE_CASE
-static
-SFstrncmp(p, q, n)
- register char *p, *q;
- register int n;
-{
- register char c1, c2;
- char *psave, *qsave;
- int nsave;
-
- psave = p;
- qsave = q;
- nsave = n;
-
- c1 = *p++;
- if (islower(c1)) {
- c1 = toupper(c1);
- }
- c2 = *q++;
- if (islower(c2)) {
- c2 = toupper(c2);
- }
-
- while ((--n >= 0) && (c1 == c2)) {
- if (!c1) {
- return strncmp(psave, qsave, nsave);
- }
- c1 = *p++;
- if (islower(c1)) {
- c1 = toupper(c1);
- }
- c2 = *q++;
- if (islower(c2)) {
- c2 = toupper(c2);
- }
- }
-
- if (n < 0) {
- return strncmp(psave, qsave, nsave);
- }
-
- return c1 - c2;
-}
-#endif /* def SEL_FILE_IGNORE_CASE */
-
-static void
-SFreplaceText(dir, str)
- SFDir *dir;
- char *str;
-{
- int len;
-
- *(dir->path) = 0;
- len = strlen(str);
- if (str[len - 1] == '/') {
- (void) strcat(SFcurrentPath, str);
- } else {
- (void) strncat(SFcurrentPath, str, len - 1);
- }
- if (strncmp(SFcurrentPath, SFstartDir, strlen(SFstartDir))) {
- SFsetText(SFcurrentPath);
- } else {
- SFsetText(&(SFcurrentPath[strlen(SFstartDir)]));
- }
-
- SFtextChanged();
- return;
-}
-
-static void
-SFexpand(str)
- char *str;
-{
- int len;
- int cmp;
- char *name, *growing;
- SFDir *dir;
- SFEntry *entry, *max;
-
- len = strlen(str);
-
- dir = &(SFdirs[SFdirEnd - 1]);
-
- if (dir->beginSelection == -1) {
- SFstrdup(&str, str);
- SFreplaceText(dir, str);
- XtFree(str);
- return;
- } else if (dir->beginSelection == dir->endSelection) {
- SFreplaceText(dir, dir->entries[dir->beginSelection].shown);
- return;
- }
-
- max = &(dir->entries[dir->endSelection + 1]);
-
- name = dir->entries[dir->beginSelection].shown;
- SFstrdup(&growing, name);
-
- cmp = 0;
- while (!cmp) {
- entry = &(dir->entries[dir->beginSelection]);
- while (entry < max) {
- if (cmp = strncmp(growing, entry->shown, len)) {
- break;
- }
- entry++;
- }
- len++;
- }
-
- /*
- * SFreplaceText() expects filename
- */
- growing[len - 2] = ' ';
-
- growing[len - 1] = 0;
- SFreplaceText(dir, growing);
- XtFree(growing);
-}
-
-static int
-SFfindFile(dir, str)
- SFDir *dir;
- register char *str;
-{
- register int i, last, max;
- register char *name, save;
- SFEntry *entries;
- int len;
- int begin, end;
- int result;
-
- len = strlen(str);
-
- if (str[len - 1] == ' ') {
- SFexpand(str);
- return 1;
- } else if (str[len - 1] == '/') {
- len--;
- }
-
- max = dir->nEntries;
-
- entries = dir->entries;
-
- i = 0;
- while (i < max) {
- name = entries[i].shown;
- last = strlen(name) - 1;
- save = name[last];
- name[last] = 0;
-
-#ifdef SEL_FILE_IGNORE_CASE
- result = SFstrncmp(str, name, len);
-#else /* def SEL_FILE_IGNORE_CASE */
- result = strncmp(str, name, len);
-#endif /* def SEL_FILE_IGNORE_CASE */
-
- name[last] = save;
- if (result <= 0) {
- break;
- }
- i++;
- }
- begin = i;
- while (i < max) {
- name = entries[i].shown;
- last = strlen(name) - 1;
- save = name[last];
- name[last] = 0;
-
-#ifdef SEL_FILE_IGNORE_CASE
- result = SFstrncmp(str, name, len);
-#else /* def SEL_FILE_IGNORE_CASE */
- result = strncmp(str, name, len);
-#endif /* def SEL_FILE_IGNORE_CASE */
-
- name[last] = save;
- if (result) {
- break;
- }
- i++;
- }
- end = i;
-
- if (begin != end) {
- if (
- (dir->beginSelection != begin) ||
- (dir->endSelection != end - 1)
- ) {
- dir->changed = 1;
- dir->beginSelection = begin;
- if (str[strlen(str) - 1] == '/') {
- dir->endSelection = begin;
- } else {
- dir->endSelection = end - 1;
- }
- }
- } else {
- if (dir->beginSelection != -1) {
- dir->changed = 1;
- dir->beginSelection = -1;
- dir->endSelection = -1;
- }
- }
-
- if (
- SFdoNotTouchVorigin ||
- ((begin > dir->vOrigin) && (end < dir->vOrigin + SFlistSize))
- ) {
- SFdoNotTouchVorigin = 0;
- return 0;
- }
-
- i = begin - 1;
- if (i > max - SFlistSize) {
- i = max - SFlistSize;
- }
- if (i < 0) {
- i = 0;
- }
-
- if (dir->vOrigin != i) {
- dir->vOrigin = i;
- dir->changed = 1;
- }
-
- return 0;
-}
-
-static void
-SFunselect()
-{
- SFDir *dir;
-
- dir = &(SFdirs[SFdirEnd - 1]);
- if (dir->beginSelection != -1) {
- dir->changed = 1;
- }
- dir->beginSelection = -1;
- dir->endSelection = -1;
- return;
-}
-
-static int
-SFcompareLogins(p, q)
- SFLogin *p, *q;
-{
- return strcmp(p->name, q->name);
-}
-
-static void
-SFgetHomeDirs()
-{
- struct passwd *pw;
- int alloc;
- int i;
- SFEntry *entries = NULL;
- int len;
- int maxChars;
-
- {
- alloc = 1;
- i = 1;
- entries = (SFEntry *) XtMalloc(sizeof(SFEntry));
- SFlogins = (SFLogin *) XtMalloc(sizeof(SFLogin));
- entries[0].real = XtMalloc(3);
- (void) strcpy(entries[0].real, "~");
- entries[0].shown = entries[0].real;
- entries[0].statDone = 1;
- SFlogins[0].name = "";
- pw = getpwuid((int) getuid());
- SFstrdup(&SFlogins[0].dir, pw ? pw->pw_dir : "/");
- maxChars = 0;
- }
-
- (void) setpwent();
-
- while ((pw = getpwent()) && (*(pw->pw_name))) {
- if (i >= alloc) {
- alloc *= 2;
- entries = (SFEntry *) XtRealloc(
- (char *) entries,
- (unsigned) (alloc * sizeof(SFEntry))
- );
- SFlogins = (SFLogin *) XtRealloc(
- (char *) SFlogins,
- (unsigned) (alloc * sizeof(SFLogin))
- );
- }
- len = strlen(pw->pw_name);
- entries[i].real = XtMalloc((unsigned) (len + 3));
- (void) strcat(strcpy(entries[i].real, "~"),
- pw->pw_name);
- entries[i].shown = entries[i].real;
- entries[i].statDone = 1;
- if (len > maxChars) {
- maxChars = len;
- }
- SFstrdup(&SFlogins[i].name, pw->pw_name);
- SFstrdup(&SFlogins[i].dir, pw->pw_dir);
- i++;
- }
-
- SFhomeDir.dir = XtMalloc(1) ;
- SFhomeDir.dir[0] = 0 ;
- SFhomeDir.path = SFcurrentPath ;
- SFhomeDir.entries = entries ;
- SFhomeDir.nEntries = i ;
- SFhomeDir.vOrigin = 0 ; /* :-) */
- SFhomeDir.nChars = maxChars + 2 ;
- SFhomeDir.hOrigin = 0 ;
- SFhomeDir.changed = 1 ;
- SFhomeDir.beginSelection = -1 ;
- SFhomeDir.endSelection = -1 ;
-
- qsort((char *) entries, (size_t)i, sizeof(SFEntry), SFcompareEntries);
- qsort((char *) SFlogins, (size_t)i, sizeof(SFLogin), SFcompareLogins);
-
- for (i--; i >= 0; i--) {
- (void) strcat(entries[i].real, "/");
- }
- return;
-}
-
-static int
-SFfindHomeDir(begin, end)
- char *begin, *end;
-{
- char save;
- char *theRest;
- int i;
-
- save = *end;
- *end = 0;
-
- for (i = SFhomeDir.nEntries - 1; i >= 0; i--) {
- if (!strcmp(SFhomeDir.entries[i].real, begin)) {
- *end = save;
- SFstrdup(&theRest, end);
- (void) strcat(strcat(strncpy(SFcurrentPath,SFlogins[i].dir,
- MAXPATHLEN), "/"),
- theRest);
- XtFree(theRest);
- SFsetText(SFcurrentPath);
- SFtextChanged();
- return 1;
- }
- }
-
- *end = save;
-
- return 0;
-}
-
-void
-SFupdatePath()
-{
- static int alloc;
- static int wasTwiddle = 0;
- char *begin, *end;
- int i, j;
- int prevChange;
- int SFdirPtrSave, SFdirEndSave;
- SFDir *dir;
-
- if (!SFdirs) {
- SFdirs = (SFDir *) XtMalloc((alloc = 10) * sizeof(SFDir));
- dir = &(SFdirs[0]);
- SFstrdup(&dir->dir, "/");
- (void) SFchdir("/");
- (void) SFgetDir(dir);
- for (j = 1; j < alloc; j++) {
- SFdirs[j].dir = NULL;
- }
- dir->path = SFcurrentPath + 1;
- dir->vOrigin = 0;
- dir->hOrigin = 0;
- dir->changed = 1;
- dir->beginSelection = -1;
- dir->endSelection = -1;
- SFhomeDir.dir = NULL;
- }
-
- SFdirEndSave = SFdirEnd;
- SFdirEnd = 1;
-
- SFdirPtrSave = SFdirPtr;
- SFdirPtr = 0;
-
- begin = NULL;
-
- if (SFcurrentPath[0] == '~') {
- if (!SFtwiddle) {
- SFtwiddle = 1;
- dir = &(SFdirs[0]);
- SFrootDir = *dir;
- if (!SFhomeDir.dir) {
- SFgetHomeDirs();
- }
- *dir = SFhomeDir;
- dir->changed = 1;
- }
- end = SFcurrentPath;
- SFdoNotTouchDirPtr = 1;
- wasTwiddle = 1;
- } else {
- if (SFtwiddle) {
- SFtwiddle = 0;
- dir = &(SFdirs[0]);
- *dir = SFrootDir;
- dir->changed = 1;
- }
- end = SFcurrentPath + 1;
- }
-
- i = 0;
-
- prevChange = 0;
-
- while (*end) {
- while (*end++ == '/') {
- ;
- }
- end--;
- begin = end;
- while ((*end) && (*end++ != '/')) {
- ;
- }
- if ((end - SFcurrentPath <= SFtextPos) && (*(end - 1) == '/')) {
- SFdirPtr = i - 1;
- if (SFdirPtr < 0) {
- SFdirPtr = 0;
- }
- }
- if (*begin) {
- if (*(end - 1) == '/') {
- char save = *end;
-
- if (SFtwiddle) {
- if (SFfindHomeDir(begin, end)) {
- return;
- }
- }
- *end = 0;
- i++;
- SFdirEnd++;
- if (i >= alloc) {
- SFdirs = (SFDir *) XtRealloc(
- (char *) SFdirs,
- (unsigned) ((alloc *= 2) *
- sizeof(SFDir))
- );
- for (j = alloc / 2; j < alloc; j++) {
- SFdirs[j].dir = NULL;
- }
- }
- dir = &(SFdirs[i]);
- if (
- (!(dir->dir)) ||
- prevChange ||
- strcmp(dir->dir, begin)
- ) {
- if (dir->dir) {
- SFfree(i);
- }
- prevChange = 1;
- SFstrdup(&dir->dir, begin);
- dir->path = end;
- dir->vOrigin = 0;
- dir->hOrigin = 0;
- dir->changed = 1;
- dir->beginSelection = -1;
- dir->endSelection = -1;
- (void) SFfindFile(dir - 1, begin);
- if (
- SFchdir(SFcurrentPath) ||
- SFgetDir(dir)
- ) {
- SFunreadableDir(dir);
- break;
- }
- }
- *end = save;
- if (!save) {
- SFunselect();
- }
- } else {
- if (SFfindFile(&(SFdirs[SFdirEnd-1]), begin)) {
- return;
- }
- }
- } else {
- SFunselect();
- }
- }
-
- if ((end == SFcurrentPath + 1) && (!SFtwiddle)) {
- SFunselect();
- }
-
- for (i = SFdirEnd; i < alloc; i++) {
- if (SFdirs[i].dir) {
- SFfree(i);
- }
- }
-
- if (SFdoNotTouchDirPtr) {
- if (wasTwiddle) {
- wasTwiddle = 0;
- SFdirPtr = SFdirEnd - 1;
- if (SFdirPtr < 0) {
- SFdirPtr = 0;
- }
- } else {
- SFdirPtr = SFdirPtrSave;
- }
- SFdoNotTouchDirPtr = 0;
- }
-
- if ((SFdirPtr != SFdirPtrSave) || (SFdirEnd != SFdirEndSave)) {
- XawScrollbarSetThumb(
- selFileHScroll,
- (float) (((double) SFdirPtr) / SFdirEnd),
- (float) (((double) ((SFdirEnd < NR) ? SFdirEnd : NR)) /
- SFdirEnd)
- );
- }
-
- if (SFdirPtr != SFdirPtrSave) {
- SFdrawLists(SF_DO_SCROLL);
- } else {
- for (i = 0; i < NR; i++) {
- if (SFdirPtr + i < SFdirEnd) {
- if (SFdirs[SFdirPtr + i].changed) {
- SFdirs[SFdirPtr + i].changed = 0;
- SFdrawList(i, SF_DO_SCROLL);
- }
- } else {
- SFclearList(i, SF_DO_SCROLL);
- }
- }
- }
- return;
-}
-
-/* ARGSUSED */
-void
-SFbuttonPressList(w, n, event)
- Widget w;
- int n;
- XButtonPressedEvent *event;
-{
- int dir = 0;
- if(event->button == Button4) dir = -2; // kludge to indicate relative motion
- if(event->button == Button5) dir = -1;
- if(dir) SFvSliderMovedCallback(w, n, dir); else
- SFbuttonPressed = 1;
-}
-
-/* ARGSUSED */
-void
-SFbuttonReleaseList(w, n, event)
- Widget w;
- int n;
- XButtonReleasedEvent *event;
-{
- SFDir *dir;
- static int lastClick;
-
- if(event->button == Button4 || event->button == Button5) return; // [HGM] mouse wheel does not select
- SFbuttonPressed = 0;
-
- if (SFcurrentInvert[n] != -1) {
- if (n < 2) {
- SFdoNotTouchDirPtr = 1;
- }
- SFdoNotTouchVorigin = 1;
- dir = &(SFdirs[SFdirPtr + n]);
- SFreplaceText(
- dir,
- dir->entries[dir->vOrigin + SFcurrentInvert[n]].shown
- );
- SFmotionList(w, n, (XMotionEvent *) event);
- if(lastClick == 256*n + SFcurrentInvert[n]) SFstatus = SEL_FILE_OK; // [HGM] double click implies OK
- }
- lastClick = 256*n + SFcurrentInvert[n];
-}
-
-static int
-SFcheckDir(n, dir)
- int n;
- SFDir *dir;
-{
- struct stat statBuf;
- int i;
-
- if (
- (!stat(".", &statBuf)) &&
- (statBuf.st_mtime != dir->mtime)
- ) {
-
- /*
- * If the pointer is currently in the window that we are about
- * to update, we must warp it to prevent the user from
- * accidentally selecting the wrong file.
- */
- if (SFcurrentInvert[n] != -1) {
- XWarpPointer(
- SFdisplay,
- None,
- XtWindow(selFileLists[n]),
- 0,
- 0,
- 0,
- 0,
- 0,
- 0
- );
- }
-
- for (i = dir->nEntries - 1; i >= 0; i--) {
- if (dir->entries[i].shown != dir->entries[i].real) {
- XtFree(dir->entries[i].shown);
- }
- XtFree(dir->entries[i].real);
- }
- XtFree((char *) dir->entries);
- if (SFgetDir(dir)) {
- SFunreadableDir(dir);
- }
- if (dir->vOrigin > dir->nEntries - SFlistSize) {
- dir->vOrigin = dir->nEntries - SFlistSize;
- }
- if (dir->vOrigin < 0) {
- dir->vOrigin = 0;
- }
- if (dir->hOrigin > dir->nChars - SFcharsPerEntry) {
- dir->hOrigin = dir->nChars - SFcharsPerEntry;
- }
- if (dir->hOrigin < 0) {
- dir->hOrigin = 0;
- }
- dir->beginSelection = -1;
- dir->endSelection = -1;
- SFdoNotTouchVorigin = 1;
- if ((dir + 1)->dir) {
- (void) SFfindFile(dir, (dir + 1)->dir);
- } else {
- (void) SFfindFile(dir, dir->path);
- }
-
- if (!SFworkProcAdded) {
- (void) XtAppAddWorkProc(SFapp, SFworkProc, NULL);
- SFworkProcAdded = 1;
- }
-
- return 1;
- }
-
- return 0;
-}
-
-/* Return a single character describing what kind of file STATBUF is. */
-
-char
-SFstatChar (statBuf)
- struct stat *statBuf;
-{
- if (S_ISDIR (statBuf->st_mode)) {
- return '/';
- } else if (S_ISREG (statBuf->st_mode)) {
- return S_ISXXX (statBuf->st_mode) ? '*' : ' ';
-#ifdef S_ISSOCK
- } else if (S_ISSOCK (statBuf->st_mode)) {
- return '=';
-#endif /* S_ISSOCK */
- } else {
- return ' ';
- }
-}
-
-static int
-SFcheckFiles(dir)
- SFDir *dir;
-{
- int from, to;
- int result;
- char old, new;
- int i;
- char *str;
- int last;
- struct stat statBuf;
-
- result = 0;
-
- from = dir->vOrigin;
- to = dir->vOrigin + SFlistSize;
- if (to > dir->nEntries) {
- to = dir->nEntries;
- }
-
- for (i = from; i < to; i++) {
- str = dir->entries[i].real;
- last = strlen(str) - 1;
- old = str[last];
- str[last] = 0;
- if (stat(str, &statBuf)) {
- new = ' ';
- } else {
- new = SFstatChar(&statBuf);
- }
- str[last] = new;
- if (new != old) {
- result = 1;
- }
- }
-
- return result;
-}
-
-void
-SFdirModTimer(cl, id)
- XtPointer cl;
- XtIntervalId *id;
-{
- static int n = -1;
- static int f = 0;
- char save;
- SFDir *dir;
-
- if ((!SFtwiddle) && (SFdirPtr < SFdirEnd)) {
- n++;
- if ((n > NR-1) || (SFdirPtr + n >= SFdirEnd)) {
- n = 0;
- f++;
- if ((f > NR-1) || (SFdirPtr + f >= SFdirEnd)) {
- f = 0;
- }
- }
- dir = &(SFdirs[SFdirPtr + n]);
- save = *(dir->path);
- *(dir->path) = 0;
- if (SFchdir(SFcurrentPath)) {
- *(dir->path) = save;
-
- /*
- * force a re-read
- */
- *(dir->dir) = 0;
-
- SFupdatePath();
- } else {
- *(dir->path) = save;
- if (
- SFcheckDir(n, dir) ||
- ((f == n) && SFcheckFiles(dir))
- ) {
- SFdrawList(n, SF_DO_SCROLL);
- }
- }
- }
-
- SFdirModTimerId = XtAppAddTimeOut(SFapp, (unsigned long) 1000,
- SFdirModTimer, (XtPointer) NULL);
-}
+++ /dev/null
-/*
- * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Software Research Associates not be used
- * in advertising or publicity pertaining to distribution of the software
- * without specific, written prior permission. Software Research Associates
- * makes no representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
- * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Erik M. van der Poel
- * Software Research Associates, Inc., Tokyo, Japan
- * erik@sra.co.jp
- */
-
-/*
- * Author's address:
- *
- * erik@sra.co.jp
- * OR
- * erik%sra.co.jp@uunet.uu.net
- * OR
- * erik%sra.co.jp@mcvax.uucp
- * OR
- * try junet instead of co.jp
- * OR
- * Erik M. van der Poel
- * Software Research Associates, Inc.
- * 1-1-1 Hirakawa-cho, Chiyoda-ku
- * Tokyo 102 Japan. TEL +81-3-234-2692
- */
-
-#include <stdio.h>
-#include <errno.h>
-/* BSD 4.3 errno.h does not declare errno */
-extern int errno;
-//extern int sys_nerr;
-//extern char *sys_errlist[]; // [HGM] this produced a compile error in Ubuntu 8.04
-
-#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/Form.h>
-#include <X11/Xaw/Command.h>
-#include <X11/Xaw/Scrollbar.h>
-#include <X11/Xaw/Label.h>
-#include <X11/Xaw/Cardinals.h>
-
-#include "xstat.h"
-#include "selfile.h"
-#include "../gettext.h"
-
-#ifndef MAXPATHLEN
-#define MAXPATHLEN 1024
-#endif /* ndef MAXPATHLEN */
-
-#if !defined(SVR4) && !defined(SYSV) && !defined(USG)
-extern char *getwd();
-#endif /* !defined(SVR4) && !defined(SYSV) && !defined(USG) */
-
-#ifdef ENABLE_NLS
-# define _(s) gettext (s)
-# define N_(s) gettext_noop (s)
-#else
-# define _(s) (s)
-# define N_(s) s
-#endif
-
-
-int SFstatus = SEL_FILE_NULL;
-
-char
- SFstartDir[MAXPATHLEN+1],
- SFcurrentPath[MAXPATHLEN+1],
- SFlastPath[MAXPATHLEN+1],
- SFcurrentDir[MAXPATHLEN+1];
-
-Widget
- selFile,
- selFileCancel,
- selFileField,
- selFileMess,
- filterField,
- selFileForm,
- selFileHScroll,
- selFileHScrolls[3],
- selFileLists[3],
- selFileOK,
- selFilePrompt,
- selFileVScrolls[3];
-
-Display *SFdisplay;
-
-Pixel SFfore, SFback;
-
-Atom SFwmDeleteWindow;
-
-XSegment SFsegs[2], SFcompletionSegs[2];
-
-XawTextPosition SFtextPos;
-
-int SFupperX, SFlowerY, SFupperY;
-
-int SFtextX, SFtextYoffset;
-
-int SFentryWidth, 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, SFvScrollHeight, SFhScrollWidth;
-
-char SFtextBuffer[MAXPATHLEN+1];
-
-char SFfilterBuffer[MAXPATHLEN+1];
-
-XtIntervalId SFdirModTimerId;
-
-int (*SFfunc)();
-
-Boolean SFpathFlag; // [HGM]
-
-static char *oneLineTextEditTranslations = "\
- <Key>Return: redraw-display()\n\
- Ctrl<Key>M: redraw-display()\n\
-";
-
-/* ARGSUSED */
-static void
-SFexposeList(w, n, event, cont)
- Widget w;
- XtPointer n;
- XEvent *event;
- Boolean *cont;
-{
- if ((event->type == NoExpose) || event->xexpose.count) {
- return;
- }
-
- SFdrawList((int)(intptr_t)n, SF_DO_NOT_SCROLL);
-}
-
-void
-SFpurge()
-{
- if(SFdirs) XtFree((XtPointer) SFdirs);
- SFdirs = NULL; // kludge to throw away all cached info
-}
-
-/* ARGSUSED */
-static void
-SFmodVerifyCallback(w, client_data, event, cont)
- Widget w;
- XtPointer client_data;
- XEvent *event;
- Boolean *cont;
-{
- char buf[2];
-
- if (
- (XLookupString(&(event->xkey), buf, 2, NULL, NULL) == 1) &&
- ((*buf) == '\r' || *buf == 033)
- ) {
- if(client_data) {
- Arg args[10]; char *p;
- if(*buf == 033) { // [HGM] esc in filter: restore and give focus to path
- XtSetArg(args[0], XtNstring, SFfilterBuffer);
- XtSetValues(filterField, args, 1);
- XtSetKeyboardFocus(selFileForm, selFileField);
- SFstatus = SEL_FILE_TEXT;
- return;
- } else
- if(!SFpathFlag) // [HGM] cr: fetch current extenson filter
- {
- XtSetArg(args[0], XtNstring, &p);
- XtGetValues(filterField, args, 1);
- if(strcmp(SFfilterBuffer, p)) SFpurge();
- strncpy(SFfilterBuffer, p, 40);
- SFstatus = SEL_FILE_TEXT;
- }
- return;
- }
- SFstatus = (*buf == 033 ? SEL_FILE_CANCEL : SEL_FILE_OK);
- } else {
- if(!client_data) SFstatus = SEL_FILE_TEXT;
- }
-}
-
-/* ARGSUSED */
-static void
-SFokCallback(w, cl, cd)
- Widget w;
- XtPointer cl, cd;
-{
- SFstatus = SEL_FILE_OK;
-}
-
-static XtCallbackRec SFokSelect[] = {
- { SFokCallback, (XtPointer) NULL },
- { NULL, (XtPointer) NULL },
-};
-
-/* ARGSUSED */
-static void
-SFcancelCallback(w, cl, cd)
- Widget w;
- XtPointer cl, cd;
-{
- SFstatus = SEL_FILE_CANCEL;
-}
-
-static XtCallbackRec SFcancelSelect[] = {
- { SFcancelCallback, (XtPointer) NULL },
- { NULL, (XtPointer) NULL },
-};
-
-/* ARGSUSED */
-static void
-SFdismissAction(w, event, params, num_params)
- Widget w;
- XEvent *event;
- String *params;
- Cardinal *num_params;
-{
- if (event->type == ClientMessage &&
- event->xclient.data.l[0] != SFwmDeleteWindow) return;
-
- SFstatus = SEL_FILE_CANCEL;
-}
-
-static char *wmDeleteWindowTranslation = "\
- <Message>WM_PROTOCOLS: SelFileDismiss()\n\
-";
-
-static XtActionsRec actions[] = {
- {"SelFileDismiss", SFdismissAction},
-};
-
-void SFsetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b)
-{
- XtSetKeyboardFocus((Widget) data, w);
-}
-
-void SFwheelProc(Widget w, XtPointer data, XEvent *event, Boolean *b)
-{ // [HGM] mouse-wheel callback scrolls lists
- int dir, n = (intptr_t) data;
- if(event->xbutton.button == Button4) dir = -2; // kludge to indicate relative motion
- if(event->xbutton.button == Button5) dir = -1;
- SFvSliderMovedCallback(w, n, dir);
-}
-
-static void
-SFcreateWidgets(toplevel, prompt, ok, cancel)
- Widget toplevel;
- char *prompt;
- char *ok;
- char *cancel;
-{
- Cardinal i, n;
- int listWidth, listHeight;
- int listSpacing = 10;
- int scrollThickness = 15;
- int hScrollX, hScrollY;
- int vScrollX, vScrollY;
- Cursor
- xtermCursor,
- sbRightArrowCursor,
- dotCursor;
- Arg arglist[20];
-
- i = 0;
- XtSetArg(arglist[i], XtNtransientFor, toplevel); i++;
-
- selFile = XtAppCreateShell(_("Browse"), "SelFile",
- transientShellWidgetClass, SFdisplay, arglist, i);
-
- /* Add WM_DELETE_WINDOW protocol */
- XtAppAddActions(XtWidgetToApplicationContext(selFile),
- actions, XtNumber(actions));
- XtOverrideTranslations(selFile,
- XtParseTranslationTable(wmDeleteWindowTranslation));
-
- i = 0;
- XtSetArg(arglist[i], XtNdefaultDistance, 30); i++;
- selFileForm = XtCreateManagedWidget("selFileForm",
- formWidgetClass, selFile, 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++;
- selFilePrompt = XtCreateManagedWidget("selFilePrompt",
- labelWidgetClass, selFileForm, arglist, i);
-
- i = 0;
- XtSetArg(arglist[i], XtNforeground, &SFfore); i++;
- XtSetArg(arglist[i], XtNbackground, &SFback); i++;
- XtGetValues(selFilePrompt, arglist, i);
-
- 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 = NR * listWidth + (NR-1) * 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, NR * listWidth + (NR - 1) * listSpacing + 4);
- i++;
- XtSetArg(arglist[i], XtNborderColor, SFfore); i++;
-
- XtSetArg(arglist[i], XtNfromVert, selFilePrompt); i++;
- XtSetArg(arglist[i], XtNvertDistance, 5); 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++;
- selFileField = XtCreateManagedWidget("selFileField",
- asciiTextWidgetClass, selFileForm, arglist, i);
-
- XtOverrideTranslations(selFileField,
- XtParseTranslationTable(oneLineTextEditTranslations));
- XtAddEventHandler(selFileField, ButtonPressMask, False, SFsetFocus, (XtPointer) selFileForm);
-
- i = 0;
- XtSetArg(arglist[i], XtNlabel, _("Filter on extensions:")); i++;
- XtSetArg(arglist[i], XtNvertDistance, 5); i++;
- XtSetArg(arglist[i], XtNfromVert, selFileField); 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++;
- selFileMess = XtCreateManagedWidget("selFileMess",
- labelWidgetClass, selFileForm, arglist, i);
-
- i = 0;
- XtSetArg(arglist[i], XtNwidth, NR * listWidth + (NR - 1) * listSpacing + 4);
- i++;
- XtSetArg(arglist[i], XtNborderColor, SFfore); i++;
- XtSetArg(arglist[i], XtNvertDistance, 5); i++;
- XtSetArg(arglist[i], XtNfromVert, selFileMess); 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], 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, False); i++;
- filterField = XtCreateManagedWidget("filterField",
- asciiTextWidgetClass, selFileForm, arglist, i);
-
- XtOverrideTranslations(filterField,
- XtParseTranslationTable(oneLineTextEditTranslations));
- XtAddEventHandler(filterField, ButtonPressMask, False, SFsetFocus, (XtPointer) selFileForm);
-
- 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, filterField); 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++;
- selFileHScroll = XtCreateManagedWidget("selFileHScroll",
- scrollbarWidgetClass, selFileForm, arglist, i);
-
- XtAddCallback(selFileHScroll, XtNjumpProc,
- SFpathSliderMovedCallback, (XtPointer) NULL);
- XtAddCallback(selFileHScroll, XtNscrollProc,
- 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);
-#if (NR == 3)
- 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);
-#endif
- for (n = 0; n < NR; 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,
- SFvFloatSliderMovedCallback, (XtPointer)(intptr_t) n);
- XtAddCallback(selFileVScrolls[n], XtNscrollProc,
- SFvAreaSelectedCallback, (XtPointer)(intptr_t) 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,
- SFhSliderMovedCallback, (XtPointer)(intptr_t) n);
- XtAddCallback(selFileHScrolls[n], XtNscrollProc,
- SFhAreaSelectedCallback, (XtPointer)(intptr_t) n);
-
- XtAddEventHandler(selFileVScrolls[n], ButtonPressMask, False,
- SFwheelProc, (XtPointer)(intptr_t) n); // [HGM] couplemouse wheel to v-scroll
- }
-
- i = 0;
- XtSetArg(arglist[i], XtNlabel, ok); i++;
- XtSetArg(arglist[i], XtNresizable, True); i++;
- XtSetArg(arglist[i], XtNcallback, SFokSelect); i++;
- XtSetArg(arglist[i], XtNborderColor, SFfore); i++;
- XtSetArg(arglist[i], XtNfromVert, selFileLists[0]); 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++;
- selFileOK = XtCreateManagedWidget("selFileOK", commandWidgetClass,
- selFileForm, arglist, i);
-
- i = 0;
- XtSetArg(arglist[i], XtNlabel, cancel); i++;
- XtSetArg(arglist[i], XtNresizable, True); i++;
- XtSetArg(arglist[i], XtNcallback, SFcancelSelect); i++;
- XtSetArg(arglist[i], XtNborderColor, SFfore); i++;
- XtSetArg(arglist[i], XtNfromHoriz, selFileOK); i++;
- XtSetArg(arglist[i], XtNfromVert, selFileLists[0]); i++;
- XtSetArg(arglist[i], XtNhorizDistance, 30); 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++;
- selFileCancel = XtCreateManagedWidget("selFileCancel",
- commandWidgetClass, selFileForm, arglist, i);
-
- 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);
- dotCursor = XCreateFontCursor(SFdisplay, XC_dot);
-
- XDefineCursor(SFdisplay, XtWindow(selFileForm), xtermCursor);
- XDefineCursor(SFdisplay, XtWindow(selFileField), xtermCursor);
- XDefineCursor(SFdisplay, XtWindow(filterField), xtermCursor);
-
- for (n = 0; n < NR; n++) {
- XDefineCursor(SFdisplay, XtWindow(selFileLists[n]),
- sbRightArrowCursor);
- }
- XDefineCursor(SFdisplay, XtWindow(selFileOK), dotCursor);
- XDefineCursor(SFdisplay, XtWindow(selFileCancel), dotCursor);
-
- for (n = 0; n < NR; n++) {
- XtAddEventHandler(selFileLists[n], ExposureMask, True,
- SFexposeList, (XtPointer)(intptr_t) n);
- XtAddEventHandler(selFileLists[n], EnterWindowMask, False,
- SFenterList, (XtPointer)(intptr_t) n);
- XtAddEventHandler(selFileLists[n], LeaveWindowMask, False,
- SFleaveList, (XtPointer)(intptr_t) n);
- XtAddEventHandler(selFileLists[n], PointerMotionMask, False,
- (XtEventHandler) SFmotionList, (XtPointer)(intptr_t) n);
- XtAddEventHandler(selFileLists[n], ButtonPressMask, False,
- SFbuttonPressList, (XtPointer)(intptr_t) n);
- XtAddEventHandler(selFileLists[n], ButtonReleaseMask, False,
- SFbuttonReleaseList, (XtPointer)(intptr_t) n);
- }
-
- XtAddEventHandler(selFileField, KeyPressMask, False,
- SFmodVerifyCallback, (XtPointer) NULL);
- XtAddEventHandler(filterField, KeyReleaseMask, False,
- SFmodVerifyCallback, (XtPointer) 1);
- XtSetKeyboardFocus(selFileForm, selFileField);
-
- SFapp = XtWidgetToApplicationContext(selFile);
-
-}
-
-/* position widget under the cursor */
-void
-SFpositionWidget(w)
- Widget w;
-{
- 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);
-}
-
-FILE *
-SFopenFile(name, mode, prompt, failed)
- char *name;
- char *mode;
- char *prompt;
- char *failed;
-{
- Arg args[1];
- FILE *fp;
-
- SFchdir(SFstartDir);
- if ((fp = fopen(name, mode)) == NULL) {
- char *buf;
- if (1) { // [HGM] always use strerror
- buf = XtMalloc(strlen(failed) + strlen(strerror(errno)) +
- strlen(prompt) + 2);
- strcpy(buf, failed);
- strcat(buf, strerror(errno));
- strcat(buf, "\n");
- strcat(buf, prompt);
- } else {
- buf = XtMalloc(strlen(failed) + strlen(prompt) + 2);
- strcpy(buf, failed);
- strcat(buf, "\n");
- strcat(buf, prompt);
- }
- XtSetArg(args[0], XtNlabel, buf);
- XtSetValues(selFilePrompt, args, ONE);
- XtFree(buf);
- return NULL;
- }
- return fp;
-}
-
-void
-SFupdateTextBuffer()
-{
- Arg arglist[2];
- int i;
- char *v;
-
- i = 0;
- XtSetArg(arglist[i], XtNstring, &v); i++;
- XtGetValues(selFileField, arglist, i);
- strncpy(SFtextBuffer, v, MAXPATHLEN);
-}
-
-void
-SFsetText(path)
- char *path;
-{
- Arg arglist[2];
- int i;
-
- i = 0;
- XtSetArg(arglist[i], XtNstring, path); i++;
- XtSetValues(selFileField, arglist, i);
- XawTextSetInsertionPoint(selFileField, strlen(path));
-}
-
-void
-SFtextChanged()
-{
- SFupdateTextBuffer();
-
- if ((SFtextBuffer[0] == '/') || (SFtextBuffer[0] == '~')) {
- (void) strncpy(SFcurrentPath, SFtextBuffer, MAXPATHLEN);
-
- SFtextPos = XawTextGetInsertionPoint(selFileField);
- } else {
- (void) strcat(strncpy(SFcurrentPath, SFstartDir, MAXPATHLEN), SFtextBuffer);
-
- SFtextPos = XawTextGetInsertionPoint(selFileField) +
- strlen(SFstartDir);
- }
-
- if (!SFworkProcAdded) {
- (void) XtAppAddWorkProc(SFapp, SFworkProc, NULL);
- SFworkProcAdded = 1;
- }
-
- SFupdatePath();
- return;
-}
-
-static char *
-SFgetText()
-{
- return strcpy(XtMalloc((unsigned) (strlen(SFtextBuffer) + 1)),
- SFtextBuffer);
-}
-
-static void
-SFprepareToReturn()
-{
- SFstatus = SEL_FILE_NULL;
- XtRemoveGrab(selFile);
- XtUnmapWidget(selFile);
- XtRemoveTimeOut(SFdirModTimerId);
- if (SFchdir(SFstartDir)) {
- XtAppError(
- SFapp,
- "XsraSelFile: can't return to current directory"
- );
- }
- return;
-}
-
-FILE *
-XsraSelFile(toplevel, prompt, ok, cancel, failed,
- init_path, filter, mode, show_entry, name_return)
- Widget toplevel;
- char *prompt;
- char *ok;
- char *cancel;
- char *failed;
- char *init_path;
- char *filter;
- char *mode;
- int (*show_entry)();
- char **name_return;
-{
- static int firstTime = 1;
- Cardinal i;
- Arg arglist[20];
- XEvent event;
- FILE *fp;
-
- if (!prompt) {
- prompt = _("Pathname:");
- }
-
- if (!ok) {
- ok = _("OK");
- }
-
- if (!cancel) {
- cancel = _("Cancel");
- }
-
- if(SFpathFlag != (mode && mode[0] == 'p') || strcmp(SFfilterBuffer, filter)) {
- SFpurge();
- SFpathFlag = (mode && mode[0] == 'p'); // [HGM] ignore everything that is not a directory
- }
-
- if (firstTime) {
- firstTime = 0;
- SFdisplay = XtDisplay(toplevel);
- SFcreateWidgets(toplevel, prompt, ok, cancel);
- } else {
- i = 0;
-
- XtSetArg(arglist[i], XtNlabel, prompt); i++;
- XtSetValues(selFilePrompt, arglist, i);
-
- i = 0;
- XtSetArg(arglist[i], XtNlabel, ok); i++;
- XtSetValues(selFileOK, arglist, i);
-
- i = 0;
- XtSetArg(arglist[i], XtNlabel, cancel); i++;
- XtSetValues(selFileCancel, arglist, i);
- }
-
- i = 0;
- XtSetArg(arglist[i], XtNstring, filter); i++;
- XtSetValues(filterField, arglist, i);
-
- strncpy(SFfilterBuffer, filter, MAXPATHLEN-1);
- SFupdateTextBuffer();
- strncpy(SFlastPath, SFtextBuffer, MAXPATHLEN-1); // remember for cancel
-
- SFpositionWidget(selFile);
- XtMapWidget(selFile);
-
-#if defined(SVR4) || defined(SYSV) || defined(USG) || 1
- if (!getcwd(SFstartDir, MAXPATHLEN)) { // [HGM] always do this, as I do not know when exactly to do it
-#else /* defined(SVR4) || defined(SYSV) || defined(USG) */
- if (!getwd(SFstartDir)) {
-#endif /* defined(SVR4) || defined(SYSV) || defined(USG) */
-
- XtAppError(SFapp, _("XsraSelFile: can't get current directory"));
- }
- (void) strcat(SFstartDir, "/");
- (void) strncpy(SFcurrentDir, SFstartDir, MAXPATHLEN);
-
- if (init_path) {
- if (init_path[0] == '/') {
- (void) strncpy(SFcurrentPath, init_path, MAXPATHLEN);
- if (strncmp(
- SFcurrentPath,
- SFstartDir,
- strlen(SFstartDir)
- )) {
- SFsetText(SFcurrentPath);
- } else {
- SFsetText(&(SFcurrentPath[strlen(SFstartDir)]));
- }
- } else {
- (void) strcat(strncpy(SFcurrentPath, SFstartDir, MAXPATHLEN),
- init_path);
- SFsetText(&(SFcurrentPath[strlen(SFstartDir)]));
- }
- } else {
- (void) strncpy(SFcurrentPath, SFstartDir, MAXPATHLEN);
- }
-
- SFfunc = show_entry;
-
- SFtextChanged();
-
- XtAddGrab(selFile, True, True);
-
- SFdirModTimerId = XtAppAddTimeOut(SFapp, (unsigned long) 1000,
- SFdirModTimer, (XtPointer) NULL);
-
- while (1) {
- XtAppNextEvent(SFapp, &event);
- XtDispatchEvent(&event);
- switch (SFstatus) {
- case SEL_FILE_TEXT:
- SFstatus = SEL_FILE_NULL;
- SFtextChanged();
- break;
- case SEL_FILE_OK:
- *name_return = SFgetText();
- if(mode && (mode[0] == 'p' || mode[0] == 'f')) { // [HGM] for use in file-option browse button
- SFprepareToReturn();
- return stderr;
- }
- if ((!(*name_return)[0] || (*name_return)[strlen(*name_return)-1] != '/') && // [HGM] refuse directories
- (fp = SFopenFile(*name_return, mode, prompt, failed))) {
- SFprepareToReturn();
- return fp;
- }
- SFstatus = SEL_FILE_NULL;
- break;
- case SEL_FILE_CANCEL:
- SFprepareToReturn();
- SFsetText(SFlastPath);
- return NULL;
- case SEL_FILE_NULL:
- break;
- }
- }
-
-}
+++ /dev/null
-/*
- * File-Selector dialog of GhostView 1.5, incorporated in XBoard by H.G.Muller
- *
- * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Software Research Associates not be used
- * in advertising or publicity pertaining to distribution of the software
- * without specific, written prior permission. Software Research Associates
- * makes no representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
- * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Erik M. van der Poel
- * Software Research Associates, Inc., Tokyo, Japan
- * erik@sra.co.jp
- */
-
-#include <X11/Intrinsic.h>
-#include <X11/StringDefs.h>
-#include <X11/Xos.h>
-#include <X11/Xaw/Text.h>
-#include <X11/Xaw/AsciiText.h>
-
-#define SEL_FILE_CANCEL -1
-#define SEL_FILE_OK 0
-#define SEL_FILE_NULL 1
-#define SEL_FILE_TEXT 2
-
-#define SF_DO_SCROLL 1
-#define SF_DO_NOT_SCROLL 0
-
-#define NR 3 /* [HGM] (so far failed) attempt to suppress some of the director listings */
-
-typedef struct {
- int statDone;
- char *real;
- char *shown;
-} SFEntry;
-
-typedef struct {
- char *dir;
- char *path;
- SFEntry *entries;
- int nEntries;
- int vOrigin;
- int nChars;
- int hOrigin;
- int changed;
- int beginSelection;
- int endSelection;
- time_t mtime;
-} SFDir;
-
-extern int SFstatus;
-
-extern char SFcurrentPath[], SFstartDir[], SFcurrentDir[];
-
-extern Widget
- selFile,
- selFileCancel,
- selFileField,
- filterField,
- selFileForm,
- selFileHScroll,
- selFileHScrolls[],
- selFileLists[],
- selFileOK,
- selFilePrompt,
- selFileVScrolls[];
-
-extern Display *SFdisplay;
-
-extern int SFcharWidth, SFcharHeight, SFcharAscent;
-
-extern SFDir *SFdirs;
-
-extern int SFdirEnd, SFdirPtr;
-
-extern Pixel SFfore, SFback;
-
-extern Atom SFwmDeleteWindow;
-
-extern XSegment SFsegs[], SFcompletionSegs[];
-
-extern XawTextPosition SFtextPos;
-
-extern void
- SFenterList(),
- SFleaveList(),
- SFmotionList(),
- SFbuttonPressList(),
- SFbuttonReleaseList();
-
-extern void
- SFvSliderMovedCallback(),
- SFvFloatSliderMovedCallback(),
- SFhSliderMovedCallback(),
- SFpathSliderMovedCallback(),
- SFvAreaSelectedCallback(),
- SFhAreaSelectedCallback(),
- SFpathAreaSelectedCallback();
-
-extern int SFupperX, SFlowerY, SFupperY;
-
-extern int SFtextX, SFtextYoffset;
-
-extern int SFentryWidth, SFentryHeight;
-
-extern int SFlineToTextH, SFlineToTextV;
-
-extern int SFbesideText, SFaboveAndBelowText;
-
-extern int SFcharsPerEntry;
-
-extern int SFlistSize;
-
-extern int SFcurrentInvert[];
-
-extern int SFworkProcAdded;
-
-extern Boolean SFworkProc();
-
-extern XtAppContext SFapp;
-
-extern int SFpathScrollWidth, SFvScrollHeight, SFhScrollWidth;
-
-extern char SFfilterBuffer[];
-
-extern int SFbuttonPressed;
-
-extern int SFcompareEntries();
-
-extern void SFdirModTimer();
-
-extern char SFstatChar();
-
-extern XtIntervalId SFdirModTimerId;
-
-extern int (*SFfunc)();
-
-extern Boolean SFpathFlag; // [HGM]
-
-/* added missing prototypes */
-char SFstatChar(struct stat *);
-int SFchdir(char *);
-void SFvSliderMovedCallback(Widget, int, int);
-void SFdrawList(int,int);
-void SFdrawLists(int);
-void SFinitFont();
-void SFcreateGC();
-void SFupdatePath();
-void SFsetText(char *);
-void SFtextChanged();
-int SFgetDir(SFDir *);
-void SFclearList(int, int);
-void SFmotionList(Widget, int, XMotionEvent*);
-
-
-
+++ /dev/null
-#include <sys/stat.h>
-#if !defined(S_ISDIR) && defined(S_IFDIR)
-#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
-#endif
-#if !defined(S_ISREG) && defined(S_IFREG)
-#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
-#endif
-#if !defined(S_ISSOCK) && defined(S_IFSOCK)
-#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
-#endif
-
-#ifndef S_IXUSR
-#define S_IXUSR 0100
-#endif
-#ifndef S_IXGRP
-#define S_IXGRP 0010
-#endif
-#ifndef S_IXOTH
-#define S_IXOTH 0001
-#endif
-
-#define S_ISXXX(m) ((m) & (S_IXUSR | S_IXGRP | S_IXOTH))
-
fileOpenMode = openMode; /* to use globals here */
{ // [HGM] use file-selector dialog stolen from Ghostview
int index; // this is not supported yet
- if(openFP = XsraSelFile(shellWidget, label, NULL, NULL, _("could not open: "),
- (def[0] ? def : NULL), filter, openMode, NULL, &openName))
- // [HGM] delay to give expose event opportunity to redraw board after browser-dialog popdown before lengthy load starts
- ScheduleDelayedEvent(&DelayedLoad, 50);
+ Browse(BoardWindow, label, (def[0] ? def : NULL), filter, False, openMode, &openName, &openFP);
}
}
void WheelProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
void TabProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
void GenericMenu P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
-FILE * XsraSelFile P((Widget w, char *prompt, char *ok, char *cancel, char *failed,
- char *init_path, char *filter, char *mode, int (*show_entry)(), char **name_return));
// from xengineoutput.c
extern char memoTranslations[];
//--------------------------- Engine-specific options menu ----------------------------------
int dialogError;
-static Boolean browserUp;
Option *dialogOptions[NrOfDialogs];
static Arg layoutArgs[] = {
for(r = ""; *q; q++) if(*q == '.') r = q; else if(*q == '/') r = ""; // last dot after last slash
if(!strcmp(r, "") && !currentCps && opt->type == FileName && opt->textValue)
r = opt->textValue;
- browserUp = True;
- if(XsraSelFile(shells[TransientDlg], opt->name, NULL, NULL, "", "", r,
- opt->type == PathName ? "p" : "f", NULL, &p)) {
- int len = strlen(p);
- if(len && p[len-1] == '/') p[len-1] = NULLCHAR;
- XtSetArg(args[0], XtNstring, p);
- XtSetValues(opt->handle, args, 1);
- }
- browserUp = False;
- SetFocus(opt->handle, shells[TransientDlg], (XEvent*) NULL, False);
+ Browse(data>>8, opt->name, NULL, r, opt->type == PathName, "", &p, (FILE**) opt);
return;
} else
if (strcmp(name, "+") == 0) {
values[i] = j; // store selected value in Option struct, for retrieval at OK
- if(opt[i].type == Graph || opt[i].min & COMBO_CALLBACK && !currentCps) {
+ if(opt[i].type == Graph || opt[i].min & COMBO_CALLBACK && (!currentCps || shellUp[BrowserDlg])) {
((ButtonCallback*) opt[i].target)(i);
return;
}
return shells[n] != NULL;
}
+void
+RaiseWindow (DialogClass dlg)
+{
+ static XEvent xev;
+ Window root = RootWindow(xDisplay, DefaultScreen(xDisplay));
+ Atom atom = XInternAtom (xDisplay, "_NET_ACTIVE_WINDOW", False);
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.serial = 0;
+ xev.xclient.send_event = True;
+ xev.xclient.display = xDisplay;
+ xev.xclient.window = XtWindow(shells[dlg]);
+ xev.xclient.message_type = atom;
+ xev.xclient.format = 32;
+ xev.xclient.data.l[0] = 1;
+ xev.xclient.data.l[1] = CurrentTime;
+
+ XSendEvent (xDisplay,
+ root, False,
+ SubstructureRedirectMask | SubstructureNotifyMask,
+ &xev);
+
+ XFlush(xDisplay);
+ XSync(xDisplay, False);
+}
+
int
PopDown (DialogClass n)
{ // pops down any dialog created by GenericPopUp (or returns False if it wasn't up), unmarks any associated marked menu
MarkMenuItem(marked[n], False);
marked[n] = NULL;
}
- if(!n) currentCps = NULL; // if an Engine Settings dialog was up, we must be popping it down now
+ if(!n && n != BrowserDlg) currentCps = NULL; // if an Engine Settings dialog was up, we must be popping it down now
currentOption = dialogOptions[TransientDlg]; // just in case a transient dialog was up (to allow its check and combo callbacks to work)
- XtSetKeyboardFocus(shells[parents[n]], n == BoardWindow ? formWidget: shells[parents[n]]);
+ RaiseWindow(parents[n]);
+ if(parents[n] == BoardWindow) XtSetKeyboardFocus(shellWidget, formWidget);
return 1;
}
{ // to cause popdown through a translation (Delete Window button!)
int dlg = atoi(prms[0]);
Widget sh = shells[dlg];
- if(browserUp || dialogError) return; // prevent closing dialog when it has an open file-browse daughter
+ if(shellUp[BrowserDlg] && dlg != BrowserDlg || dialogError) return; // prevent closing dialog when it has an open file-browse daughter
shells[dlg] = w;
PopDown(dlg);
shells[dlg] = sh; // restore
if(GenericReadout(currentOption, -1)) PopDown(dlg); // calls OK-proc after full readout, but no popdown if it returns false
} else
- if(currentCps) {
+ if(currentCps && dlg != BrowserDlg) {
XtSetArg(args[0], XtNlabel, &name);
XtGetValues(w, args, 1);
if(currentOption[data].type == SaveButton) GenericReadout(currentOption, -1);
int x, y, i, j, height=999, width=1, h, c, w, shrink=FALSE, stack = 0, box, chain;
int win_x, win_y, maxWidth, maxTextWidth;
unsigned int mask;
- char def[MSG_SIZ], *msg;
+ char def[MSG_SIZ], *msg, engineDlg = (currentCps != NULL && dlgNr != BrowserDlg);
static char pane[6] = "paneX";
Widget texts[100], forelast = NULL, anchor, widest, lastrow = NULL, browse = NULL;
Dimension bWidth = 50, m;
// WARNING: this kludge does not work for persistent dialogs, so that these cannot have spin or combo controls!
currentOption = option;
- if(currentCps) { // Settings popup for engine: format through heuristic
+ if(engineDlg) { // Settings popup for engine: format through heuristic
int n = currentCps->nrOptions;
if(!n) { DisplayNote(_("Engine has no options")); currentCps = NULL; return 0; }
if(n > 50) width = 4; else if(n>24) width = 2; else width = 1;
option[i].value = *(float*)option[i].target;
goto tBox;
case Spin:
- if(!currentCps) option[i].value = *(int*)option[i].target;
+ if(!engineDlg) option[i].value = *(int*)option[i].target;
snprintf(def, MSG_SIZ, "%d", option[i].value);
case TextBox:
case FileName:
XtSetArg(args[j], XtNresizable, True); j++;
XtSetArg(args[j], XtNinsertPosition, 9999); j++;
XtSetArg(args[j], XtNstring, option[i].type==Spin || option[i].type==Fractional ? def :
- currentCps ? option[i].textValue : *(char**)option[i].target); j++;
+ engineDlg ? option[i].textValue : *(char**)option[i].target); j++;
edit = last;
option[i].handle = (void*)
(textField = last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j));
XtAddCallback(last, XtNcallback, SpinCallback, (XtPointer)(intptr_t) i + 256*dlgNr);
break;
case CheckBox:
- if(!currentCps) option[i].value = *(Boolean*)option[i].target; // where checkbox callback uses it
+ if(!engineDlg) option[i].value = *(Boolean*)option[i].target; // where checkbox callback uses it
j = SetPositionAndSize(args, last, lastrow, 1 /* border */,
textHeight/2 /* w */, textHeight/2 /* h */, 0xC0 /* chain both to left edge */);
XtSetArg(args[j], XtNvertDistance, (textHeight+2)/4 + 3); j++;
}
option[i].handle = (void*)
(dialog = last = XtCreateManagedWidget(option[i].name, commandWidgetClass, form, args, j));
- if(option[i].choice && ((char*)option[i].choice)[0] == '#' && !currentCps) { // for the color picker default-reset
+ if(option[i].choice && ((char*)option[i].choice)[0] == '#' && !engineDlg) { // for the color picker default-reset
SetColor( *(char**) option[i-1].target, &option[i]);
XtAddEventHandler(option[i-1].handle, KeyReleaseMask, False, ColorChanged, (XtPointer)(intptr_t) i-1);
}
texts[h] = dialog = XtCreateManagedWidget(option[i].name, labelWidgetClass, form, args, j);
if(option[i].min & COMBO_CALLBACK) msg = _(option[i].name); else {
- if(!currentCps) SetCurrentComboSelection(option+i);
+ if(!engineDlg) SetCurrentComboSelection(option+i);
msg=_(((char**)option[i].choice)[option[i].value]);
}
j = SetPositionAndSize(args, dialog, last, (option[i].min & 2) == 0 /* border */,
- option[i].max && !currentCps ? option[i].max : 100 /* w */,
+ option[i].max && !engineDlg ? option[i].max : 100 /* w */,
textHeight /* h */, 0x91 /* chain */); // same row as its label!
XtSetArg(args[j], XtNmenuName, XtNewString(option[i].name)); j++;
XtSetArg(args[j], XtNlabel, msg); j++;
XtSetArg(args[j], XtNy, (Position) (wp[dlgNr]->y)); j++;
XtSetValues(popup, args, j);
}
+ RaiseWindow(dlgNr);
return 1; // tells caller he must do initialization (e.g. add specific event handlers)
}