|
|
1.1 ! root 1: /* menu selection and setup */ ! 2: ! 3: #include <stdio.h> ! 4: #include <X/Xlib.h> ! 5: #include <X/XMenu.h> ! 6: ! 7: #include "shimg.h" ! 8: ! 9: /* This structure is mainly created to easily initialize and update the ! 10: * menu panes and selections. The null elements indicate to the initializing ! 11: * routine that that particular pane (and eventually the menu) are complete. ! 12: * ! 13: * When a menu selection is successful, it returns a pointer to the data ! 14: * array in the particular element. The first element contains the pane ! 15: * number in the upper word and the selection flag in the lower word. The ! 16: * second element contains the inverse of the mask to be applied to the ! 17: * corresponding flags location to remove the other panes' selection flags ! 18: * that are orthogonal to this one. The program can then `or' in this ! 19: * pane's selection flag (if desireable) and take the appropriate action. ! 20: */ ! 21: ! 22: struct menupane { ! 23: char *label; ! 24: int active; ! 25: int data[2]; ! 26: }; ! 27: ! 28: struct menupane menuset[] = { ! 29: /* View Ops pane */ ! 30: { "View Ops", 1, VOP, 0 }, ! 31: { "gray scale", 1, { VOP | VOP_GrayScale, VOP_RGB } }, ! 32: { "rgb", 1, { VOP | VOP_RGB, VOP_GrayScale } }, ! 33: { "normal", 1, { VOP | VOP_Normal, VOP_Inverse } }, ! 34: { "inverse", 1, { VOP | VOP_Inverse, VOP_Normal } }, ! 35: { "initialize", 1, { VOP | VOP_Initialize, 0 } }, ! 36: { "EXIT", 1, { 0, 0 } }, ! 37: { 0, 0, 0, 0 }, ! 38: ! 39: /* Cursor Ops pane */ ! 40: { "Cursor Ops", 1, COP, 0 }, ! 41: { "print", 1, { COP | COP_Print, COP_Pan|COP_Zoom2|COP_Zoom4 } }, ! 42: { "pan", 1, { COP | COP_Pan, COP_Print|COP_Zoom2|COP_Zoom4 } }, ! 43: { "zoom x2", 1, { COP | COP_Zoom2, COP_Print|COP_Pan|COP_Zoom4 } }, ! 44: { "zoom x4", 1, { COP | COP_Zoom4, COP_Print|COP_Pan|COP_Zoom2 } }, ! 45: /* { "set origin", 0, COP | COP_SetOrigin, 0 }, ! 46: { "box", 0, COP | COP_Box, 0 }, ! 47: */ { 0, 0, 0, 0 }, ! 48: ! 49: /* Scaling Ops pane */ ! 50: { "Scaling", 1, SOP, 0 }, ! 51: { "linear", 1, { SOP | SOP_Linear, SOP_Log|SOP_Sqrt|SOP_Histogram } }, ! 52: { "sqrt", 1, { SOP | SOP_Sqrt, SOP_Linear|SOP_Sqrt|SOP_Histogram } }, ! 53: /* { "log", 0, { SOP | SOP_Log, SOP_Linear|SOP_Log|SOP_Histogram } }, ! 54: { "histogram", 0, { SOP | SOP_Histogram, SOP_Linear|SOP_Log|SOP_Sqrt } }, ! 55: */ { 0, 0, 0, 0 }, ! 56: ! 57: /* File Ops pane */ ! 58: /* { "I/O", 0, FOP, 0 }, ! 59: { "read image", 0, FOP | FOP_Read, 0 }, ! 60: { "flatfield", 0, FOP | FOP_Flatfield, 0 }, ! 61: { "add image", 0, FOP | FOP_AddImage, 0 }, ! 62: { 0, 0, 0, 0 }, ! 63: */ ! 64: { 0, 0, 0, 0 } ! 65: }; ! 66: ! 67: XMenu *menusetup(program) ! 68: char *program; ! 69: { ! 70: XMenu *menu, *XMenuCreate(); ! 71: int XMenuAddPane(), XMenuAddSelection(), XMenuRecompute(); ! 72: int pane = 0, sel; ! 73: ! 74: register struct menupane *imenu = &menuset[0]; ! 75: ! 76: if((menu = XMenuCreate(RootWindow,program)) == NULL) { ! 77: fprintf(stderr,"Menu creation failed!\n"); ! 78: exit(1); ! 79: } ! 80: /* insert the panes & selections into the menu structure */ ! 81: ! 82: while(imenu->label) { ! 83: sel = 0; ! 84: if((XMenuAddPane(menu,imenu->label,imenu->active)) ! 85: == XM_FAILURE) { ! 86: fprintf(stderr,"Can't add pane %d!\n",pane); ! 87: exit(1); ! 88: } ! 89: ++imenu; ! 90: while(imenu->label) { ! 91: if((XMenuAddSelection(menu,pane,(char *)&imenu->data[0], ! 92: imenu->label,imenu->active)) == XM_FAILURE) { ! 93: fprintf(stderr,"Can't add selection %d to pane %d!\n", ! 94: sel, pane); ! 95: exit(1); ! 96: } ! 97: sel++; ! 98: ++imenu; ! 99: } ! 100: pane++; ! 101: ++imenu; ! 102: } ! 103: XMenuRecompute(menu); ! 104: return(menu); ! 105: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.