Build SDL as linklib.
[AROS-Contrib.git] / ScalosV2 / PopupMenuClass.c
blob2f3f370d43575209f454f2f1180e1adb76f02fee
1 // :ts=4 (Tabsize)
3 #include <proto/utility.h>
4 #include <proto/exec.h>
5 #include <proto/alib.h>
6 #include <proto/pm.h>
7 #include <string.h>
8 #include <exec/memory.h>
10 #include <libraries/pm.h>
11 // #include <proto/pm.h>
13 #include "Scalos.h"
14 #include "PopupMenuClass.h"
15 #include "ScalosIntern.h"
17 #include "scalos_protos.h"
18 #include "Debug.h"
19 #include "SubRoutines.h"
21 /****** PopupMenu.scalos/--background ***************************************
23 * PopupMenu class is used to generate popup menus and to display them
24 * on screen.
26 *****************************************************************************
28 // /
30 /****** PopupMenu.scalos/SCCA_PopupMenu_Item ********************************
32 * NAME
33 * SCCA_PopupMenu_Item -- (V40) IS. (Object *)
35 * FUNCTION
36 * This attribute addes an popup menu item to the menu.
38 *****************************************************************************
40 // /
41 /****** PopupMenu.scalos/SCCA_PopupMenu_Window ******************************
43 * NAME
44 * SCCA_PopupMenu_Window -- (V40) IS. (Object *)
46 * FUNCTION
47 * Sets the window object where the popup menu should belong to. This
48 * attribute must be given.
50 *****************************************************************************
52 // /
54 /** Init a PopupMenu
56 static ULONG PopupMenu_Init(struct SC_Class *cl, Object *obj, struct SCCP_Init *msg, struct PopupMenuInst *inst)
58 if (SC_DoSuperMethodA(cl,obj, (Msg) msg))
60 struct TagItem *tags = msg->ops_AttrList;
61 struct TagItem **taglist = &tags;
62 struct TagItem *tag;
63 struct MenuItemNode *node;
65 NewList((struct List *) &inst->itemlist);
67 while ((tag = NextTagItem(taglist)))
69 switch (tag->ti_Tag)
72 case SCCA_PopupMenu_Item:
73 if ((node = (struct MenuItemNode *) AllocNode(&inst->itemlist,sizeof(struct MenuItemNode))))
75 node->itemobj = (Object *) tag->ti_Data;
77 break;
79 case SCCA_PopupMenu_Window:
80 inst->windowobj = (Object *) tag->ti_Data;
81 break;
84 return(TRUE);
86 return(FALSE);
88 // /
90 /** Exit a PopupMenu
92 static ULONG PopupMenu_Exit(struct SC_Class *cl, Object *obj, Msg msg, struct PopupMenuInst *inst)
94 struct MenuItemNode *node;
96 if (inst->popupmenu)
97 PM_FreePopupMenu(inst->popupmenu);
99 for (node = (struct MenuItemNode *) inst->itemlist.mlh_Head; ((struct MinNode *) node)->mln_Succ; node = (struct MenuItemNode *) ((struct MinNode *) node)->mln_Succ)
101 SC_DisposeObject(node->itemobj);
104 FreeAllNodes(&inst->itemlist);
106 return(SC_DoSuperMethodA(cl,obj, (Msg) msg));
108 // /
110 /****** PopupMenu.scalos/SCCM_PopupMenu_Open ********************************
112 * NAME
113 * SCCM_PopupMenu_Open
115 * SYNOPSIS
116 * ULONG SC_DoMethod(obj,SCCM_Popup_Open);
118 * FUNCTION
119 * This method opens the popup menu relative to the mouse position.
120 * The method will return first after the menu was closed.
122 * INPUTS
124 * RESULT
125 * TRUE if the popup was successfully open else FALSE.
127 * SEE ALSO
129 *****************************************************************************
132 static ULONG PopupMenu_Open(struct SC_Class *cl, Object *obj, Msg msg, struct PopupMenuInst *inst)
134 if (!(IsMinListEmpty(&inst->itemlist)))
136 struct MenuItemNode *node;
137 int entrycount = 1;
138 struct TagItem *taglist;
140 if (!(inst->popupmenu))
142 for (node = (struct MenuItemNode *) inst->itemlist.mlh_Head; ((struct MinNode *) node)->mln_Succ; node = (struct MenuItemNode *) ((struct MinNode *) node)->mln_Succ)
144 entrycount++;
147 if ((taglist = (struct TagItem *) AllocVec(entrycount*8,MEMF_ANY)))
149 struct TagItem *tag = taglist;
151 for (node = (struct MenuItemNode *) inst->itemlist.mlh_Head; ((struct MinNode *) node)->mln_Succ; node = (struct MenuItemNode *) ((struct MinNode *) node)->mln_Succ)
153 tag->ti_Tag = PM_Item;
154 if (!(node->item))
155 node->item = (APTR) get(node->itemobj,SCCA_MenuItem_PopupItem);
156 tag->ti_Data = (ULONG) node->item;
157 tag++;
159 tag->ti_Tag = TAG_DONE;
161 inst->popupmenu = PM_MakeMenuA(taglist);
163 FreeVec(taglist);
167 if (inst->popupmenu)
169 ULONG userdata;
171 if ((userdata = PM_OpenPopupMenu((struct Window *) get(inst->windowobj,SCCA_Window_Window),
172 PM_Menu, inst->popupmenu, TAG_DONE)))
174 SC_SetAttrs((Object *) userdata, SCCA_MenuItem_Activated,TRUE,TAG_DONE);
177 return(TRUE);
182 return(FALSE);
184 // /
187 /*-------------------------- MethodList --------------------------------*/
189 struct SC_MethodData PopupMenuMethods[] =
191 { SCCM_Init,(ULONG) PopupMenu_Init, 0, 0, NULL },
192 { SCCM_Exit,(ULONG) PopupMenu_Exit, 0, 0, NULL },
193 { SCMETHOD_DONE, NULL, 0, 0, NULL }