2 // pmfind.c - Various support functions used to search the menu item tree.
4 // Copyright ©1996 - 2002 Henrik Isaksson
5 // All Rights Reserved.
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
;
20 if(pm
->Flags
&NPM_GROUP
) {
21 tmp
=PM_FindNextSelectable(a
, pm
->Sub
, found
);
28 if(!(pm
->Flags
&NPM_NOSELECT
) && !(pm
->Flags
&NPM_HIDDEN
) && *found
)
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
;
47 if(pm
->Flags
&NPM_GROUP
) {
48 tmp
=PM_FindFirstSelectable(pm
->Sub
);
54 if(!(pm
->Flags
&NPM_NOSELECT
) && !(pm
->Flags
&NPM_HIDDEN
))
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
;
70 if(pm
->Flags
&NPM_GROUP
) {
71 tmp
=PM_FindPrevSelectable(a
, pm
->Sub
, found
);
84 if(!(pm
->Flags
&NPM_NOSELECT
) && !(pm
->Flags
&NPM_HIDDEN
))
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
;
98 if(pm
->Flags
&NPM_GROUP
) {
99 tmp
=PM_FindLastSelectable(pm
->Sub
);
103 } else if(!(pm
->Flags
&NPM_NOSELECT
) && !(pm
->Flags
&NPM_HIDDEN
))
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
;
118 if(pm
->ID
==ID
) return pm
;
120 xm
=PM_FindID(pm
->Sub
, ID
);
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
;
134 if(pm
->ID
==ID
) return prev
;
136 xm
=PM_FindBeforeID(pm
->Sub
, ID
);
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
;
151 if(pm
==fm
) return prev
;
153 xm
=PM_FindBefore(pm
->Sub
, fm
);
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
;
168 if(PM_String_Compare(pm
->Title
, fm
->Title
) < 0)
176 // PM_FindLast - Find the end of the list.
177 struct PopupMenu
*PM_FindLast(struct PopupMenu
*base
)
179 struct PopupMenu
*pm
=base
;
182 if(pm
->Next
==NULL
) return pm
;
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
;
195 if(ToUpper((UBYTE
)pm
->CommKey
)==ToUpper(key
)) return pm
;
198 xm
=PM_FindItemCommKey(pm
->Sub
, key
);
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
))
226 if(p
->Flags
&NPM_CHECKED
) return TRUE
;
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
;
244 pm
=PM_FindID(base
, id
->ID
);
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
;