Solve WinBoard name clashes, fix zippy-analyze menu graying
[xboard.git] / dialogs.c
index 07eba9b..e0d1c4e 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -103,45 +103,47 @@ SetCurrentComboSelection (Option *opt)
 void
 GenericUpdate (Option *opts, int selected)
 {
-    int i, j;
+    int i;
     char buf[MSG_SIZ];
-    float x;
-       for(i=0; ; i++) {
-           if(selected >= 0) { if(i < selected) continue; else if(i > selected) break; }
-           switch(opts[i].type) {
-               case TextBox:
-               case FileName:
-               case PathName:
-                   SetWidgetText(&opts[i],  *(char**) opts[i].target, -1);
-                   break;
-               case Spin:
-                   sprintf(buf, "%d", *(int*) opts[i].target);
-                   SetWidgetText(&opts[i], buf, -1);
-                   break;
-               case Fractional:
-                   sprintf(buf, "%4.2f", *(float*) opts[i].target);
-                   SetWidgetText(&opts[i], buf, -1);
-                   break;
-               case CheckBox:
-                   SetWidgetState(&opts[i],  *(Boolean*) opts[i].target);
-                   break;
-               case ComboBox:
-                 if(opts[i].min & COMBO_CALLBACK) break;
-                 SetCurrentComboSelection(opts+i);
-                   // TODO: actually display this (but it is never used that way...)
-                   break;
-               case EndMark:
-                   return;
-           default:
-               printf("GenericUpdate: unexpected case in switch.\n");
-               case ListBox:
-               case Button:
-               case SaveButton:
-               case Label:
-               case Break:
-             break;
-           }
-       }
+
+    for(i=0; ; i++)
+      {
+       if(selected >= 0) { if(i < selected) continue; else if(i > selected) break; }
+       switch(opts[i].type)
+         {
+         case TextBox:
+         case FileName:
+         case PathName:
+           SetWidgetText(&opts[i],  *(char**) opts[i].target, -1);
+           break;
+         case Spin:
+           sprintf(buf, "%d", *(int*) opts[i].target);
+           SetWidgetText(&opts[i], buf, -1);
+           break;
+         case Fractional:
+           sprintf(buf, "%4.2f", *(float*) opts[i].target);
+           SetWidgetText(&opts[i], buf, -1);
+           break;
+         case CheckBox:
+           SetWidgetState(&opts[i],  *(Boolean*) opts[i].target);
+           break;
+         case ComboBox:
+           if(opts[i].min & COMBO_CALLBACK) break;
+           SetCurrentComboSelection(opts+i);
+           // TODO: actually display this (but it is never used that way...)
+           break;
+         case EndMark:
+           return;
+         default:
+           printf("GenericUpdate: unexpected case in switch.\n");
+         case ListBox:
+         case Button:
+         case SaveButton:
+         case Label:
+         case Break:
+           break;
+         }
+      }
 }
 
 //------------------------------------------- Read out dialog controls ------------------------------------
@@ -202,7 +204,7 @@ GenericReadout (Option *opts, int selected)
                    break;
                case ComboBox:
                    if(opts[i].min & COMBO_CALLBACK) break;
