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

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

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

projs/trunk/shared_source/tk_base/tkwincursor.c revision 42 by dashley, Fri Oct 14 01:50:00 2016 UTC projs/dtats/trunk/shared_source/c_tk_base_7_5_w_mods/tkwincursor.c revision 98 by dashley, Sun Dec 18 00:57:31 2016 UTC
# Line 1  Line 1 
 /* $Header: /cvsroot/esrg/sfesrg/esrgpcpj/shared/tk_base/tkwincursor.c,v 1.1.1.1 2001/06/13 05:12:07 dtashley Exp $ */  
   
 /*  
  * tkWinCursor.c --  
  *  
  *      This file contains Win32 specific cursor related routines.  
  *  
  * 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: tkwincursor.c,v 1.1.1.1 2001/06/13 05:12:07 dtashley Exp $  
  */  
   
 #include "tkWinInt.h"  
   
 /*  
  * The following data structure contains the system specific data  
  * necessary to control Windows cursors.  
  */  
   
 typedef struct {  
     TkCursor info;              /* Generic cursor info used by tkCursor.c */  
     HCURSOR winCursor;          /* Win32 cursor handle. */  
     int system;                 /* 1 if cursor is a system cursor, else 0. */  
 } TkWinCursor;  
   
 /*  
  * The table below is used to map from the name of a predefined cursor  
  * to its resource identifier.  
  */  
   
 static struct CursorName {  
     char *name;  
     LPCTSTR id;  
 } cursorNames[] = {  
     {"starting",                IDC_APPSTARTING},  
     {"arrow",                   IDC_ARROW},  
     {"ibeam",                   IDC_IBEAM},  
     {"icon",                    IDC_ICON},  
     {"no",                      IDC_NO},  
     {"size",                    IDC_SIZE},  
     {"size_ne_sw",              IDC_SIZENESW},  
     {"size_ns",                 IDC_SIZENS},  
     {"size_nw_se",              IDC_SIZENWSE},  
     {"size_we",                 IDC_SIZEWE},  
     {"uparrow",                 IDC_UPARROW},  
     {"wait",                    IDC_WAIT},  
     {"crosshair",               IDC_CROSS},  
     {"fleur",                   IDC_SIZE},  
     {"sb_v_double_arrow",       IDC_SIZENS},  
     {"sb_h_double_arrow",       IDC_SIZEWE},  
     {"center_ptr",              IDC_UPARROW},  
     {"watch",                   IDC_WAIT},  
     {"xterm",                   IDC_IBEAM},  
     {NULL,                      0}  
 };  
   
 /*  
  * The default cursor is used whenever no other cursor has been specified.  
  */  
   
 #define TK_DEFAULT_CURSOR       IDC_ARROW  
   
   
 /*  
  *----------------------------------------------------------------------  
  *  
  * TkGetCursorByName --  
  *  
  *      Retrieve a system cursor by name.    
  *  
  * Results:  
  *      Returns a new cursor, or NULL on errors.    
  *  
  * Side effects:  
  *      Allocates a new cursor.  
  *  
  *----------------------------------------------------------------------  
  */  
   
 TkCursor *  
 TkGetCursorByName(interp, tkwin, string)  
     Tcl_Interp *interp;         /* Interpreter to use for error reporting. */  
     Tk_Window tkwin;            /* Window in which cursor will be used. */  
     Tk_Uid string;              /* Description of cursor.  See manual entry  
                                  * for details on legal syntax. */  
 {  
     struct CursorName *namePtr;  
     TkWinCursor *cursorPtr;  
   
     /*  
      * Check for the cursor in the system cursor set.  
      */  
   
     for (namePtr = cursorNames; namePtr->name != NULL; namePtr++) {  
         if (strcmp(namePtr->name, string) == 0) {  
             break;  
         }  
     }  
   
     cursorPtr = (TkWinCursor *) ckalloc(sizeof(TkWinCursor));  
     cursorPtr->info.cursor = (Tk_Cursor) cursorPtr;  
     cursorPtr->winCursor = NULL;  
     if (namePtr->name != NULL) {  
         cursorPtr->winCursor = LoadCursor(NULL, namePtr->id);  
         cursorPtr->system = 1;  
     }  
     if (cursorPtr->winCursor == NULL) {  
         cursorPtr->winCursor = LoadCursor(Tk_GetHINSTANCE(), string);  
         cursorPtr->system = 0;  
     }  
     if (string[0] == '@') {  
         int argc;  
         char **argv = NULL;  
         if (Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) {  
             return NULL;  
         }  
         /*  
          * Check for system cursor of type @<filename>, where only  
          * the name is allowed.  This accepts either:  
          *      -cursor @/winnt/cursors/globe.ani  
          *      -cursor @C:/Winnt/cursors/E_arrow.cur  
          *      -cursor {@C:/Program\ Files/Cursors/bart.ani}  
          */  
         if ((argc != 1) || (argv[0][0] != '@')) {  
             ckfree((char *) argv);  
             goto badCursorSpec;  
         }  
         if (Tcl_IsSafe(interp)) {  
             Tcl_AppendResult(interp, "can't get cursor from a file in",  
                     " a safe interpreter", (char *) NULL);  
             ckfree((char *) argv);  
             ckfree((char *)cursorPtr);  
             return NULL;  
         }  
         cursorPtr->winCursor = LoadCursorFromFile(&(argv[0][1]));  
         cursorPtr->system = 0;  
         ckfree((char *) argv);  
     }  
     if (cursorPtr->winCursor == NULL) {  
         badCursorSpec:  
         ckfree((char *)cursorPtr);  
         Tcl_AppendResult(interp, "bad cursor spec \"", string, "\"",  
                 (char *) NULL);  
         return NULL;  
     } else {  
         return (TkCursor *) cursorPtr;  
     }  
 }  
   
 /*  
  *----------------------------------------------------------------------  
  *  
  * TkCreateCursorFromData --  
  *  
  *      Creates a cursor from the source and mask bits.  
  *  
  * Results:  
  *      Returns a new cursor, or NULL on errors.  
  *  
  * Side effects:  
  *      Allocates a new cursor.  
  *  
  *----------------------------------------------------------------------  
  */  
   
 TkCursor *  
 TkCreateCursorFromData(tkwin, source, mask, width, height, xHot, yHot,  
         fgColor, bgColor)  
     Tk_Window tkwin;            /* Window in which cursor will be used. */  
     char *source;               /* Bitmap data for cursor shape. */  
     char *mask;                 /* Bitmap data for cursor mask. */  
     int width, height;          /* Dimensions of cursor. */  
     int xHot, yHot;             /* Location of hot-spot in cursor. */  
     XColor fgColor;             /* Foreground color for cursor. */  
     XColor bgColor;             /* Background color for cursor. */  
 {  
     return NULL;  
 }  
   
 /*  
  *----------------------------------------------------------------------  
  *  
  * TkpFreeCursor --  
  *  
  *      This procedure is called to release a cursor allocated by  
  *      TkGetCursorByName.  
  *  
  * Results:  
  *      None.  
  *  
  * Side effects:  
  *      The cursor data structure is deallocated.  
  *  
  *----------------------------------------------------------------------  
  */  
   
 void  
 TkpFreeCursor(cursorPtr)  
     TkCursor *cursorPtr;  
 {  
     TkWinCursor *winCursorPtr = (TkWinCursor *) cursorPtr;  
 }  
   
 /*  
  *----------------------------------------------------------------------  
  *  
  * TkpSetCursor --  
  *  
  *      Set the global cursor.  If the cursor is None, then use the  
  *      default Tk cursor.  
  *  
  * Results:  
  *      None.  
  *  
  * Side effects:  
  *      Changes the mouse cursor.  
  *  
  *----------------------------------------------------------------------  
  */  
   
 void  
 TkpSetCursor(cursor)  
     TkpCursor cursor;  
 {  
     HCURSOR hcursor;  
     TkWinCursor *winCursor = (TkWinCursor *) cursor;  
   
     if (winCursor == NULL || winCursor->winCursor == NULL) {  
         hcursor = LoadCursor(NULL, TK_DEFAULT_CURSOR);  
     } else {  
         hcursor = winCursor->winCursor;  
     }  
   
     if (hcursor != NULL) {  
         SetCursor(hcursor);  
     }  
 }  
   
   
 /* $History: tkWinCursor.c $  
  *  
  * *****************  Version 1  *****************  
  * User: Dtashley     Date: 1/02/01    Time: 3:09a  
  * Created in $/IjuScripter, IjuConsole/Source/Tk Base  
  * Initial check-in.  
  */  
   
 /* End of TKWINCURSOR.C */  
