grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / popupmenu / pmcreate.c
blob517edd3ade57e4381ac74477e299a28d4104dfa8
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;
104 struct TagItem *tstate;
105 struct PM_IDLst *first=0L, *last=0L, *n=0L;
106 BOOL error=0;
108 tstate = tags;
109 while((tag=NextTagItem(&tstate))) {
110 switch(tag->ti_Tag) {
111 case PM_ExcludeID:
112 n=PM_Mem_Alloc(sizeof(struct PM_IDLst));
113 if(n) {
114 n->Next=0L;
115 n->ID=tag->ti_Data;
116 n->Kind=IDKND_EXCLUDE;
117 n->Flags=0L;
119 if(last) {
120 last->Next=n;
121 last=last->Next;
122 } else {
123 last=first=n;
125 } else error=1;
126 break;
127 case PM_IncludeID:
128 n=PM_Mem_Alloc(sizeof(struct PM_IDLst));
129 if(n) {
130 n->Next=0L;
131 n->ID=tag->ti_Data;
132 n->Kind=IDKND_INCLUDE;
133 n->Flags=0L;
135 if(last) {
136 last->Next=n;
137 last=last->Next;
138 } else {
139 last=first=n;
141 } else error=1;
142 break;
143 case PM_ReflectID:
144 n=PM_Mem_Alloc(sizeof(struct PM_IDLst));
145 if(n) {
146 n->Next=0L;
147 n->ID=tag->ti_Data;
148 n->Kind=IDKND_REFLECT;
149 n->Flags=0L;
151 if(last) {
152 last->Next=n;
153 last=last->Next;
154 } else {
155 last=first=n;
157 } else error=1;
158 break;
159 case PM_InverseID:
160 n=PM_Mem_Alloc(sizeof(struct PM_IDLst));
161 if(n) {
162 n->Next=0L;
163 n->ID=tag->ti_Data;
164 n->Kind=IDKND_INVERSE;
165 n->Flags=0L;
167 if(last) {
168 last->Next=n;
169 last=last->Next;
170 } else {
171 last=first=n;
173 } else error=1;
174 break;
178 if(error) {
179 PM_FreeIDList(first);
180 first=0L;
183 return first;
186 struct PM_IDLst * __saveds ASM PM_ExLstA(register __a1 ULONG *id GNUCREG(a1))
188 struct PM_IDLst *first=0L, *last=0L, *n=0L;
189 BOOL error=0;
190 int i=0;
192 while(id[i]) {
193 n=PM_Mem_Alloc(sizeof(struct PM_IDLst));
194 if(n) {
195 n->Next=0L;
196 n->ID=id[i];
197 n->Kind=IDKND_EXCLUDE;
198 n->Flags=0L;
200 if(last) {
201 last->Next=n;
202 last=last->Next;
203 } else {
204 last=first=n;
206 } else error=1;
207 i++;
210 if(error) {
211 PM_FreeIDList(first);
212 first=0L;
215 return first;
219 // Allocate local variables to save stack
221 struct PM_Root *PM_AllocPMRoot(struct Window *w)
223 struct PM_Root *p;
225 p=PM_Mem_Alloc(sizeof(struct PM_Root));
226 if(p) {
227 p->ShadowWidth=p->ShadowHeight=4;
228 p->ShadowAddX=p->ShadowAddY=2;
230 p->BorderWidth=p->BorderHeight=1;
232 p->DrawInfo=GetScreenDrawInfo(w->WScreen);
234 p->PM=0L;
236 return p;
238 return NULL;