X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwsettings.c;h=83472f5e6e3d7e17520899dd30583172f0f67445;hb=2c6cd481ba85455e761248831c7eee4a50e8b5c7;hp=58040c9305433ecbb70051095fdd936ccc6ac416;hpb=af0e7e39409348d713114eb0e41858f552076a21;p=xboard.git diff --git a/winboard/wsettings.c b/winboard/wsettings.c index 58040c9..83472f5 100644 --- a/winboard/wsettings.c +++ b/winboard/wsettings.c @@ -12,6 +12,7 @@ #include "config.h" #include +#include #include #include #include "common.h" @@ -33,15 +34,16 @@ int breaks[MAX_OPTIONS]; int checks, combos, buttons, layout, groups; char title[MSG_SIZ]; char *engineName, *engineDir, *engineChoice, *engineLine, *nickName, *params; -Boolean isUCI, hasBook, storeVariant, v1, addToList; +Boolean isUCI, hasBook, storeVariant, v1, addToList, useNick, isUCCI; extern Option installOptions[], matchOptions[]; char *engineNr[] = { N_("First"), N_("Second"), NULL }; char *engineList[1000] = {" "}, *engineMnemonic[1000] = {""}; void (*okFunc)(); ChessProgramState *activeCps; Option *activeList; -void InstallOK P((void)); -typedef void ButtonCallback(HWND h); +int InstallOK P((void)); +typedef int ButtonCallback(HWND h); +ButtonCallback *comboCallback; void PrintOpt(int i, int right, Option *optionList) @@ -160,6 +162,10 @@ LayoutOptions(int firstOption, int endOption, char *groupName, Option *optionLis breaks[layout/2] = lastType == Button ? 0 : 100; layoutList[layout++] = -1; layoutList[layout++] = nextOption - 1; + for(i=optionList[nextOption-1].min; i>0; i--) { // extra high text edit + layoutList[layout++] = -1; + layoutList[layout++] = -1; + } } else if(nextType == Spin) { // A spin will go in the next available position (right to left!). If it had to be prefixed with // a check or combo, this next position must be to the right, and the prefix goes left to it. @@ -256,6 +262,17 @@ struct { 0x0000, 0x0000, L"Engine #1 Settings ", 8, L"MS Sans Serif" }; +char * +AddCR(char *s) +{ + char *p=s, *q; + int n=0; + while(p = strchr(p, '\n')) p++, n++; // count linefeeds + p = q = malloc(strlen(s) + n + 1); + while(*p++ = *s++) if(p[-1] == '\n') p[-1] = '\r', *p++ = '\n'; + return q; +} + void SetOptionValues(HWND hDlg, ChessProgramState *cps, Option *optionList) // Put all current option values in controls, and write option names next to them @@ -268,7 +285,7 @@ SetOptionValues(HWND hDlg, ChessProgramState *cps, Option *optionList) int j=layoutList[i]; if(j == -2) SetDlgItemText( hDlg, 2000+2*i, ". . ." ); if(j<0) continue; - name = optionList[j].name; + name = cps ? optionList[j].name : _(optionList[j].name); if(strstr(name, "Polyglot ") == name) name += 9; SetDlgItemText( hDlg, 2000+2*i, name ); //if(appData.debugMode) fprintf(debugFP, "# %s = %d\n",optionList[j].name, optionList[j].value ); @@ -279,7 +296,9 @@ SetOptionValues(HWND hDlg, ChessProgramState *cps, Option *optionList) case TextBox: case FileName: case PathName: - SetDlgItemText( hDlg, 2001+2*i, cps ? optionList[j].textValue : *(char**)optionList[j].target ); + name = AddCR(cps ? optionList[j].textValue : *(char**)optionList[j].target); // stupid CR... + SetDlgItemText( hDlg, 2001+2*i, name); + free(name); break; case CheckBox: CheckDlgButton( hDlg, 2000+2*i, (cps ? optionList[j].value : *(Boolean*)optionList[j].target) != 0); @@ -315,13 +334,13 @@ SetOptionValues(HWND hDlg, ChessProgramState *cps, Option *optionList) } -void +int GetOptionValues(HWND hDlg, ChessProgramState *cps, Option *optionList) // read out all controls, and if value is altered, remember it and send it to the engine { HANDLE hwndCombo; - int i, k, new=0, changed=0; - char **choices, newText[MSG_SIZ], buf[MSG_SIZ]; + int i, k, new=0, changed=0, len; + char **choices, newText[MSG_SIZ], buf[MSG_SIZ], *text; BOOL success; for(i=0; i 0) { if(*(char**)optionList[j].target) free(*(char**)optionList[j].target); *(char**)optionList[j].target = strdup(optionList[j].choice[new]); break; @@ -383,13 +407,16 @@ GetOptionValues(HWND hDlg, ChessProgramState *cps, Option *optionList) snprintf(buf, MSG_SIZ, "option %s=%s\n", optionList[j].name, newText); if(changed) SendToProgram(buf, cps); } - if(!cps && okFunc) ((ButtonCallback*) okFunc)(0); + if(!cps && okFunc) return ((ButtonCallback*) okFunc)(0); + return 1; } +char *defaultExt[] = { NULL, "pgn", "fen", "exe", "trn", "bin", "log", "ini" }; + LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { char buf[MSG_SIZ]; - int i, j; + int i, j, ext; switch( message ) { @@ -398,21 +425,21 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa // CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER)); SetOptionValues(hDlg, activeCps, activeList); -// SetFocus(GetDlgItem(hDlg, IDC_NFG_Edit)); + SetFocus(GetDlgItem(hDlg, IDCANCEL)); break; case WM_COMMAND: switch( LOWORD(wParam) ) { case IDOK: - GetOptionValues(hDlg, activeCps, activeList); + if(!GetOptionValues(hDlg, activeCps, activeList)) return FALSE; EndDialog( hDlg, 0 ); - activeCps = NULL; + comboCallback = NULL; activeCps = NULL; return TRUE; case IDCANCEL: EndDialog( hDlg, 1 ); - activeCps = NULL; + comboCallback = NULL; activeCps = NULL; return TRUE; default: @@ -422,15 +449,9 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa j = layoutList[(i - 2000)/2]; if(j == -2) { 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, - '*','.','b','i','n', 0, - 0 }; -*/ + "All files\0*.*\0Game files\0*.pgn;*.gam\0Position files\0*.fen;*.epd;*.pos\0" + "EXE files\0*.exe\0Tournament files (*.trn)\0*.trn\0" + "BIN Files\0*.bin\0LOG Files\0*.log\0INI Files\0*.ini\0\0"; OPENFILENAME ofn; safeStrCpy( buf, "" , sizeof( buf)/sizeof( buf[0]) ); @@ -441,6 +462,8 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa ofn.hwndOwner = hDlg; ofn.hInstance = hInst; ofn.lpstrFilter = filter; + ofn.nFilterIndex = 1L + (ext = activeCps ? 0 : activeList[layoutList[(i-2000)/2+1]].max); + ofn.lpstrDefExt = defaultExt[ext]; ofn.lpstrFile = buf; ofn.nMaxFile = sizeof(buf); ofn.lpstrTitle = _("Choose File"); @@ -456,9 +479,14 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa } } if(j < 0) break; + if(comboCallback && activeList[j].type == ComboBox && HIWORD(wParam) == CBN_SELCHANGE) { + (*comboCallback)(hDlg); + break; + } else if( activeList[j].type == SaveButton) GetOptionValues(hDlg, activeCps, activeList); else if( activeList[j].type != Button) break; + else if( !activeCps ) { (*(ButtonCallback*) activeList[j].target)(hDlg); break; } snprintf(buf, MSG_SIZ, "option %s\n", activeList[j].name); SendToProgram(buf, activeCps); } @@ -492,6 +520,7 @@ void AddControl(int x, int y, int w, int h, int type, int style, int n) void AddOption(int x, int y, Control type, int i) { + int extra; switch(type) { case Slider: @@ -501,11 +530,13 @@ void AddOption(int x, int y, Control type, int i) break; case TextBox: AddControl(x, y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i); - AddControl(x+95, y, 200, 11, 0x0081, ES_AUTOHSCROLL | WS_BORDER | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i+1); + extra = 13*activeList[layoutList[i/2]].min; + AddControl(x+95, y, 200, 11+extra, 0x0081, ES_AUTOHSCROLL | WS_BORDER | WS_VISIBLE | WS_CHILD | WS_TABSTOP | + (extra ? ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL :0), i+1); break; case Label: extra = activeList[layoutList[i/2]].value; - AddControl(x+extra, y+1, 290-extra, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i); + AddControl(x+extra, y+1, 290-extra, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i); break; case FileName: case PathName: @@ -525,7 +556,7 @@ void AddOption(int x, int y, Control type, int i) case Button: case ResetButton: case SaveButton: - AddControl(x-2, y, 65, 13, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, i); + AddControl(x-2, y, 65, 13, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i); case Message: default: break; @@ -536,7 +567,7 @@ void AddOption(int x, int y, Control type, int i) void CreateDialogTemplate(int *layoutList, int nr, Option *optionList) { - int i, j, x=1, y=0, buttonRows, breakPoint = -1, k=0; + int i, ii, j, x=1, y=0, buttonRows, breakPoint = -1, k=0; template.header.cdit = 0; template.header.cx = 307; @@ -546,31 +577,32 @@ CreateDialogTemplate(int *layoutList, int nr, Option *optionList) template.header.cx = 625; } - for(i=0; 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, - 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, 2*(i+MAX_OPTIONS)); + 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, 2*(ii+MAX_OPTIONS)); } j = layoutList[i]; if(j >= 0) AddOption(x+155-150*(i&1), y+13*(i>>1)+5, optionList[j].type, 2*i); - if(k < groups && i+1 == boxList[k+1]) { + if(k < groups && ii+1 == boxList[k+1]) { k += 2; y += 4; } - if(i+1 == breakPoint) { x += 318; y = -13*(breakPoint>>1); } + if(ii+1 == breakPoint) { x += 318; y = -13*(breakPoint>>1); } } // add butons at the bottom of dialog window y += 13*(nr>>1)+5; - 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