X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/0572b5d879aec3454751a88f8171c212236c77e0..48a10826fef7777bb8b061f4a121f481ced98bc0:/windows.c diff --git a/windows.c b/windows.c index 127311e..f503bdc 100644 --- a/windows.c +++ b/windows.c @@ -27,11 +27,13 @@ #define IDM_RESTART 0x0020 #define IDM_UNDO 0x0030 #define IDM_REDO 0x0040 -#define IDM_QUIT 0x0050 -#define IDM_CONFIG 0x0060 -#define IDM_SEED 0x0070 -#define IDM_HELPC 0x0080 -#define IDM_GAMEHELP 0x0090 +#define IDM_COPY 0x0050 +#define IDM_SOLVE 0x0060 +#define IDM_QUIT 0x0070 +#define IDM_CONFIG 0x0080 +#define IDM_SEED 0x0090 +#define IDM_HELPC 0x00A0 +#define IDM_GAMEHELP 0x00B0 #define IDM_PRESETS 0x0100 #define HELP_FILE_NAME "puzzles.hlp" @@ -154,18 +156,12 @@ void frontend_default_colour(frontend *fe, float *output) void clip(frontend *fe, int x, int y, int w, int h) { - if (!fe->clip) { - fe->clip = CreateRectRgn(0, 0, 1, 1); - GetClipRgn(fe->hdc_bm, fe->clip); - } - IntersectClipRect(fe->hdc_bm, x, y, x+w, y+h); } void unclip(frontend *fe) { - assert(fe->clip); - SelectClipRgn(fe->hdc_bm, fe->clip); + SelectClipRgn(fe->hdc_bm, NULL); } void draw_text(frontend *fe, int x, int y, int fonttype, int fontsize, @@ -191,11 +187,7 @@ void draw_text(frontend *fe, int x, int y, int fonttype, int fontsize, fe->fonts[i].type = fonttype; fe->fonts[i].size = fontsize; - /* - * FIXME: Really I should make at least _some_ effort to - * pick the correct font. - */ - fe->fonts[i].font = CreateFont(-fontsize, 0, 0, 0, 0, + fe->fonts[i].font = CreateFont(-fontsize, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, @@ -335,6 +327,53 @@ void activate_timer(frontend *fe) } } +void write_clip(HWND hwnd, char *data) +{ + HGLOBAL clipdata; + int len, i, j; + char *data2; + void *lock; + + /* + * Windows expects CRLF in the clipboard, so we must convert + * any \n that has come out of the puzzle backend. + */ + len = 0; + for (i = 0; data[i]; i++) { + if (data[i] == '\n') + len++; + len++; + } + data2 = snewn(len+1, char); + j = 0; + for (i = 0; data[i]; i++) { + if (data[i] == '\n') + data2[j++] = '\r'; + data2[j++] = data[i]; + } + assert(j == len); + data2[j] = '\0'; + + clipdata = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, len + 1); + if (!clipdata) + return; + lock = GlobalLock(clipdata); + if (!lock) + return; + memcpy(lock, data2, len); + ((unsigned char *) lock)[len] = 0; + GlobalUnlock(clipdata); + + if (OpenClipboard(hwnd)) { + EmptyClipboard(); + SetClipboardData(CF_TEXT, clipdata); + CloseClipboard(); + } else + GlobalFree(clipdata); + + sfree(data2); +} + /* * See if we can find a help file. */ @@ -468,6 +507,14 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error) AppendMenu(menu, MF_SEPARATOR, 0, 0); AppendMenu(menu, MF_ENABLED, IDM_UNDO, "Undo"); AppendMenu(menu, MF_ENABLED, IDM_REDO, "Redo"); + if (thegame.can_format_as_text) { + AppendMenu(menu, MF_SEPARATOR, 0, 0); + AppendMenu(menu, MF_ENABLED, IDM_COPY, "Copy"); + } + if (thegame.can_solve) { + AppendMenu(menu, MF_SEPARATOR, 0, 0); + AppendMenu(menu, MF_ENABLED, IDM_SOLVE, "Solve"); + } AppendMenu(menu, MF_SEPARATOR, 0, 0); AppendMenu(menu, MF_ENABLED, IDM_QUIT, "Exit"); if (fe->help_path) { @@ -902,6 +949,24 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, if (!midend_process_key(fe->me, 0, 0, '\x12')) PostQuitMessage(0); break; + case IDM_COPY: + { + char *text = midend_text_format(fe->me); + if (text) + write_clip(hwnd, text); + else + MessageBeep(MB_ICONWARNING); + sfree(text); + } + break; + case IDM_SOLVE: + { + char *msg = midend_solve(fe->me); + if (msg) + MessageBox(hwnd, msg, "Unable to solve", + MB_ICONERROR | MB_OK); + } + break; case IDM_QUIT: if (!midend_process_key(fe->me, 0, 0, 'q')) PostQuitMessage(0);