2014-05-19 20:00:53 +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/>.
|
|
|
|
*/
|
|
|
|
|
2014-10-17 00:23:51 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
2016-04-20 23:07:47 +03:00
|
|
|
#include "utils/nsoption.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "utils/nsurl.h"
|
2016-05-30 19:32:57 +03:00
|
|
|
#include "netsurf/browser_window.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "netsurf/content.h"
|
2016-07-01 16:27:04 +03:00
|
|
|
#include "netsurf/keypress.h"
|
2014-05-19 20:00:53 +04:00
|
|
|
|
|
|
|
#include "atari/gui.h"
|
2016-04-30 13:34:45 +03:00
|
|
|
#include "atari/misc.h"
|
2014-05-19 20:00:53 +04:00
|
|
|
#include "atari/rootwin.h"
|
|
|
|
#include "atari/clipboard.h"
|
2016-04-20 23:07:47 +03:00
|
|
|
#include "atari/gemtk/gemtk.h"
|
2014-05-19 20:00:53 +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
|
|
|
|
|
2014-01-13 05:08:15 +04:00
|
|
|
bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy);
|
2014-05-19 20:00:53 +04:00
|
|
|
|
|
|
|
struct s_context_info {
|
|
|
|
unsigned long flags;
|
2014-11-02 18:46:42 +03:00
|
|
|
struct browser_window_features ccdata;
|
2014-05-19 20:00:53 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct s_context_info ctxinfo;
|
|
|
|
|
|
|
|
static struct s_context_info * get_context_info( struct gui_window * gw, short mx, short my )
|
|
|
|
{
|
2016-06-06 10:59:23 +03:00
|
|
|
struct hlcache_handle *h;
|
2014-05-19 20:00:53 +04:00
|
|
|
GRECT area;
|
2013-01-03 04:22:38 +04:00
|
|
|
struct browser_window * bw = gw->browser->bw;
|
2014-05-19 20:00:53 +04:00
|
|
|
int sx, sy;
|
|
|
|
|
2014-10-25 19:04:43 +04:00
|
|
|
h = browser_window_get_content(bw);
|
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)) {
|
|
|
|
|
2014-05-19 20:00:53 +04:00
|
|
|
mx -= area.g_x;
|
2013-01-11 05:12:30 +04:00
|
|
|
my -= area.g_y;
|
|
|
|
|
2014-10-25 19:04:43 +04:00
|
|
|
if (browser_window_has_content(bw) == false ||
|
|
|
|
content_get_type(h) != CONTENT_HTML){
|
2014-05-19 20:00:53 +04:00
|
|
|
return(&ctxinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxinfo.flags |= CNT_BROWSER;
|
2013-01-03 04:22:38 +04:00
|
|
|
|
2013-01-11 05:12:30 +04:00
|
|
|
gui_window_get_scroll(gw, &sx, &sy);
|
2014-05-19 20:00:53 +04:00
|
|
|
|
2014-11-02 18:46:42 +03:00
|
|
|
browser_window_get_features( gw->browser->bw, mx+sx, my+sy,
|
|
|
|
&ctxinfo.ccdata);
|
2014-05-19 20:00:53 +04:00
|
|
|
|
2014-11-02 18:46:42 +03:00
|
|
|
if( ctxinfo.ccdata.link ){
|
2014-05-19 20:00:53 +04:00
|
|
|
ctxinfo.flags |= CNT_HREF;
|
|
|
|
}
|
|
|
|
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 )
|
2013-01-11 05:12:30 +04:00
|
|
|
ctxinfo.flags |= (CNT_INTERACTIVE | CNT_SELECTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(&ctxinfo);
|
2014-05-19 20:00:53 +04:00
|
|
|
|
|
|
|
|
2013-12-30 01:23:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
2013-12-30 02:15:53 +04:00
|
|
|
* Generates an unique filename for temp. files
|
|
|
|
* The generated filename includes the path.
|
|
|
|
* If TMPDIR environmenrt vairable is set, this will be used as path,
|
|
|
|
* otherwise U:\tmp\
|
2013-12-30 01:23:51 +04:00
|
|
|
* \param prefix
|
|
|
|
* \param sufffix
|
|
|
|
* \return pointer to static buffer owned by get_tmpfilename()
|
|
|
|
*/
|
|
|
|
static char * get_tmpfilename(const char * prefix, const char * suffix)
|
|
|
|
{
|
|
|
|
int i=0;
|
|
|
|
static char tmpfilename[PATH_MAX];
|
|
|
|
char * tmpdir;
|
|
|
|
const char * tmp_path_suffix = "";
|
|
|
|
|
|
|
|
// TODO: make function public?
|
|
|
|
tmpdir = getenv("TMPDIR");
|
|
|
|
if(tmpdir == NULL){
|
|
|
|
tmpdir = (char*)"u:\\tmp\\";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tmpdir[strlen(tmpdir)-1] != '\\'){
|
|
|
|
tmp_path_suffix = "\\";
|
|
|
|
}
|
|
|
|
|
|
|
|
do{
|
|
|
|
/* generate a new filename: */
|
|
|
|
snprintf(tmpfilename, PATH_MAX, "%s%s%s%d%s", tmpdir,
|
|
|
|
tmp_path_suffix, prefix, i++, suffix);
|
|
|
|
/* check with cflib: */
|
|
|
|
} while(file_exists(tmpfilename));
|
|
|
|
|
|
|
|
return(tmpfilename);
|
2014-05-19 20:00:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: do not open popup for gui_window, but for a rootwin?
|
|
|
|
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_SAVE_LINK_AS
|
|
|
|
|
|
|
|
OBJECT * pop;
|
|
|
|
int choice;
|
|
|
|
struct s_context_info * ctx;
|
|
|
|
unsigned long size;
|
|
|
|
const char * data;
|
|
|
|
FILE * fp_tmpfile;
|
2013-11-24 05:26:52 +04:00
|
|
|
char cmdline[128];
|
2013-11-25 01:02:40 +04:00
|
|
|
/* skip first byte, which must hold length of commandline: */
|
2014-05-19 20:00:53 +04:00
|
|
|
char * tempfile = &cmdline[1];
|
2014-05-19 20:01:40 +04:00
|
|
|
char * editor;
|
2014-05-19 20:00:53 +04:00
|
|
|
MENU pop_menu, me_data;
|
|
|
|
|
|
|
|
pop = gemtk_obj_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, OS_DISABLED, 1);
|
2013-01-11 05:12:30 +04:00
|
|
|
}
|
2014-05-19 20:00:53 +04:00
|
|
|
|
|
|
|
if( ctx->flags & CNT_INTERACTIVE ){
|
|
|
|
SET_BIT(pop[ POP_CTX_PASTE_SEL ].ob_state, OS_DISABLED, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (ctx->flags & CNT_BROWSER) ){
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ctx->flags & CNT_HREF ){
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ctx->flags & CNT_IMG ){
|
|
|
|
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);
|
2013-01-07 23:04:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2014-05-19 20:00:53 +04:00
|
|
|
pop_menu.mn_keystate = 0;
|
2013-01-07 23:04:44 +04:00
|
|
|
|
|
|
|
menu_popup(&pop_menu, x, y, &me_data);
|
2014-05-19 20:00:53 +04:00
|
|
|
choice = me_data.mn_item;
|
|
|
|
|
|
|
|
switch( choice ){
|
|
|
|
case POP_CTX_COPY_SEL:
|
2015-03-27 12:36:19 +03:00
|
|
|
browser_window_key_press(gw->browser->bw, NS_KEY_COPY_SELECTION);
|
2014-05-19 20:00:53 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case POP_CTX_CUT_SEL:
|
2015-03-27 12:36:19 +03:00
|
|
|
browser_window_key_press(gw->browser->bw, NS_KEY_CUT_SELECTION);
|
2014-05-19 20:00:53 +04:00
|
|
|
break;
|
|
|
|
|
2013-01-09 04:12:30 +04:00
|
|
|
case POP_CTX_PASTE_SEL:
|
2015-03-27 12:36:19 +03:00
|
|
|
browser_window_key_press(gw->browser->bw, NS_KEY_PASTE);
|
2014-05-19 20:00:53 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case POP_CTX_SELECT_ALL:
|
2015-03-27 12:36:19 +03:00
|
|
|
browser_window_key_press(gw->browser->bw, NS_KEY_SELECT_ALL);
|
2014-05-19 20:00:53 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case POP_CTX_SAVE_AS:
|
|
|
|
if (ctx->ccdata.object != NULL) {
|
|
|
|
if( hlcache_handle_get_url(ctx->ccdata.object) != NULL ) {
|
|
|
|
browser_window_navigate(
|
|
|
|
gw->browser->bw,
|
|
|
|
hlcache_handle_get_url(ctx->ccdata.object),
|
2014-10-25 19:04:43 +04:00
|
|
|
browser_window_get_url(gw->browser->bw),
|
2014-05-19 20:00:53 +04:00
|
|
|
BW_NAVIGATE_DOWNLOAD,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case POP_CTX_SAVE_LINK_AS:
|
2014-11-02 18:46:42 +03:00
|
|
|
if (ctx->ccdata.link != NULL) {
|
2013-02-14 22:21:11 +04:00
|
|
|
nserror error;
|
|
|
|
|
2014-11-02 18:46:42 +03:00
|
|
|
error = browser_window_navigate(
|
|
|
|
gw->browser->bw,
|
|
|
|
ctx->ccdata.link,
|
|
|
|
browser_window_get_url(gw->browser->bw),
|
|
|
|
BW_NAVIGATE_DOWNLOAD,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
2013-02-14 22:21:11 +04:00
|
|
|
if (error != NSERROR_OK) {
|
2016-04-30 13:34:45 +03:00
|
|
|
atari_warn_user(messages_get_errorcode(error), 0);
|
2013-02-14 22:21:11 +04:00
|
|
|
}
|
2014-05-19 20:00:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POP_CTX_COPY_URL:
|
|
|
|
if ((ctx->flags & CNT_IMG) && (ctx->ccdata.object != NULL)) {
|
|
|
|
if( hlcache_handle_get_url(ctx->ccdata.object) != NULL ){
|
2012-12-31 06:37:43 +04:00
|
|
|
scrap_txt_write((char*)nsurl_access(
|
2014-05-19 20:00:53 +04:00
|
|
|
hlcache_handle_get_url(ctx->ccdata.object)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POP_CTX_COPY_LINK:
|
2014-11-02 18:46:42 +03:00
|
|
|
if ((ctx->flags & CNT_HREF) &&
|
|
|
|
(ctx->ccdata.link != NULL)) {
|
|
|
|
scrap_txt_write((char*)nsurl_access(ctx->ccdata.link));
|
2014-05-19 20:00:53 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POP_CTX_OPEN_NEW:
|
2014-11-02 18:46:42 +03:00
|
|
|
if ((ctx->flags & CNT_HREF) &&
|
|
|
|
(ctx->ccdata.link != NULL)) {
|
2013-02-14 22:21:11 +04:00
|
|
|
nserror error;
|
|
|
|
|
2014-11-02 18:46:42 +03:00
|
|
|
error = browser_window_create(
|
|
|
|
BW_CREATE_HISTORY | BW_CREATE_CLONE,
|
|
|
|
ctx->ccdata.link,
|
|
|
|
browser_window_get_url(gw->browser->bw),
|
|
|
|
gw->browser->bw,
|
|
|
|
NULL);
|
2013-02-14 22:21:11 +04:00
|
|
|
if (error != NSERROR_OK) {
|
2016-04-30 13:34:45 +03:00
|
|
|
atari_warn_user(messages_get_errorcode(error), 0);
|
2013-02-14 22:21:11 +04:00
|
|
|
}
|
2014-05-19 20:00:53 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POP_CTX_VIEW_SOURCE:
|
|
|
|
editor = nsoption_charp(atari_editor);
|
|
|
|
if (editor != NULL && strlen(editor)>0) {
|
2014-10-25 19:04:43 +04:00
|
|
|
data = content_get_source_data(browser_window_get_content(gw->browser->bw),
|
2013-12-30 01:23:51 +04:00
|
|
|
&size);
|
2013-11-24 05:26:52 +04:00
|
|
|
if (size > 0 && data != NULL){
|
2013-12-30 01:23:51 +04:00
|
|
|
snprintf(tempfile, 127, "%s", get_tmpfilename("ns-", ".html"));
|
|
|
|
/* the GEMDOS cmdline contains the length of the commandline
|
|
|
|
in the first byte: */
|
2013-11-24 05:26:52 +04:00
|
|
|
cmdline[0] = (unsigned char)strlen(tempfile);
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO,
|
|
|
|
"Creating temporay source file: %s\n",
|
|
|
|
tempfile);
|
2014-05-19 20:00:53 +04:00
|
|
|
fp_tmpfile = fopen(tempfile, "w");
|
|
|
|
if (fp_tmpfile != NULL){
|
|
|
|
fwrite(data, size, 1, fp_tmpfile);
|
2013-11-24 05:26:52 +04:00
|
|
|
fclose(fp_tmpfile);
|
2013-01-07 23:04:44 +04:00
|
|
|
|
2013-12-30 01:23:51 +04:00
|
|
|
// Send SH_WDRAW to notify files changed:
|
|
|
|
gemtk_send_msg(SH_WDRAW, 0, -1, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
// start application:
|
2013-01-07 23:04:44 +04:00
|
|
|
if(strlen(tempfile)<=125){
|
2013-11-24 05:26:52 +04:00
|
|
|
shel_write(1, 1, 1, editor, cmdline);
|
2013-01-07 23:04:44 +04:00
|
|
|
}
|
2014-05-19 20:00:53 +04:00
|
|
|
} else {
|
|
|
|
printf("Could not open temp file: %s!\n", tempfile );
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO,
|
|
|
|
"Invalid content!");
|
2014-05-19 20:00:53 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
form_alert(0, "[1][Set option \"atari_editor\".][OK]");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef POP_FIRST_ITEM
|
|
|
|
#undef POP_LAST_ITEM
|
|
|
|
|
|
|
|
}
|