1 #include <intuition/intuition.h>
2 #include <libraries/gadtools.h>
4 #include <proto/exec.h>
6 #include <proto/intuition.h>
7 #include <proto/graphics.h>
8 #include <proto/gadtools.h>
9 #include <proto/alib.h>
17 struct IntuitionBase
*IntuitionBase
;
18 struct GfxBase
*GfxBase
;
19 struct Library
*GadToolsBase
;
21 static struct Screen
*scr
;
22 static struct DrawInfo
*dri
;
23 static struct Window
*win
;
24 static struct Menu
*menus
;
27 static struct NewMenu nm
[] =
29 {NM_TITLE
, "Menu Title 1" },
30 {NM_ITEM
, "Item 1", "A"},
31 {NM_ITEM
, "Item 2", "B"},
32 {NM_ITEM
, "Item 3", "C"},
33 {NM_ITEM
, NM_BARLABEL
},
35 {NM_SUB
, "Subitem 1", "!"},
36 {NM_SUB
, "Subitem 2", "O"},
37 {NM_SUB
, NM_BARLABEL
},
38 {NM_SUB
, "Subitem 3", "Q"},
40 {NM_ITEM
, NM_BARLABEL
},
42 {NM_TITLE
, "Menu Title 2"},
43 {NM_ITEM
, "One", "1", CHECKIT
| CHECKED
| MENUTOGGLE
},
44 {NM_ITEM
, "Two", "2"},
45 {NM_ITEM
, "Three", "3"},
46 {NM_TITLE
, "Menus with Commandstrings"},
47 {NM_ITEM
, "Operation 1", "CTRL 1", NM_COMMANDSTRING
},
48 {NM_ITEM
, "Operation 3", "CTRL 2", NM_COMMANDSTRING
},
49 {NM_ITEM
, "Help", "ALT 3", NM_COMMANDSTRING
},
50 {NM_ITEM
, NM_BARLABEL
},
51 {NM_ITEM
, "Cool", "4", CHECKIT
| CHECKED
, 32 + 64 + 128},
52 {NM_ITEM
, "Great", "5", CHECKIT
, 16 + 64 + 128},
53 {NM_ITEM
, "Nice", "6", CHECKIT
, 16 + 32 + 128},
54 {NM_ITEM
, "Bad", "7", CHECKIT
, 16 + 32 + 64},
55 {NM_TITLE
, "Disabled", NULL
, NM_MENUDISABLED
},
59 {NM_ITEM
, NM_BARLABEL
},
67 static void Cleanup(char *msg
)
73 printf("MenuDemo: %s\n",msg
);
85 if (menus
) FreeMenus(menus
);
87 if (vi
) FreeVisualInfo(vi
);
88 if (dri
) FreeScreenDrawInfo(scr
,dri
);
89 if (scr
) UnlockPubScreen(0,scr
);
91 if (GadToolsBase
) CloseLibrary(GadToolsBase
);
92 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
93 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
98 static void OpenLibs(void)
100 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library",39)))
102 Cleanup("Can't open intuition.library V39!");
105 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library",39)))
107 Cleanup("Can't open graphics.library V39!");
110 if (!(GadToolsBase
= OpenLibrary("gadtools.library",39)))
112 Cleanup("Can't open gadtools.library V39!");
116 static void GetVisual(void)
118 if (!(scr
= LockPubScreen(0)))
120 Cleanup("Can't lock screen!");
123 if (!(dri
= GetScreenDrawInfo(scr
)))
125 Cleanup("Can't get drawinfo!");
128 if (!(vi
= GetVisualInfo(scr
,0)))
130 Cleanup("Can't get visual info!");
134 static void MakeMenus(void)
136 menus
= CreateMenusA(nm
, NULL
);
137 if (!menus
) Cleanup("Can't create menus!");
139 if (!LayoutMenusA(menus
, vi
, NULL
)) Cleanup("Can't layout menus!");
142 static void MakeWin(void)
144 win
= OpenWindowTags(0,WA_Left
,scr
->MouseX
,
147 WA_Height
,scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1,
149 WA_Title
,(IPTR
)"MenuDemo",
154 WA_IDCMP
, IDCMP_CLOSEWINDOW
| IDCMP_MENUPICK
,
157 if (!win
) Cleanup("Can't open window!");
159 SetMenuStrip(win
, menus
);
161 ScreenToFront(win
->WScreen
);
164 static void HandleAll(void)
166 struct IntuiMessage
*msg
;
167 struct MenuItem
*item
;
174 WaitPort(win
->UserPort
);
175 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
179 case IDCMP_CLOSEWINDOW
:
184 printf("\nMENUPICK: ------------------------\n\n");
187 while(men
!= MENUNULL
)
189 printf("MENU %d, ITEM %d, SUBITEM %d\n", MENUNUM(men
), ITEMNUM(men
), SUBNUM(men
));
191 if ((item
= ItemAddress(menus
, men
)))
193 men
= item
->NextSelect
;
200 } /* switch(msg->Class) */
202 ReplyMsg((struct Message
*)msg
);
204 } /* while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) */
206 } /* while(!quitme) */