From 5bae5edd7b55822261100622e608c7c73ee69a2b Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 2 Apr 2010 16:25:55 +0000 Subject: Use DataTypes to read text files that are dropped into text boxes, this allows more exotic formats to be read such as IFF FTXT. svn path=/trunk/netsurf/; revision=10229 --- amiga/gui.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'amiga/gui.c') diff --git a/amiga/gui.c b/amiga/gui.c index b64a7fd01..efc61a40d 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -79,7 +79,7 @@ #include /* Other OS includes */ -#include +#include #include #include #include @@ -87,7 +87,6 @@ #include #include #include -#include #include /* ReAction libraries */ @@ -1606,24 +1605,45 @@ void ami_handle_appmsg(void) } else { - browser_window_mouse_click(gwin->bw, BROWSER_MOUSE_PRESS_1, x,y); - /* This bit pastes a plain text file into a form. Really we should be using - Datatypes for this to support more formats */ + Object *dto; + STRPTR buffer; + uint32 bufferlen; - if(fh = FOpen(filename,MODE_OLDFILE,0)) + browser_window_mouse_click(gwin->bw, BROWSER_MOUSE_PRESS_1, x, y); + + if(dto = NewDTObject(filename, + DTA_GroupID, GID_TEXT, TAG_DONE)) { - while(len = FRead(fh,filename,1,1024)) + if(GetDTAttrs(dto, + TDTA_Buffer, &buffer, + TDTA_BufferLen, &bufferlen, + TAG_DONE)) { - if(utf8_from_local_encoding(filename,len,&utf8text) == UTF8_CONVERT_OK) + uint32 bufferlen2 = 256; + int32 blen; + + blen = bufferlen; + + do { - browser_window_paste_text(gwin->bw,utf8text,strlen(utf8text),true); - free(utf8text); - } + if(blen < 256) bufferlen2 = blen; + + if(utf8_from_local_encoding(buffer, + bufferlen2, + &utf8text) == UTF8_CONVERT_OK) + { + browser_window_paste_text(gwin->bw, + utf8text, strlen(utf8text), + (blen <= 256) ? true : false); + free(utf8text); + } + buffer += 256; + blen -= 256; + }while(blen > 0); } - FClose(fh); + DisposeDTObject(dto); } } - } FreeVec(filename); } -- cgit v1.2.3