Added file upload / file dragdrop

svn path=/trunk/netsurf/; revision=11621
This commit is contained in:
Ole Loots 2011-02-05 14:32:15 +00:00
parent 096e638b8c
commit d7745d59bd
6 changed files with 701 additions and 8 deletions

View File

@ -40,7 +40,7 @@ S_ATARI := gui.c findfile.c filetype.c misc.c bitmap.c schedule.c \
plot.c plot/plotter.c plot/plotter_vdi.c plot/eddi.s \ plot.c plot/plotter.c plot/plotter_vdi.c plot/eddi.s \
plot/font_vdi.c plot/font_freetype.c \ plot/font_vdi.c plot/font_freetype.c \
browser_win.c toolbar.c statusbar.c browser.c \ browser_win.c toolbar.c statusbar.c browser.c \
global_evnt.c osspec.c system_colour.c global_evnt.c osspec.c dragdrop.c system_colour.c
S_ATARI := $(addprefix atari/,$(S_ATARI)) S_ATARI := $(addprefix atari/,$(S_ATARI))

View File

@ -27,6 +27,7 @@
#include <windom.h> #include <windom.h>
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#include <osbind.h>
#include "utils/log.h" #include "utils/log.h"
#include "desktop/gui.h" #include "desktop/gui.h"
@ -35,7 +36,13 @@
#include "desktop/browser.h" #include "desktop/browser.h"
#include "desktop/mouse.h" #include "desktop/mouse.h"
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "desktop/textinput.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "content/urldb.h"
#include "css/css.h"
#include "render/box.h"
#include "render/form.h"
#include "atari/gui.h" #include "atari/gui.h"
#include "atari/browser_win.h" #include "atari/browser_win.h"
#include "atari/browser.h" #include "atari/browser.h"
@ -46,6 +53,7 @@
#include "atari/toolbar.h" #include "atari/toolbar.h"
#include "atari/statusbar.h" #include "atari/statusbar.h"
#include "atari/plot/plotter.h" #include "atari/plot/plotter.h"
#include "atari/dragdrop.h"
bool cfg_rt_resize = false; bool cfg_rt_resize = false;
@ -145,6 +153,7 @@ int window_create( struct gui_window * gw, struct browser_window * bw, unsigned
EvntAdd( gw->root->handle, WM_MOVED, evnt_window_rt_resize, EV_BOT ); EvntAdd( gw->root->handle, WM_MOVED, evnt_window_rt_resize, EV_BOT );
} }
EvntAttach( gw->root->handle, WM_FORCE_MOVE, evnt_window_rt_resize ); EvntAttach( gw->root->handle, WM_FORCE_MOVE, evnt_window_rt_resize );
EvntDataAttach( gw->root->handle, AP_DRAGDROP, evnt_window_dd, gw );
EvntDataAdd( gw->root->handle, WM_DESTROY,evnt_window_destroy, NULL, EV_TOP ); EvntDataAdd( gw->root->handle, WM_DESTROY,evnt_window_destroy, NULL, EV_TOP );
EvntDataAdd( gw->root->handle, WM_ARROWED,evnt_window_arrowed, NULL, EV_TOP ); EvntDataAdd( gw->root->handle, WM_ARROWED,evnt_window_arrowed, NULL, EV_TOP );
EvntDataAdd( gw->root->handle, WM_NEWTOP, evnt_window_newtop, &evnt_data, EV_BOT); EvntDataAdd( gw->root->handle, WM_NEWTOP, evnt_window_newtop, &evnt_data, EV_BOT);
@ -333,6 +342,125 @@ bool window_widget_has_focus( struct gui_window * gw, enum focus_element_type t,
return( ( element == gw->root->focus.element && t == gw->root->focus.type) ); return( ( element == gw->root->focus.element && t == gw->root->focus.type) );
} }
static void __CDECL evnt_window_dd( WINDOW *win, short wbuff[8], void * data )
{
struct gui_window * gw = (struct gui_window *)data;
char file[DD_NAMEMAX];
char name[DD_NAMEMAX];
char *buff=NULL;
int dd_hdl;
int dd_msg; /* pipe-handle */
long size;
char ext[32];
short mx,my,bmstat,mkstat;
graf_mkstate(&mx, &my, &bmstat, &mkstat);
if( gw == NULL )
return;
if( (win->status & WS_ICONIFY))
return;
dd_hdl = ddopen( wbuff[7], DD_OK);
if( dd_hdl<0)
return; /* pipe not open */
memset( ext, 0, 32);
strcpy( ext, "ARGS");
dd_msg = ddsexts( dd_hdl, ext);
if( dd_msg<0)
goto error;
dd_msg = ddrtry( dd_hdl, (char*)&name[0], (char*)&file[0], (char*)&ext[0], &size);
if( size+1 >= PATH_MAX )
goto error;
if( !strncmp( ext, "ARGS", 4) && dd_msg > 0)
{
ddreply(dd_hdl, DD_OK);
buff = (char*)alloca(sizeof(char)*(size+1));
if( buff != NULL )
{
if( Fread(dd_hdl, size, buff ) == size)
{
buff[size] = 0;
}
LOG(("file: %s, ext: %s, size: %d dropped at: %d,%d\n",
(char*)buff, (char*)&ext,
size, mx, my
));
{
int posx, posy;
struct box *box;
struct box *file_box = 0;
hlcache_handle *h;
int box_x, box_y;
LGRECT bwrect;
struct browser_window * bw = gw->browser->bw;
h = bw->current_content;
if (!bw->current_content || content_get_type(h) != CONTENT_HTML)
return;
browser_get_rect( gw, BR_CONTENT, &bwrect );
mx = mx - bwrect.g_x;
my = my - bwrect.g_y;
if( (mx < 0 || mx > bwrect.g_w) || (my < 0 || my > bwrect.g_h) )
return;
box = html_get_box_tree(h);
box_x = box->margin[LEFT];
box_y = box->margin[TOP];
while ((box = box_at_point(box, mx+gw->browser->scroll.current.x, my+gw->browser->scroll.current.y, &box_x, &box_y, &h)))
{
if (box->style && css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN)
continue;
if (box->gadget)
{
switch (box->gadget->type)
{
case GADGET_FILE:
file_box = box;
break;
/*
TODO: handle these
case GADGET_TEXTBOX:
case GADGET_TEXTAREA:
case GADGET_PASSWORD:
text_box = box;
break;
*/
default:
break;
}
}
} /* end While */
if ( !file_box )
return;
if (file_box) {
utf8_convert_ret ret;
char *utf8_fn;
ret = local_encoding_to_utf8( buff, 0, &utf8_fn);
if (ret != UTF8_CONVERT_OK) {
/* A bad encoding should never happen */
LOG(("utf8_from_local_encoding failed"));
assert(ret != UTF8_CONVERT_BADENC);
/* Load was for us - just no memory */
return;
}
/* Found: update form input. */
free(file_box->gadget->value);
file_box->gadget->value = utf8_fn;
/* Redraw box. */
box_coords(file_box, &posx, &posy);
gui_window_redraw(bw->window,
posx - gw->browser->scroll.current.x,
posy - gw->browser->scroll.current.y,
posx - gw->browser->scroll.current.x + file_box->width,
posy - gw->browser->scroll.current.y + file_box->height);
}
}
}
}
error:
ddclose( dd_hdl);
}
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* Non Public Modul event handlers: */ /* Non Public Modul event handlers: */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */

