Back to index

im-sdk  12.3.91
XAuxMethods.c
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 #include <stdio.h>
00043 #include <malloc.h>
00044 #include <string.h>
00045 #include <X11/Xlib.h>
00046 #include <X11/cursorfont.h>
00047 #include <X11/Xutil.h>
00048 #include <X11/Xcms.h>
00049 #include <X11/Xprotostr.h>
00050 #include <assert.h>
00051 #include <locale.h>
00052 #include <dlfcn.h>
00053 #include <thread.h>
00054 #include <X11/Intrinsic.h>
00055 #include <X11/Shell.h>
00056 #include <Xm/XmAll.h>
00057 
00058 #include "XSunExt.h"
00059 #include "XSunIMProt.h"
00060 #include "XSunIMMthd.h"
00061 
00062 #include "GeneType.h"
00063 #include "XAuxMethods.h"
00064 
00065 #ifdef notdef
00066 #include "PutXpm.h"
00067 #include "SkbXpms.h"      /* Contain all xpm data */
00068 #endif
00069 
00070 const int PUNCTUATION_STATUS   = 1;
00071 const int SOFTKEYBOARD_LAYOUT  = 2;
00072 const int BUTTON_NUMBER = 3;
00073 
00074 #define  SKB_SYMBSCIENT     0
00075 #define  SKB_SERIESONE      1
00076 #define  SKB_SERIESTWO      2
00077 #define  SKB_SERIESTHREE    3
00078 #define  SKB_SERIESFOUR     4
00079 #define  SKB_GREECE         5
00080 #define  SKB_RUSSIAN        6
00081 #define  SKB_PYSYM          7
00082 #define  SKB_JAPPIN         8
00083 #define  SKB_JAPPIAN        9
00084 #define  SKB_TABSYMB        10
00085 #define  SKB_GBKEXTSYM1     11
00086 #define  SKB_GBKEXTSYM2     12
00087 #define  SKB_HALFWID        13
00088 #define  SKB_FULLWID        14
00089 
00090 #define  TOTAL_SKB          15
00091 
00092 #define  PUNCT_CHINESE      0
00093 #define  PUNCT_ENGLISH      1
00094 
00095 #define  TOTAL_PUNCT        2
00096 
00097 static int nDebugInt = 0;           /* For Debug Message */
00098 /*
00099 char   szAttrNames[17][30] = {      /* For Debug Message 
00100        "XAUX_DISPLAY",
00101        "XAUX_SCREENNUM",
00102        "XAUX_HTTWINDOW",
00103        "XAUX_FONTSET",
00104        "XAUX_AREA",
00105        "XAUX_AREANEEDED",
00106        "XAUX_COLORMAP",
00107        "XAUX_STDCOLORMAP",
00108        "XAUX_FOREGROUND",
00109        "XAUX_BACKGROUND",
00110        "XAUX_BACKGROUNDPIXMAP",
00111        "XAUX_LOCATION",
00112        "XAUX_FONTNAME",
00113        "XAUX_CURSOR",
00114        "XAUX_REPLYCALLBACK",
00115        "XAUX_REPLYCLIENTDATA",
00116        "XAUX_GC"
00117 };
00118 */
00119 
00120 /*
00121 ** Not used by any part of program!! Scott Ma 05/26, 98
00122 */
00123 xaux_methods_t xaux_methods = {
00124        XAux_Create,
00125        XAux_Start,
00126        XAux_Draw,
00127        XAux_Done,
00128        XAux_SetFocus,
00129        XAux_UnsetFocus,
00130        XAux_SetValues,
00131        XAux_GetValues,
00132        XAux_Destroy
00133 };
00134 
00135 XAux_SesDspParaNode  *pgAuxSdpnList = NULL;
00136 
00137 static XAux_SesDspParaNode  *PrefixNewNode(int nIcID);
00138 static XAux_SesDspParaNode  *GetNodeAddressByIcID(int nIcID);
00139 
00140 static BOOL DestroyNode(int nIcID);
00141 static BOOL SetAuxNodeValues(XAux_SesDspParaNode* pThisSdpn,
00142                              XAuxAttribute *pAttrArray, int nArraySize);
00143 static BOOL GetAuxNodeValues(XAux_SesDspParaNode* pThisSdpn,
00144                              XAuxAttribute *pAttrArray, int nArraySize);
00145                                                   
00146 static BOOL CreateGUI(XAux_SesDspParaNode *pThisSdpn);
00147 static BOOL MapGUI   (XAux_SesDspParaNode *pThisSdpn);
00148 static BOOL UnmapGUI (XAux_SesDspParaNode *pThisSdpn);
00149 
00150 static void aux_event_handler(Display* pDsp, Window wnd, XEvent* pEvent, void* pvCallData);
00151 static void ListXwaStruct(XWindowAttributes *pXwa);
00152 
00153 static void UpdateWndBmp1(XAux_SesDspParaNode *pThisSdpn);
00154 static void UpdateWndBmp2(XAux_SesDspParaNode *pThisSdpn);
00155 
00156     Widget toplevel, main_window, aux2_dialog;
00157     Widget startbutton, sendbutton, donebutton, form, rc;
00158 
00159 /*
00160 ** Prefix new node in the front of pgAuxSdpnList.
00161 ** Is this nIcID already existed in pgAuxSdpnList?
00162 **    YES,  just move this node to the front of List
00163 **    NO,   alloc memory for new node.
00164 */
00165 static XAux_SesDspParaNode* PrefixNewNode(int nIcID)
00166 {
00167        XAux_SesDspParaNode   *pNewSdpNode;
00168        
00169        /*
00170         * It is necessary to determine has this icID already existed in List?
00171         * If yes, don't allocate any more memory. Just move this node to the
00172         * front of this list. Notice: change ->next correctly.
00173         * Not implemented yet! ==> Scott Ma 98-05-29
00174         */
00175        pNewSdpNode = GetNodeAddressByIcID(nIcID);
00176        if (pNewSdpNode != NULL)
00177        {
00178               fprintf(stderr, "Warning:  PrefixNewNode() this node already existed!\n");
00179               return pNewSdpNode;
00180        }
00181        
00182        pNewSdpNode     = (XAux_SesDspParaNode*)malloc(sizeof(XAux_SesDspParaNode));
00183        if (pNewSdpNode == NULL)
00184        {
00185               fprintf(stderr, "htt: Failed to malloc() in PrefixNewNode().\n");
00186               exit(False);
00187        }
00188        memset(pNewSdpNode, 0x00, sizeof(XAux_SesDspParaNode));
00189        
00190        pNewSdpNode->nPuncState = PUNCT_CHINESE;
00191        pNewSdpNode->nSkbState  = SKB_HALFWID;
00192        
00193        pNewSdpNode->nIcID = nIcID;
00194        pNewSdpNode->next  = NULL;     /* Null */
00195        
00196        /* Update pgAuxSdpnList after memory allocation */
00197        pNewSdpNode->next = pgAuxSdpnList; /* Place this node in the front of List */
00198        pgAuxSdpnList     = pNewSdpNode;   /* Added by Scott Ma. 98-05-29 */
00199        
00200        /*
00201         *  Return the full list whose first node is pNewSdpNode. 
00202         *  Notice: return pgAuxSdpnList is also right!!
00203         */
00204        return pNewSdpNode;
00205 }
00206 
00207 
00208 /*
00209 ** Search pgAuxSdpnList to return the address of matched nIcID.
00210 ** If not found, return NULL
00211 */
00212 static XAux_SesDspParaNode* GetNodeAddressByIcID(int nIcID)
00213 {
00214        XAux_SesDspParaNode  *pThisSdpn;
00215        XAux_SesDspParaNode  *pTmpSdpn;
00216        
00217        pThisSdpn = NULL;
00218        pTmpSdpn  = pgAuxSdpnList;
00219        
00220        while (pTmpSdpn)
00221        {
00222               if (pTmpSdpn->nIcID == nIcID)
00223               {
00224                      pThisSdpn = pTmpSdpn;
00225                      break;
00226               }
00227               else
00228                      pTmpSdpn  = pTmpSdpn->next;
00229        }
00230        
00231        return pThisSdpn;
00232 }
00233 
00234 
00235 /*
00236 **  Destroy the specified node in pgAuxSdpnList and 
00237 **  re-assign the ->next field in the previous node
00238 **  to next node.
00239 **
00240 **  |n|---------|x| |n|---------|x| ... |n|---------|x|
00241 **   n --> nIcID,   x --> *next
00242 **
00243 **  Return   TRUE  ===> Successfully Destroyed!
00244 **           FALSE ===> Failed to Destroyed!
00245 */
00246 static BOOL DestroyNode(int nIcID)
00247 {
00248        XAux_SesDspParaNode  *pThisSdpn;
00249        XAux_SesDspParaNode  *pPrevNext;
00250        int   nFoundFlag;
00251        
00252        /* None node in pgAuxSdpnList */
00253        if (pgAuxSdpnList == NULL)
00254               return FALSE;
00255               
00256        /* The first node is just this one */
00257        pThisSdpn = pgAuxSdpnList;
00258        if (pThisSdpn->nIcID == nIcID)
00259        {
00260               pgAuxSdpnList = pThisSdpn->next;
00261               free (pThisSdpn);
00262               return TRUE;
00263        }
00264               
00265        /* Else, start directly from the 2th node in list */
00266        pThisSdpn  = pgAuxSdpnList->next;
00267        pPrevNext  = pgAuxSdpnList;
00268        nFoundFlag = FALSE;
00269        
00270        while (pThisSdpn)
00271        {
00272               if (pThisSdpn->nIcID == nIcID)
00273               {
00274                      pPrevNext->next = pThisSdpn->next;
00275                      free (pThisSdpn);
00276                      nFoundFlag = TRUE;
00277                      break;
00278               }
00279               else
00280               {
00281                      pThisSdpn = pThisSdpn->next;
00282                      pPrevNext = pPrevNext->next;
00283               }
00284        }
00285        
00286        return nFoundFlag;
00287 }
00288 
00289 
00290 /*
00291 ** The minimum valid value of nArraySize is 1. if 0, return.
00292 */
00293 static BOOL SetAuxNodeValues(XAux_SesDspParaNode* pThisSdpn, 
00294                              XAuxAttribute *pAttrArray, int nArraySize)
00295 {
00296        XAuxAttribute   *pTmpAttr;
00297 
00298        for( ; nArraySize > 0; nArraySize--)
00299        {
00300               pTmpAttr = &(pAttrArray[nArraySize - 1]);
00301               
00302 /*
00303 #ifndef NDEBUG
00304               if ((pTmpAttr->nAttrID >= 1) && (pTmpAttr->nAttrID <= 17))
00305               {
00306                      printf ("   ==> SetAuxNodeValues [%02d] %s\n", 
00307                              pTmpAttr->nAttrID, szAttrNames[pTmpAttr->nAttrID - 1]);
00308 
00309               }
00310               else
00311                      printf ("   ==> SetAuxNodeValues [%02d] %s\n", 
00312                              pTmpAttr->nAttrID, "???????");
00313 #endif
00314 */
00315               
00316               switch (pTmpAttr->nAttrID)
00317               {
00318               case XAUX_DISPLAY :
00319                      pThisSdpn->pDsp        = (Display *)(pTmpAttr->pvValue);
00320                      break;
00321                      
00322               case XAUX_SCREENNUM :
00323                      pThisSdpn->nScreenNum  = *(int *)(pTmpAttr->pvValue);
00324                      break;
00325 
00326               case XAUX_HTTWINDOW :
00327                      pThisSdpn->wndHttWin   = *(Window *)(pTmpAttr->pvValue);
00328                      break;
00329                      
00330               case XAUX_FONTSET :
00331                      pThisSdpn->xfsFontSet  = *(XFontSet *)(pTmpAttr->pvValue);
00332                      break;
00333                      
00334               case XAUX_AREA :
00335                      pThisSdpn->rectArea    = *(XRectangle *)(pTmpAttr->pvValue);
00336                      break;
00337                      
00338               case XAUX_AREANEEDED :
00339                      pThisSdpn->rectNeeded  = *(XRectangle *)(pTmpAttr->pvValue);
00340                      break;
00341                      
00342               case XAUX_COLORMAP :
00343                      pThisSdpn->cmap        = *(Colormap *)(pTmpAttr->pvValue);
00344                      break;
00345 
00346               case XAUX_STDCOLORMAP :
00347                      pThisSdpn->cmapStd     = *(Colormap *)(pTmpAttr->pvValue);
00348                      break;
00349 
00350               case XAUX_FOREGROUND :
00351                      pThisSdpn->fgPix       = *(unsigned long *)(pTmpAttr->pvValue);
00352                      break;
00353 
00354               case XAUX_BACKGROUND :
00355                      pThisSdpn->bgPix       = *(unsigned long *)(pTmpAttr->pvValue);
00356                      break;
00357                      
00358               case XAUX_LOCATION :
00359                      pThisSdpn->xyPointLoc  = *(xPoint *)(pTmpAttr->pvValue);
00360                      break;
00361                      
00362               case XAUX_FONTNAME:
00363                      pThisSdpn->pszFontName = (char *)(pTmpAttr->pvValue);
00364                      break;
00365                      
00366               case XAUX_REPLYCALLBACK :
00367                      pThisSdpn->fpReplyCb   = (void (*)())(pTmpAttr->pvValue);      
00368                      break;
00369                      
00370               case XAUX_REPLYCLIENTDATA :
00371                      pThisSdpn->pbReplyData = (void *)(pTmpAttr->pvValue);
00372                      break;
00373                      
00374               case XAUX_GC :
00375                      pThisSdpn->gc          = *(GC *)(pTmpAttr->pvValue);
00376                      break;
00377                      
00378               default :
00379                      break;
00380               }
00381        }
00382        
00383        return True;
00384 }
00385 
00386 
00387 /*
00388 **  The minimum valid value of nArraySize is 1. if 0, return.
00389 **
00390 **  Notice: Invoker must assure that related pAttrArray->nAttrID
00391 **          have already been set!  ==> Scott Ma
00392 **
00393 **  Warning:Only because pgAuxSdpnList is a global variant and
00394 **          were malloced, so we can return the address in this
00395 **          structure!! In C language, cannot return the address
00396 **          of a local variant!!    ==> Scott Ma
00397 */
00398 static BOOL GetAuxNodeValues(XAux_SesDspParaNode* pThisSdpn, 
00399                              XAuxAttribute *pAttrArray, int nArraySize)
00400 {
00401        XAuxAttribute   *pTmpAttr;
00402        
00403        for( ; nArraySize > 0; nArraySize--)
00404        {
00405               pTmpAttr = &(pAttrArray[nArraySize - 1]);
00406 /*
00407 #ifndef NDEBUG
00408               if ((pTmpAttr->nAttrID >= 1) && (pTmpAttr->nAttrID <= 17))
00409               {
00410                      printf ("   ==+++> GetAuxNodeValues [%02d] %s\n", 
00411                              pTmpAttr->nAttrID, szAttrNames[pTmpAttr->nAttrID - 1]);
00412               }
00413               else
00414                      printf ("   ==+++> GetAuxNodeValues [%02d] %s\n", 
00415                              pTmpAttr->nAttrID, "???????");
00416 #endif
00417 */
00418               
00419               switch (pTmpAttr->nAttrID)
00420               {
00421               case XAUX_DISPLAY :
00422                      pTmpAttr->pvValue      = (void *)(pThisSdpn->pDsp);
00423                      pTmpAttr->nLenValue    = sizeof(Display*);
00424                      break;
00425                      
00426               case XAUX_SCREENNUM :
00427                      pTmpAttr->pvValue      = (void *)&(pThisSdpn->nScreenNum);
00428                      pTmpAttr->nLenValue    = sizeof(int);
00429                      break;
00430 
00431               case XAUX_HTTWINDOW :
00432                      pTmpAttr->pvValue      = (void *)&(pThisSdpn->wndHttWin);
00433                      pTmpAttr->nLenValue    = sizeof(Window);
00434                      break;
00435                      
00436               case XAUX_FONTSET :
00437                      pTmpAttr->pvValue      = (void *)&(pThisSdpn->xfsFontSet);
00438                      pTmpAttr->nLenValue    = sizeof(XFontSet);
00439                      break;
00440                      
00441               case XAUX_AREA :
00442                      pTmpAttr->pvValue      = (void *)&(pThisSdpn->rectArea);
00443                      pTmpAttr->nLenValue    = sizeof(XRectangle);
00444                      break;
00445                      
00446               case XAUX_AREANEEDED :
00447                      pTmpAttr->pvValue      = (void *)&(pThisSdpn->rectNeeded);
00448                      pTmpAttr->nLenValue    = sizeof(XRectangle);
00449                      break;
00450                      
00451               case XAUX_COLORMAP :
00452                      pTmpAttr->pvValue      = (void *)&(pThisSdpn->cmap);
00453                      pTmpAttr->nLenValue    = sizeof(Colormap);
00454                      break;
00455 
00456               case XAUX_STDCOLORMAP :
00457                      pTmpAttr->pvValue      = (void *)&(pThisSdpn->cmapStd);
00458                      pTmpAttr->nLenValue    = sizeof(Colormap);
00459                      break;
00460 
00461               case XAUX_FOREGROUND :
00462                      pTmpAttr->pvValue      = (void *)&(pThisSdpn->fgPix);
00463                      pTmpAttr->nLenValue    = sizeof(unsigned long);
00464                      break;
00465 
00466               case XAUX_BACKGROUND :
00467                      pTmpAttr->pvValue      = (void *)&(pThisSdpn->bgPix);
00468                      pTmpAttr->nLenValue    = sizeof(unsigned long);
00469                      break;
00470                      
00471               case XAUX_LOCATION :
00472                      pTmpAttr->pvValue      = (void *)&(pThisSdpn->xyPointLoc);
00473                      pTmpAttr->nLenValue    = sizeof(xPoint);
00474                      break;
00475                      
00476               case XAUX_FONTNAME:
00477                      pTmpAttr->pvValue      = (void *)(pThisSdpn->pszFontName);
00478                      pTmpAttr->nLenValue    = sizeof(char *);
00479                      break;
00480                      
00481               case XAUX_REPLYCALLBACK :
00482                      pTmpAttr->pvValue      = (void *)(pThisSdpn->fpReplyCb);
00483                      pTmpAttr->nLenValue    = sizeof(void (*)());
00484                      break;
00485                      
00486               case XAUX_REPLYCLIENTDATA :
00487                      pTmpAttr->pvValue      = (void *)(pThisSdpn->pbReplyData);
00488                      pTmpAttr->nLenValue    = sizeof(void *);
00489                      break;
00490                      
00491               case XAUX_GC :
00492                      pTmpAttr->pvValue      = (void *)&(pThisSdpn->gc);
00493                      pTmpAttr->nLenValue    = sizeof(GC);
00494                      break;
00495                      
00496               default :
00497                      break;
00498               }
00499        }
00500        
00501        return True;
00502 }
00503 
00504 
00505 /*
00506 **  Notice: During realizeGUI, must set AREANEEDED and LOCATION info.
00507 */
00508 
00509 /*
00510 **  Is this nIcID already existed?
00511 **     1. NO,  PrefixNewNode() to pgAuxSdpnList, and Create GUI
00512 **     2. YES, SetAuxNodeValues() and RealizeGUI().
00513 */
00514 BOOL XAux_Create(int nIcID, XAuxAttribute *pAttrArray, int nArraySize)
00515 {
00516        XAux_SesDspParaNode  *pThisSdpn;
00517        
00518 printf("Creating...nIcID[%d]\n", nIcID);
00519 
00520        pThisSdpn = GetNodeAddressByIcID(nIcID);
00521        /* Not existed, alloc memory for it */
00522        if(pThisSdpn == NULL)
00523        {
00524               pThisSdpn  = PrefixNewNode(nIcID);
00525               if (pThisSdpn == NULL)
00526                      return FALSE;
00527        }
00528                      
00529        SetAuxNodeValues(pThisSdpn, pAttrArray, nArraySize);
00530        /* Create GUI, and set ->wndIM, wndBmp1, wndBmp2 ... */
00531 
00532 printf("Creating GUI\n");
00533        CreateGUI(pThisSdpn);
00534 
00535        pThisSdpn->nWndStatus = FALSE;
00536        
00537        return TRUE;
00538 }
00539 
00540 
00541 /*
00542 **  XAux_Start(): start an instance of the auxiliary object
00543 **                [pAcbs] means Pointer to Aux CallBack Struct.
00544 */
00545 BOOL XAux_Start(int nIcID, XIMAuxStartCallbackStruct *pAcbs)
00546 {
00547        XAux_SesDspParaNode  *pThisSdpn;
00548 
00549 printf("Starting...nIcID[%d]\n", nIcID);
00550 
00551        MapGUI(pThisSdpn);
00552 
00553 #ifdef notdef
00554        pThisSdpn = GetNodeAddressByIcID(nIcID);
00555        if (pThisSdpn == NULL) return FALSE;
00556 
00557        UnmapGUI(pThisSdpn);
00558        pThisSdpn->nWndStatus = FALSE;
00559 
00560        if(pAcbs != NULL) free(pAcbs);
00561 #endif
00562 
00563        return TRUE;
00564 }
00565 
00566 
00567 /*
00568 **  When the language engine calls iml_make_aux_draw_inst
00569 **       to let the X_auxiliary object to draw something.
00570 */
00571 BOOL XAux_Draw(int nIcID, XIMAuxDrawCallbackStruct *pAcbs) 
00572 {
00573        int i;
00574        XAux_SesDspParaNode  *pThisSdpn;
00575        int num_int, num_str;
00576        int * int_ptr;
00577     XIMText * str_ptr;
00578     int int_val;
00579     int str_val;
00580 
00581        pThisSdpn = GetNodeAddressByIcID(nIcID);
00582        if (pThisSdpn == NULL) return FALSE;
00583 
00584 printf("Drawing...nIcID[%d]\n", nIcID);
00585 
00586     num_int = pAcbs->count_integer_values;
00587     num_str = pAcbs->count_string_values;
00588     int_ptr = pAcbs->integer_values;
00589     str_ptr = pAcbs->string_values;
00590 
00591 printf("num_int=%d\n", num_int);
00592 printf("num_str=%d\n", num_str);
00593 
00594 for(i=0;i<num_int;i++){
00595        printf("int[%d]=%d\n", i, int_ptr[i]);
00596 }
00597 
00598 #ifdef notdef
00599     while (num_int--) {
00600         int_val = *int_ptr;
00601         switch (int_val) {
00602             case 1:
00603                 str_val = *(char *)(str_ptr -> string.multi_byte);
00604               pThisSdpn->nPuncState = str_val;
00605                 break;
00606             case 2:
00607                 str_val = *(char *)(str_ptr -> string.multi_byte);
00608               pThisSdpn->nSkbState = str_val;
00609                 break;
00610            case 3:
00611               break;
00612         }
00613         int_ptr++;
00614         str_ptr++;
00615     }
00616 /*
00617 printf("pThisSdpn->nPuncState = %d, pThisSdpn->nSkbState = %d\n",pThisSdpn->nPuncState, pThisSdpn->nSkbState);
00618 */
00619        MapGUI(pThisSdpn);
00620        pThisSdpn->nWndStatus = TRUE;
00621        
00622        free(pAcbs->integer_values);
00623        free(pAcbs->string_values);
00624        free(pAcbs);
00625        /* parse the call_data and do accordingly */
00626 #endif
00627        return TRUE;
00628 }
00629 
00630 
00631 /*
00632 **  When the language engine calls iml_make_aux_done_inst 
00633 **    to let the auxiliary object know that the previous
00634 **    draw action is done. 
00635 */
00636 BOOL XAux_Done(int nIcID, XIMAuxDoneCallbackStruct *pAcbs)
00637 {
00638        XAux_SesDspParaNode  *pThisSdpn;
00639 
00640 /*
00641 printf("Done...nIcID[%d]\n", nIcID);
00642 */
00643        pThisSdpn = GetNodeAddressByIcID(nIcID);
00644        if (pThisSdpn == NULL) return FALSE;
00645 
00646        UnmapGUI(pThisSdpn);
00647        pThisSdpn->nWndStatus = FALSE;
00648 
00649        if(pAcbs != NULL) free(pAcbs);
00650        return TRUE;
00651 }
00652 
00653 
00654 /*
00655 ** when a specific xic has the focus
00656 */
00657 BOOL XAux_SetFocus(int nIcID)
00658 {
00659        XAux_SesDspParaNode  *pThisSdpn;
00660 /*
00661 printf("SetFocus...nIcID[%d]\n", nIcID);
00662 */
00663        pThisSdpn = GetNodeAddressByIcID(nIcID);
00664        if (pThisSdpn == NULL) return FALSE;
00665               
00666        if(pThisSdpn->nWndStatus == TRUE) MapGUI(pThisSdpn);
00667        else UnmapGUI(pThisSdpn);
00668 
00669        /* parse the call_data and do something accordingly */
00670        return True;
00671 }
00672 
00673 
00674 /*
00675 ** when a specific xic has lost the focus
00676 */
00677 BOOL XAux_UnsetFocus(int nIcID)
00678 {
00679        XAux_SesDspParaNode  *pThisSdpn;
00680        
00681 /*
00682 printf("UnsetFocus...nIcID[%d]\n", nIcID);
00683 */
00684        pThisSdpn = GetNodeAddressByIcID(nIcID);
00685        if (pThisSdpn == NULL)
00686               return FALSE;
00687 
00688 /*     UnmapGUI(pThisSdpn);
00689 
00690        pThisSdpn->nWndStatus = FALSE;*/
00691               
00692        return TRUE;
00693 }
00694 
00695 
00696 /*
00697 **  The htt_server may set these values after negotiating with 
00698 **  the xaux object using xaux_GetValues.
00699 */
00700 BOOL XAux_SetValues(int nIcID, XAuxAttribute *pAttrArray, int nArraySize) 
00701 {
00702        XAux_SesDspParaNode  *pThisSdpn;
00703        BOOL    status;
00704        
00705 printf("SetValues...NIcID\n", nIcID);
00706 
00707 #ifdef notdef
00708        pThisSdpn = GetNodeAddressByIcID(nIcID);
00709        if (pThisSdpn == NULL)
00710               return FALSE;
00711        
00712        status = SetAuxNodeValues(pThisSdpn, pAttrArray, nArraySize);
00713 #endif
00714        return status;
00715 }
00716 
00717 
00718 /*
00719 **  The htt_server may use this method to negotiate with the xaux object 
00720 **  about the preferred settings. It can then go ahead and set the values
00721 **  in the xaux object using xaux_SetValues. 
00722 **  
00723 **  AREA and LOCATION info is important!!  ==> Scott Ma
00724 **  Notice: Invoker must assure that pAttrArray have already
00725 **          set related ->nAttrID !!
00726 */
00727 BOOL XAux_GetValues(int nIcID, XAuxAttribute *pAttrArray, int nArraySize)
00728 {
00729        XAux_SesDspParaNode  *pThisSdpn;
00730        BOOL    status;
00731        
00732 printf("GetValues...nIcID\n", nIcID);
00733 
00734        pThisSdpn = GetNodeAddressByIcID(nIcID);
00735        if (pThisSdpn == NULL)
00736               return FALSE;
00737               
00738        status = GetAuxNodeValues(pThisSdpn, pAttrArray, nArraySize);
00739        return status;
00740 }
00741 
00742 
00743 /*
00744 **  Define this method so that the htt_server can call this when 
00745 **  xic is destroyed and the corresponding session with xaux 
00746 **  object needs to be destroyed.
00747 */
00748 BOOL XAux_Destroy(int nIcID)
00749 {
00750        BOOL    status;
00751        
00752 /*
00753 printf("Destroying...nIcID\n", nIcID);
00754 */
00755        /* remove specified node */
00756        /* Should Destroy Windows for this nIcID */
00757        status = DestroyNode (nIcID);
00758        return status;
00759 }
00760 
00761 static BOOL MapGUI(XAux_SesDspParaNode *pThisSdpn)
00762 {
00763 #ifdef notdef
00764        UpdateWndBmp1(pThisSdpn);
00765        UpdateWndBmp2(pThisSdpn);
00766 #else
00767         XtRealizeWidget(toplevel);
00768         XtMapWidget(main_window);
00769 #endif
00770        return TRUE;
00771 }
00772 
00773 
00774 static BOOL UnmapGUI(XAux_SesDspParaNode *pThisSdpn)
00775 {
00776 #ifdef notdef
00777        XUnmapWindow(pThisSdpn->pDsp, pThisSdpn->wndBmp1);
00778        XUnmapWindow(pThisSdpn->pDsp, pThisSdpn->wndBmp2);
00779 #else
00780         XtUnmapWidget(main_window);
00781 #endif
00782        return TRUE;
00783 }
00784 
00785 void
00786 cancel_cb(
00787           Widget w,
00788           XtPointer clientData,
00789           XtPointer callData
00790 )
00791 {
00792     if (clientData) {
00793         XtUnrealizeWidget((Widget) clientData);
00794     }
00795 }
00796 
00797 void start_cb(Widget, XtPointer, XtPointer);
00798 void start_aux2(Widget);
00799 XtAppContext app_context;
00800 Widget label;
00801 
00802 static void * accept_loop(void *client_data);
00803 
00804 static BOOL CreateGUI(XAux_SesDspParaNode *pThisSdpn)
00805 {
00806 #ifdef notdef
00807        Display  *pDsp;
00808        Window    wndHttWin;
00809        int       nScreenNum;
00810        int       nStatus;
00811        Window    wndRoot, wndParent, *pwndChilds;
00812        UINT      nNumChild;
00813        
00814        XWindowAttributes *pXwa;
00815 
00816        pDsp       = pThisSdpn->pDsp;      
00817        wndHttWin  = pThisSdpn->wndHttWin;
00818        nScreenNum = DefaultScreen(pDsp);
00819        
00820        if (pThisSdpn->pDsp != NULL)
00821        {
00822               nStatus = XQueryTree(pDsp, wndHttWin, &wndRoot, &wndParent, &pwndChilds, &nNumChild);
00823               if (nStatus != 0)
00824               {
00825                      XGetWindowAttributes(pDsp, wndParent, pXwa);
00826 /*
00827                      ListXwaStruct(pXwa);
00828 */
00829                      pThisSdpn->wndParent = wndParent;
00830               }
00831               else
00832               {
00833                      printf("Error: XAuxMethods failed in XQueryTree()!\n");
00834                      return FALSE;
00835               }
00836        }
00837        
00838        /* This Window has nothing to do!! */
00839        pThisSdpn->wndIM = XCreateSimpleWindow(pDsp, wndHttWin,
00840                             pThisSdpn->rectArea.x,
00841                             pThisSdpn->rectArea.y,
00842                             pThisSdpn->rectArea.width,
00843                             pThisSdpn->rectArea.height,
00844                             0,                    /* Border Width */
00845                             pThisSdpn->bgPix,     /* Border Pixel */
00846                             pThisSdpn->bgPix);    /* Background Pixel */
00847        
00848        XMapWindow(pDsp, pThisSdpn->wndIM);
00849        
00850        
00851        /* Create and Map Bitmap1 Window */
00852        pThisSdpn->wndBmp1 = XCreateSimpleWindow (pDsp, wndParent,
00853                             (pXwa->width) - 50, 2,
00854                             16,        /* Width */
00855                             16,        /* Height */
00856                             0,
00857                             WhitePixel(pDsp, nScreenNum),
00858                             WhitePixel(pDsp, nScreenNum));
00859        
00860        XSelectInput (pDsp, pThisSdpn->wndBmp1, ExposureMask | ButtonPressMask | VisibilityChangeMask);
00861        _XRegisterFilterByType (pDsp, pThisSdpn->wndBmp1, Expose, Expose,
00862                               (BOOL(*)())aux_event_handler, (void *)pThisSdpn);
00863        _XRegisterFilterByType (pDsp, pThisSdpn->wndBmp1, ButtonPress, ButtonPress,
00864                               (BOOL(*)())aux_event_handler, (void *)pThisSdpn);
00865        _XRegisterFilterByType (pDsp, pThisSdpn->wndBmp1, VisibilityNotify, VisibilityNotify,
00866                               (BOOL(*)())aux_event_handler, (void *)pThisSdpn);
00867 /*     XMapWindow(pDsp, pThisSdpn->wndBmp1);*/
00868        
00869        /* Create and Map Bitmap2 Window */
00870        pThisSdpn->wndBmp2 = XCreateSimpleWindow (pDsp, wndParent,
00871                    (pXwa->width) - 30, 2,
00872                    16,
00873                    16,
00874                    0,
00875                    WhitePixel(pDsp, nScreenNum),
00876                    WhitePixel(pDsp, nScreenNum));
00877 
00878        XSelectInput (pDsp, pThisSdpn->wndBmp2, ExposureMask | ButtonPressMask | VisibilityChangeMask);
00879        _XRegisterFilterByType (pDsp, pThisSdpn->wndBmp2, Expose, Expose,
00880                               (BOOL(*)())aux_event_handler, (void *)pThisSdpn);
00881        _XRegisterFilterByType (pDsp, pThisSdpn->wndBmp2, ButtonPress, ButtonPress,
00882                               (BOOL(*)())aux_event_handler, (void *)pThisSdpn);
00883        _XRegisterFilterByType (pDsp, pThisSdpn->wndBmp2, VisibilityNotify, VisibilityNotify,
00884                               (BOOL(*)())aux_event_handler, (void *)pThisSdpn);
00885 /*     XMapWindow(pDsp, pThisSdpn->wndBmp2); */
00886        
00887        XFree(pXwa);
00888 #else
00889     {
00890     thread_t tid;
00891     int argc = 0;
00892     char **argv = 0;
00893     Arg args[20];
00894     int i;
00895     XtToolkitThreadInitialize();
00896     XtSetLanguageProc(NULL, NULL, NULL);
00897     toplevel = XtVaAppInitialize(&app_context,
00898                              "test",
00899                              NULL, NULL,
00900                              &argc, argv,
00901                              NULL, NULL);
00902     main_window = XmCreateMainWindow(toplevel, "mainw", NULL, 0);
00903     XtManageChild(main_window);
00904     i = 0;
00905     XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
00906     XtSetArg(args[i], XmNleftOffset, 10); i++;
00907     XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
00908     XtSetArg(args[i], XmNrightOffset, 10); i++;
00909     XtSetArg(args[i], XmNtopAttachment, XmATTACH_FORM); i++;
00910     XtSetArg(args[i], XmNtopOffset, 10); i++;
00911     XtSetArg(args[i], XmNorientation, XmHORIZONTAL); i++;
00912     rc = XmCreateRowColumn(main_window, "rowc", args, i);
00913     XtManageChild(rc);
00914 
00915     i = 0;
00916     XtSetArg(args[i], XmNlabelString, XmStringCreate("Add Word", XmSTRING_DEFAULT_CHARSET));
00917     i++;
00918     startbutton = XmCreatePushButton(rc, "addword", args, i);
00919     XtAddCallback(startbutton, XmNactivateCallback, start_cb, main_window);
00920     XtManageChild(startbutton);
00921 
00922     i = 0;
00923     XtSetArg(args[i], XmNlabelString, XmStringCreate("Send Data To Engine", XmSTRING_DEFAULT_CHARSET));
00924     i++;
00925     sendbutton = XmCreatePushButton(rc, "sendbutton", args, i);
00926     XtManageChild(sendbutton);
00927 
00928     i = 0;
00929     XtSetArg(args[i], XmNlabelString, XmStringCreate("Done", XmSTRING_DEFAULT_CHARSET));
00930     i++;
00931     donebutton = XmCreatePushButton(rc, "donebutton", args, i);
00932     XtManageChild(donebutton);
00933 
00934     i = 0;
00935     XtSetArg(args[i], XmNlabelString, XmStringCreate("DISPLAY RECEIVED DATA", XmSTRING_DEFAULT_CHARSET));
00936     i++;
00937     label = XmCreateLabel(rc, "label", args, i);
00938     XtManageChild(label);
00939 
00940     thr_create(NULL, 0, accept_loop, 0, THR_BOUND, &tid);
00941     }
00942 #endif
00943        
00944     return TRUE;
00945 }
00946 
00947 static void *
00948 accept_loop(void *client_data)
00949 {
00950 printf("accept_loo\n");
00951     XtAppMainLoop((XtAppContext)app_context);
00952 printf("accept_loop exit\n");
00953     return 0;
00954 }
00955 
00956 
00957 #ifdef notdef
00958 
00959 static void aux_event_handler(Display* pDsp, Window wnd, XEvent* pEvent, void* pvCallData)
00960 {
00961        XAux_SesDspParaNode       *pThisSdpn;
00962        static char  chPuncState, chSkbState, chButtonNo;
00963        static       XIMAuxDrawCallbackStruct  *pAcbs = NULL;
00964        int          nIcID;
00965        
00966        pThisSdpn = (XAux_SesDspParaNode *)pvCallData;
00967        if (pThisSdpn != NULL)
00968        {
00969               nIcID     = pThisSdpn->nIcID;
00970               assert(pDsp == pThisSdpn->pDsp); 
00971               pDsp = pThisSdpn->pDsp;
00972        }
00973 
00974        switch (pEvent->type)
00975        {
00976        case VisibilityNotify :
00977        case Expose :
00978               if (wnd == pThisSdpn->wndBmp1)
00979                      UpdateWndBmp1(pThisSdpn);
00980               else if (wnd == pThisSdpn->wndBmp2)
00981                      UpdateWndBmp2(pThisSdpn);
00982               break;
00983               
00984        case ButtonPress :
00985               chButtonNo = (char)pEvent->xbutton.button;
00986               if (pAcbs != NULL) free(pAcbs);
00987               pAcbs = (XIMAuxDrawCallbackStruct *)malloc(sizeof(XIMAuxDrawCallbackStruct));
00988               pAcbs->count_integer_values  = 2;
00989               pAcbs->count_string_values   = 2;
00990               pAcbs->integer_values = (int *)malloc(sizeof(int) * (pAcbs->count_integer_values));
00991               pAcbs->string_values = (XIMText *)malloc(sizeof(XIMText) * (pAcbs->count_string_values));
00992               
00993               *(pAcbs->integer_values)  = BUTTON_NUMBER;
00994               pAcbs->string_values->length = 5;
00995               pAcbs->string_values->encoding_is_wchar = 0;
00996               pAcbs->string_values->string.multi_byte = (char *)&chButtonNo;
00997               
00998               if (wnd == pThisSdpn->wndBmp1)
00999               {
01000                      chPuncState = (char)pThisSdpn->nPuncState;
01001                      *((pAcbs->integer_values) + 1)  = PUNCTUATION_STATUS;
01002                      ((pAcbs->string_values) + 1)->length = 5;
01003                      ((pAcbs->string_values) + 1)->encoding_is_wchar = 0;
01004                      ((pAcbs->string_values) + 1)->string.multi_byte = (char *)&chPuncState;
01005               }
01006               
01007               if (wnd == pThisSdpn->wndBmp2)
01008               {
01009                      chSkbState = (char)pThisSdpn->nSkbState;
01010                      *((pAcbs->integer_values) + 1)= SOFTKEYBOARD_LAYOUT;
01011                      ((pAcbs->string_values) + 1)->length = 5;
01012                      ((pAcbs->string_values) + 1)->encoding_is_wchar = 0;
01013                      ((pAcbs->string_values) + 1)->string.multi_byte = (char *)&chSkbState;
01014               }
01015               
01016               pThisSdpn->fpReplyCb(nIcID, pThisSdpn->pbReplyData, pAcbs);
01017               break;
01018               
01019        default :
01020               break;
01021        }
01022        
01023        return;
01024 }
01025 
01026 
01027 static void UpdateWndBmp1(XAux_SesDspParaNode *pThisSdpn)
01028 {
01029        PutXpm(pThisSdpn->pDsp, pThisSdpn->wndBmp1, 0, 0, 
01030               PuncXpmArray[pThisSdpn->nPuncState], -1, -1, -1, -1, 0);
01031               
01032        XMapWindow(pThisSdpn->pDsp, pThisSdpn->wndBmp1);
01033 }
01034 
01035 
01036 static void UpdateWndBmp2(XAux_SesDspParaNode *pThisSdpn)
01037 {
01038        PutXpm(pThisSdpn->pDsp, pThisSdpn->wndBmp2, 0, 0, 
01039               SkbXpmArray[pThisSdpn->nSkbState], -1, -1, -1, -1, 0);
01040 
01041        XMapWindow(pThisSdpn->pDsp, pThisSdpn->wndBmp2);
01042 }
01043 
01044 
01045 
01046 static void ListXwaStruct(XWindowAttributes *pXwa)
01047 {
01048        printf("    pXwa->x     [%04d]\n", pXwa->x);
01049        printf("    pXwa->y     [%04d]\n", pXwa->y);
01050        printf("    pXwa->width [%04d]\n", pXwa->width);
01051        printf("    pXwa->height[%04d]\n", pXwa->height);
01052        printf("    pXwa->depth [%04d]\n", pXwa->depth);
01053        printf("    pXwa->map_state: ");
01054               if(pXwa->map_state == IsUnmapped)
01055                      printf("[IsUnmapped]\n");
01056               else if(pXwa->map_state == IsUnviewable)
01057                      printf("[IsUnviewable]\n");
01058               else if(pXwa->map_state == IsViewable)
01059                      printf("[IsViewable]\n");
01060 }
01061 #endif
01062 
01063 void
01064 start_cb(
01065          Widget w,
01066          XtPointer clientData,
01067          XtPointer callData
01068 )
01069 {
01070     start_aux2((Widget) clientData);
01071 }
01072 
01073 
01074 void
01075 start_aux2(
01076           Widget parent
01077 )
01078 {
01079     Widget button1, button2, rc;
01080     Widget label1, label2;
01081     Widget text1, text2;
01082     Arg args[20];
01083     int i;
01084 
01085     if (aux2_dialog) {
01086        XtManageChild(aux2_dialog);
01087        XtRealizeWidget(aux2_dialog);
01088        return;
01089     }
01090     i = 0;
01091     XtSetArg(args[i], XmNtitle, "AUX2 DICTIONALY TOOL");
01092     i++;
01093     aux2_dialog = XmCreateFormDialog(parent, "dict_dialog", args, i);
01094 
01095     i = 0;
01096     XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
01097     XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
01098     XtSetArg(args[i], XmNtopAttachment, XmATTACH_FORM); i++;
01099     XtSetArg(args[i], XmNorientation, XmHORIZONTAL); i++;
01100     rc = XmCreateRowColumn(aux2_dialog, "rowc", args, i);
01101     XtManageChild(rc);
01102 
01103     i = 0;
01104     XtSetArg(args[i], XmNlabelString, XmStringCreate("String:", XmSTRING_DEFAULT_CHARSET)); i++;
01105     label1 = XmCreateLabel(rc, "label1", args, i);
01106     XtManageChild(label1);
01107 
01108     i = 0;
01109     XtSetArg(args[i], XmNcolumns, 15);
01110     i++;
01111     text1 = XmCreateTextField(rc, "textfield1", args, i);
01112     XtManageChild(text1);
01113 
01114     i = 0;
01115     XtSetArg(args[i], XmNlabelString, XmStringCreate("Japanese:", XmSTRING_DEFAULT_CHARSET));
01116     i++;
01117     label2 = XmCreateLabel(rc, "label2", args, i);
01118     XtManageChild(label2);
01119 
01120     i = 0;
01121     XtSetArg(args[i], XmNcolumns, 15);
01122     i++;
01123     text2 = XmCreateTextField(rc, "textfield2", args, i);
01124     XtManageChild(text2);
01125 
01126     i = 0;
01127     XtSetArg(args[i], XmNlabelString, XmStringCreate("Add", XmSTRING_DEFAULT_CHARSET));
01128     i++;
01129     button1 = XmCreatePushButton(rc, "button1", args, i);
01130     XtManageChild(button1);
01131 
01132     i = 0;
01133     XtManageChild(button1);
01134     XtSetArg(args[i], XmNlabelString, XmStringCreate("Cancel", XmSTRING_DEFAULT_CHARSET));
01135     i++;
01136     button2 = XmCreatePushButton(rc, "button2", args, i);
01137     XtAddCallback(button2, XmNactivateCallback, cancel_cb, aux2_dialog);
01138     XtManageChild(button2);
01139 
01140     XtManageChild(aux2_dialog);
01141 }