+/*
+ * Wrappers on midend_{get,set}_config, which extend the CFG_*
+ * enumeration to add CFG_PRINT.
+ */
+static config_item *frontend_get_config(frontend *fe, int which,
+ char **wintitle)
+{
+ if (which < CFG_FRONTEND_SPECIFIC) {
+ return midend_get_config(fe->me, which, wintitle);
+ } else if (which == CFG_PRINT) {
+ config_item *ret;
+ int i;
+
+ *wintitle = snewn(40 + strlen(thegame.name), char);
+ sprintf(*wintitle, "%s print setup", thegame.name);
+
+ ret = snewn(8, config_item);
+
+ i = 0;
+
+ ret[i].name = "Number of puzzles to print";
+ ret[i].type = C_STRING;
+ ret[i].sval = dupstr("1");
+ ret[i].ival = 0;
+ i++;
+
+ ret[i].name = "Number of puzzles across the page";
+ ret[i].type = C_STRING;
+ ret[i].sval = dupstr("1");
+ ret[i].ival = 0;
+ i++;
+
+ ret[i].name = "Number of puzzles down the page";
+ ret[i].type = C_STRING;
+ ret[i].sval = dupstr("1");
+ ret[i].ival = 0;
+ i++;
+
+ ret[i].name = "Percentage of standard size";
+ ret[i].type = C_STRING;
+ ret[i].sval = dupstr("100.0");
+ ret[i].ival = 0;
+ i++;
+
+ ret[i].name = "Include currently shown puzzle";
+ ret[i].type = C_BOOLEAN;
+ ret[i].sval = NULL;
+ ret[i].ival = TRUE;
+ i++;
+
+ ret[i].name = "Print solutions";
+ ret[i].type = C_BOOLEAN;
+ ret[i].sval = NULL;
+ ret[i].ival = FALSE;
+ i++;
+
+ if (thegame.can_print_in_colour) {
+ ret[i].name = "Print in colour";
+ ret[i].type = C_BOOLEAN;
+ ret[i].sval = NULL;
+ ret[i].ival = FALSE;
+ i++;
+ }
+
+ ret[i].name = NULL;
+ ret[i].type = C_END;
+ ret[i].sval = NULL;
+ ret[i].ival = 0;
+ i++;
+
+ return ret;
+ } else {
+ assert(!"We should never get here");
+ return NULL;
+ }
+}
+
+static char *frontend_set_config(frontend *fe, int which, config_item *cfg)
+{
+ if (which < CFG_FRONTEND_SPECIFIC) {
+ return midend_set_config(fe->me, which, cfg);
+ } else if (which == CFG_PRINT) {
+ if ((fe->printcount = atoi(cfg[0].sval)) <= 0)
+ return "Number of puzzles to print should be at least one";
+ if ((fe->printw = atoi(cfg[1].sval)) <= 0)
+ return "Number of puzzles across the page should be at least one";
+ if ((fe->printh = atoi(cfg[2].sval)) <= 0)
+ return "Number of puzzles down the page should be at least one";
+ if ((fe->printscale = (float)atof(cfg[3].sval)) <= 0)
+ return "Print size should be positive";
+ fe->printcurr = cfg[4].ival;
+ fe->printsolns = cfg[5].ival;
+ fe->printcolour = thegame.can_print_in_colour && cfg[6].ival;
+ return NULL;
+ } else {
+ assert(!"We should never get here");
+ return "Internal error";
+ }
+}
+
+#ifdef _WIN32_WCE
+/* Separate version of mkctrl function for the Pocket PC. */
+/* Control coordinates should be specified in dialog units. */
+HWND mkctrl(frontend *fe, int x1, int x2, int y1, int y2,
+ LPCTSTR wclass, int wstyle,
+ int exstyle, const char *wtext, int wid)
+{
+ RECT rc;
+ TCHAR wwtext[256];
+
+ /* Convert dialog units into pixels */
+ rc.left = x1; rc.right = x2;
+ rc.top = y1; rc.bottom = y2;
+ MapDialogRect(fe->cfgbox, &rc);
+
+ MultiByteToWideChar (CP_ACP, 0, wtext, -1, wwtext, 256);
+
+ return CreateWindowEx(exstyle, wclass, wwtext,
+ wstyle | WS_CHILD | WS_VISIBLE,
+ rc.left, rc.top,
+ rc.right - rc.left, rc.bottom - rc.top,
+ fe->cfgbox, (HMENU) wid, fe->inst, NULL);
+}
+
+static void create_config_controls(frontend * fe)
+{
+ int id, nctrls;
+ int col1l, col1r, col2l, col2r, y;
+ config_item *i;
+ struct cfg_aux *j;
+ HWND ctl;
+
+ /* Control placement done in dialog units */
+ col1l = 4; col1r = 96; /* Label column */
+ col2l = 100; col2r = 154; /* Input column (edit boxes and combo boxes) */
+
+ /*
+ * Count the controls so we can allocate cfgaux.
+ */
+ for (nctrls = 0, i = fe->cfg; i->type != C_END; i++)
+ nctrls++;
+ fe->cfgaux = snewn(nctrls, struct cfg_aux);
+
+ id = 1000;
+ y = 22; /* Leave some room for the dialog title */
+ for (i = fe->cfg, j = fe->cfgaux; i->type != C_END; i++, j++) {
+ switch (i->type) {
+ case C_STRING:
+ /*
+ * Edit box with a label beside it.
+ */
+ mkctrl(fe, col1l, col1r, y + 1, y + 11,
+ TEXT("Static"), SS_LEFTNOWORDWRAP, 0, i->name, id++);
+ mkctrl(fe, col2l, col2r, y, y + 12,
+ TEXT("EDIT"), WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL,
+ 0, "", (j->ctlid = id++));
+ SetDlgItemTextA(fe->cfgbox, j->ctlid, i->sval);
+ break;
+
+ case C_BOOLEAN:
+ /*
+ * Simple checkbox.
+ */
+ mkctrl(fe, col1l, col2r, y + 1, y + 11, TEXT("BUTTON"),
+ BS_NOTIFY | BS_AUTOCHECKBOX | WS_TABSTOP,
+ 0, i->name, (j->ctlid = id++));
+ CheckDlgButton(fe->cfgbox, j->ctlid, (i->ival != 0));
+ break;
+
+ case C_CHOICES:
+ /*
+ * Drop-down list with a label beside it.
+ */
+ mkctrl(fe, col1l, col1r, y + 1, y + 11,
+ TEXT("STATIC"), SS_LEFTNOWORDWRAP, 0, i->name, id++);
+ ctl = mkctrl(fe, col2l, col2r, y, y + 48,
+ TEXT("COMBOBOX"), WS_BORDER | WS_TABSTOP |
+ CBS_DROPDOWNLIST | CBS_HASSTRINGS,
+ 0, "", (j->ctlid = id++));
+ {
+ char c, *p, *q, *str;
+
+ p = i->sval;
+ c = *p++;
+ while (*p) {
+ q = p;
+ while (*q && *q != c) q++;
+ str = snewn(q-p+1, char);
+ strncpy(str, p, q-p);
+ str[q-p] = '\0';
+ {
+ TCHAR ws[50];
+ MultiByteToWideChar (CP_ACP, 0, str, -1, ws, 50);
+ SendMessage(ctl, CB_ADDSTRING, 0, (LPARAM)ws);
+ }
+
+ sfree(str);
+ if (*q) q++;
+ p = q;
+ }
+ }
+ SendMessage(ctl, CB_SETCURSEL, i->ival, 0);
+ break;
+ }
+
+ y += 15;
+ }
+
+}
+#endif
+