home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / Xfe / Cursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.2 KB  |  145 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /*-----------------------------------------*/
  19. /*                                                                        */
  20. /* Name:        <Xfe/Cursor.c>                                            */
  21. /* Description:    Xfe widgets cursor utilities.                            */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeP.h>
  28.  
  29. #define hand_width 16
  30. #define hand_height 16
  31.  
  32. #define hand_x_hot 3
  33. #define hand_y_hot 2
  34.  
  35. static char hand_bits[] = 
  36. {
  37.     0x80, 0x01, 0x58, 0x0e, 0x64, 0x12, 0x64, 0x52, 0x48, 0xb2, 0x48, 0x92,
  38.     0x16, 0x90, 0x19, 0x80, 0x11, 0x40, 0x02, 0x40, 0x04, 0x40, 0x04, 0x20,
  39.     0x08, 0x20, 0x10, 0x10, 0x20, 0x10, 0x20, 0x10
  40. };
  41.  
  42. #define hand_mask_width 16
  43. #define hand_mask_height 16
  44.  
  45. static char hand_mask_bits[] = 
  46. {
  47.     0xff, 0xff, 0x7f, 0xfe, 0x67, 0xf2, 0x67, 0xf2, 0x4f, 0xb2, 0x4f, 0x92,
  48.     0x17, 0x90, 0x19, 0x80, 0x11, 0xc0, 0x03, 0xc0, 0x07, 0xc0, 0x07, 0xe0,
  49.     0x0f, 0xe0, 0x1f, 0xf0, 0x3f, 0xf0, 0x3f, 0xf0
  50.  
  51. #if 0
  52.     0x80, 0x01, 0xd8, 0x0f, 0xfc, 0x1f, 0xfc, 0x5f, 0xf8, 0xff, 0xf8, 0xff,
  53.     0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0x7f, 0xfc, 0x7f, 0xfc, 0x3f,
  54.     0xf8, 0x3f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0, 0x1f
  55. #endif
  56. };
  57.  
  58. /*----------------------------------------------------------------------*/
  59. /*                                                                        */
  60. /* Cursor                                                                */
  61. /*                                                                        */
  62. /*----------------------------------------------------------------------*/
  63. /* extern */ void
  64. XfeCursorDefine(Widget w,Cursor cursor)
  65. {
  66.     if (_XfeIsRealized(w) && _XfeCursorGood(cursor))
  67.     {
  68.         XDefineCursor(XtDisplay(w),_XfeWindow(w),cursor);
  69.     }
  70. }
  71. /*----------------------------------------------------------------------*/
  72. /* extern */ void
  73. XfeCursorUndefine(Widget w)
  74. {
  75.     if (_XfeIsRealized(w))
  76.     {
  77.         XUndefineCursor(XtDisplay(w),_XfeWindow(w));
  78.     }
  79. }
  80. /*----------------------------------------------------------------------*/
  81. /* extern */ Boolean
  82. XfeCursorGood(Cursor cursor)
  83. {
  84.     return _XfeCursorGood(cursor);
  85. }
  86. /*----------------------------------------------------------------------*/
  87. /* extern */ Cursor
  88. XfeCursorGetDragHand(Widget w)
  89. {
  90.     static Cursor    hand_cursor = None;
  91.  
  92.     if (hand_cursor == None)
  93.     {
  94.         Pixmap        cursor_pixmap;
  95.         Pixmap        cursor_mask;
  96.         XColor        white_color;
  97.         XColor        black_color;
  98.  
  99.         assert( _XfeIsAlive(w) );
  100.         
  101.         cursor_pixmap = 
  102.             XCreatePixmapFromBitmapData(XtDisplay(w),
  103.                                         DefaultRootWindow(XtDisplay(w)),
  104.                                         hand_bits,
  105.                                         hand_width,
  106.                                         hand_height,
  107.                                         BlackPixelOfScreen(_XfeScreen(w)),
  108.                                         WhitePixelOfScreen(_XfeScreen(w)),
  109.                                         1);
  110.         
  111.         
  112.         assert( _XfePixmapGood(cursor_pixmap) );
  113.         
  114.         cursor_mask = 
  115.             XCreatePixmapFromBitmapData(XtDisplay(w),
  116.                                         DefaultRootWindow(XtDisplay(w)),
  117.                                         hand_mask_bits,
  118.                                         hand_mask_width,
  119.                                         hand_mask_height,
  120.                                         BlackPixelOfScreen(_XfeScreen(w)),
  121.                                         WhitePixelOfScreen(_XfeScreen(w)),
  122.                                         1);
  123.         
  124.         assert( _XfePixmapGood(cursor_mask) );
  125.         
  126.         white_color.red = white_color.green = white_color.blue = 0xffff;
  127.         black_color.red = black_color.green = black_color.blue = 0x0;
  128.         
  129.         hand_cursor = XCreatePixmapCursor(XtDisplay(w),
  130.                                           cursor_pixmap,
  131.                                           cursor_mask,
  132.                                           &white_color,
  133.                                           &black_color,
  134.                                           hand_x_hot,
  135.                                           hand_y_hot);
  136.  
  137.         assert( hand_cursor != None );
  138.     }
  139.  
  140.  
  141.     return hand_cursor;
  142. }
  143. /*----------------------------------------------------------------------*/
  144.  
  145.