1 /***************************************************************************/
3 /* This document is copyright (c) by Oz Solomonovich. All non-commercial */
4 /* use is allowed, as long as this document is not altered in any way, and */
5 /* due credit is given. */
6 /***************************************************************************/
8 // ShellContextMenu.h : header file
11 #if !defined(AFX_SHELLCONTEXTMENU_H__24BAC666_2B03_11D3_B9C1_0000861DFCE7__INCLUDED_)
12 #define AFX_SHELLCONTEXTMENU_H__24BAC666_2B03_11D3_B9C1_0000861DFCE7__INCLUDED_
16 #endif // _MSC_VER > 1000
24 typedef vector<CMenu*> vecODMenu;
25 #define STL_FOR_ITERATOR(t,v) for(t::iterator it=v.begin();it != v.end();it++)
26 #define STL_ERASE_ALL(v) v.erase(v.begin(),v.end())
27 #define STL_GET_CURRENT(v) *it
28 #define STL_ADD_ITEM(v,i) v.push_back(i);
29 #define STL_EMPTY(v) v.empty()
30 #define STL_SORT(v,f,c) TRACE0("Sorting with STL\n"); is_less_than_pidl::psf = f; sort(v.begin(),v.end(),c);
33 typedef CArray<CMenu*,CMenu*> vecODMenu;
34 #define STL_FOR_ITERATOR(t,v) for (int i=0;i < v.GetSize();i++)
35 #define STL_ERASE_ALL(v) v.RemoveAll()
36 #define STL_GET_CURRENT(v) v.GetAt(i)
37 #define STL_ADD_ITEM(v,i) v.Add(i);
38 #define STL_EMPTY(v) v.GetSize() == 0
39 #define STL_SORT(v,f,c) TRACE0("Sorting with MFC\n"); is_less_than_pidl::psf = f; qsort(v.GetData(),v.GetSize(),sizeof(void*),c);
44 class CShellContextMenu
47 LPSHELLFOLDER m_psfParent;
49 LPITEMIDLIST *m_ppidl;
53 CMenu * m_pSendToMenu;
54 vecODMenu m_OwnerDrawMenus;
55 CSize m_szOldButtonSize;
57 CShellContextMenu(HWND m_hWnd, const CString &sAbsPath, LPITEMIDLIST *ppidl, UINT cidl, LPSHELLFOLDER psfParent);
60 bool IsMenuCommand(int iCmd) const;
61 void InvokeCommand(int iCmd) const;
63 void CShellContextMenu::SetMenu(CMenu *pMenu);
66 void AddKey(CString &sDestKey,const CString &sSrcKey) const;
67 CString GetExt(const CString &sPath) const;
68 void GetAppDetails(const CString &sAppName,CString &sDisplayName,CString &sCommand,HICON &hAppIcon) const;
69 void CShellContextMenu::FillSendToMenu(CMenu *pMenu,
70 LPSHELLFOLDER pSF, UINT &idm);
71 void FillOpenWithMenu(CMenu *pMenu,const CString &sExt);
74 /////////////////////////////////////////////////////////////////////////////
75 // Addition: Philip Oldaker
76 // Maybe overkill to sort the SendTo menu but could be useful
77 /////////////////////////////////////////////////////////////////////////////
81 CShCMSort(UINT nID,LPITEMIDLIST pidl,HICON hIcon,const CString &sText,DWORD dwItemData);
84 CShCMSort(const CShCMSort &rOther);
85 const CShCMSort &operator=(const CShCMSort &rOther);
87 void SetIndent(int nIndent);
88 int GetIndent() const;
90 void SetImage(int nImage);
92 void SetSelImage(int nSelImage);
93 int GetSelImage() const;
94 void SetOverlayImage(int nOverlayImage);
95 int GetOverlayImage() const;
96 void SetPidl(LPITEMIDLIST pidl);
97 const LPITEMIDLIST GetPidl() const;
98 void SetIcon(HICON hIcon);
99 HICON GetIcon() const;
100 void SetItemID(UINT nID);
101 UINT GetItemID() const;
102 void SetText(const CString &sText);
103 const CString &GetText() const;
104 void SetItemData(DWORD dwItemData);
105 DWORD GetItemData() const;
119 inline void CShCMSort::SetIndent(int nIndent)
124 inline int CShCMSort::GetIndent() const
129 inline void CShCMSort::SetImage(int nImage)
134 inline int CShCMSort::GetImage() const
139 inline void CShCMSort::SetSelImage(int nSelImage)
141 m_nSelImage = nSelImage;
144 inline int CShCMSort::GetSelImage() const
149 inline void CShCMSort::SetOverlayImage(int nOverlayImage)
151 m_nOverlayImage = nOverlayImage;
154 inline int CShCMSort::GetOverlayImage() const
156 return m_nOverlayImage;
159 inline CShCMSort::CShCMSort()
171 inline CShCMSort::CShCMSort(UINT nID,LPITEMIDLIST pidl,HICON hIcon,const CString &sText,DWORD dwItemData)
176 m_dwItemData(dwItemData)
180 inline CShCMSort::~CShCMSort()
186 inline CShCMSort::CShCMSort(const CShCMSort &rOther)
187 : m_pidl(rOther.m_pidl),
188 m_hIcon(rOther.m_hIcon),
190 m_sText(rOther.m_sText),
191 m_dwItemData(rOther.m_dwItemData),
192 m_nIndent(rOther.m_nIndent),
193 m_nImage(rOther.m_nImage),
194 m_nSelImage(rOther.m_nSelImage),
195 m_nOverlayImage(rOther.m_nOverlayImage)
199 inline const CShCMSort &CShCMSort::operator=(const CShCMSort &rOther)
204 m_pidl = rOther.m_pidl;
205 m_hIcon = rOther.m_hIcon;
207 m_sText = rOther.m_sText;
208 m_dwItemData = rOther.m_dwItemData;
209 m_nIndent = rOther.m_nIndent;
210 m_nImage = rOther.m_nImage;
211 m_nSelImage = rOther.m_nSelImage;
212 m_nOverlayImage = rOther.m_nOverlayImage;
217 inline void CShCMSort::SetPidl(LPITEMIDLIST pidl)
222 inline const LPITEMIDLIST CShCMSort::GetPidl() const
227 inline void CShCMSort::SetIcon(HICON hIcon)
232 inline HICON CShCMSort::GetIcon() const
237 inline void CShCMSort::SetItemID(UINT nID)
242 inline UINT CShCMSort::GetItemID() const
247 inline void CShCMSort::SetText(const CString &sText)
252 inline const CString &CShCMSort::GetText() const
257 inline void CShCMSort::SetItemData(DWORD dwItemData)
259 m_dwItemData = dwItemData;
262 inline DWORD CShCMSort::GetItemData() const
267 // STL predicate helpers
270 class is_less_than_pidl
273 is_less_than_pidl() {}
275 bool operator()(const CShCMSort *x,const CShCMSort *y)
277 return ComparePidls(x,y) < 0;
279 int ComparePidls(const CShCMSort *x,const CShCMSort *y)
281 ASSERT(is_less_than_pidl::psf);
282 HRESULT hr = is_less_than_pidl::psf->CompareIDs(0, x->GetPidl(), y->GetPidl());
288 static int compare(const void *x, const void *y)
290 const CShCMSort *x1 = *(const CShCMSort**)x;
291 const CShCMSort *y1 = *(const CShCMSort**)y;
292 return is_less_than_pidl().ComparePidls(x1,y1);
295 CTRL_EXT_CLASS static LPSHELLFOLDER psf;
298 class is_greater_than_pidl
301 is_greater_than_pidl() { }
303 bool operator()(const CShCMSort *x,const CShCMSort *y)
305 return ComparePidls(x,y) > 0;
307 int ComparePidls(const CShCMSort *x,const CShCMSort *y)
309 HRESULT hr = is_greater_than_pidl::psf->CompareIDs(0, x->GetPidl(), y->GetPidl());
315 static int compare(const void *x, const void *y)
317 const CShCMSort *x1 = *(const CShCMSort**)x;
318 const CShCMSort *y1 = *(const CShCMSort**)y;
319 return is_greater_than_pidl().ComparePidls(x1,y1);
322 CTRL_EXT_CLASS static LPSHELLFOLDER psf;
326 class is_less_than_text
330 bool operator()(const CShCMSort *x,const CShCMSort *y)
332 return CompareText(x,y) < 0;
334 int CompareText(const CShCMSort *x,const CShCMSort *y)
336 return x->GetText() < y->GetText();
339 static int compare(const void *x, const void *y)
341 const CShCMSort *x1 = *(const CShCMSort**)x;
342 const CShCMSort *y1 = *(const CShCMSort**)y;
343 return is_less_than_text().CompareText(x1,y1);
347 class is_greater_than_text
351 bool operator()(const CShCMSort *x,const CShCMSort *y)
353 return CompareText(x,y) < 0;
355 int CompareText(const CShCMSort *x,const CShCMSort *y)
357 return x->GetText() > y->GetText();
360 static int compare(const void *x, const void *y)
362 const CShCMSort *x1 = *(const CShCMSort**)x;
363 const CShCMSort *y1 = *(const CShCMSort**)y;
364 return is_greater_than_text().CompareText(x1,y1);
369 typedef vector<CShCMSort*> vecCMSort;
370 #define STL_SORT_FUNC is_less_than_pidl()
372 typedef CArray<CShCMSort*,CShCMSort*> vecCMSort;
373 #define STL_SORT_FUNC is_less_than_pidl::compare
376 /////////////////////////////////////////////////////////////////
378 //{{AFX_INSERT_LOCATION}}
379 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
381 #endif // !defined(AFX_SHELLCONTEXTMENU_H__24BAC666_2B03_11D3_B9C1_0000861DFCE7__INCLUDED_)