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.

238 lines
7.8 KiB

  1. //=================================================
  2. //
  3. // File : httpwfh.h
  4. //
  5. // purpose : definition of the Cwfolders class
  6. //
  7. //=================================================
  8. // Chad Lindhorst, 1998
  9. #ifndef __HTTPWFH_H_
  10. #define __HTTPWFH_H_
  11. #include <mshtmhst.h>
  12. #include "iextag.h" // for IID_Iwfolders... etc.
  13. #include "resource.h" // main symbols
  14. #include "oledb.h"
  15. // This is used to fix the max size for strings loaded from the
  16. // string table.
  17. #define MAX_LOADSTRING MAX_PATH
  18. // This is the longest URL we should send to office. (anything longer
  19. // will get an error dialog.) (Should be MAX_PATH - talk to office...)
  20. #define MAX_WEB_FOLDER_LENGTH 100
  21. // This is the guid we use for active setup....
  22. static const GUID CLSID_IOD =
  23. { 0x73fa19d0, 0x2d75, 0x11d2, { 0x99, 0x5d, 0x00, 0xc0, 0x4f, 0x98, 0xbb, 0xc9 } };
  24. // Just to look nice.
  25. #define BAILOUT(HR) {hr=HR; goto cleanup;}
  26. #define FAILONBAD_HR(HR) {if (FAILED(HR)) BAILOUT(HR);}
  27. // These typedefs and statics are for the target frame creation code taken
  28. // out of shdocvw.
  29. typedef enum _TARGET_TYPE {
  30. TARGET_FRAMENAME,
  31. TARGET_SELF,
  32. TARGET_PARENT,
  33. TARGET_BLANK,
  34. TARGET_TOP,
  35. TARGET_MAIN,
  36. TARGET_SEARCH
  37. } TARGET_TYPE;
  38. typedef struct _TARGETENTRY {
  39. TARGET_TYPE targetType;
  40. const WCHAR *pTargetValue;
  41. } TARGETENTRY;
  42. static const TARGETENTRY targetTable[] =
  43. {
  44. {TARGET_SELF, L"_self"},
  45. {TARGET_PARENT, L"_parent"},
  46. {TARGET_BLANK, L"_blank"},
  47. {TARGET_TOP, L"_top"},
  48. {TARGET_MAIN, L"_main"},
  49. {TARGET_SEARCH, L"_search"},
  50. {TARGET_SELF, NULL}
  51. };
  52. // Custom Window Messages
  53. #define WM_WEBFOLDER_NAV WM_USER + 2000
  54. #define WM_WEBFOLDER_CANCEL WM_WEBFOLDER_NAV + 1
  55. #define WM_WEBFOLDER_DONE WM_WEBFOLDER_NAV + 2
  56. #define WM_WEBFOLDER_INIT WM_WEBFOLDER_NAV + 3
  57. // Used to keep the state of the message window. They are void * to cram into
  58. // the window properties.
  59. #define STATUS_READY (void *) 1
  60. #define STATUS_CANCELED (void *) 2
  61. // Window Property Names
  62. #define __INFO L"__WFOLDER_INFO"
  63. #define __CANCEL L"__WFOLDER_CANCEL"
  64. // Name of the class of windows that handles all the messages from ParseDisplayName
  65. #define WFOLDERSWNDCLASS L"WebFolderSilentMessageHandlerWindowClass"
  66. // These values help the various parts of this program know what is going on.
  67. // They are to be used in ONE DIRECTION ONLY because they are often carried
  68. // to different threads, and the variable they are used with is NOT
  69. // synchronized.
  70. #define READY_WORKING 0
  71. #define READY_INITIALIZED 1
  72. #define READY_CANCEL 10
  73. #define READY_DONE 11
  74. // These are my different UI codes. You pass one (or all) of these to NavigateInternal
  75. // to change what UI gets seen.
  76. #define USE_NO_UI 0
  77. #define USE_ERROR_BOXES 1
  78. #define USE_FAILED_QUESTION 2
  79. #define USE_WEB_PAGE_UI 4
  80. #define USE_ALL_UI USE_ERROR_BOXES | USE_FAILED_QUESTION | USE_WEB_PAGE_UI
  81. //+------------------------------------------------------------------------
  82. //
  83. // Class: Cwfolders
  84. //
  85. // Synopsis: Implements a behavior which allows the browser to
  86. // navigate to a folder view of a given URL. The most
  87. // important method here is Navigate.
  88. //
  89. //-------------------------------------------------------------------------
  90. class ATL_NO_VTABLE Cwfolders :
  91. public CComObjectRootEx<CComSingleThreadModel>,
  92. public CComCoClass<Cwfolders,&CLSID_wfolders>,
  93. public IDispatchImpl<Iwfolders, &IID_Iwfolders, &LIBID_IEXTagLib>,
  94. public IObjectSafetyImpl<Cwfolders>,
  95. public IElementBehavior
  96. {
  97. // METHODS
  98. // -------
  99. public:
  100. Cwfolders();
  101. ~Cwfolders();
  102. DECLARE_REGISTRY_RESOURCEID(IDR_WFOLDERS)
  103. BEGIN_COM_MAP(Cwfolders)
  104. COM_INTERFACE_ENTRY(IDispatch)
  105. COM_INTERFACE_ENTRY(Iwfolders)
  106. COM_INTERFACE_ENTRY(IElementBehavior)
  107. COM_INTERFACE_ENTRY_IMPL(IObjectSafety)
  108. END_COM_MAP()
  109. // Iwfolders
  110. STDMETHOD(navigate)(BSTR bstrUrl, BSTR * pbstrRetVal);
  111. STDMETHOD(navigateFrame)(BSTR bstrUrl, BSTR bstrTargetFrame, /*BSTR bstrProtocol,*/ BSTR * pbstrRetVal);
  112. STDMETHOD(navigateNoSite)(BSTR bstrUrl, BSTR bstrTargetFrame, /*BSTR bstrProtocol,*/
  113. DWORD dwhwnd, IUnknown* punk);
  114. // IObjectSafety
  115. STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid,
  116. DWORD dwSupportedOptions, DWORD dwEnabledOptions);
  117. // IElementBehavior
  118. HRESULT STDMETHODCALLTYPE Init (IElementBehaviorSite __RPC_FAR *pBehaviorSite);
  119. HRESULT STDMETHODCALLTYPE Notify (LONG lEvent, VARIANT __RPC_FAR *pVar);
  120. STDMETHOD(Detach)() { return S_OK; };
  121. private:
  122. // The function that actually does all the navigation.
  123. // all other (including exported) functions call this one.
  124. STDMETHOD(navigateInternal)(BSTR bstrUrl, BSTR bstrTargetFrame, /*BSTR bstrProtocol,*/ int iUI, IUnknown* punk);
  125. // show UI for four different kinds of errors.
  126. void ShowNavigationFailedQuestion (BSTR bstrUrl, BSTR bstrTargetFrame);
  127. void ShowError (HWND hWnd, unsigned int IDSmessage, unsigned int IDStitle, BSTR bstrUrl);
  128. void ShowNavigationFailed (HWND hWnd, BSTR bstrUrl, BSTR bstrTargetFrame,
  129. WCHAR * wszResource);
  130. // STATIC METHODS
  131. // --------------
  132. public:
  133. // message handler for my window (the "connecting..." dialog)
  134. static INT_PTR CALLBACK WaitDlgProc (HWND hDlg, UINT message,
  135. WPARAM wParam, LPARAM lParam);
  136. // message handler for a silent, invisible message window that
  137. // stays around to listen for ParseDisplayName to finish
  138. static INT_PTR CALLBACK NavMessageProc (HWND hDlg, UINT message, WPARAM wParam,
  139. LPARAM lParam);
  140. private:
  141. // These two (unexported) functions were taken from the shdocvw code.
  142. static TARGET_TYPE ParseTargetType(LPCOLESTR pszTarget);
  143. static HRESULT CreateTargetFrame(LPCOLESTR pszTargetName, LPUNKNOWN *ppunk);
  144. // Some helper functions for pidl stuffing
  145. static HRESULT InitVARIANTFromPidl(LPVARIANT pvar, LPITEMIDLIST pidl);
  146. static LPSAFEARRAY MakeSafeArrayFromData(LPBYTE pData, DWORD cbData);
  147. static UINT ILGetSize(LPITEMIDLIST pidl);
  148. // My thread proc
  149. static DWORD WINAPI RunParseDisplayName (LPVOID pArguments);
  150. // General helper functions (destined for utils.cxx?)
  151. static HRESULT NavToPidl (LPITEMIDLIST pidl, BSTR bstrTargetFrame,
  152. IWebBrowser2 * pwb);
  153. // Some code mostly supplied by Chris Guzak that gets a pidl from
  154. // an url.
  155. static HRESULT CreateWebFolderIDList(BSTR bstrUrl, LPITEMIDLIST *ppidl, HWND hwnd, IUnknown *punk);
  156. static void SetScriptErrorMessage (HRESULT hr, BSTR * pbstr);
  157. // DATA MEMBERS
  158. // ------------
  159. public:
  160. IWebBrowser2 * m_pwb;
  161. HWND m_hwndOwner;
  162. IElementBehaviorSite *m_pSite;
  163. };
  164. // Using this to pass arguments to my child thread.
  165. class CThreadArgs
  166. {
  167. public:
  168. CThreadArgs()
  169. {
  170. m_bstrUrl = NULL;
  171. }
  172. ~CThreadArgs()
  173. {
  174. SysFreeString (m_bstrUrl);
  175. }
  176. // holds the URL ask office for a pidl with
  177. BSTR m_bstrUrl;
  178. // holds the hwnd of the message window, once
  179. // it is created and initialized. (0 otherwise)
  180. HWND m_hwndMessage;
  181. // holds the hwnd of the dialog window, once
  182. // it is created and initialized. (0 otherwise)
  183. HWND m_hwndDialog;
  184. // holds the HRESULT returned by office
  185. HRESULT m_hrReady;
  186. // holds the pidl returned by office
  187. // (this actually only carries the pidl between the
  188. // message window and the navigateInternal call...
  189. // the pidl gets from the PDN thread to the message
  190. // window through the WM_WEBFOLDER_NAV message)
  191. LPITEMIDLIST m_pidl;
  192. // Holds the status of the message window
  193. int m_imsgStatus;
  194. // Holds the status of the PDN thread
  195. int m_ipdnStatus;
  196. };
  197. #endif //__HTTPWFH_H_