Subversion Repositories Kolibri OS

Rev

Rev 4364 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4364 Rev 5043
1
/*
1
/*
2
 * Copyright 2010 Vincent Sanders 
2
 * Copyright 2010 Vincent Sanders 
3
 *
3
 *
4
 * Framebuffer windowing toolkit scrollbar widgets
4
 * Framebuffer windowing toolkit scrollbar widgets
5
 *
5
 *
6
 * This file is part of NetSurf, http://www.netsurf-browser.org/
6
 * This file is part of NetSurf, http://www.netsurf-browser.org/
7
 *
7
 *
8
 * NetSurf is free software; you can redistribute it and/or modify
8
 * NetSurf is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; version 2 of the License.
10
 * the Free Software Foundation; version 2 of the License.
11
 *
11
 *
12
 * NetSurf is distributed in the hope that it will be useful,
12
 * NetSurf is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
15
 * GNU General Public License for more details.
16
 *
16
 *
17
 * You should have received a copy of the GNU General Public License
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see .
18
 * along with this program.  If not, see .
19
 */
19
 */
20
 
20
 
21
 
21
 
22
#include 
22
#include 
23
 
23
 
24
#include 
24
#include 
25
#include 
25
#include 
26
#include 
26
#include 
27
#include 
27
#include 
28
 
28
 
29
#include "utils/log.h"
29
#include "utils/log.h"
30
#include "desktop/browser.h"
30
#include "desktop/browser.h"
31
 
31
 
32
#include "framebuffer/gui.h"
32
#include "framebuffer/gui.h"
33
#include "framebuffer/fbtk.h"
33
#include "framebuffer/fbtk.h"
34
#include "framebuffer/image_data.h"
34
#include "framebuffer/image_data.h"
35
 
35
 
36
 
36
 
37
 
37
 
38
#include "utils/log.h"
38
#include "utils/log.h"
39
#include 
39
#include 
40
 
40
 
41
#include "widget.h"
41
#include "widget.h"
-
 
42
 
-
 
43
#ifdef DBG
-
 
44
#undef DBG
-
 
45
#endif
-
 
46
//#define DBG(s) __menuet__debug_out(s) /* For the debug messages in BOARD */
-
 
47
#define DBG(s) LOG((s))            /* So that we see debug in Netsurf's LOG files */
42
 
48
 
43
/* Vertical scroll widget */
49
/* Vertical scroll widget */
44
 
50
 
45
static int
51
static int
46
vscroll_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi)
52
vscroll_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi)
47
{
53
{
48
		LOG(("REDRAW SCROLL"));
54
		LOG(("REDRAW SCROLL"));
49
	//__menuet__debug_out("REDRAW SCROLL");
55
	//DBG("REDRAW SCROLL");
50
	int vscroll;
56
	int vscroll;
51
	int vpos;
57
	int vpos;
52
 
58
 
53
	nsfb_bbox_t bbox;
59
	nsfb_bbox_t bbox;
54
	nsfb_bbox_t rect;
60
	nsfb_bbox_t rect;
55
	
61
	
56
			LOG(("REDRAW SCROLL get rooot"));
62
			LOG(("REDRAW SCROLL get rooot"));
57
	//__menuet__debug_out("REDRAW SCROLL get root");
63
	//DBG("REDRAW SCROLL get root");
58
	fbtk_widget_t *root = fbtk_get_root_widget(widget);
64
	fbtk_widget_t *root = fbtk_get_root_widget(widget);
59
 
65
 
60
 
66
 
61
		LOG(("REDRAW SCROLL get bbox"));
67
		LOG(("REDRAW SCROLL get bbox"));
62
	//__menuet__debug_out("REDRAW SCROLL get bbox");
68
	//DBG("REDRAW SCROLL get bbox");
63
	fbtk_get_bbox(widget, &bbox);
69
	fbtk_get_bbox(widget, &bbox);
64
 
70
 
65
		LOG(("REDRAW SCROLL claim"));
71
		LOG(("REDRAW SCROLL claim"));
66
	//__menuet__debug_out("REDRAW SCROLL claim");
72
	//DBG("REDRAW SCROLL claim");
67
	nsfb_claim(root->u.root.fb, &bbox);
73
	nsfb_claim(root->u.root.fb, &bbox);
68
 
74
 
69
	rect = bbox;
75
	rect = bbox;
70
 
76
 
71
	/* background */
77
	/* background */
72
	//STUB
78
	//STUB
73
	
79
	
74
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
80
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
75
 
81
 
76
	/* scroll well */
82
	/* scroll well */
77
	rect.x0 = bbox.x0 + 2;
83
	rect.x0 = bbox.x0 + 2;
78
	rect.y0 = bbox.y0 + 1;
84
	rect.y0 = bbox.y0 + 1;
79
	rect.x1 = bbox.x1 - 3;
85
	rect.x1 = bbox.x1 - 3;
80
	rect.y1 = bbox.y1 - 2;
86
	rect.y1 = bbox.y1 - 2;
81
 
87
 
82
 
88
 
83
	//STUB!!!
89
	//STUB!!!
84
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->fg);
90
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->fg);
85
	nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0xFF999999, false, false);
91
	nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0xFF999999, false, false);
86
 
92
 
87
		LOG(("REDRAW SCROLL widg"));
93
		LOG(("REDRAW SCROLL widg"));
