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.

315 lines
7.8 KiB

  1. //
  2. // immxutil.h
  3. //
  4. #ifndef TFMXUTIL_H
  5. #define TFMXUTIL_H
  6. typedef struct tag_LIBTHREAD
  7. {
  8. ITfCategoryMgr *_pcat;
  9. ITfDisplayAttributeMgr *_pDAM;
  10. } LIBTHREAD;
  11. BOOL TFInitLib(void);
  12. void TFUninitLib(void);
  13. //
  14. // TFUninitThread should not be called in DllMain(THREAD_DETACH).
  15. // Because this calls COM.
  16. //
  17. void TFUninitLib_Thread(LIBTHREAD *plt);
  18. DWORD AsciiToNum( char *pszAscii);
  19. BOOL AsciiToNumDec(char *pszAscii, DWORD *pdw);
  20. DWORD WToNum( WCHAR *psz);
  21. void NumToW(DWORD dw, WCHAR *psz);
  22. void NumToA(DWORD dw, char *psz);
  23. BOOL GetTopIC(ITfDocumentMgr *pdim, ITfContext **ppic);
  24. int CompareGUIDs(REFGUID guid1, REFGUID guid2);
  25. BOOL IsDisabledTextServices(void);
  26. BOOL NoTipsInstalled(BOOL *pfOnlyTranslationRunning);
  27. BOOL RunningOnWow64();
  28. HKL GetSystemDefaultHKL();
  29. BOOL IsDisabledCUAS();
  30. void SetDisableCUAS(BOOL bDisableCUAS);
  31. void RebootTheSystem();
  32. BOOL IsAdminPrivilege();
  33. BOOL IsInteractiveUserLogon();
  34. BOOL FullPathExec( LPCSTR pszAppName, LPCSTR pszCmdLine, WORD wShowWindow, BOOL fWinDir);
  35. BOOL RunCPLSetting(LPTSTR pCmdLine);
  36. #define CR_ERROR 0xffffffff
  37. #define CR_EQUAL 0x00000000
  38. #define CR_RIGHTMEET 0x00000001
  39. #define CR_RIGHT 0x00010001
  40. #define CR_LEFTMEET 0x00000002
  41. #define CR_LEFT 0x00010002
  42. #define CR_PARTIAL 0x00000003
  43. #define CR_INCLUSION 0x00000004
  44. inline ITfContextView *GetActiveView(ITfDocumentMgr *dim)
  45. {
  46. ITfContext *pic;
  47. ITfContextView *pView = NULL;
  48. if (dim->GetTop(&pic) == S_OK)
  49. {
  50. pic->GetActiveView(&pView);
  51. pic->Release();
  52. }
  53. return pView;
  54. }
  55. BOOL IsActiveView(ITfContext *pic, ITfContextView *pView);
  56. HRESULT GetTextExtInActiveView(TfEditCookie ec, ITfRange *pRange, RECT *prc, BOOL *pfClipped);
  57. int CompareRanges(TfEditCookie ec, ITfRange *pRangeSrc, ITfRange *pRangeCmp);
  58. LONG AdjustAnchor(LONG ichAdjStart, LONG ichAdjEnd, LONG cchNew, LONG ichAnchor, BOOL fGravityRight);
  59. #ifdef __cplusplus // "C" files can't handle "inline"
  60. inline LONG CompareAnchors(IAnchor *pa1, IAnchor *pa2)
  61. {
  62. LONG l;
  63. return FAILED(pa1->Compare(pa2, &l)) ? 0 : l;
  64. }
  65. inline BOOL IsEqualAnchor(IAnchor *pa1, IAnchor *pa2)
  66. {
  67. BOOL fEqual;
  68. if (pa1->IsEqual(pa2, &fEqual) != S_OK)
  69. {
  70. Assert(0);
  71. // arbitrary: failure == not equal
  72. fEqual = FALSE;
  73. }
  74. return fEqual;
  75. }
  76. BOOL ShiftToOrClone(IAnchor **ppaDst, IAnchor *paSrc);
  77. inline HRESULT GetService(IUnknown *punkProvider, REFIID refiid, IUnknown **ppunk)
  78. {
  79. return punkProvider->QueryInterface(refiid, (void **)ppunk);
  80. }
  81. //
  82. // GetSelectionSimple
  83. //
  84. // wrapper for GetSelection that throws out all style info, and ignores disjoint selections
  85. //
  86. inline HRESULT GetSelectionSimple(TfEditCookie ec, ITfContext *pic, ITfRange **ppSel)
  87. {
  88. TF_SELECTION sel;
  89. ULONG cFetched;
  90. HRESULT hr;
  91. Assert(pic != NULL);
  92. Assert(ppSel != NULL);
  93. hr = pic->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &sel, &cFetched);
  94. Assert(hr != S_OK || sel.range != NULL);
  95. *ppSel = NULL;
  96. if (hr == S_OK && cFetched > 0)
  97. {
  98. *ppSel = sel.range; // caller must Release
  99. }
  100. return hr;
  101. }
  102. //
  103. // SetSelectionSimple
  104. //
  105. // Wrapper for SetSelection that takes only a single range and sets default style values.
  106. //
  107. inline HRESULT SetSelectionSimple(TfEditCookie ec, ITfContext *pic, ITfRange *range)
  108. {
  109. TF_SELECTION sel;
  110. sel.range = range;
  111. sel.style.ase = TF_AE_NONE;
  112. sel.style.fInterimChar = FALSE;
  113. return pic->SetSelection(ec, 1, &sel);
  114. }
  115. inline BOOL GetCurrentPos(IStream *pStream, LARGE_INTEGER *pli)
  116. {
  117. LARGE_INTEGER li;
  118. li.QuadPart = 0;
  119. return pStream->Seek(li, STREAM_SEEK_CUR, (ULARGE_INTEGER *)pli) == S_OK;
  120. }
  121. #endif // __cplusplus
  122. HRESULT GetRangeForWholeDoc(TfEditCookie ec, ITfContext *pic, ITfRange **pprange);
  123. #include "proputil.h"
  124. #define LoadSmIcon(hinst, psz) (HICON)LoadImage(hinst, psz, IMAGE_ICON, 16,16, 0)
  125. // NB: this is going away once we cleanup/separate the private/public libs
  126. typedef HRESULT (STDAPICALLTYPE * PFNCOCREATE)(REFCLSID rclsid, LPUNKNOWN punkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv);
  127. BOOL TFInitLib_PrivateForCiceroOnly(PFNCOCREATE pfnCoCreate);
  128. HMODULE GetSystemModuleHandle(LPCSTR lpModuleName);
  129. HMODULE LoadSystemLibrary(LPCSTR lpModuleName);
  130. HMODULE LoadSystemLibraryEx(LPCSTR lpModuleName, HANDLE hFile, DWORD dwFlags);
  131. HMODULE GetSystemModuleHandleW(LPCWSTR lpModuleName);
  132. HMODULE LoadSystemLibraryW(LPCWSTR lpModuleName);
  133. HMODULE LoadSystemLibraryExW(LPCWSTR lpModuleName, HANDLE hFile, DWORD dwFlags);
  134. #ifndef ARRAYSIZE
  135. #define ARRAYSIZE(x) (sizeof(x)/sizeof((x)[0]))
  136. #endif
  137. //+---------------------------------------------------------------------------
  138. //
  139. // CicSystemModulePath
  140. //
  141. //----------------------------------------------------------------------------
  142. class CicSystemModulePath
  143. {
  144. public:
  145. CicSystemModulePath()
  146. {
  147. m_szPath[0] = '\0';
  148. m_uRet = 0;
  149. }
  150. UINT Init(LPCSTR lpModuleName, BOOL fWinDir = FALSE)
  151. {
  152. if (fWinDir)
  153. m_uRet = GetSystemWindowsDirectoryA(m_szPath, ARRAYSIZE(m_szPath));
  154. else
  155. m_uRet = GetSystemDirectoryA(m_szPath, ARRAYSIZE(m_szPath));
  156. if (m_uRet >= ARRAYSIZE(m_szPath))
  157. {
  158. m_uRet = 0;
  159. m_szPath[0] = '\0';
  160. }
  161. else if (m_uRet)
  162. {
  163. if (m_szPath[m_uRet - 1] != '\\')
  164. {
  165. m_szPath[m_uRet] = '\\';
  166. m_uRet++;
  167. }
  168. UINT uLength = lstrlenA(lpModuleName);
  169. if (ARRAYSIZE(m_szPath) - m_uRet > uLength)
  170. {
  171. lstrcpynA(&m_szPath[m_uRet],
  172. lpModuleName,
  173. ARRAYSIZE(m_szPath) - m_uRet);
  174. m_uRet += uLength;
  175. }
  176. else
  177. {
  178. m_uRet = 0;
  179. m_szPath[0] = '\0';
  180. }
  181. }
  182. return m_uRet;
  183. }
  184. LPSTR GetPath()
  185. {
  186. return m_szPath;
  187. }
  188. UINT GetLength()
  189. {
  190. return m_uRet;
  191. }
  192. private:
  193. char m_szPath[MAX_PATH + 1];
  194. UINT m_uRet;
  195. };
  196. //+---------------------------------------------------------------------------
  197. //
  198. // CicSystemModulePathW
  199. //
  200. //----------------------------------------------------------------------------
  201. class CicSystemModulePathW
  202. {
  203. public:
  204. CicSystemModulePathW()
  205. {
  206. m_szPath[0] = L'\0';
  207. m_uRet = 0;
  208. }
  209. UINT Init(LPCWSTR lpModuleName, BOOL fWinDir = FALSE)
  210. {
  211. if (fWinDir)
  212. m_uRet = GetSystemWindowsDirectoryW(m_szPath, ARRAYSIZE(m_szPath));
  213. else
  214. m_uRet = GetSystemDirectoryW(m_szPath, ARRAYSIZE(m_szPath));
  215. if (m_uRet >= ARRAYSIZE(m_szPath))
  216. {
  217. m_uRet = 0;
  218. m_szPath[0] = L'\0';
  219. }
  220. else if (m_uRet)
  221. {
  222. if (m_szPath[m_uRet - 1] != L'\\')
  223. {
  224. m_szPath[m_uRet] = L'\\';
  225. m_uRet++;
  226. }
  227. UINT uLength = lstrlenW(lpModuleName);
  228. if (ARRAYSIZE(m_szPath) - m_uRet > uLength)
  229. {
  230. wcsncpy(&m_szPath[m_uRet],
  231. lpModuleName,
  232. ARRAYSIZE(m_szPath) - m_uRet);
  233. m_uRet += uLength;
  234. }
  235. else
  236. {
  237. m_uRet = 0;
  238. m_szPath[0] = L'\0';
  239. }
  240. }
  241. return m_uRet;
  242. }
  243. LPWSTR GetPath()
  244. {
  245. return m_szPath;
  246. }
  247. UINT GetLength()
  248. {
  249. return m_uRet;
  250. }
  251. private:
  252. WCHAR m_szPath[MAX_PATH + 1];
  253. UINT m_uRet;
  254. };
  255. #endif // TFMXUTIL_H