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