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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
|
/*
* Copyright 2010 Chris Young <chris@unsatisfactorysoftware.co.uk>
*
* 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 "amiga/os3support.h"
#include <string.h>
#include <proto/clicktab.h>
#include <proto/datatypes.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/graphics.h>
#include <proto/icon.h>
#include <proto/intuition.h>
#include <gadgets/clicktab.h>
#include <gadgets/space.h>
#ifdef __amigaos4__
#include <graphics/blitattr.h>
#endif
#include <intuition/pointerclass.h>
#include <workbench/icon.h>
#include "utils/messages.h"
#include "utils/nsoption.h"
#include "utils/utils.h"
#include "desktop/searchweb.h"
#include "desktop/mouse.h"
#include "desktop/gui_window.h"
#include "amiga/gui.h"
#include "amiga/drag.h"
#include "amiga/bitmap.h"
#include "amiga/schedule.h"
#include "amiga/theme.h"
struct BitMap *throbber = NULL;
struct bitmap *throbber_nsbm = NULL;
int throbber_frames, throbber_update_interval;
static Object *mouseptrobj[AMI_LASTPOINTER+1];
static struct BitMap *mouseptrbm[AMI_LASTPOINTER+1];
const char *ptrs[AMI_LASTPOINTER+1] = {
"ptr_default",
"ptr_point",
"ptr_caret",
"ptr_menu",
"ptr_up",
"ptr_down",
"ptr_left",
"ptr_right",
"ptr_rightup",
"ptr_leftdown",
"ptr_leftup",
"ptr_rightdown",
"ptr_cross",
"ptr_move",
"ptr_wait",
"ptr_help",
"ptr_nodrop",
"ptr_notallowed",
"ptr_progress",
"ptr_blank",
"ptr_drag"};
const char *ptrs32[AMI_LASTPOINTER+1] = {
"ptr32_default",
"ptr32_point",
"ptr32_caret",
"ptr32_menu",
"ptr32_up",
"ptr32_down",
"ptr32_left",
"ptr32_right",
"ptr32_rightup",
"ptr32_leftdown",
"ptr32_leftup",
"ptr32_rightdown",
"ptr32_cross",
"ptr32_move",
"ptr32_wait",
"ptr32_help",
"ptr32_nodrop",
"ptr32_notallowed",
"ptr32_progress",
"ptr32_blank",
"ptr32_drag"};
#ifdef __amigaos4__
/* Mapping from NetSurf to AmigaOS mouse pointers */
int osmouseptr[AMI_LASTPOINTER+1] = {
POINTERTYPE_NORMAL,
POINTERTYPE_LINK,
POINTERTYPE_TEXT,
POINTERTYPE_CONTEXTMENU,
POINTERTYPE_NORTHRESIZE,
POINTERTYPE_SOUTHRESIZE,
POINTERTYPE_WESTRESIZE,
POINTERTYPE_EASTRESIZE,
POINTERTYPE_NORTHEASTRESIZE,
POINTERTYPE_SOUTHWESTRESIZE,
POINTERTYPE_NORTHWESTRESIZE,
POINTERTYPE_SOUTHEASTRESIZE,
POINTERTYPE_CROSS,
POINTERTYPE_HAND,
POINTERTYPE_BUSY,
POINTERTYPE_HELP,
POINTERTYPE_NODROP,
POINTERTYPE_NOTALLOWED,
POINTERTYPE_PROGRESS,
POINTERTYPE_NONE,
POINTERTYPE_DRAGANDDROP};
#endif
void ami_theme_init(void)
{
char themefile[1024];
BPTR lock = 0;
strcpy(themefile,nsoption_charp(theme));
AddPart(themefile,"Theme",100);
lock = Lock(themefile,ACCESS_READ);
if(!lock)
{
warn_user("ThemeApplyErr",nsoption_charp(theme));
strcpy(themefile,"PROGDIR:Resources/Themes/Default/Theme");
nsoption_set_charp(theme, (char *)strdup("PROGDIR:Resources/Themes/Default"));
}
else
{
UnLock(lock);
}
lock = Lock(themefile,ACCESS_READ);
if(lock)
{
UnLock(lock);
messages_load(themefile);
}
}
void ami_theme_throbber_setup(void)
{
char throbberfile[1024];
struct bitmap *bm;
ami_get_theme_filename(throbberfile,"theme_throbber",false);
throbber_frames=atoi(messages_get("theme_throbber_frames"));
throbber_update_interval = atoi(messages_get("theme_throbber_delay"));
if(throbber_update_interval == 0) throbber_update_interval = 250;
bm = ami_bitmap_from_datatype(throbberfile);
throbber = ami_bitmap_get_native(bm, bm->width, bm->height, NULL);
throbber_width = bm->width / throbber_frames;
throbber_height = bm->height;
throbber_nsbm = bm;
}
void ami_theme_throbber_free(void)
{
bitmap_destroy(throbber_nsbm);
throbber = NULL;
}
void ami_get_theme_filename(char *filename, const char *themestring, bool protocol)
{
if(protocol)
strcpy(filename,"file:///");
else
strcpy(filename,"");
if(messages_get(themestring)[0] == '*')
{
strncat(filename,messages_get(themestring)+1,100);
}
else
{
strcat(filename, nsoption_charp(theme));
AddPart(filename, messages_get(themestring), 100);
}
}
void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape)
{
ami_set_pointer(g->shared, shape, true);
}
void ami_set_pointer(struct gui_window_2 *gwin, gui_pointer_shape shape, bool update)
{
if(gwin->mouse_pointer == shape) return;
ami_update_pointer(gwin->win, shape);
if(update == true) gwin->mouse_pointer = shape;
}
/* reset the mouse pointer back to what NetSurf last set it as */
void ami_reset_pointer(struct gui_window_2 *gwin)
{
ami_update_pointer(gwin->win, gwin->mouse_pointer);
}
void ami_update_pointer(struct Window *win, gui_pointer_shape shape)
{
if(drag_save_data) return;
if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 53, 42)) {
#ifdef __amigaos4__
BOOL ptr_delay = FALSE;
if(shape == GUI_POINTER_WAIT) ptr_delay = TRUE;
SetWindowPointer(win,
WA_PointerType, osmouseptr[shape],
WA_PointerDelay, ptr_delay,
TAG_DONE);
#endif
} else {
if(nsoption_bool(os_mouse_pointers))
{
switch(shape)
{
case GUI_POINTER_DEFAULT:
SetWindowPointer(win, TAG_DONE);
break;
case GUI_POINTER_WAIT:
SetWindowPointer(win,
WA_BusyPointer, TRUE,
WA_PointerDelay, TRUE,
TAG_DONE);
break;
default:
if(mouseptrobj[shape]) {
SetWindowPointer(win, WA_Pointer, mouseptrobj[shape], TAG_DONE);
} else {
SetWindowPointer(win, TAG_DONE);
}
break;
}
}
else
{
if(mouseptrobj[shape])
{
SetWindowPointer(win, WA_Pointer, mouseptrobj[shape], TAG_DONE);
}
else
{
if(shape == GUI_POINTER_WAIT)
{
SetWindowPointer(win,
WA_BusyPointer, TRUE,
WA_PointerDelay, TRUE,
TAG_DONE);
}
else
{
SetWindowPointer(win, TAG_DONE);
}
}
}
}
}
void ami_init_mouse_pointers(void)
{
if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 53, 42)) return;
int i;
struct RastPort mouseptr;
struct DiskObject *dobj;
uint32 format = IDFMT_BITMAPPED;
int32 mousexpt=0,mouseypt=0;
InitRastPort(&mouseptr);
for(i=0; i<=AMI_LASTPOINTER; i++) {
BPTR ptrfile;
mouseptrbm[i] = NULL;
mouseptrobj[i] = NULL;
char ptrfname[1024];
#ifdef __amigaos4__
if(nsoption_bool(truecolour_mouse_pointers)) {
ami_get_theme_filename((char *)&ptrfname,ptrs32[i], false);
if((dobj = GetIconTags(ptrfname,ICONGETA_UseFriendBitMap,TRUE,TAG_DONE))) {
if(IconControl(dobj, ICONCTRLA_GetImageDataFormat, &format, TAG_DONE)) {
if(IDFMT_DIRECTMAPPED == format) {
int32 width = 0, height = 0;
uint8* data = 0;
IconControl(dobj,
ICONCTRLA_GetWidth, &width,
ICONCTRLA_GetHeight, &height,
ICONCTRLA_GetImageData1, &data,
TAG_DONE);
if ((width > 0) && (width <= 64) && (height > 0) && (height <= 64) && data) {
STRPTR tooltype;
if((tooltype = FindToolType(dobj->do_ToolTypes, "XOFFSET")))
mousexpt = atoi(tooltype);
if((tooltype = FindToolType(dobj->do_ToolTypes, "YOFFSET")))
mouseypt = atoi(tooltype);
if ((mousexpt < 0) || (mousexpt >= width))
mousexpt = 0;
if ((mouseypt < 0) || (mouseypt >= height))
mouseypt = 0;
static uint8 dummyPlane[64 * 64 / 8];
static struct BitMap dummyBitMap = { 64 / 8, 64, 0, 2, 0, { dummyPlane, dummyPlane, 0, 0, 0, 0, 0, 0 }, };
mouseptrobj[i] = NewObject(NULL, "pointerclass",
POINTERA_BitMap, &dummyBitMap,
POINTERA_XOffset, -mousexpt,
POINTERA_YOffset, -mouseypt,
POINTERA_WordWidth, (width + 15) / 16,
POINTERA_XResolution, POINTERXRESN_SCREENRES,
POINTERA_YResolution, POINTERYRESN_SCREENRESASPECT,
POINTERA_ImageData, data,
POINTERA_Width, width,
POINTERA_Height, height,
TAG_DONE);
}
}
}
}
}
#endif
if(!mouseptrobj[i])
{
ami_get_theme_filename(ptrfname,ptrs[i], false);
if((ptrfile = Open(ptrfname,MODE_OLDFILE)))
{
int mx,my;
UBYTE *pprefsbuf = AllocVecTagList(1061, NULL);
Read(ptrfile,pprefsbuf,1061);
mouseptrbm[i]=AllocVecTagList(sizeof(struct BitMap), NULL);
InitBitMap(mouseptrbm[i],2,32,32);
mouseptrbm[i]->Planes[0] = AllocRaster(32,32);
mouseptrbm[i]->Planes[1] = AllocRaster(32,32);
mouseptr.BitMap = mouseptrbm[i];
for(my=0;my<32;my++)
{
for(mx=0;mx<32;mx++)
{
SetAPen(&mouseptr,pprefsbuf[(my*(33))+mx]-'0');
WritePixel(&mouseptr,mx,my);
}
}
mousexpt = ((pprefsbuf[1056]-'0')*10)+(pprefsbuf[1057]-'0');
mouseypt = ((pprefsbuf[1059]-'0')*10)+(pprefsbuf[1060]-'0');
mouseptrobj[i] = NewObject(NULL,"pointerclass",
POINTERA_BitMap,mouseptrbm[i],
POINTERA_WordWidth,2,
POINTERA_XOffset,-mousexpt,
POINTERA_YOffset,-mouseypt,
POINTERA_XResolution,POINTERXRESN_SCREENRES,
POINTERA_YResolution,POINTERYRESN_SCREENRESASPECT,
TAG_DONE);
FreeVec(pprefsbuf);
Close(ptrfile);
}
}
} // for
}
void ami_mouse_pointers_free(void)
{
if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 53, 42)) return;
int i;
for(i=0;i<=AMI_LASTPOINTER;i++)
{
if(mouseptrbm[i])
{
FreeRaster(mouseptrbm[i]->Planes[0],32,32);
FreeRaster(mouseptrbm[i]->Planes[1],32,32);
FreeVec(mouseptrbm[i]);
}
}
}
void gui_window_start_throbber(struct gui_window *g)
{
if(!g) return;
if(nsoption_bool(kiosk_mode)) return;
#ifdef __amigaos4__
if(g->tab_node && (g->shared->tabs > 1))
{
SetClickTabNodeAttrs(g->tab_node, TNA_Flagged, TRUE, TAG_DONE);
RefreshGadgets((APTR)g->shared->objects[GID_TABS],
g->shared->win, NULL);
}
#endif
g->throbbing = true;
if(g->shared->throbber_frame == 0) g->shared->throbber_frame = 1;
ami_throbber_redraw_schedule(throbber_update_interval, g);
}
void gui_window_stop_throbber(struct gui_window *g)
{
struct IBox *bbox;
if(!g) return;
if(nsoption_bool(kiosk_mode)) return;
#ifdef __amigaos4__
if(g->tab_node && (g->shared->tabs > 1))
{
SetClickTabNodeAttrs(g->tab_node, TNA_Flagged, FALSE, TAG_DONE);
RefreshGadgets((APTR)g->shared->objects[GID_TABS],
g->shared->win, NULL);
}
#endif
if(g == g->shared->gw) {
if(ami_gui_get_space_box(g->shared->objects[GID_THROBBER], &bbox) != NSERROR_OK) {
warn_user("NoMemory", "");
return;
}
BltBitMapRastPort(throbber, 0, 0, g->shared->win->RPort, bbox->Left,
bbox->Top, throbber_width, throbber_height, 0x0C0);
ami_gui_free_space_box(bbox);
}
g->throbbing = false;
ami_throbber_redraw_schedule(-1, g);
}
static void ami_throbber_update(void *p)
{
struct gui_window *g = (struct gui_window *)p;
struct IBox *bbox;
int frame = 0;
if(!g) return;
if(!g->shared->objects[GID_THROBBER]) return;
if(g->throbbing == true) {
frame = g->shared->throbber_frame;
g->shared->throbber_frame++;
if(g->shared->throbber_frame > (throbber_frames-1))
g->shared->throbber_frame=1;
}
if(g->shared->gw == g) {
if(ami_gui_get_space_box(g->shared->objects[GID_THROBBER], &bbox) != NSERROR_OK) {
warn_user("NoMemory", "");
return;
}
#ifdef __amigaos4__
BltBitMapTags(BLITA_SrcX, throbber_width * frame,
BLITA_SrcY, 0,
BLITA_DestX, bbox->Left,
BLITA_DestY, bbox->Top,
BLITA_Width, throbber_width,
BLITA_Height, throbber_height,
BLITA_Source, throbber,
BLITA_Dest, g->shared->win->RPort,
BLITA_SrcType, BLITT_BITMAP,
BLITA_DestType, BLITT_RASTPORT,
// BLITA_UseSrcAlpha, TRUE,
TAG_DONE);
#else
BltBitMapRastPort(throbber, throbber_width * frame, 0, g->shared->win->RPort,
bbox->Left, bbox->Top, throbber_width, throbber_height, 0xC0);
#endif
ami_gui_free_space_box(bbox);
}
if(frame > 0) ami_throbber_redraw_schedule(throbber_update_interval, g);
}
void ami_throbber_redraw_schedule(int t, struct gui_window *g)
{
ami_schedule(t, ami_throbber_update, g);
}
|