/[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

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

Legend:
Removed from v.29  
changed lines
  Added in v.220

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25