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>
|
2013-01-07 23:04:44 +04:00
|
|
|
#include <assert.h>
|
2012-08-27 22:05:35 +04:00
|
|
|
#include <mint/osbind.h>
|
2011-09-19 22:38:48 +04:00
|
|
|
|
|
|
|
#include "desktop/gui.h"
|
|
|
|
#include "desktop/netsurf.h"
|
2011-10-03 20:45:54 +04:00
|
|
|
#include "desktop/browser.h"
|
2012-08-22 20:03:46 +04:00
|
|
|
#include "desktop/browser_private.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-08-21 01:25:02 +04:00
|
|
|
#include "content/urldb.h"
|
2011-09-19 22:38:48 +04:00
|
|
|
#include "css/css.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
|
|
|
|
#include "atari/gui.h"
|
2012-11-19 02:22:43 +04:00
|
|
|
#include "atari/rootwin.h"
|
2011-10-03 20:45:54 +04:00
|
|
|
#include "atari/misc.h"
|
|
|
|
#include "atari/clipboard.h"
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2011-10-03 20:45:54 +04:00
|
|
|
#include "atari/res/netsurf.rsh"
|
|
|
|
#include "atari/ctxmenu.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define CNT_INVALID 0
|
|
|
|
#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
|
|
|
hlcache_handle *h;
|
2013-01-11 05:12:30 +04:00
|
|
|
GRECT area;
|
2011-09-19 22:38:48 +04:00
|
|
|
struct contextual_content ccdata;
|
2013-01-03 04:22:38 +04:00
|
|
|
struct browser_window * bw = gw->browser->bw;
|
|
|
|
int sx, sy;
|
2011-10-03 20:45:54 +04:00
|
|
|
|
2012-07-15 00:15:05 +04:00
|
|
|
h = bw->current_content;
|
2013-01-11 05:12:30 +04:00
|
|
|
ctxinfo.flags = 0;
|
|
|
|
|
|
|
|
window_get_grect(gw->root, BROWSER_AREA_CONTENT, &area);
|
|
|
|
if (POINT_WITHIN(mx, my, area)) {
|
|
|
|
|
|
|
|
mx -= area.g_x;
|
|
|
|
my -= area.g_y;
|
|
|
|
|
|
|
|
if (!bw->current_content || content_get_type(h) != CONTENT_HTML){
|
|
|
|
return(&ctxinfo);
|
|
|
|
}
|
2011-10-03 20:45:54 +04:00
|
|
|
|
2013-01-11 05:12:30 +04:00
|
|
|
ctxinfo.flags |= CNT_BROWSER;
|
2013-01-03 04:22:38 +04:00
|
|
|
|
2013-01-11 05:12:30 +04:00
|
|
|
memset( &ctxinfo.ccdata, sizeof(struct contextual_content), 0 );
|
2013-01-03 04:22:38 +04:00
|
|
|
|
2013-01-11 05:12:30 +04:00
|
|
|
gui_window_get_scroll(gw, &sx, &sy);
|
2013-01-03 04:22:38 +04:00
|
|
|
|
2013-01-11 05:12:30 +04:00
|
|
|
browser_window_get_contextual_content( gw->browser->bw, mx+sx, my+sy,
|
|
|
|
(struct contextual_content*)&ctxinfo.ccdata);
|
2013-01-03 04:22:38 +04:00
|
|
|
|
2013-01-11 05:12:30 +04:00
|
|
|
if( ctxinfo.ccdata.link_url ){
|
|
|
|
ctxinfo.flags |= CNT_HREF;
|
2011-10-03 20:45:54 +04:00
|
|
|
}
|
2013-01-11 05:12:30 +04:00
|
|
|
if( ctxinfo.ccdata.object) {
|
|
|
|
if( content_get_type(ctxinfo.ccdata.object) == CONTENT_IMAGE ){
|
|
|
|
ctxinfo.flags |= CNT_IMG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( ctxinfo.ccdata.form_features == CTX_FORM_TEXT )
|
|
|
|
ctxinfo.flags |= (CNT_INTERACTIVE | CNT_SELECTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(&ctxinfo);
|
|
|
|
|
2011-10-03 20:45:54 +04:00
|
|
|
|
2013-01-11 05:12:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: do not open popup for gui_window, but for a rootwin?
|
2012-12-06 03:26:50 +04:00
|
|
|
void context_popup(struct gui_window * gw, short x, short y)
|
2011-10-03 20:45:54 +04:00
|
|
|
{
|
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;
|
2012-08-27 22:05:35 +04:00
|
|
|
char * editor, *lastslash;
|
2013-01-07 23:04:44 +04:00
|
|
|
char cmdline[PATH_MAX];
|
|
|
|
MENU pop_menu, me_data;
|
2011-10-03 20:45:54 +04:00
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
pop = gemtk_obj_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++ ){
|
2013-01-07 23:04:44 +04:00
|
|
|
SET_BIT(pop[ choice ].ob_state, OS_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 ){
|
2013-01-07 23:04:44 +04:00
|
|
|
SET_BIT(pop[ POP_CTX_PASTE_SEL ].ob_state, OS_DISABLED, 0);
|
2011-10-14 00:39:39 +04:00
|
|
|
}
|
2011-10-03 20:45:54 +04:00
|
|
|
|
|
|
|
if( (ctx->flags & CNT_BROWSER) ){
|
2013-01-07 23:04:44 +04:00
|
|
|
SET_BIT(pop[ POP_CTX_SELECT_ALL ].ob_state, OS_DISABLED, 0);
|
|
|
|
SET_BIT(pop[ POP_CTX_COPY_SEL ].ob_state, OS_DISABLED, 0);
|
|
|
|
SET_BIT(pop[ POP_CTX_VIEW_SOURCE ].ob_state, OS_DISABLED, 0);
|
2013-01-11 05:12:30 +04:00
|
|
|
}
|
2011-10-14 00:39:39 +04:00
|
|
|
|
|
|
|
if( ctx->flags & CNT_HREF ){
|
2013-01-07 23:04:44 +04:00
|
|
|
SET_BIT(pop[ POP_CTX_COPY_LINK ].ob_state, OS_DISABLED, 0);
|
|
|
|
SET_BIT(pop[ POP_CTX_OPEN_NEW ].ob_state, OS_DISABLED, 0);
|
|
|
|
SET_BIT(pop[ POP_CTX_SAVE_LINK_AS ].ob_state, OS_DISABLED, 0);
|
2012-06-05 01:53:06 +04:00
|
|
|
}
|
2011-10-14 00:39:39 +04:00
|
|
|
|
|
|
|
if( ctx->flags & CNT_IMG ){
|
2013-01-07 23:04:44 +04:00
|
|
|
SET_BIT(pop[ POP_CTX_SAVE_AS ].ob_state, OS_DISABLED, 0);
|
|
|
|
SET_BIT(pop[ POP_CTX_COPY_URL ].ob_state, OS_DISABLED, 0);
|
|
|
|
SET_BIT(pop[ POP_CTX_OPEN_NEW ].ob_state, OS_DISABLED, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// point mn_tree tree to states popup:
|
2013-01-22 05:33:27 +04:00
|
|
|
pop_menu.mn_tree = gemtk_obj_get_tree(POP_CTX);
|
2013-01-07 23:04:44 +04:00
|
|
|
pop_menu.mn_menu = 0;
|
|
|
|
pop_menu.mn_item = POP_CTX_CUT_SEL;
|
2013-01-08 02:45:02 +04:00
|
|
|
pop_menu.mn_scroll = SCROLL_NO;
|
2013-01-07 23:04:44 +04:00
|
|
|
pop_menu.mn_keystate = 0;
|
|
|
|
|
|
|
|
menu_popup(&pop_menu, x, y, &me_data);
|
|
|
|
choice = me_data.mn_item;
|
|
|
|
|
2011-10-14 00:39:39 +04:00
|
|
|
switch( choice ){
|
2011-10-03 20:45:54 +04:00
|
|
|
case POP_CTX_COPY_SEL:
|
2013-01-10 01:59:22 +04:00
|
|
|
browser_window_key_press(gw->browser->bw, KEY_COPY_SELECTION);
|
2011-10-03 20:45:54 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case POP_CTX_CUT_SEL:
|
2013-01-10 01:59:22 +04:00
|
|
|
browser_window_key_press(gw->browser->bw, KEY_CUT_SELECTION);
|
2011-10-03 20:45:54 +04:00
|
|
|
break;
|
|
|
|
|
2013-01-09 04:12:30 +04:00
|
|
|
case POP_CTX_PASTE_SEL:
|
|
|
|
browser_window_key_press(gw->browser->bw, KEY_PASTE);
|
2011-10-03 20:45:54 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case POP_CTX_SELECT_ALL:
|
2013-01-10 01:59:22 +04:00
|
|
|
browser_window_key_press(gw->browser->bw, KEY_SELECT_ALL);
|
2011-10-03 20:45:54 +04:00
|
|
|
break;
|
|
|
|
|
2012-07-14 00:19:04 +04:00
|
|
|
case POP_CTX_SAVE_AS:
|
2013-01-10 01:59:22 +04:00
|
|
|
if (ctx->ccdata.object != NULL) {
|
2012-06-05 01:53:06 +04:00
|
|
|
if( hlcache_handle_get_url(ctx->ccdata.object) != NULL ) {
|
2013-02-14 19:09:28 +04:00
|
|
|
browser_window_navigate(
|
2012-06-05 01:53:06 +04:00
|
|
|
gw->browser->bw,
|
2013-02-14 19:09:28 +04:00
|
|
|
hlcache_handle_get_url(ctx->ccdata.object),
|
|
|
|
hlcache_handle_get_url(gw->browser->bw->current_content),
|
2013-02-18 15:51:42 +04:00
|
|
|
BROWSER_WINDOW_DOWNLOAD |
|
|
|
|
BROWSER_WINDOW_VERIFIABLE,
|
2013-02-14 19:09:28 +04:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
);
|
2012-07-14 00:19:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case POP_CTX_SAVE_LINK_AS:
|
2013-01-10 01:59:22 +04:00
|
|
|
if (ctx->ccdata.link_url != NULL) {
|
2013-02-14 19:09:28 +04:00
|
|
|
nsurl *url;
|
2013-02-14 22:21:11 +04:00
|
|
|
nserror error;
|
|
|
|
|
|
|
|
error = nsurl_create(ctx->ccdata.link_url, &url);
|
|
|
|
if (error == NSERROR_OK) {
|
|
|
|
error = browser_window_navigate(
|
2013-02-14 19:09:28 +04:00
|
|
|
gw->browser->bw,
|
|
|
|
url,
|
|
|
|
hlcache_handle_get_url(gw->browser->bw->current_content),
|
2013-02-18 15:51:42 +04:00
|
|
|
BROWSER_WINDOW_DOWNLOAD |
|
|
|
|
BROWSER_WINDOW_VERIFIABLE,
|
2013-02-14 19:09:28 +04:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
2013-02-14 22:21:11 +04:00
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
warn_user(messages_get_errorcode(error), 0);
|
|
|
|
}
|
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:
|
2013-01-10 01:59:22 +04:00
|
|
|
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 ){
|
2012-12-31 06:37:43 +04:00
|
|
|
scrap_txt_write((char*)nsurl_access(
|
|
|
|
hlcache_handle_get_url(ctx->ccdata.object)));
|
2011-10-03 20:45:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POP_CTX_COPY_LINK:
|
2013-01-10 01:59:22 +04:00
|
|
|
if ((ctx->flags & CNT_HREF) && ctx->ccdata.link_url != NULL) {
|
2012-12-31 06:37:43 +04:00
|
|
|
scrap_txt_write((char*)ctx->ccdata.link_url);
|
2011-10-03 20:45:54 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POP_CTX_OPEN_NEW:
|
2013-01-10 01:59:22 +04:00
|
|
|
if ((ctx->flags & CNT_HREF) && ctx->ccdata.link_url) {
|
2013-02-14 22:21:11 +04:00
|
|
|
nsurl *url;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
error = nsurl_create(ctx->ccdata.link_url, &url);
|
|
|
|
if (error == NSERROR_OK) {
|
2013-02-18 15:51:42 +04:00
|
|
|
error = browser_window_create(BROWSER_WINDOW_VERIFIABLE |
|
|
|
|
BROWSER_WINDOW_HISTORY,
|
2013-02-14 22:21:11 +04:00
|
|
|
url,
|
|
|
|
hlcache_handle_get_url(gw->browser->bw->current_content),
|
2013-02-18 16:24:49 +04:00
|
|
|
gw->browser->bw,
|
|
|
|
NULL
|
2013-02-14 22:21:11 +04:00
|
|
|
);
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
warn_user(messages_get_errorcode(error), 0);
|
|
|
|
}
|
2011-10-03 20:45:54 +04:00
|
|
|
}
|
|
|
|
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) {
|
2012-08-21 01:25:02 +04:00
|
|
|
data = content_get_source_data(gw->browser->bw->current_content,
|
2012-07-15 00:15:05 +04:00
|
|
|
&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);
|
2012-08-27 22:05:35 +04:00
|
|
|
fclose(fp_tmpfile );
|
2013-01-07 23:04:44 +04:00
|
|
|
/*
|
2012-08-27 22:05:35 +04:00
|
|
|
lastslash = strrchr(editor, '/');
|
|
|
|
if (lastslash == NULL)
|
|
|
|
lastslash = strrchr(editor, '\\');
|
|
|
|
if (lastslash == NULL)
|
|
|
|
lastslash = editor;
|
|
|
|
else
|
|
|
|
lastslash++;
|
2013-01-07 23:04:44 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
if(strlen(tempfile)<=125){
|
|
|
|
shel_write(1,1,0,editor,tempfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*if(is_process_running(lastslash)){
|
|
|
|
if(strlen(tempfile)<=125){
|
|
|
|
shel_write(1,1,0,editor,tempfile);
|
|
|
|
}
|
2012-08-27 22:05:35 +04:00
|
|
|
} else {
|
2013-01-07 23:04:44 +04:00
|
|
|
// check for max length of simple commandline param:
|
2012-08-27 22:05:35 +04:00
|
|
|
if(strlen(tempfile)<=125){
|
|
|
|
sprintf(cmdline, "%c%s", (char)strlen(tempfile),
|
|
|
|
tempfile);
|
|
|
|
Pexec(100, editor, cmdline, NULL);
|
|
|
|
}
|
2013-01-07 23:04:44 +04:00
|
|
|
}
|
|
|
|
*/
|
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
|
|
|
}
|