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.

391 lines
16 KiB

  1. #ifndef __FLDRICON_H_
  2. #define __FLDRICON_H_
  3. #include <evtsink.h>
  4. #include <shellp.h>
  5. #include <windef.h>
  6. #include <webvwid.h>
  7. #include <color.h>
  8. #include <cnctnpt.h>
  9. EXTERN_C const CLSID CLSID_WebViewFolderIconOld; // retired from service
  10. #define ID_FIRST 0 // Context Menu ID's
  11. #define ID_LAST 0x7fff
  12. #define MAX_SCALE_STR 10
  13. #define MAX_VIEW_STR 50
  14. #define LARGE_ICON_DEFAULT 32
  15. #define THUMBVIEW_DEFAULT 120
  16. #define PIEVIEW_DEFAULT THUMBVIEW_DEFAULT
  17. #define SLICE_NUM_GROW 2
  18. #define SZ_LARGE_ICON L"Large Icon"
  19. #define SZ_SMALL_ICON L"Small Icon"
  20. #define SZ_SMALL_ICON_LABEL L"Small Icon with Label"
  21. #define SZ_LARGE_ICON_LABEL L"Large Icon with Label"
  22. #define SZ_THUMB_VIEW L"Thumbview"
  23. #define SZ_PIE_VIEW L"Pie Graph"
  24. struct PieSlice_S {
  25. ULONGLONG MemSize;
  26. COLORREF Color;
  27. };
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CWebViewFolderIcon
  30. class ATL_NO_VTABLE CWebViewFolderIcon :
  31. public CComObjectRootEx<CComSingleThreadModel>,
  32. public CComCoClass<CWebViewFolderIcon, &CLSID_WebViewFolderIcon>,
  33. public CComControl<CWebViewFolderIcon>,
  34. public IDispatchImpl<IWebViewFolderIcon3, &IID_IWebViewFolderIcon3, &LIBID_WEBVWLib>,
  35. public IObjectSafetyImpl<CWebViewFolderIcon, INTERFACESAFE_FOR_UNTRUSTED_CALLER>,
  36. public IQuickActivateImpl<CWebViewFolderIcon>,
  37. public IOleControlImpl<CWebViewFolderIcon>,
  38. public IOleObjectImpl<CWebViewFolderIcon>,
  39. public IOleInPlaceActiveObjectImpl<CWebViewFolderIcon>,
  40. public IViewObjectExImpl<CWebViewFolderIcon>,
  41. public IOleInPlaceObjectWindowlessImpl<CWebViewFolderIcon>,
  42. public IPersistPropertyBagImpl<CWebViewFolderIcon>,
  43. public IPointerInactiveImpl<CWebViewFolderIcon>,
  44. public IConnectionPointImpl<CWebViewFolderIcon, &DIID_DWebViewFolderIconEvents>,
  45. public IConnectionPointContainerImpl<CWebViewFolderIcon>,
  46. public IProvideClassInfo2Impl<&CLSID_WebViewFolderIcon,
  47. &DIID_DWebViewFolderIconEvents, &LIBID_WEBVWLib>
  48. {
  49. public:
  50. // Drawing function
  51. HRESULT OnDraw(ATL_DRAWINFO& di);
  52. DECLARE_REGISTRY_RESOURCEID(IDR_WEBVIEWFOLDERICON)
  53. BEGIN_COM_MAP(CWebViewFolderIcon)
  54. COM_INTERFACE_ENTRY(IWebViewFolderIcon3)
  55. COM_INTERFACE_ENTRY_IID(IID_IWebViewFolderIcon, IWebViewFolderIcon3)
  56. COM_INTERFACE_ENTRY_IID(IID_IWebViewFolderIcon2, IWebViewFolderIcon3)
  57. COM_INTERFACE_ENTRY(IDispatch)
  58. COM_INTERFACE_ENTRY(IOleInPlaceObject)
  59. COM_INTERFACE_ENTRY(IViewObjectEx)
  60. COM_INTERFACE_ENTRY(IObjectSafety)
  61. COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
  62. COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
  63. COM_INTERFACE_ENTRY(IOleControl)
  64. COM_INTERFACE_ENTRY(IOleObject)
  65. COM_INTERFACE_ENTRY(IQuickActivate)
  66. COM_INTERFACE_ENTRY(IPersistPropertyBag)
  67. COM_INTERFACE_ENTRY(IPointerInactive)
  68. COM_INTERFACE_ENTRY(IConnectionPointContainer)
  69. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  70. COM_INTERFACE_ENTRY_IID(IID_IViewObject, IViewObjectEx)
  71. COM_INTERFACE_ENTRY_IID(IID_IViewObject2, IViewObjectEx)
  72. COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IOleInPlaceObjectWindowless)
  73. COM_INTERFACE_ENTRY_IID(IID_IOleInPlaceObject, IOleInPlaceObjectWindowless)
  74. END_COM_MAP()
  75. BEGIN_MSG_MAP(CWebViewFolderIcon)
  76. MESSAGE_HANDLER(WM_PAINT, OnPaint)
  77. MESSAGE_HANDLER(WM_RBUTTONDOWN, OnButtonDown)
  78. MESSAGE_HANDLER(WM_LBUTTONDOWN, OnButtonDown)
  79. MESSAGE_HANDLER(WM_RBUTTONUP, OnRButtonUp)
  80. MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnLButtonDoubleClick)
  81. MESSAGE_HANDLER(WM_CONTEXTMENU, OnContextMenu)
  82. MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
  83. MESSAGE_HANDLER(WM_INITMENUPOPUP, OnInitPopup)
  84. MESSAGE_HANDLER(WM_MOUSELEAVE, OnMouseLeave)
  85. MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
  86. END_MSG_MAP()
  87. BEGIN_PROPERTY_MAP(CWebViewFolderIcon)
  88. PROP_ENTRY("scale", DISPID_PROP_WVFOLDERICON_SCALE, CLSID_WebViewFolderIcon)
  89. PROP_ENTRY("path", DISPID_PROP_WVFOLDERICON_PATH, CLSID_WebViewFolderIcon)
  90. PROP_ENTRY("view", DISPID_PROP_WVFOLDERICON_VIEW, CLSID_WebViewFolderIcon)
  91. PROP_ENTRY("advproperty", DISPID_PROP_WVFOLDERICON_ADVPROPERTY, CLSID_WebViewFolderIcon)
  92. PROP_ENTRY("clickStyle", DISPID_PROP_WVFOLDERICON_CLICKSTYLE, CLSID_WebViewFolderIcon)
  93. PROP_ENTRY("labelGap", DISPID_PROP_WVFOLDERICON_LABELGAP, CLSID_WebViewFolderIcon)
  94. // WARNING! "item" must be last because it can fail (due to security)
  95. // and ATL stops loading once any property returns failure.
  96. PROP_ENTRY("item", DISPID_PROP_WVFOLDERICON_ITEM, CLSID_WebViewFolderIcon)
  97. END_PROPERTY_MAP()
  98. BEGIN_CONNECTION_POINT_MAP(CWebViewFolderIcon)
  99. CONNECTION_POINT_ENTRY(DIID_DWebViewFolderIconEvents)
  100. END_CONNECTION_POINT_MAP()
  101. // *** IOleWindow ***
  102. virtual STDMETHODIMP GetWindow(HWND * lphwnd) {return IOleInPlaceActiveObjectImpl<CWebViewFolderIcon>::GetWindow(lphwnd);};
  103. virtual STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode) { return IOleInPlaceActiveObjectImpl<CWebViewFolderIcon>::ContextSensitiveHelp(fEnterMode); };
  104. // *** IOleInPlaceObject ***
  105. virtual STDMETHODIMP InPlaceDeactivate(void) {return IOleInPlaceObject_InPlaceDeactivate();};
  106. virtual STDMETHODIMP SetObjectRects(LPCRECT lprcPosRect, LPCRECT lprcClipRect) {return IOleInPlaceObject_SetObjectRects(lprcPosRect, lprcClipRect);};
  107. virtual STDMETHODIMP ReactivateAndUndo(void) { return E_NOTIMPL; };
  108. virtual STDMETHODIMP UIDeactivate(void);
  109. // *** IOleInPlaceActiveObject ***
  110. virtual STDMETHODIMP TranslateAccelerator(LPMSG pMsg);
  111. // IDispatch overrides
  112. STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid,
  113. WORD wFlags, DISPPARAMS *pDispParams,
  114. VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
  115. UINT *puArgErr);
  116. // IViewObjectEx overrides
  117. STDMETHOD(GetViewStatus)(DWORD* pdwStatus);
  118. // IObjectWithSite overrides
  119. STDMETHOD(SetClientSite)(IOleClientSite *pClientSite);
  120. // IObjectSafety overrides
  121. STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid, DWORD dwOptionSetMask,
  122. DWORD dwEnabledOptions);
  123. // IOleInPlaceObjectWindowless Overrides
  124. STDMETHOD(GetDropTarget)(IDropTarget **ppDropTarget);
  125. // IPointerInactive Overrides
  126. STDMETHOD(GetActivationPolicy)(DWORD* pdwPolicy);
  127. STDMETHOD(OnInactiveSetCursor)(LPCRECT pRectBounds, long x, long y, DWORD dwMouseMsg, BOOL fSetAlways) {return S_FALSE;}; // Ask for default behavior.
  128. // IOleControl overrides
  129. STDMETHOD(OnAmbientPropertyChange)(DISPID dispid);
  130. // ATL overrides
  131. HRESULT DoVerbUIActivate(LPCRECT prcPosRect, HWND hwndParent);
  132. // Event Handlers
  133. STDMETHOD(OnWindowLoad)(VOID);
  134. STDMETHOD(OnWindowUnLoad)(VOID);
  135. STDMETHOD(OnImageChanged)(VOID);
  136. // Advanced Properties - Context Menu, Default Open, Drag and Drop
  137. LRESULT OnRButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled);
  138. LRESULT OnButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled);
  139. LRESULT OnLButtonDoubleClick(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled);
  140. LRESULT OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled);
  141. LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled);
  142. LRESULT OnInitPopup(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled);
  143. LRESULT OnMouseLeave(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled);
  144. LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled);
  145. // *** IWebViewFolder ***
  146. STDMETHOD(get_scale)(BSTR *pbstrScale);
  147. STDMETHOD(put_scale)(BSTR bstrScale);
  148. STDMETHOD(get_path)(BSTR *pbstrPath);
  149. STDMETHOD(put_path)(BSTR bstrPath);
  150. STDMETHOD(get_view)(BSTR *pView);
  151. STDMETHOD(put_view)(BSTR view);
  152. STDMETHOD(get_advproperty)(VARIANT_BOOL *pvarbAdvProp);
  153. STDMETHOD(put_advproperty)(VARIANT_BOOL varbAdvProp);
  154. // *** IWebViewFolderIcon2 ***
  155. STDMETHOD(setSlice)(INT index, VARIANT varHiBytes, VARIANT varLoBytes, VARIANT varColorref);
  156. // *** IWebViewFolderIcon3 ***
  157. STDMETHOD(get_item)(FolderItem ** ppFolderItem);
  158. STDMETHOD(put_item)(FolderItem * pFolderItem);
  159. STDMETHOD(get_clickStyle)(/* retval, out */ LONG *plClickStyle);
  160. STDMETHOD(put_clickStyle)(/* in */ LONG lClickStyle);
  161. STDMETHOD(get_labelGap)(/* retval, out */ LONG *plLabelGap);
  162. STDMETHOD(put_labelGap)(/* in */ LONG lLabelGap);
  163. public:
  164. CWebViewFolderIcon(void);
  165. ~CWebViewFolderIcon(void);
  166. private:
  167. // Private helpers
  168. HRESULT InitImage(void);
  169. HRESULT InitIcon(void);
  170. HRESULT InitThumbnail(void);
  171. HRESULT InitPieGraph(void);
  172. HRESULT SetupIThumbnail(void);
  173. HRESULT _InvokeOnThumbnailReady();
  174. HRESULT UpdateSize(void);
  175. HRESULT ForceRedraw(void);
  176. HRESULT _GetFullPidl(LPITEMIDLIST *ppidl);
  177. HRESULT _GetPathW(LPWSTR psz);
  178. HRESULT _GetPidlAndShellFolder(LPITEMIDLIST *ppidlLast, IShellFolder** ppsfParent);
  179. HRESULT _GetHwnd(HWND* phwnd);
  180. HRESULT _GetCenterPoint(POINT *pt);
  181. HRESULT _GetChildUIObjectOf(REFIID riid, void ** ppvObj);
  182. BOOL _WebViewOpen(void);
  183. HRESULT _ZoneCheck(DWORD dwFlags);
  184. BOOL IsSafeToDefaultVerb(void);
  185. void _FlipFocusRect(BOOL RectState);
  186. ULONGLONG GetUllMemFromVars(VARIANT *pvarHi, VARIANT *pvarLo);
  187. int GetPercentFromStrW(LPCWSTR pwzPercent);
  188. HRESULT DragDrop(int iClickXPos, int iClickYPos);
  189. HRESULT _DisplayContextMenu(long nXCord, long nYCord);
  190. HRESULT _DoContextMenuCmd(BOOL bDefault, long nXCord, long nYCord);
  191. BOOL _IsHostWebView(void);
  192. BOOL _IsPubWizHosted(void);
  193. HRESULT _SetDragImage(int iClickXPos, int iClickYPos, IDataObject * pdtobj);
  194. // 3dPie functions
  195. HRESULT Draw3dPie(HDC hdc, LPRECT lprc, DWORD dwPercent1000, const COLORREF *lpColors);
  196. HRESULT ComputeFreeSpace(LPCWSTR pszFileName);
  197. void ScalePieRect(LONG ShadowScale, LONG AspectRatio, LPRECT lprc);
  198. void ComputeSlicePct(ULONGLONG ullMemSize, DWORD *pdwPercent1000);
  199. void CalcSlicePoint(int *x, int *y, int rx, int ry, int cx, int cy, int FirstQuadPercent1000, DWORD dwPercent1000);
  200. void SetUpPiePts(int *pcx, int *pcy, int *prx, int *pry, RECT rect);
  201. void DrawPieDepth(HDC hdc, RECT rect, int x, int y, int cy, DWORD dwPercent1000, LONG ShadowDepth);
  202. void DrawSlice(HDC hdc, RECT rect, DWORD dwPercent1000, int rx, int ry, int cx, int cy, /*int *px, int *py,*/
  203. COLORREF Color);
  204. void DrawEllipse(HDC hdc, RECT rect, int x, int y, int cx, int cy, DWORD dwPercent1000, const COLORREF *lpColors);
  205. void DrawShadowRegions(HDC hdc, RECT rect, LPRECT lprc, int UsedArc_x, int center_y, LONG ShadowDepth,
  206. DWORD dwPercent1000, COLORREF const *lpColors);
  207. HRESULT _GetPieChartIntoBitmap();
  208. HRESULT _SetupWindow(void);
  209. HRESULT _MakeRoomForLabel();
  210. // Window Procedure for catching and storing bitmap
  211. static LRESULT CALLBACK WndProc(HWND, UINT uMsg, WPARAM, LPARAM);
  212. // Managing the bitmap/icon
  213. LONG _GetScaledImageWidth(void) { return (m_lImageWidth * m_percentScale)/100; }
  214. LONG _GetScaledImageHeight(void) { return (m_lImageHeight * m_percentScale)/100; }
  215. // Managing the label
  216. void _ClearLabel(void);
  217. void _GetLabel(IShellFolder *psf, LPCITEMIDLIST pidlItem);
  218. LONG _GetControlWidth(void)
  219. { return _GetScaledImageWidth() +
  220. (m_sizLabel.cx ? m_cxLabelGap + m_sizLabel.cx : 0); }
  221. LONG _GetControlHeight(void) { return max(_GetScaledImageHeight(), m_sizLabel.cy); }
  222. void _GetAmbientFont(void);
  223. void _ClearAmbientFont(void);
  224. private:
  225. // Private message handlers
  226. HWND m_msgHwnd;
  227. WNDCLASS m_msgWc;
  228. BOOL m_bRegWndClass;
  229. IContextMenu3 * m_pcm3; // For Context Menu events
  230. IDropTarget * m_pDropTargetCache; // Cache the IDropTarget because MSHTML should but doesn't.
  231. IDispatch * m_pdispWindow; // Cache the HTML window object that we receive events from
  232. // Image information
  233. HICON m_hIcon;
  234. INT m_iIconIndex;
  235. // Size information
  236. INT m_percentScale; // image scaling
  237. UINT m_lImageWidth; // unscaled size of bitmap/icon
  238. UINT m_lImageHeight;
  239. LONG m_cxLabelGap;
  240. SIZE m_sizLabel; // size of label
  241. IThumbnail2 *m_pthumb;
  242. HBITMAP m_hbm;
  243. BOOL m_fTabRecieved;
  244. BOOL m_fIsHostWebView; // Are we hosted in WebView?
  245. HDC m_hdc; // Saved for _SetDragImage()
  246. RECT m_rect; // Rectangle into which we draw
  247. BOOL m_fRectAdjusted; // Flag says if we need to modify
  248. // rect for drag image.
  249. BOOL m_fLoaded;
  250. HBITMAP m_hbmDrag;
  251. // Piechart
  252. enum
  253. {
  254. PIE_USEDCOLOR = 0,
  255. PIE_FREECOLOR,
  256. PIE_USEDSHADOW,
  257. PIE_FREESHADOW,
  258. PIE_NUM // keep track of number of PIE_ values
  259. };
  260. enum
  261. {
  262. COLOR_UP = 0,
  263. COLOR_DN,
  264. COLOR_UPSHADOW,
  265. COLOR_DNSHADOW,
  266. COLOR_NUM // #of entries
  267. };
  268. enum VIEWS
  269. {
  270. VIEW_SMALLICON = 0,
  271. VIEW_LARGEICON,
  272. VIEW_THUMBVIEW,
  273. VIEW_PIECHART,
  274. // Extra flags for views
  275. VIEW_WITHLABEL = 0x00010000,
  276. VIEW_SMALLICONLABEL = VIEW_SMALLICON | VIEW_WITHLABEL,
  277. VIEW_LARGEICONLABEL = VIEW_LARGEICON | VIEW_WITHLABEL,
  278. };
  279. // Putzing with the view
  280. inline static UINT _ViewType(VIEWS vw) { return LOWORD(vw); }
  281. COLORREF m_ChartColors[PIE_NUM];
  282. ULONGLONG m_ullFreeSpace;
  283. ULONGLONG m_ullUsedSpace;
  284. ULONGLONG m_ullTotalSpace;
  285. BOOL m_fUseSystemColors;
  286. HDSA m_hdsaSlices; // added slices to the Used area
  287. int m_highestIndexSlice;
  288. // Advise Cookie
  289. DWORD m_dwHtmlWindowAdviseCookie;
  290. DWORD m_dwCookieDV;
  291. CIE4ConnectionPoint *m_pccpDV;
  292. // path property
  293. LPITEMIDLIST m_pidl;
  294. // view property
  295. VIEWS m_ViewUser; // What user wants.
  296. VIEWS m_ViewCurrent; // What user gets.
  297. // clickStyle property
  298. LONG m_clickStyle; // 1 = oneclick, 2 = twoclick
  299. // Activation rectangle flag
  300. BOOL m_bHasRect;
  301. // Advanced properties setting
  302. // When it is turned off, Context Menu, Drag and Drop, fucus rectangle, and security checking support
  303. // (anything to do with mouse clicking or tabbing) is turned off.
  304. BOOL m_bAdvPropsOn;
  305. // Should we also show the display name of the target?
  306. LPTSTR m_pszDisplayName;
  307. // What font should we show the display name in?
  308. HFONT m_hfAmbient;
  309. IFont * m_pfont; // Who owns the font?
  310. // (if NULL, then we do)
  311. // Show hilite effects- underline text, dropshadow for icon etc..
  312. BOOL m_bHilite;
  313. DWORD m_dwThumbnailID; // ID to identify which bitmap we received
  314. };
  315. #endif //__WVFOLDER_H_