home *** CD-ROM | disk | FTP | other *** search
- /* SOURCE FILE *****************************************************
- * WTCLTMSG.C - Writing Tool product specific message handling
- * routines. A seperate (but similar) set of routines
- * should be written for each WTAPI-aware product.
- *******************************************************************
- *Copyright (C) 1993 WordPerfect Corp., All Rights Reserved
- *******************************************************************/
-
- #include "wtclient.h"
-
- #include <string.h>
-
- #include <wtapi.h>
- #include <wtcomm.h>
-
- extern TOOLRECORD toolRecords[]; /* writing tool records */
- extern char FileName[]; /* current file name */
-
- /*----------------------------------------------------------
- External Functions
- ------------------------------------------------------------*/
- void quitTool(char *);
- WTSTATUS GetText(WTUNIT, WTPOS, WTCOUNT, WTUNIT, WTPOS, WTCOUNT, WTTBQTYPE,
- WTSIZE, WTTBQTYPE *, WTBUFP, WTSIZE *);
- unsigned SelectedLen(void);
- WTSTATUS GoToPos(WTPOS, WTCOUNT, WTPOS, WTCOUNT, unsigned *);
- long Hilite(long);
- long DeHilite(long);
- WTCOUNT ReplaceText(WTCOUNT, WTSIZE, WTBUFP);
- unsigned FindCurrBlock(unsigned);
- void NativeToWord(WTBUFP, WTSIZE *);
- void WordToNative(WTBUFP, WTSIZE *);
-
- /*----------------------------------------------------------
- Internal Functions
- ------------------------------------------------------------*/
- WTSTATUS WTQInfoBlockRcv(WTPTR, WTQINFOBLOCKP, WTRINFOBLOCKP, WTBUFP);
- WTSTATUS WTCRqInitRcv(WTPTR, WTCRQINITP, WTBUFP);
- WTSTATUS WTCTlTermRcv(WTPTR);
- WTSTATUS WTQInfoBlockRcv(WTPTR, WTQINFOBLOCKP, WTRINFOBLOCKP, WTBUFP);
- WTSTATUS WTQUnitInfoRcv(WTPTR, WTRUNITINFOP);
- WTSTATUS WTQReadToolDataRcv(WTPTR, WTQREADTOOLDATAP, WTRREADTOOLDATAP, WTBUFP);
- WTSTATUS WTQWriteToolDataRcv(WTPTR, WTQWRITETOOLDATAP, WTBUFP, WTRWRITETOOLDATAP);
- WTSTATUS WTQTextBlockRcv(WTPTR, WTQTEXTBLOCKP, WTRTEXTBLOCKP, WTBUFP);
- WTSTATUS WTQNextTextBlockRcv(WTPTR, WTQNEXTTEXTBLOCKP, WTRTEXTBLOCKP, WTBUFP);
- WTSTATUS WTQReadTextObjectRcv(WTPTR, WTQREADTEXTOBJECTP, WTRREADTEXTOBJECTP, WTBUFP);
- WTSTATUS WTQWriteTextObjectRcv(WTPTR, WTQWRITETEXTOBJECTP, WTBUFP, WTRWRITETEXTOBJECTP);
- WTSTATUS WTQGotoRcv(WTPTR, WTQGOTOP, WTRGOTOP);
- WTSTATUS WTQHiliteRcv(WTPTR, WTQHILITEP, WTRHILITEP);
- WTSTATUS WTQDehiliteRcv(WTPTR, WTQDEHILITEP, WTRDEHILITEP);
- WTSTATUS WTQReplaceRcv(WTPTR, WTQREPLACEP, WTBUFP, WTRREPLACEP);
- WTSTATUS WTQUndoReplaceRcv(WTPTR, WTRREPLACEP);
- WTSTATUS WTCRqClActiveRcv(WTPTR);
- WTSTATUS WTCTlInactiveRcv(WTPTR);
- WTSTATUS WTQTlActiveRcv(WTPTR, WTRTLACTIVEP);
-
- /*COMMENT********************************************************
- ;WTCInitSend
- Title: Send the WTC_INIT message
- In: comm = comm info for this session
- msg = message buffer filled with product data
- Out: none
- Xin: none
- XOut: none
- Return: WTSTATUS
- Notes:
- *****************************************************************/
- WTSTATUS WTCInitSend(WTCOMM comm, WTCINITP msg)
- {
- return wtcClSend(comm, WTC_INIT,
- (WTBUFP)msg, (WTSIZE)sizeof(WTCINIT), (WTBUFP)0, 0);
- } /* WTCInitSend */
-
- /*COMMENT********************************************************
- ;WTCClActiveSend
- Title: Send the WTC_CLACTIVE message
- In: comm = comm info for this session
- msg = message buffer filled with product data
- Out: none
- Xin: none
- XOut: none
- Return: WTSTATUS
- Notes:
- *****************************************************************/
- WTSTATUS WTCClActiveSend(WTCOMM comm, WTCCLACTIVEP msg)
- {
- return wtcClSend(comm, WTC_CLACTIVE,
- (WTBUFP)msg, (WTSIZE)sizeof(WTCCLACTIVE), (WTBUFP)0, 0);
- } /* WTCClActiveSend */
-
- /*COMMENT********************************************************
- ;WTCClInactiveSend
- Title: Send the WTC_CLINACTIVE message
- In: comm = comm info for this session
- msg = message buffer filled with product data
- Out: none
- Xin: none
- XOut: none
- Return: WTSTATUS
- Notes:
- *****************************************************************/
- WTSTATUS WTCClInactiveSend(WTCOMM comm, WTCCLINACTIVEP msg)
- {
- return wtcClSend(comm, WTC_CLINACTIVE,
- (WTBUFP)msg, (WTSIZE)sizeof(WTCCLINACTIVE), (WTBUFP)0, 0);
- } /* WTCClInactiveSend */
-
- /*COMMENT********************************************************
- ;WTCRqTlTermSend
- Title: Send the WTQ_CLTERM message
- In: comm = comm info for this session
- inmsg = message buffer filled with product data
- Out: rtmsg = buffer to hold returning WTR_CLTERM message
- Xin: none
- XOut: none
- Return: WTSTATUS
- Notes:
- *****************************************************************/
- WTSTATUS WTCRqTlTermSend(WTCOMM comm, WTCRQTLTERMP inmsg)
- {
- return wtcClSend(comm, WTC_RQTLTERM,
- (WTBUFP)inmsg, (WTSIZE)sizeof(WTCRQTLTERM), (WTBUFP)0, 0);
- } /* WTCRqTlTermSend */
-
- /*COMMENT********************************************************
- ;WTQInfoBlockRcv
- Title: Reply to infoblock message
- In: wtsess = global app data
- inmsg - input message data
- Out: rtmsg - output message data
- rtbuf - location of returned data
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQInfoBlockRcv(WTPTR wtsess,
- WTQINFOBLOCKP inmsg, WTRINFOBLOCKP rtmsg, WTBUFP rtbuf)
- {
- rtmsg->msgid = WTR_INFOBLOCK; /* WTR_INFOBLOCK msg id */
-
- if (inmsg->resume) {
- rtmsg->status = WTS_CLIENTERROR;
- return WTS_OK;
- }
- if (!((inmsg->suptext & WTX_NATIVE) || (inmsg->suptext & WTX_WPWRD))) {
- rtmsg->status = WTS_COMERROR;
- return WTS_OK;
- }
- wtsess->toolType = inmsg->tooltype; /* type of writing tool */
- if (inmsg->version != WTAPI_VERSION) { /* current WTAPI version */
- rtmsg->status = WTS_NOTSUPPORTED;
- return WTS_OK;
- }
-
- rtmsg->status = WTS_OK; /* return status from client */
- if (inmsg->suptext & WTX_NATIVE) { /* mode of representing text */
- rtmsg->textmode = WTX_NATIVE;
- } else if (inmsg->suptext & WTX_WPWRD) {
- rtmsg->textmode = WTX_WPWRD;
- } else {
- rtmsg->textmode = WTX_NATIVE;
- }
- wtsess->textmode = rtmsg->textmode;
- rtmsg->tdamode = 0; /* supported tool data area modes */
- rtmsg->userlang.script = 0x00; /* user interface language: US English */
- rtmsg->userlang.language = 0x00;
- rtmsg->userlang.region = 0x01;
-
- rtmsg->textlang.script = 0x00; /* text language: US English */
- rtmsg->textlang.language = 0x00;
- rtmsg->textlang.region = 0x01;
-
- if (SelectedLen()) {
- rtmsg->hastext = 1; /* the client has default text */
- } else {
- rtmsg->hastext = 0; /* the client has NO default text */
- }
- rtmsg->service = 0; /* writing tool service requested */
- rtmsg->mysize = MYMAXBLOCKSIZE; /* maximum size block to the client */
-
- strcpy(wtsess->rtText, "WTClient - ");
- if (strlen(FileName)) {
- strcat(wtsess->rtText, FileName);
- } else {
- strcat(wtsess->rtText, "(Untitled)");
- }
-
- rtmsg->winsize = strlen(wtsess->rtText); /* size of window name text */
-
- #if 0
- if ((wtsess->textmode == WTX_WPWRD) && /* not WP tool */ ) {
- rtmsg->winsize <<= 1; /* double size */
- NativeToWord(wtsess->rtText, &rtmsg->winsize);
- }
- #endif /* 0 */
-
- if (rtmsg->winsize > inmsg->size) {
- rtmsg->complete = 0; /* text request NOT complete? */
- rtmsg->winsize = inmsg->size;
- } else {
- rtmsg->complete = 1; /* text request complete. */
- }
- memcpy(rtbuf, wtsess->rtText, (unsigned)rtmsg->winsize);
- } /* WTQInfoBlockRcv */
-
- /*COMMENT********************************************************
- ;WTCTlTermRcv
- Title: Reply to WTAPI message
- In: wtsess = global app data
- Out: rtmsg - output message data
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTCTlTermRcv(WTPTR wtsess)
- {
- quitTool(0);
- return WTS_OK;
- } /* WTCTlTermRcv */
-
- /*COMMENT********************************************************
- ;WTCRqInitRcv
- Title: Request Writing Tool Initialization
- In: wtsess = global app data
- Out:
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTCRqInitRcv(WTPTR wtsess, WTCRQINITP inmsg, WTBUFP inbuf)
- {
- return WTS_NOTSUPPORTED;
- } /* WTCRqInitRcv */
-
- /*COMMENT********************************************************
- ;WTQUnitInfoRcv
- Title: Reply to UNITINFO message
- In: wtsess - global app data
- Out: rtmsg - output message data
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQUnitInfoRcv(WTPTR wtsess, WTRUNITINFOP rtmsg)
- {
- rtmsg->msgid = WTR_UNITINFO;
- rtmsg->status = WTS_OK;
- rtmsg->supunit = WTU_DOCUMENT|WTU_SELECTION|WTU_CHAR;
- rtmsg->curunit = WTU_DOCUMENT|WTU_CHAR;
- rtmsg->defunit = WTU_DOCUMENT;
- rtmsg->size = 0;
- return WTS_OK;
- } /* WTQUnitInfoRcv */
-
- /*COMMENT********************************************************
- ;WTQReadToolDataRcv
- Title: Reply to READTOOLDATA message
- In: wtsess = global app data
- inmsg - input message data
- Out: rtmsg - output message data
- rtbuf - output buffer
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQReadToolDataRcv(WTPTR wtsess,
- WTQREADTOOLDATAP inmsg, WTRREADTOOLDATAP rtmsg, WTBUFP rtbuf)
- {
- rtmsg->msgid = WTR_READTOOLDATA;
- rtmsg->status = WTS_NOTSUPPORTED;
- return WTS_OK;
- } /* WTQReadToolDataRcv */
-
- /*COMMENT********************************************************
- ;WTQWriteToolDataRcv
- Title: Reply to WRITETOOLDATA message
- In: wtsess - global app data
- inmsg - input message data
- inbuf - input buffer
- Out: rtmsg - output message data
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQWriteToolDataRcv(WTPTR wtsess,
- WTQWRITETOOLDATAP inmsg, WTBUFP inbuf, WTRWRITETOOLDATAP rtmsg)
- {
- rtmsg->status = WTS_NOTSUPPORTED;
- rtmsg->msgid = WTR_WRITETOOLDATA;
- return WTS_OK;
- } /* WTQWriteToolDataRcv */
-
- /*COMMENT********************************************************
- ;WTQReadTextObjectRcv
- Title: Reply to READTEXTOBJECT message
- In: wtsess = global app data
- inmsg - input message data
- Out: rtmsg - output message data
- rtbuf - output buffer
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQReadTextObjectRcv(WTPTR wtsess, WTQREADTEXTOBJECTP inmsg, WTRREADTEXTOBJECTP rtmsg, WTBUFP rtbuf)
- {
- rtmsg->msgid = WTR_READTEXTOBJECT;
- rtmsg->status = WTS_NOTSUPPORTED;
- return WTS_OK;
- } /* WTQReadTextObjectRcv */
-
- /*COMMENT********************************************************
- ;WTQWriteTextObjectRcv
- Title: Reply to WRITETEXTOBJECT message
- In: wtsess - global app data
- inmsg - input message data
- inbuf - input buffer
- Out: rtmsg - output message data
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQWriteTextObjectRcv(WTPTR wtsess, WTQWRITETEXTOBJECTP inmsg, WTBUFP inbuf, WTRWRITETEXTOBJECTP rtmsg)
- {
- rtmsg->status = WTS_NOTSUPPORTED;
- rtmsg->msgid = WTR_WRITETEXTOBJECT;
- return WTS_OK;
- } /* WTQWriteTextObjectRcv */
-
- /*COMMENT********************************************************
- ;WTQTextBlockRcv
- Title: Reply to TEXTBLOCK message
- In: wtsess - global app data
- inmsg - input message data
- Out: rtmsg - output message data
- rtbuf - output buffer
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQTextBlockRcv(WTPTR wtsess,
- WTQTEXTBLOCKP inmsg, WTRTEXTBLOCKP rtmsg, WTBUFP rtbuf)
- {
- WTSTATUS status;
-
- rtmsg->msgid = WTR_TEXTBLOCK;
-
- if (wtsess->textmode == WTX_WPWRD) {
- rtmsg->size >>= 1; /* 1/2 buffer size */
- }
-
- status = GetText(inmsg->fromunit, inmsg->frompos, inmsg->fromloc,
- inmsg->tounit, inmsg->topos, inmsg->toloc,
- inmsg->qtype, inmsg->size, &rtmsg->endblock, rtbuf, &rtmsg->size);
- rtmsg->status = status;
-
- if (wtsess->textmode == WTX_WPWRD) {
- NativeToWord(rtbuf, &rtmsg->size);
- }
-
- if (status != WTS_OK) {
- rtmsg->size = 0;
- }
- rtmsg->language.script = 0; /* English U.S. */
- rtmsg->language.language = 0;
- rtmsg->language.region = 1;
- rtmsg->depth = 0;
- /* rtmsg->blocknum = wtsess->lastBlock; */
- rtmsg->depth = wtsess->lastBlock;
- return status;
- } /* WTQTextBlockRcv */
-
- /*COMMENT********************************************************
- ;WTQNextTextBlockRcv
- Title: Reply to NEXTTEXTBLOCK message
- In: wtsess = global app data
- inmsg - input message data
- Out: rtmsg - output message data
- rtbuf - output buffer
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQNextTextBlockRcv(WTPTR wtsess,
- WTQNEXTTEXTBLOCKP inmsg, WTRTEXTBLOCKP rtmsg, WTBUFP rtbuf)
- {
- rtmsg->msgid = WTR_TEXTBLOCK;
-
- if (wtsess->textmode == WTX_WPWRD) {
- rtmsg->size >>= 1; /* 1/2 buffer size */
- }
-
- rtmsg->status = GetText(0, 0, 0,
- wtsess->tounit, wtsess->topos, wtsess->toloc,
- WTB_RESUME, inmsg->size, &rtmsg->endblock, rtbuf, &rtmsg->size);
-
- if (wtsess->textmode == WTX_WPWRD) {
- NativeToWord(rtbuf, &rtmsg->size);
- }
-
- if (rtmsg->status != WTS_OK) {
- rtmsg->size = 0;
- }
- rtmsg->language.script = 0; /* English U.S. */
- rtmsg->language.language = 0;
- rtmsg->language.region = 1;
- rtmsg->depth = 0;
- /* rtmsg->blocknum = wtsess->lastBlock; */
- rtmsg->depth = wtsess->lastBlock;
- return WTS_OK;
- } /* WTQNextTextBlockRcv */
-
- /*COMMENT********************************************************
- ;WTQGotoRcv
- Title: Reply to GOTO message
- In: wtsess = global app data
- inmsg - input message data
- Out: rtmsg - output message data
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQGotoRcv(WTPTR wtsess, WTQGOTOP inmsg, WTRGOTOP rtmsg)
- {
- unsigned position=0;
-
- rtmsg->msgid = WTR_GOTO;
-
- if (wtsess->textmode == WTX_WPWRD) {
- inmsg->offsetloc >>= 1; /* 1/2 len */
- }
-
- rtmsg->status = GoToPos(inmsg->blockpos, inmsg->blocknum,
- inmsg->offsetpos, inmsg->offsetloc, &position);
- if (rtmsg->status == WTS_OK) {
- rtmsg->count = position - wtsess->absPos;
- wtsess->absPos = position;
-
- /* get current block & position in block */
- wtsess->currBlock = FindCurrBlock(position);
- wtsess->absPos = position;
- }
-
- rtmsg->offset = wtsess->absPos - wtsess->textInfo[wtsess->currBlock].offset;
-
- if (wtsess->textmode == WTX_WPWRD) {
- rtmsg->offset <<= 1; /* double offset */
- }
- rtmsg->block = wtsess->currBlock;
- return WTS_OK;
- } /* WTQGotoRcv */
-
- /*COMMENT********************************************************
- ;WTQHiliteRcv
- Title: Reply to HILITE message
- In: wtsess = global app data
- inmsg - input message data
- Out: rtmsg - output message data
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQHiliteRcv(WTPTR wtsess, WTQHILITEP inmsg, WTRHILITEP rtmsg)
- {
- rtmsg->msgid = WTR_HILITE;
- rtmsg->status = WTS_OK;
-
- if (wtsess->textmode == WTX_WPWRD) {
- rtmsg->count = (Hilite(inmsg->count >> 1) << 1);
- } else {
- rtmsg->count = Hilite(inmsg->count);
- }
- return WTS_OK;
- } /* WTQHiliteRcv */
-
- /*COMMENT********************************************************
- ;WTQDehiliteRcv
- Title: Reply to WTAPI message
- In: wtsess = global app data
- inmsg - input message data
- Out: rtmsg - output message data
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQDehiliteRcv(WTPTR wtsess, WTQDEHILITEP inmsg, WTRDEHILITEP rtmsg)
- {
- rtmsg->msgid = WTR_DEHILITE;
- rtmsg->status = WTS_OK;
- if (wtsess->textmode == WTX_WPWRD) {
- rtmsg->count = (DeHilite(inmsg->count >> 1) << 1);
- } else {
- rtmsg->count = DeHilite(inmsg->count);
- }
- return WTS_OK;
- } /* WTQDehiliteRcv */
-
- /*COMMENT********************************************************
- ;WTQReplaceRcv
- Title: Reply to WTAPI message
- In: wtsess = global app data
- inmsg - input message data
- inbuf - input buffer
- Out: rtmsg - output message data
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQReplaceRcv(WTPTR wtsess,
- WTQREPLACEP inmsg, WTBUFP inbuf, WTRREPLACEP rtmsg)
- {
- char replace[MYMAXBLOCKSIZE];
-
- if (inmsg->size < MYMAXBLOCKSIZE) {
- memcpy(replace, (char *)inbuf, inmsg->size);
- replace[inmsg->size] = 0; /* make sure is null-terminated */
- } else {
- memcpy(replace, inbuf, MYMAXBLOCKSIZE);
- replace[MYMAXBLOCKSIZE-1] = 0;
- }
-
- rtmsg->msgid = WTR_REPLACE;
-
- if (wtsess->textmode == WTX_WPWRD) {
- WordToNative(replace, &inmsg->size);
- inmsg->count >>= 1; /* 1/2 of count */
- }
-
- rtmsg->status = WTS_OK;
- rtmsg->count = ReplaceText(inmsg->count, inmsg->size, replace);
- rtmsg->size = inmsg->size; /* bytes inserted */
-
- rtmsg->block = wtsess->currBlock;
- rtmsg->offset = wtsess->absPos - wtsess->textInfo[wtsess->currBlock].offset;
- if (wtsess->textmode == WTX_WPWRD) {
- rtmsg->count <<= 1;
- rtmsg->size <<= 1;
- rtmsg->offset <<= 1;
- }
- return WTS_OK;
- } /* WTQReplaceRcv */
-
- /*COMMENT********************************************************
- ;WTQUndoReplaceRcv
- Title: Reply to WTAPI message
- In: wtsess = global app data
- Out: rtmsg - output message data
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQUndoReplaceRcv(WTPTR wtsess, WTRREPLACEP rtmsg)
- {
- rtmsg->status = WTS_NOTSUPPORTED;
- rtmsg->msgid = WTR_REPLACE;
- return WTS_OK;
- } /* WTQUndoReplaceRcv */
-
- /*COMMENT********************************************************
- ;WTCRqClActiveRcv
- Title: Reply to WTAPI message
- In: wtsess = global app data
- Out:
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTCRqClActiveRcv(WTPTR wtsess)
- {
- return WTS_OK;
- } /* WTCRqClActiveRcv */
-
- /*COMMENT********************************************************
- ;WTCTlInactiveRcv
- Title: Reply to WTAPI message
- In: wtsess = global app data
- Out:
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTCTlInactiveRcv(WTPTR wtsess)
- {
- return WTS_OK;
- } /* WTCTlInactiveRcv */
-
- /*COMMENT********************************************************
- ;WTQTlActiveRcv
- Title: Reply to WTAPI message
- In: wtsess = global app data
- Out: rtmsg - output message data
- Return: status of process
- Notes:
- *****************************************************************/
- WTSTATUS WTQTlActiveRcv(WTPTR wtsess, WTRTLACTIVEP rtmsg)
- {
- rtmsg->status = WTS_NOTSUPPORTED;
- rtmsg->msgid = WTR_TLACTIVE;
- return WTS_OK;
- } /* WTQTlActiveRcv */
-