4 * This file contains the Xlib emulation functions pertaining to
5 * creating and destroying pixmaps.
7 * Copyright (c) 1995 Sun Microsystems, Inc.
9 * See the file "license.terms" for information on usage and redistribution
10 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
19 *----------------------------------------------------------------------
23 * Creates an in memory drawing surface.
26 * Returns a handle to a new pixmap.
29 * Allocates a new Win32 bitmap.
31 *----------------------------------------------------------------------
35 Tk_GetPixmap(display, d, width, height, depth)
42 TkWinDrawable *newTwdPtr, *twdPtr;
48 newTwdPtr = (TkWinDrawable*) ckalloc(sizeof(TkWinDrawable));
49 newTwdPtr->type = TWD_BITMAP;
50 newTwdPtr->bitmap.depth = depth;
51 twdPtr = (TkWinDrawable *)d;
52 if (twdPtr->type != TWD_BITMAP) {
53 if (twdPtr->window.winPtr == NULL) {
54 newTwdPtr->bitmap.colormap = DefaultColormap(display,
55 DefaultScreen(display));
57 newTwdPtr->bitmap.colormap = twdPtr->window.winPtr->atts.colormap;
60 newTwdPtr->bitmap.colormap = twdPtr->bitmap.colormap;
62 screen = &display->screens[0];
64 if (depth == screen->root_depth) {
65 planes = (int) screen->ext_data;
68 newTwdPtr->bitmap.handle = CreateBitmap(width, height, planes, depth, NULL);
70 if (newTwdPtr->bitmap.handle == NULL) {
71 ckfree((char *) newTwdPtr);
75 return (Pixmap)newTwdPtr;
79 *----------------------------------------------------------------------
83 * Release the resources associated with a pixmap.
89 * Deletes the bitmap created by Tk_GetPixmap.
91 *----------------------------------------------------------------------
95 Tk_FreePixmap(display, pixmap)
99 TkWinDrawable *twdPtr = (TkWinDrawable *) pixmap;
102 if (twdPtr != NULL) {
103 DeleteObject(twdPtr->bitmap.handle);
104 ckfree((char *)twdPtr);
109 *----------------------------------------------------------------------
111 * TkSetPixmapColormap --
113 * The following function is a hack used by the photo widget to
114 * explicitly set the colormap slot of a Pixmap.
122 *----------------------------------------------------------------------
126 TkSetPixmapColormap(pixmap, colormap)
130 TkWinDrawable *twdPtr = (TkWinDrawable *)pixmap;
131 twdPtr->bitmap.colormap = colormap;
135 *----------------------------------------------------------------------
139 * Retrieve the geometry of the given drawable. Note that
140 * this is a degenerate implementation that only returns the
149 *----------------------------------------------------------------------
153 XGetGeometry(display, d, root_return, x_return, y_return, width_return,
154 height_return, border_width_return, depth_return)
160 unsigned int* width_return;
161 unsigned int* height_return;
162 unsigned int* border_width_return;
163 unsigned int* depth_return;
165 TkWinDrawable *twdPtr = (TkWinDrawable *)d;
169 if ((twdPtr->type != TWD_BITMAP) || (twdPtr->bitmap.handle == NULL)) {
170 panic("XGetGeometry: invalid pixmap");
173 info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
174 info.bmiHeader.biBitCount = 0;
175 if (!GetDIBits(dc, twdPtr->bitmap.handle, 0, 0, NULL, &info,
177 panic("XGetGeometry: unable to get bitmap size");
181 *width_return = info.bmiHeader.biWidth;
182 *height_return = info.bmiHeader.biHeight;