示例#1
0
/*
 * Initialize a term_data
 */
static errr term_data_init(term_data *td, Widget topLevel,
                           int key_buf, String name,
                           ArgList widget_arg, Cardinal widget_arg_no, int i)
{
	Widget parent;
	term *t = &td->t;

	int cols = 80;
	int rows = 24;

	char buf[80];
	cptr str;

	int val;

	/* Create the shell widget */
	parent = XtCreatePopupShell(name, topLevelShellWidgetClass, topLevel,
	                            NULL, 0);

	/* Window specific cols */
	sprintf(buf, "ANGBAND_X11_COLS_%d", i);
	str = getenv(buf);
	val = (str != NULL) ? atoi(str) : -1;
	if (val > 0) cols = val;

	/* Window specific rows */
	sprintf(buf, "ANGBAND_X11_ROWS_%d", i);
	str = getenv(buf);
	val = (str != NULL) ? atoi(str) : -1;
	if (val > 0) rows = val;

	/* Hack the main window must be at least 80x24 */
	if (i == 0)
	{
		if (cols < 80) cols = 80;
		if (rows < 24) rows = 24;
	}

	/* Reset the initial size */
	widget_arg[0].value = rows;
	widget_arg[1].value = cols;

	/* Create the interior widget */
	td->widget = (AngbandWidget)
	XtCreateManagedWidget(name, angbandWidgetClass,
	                      parent, widget_arg, widget_arg_no);

	/* Initialize the term (full size) */
	term_init(t, cols, rows, key_buf);

	/* Use a "soft" cursor */
	t->soft_cursor = TRUE;

	/* Erase with "white space" */
	t->attr_blank = TERM_WHITE;
	t->char_blank = ' ';

	/* Hooks */
	t->xtra_hook = Term_xtra_xaw;
	t->curs_hook = Term_curs_xaw;
	t->wipe_hook = Term_wipe_xaw;
	t->text_hook = Term_text_xaw;

	/* Save the data */
	t->data = td;

	/* Register the keypress event handler */
	XtAddEventHandler((Widget)td->widget, KeyPressMask,
	                  False, (XtEventHandler) handle_event, td);

	/* Redraw callback */
	XtAddCallback((Widget)td->widget, XtNredrawCallback,
	              react_redraw, td);

	/* Realize the widget */
	XtRealizeWidget(parent);

	/* Make it visible */
	XtPopup(parent, XtGrabNone);

	/* Activate (important) */
	Term_activate(t);

	Resize_term(td->widget);

	return 0;
}
示例#2
0
/*
 * Initialize a term_data
 */
static errr term_data_init(term_data *td, Widget topLevel,
                           int key_buf, String name,
                           ArgList widget_arg, Cardinal widget_arg_no, int i)
{
	Widget parent;
	term *t = &td->t;

	int cols = 80;
	int rows = 24;

	char buf[80];
	cptr str;

	int val;

	/* Create the shell widget */
	parent = XtCreatePopupShell(name, topLevelShellWidgetClass, topLevel,
	                            NULL, 0);

	/* Window specific cols */
	sprintf(buf, "ANGBAND_X11_COLS_%d", i);
	str = getenv(buf);
	val = (str != NULL) ? atoi(str) : -1;
	if (val > 0) cols = val;

	/* Window specific rows */
	sprintf(buf, "ANGBAND_X11_ROWS_%d", i);
	str = getenv(buf);
	val = (str != NULL) ? atoi(str) : -1;
	if (val > 0) rows = val;

	/* Hack the main window must be at least 80x24 */
	if (i == 0)
	{
		if (cols < 80) cols = 80;
		if (rows < 24) rows = 24;
	}

	/* Reset the initial size */
	widget_arg[0].value = rows;
	widget_arg[1].value = cols;

	/* Hack  ox==oy in xaw port */

	/* Window specific inner border offset (ox) */
	sprintf(buf, "ANGBAND_X11_IBOX_%d", i);
	str = getenv(buf);
	val = (str != NULL) ? atoi(str) : -1;
	if (val > 0) widget_arg[6].value = val;

	/* Window specific inner border offset (oy) */
	sprintf(buf, "ANGBAND_X11_IBOY_%d", i);
	str = getenv(buf);
	val = (str != NULL) ? atoi(str) : -1;
	if (val > 0) widget_arg[6].value = val;

	/* Create the interior widget */
	td->widget = (AngbandWidget)
	XtCreateManagedWidget(name, angbandWidgetClass,
	                      parent, widget_arg, widget_arg_no);

	/* Initialize the term (full size) */
	term_init(t, cols, rows, key_buf);

	/* Use a "soft" cursor */
	t->soft_cursor = TRUE;

	/* Erase with "white space" */
	t->attr_blank = TERM_WHITE;
	t->char_blank = ' ';

	/* Hooks */
	t->xtra_hook = Term_xtra_xaw;
	t->curs_hook = Term_curs_xaw;
	t->wipe_hook = Term_wipe_xaw;
	t->text_hook = Term_text_xaw;

	/* Save the data */
	t->data = td;

	/* Register the keypress event handler */
	XtAddEventHandler((Widget)td->widget, KeyPressMask,
	                  False, (XtEventHandler) handle_event, td);

	/* Redraw callback */
	XtAddCallback((Widget)td->widget, XtNredrawCallback,
	              react_redraw, td);

	/* Realize the widget */
	XtRealizeWidget(parent);

	/* Have we redefined the font? */
	if (streq(td->widget->angband.font, DEFAULT_X11_FONT))
	{
		XFontStruct *fnt;

		/* Check if the font exists */
		fnt = getFont(td->widget, (String) get_default_font(i), FALSE);

		/* The font didn't exist */
		if (fnt == NULL)
		{
			XtWarning("Couldn't find the requested font!");
		}
		else
		{
			int height, width;

			/* Free the old font */
			XFreeFont(XtDisplay((Widget)td->widget), td->widget->angband.fnt);

			/* Update font information */
			td->widget->angband.fontheight = fnt->ascent + fnt->descent;
			td->widget->angband.fontwidth = fnt->max_bounds.width;
			td->widget->angband.fontascent = fnt->ascent;

			for (i = 0; i < NUM_COLORS; i++)
			{
				/* Be sure the correct font is ready */
				XSetFont(XtDisplay((Widget)td->widget),
					 td->widget->angband.gc[i], fnt->fid);
			}

			/* Get the window shape */
			height = (td->widget->angband.start_rows *
				td->widget->angband.fontheight +
				2 * td->widget->angband.internal_border);
			width = (td->widget->angband.start_columns *
				td->widget->angband.fontwidth +
				2 * td->widget->angband.internal_border);

			/* Request a change to the new shape */
			if (XtMakeResizeRequest((Widget)td->widget,
				 width, height, NULL, NULL) == XtGeometryNo)
			{
				/* Not allowed */
				XtWarning("Size change denied!");
			}
			else
			{
				/* Recalculate size hints */
				calculateSizeHints(td->widget);
			}
		}
	}

	/* Make it visible */
	XtPopup(parent, XtGrabNone);

	/* Activate (important) */
	Term_activate(t);


	Resize_term(td->widget);

	return 0;
}