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.

392 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. // *** IWebViewFolderIcon ***
  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. HRESULT _IsSafe();
  185. BOOL IsSafeToDefaultVerb(void);
  186. void _FlipFocusRect(BOOL RectState);
  187. ULONGLONG GetUllMemFromVars(VARIANT *pvarHi, VARIANT *pvarLo);
  188. int GetPercentFromStrW(LPCWSTR pwzPercent);
  189. HRESULT DragDrop(int iClickXPos, int iClickYPos);
  190. HRESULT _DisplayContextMenu(long nXCord, long nYCord);
  191. HRESULT _DoContextMenuCmd(BOOL bDefault, long nXCord, long nYCord);
  192. BOOL _IsHostWebView(void);
  193. BOOL _IsPubWizHosted(void);
  194. HRESULT _SetDragImage(int iClickXPos, int iClickYPos, IDataObject * pdtobj);
  195. // 3dPie functions
  196. HRESULT Draw3dPie(HDC hdc, LPRECT lprc, DWORD dwPercent1000, const COLORREF *lpColors);
  197. HRESULT ComputeFreeSpace(LPCWSTR pszFileName);
  198. void ScalePieRect(LONG ShadowScale, LONG AspectRatio, LPRECT lprc);
  199. void ComputeSlicePct(ULONGLONG ullMemSize, DWORD *pdwPercent1000);
  200. void CalcSlicePoint(int *x, int *y, int rx, int ry, int cx, int cy, int FirstQuadPercent1000, DWORD dwPercent1000);
  201. void SetUpPiePts(int *pcx, int *pcy, int *prx, int *pry, RECT rect);
  202. void DrawPieDepth(HDC hdc, RECT rect, int x, int y, int cy, DWORD dwPercent1000, LONG ShadowDepth);
  203. void DrawSlice(HDC hdc, RECT rect, DWORD dwPercent1000, int rx, int ry, int cx, int cy, /*int *px, int *py,*/
  204. COLORREF Color);
  205. void DrawEllipse(HDC hdc, RECT rect, int x, int y, int cx, int cy, DWORD dwPercent1000, const COLORREF *lpColors);
  206. void DrawShadowRegions(HDC hdc, RECT rect, LPRECT lprc, int UsedArc_x, int center_y, LONG ShadowDepth,
  207. DWORD dwPercent1000, COLORREF const *lpColors);
  208. HRESULT _GetPieChartIntoBitmap();
  209. HRESULT _SetupWindow(void);
  210. HRESULT _MakeRoomForLabel();
  211. // Window Procedure for catching and storing bitmap
  212. static LRESULT CALLBACK WndProc(HWND, UINT uMsg, WPARAM, LPARAM);
  213. // Managing the bitmap/icon
  214. LONG _GetScaledImageWidth(void) { return (m_lImageWidth * m_percentScale)/100; }
  215. LONG _GetScaledImageHeight(void) { return (m_lImageHeight * m_percentScale)/100; }
  216. // Managing the label
  217. void _ClearLabel(void);
  218. void _GetLabel(IShellFolder *psf, LPCITEMIDLIST pidlItem);
  219. LONG _GetControlWidth(void)
  220. { return _GetScaledImageWidth() +
  221. (m_sizLabel.cx ? m_cxLabelGap + m_sizLabel.cx : 0); }
  222. LONG _GetControlHeight(void) { return max(_GetScaledImageHeight(), m_sizLabel.cy); }
  223. void _GetAmbientFont(void);
  224. void _ClearAmbientFont(void);
  225. private:
  226. // Private message handlers
  227. HWND m_msgHwnd;
  228. WNDCLASS m_msgWc;
  229. BOOL m_bRegWndClass;
  230. IContextMenu3 * m_pcm3; // For Context Menu events
  231. IDropTarget * m_pDropTargetCache; // Cache the IDropTarget because MSHTML should but doesn't.
  232. IDispatch * m_pdispWindow; // Cache the HTML window object that we receive events from
  233. // Image information
  234. HICON m_hIcon;
  235. INT m_iIconIndex;
  236. // Size information
  237. INT m_percentScale; // image scaling
  238. UINT m_lImageWidth; // unscaled size of bitmap/icon
  239. UINT m_lImageHeight;
  240. LONG m_cxLabelGap;
  241. SIZE m_sizLabel; // size of label
  242. IThumbnail2 *m_pthumb;
  243. HBITMAP m_hbm;
  244. BOOL m_fTabRecieved;
  245. BOOL m_fIsHostWebView; // Are we hosted in WebView?
  246. HDC m_hdc; // Saved for _SetDragImage()
  247. RECT m_rect; // Rectangle into which we draw
  248. BOOL m_fRectAdjusted; // Flag says if we need to modify
  249. // rect for drag image.
  250. BOOL m_fLoaded;
  251. HBITMAP m_hbmDrag;
  252. // Piechart
  253. enum
  254. {
  255. PIE_USEDCOLOR = 0,
  256. PIE_FREECOLOR,
  257. PIE_USEDSHADOW,
  258. PIE_FREESHADOW,
  259. PIE_NUM // keep track of number of PIE_ values
  260. };
  261. enum
  262. {
  263. COLOR_UP = 0,
  264. COLOR_DN,
  265. COLOR_UPSHADOW,
  266. COLOR_DNSHADOW,
  267. COLOR_NUM // #of entries
  268. };
  269. enum VIEWS
  270. {
  271. VIEW_SMALLICON = 0,
  272. VIEW_LARGEICON,
  273. VIEW_THUMBVIEW,
  274. VIEW_PIECHART,
  275. // Extra flags for views
  276. VIEW_WITHLABEL = 0x00010000,
  277. VIEW_SMALLICONLABEL = VIEW_SMALLICON | VIEW_WITHLABEL,
  278. VIEW_LARGEICONLABEL = VIEW_LARGEICON | VIEW_WITHLABEL,
  279. };
  280. // Putzing with the view
  281. inline static UINT _ViewType(VIEWS vw) { return LOWORD(vw); }
  282. COLORREF m_ChartColors[PIE_NUM];
  283. ULONGLONG m_ullFreeSpace;
  284. ULONGLONG m_ullUsedSpace;
  285. ULONGLONG m_ullTotalSpace;
  286. BOOL m_fUseSystemColors;
  287. HDSA m_hdsaSlices; // added slices to the Used area
  288. int m_highestIndexSlice;
  289. // Advise Cookie
  290. DWORD m_dwHtmlWindowAdviseCookie;
  291. DWORD m_dwCookieDV;
  292. CIE4ConnectionPoint *m_pccpDV;
  293. // path property
  294. LPITEMIDLIST m_pidl;
  295. // view property
  296. VIEWS m_ViewUser; // What user wants.
  297. VIEWS m_ViewCurrent; // What user gets.
  298. // clickStyle property
  299. LONG m_clickStyle; // 1 = oneclick, 2 = twoclick
  300. // Activation rectangle flag
  301. BOOL m_bHasRect;
  302. // Advanced properties setting
  303. // When it is turned off, Context Menu, Drag and Drop, fucus rectangle, and security checking support
  304. // (anything to do with mouse clicking or tabbing) is turned off.
  305. BOOL m_bAdvPropsOn;
  306. // Should we also show the display name of the target?
  307. LPTSTR m_pszDisplayName;
  308. // What font should we show the display name in?
  309. HFONT m_hfAmbient;
  310. IFont * m_pfont; // Who owns the font?
  311. // (if NULL, then we do)
  312. // Show hilite effects- underline text, dropshadow for icon etc..
  313. BOOL m_bHilite;
  314. DWORD m_dwThumbnailID; // ID to identify which bitmap we received
  315. };
  316. #endif //__WVFOLDER_H_