+/*
+ * Given a proposed new window rect, work out the resulting
+ * difference in client size (from current), and use to try
+ * and resize the puzzle, returning (wx,wy) as the actual
+ * new window size.
+ */
+
+static void adjust_game_size(frontend *fe, RECT *proposed, int isedge,
+ int *wx_r, int *wy_r)
+{
+ RECT cr, wr;
+ int nx, ny, xdiff, ydiff, wx, wy;
+
+ /* Work out the current window sizing, and thus the
+ * difference in size we're asking for. */
+ GetClientRect(fe->hwnd, &cr);
+ wr = cr;
+ AdjustWindowRectEx(&wr, WINFLAGS, TRUE, 0);
+
+ xdiff = (proposed->right - proposed->left) - (wr.right - wr.left);
+ ydiff = (proposed->bottom - proposed->top) - (wr.bottom - wr.top);
+
+ if (isedge) {
+ /* These next four lines work around the fact that midend_size
+ * is happy to shrink _but not grow_ if you change one dimension
+ * but not the other. */
+ if (xdiff > 0 && ydiff == 0)
+ ydiff = (xdiff * (wr.right - wr.left)) / (wr.bottom - wr.top);
+ if (xdiff == 0 && ydiff > 0)
+ xdiff = (ydiff * (wr.bottom - wr.top)) / (wr.right - wr.left);
+ }
+
+ if (check_window_resize(fe,
+ (cr.right - cr.left) + xdiff,
+ (cr.bottom - cr.top) + ydiff,
+ &nx, &ny, &wx, &wy)) {
+ new_bitmap(fe, nx, ny);
+ midend_force_redraw(fe->me);
+ } else {
+ /* reset size to current window size */
+ wx = wr.right - wr.left;
+ wy = wr.bottom - wr.top;
+ }
+ /* Re-fetch rectangle; size limits mean we might not have
+ * taken it quite to the mouse drag positions. */
+ GetClientRect(fe->hwnd, &cr);
+ adjust_statusbar(fe, &cr);
+
+ *wx_r = wx; *wy_r = wy;
+}
+
+static void update_type_menu_tick(frontend *fe)
+{
+ int total, n, i;
+
+ if (fe->typemenu == INVALID_HANDLE_VALUE)
+ return;
+
+ total = GetMenuItemCount(fe->typemenu);
+ n = midend_which_preset(fe->me);
+ if (n < 0)
+ n = total - 1; /* "Custom" item */
+
+ for (i = 0; i < total; i++) {
+ int flag = (i == n ? MF_CHECKED : MF_UNCHECKED);
+ CheckMenuItem(fe->typemenu, i, MF_BYPOSITION | flag);
+ }
+
+ DrawMenuBar(fe->hwnd);
+}
+
+static void update_copy_menu_greying(frontend *fe)
+{
+ UINT enable = (midend_can_format_as_text_now(fe->me) ?
+ MF_ENABLED : MF_GRAYED);
+ EnableMenuItem(fe->gamemenu, IDM_COPY, MF_BYCOMMAND | enable);
+}
+