FileUtils.c: fix CERT VU#575804
[oweals/cde.git] / cde / lib / DtHelp / 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/6 1996/04/13 11:55:39 ageorge $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  **
27  **   File:        HourGlass.c
28  **
29  **   Project:     coe Dt Utility function
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 Hewlett-Packard Company
35  **
36  **  (c) Copyright 1993, 1994 Hewlett-Packard Company
37  **  (c) Copyright 1993, 1994 International Business Machines Corp.
38  **  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
39  **  (c) Copyright 1993, 1994 Novell, Inc.
40  **
41  **
42  **
43  ****************************************************************************
44  ************************************<+>*************************************/
45
46
47 #include <X11/Xlib.h>
48 #include <X11/Intrinsic.h>
49
50 #include "Lock.h"
51
52 #define time32_width 32
53 #define time32_height 32
54 #define time32_x_hot 15
55 #define time32_y_hot 15
56 static unsigned char time32_bits[] = {
57    0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
58    0x8c, 0x00, 0x00, 0x31, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
59    0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
60    0x8c, 0x00, 0x00, 0x31, 0x0c, 0x7f, 0xfe, 0x30, 0x0c, 0xfe, 0x7f, 0x30,
61    0x0c, 0xfc, 0x3f, 0x30, 0x0c, 0xf8, 0x1f, 0x30, 0x0c, 0xe0, 0x07, 0x30,
62    0x0c, 0x80, 0x01, 0x30, 0x0c, 0x80, 0x01, 0x30, 0x0c, 0x60, 0x06, 0x30,
63    0x0c, 0x18, 0x18, 0x30, 0x0c, 0x04, 0x20, 0x30, 0x0c, 0x02, 0x40, 0x30,
64    0x0c, 0x01, 0x80, 0x30, 0x8c, 0x00, 0x00, 0x31, 0x4c, 0x80, 0x01, 0x32,
65    0x4c, 0xc0, 0x03, 0x32, 0x4c, 0xf0, 0x1f, 0x32, 0x4c, 0xff, 0xff, 0x32,
66    0xcc, 0xff, 0xff, 0x33, 0x8c, 0xff, 0xff, 0x31, 0xfe, 0xff, 0xff, 0x7f,
67    0xfe, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00};
68
69 #define time32m_width 32
70 #define time32m_height 32
71 static unsigned char time32m_bits[] = {
72    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
73    0xcf, 0x00, 0x00, 0xf3, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
74    0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
75    0xce, 0x00, 0x00, 0x73, 0x8e, 0x7f, 0xfe, 0x71, 0x0e, 0xff, 0xff, 0x70,
76    0x0e, 0xfe, 0x7f, 0x70, 0x0e, 0xfc, 0x3f, 0x70, 0x0e, 0xf8, 0x1f, 0x70,
77    0x0e, 0xe0, 0x07, 0x70, 0x0e, 0xe0, 0x07, 0x70, 0x0e, 0x78, 0x1e, 0x70,
78    0x0e, 0x1c, 0x38, 0x70, 0x0e, 0x06, 0x60, 0x70, 0x0e, 0x03, 0xc0, 0x70,
79    0x8e, 0x01, 0x80, 0x71, 0xce, 0x00, 0x00, 0x73, 0x6e, 0x80, 0x01, 0x76,
80    0x6e, 0xc0, 0x03, 0x76, 0x6e, 0xf0, 0x1f, 0x76, 0x6e, 0xff, 0xff, 0x76,
81    0xee, 0xff, 0xff, 0x77, 0xcf, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff,
82    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
83
84
85 #define time16_x_hot 7
86 #define time16_y_hot 7
87 #define time16_width 16
88 #define time16_height 16
89 static unsigned char time16_bits[] = {
90    0x00, 0x00, 0xfe, 0x7f, 0x14, 0x28, 0x14, 0x28, 0x14, 0x28, 0x24, 0x24,
91    0x44, 0x22, 0x84, 0x21, 0x84, 0x21, 0x44, 0x22, 0x24, 0x24, 0x14, 0x28,
92    0x94, 0x29, 0xd4, 0x2b, 0xfe, 0x7f, 0x00, 0x00};
93
94 #define time16m_width 16
95 #define time16m_height 16
96 static unsigned char time16m_bits[] = {
97    0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
98    0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
99    0xfe, 0x7f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff};
100
101 #define noenter32_width 32
102 #define noenter32_height 32
103 #define noenter32_x_hot 15
104 #define noenter32_y_hot 15
105
106 static unsigned char noenter32_bits[] = {
107    0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xfc, 0x3f, 0x00,
108    0x00, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x01, 0xc0, 0xff, 0xff, 0x03,
109    0xe0, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x1f,
110    0xf8, 0xff, 0xff, 0x1f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
111    0xfc, 0xff, 0xff, 0x3f, 0x06, 0x00, 0x00, 0x60, 0x06, 0x00, 0x00, 0x60,
112    0x06, 0x00, 0x00, 0x60, 0x06, 0x00, 0x00, 0x60, 0x06, 0x00, 0x00, 0x60,
113    0x06, 0x00, 0x00, 0x60, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
114    0xfc, 0xff, 0xff, 0x3f, 0xf8, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0x1f,
115    0xf0, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0x07, 0xc0, 0xff, 0xff, 0x03,
116    0x80, 0xff, 0xff, 0x01, 0x00, 0xff, 0xff, 0x00, 0x00, 0xfc, 0x3f, 0x00,
117    0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00};
118
119 static unsigned char noenter32m_bits[] = {
120    0x00, 0xe0, 0x07, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0xff, 0xff, 0x00,
121    0x80, 0xff, 0xff, 0x01, 0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07,
122    0xf0, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x1f, 0xfc, 0xff, 0xff, 0x3f,
123    0xfc, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
124    0xfe, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
125    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
126    0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
127    0xfe, 0xff, 0xff, 0x7f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
128    0xf8, 0xff, 0xff, 0x1f, 0xf0, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0x07,
129    0xc0, 0xff, 0xff, 0x03, 0x80, 0xff, 0xff, 0x01, 0x00, 0xff, 0xff, 0x00,
130    0x00, 0xfc, 0x3f, 0x00, 0x00, 0xe0, 0x07, 0x00};
131
132 #define noenter16_width 16
133 #define noenter16_height 16
134 #define noenter16_x_hot 7
135 #define noenter16_y_hot 7
136
137 static unsigned char noenter16_bits[] = {
138    0x00, 0x00, 0xc0, 0x03, 0xf0, 0x0f, 0xf8, 0x1f, 0xfc, 0x3f, 0xfc, 0x3f,
139    0xfe, 0x7f, 0x02, 0x40, 0x02, 0x40, 0xfe, 0x7f, 0xfc, 0x3f, 0xfc, 0x3f,
140    0xf8, 0x1f, 0xf0, 0x0f, 0xc0, 0x03, 0x00, 0x00};
141
142 static unsigned char noenter16m_bits[] = {
143    0xc0, 0x03, 0xf0, 0x0f, 0xf8, 0x1f, 0xfc, 0x3f, 0xfe, 0x7f, 0xfe, 0x7f,
144    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x7f,
145    0xfc, 0x3f, 0xf8, 0x1f, 0xf0, 0x0f, 0xc0, 0x03};
146
147 /*************************************<->*************************************
148  *
149  *  Cursor GetNoEnterCursor ()
150  *
151  *
152  *  Description:
153  *  -----------
154  *  Builds and returns the appropriate Hourglass cursor
155  *
156  *
157  *  Inputs:
158  *  ------
159  *  dpy = display
160  * 
161  *  Outputs:
162  *  -------
163  *  Return = cursor.
164  *
165  *  Comments:
166  *  --------
167  *  None. (None doesn't count as a comment)
168  * 
169  *************************************<->***********************************/
170 static Cursor 
171 GetNoEnterCursor(
172         Display *dpy )
173 {
174     char        *bits;
175     char        *maskBits;
176     unsigned int width;
177     unsigned int height;
178     unsigned int xHotspot;
179     unsigned int yHotspot;
180     Pixmap       pixmap;
181     Pixmap       maskPixmap;
182     XColor       xcolors[2];
183     int          scr;
184     unsigned int cWidth;
185     unsigned int cHeight;
186     int          useLargeCursors = 0;
187     static Cursor waitCursor=0;
188
189     _DtHelpProcessLock();
190
191     if (waitCursor != 0)
192       {
193         _DtHelpProcessUnlock();
194         return(waitCursor);
195       }
196
197     if (XQueryBestCursor (dpy, DefaultRootWindow(dpy), 
198         32, 32, &cWidth, &cHeight))
199     {
200         if ((cWidth >= 32) && (cHeight >= 32))
201         {
202             useLargeCursors = 1;
203         }
204     }
205
206     if (useLargeCursors)
207     {
208         width    = noenter32_width;
209         height   = noenter32_height;
210         bits     = (char *) noenter32_bits;
211         maskBits = (char *) noenter32m_bits;
212         xHotspot = noenter32_x_hot;
213         yHotspot = noenter32_y_hot;
214     }
215     else
216     {
217         width    = noenter16_width;
218         height   = noenter16_height;
219         bits     = (char *) noenter16_bits;
220         maskBits = (char *) noenter16m_bits;
221         xHotspot = noenter16_x_hot;
222         yHotspot = noenter16_y_hot;
223     }
224
225     pixmap = XCreateBitmapFromData (dpy, 
226                      DefaultRootWindow(dpy), bits, 
227                      width, height);
228
229   
230     maskPixmap = XCreateBitmapFromData (dpy, 
231                      DefaultRootWindow(dpy), maskBits, 
232                      width, height);
233
234     xcolors[0].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(dpy));
235     xcolors[1].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(dpy));
236
237     XQueryColors (dpy, 
238                   DefaultColormapOfScreen(DefaultScreenOfDisplay
239                                           (dpy)), xcolors, 2);
240
241     waitCursor = XCreatePixmapCursor (dpy, pixmap, maskPixmap,
242                                       &(xcolors[0]), &(xcolors[1]),
243                                       xHotspot, yHotspot);
244     XFreePixmap (dpy, pixmap);
245     XFreePixmap (dpy, maskPixmap);
246
247     _DtHelpProcessUnlock();
248     return (waitCursor);
249 }
250
251 /*************************************<->*************************************
252  *
253  *  Cursor _DtHelpGetHourGlassCursor ()
254  *
255  *
256  *  Description:
257  *  -----------
258  *  Builds and returns the appropriate Hourglass cursor
259  *
260  *
261  *  Inputs:
262  *  ------
263  *  dpy = display
264  * 
265  *  Outputs:
266  *  -------
267  *  Return = cursor.
268  *
269  *  Comments:
270  *  --------
271  *  None. (None doesn't count as a comment)
272  * 
273  *************************************<->***********************************/
274 Cursor 
275 _DtHelpGetHourGlassCursor(
276         Display *dpy )
277 {
278     char        *bits;
279     char        *maskBits;
280     unsigned int width;
281     unsigned int height;
282     unsigned int xHotspot;
283     unsigned int yHotspot;
284     Pixmap       pixmap;
285     Pixmap       maskPixmap;
286     XColor       xcolors[2];
287     int          scr;
288     unsigned int cWidth;
289     unsigned int cHeight;
290     int          useLargeCursors = 0;
291     static Cursor waitCursor=0;
292
293
294     if (waitCursor != 0)
295       return(waitCursor);
296
297     if (XQueryBestCursor (dpy, DefaultRootWindow(dpy), 
298         32, 32, &cWidth, &cHeight))
299     {
300         if ((cWidth >= 32) && (cHeight >= 32))
301         {
302             useLargeCursors = 1;
303         }
304     }
305
306     if (useLargeCursors)
307     {
308         width    = time32_width;
309         height   = time32_height;
310         bits     = (char *) time32_bits;
311         maskBits = (char *) time32m_bits;
312         xHotspot = time32_x_hot;
313         yHotspot = time32_y_hot;
314     }
315     else
316     {
317         width    = time16_width;
318         height   = time16_height;
319         bits     = (char *) time16_bits;
320         maskBits = (char *) time16m_bits;
321         xHotspot = time16_x_hot;
322         yHotspot = time16_y_hot;
323     }
324
325     pixmap = XCreateBitmapFromData (dpy, 
326                      DefaultRootWindow(dpy), bits, 
327                      width, height);
328
329   
330     maskPixmap = XCreateBitmapFromData (dpy, 
331                      DefaultRootWindow(dpy), maskBits, 
332                      width, height);
333
334     xcolors[0].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(dpy));
335     xcolors[1].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(dpy));
336
337     XQueryColors (dpy, 
338                   DefaultColormapOfScreen(DefaultScreenOfDisplay
339                                           (dpy)), xcolors, 2);
340
341     waitCursor = XCreatePixmapCursor (dpy, pixmap, maskPixmap,
342                                       &(xcolors[0]), &(xcolors[1]),
343                                       xHotspot, yHotspot);
344     XFreePixmap (dpy, pixmap);
345     XFreePixmap (dpy, maskPixmap);
346
347     return (waitCursor);
348 }
349
350  
351 /*************************************<->*************************************
352  *
353  *  void _DtSetHourGlass
354  *
355  *
356  *  Description:
357  *  -----------
358  *  sets the window cursor to an hourglass
359  *
360  *
361  *  Inputs:
362  *  ------
363  *  w   = Widget
364  *
365  *  Outputs:
366  *  -------
367  *  None
368  *
369  *  Comments:
370  *  --------
371  *  None. (None doesn't count as a comment)
372  *
373  *************************************<->***********************************/
374
375 void 
376 _DtHelpTurnOnHourGlass(
377         Widget w )
378 {
379     Cursor cursor;
380     
381     cursor = _DtHelpGetHourGlassCursor(XtDisplay(w));
382
383     XDefineCursor(XtDisplay(w), XtWindow(w), cursor);
384     XFlush(XtDisplay(w));
385 }
386
387
388 /*************************************<->*************************************
389  *
390  *  void _DtHelpTurnOffHourGlass
391  *
392  *
393  *  Description:
394  *  -----------
395  *  Removed the hourglass cursor from a window
396  *
397  *
398  *  Inputs:
399  *  ------
400  *  w = Widget
401  *
402  *  Outputs:
403  *  -------
404  *  None
405  *
406  *  Comments:
407  *  --------
408  *  None. (None doesn't count as a comment)
409  *
410  *************************************<->***********************************/
411
412 void 
413 _DtHelpTurnOffHourGlass(
414         Widget w )
415 {
416    
417     XUndefineCursor(XtDisplay(w), XtWindow(w));
418     XFlush(XtDisplay(w));
419 }
420
421 /*************************************<->*************************************
422  *
423  *  void _DtHelpTurnOnNoEnter
424  *
425  *
426  *  Description:
427  *  -----------
428  *  sets the window cursor to a 'no enter' sign
429  *
430  *
431  *  Inputs:
432  *  ------
433  *  w   = Widget
434  *
435  *  Outputs:
436  *  -------
437  *  None
438  *
439  *  Comments:
440  *  --------
441  *  None. (None doesn't count as a comment)
442  *
443  *************************************<->***********************************/
444
445 void 
446 _DtHelpTurnOnNoEnter(
447         Widget w )
448 {
449     Cursor cursor;
450
451     cursor = GetNoEnterCursor(XtDisplay(w));
452
453     XDefineCursor(XtDisplay(w), XtWindow(w), cursor);
454     XFlush(XtDisplay(w));
455 }
456
457
458 /*************************************<->*************************************
459  *
460  *  void _DtHelpTurnOffNoEnter
461  *
462  *
463  *  Description:
464  *  -----------
465  *  Removed the 'no enter' cursor from a window
466  *
467  *
468  *  Inputs:
469  *  ------
470  *  w = Widget
471  *
472  *  Outputs:
473  *  -------
474  *  None
475  *
476  *  Comments:
477  *  --------
478  *  None. (None doesn't count as a comment)
479  *
480  *************************************<->***********************************/
481
482 void 
483 _DtHelpTurnOffNoEnter(
484         Widget w )
485 {
486
487     XUndefineCursor(XtDisplay(w), XtWindow(w));
488     XFlush(XtDisplay(w));
489 }