add casts to zune macros to silence some warnings
[tangerine.git] / workbench / libs / popupmenu / pminput.c
bloba175eb3ed875ab496a9c7ee86681316f3d0d42a0
1 //
2 // PopupMenu
3 // ©1996-2002 Henrik Isaksson
4 //
5 // User Input & timer
6 //
8 #include "pmpriv.h"
9 #include "pminput.h"
12 // Input Handler
15 /// Input handler
16 struct InputEvent * __saveds ASM myhandler(register __a0 struct InputEvent *ev GNUCREG(a0),
17 register __a1 struct MsgPort *port GNUCREG(a1))
19 struct InputEvent *evnt=ev;
21 do {
22 if(evnt->ie_Class == IECLASS_RAWKEY) {
23 struct PM_InpMsg *m;
25 m=PM_Mem_Alloc(sizeof(struct PM_InpMsg));
26 if(m) {
27 m->msg.mn_Length=sizeof(struct PM_InpMsg);
28 m->msg.mn_ReplyPort=NULL;
29 m->Kind=0;
30 switch(evnt->ie_Code) {
31 case 208:
32 case 0x45:
33 m->Kind=PM_MSG_TERMINATE;
34 break;
35 case 0x4c:
36 m->Kind=PM_MSG_UP;
37 break;
38 case 0x4d:
39 m->Kind=PM_MSG_DOWN;
40 break;
41 case 0x4e:
42 m->Kind=PM_MSG_OPENSUB;
43 break;
44 case 0x4f:
45 m->Kind=PM_MSG_CLOSESUB;
46 break;
47 case 0x44:
48 case 0x43:
49 m->Kind=PM_MSG_SELECT;
50 break;
51 case 0x40:
52 m->Kind=PM_MSG_MULTISELECT;
53 break;
54 case 0x50:
55 m->Kind=PM_MSG_DEBUGINFO;
56 break;
58 if(m->Kind) PutMsg(port, (struct Message *)m);
59 else PM_Mem_Free(m);
61 evnt->ie_Class = 0;
63 if(evnt->ie_Class == IECLASS_TIMER) {
64 struct PM_InpMsg *m;
66 m=PM_Mem_Alloc(sizeof(struct PM_InpMsg));
67 if(m) {
68 m->msg.mn_Length=sizeof(struct PM_InpMsg);
69 m->msg.mn_ReplyPort=NULL;
70 m->Kind=PM_MSG_TIMER;
71 PutMsg(port, (struct Message *)m);
74 if(evnt->ie_Class == IECLASS_RAWMOUSE) {
75 struct PM_InpMsg *m;
77 m=PM_Mem_Alloc(sizeof(struct PM_InpMsg));
78 if(m) {
79 m->msg.mn_Length=sizeof(struct PM_InpMsg);
80 m->msg.mn_ReplyPort=NULL;
81 m->Kind=PM_MSG_RAWMOUSE;
82 m->Code=evnt->ie_Code;
83 m->Qual=evnt->ie_Qualifier;
84 PutMsg(port, (struct Message *)m);
87 evnt->ie_Code=IECODE_NOBUTTON;
89 evnt=evnt->ie_NextEvent;
90 } while(evnt);
92 return ev;
94 ///
96 /// handlername
97 static char handlername[] = "PM Input Handler";
98 ///
100 #ifdef __AROS__
101 AROS_UFH2(struct InputEvent *, myhandler_aros,
102 AROS_UFHA(struct InputEvent *, ev, A0),
103 AROS_UFHA(struct MsgPort *, port, A1))
105 AROS_USERFUNC_INIT
107 return myhandler(ev, port);
109 AROS_USERFUNC_EXIT
111 #define HANDLER_CODE (APTR)AROS_ASMSYMNAME(myhandler_aros)
112 #else
113 #define HANDLER_CODE (void *)myhandler
114 #endif
117 /// Install handler
118 struct PM_InputHandler *PM_InstallHandler(int pri)
120 struct PM_InputHandler *pmh;
122 pmh=PM_Mem_Alloc(sizeof(struct PM_InputHandler));
123 if(pmh) {
124 pmh->mp=CreatePort(0,0);
125 if(pmh->mp) {
126 pmh->port=CreatePort(0,0);
127 if(pmh->port) {
128 pmh->ior=CreateStdIO(pmh->mp);
129 if(pmh->ior) {
130 pmh->error=OpenDevice("input.device",0,(struct IORequest *)pmh->ior,0);
131 if(!pmh->error) {
132 pmh->intr.is_Data=(APTR)pmh->port;
133 pmh->intr.is_Code=HANDLER_CODE;
134 pmh->intr.is_Node.ln_Pri=pri;
135 pmh->intr.is_Node.ln_Name=handlername;
136 pmh->ior->io_Command=IND_ADDHANDLER;
137 pmh->ior->io_Data=(APTR)&pmh->intr;
138 pmh->ior->io_Message.mn_ReplyPort=pmh->mp;
140 DoIO((struct IORequest *)pmh->ior);
149 return pmh;
153 /// Remove handler
154 void PM_RemoveHandler(struct PM_InputHandler *pmh)
156 struct PM_InpMsg *msg;
158 if(pmh->mp) {
159 if(pmh->port) {
160 if(pmh->ior) {
161 if(!pmh->error) {
162 pmh->ior->io_Command=IND_REMHANDLER;
163 pmh->ior->io_Data=(APTR)&pmh->intr;
164 DoIO((struct IORequest *)pmh->ior);
166 CloseDevice((struct IORequest *)pmh->ior);
168 DeleteStdIO(pmh->ior);
170 while((msg=(struct PM_InpMsg *)GetMsg(pmh->port))) {
171 PM_Mem_Free(msg);
173 DeletePort(pmh->port);
175 DeletePort(pmh->mp);
177 PM_Mem_Free(pmh);
182 // Timer
185 /// Timer functions
187 // timer funcs
190 void EZDeleteTimer(struct timerequest *TimeRequest)
192 struct MsgPort *TimePort;
194 if(TimeRequest)
196 if(TimeRequest->tr_node.io_Device)
197 CloseDevice((struct IORequest *)TimeRequest);
199 if((TimePort=TimeRequest->tr_node.io_Message.mn_ReplyPort))
200 DeletePort(TimePort);
202 DeleteExtIO((struct IORequest *)TimeRequest);
206 struct timerequest *EZCreateTimer(LONG Unit)
208 struct MsgPort *TimePort;
209 struct timerequest *TimeRequest;
211 if(!(TimePort = (struct MsgPort *)CreatePort(NULL,0)))
212 return(NULL);
214 if(!(TimeRequest = (struct timerequest *)CreateExtIO(TimePort,sizeof(struct timerequest))))
216 DeletePort(TimePort);
218 return(NULL);
221 if(OpenDevice(TIMERNAME, Unit, (struct IORequest *)TimeRequest, 0))
223 DeleteExtIO((struct IORequest *)TimeRequest);
224 DeletePort(TimePort);
226 return(NULL);
229 return(TimeRequest);