grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / popupmenu / pminput.c
blob4ca81bedcd76343e887b7e19a769cce4bb892026
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 #ifdef __AROS__
17 struct InputEvent *myhandler(struct InputEvent *ev, struct MsgPort *port)
18 #else
19 struct InputEvent * __saveds ASM myhandler(register __a0 struct InputEvent *ev GNUCREG(a0),
20 register __a1 struct MsgPort *port GNUCREG(a1))
21 #endif
23 struct InputEvent *evnt=ev;
25 do {
26 if(evnt->ie_Class == IECLASS_RAWKEY) {
27 struct PM_InpMsg *m;
29 m=PM_Mem_Alloc(sizeof(struct PM_InpMsg));
30 if(m) {
31 m->msg.mn_Length=sizeof(struct PM_InpMsg);
32 m->msg.mn_ReplyPort=NULL;
33 m->Kind=0;
34 switch(evnt->ie_Code) {
35 case 208:
36 case 0x45:
37 m->Kind=PM_MSG_TERMINATE;
38 break;
39 case 0x4c:
40 m->Kind=PM_MSG_UP;
41 break;
42 case 0x4d:
43 m->Kind=PM_MSG_DOWN;
44 break;
45 case 0x4e:
46 m->Kind=PM_MSG_OPENSUB;
47 break;
48 case 0x4f:
49 m->Kind=PM_MSG_CLOSESUB;
50 break;
51 case 0x44:
52 case 0x43:
53 m->Kind=PM_MSG_SELECT;
54 break;
55 case 0x40:
56 m->Kind=PM_MSG_MULTISELECT;
57 break;
58 case 0x50:
59 m->Kind=PM_MSG_DEBUGINFO;
60 break;
62 if(m->Kind) PutMsg(port, (struct Message *)m);
63 else PM_Mem_Free(m);
65 evnt->ie_Class = 0;
67 if(evnt->ie_Class == IECLASS_TIMER) {
68 struct PM_InpMsg *m;
70 m=PM_Mem_Alloc(sizeof(struct PM_InpMsg));
71 if(m) {
72 m->msg.mn_Length=sizeof(struct PM_InpMsg);
73 m->msg.mn_ReplyPort=NULL;
74 m->Kind=PM_MSG_TIMER;
75 PutMsg(port, (struct Message *)m);
78 if(evnt->ie_Class == IECLASS_RAWMOUSE) {
79 struct PM_InpMsg *m;
81 m=PM_Mem_Alloc(sizeof(struct PM_InpMsg));
82 if(m) {
83 m->msg.mn_Length=sizeof(struct PM_InpMsg);
84 m->msg.mn_ReplyPort=NULL;
85 m->Kind=PM_MSG_RAWMOUSE;
86 m->Code=evnt->ie_Code;
87 m->Qual=evnt->ie_Qualifier;
88 PutMsg(port, (struct Message *)m);
91 evnt->ie_Code=IECODE_NOBUTTON;
93 evnt=evnt->ie_NextEvent;
94 } while(evnt);
96 return ev;
98 ///
100 /// handlername
101 static char handlername[] = "PM Input Handler";
104 #ifdef __AROS__
105 AROS_UFH2(struct InputEvent *, myhandler_aros,
106 AROS_UFHA(struct InputEvent *, ev, A0),
107 AROS_UFHA(struct MsgPort *, port, A1))
109 AROS_USERFUNC_INIT
111 return myhandler(ev, port);
113 AROS_USERFUNC_EXIT
115 #define HANDLER_CODE (APTR)AROS_ASMSYMNAME(myhandler_aros)
116 #else
117 #define HANDLER_CODE (void *)myhandler
118 #endif
121 /// Install handler
122 struct PM_InputHandler *PM_InstallHandler(int pri)
124 struct PM_InputHandler *pmh;
126 pmh=PM_Mem_Alloc(sizeof(struct PM_InputHandler));
127 if(pmh) {
128 pmh->mp=CreatePort(0,0);
129 if(pmh->mp) {
130 pmh->port=CreatePort(0,0);
131 if(pmh->port) {
132 pmh->ior=CreateStdIO(pmh->mp);
133 if(pmh->ior) {
134 pmh->error=OpenDevice("input.device",0,(struct IORequest *)pmh->ior,0);
135 if(!pmh->error) {
136 pmh->intr.is_Data=(APTR)pmh->port;
137 pmh->intr.is_Code=HANDLER_CODE;
138 pmh->intr.is_Node.ln_Pri=pri;
139 pmh->intr.is_Node.ln_Name=handlername;
140 pmh->ior->io_Command=IND_ADDHANDLER;
141 pmh->ior->io_Data=(APTR)&pmh->intr;
142 pmh->ior->io_Message.mn_ReplyPort=pmh->mp;
144 DoIO((struct IORequest *)pmh->ior);
153 return pmh;
157 /// Remove handler
158 void PM_RemoveHandler(struct PM_InputHandler *pmh)
160 struct PM_InpMsg *msg;
162 if(pmh->mp) {
163 if(pmh->port) {
164 if(pmh->ior) {
165 if(!pmh->error) {
166 pmh->ior->io_Command=IND_REMHANDLER;
167 pmh->ior->io_Data=(APTR)&pmh->intr;
168 DoIO((struct IORequest *)pmh->ior);
170 CloseDevice((struct IORequest *)pmh->ior);
172 DeleteStdIO(pmh->ior);
174 while((msg=(struct PM_InpMsg *)GetMsg(pmh->port))) {
175 PM_Mem_Free(msg);
177 DeletePort(pmh->port);
179 DeletePort(pmh->mp);
181 PM_Mem_Free(pmh);
186 // Timer
189 /// Timer functions
191 // timer funcs
194 void EZDeleteTimer(struct timerequest *TimeRequest)
196 struct MsgPort *TimePort;
198 if(TimeRequest)
200 if(TimeRequest->tr_node.io_Device)
201 CloseDevice((struct IORequest *)TimeRequest);
203 if((TimePort=TimeRequest->tr_node.io_Message.mn_ReplyPort))
204 DeletePort(TimePort);
206 DeleteExtIO((struct IORequest *)TimeRequest);
210 struct timerequest *EZCreateTimer(LONG Unit)
212 struct MsgPort *TimePort;
213 struct timerequest *TimeRequest;
215 if(!(TimePort = (struct MsgPort *)CreatePort(NULL,0)))
216 return(NULL);
218 if(!(TimeRequest = (struct timerequest *)CreateExtIO(TimePort,sizeof(struct timerequest))))
220 DeletePort(TimePort);
222 return(NULL);
225 if(OpenDevice(TIMERNAME, Unit, (struct IORequest *)TimeRequest, 0))
227 DeleteExtIO((struct IORequest *)TimeRequest);
228 DeletePort(TimePort);
230 return(NULL);
233 return(TimeRequest);