Allow text selection dragging across (NetSurf) windows. DisplayBeep if it is dropped

somewhere invalid.

svn path=/trunk/netsurf/; revision=10665
This commit is contained in:
Chris Young 2010-07-27 21:41:21 +00:00
parent 7bf81dbf35
commit acf46e01a8
4 changed files with 71 additions and 13 deletions

View File

@ -257,17 +257,31 @@ bool gui_copy_to_clipboard(struct selection *s)
void ami_drag_selection(struct selection *s)
{
struct box *text_box;
ULONG x = s->bw->window->shared->win->MouseX;
ULONG y = s->bw->window->shared->win->MouseY;
ULONG x;
ULONG y;
struct gui_window_2 *gwin = ami_window_at_pointer();
if(text_box = ami_text_box_at_point(s->bw->window, &x, &y))
if(!gwin)
{
DisplayBeep(scrn);
return;
}
x = gwin->win->MouseX;
y = gwin->win->MouseY;
if(text_box = ami_text_box_at_point(gwin, &x, &y))
{
if(gui_copy_to_clipboard(s))
{
browser_window_mouse_click(s->bw, BROWSER_MOUSE_PRESS_1, x, y);
browser_window_key_press(s->bw, KEY_PASTE);
browser_window_mouse_click(gwin->bw, BROWSER_MOUSE_PRESS_1, x, y);
browser_window_key_press(gwin->bw, KEY_PASTE);
}
}
else
{
DisplayBeep(scrn);
}
}
bool ami_easy_clipboard(char *text)

View File

@ -345,18 +345,21 @@ void gui_drag_save_selection(struct selection *s, struct gui_window *g)
void ami_drag_save(struct Window *win)
{
ULONG which,type;
ULONG which = WBO_NONE,type;
char path[1025],dpath[1025];
char *source_data;
ULONG source_size;
which = WhichWorkbenchObject(NULL,scrn->MouseX,scrn->MouseY,
if(strcmp(option_use_pubscreen,"Workbench") == 0)
{
which = WhichWorkbenchObject(NULL,scrn->MouseX,scrn->MouseY,
WBOBJA_Type,&type,
WBOBJA_FullPath,&path,
WBOBJA_FullPathSize,1024,
WBOBJA_DrawerPath,&dpath,
WBOBJA_DrawerPathSize,1024,
TAG_DONE);
}
if((which == WBO_DRAWER) || ((which == WBO_ICON) && (type > WBDRAWER)))
{
@ -366,6 +369,7 @@ void ami_drag_save(struct Window *win)
{
if(drag_save == GUI_SAVE_TEXT_SELECTION)
ami_drag_selection((struct selection *)drag_save_data);
else DisplayBeep(scrn);
drag_save = 0;
drag_save_data = NULL;
@ -374,6 +378,7 @@ void ami_drag_save(struct Window *win)
if(path[0] == '\0')
{
DisplayBeep(scrn);
drag_save = 0;
drag_save_data = NULL;
return;

View File

@ -73,6 +73,7 @@
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/keymap.h>
#include <proto/layers.h>
#include <proto/locale.h>
#include <proto/Picasso96API.h>
#include <proto/timer.h>
@ -3784,7 +3785,7 @@ uint32 ami_popup_hook(struct Hook *hook,Object *item,APTR reserved)
/* return the text box at posn x,y in window coordinates
x,y are updated to be document co-ordinates */
struct box *ami_text_box_at_point(struct gui_window *g, ULONG *x, ULONG *y)
struct box *ami_text_box_at_point(struct gui_window_2 *gwin, ULONG *x, ULONG *y)
{
struct IBox *bbox;
ULONG xs,ys,width,height;
@ -3792,19 +3793,19 @@ struct box *ami_text_box_at_point(struct gui_window *g, ULONG *x, ULONG *y)
hlcache_handle *content;
int box_x=0,box_y=0;
GetAttr(SPACE_AreaBox, (Object *)g->shared->objects[GID_BROWSER],
GetAttr(SPACE_AreaBox, (Object *)gwin->objects[GID_BROWSER],
(ULONG *)&bbox);
ami_get_hscroll_pos(g->shared, (ULONG *)&xs);
ami_get_hscroll_pos(gwin, (ULONG *)&xs);
*x = *x - (bbox->Left) +xs;
ami_get_vscroll_pos(g->shared, (ULONG *)&ys);
ami_get_vscroll_pos(gwin, (ULONG *)&ys);
*y = *y - (bbox->Top) + ys;
width=bbox->Width;
height=bbox->Height;
content = g->shared->bw->current_content;
content = gwin->bw->current_content;
box = html_get_box_tree(content);
while ((box = box_at_point(box, *x, *y, &box_x, &box_y, &content)))
{
@ -3827,3 +3828,40 @@ struct box *ami_text_box_at_point(struct gui_window *g, ULONG *x, ULONG *y)
}
return text_box;
}
struct gui_window_2 *ami_find_gwin_by_id(struct Window *win)
{
struct nsObject *node, *nnode;
struct gui_window_2 *gwin;
if(!IsMinListEmpty(window_list))
{
node = (struct nsObject *)GetHead((struct List *)window_list);
do
{
nnode=(struct nsObject *)GetSucc((struct Node *)node);
if(node->Type == AMINS_WINDOW) // or frame?
{
gwin = node->objstruct;
if(win == gwin->win) return gwin;
}
} while(node = nnode);
}
return NULL;
}
struct gui_window_2 *ami_window_at_pointer(void)
{
struct Layer *layer;
LockLayerInfo(&scrn->LayerInfo);
layer = WhichLayer(&scrn->LayerInfo, scrn->MouseX, scrn->MouseY);
UnlockLayerInfo(&scrn->LayerInfo);
if(layer) return ami_find_gwin_by_id(layer->Window);
else return NULL;
}

View File

@ -127,7 +127,8 @@ void ami_close_all_tabs(struct gui_window_2 *gwin);
void ami_quit_netsurf(void);
void ami_do_redraw(struct gui_window_2 *g);
STRPTR ami_locale_langs(void);
struct box *ami_text_box_at_point(struct gui_window *g, ULONG *x, ULONG *y);
struct box *ami_text_box_at_point(struct gui_window_2 *gwin, ULONG *x, ULONG *y);
struct gui_window_2 *ami_window_at_pointer(void);
struct TextFont *origrpfont;
struct MinList *window_list;