apple@nprdc.navy.mil (Jim Apple) (04/13/91)
I need some help with WcCallback, I'm trying to use WcCallback and XtSetValues to update a XmList widget. But it seg faults when it gets to the XtSetValues call. Below is a short example of a resource file and the main.c file. Configuration: Wcl-1.05 and motif 1.1 Any Help would be great. Thanks in advance ---------------------- Wcl resource file ------------------ ! !PaperLess Wcl ! paperless.wcChildren: main paperless.title: PaperLess *main.wcConstructor: XmCreateForm *main.wcChildren: courseList *main.height: 500 *main.width: 750 *courseList.wcTrace: True *courseList.wcConstructor: XmCreateScrolledList *courseList.wcCallback: CreateCourseListCB( ) *courseListSW.leftAttachment: ATTACH_FORM *courseListSW.rightAttachment: ATTACH_FORM *courseListSW.topAttachment: ATTACH_POSITION *courseListSW.topPosition: 6 main.c CreateCourseListCB() is at the end of the file ------- #include <Xm/Xm.h> #include <ctype.h> #include <X11/Wc/WcCreate.h> #include <X11/Xmp/Table.h> #define MAX_ARGS 50 void CreateCourseListCB(); extern void MriRegisterMotif(); static void RegisterTable ( app ) XtAppContext app; { #define RCN( name, class ) WcRegisterClassName ( app, name, class ); #define RCP( name, class ) WcRegisterClassPtr ( app, name, class ); /* -- register widget classes */ RCN( "Table", tableWidgetClass ); RCP( "tableWidgetClass", tableWidgetClass ); } /* as defined in the resource file */ Widget courseList; /****************************************************************************** * MAIN function ******************************************************************************/ main ( argc, argv ) int argc; char* argv[]; { char* appClass; XtAppContext app; Widget appShell; appClass = (char*) XtMalloc ( strlen ( argv[0] ) + 1 ); strcpy (appClass, argv[0]); /* initialize first letter to make class, or first two if ** first is already capitalized, or don't worry about it. */ if (islower(appClass[0])) appClass[0] = toupper(appClass[0]); else if (islower(appClass[1])) appClass[1] = toupper(appClass[1]); /* -- Intialize Toolkit creating the application shell */ appShell = XtInitialize ( argv[0], appClass, /* app name and class */ NULL, 0, /* description of cmd line options */ &argc, argv ); app = XtWidgetToApplicationContext(appShell); /* -- Register all application specific callbacks and widget classes */ RegisterTable ( app ); /* register CreateCourseListCB */ WcRegisterCallback(app, "CreateCourseListCB", CreateCourseListCB, NULL); /* -- Register all Motif classes and constructors */ MriRegisterMotif ( app ); /* -- Create widget tree below toplevel shell using Xrm database */ WcWidgetCreation ( appShell ); /* -- Realize the widget tree and enter the main application loop */ XtRealizeWidget ( appShell ); XtMainLoop ( ); } /***************************************************************************** CreateCourseList() *****************************************************************************/ void CreateCourseListCB( w, ignored, unused) Widget w; caddr_t ignored; caddr_t unused; { Arg args[MAX_ARGS]; int argn = 0; int i = 0; XmString courses[5]; static char *course_list_items[3] = { "C 102-2001 test", "A 101-1001 test", "B 102-2001 test", }; for(i = 0; i < 3; i++) { courses[i] = (XmString )XmStringCreateLtoR(course_list_items[i],XmSTRING_DEFAULT_CHARSET); } XtSetArg(args[argn], XmNitems, (XtArgVal) courses); argn++; XtSetArg(args[argn], XmNitemCount, (XtArgVal) 3 ); argn++; XtSetValues(courseList,args,argn); } Jim Apple apple@nprdc.navy.mil WB1DOG ...}ucsd!nprdc!apple
aw@jello.bae.bellcore.com (Andrew Wason) (04/17/91)
In article <14109@arctic.nprdc.navy.mil>, apple@nprdc.navy.mil (Jim Apple) writes: > > I need some help with WcCallback, I'm trying to use WcCallback > and XtSetValues to update a XmList widget. But it seg faults > when it gets to the XtSetValues call. Below is a short example of a > resource file and the main.c file. > [...] > *courseList.wcConstructor: XmCreateScrolledList > *courseList.wcCallback: CreateCourseListCB( ) > > [...] > > /* as defined in the resource file */ > > Widget courseList; You declare this global Widget variable. > [...] > > void CreateCourseListCB( w, ignored, unused) > Widget w; > caddr_t ignored; > caddr_t unused; > { > > [...] > > XtSetArg(args[argn], XmNitems, (XtArgVal) courses); argn++; > XtSetArg(args[argn], XmNitemCount, (XtArgVal) 3 ); argn++; > > XtSetValues(courseList,args,argn); And use it without ever setting it. 'courseList' is NULL at this point. You should be using 'w' in your callback. 'w' points to the widget this wcCallback is being called for (the widget named "courseList"). XtSetValues(w,args,argn); Andrew _______________________________________________________________________________ Andrew Wason Bell Communications Research aw@bae.bellcore.com Piscataway, NJ bellcore!bae!aw