View File

@ -74,6 +74,7 @@ void __CDECL evnt_window_resize( WINDOW *win, short buff[8] );
static void __CDECL evnt_window_move( WINDOW *win, short buff[8] ); static void __CDECL evnt_window_move( WINDOW *win, short buff[8] );
static void __CDECL evnt_window_rt_resize( WINDOW *win, short buff[8] ); static void __CDECL evnt_window_rt_resize( WINDOW *win, short buff[8] );
static void __CDECL evnt_window_close( WINDOW *win, short buff[8], void *data ); static void __CDECL evnt_window_close( WINDOW *win, short buff[8], void *data );
static void __CDECL evnt_window_dd( WINDOW *win, short wbuff[8], void * data ) ;
static void __CDECL evnt_window_destroy( WINDOW *win, short buff[8], void *data ); static void __CDECL evnt_window_destroy( WINDOW *win, short buff[8], void *data );
static void __CDECL evnt_window_keybd(WINDOW *win, short buff[8], void *data ); static void __CDECL evnt_window_keybd(WINDOW *win, short buff[8], void *data );
static void __CDECL evnt_window_mbutton(WINDOW *win, short buff[8], void *data ); static void __CDECL evnt_window_mbutton(WINDOW *win, short buff[8], void *data );

515
atari/dragdrop.c Executable file
View File

