[comp.windows.x] Problem with dialog widget

wong@h.cs.wvu.wvnet.edu (Hiulum Wong) (01/27/89)

Question 1:
  I am trying to reset the label and value of dialog
widget at runtime using XtSetValues on XtNlabel and XtNvalue.
It does not work (see the program below). This works fine for
label and command widget though. Why?

Question 2:
  If I change some resources using XtSetValues in a callback
function, when does the system change the resource databace
internally and remap the window so that we can see the changes?
I have used XtSetValues in a callback function to change a
command widget's label two times and sleeped 10 seconds in between.
But, I can only see the last change. Is there any way to change
a command widget's label more than once in a callback function?

  If you have any ideas and suggestions, please email to 
                 wong@b.cs.wvu.wvunet.edu


A exmaple program:

#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Dialog.h>
#include <X11/Command.h>
#include <X11/Form.h>

Widget toplevel, outer, dial, quit, change;
char *val;
char *label_str = "label    ";
char *cmd_str = "change   ";
char *cmd_str2 = "changed ";
char *label_str2 = "new label";
char *default_val = "dialog      ";
char *default_val2 = "changed";

void change_func(widget,closure,callData)
    Widget widget;
    caddr_t closure;		
    caddr_t callData;
{
    Arg arg[3];
    int i;

    val = XtDialogGetValueString(dial);
    printf("value = %s\n", val);

    /* change dialog widget's label and default value */
    i = 0;	
    XtSetArg( arg[i], XtNlabel, label_str2); i++;
    XtSetArg( arg[i], XtNvalue, default_val2); i++;
    XtSetValues(dial, arg, i);

    /* change command widget's label */
    i = 0;
    XtSetArg( arg[i], XtNlabel, cmd_str2); i++;
    XtSetValues(change, arg, i);
 
    sleep(10);
    int i = 0;
    XtSetArg( arg[i], XtNlabel, label_str2); i++;
    XtSetValues(change, arg, i);

}
void Quit(widget,closure,callData)
    Widget widget;
    caddr_t closure;		
    caddr_t callData;
{
    XtDestroyWidget((Widget)closure);
    exit(1);
}

/**********************************************************************************/

void main(argc, argv)
    unsigned int argc;
    char **argv;
{
    Arg arg[20];
    int i, k;

    /* outer window (the parent)*/
    toplevel = XtInitialize( NULL, "Dialog", (char *)NULL, 0, &argc, argv);

    i = 0;
    XtSetArg( arg[i], XtNwidth, 600 ); i++;
    XtSetArg( arg[i], XtNheight, 600 ); i++;

    outer = XtCreateManagedWidget( "form", formWidgetClass, toplevel,
				   arg, i);

    /* dialog widget */

    i = 0;
    XtSetArg( arg[i], XtNlabel, label_str); i++;
    XtSetArg( arg[i], XtNvalue, default_val); i++;
    XtSetArg( arg[i], XtNwidth, 200 ); i++;
    XtSetArg( arg[i], XtNheight, 200 ); i++;
    XtSetArg( arg[i], XtNborderWidth, 0 ); i++;
    dial = XtCreateManagedWidget( "dial", dialogWidgetClass, outer, arg, i);

    /* command widget */
    i = 0;
    XtSetArg( arg[i], XtNfromVert, dial); i++;
    XtSetArg( arg[i], XtNlabel, cmd_str); i++;
    change = XtCreateManagedWidget( " change ", commandWidgetClass, outer, arg, i);
    XtAddCallback(change, XtNcallback, change_func, change);

    i = 0;
    XtSetArg( arg[i], XtNfromVert, dial); i++;
    XtSetArg( arg[i], XtNfromHoriz, change); i++;
    quit = XtCreateManagedWidget( " exit ", commandWidgetClass, outer, arg, i);
    XtAddCallback(quit, XtNcallback, Quit, toplevel);

    XtRealizeWidget(toplevel);
    XtMainLoop();
}