[comp.windows.x] Some questions about asciiString Widget.

lmgc@gmv.es (Luis Mariano Gonzalez) (08/30/89)

  Hello -

         1)  I want to  read the text from the widget 
          using XtGetValues but it seems not to work.

/* this is the way I create the Text Widget   */
.....
char buf[100];
.....

  n=0;
  XtSetArg(arg[n], XtNheight, 40);                    n++;
  XtSetArg(arg[n], XtNwidth, 200);                     n++;
  XtSetArg(arg[n], XtNtextOptions,editable);                     n++;
  XtSetArg(arg[n], XtNeditType,XttextEdit);                     n++;
  XtSetArg(arg[n], XtNstring, buf );                    n++;
  w_text = XtCreateManagedWidget("text", asciiStringWidgetClass, form, arg, n);


/*  Here I fetch the text */
void  Accep_text(widget,call_data,client_data)
Widget widget;
caddr_t call_data,client_data;
{                 
  Arg arg[20];
  unsigned int n;
  char buff[100];


  n =0;
  XtSetArg(arg[n], XtNstring,buff) ;                     n++;
  XtGetValues(w_text,arg,n);                     n++;
 }


     ( I've also tried  using  - char * buff - instead of  - buff[100]-,
       but the result was the same : null string).
 
   Do I miss something?.

        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?


 Another question:

       I'm using a widget form to implement a menu. Every menu item is
   a command widget. 
      At any moment I want to make insensitive some command widgets.
   I wanted every event that occurs  over these widgets  to be send to the
   form widget. If the mouse button was released over an insensitive menu
   item I wanted to perform an specific  operation. I select button_release
   for the form widgets, but when the button is released over an insensitive
   widget  nothing occurs.


   Thanks in advance for any help!


L.M. Gonzalez                            Ph. +54 1 234 30 04
Grupo de Mecanica del Vuelo, S.A. (GMV)  Fax +54 1 233 32 50
Cristobal Bordiu, 35                     Telex  48487 GMEV E
E-28003 MADRID                           lmgonzalez@gmv.es
SPAIN                                    mcvax!gmv.es!lmgonzalez@uunet.uu.net
                                         uunet!mcvax!gmv.es!lmgonzalez

kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (08/30/89)

>         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