@ -0,0 +1,515 @@
/*
* Routine pour Drag and drop sous MultiTos
* source: D&D Atari, demo OEP (Alexander Lorenz)
*
* Struktur OEP (oep.apid): AES-ID der Applikation
*
* (Tab = 4)
*/
#ifdef __PUREC__
#include <tos.h>
#else
#include <osbind.h>
#include <mintbind.h>
#include <signal.h>
#endif
#include <string.h>
#include <stdio.h>
#include "windom.h"
#include "dragdrop.h"
#ifndef EACCDN
#define EACCDN (-36)
#endif
#ifndef FA_HIDDEN
#define FA_HIDDEN 0x02
#endif
static char pipename[] = "U:\\PIPE\\DRAGDROP.AA";
static long pipesig;
/*
* Routinen f<EFBFBD>r den Sender
*/
/*
* Erzeugt Pipe f<EFBFBD>r D&D
*
* Eingabeparameter:
* pipe - Pointer auf 2 Byte Buffer f<EFBFBD>r Pipeextension
*
* Ausgabeparameters:
* keine
*
* Returnwert:
* >0: Filehandle der Pipe
* -1: Fehler beim Erzeugen der Pipe
*/
short ddcreate(short *pipe)
{
long fd = -1;
pipename[17] = 'A';
pipename[18] = 'A' - 1;
do /* ouvre un pipe inoccup */
{
pipename[18]++;
if (pipename[18] > 'Z')
{
pipename[17]++;
if (pipename[17] > 'Z')
break;
else
pipename[18] = 'A';
}
/* FA_HIDDEN f<>r Pipe notwendig! */
fd = Fcreate(pipename, FA_HIDDEN);
} while (fd == (long) EACCDN);
if (fd < 0L)
return(-1);
*pipe = (pipename[17] << 8) | pipename[18];
/* Signalhandler konfigurieren */
ddgetsig(&pipesig);
return((short) fd);
}
/*
* Sendet AP_DRAGDROP an Empfngerapplikation
*
* Eingabeparameter:
* apid - AES-ID der Emfngerapp.
* fd - Filehandle der D&D-Pipe
* winid - Handle des Zielfensters (0 f<EFBFBD>r Desktopfenster)
* mx/my - Maus X und Y Koord.
* (-1/-1 f<EFBFBD>r einen fake Drag&Drop)
* kstate - Sondertastenstatus
* pipename - Extension der D&D-Pipe
*
* Ausgabeparameter:
* keine
*
* Returnwert:
* >0: kein Fehler
* -1: Empfngerapp. gibt DD_NAK zur<EFBFBD>ck
* -2: Empfngerapp. antwortet nicht (Timeout)
* -3: Fehler bei appl_write()
*/
short ddmessage(short apid, short fd, short winid, short mx, short my, short kstate, short pipeid)
{
char c;
short i, msg[8];
long fd_mask;
/* AES-Message define and post */
msg[0] = AP_DRAGDROP;
msg[1] = _AESapid;
msg[2] = 0;
msg[3] = winid;
msg[4] = mx;
msg[5] = my;
msg[6] = kstate;
msg[7] = pipeid;
i = appl_write(apid, 16, msg);
if (i == 0)
{
ddclose(fd);
return(-3);
}
/* receiver reaction */
fd_mask = (1L << fd);
i = Fselect(DD_TIMEOUT, &fd_mask, 0L, 0L);
if (!i || !fd_mask)
{
/* Timeout eingetreten */
ddclose(fd);
return(-2);
}
/* le recepteur refuse (lecture du pipe) */
if (Fread(fd, 1L, &c) != 1L)
{
ddclose(fd);
return(-1);
}
if (c != DD_OK)
{
ddclose(fd);
return(-1);
}
return(1);
}
/*
* Liest die 8 "bevorzugten" Extensionen der Empfngerapplikation
*
* Eingabeparameter:
* fd - Filehandle der D&D-Pipe
*
* Ausgabeparameters:
* exts - 32 Bytebuffer f<EFBFBD>r die 8 bevorzugten Extensionen
* der Zielapp.
*
* Returnwert:
* >0: kein Fehler
* -1: Fehler beim Lesen aus der Pipe
*/
short ddrexts(short fd, char *exts)
{
if (Fread(fd, DD_EXTSIZE, exts) != DD_EXTSIZE)
{
ddclose(fd);
return(-1);
}
return(1);
}
/*
* Testet, ob der Empfnger einen Datentyp akzeptiert
*
* Eingabeparameter:
* fd - Filehandle (von ddcreate())
* ext - Zeiger auf Datentyp (4 Bytes zB. "ARGS")
* text - Zeiger auf Datenbeschreibung (optional, zB. "DESKTOP args")
* name - Zeiger auf Datendateiname (optional, zB. "SAMPLE.TXT")
* size - Anzahl Bytes der zu sendenden Daten
*
* Ausgabeparameter:
* keine
*
* Returnwert:
* DD_OK - Empfnger akzeptiert Datentyp
* DD_NAK - Empfnger brach Drag&Drop ab
* DD_EXT - Empfnger lehnt Datentyp ab
* DD_LEN - Empfnger kann Datenmenge nicht verarbeiten
* DD_TRASH - Drop erfolgte auf M<EFBFBD>lleimer
* DD_PRINTER - Drop erfolgte auf Drucker
* DD_CLIPBOARD - Drop erfolgte auf Clipboard
*/
short ddstry(short fd, char *ext, char *text, char *name, long size)
{
char c;
short hdrlen, i;
/* 4 Bytes f<>r "ext", 4 Bytes f<>r "size",
2 Bytes f<EFBFBD>r Stringendnullen */
hdrlen = (short) (4 + 4 + strlen(text)+1 + strlen(name)+1);
/* Header senden */
if (Fwrite(fd, 2L, &hdrlen) != 2L)
return(DD_NAK);
i = (short) Fwrite(fd, 4L, ext);
i += (short) Fwrite(fd, 4L, &size);
i += (short) Fwrite(fd, strlen(text)+1, text);
i += (short) Fwrite(fd, strlen(name)+1, name);
if (i != hdrlen)
return(DD_NAK);
/* auf die Antwort warten */
if (Fread(fd, 1L, &c) != 1L)
return(DD_NAK);
return(c);
}
/* Routinen f<>r Sender und Empf„nger */
/*
* Pipe schliežen (Drag&Drop beenden/abbrechen)
*/
void ddclose(short fd)
{
/* Signalhandler restaurieren */
ddsetsig(pipesig);
Fclose(fd);
}
/*
* Signalhandler f<EFBFBD>r D&D konfigurieren
*
* Eingabeparameter:
* oldsig - Zeiger auf 4 Byte Puffer f<EFBFBD>r alten Handlerwert
*
* Ausgabeparameter:
* keine
*
* Returnwerte:
* keine
*/
void ddgetsig(long *oldsig)
{
*oldsig = (long) Psignal(SIGPIPE, (void *) SIG_IGN);
}
/*
* Signalhandler nach D&D restaurieren
*
* Eingabeparameter:
* oldsig - Alter Handlerwert (von ddgetsig)
*
* Ausgabeparameter:
* keine
*
* Returnwerte:
* keine
*/
void ddsetsig(long oldsig)
{
if (oldsig != -32L)
Psignal(SIGPIPE, (void *) oldsig);
}
/* Routinen f<>r Empf„nger */
/*
* Drag&Drop Pipe ffnen
*
* Eingabeparameter:
* ddnam - Extension der Pipe (letztes short von AP_DRAGDROP)
* ddmsg - DD_OK oder DD_NAK
*
* Ausgabeparameter:
* keine
*
* Returnwerte:
* >0 - Filehandle der Drag&Drop pipe
* -1 - Drag&Drop abgebrochen
*/
short ddopen(short ddnam, char ddmsg)
{
long fd;
pipename[17] = (ddnam & 0xff00) >> 8;
pipename[18] = ddnam & 0x00ff;
fd = Fopen(pipename, 2);
if (fd < 0L)
return(-1);
/* Signalhandler konfigurieren */
ddgetsig(&pipesig);
if (Fwrite((short) fd, 1L, &ddmsg) != 1L)
{
ddclose((short) fd);
return(-1);
}
return((short) fd);
}
/*
* Schreibt die 8 "bevorzugten" Extensionen der Applikation
*
* Eingabeparameter:
* fd - Filehandle der D&D-Pipe
* exts - Liste aus acht 4 Byte Extensionen die verstanden
* werden. Diese Liste sollte nach bevorzugten Datentypen
* sortiert sein. Sollten weniger als DD_NUMEXTS
* Extensionen unterst<EFBFBD>tzt werden, muž die Liste mit
* Nullen (0) aufgef<EFBFBD>llt werden!
*
* Ausgabeparameter:
* keine
*
* Returnwert:
* >0: kein Fehler
* -1: Fehler beim Schreiben in die Pipe
*/
short ddsexts(short fd, char *exts)
{
if (Fwrite(fd, DD_EXTSIZE, exts) != DD_EXTSIZE)
{
ddclose(fd);
return(-1);
}
return(1);
}
/*
* Nchsten Header vom Sender holen
*
* Eingabeparameter:
* fd - Filehandle der Pipe (von ddopen())
*
* Ausgabeparameters:
* name - Zeiger auf Buffer f<EFBFBD>r Datenbeschreibung (min. DD_NAMEMAX!)
* file - Zeiger auf Buffer f<EFBFBD>r Datendateiname (min. DD_NAMEMAX!)
* whichext- Zeiger auf Buffer f<EFBFBD>r Extension (4 Bytes)
* size - Zeiger auf Buffer f<EFBFBD>r Datengrže (4 Bytes)
*
* Returnwert:
* >0: kein Fehler
* -1: Sender brach Drag&Drop ab
*
* On lit dans le pipe qui normalement est constitu de:
* 1 short: taille du header
* 4 CHAR: type de donne (extension)
* 1 long: taille des donnes
* STRING: description des donnes
* STRING: nom du fichiers
* soit au minimun 11 octets (cas ou les string sont rduites \0)
* les string sont limit a 128 octets
*/
short ddrtry(short fd, char *name, char *file, char *whichext, long *size)
{
char buf[DD_NAMEMAX * 2];
short hdrlen, i, len;
if (Fread(fd, 2L, &hdrlen) != 2L)
return(-1);
if (hdrlen < 9) /* il reste au minimum 11 - 2 = 9 octets a lire */
{
/* sollte eigentlich nie passieren */
return(-1); /* erreur taille incorrecte */
}
if (Fread(fd, 4L, whichext) != 4L) /* lecture de l'extension */
return(-1);
if (Fread(fd, 4L, size) != 4L) /* lecture de la longueurs des donnes */
return(-1);
hdrlen -= 8; /* on a lu 8 octets */
if (hdrlen > DD_NAMEMAX*2)
i = DD_NAMEMAX*2;
else
i = hdrlen;
len = i;
if (Fread(fd, (long) i, buf) != (long) i)
return(-1);
hdrlen -= i;
strncpy(name, buf, DD_NAMEMAX);
i = (short) strlen(name) + 1;
if (len - i > 0)
strncpy(file, buf + i, DD_NAMEMAX);
else
file[0] = '\0';
/* weitere Bytes im Header in den M<>ll */
while (hdrlen > DD_NAMEMAX*2)
{
if (Fread(fd, DD_NAMEMAX*2, buf) != DD_NAMEMAX*2)
return(-1);
hdrlen -= DD_NAMEMAX*2;
}
if (hdrlen > 0)
{
if (Fread(fd, (long) hdrlen, buf) != (long) hdrlen)
return(-1);
}
return(1);
}
/*
* Sendet der Senderapplikation eine 1 Byte Antwort
*
* Eingabeparameter:
* fd - Filehandle der Pipe (von ddopen())
* ack - Byte das gesendet werden soll (zB. DD_OK)
*
* Ausgabeparameter:
* keine
*
* Returnwert:
* >0: kein Fehler
* -1: Fehler (die Pipe wird automatisch geschlossen!)
*/
short ddreply(short fd, char ack)
{
if (Fwrite(fd, 1L, &ack) != 1L)
{
ddclose(fd);
return(-1);
}
return(1);
}

