7fd59977 |
1 | |
2 | #include <Xw_Extension.h> |
3 | |
4 | /* ifdef then trace on */ |
5 | #ifdef TRACE |
6 | #define TRACE_SET_SOFT_CURSOR |
7 | #endif |
8 | |
9 | /* |
10 | XW_STATUS Xw_set_soft_cursor (awindow,type,button) |
11 | XW_EXT_WINDOW *awindow |
12 | XW_CURSORTYPE type |
13 | int button Mouse Button number (1 to 3) |
14 | |
15 | Associate the soft cursor to the window and a mouse button |
16 | Soft cursor is activated when Mouse Button is press |
17 | drawn when mouse move with button press |
18 | and Unactivated when Mouse Button is Release |
19 | |
20 | Returns XW_ERROR if button is out of range |
21 | Returns XW_SUCCESS if successful |
22 | |
23 | */ |
24 | |
25 | static int Start = False ; |
26 | static XPoint points[100] ; |
27 | |
28 | #ifdef XW_PROTOTYPE |
29 | static XW_STATUS Xw_rubberline_cursor(XW_EVENT *event) ; |
30 | static XW_STATUS Xw_rubberband_cursor(XW_EVENT *event) ; |
31 | static XW_STATUS Xw_userdefined_cursor(XW_EVENT *event) ; |
32 | static void DrawLines(XW_EXT_WINDOW *pwindow,XPoint *points,int npoint) ; |
33 | XW_STATUS Xw_set_soft_cursor (void *awindow,XW_CURSORTYPE type,int button) |
34 | #else |
35 | static XW_STATUS Xw_rubberline_cursor() ; |
36 | static XW_STATUS Xw_rubberband_cursor() ; |
37 | static XW_STATUS Xw_userdefined_cursor() ; |
38 | static void DrawLines() ; |
39 | XW_STATUS Xw_set_soft_cursor (awindow,type,button) |
40 | void *awindow ; |
41 | XW_CURSORTYPE type; |
42 | int button ; |
43 | #endif /*XW_PROTOTYPE*/ |
44 | { |
45 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ; |
46 | XW_STATUS status ; |
47 | XW_EVENTTYPE mask1=(XW_EVENTTYPE ) 0 ,mask2=(XW_EVENTTYPE ) 0 ; |
48 | |
49 | if( !Xw_isdefine_window(pwindow) ) { |
50 | /*ERROR*Bad EXT_WINDOW Address*/ |
51 | Xw_set_error(24,"Xw_set_soft_cursor",pwindow) ; |
52 | return (XW_ERROR) ; |
53 | } |
54 | |
55 | if( button <= 0 || button > 3 ) { |
56 | /*WARNING*Bad Mouse button number*/ |
57 | Xw_set_error(70,"Xw_set_soft_cursor",&button) ; |
58 | return (XW_ERROR) ; |
59 | } |
60 | |
61 | if( button == 1 ) { |
62 | mask1 = XW_MOUSEBUTTON1 ; mask2 = XW_MOUSEMOVEWITHBUTTON1 ; |
63 | } else if( button == 2 ) { |
64 | mask1 = XW_MOUSEBUTTON2 ; mask2 = XW_MOUSEMOVEWITHBUTTON2 ; |
65 | } else if( button == 3 ) { |
66 | mask1 = XW_MOUSEBUTTON3 ; mask2 = XW_MOUSEMOVEWITHBUTTON3 ; |
67 | } |
68 | |
69 | switch (type) { |
70 | |
71 | case XW_WITHOUT_CURSOR : |
72 | status = Xw_set_internal_event(pwindow,mask1,NULL) ; |
73 | status = Xw_set_internal_event(pwindow,mask2,NULL) ; |
74 | break ; |
75 | case XW_RUBBERLINE_CURSOR : |
76 | status = Xw_set_internal_event(pwindow,mask1, |
77 | Xw_rubberline_cursor) ; |
78 | status = Xw_set_internal_event(pwindow,mask2, |
79 | Xw_rubberline_cursor) ; |
80 | break ; |
81 | case XW_RUBBERBAND_CURSOR : |
82 | status = Xw_set_internal_event(pwindow,mask1, |
83 | Xw_rubberband_cursor) ; |
84 | status = Xw_set_internal_event(pwindow,mask2, |
85 | Xw_rubberband_cursor) ; |
86 | break ; |
87 | case XW_USERDEFINED_CURSOR : |
88 | status = Xw_set_internal_event(pwindow,mask1, |
89 | Xw_userdefined_cursor) ; |
90 | status = Xw_set_internal_event(pwindow,mask2, |
91 | Xw_userdefined_cursor) ; |
92 | break ; |
93 | #ifndef DEB |
94 | default: |
95 | break ; |
96 | #endif |
97 | } |
98 | |
99 | |
100 | #ifdef TRACE_SET_SOFT_CURSOR |
101 | if( Xw_get_trace() ) { |
102 | printf (" Xw_set_soft_cursor(%lx,%d,%d)\n",(long ) pwindow,type,button) ; |
103 | } |
104 | #endif |
105 | return (XW_SUCCESS); |
106 | |
107 | } |
108 | |
109 | #ifdef XW_PROTOTYPE |
110 | static XW_STATUS Xw_rubberline_cursor(XW_EVENT *event) |
111 | #else |
112 | static XW_STATUS Xw_rubberline_cursor(event) |
113 | XW_EVENT *event ; |
114 | #endif /*XW_PROTOTYPE*/ |
115 | { |
116 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) event->any.awindow ; |
117 | |
118 | #ifdef TRACE_SET_SOFT_CURSOR |
119 | if( Xw_get_trace() > 2 ) { |
120 | printf (" Xw_rubberline_cursor(%lx,%d)\n", |
121 | (long ) event->any.awindow,event->any.type) ; |
122 | } |
123 | #endif |
124 | |
125 | switch (event->any.type) { |
126 | |
127 | case XW_MOUSEBUTTON1 : |
128 | case XW_MOUSEBUTTON2 : |
129 | case XW_MOUSEBUTTON3 : |
130 | if( Start ) { |
131 | Start = False ; |
132 | DrawLines(pwindow,points,2) ; |
133 | } else { |
134 | points[0].x = event->mousebutton.x ; |
135 | points[0].y = event->mousebutton.y ; |
136 | } |
137 | break ; |
138 | |
139 | case XW_MOUSEMOVEWITHBUTTON1 : |
140 | case XW_MOUSEMOVEWITHBUTTON2 : |
141 | case XW_MOUSEMOVEWITHBUTTON3 : |
142 | if( Start ) { |
143 | DrawLines(pwindow,points,2) ; |
144 | } |
145 | Start = True ; |
146 | points[1].x = event->mousemovewithbutton.x - points[0].x ; |
147 | points[1].y = event->mousemovewithbutton.y - points[0].y ; |
148 | DrawLines(pwindow,points,2) ; |
149 | XFlush(_DISPLAY) ; |
150 | break ; |
151 | #ifndef DEB |
152 | default: |
153 | break ; |
154 | #endif |
155 | } |
156 | |
157 | return (XW_SUCCESS) ; |
158 | } |
159 | |
160 | #ifdef XW_PROTOTYPE |
161 | static XW_STATUS Xw_rubberband_cursor(XW_EVENT *event) |
162 | #else |
163 | static XW_STATUS Xw_rubberband_cursor(event) |
164 | XW_EVENT *event ; |
165 | #endif /*XW_PROTOTYPE*/ |
166 | { |
167 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) event->any.awindow ; |
168 | |
169 | #ifdef TRACE_SET_SOFT_CURSOR |
170 | if( Xw_get_trace() > 2 ) { |
171 | printf (" Xw_rubberband_cursor(%lx,%d)\n", |
172 | (long ) event->any.awindow,event->any.type) ; |
173 | } |
174 | #endif |
175 | |
176 | switch (event->any.type) { |
177 | |
178 | case XW_MOUSEBUTTON1 : |
179 | case XW_MOUSEBUTTON2 : |
180 | case XW_MOUSEBUTTON3 : |
181 | if( Start ) { |
182 | Start = False ; |
183 | DrawLines(pwindow,points,5) ; |
184 | } else { |
185 | points[0].x = event->mousebutton.x ; |
186 | points[0].y = event->mousebutton.y ; |
187 | } |
188 | break ; |
189 | |
190 | case XW_MOUSEMOVEWITHBUTTON1 : |
191 | case XW_MOUSEMOVEWITHBUTTON2 : |
192 | case XW_MOUSEMOVEWITHBUTTON3 : |
193 | if( Start ) { |
194 | DrawLines(pwindow,points,5) ; |
195 | } |
196 | Start = True ; |
197 | points[1].x = 0 ; |
198 | points[1].y = event->mousemovewithbutton.y - points[0].y ; |
199 | points[2].x = event->mousemovewithbutton.x - points[0].x ; |
200 | points[2].y = 0 ; |
201 | points[3].x = 0 ; |
202 | points[3].y = -points[1].y ; |
203 | points[4].x = -points[2].x ; |
204 | points[4].y = 0 ; |
205 | DrawLines(pwindow,points,5) ; |
206 | XFlush(_DISPLAY) ; |
207 | break ; |
208 | #ifndef DEB |
209 | default: |
210 | break ; |
211 | #endif |
212 | } |
213 | |
214 | return (XW_SUCCESS) ; |
215 | } |
216 | |
217 | #ifdef XW_PROTOTYPE |
218 | static XW_STATUS Xw_userdefined_cursor(XW_EVENT *event) |
219 | #else |
220 | static XW_STATUS Xw_userdefined_cursor(event) |
221 | XW_EVENT *event ; |
222 | #endif /*XW_PROTOTYPE*/ |
223 | { |
224 | #ifdef TRACE_SET_SOFT_CURSOR |
225 | if( Xw_get_trace() > 2 ) { |
226 | printf (" Xw_userdefined_cursor(%lx,%d)\n", |
227 | (long ) event->any.awindow,event->any.type) ; |
228 | } |
229 | #endif |
230 | Xw_set_error(97,"Xw_userdefined_cursor",&event->any.type) ; |
231 | |
232 | return (XW_SUCCESS) ; |
233 | } |
234 | |
235 | #ifdef XW_PROTOTYPE |
236 | static void DrawLines(XW_EXT_WINDOW *pwindow,XPoint *points,int npoint) |
237 | #else |
238 | static void DrawLines(pwindow,points,npoint) |
239 | XW_EXT_WINDOW *pwindow ; |
240 | XPoint *points ; |
241 | int npoint ; |
242 | #endif /*XW_PROTOTYPE*/ |
243 | { |
244 | XW_EXT_DISPLAY *pdisplay = pwindow->connexion ; |
245 | |
246 | if( _DGRAB ) { |
247 | int xs = points[0].x,ys = points[0].y ; |
248 | |
249 | points[0].x += _X ; points[0].y += _Y ; |
250 | XDrawLines(_DISPLAY,_DROOT,_DGC,points,npoint,CoordModePrevious) ; |
251 | points[0].x = xs ; points[0].y = ys ; |
252 | } else { |
253 | XDrawLines(_DISPLAY,_WINDOW,pwindow->qgwind.gchigh, |
254 | points,npoint,CoordModePrevious) ; |
255 | } |
256 | } |