[comp.windows.x] Can't change the cursor of a Athena widget using XtSetArg

soh@shiva.trl.oz (kam hung soh) (08/03/90)

Dear Netters,

	I have a quirky problem trying to change the cursor of an Athena
widget.  If I set the fallback resource string, I can change a cursor.
For example:

String fallback_resources[] = {
	"*scrollbar.scrollDCursor: gumby",
	NULL,
};

However, if I try to do the following, I get an error from the server:

XtSetArg(args[num_args], XtNscrollDCursor, "trek"); num_args++;
scrollbar = XtCreateManagedWidget("scrollbar", scrollbarWidgetClass,
                                    toplevel, args, num_args);

X Error of failed request:  BadCursor (invalid Cursor parameter)
  Major opcode of failed request:  1 (X_CreateWindow)
  Minor opcode of failed request:  0
  Resource id in failed request:  0x875d
  Serial number of failed request:  65
  Current serial number in output stream:  75

Below is a copy of my program.

Please email any ideas you have.  Thanks!

---cut---cut---

#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/Scrollbar.h>
#include <X11/Xaw/Cardinals.h>

static XtCallbackProc Scrolled(), Jumped();

String fallback_resources[] = {
  "*Scroll.Translations:  #override \\n\
    <Btn1Down>:            StartScroll(Forward) \\n\
    <Btn3Down>:            StartScroll(Backward)",
  "*scrollbar.scrollDCursor:  gumby",
  "*scrollbar.scrollHCursor:  gumby",
  "*scrollbar.scrollLCursor:  gumby",
  "*scrollbar.scrollRCursor:  gumby",
  "*scrollbar.scrollUCursor:  gumby",
  "*scrollbar.scrollVCursor:  gumby",
  NULL,
};

static XrmOptionDescRec options[] = {
  {"-horiz", "scrollbar.orientation", XrmoptionNoArg, "horizontal"}
};

void main(argc, argv)
int argc;
char **argv;
{
  static void Syntax();
  XtAppContext app_con;
  Widget toplevel, scrollbar;
  XtArgVal *l_top;
  float top;
  Arg args[5];
  Cardinal num_args;

  toplevel = XtAppInitialize(&app_con, "Scroll", options, XtNumber(options), 
                             &argc, argv, fallback_resources, NULL, ZERO);

  if (argc != 1) Syntax(app_con, argv[0]);

  top = 0.5;
  num_args = 0;
  if (sizeof(float) > sizeof(XtArgVal)) {
    XtSetArg(args[num_args], XtNtopOfThumb, &top); num_args++;
  }
  else {
    /* convince C not to perform an automatic conversion, 
    which would truncate 0.5 to 0. */
    l_top = (XtArgVal *)&top; 
    XtSetArg(args[num_args], XtNtopOfThumb, *l_top); num_args++;
  }

  XtSetArg(args[num_args], XtNscrollDCursor, "trek"); num_args++;
  XtSetArg(args[num_args], XtNlength, 200); num_args++;

  scrollbar = XtCreateManagedWidget("scrollbar", scrollbarWidgetClass,
                                    toplevel, args, num_args);

  XtAddCallback(scrollbar, XtNjumpProc, Jumped, NULL);
  XtAddCallback(scrollbar, XtNscrollProc, Scrolled, NULL);

  XtRealizeWidget(toplevel);
  XtAppMainLoop(app_con);
}

static XtCallbackProc Scrolled(w, closure, call_data)
Widget w;
XtPointer closure, call_data;
{
  fprintf(stdout, "scrolled by %d pixels.\n", (int)call_data);
}

static XtCallbackProc Jumped(w, closure, call_data)
Widget w;
XtPointer closure, call_data;
{
  float top = *((float *)call_data);
  fprintf(stdout, "thumbewd at %4.2f%% the height of the scrollbar\n",
          top*100);
}

static void Syntax(app_con, call)
XtAppContext app_con;
char *call;
{
  XtDestroyApplicationContext(app_con);
  fprintf(stderr, "Usage: %s [-horiz]\n", call);
  exit(1);
}


---
Soh, Kam Hung      email: h.soh@trl.oz.au     tel: +61 03 541 6403 
Telecom Research Laboratories, P.O. Box 249, Clayton, Victoria 3168, Australia