1    /* $Header$ */
2    
3    /*
4     * tkWinCursor.c --
5     *
6     *      This file contains Win32 specific cursor related routines.
7     *
8     * Copyright (c) 1995 Sun Microsystems, Inc.
9     *
10     * See the file "license.terms" for information on usage and redistribution
11     * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12     *
13     * RCS: @(#) $Id: tkwincursor.c,v 1.1.1.1 2001/06/13 05:12:07 dtashley Exp $
14     */
15    
16    #include "tkWinInt.h"
17    
18    /*
19     * The following data structure contains the system specific data
20     * necessary to control Windows cursors.
21     */
22    
23    typedef struct {
24        TkCursor info;              /* Generic cursor info used by tkCursor.c */
25        HCURSOR winCursor;          /* Win32 cursor handle. */
26        int system;                 /* 1 if cursor is a system cursor, else 0. */
27    } TkWinCursor;
28    
29    /*
30     * The table below is used to map from the name of a predefined cursor
31     * to its resource identifier.
32     */
33    
34    static struct CursorName {
35        char *name;
36        LPCTSTR id;
37    } cursorNames[] = {
38        {"starting",                IDC_APPSTARTING},
39        {"arrow",                   IDC_ARROW},
40        {"ibeam",                   IDC_IBEAM},
41        {"icon",                    IDC_ICON},
42        {"no",                      IDC_NO},
43        {"size",                    IDC_SIZE},
44        {"size_ne_sw",              IDC_SIZENESW},
45        {"size_ns",                 IDC_SIZENS},
46        {"size_nw_se",              IDC_SIZENWSE},
47        {"size_we",                 IDC_SIZEWE},
48        {"uparrow",                 IDC_UPARROW},
49        {"wait",                    IDC_WAIT},
50        {"crosshair",               IDC_CROSS},
51        {"fleur",                   IDC_SIZE},
52        {"sb_v_double_arrow",       IDC_SIZENS},
53        {"sb_h_double_arrow",       IDC_SIZEWE},
54        {"center_ptr",              IDC_UPARROW},
55        {"watch",                   IDC_WAIT},
56        {"xterm",                   IDC_IBEAM},
57        {NULL,                      0}
58    };
59    
60    /*
61     * The default cursor is used whenever no other cursor has been specified.
62     */
63    
64    #define TK_DEFAULT_CURSOR       IDC_ARROW
65    
66    
67    /*
68     *----------------------------------------------------------------------
69     *
70     * TkGetCursorByName --
71     *
72     *      Retrieve a system cursor by name.  
73     *
74     * Results:
75     *      Returns a new cursor, or NULL on errors.  
76     *
77     * Side effects:
78     *      Allocates a new cursor.
79     *
80     *----------------------------------------------------------------------
81     */
82    
83    TkCursor *
84    TkGetCursorByName(interp, tkwin, string)
85        Tcl_Interp *interp;         /* Interpreter to use for error reporting. */
86        Tk_Window tkwin;            /* Window in which cursor will be used. */
87        Tk_Uid string;              /* Description of cursor.  See manual entry
88                                     * for details on legal syntax. */
89    {
90        struct CursorName *namePtr;
91        TkWinCursor *cursorPtr;
92    
93        /*
94         * Check for the cursor in the system cursor set.
95         */
96    
97        for (namePtr = cursorNames; namePtr->name != NULL; namePtr++) {
98            if (strcmp(namePtr->name, string) == 0) {
99                break;
100            }
101        }
102    
103        cursorPtr = (TkWinCursor *) ckalloc(sizeof(TkWinCursor));
104        cursorPtr->info.cursor = (Tk_Cursor) cursorPtr;
105        cursorPtr->winCursor = NULL;
106        if (namePtr->name != NULL) {
107            cursorPtr->winCursor = LoadCursor(NULL, namePtr->id);
108            cursorPtr->system = 1;
109        }
110        if (cursorPtr->winCursor == NULL) {
111            cursorPtr->winCursor = LoadCursor(Tk_GetHINSTANCE(), string);
112            cursorPtr->system = 0;
113        }
114        if (string[0] == '@') {
115            int argc;
116            char **argv = NULL;
117            if (Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) {
118                return NULL;
119            }
120            /*
121             * Check for system cursor of type @<filename>, where only
122             * the name is allowed.  This accepts either:
123             *      -cursor @/winnt/cursors/globe.ani
124             *      -cursor @C:/Winnt/cursors/E_arrow.cur
125             *      -cursor {@C:/Program\ Files/Cursors/bart.ani}
126             */
127            if ((argc != 1) || (argv[0][0] != '@')) {
128                ckfree((char *) argv);
129                goto badCursorSpec;
130            }
131            if (Tcl_IsSafe(interp)) {
132                Tcl_AppendResult(interp, "can't get cursor from a file in",
133                        " a safe interpreter", (char *) NULL);
134                ckfree((char *) argv);
135                ckfree((char *)cursorPtr);
136                return NULL;
137            }
138            cursorPtr->winCursor = LoadCursorFromFile(&(argv[0][1]));
139            cursorPtr->system = 0;
140            ckfree((char *) argv);
141        }
142        if (cursorPtr->winCursor == NULL) {
143            badCursorSpec:
144            ckfree((char *)cursorPtr);
145            Tcl_AppendResult(interp, "bad cursor spec \"", string, "\"",
146                    (char *) NULL);
147            return NULL;
148        } else {
149            return (TkCursor *) cursorPtr;
150        }
151    }
152    
153    /*
154     *----------------------------------------------------------------------
155     *
156     * TkCreateCursorFromData --
157     *
158     *      Creates a cursor from the source and mask bits.
159     *
160     * Results:
161     *      Returns a new cursor, or NULL on errors.
162     *
163     * Side effects:
164     *      Allocates a new cursor.
165     *
166     *----------------------------------------------------------------------
167     */
168    
169    TkCursor *
170    TkCreateCursorFromData(tkwin, source, mask, width, height, xHot, yHot,
171            fgColor, bgColor)
172        Tk_Window tkwin;            /* Window in which cursor will be used. */
173        char *source;               /* Bitmap data for cursor shape. */
174        char *mask;                 /* Bitmap data for cursor mask. */
175        int width, height;          /* Dimensions of cursor. */
176        int xHot, yHot;             /* Location of hot-spot in cursor. */
177        XColor fgColor;             /* Foreground color for cursor. */
178        XColor bgColor;             /* Background color for cursor. */
179    {
180        return NULL;
181    }
182    
183    /*
184     *----------------------------------------------------------------------
185     *
186     * TkpFreeCursor --
187     *
188     *      This procedure is called to release a cursor allocated by
189     *      TkGetCursorByName.
190     *
191     * Results:
192     *      None.
193     *
194     * Side effects:
195     *      The cursor data structure is deallocated.
196     *
197     *----------------------------------------------------------------------
198     */
199    
200    void
201    TkpFreeCursor(cursorPtr)
202        TkCursor *cursorPtr;
203    {
204        TkWinCursor *winCursorPtr = (TkWinCursor *) cursorPtr;
205    }
206    
207    /*
208     *----------------------------------------------------------------------
209     *
210     * TkpSetCursor --
211     *
212     *      Set the global cursor.  If the cursor is None, then use the
213     *      default Tk cursor.
214     *
215     * Results:
216     *      None.
217     *
218     * Side effects:
219     *      Changes the mouse cursor.
220     *
221     *----------------------------------------------------------------------
222     */
223    
224    void
225    TkpSetCursor(cursor)
226        TkpCursor cursor;
227    {
228        HCURSOR hcursor;
229        TkWinCursor *winCursor = (TkWinCursor *) cursor;
230    
231        if (winCursor == NULL || winCursor->winCursor == NULL) {
232            hcursor = LoadCursor(NULL, TK_DEFAULT_CURSOR);
233        } else {
234            hcursor = winCursor->winCursor;
235        }
236    
237        if (hcursor != NULL) {
238            SetCursor(hcursor);
239        }
240    }
241    
242    /* End of tkwincursor.c */

Legend:
Removed from v.42  
changed lines
  Added in v.98

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25