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
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
28 #include "wine/debug.h"
31 #include "shell32_main.h"
32 #include "undocshell.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
36 static CRITICAL_SECTION SHELL32_ChangenotifyCS
;
37 static CRITICAL_SECTION_DEBUG critsect_debug
=
39 0, 0, &SHELL32_ChangenotifyCS
,
40 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
41 0, 0, { 0, (DWORD
)(__FILE__
": SHELL32_ChangenotifyCS") }
43 static CRITICAL_SECTION SHELL32_ChangenotifyCS
= { &critsect_debug
, -1, 0, 0, 0, 0 };
45 typedef SHChangeNotifyEntry
*LPNOTIFYREGISTER
;
47 /* internal list of notification clients (internal) */
48 typedef struct _NOTIFICATIONLIST
50 struct _NOTIFICATIONLIST
*next
;
51 struct _NOTIFICATIONLIST
*prev
;
52 HWND hwnd
; /* window to notify */
53 DWORD uMsg
; /* message to send */
54 LPNOTIFYREGISTER apidl
; /* array of entries to watch*/
55 UINT cidl
; /* number of pidls in array */
56 LONG wEventMask
; /* subscribed events */
57 LONG wSignalledEvent
; /* event that occurred */
58 DWORD dwFlags
; /* client flags */
59 LPCITEMIDLIST pidlSignaled
; /*pidl of the path that caused the signal*/
61 } NOTIFICATIONLIST
, *LPNOTIFICATIONLIST
;
63 static NOTIFICATIONLIST
*head
, *tail
;
65 #define SHCNE_NOITEMEVENTS ( \
68 #define SHCNE_ONEITEMEVENTS ( \
69 SHCNE_ATTRIBUTES | SHCNE_CREATE | SHCNE_DELETE | SHCNE_DRIVEADD | \
70 SHCNE_DRIVEADDGUI | SHCNE_DRIVEREMOVED | SHCNE_FREESPACE | \
71 SHCNE_MEDIAINSERTED | SHCNE_MEDIAREMOVED | SHCNE_MKDIR | \
72 SHCNE_NETSHARE | SHCNE_NETUNSHARE | SHCNE_RMDIR | \
73 SHCNE_SERVERDISCONNECT | SHCNE_UPDATEDIR | SHCNE_UPDATEIMAGE )
75 #define SHCNE_TWOITEMEVENTS ( \
76 SHCNE_RENAMEFOLDER | SHCNE_RENAMEITEM | SHCNE_UPDATEITEM )
78 /* for dumping events */
79 static const char * DumpEvent( LONG event
)
81 if( event
== SHCNE_ALLEVENTS
)
82 return "SHCNE_ALLEVENTS";
83 #define DUMPEV(x) ,( event & SHCNE_##x )? #x " " : ""
84 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"
99 DUMPEV(SERVERDISCONNECT
)
104 DUMPEV(EXTENDED_EVENT
)
111 static const char * NodeName(LPNOTIFICATIONLIST item
)
114 WCHAR path
[MAX_PATH
];
116 if(SHGetPathFromIDListW(item
->apidl
[0].pidl
, path
))
117 str
= wine_dbg_sprintf("%s", debugstr_w(path
));
119 str
= wine_dbg_sprintf("<not a disk file>" );
123 static void AddNode(LPNOTIFICATIONLIST item
)
125 TRACE("item %p\n", item
);
137 static LPNOTIFICATIONLIST
FindNode( HANDLE hitem
)
139 LPNOTIFICATIONLIST ptr
;
140 for( ptr
= head
; ptr
; ptr
= ptr
->next
)
141 if( ptr
== (LPNOTIFICATIONLIST
) hitem
)
146 static void DeleteNode(LPNOTIFICATIONLIST item
)
150 TRACE("item=%p prev=%p next=%p\n", item
, item
->prev
, item
->next
);
152 /* remove item from list */
154 item
->prev
->next
= item
->next
;
158 item
->next
->prev
= item
->prev
;
163 for (i
=0; i
<item
->cidl
; i
++)
164 SHFree((LPITEMIDLIST
)item
->apidl
[i
].pidl
);
169 void InitChangeNotifications(void)
173 void FreeChangeNotifications(void)
177 EnterCriticalSection(&SHELL32_ChangenotifyCS
);
182 LeaveCriticalSection(&SHELL32_ChangenotifyCS
);
184 DeleteCriticalSection(&SHELL32_ChangenotifyCS
);
187 /*************************************************************************
188 * SHChangeNotifyRegister [SHELL32.2]
192 SHChangeNotifyRegister(
198 SHChangeNotifyEntry
*lpItems
)
200 LPNOTIFICATIONLIST item
;
203 item
= SHAlloc(sizeof(NOTIFICATIONLIST
));
205 TRACE("(%p,0x%08x,0x%08lx,0x%08x,%d,%p) item=%p\n",
206 hwnd
, fSources
, wEventMask
, uMsg
, cItems
, lpItems
, item
);
211 item
->apidl
= SHAlloc(sizeof(SHChangeNotifyEntry
) * cItems
);
212 for(i
=0;i
<cItems
;i
++)
214 item
->apidl
[i
].pidl
= ILClone(lpItems
[i
].pidl
);
215 item
->apidl
[i
].fRecursive
= lpItems
[i
].fRecursive
;
219 item
->wEventMask
= wEventMask
;
220 item
->wSignalledEvent
= 0;
221 item
->dwFlags
= fSources
;
223 TRACE("new node: %s\n", NodeName( item
));
225 EnterCriticalSection(&SHELL32_ChangenotifyCS
);
229 LeaveCriticalSection(&SHELL32_ChangenotifyCS
);
234 /*************************************************************************
235 * SHChangeNotifyDeregister [SHELL32.4]
237 BOOL WINAPI
SHChangeNotifyDeregister(ULONG hNotify
)
239 LPNOTIFICATIONLIST node
;
241 TRACE("(0x%08lx)\n", hNotify
);
243 EnterCriticalSection(&SHELL32_ChangenotifyCS
);
245 node
= FindNode((HANDLE
)hNotify
);
249 LeaveCriticalSection(&SHELL32_ChangenotifyCS
);
251 return node
?TRUE
:FALSE
;
254 /*************************************************************************
255 * SHChangeNotifyUpdateEntryList [SHELL32.5]
257 BOOL WINAPI
SHChangeNotifyUpdateEntryList(DWORD unknown1
, DWORD unknown2
,
258 DWORD unknown3
, DWORD unknown4
)
260 FIXME("(0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx)\n",
261 unknown1
, unknown2
, unknown3
, unknown4
);
266 static BOOL
should_notify( LPITEMIDLIST changed
, LPCITEMIDLIST watched
, BOOL sub
)
268 TRACE("%p %p %d\n", changed
, watched
, sub
);
271 if (ILIsEqual( watched
, changed
) )
273 if( sub
&& ILIsParent( watched
, changed
, FALSE
) )
278 /*************************************************************************
279 * SHChangeNotify [SHELL32.@]
281 void WINAPI
SHChangeNotify(LONG wEventId
, UINT uFlags
, LPCVOID dwItem1
, LPCVOID dwItem2
)
283 LPITEMIDLIST Pidls
[2];
284 LPNOTIFICATIONLIST ptr
;
285 UINT typeFlag
= uFlags
& SHCNF_TYPE
;
290 TRACE("(0x%08lx,0x%08x,%p,%p):stub.\n", wEventId
, uFlags
, dwItem1
, dwItem2
);
292 if( ( wEventId
& SHCNE_NOITEMEVENTS
) && ( dwItem1
|| dwItem2
) )
294 TRACE("dwItem1 and dwItem2 are not zero, but should be\n");
299 else if( ( wEventId
& SHCNE_ONEITEMEVENTS
) && dwItem2
)
301 TRACE("dwItem2 is not zero, but should be\n");
306 if( ( ( wEventId
& SHCNE_NOITEMEVENTS
) &&
307 ( wEventId
& ~SHCNE_NOITEMEVENTS
) ) ||
308 ( ( wEventId
& SHCNE_ONEITEMEVENTS
) &&
309 ( wEventId
& ~SHCNE_ONEITEMEVENTS
) ) ||
310 ( ( wEventId
& SHCNE_TWOITEMEVENTS
) &&
311 ( wEventId
& ~SHCNE_TWOITEMEVENTS
) ) )
313 WARN("mutually incompatible events listed\n");
317 /* convert paths in IDLists*/
321 if (dwItem1
) Pidls
[0] = SHSimpleIDListFromPathA((LPCSTR
)dwItem1
);
322 if (dwItem2
) Pidls
[1] = SHSimpleIDListFromPathA((LPCSTR
)dwItem2
);
325 if (dwItem1
) Pidls
[0] = SHSimpleIDListFromPathW((LPCWSTR
)dwItem1
);
326 if (dwItem2
) Pidls
[1] = SHSimpleIDListFromPathW((LPCWSTR
)dwItem2
);
329 Pidls
[0] = (LPITEMIDLIST
)dwItem1
;
330 Pidls
[1] = (LPITEMIDLIST
)dwItem2
;
334 FIXME("SHChangeNotify with (uFlags & SHCNF_PRINTER)");
338 FIXME("unknown type %08x\n",typeFlag
);
343 WCHAR path
[MAX_PATH
];
345 if( Pidls
[0] && SHGetPathFromIDListW(Pidls
[0], path
))
346 TRACE("notify %08lx on item1 = %s\n", wEventId
, debugstr_w(path
));
348 if( Pidls
[1] && SHGetPathFromIDListW(Pidls
[1], path
))
349 TRACE("notify %08lx on item2 = %s\n", wEventId
, debugstr_w(path
));
352 EnterCriticalSection(&SHELL32_ChangenotifyCS
);
354 /* loop through the list */
355 for( ptr
= head
; ptr
; ptr
= ptr
->next
)
362 TRACE("trying %p\n", ptr
);
364 for( i
=0; (i
<ptr
->cidl
) && !notify
; i
++ )
366 LPCITEMIDLIST pidl
= ptr
->apidl
[i
].pidl
;
367 BOOL subtree
= ptr
->apidl
[i
].fRecursive
;
369 if (wEventId
& ptr
->wEventMask
)
371 if( !pidl
) /* all ? */
373 else if( wEventId
& SHCNE_NOITEMEVENTS
)
375 else if( wEventId
& ( SHCNE_ONEITEMEVENTS
| SHCNE_TWOITEMEVENTS
) )
376 notify
= should_notify( Pidls
[0], pidl
, subtree
);
377 else if( wEventId
& SHCNE_TWOITEMEVENTS
)
378 notify
= should_notify( Pidls
[1], pidl
, subtree
);
385 ptr
->pidlSignaled
= ILClone(Pidls
[0]);
387 TRACE("notifying %s, event %s(%lx) before\n", NodeName( ptr
), DumpEvent(
388 wEventId
),wEventId
);
390 ptr
->wSignalledEvent
|= wEventId
;
391 SendMessageA(ptr
->hwnd
, ptr
->uMsg
, (WPARAM
)ptr
, GetCurrentProcessId());
393 TRACE("notifying %s, event %s(%lx) after\n", NodeName( ptr
), DumpEvent(
394 wEventId
),wEventId
);
397 TRACE("notify Done\n");
398 LeaveCriticalSection(&SHELL32_ChangenotifyCS
);
400 /* if we allocated it, free it. The ANSI flag is also set in its Unicode sibling. */
401 if ((typeFlag
& SHCNF_PATHA
) || (typeFlag
& SHCNF_PRINTERA
))
403 if (Pidls
[0]) SHFree(Pidls
[0]);
404 if (Pidls
[1]) SHFree(Pidls
[1]);
408 /*************************************************************************
409 * NTSHChangeNotifyRegister [SHELL32.640]
411 * Idlist is an array of structures and Count specifies how many items in the array
412 * (usually just one I think).
414 DWORD WINAPI
NTSHChangeNotifyRegister(
420 SHChangeNotifyEntry
*idlist
)
422 FIXME("(%p,0x%08lx,0x%08lx,0x%08lx,0x%08x,%p):semi stub.\n",
423 hwnd
,events1
,events2
,msg
,count
,idlist
);
425 return (DWORD
) SHChangeNotifyRegister(hwnd
, events1
, events2
, msg
, count
, idlist
);
428 /*************************************************************************
429 * SHChangeNotification_Lock [SHELL32.644]
431 HANDLE WINAPI
SHChangeNotification_Lock(
434 LPITEMIDLIST
**lppidls
,
438 LPNOTIFICATIONLIST node
;
439 LPITEMIDLIST
*idlist
;
441 TRACE("%p %08lx %p %p\n", hChange
, dwProcessId
, lppidls
, lpwEventId
);
443 /* EnterCriticalSection(&SHELL32_ChangenotifyCS); */
445 node
= FindNode( hChange
);
448 idlist
= SHAlloc( sizeof(LPCITEMIDLIST
*) * node
->cidl
);
449 for(i
=0; i
<node
->cidl
; i
++)
450 idlist
[i
] = (LPITEMIDLIST
)node
->pidlSignaled
;
451 *lpwEventId
= node
->wSignalledEvent
;
453 node
->wSignalledEvent
= 0;
456 ERR("Couldn't find %p\n", hChange
);
458 /* LeaveCriticalSection(&SHELL32_ChangenotifyCS); */
460 return (HANDLE
) node
;
463 /*************************************************************************
464 * SHChangeNotification_Unlock [SHELL32.645]
466 BOOL WINAPI
SHChangeNotification_Unlock ( HANDLE hLock
)
472 /*************************************************************************
473 * NTSHChangeNotifyDeregister [SHELL32.641]
475 DWORD WINAPI
NTSHChangeNotifyDeregister(ULONG x1
)
477 FIXME("(0x%08lx):semi stub.\n",x1
);
479 return SHChangeNotifyDeregister( x1
);