88
	//__menuet__debug_out("REDRAW SCROLL widg");
94
	//DBG("REDRAW SCROLL widg");
89
 
95
 
90
	/* scroll bar */
96
	/* scroll bar */
91
	if ((widget->u.scroll.maximum - widget->u.scroll.minimum) > 0) {
97
	if ((widget->u.scroll.maximum - widget->u.scroll.minimum) > 0) {
92
		vscroll = ((widget->height - 4) * widget->u.scroll.thumb) /
98
		vscroll = ((widget->height - 4) * widget->u.scroll.thumb) /
93
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
99
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
94
		vpos = ((widget->height - 4) * widget->u.scroll.position) /
100
		vpos = ((widget->height - 4) * widget->u.scroll.position) /
95
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
101
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
96
	} else {
102
	} else {
97
		vscroll = (widget->height - 4);
103
		vscroll = (widget->height - 4);
98
		vpos = 0;
104
		vpos = 0;
99
	}
105
	}
100
 
106
 
101
	rect.x0 = bbox.x0 + 5;
107
	rect.x0 = bbox.x0 + 5;
102
	rect.y0 = bbox.y0 + 3 + vpos;
108
	rect.y0 = bbox.y0 + 3 + vpos;
103
	rect.x1 = bbox.x0 + widget->width - 5;
109
	rect.x1 = bbox.x0 + widget->width - 5;
104
	rect.y1 = bbox.y0 + vscroll + vpos;
110
	rect.y1 = bbox.y0 + vscroll + vpos;
105
 
111
 
106
	//STUB!!!
112
	//STUB!!!
107
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
113
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
108
 
114
 
109
		LOG(("REDRAW SCROLL upd"));
115
		LOG(("REDRAW SCROLL upd"));
110
	//__menuet__debug_out("RED upd");
116
	//DBG("RED upd");
111
 
117
 
112
//STUB
118
//STUB
113
	nsfb_update(root->u.root.fb, &bbox); //&bbox 
119
	nsfb_update(root->u.root.fb, &bbox); //&bbox 
114
 
120
 
115
	return 0;
121
	return 0;
116
}
122
}
117
 
123
 
118
static int
124
static int
119
vscroll_drag(fbtk_widget_t *widget, fbtk_callback_info *cbi)
125
vscroll_drag(fbtk_widget_t *widget, fbtk_callback_info *cbi)
120
{
126
{
121
	
127
	
122
		LOG(("REDRAG SCROLL"));
128
		LOG(("REDRAG SCROLL"));
123
	//__menuet__debug_out("REDRAG SCROLL");
129
	//DBG("REDRAG SCROLL");
124
	int newpos;
130
	int newpos;
125
	fbtk_widget_t *scrollw = cbi->context;
131
	fbtk_widget_t *scrollw = cbi->context;
126
 
132
 
127
	newpos = ((widget->u.scroll.drag_position +
133
	newpos = ((widget->u.scroll.drag_position +
128
			(cbi->y - widget->u.scroll.drag)) *
134
			(cbi->y - widget->u.scroll.drag)) *
129
			(widget->u.scroll.maximum - widget->u.scroll.minimum)) /
135
			(widget->u.scroll.maximum - widget->u.scroll.minimum)) /
130
			(widget->height - 4);
136
			(widget->height - 4);
131
 
137
 
132
	if (newpos < scrollw->u.scroll.minimum)
138
	if (newpos < scrollw->u.scroll.minimum)
133
		newpos = scrollw->u.scroll.minimum;
139
		newpos = scrollw->u.scroll.minimum;
134
 
140
 
135
	if (newpos > (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb ))
141
	if (newpos > (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb ))
136
		newpos = (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb);
142
		newpos = (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb);
137
 
143
 
138
	if (newpos == scrollw->u.scroll.position)
144
	if (newpos == scrollw->u.scroll.position)
139
		return 0;
145
		return 0;
140
 
146
 
141
	return fbtk_post_callback(widget, FBTK_CBT_SCROLLY, newpos);
147
	return fbtk_post_callback(widget, FBTK_CBT_SCROLLY, newpos);
142
}
148
}
143
 
149
 
144
static int
150
static int
145
vscrollu_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
151
vscrollu_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
146
{
152
{
147
	
153
	
148
		LOG(("REDRAW Ck SCROLL"));
154
		LOG(("REDRAW Ck SCROLL"));
149
	//__menuet__debug_out("REDRAW Ck SCROLL");
155
	//DBG("REDRAW Ck SCROLL");
150
	int newpos;
156
	int newpos;
151
	fbtk_widget_t *scrollw = cbi->context;
157
	fbtk_widget_t *scrollw = cbi->context;
152
 
158
 
153
	if (cbi->event->type != NSFB_EVENT_KEY_DOWN)
159
	if (cbi->event->type != NSFB_EVENT_KEY_DOWN)
154
		return 0;
160
		return 0;
155
 
161
 
156
	newpos = scrollw->u.scroll.position - scrollw->u.scroll.page;
162
	newpos = scrollw->u.scroll.position - scrollw->u.scroll.page;
157
	if (newpos < scrollw->u.scroll.minimum)
163
	if (newpos < scrollw->u.scroll.minimum)
158
		newpos = scrollw->u.scroll.minimum;
164
		newpos = scrollw->u.scroll.minimum;
159
 
165
 
160
	if (newpos ==  scrollw->u.scroll.position)
166
	if (newpos ==  scrollw->u.scroll.position)
161
		return 0;
167
		return 0;
162
 
168
 
163
	return fbtk_post_callback(scrollw, FBTK_CBT_SCROLLY, newpos);
169
	return fbtk_post_callback(scrollw, FBTK_CBT_SCROLLY, newpos);
164
}
170
}
165
 
