Cleanup, small fixes, a few new stubs.
[wine] / dlls / shell32 / folders.c
1 /*
2  *      Shell Folder stuff (...and all the OLE-Objects of SHELL32.DLL)
3  *
4  *      Copyright 1997  Marcus Meissner
5  *      Copyright 1998  Juergen Schmied
6  *
7  *  !!! currently work in progress on all classes !!!
8  *  <contact juergen.schmied@metronet.de, 980801>
9  */
10
11 #include <ctype.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include "ole.h"
15 #include "ole2.h"
16 #include "debug.h"
17 #include "compobj.h"
18 #include "interfaces.h"
19 #include "shlobj.h"
20 #include "shell.h"
21 #include "winerror.h"
22 #include "winnls.h"
23 #include "winproc.h"
24 #include "commctrl.h"
25 #include "pidl.h"
26
27 #include "shell32_main.h"
28
29
30 /******************************************************************************
31 * foreward declaration
32 */
33
34 /* IExtractIcon implementation*/
35 static HRESULT WINAPI IExtractIcon_QueryInterface(LPEXTRACTICON, REFIID, LPVOID *);
36 static ULONG WINAPI IExtractIcon_AddRef(LPEXTRACTICON);
37 static ULONG WINAPI IExtractIcon_AddRef(LPEXTRACTICON);
38 static ULONG WINAPI IExtractIcon_Release(LPEXTRACTICON);
39 static HRESULT WINAPI IExtractIcon_GetIconLocation(LPEXTRACTICON, UINT32, LPSTR, UINT32, int *, UINT32 *);
40 static HRESULT WINAPI IExtractIcon_Extract(LPEXTRACTICON, LPCSTR, UINT32, HICON32 *, HICON32 *, UINT32);
41
42 /* IShellLink Implementation */
43 static HRESULT WINAPI IShellLink_QueryInterface(LPSHELLLINK,REFIID,LPVOID*);
44 static ULONG WINAPI IShellLink_AddRef(LPSHELLLINK);
45 static ULONG WINAPI IShellLink_Release(LPSHELLLINK);
46 static HRESULT WINAPI IShellLink_GetPath(LPSHELLLINK, LPSTR,INT32, WIN32_FIND_DATA32A *, DWORD);
47 static HRESULT WINAPI IShellLink_GetIDList(LPSHELLLINK, LPITEMIDLIST *);
48 static HRESULT WINAPI IShellLink_SetIDList(LPSHELLLINK, LPCITEMIDLIST);
49 static HRESULT WINAPI IShellLink_GetDescription(LPSHELLLINK, LPSTR,INT32);
50 static HRESULT WINAPI IShellLink_SetDescription(LPSHELLLINK, LPCSTR);
51 static HRESULT WINAPI IShellLink_GetWorkingDirectory(LPSHELLLINK, LPSTR,INT32);
52 static HRESULT WINAPI IShellLink_SetWorkingDirectory(LPSHELLLINK, LPCSTR);
53 static HRESULT WINAPI IShellLink_GetArguments(LPSHELLLINK, LPSTR,INT32);
54 static HRESULT WINAPI IShellLink_SetArguments(LPSHELLLINK, LPCSTR);
55 static HRESULT WINAPI IShellLink_GetHotkey(LPSHELLLINK, WORD *);
56 static HRESULT WINAPI IShellLink_SetHotkey(LPSHELLLINK, WORD);
57 static HRESULT WINAPI IShellLink_GetShowCmd(LPSHELLLINK, INT32 *);
58 static HRESULT WINAPI IShellLink_SetShowCmd(LPSHELLLINK, INT32);
59 static HRESULT WINAPI IShellLink_GetIconLocation(LPSHELLLINK, LPSTR,INT32,INT32 *);
60 static HRESULT WINAPI IShellLink_SetIconLocation(LPSHELLLINK, LPCSTR,INT32);
61 static HRESULT WINAPI IShellLink_SetRelativePath(LPSHELLLINK, LPCSTR, DWORD);
62 static HRESULT WINAPI IShellLink_Resolve(LPSHELLLINK, HWND32, DWORD);
63 static HRESULT WINAPI IShellLink_SetPath(LPSHELLLINK, LPCSTR);
64
65
66 /***********************************************************************
67 *   IExtractIcon implementation
68 */
69 static struct IExtractIcon_VTable eivt = 
70 { IExtractIcon_QueryInterface,
71   IExtractIcon_AddRef,
72   IExtractIcon_Release,
73   IExtractIcon_GetIconLocation,
74   IExtractIcon_Extract
75 };
76 /**************************************************************************
77 *  IExtractIcon_Constructor
78 */
79 LPEXTRACTICON IExtractIcon_Constructor(LPCITEMIDLIST pidl)
80 { LPEXTRACTICON ei;
81
82   ei=(LPEXTRACTICON)HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIcon));
83   ei->ref=1;
84   ei->lpvtbl=&eivt;
85   ei->pidl=ILClone(pidl);
86
87   pdump(pidl);
88
89   TRACE(shell,"(%p)\n",ei);
90   return ei;
91 }
92 /**************************************************************************
93  *  IExtractIcon_QueryInterface
94  */
95 static HRESULT WINAPI IExtractIcon_QueryInterface( LPEXTRACTICON this, REFIID riid, LPVOID *ppvObj)
96 {  char xriid[50];
97    WINE_StringFromCLSID((LPCLSID)riid,xriid);
98    TRACE(shell,"(%p)->(\n\tIID:\t%s,%p)\n",this,xriid,ppvObj);
99
100   *ppvObj = NULL;
101
102   if(IsEqualIID(riid, &IID_IUnknown))          /*IUnknown*/
103   { *ppvObj = this; 
104   }
105   else if(IsEqualIID(riid, &IID_IExtractIcon))  /*IExtractIcon*/
106   {    *ppvObj = (IExtractIcon*)this;
107   }   
108
109   if(*ppvObj)
110   { (*(LPEXTRACTICON*)ppvObj)->lpvtbl->fnAddRef(this);          
111     TRACE(shell,"-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
112     return S_OK;
113   }
114         TRACE(shell,"-- Interface: E_NOINTERFACE\n");
115         return E_NOINTERFACE;
116 }   
117
118 /**************************************************************************
119 *  IExtractIcon_AddRef
120 */
121 static ULONG WINAPI IExtractIcon_AddRef(LPEXTRACTICON this)
122 { TRACE(shell,"(%p)->(count=%lu)\n",this,(this->ref)+1);
123   return ++(this->ref);
124 }
125 /**************************************************************************
126 *  IExtractIcon_Release
127 */
128 static ULONG WINAPI IExtractIcon_Release(LPEXTRACTICON this)
129 { TRACE(shell,"(%p)->()\n",this);
130   if (!--(this->ref)) 
131   { TRACE(shell," destroying IExtractIcon(%p)\n",this);
132     SHFree(this->pidl);
133     HeapFree(GetProcessHeap(),0,this);
134     return 0;
135   }
136   return this->ref;
137 }
138 /**************************************************************************
139 *  IExtractIcon_GetIconLocation
140 */
141 static HRESULT WINAPI IExtractIcon_GetIconLocation(LPEXTRACTICON this, UINT32 uFlags, LPSTR szIconFile, UINT32 cchMax, int * piIndex, UINT32 * pwFlags)
142 {       FIXME (shell,"(%p) (flags=%u file=%s max=%u %p %p) semi-stub\n", this, uFlags, szIconFile, cchMax, piIndex, pwFlags);
143
144         *piIndex = (int) SHMapPIDLToSystemImageListIndex(0, this->pidl,0);
145         *pwFlags = GIL_NOTFILENAME;
146
147         FIXME (shell,"-- %x\n",*piIndex);
148
149         return NOERROR;
150 }
151 /**************************************************************************
152 *  IExtractIcon_Extract
153 */
154 static HRESULT WINAPI IExtractIcon_Extract(LPEXTRACTICON this, LPCSTR pszFile, UINT32 nIconIndex, HICON32 *phiconLarge, HICON32 *phiconSmall, UINT32 nIconSize)
155 { FIXME (shell,"(%p) (file=%s index=%u %p %p size=%u) semi-stub\n", this, pszFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
156   *phiconLarge = pImageList_GetIcon(ShellBigIconList, nIconIndex, ILD_TRANSPARENT);
157   *phiconSmall = pImageList_GetIcon(ShellSmallIconList, nIconIndex, ILD_TRANSPARENT);
158   return S_OK;
159 }
160
161 /**************************************************************************
162 * IShellLink Implementation
163 */
164
165 static struct IShellLink_VTable slvt = 
166 {       IShellLink_QueryInterface,
167         IShellLink_AddRef,
168         IShellLink_Release,
169         IShellLink_GetPath,
170         IShellLink_GetIDList,
171         IShellLink_SetIDList,
172         IShellLink_GetDescription,
173         IShellLink_SetDescription,
174         IShellLink_GetWorkingDirectory,
175         IShellLink_SetWorkingDirectory,
176         IShellLink_GetArguments,
177         IShellLink_SetArguments,
178         IShellLink_GetHotkey,
179         IShellLink_SetHotkey,
180         IShellLink_GetShowCmd,
181         IShellLink_SetShowCmd,
182         IShellLink_GetIconLocation,
183         IShellLink_SetIconLocation,
184         IShellLink_SetRelativePath,
185         IShellLink_Resolve,
186         IShellLink_SetPath
187 };
188
189 /**************************************************************************
190  *        IShellLink_Constructor
191  */
192 LPSHELLLINK IShellLink_Constructor() 
193 {       LPSHELLLINK sl;
194
195         sl = (LPSHELLLINK)HeapAlloc(GetProcessHeap(),0,sizeof(IShellLink));
196         sl->ref = 1;
197         sl->lpvtbl = &slvt;
198         TRACE(shell,"(%p)->()\n",sl);
199         return sl;
200 }
201
202 /**************************************************************************
203  *  IShellLink::QueryInterface
204  */
205 static HRESULT WINAPI IShellLink_QueryInterface(
206   LPSHELLLINK this, REFIID riid, LPVOID *ppvObj)
207 {  char    xriid[50];
208    WINE_StringFromCLSID((LPCLSID)riid,xriid);
209    TRACE(shell,"(%p)->(\n\tIID:\t%s)\n",this,xriid);
210
211   *ppvObj = NULL;
212
213   if(IsEqualIID(riid, &IID_IUnknown))          /*IUnknown*/
214   { *ppvObj = this; 
215   }
216   else if(IsEqualIID(riid, &IID_IShellLink))  /*IShellLink*/
217   {    *ppvObj = (LPSHELLLINK)this;
218   }   
219
220   if(*ppvObj)
221   { (*(LPSHELLLINK*)ppvObj)->lpvtbl->fnAddRef(this);      
222     TRACE(shell,"-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
223     return S_OK;
224   }
225     TRACE(shell,"-- Interface: E_NOINTERFACE\n");
226   return E_NOINTERFACE;
227 }  
228 /******************************************************************************
229  * IShellLink_AddRef
230  */
231 static ULONG WINAPI IShellLink_AddRef(LPSHELLLINK this)
232 { TRACE(shell,"(%p)->(count=%lu)\n",this,this->ref);
233     return ++(this->ref);
234 }
235 /******************************************************************************
236  * IClassFactory_Release
237  */
238 static ULONG WINAPI IShellLink_Release(LPSHELLLINK this)
239 { TRACE(shell,"(%p)->(count=%lu)\n",this,this->ref);
240   if (!--(this->ref)) 
241   { TRACE(shell,"-- destroying IShellLink(%p)\n",this);
242     HeapFree(GetProcessHeap(),0,this);
243     return 0;
244   }
245   return this->ref;
246 }
247
248 static HRESULT WINAPI IShellLink_GetPath(LPSHELLLINK this, LPSTR pszFile,INT32 cchMaxPath, WIN32_FIND_DATA32A *pfd, DWORD fFlags)
249 {       FIXME(shell,"(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",this, pszFile, cchMaxPath, pfd, fFlags);
250         strncpy(pszFile,"c:\\foo.bar", cchMaxPath);
251         return NOERROR;
252 }
253 static HRESULT WINAPI IShellLink_GetIDList(LPSHELLLINK this, LPITEMIDLIST * ppidl)
254 {       FIXME(shell,"(%p)->(ppidl=%p)\n",this, ppidl);
255         *ppidl = _ILCreateDesktop();
256         return NOERROR;
257 }
258 static HRESULT WINAPI IShellLink_SetIDList(LPSHELLLINK this, LPCITEMIDLIST pidl)
259 {       FIXME(shell,"(%p)->(pidl=%p)\n",this, pidl);
260         return NOERROR;
261 }
262 static HRESULT WINAPI IShellLink_GetDescription(LPSHELLLINK this, LPSTR pszName,INT32 cchMaxName)
263 {       FIXME(shell,"(%p)->(%p len=%u)\n",this, pszName, cchMaxName);
264         strncpy(pszName,"Description, FIXME",cchMaxName);
265         return NOERROR;
266 }
267 static HRESULT WINAPI IShellLink_SetDescription(LPSHELLLINK this, LPCSTR pszName)
268 {       FIXME(shell,"(%p)->(desc=%s)\n",this, pszName);
269         return NOERROR;
270 }
271 static HRESULT WINAPI IShellLink_GetWorkingDirectory(LPSHELLLINK this, LPSTR pszDir,INT32 cchMaxPath)
272 {       FIXME(shell,"(%p)->()\n",this);
273         strncpy(pszDir,"c:\\", cchMaxPath);
274         return NOERROR;
275 }
276 static HRESULT WINAPI IShellLink_SetWorkingDirectory(LPSHELLLINK this, LPCSTR pszDir)
277 {       FIXME(shell,"(%p)->(dir=%s)\n",this, pszDir);
278         return NOERROR;
279 }
280 static HRESULT WINAPI IShellLink_GetArguments(LPSHELLLINK this, LPSTR pszArgs,INT32 cchMaxPath)
281 {       FIXME(shell,"(%p)->(%p len=%u)\n",this, pszArgs, cchMaxPath);
282         strncpy(pszArgs, "", cchMaxPath);
283         return NOERROR;
284 }
285 static HRESULT WINAPI IShellLink_SetArguments(LPSHELLLINK this, LPCSTR pszArgs)
286 {       FIXME(shell,"(%p)->(args=%s)\n",this, pszArgs);
287         return NOERROR;
288 }
289 static HRESULT WINAPI IShellLink_GetHotkey(LPSHELLLINK this, WORD *pwHotkey)
290 {       FIXME(shell,"(%p)->(%p)\n",this, pwHotkey);
291         *pwHotkey=0x0;
292         return NOERROR;
293 }
294 static HRESULT WINAPI IShellLink_SetHotkey(LPSHELLLINK this, WORD wHotkey)
295 {       FIXME(shell,"(%p)->(hotkey=%x)\n",this, wHotkey);
296         return NOERROR;
297 }
298 static HRESULT WINAPI IShellLink_GetShowCmd(LPSHELLLINK this, INT32 *piShowCmd)
299 {       FIXME(shell,"(%p)->(%p)\n",this, piShowCmd);
300         *piShowCmd=0;
301         return NOERROR;
302 }
303 static HRESULT WINAPI IShellLink_SetShowCmd(LPSHELLLINK this, INT32 iShowCmd)
304 {       FIXME(shell,"(%p)->(showcmd=%x)\n",this, iShowCmd);
305         return NOERROR;
306 }
307 static HRESULT WINAPI IShellLink_GetIconLocation(LPSHELLLINK this, LPSTR pszIconPath,INT32 cchIconPath,INT32 *piIcon)
308 {       FIXME(shell,"(%p)->(%p len=%u iicon=%p)\n",this, pszIconPath, cchIconPath, piIcon);
309         strncpy(pszIconPath,"shell32.dll",cchIconPath);
310         *piIcon=1;
311         return NOERROR;
312 }
313 static HRESULT WINAPI IShellLink_SetIconLocation(LPSHELLLINK this, LPCSTR pszIconPath,INT32 iIcon)
314 {       FIXME(shell,"(%p)->(path=%s iicon=%u)\n",this, pszIconPath, iIcon);
315         return NOERROR;
316 }
317 static HRESULT WINAPI IShellLink_SetRelativePath(LPSHELLLINK this, LPCSTR pszPathRel, DWORD dwReserved)
318 {       FIXME(shell,"(%p)->(path=%s %lx)\n",this, pszPathRel, dwReserved);
319         return NOERROR;
320 }
321 static HRESULT WINAPI IShellLink_Resolve(LPSHELLLINK this, HWND32 hwnd, DWORD fFlags)
322 {       FIXME(shell,"(%p)->(hwnd=%x flags=%lx)\n",this, hwnd, fFlags);
323         return NOERROR;
324 }
325 static HRESULT WINAPI IShellLink_SetPath(LPSHELLLINK this, LPCSTR pszFile)
326 {       FIXME(shell,"(%p)->(path=%s)\n",this, pszFile);
327         return NOERROR;
328 }
329