Back to index

plt-scheme  4.2.1
xwGroup.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 <stdio.h>
00007 #include <X11/Xmu/Converters.h>
00008 #include <X11/Xmu/CharSet.h>
00009 #include <xwToggle.h>
00010 #include <./xwGroupP.h>
00011 static void _resolve_inheritance(
00012 #if NeedFunctionPrototypes
00013 WidgetClass
00014 #endif
00015 );
00016 static void class_initialize(
00017 #if NeedFunctionPrototypes
00018 void
00019 #endif
00020 );
00021 static void initialize(
00022 #if NeedFunctionPrototypes
00023 Widget ,Widget,ArgList ,Cardinal *
00024 #endif
00025 );
00026 static void destroy(
00027 #if NeedFunctionPrototypes
00028 Widget
00029 #endif
00030 );
00031 static Boolean  set_values(
00032 #if NeedFunctionPrototypes
00033 Widget ,Widget ,Widget,ArgList ,Cardinal *
00034 #endif
00035 );
00036 static void _expose(
00037 #if NeedFunctionPrototypes
00038 Widget,XEvent *,Region 
00039 #endif
00040 );
00041 static void insert_child(
00042 #if NeedFunctionPrototypes
00043 Widget 
00044 #endif
00045 );
00046 static void make_textgc(
00047 #if NeedFunctionPrototypes
00048 Widget
00049 #endif
00050 );
00051 static void on_cb(
00052 #if NeedFunctionPrototypes
00053 Widget ,XtPointer ,XtPointer 
00054 #endif
00055 );
00056 static void off_cb(
00057 #if NeedFunctionPrototypes
00058 Widget ,XtPointer ,XtPointer 
00059 #endif
00060 );
00061 static void set_toggles(
00062 #if NeedFunctionPrototypes
00063 Widget
00064 #endif
00065 );
00066 #define done(type, value) do {\
00067       if (to->addr != NULL) {\
00068          if (to->size < sizeof(type)) {\
00069              to->size = sizeof(type);\
00070              return False;\
00071          }\
00072          *(type*)(to->addr) = (value);\
00073       } else {\
00074          static type static_val;\
00075          static_val = (value);\
00076          to->addr = (XtPointer)&static_val;\
00077       }\
00078       to->size = sizeof(type);\
00079       return True;\
00080   }while (0 )
00081 
00082 
00083 static Boolean  cvtStringToSelectionType(
00084 #if NeedFunctionPrototypes
00085 Display *,XrmValuePtr ,Cardinal *,XrmValuePtr ,XrmValuePtr ,XtPointer *
00086 #endif
00087 );
00088 static Boolean  cvtSelectionTypeToString(
00089 #if NeedFunctionPrototypes
00090 Display *,XrmValuePtr ,Cardinal *,XrmValuePtr ,XrmValuePtr ,XtPointer *
00091 #endif
00092 );
00093 /*ARGSUSED*/
00094 #if NeedFunctionPrototypes
00095 static void make_textgc(Widget self)
00096 #else
00097 static void make_textgc(self)Widget self;
00098 #endif
00099 {
00100     XtGCMask mask;
00101     XGCValues values;
00102 
00103     if (((XfwfGroupWidget)self)->xfwfGroup.textgc != NULL) XtReleaseGC(self, ((XfwfGroupWidget)self)->xfwfGroup.textgc);
00104     values.background = ((XfwfGroupWidget)self)->core.background_pixel;
00105     values.foreground = ((XfwfGroupWidget)self)->xfwfGroup.foreground;
00106     mask = GCBackground | GCForeground;
00107     if (((XfwfGroupWidget)self)->xfwfGroup.font) {
00108       values.font = ((XfwfGroupWidget)self)->xfwfGroup.font->fid;
00109       mask |= GCFont;
00110     }
00111     ((XfwfGroupWidget)self)->xfwfGroup.textgc = XtGetGC(self, mask, &values);
00112 }
00113 /*ARGSUSED*/
00114 #if NeedFunctionPrototypes
00115 static void on_cb(Widget  toggle,XtPointer  client_data,XtPointer  call_data)
00116 #else
00117 static void on_cb(toggle,client_data,call_data)Widget  toggle;XtPointer  client_data;XtPointer  call_data;
00118 #endif
00119 {
00120     Widget self = XtParent(toggle);
00121     Cardinal toggle_ord = (Cardinal) client_data;
00122     Cardinal t, i, bits = sizeof(((XfwfGroupWidget)self)->xfwfGroup.selection) * 8;
00123 
00124     switch (((XfwfGroupWidget)self)->xfwfGroup.selectionStyle) {
00125     case XfwfMultipleSelection:
00126        if (toggle_ord < bits) ((XfwfGroupWidget)self)->xfwfGroup.selection |= 1L << toggle_ord;
00127        break;
00128     case XfwfSingleSelection:
00129     case XfwfOneSelection:
00130        if (((XfwfGroupWidget)self)->xfwfGroup.selection != -1L)
00131            for (t = 0, i = 0; i < ((XfwfGroupWidget)self)->composite.num_children; i++)
00132               if (XtIsSubclass(((XfwfGroupWidget)self)->composite.children[i], xfwfToggleWidgetClass)) {
00133                   if (((XfwfGroupWidget)self)->xfwfGroup.selection == t) {
00134                      XtVaSetValues(((XfwfGroupWidget)self)->composite.children[i], XtNon, False, NULL);
00135                      break;
00136                   }
00137                   t++;
00138               }
00139        ((XfwfGroupWidget)self)->xfwfGroup.selection = toggle_ord;
00140        break;
00141     default: ;
00142     }
00143     XtCallCallbackList(self, ((XfwfGroupWidget)self)->xfwfGroup.activate, (XtPointer) ((XfwfGroupWidget)self)->xfwfGroup.selection);
00144 }
00145 /*ARGSUSED*/
00146 #if NeedFunctionPrototypes
00147 static void off_cb(Widget  toggle,XtPointer  client_data,XtPointer  call_data)
00148 #else
00149 static void off_cb(toggle,client_data,call_data)Widget  toggle;XtPointer  client_data;XtPointer  call_data;
00150 #endif
00151 {
00152     Widget self = XtParent(toggle);
00153     Cardinal toggle_ord = (Cardinal) client_data;
00154     Cardinal bits = sizeof(((XfwfGroupWidget)self)->xfwfGroup.selection) * 8;
00155 
00156     switch (((XfwfGroupWidget)self)->xfwfGroup.selectionStyle) {
00157     case XfwfOneSelection:
00158        XtVaSetValues(toggle, XtNon, True, NULL); /* Undo */
00159        break;
00160     case XfwfSingleSelection:
00161        ((XfwfGroupWidget)self)->xfwfGroup.selection = -1L;                   /* Nothing selected */
00162        break;
00163     case XfwfMultipleSelection:
00164        if (toggle_ord < bits) ((XfwfGroupWidget)self)->xfwfGroup.selection &= ~(1L << toggle_ord);
00165        break;
00166     default: ;
00167     }
00168     XtCallCallbackList(self, ((XfwfGroupWidget)self)->xfwfGroup.activate, (XtPointer) ((XfwfGroupWidget)self)->xfwfGroup.selection);
00169 }
00170 /*ARGSUSED*/
00171 #if NeedFunctionPrototypes
00172 static void set_toggles(Widget self)
00173 #else
00174 static void set_toggles(self)Widget self;
00175 #endif
00176 {
00177     Cardinal i, t;
00178 
00179     for (t = 0, i = 0; i < ((XfwfGroupWidget)self)->composite.num_children; i++)
00180        if (XtIsSubclass(((XfwfGroupWidget)self)->composite.children[i], xfwfToggleWidgetClass)) {
00181            switch (((XfwfGroupWidget)self)->xfwfGroup.selectionStyle) {
00182            case XfwfNoSelection:
00183               break;
00184            case XfwfSingleSelection:
00185            case XfwfOneSelection:
00186               XtVaSetValues(((XfwfGroupWidget)self)->composite.children[i], XtNon, t == ((XfwfGroupWidget)self)->xfwfGroup.selection, NULL);
00187               break;
00188            case XfwfMultipleSelection:
00189               XtVaSetValues(((XfwfGroupWidget)self)->composite.children[i],
00190                            XtNon, (((XfwfGroupWidget)self)->xfwfGroup.selection & (1L<<t)) != 0, NULL);
00191               break;
00192            }
00193            t++;
00194        }
00195 }
00196 /*ARGSUSED*/
00197 #if NeedFunctionPrototypes
00198 static Boolean  cvtStringToSelectionType(Display * display,XrmValuePtr  args,Cardinal * num_args,XrmValuePtr  from,XrmValuePtr  to,XtPointer * converter_data)
00199 #else
00200 static Boolean  cvtStringToSelectionType(display,args,num_args,from,to,converter_data)Display * display;XrmValuePtr  args;Cardinal * num_args;XrmValuePtr  from;XrmValuePtr  to;XtPointer * converter_data;
00201 #endif
00202 {
00203     String s = (String) from->addr;
00204 
00205     if (*num_args != 0)
00206        XtAppErrorMsg(XtDisplayToApplicationContext(display),
00207                     "cvtStringToSelectionType", "wrongParameters",
00208                     "XtToolkitError",
00209                     "String to SelectionType conversion needs no arguments",
00210                     (String*) NULL, (Cardinal*) NULL);
00211 
00212     if (XmuCompareISOLatin1(s, "no") == 0)
00213        done(SelectionType, XfwfNoSelection);
00214     if (XmuCompareISOLatin1(s, "none") == 0)
00215        done(SelectionType, XfwfNoSelection);
00216     if (XmuCompareISOLatin1(s, "single") == 0)
00217        done(SelectionType, XfwfSingleSelection);
00218     if (XmuCompareISOLatin1(s, "one") == 0)
00219        done(SelectionType, XfwfOneSelection);
00220     if (XmuCompareISOLatin1(s, "multi") == 0)
00221        done(SelectionType, XfwfMultipleSelection);
00222     if (XmuCompareISOLatin1(s, "multiple") == 0)
00223        done(SelectionType, XfwfMultipleSelection);
00224 
00225     XtDisplayStringConversionWarning(display, s, XtRSelectionType);
00226     done(SelectionType, XfwfSingleSelection);
00227 }
00228 /*ARGSUSED*/
00229 #if NeedFunctionPrototypes
00230 static Boolean  cvtSelectionTypeToString(Display * display,XrmValuePtr  args,Cardinal * num_args,XrmValuePtr  from,XrmValuePtr  to,XtPointer * converter_data)
00231 #else
00232 static Boolean  cvtSelectionTypeToString(display,args,num_args,from,to,converter_data)Display * display;XrmValuePtr  args;Cardinal * num_args;XrmValuePtr  from;XrmValuePtr  to;XtPointer * converter_data;
00233 #endif
00234 {
00235     char s[30];
00236 
00237     if (*num_args != 0)
00238        XtAppErrorMsg(XtDisplayToApplicationContext(display),
00239                     "cvtStringToSelectionStyle", "wrongParameters",
00240                     "XtToolkitError",
00241                     "String to SelectionStyle conversion needs no arguments",
00242                     (String*) NULL, (Cardinal*) NULL);
00243     switch (*((SelectionType*) from->addr)) {
00244     case XfwfNoSelection: done(String, "none");
00245     case XfwfSingleSelection: done(String, "single");
00246     case XfwfOneSelection: done(String, "one");
00247     case XfwfMultipleSelection: done(String, "multiple");
00248     }
00249     XtDisplayStringConversionWarning(display, s, XtRSelectionType);
00250     done(String, "none");
00251 }
00252 
00253 static XtResource resources[] = {
00254 {XtNlabel,XtCLabel,XtRString,sizeof(((XfwfGroupRec*)NULL)->xfwfGroup.label),XtOffsetOf(XfwfGroupRec,xfwfGroup.label),XtRImmediate,(XtPointer)NULL },
00255 {XtNfont,XtCFont,XtRFontStruct,sizeof(((XfwfGroupRec*)NULL)->xfwfGroup.font),XtOffsetOf(XfwfGroupRec,xfwfGroup.font),XtRString,(XtPointer)XtDefaultFont },
00256 {XtNforeground,XtCForeground,XtRPixel,sizeof(((XfwfGroupRec*)NULL)->xfwfGroup.foreground),XtOffsetOf(XfwfGroupRec,xfwfGroup.foreground),XtRString,(XtPointer)XtDefaultForeground },
00257 {XtNselectionStyle,XtCSelectionStyle,XtRSelectionType,sizeof(((XfwfGroupRec*)NULL)->xfwfGroup.selectionStyle),XtOffsetOf(XfwfGroupRec,xfwfGroup.selectionStyle),XtRImmediate,(XtPointer)XfwfSingleSelection },
00258 {XtNselection,XtCSelection,XtRLong,sizeof(((XfwfGroupRec*)NULL)->xfwfGroup.selection),XtOffsetOf(XfwfGroupRec,xfwfGroup.selection),XtRImmediate,(XtPointer)0 },
00259 {XtNactivate,XtCActivate,XtRCallback,sizeof(((XfwfGroupRec*)NULL)->xfwfGroup.activate),XtOffsetOf(XfwfGroupRec,xfwfGroup.activate),XtRImmediate,(XtPointer)NULL },
00260 {XtNframeType,XtCFrameType,XtRFrameType,sizeof(((XfwfGroupRec*)NULL)->xfwfFrame.frameType),XtOffsetOf(XfwfGroupRec,xfwfFrame.frameType),XtRImmediate,(XtPointer)XfwfChiseled },
00261 {XtNinnerOffset,XtCInnerOffset,XtRDimension,sizeof(((XfwfGroupRec*)NULL)->xfwfFrame.innerOffset),XtOffsetOf(XfwfGroupRec,xfwfFrame.innerOffset),XtRImmediate,(XtPointer)0 },
00262 };
00263 
00264 XfwfGroupClassRec xfwfGroupClassRec = {
00265 { /* core_class part */
00266 /* superclass        */  (WidgetClass) &xfwfRowColClassRec,
00267 /* class_name        */  "XfwfGroup",
00268 /* widget_size       */  sizeof(XfwfGroupRec),
00269 /* class_initialize  */  class_initialize,
00270 /* class_part_initialize*/  _resolve_inheritance,
00271 /* class_inited      */  FALSE,
00272 /* initialize        */  initialize,
00273 /* initialize_hook   */  NULL,
00274 /* realize           */  XtInheritRealize,
00275 /* actions           */  NULL,
00276 /* num_actions       */  0,
00277 /* resources         */  resources,
00278 /* num_resources     */  8,
00279 /* xrm_class         */  NULLQUARK,
00280 /* compres_motion    */  True ,
00281 /* compress_exposure        */  XtExposeCompressMaximal ,
00282 /* compress_enterleave      */  True ,
00283 /* visible_interest  */  False ,
00284 /* destroy           */  destroy,
00285 /* resize            */  XtInheritResize,
00286 /* expose            */  XtInheritExpose,
00287 /* set_values        */  set_values,
00288 /* set_values_hook   */  NULL,
00289 /* set_values_almost        */  XtInheritSetValuesAlmost,
00290 /* get_values+hook   */  NULL,
00291 /* accept_focus      */  XtInheritAcceptFocus,
00292 /* version           */  XtVersion,
00293 /* callback_private  */  NULL,
00294 /* tm_table          */  NULL,
00295 /* query_geometry    */  XtInheritQueryGeometry,
00296 /* display_acceleator       */  XtInheritDisplayAccelerator,
00297 /* extension         */  NULL 
00298 },
00299 { /* composite_class part */
00300 XtInheritGeometryManager,
00301 XtInheritChangeManaged,
00302 insert_child,
00303 XtInheritDeleteChild,
00304 NULL
00305 },
00306 { /* XfwfCommon_class part */
00307 XtInherit_compute_inside,
00308 XtInherit_total_frame_width,
00309 _expose,
00310 XtInherit_highlight_border,
00311 XtInherit_unhighlight_border,
00312 XtInherit_hilite_callbacks,
00313 XtInherit_would_accept_focus,
00314 XtInherit_traverse,
00315 XtInherit_lighter_color,
00316 XtInherit_darker_color,
00317 XtInherit_set_color,
00318 /* traversal_trans */  NULL ,
00319 /* traversal_trans_small */  NULL ,
00320 /* travMode */  1 ,
00321 },
00322 { /* XfwfFrame_class part */
00323  /* dummy */  0
00324 },
00325 { /* XfwfBoard_class part */
00326 XtInherit_set_abs_location,
00327 },
00328 { /* XfwfRowCol_class part */
00329 XtInherit_layout,
00330 },
00331 { /* XfwfGroup_class part */
00332  /* dummy */  0
00333 },
00334 };
00335 WidgetClass xfwfGroupWidgetClass = (WidgetClass) &xfwfGroupClassRec;
00336 static void _resolve_inheritance(class)
00337 WidgetClass class;
00338 {
00339   XfwfGroupWidgetClass c = (XfwfGroupWidgetClass) class;
00340   XfwfGroupWidgetClass super;
00341   static CompositeClassExtensionRec extension_rec = {
00342     NULL, NULLQUARK, XtCompositeExtensionVersion,
00343     sizeof(CompositeClassExtensionRec), True};
00344   CompositeClassExtensionRec *ext;
00345   ext = (XtPointer)XtMalloc(sizeof(*ext));
00346   *ext = extension_rec;
00347   ext->next_extension = c->composite_class.extension;
00348   c->composite_class.extension = ext;
00349   if (class == xfwfGroupWidgetClass) return;
00350   super = (XfwfGroupWidgetClass)class->core_class.superclass;
00351 }
00352 /*ARGSUSED*/
00353 #if NeedFunctionPrototypes
00354 static void class_initialize(void)
00355 #else
00356 static void class_initialize()
00357 #endif
00358 {
00359     XtAddConverter(XtRString, XtRLong, XmuCvtStringToLong, NULL, 0);
00360     XtSetTypeConverter(XtRString, XtRSelectionType, cvtStringToSelectionType,
00361                      NULL, 0, XtCacheNone, NULL);
00362     XtSetTypeConverter(XtRSelectionType, XtRString, cvtSelectionTypeToString,
00363                      NULL, 0, XtCacheNone, NULL);
00364 }
00365 /*ARGSUSED*/
00366 #if NeedFunctionPrototypes
00367 static void initialize(Widget  request,Widget self,ArgList  args,Cardinal * num_args)
00368 #else
00369 static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
00370 #endif
00371 {
00372     ((XfwfGroupWidget)self)->xfwfGroup.toggle_ord = 0;
00373     ((XfwfGroupWidget)self)->xfwfGroup.textgc = NULL;
00374     make_textgc(self);
00375     if (((XfwfGroupWidget)self)->xfwfGroup.label)
00376      ((XfwfGroupWidget)self)->xfwfGroup.label = XtNewString(((XfwfGroupWidget)self)->xfwfGroup.label);
00377     if (((XfwfGroupWidget)self)->xfwfGroup.selectionStyle == XfwfOneSelection && ((XfwfGroupWidget)self)->xfwfGroup.selection == -1L) {
00378        XtWarning
00379            ("Illegal combination of selectionStyle and selection resources");
00380        ((XfwfGroupWidget)self)->xfwfGroup.selection = 0;
00381     }
00382 }
00383 /*ARGSUSED*/
00384 #if NeedFunctionPrototypes
00385 static void destroy(Widget self)
00386 #else
00387 static void destroy(self)Widget self;
00388 #endif
00389 {
00390    if (((XfwfGroupWidget)self)->xfwfGroup.textgc) XtReleaseGC(self, ((XfwfGroupWidget)self)->xfwfGroup.textgc); ((XfwfGroupWidget)self)->xfwfGroup.textgc = NULL;
00391 }
00392 /*ARGSUSED*/
00393 #if NeedFunctionPrototypes
00394 static Boolean  set_values(Widget  old,Widget  request,Widget self,ArgList  args,Cardinal * num_args)
00395 #else
00396 static Boolean  set_values(old,request,self,args,num_args)Widget  old;Widget  request;Widget self;ArgList  args;Cardinal * num_args;
00397 #endif
00398 {
00399     Boolean need_redraw = False;
00400 
00401     if (((XfwfGroupWidget)old)->xfwfGroup.label != ((XfwfGroupWidget)self)->xfwfGroup.label) {
00402        XtFree(((XfwfGroupWidget)old)->xfwfGroup.label);
00403        ((XfwfGroupWidget)self)->xfwfGroup.label = XtNewString(((XfwfGroupWidget)self)->xfwfGroup.label);
00404        need_redraw = True;
00405     }
00406     if (((XfwfGroupWidget)self)->xfwfGroup.font != ((XfwfGroupWidget)old)->xfwfGroup.font) {
00407        make_textgc(self);
00408        if (((XfwfGroupWidget)self)->xfwfGroup.label != NULL) need_redraw = True;
00409     }
00410     if (((XfwfGroupWidget)old)->xfwfGroup.selection != ((XfwfGroupWidget)self)->xfwfGroup.selection
00411        || ((XfwfGroupWidget)old)->xfwfGroup.selectionStyle != ((XfwfGroupWidget)self)->xfwfGroup.selectionStyle) {
00412        if (((XfwfGroupWidget)self)->xfwfGroup.selectionStyle == XfwfOneSelection && ((XfwfGroupWidget)self)->xfwfGroup.selection == -1L)
00413            ((XfwfGroupWidget)self)->xfwfGroup.selection = 0;
00414        set_toggles(self);
00415     }
00416 
00417     return need_redraw;
00418 }
00419 /*ARGSUSED*/
00420 #if NeedFunctionPrototypes
00421 static void _expose(Widget self,XEvent * event,Region  region)
00422 #else
00423 static void _expose(self,event,region)Widget self;XEvent * event;Region  region;
00424 #endif
00425 {
00426     int w, h;
00427     Position x, y;
00428 
00429     if (! XtIsRealized(self)) return;
00430     xfwfRowColClassRec.xfwfCommon_class._expose(self, event, region);
00431     if (((XfwfGroupWidget)self)->xfwfGroup.label) {
00432        ((XfwfGroupWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &x, &y, &w, &h);
00433 
00434        XDrawImageString(XtDisplay(self), XtWindow(self), ((XfwfGroupWidget)self)->xfwfGroup.textgc, x + 3,
00435                       y - ((XfwfGroupWidget)self)->xfwfFrame.innerOffset, ((XfwfGroupWidget)self)->xfwfGroup.label, strlen(((XfwfGroupWidget)self)->xfwfGroup.label));
00436     }
00437 
00438    
00439 }
00440 /*ARGSUSED*/
00441 #if NeedFunctionPrototypes
00442 static void insert_child(Widget  child)
00443 #else
00444 static void insert_child(child)Widget  child;
00445 #endif
00446 { Widget self = XtParent(child); {
00447     xfwfRowColClassRec.composite_class.insert_child(child);
00448     if (((XfwfGroupWidget)self)->xfwfGroup.selectionStyle != XfwfNoSelection
00449        && XtIsSubclass(child, xfwfToggleWidgetClass)) {
00450        XtAddCallback(child, XtNonCallback, on_cb, (XtPointer) ((XfwfGroupWidget)self)->xfwfGroup.toggle_ord);
00451        XtAddCallback(child, XtNoffCallback, off_cb, (XtPointer) ((XfwfGroupWidget)self)->xfwfGroup.toggle_ord);
00452        switch (((XfwfGroupWidget)self)->xfwfGroup.selectionStyle) {
00453        case XfwfOneSelection:
00454        case XfwfSingleSelection:
00455            XtVaSetValues(child, XtNon, ((XfwfGroupWidget)self)->xfwfGroup.toggle_ord == ((XfwfGroupWidget)self)->xfwfGroup.selection,
00456                              XtNindicatorType, XfwfDiamondIndicator, NULL);
00457            break;
00458        case XfwfMultipleSelection:
00459            XtVaSetValues(child, XtNon, (((XfwfGroupWidget)self)->xfwfGroup.selection & (1L<<((XfwfGroupWidget)self)->xfwfGroup.toggle_ord)) != 0,
00460                              XtNindicatorType, XfwfSquareIndicator, NULL);
00461            break;
00462        default: ;
00463        }
00464        ((XfwfGroupWidget)self)->xfwfGroup.toggle_ord++;
00465     }
00466 }
00467 }