Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / muimaster / classes / poplist.c
blobb137b0fe562305617b692be476db3263d924c340
1 /*
2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/memory.h>
9 #include <clib/alib_protos.h>
10 #include <proto/exec.h>
11 #include <proto/dos.h>
12 #include <proto/utility.h>
13 #include <proto/intuition.h>
14 #include <proto/muimaster.h>
16 #include <string.h>
17 #include <stdio.h>
19 #include "mui.h"
20 #include "muimaster_intern.h"
21 #include "support.h"
22 #include "support_classes.h"
23 #include "debug.h"
24 #include "poplist_private.h"
26 extern struct Library *MUIMasterBase;
28 LONG PoplistStrObjFunc(struct Hook *hook, Object *popup, Object *str)
30 struct Poplist_DATA *data = (struct Poplist_DATA *)hook->h_Data;
31 STRPTR strtext, listentry;
32 LONG index;
34 get(str, MUIA_String_Contents, &strtext);
36 for(index = 0; ; index++)
38 DoMethod(data->list, MUIM_List_GetEntry, index, (IPTR)&listentry);
40 if (!listentry)
42 set(data->list, MUIA_List_Active, MUIV_List_Active_Off);
43 break;
46 if (stricmp(strtext, listentry) == 0)
48 set(data->list, MUIA_List_Active, index);
49 break;
53 return TRUE;
56 void PoplistObjStrFunc(struct Hook *hook, Object *popup, Object *str)
58 STRPTR listentry;
60 DoMethod(popup, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR)&listentry);
62 if (listentry)
64 set(str, MUIA_String_Contents, listentry);
68 IPTR Poplist__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
70 STRPTR array = (STRPTR)GetTagData(MUIA_Poplist_Array, 0, msg->ops_AttrList);
71 Object *lv, *list;
73 obj = (Object *)DoSuperNewTags
75 cl, obj, NULL,
76 MUIA_Popobject_Object, (IPTR)(lv = (Object *)ListviewObject,
77 MUIA_Listview_List, (IPTR)(list = (Object *)ListObject,
78 InputListFrame,
79 array ? MUIA_List_SourceArray : TAG_IGNORE, (IPTR)array,
80 End),
81 End),
82 TAG_MORE, (IPTR) msg->ops_AttrList
85 if (obj)
87 struct Poplist_DATA *data = INST_DATA(cl, obj);
89 data->list = list;
91 data->strobj_hook.h_Entry = HookEntry;
92 data->strobj_hook.h_SubEntry = (HOOKFUNC)PoplistStrObjFunc;
93 data->strobj_hook.h_Data = data;
95 data->objstr_hook.h_Entry = HookEntry;
96 data->objstr_hook.h_SubEntry = (HOOKFUNC)PoplistObjStrFunc;
97 data->objstr_hook.h_Data = data;
99 SetAttrs(obj, MUIA_Popobject_StrObjHook, (IPTR)&data->strobj_hook,
100 MUIA_Popobject_ObjStrHook, (IPTR)&data->objstr_hook,
101 TAG_DONE);
103 DoMethod(lv, MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
104 (IPTR)obj, 2, MUIM_Popstring_Close, TRUE);
107 return (IPTR)obj;
110 #if ZUNE_BUILTIN_POPLIST
111 BOOPSI_DISPATCHER(IPTR, Poplist_Dispatcher, cl, obj, msg)
113 switch (msg->MethodID)
115 case OM_NEW: return Poplist__OM_NEW(cl, obj, (struct opSet *)msg);
116 default: return DoSuperMethodA(cl, obj, msg);
119 BOOPSI_DISPATCHER_END
121 const struct __MUIBuiltinClass _MUI_Poplist_desc =
123 MUIC_Poplist,
124 MUIC_Popobject,
125 sizeof(struct Poplist_DATA),
126 (void*)Poplist_Dispatcher
128 #endif /* ZUNE_BUILTIN_POPLIST */