Amiga: Add "cut" option; make cut/copy/paste menus context sensitive; allow dragging

selections within NetSurf window to text fields (does not work across windows).

todo: switching tabs will reset cut/copy/paste menus to initial state; cut option is
putting something on the clipboard which causes a crash when pasting it back

svn path=/trunk/netsurf/; revision=10660
This commit is contained in:
Chris Young 2010-07-24 16:39:37 +00:00
parent d5b8cf89da
commit 004aee8281
21 changed files with 249 additions and 45 deletions

View File

@ -252,6 +252,7 @@ PrintNS:Drucken...
# Edit menu
#
CutNS:Ausschneiden
CopyNS:Kopieren
PasteNS:Einfügen
SelectAllNS:Alles auswählen

View File

@ -252,6 +252,7 @@ PrintNS:Print...
# Edit menu
#
CutNS:Cut
CopyNS:Copy
PasteNS:Paste
SelectAllNS:Select all

View File

@ -252,6 +252,7 @@ PrintNS:Print...
# Edit menu
#
CutNS:Cut
CopyNS:Copy
PasteNS:Paste
SelectAllNS:Select all

View File

@ -254,6 +254,7 @@ PrintNS:Stampa...
# Edit menu
#
CutNS:Cut
CopyNS:Copia
PasteNS:Incolla
SelectAllNS:Seleziona tutto

View File

@ -252,6 +252,7 @@ PrintNS:Print...
# Edit menu
#
CutNS:Cut
CopyNS:Copy
PasteNS:Paste
SelectAllNS:Select all

View File

@ -17,21 +17,26 @@
*/
#include "desktop/gui.h"
#include "amiga/iff_cset.h"
#include <proto/iffparse.h>
#include <datatypes/textclass.h>
#include "amiga/options.h"
#include "amiga/gui.h"
#include <proto/exec.h>
#include "amiga/utf8.h"
#include "utils/utf8.h"
#include "desktop/selection.h"
#include <datatypes/pictureclass.h>
#include <proto/datatypes.h>
#include "amiga/iff_cset.h"
#include "amiga/options.h"
#include "amiga/gui.h"
#include "amiga/utf8.h"
#include "amiga/bitmap.h"
#include "amiga/iff_dr2d.h"
#include "amiga/menu.h"
#include <proto/iffparse.h>
#include <proto/intuition.h>
#include <proto/exec.h>
#include <proto/datatypes.h>
#include <proto/diskfont.h>
#include <diskfont/diskfonttag.h>
#include <datatypes/textclass.h>
#include <datatypes/pictureclass.h>
struct IFFHandle *iffh = NULL;
@ -54,6 +59,24 @@ void ami_clipboard_free(void)
void gui_start_selection(struct gui_window *g)
{
if(!g) return;
if(!g->shared->win) return;
OnMenu(g->shared->win, AMI_MENU_CLEAR);
OnMenu(g->shared->win, AMI_MENU_COPY);
if(selection_read_only(g->shared->bw->sel) == false)
OnMenu(g->shared->win, AMI_MENU_CUT);
}
void gui_clear_selection(struct gui_window *g)
{
if(!g) return;
if(!g->shared->win) return;
OffMenu(g->shared->win, AMI_MENU_CLEAR);
OffMenu(g->shared->win, AMI_MENU_CUT);
OffMenu(g->shared->win, AMI_MENU_COPY);
}
void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
@ -109,6 +132,7 @@ void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
bool gui_empty_clipboard(void)
{
return true;
}
bool gui_add_to_clipboard(const char *text, size_t length, bool space)

View File

