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.

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