1 /*
2  *  This file is part of XForms.
3  *
4  *  XForms is free software; you can redistribute it and/or modify it
5  *  under the terms of the GNU Lesser General Public License as
6  *  published by the Free Software Foundation; either version 2.1, or
7  *  (at your option) any later version.
8  *
9  *  XForms is distributed in the hope that it will be useful, but
10  *  WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  *  Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public
15  *  License along with XForms; see the file COPYING.  If not, write to
16  *  the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
17  *  MA 02111-1307, USA.
18  */
19 
20 
21 /*
22  * Cursor routines demo.
23  *
24  * This file is part of xforms package
25  * T.C. Zhao and M. Overmars   (1997)
26  *
27  */
28 
29 
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33 
34 #include <stdlib.h>
35 #include "include/forms.h"
36 #include "bm1.xbm"
37 #include "bm2.xbm"
38 
39 
40 static int animated = 0;
41 
42 typedef struct {
43     FL_FORM * cursor;
44     void    * vdata;
45     char    * cdata;
46     long      ldata;
47 } FD_cursor;
48 
49 extern FD_cursor * create_form_cursor( void );
50 
51 
52 /* callbacks for form cursor */
53 
54 /***************************************
55  ***************************************/
56 
57 void
setcursor_cb(FL_OBJECT * ob,long data)58 setcursor_cb( FL_OBJECT * ob,
59               long        data )
60 {
61     fl_set_cursor( FL_ObjWin( ob ), data );
62 }
63 
64 
65 /***************************************
66  ***************************************/
67 
68 void
setbitmapcursor_cb(FL_OBJECT * ob,long data FL_UNUSED_ARG)69 setbitmapcursor_cb( FL_OBJECT * ob,
70                     long        data  FL_UNUSED_ARG )
71 {
72     static int bitmapcur;
73 
74     if ( ! bitmapcur )
75         bitmapcur = fl_create_bitmap_cursor( ( char * ) bm1_bits,
76                                              ( char * ) bm2_bits,
77                                              bm1_width, bm1_height,
78                                              bm1_width / 2, bm1_height / 2 );
79     fl_set_cursor( FL_ObjWin( ob ), bitmapcur );
80 
81 }
82 
83 
84 /***************************************
85  ***************************************/
86 
87 void
setanimatedcursor_cb(FL_OBJECT * ob,long data FL_UNUSED_ARG)88 setanimatedcursor_cb( FL_OBJECT * ob,
89                       long        data  FL_UNUSED_ARG )
90 {
91     fl_set_cursor( FL_ObjWin(ob), animated );
92 }
93 
94 
95 /***************************************
96  ***************************************/
97 
done_cb(FL_OBJECT * ob,long data FL_UNUSED_ARG)98 void done_cb( FL_OBJECT * ob,
99               long        data  FL_UNUSED_ARG )
100 {
101     fl_free( ob->form->fdui );
102     fl_finish( );
103     exit( 0 );
104 }
105 
106 
107 
108 int curs[ ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1 };
109 
110 
111 /***************************************
112  ***************************************/
113 
114 int
main(int argc,char * argv[])115 main( int    argc,
116       char * argv[ ] )
117 {
118     FD_cursor *fd_cursor;
119 
120     fl_set_border_width( -2 );
121     fl_initialize( &argc, argv, "FormDemo", 0, 0 );
122     fd_cursor = create_form_cursor( );
123 
124     /* fill-in form initialization code */
125 
126     fl_set_cursor_color( XC_watch, FL_BLACK, FL_RED );
127 
128     animated = fl_create_animated_cursor( curs, 100 );
129 
130     fl_show_form( fd_cursor->cursor, FL_PLACE_CENTER, FL_FULLBORDER, "cursor" );
131 
132     fl_do_forms( );
133 
134     return 0;
135 }
136 
137 
138 /***************************************
139  ***************************************/
140 
141 FD_cursor *
create_form_cursor(void)142 create_form_cursor( void )
143 {
144     FL_OBJECT *obj;
145     FD_cursor *fdui = fl_calloc(1, sizeof *fdui );
146 
147     fdui->cursor = fl_bgn_form( FL_NO_BOX, 325, 175 );
148 
149     fl_add_box( FL_UP_BOX, 0 ,0, 325, 175, "" );
150     fl_add_frame( FL_EMBOSSED_FRAME, 10, 10, 305, 120, "" );
151 
152     obj = fl_add_button( FL_NORMAL_BUTTON, 20, 20, 50, 25, "Hand" );
153     fl_set_object_callback( obj, setcursor_cb, XC_hand2 );
154 
155     obj = fl_add_button( FL_NORMAL_BUTTON, 70, 20, 50, 25, "Watch" );
156     fl_set_object_callback( obj, setcursor_cb, XC_watch );
157 
158     obj = fl_add_button( FL_NORMAL_BUTTON, 120, 20, 60, 25, "Invisible" );
159     fl_set_object_callback( obj, setcursor_cb, FL_INVISIBLE_CURSOR );
160 
161     obj = fl_add_button( FL_NORMAL_BUTTON, 180, 20, 62, 25, "Animated" );
162     fl_set_object_callback( obj, setanimatedcursor_cb, 0 );
163 
164     obj = fl_add_button( FL_NORMAL_BUTTON, 242, 20, 62, 25, "BitmapCur" );
165     fl_set_object_callback( obj, setbitmapcursor_cb, 0 );
166 
167     obj = fl_add_button( FL_NORMAL_BUTTON, 90, 70, 140, 50, "DefaultCursor" );
168     fl_set_button_shortcut( obj, "Dd#d", 1);
169     fl_set_object_callback( obj, setcursor_cb, FL_DEFAULT_CURSOR );
170 
171     obj = fl_add_button( FL_NORMAL_BUTTON, 250, 140, 60, 25, "Done" );
172     fl_set_object_callback( obj, done_cb, 0 );
173 
174     fl_end_form( );
175 
176     fl_adjust_form_size( fdui->cursor );
177 
178     return fdui;
179 }
180 
181 
182 /*
183  * Local variables:
184  * tab-width: 4
185  * indent-tabs-mode: nil
186  * End:
187  */
188