wined3d: Print lastpixel state fixme only once.
[wine/hacks.git] / dlls / shell32 / changenotify.c
blob6d528eeb37d8eb6d62113242317b423bd0f419ce
1 /*
2 * shell change notification
4 * Copyright 2000 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <string.h>
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wine/debug.h"
29 #include "wingdi.h"
30 #include "shell32_main.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(shell);
34 static CRITICAL_SECTION SHELL32_ChangenotifyCS;
35 static CRITICAL_SECTION_DEBUG critsect_debug =
37 0, 0, &SHELL32_ChangenotifyCS,
38 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
39 0, 0, { (DWORD_PTR)(__FILE__ ": SHELL32_ChangenotifyCS") }
41 static CRITICAL_SECTION SHELL32_ChangenotifyCS = { &critsect_debug, -1, 0, 0, 0, 0 };
43 typedef SHChangeNotifyEntry *LPNOTIFYREGISTER;
45 /* internal list of notification clients (internal) */
46 typedef struct _NOTIFICATIONLIST
48 struct _NOTIFICATIONLIST *next;
49 struct _NOTIFICATIONLIST *prev;
50 HWND hwnd; /* window to notify */
51 DWORD uMsg; /* message to send */
52 LPNOTIFYREGISTER apidl; /* array of entries to watch*/
53 UINT cidl; /* number of pidls in array */
54 LONG wEventMask; /* subscribed events */
55 LONG wSignalledEvent; /* event that occurred */
56 DWORD dwFlags; /* client flags */
57 LPCITEMIDLIST pidlSignaled; /*pidl of the path that caused the signal*/
59 } NOTIFICATIONLIST, *LPNOTIFICATIONLIST;
61 static NOTIFICATIONLIST *head, *tail;
63 #define SHCNE_NOITEMEVENTS ( \
64 SHCNE_ASSOCCHANGED )
66 #define SHCNE_ONEITEMEVENTS ( \
67 SHCNE_ATTRIBUTES | SHCNE_CREATE | SHCNE_DELETE | SHCNE_DRIVEADD | \
68 SHCNE_DRIVEADDGUI | SHCNE_DRIVEREMOVED | SHCNE_FREESPACE | \
69 SHCNE_MEDIAINSERTED | SHCNE_MEDIAREMOVED | SHCNE_MKDIR | \
70 SHCNE_NETSHARE | SHCNE_NETUNSHARE | SHCNE_RMDIR | \
71 SHCNE_SERVERDISCONNECT | SHCNE_UPDATEDIR | SHCNE_UPDATEIMAGE )
73 #define SHCNE_TWOITEMEVENTS ( \
74 SHCNE_RENAMEFOLDER | SHCNE_RENAMEITEM | SHCNE_UPDATEITEM )
76 /* for dumping events */
77 static const char * DumpEvent( LONG event )
79 if( event == SHCNE_ALLEVENTS )
80 return "SHCNE_ALLEVENTS";
81 #define DUMPEV(x) ,( event & SHCNE_##x )? #x " " : ""
82 return wine_dbg_sprintf( "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
83 DUMPEV(RENAMEITEM)
84 DUMPEV(CREATE)
85 DUMPEV(DELETE)
86 DUMPEV(MKDIR)
87 DUMPEV(RMDIR)
88 DUMPEV(MEDIAINSERTED)
89 DUMPEV(MEDIAREMOVED)
90 DUMPEV(DRIVEREMOVED)
91 DUMPEV(DRIVEADD)
92 DUMPEV(NETSHARE)
93 DUMPEV(NETUNSHARE)
94 DUMPEV(ATTRIBUTES)
95 DUMPEV(UPDATEDIR)
96 DUMPEV(UPDATEITEM)
97 DUMPEV(SERVERDISCONNECT)
98 DUMPEV(UPDATEIMAGE)
99 DUMPEV(DRIVEADDGUI)
100 DUMPEV(RENAMEFOLDER)
101 DUMPEV(FREESPACE)
102 DUMPEV(EXTENDED_EVENT)
103 DUMPEV(ASSOCCHANGED)
104 DUMPEV(INTERRUPT)
106 #undef DUMPEV
109 static const char * NodeName(LPNOTIFICATIONLIST item)
111 const char *str;
112 WCHAR path[MAX_PATH];
114 if(SHGetPathFromIDListW(item->apidl[0].pidl, path ))
115 str = wine_dbg_sprintf("%s", debugstr_w(path));
116 else
117 str = wine_dbg_sprintf("<not a disk file>" );
118 return str;
121 static void AddNode(LPNOTIFICATIONLIST item)
123 TRACE("item %p\n", item );
125 /* link items */
126 item->prev = tail;
127 item->next = NULL;
128 if( tail )
129 tail->next = item;
130 else
131 head = item;
132 tail = item;
135 static LPNOTIFICATIONLIST FindNode( HANDLE hitem )
137 LPNOTIFICATIONLIST ptr;
138 for( ptr = head; ptr; ptr = ptr->next )
139 if( ptr == (LPNOTIFICATIONLIST) hitem )
140 return ptr;
141 return NULL;
144 static void DeleteNode(LPNOTIFICATIONLIST item)
146 UINT i;
148 TRACE("item=%p prev=%p next=%p\n", item, item->prev, item->next);
150 /* remove item from list */
151 if( item->prev )
152 item->prev->next = item->next;
153 else
154 head = item->next;
155 if( item->next )
156 item->next->prev = item->prev;
157 else
158 tail = item->prev;
160 /* free the item */
161 for (i=0; i<item->cidl; i++)
162 SHFree((LPITEMIDLIST)item->apidl[i].pidl);
163 SHFree(item->apidl);
164 SHFree(item);
167 void InitChangeNotifications(void)
171 void FreeChangeNotifications(void)
173 TRACE("\n");
175 EnterCriticalSection(&SHELL32_ChangenotifyCS);
177 while( head )
178 DeleteNode( head );
180 LeaveCriticalSection(&SHELL32_ChangenotifyCS);
182 DeleteCriticalSection(&SHELL32_ChangenotifyCS);
185 /*************************************************************************
186 * SHChangeNotifyRegister [SHELL32.2]
189 ULONG WINAPI
190 SHChangeNotifyRegister(
191 HWND hwnd,
192 int fSources,
193 LONG wEventMask,
194 UINT uMsg,
195 int cItems,
196 SHChangeNotifyEntry *lpItems)
198 LPNOTIFICATIONLIST item;
199 int i;
201 item = SHAlloc(sizeof(NOTIFICATIONLIST));
203 TRACE("(%p,0x%08x,0x%08x,0x%08x,%d,%p) item=%p\n",
204 hwnd, fSources, wEventMask, uMsg, cItems, lpItems, item);
206 item->next = NULL;
207 item->prev = NULL;
208 item->cidl = cItems;
209 item->apidl = SHAlloc(sizeof(SHChangeNotifyEntry) * cItems);
210 for(i=0;i<cItems;i++)
212 item->apidl[i].pidl = ILClone(lpItems[i].pidl);
213 item->apidl[i].fRecursive = lpItems[i].fRecursive;
215 item->hwnd = hwnd;
216 item->uMsg = uMsg;
217 item->wEventMask = wEventMask;
218 item->wSignalledEvent = 0;
219 item->dwFlags = fSources;
221 TRACE("new node: %s\n", NodeName( item ));
223 EnterCriticalSection(&SHELL32_ChangenotifyCS);
225 AddNode(item);
227 LeaveCriticalSection(&SHELL32_ChangenotifyCS);
229 return (ULONG)item;
232 /*************************************************************************
233 * SHChangeNotifyDeregister [SHELL32.4]
235 BOOL WINAPI SHChangeNotifyDeregister(ULONG hNotify)
237 LPNOTIFICATIONLIST node;
239 TRACE("(0x%08x)\n", hNotify);
241 EnterCriticalSection(&SHELL32_ChangenotifyCS);
243 node = FindNode((HANDLE)hNotify);
244 if( node )
245 DeleteNode(node);
247 LeaveCriticalSection(&SHELL32_ChangenotifyCS);
249 return node?TRUE:FALSE;
252 /*************************************************************************
253 * SHChangeNotifyUpdateEntryList [SHELL32.5]
255 BOOL WINAPI SHChangeNotifyUpdateEntryList(DWORD unknown1, DWORD unknown2,
256 DWORD unknown3, DWORD unknown4)
258 FIXME("(0x%08x, 0x%08x, 0x%08x, 0x%08x)\n",
259 unknown1, unknown2, unknown3, unknown4);
261 return -1;
264 static BOOL should_notify( LPCITEMIDLIST changed, LPCITEMIDLIST watched, BOOL sub )
266 TRACE("%p %p %d\n", changed, watched, sub );
267 if ( !watched )
268 return FALSE;
269 if (ILIsEqual( watched, changed ) )
270 return TRUE;
271 if( sub && ILIsParent( watched, changed, FALSE ) )
272 return TRUE;
273 return FALSE;
276 /*************************************************************************
277 * SHChangeNotify [SHELL32.@]
279 void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
281 LPCITEMIDLIST Pidls[2];
282 LPNOTIFICATIONLIST ptr;
283 UINT typeFlag = uFlags & SHCNF_TYPE;
285 Pidls[0] = NULL;
286 Pidls[1] = NULL;
288 TRACE("(0x%08x,0x%08x,%p,%p):stub.\n", wEventId, uFlags, dwItem1, dwItem2);
290 if( ( wEventId & SHCNE_NOITEMEVENTS ) && ( dwItem1 || dwItem2 ) )
292 TRACE("dwItem1 and dwItem2 are not zero, but should be\n");
293 dwItem1 = 0;
294 dwItem2 = 0;
295 return;
297 else if( ( wEventId & SHCNE_ONEITEMEVENTS ) && dwItem2 )
299 TRACE("dwItem2 is not zero, but should be\n");
300 dwItem2 = 0;
301 return;
304 if( ( ( wEventId & SHCNE_NOITEMEVENTS ) &&
305 ( wEventId & ~SHCNE_NOITEMEVENTS ) ) ||
306 ( ( wEventId & SHCNE_ONEITEMEVENTS ) &&
307 ( wEventId & ~SHCNE_ONEITEMEVENTS ) ) ||
308 ( ( wEventId & SHCNE_TWOITEMEVENTS ) &&
309 ( wEventId & ~SHCNE_TWOITEMEVENTS ) ) )
311 WARN("mutually incompatible events listed\n");
312 return;
315 /* convert paths in IDLists*/
316 switch (typeFlag)
318 case SHCNF_PATHA:
319 if (dwItem1) Pidls[0] = SHSimpleIDListFromPathA((LPCSTR)dwItem1);
320 if (dwItem2) Pidls[1] = SHSimpleIDListFromPathA((LPCSTR)dwItem2);
321 break;
322 case SHCNF_PATHW:
323 if (dwItem1) Pidls[0] = SHSimpleIDListFromPathW((LPCWSTR)dwItem1);
324 if (dwItem2) Pidls[1] = SHSimpleIDListFromPathW((LPCWSTR)dwItem2);
325 break;
326 case SHCNF_IDLIST:
327 Pidls[0] = (LPCITEMIDLIST)dwItem1;
328 Pidls[1] = (LPCITEMIDLIST)dwItem2;
329 break;
330 case SHCNF_PRINTERA:
331 case SHCNF_PRINTERW:
332 FIXME("SHChangeNotify with (uFlags & SHCNF_PRINTER)\n");
333 return;
334 case SHCNF_DWORD:
335 default:
336 FIXME("unknown type %08x\n",typeFlag);
337 return;
341 WCHAR path[MAX_PATH];
343 if( Pidls[0] && SHGetPathFromIDListW(Pidls[0], path ))
344 TRACE("notify %08x on item1 = %s\n", wEventId, debugstr_w(path));
346 if( Pidls[1] && SHGetPathFromIDListW(Pidls[1], path ))
347 TRACE("notify %08x on item2 = %s\n", wEventId, debugstr_w(path));
350 EnterCriticalSection(&SHELL32_ChangenotifyCS);
352 /* loop through the list */
353 for( ptr = head; ptr; ptr = ptr->next )
355 BOOL notify;
356 DWORD i;
358 notify = FALSE;
360 TRACE("trying %p\n", ptr);
362 for( i=0; (i<ptr->cidl) && !notify ; i++ )
364 LPCITEMIDLIST pidl = ptr->apidl[i].pidl;
365 BOOL subtree = ptr->apidl[i].fRecursive;
367 if (wEventId & ptr->wEventMask)
369 if( !pidl ) /* all ? */
370 notify = TRUE;
371 else if( wEventId & SHCNE_NOITEMEVENTS )
372 notify = TRUE;
373 else if( wEventId & ( SHCNE_ONEITEMEVENTS | SHCNE_TWOITEMEVENTS ) )
374 notify = should_notify( Pidls[0], pidl, subtree );
375 else if( wEventId & SHCNE_TWOITEMEVENTS )
376 notify = should_notify( Pidls[1], pidl, subtree );
380 if( !notify )
381 continue;
383 ptr->pidlSignaled = ILClone(Pidls[0]);
385 TRACE("notifying %s, event %s(%x) before\n", NodeName( ptr ), DumpEvent(
386 wEventId ),wEventId );
388 ptr->wSignalledEvent |= wEventId;
390 if (ptr->dwFlags & SHCNRF_NewDelivery)
391 SendMessageA(ptr->hwnd, ptr->uMsg, (WPARAM) ptr, (LPARAM) GetCurrentProcessId());
392 else
393 SendMessageA(ptr->hwnd, ptr->uMsg, (WPARAM)Pidls, wEventId);
395 TRACE("notifying %s, event %s(%x) after\n", NodeName( ptr ), DumpEvent(
396 wEventId ),wEventId );
399 TRACE("notify Done\n");
400 LeaveCriticalSection(&SHELL32_ChangenotifyCS);
402 /* if we allocated it, free it. The ANSI flag is also set in its Unicode sibling. */
403 if ((typeFlag & SHCNF_PATHA) || (typeFlag & SHCNF_PRINTERA))
405 SHFree((LPITEMIDLIST)Pidls[0]);
406 SHFree((LPITEMIDLIST)Pidls[1]);
410 /*************************************************************************
411 * NTSHChangeNotifyRegister [SHELL32.640]
412 * NOTES
413 * Idlist is an array of structures and Count specifies how many items in the array
414 * (usually just one I think).
416 DWORD WINAPI NTSHChangeNotifyRegister(
417 HWND hwnd,
418 LONG events1,
419 LONG events2,
420 DWORD msg,
421 int count,
422 SHChangeNotifyEntry *idlist)
424 FIXME("(%p,0x%08x,0x%08x,0x%08x,0x%08x,%p):semi stub.\n",
425 hwnd,events1,events2,msg,count,idlist);
427 return (DWORD) SHChangeNotifyRegister(hwnd, events1, events2, msg, count, idlist);
430 /*************************************************************************
431 * SHChangeNotification_Lock [SHELL32.644]
433 HANDLE WINAPI SHChangeNotification_Lock(
434 HANDLE hChange,
435 DWORD dwProcessId,
436 LPITEMIDLIST **lppidls,
437 LPLONG lpwEventId)
439 DWORD i;
440 LPNOTIFICATIONLIST node;
441 LPCITEMIDLIST *idlist;
443 TRACE("%p %08x %p %p\n", hChange, dwProcessId, lppidls, lpwEventId);
445 /* EnterCriticalSection(&SHELL32_ChangenotifyCS); */
447 node = FindNode( hChange );
448 if( node )
450 idlist = SHAlloc( sizeof(LPCITEMIDLIST *) * node->cidl );
451 for(i=0; i<node->cidl; i++)
452 idlist[i] = (LPCITEMIDLIST)node->pidlSignaled;
453 *lpwEventId = node->wSignalledEvent;
454 *lppidls = (LPITEMIDLIST*)idlist;
455 node->wSignalledEvent = 0;
457 else
458 ERR("Couldn't find %p\n", hChange );
460 /* LeaveCriticalSection(&SHELL32_ChangenotifyCS); */
462 return (HANDLE) node;
465 /*************************************************************************
466 * SHChangeNotification_Unlock [SHELL32.645]
468 BOOL WINAPI SHChangeNotification_Unlock ( HANDLE hLock)
470 TRACE("\n");
471 return 1;
474 /*************************************************************************
475 * NTSHChangeNotifyDeregister [SHELL32.641]
477 DWORD WINAPI NTSHChangeNotifyDeregister(ULONG x1)
479 FIXME("(0x%08x):semi stub.\n",x1);
481 return SHChangeNotifyDeregister( x1 );