2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
8 #include <proto/utility.h>
9 #include <proto/icon.h>
10 #include <proto/dos.h>
11 #include <proto/datatypes.h>
12 #include <exec/memory.h>
13 #include <datatypes/datatypesclass.h>
14 #include <workbench/icon.h>
15 #include <workbench/workbench.h>
16 #include <utility/tagitem.h>
17 #include "datatypes_intern.h"
19 STRPTR
CreateIconName(STRPTR name
, struct Library
*DataTypesBase
);
21 /*****************************************************************************
25 AROS_LH7(ULONG
, SaveDTObjectA
,
28 AROS_LHA(Object
*, o
, A0
),
29 AROS_LHA(struct Window
*, win
, A1
),
30 AROS_LHA(struct Requester
*, req
, A2
),
31 AROS_LHA(STRPTR
, file
, A3
),
32 AROS_LHA(ULONG
, mode
, D0
),
33 AROS_LHA(BOOL
, saveicon
, D1
),
34 AROS_LHA(struct TagItem
*, attrs
, A4
),
37 struct Library
*, DataTypesBase
, 49, DataTypes
)
41 Save the contents of an object to a file using DTM_WRITE.
45 o -- data type object to write to a file
46 win -- window the object is attached to
47 req -- requester the object is attached to
48 file -- name of the file to save the object to
49 mode -- save mode (RAW, IFF etc.), one of the DTWM_ identifiers
50 saveicon -- should an icon be saved together with the file
51 attrs -- additional attributes (these are subclass specific)
55 The return value of DTM_WRITE.
59 If DTM_WRITE returns 0, the file will be deleted.
69 *****************************************************************************/
77 struct Library
*IconBase
= OpenLibrary("icon.library", 39L);
78 struct TagItem tags
[2] =
80 { DTA_DataType
, (STACKIPTR
)&dt
},
81 { TAG_DONE
, (STACKIPTR
)NULL
}
84 if(o
== NULL
|| file
== NULL
)
86 SetIoErr(ERROR_REQUIRED_ARG_MISSING
);
91 write
.MethodID
= DTM_WRITE
;
92 write
.dtw_GInfo
= NULL
;
93 write
.dtw_Mode
= mode
;
94 write
.dtw_AttrList
= attrs
;
96 if(GetDTAttrsA(o
, (struct TagItem
*)&tags
) == 0)
98 SetIoErr(ERROR_OBJECT_WRONG_TYPE
);
103 write
.dtw_FileHandle
= Open(file
, MODE_NEWFILE
);
104 if (write
.dtw_FileHandle
== BNULL
)
110 rc
= DoDTMethodA(o
, win
, req
, (Msg
)&write
);
112 /* Save possible error */
115 if (Close(write
.dtw_FileHandle
) == DOSFALSE
)
117 if(rc
!= 0) SetIoErr(err
);
118 else DeleteFile(file
);
124 /* If the DTM_WRITE didn't succeed, we delete the file */
132 if (saveicon
&& IconBase
!= NULL
)
134 struct DiskObject
*icon
= GetDiskObjectNew(file
);
138 PutDiskObject(file
, icon
);
139 FreeDiskObject(icon
);
144 if (IconBase
!= NULL
) CloseLibrary(IconBase
);
149 } /* SaveDTObjectA() */