summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/windows.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/puzzles/src/windows.c')
-rw-r--r--apps/plugins/puzzles/src/windows.c106
1 files changed, 54 insertions, 52 deletions
diff --git a/apps/plugins/puzzles/src/windows.c b/apps/plugins/puzzles/src/windows.c
index ffd0f75894..8e5b40650d 100644
--- a/apps/plugins/puzzles/src/windows.c
+++ b/apps/plugins/puzzles/src/windows.c
@@ -150,7 +150,7 @@ void dputs(char *buf)
150 OutputDebugString(buf); 150 OutputDebugString(buf);
151} 151}
152 152
153void debug_printf(char *fmt, ...) 153void debug_printf(const char *fmt, ...)
154{ 154{
155 char buf[4096]; 155 char buf[4096];
156 va_list ap; 156 va_list ap;
@@ -258,7 +258,7 @@ void frontend_free(frontend *fe)
258static void update_type_menu_tick(frontend *fe); 258static void update_type_menu_tick(frontend *fe);
259static void update_copy_menu_greying(frontend *fe); 259static void update_copy_menu_greying(frontend *fe);
260 260
261void fatal(char *fmt, ...) 261void fatal(const char *fmt, ...)
262{ 262{
263 char buf[2048]; 263 char buf[2048];
264 va_list ap; 264 va_list ap;
@@ -304,7 +304,7 @@ void get_random_seed(void **randseed, int *randseedsize)
304 *randseedsize = sizeof(SYSTEMTIME); 304 *randseedsize = sizeof(SYSTEMTIME);
305} 305}
306 306
307static void win_status_bar(void *handle, char *text) 307static void win_status_bar(void *handle, const char *text)
308{ 308{
309#ifdef _WIN32_WCE 309#ifdef _WIN32_WCE
310 TCHAR wText[255]; 310 TCHAR wText[255];
@@ -556,7 +556,8 @@ static void win_unclip(void *handle)
556} 556}
557 557
558static void win_draw_text(void *handle, int x, int y, int fonttype, 558static void win_draw_text(void *handle, int x, int y, int fonttype,
559 int fontsize, int align, int colour, char *text) 559 int fontsize, int align, int colour,
560 const char *text)
560{ 561{
561 frontend *fe = (frontend *)handle; 562 frontend *fe = (frontend *)handle;
562 POINT xy; 563 POINT xy;
@@ -1002,7 +1003,7 @@ void print(frontend *fe)
1002 document *doc; 1003 document *doc;
1003 midend *nme = NULL; /* non-interactive midend for bulk puzzle generation */ 1004 midend *nme = NULL; /* non-interactive midend for bulk puzzle generation */
1004 int i; 1005 int i;
1005 char *err = NULL; 1006 const char *err = NULL;
1006 1007
1007 /* 1008 /*
1008 * Create our document structure and fill it up with puzzles. 1009 * Create our document structure and fill it up with puzzles.
@@ -1550,7 +1551,7 @@ static frontend *frontend_new(HINSTANCE inst)
1550 return fe; 1551 return fe;
1551} 1552}
1552 1553
1553static void savefile_write(void *wctx, void *buf, int len) 1554static void savefile_write(void *wctx, const void *buf, int len)
1554{ 1555{
1555 FILE *fp = (FILE *)wctx; 1556 FILE *fp = (FILE *)wctx;
1556 fwrite(buf, 1, len, fp); 1557 fwrite(buf, 1, len, fp);
@@ -1586,7 +1587,7 @@ static midend *midend_for_new_game(frontend *fe, const game *cgame,
1586 midend_new_game(me); 1587 midend_new_game(me);
1587 } else { 1588 } else {
1588 FILE *fp; 1589 FILE *fp;
1589 char *err_param, *err_load; 1590 const char *err_param, *err_load;
1590 1591
1591 /* 1592 /*
1592 * See if arg is a valid filename of a save game file. 1593 * See if arg is a valid filename of a save game file.
@@ -2057,52 +2058,43 @@ static config_item *frontend_get_config(frontend *fe, int which,
2057 2058
2058 ret[i].name = "Number of puzzles to print"; 2059 ret[i].name = "Number of puzzles to print";
2059 ret[i].type = C_STRING; 2060 ret[i].type = C_STRING;
2060 ret[i].sval = dupstr("1"); 2061 ret[i].u.string.sval = dupstr("1");
2061 ret[i].ival = 0;
2062 i++; 2062 i++;
2063 2063
2064 ret[i].name = "Number of puzzles across the page"; 2064 ret[i].name = "Number of puzzles across the page";
2065 ret[i].type = C_STRING; 2065 ret[i].type = C_STRING;
2066 ret[i].sval = dupstr("1"); 2066 ret[i].u.string.sval = dupstr("1");
2067 ret[i].ival = 0;
2068 i++; 2067 i++;
2069 2068
2070 ret[i].name = "Number of puzzles down the page"; 2069 ret[i].name = "Number of puzzles down the page";
2071 ret[i].type = C_STRING; 2070 ret[i].type = C_STRING;
2072 ret[i].sval = dupstr("1"); 2071 ret[i].u.string.sval = dupstr("1");
2073 ret[i].ival = 0;
2074 i++; 2072 i++;
2075 2073
2076 ret[i].name = "Percentage of standard size"; 2074 ret[i].name = "Percentage of standard size";
2077 ret[i].type = C_STRING; 2075 ret[i].type = C_STRING;
2078 ret[i].sval = dupstr("100.0"); 2076 ret[i].u.string.sval = dupstr("100.0");
2079 ret[i].ival = 0;
2080 i++; 2077 i++;
2081 2078
2082 ret[i].name = "Include currently shown puzzle"; 2079 ret[i].name = "Include currently shown puzzle";
2083 ret[i].type = C_BOOLEAN; 2080 ret[i].type = C_BOOLEAN;
2084 ret[i].sval = NULL; 2081 ret[i].u.boolean.bval = TRUE;
2085 ret[i].ival = TRUE;
2086 i++; 2082 i++;
2087 2083
2088 ret[i].name = "Print solutions"; 2084 ret[i].name = "Print solutions";
2089 ret[i].type = C_BOOLEAN; 2085 ret[i].type = C_BOOLEAN;
2090 ret[i].sval = NULL; 2086 ret[i].u.boolean.bval = FALSE;
2091 ret[i].ival = FALSE;
2092 i++; 2087 i++;
2093 2088
2094 if (fe->game->can_print_in_colour) { 2089 if (fe->game->can_print_in_colour) {
2095 ret[i].name = "Print in colour"; 2090 ret[i].name = "Print in colour";
2096 ret[i].type = C_BOOLEAN; 2091 ret[i].type = C_BOOLEAN;
2097 ret[i].sval = NULL; 2092 ret[i].u.boolean.bval = FALSE;
2098 ret[i].ival = FALSE;
2099 i++; 2093 i++;
2100 } 2094 }
2101 2095
2102 ret[i].name = NULL; 2096 ret[i].name = NULL;
2103 ret[i].type = C_END; 2097 ret[i].type = C_END;
2104 ret[i].sval = NULL;
2105 ret[i].ival = 0;
2106 i++; 2098 i++;
2107 2099
2108 return ret; 2100 return ret;
@@ -2112,22 +2104,24 @@ static config_item *frontend_get_config(frontend *fe, int which,
2112 } 2104 }
2113} 2105}
2114 2106
2115static char *frontend_set_config(frontend *fe, int which, config_item *cfg) 2107static const char *frontend_set_config(
2108 frontend *fe, int which, config_item *cfg)
2116{ 2109{
2117 if (which < CFG_FRONTEND_SPECIFIC) { 2110 if (which < CFG_FRONTEND_SPECIFIC) {
2118 return midend_set_config(fe->me, which, cfg); 2111 return midend_set_config(fe->me, which, cfg);
2119 } else if (which == CFG_PRINT) { 2112 } else if (which == CFG_PRINT) {
2120 if ((fe->printcount = atoi(cfg[0].sval)) <= 0) 2113 if ((fe->printcount = atoi(cfg[0].u.string.sval)) <= 0)
2121 return "Number of puzzles to print should be at least one"; 2114 return "Number of puzzles to print should be at least one";
2122 if ((fe->printw = atoi(cfg[1].sval)) <= 0) 2115 if ((fe->printw = atoi(cfg[1].u.string.sval)) <= 0)
2123 return "Number of puzzles across the page should be at least one"; 2116 return "Number of puzzles across the page should be at least one";
2124 if ((fe->printh = atoi(cfg[2].sval)) <= 0) 2117 if ((fe->printh = atoi(cfg[2].u.string.sval)) <= 0)
2125 return "Number of puzzles down the page should be at least one"; 2118 return "Number of puzzles down the page should be at least one";
2126 if ((fe->printscale = (float)atof(cfg[3].sval)) <= 0) 2119 if ((fe->printscale = (float)atof(cfg[3].u.string.sval)) <= 0)
2127 return "Print size should be positive"; 2120 return "Print size should be positive";
2128 fe->printcurr = cfg[4].ival; 2121 fe->printcurr = cfg[4].u.boolean.bval;
2129 fe->printsolns = cfg[5].ival; 2122 fe->printsolns = cfg[5].u.boolean.bval;
2130 fe->printcolour = fe->game->can_print_in_colour && cfg[6].ival; 2123 fe->printcolour = fe->game->can_print_in_colour &&
2124 cfg[6].u.boolean.bval;
2131 return NULL; 2125 return NULL;
2132 } else { 2126 } else {
2133 assert(!"We should never get here"); 2127 assert(!"We should never get here");
@@ -2140,7 +2134,7 @@ static char *frontend_set_config(frontend *fe, int which, config_item *cfg)
2140/* Control coordinates should be specified in dialog units. */ 2134/* Control coordinates should be specified in dialog units. */
2141HWND mkctrl(frontend *fe, int x1, int x2, int y1, int y2, 2135HWND mkctrl(frontend *fe, int x1, int x2, int y1, int y2,
2142 LPCTSTR wclass, int wstyle, 2136 LPCTSTR wclass, int wstyle,
2143 int exstyle, const char *wtext, int wid) 2137 int exstyle, const char *wtext, INT_PTR wid)
2144{ 2138{
2145 RECT rc; 2139 RECT rc;
2146 TCHAR wwtext[256]; 2140 TCHAR wwtext[256];
@@ -2191,7 +2185,7 @@ static void create_config_controls(frontend * fe)
2191 mkctrl(fe, col2l, col2r, y, y + 12, 2185 mkctrl(fe, col2l, col2r, y, y + 12,
2192 TEXT("EDIT"), WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL, 2186 TEXT("EDIT"), WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL,
2193 0, "", (j->ctlid = id++)); 2187 0, "", (j->ctlid = id++));
2194 SetDlgItemTextA(fe->cfgbox, j->ctlid, i->sval); 2188 SetDlgItemTextA(fe->cfgbox, j->ctlid, i->u.string.sval);
2195 break; 2189 break;
2196 2190
2197 case C_BOOLEAN: 2191 case C_BOOLEAN:
@@ -2201,7 +2195,7 @@ static void create_config_controls(frontend * fe)
2201 mkctrl(fe, col1l, col2r, y + 1, y + 11, TEXT("BUTTON"), 2195 mkctrl(fe, col1l, col2r, y + 1, y + 11, TEXT("BUTTON"),
2202 BS_NOTIFY | BS_AUTOCHECKBOX | WS_TABSTOP, 2196 BS_NOTIFY | BS_AUTOCHECKBOX | WS_TABSTOP,
2203 0, i->name, (j->ctlid = id++)); 2197 0, i->name, (j->ctlid = id++));
2204 CheckDlgButton(fe->cfgbox, j->ctlid, (i->ival != 0)); 2198 CheckDlgButton(fe->cfgbox, j->ctlid, (i->u.boolean.bval != 0));
2205 break; 2199 break;
2206 2200
2207 case C_CHOICES: 2201 case C_CHOICES:
@@ -2215,9 +2209,11 @@ static void create_config_controls(frontend * fe)
2215 CBS_DROPDOWNLIST | CBS_HASSTRINGS, 2209 CBS_DROPDOWNLIST | CBS_HASSTRINGS,
2216 0, "", (j->ctlid = id++)); 2210 0, "", (j->ctlid = id++));
2217 { 2211 {
2218 char c, *p, *q, *str; 2212 char c;
2213 const char *p, *q;
2214 char *str;
2219 2215
2220 p = i->sval; 2216 p = i->u.choices.choicenames;
2221 c = *p++; 2217 c = *p++;
2222 while (*p) { 2218 while (*p) {
2223 q = p; 2219 q = p;
@@ -2236,7 +2232,7 @@ static void create_config_controls(frontend * fe)
2236 p = q; 2232 p = q;
2237 } 2233 }
2238 } 2234 }
2239 SendMessage(ctl, CB_SETCURSEL, i->ival, 0); 2235 SendMessage(ctl, CB_SETCURSEL, i->u.choices.selected, 0);
2240 break; 2236 break;
2241 } 2237 }
2242 2238
@@ -2282,7 +2278,8 @@ static int CALLBACK ConfigDlgProc(HWND hwnd, UINT msg,
2282 */ 2278 */
2283 if ((LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)) { 2279 if ((LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)) {
2284 if (LOWORD(wParam) == IDOK) { 2280 if (LOWORD(wParam) == IDOK) {
2285 char *err = frontend_set_config(fe, fe->cfg_which, fe->cfg); 2281 const char *err = frontend_set_config(
2282 fe, fe->cfg_which, fe->cfg);
2286 2283
2287 if (err) { 2284 if (err) {
2288 MessageBox(hwnd, err, "Validation error", 2285 MessageBox(hwnd, err, "Validation error",
@@ -2324,16 +2321,16 @@ static int CALLBACK ConfigDlgProc(HWND hwnd, UINT msg,
2324 GetDlgItemText(fe->cfgbox, j->ctlid, buffer, lenof(buffer)); 2321 GetDlgItemText(fe->cfgbox, j->ctlid, buffer, lenof(buffer));
2325#endif 2322#endif
2326 buffer[lenof(buffer)-1] = '\0'; 2323 buffer[lenof(buffer)-1] = '\0';
2327 sfree(i->sval); 2324 sfree(i->u.string.sval);
2328 i->sval = dupstr(buffer); 2325 i->u.string.sval = dupstr(buffer);
2329 } else if (i->type == C_BOOLEAN && 2326 } else if (i->type == C_BOOLEAN &&
2330 (HIWORD(wParam) == BN_CLICKED || 2327 (HIWORD(wParam) == BN_CLICKED ||
2331 HIWORD(wParam) == BN_DBLCLK)) { 2328 HIWORD(wParam) == BN_DBLCLK)) {
2332 i->ival = IsDlgButtonChecked(fe->cfgbox, j->ctlid); 2329 i->u.boolean.bval = IsDlgButtonChecked(fe->cfgbox, j->ctlid);
2333 } else if (i->type == C_CHOICES && 2330 } else if (i->type == C_CHOICES &&
2334 HIWORD(wParam) == CBN_SELCHANGE) { 2331 HIWORD(wParam) == CBN_SELCHANGE) {
2335 i->ival = SendDlgItemMessage(fe->cfgbox, j->ctlid, 2332 i->u.choices.selected = SendDlgItemMessage(fe->cfgbox, j->ctlid,
2336 CB_GETCURSEL, 0, 0); 2333 CB_GETCURSEL, 0, 0);
2337 } 2334 }
2338 2335
2339 return 0; 2336 return 0;
@@ -2349,7 +2346,7 @@ static int CALLBACK ConfigDlgProc(HWND hwnd, UINT msg,
2349#ifndef _WIN32_WCE 2346#ifndef _WIN32_WCE
2350HWND mkctrl(frontend *fe, int x1, int x2, int y1, int y2, 2347HWND mkctrl(frontend *fe, int x1, int x2, int y1, int y2,
2351 char *wclass, int wstyle, 2348 char *wclass, int wstyle,
2352 int exstyle, const char *wtext, int wid) 2349 int exstyle, const char *wtext, INT_PTR wid)
2353{ 2350{
2354 HWND ret; 2351 HWND ret;
2355 ret = CreateWindowEx(exstyle, wclass, wtext, 2352 ret = CreateWindowEx(exstyle, wclass, wtext,
@@ -2683,7 +2680,7 @@ static int get_config(frontend *fe, int which)
2683 ctl = mkctrl(fe, col2l, col2r, y, y+height*3/2, 2680 ctl = mkctrl(fe, col2l, col2r, y, y+height*3/2,
2684 "EDIT", WS_TABSTOP | ES_AUTOHSCROLL, 2681 "EDIT", WS_TABSTOP | ES_AUTOHSCROLL,
2685 WS_EX_CLIENTEDGE, "", (j->ctlid = id++)); 2682 WS_EX_CLIENTEDGE, "", (j->ctlid = id++));
2686 SetWindowText(ctl, i->sval); 2683 SetWindowText(ctl, i->u.string.sval);
2687 y += height*3/2; 2684 y += height*3/2;
2688 break; 2685 break;
2689 2686
@@ -2694,7 +2691,7 @@ static int get_config(frontend *fe, int which)
2694 mkctrl(fe, col1l, col2r, y, y+height, "BUTTON", 2691 mkctrl(fe, col1l, col2r, y, y+height, "BUTTON",
2695 BS_NOTIFY | BS_AUTOCHECKBOX | WS_TABSTOP, 2692 BS_NOTIFY | BS_AUTOCHECKBOX | WS_TABSTOP,
2696 0, i->name, (j->ctlid = id++)); 2693 0, i->name, (j->ctlid = id++));
2697 CheckDlgButton(fe->cfgbox, j->ctlid, (i->ival != 0)); 2694 CheckDlgButton(fe->cfgbox, j->ctlid, (i->u.boolean.bval != 0));
2698 y += height; 2695 y += height;
2699 break; 2696 break;
2700 2697
@@ -2709,10 +2706,12 @@ static int get_config(frontend *fe, int which)
2709 CBS_DROPDOWNLIST | CBS_HASSTRINGS, 2706 CBS_DROPDOWNLIST | CBS_HASSTRINGS,
2710 WS_EX_CLIENTEDGE, "", (j->ctlid = id++)); 2707 WS_EX_CLIENTEDGE, "", (j->ctlid = id++));
2711 { 2708 {
2712 char c, *p, *q, *str; 2709 char c;
2710 const char *p, *q;
2711 char *str;
2713 2712
2714 SendMessage(ctl, CB_RESETCONTENT, 0, 0); 2713 SendMessage(ctl, CB_RESETCONTENT, 0, 0);
2715 p = i->sval; 2714 p = i->u.choices.choicenames;
2716 c = *p++; 2715 c = *p++;
2717 while (*p) { 2716 while (*p) {
2718 q = p; 2717 q = p;
@@ -2727,7 +2726,7 @@ static int get_config(frontend *fe, int which)
2727 } 2726 }
2728 } 2727 }
2729 2728
2730 SendMessage(ctl, CB_SETCURSEL, i->ival, 0); 2729 SendMessage(ctl, CB_SETCURSEL, i->u.choices.selected, 0);
2731 2730
2732 y += height*3/2; 2731 y += height*3/2;
2733 break; 2732 break;
@@ -3019,7 +3018,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
3019 break; 3018 break;
3020 case IDM_SOLVE: 3019 case IDM_SOLVE:
3021 { 3020 {
3022 char *msg = midend_solve(fe->me); 3021 const char *msg = midend_solve(fe->me);
3023 if (msg) 3022 if (msg)
3024 MessageBox(hwnd, msg, "Unable to solve", 3023 MessageBox(hwnd, msg, "Unable to solve",
3025 MB_ICONERROR | MB_OK); 3024 MB_ICONERROR | MB_OK);
@@ -3111,7 +3110,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
3111 fclose(fp); 3110 fclose(fp);
3112 } else { 3111 } else {
3113 FILE *fp = fopen(filename, "r"); 3112 FILE *fp = fopen(filename, "r");
3114 char *err = NULL; 3113 const char *err = NULL;
3114 char *err_w = NULL;
3115 midend *me = fe->me; 3115 midend *me = fe->me;
3116#ifdef COMBINED 3116#ifdef COMBINED
3117 char *id_name; 3117 char *id_name;
@@ -3139,7 +3139,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
3139 "supported by this program"; 3139 "supported by this program";
3140 } else { 3140 } else {
3141 me = midend_for_new_game(fe, gamelist[i], NULL, 3141 me = midend_for_new_game(fe, gamelist[i], NULL,
3142 FALSE, FALSE, &err); 3142 FALSE, FALSE, &err_w);
3143 err = err_w;
3143 rewind(fp); /* for the actual load */ 3144 rewind(fp); /* for the actual load */
3144 } 3145 }
3145 sfree(id_name); 3146 sfree(id_name);
@@ -3152,6 +3153,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
3152 3153
3153 if (err) { 3154 if (err) {
3154 MessageBox(hwnd, err, "Error", MB_ICONERROR|MB_OK); 3155 MessageBox(hwnd, err, "Error", MB_ICONERROR|MB_OK);
3156 sfree(err_w);
3155 break; 3157 break;
3156 } 3158 }
3157 3159