Activate -path and -file options
[xboard.git] / winboard / wsettings.c
index a250e2e..6298309 100644 (file)
@@ -1,7 +1,7 @@
 /*\r
  * Engine-settings dialog. The complexity come from an attempt to present the engine-defined options\r
  * in a nicey formatted layout. To this end we first run a back-end pre-formatter, which will distribute\r
- * the controls over two columns (the minimum required, as some are double width). It also takes care of \r
+ * the controls over two columns (the minimum required, as some are double width). It also takes care of\r
  * grouping options that start with the same word (mainly for "Polyglot ..." options). It assigns relative\r
  * suitability to break points between lines, and in the end decides if and where to break up the list\r
  * for display in multiple (2*N) columns.\r
@@ -59,6 +59,7 @@ PrintOpt(int i, int right, ChessProgramState *cps)
            case ResetButton:\r
                fprintf(debugFP, "[ %26.26s ]", opt.name);\r
            case Message:\r
+           default:\r
                break;\r
        }\r
     }\r
@@ -99,15 +100,16 @@ LayoutOptions(int firstOption, int endOption, char *groupName, Option *optionLis
                case PathName:\r
                case Slider:\r
                case Spin: stop++;\r
+               default:\r
                case Message: ; // cannot happen\r
            }\r
            nextOption++;\r
        }\r
        // We now must be at the end, or looking at a spin or textbox (in nextType)\r
-       if(!stop) \r
+       if(!stop)\r
            nextType = Button; // kudge to flush remaining checks and combos undistorted\r
        // Take a new line if a spin follows combos or checks, or when we encounter a textbox\r
-       if((combos+checks || nextType == TextBox) && layout&1) {\r
+       if((combos+checks || nextType == TextBox || nextType == FileName || nextType == PathName) && layout&1) {\r
            layoutList[layout++] = -1;\r
        }\r
        // The last check or combo before a spin will be put on the same line as that spin (prefix)\r
@@ -119,10 +121,10 @@ LayoutOptions(int firstOption, int endOption, char *groupName, Option *optionLis
        }\r
        // if a combo is followed by a textbox, it must stay at the end of the combo/checks list to appear\r
        // immediately above the textbox, so treat it as check. (A check would automatically be and remain there.)\r
-       if(nextType == TextBox && lastType == ComboBox)\r
+       if((nextType == TextBox || nextType == FileName || nextType == PathName) && lastType == ComboBox)\r
            checkList[checks++] = comboList[--combos];\r
        // Now append the checks behind the (remaining) combos to treat them as one group\r
-       for(i=0; i< checks; i++) \r
+       for(i=0; i< checks; i++)\r
            comboList[combos++] = checkList[i];\r
        // emit the consecutive checks and combos in two columns\r
        right = combos/2; // rounded down if odd!\r
@@ -137,7 +139,7 @@ LayoutOptions(int firstOption, int endOption, char *groupName, Option *optionLis
            layoutList[layout++] = -1;\r
            layoutList[layout++] = comboList[2*right];\r
        }\r
-       if(nextType == TextBox) {\r
+       if(nextType == TextBox || nextType == FileName || nextType == PathName) {\r
            // A textBox is double width, so must be left-adjusted, and the right column remains empty\r
            breaks[layout/2] = lastType == Button ? 0 : 100;\r
            layoutList[layout++] = -1;\r
@@ -189,7 +191,7 @@ DesignOptionDialog(ChessProgramState *cps)
                    if( cps->option[k].name[j] != cps->option[k+groupSize].name[j]) break;\r
                groupNameLength = j;\r
                groupSize++;\r
-               \r
+\r
        }\r
        if(groupSize > 3) {\r
                // We found a group to terminates the current section\r
@@ -203,7 +205,7 @@ DesignOptionDialog(ChessProgramState *cps)
     }\r
     if(n != k) LayoutOptions(n, k, "", cps->option); // flush remaining solitary options\r
     // decide if and where we break into two column pairs\r
-    \r
+\r
     // Emit buttons and add OK and cancel\r
 //    for(k=0; k<buttons; k++) layoutList[layout++] = buttonList[k];\r
     // Create the dialog window\r
@@ -259,6 +261,8 @@ SetOptionValues(HWND hDlg, ChessProgramState *cps)
                SetDlgItemInt( hDlg, 2001+2*i, cps->option[j].value, TRUE );\r
                break;\r
            case TextBox:\r
+           case FileName:\r
+           case PathName:\r
                SetDlgItemText( hDlg, 2001+2*i, cps->option[j].textValue );\r
                break;\r
            case CheckBox:\r
@@ -281,10 +285,10 @@ SetOptionValues(HWND hDlg, ChessProgramState *cps)
     }\r
     SetDlgItemText( hDlg, IDOK, _("OK") );\r
     SetDlgItemText( hDlg, IDCANCEL, _("Cancel") );\r
-    sprintf(title, _("%s Engine Settings (%s)"), T_(cps->which), cps->tidy); \r
+    snprintf(title, MSG_SIZ, _("%s Engine Settings (%s)"), T_(cps->which), cps->tidy);\r
     title[0] &= ~32; // capitalize\r
     SetWindowText( hDlg, title);\r
-    for(i=0; i<groups; i+=2) { \r
+    for(i=0; i<groups; i+=2) {\r
        int id, p; char buf[MSG_SIZ];\r
        id = k = boxList[i];\r
        if(layoutList[k] < 0) k++;\r
@@ -323,7 +327,7 @@ GetOptionValues(HWND hDlg, ChessProgramState *cps)
                success = GetDlgItemText( hDlg, 2001+2*i, newText, MSG_SIZ - strlen(cps->option[j].name) - 9 );\r
                if(!success) break;\r
                changed = strcmp(cps->option[j].textValue, newText) != 0;\r
-               safeStrCpy(cps->option[j].textValue, newText, sizeof(cps->option[j].textValue)/sizeof(cps->option[j].textValue[0]) );\r
+               safeStrCpy(cps->option[j].textValue, newText, MSG_SIZ - (cps->option[j].textValue - cps->option[j].name) );\r
                break;\r
            case CheckBox:\r
                new = IsDlgButtonChecked( hDlg, 2000+2*i );\r
@@ -346,8 +350,10 @@ GetOptionValues(HWND hDlg, ChessProgramState *cps)
            default:\r
                break; // are treated instantly, so they have been sent already\r
        }\r
-       if(changed == 2) sprintf(buf, "option %s=%d\n", cps->option[j].name, new); else\r
-       if(changed == 1) sprintf(buf, "option %s=%s\n", cps->option[j].name, newText);\r
+       if(changed == 2)\r
+         snprintf(buf, MSG_SIZ, "option %s=%d\n", cps->option[j].name, new); else\r
+       if(changed == 1)\r
+         snprintf(buf, MSG_SIZ, "option %s=%s\n", cps->option[j].name, newText);\r
        if(changed) SendToProgram(buf, cps);\r
     }\r
 }\r
@@ -376,7 +382,7 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
             return TRUE;\r
 \r
         case IDCANCEL:\r
-            EndDialog( hDlg, 1 );   \r
+            EndDialog( hDlg, 1 );\r
             return TRUE;\r
 \r
        default:\r
@@ -385,10 +391,10 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
            if( i>=2000 &&  i < 2000+2*(layout+buttons)) {\r
                j = layoutList[(i - 2000)/2];\r
                if(j == -2) {\r
-                         char filter[] = \r
+                         char filter[] =\r
                                "All files\0*.*\0BIN Files\0*.bin\0LOG Files\0*.log\0INI Files\0*.ini\0\0";\r
 /*\r
-{ \r
+{\r
                              'A','l','l',' ','F','i','l','e','s', 0,\r
                              '*','.','*', 0,\r
                              'B','I','N',' ','F','i','l','e','s', 0,\r
@@ -407,18 +413,24 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
                          ofn.lpstrFilter = filter;\r
                          ofn.lpstrFile = buf;\r
                          ofn.nMaxFile = sizeof(buf);\r
-                         ofn.lpstrTitle = _("Choose Book");\r
+                         ofn.lpstrTitle = _("Choose File");\r
                          ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;\r
 \r
                          if( GetOpenFileName( &ofn ) ) {\r
                              SetDlgItemText( hDlg, i+3, buf );\r
                          }\r
+               } else\r
+               if(j == -3) {\r
+                   if( BrowseForFolder( _("Choose Folder:"), buf ) ) {\r
+                       SetDlgItemText( hDlg, i+3, buf );\r
+                   }\r
                }\r
+      return TRUE;\r
                if(j < 0) break;\r
                if( activeCps->option[j].type  == SaveButton)\r
                     GetOptionValues(hDlg, activeCps);\r
                else if( activeCps->option[j].type  != Button) break;\r
-               sprintf(buf, "option %s\n", activeCps->option[j].name);\r
+               snprintf(buf, MSG_SIZ, "option %s\n", activeCps->option[j].name);\r
                SendToProgram(buf, activeCps);\r
            }\r
            break;\r
@@ -458,17 +470,16 @@ void AddOption(int x, int y, Control type, int i)
            AddControl(x, y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i);\r
            AddControl(x+95, y, 50, 11, 0x0081, ES_AUTOHSCROLL | ES_NUMBER | WS_BORDER | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i+1);\r
            break;\r
-//     case TextBox:\r
+       case TextBox:\r
            AddControl(x, y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i);\r
            AddControl(x+95, y, 190, 11, 0x0081, ES_AUTOHSCROLL | WS_BORDER | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i+1);\r
            break;\r
-       case TextBox:  // For now all text edits get a browse button, as long as -file and -path options are not yet implemented\r
        case FileName:\r
        case PathName:\r
            AddControl(x, y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i);\r
            AddControl(x+95, y, 180, 11, 0x0081, ES_AUTOHSCROLL | WS_BORDER | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i+1);\r
            AddControl(x+275, y, 20, 12, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i-2);\r
-           layoutList[i/2-1] = -2;\r
+           layoutList[i/2-1] = -2 - (type == PathName);\r
            break;\r
        case CheckBox:\r
            AddControl(x, y, 145, 11, 0x0080, BS_AUTOCHECKBOX | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i);\r
@@ -482,9 +493,10 @@ void AddOption(int x, int y, Control type, int i)
        case SaveButton:\r
            AddControl(x-2, y, 65, 13, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, i);\r
        case Message:\r
+       default:\r
            break;\r
     }\r
-    \r
+\r
 }\r
 \r
 void\r
@@ -495,7 +507,7 @@ CreateDialogTemplate(int *layoutList, int nr, ChessProgramState *cps)
     template.header.cdit = 0;\r
     template.header.cx = 307;\r
     buttonRows = (buttons + 1 + 3)/4; // 4 per row, rounded up\r
-    if(nr > 50) { \r
+    if(nr > 50) {\r
        breakPoint = (nr+2*buttonRows+1)/2 & ~1;\r
        template.header.cx = 625;\r
     }\r
@@ -503,9 +515,9 @@ CreateDialogTemplate(int *layoutList, int nr, ChessProgramState *cps)
     for(i=0; i<nr; i++) {\r
        if(k < groups && i == boxList[k]) {\r
            y += 10;\r
-           AddControl(x+2, y+13*(i>>1)-2, 301, 13*(boxList[k+1]-boxList[k]>>1)+8, \r
+           AddControl(x+2, y+13*(i>>1)-2, 301, 13*(boxList[k+1]-boxList[k]>>1)+8,\r
                                                0x0082, WS_VISIBLE | WS_CHILD | SS_BLACKFRAME, 2400);\r
-           AddControl(x+60, y+13*(i>>1)-6, 10*groupNameList[k]/3, 10, \r
+           AddControl(x+60, y+13*(i>>1)-6, 10*groupNameList[k]/3, 10,\r
                                                0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, 2*(i+MAX_OPTIONS));\r
        }\r
        j = layoutList[i];\r
@@ -519,8 +531,8 @@ CreateDialogTemplate(int *layoutList, int nr, ChessProgramState *cps)
     // add butons at the bottom of dialog window\r
     y += 13*(nr>>1)+5;\r
 \r
-    AddControl(x+275, y+18*(buttonRows-1), 25, 15, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, IDOK-2000);\r
-    AddControl(x+235, y+18*(buttonRows-1), 35, 15, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, IDCANCEL-2000);\r
+    AddControl(x+225, y+18*(buttonRows-1), 30, 15, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, IDOK-2000);\r
+    AddControl(x+260, y+18*(buttonRows-1), 40, 15, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, IDCANCEL-2000);\r
     for(i=0; i<buttons; i++) {\r
        AddControl(x+70*(i%4)+5, y+18*(i/4), 65, 15, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, 2*(nr+i));\r
        layoutList[nr+i] = buttonList[i];\r
@@ -530,7 +542,7 @@ CreateDialogTemplate(int *layoutList, int nr, ChessProgramState *cps)
     template.header.style &= ~WS_VSCROLL;\r
 }\r
 \r
-void \r
+void\r
 EngineOptionsPopup(HWND hwnd, ChessProgramState *cps)\r
 {\r
     FARPROC lpProc = MakeProcInstance( (FARPROC) SettingsProc, hInst );\r