PageRenderTime 76ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Xw/Xw_set_soft_cursor.cxx

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