@ -32,6 +32,7 @@
#include "utils/utils.h"
#include <proto/asl.h>
#include "desktop/textinput.h"
#include "desktop/selection.h"
#include "amiga/bitmap.h"
#include "amiga/iff_dr2d.h"
@ -53,8 +54,11 @@ void ami_context_menu_init(void)
ctxmenulab[CMID_URLOPENWIN] = ami_utf8_easy((char *)messages_get("LinkNewWin"));
ctxmenulab[CMID_URLOPENTAB] = ami_utf8_easy((char *)messages_get("LinkNewTab"));
ctxmenulab[CMID_SELCUT] = ami_utf8_easy((char *)messages_get("CutNS"));
ctxmenulab[CMID_SELCOPY] = ami_utf8_easy((char *)messages_get("CopyNS"));
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[CMSUB_OBJECT] = ami_utf8_easy((char *)messages_get("Object"));
ctxmenulab[CMSUB_URL] = ami_utf8_easy((char *)messages_get("Link"));
@ -170,20 +174,38 @@ void ami_context_menu_show(struct gui_window_2 *gwin,int x,int y)
if(curbox->text)
{
BOOL disabled_readonly = selection_read_only(gwin->bw->sel);
BOOL disabled_noselection = !selection_defined(gwin->bw->sel);
IDoMethod(gwin->objects[OID_MENU],PM_INSERT,
NewObject(POPUPMENU_GetItemClass(), NULL,
PMIA_Title, (ULONG)ctxmenulab[CMSUB_SEL],
PMSIMPLESUB,
PMIA_SubMenu, NewObject(POPUPMENU_GetClass(), NULL,
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
PMIA_Title, (ULONG)ctxmenulab[CMID_SELCUT],
PMIA_ID,CMID_SELCUT,
PMIA_Disabled, disabled_noselection && disabled_readonly,
TAG_DONE),
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
PMIA_Title, (ULONG)ctxmenulab[CMID_SELCOPY],
PMIA_ID,CMID_SELCOPY,
//PMIA_UserData,curbox->href,
PMIA_Disabled, disabled_noselection,
TAG_DONE),
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
PMIA_Title, (ULONG)ctxmenulab[CMID_SELPASTE],
PMIA_ID,CMID_SELPASTE,
PMIA_Disabled, (gwin->bw->window->c_h == 0),
TAG_DONE),
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
PMIA_Title, (ULONG)ctxmenulab[CMID_SELALL],
PMIA_ID,CMID_SELALL,
//PMIA_UserData,curbox->href,
TAG_DONE),
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
PMIA_Title, (ULONG)ctxmenulab[CMID_SELCLEAR],
PMIA_ID,CMID_SELALL,
PMIA_Disabled, disabled_noselection,
TAG_DONE),
TAG_DONE),
TAG_DONE),
~0);
@ -362,14 +384,27 @@ uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved)
}
break;
case CMID_SELCUT:
browser_window_key_press(gwin->bw, KEY_COPY_SELECTION);
browser_window_key_press(gwin->bw, KEY_CUT_SELECTION);
break;
case CMID_SELCOPY:
browser_window_key_press(gwin->bw, KEY_COPY_SELECTION);
browser_window_key_press(gwin->bw, KEY_CLEAR_SELECTION);
break;
case CMID_SELPASTE:
browser_window_key_press(gwin->bw, KEY_PASTE);
break;
case CMID_SELALL:
browser_window_key_press(gwin->bw, KEY_SELECT_ALL);
break;
case CMID_SELCLEAR:
browser_window_key_press(gwin->bw, KEY_CLEAR_SELECTION);
break;
}
}

View File

