2014-05-31 11:42:08 +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/>.
|
|
|
|
*/
|
2012-04-11 03:10:49 +04:00
|
|
|
|
|
|
|
#include <assert.h>
|
2014-05-31 11:42:08 +04:00
|
|
|
#include <stdlib.h>
|
2012-04-11 03:10:49 +04:00
|
|
|
#include <stdio.h>
|
2014-05-31 11:42:08 +04:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
2013-01-07 23:04:44 +04:00
|
|
|
|
2014-05-31 11:42:08 +04:00
|
|
|
#include <sys/types.h>
|
2013-01-07 23:04:44 +04:00
|
|
|
#include <mint/osbind.h>
|
2012-04-11 03:10:49 +04:00
|
|
|
|
2016-04-19 17:56:57 +03:00
|
|
|
#include "utils/dirent.h"
|
2012-04-11 03:10:49 +04:00
|
|
|
#include "content/content.h"
|
2014-05-31 11:42:08 +04:00
|
|
|
#include "content/hlcache.h"
|
|
|
|
#include "desktop/cookie_manager.h"
|
2012-01-12 00:35:14 +04:00
|
|
|
#include "desktop/mouse.h"
|
2012-04-11 03:10:49 +04:00
|
|
|
#include "desktop/tree.h"
|
2014-05-31 11:42:08 +04:00
|
|
|
#include "utils/nsoption.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/log.h"
|
2014-09-13 16:43:10 +04:00
|
|
|
#include "utils/file.h"
|
2013-01-07 23:04:44 +04:00
|
|
|
#include "content/fetch.h"
|
2014-05-31 11:42:08 +04:00
|
|
|
|
|
|
|
#include "atari/gui.h"
|
|
|
|
#include "atari/toolbar.h"
|
|
|
|
|
2011-11-23 23:56:20 +04:00
|
|
|
#include "atari/misc.h"
|
2011-11-30 01:31:31 +04:00
|
|
|
#include "atari/encoding.h"
|
2012-11-19 02:22:43 +04:00
|
|
|
#include "atari/gemtk/gemtk.h"
|
2014-05-31 11:42:08 +04:00
|
|
|
#include "cflib.h"
|
|
|
|
|
|
|
|
extern void * h_gem_rsrc;
|
2012-08-27 22:05:35 +04:00
|
|
|
|
|
|
|
struct is_process_running_callback_data {
|
|
|
|
const char * fname;
|
|
|
|
bool found;
|
|
|
|
};
|
2014-05-31 11:42:08 +04:00
|
|
|
|
2016-04-26 01:11:55 +03:00
|
|
|
/* exported function documented in atari/misc/h */
|
|
|
|
nserror atari_warn_user(const char *warning, const char *detail)
|
2014-05-31 11:42:08 +04:00
|
|
|
{
|
|
|
|
size_t len = 1 + ((warning != NULL) ? strlen(messages_get(warning)) :
|
|
|
|
0) + ((detail != 0) ? strlen(detail) : 0);
|
|
|
|
char message[len];
|
|
|
|
snprintf(message, len, messages_get(warning), detail);
|
2012-11-13 00:23:39 +04:00
|
|
|
|
|
|
|
printf("%s\n", message);
|
2014-05-31 11:42:08 +04:00
|
|
|
gemtk_msg_box_show(GEMTK_MSG_BOX_ALERT, message);
|
2016-04-26 01:11:55 +03:00
|
|
|
|
|
|
|
return NSERROR_OK;
|
2014-05-31 11:42:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void die(const char *error)
|
2012-11-13 00:23:39 +04:00
|
|
|
{
|
2014-05-31 11:42:08 +04:00
|
|
|
printf("%s\n", error);
|
2013-01-22 05:33:27 +04:00
|
|
|
gemtk_msg_box_show(GEMTK_MSG_BOX_ALERT, error);
|
2014-05-31 11:42:08 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct gui_window * find_guiwin_by_aes_handle(short handle){
|
|
|
|
|
|
|
|
struct gui_window * gw;
|
|
|
|
gw = window_list;
|
|
|
|
|
|
|
|
if( handle == 0 ){
|
2011-12-16 03:04:31 +04:00
|
|
|
return( NULL );
|
|
|
|
}
|
2012-11-19 02:22:43 +04:00
|
|
|
|
2014-05-31 11:42:08 +04:00
|
|
|
while(gw != NULL) {
|
2013-09-16 04:04:29 +04:00
|
|
|
if(gw->root->win != NULL
|
2014-05-31 11:42:08 +04:00
|
|
|
&& gemtk_wm_get_handle(gw->root->win) == handle) {
|
|
|
|
return(gw);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gw = gw->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return( NULL );
|
2011-12-16 03:04:31 +04:00
|
|
|
}
|
2014-05-31 11:42:08 +04:00
|
|
|
|
|
|
|
|
2012-08-27 22:05:35 +04:00
|
|
|
static int scan_process_list(scan_process_callback cb, void *data)
|
|
|
|
{
|
|
|
|
int pid, count = 0;
|
|
|
|
DIR *dir;
|
|
|
|
char*dirname;
|
|
|
|
struct dirent *de;
|
|
|
|
|
|
|
|
if (( dir = opendir("U:/kern")) == NULL)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
while ((de = readdir( dir)) != NULL) {
|
|
|
|
dirname = de->d_name;
|
|
|
|
|
|
|
|
if( dirname[0] != '1' && dirname[0] != '2' && dirname[0] != '3' && dirname[0] != '4' && dirname[0] != '5'
|
|
|
|
&& dirname[0] != '6' && dirname[0] != '7' && dirname[0] != '8' && dirname[0] != '9')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
if (cb != NULL) {
|
|
|
|
/* when callback returns negative value, we stop scanning: */
|
|
|
|
pid = atoi(dirname);
|
|
|
|
if (cb(pid, data)<0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
|
|
|
|
return(count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int proc_running_callback(int pid, void * arg)
|
|
|
|
{
|
|
|
|
char buf[PATH_MAX], fnamepath[256];
|
|
|
|
FILE *fp;
|
|
|
|
int nread;
|
|
|
|
struct is_process_running_callback_data *data;
|
|
|
|
|
|
|
|
data = (struct is_process_running_callback_data *)arg;
|
|
|
|
|
|
|
|
sprintf(fnamepath, "U:\\kern\\%d\\fname", pid);
|
2012-08-27 22:39:14 +04:00
|
|
|
printf("checking: %s\n", fnamepath);
|
2012-08-27 22:05:35 +04:00
|
|
|
|
|
|
|
fp = fopen(fnamepath, "r");
|
|
|
|
if(!fp)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
nread = fread(buf, 1, PATH_MAX-1, fp);
|
|
|
|
fclose(fp);
|
2012-08-27 22:39:14 +04:00
|
|
|
nread = MIN(PATH_MAX-1, nread);
|
2012-08-27 22:05:35 +04:00
|
|
|
|
|
|
|
if (nread > 0) {
|
|
|
|
buf[nread] = 0;
|
|
|
|
|
|
|
|
char *lastslash = strrchr(buf, '/');
|
|
|
|
|
|
|
|
if(lastslash == NULL)
|
|
|
|
lastslash = strrchr(buf, '\\');
|
|
|
|
|
|
|
|
if(lastslash==NULL)
|
|
|
|
lastslash = buf;
|
|
|
|
else
|
|
|
|
lastslash++;
|
|
|
|
|
|
|
|
if(strcasecmp(lastslash, data->fname)==0){
|
2012-08-27 22:39:14 +04:00
|
|
|
/* found process, check status: */
|
|
|
|
sprintf(fnamepath, "U:\\kern\\%d\\status", pid);
|
|
|
|
fp = fopen(fnamepath, "r");
|
|
|
|
if (fp) {
|
|
|
|
nread = fread(buf, 1, PATH_MAX-1, fp);
|
|
|
|
fclose(fp);
|
|
|
|
if (nread>0) {
|
|
|
|
nread = MIN(PATH_MAX-1,nread);
|
|
|
|
}
|
|
|
|
buf[nread] = 0;
|
|
|
|
if (strstr(buf, "zombie")==NULL) {
|
|
|
|
data->found = true;
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-27 22:05:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_process_running(const char * name)
|
|
|
|
{
|
|
|
|
struct is_process_running_callback_data data = {name, false};
|
|
|
|
|
|
|
|
scan_process_list(proc_running_callback, &data);
|
|
|
|
|
|
|
|
return( (data.found==1) ? true : false );
|
2014-05-31 11:42:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void gem_set_cursor( MFORM_EX * cursor )
|
|
|
|
{
|
|
|
|
static unsigned char flags = 255;
|
|
|
|
static int number = 255;
|
|
|
|
if( flags == cursor->flags && number == cursor->number )
|
|
|
|
return;
|
2013-01-07 23:04:44 +04:00
|
|
|
if( cursor->flags & MFORM_EX_FLAG_USERFORM ) {
|
2014-05-31 11:42:08 +04:00
|
|
|
gemtk_obj_mouse_sprite(cursor->tree, cursor->number);
|
|
|
|
} else {
|
|
|
|
graf_mouse(cursor->number, NULL );
|
|
|
|
}
|
|
|
|
number = cursor->number;
|
|
|
|
flags = cursor->flags;
|
2011-11-23 23:56:20 +04:00
|
|
|
}
|
|
|
|
|
2016-04-30 13:34:45 +03:00
|
|
|
|
|
|
|
/* exported interface documented in atari/misc.h */
|
2011-11-23 23:56:20 +04:00
|
|
|
long nkc_to_input_key(short nkc, long * ucs4_out)
|
|
|
|
{
|
2014-05-31 11:42:08 +04:00
|
|
|
unsigned char ascii = (nkc & 0xFF);
|
2011-11-23 23:56:20 +04:00
|
|
|
long ik = 0;
|
2013-04-11 02:49:02 +04:00
|
|
|
|
|
|
|
// initialize result:
|
2011-11-23 23:56:20 +04:00
|
|
|
*ucs4_out = 0;
|
|
|
|
|
2013-04-11 02:49:02 +04:00
|
|
|
// sanitize input key:
|
|
|
|
nkc = (nkc & (NKF_CTRL|NKF_SHIFT|0xFF));
|
|
|
|
|
2011-11-23 23:56:20 +04:00
|
|
|
/* shift + cntrl key: */
|
|
|
|
if( ((nkc & NKF_CTRL) == NKF_CTRL) && ((nkc & (NKF_SHIFT))!=0) ) {
|
|
|
|
|
|
|
|
}
|
2014-05-31 11:42:08 +04:00
|
|
|
/* cntrl key only: */
|
|
|
|
else if( (nkc & NKF_CTRL) == NKF_CTRL ) {
|
|
|
|
switch ( ascii ) {
|
|
|
|
case 'A':
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_SELECT_ALL;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C':
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_COPY_SELECTION;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X':
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_CUT_SELECTION;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'V':
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_PASTE;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-11-23 23:56:20 +04:00
|
|
|
}
|
2014-05-31 11:42:08 +04:00
|
|
|
/* shift key only: */
|
2011-11-23 23:56:20 +04:00
|
|
|
else if( (nkc & NKF_SHIFT) != 0 ) {
|
2014-05-31 11:42:08 +04:00
|
|
|
switch( ascii ) {
|
|
|
|
case NK_TAB:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_SHIFT_TAB;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_LEFT:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_LINE_START;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_RIGHT:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_LINE_END;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_UP:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_PAGE_UP;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_DOWN:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_PAGE_DOWN;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-11-23 23:56:20 +04:00
|
|
|
}
|
2014-05-31 11:42:08 +04:00
|
|
|
/* No modifier keys: */
|
|
|
|
else {
|
2011-11-30 01:31:31 +04:00
|
|
|
switch( ascii ) {
|
|
|
|
|
|
|
|
case NK_INS:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_PASTE;
|
2011-11-30 01:31:31 +04:00
|
|
|
break;
|
2014-05-31 11:42:08 +04:00
|
|
|
|
|
|
|
case NK_BS:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_DELETE_LEFT;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_DEL:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_DELETE_RIGHT;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_TAB:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_TAB;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case NK_ENTER:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_NL;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_RET:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_CR;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_ESC:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_ESCAPE;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_CLRHOME:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_TEXT_START;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_RIGHT:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_RIGHT;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_LEFT:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_LEFT;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_UP:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_UP;
|
2013-10-26 17:39:05 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_UNDO:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_UNDO;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_DOWN:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_DOWN;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_M_PGUP:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_PAGE_UP;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_M_PGDOWN:
|
2015-03-27 12:36:19 +03:00
|
|
|
ik = NS_KEY_PAGE_DOWN;
|
2014-05-31 11:42:08 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-11-23 23:56:20 +04:00
|
|
|
}
|
2014-05-31 11:42:08 +04:00
|
|
|
|
|
|
|
if( ik == 0 && ( (nkc & NKF_CTRL)==0) ) {
|
2011-11-23 23:56:20 +04:00
|
|
|
if (ascii >= 9 ) {
|
|
|
|
*ucs4_out = atari_to_ucs4(ascii);
|
2014-05-31 11:42:08 +04:00
|
|
|
}
|
|
|
|
}
|
2011-11-23 23:56:20 +04:00
|
|
|
return ( ik );
|
|
|
|
}
|
2011-12-07 01:06:41 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show default file selector
|
|
|
|
*
|
|
|
|
* \param title The selector title.
|
|
|
|
* \param name Default file name
|
|
|
|
* \return a static char pointer or null if the user aborted the selection.
|
|
|
|
*/
|
2013-12-21 05:07:13 +04:00
|
|
|
const char * file_select(const char * title, const char * name) {
|
2013-01-07 23:04:44 +04:00
|
|
|
|
2011-12-07 01:06:41 +04:00
|
|
|
static char path[PATH_MAX]=""; // First usage : current directory
|
|
|
|
static char fullname[PATH_MAX]="";
|
|
|
|
char tmpname[255];
|
|
|
|
char * use_title = (char*)title;
|
|
|
|
|
|
|
|
if( strlen(name)>254)
|
|
|
|
return( NULL );
|
|
|
|
|
2013-01-07 23:04:44 +04:00
|
|
|
strcpy(tmpname, name);
|
2011-12-07 01:06:41 +04:00
|
|
|
|
|
|
|
if( use_title == NULL ){
|
|
|
|
use_title = (char*)"";
|
|
|
|
}
|
|
|
|
|
2013-01-07 23:04:44 +04:00
|
|
|
if (select_file(path, tmpname, (char*)"*", use_title, NULL)) {
|
2012-12-21 03:56:50 +04:00
|
|
|
snprintf(fullname, PATH_MAX, "%s%s", path, tmpname);
|
2013-01-07 23:04:44 +04:00
|
|
|
return((const char*)&fullname);
|
2011-12-07 01:06:41 +04:00
|
|
|
}
|
2013-01-07 23:04:44 +04:00
|
|
|
|
2011-12-07 01:06:41 +04:00
|
|
|
return( NULL );
|
|
|
|
}
|
2014-05-31 11:42:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
void dbg_grect(const char * str, GRECT * r)
|
|
|
|
{
|
|
|
|
printf("%s: x: %d, y: %d, w: %d, h: %d (x2: %d, y2: %d)\n", str,
|
|
|
|
r->g_x, r->g_y, r->g_w, r->g_h, r->g_x + r->g_w, r->g_y + r->g_h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dbg_pxy(const char * str, short * pxy )
|
|
|
|
{
|
|
|
|
printf("%s: x: %d, y: %d, w: %d, h: %d\n", str,
|
|
|
|
pxy[0], pxy[1], pxy[2], pxy[3] );
|
2012-03-22 01:19:59 +04:00
|
|
|
}
|
|
|
|
|
2014-05-31 11:42:08 +04:00
|
|
|
void dbg_rect(const char * str, int * pxy)
|
|
|
|
{
|
|
|
|
printf("%s: x0: %d, y0: %d, x1: %d, y1: %d (w: %d, h: %d)\n", str,
|
2013-01-16 06:21:35 +04:00
|
|
|
pxy[0], pxy[1], pxy[2], pxy[3],
|
|
|
|
pxy[2] - pxy[0],
|
2014-05-31 11:42:08 +04:00
|
|
|
pxy[3] - pxy[1] );
|
|
|
|
}
|
|
|
|
|