|
|
1.1 root 1: /****************************************************************************/
2: /* */
3: /* Microsoft Confidential */
4: /* */
5: /* Copyright (c) Microsoft Corp. 1987, 1991 */
6: /* All Rights Reserved */
7: /* */
8: /****************************************************************************/
9: /****************************** Module Header *******************************
10: * Module Name: menucmd.c
11: *
12: * Contains routines to dispatch the menu commands.
13: *
14: * History:
15: *
16: ****************************************************************************/
17:
18: #include "imagedit.h"
19: #include "dialogs.h"
20: #include "ids.h"
21:
22: #include <direct.h>
23: #include <string.h>
24:
25: STATICFN INT GetHelpContext(INT idSubject, PHELPMAP phmap);
26:
27:
28:
29: /************************************************************************
30: * InitMenu
31: *
32: * This function grays/enables and checks/unchecks the menu items
33: * appropriately for the given state.
34: *
35: * Arguments:
36: * HMENU hMenu - The menu handle.
37: *
38: * History:
39: *
40: ************************************************************************/
41:
42: VOID InitMenu(
43: HMENU hMenu)
44: {
45: BOOL fEnable;
46: INT i;
47:
48: MyEnableMenuItem(hMenu, MENU_FILE_SAVE, fImageDirty || fFileDirty);
49: MyEnableMenuItem(hMenu, MENU_FILE_SAVEAS, gpImageHead);
50: MyEnableMenuItem(hMenu, MENU_FILE_LOADCOLORS, gnColors != 2);
51: MyEnableMenuItem(hMenu, MENU_FILE_SAVECOLORS, gnColors != 2);
52:
53: /*
54: * Only enable the option to restore the default colors if this
55: * is not a monochrome palette and at least one of the colors
56: * has been changed.
57: */
58: fEnable = FALSE;
59: if (gnColors != 2) {
60: for (i = 0; i < COLORSMAX; i++) {
61: if (gargbColor[i] != gargbDefaultColor[i]) {
62: fEnable = TRUE;
63: break;
64: }
65: }
66: }
67:
68: MyEnableMenuItem(hMenu, MENU_FILE_DEFAULTCOLORS, fEnable);
69:
70: MyEnableMenuItem(hMenu, MENU_EDIT_UNDO, ghbmUndo);
71: MyEnableMenuItem(hMenu, MENU_EDIT_RESTORE,
72: gpImageCur && gpImageCur->DIBPtr && fImageDirty);
73: MyEnableMenuItem(hMenu, MENU_EDIT_COPY, gpImageCur);
74: MyEnableMenuItem(hMenu, MENU_EDIT_PASTE,
75: gpImageCur && IsClipboardFormatAvailable(CF_BITMAP));
76: MyEnableMenuItem(hMenu, MENU_EDIT_CLEAR, gpImageCur);
77:
78: /*
79: * We can add new images if the current image is not a bitmap,
80: * and we have possible new images to add, and there is a current
81: * file being edited. This last case is checked by looking to
82: * see that there is either a current file name, or there is a
83: * current image (the case for new files).
84: */
85: MyEnableMenuItem(hMenu, MENU_EDIT_NEWIMAGE,
86: giType != FT_BITMAP &&
87: ((giType == FT_ICON) ?
88: (gnImages < gnIconDevices) : (gnImages < gnCursorDevices)) &&
89: (gpImageCur || gpszFileName));
90:
91: MyEnableMenuItem(hMenu, MENU_EDIT_SELECTIMAGE,
92: giType != FT_BITMAP && gnImages > 0);
93: MyEnableMenuItem(hMenu, MENU_EDIT_DELETEIMAGE,
94: giType != FT_BITMAP && gnImages > 0);
95:
96: MyCheckMenuItem(hMenu, MENU_OPTIONS_GRID, gfGrid);
97: MyCheckMenuItem(hMenu, MENU_OPTIONS_BRUSH2, gnBrushSize == 2);
98: MyCheckMenuItem(hMenu, MENU_OPTIONS_BRUSH3, gnBrushSize == 3);
99: MyCheckMenuItem(hMenu, MENU_OPTIONS_BRUSH4, gnBrushSize == 4);
100: MyCheckMenuItem(hMenu, MENU_OPTIONS_BRUSH5, gnBrushSize == 5);
101: MyCheckMenuItem(hMenu, MENU_OPTIONS_SHOWCOLOR, gfShowColor);
102: MyCheckMenuItem(hMenu, MENU_OPTIONS_SHOWVIEW, gfShowView);
103: MyCheckMenuItem(hMenu, MENU_OPTIONS_SHOWTOOLBOX, gfShowToolbox);
104: }
105:
106:
107:
108: /************************************************************************
109: * MenuCmd
110: *
111: * Dispatches all the menu commands.
112: *
113: * Arguments:
114: *
115: * History:
116: *
117: ************************************************************************/
118:
119: VOID MenuCmd(
120: INT item)
121: {
122: switch (item) {
123:
124: /*
125: * File menu ----------------------------------------------------
126: */
127:
128: case MENU_FILE_OPEN:
129: if (VerifySaveFile())
130: OpenAFile();
131:
132: break;
133:
134: case MENU_FILE_NEW:
135: if (VerifySaveFile()) {
136: if (DlgBox(DID_RESOURCETYPE,
137: (WNDPROC)ResourceTypeDlgProc) == IDOK) {
138: /*
139: * Clear out the current resource.
140: */
141: ClearResource();
142:
143: if (iNewFileType == FT_BITMAP)
144: DlgBox(DID_BITMAPSIZE, (WNDPROC)BitmapSizeDlgProc);
145: else
146: ImageNewDialog(iNewFileType);
147: }
148: }
149:
150: break;
151:
152: case MENU_FILE_SAVE:
153: SaveFile(FALSE);
154: break;
155:
156: case MENU_FILE_SAVEAS:
157: SaveFile(TRUE);
158: break;
159:
160: case MENU_FILE_LOADCOLORS:
161: LoadColorFile();
162: break;
163:
164: case MENU_FILE_SAVECOLORS:
165: SaveColorFile();
166: break;
167:
168: case MENU_FILE_DEFAULTCOLORS:
169: RestoreDefaultColors();
170: break;
171:
172: case MENU_FILE_EXIT:
173: SendMessage(ghwndMain, WM_SYSCOMMAND, SC_CLOSE, 0L);
174: break;
175:
176: /*
177: * Edit menu ----------------------------------------------------
178: */
179:
180: case MENU_EDIT_UNDO:
181: ImageUndo();
182: break;
183:
184: case MENU_EDIT_RESTORE:
185: /*
186: * Reopen the most recently retained image (without
187: * prompting for a save).
188: */
189: ImageOpen2(gpImageCur);
190: break;
191:
192: case MENU_EDIT_COPY:
193: CopyImageClip();
194: break;
195:
196: case MENU_EDIT_PASTE:
197: PasteImageClip();
198: break;
199:
200: case MENU_EDIT_CLEAR:
201: ImageUpdateUndo();
202: ImageDCClear();
203: ViewUpdate();
204: break;
205:
206: case MENU_EDIT_NEWIMAGE:
207: ImageNewDialog(giType);
208: break;
209:
210: case MENU_EDIT_SELECTIMAGE:
211: ImageSelectDialog();
212: break;
213:
214: case MENU_EDIT_DELETEIMAGE:
215: ImageDelete();
216: break;
217:
218: /*
219: * Options menu -------------------------------------------------
220: */
221:
222: case MENU_OPTIONS_GRID:
223: /*
224: * Toggle the grid state.
225: */
226: gfGrid ^= TRUE;
227:
228: /*
229: * Repaint the workspace window to show/remove the grid.
230: */
231: WorkUpdate();
232:
233: break;
234:
235: case MENU_OPTIONS_BRUSH2:
236: case MENU_OPTIONS_BRUSH3:
237: case MENU_OPTIONS_BRUSH4:
238: case MENU_OPTIONS_BRUSH5:
239: switch (item) {
240: case MENU_OPTIONS_BRUSH2:
241: gnBrushSize = 2;
242: break;
243:
244: case MENU_OPTIONS_BRUSH3:
245: gnBrushSize = 3;
246: break;
247:
248: case MENU_OPTIONS_BRUSH4:
249: gnBrushSize = 4;
250: break;
251:
252: case MENU_OPTIONS_BRUSH5:
253: gnBrushSize = 5;
254: break;
255: }
256:
257: break;
258:
259: case MENU_OPTIONS_SHOWCOLOR:
260: /*
261: * Toggle the state of the color palette.
262: */
263: gfShowColor = gfShowColor ? FALSE : TRUE;
264: ColorShow(gfShowColor);
265: break;
266:
267: case MENU_OPTIONS_SHOWVIEW:
268: /*
269: * Toggle the state of the view window.
270: */
271: gfShowView = gfShowView ? FALSE : TRUE;
272: ViewShow(gfShowView);
273: break;
274:
275: case MENU_OPTIONS_SHOWTOOLBOX:
276: /*
277: * Toggle the state of the Toolbox.
278: */
279: gfShowToolbox = gfShowToolbox ? FALSE : TRUE;
280: ToolboxShow(gfShowToolbox);
281: break;
282:
283: /*
284: * Help menu ----------------------------------------------------
285: */
286:
287: case MENU_HELP_CONTENTS:
288: WinHelp(ghwndMain, gszHelpFile, HELP_CONTENTS, 0L);
289: break;
290:
291: case MENU_HELP_SEARCH:
292: /*
293: * Tell winhelp to be sure this app's help file is current,
294: * then invoke a search with an empty starting key.
295: */
296: WinHelp(ghwndMain, gszHelpFile, HELP_FORCEFILE, 0);
297: WinHelp(ghwndMain, gszHelpFile, HELP_PARTIALKEY, (DWORD)(LPSTR)"");
298: break;
299:
300: case MENU_HELP_ABOUT:
301: DlgBox(DID_ABOUT, (WNDPROC)AboutDlgProc);
302: break;
303:
304: /*
305: * Hidden menu commands (accessed by accelerators) --------------
306: */
307:
308: case MENU_HIDDEN_TOCOLORPAL:
309: if (IsWindowVisible(ghwndColor))
310: SetFocus(ghwndColor);
311:
312: break;
313:
314: case MENU_HIDDEN_TOVIEW:
315: if (IsWindowVisible(ghwndView))
316: SetFocus(ghwndView);
317:
318: break;
319:
320: case MENU_HIDDEN_TOTOOLBOX:
321: if (IsWindowVisible(ghwndToolbox))
322: SetFocus(ghwndToolbox);
323:
324: break;
325:
326: case MENU_HIDDEN_TOPROPBAR:
327: SetFocus(ghwndPropBar);
328: break;
329: }
330: }
331:
332:
333:
334: /************************************************************************
335: * MsgFilterHookFunc
336: *
337: * This is the exported message filter function that is hooked into
338: * the message stream for detecting the pressing of the F1 key, at
339: * which time it calls up the appropriate help.
340: *
341: * Arguments:
342: *
343: * History:
344: *
345: ************************************************************************/
346:
347: DWORD APIENTRY MsgFilterHookFunc(
348: INT nCode,
349: WPARAM wParam,
350: LPMSG lpMsg)
351: {
352: if ((nCode == MSGF_MENU || nCode == MSGF_DIALOGBOX) &&
353: (lpMsg->message == WM_KEYDOWN && lpMsg->wParam == VK_F1)) {
354: /*
355: * Display help.
356: */
357: ShowHelp((nCode == MSGF_MENU) ? TRUE : FALSE);
358:
359: /*
360: * Tell Windows to swallow this message.
361: */
362: return 1;
363: }
364:
365: return DefHookProc(nCode, wParam, (LONG)lpMsg, &ghhkMsgFilter);
366: }
367:
368:
369:
370: /************************************************************************
371: * ShowHelp
372: *
373: * This function is called when the user has requested help. It will
374: * look at the menu state (if fMenuHelp is TRUE) or which dialog
375: * is currently up to determine the help topic, then it calls WinHelp.
376: *
377: * Arguments:
378: * BOOL fMenuHelp - TRUE if this help is for a menu (help was requested
379: * in the menu modal loop). If FALSE, general help
380: * or help for a dialog is assumed.
381: *
382: * History:
383: *
384: ************************************************************************/
385:
386: VOID ShowHelp(
387: BOOL fMenuHelp)
388: {
389: INT nHelpContext = 0;
390: HWND hwndFocus;
391:
392: if (fMenuHelp) {
393: nHelpContext = GetHelpContext(gMenuSelected, gahmapMenu);
394: }
395: else {
396: /*
397: * Look for help for the current dialog.
398: */
399: if (gidCurrentDlg) {
400: nHelpContext = GetHelpContext(gidCurrentDlg, gahmapDialog);
401: }
402: else {
403: /*
404: * There is no current dialog. Is the window with the
405: * focus a control on the Properties Bar?
406: */
407: if ((hwndFocus = GetFocus()) && IsChild(ghwndPropBar, hwndFocus))
408: nHelpContext = GetHelpContext(DID_PROPBAR, gahmapDialog);
409: }
410: }
411:
412: /*
413: * If there is help context, display it. Otherwise display
414: * the Contents screen.
415: */
416: if (nHelpContext)
417: WinHelp(ghwndMain, gszHelpFile, HELP_CONTEXT, nHelpContext);
418: else
419: WinHelp(ghwndMain, gszHelpFile, HELP_CONTENTS, 0L);
420: }
421:
422:
423:
424: /************************************************************************
425: * GetHelpContext
426: *
427: * This function takes a subject and returns its matching help
428: * context id from the given HELPMAP table.
429: *
430: * Arguments:
431: * INT idSubject - ID of the subject to find the help context for.
432: * PHELPMAP phmap - The help map table. It is assumed that the
433: * last entry in the table has a NULL subject id.
434: *
435: * History:
436: *
437: ************************************************************************/
438:
439: STATICFN INT GetHelpContext(
440: INT idSubject,
441: PHELPMAP phmap)
442: {
443: while (phmap->idSubject) {
444: if (phmap->idSubject == idSubject)
445: return phmap->HelpContext;
446:
447: phmap++;
448: }
449:
450: return 0;
451: }
452:
453:
454:
455: /************************************************************************
456: * AboutDlgProc
457: *
458: * This is the About Box dialog procedure.
459: *
460: * History:
461: *
462: ************************************************************************/
463:
464: DIALOGPROC AboutDlgProc(
465: HWND hwnd,
466: UINT msg,
467: WPARAM wParam,
468: LPARAM lParam)
469: {
470: switch (msg) {
471: case WM_INITDIALOG:
472: {
473: CHAR szVersion[CCHTEXTMAX];
474:
475: strcpy(szVersion, ids(IDS_VERSION));
476: strcat(szVersion, ids(IDS_VERSIONMINOR));
477:
478: #ifdef DBG
479: strcat(szVersion, " (debug)");
480: #endif
481:
482: SetDlgItemText(hwnd, DID_ABOUTVERSION, szVersion);
483: CenterWindow(hwnd);
484: }
485:
486: return TRUE;
487:
488: case WM_COMMAND:
489: EndDialog(hwnd, IDOK);
490: return TRUE;
491:
492: default:
493: return FALSE;
494: }
495: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.