return to first page linux journal archive
keywordscontents

Listing 2. sample.c, Version 2

/*
 *	Sample XView Program, Version 2
 *	- creates window frame
 *	- adds control panel with two buttons
 *	- adds text sub-window
 */
#include	<xview/xview.h>
#include	<xview/textsw.h>
#include	<xview/panel.h>
/*
 * fixed literal string, inserted into text
 * sub-window */
char	*heyyou = "Hey, you!\n";
/*
 * handle for the text sub-window */
Textsw	textpane;
/*
 * Callback function for the "Insert String"
 * button */
void insert_string(Panel_item item, Event *event)
{
	textsw_insert(textpane, heyyou,
		strlen(heyyou));
}
/*
 * Callback function for the "Clear Window"
 * button */
void clear_window(Panel_item item, Event *event)
{
	textsw_reset(textpane, 0, 0);
}
/*
 * Mainline for sample program, version 2 */
void main(int argc, char *argv[])
{
	Frame	frame;
	Panel	panel;
	/*
	 * let XView scan command-line arguments */
	xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, &argv,
		NULL);
	/* create a top level frame */
	frame = (Frame)xv_create(XV_NULL, FRAME,
			FRAME_LABEL,	argv[0],
			XV_WIDTH,	300,
			XV_HEIGHT,	200,
			NULL);
	/* add a control panel to the frame */
	panel = (Panel)xv_create(frame, PANEL,
		XV_X,		0,
		XV_Y,		0,
		XV_WIDTH,	WIN_EXTEND_TO_EDGE,
		XV_HEIGHT,	30,
		WIN_BORDER,	FALSE,
		NULL);
	/* add a button to the control panel */
	(void)xv_create(panel, PANEL_BUTTON,
		PANEL_LABEL_STRING,	"Insert String",
		PANEL_NOTIFY_PROC,	insert_string,
		NULL);
	/* add another button to the control panel */
	(void)xv_create(panel, PANEL_BUTTON,
		PANEL_LABEL_STRING,	"Clear Window",
		PANEL_NOTIFY_PROC,	clear_window,
		NULL);
	/* add the text sub-window to the frame */
	textpane = xv_create(frame, TEXTSW, NULL);
	/*
	 * let XView handle all events for us */
	xv_main_loop(frame);
	exit(0);
	}