-                   if(!opts[i].textValue) { *(int*)opts[i].target == opts[i].value; break; } // numeric
+                   if(!opts[i].textValue) { *(int*)opts[i].target = values[i]; break; } // numeric
                    val = ((char**)opts[i].textValue)[values[i]];
                    if(currentCps) {
                        if(opts[i].value == values[i]) break; // not changed
@@ -734,7 +736,7 @@ static void
 Test (int n)
 {
     GenericReadout(soundOptions, 2);
-    if(soundFiles[values[3]]) PlaySound(soundFiles[values[3]]);
+    if(soundFiles[values[3]]) PlaySoundFile(soundFiles[values[3]]);
 }
 
 void
@@ -965,7 +967,6 @@ NewCommentPopup (char *title, char *text, int index)
 void
 EditCommentProc ()
 {
-    int j;
     if (PopDown(CommentDlg)) { // popdown succesful
 //     MarkMenuItem("Edit.EditComment", False);
 //     MarkMenuItem("View.Comments", False);
@@ -1077,7 +1078,7 @@ ICSInputSendText ()
     GetWidgetText(&boxOptions[0], &val);
     SaveInHistory(val);
     SendMultiLineToICS(val);
-    SetWidgetText(&boxOptions[0], val, InputBoxDlg);
+    SetWidgetText(&boxOptions[0], "", InputBoxDlg);
 }
 
 void
@@ -1319,11 +1320,6 @@ ShuffleMenuProc ()
 static int TcOK P((int n));
 int tmpMoves, tmpTc, tmpInc, tmpOdds1, tmpOdds2, tcType;
 
-static void
-ShowTC (int n)
-{
-}
-
 static void SetTcType P((int n));
 
 static char *
@@ -1944,7 +1940,6 @@ Exp (int n, int x, int y)
 Option *
 BoardPopUp (int squareSize, int lineGap, void *clockFontThingy)
 {
-    extern Option *dialogOptions[];
     int i, size = BOARD_WIDTH*(squareSize + lineGap) + lineGap;
     mainOptions[W_WHITE].choice = (char**) clockFontThingy;
     mainOptions[W_BLACK].choice = (char**) clockFontThingy;
@@ -2062,11 +2057,13 @@ DisplayMessage (char *message, char *extMessage)
 
 #include <sys/stat.h>
 
+#define MAXFILES 1000
+
 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 *fileName, *extFilter, *savMode, **namePtr;
+static int folderPtr, filePtr, oldVal, byExtension, extFlag, pageStart, cnt;
+static char curDir[MSG_SIZ], title[MSG_SIZ], *folderList[MAXFILES], *fileList[MAXFILES];
 
 static char *FileTypes[] = {
 "Chess Games",
@@ -2074,6 +2071,7 @@ static char *FileTypes[] = {
 "Tournaments",
 "Opening Books",
 "Sound files",
+"Images",
 "Settings (*.ini)",
 "Log files",
 "All files",
@@ -2092,6 +2090,7 @@ static char *Extensions[] = {
 ".trn",
 ".bin",
 ".wav",
+".xpm",
 ".ini",
 ".log",
 "",
@@ -2152,14 +2151,6 @@ BrowseOK (int n)
        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)
 {
@@ -2196,22 +2187,22 @@ ListDir (int pathFlag)
        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
+       folderPtr = filePtr = cnt = 0; // clear listing
 
        while (dp = readdir(dir)) { // pass 1: list foders
-           char *s = dp->d_name, match;
+           char *s = dp->d_name;
            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++;
+               ASSIGN(folderList[folderPtr], s); if(folderPtr < MAXFILES-2) folderPtr++;
            } else if(!pathFlag) {
                char *s = dp->d_name, match=0;
+//             if(cnt == pageStart) { ASSIGN }
                if(s[0] == '.') continue; // suppress hidden files
                if(extFilter[0]) { // [HGM] filter on extension
                    char *p = extFilter, *q;
@@ -2222,9 +2213,12 @@ ListDir (int pathFlag)
                    } while(q && (p = q+1));
                    if(!match) continue;
                }
+               if(filePtr == MAXFILES-2) continue;
+               if(cnt++ < pageStart) continue;
                ASSIGN(fileList[filePtr], s); filePtr++;
            }
        }
+       if(filePtr == MAXFILES-2) { ASSIGN(fileList[filePtr], _("\177 next page")); filePtr++; }
        FREE(folderList[folderPtr]); folderList[folderPtr] = NULL;
        FREE(fileList[filePtr]); fileList[filePtr] = NULL;
        closedir(dir);
@@ -2272,11 +2266,21 @@ SetTypeFilter (int n)
     browseOptions[n].value = j;
     SetWidgetLabel(&browseOptions[n], FileTypes[j]);
     ASSIGN(extFilter, Extensions[j]);
+    pageStart = 0;
     Refresh(-1); // uses pathflag remembered by ListDir
     values[n] = oldVal; // do not disturb combo settings of underlying dialog
 }
 
 void
+FileSelProc (int n, int sel)
+{
+    if(sel<0) return;
+    if(sel == MAXFILES-2) { pageStart = cnt; Refresh(-1); return; }
+    ASSIGN(fileName, fileList[sel]);
+    if(BrowseOK(0)) PopDown(BrowserDlg);
+}
+
+void
 DirSelProc (int n, int sel)
 {
     if(!chdir(folderList[sel])) { // cd succeeded, so we are in new directory now
@@ -2296,10 +2300,32 @@ Browse (DialogClass dlg, char *label, char *proposed, char *ext, Boolean pathFla
     if(Extensions[j] == NULL) { j++; ASSIGN(FileTypes[j], extFilter); }
     browseOptions[9].value = j;
     browseOptions[6].textValue = (char*) (pathFlag ? NULL : &FileSelProc); // disable file listbox during path browsing
-    ListDir(pathFlag);
+    pageStart = 0; ListDir(pathFlag);
     currentCps = NULL;
     GenericPopUp(browseOptions, label, BrowserDlg, dlg, MODAL, 0);
     SetWidgetLabel(&browseOptions[9], FileTypes[j]);
 }
 
+static char *openName;
+FileProc fileProc;
+char *fileOpenMode;
+FILE *openFP;
+
+void
+DelayedLoad ()
+{
+  (void) (*fileProc)(openFP, 0, openName);
+}
+
+void
+FileNamePopUp (char *label, char *def, char *filter, FileProc proc, char *openMode)
+{
+    fileProc = proc;           /* I can't see a way not */
+    fileOpenMode = openMode;   /*   to use globals here */
+    {   // [HGM] use file-selector dialog stolen from Ghostview
+       // int index; // this is not supported yet
+       Browse(BoardWindow, label, (def[0] ? def : NULL), filter, False, openMode, &openName, &openFP);
+    }
+}
+