AmendHub

Download

pfuentes69

/

FractalViewer

/

FractalViewerMenus.cp

 

(View History)

pfp   First commit Latest amendment: 1 on 2022-08-26

1 /*****
2 * FractalViewerMenus.cp
3 *
4 * Menu handling routines for the program
5 *
6 *****/
7
8 #include <oops.h>
9 #include "FractalViewerMenus.h"
10 #include "FractalViewerPrefs.h"
11 #include "TFractalViewerWindow.h"
12 #include "TMandelbrot.h"
13 #include "TJulia.h"
14 #include "TPlasma.h"
15
16
17 // prototypes for utility routines
18 static void enable (MenuHandle menu, short item, Boolean enableMenu);
19 static findColorItem (long color);
20
21 MenuHandle appleMenu,
22 fileMenu,
23 editMenu,
24 styleMenu,
25 viewMenu;
26
27 enum { // Menu ids
28 appleID = 1,
29 fileID,
30 editID,
31 styleID,
32 viewID
33 };
34
35 enum { // items in the File menu
36 mandelItem = 1,
37 juliaItem,
38 plasmaItem,
39 closeItem,
40 prefsItem = closeItem+2, // leave space for the dashed line before Preferences
41 quitItem = prefsItem+2 // leave space for the dashed line before Quit
42 };
43
44
45 enum { // items in the File menu
46 restoreItem = 1,
47 zoomInItem,
48 zoomOutItem,
49 separatorItem,
50 FastModeItem,
51 NormalModeItem,
52 FineModeItem
53 };
54
55
56
57 /****
58 * SetUpMenus()
59 *
60 * Set up the menus.
61 *
62 ****/
63
64 void SetUpMenus(void)
65
66 {
67 InsertMenu(appleMenu = GetMenu(appleID), 0);
68 AddResMenu(appleMenu, 'DRVR');
69
70 InsertMenu(fileMenu = GetMenu(fileID), 0);
71 InsertMenu(editMenu = GetMenu(editID), 0);
72 InsertMenu(styleMenu = GetMenu(styleID), 0);
73 InsertMenu(viewMenu = GetMenu(viewID), 0);
74
75 DrawMenuBar();
76 }
77 /* end SetUpMenus */
78
79
80 /****
81 * AdjustMenus()
82 *
83 * Enable or disable the items in the Edit menu if a DA window
84 * comes up or goes away. Our application doesn't do anything with
85 * the Edit menu. If one of our windows is frontmost, adjust the
86 * Width and color menus to reflect the proper values for the
87 * windows.
88 *
89 ****/
90
91 #define isEnabled(mH) ((**mH).enableFlags & 0x01)
92
93 void AdjustMenus(void)
94 {
95 register WindowPeek wp = (WindowPeek) FrontWindow();
96 short kind = wp ? wp->windowKind : 0;
97 short i;
98 short max;
99 static short redrawForEdit = true; // did the Edit menu change?
100 static short redrawForWidth = true; // did the Width menu change?
101
102 if (kind < 0) { // enable Edit for desk accessories
103 redrawForEdit = !isEnabled(editMenu);
104 enable(editMenu, 0, true);
105 }
106 else { // disable it for all others
107 redrawForEdit = isEnabled(editMenu);
108 enable(editMenu, 0, false);
109 }
110
111 // enable the Close command for DAs and our windows
112 enable(fileMenu, closeItem, kind < 0 || kind == TWINDOWKIND);
113
114 // disable the Width and color menus if our window isn't frontmost
115 if (kind != TWINDOWKIND) {
116 redrawForWidth = isEnabled(styleMenu);
117 enable(styleMenu, 0, false);
118 enable(viewMenu, 0, false);
119 }
120 else {
121 redrawForWidth = !isEnabled(styleMenu);
122 enable(styleMenu, 0, true);
123 enable(viewMenu, 0, true);
124
125 max = CountMItems(styleMenu); // uncheck all the widths
126 for (i = 1; i <= max; i++)
127 CheckItem(styleMenu, i, false);
128
129 max = CountMItems(viewMenu); // uncheck all the colors
130 for (i = 1; i <= max; i++) {
131 CheckItem(viewMenu, i, false);
132 }
133
134 // check the style for the frontmost window
135 CheckItem(styleMenu, OBJ(wp)->GetStyle(), true);
136 // check the drawMode for the frontmost window
137 CheckItem(viewMenu, separatorItem + OBJ(wp)->GetDrawMode(), true);
138 }
139
140 if (redrawForEdit || redrawForWidth) {
141 DrawMenuBar();
142 redrawForEdit = redrawForWidth = false;
143 }
144 }
145
146 /**
147 * enable or disable a menu
148 *
149 **/
150
151 static void enable (MenuHandle menu, short item, Boolean enableMenu)
152 {
153 if (enableMenu)
154 EnableItem(menu, item);
155 else
156 DisableItem(menu, item);
157 }
158
159 /**
160 * given an old QuickDraw color, find its menu item number
161 *
162 **/
163
164 /*
165 static findColorItem (long color)
166 {
167 short i;
168 short max = sizeof(colorTable) / sizeof(long);
169
170 for (i= 1; i <= max; i++)
171 if (colorTable[i] == color)
172 return i;
173 else return 0;
174 DebugStr("\pBAD COLOR!");
175 }
176 */
177
178
179
180 /*****
181 * HandleMenu(mSelect)
182 *
183 * Handle the menu selection. mSelect is what MenuSelect() and
184 * MenuKey() return: the high word is the menu ID, the low word
185 * is the menu item
186 *
187 *****/
188
189 void HandleMenu (long mSelect)
190 {
191 short menuID = HiWord(mSelect);
192 short menuItem = LoWord(mSelect);
193 Str255 name;
194 GrafPtr savePort;
195 TFractalViewerWindow *fractalWindow;
196 WindowPeek wp;
197
198 switch (menuID)
199 {
200 case appleID:
201 if (menuItem == 1)
202 {
203 Alert(128, 0L);
204 break;
205 }
206
207 GetPort(&savePort);
208 GetItem(appleMenu, menuItem, name);
209 OpenDeskAcc(name);
210 SetPort(savePort);
211 break;
212
213 case fileID:
214 switch (menuItem)
215 {
216 case mandelItem:
217 fractalWindow = new(TMandelbrot);
218 break;
219
220 case juliaItem:
221 fractalWindow = new(TJulia);
222 break;
223
224 case plasmaItem:
225 fractalWindow = new(TPlasma);
226 break;
227
228 case closeItem:
229 if ((wp = (WindowPeek) FrontWindow()) == NULL)
230 break;
231
232 if (wp->windowKind < 0)
233 CloseDeskAcc(wp->windowKind);
234 else if (wp->windowKind == TWINDOWKIND)
235 OBJ(wp)->Close();
236 break;
237
238 case prefsItem:
239 HandlePrefs();
240 break;
241
242 case quitItem:
243 ExitToShell();
244 break;
245 }
246 break;
247
248 case editID:
249 if (!SystemEdit(menuItem-1))
250 SysBeep(5);
251 break;
252
253 case styleID:
254 if ((wp = (WindowPeek) FrontWindow()) == 0L ||
255 wp->windowKind != TWINDOWKIND)
256 break;
257
258 OBJ(wp)->SetStyle(menuItem);
259 break;
260
261 case viewID:
262 if ((wp = (WindowPeek) FrontWindow()) == 0L ||
263 wp->windowKind != TWINDOWKIND)
264 break;
265
266 switch (menuItem) {
267 case restoreItem:
268 OBJ(wp)->ZoomContent(0);
269 break;
270
271 case zoomInItem:
272 OBJ(wp)->ZoomContent(+1);
273 break;
274
275 case zoomOutItem:
276 OBJ(wp)->ZoomContent(-1);
277 break;
278
279 case FastModeItem:
280 OBJ(wp)->SetDrawMode(1);
281 break;
282
283 case NormalModeItem:
284 OBJ(wp)->SetDrawMode(2);
285 break;
286
287 case FineModeItem:
288 OBJ(wp)->SetDrawMode(3);
289 break;
290
291 }
292 break;
293 }
294 }
295 /* end HandleMenu */