Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef toolx_Xt_ImageArea 5 #define toolx_Xt_ImageArea 6 7 #include <X11/IntrinsicP.h> 8 #include <X11/CoreP.h> 9 #include <X11/CompositeP.h> 10 #include <X11/StringDefs.h> 11 12 //#define TOOLX_XT_IMAGEAREA_DEBUG 13 14 #ifdef TOOLX_XT_IMAGEAREA_DEBUG 15 #include <stdio.h> 16 #endif 17 18 namespace toolx { 19 namespace Xt { 20 21 /////////////////////////////////////////////////////////// 22 /////////////////////////////////////////////////////////// 23 /////////////////////////////////////////////////////////// 24 25 typedef struct _ImageAreaClassRec* ImageAreaWidgetClass; 26 typedef struct _ImageAreaRec* ImageAreaWidget; 27 28 /////////////////////////////////////////////////////////// 29 /////////////////////////////////////////////////////////// 30 /////////////////////////////////////////////////////////// 31 32 typedef struct { 33 void* extension; 34 } ImageAreaClassPart; 35 36 typedef struct _ImageAreaClassRec { 37 CoreClassPart core_class; 38 CompositeClassPart composite_class; 39 ImageAreaClassPart imageArea_class; 40 } ImageAreaClassRec; 41 42 typedef struct { 43 XtCallbackList resizeCallback; 44 XtCallbackList paintCallback; 45 XtCallbackList eventCallback; 46 } ImageAreaPart; 47 48 typedef struct _ImageAreaRec { 49 CorePart core; 50 CompositePart composite; 51 ImageAreaPart imageArea; 52 } ImageAreaRec; 53 54 /////////////////////////////////////////////////////////// 55 /////////////////////////////////////////////////////////// 56 /////////////////////////////////////////////////////////// 57 58 class ImageArea { 59 protected: 60 static const char* class_name() {static const char* s_s = "ImageArea";return s_s;} 61 public: 62 typedef struct { 63 int reason; 64 XEvent* event; 65 } XoAnyCallbackStruct; 66 67 static int XoCR_RESIZE() {return 1;} 68 static int XoCR_PAINT() {return 2;} 69 static int XoCR_EVENT() {return 3;} 70 71 static const char* XoN_resizeCallback() {static const char* s_s = "resizeCallback";return s_s;} 72 static const char* XoN_paintCallback() {static const char* s_s = "paintCallback";return s_s;} 73 static const char* XoN_eventCallback() {static const char* s_s = "eventCallback";return s_s;} 74 public: 75 static void paint(Widget a_this) { 76 if(!XtIsRealized(a_this)) return; 77 XoAnyCallbackStruct value; 78 value.reason = XoCR_PAINT(); 79 value.event = 0; 80 ::XtCallCallbacks(a_this,XoN_paintCallback(),(XtPointer)&value); 81 } 82 protected: 83 static void initialize_class(void) { 84 #ifdef TOOLX_XT_IMAGEAREA_DEBUG 85 ::printf("debug: toolx::Xt::ImageArea: initialize_class.\n"); 86 #endif 87 } 88 89 static void initialize_widget(Widget a_request,Widget a_this,ArgList,Cardinal*) { 90 if(a_request->core.width<=0) a_this->core.width = 100; 91 if(a_request->core.height<=0) a_this->core.height = 100; 92 93 #ifdef TOOLX_XT_IMAGEAREA_DEBUG 94 ::printf("debug: toolx::Xt::ImageArea: initialize_widget: %s\n",::XtName(a_this)); 95 #endif 96 97 ::XtAddEventHandler 98 (a_this,ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|KeyPressMask|KeyReleaseMask,0,event_handler,NULL); 99 100 #ifdef TOOLX_XT_IMAGEAREA_DEBUG 101 ::printf("debug: toolx::Xt::ImageArea: initialize_widget: end\n"); 102 #endif 103 } 104 105 static void destroy_widget(Widget) { 106 #ifdef TOOLX_XT_IMAGEAREA_DEBUG 107 ::printf("debug: toolx::Xt::ImageArea: destroy_widget.\n"); 108 #endif 109 } 110 111 static void change_widget_size(Widget a_this) { 112 #ifdef TOOLX_XT_IMAGEAREA_DEBUG 113 ::printf("debug: toolx::Xt::ImageArea: change_widget_size: %s\n",XtName(a_this)); 114 #endif 115 116 if(widget_class()->core_class.superclass->core_class.resize!=NULL) 117 (widget_class()->core_class.superclass->core_class.resize)(a_this); 118 119 XoAnyCallbackStruct value; 120 value.reason = XoCR_RESIZE(); 121 value.event = 0; 122 ::XtCallCallbacks(a_this,XoN_resizeCallback(),(XtPointer)&value); 123 124 #ifdef TOOLX_XT_IMAGEAREA_DEBUG 125 ::printf("debug: toolx::Xt::ImageArea: change_widget_size: end\n"); 126 #endif 127 } 128 129 static void draw_widget(Widget a_this,XEvent* a_event,Region a_region) { 130 #ifdef TOOLX_XT_IMAGEAREA_DEBUG 131 ::printf("debug: toolx::Xt::ImageArea: draw_widget: %s\n",XtName(a_this)); 132 #endif 133 134 if(widget_class()->core_class.superclass->core_class.expose!=NULL) 135 (widget_class()->core_class.superclass->core_class.expose)(a_this,a_event,a_region); 136 137 XoAnyCallbackStruct value; 138 value.reason = XoCR_PAINT(); 139 value.event = a_event; 140 ::XtCallCallbacks(a_this,XoN_paintCallback(),(XtPointer)&value); 141 142 #ifdef TOOLX_XT_IMAGEAREA_DEBUG 143 ::printf("debug: toolx::Xt::ImageArea: draw_widget: end\n"); 144 #endif 145 } 146 147 protected: 148 static void event_handler(Widget a_this,XtPointer,XEvent* a_event ,Boolean*) { 149 XoAnyCallbackStruct value; 150 value.reason = XoCR_EVENT(); 151 value.event = a_event; 152 ::XtCallCallbacks(a_this,XoN_eventCallback(),(XtPointer)&value); 153 } 154 155 public: 156 static WidgetClass widget_class() { 157 static XtResource s_resources[] = { 158 {(String)XoN_resizeCallback(),XtCCallback,XtRCallback,sizeof(XtCallbackList), 159 XtOffset(ImageAreaWidget,imageArea.resizeCallback),XtRImmediate,(XtPointer)NULL}, 160 {(String)XoN_paintCallback(),XtCCallback,XtRCallback,sizeof(XtCallbackList), 161 XtOffset(ImageAreaWidget,imageArea.paintCallback),XtRImmediate,(XtPointer)NULL}, 162 {(String)XoN_eventCallback(),XtCCallback,XtRCallback,sizeof(XtCallbackList), 163 XtOffset(ImageAreaWidget,imageArea.eventCallback),XtRImmediate,(XtPointer)NULL} 164 }; 165 166 static ImageAreaClassRec s_imageAreaClassRec = { 167 // Core Class Part : 168 { 169 (WidgetClass) &compositeClassRec, // pointer to superclass ClassRec 170 (String)class_name(), // widget resource class name 171 sizeof(ImageAreaRec), // size in bytes of widget record 172 initialize_class, // class_initialize 173 NULL, // dynamic initialization 174 FALSE, // has class been initialized? 175 initialize_widget, // initialize 176 NULL, // notify that initialize called 177 XtInheritRealize, // XCreateWindow for widget 178 NULL, // widget semantics name to proc mapWidget 179 0, // number of entries in actions 180 s_resources, // resources for subclass fields 181 XtNumber(s_resources), // number of entries in resources 182 NULLQUARK, // resource class quarkified 183 TRUE, // compress MotionNotify for widget 184 TRUE, // compress Expose events for widget 185 TRUE, // compress enter and leave events 186 TRUE, // select for VisibilityNotify 187 destroy_widget, // free data for subclass pointers 188 change_widget_size, // geom manager changed widget size 189 draw_widget, // rediplay window 190 NULL, // set subclass resource values 191 NULL, // notify that SetValues called 192 XtInheritSetValuesAlmost, // SetValues got "Almost" geo reply 193 NULL, // notify that get_values called 194 XtInheritAcceptFocus, // assign input focus to widget 195 XtVersion, // version of intrinsics used 196 NULL, // list of callback offsets 197 XtInheritTranslations, // translations 198 XtInheritQueryGeometry, // return preferred geometry 199 XtInheritDisplayAccelerator, // display your accelerator 200 NULL // pointer to extension record 201 }, 202 // Composite Class Part : 203 { 204 XtInheritGeometryManager, // geometry manager for children 205 XtInheritChangeManaged, // change managed state of child 206 XtInheritInsertChild, // physically add child to parent 207 XtInheritDeleteChild, // physically remove child 208 NULL // pointer to extension record 209 }, 210 // ImageArea : 211 { 212 NULL 213 } 214 }; 215 return (WidgetClass)&s_imageAreaClassRec; 216 } 217 }; 218 219 }} 220 221 222 #endif