171
 
166
static int
172
static int
167
vscrolld_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
173
vscrolld_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
168
{
174
{
169
	
175
	
170
		LOG(("REDRAW SCROLL 2"));
176
		LOG(("REDRAW SCROLL 2"));
171
	//__menuet__debug_out("REDRAW SCROLL 2");
177
	//DBG("REDRAW SCROLL 2");
172
	int newpos;
178
	int newpos;
173
	fbtk_widget_t *scrollw = cbi->context;
179
	fbtk_widget_t *scrollw = cbi->context;
174
 
180
 
175
	if (cbi->event->type != NSFB_EVENT_KEY_DOWN)
181
	if (cbi->event->type != NSFB_EVENT_KEY_DOWN)
176
		return 0;
182
		return 0;
177
 
183
 
178
	newpos = scrollw->u.scroll.position + scrollw->u.scroll.page;
184
	newpos = scrollw->u.scroll.position + scrollw->u.scroll.page;
179
	if (newpos > (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb ))
185
	if (newpos > (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb ))
180
		newpos = (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb);
186
		newpos = (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb);
181
 
187
 
182
	if (newpos == scrollw->u.scroll.position)
188
	if (newpos == scrollw->u.scroll.position)
183
		return 0;
189
		return 0;
184
 
190
 
185
	return fbtk_post_callback(scrollw, FBTK_CBT_SCROLLY, newpos);
191
	return fbtk_post_callback(scrollw, FBTK_CBT_SCROLLY, newpos);
186
}
192
}
187
 
193
 
188
static int
194
static int
189
vscrollarea_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
195
vscrollarea_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
190
{
196
{
191
		LOG(("REDRAW SCROLL 3"));
197
		LOG(("REDRAW SCROLL 3"));
192
	//__menuet__debug_out("REDRAW SCROLL 3");
198
	//DBG("REDRAW SCROLL 3");
193
	int vscroll;
199
	int vscroll;
194
	int vpos;
200
	int vpos;
195
	int newpos;
201
	int newpos;
196
	int ret = 0;
202
	int ret = 0;
197
 
203
 
198
	if (cbi->event->type != NSFB_EVENT_KEY_DOWN) {
204
	if (cbi->event->type != NSFB_EVENT_KEY_DOWN) {
199
		/* end all drags, just in case */
205
		/* end all drags, just in case */
200
		if (fbtk_set_handler(widget, FBTK_CBT_POINTERMOVE, NULL, NULL) != NULL)
206
		if (fbtk_set_handler(widget, FBTK_CBT_POINTERMOVE, NULL, NULL) != NULL)
201
			fbtk_tgrab_pointer(widget);
207
			fbtk_tgrab_pointer(widget);
202
		return 0;
208
		return 0;
203
	}
209
	}
204
 
210
 
205
	switch (cbi->event->value.keycode) {
211
	switch (cbi->event->value.keycode) {
206
 
212
 
207
	case NSFB_KEY_MOUSE_4:
213
	case NSFB_KEY_MOUSE_4:
208
		/* scroll up */
214
		/* scroll up */
209
		newpos = widget->u.scroll.position - widget->u.scroll.page;
215
		newpos = widget->u.scroll.position - widget->u.scroll.page;
210
		if (newpos < widget->u.scroll.minimum)
216
		if (newpos < widget->u.scroll.minimum)
211
			newpos = widget->u.scroll.minimum;
217
			newpos = widget->u.scroll.minimum;
212
		ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, newpos);
218
		ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, newpos);
213
		break;
219
		break;
214
 
220
 
215
	case NSFB_KEY_MOUSE_5:
221
	case NSFB_KEY_MOUSE_5:
216
		/* scroll down */
222
		/* scroll down */
217
		newpos = widget->u.scroll.position + widget->u.scroll.page;
223
		newpos = widget->u.scroll.position + widget->u.scroll.page;
218
		if (newpos > widget->u.scroll.maximum)
224
		if (newpos > widget->u.scroll.maximum)
219
			newpos = widget->u.scroll.maximum;
225
			newpos = widget->u.scroll.maximum;
220
		ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, newpos);
226
		ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, newpos);
221
		break;
227
		break;
222
 
228
 
223
	default:
229
	default:
224
 
230
 
