This commit was manufactured by cvs2svn to create branch 'captive'.
[reactos.git] / subsys / system / explorer / Seashell / SeaShellExt / Include / ShellContextMenu.h
1 /***************************************************************************/
2 /* NOTE:                                                                   */
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 /***************************************************************************/
7
8 // ShellContextMenu.h : header file
9 //
10
11 #if !defined(AFX_SHELLCONTEXTMENU_H__24BAC666_2B03_11D3_B9C1_0000861DFCE7__INCLUDED_)
12 #define AFX_SHELLCONTEXTMENU_H__24BAC666_2B03_11D3_B9C1_0000861DFCE7__INCLUDED_
13
14 #if _MSC_VER > 1000
15 #pragma once
16 #endif // _MSC_VER > 1000
17
18 //#define USESTL
19
20 #if defined USESTL
21 #include <vector>
22 #include <algorithm>
23 using namespace std;
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);
31 #else
32 #include <afxtempl.h>
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);
40 #endif
41
42 #include "PIDL.h"
43
44 class CShellContextMenu
45 {
46     LPCONTEXTMENU           m_lpcm;
47         LPSHELLFOLDER                   m_psfParent;
48         LPITEMIDLIST                    m_pidl;
49         LPITEMIDLIST                    *m_ppidl;
50         UINT                                    m_cidl;
51         CString                                 m_sAbsPath;
52     HWND                    m_hWnd;
53     CMenu *                 m_pSendToMenu;
54         vecODMenu               m_OwnerDrawMenus;
55         CSize                                   m_szOldButtonSize;
56 public:    
57     CShellContextMenu(HWND m_hWnd, const CString &sAbsPath, LPITEMIDLIST *ppidl, UINT cidl, LPSHELLFOLDER psfParent);
58     ~CShellContextMenu();
59
60     bool IsMenuCommand(int iCmd) const;
61     void InvokeCommand(int iCmd) const;
62
63     void CShellContextMenu::SetMenu(CMenu *pMenu);
64
65 protected:    
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); 
72 };
73
74 /////////////////////////////////////////////////////////////////////////////
75 // Addition: Philip Oldaker
76 // Maybe overkill to sort the SendTo menu but could be useful
77 /////////////////////////////////////////////////////////////////////////////
78 class CShCMSort
79 {
80 public:
81     CShCMSort(UINT nID,LPITEMIDLIST pidl,HICON hIcon,const CString &sText,DWORD dwItemData);
82     CShCMSort();
83     ~CShCMSort();
84     CShCMSort(const CShCMSort &rOther);
85     const CShCMSort &operator=(const CShCMSort &rOther);
86 // Properties
87         void SetIndent(int nIndent);
88         int GetIndent() const;
89 public:
90     void SetImage(int nImage);
91     int GetImage() const;
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;
106 private:
107     // relative pidl
108     LPITEMIDLIST    m_pidl;   
109     int             m_nIndent;
110     int             m_nImage;
111     int             m_nSelImage;
112     int             m_nOverlayImage;
113     HICON           m_hIcon;
114     UINT            m_ID;
115     CString         m_sText;
116     DWORD           m_dwItemData;       
117 };
118
119 inline void CShCMSort::SetIndent(int nIndent)
120 {
121         m_nIndent = nIndent;
122 }
123
124 inline int CShCMSort::GetIndent() const
125 {
126         return m_nIndent;
127 }
128
129 inline void CShCMSort::SetImage(int nImage)
130 {
131         m_nImage = nImage;
132 }
133
134 inline int CShCMSort::GetImage() const
135 {
136         return m_nImage;
137 }
138
139 inline void CShCMSort::SetSelImage(int nSelImage)
140 {
141         m_nSelImage = nSelImage;
142 }
143
144 inline int CShCMSort::GetSelImage() const
145 {
146         return m_nSelImage;
147 }
148
149 inline void CShCMSort::SetOverlayImage(int nOverlayImage)
150 {
151         m_nOverlayImage = nOverlayImage;
152 }
153
154 inline int CShCMSort::GetOverlayImage() const
155 {
156         return m_nOverlayImage;
157 }
158
159 inline CShCMSort::CShCMSort()   
160 {
161     m_ID = 0;
162     m_dwItemData = 0;
163     m_pidl = NULL;
164     m_hIcon = NULL;
165         m_nIndent = 0;
166         m_nImage = 0;
167         m_nSelImage = 0;
168         m_nOverlayImage = 0;
169 }
170
171 inline CShCMSort::CShCMSort(UINT nID,LPITEMIDLIST pidl,HICON hIcon,const CString &sText,DWORD dwItemData)
172 :       m_ID(nID),
173         m_pidl(pidl),
174         m_hIcon(hIcon),
175         m_sText(sText),
176         m_dwItemData(dwItemData)
177 {
178 }
179
180 inline CShCMSort::~CShCMSort()
181 {
182
183 }
184
185
186 inline CShCMSort::CShCMSort(const CShCMSort &rOther)
187  :  m_pidl(rOther.m_pidl),
188     m_hIcon(rOther.m_hIcon),
189     m_ID(rOther.m_ID),
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)
196 {
197 }
198
199 inline const CShCMSort &CShCMSort::operator=(const CShCMSort &rOther)
200 {
201     if (this == &rOther)
202         return *this;
203
204     m_pidl = rOther.m_pidl;
205     m_hIcon = rOther.m_hIcon;
206     m_ID = rOther.m_ID;
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;
213
214     return *this;
215 }
216
217 inline void CShCMSort::SetPidl(LPITEMIDLIST     pidl)
218 {
219         m_pidl = pidl;
220 }
221
222 inline const LPITEMIDLIST CShCMSort::GetPidl() const
223 {
224         return m_pidl;
225 }
226
227 inline void CShCMSort::SetIcon(HICON hIcon)
228 {
229         m_hIcon = hIcon;
230 }
231
232 inline HICON CShCMSort::GetIcon() const
233 {
234         return m_hIcon;
235 }
236
237 inline void CShCMSort::SetItemID(UINT nID)
238 {
239         m_ID = nID;
240 }
241
242 inline UINT CShCMSort::GetItemID() const
243 {
244         return m_ID;
245 }
246
247 inline void CShCMSort::SetText(const CString &sText)
248 {
249         m_sText = sText;
250 }
251
252 inline const CString &CShCMSort::GetText() const
253 {
254         return m_sText;
255 }
256
257 inline void CShCMSort::SetItemData(DWORD dwItemData)
258 {
259         m_dwItemData = dwItemData;
260 }
261
262 inline DWORD CShCMSort::GetItemData() const
263 {
264         return m_dwItemData;
265 }
266
267 // STL predicate helpers
268
269 // sort by pidl
270 class is_less_than_pidl
271 {                           
272 public:
273         is_less_than_pidl() {}
274         // STL
275         bool operator()(const CShCMSort *x,const CShCMSort *y)
276         {
277                 return ComparePidls(x,y) < 0;
278         }
279         int ComparePidls(const CShCMSort *x,const CShCMSort *y)
280         {
281                 ASSERT(is_less_than_pidl::psf);
282                 HRESULT hr = is_less_than_pidl::psf->CompareIDs(0, x->GetPidl(), y->GetPidl());
283                 if (FAILED(hr))
284                         return 0;
285                 return (short)hr;
286         }
287         // MFC
288         static int compare(const void *x, const void *y)
289         {
290                 const CShCMSort *x1 = *(const CShCMSort**)x;
291                 const CShCMSort *y1 = *(const CShCMSort**)y;
292                 return is_less_than_pidl().ComparePidls(x1,y1);
293         }
294 public:
295         CTRL_EXT_CLASS static LPSHELLFOLDER psf;
296 };
297
298 class is_greater_than_pidl
299 {                           
300 public:
301         is_greater_than_pidl() { }
302         // STL
303         bool operator()(const CShCMSort *x,const CShCMSort *y)
304         {
305                 return ComparePidls(x,y) > 0;
306         }
307         int ComparePidls(const CShCMSort *x,const CShCMSort *y)
308         {
309                 HRESULT hr = is_greater_than_pidl::psf->CompareIDs(0, x->GetPidl(), y->GetPidl());
310                 if (FAILED (hr))
311                         return 0;
312                 return (short)hr;
313         }
314         // MFC
315         static int compare(const void *x, const void *y)
316         {
317                 const CShCMSort *x1 = *(const CShCMSort**)x;
318                 const CShCMSort *y1 = *(const CShCMSort**)y;
319                 return is_greater_than_pidl().ComparePidls(x1,y1);
320         }
321 public:
322         CTRL_EXT_CLASS static LPSHELLFOLDER psf;
323 };
324
325 // sort by text
326 class is_less_than_text
327 {                           
328 public:
329         // STL
330         bool operator()(const CShCMSort *x,const CShCMSort *y)
331         {
332                 return CompareText(x,y) < 0;
333         }
334         int CompareText(const CShCMSort *x,const CShCMSort *y)
335         {
336                 return x->GetText() < y->GetText();
337         }
338         // MFC
339         static int compare(const void *x, const void *y)
340         {
341                 const CShCMSort *x1 = *(const CShCMSort**)x;
342                 const CShCMSort *y1 = *(const CShCMSort**)y;
343                 return is_less_than_text().CompareText(x1,y1);
344         }
345 };
346
347 class is_greater_than_text
348 {                           
349 public:
350         // STL
351         bool operator()(const CShCMSort *x,const CShCMSort *y)
352         {
353                 return CompareText(x,y) < 0;
354         }
355         int CompareText(const CShCMSort *x,const CShCMSort *y)
356         {
357                 return x->GetText() > y->GetText();
358         }
359         // MFC
360         static int compare(const void *x, const void *y)
361         {
362                 const CShCMSort *x1 = *(const CShCMSort**)x;
363                 const CShCMSort *y1 = *(const CShCMSort**)y;
364                 return is_greater_than_text().CompareText(x1,y1);
365         }
366 };
367
368 #if defined USESTL
369 typedef vector<CShCMSort*> vecCMSort;
370 #define STL_SORT_FUNC is_less_than_pidl()
371 #else
372 typedef CArray<CShCMSort*,CShCMSort*> vecCMSort;
373 #define STL_SORT_FUNC is_less_than_pidl::compare
374 #endif
375
376 /////////////////////////////////////////////////////////////////
377
378 //{{AFX_INSERT_LOCATION}}
379 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
380
381 #endif // !defined(AFX_SHELLCONTEXTMENU_H__24BAC666_2B03_11D3_B9C1_0000861DFCE7__INCLUDED_)