-
Notifications
You must be signed in to change notification settings - Fork 4
/
icon.c
3229 lines (2512 loc) · 63.9 KB
/
icon.c
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Teradesk. Copyright (c) 1993 - 2002 W. Klaren,
* 2002 - 2003 H. Robbers,
* 2003 - 2017 Dj. Vukovic
*
* This file is part of Teradesk.
*
* Teradesk 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; either version 2 of the License, or
* (at your option) any later version.
*
* Teradesk 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 Teradesk; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA
*/
#include <library.h>
#include <xdialog.h>
#include "resource.h"
#include "stringf.h"
#include "desk.h"
#include "error.h"
#include "events.h"
#include "open.h"
#include "file.h"
#include "lists.h"
#include "slider.h"
#include "xfilesys.h"
#include "copy.h"
#include "config.h"
#include "font.h"
#include "window.h" /* before dir.h and viewer.h */
#include "showinfo.h"
#include "dir.h"
#include "icon.h"
#include "icontype.h"
#include "prgtype.h"
#include "screen.h"
#include "viewer.h"
#include "video.h"
#include "filetype.h" /* must be before applik.h */
#include "applik.h"
#include "rsc_load.h"
typedef enum
{
ICN_NO_UPDATE,
ICN_REDRAW,
ICN_DELETE
} ICNUPDTYPE;
typedef struct
{
_WORD x; /* position on the desktop */
_WORD y; /* position on the desktop */
_WORD icon_index; /* index in the list of icons */
union
{
_WORD drv; /* disk volume (partition) name */
char *name; /* file/folder name to which this icon applies */
} icon_dat;
INAME label; /* text in icon label */
INAME icon_name; /* name of this icon in the resource file */
ITMTYPE item_type; /* item type of the object to which this icon applies */
ITMTYPE tgt_type; /* type of the target object if this obect is a link */
ICNUPDTYPE update;
bool link; /* true if the icon represents a symbolic link */
bool selected; /* true if icon is selected */
bool newstate; /* new selected/deselected state */
} ICON; /* Data for one desktop icon */
typedef struct
{
VLNAME name;
ICON ic;
} ICONINFO;
typedef struct
{
ITM_INTVARS;
} DSK_WINDOW;
OBJECT *icons; /* use rsrc_load for icons. */
OBJECT *desktop; /* desktop background object */
WINDOW *desk_window; /* pointer to desktop background window */
XDINFO icd_info;
_WORD *icon_data;
_WORD iconw = ICON_W; /* icon sell size */
_WORD iconh = ICON_H; /* icon cell size */
_WORD sl_noop; /* if 1, do not open icon dialog- it is already open */
_WORD n_icons; /* number of icons in the icons file */
INAME iname;
static OBJECT **svicntree;
static void *svicnrshdr;
static ICON *desk_icons; /* An array of desktop ICONs */
static XUSERBLK dxub;
static _WORD m_icnx;
static _WORD m_icny;
static _WORD icn_xoff = 0;
static _WORD icn_yoff = 0;
static _WORD max_icons;
static ITMTYPE icd_itm_type; /* type of an item entered by name in the dialog */
static ITMTYPE icd_tgt_type;
static bool icd_islink;
bool noicons = FALSE;
static void dsk_diskicons(_WORD *x, _WORD *y, _WORD ic, char *name);
static void dsk_do_update(void);
static void set_dsk_obtype(_WORD type);
static _WORD dsk_defaultpatt(void);
static _WORD chng_icon(_WORD object);
static void redraw_icon(_WORD object, _WORD mode);
/*
* Functions that apply to desktop window
*/
static WD_FUNC dsk_functions = {
0L, /* handle keypress */
wd_hndlbutton, /* handle button */
0L, /* redraw */
xw_nop1, /* topped */
xw_nop1, /* bottomed */
xw_nop1, /* newtop */
0L, /* closed */
0L, /* fulled */
xw_nop2, /* arrowed */
0L, /* hslid */
0L, /* vslid */
0L, /* sized */
0L, /* moved */
0L, /* hndlmenu */
0L, /* top */
0L, /* iconify */
0L /* uniconify */
};
/*
* Functions that apply to desktop items
*/
static _WORD icn_find(WINDOW *w, _WORD x, _WORD y);
static bool icn_state(WINDOW *w, _WORD icon);
static ITMTYPE icn_type(WINDOW *w, _WORD icon);
static ITMTYPE icn_tgttype(WINDOW *w, _WORD icon);
static const char *icn_name(WINDOW *w, _WORD icon);
static char *icn_fullname(WINDOW *w, _WORD icon);
static _WORD icn_attrib(WINDOW *w, _WORD icon, _WORD mode, XATTR *attrib);
static bool icn_islink(WINDOW *w, _WORD icon);
static bool icn_open(WINDOW *w, _WORD item, _WORD kstate);
static bool icn_copy(WINDOW *dw, _WORD dobject, WINDOW *sw, _WORD n, _WORD *list, ICND *icns, _WORD x, _WORD y,
_WORD kstate);
static void icn_rselect(WINDOW *w, _WORD x, _WORD y);
static ICND *icn_xlist(WINDOW *w, _WORD *nselected, _WORD *nvisible, _WORD **sel_list, _WORD mx, _WORD my);
static _WORD *icn_list(WINDOW *w, _WORD *nselected);
static void icn_set_update(WINDOW *w, wd_upd_type type, const char *fname1, const char *fname2);
static void icn_do_update(WINDOW *w);
static void icn_select(WINDOW *w, _WORD selected, _WORD mode, bool draw);
static ITMFUNC itm_func = {
icn_find, /* itm_find */
icn_state, /* itm_state */
icn_type, /* itm_type */
icn_tgttype, /* target object type */
icn_name, /* itm_name */
icn_fullname, /* itm_fullname */
icn_attrib, /* itm_attrib */
icn_islink, /* itm_islink */
icn_open, /* itm_open */
icn_copy, /* itm_copy */
icn_select, /* itm_select */
icn_rselect, /* itm_rselect */
icn_xlist, /* itm_xlist */
icn_list, /* itm_list */
0L, /* wd_path */
icn_set_update, /* wd_set_update */
icn_do_update, /* wd_do_update */
0L /* wd_seticons */
};
/*
* Mouse form (like a small icon) for placing a desktop icon
*/
static const MFORM icnm = {
8, 8, 1, 1, 0,
{ 0x1FF8, 0x1008, 0x1008, 0x1008, 0x1008, 0x1008, 0x1008, 0x1008,
0x1008, 0x1008, 0x1008, 0x1008, 0xF00F, 0x8001, 0x8001, 0xFFFF },
{ 0x0000, 0x0FF0, 0x0FF0, 0x0FF0, 0x0FF0, 0x0FF0, 0x0FF0, 0x0FF0,
0x0FF0, 0x0FF0, 0x0FF0, 0x0FF0, 0x0FF0, 0x7FFE, 0x7FFE, 0x0000 }
};
/*
* Funktie voor het opnieuw tekenen van de desktop.
*/
static void form_dialall(_WORD what)
{
form_dial(what, xd_desk.g_x, xd_desk.g_y, xd_desk.g_w, xd_desk.g_h, xd_desk.g_x, xd_desk.g_y, xd_desk.g_w, xd_desk.g_h);
}
void dsk_draw(void)
{
form_dialall(FMD_START);
form_dialall(FMD_FINISH);
}
/*
* Some toutines to manipulate setting desktop icon grid
*/
static _WORD icn_atoi(_WORD obj)
{
return atoi(wdoptions[obj].ob_spec.tedinfo->te_ptext);
}
static void icn_itoa(_WORD val, _WORD obj)
{
itoa(val, wdoptions[obj].ob_spec.tedinfo->te_ptext, 10);
}
static void set_maxicons(void)
{
m_icnx = (xd_desk.g_w - icn_xoff) / iconw - 1;
m_icny = (xd_desk.g_h - icn_yoff) / iconh - 1;
}
/*
* A routine to set desktop icons in a new grid
*/
static void put_newgrid(void)
{
_WORD i;
ICON *icn = desk_icons;
OBJECT *deskto = &desktop[1];
for (i = 0; i < max_icons; i++)
{
if (icn->item_type != ITM_NOTUSED)
{
redraw_icon(i, 1); /* erase at old position */
if (icn->x > m_icnx)
icn->x = m_icnx;
if (icn->y > m_icny)
icn->y = m_icny;
deskto->ob_x = icn->x * iconw + icn_xoff;
deskto->ob_y = icn->y * iconh + icn_yoff;
redraw_icon(i, 2); /* draw at new position */
}
deskto++;
icn++;
}
}
/*
* Determine whether an icon item is a file/folder/program/link or not.
* This is determined by analyzing the stored item type, not by
* actually inquiring the item represented by the icon.
*/
bool isfile(ITMTYPE type)
{
return type == ITM_FILE || type == ITM_PROGRAM || type == ITM_FOLDER || type == ITM_LINK;
}
/*
* Similar to above, but includes network objects
*/
static bool isfilenet(ITMTYPE type)
{
return (isfile(type) || type == ITM_NETOB);
}
/*
* Increment position for placing an icon on the screen.
* Start a new row if right edge of screen reached.
*/
static void incr_pos(_WORD *x, _WORD *y)
{
if ((*x += 1) > m_icnx)
{
*x = 0;
*y += 1;
}
}
/*
* Hide an object (e.g. "Skip" button) is there is only one
* object selected in a list
*/
void hideskip(_WORD n, OBJECT *obj)
{
if (n < 2)
{
obj->ob_flags |= OF_HIDETREE;
} else
{
obj->ob_flags &= ~OF_HIDETREE;
}
}
/*
* Set desktop icon type correctly for executable files (programs)
* and also for network objects.
* This is needed after changes in the list of executable filetypes,
* or after a link is made to reference a network object.
* Beware that, if desktop icons reference items on currently nonexistent
* disk volumes, any program-type items on those locations will be
* degraded to ordinary files.
*/
void icn_fix_ictype(void)
{
ICON *ic;
XATTR att;
_WORD i;
ic = desk_icons;
for (i = 0; i < max_icons; i++)
{
/* Is this either ITM_FILE or ITM_PROGRAM (not a folder) ? */
if (isfileprog(ic->item_type))
{
char *tgtname = x_fllink(ic->icon_dat.name);
/* Is either this or the target item an executable file type ? */
#if _MINT_
if (ic->link && x_netob(tgtname))
{
ic->item_type = ITM_FILE;
ic->tgt_type = ITM_NETOB;
} else
#endif
{
if ((x_attr(1, x_inq_xfs(tgtname), tgtname, &att) >= 0) && dir_isexec(fn_get_name(tgtname), &att))
{
ic->tgt_type = ITM_PROGRAM;
#if _MINT_
if (!ic->link)
#endif
ic->item_type = ITM_PROGRAM;
} else
{
/* Maybe this was a program once, but now is just a file */
ic->item_type = ITM_FILE;
ic->tgt_type = ITM_FILE;
}
}
free(tgtname);
}
ic++;
}
}
/*
* Redraw icons that may be partially obscured by other objects
*/
void draw_icrects(WINDOW *w, OBJECT *tree, GRECT *r1)
{
GRECT r2, d;
xw_getfirst(w, &r2);
while (r2.g_w != 0 && r2.g_h != 0)
{
if (xd_rcintersect(r1, &r2, &d))
draw_tree(tree, &d);
xw_getnext(w, &r2);
}
}
#define WF_OWNER 20
/*
* Redraw part of the desktop.
*/
void redraw_desk(GRECT *r1)
{
_WORD owner = 0;
bool redraw = TRUE;
xd_begupdate();
/* In newer (multitasking) systems, redraw only what is owned by the desktop ? */
/* Should this perhaps be 399 or 340 instead of 400 ? (i.e. Magic & Falcon TOS) */
if (aes_version >= 0x399)
{
wind_get_int(0, WF_OWNER, &owner);
if (ap_id != owner)
redraw = FALSE;
}
/* Actually redraw... */
if (redraw)
draw_icrects(NULL, desktop, r1);
xd_endupdate();
}
/*
* Erase and/or draw an icon
* mode=1: erase, mode=2: draw, mode=3: redraw (erase, then draw)
*/
static void redraw_icon(_WORD object, _WORD mode)
{
GRECT r;
_WORD o1 = object + 1;
xd_objrect(desktop, o1, &r);
if ((mode & 1) != 0)
{
desktop[o1].ob_flags = OF_HIDETREE;
redraw_desk(&r);
desktop[o1].ob_flags = OF_NONE;
}
if ((mode & 2) != 0)
redraw_desk(&r);
}
/*
* routines voor selecteren/deselecteren van iconen
* mode = 0 : deselect all, select selected
* 1 : toggle selected
* 2 : deselect selected
* 3 : select selected
*/
static void dsk_setnws(void)
{
ICON *icn;
_WORD i;
icn = desk_icons;
for (i = 0; i < max_icons; i++)
{
if (icn->item_type != ITM_NOTUSED)
icn->selected = icn->newstate;
icn++;
}
}
/*
* Draw/redraw selected or deselected icons, i.e. those the state of which
* has changed. In order to improve speed, a summary surrounding rectangle
* for all changed icons is computed and then all icons are redrawn
* by one call to objc_draw, without redrawing the background.
* In case of colour icons, which may be animated and change their outline,
* this is not satisfactory. In that case, draw each icon separately
* including the background- which is noticeably slower.
* Monochrome icons are treated like the colour ones if TeraDesk is set
* for display of background pictures.
*/
static void dsk_drawsel(void)
{
ICON *icn; /* pointer to current icon */
OBJECT *deskti;
_WORD i; /* object counter */
GRECT c; /* icon object rectangle */
GRECT r = { SHRT_MAX, SHRT_MAX, -1, -1}; /* summary rectangle */
icn = desk_icons;
set_dsk_obtype(G_IBOX);
for (i = 1; i <= max_icons; i++)
{
deskti = &desktop[i];
if (icn->item_type != ITM_NOTUSED)
{
if (icn->selected == icn->newstate)
{
/* State has not changed; hide the icon temporarily */
obj_hide(desktop[i]);
} else
{
/* State has changed; draw the icon */
if (icn->newstate)
deskti->ob_state |= OS_SELECTED;
else
deskti->ob_state &= ~OS_SELECTED;
xd_objrect(desktop, i, &c);
if (colour_icons || (options.dsk_colour == 0))
{
/* Draw each colour icon separately, -with background- */
set_dsk_obtype(G_BOX);
redraw_desk(&c);
} else
{
/* For monochrome, update surrounding rectangle for all icons */
if (c.g_x < r.g_x) /* left edge minimum */
r.g_x = c.g_x;
if (c.g_y < r.g_y) /* upper edge minimum */
r.g_y = c.g_y;
c.g_x += deskti->ob_width - 1;
c.g_y += deskti->ob_height - 1;
if (c.g_x > r.g_w) /* right edge maximum */
r.g_w = c.g_x;
if (c.g_y > r.g_h) /* lower edge maximum */
r.g_h = c.g_y;
}
}
}
icn++;
}
/* This will happen only for mono icons */
if (r.g_w >= 0)
{
r.g_w -= r.g_x + 1;
r.g_h -= r.g_y + 1;
redraw_desk(&r);
}
/* Set temporarily hidden icons to visible again */
icn = desk_icons;
for (i = 0; i < max_icons; i++)
{
if (icn->item_type != ITM_NOTUSED)
obj_unhide(desktop[i + 1]);
icn++;
}
set_dsk_obtype(G_BOX);
}
/*
* Compute rubberbox rectangle. Beware of asymmetrical wind_update()
*/
void rubber_rect(_WORD x1, _WORD x2, _WORD y1, _WORD y2, GRECT *r)
{
_WORD h;
arrow_mouse();
xd_endmctrl();
if ((h = x2 - x1) < 0)
{
r->g_x = x2;
r->g_w = 1 - h;
} else
{
r->g_x = x1;
r->g_w = h + 1;
}
if ((h = y2 - y1) < 0)
{
r->g_y = y2;
r->g_h = 1 - h;
} else
{
r->g_y = y1;
r->g_h = h + 1;
}
}
/*
* A size-saving aux. function for setting-up rubberbox drawing
* Beware of asymmetrical wind_update()
*/
void start_rubberbox(void)
{
set_rect_default();
xd_begmctrl();
graf_mouse(POINT_HAND, NULL);
}
/*
* Rubberbox function
*/
static void rubber_box(_WORD x, _WORD y, GRECT *r)
{
_WORD x1, x2, ox, y1, y2, oy, kstate;
bool released;
x1 = x2 = ox = x;
y1 = y2 = oy = y;
start_rubberbox();
draw_rect(x1, y1, x2, y2);
/* Loop until mouse button is released */
do
{
released = xe_mouse_event(0, &x2, &y2, &kstate);
/* Menu bar is inaccessible */
if (y2 < xd_desk.g_y)
y2 = xd_desk.g_y;
if (released || (x2 != ox) || (y2 != oy))
{
draw_rect(x1, y1, ox, oy);
if (!released)
{
draw_rect(x1, y1, x2, y2);
ox = x2;
oy = y2;
}
}
} while (!released);
rubber_rect(x1, x2, y1, y2, r);
}
/*
* Change the selection state of some items
* mode = 0: select selected and deselect the rest.
* mode = 1: invert the status of selected.
* mode = 2: deselect selected.
* mode = 3: select selected.
* mode = 4: select all (maybe)
* External consideration is needed for mode 4
*/
void changestate(_WORD mode, bool *newstate, _WORD i, _WORD selected, bool iselected, bool iselected4)
{
switch (mode)
{
case 0:
*newstate = (i == selected) ? TRUE : FALSE;
break;
case 1:
*newstate = iselected;
break;
case 2:
*newstate = (i == selected) ? FALSE : iselected;
break;
case 3:
*newstate = (i == selected) ? TRUE : iselected;
break;
case 4:
*newstate = iselected4;
break;
}
}
/*
* Externe funkties voor iconen.
*/
static void icn_select(WINDOW *w, _WORD selected, _WORD mode, bool draw)
{
_WORD i;
ICON *icn = desk_icons;
(void) w;
/* Newstates after the switch below is equal to selection state of all icons */
for (i = 0; i < max_icons; i++)
{
if (icn->item_type != ITM_NOTUSED)
changestate(mode, &(icn->newstate), i, selected, icn->selected, TRUE);
icn++;
}
if (mode == 1)
desk_icons[selected].newstate = (desk_icons[selected].selected) ? FALSE : TRUE;
if (draw)
dsk_drawsel();
dsk_setnws();
}
static void icn_rselect(WINDOW *w, _WORD x, _WORD y)
{
ICONBLK *monoblk;
OBJECT *deskto;
ICON *icn;
GRECT r1, r2;
_WORD ox, oy, i;
(void) w;
icn = desk_icons;
rubber_box(x, y, &r1);
for (i = 1; i <= max_icons; i++)
{
deskto = &desktop[i];
if (icn->item_type != ITM_NOTUSED)
{
monoblk = &(deskto->ob_spec.ciconblk->monoblk);
r2.g_x = monoblk->ib_xicon;
r2.g_y = monoblk->ib_yicon;
r2.g_w = monoblk->ib_wicon;
r2.g_h = monoblk->ib_hicon;
ox = desktop[0].ob_x + deskto->ob_x;
oy = desktop[0].ob_y + deskto->ob_y;
r2.g_x += ox;
r2.g_y += oy;
if (rc_intersect2(&r1, &r2))
{
icn->newstate = !icn->selected;
} else
{
r2.g_x = monoblk->ib_xtext;
r2.g_y = monoblk->ib_ytext;
r2.g_w = monoblk->ib_wtext;
r2.g_h = monoblk->ib_htext;
r2.g_x += ox;
r2.g_y += oy;
if (rc_intersect2(&r1, &r2))
icn->newstate = !icn->selected;
else
icn->newstate = icn->selected;
}
}
icn++;
}
dsk_drawsel();
dsk_setnws();
}
/*
* Check if a desktop icon is used and selected
*/
static bool dsk_isselected(_WORD i)
{
return ((desk_icons[i].item_type != ITM_NOTUSED) && desk_icons[i].selected);
}
/*
* Count the selected desktop icons
*/
#if 0
static void icn_nselected(WINDOW *w, _WORD *n, _WORD *sel)
{
_WORD i, s, c = 0;
(void) w;
for (i = 0; i < max_icons; i++)
{
if (dsk_isselected(i))
{
c++;
s = i;
}
}
*n = c;
*sel = (c == 1) ? s : -1;
}
#endif
/*
* Note: WINDOW *w parameter is not used in the following functions
* but must exist because these are ITMFUNCs
*/
static bool icn_state(WINDOW *w, _WORD icon)
{
(void) w;
return desk_icons[icon].selected;
}
/*
* Return type of a desktop icon item
*/
static ITMTYPE icn_type(WINDOW *w, _WORD icon)
{
(void) w;
return desk_icons[icon].item_type;
}
/*
* Return type of the target object of a desktop icon
*/
static ITMTYPE icn_tgttype(WINDOW *w, _WORD icon)
{
(void) w;
return desk_icons[icon].tgt_type;
}
/*
* Return pointer to the name of a (desktop) object
*/
static const char *icn_name(WINDOW *w, _WORD icon)
{
ICON *icn = &desk_icons[icon];
/*
* "name" must exist after return from this function and be
* sufficiently long to accomodate string MDRVNAME + drive letter
*/
static char name[20];
(void) w;
if (isfile(icn->item_type))
{
/* this is a file, folder, program or link- treat as a file(name) */
return fn_get_name(icn->icon_dat.name);
} else
{
if (icn->item_type == ITM_DRIVE)
{
/* this is a disk volume. Return text "drive X" */
sprintf(name, get_freestring(MDRVNAME), (char) icn->icon_dat.drv);
return name;
} else if (icn->item_type == ITM_NETOB)
{
return icn->icon_dat.name;
}
}
return NULL;
}
/*
* Return the identification of the icon for an object given by name.
* This routine is used when assigning window icons from desktop ones.
*/
_WORD icn_iconid(const char *name)
{
_WORD i;
ICON *icn = desk_icons;
if (name)
{
for (i = 0; i < max_icons; i++)
{
if (isfile(icn->item_type))
{
if (strcmp(name, icn->icon_dat.name) == 0)
return icn->icon_index;
}
icn++;
}
}
return -1;
}
/*
* Get fullname of an object to which the icon has been assigned.
* When an item can not have a name, or there is an error, return NULL
* (i.e. only files, folders, programs and disk volumes can have fullnames).
* This routine allocates space for the name.
*/
static char *icn_fullname(WINDOW *w, _WORD icon)
{
ICON *icn = &desk_icons[icon];
char *s = NULL;
(void) w;
if (icn->item_type == ITM_DRIVE)
{
if ((s = strdup(adrive)) != NULL)
*s = icn->icon_dat.drv;
} else if (isfilenet(icn->item_type))
{
s = strdup(icn->icon_dat.name);
}
return s;
}