@ -32,7 +32,10 @@ enum {
CMID_SAVEOBJ,
CMID_SAVEIFFOBJ,
CMID_SELALL,
CMID_SELCLEAR,
CMID_SELCUT,
CMID_SELCOPY,
CMID_SELPASTE,
CMSUB_OBJECT,
CMSUB_URL,
CMSUB_SEL,

View File

@ -336,7 +336,7 @@ void gui_drag_save_object(gui_save_type type, hlcache_handle *c,
void gui_drag_save_selection(struct selection *s, struct gui_window *g)
{
if(strcmp(option_use_pubscreen,"Workbench")) return;
// if(strcmp(option_use_pubscreen,"Workbench")) return;
gui_window_set_pointer(g,AMI_GUI_POINTER_DRAG);
drag_save_data = s;
@ -364,6 +364,9 @@ void ami_drag_save(struct Window *win)
}
else if(which == WBO_NONE)
{
if(drag_save == GUI_SAVE_TEXT_SELECTION)
ami_drag_selection((struct selection *)drag_save_data);
drag_save = 0;
drag_save_data = NULL;
return;

View File

@ -103,6 +103,10 @@ const char *fetch_filetype(const char *unix_path)
break;
case GID_PICTURE:
sprintf(mimetype,"image/%s",dth->dth_BaseName);
if(strcmp("sprite",dth->dth_BaseName)==0)
{
strcpy(mimetype,"image/x-riscos-sprite");
}
break;
case GID_ANIMATION:
case GID_MOVIE:

View File

@ -1291,10 +1291,16 @@ void ami_handle_msg(void)
browser_window_key_press(gwin->bw, KEY_SELECT_ALL);
break;
case 'x':
browser_window_key_press(gwin->bw, KEY_CUT_SELECTION);
browser_window_key_press(gwin->bw, KEY_CLEAR_SELECTION);
break;
case 'c':
browser_window_key_press(gwin->bw, KEY_COPY_SELECTION);
browser_window_key_press(gwin->bw, KEY_CLEAR_SELECTION);
break;
case 'v':
browser_window_key_press(gwin->bw, KEY_PASTE);
break;
@ -3615,6 +3621,8 @@ void gui_window_place_caret(struct gui_window *g, int x, int y, int height)
g->c_x = x;
g->c_y = y;
g->c_h = height;
OnMenu(g->shared->win, AMI_MENU_PASTE);
}
void gui_window_remove_caret(struct gui_window *g)
@ -3624,6 +3632,8 @@ void gui_window_remove_caret(struct gui_window *g)
if(!g) return;
OffMenu(g->shared->win, AMI_MENU_PASTE);
GetAttr(SPACE_AreaBox, g->shared->objects[GID_BROWSER], (ULONG *)&bbox);
ami_get_hscroll_pos(g->shared, (ULONG *)&xs);
ami_get_vscroll_pos(g->shared, (ULONG *)&ys);
@ -3772,3 +3782,78 @@ uint32 ami_popup_hook(struct Hook *hook,Object *item,APTR reserved)
return itemid;
}
/* Below two are more suited to clipboard.c but use some functions internal to gui.c,
so we put them here. */
bool ami_drag_selection_paste(const char *text, size_t length, struct box *box,
void *handle, const char *whitespace_text,size_t whitespace_length)
{
struct browser_window *bw = handle;
printf("dspaste\n");
if(whitespace_text)
{
browser_window_paste_text(bw, whitespace_text, whitespace_length, true);
}
if(text)
{
browser_window_paste_text(bw, text, length, true);
}
return true;
}
void ami_drag_selection(struct selection *s)
{
struct gui_window *g = s->bw->window;
struct IBox *bbox;
ULONG x,y,xs,ys,width,height;
struct box *box,*text_box=0;
hlcache_handle *content;
int box_x=0,box_y=0;
GetAttr(SPACE_AreaBox, (Object *)g->shared->objects[GID_BROWSER],
(ULONG *)&bbox);
ami_get_hscroll_pos(g->shared, (ULONG *)&xs);
x = (s->bw->window->shared->win->MouseX) - (bbox->Left) +xs;
ami_get_vscroll_pos(g->shared, (ULONG *)&ys);
y = (s->bw->window->shared->win->MouseY) - bbox->Top + ys;
width=bbox->Width;
height=bbox->Height;
content = s->bw->current_content;
box = html_get_box_tree(content);
while ((box = box_at_point(box, x, y, &box_x, &box_y, &content)))
{
if (box->style && css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN) continue;
if (box->gadget)
{
switch (box->gadget->type)
{
case GADGET_TEXTBOX:
case GADGET_TEXTAREA:
case GADGET_PASSWORD:
text_box = box;
break;
default:
break;
}
}
}
if(text_box)
{
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);
}
}
}

View File

@ -128,6 +128,8 @@ void ami_quit_netsurf(void);
void ami_do_redraw(struct gui_window_2 *g);
STRPTR ami_locale_langs(void);
void ami_drag_selection(struct selection *s);
struct TextFont *origrpfont;
struct MinList *window_list;
struct Screen *scrn;

View File

