summaryrefslogtreecommitdiff
path: root/atari/cookies.c
blob: 6019b47301b4632ccb0b9aa389901099a370f432 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
 * 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/>.
 */

#include <assert.h>

#include "utils/log.h"
#include "utils/messages.h"
#include "desktop/mouse.h"
#include "desktop/plotters.h"
#include "desktop/cookie_manager.h"
#include "desktop/core_window.h"

#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
};


static nserror
atari_cookie_manager_init_phase2(struct core_window *cw,
                                 struct core_window_callback_table *cb_t)
{
	LOG("cw %p",cw);
	return(cookie_manager_init(cb_t, cw));
}


static void
atari_cookie_manager_finish(struct core_window *cw)
{
	LOG("cw %p",cw);
	cookie_manager_fini();
}


static void
atari_cookie_manager_draw(struct core_window *cw,
                          int x, int y,
                          struct rect *clip,
                          const struct redraw_context *ctx)
{
	cookie_manager_redraw(x, y, clip, ctx);
}


static void
atari_cookie_manager_keypress(struct core_window *cw, uint32_t ucs4)
{
	LOG("ucs4: %"PRIu32, ucs4);
	cookie_manager_keypress(ucs4);
}


static void
atari_cookie_manager_mouse_action(struct core_window *cw,
                                  browser_mouse_state mouse,
                                  int x, int y)
{
	cookie_manager_mouse_action(mouse, x, y);
}



static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
{
	short retval = 0;

	LOG("win %p", win);

	if (ev_out->emo_events & MU_MESAG) {
		switch (msg[0]) {

			case WM_TOOLBAR:
				LOG("WM_TOOLBAR");
			break;

			case WM_CLOSED:
				atari_cookie_manager_close();
				retval = 1;
			break;

			default: break;
		}
	}

	return(retval);
}

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,
										NULL, flags);

			if (atari_cookie_manager.tv == NULL) {
				/* handle it properly, clean up previous allocs */
				LOG("Failed to allocate treeview");
				return;
			}

		} else {

		}
	}
	atari_cookie_manager.init = true;
}

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);
	}
}


void atari_cookie_manager_close(void)
{
	atari_treeview_close(atari_cookie_manager.tv);
}


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;
	}
	LOG("done");

}


void atari_cookie_manager_redraw(void)
{
	atari_treeview_redraw(atari_cookie_manager.tv);
}