Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!bloom-beacon!GATEWAY.MITRE.ORG!sbuck From: sbuck@GATEWAY.MITRE.ORG (Steve Buck) Newsgroups: comp.windows.x Subject: re: graphics and widgets Message-ID: <8908161508.AA12805@gateway.mitre.org> Date: 16 Aug 89 15:08:25 GMT References: <8908161014.AA08537@gateway.mitre.org> Sender: daemon@bloom-beacon.MIT.EDU Organization: The Internet Lines: 98 > out in the manuals, sigh. Anyway all you need to display graphics > is the Display and Window id of the widget you want to draw into > (plus of course a suitable graphics context). To retrieve the Display Ok, here is a section of code that I use to create the GC and when I try to run it it gives me 'X Protocol error: BadDrawable, invalid Pixmap or Window parameter' Widget dispwin; Window displaywin; . . . /* get window from widget */ displaywin = XtWindow (dispwin); /* create GC for text and drawing */ get_GC(displaywin, &gc, font_info); /* Ask parents to manage children */ XtManageChild (dispwin); /* Realize widget tree */ XtRealizeWidget (win); /* Start event processing loop */ XtAppMainLoop (app_context); } void get_GC (displaywin, gc, font_info) Window displaywin; GC *gc; XFontStruct *font_info; { /* create default graphics context */ *gc = XCreateGC (display, displaywin, 0, NULL); /* specify font */ XSetFont (display, *gc, font_info->fid); /* specify black foreground since default may be white on white */ XSetForeground (display, *gc, BlackPixel(display, screen)); } > and Window id from a widget use ... XtDisplay(w) and XtWindow(w). Nothing > could be simpler! eg: > > XDrawLine(XtDisplay(w), XtWindow(w), gc, 0, 0, 10, 20); > > However ... a word of warning this will not work until the window has been > realized and mapped and has received the first ConfigureNotify event. > ie. The Server will ignore these requests as it has no real window to draw > into. So what you need to do is to capture the first ConfigureNotify event > either using a translation string ": turn_on_graphics()" > or using XtAddEventHandler(w, ... ), the choice is yours, plus you > need to capture resize and expose events for redrawing, so a suitable > XtNtranslations string for your drawing widget might be... > > ": turn_on_graphics() resize()\n\ > : redraw()" > Ok, I also have the problem that when I try to add the procedure draw_graphics to the translation table it comes back with the error 'X Toolkit Warning: Actions not found: draw_graphics. Here is how I'm changing the translation table: XtTranslations DisplayTrans; static char DisplayTransTable[]= ": draw_graphics() \n\ : draw_graphics()"; . . . /* create display window */ i = 0; XtSetArg(args[i], XtNx, 2); i++; XtSetArg(args[i], XtNy, 152); i++; XtSetArg(args[i], XtNwidth, 600); i++; XtSetArg(args[i], XtNheight, 600); i++; XtSetArg(args[i], XtNborderWidth, border_width); i++; dispwin = XtCreateWidget ("window", formWidgetClass, win, args, i); /* modify translation table */ DisplayTrans = XtParseTranslationTable(DisplayTransTable); XtAugmentTranslations (dispwin, DisplayTrans); Any ideas as to what is wrong would be appreciated. Thanks, -- -- Steve Buck The MITRE Corporation, Networking Center McLean, Virginia phone: (703) 883-5574 email: sbuck@gateway.mitre.org