2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
8 #include <proto/intuition.h>
9 #include <proto/utility.h>
10 #include <proto/iffparse.h>
11 #include <proto/dos.h>
12 #include <utility/tagitem.h>
13 #include <intuition/intuition.h>
14 #include "datatypes_intern.h" /* Must be after <intuition/intuition.h> */
16 #include <aros/debug.h>
18 /*****************************************************************************
21 #include <proto/datatypes.h>
23 AROS_LH2(Object
*, NewDTObjectA
,
26 AROS_LHA(APTR
, name
, D0
),
27 AROS_LHA(struct TagItem
*, attrs
, A0
),
30 struct Library
*, DataTypesBase
, 8, DataTypes
)
34 Create a data type object from a BOOPSI class.
38 name -- name of the data source; generally an existing file name
39 attrs -- pointer to a TagList specifying additional arguments
43 DTA_SourceType -- The type of source data (defaults to DTST_FILE).
44 If the source is the clipboard the name field
45 contains the numeric clipboard unit.
47 DTA_Handle -- Can be used instead of the 'name' field. If the
48 source is DTST_FILE, ths must be a valid FileHandle;
49 must be a valid IFFHandle if source is DTST_CLIPBOARD.
51 DTA_DataType -- The class of the data. Data is a pointer to a valid
52 DataType; only used when creating a new object that
53 doens't have any source data.
55 DTA_GroupID -- If the object isn't of this type, fail with an IoErr()
56 of ERROR_OBJECT_WRONG_TYPE.
65 GA_RelHeight -- Specify the position of the object relative to the
68 GA_ID -- ID of the object.
70 GA_UserData -- Application specific data for the object.
72 GA_Previous -- Previous object / gadget in the list.
76 A BOOPSI object. This may be used in different contexts such as a gadget
77 or image. NULL indicates failure -- in that case IoErr() gives more
80 ERROR_REQUIRED_ARG_MISSING -- A required attribute wasn't specified.
82 ERROR_BAD_NUMBER -- The group ID specified was invalid.
84 ERROR_OBJECT_WRONG_TYPE -- Object data type doesn't match DTA_GroupID.
88 This function invokes the method OM_NEW for the specified class.
90 The object should (eventually) be freed by DisposeDTObject() when no
99 AddDTObject(), DisposeDTObject(), RemoveDTObject(),
100 intuition.library/NewObjectA()
106 *****************************************************************************/
111 struct DataType
*DataType
;
115 struct IFFHandle
*iff
= NULL
;
116 Object
*dtobj
= NULL
;
117 UBYTE
*BaseName
= NULL
;
119 D(bug("datatypes.library/NewDTObjectA\n"));
121 if(!(SourceType
= GetTagData(DTA_SourceType
, DTST_FILE
, attrs
)))
123 D(bug("datatypes.library/NewDTObjectA: Bad DTA_SourceType (or no such tag)\n"));
124 SetIoErr(ERROR_REQUIRED_ARG_MISSING
);
128 D(bug("datatypes.library/NewDTObjectA: DTA_SourceType okay\n"));
130 DataType
= (struct DataType
*)GetTagData(DTA_DataType
, (IPTR
) NULL
, attrs
);
131 Handle
= (APTR
)GetTagData(DTA_Handle
, (IPTR
) NULL
, attrs
);
132 GroupID
= GetTagData(DTA_GroupID
, 0, attrs
);
133 BaseName
= (UBYTE
*)GetTagData(DTA_BaseName
, (IPTR
) NULL
, attrs
);
135 D(bug("datatypes.library/NewDTObjectA: Got attrs DTA_DataType, DTA_Handle and DTA_GroupID\n"));
137 if((SourceType
== DTST_RAM
) && GroupID
)
139 D(bug("datatypes.library/NewDTObjectA: SourceType is DTST_RAM and GroupID is != 0\n"));
142 case GID_ANIMATION
: BaseName
="animation"; break;
143 case GID_DOCUMENT
: BaseName
="document"; break;
144 case GID_INSTRUMENT
: BaseName
="instrument"; break;
145 case GID_MOVIE
: BaseName
="movie"; break;
146 case GID_MUSIC
: BaseName
="music"; break;
147 case GID_PICTURE
: BaseName
="picture"; break;
148 case GID_SOUND
: BaseName
="sound"; break;
149 case GID_TEXT
: BaseName
="ascii"; break;
151 default: SetIoErr(ERROR_BAD_NUMBER
); break;
156 D(bug("datatypes.library/NewDTObjectA: SourceType is *not* DTST_RAM or GroupID is 0\n"));
160 D(bug("datatypes.library/NewDTObjectA: We have a DTA_Handle. Calling ObtainDataTypeA\n"));
162 DataType
= ObtainDataTypeA(SourceType
, Handle
, attrs
);
164 D(bug("datatypes.library/NewDTObjectA: ObtainDataTypeA() returned %x\n", DataType
));
169 D(bug("datatypes.library/NewDTObjectA: DTA_Handle is NULL\n"));
172 D(bug("datatypes.library/NewDTObjectA: DataType is NULL\n"));
177 D(bug("datatypes.library/NewDTObjectA: SourceType is DTST_FILE\n"));
179 if((lock
= Lock(name
, ACCESS_READ
)))
181 D(bug("datatypes.library/NewDTObjectA: Lock(\"%s\") okay\n", name
));
182 if((DataType
= ObtainDataTypeA(SourceType
,
185 D(bug("datatypes.library/NewDTObjectA: ObtainDataType returned %x\n", DataType
));
186 if (GroupID
&& (DataType
->dtn_Header
->dth_GroupID
!= GroupID
))
188 D(bug("datatypes.library/NewDTObjectA: Bad GroupID\n"));
190 ReleaseDataType(DataType
);
192 SetIoErr(ERROR_OBJECT_WRONG_TYPE
);
204 } /* if lock aquired */
208 D(bug("datatypes.library/NewDTObjectA: SourceType = DTST_CLIPBOARD\n"));
210 if(!(iff
= AllocIFF()))
211 SetIoErr(ERROR_NO_FREE_STORE
);
214 D(bug("datatypes.library/NewDTObjectA: AllocIFF okay\n"));
215 if((iff
->iff_Stream
= (ULONG
)OpenClipboard((ULONG
)name
)))
217 D(bug("datatypes.library/NewDTObjectA: OpenClipBoard okay\n"));
221 if(!OpenIFF(iff
, IFFF_READ
))
223 D(bug("datatypes.library/NewDTObjectA: OpenIFF okay\n"));
225 if((DataType
= ObtainDataTypeA(SourceType
,
228 D(bug("datatypes.library/NewDTObjectA: ObtainDataType returned %x\n", DataType
));
230 if (GroupID
&& (DataType
->dtn_Header
->dth_GroupID
!= GroupID
))
232 D(bug("datatypes.library/NewDTObjectA: Bad GroupID\n"));
234 ReleaseDataType(DataType
);
236 SetIoErr(ERROR_OBJECT_WRONG_TYPE
);
241 } /* ObtainDataType okay */
248 CloseClipboard((struct ClipboardHandle
*)iff
->iff_Stream
);
250 } /* OpenClipBoard okay */
258 } /* AllocIFF okay */
262 } /* switch(SourceType) */
264 } /* if (DataType == NULL */
266 } /* DTA_Handle == NULL */
268 } /* SourceType != DTST_RAM or GroupID == 0 */
271 BaseName
= DataType
->dtn_Header
->dth_BaseName
;
276 struct Library
*DTClassBase
;
278 D(bug("datatypes.library/NewDTObjectA: Trying OpenLibrary(datatypes/%s.datatype)\n", BaseName
));
279 strcpy(libname
, "datatypes/");
280 strcat(libname
, BaseName
);
281 strcat(libname
, ".datatype");
283 if(!(DTClassBase
= OpenLibrary(libname
, 0)))
284 SetIoErr(DTERROR_UNKNOWN_DATATYPE
);
287 struct IClass
*DTClass
;
289 D(bug("datatypes.library/NewDTObjectA: OpenLibrary okay. Now calling ObtainEngine\n"));
291 /* Call ObtainEngine() */
292 if((DTClass
= AROS_LVO_CALL0(Class
*, struct Library
*,
296 struct TagItem Tags
[4];
298 D(bug("datatypes.library/NewDTObjectA: ObtainEngine returned %x\n", DTClass
));
300 Tags
[0].ti_Tag
= DTA_Name
;
301 Tags
[0].ti_Data
= (ULONG
)name
;
302 Tags
[1].ti_Tag
= DTA_DataType
;
303 Tags
[1].ti_Data
= (ULONG
)DataType
;
304 Tags
[2].ti_Tag
= DTA_Handle
;
305 Tags
[2].ti_Data
= (ULONG
)Handle
;
306 Tags
[3].ti_Tag
= TAG_MORE
;
307 Tags
[3].ti_Data
= (ULONG
)attrs
;
309 D(bug("datatypes.library/NewDTObjectA: Calling NewObjectA on obtained engine\n"));
311 dtobj
= NewObjectA(DTClass
, NULL
, Tags
);
313 D(bug("datatypes.library/NewDTObjectA: NewObjectA returned %x\n", dtobj
));
318 } /* ObtainEngine okay */
321 CloseLibrary(DTClassBase
);
323 } /* datatype class library could be opened */
325 } /* if (BaseName != NULL) */
329 D(bug("datatypes.library/NewDTObjectA: dtobj is NULL. Cleaning up\n"));
336 D(bug("datatypes.library/NewDTObjectA: Calling CloseIFF\n"));
338 D(bug("datatypes.library/NewDTObjectA: Calling CloseClipboard\n"));
339 CloseClipboard((struct ClipboardHandle
*)iff
->iff_Stream
);
340 D(bug("datatypes.library/NewDTObjectA: Calling FreeIFF\n"));
342 D(bug("datatypes.library/NewDTObjectA: IFF cleanup done\n"));
344 } /* if (iff != NULL) */
346 } /* if (dtobj == NULL) */
348 } /* SourceType okay */
350 if(IoErr() == ERROR_OBJECT_NOT_FOUND
)
351 SetIoErr(DTERROR_COULDNT_OPEN
);
353 D(bug("datatypes.library/NewDTObjectA: Done. Returning %x\n", dtobj
));