home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / edtrcdll / src / imewrap.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.5 KB  |  238 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "stdafx.h"
  20. #include "imewrap.h"
  21. #include "edtiface.h"//for the callbacks
  22. /*imewrap.h edtor client wrapper */
  23. /*Dynamic Library wrapper for loading on call*/
  24.  
  25.  
  26. HINSTANCE CIMEDll::s_dllinstance=NULL;
  27. unsigned int CIMEDll::s_refcount=0;
  28.  
  29.  
  30. IMMNOTIFYIME                CIMEDll::s_ImmNotifyIME=NULL;
  31. IMMGETCONTEXT               CIMEDll::s_ImmGetContext=NULL;
  32. IMMRELEASECONTEXT           CIMEDll::s_ImmReleaseContext=NULL;
  33. IMMGETCOMPOSITIONSTRING     CIMEDll::s_ImmGetCompositionString=NULL;
  34. IMMSETCANDIDATEWINDOW       CIMEDll::s_ImmSetCandidateWindow=NULL;
  35. IMMSETCOMPOSITIONWINDOW     CIMEDll::s_ImmSetCompositionWindow=NULL;
  36. IMMSETCOMPOSITIONFONT       CIMEDll::s_ImmSetCompositionFont=NULL;
  37. IMMSETCOMPOSITIONSTRING     CIMEDll::s_ImmSetCompositionString=NULL;
  38. IMMGETCONVERSIONSTATUS      CIMEDll::s_ImmGetConversionStatus=NULL;
  39. IMMSETCONVERSIONSTATUS      CIMEDll::s_ImmSetConversionStatus=NULL;
  40. IMEESCAPE                   CIMEDll::s_ImmEscape=NULL;
  41.  
  42. #ifdef WIN32
  43. #define XP_ASSERT(x) assert(x)
  44. #else
  45. #define XP_ASSERT(x) 
  46. #endif
  47.  
  48. CIMEDll::CIMEDll()
  49. {
  50.     HINSTANCE t_instance=LoadLibrary("IMM32.DLL");
  51.     if(!t_instance)
  52.     {
  53.         s_dllinstance=NULL;
  54.         s_ImmNotifyIME=NULL;
  55.         s_ImmGetContext=NULL;
  56.         s_ImmReleaseContext=NULL;
  57.         s_ImmGetCompositionString=NULL;
  58.         s_ImmSetCandidateWindow=NULL;
  59.         s_ImmSetCompositionWindow=NULL;
  60.         s_ImmSetCompositionFont=NULL;
  61.         s_ImmSetCompositionString=NULL;
  62.         s_ImmGetConversionStatus=NULL;
  63.         s_ImmSetConversionStatus=NULL;
  64.         s_ImmEscape=NULL;
  65.         return;//this is OK! this must be an english version of NT3.5
  66.     }
  67.     s_refcount++;
  68.     if (t_instance==s_dllinstance)
  69.         return;
  70.     else
  71.     {
  72.         s_dllinstance=t_instance;
  73.         //retrieve all proc addresses and place them into holders
  74.         s_ImmNotifyIME= (IMMNOTIFYIME)GetProcAddress(s_dllinstance,"ImmNotifyIME");
  75.         XP_ASSERT(s_ImmNotifyIME);
  76.  
  77.         s_ImmGetContext= (IMMGETCONTEXT)GetProcAddress(s_dllinstance,"ImmGetContext");
  78.         XP_ASSERT(s_ImmGetContext);
  79.  
  80.         s_ImmReleaseContext= (IMMRELEASECONTEXT)GetProcAddress(s_dllinstance,"ImmReleaseContext");
  81.         XP_ASSERT(s_ImmReleaseContext);
  82.  
  83.         #ifdef UNICODE_ONLY
  84.         s_ImmGetCompositionString= (IMMGETCOMPOSITIONSTRING)GetProcAddress(s_dllinstance,"ImmGetCompositionStringW");
  85.         #else //ANSI ONLY
  86.         s_ImmGetCompositionString= (IMMGETCOMPOSITIONSTRING)GetProcAddress(s_dllinstance,"ImmGetCompositionStringA");
  87.         #endif //!ANSI_ONLY
  88.         XP_ASSERT(s_ImmGetCompositionString);
  89.  
  90.         #ifdef UNICODE_ONLY
  91.         s_ImmSetCompositionFont= (IMMSETCOMPOSITIONFONT)GetProcAddress(s_dllinstance,"ImmSetCompositionFontW");
  92.         #else //ANSI ONLY
  93.         s_ImmSetCompositionFont= (IMMSETCOMPOSITIONFONT)GetProcAddress(s_dllinstance,"ImmSetCompositionFontA");
  94.         #endif //!ANSI_ONLY
  95.         XP_ASSERT(s_ImmSetCompositionFont);
  96.  
  97.         s_ImmSetCandidateWindow= (IMMSETCANDIDATEWINDOW)GetProcAddress(s_dllinstance,"ImmSetCandidateWindow");
  98.         XP_ASSERT(s_ImmSetCandidateWindow);
  99.  
  100.         s_ImmSetCompositionWindow= (IMMSETCOMPOSITIONWINDOW)GetProcAddress(s_dllinstance,"ImmSetCompositionWindow");
  101.         XP_ASSERT(s_ImmSetCompositionWindow);
  102.  
  103.         #ifdef UNICODE_ONLY
  104.         s_ImmSetCompositionString= (IMMSETCOMPOSITIONSTRING)GetProcAddress(s_dllinstance,"ImmSetCompositionStringW");
  105.         #else //ANSI ONLY
  106.         s_ImmSetCompositionString= (IMMSETCOMPOSITIONSTRING)GetProcAddress(s_dllinstance,"ImmSetCompositionStringA");
  107.         #endif //!ANSI_ONLY
  108.         XP_ASSERT(s_ImmSetCompositionString);
  109.  
  110.         s_ImmGetConversionStatus= (IMMGETCONVERSIONSTATUS)GetProcAddress(s_dllinstance,"ImmGetConversionStatus");
  111.         XP_ASSERT(s_ImmGetConversionStatus);
  112.  
  113.         s_ImmSetConversionStatus= (IMMSETCONVERSIONSTATUS)GetProcAddress(s_dllinstance,"ImmSetConversionStatus");
  114.         XP_ASSERT(s_ImmSetConversionStatus);
  115.  
  116.         #ifdef UNICODE_ONLY
  117.         s_ImmEscape= (IMEESCAPE)GetProcAddress(s_dllinstance,"ImmEscapeW");
  118.         #else //ANSI ONLY
  119.         s_ImmEscape= (IMEESCAPE)GetProcAddress(s_dllinstance,"ImmEscapeA");
  120.         #endif //!ANSI_ONLY
  121.         XP_ASSERT(s_ImmEscape);
  122.  
  123.     }
  124. }
  125.  
  126. CIMEDll::~CIMEDll()
  127. {
  128.     if (s_dllinstance)
  129.     {
  130.         if (!FreeLibrary(s_dllinstance))
  131.             XP_ASSERT(0);
  132.         s_refcount--;
  133.     }
  134.     if (!s_refcount)
  135.         s_dllinstance=NULL;
  136. }
  137.  
  138. BOOL
  139. CIMEDll::ImmNotifyIME(HIMC hIMC,DWORD dwAction,DWORD dwIndex,DWORD dwValue)
  140. {
  141.     if (s_ImmNotifyIME)
  142.         return (*s_ImmNotifyIME)(hIMC,dwAction,dwIndex,dwValue);
  143.     else
  144.         return FALSE;
  145. }
  146.  
  147. HIMC
  148. CIMEDll::ImmGetContext(HWND hWnd)
  149. {
  150.     if (s_ImmGetContext)
  151.         return (*s_ImmGetContext)(hWnd);
  152.     else
  153.         return FALSE;
  154. }
  155.  
  156. BOOL 
  157. CIMEDll::ImmReleaseContext(HWND hWnd,HIMC hIMC)
  158. {
  159.     if (s_ImmReleaseContext)
  160.         return (*s_ImmReleaseContext)(hWnd,hIMC);
  161.     else
  162.         return FALSE;
  163. }
  164.  
  165. LONG 
  166. CIMEDll::ImmGetCompositionString(HIMC hIMC,DWORD dwIndex,LPVOID lpBuf,DWORD dwBufLen)
  167. {
  168.     if (s_ImmGetCompositionString)
  169.         return (*s_ImmGetCompositionString)(hIMC,dwIndex,lpBuf,dwBufLen);
  170.     else
  171.         return FALSE;
  172. }
  173.  
  174. BOOL 
  175. CIMEDll::ImmSetCompositionFont(HIMC hIMC,LPLOGFONT lpLogFont)
  176. {
  177.     if (s_ImmSetCompositionFont)
  178.         return (*s_ImmSetCompositionFont)(hIMC,lpLogFont);
  179.     else
  180.         return FALSE;
  181. }
  182.  
  183. BOOL 
  184. CIMEDll::ImmSetCandidateWindow(HIMC hIMC, LPCANDIDATEFORM lpcandidate)
  185. {
  186.     if (s_ImmSetCandidateWindow)
  187.         return (*s_ImmSetCandidateWindow)(hIMC,lpcandidate);
  188.     else
  189.         return FALSE;
  190. }
  191.  
  192. BOOL 
  193. CIMEDll::ImmSetCompositionWindow(HIMC hIMC,LPCOMPOSITIONFORM lpcomposition)
  194. {
  195.     if (s_ImmSetCompositionWindow)
  196.         return (*s_ImmSetCompositionWindow)(hIMC,lpcomposition);
  197.     else
  198.         return FALSE;
  199. }
  200.  
  201. BOOL
  202. CIMEDll::ImmSetCompositionString(HIMC hIMC,DWORD dwIndex,LPVOID lpComp,DWORD dwCompLen,LPVOID lpRead,DWORD dwReadLen)
  203. {
  204.     if (s_ImmSetCompositionString)
  205.         return (*s_ImmSetCompositionString)(hIMC,dwIndex,lpComp,dwCompLen,lpRead,dwReadLen);
  206.     else
  207.         return FALSE;
  208. }
  209.  
  210.  
  211. BOOL
  212. CIMEDll::ImmSetConversionStatus(HIMC hIMC,DWORD fdwConversion,DWORD fdwSentence)
  213. {
  214.     if (s_ImmSetConversionStatus)
  215.         return (*s_ImmSetConversionStatus)(hIMC,fdwConversion,fdwSentence);
  216.     else
  217.         return FALSE;
  218. }
  219.  
  220. BOOL
  221. CIMEDll::ImmGetConversionStatus(HIMC hIMC,LPDWORD lpfdwConversion,LPDWORD lpfdwSentence)
  222. {
  223.     if (s_ImmGetConversionStatus)
  224.         return (*s_ImmGetConversionStatus)(hIMC,lpfdwConversion,lpfdwSentence);
  225.     else
  226.         return FALSE;
  227. }
  228.  
  229. LRESULT 
  230. CIMEDll::ImeEscape(HKL hKL,HIMC hIMC,UINT uEscape,LPVOID lpData)
  231. {
  232.     if (s_ImmEscape)
  233.         return (*s_ImmEscape)(hKL,hIMC,uEscape,lpData);
  234.     else
  235.         return FALSE;
  236. }
  237.  
  238.