HourGlass.c 13 KB

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