Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / muimaster / classes / popstring.c
bloba1aa8ab67084a17e9a431ba1847d3497d633efa7
1 /*
2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <graphics/gfx.h>
7 #include <graphics/view.h>
8 #include <clib/alib_protos.h>
9 #include <proto/exec.h>
10 #include <proto/graphics.h>
11 #include <proto/utility.h>
12 #include <proto/intuition.h>
13 #include <proto/muimaster.h>
15 #include "mui.h"
16 #include "muimaster_intern.h"
17 #include "support.h"
19 /* #define MYDEBUG 0 */
20 #include "debug.h"
22 extern struct Library *MUIMasterBase;
24 struct Popstring_DATA
26 struct Hook *close_hook;
27 struct Hook *open_hook;
28 Object *string;
29 Object *button;
30 int open;
31 int toggle;
32 struct MUI_EventHandlerNode ehn;
36 IPTR Popstring__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
38 struct Popstring_DATA *data;
39 struct TagItem *tag, *tags;
40 Object *string, *button;
42 button = (Object*)GetTagData(MUIA_Popstring_Button,0,msg->ops_AttrList);
43 string = (Object*)GetTagData(MUIA_Popstring_String,0,msg->ops_AttrList);
45 obj = (Object *) DoSuperNewTags
47 cl, obj, 0,
49 MUIA_Group_Horiz, TRUE,
50 MUIA_Group_Spacing, 0,
51 (string ? Child : TAG_IGNORE), (IPTR) string,
52 Child, (IPTR) button,
54 TAG_MORE, (IPTR) msg->ops_AttrList
56 if (!obj) return FALSE;
58 data = INST_DATA(cl, obj);
59 data->button = button;
60 data->string = string;
62 data->ehn.ehn_Events = IDCMP_RAWKEY;
63 data->ehn.ehn_Priority = 0;
64 data->ehn.ehn_Flags = 0;
65 data->ehn.ehn_Object = obj;
66 data->ehn.ehn_Class = cl;
68 /* parse initial taglist */
70 for (tags = msg->ops_AttrList; (tag = NextTagItem((const struct TagItem **)&tags)); )
72 switch (tag->ti_Tag)
74 case MUIA_Popstring_Toggle: data->toggle = tag->ti_Data; break;
75 case MUIA_Popstring_CloseHook: data->close_hook = (struct Hook*)tag->ti_Data;break;
76 case MUIA_Popstring_OpenHook: data->open_hook = (struct Hook*)tag->ti_Data;break;
80 DoMethod(button,MUIM_Notify,MUIA_Pressed,FALSE,(IPTR)obj,1,MUIM_Popstring_Open);
82 return (IPTR)obj;
85 IPTR Popstring__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
87 struct TagItem *tags,*tag;
88 struct Popstring_DATA *data = INST_DATA(cl, obj);
90 for (tags = msg->ops_AttrList; (tag = NextTagItem((const struct TagItem **)&tags)); )
92 switch (tag->ti_Tag)
94 case MUIA_Popstring_Toggle: data->toggle = tag->ti_Data; break;
95 case MUIA_Popstring_CloseHook: data->close_hook = (struct Hook*)tag->ti_Data;break;
96 case MUIA_Popstring_OpenHook: data->open_hook = (struct Hook*)tag->ti_Data;break;
100 return DoSuperMethodA(cl,obj,(Msg)msg);
103 #define STORE *(msg->opg_Storage)
104 IPTR Popstring__OM_GET(struct IClass *cl, Object *obj, struct opGet *msg)
106 struct Popstring_DATA *data = INST_DATA(cl, obj);
108 switch(msg->opg_AttrID)
110 case MUIA_Popstring_String: STORE = (IPTR)data->string; return 1;
112 return DoSuperMethodA(cl, obj, (Msg) msg);
114 #undef STORE
116 IPTR Popstring__MUIM_Setup(struct IClass *cl, Object *obj, struct MUIP_Setup *msg)
118 struct Popstring_DATA *data = INST_DATA(cl, obj);
120 if (!(DoSuperMethodA(cl, obj, (Msg) msg)))
121 return FALSE;
123 DoMethod(_win(obj), MUIM_Window_AddEventHandler, (IPTR)&data->ehn);
125 return TRUE;
128 IPTR Popstring__MUIM_Cleanup(struct IClass *cl, Object *obj, struct MUIP_Cleanup *msg)
130 struct Popstring_DATA *data = INST_DATA(cl, obj);
132 DoMethod(_win(obj), MUIM_Window_RemEventHandler, (IPTR)&data->ehn);
134 return DoSuperMethodA(cl, obj, (Msg) msg);
137 IPTR Popstring__MUIM_HandleEvent(struct IClass *cl, Object *obj, struct MUIP_HandleEvent *msg)
139 if (msg->muikey == MUIKEY_POPUP)
141 D(bug("Popstring__MUIM_HandleEvent %p got MUIKEY_POPUP\n", obj));
142 DoMethod(obj, MUIM_Popstring_Open);
143 return MUI_EventHandlerRC_Eat;
145 return 0;
148 IPTR Popstring__MUIM_Popstring_Close(struct IClass *cl, Object *obj, struct MUIP_Popstring_Close *msg)
150 struct Popstring_DATA *data = INST_DATA(cl, obj);
151 if (data->close_hook && data->open)
153 DoMethod(_app(obj), MUIM_Application_PushMethod, (IPTR)obj, 4, MUIM_CallHook, (IPTR)data->close_hook, (IPTR)data->string, msg->result);
154 data->open = 0;
155 set(data->button,MUIA_Disabled, FALSE);
157 return 0;
160 IPTR Popstring__MUIM_Popstring_Open(struct IClass *cl, Object *obj, struct MUIP_Popstring_Open *msg)
162 struct Popstring_DATA *data = INST_DATA(cl, obj);
163 if (data->open_hook)
165 if (data->open && data->toggle)
167 DoMethod(obj,MUIM_Popstring_Close,FALSE);
168 return 0;
171 if (!data->open)
173 if (DoMethod(obj, MUIM_CallHook, (IPTR)data->open_hook, (IPTR)data->string))
175 /* Opening the popup window was successful */
176 data->open = 1;
177 if (!data->toggle) set(data->button,MUIA_Disabled, TRUE);
181 return 0;
185 BOOPSI_DISPATCHER(IPTR, Popstring_Dispatcher, cl, obj, msg)
187 switch (msg->MethodID)
189 case OM_NEW:
190 return Popstring__OM_NEW(cl, obj, (APTR)msg);
191 case OM_SET:
192 return Popstring__OM_SET(cl, obj, (APTR)msg);
193 case OM_GET:
194 return Popstring__OM_GET(cl, obj, (APTR)msg);
195 case MUIM_Setup:
196 return Popstring__MUIM_Setup(cl, obj, (APTR)msg);
197 case MUIM_Cleanup:
198 return Popstring__MUIM_Cleanup(cl, obj, (APTR)msg);
199 case MUIM_HandleEvent:
200 return Popstring__MUIM_HandleEvent(cl, obj, (APTR)msg);
201 case MUIM_Popstring_Close:
202 return Popstring__MUIM_Popstring_Close(cl, obj, (APTR)msg);
203 case MUIM_Popstring_Open:
204 return Popstring__MUIM_Popstring_Open(cl, obj, (APTR)msg);
207 return DoSuperMethodA(cl, obj, msg);
209 BOOPSI_DISPATCHER_END
211 const struct __MUIBuiltinClass _MUI_Popstring_desc =
213 MUIC_Popstring,
214 MUIC_Group,
215 sizeof(struct Popstring_DATA),
216 (void*)Popstring_Dispatcher