1 /*************************************************************************\
5 * Copyright 2001 Emmanuel Lesueur *
7 \*************************************************************************/
12 #include <dos/notify.h>
13 #include <libraries/mui.h>
14 #include <proto/exec.h>
15 #include <proto/muimaster.h>
16 #include <proto/dos.h>
24 struct NotifyRequest nr
;
26 typedef struct NotifierData NotifierData
;
28 struct NotifierBaseData
{
29 struct MUI_InputHandlerNode ihn
;
31 typedef struct NotifierBaseData NotifierBaseData
;
33 static struct MsgPort
*port
;
36 Static ULONG
ntfNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
) {
37 STRPTR name
=(STRPTR
)GetTagData(MYATTR_Notifier_Name
,NULL
,msg
->ops_AttrList
);
39 if(obj
=(Object
*)DoSuperMethodA(cl
,obj
,(Msg
)msg
)) {
40 NotifierData
*dat
=INST_DATA(cl
,obj
);
41 dat
->nr
.nr_Name
=(STRPTR
)GetTagData(MYATTR_Notifier_Name
,NULL
,msg
->ops_AttrList
);
42 dat
->nr
.nr_Flags
=NRF_SEND_MESSAGE
;
43 dat
->nr
.nr_UserData
=(ULONG
)obj
;
44 dat
->nr
.nr_stuff
.nr_Msg
.nr_Port
=port
;
45 StartNotify(&dat
->nr
);
52 Static ULONG
ntfDispose(struct IClass
*cl
,Object
*obj
,Msg msg
) {
53 NotifierData
*dat
=INST_DATA(cl
,obj
);
55 return DoSuperMethodA(cl
,obj
,msg
);
58 Static ULONG
ntfGet(struct IClass
*cl
,Object
*obj
,struct opGet
*msg
) {
59 NotifierData
*dat
=INST_DATA(cl
,obj
);
60 switch(msg
->opg_AttrID
) {
61 case MYATTR_Notifier_Changed
:
62 *msg
->opg_Storage
=FALSE
;
65 return DoSuperMethodA(cl
,obj
,(APTR
)msg
);
68 BEGIN_DISPATCHER(ntfDispatcher
,cl
,obj
,msg
) {
69 switch(msg
->MethodID
) {
70 case OM_NEW
: return ntfNew (cl
,obj
,(APTR
)msg
);
71 case OM_DISPOSE
: return ntfDispose (cl
,obj
,msg
);
72 //case OM_SET: return ntfSet (cl,obj,(APTR)msg);
73 case OM_GET
: return ntfGet (cl
,obj
,(APTR
)msg
);
75 return DoSuperMethodA(cl
,obj
,msg
);
77 END_DISPATCHER(ntfDispatcher
)
80 Static ULONG
ntbNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
) {
81 /*struct MsgPort **/port
=CreateMsgPort();
82 if(port
&& (obj
=(Object
*)DoSuperMethodA(cl
,obj
,(Msg
)msg
))) {
83 NotifierBaseData
*dat
=INST_DATA(cl
,obj
);
85 dat
->ihn
.ihn_Object
=obj
;
86 dat
->ihn
.ihn_Signals
=1<<port
->mp_SigBit
;
88 dat
->ihn
.ihn_Method
=MYM_NotifierBase_Handle
;
89 DoMethod3(app
,MUIM_Application_AddInputHandler
,&dat
->ihn
);
96 Static ULONG
ntbDispose(struct IClass
*cl
,Object
*obj
,Msg msg
) {
97 NotifierBaseData
*dat
=INST_DATA(cl
,obj
);
98 DoMethod3(app
,MUIM_Application_RemInputHandler
,&dat
->ihn
);
99 DeleteMsgPort(/*dat->*/port
);
100 return DoSuperMethodA(cl
,obj
,msg
);
103 Static ULONG
ntbHandle(struct IClass
*cl
,Object
*obj
) {
104 struct NotifyMessage
*nm
;
105 while(nm
=(APTR
)GetMsg(port
)) {
106 Object
*o
=(APTR
)nm
->nm_NReq
->nr_UserData
;
107 ReplyMsg(&nm
->nm_ExecMessage
);
108 set(o
,MYATTR_Notifier_Changed
,TRUE
);
112 BEGIN_DISPATCHER(ntbDispatcher
,cl
,obj
,msg
) {
113 switch(msg
->MethodID
) {
114 case OM_NEW
: return ntbNew (cl
,obj
,(APTR
)msg
);
115 case OM_DISPOSE
: return ntbDispose (cl
,obj
,msg
);
116 case MYM_NotifierBase_Handle
: return ntbHandle (cl
,obj
);
118 return DoSuperMethodA(cl
,obj
,msg
);
120 END_DISPATCHER(ntbDispatcher
)
123 struct MUI_CustomClass
*notifier_mcc
;
124 static struct MUI_CustomClass
*notifierbase_mcc
;
126 static Object
*notifier_base
;
128 BOOL
initNotifier(Object
*app1
) {
131 notifierbase_mcc
=MUI_CreateCustomClass(NULL
,MUIC_Notify
,NULL
,sizeof(NotifierBaseData
),(APTR
)&ntbDispatcher
);
132 if(notifierbase_mcc
) {
133 notifier_base
=NewObject(notifierbase_mcc
->mcc_Class
,NULL
,TAG_END
);
135 notifier_mcc
=MUI_CreateCustomClass(NULL
,MUIC_Notify
,NULL
,sizeof(NotifierData
),(APTR
)&ntfDispatcher
);
139 DisposeObject(notifier_base
);
141 MUI_DeleteCustomClass(notifierbase_mcc
);
149 void cleanupNotifier(void) {
150 if(count
&& !--count
) {
151 MUI_DeleteCustomClass(notifier_mcc
);
152 DisposeObject(notifier_base
);
153 MUI_DeleteCustomClass(notifierbase_mcc
);