Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / muimaster / classes / popscreen.c
blob1028bda1d954217afae10fe3107368579ac636a2
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 "popscreen_private.h"
26 extern struct Library *MUIMasterBase;
28 LONG PopscreenStrObjFunc(struct Hook *hook, Object *popup, Object *str)
30 struct Popscreen_DATA *data = (struct Popscreen_DATA *)hook->h_Data;
31 struct List *pubscrlist;
32 struct PubScreenNode *pubscrnode;
33 STRPTR strtext, listentry;
34 LONG index;
36 DoMethod(data->list, MUIM_List_Clear);
38 pubscrlist = LockPubScreenList();
39 ForeachNode(pubscrlist, pubscrnode)
41 DoMethod(data->list, MUIM_List_InsertSingle, (IPTR)pubscrnode->psn_Node.ln_Name, MUIV_List_Insert_Bottom);
43 UnlockPubScreenList();
45 get(str, MUIA_String_Contents, &strtext);
47 for(index = 0; ; index++)
49 DoMethod(data->list, MUIM_List_GetEntry, index, (IPTR)&listentry);
51 if (!listentry)
53 set(data->list, MUIA_List_Active, strtext[0] ? MUIV_List_Active_Off : 0);
54 break;
57 if (stricmp(strtext, listentry) == 0)
59 set(data->list, MUIA_List_Active, index);
60 break;
64 return TRUE;
67 void PopscreenObjStrFunc(struct Hook *hook, Object *popup, Object *str)
69 STRPTR listentry;
71 DoMethod(popup, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR)&listentry);
73 if (listentry)
75 set(str, MUIA_String_Contents, listentry);
79 IPTR Popscreen__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
81 Object *lv, *list;
83 obj = (Object *)DoSuperNewTags
85 cl, obj, NULL,
86 MUIA_Popobject_Object, (IPTR)(lv = (Object *)ListviewObject,
87 MUIA_Listview_List, (IPTR)(list = (Object *)ListObject,
88 InputListFrame,
89 End),
90 End),
91 TAG_MORE, (IPTR) msg->ops_AttrList
94 if (obj)
96 struct Popscreen_DATA *data = INST_DATA(cl, obj);
98 data->list = list;
100 data->strobj_hook.h_Entry = HookEntry;
101 data->strobj_hook.h_SubEntry = (HOOKFUNC)PopscreenStrObjFunc;
102 data->strobj_hook.h_Data = data;
104 data->objstr_hook.h_Entry = HookEntry;
105 data->objstr_hook.h_SubEntry = (HOOKFUNC)PopscreenObjStrFunc;
106 data->objstr_hook.h_Data = data;
108 SetAttrs(obj, MUIA_Popobject_StrObjHook, (IPTR)&data->strobj_hook,
109 MUIA_Popobject_ObjStrHook, (IPTR)&data->objstr_hook,
110 TAG_DONE);
113 DoMethod(lv, MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
114 (IPTR)obj, 2, MUIM_Popstring_Close, TRUE);
117 return (IPTR)obj;
120 #if ZUNE_BUILTIN_POPSCREEN
121 BOOPSI_DISPATCHER(IPTR, Popscreen_Dispatcher, cl, obj, msg)
123 switch (msg->MethodID)
125 case OM_NEW: return Popscreen__OM_NEW(cl, obj, (struct opSet *)msg);
126 default: return DoSuperMethodA(cl, obj, msg);
129 BOOPSI_DISPATCHER_END
131 const struct __MUIBuiltinClass _MUI_Popscreen_desc =
133 MUIC_Popscreen,
134 MUIC_Popobject,
135 sizeof(struct Popscreen_DATA),
136 (void*)Popscreen_Dispatcher
138 #endif /* ZUNE_BUILTIN_POPSCREEN */