2014-05-19 19:53:13 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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/>.
|
2013-09-16 04:26:43 +04:00
|
|
|
*/
|
2013-09-21 07:29:04 +04:00
|
|
|
|
2016-04-21 01:56:29 +03:00
|
|
|
#include <assert.h>
|
|
|
|
|
2014-10-17 00:23:51 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
2016-05-30 14:07:16 +03:00
|
|
|
#include "netsurf/mouse.h"
|
2016-05-30 23:05:57 +03:00
|
|
|
#include "netsurf/plotters.h"
|
2013-09-21 07:29:04 +04:00
|
|
|
#include "desktop/cookie_manager.h"
|
2014-10-17 00:23:51 +04:00
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
#include "atari/treeview.h"
|
|
|
|
#include "atari/cookies.h"
|
|
|
|
#include "atari/gemtk/gemtk.h"
|
|
|
|
#include "atari/res/netsurf.rsh"
|
|
|
|
|
|
|
|
extern GRECT desk_area;
|
|
|
|
|
|
|
|
struct atari_cookie_manager_s atari_cookie_manager;
|
|
|
|
|
|
|
|
|
|
|
|
/* Setup Atari Treeview Callbacks: */
|
|
|
|
static nserror atari_cookie_manager_init_phase2(struct core_window *cw,
|
|
|
|
struct core_window_callback_table * default_callbacks);
|
|
|
|
static void atari_cookie_manager_finish(struct core_window *cw);
|
|
|
|
static void atari_cookie_manager_keypress(struct core_window *cw,
|
|
|
|
uint32_t ucs4);
|
|
|
|
static void atari_cookie_manager_mouse_action(struct core_window *cw,
|
|
|
|
browser_mouse_state mouse,
|
|
|
|
int x, int y);
|
|
|
|
static void atari_cookie_manager_draw(struct core_window *cw, int x,
|
|
|
|
int y, struct rect *clip,
|
|
|
|
const struct redraw_context *ctx);
|
|
|
|
static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]);
|
|
|
|
|
|
|
|
static struct atari_treeview_callbacks atari_cookie_manager_treeview_callbacks = {
|
|
|
|
.init_phase2 = atari_cookie_manager_init_phase2,
|
|
|
|
.finish = atari_cookie_manager_finish,
|
|
|
|
.draw = atari_cookie_manager_draw,
|
|
|
|
.keypress = atari_cookie_manager_keypress,
|
|
|
|
.mouse_action = atari_cookie_manager_mouse_action,
|
|
|
|
.gemtk_user_func = handle_event
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-04-20 12:43:58 +03:00
|
|
|
static nserror
|
|
|
|
atari_cookie_manager_init_phase2(struct core_window *cw,
|
|
|
|
struct core_window_callback_table *cb_t)
|
2013-09-21 07:29:04 +04:00
|
|
|
{
|
2016-04-20 12:43:58 +03:00
|
|
|
LOG("cw %p",cw);
|
2013-09-21 07:29:04 +04:00
|
|
|
return(cookie_manager_init(cb_t, cw));
|
|
|
|
}
|
|
|
|
|
2016-04-20 12:43:58 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
atari_cookie_manager_finish(struct core_window *cw)
|
2013-09-21 07:29:04 +04:00
|
|
|
{
|
2016-04-20 12:43:58 +03:00
|
|
|
LOG("cw %p",cw);
|
2013-09-21 07:29:04 +04:00
|
|
|
cookie_manager_fini();
|
|
|
|
}
|
|
|
|
|
2016-04-20 12:43:58 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
atari_cookie_manager_draw(struct core_window *cw,
|
|
|
|
int x, int y,
|
|
|
|
struct rect *clip,
|
|
|
|
const struct redraw_context *ctx)
|
2013-09-21 07:29:04 +04:00
|
|
|
{
|
|
|
|
cookie_manager_redraw(x, y, clip, ctx);
|
|
|
|
}
|
|
|
|
|
2016-04-20 12:43:58 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
atari_cookie_manager_keypress(struct core_window *cw, uint32_t ucs4)
|
2013-09-21 07:29:04 +04:00
|
|
|
{
|
2016-04-20 12:43:58 +03:00
|
|
|
LOG("ucs4: %"PRIu32, ucs4);
|
2013-09-21 07:29:04 +04:00
|
|
|
cookie_manager_keypress(ucs4);
|
|
|
|
}
|
|
|
|
|
2016-04-20 12:43:58 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
atari_cookie_manager_mouse_action(struct core_window *cw,
|
|
|
|
browser_mouse_state mouse,
|
|
|
|
int x, int y)
|
2013-09-21 07:29:04 +04:00
|
|
|
{
|
2014-05-19 19:53:45 +04:00
|
|
|
cookie_manager_mouse_action(mouse, x, y);
|
2013-09-21 07:29:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
|
|
|
|
{
|
2013-09-26 03:24:49 +04:00
|
|
|
short retval = 0;
|
2013-09-21 07:29:04 +04:00
|
|
|
|
2016-04-20 12:43:58 +03:00
|
|
|
LOG("win %p", win);
|
2013-09-21 07:29:04 +04:00
|
|
|
|
2016-04-20 12:43:58 +03:00
|
|
|
if (ev_out->emo_events & MU_MESAG) {
|
2013-09-21 07:29:04 +04:00
|
|
|
switch (msg[0]) {
|
|
|
|
|
|
|
|
case WM_TOOLBAR:
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("WM_TOOLBAR");
|
2013-09-21 07:29:04 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_CLOSED:
|
|
|
|
atari_cookie_manager_close();
|
2013-09-26 03:24:49 +04:00
|
|
|
retval = 1;
|
2013-09-21 07:29:04 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 03:24:49 +04:00
|
|
|
return(retval);
|
2014-05-19 19:53:13 +04:00
|
|
|
}
|
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
void atari_cookie_manager_init(void)
|
|
|
|
{
|
|
|
|
if (atari_cookie_manager.init == false) {
|
|
|
|
|
|
|
|
if (atari_cookie_manager.window == NULL) {
|
|
|
|
int flags = ATARI_TREEVIEW_WIDGETS;
|
|
|
|
short handle = -1;
|
|
|
|
OBJECT * tree = gemtk_obj_get_tree(TOOLBAR_COOKIES);
|
|
|
|
assert( tree );
|
|
|
|
|
|
|
|
handle = wind_create(flags, 0, 0, desk_area.g_w, desk_area.g_h);
|
|
|
|
atari_cookie_manager.window = gemtk_wm_add(handle,
|
|
|
|
GEMTK_WM_FLAG_DEFAULTS, NULL);
|
|
|
|
if( atari_cookie_manager.window == NULL ) {
|
|
|
|
gemtk_msg_box_show(GEMTK_MSG_BOX_ALERT,
|
|
|
|
"Failed to allocate Treeview:\nCookies");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wind_set_str(handle, WF_NAME, (char*)messages_get("Cookies"));
|
|
|
|
gemtk_wm_set_toolbar(atari_cookie_manager.window, tree, 0, 0);
|
|
|
|
gemtk_wm_unlink(atari_cookie_manager.window);
|
|
|
|
|
|
|
|
atari_cookie_manager.tv = atari_treeview_create(
|
|
|
|
atari_cookie_manager.window,
|
|
|
|
&atari_cookie_manager_treeview_callbacks,
|
2013-09-21 22:20:49 +04:00
|
|
|
NULL, flags);
|
2013-09-21 07:29:04 +04:00
|
|
|
|
|
|
|
if (atari_cookie_manager.tv == NULL) {
|
|
|
|
/* handle it properly, clean up previous allocs */
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Failed to allocate treeview");
|
2013-09-21 07:29:04 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
atari_cookie_manager.init = true;
|
2014-05-19 19:53:13 +04:00
|
|
|
}
|
2015-05-28 11:11:32 +03:00
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
void atari_cookie_manager_open(void)
|
|
|
|
{
|
|
|
|
assert(atari_cookie_manager.init);
|
|
|
|
|
|
|
|
if (atari_treeview_is_open(atari_cookie_manager.tv) == false) {
|
|
|
|
|
|
|
|
GRECT pos;
|
|
|
|
pos.g_x = desk_area.g_w - desk_area.g_w / 4;
|
|
|
|
pos.g_y = desk_area.g_y;
|
|
|
|
pos.g_w = desk_area.g_w / 4;
|
|
|
|
pos.g_h = desk_area.g_h;
|
|
|
|
|
|
|
|
atari_treeview_open(atari_cookie_manager.tv, &pos);
|
|
|
|
} else {
|
|
|
|
wind_set(gemtk_wm_get_handle(atari_cookie_manager.window), WF_TOP, 1, 0,
|
|
|
|
0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-19 19:53:13 +04:00
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
void atari_cookie_manager_close(void)
|
|
|
|
{
|
|
|
|
atari_treeview_close(atari_cookie_manager.tv);
|
|
|
|
}
|
|
|
|
|
2014-05-19 19:53:13 +04:00
|
|
|
|
2013-09-21 07:29:04 +04:00
|
|
|
void atari_cookie_manager_destroy(void)
|
|
|
|
{
|
|
|
|
if( atari_cookie_manager.init == false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( atari_cookie_manager.window != NULL ) {
|
|
|
|
if (atari_treeview_is_open(atari_cookie_manager.tv))
|
|
|
|
atari_cookie_manager_close();
|
|
|
|
wind_delete(gemtk_wm_get_handle(atari_cookie_manager.window));
|
|
|
|
gemtk_wm_remove(atari_cookie_manager.window);
|
|
|
|
atari_cookie_manager.window = NULL;
|
|
|
|
atari_treeview_delete(atari_cookie_manager.tv);
|
|
|
|
atari_cookie_manager.init = false;
|
|
|
|
}
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("done");
|
2013-09-21 07:29:04 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void atari_cookie_manager_redraw(void)
|
|
|
|
{
|
|
|
|
atari_treeview_redraw(atari_cookie_manager.tv);
|
|
|
|
}
|