From 1518543c227c61250da14a864ad88c10fc6cd4c4 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Fri, 29 Apr 2011 18:15:20 +0000 Subject: Fix DSI when drag saving Allow selection drags to URL and search gadgets svn path=/trunk/netsurf/; revision=12259 --- amiga/clipboard.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++--- amiga/clipboard.h | 10 +++++++- amiga/context_menu.c | 38 ++--------------------------- amiga/drag.c | 4 ++-- 4 files changed, 77 insertions(+), 42 deletions(-) (limited to 'amiga') diff --git a/amiga/clipboard.c b/amiga/clipboard.c index 826f2f2dd..bf0b6f618 100755 --- a/amiga/clipboard.c +++ b/amiga/clipboard.c @@ -21,6 +21,7 @@ #include "desktop/selection.h" #include "desktop/textinput.h" +#include "amiga/clipboard.h" #include "amiga/iff_cset.h" #include "amiga/options.h" #include "amiga/gui.h" @@ -43,6 +44,9 @@ struct IFFHandle *iffh = NULL; bool ami_add_to_clipboard(const char *text, size_t length, bool space); +static bool ami_copy_selection(const char *text, size_t length, + struct box *box, void *handle, const char *whitespace_text, + size_t whitespace_length); struct IFFHandle *ami_clipboard_init_internal(int unit) { @@ -275,11 +279,44 @@ bool gui_copy_to_clipboard(struct selection *s) return false; } +struct ami_text_selection *ami_selection_to_text(struct gui_window_2 *gwin) +{ + struct ami_text_selection *sel; + + sel = AllocVec(sizeof(struct ami_text_selection), + MEMF_PRIVATE | MEMF_CLEAR); + + if(sel) selection_traverse(gwin->bw->sel, ami_copy_selection, sel); + + return sel; +} + +static bool ami_copy_selection(const char *text, size_t length, + struct box *box, void *handle, const char *whitespace_text, + size_t whitespace_length) +{ + struct ami_text_selection *sel = handle; + int len = length; + + if((length + (sel->length)) > (sizeof(sel->text))) + len = sizeof(sel->text) - (sel->length); + + if(len <= 0) return false; + + memcpy((sel->text) + (sel->length), text, len); + sel->length += len; + + sel->text[sel->length] = '\0'; + + return true; +} + void ami_drag_selection(struct selection *s) { struct box *text_box; - ULONG x; - ULONG y; + int x; + int y; + struct ami_text_selection *sel; struct IFFHandle *old_iffh = iffh; struct gui_window_2 *gwin = ami_window_at_pointer(); @@ -307,7 +344,31 @@ void ami_drag_selection(struct selection *s) } else { - DisplayBeep(scrn); + x = gwin->win->MouseX; + y = gwin->win->MouseY; + + if(ami_gadget_hit(gwin->objects[GID_URL], x, y)) + { + if(sel = ami_selection_to_text(gwin)) + { + RefreshSetGadgetAttrs((struct Gadget *)gwin->objects[GID_URL], + gwin->win, NULL, STRINGA_TextVal, sel->text, TAG_DONE); + FreeVec(sel); + } + } + else if(ami_gadget_hit(gwin->objects[GID_SEARCHSTRING], x, y)) + { + if(sel = ami_selection_to_text(gwin)) + { + RefreshSetGadgetAttrs((struct Gadget *)gwin->objects[GID_SEARCHSTRING], + gwin->win, NULL, STRINGA_TextVal, sel->text, TAG_DONE); + FreeVec(sel); + } + } + else + { + DisplayBeep(scrn); + } } } diff --git a/amiga/clipboard.h b/amiga/clipboard.h index f9be4f419..8d0d8d459 100755 --- a/amiga/clipboard.h +++ b/amiga/clipboard.h @@ -1,5 +1,5 @@ /* - * Copyright 2008,2009 Chris Young + * Copyright 2008-2009, 2011 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -23,12 +23,20 @@ struct bitmap; struct hlcache_handle; struct selection; +struct gui_window_2; + +struct ami_text_selection +{ + char text[1024]; + int length; +}; void ami_clipboard_init(void); void ami_clipboard_free(void); void ami_drag_selection(struct selection *s); bool ami_easy_clipboard(char *text); bool ami_easy_clipboard_bitmap(struct bitmap *bitmap); +struct ami_text_selection *ami_selection_to_text(struct gui_window_2 *gwin); #ifdef WITH_NS_SVG bool ami_easy_clipboard_svg(struct hlcache_handle *c); #endif diff --git a/amiga/context_menu.c b/amiga/context_menu.c index cdd3df584..81f81361e 100755 --- a/amiga/context_menu.c +++ b/amiga/context_menu.c @@ -48,9 +48,6 @@ #include static uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved); -static bool ami_context_menu_copy_selection(const char *text, size_t length, - struct box *box, void *handle, const char *whitespace_text, - size_t whitespace_length); static bool ami_context_menu_history(const struct history *history, int x0, int y0, int x1, int y1, const struct history_entry *entry, void *user_data); @@ -84,12 +81,6 @@ struct Library *PopupMenuBase = NULL; struct PopupMenuIFace *IPopupMenu = NULL; char *ctxmenulab[CMID_LAST]; -struct ami_context_menu_selection -{ - char text[1024]; - int length; -}; - void ami_context_menu_init(void) { if(PopupMenuBase = OpenLibrary("popupmenu.class",0)) @@ -584,16 +575,11 @@ static uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved case CMID_SELSEARCH: { - struct ami_context_menu_selection *sel; + struct ami_text_selection *sel; char *url; - sel = AllocVec(sizeof(struct ami_context_menu_selection), - MEMF_PRIVATE | MEMF_CLEAR); - - if(sel) + if(sel = ami_selection_to_text(gwin)) { - selection_traverse(gwin->bw->sel, ami_context_menu_copy_selection, - sel); url = search_web_from_term(sel->text); browser_window_go(gwin->bw, url, NULL, true); @@ -607,26 +593,6 @@ static uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved return itemid; } -static bool ami_context_menu_copy_selection(const char *text, size_t length, - struct box *box, void *handle, const char *whitespace_text, - size_t whitespace_length) -{ - struct ami_context_menu_selection *sel = handle; - int len = length; - - if((length + (sel->length)) > (sizeof(sel->text))) - len = sizeof(sel->text) - (sel->length); - - if(len <= 0) return false; - - memcpy((sel->text) + (sel->length), text, len); - sel->length += len; - - sel->text[sel->length] = '\0'; - - return true; -} - static bool ami_context_menu_history(const struct history *history, int x0, int y0, int x1, int y1, const struct history_entry *entry, void *user_data) { diff --git a/amiga/drag.c b/amiga/drag.c index 77a44dab7..37e0acd24 100644 --- a/amiga/drag.c +++ b/amiga/drag.c @@ -111,7 +111,7 @@ void ami_drag_save(struct Window *win) ami_drag_icon_close(NULL); ami_autoscroll = FALSE; - if(strcmp(option_use_pubscreen,"Workbench") == 0) + if(option_use_pubscreen && (strcmp(option_use_pubscreen,"Workbench") == 0)) { which = WhichWorkbenchObject(NULL,scrn->MouseX,scrn->MouseY, WBOBJA_Type,&type, @@ -348,5 +348,5 @@ struct gui_window_2 *ami_window_at_pointer(void) UnlockLayerInfo(&scrn->LayerInfo); if(layer) return ami_find_gwin_by_id(layer->Window); - else return NULL; + else return NULL; } -- cgit v1.2.3