add casts to zune macros to silence some warnings
[tangerine.git] / workbench / libs / popupmenu / pmcreate.c
blob930957ba5113d52def2dbba83f3ea6300765395c
1 //
2 // PopupMenu
3 // ©1996-2002 Henrik Isaksson
4 //
5 // Menu creation/disposal & id list functions
6 //
8 #include "pmpriv.h"
10 void FreeIDList(struct PM_IDLst *f)
12 if(f) {
13 struct PM_IDLst *n;
15 while(f) {
16 n=f->Next;
17 PM_Mem_Free(f);
18 f=n;
23 void PM_FreeTitle(struct PopupMenu *p)
25 if(!p) return;
27 if(p->Title && GET_TXTMODE(p)==0) PM_Mem_Free(p->Title);
29 p->Title=NULL;
32 void __saveds ASM PM_FreePopupMenu(register __a1 struct PopupMenu *p GNUCREG(a1))
34 if(p) {
35 struct PopupMenu *n;
37 while(p) {
38 n=p->Next;
39 if(p->Sub) PM_FreePopupMenu(p->Sub);
40 PM_FreeTitle(p);
41 if(p->UserData && (p->Flags&NPM_UDATASTRING)) PM_Mem_Free(p->UserData);
42 if(p->Exclude && !(p->Flags&NPM_EXCLUDE_SHARED)) {
43 FreeIDList(p->Exclude);
45 PM_Mem_Free(p);
46 p=n;
51 void __saveds ASM PM_FreeIDList(
52 register __a0 struct PM_IDLst *f GNUCREG(a0))
54 FreeIDList(f);
57 struct PopupMenu *__saveds ASM PM_MakeItemA(register __a1 struct TagItem *tags GNUCREG(a1))
59 struct PopupMenu *p;
61 p=PM_Mem_Alloc(sizeof(struct PopupMenu));
62 if(p) {
63 PM_SetItemAttrsA(p, tags);
65 return p;
68 return NULL;
71 struct PopupMenu * __saveds ASM PM_MakeMenuA(register __a1 struct TagItem *tags GNUCREG(a1))
73 struct TagItem *tag, *tstate;
74 struct PopupMenu *first=0L, *last=0L;
75 BOOL error=0;
77 tstate = tags;
78 while((tag=NextTagItem(&tstate))) {
79 switch(tag->ti_Tag) {
80 case PM_Item:
81 if(tag->ti_Data) {
82 if(last) {
83 last->Next=(struct PopupMenu *)tag->ti_Data;
84 last=last->Next;
85 } else {
86 last=first=(struct PopupMenu *)tag->ti_Data;
88 } else error=1;
89 break;
93 if(error) {
94 PM_FreePopupMenu(first);
95 first=0L;
98 return first;
101 struct PM_IDLst * __saveds ASM PM_MakeIDListA(register __a1 struct TagItem *tags GNUCREG(a1))
103 struct TagItem *tag, *tstate;
104 struct PM_IDLst *first=0L, *last=0L, *n=0L;
105 BOOL error=0;
107 tstate = tags;
108 while((tag=NextTagItem(&tstate))) {
109 switch(tag->ti_Tag) {
110 case PM_ExcludeID:
111 n=PM_Mem_Alloc(sizeof(struct PM_IDLst));
112 if(n) {
113 n->Next=0L;
114 n->ID=tag->ti_Data;
115 n->Kind=IDKND_EXCLUDE;
116 n->Flags=0L;
118 if(last) {
119 last->Next=n;
120 last=last->Next;
121 } else {
122 last=first=n;
124 } else error=1;
125 break;
126 case PM_IncludeID:
127 n=PM_Mem_Alloc(sizeof(struct PM_IDLst));
128 if(n) {
129 n->Next=0L;
130 n->ID=tag->ti_Data;
131 n->Kind=IDKND_INCLUDE;
132 n->Flags=0L;
134 if(last) {
135 last->Next=n;
136 last=last->Next;
137 } else {
138 last=first=n;
140 } else error=1;
141 break;
142 case PM_ReflectID:
143 n=PM_Mem_Alloc(sizeof(struct PM_IDLst));
144 if(n) {
145 n->Next=0L;
146 n->ID=tag->ti_Data;
147 n->Kind=IDKND_REFLECT;
148 n->Flags=0L;
150 if(last) {
151 last->Next=n;
152 last=last->Next;
153 } else {
154 last=first=n;
156 } else error=1;
157 break;
158 case PM_InverseID:
159 n=PM_Mem_Alloc(sizeof(struct PM_IDLst));
160 if(n) {
161 n->Next=0L;
162 n->ID=tag->ti_Data;
163 n->Kind=IDKND_INVERSE;
164 n->Flags=0L;
166 if(last) {
167 last->Next=n;
168 last=last->Next;
169 } else {
170 last=first=n;
172 } else error=1;
173 break;
177 if(error) {
178 PM_FreeIDList(first);
179 first=0L;
182 return first;
185 struct PM_IDLst * __saveds ASM PM_ExLstA(register __a1 ULONG *id GNUCREG(a1))
187 struct PM_IDLst *first=0L, *last=0L, *n=0L;
188 BOOL error=0;
189 int i=0;
191 while(id[i]) {
192 n=PM_Mem_Alloc(sizeof(struct PM_IDLst));
193 if(n) {
194 n->Next=0L;
195 n->ID=id[i];
196 n->Kind=IDKND_EXCLUDE;
197 n->Flags=0L;
199 if(last) {
200 last->Next=n;
201 last=last->Next;
202 } else {
203 last=first=n;
205 } else error=1;
206 i++;
209 if(error) {
210 PM_FreeIDList(first);
211 first=0L;
214 return first;
218 // Allocate local variables to save stack
220 struct PM_Root *PM_AllocPMRoot(struct Window *w)
222 struct PM_Root *p;
224 p=PM_Mem_Alloc(sizeof(struct PM_Root));
225 if(p) {
226 p->ShadowWidth=p->ShadowHeight=4;
227 p->ShadowAddX=p->ShadowAddY=2;
229 p->BorderWidth=p->BorderHeight=1;
231 p->DrawInfo=GetScreenDrawInfo(w->WScreen);
233 p->PM=0L;
235 return p;
237 return NULL;