Allow grouping of engines in engine list
[xboard.git] / winboard / wsettings.c
index 83472f5..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
@@ -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
@@ -751,7 +770,7 @@ Option tourneyOptions[] = {
   { 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
@@ -779,25 +798,34 @@ Option tourneyOptions[] = {
 \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