Allow grouping of engines in engine list
[xboard.git] / winboard / wsettings.c
index 6fc5c40..10bb427 100644 (file)
@@ -366,7 +366,7 @@ GetOptionValues(HWND hDlg, ChessProgramState *cps, Option *optionList)
                if(!cps) {\r
                    char *p;\r
                    p = (optionList[j].type != FileName ? strdup(text) : InterpretFileName(text, homeDir)); // all files relative to homeDir!\r
-                   FREE(*(char**)optionList[j].target); *(char**)optionList[j].target = p;
+                   FREE(*(char**)optionList[j].target); *(char**)optionList[j].target = p;\r
                    free(text); text = p;\r
                    while(*p++ = *text++) if(p[-1] == '\r') p--; // crush CR\r
                    break;\r
@@ -389,7 +389,7 @@ GetOptionValues(HWND hDlg, ChessProgramState *cps, Option *optionList)
                for(k=0; k<optionList[j].max; k++) {\r
                    if(!strcmp(choices[k], newText)) new = k;\r
                }\r
-               if(!cps && new) {\r
+               if(!cps && new > 0) {\r
                    if(*(char**)optionList[j].target) free(*(char**)optionList[j].target);\r
                    *(char**)optionList[j].target = strdup(optionList[j].choice[new]);\r
                    break;\r
@@ -480,6 +480,7 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
                }\r
                if(j < 0) break;\r
                if(comboCallback && activeList[j].type == ComboBox && HIWORD(wParam) == CBN_SELCHANGE) {\r
+                   if(j > 5) break; // Yegh! Must solve problem with more than one ombobox in dialog\r
                    (*comboCallback)(hDlg);\r
                    break;\r
                } else\r
@@ -628,6 +629,7 @@ EngineOptionsPopup(HWND hwnd, ChessProgramState *cps)
 \r
 int InstallOK()\r
 {\r
+    if(engineLine[0] == '#') { DisplayError(_("Select single engine from the group"), 0); return 0; }\r
     if(isUCCI) isUCI = 2;\r
     if(engineChoice[0] == engineNr[0][0])  Load(&first, 0); else Load(&second, 1);\r
     return 1;\r
@@ -670,10 +672,27 @@ GenericPopup(HWND hwnd, Option *optionList)
     return;\r
 }\r
 \r
-void LoadEnginePopUp(HWND hwnd)\r
+int\r
+EnterGroup(HWND hDlg)\r
 {\r
-    int n=0;\r
+    char buf[MSG_SIZ];\r
+    HANDLE hwndCombo = GetDlgItem(hDlg, 2001+2*1);\r
+    int i = ComboBox_GetCurSel(hwndCombo);\r
+    if(i == 0) buf[0] = NULLCHAR; // back to top level\r
+    else if(engineList[i][0] == '#') safeStrCpy(buf, engineList[i], MSG_SIZ); // group header, open group\r
+    else return 0; // normal line, select engine\r
+    installOptions[0].max = NamesToList(firstChessProgramNames, engineList, engineMnemonic, buf); // replace list by only the group contents\r
+    SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);\r
+    SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) buf);\r
+    for(i=1; i<installOptions[0].max; i++) {\r
+           SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) engineMnemonic[i]);\r
+    }\r
+    SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) 0, (LPARAM) buf);\r
+    return 0;\r
+}\r
 \r
+void LoadEnginePopUp(HWND hwnd)\r
+{\r
     isUCI = isUCCI = storeVariant = v1 = useNick = FALSE; addToList = hasBook = TRUE; // defaults\r
     if(engineDir)    free(engineDir);    engineDir = strdup("");\r
     if(params)       free(params);       params = strdup("");\r
@@ -681,9 +700,9 @@ void LoadEnginePopUp(HWND hwnd)
     if(engineChoice) free(engineChoice); engineChoice = strdup(engineNr[0]);\r
     if(engineLine)   free(engineLine);   engineLine = strdup("");\r
     if(engineName)   free(engineName);   engineName = strdup("");\r
-    NamesToList(firstChessProgramNames, engineList, engineMnemonic);\r
-    while(engineList[n]) n++; installOptions[0].max = n;\r
+    installOptions[0].max = NamesToList(firstChessProgramNames, engineList, engineMnemonic, ""); // only top level\r
     snprintf(title, MSG_SIZ, _("Load Engine"));\r
+    comboCallback = &EnterGroup;\r
 \r
     GenericPopup(hwnd, installOptions);\r
 }\r
@@ -727,11 +746,31 @@ void UpgradeParticipant(HWND hDlg)
     Substitute(participants, FALSE);\r
 }\r
 \r
