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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/debug.h"
25 #include "shell32_main.h"
26 #include "undocshell.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
30 static CRITICAL_SECTION SHELL32_ChangenotifyCS
;
31 static CRITICAL_SECTION_DEBUG critsect_debug
=
33 0, 0, &SHELL32_ChangenotifyCS
,
34 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
35 0, 0, { 0, (DWORD
)(__FILE__
": SHELL32_ChangenotifyCS") }
37 static CRITICAL_SECTION SHELL32_ChangenotifyCS
= { &critsect_debug
, -1, 0, 0, 0, 0 };
39 /* internal list of notification clients (internal) */
40 typedef struct _NOTIFICATIONLIST
42 struct _NOTIFICATIONLIST
*next
;
43 struct _NOTIFICATIONLIST
*prev
;
44 HWND hwnd
; /* window to notify */
45 DWORD uMsg
; /* message to send */
46 LPNOTIFYREGISTER apidl
; /* array of entries to watch*/
47 UINT cidl
; /* number of pidls in array */
48 LONG wEventMask
; /* subscribed events */
49 LONG wSignalledEvent
; /* event that occurred */
50 DWORD dwFlags
; /* client flags */
51 LPCITEMIDLIST pidlSignaled
; /*pidl of the path that caused the signal*/
53 } NOTIFICATIONLIST
, *LPNOTIFICATIONLIST
;
55 static NOTIFICATIONLIST
*head
, *tail
;
57 #define SHCNE_NOITEMEVENTS ( \
60 #define SHCNE_ONEITEMEVENTS ( \
61 SHCNE_ATTRIBUTES | SHCNE_CREATE | SHCNE_DELETE | SHCNE_DRIVEADD | \
62 SHCNE_DRIVEADDGUI | SHCNE_DRIVEREMOVED | SHCNE_FREESPACE | \
63 SHCNE_MEDIAINSERTED | SHCNE_MEDIAREMOVED | SHCNE_MKDIR | \
64 SHCNE_NETSHARE | SHCNE_NETUNSHARE | SHCNE_RMDIR | \
65 SHCNE_SERVERDISCONNECT | SHCNE_UPDATEDIR | SHCNE_UPDATEIMAGE )
67 #define SHCNE_TWOITEMEVENTS ( \
68 SHCNE_RENAMEFOLDER | SHCNE_RENAMEITEM | SHCNE_UPDATEITEM )
70 /* for dumping events */
71 static const char * DumpEvent( LONG event
)
73 if( event
== SHCNE_ALLEVENTS
)
74 return "SHCNE_ALLEVENTS";
75 #define DUMPEV(x) ,( event & SHCNE_##x )? #x " " : ""
76 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"
91 DUMPEV(SERVERDISCONNECT
)
96 DUMPEV(EXTENDED_EVENT
)
103 static const char * NodeName(LPNOTIFICATIONLIST item
)
106 WCHAR path
[MAX_PATH
];
108 if(SHGetPathFromIDListW(item
->apidl
[0].pidlPath
, path
))
109 str
= wine_dbg_sprintf("%s", debugstr_w(path
));
111 str
= wine_dbg_sprintf("<not a disk file>" );
115 static void AddNode(LPNOTIFICATIONLIST item
)
117 TRACE("item %p\n", item
);
129 static LPNOTIFICATIONLIST
FindNode( HANDLE hitem
)
131 LPNOTIFICATIONLIST ptr
;
132 for( ptr
= head
; ptr
; ptr
= ptr
->next
)
133 if( ptr
== (LPNOTIFICATIONLIST
) hitem
)
138 static void DeleteNode(LPNOTIFICATIONLIST item
)
142 TRACE("item=%p prev=%p next=%p\n", item
, item
->prev
, item
->next
);
144 /* remove item from list */
146 item
->prev
->next
= item
->next
;
150 item
->next
->prev
= item
->prev
;
155 for (i
=0; i
<item
->cidl
; i
++)
156 SHFree(item
->apidl
[i
].pidlPath
);
161 void InitChangeNotifications(void)
165 void FreeChangeNotifications(void)
169 EnterCriticalSection(&SHELL32_ChangenotifyCS
);
174 LeaveCriticalSection(&SHELL32_ChangenotifyCS
);
176 DeleteCriticalSection(&SHELL32_ChangenotifyCS
);
179 /*************************************************************************
180 * SHChangeNotifyRegister [SHELL32.2]
184 SHChangeNotifyRegister(
190 LPCNOTIFYREGISTER lpItems
)
192 LPNOTIFICATIONLIST item
;
195 item
= SHAlloc(sizeof(NOTIFICATIONLIST
));
197 TRACE("(%p,0x%08lx,0x%08lx,0x%08x,0x%08x,%p) item=%p\n",
198 hwnd
, dwFlags
, wEventMask
, uMsg
, cItems
, lpItems
, item
);
203 item
->apidl
= SHAlloc(sizeof(NOTIFYREGISTER
) * cItems
);
204 for(i
=0;i
<cItems
;i
++)
206 item
->apidl
[i
].pidlPath
= ILClone(lpItems
[i
].pidlPath
);
207 item
->apidl
[i
].bWatchSubtree
= lpItems
[i
].bWatchSubtree
;
211 item
->wEventMask
= wEventMask
;
212 item
->wSignalledEvent
= 0;
213 item
->dwFlags
= dwFlags
;
215 TRACE("new node: %s\n", NodeName( item
));
217 EnterCriticalSection(&SHELL32_ChangenotifyCS
);
221 LeaveCriticalSection(&SHELL32_ChangenotifyCS
);
226 /*************************************************************************
227 * SHChangeNotifyDeregister [SHELL32.4]
229 BOOL WINAPI
SHChangeNotifyDeregister(HANDLE hNotify
)
231 LPNOTIFICATIONLIST node
;
233 TRACE("(%p)\n",hNotify
);
235 EnterCriticalSection(&SHELL32_ChangenotifyCS
);
237 node
= FindNode(hNotify
);
241 LeaveCriticalSection(&SHELL32_ChangenotifyCS
);
243 return node
?TRUE
:FALSE
;
246 /*************************************************************************
247 * SHChangeNotifyUpdateEntryList [SHELL32.5]
249 BOOL WINAPI
SHChangeNotifyUpdateEntryList(DWORD unknown1
, DWORD unknown2
,
250 DWORD unknown3
, DWORD unknown4
)
252 FIXME("(0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx)\n",
253 unknown1
, unknown2
, unknown3
, unknown4
);
258 static BOOL
should_notify( LPITEMIDLIST changed
, LPITEMIDLIST watched
, BOOL sub
)
260 TRACE("%p %p %d\n", changed
, watched
, sub
);
263 if (ILIsEqual( watched
, changed
) )
265 if( sub
&& ILIsParent( watched
, changed
, FALSE
) )
270 /*************************************************************************
271 * SHChangeNotify [SHELL32.@]
273 void WINAPI
SHChangeNotify(LONG wEventId
, UINT uFlags
, LPCVOID dwItem1
, LPCVOID dwItem2
)
275 LPITEMIDLIST Pidls
[2];
276 LPNOTIFICATIONLIST ptr
;
278 UINT typeFlag
= uFlags
& SHCNF_TYPE
;
283 TRACE("(0x%08lx,0x%08x,%p,%p):stub.\n", wEventId
, uFlags
, dwItem1
, dwItem2
);
285 if( ( wEventId
& SHCNE_NOITEMEVENTS
) && ( dwItem1
|| dwItem2
) )
287 TRACE("dwItem1 and dwItem2 are not zero, but should be\n");
292 else if( ( wEventId
& SHCNE_ONEITEMEVENTS
) && dwItem2
)
294 TRACE("dwItem2 is not zero, but should be\n");
299 if( ( ( wEventId
& SHCNE_NOITEMEVENTS
) &&
300 ( wEventId
& ~SHCNE_NOITEMEVENTS
) ) ||
301 ( ( wEventId
& SHCNE_ONEITEMEVENTS
) &&
302 ( wEventId
& ~SHCNE_ONEITEMEVENTS
) ) ||
303 ( ( wEventId
& SHCNE_TWOITEMEVENTS
) &&
304 ( wEventId
& ~SHCNE_TWOITEMEVENTS
) ) )
306 WARN("mutually incompatible events listed\n");
310 /* convert paths in IDLists*/
314 if (dwItem1
) SHILCreateFromPathA((LPCSTR
)dwItem1
, &Pidls
[0], &dummy
);
315 if (dwItem2
) SHILCreateFromPathA((LPCSTR
)dwItem2
, &Pidls
[1], &dummy
);
318 if (dwItem1
) SHILCreateFromPathW((LPCWSTR
)dwItem1
, &Pidls
[0], &dummy
);
319 if (dwItem2
) SHILCreateFromPathW((LPCWSTR
)dwItem2
, &Pidls
[1], &dummy
);
322 Pidls
[0] = (LPITEMIDLIST
)dwItem1
;
323 Pidls
[1] = (LPITEMIDLIST
)dwItem2
;
327 FIXME("SHChangeNotify with (uFlags & SHCNF_PRINTER)");
331 FIXME("unknown type %08x\n",typeFlag
);
336 WCHAR path
[MAX_PATH
];
338 if( Pidls
[0] && SHGetPathFromIDListW(Pidls
[0], path
))
339 TRACE("notify %08lx on item1 = %s\n", wEventId
, debugstr_w(path
));
341 if( Pidls
[1] && SHGetPathFromIDListW(Pidls
[1], path
))
342 TRACE("notify %08lx on item2 = %s\n", wEventId
, debugstr_w(path
));
345 EnterCriticalSection(&SHELL32_ChangenotifyCS
);
347 /* loop through the list */
348 for( ptr
= head
; ptr
; ptr
= ptr
->next
)
355 TRACE("trying %p\n", ptr
);
357 for( i
=0; (i
<ptr
->cidl
) && !notify
; i
++ )
359 LPITEMIDLIST pidl
= ptr
->apidl
[i
].pidlPath
;
360 BOOL subtree
= ptr
->apidl
[i
].bWatchSubtree
;
362 if (wEventId
& ptr
->wEventMask
)
364 if( !pidl
) /* all ? */
366 else if( wEventId
& SHCNE_NOITEMEVENTS
)
368 else if( wEventId
& ( SHCNE_ONEITEMEVENTS
| SHCNE_TWOITEMEVENTS
) )
369 notify
= should_notify( Pidls
[0], pidl
, subtree
);
370 else if( wEventId
& SHCNE_TWOITEMEVENTS
)
371 notify
= should_notify( Pidls
[1], pidl
, subtree
);
378 ptr
->pidlSignaled
= ILClone(Pidls
[0]);
380 TRACE("notifying %s, event %s(%lx) before\n", NodeName( ptr
), DumpEvent(
381 wEventId
),wEventId
);
383 ptr
->wSignalledEvent
|= wEventId
;
384 SendMessageA(ptr
->hwnd
, ptr
->uMsg
, (WPARAM
)ptr
, GetCurrentProcessId());
386 TRACE("notifying %s, event %s(%lx) after\n", NodeName( ptr
), DumpEvent(
387 wEventId
),wEventId
);
390 TRACE("notify Done\n");
391 LeaveCriticalSection(&SHELL32_ChangenotifyCS
);
393 /* if we allocated it, free it */
394 if ((typeFlag
== SHCNF_PATHA
) || (typeFlag
== SHCNF_PATHW
))
396 if (Pidls
[0]) SHFree(Pidls
[0]);
397 if (Pidls
[1]) SHFree(Pidls
[1]);
401 /*************************************************************************
402 * NTSHChangeNotifyRegister [SHELL32.640]
404 * Idlist is an array of structures and Count specifies how many items in the array
405 * (usually just one I think).
407 DWORD WINAPI
NTSHChangeNotifyRegister(
413 LPCNOTIFYREGISTER idlist
)
415 FIXME("(%p,0x%08lx,0x%08lx,0x%08lx,0x%08x,%p):semi stub.\n",
416 hwnd
,events1
,events2
,msg
,count
,idlist
);
418 return (DWORD
) SHChangeNotifyRegister(hwnd
, events1
, events2
, msg
, count
, idlist
);
421 /*************************************************************************
422 * SHChangeNotification_Lock [SHELL32.644]
424 HANDLE WINAPI
SHChangeNotification_Lock(
427 LPITEMIDLIST
**lppidls
,
431 LPNOTIFICATIONLIST node
;
432 LPCITEMIDLIST
*idlist
;
434 TRACE("%p %08lx %p %p\n", hChange
, dwProcessId
, lppidls
, lpwEventId
);
436 /* EnterCriticalSection(&SHELL32_ChangenotifyCS); */
438 node
= FindNode( hChange
);
441 idlist
= SHAlloc( sizeof(LPCITEMIDLIST
*) * node
->cidl
);
442 for(i
=0; i
<node
->cidl
; i
++)
443 idlist
[i
] = node
->pidlSignaled
;
444 *lpwEventId
= node
->wSignalledEvent
;
446 node
->wSignalledEvent
= 0;
449 ERR("Couldn't find %p\n", hChange
);
451 /* LeaveCriticalSection(&SHELL32_ChangenotifyCS); */
453 return (HANDLE
) node
;
456 /*************************************************************************
457 * SHChangeNotification_Unlock [SHELL32.645]
459 BOOL WINAPI
SHChangeNotification_Unlock ( HANDLE hLock
)
465 /*************************************************************************
466 * NTSHChangeNotifyDeregister [SHELL32.641]
468 DWORD WINAPI
NTSHChangeNotifyDeregister(LONG x1
)
470 FIXME("(0x%08lx):semi stub.\n",x1
);
472 return SHChangeNotifyDeregister( (HANDLE
)x1
);