Fix some compile errors / warnings
[xboard.git] / dialogs.c
index 12b668a..93e817a 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -1454,13 +1454,13 @@ static int count;
 static void PromoPick P((int n));
 
 static Option promoOptions[] = {
-{   0,         0,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
-{   0,  SAME_ROW,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
-{   0,  SAME_ROW,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
-{   0,  SAME_ROW,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
-{   0,  SAME_ROW,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
-{   0,  SAME_ROW,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
-{   0,  SAME_ROW,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, "" },
+{   0,         0,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, NULL },
+{   0,  SAME_ROW,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, NULL },
+{   0,  SAME_ROW,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, NULL },
+{   0,  SAME_ROW,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, NULL },
+{   0,  SAME_ROW,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, NULL },
+{   0,  SAME_ROW,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, NULL },
+{   0,  SAME_ROW,    0, NULL, (void*) &PromoPick, NULL, NULL, Button, NULL },
 {   0, SAME_ROW | NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" }
 };
 
@@ -1489,8 +1489,9 @@ PromoPick (int n)
 static void
 SetPromo (char *name, int nr, char promoChar)
 {
-    safeStrCpy(promoOptions[nr].name, name, MSG_SIZ);
+    ASSIGN(promoOptions[nr].name, name);
     promoOptions[nr].value = promoChar;
+    promoOptions[nr].min = SAME_ROW;
 }
 
 void
@@ -1526,6 +1527,7 @@ PromotionPopUp ()
       SetPromo(_("Defer"), --count, '=');
       SetPromo(_("Promote"), --count, '+');
   }
+  promoOptions[count].min = 0;
   GenericPopUp(promoOptions + count, "Promotion", PromoDlg, BoardWindow, NONMODAL, 0);
 }
 
@@ -1838,15 +1840,15 @@ static void
 PMSelect (int n)
 {   // user callback for board context menus
     if (pmFromX < 0 || pmFromY < 0) return;
-    if(n == 25) DropMenuEvent(dropMenuTranslation[values[n]], pmFromX, pmFromY);
-    else EditPositionMenuEvent(pieceMenuTranslation[n-23][values[n]], pmFromX, pmFromY);
+    if(n == W_DROP) DropMenuEvent(dropMenuTranslation[values[n]], pmFromX, pmFromY);
+    else EditPositionMenuEvent(pieceMenuTranslation[n - W_MENUW][values[n]], pmFromX, pmFromY);
 }
 
-int
+static void
 CCB (int n)
 {
     shiftKey = (ShiftKeys() & 3) != 0;
-    ClockClick(n == 12);
+    ClockClick(n == W_BLACK);
 }
 
 Option mainOptions[] = { // description of main window in terms of generic dialog creator
@@ -1884,9 +1886,9 @@ SizeKludge (int n)
 {   // callback called by GenericPopUp immediately after sizing the menu bar
     int width = BOARD_WIDTH*(squareSize + lineGap) + lineGap;
     int w = width - 44 - mainOptions[n].min;
-    mainOptions[10].max = w; // width left behind menu bar
+    mainOptions[W_TITLE].max = w; // width left behind menu bar
     if(w < 0.4*width) // if no reasonable amount of space for title, force small layout
-       mainOptions[13].type = mainOptions[10].type, mainOptions[10].type = -1; 
+       mainOptions[W_SMALL].type = mainOptions[W_TITLE].type, mainOptions[W_TITLE].type = -1; 
 }
 
 void
@@ -1909,6 +1911,7 @@ Exp (int n, int x, int y)
        if(but3) MovePV(x, y, lineGap + BOARD_HEIGHT * (squareSize + lineGap));
        return NULL;
     }
+    if(n != 10 && PopDown(PromoDlg)) fromX = fromY = -1; // user starts fiddling with board when promotion dialog is up
     shiftKey = ShiftKeys();
     controlKey = (shiftKey & 0xC) != 0;
     shiftKey = (shiftKey & 3) != 0;
@@ -1926,8 +1929,8 @@ Exp (int n, int x, int y)
     }
 
     switch(menuNr) {
-      case 0: return &mainOptions[shiftKey ? 23: 24];
-      case 1: SetupDropMenu(); return &mainOptions[25];
+      case 0: return &mainOptions[shiftKey ? W_MENUW: W_MENUB];
+      case 1: SetupDropMenu(); return &mainOptions[W_DROP];
       case 2:
       case -1: ErrorPopDown();
       case -2:
@@ -1941,16 +1944,16 @@ BoardPopUp (int squareSize, int lineGap, void *clockFontThingy)
 {
     extern Option *dialogOptions[];
     int i, size = BOARD_WIDTH*(squareSize + lineGap) + lineGap;
-    mainOptions[11].choice = (char**) clockFontThingy;
-    mainOptions[12].choice = (char**) clockFontThingy;
-    mainOptions[22].value = BOARD_HEIGHT*(squareSize + lineGap) + lineGap;
-    mainOptions[22].max = mainOptions[13].max = size; // board size
-    mainOptions[13].max = size - 2; // board title (subtract border!)
-    mainOptions[12].max = mainOptions[11].max = size/2-3; // clock width
-    mainOptions[14].max = appData.showButtonBar ? size-130 : size-2; // message
-    mainOptions[0].max = size-40; // menu bar
-    mainOptions[10].type = appData.titleInWindow ? Label : -1 ;
-    if(!appData.showButtonBar) for(i=15; i<22; i++) mainOptions[i].type = -1;
+    mainOptions[W_WHITE].choice = (char**) clockFontThingy;
+    mainOptions[W_BLACK].choice = (char**) clockFontThingy;
+    mainOptions[W_BOARD].value = BOARD_HEIGHT*(squareSize + lineGap) + lineGap;
+    mainOptions[W_BOARD].max = mainOptions[W_SMALL].max = size; // board size
+    mainOptions[W_SMALL].max = size - 2; // board title (subtract border!)
+    mainOptions[W_BLACK].max = mainOptions[W_WHITE].max = size/2-3; // clock width
+    mainOptions[W_MESSG].max = appData.showButtonBar ? size-130 : size-2; // message
+    mainOptions[W_MENU].max = size-40; // menu bar
+    mainOptions[W_TITLE].type = appData.titleInWindow ? Label : -1 ;
+    if(!appData.showButtonBar) for(i=W_BUTTON; i<W_BOARD; i++) mainOptions[i].type = -1;
     for(i=0; i<8; i++) mainOptions[i+1].choice = (char**) menuBar[i].mi;
     GenericPopUp(mainOptions, "XBoard", BoardWindow, BoardWindow, NONMODAL, 1);
     return mainOptions;
@@ -1979,11 +1982,11 @@ void
 SlavePopUp ()
 {
     // copy params from main board
-    dualOptions[0].choice = mainOptions[11].choice;
-    dualOptions[1].choice = mainOptions[12].choice;
-    dualOptions[3].value = mainOptions[22].value;
-    dualOptions[3].max = dualOptions[2].max = mainOptions[22].max; // board size
-    dualOptions[0].max = dualOptions[1].max = mainOptions[11].max; // clock width
+    dualOptions[0].choice = mainOptions[W_WHITE].choice;
+    dualOptions[1].choice = mainOptions[W_BLACK].choice;
+    dualOptions[3].value = mainOptions[W_BOARD].value;
+    dualOptions[3].max = dualOptions[2].max = mainOptions[W_BOARD].max; // board size
+    dualOptions[0].max = dualOptions[1].max = mainOptions[W_WHITE].max; // clock width
     GenericPopUp(dualOptions, "XBoard", DummyDlg, BoardWindow, NONMODAL, 1);
 }
 
@@ -1995,7 +1998,7 @@ DisplayWhiteClock (long timeRemaining, int highlight)
        DisplayTimerLabel(&dualOptions[0], _("White"), timeRemaining, highlight);
        return;
     }
-    DisplayTimerLabel(&mainOptions[11], _("White"), timeRemaining, highlight);
+    DisplayTimerLabel(&mainOptions[W_WHITE], _("White"), timeRemaining, highlight);
     if(highlight) SetClockIcon(0);
 }
 
@@ -2007,7 +2010,7 @@ DisplayBlackClock (long timeRemaining, int highlight)
        DisplayTimerLabel(&dualOptions[1], _("Black"), timeRemaining, highlight);
        return;
     }
-    DisplayTimerLabel(&mainOptions[12], _("Black"), timeRemaining, highlight);
+    DisplayTimerLabel(&mainOptions[W_BLACK], _("Black"), timeRemaining, highlight);
     if(highlight) SetClockIcon(1);
 }
 
@@ -2039,8 +2042,8 @@ DisplayMessage (char *message, char *extMessage)
   /* need to test if messageWidget already exists, since this function
      can also be called during the startup, if for example a Xresource
      is not set up correctly */
-  if(mainOptions[14].handle)
-    SetWidgetLabel(&mainOptions[14], message);
+  if(mainOptions[W_MESSG].handle)
+    SetWidgetLabel(&mainOptions[W_MESSG], message);
 
   return;
 }
@@ -2067,6 +2070,7 @@ static char *FileTypes[] = {
 "Chess Positions",
 "Tournaments",
 "Opening Books",
+"Sound files",
 "Settings (*.ini)",
 "Log files",
 "All files",
@@ -2084,6 +2088,7 @@ static char *Extensions[] = {
 ".fen .epd .pos",
 ".trn",
 ".bin",
+".wav",
 ".ini",
 ".log",
 "",
@@ -2101,6 +2106,7 @@ void FileSelProc P((int n, int sel));
 void SetTypeFilter P((int n));
 int BrowseOK P((int n));
 void Switch P((int n));
+void CreateDir P((int n));
 
 Option browseOptions[] = {
 {   0,    LR|T2T,      500, NULL, NULL, NULL, NULL, Label, title },
@@ -2110,7 +2116,8 @@ Option browseOptions[] = {
 {   0, R2R|TT|SAME_ROW, 70, NULL, (void*) &Switch, NULL, NULL, Button, N_("by type") },
 { 300,    L2L|TB,      250, NULL, (void*) folderList, (char*) &DirSelProc, NULL, ListBox, "" },
 { 300, R2R|TB|SAME_ROW,250, NULL, (void*) fileList, (char*) &FileSelProc, NULL, ListBox, "" },
-{   0,       0,        350, NULL, (void*) &fileName, NULL, NULL, TextBox, N_("Filename:") },
+{   0,       0,        300, NULL, (void*) &fileName, NULL, NULL, TextBox, N_("Filename:") },
+{   0,    SAME_ROW,    120, NULL, (void*) &CreateDir, NULL, NULL, Button, N_("New directory") },
 {   0, COMBO_CALLBACK, 150, NULL, (void*) &SetTypeFilter, NULL, FileTypes, ComboBox, N_("File type:") },
 {   0,    SAME_ROW,      0, NULL, (void*) &BrowseOK, "", NULL, EndMark , "" }
 };
@@ -2228,6 +2235,21 @@ Refresh (int pathFlag)
     ListDir(pathFlag); // and make new one
     LoadListBox(&browseOptions[5], "");
     LoadListBox(&browseOptions[6], "");
+    SetWidgetLabel(&browseOptions[0], title);
+}
+
+void
+CreateDir (int n)
+{
+    char *name, *errmsg = "";
+    GetWidgetText(&browseOptions[n-1], &name);
+    if(!name[0]) errmsg = _("FIRST TYPE DIRECTORY NAME HERE"); else
+    if(mkdir(name, 0755)) errmsg = _("TRY ANOTHER NAME");
+    else {
+       chdir(name);
+       Refresh(-1);
+    }
+    SetWidgetText(&browseOptions[n-1], errmsg, BrowserDlg);
 }
 
 void
@@ -2256,27 +2278,25 @@ 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 *
+void
 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
+    savFP = fp; savMode = mode, namePtr = name, savCps = currentCps, oldVal = values[9]; // 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[9].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]);
+    GenericPopUp(browseOptions, label, BrowserDlg, dlg, MODAL, 0);
+    SetWidgetLabel(&browseOptions[9], FileTypes[j]);
 }