+ sfree(colours);
+ }
+
+ if (fe->statusbar)
+ DestroyWindow(fe->statusbar);
+ if (midend_wants_statusbar(fe->me)) {
+ fe->statusbar = CreateWindowEx(0, STATUSCLASSNAME, TEXT("ooh"),
+ WS_CHILD | WS_VISIBLE,
+ 0, 0, 0, 0, /* status bar does these */
+ NULL, NULL, fe->inst, NULL);
+ } else
+ fe->statusbar = NULL;
+
+ get_max_puzzle_size(fe, &x, &y);
+ midend_size(fe->me, &x, &y, FALSE);
+
+ r.left = r.top = 0;
+ r.right = x;
+ r.bottom = y;
+ AdjustWindowRectEx(&r, WINFLAGS, TRUE, 0);
+
+#ifdef _WIN32_WCE
+ if (fe->numpad)
+ DestroyWindow(fe->numpad);
+ if (fe->game->flags & REQUIRE_NUMPAD)
+ {
+ fe->numpad = CreateToolbarEx (fe->hwnd,
+ WS_VISIBLE | WS_CHILD | CCS_NOPARENTALIGN | TBSTYLE_FLAT,
+ 0, 10, fe->inst, IDR_PADTOOLBAR,
+ tbNumpadButtons, sizeof (tbNumpadButtons) / sizeof (TBBUTTON),
+ 0, 0, 14, 15, sizeof (TBBUTTON));
+ GetWindowRect(fe->numpad, &rcTB);
+ GetClientRect(fe->hwnd, &rcClient);
+ MoveWindow(fe->numpad,
+ 0,
+ rcClient.bottom - (rcTB.bottom - rcTB.top) - 1,
+ rcClient.right,
+ rcTB.bottom - rcTB.top,
+ FALSE);
+ SendMessage(fe->numpad, TB_SETINDENT, (rcClient.right - (10 * 21)) / 2, 0);
+ }
+ else {
+ fe->numpad = NULL;
+ }
+ MultiByteToWideChar (CP_ACP, 0, fe->game->name, -1, wGameName, 256);
+ SetWindowText(fe->hwnd, wGameName);
+#else
+ SetWindowText(fe->hwnd, fe->game->name);
+#endif
+
+ if (fe->statusbar)
+ DestroyWindow(fe->statusbar);
+ if (midend_wants_statusbar(fe->me)) {
+ RECT sr;
+ fe->statusbar = CreateWindowEx(0, STATUSCLASSNAME, TEXT("ooh"),
+ WS_CHILD | WS_VISIBLE,
+ 0, 0, 0, 0, /* status bar does these */
+ fe->hwnd, NULL, fe->inst, NULL);
+#ifdef _WIN32_WCE
+ /* Flat status bar looks better on the Pocket PC */
+ SendMessage(fe->statusbar, SB_SIMPLE, (WPARAM) TRUE, 0);
+ SendMessage(fe->statusbar, SB_SETTEXT,
+ (WPARAM) 255 | SBT_NOBORDERS,
+ (LPARAM) L"");
+#endif
+
+ /*
+ * Now resize the window to take account of the status bar.
+ */
+ GetWindowRect(fe->statusbar, &sr);
+ GetWindowRect(fe->hwnd, &r);
+#ifndef _WIN32_WCE
+ SetWindowPos(fe->hwnd, NULL, 0, 0, r.right - r.left,
+ r.bottom - r.top + sr.bottom - sr.top,
+ SWP_NOMOVE | SWP_NOZORDER);
+#endif
+ } else {
+ fe->statusbar = NULL;
+ }
+
+ {
+ HMENU oldmenu = GetMenu(fe->hwnd);
+
+#ifndef _WIN32_WCE
+ HMENU bar = CreateMenu();
+ HMENU menu = CreateMenu();
+ RECT menusize;
+
+ AppendMenu(bar, MF_ENABLED|MF_POPUP, (UINT)menu, "&Game");
+#else
+ HMENU menu = SHGetSubMenu(SHFindMenuBar(fe->hwnd), ID_GAME);
+ DeleteMenu(menu, 0, MF_BYPOSITION);
+#endif
+ fe->gamemenu = menu;
+ AppendMenu(menu, MF_ENABLED, IDM_NEW, TEXT("&New"));
+ AppendMenu(menu, MF_ENABLED, IDM_RESTART, TEXT("&Restart"));
+#ifndef _WIN32_WCE
+ /* ...here I run out of sensible accelerator characters. */
+ AppendMenu(menu, MF_ENABLED, IDM_DESC, TEXT("Speci&fic..."));
+ AppendMenu(menu, MF_ENABLED, IDM_SEED, TEXT("Rando&m Seed..."));
+#endif
+
+ if (fe->presets)
+ sfree(fe->presets);
+ if ((fe->npresets = midend_num_presets(fe->me)) > 0 ||
+ fe->game->can_configure) {
+ int i;
+#ifndef _WIN32_WCE
+ HMENU sub = CreateMenu();
+
+ AppendMenu(bar, MF_ENABLED|MF_POPUP, (UINT)sub, "&Type");
+#else
+ HMENU sub = SHGetSubMenu(SHFindMenuBar(fe->hwnd), ID_TYPE);
+ DeleteMenu(sub, 0, MF_BYPOSITION);
+#endif
+ fe->presets = snewn(fe->npresets, game_params *);
+
+ for (i = 0; i < fe->npresets; i++) {
+ char *name;
+#ifdef _WIN32_WCE
+ TCHAR wName[255];
+#endif
+
+ midend_fetch_preset(fe->me, i, &name, &fe->presets[i]);
+
+ /*
+ * FIXME: we ought to go through and do something
+ * with ampersands here.
+ */
+
+#ifndef _WIN32_WCE
+ AppendMenu(sub, MF_ENABLED, IDM_PRESETS + 0x10 * i, name);
+#else
+ MultiByteToWideChar (CP_ACP, 0, name, -1, wName, 255);
+ AppendMenu(sub, MF_ENABLED, IDM_PRESETS + 0x10 * i, wName);
+#endif
+ }
+ if (fe->game->can_configure) {
+ AppendMenu(sub, MF_ENABLED, IDM_CONFIG, TEXT("&Custom..."));
+ }
+
+ fe->typemenu = sub;
+ } else {
+ fe->typemenu = INVALID_HANDLE_VALUE;
+ fe->presets = NULL;
+ }
+
+#ifdef COMBINED
+#ifdef _WIN32_WCE
+#error Windows CE does not support COMBINED build.
+#endif
+ {
+ HMENU games = CreateMenu();
+ int i;
+
+ AppendMenu(menu, MF_SEPARATOR, 0, 0);
+ AppendMenu(menu, MF_ENABLED|MF_POPUP, (UINT)games, "&Other");
+ for (i = 0; i < gamecount; i++) {
+ if (strcmp(gamelist[i]->name, fe->game->name) != 0) {
+ /* only include those games that aren't the same as the
+ * game we're currently playing. */
+ AppendMenu(games, MF_ENABLED, IDM_GAMES + i, gamelist[i]->name);
+ }
+ }
+ }
+#endif
+
+ AppendMenu(menu, MF_SEPARATOR, 0, 0);
+#ifndef _WIN32_WCE
+ AppendMenu(menu, MF_ENABLED, IDM_LOAD, TEXT("&Load..."));
+ AppendMenu(menu, MF_ENABLED, IDM_SAVE, TEXT("&Save..."));
+ AppendMenu(menu, MF_SEPARATOR, 0, 0);
+ if (fe->game->can_print) {
+ AppendMenu(menu, MF_ENABLED, IDM_PRINT, TEXT("&Print..."));
+ AppendMenu(menu, MF_SEPARATOR, 0, 0);
+ }
+#endif
+ AppendMenu(menu, MF_ENABLED, IDM_UNDO, TEXT("Undo"));
+ AppendMenu(menu, MF_ENABLED, IDM_REDO, TEXT("Redo"));
+#ifndef _WIN32_WCE
+ if (fe->game->can_format_as_text_ever) {
+ AppendMenu(menu, MF_SEPARATOR, 0, 0);
+ AppendMenu(menu, MF_ENABLED, IDM_COPY, TEXT("&Copy"));
+ }
+#endif
+ if (fe->game->can_solve) {
+ AppendMenu(menu, MF_SEPARATOR, 0, 0);
+ AppendMenu(menu, MF_ENABLED, IDM_SOLVE, TEXT("Sol&ve"));
+ }
+ AppendMenu(menu, MF_SEPARATOR, 0, 0);
+#ifndef _WIN32_WCE
+ AppendMenu(menu, MF_ENABLED, IDM_QUIT, TEXT("E&xit"));
+ menu = CreateMenu();
+ AppendMenu(bar, MF_ENABLED|MF_POPUP, (UINT)menu, TEXT("&Help"));
+#endif
+ AppendMenu(menu, MF_ENABLED, IDM_ABOUT, TEXT("&About"));
+#ifndef _WIN32_WCE
+ if (help_type != NONE) {
+ char *item;
+ AppendMenu(menu, MF_SEPARATOR, 0, 0);
+ AppendMenu(menu, MF_ENABLED, IDM_HELPC, TEXT("&Contents"));
+ assert(fe->game->name);
+ item = snewn(10+strlen(fe->game->name), char); /*ick*/
+ sprintf(item, "&Help on %s", fe->game->name);
+ AppendMenu(menu, MF_ENABLED, IDM_GAMEHELP, item);
+ sfree(item);
+ }
+ DestroyMenu(oldmenu);
+ SetMenu(fe->hwnd, bar);
+ get_menu_size(fe->hwnd, &menusize);
+ fe->xmin = (menusize.right - menusize.left) + 25;
+#endif
+ }
+
+ if (fe->bitmap) DeleteObject(fe->bitmap);
+ fe->bitmap = NULL;
+ new_game_size(fe, fe->puzz_scale); /* initialises fe->bitmap */
+
+ return 0;
+}
+
+static void show_window(frontend *fe)
+{
+ ShowWindow(fe->hwnd, SW_SHOWNORMAL);
+ SetForegroundWindow(fe->hwnd);
+
+ update_type_menu_tick(fe);
+ update_copy_menu_greying(fe);
+
+ midend_redraw(fe->me);
+}
+
+#ifdef _WIN32_WCE
+static HFONT dialog_title_font()
+{
+ static HFONT hf = NULL;
+ LOGFONT lf;
+
+ if (hf)
+ return hf;
+
+ memset (&lf, 0, sizeof(LOGFONT));
+ lf.lfHeight = -11; /* - ((8 * GetDeviceCaps(hdc, LOGPIXELSY)) / 72) */
+ lf.lfWeight = FW_BOLD;
+ wcscpy(lf.lfFaceName, TEXT("Tahoma"));
+
+ return hf = CreateFontIndirect(&lf);
+}
+
+static void make_dialog_full_screen(HWND hwnd)
+{
+ SHINITDLGINFO shidi;
+
+ /* Make dialog full screen */
+ shidi.dwMask = SHIDIM_FLAGS;
+ shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIZEDLGFULLSCREEN |
+ SHIDIF_EMPTYMENU;
+ shidi.hDlg = hwnd;
+ SHInitDialog(&shidi);
+}
+#endif
+
+static int CALLBACK AboutDlgProc(HWND hwnd, UINT msg,
+ WPARAM wParam, LPARAM lParam)
+{
+ frontend *fe = (frontend *)GetWindowLong(hwnd, GWL_USERDATA);
+
+ switch (msg) {
+ case WM_INITDIALOG:
+#ifdef _WIN32_WCE
+ {
+ char title[256];
+
+ make_dialog_full_screen(hwnd);
+
+ sprintf(title, "About %.250s", fe->game->name);
+ SetDlgItemTextA(hwnd, IDC_ABOUT_CAPTION, title);
+
+ SendDlgItemMessage(hwnd, IDC_ABOUT_CAPTION, WM_SETFONT,
+ (WPARAM) dialog_title_font(), 0);
+
+ SetDlgItemTextA(hwnd, IDC_ABOUT_GAME, fe->game->name);
+ SetDlgItemTextA(hwnd, IDC_ABOUT_VERSION, ver);
+ }
+#endif
+ return TRUE;
+
+ case WM_COMMAND:
+ if (LOWORD(wParam) == IDOK)
+#ifdef _WIN32_WCE
+ EndDialog(hwnd, 1);
+#else
+ fe->dlg_done = 1;
+#endif
+ return 0;
+
+ case WM_CLOSE:
+#ifdef _WIN32_WCE
+ EndDialog(hwnd, 1);
+#else
+ fe->dlg_done = 1;
+#endif
+ return 0;
+ }
+
+ return 0;
+}
+
+/*
+ * 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(fe->game->name), char);
+ sprintf(*wintitle, "%s print setup", fe->game->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 (fe->game->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;