Back to index

plt-scheme  4.2.1
xwToggle.c
Go to the documentation of this file.
00001 /* Generated by wbuild
00002  * (generator version 3.2)
00003  */
00004 #include <X11/IntrinsicP.h>
00005 #include <X11/StringDefs.h>
00006 #include <xwTools3d.h>
00007 #include <xwTabString.h>
00008 #include <./xwToggleP.h>
00009 static void toggle(
00010 #if NeedFunctionPrototypes
00011 Widget,XEvent*,String*,Cardinal*
00012 #endif
00013 );
00014 static void switch_on(
00015 #if NeedFunctionPrototypes
00016 Widget,XEvent*,String*,Cardinal*
00017 #endif
00018 );
00019 static void switch_off(
00020 #if NeedFunctionPrototypes
00021 Widget,XEvent*,String*,Cardinal*
00022 #endif
00023 );
00024 
00025 static XtActionsRec actionsList[] = {
00026 {"toggle", toggle},
00027 {"switch_on", switch_on},
00028 {"switch_off", switch_off},
00029 };
00030 
00031 static char defaultTranslations[] = "\
00032 <Btn1Up>: toggle() \n\
00033 <Key>Return: toggle() \n\
00034 ";
00035 static void _resolve_inheritance(
00036 #if NeedFunctionPrototypes
00037 WidgetClass
00038 #endif
00039 );
00040 static void initialize(
00041 #if NeedFunctionPrototypes
00042 Widget ,Widget,ArgList ,Cardinal *
00043 #endif
00044 );
00045 static void destroy(
00046 #if NeedFunctionPrototypes
00047 Widget
00048 #endif
00049 );
00050 static void realize(
00051 #if NeedFunctionPrototypes
00052 Widget,XtValueMask *,XSetWindowAttributes *
00053 #endif
00054 );
00055 static Boolean  set_values(
00056 #if NeedFunctionPrototypes
00057 Widget ,Widget ,Widget,ArgList ,Cardinal *
00058 #endif
00059 );
00060 static void _expose(
00061 #if NeedFunctionPrototypes
00062 Widget,XEvent *,Region 
00063 #endif
00064 );
00065 static void create_ex_gc(
00066 #if NeedFunctionPrototypes
00067 Widget
00068 #endif
00069 );
00070 static void create_indicator_gc(
00071 #if NeedFunctionPrototypes
00072 Widget
00073 #endif
00074 );
00075 static void create_center_gc(
00076 #if NeedFunctionPrototypes
00077 Widget
00078 #endif
00079 );
00080 static void compute_indicatorcolor(
00081 #if NeedFunctionPrototypes
00082 Widget,int ,XrmValue *
00083 #endif
00084 );
00085 /*ARGSUSED*/
00086 #if NeedFunctionPrototypes
00087 static void create_ex_gc(Widget self)
00088 #else
00089 static void create_ex_gc(self)Widget self;
00090 #endif
00091 {
00092     XtGCMask mask = 0;
00093     XGCValues values;
00094 
00095     if (((XfwfToggleWidget)self)->xfwfToggle.ex_gc != NULL) XtReleaseGC(self, ((XfwfToggleWidget)self)->xfwfToggle.ex_gc);
00096     mask = GCForeground;
00097     values.foreground = ((XfwfToggleWidget)self)->xfwfCommon.highlightColor;
00098     ((XfwfToggleWidget)self)->xfwfToggle.ex_gc = XtGetGC(self, mask, &values);
00099 }
00100 /*ARGSUSED*/
00101 #if NeedFunctionPrototypes
00102 static void create_indicator_gc(Widget self)
00103 #else
00104 static void create_indicator_gc(self)Widget self;
00105 #endif
00106 {
00107     XtGCMask mask = 0;
00108     XGCValues values;
00109 
00110     if (((XfwfToggleWidget)self)->xfwfToggle.indicator_gc != NULL) XtReleaseGC(self, ((XfwfToggleWidget)self)->xfwfToggle.indicator_gc);
00111     switch (((XfwfToggleWidget)self)->xfwfFrame.shadowScheme) {
00112     case XfwfColor:
00113         mask = GCForeground;
00114         values.foreground = ((XfwfToggleWidget)self)->xfwfFrame.topShadowColor;
00115         break;
00116     case XfwfStipple:
00117         mask = GCFillStyle | GCStipple | GCForeground | GCBackground;
00118         values.fill_style = FillOpaqueStippled;
00119         values.background = BlackPixelOfScreen(XtScreen(self));
00120         values.foreground = WhitePixelOfScreen(XtScreen(self));
00121         values.stipple    = GetGray(self);
00122         break;
00123     case XfwfBlack:
00124     case XfwfAuto:
00125         if (DefaultDepthOfScreen(XtScreen(self)) > 4
00126             && ((XfwfToggleWidgetClass)self->core.widget_class)->xfwfCommon_class.set_color(self, ((XfwfToggleWidget)self)->core.background_pixel, &values.foreground)) {
00127             mask = GCForeground;
00128         } else {
00129             mask = GCFillStyle | GCBackground | GCForeground | GCStipple;
00130             values.fill_style = FillOpaqueStippled;
00131             values.background = BlackPixelOfScreen(XtScreen(self));
00132             values.foreground = WhitePixelOfScreen(XtScreen(self));
00133             values.stipple    = GetGray(self);
00134         }
00135         break;
00136     }
00137     ((XfwfToggleWidget)self)->xfwfToggle.indicator_gc = XtGetGC(self, mask, &values);
00138 }
00139 /*ARGSUSED*/
00140 #if NeedFunctionPrototypes
00141 static void create_center_gc(Widget self)
00142 #else
00143 static void create_center_gc(self)Widget self;
00144 #endif
00145 {
00146   XtGCMask mask = 0;
00147   XGCValues values;
00148 
00149   if (((XfwfToggleWidget)self)->xfwfToggle.center_gc != NULL) XtReleaseGC(self, ((XfwfToggleWidget)self)->xfwfToggle.center_gc);
00150   if (((XfwfToggleWidget)self)->xfwfToggle.indicatorType == XfwfDiamondIndicator) {
00151     mask = GCForeground;
00152     values.foreground = ((XfwfToggleWidget)self)->core.background_pixel;
00153     ((XfwfToggleWidget)self)->xfwfToggle.center_gc = XtGetGC(self, mask, &values);
00154   } else
00155     ((XfwfToggleWidget)self)->xfwfToggle.center_gc = NULL;
00156 }
00157 /*ARGSUSED*/
00158 #if NeedFunctionPrototypes
00159 static void compute_indicatorcolor(Widget self,int  offset,XrmValue * value)
00160 #else
00161 static void compute_indicatorcolor(self,offset,value)Widget self;int  offset;XrmValue * value;
00162 #endif
00163 {
00164     static Pixel color;
00165 #if 1
00166     ((XfwfToggleWidgetClass)self->core.widget_class)->xfwfCommon_class.set_color(self, ((XfwfToggleWidget)self)->core.background_pixel, &color);
00167 #else
00168     (void) choose_color(self, 0.85, ((XfwfToggleWidget)self)->core.background_pixel, &color);
00169 #endif
00170     value->addr = (XtPointer) &color;
00171 }
00172 
00173 static XtResource resources[] = {
00174 {XtNonCallback,XtCOnCallback,XtRCallback,sizeof(((XfwfToggleRec*)NULL)->xfwfToggle.onCallback),XtOffsetOf(XfwfToggleRec,xfwfToggle.onCallback),XtRImmediate,(XtPointer)NULL },
00175 {XtNoffCallback,XtCOffCallback,XtRCallback,sizeof(((XfwfToggleRec*)NULL)->xfwfToggle.offCallback),XtOffsetOf(XfwfToggleRec,xfwfToggle.offCallback),XtRImmediate,(XtPointer)NULL },
00176 {XtNon,XtCOn,XtRBoolean,sizeof(((XfwfToggleRec*)NULL)->xfwfToggle.on),XtOffsetOf(XfwfToggleRec,xfwfToggle.on),XtRImmediate,(XtPointer)False },
00177 {XtNindicatorSize,XtCIndicatorSize,XtRDimension,sizeof(((XfwfToggleRec*)NULL)->xfwfToggle.indicatorSize),XtOffsetOf(XfwfToggleRec,xfwfToggle.indicatorSize),XtRImmediate,(XtPointer)0 },
00178 {XtNindicatorType,XtCIndicatorType,XtRIndicatorType,sizeof(((XfwfToggleRec*)NULL)->xfwfToggle.indicatorType),XtOffsetOf(XfwfToggleRec,xfwfToggle.indicatorType),XtRImmediate,(XtPointer)XfwfSquareIndicator },
00179 {XtNindicatorColor,XtCIndicatorColor,XtRPixel,sizeof(((XfwfToggleRec*)NULL)->xfwfToggle.indicatorColor),XtOffsetOf(XfwfToggleRec,xfwfToggle.indicatorColor),XtRCallProc,(XtPointer)compute_indicatorcolor },
00180 {XtNframeWidth,XtCFrameWidth,XtRDimension,sizeof(((XfwfToggleRec*)NULL)->xfwfFrame.frameWidth),XtOffsetOf(XfwfToggleRec,xfwfFrame.frameWidth),XtRImmediate,(XtPointer)0 },
00181 };
00182 
00183 XfwfToggleClassRec xfwfToggleClassRec = {
00184 { /* core_class part */
00185 /* superclass        */  (WidgetClass) &xfwfButtonClassRec,
00186 /* class_name        */  "XfwfToggle",
00187 /* widget_size       */  sizeof(XfwfToggleRec),
00188 /* class_initialize  */  NULL,
00189 /* class_part_initialize*/  _resolve_inheritance,
00190 /* class_inited      */  FALSE,
00191 /* initialize        */  initialize,
00192 /* initialize_hook   */  NULL,
00193 /* realize           */  realize,
00194 /* actions           */  actionsList,
00195 /* num_actions       */  3,
00196 /* resources         */  resources,
00197 /* num_resources     */  7,
00198 /* xrm_class         */  NULLQUARK,
00199 /* compres_motion    */  True ,
00200 /* compress_exposure        */  XtExposeCompressMaximal ,
00201 /* compress_enterleave      */  True ,
00202 /* visible_interest  */  False ,
00203 /* destroy           */  destroy,
00204 /* resize            */  XtInheritResize,
00205 /* expose            */  XtInheritExpose,
00206 /* set_values        */  set_values,
00207 /* set_values_hook   */  NULL,
00208 /* set_values_almost        */  XtInheritSetValuesAlmost,
00209 /* get_values+hook   */  NULL,
00210 /* accept_focus      */  XtInheritAcceptFocus,
00211 /* version           */  XtVersion,
00212 /* callback_private  */  NULL,
00213 /* tm_table          */  defaultTranslations,
00214 /* query_geometry    */  XtInheritQueryGeometry,
00215 /* display_acceleator       */  XtInheritDisplayAccelerator,
00216 /* extension         */  NULL 
00217 },
00218 { /* composite_class part */
00219 XtInheritGeometryManager,
00220 XtInheritChangeManaged,
00221 XtInheritInsertChild,
00222 XtInheritDeleteChild,
00223 NULL
00224 },
00225 { /* XfwfCommon_class part */
00226 XtInherit_compute_inside,
00227 XtInherit_total_frame_width,
00228 _expose,
00229 XtInherit_highlight_border,
00230 XtInherit_unhighlight_border,
00231 XtInherit_hilite_callbacks,
00232 XtInherit_would_accept_focus,
00233 XtInherit_traverse,
00234 XtInherit_lighter_color,
00235 XtInherit_darker_color,
00236 XtInherit_set_color,
00237 /* traversal_trans */  NULL ,
00238 /* traversal_trans_small */  NULL ,
00239 /* travMode */  1 ,
00240 },
00241 { /* XfwfFrame_class part */
00242  /* dummy */  0
00243 },
00244 { /* XfwfBoard_class part */
00245 XtInherit_set_abs_location,
00246 },
00247 { /* XfwfLabel_class part */
00248 XtInherit_set_label,
00249 },
00250 { /* XfwfButton_class part */
00251  /* dummy */  0
00252 },
00253 { /* XfwfToggle_class part */
00254  /* dummy */  0
00255 },
00256 };
00257 WidgetClass xfwfToggleWidgetClass = (WidgetClass) &xfwfToggleClassRec;
00258 /*ARGSUSED*/
00259 static void toggle(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
00260 {
00261     XtVaSetValues(self, "on", !((XfwfToggleWidget)self)->xfwfToggle.on, NULL);
00262     XtCallCallbackList(self, ((XfwfToggleWidget)self)->xfwfToggle.on ? ((XfwfToggleWidget)self)->xfwfToggle.onCallback : ((XfwfToggleWidget)self)->xfwfToggle.offCallback, event);
00263 }
00264 
00265 /*ARGSUSED*/
00266 static void switch_on(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
00267 {
00268     if (! ((XfwfToggleWidget)self)->xfwfToggle.on) {
00269         XtVaSetValues(self, "on", True, NULL);
00270         XtCallCallbackList(self, ((XfwfToggleWidget)self)->xfwfToggle.onCallback, event);
00271     }
00272 }
00273 
00274 /*ARGSUSED*/
00275 static void switch_off(self,event,params,num_params)Widget self;XEvent*event;String*params;Cardinal*num_params;
00276 {
00277     if (((XfwfToggleWidget)self)->xfwfToggle.on) {
00278         XtVaSetValues(self, "on", False, NULL);
00279         XtCallCallbackList(self, ((XfwfToggleWidget)self)->xfwfToggle.offCallback, event);
00280     }
00281 }
00282 
00283 static void _resolve_inheritance(class)
00284 WidgetClass class;
00285 {
00286   XfwfToggleWidgetClass c = (XfwfToggleWidgetClass) class;
00287   XfwfToggleWidgetClass super;
00288   static CompositeClassExtensionRec extension_rec = {
00289     NULL, NULLQUARK, XtCompositeExtensionVersion,
00290     sizeof(CompositeClassExtensionRec), True};
00291   CompositeClassExtensionRec *ext;
00292   ext = (XtPointer)XtMalloc(sizeof(*ext));
00293   *ext = extension_rec;
00294   ext->next_extension = c->composite_class.extension;
00295   c->composite_class.extension = ext;
00296   if (class == xfwfToggleWidgetClass) return;
00297   super = (XfwfToggleWidgetClass)class->core_class.superclass;
00298 }
00299 /*ARGSUSED*/
00300 #if NeedFunctionPrototypes
00301 static void initialize(Widget  request,Widget self,ArgList  args,Cardinal * num_args)
00302 #else
00303 static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
00304 #endif
00305 {
00306     ((XfwfToggleWidget)self)->xfwfToggle.saveLeftMargin = ((XfwfToggleWidget)self)->xfwfLabel.leftMargin;
00307 
00308     if (((XfwfToggleWidget)self)->xfwfLabel.xfont) {
00309       if (!((XfwfToggleWidget)self)->xfwfToggle.indicatorSize || ((XfwfToggleWidget)self)->xfwfToggle.indicatorSize > wx_ASCENT(((XfwfToggleWidget)self)->xfwfLabel.font, ((wxExtFont)((XfwfToggleWidget)self)->xfwfLabel.xfont)))
00310        ((XfwfToggleWidget)self)->xfwfToggle.indicatorSize = wx_ASCENT(((XfwfToggleWidget)self)->xfwfLabel.font, ((wxExtFont)((XfwfToggleWidget)self)->xfwfLabel.xfont));
00311     } else {
00312       if (!((XfwfToggleWidget)self)->xfwfToggle.indicatorSize || ((XfwfToggleWidget)self)->xfwfToggle.indicatorSize > (((XfwfToggleWidget)self)->xfwfLabel.font ? ((XfwfToggleWidget)self)->xfwfLabel.font->ascent : 10))
00313        ((XfwfToggleWidget)self)->xfwfToggle.indicatorSize = (((XfwfToggleWidget)self)->xfwfLabel.font ? ((XfwfToggleWidget)self)->xfwfLabel.font->ascent : 10) + 2;
00314     }
00315 
00316     ((XfwfToggleWidget)self)->xfwfToggle.indicator_gc = NULL;
00317     ((XfwfToggleWidget)self)->xfwfToggle.center_gc = NULL;
00318     ((XfwfToggleWidget)self)->xfwfToggle.ex_gc = NULL;
00319 
00320     XtVaSetValues(self, XtNleftMargin, 2 * ((XfwfToggleWidget)self)->xfwfLabel.leftMargin + ((XfwfToggleWidget)self)->xfwfToggle.indicatorSize, NULL);
00321 }
00322 /*ARGSUSED*/
00323 #if NeedFunctionPrototypes
00324 static void destroy(Widget self)
00325 #else
00326 static void destroy(self)Widget self;
00327 #endif
00328 {
00329    if (((XfwfToggleWidget)self)->xfwfToggle.center_gc) XtReleaseGC(self, ((XfwfToggleWidget)self)->xfwfToggle.center_gc); ((XfwfToggleWidget)self)->xfwfToggle.center_gc = NULL;
00330    if (((XfwfToggleWidget)self)->xfwfToggle.indicator_gc) XtReleaseGC(self, ((XfwfToggleWidget)self)->xfwfToggle.indicator_gc); ((XfwfToggleWidget)self)->xfwfToggle.indicator_gc = NULL;
00331    if (((XfwfToggleWidget)self)->xfwfToggle.ex_gc) XtReleaseGC(self, ((XfwfToggleWidget)self)->xfwfToggle.ex_gc); ((XfwfToggleWidget)self)->xfwfToggle.ex_gc = NULL;
00332 }
00333 /*ARGSUSED*/
00334 #if NeedFunctionPrototypes
00335 static void realize(Widget self,XtValueMask * mask,XSetWindowAttributes * attributes)
00336 #else
00337 static void realize(self,mask,attributes)Widget self;XtValueMask * mask;XSetWindowAttributes * attributes;
00338 #endif
00339 {
00340     xfwfButtonClassRec.core_class.realize(self, mask, attributes);
00341     create_indicator_gc(self);
00342     create_center_gc(self);
00343     create_ex_gc(self);
00344 }
00345 /*ARGSUSED*/
00346 #if NeedFunctionPrototypes
00347 static Boolean  set_values(Widget  old,Widget  request,Widget self,ArgList  args,Cardinal * num_args)
00348 #else
00349 static Boolean  set_values(old,request,self,args,num_args)Widget  old;Widget  request;Widget self;ArgList  args;Cardinal * num_args;
00350 #endif
00351 {
00352     Boolean redraw = False;
00353 
00354     if (!XtIsRealized(self))
00355        return False;
00356 
00357     if (((XfwfToggleWidget)self)->xfwfToggle.on != ((XfwfToggleWidget)old)->xfwfToggle.on
00358     ||  ((XfwfToggleWidget)self)->xfwfToggle.indicatorType != ((XfwfToggleWidget)old)->xfwfToggle.indicatorType) {
00359         redraw = True;
00360     }
00361     if (((XfwfToggleWidget)self)->xfwfFrame.shadowScheme != ((XfwfToggleWidget)old)->xfwfFrame.shadowScheme) {
00362         create_indicator_gc(self);
00363         redraw = True;
00364     } else if (((XfwfToggleWidget)self)->xfwfFrame.shadowScheme == XfwfColor
00365            &&  ((XfwfToggleWidget)self)->xfwfToggle.indicatorColor != ((XfwfToggleWidget)old)->xfwfToggle.indicatorColor) {
00366        create_indicator_gc(self);
00367         redraw = True;
00368     }
00369     if (((XfwfToggleWidget)self)->xfwfToggle.indicatorSize != ((XfwfToggleWidget)old)->xfwfToggle.indicatorSize) {
00370        /* Compute new left margin */
00371        Dimension w = ((XfwfToggleWidget)self)->xfwfLabel.leftMargin + 2 * ((XfwfToggleWidget)self)->xfwfToggle.saveLeftMargin;
00372        /* change left margin */
00373        XtVaSetValues(self, XtNleftMargin, w, NULL);
00374        redraw = True;
00375     }
00376     return redraw;
00377 }
00378 /*ARGSUSED*/
00379 #if NeedFunctionPrototypes
00380 static void _expose(Widget self,XEvent * event,Region  region)
00381 #else
00382 static void _expose(self,event,region)Widget self;XEvent * event;Region  region;
00383 #endif
00384 {
00385     Position x, y;
00386     int w, h;
00387 
00388     if (! XtIsRealized(self)) return;
00389     xfwfButtonClassRec.xfwfCommon_class._expose(self, event, region);
00390     ((XfwfToggleWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &w, &h);
00391     x += ((XfwfToggleWidget)self)->xfwfToggle.saveLeftMargin;
00392     y += (h - ((XfwfToggleWidget)self)->xfwfToggle.indicatorSize) / 2;
00393     switch (((XfwfToggleWidget)self)->xfwfToggle.indicatorType) {
00394     default:
00395        XtWarning("XfwfToggle has wrong indicatorType, using square!");
00396     case XfwfSquareIndicator:
00397        Xaw3dDrawToggle(XtDisplay(self), XtWindow(self),
00398                       ((XfwfToggleWidget)self)->xfwfFrame.lightgc, ((XfwfToggleWidget)self)->xfwfFrame.darkgc, ((XfwfToggleWidget)self)->xfwfToggle.indicator_gc, NULL, ((XfwfToggleWidget)self)->xfwfToggle.ex_gc,
00399                       x, y, ((XfwfToggleWidget)self)->xfwfToggle.indicatorSize, 2, ((XfwfToggleWidget)self)->xfwfToggle.on);
00400        break;
00401     case XfwfDiamondIndicator:
00402        Xaw3dDrawRadio(XtDisplay(self), XtWindow(self),
00403                      ((XfwfToggleWidget)self)->xfwfFrame.lightgc, ((XfwfToggleWidget)self)->xfwfFrame.darkgc, ((XfwfToggleWidget)self)->xfwfToggle.indicator_gc, ((XfwfToggleWidget)self)->xfwfToggle.center_gc, ((XfwfToggleWidget)self)->xfwfToggle.ex_gc,
00404                      x, y, ((XfwfToggleWidget)self)->xfwfToggle.indicatorSize, 2, ((XfwfToggleWidget)self)->xfwfToggle.on);
00405        break;
00406     }
00407 }