security fix: replaced sprintf with snprintf
[xboard.git] / winboard / wsettings.c
1 /*\r
2  * Engine-settings dialog. The complexity come from an attempt to present the engine-defined options\r
3  * in a nicey formatted layout. To this end we first run a back-end pre-formatter, which will distribute\r
4  * the controls over two columns (the minimum required, as some are double width). It also takes care of\r
5  * grouping options that start with the same word (mainly for "Polyglot ..." options). It assigns relative\r
6  * suitability to break points between lines, and in the end decides if and where to break up the list\r
7  * for display in multiple (2*N) columns.\r
8  * The thus obtained list representing the topology of the layout is then passed to a front-end routine\r
9  * that generates the actual dialog box from it.\r
10  */\r
11 \r
12 #include "config.h"\r
13 \r
14 #include <windows.h>\r
15 #include <stdio.h>\r
16 #include <string.h>\r
17 #include "common.h"\r
18 #include "frontend.h"\r
19 #include "backend.h"\r
20 #include "winboard.h"\r
21 #include "backendz.h"\r
22 \r
23 #define _(s) T_(s)\r
24 \r
25 int layoutList[2*MAX_OPTIONS];\r
26 int checkList[2*MAX_OPTIONS];\r
27 int comboList[2*MAX_OPTIONS];\r
28 int buttonList[2*MAX_OPTIONS];\r
29 int boxList[2*MAX_OPTIONS];\r
30 int groupNameList[2*MAX_OPTIONS];\r
31 int breaks[MAX_OPTIONS];\r
32 int checks, combos, buttons, layout, groups;\r
33 \r
34 void\r
35 PrintOpt(int i, int right, ChessProgramState *cps)\r
36 {\r
37     if(i<0) {\r
38         if(!right) fprintf(debugFP, "%30s", "");\r
39     } else {\r
40         Option opt = cps->option[i];\r
41         switch(opt.type) {\r
42             case Slider:\r
43             case Spin:\r
44                 fprintf(debugFP, "%20.20s [    +/-]", opt.name);\r
45                 break;\r
46             case TextBox:\r
47             case FileName:\r
48             case PathName:\r
49                 fprintf(debugFP, "%20.20s [______________________________________]", opt.name);\r
50                 break;\r
51             case CheckBox:\r
52                 fprintf(debugFP, "[x] %-26.25s", opt.name);\r
53                 break;\r
54             case ComboBox:\r
55                 fprintf(debugFP, "%20.20s [ COMBO ]", opt.name);\r
56                 break;\r
57             case Button:\r
58             case SaveButton:\r
59             case ResetButton:\r
60                 fprintf(debugFP, "[ %26.26s ]", opt.name);\r
61             case Message:\r
62                 break;\r
63         }\r
64     }\r
65     fprintf(debugFP, right ? "\n" : " ");\r
66 }\r
67 \r
68 void\r
69 CreateOptionDialogTest(int *list, int nr, ChessProgramState *cps)\r
70 {\r
71     int line;\r
72 \r
73     for(line = 0; line < nr; line+=2) {\r
74         PrintOpt(list[line+1], 0, cps);\r
75         PrintOpt(list[line], 1, cps);\r
76     }\r
77 }\r
78 \r
79 void\r
80 LayoutOptions(int firstOption, int endOption, char *groupName, Option *optionList)\r
81 {\r
82     int i, b = strlen(groupName), stop, prefix, right, nextOption, firstButton = buttons;\r
83     Control lastType, nextType;\r
84 \r
85     nextOption = firstOption;\r
86     while(nextOption < endOption) {\r
87         checks = combos = 0; stop = 0;\r
88         lastType = Button; // kludge to make sure leading Spin will not be prefixed\r
89         // first separate out buttons for later treatment, and collect consecutive checks and combos\r
90         while(nextOption < endOption && !stop) {\r
91             switch(nextType = optionList[nextOption].type) {\r
92                 case CheckBox: checkList[checks++] = nextOption; lastType = CheckBox; break;\r
93                 case ComboBox: comboList[combos++] = nextOption; lastType = ComboBox; break;\r
94                 case ResetButton:\r
95                 case SaveButton:\r
96                 case Button:  buttonList[buttons++] = nextOption; lastType = Button; break;\r
97                 case TextBox:\r
98                 case FileName:\r
99                 case PathName:\r
100                 case Slider:\r
101                 case Spin: stop++;\r
102                 case Message: ; // cannot happen\r
103             }\r
104             nextOption++;\r
105         }\r
106         // We now must be at the end, or looking at a spin or textbox (in nextType)\r
107         if(!stop)\r
108             nextType = Button; // kudge to flush remaining checks and combos undistorted\r
109         // Take a new line if a spin follows combos or checks, or when we encounter a textbox\r
110         if((combos+checks || nextType == TextBox) && layout&1) {\r
111             layoutList[layout++] = -1;\r
112         }\r
113         // The last check or combo before a spin will be put on the same line as that spin (prefix)\r
114         // and will thus not be grouped with other checks and combos\r
115         prefix = -1;\r
116         if(nextType == Spin && lastType != Button) {\r
117             if(lastType == CheckBox) prefix = checkList[--checks]; else\r
118             if(lastType == ComboBox) prefix = comboList[--combos];\r
119         }\r
120         // if a combo is followed by a textbox, it must stay at the end of the combo/checks list to appear\r
121         // immediately above the textbox, so treat it as check. (A check would automatically be and remain there.)\r
122         if(nextType == TextBox && lastType == ComboBox)\r
123             checkList[checks++] = comboList[--combos];\r
124         // Now append the checks behind the (remaining) combos to treat them as one group\r
125         for(i=0; i< checks; i++)\r
126             comboList[combos++] = checkList[i];\r
127         // emit the consecutive checks and combos in two columns\r
128         right = combos/2; // rounded down if odd!\r
129         for(i=0; i<right; i++) {\r
130             breaks[layout/2] = 2;\r
131             layoutList[layout++] = comboList[i];\r
132             layoutList[layout++] = comboList[i + right];\r
133         }\r
134         // An odd check or combo (which could belong to following textBox) will be put in the left column\r
135         // If there was an even number of checks and combos the last one will automatically be in that position\r
136         if(combos&1) {\r
137             layoutList[layout++] = -1;\r
138             layoutList[layout++] = comboList[2*right];\r
139         }\r
140         if(nextType == TextBox) {\r
141             // A textBox is double width, so must be left-adjusted, and the right column remains empty\r
142             breaks[layout/2] = lastType == Button ? 0 : 100;\r
143             layoutList[layout++] = -1;\r
144             layoutList[layout++] = nextOption - 1;\r
145         } else if(nextType == Spin) {\r
146             // A spin will go in the next available position (right to left!). If it had to be prefixed with\r
147             // a check or combo, this next position must be to the right, and the prefix goes left to it.\r
148             layoutList[layout++] = nextOption - 1;\r
149             if(prefix >= 0) layoutList[layout++] = prefix;\r
150         }\r
151     }\r
152     // take a new line if needed\r
153     if(layout&1) layoutList[layout++] = -1;\r
154     // emit the buttons belonging in this group; loose buttons are saved for last, to appear at bottom of dialog\r
155     if(b) {\r
156         while(buttons > firstButton)\r
157             layoutList[layout++] = buttonList[--buttons];\r
158         if(layout&1) layoutList[layout++] = -1;\r
159     }\r
160 }\r
161 \r
162 char *\r
163 EndMatch(char *s1, char *s2)\r
164 {\r
165         char *p, *q;\r
166         p = s1; while(*p) p++;\r
167         q = s2; while(*q) q++;\r
168         while(p > s1 && q > s2 && *p == *q) { p--; q--; }\r
169         if(p[1] == 0) return NULL;\r
170         return p+1;\r
171 }\r
172 \r
173 void\r
174 DesignOptionDialog(ChessProgramState *cps)\r
175 {\r
176     int k=0, n=0;\r
177     char buf[MSG_SIZ];\r
178 \r
179     layout = 0;\r
180     buttons = groups = 0;\r
181     while(k < cps->nrOptions) { // k steps through 'solitary' options\r
182         // look if we hit a group of options having names that start with the same word\r
183         int groupSize = 1, groupNameLength = 50;\r
184         sscanf(cps->option[k].name, "%s", buf); // get first word of option name\r
185         while(k + groupSize < cps->nrOptions &&\r
186               strstr(cps->option[k+groupSize].name, buf) == cps->option[k+groupSize].name) {\r
187                 int j;\r
188                 for(j=0; j<groupNameLength; j++) // determine common initial part of option names\r
189                     if( cps->option[k].name[j] != cps->option[k+groupSize].name[j]) break;\r
190                 groupNameLength = j;\r
191                 groupSize++;\r
192 \r
193         }\r
194         if(groupSize > 3) {\r
195                 // We found a group to terminates the current section\r
196                 LayoutOptions(n, k, "", cps->option); // flush all solitary options appearing before the group\r
197                 groupNameList[groups] = groupNameLength;\r
198                 boxList[groups++] = layout; // group start in even entries\r
199                 LayoutOptions(k, k+groupSize, buf, cps->option); // flush the group\r
200                 boxList[groups++] = layout; // group end in odd entries\r
201                 k = n = k + groupSize;\r
202         } else k += groupSize; // small groups are grouped with the solitary options\r
203     }\r
204     if(n != k) LayoutOptions(n, k, "", cps->option); // flush remaining solitary options\r
205     // decide if and where we break into two column pairs\r
206 \r
207     // Emit buttons and add OK and cancel\r
208 //    for(k=0; k<buttons; k++) layoutList[layout++] = buttonList[k];\r
209     // Create the dialog window\r
210     if(appData.debugMode) CreateOptionDialogTest(layoutList, layout, cps);\r
211 //    CreateOptionDialog(layoutList, layout, cps);\r
212 }\r
213 \r
214 #include <windows.h>\r
215 \r
216 extern HINSTANCE hInst;\r
217 \r
218 typedef struct {\r
219     DLGITEMTEMPLATE item;\r
220     WORD code;\r
221     WORD controlType;\r
222     wchar_t d1, data;\r
223     WORD creationData;\r
224 } Item;\r
225 \r
226 struct {\r
227     DLGTEMPLATE header;\r
228     WORD menu;\r
229     WORD winClass;\r
230     wchar_t title[20];\r
231     WORD pointSize;\r
232     wchar_t fontName[14];\r
233     Item control[MAX_OPTIONS];\r
234 } template = {\r
235     { DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_SETFONT, 0, 0, 0, 0, 295, 300 },\r
236     0x0000, 0x0000, L"Engine #1 Settings ", 8, L"MS Sans Serif"\r
237 };\r
238 \r
239 ChessProgramState *activeCps;\r
240 \r
241 void\r
242 SetOptionValues(HWND hDlg, ChessProgramState *cps)\r
243 // Put all current option values in controls, and write option names next to them\r
244 {\r
245     HANDLE hwndCombo;\r
246     int i, k;\r
247     char **choices, title[MSG_SIZ], *name;\r
248 \r
249     for(i=0; i<layout+buttons; i++) {\r
250         int j=layoutList[i];\r
251         if(j == -2) SetDlgItemText( hDlg, 2000+2*i, ". . ." );\r
252         if(j<0) continue;\r
253         name = cps->option[j].name;\r
254         if(strstr(name, "Polyglot ") == name) name += 9;\r
255         SetDlgItemText( hDlg, 2000+2*i, name );\r
256 //if(appData.debugMode) fprintf(debugFP, "# %s = %d\n",cps->option[j].name, cps->option[j].value );\r
257         switch(cps->option[j].type) {\r
258             case Spin:\r
259                 SetDlgItemInt( hDlg, 2001+2*i, cps->option[j].value, TRUE );\r
260                 break;\r
261             case TextBox:\r
262                 SetDlgItemText( hDlg, 2001+2*i, cps->option[j].textValue );\r
263                 break;\r
264             case CheckBox:\r
265                 CheckDlgButton( hDlg, 2000+2*i, cps->option[j].value != 0);\r
266                 break;\r
267             case ComboBox:\r
268                 choices = (char**) cps->option[j].textValue;\r
269                 hwndCombo = GetDlgItem(hDlg, 2001+2*i);\r
270                 SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);\r
271                 for(k=0; k<cps->option[j].max; k++) {\r
272                     SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) choices[k]);\r
273                 }\r
274                 SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) choices[cps->option[j].value]);\r
275                 break;\r
276             case Button:\r
277             case SaveButton:\r
278             default:\r
279                 break;\r
280         }\r
281     }\r
282     SetDlgItemText( hDlg, IDOK, _("OK") );\r
283     SetDlgItemText( hDlg, IDCANCEL, _("Cancel") );\r
284     snprintf(title, MSG_SIZ, _("%s Engine Settings (%s)"), T_(cps->which), cps->tidy);\r
285     title[0] &= ~32; // capitalize\r
286     SetWindowText( hDlg, title);\r
287     for(i=0; i<groups; i+=2) {\r
288         int id, p; char buf[MSG_SIZ];\r
289         id = k = boxList[i];\r
290         if(layoutList[k] < 0) k++;\r
291         if(layoutList[k] < 0) continue;\r
292         for(p=0; p<groupNameList[i]; p++) buf[p] = cps->option[layoutList[k]].name[p];\r
293         buf[p] = 0;\r
294         SetDlgItemText( hDlg, 2000+2*(id+MAX_OPTIONS), buf );\r
295     }\r
296 }\r
297 \r
298 \r
299 void\r
300 GetOptionValues(HWND hDlg, ChessProgramState *cps)\r
301 // read out all controls, and if value is altered, remember it and send it to the engine\r
302 {\r
303     HANDLE hwndCombo;\r
304     int i, k, new=0, changed=0;\r
305     char **choices, newText[MSG_SIZ], buf[MSG_SIZ];\r
306     BOOL success;\r
307 \r
308     for(i=0; i<layout; i++) {\r
309         int j=layoutList[i];\r
310         if(j<0) continue;\r
311         switch(cps->option[j].type) {\r
312             case Spin:\r
313                 new = GetDlgItemInt( hDlg, 2001+2*i, &success, TRUE );\r
314                 if(!success) break;\r
315                 if(new < cps->option[j].min) new = cps->option[j].min;\r
316                 if(new > cps->option[j].max) new = cps->option[j].max;\r
317                 changed = 2*(cps->option[j].value != new);\r
318                 cps->option[j].value = new;\r
319                 break;\r
320             case TextBox:\r
321             case FileName:\r
322             case PathName:\r
323                 success = GetDlgItemText( hDlg, 2001+2*i, newText, MSG_SIZ - strlen(cps->option[j].name) - 9 );\r
324                 if(!success) break;\r
325                 changed = strcmp(cps->option[j].textValue, newText) != 0;\r
326                 safeStrCpy(cps->option[j].textValue, newText, sizeof(cps->option[j].textValue)/sizeof(cps->option[j].textValue[0]) );\r
327                 break;\r
328             case CheckBox:\r
329                 new = IsDlgButtonChecked( hDlg, 2000+2*i );\r
330                 changed = 2*(cps->option[j].value != new);\r
331                 cps->option[j].value = new;\r
332                 break;\r
333             case ComboBox:\r
334                 choices = (char**) cps->option[j].textValue;\r
335                 hwndCombo = GetDlgItem(hDlg, 2001+2*i);\r
336                 success = GetDlgItemText( hDlg, 2001+2*i, newText, MSG_SIZ );\r
337                 if(!success) break;\r
338                 new = -1;\r
339                 for(k=0; k<cps->option[j].max; k++) {\r
340                     if(!strcmp(choices[k], newText)) new = k;\r
341                 }\r
342                 changed = new >= 0 && (cps->option[j].value != new);\r
343                 if(changed) cps->option[j].value = new;\r
344                 break;\r
345             case Button:\r
346             default:\r
347                 break; // are treated instantly, so they have been sent already\r
348         }\r
349         if(changed == 2)\r
350           snprintf(buf, MSG_SIZ, "option %s=%d\n", cps->option[j].name, new); else\r
351         if(changed == 1)\r
352           snprintf(buf, MSG_SIZ, "option %s=%s\n", cps->option[j].name, newText);\r
353         if(changed) SendToProgram(buf, cps);\r
354     }\r
355 }\r
356 \r
357 LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
358 {\r
359     char buf[MSG_SIZ];\r
360     int i, j;\r
361 \r
362     switch( message )\r
363     {\r
364     case WM_INITDIALOG:\r
365 \r
366 //        CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER));\r
367         SetOptionValues(hDlg, activeCps);\r
368 \r
369 //        SetFocus(GetDlgItem(hDlg, IDC_NFG_Edit));\r
370 \r
371         break;\r
372 \r
373     case WM_COMMAND:\r
374         switch( LOWORD(wParam) ) {\r
375         case IDOK:\r
376             GetOptionValues(hDlg, activeCps);\r
377             EndDialog( hDlg, 0 );\r
378             return TRUE;\r
379 \r
380         case IDCANCEL:\r
381             EndDialog( hDlg, 1 );\r
382             return TRUE;\r
383 \r
384         default:\r
385             // program-defined push buttons\r
386             i = LOWORD(wParam);\r
387             if( i>=2000 &&  i < 2000+2*(layout+buttons)) {\r
388                 j = layoutList[(i - 2000)/2];\r
389                 if(j == -2) {\r
390                           char filter[] =\r
391                                 "All files\0*.*\0BIN Files\0*.bin\0LOG Files\0*.log\0INI Files\0*.ini\0\0";\r
392 /*\r
393 {\r
394                               'A','l','l',' ','F','i','l','e','s', 0,\r
395                               '*','.','*', 0,\r
396                               'B','I','N',' ','F','i','l','e','s', 0,\r
397                               '*','.','b','i','n', 0,\r
398                               0 };\r
399 */\r
400                           OPENFILENAME ofn;\r
401 \r
402                           safeStrCpy( buf, "" , sizeof( buf)/sizeof( buf[0]) );\r
403 \r
404                           ZeroMemory( &ofn, sizeof(ofn) );\r
405 \r
406                           ofn.lStructSize = sizeof(ofn);\r
407                           ofn.hwndOwner = hDlg;\r
408                           ofn.hInstance = hInst;\r
409                           ofn.lpstrFilter = filter;\r
410                           ofn.lpstrFile = buf;\r
411                           ofn.nMaxFile = sizeof(buf);\r
412                           ofn.lpstrTitle = _("Choose Book");\r
413                           ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;\r
414 \r
415                           if( GetOpenFileName( &ofn ) ) {\r
416                               SetDlgItemText( hDlg, i+3, buf );\r
417                           }\r
418                 }\r
419                 if(j < 0) break;\r
420                 if( activeCps->option[j].type  == SaveButton)\r
421                      GetOptionValues(hDlg, activeCps);\r
422                 else if( activeCps->option[j].type  != Button) break;\r
423                 snprintf(buf, MSG_SIZ, "option %s\n", activeCps->option[j].name);\r
424                 SendToProgram(buf, activeCps);\r
425             }\r
426             break;\r
427         }\r
428 \r
429         break;\r
430     }\r
431 \r
432     return FALSE;\r
433 }\r
434 \r
435 void AddControl(int x, int y, int w, int h, int type, int style, int n)\r
436 {\r
437     int i;\r
438 \r
439     i = template.header.cdit++;\r
440     template.control[i].item.style = style;\r
441     template.control[i].item.dwExtendedStyle = 0;\r
442     template.control[i].item.x = x;\r
443     template.control[i].item.y = y;\r
444     template.control[i].item.cx = w;\r
445     template.control[i].item.cy = h;\r
446     template.control[i].item.id = 2000 + n;\r
447     template.control[i].code = 0xFFFF;\r
448     template.control[i].controlType = type;\r
449     template.control[i].d1 = ' ';\r
450     template.control[i].data = 0;\r
451     template.control[i].creationData = 0;\r
452 }\r
453 \r
454 void AddOption(int x, int y, Control type, int i)\r
455 {\r
456 \r
457     switch(type) {\r
458         case Slider:\r
459         case Spin:\r
460             AddControl(x, y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i);\r
461             AddControl(x+95, y, 50, 11, 0x0081, ES_AUTOHSCROLL | ES_NUMBER | WS_BORDER | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i+1);\r
462             break;\r
463 //      case TextBox:\r
464             AddControl(x, y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i);\r
465             AddControl(x+95, y, 190, 11, 0x0081, ES_AUTOHSCROLL | WS_BORDER | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i+1);\r
466             break;\r
467         case TextBox:  // For now all text edits get a browse button, as long as -file and -path options are not yet implemented\r
468         case FileName:\r
469         case PathName:\r
470             AddControl(x, y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i);\r
471             AddControl(x+95, y, 180, 11, 0x0081, ES_AUTOHSCROLL | WS_BORDER | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i+1);\r
472             AddControl(x+275, y, 20, 12, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i-2);\r
473             layoutList[i/2-1] = -2;\r
474             break;\r
475         case CheckBox:\r
476             AddControl(x, y, 145, 11, 0x0080, BS_AUTOCHECKBOX | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i);\r
477             break;\r
478         case ComboBox:\r
479             AddControl(x, y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i);\r
480             AddControl(x+95, y-1, 50, 500, 0x0085, CBS_AUTOHSCROLL | CBS_DROPDOWN | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i+1);\r
481             break;\r
482         case Button:\r
483         case ResetButton:\r
484         case SaveButton:\r
485             AddControl(x-2, y, 65, 13, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, i);\r
486         case Message:\r
487             break;\r
488     }\r
489 \r
490 }\r
491 \r
492 void\r
493 CreateDialogTemplate(int *layoutList, int nr, ChessProgramState *cps)\r
494 {\r
495     int i, j, x=1, y=0, buttonRows, breakPoint = -1, k=0;\r
496 \r
497     template.header.cdit = 0;\r
498     template.header.cx = 307;\r
499     buttonRows = (buttons + 1 + 3)/4; // 4 per row, rounded up\r
500     if(nr > 50) {\r
501         breakPoint = (nr+2*buttonRows+1)/2 & ~1;\r
502         template.header.cx = 625;\r
503     }\r
504 \r
505     for(i=0; i<nr; i++) {\r
506         if(k < groups && i == boxList[k]) {\r
507             y += 10;\r
508             AddControl(x+2, y+13*(i>>1)-2, 301, 13*(boxList[k+1]-boxList[k]>>1)+8,\r
509                                                 0x0082, WS_VISIBLE | WS_CHILD | SS_BLACKFRAME, 2400);\r
510             AddControl(x+60, y+13*(i>>1)-6, 10*groupNameList[k]/3, 10,\r
511                                                 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, 2*(i+MAX_OPTIONS));\r
512         }\r
513         j = layoutList[i];\r
514         if(j >= 0)\r
515             AddOption(x+155-150*(i&1), y+13*(i>>1)+5, cps->option[j].type, 2*i);\r
516         if(k < groups && i+1 == boxList[k+1]) {\r
517             k += 2; y += 4;\r
518         }\r
519         if(i+1 == breakPoint) { x += 318; y = -13*(breakPoint>>1); }\r
520     }\r
521     // add butons at the bottom of dialog window\r
522     y += 13*(nr>>1)+5;\r
523 \r
524     AddControl(x+275, y+18*(buttonRows-1), 25, 15, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, IDOK-2000);\r
525     AddControl(x+235, y+18*(buttonRows-1), 35, 15, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, IDCANCEL-2000);\r
526     for(i=0; i<buttons; i++) {\r
527         AddControl(x+70*(i%4)+5, y+18*(i/4), 65, 15, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD, 2*(nr+i));\r
528         layoutList[nr+i] = buttonList[i];\r
529     }\r
530     template.title[8] = cps == &first ? '1' :  '2';\r
531     template.header.cy = y += 18*buttonRows+2;\r
532     template.header.style &= ~WS_VSCROLL;\r
533 }\r
534 \r
535 void\r
536 EngineOptionsPopup(HWND hwnd, ChessProgramState *cps)\r
537 {\r
538     FARPROC lpProc = MakeProcInstance( (FARPROC) SettingsProc, hInst );\r
539 \r
540     activeCps = cps;\r
541     DesignOptionDialog(cps);\r
542     CreateDialogTemplate(layoutList, layout, cps);\r
543 \r
544 \r
545     DialogBoxIndirect( hInst, &template.header, hwnd, (DLGPROC)lpProc );\r
546 \r
547     FreeProcInstance(lpProc);\r
548 \r
549     return;\r
550 }\r
551 \r
552 \r