HourGlass.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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/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. #include <X11/Xlib.h>
  46. #include <X11/Intrinsic.h>
  47. #define time32_width 32
  48. #define time32_height 32
  49. #define time32_x_hot 15
  50. #define time32_y_hot 15
  51. static unsigned char time32_bits[] = {
  52. 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
  53. 0x8c, 0x00, 0x00, 0x31, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
  54. 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32, 0x4c, 0x00, 0x00, 0x32,
  55. 0x8c, 0x00, 0x00, 0x31, 0x0c, 0x7f, 0xfe, 0x30, 0x0c, 0xfe, 0x7f, 0x30,
  56. 0x0c, 0xfc, 0x3f, 0x30, 0x0c, 0xf8, 0x1f, 0x30, 0x0c, 0xe0, 0x07, 0x30,
  57. 0x0c, 0x80, 0x01, 0x30, 0x0c, 0x80, 0x01, 0x30, 0x0c, 0x60, 0x06, 0x30,
  58. 0x0c, 0x18, 0x18, 0x30, 0x0c, 0x04, 0x20, 0x30, 0x0c, 0x02, 0x40, 0x30,
  59. 0x0c, 0x01, 0x80, 0x30, 0x8c, 0x00, 0x00, 0x31, 0x4c, 0x80, 0x01, 0x32,
  60. 0x4c, 0xc0, 0x03, 0x32, 0x4c, 0xf0, 0x1f, 0x32, 0x4c, 0xff, 0xff, 0x32,
  61. 0xcc, 0xff, 0xff, 0x33, 0x8c, 0xff, 0xff, 0x31, 0xfe, 0xff, 0xff, 0x7f,
  62. 0xfe, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00};
  63. #define time32m_width 32
  64. #define time32m_height 32
  65. static unsigned char time32m_bits[] = {
  66. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  67. 0xcf, 0x00, 0x00, 0xf3, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
  68. 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76, 0x6e, 0x00, 0x00, 0x76,
  69. 0xce, 0x00, 0x00, 0x73, 0x8e, 0x7f, 0xfe, 0x71, 0x0e, 0xff, 0xff, 0x70,
  70. 0x0e, 0xfe, 0x7f, 0x70, 0x0e, 0xfc, 0x3f, 0x70, 0x0e, 0xf8, 0x1f, 0x70,
  71. 0x0e, 0xe0, 0x07, 0x70, 0x0e, 0xe0, 0x07, 0x70, 0x0e, 0x78, 0x1e, 0x70,
  72. 0x0e, 0x1c, 0x38, 0x70, 0x0e, 0x06, 0x60, 0x70, 0x0e, 0x03, 0xc0, 0x70,
  73. 0x8e, 0x01, 0x80, 0x71, 0xce, 0x00, 0x00, 0x73, 0x6e, 0x80, 0x01, 0x76,
  74. 0x6e, 0xc0, 0x03, 0x76, 0x6e, 0xf0, 0x1f, 0x76, 0x6e, 0xff, 0xff, 0x76,
  75. 0xee, 0xff, 0xff, 0x77, 0xcf, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff,
  76. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  77. #define time16_x_hot 7
  78. #define time16_y_hot 7
  79. #define time16_width 16
  80. #define time16_height 16
  81. static unsigned char time16_bits[] = {
  82. 0x00, 0x00, 0xfe, 0x7f, 0x14, 0x28, 0x14, 0x28, 0x14, 0x28, 0x24, 0x24,
  83. 0x44, 0x22, 0x84, 0x21, 0x84, 0x21, 0x44, 0x22, 0x24, 0x24, 0x14, 0x28,
  84. 0x94, 0x29, 0xd4, 0x2b, 0xfe, 0x7f, 0x00, 0x00};
  85. #define time16m_width 16
  86. #define time16m_height 16
  87. static unsigned char time16m_bits[] = {
  88. 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
  89. 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f,
  90. 0xfe, 0x7f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff};
  91. /******** End Public Function Declarations ********/
  92. /*************************************<->*************************************
  93. *
  94. * Cursor GetHourGlassCursor ()
  95. *
  96. *
  97. * Description:
  98. * -----------
  99. * Builds and returns the appropriate Hourglass cursor
  100. *
  101. *
  102. * Inputs:
  103. * ------
  104. * dpy = display
  105. *
  106. * Outputs:
  107. * -------
  108. * Return = cursor.
  109. *
  110. * Comments:
  111. * --------
  112. * None. (None doesn't count as a comment)
  113. *
  114. *************************************<->***********************************/
  115. static Cursor GetHourGlassCursor(
  116. Display *dpy)
  117. {
  118. char *bits;
  119. char *maskBits;
  120. unsigned int width;
  121. unsigned int height;
  122. unsigned int xHotspot;
  123. unsigned int yHotspot;
  124. Pixmap pixmap;
  125. Pixmap maskPixmap;
  126. XColor xcolors[2];
  127. int scr;
  128. unsigned int cWidth;
  129. unsigned int cHeight;
  130. int useLargeCursors = 0;
  131. static Cursor waitCursor=0;
  132. if (waitCursor != 0)
  133. return(waitCursor);
  134. if (XQueryBestCursor (dpy, DefaultRootWindow(dpy),
  135. 32, 32, &cWidth, &cHeight))
  136. {
  137. if ((cWidth >= 32) && (cHeight >= 32))
  138. {
  139. useLargeCursors = 1;
  140. }
  141. }
  142. if (useLargeCursors)
  143. {
  144. width = time32_width;
  145. height = time32_height;
  146. bits = (char *) time32_bits;
  147. maskBits = (char *) time32m_bits;
  148. xHotspot = time32_x_hot;
  149. yHotspot = time32_y_hot;
  150. }
  151. else
  152. {
  153. width = time16_width;
  154. height = time16_height;
  155. bits = (char *) time16_bits;
  156. maskBits = (char *) time16m_bits;
  157. xHotspot = time16_x_hot;
  158. yHotspot = time16_y_hot;
  159. }
  160. pixmap = XCreateBitmapFromData (dpy,
  161. DefaultRootWindow(dpy), bits,
  162. width, height);
  163. maskPixmap = XCreateBitmapFromData (dpy,
  164. DefaultRootWindow(dpy), maskBits,
  165. width, height);
  166. xcolors[0].pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(dpy));
  167. xcolors[1].pixel = WhitePixelOfScreen(DefaultScreenOfDisplay(dpy));
  168. XQueryColors (dpy,
  169. DefaultColormapOfScreen(DefaultScreenOfDisplay
  170. (dpy)), xcolors, 2);
  171. waitCursor = XCreatePixmapCursor (dpy, pixmap, maskPixmap,
  172. &(xcolors[0]), &(xcolors[1]),
  173. xHotspot, yHotspot);
  174. XFreePixmap (dpy, pixmap);
  175. XFreePixmap (dpy, maskPixmap);
  176. return (waitCursor);
  177. }
  178. /*************************************<->*************************************
  179. *
  180. * void TurnOnHourGlass
  181. *
  182. *
  183. * Description:
  184. * -----------
  185. * sets the window cursor to an hourglass
  186. *
  187. *
  188. * Inputs:
  189. * ------
  190. * w = Widget
  191. *
  192. * Outputs:
  193. * -------
  194. * None
  195. *
  196. * Comments:
  197. * --------
  198. * None. (None doesn't count as a comment)
  199. *
  200. *************************************<->***********************************/
  201. void TurnOnHourGlass(
  202. Widget w)
  203. {
  204. Cursor cursor;
  205. cursor = GetHourGlassCursor(XtDisplay(w));
  206. XDefineCursor(XtDisplay(w), XtWindow(w), cursor);
  207. XFlush(XtDisplay(w));
  208. }
  209. /*************************************<->*************************************
  210. *
  211. * void TurnOffHourGlass
  212. *
  213. *
  214. * Description:
  215. * -----------
  216. * Removed the hourglass cursor from a window
  217. *
  218. *
  219. * Inputs:
  220. * ------
  221. * w = Widget
  222. *
  223. * Outputs:
  224. * -------
  225. * None
  226. *
  227. * Comments:
  228. * --------
  229. * None. (None doesn't count as a comment)
  230. *
  231. *************************************<->***********************************/
  232. void TurnOffHourGlass(
  233. Widget w)
  234. {
  235. XUndefineCursor(XtDisplay(w), XtWindow(w));
  236. XFlush(XtDisplay(w));
  237. }