tkWinPixmap.c
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:5k
源码类别:

通讯编程

开发平台:

Visual C++

  1. /* 
  2.  * tkWinPixmap.c --
  3.  *
  4.  * This file contains the Xlib emulation functions pertaining to
  5.  * creating and destroying pixmaps.
  6.  *
  7.  * Copyright (c) 1995 Sun Microsystems, Inc.
  8.  *
  9.  * See the file "license.terms" for information on usage and redistribution
  10.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11.  *
  12.  * RCS: @(#) $Id: tkWinPixmap.c,v 1.3 2000/02/01 11:41:44 hobbs Exp $
  13.  */
  14. #include "tkWinInt.h"
  15. /*
  16.  *----------------------------------------------------------------------
  17.  *
  18.  * Tk_GetPixmap --
  19.  *
  20.  * Creates an in memory drawing surface.
  21.  *
  22.  * Results:
  23.  * Returns a handle to a new pixmap.
  24.  *
  25.  * Side effects:
  26.  * Allocates a new Win32 bitmap.
  27.  *
  28.  *----------------------------------------------------------------------
  29.  */
  30. Pixmap
  31. Tk_GetPixmap(display, d, width, height, depth)
  32.     Display* display;
  33.     Drawable d;
  34.     int width;
  35.     int height;
  36.     int depth;
  37. {
  38.     TkWinDrawable *newTwdPtr, *twdPtr;
  39.     int planes;
  40.     Screen *screen;
  41.     
  42.     display->request++;
  43.     newTwdPtr = (TkWinDrawable*) ckalloc(sizeof(TkWinDrawable));
  44.     newTwdPtr->type = TWD_BITMAP;
  45.     newTwdPtr->bitmap.depth = depth;
  46.     twdPtr = (TkWinDrawable *)d;
  47.     if (twdPtr->type != TWD_BITMAP) {
  48. if (twdPtr->window.winPtr == NULL) {
  49.     newTwdPtr->bitmap.colormap = DefaultColormap(display,
  50.     DefaultScreen(display));
  51. } else {
  52.     newTwdPtr->bitmap.colormap = twdPtr->window.winPtr->atts.colormap;
  53. }
  54.     } else {
  55. newTwdPtr->bitmap.colormap = twdPtr->bitmap.colormap;
  56.     }
  57.     screen = &display->screens[0];
  58.     planes = 1;
  59.     if (depth == screen->root_depth) {
  60. planes = (int) screen->ext_data;
  61. depth /= planes;
  62.     }
  63.     newTwdPtr->bitmap.handle = CreateBitmap(width, height, planes, depth, NULL);
  64.     if (newTwdPtr->bitmap.handle == NULL) {
  65. ckfree((char *) newTwdPtr);
  66. return None;
  67.     }
  68.     
  69.     return (Pixmap)newTwdPtr;
  70. }
  71. /*
  72.  *----------------------------------------------------------------------
  73.  *
  74.  * Tk_FreePixmap --
  75.  *
  76.  * Release the resources associated with a pixmap.
  77.  *
  78.  * Results:
  79.  * None.
  80.  *
  81.  * Side effects:
  82.  * Deletes the bitmap created by Tk_GetPixmap.
  83.  *
  84.  *----------------------------------------------------------------------
  85.  */
  86. void
  87. Tk_FreePixmap(display, pixmap)
  88.     Display* display;
  89.     Pixmap pixmap;
  90. {
  91.     TkWinDrawable *twdPtr = (TkWinDrawable *) pixmap;
  92.     display->request++;
  93.     if (twdPtr != NULL) {
  94. DeleteObject(twdPtr->bitmap.handle);
  95. ckfree((char *)twdPtr);
  96.     }
  97. }
  98. /*
  99.  *----------------------------------------------------------------------
  100.  *
  101.  * TkSetPixmapColormap --
  102.  *
  103.  * The following function is a hack used by the photo widget to
  104.  * explicitly set the colormap slot of a Pixmap.
  105.  *
  106.  * Results:
  107.  * None.
  108.  *
  109.  * Side effects:
  110.  * None.
  111.  *
  112.  *----------------------------------------------------------------------
  113.  */
  114. void
  115. TkSetPixmapColormap(pixmap, colormap)
  116.     Pixmap pixmap;
  117.     Colormap colormap;
  118. {
  119.     TkWinDrawable *twdPtr = (TkWinDrawable *)pixmap;
  120.     twdPtr->bitmap.colormap = colormap;
  121. }
  122. /*
  123.  *----------------------------------------------------------------------
  124.  *
  125.  * XGetGeometry --
  126.  *
  127.  * Retrieve the geometry of the given drawable.  Note that
  128.  * this is a degenerate implementation that only returns the
  129.  * size of a pixmap or window.
  130.  *
  131.  * Results:
  132.  * Returns 0.
  133.  *
  134.  * Side effects:
  135.  * None.
  136.  *
  137.  *----------------------------------------------------------------------
  138.  */
  139. int
  140. XGetGeometry(display, d, root_return, x_return, y_return, width_return,
  141. height_return, border_width_return, depth_return)
  142.     Display* display;
  143.     Drawable d;
  144.     Window* root_return;
  145.     int* x_return;
  146.     int* y_return;
  147.     unsigned int* width_return;
  148.     unsigned int* height_return;
  149.     unsigned int* border_width_return;
  150.     unsigned int* depth_return;
  151. {
  152.     TkWinDrawable *twdPtr = (TkWinDrawable *)d;
  153.     if (twdPtr->type == TWD_BITMAP) {
  154. HDC dc;
  155. BITMAPINFO info;
  156. if (twdPtr->bitmap.handle == NULL) {
  157.             panic("XGetGeometry: invalid pixmap");
  158.         }
  159.         dc = GetDC(NULL);
  160.         info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  161.         info.bmiHeader.biBitCount = 0;
  162.         if (!GetDIBits(dc, twdPtr->bitmap.handle, 0, 0, NULL, &info,
  163.                 DIB_RGB_COLORS)) {
  164.             panic("XGetGeometry: unable to get bitmap size");
  165.         }
  166.         ReleaseDC(NULL, dc);
  167.         *width_return = info.bmiHeader.biWidth;
  168.         *height_return = info.bmiHeader.biHeight;
  169.     } else if (twdPtr->type == TWD_WINDOW) {
  170. RECT rect;
  171.         if (twdPtr->window.handle == NULL) {
  172.             panic("XGetGeometry: invalid window");
  173.         }
  174.         GetClientRect(twdPtr->window.handle, &rect);
  175.         *width_return = rect.right - rect.left;
  176.         *height_return = rect.bottom - rect.top;
  177.     } else {
  178.         panic("XGetGeometry: invalid window");
  179.     }
  180.     return 1;
  181. }