add the common pc IRQTYPE definitions, and copy them for both the 32bit and 64bit...
[AROS.git] / rom / intuition / menus.c
blobc8fec3dfbe82981d7e46a6c94457f024d267e09a
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <proto/exec.h>
8 #include <proto/intuition.h>
9 #include <proto/alib.h>
10 #include <proto/layers.h>
11 #include <proto/graphics.h>
12 #include <proto/keymap.h>
13 #include <proto/utility.h>
14 #include <clib/macros.h>
15 #include <exec/memory.h>
16 #include <exec/alerts.h>
17 #include <exec/interrupts.h>
18 #include <exec/ports.h>
19 #include <intuition/intuition.h>
20 #include <intuition/intuitionbase.h>
21 #include <intuition/gadgetclass.h>
22 #include <devices/inputevent.h>
23 #include <devices/input.h>
24 #include "inputhandler.h"
26 #include "intuition_intern.h"
27 #include "menus.h"
29 #define DEBUG_FINDMENUSHORTCUT(x) ;
31 /**************************************************************************************************/
33 struct MenuMessage *AllocMenuMessage(struct IntuitionBase *IntuitionBase)
35 struct MenuMessage *msg;
37 msg = AllocVec(sizeof(struct MenuMessage), MEMF_PUBLIC | MEMF_CLEAR);
39 return msg;
42 /**************************************************************************************************/
44 void FreeMenuMessage(struct MenuMessage *msg, struct IntuitionBase *IntuitionBase)
46 FreeVec(msg);
50 /**************************************************************************************************/
52 void SendMenuMessage(struct MenuMessage *msg, struct IntuitionBase *IntuitionBase)
54 PutMsg(GetPrivIBase(IntuitionBase)->MenuHandlerPort, &msg->msg);
57 /**************************************************************************************************/
59 struct MenuMessage *GetMenuMessage(struct MsgPort *port, struct IntuitionBase *IntuitionBase)
61 return (struct MenuMessage *)GetMsg(port);
65 /**************************************************************************************************/
67 void ReplyMenuMessage(struct MenuMessage *msg, struct IntuitionBase *IntuitionBase)
69 FreeMenuMessage(msg, IntuitionBase);
72 /**************************************************************************************************/
76 void MH2Int_MakeMenusInactive(struct Window *win, UWORD menupick, struct IntuitionBase *IntuitionBase)
78 struct InputEvent ie;
79 struct IOStdReq ior;
80 struct MsgPort replyport;
82 memset( &replyport, 0, sizeof( replyport ) );
84 ie.ie_NextEvent = 0;
85 ie.ie_Class = IECLASS_MENU;
86 ie.ie_SubClass = IESUBCLASS_MENUSTOP;
87 ie.ie_Code = menupick;
88 ie.ie_EventAddress = win;
90 replyport.mp_Node.ln_Type = NT_MSGPORT;
91 replyport.mp_Flags = PA_SIGNAL;
92 replyport.mp_SigBit = SIGB_INTUITION;
93 replyport.mp_SigTask = FindTask(NULL);
94 NEWLIST(&replyport.mp_MsgList);
96 ior = *(GetPrivIBase(IntuitionBase)->InputIO);
97 ior.io_Message.mn_ReplyPort = &replyport;
99 ior.io_Command = IND_WRITEEVENT;
100 ior.io_Data = &ie;
101 ior.io_Length = sizeof(struct InputEvent);
103 DoIO((struct IORequest *)&ior);
106 /**************************************************************************************************/
107 /**************************************************************************************************/
108 /**************************************************************************************************/
110 void GetMenuBox(struct Window *win, struct MenuItem *item,
111 WORD *xmin, WORD *ymin, WORD *xmax, WORD *ymax)
114 WORD left, right, top, bottom;
116 left = top = 0x7fff;
117 right = bottom = -0x7fff;
119 while(item != NULL)
121 left = min(left, item->LeftEdge);
122 top = min(top, item->TopEdge);
123 right = max(right, item->LeftEdge + item->Width - 1);
124 bottom = max(bottom, item->TopEdge + item->Height - 1);
126 item = item->NextItem;
129 if (xmin) *xmin = left - win->WScreen->MenuHBorder;
130 if (ymin) *ymin = top - win->WScreen->MenuVBorder;
131 if (xmax) *xmax = right + win->WScreen->MenuHBorder;
132 if (ymax) *ymax = bottom + win->WScreen->MenuVBorder;
136 /**************************************************************************************************/
138 UWORD FindMenuShortCut(struct Menu *menu, UBYTE key, BOOL do_click_op,
139 struct IntuitionBase *IntuitionBase)
141 struct Library *UtilityBase = GetPrivIBase(IntuitionBase)->UtilityBase;
142 struct MenuItem *item, *sub;
143 UWORD menunum, itemnum = 0, subnum = 0;
144 BOOL found = FALSE;
146 DEBUG_FINDMENUSHORTCUT(dprintf("FindMenuShortCut: Menu 0x%lx key 0x%lx <%c> do_click_op 0x%lx\n",menu,key,key,do_click_op));
148 key = ToUpper(key);
150 DEBUG_FINDMENUSHORTCUT(dprintf("FindMenuShortCut: Upperkey 0x%lx <%c>\n",key));
152 for(menunum = 0; menu; menu = menu->NextMenu, menunum ++)
154 DEBUG_FINDMENUSHORTCUT(dprintf("FindMenuShortCut: Menu 0x%lx Menunum %ld\n",menu,menunum));
156 for(item = menu->FirstItem, itemnum = 0; item; item = item->NextItem, itemnum++)
158 DEBUG_FINDMENUSHORTCUT(dprintf("FindMenuShortCut: Item 0x%lx itemnum %ld\n",item,itemnum));
159 if ((sub = item->SubItem))
161 DEBUG_FINDMENUSHORTCUT(dprintf("FindMenuShortCut: Sub 0x%lx\n",sub));
162 for(subnum = 0; sub; sub = sub->NextItem, subnum++)
164 DEBUG_FINDMENUSHORTCUT(dprintf("FindMenuShortCut: Sub 0x%lx subnum %ld Flags 0x%lx Cmd 0x%lx <%c>\n",sub,subnum,sub->Flags,sub->Command,sub->Command));
165 if ((sub->Flags & COMMSEQ) &&
166 (ToUpper((UBYTE)sub->Command) == key))
168 DEBUG_FINDMENUSHORTCUT(dprintf("FindMenuShortCut: found\n"));
169 if (do_click_op)
171 DEBUG_FINDMENUSHORTCUT(dprintf("FindMenuShortCut: click_op\n"));
172 if (sub->Flags & CHECKIT)
174 DEBUG_FINDMENUSHORTCUT(dprintf("FindMenuShortCut: CheckIt change\n"));
175 CheckMenuItemWasClicked(sub, subnum, item);
177 sub->NextSelect = MENUNULL;
179 found = TRUE;
180 break;
183 if (found) break;
186 else
188 DEBUG_FINDMENUSHORTCUT(dprintf("FindMenuShortCut: Item 0x%lx itemnum %ld Flags 0x%lx Cmd 0x%lx <%c>\n",item,itemnum,item->Flags,item->Command,item->Command));
190 if ((item->Flags & COMMSEQ) &&
191 (ToUpper((UBYTE)item->Command) == key))
193 DEBUG_FINDMENUSHORTCUT(dprintf("FindMenuShortCut: found\n"));
194 if (do_click_op)
196 DEBUG_FINDMENUSHORTCUT(dprintf("FindMenuShortCut: click_op\n"));
197 if (item->Flags & CHECKIT)
199 DEBUG_FINDMENUSHORTCUT(dprintf("FindMenuShortCut: CheckIt change\n"));
200 CheckMenuItemWasClicked(item, itemnum, menu->FirstItem);
202 item->NextSelect = MENUNULL;
204 found = TRUE;
205 subnum = NOSUB;
206 break;
210 } /* for each item */
212 if (found) break;
214 } /* for each menu */
216 return found ? FULLMENUNUM(menunum, itemnum, subnum) : MENUNULL;
219 /**************************************************************************************************/
221 void CheckMenuItemWasClicked(struct MenuItem *item, UWORD itemnum, struct MenuItem *parentitem)
223 /* Note: If you change something here, you probably must also change
224 menutask.c/HandleCheckItem() which is used when the
225 user uses the menus with the mouse! */
227 if (item->Flags & MENUTOGGLE)
229 item->Flags ^= CHECKED;
231 else
233 item->Flags |= CHECKED;
236 if (item->MutualExclude)
238 WORD i;
240 for(i = 0; (i < 32) && parentitem; i++, parentitem = parentitem->NextItem)
242 if ((i != itemnum) && (item->MutualExclude & (1L << i)) &&
243 ((parentitem->Flags & (CHECKED | CHECKIT)) == (CHECKIT | CHECKED)))
245 parentitem->Flags &= ~CHECKED;
249 } /* if (item->MutualExclude) */
253 /**************************************************************************************************/