51
atari/dragdrop.h Executable file
View File

@ -0,0 +1,51 @@
/*
* MultiTOS Drag&Drop Header file
*/
/* R<>ckgabewerte von ddstry() etc. */
#define DD_OK 0
#define DD_NAK 1
#define DD_EXT 2
#define DD_LEN 3
#define DD_TRASH 4
#define DD_PRINTER 5
#define DD_CLIPBOARD 6
/* Timeout in Millisekunden (4 sek.) */
#define DD_TIMEOUT 4000
/* Anzahl der Extensionen/Bytes der "bevorzugten Extensionen" */
#define DD_NUMEXTS 8
#define DD_EXTSIZE 32L
/* Max. L„nge des Drag&Drop name/file */
#define DD_NAMEMAX 128
/* Max. L„nge des Drag&Drop Header */
#define DD_HDRMAX (8+DD_NAMEMAX+DD_NAMEMAX)
/*
* Funktionsdeklarationen
*/
short ddcreate(short *pipe);
short ddmessage(short apid, short fd, short winid, short mx, short my, short kstate, short pipename);
short ddrexts(short fd, char *exts);
short ddstry(short fd, char *ext, char *text, char *name, long size);
void ddclose(short fd);
void ddgetsig(long *oldsig);
void ddsetsig(long oldsig);
short ddopen(short ddnam, char ddmsg);
short ddsexts(short fd, char *exts);
short ddrtry(short fd, char *name, char *file, char *whichext, long *size);
short ddreply(short fd, char ack);