@ -95,27 +95,29 @@ void ami_init_menulabs(void)
menulab[17] = ami_utf8_easy((char *)messages_get("About"));
menulab[18] = ami_utf8_easy((char *)messages_get("Quit"));
menulab[19] = ami_utf8_easy((char *)messages_get("Edit"));
menulab[20] = ami_utf8_easy((char *)messages_get("CopyNS"));
menulab[21] = ami_utf8_easy((char *)messages_get("PasteNS"));
menulab[22] = ami_utf8_easy((char *)messages_get("SelectAllNS"));
menulab[23] = ami_utf8_easy((char *)messages_get("ClearNS"));
menulab[24] = ami_utf8_easy((char *)messages_get("Browser"));
menulab[25] = ami_utf8_easy((char *)messages_get("FindTextNS"));
menulab[26] = NM_BARLABEL;
menulab[27] = ami_utf8_easy((char *)messages_get("HistLocalNS"));
menulab[28] = ami_utf8_easy((char *)messages_get("HistGlobalNS"));
menulab[29] = NM_BARLABEL;
menulab[30] = ami_utf8_easy((char *)messages_get("ShowCookies"));
menulab[20] = ami_utf8_easy((char *)messages_get("CutNS"));
menulab[21] = ami_utf8_easy((char *)messages_get("CopyNS"));
menulab[22] = ami_utf8_easy((char *)messages_get("PasteNS"));
menulab[23] = NM_BARLABEL;
menulab[24] = ami_utf8_easy((char *)messages_get("SelectAllNS"));
menulab[25] = ami_utf8_easy((char *)messages_get("ClearNS"));
menulab[26] = ami_utf8_easy((char *)messages_get("Browser"));
menulab[27] = ami_utf8_easy((char *)messages_get("FindTextNS"));
menulab[28] = NM_BARLABEL;
menulab[29] = ami_utf8_easy((char *)messages_get("HistLocalNS"));
menulab[30] = ami_utf8_easy((char *)messages_get("HistGlobalNS"));
menulab[31] = NM_BARLABEL;
menulab[32] = ami_utf8_easy((char *)messages_get("ScaleNS"));
menulab[33] = ami_utf8_easy((char *)messages_get("ScaleDec"));
menulab[34] = ami_utf8_easy((char *)messages_get("ScaleNorm"));
menulab[35] = ami_utf8_easy((char *)messages_get("ScaleInc"));
menulab[36] = ami_utf8_easy((char *)messages_get("Redraw"));
menulab[37] = ami_utf8_easy((char *)messages_get("Hotlist"));
menulab[38] = ami_utf8_easy((char *)messages_get("HotlistAdd"));
menulab[39] = ami_utf8_easy((char *)messages_get("HotlistShowNS"));
menulab[40] = NM_BARLABEL;
menulab[32] = ami_utf8_easy((char *)messages_get("ShowCookies"));
menulab[33] = NM_BARLABEL;
menulab[34] = ami_utf8_easy((char *)messages_get("ScaleNS"));
menulab[35] = ami_utf8_easy((char *)messages_get("ScaleDec"));
menulab[36] = ami_utf8_easy((char *)messages_get("ScaleNorm"));
menulab[37] = ami_utf8_easy((char *)messages_get("ScaleInc"));
menulab[38] = ami_utf8_easy((char *)messages_get("Redraw"));
menulab[39] = ami_utf8_easy((char *)messages_get("Hotlist"));
menulab[40] = ami_utf8_easy((char *)messages_get("HotlistAdd"));
menulab[41] = ami_utf8_easy((char *)messages_get("HotlistShowNS"));
menulab[42] = NM_BARLABEL;
menulab[AMI_MENU_HOTLIST_MAX] = ami_utf8_easy((char *)messages_get("Settings"));
menulab[AMI_MENU_HOTLIST_MAX+1] = ami_utf8_easy((char *)messages_get("SettingsEdit"));
@ -152,8 +154,10 @@ struct NewMenu *ami_create_menu(ULONG type)
{ NM_ITEM,0,"?",0,0,0,}, // about
{ NM_ITEM,0,"Q",0,0,0,}, // quit
{NM_TITLE,0,0,0,0,0,}, // edit
{ NM_ITEM,0,"X",0,0,0,}, // cut
{ NM_ITEM,0,"C",0,0,0,}, // copy
{ NM_ITEM,0,"V",0,0,0,}, // paste
{ NM_ITEM,NM_BARLABEL,0,0,0,0,},
{ NM_ITEM,0,"A",0,0,0,}, // select all
{ NM_ITEM,0,"Z",0,0,0,}, // clear selection
{NM_TITLE,0,0,0,0,0,}, // browser
@ -629,7 +633,12 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item)
case 1: // edit
switch(itemnum)
{
case 0: // copy
case 0: // cut
browser_window_key_press(gwin->bw, KEY_COPY_SELECTION);
browser_window_key_press(gwin->bw, KEY_CUT_SELECTION);
break;
case 1: // copy
if(content_get_type(gwin->bw->current_content) <= CONTENT_CSS)
{
browser_window_key_press(gwin->bw, KEY_COPY_SELECTION);
@ -649,16 +658,16 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item)
#endif
break;
case 1: // paste
case 2: // paste
browser_window_key_press(gwin->bw, KEY_PASTE);
//gui_paste_from_clipboard(&tgw,0,0);
break;
case 2: // select all
case 4: // select all
browser_window_key_press(gwin->bw, KEY_SELECT_ALL);
break;
case 3: // clear selection
case 5: // clear selection
browser_window_key_press(gwin->bw, KEY_CLEAR_SELECTION);
break;
}
@ -824,6 +833,10 @@ static const ULONG ami_asl_mime_hook(struct Hook *mh,struct FileRequester *fr,st
void ami_menu_update_disabled(struct Window *win, hlcache_handle *c)
{
OffMenu(win,AMI_MENU_CUT);
OffMenu(win,AMI_MENU_CLEAR);
OffMenu(win,AMI_MENU_PASTE); // c_h
if(content_get_type(c) <= CONTENT_CSS)
{
OnMenu(win,AMI_MENU_SAVEAS_TEXT);
@ -831,10 +844,8 @@ void ami_menu_update_disabled(struct Window *win, hlcache_handle *c)
#ifdef WITH_PDF_EXPORT
OnMenu(win,AMI_MENU_SAVEAS_PDF);
#endif
OnMenu(win,AMI_MENU_COPY);
OnMenu(win,AMI_MENU_PASTE);
OffMenu(win,AMI_MENU_COPY);
OnMenu(win,AMI_MENU_SELECTALL);
OnMenu(win,AMI_MENU_CLEAR);
OnMenu(win,AMI_MENU_FIND);
OffMenu(win,AMI_MENU_SAVEAS_IFF);
}

View File

@ -28,10 +28,10 @@
/* Maximum number of menu items - first value is number of static items
* (ie. everything not intially defined as NM_IGNORE) */
#define AMI_MENU_MAX 49 + AMI_HOTLIST_ITEMS
#define AMI_MENU_MAX 51 + AMI_HOTLIST_ITEMS
/* Where the hotlist entries start */
#define AMI_MENU_HOTLIST 41
#define AMI_MENU_HOTLIST 43
/* Where the hotlist entries end */
#define AMI_MENU_HOTLIST_MAX AMI_MENU_HOTLIST+AMI_HOTLIST_ITEMS
@ -54,10 +54,11 @@
#define AMI_MENU_SAVEAS_PDF FULLMENUNUM(0,4,3)
#define AMI_MENU_SAVEAS_IFF FULLMENUNUM(0,4,4)
#define AMI_MENU_CLOSETAB FULLMENUNUM(0,6,0)
#define AMI_MENU_COPY FULLMENUNUM(1,0,0)
#define AMI_MENU_PASTE FULLMENUNUM(1,1,0)
#define AMI_MENU_SELECTALL FULLMENUNUM(1,2,0)
#define AMI_MENU_CLEAR FULLMENUNUM(1,3,0)
#define AMI_MENU_CUT FULLMENUNUM(1,0,0)
#define AMI_MENU_COPY FULLMENUNUM(1,1,0)
#define AMI_MENU_PASTE FULLMENUNUM(1,2,0)
#define AMI_MENU_SELECTALL FULLMENUNUM(1,4,0)
#define AMI_MENU_CLEAR FULLMENUNUM(1,5,0)
#define AMI_MENU_FIND FULLMENUNUM(2,0,0)
char *menulab[AMI_MENU_MAX+1];

View File

@ -1783,6 +1783,10 @@ void gui_start_selection(struct gui_window *g)
g->view->UnlockLooper();
}
void gui_clear_selection(struct gui_window *g)
{
}
void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
{
BMessage *clip;

View File

@ -117,6 +117,7 @@ void gui_drag_save_object(gui_save_type type, hlcache_handle *c,
struct gui_window *g);
void gui_drag_save_selection(struct selection *s, struct gui_window *g);
void gui_start_selection(struct gui_window *g);
void gui_clear_selection(struct gui_window *g);
void gui_paste_from_clipboard(struct gui_window *g, int x, int y);
bool gui_empty_clipboard(void);

View File

@ -703,6 +703,8 @@ void selection_clear(struct selection *s, bool redraw)
s->start_idx = 0;
s->end_idx = 0;
gui_clear_selection(s->bw->window);
if (redraw && was_defined)
selection_redraw(s, old_start, old_end);
}

View File

@ -1453,6 +1453,11 @@ gui_start_selection(struct gui_window *g)
{
}
void
gui_clear_selection(struct gui_window *g)
{
}
void
gui_paste_from_clipboard(struct gui_window *g, int x, int y)
{

View File

@ -82,6 +82,10 @@ void gui_start_selection(struct gui_window *g)
gtk_widget_grab_focus(GTK_WIDGET(nsgtk_window_get_layout(g)));
}
void gui_clear_selection(struct gui_window *g)
{
}
void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
{
gchar *text;

View File

@ -248,6 +248,17 @@ bool gui_empty_clipboard(void)
}
/**
* Perform tasks after a selection has been cleared.
*
* \param g gui window
*/
void gui_clear_selection(struct gui_window *g)
{
}
/**
* Add some text to the clipboard, optionally appending a trailing space.
*

View File

@ -2183,6 +2183,10 @@ void gui_start_selection(struct gui_window *w)
{
}
void gui_clear_selection(struct gui_window *w)
{
}
void gui_paste_from_clipboard(struct gui_window *w, int x, int y)
{
HANDLE clipboard_handle;