G5G has developed a specific GPHIGS widget to solve these problems. This widget ensures correct widget/graphic-window association. It manages the backing store and any possible expose events, additionally providing the capability of having only a part of the graphic window visible and of moving within the graphic window using scrollbars (without the difficulties which redisplay normally causes).
As a Motif widget it possesses resources. It is easy to set certain parameters specific to the graphic workstation by means of resources.
Widget creation:
XmCreateGPhigsW(parent, name, args, count);
parent parent of the widget
name name of the widget
args list of resource values to set
count number of resources to set
Example:
main(argc,argv)
int *argc;
char **argv;
{
Widget toplevel, r;
/* Initialization of toolkit */
toplevel = XtInitialize(argv[0],"test",NULL,&argc,argv);
/* open PHIGS */
popen_phigs("/dev/tty",-1);
/* Creation of GPHIGS widget */
r = XmCreateGPhigsW(toplevel,"GPHIGS",NULL,0);
XtRealize(toplevel);
XtMainLoop();
}
This small program creates a PHIGS graphics widget. The created workstation is the default workstation (1) and the driver is the default driver (X11). The utility XmIsGPhigsW(r) may be used to determine if r is a GPHIGS widget, in which case it returns true. If r is not a GPHIGS widget, it returns false.
The resources described below may be set with XtSetArg.
Example: To open workstation number 2 instead of the default (1), just add the following to the preceding program:
n = 0; XtSetArg(args[n], XmNwsid, 2); n++; r = XmCreateGPhigsW(toplevel,"GPHIGS",args,n);
where XmNwsid is the name of the resource workstation number.
The resources available for this widget are:
XmNwsid Workstation number (1 - 5, 1 by default).
XmNwidthWs Width of the graphic window (50 by default).
XmNheightWs Height of the graphic window (50 by default).
XmNlocdev Locator device number (1 by default).
XmNpickdev Pick device number (1 by default).
XmNnumButton Mouse button number to use for input (1 - 3, 1 by default).
XmNpressButton Activation by press or release for a pick or locator device.
XmNdepthPick Search depth for a PHIGS pick.
XmNresizeWs Window behavior during a widget resize.
XmNdeviceWs Device number used for graphic output (8887 by default (X11)).
XmNphigureWs To use widget with PhigureTM.
XmNwidgetDA To obtain workstation identifier.
The callbacks for the widget:
XmNlocatorCallback Callback returning the structure XmGPhigsLocatorStruct.
XmNpickCallback Callback returning the structure XmGPhigsPickStruct.
XmNcreateDACallback Callback to inform the user that the graphic window is mapped.
Note: This callback is active only once.
XmNresizeDACallback Callback to inform the user that the graphic window has been resized.
XmNexposeDACallback Callback to inform the user that the graphic window has received an expose event.
The questions listed above become trivial when the resources and callbacks are used. In effect:
1. The CSS may now be constructed, together with any display, in the function called by the callback XmNcreateDACallback. It is activated when the window is mapped on the screen, thus assuring that it is present and that we may draw inside it.
2. It is now associated with a widget for the user, in transparent mode at the moment of the creation of the GPHIGS widget, no matter which driver is used (X11, GLX, Starbase, XGL, etc.).
3. Locator and pick events are retrieved by callback and as a function of the resources that have been set up (button number, press or release, etc.).