2 Copyright © 2002-2014, The AROS Development Team. All rights reserved.
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>
16 #include "muimaster_intern.h"
20 extern struct Library
*MUIMasterBase
;
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
;
37 /****** Popobject.mui/MUIA_Popobject_Follow **********************************
40 * MUIA_Popobject_Follow -- (V7) [ISG], BOOL
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 ***********************************
56 * MUIA_Popobject_Light -- (V7) [ISG], BOOL
59 * Specifies whether the pop-up window should be drawn without a border.
62 ******************************************************************************
66 /****** Popobject.mui/MUIA_Popobject_Object **********************************
69 * MUIA_Popobject_Object -- (V7) [I.G], Object *
72 * The object to pop up.
74 ******************************************************************************
78 /****** Popobject.mui/MUIA_Popobject_ObjStrHook ******************************
81 * MUIA_Popobject_ObjStrHook -- (V7) [ISG], struct Hook *
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.
92 * MUIA_Popobject_StrObjHook
94 ******************************************************************************
98 /****** Popobject.mui/MUIA_Popobject_StrObjHook ******************************
101 * MUIA_Popobject_StrObjHook -- (V7) [ISG], struct Hook *
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.
113 * MUIA_Popobject_ObjStrHook
115 ******************************************************************************
119 /****** Popobject.mui/MUIA_Popobject_Volatile ********************************
122 * MUIA_Popobject_Volatile -- (V7) [ISG], BOOL
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.
132 ******************************************************************************
136 /****** Popobject.mui/MUIA_Popobject_WindowHook ******************************
139 * MUIA_Popobject_WindowHook -- (V9) [ISG], struct Hook *
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.
148 * MUIA_Popobject_ObjStrHook
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
))
166 struct Popobject_DATA
*data
= (struct Popobject_DATA
*)hook
->h_Data
;
167 Object
*string
= (Object
*) msg
[0];
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
},
181 data
->wnd
= WindowObject
,
182 WindowContents
, data
->object
,
183 data
->light
? TAG_MORE
: TAG_IGNORE
, (IPTR
) light_tags
, End
;
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
)))
200 if (data
->window_hook
)
202 CallHookPkt(data
->window_hook
, data
->object
, 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
);
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
))
224 struct Popobject_DATA
*data
= (struct Popobject_DATA
*)hook
->h_Data
;
225 Object
*string
= (Object
*) msg
[0];
226 SIPTR suc
= (SIPTR
) msg
[1];
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
);
241 IPTR
Popobject__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
243 struct Popobject_DATA
*data
;
244 struct TagItem
*tags
;
247 obj
= (Object
*) DoSuperMethodA(cl
, obj
, (Msg
) msg
);
251 data
= INST_DATA(cl
, obj
);
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
));)
267 case MUIA_Popobject_Follow
:
268 data
->follow
= tag
->ti_Data
;
271 case MUIA_Popobject_Light
:
272 data
->light
= tag
->ti_Data
;
275 case MUIA_Popobject_Object
:
276 data
->object
= (Object
*) tag
->ti_Data
;
279 case MUIA_Popobject_ObjStrHook
:
280 data
->objstr_hook
= (struct Hook
*)tag
->ti_Data
;
283 case MUIA_Popobject_StrObjHook
:
284 data
->strobj_hook
= (struct Hook
*)tag
->ti_Data
;
287 case MUIA_Popobject_Volatile
:
288 data
->vol
= tag
->ti_Data
;
291 case MUIA_Popobject_WindowHook
:
292 data
->window_hook
= (struct Hook
*)tag
->ti_Data
;
298 MUIA_Popstring_OpenHook
, (IPTR
) & data
->open_hook
,
299 MUIA_Popstring_CloseHook
, (IPTR
) & data
->close_hook
,
300 MUIA_Popstring_Toggle
, TRUE
,
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
;
322 /* parse initial taglist */
324 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
328 case MUIA_Popobject_Follow
:
329 data
->follow
= tag
->ti_Data
;
332 case MUIA_Popobject_ObjStrHook
:
333 data
->objstr_hook
= (struct Hook
*)tag
->ti_Data
;
336 case MUIA_Popobject_StrObjHook
:
337 data
->strobj_hook
= (struct Hook
*)tag
->ti_Data
;
340 case MUIA_Popobject_Volatile
:
341 data
->vol
= tag
->ti_Data
;
344 case MUIA_Popobject_WindowHook
:
345 data
->window_hook
= (struct Hook
*)tag
->ti_Data
;
349 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
353 IPTR
Popobject__MUIM_Get(struct IClass
*cl
, Object
*obj
,
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
;
364 case MUIA_Popobject_Light
:
365 *msg
->opg_Storage
= data
->light
;
368 case MUIA_Popobject_Object
:
369 *msg
->opg_Storage
= (IPTR
) data
->object
;
372 case MUIA_Popobject_ObjStrHook
:
373 *msg
->opg_Storage
= (IPTR
) data
->objstr_hook
;
376 case MUIA_Popobject_StrObjHook
:
377 *msg
->opg_Storage
= (IPTR
) data
->strobj_hook
;
380 case MUIA_Popobject_Volatile
:
381 *msg
->opg_Storage
= data
->vol
;
384 case MUIA_Popobject_WindowHook
:
385 *msg
->opg_Storage
= (IPTR
) data
->window_hook
;
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) */
404 if (!XGET(data
->wnd
, MUIA_Window_Open
))
406 set(data
->wnd
, MUIA_Window_Activate
, FALSE
);
407 set(data
->wnd
, MUIA_Window_Open
, TRUE
);
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
);
448 BOOPSI_DISPATCHER(IPTR
, Popobject_Dispatcher
, cl
, obj
, msg
)
450 switch (msg
->MethodID
)
453 return Popobject__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
455 return Popobject__OM_DISPOSE(cl
, obj
, msg
);
457 return Popobject__OM_SET(cl
, obj
, (struct opSet
*)msg
);
459 return Popobject__MUIM_Get(cl
, obj
, (struct opGet
*)msg
);
461 return Popobject__MUIM_Show(cl
, obj
, (struct MUIP_Show
*)msg
);
463 return Popobject__MUIM_Hide(cl
, obj
, (struct MUIP_Hide
*)msg
);
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
=
476 sizeof(struct Popobject_DATA
),
477 (void *) Popobject_Dispatcher