fm@neptune.iex.com (Mohammad Faroog) (03/13/91)
Would you please put some light on stub widget. I want to capture keyboard and mouse events in the stub widget's window. I can capture mouse events but I don't have luck with keyboard event. Do I have to do any black magic. I there a better way to flash a button ( oblongButton ) continously. The way I do it by using XtAppAddTimeOut(). Please send me direct mail. Thanks. My address is : fm@iex.comp Following is the code example : Translation table : *clearButton.label:Clear area *lineButton.label:Draw line *boxButton.label:Draw box *circleButton.label:Draw circle *exitButton.label:Exit editor *drawArea.width:1 *drawArea.height:1 *drawArea.y:50 *drawArea.translations: #override\n\ <Btn1Down>:eventhandler()\n\ <Btn1Up>:eventhandler()\n\ <Btn1Motion>:eventhandler()\n\ <Key>:eventhandler() ------------------------- #include <stdio.h> #include <errno.h> #include <X11/Intrinsic.h> #include <X11/StringDefs.h> #include <Xol/OlMinStr.h> #include <Xol/OpenLook.h> #include <Xol/ControlAre.h> #include <Xol/Form.h> #include <Xol/OblongButt.h> #include <Xol/Stub.h> #define BITMAP_FILE "us.bitmap" XtActionProc EventHandler(w,event,param,num) Widget w; XEvent *event; String *param; Cardinal *num; { puts("in event"); } CBExit(w,client_data,call_data) Widget w; caddr_t client_data, call_data; { exit(); } void main(argc, argv) unsigned int argc; char *argv[]; { Widget w_toplevel, w_form, w_button, w_control, w_draw; int drawImage(); static XtActionsRec new_actions[] = { {"eventhandler",(XtActionProc) EventHandler} }; XtAppContext app_context; w_toplevel = OlInitialize( NULL, /* app name - filled by Xt */ "Ged", /* app class */ NULL, /* option list */ 0, /* # of options */ &argc, /* addr of main argc */ argv /* main argv */ ); app_context = XtWidgetToApplicationContext(w_toplevel); XtAppAddActions(app_context,new_actions,XtNumber(new_actions)); w_form = XtVaCreateManagedWidget( /* create form widget */ "formArea", formWidgetClass, w_toplevel, XtNborderWidth,1, XtNxResizable,FALSE, XtNyResizable, FALSE, NULL ); w_control = XtVaCreateManagedWidget( /* create form widget */ "controlArea", controlAreaWidgetClass, w_form, XtNlayoutType,OL_FIXEDROWS, XtNmeasure, 1, XtNborderWidth,1, NULL ); w_button = XtVaCreateManagedWidget( /* create form widget */ "clearButton", oblongButtonWidgetClass, w_control, NULL ); w_button = XtVaCreateManagedWidget( /* create form widget */ "lineButton", oblongButtonWidgetClass, w_control, NULL ); w_button = XtVaCreateManagedWidget( /* create form widget */ "boxButton", oblongButtonWidgetClass, w_control, NULL ); w_button = XtVaCreateManagedWidget( /* create form widget */ "circleButton", oblongButtonWidgetClass, w_control, NULL ); w_button = XtVaCreateManagedWidget( /* create form widget */ "exitButton", oblongButtonWidgetClass, w_control, NULL ); XtAddCallback(w_button,XtNselect,CBExit,NULL); w_draw = XtVaCreateManagedWidget( "drawArea", stubWidgetClass, w_form, XtNexpose, drawImage, NULL ); (void) XtRealizeWidget(w_toplevel); (void) XtMainLoop(); } drawImage(wid, event, region) Widget wid; XEvent *event; Region region; { XExposeEvent *expose = &event->xexpose; static Pixmap bitmap; static GC gc; static Boolean inited = FALSE; /* * The first time we get called, read in the bitmap * and initialize a graphics context for drawing the image. */ if (inited == FALSE) { XGCValues xgc; Status status; unsigned int width, height; int xhot, yhot; status = XReadBitmapFile( XtDisplay(wid), /* display */ XtWindow(wid), /* any drawable */ BITMAP_FILE, /* file name */ &width, /* returns width */ &height, /* returns height */ &bitmap, /* returns bitmap */ &xhot, /* returns x hotspot */ &yhot /* returns y hotspot */ ); if (status != BitmapSuccess) fprintf(stderr,"XReadBitmapFile Failed\n"); XtVaSetValues( wid, XtNwidth, width, XtNheight, height, NULL); xgc.foreground = XWhitePixelOfScreen(XtScreen(wid)); xgc.background = XBlackPixelOfScreen(XtScreen(wid)); gc = XCreateGC( XtDisplay(wid), /* display */ XtWindow(wid), /* drawable */ GCForeground | GCBackground, /* values to set */ &xgc /* values */ ); inited = TRUE; } XCopyPlane( XtDisplay(wid), /* display */ bitmap, /* bitmap */ XtWindow(wid), /* drawable */ gc, /* graphics context */ expose->x, /* src x */ expose->y, /* src y */ expose->width, /* width */ expose->height, /* height */ expose->x, /* dst x */ expose->y, /* dst y */ 1 /* plane mask */ ); return; } Mohammad.
aim@Corp.Sun.COM (Amy) (03/14/91)
>>From owner-openlook@uunet.uu.net Wed Mar 13 01:33:55 1991 >>To: openlook@uunet.UU.NET >>Path: unify!csusac!ucdavis!csus.edu!decwrl!elroy.jpl.nasa.gov!usc!cs.utexas.edu!solo.csci.unt.edu!iex!neptune!fm >>Newsgroups: comp.windows.open-look >>Subject: OLIT/Stub widget ???? >>Sender: iex!news@uunet.UU.NET (USENET news) >>Organization: IEX Corporation >>Lines: 221 >> >>Would you please put some light on stub widget. I want to capture keyboard and >>mouse events in the stub widget's window. I can capture mouse events but I >>don't have luck with keyboard event. Do I have to do any black magic. In OLIT2.0 (comes with OpenWindows V2), there were problems getting translations to work for keys in Non-text widgets (such as the Stub). The good news is that this problem has been fixed for the next version of OLIT...(it was essentially fixed in USL's Release 4 of the toolkit, which was released in December). unfortunately I know of no workaround for OLIT2.0. :( Regards, Amy Moore aim@sun.com >>