225
		if ((widget->u.scroll.maximum - widget->u.scroll.minimum) > 0) {
231
		if ((widget->u.scroll.maximum - widget->u.scroll.minimum) > 0) {
226
			vscroll = ((widget->height - 4) * widget->u.scroll.thumb) /
232
			vscroll = ((widget->height - 4) * widget->u.scroll.thumb) /
227
				(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
233
				(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
228
			vpos = ((widget->height - 4) * widget->u.scroll.position) /
234
			vpos = ((widget->height - 4) * widget->u.scroll.position) /
229
				(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
235
				(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
230
		} else {
236
		} else {
231
			vscroll = (widget->height - 4);
237
			vscroll = (widget->height - 4);
232
			vpos = 0;
238
			vpos = 0;
233
		}
239
		}
234
 
240
 
235
		if (cbi->y < vpos) {
241
		if (cbi->y < vpos) {
236
			/* above bar */
242
			/* above bar */
237
			newpos = widget->u.scroll.position - widget->u.scroll.thumb;
243
			newpos = widget->u.scroll.position - widget->u.scroll.thumb;
238
			if (newpos < widget->u.scroll.minimum)
244
			if (newpos < widget->u.scroll.minimum)
239
				newpos = widget->u.scroll.minimum;
245
				newpos = widget->u.scroll.minimum;
240
			ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, newpos);
246
			ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, newpos);
241
		} else if (cbi->y > (vpos + vscroll)) {
247
		} else if (cbi->y > (vpos + vscroll)) {
242
			/* below bar */
248
			/* below bar */
243
			newpos = widget->u.scroll.position + widget->u.scroll.thumb;
249
			newpos = widget->u.scroll.position + widget->u.scroll.thumb;
244
			if (newpos > widget->u.scroll.maximum)
250
			if (newpos > widget->u.scroll.maximum)
245
				newpos = widget->u.scroll.maximum;
251
				newpos = widget->u.scroll.maximum;
246
			ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, newpos);
252
			ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, newpos);
247
		} else {
253
		} else {
248
			/* on bar - start drag */
254
			/* on bar - start drag */
249
			widget->u.scroll.drag = cbi->y;
255
			widget->u.scroll.drag = cbi->y;
250
			widget->u.scroll.drag_position = vpos;
256
			widget->u.scroll.drag_position = vpos;
251
			fbtk_set_handler(widget, FBTK_CBT_POINTERMOVE, vscroll_drag, widget);
257
			fbtk_set_handler(widget, FBTK_CBT_POINTERMOVE, vscroll_drag, widget);
252
			fbtk_tgrab_pointer(widget);
258
			fbtk_tgrab_pointer(widget);
253
		}
259
		}
254
	}
260
	}
255
	return ret;
261
	return ret;
256
}
262
}
257
 
263
 
258
 
264
 
259
/* exported function documented in fbtk.h */
265
/* exported function documented in fbtk.h */
260
fbtk_widget_t *
266
fbtk_widget_t *
261
fbtk_create_vscroll(fbtk_widget_t *parent,
267
fbtk_create_vscroll(fbtk_widget_t *parent,
262
		    int x,
268
		    int x,
263
		    int y,
269
		    int y,
264
		    int width,
270
		    int width,
265
		    int height,
271
		    int height,
266
		    colour fg,
272
		    colour fg,
267
		    colour bg,
273
		    colour bg,
268
		    fbtk_callback callback,
274
		    fbtk_callback callback,
269
		    void *context)
275
		    void *context)
270
{
276
{
271
	
277
	
272
		LOG(("REDRAW SCROLL 4"));
278
		LOG(("REDRAW SCROLL 4"));
273
	//__menuet__debug_out("REDRAW SCROLL 4");
279
	//DBG("REDRAW SCROLL 4");
274
	fbtk_widget_t *neww;
280
	fbtk_widget_t *neww;
275
 
281
 
276
	neww = fbtk_widget_new(parent,
282
	neww = fbtk_widget_new(parent,
277
			       FB_WIDGET_TYPE_VSCROLL,
283
			       FB_WIDGET_TYPE_VSCROLL,
278
			       x,
284
			       x,
279
			       y + scrollu.height,
285
			       y + scrollu.height,
280
			       width,
286
			       width,
281
			       height  - scrollu.height - scrolld.height);
287
			       height  - scrollu.height - scrolld.height);
282
 
288
 
283
	neww->fg = fg;
289
	neww->fg = fg;
284
	neww->bg = bg;
290
	neww->bg = bg;
285
	neww->mapped = true;
291
	neww->mapped = true;
286
 
292
 
287
	fbtk_set_handler(neww, FBTK_CBT_REDRAW, vscroll_redraw, NULL);
293
	fbtk_set_handler(neww, FBTK_CBT_REDRAW, vscroll_redraw, NULL);
288
 
294
 
289
	fbtk_set_handler(neww, FBTK_CBT_CLICK, vscrollarea_click, neww);
295
	fbtk_set_handler(neww, FBTK_CBT_CLICK, vscrollarea_click, neww);
290
 
296
 
291
	fbtk_set_handler(neww, FBTK_CBT_SCROLLY, callback, context);
297
	fbtk_set_handler(neww, FBTK_CBT_SCROLLY, callback, context);
292
 
298
 
293
	neww->u.scroll.btnul = fbtk_create_button(parent,
299
	neww->u.scroll.btnul = fbtk_create_button(parent,
294
						  x,
300
						  x,
295
						  y,
301
						  y,
296
						  width,
302
						  width,
297
						  scrollu.height,
303
						  scrollu.height,
298
						  fg,
304
						  fg,
299
						  &scrollu,
305
						  &scrollu,
300
						  vscrollu_click,
306
						  vscrollu_click,
301
						  neww);
307
						  neww);
302
 
308
 
303
	neww->u.scroll.btndr = fbtk_create_button(parent,
309
	neww->u.scroll.btndr = fbtk_create_button(parent,
304
						  x,
310
						  x,
305
						  y + height - scrolld.height,
311
						  y + height - scrolld.height,
306
						  width,
312
						  width,
307
						  scrolld.height,
313
						  scrolld.height,
308
						  fg,
314
						  fg,
309
						  &scrolld,
315
						  &scrolld,
310
						  vscrolld_click,
316
						  vscrolld_click,
311
						  neww);
317
						  neww);
312
 
318
 
313
 
319
 
314
	return neww;
320
	return neww;
315
}
321
}
316
 
