Merge branch 'master' into cde-next
[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 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/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     unsigned int cWidth;
184     unsigned int cHeight;
185     int          useLargeCursors = 0;
186     static Cursor waitCursor=0;
187
188     _DtHelpProcessLock();
189
190     if (waitCursor != 0)
191       {
192         _DtHelpProcessUnlock();
193         return(waitCursor);
194       }
195
196     if (XQueryBestCursor (dpy, DefaultRootWindow(dpy), 
197         32, 32, &cWidth, &cHeight))
198     {
199         if ((cWidth >= 32) && (cHeight >= 32))
200         {
201             useLargeCursors = 1;
202         }
203     }
204
205     if (useLargeCursors)
206     {
207         width    = noenter32_width;
208         height   = noenter32_height;
209         bits     = (char *) noenter32_bits;
210         maskBits = (char *) noenter32m_bits;
211         xHotspot = noenter32_x_hot;
212         yHotspot = noenter32_y_hot;
213     }
214     else
215     {
216         width    = noenter16_width;
217         height   = noenter16_height;
218         bits     = (char *) noenter16_bits;
219         maskBits = (char *) noenter16m_bits;
220         xHotspot = noenter16_x_hot;
221         yHotspot = noenter16_y_hot;
222     }
223
224     pixmap = XCreateBitmapFromData (dpy, 
225                      DefaultRootWindow(dpy), bits, 
226                      width, height);
227
228   
229     maskPixmap = XCreateBitmapFromData (dpy, 
230                      DefaultRootWindow(dpy), maskBits, 
231                      width, height);
232
233     xcolors[0].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(dpy));
234     xcolors[1].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(dpy));
235
236     XQueryColors (dpy, 
237                   DefaultColormapOfScreen(DefaultScreenOfDisplay
238                                           (dpy)), xcolors, 2);
239
240     waitCursor = XCreatePixmapCursor (dpy, pixmap, maskPixmap,
241                                       &(xcolors[0]), &(xcolors[1]),
242                                       xHotspot, yHotspot);
243     XFreePixmap (dpy, pixmap);
244     XFreePixmap (dpy, maskPixmap);
245
246     _DtHelpProcessUnlock();
247     return (waitCursor);
248 }
249
250 /*************************************<->*************************************
251  *
252  *  Cursor _DtHelpGetHourGlassCursor ()
253  *
254  *
255  *  Description:
256  *  -----------
257  *  Builds and returns the appropriate Hourglass cursor
258  *
259  *
260  *  Inputs:
261  *  ------
262  *  dpy = display
263  * 
264  *  Outputs:
265  *  -------
266  *  Return = cursor.
267  *
268  *  Comments:
269  *  --------
270  *  None. (None doesn't count as a comment)
271  * 
272  *************************************<->***********************************/
273 Cursor 
274 _DtHelpGetHourGlassCursor(
275         Display *dpy )
276 {
277     char        *bits;
278     char        *maskBits;
279     unsigned int width;
280     unsigned int height;
281     unsigned int xHotspot;
282     unsigned int yHotspot;
283     Pixmap       pixmap;
284     Pixmap       maskPixmap;
285     XColor       xcolors[2];
286     unsigned int cWidth;
287     unsigned int cHeight;
288     int          useLargeCursors = 0;
289     static Cursor waitCursor=0;
290
291
292     if (waitCursor != 0)
293       return(waitCursor);
294
295     if (XQueryBestCursor (dpy, DefaultRootWindow(dpy), 
296         32, 32, &cWidth, &cHeight))
297     {
298         if ((cWidth >= 32) && (cHeight >= 32))
299         {
300             useLargeCursors = 1;
301         }
302     }
303
304     if (useLargeCursors)
305     {
306         width    = time32_width;
307         height   = time32_height;
308         bits     = (char *) time32_bits;
309         maskBits = (char *) time32m_bits;
310         xHotspot = time32_x_hot;
311         yHotspot = time32_y_hot;
312     }
313     else
314     {
315         width    = time16_width;
316         height   = time16_height;
317         bits     = (char *) time16_bits;
318         maskBits = (char *) time16m_bits;
319         xHotspot = time16_x_hot;
320         yHotspot = time16_y_hot;
321     }
322
323     pixmap = XCreateBitmapFromData (dpy, 
324                      DefaultRootWindow(dpy), bits, 
325                      width, height);
326
327   
328     maskPixmap = XCreateBitmapFromData (dpy, 
329                      DefaultRootWindow(dpy), maskBits, 
330                      width, height);
331
332     xcolors[0].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(dpy));
333     xcolors[1].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(dpy));
334
335     XQueryColors (dpy, 
336                   DefaultColormapOfScreen(DefaultScreenOfDisplay
337                                           (dpy)), xcolors, 2);
338
339     waitCursor = XCreatePixmapCursor (dpy, pixmap, maskPixmap,
340                                       &(xcolors[0]), &(xcolors[1]),
341                                       xHotspot, yHotspot);
342     XFreePixmap (dpy, pixmap);
343     XFreePixmap (dpy, maskPixmap);
344
345     return (waitCursor);
346 }
347
348  
349 /*************************************<->*************************************
350  *
351  *  void _DtSetHourGlass
352  *
353  *
354  *  Description:
355  *  -----------
356  *  sets the window cursor to an hourglass
357  *
358  *
359  *  Inputs:
360  *  ------
361  *  w   = Widget
362  *
363  *  Outputs:
364  *  -------
365  *  None
366  *
367  *  Comments:
368  *  --------
369  *  None. (None doesn't count as a comment)
370  *
371  *************************************<->***********************************/
372
373 void 
374 _DtHelpTurnOnHourGlass(
375         Widget w )
376 {
377     Cursor cursor;
378     
379     cursor = _DtHelpGetHourGlassCursor(XtDisplay(w));
380
381     XDefineCursor(XtDisplay(w), XtWindow(w), cursor);
382     XFlush(XtDisplay(w));
383 }
384
385
386 /*************************************<->*************************************
387  *
388  *  void _DtHelpTurnOffHourGlass
389  *
390  *
391  *  Description:
392  *  -----------
393  *  Removed the hourglass cursor from a window
394  *
395  *
396  *  Inputs:
397  *  ------
398  *  w = Widget
399  *
400  *  Outputs:
401  *  -------
402  *  None
403  *
404  *  Comments:
405  *  --------
406  *  None. (None doesn't count as a comment)
407  *
408  *************************************<->***********************************/
409
410 void 
411 _DtHelpTurnOffHourGlass(
412         Widget w )
413 {
414    
415     XUndefineCursor(XtDisplay(w), XtWindow(w));
416     XFlush(XtDisplay(w));
417 }
418
419 /*************************************<->*************************************
420  *
421  *  void _DtHelpTurnOnNoEnter
422  *
423  *
424  *  Description:
425  *  -----------
426  *  sets the window cursor to a 'no enter' sign
427  *
428  *
429  *  Inputs:
430  *  ------
431  *  w   = Widget
432  *
433  *  Outputs:
434  *  -------
435  *  None
436  *
437  *  Comments:
438  *  --------
439  *  None. (None doesn't count as a comment)
440  *
441  *************************************<->***********************************/
442
443 void 
444 _DtHelpTurnOnNoEnter(
445         Widget w )
446 {
447     Cursor cursor;
448
449     cursor = GetNoEnterCursor(XtDisplay(w));
450
451     XDefineCursor(XtDisplay(w), XtWindow(w), cursor);
452     XFlush(XtDisplay(w));
453 }
454
455
456 /*************************************<->*************************************
457  *
458  *  void _DtHelpTurnOffNoEnter
459  *
460  *
461  *  Description:
462  *  -----------
463  *  Removed the 'no enter' cursor from a window
464  *
465  *
466  *  Inputs:
467  *  ------
468  *  w = Widget
469  *
470  *  Outputs:
471  *  -------
472  *  None
473  *
474  *  Comments:
475  *  --------
476  *  None. (None doesn't count as a comment)
477  *
478  *************************************<->***********************************/
479
480 void 
481 _DtHelpTurnOffNoEnter(
482         Widget w )
483 {
484
485     XUndefineCursor(XtDisplay(w), XtWindow(w));
486     XFlush(XtDisplay(w));
487 }