X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwsettings.c;h=62983092af550a4544e1c58ec4a10ac7c115addd;hb=eb4c25525f55082325940435f0175de2d388f27e;hp=0a25f9bbe786d4dab74724d3b3ce62f1a52da08a;hpb=b9c351f74daacf02bfbaa97669555d8046b27b43;p=xboard.git diff --git a/winboard/wsettings.c b/winboard/wsettings.c index 0a25f9b..6298309 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. @@ -9,12 +9,18 @@ * that generates the actual dialog box from it. */ -//#include "config.h" #include "config.h" +#include #include +#include #include "common.h" +#include "frontend.h" #include "backend.h" +#include "winboard.h" +#include "backendz.h" + +#define _(s) T_(s) int layoutList[2*MAX_OPTIONS]; int checkList[2*MAX_OPTIONS]; @@ -33,10 +39,13 @@ PrintOpt(int i, int right, ChessProgramState *cps) } else { Option opt = cps->option[i]; switch(opt.type) { + case Slider: case Spin: fprintf(debugFP, "%20.20s [ +/-]", opt.name); break; case TextBox: + case FileName: + case PathName: fprintf(debugFP, "%20.20s [______________________________________]", opt.name); break; case CheckBox: @@ -47,7 +56,10 @@ PrintOpt(int i, int right, ChessProgramState *cps) break; case Button: case SaveButton: + case ResetButton: fprintf(debugFP, "[ %26.26s ]", opt.name); + case Message: + default: break; } } @@ -68,7 +80,7 @@ CreateOptionDialogTest(int *list, int nr, ChessProgramState *cps) void LayoutOptions(int firstOption, int endOption, char *groupName, Option *optionList) { - int n, i, b = strlen(groupName), stop, prefix, right, nextOption, firstButton = buttons; + int i, b = strlen(groupName), stop, prefix, right, nextOption, firstButton = buttons; Control lastType, nextType; nextOption = firstOption; @@ -80,18 +92,24 @@ LayoutOptions(int firstOption, int endOption, char *groupName, Option *optionLis switch(nextType = optionList[nextOption].type) { case CheckBox: checkList[checks++] = nextOption; lastType = CheckBox; break; case ComboBox: comboList[combos++] = nextOption; lastType = ComboBox; break; + case ResetButton: case SaveButton: case Button: buttonList[buttons++] = nextOption; lastType = Button; break; case TextBox: + case FileName: + 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) @@ -103,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! @@ -121,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; @@ -143,7 +161,7 @@ LayoutOptions(int firstOption, int endOption, char *groupName, Option *optionLis } } -char *p +char * EndMatch(char *s1, char *s2) { char *p, *q; @@ -165,7 +183,7 @@ DesignOptionDialog(ChessProgramState *cps) while(k < cps->nrOptions) { // k steps through 'solitary' options // look if we hit a group of options having names that start with the same word int groupSize = 1, groupNameLength = 50; - sscanf(cps->option[k].name, "%s", &buf); // get first word of option name + sscanf(cps->option[k].name, "%s", buf); // get first word of option name while(k + groupSize < cps->nrOptions && strstr(cps->option[k+groupSize].name, buf) == cps->option[k+groupSize].name) { int j; @@ -173,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 @@ -183,16 +201,11 @@ DesignOptionDialog(ChessProgramState *cps) LayoutOptions(k, k+groupSize, buf, cps->option); // flush the group boxList[groups++] = layout; // group end in odd entries k = n = k + groupSize; - } else { - // try to recognize "two-column groups" based on option suffix - int j = 1; - while((p = EndMatch(cps->option[k].name, EndMatch(cps->option[k+2*j].name)) && - (q = EndMatch(cps->option[k+1].name, EndMatch(cps->option[k+2*j+1].name)) ) j++ } else k += groupSize; // small groups are grouped with the solitary options } 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: @@ -264,15 +279,16 @@ SetOptionValues(HWND hDlg, ChessProgramState *cps) break; case Button: case SaveButton: + default: break; } } - SetDlgItemText( hDlg, IDOK, "OK" ); - SetDlgItemText( hDlg, IDCANCEL, "Cancel" ); - sprintf(title, "%s Engine Settings (%s)", cps->which, cps->tidy); + SetDlgItemText( hDlg, IDOK, _("OK") ); + SetDlgItemText( hDlg, IDCANCEL, _("Cancel") ); + 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 ); switch(cps->option[j].type) { case Spin: new = GetDlgItemInt( hDlg, 2001+2*i, &success, TRUE ); @@ -312,7 +327,7 @@ GetOptionValues(HWND hDlg, ChessProgramState *cps) success = GetDlgItemText( hDlg, 2001+2*i, newText, MSG_SIZ - strlen(cps->option[j].name) - 9 ); if(!success) break; changed = strcmp(cps->option[j].textValue, newText) != 0; - strcpy(cps->option[j].textValue, newText); + 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 ); @@ -332,18 +347,19 @@ GetOptionValues(HWND hDlg, ChessProgramState *cps) if(changed) cps->option[j].value = new; break; case Button: + 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); } } LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - static int * lpIndexFRC; - BOOL index_is_ok; char buf[MSG_SIZ]; int i, j; @@ -366,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: @@ -375,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, @@ -387,7 +403,7 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa */ OPENFILENAME ofn; - strcpy( buf, "" ); + safeStrCpy( buf, "" , sizeof( buf)/sizeof( buf[0]) ); ZeroMemory( &ofn, sizeof(ofn) ); @@ -397,18 +413,24 @@ 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 ); + } } + return TRUE; 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; @@ -420,123 +442,6 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa return FALSE; } -#if 0 -// example copied from MS docs -#define ID_HELP 150 -#define ID_TEXT 200 - -LPWORD lpwAlign(LPWORD lpIn) -{ - ULONG ul; - - ul = (ULONG)lpIn; - ul ++; - ul >>=1; - ul <<=1; - return (LPWORD)ul; -} - -LRESULT DisplayMyMessage(HINSTANCE hinst, HWND hwndOwner, LPSTR lpszMessage) -{ - HGLOBAL hgbl; - LPDLGTEMPLATE lpdt; - LPDLGITEMTEMPLATE lpdit; - LPWORD lpw; - LPWSTR lpwsz; - LRESULT ret; - int nchar; - - hgbl = GlobalAlloc(GMEM_ZEROINIT, 1024); - if (!hgbl) - return -1; - - lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl); - - // Define a dialog box. - - lpdt->style = WS_POPUP | WS_BORDER | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION; -// WS_POPUP | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION | DS_SETFONT - lpdt->cdit = 3; // Number of controls - lpdt->x = 10; lpdt->y = 10; - lpdt->cx = 100; lpdt->cy = 100; - - lpw = (LPWORD)(lpdt + 1); - *lpw++ = 0; // No menu - *lpw++ = 0; // Predefined dialog box class (by default) - - lpwsz = (LPWSTR)lpw; - nchar = 1 + MultiByteToWideChar(CP_ACP, 0, "My Dialog", -1, lpwsz, 50); - lpw += nchar; - - //----------------------- - // Define an OK button. - //----------------------- - lpw = lpwAlign(lpw); // Align DLGITEMTEMPLATE on DWORD boundary - lpdit = (LPDLGITEMTEMPLATE)lpw; - lpdit->x = 10; lpdit->y = 70; - lpdit->cx = 80; lpdit->cy = 20; - lpdit->id = IDOK; // OK button identifier - lpdit->style = WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON; - - lpw = (LPWORD)(lpdit + 1); - *lpw++ = 0xFFFF; - *lpw++ = 0x0080; // Button class - - lpwsz = (LPWSTR)lpw; - nchar = 1 + MultiByteToWideChar(CP_ACP, 0, "OK", -1, lpwsz, 50); - lpw += nchar; - lpw = lpwAlign(lpw); // Align creation data on DWORD boundary - *lpw++ = 0; // No creation data - - //----------------------- - // Define a Help button. - //----------------------- - lpw = lpwAlign(lpw); // Align DLGITEMTEMPLATE on DWORD boundary - lpdit = (LPDLGITEMTEMPLATE)lpw; - lpdit->x = 55; lpdit->y = 10; - lpdit->cx = 40; lpdit->cy = 20; - lpdit->id = ID_HELP; // Help button identifier - lpdit->style = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON; - - lpw = (LPWORD)(lpdit + 1); - *lpw++ = 0xFFFF; - *lpw++ = 0x0080; // Button class atom - - lpwsz = (LPWSTR)lpw; - nchar = 1 + MultiByteToWideChar(CP_ACP, 0, "Help", -1, lpwsz, 50); - lpw += nchar; - lpw = lpwAlign(lpw); // Align creation data on DWORD boundary - *lpw++ = 0; // No creation data - - //----------------------- - // Define a static text control. - //----------------------- - lpw = lpwAlign(lpw); // Align DLGITEMTEMPLATE on DWORD boundary - lpdit = (LPDLGITEMTEMPLATE)lpw; - lpdit->x = 10; lpdit->y = 10; - lpdit->cx = 40; lpdit->cy = 20; - lpdit->id = ID_TEXT; // Text identifier - lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT; - - lpw = (LPWORD)(lpdit + 1); - *lpw++ = 0xFFFF; - *lpw++ = 0x0082; // Static class - - for (lpwsz = (LPWSTR)lpw; *lpwsz++ = (WCHAR)*lpszMessage++;); - lpw = (LPWORD)lpwsz; - lpw = lpwAlign(lpw); // Align creation data on DWORD boundary - *lpw++ = 0; // No creation data - - GlobalUnlock(hgbl); - ret = DialogBoxIndirect(hinst, - (LPDLGTEMPLATE)hgbl, - hwndOwner, - (DLGPROC)DialogProc); - GlobalFree(hgbl); - return ret; -} -#endif - void AddControl(int x, int y, int w, int h, int type, int style, int n) { int i; @@ -560,21 +465,21 @@ void AddOption(int x, int y, Control type, int i) { switch(type) { + case Slider: case Spin: 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); @@ -584,10 +489,14 @@ void AddOption(int x, int y, Control type, int i) AddControl(x+95, y-1, 50, 500, 0x0085, CBS_AUTOHSCROLL | CBS_DROPDOWN | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i+1); break; case Button: - AddControl(x, y, 40, 15, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, i); + case ResetButton: + case SaveButton: + AddControl(x-2, y, 65, 13, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, i); + case Message: + default: break; } - + } void @@ -597,8 +506,8 @@ CreateDialogTemplate(int *layoutList, int nr, ChessProgramState *cps) template.header.cdit = 0; template.header.cx = 307; - buttonRows = (buttons + 1 + 3)/4; // 4 per row, ronded up - if(nr > 50) { + buttonRows = (buttons + 1 + 3)/4; // 4 per row, rounded up + if(nr > 50) { breakPoint = (nr+2*buttonRows+1)/2 & ~1; template.header.cx = 625; } @@ -606,9 +515,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]; @@ -622,8 +531,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 300, 0) { - template.header.cx = 295; - template.header.cy = 300; - template.header.style |= WS_VSCROLL; - } } -void +void EngineOptionsPopup(HWND hwnd, ChessProgramState *cps) { FARPROC lpProc = MakeProcInstance( (FARPROC) SettingsProc, hInst );