322
 
317
/* Horizontal scroll widget */
323
/* Horizontal scroll widget */
318
 
324
 
319
static int
325
static int
320
hscroll_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi)
326
hscroll_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi)
321
{
327
{
322
	
328
	
323
		LOG(("REDRAW SCROLL 5"));
329
		LOG(("REDRAW SCROLL 5"));
324
	//__menuet__debug_out("REDRAW SCROLL 5");
330
	//DBG("REDRAW SCROLL 5");
325
	int hscroll;
331
	int hscroll;
326
	int hpos;
332
	int hpos;
327
	nsfb_bbox_t bbox;
333
	nsfb_bbox_t bbox;
328
	nsfb_bbox_t rect;
334
	nsfb_bbox_t rect;
329
	fbtk_widget_t *root = fbtk_get_root_widget(widget);
335
	fbtk_widget_t *root = fbtk_get_root_widget(widget);
330
 
336
 
331
	fbtk_get_bbox(widget, &bbox);
337
	fbtk_get_bbox(widget, &bbox);
332
 
338
 
333
	nsfb_claim(root->u.root.fb, &bbox);
339
	nsfb_claim(root->u.root.fb, &bbox);
334
 
340
 
335
	rect = bbox;
341
	rect = bbox;
336
 
342
 
337
	/* background */
343
	/* background */
338
	
344
	
339
	//STUB
345
	//STUB
340
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
346
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
341
 
347
 
342
	/* scroll well */
348
	/* scroll well */
343
	rect.x0 = bbox.x0 + 1;
349
	rect.x0 = bbox.x0 + 1;
344
	rect.y0 = bbox.y0 + 2;
350
	rect.y0 = bbox.y0 + 2;
345
	rect.x1 = bbox.x1 - 2;
351
	rect.x1 = bbox.x1 - 2;
346
	rect.y1 = bbox.y1 - 3;
352
	rect.y1 = bbox.y1 - 3;
347
	
353
	
348
	//STUB
354
	//STUB
349
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->fg);
355
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->fg);
350
 
356
 
351
	/* scroll well outline */
357
	/* scroll well outline */
352
	//STUB
358
	//STUB
353
	nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0xFF999999, false, false);
359
	nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0xFF999999, false, false);
354
 
360
 
355
	if ((widget->u.scroll.maximum - widget->u.scroll.minimum) > 0) {
361
	if ((widget->u.scroll.maximum - widget->u.scroll.minimum) > 0) {
356
		hscroll = ((widget->width - 4) * widget->u.scroll.thumb) /
362
		hscroll = ((widget->width - 4) * widget->u.scroll.thumb) /
357
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
363
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
358
		hpos = ((widget->width - 4) * widget->u.scroll.position) /
364
		hpos = ((widget->width - 4) * widget->u.scroll.position) /
359
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
365
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
360
	} else {
366
	} else {
361
		hscroll = (widget->width - 4);
367
		hscroll = (widget->width - 4);
362
		hpos = 0;
368
		hpos = 0;
363
	}
369
	}
364
 
370
 
365
	LOG(("hscroll %d", hscroll));
371
	LOG(("hscroll %d", hscroll));
366
 
372
 
367
	rect.x0 = bbox.x0 + 3 + hpos;
373
	rect.x0 = bbox.x0 + 3 + hpos;
368
	rect.y0 = bbox.y0 + 5;
374
	rect.y0 = bbox.y0 + 5;
369
	rect.x1 = bbox.x0 + hscroll + hpos;
375
	rect.x1 = bbox.x0 + hscroll + hpos;
370
	rect.y1 = bbox.y0 + widget->height - 5;
376
	rect.y1 = bbox.y0 + widget->height - 5;
371
 
377
 
372
 
378
 
373
	//STUB
379
	//STUB
374
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
380
	nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
375
 
381
 
376
	nsfb_update(root->u.root.fb, &bbox);
382
	nsfb_update(root->u.root.fb, &bbox);
377
 
383
 
378
	return 0;
384
	return 0;
379
}
385
}
380
 
386
 
381
static int
387
static int
382
hscrolll_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
388
hscrolll_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
383
{
389
{
384
	
390
	
385
		LOG(("REDRAW SCROLL 6"));
391
		LOG(("REDRAW SCROLL 6"));
386
	//__menuet__debug_out("REDRAW SCROLL 6");
392
	//DBG("REDRAW SCROLL 6");
387
	int newpos;
393
	int newpos;
388
	fbtk_widget_t *scrollw = cbi->context;
394
	fbtk_widget_t *scrollw = cbi->context;
389
 
395
 
390
	if (cbi->event->type != NSFB_EVENT_KEY_DOWN)
396
	if (cbi->event->type != NSFB_EVENT_KEY_DOWN)
391
		return 0;
397
		return 0;
392
 
398
 
393
	newpos = scrollw->u.scroll.position - scrollw->u.scroll.page;
399
	newpos = scrollw->u.scroll.position - scrollw->u.scroll.page;
394
	if (newpos < scrollw->u.scroll.minimum)
400
	if (newpos < scrollw->u.scroll.minimum)
395
		newpos = scrollw->u.scroll.minimum;
401
		newpos = scrollw->u.scroll.minimum;
396
 
402
 
397
	if (newpos == scrollw->u.scroll.position) {
403
	if (newpos == scrollw->u.scroll.position) {
398
		LOG(("horiz scroll was the same %d", newpos));
404
		LOG(("horiz scroll was the same %d", newpos));
399
		return 0;
405
		return 0;
400
	}
406
	}
401
 
407
 
402
	return fbtk_post_callback(scrollw, FBTK_CBT_SCROLLX, newpos);
408
	return fbtk_post_callback(scrollw, FBTK_CBT_SCROLLX, newpos);
403
}
409
}
404
 
