summaryrefslogtreecommitdiff
path: root/src/Xw/Xw_set_soft_cursor.cxx
blob: c1102cc3928496ec4d163e767ca70b9ff593170c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

#include <Xw_Extension.h>

	/* ifdef then trace on */
#ifdef TRACE
#define TRACE_SET_SOFT_CURSOR
#endif

/*
   XW_STATUS Xw_set_soft_cursor (awindow,type,button)
	XW_EXT_WINDOW 	*awindow	
	XW_CURSORTYPE	type	
	int		button		Mouse Button number (1 to 3)

	Associate the soft cursor to the window and a mouse button
	Soft cursor is activated when Mouse Button is press
		    drawn when mouse move with button press
		    and Unactivated when Mouse Button is Release

	Returns XW_ERROR if button is out of range
	Returns XW_SUCCESS if successful

*/

static int Start = False ;
static XPoint points[100] ;

#ifdef XW_PROTOTYPE
static XW_STATUS Xw_rubberline_cursor(XW_EVENT *event) ;
static XW_STATUS Xw_rubberband_cursor(XW_EVENT *event) ;
static XW_STATUS Xw_userdefined_cursor(XW_EVENT *event) ;
static void DrawLines(XW_EXT_WINDOW *pwindow,XPoint *points,int npoint) ;
XW_STATUS Xw_set_soft_cursor (void *awindow,XW_CURSORTYPE type,int button)
#else
static XW_STATUS Xw_rubberline_cursor() ;
static XW_STATUS Xw_rubberband_cursor() ;
static XW_STATUS Xw_userdefined_cursor() ;
static void DrawLines() ;
XW_STATUS Xw_set_soft_cursor (awindow,type,button)
void *awindow ;
XW_CURSORTYPE type;
int button ;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
XW_EVENTTYPE mask1=(XW_EVENTTYPE ) 0 ,mask2=(XW_EVENTTYPE ) 0 ;

        if( !Xw_isdefine_window(pwindow) ) {
            /*ERROR*Bad EXT_WINDOW Address*/
            Xw_set_error(24,"Xw_set_soft_cursor",pwindow) ;
            return (XW_ERROR) ;
        }

	if( button <= 0 || button > 3 ) {
	    /*WARNING*Bad Mouse button number*/
	    Xw_set_error(70,"Xw_set_soft_cursor",&button) ;
	    return (XW_ERROR) ;
	}

	if( button == 1 ) {
	    mask1 = XW_MOUSEBUTTON1 ; mask2 = XW_MOUSEMOVEWITHBUTTON1 ;
	} else if( button == 2 ) {
	    mask1 = XW_MOUSEBUTTON2 ; mask2 = XW_MOUSEMOVEWITHBUTTON2 ;
	} else if( button == 3 ) {
	    mask1 = XW_MOUSEBUTTON3 ; mask2 = XW_MOUSEMOVEWITHBUTTON3 ;
	}

	switch (type) {

	    case XW_WITHOUT_CURSOR :
		Xw_set_internal_event(pwindow,mask1,NULL) ;
		Xw_set_internal_event(pwindow,mask2,NULL) ;
		break ;
	    case XW_RUBBERLINE_CURSOR :
		Xw_set_internal_event(pwindow,mask1,
							Xw_rubberline_cursor) ;
		Xw_set_internal_event(pwindow,mask2,
							Xw_rubberline_cursor) ;
		break ;
	    case XW_RUBBERBAND_CURSOR :
		Xw_set_internal_event(pwindow,mask1,
							Xw_rubberband_cursor) ;
		Xw_set_internal_event(pwindow,mask2,
							Xw_rubberband_cursor) ;
		break ;
	    case XW_USERDEFINED_CURSOR :
		Xw_set_internal_event(pwindow,mask1,
							Xw_userdefined_cursor) ;
		Xw_set_internal_event(pwindow,mask2,
							Xw_userdefined_cursor) ;
		break ;
#ifndef DEB
	default:
		break ;
#endif
   	}


#ifdef TRACE_SET_SOFT_CURSOR
if( Xw_get_trace() ) {
	printf (" Xw_set_soft_cursor(%lx,%d,%d)\n",(long ) pwindow,type,button) ;
}
#endif
	return (XW_SUCCESS);

}

#ifdef XW_PROTOTYPE
static XW_STATUS Xw_rubberline_cursor(XW_EVENT *event) 
#else
static XW_STATUS Xw_rubberline_cursor(event) 
XW_EVENT *event ;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) event->any.awindow ;

