chapman@lll-crg.llnl.gov (Carol Chapman) (04/26/91)
Regarding my postings on XmString problems, I reported the problem to DEC since I'm using DEC software, and sent them the same 2 test cases (test.c and test1.c) that I have previously posted to the net. Here's the reply I received from their investigation and a possible workaround: ---------------------------------------------------------------------- From: Graphics Workstation Support <knorr@rhett.enet.dec.COM> Subject: XmStringGetLtoR problem Carol, Well as it turns out I was incorrect when I stated that your TEST1 program (the one that doesn't work that uses UIL) did NOT work under DECwindows V3 Field Test. Embarassingly, I thought I'd rebuilt the program when I tried it, but I hadn't. The bottom line is TEST1 *does* work under DECwindows V3, which is still in external field test. Bottom bottom line is it looks like this is a bug that has been fixed. The following dialog took place in our MOTIF NOTES conference (our internal equivalent to usenet I suppose): Problem: For some reason (I guess I must be doing something wrong...) getting the label from a push button with XmStringGetLtoR is not working for me. Not even with the 40 line example below. It always seems to return NULL. Can somebody lay his finger on the error{s) I made ? #include <x11/intrinsic.h> #include <xm/xm.h> #include <xm/pushb.h> int main(); void activateCB(); char *btn_text; int main (argc,argv) unsigned int argc; char **argv; { Widget toplevel; Widget button; XtAppContext app_context; Arg args[10]; register int n; toplevel= XtAppInitialize(&app_context,"XMdemos",NULL,0,&argc,argv,NULL,NULL,0); btn_text = XmStringCreateLtoR ("push",XmSTRING_DEFAULT_CHARSET); n=0; XtSetArg (args[n],XmNlabelString,btn_text);n++; XtSetArg (args[n],XmNwidth,80);n++; XtSetArg (args[n],XmNheight,40);n++; button= XtCreateManagedWidget ("button",xmPushButtonWidgetClass,toplevel,args,n); XtAddCallback (button,XmNactivateCallback,activateCB,NULL); XtRealizeWidget(toplevel); XtAppMainLoop(app_context); } void activateCB (w,client_data,call_data) Widget w; caddr_t client_data; caddr_t call_data; { int n; Arg args[5]; XmString mstring = NULL; char *nstring = NULL; n= 0; XtSetArg (args[n],XmNlabelString,&mstring);n++; XtGetValues (w,args,n); XmStringGetLtoR (mstring,XmSTRING_DEFAULT_CHARSET,&nstring); printf ("%s\n",nstring); exit (0); } ============================================================================== Eng. Feedback: Well, I don't know what version of Motif you have, but I tried it with the layered product kit, and XmStringGetLtoR returned NULL. I tried it with DECwindows V3 IFT2, and it works fine. There have been a couple of problems with the compound string routines. Looks like this was one that got fixed... -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There may be a workaround to your problem, as the following Question/Answer dialog points out. Question: Is the XmStringGetLtoR routine for extracting string from a compound string? If so, which one is better: the XmStringGetLtoR routine or the XmStringInitContext + XmStringGetNextSegment + XmStringFreeContext sequence? Answer: XmStringGetLtoR runs through the XmStringInitContext + XmStringGetNextSegment + XmStringFreeContext sequence and returns the first text segment it finds that has a charset matching the requested charset and is a left to right segment. This is a very dangerous routine to use in conjunction with the CSText widget, because there is never a guarantee that the XmString returned from a CSText widget (even if only a few characters of LtoR text are entered) is in a single segment. I recommend you use the XmStringInitContext+XmStringGetNextSegment+XmStringFreeContext sequence. Regards, Chris Carol Chapman Tel. (415) 423-7876 Livermore National Laboratory NEW --> chapman@.llnl.gov P. O. Box 808, L-572 "Are you in charge here?" Livermore, CA 94550 "No, but I'm full of ideas!" -- Dr. Who