3 #include <proto/utility.h>
4 #include <proto/exec.h>
5 #include <proto/alib.h>
8 #include <exec/memory.h>
10 #include <libraries/pm.h>
11 // #include <proto/pm.h>
14 #include "PopupMenuClass.h"
15 #include "ScalosIntern.h"
17 #include "scalos_protos.h"
19 #include "SubRoutines.h"
21 /****** PopupMenu.scalos/--background ***************************************
23 * PopupMenu class is used to generate popup menus and to display them
26 *****************************************************************************
30 /****** PopupMenu.scalos/SCCA_PopupMenu_Item ********************************
33 * SCCA_PopupMenu_Item -- (V40) IS. (Object *)
36 * This attribute addes an popup menu item to the menu.
38 *****************************************************************************
41 /****** PopupMenu.scalos/SCCA_PopupMenu_Window ******************************
44 * SCCA_PopupMenu_Window -- (V40) IS. (Object *)
47 * Sets the window object where the popup menu should belong to. This
48 * attribute must be given.
50 *****************************************************************************
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
;
63 struct MenuItemNode
*node
;
65 NewList((struct List
*) &inst
->itemlist
);
67 while ((tag
= NextTagItem(taglist
)))
72 case SCCA_PopupMenu_Item
:
73 if ((node
= (struct MenuItemNode
*) AllocNode(&inst
->itemlist
,sizeof(struct MenuItemNode
))))
75 node
->itemobj
= (Object
*) tag
->ti_Data
;
79 case SCCA_PopupMenu_Window
:
80 inst
->windowobj
= (Object
*) tag
->ti_Data
;
92 static ULONG
PopupMenu_Exit(struct SC_Class
*cl
, Object
*obj
, Msg msg
, struct PopupMenuInst
*inst
)
94 struct MenuItemNode
*node
;
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
));
110 /****** PopupMenu.scalos/SCCM_PopupMenu_Open ********************************
113 * SCCM_PopupMenu_Open
116 * ULONG SC_DoMethod(obj,SCCM_Popup_Open);
119 * This method opens the popup menu relative to the mouse position.
120 * The method will return first after the menu was closed.
125 * TRUE if the popup was successfully open else FALSE.
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
;
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
)
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
;
155 node
->item
= (APTR
) get(node
->itemobj
,SCCA_MenuItem_PopupItem
);
156 tag
->ti_Data
= (ULONG
) node
->item
;
159 tag
->ti_Tag
= TAG_DONE
;
161 inst
->popupmenu
= PM_MakeMenuA(taglist
);
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
);
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
}