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.

411 lines
14 KiB

  1. #ifndef _UTIL_H_
  2. #define _UTIL_H_
  3. #include "mshtmdid.h"
  4. #include "shlwapi.h"
  5. #include <htmlhelp.h>
  6. #include "mshtml.h" // for IHTMLElement
  7. #ifndef UNIX
  8. #include <webcheck.h>
  9. #else
  10. #include <subsmgr.h>
  11. #endif
  12. #include "shui.h"
  13. #ifdef __cplusplus
  14. extern "C" { /* Assume C declarations for C++. */
  15. #endif /* __cplusplus */
  16. extern HICON g_hiconSplat;
  17. extern HICON g_hiconSplatSm;
  18. void LoadCommonIcons(void);
  19. BOOL ViewIDFromViewMode(UINT uViewMode, SHELLVIEWID *pvid);
  20. void SaveDefaultFolderSettings();
  21. HRESULT DropOnMailRecipient(IDataObject *pdtobj, DWORD grfKeyState);
  22. HRESULT SendDocToMailRecipient(LPCITEMIDLIST pidl, UINT uiCodePage, DWORD grfKeyState);
  23. //
  24. // Automation support.
  25. //
  26. HRESULT CDDEAuto_Navigate(BSTR str, HWND *phwnd, long lLaunchNewWindow);
  27. HRESULT CDDEAuto_get_LocationURL(BSTR * pstr, HWND hwnd);
  28. HRESULT CDDEAuto_get_LocationTitle(BSTR * pstr, HWND hwnd);
  29. HRESULT CDDEAuto_get_HWND(long * phwnd);
  30. HRESULT CDDEAuto_Exit(void);
  31. BOOL _InitComCtl32();
  32. //
  33. // Menu utility functions
  34. //
  35. void Menu_Replace(HMENU hmenuDst, HMENU hmenuSrc);
  36. #define LoadMenuPopup(id) SHLoadMenuPopup(MLGetHinst(), id)
  37. void Menu_AppendMenu(HMENU hmenuDst, HMENU hmenuSrc);
  38. TCHAR StripMneumonic(LPTSTR szMenu);
  39. DWORD CommonDragEnter(IDataObject *pdtobj, DWORD grfKeyState, POINTL pt);
  40. int PropBag_ReadInt4(IPropertyBag* pPropBag, LPWSTR pszKey, int iDefault);
  41. DWORD SHRandom(void);
  42. STDAPI_(BOOL) UrlIsInCache(LPCTSTR pszURL);
  43. STDAPI_(BOOL) UrlIsMappedOrInCache(LPCTSTR pszURL);
  44. #ifdef UNICODE
  45. #define IsSubscribable IsSubscribableW
  46. #endif // UNICODE
  47. BOOL IsFileUrl(LPCSTR psz);
  48. BOOL IsFileUrlW(LPCWSTR pcwzUrl);
  49. BOOL IsEmptyStream(IStream* pstm);
  50. BOOL IsInternetExplorerApp();
  51. BOOL IsTopFrameBrowser(IServiceProvider *psp, IUnknown *punk);
  52. BOOL IsSubscribableW(LPCWSTR psz);
  53. #define GEN_DEBUGSTRW(str) ((str) ? (str) : L"<Null Str>")
  54. #define GEN_DEBUGSTRA(str) ((str) ? (str) : "<Null Str>")
  55. #ifdef UNICODE
  56. #define GEN_DEBUGSTR GEN_DEBUGSTRW
  57. #else // UNICODE
  58. #define GEN_DEBUGSTR GEN_DEBUGSTRA
  59. #endif // UNICODE
  60. HRESULT URLSubRegQueryA(LPCSTR pszKey, LPCSTR pszValue, BOOL fUseHKCU,
  61. LPSTR pszUrlOut, DWORD cchSize, DWORD dwSubstitutions);
  62. HRESULT URLSubRegQueryW(LPCWSTR pszKey, LPCWSTR pszValue, BOOL fUseHKCU,
  63. LPWSTR pszUrlOut, DWORD cchSize, DWORD dwSubstitutions);
  64. #ifdef UNICODE
  65. #define URLSubRegQuery URLSubRegQueryW
  66. #else
  67. #define URLSubRegQuery URLSubRegQueryA
  68. #endif
  69. #define FillExecInfo(_info, _hwnd, _verb, _file, _params, _dir, _show) \
  70. (_info).hwnd = _hwnd; \
  71. (_info).lpVerb = _verb; \
  72. (_info).lpFile = _file; \
  73. (_info).lpParameters = _params; \
  74. (_info).lpDirectory = _dir; \
  75. (_info).nShow = _show; \
  76. (_info).fMask = 0; \
  77. (_info).cbSize = sizeof(SHELLEXECUTEINFO);
  78. void _DeletePidlDPA(HDPA hdpa);
  79. STDAPI_(BOOL) GetShortcutFileName(LPCTSTR pszTarget, LPCTSTR pszTitle, LPCTSTR pszDir, LPTSTR pszOut, int cchOut);
  80. //-----------------------------------------------------------------------------
  81. #define PropagateMessage SHPropagateMessage
  82. //-----------------------------------------------------------------------------
  83. BOOL PrepareURLForExternalApp(LPCWSTR psz, LPWSTR pszOut, LPDWORD pcchOut);
  84. #define PrepareURLForDisplayUTF8 PrepareURLForDisplayUTF8W
  85. #define PrepareURLForDisplay PrepareURLForDisplayW
  86. STDAPI_(BOOL) PrepareURLForDisplayW(LPCWSTR pwz, LPWSTR pwzOut, LPDWORD pcbOut);
  87. HRESULT PrepareURLForDisplayUTF8W(LPCWSTR pwz, LPWSTR pwzOut, LPDWORD pcbOut, BOOL fUTF8Enabled);
  88. BOOL ParseURLFromOutsideSourceA (LPCSTR psz, LPSTR pszOut, LPDWORD pcchOut, LPBOOL pbWasSearchURL);
  89. BOOL ParseURLFromOutsideSourceW (LPCWSTR psz, LPWSTR pszOut, LPDWORD pcchOut, LPBOOL pbWasSearchURL);
  90. BOOL ParseURLFromOutsideSourceWithContextW (LPCWSTR psz, LPWSTR pszOut, LPDWORD pcchOut, LPBOOL pbWasSearchURL, ISearchContext * pSC);
  91. BOOL UTF8Enabled();
  92. HRESULT FormatUrlForDisplay(LPWSTR pszURL, LPWSTR pszFriendly, UINT cbBuf, LPWSTR pszFrom, UINT cbFrom, BOOL fSeperate, DWORD dwCodePage, PWSTR pwzCachedFileName);
  93. BOOL __cdecl _FormatMessage(LPCWSTR szTemplate, LPWSTR szBuf, UINT cchBuf, ...);
  94. EXECUTION_STATE _SetThreadExecutionState(EXECUTION_STATE esFlags);
  95. //=--------------------------------------------------------------------------=
  96. // string helpers.
  97. //
  98. STDAPI_(BSTR) SysAllocStringA(LPCSTR pszAnsiStr);
  99. STDAPI_(BSTR) LoadBSTR(UINT uID);
  100. #ifdef UNICODE
  101. #define SysAllocStringT(psz) SysAllocString(psz)
  102. #else
  103. #define SysAllocStringT(psz) SysAllocStringA(psz)
  104. #endif
  105. // FEATURE:: Need to handle two different implementations of SHChangeRegister...
  106. typedef ULONG (* PFNSHCHANGENOTIFYREGISTER)(HWND hwnd, int fSources, LONG fEvents, UINT wMsg, int cEntries, SHChangeNotifyEntry *pshcne);
  107. typedef BOOL (* PFNSHCHANGENOTIFYDEREGISTER)(unsigned long ulID);
  108. extern PFNSHCHANGENOTIFYREGISTER g_pfnSHChangeNotifyRegister;
  109. extern PFNSHCHANGENOTIFYDEREGISTER g_pfnSHChangeNotifyDeregister;
  110. extern BOOL g_fNewNotify;
  111. #define SZ_BINDCTXKEY_SITE L"Site"
  112. #define MAX_PAGES 16 // limit on the number of pages we can have
  113. BOOL CALLBACK AddPropSheetPage(HPROPSHEETPAGE hpage, LPARAM lParam);
  114. ULONG RegisterNotify(HWND hwnd, UINT nMsg, LPCITEMIDLIST pidl, DWORD dwEvents, UINT uFlags, BOOL fRecursive);
  115. void Cabinet_FlagsToParams(UINT uFlags, LPTSTR pszParams);
  116. HRESULT BindToAncesterFolder(LPCITEMIDLIST pidlAncester, LPCITEMIDLIST pidl, IShellFolder** ppsfParent, LPCITEMIDLIST *ppidlChild);
  117. // logical defines for grfKeyState bits
  118. #define FORCE_COPY (MK_LBUTTON | MK_CONTROL) // means copy
  119. #define FORCE_LINK (MK_LBUTTON | MK_CONTROL | MK_SHIFT) // means link
  120. HRESULT IsChildOrSelf(HWND hwndParent, HWND hwnd);
  121. extern HIMAGELIST g_himlSysSmall;
  122. extern HIMAGELIST g_himlSysLarge;
  123. void _InitSysImageLists();
  124. extern const VARIANT c_vaEmpty;
  125. //
  126. // FEATURE: Remove this ugly const to non-const casting if we can
  127. // figure out how to put const in IDL files.
  128. //
  129. #define PVAREMPTY ((VARIANT*)&c_vaEmpty)
  130. extern UINT g_cfURL;
  131. extern UINT g_cfURLW;
  132. extern UINT g_cfHIDA;
  133. extern UINT g_cfFileDescA;
  134. extern UINT g_cfFileDescW;
  135. extern UINT g_cfFileContents;
  136. #ifdef UNICODE
  137. #define g_cfFileDesc g_cfFileDescW
  138. #else
  139. #define g_cfFileDesc g_cfFileDescA
  140. #endif
  141. void InitClipboardFormats();
  142. void* DataObj_GetDataOfType(IDataObject* pdtobj, UINT cfType, STGMEDIUM *pstg);
  143. LONG OpenRegUSKey(LPCTSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult); // dllreg.cpp
  144. //-------------------------------------------------------------------------
  145. extern int g_cxEdge;
  146. extern int g_cyEdge;
  147. extern int g_cxIcon;
  148. extern int g_cyIcon;
  149. extern int g_cxSmIcon;
  150. extern int g_cySmIcon;
  151. enum TRI_STATE
  152. {
  153. TRI_UNKNOWN = 2,
  154. TRI_TRUE = TRUE,
  155. TRI_FALSE = FALSE
  156. };
  157. BOOL IsSameObject(IUnknown* punk1, IUnknown* punk2);
  158. #define TrimWhiteSpaceW(psz) StrTrimW(psz, L" \t")
  159. #define TrimWhiteSpaceA(psz) StrTrimA(psz, " \t")
  160. #ifdef UNICODE
  161. #define TrimWhiteSpace TrimWhiteSpaceW
  162. #else
  163. #define TrimWhiteSpace TrimWhiteSpaceA
  164. #endif
  165. LPCTSTR SkipLeadingSlashes(LPCTSTR pszURL);
  166. extern const LARGE_INTEGER c_li0;
  167. extern const DISPPARAMS c_dispparamsNoArgs;
  168. #ifndef UNIX
  169. #define g_dispparamsNoArgs ((DISPPARAMS)c_dispparamsNoArgs) // prototype was incorrect!
  170. #else
  171. #define g_dispparamsNoArgs c_dispparamsNoArgs // prototype was incorrect!
  172. #endif
  173. BOOL IsEmptyStream(IStream* pstm);
  174. void SetParentHwnd(HWND hwnd, HWND hwndParent);
  175. #ifndef UNICODE
  176. #define ADJUST_TO_WCHAR_POS 0
  177. #define ADJUST_TO_TCHAR_POS 1
  178. int AdjustECPosition(char *psz, int iPos, int iType);
  179. HRESULT MapNbspToSp(LPCWSTR lpwszIn, LPTSTR lpszOut, int cbszOut);
  180. HRESULT GetDisplayableTitle(LPTSTR psz, LPCWSTR wszTitle, int cch);
  181. #endif
  182. LPITEMIDLIST GetTravelLogPidl(IBrowserService * pbs);
  183. BOOL ILIsWeb(LPCITEMIDLIST pidl);
  184. #define AnsiToUnicode(pstr, pwstr, cch) SHAnsiToUnicode(pstr, pwstr, cch)
  185. #define UnicodeToAnsi(pwstr, pstr, cch) SHUnicodeToAnsi(pwstr, pstr, cch)
  186. #define UnicodeToTChar(pwstr, pstr, cch) SHUnicodeToTChar(pwstr, pstr, cch)
  187. #define AnsiToTChar(pstr, ptstr, cch) SHAnsiToTChar(pstr, ptstr, cch)
  188. #define TCharToAnsi(ptstr, pstr, cch) SHTCharToAnsi(ptstr, pstr, cch)
  189. //Function for doing drag and drop given a pidl
  190. HRESULT DragDrop(HWND hwnd, IShellFolder* psfParent, LPCITEMIDLIST pidl, DWORD dwPrefEffect, DWORD* pdwEffect);
  191. HRESULT _SetPreferredDropEffect(IDataObject *pdtobj, DWORD dwEffect);
  192. //Function for getting icon index corresponding to htm files
  193. int _GetIEHTMLImageIndex();
  194. int _GetHTMLImageIndex();
  195. int IEMapPIDLToSystemImageListIndex(IShellFolder *psfParent, LPCITEMIDLIST pidlChild, int * piSelectedImage);
  196. void IEInvalidateImageList(void);
  197. extern UINT g_cfURL;
  198. extern UINT g_cfURLW;
  199. extern UINT g_cfFileDescA;
  200. extern UINT g_cfFileContents;
  201. extern UINT g_cfPreferredEffect;
  202. extern UINT g_cfPerformedEffect;
  203. extern UINT g_cfTargetCLSID;
  204. #ifdef UNICODE
  205. #define g_cfFileDesc g_cfFileDescW
  206. #else
  207. #define g_cfFileDesc g_cfFileDescA
  208. #endif
  209. void InitClipboardFormats();
  210. BOOL IsExpandableFolder(IShellFolder* psf, LPCITEMIDLIST pidl);
  211. extern BOOL IsGlobalOffline(void);
  212. extern void SetGlobalOffline(BOOL fOffline);
  213. BOOL GetHistoryFolderPath(LPTSTR pszPath, int cchPath);
  214. IStream * OpenPidlOrderStream(LPCITEMIDLIST pidlRoot
  215. , LPCITEMIDLIST pidl
  216. , LPCSTR pszKey
  217. , DWORD grfMode);
  218. int SearchMapInt(const int *src, const int *dst, int cnt, int val);
  219. STDAPI_(LPITEMIDLIST) IEILCreate(UINT cbSize);
  220. // this is for the file menus recently visited list.
  221. // it represents the count of entries both back and forward
  222. // that should be on the menu.
  223. #define CRECENTMENU_MAXEACH 5
  224. BOOL VerbExists(LPCTSTR pszExtension, LPCTSTR pszVerb, LPTSTR pszCommand);
  225. HRESULT CreateLinkToPidl(LPCITEMIDLIST pidlTo, LPCTSTR pszDir, LPCTSTR pszTitle, LPTSTR pszOut, int cchOut);
  226. // the shell32 implementation of ILClone is different for win95 an ie4.
  227. // it doesnt check for NULL in the old version, but it does in the new...
  228. // so we need to redefine it to always check
  229. STDAPI_(LPITEMIDLIST) SafeILClone(LPCITEMIDLIST pidl);
  230. #define ILClone SafeILClone
  231. STDAPI CActiveDesktop_InternalCreateInstance(LPUNKNOWN * ppunk, REFIID riid);
  232. BOOL ExecItemFromFolder(HWND hwnd, LPCSTR pszVerb, IShellFolder* psf, LPCITEMIDLIST pidlItem);
  233. HRESULT NavToUrlUsingIEA(LPCSTR szUrl, BOOL fNewWindow);
  234. HRESULT NavToUrlUsingIEW(LPCWSTR wszUrl, BOOL fNewWindow);
  235. #ifdef UNICODE
  236. #define NavToUrlUsingIE NavToUrlUsingIEW
  237. #else // UNICODE
  238. #define NavToUrlUsingIE NavToUrlUsingIEA
  239. #endif // UNICODE
  240. DWORD WaitForSendMessageThread(HANDLE hThread, DWORD dwTimeout);
  241. BOOL CreateNewFolder(HWND hwndOwner, LPCITEMIDLIST pidlParent, LPTSTR szPathNew, int nSize);
  242. #ifdef __cplusplus
  243. } /* End of extern "C" {. */
  244. #endif /* __cplusplus */
  245. STDAPI GetHTMLDoc2(IUnknown *punk, IHTMLDocument2 **ppHtmlDoc);
  246. STDAPI_(IBindCtx *) CreateBindCtxForUI(IUnknown * punkSite);
  247. void GetWebLocaleAsRFC1766(LPTSTR pszLocale, int cchLocale);
  248. BOOL IsExplorerWindow(HWND hwnd);
  249. BOOL IsFolderWindow(HWND hwnd);
  250. BOOL FindBrowserWindow(void);
  251. BOOL IsVK_TABCycler(MSG * pMsg);
  252. // Review chrisny: this can be moved into an object easily to handle generic droptarget, dropcursor
  253. // , autoscrool, etc. . .
  254. void _DragEnter(HWND hwndTarget, const POINTL ptStart, IDataObject *pdtObject);
  255. void _DragMove(HWND hwndTarget, const POINTL ptStart);
  256. BOOL IsFeaturePotentiallyAvailable(REFCLSID rclsid);
  257. STDAPI_(UINT) GetWheelMsg();
  258. STDAPI GetCacheLocation(LPTSTR pszCacheLocation, DWORD cchCacheLocation);
  259. STDAPI StringToStrRet(LPCTSTR pString, STRRET *pstrret);
  260. STDAPI_(HCURSOR) LoadHandCursor(DWORD dwRes);
  261. HRESULT GetNavTargetName(IShellFolder* psf, LPCITEMIDLIST pidl, LPTSTR pszUrl, UINT cMaxChars);
  262. STDAPI GetLinkInfo(IShellFolder* psf, LPCITEMIDLIST pidlItem, BOOL* pfAvailable, BOOL* pfSticky);
  263. void FixAmpersands(LPWSTR pszToFix, UINT cchMax);
  264. BOOL IsInetcplRestricted(LPCWSTR pszCommand);
  265. BOOL IsNamedWindow(HWND hwnd, LPCTSTR pszClass);
  266. BOOL HasExtendedChar(LPCWSTR pszQuery);
  267. void ConvertToUtf8Escaped(LPWSTR pszQuery, int cch);
  268. HRESULT SHPathPrepareForWriteWrap(HWND hwnd, IUnknown *punkEnableModless, LPCTSTR pszPath, UINT wFunc, DWORD dwFlags);
  269. BOOL SHIsRestricted2W(HWND hwnd, BROWSER_RESTRICTIONS rest, LPCWSTR pwzUrl, DWORD dwReserved);
  270. HRESULT IExtractIcon_GetIconLocation(
  271. IUnknown *punk,
  272. IN UINT uInFlags,
  273. OUT LPTSTR pszIconFile,
  274. IN UINT cchIconFile,
  275. OUT PINT pniIcon,
  276. OUT PUINT puOutFlags);
  277. HRESULT IExtractIcon_Extract(
  278. IUnknown *punk,
  279. IN LPCTSTR pszIconFile,
  280. IN UINT iIcon,
  281. OUT HICON * phiconLarge,
  282. OUT HICON * phiconSmall,
  283. IN UINT ucIconSize);
  284. // Takes in lpszPath and returns the other form (SFN or LFN).
  285. void GetPathOtherFormA(LPSTR lpszPath, LPSTR lpszNewPath, DWORD dwSize);
  286. STDAPI CoAllowSetForegroundWindow(IUnknown *punk, void *pvReserved); // in > v5 headers
  287. HRESULT GetSearchStyle(IServiceProvider * psp, LPDWORD pdwSearchStyle);
  288. BOOL AccessAllowed(
  289. IUnknown* punkSite,
  290. LPCWSTR pwszURL1,
  291. LPCWSTR pwszURL2);
  292. BOOL IsFrameWindow(IHTMLWindow2 * pHTMLWindow);
  293. STDAPI SHGetFolderPathD(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath);
  294. STDAPI_(BOOL) IsCSIDLFolder(UINT csidl, LPCITEMIDLIST pidl);
  295. #endif // _UTIL_H_