Trusted Solaris Developer's Guide

Source Code

This is the source code for the simple Motif applications shown in Figure 14-1 and Figure 14-2. Launch it with any command line argument to see the text label string in italic font in the label widget.

Resource File

Here is the Resource file for the simple Motif application. One way to use it is to create the file and set the XENVIRONMENT variable with the pathname.


phoenix% setenv XENVIRONMENT /export/home/zelda/resfile
Example.*geometry: 400X100
Example.*orientation: XmHORIZONTAL
Example.*label.labelString: Launch an application
Example.*xclock.labelString: Run xclock
Example.*xterm.labelString: Run xterm
Example.*xmag.labelString: Run xmag
Example.*goodbye.labelString: Quit
Example.*XmPushButton*background: blue
Example.*XmLabel*foreground: white
Example.*XmLabel*foreground: white

Compile Command


phoenix% cc -I/usr/openwin/include -I/usr/dt/include ex.c -o Example \
-L/usr/openwin/lib -L/usr/dt/lib -lXm -lXt -lX11 -lXtsol -ltsol -lDtTsol

Code

#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <Xm/Xm.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
#include <Xm/Form.h>
#include <tsol/Xtsol.h>
#include <Dt/label_clipping.h>

XTsolResAttributes winattrs;
int retval, error;
uid_t uid;
Window window;
Display *display;
char *string = (char *)0, *string1 = (char *)0, *string2 = (char *)0,
	*string3 = (char *)0, *string4 = "SECRET";
XmFontList fontlist;
XmString xmstr;
XFontStruct *italic;
Arg args[9];
Dimension width = 144;
Widget stringLabel;
bslabel_t senslabel;
bclabel_t cmwlabel;

/* Callbacks */

void Xclock(Widget w, caddr_t client_data, caddr_t call_data)
{ system("xclock &"); }

void Xterm(Widget w, caddr_t client_data, caddr_t call_data)
{ system("xterm &"); }

void Quit(Widget w, caddr_t client_data, caddr_t call_data)
{
	fprintf(stderr, "exiting  . . .\n");
	exit(0);
}
main(int argc, char **argv)
{
	Widget rowcolumn, label, xclock, xterm, quit, form, topLevel;
	int i = 0;
	Arg args[9];

/* Create Widgets */
	topLevel = XtInitialize(argv[0], "XMCmds1", NULL, 0, &argc, argv);
	form = XtCreateManagedWidget("form", xmFormWidgetClass, 
	       topLevel, NULL, 0);

/* Launch application with any command argument to use the */
/* Text label string and font list for the label widget */

	if (argc == 2) {
/* Create the font list and translate the label using it */
		retval = getcmwplabel(&cmwlabel);
		getcsl(&senslabel, &cmwlabel);
		italic = XLoadQueryFont(XtDisplay(topLevel),
			"-adobe-times-medium-i-*-*-14-*-*-*-*-*-iso8859-1");
		fontlist = XmFontListCreate(italic, "italic");
		xmstr = (XmString)Xbsltos(XtDisplay(topLevel), &senslabel,
			width, fontlist, LONG_WORDS);

/* Create a label widget using the font list and label text*/
		i=0;
		XtSetArg(args[i], XmNfontList, fontlist); i++;
		XtSetArg(args[i], XmNlabelString, xmstr); i++;
		label = XtCreateManagedWidget("label", xmLabelWidgetClass, 
			form, args, i);
	}

/* Launch application with no command arguments to use the text */
/* in the resource file for the label widget */

	else {
		label = XtCreateManagedWidget("label", xmLabelWidgetClass, 
		        form, NULL, 0); }

/* Continue widget creation */
	i=0;
	XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
	XtSetArg(args[i], XmNtopWidget, label); i++;
	XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
	XtSetArg(args[i], XmNrightAttachment, XmATTACH_POSITION); i++;
	XtSetArg(args[i], XmNrightPosition, 33); i++;
	XtSetArg(args[i], XmNbottomAttachment, XmATTACH_FORM); i++;
	xclock = XtCreateManagedWidget("xclock", xmPushButtonWidgetClass, 
	   form, args, i);

	i=0;
	XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
	XtSetArg(args[i], XmNtopWidget, label); i++;
	XtSetArg(args[i], XmNleftAttachment, XmATTACH_POSITION); i++;
	XtSetArg(args[i], XmNleftPosition, 33); i++;
	XtSetArg(args[i], XmNrightAttachment, XmATTACH_POSITION);i++;Ha>