410
 
405
static int
411
static int
406
hscrollr_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
412
hscrollr_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
407
{
413
{
408
	
414
	
409
		LOG(("REDRAW SCROLL 7"));
415
		LOG(("REDRAW SCROLL 7"));
410
	//__menuet__debug_out("REDRAW SCROLL 7");
416
	//DBG("REDRAW SCROLL 7");
411
	int newpos;
417
	int newpos;
412
	fbtk_widget_t *scrollw = cbi->context;
418
	fbtk_widget_t *scrollw = cbi->context;
413
 
419
 
414
	if (cbi->event->type != NSFB_EVENT_KEY_DOWN)
420
	if (cbi->event->type != NSFB_EVENT_KEY_DOWN)
415
		return 0;
421
		return 0;
416
 
422
 
417
	newpos = scrollw->u.scroll.position + scrollw->u.scroll.page;
423
	newpos = scrollw->u.scroll.position + scrollw->u.scroll.page;
418
	if (newpos > (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb ))
424
	if (newpos > (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb ))
419
		newpos = (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb);
425
		newpos = (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb);
420
 
426
 
421
	if (newpos == scrollw->u.scroll.position)
427
	if (newpos == scrollw->u.scroll.position)
422
		return 0;
428
		return 0;
423
 
429
 
424
	return fbtk_post_callback(scrollw, FBTK_CBT_SCROLLX, newpos);
430
	return fbtk_post_callback(scrollw, FBTK_CBT_SCROLLX, newpos);
425
}
431
}
426
 
432
 
427
static int
433
static int
428
hscroll_drag(fbtk_widget_t *widget, fbtk_callback_info *cbi)
434
hscroll_drag(fbtk_widget_t *widget, fbtk_callback_info *cbi)
429
{
435
{
430
	
436
	
431
		LOG(("REDRAW SCROLL 8"));
437
		LOG(("REDRAW SCROLL 8"));
432
	//__menuet__debug_out("REDRAW SCROLL 8");
438
	//DBG("REDRAW SCROLL 8");
433
	int newpos;
439
	int newpos;
434
	fbtk_widget_t *scrollw = cbi->context;
440
	fbtk_widget_t *scrollw = cbi->context;
435
 
441
 
436
	newpos = ((widget->u.scroll.drag_position +
442
	newpos = ((widget->u.scroll.drag_position +
437
			(cbi->x - widget->u.scroll.drag)) *
443
			(cbi->x - widget->u.scroll.drag)) *
438
			(widget->u.scroll.maximum - widget->u.scroll.minimum)) /
444
			(widget->u.scroll.maximum - widget->u.scroll.minimum)) /
439
			(widget->width - 4);
445
			(widget->width - 4);
440
 
446
 
441
	if (newpos < scrollw->u.scroll.minimum)
447
	if (newpos < scrollw->u.scroll.minimum)
442
		newpos = scrollw->u.scroll.minimum;
448
		newpos = scrollw->u.scroll.minimum;
443
 
449
 
444
	if (newpos > (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb ))
450
	if (newpos > (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb ))
445
		newpos = (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb);
451
		newpos = (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb);
446
 
452
 
447
	if (newpos == scrollw->u.scroll.position)
453
	if (newpos == scrollw->u.scroll.position)
448
		return 0;
454
		return 0;
449
 
455
 
450
	return fbtk_post_callback(widget, FBTK_CBT_SCROLLX, newpos);
456
	return fbtk_post_callback(widget, FBTK_CBT_SCROLLX, newpos);
451
}
457
}
452
 
458
 
