Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / popupmenu / pmfind.c
blob132120b842bd4034c76f49fde81d096ce10fc234
1 //
2 // pmfind.c - Various support functions used to search the menu item tree.
3 //
4 // Copyright ©1996 - 2002 Henrik Isaksson
5 // All Rights Reserved.
6 //
8 #include "pmpriv.h"
11 // Find an item
14 // Find a selectable item after a->Selected. If none is found, return NULL.
15 struct PopupMenu *PM_FindNextSelectable(struct PM_Window *a, struct PopupMenu *pm, BOOL *found)
17 struct PopupMenu *tmp;
19 if(pm) do {
20 if(pm->Flags&NPM_GROUP) {
21 tmp=PM_FindNextSelectable(a, pm->Sub, found);
22 if(tmp) {
23 if(*found)
24 return tmp;
28 if(!(pm->Flags&NPM_NOSELECT) && !(pm->Flags&NPM_HIDDEN) && *found)
29 return pm;
31 if(pm==a->Selected) {
32 *found=TRUE;
35 pm=pm->Next;
36 } while(pm);
38 return NULL;
41 // Find the first selectable item in the menu. If none is found, return NULL.
42 struct PopupMenu *PM_FindFirstSelectable(struct PopupMenu *pm)
44 struct PopupMenu *tmp;
46 if(pm) do {
47 if(pm->Flags&NPM_GROUP) {
48 tmp=PM_FindFirstSelectable(pm->Sub);
49 if(tmp) {
50 return tmp;
54 if(!(pm->Flags&NPM_NOSELECT) && !(pm->Flags&NPM_HIDDEN))
55 return pm;
57 pm=pm->Next;
58 } while(pm);
60 return NULL;
64 // Find a selectable item ahead of a->Selected. If none is found, return NULL.
65 struct PopupMenu *PM_FindPrevSelectable(struct PM_Window *a, struct PopupMenu *pm, BOOL *found)
67 struct PopupMenu *prv=NULL, *tmp;
69 if(pm) do {
70 if(pm->Flags&NPM_GROUP) {
71 tmp=PM_FindPrevSelectable(a, pm->Sub, found);
72 if(tmp) {
73 if(*found)
74 return tmp;
75 prv=tmp;
76 } else if(*found)
77 return prv;
80 if(pm==a->Selected) {
81 *found=TRUE;
82 return prv;
84 if(!(pm->Flags&NPM_NOSELECT) && !(pm->Flags&NPM_HIDDEN))
85 prv=pm;
86 pm=pm->Next;
87 } while(pm);
89 return prv;
92 // Find the last selectable item in the menu. If none is found, return NULL.
93 struct PopupMenu *PM_FindLastSelectable(struct PopupMenu *pm)
95 struct PopupMenu *prv=NULL, *tmp;
97 if(pm) do {
98 if(pm->Flags&NPM_GROUP) {
99 tmp=PM_FindLastSelectable(pm->Sub);
100 if(tmp) {
101 prv=tmp;
103 } else if(!(pm->Flags&NPM_NOSELECT) && !(pm->Flags&NPM_HIDDEN))
104 prv=pm;
106 pm=pm->Next;
107 } while(pm);
109 return prv;
112 // PM_FindID - Find an item based on it's ID
113 struct PopupMenu *PM_FindID(struct PopupMenu *base, ULONG ID)
115 struct PopupMenu *pm=base,*xm;
117 while(pm) {
118 if(pm->ID==ID) return pm;
119 if(pm->Sub) {
120 xm=PM_FindID(pm->Sub, ID);
121 if(xm) return xm;
123 pm=pm->Next;
125 return NULL;
128 // PM_FindBeforeID - find the item before item with ID in pm
129 struct PopupMenu *PM_FindBeforeID(struct PopupMenu *pm, ULONG ID)
131 struct PopupMenu *prev=pm,*xm;
133 while(pm) {
134 if(pm->ID==ID) return prev;
135 if(pm->Sub) {
136 xm=PM_FindBeforeID(pm->Sub, ID);
137 if(xm) return xm;
139 prev=pm;
140 pm=pm->Next;
142 return NULL;
145 // PM_FindBefore - Find the item before fm in pm
146 struct PopupMenu *PM_FindBefore(struct PopupMenu *pm, struct PopupMenu *fm)
148 struct PopupMenu *prev=pm,*xm;
150 while(pm) {
151 if(pm==fm) return prev;
152 if(pm->Sub) {
153 xm=PM_FindBefore(pm->Sub, fm);
154 if(xm) return xm;
156 prev=pm;
157 pm=pm->Next;
159 return NULL;
162 // PM_FindSortedInsertPoint - find where to insert the item fm in the list pm
163 struct PopupMenu *PM_FindSortedInsertPoint(struct PopupMenu *pm, struct PopupMenu *fm)
165 struct PopupMenu *prev=pm;
167 while(pm) {
168 if(PM_String_Compare(pm->Title, fm->Title) < 0)
169 return prev;
170 prev=pm;
171 pm=pm->Next;
173 return NULL;
176 // PM_FindLast - Find the end of the list.
177 struct PopupMenu *PM_FindLast(struct PopupMenu *base)
179 struct PopupMenu *pm=base;
181 while(pm) {
182 if(pm->Next==NULL) return pm;
183 pm=pm->Next;
186 return NULL;
189 // PM_FindItemCommKey - Find an item based on it's CommKey (command key)
190 struct PopupMenu *PM_FindItemCommKey(struct PopupMenu *base, UBYTE key)
192 struct PopupMenu *pm=base,*xm;
194 while(pm) {
195 if(ToUpper((UBYTE)pm->CommKey)==ToUpper(key)) return pm;
197 if(pm->Sub) {
198 xm=PM_FindItemCommKey(pm->Sub, key);
199 if(xm) return xm;
201 pm=pm->Next;
203 return NULL;
206 // PM_FindItem - find an item based on it's ID
207 struct PopupMenu * __saveds ASM PM_FindItem(register __a1 struct PopupMenu *menu GNUCREG(a1),
208 register __d1 ULONG ID GNUCREG(d1))
211 if(!menu) return NULL;
212 return PM_FindID(menu, ID);
216 // See if an item is checked
218 BOOL __saveds ASM PM_ItemChecked(register __a1 struct PopupMenu *pm GNUCREG(a1),
219 register __d1 ULONG ID GNUCREG(d1))
221 struct PopupMenu *p;
223 p=PM_FindID(pm, ID);
225 if(p) {
226 if(p->Flags&NPM_CHECKED) return TRUE;
227 return FALSE;
229 return -5L;
233 // Set/Clear all items in a list
236 void __saveds ASM PM_AlterState(register __a1 struct PopupMenu *base GNUCREG(a1),
237 register __a2 struct PM_IDLst *ids GNUCREG(a2),
238 register __d1 UWORD action GNUCREG(d1))
240 struct PopupMenu *pm;
241 struct PM_IDLst *id=ids;
243 while(id) {
244 pm=PM_FindID(base, id->ID);
245 if(pm) {
246 if(action==PMACT_SELECT) {
247 if(id->Kind==IDKND_REFLECT) {
248 pm->Flags|=NPM_CHECKED|NPM_ISSELECTED;
249 if(pm->AutoSetPtr) *pm->AutoSetPtr=TRUE;
250 } else if(id->Kind==IDKND_INVERSE) {
251 pm->Flags&=~(NPM_CHECKED|NPM_ISSELECTED);
252 if(pm->AutoSetPtr) *pm->AutoSetPtr=FALSE;
253 } else if(id->Kind==IDKND_INCLUDE) {
254 pm->Flags|=NPM_CHECKED|NPM_ISSELECTED;
255 if(pm->AutoSetPtr) *pm->AutoSetPtr=TRUE;
256 } else if(id->Kind==IDKND_EXCLUDE) {
257 pm->Flags&=~(NPM_CHECKED|NPM_ISSELECTED);
258 if(pm->AutoSetPtr) *pm->AutoSetPtr=FALSE;
260 } else if(action==PMACT_DESELECT) {
261 if(id->Kind==IDKND_INVERSE) {
262 pm->Flags|=NPM_CHECKED|NPM_ISSELECTED;
263 if(pm->AutoSetPtr) *pm->AutoSetPtr=TRUE;
264 } else if(id->Kind==IDKND_REFLECT) {
265 pm->Flags&=~(NPM_CHECKED|NPM_ISSELECTED);
266 if(pm->AutoSetPtr) *pm->AutoSetPtr=FALSE;
270 id=id->Next;