#ifdef TRACE_SET_SOFT_CURSOR
if( Xw_get_trace() > 2 ) {
	printf (" Xw_rubberline_cursor(%lx,%d)\n",
				(long ) event->any.awindow,event->any.type) ;
}
#endif

	switch (event->any.type) {

	    case XW_MOUSEBUTTON1 :
	    case XW_MOUSEBUTTON2 :
	    case XW_MOUSEBUTTON3 :
		if( Start ) {
		    Start = False ;
		    DrawLines(pwindow,points,2) ;
		} else {
		    points[0].x = event->mousebutton.x ;
		    points[0].y = event->mousebutton.y ;
		}
		break ;

	    case XW_MOUSEMOVEWITHBUTTON1 :
	    case XW_MOUSEMOVEWITHBUTTON2 :
	    case XW_MOUSEMOVEWITHBUTTON3 :
		if( Start ) {
		    DrawLines(pwindow,points,2) ;
		}
		Start = True ;
		points[1].x = event->mousemovewithbutton.x - points[0].x ;
		points[1].y = event->mousemovewithbutton.y - points[0].y ;
		DrawLines(pwindow,points,2) ;
		XFlush(_DISPLAY) ;
		break ;
#ifndef DEB
	default:
		break ;
#endif
	}

	return (XW_SUCCESS) ;
}

#ifdef XW_PROTOTYPE
static XW_STATUS Xw_rubberband_cursor(XW_EVENT *event) 
#else
static XW_STATUS Xw_rubberband_cursor(event) 
XW_EVENT *event ;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) event->any.awindow ;

#ifdef TRACE_SET_SOFT_CURSOR
if( Xw_get_trace() > 2 ) {
	printf (" Xw_rubberband_cursor(%lx,%d)\n",
				(long ) event->any.awindow,event->any.type) ;
}
#endif

	switch (event->any.type) {

	    case XW_MOUSEBUTTON1 :
	    case XW_MOUSEBUTTON2 :
	    case XW_MOUSEBUTTON3 :
		if( Start ) {
		    Start = False ;
		    DrawLines(pwindow,points,5) ;
		} else {
		    points[0].x = event->mousebutton.x ;
		    points[0].y = event->mousebutton.y ;
		}
		break ;

	    case XW_MOUSEMOVEWITHBUTTON1 :
	    case XW_MOUSEMOVEWITHBUTTON2 :
	    case XW_MOUSEMOVEWITHBUTTON3 :
		if( Start ) {
		    DrawLines(pwindow,points,5) ;
		}
		Start = True ;
		points[1].x = 0 ;
		points[1].y = event->mousemovewithbutton.y - points[0].y ;
		points[2].x = event->mousemovewithbutton.x - points[0].x ;
		points[2].y = 0 ;
		points[3].x = 0 ;
		points[3].y = -points[1].y ;
		points[4].x = -points[2].x ;
		points[4].y = 0 ;
		DrawLines(pwindow,points,5) ;
		XFlush(_DISPLAY) ;
		break ;
#ifndef DEB
	default:
		break ;
#endif
	}

	return (XW_SUCCESS) ;
}

#ifdef XW_PROTOTYPE
static XW_STATUS Xw_userdefined_cursor(XW_EVENT *event) 
#else
static XW_STATUS Xw_userdefined_cursor(event) 
XW_EVENT *event ;
#endif /*XW_PROTOTYPE*/
{
#ifdef TRACE_SET_SOFT_CURSOR
if( Xw_get_trace() > 2 ) {
	printf (" Xw_userdefined_cursor(%lx,%d)\n",
				(long ) event->any.awindow,event->any.type) ;
}
#endif
	Xw_set_error(97,"Xw_userdefined_cursor",&event->any.type) ;

	return (XW_SUCCESS) ;
}

#ifdef XW_PROTOTYPE
static void DrawLines(XW_EXT_WINDOW *pwindow,XPoint *points,int npoint)
#else
static void DrawLines(pwindow,points,npoint)
XW_EXT_WINDOW *pwindow ;
XPoint *points ;
int npoint ;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_DISPLAY *pdisplay = pwindow->connexion ;

    if( _DGRAB ) {
	int xs = points[0].x,ys = points[0].y ;

	points[0].x += _X ; points[0].y += _Y ;
        XDrawLines(_DISPLAY,_DROOT,_DGC,points,npoint,CoordModePrevious) ;
	points[0].x = xs ; points[0].y = ys ;
    } else {
        XDrawLines(_DISPLAY,_WINDOW,pwindow->qgwind.gchigh,
					points,npoint,CoordModePrevious) ;
    }
}