aboutsummaryrefslogtreecommitdiff
path: root/emcc.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-07-05 19:39:57 +0100
committerBen Harris <bjh21@bjh21.me.uk>2023-07-05 19:39:57 +0100
commitad7042db989eb525defea9298b2b14d564498473 (patch)
tree2745e325e200d421f881ed28c555ea3a75f2a980 /emcc.c
parentc8cc4a5f387774c35e3e8f924d4200c0908c9d5a (diff)
downloadpuzzles-ad7042db989eb525defea9298b2b14d564498473.zip
puzzles-ad7042db989eb525defea9298b2b14d564498473.tar.gz
puzzles-ad7042db989eb525defea9298b2b14d564498473.tar.bz2
puzzles-ad7042db989eb525defea9298b2b14d564498473.tar.xz
js: Copy-to-clipboard support
Now using the browser's "copy" operation while the focus is in the puzzle will copy the puzzle state to the clipboard. Browsers seem to have odd ideas about whate element to target with the "copy" event: Firefox targets the parent of the <canvas> while Chromium targets the <body>. To cope with these and possible future weirdness I attach the event handler to the document and then look to see if it's plausibly related to the canvas. Arguably we might want to handle a wider range of "copy" events, maybe any where the selection isn't empty. I'm not sure, though, so we'll start with the minimal change.
Diffstat (limited to 'emcc.c')
-rw-r--r--emcc.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/emcc.c b/emcc.c
index 7d7a09b..2f82878 100644
--- a/emcc.c
+++ b/emcc.c
@@ -115,6 +115,8 @@ bool key(int keycode, const char *key, const char *chr, int location,
bool shift, bool ctrl);
void timer_callback(double tplus);
void command(int n);
+char *get_text_format(void);
+void free_save_file(char *buffer);
char *get_save_file(void);
void free_save_file(char *buffer);
void load_game(void);
@@ -880,6 +882,16 @@ void command(int n)
}
}
+char *get_text_format(void)
+{
+ return midend_text_format(me);
+}
+
+void free_text_format(char *buffer)
+{
+ sfree(buffer);
+}
+
/* ----------------------------------------------------------------------
* Called from JS to prepare a save-game file, and free one after it's
* been used.