1 /***************************************************************************** 2 Major portions of this software are copyrighted by the Medical College 3 of Wisconsin, 1994-2000, and are released under the Gnu General Public 4 License, Version 2. See the file README.Copyright for details. 5 ******************************************************************************/ 6 7 #ifndef _MCW_XUTIL_HEADER_ 8 #define _MCW_XUTIL_HEADER_ 9 10 #include <X11/X.h> 11 #include <X11/Intrinsic.h> 12 #include <X11/IntrinsicP.h> 13 #include <X11/cursorfont.h> 14 #include <Xm/XmAll.h> 15 16 #include <stdio.h> 17 #include <string.h> 18 #include <math.h> 19 #include <stdlib.h> 20 #include "machdep.h" 21 22 #include "mcw_malloc.h" 23 #include "afni_environ.h" 24 #include "display.h" 25 26 #ifdef __cplusplus 27 extern "C" { /* care of Greg Balls 7 Aug 2006 [rickr] */ 28 #endif 29 30 #ifndef MAX 31 # define MAX(a,b) (((a)<(b)) ? (b) : (a)) 32 # define MIN(a,b) (((a)>(b)) ? (b) : (a)) 33 #endif 34 35 #ifndef myXtFree 36 #define myXtFree(xp) (XtFree((char *)(xp)) , (xp)=NULL) 37 #endif 38 39 #ifndef myXtNew 40 #define myXtNew(type) ((type *) XtCalloc(1,(unsigned) sizeof(type))) 41 #endif 42 43 #define SENSITIZE(w,sen) \ 44 do{ RwcBoolean fred = (RwcBoolean) sen ; \ 45 if(w != NULL){ \ 46 int exp = (XtIsSensitive(w) != fred) ; \ 47 XtSetSensitive(w,fred) ; \ 48 if(exp) MCW_expose_widget(w) ; break ; } } while(0) 49 50 #define SAVEUNDERIZE(w) XtVaSetValues((w),XmNsaveUnder,True,NULL) /* 27 Feb 2001 */ 51 52 #define TEAROFFIZE(w) XtVaSetValues((w),XmNtearOffModel,XmTEAR_OFF_ENABLED ,NULL) 53 #define UNTEAROFFIZE(w) XtVaSetValues((w),XmNtearOffModel,XmTEAR_OFF_DISABLED,NULL) 54 55 extern void MCW_expose_widget( Widget ) ; 56 extern void MCW_invert_widget( Widget ) ; 57 extern void MCW_invert_widget_sync( Widget w , int sync) ; 58 extern void MCW_flash_widget ( int , Widget ) ; 59 extern void MCW_set_widget_bg( Widget , char * , Pixel ) ; 60 extern void MCW_set_widget_fg( Widget , char * ) ; 61 extern void MCW_scale_widget_bg( Widget w , float fac , MCW_DC *dc ) ; /* 18 Feb 2014 */ 62 63 #define BLACK_AND_WHITE_WIDGET(www) \ 64 do{ MCW_set_widget_bg( (www) , "black" , 0 ) ; \ 65 MCW_set_widget_fg( (www) , "#ffddbb" ) ; } while(0) 66 67 #undef LABELIZE 68 #define LABELIZE(w) \ 69 do{ char *eee ; \ 70 eee = getenv("AFNI_LABEL_BG") ; \ 71 if( eee != NULL ) MCW_set_widget_bg((w),eee,0) ; \ 72 eee = getenv("AFNI_LABEL_FG") ; \ 73 if( eee != NULL ) MCW_set_widget_fg((w),eee) ; \ 74 } while(0) 75 76 /** #include <stdarg.h> **/ 77 extern void MCW_flash_widget_list( int ntime , ... ) ; 78 79 extern Colormap MCW_get_colormap( Widget ) ; /* 01 Sep 1998 */ 80 extern void MCW_set_colormap( Widget , Colormap ) ; /* 14 Sep 1998 */ 81 extern int MCW_get_depth( Widget ) ; 82 extern Visual * MCW_get_visual( Widget ) ; 83 84 extern void MCW_set_widget_cursor( Widget,int ) ; 85 extern void MCW_alter_widget_cursor( Widget,int , char * , char * ) ; 86 87 extern void RWC_sleep( int ) ; /* 16 Aug 2002 */ 88 89 #define WAIT_for_window(w) \ 90 do{ XSync( XtDisplay(w) , False ) ; \ 91 while( XtWindow(w) == (Window) NULL ) ; /* spin */ \ 92 XSync( XtDisplay(w) , False ) ; \ 93 RWC_sleep(3) ; \ 94 } while(0) 95 96 #define POPUP_cursorize(w) \ 97 do{ if( (w) != (Widget)NULL && XtWindow(w) != (Window)NULL ) \ 98 MCW_alter_widget_cursor( (w), -XC_left_ptr,"yellow","blue" ); \ 99 } while(0) 100 101 #define NORMAL_cursorize(w) \ 102 do{ if( (w) != (Widget)NULL && XtWindow(w) != (Window)NULL ) \ 103 MCW_alter_widget_cursor( (w), -XC_top_left_arrow,"#ffb700","blue" ) ; \ 104 } while(0) 105 106 #define WATCH_cursorize(w) \ 107 do{ if( (w) != (Widget)NULL && XtWindow(w) != (Window)NULL ) \ 108 MCW_set_widget_cursor( (w) , -XC_watch ) ; \ 109 } while(0) 110 111 #define HAND_cursorize(w) \ 112 do{ if( (w) != (Widget)NULL && XtWindow(w) != (Window)NULL ) \ 113 MCW_set_widget_cursor( (w) , -XC_hand2 ) ; \ 114 } while(0) 115 116 #define PENCIL_cursorize(w) \ 117 do{ if( (w) != (Widget)NULL && XtWindow(w) != (Window)NULL ) \ 118 MCW_set_widget_cursor( (w) , -XC_pencil ) ; \ 119 } while(0) 120 121 #define CROSSHAIR_cursorize(w) \ 122 do{ if( (w) != (Widget)NULL && XtWindow(w) != (Window)NULL ) \ 123 MCW_set_widget_cursor( (w) , -XC_crosshair ) ; \ 124 } while(0) 125 126 extern void MCW_register_hint( Widget , char * ) ; 127 extern void MCW_reghint_children( Widget , char * ) ; 128 extern void MCW_hint_toggle(void) ; 129 130 extern void MCW_disable_help(void) ; /* 02 Aug 1999 */ 131 extern void MCW_enable_help (void) ; 132 133 extern void MCW_click_help_CB( Widget , XtPointer , XtPointer ) ; 134 extern void MCW_register_help( Widget , char * ) ; 135 extern void MCW_reghelp_children( Widget , char * ) ; 136 extern void MCW_help_CB( Widget , XtPointer , XtPointer ) ; 137 extern void MCW_unhelp_CB( Widget , XtPointer , XtPointer ) ; 138 139 extern void MCW_unregister_help( Widget ) ; /* 24 Apr 2001 */ 140 extern void MCW_unregister_hint( Widget ) ; /* 11 Jul 2001 */ 141 142 extern void MCW_set_widget_label( Widget , char * ) ; 143 extern void MCW_widget_geom( Widget , int * , int * , int * , int * ) ; 144 extern void MCW_discard_events( Widget , int ) ; 145 extern void MCW_discard_events_all( Widget , int ) ; 146 147 #if 0 148 extern void MCW_set_widget_label_tagged( Widget , char * , char *) ; 149 #endif 150 151 typedef struct { 152 char * label ; /* label for button */ 153 XtCallbackProc func_CB ; /* callback procedure */ 154 XtPointer data ; /* data for func_CB */ 155 char * help_text ; /* for MCW_register_help */ 156 char * hint_text ; /* for MCW_register_hint */ 157 int make_red ; /* nonzero for red button */ 158 159 XtPointer parent , aux ; 160 } MCW_action_item ; 161 162 extern char * MCW_hotcolor(Widget w) ; /* 01 Nov 1999 */ 163 extern char * MCW_buthighlight(Widget w) ; /* 04 March 2015 */ 164 165 extern Widget MCW_action_area( Widget , MCW_action_item * , int ) ; 166 167 #define MCW_CALLER_KILL 1 168 #define MCW_USER_KILL 2 169 #define MCW_TIMER_KILL (1<<10) 170 #define MCW_QUICK_KILL (1<<11) 171 172 extern Widget MCW_popup_message( Widget , char * , int ) ; 173 extern void MCW_message_CB( Widget , XtPointer , XtPointer ) ; 174 extern void MCW_message_timer_CB( XtPointer , XtIntervalId * ) ; 175 176 extern void MCW_message_alter( Widget , char * ) ; /* 10 Jul 2001 */ 177 178 extern void MCW_popup_message_once( Widget w, char *msg, char *expiry, char *codestring ) ; 179 180 #define MCW_nofile 0 181 #define MCW_readonly 1 182 #define MCW_readwrite 2 183 184 extern int MCW_filetype( char * ) ; 185 186 #if 0 187 extern RwcBoolean MCW_isitmwm( Widget ) ; 188 #else 189 #define MCW_isitmwm(ww) (!AFNI_noenv("AFNI_X11_REDECORATE")) 190 #endif 191 192 #define METER_TOP 1 193 #define METER_TOP_WIDE 2 194 #define METER_BOT 3 195 #define METER_BOT_WIDE 4 196 197 extern Widget MCW_popup_meter( Widget , int ) ; 198 extern void MCW_popdown_meter( Widget ) ; 199 extern void MCW_set_meter( Widget , int ) ; 200 201 extern int MCW_widget_visible( Widget w ) ; /* 03 Jan 1999 */ 202 203 extern char * RWC_getname( Display * , char * ) ; /* 04 Jun 1999 */ 204 205 /*------------------------------------------------------------------------*/ 206 207 #define TEXT_READONLY 1 208 #define TEXT_EDITABLE 2 209 210 #ifndef VOID_FUNC 211 #define VOID_FUNC 212 typedef void void_func() ; 213 #endif 214 215 typedef struct { 216 Widget wshell , wtop , wactar , wscroll , wtext ; 217 void_func *kill_func ; 218 XtPointer kill_data ; 219 int shell_width , shell_height ; 220 } MCW_textwin ; 221 222 extern MCW_textwin * new_MCW_textwin( Widget, char *, int ) ; 223 extern void MCW_textwin_CB( Widget , XtPointer , XtPointer ) ; 224 extern void MCW_textwinkill_CB( Widget , XtPointer , XtPointer ) ; 225 extern void MCW_textwin_setbig( int b ) ; /* 29 Apr 2009 */ 226 227 extern void MCW_textwin_alter( MCW_textwin * , char * ) ; /* 10 Jul 2001 */ 228 extern MCW_textwin * new_MCW_textwin_2001(Widget,char *,int,void_func *,XtPointer); 229 230 typedef struct { 231 Widget wshell , wtop , wactar , wframe , whtml ; 232 void_func *kill_func ; 233 XtPointer kill_data ; 234 int shell_width , shell_height ; 235 } MCW_htmlwin ; 236 237 extern MCW_htmlwin * new_MCW_htmlwin( Widget wpar , char *msg , 238 void_func *kill_func , XtPointer kill_data, 239 MCW_action_item *umai, int nact ) ; 240 extern void MCW_htmlwin_alter( MCW_htmlwin *hw , char *mmm ) ; 241 242 extern char * convert_text_to_html( char *txt ) ; /* 06 May 2015 */ 243 244 extern void RWC_visibilize_widget( Widget ) ; /* 09 Nov 1999 */ 245 246 #define RWC_visibilize RWC_visibilize_widget /* 27 Sep 2000: sometimes I forget */ 247 248 extern void RWC_xineramize( Display *, /* 27 Sep 2000 */ 249 int,int,int,int, int *, int * ) ; 250 251 extern void RWC_visibilize_CB( Widget , XtPointer , XtPointer ) ; /* 27 Sep 2000 */ 252 253 #define VISIBILIZE_WHEN_MAPPED(w) \ 254 XtAddCallback(w,XmNmapCallback,RWC_visibilize_CB,NULL) 255 256 extern void MCW_manage_widgets ( Widget * , int ) ; /* 24 Apr 2001 */ 257 extern void MCW_unmanage_widgets( Widget * , int ) ; 258 259 void RWC_destroy_nullify ( Widget, void ** ) ; /* 31 Jul 2001 */ 260 void RWC_destroy_nullify_cancel( Widget, void ** ) ; 261 262 #define NULLIFY_ON_DESTROY(pp,ww) RWC_destroy_nullify((ww),(void **)&(pp)) 263 #define CANCEL_NULLIFY_ON_DESTROY(pp,ww) RWC_destroy_nullify_cancel((ww),(void **)&(pp)) 264 265 /* invert the managed status of a widget */ 266 267 #define INVERT_manage(w) \ 268 do{ if( XtIsManaged(w) ) XtUnmanageChild(w); \ 269 else XtManageChild(w); } while(0) /* 21 Sep 2001 */ 270 271 extern void RWC_drag_rectangle( Widget, int,int, int *,int * ) ; /* 12 Jun 2002 */ 272 273 extern void RWC_XtPopdown( Widget ) ; /* 30 Jun 2003 */ 274 275 extern void AFNI_speak( char *string , int nofork ) ; /* 24 Nov 2003 */ 276 extern void AFNI_speak_setvoice( char *vvv ) ; 277 extern void AFNI_startup_sound(int nnn) ; /* 17 Aug 2018 */ 278 279 #ifdef DONT_USE_XTDESTROY /** bug fix for some stupid X11 distributions **/ 280 # undef XtDestroyWidget 281 # define XtDestroyWidget XtUnrealizeWidget 282 #endif 283 284 extern void MCW_melt_widget( Widget w ) ; 285 286 /* The next two funcs are now in xdraw.c [30 Aug 2021] */ 287 288 /* Replacement for XDrawLines, now with chocolate sprinkles [28 May 2020] */ 289 void AFNI_XDrawLines( Display *display, Drawable d, GC gc, 290 XPoint *points, int npoints, int mode, int nupsam ) ; 291 292 /* Replacement for XFillPolygon, with champagne truffles [01 Jun 2020] */ 293 void AFNI_XFillPolygon( Display *display, Drawable d, 294 GC gc, XPoint *points, int npoints, int shape, 295 int mode, int nupsam ) ; 296 297 #define AFNI_REPLACE_XDRAWLINES memplot_XDrawLines_set_substitute(AFNI_XDrawLines) 298 #define AFNI_RESTORE_XDRAWLINES memplot_XDrawLines_set_substitute(NULL) 299 300 #ifdef __cplusplus 301 } 302 #endif 303 304 extern char * get_XQuartz_version(void) ; /* 27 Jan 2017 */ 305 306 #endif /* _MCW_XUTIL_HEADER_ */ 307