Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / icon / diskobjio.c
blob24457c81dc671e1fc5a0b2ff5b7d6823f8e5e728
1 /*
2 Copyright © 1995-2003, 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, ProcessClearMem,
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, ProcessCheckFileType,
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, ProcessOldDrawerData,
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, ProcessNewDrawerData,
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, ProcessGadgetRender,
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, ProcessSelectRender,
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, ProcessDefaultTool,
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, ProcessToolWindow,
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, ProcessToolTypes,
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, ProcessFlagPtr,
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, ProcessIcon35,
97 AROS_UFPA(struct Hook *, hook, A0),
98 AROS_UFPA(struct Hook *, streamhook, A2),
99 AROS_UFPA(struct SDData *, data, A1)
102 AROS_UFP3S(ULONG, ProcessIconNI,
103 AROS_UFPA(struct Hook *, hook, A0),
104 AROS_UFPA(struct Hook *, streamhook, A2),
105 AROS_UFPA(struct SDData *, data, A1)
108 static const struct Hook ProcessClearMemHook =
110 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessClearMem), NULL, NULL
112 ProcessCheckFileTypeHook =
114 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessCheckFileType), NULL, NULL
116 ProcessOldDrawerDataHook =
118 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessOldDrawerData), NULL, NULL
120 ProcessNewDrawerDataHook =
122 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessNewDrawerData), NULL, NULL
124 ProcessGadgetRenderHook =
126 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessGadgetRender), NULL, NULL
128 ProcessSelectRenderHook =
130 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessSelectRender), NULL, NULL
132 ProcessFlagPtrHook =
134 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessFlagPtr), NULL, NULL
136 ProcessDefaultToolHook =
138 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessDefaultTool), NULL, NULL
140 ProcessToolWindowHook =
142 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessToolWindow), NULL, NULL
144 ProcessToolTypesHook =
146 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessToolTypes), NULL, NULL
148 ProcessIcon35Hook =
150 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessIcon35), NULL, NULL
152 ProcessIconNIHook =
154 { NULL, NULL}, (HOOKFUNC)AROS_ASMSYMNAME(ProcessIconNI), NULL, NULL
157 /****************************************************************************************/
159 #undef O
160 #define O(x) (offsetof (struct Gadget,x))
162 /****************************************************************************************/
164 static const IPTR GadgetDesc[] =
166 sizeof (struct Gadget),
167 SDM_IGNORE(4), /* NextGadget */
168 SDM_WORD(O(LeftEdge)),
169 SDM_WORD(O(TopEdge)),
170 SDM_WORD(O(Width)),
171 SDM_WORD(O(Height)),
172 SDM_UWORD(O(Flags)),
173 SDM_UWORD(O(Activation)),
174 SDM_UWORD(O(GadgetType)),
175 SDM_SPECIAL(O(GadgetRender),&ProcessFlagPtrHook),
176 SDM_SPECIAL(O(SelectRender),&ProcessFlagPtrHook),
177 SDM_SPECIAL(O(GadgetText),&ProcessFlagPtrHook),
178 SDM_LONG(O(MutualExclude)),
179 SDM_SPECIAL(O(SpecialInfo),&ProcessFlagPtrHook),
180 SDM_UWORD(O(GadgetID)),
181 SDM_ULONG(O(UserData)),
182 SDM_END
185 /****************************************************************************************/
187 #undef O
188 #define O(x) (offsetof (struct DiskObject,x))
190 /****************************************************************************************/
192 static const IPTR DiskObjectDesc[] =
194 sizeof (struct DiskObject),
195 SDM_UWORD(O(do_Magic)),
196 SDM_UWORD(O(do_Version)),
197 SDM_STRUCT(O(do_Gadget),GadgetDesc),
198 SDM_UBYTE(O(do_Type)),
199 SDM_IGNORE(1), /* Pad */
200 SDM_SPECIAL(O(do_DefaultTool),&ProcessFlagPtrHook),
201 SDM_SPECIAL(O(do_ToolTypes),&ProcessFlagPtrHook),
202 SDM_LONG(O(do_CurrentX)),
203 SDM_LONG(O(do_CurrentY)),
204 SDM_SPECIAL(O(do_DrawerData),&ProcessFlagPtrHook),
205 SDM_SPECIAL(O(do_ToolWindow),&ProcessFlagPtrHook),
206 SDM_LONG(O(do_StackSize)),
207 SDM_END
210 /****************************************************************************************/
212 #undef O
213 #define O(x) (offsetof (struct Image,x))
215 /****************************************************************************************/
217 static const IPTR ImageDesc[] =
219 sizeof (struct Image),
220 SDM_WORD(O(LeftEdge)),
221 SDM_WORD(O(TopEdge)),
222 SDM_WORD(O(Width)),
223 SDM_WORD(O(Height)),
224 SDM_WORD(O(Depth)),
225 SDM_SPECIAL(O(ImageData),&ProcessFlagPtrHook),
226 SDM_UBYTE(O(PlanePick)),
227 SDM_UBYTE(O(PlaneOnOff)),
228 SDM_SPECIAL(O(NextImage),&ProcessFlagPtrHook),
229 SDM_END
232 /****************************************************************************************/
234 const IPTR IconDesc[] =
236 sizeof (struct NativeIcon),
237 SDM_SPECIAL(0,&ProcessClearMemHook),
238 SDM_STRUCT(0,DiskObjectDesc),
239 SDM_SPECIAL(0,&ProcessCheckFileTypeHook),
240 SDM_SPECIAL(0,&ProcessOldDrawerDataHook),
241 SDM_SPECIAL(0,&ProcessGadgetRenderHook),
242 SDM_SPECIAL(0,&ProcessSelectRenderHook),
243 SDM_SPECIAL(0,&ProcessDefaultToolHook),
244 SDM_SPECIAL(0,&ProcessToolTypesHook),
245 SDM_SPECIAL(0,&ProcessToolWindowHook),
246 SDM_SPECIAL(0,&ProcessNewDrawerDataHook),
247 SDM_SPECIAL(0,&ProcessIcon35Hook),
248 SDM_SPECIAL(0,&ProcessIconNIHook),
249 SDM_END
252 /****************************************************************************************/
254 #undef O
255 #define O(x) (offsetof (struct NewWindow,x))
257 /****************************************************************************************/
259 const IPTR NewWindowDesc[] =
261 sizeof (struct NewWindow),
262 SDM_WORD(O(LeftEdge)),
263 SDM_WORD(O(TopEdge)),
264 SDM_WORD(O(Width)),
265 SDM_WORD(O(Height)),
266 SDM_UBYTE(O(DetailPen)),
267 SDM_UBYTE(O(BlockPen)),
268 SDM_ULONG(O(IDCMPFlags)),
269 SDM_ULONG(O(Flags)),
270 SDM_IGNORE(4+4+4+4+4), /* FirstGadget
271 +CheckMark
272 +Title
273 +Screen
274 +BitMap
276 SDM_WORD(O(MinWidth)),
277 SDM_WORD(O(MinHeight)),
278 SDM_UWORD(O(MaxWidth)),
279 SDM_UWORD(O(MaxHeight)),
280 SDM_UWORD(O(Type)),
281 SDM_END
284 /****************************************************************************************/
286 #undef O
287 #define O(x) (offsetof (struct DrawerData,x))
289 /****************************************************************************************/
291 const IPTR OldDrawerDataDesc[] =
293 sizeof (struct DrawerData),
294 SDM_STRUCT(O(dd_NewWindow),NewWindowDesc),
295 SDM_LONG(O(dd_CurrentX)),
296 SDM_LONG(O(dd_CurrentY)),
297 SDM_END
300 /****************************************************************************************/
302 AROS_UFH3(LONG, dosstreamhook,
303 AROS_UFHA(struct Hook *, hook, A0),
304 AROS_UFHA(BPTR, fh, A2),
305 AROS_UFHA(ULONG *, msg, A1)
308 AROS_USERFUNC_INIT
310 LONG rc = 0;
312 switch (*msg)
314 case BEIO_READ:
315 rc = FGetC (fh);
316 #if 0
317 kprintf ("dsh: Read: %02X\n", rc);
318 #endif
319 break;
321 case BEIO_WRITE:
322 rc = FPutC (fh, ((struct BEIOM_Write *)msg)->Data);
323 break;
325 case BEIO_IGNORE:
326 Flush (fh);
328 rc = Seek (fh, ((struct BEIOM_Ignore *)msg)->Count, OFFSET_CURRENT);
329 #if 0
330 kprintf ("dsh: Skip %d\n", ((struct BEIOM_Ignore *)msg)->Count);
331 #endif
332 break;
336 return rc;
338 AROS_USERFUNC_EXIT
339 } /* dosstreamhook */
341 /****************************************************************************************/
343 #define DO(x) ((struct DiskObject *)x)
345 /****************************************************************************************/
347 AROS_UFH3S(ULONG, ProcessClearMem,
348 AROS_UFHA(struct Hook *, hook, A0),
349 AROS_UFHA(struct Hook *, streamhook, A2),
350 AROS_UFHA(struct SDData *, data, A1)
353 AROS_USERFUNC_INIT
355 if (data->sdd_Mode == SDV_SPECIALMODE_READ)
357 memset(data->sdd_Dest, 0, sizeof(struct NativeIcon));
359 NATIVEICON(DO(data->sdd_Dest))->iconbase = (struct IconBase *)streamhook->h_Data;
362 return TRUE;
364 AROS_USERFUNC_EXIT
368 /****************************************************************************************/
370 AROS_UFH3S(ULONG, ProcessCheckFileType,
371 AROS_UFHA(struct Hook *, hook, A0),
372 AROS_UFHA(struct Hook *, streamhook, A2),
373 AROS_UFHA(struct SDData *, data, A1)
376 AROS_USERFUNC_INIT
378 if (data->sdd_Mode == SDV_SPECIALMODE_READ)
380 if ((DO(data->sdd_Dest)->do_Magic != WB_DISKMAGIC))
382 return FALSE;
386 return TRUE;
388 AROS_USERFUNC_EXIT
392 /****************************************************************************************/
394 AROS_UFH3S(ULONG, ProcessOldDrawerData,
395 AROS_UFHA(struct Hook *, hook, A0),
396 AROS_UFHA(struct Hook *, streamhook, A2),
397 AROS_UFHA(struct SDData *, data, A1)
400 AROS_USERFUNC_INIT
401 #if 0
402 kprintf ("ProcessOldDrawerData\n");
403 #endif
405 /* if (DO(data->sdd_Dest)->do_Type == WBDRAWER)
407 /* sba: all icons which have do_DrawerData set actually contain
408 * also the drawer data */
410 if (DO(data->sdd_Dest)->do_DrawerData)
412 switch (data->sdd_Mode)
414 case SDV_SPECIALMODE_READ:
415 if (ReadStruct (streamhook
416 , (APTR *)&(DO(data->sdd_Dest)->do_DrawerData)
417 , data->sdd_Stream
418 , OldDrawerDataDesc
421 NATIVEICON(data->sdd_Dest)->readstruct_state |= RSS_OLDDRAWERDATA_READ;
422 return TRUE;
424 return FALSE;
426 case SDV_SPECIALMODE_WRITE:
427 return WriteStruct (streamhook
428 , DO(data->sdd_Dest)->do_DrawerData
429 , data->sdd_Stream
430 , OldDrawerDataDesc
433 case SDV_SPECIALMODE_FREE:
434 if (NATIVEICON(data->sdd_Dest)->readstruct_state & RSS_OLDDRAWERDATA_READ)
436 FreeStruct (DO(data->sdd_Dest)->do_DrawerData
437 , OldDrawerDataDesc
440 break;
444 return TRUE;
446 AROS_USERFUNC_EXIT
447 } /* ProcessOldDrawerData */
449 /****************************************************************************************/
451 static struct Image * ReadImage (struct Hook * streamhook, BPTR file)
453 struct Image * image;
454 ULONG size;
455 ULONG t;
457 if (!ReadStruct (streamhook, (APTR *)&image, file, ImageDesc))
458 return NULL;
460 /* Size of imagedata in bytes */
461 size = ((image->Width + 15) >> 4) * image->Height * image->Depth * 2;
463 #if 0
464 kprintf ("ReadImage: %dx%dx%d (%d bytes)\n"
465 , image->Width
466 , image->Height
467 , image->Depth
468 , size
470 #endif
472 if (size)
474 if (!(image->ImageData = AllocMem (size, MEMF_CHIP)) )
476 FreeStruct (image, ImageDesc);
477 return NULL;
480 size >>= 1;
482 for (t=0; t<size; t++)
484 UWORD data;
486 if (!ReadWord (streamhook, &data, file))
487 break;
489 image->ImageData[t] = AROS_WORD2BE(data);
492 if (t != size)
494 FreeStruct (image, ImageDesc);
495 return NULL;
499 return image;
500 } /* ReadImage */
502 /****************************************************************************************/
504 static int WriteImage (struct Hook * streamhook, BPTR file,
505 struct Image * image)
507 ULONG size;
508 ULONG t;
510 if (!WriteStruct (streamhook, image, file, ImageDesc) )
511 return FALSE;
513 /* Get size in words */
514 size = ((image->Width + 15) >> 4) * image->Height * image->Depth;
516 #if 0
517 kprintf ("WriteImage: %dx%dx%d (%d bytes)\n"
518 , image->Width
519 , image->Height
520 , image->Depth
521 , size*2
523 #endif
525 for (t=0; t<size; t++)
527 UWORD data = image->ImageData[t];
529 if (!WriteWord (streamhook, AROS_WORD2BE(data), file))
530 break;
533 return (t == size);
534 } /* WriteImage */
536 /****************************************************************************************/
538 static void FreeImage (struct Image * image)
540 ULONG size;
542 /* Get size in bytes */
543 size = ((image->Width + 15) >> 4) * image->Height * image->Depth * 2;
545 if (size)
547 FreeMem (image->ImageData, size);
550 FreeStruct (image, ImageDesc);
551 } /* FreeImage */
553 /****************************************************************************************/
555 AROS_UFH3S(ULONG, ProcessGadgetRender,
556 AROS_UFHA(struct Hook *, hook, A0),
557 AROS_UFHA(struct Hook *, streamhook, A2),
558 AROS_UFHA(struct SDData *, data, A1)
561 AROS_USERFUNC_INIT
563 struct Image * image;
565 #if 0
566 kprintf ("ProcessGadgetRender\n");
567 #endif
569 switch (data->sdd_Mode)
571 case SDV_SPECIALMODE_READ:
572 image = ReadImage (streamhook, data->sdd_Stream);
574 if (!image)
575 return FALSE;
577 DO(data->sdd_Dest)->do_Gadget.GadgetRender = image;
578 NATIVEICON(data->sdd_Dest)->readstruct_state |= RSS_GADGETIMAGE_READ;
579 break;
581 case SDV_SPECIALMODE_WRITE:
582 image = DO(data->sdd_Dest)->do_Gadget.GadgetRender;
584 return WriteImage (streamhook, data->sdd_Stream, image);
586 case SDV_SPECIALMODE_FREE:
587 image = DO(data->sdd_Dest)->do_Gadget.GadgetRender;
588 if (NATIVEICON(data->sdd_Dest)->readstruct_state & RSS_GADGETIMAGE_READ)
590 FreeImage (image);
592 break;
595 return TRUE;
597 AROS_USERFUNC_EXIT
598 } /* ProcessGadgetRender */
600 /****************************************************************************************/
602 AROS_UFH3S(ULONG, ProcessSelectRender,
603 AROS_UFHA(struct Hook *, hook, A0),
604 AROS_UFHA(struct Hook *, streamhook, A2),
605 AROS_UFHA(struct SDData *, data, A1)
608 AROS_USERFUNC_INIT
610 struct Image * image;
612 #if 0
613 kprintf ("ProcessSelectRender\n");
614 #endif
616 if (DO(data->sdd_Dest)->do_Gadget.Flags & GFLG_GADGHIMAGE)
618 switch (data->sdd_Mode)
620 case SDV_SPECIALMODE_READ:
621 image = ReadImage (streamhook, data->sdd_Stream);
623 if (!image)
624 return FALSE;
626 DO(data->sdd_Dest)->do_Gadget.SelectRender = image;
627 NATIVEICON(data->sdd_Dest)->readstruct_state |= RSS_SELECTIMAGE_READ;
628 break;
630 case SDV_SPECIALMODE_WRITE:
631 image = DO(data->sdd_Dest)->do_Gadget.SelectRender;
633 return WriteImage (streamhook, data->sdd_Stream, image);
635 case SDV_SPECIALMODE_FREE:
636 image = DO(data->sdd_Dest)->do_Gadget.SelectRender;
637 if (NATIVEICON(data->sdd_Dest)->readstruct_state & RSS_SELECTIMAGE_READ)
639 FreeImage (image);
641 break;
645 return TRUE;
647 AROS_USERFUNC_EXIT
648 } /* ProcessSelectRender */
650 /****************************************************************************************/
652 AROS_UFH3S(ULONG, ProcessFlagPtr,
653 AROS_UFHA(struct Hook *, hook, A0),
654 AROS_UFHA(struct Hook *, streamhook, A2),
655 AROS_UFHA(struct SDData *, data, A1)
658 AROS_USERFUNC_INIT
660 LONG ptr;
662 switch (data->sdd_Mode)
664 case SDV_SPECIALMODE_READ:
665 if (FRead (data->sdd_Stream, &ptr, 1, 4) != 4)
666 return FALSE;
668 #if 0
669 kprintf ("ProcessFlagPtr: %08lx %ld\n", ptr);
670 #endif
672 *((APTR *)data->sdd_Dest) = (APTR)(ptr != 0L);
674 break;
676 case SDV_SPECIALMODE_WRITE:
677 if (*((APTR *)data->sdd_Dest))
678 ptr = 0xABADCAFEL;
679 else
680 ptr = 0L;
682 if (FWrite (data->sdd_Stream, &ptr, 1, 4) != 4)
683 return FALSE;
685 break;
687 case SDV_SPECIALMODE_FREE:
688 break;
692 return TRUE;
694 AROS_USERFUNC_EXIT
695 } /* ProcessFlagPtr */
697 /****************************************************************************************/
699 static STRPTR ReadIconString (struct Hook * streamhook, BPTR file)
701 ULONG len;
702 STRPTR str;
704 if (!ReadLong (streamhook, &len, file))
705 return NULL;
707 str = AllocVec (len, MEMF_ANY);
709 if (!str)
710 return NULL;
712 if (FRead (file, str, len, 1) == EOF)
714 FreeVec (str);
715 return NULL;
718 #if 0
719 kprintf ("ReadIconString: \"%s\"\n", str);
720 #endif
722 return str;
723 } /* ReadIconString */
725 /****************************************************************************************/
727 static int WriteIconString (struct Hook * streamhook, BPTR file, STRPTR str)
729 ULONG len;
731 len = strlen (str) + 1;
733 if (!WriteLong (streamhook, len, file))
734 return FALSE;
736 return FWrite (file, str, len, 1) != EOF;
737 } /* WriteIconString */
739 /****************************************************************************************/
741 AROS_UFH3S(ULONG, ProcessDefaultTool,
742 AROS_UFHA(struct Hook *, hook, A0),
743 AROS_UFHA(struct Hook *, streamhook, A2),
744 AROS_UFHA(struct SDData *, data, A1)
747 AROS_USERFUNC_INIT
749 STRPTR str;
751 #if 0
752 kprintf ("ProcessDefaultTool\n");
753 #endif
755 if (DO(data->sdd_Dest)->do_DefaultTool)
757 switch (data->sdd_Mode)
759 case SDV_SPECIALMODE_READ:
760 str = ReadIconString (streamhook, data->sdd_Stream);
762 if (!str)
763 return FALSE;
765 DO(data->sdd_Dest)->do_DefaultTool = str;
766 NATIVEICON(data->sdd_Dest)->readstruct_state |= RSS_DEFAULTTOOL_READ;
767 break;
769 case SDV_SPECIALMODE_WRITE: {
770 str = DO(data->sdd_Dest)->do_DefaultTool;
772 WriteIconString (streamhook, data->sdd_Stream, str);
774 break; }
776 case SDV_SPECIALMODE_FREE:
777 str = DO(data->sdd_Dest)->do_DefaultTool;
778 if (NATIVEICON(data->sdd_Dest)->readstruct_state & RSS_DEFAULTTOOL_READ)
780 FreeVec (str);
782 break;
786 return TRUE;
788 AROS_USERFUNC_EXIT
789 } /* ProcessDefaultTool */
791 /****************************************************************************************/
793 AROS_UFH3S(ULONG, ProcessToolWindow,
794 AROS_UFHA(struct Hook *, hook, A0),
795 AROS_UFHA(struct Hook *, streamhook, A2),
796 AROS_UFHA(struct SDData *, data, A1)
799 AROS_USERFUNC_INIT
801 STRPTR str;
803 #if 0
804 kprintf ("ProcessToolWindow\n");
805 #endif
807 if (DO(data->sdd_Dest)->do_ToolWindow)
809 switch (data->sdd_Mode)
811 case SDV_SPECIALMODE_READ:
812 str = ReadIconString (streamhook, data->sdd_Stream);
814 if (!str)
815 return FALSE;
817 DO(data->sdd_Dest)->do_ToolWindow = str;
818 NATIVEICON(data->sdd_Dest)->readstruct_state |= RSS_TOOLWINDOW_READ;
819 break;
821 case SDV_SPECIALMODE_WRITE: {
822 str = DO(data->sdd_Dest)->do_ToolWindow;
824 WriteIconString (streamhook, data->sdd_Stream, str);
826 break; }
828 case SDV_SPECIALMODE_FREE:
829 str = DO(data->sdd_Dest)->do_ToolWindow;
830 if (NATIVEICON(data->sdd_Dest)->readstruct_state & RSS_TOOLWINDOW_READ)
832 FreeVec (str);
834 break;
838 return TRUE;
840 AROS_USERFUNC_EXIT
841 } /* ProcessToolWindow */
843 /****************************************************************************************/
845 AROS_UFH3S(ULONG, ProcessToolTypes,
846 AROS_UFHA(struct Hook *, hook, A0),
847 AROS_UFHA(struct Hook *, streamhook, A2),
848 AROS_UFHA(struct SDData *, data, A1)
851 AROS_USERFUNC_INIT
853 #if 0
854 kprintf ("ProcessToolTypes\n");
855 #endif
857 if (DO(data->sdd_Dest)->do_ToolTypes)
859 ULONG t;
860 ULONG count;
861 STRPTR * ttarray;
863 switch (data->sdd_Mode)
865 case SDV_SPECIALMODE_READ:
866 /* Read size of ToolTypes array (each entry is 4 bytes and the
867 last is 0L */
868 if (!ReadLong (streamhook, &count, data->sdd_Stream))
869 return FALSE;
871 count = (count >> 2) - 1; /* How many entries */
873 ttarray = AllocVec ((count+1)*sizeof(STRPTR), MEMF_ANY);
874 if (!ttarray) return FALSE;
876 #if 0
877 kprintf ("Read %d tooltypes (tt=%p)\n", count, ttarray);
878 #endif
880 for (t=0; t<count; t++)
882 ttarray[t] = ReadIconString (streamhook, data->sdd_Stream);
883 #if 0
884 kprintf ("String %d=%p=%s\n", t, ttarray[t], ttarray[t]);
885 #endif
887 if (!ttarray[t])
889 ULONG i;
891 for (i=0; i<t; i++)
893 FreeVec(ttarray[t]);
896 FreeVec (ttarray);
898 return FALSE;
902 ttarray[t] = NULL;
904 DO(data->sdd_Dest)->do_ToolTypes = (STRPTR *)ttarray;
905 NATIVEICON(data->sdd_Dest)->readstruct_state |= RSS_TOOLTYPES_READ;
906 break;
908 case SDV_SPECIALMODE_WRITE: {
909 ULONG size;
911 ttarray = (STRPTR *)DO(data->sdd_Dest)->do_ToolTypes;
913 for (count=0; ttarray[count]; count++);
915 #if 0
916 kprintf ("Write %d tooltypes (%p)\n", count, ttarray);
917 #endif
919 size = (count+1)*4;
921 if (!WriteLong (streamhook, size, data->sdd_Stream))
922 return FALSE;
924 for (t=0; t<count; t++)
926 #if 0
927 kprintf ("String %d=%p=%s\n", t, ttarray[t], ttarray[t]);
928 #endif
929 if (!WriteIconString (streamhook, data->sdd_Stream, ttarray[t]))
930 return FALSE;
933 break; }
935 case SDV_SPECIALMODE_FREE:
936 ttarray = (STRPTR *)DO(data->sdd_Dest)->do_ToolTypes;
938 if (!(NATIVEICON(data->sdd_Dest)->readstruct_state & RSS_TOOLTYPES_READ))
940 break;
943 #if 0
944 kprintf ("Free tooltypes (%p)\n", count, ttarray);
945 #endif
947 for (t=0; ttarray[t]; t++)
949 #if 0
950 kprintf ("String %d=%p=%s\n", t, ttarray[t], ttarray[t]);
951 #endif
952 FreeVec(ttarray[t]);
954 FreeVec (ttarray);
956 break;
959 #if 0
960 else
961 kprintf ("No tool types\n");
962 #endif
964 return TRUE;
966 AROS_USERFUNC_EXIT
967 } /* ProcessToolTypes */
969 /****************************************************************************************/
971 AROS_UFH3S(ULONG, ProcessNewDrawerData,
972 AROS_UFHA(struct Hook *, hook, A0),
973 AROS_UFHA(struct Hook *, streamhook, A2),
974 AROS_UFHA(struct SDData *, data, A1)
977 AROS_USERFUNC_INIT
979 IPTR rev = (IPTR)DO(data->sdd_Dest)->do_Gadget.UserData & WB_DISKREVISIONMASK;
980 #if 0
981 kprintf ("ProcessNewDrawerData\n");
982 #endif
984 if (DO(data->sdd_Dest)->do_DrawerData && (rev > 0) && (rev <= WB_DISKREVISION))
986 switch (data->sdd_Mode)
988 case SDV_SPECIALMODE_READ:
989 if (!ReadLong(streamhook, &DO(data->sdd_Dest)->do_DrawerData->dd_Flags, data->sdd_Stream))
990 return FALSE;
992 if (!ReadWord(streamhook, &DO(data->sdd_Dest)->do_DrawerData->dd_ViewModes, data->sdd_Stream))
993 return FALSE;
995 break;
997 case SDV_SPECIALMODE_WRITE:
998 if (!WriteLong(streamhook, DO(data->sdd_Dest)->do_DrawerData->dd_Flags, data->sdd_Stream))
999 return FALSE;
1001 if (!WriteWord(streamhook, DO(data->sdd_Dest)->do_DrawerData->dd_ViewModes, data->sdd_Stream))
1002 return FALSE;
1003 break;
1007 return TRUE;
1009 AROS_USERFUNC_EXIT
1010 } /* ProcessNewDrawerData */
1012 /****************************************************************************************/
1014 #define IconBase ((IconBase_T *)(streamhook->h_Data))
1016 /****************************************************************************************/
1018 AROS_UFH3S(ULONG, ProcessIcon35,
1019 AROS_UFHA(struct Hook *, hook, A0),
1020 AROS_UFHA(struct Hook *, streamhook, A2),
1021 AROS_UFHA(struct SDData *, data, A1)
1024 AROS_USERFUNC_INIT
1026 IPTR retval = TRUE;
1028 #if 0
1029 kprintf ("ProcessIcon35\n");
1030 #endif
1032 switch (data->sdd_Mode)
1034 case SDV_SPECIALMODE_READ:
1035 ReadIcon35(NATIVEICON(DO(data->sdd_Dest)), streamhook, data->sdd_Stream, IconBase);
1036 break;
1038 case SDV_SPECIALMODE_FREE:
1039 FreeIcon35(NATIVEICON(DO(data->sdd_Dest)), (IconBase_T *)NATIVEICON(DO(data->sdd_Dest))->iconbase);
1040 break;
1042 case SDV_SPECIALMODE_WRITE:
1043 retval = WriteIcon35(NATIVEICON(DO(data->sdd_Dest)), streamhook, data->sdd_Stream, IconBase);
1044 break;
1048 return retval;
1050 AROS_USERFUNC_EXIT
1051 } /* ProcessIcon35 */
1053 /****************************************************************************************/
1055 AROS_UFH3S(ULONG, ProcessIconNI,
1056 AROS_UFHA(struct Hook *, hook, A0),
1057 AROS_UFHA(struct Hook *, streamhook, A2),
1058 AROS_UFHA(struct SDData *, data, A1)
1061 AROS_USERFUNC_INIT
1063 IPTR retval = TRUE;
1065 #if 0
1066 kprintf ("ProcessIconNI\n");
1067 #endif
1069 switch (data->sdd_Mode)
1071 case SDV_SPECIALMODE_READ:
1072 ReadIconNI(NATIVEICON(DO(data->sdd_Dest)), streamhook, data->sdd_Stream, IconBase);
1073 break;
1075 case SDV_SPECIALMODE_FREE:
1076 FreeIconNI(NATIVEICON(DO(data->sdd_Dest)), (IconBase_T *)NATIVEICON(DO(data->sdd_Dest))->iconbase);
1077 break;
1079 case SDV_SPECIALMODE_WRITE:
1080 retval = WriteIconNI(NATIVEICON(DO(data->sdd_Dest)), streamhook, data->sdd_Stream, IconBase);
1081 break;
1085 return retval;
1087 AROS_USERFUNC_EXIT
1088 } /* ProcessIconNI */
1090 /****************************************************************************************/