Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

407 lines
12 KiB

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include <objbase.h>
  4. #include "memmgr.h"
  5. #include "hwxapp.h"
  6. #include "hwxobj.h"
  7. #include "resource.h"
  8. #include "guids.h" //980408:ToshiaK
  9. #include "hwxfe.h" //980803 new: By ToshiaK
  10. #include "dbg.h"
  11. #include "ipoint1.h" //990507:HiroakiK for IPINS_CURRENT
  12. #ifdef UNDER_CE // Windows CE Stub for unsupported APIs
  13. #include "stub_ce.h"
  14. #endif // UNDER_CE
  15. STDMETHODIMP CApplet::QueryInterface(REFIID refiid, VOID **ppv)
  16. {
  17. if(refiid == IID_IUnknown) {
  18. *ppv = static_cast<IImePadApplet *>(this);
  19. }
  20. else if(refiid == IID_IImeSpecifyApplets) {
  21. *ppv = static_cast<IImeSpecifyApplets *>(this);
  22. }
  23. else if(refiid == IID_MultiBox) {
  24. *ppv = static_cast<IImePadApplet *>(this);
  25. }
  26. else {
  27. *ppv = NULL;
  28. return E_NOINTERFACE;
  29. }
  30. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  31. return S_OK;
  32. }
  33. STDMETHODIMP_(ULONG) CApplet::AddRef(void)
  34. {
  35. return InterlockedIncrement(&m_cRef);
  36. }
  37. STDMETHODIMP_(ULONG) CApplet::Release(void)
  38. {
  39. if(InterlockedDecrement(&m_cRef) == 0) {
  40. delete this;
  41. return 0;
  42. }
  43. return m_cRef;
  44. }
  45. //////////////////////////////////////////////////////////////////
  46. // Function : CApplet::GetAppletIIDList
  47. // Type : STDMETHODIMP
  48. // Purpose : Enhancement for IME98A
  49. // Args :
  50. // : REFIID refiid
  51. // : LPAPPLETIDLIST lpIIDList
  52. // Return :
  53. // DATE : Thu Apr 09 22:46:04 1998
  54. // Author : ToshiaK
  55. //////////////////////////////////////////////////////////////////
  56. STDMETHODIMP CApplet::GetAppletIIDList(REFIID refiid,
  57. LPAPPLETIDLIST lpIIDList)
  58. {
  59. if(refiid == IID_IImePadApplet) {
  60. lpIIDList->pIIDList = (IID *)::CoTaskMemAlloc(sizeof(IID)*1);
  61. if(!lpIIDList->pIIDList) {
  62. return E_OUTOFMEMORY;
  63. }
  64. lpIIDList->pIIDList[0] = IID_MultiBox;
  65. lpIIDList->count = 1;
  66. return S_OK;
  67. }
  68. return E_NOINTERFACE;
  69. }
  70. CApplet::CApplet()
  71. {
  72. m_cRef = 1; //ToshiaK
  73. m_pPad = NULL;
  74. m_bInit = FALSE;
  75. m_hInstance = NULL;
  76. m_pCHwxInkWindow = NULL;
  77. }
  78. CApplet::CApplet(HINSTANCE hInst)
  79. {
  80. m_cRef = 1;
  81. m_pPad = NULL;
  82. m_bInit = FALSE;
  83. m_hInstance = hInst;
  84. m_pCHwxInkWindow = NULL;
  85. }
  86. CApplet::~CApplet()
  87. {
  88. // should call Terminate() before deleting CApplet object
  89. }
  90. // detect if this IME instance is attached to a 16-bit program
  91. DWORD WINAPI Dummy(LPVOID pv)
  92. {
  93. return 0;
  94. UNREFERENCED_PARAMETER(pv);
  95. }
  96. //----------------------------------------------------------------
  97. //ToshiaK: temporary Code
  98. //----------------------------------------------------------------
  99. static INT GetPlatform(VOID)
  100. {
  101. static INT platForm;
  102. static BOOL fFirst = TRUE;
  103. static OSVERSIONINFO verInfo;
  104. if(fFirst) {
  105. verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  106. if ( GetVersionEx( &verInfo) ) {
  107. fFirst = FALSE;
  108. }
  109. platForm = verInfo.dwPlatformId;
  110. }
  111. return platForm;
  112. }
  113. BOOL IsWindowsNT(VOID)
  114. {
  115. #ifndef UNDER_CE // Windows CE
  116. if(GetPlatform() == VER_PLATFORM_WIN32_NT) {
  117. return TRUE;
  118. }
  119. return FALSE;
  120. #else // UNDER_CE
  121. return TRUE;
  122. #endif // UNDER_CE
  123. }
  124. STDMETHODIMP CApplet::Initialize(IUnknown *pIImePad)
  125. {
  126. HRESULT hr = S_OK;
  127. if ( !m_bInit )
  128. {
  129. //for IME98A Enhancement: By ToshiaK
  130. pIImePad->QueryInterface(IID_IImePad, (LPVOID *)&m_pPad);
  131. // support both WINDOWS95 and WINDOWS NT
  132. //----------------------------------------------------------------
  133. //ToshiaK: 970715
  134. //opengl32.dll is included in Memphis
  135. //below code recognize platform as WinNT in Memphis environment
  136. //----------------------------------------------------------------
  137. BOOL bNT = IsWindowsNT();
  138. HANDLE hLib;
  139. // see if this IME is attached to a 16 bit program
  140. BOOL b16 = FALSE;
  141. //DWORD dID = 0;
  142. hLib = NULL;
  143. // hLib = CreateThread(NULL,0,Dummy,NULL,CREATE_SUSPENDED,&dID);
  144. #ifdef BUGBUG
  145. hLib = CreateThread(NULL,0,Dummy,NULL,0,&dID);
  146. if ( !hLib )
  147. b16 = TRUE;
  148. else
  149. CloseHandle(hLib);
  150. #endif
  151. b16 = CHwxFE::Is16bitApplication();
  152. Dbg(("b16 %d\n", b16));
  153. // GetModuleFileName(m_hInstance, tchPath, sizeof(tchPath)/sizeof(tchPath[0]));
  154. m_pCHwxInkWindow = (CHwxInkWindow *)new CHwxInkWindow(bNT,b16,this,m_hInstance);
  155. if ( !m_pCHwxInkWindow )
  156. {
  157. m_pPad->Release();
  158. m_pPad = NULL;
  159. hr = S_FALSE;
  160. }
  161. if ( hr == S_OK )
  162. {
  163. if ( !m_pCHwxInkWindow->Initialize(TEXT("CHwxInkWindow")) )
  164. {
  165. m_pPad->Release();
  166. m_pPad = NULL;
  167. delete m_pCHwxInkWindow;
  168. m_pCHwxInkWindow = NULL;
  169. hr = S_FALSE;
  170. }
  171. else
  172. {
  173. m_bInit = TRUE;
  174. }
  175. }
  176. }
  177. return hr;
  178. }
  179. STDMETHODIMP CApplet::Terminate(VOID)
  180. {
  181. Dbg(("CApplet::Terminate START\n"));
  182. if ( m_pPad )
  183. {
  184. m_pPad->Release();
  185. m_pPad = NULL;
  186. }
  187. m_hInstance = NULL;
  188. m_bInit = FALSE;
  189. if ( m_pCHwxInkWindow )
  190. {
  191. m_pCHwxInkWindow->Terminate();
  192. delete m_pCHwxInkWindow;
  193. m_pCHwxInkWindow = NULL;
  194. }
  195. return S_OK;
  196. }
  197. STDMETHODIMP CApplet::GetAppletConfig(LPIMEAPPLETCFG lpAppletCfg)
  198. {
  199. //----------------------------------------------------------------
  200. //980803: by ToshiaKfor FarEast merge.
  201. //----------------------------------------------------------------
  202. CHwxFE::GetTitleStringW(m_hInstance,
  203. lpAppletCfg->wchTitle,
  204. sizeof(lpAppletCfg->wchTitle)/sizeof(lpAppletCfg->wchTitle[0]));
  205. BOOL b16 = FALSE;
  206. //DWORD dID = 0;
  207. //HANDLE hLib = NULL;
  208. #ifdef BUGBUG //981120
  209. hLib = CreateThread(NULL,0,Dummy,NULL,0,&dID);
  210. if ( !hLib )
  211. b16 = TRUE;
  212. else
  213. CloseHandle(hLib);
  214. #endif
  215. //we have to use this one to check this.
  216. b16 = CHwxFE::Is16bitApplication();
  217. #ifdef FE_JAPANESE
  218. lpAppletCfg->hIcon = (HICON)LoadImage(m_hInstance,
  219. MAKEINTRESOURCE(IDI_HWXPAD),
  220. IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
  221. #elif FE_KOREAN
  222. lpAppletCfg->hIcon = (HICON)LoadImage(m_hInstance,
  223. MAKEINTRESOURCE(IDI_HWXPADKO),
  224. IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
  225. #elif FE_CHINESE_SIMPLIFIED
  226. lpAppletCfg->hIcon = (HICON)LoadImage(m_hInstance,
  227. MAKEINTRESOURCE(IDI_HWXPADSC),
  228. IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
  229. #endif
  230. lpAppletCfg->dwConfig = (!b16 ? IPACFG_PROPERTY : 0) | IPACFG_HELP;
  231. lpAppletCfg->iCategory = IPACID_HANDWRITING; //970812:ToshiaK
  232. //----------------------------------------------------------------
  233. //000804: Satori #2286. for Check Applet's main language to invoke help.
  234. //----------------------------------------------------------------
  235. #ifdef FE_JAPANESE
  236. lpAppletCfg->langID = MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT);
  237. #elif FE_KOREAN
  238. lpAppletCfg->langID = MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT);
  239. #elif FE_CHINESE_SIMPLIFIED
  240. lpAppletCfg->langID = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED);
  241. #endif
  242. return S_OK;
  243. }
  244. STDMETHODIMP CApplet::CreateUI(HWND hwndParent,
  245. LPIMEAPPLETUI lpImeAppletUI)
  246. {
  247. HRESULT hr = S_OK;
  248. if( m_pCHwxInkWindow )
  249. {
  250. if ( !m_pCHwxInkWindow->GetInkWindow() )
  251. {
  252. if ( !m_pCHwxInkWindow->CreateUI(hwndParent) )
  253. {
  254. hr = S_FALSE;
  255. }
  256. }
  257. lpImeAppletUI->dwStyle = IPAWS_SIZINGNOTIFY;
  258. lpImeAppletUI->hwnd = m_pCHwxInkWindow->GetInkWindow();
  259. lpImeAppletUI->width = m_pCHwxInkWindow->GetInkWindowWidth() + 3*Box_Border;
  260. lpImeAppletUI->height = m_pCHwxInkWindow->GetInkWindowHeight();
  261. }
  262. else
  263. {
  264. hr = S_FALSE;
  265. }
  266. return hr;
  267. }
  268. STDMETHODIMP CApplet::Notify(IUnknown *pImePad,
  269. INT notify,
  270. WPARAM wParam,
  271. LPARAM lParam)
  272. {
  273. switch (notify)
  274. {
  275. case IMEPN_ACTIVATE:
  276. if ( m_pCHwxInkWindow )
  277. {
  278. UpdateWindow(GetParent(m_pCHwxInkWindow->GetInkWindow()));
  279. InvalidateRect(m_pCHwxInkWindow->GetInkWindow(),NULL,TRUE);
  280. UpdateWindow(m_pCHwxInkWindow->GetInkWindow());
  281. }
  282. break;
  283. case IMEPN_INACTIVATE:
  284. break;
  285. case IMEPN_SHOW:
  286. if ( m_pCHwxInkWindow )
  287. {
  288. //----------------------------------------------------------------
  289. //for IME98A raid #2027.
  290. //980612: by ToshiaK. Check window is created or not.
  291. //when IMEPN_SHOW come before window has created,
  292. // UpdateWindow(NULL); is called and Desktop flushes.
  293. //----------------------------------------------------------------
  294. if(m_pCHwxInkWindow->GetInkWindow() != NULL && ::IsWindow(m_pCHwxInkWindow->GetInkWindow())) {
  295. UpdateWindow(GetParent(m_pCHwxInkWindow->GetInkWindow()));
  296. InvalidateRect(m_pCHwxInkWindow->GetInkWindow(),NULL,TRUE);
  297. UpdateWindow(m_pCHwxInkWindow->GetInkWindow());
  298. if ( !m_pCHwxInkWindow->Is16BitApp() )
  299. {
  300. m_pCHwxInkWindow->UpdateRegistry(FALSE);
  301. }
  302. }
  303. }
  304. break;
  305. case IMEPN_CONFIG:
  306. if ( m_pCHwxInkWindow && !m_pCHwxInkWindow->Is16BitApp() )
  307. m_pCHwxInkWindow->HandleConfigNotification();
  308. break;
  309. case IMEPN_HELP:
  310. //----------------------------------------------------------------
  311. //980803: for FarEast merge
  312. //----------------------------------------------------------------
  313. if(m_pCHwxInkWindow) {
  314. CHwxFE::ShowHelp(m_pCHwxInkWindow->GetInkWindow());
  315. }
  316. break;
  317. case IMEPN_SIZECHANGING:
  318. if ( m_pCHwxInkWindow )
  319. {
  320. if(m_pCHwxInkWindow->HandleSizeNotify((INT *)wParam, (INT *)lParam)) {
  321. return S_OK;
  322. }
  323. else {
  324. return S_FALSE;
  325. }
  326. }
  327. break;
  328. default:
  329. break;
  330. }
  331. return S_OK;
  332. UNREFERENCED_PARAMETER(pImePad);
  333. }
  334. void CApplet::SendHwxChar(WCHAR wch)
  335. {
  336. WCHAR wstr[2];
  337. wstr[0] = wch;
  338. wstr[1] = 0;
  339. m_pPad->Request(this,IMEPADREQ_INSERTSTRING,(WPARAM)wstr,0);
  340. }
  341. void CApplet::SendHwxStringCandidate(LPIMESTRINGCANDIDATE lpISC)
  342. {
  343. if ( lpISC ) {
  344. if(m_pPad) {
  345. m_pPad->Request(this,IMEPADREQ_INSERTSTRINGCANDIDATE,(WPARAM)lpISC,0);
  346. }
  347. }
  348. }
  349. void CApplet::SendHwxStringCandidateInfo(LPIMESTRINGCANDIDATEINFO lpISC)
  350. {
  351. if ( lpISC ) {
  352. if(m_pPad) {
  353. //----------------------------------------------------------------
  354. //For Satori #2123. Don't use Ipoint1.h's definition,
  355. //instead, use IPR_DEFAULT_INSERTPOS defined in imepad.h
  356. //----------------------------------------------------------------
  357. m_pPad->Request(this,
  358. IMEPADREQ_INSERTSTRINGCANDIDATEINFO,
  359. (WPARAM)lpISC,
  360. IPR_DEFAULT_INSERTPOS); // IPINS_CURRENT);
  361. }
  362. }
  363. }
  364. void *CApplet::operator new(size_t size)
  365. {
  366. return MemAlloc(size);
  367. }
  368. void CApplet::operator delete(void *pv)
  369. {
  370. if(pv)
  371. {
  372. MemFree(pv);
  373. }
  374. }