453
static int
459
static int
454
hscrollarea_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
460
hscrollarea_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
455
{
461
{
456
	
462
	
457
		LOG(("REDRAW SCROLL 9"));
463
		LOG(("REDRAW SCROLL 9"));
458
	//__menuet__debug_out("REDRAW SCROLL 9");
464
	//DBG("REDRAW SCROLL 9");
459
	int hscroll;
465
	int hscroll;
460
	int hpos;
466
	int hpos;
461
	int newpos;
467
	int newpos;
462
	int ret = 0;
468
	int ret = 0;
463
 
469
 
464
	if (cbi->event->type != NSFB_EVENT_KEY_DOWN) {
470
	if (cbi->event->type != NSFB_EVENT_KEY_DOWN) {
465
		/* end all drags, just in case */
471
		/* end all drags, just in case */
466
		if (fbtk_set_handler(widget, FBTK_CBT_POINTERMOVE, NULL, NULL) != NULL)
472
		if (fbtk_set_handler(widget, FBTK_CBT_POINTERMOVE, NULL, NULL) != NULL)
467
			fbtk_tgrab_pointer(widget);
473
			fbtk_tgrab_pointer(widget);
468
		return 0;
474
		return 0;
469
	}
475
	}
470
 
476
 
471
	if ((widget->u.scroll.maximum - widget->u.scroll.minimum) > 0) {
477
	if ((widget->u.scroll.maximum - widget->u.scroll.minimum) > 0) {
472
		hscroll = ((widget->width - 4) * widget->u.scroll.thumb) /
478
		hscroll = ((widget->width - 4) * widget->u.scroll.thumb) /
473
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
479
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
474
		hpos = ((widget->width - 4) * widget->u.scroll.position) /
480
		hpos = ((widget->width - 4) * widget->u.scroll.position) /
475
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
481
			(widget->u.scroll.maximum - widget->u.scroll.minimum) ;
476
	} else {
482
	} else {
477
		hscroll = (widget->width - 4);
483
		hscroll = (widget->width - 4);
478
		hpos = 0;
484
		hpos = 0;
479
	}
485
	}
480
 
486
 
481
	if (cbi->x < hpos) {
487
	if (cbi->x < hpos) {
482
		/* left of  bar */
488
		/* left of  bar */
483
		newpos = widget->u.scroll.position - widget->u.scroll.page;
489
		newpos = widget->u.scroll.position - widget->u.scroll.page;
484
		if (newpos < widget->u.scroll.minimum)
490
		if (newpos < widget->u.scroll.minimum)
485
			newpos = widget->u.scroll.minimum;
491
			newpos = widget->u.scroll.minimum;
486
		ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLX, newpos);
492
		ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLX, newpos);
487
	} else if (cbi->x > (hpos + hscroll)) {
493
	} else if (cbi->x > (hpos + hscroll)) {
488
		/* right of bar */
494
		/* right of bar */
489
		newpos = widget->u.scroll.position + widget->u.scroll.page;
495
		newpos = widget->u.scroll.position + widget->u.scroll.page;
490
		if (newpos > widget->u.scroll.maximum)
496
		if (newpos > widget->u.scroll.maximum)
491
			newpos = widget->u.scroll.maximum;
497
			newpos = widget->u.scroll.maximum;
492
		ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLX, newpos);
498
		ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLX, newpos);
493
	} else {
499
	} else {
494
		/* on bar - start drag */
500
		/* on bar - start drag */
495
		widget->u.scroll.drag = cbi->x;
501
		widget->u.scroll.drag = cbi->x;
496
		widget->u.scroll.drag_position = hpos;
502
		widget->u.scroll.drag_position = hpos;
497
		fbtk_set_handler(widget, FBTK_CBT_POINTERMOVE, hscroll_drag, widget);
503
		fbtk_set_handler(widget, FBTK_CBT_POINTERMOVE, hscroll_drag, widget);
498
		fbtk_tgrab_pointer(widget);
504
		fbtk_tgrab_pointer(widget);
499
	}
505
	}
500
	return ret;
506
	return ret;
501
}
507
}
502
 
508
 
503
/* exported function documented in fbtk.h */
509
/* exported function documented in fbtk.h */
504
fbtk_widget_t *
510
fbtk_widget_t *
505
fbtk_create_hscroll(fbtk_widget_t *parent,
511
fbtk_create_hscroll(fbtk_widget_t *parent,
506
		    int x,
512
		    int x,
507
		    int y,
513
		    int y,
508
		    int width,
514
		    int width,
509
		    int height,
515
		    int height,
510
		    colour fg,
516
		    colour fg,
511
		    colour bg,
517
		    colour bg,
512
		    fbtk_callback callback,
518
		    fbtk_callback callback,
513
		    void *context)
519
		    void *context)
514
{
520
{
515
	
521
	
516
		LOG(("REDRAW SCROLL 10"));
522
		LOG(("REDRAW SCROLL 10"));
517
	//__menuet__debug_out("REDRAW SCROLL 10");
523
	//DBG("REDRAW SCROLL 10");
518
	fbtk_widget_t *neww;
524
	fbtk_widget_t *neww;
519
 
525
 
520
	neww = fbtk_widget_new(parent,
526
	neww = fbtk_widget_new(parent,
521
			       FB_WIDGET_TYPE_HSCROLL,
527
			       FB_WIDGET_TYPE_HSCROLL,
522
			       x + scrolll.width,
528
			       x + scrolll.width,
523
			       y,
529
			       y,
524
			       width - scrolll.width - scrollr.width,
530
			       width - scrolll.width - scrollr.width,
525
			       height);
531
			       height);
526
 
532
 
527
	neww->fg = fg;
533
	neww->fg = fg;
528
	neww->bg = bg;
534
	neww->bg = bg;
529
	neww->mapped = true;
535
	neww->mapped = true;
530
 
536
 
531
	fbtk_set_handler(neww, FBTK_CBT_REDRAW, hscroll_redraw, NULL);
537
	fbtk_set_handler(neww, FBTK_CBT_REDRAW, hscroll_redraw, NULL);
532
	fbtk_set_handler(neww, FBTK_CBT_CLICK, hscrollarea_click, neww);
538
	fbtk_set_handler(neww, FBTK_CBT_CLICK, hscrollarea_click, neww);
533
	fbtk_set_handler(neww, FBTK_CBT_SCROLLX, callback, context);
539
	fbtk_set_handler(neww, FBTK_CBT_SCROLLX, callback, context);
534
 
540
 
535
	neww->u.scroll.btnul = fbtk_create_button(parent,
541
	neww->u.scroll.btnul = fbtk_create_button(parent,
536
						  x,
542
						  x,
537
						  y,
543
						  y,
538
						  scrolll.width,
544
						  scrolll.width,
539
						  height,
545
						  height,
540
						  fg,
546
						  fg,
541
						  &scrolll,
547
						  &scrolll,
542
						  hscrolll_click,
548
						  hscrolll_click,
543
						  neww);
549
						  neww);
544
 
550
 
545
	neww->u.scroll.btndr = fbtk_create_button(parent,
551
	neww->u.scroll.btndr = fbtk_create_button(parent,
546
						  x + width - scrollr.width,
552
						  x + width - scrollr.width,
547
						  y,
553
						  y,
548
						  scrollr.width,
554
						  scrollr.width,
549
						  height,
555
						  height,
550
						  fg,
556
						  fg,
551
						  &scrollr,
557
						  &scrollr,
552
						  hscrollr_click,
558
						  hscrollr_click,
553
						  neww);
559
						  neww);
554
 
560
 
555
	return neww;
561
	return neww;
556
}
562
}
557
 
