childs -> children.
[AROS.git] / workbench / libs / icon / icon_intern.h
blob61da098926af75c3e016a6bc9b32f603f47368a0
1 #ifndef ICON_INTERN_H
2 #define ICON_INTERN_H
4 /*
5 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 $Id$
7 */
9 #include <exec/memory.h>
10 #include <exec/libraries.h>
11 #include <aros/asmcall.h>
12 #include <dos/dos.h>
13 #include <libraries/iffparse.h>
14 #include <cybergraphx/cybergraphics.h>
15 #include <workbench/workbench.h>
16 #include <workbench/icon.h>
17 #include <graphics/view.h>
19 #include <proto/alib.h>
20 #include <proto/exec.h>
21 #include <proto/intuition.h>
22 #include <proto/graphics.h>
23 #include <proto/icon.h>
24 #include <proto/iffparse.h>
25 #include <proto/utility.h>
26 #include <proto/cybergraphics.h>
27 #include <proto/dos.h>
29 #include <stddef.h>
31 #include <string.h>
32 #include <aros/libcall.h>
33 #include <aros/asmcall.h>
35 /****************************************************************************************/
37 /* Constants */
38 #define MAX_DEFICON_FILEPATH 256
40 /* Number of entries in the mementrys in the freelists */
41 #define FREELIST_MEMLISTENTRIES 10
43 /* This must be a power of 2 */
44 #ifdef __mc68000
45 #define ICONLIST_HASHSIZE 32 /* Save space on small memory m68k machines */
46 #else
47 #define ICONLIST_HASHSIZE 256
48 #endif
50 /****************************************************************************************/
52 /*
53 To get right alignment we make our very own memlist structure.
54 Look at the original struct MemList in <exec/memory.h> to see why.
57 struct IconInternalMemList
59 struct Node iiml_Node;
60 UWORD iiml_NumEntries;
61 struct MemEntry iiml_ME[FREELIST_MEMLISTENTRIES];
64 #define IMAGE35F_HASTRANSPARENTCOLOR 1
65 #define IMAGE35F_HASPALETTE 2
67 #define ICON35F_FRAMELESS 1
69 struct NativeIcon
71 struct MinNode ni_Node;
72 struct DiskObject ni_DiskObject;
73 struct FreeList ni_FreeList;
74 ULONG ni_ReadStruct_State;
76 /* Source icon data */
77 struct {
78 APTR Data; /* Raw IFF or PNG stream */
79 ULONG Size;
80 struct {
81 LONG Offset;
82 LONG Size;
83 } PNG[2];
84 } ni_Extra;
86 /* Parameters */
87 BOOL ni_IsDefault;
88 BOOL ni_Frameless;
89 ULONG ni_ScaleBox;
91 /* The 'laid out' icon. The laid out data will
92 * also be resized for the screen's aspect ratio,
93 * so the nil_Width and nil_Height will probably
94 * be different then the original image on some
95 * screens.
97 struct Screen *ni_Screen; /* Screen for the layout */
98 ULONG ni_Width; /* Dimension of the aspect */
99 ULONG ni_Height; /* ratio corrected icon */
101 /* Pens for drawing the border and frame */
102 UWORD ni_Pens[NUMDRIPENS]; /* Copied from DrawInfo for the screen */
104 struct NativeIconFace {
105 UBYTE Aspect; /* Source aspect ratio */
106 ULONG Width;
107 ULONG Height;
108 } ni_Face;
110 struct NativeIconImage {
111 /* This data was either allocated during icon load
112 * (and is in the ni_FreeList), or was provided by
113 * the user via IconControlA().
115 LONG TransparentColor;
116 ULONG Pens; /* Pens allocated for the layout */
117 const struct ColorRegister *Palette; /* one entry per pen */
118 const UBYTE *ImageData; /* 'ChunkyPixels' image */
119 const ULONG *ARGB; /* RGB+Alpha (A 0=transparent) */
121 /* Dynamically allocated by LayoutIconA(), and are
122 * _not_ in the ni_FreeList.
124 * You must call LayoutIconA(icon, NULL, NULL) or
125 * FreeDiskObject() to free this memory.
127 ULONG *Pen; /* Pallete n to Pen m mapping */
128 struct BitMap *BitMap; /* 'friend' of the Screen */
129 PLANEPTR BitMask; /* TransparentColor >= 0 bitmask */
130 APTR ARGBMap; /* ARGB, rescaled version */
132 /* For m68k legacy support, the struct Image render
133 * is stored here.
135 struct Image Render;
136 } ni_Image[2];
139 #define RSS_OLDDRAWERDATA_READ (1 << 0)
140 #define RSS_GADGETIMAGE_READ (1 << 1)
141 #define RSS_SELECTIMAGE_READ (1 << 2)
142 #define RSS_DEFAULTTOOL_READ (1 << 3)
143 #define RSS_TOOLWINDOW_READ (1 << 4)
144 #define RSS_TOOLTYPES_READ (1 << 5)
146 #define NATIVEICON(icon) ((struct NativeIcon *)((UBYTE *)(icon) - offsetof(struct NativeIcon, ni_DiskObject)))
148 /* Allocate, and save to an icon's freelist
150 #define AllocMemIcon(icon, size, req) \
151 ({ APTR _ret; struct DiskObject *_icon = (icon); \
152 ULONG _size = (ULONG)(size); \
153 ULONG _req = (ULONG)(req); \
154 _ret = AllocMem(_size, _req); \
155 if (_ret) AddFreeList((struct FreeList *)&_icon[1], _ret, _size); \
156 _ret; })
158 struct IconBase
160 struct Library ib_Lib;
162 struct Hook dsh;
163 struct SignalSemaphore iconlistlock;
164 struct MinList iconlists[ICONLIST_HASHSIZE];
166 ULONG *ib_CRCTable;
168 /* Global settings -----------------------------------------------------*/
169 struct Screen *ib_Screen;
170 LONG ib_Precision;
171 struct Rectangle ib_EmbossRectangle;
172 BOOL ib_Frameless;
173 ULONG ib_ScaleBox;
174 struct Hook *ib_IdentifyHook;
175 LONG ib_MaxNameLength;
176 BOOL ib_NewIconsSupport;
177 BOOL ib_ColorIconSupport;
178 BPTR ib_SegList;
180 /* Required External libraries */
181 APTR ib_DOSBase;
182 APTR ib_GfxBase;
183 APTR ib_IntuitionBase;
184 APTR ib_UtilityBase;
186 /* Optional external libraries */
187 APTR ib_CyberGfxBase;
188 APTR ib_IFFParseBase;
189 APTR ib_DataTypesBase;
190 APTR ib_WorkbenchBase;
193 typedef struct IconBase IconBase_T;
195 /* FIXME: Remove these #define xxxBase hacks
196 Do not use this in new code !
198 #define DOSBase (IconBase->ib_DOSBase)
199 #define GfxBase (IconBase->ib_GfxBase)
200 #define IntuitionBase (IconBase->ib_IntuitionBase)
201 #define UtilityBase (IconBase->ib_UtilityBase)
203 /****************************************************************************************/
205 extern struct ExecBase *SysBase;
207 /****************************************************************************************/
208 /* On-demand open of optional libraries. Just that is
209 * non-NULL before you use it!
211 extern const LONG IFFParseBase_version,
212 GfxBase_version,
213 CyberGfxBase_version,
214 DataTypesBase_version;
216 static inline APTR DemandOpenLibrary(struct Library **libp, CONST_STRPTR libname, ULONG version)
218 if (*libp == NULL)
219 *libp = OpenLibrary(libname, version);
221 return *libp;
224 #define IFFParseBase DemandOpenLibrary((struct Library **)&IconBase->ib_IFFParseBase, "iffparse.library", IFFParseBase_version)
225 #define CyberGfxBase DemandOpenLibrary((struct Library **)&IconBase->ib_CyberGfxBase, "cybergraphics.library", CyberGfxBase_version)
226 #define DataTypesBase DemandOpenLibrary((struct Library **)&IconBase->ib_DataTypesBase, "datatypes.library", DataTypesBase_version)
227 #define WorkbenchBase DemandOpenLibrary((struct Library **)&IconBase->ib_WorkbenchBase, "workbench.library", 0)
229 /****************************************************************************************/
231 /* Internal prototypes */
232 AROS_UFP3(LONG, dosstreamhook,
233 AROS_UFPA(struct Hook *, hook, A0),
234 AROS_UFPA(BPTR, file, A2),
235 AROS_UFPA(ULONG *, msg, A1)
238 #include "support.h"
240 UBYTE * WriteValue (LONG, UBYTE *);
242 BOOL ReadIcon35(struct NativeIcon *icon, struct Hook *streamhook, void *stream, struct IconBase *IconBase);
243 BOOL WriteIcon35(struct NativeIcon *icon, struct Hook *streamhook, void *stream, struct IconBase *IconBase);
244 VOID FreeIcon35(struct NativeIcon *icon, struct IconBase *IconBase);
245 VOID MakeMask35(UBYTE *imgdata, UBYTE *imgmask, UBYTE transpcolor, LONG imagew, LONG imageh);
247 BOOL ReadIconNI(struct NativeIcon *icon, struct Hook *streamhook, void *stream, struct IconBase *IconBase);
248 BOOL WriteIconNI(struct NativeIcon *icon, struct Hook *streamhook, void *stream, struct IconBase *IconBase);
249 VOID FreeIconNI(struct NativeIcon *icon, struct IconBase *IconBase);
251 /* Returns an ARGB image.
252 * Set &width == ~0 and &height == ~0 to get the size.
253 * Otherwise, sets the image size of width & height
255 ULONG *ReadMemPNG(struct DiskObject *icon, APTR stream, LONG *width, LONG *height, const CONST_STRPTR *chunknames, APTR *chunkpointer, struct IconBase *IconBase);
257 BOOL ReadIconPNG(struct DiskObject *dobj, BPTR file, struct IconBase *IconBase);
258 BOOL WriteIconPNG(BPTR file, struct DiskObject *dobj, struct IconBase *IconBase);
259 VOID FreeIconPNG(struct DiskObject *dobj, struct IconBase *IconBase);
262 #define LB(ib) ((struct IconBase *) (ib))
264 #endif /* ICON_INTERN_H */