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