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.

430 lines
14 KiB

  1. #ifndef pack2cpp_h__
  2. #define pack2cpp_h__
  3. #include <priv.h>
  4. #ifdef __cplusplus
  5. #undef DebugMsg
  6. #define DebugMsg TraceMsg
  7. ////////////////////////////////
  8. // Forward declarations
  9. //
  10. class CPackage_IOleObject;
  11. class CPackage_IViewObject2;
  12. class CPackage_IDataObject;
  13. class CPackage_IPersistStorage;
  14. class CPackage_IAdviseSink;
  15. class CPackage_IRunnableObject;
  16. class CPackage_IPersistFile;
  17. ////////////////////////////////
  18. // CPackage Definition
  19. //
  20. class CPackage : public IEnumOLEVERB
  21. {
  22. // CPackage interfaces
  23. friend CPackage_IOleObject;
  24. friend CPackage_IViewObject2;
  25. friend CPackage_IDataObject;
  26. friend CPackage_IPersistStorage;
  27. friend CPackage_IAdviseSink;
  28. friend CPackage_IRunnableObject;
  29. friend CPackage_IPersistFile;
  30. friend DWORD CALLBACK MainWaitOnChildThreadProc(void *); // used when we shellexec a package
  31. public:
  32. CPackage(); // constructor
  33. ~CPackage(); // destructor
  34. HRESULT Init(); // used to initialze fields that could fail
  35. BOOL RunWizard();
  36. // IUnknown methods...
  37. STDMETHODIMP QueryInterface(REFIID,void **);
  38. STDMETHODIMP_(ULONG) AddRef(void);
  39. STDMETHODIMP_(ULONG) Release(void);
  40. // IEnumOLEVERB methods...
  41. STDMETHODIMP Next(ULONG celt, OLEVERB* rgVerbs, ULONG* pceltFetched);
  42. STDMETHODIMP Skip(ULONG celt);
  43. STDMETHODIMP Reset();
  44. STDMETHODIMP Clone(IEnumOLEVERB** ppEnum);
  45. protected:
  46. UINT _cRef; // package reference count
  47. UINT _cf; // package clipboard format
  48. LPIC _lpic; // icon for the packaged object
  49. PANETYPE _panetype; // tells us whether we have a cmdlink or embed
  50. // These are mutually exclusive, so should probably be made into a union,
  51. // but that's a minor point.
  52. LPEMBED _pEmbed; // embedded file structure
  53. LPCML _pCml; // command line structure
  54. BOOL _fLoaded; // true if data from persistent storage
  55. // IOleObject vars from SetHostNames
  56. LPOLESTR _lpszContainerApp;
  57. LPOLESTR _lpszContainerObj;
  58. BOOL _fIsDirty; // dirty flag for our internal storage from the pov of our container
  59. DWORD _dwCookie; // connection value for AdviseSink
  60. // Package Storages and streams
  61. IStorage* _pIStorage; // storage used to save the package
  62. IStream* _pstm; // stream used to save package
  63. IStream* _pstmFileContents; // stream used to get file contents
  64. // CPackage Interfaces...
  65. CPackage_IPersistStorage* _pIPersistStorage;
  66. CPackage_IDataObject* _pIDataObject;
  67. CPackage_IOleObject* _pIOleObject;
  68. CPackage_IViewObject2* _pIViewObject2;
  69. CPackage_IAdviseSink* _pIAdviseSink;
  70. CPackage_IRunnableObject* _pIRunnableObject;
  71. CPackage_IPersistFile* _pIPersistFile;
  72. // Advise interfaces
  73. LPDATAADVISEHOLDER _pIDataAdviseHolder;
  74. LPOLEADVISEHOLDER _pIOleAdviseHolder;
  75. LPOLECLIENTSITE _pIOleClientSite;
  76. // Excel hack: when Excel hosts what it thinks is a link it always NULLs out
  77. // it's "object" pointer. If we call anything on IOleClientSite other than
  78. // save then it will fault.
  79. BOOL _fNoIOleClientSiteCalls;
  80. // to be able to send view change notifications we need these vars
  81. IAdviseSink *_pViewSink;
  82. DWORD _dwViewAspects;
  83. DWORD _dwViewAdvf;
  84. // IEnumOLEVERB variables:
  85. ULONG _cVerbs;
  86. ULONG _nCurVerb;
  87. OLEVERB* _pVerbs;
  88. IContextMenu* _pcm;
  89. // IEnumOLEVERB helper methods:
  90. HRESULT InitVerbEnum(OLEVERB* pVerbs, ULONG cVerbs);
  91. HRESULT GetContextMenu(IContextMenu** ppcm);
  92. VOID ReleaseContextMenu();
  93. // if fInitFile is TRUE, then we will totally initialize ourselves
  94. // from the given filename. In other words, all our structures will be
  95. // initialized after calling this is fInitFile = TRUE. On the other hand,
  96. // if it's FALSE, then we'll just reinit our data and not update icon
  97. // and filename information.
  98. //
  99. HRESULT EmbedInitFromFile(LPCTSTR lpFileName, BOOL fInitFile);
  100. HRESULT CmlInitFromFile(LPTSTR lpFilename, BOOL fUpdateIcon, PANETYPE paneType);
  101. HRESULT InitFromPackInfo(LPPACKAGER_INFO lppi);
  102. HRESULT CreateTempFile();
  103. HRESULT CreateTempFileName();
  104. HRESULT IconRefresh();
  105. void DestroyIC();
  106. // Data Transfer functions...
  107. HRESULT GetFileDescriptor(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
  108. HRESULT GetFileContents(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
  109. HRESULT GetMetafilePict(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
  110. HRESULT GetEnhMetafile(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
  111. HRESULT GetObjectDescriptor(LPFORMATETC pFE, LPSTGMEDIUM pSTM) ;
  112. HRESULT CreateShortcutOnStream(IStream* pstm);
  113. // Packager Read/Write Functions...
  114. HRESULT PackageReadFromStream(IStream* pstm);
  115. HRESULT IconReadFromStream(IStream* pstm);
  116. HRESULT EmbedReadFromStream(IStream* pstm);
  117. HRESULT CmlReadFromStream(IStream* pstm);
  118. HRESULT PackageWriteToStream(IStream* pstm);
  119. HRESULT IconWriteToStream(IStream* pstm, DWORD *pdw);
  120. HRESULT EmbedWriteToStream(IStream* pstm, DWORD *pdw);
  121. HRESULT CmlWriteToStream(IStream* pstm, DWORD *pdw);
  122. };
  123. ////////////////////////////////////////////
  124. //
  125. // CPackage_IPersistStorage Interface
  126. //
  127. class CPackage_IPersistStorage : public IPersistStorage
  128. {
  129. public:
  130. CPackage_IPersistStorage(CPackage *pPackage);
  131. ~CPackage_IPersistStorage();
  132. // IUnknown Methods...
  133. STDMETHODIMP QueryInterface(REFIID,void **);
  134. STDMETHODIMP_(ULONG) AddRef(void);
  135. STDMETHODIMP_(ULONG) Release(void);
  136. // IPersistStorage Methods...
  137. STDMETHODIMP GetClassID(LPCLSID pClassID);
  138. STDMETHODIMP IsDirty(void);
  139. STDMETHODIMP InitNew(IStorage* pstg);
  140. STDMETHODIMP Load(IStorage* pstg);
  141. STDMETHODIMP Save(IStorage* pstg, BOOL fSameAsLoad);
  142. STDMETHODIMP SaveCompleted(IStorage* pstg);
  143. STDMETHODIMP HandsOffStorage(void);
  144. protected:
  145. UINT _cRef; // interface ref count
  146. CPackage* _pPackage; // back pointer to object
  147. PSSTATE _psState; // persistent storage state
  148. };
  149. ////////////////////////////////////////////
  150. //
  151. // CPackage_IPersistFile Interface
  152. //
  153. class CPackage_IPersistFile : public IPersistFile
  154. {
  155. public:
  156. CPackage_IPersistFile(CPackage *pPackage);
  157. ~CPackage_IPersistFile();
  158. // IUnknown Methods...
  159. STDMETHODIMP QueryInterface(REFIID,void **);
  160. STDMETHODIMP_(ULONG) AddRef(void);
  161. STDMETHODIMP_(ULONG) Release(void);
  162. // IPersistStorage Methods...
  163. STDMETHODIMP GetClassID(LPCLSID pClassID);
  164. STDMETHODIMP IsDirty(void);
  165. STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwdMode);
  166. STDMETHODIMP Save(LPCOLESTR pszFileName, BOOL fRemember);
  167. STDMETHODIMP SaveCompleted(LPCOLESTR pszFileName);
  168. STDMETHODIMP GetCurFile(LPOLESTR *ppszFileName);
  169. protected:
  170. UINT _cRef; // interface ref count
  171. CPackage* _pPackage; // back pointer to object
  172. };
  173. ////////////////////////////////////////////
  174. //
  175. // CPackage_IDataObject Interface
  176. //
  177. class CPackage_IDataObject : public IDataObject
  178. {
  179. public:
  180. CPackage_IDataObject(CPackage *pPackage);
  181. ~CPackage_IDataObject();
  182. // IUnknown Methods...
  183. STDMETHODIMP QueryInterface(REFIID,void **);
  184. STDMETHODIMP_(ULONG) AddRef(void);
  185. STDMETHODIMP_(ULONG) Release(void);
  186. // IDataObject Methods...
  187. STDMETHODIMP GetData(LPFORMATETC pFEIn, LPSTGMEDIUM pSTM);
  188. STDMETHODIMP GetDataHere(LPFORMATETC pFE, LPSTGMEDIUM pSTM);
  189. STDMETHODIMP QueryGetData(LPFORMATETC pFE);
  190. STDMETHODIMP GetCanonicalFormatEtc(LPFORMATETC pFEIn, LPFORMATETC pFEOut);
  191. STDMETHODIMP SetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM, BOOL fRelease);
  192. STDMETHODIMP EnumFormatEtc(DWORD dwDirection, LPENUMFORMATETC *ppEnum);
  193. STDMETHODIMP DAdvise(LPFORMATETC pFE, DWORD grfAdv, LPADVISESINK pAdvSink,
  194. DWORD *pdwConnection);
  195. STDMETHODIMP DUnadvise(DWORD dwConnection);
  196. STDMETHODIMP EnumDAdvise(LPENUMSTATDATA *ppEnum);
  197. protected:
  198. UINT _cRef;
  199. CPackage* _pPackage;
  200. };
  201. ////////////////////////////////////////////
  202. //
  203. // CPackage_IOleObject Interface
  204. //
  205. class CPackage_IOleObject : public IOleObject
  206. {
  207. friend DWORD CALLBACK MainWaitOnChildThreadProc(void *);
  208. public:
  209. CPackage_IOleObject(CPackage *pPackage);
  210. ~CPackage_IOleObject();
  211. // IUnknown Methods...
  212. STDMETHODIMP QueryInterface(REFIID,void **);
  213. STDMETHODIMP_(ULONG) AddRef(void);
  214. STDMETHODIMP_(ULONG) Release(void);
  215. // IOleObject Methods...
  216. STDMETHODIMP SetClientSite(LPOLECLIENTSITE pClientSite);
  217. STDMETHODIMP GetClientSite(LPOLECLIENTSITE *ppClientSite);
  218. STDMETHODIMP SetHostNames(LPCOLESTR szContainerApp, LPCOLESTR szContainerObj);
  219. STDMETHODIMP Close(DWORD dwSaveOption);
  220. STDMETHODIMP SetMoniker(DWORD dwWhichMoniker, LPMONIKER pmk);
  221. STDMETHODIMP GetMoniker(DWORD dwAssign, DWORD dwWhichMonkier,LPMONIKER *ppmk);
  222. STDMETHODIMP InitFromData(LPDATAOBJECT pDataObject, BOOL fCreation,
  223. DWORD dwReserved);
  224. STDMETHODIMP GetClipboardData(DWORD dwReserved, LPDATAOBJECT *ppDataObject);
  225. STDMETHODIMP DoVerb(LONG iVerb, LPMSG lpmsg, LPOLECLIENTSITE pActiveSite,
  226. LONG lindex, HWND hwndParent, LPCRECT lprcPosRect);
  227. STDMETHODIMP EnumVerbs(LPENUMOLEVERB *ppEnumOleVerb);
  228. STDMETHODIMP Update(void);
  229. STDMETHODIMP IsUpToDate(void);
  230. STDMETHODIMP GetUserClassID(LPCLSID pClsid);
  231. STDMETHODIMP GetUserType(DWORD dwFromOfType, LPOLESTR *pszUserType);
  232. STDMETHODIMP SetExtent(DWORD dwDrawAspect, LPSIZEL psizel);
  233. STDMETHODIMP GetExtent(DWORD dwDrawAspect, LPSIZEL psizel);
  234. STDMETHODIMP Advise(LPADVISESINK pAdvSink, DWORD *pdwConnection);
  235. STDMETHODIMP Unadvise(DWORD dwConnection);
  236. STDMETHODIMP EnumAdvise(LPENUMSTATDATA *ppenumAdvise);
  237. STDMETHODIMP GetMiscStatus(DWORD dwAspect, DWORD *pdwStatus);
  238. STDMETHODIMP SetColorScheme(LPLOGPALETTE pLogpal);
  239. protected:
  240. UINT _cRef;
  241. CPackage* _pPackage;
  242. };
  243. ////////////////////////////////////////////
  244. //
  245. // CPackage_IViewObject2 Interface
  246. //
  247. class CPackage_IViewObject2 : public IViewObject2
  248. {
  249. public:
  250. CPackage_IViewObject2(CPackage *pPackage);
  251. ~CPackage_IViewObject2();
  252. // IUnknown Methods...
  253. STDMETHODIMP QueryInterface(REFIID,void **);
  254. STDMETHODIMP_(ULONG) AddRef(void);
  255. STDMETHODIMP_(ULONG) Release(void);
  256. // IViewObject2 Methods...
  257. STDMETHODIMP Draw(DWORD dwDrawAspect, LONG lindex, void *pvAspect,
  258. DVTARGETDEVICE *ptd, HDC hdcTargetDev,
  259. HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds,
  260. BOOL (CALLBACK *pfnContinue)(ULONG_PTR), ULONG_PTR dwContinue);
  261. STDMETHODIMP GetColorSet(DWORD dwAspect, LONG lindex, void *pvAspect,
  262. DVTARGETDEVICE *ptd, HDC hdcTargetDev,
  263. LPLOGPALETTE *ppColorSet);
  264. STDMETHODIMP Freeze(DWORD dwDrawAspect, LONG lindex, void * pvAspect,
  265. DWORD *pdwFreeze);
  266. STDMETHODIMP Unfreeze(DWORD dwFreeze);
  267. STDMETHODIMP SetAdvise(DWORD dwAspects, DWORD dwAdvf,
  268. LPADVISESINK pAdvSink);
  269. STDMETHODIMP GetAdvise(DWORD *pdwAspects, DWORD *pdwAdvf,
  270. LPADVISESINK *ppAdvSink);
  271. STDMETHODIMP GetExtent(DWORD dwAspect, LONG lindex, DVTARGETDEVICE *ptd,
  272. LPSIZEL pszl);
  273. protected:
  274. UINT _cRef;
  275. CPackage* _pPackage;
  276. BOOL _fFrozen;
  277. };
  278. ////////////////////////////////////////////
  279. //
  280. // CPackage_IAdviseSink Interface
  281. //
  282. class CPackage_IAdviseSink : public IAdviseSink
  283. {
  284. public:
  285. CPackage_IAdviseSink(CPackage *pPackage);
  286. ~CPackage_IAdviseSink();
  287. // IUnknown Methods...
  288. STDMETHODIMP QueryInterface(REFIID,void **);
  289. STDMETHODIMP_(ULONG) AddRef(void);
  290. STDMETHODIMP_(ULONG) Release(void);
  291. // IAdviseSink Methods...
  292. STDMETHODIMP_(void) OnDataChange(LPFORMATETC, LPSTGMEDIUM);
  293. STDMETHODIMP_(void) OnViewChange(DWORD, LONG);
  294. STDMETHODIMP_(void) OnRename(LPMONIKER);
  295. STDMETHODIMP_(void) OnSave(void);
  296. STDMETHODIMP_(void) OnClose(void);
  297. protected:
  298. UINT _cRef;
  299. CPackage* _pPackage;
  300. };
  301. ////////////////////////////////////////////
  302. //
  303. // CPackage_IRunnableObject Interface
  304. //
  305. class CPackage_IRunnableObject : public IRunnableObject
  306. {
  307. public:
  308. CPackage_IRunnableObject(CPackage *pPackage);
  309. ~CPackage_IRunnableObject();
  310. // IUnknown Methods...
  311. STDMETHODIMP QueryInterface(REFIID,void **);
  312. STDMETHODIMP_(ULONG) AddRef(void);
  313. STDMETHODIMP_(ULONG) Release(void);
  314. // IRunnable Object methods...
  315. STDMETHODIMP GetRunningClass(LPCLSID);
  316. STDMETHODIMP Run(LPBC);
  317. STDMETHODIMP_(BOOL) IsRunning();
  318. STDMETHODIMP LockRunning(BOOL,BOOL);
  319. STDMETHODIMP SetContainedObject(BOOL);
  320. protected:
  321. UINT _cRef;
  322. CPackage* _pPackage;
  323. };
  324. ////////////////////////////////////////////
  325. //
  326. // Package Wizard and Edit Package Dialog Procs and functions
  327. //
  328. // Pages for Wizard
  329. INT_PTR APIENTRY PackWiz_CreatePackageDlgProc(HWND, UINT, WPARAM, LPARAM);
  330. INT_PTR APIENTRY PackWiz_SelectFileDlgProc(HWND, UINT, WPARAM, LPARAM);
  331. INT_PTR APIENTRY PackWiz_SelectIconDlgProc(HWND, UINT, WPARAM, LPARAM);
  332. INT_PTR APIENTRY PackWiz_SelectLabelDlgProc(HWND, UINT, WPARAM, LPARAM);
  333. // Edit dialog procs
  334. INT_PTR APIENTRY PackWiz_EditEmbedPackageDlgProc(HWND, UINT, WPARAM, LPARAM);
  335. INT_PTR APIENTRY PackWiz_EditCmdPackakgeDlgProc(HWND, UINT, WPARAM, LPARAM);
  336. // functions
  337. int PackWiz_CreateWizard(HWND,LPPACKAGER_INFO);
  338. int PackWiz_EditPackage(HWND,int,LPPACKAGER_INFO);
  339. VOID PackWiz_FillInPropertyPage(PROPSHEETPAGE *, INT, DLGPROC);
  340. #endif // __cplusplus
  341. #endif