2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
9 #include <aros/debug.h>
11 #include <workbench/icon.h>
12 #include <graphics/gfx.h>
13 #include <proto/arossupport.h>
14 #include "icon_intern.h"
16 /*#define OUTPUT_DATA*/
18 STATIC STRPTR
StrDupIcon(struct DiskObject
*dobj
, STRPTR str
, APTR IconBase
)
21 if (!str
) return NULL
;
22 newstr
= AllocMemIcon(dobj
, strlen(str
)+1, MEMF_PUBLIC
, IconBase
);
23 if (newstr
) strcpy(newstr
,str
);
27 STATIC APTR
MemDupIcon(struct DiskObject
*dobj
, CONST_APTR src
, ULONG size
, APTR IconBase
)
31 newmem
= AllocMemIcon(dobj
, size
, MEMF_PUBLIC
, IconBase
);
32 if (newmem
) CopyMem(src
, newmem
, size
);
37 STATIC
struct Image
*ImageDupIcon(struct DiskObject
*dobj
, struct Image
*src
, BOOL dupImage
, BOOL dupImageData
, APTR IconBase
)
41 if (!src
) return NULL
;
49 dest
= (struct Image
*)AllocMemIcon(dobj
, sizeof(struct Image
),
50 MEMF_PUBLIC
, IconBase
);
56 int plane_pick
= src
->PlanePick
;
59 dest
->NextImage
= NULL
;
61 /* Calc the size all used planes */
62 plane_size
= RASSIZE(src
->Width
,src
->Height
);
66 if (plane_pick
& 1) data_size
+= plane_size
;
70 /* It seems planepick must be ignored. See drawer icon in MCC_TheBar-26.7.lha
71 which seems to contain a SelectRender image with planepick == 0, but the image
72 data is still there. */
77 data_size
= plane_size
* src
->Depth
;
83 if ((dest
->ImageData
= AllocMemIcon(dobj
, data_size
,
84 MEMF_PUBLIC
| MEMF_CHIP
, IconBase
)))
86 memcpy(dest
->ImageData
,src
->ImageData
,data_size
);
88 kprintf("plane_pick = %ld\n",src
->PlanePick
);
89 kprintf("width = %ld\n",src
->Width
);
90 kprintf("height = %ld\n",src
->Height
);
92 for (i
=0;i
<data_size
;i
++)
94 kprintf("0x%02lx,",((unsigned char*)src
->ImageData
)[i
]);
95 if (i
%16 == 15) kprintf("\n");
105 /*****************************************************************************
108 #include <clib/icon_protos.h>
110 AROS_LH2(struct DiskObject
*, DupDiskObjectA
,
113 AROS_LHA(struct DiskObject
*, icon
, A0
),
114 AROS_LHA(struct TagItem
*, tags
, A1
),
117 struct IconBase
*, IconBase
, 25, Icon
)
137 *****************************************************************************/
141 struct NativeIcon
*mem
;
142 struct DiskObject
*dobj
;
143 struct NativeIcon
*srcnativeicon
;
145 if (!icon
) return NULL
;
147 dobj
= NewDiskObject(icon
->do_Type
);
151 mem
= NATIVEICON(dobj
);
152 /* We can't cast this, since it could be a hand-build one */
153 srcnativeicon
= GetNativeIcon(icon
, IconBase
);
155 /* copy the contents */
158 if (srcnativeicon
&& GetTagData(ICONDUPA_DuplicateImageData
, TRUE
, tags
) == TRUE
)
162 mem
->ni_IsDefault
= srcnativeicon
->ni_IsDefault
;
163 mem
->ni_Frameless
= srcnativeicon
->ni_Frameless
;
164 mem
->ni_ScaleBox
= srcnativeicon
->ni_ScaleBox
;
165 mem
->ni_Face
= srcnativeicon
->ni_Face
;
167 /* The duplicate will *not* be laid out to a specific screen */
168 mem
->ni_Screen
= NULL
;
172 /* Duplicate any extra data */
173 if (srcnativeicon
->ni_Extra
.Data
&& srcnativeicon
->ni_Extra
.Size
> 0) {
174 mem
->ni_Extra
= srcnativeicon
->ni_Extra
;
175 mem
->ni_Extra
.Data
= MemDupIcon(dobj
, srcnativeicon
->ni_Extra
.Data
, srcnativeicon
->ni_Extra
.Size
,IconBase
);
176 if (!mem
->ni_Extra
.Data
) goto fail
;
179 for (i
= 0; i
< 2; i
++)
181 struct NativeIconImage
*src
, *dst
;
183 src
= &srcnativeicon
->ni_Image
[i
];
184 dst
= &mem
->ni_Image
[i
];
187 dst
->ARGB
= MemDupIcon(dobj
, src
->ARGB
, srcnativeicon
->ni_Face
.Width
* srcnativeicon
->ni_Face
.Height
* 4, IconBase
);
192 dst
->Pens
= src
->Pens
;
193 dst
->TransparentColor
= src
->TransparentColor
;
195 /* Clone Palette, if we have pens allocated */
196 if (src
->Palette
&& src
->Pens
)
198 dst
->Palette
= MemDupIcon(dobj
, src
->Palette
, src
->Pens
* sizeof(struct ColorRegister
),IconBase
);
199 if (!dst
->Palette
) goto fail
;
202 if (src
->ImageData
) {
203 dst
->ImageData
= MemDupIcon(dobj
, src
->ImageData
, srcnativeicon
->ni_Face
.Width
* srcnativeicon
->ni_Face
.Height
* sizeof(UBYTE
), IconBase
);
204 if (!dst
->ImageData
) goto fail
;
207 /* Do *not* clone the screen specific layout */
212 } /* if (srcnativeicon && GetTagData(ICONDUPA_DuplicateImageData, TRUE, tags) == TRUE) */
215 kprintf("gadgetwidth = %ld\ngadgetheight = %ld\n",dobj
->do_Gadget
.Width
,dobj
->do_Gadget
.Height
);
218 /* and now the pointers and the rest */
219 /* TODO: check for errors here */
221 if (GetTagData(ICONDUPA_DuplicateDefaultTool
, TRUE
, tags
) &&
222 dobj
->do_DefaultTool
)
224 dobj
->do_DefaultTool
= StrDupIcon(dobj
,icon
->do_DefaultTool
,IconBase
);
225 if (!dobj
->do_DefaultTool
) goto fail
;
228 if (GetTagData(ICONDUPA_DuplicateToolWindow
, TRUE
, tags
) &&
231 dobj
->do_ToolWindow
= StrDupIcon(dobj
,icon
->do_ToolWindow
,IconBase
);
232 if (!dobj
->do_ToolWindow
) goto fail
;
235 if (GetTagData(ICONDUPA_DuplicateDrawerData
, TRUE
, tags
) &&
240 dobj
->do_DrawerData
= AllocMemIcon(dobj
, sizeof(struct DrawerData
),
241 MEMF_PUBLIC
, IconBase
);
242 if (!dobj
->do_DrawerData
) goto fail
;
244 if (((SIPTR
)icon
->do_Gadget
.UserData
> 0) &&
245 ((SIPTR
)icon
->do_Gadget
.UserData
<= WB_DISKREVISION
))
247 size
= sizeof(struct DrawerData
);
251 size
= sizeof(struct OldDrawerData
);
254 memset(dobj
->do_DrawerData
, 0, sizeof(struct DrawerData
));
255 memcpy(dobj
->do_DrawerData
, icon
->do_DrawerData
, size
);
258 /* Duplicate the image data */
260 if (icon
->do_Gadget
.GadgetRender
)
262 dobj
->do_Gadget
.GadgetRender
= ImageDupIcon(dobj
, (struct Image
*)icon
->do_Gadget
.GadgetRender
,
263 GetTagData(ICONDUPA_DuplicateImages
, TRUE
, tags
),
264 GetTagData(ICONDUPA_DuplicateImageData
, TRUE
, tags
),IconBase
);
265 if (!dobj
->do_Gadget
.GadgetRender
) goto fail
;
268 if (icon
->do_Gadget
.SelectRender
)
270 dobj
->do_Gadget
.SelectRender
= ImageDupIcon(dobj
, (struct Image
*)icon
->do_Gadget
.SelectRender
,
271 GetTagData(ICONDUPA_DuplicateImages
, TRUE
, tags
),
272 GetTagData(ICONDUPA_DuplicateImageData
, TRUE
, tags
),IconBase
);
273 if (!dobj
->do_Gadget
.SelectRender
) goto fail
;
276 /* Duplicate the tool types */
277 if (GetTagData(ICONDUPA_DuplicateToolTypes
, TRUE
, tags
) &&
281 /* Get number of tool types */
282 for (num_tts
= 0;icon
->do_ToolTypes
[num_tts
];num_tts
++);
284 if ((dobj
->do_ToolTypes
= (STRPTR
*)AllocMemIcon(dobj
,
285 sizeof(char*) * (num_tts
+ 1), MEMF_PUBLIC
, IconBase
)))
288 for (i
=0;i
<num_tts
;i
++)
290 dobj
->do_ToolTypes
[i
] = StrDupIcon(dobj
,icon
->do_ToolTypes
[i
],IconBase
);
291 if (!dobj
->do_ToolTypes
[i
]) goto fail
;
293 dobj
->do_ToolTypes
[i
] = NULL
;
301 if (GetTagData(ICONDUPA_ActivateImageData
, FALSE
, tags
))
302 LayoutIconA(dobj
, LB(IconBase
)->ib_Screen
, NULL
);
304 D(bug("%s: Icon %p => %p\n", __func__
, icon
, dobj
));
309 FreeDiskObject(dobj
);
313 } /* FreeDiskObject */