update for HEAD-2003091401
[reactos.git] / subsys / system / explorer / Seashell / SeaShellExt / Include / PIDL.h
1 ////////////////////////////////////////////////////////////////////
2 // PIDL.h: interface for the CPIDL class.
3 //
4
5 #ifndef __PIDL_H
6 #define __PIDL_H
7
8 #include <shlobj.h>
9
10 class CPIDL
11 {
12 public:
13     LPITEMIDLIST  m_pidl;
14
15 // == Construction/Destruction == //
16
17     CPIDL() : m_pidl(NULL) {}
18
19     // Copy constructor
20     CPIDL(const CPIDL& cpidl) : m_pidl(NULL) { Set(cpidl); }
21
22     // From path (szPath relative to the folder psf) - see Set()
23     CPIDL(LPCTSTR szPath, LPSHELLFOLDER psf = m_sfDesktop); 
24
25     // From a list ptr - *doesn't* copy the actual data - see Set()
26     CPIDL(LPITEMIDLIST pidl) : m_pidl(pidl) {}
27
28     virtual ~CPIDL();
29
30
31 // == Assignment == //
32
33     // Make a copy of cpidl's list data
34     HRESULT Set(const CPIDL& cpidl);
35
36     // Set by path: szPath relative to the folder psf.
37     HRESULT Set(LPCTSTR szPath, LPSHELLFOLDER psf = m_sfDesktop);
38
39     // Points the CPIDL to an existing item list: does *not* copy
40     // the actual data - just the pointer (unlike MakeCopyOf()).
41     HRESULT Set(LPITEMIDLIST pidl);
42
43     // Special Assignment: Copies the data of an exisiting list.
44     HRESULT MakeCopyOf(LPITEMIDLIST pidl);
45
46     // Special Assignment: Makes a PIDL rooted at the desktop.
47     HRESULT MakeAbsPIDLOf(LPSHELLFOLDER psf, LPITEMIDLIST pidl);
48
49
50 // == Item Access == //
51
52     // Returns a pointer to the first item in the list
53     LPSHITEMID GetFirstItemID() const { return (LPSHITEMID)m_pidl; }
54
55     // Points to the next item in the list
56     void GetNextItemID(LPSHITEMID& pid) const 
57         { (LPBYTE &)pid += pid->cb; }
58
59
60 // == General Operations == //
61
62     void Free();          // Frees the memory used by the item id list
63     UINT GetSize() const; // Counts the actual memory in use
64
65     // Split into direct parent and object pidls
66     void Split(CPIDL& parent, CPIDL& obj) const;
67
68     // Concatenation
69     CPIDL operator + (CPIDL& pidl) const;  // using + operator
70     static void Concat(const CPIDL &a, const CPIDL& b, 
71         CPIDL& result);                    // result = a+b (faster)
72
73
74 // == Shell Name-space Access Helper Functions == //
75
76     // 1) Won't always work: psf->GetUIObjectOf(pidl, ... )
77     // 2) Will always work:  pidl.GetUIObjectOf(..., psf)
78     HRESULT GetUIObjectOf(REFIID riid, LPVOID *ppvOut, 
79         HWND hWnd = NULL, LPSHELLFOLDER psf = m_sfDesktop);
80
81     // Places the STRRET string in the cStr field.  
82     void ExtractCStr(STRRET& strRet) const;
83
84
85 // == Conversion Operators == //
86
87     operator LPITEMIDLIST&  () { return m_pidl; }
88     operator LPITEMIDLIST * () { return &m_pidl; }
89     operator LPCITEMIDLIST  () const { return m_pidl; }
90     operator LPCITEMIDLIST* () const 
91         { return (LPCITEMIDLIST *)&m_pidl; }
92
93 protected:
94     static LPSHELLFOLDER    m_sfDesktop;    // desktop object
95     static LPMALLOC         m_pAllocator;   // system allocator
96
97     // allocate memory for the pidl using the system allocator
98     void AllocMem(int iAllocSize);
99
100     // initializer (used for automatic initialization)
101     static struct pidl_initializer {
102         pidl_initializer();
103         ~pidl_initializer();
104     } m_initializer;
105     friend struct pidl_initializer;
106 };
107
108 #endif  // __PIDL_H