grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / icon / dupdiskobject.c
blob17a0678de54f78577e4f7cbc2f28b6e05152cee9
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
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)
20 char *newstr;
21 if (!str) return NULL;
22 newstr = AllocMemIcon(dobj, strlen(str)+1, MEMF_PUBLIC, IconBase);
23 if (newstr) strcpy(newstr,str);
24 return newstr;
27 STATIC APTR MemDupIcon(struct DiskObject *dobj, CONST_APTR src, ULONG size, APTR IconBase)
29 UBYTE *newmem;
31 newmem = AllocMemIcon(dobj, size, MEMF_PUBLIC, IconBase);
32 if (newmem) CopyMem(src, newmem, size);
34 return newmem;
37 STATIC struct Image *ImageDupIcon(struct DiskObject *dobj, struct Image *src, BOOL dupImage, BOOL dupImageData, APTR IconBase)
39 struct Image *dest;
41 if (!src) return NULL;
43 if (dupImageData)
44 dupImage = TRUE;
46 if (!dupImage)
47 return src;
49 dest = (struct Image*)AllocMemIcon(dobj, sizeof(struct Image),
50 MEMF_PUBLIC, IconBase);
51 if (dest)
53 int data_size = 0;
54 int plane_size;
55 int i;
56 int plane_pick = src->PlanePick;
58 *dest = *src;
59 dest->NextImage = NULL;
61 /* Calc the size all used planes */
62 plane_size = RASSIZE(src->Width,src->Height);
63 #if 0
64 for (i=0;i<8;i++)
66 if (plane_pick & 1) data_size += plane_size;
67 plane_pick >>= 1;
69 #else
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. */
74 (void)plane_pick;
75 (void)i;
77 data_size = plane_size * src->Depth;
78 #endif
80 if (!dupImageData)
81 return dest;
83 if ((dest->ImageData = AllocMemIcon(dobj, data_size,
84 MEMF_PUBLIC | MEMF_CHIP, IconBase)))
86 memcpy(dest->ImageData,src->ImageData,data_size);
87 #ifdef OUTPUT_DATA
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");
97 kprintf("\n");
98 #endif
99 return dest;
102 return NULL;
105 /*****************************************************************************
107 NAME */
108 #include <clib/icon_protos.h>
110 AROS_LH2(struct DiskObject *, DupDiskObjectA,
112 /* SYNOPSIS */
113 AROS_LHA(struct DiskObject *, icon, A0),
114 AROS_LHA(struct TagItem *, tags, A1),
116 /* LOCATION */
117 struct IconBase *, IconBase, 25, Icon)
119 /* FUNCTION
121 INPUTS
123 RESULT
125 NOTES
127 EXAMPLE
129 BUGS
131 SEE ALSO
133 INTERNALS
135 HISTORY
137 *****************************************************************************/
139 AROS_LIBFUNC_INIT
141 struct NativeIcon *mem;
142 struct DiskObject *dobj;
143 struct NativeIcon *srcnativeicon;
145 if (!icon) return NULL;
147 dobj = NewDiskObject(icon->do_Type);
148 if (dobj == NULL)
149 return NULL;
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 */
156 *dobj = *icon;
158 if (srcnativeicon && GetTagData(ICONDUPA_DuplicateImageData, TRUE, tags) == TRUE)
160 int i;
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;
169 mem->ni_Width = 0;
170 mem->ni_Height = 0;
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];
186 if (src->ARGB) {
187 dst->ARGB = MemDupIcon(dobj, src->ARGB, srcnativeicon->ni_Face.Width * srcnativeicon->ni_Face.Height * 4, IconBase);
188 if (!dst->ARGB)
189 goto fail;
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 */
208 dst->BitMap = NULL;
209 dst->BitMask = NULL;
210 dst->Pen = NULL;
212 } /* if (srcnativeicon && GetTagData(ICONDUPA_DuplicateImageData, TRUE, tags) == TRUE) */
214 #ifdef OUTPUT_DATA
215 kprintf("gadgetwidth = %ld\ngadgetheight = %ld\n",dobj->do_Gadget.Width,dobj->do_Gadget.Height);
216 #endif
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) &&
229 dobj->do_ToolWindow)
231 dobj->do_ToolWindow = StrDupIcon(dobj,icon->do_ToolWindow,IconBase);
232 if (!dobj->do_ToolWindow) goto fail;
235 if (GetTagData(ICONDUPA_DuplicateDrawerData, TRUE, tags) &&
236 icon->do_DrawerData)
238 LONG size;
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);
249 else
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) &&
278 icon->do_ToolTypes)
280 int num_tts;
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)))
287 int i;
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;
295 else
297 goto fail;
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));
306 return dobj;
308 fail:
309 FreeDiskObject(dobj);
310 return NULL;
312 AROS_LIBFUNC_EXIT
313 } /* FreeDiskObject */