Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / icon / diskobjio.c
blobb743603e0507230cee13bbb33fed30abcba8c481
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Read an icon from an .info file
6 */
8 #ifdef __MORPHOS__
9 #undef __NOLIBBASE__
10 #endif
12 /****************************************************************************************/
14 #include <stdio.h>
15 #include <stddef.h>
16 #include <string.h>
18 #include <exec/memory.h>
19 #include <aros/bigendianio.h>
20 #include <aros/asmcall.h>
21 #include <aros/macros.h>
22 #include <workbench/workbench.h>
24 #include <proto/alib.h>
25 #include <proto/exec.h>
26 #include <proto/dos.h>
27 #include <proto/arossupport.h>
28 #include <proto/intuition.h>
30 #include "icon_intern.h"
32 # include <aros/debug.h>
34 /****************************************************************************************/
36 AROS_UFP3S(ULONG, ProcessCheckFileType,
37 AROS_UFPA(struct Hook *, hook, A0),
38 AROS_UFPA(struct Hook *, streamhook, A2),
39 AROS_UFPA(struct SDData *, data, A1)
42 AROS_UFP3S(ULONG, ProcessOldDrawerData,
43 AROS_UFPA(struct Hook *, hook, A0),
44 AROS_UFPA(struct Hook *, streamhook, A2),
45 AROS_UFPA(struct SDData *, data, A1)
48 AROS_UFP3S(ULONG, ProcessNewDrawerData,
49 AROS_UFPA(struct Hook *, hook, A0),
50 AROS_UFPA(struct Hook *, streamhook, A2),
51 AROS_UFPA(struct SDData *, data, A1)
54 AROS_UFP3S(ULONG, ProcessGadgetRender,
55 AROS_UFPA(struct Hook *, hook, A0),
56 AROS_UFPA(struct Hook *, streamhook, A2),
57 AROS_UFPA(struct SDData *, data, A1)
60 AROS_UFP3S(ULONG, ProcessSelectRender,
61 AROS_UFPA(struct Hook *, hook, A0),
62 AROS_UFPA(struct Hook *, streamhook, A2),
63 AROS_UFPA(struct SDData *, data, A1)
66 AROS_UFP3S(ULONG, ProcessDefaultTool,
67 AROS_UFPA(struct Hook *, hook, A0),
68 AROS_UFPA(struct Hook *, streamhook, A2),
69 AROS_UFPA(struct SDData *, data, A1)
72 AROS_UFP3S(ULONG, ProcessToolWindow,
73 AROS_UFPA(struct Hook *, hook, A0),
74 AROS_UFPA(struct Hook *, streamhook, A2),
75 AROS_UFPA(struct SDData *, data, A1)
78 AROS_UFP3S(ULONG, ProcessToolTypes,
79 AROS_UFPA(struct Hook *, hook, A0),
80 AROS_UFPA(struct Hook *, streamhook, A2),
81 AROS_UFPA(struct SDData *, data, A1)
84 AROS_UFP3S(ULONG, ProcessFlagPtr,
85 AROS_UFPA(struct Hook *, hook, A0),
86 AROS_UFPA(struct Hook *, streamhook, A2),
87 AROS_UFPA(struct SDData *, data, A1)
90 AROS_UFP3S(ULONG, ProcessIcon35,
91 AROS_UFPA(struct Hook *, hook, A0),
92 AROS_UFPA(struct Hook *, streamhook, A2),
93 AROS_UFPA(struct SDData *, data, A1)
96 AROS_UFP3S(ULONG, ProcessIconNI,
97 AROS_UFPA(struct Hook *, hook, A0),
98 AROS_UFPA(struct Hook *, streamhook, A2),
99 AROS_UFPA(struct SDData *, data, A1)
102 const struct Hook
103 ProcessCheckFileTypeHook =
105 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessCheckFileType), NULL, NULL
107 ProcessOldDrawerDataHook =
109 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessOldDrawerData), NULL, NULL
111 ProcessNewDrawerDataHook =
113 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessNewDrawerData), NULL, NULL
115 ProcessGadgetRenderHook =
117 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessGadgetRender), NULL, NULL
119 ProcessSelectRenderHook =
121 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessSelectRender), NULL, NULL
123 ProcessFlagPtrHook =
125 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessFlagPtr), NULL, NULL
127 ProcessDefaultToolHook =
129 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessDefaultTool), NULL, NULL
131 ProcessToolWindowHook =
133 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessToolWindow), NULL, NULL
135 ProcessToolTypesHook =
137 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessToolTypes), NULL, NULL
139 ProcessIcon35Hook =
141 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessIcon35), NULL, NULL
143 ProcessIconNIHook =
145 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessIconNI), NULL, NULL
148 /****************************************************************************************/
150 #undef O
151 #define O(x) (offsetof (struct Gadget,x))
153 /****************************************************************************************/
155 static const IPTR GadgetDesc[] =
157 sizeof (struct Gadget),
158 SDM_IGNORE(4), /* NextGadget */
159 SDM_WORD(O(LeftEdge)),
160 SDM_WORD(O(TopEdge)),
161 SDM_WORD(O(Width)),
162 SDM_WORD(O(Height)),
163 SDM_UWORD(O(Flags)),
164 SDM_UWORD(O(Activation)),
165 SDM_UWORD(O(GadgetType)),
166 SDM_SPECIAL(O(GadgetRender),&ProcessFlagPtrHook),
167 SDM_SPECIAL(O(SelectRender),&ProcessFlagPtrHook),
168 SDM_SPECIAL(O(GadgetText),&ProcessFlagPtrHook),
169 SDM_LONG(O(MutualExclude)),
170 SDM_SPECIAL(O(SpecialInfo),&ProcessFlagPtrHook),
171 SDM_UWORD(O(GadgetID)),
172 SDM_ULONG(O(UserData)),
173 SDM_END
176 /****************************************************************************************/
178 #undef O
179 #define O(x) (offsetof (struct DiskObject,x))
181 /****************************************************************************************/
183 static const IPTR DiskObjectDesc[] =
185 sizeof (struct DiskObject),
186 SDM_UWORD(O(do_Magic)),
187 SDM_UWORD(O(do_Version)),
188 SDM_STRUCT(O(do_Gadget),GadgetDesc),
189 SDM_UBYTE(O(do_Type)),
190 SDM_IGNORE(1), /* Pad */
191 SDM_SPECIAL(O(do_DefaultTool),&ProcessFlagPtrHook),
192 SDM_SPECIAL(O(do_ToolTypes),&ProcessFlagPtrHook),
193 SDM_LONG(O(do_CurrentX)),
194 SDM_LONG(O(do_CurrentY)),
195 SDM_SPECIAL(O(do_DrawerData),&ProcessFlagPtrHook),
196 SDM_SPECIAL(O(do_ToolWindow),&ProcessFlagPtrHook),
197 SDM_LONG(O(do_StackSize)),
198 SDM_END
201 /****************************************************************************************/
203 #undef O
204 #define O(x) (offsetof (struct Image,x))
206 /****************************************************************************************/
208 static const IPTR ImageDesc[] =
210 sizeof (struct Image),
211 SDM_WORD(O(LeftEdge)),
212 SDM_WORD(O(TopEdge)),
213 SDM_WORD(O(Width)),
214 SDM_WORD(O(Height)),
215 SDM_WORD(O(Depth)),
216 SDM_SPECIAL(O(ImageData),&ProcessFlagPtrHook),
217 SDM_UBYTE(O(PlanePick)),
218 SDM_UBYTE(O(PlaneOnOff)),
219 SDM_SPECIAL(O(NextImage),&ProcessFlagPtrHook),
220 SDM_END
223 /****************************************************************************************/
225 const IPTR IconDesc[] =
227 sizeof (struct NativeIcon),
228 SDM_STRUCT(0,DiskObjectDesc),
229 SDM_SPECIAL(0,&ProcessCheckFileTypeHook),
230 SDM_SPECIAL(0,&ProcessOldDrawerDataHook),
231 SDM_SPECIAL(0,&ProcessGadgetRenderHook),
232 SDM_SPECIAL(0,&ProcessSelectRenderHook),
233 SDM_SPECIAL(0,&ProcessDefaultToolHook),
234 SDM_SPECIAL(0,&ProcessToolTypesHook),
235 SDM_SPECIAL(0,&ProcessToolWindowHook),
236 SDM_SPECIAL(0,&ProcessNewDrawerDataHook),
237 SDM_SPECIAL(0,&ProcessIcon35Hook),
238 SDM_SPECIAL(0,&ProcessIconNIHook),
239 SDM_END
242 /****************************************************************************************/
244 #undef O
245 #define O(x) (offsetof (struct NewWindow,x))
247 /****************************************************************************************/
249 const IPTR NewWindowDesc[] =
251 sizeof (struct NewWindow),
252 SDM_WORD(O(LeftEdge)),
253 SDM_WORD(O(TopEdge)),
254 SDM_WORD(O(Width)),
255 SDM_WORD(O(Height)),
256 SDM_UBYTE(O(DetailPen)),
257 SDM_UBYTE(O(BlockPen)),
258 SDM_ULONG(O(IDCMPFlags)),
259 SDM_ULONG(O(Flags)),
260 SDM_IGNORE(4+4+4+4+4), /* FirstGadget
261 +CheckMark
262 +Title
263 +Screen
264 +BitMap
266 SDM_WORD(O(MinWidth)),
267 SDM_WORD(O(MinHeight)),
268 SDM_UWORD(O(MaxWidth)),
269 SDM_UWORD(O(MaxHeight)),
270 SDM_UWORD(O(Type)),
271 SDM_END
274 /****************************************************************************************/
276 #undef O
277 #define O(x) (offsetof (struct DrawerData,x))
279 /****************************************************************************************/
281 const IPTR OldDrawerDataDesc[] =
283 sizeof (struct DrawerData),
284 SDM_STRUCT(O(dd_NewWindow),NewWindowDesc),
285 SDM_LONG(O(dd_CurrentX)),
286 SDM_LONG(O(dd_CurrentY)),
287 SDM_END
290 /****************************************************************************************/
292 AROS_UFH3(LONG, dosstreamhook,
293 AROS_UFHA(struct Hook *, hook, A0),
294 AROS_UFHA(BPTR, fh, A2),
295 AROS_UFHA(ULONG *, msg, A1)
298 AROS_USERFUNC_INIT
300 struct IconBase *IconBase = hook->h_Data;
302 LONG rc = 0;
304 switch (*msg)
306 case BEIO_READ:
307 rc = FGetC (fh);
308 #if 0
309 kprintf ("dsh: Read: %02X\n", rc);
310 #endif
311 break;
313 case BEIO_WRITE:
314 rc = FPutC (fh, ((struct BEIOM_Write *)msg)->Data);
315 break;
317 case BEIO_IGNORE:
318 Flush (fh);
320 rc = Seek (fh, ((struct BEIOM_Ignore *)msg)->Count, OFFSET_CURRENT);
321 #if 0
322 kprintf ("dsh: Skip %d\n", ((struct BEIOM_Ignore *)msg)->Count);
323 #endif
324 break;
328 return rc;
330 AROS_USERFUNC_EXIT
331 } /* dosstreamhook */
333 /****************************************************************************************/
335 #define DO(x) ((struct DiskObject *)x)
337 /****************************************************************************************/
339 AROS_UFH3S(ULONG, ProcessCheckFileType,
340 AROS_UFHA(struct Hook *, hook, A0),
341 AROS_UFHA(struct Hook *, streamhook, A2),
342 AROS_UFHA(struct SDData *, data, A1)
345 AROS_USERFUNC_INIT
347 struct DiskObject *icon = DO(data->sdd_Dest);
349 if (data->sdd_Mode == SDV_SPECIALMODE_READ)
351 if ((icon->do_Magic != WB_DISKMAGIC))
353 return FALSE;
357 return TRUE;
359 AROS_USERFUNC_EXIT
363 /****************************************************************************************/
365 AROS_UFH3S(ULONG, ProcessOldDrawerData,
366 AROS_UFHA(struct Hook *, hook, A0),
367 AROS_UFHA(struct Hook *, streamhook, A2),
368 AROS_UFHA(struct SDData *, data, A1)
371 AROS_USERFUNC_INIT
373 APTR ptr;
374 struct IconBase *IconBase = streamhook->h_Data;
375 struct DiskObject *icon = DO(data->sdd_Dest);
377 #if 0
378 kprintf ("ProcessOldDrawerData\n");
379 #endif
381 /* if (icon->do_Type == WBDRAWER)
383 /* sba: all icons which have do_DrawerData set actually contain
384 * also the drawer data */
386 if (icon->do_DrawerData)
388 switch (data->sdd_Mode)
390 case SDV_SPECIALMODE_READ:
391 ptr = AllocMemIcon(icon, sizeof(struct DrawerData), MEMF_PUBLIC,
392 IconBase);
393 if (ptr == NULL)
394 return FALSE;
396 if (ReadStruct (streamhook
397 , (APTR *)&ptr
398 , data->sdd_Stream
399 , OldDrawerDataDesc
402 icon->do_DrawerData = ptr;
403 NATIVEICON(data->sdd_Dest)->ni_ReadStruct_State |= RSS_OLDDRAWERDATA_READ;
404 return TRUE;
406 return FALSE;
408 case SDV_SPECIALMODE_WRITE:
409 return WriteStruct (streamhook
410 , icon->do_DrawerData
411 , data->sdd_Stream
412 , OldDrawerDataDesc
414 case SDV_SPECIALMODE_FREE:
415 return TRUE;
419 return TRUE;
421 AROS_USERFUNC_EXIT
422 } /* ProcessOldDrawerData */
424 /****************************************************************************************/
426 static struct Image * ReadImage (struct DiskObject *icon, struct Hook * streamhook, BPTR file)
428 struct Image * image;
429 ULONG size;
430 ULONG t;
431 struct IconBase *IconBase = streamhook->h_Data;
433 image = AllocMemIcon(icon, sizeof(struct Image),
434 MEMF_PUBLIC | MEMF_CLEAR, IconBase);
435 if (!image)
436 return NULL;
438 if (!ReadStruct (streamhook, (APTR *)&image, (APTR)file, ImageDesc))
439 return NULL;
441 /* Size of imagedata in bytes */
442 size = ((image->Width + 15) >> 4) * image->Height * image->Depth * 2;
444 D(bug("%s: %dx%dx%d (%d bytes)\n", __func__
445 , image->Width
446 , image->Height
447 , image->Depth
448 , size));
450 if (size)
452 if (!(image->ImageData = AllocMemIcon(icon, size,
453 MEMF_PUBLIC | MEMF_CHIP, IconBase)))
454 return NULL;
456 size >>= 1;
458 for (t=0; t<size; t++)
460 UWORD data;
462 if (!ReadWord (streamhook, &data, (APTR)file))
463 break;
465 image->ImageData[t] = AROS_WORD2BE(data);
468 if (t != size)
470 D(bug("[%s] Strange. Short read at %d, expected %d\n", t, size));
471 return NULL;
475 return image;
476 } /* ReadImage */
478 /****************************************************************************************/
480 static int WriteImage (struct Hook * streamhook, BPTR file,
481 struct Image * image)
483 ULONG size;
484 ULONG t;
486 if (!WriteStruct (streamhook, image, (APTR)file, ImageDesc) )
487 return FALSE;
489 /* Get size in words */
490 size = ((image->Width + 15) >> 4) * image->Height * image->Depth;
492 #if 0
493 kprintf ("WriteImage: %dx%dx%d (%d bytes)\n"
494 , image->Width
495 , image->Height
496 , image->Depth
497 , size*2
499 #endif
501 for (t=0; t<size; t++)
503 UWORD data = image->ImageData[t];
505 if (!WriteWord (streamhook, AROS_WORD2BE(data), (APTR)file))
506 break;
509 return (t == size);
510 } /* WriteImage */
512 /****************************************************************************************/
514 AROS_UFH3S(ULONG, ProcessGadgetRender,
515 AROS_UFHA(struct Hook *, hook, A0),
516 AROS_UFHA(struct Hook *, streamhook, A2),
517 AROS_UFHA(struct SDData *, data, A1)
520 AROS_USERFUNC_INIT
522 struct Image * image;
523 struct DiskObject *icon = DO(data->sdd_Dest);
525 #if 0
526 kprintf ("ProcessGadgetRender\n");
527 #endif
529 if (icon->do_Gadget.GadgetRender || (icon->do_Gadget.Flags & GFLG_GADGIMAGE))
531 switch (data->sdd_Mode)
533 case SDV_SPECIALMODE_READ:
534 image = ReadImage (icon, streamhook, (BPTR)data->sdd_Stream);
536 if (!image)
537 return FALSE;
539 icon->do_Gadget.GadgetRender = image;
540 NATIVEICON(data->sdd_Dest)->ni_ReadStruct_State |= RSS_GADGETIMAGE_READ;
541 break;
543 case SDV_SPECIALMODE_WRITE:
544 image = icon->do_Gadget.GadgetRender;
545 if (!image)
546 return TRUE;
548 return WriteImage (streamhook, (BPTR)data->sdd_Stream, image);
550 case SDV_SPECIALMODE_FREE:
551 break;
555 return TRUE;
557 AROS_USERFUNC_EXIT
558 } /* ProcessGadgetRender */
560 /****************************************************************************************/
562 AROS_UFH3S(ULONG, ProcessSelectRender,
563 AROS_UFHA(struct Hook *, hook, A0),
564 AROS_UFHA(struct Hook *, streamhook, A2),
565 AROS_UFHA(struct SDData *, data, A1)
568 AROS_USERFUNC_INIT
570 struct Image * image;
571 struct DiskObject *icon = DO(data->sdd_Dest);
573 #if 0
574 kprintf ("ProcessSelectRender\n");
575 #endif
577 /* Not all icon with second image seem to have GFLG_GADGHIMAGE set */
579 if (icon->do_Gadget.SelectRender || (icon->do_Gadget.Flags & GFLG_GADGHIMAGE))
581 switch (data->sdd_Mode)
583 case SDV_SPECIALMODE_READ:
584 image = ReadImage (icon, streamhook, (BPTR)data->sdd_Stream);
586 if (!image)
587 return FALSE;
589 icon->do_Gadget.SelectRender = image;
590 NATIVEICON(data->sdd_Dest)->ni_ReadStruct_State |= RSS_SELECTIMAGE_READ;
591 break;
593 case SDV_SPECIALMODE_WRITE:
594 image = icon->do_Gadget.SelectRender;
596 return WriteImage (streamhook, (BPTR)data->sdd_Stream, image);
598 case SDV_SPECIALMODE_FREE:
599 break;
603 return TRUE;
605 AROS_USERFUNC_EXIT
606 } /* ProcessSelectRender */
608 /****************************************************************************************/
610 AROS_UFH3S(ULONG, ProcessFlagPtr,
611 AROS_UFHA(struct Hook *, hook, A0),
612 AROS_UFHA(struct Hook *, streamhook, A2),
613 AROS_UFHA(struct SDData *, data, A1)
616 AROS_USERFUNC_INIT
618 LONG ptr;
619 struct IconBase *IconBase = streamhook->h_Data;
621 switch (data->sdd_Mode)
623 case SDV_SPECIALMODE_READ:
624 if (FRead ((BPTR)data->sdd_Stream, &ptr, 1, 4) != 4)
625 return FALSE;
627 #if 0
628 kprintf ("ProcessFlagPtr: %08lx %ld\n", ptr);
629 #endif
631 *((IPTR *)data->sdd_Dest) = (IPTR)(ptr != 0L);
633 break;
635 case SDV_SPECIALMODE_WRITE:
636 IconBase = streamhook->h_Data;
637 if (*((APTR *)data->sdd_Dest))
638 ptr = 0xABADCAFEL;
639 else
640 ptr = 0L;
642 if (FWrite ((BPTR)data->sdd_Stream, &ptr, 1, 4) != 4)
643 return FALSE;
645 break;
647 case SDV_SPECIALMODE_FREE:
648 break;
652 return TRUE;
654 AROS_USERFUNC_EXIT
655 } /* ProcessFlagPtr */
657 /****************************************************************************************/
659 static STRPTR ReadIconString (struct DiskObject *icon, struct Hook * streamhook, BPTR file)
661 ULONG len;
662 STRPTR str;
664 struct IconBase *IconBase = streamhook->h_Data;
666 if (!ReadLong (streamhook, &len, (APTR)file))
667 return NULL;
669 str = AllocMemIcon(icon, len, MEMF_PUBLIC, IconBase);
671 if (!str)
672 return NULL;
674 if (FRead ((BPTR)file, str, len, 1) == EOF)
676 return NULL;
679 #if 0
680 kprintf ("ReadIconString: \"%s\"\n", str);
681 #endif
683 return str;
684 } /* ReadIconString */
686 /****************************************************************************************/
688 static int WriteIconString (struct Hook * streamhook, BPTR file, STRPTR str)
690 ULONG len;
692 struct IconBase *IconBase = streamhook->h_Data;
694 len = strlen (str) + 1;
696 if (!WriteLong (streamhook, len, (APTR)file))
697 return FALSE;
699 return FWrite (file, str, len, 1) != EOF;
700 } /* WriteIconString */
702 /****************************************************************************************/
704 AROS_UFH3S(ULONG, ProcessDefaultTool,
705 AROS_UFHA(struct Hook *, hook, A0),
706 AROS_UFHA(struct Hook *, streamhook, A2),
707 AROS_UFHA(struct SDData *, data, A1)
710 AROS_USERFUNC_INIT
712 STRPTR str;
713 struct DiskObject *icon = DO(data->sdd_Dest);
715 #if 0
716 kprintf ("ProcessDefaultTool\n");
717 #endif
719 if (icon->do_DefaultTool)
721 switch (data->sdd_Mode)
723 case SDV_SPECIALMODE_READ:
724 str = ReadIconString (icon, streamhook, (BPTR) data->sdd_Stream);
726 if (!str)
727 return FALSE;
729 icon->do_DefaultTool = str;
730 NATIVEICON(data->sdd_Dest)->ni_ReadStruct_State |= RSS_DEFAULTTOOL_READ;
731 break;
733 case SDV_SPECIALMODE_WRITE: {
734 str = icon->do_DefaultTool;
736 WriteIconString (streamhook, (BPTR) data->sdd_Stream, str);
738 break; }
740 case SDV_SPECIALMODE_FREE:
741 break;
745 return TRUE;
747 AROS_USERFUNC_EXIT
748 } /* ProcessDefaultTool */
750 /****************************************************************************************/
752 AROS_UFH3S(ULONG, ProcessToolWindow,
753 AROS_UFHA(struct Hook *, hook, A0),
754 AROS_UFHA(struct Hook *, streamhook, A2),
755 AROS_UFHA(struct SDData *, data, A1)
758 AROS_USERFUNC_INIT
760 STRPTR str;
761 struct DiskObject *icon = DO(data->sdd_Dest);
763 #if 0
764 kprintf ("ProcessToolWindow\n");
765 #endif
767 if (icon->do_ToolWindow)
769 switch (data->sdd_Mode)
771 case SDV_SPECIALMODE_READ:
772 str = ReadIconString (icon, streamhook, (BPTR)data->sdd_Stream);
774 if (!str)
775 return FALSE;
777 icon->do_ToolWindow = str;
778 NATIVEICON(data->sdd_Dest)->ni_ReadStruct_State |= RSS_TOOLWINDOW_READ;
779 break;
781 case SDV_SPECIALMODE_WRITE: {
782 str = icon->do_ToolWindow;
784 WriteIconString (streamhook, (BPTR)data->sdd_Stream, str);
786 break; }
788 case SDV_SPECIALMODE_FREE:
789 break;
793 return TRUE;
795 AROS_USERFUNC_EXIT
796 } /* ProcessToolWindow */
798 /****************************************************************************************/
800 AROS_UFH3S(ULONG, ProcessToolTypes,
801 AROS_UFHA(struct Hook *, hook, A0),
802 AROS_UFHA(struct Hook *, streamhook, A2),
803 AROS_UFHA(struct SDData *, data, A1)
806 AROS_USERFUNC_INIT
808 struct IconBase *IconBase = streamhook->h_Data;
809 struct DiskObject *icon = DO(data->sdd_Dest);
811 #if 0
812 kprintf ("ProcessToolTypes\n");
813 #endif
815 if (icon->do_ToolTypes)
817 ULONG t;
818 ULONG count;
819 STRPTR * ttarray;
821 switch (data->sdd_Mode)
823 case SDV_SPECIALMODE_READ:
824 /* Read size of ToolTypes array (each entry is 4 bytes and the
825 last is 0L */
826 if (!ReadLong (streamhook, &count, data->sdd_Stream))
827 return FALSE;
829 count = (count >> 2) - 1; /* How many entries */
831 if ((LONG)count < 0)
833 icon->do_ToolTypes = NULL;
834 return TRUE;
837 ttarray = AllocMemIcon(icon, (count+1)*sizeof(STRPTR),
838 MEMF_PUBLIC, IconBase);
839 if (!ttarray) return FALSE;
841 #if 0
842 kprintf ("Read %d tooltypes (tt=%p)\n", count, ttarray);
843 #endif
845 for (t=0; t<count; t++)
847 ttarray[t] = ReadIconString (icon, streamhook, (BPTR)data->sdd_Stream);
848 #if 0
849 kprintf ("String %d=%p=%s\n", t, ttarray[t], ttarray[t]);
850 #endif
852 if (!ttarray[t])
853 return FALSE;
856 ttarray[t] = NULL;
858 icon->do_ToolTypes = (STRPTR *)ttarray;
859 NATIVEICON(icon)->ni_ReadStruct_State |= RSS_TOOLTYPES_READ;
860 break;
862 case SDV_SPECIALMODE_WRITE: {
863 ULONG size;
865 ttarray = (STRPTR *)icon->do_ToolTypes;
867 for (count=0; ttarray[count]; count++);
869 #if 0
870 kprintf ("Write %d tooltypes (%p)\n", count, ttarray);
871 #endif
873 size = (count+1)*4;
875 if (!WriteLong (streamhook, size, data->sdd_Stream))
876 return FALSE;
878 for (t=0; t<count; t++)
880 #if 0
881 kprintf ("String %d=%p=%s\n", t, ttarray[t], ttarray[t]);
882 #endif
883 if (!WriteIconString (streamhook, (BPTR)data->sdd_Stream, ttarray[t]))
884 return FALSE;
887 break; }
889 case SDV_SPECIALMODE_FREE:
890 break;
893 #if 0
894 else
895 kprintf ("No tool types\n");
896 #endif
898 return TRUE;
900 AROS_USERFUNC_EXIT
901 } /* ProcessToolTypes */
903 /****************************************************************************************/
905 AROS_UFH3S(ULONG, ProcessNewDrawerData,
906 AROS_UFHA(struct Hook *, hook, A0),
907 AROS_UFHA(struct Hook *, streamhook, A2),
908 AROS_UFHA(struct SDData *, data, A1)
911 AROS_USERFUNC_INIT
913 struct DiskObject *icon = DO(data->sdd_Dest);
914 IPTR rev = (IPTR)icon->do_Gadget.UserData & WB_DISKREVISIONMASK;
915 #if 0
916 kprintf ("ProcessNewDrawerData\n");
917 #endif
919 if (icon->do_DrawerData && (rev > 0) && (rev <= WB_DISKREVISION))
921 switch (data->sdd_Mode)
923 case SDV_SPECIALMODE_READ:
924 if (!ReadLong(streamhook, &icon->do_DrawerData->dd_Flags, data->sdd_Stream))
925 return FALSE;
927 if (!ReadWord(streamhook, &icon->do_DrawerData->dd_ViewModes, data->sdd_Stream))
928 return FALSE;
930 break;
932 case SDV_SPECIALMODE_WRITE:
933 if (!WriteLong(streamhook, icon->do_DrawerData->dd_Flags, data->sdd_Stream))
934 return FALSE;
936 if (!WriteWord(streamhook, icon->do_DrawerData->dd_ViewModes, data->sdd_Stream))
937 return FALSE;
938 break;
942 return TRUE;
944 AROS_USERFUNC_EXIT
945 } /* ProcessNewDrawerData */
947 /****************************************************************************************/
949 #define IconBase ((IconBase_T *)(streamhook->h_Data))
951 /****************************************************************************************/
953 AROS_UFH3S(ULONG, ProcessIcon35,
954 AROS_UFHA(struct Hook *, hook, A0),
955 AROS_UFHA(struct Hook *, streamhook, A2),
956 AROS_UFHA(struct SDData *, data, A1)
959 AROS_USERFUNC_INIT
961 IPTR retval = TRUE;
963 #if 0
964 kprintf ("ProcessIcon35\n");
965 #endif
967 switch (data->sdd_Mode)
969 case SDV_SPECIALMODE_READ:
970 ReadIcon35(NATIVEICON(DO(data->sdd_Dest)), streamhook, data->sdd_Stream, IconBase);
971 break;
973 case SDV_SPECIALMODE_FREE:
974 FreeIcon35(NATIVEICON(DO(data->sdd_Dest)), IconBase);
975 break;
977 case SDV_SPECIALMODE_WRITE:
978 retval = WriteIcon35(NATIVEICON(DO(data->sdd_Dest)), streamhook, data->sdd_Stream, IconBase);
979 break;
983 return retval;
985 AROS_USERFUNC_EXIT
986 } /* ProcessIcon35 */
988 /****************************************************************************************/
990 AROS_UFH3S(ULONG, ProcessIconNI,
991 AROS_UFHA(struct Hook *, hook, A0),
992 AROS_UFHA(struct Hook *, streamhook, A2),
993 AROS_UFHA(struct SDData *, data, A1)
996 AROS_USERFUNC_INIT
998 IPTR retval = TRUE;
1000 #if 0
1001 kprintf ("ProcessIconNI\n");
1002 #endif
1004 switch (data->sdd_Mode)
1006 case SDV_SPECIALMODE_READ:
1007 ReadIconNI(NATIVEICON(DO(data->sdd_Dest)), streamhook, data->sdd_Stream, IconBase);
1008 break;
1010 case SDV_SPECIALMODE_FREE:
1011 FreeIconNI(NATIVEICON(DO(data->sdd_Dest)), IconBase);
1012 break;
1014 case SDV_SPECIALMODE_WRITE:
1015 retval = WriteIconNI(NATIVEICON(DO(data->sdd_Dest)), streamhook, data->sdd_Stream, IconBase);
1016 break;
1020 return retval;
1022 AROS_USERFUNC_EXIT
1023 } /* ProcessIconNI */
1025 /****************************************************************************************/