home *** CD-ROM | disk | FTP | other *** search
/ WordPerfect for Linux Bible / WP4LinuxBible.iso / sdk / wpx / code / wt / server / wtsrvmsg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-25  |  5.5 KB  |  177 lines

  1. /* SOURCE FILE *****************************************************
  2.  * WTSRVMSG.C  -  Writing Tools API Server Sample Application
  3.  *                API message handling routines.
  4.  *******************************************************************
  5.  *  Copyright (C) 1993 WordPerfect Corp., All Rights Reserved
  6.  *******************************************************************/
  7.  
  8. #include "wtserver.h"
  9.  
  10. #include <Xm/Xm.h>
  11.  
  12. #include <wtdef.h>
  13. #include <wtapi.h>
  14. #include <wtcomm.h>
  15.  
  16. /*----------------------------------------------------------
  17.         External Variables
  18. ------------------------------------------------------------*/
  19. extern Widget Server;
  20. extern BOOL inAPI;
  21. extern BOOL inBlock; 
  22. extern TL_TRANS CurSel;
  23. extern WTCOMM comm_id;                        /* conversation handle */
  24. extern WTBUF sndbuf[BUFSIZE];                /* buffer for outgoing messages */
  25. extern WTBUF rcvbuf[BUFSIZE];                /* buffer for return messages */
  26. extern WTBUF winbuf[BUFSIZE];                /* buffer for client window name */
  27.  
  28. /*----------------------------------------------------------
  29.         External Functions
  30. ------------------------------------------------------------*/
  31. extern void SetDialogState();
  32. extern BOOL MsgBox(MSGBOX, Widget, char *, char *);
  33.  
  34. /*----------------------------------------------------------
  35.         Internal Functions
  36. ------------------------------------------------------------*/
  37. WTSTATUS WTCInitRcv(WTCINITP);
  38. WTSTATUS WTCClActiveRcv(WTCCLACTIVEP);
  39. WTSTATUS WTCClInactiveRcv(WTCCLINACTIVEP);
  40. WTSTATUS WTCRqTlTermRcv();
  41. void TermSession(void);
  42.  
  43. /* FUNCTION *******************************************************
  44. ;TermSession
  45. Title:    Terminate session with client
  46. In:        none
  47. Out:    none
  48. Return:    none
  49. Notes:
  50. *******************************************************************/
  51. void TermSession()
  52. {
  53.     WTCTLTERM sndmsg;
  54.  
  55.     /* send quit message */
  56.     sndmsg.msgid = WTC_TLTERM;
  57.     wtcTlSend(comm_id, WTC_TLTERM, (WTBUFP)&sndmsg, 
  58.             (WTSIZE)sizeof(WTCTLTERM), (WTBUFP)0, (WTSIZE)0);
  59. } /* TermSession */
  60.  
  61. /* FUNCTION *******************************************************
  62. ;WTCInitRcv
  63. Title:    Receive a WTC_INIT msg from the client
  64. In:        inmsg = incoming WTC_INIT message
  65. Out:    none
  66. Return:    writing tool status
  67. Notes:    initialize API communication
  68. ********************************************************************/
  69. WTSTATUS WTCInitRcv(WTCINITP inmsg)
  70. {
  71.     WTQINFOBLOCKP ininfo;
  72.     WTRINFOBLOCKP rtinfo;
  73.     WTQUNITINFOP inunit;
  74.     WTRUNITINFOP rtunit;
  75.     WTSTATUS status;
  76.  
  77.     inAPI = TRUE;    /* set client communicating flag */
  78.     
  79.     /* send the WTQ_INFOBLOCK message */
  80.     ininfo = (WTQINFOBLOCKP)sndbuf;
  81.     rtinfo = (WTRINFOBLOCKP)rcvbuf;
  82.     ininfo->msgid = WTQ_INFOBLOCK;        /* message id */
  83.     ininfo->tooltype = WTT_TRANSLATOR;    /* tool type */
  84.     ininfo->suptext = WTX_NATIVE;
  85.     ininfo->preftext = WTX_NATIVE;
  86.     ininfo->version = WTAPI_VERSION;    /* api version number */
  87.     ininfo->resume = WT_FALSE;            /* initial call to infoblock */
  88.     ininfo->size = BUFSIZE;                /* size of buffer for document name */
  89.     status = wtqTlSend(comm_id, WTQ_INFOBLOCK, sndbuf, sizeof(WTQINFOBLOCK),
  90.                         NULL, 0, WTR_INFOBLOCK, rcvbuf, sizeof(WTRINFOBLOCK),
  91.                         winbuf, BUFSIZE);
  92.     switch (status) {
  93.         case WTS_OK:
  94.             break;
  95.         case WTS_COMERROR:
  96.             XBell(XtDisplay(Server), 100);
  97.             MsgBox(MB_OK, Server, "WTServer Error",
  98.                 "Writing Tools API communication error!");
  99.             break;
  100.         default :
  101.             XBell(XtDisplay(Server), 100);
  102.             MsgBox(MB_OK, Server, "WTServer Error",
  103.                 "Action could not be completed.");
  104.             break;
  105.     }
  106.     /* check to see if the client has a block of selected text */    
  107.     if ((BOOL)rtinfo->hastext) {        /* currently highlighted text */
  108.         inBlock = TRUE;                    /* client has a default selection */
  109.         CurSel = TL_TRANS_SELECT;        /* default text unit is the selection */
  110.     } else {
  111.         inBlock = FALSE;
  112.         CurSel = TL_TRANS_DOC;
  113.     }       
  114.     winbuf[rtinfo->winsize] = 0;        /* null terminate window name */
  115.     /* Send the WTQ_UNITINFO message */
  116.     inunit = (WTQUNITINFOP)sndbuf;
  117.     rtunit = (WTRUNITINFOP)rcvbuf;
  118.     inunit->msgid = WTQ_UNITINFO;
  119.     status = wtqTlSend(comm_id, WTQ_UNITINFO, sndbuf, sizeof(WTQUNITINFO),
  120.                         NULL, 0, WTR_UNITINFO, rcvbuf, sizeof(WTRUNITINFO),
  121.                         NULL, 0);
  122.     switch (status)
  123.     {
  124.         case WTS_OK:
  125.             break;
  126.         case WTS_COMERROR:
  127.             XBell(XtDisplay(Server), 100);
  128.             MsgBox(MB_OK, Server, "WTServer Error",
  129.                 "Writing Tools API communication error!");
  130.             break;
  131.         default :
  132.             XBell(XtDisplay(Server), 100);
  133.             MsgBox(MB_OK, Server, "WTServer Error",
  134.                 "Action could not be completed.");
  135.             break;
  136.     }
  137.     SetDialogState();
  138.     return status;
  139. } /* WTCInitRcv */
  140.  
  141. /* FUNCTION *******************************************************
  142. ;WTCClActiveRcv
  143. Title:    Receive a WTC_CLACTIVE msg from the client
  144. In:        inmsg = incoming WTC_CLACTIVE message
  145. Out:    None
  146. Return:    writing tool status
  147. *******************************************************************/
  148. WTSTATUS WTCClActiveRcv(WTCCLACTIVEP inmsg)
  149. {
  150.     return WTS_OK;
  151. } /* WTCClActiveRcv */
  152.  
  153. /* FUNCTION *******************************************************
  154. ;WTCClInactiveRcv
  155. Title:    Receive a WTC_CLINACTIVE msg from the client
  156. In:        inmsg = incoming WTC_CLINACTIVE message
  157. Out:    None
  158. Return:    writing tool status
  159. *******************************************************************/
  160. WTSTATUS WTCClInactiveRcv(WTCCLINACTIVEP inmsg)
  161. {
  162.     return WTS_OK;
  163. } /* WTCClInactiveRcv */
  164.  
  165. /* FUNCTION *******************************************************
  166. ;WTCRqTlTermRcv
  167. Title:    Receive a WTQ_CLTERM msg from the client
  168. In:        inmsg = incoming WTQ_CLTERM message
  169. Out:    rtmsg = outgoing WTR_CLTERM message
  170. Return:    writing tool status
  171. *******************************************************************/
  172. WTSTATUS WTCRqTlTermRcv()
  173. {
  174.     TermSession();
  175.     return WTS_OK;
  176. } /* WTCRqTlTermRcv */
  177.