Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
B.  A Simple Demonstration of How the ToolTalk Service Works Adding ToolTalk Code to the Demonstration Applications Adding ToolTalk Code to the Xedit Files  Previous   Contents   Next 
   
 


Example B-3 Modified commands.c File

#if (!defined(lint) && !defined(SABER))
static char Xrcsid[] = "$XConsortium: 
commands.c,v 1.27 89/12/10
					17:08:26 rws Exp $";
#endif /* lint && SABER */

...

#ifdef USG
int rename (from, to)
 char *from, *to;
{
 (void) unlink (to);
 if (link (from, to) == 0) {
 unlink (from);
 return 0;
 } else {
 return -1;
 }
}
#endif

/*
 * For the ToolTalk demonstration, add the
 * following lines to have Xfontsel
 * send a callback that the operation has either
 * completed or failed:
 */
static Tt_callback_action FinishChangeFont(m,p)/* ToolTalk message callback */
 Tt_message m;
		/* ToolTalk message */
 Tt_pattern p;	
		/* ToolTalk pattern */
{
	static XFontStruct *fs;
			/* Font structure */
	int ttmark;				
			/* ToolTalk mark */
	
	ttmark = tt_mark();	
			/* ToolTalk mark */
		/*
		 * If operation fails, notify user
		 */
	if (TT_FAILED==tt_message_state(m)) {
		XeditPrintf("Font change failed\n");
		tt_message_destroy(m);						
			/* Destroy message */
	} else if (TT_HANDLED==tt_message_state(m)) {
		XFontStruct *newfs;
		/* Try to load the new font */
		newfs = 
XLoadQueryFont(CurDpy,tt_message_arg_val(m,0));
		/* If the new font is OK, and there is an 
   * old font,
		 * unload the old font. Then use the new font
		 */
		if (newfs) {
			if (fs) {
				XUnloadFont(CurDpy, fs->fid);
			}
			XtVaSetValues(textwindow, XtNfont, newfs, 0);
			fs = newfs;
		}
		tt_message_destroy(m);	
			/* Destroy message */
	}
	tt_release(ttmark);	
				/* Release mark */
		/*
		 * Process callback to notify sender 
   * operation completed
		 */
	return TT_CALLBACK_PROCESSED;		
}

void
DoChangeFont()		
/* Change font */
{
	Tt_message m;
		/* ToolTalk message */
	Tt_status ttrc;			
		/* ToolTalk status */

		/*
		 * Create request
		 */
	m = tt_prequest_create(TT_SESSION, 
  "GetFontName");
		/*
		 * Add arguments to message
		 */
	tt_message_arg_add(m,TT_OUT,"string",
   (char *)NULL);
		/*
		 * Add callback to notify when change 
   * complete
		 */
	tt_message_callback_add(m,FinishChangeFont);
		/*
		 * Send message
		 */
	ttrc = tt_message_send(m);
		/*
		 * Fail if error occurs
		 */
	dieFromToolTalkError("tt_message_send",ttrc);
}



void DoSave()
{

 
 
 
  Previous   Contents   Next