ilbmtoicon: Refuse to generate icons with differently sized select and normal images
[AROS.git] / tools / genmodule / oopsupport.c
blob8cf890b0433b31ebdf9995e2d02ce3201aca1170
1 /*
2 Copyright © 2005-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Support functions for oop.library classes. Part of genmodule.
6 */
7 #include "genmodule.h"
8 #include "oopsupport.h"
10 void writeoopincludes(FILE *out)
12 fprintf
14 out,
15 "#include <proto/oop.h>\n"
16 "#include <oop/oop.h>\n"
17 "#include <hidd/hidd.h>\n"
18 "\n"
22 void writeoopinit(FILE *out, struct classinfo *cl)
24 struct functionhead *methlistit;
25 struct functionarg *arglistit;
26 struct stringlist *interface;
27 int methods;
28 fprintf
30 out,
31 "/* Initialisation routines of a OOP class */\n"
32 "/* =======================================*/\n"
33 "\n"
36 if (cl->classdatatype == NULL)
37 fprintf(out, "# define %s_DATA_SIZE (0)\n", cl->basename);
38 else
39 fprintf
41 out,
42 "# define %s_DATA_SIZE (sizeof(%s))\n",
43 cl->basename, cl->classdatatype
46 /* Write defines of methods */
47 writefuncdefs(out, NULL, cl->methlist);
49 fprintf
51 out,
52 "\n"
53 "\n"
54 "/*** Library startup and shutdown *******************************************/\n"
55 "static int OOP_%s_Startup(LIBBASETYPEPTR LIBBASE)\n"
56 "{\n"
57 "#ifdef GM_OOPBASE_FIELD\n"
58 " struct Library *OOPBase = GM_OOPBASE_FIELD(LIBBASE);\n"
59 "#endif\n"
60 " OOP_AttrBase MetaAttrBase = OOP_ObtainAttrBase(IID_Meta);\n"
61 " OOP_Class *cl = NULL;\n"
62 "\n",
63 cl->basename
66 /* Write variables initialization */
67 for (methlistit = cl->methlist, interface = NULL, methods = 0;
68 methlistit != NULL;
69 methlistit = methlistit->next
72 if (interface != methlistit->interface)
74 if (interface != NULL)
76 /* Close the previous declaration */
77 fprintf(out,
78 " {NULL, 0}\n"
79 " };\n"
80 "#define NUM_%s_%s_METHODS %d\n"
81 "\n",
82 cl->basename, interface->s, methods
86 /* Start new MethodDescr declaration */
87 fprintf(out, " struct OOP_MethodDescr %s_%s_descr[] =\n {\n",
88 cl->basename, methlistit->interface->s
90 methods = 1;
91 interface = methlistit->interface;
93 else
94 methods++;
96 fprintf(out, " {(OOP_MethodFunc)%s, %s},\n",
97 methlistit->internalname, methlistit->method
100 if (methods) {
101 /* Close the last declaration */
102 fprintf(out,
103 " {NULL, 0}\n"
104 " };\n"
105 "#define NUM_%s_%s_METHODS %d\n"
106 "\n",
107 cl->basename, interface->s, methods
111 /* Write the interface description */
112 fprintf(out, " struct OOP_InterfaceDescr %s_ifdescr[] =\n {\n", cl->basename);
113 for (interface = cl->interfaces; interface != NULL; interface = interface->next)
115 fprintf(out,
116 " {%s_%s_descr, IID_%s, NUM_%s_%s_METHODS},\n",
117 cl->basename, interface->s,
118 interface->s,
119 cl->basename, interface->s
122 fprintf(out,
123 " {NULL, NULL}\n"
124 " };\n"
125 "\n"
128 /* Write the class creation TagList */
129 fprintf(out,
130 " struct TagItem %s_tags[] =\n"
131 " {\n",
132 cl->basename
134 if (cl->superclass != NULL)
135 fprintf(out,
136 " {aMeta_SuperID, (IPTR)%s},\n",
137 cl->superclass
139 else if (cl->superclass_field != NULL)
140 fprintf(out,
141 " {aMeta_SuperPtr, (IPTR)LIBBASE->%s},\n",
142 cl->superclass_field
144 else
146 fprintf(stderr, "Internal error: both superclass and superclass_field are NULL\n");
147 exit(20);
150 fprintf(out,
151 " {aMeta_InterfaceDescr, (IPTR)%s_ifdescr},\n"
152 " {aMeta_InstSize, (IPTR)%s_DATA_SIZE},\n",
153 cl->basename,
154 cl->basename
156 if (cl->classid != NULL)
157 fprintf(out,
158 " {aMeta_ID, (IPTR)%s},\n",
159 cl->classid
161 fprintf(out, " {TAG_DONE, (IPTR)0}\n };\n");
163 /* Write class constructor */
164 fprintf
166 out,
167 "\n"
168 " if (MetaAttrBase == 0)\n"
169 " return FALSE;\n"
170 "\n"
171 " cl = OOP_NewObject(NULL, CLID_HiddMeta, %s_tags);\n"
172 " if (cl != NULL)\n"
173 " {\n"
174 " cl->UserData = (APTR)LIBBASE;\n"
175 " %s_CLASSPTR_FIELD(LIBBASE) = cl;\n"
176 " OOP_AddClass(cl);\n"
177 " }\n"
178 "\n"
179 " OOP_ReleaseAttrBase(IID_Meta);\n"
180 " return cl != NULL;\n"
181 "}\n",
182 cl->basename,
183 cl->basename,
184 cl->basename
187 /* Write class destructor */
188 fprintf
190 out,
191 "static void OOP_%s_Shutdown(LIBBASETYPEPTR LIBBASE)\n"
192 "{\n"
193 "#ifdef GM_OOPBASE_FIELD\n"
194 " struct Library *OOPBase = GM_OOPBASE_FIELD(LIBBASE);\n"
195 "#endif\n"
196 " if (%s_CLASSPTR_FIELD(LIBBASE) != NULL)\n"
197 " {\n"
198 " OOP_RemoveClass(%s_CLASSPTR_FIELD(LIBBASE));\n"
199 " OOP_DisposeObject((OOP_Object *)%s_CLASSPTR_FIELD(LIBBASE));\n"
200 " }\n"
201 "\n"
202 // " return TRUE;\n"
203 "}\n",
204 cl->basename,
205 cl->basename,
206 cl->basename,
207 cl->basename
210 fprintf
212 out,
213 "ADD2INITCLASSES(OOP_%s_Startup, %d);\n"
214 "ADD2EXPUNGECLASSES(OOP_%s_Shutdown, %d);\n",
215 cl->basename, -cl->initpri,
216 cl->basename, -cl->initpri