2 // pmfind.c - Various support functions used to search the menu item tree.
4 // Copyright ©1996 - 2002 Henrik Isaksson
5 // All Rights Reserved.
17 // Find a selectable item after a->Selected. If none is found, return NULL.
18 struct PopupMenu
*PM_FindNextSelectable(struct PM_Window
*a
, struct PopupMenu
*pm
, BOOL
*found
)
20 struct PopupMenu
*tmp
;
23 if (pm
->Flags
&NPM_GROUP
) {
24 tmp
=PM_FindNextSelectable(a
, pm
->SubGroup
.Sub
, found
);
31 if (!(pm
->Flags
&NPM_NOSELECT
) && !(pm
->Flags
&NPM_HIDDEN
) && *found
)
34 if (pm
==a
->Selected
) {
44 // Find the first selectable item in the menu. If none is found, return NULL.
45 struct PopupMenu
*PM_FindFirstSelectable(struct PopupMenu
*pm
)
47 struct PopupMenu
*tmp
;
50 if (pm
->Flags
&NPM_GROUP
) {
51 tmp
=PM_FindFirstSelectable(pm
->SubGroup
.Sub
);
57 if (!(pm
->Flags
&NPM_NOSELECT
) && !(pm
->Flags
&NPM_HIDDEN
))
67 // Find a selectable item ahead of a->Selected. If none is found, return NULL.
68 struct PopupMenu
*PM_FindPrevSelectable(struct PM_Window
*a
, struct PopupMenu
*pm
, BOOL
*found
)
70 struct PopupMenu
*prv
=NULL
, *tmp
;
73 if (pm
->Flags
&NPM_GROUP
) {
74 tmp
=PM_FindPrevSelectable(a
, pm
->SubGroup
.Sub
, found
);
83 if (pm
==a
->Selected
) {
87 if (!(pm
->Flags
&NPM_NOSELECT
) && !(pm
->Flags
&NPM_HIDDEN
))
95 // Find the last selectable item in the menu. If none is found, return NULL.
96 struct PopupMenu
*PM_FindLastSelectable(struct PopupMenu
*pm
)
98 struct PopupMenu
*prv
=NULL
, *tmp
;
101 if (pm
->Flags
&NPM_GROUP
) {
102 tmp
=PM_FindLastSelectable(pm
->SubGroup
.Sub
);
106 } else if (!(pm
->Flags
&NPM_NOSELECT
) && !(pm
->Flags
&NPM_HIDDEN
))
115 // PM_FindID - Find an item based on it's ID
116 struct PopupMenu
*PM_FindID(struct PopupMenu
*base
, ULONG ID
)
118 struct PopupMenu
*pm
=base
,*xm
;
121 if (pm
->ID
==ID
) return pm
;
122 if (pm
->SubGroup
.Sub
) {
123 xm
=PM_FindID(pm
->SubGroup
.Sub
, ID
);
131 // PM_FindBeforeID - find the item before item with ID in pm
132 struct PopupMenu
*PM_FindBeforeID(struct PopupMenu
*pm
, ULONG ID
)
134 struct PopupMenu
*prev
=pm
,*xm
;
137 if (pm
->ID
==ID
) return prev
;
138 if (pm
->SubGroup
.Sub
) {
139 xm
=PM_FindBeforeID(pm
->SubGroup
.Sub
, ID
);
148 // PM_FindBefore - Find the item before fm in pm
149 struct PopupMenu
*PM_FindBefore(struct PopupMenu
*pm
, struct PopupMenu
*fm
)
151 struct PopupMenu
*prev
=pm
,*xm
;
154 if (pm
==fm
) return prev
;
155 if (pm
->SubGroup
.Sub
) {
156 xm
=PM_FindBefore(pm
->SubGroup
.Sub
, fm
);
165 // PM_FindSortedInsertPoint - find where to insert the item fm in the list pm
166 struct PopupMenu
*PM_FindSortedInsertPoint(struct PopupMenu
*pm
, struct PopupMenu
*fm
)
168 struct PopupMenu
*prev
=pm
;
171 if (PM_String_Compare(pm
->TitleUnion
.Title
, fm
->TitleUnion
.Title
) < 0)
179 // PM_FindLast - Find the end of the list.
180 struct PopupMenu
*PM_FindLast(struct PopupMenu
*base
)
182 struct PopupMenu
*pm
=base
;
185 if (pm
->Next
==NULL
) return pm
;
192 // PM_FindItemCommKey - Find an item based on it's CommKey (command key)
193 struct PopupMenu
*PM_FindItemCommKey(struct PopupMenu
*base
, UBYTE key
)
195 struct PopupMenu
*pm
=base
,*xm
;
198 if (ToUpper((UBYTE
)pm
->CommKey
)==ToUpper(key
)) return pm
;
200 if (pm
->SubGroup
.Sub
) {
201 xm
=PM_FindItemCommKey(pm
->SubGroup
.Sub
, key
);
209 // PM_FindItem - find an item based on it's ID
210 LIBFUNC_P3(struct PopupMenu
*, LIBPM_FindItem
,
211 A1
, struct PopupMenu
*, menu
,
213 A6
, struct PopupMenuBase
*, l
)
217 if (!menu
) return NULL
;
218 return PM_FindID(menu
, ID
);
223 // See if an item is checked
225 LIBFUNC_P3(BOOL
, LIBPM_ItemChecked
,
226 A1
, struct PopupMenu
*, pm
,
228 A6
, struct PopupMenuBase
*, l
);
237 if (p
->Flags
&NPM_CHECKED
) return TRUE
;
245 // Set/Clear all items in a list
248 LIBFUNC_P4(void, LIBPM_AlterState
,
249 A1
, struct PopupMenu
*, base
,
250 A2
, struct PM_IDLst
*, ids
,
252 A6
, struct PopupMenuBase
*, l
)
256 pm_AlterState(base
, ids
, action
);
261 void pm_AlterState(struct PopupMenu
*base
, struct PM_IDLst
*ids
, UWORD action
)
263 struct PopupMenu
*pm
;
264 struct PM_IDLst
*id
=ids
;
266 pm
=PM_FindID(base
, id
->ID
);
268 if (action
==PMACT_SELECT
) {
269 if (id
->Kind
==IDKND_REFLECT
) {
270 pm
->Flags
|=NPM_CHECKED
|NPM_ISSELECTED
;
271 if (pm
->AutoSetPtr
) *pm
->AutoSetPtr
=TRUE
;
272 } else if (id
->Kind
==IDKND_INVERSE
) {
273 pm
->Flags
&=~(NPM_CHECKED
|NPM_ISSELECTED
);
274 if (pm
->AutoSetPtr
) *pm
->AutoSetPtr
=FALSE
;
275 } else if (id
->Kind
==IDKND_INCLUDE
) {
276 pm
->Flags
|=NPM_CHECKED
|NPM_ISSELECTED
;
277 if (pm
->AutoSetPtr
) *pm
->AutoSetPtr
=TRUE
;
278 } else if (id
->Kind
==IDKND_EXCLUDE
) {
279 pm
->Flags
&=~(NPM_CHECKED
|NPM_ISSELECTED
);
280 if (pm
->AutoSetPtr
) *pm
->AutoSetPtr
=FALSE
;
282 } else if (action
==PMACT_DESELECT
) {
283 if (id
->Kind
==IDKND_INVERSE
) {
284 pm
->Flags
|=NPM_CHECKED
|NPM_ISSELECTED
;
285 if (pm
->AutoSetPtr
) *pm
->AutoSetPtr
=TRUE
;
286 } else if (id
->Kind
==IDKND_REFLECT
) {
287 pm
->Flags
&=~(NPM_CHECKED
|NPM_ISSELECTED
);
288 if (pm
->AutoSetPtr
) *pm
->AutoSetPtr
=FALSE
;