HourGlass.c 11 KB

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