summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2012-08-03 19:19:04 +0100
committerChris Young <chris@unsatisfactorysoftware.co.uk>2012-08-03 19:19:04 +0100
commit0b0c6a4f6ae8d04546028f42440054508c6121d0 (patch)
treef940f51e36cc2e5234af73f0a5e3e3eeeed8fabf
parentc4a412604106e06ca4a0e59c6f7279d1e4b182a4 (diff)
downloadnetsurf-0b0c6a4f6ae8d04546028f42440054508c6121d0.tar.gz
netsurf-0b0c6a4f6ae8d04546028f42440054508c6121d0.tar.bz2
Support pasting the UTF8 chunk of clipboard IFF FTXT when present, instead of CHRS
-rwxr-xr-xamiga/clipboard.c44
1 files changed, 39 insertions, 5 deletions
diff --git a/amiga/clipboard.c b/amiga/clipboard.c
index 6c91f95e6..66a4da2e0 100755
--- a/amiga/clipboard.c
+++ b/amiga/clipboard.c
@@ -108,6 +108,22 @@ void gui_clear_selection(struct gui_window *g)
OffMenu(g->shared->win, AMI_MENU_COPY);
}
+bool ami_clipboard_check_for_utf8(struct IFFHandle *iffh) {
+ struct ContextNode *cn;
+ ULONG error;
+ bool utf8_chunk = false;
+
+ if(OpenIFF(iffh, IFFF_READ)) return false;
+ if(!StopChunk(iffh, ID_FTXT, ID_UTF8)) {
+ error = ParseIFF(iffh, IFFPARSE_SCAN);
+ if(error != IFFERR_EOF)
+ utf8_chunk = true; /* or a real error, but that'll get caught later */
+ }
+ CloseIFF(iffh);
+
+ return utf8_chunk;
+}
+
void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
{
/* This and the other clipboard code is heavily based on the RKRM examples */
@@ -116,14 +132,23 @@ void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
struct CSet cset;
LONG codeset = 0;
char *clip;
+ bool utf8_chunks = false;
STRPTR readbuf = AllocVec(1024,MEMF_PRIVATE | MEMF_CLEAR);
cset.CodeSet = 0;
+ if(ami_clipboard_check_for_utf8(iffh))
+ utf8_chunks = true;
+
if(OpenIFF(iffh,IFFF_READ)) return;
- if(StopChunk(iffh,ID_FTXT,ID_CHRS)) return;
- if(StopChunk(iffh,ID_FTXT,ID_CSET)) return;
-
+
+ if(utf8_chunks == false) {
+ if(StopChunk(iffh,ID_FTXT,ID_CHRS)) return;
+ if(StopChunk(iffh,ID_FTXT,ID_CSET)) return;
+ } else {
+ if(StopChunk(iffh,ID_FTXT,ID_UTF8)) return;
+ }
+
while(1)
{
error = ParseIFF(iffh,IFFPARSE_SCAN);
@@ -132,14 +157,14 @@ void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
cn = CurrentChunk(iffh);
- if((cn)&&(cn->cn_Type == ID_FTXT)&&(cn->cn_ID == ID_CSET))
+ if((cn)&&(cn->cn_Type == ID_FTXT)&&(cn->cn_ID == ID_CSET)&&(utf8_chunks == false))
{
rlen = ReadChunkBytes(iffh,&cset,32);
if(cset.CodeSet == 1) codeset = 106;
else codeset = cset.CodeSet;
}
- if((cn)&&(cn->cn_Type == ID_FTXT)&&(cn->cn_ID == ID_CHRS))
+ if((cn)&&(cn->cn_Type == ID_FTXT)&&(cn->cn_ID == ID_CHRS)&&(utf8_chunks == false))
{
while((rlen = ReadChunkBytes(iffh,readbuf,1024)) > 0)
{
@@ -159,6 +184,15 @@ void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
}
if(rlen < 0) error = rlen;
}
+
+ if((cn)&&(cn->cn_Type == ID_FTXT)&&(cn->cn_ID == ID_UTF8)&&(utf8_chunks == true))
+ {
+ while((rlen = ReadChunkBytes(iffh, readbuf, 1024)) > 0)
+ {
+ browser_window_paste_text(g->shared->bw, readbuf, rlen, true);
+ }
+ if(rlen < 0) error = rlen;
+ }
}
CloseIFF(iffh);
}