/[dtapublic]/projs/ets/trunk/src/c_tk_base_7_5_w_mods/tkwinpixmap.c
ViewVC logotype

Diff of /projs/ets/trunk/src/c_tk_base_7_5_w_mods/tkwinpixmap.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.69  
changed lines
  Added in v.71

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25