XlationSvc: remove a "'" added in previous spelling commit that causes warnings
[oweals/cde.git] / cde / lib / DtSvc / DtUtil2 / 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 libraries 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/5 1996/06/21 17:22:09 ageorge $ */
24 /*
25  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
26  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
27  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
28  * (c) Copyright 1993, 1994 Novell, Inc.                                *
29  */
30 /************************************<+>*************************************
31  ****************************************************************************
32  **
33  **   File:        HourGlass.c
34  **
35  **   Project:     dt Dt Utility function
36  **
37  **   Description: This module contains a simple function for
38  **                creating an hourglass cursor.
39  **
40  **   (c) Copyright 1987, 1988, 1989 by Hewlett-Packard Company
41  **
42  **
43  **
44  ****************************************************************************
45  ************************************<+>*************************************/
46
47 /*****************************************************************************
48  *
49  * (c) Copyright 1989,1990 OPEN SOFTWARE FOUNDATION, INC.
50  * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY
51  * ALL RIGHTS RESERVED
52  *
53  *      THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED
54  * AND COPIED ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND
55  * WITH THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR
56  * ANY OTHER COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE
57  * AVAILABLE TO ANY OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF THE
58  * SOFTWARE IS HEREBY TRANSFERRED.
59  *
60  *      THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT
61  * NOTICE AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY OPEN SOFTWARE
62  * FOUNDATION, INC. OR ITS THIRD PARTY SUPPLIERS
63  *
64  *      OPEN SOFTWARE FOUNDATION, INC. AND ITS THIRD PARTY SUPPLIERS,
65  * ASSUME NO RESPONSIBILITY FOR THE USE OR INABILITY TO USE ANY OF ITS
66  * SOFTWARE .   OSF SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
67  * KIND, AND OSF EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES, INCLUDING
68  * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
69  * FITNESS FOR A PARTICULAR PURPOSE.
70  *
71  * Notice:  Notwithstanding any other lease or license that may pertain to,
72  * or accompany the delivery of, this computer software, the rights of the
73  * Government regarding its use, reproduction and disclosure are as set
74  * forth in Section 52.227-19 of the FARS Computer Software-Restricted
75  * Rights clause.
76  *
77  * (c) Copyright 1989,1990 Open Software Foundation, Inc.  Unpublished - all
78  * rights reserved under the Copyright laws of the United States.
79  *
80  * RESTRICTED RIGHTS NOTICE:  Use, duplication, or disclosure by the
81  * Government is subject to the restrictions as set forth in subparagraph
82  * (c)(1)(ii) of the Rights in Technical Data and Computer Software clause
83  * at DFARS 52.227-7013.
84  *
85  * Open Software Foundation, Inc.
86  * 11 Cambridge Center
87  * Cambridge, MA   02142
88  * (617)621-8700
89  *
90  * RESTRICTED RIGHTS LEGEND:  This computer software is submitted with
91  * "restricted rights."  Use, duplication or disclosure is subject to the
92  * restrictions as set forth in NASA FAR SUP 18-52.227-79 (April 1985)
93  * "Commercial Computer Software- Restricted Rights (April 1985)."  Open
94  * Software Foundation, Inc., 11 Cambridge Center, Cambridge, MA  02142.  If
95  * the contract contains the Clause at 18-52.227-74 "Rights in Data General"
96  * then the "Alternate III" clause applies.
97  *
98  * (c) Copyright 1989,1990 Open Software Foundation, Inc.
99  * ALL RIGHTS RESERVED
100  *
101  *
102  * Open Software Foundation is a trademark of The Open Software  
103  * Foundation, Inc.
104  *
105  * OSF is a trademark of Open Software Foundation, Inc.
106  * OSF/Motif is a trademark of Open Software Foundation, Inc.
107  * Motif is a trademark of Open Software Foundation, Inc.
108  * DEC is a registered trademark of Digital Equipment Corporation
109  * DIGITAL is a registered trademark of Digital Equipment Corporation
110  * X Window System is a trademark of the Massachusetts Institute of Technology
111  *
112  *****************************************************************************
113  *************************************<+>*************************************/
114
115
116 #include <X11/Xlib.h>
117 #include <X11/Intrinsic.h>
118 #include "DtSvcLock.h"
119
120 #define time32_width 32
121 #define time32_height 32
122 #define time32_x_hot 15
123 #define time32_y_hot 15
124 static unsigned char time32_bits[] = {
125    0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
126    0x8c, 0x00, 0x00, 0x31, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
127    0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
128    0x8c, 0x00, 0x00, 0x31, 0x0c, 0x7f, 0xfe, 0x30, 0x0c, 0xfe, 0x7f, 0x30,
129    0x0c, 0xfc, 0x3f, 0x30, 0x0c, 0xf8, 0x1f, 0x30, 0x0c, 0xe0, 0x07, 0x30,
130    0x0c, 0x80, 0x01, 0x30, 0x0c, 0x80, 0x01, 0x30, 0x0c, 0x60, 0x06, 0x30,
131    0x0c, 0x18, 0x18, 0x30, 0x0c, 0x04, 0x20, 0x30, 0x0c, 0x02, 0x40, 0x30,
132    0x0c, 0x01, 0x80, 0x30, 0x8c, 0x00, 0x00, 0x31, 0x4c, 0x80, 0x01, 0x32,
133    0x4c, 0xc0, 0x03, 0x32, 0x4c, 0xf0, 0x1f, 0x32, 0x4c, 0xff, 0xff, 0x32,
134    0xcc, 0xff, 0xff, 0x33, 0x8c, 0xff, 0xff, 0x31, 0xfe, 0xff, 0xff, 0x7f,
135    0xfe, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00};
136
137 #define time32m_width 32
138 #define time32m_height 32
139 static unsigned char time32m_bits[] = {
140    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
141    0xcf, 0x00, 0x00, 0xf3, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
142    0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
143    0xce, 0x00, 0x00, 0x73, 0x8e, 0x7f, 0xfe, 0x71, 0x0e, 0xff, 0xff, 0x70,
144    0x0e, 0xfe, 0x7f, 0x70, 0x0e, 0xfc, 0x3f, 0x70, 0x0e, 0xf8, 0x1f, 0x70,
145    0x0e, 0xe0, 0x07, 0x70, 0x0e, 0xe0, 0x07, 0x70, 0x0e, 0x78, 0x1e, 0x70,
146    0x0e, 0x1c, 0x38, 0x70, 0x0e, 0x06, 0x60, 0x70, 0x0e, 0x03, 0xc0, 0x70,
147    0x8e, 0x01, 0x80, 0x71, 0xce, 0x00, 0x00, 0x73, 0x6e, 0x80, 0x01, 0x76,
148    0x6e, 0xc0, 0x03, 0x76, 0x6e, 0xf0, 0x1f, 0x76, 0x6e, 0xff, 0xff, 0x76,
149    0xee, 0xff, 0xff, 0x77, 0xcf, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff,
150    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
151
152
153 #define time16_x_hot 7
154 #define time16_y_hot 7
155 #define time16_width 16
156 #define time16_height 16
157 static unsigned char time16_bits[] = {
158    0x00, 0x00, 0xfe, 0x7f, 0x14, 0x28, 0x14, 0x28, 0x14, 0x28, 0x24, 0x24,
159    0x44, 0x22, 0x84, 0x21, 0x84, 0x21, 0x44, 0x22, 0x24, 0x24, 0x14, 0x28,
160    0x94, 0x29, 0xd4, 0x2b, 0xfe, 0x7f, 0x00, 0x00};
161
162 #define time16m_width 16
163 #define time16m_height 16
164 static unsigned char time16m_bits[] = {
165    0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
166    0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
167    0xfe, 0x7f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff};
168
169
170 /********    Public Function Declarations    ********/
171
172 extern Cursor _DtGetHourGlassCursor( 
173                         Display *dpy) ;
174 extern void _DtTurnOnHourGlass( 
175                         Widget w) ;
176 extern void _DtTurnOffHourGlass( 
177                         Widget w) ;
178
179 /********    End Public Function Declarations    ********/
180
181 /*************************************<->*************************************
182  *
183  *  Cursor _DtGetHourGlassCursor ()
184  *
185  *
186  *  Description:
187  *  -----------
188  *  Builds and returns the appropriate Hourglass cursor
189  *
190  *
191  *  Inputs:
192  *  ------
193  *  dpy = display
194  * 
195  *  Outputs:
196  *  -------
197  *  Return = cursor.
198  *
199  *  Comments:
200  *  --------
201  *  None. (None doesn't count as a comment)
202  * 
203  *************************************<->***********************************/
204 Cursor 
205 _DtGetHourGlassCursor(
206         Display *dpy )
207 {
208     unsigned char *bits;
209     unsigned char *maskBits;
210     unsigned int width;
211     unsigned int height;
212     unsigned int xHotspot;
213     unsigned int yHotspot;
214     Pixmap       pixmap;
215     Pixmap       maskPixmap;
216     XColor       xcolors[2];
217     int          scr;
218     unsigned int cWidth;
219     unsigned int cHeight;
220     int          useLargeCursors = 0;
221     static Cursor waitCursor=0;
222
223     _DtSvcProcessLock();
224     if (waitCursor != 0) {
225       _DtSvcProcessUnlock();
226       return(waitCursor);
227     }
228
229     if (XQueryBestCursor (dpy, DefaultRootWindow(dpy), 
230         32, 32, &cWidth, &cHeight))
231     {
232         if ((cWidth >= 32) && (cHeight >= 32))
233         {
234             useLargeCursors = 1;
235         }
236     }
237
238     if (useLargeCursors)
239     {
240         width = time32_width;
241         height = time32_height;
242         bits = time32_bits;
243         maskBits = time32m_bits;
244         xHotspot = time32_x_hot;
245         yHotspot = time32_y_hot;
246     }
247     else
248     {
249         width = time16_width;
250         height = time16_height;
251         bits = time16_bits;
252         maskBits = time16m_bits;
253         xHotspot = time16_x_hot;
254         yHotspot = time16_y_hot;
255     }
256
257     pixmap = XCreateBitmapFromData (dpy, 
258                      DefaultRootWindow(dpy), (char*) bits, 
259                      width, height);
260
261   
262     maskPixmap = XCreateBitmapFromData (dpy, 
263                      DefaultRootWindow(dpy), (char*) maskBits, 
264                      width, height);
265
266     xcolors[0].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(dpy));
267     xcolors[1].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(dpy));
268
269     XQueryColors (dpy, 
270                   DefaultColormapOfScreen(DefaultScreenOfDisplay
271                                           (dpy)), xcolors, 2);
272
273     waitCursor = XCreatePixmapCursor (dpy, pixmap, maskPixmap,
274                                       &(xcolors[0]), &(xcolors[1]),
275                                       xHotspot, yHotspot);
276     XFreePixmap (dpy, pixmap);
277     XFreePixmap (dpy, maskPixmap);
278
279     _DtSvcProcessUnlock();
280     return (waitCursor);
281 }
282
283  
284 /*************************************<->*************************************
285  *
286  *  void DtSetHourGlass
287  *
288  *
289  *  Description:
290  *  -----------
291  *  sets the window cursor to an hourglass
292  *
293  *
294  *  Inputs:
295  *  ------
296  *  w   = Widget
297  *
298  *  Outputs:
299  *  -------
300  *  None
301  *
302  *  Comments:
303  *  --------
304  *  None. (None doesn't count as a comment)
305  *
306  *************************************<->***********************************/
307
308 void 
309 _DtTurnOnHourGlass(
310         Widget w )
311 {
312     Cursor cursor;
313     
314     cursor = _DtGetHourGlassCursor(XtDisplay(w));
315
316     XDefineCursor(XtDisplay(w), XtWindow(w), cursor);
317     XFlush(XtDisplay(w));
318 }
319
320
321 /*************************************<->*************************************
322  *
323  *  void _DtTurnOffHourGlass
324  *
325  *
326  *  Description:
327  *  -----------
328  *  Removed the hourglass cursor from a window
329  *
330  *
331  *  Inputs:
332  *  ------
333  *  w = Widget
334  *
335  *  Outputs:
336  *  -------
337  *  None
338  *
339  *  Comments:
340  *  --------
341  *  None. (None doesn't count as a comment)
342  *
343  *************************************<->***********************************/
344
345 void 
346 _DtTurnOffHourGlass(
347         Widget w )
348 {
349    
350     XUndefineCursor(XtDisplay(w), XtWindow(w));
351     XFlush(XtDisplay(w));
352 }
353
354
355
356
357
358
359
360
361
362
363
364
365
366