[comp.windows.x] Defining cursor for a widget.

somani@parns.nsc.com (Anil Somani X14146) (04/26/89)

I am trying to set the cursor for a popup widget using the XtNcursor
resource, and understand that all the children of this popup will
inherit this cursor by default. I have the following hierarchy in
my application:
           		-->Command
           	       |
               Popup--->Form---->Label1
           	       |
           		-->Label2
Defining XtNcursor for Popup or Form doesn't work. Defining XtNcursor
explicitly for Command, Label1, Label2 works. I can never display
the new cursor in the form widget even if I declare explicitly. 

Below is a small test program which exhibits the problem. The hierarchy
for the test program is:
               Top->Command->Popup->Label
The label widget does not get the new cursor.

Any help will be appreciated. Please post or email.
Thanks in advance,

--------------- TEST PROGRAM --------------------------------------
#include <X11/Intrinsic.h>
#include <X11/Xatom.h>
#include <X11/Cardinals.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Command.h>
#include <X11/Label.h>
#include <X11/cursorfont.h>

static Arg args[25];
static int i=0;
static XtCallbackRec callback[2];

void
buttonCallback(widget,closure,calldata)
Widget widget;
caddr_t closure;
caddr_t calldata;
{
static Widget popup, label;
Cursor cursor;
  cursor=XCreateFontCursor(XtDisplay(widget),XtWindow(widget),XC_watch);
  i=0; XtSetArg(args[0],XtNcursor,cursor); i++;
  popup=XtCreatePopupShell("Popup",shellWidgetClass,widget, args,1);
  label=XtCreateManagedWidget("Label",labelWidgetClass,popup,NULL,0);
  XtPopup(popup,XtGrabNone);
}

main(argc,argv)
int argc;
char **argv;
{
static Widget top, button;
   top=XtInitialize(argv[0],"top",NULL,0,&argc,argv);
   callback[0].callback = buttonCallback;
   callback[0].closure  = NULL;
   i=0; XtSetArg(args[0],XtNcallback,callback); i++;
   button=XtCreateManagedWidget("button",commandWidgetClass,top,args,i);

   XtRealizeWidget(top);
   XtMainLoop();
}
-----------------------END TEST PROGRAM---------------------------------
-- 
Anil Somani                uucp: {sun|hplabs|amdahl|decwrl}!nsc!parns!somani\n\
National Semiconductor     Domain: somani@parns.nsc.com\n\
2900 Semiconductor Dr.     M/S D3-677\n\
Santa Clara, CA 95052-8090 Phone: (408)721-4146\n\

converse@EXPO.LCS.MIT.EDU (Donna Converse) (04/26/89)

To define a cursor effective for the entire popup widget and
all of its children, you must use XDefineCursor() after the widget
has been realized.  

In this case, you do not set the cursor for the individual
children of the popup widget, or on the popup widget itself,
at the time of widget creation.

XDefineCursor takes an argument indicating which cursor to use.
There are two ways to get this argument:
1. You may `hard code' the choice of cursor with an Xlib call,
such as XCreateFontCursor(dpy, XC_gumby)
2. If the application programmer wants to allow the user to set
his/her own cursor, then the cursor can be specified in an
application defaults file, and in that case, the name of the
cursor does not include the leading XC_ and the toolkit will
call XCreateFontCursor() for you.

The example code will work if the button callback is changed to:
{
static Widget popup, label;
Cursor cursor;
  cursor=XCreateFontCursor(XtDisplay(widget),XC_watch);                  
  popup=XtCreatePopupShell("Popup",shellWidgetClass,widget,NULL,0);
  label=XtCreateManagedWidget("Label",labelWidgetClass,popup,NULL,0);
  XtPopup(popup,XtGrabNone);
  XDefineCursor(XtDisplay(popup), XtWindow(popup), cursor);
}

The original example code had an extra argument
to XCreateFontCursor()