-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmart_menu.h
184 lines (174 loc) · 6.07 KB
/
smart_menu.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* =============================================================================
* PROGRAM: CODE LIBRARY
* FILENAME: smart_menu.h
*
* DESCRIPTION:
* This module provides a set of functions to make menu handling for
* Intuition easier.
* A much simpler set of data structures for simple text menu are used.
*
* Each menu on is specified in an array of SmartMenuItem.
* The last element of the array should have all fields set to NULL to mark
* the end of the menu.
* Each SmartMenuItem specifies the Text, colour and command sequence to use
* for the menu item. It also specifies the function to be called when the
* menu item is selected.
* Note: The same structure is used for menus and submenus.
*
* The menus on the menu bar are specified in an array of SmartMenu.
* This array should also be terminated with an entry with all elements set to
* NULL.
*
* The menu structure specified in the array of SmartMenu is set to a window
* using the MakeMenuStructure function. This function alocates and sets up the
* Intuition structures required for the menu and then assigns the menu to the
* specified window.
*
* The window containing the menu should have the IDCMP_MENUPICK flag set so
* it will receive menu events.
* When a menu event is received for the window, call DoMenuSelection to
* with the Code field of the IntuiMessage handle the event. This will call
* the specified callback function of the event picked.
*
* NOTE: This module can currently only handle the menu for one window at a
* time.
*
* =============================================================================
* COPYRIGHT:
*
* Copyright (c) 1995, 2004, Julian Olds
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* . Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* . Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
* =============================================================================
* EXPORTED VARIABLES
*
* Quit : This is set to true for the quit event.
*
* =============================================================================
* EXPORTED FUNCTIONS
*
* MenuNil : The Null action event handler for menu items that do nothing.
* MenuQuit : The default Quit application menu handler. Sets the Quit flag.
* This should also be called when the application exits if it is not
* used to handle the Quit menu item.
* MakeMenuStructure : Makes the Intuition menu structure and assigns the menu
* into a window.
* DoMenuSelection : Handles the menu selection events.
*
* =============================================================================
*/
#ifndef __SMART_MENU_H
# define __SMART_MENU_H
# include <intuition/intuition.h>
extern int Quit;
struct SmartMenuItem {
char *Text;
char ComSeq;
UBYTE FrontPen;
UBYTE BackPen;
void (*SelectFunction)(void);
struct SmartMenuItem *SubItem;
};
struct SmartMenu {
char *Text;
struct SmartMenuItem *FirstItem;
};
/* =============================================================================
* FUNCTION: MenuNil
*
* DESCRIPTION:
* This is the null callback function for menu events. This is to be used
* for any items used as separators inthe menu structure.
* It can also be used as a stub function for any menu item whose behaviour
* is not yet defined.
*
* PARAMETERS:
*
* None.
*
* RETURN VALUE:
*
* None.
*/
void MenuNil(void);
/* =============================================================================
* FUNCTION: MenuQuit
*
* DESCRIPTION:
* The default Quit application menu handler.
* This function frees any allcoated memory for menu structures and sets the
* Quit flag.
* This should also be called when the application exits if it is not used to
* handle the Quit menu item.
*
* PARAMETERS:
*
* None.
*
* RETURN VALUE:
*
* None.
*/
void MenuQuit(void);
/* =============================================================================
* FUNCTION: MakeMenuStructure
*
* DESCRIPTION:
* This function build the Intuition Menu structures according to the
* menu layout specified in WindowMenu and assigns the menu created to the
* Window specified in MenuWindow.
*
* PARAMETERS:
*
* MWindow : The window to use the menu.
*
* WindowMenu : The SmartMenu specification of the menu structure.
*
* RETURN VALUE:
*
* int: TRUE if the menu was successfully created.
*/
int MakeMenuStructure(struct Window *MWindow, struct SmartMenu *WindowMenu);
/* =============================================================================
* FUNCTION: DoMenuSelection
*
* DESCRIPTION:
* This function handles the IDCMP_MENIPICK event, and calls the handler
* function for the menu item picked.
*
* PARAMETERS:
*
* code : The Code field of the IntuiMessage.
*
* RETURN VALUE:
*
* None.
*/
void DoMenuSelection(USHORT code);
#endif