563
 
558
 
564
 
559
/* exported function documented in fbtk.h */
565
/* exported function documented in fbtk.h */
560
bool
566
bool
561
fbtk_set_scroll_parameters(fbtk_widget_t *widget,
567
fbtk_set_scroll_parameters(fbtk_widget_t *widget,
562
			   int min,
568
			   int min,
563
			   int max,
569
			   int max,
564
			   int thumb,
570
			   int thumb,
565
			   int page)
571
			   int page)
566
{
572
{
567
		LOG(("REDRAW SCROLL 11"));
573
		LOG(("REDRAW SCROLL 11"));
568
	//__menuet__debug_out("REDRAW SCROLL 11");
574
	//DBG("REDRAW SCROLL 11");
569
	if (widget == NULL)
575
	if (widget == NULL)
570
		return false;
576
		return false;
571
 
577
 
572
	if ((widget->type != FB_WIDGET_TYPE_HSCROLL) &&
578
	if ((widget->type != FB_WIDGET_TYPE_HSCROLL) &&
573
	    (widget->type != FB_WIDGET_TYPE_VSCROLL))
579
	    (widget->type != FB_WIDGET_TYPE_VSCROLL))
574
		return false;
580
		return false;
575
 
581
 
576
	widget->u.scroll.minimum = min;
582
	widget->u.scroll.minimum = min;
577
	widget->u.scroll.maximum = max;
583
	widget->u.scroll.maximum = max;
578
	widget->u.scroll.thumb = thumb;
584
	widget->u.scroll.thumb = thumb;
579
	widget->u.scroll.page = page;
585
	widget->u.scroll.page = page;
580
 
586
 
581
	if (widget->u.scroll.position > max)
587
	if (widget->u.scroll.position > max)
582
		widget->u.scroll.position = max;
588
		widget->u.scroll.position = max;
583
	if (widget->u.scroll.position < min)
589
	if (widget->u.scroll.position < min)
584
		widget->u.scroll.position = min;
590
		widget->u.scroll.position = min;
585
 
591
 
586
	fbtk_request_redraw(widget);
592
	fbtk_request_redraw(widget);
587
 
593
 
588
	return true;
594
	return true;
589
}
595
}
590
 
596
 
591
/* exported function documented in fbtk.h */
597
/* exported function documented in fbtk.h */
592
bool
598
bool
593
fbtk_set_scroll_position(fbtk_widget_t *widget, int position)
599
fbtk_set_scroll_position(fbtk_widget_t *widget, int position)
594
{
600
{
595
		LOG(("REDRAW SCROLL 12"));
601
		LOG(("REDRAW SCROLL 12"));
596
	//__menuet__debug_out("REDRAW SCROLL 12");
602
	//DBG("REDRAW SCROLL 12");
597
	if (widget == NULL)
603
	if (widget == NULL)
598
		return false;
604
		return false;
599
 
605
 
600
	if ((widget->type != FB_WIDGET_TYPE_HSCROLL) &&
606
	if ((widget->type != FB_WIDGET_TYPE_HSCROLL) &&
601
	    (widget->type != FB_WIDGET_TYPE_VSCROLL))
607
	    (widget->type != FB_WIDGET_TYPE_VSCROLL))
602
		return false;
608
		return false;
603
 
609
 
604
	if ((position < widget->u.scroll.minimum) ||
610
	if ((position < widget->u.scroll.minimum) ||
605
	    (position > widget->u.scroll.maximum))
611
	    (position > widget->u.scroll.maximum))
606
		return false;
612
		return false;
607
 
613
 
608
	widget->u.scroll.position = position;
614
	widget->u.scroll.position = position;
609
 
615
 
610
	fbtk_request_redraw(widget);
616
	fbtk_request_redraw(widget);
611
 
617
 
612
	return true;
618
	return true;
613
}
619
}
614
 
620
 
615
/*
621
/*
616
 * Local Variables:
622
 * Local Variables:
617
 * c-basic-offset:8
623
 * c-basic-offset:8
618
 * End:
624
 * End:
619
 */
625
 */