View File

@ -152,7 +152,7 @@ http_proxy_auth_user:
http_proxy_auth_pass: http_proxy_auth_pass:
suppress_curl_debug:1 suppress_curl_debug:1
font_size:120 font_size:120
font_min_size:80 font_min_size:110
#font_sans:Sans #font_sans:Sans
#font_serif:Serif #font_serif:Serif
#font_mono:Monospace #font_mono:Monospace
@ -183,10 +183,10 @@ window_screen_width:0
window_screen_height:0 window_screen_height:0
scale:100 scale:100
incremental_reflow:1 incremental_reflow:1
min_reflow_period:200 min_reflow_period:2000
tree_icons_dir:./res/icons tree_icons_dir:./res/icons
core_select_menu:1 core_select_menu:1
max_fetchers:16 max_fetchers:8
max_fetchers_per_host:2 max_fetchers_per_host:2
max_cached_fetch_handles:6 max_cached_fetch_handles:6
target_blank:1 target_blank:1
@ -205,11 +205,9 @@ downloads_clear:0
request_overwrite:1 request_overwrite:1
downloads_directory:./download downloads_directory:./download
url_file:./res/URLs url_file:./res/URLs
button_type:2
disable_popups:0 disable_popups:0
disable_plugins:0
history_age:0 history_age:0
hover_urls:0 hover_urls:1
focus_new:0 focus_new:0
new_blank:0 new_blank:0
hotlist_path:./res/Hotlist hotlist_path:./res/Hotlist