Path: utzoo!utgpu!watmath!att!dptg!rutgers!tut.cis.ohio-state.edu!bloom-beacon!EXPO.LCS.MIT.EDU!kit From: kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) Newsgroups: comp.windows.x Subject: Re: Some questions about asciiString Widget. Message-ID: <8908301623.AA26866@expo.lcs.mit.edu> Date: 30 Aug 89 16:23:27 GMT References: <1334@colon.gmv.es> Sender: daemon@bloom-beacon.MIT.EDU Organization: The Internet Lines: 67 > 1) I want to read the text from the widget > using XtGetValues but it seems not to work. > char buf[100]; > XtSetArg(arg[n], XtNstring, buf ); n++; > w_text = XtCreateManagedWidget("text", asciiStringWidgetClass, form, arg, n); This allocates your memory off off of the stack, and when you function returns this memory goes away. The string widget explicitally states that it uses the string in place. Once your functions returns the text widget will be writing into bad memory. The proper way to code this is: char * buf = XtMalloc(sizeof(char) * BUFSIZ); XtSetArg(arg[n], XtNstring, buf ); n++; XtSetArg(arg[n], XtNlength, BUFSIZ ); n++; w_text = XtCreateManagedWidget("text", asciiStringWidgetClass, form, arg, n); When retreiving the values use somethin like this: void Accep_text(widget,call_data,client_data) Widget widget; caddr_t call_data, client_data; { char * buf; Arg arg[1]; Cardinal n = 0; XtSetArg(arg[n], XtNstring, &buff) ; n++; XtGetValues(w_text, arg, n); } > 2) I decided to use an asciiStringWidget to allow the user to > edit one line text. The length of the string the user can > introduce is given by the initial value of XtNstring.Thus > if you initialize XtNstring to null the user won't be able > to edit anything. > ( Maybe dialog widget would be better in this case but I had > problems with the initialization : length of text field was > given by label lenght) > Is it correct?. How can the user be allowed to edit one line > without initializing the text? The example code above will work (you will need to make the text editable, however). The key point to remember is that you need to allocate the string to contain enough space, and then specify the anount of space that was allocated in the XtNlength resource. Since the text widget uses the string in place it must know the length of the buffer. The default lenght is strlen(string) and this is what is causing you the problems that you have seen. > ...but when the button is released over an insensitive widget nothing occurs. That's right. The toolkit does not deliver events to an insensitive widget, this is the definition of insensitive. Any look and feel issues associated with insensitivity are left up to the widget implementor. In the Athena widget set we decided to use stippled text and borders. Chris D. Peterson MIT X Consortium Net: kit@expo.lcs.mit.edu Phone: (617) 253 - 9608 Address: MIT - Room NE43-213