Source code of Windows XP (NT5)
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.

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