PageRenderTime 62ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/Utilities/ipPic/annotation/Annotation.c

https://github.com/cim-unito/MITK
C | 379 lines | 300 code | 53 blank | 26 comment | 12 complexity | 6a019019301bf8c5afadca292ecd998d MD5 | raw file
  1. /*
  2. * Annotation.c
  3. *---------------------------------------------------------------
  4. * DESCRIPTION
  5. * the annotation widget methods
  6. *
  7. * Author
  8. * a.schroeter
  9. *
  10. *---------------------------------------------------------------
  11. * COPYRIGHT (c) 1993 by DKFZ (Dept. MBI) Heidelberg, FRG
  12. */
  13. #ifndef lint
  14. static char *what = { "@(#)XipAnnotationWidget\tDKFZ (Dept. MBI)\t1993/09/17" };
  15. #endif
  16. #include <X11/StringDefs.h>
  17. #include <X11/cursorfont.h>
  18. #include "AnnotationP.h"
  19. #include "icon_text.xbm"
  20. #ifdef SHAPE
  21. #include <X11/extensions/shape.h>
  22. #endif
  23. static void Initialize();
  24. static void Realize();
  25. static void Redisplay();
  26. static void Resize();
  27. static XtGeometryResult QueryGeometry();
  28. static void Destroy();
  29. static Boolean SetValues();
  30. static void activate();
  31. static void getDrawGC();
  32. static XtResource resources[] =
  33. {
  34. { XipNactivateCallback, XtCCallback, XtRCallback,
  35. sizeof(XtPointer),
  36. XtOffset (XipAnnotationWidget, annotation.activate_CB),
  37. XtRCallback, NULL },
  38. /* change parent class defaults */
  39. { XmNtopShadowColor, XmCTopShadowColor, XmRPixel,
  40. sizeof(Pixel),
  41. XtOffset(XipAnnotationWidget, primitive.top_shadow_color),
  42. XtRString, "black" },
  43. { XmNbottomShadowColor, XmCBottomShadowColor, XmRPixel,
  44. sizeof(Pixel),
  45. XtOffset(XipAnnotationWidget, primitive.bottom_shadow_color),
  46. XtRString, "black" },
  47. { XmNbackground, XmCBackground, XmRPixel,
  48. sizeof(Pixel),
  49. XtOffset(XipAnnotationWidget, core.background_pixel),
  50. XtRString, "Yellow" },
  51. { XmNtraversalOn, XmCTraversalOn, XmRBoolean,
  52. sizeof(Boolean),
  53. XtOffset (XipAnnotationWidget, primitive.traversal_on),
  54. XmRImmediate, (XtPointer)False },
  55. };
  56. static char defaultTranslations[] =
  57. " <Btn1Down>: activate()\n\
  58. ";
  59. static XtActionsRec actions[] =
  60. {
  61. { "activate", (XtActionProc)activate },
  62. };
  63. XipAnnotationClassRec xipAnnotationClassRec =
  64. {
  65. { /* core_class fields */
  66. (WidgetClass)&xmPrimitiveClassRec, /* superclass */
  67. "XipAnnotation", /* class_name */
  68. sizeof(XipAnnotationRec), /* widget_size */
  69. NULL, /* class_initialize */
  70. NULL, /* class_part_initialize */
  71. False, /* class_inited */
  72. Initialize, /* initialize */
  73. NULL, /* initialize_hook */
  74. Realize, /* realize */
  75. /*XtInheritRealize, /* realize */
  76. actions, /* actions */
  77. XtNumber(actions), /* num_actions */
  78. resources, /* resources */
  79. XtNumber(resources), /* num_resources */
  80. NULLQUARK, /* xrm_class */
  81. True, /* compress_motion */
  82. False, /* compress_exposure */
  83. True, /* compress_enterleave */
  84. False, /* visible_interest */
  85. Destroy, /* destroy */
  86. Resize, /* resize */
  87. Redisplay, /* expose */
  88. SetValues, /* set_values */
  89. NULL, /* set_values_hook */
  90. XtInheritSetValuesAlmost, /* set_values_almost */
  91. NULL, /* get_values_hook */
  92. NULL, /* accept_focus */
  93. XtVersion, /* version */
  94. NULL, /* callback private */
  95. defaultTranslations, /* tm_table */
  96. QueryGeometry, /* query_geometry */
  97. XtInheritDisplayAccelerator, /* display_accelerator */
  98. NULL, /* extension */
  99. },
  100. { /* primitive_class fields */
  101. (XtWidgetProc)_XtInherit, /* border highlight */
  102. (XtWidgetProc)_XtInherit, /* border unhiglight */
  103. XtInheritTranslations, /* translations */
  104. NULL, /* arm_and_activate */
  105. NULL, /* syn resources */
  106. 0, /* num_sysresources */
  107. NULL, /* extensions */
  108. },
  109. { /* annotation_class fields */
  110. 0, /* extension */
  111. },
  112. };
  113. WidgetClass xipAnnotationWidgetClass = (WidgetClass) &xipAnnotationClassRec;
  114. static void Initialize( request, new, args, num_args )
  115. XipAnnotationWidget request, new;
  116. ArgList args;
  117. Cardinal *num_args;
  118. {
  119. /*printf( "init\n" );*/
  120. getDrawGC( new );
  121. new->annotation.cursor = XCreateFontCursor( XtDisplay(new),
  122. XC_hand1 );
  123. new->annotation.icon_text = 0;
  124. if( request->core.width == 0 )
  125. new->core.width = 25;
  126. if( request->core.height == 0 )
  127. new->core.height = 30;
  128. }
  129. static void getDrawGC( w )
  130. XipAnnotationWidget w;
  131. {
  132. XGCValues values;
  133. XtGCMask valueMask;
  134. values.foreground = w->primitive.foreground;
  135. values.background = w->core.background_pixel;
  136. valueMask = GCForeground | GCBackground;
  137. w->annotation.draw_GC = XtGetGC ( (Widget)w, valueMask, &values );
  138. }
  139. static void Realize( w, valueMask, attributes )
  140. XipAnnotationWidget w;
  141. Mask *valueMask;
  142. XSetWindowAttributes *attributes;
  143. {
  144. /*(*xipAnnotationClassRec.core_class.superclass->core_class.realize)
  145. (w, valueMask, attributes);*/
  146. XtCreateWindow( (Widget)w,
  147. InputOutput,
  148. CopyFromParent,
  149. *valueMask,
  150. attributes);
  151. #ifdef SHAPE
  152. {
  153. GC shape_gc;
  154. Pixmap shape_mask;
  155. XGCValues xgcv;
  156. shape_mask = XCreatePixmap( XtDisplay(w),
  157. XtWindow(w),
  158. w->core.width,
  159. w->core.height,
  160. 1 );
  161. shape_gc = XCreateGC( XtDisplay(w),
  162. shape_mask,
  163. 0,
  164. &xgcv);
  165. XSetForeground( XtDisplay(w),
  166. shape_gc,
  167. 0);
  168. XFillRectangle( XtDisplay(w),
  169. shape_mask,
  170. shape_gc,
  171. 0, 0,
  172. w->core.width, w->core.height );
  173. XSetForeground( XtDisplay(w),
  174. shape_gc,
  175. 1);
  176. XFillRectangle( XtDisplay(w),
  177. shape_mask,
  178. shape_gc,
  179. 1, 1,
  180. w->core.width-4, w->core.height-4 );
  181. XSetForeground( XtDisplay(w),
  182. shape_gc,
  183. 0);
  184. {
  185. int i;
  186. for( i = 0; i < w->core.width/6; i++ )
  187. XDrawLine( XtDisplay(w),
  188. shape_mask,
  189. shape_gc,
  190. w->core.width-4-i, w->core.height-4,
  191. w->core.width-4, w->core.height-4-i );
  192. XDrawLine( XtDisplay(w),
  193. shape_mask,
  194. shape_gc,
  195. w->core.width-4-i, w->core.height-4-i,
  196. w->core.width-4-i, w->core.height-4 );
  197. XDrawLine( XtDisplay(w),
  198. shape_mask,
  199. shape_gc,
  200. w->core.width-4-i, w->core.height-4-i,
  201. w->core.width-4, w->core.height-4-i );
  202. }
  203. XShapeCombineMask( XtDisplay(w),
  204. XtWindow(w),
  205. ShapeClip,
  206. 0, 0,
  207. shape_mask,
  208. ShapeSet);
  209. XSetForeground( XtDisplay(w),
  210. shape_gc,
  211. 0);
  212. XFillRectangle( XtDisplay(w),
  213. shape_mask,
  214. shape_gc,
  215. 0, 0,
  216. w->core.width, w->core.height );
  217. XSetForeground( XtDisplay(w),
  218. shape_gc,
  219. 1);
  220. XFillRectangle( XtDisplay(w),
  221. shape_mask,
  222. shape_gc,
  223. 0, 0,
  224. w->core.width-2, w->core.height-2 );
  225. XFillRectangle( XtDisplay(w),
  226. shape_mask,
  227. shape_gc,
  228. 2, 2,
  229. w->core.width-2, w->core.height-2 );
  230. XSetForeground( XtDisplay(w),
  231. shape_gc,
  232. 0);
  233. {
  234. int i;
  235. for( i = 0; i < w->core.width/6; i++ )
  236. XDrawLine( XtDisplay(w),
  237. shape_mask,
  238. shape_gc,
  239. w->core.width-1-i, w->core.height-1,
  240. w->core.width-1, w->core.height-1-i );
  241. }
  242. XShapeCombineMask( XtDisplay(w),
  243. XtWindow(w),
  244. ShapeBounding,
  245. 0, 0,
  246. shape_mask,
  247. ShapeSet);
  248. XFreePixmap( XtDisplay(w),
  249. shape_mask );
  250. }
  251. #endif
  252. XDefineCursor( XtDisplay(w),
  253. XtWindow(w),
  254. w->annotation.cursor );
  255. }
  256. static XtGeometryResult QueryGeometry( w, proposed, answer )
  257. XipAnnotationWidget w;
  258. XtWidgetGeometry *proposed;
  259. XtWidgetGeometry *answer;
  260. {
  261. answer->width = (Dimension)256;
  262. answer->height = (Dimension)120;
  263. answer->request_mode = CWWidth || CWHeight;
  264. return( XtGeometryAlmost );
  265. }
  266. static void Destroy( w )
  267. XipAnnotationWidget w;
  268. {
  269. XtReleaseGC( (Widget)w, w->annotation.draw_GC );
  270. XtRemoveAllCallbacks ( (Widget)w, XipNactivateCallback );
  271. }
  272. static void Resize( w )
  273. XipAnnotationWidget w;
  274. {
  275. /*if( w->core.width > w->annotation.image->width
  276. || w->core.height > w->annotation.image->height )
  277. XtWarning( "XipAnnotationWidget resized" );*/
  278. }
  279. static void Redisplay( w, event, region)
  280. XipAnnotationWidget w;
  281. XExposeEvent *event;
  282. Region region;
  283. {
  284. if( w->core.visible )
  285. {
  286. if( w->annotation.icon_text == 0 )
  287. w->annotation.icon_text = XCreateBitmapFromData( XtDisplay(w),
  288. XtWindow(w),
  289. icon_text_bits,
  290. icon_text_width,
  291. icon_text_height );
  292. XCopyPlane( XtDisplay(w),
  293. w->annotation.icon_text,
  294. XtWindow(w),
  295. w->annotation.draw_GC,
  296. 0, 0,
  297. icon_text_width, icon_text_height,
  298. 0, 0,
  299. 1 );
  300. /*XDrawLine( XtDisplay(w),
  301. XtWindow(w),
  302. w->annotation.draw_GC,
  303. 0, 0,
  304. 200, 200 );*/
  305. }
  306. }
  307. static Boolean SetValues( current, request, new, args, num_args )
  308. XipAnnotationWidget current, request, new;
  309. ArgList args;
  310. Cardinal *num_args;
  311. {
  312. Cardinal i;
  313. Boolean redraw = False;
  314. /*printf( "setv\n" );*/
  315. return( redraw );
  316. }
  317. static void activate( w, event )
  318. XipAnnotationWidget w;
  319. XEvent *event;
  320. {
  321. if( event->xbutton.x < w->core.width
  322. && event->xbutton.y < w->core.height )
  323. XtCallCallbacks( (Widget)w,
  324. XipNactivateCallback,
  325. (XtPointer) event );
  326. }