2 * NamespaceTreeControl implementation.
4 * Copyright 2010 David Hedberg
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
24 #define NONAMELESSUNION
32 #include "wine/list.h"
33 #include "wine/debug.h"
35 #include "explorerframe_main.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(nstc
);
39 typedef struct nstc_root
{
43 NSTCROOTSTYLE root_style
;
44 IShellItemFilter
*pif
;
49 INameSpaceTreeControl2 INameSpaceTreeControl2_iface
;
50 IOleWindow IOleWindow_iface
;
56 WNDPROC tv_oldwndproc
;
62 INameSpaceTreeControlCustomDraw
*customdraw
;
63 INameSpaceTreeControlDropHandler
*dragdrop
;
64 INameSpaceTreeControlEvents
*events
;
67 static const DWORD unsupported_styles
=
68 NSTCS_SINGLECLICKEXPAND
| NSTCS_NOREPLACEOPEN
| NSTCS_NOORDERSTREAM
| NSTCS_FAVORITESMODE
|
69 NSTCS_EMPTYTEXT
| NSTCS_ALLOWJUNCTIONS
| NSTCS_SHOWTABSBUTTON
| NSTCS_SHOWDELETEBUTTON
|
70 NSTCS_SHOWREFRESHBUTTON
| NSTCS_SPRINGEXPAND
| NSTCS_RICHTOOLTIP
| NSTCS_NOINDENTCHECKS
;
71 static const DWORD unsupported_styles2
=
72 NSTCS2_INTERRUPTNOTIFICATIONS
| NSTCS2_SHOWNULLSPACEMENU
| NSTCS2_DISPLAYPADDING
|
73 NSTCS2_DISPLAYPINNEDONLY
| NTSCS2_NOSINGLETONAUTOEXPAND
| NTSCS2_NEVERINSERTNONENUMERATED
;
75 static const WCHAR thispropW
[] = {'P','R','O','P','_','T','H','I','S',0};
77 static inline NSTC2Impl
*impl_from_INameSpaceTreeControl2(INameSpaceTreeControl2
*iface
)
79 return CONTAINING_RECORD(iface
, NSTC2Impl
, INameSpaceTreeControl2_iface
);
82 static inline NSTC2Impl
*impl_from_IOleWindow(IOleWindow
*iface
)
84 return CONTAINING_RECORD(iface
, NSTC2Impl
, IOleWindow_iface
);
87 /* Forward declarations */
88 static LRESULT CALLBACK
tv_wndproc(HWND hWnd
, UINT uMessage
, WPARAM wParam
, LPARAM lParam
);
90 /*************************************************************************
91 * NamespaceTree event wrappers
93 static HRESULT
events_OnGetDefaultIconIndex(NSTC2Impl
*This
, IShellItem
*psi
,
94 int *piDefaultIcon
, int *piOpenIcon
)
98 if(!This
->events
) return E_NOTIMPL
;
100 refcount
= IShellItem_AddRef(psi
);
101 ret
= INameSpaceTreeControlEvents_OnGetDefaultIconIndex(This
->events
, psi
, piDefaultIcon
, piOpenIcon
);
102 if(IShellItem_Release(psi
) < refcount
- 1)
103 ERR("ShellItem was released by client - please file a bug.\n");
107 static HRESULT
events_OnItemAdded(NSTC2Impl
*This
, IShellItem
*psi
, BOOL fIsRoot
)
111 if(!This
->events
) return S_OK
;
113 refcount
= IShellItem_AddRef(psi
);
114 ret
= INameSpaceTreeControlEvents_OnItemAdded(This
->events
, psi
, fIsRoot
);
115 if(IShellItem_Release(psi
) < refcount
- 1)
116 ERR("ShellItem was released by client - please file a bug.\n");
120 static HRESULT
events_OnItemDeleted(NSTC2Impl
*This
, IShellItem
*psi
, BOOL fIsRoot
)
124 if(!This
->events
) return S_OK
;
126 refcount
= IShellItem_AddRef(psi
);
127 ret
= INameSpaceTreeControlEvents_OnItemDeleted(This
->events
, psi
, fIsRoot
);
128 if(IShellItem_Release(psi
) < refcount
- 1)
129 ERR("ShellItem was released by client - please file a bug.\n");
133 static HRESULT
events_OnBeforeExpand(NSTC2Impl
*This
, IShellItem
*psi
)
137 if(!This
->events
) return S_OK
;
139 refcount
= IShellItem_AddRef(psi
);
140 ret
= INameSpaceTreeControlEvents_OnBeforeExpand(This
->events
, psi
);
141 if(IShellItem_Release(psi
) < refcount
- 1)
142 ERR("ShellItem was released by client - please file a bug.\n");
146 static HRESULT
events_OnAfterExpand(NSTC2Impl
*This
, IShellItem
*psi
)
150 if(!This
->events
) return S_OK
;
152 refcount
= IShellItem_AddRef(psi
);
153 ret
= INameSpaceTreeControlEvents_OnAfterExpand(This
->events
, psi
);
154 if(IShellItem_Release(psi
) < refcount
- 1)
155 ERR("ShellItem was released by client - please file a bug.\n");
159 static HRESULT
events_OnItemClick(NSTC2Impl
*This
, IShellItem
*psi
,
160 NSTCEHITTEST nstceHitTest
, NSTCECLICKTYPE nstceClickType
)
164 if(!This
->events
) return S_OK
;
166 refcount
= IShellItem_AddRef(psi
);
167 ret
= INameSpaceTreeControlEvents_OnItemClick(This
->events
, psi
, nstceHitTest
, nstceClickType
);
168 if(IShellItem_Release(psi
) < refcount
- 1)
169 ERR("ShellItem was released by client - please file a bug.\n");
173 static HRESULT
events_OnSelectionChanged(NSTC2Impl
*This
, IShellItemArray
*psia
)
175 if(!This
->events
) return S_OK
;
177 return INameSpaceTreeControlEvents_OnSelectionChanged(This
->events
, psia
);
180 static HRESULT
events_OnKeyboardInput(NSTC2Impl
*This
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
182 if(!This
->events
) return S_OK
;
184 return INameSpaceTreeControlEvents_OnKeyboardInput(This
->events
, uMsg
, wParam
, lParam
);
187 /*************************************************************************
188 * NamespaceTree helper functions
190 static DWORD
treeview_style_from_nstcs(NSTC2Impl
*This
, NSTCSTYLE nstcs
,
191 NSTCSTYLE nstcs_mask
, DWORD
*new_style
)
193 DWORD old_style
, tv_mask
= 0;
194 TRACE("%p, %x, %x, %p\n", This
, nstcs
, nstcs_mask
, new_style
);
197 old_style
= GetWindowLongPtrW(This
->hwnd_tv
, GWL_STYLE
);
199 old_style
= /* The default */
200 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
|
201 WS_TABSTOP
| TVS_NOHSCROLL
| TVS_NONEVENHEIGHT
| TVS_INFOTIP
|
202 TVS_EDITLABELS
| TVS_TRACKSELECT
;
204 if(nstcs_mask
& NSTCS_HASEXPANDOS
) tv_mask
|= TVS_HASBUTTONS
;
205 if(nstcs_mask
& NSTCS_HASLINES
) tv_mask
|= TVS_HASLINES
;
206 if(nstcs_mask
& NSTCS_FULLROWSELECT
) tv_mask
|= TVS_FULLROWSELECT
;
207 if(nstcs_mask
& NSTCS_HORIZONTALSCROLL
) tv_mask
|= TVS_NOHSCROLL
;
208 if(nstcs_mask
& NSTCS_ROOTHASEXPANDO
) tv_mask
|= TVS_LINESATROOT
;
209 if(nstcs_mask
& NSTCS_SHOWSELECTIONALWAYS
) tv_mask
|= TVS_SHOWSELALWAYS
;
210 if(nstcs_mask
& NSTCS_NOINFOTIP
) tv_mask
|= TVS_INFOTIP
;
211 if(nstcs_mask
& NSTCS_EVENHEIGHT
) tv_mask
|= TVS_NONEVENHEIGHT
;
212 if(nstcs_mask
& NSTCS_DISABLEDRAGDROP
) tv_mask
|= TVS_DISABLEDRAGDROP
;
213 if(nstcs_mask
& NSTCS_NOEDITLABELS
) tv_mask
|= TVS_EDITLABELS
;
214 if(nstcs_mask
& NSTCS_CHECKBOXES
) tv_mask
|= TVS_CHECKBOXES
;
218 if(nstcs
& NSTCS_HASEXPANDOS
) *new_style
|= TVS_HASBUTTONS
;
219 if(nstcs
& NSTCS_HASLINES
) *new_style
|= TVS_HASLINES
;
220 if(nstcs
& NSTCS_FULLROWSELECT
) *new_style
|= TVS_FULLROWSELECT
;
221 if(!(nstcs
& NSTCS_HORIZONTALSCROLL
)) *new_style
|= TVS_NOHSCROLL
;
222 if(nstcs
& NSTCS_ROOTHASEXPANDO
) *new_style
|= TVS_LINESATROOT
;
223 if(nstcs
& NSTCS_SHOWSELECTIONALWAYS
) *new_style
|= TVS_SHOWSELALWAYS
;
224 if(!(nstcs
& NSTCS_NOINFOTIP
)) *new_style
|= TVS_INFOTIP
;
225 if(!(nstcs
& NSTCS_EVENHEIGHT
)) *new_style
|= TVS_NONEVENHEIGHT
;
226 if(nstcs
& NSTCS_DISABLEDRAGDROP
) *new_style
|= TVS_DISABLEDRAGDROP
;
227 if(!(nstcs
& NSTCS_NOEDITLABELS
)) *new_style
|= TVS_EDITLABELS
;
228 if(nstcs
& NSTCS_CHECKBOXES
) *new_style
|= TVS_CHECKBOXES
;
230 *new_style
= (old_style
& ~tv_mask
) | (*new_style
& tv_mask
);
232 TRACE("old: %08x, new: %08x\n", old_style
, *new_style
);
234 return old_style
^*new_style
;
237 static IShellItem
*shellitem_from_treeitem(NSTC2Impl
*This
, HTREEITEM hitem
)
241 tvi
.mask
= TVIF_PARAM
;
245 SendMessageW(This
->hwnd_tv
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
247 TRACE("ShellItem: %p\n", (void*)tvi
.lParam
);
248 return (IShellItem
*)tvi
.lParam
;
251 /* Returns the root that the given treeitem belongs to. */
252 static nstc_root
*root_for_treeitem(NSTC2Impl
*This
, HTREEITEM hitem
)
254 HTREEITEM tmp
, hroot
= hitem
;
257 /* Work our way up the hierarchy */
258 for(tmp
= hitem
; tmp
!= NULL
; hroot
= tmp
?tmp
:hroot
)
259 tmp
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_PARENT
, (LPARAM
)hroot
);
261 /* Search through the list of roots for a match */
262 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
263 if(root
->htreeitem
== hroot
)
266 TRACE("root is %p\n", root
);
270 /* Find a shellitem in the tree, starting from the given node. */
271 static HTREEITEM
search_for_shellitem(NSTC2Impl
*This
, HTREEITEM node
,
274 IShellItem
*psi_node
;
275 HTREEITEM next
, result
= NULL
;
278 TRACE("%p, %p, %p\n", This
, node
, psi
);
280 /* Check this node */
281 psi_node
= shellitem_from_treeitem(This
, node
);
282 hr
= IShellItem_Compare(psi
, psi_node
, SICHINT_DISPLAY
, &cmpo
);
287 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
,
288 TVGN_CHILD
, (LPARAM
)node
);
291 result
= search_for_shellitem(This
, next
, psi
);
292 if(result
) return result
;
295 /* Try our next sibling. */
296 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
,
297 TVGN_NEXT
, (LPARAM
)node
);
299 result
= search_for_shellitem(This
, next
, psi
);
304 static HTREEITEM
treeitem_from_shellitem(NSTC2Impl
*This
, IShellItem
*psi
)
307 TRACE("%p, %p\n", This
, psi
);
309 root
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
,
314 return search_for_shellitem(This
, root
, psi
);
317 static int get_icon(LPCITEMIDLIST lpi
, UINT extra_flags
)
320 UINT flags
= SHGFI_PIDL
| SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
;
321 SHGetFileInfoW((LPCWSTR
)lpi
, 0 ,&sfi
, sizeof(SHFILEINFOW
), flags
| extra_flags
);
325 /* Insert a shellitem into the given place in the tree and return the
326 resulting treeitem. */
327 static HTREEITEM
insert_shellitem(NSTC2Impl
*This
, IShellItem
*psi
,
328 HTREEITEM hParent
, HTREEITEM hInsertAfter
)
330 TVINSERTSTRUCTW tvins
;
331 TVITEMEXW
*tvi
= &tvins
.u
.itemex
;
333 TRACE("%p (%p, %p)\n", psi
, hParent
, hInsertAfter
);
335 tvi
->mask
= TVIF_PARAM
| TVIF_CHILDREN
| TVIF_IMAGE
| TVIF_SELECTEDIMAGE
| TVIF_TEXT
;
336 tvi
->cChildren
= I_CHILDRENCALLBACK
;
337 tvi
->iImage
= tvi
->iSelectedImage
= I_IMAGECALLBACK
;
338 tvi
->pszText
= LPSTR_TEXTCALLBACKW
;
340 /* Every treeitem contains a pointer to the corresponding ShellItem. */
341 tvi
->lParam
= (LPARAM
)psi
;
342 tvins
.hParent
= hParent
;
343 tvins
.hInsertAfter
= hInsertAfter
;
345 hinserted
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_INSERTITEMW
, 0,
346 (LPARAM
)(LPTVINSERTSTRUCTW
)&tvins
);
348 IShellItem_AddRef(psi
);
353 /* Enumerates the children of the folder represented by hitem
354 * according to the settings for the root, and adds them to the
355 * treeview. Returns the number of children added. */
356 static UINT
fill_sublevel(NSTC2Impl
*This
, HTREEITEM hitem
)
358 IShellItem
*psiParent
= shellitem_from_treeitem(This
, hitem
);
359 nstc_root
*root
= root_for_treeitem(This
, hitem
);
360 LPITEMIDLIST pidl_parent
;
366 hr
= SHGetIDListFromObject((IUnknown
*)psiParent
, &pidl_parent
);
369 hr
= IShellItem_BindToHandler(psiParent
, NULL
, &BHID_SFObject
, &IID_IShellFolder
, (void**)&psf
);
372 hr
= IShellFolder_EnumObjects(psf
, NULL
, root
->enum_flags
, &peidl
);
379 while( S_OK
== IEnumIDList_Next(peidl
, 1, &pidl
, &fetched
) )
381 hr
= SHCreateShellItem(NULL
, psf
, pidl
, &psi
);
385 if(insert_shellitem(This
, psi
, hitem
, NULL
))
387 events_OnItemAdded(This
, psi
, FALSE
);
391 IShellItem_Release(psi
);
394 ERR("SHCreateShellItem failed with 0x%08x\n", hr
);
396 IEnumIDList_Release(peidl
);
399 ERR("EnumObjects failed with 0x%08x\n", hr
);
401 IShellFolder_Release(psf
);
404 ERR("BindToHandler failed with 0x%08x\n", hr
);
409 ERR("SHGetIDListFromObject failed with 0x%08x\n", hr
);
414 static HTREEITEM
get_selected_treeitem(NSTC2Impl
*This
)
416 return (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_CARET
, 0);
419 static IShellItem
*get_selected_shellitem(NSTC2Impl
*This
)
421 return shellitem_from_treeitem(This
, get_selected_treeitem(This
));
424 static void collapse_all(NSTC2Impl
*This
, HTREEITEM node
)
428 /* Collapse this node first, and then first child/next sibling. */
429 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, TVE_COLLAPSE
, (LPARAM
)node
);
431 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_CHILD
, (LPARAM
)node
);
432 if(next
) collapse_all(This
, next
);
434 next
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_NEXT
, (LPARAM
)node
);
435 if(next
) collapse_all(This
, next
);
438 static HTREEITEM
treeitem_from_point(NSTC2Impl
*This
, const POINT
*pt
, UINT
*hitflag
)
445 SendMessageW(This
->hwnd_tv
, TVM_HITTEST
, 0, (LPARAM
)&tviht
);
446 if(hitflag
) *hitflag
= tviht
.flags
;
450 /*************************************************************************
451 * NamespaceTree window functions
453 static LRESULT
create_namespacetree(HWND hWnd
, CREATESTRUCTW
*crs
)
455 NSTC2Impl
*This
= crs
->lpCreateParams
;
456 HIMAGELIST ShellSmallIconList
;
457 DWORD treeview_style
, treeview_ex_style
;
459 TRACE("%p (%p)\n", This
, crs
);
460 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (LPARAM
)This
);
461 This
->hwnd_main
= hWnd
;
463 treeview_style_from_nstcs(This
, This
->style
, 0xFFFFFFFF, &treeview_style
);
465 This
->hwnd_tv
= CreateWindowExW(0, WC_TREEVIEWW
, NULL
, treeview_style
,
466 0, 0, crs
->cx
, crs
->cy
,
467 hWnd
, NULL
, explorerframe_hinstance
, NULL
);
471 ERR("Failed to create treeview!\n");
472 return HRESULT_FROM_WIN32(GetLastError());
475 treeview_ex_style
= TVS_EX_DRAWIMAGEASYNC
| TVS_EX_RICHTOOLTIP
|
476 TVS_EX_DOUBLEBUFFER
| TVS_EX_NOSINGLECOLLAPSE
;
478 if(This
->style
& NSTCS_AUTOHSCROLL
)
479 treeview_ex_style
|= TVS_EX_AUTOHSCROLL
;
480 if(This
->style
& NSTCS_FADEINOUTEXPANDOS
)
481 treeview_ex_style
|= TVS_EX_FADEINOUTEXPANDOS
;
482 if(This
->style
& NSTCS_PARTIALCHECKBOXES
)
483 treeview_ex_style
|= TVS_EX_PARTIALCHECKBOXES
;
484 if(This
->style
& NSTCS_EXCLUSIONCHECKBOXES
)
485 treeview_ex_style
|= TVS_EX_EXCLUSIONCHECKBOXES
;
486 if(This
->style
& NSTCS_DIMMEDCHECKBOXES
)
487 treeview_ex_style
|= TVS_EX_DIMMEDCHECKBOXES
;
489 SendMessageW(This
->hwnd_tv
, TVM_SETEXTENDEDSTYLE
, treeview_ex_style
, 0xffff);
491 if(Shell_GetImageLists(NULL
, &ShellSmallIconList
))
493 SendMessageW(This
->hwnd_tv
, TVM_SETIMAGELIST
,
494 (WPARAM
)TVSIL_NORMAL
, (LPARAM
)ShellSmallIconList
);
498 ERR("Failed to get the System Image List.\n");
501 INameSpaceTreeControl2_AddRef(&This
->INameSpaceTreeControl2_iface
);
503 /* Subclass the treeview to get the keyboard events. */
504 This
->tv_oldwndproc
= (WNDPROC
)SetWindowLongPtrW(This
->hwnd_tv
, GWLP_WNDPROC
,
505 (ULONG_PTR
)tv_wndproc
);
506 if(This
->tv_oldwndproc
)
507 SetPropW(This
->hwnd_tv
, thispropW
, This
);
512 static LRESULT
resize_namespacetree(NSTC2Impl
*This
)
517 GetClientRect(This
->hwnd_main
, &rc
);
518 MoveWindow(This
->hwnd_tv
, 0, 0, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, TRUE
);
523 static LRESULT
destroy_namespacetree(NSTC2Impl
*This
)
527 /* Undo the subclassing */
528 if(This
->tv_oldwndproc
)
530 SetWindowLongPtrW(This
->hwnd_tv
, GWLP_WNDPROC
, (ULONG_PTR
)This
->tv_oldwndproc
);
531 RemovePropW(This
->hwnd_tv
, thispropW
);
534 INameSpaceTreeControl2_RemoveAllRoots(&This
->INameSpaceTreeControl2_iface
);
536 /* This reference was added in create_namespacetree */
537 INameSpaceTreeControl2_Release(&This
->INameSpaceTreeControl2_iface
);
541 static LRESULT
on_tvn_deleteitemw(NSTC2Impl
*This
, LPARAM lParam
)
543 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
546 IShellItem_Release((IShellItem
*)nmtv
->itemOld
.lParam
);
550 static LRESULT
on_tvn_getdispinfow(NSTC2Impl
*This
, LPARAM lParam
)
552 NMTVDISPINFOW
*dispinfo
= (NMTVDISPINFOW
*)lParam
;
553 TVITEMEXW
*item
= (TVITEMEXW
*)&dispinfo
->item
;
554 IShellItem
*psi
= shellitem_from_treeitem(This
, item
->hItem
);
557 TRACE("%p, %p (mask: %x)\n", This
, dispinfo
, item
->mask
);
559 if(item
->mask
& TVIF_CHILDREN
)
563 hr
= IShellItem_GetAttributes(psi
, SFGAO_HASSUBFOLDER
, &sfgao
);
565 item
->cChildren
= (sfgao
& SFGAO_HASSUBFOLDER
)?1:0;
569 item
->mask
|= TVIF_DI_SETITEM
;
572 if(item
->mask
& (TVIF_IMAGE
|TVIF_SELECTEDIMAGE
))
576 hr
= events_OnGetDefaultIconIndex(This
, psi
, &item
->iImage
, &item
->iSelectedImage
);
579 hr
= SHGetIDListFromObject((IUnknown
*)psi
, &pidl
);
582 item
->iImage
= item
->iSelectedImage
= get_icon(pidl
, 0);
583 item
->mask
|= TVIF_DI_SETITEM
;
587 ERR("Failed to get IDList (%08x).\n", hr
);
591 if(item
->mask
& TVIF_TEXT
)
595 hr
= IShellItem_GetDisplayName(psi
, SIGDN_NORMALDISPLAY
, &display_name
);
598 lstrcpynW(item
->pszText
, display_name
, MAX_PATH
);
599 item
->mask
|= TVIF_DI_SETITEM
;
600 CoTaskMemFree(display_name
);
603 ERR("Failed to get display name (%08x).\n", hr
);
609 static BOOL
treenode_has_subfolders(NSTC2Impl
*This
, HTREEITEM node
)
611 return SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, TVGN_CHILD
, (LPARAM
)node
);
614 static LRESULT
on_tvn_itemexpandingw(NSTC2Impl
*This
, LPARAM lParam
)
616 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
620 psi
= shellitem_from_treeitem(This
, nmtv
->itemNew
.hItem
);
621 events_OnBeforeExpand(This
, psi
);
623 if(!treenode_has_subfolders(This
, nmtv
->itemNew
.hItem
))
625 /* The node has no children, try to find some */
626 if(!fill_sublevel(This
, nmtv
->itemNew
.hItem
))
629 /* Failed to enumerate any children, remove the expando
631 tvi
.hItem
= nmtv
->itemNew
.hItem
;
632 tvi
.mask
= TVIF_CHILDREN
;
634 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
642 static LRESULT
on_tvn_itemexpandedw(NSTC2Impl
*This
, LPARAM lParam
)
644 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
648 psi
= shellitem_from_treeitem(This
, nmtv
->itemNew
.hItem
);
649 events_OnAfterExpand(This
, psi
);
653 static LRESULT
on_tvn_selchangedw(NSTC2Impl
*This
, LPARAM lParam
)
655 NMTREEVIEWW
*nmtv
= (NMTREEVIEWW
*)lParam
;
656 IShellItemArray
*psia
;
661 /* Note: Only supports one selected item. */
662 psi
= shellitem_from_treeitem(This
, nmtv
->itemNew
.hItem
);
663 hr
= SHCreateShellItemArrayFromShellItem(psi
, &IID_IShellItemArray
, (void**)&psia
);
666 events_OnSelectionChanged(This
, psia
);
667 IShellItemArray_Release(psia
);
673 static LRESULT
on_nm_click(NSTC2Impl
*This
, NMHDR
*nmhdr
)
678 TRACE("%p (%p)\n", This
, nmhdr
);
680 GetCursorPos(&tvhit
.pt
);
681 ScreenToClient(This
->hwnd_tv
, &tvhit
.pt
);
682 SendMessageW(This
->hwnd_tv
, TVM_HITTEST
, 0, (LPARAM
)&tvhit
);
684 if(tvhit
.flags
& (TVHT_NOWHERE
|TVHT_ABOVE
|TVHT_BELOW
))
687 /* TVHT_ maps onto the corresponding NSTCEHT_ */
688 psi
= shellitem_from_treeitem(This
, tvhit
.hItem
);
689 hr
= events_OnItemClick(This
, psi
, tvhit
.flags
, NSTCECT_LBUTTON
);
691 /* The expando should not be expanded unless
693 if(tvhit
.flags
== TVHT_ONITEMBUTTON
)
702 static LRESULT
on_wm_mbuttonup(NSTC2Impl
*This
, WPARAM wParam
, LPARAM lParam
)
707 TRACE("%p (%lx, %lx)\n", This
, wParam
, lParam
);
709 tvhit
.pt
.x
= (int)(short)LOWORD(lParam
);
710 tvhit
.pt
.y
= (int)(short)HIWORD(lParam
);
712 SendMessageW(This
->hwnd_tv
, TVM_HITTEST
, 0, (LPARAM
)&tvhit
);
714 /* Seems to generate only ONITEM and ONITEMICON */
715 if( !(tvhit
.flags
& (TVHT_ONITEM
|TVHT_ONITEMICON
)) )
718 psi
= shellitem_from_treeitem(This
, tvhit
.hItem
);
719 hr
= events_OnItemClick(This
, psi
, tvhit
.flags
, NSTCECT_MBUTTON
);
727 static LRESULT
on_kbd_event(NSTC2Impl
*This
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
731 TRACE("%p : %d, %lx, %lx\n", This
, uMsg
, wParam
, lParam
);
733 /* Handled by the client? */
734 if(FAILED(events_OnKeyboardInput(This
, uMsg
, wParam
, lParam
)))
737 if(uMsg
== WM_KEYDOWN
)
742 psi
= get_selected_shellitem(This
);
743 FIXME("Deletion of file requested (shellitem: %p).\n", psi
);
747 hitem
= get_selected_treeitem(This
);
748 SendMessageW(This
->hwnd_tv
, TVM_EDITLABELW
, 0, (LPARAM
)hitem
);
753 /* Let the TreeView handle the key */
757 static LRESULT CALLBACK
tv_wndproc(HWND hWnd
, UINT uMessage
, WPARAM wParam
, LPARAM lParam
)
759 NSTC2Impl
*This
= (NSTC2Impl
*)GetPropW(hWnd
, thispropW
);
768 if(on_kbd_event(This
, uMessage
, wParam
, lParam
))
772 case WM_MBUTTONUP
: return on_wm_mbuttonup(This
, wParam
, lParam
);
775 /* Pass the message on to the treeview */
776 return CallWindowProcW(This
->tv_oldwndproc
, hWnd
, uMessage
, wParam
, lParam
);
779 static LRESULT CALLBACK
NSTC2_WndProc(HWND hWnd
, UINT uMessage
,
780 WPARAM wParam
, LPARAM lParam
)
782 NSTC2Impl
*This
= (NSTC2Impl
*)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
787 case WM_NCCREATE
: return create_namespacetree(hWnd
, (CREATESTRUCTW
*)lParam
);
788 case WM_SIZE
: return resize_namespacetree(This
);
789 case WM_DESTROY
: return destroy_namespacetree(This
);
791 nmhdr
= (NMHDR
*)lParam
;
794 case NM_CLICK
: return on_nm_click(This
, nmhdr
);
795 case TVN_DELETEITEMW
: return on_tvn_deleteitemw(This
, lParam
);
796 case TVN_GETDISPINFOW
: return on_tvn_getdispinfow(This
, lParam
);
797 case TVN_ITEMEXPANDINGW
: return on_tvn_itemexpandingw(This
, lParam
);
798 case TVN_ITEMEXPANDEDW
: return on_tvn_itemexpandedw(This
, lParam
);
799 case TVN_SELCHANGEDW
: return on_tvn_selchangedw(This
, lParam
);
803 default: return DefWindowProcW(hWnd
, uMessage
, wParam
, lParam
);
808 /**************************************************************************
809 * INameSpaceTreeControl2 Implementation
811 static HRESULT WINAPI
NSTC2_fnQueryInterface(INameSpaceTreeControl2
* iface
,
815 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
816 TRACE("%p (%s, %p)\n", This
, debugstr_guid(riid
), ppvObject
);
819 if(IsEqualIID(riid
, &IID_INameSpaceTreeControl2
) ||
820 IsEqualIID(riid
, &IID_INameSpaceTreeControl
) ||
821 IsEqualIID(riid
, &IID_IUnknown
))
823 *ppvObject
= &This
->INameSpaceTreeControl2_iface
;
825 else if(IsEqualIID(riid
, &IID_IOleWindow
))
827 *ppvObject
= &This
->IOleWindow_iface
;
832 IUnknown_AddRef((IUnknown
*)*ppvObject
);
836 return E_NOINTERFACE
;
839 static ULONG WINAPI
NSTC2_fnAddRef(INameSpaceTreeControl2
* iface
)
841 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
842 LONG ref
= InterlockedIncrement(&This
->ref
);
844 TRACE("%p - ref %d\n", This
, ref
);
849 static ULONG WINAPI
NSTC2_fnRelease(INameSpaceTreeControl2
* iface
)
851 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
852 LONG ref
= InterlockedDecrement(&This
->ref
);
854 TRACE("%p - ref: %d\n", This
, ref
);
859 HeapFree(GetProcessHeap(), 0, This
);
860 EFRAME_UnlockModule();
867 static HRESULT WINAPI
NSTC2_fnInitialize(INameSpaceTreeControl2
* iface
,
870 NSTCSTYLE nstcsFlags
)
872 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
874 DWORD window_style
, window_ex_style
;
875 INITCOMMONCONTROLSEX icex
;
877 static const WCHAR NSTC2_CLASS_NAME
[] =
878 {'N','a','m','e','s','p','a','c','e','T','r','e','e',
879 'C','o','n','t','r','o','l',0};
881 TRACE("%p (%p, %p, %x)\n", This
, hwndParent
, prc
, nstcsFlags
);
883 if(nstcsFlags
& unsupported_styles
)
884 FIXME("0x%08x contains the unsupported style(s) 0x%08x\n",
885 nstcsFlags
, nstcsFlags
& unsupported_styles
);
887 This
->style
= nstcsFlags
;
889 icex
.dwSize
= sizeof( icex
);
890 icex
.dwICC
= ICC_TREEVIEW_CLASSES
;
891 InitCommonControlsEx( &icex
);
893 if(!GetClassInfoW(explorerframe_hinstance
, NSTC2_CLASS_NAME
, &wc
))
895 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
896 wc
.lpfnWndProc
= NSTC2_WndProc
;
899 wc
.hInstance
= explorerframe_hinstance
;
901 wc
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
902 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
903 wc
.lpszMenuName
= NULL
;
904 wc
.lpszClassName
= NSTC2_CLASS_NAME
;
906 if (!RegisterClassW(&wc
)) return E_FAIL
;
909 /* NSTCS_TABSTOP and NSTCS_BORDER affects the host window */
910 window_style
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
|
911 (nstcsFlags
& NSTCS_BORDER
? WS_BORDER
: 0);
912 window_ex_style
= nstcsFlags
& NSTCS_TABSTOP
? WS_EX_CONTROLPARENT
: 0;
919 This
->hwnd_main
= CreateWindowExW(window_ex_style
, NSTC2_CLASS_NAME
, NULL
, window_style
,
920 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
921 hwndParent
, 0, explorerframe_hinstance
, This
);
925 ERR("Failed to create the window.\n");
926 return HRESULT_FROM_WIN32(GetLastError());
932 static HRESULT WINAPI
NSTC2_fnTreeAdvise(INameSpaceTreeControl2
* iface
, IUnknown
*handler
, DWORD
*cookie
)
934 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
936 TRACE("%p (%p, %p)\n", This
, handler
, cookie
);
940 /* Only one client supported */
941 if (This
->events
|| This
->customdraw
|| This
->dragdrop
)
944 /* FIXME: request INameSpaceTreeAccessible too */
945 IUnknown_QueryInterface(handler
, &IID_INameSpaceTreeControlEvents
, (void**)&This
->events
);
946 IUnknown_QueryInterface(handler
, &IID_INameSpaceTreeControlCustomDraw
, (void**)&This
->customdraw
);
947 IUnknown_QueryInterface(handler
, &IID_INameSpaceTreeControlDropHandler
, (void**)&This
->dragdrop
);
949 if (This
->events
|| This
->customdraw
|| This
->dragdrop
)
952 return *cookie
? S_OK
: E_FAIL
;
955 static HRESULT WINAPI
NSTC2_fnTreeUnadvise(INameSpaceTreeControl2
* iface
, DWORD cookie
)
957 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
959 TRACE("%p (%x)\n", This
, cookie
);
961 /* The cookie is ignored. */
965 INameSpaceTreeControlEvents_Release(This
->events
);
969 if (This
->customdraw
)
971 INameSpaceTreeControlCustomDraw_Release(This
->customdraw
);
972 This
->customdraw
= NULL
;
977 INameSpaceTreeControlDropHandler_Release(This
->dragdrop
);
978 This
->dragdrop
= NULL
;
984 static HRESULT WINAPI
NSTC2_fnInsertRoot(INameSpaceTreeControl2
* iface
,
987 SHCONTF grfEnumFlags
,
988 NSTCROOTSTYLE grfRootStyle
,
989 IShellItemFilter
*pif
)
991 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
993 struct list
*add_after_entry
;
994 HTREEITEM add_after_hitem
;
997 TRACE("%p, %d, %p, %x, %x, %p\n", This
, iIndex
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
999 new_root
= HeapAlloc(GetProcessHeap(), 0, sizeof(nstc_root
));
1001 return E_OUTOFMEMORY
;
1003 new_root
->psi
= psiRoot
;
1004 new_root
->enum_flags
= grfEnumFlags
;
1005 new_root
->root_style
= grfRootStyle
;
1006 new_root
->pif
= pif
;
1008 /* We want to keep the roots in the internal list and in the
1009 * treeview in the same order. */
1010 add_after_entry
= &This
->roots
;
1011 for(i
= 0; i
< max(0, iIndex
) && list_next(&This
->roots
, add_after_entry
); i
++)
1012 add_after_entry
= list_next(&This
->roots
, add_after_entry
);
1014 if(add_after_entry
== &This
->roots
)
1015 add_after_hitem
= TVI_FIRST
;
1017 add_after_hitem
= LIST_ENTRY(add_after_entry
, nstc_root
, entry
)->htreeitem
;
1019 new_root
->htreeitem
= insert_shellitem(This
, psiRoot
, TVI_ROOT
, add_after_hitem
);
1020 if(!new_root
->htreeitem
)
1022 WARN("Failed to add the root.\n");
1023 HeapFree(GetProcessHeap(), 0, new_root
);
1027 list_add_after(add_after_entry
, &new_root
->entry
);
1028 events_OnItemAdded(This
, psiRoot
, TRUE
);
1030 if(grfRootStyle
& NSTCRS_HIDDEN
)
1033 tvi
.mask
= TVIF_STATEEX
;
1034 tvi
.uStateEx
= TVIS_EX_FLAT
;
1035 tvi
.hItem
= new_root
->htreeitem
;
1037 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
1040 if(grfRootStyle
& NSTCRS_EXPANDED
)
1041 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, TVE_EXPAND
,
1042 (LPARAM
)new_root
->htreeitem
);
1047 static HRESULT WINAPI
NSTC2_fnAppendRoot(INameSpaceTreeControl2
* iface
,
1048 IShellItem
*psiRoot
,
1049 SHCONTF grfEnumFlags
,
1050 NSTCROOTSTYLE grfRootStyle
,
1051 IShellItemFilter
*pif
)
1053 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1055 TRACE("%p, %p, %x, %x, %p\n",
1056 This
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
1058 root_count
= list_count(&This
->roots
);
1060 return INameSpaceTreeControl2_InsertRoot(iface
, root_count
, psiRoot
, grfEnumFlags
, grfRootStyle
, pif
);
1063 static HRESULT WINAPI
NSTC2_fnRemoveRoot(INameSpaceTreeControl2
* iface
,
1064 IShellItem
*psiRoot
)
1066 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1067 nstc_root
*cursor
, *root
= NULL
;
1068 TRACE("%p (%p)\n", This
, psiRoot
);
1071 return E_NOINTERFACE
;
1073 LIST_FOR_EACH_ENTRY(cursor
, &This
->roots
, nstc_root
, entry
)
1077 hr
= IShellItem_Compare(psiRoot
, cursor
->psi
, SICHINT_DISPLAY
, &order
);
1085 TRACE("root %p\n", root
);
1088 events_OnItemDeleted(This
, root
->psi
, TRUE
);
1089 SendMessageW(This
->hwnd_tv
, TVM_DELETEITEM
, 0, (LPARAM
)root
->htreeitem
);
1090 list_remove(&root
->entry
);
1091 HeapFree(GetProcessHeap(), 0, root
);
1096 WARN("No matching root found.\n");
1101 static HRESULT WINAPI
NSTC2_fnRemoveAllRoots(INameSpaceTreeControl2
* iface
)
1103 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1104 nstc_root
*cur1
, *cur2
;
1106 TRACE("%p\n", This
);
1108 if (list_empty(&This
->roots
))
1109 return E_INVALIDARG
;
1111 LIST_FOR_EACH_ENTRY_SAFE(cur1
, cur2
, &This
->roots
, nstc_root
, entry
)
1112 INameSpaceTreeControl2_RemoveRoot(iface
, cur1
->psi
);
1117 static HRESULT WINAPI
NSTC2_fnGetRootItems(INameSpaceTreeControl2
* iface
,
1118 IShellItemArray
**ppsiaRootItems
)
1120 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1122 LPITEMIDLIST
*array
;
1126 TRACE("%p (%p)\n", This
, ppsiaRootItems
);
1128 count
= list_count(&This
->roots
);
1131 return E_INVALIDARG
;
1133 array
= HeapAlloc(GetProcessHeap(), 0, sizeof(LPITEMIDLIST
)*count
);
1136 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
1137 SHGetIDListFromObject((IUnknown
*)root
->psi
, &array
[i
++]);
1139 SHGetDesktopFolder(&psf
);
1140 hr
= SHCreateShellItemArray(NULL
, psf
, count
, (PCUITEMID_CHILD_ARRAY
)array
,
1142 IShellFolder_Release(psf
);
1144 for(i
= 0; i
< count
; i
++)
1147 HeapFree(GetProcessHeap(), 0, array
);
1152 static HRESULT WINAPI
NSTC2_fnSetItemState(INameSpaceTreeControl2
* iface
,
1154 NSTCITEMSTATE nstcisMask
,
1155 NSTCITEMSTATE nstcisFlags
)
1157 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1161 TRACE("%p (%p, %x, %x)\n", This
, psi
, nstcisMask
, nstcisFlags
);
1163 hitem
= treeitem_from_shellitem(This
, psi
);
1164 if(!hitem
) return E_INVALIDARG
;
1166 /* Passing both NSTCIS_SELECTED and NSTCIS_SELECTEDNOEXPAND results
1167 in two TVM_SETITEMW's */
1168 if((nstcisMask
&nstcisFlags
) & NSTCIS_SELECTED
)
1170 SendMessageW(This
->hwnd_tv
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)hitem
);
1171 SendMessageW(This
->hwnd_tv
, TVM_ENSUREVISIBLE
, 0, (LPARAM
)hitem
);
1173 if((nstcisMask
&nstcisFlags
) & NSTCIS_SELECTEDNOEXPAND
)
1175 SendMessageW(This
->hwnd_tv
, TVM_SELECTITEM
, TVGN_CARET
|TVSI_NOSINGLEEXPAND
, (LPARAM
)hitem
);
1178 /* If NSTCIS_EXPANDED is among the flags, the mask is ignored. */
1179 if((nstcisMask
|nstcisFlags
) & NSTCIS_EXPANDED
)
1181 WPARAM arg
= nstcisFlags
&NSTCIS_EXPANDED
? TVE_EXPAND
:TVE_COLLAPSE
;
1182 SendMessageW(This
->hwnd_tv
, TVM_EXPAND
, arg
, (LPARAM
)hitem
);
1185 if(nstcisMask
& NSTCIS_DISABLED
)
1186 tvi
.mask
= TVIF_STATE
| TVIF_STATEEX
;
1187 else if( ((nstcisMask
^nstcisFlags
) & (NSTCIS_SELECTED
|NSTCIS_EXPANDED
|NSTCIS_SELECTEDNOEXPAND
)) ||
1188 ((nstcisMask
|nstcisFlags
) & NSTCIS_BOLD
) ||
1189 (nstcisFlags
& NSTCIS_DISABLED
) )
1190 tvi
.mask
= TVIF_STATE
;
1196 tvi
.stateMask
= tvi
.state
= 0;
1197 tvi
.stateMask
|= ((nstcisFlags
^nstcisMask
)&NSTCIS_SELECTED
) ? TVIS_SELECTED
: 0;
1198 tvi
.stateMask
|= (nstcisMask
|nstcisFlags
)&NSTCIS_BOLD
? TVIS_BOLD
:0;
1199 tvi
.state
|= (nstcisMask
&nstcisFlags
)&NSTCIS_BOLD
? TVIS_BOLD
:0;
1201 if((nstcisMask
&NSTCIS_EXPANDED
)^(nstcisFlags
&NSTCIS_EXPANDED
))
1206 tvi
.uStateEx
= (nstcisFlags
&nstcisMask
)&NSTCIS_DISABLED
?TVIS_EX_DISABLED
:0;
1209 SendMessageW(This
->hwnd_tv
, TVM_SETITEMW
, 0, (LPARAM
)&tvi
);
1215 static HRESULT WINAPI
NSTC2_fnGetItemState(INameSpaceTreeControl2
* iface
,
1217 NSTCITEMSTATE nstcisMask
,
1218 NSTCITEMSTATE
*pnstcisFlags
)
1220 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1223 TRACE("%p (%p, %x, %p)\n", This
, psi
, nstcisMask
, pnstcisFlags
);
1225 hitem
= treeitem_from_shellitem(This
, psi
);
1227 return E_INVALIDARG
;
1232 tvi
.mask
= TVIF_STATE
;
1233 tvi
.stateMask
= TVIS_SELECTED
|TVIS_EXPANDED
|TVIS_BOLD
;
1235 if(nstcisMask
& NSTCIS_DISABLED
)
1236 tvi
.mask
|= TVIF_STATEEX
;
1238 SendMessageW(This
->hwnd_tv
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
1239 *pnstcisFlags
|= (tvi
.state
& TVIS_SELECTED
)?NSTCIS_SELECTED
:0;
1240 *pnstcisFlags
|= (tvi
.state
& TVIS_EXPANDED
)?NSTCIS_EXPANDED
:0;
1241 *pnstcisFlags
|= (tvi
.state
& TVIS_BOLD
)?NSTCIS_BOLD
:0;
1242 *pnstcisFlags
|= (tvi
.uStateEx
& TVIS_EX_DISABLED
)?NSTCIS_DISABLED
:0;
1244 *pnstcisFlags
&= nstcisMask
;
1249 static HRESULT WINAPI
NSTC2_fnGetSelectedItems(INameSpaceTreeControl2
* iface
,
1250 IShellItemArray
**psiaItems
)
1252 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1253 IShellItem
*psiselected
;
1255 TRACE("%p (%p)\n", This
, psiaItems
);
1257 psiselected
= get_selected_shellitem(This
);
1264 return SHCreateShellItemArrayFromShellItem(psiselected
, &IID_IShellItemArray
,
1268 static HRESULT WINAPI
NSTC2_fnGetItemCustomState(INameSpaceTreeControl2
* iface
,
1272 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1273 FIXME("stub, %p (%p, %p)\n", This
, psi
, piStateNumber
);
1277 static HRESULT WINAPI
NSTC2_fnSetItemCustomState(INameSpaceTreeControl2
* iface
,
1281 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1282 FIXME("stub, %p (%p, %d)\n", This
, psi
, iStateNumber
);
1286 static HRESULT WINAPI
NSTC2_fnEnsureItemVisible(INameSpaceTreeControl2
* iface
,
1289 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1292 TRACE("%p (%p)\n", This
, psi
);
1294 hitem
= treeitem_from_shellitem(This
, psi
);
1297 SendMessageW(This
->hwnd_tv
, TVM_ENSUREVISIBLE
, 0, (WPARAM
)hitem
);
1301 return E_INVALIDARG
;
1304 static HRESULT WINAPI
NSTC2_fnSetTheme(INameSpaceTreeControl2
* iface
,
1307 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1308 FIXME("stub, %p (%p)\n", This
, pszTheme
);
1312 static HRESULT WINAPI
NSTC2_fnGetNextItem(INameSpaceTreeControl2
* iface
,
1315 IShellItem
**ppsiNext
)
1317 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1318 HTREEITEM hitem
, hnext
;
1320 TRACE("%p (%p, %x, %p)\n", This
, psi
, nstcgi
, ppsiNext
);
1322 if(!ppsiNext
) return E_POINTER
;
1323 if(!psi
) return E_FAIL
;
1327 hitem
= treeitem_from_shellitem(This
, psi
);
1329 return E_INVALIDARG
;
1333 case NSTCGNI_NEXT
: tvgn
= TVGN_NEXT
; break;
1334 case NSTCGNI_NEXTVISIBLE
: tvgn
= TVGN_NEXTVISIBLE
; break;
1335 case NSTCGNI_PREV
: tvgn
= TVGN_PREVIOUS
; break;
1336 case NSTCGNI_PREVVISIBLE
: tvgn
= TVGN_PREVIOUSVISIBLE
; break;
1337 case NSTCGNI_PARENT
: tvgn
= TVGN_PARENT
; break;
1338 case NSTCGNI_CHILD
: tvgn
= TVGN_CHILD
; break;
1339 case NSTCGNI_FIRSTVISIBLE
: tvgn
= TVGN_FIRSTVISIBLE
; break;
1340 case NSTCGNI_LASTVISIBLE
: tvgn
= TVGN_LASTVISIBLE
; break;
1342 FIXME("Unknown nstcgi value %d\n", nstcgi
);
1346 hnext
= (HTREEITEM
)SendMessageW(This
->hwnd_tv
, TVM_GETNEXTITEM
, tvgn
, (WPARAM
)hitem
);
1349 *ppsiNext
= shellitem_from_treeitem(This
, hnext
);
1350 IShellItem_AddRef(*ppsiNext
);
1357 static HRESULT WINAPI
NSTC2_fnHitTest(INameSpaceTreeControl2
* iface
,
1359 IShellItem
**ppsiOut
)
1361 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1363 TRACE("%p (%p, %p)\n", This
, ppsiOut
, ppt
);
1365 if(!ppt
|| !ppsiOut
)
1370 hitem
= treeitem_from_point(This
, ppt
, NULL
);
1372 *ppsiOut
= shellitem_from_treeitem(This
, hitem
);
1376 IShellItem_AddRef(*ppsiOut
);
1383 static HRESULT WINAPI
NSTC2_fnGetItemRect(INameSpaceTreeControl2
* iface
,
1387 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1389 TRACE("%p (%p, %p)\n", This
, psi
, prect
);
1394 hitem
= treeitem_from_shellitem(This
, psi
);
1397 *(HTREEITEM
*)prect
= hitem
;
1398 if(SendMessageW(This
->hwnd_tv
, TVM_GETITEMRECT
, FALSE
, (LPARAM
)prect
))
1400 MapWindowPoints(This
->hwnd_tv
, HWND_DESKTOP
, (POINT
*)prect
, 2);
1405 return E_INVALIDARG
;
1408 static HRESULT WINAPI
NSTC2_fnCollapseAll(INameSpaceTreeControl2
* iface
)
1410 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1412 TRACE("%p\n", This
);
1414 LIST_FOR_EACH_ENTRY(root
, &This
->roots
, nstc_root
, entry
)
1415 collapse_all(This
, root
->htreeitem
);
1420 static HRESULT WINAPI
NSTC2_fnSetControlStyle(INameSpaceTreeControl2
* iface
,
1421 NSTCSTYLE nstcsMask
,
1422 NSTCSTYLE nstcsStyle
)
1424 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1425 static const DWORD tv_style_flags
=
1426 NSTCS_HASEXPANDOS
| NSTCS_HASLINES
| NSTCS_FULLROWSELECT
|
1427 NSTCS_HORIZONTALSCROLL
| NSTCS_ROOTHASEXPANDO
|
1428 NSTCS_SHOWSELECTIONALWAYS
| NSTCS_NOINFOTIP
| NSTCS_EVENHEIGHT
|
1429 NSTCS_DISABLEDRAGDROP
| NSTCS_NOEDITLABELS
| NSTCS_CHECKBOXES
;
1430 static const DWORD host_style_flags
= NSTCS_TABSTOP
| NSTCS_BORDER
;
1431 static const DWORD nstc_flags
=
1432 NSTCS_SINGLECLICKEXPAND
| NSTCS_NOREPLACEOPEN
| NSTCS_NOORDERSTREAM
|
1433 NSTCS_FAVORITESMODE
| NSTCS_EMPTYTEXT
| NSTCS_ALLOWJUNCTIONS
|
1434 NSTCS_SHOWTABSBUTTON
| NSTCS_SHOWDELETEBUTTON
| NSTCS_SHOWREFRESHBUTTON
;
1435 TRACE("%p (%x, %x)\n", This
, nstcsMask
, nstcsStyle
);
1437 /* Fail if there is an attempt to set an unknown style. */
1438 if(nstcsMask
& ~(tv_style_flags
| host_style_flags
| nstc_flags
))
1441 if(nstcsMask
& tv_style_flags
)
1444 treeview_style_from_nstcs(This
, nstcsStyle
, nstcsMask
, &new_style
);
1445 SetWindowLongPtrW(This
->hwnd_tv
, GWL_STYLE
, new_style
);
1448 /* Flags affecting the host window */
1449 if(nstcsMask
& NSTCS_BORDER
)
1451 DWORD new_style
= GetWindowLongPtrW(This
->hwnd_main
, GWL_STYLE
);
1452 new_style
&= ~WS_BORDER
;
1453 new_style
|= nstcsStyle
& NSTCS_BORDER
? WS_BORDER
: 0;
1454 SetWindowLongPtrW(This
->hwnd_main
, GWL_STYLE
, new_style
);
1456 if(nstcsMask
& NSTCS_TABSTOP
)
1458 DWORD new_style
= GetWindowLongPtrW(This
->hwnd_main
, GWL_EXSTYLE
);
1459 new_style
&= ~WS_EX_CONTROLPARENT
;
1460 new_style
|= nstcsStyle
& NSTCS_TABSTOP
? WS_EX_CONTROLPARENT
: 0;
1461 SetWindowLongPtrW(This
->hwnd_main
, GWL_EXSTYLE
, new_style
);
1464 if((nstcsStyle
& nstcsMask
) & unsupported_styles
)
1465 FIXME("mask & style (0x%08x) contains unsupported style(s): 0x%08x\n",
1466 (nstcsStyle
& nstcsMask
),
1467 (nstcsStyle
& nstcsMask
) & unsupported_styles
);
1469 This
->style
&= ~nstcsMask
;
1470 This
->style
|= (nstcsStyle
& nstcsMask
);
1475 static HRESULT WINAPI
NSTC2_fnGetControlStyle(INameSpaceTreeControl2
* iface
,
1476 NSTCSTYLE nstcsMask
,
1477 NSTCSTYLE
*pnstcsStyle
)
1479 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1480 TRACE("%p (%x, %p)\n", This
, nstcsMask
, pnstcsStyle
);
1482 *pnstcsStyle
= (This
->style
& nstcsMask
);
1487 static HRESULT WINAPI
NSTC2_fnSetControlStyle2(INameSpaceTreeControl2
* iface
,
1488 NSTCSTYLE2 nstcsMask
,
1489 NSTCSTYLE2 nstcsStyle
)
1491 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1492 TRACE("%p (%x, %x)\n", This
, nstcsMask
, nstcsStyle
);
1494 if((nstcsStyle
& nstcsMask
) & unsupported_styles2
)
1495 FIXME("mask & style (0x%08x) contains unsupported style(s): 0x%08x\n",
1496 (nstcsStyle
& nstcsMask
),
1497 (nstcsStyle
& nstcsMask
) & unsupported_styles2
);
1499 This
->style2
&= ~nstcsMask
;
1500 This
->style2
|= (nstcsStyle
& nstcsMask
);
1505 static HRESULT WINAPI
NSTC2_fnGetControlStyle2(INameSpaceTreeControl2
* iface
,
1506 NSTCSTYLE2 nstcsMask
,
1507 NSTCSTYLE2
*pnstcsStyle
)
1509 NSTC2Impl
*This
= impl_from_INameSpaceTreeControl2(iface
);
1510 TRACE("%p (%x, %p)\n", This
, nstcsMask
, pnstcsStyle
);
1512 *pnstcsStyle
= (This
->style2
& nstcsMask
);
1517 static const INameSpaceTreeControl2Vtbl vt_INameSpaceTreeControl2
= {
1518 NSTC2_fnQueryInterface
,
1523 NSTC2_fnTreeUnadvise
,
1527 NSTC2_fnRemoveAllRoots
,
1528 NSTC2_fnGetRootItems
,
1529 NSTC2_fnSetItemState
,
1530 NSTC2_fnGetItemState
,
1531 NSTC2_fnGetSelectedItems
,
1532 NSTC2_fnGetItemCustomState
,
1533 NSTC2_fnSetItemCustomState
,
1534 NSTC2_fnEnsureItemVisible
,
1536 NSTC2_fnGetNextItem
,
1538 NSTC2_fnGetItemRect
,
1539 NSTC2_fnCollapseAll
,
1540 NSTC2_fnSetControlStyle
,
1541 NSTC2_fnGetControlStyle
,
1542 NSTC2_fnSetControlStyle2
,
1543 NSTC2_fnGetControlStyle2
1546 /**************************************************************************
1547 * IOleWindow Implementation
1550 static HRESULT WINAPI
IOW_fnQueryInterface(IOleWindow
*iface
, REFIID riid
, void **ppvObject
)
1552 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1553 return INameSpaceTreeControl2_QueryInterface(&This
->INameSpaceTreeControl2_iface
, riid
, ppvObject
);
1556 static ULONG WINAPI
IOW_fnAddRef(IOleWindow
*iface
)
1558 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1559 return INameSpaceTreeControl2_AddRef(&This
->INameSpaceTreeControl2_iface
);
1562 static ULONG WINAPI
IOW_fnRelease(IOleWindow
*iface
)
1564 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1565 return INameSpaceTreeControl2_Release(&This
->INameSpaceTreeControl2_iface
);
1568 static HRESULT WINAPI
IOW_fnGetWindow(IOleWindow
*iface
, HWND
*phwnd
)
1570 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1571 TRACE("%p (%p)\n", This
, phwnd
);
1573 *phwnd
= This
->hwnd_main
;
1577 static HRESULT WINAPI
IOW_fnContextSensitiveHelp(IOleWindow
*iface
, BOOL fEnterMode
)
1579 NSTC2Impl
*This
= impl_from_IOleWindow(iface
);
1580 TRACE("%p (%d)\n", This
, fEnterMode
);
1582 /* Not implemented */
1586 static const IOleWindowVtbl vt_IOleWindow
= {
1587 IOW_fnQueryInterface
,
1591 IOW_fnContextSensitiveHelp
1594 HRESULT
NamespaceTreeControl_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, void **ppv
)
1599 TRACE ("%p %s %p\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
1604 return CLASS_E_NOAGGREGATION
;
1606 EFRAME_LockModule();
1608 nstc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(NSTC2Impl
));
1610 return E_OUTOFMEMORY
;
1613 nstc
->INameSpaceTreeControl2_iface
.lpVtbl
= &vt_INameSpaceTreeControl2
;
1614 nstc
->IOleWindow_iface
.lpVtbl
= &vt_IOleWindow
;
1616 list_init(&nstc
->roots
);
1618 ret
= INameSpaceTreeControl2_QueryInterface(&nstc
->INameSpaceTreeControl2_iface
, riid
, ppv
);
1619 INameSpaceTreeControl2_Release(&nstc
->INameSpaceTreeControl2_iface
);
1621 TRACE("--(%p)\n", ppv
);