⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xpig.c

📁 Programs in the irregular grid design package described in this manual are used to carry out five ma
💻 C
📖 第 1 页 / 共 5 页
字号:
		command_window,		(Widget)NULL, 		(Widget)NULL, 		layout);	/* call set window rect function to get window rects to initial settings */	iXPigSetWindowRects();/* PIGDBG2("Calling iXPigRepaint() int WinPigMain() \n"); */	/* iXPigRepaint(); */	/* Now, map the widget */PIGDBG3("Calling XtMapWidget(toplevel)\n");	XtMapWidget(toplevel);PIGDBG3("Returned from XtMapWidget(toplevel)\n");}void  WPigMain(        Long (*InitFnc)(void),       Long (*MenuFnc)( const Long * item),       Long (*MousFnc)( const Long * window, 		const Long * button, 		const float * x, 		const float * y),       Long (*StriFnc)( const Long * length, 		const char * string, 		const Long dummy_len)		){PIGDBG3("%s %s %s %s\n",		"void  WPigMain( Long (*InitFnc)(void),",                     "Long (*MenuFnc)( const Long * item),",                     "Long (*MousFnc)( const Long * window, const Long * button, const float * x, const float * y)",                     "Long (*StriFnc)( const Long * length, const char * string, Long dummy_len) )");	FuncPtrs.InitFnc = InitFnc;	FuncPtrs.MenuFnc = MenuFnc;	FuncPtrs.MousFnc = MousFnc;	FuncPtrs.StriFnc = StriFnc;	/* disable menu here */	iXPig_disable_menus();PIGDBG3("JUST BEFORE CALL TO INITFUNC**********\n");	iXPig_call_init();PIGDBG3("JUST AFTER CALL TO INITFUNC**********\n");	/* enable menu here */	iXPig_enable_menus();
/* call to XtAppMainLoop moved to main() to support repeated calls to WPigSetHandlers */
/* agd June 1998 */
	/* Call the X main loop for event processing *//* PIGDBG3("JUST BEFORE CALL TO XtAppMainLoop**********\n"); *//* 	XtAppMainLoop(context); */	return;}typedef struct {	Dimension LineWidth;	Font MainWindowFont;	Font ControlPanelFont;	} Appres;static Appres appres;/*----------------------------------------------------------------------------*/static void  iXPigGetTextExtent (const char * string, float *the_width, float *the_height, float *the_ascent, float *the_descent){	int		dir, dummy_height, dummy_width;	XCharStruct	char_struct;PIGDBG2("iXPigGetTextExtent (const char * string, float *the_width, float *the_height, float *the_ascent, float *the_descent)");	switch(current_pig_window) {	case PIG_MAIN_WIN:		case PIG_PROFILE_WIN:			XSetFont(XtDisplay(CurrentXCanvas), GraphicsContext, appres.MainWindowFont);		break;	case PIG_CONTROL_WIN:			XSetFont(XtDisplay(CurrentXCanvas), GraphicsContext, appres.ControlPanelFont);		break;	}	XTextExtents(XQueryFont(XtDisplay(CurrentXCanvas), XGContextFromGC(GraphicsContext)), string, strlen(string), 			&dir, &dummy_height, &dummy_width, &char_struct);	PIGDBG2("direction = %d\nheight = %d\nwidth = %d\nchar_struct.ascent: %d\n"			"char_struct.descent: %d\nchar_struct.width: %d\n", 				dir, dummy_height, dummy_width, 				char_struct.ascent,  char_struct.descent, char_struct.width);	*the_width   = (float) (char_struct.width);	*the_height  = (float) (char_struct.ascent + char_struct.descent);	*the_ascent  = (float) (char_struct.ascent);	*the_descent = (float) (char_struct.descent);	PIGDBG2("the_width :%f\nthe_height :%f\nthe_ascent :%f\nthe_descent :%f\n",		*the_width, *the_height, *the_ascent, *the_descent);	return;}/*----------------------------------------------------------------------------*/void  WPigDrawText( const float *x, const float *y, const char * string, const Long dummy_len){PIGDBG1("void  WPigDrawText(%f,%f,[%s],%li)\n", *x, *y, string, dummy_len); PIGDBG1("current_pig_window = %li\n", current_pig_window);	if (current_pig_window == PIG_STATUS_WIN) {		show_message(string);	} else {		short		x_text, y_text;		double		x_in, y_in;		float		text_width, text_height, text_ascent, text_descent;		switch(current_pig_window) {		case PIG_MAIN_WIN:			case PIG_PROFILE_WIN:				XSetFont(XtDisplay(CurrentXCanvas), GraphicsContext, appres.MainWindowFont);			break;		case PIG_CONTROL_WIN:				XSetFont(XtDisplay(CurrentXCanvas), GraphicsContext, appres.ControlPanelFont);			break;		}PIGDBG1("void  WPigDrawText(%f,%f,[%s],%li)\n", *x, *y, string, dummy_len); 		x_in = (double) *x;		y_in = (double) *y;		iXPigResolvePoint(x_in, y_in, &x_text, &y_text);		iXPigGetTextExtent(string, &text_width, &text_height, &text_ascent, &text_descent);        	switch (Vert_align) {                	case BASE_ALIGN:        y_text = y_text;                                        	break;                	case TOP_ALIGN:         y_text = y_text + (int)(text_ascent);                                        	break;                	case BOTTOM_ALIGN:      y_text = y_text - (int)(text_descent);                                        	break;        	}        	switch (Horiz_align) {                	case LEFT_ALIGN:        x_text = x_text;                                        	break;                	case CENTRE_ALIGN:      x_text = x_text - (int)(text_width / 2);                                        	break;                	case RIGHT_ALIGN:       x_text = x_text - (int) text_width;                                        	break;        	}	XSetForeground(XtDisplay(CurrentXCanvas), GraphicsContext, CmsColourDefs[XTextColour]);	XDrawString(XtDisplay(CurrentXCanvas), XtWindow(CurrentXCanvas), 		GraphicsContext, x_text, y_text,		string, strlen(string));	XSetForeground(XtDisplay(CurrentXCanvas), GraphicsContext, CmsColourDefs[XForegrColour]);	}}/*----------------------------------------------------------------------------*/static void iXPigGetString( const char *prompt, Long *anslen, char *string){	XmString	question_string, answer_string;        Arg             args[20];        Cardinal        n;PIGDBG("iXPigGetString(%s,%li,%s)\n", prompt, *anslen, string);	PIGDBG2("\n\n\t\tPROMPT\n\n%s [%s]: \n", prompt, string); 	question_string = XmStringCreateSimple(prompt);	answer_string = XmStringCreateSimple(string);	n =  0;	XtSetArg(args[n], XmNselectionLabelString, question_string); n++;	XtSetArg(args[n], XmNtextString, answer_string); n++;	XtSetValues(string_question_dialog, args, n);	XmStringFree(question_string);	XmStringFree(answer_string);	XtManageChild(string_question_dialog);	callback_data.reason = xpACTIVE;	callback_data.name = "GetString";	while(callback_data.reason == xpACTIVE) {		XtAppProcessEvent(context, XtIMAll);	}	XtUnmanageChild(string_question_dialog);	switch (callback_data.reason) {	case xpOK:		(void)strncpy(string, callback_data.answer,*anslen);		*anslen = strlen(string);		break;	default:		string[0] = '\0';		*anslen = 0;	}	PIGDBG("\nString read has %li characters, and was %s\n\n", *anslen, string);	PIGDBG("Returning from iXPigGetString(%s,%li,%s)\n", prompt, *anslen, string);}/*----------------------------------------------------------------------------*/void  WPigGetString( const char *prompt, Long *anslen, char * string, const Long dummy_len1, const Long dummy_len2){	iXPigGetString( prompt, anslen, string);}/*----------------------------------------------------------------------------*/static Long iWPigGetOpenFileName(const char *prompt, char *name, const char *tmpl){	Long anslen = strlen(name);PIGDBG("Long iWPigGetOpenFileName(%s, %s, %s)\n", prompt, name, tmpl);	/*  */	/* if file selection dialog does not work on linux systems, then */	/* it may be that an old version of libc.so is being used */	/* The version must be at least 4.6.27 */	/* To check the version being used, use one of the following */	/* commands: */	/* 	ldconfig -p */	/* or */	/* 	ldd program_name */	/*  */	{        	Arg             args[20];        	Cardinal        n;		XmString X_string_prompt;		XmString X_string_pattern;		/* load question into selection_dialog */		X_string_prompt = XmStringCreateSimple(prompt);/* tmpl contains alternating labels and masks, separated by '|' characters, *//* as required for MS-Windows *//* For Motif dialog box, we cannot use most of this information, so we *//* simply discard most of it. We do need to set the initial filter though, *//* and that is in the first mask. */		{			char *s = strtok((char *)tmpl, "|");			s = strtok(NULL, "|");			PIGDBG("File mask selected is %s\n", s);						X_string_pattern = XmStringCreateSimple(s);		}		n = 0;		/* initialize label */       		XtSetArg(args[n], XmNselectionLabelString, X_string_prompt); n++;		/* initialize default answer *//* don't know how right now! */		/* initialize filter string */       		XtSetArg(args[n], XmNpattern, X_string_pattern); n++;       		XtSetValues(file_selection_dialog, args, n);		XmStringFree(X_string_prompt);		XmStringFree(X_string_pattern);	}	XtManageChild(file_selection_dialog);	callback_data.name = "GetFile";        callback_data.reason = xpACTIVE;        while(callback_data.reason == xpACTIVE) {                XtAppProcessEvent(context, XtIMAll);        }	XtUnmanageChild(file_selection_dialog);	switch (callback_data.reason) {	case xpOK:		PIGDBG("callback_data.answer=[%s]\n", callback_data.answer);		PIGDBG("anslen=%li\n", (long)anslen);		(void *)strncpy(name,callback_data.answer,(anslen-1));		PIGDBG("name=[%s]\n", name);		break;	default:		name[0] = '\0';	}/* pause(); */	/* { */		/* char *end; */		/* end = strchr(name,' '); */		/* if(end != NULL) */			/* *end = '\000'; */		/* iXPigGetString( prompt, &anslen, name); */	/* } */PIGDBG("returning from Long iWPigGetOpenFileName(%s, %s, %s)\n", prompt, name, tmpl);	/* return false if null string entered - user quit operation */	if(strlen(name)==0) return FALSE;	/* otherwise return true */	return TRUE;}/*----------------------------------------------------------------------------*/Long WPigGetOpenFileName(const char *prompt, char *name, const char *tmpl, const Long dummy_len1, const Long dummy_len2, const Long dummy_len3){PIGDBG1("Long WPigGetOpenFileName(%s, %s, %s)\n", prompt, name, tmpl);	return iWPigGetOpenFileName(prompt, name, tmpl);}/*----------------------------------------------------------------------------*/Long WPigGetSaveFileName(const char *prompt, char *name, const char *tmpl, const Long dummy_len1, const Long dummy_len2, const Long dummy_len3){PIGDBG1("Long WPigGetSaveFileName(%s, %s, %s)\n", prompt, name, tmpl);	return iWPigGetOpenFileName(prompt, name, tmpl);}/*----------------------------------------------------------------------------*/void WPigCursPrompt( char *reply, const Long *noptions, const char * question, const char * answers, const Long dummy_len1, const Long dummy_len2, const Long dummy_len3){	int 		i, j, len;	XmString	X_string;	XmString	X_string_blank;	char		*item_string;        Arg             args[20];        Cardinal        n;PIGDBG1("void WPigCursPrompt(%s,%li,%s,%s,%li,%li,%li)\n", reply, *noptions, question, answers, dummy_len1, dummy_len2, dummy_len3);	/* load question into selection_dialog */	X_string = XmStringCreateSimple(question);	X_string_blank = XmStringCreateSimple("");	n = 0;        XtSetArg(args[n], XmNselectionLabelString, X_string); n++;	/* set answer to blank */        XtSetArg(args[n], XmNtextString, X_string_blank); n++;        XtSetValues(selection_dialog, args, n);	XmStringFree(X_string);	XmStringFree(X_string_blank);	/* load answers into selection_dialog's child list - selection_list_widget */	/* item_string = strdup(answers); */ /* this fails because it only copies the first item! */	item_string = (char *)answers;	XmListDeleteAllItems(selection_list_widget);	for (i = 0; i < (int) *noptions; i++) {		X_string = XmStringCreateSimple(item_string);		XmListAddItem(selection_list_widget, X_string, 0);		if(i == 0) {			XmListSelectItem(selection_list_widget, X_string, False);			n = 0;			/* set answer to first item */       			XtSetArg(args[n], XmNtextString, X_string); n++;       			XtSetValues(selection_dialog, args, n);		}		XmStringFree(X_string);		/* advance item_string to next item */		len = strlen(item_string);		for (j = 0; j < len + 1; j++) {			item_string++;		}	}	/* free(item_string); */	XtManageChild(selection_dialog);        callback_data.reason = xpACTIVE;        while(callback_data.reason == xpACTIVE) {                XtAppProcessEvent(context, XtIMAll);        }	XtUnmanageChild(selection_dialog);	/* reply[0] = selection_box_value[0]; */	reply[0] = callback_data.answer[0];}/*----------------------------------------------------------------------------*/void WPigCursYesNo( char *reply, const char * question, const Long dummy_len1, const Long dummy_len2) {	XmString	yesno_question_string;        Arg             args[5];        Cardinal        n;PIGDBG1("void WPigCursYesNo(%s)\n", question); 	yesno_question_string = XmStringCreateSimple(question);	n =  0;	XtSetArg(args[n], XmNmessageString, yesno_question_string); n++;	XtSetValues(yesno_question_dialog, args, n);	XmStringFree(yesno_question_string);	XtManageChild(yesno_question_dialog);	callback_data.reason = xpACTIVE;	while(callback_data.reason == xpACTIVE) {		XtAppProcessEvent(context, XtIMAll);	}	XtUnmanageChild(yesno_question_dialog);	reply[0] = 'N';	if(callback_data.reason == xpOK) reply[0] = 'Y';PIGDBG("WPigCursYesNo returning \"%c\"\n", reply[0]);}void  WPigFatal( const char * message, const Long dummy_len){/* PIGDBG("WPigFatal( %s, dummy_len)", message); */	iWPigFatal(message);}/*----------------------------------------------------------------------------*/void  WPigExit(void){PIGDBG1("void  WPigExit()\n");	exit(0);}/*----------------------------------------------------------------------------*/void  WPigSetTextAlignment(const Long *horizontal, const Long *vertical){PIGDBG1("void  WPigSetTextAlignment(vertical, horizontal)(%li, %li)\n", *horizontal, *vertical);	switch (*vertical) {		case BASE_ALIGN:	Vert_align = BASE_ALIGN;			break;		case TOP_ALIGN:		Vert_align = TOP_ALIGN;			break;		case BOTTOM_ALIGN:	Vert_align = BOTTOM_ALIGN;			break;	}	switch (*horizontal) {		case LEFT_ALIGN:	Horiz_align = LEFT_ALIGN;			break;		case CENTRE_ALIGN:	Horiz_align = CENTRE_ALIGN;			break;		case RIGHT_ALIGN:	Horiz_align = RIGHT_ALIGN;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -