X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwsettings.c;h=6fc5c40682a7f677319e72d6271504a1e407ec18;hb=f29ff21f23c2a22fc55e14ba48c53d704c22289d;hp=72465909bfe8dbf3489b0c741e91e3dd84a48778;hpb=a2724ace243e91f45310697eafaafe8d44245242;p=xboard.git diff --git a/winboard/wsettings.c b/winboard/wsettings.c index 7246590..6fc5c40 100644 --- a/winboard/wsettings.c +++ b/winboard/wsettings.c @@ -34,15 +34,15 @@ 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 @@ -262,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 @@ -274,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 ); @@ -285,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); @@ -321,7 +334,7 @@ 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 { @@ -349,7 +362,7 @@ GetOptionValues(HWND hDlg, ChessProgramState *cps, Option *optionList) if(cps) len = MSG_SIZ - strlen(optionList[j].name) - 9, text = newText; else len = GetWindowTextLength(GetDlgItem(hDlg, 2001+2*i)) + 1, text = (char*) malloc(len); success = GetDlgItemText( hDlg, 2001+2*i, text, len ); - if(!success) break; + if(!success) text[0] = NULLCHAR; // empty string can be valid input if(!cps) { char *p; p = (optionList[j].type != FileName ? strdup(text) : InterpretFileName(text, homeDir)); // all files relative to homeDir! @@ -394,7 +407,8 @@ 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" }; @@ -411,14 +425,14 @@ 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 ); comboCallback = NULL; activeCps = NULL; return TRUE; @@ -472,6 +486,7 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa 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); } @@ -517,11 +532,11 @@ void AddOption(int x, int y, Control type, int i) AddControl(x, y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i); 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 | WS_VSCROLL :0), i+1); + (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: @@ -541,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; @@ -552,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; @@ -562,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