void ami_drag_selection(struct selection *s) { struct box *text_box; int x; int y; char *utf8text; struct ami_text_selection *sel; struct IFFHandle *old_iffh = iffh; struct gui_window_2 *gwin = ami_window_at_pointer(AMINS_WINDOW); if(!gwin) { DisplayBeep(scrn); return; } x = gwin->win->MouseX; y = gwin->win->MouseY; if(text_box = ami_text_box_at_point(gwin, (ULONG *)&x, (ULONG *)&y)) { ami_utf8_clipboard = true; iffh = ami_clipboard_init_internal(1); if(gui_copy_to_clipboard(s)) { browser_window_mouse_click(gwin->bw, BROWSER_MOUSE_PRESS_1, x, y); browser_window_key_press(gwin->bw, KEY_PASTE); } ami_clipboard_free_internal(iffh); iffh = old_iffh; ami_utf8_clipboard = false; } else { 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)) { utf8text = ami_utf8_easy(sel->text); RefreshSetGadgetAttrs((struct Gadget *)gwin->objects[GID_URL], gwin->win, NULL, STRINGA_TextVal, utf8text, TAG_DONE); FreeVec(sel); ami_utf8_free(utf8text); } } else if(ami_gadget_hit(gwin->objects[GID_SEARCHSTRING], x, y)) { if(sel = ami_selection_to_text(gwin)) { utf8text = ami_utf8_easy(sel->text); RefreshSetGadgetAttrs((struct Gadget *)gwin->objects[GID_SEARCHSTRING], gwin->win, NULL, STRINGA_TextVal, utf8text, TAG_DONE); FreeVec(sel); ami_utf8_free(utf8text); } } else { DisplayBeep(scrn); } } }
void ami_drag_selection(struct gui_window *g) { int x; int y; char *utf8text; char *sel; struct IFFHandle *old_iffh = iffh; struct gui_window_2 *gwin = ami_window_at_pointer(AMINS_WINDOW); /* NB: 'gwin' is at the drop point, 'g' is where the selection was dragged from. * These may be different if the selection has been dragged between windows. */ if(!gwin) { DisplayBeep(scrn); return; } x = gwin->win->MouseX; y = gwin->win->MouseY; if(ami_text_box_at_point(gwin, (ULONG *)&x, (ULONG *)&y)) { iffh = ami_clipboard_init_internal(1); browser_window_key_press(g->shared->bw, KEY_COPY_SELECTION); browser_window_mouse_click(gwin->bw, BROWSER_MOUSE_PRESS_1, x, y); browser_window_key_press(gwin->bw, KEY_PASTE); ami_clipboard_free_internal(iffh); iffh = old_iffh; } else { x = gwin->win->MouseX; y = gwin->win->MouseY; if(ami_gadget_hit(gwin->objects[GID_URL], x, y)) { if(sel = browser_window_get_selection(g->shared->bw)) { utf8text = ami_utf8_easy(sel); RefreshSetGadgetAttrs((struct Gadget *)gwin->objects[GID_URL], gwin->win, NULL, STRINGA_TextVal, utf8text, TAG_DONE); free(sel); ami_utf8_free(utf8text); } } else if(ami_gadget_hit(gwin->objects[GID_SEARCHSTRING], x, y)) { if(sel = browser_window_get_selection(g->shared->bw)) { utf8text = ami_utf8_easy(sel); RefreshSetGadgetAttrs((struct Gadget *)gwin->objects[GID_SEARCHSTRING], gwin->win, NULL, STRINGA_TextVal, utf8text, TAG_DONE); free(sel); ami_utf8_free(utf8text); } } else { DisplayBeep(scrn); } } }