netsurf/frontends/atari/gui.c

1244 lines
30 KiB
C
Raw Normal View History

2013-01-10 02:31:00 +04:00
/*
* Copyright 2010 <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-05-09 13:15:42 +04:00
/**
2014-10-12 13:35:56 +04:00
* \file
*
* Provides all the mandatory functions prefixed with gui_ for atari
2014-05-09 13:15:42 +04:00
*/
2013-01-10 02:31:00 +04:00
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/corestrings.h"
#include "netsurf/browser_window.h"
2016-05-30 13:31:35 +03:00
#include "netsurf/layout.h"
2016-05-30 13:01:40 +03:00
#include "netsurf/window.h"
2016-05-30 13:04:32 +03:00
#include "netsurf/clipboard.h"
2016-05-30 13:29:39 +03:00
#include "netsurf/fetch.h"
2016-05-30 13:23:32 +03:00
#include "netsurf/misc.h"
2016-05-30 13:51:10 +03:00
#include "netsurf/netsurf.h"
#include "netsurf/content.h"
#include "netsurf/cookie_db.h"
#include "netsurf/url_db.h"
2017-02-12 21:01:46 +03:00
#include "netsurf/plotters.h"
#include "content/backing_store.h"
2013-01-10 02:31:00 +04:00
#include "atari/gemtk/gemtk.h"
#include "atari/gui.h"
#include "atari/misc.h"
#include "atari/findfile.h"
#include "atari/schedule.h"
#include "atari/rootwin.h"
#include "atari/statusbar.h"
#include "atari/toolbar.h"
#include "atari/hotlist.h"
#include "atari/cookies.h"
#include "atari/certview.h"
2013-01-10 02:31:00 +04:00
#include "atari/history.h"
#include "atari/encoding.h"
#include "atari/res/netsurf.rsh"
#include "atari/plot/plot.h"
#include "atari/clipboard.h"
#include "atari/osspec.h"
#include "atari/search.h"
#include "atari/deskmenu.h"
2014-01-16 19:07:14 +04:00
#include "atari/download.h"
#include "atari/file.h"
#include "atari/filetype.h"
#include "atari/bitmap.h"
2016-04-24 20:41:00 +03:00
#include "atari/font.h"
2013-01-10 02:31:00 +04:00
#include "cflib.h"
static bool atari_quit = false;
2013-01-10 02:31:00 +04:00
struct gui_window *input_window = NULL;
struct gui_window *window_list = NULL;
2014-10-12 13:35:56 +04:00
void *h_gem_rsrc;
2013-01-10 02:31:00 +04:00
long next_poll;
bool rendering = false;
GRECT desk_area;
/* Comandline / Options: */
int option_window_width;
int option_window_height;
int option_window_x;
int option_window_y;
/* Defaults to option_homepage_url, commandline options overwrites that value */
2014-10-12 13:35:56 +04:00
const char *option_homepage_url;
2013-01-10 02:31:00 +04:00
/* path to choices file: */
char options[PATH_MAX];
EVMULT_IN aes_event_in = {
.emi_flags = MU_MESAG | MU_TIMER | MU_KEYBD | MU_BUTTON | MU_M1,
.emi_bclicks = 258,
.emi_bmask = 3,
.emi_bstate = 0,
.emi_m1leave = MO_ENTER,
.emi_m1 = {0,0,0,0},
.emi_m2leave = 0,
.emi_m2 = {0,0,0,0},
.emi_tlow = 0,
.emi_thigh = 0
};
EVMULT_OUT aes_event_out;
short aes_msg_out[8];
bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy);
static nserror gui_window_set_url(struct gui_window *w, nsurl *url);
2013-01-10 02:31:00 +04:00
2014-10-12 13:35:56 +04:00
/**
* Core atari event processing.
*/
static void atari_poll(void)
2013-01-10 02:31:00 +04:00
{
2014-10-12 13:35:56 +04:00
struct gui_window *tmp;
2013-01-10 02:31:00 +04:00
short mx, my, dummy;
aes_event_in.emi_tlow = schedule_run();
if(rendering){
2014-10-12 13:35:56 +04:00
aes_event_in.emi_tlow = nsoption_int(atari_gui_poll_timeout);
}
2013-01-10 02:31:00 +04:00
2013-01-31 22:22:35 +04:00
if(aes_event_in.emi_tlow < 0) {
2014-10-12 13:35:56 +04:00
aes_event_in.emi_tlow = 10000;
printf("long poll!\n");
2013-01-31 22:22:35 +04:00
}
2013-01-10 02:31:00 +04:00
2014-10-12 13:35:56 +04:00
if(input_window && input_window->root->redraw_slots.areas_used > 0) {
window_process_redraws(input_window->root);
}
2013-01-10 02:31:00 +04:00
2013-01-31 22:22:35 +04:00
graf_mkstate(&mx, &my, &dummy, &dummy);
aes_event_in.emi_m1.g_x = mx;
aes_event_in.emi_m1.g_y = my;
evnt_multi_fast(&aes_event_in, aes_msg_out, &aes_event_out);
if(gemtk_wm_dispatch_event(&aes_event_in, &aes_event_out, aes_msg_out) == 0) {
2014-10-12 13:35:56 +04:00
if( (aes_event_out.emo_events & MU_MESAG) != 0 ) {
NSLOG(netsurf, INFO, "WM: %d\n", aes_msg_out[0]);
2014-10-12 13:35:56 +04:00
switch(aes_msg_out[0]) {
case MN_SELECTED:
NSLOG(netsurf, INFO, "Menu Item: %d\n", aes_msg_out[4]);
2014-10-12 13:35:56 +04:00
deskmenu_dispatch_item(aes_msg_out[3], aes_msg_out[4]);
break;
case AP_TERM:
atari_quit = true;
2014-10-12 13:35:56 +04:00
break;
default:
break;
}
}
if((aes_event_out.emo_events & MU_KEYBD) != 0) {
uint16_t nkc = gem_to_norm( (short)aes_event_out.emo_kmeta,
(short)aes_event_out.emo_kreturn);
deskmenu_dispatch_keypress(aes_event_out.emo_kreturn,
aes_event_out.emo_kmeta, nkc);
}
2013-01-31 22:22:35 +04:00
}
tmp = window_list;
while(tmp){
2014-10-12 13:35:56 +04:00
if(tmp->root->redraw_slots.areas_used > 0){
window_process_redraws(tmp->root);
}
tmp = tmp->next;
2013-01-31 22:22:35 +04:00
}
2013-01-10 02:31:00 +04:00
2014-10-12 13:35:56 +04:00
/** @todo implement generic treeview redraw function. */
/** @todo rename hl to atari_hotlist or create getter for it... */
2013-01-31 22:22:35 +04:00
2014-10-12 13:35:56 +04:00
atari_treeview_flush_redraws();
2013-01-10 02:31:00 +04:00
}
2014-10-12 13:35:56 +04:00
/**
* Create and open a gui window for a browsing context.
*
* \param bw bw to create gui_window for
* \param existing an existing gui_window, may be NULL
* \param flags flags for gui window creation
* \return gui window, or NULL on error
*
* If GW_CREATE_CLONE flag is set existing is non-NULL.
*
* The created gui_window must include a reference to the browser
* window passed in the bw param.
*/
static struct gui_window *
gui_window_create(struct browser_window *bw,
2014-10-12 13:35:56 +04:00
struct gui_window *existing,
gui_window_create_flags flags)
{
2013-01-10 02:31:00 +04:00
struct gui_window *gw=NULL;
NSLOG(netsurf, INFO, "gw: %p, BW: %p, existing %p, flags: %d\n", gw, bw,
existing, (int)flags);
2013-01-10 02:31:00 +04:00
gw = calloc(1, sizeof(struct gui_window));
2013-01-10 02:31:00 +04:00
if (gw == NULL)
2014-10-12 13:35:56 +04:00
return NULL;
2013-01-10 02:31:00 +04:00
NSLOG(netsurf, INFO, "new window: %p, bw: %p\n", gw, bw);
2014-02-09 17:07:39 +04:00
window_create(gw, bw, existing, WIDGET_STATUSBAR|WIDGET_TOOLBAR|WIDGET_RESIZE\
2014-10-12 13:35:56 +04:00
|WIDGET_SCROLL);
2013-01-10 02:31:00 +04:00
if (gw->root->win) {
2014-10-12 13:35:56 +04:00
GRECT pos = {
option_window_x, option_window_y,
option_window_width, option_window_height
};
gui_window_set_url(gw, corestring_nsurl_about_blank);
2014-10-12 13:35:56 +04:00
gui_window_set_pointer(gw, BROWSER_POINTER_DEFAULT);
gui_set_input_gui_window(gw);
window_open(gw->root, gw, pos);
2013-01-10 02:31:00 +04:00
}
/* add the window to the window list: */
if( window_list == NULL ) {
2014-10-12 13:35:56 +04:00
window_list = gw;
gw->next = NULL;
gw->prev = NULL;
2013-01-10 02:31:00 +04:00
} else {
2014-10-12 13:35:56 +04:00
struct gui_window * tmp = window_list;
while( tmp->next != NULL ) {
tmp = tmp->next;
}
tmp->next = gw;
gw->prev = tmp;
gw->next = NULL;
2013-01-10 02:31:00 +04:00
}
/* Loose focus: */
window_set_focus(gw->root, WIDGET_NONE, NULL );
/* trigger on-focus event (select all text): */
window_set_focus(gw->root, URL_WIDGET, NULL);
/* delete selection: */
toolbar_key_input(gw->root->toolbar, NK_DEL);
2013-01-10 02:31:00 +04:00
return( gw );
}
2014-10-12 13:35:56 +04:00
/**
* Destroy previously created gui window
*
* \param gw The gui window to destroy.
*/
void gui_window_destroy(struct gui_window *gw)
2013-01-10 02:31:00 +04:00
{
2014-10-12 13:35:56 +04:00
if (gw == NULL)
return;
2013-01-10 02:31:00 +04:00
NSLOG(netsurf, INFO, "%s\n", __FUNCTION__);
2013-01-10 02:31:00 +04:00
2014-10-12 13:35:56 +04:00
if (input_window == gw) {
gui_set_input_gui_window(NULL);
2013-01-10 02:31:00 +04:00
}
2014-10-12 13:35:56 +04:00
nsatari_search_session_destroy(gw->search);
free(gw->browser);
free(gw->status);
free(gw->title);
free(gw->url);
2013-01-10 02:31:00 +04:00
/* unlink the window: */
2014-10-12 13:35:56 +04:00
if(gw->prev != NULL ) {
gw->prev->next = gw->next;
2013-01-10 02:31:00 +04:00
} else {
2014-10-12 13:35:56 +04:00
window_list = gw->next;
2013-01-10 02:31:00 +04:00
}
2014-10-12 13:35:56 +04:00
if( gw->next != NULL ) {
gw->next->prev = gw->prev;
2013-01-10 02:31:00 +04:00
}
2014-10-12 13:35:56 +04:00
window_unref_gui_window(gw->root, gw);
2013-01-10 02:31:00 +04:00
2014-10-12 13:35:56 +04:00
free(gw);
gw = NULL;
2013-01-10 02:31:00 +04:00
2013-01-31 22:22:35 +04:00
if(input_window == NULL) {
2014-10-12 13:35:56 +04:00
gw = window_list;
while( gw != NULL ) {
if(gw->root) {
2014-10-12 16:03:16 +04:00
gui_set_input_gui_window(gw);
2014-10-12 13:35:56 +04:00
break;
}
gw = gw->next;
}
2013-01-10 02:31:00 +04:00
}
}
2014-10-12 13:35:56 +04:00
/**
* Find the current dimensions of a atari browser window content area.
2014-10-12 13:35:56 +04:00
*
* \param gw The gui window to measure content area of.
* \param width receives width of window
2014-10-12 13:35:56 +04:00
* \param height receives height of window
* \return NSERROR_OK on sucess and width and height updated
* else error code.
2014-10-12 13:35:56 +04:00
*/
static nserror
gui_window_get_dimensions(struct gui_window *gw, int *width, int *height)
2013-01-10 02:31:00 +04:00
{
GRECT rect;
window_get_grect(gw->root, BROWSER_AREA_CONTENT, &rect);
2013-01-10 02:31:00 +04:00
*width = rect.g_w;
*height = rect.g_h;
return NSERROR_OK;
2013-01-10 02:31:00 +04:00
}
2014-10-12 13:35:56 +04:00
/**
* Set the title of a window.
*
* \param gw window to update
* \param title new window title
*/
static void gui_window_set_title(struct gui_window *gw, const char *title)
2013-01-10 02:31:00 +04:00
{
if (gw == NULL)
2014-10-12 13:35:56 +04:00
return;
2013-01-10 02:31:00 +04:00
if (gw->root) {
2014-10-12 13:35:56 +04:00
int l;
char * conv;
l = strlen(title)+1;
if (utf8_to_local_encoding(title, l-1, &conv) == NSERROR_OK ) {
l = MIN((uint32_t)atari_sysinfo.aes_max_win_title_len, strlen(conv));
if(gw->title == NULL)
gw->title = malloc(l);
else
gw->title = realloc(gw->title, l);
strncpy(gw->title, conv, l);
free( conv );
} else {
l = MIN((size_t)atari_sysinfo.aes_max_win_title_len, strlen(title));
if(gw->title == NULL)
gw->title = malloc(l);
else
gw->title = realloc(gw->title, l);
strncpy(gw->title, title, l);
}
gw->title[l] = 0;
if(input_window == gw)
window_set_title(gw->root, gw->title);
2013-01-10 02:31:00 +04:00
}
}
2014-11-09 01:08:29 +03:00
/* exported interface documented in atari/gui.h */
2014-11-10 23:15:14 +03:00
void atari_window_set_status(struct gui_window *w, const char *text)
2013-01-10 02:31:00 +04:00
{
int l;
if (w == NULL || text == NULL)
2014-10-12 13:35:56 +04:00
return;
2013-01-10 02:31:00 +04:00
assert(w->root);
l = strlen(text)+1;
if(w->status == NULL)
2014-10-12 13:35:56 +04:00
w->status = malloc(l);
2013-01-10 02:31:00 +04:00
else
2014-10-12 13:35:56 +04:00
w->status = realloc(w->status, l);
2013-01-10 02:31:00 +04:00
strncpy(w->status, text, l);
w->status[l] = 0;
if(input_window == w)
2014-10-12 13:35:56 +04:00
window_set_stauts(w->root, (char*)text);
2013-01-10 02:31:00 +04:00
}
/**
* Invalidates an area of an atari browser window
*
* \param gw gui_window
* \param rect area to redraw or NULL for the entire window area
* \return NSERROR_OK on success or appropriate error code
*/
static nserror
atari_window_invalidate_area(struct gui_window *gw,
const struct rect *rect)
2013-01-10 02:31:00 +04:00
{
2013-01-31 22:22:35 +04:00
GRECT area;
2013-01-10 02:31:00 +04:00
if (gw == NULL) {
return NSERROR_BAD_PARAMETER;
}
2013-01-10 02:31:00 +04:00
window_get_grect(gw->root, BROWSER_AREA_CONTENT, &area);
if (rect != NULL) {
struct gemtk_wm_scroll_info_s *slid;
slid = gemtk_wm_get_scroll_info(gw->root->win);
area.g_x += rect->x0 - (slid->x_pos * slid->x_unit_px);
area.g_y += rect->y0 - (slid->y_pos * slid->y_unit_px);
area.g_w = rect->x1 - rect->x0;
area.g_h = rect->y1 - rect->y0;
}
2013-01-10 02:31:00 +04:00
//dbg_grect("update box", &area);
window_schedule_redraw_grect(gw->root, &area);
return NSERROR_OK;
2013-01-10 02:31:00 +04:00
}
bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy)
{
if (w == NULL)
2014-10-12 13:35:56 +04:00
return false;
2013-01-10 02:31:00 +04:00
2013-01-31 22:22:35 +04:00
window_get_scroll(w->root, sx, sy);
2013-01-10 02:31:00 +04:00
return( true );
}
/**
* Set the scroll position of a atari browser window.
*
* Scrolls the viewport to ensure the specified rectangle of the
* content is shown. The atari implementation scrolls the contents so
* the specified point in the content is at the top of the viewport.
*
* \param gw gui window to scroll
* \param rect The rectangle to ensure is shown.
* \return NSERROR_OK on success or apropriate error code.
*/
static nserror
gui_window_set_scroll(struct gui_window *gw, const struct rect *rect)
2013-01-10 02:31:00 +04:00
{
if ((gw == NULL) ||
(gw->browser->bw == NULL) ||
(!browser_window_has_content(gw->browser->bw))) {
return NSERROR_BAD_PARAMETER;
}
2013-01-10 02:31:00 +04:00
NSLOG(netsurf, INFO, "scroll (gui_window: %p) %d, %d\n", gw, rect->x0,
rect->y0);
window_scroll_by(gw->root, rect->x0, rect->y0);
2013-01-10 02:31:00 +04:00
return NSERROR_OK;
2013-01-10 02:31:00 +04:00
}
2014-10-12 13:35:56 +04:00
/**
* Update the extent of the inside of a browser window to that of the
* current content.
*
* It seems this method is called when content size got adjusted, so
* that we can adjust scroll info. We also have to call it when tab
* change occurs.
*
* \param gw gui_window to update the extent of
*/
static void gui_window_update_extent(struct gui_window *gw)
2013-01-10 02:31:00 +04:00
{
2014-10-12 13:35:56 +04:00
if(browser_window_has_content(gw->browser->bw)) {
/** @todo store content size. */
if(window_get_active_gui_window(gw->root) == gw) {
int width, height;
2014-10-12 13:35:56 +04:00
GRECT area;
browser_window_get_extents(gw->browser->bw, false, &width, &height);
window_set_content_size(gw->root, width, height);
window_update_back_forward(gw->root);
2014-10-12 13:35:56 +04:00
window_get_grect(gw->root, BROWSER_AREA_CONTENT, &area);
window_schedule_redraw_grect(gw->root, &area);
}
2013-01-10 02:31:00 +04:00
}
}
/**
* set the pointer shape
*/
void gui_window_set_pointer(struct gui_window *gw, gui_pointer_shape shape)
{
if (gw == NULL)
2014-10-12 13:35:56 +04:00
return;
2013-01-10 02:31:00 +04:00
switch (shape) {
case GUI_POINTER_POINT: /* link */
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.hand;
break;
2013-01-10 02:31:00 +04:00
case GUI_POINTER_MENU:
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.menu;
break;
2013-01-10 02:31:00 +04:00
case GUI_POINTER_CARET: /* input */
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.ibeam;
break;
2013-01-10 02:31:00 +04:00
case GUI_POINTER_CROSS:
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.cross;
break;
2013-01-10 02:31:00 +04:00
case GUI_POINTER_MOVE:
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.sizeall;
break;
2013-01-10 02:31:00 +04:00
case GUI_POINTER_RIGHT:
case GUI_POINTER_LEFT:
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.sizewe;
break;
2013-01-10 02:31:00 +04:00
case GUI_POINTER_UP:
case GUI_POINTER_DOWN:
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.sizens;
break;
2013-01-10 02:31:00 +04:00
case GUI_POINTER_RU:
case GUI_POINTER_LD:
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.sizenesw;
break;
2013-01-10 02:31:00 +04:00
case GUI_POINTER_RD:
case GUI_POINTER_LU:
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.sizenwse;
break;
2013-01-10 02:31:00 +04:00
case GUI_POINTER_WAIT:
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.wait;
break;
2013-01-10 02:31:00 +04:00
case GUI_POINTER_PROGRESS:
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.appstarting;
break;
2013-01-10 02:31:00 +04:00
case GUI_POINTER_NO_DROP:
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.nodrop;
break;
2013-01-10 02:31:00 +04:00
case GUI_POINTER_NOT_ALLOWED:
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.deny;
break;
2013-01-10 02:31:00 +04:00
case GUI_POINTER_HELP:
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.help;
break;
2013-01-10 02:31:00 +04:00
default:
2014-10-12 13:35:56 +04:00
gw->cursor = &gem_cursors.arrow;
break;
2013-01-10 02:31:00 +04:00
}
if (input_window == gw) {
2014-10-12 13:35:56 +04:00
gem_set_cursor(gw->cursor);
2013-01-10 02:31:00 +04:00
}
}
static nserror gui_window_set_url(struct gui_window *w, nsurl *url)
2013-01-10 02:31:00 +04:00
{
int l;
if (w == NULL)
2014-11-11 01:16:38 +03:00
return NSERROR_OK;
2013-01-10 02:31:00 +04:00
l = strlen(nsurl_access(url))+1;
2013-01-10 02:31:00 +04:00
if (w->url == NULL) {
2014-10-12 13:35:56 +04:00
w->url = malloc(l);
2013-01-10 02:31:00 +04:00
} else {
2014-10-12 13:35:56 +04:00
w->url = realloc(w->url, l);
2013-01-10 02:31:00 +04:00
}
strncpy(w->url, nsurl_access(url), l);
2013-01-10 02:31:00 +04:00
w->url[l] = 0;
2013-01-31 22:22:35 +04:00
if(input_window == w->root->active_gui_window) {
toolbar_set_url(w->root->toolbar, nsurl_access(url));
2013-01-10 02:31:00 +04:00
}
return NSERROR_OK;
2013-01-10 02:31:00 +04:00
}
char * gui_window_get_url(struct gui_window *gw)
{
2014-10-12 13:35:56 +04:00
if (gw == NULL) {
return(NULL);
}
return(gw->url);
}
char * gui_window_get_title(struct gui_window *gw)
{
2014-10-12 13:35:56 +04:00
if (gw == NULL) {
return(NULL);
}
return(gw->title);
}
2013-01-10 02:31:00 +04:00
static void throbber_advance( void * data )
{
struct gui_window * gw = (struct gui_window *)data;
if (gw->root == NULL)
2014-10-12 13:35:56 +04:00
return;
2013-01-10 02:31:00 +04:00
if (gw->root->toolbar == NULL)
2014-10-12 13:35:56 +04:00
return;
2013-01-10 02:31:00 +04:00
if (gw->root->toolbar->throbber.running == false)
2014-10-12 13:35:56 +04:00
return;
2013-01-10 02:31:00 +04:00
toolbar_throbber_progress(gw->root->toolbar);
atari_schedule(1000, throbber_advance, gw );
}
static void gui_window_start_throbber(struct gui_window *w)
2013-01-10 02:31:00 +04:00
{
if (w == NULL)
2014-10-12 13:35:56 +04:00
return;
2013-01-10 02:31:00 +04:00
toolbar_set_throbber_state(w->root->toolbar, true);
atari_schedule(1000, throbber_advance, w );
2013-01-10 02:31:00 +04:00
rendering = true;
}
static void gui_window_stop_throbber(struct gui_window *w)
2013-01-10 02:31:00 +04:00
{
if (w == NULL)
2014-10-12 13:35:56 +04:00
return;
2013-01-10 02:31:00 +04:00
if (w->root->toolbar->throbber.running == false)
2014-10-12 13:35:56 +04:00
return;
2013-01-10 02:31:00 +04:00
atari_schedule(-1, throbber_advance, w);
2013-01-10 02:31:00 +04:00
toolbar_set_throbber_state(w->root->toolbar, false);
rendering = false;
}
2014-10-12 13:35:56 +04:00
/**
* Place caret in window
*/
static void
gui_window_place_caret(struct gui_window *w, int x, int y, int height,
const struct rect *clip)
2013-01-10 02:31:00 +04:00
{
2013-01-31 22:22:35 +04:00
window_place_caret(w->root, 1, x, y, height, NULL);
w->root->caret.state |= CARET_STATE_ENABLED;
2013-01-10 02:31:00 +04:00
return;
}
/**
* clear window caret
*/
static void
2013-01-10 02:31:00 +04:00
gui_window_remove_caret(struct gui_window *w)
{
if (w == NULL)
2014-10-12 13:35:56 +04:00
return;
2013-01-10 02:31:00 +04:00
2013-01-31 22:22:35 +04:00
if ((w->root->caret.state & CARET_STATE_ENABLED) != 0) {
2014-10-12 13:35:56 +04:00
//printf("gw hide caret\n");
window_place_caret(w->root, 0, -1, -1, -1, NULL);
w->root->caret.state &= ~CARET_STATE_ENABLED;
2013-01-31 22:22:35 +04:00
}
2013-01-10 02:31:00 +04:00
return;
}
2014-10-12 13:35:56 +04:00
/**
* Set a favicon for a gui window.
*
* \param g window to update.
* \param icon handle to object to use as icon.
*/
static void
gui_window_set_icon(struct gui_window *g, struct hlcache_handle *icon)
2013-01-10 02:31:00 +04:00
{
struct bitmap *bmp_icon;
bmp_icon = (icon != NULL) ? content_get_bitmap(icon) : NULL;
g->icon = bmp_icon;
2013-01-31 22:22:35 +04:00
if(input_window == g) {
2014-10-12 13:35:56 +04:00
window_set_icon(g->root, bmp_icon);
2013-01-10 02:31:00 +04:00
}
}
static void gui_window_new_content(struct gui_window *w)
2013-01-10 02:31:00 +04:00
{
2013-01-31 22:22:35 +04:00
struct gemtk_wm_scroll_info_s *slid = gemtk_wm_get_scroll_info(w->root->win);
slid->x_pos = 0;
slid->y_pos = 0;
gemtk_wm_update_slider(w->root->win, GEMTK_WM_VH_SLIDER);
atari_window_invalidate_area(w, NULL);
2013-01-10 02:31:00 +04:00
}
/**
2013-01-09 04:12:30 +04:00
* Core asks front end for clipboard contents.
*
* \param buffer UTF-8 text, allocated by front end, ownership yeilded to core
* \param length Byte length of UTF-8 text in buffer
*/
2014-01-15 03:31:54 +04:00
static void gui_get_clipboard(char **buffer, size_t *length)
{
2013-01-31 22:22:35 +04:00
char *clip;
2013-01-31 22:22:35 +04:00
*length = 0;
*buffer = 0;
2013-01-31 22:22:35 +04:00
clip = scrap_txt_read();
2013-01-31 22:22:35 +04:00
if(clip == NULL) {
2014-10-12 13:35:56 +04:00
return;
2013-01-31 22:22:35 +04:00
} else {
2014-10-12 13:35:56 +04:00
// clipboard is in atari encoding, convert it to utf8:
size_t clip_len;
char *utf8 = NULL;
clip_len = strlen(clip);
if (clip_len > 0) {
nserror ret;
ret = utf8_to_local_encoding(clip, clip_len, &utf8);
if (ret == NSERROR_OK && utf8 != NULL) {
*buffer = utf8;
*length = strlen(utf8);
} else {
assert(ret == NSERROR_OK && utf8 != NULL);
}
}
2013-01-10 02:31:00 +04:00
2014-10-12 13:35:56 +04:00
free(clip);
2013-01-31 22:22:35 +04:00
}
}
/**
2013-01-09 04:12:30 +04:00
* Core tells front end to put given text in clipboard
*
2013-01-09 04:12:30 +04:00
* \param buffer UTF-8 text, owned by core
* \param length Byte length of UTF-8 text in buffer
* \param styles Array of styles given to text runs, owned by core, or NULL
* \param n_styles Number of text run styles in array
*/
2014-01-15 03:31:54 +04:00
static void gui_set_clipboard(const char *buffer, size_t length,
2014-10-12 13:35:56 +04:00
nsclipboard_styles styles[], int n_styles)
{
2013-01-31 22:22:35 +04:00
if (length > 0 && buffer != NULL) {
2014-10-12 13:35:56 +04:00
// convert utf8 input to atari encoding:
2014-10-12 13:35:56 +04:00
nserror ret;
char *clip = NULL;
2013-01-10 02:31:00 +04:00
2014-10-12 13:35:56 +04:00
ret = utf8_to_local_encoding(buffer,length, &clip);
if (ret == NSERROR_OK) {
scrap_txt_write(clip);
} else {
assert(ret == NSERROR_OK);
}
free(clip);
2013-01-31 22:22:35 +04:00
}
}
static nserror
2014-10-12 13:35:56 +04:00
gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
unsigned long num, nserror (*cb)(bool proceed, void *pw),
void *cbpw)
2013-01-10 02:31:00 +04:00
{
struct sslcert_session_data *data;
NSLOG(netsurf, INFO, "url %s", nsurl_access(url));
// TODO: localize string
int b = form_alert(1, "[2][SSL Verify failed, continue?][Continue|Abort|Details...]");
if(b == 1){
// Accept
urldb_set_cert_permissions(url, true);
cb(true, cbpw);
} else if(b == 2) {
// Reject
urldb_set_cert_permissions(url, false);
cb(false, cbpw);
} else if(b == 3) {
// Inspect
sslcert_viewer_create_session_data(num, url, cb, cbpw, certs,
&data);
atari_sslcert_viewer_open(data);
}
return NSERROR_OK;
2013-01-10 02:31:00 +04:00
}
void gui_set_input_gui_window(struct gui_window *gw)
{
NSLOG(netsurf, INFO, "Setting input window from: %p to %p\n",
input_window, gw);
2013-01-31 22:22:35 +04:00
input_window = gw;
2013-01-10 02:31:00 +04:00
}
struct gui_window * gui_get_input_window(void)
{
2014-10-12 13:35:56 +04:00
return(input_window);
}
static void gui_quit(void)
2013-01-10 02:31:00 +04:00
{
NSLOG(netsurf, INFO, "quitting");
2013-01-10 02:31:00 +04:00
struct gui_window *gw = window_list;
struct gui_window *tmp = window_list;
2013-01-10 02:31:00 +04:00
2014-10-12 13:35:56 +04:00
/* Destroy all remaining browser windows: */
while (gw) {
2014-10-12 13:35:56 +04:00
tmp = gw->next;
browser_window_destroy(gw->browser->bw);
gw = tmp;
2013-01-10 02:31:00 +04:00
}
2014-10-12 13:35:56 +04:00
/* destroy the treeview windows: */
atari_global_history_destroy();
2013-08-13 15:41:04 +04:00
atari_hotlist_destroy();
atari_cookie_manager_destroy();
2014-10-12 13:35:56 +04:00
/* shutdown the toolbar framework: */
2013-01-10 02:31:00 +04:00
toolbar_exit();
2014-10-12 13:35:56 +04:00
/* save persistent informations: */
2013-01-10 02:31:00 +04:00
urldb_save_cookies(nsoption_charp(cookie_file));
urldb_save(nsoption_charp(url_file));
deskmenu_destroy();
2013-01-22 05:33:27 +04:00
gemtk_wm_exit();
2013-01-10 02:31:00 +04:00
rsrc_free();
NSLOG(netsurf, INFO, "Shutting down plotter");
2013-01-10 02:31:00 +04:00
plot_finalise();
NSLOG(netsurf, INFO, "done");
2013-01-10 02:31:00 +04:00
}
2014-10-12 13:35:56 +04:00
/**
* Process commandline parameters.
*/
2013-01-10 02:31:00 +04:00
static bool
process_cmdline(int argc, char** argv)
{
int opt;
bool set_default_dimensions = true;
NSLOG(netsurf, INFO, "argc %d, argv %p", argc, argv);
2013-01-10 02:31:00 +04:00
if ((nsoption_int(window_width) != 0) && (nsoption_int(window_height) != 0)) {
2014-10-12 13:35:56 +04:00
option_window_width = nsoption_int(window_width);
option_window_height = nsoption_int(window_height);
option_window_x = nsoption_int(window_x);
option_window_y = nsoption_int(window_y);
2013-01-10 02:31:00 +04:00
2014-10-12 13:35:56 +04:00
if (option_window_width <= desk_area.g_w
&& option_window_height < desk_area.g_h) {
set_default_dimensions = false;
}
2013-01-10 02:31:00 +04:00
}
if (set_default_dimensions) {
2014-10-12 13:35:56 +04:00
if( sys_type() == SYS_TOS ) {
/* on single tasking OS, start as fulled window: */
option_window_width = desk_area.g_w;
option_window_height = desk_area.g_h;
option_window_x = desk_area.g_w/2-(option_window_width/2);
option_window_y = (desk_area.g_h/2)-(option_window_height/2);
} else {
option_window_width = 600;
option_window_height = 360;
option_window_x = 10;
option_window_y = 30;
}
2013-01-10 02:31:00 +04:00
}
if (nsoption_charp(homepage_url) != NULL)
2014-10-12 13:35:56 +04:00
option_homepage_url = nsoption_charp(homepage_url);
2013-01-10 02:31:00 +04:00
else
2014-10-12 13:35:56 +04:00
option_homepage_url = NETSURF_HOMEPAGE;
2013-01-10 02:31:00 +04:00
while((opt = getopt(argc, argv, "w:h:")) != -1) {
2014-10-12 13:35:56 +04:00
switch (opt) {
case 'w':
option_window_width = atoi(optarg);
break;
case 'h':
option_window_height = atoi(optarg);
break;
default:
fprintf(stderr,
"Usage: %s [w,h,v] url\n",
argv[0]);
return false;
}
2013-01-10 02:31:00 +04:00
}
if (optind < argc) {
2014-10-12 13:35:56 +04:00
option_homepage_url = argv[optind];
2013-01-10 02:31:00 +04:00
}
return true;
}
static inline void create_cursor(int flags, short mode, void * form,
2014-10-12 13:35:56 +04:00
MFORM_EX * m)
2013-01-10 02:31:00 +04:00
{
m->flags = flags;
m->number = mode;
if( flags & MFORM_EX_FLAG_USERFORM ) {
2014-10-12 13:35:56 +04:00
m->number = mode;
m->tree = (OBJECT*)form;
2013-01-10 02:31:00 +04:00
}
}
2014-01-15 03:31:54 +04:00
static nsurl *gui_get_resource_url(const char *path)
2013-01-10 02:31:00 +04:00
{
char buf[PATH_MAX];
nsurl *url = NULL;
atari_find_resource((char*)&buf, path, path);
netsurf_path_to_nsurl(buf, &url);
2013-01-10 02:31:00 +04:00
return url;
}
2013-05-27 18:02:04 +04:00
/**
* Set option defaults for atari frontend
*
* @param defaults The option table to update.
* @return error status.
*/
static nserror set_defaults(struct nsoption_s *defaults)
2013-01-10 02:31:00 +04:00
{
/* Set defaults for absent option strings */
nsoption_setnull_charp(cookie_file, strdup("cookies"));
if (nsoption_charp(cookie_file) == NULL) {
NSLOG(netsurf, INFO, "Failed initialising string options");
2013-05-27 18:02:04 +04:00
return NSERROR_BAD_PARAMETER;
2013-01-10 02:31:00 +04:00
}
2013-05-27 18:02:04 +04:00
return NSERROR_OK;
2013-01-10 02:31:00 +04:00
}
static char *theapp = (char*)"NetSurf";
/**
* Initialise atari gui.
*/
2013-01-10 02:31:00 +04:00
static void gui_init(int argc, char** argv)
{
char buf[PATH_MAX];
OBJECT * cursors;
atari_find_resource(buf, "netsurf.rsc", "./res/netsurf.rsc");
NSLOG(netsurf, INFO, "Using RSC file: %s ", (char *)&buf);
2013-01-10 02:31:00 +04:00
if (rsrc_load(buf)==0) {
2014-10-12 13:35:56 +04:00
char msg[1024];
2014-10-12 13:35:56 +04:00
snprintf(msg, 1024, "Unable to open GEM Resource file (%s)!", buf);
die(msg);
2013-01-10 02:31:00 +04:00
}
2013-01-31 22:22:35 +04:00
wind_get_grect(0, WF_WORKXYWH, &desk_area);
2013-01-10 02:31:00 +04:00
create_cursor(0, POINT_HAND, NULL, &gem_cursors.hand );
create_cursor(0, TEXT_CRSR, NULL, &gem_cursors.ibeam );
create_cursor(0, THIN_CROSS, NULL, &gem_cursors.cross);
create_cursor(0, BUSY_BEE, NULL, &gem_cursors.wait);
create_cursor(0, ARROW, NULL, &gem_cursors.arrow);
create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizeall);
create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizenesw);
create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizenwse);
2013-01-22 05:33:27 +04:00
cursors = gemtk_obj_get_tree(CURSOR);
2013-01-10 02:31:00 +04:00
create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_APPSTART,
2014-10-12 13:35:56 +04:00
cursors, &gem_cursors.appstarting);
2013-01-10 02:31:00 +04:00
gem_set_cursor( &gem_cursors.appstarting );
create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_SIZEWE,
2014-10-12 13:35:56 +04:00
cursors, &gem_cursors.sizewe);
2013-01-10 02:31:00 +04:00
create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_SIZENS,
2014-10-12 13:35:56 +04:00
cursors, &gem_cursors.sizens);
2013-01-10 02:31:00 +04:00
create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_NODROP,
2014-10-12 13:35:56 +04:00
cursors, &gem_cursors.nodrop);
2013-01-10 02:31:00 +04:00
create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_DENY,
2014-10-12 13:35:56 +04:00
cursors, &gem_cursors.deny);
2013-01-10 02:31:00 +04:00
create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_MENU,
2014-10-12 13:35:56 +04:00
cursors, &gem_cursors.menu);
2013-01-10 02:31:00 +04:00
create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_HELP,
2014-10-12 13:35:56 +04:00
cursors, &gem_cursors.help);
2013-01-10 02:31:00 +04:00
NSLOG(netsurf, INFO, "Enabling core select menu");
2013-01-10 02:31:00 +04:00
nsoption_set_bool(core_select_menu, true);
NSLOG(netsurf, INFO, "Loading url.db from: %s", nsoption_charp(url_file));
2013-01-10 02:31:00 +04:00
if( strlen(nsoption_charp(url_file)) ) {
2014-10-12 13:35:56 +04:00
urldb_load(nsoption_charp(url_file));
2013-01-10 02:31:00 +04:00
}
NSLOG(netsurf, INFO, "Loading cookies from: %s",
nsoption_charp(cookie_file));
2013-01-10 02:31:00 +04:00
if( strlen(nsoption_charp(cookie_file)) ) {
2014-10-12 13:35:56 +04:00
urldb_load_cookies(nsoption_charp(cookie_file));
2013-01-10 02:31:00 +04:00
}
if (process_cmdline(argc,argv) != true)
2014-10-12 13:35:56 +04:00
die("unable to process command line.\n");
2013-01-10 02:31:00 +04:00
NSLOG(netsurf, INFO, "Initializing NKC...");
2013-01-10 02:31:00 +04:00
nkc_init();
NSLOG(netsurf, INFO, "Initializing plotters...");
2017-02-12 21:01:46 +03:00
struct redraw_context ctx = {
.interactive = true,
.background_images = true,
.plot = &atari_plotters
};
plot_init(&ctx, nsoption_charp(atari_font_driver));
2013-01-10 02:31:00 +04:00
2013-01-31 22:22:35 +04:00
aes_event_in.emi_m1leave = MO_LEAVE;
aes_event_in.emi_m1.g_w = 1;
aes_event_in.emi_m1.g_h = 1;
//next_poll = clock() + (CLOCKS_PER_SEC>>3);
2013-01-10 02:31:00 +04:00
deskmenu_init();
menu_register( -1, theapp);
if (sys_type() & (SYS_MAGIC|SYS_NAES|SYS_XAAES)) {
2014-10-12 13:35:56 +04:00
menu_register( _AESapid, (char*)" NetSurf ");
2013-01-10 02:31:00 +04:00
}
2013-01-22 05:33:27 +04:00
gemtk_wm_init();
2014-10-12 13:35:56 +04:00
/* Initialize the specific treeview windows: */
atari_global_history_init();
2013-08-13 15:41:04 +04:00
atari_hotlist_init();
atari_cookie_manager_init();
/* Initialize the toolbar framework: */
2013-01-10 02:31:00 +04:00
toolbar_init();
}
/**
* process miscellaneous window events
*
* \param gw The window receiving the event.
* \param event The event code.
* \return NSERROR_OK when processed ok
*/
static nserror
gui_window_event(struct gui_window *gw, enum gui_window_event event)
{
switch (event) {
case GW_EVENT_UPDATE_EXTENT:
gui_window_update_extent(gw);
break;
case GW_EVENT_REMOVE_CARET:
gui_window_remove_caret(gw);
break;
case GW_EVENT_NEW_CONTENT:
gui_window_new_content(gw);
break;
case GW_EVENT_START_THROBBER:
gui_window_start_throbber(gw);
break;
case GW_EVENT_STOP_THROBBER:
gui_window_stop_throbber(gw);
break;
default:
break;
}
return NSERROR_OK;
}
static struct gui_window_table atari_window_table = {
.create = gui_window_create,
.destroy = gui_window_destroy,
.invalidate = atari_window_invalidate_area,
.get_scroll = gui_window_get_scroll,
.set_scroll = gui_window_set_scroll,
.get_dimensions = gui_window_get_dimensions,
.event = gui_window_event,
.set_title = gui_window_set_title,
.set_url = gui_window_set_url,
.set_icon = gui_window_set_icon,
2014-11-10 23:15:14 +03:00
.set_status = atari_window_set_status,
.set_pointer = gui_window_set_pointer,
.place_caret = gui_window_place_caret,
};
2014-01-15 23:37:05 +04:00
static struct gui_clipboard_table atari_clipboard_table = {
.get = gui_get_clipboard,
.set = gui_set_clipboard,
};
static struct gui_fetch_table atari_fetch_table = {
.filetype = fetch_filetype,
.get_resource_url = gui_get_resource_url,
};
static struct gui_misc_table atari_misc_table = {
.schedule = atari_schedule,
.warning = atari_warn_user,
.quit = gui_quit,
};
2013-01-10 02:31:00 +04:00
/* #define WITH_DBG_LOGFILE 1 */
/**
* Entry point from OS.
2013-01-10 02:31:00 +04:00
*
* /param argc The number of arguments in the string vector.
* /param argv The argument string vector.
* /return The return code to the OS
*/
int main(int argc, char** argv)
{
char messages[PATH_MAX];
2014-09-15 23:51:24 +04:00
char store[PATH_MAX];
2013-05-27 18:02:04 +04:00
const char *addr;
char * file_url = NULL;
struct stat stat_buf;
nsurl *url;
nserror ret;
2014-09-16 01:06:28 +04:00
struct netsurf_table atari_table = {
.misc = &atari_misc_table,
2014-01-15 23:37:05 +04:00
.window = &atari_window_table,
.clipboard = &atari_clipboard_table,
.download = atari_download_table,
.fetch = &atari_fetch_table,
.file = atari_file_table,
.utf8 = atari_utf8_table,
.search = atari_search_table,
.llcache = filesystem_llcache_table,
2016-04-24 20:41:00 +03:00
.bitmap = atari_bitmap_table,
.layout = atari_layout_table
2014-01-15 23:37:05 +04:00
};
2013-01-10 02:31:00 +04:00
ret = netsurf_register(&atari_table);
if (ret != NSERROR_OK) {
2014-10-12 13:35:56 +04:00
die("NetSurf operation table failed registration");
}
/** @todo logging file descriptor update belongs in a nslog_init callback */
2013-01-10 02:31:00 +04:00
setbuf(stderr, NULL);
setbuf(stdout, NULL);
#ifdef WITH_DBG_LOGFILE
freopen("stdout.log", "a+", stdout);
freopen("stderr.log", "a+", stderr);
#endif
graf_mouse(BUSY_BEE, NULL);
init_app(NULL);
init_os_info();
atari_find_resource((char*)&messages, "messages", "res/messages");
atari_find_resource((char*)&options, "Choices", "Choices");
2014-09-15 23:51:24 +04:00
atari_find_resource((char*)&store, "cache", "res/cache");
2013-01-10 02:31:00 +04:00
/* initialise logging - not fatal if it fails but not much we can
* do about it
*/
nslog_init(NULL, &argc, argv);
2013-05-27 18:02:04 +04:00
/* user options setup */
ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default);
if (ret != NSERROR_OK) {
2014-10-12 13:35:56 +04:00
die("Options failed to initialise");
2013-05-27 18:02:04 +04:00
}
nsoption_read(options, NULL);
nsoption_commandline(&argc, argv, NULL);
ret = messages_add_from_file(messages);
2013-05-27 18:02:04 +04:00
/* common initialisation */
NSLOG(netsurf, INFO, "Initialising core...");
ret = netsurf_init(store);
2013-05-27 18:02:04 +04:00
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");
}
2013-01-10 02:31:00 +04:00
NSLOG(netsurf, INFO, "Initializing GUI...");
2013-01-10 02:31:00 +04:00
gui_init(argc, argv);
graf_mouse( ARROW , NULL);
NSLOG(netsurf, INFO, "Creating initial browser window...");
addr = option_homepage_url;
if (strncmp(addr, "file://", 7) && strncmp(addr, "http://", 7)) {
2014-10-12 13:35:56 +04:00
if (stat(addr, &stat_buf) == 0) {
file_url = local_file_to_url(addr);
addr = file_url;
}
}
2013-05-27 18:02:04 +04:00
/* create an initial browser window */
ret = nsurl_create(addr, &url);
if (ret == NSERROR_OK) {
ret = browser_window_create(BW_CREATE_HISTORY,
2013-05-27 18:02:04 +04:00
url,
NULL,
NULL,
NULL);
nsurl_unref(url);
}
if (ret != NSERROR_OK) {
atari_warn_user(messages_get_errorcode(ret), 0);
2013-05-27 18:02:04 +04:00
} else {
NSLOG(netsurf, INFO, "Entering Atari event mainloop...");
while (!atari_quit) {
atari_poll();
}
2013-05-27 18:02:04 +04:00
}
2013-01-10 02:31:00 +04:00
netsurf_exit();
free(file_url);
2013-01-10 02:31:00 +04:00
#ifdef WITH_DBG_LOGFILE
fclose(stdout);
fclose(stderr);
#endif
NSLOG(netsurf, INFO, "exit_gem");
/* finalise logging */
nslog_finalise();
2013-01-31 22:22:35 +04:00
exit_gem();
2013-01-10 02:31:00 +04:00
return 0;
}