+void Inspect(HWND hDlg)\r
+{\r
+    FILE *f;\r
+    char name[MSG_SIZ];\r
+    GetDlgItemText(hDlg, 2001+2*1, name, MSG_SIZ );\r
+    if(name && name[0] && (f = fopen(name, "r")) ) {\r
+       char *saveSaveFile;\r
+       saveSaveFile = appData.saveGameFile; appData.saveGameFile = NULL; // this is a persistent option, protect from change\r
+       ParseArgsFromFile(f);\r
+       autoinc = ((appData.loadPositionFile[0] ? appData.loadGameIndex : appData.loadPositionIndex) < 0);\r
+       twice = ((appData.loadPositionFile[0] ? appData.loadGameIndex : appData.loadPositionIndex) == -2);\r
+       swiss = appData.tourneyType < 0;\r
+       SetOptionValues(hDlg, NULL, activeList);\r
+       FREE(appData.saveGameFile); appData.saveGameFile = saveSaveFile;\r
+    } else DisplayError(_("First you must specify an existing tourney file to clone"), 0);\r
+}\r
+\r
+void TimeControlOptionsPopup P((HWND hDlg));\r
+void UciOptionsPopup P((HWND hDlg));\r
+\r
 Option tourneyOptions[] = {\r
   { 0,  0,          4, NULL, (void*) &tfName, "", NULL, FileName, N_("Tournament file:") },\r
   { 30, 0,          0, NULL, NULL, NULL, NULL, Label, N_("If you specify an existing file, the rest of this dialog will be ignored.") },\r
   { 30, 0,          0, NULL, NULL, NULL, NULL, Label, N_("Otherwise, the file will be created, with the settings you specify below:") },\r
-  { 0,  1,          0, NULL, (void*) &engineChoice, (char*) (engineMnemonic+1), (engineMnemonic+1), ComboBox, N_("Select Engine:") },\r
+  { 0,  1,          0, NULL, (void*) &engineChoice, (char*) engineMnemonic, engineMnemonic, ComboBox, N_("Select Engine:") },\r
   { 0xD, 7,         0, NULL, (void*) &appData.participants, "", NULL, TextBox, N_("Tourney participants:") },\r
   { 0,  0,          0, NULL, (void*) &swiss, "", NULL, CheckBox, N_("Use Swiss pairing engine (cycles = rounds)") },\r
   { 0,  0,         10, NULL, (void*) &appData.tourneyType, "", NULL, Spin, N_("Tourney type (0=RR, 1=gauntlet):") },\r
@@ -747,33 +786,46 @@ Option tourneyOptions[] = {
   { 0,  0,          0, NULL, (void*) &autoinc, "", NULL, CheckBox, N_("Step through lines/positions in file") },\r
   { 0,  0, 1000000000, NULL, (void*) &appData.rewindIndex, "", NULL, Spin, N_("Rewind after (0 = never):") },\r
   { 0,  0,          0, NULL, (void*) &twice, "", NULL, CheckBox, N_("Use each line/position twice") },\r
+  { 0,  0,          0, NULL, (void*) &appData.defNoBook, "", NULL, CheckBox, N_("Make all use GUI book by default") },\r
   { 0,  0, 1000000000, NULL, (void*) &appData.matchPause, "", NULL, Spin, N_("Pause between Games (ms):") },\r
   { 0,  0,          0, NULL, (void*) &ReplaceParticipant, "", NULL, Button, N_("Replace Engine") },\r
   { 0,  0,          0, NULL, (void*) &UpgradeParticipant, "", NULL, Button, N_("Upgrade Engine") },\r
+  { 0,  0,          0, NULL, (void*) &TimeControlOptionsPopup, "", NULL, Button, N_("Time Control...") },\r
+  { 0,  0,          0, NULL, (void*) &UciOptionsPopup, "", NULL, Button, N_("Common Engine...") },\r
+  { 0,  0,          0, NULL, (void*) &Inspect, "", NULL, Button, N_("Clone Tourney") },\r
   { 0, 0, 0, NULL, (void*) &MatchOK, "", NULL, EndMark , "" }\r
 };\r
 \r
 int AddToTourney(HWND hDlg)\r
 {\r
-    char buf[MSG_SIZ];\r
-//    GetDlgItemText( hDlg, 2001+2*7, buf, MSG_SIZ-3 ); // this gives the previous selection !!!\r
-//    strncat(buf, "\r\n", MSG_SIZ);\r
-    int i = ComboBox_GetCurSel(GetDlgItem(hDlg, 2001+2*7));\r
-    snprintf(buf, MSG_SIZ, "%s\r\n", engineMnemonic[i+1]);\r
+  char buf[MSG_SIZ];\r
+  HANDLE hwndCombo = GetDlgItem(hDlg, 2001+2*7);\r
+  int i = ComboBox_GetCurSel(hwndCombo);\r
+  if(i == 0) buf[0] = NULLCHAR; // back to top level\r
+  else if(engineList[i][0] == '#') safeStrCpy(buf, engineList[i], MSG_SIZ); // group header, open group\r
+  else { // normal line, select engine\r
+    snprintf(buf, MSG_SIZ, "%s\r\n", engineMnemonic[i]);\r
     SendMessage( GetDlgItem(hDlg, 2001+2*9), EM_SETSEL, 99999, 99999 );\r
     SendMessage( GetDlgItem(hDlg, 2001+2*9), EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) buf );\r
     return 0;\r
+  }\r
+  installOptions[0].max = NamesToList(firstChessProgramNames, engineList, engineMnemonic, buf); // replace list by only the group contents\r
+  SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);\r
+  SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) buf);\r
+  for(i=1; i<installOptions[0].max; i++) {\r
+    SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) engineMnemonic[i]);\r
+  }\r
+  SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) 0, (LPARAM) buf);\r
+  return 0;\r
 }\r
 \r
 void TourneyPopup(HWND hwnd)\r
 {\r
-    int n=0;\r
-\r
-    NamesToList(firstChessProgramNames, engineList, engineMnemonic);\r
+    int n = NamesToList(firstChessProgramNames, engineList, engineMnemonic, "");\r
     comboCallback = &AddToTourney;\r
     autoinc = appData.loadGameIndex < 0 || appData.loadPositionIndex < 0;\r
     twice = FALSE; swiss = appData.tourneyType < 0;\r
-    while(engineList[n]) n++; tourneyOptions[3].max = n-1;\r
+    tourneyOptions[3].max = n;\r
     snprintf(title, MSG_SIZ, _("Tournament and Match Options"));\r
     ASSIGN(tfName, appData.tourneyFile[0] ? appData.tourneyFile : MakeName(appData.defName));\r
 \r