Path: utzoo!attcan!uunet!lll-winken!ames!pasteur!ucbvax!bloom-beacon!ATHENA.MIT.EDU!swick From: swick@ATHENA.MIT.EDU (Ralph R. Swick) Newsgroups: comp.windows.x Subject: Re: Novice question about using raw Xlib for drawing in a widget. Message-ID: <8901171309.AA11516@LYRE.MIT.EDU> Date: 17 Jan 89 13:09:48 GMT References: <5520@phoenix.Princeton.EDU> Sender: daemon@bloom-beacon.MIT.EDU Organization: DEC/MIT Project Athena Lines: 91 > First, if I put the line ": draw()\n" in my translation table > draw() does not end up being called even though ": draw()\n" > does cause draw to be called. What is the deal? I dunno. The following patch to X11R3/examples/Xaw/xcommand.c seems to do what you and I would expect. Perhaps you can figure out what you're missing from this. *** X11R3/examples/Xaw/xcommand.c --- /tmp/f.c *************** *** 1,6 **** --- 1,7 ---- #include #include #include + #include static XrmOptionDescRec options[] = { {"-label", "*label", XrmoptionSepArg, NULL} *************** *** 22,33 **** --- 23,64 ---- printf( "button was activated.\n" ); } + void Exposed(w, event, params, param_count) + Widget w; + XEvent *event; + String *params; + Cardinal *param_count; + { + printf( "button was exposed.\n" ); + } + void Draw(w, event, params, param_count) + Widget w; + XEvent *event; + String *params; + Cardinal *param_count; + { + static GC gc; + if (gc == NULL) { + XGCValues values; + Arg args[2]; + XtSetArg( args[0], XtNforeground, &values.foreground ); + XtSetArg( args[1], XtNbackground, &values.background ); + XtGetValues( w, args, (Cardinal)2 ); + gc = XtGetGC( w, GCForeground | GCBackground, &values ); + } + XDrawPoint( XtDisplay(w), XtWindow(w), gc, + event->xmotion.x, event->xmotion.y ); + } + + + void main(argc, argv) unsigned int argc; char **argv; { Widget toplevel; + Widget c; static XtCallbackRec callbacks[] = { { Activate, NULL }, { NULL, NULL }, *************** *** 42,49 **** --- 73,95 ---- if (argc != 1) Syntax(argv[0]); + c = XtCreateManagedWidget( "command", commandWidgetClass, toplevel, args, XtNumber(args) ); + + { + static XtActionsRec actions[] = { + { "expose", Exposed }, + { "draw", Draw }, + }; + XtAddActions( actions, XtNumber(actions) ); + } + XtOverrideTranslations( c, + XtParseTranslationTable( + ": expose() \n\ + : draw() " + ) + ); XtRealizeWidget(toplevel); XtMainLoop();