mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-27 00:40:15 +03:00
Fix up for nsurl changes. Untested.
svn path=/trunk/netsurf/; revision=12929
This commit is contained in:
parent
e52aaecd7a
commit
7dc000e643
384
atari/ctxmenu.c
384
atari/ctxmenu.c
@ -27,9 +27,9 @@
|
||||
|
||||
#include "desktop/gui.h"
|
||||
#include "desktop/netsurf.h"
|
||||
#include "desktop/browser.h"
|
||||
#include "desktop/browser.h"
|
||||
#include "desktop/mouse.h"
|
||||
#include "desktop/textinput.h"
|
||||
#include "desktop/textinput.h"
|
||||
#include "content/content.h"
|
||||
#include "content/hlcache.h"
|
||||
#include "content/urldb.h"
|
||||
@ -40,223 +40,223 @@
|
||||
#include "utils/messages.h"
|
||||
|
||||
#include "atari/gui.h"
|
||||
#include "atari/browser.h"
|
||||
#include "atari/browser_win.h"
|
||||
#include "atari/misc.h"
|
||||
#include "atari/clipboard.h"
|
||||
#include "atari/options.h"
|
||||
#include "atari/res/netsurf.rsh"
|
||||
#include "atari/ctxmenu.h"
|
||||
|
||||
|
||||
#define CNT_INVALID 0
|
||||
#define CNT_URLINPUT 32
|
||||
#define CNT_BROWSER 64
|
||||
#define CNT_HREF 128
|
||||
#define CNT_SELECTION 256
|
||||
#define CNT_INTERACTIVE 512
|
||||
#define CNT_IMG 1024
|
||||
|
||||
|
||||
struct s_context_info {
|
||||
unsigned long flags;
|
||||
struct contextual_content ccdata;
|
||||
};
|
||||
|
||||
struct s_context_info ctxinfo;
|
||||
|
||||
static struct s_context_info * get_context_info( struct gui_window * gw, short mx, short my )
|
||||
{
|
||||
#include "atari/browser.h"
|
||||
#include "atari/browser_win.h"
|
||||
#include "atari/misc.h"
|
||||
#include "atari/clipboard.h"
|
||||
#include "atari/options.h"
|
||||
#include "atari/res/netsurf.rsh"
|
||||
#include "atari/ctxmenu.h"
|
||||
|
||||
|
||||
#define CNT_INVALID 0
|
||||
#define CNT_URLINPUT 32
|
||||
#define CNT_BROWSER 64
|
||||
#define CNT_HREF 128
|
||||
#define CNT_SELECTION 256
|
||||
#define CNT_INTERACTIVE 512
|
||||
#define CNT_IMG 1024
|
||||
|
||||
|
||||
struct s_context_info {
|
||||
unsigned long flags;
|
||||
struct contextual_content ccdata;
|
||||
};
|
||||
|
||||
struct s_context_info ctxinfo;
|
||||
|
||||
static struct s_context_info * get_context_info( struct gui_window * gw, short mx, short my )
|
||||
{
|
||||
int posx, posy;
|
||||
struct box *box;
|
||||
struct box *file_box = 0;
|
||||
hlcache_handle *h;
|
||||
int box_x, box_y;
|
||||
LGRECT bwrect;
|
||||
LGRECT bwrect;
|
||||
struct contextual_content ccdata;
|
||||
struct browser_window * bw = gw->browser->bw;
|
||||
h = bw->current_content;
|
||||
|
||||
ctxinfo.flags = 0;
|
||||
|
||||
h = bw->current_content;
|
||||
|
||||
ctxinfo.flags = 0;
|
||||
|
||||
browser_get_rect( gw, BR_CONTENT, &bwrect );
|
||||
mx = mx - bwrect.g_x;
|
||||
my = my - bwrect.g_y;
|
||||
if( (mx < 0 || mx > bwrect.g_w) || (my < 0 || my > bwrect.g_h) ){
|
||||
// TODO: check for urlinput location
|
||||
if( (mx < 0 || mx > bwrect.g_w) || (my < 0 || my > bwrect.g_h) ){
|
||||
// TODO: check for urlinput location
|
||||
// and set CNT_URLINPUT
|
||||
return(&ctxinfo);
|
||||
}
|
||||
|
||||
return(&ctxinfo);
|
||||
}
|
||||
|
||||
if (!bw->current_content || content_get_type(h) != CONTENT_HTML){
|
||||
return(&ctxinfo);
|
||||
}
|
||||
|
||||
ctxinfo.flags |= CNT_BROWSER;
|
||||
memset( &ctxinfo.ccdata, sizeof(struct contextual_content), 0 );
|
||||
browser_window_get_contextual_content(
|
||||
gw->browser->bw, mx, my,
|
||||
(struct contextual_content*)&ctxinfo.ccdata
|
||||
);
|
||||
if( ctxinfo.ccdata.link_url ){
|
||||
ctxinfo.flags |= CNT_HREF;
|
||||
}
|
||||
if( ctxinfo.ccdata.object) {
|
||||
if( content_get_type(ctxinfo.ccdata.object) == CONTENT_IMAGE ){
|
||||
ctxinfo.flags |= CNT_IMG;
|
||||
}
|
||||
}
|
||||
return(&ctxinfo);
|
||||
}
|
||||
|
||||
ctxinfo.flags |= CNT_BROWSER;
|
||||
memset( &ctxinfo.ccdata, sizeof(struct contextual_content), 0 );
|
||||
browser_window_get_contextual_content(
|
||||
gw->browser->bw, mx, my,
|
||||
(struct contextual_content*)&ctxinfo.ccdata
|
||||
);
|
||||
if( ctxinfo.ccdata.link_url ){
|
||||
ctxinfo.flags |= CNT_HREF;
|
||||
}
|
||||
if( ctxinfo.ccdata.object) {
|
||||
if( content_get_type(ctxinfo.ccdata.object) == CONTENT_IMAGE ){
|
||||
ctxinfo.flags |= CNT_IMG;
|
||||
}
|
||||
}
|
||||
|
||||
box = html_get_box_tree(h);
|
||||
box_x = box->margin[LEFT];
|
||||
box_y = box->margin[TOP];
|
||||
box_y = box->margin[TOP];
|
||||
|
||||
while ((box = box_at_point(box, mx+gw->browser->scroll.current.x, my+gw->browser->scroll.current.y, &box_x, &box_y, &h)))
|
||||
{
|
||||
{
|
||||
if (box->style && css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN)
|
||||
continue;
|
||||
continue;
|
||||
if (box->gadget)
|
||||
{
|
||||
switch (box->gadget->type)
|
||||
{
|
||||
case GADGET_TEXTBOX:
|
||||
case GADGET_TEXTAREA:
|
||||
case GADGET_PASSWORD:
|
||||
// TODO: check if there is really an selection, but it
|
||||
// doesn't hurt for now...:
|
||||
case GADGET_PASSWORD:
|
||||
// TODO: check if there is really an selection, but it
|
||||
// doesn't hurt for now...:
|
||||
ctxinfo.flags |= (CNT_INTERACTIVE | CNT_SELECTION);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return( &ctxinfo );
|
||||
}
|
||||
|
||||
void context_popup( struct gui_window * gw, short x, short y )
|
||||
{
|
||||
#define POP_FIRST_ITEM POP_CTX_CUT_SEL
|
||||
#define POP_LAST_ITEM POP_CTX_VIEW_SOURCE
|
||||
OBJECT * pop;
|
||||
int choice;
|
||||
struct s_context_info * ctx;
|
||||
unsigned long size;
|
||||
char * data;
|
||||
FILE * fp_tmpfile;
|
||||
char * tempfile;
|
||||
int err = 0;
|
||||
|
||||
pop = get_tree( POP_CTX );
|
||||
if( pop == NULL )
|
||||
return;
|
||||
ctx = get_context_info( gw, x, y );
|
||||
|
||||
/*
|
||||
Disable all items by default:
|
||||
*/
|
||||
for( choice = POP_FIRST_ITEM; choice<=POP_LAST_ITEM; choice++ ){
|
||||
SET_BIT(pop[ choice ].ob_state, DISABLED, 1);
|
||||
}
|
||||
|
||||
if( ctx->flags & CNT_INTERACTIVE ){
|
||||
SET_BIT(pop[ POP_CTX_PASTE_SEL ].ob_state, DISABLED, 0);
|
||||
}
|
||||
|
||||
if( (ctx->flags & CNT_BROWSER) ){
|
||||
SET_BIT(pop[ POP_CTX_SELECT_ALL ].ob_state, DISABLED, 0);
|
||||
SET_BIT(pop[ POP_CTX_COPY_SEL ].ob_state, DISABLED, 0);
|
||||
SET_BIT(pop[ POP_CTX_VIEW_SOURCE ].ob_state, DISABLED, 0);
|
||||
}
|
||||
|
||||
if( ctx->flags & CNT_HREF ){
|
||||
SET_BIT(pop[ POP_CTX_SAVE_AS ].ob_state, DISABLED, 0);
|
||||
SET_BIT(pop[ POP_CTX_COPY_LINK ].ob_state, DISABLED, 0);
|
||||
SET_BIT(pop[ POP_CTX_OPEN_NEW ].ob_state, DISABLED, 0);
|
||||
}
|
||||
|
||||
if( ctx->flags & CNT_IMG ){
|
||||
SET_BIT(pop[ POP_CTX_SAVE_AS ].ob_state, DISABLED, 0);
|
||||
SET_BIT(pop[ POP_CTX_COPY_URL ].ob_state, DISABLED, 0);
|
||||
SET_BIT(pop[ POP_CTX_OPEN_NEW ].ob_state, DISABLED, 0);
|
||||
}
|
||||
|
||||
choice = MenuPopUp(
|
||||
pop, x, y,
|
||||
-1, -1, -1,
|
||||
P_WNDW + P_CHCK
|
||||
);
|
||||
|
||||
switch( choice ){
|
||||
case POP_CTX_COPY_SEL:
|
||||
browser_window_key_press( gw->browser->bw, KEY_COPY_SELECTION );
|
||||
break;
|
||||
|
||||
case POP_CTX_CUT_SEL:
|
||||
browser_window_key_press( gw->browser->bw, KEY_CUT_SELECTION );
|
||||
break;
|
||||
|
||||
case POP_CTX_PASTE_SEL:
|
||||
gui_paste_from_clipboard(gw, x, y);
|
||||
break;
|
||||
|
||||
case POP_CTX_SELECT_ALL:
|
||||
browser_window_key_press( gw->browser->bw, KEY_SELECT_ALL );
|
||||
break;
|
||||
|
||||
case POP_CTX_SAVE_AS:
|
||||
if( content_get_url(ctx->ccdata.object) != NULL ){
|
||||
browser_window_download(
|
||||
gw->browser->bw,
|
||||
content_get_url(ctx->ccdata.object),
|
||||
content_get_url(gw->browser->bw->current_content)
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case POP_CTX_COPY_URL:
|
||||
if( (ctx->flags & CNT_IMG) && (ctx->ccdata.object != NULL) ){
|
||||
if( content_get_url(ctx->ccdata.object) != NULL ){
|
||||
scrap_txt_write(&app, (char*)content_get_url(ctx->ccdata.object) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case POP_CTX_COPY_LINK:
|
||||
if( (ctx->flags & CNT_HREF) && ctx->ccdata.link_url != NULL ){
|
||||
scrap_txt_write(&app, (char*)ctx->ccdata.link_url);
|
||||
}
|
||||
break;
|
||||
|
||||
case POP_CTX_OPEN_NEW:
|
||||
if( (ctx->flags & CNT_HREF) && ctx->ccdata.link_url) {
|
||||
browser_window_create(
|
||||
ctx->ccdata.link_url,
|
||||
gw->browser->bw,
|
||||
content_get_url(gw->browser->bw->current_content),
|
||||
true, false
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case POP_CTX_VIEW_SOURCE:
|
||||
if( option_atari_editor != NULL ) {
|
||||
data = content_get_source_data( gw->browser->bw->current_content, &size );
|
||||
if( size > 0 && data != NULL ){
|
||||
tempfile = tmpnam( NULL );
|
||||
fp_tmpfile = fopen( tempfile, "w" );
|
||||
if( fp_tmpfile ){
|
||||
fwrite( data, size, 1, fp_tmpfile );
|
||||
fclose( fp_tmpfile );
|
||||
err = ShelWrite( option_atari_editor, tempfile , NULL, 1, 0);
|
||||
LOG(("launched: %s %s (%d)\n", option_atari_editor, tempfile, err ));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
#undef POP_FIRST_ITEM
|
||||
#undef POP_LAST_ITEM
|
||||
}
|
||||
}
|
||||
return( &ctxinfo );
|
||||
}
|
||||
|
||||
void context_popup( struct gui_window * gw, short x, short y )
|
||||
{
|
||||
#define POP_FIRST_ITEM POP_CTX_CUT_SEL
|
||||
#define POP_LAST_ITEM POP_CTX_VIEW_SOURCE
|
||||
OBJECT * pop;
|
||||
int choice;
|
||||
struct s_context_info * ctx;
|
||||
unsigned long size;
|
||||
char * data;
|
||||
FILE * fp_tmpfile;
|
||||
char * tempfile;
|
||||
int err = 0;
|
||||
|
||||
pop = get_tree( POP_CTX );
|
||||
if( pop == NULL )
|
||||
return;
|
||||
ctx = get_context_info( gw, x, y );
|
||||
|
||||
/*
|
||||
Disable all items by default:
|
||||
*/
|
||||
for( choice = POP_FIRST_ITEM; choice<=POP_LAST_ITEM; choice++ ){
|
||||
SET_BIT(pop[ choice ].ob_state, DISABLED, 1);
|
||||
}
|
||||
|
||||
if( ctx->flags & CNT_INTERACTIVE ){
|
||||
SET_BIT(pop[ POP_CTX_PASTE_SEL ].ob_state, DISABLED, 0);
|
||||
}
|
||||
|
||||
if( (ctx->flags & CNT_BROWSER) ){
|
||||
SET_BIT(pop[ POP_CTX_SELECT_ALL ].ob_state, DISABLED, 0);
|
||||
SET_BIT(pop[ POP_CTX_COPY_SEL ].ob_state, DISABLED, 0);
|
||||
SET_BIT(pop[ POP_CTX_VIEW_SOURCE ].ob_state, DISABLED, 0);
|
||||
}
|
||||
|
||||
if( ctx->flags & CNT_HREF ){
|
||||
SET_BIT(pop[ POP_CTX_SAVE_AS ].ob_state, DISABLED, 0);
|
||||
SET_BIT(pop[ POP_CTX_COPY_LINK ].ob_state, DISABLED, 0);
|
||||
SET_BIT(pop[ POP_CTX_OPEN_NEW ].ob_state, DISABLED, 0);
|
||||
}
|
||||
|
||||
if( ctx->flags & CNT_IMG ){
|
||||
SET_BIT(pop[ POP_CTX_SAVE_AS ].ob_state, DISABLED, 0);
|
||||
SET_BIT(pop[ POP_CTX_COPY_URL ].ob_state, DISABLED, 0);
|
||||
SET_BIT(pop[ POP_CTX_OPEN_NEW ].ob_state, DISABLED, 0);
|
||||
}
|
||||
|
||||
choice = MenuPopUp(
|
||||
pop, x, y,
|
||||
-1, -1, -1,
|
||||
P_WNDW + P_CHCK
|
||||
);
|
||||
|
||||
switch( choice ){
|
||||
case POP_CTX_COPY_SEL:
|
||||
browser_window_key_press( gw->browser->bw, KEY_COPY_SELECTION );
|
||||
break;
|
||||
|
||||
case POP_CTX_CUT_SEL:
|
||||
browser_window_key_press( gw->browser->bw, KEY_CUT_SELECTION );
|
||||
break;
|
||||
|
||||
case POP_CTX_PASTE_SEL:
|
||||
gui_paste_from_clipboard(gw, x, y);
|
||||
break;
|
||||
|
||||
case POP_CTX_SELECT_ALL:
|
||||
browser_window_key_press( gw->browser->bw, KEY_SELECT_ALL );
|
||||
break;
|
||||
|
||||
case POP_CTX_SAVE_AS:
|
||||
if( content_get_url(ctx->ccdata.object) != NULL ){
|
||||
browser_window_download(
|
||||
gw->browser->bw,
|
||||
nsurl_access(content_get_url(ctx->ccdata.object)),
|
||||
nsurl_access(content_get_url(gw->browser->bw->current_content))
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case POP_CTX_COPY_URL:
|
||||
if( (ctx->flags & CNT_IMG) && (ctx->ccdata.object != NULL) ){
|
||||
if( content_get_url(ctx->ccdata.object) != NULL ){
|
||||
scrap_txt_write(&app, (char*)nsurl_access(content_get_url(ctx->ccdata.object)) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case POP_CTX_COPY_LINK:
|
||||
if( (ctx->flags & CNT_HREF) && ctx->ccdata.link_url != NULL ){
|
||||
scrap_txt_write(&app, (char*)ctx->ccdata.link_url);
|
||||
}
|
||||
break;
|
||||
|
||||
case POP_CTX_OPEN_NEW:
|
||||
if( (ctx->flags & CNT_HREF) && ctx->ccdata.link_url) {
|
||||
browser_window_create(
|
||||
ctx->ccdata.link_url,
|
||||
gw->browser->bw,
|
||||
nsurl_access(content_get_url(gw->browser->bw->current_content)),
|
||||
true, false
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case POP_CTX_VIEW_SOURCE:
|
||||
if( option_atari_editor != NULL ) {
|
||||
data = content_get_source_data( gw->browser->bw->current_content, &size );
|
||||
if( size > 0 && data != NULL ){
|
||||
tempfile = tmpnam( NULL );
|
||||
fp_tmpfile = fopen( tempfile, "w" );
|
||||
if( fp_tmpfile ){
|
||||
fwrite( data, size, 1, fp_tmpfile );
|
||||
fclose( fp_tmpfile );
|
||||
err = ShelWrite( option_atari_editor, tempfile , NULL, 1, 0);
|
||||
LOG(("launched: %s %s (%d)\n", option_atari_editor, tempfile, err ));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
#undef POP_FIRST_ITEM
|
||||
#undef POP_LAST_ITEM
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ static void __CDECL menu_home(WINDOW *win, int item, int title, void *data)
|
||||
|
||||
static void __CDECL menu_lhistory(WINDOW *win, int item, int title, void *data)
|
||||
{
|
||||
LOG(("%s", __FUNCTION__));
|
||||
LOG(("%s", __FUNCTION__));
|
||||
if( input_window == NULL )
|
||||
return;
|
||||
}
|
||||
@ -243,7 +243,7 @@ static void __CDECL menu_add_bookmark(WINDOW *win, int item, int title, void *da
|
||||
if( input_window ) {
|
||||
if( input_window->browser->bw->current_content != NULL ){
|
||||
atari_hotlist_add_page(
|
||||
content_get_url( input_window->browser->bw->current_content),
|
||||
nsurl_access(content_get_url( input_window->browser->bw->current_content)),
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user