summaryrefslogtreecommitdiff
path: root/atari/treeview.c
blob: 7ea039c132809f5a4f313907538330c373de2dff (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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*

 * 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 <inttypes.h>
#include <sys/types.h>
#include <string.h>


#include "assert.h"
#include "cflib.h"

#include "utils/nsoption.h"
#include "content/urldb.h"
#include "desktop/browser.h"
#include "desktop/plotters.h"
#include "desktop/mouse.h"
#include "desktop/treeview.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "atari/gui.h"
#include "atari/plot/plot.h"
#include "atari/misc.h"
#include "atari/gemtk/gemtk.h"
#include "atari/treeview.h"


/**
 * Declare Core Window Callbacks:
 */

void atari_treeview_redraw_request(struct core_window *cw,
								const struct rect *r);
void atari_treeview_update_size(struct core_window *cw, int width, int height);
void atari_treeview_scroll_visible(struct core_window *cw,
								const struct rect *r);
void atari_treeview_get_window_dimensions(struct core_window *cw,
		int *width, int *height);
void atari_treeview_drag_status(struct core_window *cw,
		core_window_drag_status ds);


static struct core_window_callback_table cw_t = {
	.redraw_request = atari_treeview_redraw_request,
	.update_size = atari_treeview_update_size,
	.scroll_visible = atari_treeview_scroll_visible,
	.get_window_dimensions = atari_treeview_get_window_dimensions,
	.drag_status = atari_treeview_drag_status
};


struct atari_treeview_window {
	GUIWIN * window;
	bool disposing;
	bool redraw;
	GRECT rdw_area;
	POINT extent;
	POINT click;
	POINT startdrag;
	struct atari_treeview_callbacks *io;
};

typedef struct atari_treeview_window *ATARI_TREEVIEW;


/* native GUI event handlers: */
static void __CDECL on_mbutton_event(struct atari_treeview_window tvw,
									EVMULT_OUT *ev_out, short msg[8]);
static void __CDECL on_keybd_event(struct atari_treeview_window tvw,
									EVMULT_OUT *ev_out, short msg[8]);
static void __CDECL on_redraw_event(struct atari_treeview_window tvw,
									EVMULT_OUT *ev_out, short msg[8]);

/* GEMTK event sink: */
static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
{

}


struct atari_treeview_window *
atari_treeview_create(GUIWIN *win, struct atari_treeview_callbacks * callbacks,
					uint32_t flags)
{
/*
	init_func();

	sslcert_viewer_init(&cw_t, (struct core_window *)tree,
				ssl_current_session);
*/

	/* allocate the core_window struct: */
	struct atari_treeview_window * cw;

	cw = calloc(sizeof(struct atari_treeview_window), 1);
	if (cw == NULL) {
		LOG(("calloc failed"));
		warn_user(messages_get_errorcode(NSERROR_NOMEM), 0);
		return NULL;
	}

	cw->window = win;
	cw->io = callbacks;

	assert(cw->io);
	assert(cw->io->init);

	nserror err = cw->io->init(cw, &cw_t);
	if (err != NSERROR_OK) {
		free(cw);
		cw = NULL;
	}

	return(cw);
}

void atari_treeview_delete(struct atari_treeview_window * cw)
{
	assert(cw);
	assert(cw->io->fini);

	cw->io->fini(cw);

	free(cw);
}



/**
 * Core Window Callbacks:
 */


/**
 * Request a redraw of the window
 *
 * \param cw		the core window object
 * \param r		rectangle to redraw
 */
void atari_treeview_redraw_request(struct core_window *cw, const struct rect *r)
{
	GRECT area;

	RECT_TO_GRECT(r, &area)

	if (cw != NULL) {
		ATARI_TREEVIEW tv = (ATARI_TREEVIEW) cw;
		if( tv->redraw == false ){
			tv->redraw = true;
			tv->rdw_area.g_x = area.g_x;
			tv->rdw_area.g_y = area.g_y;
			tv->rdw_area.g_w = area.g_w;
			tv->rdw_area.g_h = area.g_h;
		} else {
			/* merge the redraw area to the new area.: */
			int newx1 = area.g_x+area.g_w;
			int newy1 = area.g_y+area.g_h;
			int oldx1 = tv->rdw_area.g_x + tv->rdw_area.g_w;
			int oldy1 = tv->rdw_area.g_y + tv->rdw_area.g_h;
			tv->rdw_area.g_x = MIN(tv->rdw_area.g_x, area.g_x);
			tv->rdw_area.g_y = MIN(tv->rdw_area.g_y, area.g_y);
			tv->rdw_area.g_w = ( oldx1 > newx1 ) ? oldx1 - tv->rdw_area.g_x : newx1 - tv->rdw_area.g_x;
			tv->rdw_area.g_h = ( oldy1 > newy1 ) ? oldy1 - tv->rdw_area.g_y : newy1 - tv->rdw_area.g_y;
		}
		// dbg_grect("atari_treeview_request_redraw", &tv->rdw_area);
	}
}

/**
 * Update the limits of the window
 *
 * \param cw		the core window object
 * \param width		the width in px, or negative if don't care
 * \param height	the height in px, or negative if don't care
 */
void atari_treeview_update_size(struct core_window *cw, int width, int height)
{

}


/**
 * Scroll the window to make area visible
 *
 * \param cw		the core window object
 * \param r		rectangle to make visible
 */
void atari_treeview_scroll_visible(struct core_window *cw, const struct rect *r)
{

}


/**
 * Get window viewport dimensions
 *
 * \param cw		the core window object
 * \param width		to be set to viewport width in px, if non NULL
 * \param height	to be set to viewport height in px, if non NULL
 */
void atari_treeview_get_window_dimensions(struct core_window *cw,
		int *width, int *height)
{

}


/**
 * Inform corewindow owner of drag status
 *
 * \param cw		the core window object
 * \param ds		the current drag status
 */
void atari_treeview_drag_status(struct core_window *cw,
		core_window_drag_status ds)
{

}