From bc2bce8d35bcb631168b3ae91ab6868b7057debc Mon Sep 17 00:00:00 2001 From: Chris Young Date: Wed, 9 Feb 2011 22:16:11 +0000 Subject: Web search text selection svn path=/trunk/netsurf/; revision=11638 --- amiga/context_menu.c | 82 ++++++++++++++++++++++++++++++++++++++++++++-------- amiga/context_menu.h | 1 + 2 files changed, 71 insertions(+), 12 deletions(-) (limited to 'amiga') diff --git a/amiga/context_menu.c b/amiga/context_menu.c index f3d7fe072..c8850ca5b 100755 --- a/amiga/context_menu.c +++ b/amiga/context_menu.c @@ -16,32 +16,42 @@ * along with this program. If not, see . */ -#include "amiga/context_menu.h" -#include "render/box.h" -#include "render/form.h" #ifdef __amigaos4__ #include #endif #include +#include +#include +#include + +#include "amiga/context_menu.h" #include "amiga/utf8.h" -#include "utils/utf8.h" -#include "utils/messages.h" #include "amiga/options.h" #include "amiga/clipboard.h" -#include -#include -#include -#include "utils/utils.h" -#include -#include "desktop/textinput.h" -#include "desktop/selection.h" #include "amiga/bitmap.h" #include "amiga/iff_dr2d.h" +#include "desktop/textinput.h" +#include "desktop/selection.h" +#include "render/box.h" +#include "render/form.h" +#include "utils/utf8.h" +#include "utils/messages.h" +#include "utils/utils.h" + +#include uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved); +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); char *ctxmenulab[CMID_LAST]; +struct ami_context_menu_selection +{ + char text[1024]; + int length; +}; + void ami_context_menu_init(void) { ctxmenulab[CMID_SELECTFILE] = ami_utf8_easy((char *)messages_get("SelectFile")); @@ -61,6 +71,7 @@ void ami_context_menu_init(void) ctxmenulab[CMID_SELPASTE] = ami_utf8_easy((char *)messages_get("PasteNS")); ctxmenulab[CMID_SELALL] = ami_utf8_easy((char *)messages_get("SelectAllNS")); ctxmenulab[CMID_SELCLEAR] = ami_utf8_easy((char *)messages_get("ClearNS")); + ctxmenulab[CMID_SELSEARCH] = ami_utf8_easy((char *)messages_get("SearchWeb")); ctxmenulab[CMSUB_OBJECT] = ami_utf8_easy((char *)messages_get("Object")); ctxmenulab[CMSUB_URL] = ami_utf8_easy((char *)messages_get("Link")); @@ -208,6 +219,14 @@ void ami_context_menu_show(struct gui_window_2 *gwin,int x,int y) PMIA_ID,CMID_SELCLEAR, PMIA_Disabled, disabled_noselection, TAG_DONE), + PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, ~0, + TAG_DONE), + PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL, + PMIA_Title, (ULONG)ctxmenulab[CMID_SELSEARCH], + PMIA_ID,CMID_SELSEARCH, + PMIA_Disabled, disabled_noselection, + TAG_DONE), TAG_DONE), TAG_DONE), ~0); @@ -407,8 +426,47 @@ uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved) case CMID_SELCLEAR: browser_window_key_press(gwin->bw, KEY_CLEAR_SELECTION); break; + + case CMID_SELSEARCH: + { + struct ami_context_menu_selection *sel; + char *url; + + sel = AllocVec(sizeof(struct ami_context_menu_selection), + MEMF_PRIVATE | MEMF_CLEAR); + + if(sel) + { + 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); + + FreeVec(sel); + } + } + break; } } return itemid; } + +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; +} diff --git a/amiga/context_menu.h b/amiga/context_menu.h index 579c59eb6..5e6bed88a 100755 --- a/amiga/context_menu.h +++ b/amiga/context_menu.h @@ -36,6 +36,7 @@ enum { CMID_SELCUT, CMID_SELCOPY, CMID_SELPASTE, + CMID_SELSEARCH, CMSUB_OBJECT, CMSUB_URL, CMSUB_SEL, -- cgit v1.2.3