home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tk42r2s.zip / tk4.2 / os2 / tkOS2Pixmap.c < prev    next >
C/C++ Source or Header  |  1999-07-26  |  5KB  |  174 lines

  1. /* 
  2.  * tkOS2Pixmap.c --
  3.  *
  4.  *    This file contains the Xlib emulation functions pertaining to
  5.  *    creating and destroying pixmaps.
  6.  *
  7.  * Copyright (c) 1996-1998 Illya Vaes
  8.  * Copyright (c) 1995 Sun Microsystems, Inc.
  9.  *
  10.  * See the file "license.terms" for information on usage and redistribution
  11.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12.  */
  13.  
  14.  
  15. #include "tkOS2Int.h"
  16.  
  17.  
  18. /*
  19.  *----------------------------------------------------------------------
  20.  *
  21.  * Tk_GetPixmap --
  22.  *
  23.  *    Creates an in memory drawing surface.
  24.  *
  25.  * Results:
  26.  *    Returns a handle to a new pixmap.
  27.  *
  28.  * Side effects:
  29.  *    Allocates a new OS/2 bitmap, hps, DC.
  30.  *
  31.  *----------------------------------------------------------------------
  32.  */
  33.  
  34. Pixmap
  35. Tk_GetPixmap(display, d, width, height, depth)
  36.     Display* display;
  37.     Drawable d;
  38.     int width;
  39.     int height;
  40.     int depth;
  41. {
  42.     TkOS2Drawable *newTodPtr, *todPtr;
  43.     BITMAPINFOHEADER2 bmpInfo;
  44.     LONG rc;
  45.     DEVOPENSTRUC dop = {0L, (PSZ)"DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
  46.     SIZEL sizl = {0,0}; /* use same page size as device */
  47.     sizl.cx = width; sizl.cy = height;
  48.     
  49.     display->request++;
  50.  
  51.     newTodPtr = (TkOS2Drawable*) ckalloc(sizeof(TkOS2Drawable));
  52.     if (newTodPtr == NULL) {
  53.     return (Pixmap)None;
  54.     }
  55.  
  56.     newTodPtr->type = TOD_BITMAP;
  57.     newTodPtr->bitmap.depth = depth;
  58.     todPtr = (TkOS2Drawable *)d;
  59.     if (todPtr->type != TOD_BITMAP) {
  60.         newTodPtr->bitmap.parent = todPtr->window.handle;
  61.         if (todPtr->window.winPtr == NULL) {
  62.             newTodPtr->bitmap.colormap = DefaultColormap(display,
  63.                     DefaultScreen(display));
  64.         } else {
  65.             newTodPtr->bitmap.colormap = todPtr->window.winPtr->atts.colormap;
  66.         }
  67.     } else {
  68.         newTodPtr->bitmap.colormap = todPtr->bitmap.colormap;
  69.         newTodPtr->bitmap.parent = todPtr->bitmap.parent;
  70.     }
  71.     bmpInfo.cbFix = 16L;
  72.     bmpInfo.cx = width;
  73.     bmpInfo.cy = height;
  74.     bmpInfo.cPlanes = 1;
  75.     bmpInfo.cBitCount = depth;
  76.     newTodPtr->bitmap.dc = DevOpenDC(hab, OD_MEMORY, (PSZ)"*", 5L,
  77.                                      (PDEVOPENDATA)&dop, NULLHANDLE);
  78.     if (newTodPtr->bitmap.dc == DEV_ERROR) {
  79.         ckfree((char *) newTodPtr);
  80.         return (Pixmap)None;
  81.     }
  82.     newTodPtr->bitmap.hps = GpiCreatePS(hab, newTodPtr->bitmap.dc, &sizl,
  83.                                         PU_PELS | GPIT_MICRO | GPIA_ASSOC);
  84.     if (newTodPtr->bitmap.hps == GPI_ERROR) {
  85.         DevCloseDC(newTodPtr->bitmap.dc);
  86.         ckfree((char *) newTodPtr);
  87.         return (Pixmap)None;
  88.     }
  89.     newTodPtr->bitmap.handle = GpiCreateBitmap(newTodPtr->bitmap.hps,
  90.                                                &bmpInfo, 0L, NULL, NULL);
  91.  
  92.     if (newTodPtr->bitmap.handle == NULLHANDLE) {
  93.     ckfree((char *) newTodPtr);
  94.     return (Pixmap)None;
  95.     }
  96.     sizl.cx = width;
  97.     sizl.cy = height;
  98.     rc = GpiSetBitmapDimension(newTodPtr->bitmap.handle, &sizl);
  99.     rc = GpiSetBitmap(newTodPtr->bitmap.hps, newTodPtr->bitmap.handle);
  100.     if (rc == HBM_ERROR) {
  101.         GpiDestroyPS(newTodPtr->bitmap.hps);
  102.         DevCloseDC(newTodPtr->bitmap.dc);
  103.         ckfree((char *) newTodPtr);
  104.         return (Pixmap)None;
  105.     }
  106.  
  107.     return (Pixmap)newTodPtr;
  108. }
  109.  
  110. /*
  111.  *----------------------------------------------------------------------
  112.  *
  113.  * Tk_FreePixmap --
  114.  *
  115.  *    Release the resources associated with a pixmap.
  116.  *
  117.  * Results:
  118.  *    None.
  119.  *
  120.  * Side effects:
  121.  *    Deletes the bitmap created by Tk_FreePixmap.
  122.  *
  123.  *----------------------------------------------------------------------
  124.  */
  125.  
  126. void
  127. Tk_FreePixmap(display, pixmap)
  128.     Display* display;
  129.     Pixmap pixmap;
  130. {
  131.     TkOS2Drawable *todPtr = (TkOS2Drawable *) pixmap;
  132.     HBITMAP hbm;
  133.  
  134.     display->request++;
  135.     if (todPtr != NULL) {
  136.         hbm = GpiSetBitmap(todPtr->bitmap.hps, NULLHANDLE);
  137.     GpiDeleteBitmap(todPtr->bitmap.handle);
  138.         GpiDestroyPS(todPtr->bitmap.hps);
  139.         DevCloseDC(todPtr->bitmap.dc);
  140.     ckfree((char *)todPtr);
  141.     }
  142. }
  143.  
  144. /*
  145.  *----------------------------------------------------------------------
  146.  *
  147.  * TkSetPixmapColormap --
  148.  *
  149.  *      The following function is a hack used by the photo widget to
  150.  *      explicitly set the colormap slot of a Pixmap.
  151.  *
  152.  * Results:
  153.  *      None.
  154.  *
  155.  * Side effects:
  156.  *      None.
  157.  *
  158.  *----------------------------------------------------------------------
  159.  */
  160.  
  161. void
  162. TkSetPixmapColormap(pixmap, colormap)
  163.     Pixmap pixmap;
  164.     Colormap colormap;
  165. {
  166.     TkOS2Drawable *todPtr = (TkOS2Drawable *)pixmap;
  167.  
  168.     todPtr->bitmap.colormap = colormap;
  169.     /*
  170.     rc = (HPAL) TkOS2SelectPalette(todPtr->bitmap.hps, todPtr->bitmap.parent,
  171.                                    colormap);
  172.     */
  173. }
  174.