2 Copyright © 1995-2015, 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
;
120 D(bug("datatypes.library/NewDTObjectA\n"));
122 if(!(SourceType
= GetTagData(DTA_SourceType
, DTST_FILE
, attrs
)))
124 D(bug("datatypes.library/NewDTObjectA: Bad DTA_SourceType (or no such tag)\n"));
125 error
= ERROR_REQUIRED_ARG_MISSING
;
129 D(bug("datatypes.library/NewDTObjectA: DTA_SourceType okay\n"));
131 DataType
= (struct DataType
*)GetTagData(DTA_DataType
, (IPTR
) NULL
, attrs
);
132 Handle
= (APTR
)GetTagData(DTA_Handle
, (IPTR
) NULL
, attrs
);
133 GroupID
= GetTagData(DTA_GroupID
, 0, attrs
);
134 BaseName
= (UBYTE
*)GetTagData(DTA_BaseName
, (IPTR
) NULL
, attrs
);
136 D(bug("datatypes.library/NewDTObjectA: Got attrs DTA_DataType, DTA_Handle and DTA_GroupID\n"));
138 if((SourceType
== DTST_RAM
) && GroupID
)
140 D(bug("datatypes.library/NewDTObjectA: SourceType is DTST_RAM and GroupID is != 0\n"));
143 case GID_ANIMATION
: BaseName
="animation"; break;
144 case GID_DOCUMENT
: BaseName
="document"; break;
145 case GID_INSTRUMENT
: BaseName
="instrument"; break;
146 case GID_MOVIE
: BaseName
="movie"; break;
147 case GID_MUSIC
: BaseName
="music"; break;
148 case GID_PICTURE
: BaseName
="picture"; break;
149 case GID_SOUND
: BaseName
="sound"; break;
150 case GID_TEXT
: BaseName
="ascii"; break;
152 default: error
= ERROR_BAD_NUMBER
; break;
157 D(bug("datatypes.library/NewDTObjectA: SourceType is *not* DTST_RAM or GroupID is 0\n"));
161 D(bug("datatypes.library/NewDTObjectA: We have a DTA_Handle. Calling ObtainDataTypeA\n"));
163 DataType
= ObtainDataTypeA(SourceType
, Handle
, attrs
);
165 D(bug("datatypes.library/NewDTObjectA: ObtainDataTypeA() returned %x\n", DataType
));
170 D(bug("datatypes.library/NewDTObjectA: DTA_Handle is NULL\n"));
173 D(bug("datatypes.library/NewDTObjectA: DataType is NULL\n"));
178 D(bug("datatypes.library/NewDTObjectA: SourceType is DTST_FILE\n"));
180 if((lock
= Lock(name
, ACCESS_READ
)))
182 D(bug("datatypes.library/NewDTObjectA: Lock(\"%s\") okay\n", name
));
183 if((DataType
= ObtainDataTypeA(SourceType
,
186 D(bug("datatypes.library/NewDTObjectA: ObtainDataType returned %x\n", DataType
));
187 if (GroupID
&& (DataType
->dtn_Header
->dth_GroupID
!= GroupID
))
189 D(bug("datatypes.library/NewDTObjectA: Bad GroupID\n"));
191 ReleaseDataType(DataType
);
193 error
= ERROR_OBJECT_WRONG_TYPE
;
205 } /* if lock aquired */
211 D(bug("datatypes.library/NewDTObjectA: SourceType = DTST_CLIPBOARD\n"));
213 if(!(iff
= AllocIFF()))
214 error
= ERROR_NO_FREE_STORE
;
217 D(bug("datatypes.library/NewDTObjectA: AllocIFF okay\n"));
218 if((iff
->iff_Stream
= (IPTR
)OpenClipboard((IPTR
)name
)))
220 D(bug("datatypes.library/NewDTObjectA: OpenClipBoard okay\n"));
224 if(!OpenIFF(iff
, IFFF_READ
))
226 D(bug("datatypes.library/NewDTObjectA: OpenIFF okay\n"));
228 if((DataType
= ObtainDataTypeA(SourceType
,
231 D(bug("datatypes.library/NewDTObjectA: ObtainDataType returned %x\n", DataType
));
233 if (GroupID
&& (DataType
->dtn_Header
->dth_GroupID
!= GroupID
))
235 D(bug("datatypes.library/NewDTObjectA: Bad GroupID\n"));
237 ReleaseDataType(DataType
);
239 error
= ERROR_OBJECT_WRONG_TYPE
;
244 } /* ObtainDataType okay */
251 CloseClipboard((struct ClipboardHandle
*)iff
->iff_Stream
);
253 } /* OpenClipBoard okay */
261 } /* AllocIFF okay */
265 } /* switch(SourceType) */
267 } /* if (DataType == NULL */
269 } /* DTA_Handle == NULL */
271 } /* SourceType != DTST_RAM or GroupID == 0 */
274 BaseName
= DataType
->dtn_Header
->dth_BaseName
;
279 struct Library
*DTClassBase
;
281 D(bug("datatypes.library/NewDTObjectA: Trying OpenLibrary(datatypes/%s.datatype)\n", BaseName
));
282 strcpy(libname
, "datatypes/");
283 strcat(libname
, BaseName
);
284 strcat(libname
, ".datatype");
286 if(!(DTClassBase
= OpenLibrary(libname
, 0)))
287 error
= DTERROR_UNKNOWN_DATATYPE
;
290 struct IClass
*DTClass
;
292 D(bug("datatypes.library/NewDTObjectA: OpenLibrary okay. Now calling ObtainEngine\n"));
294 /* Call ObtainEngine() */
295 if((DTClass
= AROS_LVO_CALL0(Class
*, struct Library
*,
299 struct TagItem Tags
[4];
301 D(bug("datatypes.library/NewDTObjectA: ObtainEngine returned %x\n", DTClass
));
303 Tags
[0].ti_Tag
= DTA_Name
;
304 Tags
[0].ti_Data
= (IPTR
)name
;
305 Tags
[1].ti_Tag
= DTA_DataType
;
306 Tags
[1].ti_Data
= (IPTR
)DataType
;
307 Tags
[2].ti_Tag
= DTA_Handle
;
308 Tags
[2].ti_Data
= (IPTR
)Handle
;
309 Tags
[3].ti_Tag
= TAG_MORE
;
310 Tags
[3].ti_Data
= (IPTR
)attrs
;
312 D(bug("datatypes.library/NewDTObjectA: Calling NewObjectA on obtained engine\n"));
314 dtobj
= NewObjectA(DTClass
, NULL
, Tags
);
316 D(bug("datatypes.library/NewDTObjectA: NewObjectA returned %x\n", dtobj
));
321 } /* ObtainEngine okay */
324 CloseLibrary(DTClassBase
);
326 } /* datatype class library could be opened */
328 } /* if (BaseName != NULL) */
332 D(bug("datatypes.library/NewDTObjectA: dtobj is NULL. Cleaning up\n"));
339 D(bug("datatypes.library/NewDTObjectA: Calling CloseIFF\n"));
341 D(bug("datatypes.library/NewDTObjectA: Calling CloseClipboard\n"));
342 CloseClipboard((struct ClipboardHandle
*)iff
->iff_Stream
);
343 D(bug("datatypes.library/NewDTObjectA: Calling FreeIFF\n"));
345 D(bug("datatypes.library/NewDTObjectA: IFF cleanup done\n"));
347 } /* if (iff != NULL) */
349 } /* if (dtobj == NULL) */
351 } /* SourceType okay */
353 if(error
== ERROR_OBJECT_NOT_FOUND
)
354 error
= DTERROR_COULDNT_OPEN
;
356 D(bug("datatypes.library/NewDTObjectA: Done. Returning %x\n", dtobj
));