New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / libs / datatypes / newdtobjecta.c
blobf4b8501db59a2f3705bcdd04640d416e7febedb4
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
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 /*****************************************************************************
20 NAME */
21 #include <proto/datatypes.h>
23 AROS_LH2(Object *, NewDTObjectA,
25 /* SYNOPSIS */
26 AROS_LHA(APTR , name , D0),
27 AROS_LHA(struct TagItem *, attrs, A0),
29 /* LOCATION */
30 struct Library *, DataTypesBase, 8, DataTypes)
32 /* FUNCTION
34 Create a data type object from a BOOPSI class.
36 INPUTS
38 name -- name of the data source; generally an existing file name
39 attrs -- pointer to a TagList specifying additional arguments
41 TAGS
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.
58 GA_Left
59 GA_RelRight
60 GA_Top
61 GA_RelBottom
62 GA_Width
63 GA_RelWidth
64 GA_Height
65 GA_RelHeight -- Specify the position of the object relative to the
66 window.
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.
74 RESULT
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
78 information:
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.
86 NOTES
88 This function invokes the method OM_NEW for the specified class.
90 The object should (eventually) be freed by DisposeDTObject() when no
91 longer needed.
93 EXAMPLE
95 BUGS
97 SEE ALSO
99 AddDTObject(), DisposeDTObject(), RemoveDTObject(),
100 intuition.library/NewObjectA()
102 INTERNALS
104 HISTORY
106 *****************************************************************************/
108 AROS_LIBFUNC_INIT
110 ULONG SourceType;
111 struct DataType *DataType;
112 APTR Handle;
113 ULONG GroupID;
114 BPTR lock = NULL;
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);
126 else
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"));
140 switch (GroupID)
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;
154 else
156 D(bug("datatypes.library/NewDTObjectA: SourceType is *not* DTST_RAM or GroupID is 0\n"));
158 if(Handle != NULL)
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));
167 else
169 D(bug("datatypes.library/NewDTObjectA: DTA_Handle is NULL\n"));
170 if(DataType == NULL)
172 D(bug("datatypes.library/NewDTObjectA: DataType is NULL\n"));
174 switch(SourceType)
176 case DTST_FILE:
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,
183 (APTR)lock, attrs)))
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);
191 DataType = NULL;
192 SetIoErr(ERROR_OBJECT_WRONG_TYPE);
194 else
195 Handle = (APTR)lock;
198 if(Handle == NULL)
200 UnLock(lock);
201 lock = NULL;
204 } /* if lock aquired */
205 break;
207 case DTST_CLIPBOARD:
208 D(bug("datatypes.library/NewDTObjectA: SourceType = DTST_CLIPBOARD\n"));
210 if(!(iff = AllocIFF()))
211 SetIoErr(ERROR_NO_FREE_STORE);
212 else
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"));
219 InitIFFasClip(iff);
221 if(!OpenIFF(iff, IFFF_READ))
223 D(bug("datatypes.library/NewDTObjectA: OpenIFF okay\n"));
225 if((DataType = ObtainDataTypeA(SourceType,
226 iff, attrs)))
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);
235 DataType = NULL;
236 SetIoErr(ERROR_OBJECT_WRONG_TYPE);
238 else
239 Handle = iff;
241 } /* ObtainDataType okay */
242 if(Handle == NULL)
243 CloseIFF(iff);
245 } /* OpenIFF okay */
247 if(Handle == NULL)
248 CloseClipboard((struct ClipboardHandle*)iff->iff_Stream);
250 } /* OpenClipBoard okay */
252 if(Handle == NULL)
254 FreeIFF(iff);
255 iff = NULL;
258 } /* AllocIFF okay */
260 break;
262 } /* switch(SourceType) */
264 } /* if (DataType == NULL */
266 } /* DTA_Handle == NULL */
268 } /* SourceType != DTST_RAM or GroupID == 0 */
270 if(DataType != NULL)
271 BaseName = DataType->dtn_Header->dth_BaseName;
273 if(BaseName != NULL)
275 UBYTE libname[120];
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);
285 else
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 *,
293 DTClassBase, 5,)))
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));
315 lock = NULL;
316 iff = NULL;
318 } /* ObtainEngine okay */
320 if(dtobj == NULL)
321 CloseLibrary(DTClassBase);
323 } /* datatype class library could be opened */
325 } /* if (BaseName != NULL) */
327 if(dtobj == NULL)
329 D(bug("datatypes.library/NewDTObjectA: dtobj is NULL. Cleaning up\n"));
331 if(lock != NULL)
332 UnLock(lock);
334 if(iff != NULL)
336 D(bug("datatypes.library/NewDTObjectA: Calling CloseIFF\n"));
337 CloseIFF(iff);
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"));
341 FreeIFF(iff);
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));
355 return dtobj;
357 AROS_LIBFUNC_EXIT
359 } /* NewDTObjectA */