Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dthelp / dthelpdemo / HourGlass.c
1 /* $XConsortium: HourGlass.c /main/3 1995/11/08 09:18:28 rswiston $ */
2 /************************************<+>*************************************
3  ****************************************************************************
4  **
5  **   File:        HourGlass.c
6  **
7  **   Project:     CDE dthelpdemo sample program.
8  **
9  **   Description: This module contains a simple function for
10  **                creating an hourglass cursor.
11  **
12  **  (c) Copyright 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
13  **      Hewlett-Packard Company
14  **  (c) Copyright 1993, 1994 International Business Machines Corp.
15  **  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
16  **  (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
17  **      Novell, Inc.
18  **
19  **
20  **
21  ****************************************************************************
22  ************************************<+>*************************************/
23
24
25 #include <X11/Xlib.h>
26 #include <X11/Intrinsic.h>
27
28 #define time32_width 32
29 #define time32_height 32
30 #define time32_x_hot 15
31 #define time32_y_hot 15
32 static unsigned char time32_bits[] = {
33    0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
34    0x8c, 0x00, 0x00, 0x31, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
35    0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
36    0x8c, 0x00, 0x00, 0x31, 0x0c, 0x7f, 0xfe, 0x30, 0x0c, 0xfe, 0x7f, 0x30,
37    0x0c, 0xfc, 0x3f, 0x30, 0x0c, 0xf8, 0x1f, 0x30, 0x0c, 0xe0, 0x07, 0x30,
38    0x0c, 0x80, 0x01, 0x30, 0x0c, 0x80, 0x01, 0x30, 0x0c, 0x60, 0x06, 0x30,
39    0x0c, 0x18, 0x18, 0x30, 0x0c, 0x04, 0x20, 0x30, 0x0c, 0x02, 0x40, 0x30,
40    0x0c, 0x01, 0x80, 0x30, 0x8c, 0x00, 0x00, 0x31, 0x4c, 0x80, 0x01, 0x32,
41    0x4c, 0xc0, 0x03, 0x32, 0x4c, 0xf0, 0x1f, 0x32, 0x4c, 0xff, 0xff, 0x32,
42    0xcc, 0xff, 0xff, 0x33, 0x8c, 0xff, 0xff, 0x31, 0xfe, 0xff, 0xff, 0x7f,
43    0xfe, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00};
44
45 #define time32m_width 32
46 #define time32m_height 32
47 static unsigned char time32m_bits[] = {
48    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
49    0xcf, 0x00, 0x00, 0xf3, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
50    0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
51    0xce, 0x00, 0x00, 0x73, 0x8e, 0x7f, 0xfe, 0x71, 0x0e, 0xff, 0xff, 0x70,
52    0x0e, 0xfe, 0x7f, 0x70, 0x0e, 0xfc, 0x3f, 0x70, 0x0e, 0xf8, 0x1f, 0x70,
53    0x0e, 0xe0, 0x07, 0x70, 0x0e, 0xe0, 0x07, 0x70, 0x0e, 0x78, 0x1e, 0x70,
54    0x0e, 0x1c, 0x38, 0x70, 0x0e, 0x06, 0x60, 0x70, 0x0e, 0x03, 0xc0, 0x70,
55    0x8e, 0x01, 0x80, 0x71, 0xce, 0x00, 0x00, 0x73, 0x6e, 0x80, 0x01, 0x76,
56    0x6e, 0xc0, 0x03, 0x76, 0x6e, 0xf0, 0x1f, 0x76, 0x6e, 0xff, 0xff, 0x76,
57    0xee, 0xff, 0xff, 0x77, 0xcf, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff,
58    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
59
60
61 #define time16_x_hot 7
62 #define time16_y_hot 7
63 #define time16_width 16
64 #define time16_height 16
65 static unsigned char time16_bits[] = {
66    0x00, 0x00, 0xfe, 0x7f, 0x14, 0x28, 0x14, 0x28, 0x14, 0x28, 0x24, 0x24,
67    0x44, 0x22, 0x84, 0x21, 0x84, 0x21, 0x44, 0x22, 0x24, 0x24, 0x14, 0x28,
68    0x94, 0x29, 0xd4, 0x2b, 0xfe, 0x7f, 0x00, 0x00};
69
70 #define time16m_width 16
71 #define time16m_height 16
72 static unsigned char time16m_bits[] = {
73    0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
74    0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
75    0xfe, 0x7f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff};
76
77
78 /********    End Public Function Declarations    ********/
79
80 /*************************************<->*************************************
81  *
82  *  Cursor GetHourGlassCursor ()
83  *
84  *
85  *  Description:
86  *  -----------
87  *  Builds and returns the appropriate Hourglass cursor
88  *
89  *
90  *  Inputs:
91  *  ------
92  *  dpy = display
93  * 
94  *  Outputs:
95  *  -------
96  *  Return = cursor.
97  *
98  *  Comments:
99  *  --------
100  *  None. (None doesn't count as a comment)
101  * 
102  *************************************<->***********************************/
103 static Cursor GetHourGlassCursor(
104   Display *dpy)
105
106 {
107     char        *bits;
108     char        *maskBits;
109     unsigned int width;
110     unsigned int height;
111     unsigned int xHotspot;
112     unsigned int yHotspot;
113     Pixmap       pixmap;
114     Pixmap       maskPixmap;
115     XColor       xcolors[2];
116     int          scr;
117     unsigned int cWidth;
118     unsigned int cHeight;
119     int          useLargeCursors = 0;
120     static Cursor waitCursor=0;
121
122
123     if (waitCursor != 0)
124       return(waitCursor);
125
126     if (XQueryBestCursor (dpy, DefaultRootWindow(dpy), 
127         32, 32, &cWidth, &cHeight))
128     {
129         if ((cWidth >= 32) && (cHeight >= 32))
130         {
131             useLargeCursors = 1;
132         }
133     }
134
135     if (useLargeCursors)
136     {
137         width    = time32_width;
138         height   = time32_height;
139         bits     = (char *) time32_bits;
140         maskBits = (char *) time32m_bits;
141         xHotspot = time32_x_hot;
142         yHotspot = time32_y_hot;
143     }
144     else
145     {
146         width    = time16_width;
147         height   = time16_height;
148         bits     = (char *) time16_bits;
149         maskBits = (char *) time16m_bits;
150         xHotspot = time16_x_hot;
151         yHotspot = time16_y_hot;
152     }
153
154     pixmap = XCreateBitmapFromData (dpy, 
155                      DefaultRootWindow(dpy), bits, 
156                      width, height);
157
158   
159     maskPixmap = XCreateBitmapFromData (dpy, 
160                      DefaultRootWindow(dpy), maskBits, 
161                      width, height);
162
163     xcolors[0].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(dpy));
164     xcolors[1].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(dpy));
165
166     XQueryColors (dpy, 
167                   DefaultColormapOfScreen(DefaultScreenOfDisplay
168                                           (dpy)), xcolors, 2);
169
170     waitCursor = XCreatePixmapCursor (dpy, pixmap, maskPixmap,
171                                       &(xcolors[0]), &(xcolors[1]),
172                                       xHotspot, yHotspot);
173     XFreePixmap (dpy, pixmap);
174     XFreePixmap (dpy, maskPixmap);
175
176     return (waitCursor);
177 }
178
179  
180 /*************************************<->*************************************
181  *
182  *  void TurnOnHourGlass
183  *
184  *
185  *  Description:
186  *  -----------
187  *  sets the window cursor to an hourglass
188  *
189  *
190  *  Inputs:
191  *  ------
192  *  w   = Widget
193  *
194  *  Outputs:
195  *  -------
196  *  None
197  *
198  *  Comments:
199  *  --------
200  *  None. (None doesn't count as a comment)
201  *
202  *************************************<->***********************************/
203 void TurnOnHourGlass(
204         Widget w)
205 {
206     Cursor cursor;
207     
208     cursor = GetHourGlassCursor(XtDisplay(w));
209
210     XDefineCursor(XtDisplay(w), XtWindow(w), cursor);
211     XFlush(XtDisplay(w));
212 }
213
214
215 /*************************************<->*************************************
216  *
217  *  void TurnOffHourGlass
218  *
219  *
220  *  Description:
221  *  -----------
222  *  Removed the hourglass cursor from a window
223  *
224  *
225  *  Inputs:
226  *  ------
227  *  w = Widget
228  *
229  *  Outputs:
230  *  -------
231  *  None
232  *
233  *  Comments:
234  *  --------
235  *  None. (None doesn't count as a comment)
236  *
237  *************************************<->***********************************/
238 void TurnOffHourGlass(
239         Widget w)
240
241 {
242    
243     XUndefineCursor(XtDisplay(w), XtWindow(w));
244     XFlush(XtDisplay(w));
245 }
246
247
248
249
250
251
252
253
254
255
256
257
258
259