Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!rutgers!ucla-cs!zen!ucbvax!hplabs!hp-pcd!hpcvlo!julie From: julie@hpcvlo.HP.COM (Julie Skeen) Newsgroups: comp.windows.x Subject: Re: Xr11 Example Programs (fixes) Message-ID: <3940062@hpcvlo.HP.COM> Date: 28 Dec 87 22:21:13 GMT References: <3940058@hpcvlo.HP.COM> Organization: Hewlett-Packard Co., Corvallis, OR, USA Lines: 542 # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by fred at hpcvxft on Mon Dec 28 14:11:12 1987 # # This archive contains: # sample4.c HelloWorld.h frown.h smile.h # echo x - sample4.c cat >sample4.c <<'@EOF' #include #include #include "HelloWorld.h" #include "smile.h" #include "frown.h" GC gc1, gc2; Display * displayPtr; int screen; main (argc, argv) int argc; char * argv[]; { xrWindowData windowData; XEvent xinput; xrEvent * input; extern xrPFI DrawWindow(); Pixmap pixmap; XImage * image; XSetWindowAttributes wAttr; input = (xrEvent *) & xinput; /* 1. Open the display */ if ((displayPtr = XOpenDisplay (argv[1])) == NULL) { printf ("Could not open the display\n"); exit(); } screen = DefaultScreen(displayPtr); /* 2. Initialize Xrlib */ if (XrInit (displayPtr, screen, NULL) == FALSE) { printf ("Could not initialize Xrlib\n"); exit(); } /* 3. Create and map the window */ wAttr.override_redirect = TRUE; wAttr.border_pixmap = xrWindowForeground; wAttr.background_pixmap = xrWindowBackground; if ((windowId = XCreateWindow (displayPtr, RootWindow(displayPtr, screen), 150, 150, 375, 120, xrBorderWidth, DefaultDepth(displayPtr, screen), InputOutput, DefaultVisual(displayPtr, screen), CWBorderPixmap | CWBackPixmap | CWOverrideRedirect, &wAttr)) == 0) { printf("The window create failed\n"); exit(); } /* 4. Make the window appear on the display */ XMapRaised (displayPtr, windowId); /* 5. Set the window's input */ XrSetRect (&windowData.windowRect, 150, 150 , 375, 120); windowData.foreTile = xrWindowForeground; windowData.backTile = xrWindowBackground; XrInput (windowId,MSG_ADDWINDOW, &windowData); /* 6. Select the input types */ XSelectInput (displayPtr, windowId, ButtonPressMask | ButtonReleaseMask | KeyPressMask | ExposureMask); /* 7. Set up the graphics context to be used during drawing */ gc1 = XCreateGC (displayPtr, RootWindow(displayPtr, screen), 0, 0); _XrSetUpGC (gc1); XSetForeground (displayPtr, gc1, xrBackgroundColor); XSetBackground (displayPtr, gc1, xrForegroundColor); gc2 = XCreateGC (displayPtr, RootWindow(displayPtr, screen), 0, 0); _XrSetUpGC (gc2); XSetForeground (displayPtr, gc2, xrForegroundColor); XSetBackground (displayPtr, gc2, xrBackgroundColor); XSetFont (displayPtr, gc2, xrBaseFontInfo->fid); XSetGraphicsExposures (displayPtr, gc2, 0); /* 8. Draw the window */ DrawWindow (windowId, MSG_NEW, NULL); /* 9. Define the cursor for the window */ XDefineCursor (displayPtr, windowId, xrDefaultCursor); /* 10. Set up and create the menu */ menu = XrMenu (NULL, MSG_NEW, &menuInfo); XrMenu (menu, MSG_ACTIVATEMENU, windowId); /* 11. Set up rasters from smile.h and frown.h */ image = (XImage *)XCreateImage (displayPtr, DefaultVisual(displayPtr, screen), 1, XYBitmap, 0, smile.raster, smile.width, smile.height, BitmapPad(displayPtr), 0); image->bitmap_unit = 16; image->bitmap_pad = 16; image->byte_order = LSBFirst; image->bitmap_bit_order = LSBFirst; pixmap = XCreatePixmap (displayPtr, RootWindow(displayPtr, screen), smile.width, smile.height, DefaultDepth(displayPtr, screen)); XPutImage(displayPtr, pixmap, gc1, image, 0,0,0,0, smile.width, smile.height); niceMsgInfo.rasterId = pixmap; niceMsgInfo.rasterWidth = smile.width; niceMsgInfo.rasterHeight = smile.height; image = (XImage *)XCreateImage (displayPtr, DefaultVisual(displayPtr, screen), 1, XYBitmap, 0, frown.raster, frown.width, frown.height, BitmapPad(displayPtr), 0); image->bitmap_unit = 16; image->bitmap_pad = 16; image->byte_order = LSBFirst; image->bitmap_bit_order = LSBFirst; pixmap = XCreatePixmap (displayPtr, RootWindow(displayPtr, screen), frown.width, frown.height, DefaultDepth(displayPtr, screen)); XPutImage(displayPtr, pixmap, gc1, image, 0,0,0,0,frown.width, frown.height); meanMsgInfo.rasterId = pixmap; meanMsgInfo.rasterWidth = frown.width; meanMsgInfo.rasterHeight = frown.height; /* 12. input loop */ while (1) { if (XrInput (0, MSG_BLKHOTREAD, input) != FALSE) { if (input->type == XrXRAY && input->inputType == XrMENU) { switch (input->value3) { case 0: /* Show the nice message box */ XrMessageBox (&niceMsgInfo, MSG_EDIT, input); break; case 1: /* Show the mean message box */ XrMessageBox (&meanMsgInfo, MSG_EDIT, input); break; case 3: /* Exit */ exit(); break; } } } } } /* This function handles the initial drawing of the window, which occurs if the message is set to MSG_DRAW. It also handles the redrawing of the window when an exposure event occurs. Message will contain MSG_REDRAW. */ xrPFI DrawWindow (window, message, data) Window window; INT32 message; XEvent * data; { xrWindowEvent exposeEvent[1]; xrWindowFunctInfo exposeFunct; XEvent xnullEvent; xrEvent * nullEvent; /* Set up switch to handle the two possible messages */ switch (message) { case MSG_NEW: /* create the titlebar editor */ titleBarInfo.editorWindowId = windowId; titleBar = XrTitleBar (NULL, MSG_NEW, &titleBarInfo); /* * Set up the structure necessary to have this function called * automatically upon an exposure event. */ exposeEvent[0].type = Expose; exposeEvent[0].code = 0; exposeEvent[0].modifier = 0; exposeFunct.processFlag = TRUE; exposeFunct.funct = (xrPFI) DrawWindow; exposeFunct.instance = (INT32) windowId; exposeFunct.message = MSG_REDRAW; exposeFunct.eventCount = 1; exposeFunct.eventList = &exposeEvent[0]; XrInput (windowId, MSG_ADDWINDOWFUNCT, &exposeFunct); case MSG_REDRAW: /* write the text into the window */ XDrawImageString (displayPtr, window, gc2, 20, 50, "Press the Menu Button to display the menu.", 42); XDrawImageString (displayPtr, window, gc2, 70, 50 + xrBaseFontInfo->ascent + xrBaseFontInfo->descent + 5, "(Default: Right Button Down)", 28); /* Redraw the titlebar */ XrTitleBar (titleBar, MSG_REDRAW, XrREDRAW_ALL); /* Push a null event to be returned to the application */ nullEvent = (xrEvent *) &xnullEvent; nullEvent->type = XrXRAY; nullEvent->display = displayPtr; nullEvent->inputType = NULL; XrInput (0, MSG_PUSHEVENT, nullEvent); break; } } @EOF chmod 666 sample4.c echo x - HelloWorld.h cat >HelloWorld.h <<'@EOF' Window windowId; /* The window identifier for the main window */ /* * The declarations for the title bar and the info structure * needed to create the title bar. */ xrEditor * titleBar; xrTitleBarInfo titleBarInfo = { 0, /* windowId */ {0, 0, 0, 0}, /* editor rectangle */ XrVISIBLE | XrSENSITIVE, /* editor state */ -1, -1, /* editor colors - use defaults */ NULL, /* editor font - use defaults */ "Hello World", /* title name */ NULL, /* gadget 1 - unused */ NULL /* gadget 2 - unused */ }; /* * The declarations for the menu instance, items contained * in the menu, and the menu info structure. */ xrMenu * menu; INT8 * menuItems [9] = { "\\KEHHello Message", /* item with a keyboad equiv of ^N */ "\\KEGGoodbye Message", /* item with a keyboad equiv of ^M */ "\\=", /* double line seperator item */ "Quit" }; xrMenuInfo menuInfo = { "Hello World", /* Menu title bar string */ menuItems, /* item array declared above */ 4, /* item count */ NULL, /* menu context - unused */ 0 /* id returned with menu input */ }; /* * The declarations for the two message box info structures. */ INT8 * niceButton[1] = { "Oky Doky" }; xrMsgBoxInfo niceMsgInfo = { { 240, 245 }, /* message box origin */ NULL, /* relative to the RootWindow */ NULL, /* use default panel context */ 0, /* raster height */ 0, /* raster width */ 0, /* raster id */ "Hello World!", /* Text message */ niceButton, /* button strings */ 1 /* button count */ }; INT8 * meanButton[1] = { "Adios" }; xrMsgBoxInfo meanMsgInfo = { { 240, 245 }, /* message box origin */ NULL, /* relative to the RootWindow */ NULL, /* use default panel context */ 0, /* raster height */ 0, /* raster width */ 0, /* raster id */ "Goodbye World!", /* Text message */ meanButton, /* button strings */ 1 /* button count */ }; @EOF chmod 644 HelloWorld.h echo x - frown.h cat >frown.h <<'@EOF' UINT16 frownRaster[] = { 0xffff, 0x01ff, 0xfe00, 0xffff, 0xffff, 0x003f, 0xe000, 0xffff, 0xffff, 0xfc0f, 0xc1ff, 0xffff, 0xffff, 0xff83, 0x0fff, 0xffff, 0xffff, 0xfff0, 0x3fff, 0xfffc, 0x3fff, 0xfffc, 0xffff, 0xfff8, 0x1fff, 0xffff, 0xffff, 0xfff1, 0xcfff, 0xffff, 0xffff, 0xfff3, 0xe7ff, 0xffff, 0xffff, 0xffe7, 0xf3ff, 0xffff, 0xffff, 0xffcf, 0xf9ff, 0xffff, 0xffff, 0xff8f, 0xfcff, 0xffff, 0xffff, 0xff9f, 0xfc7f, 0xfe1f, 0xf87f, 0xff3f, 0xfe7f, 0xf9e7, 0xe79f, 0xff3f, 0xff3f, 0xf7fb, 0xdfef, 0xfe7f, 0xff3f, 0xeffd, 0xbff7, 0xfe7f, 0xff3f, 0xeffd, 0xbff7, 0xfcff, 0xff9f, 0xdffe, 0x7ffb, 0xfcff, 0xff9f, 0xdffe, 0x7ffb, 0xf9ff, 0xff9f, 0xc1fe, 0x07fb, 0xf9ff, 0xffcf, 0xc0fe, 0x03fb, 0xf9ff, 0xffcf, 0xe07d, 0x81f7, 0xf3ff, 0xffcf, 0xe03d, 0x80f7, 0xf3ff, 0xffcf, 0xf03b, 0xc0ef, 0xf3ff, 0xffcf, 0xf827, 0xe09f, 0xf3ff, 0xffcf, 0xfe1f, 0xf87f, 0xf3ff, 0xffcf, 0xffff, 0xffff, 0xf3ff, 0xffcf, 0xffff, 0xffff, 0xf3ff, 0xffcf, 0xffff, 0xffff, 0xf3ff, 0xffcf, 0xffff, 0xffff, 0xf3ff, 0xffcf, 0xffff, 0xffff, 0xf3ff, 0xffcf, 0xffff, 0xffff, 0xf3ff, 0xffcf, 0xffff, 0xffff, 0xf3ff, 0xffcf, 0xffff, 0xffff, 0xf3ff, 0xffcf, 0x07ff, 0xff00, 0xf3ff, 0xffcf, 0xf8ff, 0xf8ff, 0xfbff, 0xffdf, 0xff1f, 0xe7ff, 0xfbff, 0xff9f, 0xffe7, 0x9fff, 0xf9ff, 0xff9f, 0xfffb, 0x7fff, 0xf9ff, 0xff3f, 0xfffc, 0xffff, 0xfcfe, 0x7f3f, 0xffff, 0xffff, 0xfcfd, 0xbf3f, 0xffff, 0xffff, 0xfefb, 0xde7f, 0xffff, 0xffff, 0xfe77, 0xfe7f, 0xffff, 0xffff, 0xff3f, 0xfcff, 0xffff, 0xffff, 0xff3f, 0xf8ff, 0xffff, 0xffff, 0xff9f, 0xf9ff, 0xffff, 0xffff, 0xffcf, 0xf3ff, 0xffff, 0xffff, 0xffc7, 0xe7ff, 0xffff, 0xffff, 0xffe7, 0xcfff, 0xffff, 0xffff, 0xfff3, 0x8fff, 0xffff, 0xffff, 0xfff9, 0x1fff, 0xffff, 0xffff, 0xfffc, 0x3fff, 0xfffe, 0x3fff, 0xfffe, 0x7fff, 0xfffc, 0x1fff, 0xffff, 0xffff, 0xfff0, 0xc3ff, 0xffff, 0xffff, 0xffe1, 0xe0ff, 0xffff, 0xffff, 0xff03, 0xf83f, 0xffff, 0xffff, 0x000f, 0xfe00, 0xffff, 0xffff, 0x00ff, 0xffc0, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, }; xrPixmap frown = { 64, /* raster width */ 64, /* raster height */ 1, /* raster depth */ frownRaster /* ptr to the raster */ }; @EOF chmod 644 frown.h echo x - smile.h cat >smile.h <<'@EOF' UINT16 smileRaster[] = { 0xffff, 0x01ff, 0xfe00, 0xffff, 0xffff, 0x003f, 0xe000, 0xffff, 0xffff, 0xfc0f, 0xc1ff, 0xffff, 0xffff, 0xff83, 0x0fff, 0xffff, 0xffff, 0xfff0, 0x3fff, 0xfffc, 0x3fff, 0xfffc, 0xffff, 0xfff8, 0x1fff, 0xffff, 0xffff, 0xfff1, 0xcfff, 0xffff, 0xffff, 0xfff3, 0xe7ff, 0xffff, 0xffff, 0xffe7, 0xf3ff, 0xffff, 0xffff, 0xffcf, 0xf9ff, 0xffff, 0xffff, 0xff8f, 0xfcff, 0xffff, 0xffff, 0xff9f, 0xfc7f, 0xfe1f, 0xf87f, 0xff3f, 0xfe7f, 0xf9e7, 0xe79f, 0xff3f, 0xff3f, 0xf7fb, 0xdfef, 0xfe7f, 0xff3f, 0xeffd, 0xbff7, 0xfe7f, 0xff3f, 0xeffd, 0xbff7, 0xfcff, 0xff9f, 0xdffe, 0x7ffb, 0xfcff, 0xff9f, 0xdffe, 0x7ffb, 0xf9ff, 0xff9f, 0xc1fe, 0x07fb, 0xf9ff, 0xffcf, 0xc0fe, 0x03fb, 0xf9ff, 0xffcf, 0xe07d, 0x81f7, 0xf3ff, 0xffcf, 0xe03d, 0x80f7, 0xf3ff, 0xffcf, 0xf03b, 0xc0ef, 0xf3ff, 0xffcf, 0xf827, 0xe09f, 0xf3ff, 0xffcf, 0xfe1f, 0xf87f, 0xf3ff, 0xffcf, 0xffff, 0xffff, 0xf3ff, 0xffcf, 0xffff, 0xffff, 0xf3ff, 0xffcf, 0xffff, 0xffff, 0xf3ff, 0xffcf, 0xffff, 0xffff, 0xf3ff, 0xffcf, 0xffff, 0xffff, 0xf3ff, 0xefcf, 0xffff, 0xffff, 0xf3f7, 0xefcf, 0xffff, 0xffff, 0xf3f7, 0xcfcf, 0xffff, 0xffff, 0xf3f3, 0x9fcf, 0xffff, 0xffff, 0xf3f9, 0x7fcf, 0xffff, 0xffff, 0xfbfe, 0x7fdf, 0xffff, 0x7fff, 0xfbfe, 0xff9f, 0xfffc, 0x9fff, 0xf9ff, 0xff9f, 0xfffb, 0xcfff, 0xf9ff, 0xff3f, 0xffe7, 0xf3ff, 0xfcff, 0xff3f, 0xff1f, 0xf87f, 0xfcff, 0xff3f, 0x00ff, 0xff00, 0xfeff, 0xfe7f, 0xffff, 0xffff, 0xfe7f, 0xfe7f, 0xffff, 0xffff, 0xff3f, 0xfcff, 0xffff, 0xffff, 0xff3f, 0xf8ff, 0xffff, 0xffff, 0xff9f, 0xf9ff, 0xffff, 0xffff, 0xffcf, 0xf3ff, 0xffff, 0xffff, 0xffc7, 0xe7ff, 0xffff, 0xffff, 0xffe7, 0xcfff, 0xffff, 0xffff, 0xfff3, 0x8fff, 0xffff, 0xffff, 0xfff9, 0x1fff, 0xffff, 0xffff, 0xfffc, 0x3fff, 0xfffe, 0x3fff, 0xfffe, 0x7fff, 0xfffc, 0x1fff, 0xffff, 0xffff, 0xfff0, 0xc3ff, 0xffff, 0xffff, 0xffe1, 0xe0ff, 0xffff, 0xffff, 0xff03, 0xf83f, 0xffff, 0xffff, 0x000f, 0xfe00, 0xffff, 0xffff, 0x00ff, 0xffc0, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, }; xrPixmap smile = { 64, /* raster width */ 64, /* raster height */ 1, /* raster depth */ smileRaster /* ptr to the raster */ }; @EOF chmod 644 smile.h exit 0