| 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 |
|
| 15 |
#include "tkWinInt.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 Win32 bitmap. |
| 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 |
TkWinDrawable *newTwdPtr, *twdPtr; |
| 43 |
int planes; |
| 44 |
Screen *screen; |
| 45 |
|
| 46 |
display->request++; |
| 47 |
|
| 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)); |
| 56 |
} else { |
| 57 |
newTwdPtr->bitmap.colormap = twdPtr->window.winPtr->atts.colormap; |
| 58 |
} |
| 59 |
} else { |
| 60 |
newTwdPtr->bitmap.colormap = twdPtr->bitmap.colormap; |
| 61 |
} |
| 62 |
screen = &display->screens[0]; |
| 63 |
planes = 1; |
| 64 |
if (depth == screen->root_depth) { |
| 65 |
planes = (int) screen->ext_data; |
| 66 |
depth /= planes; |
| 67 |
} |
| 68 |
newTwdPtr->bitmap.handle = CreateBitmap(width, height, planes, depth, NULL); |
| 69 |
|
| 70 |
if (newTwdPtr->bitmap.handle == NULL) { |
| 71 |
ckfree((char *) newTwdPtr); |
| 72 |
return None; |
| 73 |
} |
| 74 |
|
| 75 |
return (Pixmap)newTwdPtr; |
| 76 |
} |
| 77 |
|
| 78 |
/* |
| 79 |
*---------------------------------------------------------------------- |
| 80 |
* |
| 81 |
* Tk_FreePixmap -- |
| 82 |
* |
| 83 |
* Release the resources associated with a pixmap. |
| 84 |
* |
| 85 |
* Results: |
| 86 |
* None. |
| 87 |
* |
| 88 |
* Side effects: |
| 89 |
* Deletes the bitmap created by Tk_GetPixmap. |
| 90 |
* |
| 91 |
*---------------------------------------------------------------------- |
| 92 |
*/ |
| 93 |
|
| 94 |
void |
| 95 |
Tk_FreePixmap(display, pixmap) |
| 96 |
Display* display; |
| 97 |
Pixmap pixmap; |
| 98 |
{ |
| 99 |
TkWinDrawable *twdPtr = (TkWinDrawable *) pixmap; |
| 100 |
|
| 101 |
display->request++; |
| 102 |
if (twdPtr != NULL) { |
| 103 |
DeleteObject(twdPtr->bitmap.handle); |
| 104 |
ckfree((char *)twdPtr); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
/* |
| 109 |
*---------------------------------------------------------------------- |
| 110 |
* |
| 111 |
* TkSetPixmapColormap -- |
| 112 |
* |
| 113 |
* The following function is a hack used by the photo widget to |
| 114 |
* explicitly set the colormap slot of a Pixmap. |
| 115 |
* |
| 116 |
* Results: |
| 117 |
* None. |
| 118 |
* |
| 119 |
* Side effects: |
| 120 |
* None. |
| 121 |
* |
| 122 |
*---------------------------------------------------------------------- |
| 123 |
*/ |
| 124 |
|
| 125 |
void |
| 126 |
TkSetPixmapColormap(pixmap, colormap) |
| 127 |
Pixmap pixmap; |
| 128 |
Colormap colormap; |
| 129 |
{ |
| 130 |
TkWinDrawable *twdPtr = (TkWinDrawable *)pixmap; |
| 131 |
twdPtr->bitmap.colormap = colormap; |
| 132 |
} |
| 133 |
|
| 134 |
/* |
| 135 |
*---------------------------------------------------------------------- |
| 136 |
* |
| 137 |
* XGetGeometry -- |
| 138 |
* |
| 139 |
* Retrieve the geometry of the given drawable. Note that |
| 140 |
* this is a degenerate implementation that only returns the |
| 141 |
* size of a pixmap or window. |
| 142 |
* |
| 143 |
* Results: |
| 144 |
* Returns 0. |
| 145 |
* |
| 146 |
* Side effects: |
| 147 |
* None. |
| 148 |
* |
| 149 |
*---------------------------------------------------------------------- |
| 150 |
*/ |
| 151 |
|
| 152 |
int |
| 153 |
XGetGeometry(display, d, root_return, x_return, y_return, width_return, |
| 154 |
height_return, border_width_return, depth_return) |
| 155 |
Display* display; |
| 156 |
Drawable d; |
| 157 |
Window* root_return; |
| 158 |
int* x_return; |
| 159 |
int* y_return; |
| 160 |
unsigned int* width_return; |
| 161 |
unsigned int* height_return; |
| 162 |
unsigned int* border_width_return; |
| 163 |
unsigned int* depth_return; |
| 164 |
{ |
| 165 |
TkWinDrawable *twdPtr = (TkWinDrawable *)d; |
| 166 |
|
| 167 |
if (twdPtr->type == TWD_BITMAP) { |
| 168 |
HDC dc; |
| 169 |
BITMAPINFO info; |
| 170 |
|
| 171 |
if (twdPtr->bitmap.handle == NULL) { |
| 172 |
panic("XGetGeometry: invalid pixmap"); |
| 173 |
} |
| 174 |
dc = GetDC(NULL); |
| 175 |
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
| 176 |
info.bmiHeader.biBitCount = 0; |
| 177 |
if (!GetDIBits(dc, twdPtr->bitmap.handle, 0, 0, NULL, &info, |
| 178 |
DIB_RGB_COLORS)) { |
| 179 |
panic("XGetGeometry: unable to get bitmap size"); |
| 180 |
} |
| 181 |
ReleaseDC(NULL, dc); |
| 182 |
|
| 183 |
*width_return = info.bmiHeader.biWidth; |
| 184 |
*height_return = info.bmiHeader.biHeight; |
| 185 |
} else if (twdPtr->type == TWD_WINDOW) { |
| 186 |
RECT rect; |
| 187 |
|
| 188 |
if (twdPtr->window.handle == NULL) { |
| 189 |
panic("XGetGeometry: invalid window"); |
| 190 |
} |
| 191 |
GetClientRect(twdPtr->window.handle, &rect); |
| 192 |
*width_return = rect.right - rect.left; |
| 193 |
*height_return = rect.bottom - rect.top; |
| 194 |
} else { |
| 195 |
panic("XGetGeometry: invalid window"); |
| 196 |
} |
| 197 |
return 1; |
| 198 |
} |