2011-09-19 22:38:48 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Ole Loots <ole@monochrom.net>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <windom.h>
|
|
|
|
|
|
|
|
#include "desktop/gui.h"
|
|
|
|
#include "desktop/netsurf.h"
|
2011-10-03 20:45:54 +04:00
|
|
|
#include "desktop/browser.h"
|
2011-09-19 22:38:48 +04:00
|
|
|
#include "desktop/mouse.h"
|
2011-10-03 20:45:54 +04:00
|
|
|
#include "desktop/textinput.h"
|
2011-09-19 22:38:48 +04:00
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/hlcache.h"
|
2012-07-15 00:15:05 +04:00
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "render/html.h"
|
2011-09-19 22:38:48 +04:00
|
|
|
#include "css/css.h"
|
|
|
|
#include "render/box.h"
|
|
|
|
#include "render/form.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
|
|
|
|
#include "atari/gui.h"
|
2011-10-03 20:45:54 +04:00
|
|
|
#include "atari/browser.h"
|
|
|
|
#include "atari/browser_win.h"
|
|
|
|
#include "atari/misc.h"
|
|
|
|
#include "atari/clipboard.h"
|
2012-03-22 13:34:34 +04:00
|
|
|
#include "desktop/options.h"
|
2011-10-03 20:45:54 +04:00
|
|
|
#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 )
|
|
|
|
{
|
2011-09-19 22:38:48 +04:00
|
|
|
struct box *box;
|
|
|
|
hlcache_handle *h;
|
|
|
|
int box_x, box_y;
|
2011-10-03 20:45:54 +04:00
|
|
|
LGRECT bwrect;
|
2011-09-19 22:38:48 +04:00
|
|
|
struct contextual_content ccdata;
|
2012-07-15 00:15:05 +04:00
|
|
|
struct browser_window * bw = gw->browser->bw;
|
2011-10-03 20:45:54 +04:00
|
|
|
|
2012-07-15 00:15:05 +04:00
|
|
|
h = bw->current_content;
|
2011-10-03 20:45:54 +04:00
|
|
|
ctxinfo.flags = 0;
|
|
|
|
|
2011-10-14 00:39:39 +04:00
|
|
|
browser_get_rect( gw, BR_CONTENT, &bwrect );
|
|
|
|
mx -= bwrect.g_x;
|
|
|
|
my -= bwrect.g_y;
|
2011-10-03 20:45:54 +04:00
|
|
|
if( (mx < 0 || mx > bwrect.g_w) || (my < 0 || my > bwrect.g_h) ){
|
|
|
|
// TODO: check for urlinput location
|
2011-09-19 22:38:48 +04:00
|
|
|
// and set CNT_URLINPUT
|
2011-10-03 20:45:54 +04:00
|
|
|
return(&ctxinfo);
|
|
|
|
}
|
|
|
|
|
2011-09-19 22:38:48 +04:00
|
|
|
if (!bw->current_content || content_get_type(h) != CONTENT_HTML){
|
2011-10-14 00:39:39 +04:00
|
|
|
return(&ctxinfo);
|
2011-10-03 20:45:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ctxinfo.flags |= CNT_BROWSER;
|
|
|
|
memset( &ctxinfo.ccdata, sizeof(struct contextual_content), 0 );
|
|
|
|
browser_window_get_contextual_content(
|
2011-10-14 00:39:39 +04:00
|
|
|
gw->browser->bw,
|
2011-11-29 03:23:28 +04:00
|
|
|
mx+gw->browser->scroll.current.x,
|
2011-10-14 00:39:39 +04:00
|
|
|
my+gw->browser->scroll.current.y,
|
2011-10-03 20:45:54 +04:00
|
|
|
(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;
|
|
|
|
}
|
|
|
|
}
|
2011-09-19 22:38:48 +04:00
|
|
|
|
|
|
|
box = html_get_box_tree(h);
|
|
|
|
box_x = box->margin[LEFT];
|
2011-10-03 20:45:54 +04:00
|
|
|
box_y = box->margin[TOP];
|
2011-09-19 22:38:48 +04:00
|
|
|
|
|
|
|
while ((box = box_at_point(box, mx+gw->browser->scroll.current.x, my+gw->browser->scroll.current.y, &box_x, &box_y, &h)))
|
2011-10-14 00:39:39 +04:00
|
|
|
{
|
|
|
|
if (box->style && css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN)
|
2011-10-03 20:45:54 +04:00
|
|
|
continue;
|
2011-09-19 22:38:48 +04:00
|
|
|
if (box->gadget)
|
2011-10-14 00:39:39 +04:00
|
|
|
{
|
2011-09-19 22:38:48 +04:00
|
|
|
switch (box->gadget->type)
|
|
|
|
{
|
|
|
|
case GADGET_TEXTBOX:
|
|
|
|
case GADGET_TEXTAREA:
|
2011-10-03 20:45:54 +04:00
|
|
|
case GADGET_PASSWORD:
|
|
|
|
// TODO: check if there is really an selection, but it
|
|
|
|
// doesn't hurt for now...:
|
2011-09-19 22:38:48 +04:00
|
|
|
ctxinfo.flags |= (CNT_INTERACTIVE | CNT_SELECTION);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
2011-10-14 00:39:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return( &ctxinfo );
|
2011-10-03 20:45:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void context_popup( struct gui_window * gw, short x, short y )
|
|
|
|
{
|
2011-10-14 00:39:39 +04:00
|
|
|
|
|
|
|
#define POP_FIRST_ITEM POP_CTX_CUT_SEL
|
2012-06-05 01:53:06 +04:00
|
|
|
#define POP_LAST_ITEM POP_CTX_SAVE_LINK_AS
|
2011-10-14 00:39:39 +04:00
|
|
|
|
|
|
|
OBJECT * pop;
|
|
|
|
int choice;
|
|
|
|
struct s_context_info * ctx;
|
2011-10-03 20:45:54 +04:00
|
|
|
unsigned long size;
|
2012-07-15 00:15:05 +04:00
|
|
|
const char * data;
|
2011-10-03 20:45:54 +04:00
|
|
|
FILE * fp_tmpfile;
|
|
|
|
char * tempfile;
|
2012-07-14 00:19:04 +04:00
|
|
|
int err = 0;
|
|
|
|
char * editor;
|
2011-11-29 03:23:28 +04:00
|
|
|
char cmdline[128];
|
2011-10-03 20:45:54 +04:00
|
|
|
|
2011-10-14 00:39:39 +04:00
|
|
|
pop = get_tree( POP_CTX );
|
2012-07-15 00:15:05 +04:00
|
|
|
if (pop == NULL)
|
2011-10-14 00:39:39 +04:00
|
|
|
return;
|
2012-07-15 00:15:05 +04:00
|
|
|
ctx = get_context_info(gw, x, y);
|
2011-10-03 20:45:54 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
Disable all items by default:
|
|
|
|
*/
|
2011-10-14 00:39:39 +04:00
|
|
|
for( choice = POP_FIRST_ITEM; choice<=POP_LAST_ITEM; choice++ ){
|
2011-10-03 20:45:54 +04:00
|
|
|
SET_BIT(pop[ choice ].ob_state, DISABLED, 1);
|
2011-10-14 00:39:39 +04:00
|
|
|
}
|
2011-10-03 20:45:54 +04:00
|
|
|
|
2011-10-14 00:39:39 +04:00
|
|
|
if( ctx->flags & CNT_INTERACTIVE ){
|
|
|
|
SET_BIT(pop[ POP_CTX_PASTE_SEL ].ob_state, DISABLED, 0);
|
|
|
|
}
|
2011-10-03 20:45:54 +04:00
|
|
|
|
|
|
|
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);
|
2011-10-14 00:39:39 +04:00
|
|
|
SET_BIT(pop[ POP_CTX_VIEW_SOURCE ].ob_state, DISABLED, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ctx->flags & CNT_HREF ){
|
2012-06-05 01:53:06 +04:00
|
|
|
SET_BIT(pop[ POP_CTX_COPY_LINK ].ob_state, DISABLED, 0);
|
2012-07-14 00:19:04 +04:00
|
|
|
SET_BIT(pop[ POP_CTX_OPEN_NEW ].ob_state, DISABLED, 0);
|
2012-06-05 01:53:06 +04:00
|
|
|
SET_BIT(pop[ POP_CTX_SAVE_LINK_AS ].ob_state, DISABLED, 0);
|
|
|
|
}
|
2011-10-14 00:39:39 +04:00
|
|
|
|
|
|
|
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);
|
2011-10-03 20:45:54 +04:00
|
|
|
}
|
|
|
|
|
2011-10-14 00:39:39 +04:00
|
|
|
choice = MenuPopUp(
|
|
|
|
pop, x, y,
|
|
|
|
-1, -1, -1,
|
|
|
|
P_WNDW + P_CHCK
|
|
|
|
);
|
|
|
|
|
|
|
|
switch( choice ){
|
2011-10-03 20:45:54 +04:00
|
|
|
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;
|
|
|
|
|
2012-07-14 00:19:04 +04:00
|
|
|
case POP_CTX_SAVE_AS:
|
|
|
|
if( ctx->ccdata.object != NULL ) {
|
2012-06-05 01:53:06 +04:00
|
|
|
if( hlcache_handle_get_url(ctx->ccdata.object) != NULL ) {
|
|
|
|
browser_window_download(
|
|
|
|
gw->browser->bw,
|
|
|
|
nsurl_access(hlcache_handle_get_url(ctx->ccdata.object)),
|
|
|
|
nsurl_access(hlcache_handle_get_url(gw->browser->bw->current_content))
|
|
|
|
);
|
2012-07-14 00:19:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case POP_CTX_SAVE_LINK_AS:
|
|
|
|
if( ctx->ccdata.link_url != NULL ) {
|
2011-10-03 20:45:54 +04:00
|
|
|
browser_window_download(
|
|
|
|
gw->browser->bw,
|
2012-07-15 00:15:05 +04:00
|
|
|
ctx->ccdata.link_url,
|
2011-12-04 18:55:23 +04:00
|
|
|
nsurl_access(hlcache_handle_get_url(gw->browser->bw->current_content))
|
2012-07-14 00:19:04 +04:00
|
|
|
);
|
2011-10-03 20:45:54 +04:00
|
|
|
}
|
2012-06-05 01:53:06 +04:00
|
|
|
|
2011-10-03 20:45:54 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case POP_CTX_COPY_URL:
|
|
|
|
if( (ctx->flags & CNT_IMG) && (ctx->ccdata.object != NULL) ){
|
2011-12-04 18:55:23 +04:00
|
|
|
if( hlcache_handle_get_url(ctx->ccdata.object) != NULL ){
|
|
|
|
scrap_txt_write(&app, (char*)nsurl_access(hlcache_handle_get_url(ctx->ccdata.object)) );
|
2011-10-03 20:45:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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,
|
2011-12-04 18:55:23 +04:00
|
|
|
nsurl_access(hlcache_handle_get_url(gw->browser->bw->current_content)),
|
2011-10-03 20:45:54 +04:00
|
|
|
true, false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-07-14 00:19:04 +04:00
|
|
|
case POP_CTX_VIEW_SOURCE:
|
2012-06-23 04:17:57 +04:00
|
|
|
editor = nsoption_charp(atari_editor);
|
2012-07-15 00:15:05 +04:00
|
|
|
if (editor != NULL && strlen(editor)>0) {
|
|
|
|
data = content_get_source_data(gw->browser->bw->current_content,
|
|
|
|
&size);
|
|
|
|
if (size > 0 && data != NULL){
|
2011-10-03 20:45:54 +04:00
|
|
|
tempfile = tmpnam( NULL );
|
|
|
|
fp_tmpfile = fopen( tempfile, "w" );
|
2012-07-15 00:15:05 +04:00
|
|
|
if (fp_tmpfile != NULL){
|
|
|
|
fwrite(data, size, 1, fp_tmpfile);
|
|
|
|
fclose(fp_tmpfile );
|
2012-07-14 00:19:04 +04:00
|
|
|
|
|
|
|
// TODO: check if app is runnin, if not, use pexec or such.
|
|
|
|
/*
|
|
|
|
sprintf((char*)&cmdline, "%s \"%s\"", nsoption_charp(atari_editor), tempfile );
|
|
|
|
system( (char*)&cmdline );
|
|
|
|
*/
|
|
|
|
err = ShelWrite( editor, tempfile , editor, 1, 0);
|
2012-06-23 04:17:57 +04:00
|
|
|
LOG(("Launched: %s %s (%d)\n", editor, tempfile, err ));
|
2012-07-14 00:19:04 +04:00
|
|
|
} else {
|
|
|
|
printf("Could not open temp file: %s!\n", tempfile );
|
|
|
|
}
|
2011-11-29 03:23:28 +04:00
|
|
|
|
2012-07-14 00:19:04 +04:00
|
|
|
} else {
|
|
|
|
LOG(("Invalid content!"));
|
2011-10-03 20:45:54 +04:00
|
|
|
}
|
2012-07-14 00:19:04 +04:00
|
|
|
} else {
|
|
|
|
form_alert(0, "[1][Set option \"option_atari_editor\".][OK]");
|
2011-10-03 20:45:54 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
2011-10-14 00:39:39 +04:00
|
|
|
}
|
|
|
|
|
2011-10-03 20:45:54 +04:00
|
|
|
#undef POP_FIRST_ITEM
|
|
|
|
#undef POP_LAST_ITEM
|
2011-10-14 00:39:39 +04:00
|
|
|
|
2011-09-19 22:38:48 +04:00
|
|
|
}
|