/*
 * What does XtVaGetValues(w, XmNlabelString, &x, NULL); return ?
 */
#include <stdio.h>
#include <Xm/XmAll.h>

void
cb(Widget w, XtPointer data, XtPointer cbs)
{
    XmString	xms = NULL;
    char	*s = NULL;

    XtVaGetValues(w, XmNlabelString, &xms, NULL);
    if (xms == NULL) {
	fprintf(stderr, "XmString was NULL\n");
	return;
    }
    XmStringGetLtoR(xms, XmSTRING_DEFAULT_CHARSET, &s);
    if (s == NULL) {
	fprintf(stderr, "Conversion to String failed\n");
	return;
    }
    fprintf(stderr, "Label : %s\n", s);
    XmStringFree(xms);
    XtFree(s);
}

String fallback[] = {
	"*One.labelString:	this is a labelString on a widget",
	"*Two.labelString:	this is a labelString on a gadget",
	NULL
};

int
main(int argc, char **argv)
{
  Widget toplevel, rc, w;
  XtAppContext app;

  XtSetLanguageProc(NULL, NULL, NULL);
  toplevel = XtVaAppInitialize(&app, "Label", NULL, 0, &argc, argv, fallback, NULL);

  rc = XtVaCreateManagedWidget("rc", xmRowColumnWidgetClass, toplevel, NULL);

  w = XtVaCreateManagedWidget("PushButtonWidget", xmPushButtonWidgetClass, rc, NULL);
  XtAddCallback(w, XmNactivateCallback, cb, NULL);
  w = XtVaCreateManagedWidget("PushButtonGadget", xmPushButtonGadgetClass, rc, NULL);
  XtAddCallback(w, XmNactivateCallback, cb, NULL);
  w = XtVaCreateManagedWidget("One", xmPushButtonWidgetClass, rc, NULL);
  XtAddCallback(w, XmNactivateCallback, cb, NULL);
  w = XtVaCreateManagedWidget("Two", xmPushButtonGadgetClass, rc, NULL);
  XtAddCallback(w, XmNactivateCallback, cb, NULL);

  XtRealizeWidget(toplevel);
  XtAppMainLoop(app);

  exit(0);
}
