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.

478 lines
8.9 KiB

  1. /**************************************************************************\
  2. * Module Name: fnsoftkbd.cpp
  3. *
  4. * Copyright (c) 1985 - 2000, Microsoft Corporation
  5. *
  6. * Implementation of SoftKbd function object so that other TIPs can control
  7. * this SoftKbd IMX behavior.
  8. *
  9. * History:
  10. * 11-April-2000 weibz Created
  11. \**************************************************************************/
  12. #include "private.h"
  13. #include "globals.h"
  14. #include "softkbdimx.h"
  15. #include "fnsoftkbd.h"
  16. #include "funcprv.h"
  17. #include "helpers.h"
  18. //////////////////////////////////////////////////////////////////////////////
  19. //
  20. // CFnSoftKbd
  21. //
  22. //////////////////////////////////////////////////////////////////////////////
  23. //+---------------------------------------------------------------------------
  24. //
  25. // IUnknown
  26. //
  27. //----------------------------------------------------------------------------
  28. STDAPI CFnSoftKbd::QueryInterface(REFIID riid, void **ppvObj)
  29. {
  30. if ( ppvObj == NULL )
  31. return E_FAIL;
  32. *ppvObj = NULL;
  33. if (IsEqualIID(riid, IID_IUnknown) ||
  34. IsEqualIID(riid, IID_ITfFnSoftKbd))
  35. {
  36. *ppvObj = SAFECAST(this, CFnSoftKbd *);
  37. }
  38. if (*ppvObj)
  39. {
  40. AddRef();
  41. return S_OK;
  42. }
  43. return E_NOINTERFACE;
  44. }
  45. STDAPI_(ULONG) CFnSoftKbd::AddRef()
  46. {
  47. return InterlockedIncrement(&_cRef);
  48. }
  49. STDAPI_(ULONG) CFnSoftKbd::Release()
  50. {
  51. long cr;
  52. cr = InterlockedDecrement(&_cRef);
  53. Assert(cr >= 0);
  54. if (cr == 0)
  55. {
  56. delete this;
  57. }
  58. return cr;
  59. }
  60. //+---------------------------------------------------------------------------
  61. //
  62. // ctor
  63. //
  64. //----------------------------------------------------------------------------
  65. CFnSoftKbd::CFnSoftKbd(CFunctionProvider *pFuncPrv)
  66. {
  67. _pFuncPrv = pFuncPrv;
  68. _pFuncPrv->AddRef();
  69. _cRef = 1;
  70. }
  71. //+---------------------------------------------------------------------------
  72. //
  73. // dtor
  74. //
  75. //----------------------------------------------------------------------------
  76. CFnSoftKbd::~CFnSoftKbd()
  77. {
  78. SafeRelease(_pFuncPrv);
  79. }
  80. //+---------------------------------------------------------------------------
  81. //
  82. // GetDisplayName
  83. //
  84. //----------------------------------------------------------------------------
  85. STDAPI CFnSoftKbd::GetDisplayName(BSTR *pbstrName)
  86. {
  87. HRESULT hr = S_OK;
  88. if ( pbstrName == NULL )
  89. {
  90. hr = E_FAIL;
  91. return hr;
  92. }
  93. *pbstrName = SysAllocString(L"FnSoftKbd");
  94. if ( *pbstrName == NULL )
  95. {
  96. hr = E_OUTOFMEMORY;
  97. }
  98. return hr;
  99. }
  100. //+---------------------------------------------------------------------------
  101. //
  102. // IsEnabled
  103. //
  104. //----------------------------------------------------------------------------
  105. STDAPI CFnSoftKbd::IsEnabled(BOOL *pfEnable)
  106. {
  107. HRESULT hr = S_OK;
  108. if ( pfEnable == NULL )
  109. {
  110. hr = E_FAIL;
  111. return hr;
  112. }
  113. *pfEnable = TRUE;
  114. return hr;
  115. }
  116. //+---------------------------------------------------------------------------
  117. //
  118. // GetSoftKbdLayoutId
  119. //
  120. // Get the soft keyboard Id for specified type.
  121. //
  122. // Current supported types are:
  123. // SOFTKBD_TYPE_US_STANDARD
  124. // SOFTKBD_TYPE_US_SYMBOL
  125. //
  126. //----------------------------------------------------------------------------
  127. STDAPI CFnSoftKbd::GetSoftKbdLayoutId(DWORD dwLayoutType, DWORD *lpdwLayoutId)
  128. {
  129. HRESULT hr;
  130. hr = S_OK;
  131. if ( lpdwLayoutId == NULL )
  132. {
  133. hr = E_FAIL;
  134. goto CleanUp;
  135. }
  136. if ( (_pFuncPrv == NULL) || (_pFuncPrv->_pimx == NULL) )
  137. {
  138. hr = E_FAIL;
  139. goto CleanUp;
  140. }
  141. switch (dwLayoutType) {
  142. case SOFTKBD_TYPE_US_STANDARD :
  143. *lpdwLayoutId = (_pFuncPrv->_pimx->_KbdStandard).dwSoftKbdLayout;
  144. break;
  145. case SOFTKBD_TYPE_US_SYMBOL :
  146. *lpdwLayoutId = (_pFuncPrv->_pimx->_KbdSymbol).dwSoftKbdLayout;
  147. break;
  148. default :
  149. hr = E_FAIL;
  150. }
  151. CleanUp:
  152. return hr;
  153. }
  154. //+---------------------------------------------------------------------------
  155. //
  156. // SetActiveLayoutId
  157. //
  158. // Set Current Active soft keyboard layout. the layout Id is returned from
  159. // GetSoftKbdLayoutId( ).
  160. //
  161. //----------------------------------------------------------------------------
  162. STDAPI CFnSoftKbd::SetActiveLayoutId(DWORD dwLayoutId )
  163. {
  164. HRESULT hr;
  165. hr = S_OK;
  166. if ( (_pFuncPrv == NULL) || (_pFuncPrv->_pimx == NULL) )
  167. {
  168. hr = E_FAIL;
  169. goto CleanUp;
  170. }
  171. _pFuncPrv->_pimx->SetSoftKBDLayout( dwLayoutId );
  172. CleanUp:
  173. return hr;
  174. }
  175. //+---------------------------------------------------------------------------
  176. //
  177. // SetSoftKbdOnOff
  178. //
  179. // Set the current soft keyboard window show status. On or Off based on fOn
  180. //
  181. //----------------------------------------------------------------------------
  182. STDAPI CFnSoftKbd::SetSoftKbdOnOff(BOOL fOn )
  183. {
  184. HRESULT hr;
  185. hr = S_OK;
  186. if ( (_pFuncPrv == NULL) || (_pFuncPrv->_pimx == NULL) )
  187. {
  188. hr = E_FAIL;
  189. goto CleanUp;
  190. }
  191. _pFuncPrv->_pimx->SetSoftKBDOnOff( fOn );
  192. CleanUp:
  193. return hr;
  194. }
  195. //+---------------------------------------------------------------------------
  196. //
  197. // GetActiveLayoutId
  198. //
  199. // Get Current Active soft keyboard layout.
  200. //
  201. //----------------------------------------------------------------------------
  202. STDAPI CFnSoftKbd::GetActiveLayoutId(DWORD *lpdwLayoutId )
  203. {
  204. HRESULT hr;
  205. hr = S_OK;
  206. if ( lpdwLayoutId == NULL )
  207. {
  208. hr = E_FAIL;
  209. goto CleanUp;
  210. }
  211. if ( (_pFuncPrv == NULL) || (_pFuncPrv->_pimx == NULL) )
  212. {
  213. hr = E_FAIL;
  214. goto CleanUp;
  215. }
  216. *lpdwLayoutId = _pFuncPrv->_pimx->GetSoftKBDLayout( );
  217. CleanUp:
  218. return hr;
  219. }
  220. //+---------------------------------------------------------------------------
  221. //
  222. // GetSoftKbdOnOff
  223. //
  224. // Get the current soft keyboard window show status.
  225. //
  226. //----------------------------------------------------------------------------
  227. STDAPI CFnSoftKbd::GetSoftKbdOnOff(BOOL *lpfOn )
  228. {
  229. HRESULT hr;
  230. hr = S_OK;
  231. if ( lpfOn == NULL )
  232. {
  233. hr = E_FAIL;
  234. goto CleanUp;
  235. }
  236. if ( (_pFuncPrv == NULL) || (_pFuncPrv->_pimx == NULL) )
  237. {
  238. hr = E_FAIL;
  239. goto CleanUp;
  240. }
  241. *lpfOn = _pFuncPrv->_pimx->GetSoftKBDOnOff( );
  242. CleanUp:
  243. return hr;
  244. }
  245. STDAPI CFnSoftKbd::SetSoftKbdPosSize(POINT StartPoint, WORD width, WORD height)
  246. {
  247. HRESULT hr;
  248. ISoftKbd *pSoftKbd;
  249. hr = S_OK;
  250. if ( (_pFuncPrv == NULL) || (_pFuncPrv->_pimx == NULL) )
  251. {
  252. hr = E_FAIL;
  253. goto CleanUp;
  254. }
  255. if ( _pFuncPrv->_pimx->_SoftKbd == NULL )
  256. {
  257. hr = E_FAIL;
  258. goto CleanUp;
  259. }
  260. pSoftKbd = _pFuncPrv->_pimx->_SoftKbd;
  261. pSoftKbd->AddRef( );
  262. hr = pSoftKbd->SetSoftKeyboardPosSize(StartPoint, width, height );
  263. SafeRelease(pSoftKbd);
  264. CleanUp:
  265. return hr;
  266. }
  267. STDAPI CFnSoftKbd::SetSoftKbdColors(COLORTYPE colorType, COLORREF Color)
  268. {
  269. HRESULT hr;
  270. ISoftKbd *pSoftKbd;
  271. hr = S_OK;
  272. if ( (_pFuncPrv == NULL) || (_pFuncPrv->_pimx == NULL) )
  273. {
  274. hr = E_FAIL;
  275. goto CleanUp;
  276. }
  277. if ( _pFuncPrv->_pimx->_SoftKbd == NULL )
  278. {
  279. hr = E_FAIL;
  280. goto CleanUp;
  281. }
  282. pSoftKbd = _pFuncPrv->_pimx->_SoftKbd;
  283. pSoftKbd->AddRef( );
  284. hr = pSoftKbd->SetSoftKeyboardColors( colorType, Color );
  285. SafeRelease(pSoftKbd);
  286. CleanUp:
  287. return hr;
  288. }
  289. STDAPI CFnSoftKbd::GetSoftKbdPosSize(POINT *lpStartPoint,WORD *lpwidth,WORD *lpheight)
  290. {
  291. HRESULT hr;
  292. ISoftKbd *pSoftKbd;
  293. hr = S_OK;
  294. if ( (lpStartPoint==NULL) || (lpwidth == NULL) || (lpheight == NULL))
  295. {
  296. hr = E_FAIL;
  297. goto CleanUp;
  298. }
  299. if ( (_pFuncPrv == NULL) || (_pFuncPrv->_pimx == NULL) )
  300. {
  301. hr = E_FAIL;
  302. goto CleanUp;
  303. }
  304. if ( _pFuncPrv->_pimx->_SoftKbd == NULL )
  305. {
  306. hr = E_FAIL;
  307. goto CleanUp;
  308. }
  309. pSoftKbd = _pFuncPrv->_pimx->_SoftKbd;
  310. pSoftKbd->AddRef( );
  311. hr = pSoftKbd->GetSoftKeyboardPosSize(lpStartPoint, lpwidth, lpheight );
  312. SafeRelease(pSoftKbd);
  313. CleanUp:
  314. return hr;
  315. }
  316. STDAPI CFnSoftKbd::GetSoftKbdColors(COLORTYPE colorType, COLORREF *lpColor)
  317. {
  318. HRESULT hr;
  319. ISoftKbd *pSoftKbd;
  320. hr = S_OK;
  321. if ( (_pFuncPrv == NULL) || (_pFuncPrv->_pimx == NULL) )
  322. {
  323. hr = E_FAIL;
  324. goto CleanUp;
  325. }
  326. if ( _pFuncPrv->_pimx->_SoftKbd == NULL )
  327. {
  328. hr = E_FAIL;
  329. goto CleanUp;
  330. }
  331. pSoftKbd = _pFuncPrv->_pimx->_SoftKbd;
  332. pSoftKbd->AddRef( );
  333. hr = pSoftKbd->GetSoftKeyboardColors(colorType, lpColor );
  334. SafeRelease(pSoftKbd);
  335. CleanUp:
  336. return hr;
  337. }