home *** CD-ROM | disk | FTP | other *** search
- /* SOURCE FILE *****************************************************
- * WTSRVMSG.C - Writing Tools API Server Sample Application
- * API message handling routines.
- *******************************************************************
- * Copyright (C) 1993 WordPerfect Corp., All Rights Reserved
- *******************************************************************/
-
- #include "wtserver.h"
-
- #include <Xm/Xm.h>
-
- #include <wtdef.h>
- #include <wtapi.h>
- #include <wtcomm.h>
-
- /*----------------------------------------------------------
- External Variables
- ------------------------------------------------------------*/
- extern Widget Server;
- extern BOOL inAPI;
- extern BOOL inBlock;
- extern TL_TRANS CurSel;
- extern WTCOMM comm_id; /* conversation handle */
- extern WTBUF sndbuf[BUFSIZE]; /* buffer for outgoing messages */
- extern WTBUF rcvbuf[BUFSIZE]; /* buffer for return messages */
- extern WTBUF winbuf[BUFSIZE]; /* buffer for client window name */
-
- /*----------------------------------------------------------
- External Functions
- ------------------------------------------------------------*/
- extern void SetDialogState();
- extern BOOL MsgBox(MSGBOX, Widget, char *, char *);
-
- /*----------------------------------------------------------
- Internal Functions
- ------------------------------------------------------------*/
- WTSTATUS WTCInitRcv(WTCINITP);
- WTSTATUS WTCClActiveRcv(WTCCLACTIVEP);
- WTSTATUS WTCClInactiveRcv(WTCCLINACTIVEP);
- WTSTATUS WTCRqTlTermRcv();
- void TermSession(void);
-
- /* FUNCTION *******************************************************
- ;TermSession
- Title: Terminate session with client
- In: none
- Out: none
- Return: none
- Notes:
- *******************************************************************/
- void TermSession()
- {
- WTCTLTERM sndmsg;
-
- /* send quit message */
- sndmsg.msgid = WTC_TLTERM;
- wtcTlSend(comm_id, WTC_TLTERM, (WTBUFP)&sndmsg,
- (WTSIZE)sizeof(WTCTLTERM), (WTBUFP)0, (WTSIZE)0);
- } /* TermSession */
-
- /* FUNCTION *******************************************************
- ;WTCInitRcv
- Title: Receive a WTC_INIT msg from the client
- In: inmsg = incoming WTC_INIT message
- Out: none
- Return: writing tool status
- Notes: initialize API communication
- ********************************************************************/
- WTSTATUS WTCInitRcv(WTCINITP inmsg)
- {
- WTQINFOBLOCKP ininfo;
- WTRINFOBLOCKP rtinfo;
- WTQUNITINFOP inunit;
- WTRUNITINFOP rtunit;
- WTSTATUS status;
-
- inAPI = TRUE; /* set client communicating flag */
-
- /* send the WTQ_INFOBLOCK message */
- ininfo = (WTQINFOBLOCKP)sndbuf;
- rtinfo = (WTRINFOBLOCKP)rcvbuf;
- ininfo->msgid = WTQ_INFOBLOCK; /* message id */
- ininfo->tooltype = WTT_TRANSLATOR; /* tool type */
- ininfo->suptext = WTX_NATIVE;
- ininfo->preftext = WTX_NATIVE;
- ininfo->version = WTAPI_VERSION; /* api version number */
- ininfo->resume = WT_FALSE; /* initial call to infoblock */
- ininfo->size = BUFSIZE; /* size of buffer for document name */
- status = wtqTlSend(comm_id, WTQ_INFOBLOCK, sndbuf, sizeof(WTQINFOBLOCK),
- NULL, 0, WTR_INFOBLOCK, rcvbuf, sizeof(WTRINFOBLOCK),
- winbuf, BUFSIZE);
- switch (status) {
- case WTS_OK:
- break;
- case WTS_COMERROR:
- XBell(XtDisplay(Server), 100);
- MsgBox(MB_OK, Server, "WTServer Error",
- "Writing Tools API communication error!");
- break;
- default :
- XBell(XtDisplay(Server), 100);
- MsgBox(MB_OK, Server, "WTServer Error",
- "Action could not be completed.");
- break;
- }
- /* check to see if the client has a block of selected text */
- if ((BOOL)rtinfo->hastext) { /* currently highlighted text */
- inBlock = TRUE; /* client has a default selection */
- CurSel = TL_TRANS_SELECT; /* default text unit is the selection */
- } else {
- inBlock = FALSE;
- CurSel = TL_TRANS_DOC;
- }
- winbuf[rtinfo->winsize] = 0; /* null terminate window name */
- /* Send the WTQ_UNITINFO message */
- inunit = (WTQUNITINFOP)sndbuf;
- rtunit = (WTRUNITINFOP)rcvbuf;
- inunit->msgid = WTQ_UNITINFO;
- status = wtqTlSend(comm_id, WTQ_UNITINFO, sndbuf, sizeof(WTQUNITINFO),
- NULL, 0, WTR_UNITINFO, rcvbuf, sizeof(WTRUNITINFO),
- NULL, 0);
- switch (status)
- {
- case WTS_OK:
- break;
- case WTS_COMERROR:
- XBell(XtDisplay(Server), 100);
- MsgBox(MB_OK, Server, "WTServer Error",
- "Writing Tools API communication error!");
- break;
- default :
- XBell(XtDisplay(Server), 100);
- MsgBox(MB_OK, Server, "WTServer Error",
- "Action could not be completed.");
- break;
- }
- SetDialogState();
- return status;
- } /* WTCInitRcv */
-
- /* FUNCTION *******************************************************
- ;WTCClActiveRcv
- Title: Receive a WTC_CLACTIVE msg from the client
- In: inmsg = incoming WTC_CLACTIVE message
- Out: None
- Return: writing tool status
- *******************************************************************/
- WTSTATUS WTCClActiveRcv(WTCCLACTIVEP inmsg)
- {
- return WTS_OK;
- } /* WTCClActiveRcv */
-
- /* FUNCTION *******************************************************
- ;WTCClInactiveRcv
- Title: Receive a WTC_CLINACTIVE msg from the client
- In: inmsg = incoming WTC_CLINACTIVE message
- Out: None
- Return: writing tool status
- *******************************************************************/
- WTSTATUS WTCClInactiveRcv(WTCCLINACTIVEP inmsg)
- {
- return WTS_OK;
- } /* WTCClInactiveRcv */
-
- /* FUNCTION *******************************************************
- ;WTCRqTlTermRcv
- Title: Receive a WTQ_CLTERM msg from the client
- In: inmsg = incoming WTQ_CLTERM message
- Out: rtmsg = outgoing WTR_CLTERM message
- Return: writing tool status
- *******************************************************************/
- WTSTATUS WTCRqTlTermRcv()
- {
- TermSession();
- return WTS_OK;
- } /* WTCRqTlTermRcv */
-