Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / muimaster / classes / popimage.c
blobd095cef05f455da0a023c7e5dc33353988e63f11
1 /*
2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
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 /* #define MYDEBUG 1 */
16 #include "debug.h"
17 #include "mui.h"
18 #include "muimaster_intern.h"
19 #include "support.h"
20 #include "support_classes.h"
21 #include "popimage_private.h"
23 extern struct Library *MUIMasterBase;
25 IPTR Popimage__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
27 struct Popimage_DATA *data;
28 struct TagItem *tag, *tags;
30 obj = (Object *) DoSuperNewTags
32 cl, obj, NULL,
34 ButtonFrame,
35 InnerSpacing(4,4),
36 MUIA_Background, MUII_ButtonBack,
37 MUIA_InputMode, MUIV_InputMode_RelVerify,
38 MUIA_Draggable, TRUE,
40 TAG_MORE, (IPTR) msg->ops_AttrList
43 if (!obj) return FALSE;
44 data = INST_DATA(cl, obj);
45 data->wintitle = NULL;
46 data->adjust_type = MUIV_Imageadjust_Type_All;
48 /* parse initial taglist */
49 for (tags = msg->ops_AttrList; (tag = NextTagItem((const struct TagItem**)&tags)); )
51 switch (tag->ti_Tag)
53 case MUIA_Window_Title:
54 data->wintitle = (CONST_STRPTR)tag->ti_Data;
55 break;
57 case MUIA_Imageadjust_Type:
58 data->adjust_type = tag->ti_Data;
59 break;
63 DoMethod(obj, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR)obj, 1,
64 MUIM_Popimage_OpenWindow);
66 return (IPTR)obj;
69 IPTR Popimage__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
71 struct Popimage_DATA *data = INST_DATA(cl, obj);
73 if (data->wnd)
75 D(bug("Popimage_Dispose(%p) : MUI_DisposeObject(%p)\n", obj, data->wnd));
76 MUI_DisposeObject(data->wnd);
77 data->wnd = NULL;
79 return DoSuperMethodA(cl,obj,(Msg)msg);
82 IPTR Popimage__MUIM_Hide(struct IClass *cl, Object *obj, struct opGet *msg)
84 #if 0
85 struct Popimage_DATA *data = INST_DATA(cl, obj);
86 if (data->wnd)
88 D(bug("Popimage_Hide(%p) : closing window %p\n", obj, data->wnd));
89 set(data->wnd,MUIA_Window_Open,FALSE);
90 D(bug("Popimage_Hide(%p) : app REMMEMBER win (%p)\n", obj, data->wnd));
91 DoMethod(_app(obj),OM_REMMEMBER,(IPTR)data->wnd);
92 D(bug("Popimage_Hide(%p) : MUI_DisposeObject(%p)\n", obj, data->wnd));
93 MUI_DisposeObject(data->wnd);
94 data->wnd = NULL;
96 #endif
97 return DoSuperMethodA(cl,obj,(Msg)msg);
100 IPTR Popimage__MUIM_Popimage_OpenWindow(struct IClass *cl, Object *obj, Msg msg)
102 struct Popimage_DATA *data = INST_DATA(cl, obj);
104 if (!data->wnd)
106 Object *ok_button, *cancel_button;
107 char *img_spec;
108 ULONG x = 0, y = 0;
110 get(_win(obj), MUIA_Window_LeftEdge, &x);
111 get(_win(obj), MUIA_Window_TopEdge, &y);
113 get(obj,MUIA_Imagedisplay_Spec, &img_spec);
115 data->wnd = (Object *)WindowObject,
116 MUIA_Window_Title, (IPTR) data->wintitle,
117 MUIA_Window_Activate, TRUE,
118 MUIA_Window_IsSubWindow, TRUE,
119 MUIA_Window_LeftEdge, _left(obj) + x,
120 MUIA_Window_TopEdge, _bottom(obj) + y + 1,
122 WindowContents, (IPTR) VGroup,
123 Child, (IPTR) (data->imageadjust = MUI_NewObject
125 MUIC_Imageadjust,
126 MUIA_CycleChain, 1,
127 MUIA_Imageadjust_Spec, (IPTR) img_spec,
128 MUIA_Imageadjust_Type, data->adjust_type,
129 MUIA_Imageadjust_Originator, (IPTR) obj,
130 TAG_DONE
132 Child, (IPTR) HGroup,
133 MUIA_Group_SameWidth, TRUE,
134 Child, (IPTR) (ok_button = MUI_MakeObject
136 MUIO_Button, (IPTR) "_Ok"
138 Child, (IPTR) HVSpace,
139 Child, (IPTR) HVSpace,
140 Child, (IPTR) (cancel_button = MUI_MakeObject
142 MUIO_Button, (IPTR) "_Cancel"
144 End,
145 End,
146 End;
148 if (data->wnd)
150 set(ok_button, MUIA_CycleChain, 1);
151 set(cancel_button, MUIA_CycleChain, 1);
153 DoMethod(_app(obj),OM_ADDMEMBER,(IPTR)data->wnd);
155 DoMethod
157 ok_button, MUIM_Notify, MUIA_Pressed, FALSE,
158 (IPTR) _app(obj), 5, MUIM_Application_PushMethod,
159 (IPTR) obj, 2, MUIM_Popimage_CloseWindow, TRUE
161 DoMethod
163 cancel_button, MUIM_Notify, MUIA_Pressed, FALSE,
164 (IPTR) _app(obj), 5, MUIM_Application_PushMethod,
165 (IPTR) obj, 2, MUIM_Popimage_CloseWindow, FALSE
167 DoMethod
169 data->wnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
170 (IPTR) _app(obj), 5, MUIM_Application_PushMethod,
171 (IPTR) obj, 2, MUIM_Popimage_CloseWindow, FALSE
176 if (data->wnd)
178 ULONG opened;
180 set(data->wnd, MUIA_Window_Open,TRUE);
181 get(data->wnd, MUIA_Window_Open, &opened);
182 if (!opened)
184 DoMethod(obj, MUIM_Popimage_CloseWindow, FALSE);
188 return 1;
191 IPTR Popimage__MUIM_Popimage_CloseWindow(struct IClass *cl, Object *obj,
192 struct MUIP_Popimage_CloseWindow *msg)
194 struct Popimage_DATA *data = INST_DATA(cl, obj);
195 int ok = msg->ok;
197 set(data->wnd, MUIA_Window_Open, FALSE);
199 if (ok)
201 char *spec;
202 get(data->imageadjust, MUIA_Imageadjust_Spec, &spec);
203 /* D(bug("popimage: got %s\n", spec)); */
204 set(obj, MUIA_Imagedisplay_Spec, (IPTR)spec);
207 DoMethod(_app(obj), OM_REMMEMBER, (IPTR)data->wnd);
208 MUI_DisposeObject(data->wnd);
209 data->wnd = NULL;
210 data->imageadjust = NULL;
211 return 1;
214 IPTR Popimage__MUIM_DisconnectParent(struct IClass *cl, Object *obj,
215 struct MUIP_DisconnectParent *msg)
217 struct Popimage_DATA *data = INST_DATA(cl, obj);
219 if (data->wnd) DoMethod(obj, MUIM_Popimage_CloseWindow, FALSE);
220 return DoSuperMethodA(cl, obj, (Msg)msg);
223 #if ZUNE_BUILTIN_POPIMAGE
224 BOOPSI_DISPATCHER(IPTR, Popimage_Dispatcher, cl, obj, msg)
226 switch (msg->MethodID)
228 case OM_NEW: return Popimage__OM_NEW(cl, obj, (struct opSet *)msg);
229 case OM_DISPOSE: return Popimage__OM_DISPOSE(cl, obj, msg);
230 case MUIM_Hide: return Popimage__MUIM_Hide(cl, obj, (APTR)msg);
231 case MUIM_Popimage_OpenWindow: return Popimage__MUIM_Popimage_OpenWindow(cl, obj, (APTR)msg);
232 case MUIM_Popimage_CloseWindow: return Popimage__MUIM_Popimage_CloseWindow(cl, obj, (APTR)msg);
233 case MUIM_DisconnectParent: return Popimage__MUIM_DisconnectParent(cl, obj, (APTR)msg);
234 default: return DoSuperMethodA(cl, obj, msg);
237 BOOPSI_DISPATCHER_END
239 const struct __MUIBuiltinClass _MUI_Popimage_desc =
241 MUIC_Popimage,
242 MUIC_Imagedisplay,
243 sizeof(struct Popimage_DATA),
244 (void*)Popimage_Dispatcher
246 #endif /* ZUNE_BUILTIN_POPIMAGE */