revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / muimaster / classes / popobject.c
blobed81b9d3d34ec2d53332163b9d605399b5e0b51b
1 /*
2 Copyright © 2002-2014, 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"
18 #include "debug.h"
20 extern struct Library *MUIMasterBase;
22 struct Popobject_DATA
24 BOOL light;
25 BOOL vol;
26 BOOL follow;
27 BOOL popped;
28 struct Hook *strobj_hook;
29 struct Hook *objstr_hook;
30 struct Hook *window_hook;
31 struct Hook open_hook;
32 struct Hook close_hook;
33 Object *object;
34 Object *wnd;
37 /****** Popobject.mui/MUIA_Popobject_Follow **********************************
39 * NAME
40 * MUIA_Popobject_Follow -- (V7) [ISG], BOOL
42 * FUNCTION
43 * Specifies whether the pop-up window should update its position and
44 * width to match the position and width of its string gadget when the
45 * parent window is moved or resized, i.e. if it should look like it is
46 * attached to the string gadget, or should be more like a floating
47 * object. Defaults to TRUE.
49 ******************************************************************************
53 /****** Popobject.mui/MUIA_Popobject_Light ***********************************
55 * NAME
56 * MUIA_Popobject_Light -- (V7) [ISG], BOOL
58 * FUNCTION
59 * Specifies whether the pop-up window should be drawn without a border.
60 * Defaults to TRUE.
62 ******************************************************************************
66 /****** Popobject.mui/MUIA_Popobject_Object **********************************
68 * NAME
69 * MUIA_Popobject_Object -- (V7) [I.G], Object *
71 * FUNCTION
72 * The object to pop up.
74 ******************************************************************************
78 /****** Popobject.mui/MUIA_Popobject_ObjStrHook ******************************
80 * NAME
81 * MUIA_Popobject_ObjStrHook -- (V7) [ISG], struct Hook *
83 * FUNCTION
84 * This hook is called to update the string gadget when the pop-up is
85 * closed with a TRUE success value. For example, it can set the string
86 * to the name of the item selected from a Listview pop-up.
88 * The hook receives pointers to the pop-up object and the string gadget
89 * as its second and third arguments respectively.
91 * SEE ALSO
92 * MUIA_Popobject_StrObjHook
94 ******************************************************************************
98 /****** Popobject.mui/MUIA_Popobject_StrObjHook ******************************
100 * NAME
101 * MUIA_Popobject_StrObjHook -- (V7) [ISG], struct Hook *
103 * FUNCTION
104 * This hook is called whenever the pop-up object is opened to initialise
105 * or update the pop-up object according to the contents of the string
106 * gadget. For example, it can pre-select an item in a Listview pop-up
107 * that matches the current string.
109 * The hook receives pointers to the pop-up object and the string gadget
110 * as its second and third arguments respectively.
112 * SEE ALSO
113 * MUIA_Popobject_ObjStrHook
115 ******************************************************************************
119 /****** Popobject.mui/MUIA_Popobject_Volatile ********************************
121 * NAME
122 * MUIA_Popobject_Volatile -- (V7) [ISG], BOOL
124 * FUNCTION
125 * Specifies whether the pop-up window should be hidden when the portion
126 * of the Popobject residing in the parent window is hidden. This would
127 * normally be desirable if the Popobject is in a page group for
128 * example. If the pop-up window is on display when the Popobject is
129 * hidden, it will reappear as soon as the Popobject is reshown.
130 * Defaults to TRUE.
132 ******************************************************************************
136 /****** Popobject.mui/MUIA_Popobject_WindowHook ******************************
138 * NAME
139 * MUIA_Popobject_WindowHook -- (V9) [ISG], struct Hook *
141 * FUNCTION
142 * This hook is called just before the pop-up window is opened.
144 * The hook receives pointers to the pop-up object and the window object
145 * as its second and third arguments respectively.
147 * SEE ALSO
148 * MUIA_Popobject_ObjStrHook
150 * INTERNALS
151 * It is unclear whether this hook should be called every time the window
152 * is opened or only the first time.
154 ******************************************************************************
159 AROS_UFH3(ULONG, Popobject_Open_Function,
160 AROS_UFHA(struct Hook *, hook, A0),
161 AROS_UFHA(Object *, obj, A2),
162 AROS_UFHA(void **, msg, A1))
164 AROS_USERFUNC_INIT
166 struct Popobject_DATA *data = (struct Popobject_DATA *)hook->h_Data;
167 Object *string = (Object *) msg[0];
169 if (!data->wnd)
171 static struct TagItem light_tags[] =
173 {MUIA_Window_Borderless, TRUE},
174 {MUIA_Window_CloseGadget, FALSE},
175 {MUIA_Window_SizeGadget, FALSE},
176 {MUIA_Window_DepthGadget, FALSE},
177 {MUIA_Window_DragBar, FALSE},
178 {TAG_DONE}
181 data->wnd = WindowObject,
182 WindowContents, data->object,
183 data->light ? TAG_MORE : TAG_IGNORE, (IPTR) light_tags, End;
185 if (!data->wnd)
186 return 0;
188 DoMethod(_app(obj), OM_ADDMEMBER, (IPTR) data->wnd);
190 DoMethod(data->wnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
191 (IPTR) obj, 2, MUIM_Popstring_Close, FALSE);
194 if (data->strobj_hook)
196 if (!(CallHookPkt(data->strobj_hook, data->object, string)))
197 return 0;
200 if (data->window_hook)
202 CallHookPkt(data->window_hook, data->object, data->wnd);
205 SetAttrs(data->wnd,
206 MUIA_Window_LeftEdge, _left(obj) + _window(obj)->LeftEdge,
207 MUIA_Window_TopEdge, _bottom(obj) + 1 + _window(obj)->TopEdge,
208 MUIA_Window_Width, _width(obj), MUIA_Window_Open, TRUE, TAG_DONE);
209 data->popped = TRUE;
211 return 1;
213 AROS_USERFUNC_EXIT
217 AROS_UFH3(ULONG, Popobject_Close_Function,
218 AROS_UFHA(struct Hook *, hook, A0),
219 AROS_UFHA(Object *, obj, A2),
220 AROS_UFHA(void **, msg, A1))
222 AROS_USERFUNC_INIT
224 struct Popobject_DATA *data = (struct Popobject_DATA *)hook->h_Data;
225 Object *string = (Object *) msg[0];
226 SIPTR suc = (SIPTR) msg[1];
228 if (data->wnd)
230 set(data->wnd, MUIA_Window_Open, FALSE);
231 data->popped = FALSE;
233 if (data->objstr_hook && suc)
234 CallHookPkt(data->objstr_hook, data->object, string);
236 return 0;
238 AROS_USERFUNC_EXIT
241 IPTR Popobject__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
243 struct Popobject_DATA *data;
244 struct TagItem *tags;
245 struct TagItem *tag;
247 obj = (Object *) DoSuperMethodA(cl, obj, (Msg) msg);
248 if (!obj)
249 return FALSE;
251 data = INST_DATA(cl, obj);
252 data->follow = TRUE;
253 data->vol = TRUE;
254 data->light = TRUE;
256 data->open_hook.h_Entry = (HOOKFUNC) Popobject_Open_Function;
257 data->open_hook.h_Data = data;
258 data->close_hook.h_Entry = (HOOKFUNC) Popobject_Close_Function;
259 data->close_hook.h_Data = data;
261 /* parse initial taglist */
263 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags));)
265 switch (tag->ti_Tag)
267 case MUIA_Popobject_Follow:
268 data->follow = tag->ti_Data;
269 break;
271 case MUIA_Popobject_Light:
272 data->light = tag->ti_Data;
273 break;
275 case MUIA_Popobject_Object:
276 data->object = (Object *) tag->ti_Data;
277 break;
279 case MUIA_Popobject_ObjStrHook:
280 data->objstr_hook = (struct Hook *)tag->ti_Data;
281 break;
283 case MUIA_Popobject_StrObjHook:
284 data->strobj_hook = (struct Hook *)tag->ti_Data;
285 break;
287 case MUIA_Popobject_Volatile:
288 data->vol = tag->ti_Data;
289 break;
291 case MUIA_Popobject_WindowHook:
292 data->window_hook = (struct Hook *)tag->ti_Data;
293 break;
297 SetAttrs(obj,
298 MUIA_Popstring_OpenHook, (IPTR) & data->open_hook,
299 MUIA_Popstring_CloseHook, (IPTR) & data->close_hook,
300 MUIA_Popstring_Toggle, TRUE,
301 TAG_DONE);
303 return (IPTR) obj;
306 IPTR Popobject__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
308 struct Popobject_DATA *data = INST_DATA(cl, obj);
310 if (!data->wnd && data->object)
311 MUI_DisposeObject(data->object);
313 return DoSuperMethodA(cl, obj, msg);
316 IPTR Popobject__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
318 struct Popobject_DATA *data = INST_DATA(cl, obj);
319 struct TagItem *tags;
320 struct TagItem *tag;
322 /* parse initial taglist */
324 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags));)
326 switch (tag->ti_Tag)
328 case MUIA_Popobject_Follow:
329 data->follow = tag->ti_Data;
330 break;
332 case MUIA_Popobject_ObjStrHook:
333 data->objstr_hook = (struct Hook *)tag->ti_Data;
334 break;
336 case MUIA_Popobject_StrObjHook:
337 data->strobj_hook = (struct Hook *)tag->ti_Data;
338 break;
340 case MUIA_Popobject_Volatile:
341 data->vol = tag->ti_Data;
342 break;
344 case MUIA_Popobject_WindowHook:
345 data->window_hook = (struct Hook *)tag->ti_Data;
346 break;
349 return DoSuperMethodA(cl, obj, (Msg) msg);
353 IPTR Popobject__MUIM_Get(struct IClass *cl, Object *obj,
354 struct opGet *msg)
356 struct Popobject_DATA *data = INST_DATA(cl, obj);
358 switch (msg->opg_AttrID)
360 case MUIA_Popobject_Follow:
361 *msg->opg_Storage = data->follow;
362 return TRUE;
364 case MUIA_Popobject_Light:
365 *msg->opg_Storage = data->light;
366 return TRUE;
368 case MUIA_Popobject_Object:
369 *msg->opg_Storage = (IPTR) data->object;
370 return TRUE;
372 case MUIA_Popobject_ObjStrHook:
373 *msg->opg_Storage = (IPTR) data->objstr_hook;
374 return TRUE;
376 case MUIA_Popobject_StrObjHook:
377 *msg->opg_Storage = (IPTR) data->strobj_hook;
378 return TRUE;
380 case MUIA_Popobject_Volatile:
381 *msg->opg_Storage = data->vol;
382 return TRUE;
384 case MUIA_Popobject_WindowHook:
385 *msg->opg_Storage = (IPTR) data->window_hook;
386 return TRUE;
389 return DoSuperMethodA(cl, obj, (Msg) msg);
392 IPTR Popobject__MUIM_Show(struct IClass *cl, Object *obj,
393 struct MUIP_Show *msg)
395 struct Popobject_DATA *data = INST_DATA(cl, obj);
397 IPTR rc = DoSuperMethodA(cl, obj, (Msg) msg);
399 /* If the pop-up window was shown when we were hidden, we reopen it, but
400 keep it inactive to prevent objects in the parent window missing
401 events (e.g. mouse up on a Listview) */
402 if (data->popped)
404 if (!XGET(data->wnd, MUIA_Window_Open))
406 set(data->wnd, MUIA_Window_Activate, FALSE);
407 set(data->wnd, MUIA_Window_Open, TRUE);
410 if (!rc)
411 return 0;
412 return rc;
415 IPTR Popobject__MUIM_Hide(struct IClass *cl, Object *obj,
416 struct MUIP_Hide *msg)
418 struct Popobject_DATA *data = INST_DATA(cl, obj);
420 /* Hide pop-up window too */
421 if (data->popped && data->vol)
422 set(data->wnd, MUIA_Window_Open, FALSE);
424 return DoSuperMethodA(cl, obj, (Msg) msg);
427 IPTR Popobject__MUIM_Draw(struct IClass *cl, Object *obj,
428 struct MUIP_Draw *msg)
430 struct Popobject_DATA *data = INST_DATA(cl, obj);
431 struct Window *popwin = NULL;
432 struct Window *parentwin = _window(obj);
434 DoSuperMethodA(cl, obj, (Msg) msg);
436 get(data->wnd, MUIA_Window_Window, &popwin);
438 if (data->follow && popwin && parentwin)
440 ChangeWindowBox(popwin, _left(obj) + parentwin->LeftEdge,
441 _bottom(obj) + parentwin->TopEdge + 1,
442 _width(obj), popwin->Height);
445 return 0;
448 BOOPSI_DISPATCHER(IPTR, Popobject_Dispatcher, cl, obj, msg)
450 switch (msg->MethodID)
452 case OM_NEW:
453 return Popobject__OM_NEW(cl, obj, (struct opSet *)msg);
454 case OM_DISPOSE:
455 return Popobject__OM_DISPOSE(cl, obj, msg);
456 case OM_SET:
457 return Popobject__OM_SET(cl, obj, (struct opSet *)msg);
458 case OM_GET:
459 return Popobject__MUIM_Get(cl, obj, (struct opGet *)msg);
460 case MUIM_Show:
461 return Popobject__MUIM_Show(cl, obj, (struct MUIP_Show *)msg);
462 case MUIM_Hide:
463 return Popobject__MUIM_Hide(cl, obj, (struct MUIP_Hide *)msg);
464 case MUIM_Draw:
465 return Popobject__MUIM_Draw(cl, obj, (struct MUIP_Draw *)msg);
468 return DoSuperMethodA(cl, obj, msg);
470 BOOPSI_DISPATCHER_END
472 const struct __MUIBuiltinClass _MUI_Popobject_desc =
474 MUIC_Popobject,
475 MUIC_Popstring,
476 sizeof(struct Popobject_DATA),
477 (void *) Popobject_Dispatcher