2 Copyright © 2002-2003, 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"
19 /* #define MYDEBUG 0 */
22 extern struct Library
*MUIMasterBase
;
26 struct Hook
*close_hook
;
27 struct Hook
*open_hook
;
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
49 MUIA_Group_Horiz
, TRUE
,
50 MUIA_Group_Spacing
, 0,
51 (string
? Child
: TAG_IGNORE
), (IPTR
) string
,
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
)); )
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
);
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
)); )
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
);
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
)))
123 DoMethod(_win(obj
), MUIM_Window_AddEventHandler
, (IPTR
)&data
->ehn
);
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
;
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
);
155 set(data
->button
,MUIA_Disabled
, FALSE
);
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
);
165 if (data
->open
&& data
->toggle
)
167 DoMethod(obj
,MUIM_Popstring_Close
,FALSE
);
173 if (DoMethod(obj
, MUIM_CallHook
, (IPTR
)data
->open_hook
, (IPTR
)data
->string
))
175 /* Opening the popup window was successful */
177 if (!data
->toggle
) set(data
->button
,MUIA_Disabled
, TRUE
);
185 BOOPSI_DISPATCHER(IPTR
, Popstring_Dispatcher
, cl
, obj
, msg
)
187 switch (msg
->MethodID
)
190 return Popstring__OM_NEW(cl
, obj
, (APTR
)msg
);
192 return Popstring__OM_SET(cl
, obj
, (APTR
)msg
);
194 return Popstring__OM_GET(cl
, obj
, (APTR
)msg
);
196 return Popstring__MUIM_Setup(cl
, obj
, (APTR
)msg
);
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
=
215 sizeof(struct Popstring_DATA
),
216 (void*)Popstring_Dispatcher